From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53233410D13; Wed, 7 Oct 2026 07:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791358576; cv=none; b=N0BPxT7+2bj/8oe0Bt2a6um2yxnxWLHZCm6FUM1BGr0SN9OLz8YxXPWUdo6ZjulOv287Uns6o+1+/49PgHRJlvdCM0Q/f2C31tPF4Of/8tvPu/+xfJJ3ZaElklzLWLi7BcE1qKW0dcw3+t9acEV0CfnomLWYw2bxY7a+JBAe34s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791358576; c=relaxed/simple; bh=JqHf8DT/ZSKzWzg5h8EbGrP2BJZCE3z9HkTqxcgLYWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=azVOCDDPeJo0WVlJg2vQ3Q9v6F7VsKWftjtLz5sUJ5MhM2hnRRRC/CblBWqrusTwJUdS5beCvz3u65eX75jjo/LzHnoEgEbtecqsKwL7HC9kFc/JQTMt9GbjvAF4JtZFjJXCJatTcOAqVLCK6qF+oOBRLlh+36Ye4rEWT16o3lc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=eBGgBfRw; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="eBGgBfRw" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 56B1A1477; Wed, 7 Oct 2026 00:36:09 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.2.197.99]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 299E03F763; Wed, 7 Oct 2026 00:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1791358572; bh=JqHf8DT/ZSKzWzg5h8EbGrP2BJZCE3z9HkTqxcgLYWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eBGgBfRwAFY7TjpKhLFx+CaPPqiwV1PRRl4EGs9FXfFsuI3TpaXft8Y+jgzhs5QwT 6LNYOstgU6w5Ku+/1LEd0A2LkkjwLxRtj6C0yUOjrdCmaP1oXVYnXYyRgQJwTPCovu lIkf51h3yeZ1nW0WpWtrsRtypTidRccTIO9h7EUY= From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: maz@kernel.org, will@kernel.org, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, steven.price@arm.com, aneesh.kumar@kernel.org, oupton@kernel.org, gshan@redhat.com, joey.gouly@arm.com, tabba@google.com, yuzenghui@huawei.com, linux-coco@lists.linux.dev, gankulkarni@os.amperecomputing.com, sdonthineni@nvidia.com, alpergun@google.com, fj0570is@fujitsu.com, WeiLin.Chang@arm.com, lpieralisi@kernel.org, enju.kohei@fujitsu.com, sudeep.holla@arm.com, jonathan.cameron@oss.qualcomm.com, Suzuki K Poulose Subject: [PATCH v23 06/14] KVM: arm64: Don't call vcpu_set_pauth_traps for pKVM host Date: Wed, 7 Oct 2026 08:35:29 +0100 Message-ID: <20261007073537.2454351-7-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261007073537.2454351-1-suzuki.poulose@arm.com> References: <20261007073537.2454351-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vcpu_set_pauth_traps() bails out and does nothing for pKVM hosts. Clean this up by moving the is_protected_kvm_enabled() check to the caller, in preparation for adding VM specific vcpu load/put callbacks. While at it, do an early return if the vcpu doesn't have ptrauth. No functional changes Reviewed-by: Gavin Shan Signed-off-by: Suzuki K Poulose --- Changes since v19: - New patch, since addition of this to the Refactoring patch makes it a bit more bigger and harder to review --- arch/arm64/kvm/arm.c | 52 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index bcec14c587119..50b84065ead1a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -631,33 +631,34 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) static void vcpu_set_pauth_traps(struct kvm_vcpu *vcpu) { - if (vcpu_has_ptrauth(vcpu) && !is_protected_kvm_enabled()) { - /* - * Either we're running an L2 guest, and the API/APK bits come - * from L1's HCR_EL2, or API/APK are both set. - */ - if (unlikely(is_nested_ctxt(vcpu))) { - u64 val; + if (!vcpu_has_ptrauth(vcpu)) + return; - val = __vcpu_sys_reg(vcpu, HCR_EL2); - val &= (HCR_API | HCR_APK); - vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK); - vcpu->arch.hcr_el2 |= val; - } else { - vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK); - } + /* + * Either we're running an L2 guest, and the API/APK bits come + * from L1's HCR_EL2, or API/APK are both set. + */ + if (unlikely(is_nested_ctxt(vcpu))) { + u64 val; - /* - * Save the host keys if there is any chance for the guest - * to use pauth, as the entry code will reload the guest - * keys in that case. - */ - if (vcpu->arch.hcr_el2 & (HCR_API | HCR_APK)) { - struct kvm_cpu_context *ctxt; + val = __vcpu_sys_reg(vcpu, HCR_EL2); + val &= (HCR_API | HCR_APK); + vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK); + vcpu->arch.hcr_el2 |= val; + } else { + vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK); + } - ctxt = this_cpu_ptr_hyp_sym(kvm_hyp_ctxt); - ptrauth_save_keys(ctxt); - } + /* + * Save the host keys if there is any chance for the guest + * to use pauth, as the entry code will reload the guest + * keys in that case. + */ + if (vcpu->arch.hcr_el2 & (HCR_API | HCR_APK)) { + struct kvm_cpu_context *ctxt; + + ctxt = this_cpu_ptr_hyp_sym(kvm_hyp_ctxt); + ptrauth_save_keys(ctxt); } } @@ -749,7 +750,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) else vcpu->arch.hcr_el2 |= HCR_TWI; - vcpu_set_pauth_traps(vcpu); + if (!is_protected_kvm_enabled()) + vcpu_set_pauth_traps(vcpu); if (is_protected_kvm_enabled()) { kvm_call_hyp_nvhe(__pkvm_vcpu_load, -- 2.43.0