From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B741EC54798 for ; Thu, 7 Mar 2024 15:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SiqE65fkqO5E6S5tB85Wjf2bPz5woZ6uZ0ekJErbSHQ=; b=GgPeBi4HksdPFl RFpZuucTdL9XfHESUQgqXlqlJOHXwbXifi2l+Sw4P6jRvBIF96nmq9jJ0+yataeZlUYQz/N/+DRPq k1tIlh3GJrb+QU6mFxFiVOxr07qMhj0D0s/HfBni40SRhcPv0QGetR4v2G3ngV3Lyp5146/1vth1U cZflhgNpW6eml7u8g+uiPYc021uoVfilZe8x+kKjOdW2v5BNAh18am8zAf4tZam8BbH7gyIr6EKvY 6AsE+LTB2dd5rkjHOUngLuIj8z6YLY2N+KFkbrTrtHGFRTEZuU8pSx7XlzjIqDLq0SD2HQwU993Zj yUnX81/kDOs3ajFruTFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1riG9C-00000005O68-3kKd; Thu, 07 Mar 2024 15:59:06 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1riG99-00000005O47-0nxr for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 15:59:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 34F0061C5B; Thu, 7 Mar 2024 15:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C335DC433F1; Thu, 7 Mar 2024 15:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709827141; bh=UYtkG8yfOSupBSMZ3Yyq2qnzTXCcLitPyHm9qpOJKYc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FUh5wB7teSfQ4E3Jgt0/JB2cACgh+qZ1YBngLgiU9iyk5TbuFh30QrjPlGT7cgcCc LSVaniC6YV079btLKS2gC+lyWgl46McHPlku5Ycsh7D0HzJUt9C03O8PP8Cm4iRJEn wcYPGkpeHfulvLEjQdx27NmEXEMNwWow1JZNwW9vZLA/hH7ExoXVWyMOqZS+w4hA7T XKeU/BeQDd5sxV5FWYurXRXsxP60aw3h+BCe7nSbFOY0yWMsFocdKOmWhGiyVwNiNz v1ltzB4Ib3Nl9eWkh/xmI6BGnqu29l7ZY8LXNcMHX0UQdM4D/YiVeP6XqjVlzuwmY3 twceigxI/L1mA== 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 1riG94-00AMt8-FV; Thu, 07 Mar 2024 15:58:58 +0000 Date: Thu, 07 Mar 2024 15:58:58 +0000 Message-ID: <86il1y11a5.wl-maz@kernel.org> From: Marc Zyngier To: Joey Gouly Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Will Deacon , Catalin Marinas Subject: Re: [PATCH v2 08/13] KVM: arm64: nv: Handle HCR_EL2.{API,APK} independently In-Reply-To: <20240307151454.GA913041@e124191.cambridge.arm.com> References: <20240226100601.2379693-1-maz@kernel.org> <20240226100601.2379693-9-maz@kernel.org> <20240307151454.GA913041@e124191.cambridge.arm.com> 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.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: joey.gouly@arm.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, will@kernel.org, catalin.marinas@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240307_075903_390140_08FB4410 X-CRM114-Status: GOOD ( 36.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 07 Mar 2024 15:14:54 +0000, Joey Gouly wrote: > > On Mon, Feb 26, 2024 at 10:05:56AM +0000, Marc Zyngier wrote: > > Although KVM couples API and APK for simplicity, the architecture > > makes no such requirement, and the two can be independently set or > > cleared. > > > > Check for which of the two possible reasons we have trapped here, > > and if the corresponding L1 control bit isn't set, delegate the > > handling for forwarding. > > > > Otherwise, set this exact bit in HCR_EL2 and resume the guest. > > Of course, in the non-NV case, we keep setting both bits and > > be done with it. Note that the entry core already saves/restores > > the keys should any of the two control bits be set. > > > > This results in a bit of rework, and the removal of the (trivial) > > vcpu_ptrauth_enable() helper. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_emulate.h | 5 ---- > > arch/arm64/kvm/hyp/include/hyp/switch.h | 32 +++++++++++++++++++++---- > > 2 files changed, 27 insertions(+), 10 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > > index debc3753d2ef..d2177bc77844 100644 > > --- a/arch/arm64/include/asm/kvm_emulate.h > > +++ b/arch/arm64/include/asm/kvm_emulate.h > > @@ -125,11 +125,6 @@ static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu) > > vcpu->arch.hcr_el2 |= HCR_TWI; > > } > > > > -static inline void vcpu_ptrauth_enable(struct kvm_vcpu *vcpu) > > -{ > > - vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK); > > -} > > - > > static inline void vcpu_ptrauth_disable(struct kvm_vcpu *vcpu) > > { > > vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK); > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > > index f5f701f309a9..a0908d7a8f56 100644 > > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > > @@ -480,11 +480,35 @@ DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); > > static bool kvm_hyp_handle_ptrauth(struct kvm_vcpu *vcpu, u64 *exit_code) > > { > > struct kvm_cpu_context *ctxt; > > - u64 val; > > + u64 enable = 0; > > > > if (!vcpu_has_ptrauth(vcpu)) > > return false; > > > > + /* > > + * NV requires us to handle API and APK independently, just in > > + * case the hypervisor is totally nuts. Please barf >here<. > > + */ > > + if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) { > > + switch (ESR_ELx_EC(kvm_vcpu_get_esr(vcpu))) { > > + case ESR_ELx_EC_PAC: > > + if (!(__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_API)) > > + return false; > > + > > + enable |= HCR_API; > > + break; > > + > > + case ESR_ELx_EC_SYS64: > > + if (!(__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_APK)) > > + return false; > > + > > + enable |= HCR_APK; > > + break; > > + } > > + } else { > > + enable = HCR_API | HCR_APK; > > + } > > + > > ctxt = this_cpu_ptr(&kvm_hyp_ctxt); > > __ptrauth_save_key(ctxt, APIA); > > __ptrauth_save_key(ctxt, APIB); > > @@ -492,11 +516,9 @@ static bool kvm_hyp_handle_ptrauth(struct kvm_vcpu *vcpu, u64 *exit_code) > > __ptrauth_save_key(ctxt, APDB); > > __ptrauth_save_key(ctxt, APGA); > > > > - vcpu_ptrauth_enable(vcpu); > > > > - val = read_sysreg(hcr_el2); > > - val |= (HCR_API | HCR_APK); > > - write_sysreg(val, hcr_el2); > > + vcpu->arch.hcr_el2 |= enable; > > + sysreg_clear_set(hcr_el2, 0, enable); > > > > return true; > > } > > A bit of sleuthing tells me you plan to delete kvm_hyp_handle_ptrauth() anyway, > so presumably it makes some sense to put that patch before this to avoid > modifying the code just to delete it! Well, I haven't posted that patch yet (soon!), but it is also important to show how these things interact overall. *if* we agree that there is no point in the current approach, then I'll squash the two. But there is a lot to be said about: - discussion on the list first - minimal changes to track regressions So I think there is still value in reviewing this patch on its own! Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel