Received: by 10.223.164.202 with SMTP id h10csp632225wrb; Wed, 22 Nov 2017 12:42:56 -0800 (PST) X-Google-Smtp-Source: AGs4zMYaq1wU40qLFM2hRb+ixUcMmWNChJVlsKyOs1UO4wSkxNAE39unBxxqvroBZBbQYafciSdW X-Received: by 10.84.172.195 with SMTP id n61mr22052845plb.78.1511383376880; Wed, 22 Nov 2017 12:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511383376; cv=none; d=google.com; s=arc-20160816; b=dGAtEHi6jdw6Gx7ChTyTPu9OPKPyNJMbx5H3rXZKy1Twr0qH155CPHSllz+C+H93BO z4I62fhcuiH7qDIrCFw66AAufGaFLjFZ9GYnYvOcxJfZLgkRHwNoasLo5QQpzvK9BFiP 3XbH7nmYe/U7lcktEdOnjRXHvMv7BGa89eJgWyfaL0sQVnmYmT97Eo+aaOlcgLm4E3nn ErsF+ASEfVHnYWNi9x7PxyAO6SKgi7xYB1Cua8OzLM1jG3JRy5oDzXTxt7Aya/VKrSR0 mQ11D+Siy8952KxJp3fjHCuYOltNFP1OwCPK2foGpzPqGmaQDc83LQTHmb0eEm4opHXm sMGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=PII/er6X+Q/D/PpZRI1s+1sgl2XbKRDRjh3zIW7UdzM=; b=hq7+ItRIaO/F48XokUhd7hni8Gop0/Y0dpsaiP/bSWypuk9pRmdKNn4QPgv9kSJ8wN myMugds6ByIwOy9XjML2Q42EhvZjEkJz9TDV0fC7UWgtrkz2IP2liSJHpI08jtvTa711 IVW7Xl2OkxqNSaV2iVocKhfPayt6/jFz7+YtkaK5nQwKfJt5c2WRJ0U0BXPGUkulJkBa AKGbYcq6ayD/PD4Nid4O8BqdfBON3wu/DPclzID2jYKxXzKuAuyM7wAQtg+By4TUSy4e V0TKnh1AczZ9yF0aIQ3gny+av8qLtBrMZMvk9ZtjFfHr3kDi+gq52K+Cj2/gWLrJEHlq Mwvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f0zaD3kC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si14299053plo.763.2017.11.22.12.42.39; Wed, 22 Nov 2017 12:42:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f0zaD3kC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbdKVUlv (ORCPT + 77 others); Wed, 22 Nov 2017 15:41:51 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34862 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbdKVUlt (ORCPT ); Wed, 22 Nov 2017 15:41:49 -0500 Received: by mail-wm0-f66.google.com with SMTP id y80so12694113wmd.0 for ; Wed, 22 Nov 2017 12:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=PII/er6X+Q/D/PpZRI1s+1sgl2XbKRDRjh3zIW7UdzM=; b=f0zaD3kCFHLCK77OnfSog2a8i4T+Dry+u0hy6PfffVFuOiEHLJcRsfq3j2mc2CKnew zGKYYniuk4eY0KusoPdw2WTKaIjlDWiTWIpliDFQK0qAuNSw04YP39lDHTVgM1L8NOOT 1QiOZUb+FouvgUSRNbkKvZK3t6ZxDbyuSyixg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=PII/er6X+Q/D/PpZRI1s+1sgl2XbKRDRjh3zIW7UdzM=; b=YzuwzqYTJ0GxK5SYnMfOdEEC6oH7ZFUPbYBRrQTEDrVpwJJ70Dy7H64t1Yk2V7AcYU p8MWhxBMNWnXueIgupZodOmrKzS7c//ER9X+9Y7h3kH6yqcg/eJHqDeS76HvhR96qYW/ ufZ2z5K4m+3WHXk3M2aAeghASPBICSSxvbAvC1Gd5iaBYN9psDOW/PeUqzeK7q3aX7WY s86hr2QO1g+aw3IWA7sJHB/U2wj1TeASjY06c41L7Pv2TK7zU3KyZsbWV/nfwWGVZHGO n+gGel/LJR3zZ/STSh0/ZOmQ3llZsyqgff4XfQwEliAl1Qj0FK2VIA/YH207+a6xHPtb JjTw== X-Gm-Message-State: AJaThX6QFpvLsRQbjy5Q4l2WWIYFbd7IMSq/ty+PZIEPVHfSyAsIh2TC LhKeZRuUUGqjRrDMopYYXWonew== X-Received: by 10.28.111.15 with SMTP id k15mr2153253wmc.139.1511383308006; Wed, 22 Nov 2017 12:41:48 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id v195sm2764639wmf.25.2017.11.22.12.41.46 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 22 Nov 2017 12:41:46 -0800 (PST) Date: Wed, 22 Nov 2017 21:41:58 +0100 From: Christoffer Dall To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: 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, Catalin Marinas , Will Deacon , David Daney , Eric Auger , James Morse , open list Subject: Re: [RFC PATCH] kvm: arm64: handle single-step of hyp emulated mmio instructions Message-ID: <20171122204158.GW28855@cbox> References: <20171122170747.12192-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171122170747.12192-1-alex.bennee@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 22, 2017 at 05:07:46PM +0000, Alex Benn�e wrote: > 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 signal > to handle_exit() by clearing the DBG_SPSR_SS bit as would have > actually happened had the hardware really single-stepped the > instruction. > > [AJB: currently compile tested only] > > Signed-off-by: Alex Benn�e > --- > arch/arm64/kvm/handle_exit.c | 8 +++++++- > arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++------- > 2 files changed, 37 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > index af1c804742f6..128120f04e0e 100644 > --- a/arch/arm64/kvm/handle_exit.c > +++ b/arch/arm64/kvm/handle_exit.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include "trace.h" > @@ -242,7 +243,12 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, > return 1; > case ARM_EXCEPTION_EL1_SERROR: > kvm_inject_vabt(vcpu); > - return 1; > + /* We may still need to return for single-step */ > + if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS) > + && kvm_arm_handle_step_debug(vcpu, run)) > + return 0; > + else > + return 1; I think you need to describe in the commit message that this is actually fixing an additional potential problem, not necessarily related to mmio emulation. Hmmm, maybe it is easier to see this in two separate patches after all, introducing this logic first to plug the "debug step exception vs. SError from guest priority is implementation defined" problem, and then using it afterwards for the mmio emulation as well. Come to think of it, we should probably expand on the comment above as well. > case ARM_EXCEPTION_TRAP: > return handle_trap_exceptions(vcpu, run); > case ARM_EXCEPTION_HYP_GONE: > diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c > index 945e79c641c4..a6712f179b52 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) > { > @@ -263,7 +264,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); > > @@ -276,6 +281,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) > @@ -336,13 +349,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; Could this be overriding guest state if the guest is debugging itself and we don't have (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) ? > exit_code = ARM_EXCEPTION_EL1_SERROR; > } > > @@ -357,8 +378,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 */ > -- > 2.15.0 > Other than that, this looks good. Thanks, -Christoffer From 1584786859261112723@xxx Wed Nov 22 17:08:44 +0000 2017 X-GM-THRID: 1584786859261112723 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread