From nobody Wed Dec 31 09:01:06 2025 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 2350CC4167D for ; Sun, 5 Nov 2023 21:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjKEVhw (ORCPT ); Sun, 5 Nov 2023 16:37:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjKEVhq (ORCPT ); Sun, 5 Nov 2023 16:37:46 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D02CF for ; Sun, 5 Nov 2023 13:37:44 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5437d60fb7aso6367781a12.3 for ; Sun, 05 Nov 2023 13:37:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699220262; x=1699825062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=diDfHIDfGzS7c9D5uSx32GZFst0D3sZaoS/knnykPTI=; b=aD2/r9nXgwm+9xCoRq8kBwt492FoNlaj7r7AGqiuV6bMETq969Sr1i5qjv3RP/WHKo iTty/iZ18yEw03/6NubkAL9iMpVxH9Y09SJOqbWfm4oi/hD9eIusJAT8hoqrOooc0Luw t0FEefT89M0LRk34JVa3TBisoe4c/m3hbBPu9El4R5uaY65tcolH2MMuvjI1XlpfHs8K GelxEleqG/n/TbyXiSVD7Y/waIH24M5VqZXijqIqvXarMKlz368/pWXdUIhIvX36gfcQ 66x2bsrYXoGqTFptMN1aWJVopMvuVLCrSAXUKCVcUi/VLFghmuDsXuARZ+8h4JYk9PX6 k/GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699220262; x=1699825062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=diDfHIDfGzS7c9D5uSx32GZFst0D3sZaoS/knnykPTI=; b=kHrx7E5deiGBGRlWS67A5GfzOXpLF2oxXA3Fqty1pDjf/r9suxoKvwuh4G/GEHch7l c4Sq5uScR3AGJCwUMBdipYszwkkWiiEGWWJ3LH3vq0pBNmOmvs1tVLXjsmBzwHx/kXph 4VPPbjCTzxhwBbZt5DlVzHsPxoHNyzGzE21bIm+aEQtwLuEX6e4HxdFze9Nv6dlCsce0 wd6E7jKYwxKWcE+G882qZd/SH1iBTMXgaj6FpyyMKxlX1atkYql1gImWWhYycPS74Z6E G5usL9L12vd2hVB7CA5sWpKv4lvg2jGFMTdAk/II0mDGbMYO2o8+7p210jHFEg1Ou7jQ UyIg== X-Gm-Message-State: AOJu0Yz+azVQ4zc/hXNh0ZN+piGyIjUZcEZcvgEy3zhcTG3LkTps33LV Ho6rZBA9kEorYrhLOUsMd4c= X-Google-Smtp-Source: AGHT+IFVOadnmL/alBy4c8y9RNvZMi65oYx/lDUJpauY31a3sEHQxWYTV3iLLMF7XHncpdkiJR/ZXg== X-Received: by 2002:a17:907:96a7:b0:9c3:b3cb:29b8 with SMTP id hd39-20020a17090796a700b009c3b3cb29b8mr13422705ejc.0.1699220262378; Sun, 05 Nov 2023 13:37:42 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id g23-20020a1709064e5700b009c5c5c2c5a4sm3386559ejw.219.2023.11.05.13.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 13:37:42 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH -tip v2 1/3] x86/percpu: Define PER_CPU_VAR macro also for !__ASSEMBLY__ Date: Sun, 5 Nov 2023 22:34:35 +0100 Message-ID: <20231105213731.1878100-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231105213731.1878100-1-ubizjak@gmail.com> References: <20231105213731.1878100-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some C source files define 'asm' statements that use PER_CPU_VAR, so make PER_CPU_VAR macro available also without __ASSEMBLY__. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Signed-off-by: Uros Bizjak --- v2: Make PER_CPU_VAR macro available in 'asm' statements instead of moving 'asm' statements to *.S assembly files. --- arch/x86/include/asm/percpu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index b86b27d15e52..0f12b2004b94 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -84,10 +84,15 @@ }) #endif /* CONFIG_USE_X86_SEG_SUPPORT */ =20 +#define PER_CPU_VAR(var) %__percpu_seg:(var)__percpu_rel + #else /* CONFIG_SMP */ #define __percpu_seg_override #define __percpu_prefix "" #define __force_percpu_prefix "" + +#define PER_CPU_VAR(var) (var)__percpu_rel + #endif /* CONFIG_SMP */ =20 #define __my_cpu_type(var) typeof(var) __percpu_seg_override --=20 2.41.0 From nobody Wed Dec 31 09:01:06 2025 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 14A77C4332F for ; Sun, 5 Nov 2023 21:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbjKEVhy (ORCPT ); Sun, 5 Nov 2023 16:37:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjKEVhs (ORCPT ); Sun, 5 Nov 2023 16:37:48 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FDEFCC for ; Sun, 5 Nov 2023 13:37:45 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5437269a661so9636179a12.0 for ; Sun, 05 Nov 2023 13:37:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699220264; x=1699825064; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QWoTXFWh8QhoMIOAEXcP9Z3H1Z7HK9iPUfGCUZ9d8xA=; b=kfP3BLMj31VbHR5yLGP2TgI5Qrcfh6F268pJAznApGtPiHxDAO1AdFewCgqoNsYK+2 q+jdoou+hqBYW0Hc2sNBeWIMZmq4FTly6B7XQgbEa/pSgkWrsbgjoAMjlm5namqLS4vL A0Kfizk2wAlOlT1WVH5ur6lXFp9P6dEZ9o+eFEUdeZcvrvP4ZWt5MMeJaA008BeIJrFt MFQfbNL4TXSuxjf5kVMb4H7ap1P0LVGLuxmqePzhaTt7eTsHBJLp9BDoCMgZ1RUZuXWx nwjJxBrVgGWNsuFYPUHXk4RAbolnnhHj0BxFEUmjEmKk7MbTmQdidIFinJC/sY1wmE+t oCvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699220264; x=1699825064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QWoTXFWh8QhoMIOAEXcP9Z3H1Z7HK9iPUfGCUZ9d8xA=; b=hddOKAB9W31mHWdDXU3IHKZL9wmi7fnwoPw7P3nGwwSzcFS9fvs78xS1muBxSjJVLt n+uGSC94pg6GmmuMpgApi51/pCzBdXZ3C9NILofahsskTESM8Uy4MQCVWxduvLgm+jaK JK8/TsPrsGxd7g5a51AVNgvlnoomJVOCOiS7lD35HGB8/jrbJgqS+R2czHv3zgQlA1tn z6yKUq6kM4a4d+LzCfe2K4f90z9GJq5jB3TUtiztHo3lzFb1oZx7Y77zM4+YfqB02+P4 ZmyPUW2eFAMPmEVpbBnSuhsQzlGHc1Nkhss8+qSxJf09JzIO5Lk3TRIdWAAj6Bvty9w8 Ux0w== X-Gm-Message-State: AOJu0Yw1rsz2gXcHfU9GLT6BZQ0ndrVKCTtby3JGr1QSykk46Hrh9QJU xEE+SpBxqua0jCupCkmy+6Y= X-Google-Smtp-Source: AGHT+IGyuFhdDqaEX51WwdMsmORV8JuNrCfbBLptM4ba0fIP9R5uSRLc3pqGrspyQbkr2ACSwX0kDQ== X-Received: by 2002:a17:907:e8d:b0:9de:9ecb:eb03 with SMTP id ho13-20020a1709070e8d00b009de9ecbeb03mr4469048ejc.33.1699220263848; Sun, 05 Nov 2023 13:37:43 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id g23-20020a1709064e5700b009c5c5c2c5a4sm3386559ejw.219.2023.11.05.13.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 13:37:42 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH -tip v2 2/3] x86/callthunks: Handle %rip-relative relocations in call thunk template Date: Sun, 5 Nov 2023 22:34:36 +0100 Message-ID: <20231105213731.1878100-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231105213731.1878100-1-ubizjak@gmail.com> References: <20231105213731.1878100-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Contrary to alternatives, relocations are currently not supported in call thunk templates. Re-use the existing infrastructure from alternative.c to allow %rip-relative relocations when copying call thunk template from its storage location. The patch allows unification of ASM_INCREMENT_CALL_DEPTH, which already uses PER_CPU_VAR macro, with INCREMENT_CALL_DEPTH, used in call thunk template, which is currently limited to use absolute address. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Signed-off-by: Uros Bizjak --- v2: Reuse existing relocation infrastructure from alternative.c. --- arch/x86/include/asm/text-patching.h | 2 ++ arch/x86/kernel/alternative.c | 3 +-- arch/x86/kernel/callthunks.c | 32 ++++++++++++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 29832c338cdc..ba8d900f3ebe 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -18,6 +18,8 @@ static inline void apply_paravirt(struct paravirt_patch_s= ite *start, #define __parainstructions_end NULL #endif =20 +void apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src, size_t src_l= en); + /* * Currently, the max observed size in the kernel code is * JUMP_LABEL_NOP_SIZE/RELATIVEJUMP_SIZE, which are 5. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 73be3931e4f0..66140c54d4f6 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -325,8 +325,7 @@ bool need_reloc(unsigned long offset, u8 *src, size_t s= rc_len) return (target < src || target > src + src_len); } =20 -static void __init_or_module noinline -apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src, size_t src_len) +void apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src, size_t src_l= en) { int prev, target =3D 0; =20 diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c index e9ad518a5003..ef9c04707b3c 100644 --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -24,6 +24,8 @@ =20 static int __initdata_or_module debug_callthunks; =20 +#define MAX_PATCH_LEN (255-1) + #define prdbg(fmt, args...) \ do { \ if (debug_callthunks) \ @@ -179,10 +181,15 @@ static const u8 nops[] =3D { static void *patch_dest(void *dest, bool direct) { unsigned int tsize =3D SKL_TMPL_SIZE; + u8 insn_buff[MAX_PATCH_LEN]; u8 *pad =3D dest - tsize; =20 + memcpy(insn_buff, skl_call_thunk_template, tsize); + apply_relocation(insn_buff, tsize, pad, + skl_call_thunk_template, tsize); + /* Already patched? */ - if (!bcmp(pad, skl_call_thunk_template, tsize)) + if (!bcmp(pad, insn_buff, tsize)) return pad; =20 /* Ensure there are nops */ @@ -192,9 +199,9 @@ static void *patch_dest(void *dest, bool direct) } =20 if (direct) - memcpy(pad, skl_call_thunk_template, tsize); + memcpy(pad, insn_buff, tsize); else - text_poke_copy_locked(pad, skl_call_thunk_template, tsize, true); + text_poke_copy_locked(pad, insn_buff, tsize, true); return pad; } =20 @@ -291,20 +298,27 @@ void *callthunks_translate_call_dest(void *dest) static bool is_callthunk(void *addr) { unsigned int tmpl_size =3D SKL_TMPL_SIZE; - void *tmpl =3D skl_call_thunk_template; + u8 insn_buff[MAX_PATCH_LEN]; unsigned long dest; + u8 *pad; =20 dest =3D roundup((unsigned long)addr, CONFIG_FUNCTION_ALIGNMENT); if (!thunks_initialized || skip_addr((void *)dest)) return false; =20 - return !bcmp((void *)(dest - tmpl_size), tmpl, tmpl_size); + *pad =3D dest - tmpl_size; + + memcpy(insn_buff, skl_call_thunk_template, tmpl_size); + apply_relocation(insn_buff, tmpl_size, pad, + skl_call_thunk_template, tmpl_size); + + return !bcmp(pad, insn_buff, tmpl_size); } =20 int x86_call_depth_emit_accounting(u8 **pprog, void *func) { unsigned int tmpl_size =3D SKL_TMPL_SIZE; - void *tmpl =3D skl_call_thunk_template; + u8 insn_buff[MAX_PATCH_LEN]; =20 if (!thunks_initialized) return 0; @@ -313,7 +327,11 @@ int x86_call_depth_emit_accounting(u8 **pprog, void *f= unc) if (func && is_callthunk(func)) return 0; =20 - memcpy(*pprog, tmpl, tmpl_size); + memcpy(insn_buff, skl_call_thunk_template, tmpl_size); + apply_relocation(insn_buff, tmpl_size, *pprog, + skl_call_thunk_template, tmpl_size); + + memcpy(*pprog, insn_buff, tmpl_size); *pprog +=3D tmpl_size; return tmpl_size; } --=20 2.41.0 From nobody Wed Dec 31 09:01:06 2025 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 27739C4332F for ; Sun, 5 Nov 2023 21:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbjKEVh6 (ORCPT ); Sun, 5 Nov 2023 16:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjKEVht (ORCPT ); Sun, 5 Nov 2023 16:37:49 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51066CF for ; Sun, 5 Nov 2023 13:37:46 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ae2cc4d17eso586104166b.1 for ; Sun, 05 Nov 2023 13:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699220265; x=1699825065; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tgAqePGVhUCu3U56kTFLSJugpfg6qt/lSZ7uytS2Gf4=; b=beN4WwOD5FVwnUp8UIdN4MM/fbIPFd7Z5y1dDuuF0fgIrBdq3bhAMHdF+l77ltYJ79 x+18nDszzq9cFePvqiBWqncGzsDff8Bkr/JkODmWZPu0qXo24n1luWcSSUdcHK7G4gWz 60guZ8EIP0tyCm184ZwbH/2RPcEL4AMOvux0RdpVMA3di1iznqUOfYBI1Ew82ylHlxAT sA5y+7TU2UpTNLsbo1ETR7KqvDuw5lv/6ET20VDmIQ9M4p6F0M6cuXdyeEopYuI+nZ6F 5AlbWtqIlLdP9Q/JGbouIMRtXu7Bj68kT2Xo5iw/GHG0uU5arY5SUk36coK98WSnEp4H ZnSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699220265; x=1699825065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tgAqePGVhUCu3U56kTFLSJugpfg6qt/lSZ7uytS2Gf4=; b=MQB8K0xi0UqBO8/s4FORXUbpeXLwXzw9w+BIB0CJKJuDUceyxmukLxyz5Ih1yIxY76 oT+9w5w93ESp7v7ZbI/zAPNcDBoxp8aADVDyH1gXibJFbwOgH9jzy7ZzY58t4hKihR00 FucmyLBnrtJshwIIzWvAq/MPn6Pqngm6qTCjEZtWl8kLxM+HvYiKsUphT3KTpt0r1uUM 2KJjl3msn0bL/tY1emwHxe3ydD2q/55DgHbQlLnYPrYcEEzRdzxbxC6Kn9LPBY0+keWr l/Aq0kCL3KcKLm7RpzW1TOO2lSlNVZLYrO5n8thmbhZF5P72mDBFyJGXuG11QXp5Un/K 6qZA== X-Gm-Message-State: AOJu0Yz5jicpIgAD27qIxQ2t3QCoQG94a250AZCQgVpfgpUIEH79GSTk U0OJ37vW+Iuo325+X3ZHBd8= X-Google-Smtp-Source: AGHT+IEF2ldJdGcZVoPUorSjwHeNACRqRBtR/1vAQ2Y2jzwokkjTG5dZddGUTHREoRFo8Un1Uqn5WA== X-Received: by 2002:a17:907:c313:b0:9bd:e3ae:ef57 with SMTP id tl19-20020a170907c31300b009bde3aeef57mr12829693ejc.60.1699220264570; Sun, 05 Nov 2023 13:37:44 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id g23-20020a1709064e5700b009c5c5c2c5a4sm3386559ejw.219.2023.11.05.13.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 13:37:44 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH -tip v2 3/3] x86/callthunks: Fix and unify call thunks assembly snippets Date: Sun, 5 Nov 2023 22:34:37 +0100 Message-ID: <20231105213731.1878100-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231105213731.1878100-1-ubizjak@gmail.com> References: <20231105213731.1878100-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently thunk debug macros explicitly define %gs: segment register prefix for their percpu variables. This is not compatible with !CONFIG_SMP, which requires non-prefixed percpu variables. Fix call thunks debug macros to use PER_CPU_VAR macro from percpu.h to conditionally use %gs: segment register prefix, depending on CONFIG_SMP. Finally, unify ASM_ prefixed assembly macros with their non-prefixed variants. With support of %rip-relative relocations in place, call thunk templates allow %rip-relative addressing, so unified assembly snippet can be used everywhere. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Signed-off-by: Uros Bizjak --- arch/x86/include/asm/nospec-branch.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/no= spec-branch.h index f93e9b96927a..6f677be6bdb9 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -59,13 +59,13 @@ =20 #ifdef CONFIG_CALL_THUNKS_DEBUG # define CALL_THUNKS_DEBUG_INC_CALLS \ - incq %gs:__x86_call_count; + incq PER_CPU_VAR(__x86_call_count); # define CALL_THUNKS_DEBUG_INC_RETS \ - incq %gs:__x86_ret_count; + incq PER_CPU_VAR(__x86_ret_count); # define CALL_THUNKS_DEBUG_INC_STUFFS \ - incq %gs:__x86_stuffs_count; + incq PER_CPU_VAR(__x86_stuffs_count); # define CALL_THUNKS_DEBUG_INC_CTXSW \ - incq %gs:__x86_ctxsw_count; + incq PER_CPU_VAR(__x86_ctxsw_count); #else # define CALL_THUNKS_DEBUG_INC_CALLS # define CALL_THUNKS_DEBUG_INC_RETS @@ -80,9 +80,6 @@ #define CREDIT_CALL_DEPTH \ movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); =20 -#define ASM_CREDIT_CALL_DEPTH \ - movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); - #define RESET_CALL_DEPTH \ xor %eax, %eax; \ bts $63, %rax; \ @@ -95,20 +92,14 @@ CALL_THUNKS_DEBUG_INC_CALLS =20 #define INCREMENT_CALL_DEPTH \ - sarq $5, %gs:pcpu_hot + X86_call_depth; \ - CALL_THUNKS_DEBUG_INC_CALLS - -#define ASM_INCREMENT_CALL_DEPTH \ sarq $5, PER_CPU_VAR(pcpu_hot + X86_call_depth); \ CALL_THUNKS_DEBUG_INC_CALLS =20 #else #define CREDIT_CALL_DEPTH -#define ASM_CREDIT_CALL_DEPTH #define RESET_CALL_DEPTH -#define INCREMENT_CALL_DEPTH -#define ASM_INCREMENT_CALL_DEPTH #define RESET_CALL_DEPTH_FROM_CALL +#define INCREMENT_CALL_DEPTH #endif =20 /* @@ -158,7 +149,7 @@ jnz 771b; \ /* barrier for jnz misprediction */ \ lfence; \ - ASM_CREDIT_CALL_DEPTH \ + CREDIT_CALL_DEPTH \ CALL_THUNKS_DEBUG_INC_CTXSW #else /* @@ -311,7 +302,7 @@ .macro CALL_DEPTH_ACCOUNT #ifdef CONFIG_CALL_DEPTH_TRACKING ALTERNATIVE "", \ - __stringify(ASM_INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH + __stringify(INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH #endif .endm =20 --=20 2.41.0