From nobody Wed Dec 17 00:14:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1697127198; cv=none; d=zohomail.com; s=zohoarc; b=HOt9QlhBAIGoAombxcjnBQqxp0DaOmimMrQuiJzHtaibTOFp2rRN0zxqJ29H6fL0Y1DoRIai3dvGiUJyWhLYX8xAVR5N+pQX3hVF5lIer8KzjHxG3YsIRLmQJYfFUkBiaTAdbyWE2S3aFIUC+eSphSk3lCr5bUV/xRi4cVpwmr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697127198; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HQbyfobss6xeclCGhQMgW1ClZu9bZ4s/snJGfv9Jbpo=; b=dSd9DSwsSfxIBkViMYk/Rh4nGyPTp3JgX/+zDCjRXUTfFe3KYYM0agfp7bC84tABT2Qmbu+hLujdyJTGkhc09et3TbZAKg00EMNXWG2c0OklDufeVxklThsEKUU8BH7lNFuT2eg36Irs4dR0xbWrfH8x/ozIQh/ngj/7v5BLK/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1697127198598295.2391855341266; Thu, 12 Oct 2023 09:13:18 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1697127199811100001 Content-Type: text/plain; charset="utf-8" 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 =20 /* if (*ptr =3D=3D 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 =20 /* *ptr =3D new */ - movq %rbx, PER_CPU_VAR(0(%rsi)) - movq %rcx, PER_CPU_VAR(8(%rsi)) + movq %rbx, %gs:(%rsi) + movq %rcx, %gs: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 %gs:(%rsi), %rax + movq %gs: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..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 =20 - cmpl 0(%esi), %eax + cmpl (%esi), %eax jne .Lnot_same cmpl 4(%esi), %edx jne .Lnot_same =20 - movl %ebx, 0(%esi) + movl %ebx, (%esi) movl %ecx, 4(%esi) =20 orl $X86_EFLAGS_ZF, (%esp) @@ -38,7 +38,7 @@ SYM_FUNC_START(cmpxchg8b_emu) RET =20 .Lnot_same: - movl 0(%esi), %eax + movl (%esi), %eax movl 4(%esi), %edx =20 andl $(~X86_EFLAGS_ZF), (%esp) @@ -53,18 +53,30 @@ EXPORT_SYMBOL(cmpxchg8b_emu) =20 #ifndef CONFIG_UML =20 +/* + * 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) =20 pushfl cli =20 - 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 =20 - movl %ebx, PER_CPU_VAR(0(%esi)) - movl %ecx, PER_CPU_VAR(4(%esi)) + movl %ebx, %fs:(%esi) + movl %ecx, %fs: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 %fs:(%esi), %eax + movl %fs:4(%esi), %edx =20 andl $(~X86_EFLAGS_ZF), (%esp) =20 --=20 2.41.0