From nobody Mon Jun 22 23:42:22 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C756AC43217 for ; Tue, 15 Mar 2022 10:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347928AbiCOKsm (ORCPT ); Tue, 15 Mar 2022 06:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347334AbiCOKpm (ORCPT ); Tue, 15 Mar 2022 06:45:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2EC850E0E; Tue, 15 Mar 2022 03:44:11 -0700 (PDT) Date: Tue, 15 Mar 2022 10:44:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647341050; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QgaMfQDGmB6xa61c4iPZF7xI7f6FpOAdAEy4Yeycf3s=; b=15Ez6qvDl107ftVmhHZncGkh29Ticvj4C5PsZfSyjwCoUO9aJziYrswg/47TNVh5BGjSq9 4rtjlpMsq1N7ODNukm2j+cOjUbbzrHn0MgYblaruCOlt+HX/7BEwi4JRketNUSFg9HE2Bl b3Oo0PvIO6fq+tPTo1CUgPniZgvBL/i730FUi/kABNp76dIXz2RmNQkgmf4C3hMD1lCJ1p AS6XzBo6P2o5dwV3XBtFmCalzGe/7ziRWror8Ts2qJbz8TCF2XiSp5gAZyWU5FHDipxmfQ QbdOQBOtXBj9eHLKj5Oog+2BIf7fLP1tExtCWLmw8v7Oe4biM+glu5qrBoyDKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647341050; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QgaMfQDGmB6xa61c4iPZF7xI7f6FpOAdAEy4Yeycf3s=; b=YMf8RbhluRsEdrLCPbG1MWiEiCotPPqXcT21q2iAJInf9m0MkrGGb6GTXb6nICvNK/TTiN XiLZwZKtC+Lg7HCA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/entry,xen: Early rewrite of restore_regs_and_return_to_kernel() Cc: Andrew Cooper , "Peter Zijlstra (Intel)" , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220308154317.815039833@infradead.org> References: <20220308154317.815039833@infradead.org> MIME-Version: 1.0 Message-ID: <164734104900.16921.17841903225328689530.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: 8b87d8cec1b31ea710568ae49ba5f5146318da0d Gitweb: https://git.kernel.org/tip/8b87d8cec1b31ea710568ae49ba5f5146= 318da0d Author: Peter Zijlstra AuthorDate: Tue, 08 Mar 2022 16:30:22 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 15 Mar 2022 10:32:34 +01:00 x86/entry,xen: Early rewrite of restore_regs_and_return_to_kernel() By doing an early rewrite of 'jmp native_iret` in restore_regs_and_return_to_kernel() we can get rid of the last INTERRUPT_RETURN user and paravirt_iret. Suggested-by: Andrew Cooper Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220308154317.815039833@infradead.org --- arch/x86/entry/entry_64.S | 11 ++++++++--- arch/x86/include/asm/irqflags.h | 5 ----- arch/x86/include/asm/paravirt_types.h | 1 - arch/x86/kernel/head_64.S | 3 ++- arch/x86/kernel/paravirt.c | 4 ---- arch/x86/xen/enlighten_pv.c | 7 ++++++- arch/x86/xen/xen-asm.S | 1 + 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 22e4e9a..f731393 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -609,7 +609,7 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_userm= ode, SYM_L_GLOBAL) /* Restore RDI. */ popq %rdi swapgs - jmp native_iret + jmp .Lnative_iret =20 =20 SYM_INNER_LABEL(restore_regs_and_return_to_kernel, SYM_L_GLOBAL) @@ -626,9 +626,14 @@ SYM_INNER_LABEL(restore_regs_and_return_to_kernel, SYM= _L_GLOBAL) * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization * when returning from IPI handler. */ - INTERRUPT_RETURN +#ifdef CONFIG_XEN_PV +SYM_INNER_LABEL(early_xen_iret_patch, SYM_L_GLOBAL) + ANNOTATE_NOENDBR + .byte 0xe9 + .long .Lnative_iret - (. + 4) +#endif =20 -SYM_INNER_LABEL_ALIGN(native_iret, SYM_L_GLOBAL) +.Lnative_iret: UNWIND_HINT_IRET_REGS /* * Are we returning to a stack segment from the LDT? Note: in diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflag= s.h index 8776139..111104d 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -141,13 +141,8 @@ static __always_inline void arch_local_irq_restore(uns= igned long flags) #ifdef CONFIG_X86_64 #ifdef CONFIG_XEN_PV #define SWAPGS ALTERNATIVE "swapgs", "", X86_FEATURE_XENPV -#define INTERRUPT_RETURN \ - ANNOTATE_RETPOLINE_SAFE; \ - ALTERNATIVE_TERNARY("jmp *paravirt_iret(%rip);", \ - X86_FEATURE_XENPV, "jmp xen_iret;", "jmp native_iret;") #else #define SWAPGS swapgs -#define INTERRUPT_RETURN jmp native_iret #endif #endif #endif /* !__ASSEMBLY__ */ diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/p= aravirt_types.h index a69012e..7cd2874 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -272,7 +272,6 @@ struct paravirt_patch_template { =20 extern struct pv_info pv_info; extern struct paravirt_patch_template pv_ops; -extern void (*paravirt_iret)(void); =20 #define PARAVIRT_PATCH(x) \ (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 9c63fc5..023761c 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -345,7 +345,6 @@ SYM_CODE_START_NOALIGN(vc_boot_ghcb) /* Remove Error Code */ addq $8, %rsp =20 - /* Pure iret required here - don't use INTERRUPT_RETURN */ iretq SYM_CODE_END(vc_boot_ghcb) #endif @@ -426,6 +425,8 @@ SYM_CODE_END(early_idt_handler_common) * early_idt_handler_array can't be used because it returns via the * paravirtualized INTERRUPT_RETURN and pv-ops don't work that early. * + * XXX it does, fix this. + * * This handler will end up in the .init.text section and not be * available to boot secondary CPUs. */ diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 06af2cf..6ecbbb0 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -132,8 +132,6 @@ void paravirt_set_sched_clock(u64 (*func)(void)) } =20 /* These are in entry.S */ -extern void native_iret(void); - static struct resource reserve_ioports =3D { .start =3D 0, .end =3D IO_SPACE_LIMIT, @@ -397,8 +395,6 @@ struct paravirt_patch_template pv_ops =3D { =20 #ifdef CONFIG_PARAVIRT_XXL NOKPROBE_SYMBOL(native_load_idt); - -void (*paravirt_iret)(void) =3D native_iret; #endif =20 EXPORT_SYMBOL(pv_ops); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index d47c3d1..3c7a55c 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1177,6 +1177,8 @@ static void __init xen_domu_set_legacy_features(void) x86_platform.legacy.rtc =3D 0; } =20 +extern void early_xen_iret_patch(void); + /* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) { @@ -1187,6 +1189,10 @@ asmlinkage __visible void __init xen_start_kernel(vo= id) if (!xen_start_info) return; =20 + __text_gen_insn(&early_xen_iret_patch, + JMP32_INSN_OPCODE, &early_xen_iret_patch, &xen_iret, + JMP32_INSN_SIZE); + xen_domain_type =3D XEN_PV_DOMAIN; xen_start_flags =3D xen_start_info->flags; =20 @@ -1195,7 +1201,6 @@ asmlinkage __visible void __init xen_start_kernel(voi= d) /* Install Xen paravirt ops */ pv_info =3D xen_info; pv_ops.cpu =3D xen_cpu_ops.cpu; - paravirt_iret =3D xen_iret; xen_init_irq_ops(); =20 /* diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S index e730e62..ee17b94 100644 --- a/arch/x86/xen/xen-asm.S +++ b/arch/x86/xen/xen-asm.S @@ -189,6 +189,7 @@ hypercall_iret =3D hypercall_page + __HYPERVISOR_iret *= 32 */ SYM_CODE_START(xen_iret) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR pushq $0 jmp hypercall_iret SYM_CODE_END(xen_iret)