From patchwork Thu Oct 12 16:10:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13419415 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 46946CDB46E for ; Thu, 12 Oct 2023 16:13:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615913.957453 (Exim 4.92) (envelope-from ) id 1qqyIs-00039g-Mr; Thu, 12 Oct 2023 16:12:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615913.957453; Thu, 12 Oct 2023 16:12:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIs-00039Z-KA; Thu, 12 Oct 2023 16:12:50 +0000 Received: by outflank-mailman (input) for mailman id 615913; Thu, 12 Oct 2023 16:12:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIr-00039I-O4 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 16:12:49 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2fc758d0-691a-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 18:12:48 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9adb9fa7200so234958266b.0 for ; Thu, 12 Oct 2023 09:12:48 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ci24-20020a170906c35800b009a2235ed496sm11414461ejb.141.2023.10.12.09.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:12:47 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2fc758d0-691a-11ee-98d4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697127168; x=1697731968; darn=lists.xenproject.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=HQbyfobss6xeclCGhQMgW1ClZu9bZ4s/snJGfv9Jbpo=; b=GVk5TceC7qTadNwETNKYbj8wjoY+1e/GJhTe//ZWwYCERthPW+ENoQpvvpx5zaMsbn uZE6EbVGC+bDvbkDOD8VietIZ/6Ck1s41y+PDWRW6v/xIWOuAMl1hEnH2vKTu2+4lQzA W55wOZQbdNgaAMae9nIEDyy+SpRdL/yiuuREqzHlFufVJOOKGnqltGLdGXljA8ahBqxA /D/5nY/93S0ykaByooNGo6/WmvxlmhkylJCQBZJseX75iws38p8N2ZuLM3AhXy0keFMV Wc7KaOQUFMrd5iViMtY0jKUR8qrCJcNCxstBIh5fK5rQ+16qrwuLLsNNngfyxdaOcANZ Yz3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697127168; x=1697731968; 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=HQbyfobss6xeclCGhQMgW1ClZu9bZ4s/snJGfv9Jbpo=; b=A5gEiO8L3WM79XseGOuC341sXzn/jxiLQFv2C8aDXVGWQxg5HkE0LO5jmvAoG/v9gy pXrFsB2ZEXipkVS7UWpesaNesgRUDU2cxlZe8CbNWIMx78akabapD7E4VPHHyQ6V5JNu 2tM0bTZb2G2gpq6MjQrPfdmyj+YZ+/+Ou/knj17TTm038uknRHnTM577X0LwOErjP8o2 FiACC7rTSGBbZdsPzP3ZhUUAZLaSpxXFK+IfqEOcf8wpNLOt2Xbi/bMzlKS5MQk0gI7N L92aDrjLprpp0SeTIl7HrDFAO+ZfUewq1V10pqVKTdgWPbynx/SwdnBMxspPblsWd/St XtCg== X-Gm-Message-State: AOJu0Yx4czBNr76kZ7xzUTHvYdhCeoqvyxHR3nJY/uZcWswBpVwacYEi LJD9RR9IJEx1NVh0GnkZc2g= X-Google-Smtp-Source: AGHT+IFcqbuNzLQmgxkQeiKP2KIso3r6ZxxKVuexp+Jb8ccabLciAyOXFrL77NO8rhOPn+oPIIJ4xw== X-Received: by 2002:a17:906:99c5:b0:9ae:3768:f0ce with SMTP id s5-20020a17090699c500b009ae3768f0cemr20792970ejn.0.1697127167910; Thu, 12 Oct 2023 09:12:47 -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 1/4] x86/percpu: Use explicit segment registers in lib/cmpxchg{8,16}b_emu.S Date: Thu, 12 Oct 2023 18:10:36 +0200 Message-ID: <20231012161237.114733-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012161237.114733-1-ubizjak@gmail.com> References: <20231012161237.114733-1-ubizjak@gmail.com> MIME-Version: 1.0 PER_CPU_VAR macro is intended to be applied to a symbol, it is not intended to be used as a selector between %fs and %gs segment registers for general operands. The address to these emulation functions is passed in a register, so use explicit segment registers to access percpu variable instead. 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 --- arch/x86/lib/cmpxchg16b_emu.S | 12 ++++++------ arch/x86/lib/cmpxchg8b_emu.S | 30 +++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S index 6962df315793..2bd8b89bce75 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 /* if (*ptr == old) */ - cmpq PER_CPU_VAR(0(%rsi)), %rax + cmpq %gs:(%rsi), %rax jne .Lnot_same - cmpq PER_CPU_VAR(8(%rsi)), %rdx + cmpq %gs:8(%rsi), %rdx jne .Lnot_same /* *ptr = new */ - movq %rbx, PER_CPU_VAR(0(%rsi)) - movq %rcx, PER_CPU_VAR(8(%rsi)) + movq %rbx, %gs:(%rsi) + movq %rcx, %gs:8(%rsi) /* set ZF in EFLAGS to indicate success */ orl $X86_EFLAGS_ZF, (%rsp) @@ -42,8 +42,8 @@ SYM_FUNC_START(this_cpu_cmpxchg16b_emu) /* *ptr != old */ /* old = *ptr */ - movq PER_CPU_VAR(0(%rsi)), %rax - movq PER_CPU_VAR(8(%rsi)), %rdx + movq %gs:(%rsi), %rax + movq %gs:8(%rsi), %rdx /* 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..b7d68d5e2d31 100644 --- a/arch/x86/lib/cmpxchg8b_emu.S +++ b/arch/x86/lib/cmpxchg8b_emu.S @@ -24,12 +24,12 @@ SYM_FUNC_START(cmpxchg8b_emu) pushfl cli - cmpl 0(%esi), %eax + cmpl (%esi), %eax jne .Lnot_same cmpl 4(%esi), %edx jne .Lnot_same - movl %ebx, 0(%esi) + movl %ebx, (%esi) movl %ecx, 4(%esi) orl $X86_EFLAGS_ZF, (%esp) @@ -38,7 +38,7 @@ SYM_FUNC_START(cmpxchg8b_emu) RET .Lnot_same: - movl 0(%esi), %eax + movl (%esi), %eax movl 4(%esi), %edx andl $(~X86_EFLAGS_ZF), (%esp) @@ -53,18 +53,30 @@ EXPORT_SYMBOL(cmpxchg8b_emu) #ifndef CONFIG_UML +/* + * Emulate 'cmpxchg8b %fs:(%esi)' + * + * 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) pushfl cli - cmpl PER_CPU_VAR(0(%esi)), %eax + cmpl %fs:(%esi), %eax jne .Lnot_same2 - cmpl PER_CPU_VAR(4(%esi)), %edx + cmpl %fs:4(%esi), %edx jne .Lnot_same2 - movl %ebx, PER_CPU_VAR(0(%esi)) - movl %ecx, PER_CPU_VAR(4(%esi)) + movl %ebx, %fs:(%esi) + movl %ecx, %fs:4(%esi) orl $X86_EFLAGS_ZF, (%esp) @@ -72,8 +84,8 @@ SYM_FUNC_START(this_cpu_cmpxchg8b_emu) RET .Lnot_same2: - movl PER_CPU_VAR(0(%esi)), %eax - movl PER_CPU_VAR(4(%esi)), %edx + movl %fs:(%esi), %eax + movl %fs:4(%esi), %edx andl $(~X86_EFLAGS_ZF), (%esp) From patchwork Thu Oct 12 16:10:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13419417 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 004DBCDB46E for ; Thu, 12 Oct 2023 16:13:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615915.957472 (Exim 4.92) (envelope-from ) id 1qqyIu-0003d8-5E; Thu, 12 Oct 2023 16:12:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615915.957472; Thu, 12 Oct 2023 16:12:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIu-0003d1-2X; Thu, 12 Oct 2023 16:12:52 +0000 Received: by outflank-mailman (input) for mailman id 615915; Thu, 12 Oct 2023 16:12:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIs-00039I-DY for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 16:12:50 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2ffdc354-691a-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 18:12:49 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-99c3c8adb27so185611266b.1 for ; Thu, 12 Oct 2023 09:12:49 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ci24-20020a170906c35800b009a2235ed496sm11414461ejb.141.2023.10.12.09.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:12:48 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2ffdc354-691a-11ee-98d4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697127168; x=1697731968; darn=lists.xenproject.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=hn8MyaatYHscqsveVfaTn48fml4MZnlVKcZ80z2VgUhQWJUTsnnJL74jCSa0gd7zuR A2gPZyN7S+JY7RlcuV+Htk4qmLcw4wx4suaaJqs8v2qejhLfSe+vhvt07z54zGq8rKPW y4GzQDR324Ki6hI+dV3zlJXjH5X4c+FrV5DXRD6a2ajQuCJ9A9MKHMbxVw48KkOUkfbn fyUku6nCaX/40rJgrtG4CcZS4VUYPOsl02dWjZvEOUtaB03h8u5Mm/cRmiPF0vDGbcCL XzGizY0S7gLpHO9KIO4ICexVNEAbOn1KckQ+t4vT8p1azbs4XDZEJVzC2At+FPZBNms8 /BaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697127168; x=1697731968; 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=vH8fN9ikea+xZ9636kIBXP+bZw68ml5KQskTC5uL7QXV5hZQnc1S/VW5481ByjKz8U qsMOsrUs6l/5z2DPL+Y1zNNYzA6X6261QWqgi+zAfUMiieC/G8KNtXaSZqy5jxPcnb5/ nU7feWyfe/3eS1U08EvF+L2uCi8DnS38dwf9HVIrYvkBX3ohfeef2mdr7WaB4cqguCSx ALficSmoOxlX+Do9rsHnWWi9eG74Dmmvtc/o5lmXEH4KqGoxhGZXmSyfwUaetCWYoqCw PAQXZVBOntWvyOJm1f2G5/BQkndPIORASiRCSPnbXrLI5wimaOyr45lmErOZbAB7I9gw s1vQ== X-Gm-Message-State: AOJu0YwuT7DR+sn20TgV332wsEOxYiH8G2YL8V2rX75DgdZrXwaSEh52 nA2vTNeV9pUJ56aP4EOg1SQ= X-Google-Smtp-Source: AGHT+IEJe39mReMmuqoI7tLyKV8yCFM2VE+XW0dysIJl/d8IcLEFQpg5Cv5p2IFg4LrOKeuqQ65l1Q== X-Received: by 2002:a17:906:2d1:b0:9b2:b765:8802 with SMTP id 17-20020a17090602d100b009b2b7658802mr24346581ejk.40.1697127168624; Thu, 12 Oct 2023 09:12:48 -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 2/4] x86/percpu: Correct PER_CPU_VAR usage to include symbol and its addend Date: Thu, 12 Oct 2023 18:10:37 +0200 Message-ID: <20231012161237.114733-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012161237.114733-1-ubizjak@gmail.com> References: <20231012161237.114733-1-ubizjak@gmail.com> MIME-Version: 1.0 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 is built with .endm #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) .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) ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX 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) #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 /* 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 /* 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 jmp .Ljump_to_C_code From patchwork Thu Oct 12 16:10:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13419419 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 655A5CDB483 for ; Thu, 12 Oct 2023 16:13:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615916.957483 (Exim 4.92) (envelope-from ) id 1qqyIv-0003sN-Do; Thu, 12 Oct 2023 16:12:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615916.957483; Thu, 12 Oct 2023 16:12:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIv-0003sA-Az; Thu, 12 Oct 2023 16:12:53 +0000 Received: by outflank-mailman (input) for mailman id 615916; Thu, 12 Oct 2023 16:12:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIt-00039I-Dk for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 16:12:51 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 307d2589-691a-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 18:12:50 +0200 (CEST) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-9b9a494cc59so174209566b.3 for ; Thu, 12 Oct 2023 09:12:50 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ci24-20020a170906c35800b009a2235ed496sm11414461ejb.141.2023.10.12.09.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:12:49 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 307d2589-691a-11ee-98d4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697127169; x=1697731969; darn=lists.xenproject.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=eo5fxUe36dZDhzGMveObrzDeK18Eoy2+TmAeOndTr/74I429kXOAspj+zacEYAxfvm 6np6W3dAVTa6Ih0g9c2VZYZf/8zER8PdBXXdQF8/YxvJhIpIbzGp9rIkrWeNkL/uhTSO NqB+RSkARdbbTwPSv98dqTfVcpgdTaWIOxl22CpINR2E0H9XEGN+RASdDyPFWPFJXzxI QkBhZ8B4okjiNXe5ZABceuPPid45PqjYc+D3Nnl0kWpRUnb5/AKhIAugPJNPIIbH3ZWd FmTLQvtFxDygHpnafJaqBeMpVKlxBIFt6ZcQi7jnEhtJjd4pEOjWLG4a33EMmyPgy8Gz XvCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697127169; x=1697731969; 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=MgWtAjHDKdphfCPI0qH1j2MG6iOinOsbevhfr7LRHxz7erV7EPpCqQmFFgG637g9fv kRakPgxCT74EMT/8nW5lTiQ4NZuKNuiJxpHvNMcHFSSm8rSrG43DO5hD+YwOek2JINJa pf/EpbomZjzP9e8cWwjzh4BT45QpOuLFax4QV9cLK33afJhoxobAMM3nBLyrJNOqHrdP T+BqhrwukjIAVr01srm3ENNyX327oVmN3wuYLj37+pbvhnmXjalbv+A987CmTSjZjLLR 24N9FeLQdvfUceNuM5Cvwtt+BzafrPukkCfMNQAuUd4uAHVFd63A1JHeBsqGfdkonnUW Hb8w== X-Gm-Message-State: AOJu0YwQcQDDwpT99dmAsO2s/B18O3RBMwXwR3iehsna4nEpto/ZIOqx UxNQkrjQsac9CLzNizyiCQ0= X-Google-Smtp-Source: AGHT+IGx9PkHoJpnehpt9pu+WFKAxecc4I9gQHgLxLDfU4O7a5NswxaCFNLbcJfvXgFPcLDWLdekjw== X-Received: by 2002:a17:906:218:b0:9ba:2b14:44f2 with SMTP id 24-20020a170906021800b009ba2b1444f2mr10518666ejd.73.1697127169365; Thu, 12 Oct 2023 09:12:49 -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 3/4] x86/percpu, xen: Correct PER_CPU_VAR usage to include symbol and its addend Date: Thu, 12 Oct 2023 18:10:38 +0200 Message-ID: <20231012161237.114733-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012161237.114733-1-ubizjak@gmail.com> References: <20231012161237.114733-1-ubizjak@gmail.com> MIME-Version: 1.0 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) @@ -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) /* * Preempt here doesn't matter because that will deal with any @@ -78,7 +78,7 @@ SYM_FUNC_START(xen_irq_enable_direct) */ /* 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 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); 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); From patchwork Thu Oct 12 16:10:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13419416 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 4C046CDB47E for ; Thu, 12 Oct 2023 16:13:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615917.957488 (Exim 4.92) (envelope-from ) id 1qqyIv-0003vg-P1; Thu, 12 Oct 2023 16:12:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615917.957488; Thu, 12 Oct 2023 16:12:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIv-0003uy-K1; Thu, 12 Oct 2023 16:12:53 +0000 Received: by outflank-mailman (input) for mailman id 615917; Thu, 12 Oct 2023 16:12:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqyIu-00039J-L3 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 16:12:52 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 311d453e-691a-11ee-9b0e-b553b5be7939; Thu, 12 Oct 2023 18:12:51 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-991c786369cso186313166b.1 for ; Thu, 12 Oct 2023 09:12:51 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ci24-20020a170906c35800b009a2235ed496sm11414461ejb.141.2023.10.12.09.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:12:49 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 311d453e-691a-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697127170; x=1697731970; darn=lists.xenproject.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=vSHi5/2cUoPsahCtfSXb7KL8cBzud0m2fEvRiojl9UE=; b=jmLnJTSocAIocPdvkghOiaqt+L/vI15+glJvKXLkTjS64iN4Texl6JxcRW6H79Xaaj q/Nsu3oHfdwJ4uA8iIwekgmJz8P02TdIOR8jjQ9wZFdBuXiU+E0kPJOOpSNKBq9RYs9y jw440MSkgvnhE9lLaKZ98ijEKpFiSfo0intyL2ezzoujX2DZP3oaaOVHPRDJajd7rEje vp3P7U1UAq+xl9WdQTtnEJX9ag57bf6I6L8GZlUx+oi4H3sE61HgUljPVRR3grnw0ktN 2viL+1ISSzWpUYfg3nfqEijrG3KIqJNtwekgK2BrTYGbEelFKyRbSUv1Oumzcdbb17IB nU1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697127170; x=1697731970; 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=vSHi5/2cUoPsahCtfSXb7KL8cBzud0m2fEvRiojl9UE=; b=JPUHBSU+O/W+AwxpL7BJHXbtVjkrkFe17EBPDFclQsiPMbOUuRtfFb/tQqpcUeSLiQ lY7mZmAfLeF0XL53J6FvltrYBCfM1hmxeopotQRDJnDxLdu9mQeRTti//5k1xYHQXj0i /73Vz2+utptlJ0Tx1RiwKsUlgrZNwxU3AIJ+cpD/AgLQxbL6zcrQgvcJiAye2ol2MCEB oeweDhMlHRfaVWXMZbEFvmsVlNacNyH4s68cPs3Bv7n0If0smiA4VEWvQtHrTlbi4ySW F/TtihIjLnsriwYGlv5kNg4BcbJAMsuq5hrxh6G+/N5UVeozHFs6LdHi9dcs1MgF3m0Z AKKw== X-Gm-Message-State: AOJu0YzmJ0+gUfNDp0pLZ7b7NX4P5o3iUIJsUezCmRytABXvzwvDK4Px ZSAwXypcjBwx4dxSW9v2Kc0= X-Google-Smtp-Source: AGHT+IFpYi1blV2KJsYt/+b2deArMIbm7cJzAsEuhn9TEMfBcKQAcEqKVR0HJV8k5hdf8tw21y1uTg== X-Received: by 2002:a17:906:76cf:b0:9b7:303b:1ecb with SMTP id q15-20020a17090676cf00b009b7303b1ecbmr22078486ejn.61.1697127170254; Thu, 12 Oct 2023 09:12:50 -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 4/4] x86/percpu: Introduce %rip-relative addressing to PER_CPU_VAR macro Date: Thu, 12 Oct 2023 18:10:39 +0200 Message-ID: <20231012161237.114733-5-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012161237.114733-1-ubizjak@gmail.com> References: <20231012161237.114733-1-ubizjak@gmail.com> MIME-Version: 1.0 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 34734d730463..9a5f1896c5ef 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -4,16 +4,18 @@ #ifdef CONFIG_X86_64 #define __percpu_seg gs +#define __percpu_rel (%rip) #else #define __percpu_seg fs +#define __percpu_rel #endif #ifdef __ASSEMBLY__ #ifdef CONFIG_SMP -#define PER_CPU_VAR(var) %__percpu_seg:var +#define PER_CPU_VAR(var) %__percpu_seg:(var)##__percpu_rel #else /* ! SMP */ -#define PER_CPU_VAR(var) var +#define PER_CPU_VAR(var) (var)##__percpu_rel #endif /* SMP */ #ifdef CONFIG_X86_64_SMP