From nobody Mon Jun 22 23:41:37 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 7C456C433EF for ; Tue, 15 Mar 2022 10:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347856AbiCOKsQ (ORCPT ); Tue, 15 Mar 2022 06:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347244AbiCOKpv (ORCPT ); Tue, 15 Mar 2022 06:45:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF4F50E3E; Tue, 15 Mar 2022 03:44:13 -0700 (PDT) Date: Tue, 15 Mar 2022 10:44:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647341051; 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=QKm8bnnr+rW/jkTW5jITWcTDsplyawMvoVH4+3yWbVI=; b=jKn06OsmQHktFyw+cl4B34KhIbAzxHgB8e8cp9lrWxASIPsq4hhlyAA8PJ3WLYiwwJFdxQ p7c1QmLs1o6vQl9jdr38MpnweRNnLIb4tLWkmARnJLMHciEU/HM2rNW+1ILk6hMPLj5Y9W teQIQ0EFCjzcPyBfQOHJzPHqiJXXMBpzWJhWvH5cRSjtPt6mWnmlHLHvqBuQLnRpRkYH6F zvXhKwa0l1myPdjbyu8hAqPWKkQm0t3SFzp03pRungjM8q4RCUzRBzeJX09jrtqcW3bIOa ODRAUmX84igtFVCwkNCXwUpDhHiUR4aSXmdLnw3zhSyiMSDNWseaJwAY3N1kdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647341051; 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=QKm8bnnr+rW/jkTW5jITWcTDsplyawMvoVH4+3yWbVI=; b=FjrTUpKaclw9y2LhrIrj0tusTydoGVC98eyBU22T7I+p9QxlmP5KZW6pUwtCEhB32WpxSu EH2YVy+5v+v7a+CA== 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/ibt,paravirt: Use text_gen_insn() for paravirt_patch() Cc: "Peter Zijlstra (Intel)" , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220308154317.697253958@infradead.org> References: <20220308154317.697253958@infradead.org> MIME-Version: 1.0 Message-ID: <164734105064.16921.15259204948431866651.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: ba27d1a80871eb8dbeddf34ec7d396c149cbb8d7 Gitweb: https://git.kernel.org/tip/ba27d1a80871eb8dbeddf34ec7d396c14= 9cbb8d7 Author: Peter Zijlstra AuthorDate: Tue, 08 Mar 2022 16:30:20 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 15 Mar 2022 10:32:34 +01:00 x86/ibt,paravirt: Use text_gen_insn() for paravirt_patch() Less duplication is more better. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220308154317.697253958@infradead.org --- arch/x86/include/asm/text-patching.h | 20 ++++++++++++++------ arch/x86/kernel/paravirt.c | 23 +++-------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 1c4cfb1..c6015b4 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -96,32 +96,40 @@ union text_poke_insn { }; =20 static __always_inline -void *text_gen_insn(u8 opcode, const void *addr, const void *dest) +void __text_gen_insn(void *buf, u8 opcode, const void *addr, const void *d= est, int size) { - static union text_poke_insn insn; /* per instance */ - int size =3D text_opcode_size(opcode); + union text_poke_insn *insn =3D buf; + + BUG_ON(size < text_opcode_size(opcode)); =20 /* * Hide the addresses to avoid the compiler folding in constants when * referencing code, these can mess up annotations like * ANNOTATE_NOENDBR. */ + OPTIMIZER_HIDE_VAR(insn); OPTIMIZER_HIDE_VAR(addr); OPTIMIZER_HIDE_VAR(dest); =20 - insn.opcode =3D opcode; + insn->opcode =3D opcode; =20 if (size > 1) { - insn.disp =3D (long)dest - (long)(addr + size); + insn->disp =3D (long)dest - (long)(addr + size); if (size =3D=3D 2) { /* * Ensure that for JMP8 the displacement * actually fits the signed byte. */ - BUG_ON((insn.disp >> 31) !=3D (insn.disp >> 7)); + BUG_ON((insn->disp >> 31) !=3D (insn->disp >> 7)); } } +} =20 +static __always_inline +void *text_gen_insn(u8 opcode, const void *addr, const void *dest) +{ + static union text_poke_insn insn; /* per instance */ + __text_gen_insn(&insn, opcode, addr, dest, text_opcode_size(opcode)); return &insn.text; } =20 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 4420499..06af2cf 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -69,29 +69,12 @@ noinstr void paravirt_BUG(void) BUG(); } =20 -struct branch { - unsigned char opcode; - u32 delta; -} __attribute__((packed)); - static unsigned paravirt_patch_call(void *insn_buff, const void *target, unsigned long addr, unsigned len) { - const int call_len =3D 5; - struct branch *b =3D insn_buff; - unsigned long delta =3D (unsigned long)target - (addr+call_len); - - if (len < call_len) { - pr_warn("paravirt: Failed to patch indirect CALL at %ps\n", (void *)addr= ); - /* Kernel might not be viable if patching fails, bail out: */ - BUG_ON(1); - } - - b->opcode =3D 0xe8; /* call */ - b->delta =3D delta; - BUILD_BUG_ON(sizeof(*b) !=3D call_len); - - return call_len; + __text_gen_insn(insn_buff, CALL_INSN_OPCODE, + (void *)addr, target, CALL_INSN_SIZE); + return CALL_INSN_SIZE; } =20 #ifdef CONFIG_PARAVIRT_XXL