From nobody Fri May 17 07:55:52 2024 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 7F910CDB47E for ; Thu, 12 Oct 2023 20:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442691AbjJLUSF (ORCPT ); Thu, 12 Oct 2023 16:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343828AbjJLUSA (ORCPT ); Thu, 12 Oct 2023 16:18:00 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDFFEBB for ; Thu, 12 Oct 2023 13:17:56 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso227739766b.2 for ; Thu, 12 Oct 2023 13:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697141875; x=1697746675; 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=dP3aL79sYs1c4BQa/blYah2PDJJ2vnSgtty8PYNApno=; b=OBT+JQwUiTaaewIJOAP8bA/+OUrV5fINBa6qSsFmrEtVpBM26wwelwIH96gPAVMzFp 6Y5wjg5KpnX4eOkpCozcTlPSSzskM7X51/eFC61KtpVYdBcL5TamUmlUPjeNfWZmoKUd lL6fPZfpR2aiuDRFiLtHZGRZwaLqbt/4YtbR2wzfn5WJ6YpF6whl+TCiGNMwDFzXQPHq Kmdu04kKTu7WJast9a1x5GfdzEk5gCzR2M75U7gLxlqMtBjLIV9xnUMft739C7Ay2QLJ oZkMgI7HWgovoXKUaFZJWbffiKaDyIi1t2glat08mScCUqVwWN/86F4WrtxaplJNEOGe KqSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697141875; x=1697746675; 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=dP3aL79sYs1c4BQa/blYah2PDJJ2vnSgtty8PYNApno=; b=TfRmPiIkTNXYoyB5jg/zQiBe3RkWq2VXGy9i31aHRQ6Uo+Tej63ocyCE0cijViAFct iA+r5qt3D7UlgPs1i/yIYHEiDsz1aqraebUnBppVG4boY55qVEoVC7QmiArUM4+GIivr W6DHP2msIOwomRfJSNnNLPVPJDZq5ry5+9YHtPHDnoOMXKmN3E2fAD61achel/qqyGbO GlmC6Vc4oF8TSxVo24XNJ6vSKA3ayT/UW7dThzV1/E0oNmmANDUeh7xYI0D6dG+6IVqB gAuiTIfNlnNvq/tMaNn2hRwhwlgQyr4pKNQNHuNqBmwMa7vbQT6jo44vA3YW+GR6Ggiq QC+Q== X-Gm-Message-State: AOJu0YwPgMftuJN9ftvcpSKPrba11Udc87IDr6AT/Q1tghWOfNiPOybv roesfwY9srXzojK3zzfe4qQ= X-Google-Smtp-Source: AGHT+IELD/QO6fBcwqkcTgyrHC0COQGBYhxDdLfdbjk87Rjg0EnZvIr/K2PKpKW7JQhrL4PcCINltg== X-Received: by 2002:a17:907:c205:b0:9a5:c54f:da1c with SMTP id ti5-20020a170907c20500b009a5c54fda1cmr22823408ejc.47.1697141874988; Thu, 12 Oct 2023 13:17:54 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id i3-20020a1709064ec300b00997d7aa59fasm11692552ejv.14.2023.10.12.13.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 13:17:54 -0700 (PDT) From: Uros Bizjak To: x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH v2 1/4] x86/percpu: Introduce PER_CPU_ARG and use it in cmpxchg{8,16}b_emu.S Date: Thu, 12 Oct 2023 22:12:04 +0200 Message-ID: <20231012201743.292149-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012201743.292149-1-ubizjak@gmail.com> References: <20231012201743.292149-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" PER_CPU_VAR macro is intended to be applied to a symbol and should not be used with general operands. Introduce new PER_CPU_ARG macro and use it in cmpxchg{8,16}b_emu.S instead. PER_CPU_VAR macro will be repurposed for %rip-relative addressing. Also add a missing function comment to this_cpu_cmpxchg8b_emu. No functional changes intended. 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: Introduce PER_CPU_ARG macro to conditionally enable segment registers in cmpxchg{8,16}b_emu.S for CONFIG_SMP. --- arch/x86/include/asm/percpu.h | 2 ++ arch/x86/lib/cmpxchg16b_emu.S | 12 ++++++------ arch/x86/lib/cmpxchg8b_emu.S | 24 ++++++++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 34734d730463..83e6a4bcea38 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -11,8 +11,10 @@ #ifdef __ASSEMBLY__ =20 #ifdef CONFIG_SMP +#define PER_CPU_ARG(arg) %__percpu_seg:arg #define PER_CPU_VAR(var) %__percpu_seg:var #else /* ! SMP */ +#define PER_CPU_ARG(arg) arg #define PER_CPU_VAR(var) var #endif /* SMP */ =20 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S index 6962df315793..b6b942d07a00 100644 --- a/arch/x86/lib/cmpxchg16b_emu.S +++ b/arch/x86/lib/cmpxchg16b_emu.S @@ -23,14 +23,14 @@ SYM_FUNC_START(this_cpu_cmpxchg16b_emu) cli =20 /* if (*ptr =3D=3D old) */ - cmpq PER_CPU_VAR(0(%rsi)), %rax + cmpq PER_CPU_ARG(0(%rsi)), %rax jne .Lnot_same - cmpq PER_CPU_VAR(8(%rsi)), %rdx + cmpq PER_CPU_ARG(8(%rsi)), %rdx jne .Lnot_same =20 /* *ptr =3D new */ - movq %rbx, PER_CPU_VAR(0(%rsi)) - movq %rcx, PER_CPU_VAR(8(%rsi)) + movq %rbx, PER_CPU_ARG(0(%rsi)) + movq %rcx, PER_CPU_ARG(8(%rsi)) =20 /* set ZF in EFLAGS to indicate success */ orl $X86_EFLAGS_ZF, (%rsp) @@ -42,8 +42,8 @@ SYM_FUNC_START(this_cpu_cmpxchg16b_emu) /* *ptr !=3D old */ =20 /* old =3D *ptr */ - movq PER_CPU_VAR(0(%rsi)), %rax - movq PER_CPU_VAR(8(%rsi)), %rdx + movq PER_CPU_ARG(0(%rsi)), %rax + movq PER_CPU_ARG(8(%rsi)), %rdx =20 /* clear ZF in EFLAGS to indicate failure */ andl $(~X86_EFLAGS_ZF), (%rsp) diff --git a/arch/x86/lib/cmpxchg8b_emu.S b/arch/x86/lib/cmpxchg8b_emu.S index 49805257b125..9a0a7feeaf7c 100644 --- a/arch/x86/lib/cmpxchg8b_emu.S +++ b/arch/x86/lib/cmpxchg8b_emu.S @@ -53,18 +53,30 @@ EXPORT_SYMBOL(cmpxchg8b_emu) =20 #ifndef CONFIG_UML =20 +/* + * Emulate 'cmpxchg8b %fs:(%rsi)' + * + * Inputs: + * %esi : memory location to compare + * %eax : low 32 bits of old value + * %edx : high 32 bits of old value + * %ebx : low 32 bits of new value + * %ecx : high 32 bits of new value + * + * Notably this is not LOCK prefixed and is not safe against NMIs + */ SYM_FUNC_START(this_cpu_cmpxchg8b_emu) =20 pushfl cli =20 - cmpl PER_CPU_VAR(0(%esi)), %eax + cmpl PER_CPU_ARG(0(%esi)), %eax jne .Lnot_same2 - cmpl PER_CPU_VAR(4(%esi)), %edx + cmpl PER_CPU_ARG(4(%esi)), %edx jne .Lnot_same2 =20 - movl %ebx, PER_CPU_VAR(0(%esi)) - movl %ecx, PER_CPU_VAR(4(%esi)) + movl %ebx, PER_CPU_ARG(0(%esi)) + movl %ecx, PER_CPU_ARG(4(%esi)) =20 orl $X86_EFLAGS_ZF, (%esp) =20 @@ -72,8 +84,8 @@ SYM_FUNC_START(this_cpu_cmpxchg8b_emu) RET =20 .Lnot_same2: - movl PER_CPU_VAR(0(%esi)), %eax - movl PER_CPU_VAR(4(%esi)), %edx + movl PER_CPU_ARG(0(%esi)), %eax + movl PER_CPU_ARG(4(%esi)), %edx =20 andl $(~X86_EFLAGS_ZF), (%esp) =20 --=20 2.41.0 From nobody Fri May 17 07:55:52 2024 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 B1C50CDB47E for ; Thu, 12 Oct 2023 20:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442770AbjJLUSL (ORCPT ); Thu, 12 Oct 2023 16:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442408AbjJLUSC (ORCPT ); Thu, 12 Oct 2023 16:18:02 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D75EC0 for ; Thu, 12 Oct 2023 13:17:57 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5230a22cfd1so2505596a12.1 for ; Thu, 12 Oct 2023 13:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697141875; x=1697746675; 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=hDMSEbE6Ie84T5BkOrHBUuyCR3ToRtFXIBnMpzsN9Bo=; b=AeHI+98YkFhglLwgBxMDJpvwQDC7roZCx/6gVcoqkh8r8FWHNP5vjnAsLoy+dFnz78 OQuVTAy6XICjR4kYpgQn9KaOeAHC0dOeaYH6Rf9lkq9vF9h3jR5w7xRWsBLMnWi4SYMI yU5DMG9nv7x48Ll7G8oChv91ln4l1mhx28BvcG4uhGmBT/oWgV2A/th9oiJUpmJLXPSC Wnn5wEPIhT+g3kBCB3RPnQeu07vbbm64Q4w0Wj+e9FtvOq1KVV7heE3hk5w1X0WRB28p QefWP6ZCa42EZMIuIa5otLokUL9Y4ckA00ZJw84XGeyPo6ev0SKnEXmiTwnzaFs4aMmg H97A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697141875; x=1697746675; 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=hDMSEbE6Ie84T5BkOrHBUuyCR3ToRtFXIBnMpzsN9Bo=; b=g2lNEIQsypXbBWP4knl5GRJNeLBkrwb3tnlF2IZSl8cTLi4xsNmxOHWTjqewkg2O8a XYe3mXYoyBE0FR4zJTjQTAe4rrWpaVjDpjb05v2qFzo4+AX8TwR+iN6xo0iRakboMKNn XlOEnIzYwv9kvFAIdt0fETL7wj5g0U9S7cOTiE0jYT99pdaVSqxklTtpVtPo6+yxqmKc v6eGjCGyD+lxYFlY3j96RyRpQWReY1p/7Uctqx/oFAmuOmRFW7FoSnmTjDoAIfBUV8yX HMnVFCxFafv+y3pAzOO3st7+O4BGGTpYBtZubMQBlkL90UgZ1K+vWg76qVcQHoWEokdv 1bcQ== X-Gm-Message-State: AOJu0Ywbcbe3xTTxUOjlxgkP98k5xwQlaznaBhdIik4MT+fo8mxjSGCM G1iSjXROkDESdMyBdrjZu7Y= X-Google-Smtp-Source: AGHT+IGhoWha4M/ka8e2JRhDL76Q3hwso5VE/0ZSrUJ5K72lB/D3qkiWMd0b7LflyD+sVTpFdiWVHw== X-Received: by 2002:a17:906:3e52:b0:9b2:aa2f:ab69 with SMTP id t18-20020a1709063e5200b009b2aa2fab69mr24396120eji.30.1697141875609; Thu, 12 Oct 2023 13:17:55 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id i3-20020a1709064ec300b00997d7aa59fasm11692552ejv.14.2023.10.12.13.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 13:17:55 -0700 (PDT) From: Uros Bizjak To: x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH v2 2/4] x86/percpu: Correct PER_CPU_VAR usage to include symbol and its addend Date: Thu, 12 Oct 2023 22:12:05 +0200 Message-ID: <20231012201743.292149-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012201743.292149-1-ubizjak@gmail.com> References: <20231012201743.292149-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" PER_CPU_VAR macro should be applied to a symbol and its addend. Inconsistent usage is currently harmless, but needs to be corrected before %rip-relative addressing is introduced to PER_CPU_VAR macro. No functional changes intended. 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/entry/calling.h | 2 +- arch/x86/entry/entry_32.S | 2 +- arch/x86/entry/entry_64.S | 2 +- arch/x86/kernel/head_64.S | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h index f6907627172b..47368ab0bda0 100644 --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -173,7 +173,7 @@ For 32-bit we have the following conventions - kernel i= s built with .endm =20 #define THIS_CPU_user_pcid_flush_mask \ - PER_CPU_VAR(cpu_tlbstate) + TLB_STATE_user_pcid_flush_mask + PER_CPU_VAR(cpu_tlbstate + TLB_STATE_user_pcid_flush_mask) =20 .macro SWITCH_TO_USER_CR3_NOSTACK scratch_reg:req scratch_reg2:req ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 6e6af42e044a..d4e094b2c877 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -305,7 +305,7 @@ .macro CHECK_AND_APPLY_ESPFIX #ifdef CONFIG_X86_ESPFIX32 #define GDT_ESPFIX_OFFSET (GDT_ENTRY_ESPFIX_SS * 8) -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + GDT_ESPFIX_OFFSET +#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page + GDT_ESPFIX_OFFSET) =20 ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX =20 diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 43606de22511..3d6770b87b87 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -252,7 +252,7 @@ SYM_FUNC_START(__switch_to_asm) =20 #ifdef CONFIG_STACKPROTECTOR movq TASK_stack_canary(%rsi), %rbx - movq %rbx, PER_CPU_VAR(fixed_percpu_data) + FIXED_stack_canary + movq %rbx, PER_CPU_VAR(fixed_percpu_data + FIXED_stack_canary) #endif =20 /* diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index ea6995920b7a..bfe5ec2f4f83 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -449,7 +449,7 @@ SYM_CODE_START(soft_restart_cpu) UNWIND_HINT_END_OF_STACK =20 /* Find the idle task stack */ - movq PER_CPU_VAR(pcpu_hot) + X86_current_task, %rcx + movq PER_CPU_VAR(pcpu_hot + X86_current_task), %rcx movq TASK_threadsp(%rcx), %rsp =20 jmp .Ljump_to_C_code --=20 2.41.0 From nobody Fri May 17 07:55:52 2024 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 C71F9CDB487 for ; Thu, 12 Oct 2023 20:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442738AbjJLUSJ (ORCPT ); Thu, 12 Oct 2023 16:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344142AbjJLUSB (ORCPT ); Thu, 12 Oct 2023 16:18:01 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F32C9 for ; Thu, 12 Oct 2023 13:17:58 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-53e0d21a4easo1855850a12.1 for ; Thu, 12 Oct 2023 13:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697141877; x=1697746677; 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=yNuYyWEUkCBUvaAXEq0aoPImcZWnaX/wCmiSUbk6m0g=; b=gvVsoXwXV48YfHZY6A3mEi7dhLLcqahGXz5x1GuJvJzJ+enjMhUfd9NdQ/wUxkrQGS 7iVHdiwHjaKIUm78QgfxNA8ghdo6DE3Q10LxXv26P+mcko7VmzIiZ6NdiGm1OxpCJ12j zOqHEcY6FOPjoUKCodlqcb8WejponjTZFPr5ROfAstwwJ+dKOtGzcBEGjBgQBZdFL8j8 nwsrcv+1t9Llg2cjUxdoLUMS4sLAcXPcJSfVIq8mDwHi28VONfF7egAboXFFg6oHMxiO CpYaKbN1QcUa23FZIiV7agG318R35Qnhnmnn00S4G4zZKuUGPl3oZUz0wh1PkN1qQFmD ZknA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697141877; x=1697746677; 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=yNuYyWEUkCBUvaAXEq0aoPImcZWnaX/wCmiSUbk6m0g=; b=N48QTlG0bDqK584yGSYT38HHkmRygZgpBoYAkbazOgT+58ZVAMpJ++rFoWxGizmTo1 ERCFIaGvsnpYDO12WlbS+Mv66wffQf4PyEXxQFjv4abc4uabBpOqP7nHh9xZEw3g1Fkm i/WzU6Gkl4/HkKYKaPAleMthtH4bi/VB/j7sJOiEw8ThwdxvTY5s8gKU8/f1mich8k9+ TZeJ1aTfIKMfBzM2ZxSEllrRNBRvAwLChZ7VnLlremOFfSD9xK3Gjg/0RTTd0FP8QeXB lPrKbpfXEkGc+oygFg9XQgijy40zk0M/DdzvK5yVGha+mfPPAvKA5620WRvG9Pwq7qDe iYuA== X-Gm-Message-State: AOJu0Yx8/kaoCFTJN3UmSjL5j/+fTZ5OMqVC7oyQY1Ao4tbXdWTMbJLi 7KJd6ZOWYAwI+axEjhNfQOY= X-Google-Smtp-Source: AGHT+IGmOK7ZIlt1roxwebKg2U7mq6HSiacaJSzpvBLJtS6/apvSq2Xo3cDatgmKdrTKmuZCNTp1Yw== X-Received: by 2002:a17:906:3003:b0:9b2:8df4:c692 with SMTP id 3-20020a170906300300b009b28df4c692mr22597068ejz.27.1697141876293; Thu, 12 Oct 2023 13:17:56 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id i3-20020a1709064ec300b00997d7aa59fasm11692552ejv.14.2023.10.12.13.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 13:17:56 -0700 (PDT) From: Uros Bizjak To: x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 3/4] x86/percpu, xen: Correct PER_CPU_VAR usage to include symbol and its addend Date: Thu, 12 Oct 2023 22:12:06 +0200 Message-ID: <20231012201743.292149-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012201743.292149-1-ubizjak@gmail.com> References: <20231012201743.292149-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" PER_CPU_VAR macro should be applied to a symbol and its addend. Inconsisten usage is currently harmless, but needs to be corrected before %rip-relative addressing is introduced to PER_CPU_VAR macro. No functional changes intended. Cc: Juergen Gross Cc: Boris Ostrovsky Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Signed-off-by: Uros Bizjak --- arch/x86/xen/xen-asm.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S index 9e5e68008785..448958ddbaf8 100644 --- a/arch/x86/xen/xen-asm.S +++ b/arch/x86/xen/xen-asm.S @@ -28,7 +28,7 @@ * non-zero. */ SYM_FUNC_START(xen_irq_disable_direct) - movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask + movb $1, PER_CPU_VAR(xen_vcpu_info + XEN_vcpu_info_mask) RET SYM_FUNC_END(xen_irq_disable_direct) =20 @@ -69,7 +69,7 @@ SYM_FUNC_END(check_events) SYM_FUNC_START(xen_irq_enable_direct) FRAME_BEGIN /* Unmask events */ - movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask + movb $0, PER_CPU_VAR(xen_vcpu_info + XEN_vcpu_info_mask) =20 /* * Preempt here doesn't matter because that will deal with any @@ -78,7 +78,7 @@ SYM_FUNC_START(xen_irq_enable_direct) */ =20 /* Test for pending */ - testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending + testb $0xff, PER_CPU_VAR(xen_vcpu_info + XEN_vcpu_info_pending) jz 1f =20 call check_events @@ -97,7 +97,7 @@ SYM_FUNC_END(xen_irq_enable_direct) * x86 use opposite senses (mask vs enable). */ SYM_FUNC_START(xen_save_fl_direct) - testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask + testb $0xff, PER_CPU_VAR(xen_vcpu_info + XEN_vcpu_info_mask) setz %ah addb %ah, %ah RET @@ -113,7 +113,7 @@ SYM_FUNC_END(xen_read_cr2); =20 SYM_FUNC_START(xen_read_cr2_direct) FRAME_BEGIN - _ASM_MOV PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_arch_cr2, %_ASM_AX + _ASM_MOV PER_CPU_VAR(xen_vcpu_info + XEN_vcpu_info_arch_cr2), %_ASM_AX FRAME_END RET SYM_FUNC_END(xen_read_cr2_direct); --=20 2.41.0 From nobody Fri May 17 07:55:52 2024 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 EC2FFCDB47E for ; Thu, 12 Oct 2023 20:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442715AbjJLUSG (ORCPT ); Thu, 12 Oct 2023 16:18:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344109AbjJLUSB (ORCPT ); Thu, 12 Oct 2023 16:18:01 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE8ECA for ; Thu, 12 Oct 2023 13:17:58 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9b275afb6abso536715766b.1 for ; Thu, 12 Oct 2023 13:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697141877; x=1697746677; 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=ALeoGKxiNsNupqhZSQanqEeTZk7gDRiZ8s33h27zT00=; b=VjQQA2i+25ld5AjYxv18h+nEEzlPthMa1EMjkm+7Kkh8436osYa2j+xkzg1+NFy8W0 Wum2QXGXs2oF+EGm/k5OZ6nPtowqYCbumneeYaBq9+wx1CwSdAwCnQrmNP+x2IiMFcoC LrgYoZXka3SWlCmHe7dFTQ1eTj7hrVduJZh6ijIhwXS6P0iRAxl44ZF3O36AIh5A7Jid Y4oHaH9p8B/bUDPYf8OPFs/50Cgg2Z3kt21jTrtax4bDSxmDgXP0czP4SMTAMybMSsbq ASONUuUUY/Fe77y8yPbnrLxQk5MmqCD9pA1/MuoY2sez9Y7Z4q8z/UxqWbuoHEk8a3Q0 sCCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697141877; x=1697746677; 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=ALeoGKxiNsNupqhZSQanqEeTZk7gDRiZ8s33h27zT00=; b=j1YQfYFg7rj6Nq1e5TD+zsynYpn9Ij4x2HJg3lFSh/45MlXX8nToyh4LJK9xqUH7vP eLUyGzekCetfzDZvXO76eBD2HeRGkDLWB12f5yq9TMnX4xuId8qLL4uoX9HmE2oXGkug 0A9vkEP3+qNo65lITWqSzkYwTrX+96aDV/TLBtSv7epkyAg1QSWzxmYQZ7mqRmrxx13j FlIEBehUnVQXAtEXMmbs4nHxj+KY8csSllwTkyI2vlVZHeV1e+HQKvFllQnQ5QexcOyp cqcgLza7i3WhVEMTifqtHLEg2rOgUVLZxLNrbZgZsNCz3esosNlRx3hxpef6oahY0cni w8hw== X-Gm-Message-State: AOJu0YyWbAGiNyF+SE4+Re0DBsr+zLqFYWLCKlkdVccKun/OYOZmdo6R PrUVKkEcdMi3FlAEv3Dle6w= X-Google-Smtp-Source: AGHT+IGL/aK1BGpYJaP/mMy11SXb55Cywvjox0gtbzUH0yanedqIAwh6/5blT0OJLYZSBuGZJQt9Dw== X-Received: by 2002:a17:907:9715:b0:9ae:705a:8451 with SMTP id jg21-20020a170907971500b009ae705a8451mr21130335ejc.25.1697141877018; Thu, 12 Oct 2023 13:17:57 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id i3-20020a1709064ec300b00997d7aa59fasm11692552ejv.14.2023.10.12.13.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 13:17:56 -0700 (PDT) From: Uros Bizjak To: x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH v2 4/4] x86/percpu: Introduce %rip-relative addressing to PER_CPU_VAR macro Date: Thu, 12 Oct 2023 22:12:07 +0200 Message-ID: <20231012201743.292149-5-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012201743.292149-1-ubizjak@gmail.com> References: <20231012201743.292149-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" Introduce x86_64 %rip-relative addressing to PER_CPU_VAR macro. Instruction with %rip-relative address operand is one byte shorter than its absolute address counterpart and is also compatible with position independent executable (-fpie) build. 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/percpu.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 83e6a4bcea38..c53c5a7f8e78 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -4,19 +4,21 @@ =20 #ifdef CONFIG_X86_64 #define __percpu_seg gs +#define __percpu_rel (%rip) #else #define __percpu_seg fs +#define __percpu_rel #endif =20 #ifdef __ASSEMBLY__ =20 #ifdef CONFIG_SMP #define PER_CPU_ARG(arg) %__percpu_seg:arg -#define PER_CPU_VAR(var) %__percpu_seg:var +#define PER_CPU_VAR(var) %__percpu_seg:(var)##__percpu_rel #else /* ! SMP */ #define PER_CPU_ARG(arg) arg -#define PER_CPU_VAR(var) var -#endif /* SMP */ +#define PER_CPU_VAR(var) (var)##__percpu_rel +#endif /* SMP */ =20 #ifdef CONFIG_X86_64_SMP #define INIT_PER_CPU_VAR(var) init_per_cpu__##var --=20 2.41.0