From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C41612F5B1 for ; Sat, 9 Nov 2024 11:57:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731153469; cv=none; b=tnTw/VniAfnp6EFkB75vUBf285h4ST20pVAKgRgPtmd7HkAxsYYAeHfJWB7dZGZX1wdl5LQWfB4wv8SFhJL9wIbRqbLeVO5q2ppfPd0ZpkkiPFljkYBSRVa7/rkM8qlZqKqsP8iiiVZpUSpWR6nNdBINHPAPBe7/nvuHVphmrJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731153469; c=relaxed/simple; bh=/pKqotiNG18b73RV6gOYJNlreafs0VEOHaFFJT4FIY8=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=CNKR1uHsDTLHOjB8tOcK9EfD1EVO2TZQGRZJjkM+tTYBE6hwrPDUYNAipCtDy4u6Ttpb+2gxRu87ii3ympE5D9cN1W6EPMkaN0DDrLFRmiLMZ0j2534FKAmQbik5EGZz/O1ve0RsrNqYZetSYILIJeZEm1AGEGddmAm2HEtMZfk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hqwlAp94; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hqwlAp94" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E65D6C4CECE; Sat, 9 Nov 2024 11:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731153468; bh=/pKqotiNG18b73RV6gOYJNlreafs0VEOHaFFJT4FIY8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hqwlAp94wJD4Icgofgr8LVAO4L9n7WeMw/o7vjeYioaHVEPCQ5ftAnfn6JYLiTimC rSyaWs6mqM+rMoSiclTVAu+usiEVN/nF+7cFS9onALSEp5aXw64u8odgr3dwlVPedu fQEiSRVOVpBtPruC1PFRz/YdxxNMD0E48B7dvhl64TJvCxVWhncjIPElEKweppGzta 0KR1dw/uYnShjXcOtMVqk4mawxTDQrm2lGTcq0/ZUFEhL978CjFDXQzFb/yRtIXzWv dyh2VSalIYHbhFKhlvBwytnu5jPoL4frjhahiq+3UNvhSyioxO/ZQcKSlAtIrp/jn3 aPxOwAgDeZ2cA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t9k66-00BPSF-PL; Sat, 09 Nov 2024 11:57:46 +0000 Date: Sat, 09 Nov 2024 11:57:46 +0000 Message-ID: <861pzk1ux1.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mingwei Zhang , Colton Lewis , Alexandru Elisei Subject: Re: [PATCH 08/15] KVM: arm64: Select debug state to save/restore based on debug owner In-Reply-To: <20241108222418.1677420-9-oliver.upton@linux.dev> References: <20241108222418.1677420-1-oliver.upton@linux.dev> <20241108222418.1677420-9-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, mizhang@google.com, coltonlewis@google.com, alexandru.elisei@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 08 Nov 2024 22:24:12 +0000, Oliver Upton wrote: > > Select the set of debug registers to use based on the owner rather than > relying on debug_ptr. > > Signed-off-by: Oliver Upton > --- > arch/arm64/include/asm/kvm_host.h | 21 +++++++++++++++++++++ > arch/arm64/kvm/hyp/include/hyp/debug-sr.h | 8 ++++---- > 2 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index d76e4e44b65b..2d9aee66d5d4 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -1357,9 +1357,30 @@ void kvm_handle_debug_access(struct kvm_vcpu *vcpu); > #define kvm_vcpu_os_lock_enabled(vcpu) \ > (!!(__vcpu_sys_reg(vcpu, OSLSR_EL1) & OSLSR_EL1_OSLK)) > > +#define kvm_debug_regs_in_use(vcpu) \ > + ((vcpu)->arch.debug_owner != VCPU_DEBUG_FREE) > #define kvm_host_owns_debug_regs(vcpu) \ > ((vcpu)->arch.debug_owner == VCPU_DEBUG_HOST_OWNED) > > +#define vcpu_debug_regs(vcpu) \ > +({ \ > + struct kvm_guest_debug_arch *__d; \ > + \ > + switch ((vcpu)->arch.debug_owner) { \ > + case VCPU_DEBUG_FREE: \ > + WARN_ON_ONCE(1); \ > + fallthrough; \ > + case VCPU_DEBUG_GUEST_OWNED: \ > + __d = &(vcpu)->arch.vcpu_debug_state; \ > + break; \ > + case VCPU_DEBUG_HOST_OWNED: \ > + __d = &(vcpu)->arch.external_debug_state; \ > + break; \ > + } \ > + \ > + __d; \ > +}) Any particular reason why this can't be an actual function? Or at least a function taking a kvm_ vcpu_arch as a parameter, and a preprocessor wrapper for the vcpu->arch pointer chasing? > + > int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, > struct kvm_device_attr *attr); > int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu, > diff --git a/arch/arm64/kvm/hyp/include/hyp/debug-sr.h b/arch/arm64/kvm/hyp/include/hyp/debug-sr.h > index d00093699aaf..acc47f77b3d0 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/debug-sr.h > +++ b/arch/arm64/kvm/hyp/include/hyp/debug-sr.h > @@ -132,13 +132,13 @@ static inline void __debug_switch_to_guest_common(struct kvm_vcpu *vcpu) > struct kvm_guest_debug_arch *host_dbg; > struct kvm_guest_debug_arch *guest_dbg; > > - if (!vcpu_get_flag(vcpu, DEBUG_DIRTY)) > + if (!kvm_debug_regs_in_use(vcpu)) > return; > > host_ctxt = host_data_ptr(host_ctxt); > guest_ctxt = &vcpu->arch.ctxt; > host_dbg = host_data_ptr(host_debug_state.regs); > - guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr); > + guest_dbg = vcpu_debug_regs(vcpu); One thing you may want to note in the commit log is that this also allows us to drop a couple of kern_hyp_va() instances, which is always a good thing. > > __debug_save_state(host_dbg, host_ctxt); > __debug_restore_state(guest_dbg, guest_ctxt); > @@ -151,13 +151,13 @@ static inline void __debug_switch_to_host_common(struct kvm_vcpu *vcpu) > struct kvm_guest_debug_arch *host_dbg; > struct kvm_guest_debug_arch *guest_dbg; > > - if (!vcpu_get_flag(vcpu, DEBUG_DIRTY)) > + if (!kvm_debug_regs_in_use(vcpu)) > return; > > host_ctxt = host_data_ptr(host_ctxt); > guest_ctxt = &vcpu->arch.ctxt; > host_dbg = host_data_ptr(host_debug_state.regs); > - guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr); > + guest_dbg = vcpu_debug_regs(vcpu); > > __debug_save_state(guest_dbg, guest_ctxt); > __debug_restore_state(host_dbg, host_ctxt); Thanks, M. -- Without deviation from the norm, progress is not possible.