From patchwork Thu Nov 23 12:11:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 10072717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4859A60353 for ; Thu, 23 Nov 2017 12:11:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 359A92972E for ; Thu, 23 Nov 2017 12:11:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A6A429FE8; Thu, 23 Nov 2017 12:11:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC64429FE7 for ; Thu, 23 Nov 2017 12:11:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbdKWMLm (ORCPT ); Thu, 23 Nov 2017 07:11:42 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:47030 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752405AbdKWMLk (ORCPT ); Thu, 23 Nov 2017 07:11:40 -0500 Received: by mail-wm0-f67.google.com with SMTP id u83so16490124wmb.5 for ; Thu, 23 Nov 2017 04:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EYF0sMOBzBWqbkDMFpJz09wwUdXiuhAlZy37sizlgnU=; b=NGRdthlnLELYoxJeXnGv1ZrrHjWxGxr3dI3MSvPKgHfoK7THo0iSc4o381jTBjL4O8 arWFk3clA0uObzEXONIT8GBVk3AePBW+SIT1cCY65PZW6ucWlOqdI2bnP5GFYEHU1VoG CIAEjh7iA4iOMaPCNqY41uOAHu50m98PfLuuQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EYF0sMOBzBWqbkDMFpJz09wwUdXiuhAlZy37sizlgnU=; b=fPMvEB+rxtuvfOvtlq7zvBKsYkNY8AS+tlMQjwqvTp5yac6Ns+Xfmt/ue52qMSytFZ LOnX975u6cI2O36DEKCIMlpRXMhRKtWcDQbxcWScnfs8Zuj8wx36CwnDEAfkdaBxLTKm BMy6c3K8TnvNG0++gZ5u+o30uQcBpJRkNeOWGz2HmccVjqggpt2hbHeoDRt+QWWWF/9q gdLLxZ6zHIAwbf1dYbHazMfEoJ18PxlfmXtGsjGt7LRPNdK1eRyomJsXn9w3LN9twX4B b+IQFwHJV9kK6r5QFDSMUz5vHpTEAeG4dPYSrk4g7BF1ijp/xkWhTjY0Io2oElkltT3f wmrg== X-Gm-Message-State: AJaThX6E6zKdW/knPtoHrsO2hCx9RNB7cLx76pkmgP5LOuHBC4nZjDzc 882uXvqWPTg52JstixsadjSJwA== X-Google-Smtp-Source: AGs4zMb3CiQ6o6qDcv7AaVVbryL3KpqIph9+4xZHdXOqjG4/N7/8BJAX9H4d9li5wdozlL5nqb/4Hg== X-Received: by 10.28.105.14 with SMTP id e14mr6906849wmc.74.1511439098776; Thu, 23 Nov 2017 04:11:38 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c3sm3914552wrf.21.2017.11.23.04.11.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 04:11:37 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id CBE833E009E; Thu, 23 Nov 2017 12:11:36 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: julien.thierry@arm.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Catalin Marinas , Will Deacon , Dave Martin , James Morse , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1 2/2] kvm: arm64: handle single-step of hyp emulated mmio instructions Date: Thu, 23 Nov 2017 12:11:34 +0000 Message-Id: <20171123121134.11050-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171123121134.11050-1-alex.bennee@linaro.org> References: <20171123121134.11050-1-alex.bennee@linaro.org> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a fast-path of MMIO emulation inside hyp mode. The handling of single-step is broadly the same as kvm_arm_handle_step_debug() except we just setup ESR/HSR so handle_exit() does the correct thing as we exit. For the case of an emulated illegal access causing an SError we will exit via the ARM_EXCEPTION_EL1_SERROR path in handle_exit(). We behave as we would during a real SError and clear the DBG_SPSR_SS bit for the emulated instruction. Signed-off-by: Alex Bennée Reviewed-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 525c01f48867..f7c651f3a8c0 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -22,6 +22,7 @@ #include #include #include +#include static bool __hyp_text __fpsimd_enabled_nvhe(void) { @@ -269,7 +270,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) return true; } -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) +/* Skip an instruction which has been emulated. Returns true if + * execution can continue or false if we need to exit hyp mode because + * single-step was in effect. + */ +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu) { *vcpu_pc(vcpu) = read_sysreg_el2(elr); @@ -282,6 +287,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) } write_sysreg_el2(*vcpu_pc(vcpu), elr); + + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { + vcpu->arch.fault.esr_el2 = + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22; + return false; + } else { + return true; + } } int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) @@ -342,13 +355,21 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v2_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } if (ret == -1) { - /* Promote an illegal access to an SError */ - __skip_instr(vcpu); + /* Promote an illegal access to an + * SError. If we would be returning + * due to single-step clear the SS + * bit so handle_exit knows what to + * do after dealing with the error. + */ + if (!__skip_instr(vcpu)) + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; exit_code = ARM_EXCEPTION_EL1_SERROR; } @@ -363,8 +384,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v3_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } /* 0 falls through to be handled out of EL2 */