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 94C55CA600A for ; Thu, 8 Oct 2026 07:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To:Subject :MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JgMaUazBcpqvux2KQDW+vhUXwrg8xsyRivF3+Hr/oNo=; b=hwQ6YlDVCG59PM cgtEuv/jUgnqyzQlveshAy8gUqn31ub2Wesxtf71qRJ9QFKsAkXOlCEYJlLCmoSgKFkcIz3lpVqYn E8u7rE2I+0puM5RUGniW7LR6Qyq8mpPvkqthpdJzoOyhlJC2jPM5W01iJiVyU7C0GqQYoN0GG1CYX E43Y6pt5gcnKju2iWHqGLqGeeQo9l/rDlXzd8QZo2RYbbTaVl/hVosYRgL6T/3AigUHCuUbS77oOx wCXIiYrNlZYbg3MWpZnNMqXzdgeoQvQ4eQ/e7D69vTbkWDXFS3/ZeHnMykW6oDJ30jupVjRorJbOh zdgGnBGP0RVQyXc55Hrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xEior-00000003mtS-2ora; Thu, 08 Oct 2026 07:45:37 +0000 Received: from canpmsgout12.his.huawei.com ([113.46.200.227]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xEioo-00000003msh-2tyF for linux-arm-kernel@lists.infradead.org; Thu, 08 Oct 2026 07:45:36 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=JgMaUazBcpqvux2KQDW+vhUXwrg8xsyRivF3+Hr/oNo=; b=Sgvf7B59ydpF9D5jY+B+heyPb50E82OAtETzIJuBlsByFUHSTjmArd7xNCixSIXjb0p2MggUx WFV/UHdLl+c/mjnY4tQiOubY8pSnKYKq9W23opyxq2rRwEJ9jqATT3O/gCpI9ICn9RGuJQ3YfiR oAhr8bQc9hfeeO7iDVRzG8g= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4j0hYl4FHDznTVd; Thu, 8 Oct 2026 15:33:31 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 63B504055B; Thu, 8 Oct 2026 15:45:27 +0800 (CST) Received: from [10.67.110.68] (10.67.110.68) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Thu, 8 Oct 2026 15:45:26 +0800 Message-ID: Date: Thu, 8 Oct 2026 15:45:25 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 05/21] KVM: arm64: Protect TPIDRRO_EL0 across guest entry/exit To: Will Deacon , References: <20260918161407.2300-1-will@kernel.org> <20260918161407.2300-6-will@kernel.org> From: Jinjie Ruan In-Reply-To: <20260918161407.2300-6-will@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.68] X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261008_004535_353653_FAC6423B X-CRM114-Status: GOOD ( 16.64 ) 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: , Cc: Mark Rutland , Vladimir Murzin , Arnd Bergmann , Catalin Marinas , Linus Walleij , linux-kernel@vger.kernel.org, Mostafa Saleh , Marc Zyngier , David Hildenbrand , Lorenzo Stoakes , Oliver Upton , Ard Biesheuvel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 在 2026/9/19 0:13, Will Deacon 写道: > From: Mostafa Saleh > > To prepare for using TPIDRRO_EL0 to hold 'current' and repurposing > SP_EL0 as an overflow stack pointer, eagerly switch both registers when > entering and exiting the guest. > > Signed-off-by: Mostafa Saleh > Signed-off-by: Will Deacon > --- > arch/arm64/include/asm/kvm_asm.h | 10 ++++++++++ > arch/arm64/kernel/asm-offsets.c | 1 + > arch/arm64/kvm/hyp/entry.S | 12 ++++++++---- > arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 2 -- > 4 files changed, 19 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index e5b92ac09e69..1cfe9216a2ff 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -408,6 +408,16 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr_virt, > msr sp_el0, \tmp > .endm > > +.macro save_tpidrro_el0 ctxt, tmp > + mrs \tmp, tpidrro_el0 > + str \tmp, [\ctxt, #CPU_TPIDRRO_EL0_OFFSET] > +.endm > + > +.macro restore_tpidrro_el0 ctxt, tmp > + ldr \tmp, [\ctxt, #CPU_TPIDRRO_EL0_OFFSET] > + msr tpidrro_el0, \tmp > +.endm > + > #endif > > #endif /* __ARM_KVM_ASM_H__ */ > diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c > index 6038ab3beb25..cb8448cc5f51 100644 > --- a/arch/arm64/kernel/asm-offsets.c > +++ b/arch/arm64/kernel/asm-offsets.c > @@ -108,6 +108,7 @@ int main(void) > DEFINE(VCPU_HCR_EL2, offsetof(struct kvm_vcpu, arch.hcr_el2)); > DEFINE(CPU_USER_PT_REGS, offsetof(struct kvm_cpu_context, regs)); > DEFINE(CPU_ELR_EL2, offsetof(struct kvm_cpu_context, sys_regs[ELR_EL2])); > + DEFINE(CPU_TPIDRRO_EL0_OFFSET, offsetof(struct kvm_cpu_context, sys_regs[TPIDRRO_EL0])); > DEFINE(CPU_RGSR_EL1, offsetof(struct kvm_cpu_context, sys_regs[RGSR_EL1])); > DEFINE(CPU_GCR_EL1, offsetof(struct kvm_cpu_context, sys_regs[GCR_EL1])); > DEFINE(CPU_APIAKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APIAKEYLO_EL1])); > diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S > index 308100ed25de..4c89931a6a92 100644 > --- a/arch/arm64/kvm/hyp/entry.S > +++ b/arch/arm64/kvm/hyp/entry.S > @@ -30,8 +30,9 @@ SYM_FUNC_START(__guest_enter) > // Store the hyp regs > save_callee_saved_regs x1 > > - // Save hyp's sp_el0 > + // Save hyp's sp_el0 and tpidrro_el0 > save_sp_el0 x1, x2 > + save_tpidrro_el0 x1, x2 > > // Now the hyp state is stored if we have a pending RAS SError it must > // affect the host or hyp. If any asynchronous exception is pending we > @@ -66,8 +67,9 @@ alternative_else_nop_endif > // when this feature is enabled for kernel code. > ptrauth_switch_to_guest x29, x0, x1, x2 > > - // Restore the guest's sp_el0 > + // Restore the guest's sp_el0 and tpidrro_el0 > restore_sp_el0 x29, x0 > + restore_tpidrro_el0 x29, x0 > > // Restore guest regs x0-x17 > ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] > @@ -146,8 +148,9 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) > // Store the guest regs x18-x29, lr > save_callee_saved_regs x1 > > - // Store the guest's sp_el0 > + // Store the guest's sp_el0 and tpidrro_el0 > save_sp_el0 x1, x2 > + save_tpidrro_el0 x1, x2 > > adr_this_cpu x2, kvm_hyp_ctxt, x3 > > @@ -161,8 +164,9 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) > // mte_switch_to_hyp(g_ctxt, h_ctxt, reg1) > mte_switch_to_hyp x1, x2, x3 > > - // Restore hyp's sp_el0 > + // Restore hyp's sp_el0 and tpidrro_el0 > restore_sp_el0 x2, x3 > + restore_tpidrro_el0 x2, x3 Reviewed-by: Jinjie Ruan > > // Now restore the hyp regs > restore_callee_saved_regs x2 > diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > index c382848d3194..b5f7ef8e6371 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > @@ -66,7 +66,6 @@ static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) > static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) > { > ctxt_sys_reg(ctxt, TPIDR_EL0) = read_sysreg(tpidr_el0); > - ctxt_sys_reg(ctxt, TPIDRRO_EL0) = read_sysreg(tpidrro_el0); > } > > static inline bool ctxt_has_mte(struct kvm_cpu_context *ctxt) > @@ -209,7 +208,6 @@ static inline void __sysreg_restore_common_state(struct kvm_cpu_context *ctxt) > static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctxt) > { > write_sysreg(ctxt_sys_reg(ctxt, TPIDR_EL0), tpidr_el0); > - write_sysreg(ctxt_sys_reg(ctxt, TPIDRRO_EL0), tpidrro_el0); > } > > static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt, -- Best regards, Jinjie