Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp798344lqb; Wed, 17 Apr 2024 10:58:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGXN2Pi2XW6t1SBaFMG4NtdSxBAPM1Vt4u/+uvbyfpyKu2FfgCi8Iwg4i5oBj0PMjgpsXx6YoWnqijsRYJsm2qTY8g60OiSBMB4Dkb+w== X-Google-Smtp-Source: AGHT+IEp2TYDw++G6R4cNCoBKWDZ4WtajElVDFXxpFGlCjDGjZC0PgLfkUyuIjPIWfgB0JFWOu// X-Received: by 2002:a05:622a:11d1:b0:437:4ddd:5c5d with SMTP id n17-20020a05622a11d100b004374ddd5c5dmr260559qtk.10.1713376729315; Wed, 17 Apr 2024 10:58:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713376729; cv=pass; d=google.com; s=arc-20160816; b=HqV8nxjPhC6GPg0NpuOXWgnk1TLpRnLWDoOm3IM/6ezJjdjFeQEFIP3MRlKHrQjgzv FvSohCG+njLrt2L0zd5Sts2X7aZA2UAFohURm4ocY+QF658tWceRI4BaPQLh2LorCniH D3GoVofW6ZD5F26sE+/8E8fi3vY1Qmy8zuvp3zqVyC4RCKnlrlc+pc+sOAKA4iMa6zQe E9oRo2BzHfWy9RY96jDWM/1HEJgNxHUNO1z0FwH0lVm6/njdnGB0IUsZclYvQZI3kvnh 0tVHfIpmjjpKJlw+jXNvzyeTIK7FIeUvhg4TS+/FrRH9EAoY4WI+g87s1rSPioYkuaq0 rXUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Eso1cJErLr5fMl62SnEcQ5C9TY3ZGBWSN1bAngprfS8=; fh=tswaGDUr3oylk8zyQmycy4It9gsnyAIm8P6rB2H3JJ0=; b=WTnbsXHg+0d4OFbDXWiOmxO5hnIR4gNfsg8gb+p1PIF/1EzUsiuKngdx1Jr5KcpdYK I35TM7GH8BTia5oN8vDJFRIdTY6xAuqjEmXxBpv7D1c0E9SB1ksbFxAcPneGjcVjUFNt 5FugXXS0/tGkFH/smkD9Vnt3jJPXwqUcaS1z4S9wY2K0PgpzOP7acAslWQSnVPvdR8BM yZ36lVG1hBIQff1/HlXtnIgmWrWeH4CPHOfGjhP4yjqmCc/dAeQrkwVw/f2wacfo9CKG mEQc1Db6AvUmH76BhgORqTnbU1Iv3ZwZDZUWdzrPpTXmkQR4TLBwkUsM+cSIpQR9hEW4 shHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dEDG4pOH; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149024-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149024-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t15-20020a05622a180f00b004364fb2f13esi15774801qtc.511.2024.04.17.10.58.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149024-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dEDG4pOH; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149024-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149024-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F40251C220F8 for ; Wed, 17 Apr 2024 17:58:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80AA7172BC9; Wed, 17 Apr 2024 17:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dEDG4pOH" Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD56416FF52 for ; Wed, 17 Apr 2024 17:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713376723; cv=none; b=aj+34O/NzC+hGUXGXxc2d5V44dJWs+yVKKq493BN0VOMdKt9llPr3P/Qpzgrfj+nZRJGQoKie511fVaOra/j8Kovxc83+GIin8+tNeDNIhhA7SqZb+Esn1ulncE7xWQ9pcPClhOee4zjsidevzrEcVegaGqo3PuFO0BT0aiNNRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713376723; c=relaxed/simple; bh=ZKyapYL4RldrjpQ9jjqVJyk+yZwJ4tJfRj7tapsNa/k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=I4pq0WhtB6wXvv4CAOra39iw79nhyU6nuT9iqZvIPO0Q90WYHjFnsqH67WfY/536rhRz16etUs+RJfqcNDVVpv99HchMznrJVmky2HXTlbUtMeXLpw1vedRQzKhn3ZGo44Mbinn5Jo18sweZ/1QqfNRjqr1GopQuUrWg+XFt7A0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dEDG4pOH; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5194a2cf7c2so1129938e87.0 for ; Wed, 17 Apr 2024 10:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713376720; x=1713981520; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Eso1cJErLr5fMl62SnEcQ5C9TY3ZGBWSN1bAngprfS8=; b=dEDG4pOHSrHk9YNGOz1tuD3uPSW5JtMGBwTH/mNFns52ouYQZuqkeXNogaEqY7OsEI 6o4KH5wELxR9UBJXcU4IouDE4qtNA5HS3+uNkGMfCM/D1JezAwEqVgopy/I5dyy0gTM0 Dyuvl6f0wB7kFpOiqQgjCZgC+8AyHglFYdj0w0fNFzoLKX5ftm3T/nApuOot1+LxNtqq jI91DjVq7qB5eDiwNMsVJ5gCJFK2d1Q8Rx0LM6z+RhPhxJAXKN8Ix3osUSz3WLnz4CaM wbAYPwRsQv9ByloZrO7bjgkPfpgbpbNGl0XveL+GG7j2s/c7OsTZvtdaii90A+/MWeml uGLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713376720; x=1713981520; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Eso1cJErLr5fMl62SnEcQ5C9TY3ZGBWSN1bAngprfS8=; b=i4cIDrmbmeCDMfiSGSs5SzRx+AsojA1rIUZZh8ar5n3UG8RXRFlNCTMEmnpCivisWS 0FCadHwG9lGqHY89wY4DLQ84gHvrLTpOJr3nLmuDvun8f1yqTrWVEyarvq5G9r4EEL43 PEq9E34cLlFY5GAoXcd24nDcfAeOnG+0f7UpxvHSk0JNXz1S/iTDRyCG4IAErgA2I03L 5lFwBSzSb+8eX+EOCaQvYBrFPpMrM3tVWVQIxF6Vn/s+JH8T4vc/fUy2wPveA95BmQ1j qH+wIHcp7aY3xcjRnwAIJz+pcRW53Zovrk8DO0WTux6WYr2pt/CLeSzX9ZgCy1lCEoYM sWJQ== X-Forwarded-Encrypted: i=1; AJvYcCV7maNr3KWFtPKTdLmkgyjwfjtT+BF1Pg9fS2kRZNpcr5IW0eM+QZlGRgzhxfJ2Btl6LTIsOOCFVEdeDVPId2lz/CIjrmbxBzSyybX9 X-Gm-Message-State: AOJu0YzzvOl9P98NJs29EZaGtBJQETluV9147OG/hVH/cTnIb2fJK1W2 NcAoFUvWFrydgXnhlxbezfo9yQ7Op6H7OxMA2VpJQ6waUNnYKZsy X-Received: by 2002:a05:6512:3b22:b0:517:5ee6:4f56 with SMTP id f34-20020a0565123b2200b005175ee64f56mr36531lfv.8.1713376719696; Wed, 17 Apr 2024 10:58:39 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id s17-20020a170906501100b00a4e696e613esm8373650ejj.153.2024.04.17.10.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:58:38 -0700 (PDT) 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] locking/atomic/x86: Merge __arch{,_try}_cmpxchg64_emu_local() with __arch{,_try}_cmpxchg64_emu() Date: Wed, 17 Apr 2024 19:58:12 +0200 Message-ID: <20240417175830.161561-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Macros __arch{,_try}_cmpxchg64_emu() are almost identical to their local variants __arch{,_try}_cmpxchg64_emu_local(), differing only by lock prefixes. Merge these two macros by introducing additional macro parameters to pass lock location and lock prefix from their respective static inline functions. No functional change intended. Signed-off-by: Uros Bizjak Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra --- arch/x86/include/asm/cmpxchg_32.h | 56 ++++++------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/arch/x86/include/asm/cmpxchg_32.h b/arch/x86/include/asm/cmpxchg_32.h index 9dedc13d5a77..ed2797f132ce 100644 --- a/arch/x86/include/asm/cmpxchg_32.h +++ b/arch/x86/include/asm/cmpxchg_32.h @@ -86,14 +86,14 @@ static __always_inline bool __try_cmpxchg64_local(volatile u64 *ptr, u64 *oldp, * to simulate the cmpxchg8b on the 80386 and 80486 CPU. */ -#define __arch_cmpxchg64_emu(_ptr, _old, _new) \ +#define __arch_cmpxchg64_emu(_ptr, _old, _new, _lock_loc, _lock) \ ({ \ union __u64_halves o = { .full = (_old), }, \ n = { .full = (_new), }; \ \ - asm volatile(ALTERNATIVE(LOCK_PREFIX_HERE \ + asm volatile(ALTERNATIVE(_lock_loc \ "call cmpxchg8b_emu", \ - "lock; cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ + _lock "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ : [ptr] "+m" (*(_ptr)), \ "+a" (o.low), "+d" (o.high) \ : "b" (n.low), "c" (n.high), "S" (_ptr) \ @@ -104,40 +104,25 @@ static __always_inline bool __try_cmpxchg64_local(volatile u64 *ptr, u64 *oldp, static __always_inline u64 arch_cmpxchg64(volatile u64 *ptr, u64 old, u64 new) { - return __arch_cmpxchg64_emu(ptr, old, new); + return __arch_cmpxchg64_emu(ptr, old, new, LOCK_PREFIX_HERE, "lock; "); } #define arch_cmpxchg64 arch_cmpxchg64 -#define __arch_cmpxchg64_emu_local(_ptr, _old, _new) \ -({ \ - union __u64_halves o = { .full = (_old), }, \ - n = { .full = (_new), }; \ - \ - asm volatile(ALTERNATIVE("call cmpxchg8b_emu", \ - "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ - : [ptr] "+m" (*(_ptr)), \ - "+a" (o.low), "+d" (o.high) \ - : "b" (n.low), "c" (n.high), "S" (_ptr) \ - : "memory"); \ - \ - o.full; \ -}) - static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64 new) { - return __arch_cmpxchg64_emu_local(ptr, old, new); + return __arch_cmpxchg64_emu(ptr, old, new, ,); } #define arch_cmpxchg64_local arch_cmpxchg64_local -#define __arch_try_cmpxchg64_emu(_ptr, _oldp, _new) \ +#define __arch_try_cmpxchg64_emu(_ptr, _oldp, _new, _lock_loc, _lock) \ ({ \ union __u64_halves o = { .full = *(_oldp), }, \ n = { .full = (_new), }; \ bool ret; \ \ - asm volatile(ALTERNATIVE(LOCK_PREFIX_HERE \ + asm volatile(ALTERNATIVE(_lock_loc \ "call cmpxchg8b_emu", \ - "lock; cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ + _lock "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ CC_SET(e) \ : CC_OUT(e) (ret), \ [ptr] "+m" (*(_ptr)), \ @@ -153,34 +138,13 @@ static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64 static __always_inline bool arch_try_cmpxchg64(volatile u64 *ptr, u64 *oldp, u64 new) { - return __arch_try_cmpxchg64_emu(ptr, oldp, new); + return __arch_try_cmpxchg64_emu(ptr, oldp, new, LOCK_PREFIX_HERE, "lock; "); } #define arch_try_cmpxchg64 arch_try_cmpxchg64 -#define __arch_try_cmpxchg64_emu_local(_ptr, _oldp, _new) \ -({ \ - union __u64_halves o = { .full = *(_oldp), }, \ - n = { .full = (_new), }; \ - bool ret; \ - \ - asm volatile(ALTERNATIVE("call cmpxchg8b_emu", \ - "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \ - CC_SET(e) \ - : CC_OUT(e) (ret), \ - [ptr] "+m" (*(_ptr)), \ - "+a" (o.low), "+d" (o.high) \ - : "b" (n.low), "c" (n.high), "S" (_ptr) \ - : "memory"); \ - \ - if (unlikely(!ret)) \ - *(_oldp) = o.full; \ - \ - likely(ret); \ -}) - static __always_inline bool arch_try_cmpxchg64_local(volatile u64 *ptr, u64 *oldp, u64 new) { - return __arch_try_cmpxchg64_emu_local(ptr, oldp, new); + return __arch_try_cmpxchg64_emu(ptr, oldp, new, ,); } #define arch_try_cmpxchg64_local arch_try_cmpxchg64_local -- 2.42.0