Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1218409lqe; Mon, 8 Apr 2024 02:17:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTifZm4I/QHxTuOKYJtnOFceyBb0nfjAQDBKvNtyCS/FWqwPc7W5n/pmYyNMjznj+H2FSHVto5YjljNIy2Gbs1gtZoq8GPYeqwxTl4JA== X-Google-Smtp-Source: AGHT+IFzyEDdVXfa9UEqVbOqOGjX6r8fpPb70xXsBFa8xpvVnGuPpz3HkPimN/QHLWYzGOO90VjG X-Received: by 2002:a05:6871:530d:b0:22f:33b3:5654 with SMTP id hx13-20020a056871530d00b0022f33b35654mr3278182oac.28.1712567828930; Mon, 08 Apr 2024 02:17:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712567828; cv=pass; d=google.com; s=arc-20160816; b=he0xgbKTXZYeJeMZqaggKk21SXytfITzIqOxicPB6KD0tlghd5LoebK2YW1mWF1lVf 5fu2ncLbMLiUeA5zo+iq6OfRq7sJzvc4Iut/qtpfzxvEJv0j2RQDv8s94SPG25T0nIJK 2DrgavtNeyKoemwf0wGBVwB+KDm7JJ6Eph3lNMPHieVr+E5wlg4zU/yZ8Uh8TyxuV+y1 Qe9mwxGeK4AHHm5NoMZei2/lJPaKh1zCpVOmZ8MsZuLQta18FRhPD2w/GaB9B+9+Co+s LCi7v/nC0Y9mOQ6WJm00HqyR79CF4mQmC956EmQXzaqBpoCB8/XJzd4JzxgJ4nxXW7nd t/EA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=eOdMmskLhpoulw50kdQ3gfPaoFiHiAEoT4mUXvHBa/M=; fh=T7MWbdadDeiRUtmKQPZPW5hT7sGDiTrzSiva8eXMGwU=; b=kmpvJXTdcmVVyN7DAZO1r6dT/ReRn5Uwjrc0RG+R9AMb7ix01pmuGhiOQspUQwwvqY d2mM5NGXjn2CYIAda7t4847xzNnWoGWEB4GcqqeOfd4t46bJXWHY77qb7F725M9PQaqZ SCZJHAox7N/yq7c0Vfj0lvb6jQ2yUruTkD2j/u8Q4twOpKWpF74aViSoKo3/LkWYZJwM pzMplzxr4aJ7BKLMoJbynJuttz576ohksP7zieP5TQDbVPPtnR7WSOehlrgjLHZ1t/pX 6Aent8UMea9t3eqHZQHOmdPn4Yv4xWNGAj3NXnAYSOl+Tz9Vct+F2gA/4AAy50DnFf1z /H/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F1kAwpE8; 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-135127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 8-20020a631948000000b005ee3cfc3620si5937356pgz.670.2024.04.08.02.17.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 02:17:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F1kAwpE8; 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-135127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135127-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 841C4281150 for ; Mon, 8 Apr 2024 09:17:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05B154EB2B; Mon, 8 Apr 2024 09:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F1kAwpE8" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 7AD334C61F for ; Mon, 8 Apr 2024 09:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712567758; cv=none; b=l2MkoCLgUnxtz8zHncRSAXjOrHOjCbW+5jT0lsL6HOob8CV8h/++jPkDuGyi5gEvwohljFC06Vb+Klgf3kfVsKAuaGTWWEgr4OYBR5krRgXWOpaam/ruHYxJaF2ME6TYtxCcfla8UVm0kBXfASzDOs3nTeWiFFuHKVGTydGHQ14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712567758; c=relaxed/simple; bh=+l84a63zQDa3KCQZBJ4TJN5KeUrb8PGLNV0AJ96geus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X56yuT8mUpNzTZMkpLxVb792wVZCBI1eDrfa6TdgHbcRUsc4p817MT2FjKOIynG9pXBNRcK1m5mjfkbsqgLFYv9pGu6rFuzxTYc45XVtG7Wu3l/QQporE688dRDWdTNlgzEyXuc7LncWsmdOIrXMNlvt8GSyRlluWv+l4L2l+H8= 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=F1kAwpE8; arc=none smtp.client-ip=209.85.208.54 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-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-56e346224bdso2220723a12.1 for ; Mon, 08 Apr 2024 02:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712567755; x=1713172555; 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=eOdMmskLhpoulw50kdQ3gfPaoFiHiAEoT4mUXvHBa/M=; b=F1kAwpE8ebOc6jF9LVlYe6Tu5cDedi+bln5+78s6k06sS+q7gwOR4sOOMrxEIgZfT6 yg0Sfr1zUbUkKoZK+M2sixYWzWZLv4AxzqrAhFGlmJDNy7t2ntV4GN9LKHRa4C4VM72s jGyvVy9ntxIOwlgf7PdJ8eNzbIeJDr3/cYZCF8Zz2bbWUjFByXcEKYAcP1aGQcXKz/WW NGchpEcmuPqTJBlKMkWGEPjebzoyOoyta3LMotGHVJIRZsR6Qj+cwnYXUyjFHdqxHn2B Cnjnzk7FahyxpTFHlL9s0F5ImLDAvbwsSmSZKiq+vmGElpWeXLUiJhZxO/Og0c6VDhUq r6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712567755; x=1713172555; 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=eOdMmskLhpoulw50kdQ3gfPaoFiHiAEoT4mUXvHBa/M=; b=K8S7dpo4Bzuh3SqbfpRLNK+HeqRnLXwWaqtMR5j8vv3Qp+q4JtTabhUFUELpdulID/ xtFVipV9CvOiJ693ZrRJw/TKLFWeudbjDAYxJVU2JAY9o1TNJt58Ks3cMfyRE9sIPmSW c2O4yUw7+wKyamiq76ImbXxgSNiyvcgKAa+yQXFswLe0PN5XuKJGg+AhN9TW3Eep7iQM KLXrXjaYSTTKHArVnE3Tx8ttYxxhw23kxLXiw9+bT5MMcXQ+0ZLQPSWEPWE8Tza+YGhL /futn5Gc36LJWw7Ra/24Z5C1IsUc8Of7pJic/YCTwbsi+1hVFzoeckd/9BNuqwlQdZjE FeOA== X-Forwarded-Encrypted: i=1; AJvYcCUYx2310W3R67Uhy3AQ4J99zw7pu6hwFeTNL5QBlpIb19EvnJVhPaqGslszaJGPI47qOQoxa1IVI7RN5itJKGV5ePukG6wzKDVYTIhQ X-Gm-Message-State: AOJu0YwrBPDJwJdw7L2SUtb2eUBM7O68jfgXGG9yAy3EUBscsEtS2nKG fwMcL5naP+YPkGaVRwyKSs7fjFENpIHfgquc0b1TMwOMsZXVYW9/ X-Received: by 2002:a50:ab50:0:b0:568:c6a2:f427 with SMTP id t16-20020a50ab50000000b00568c6a2f427mr5624423edc.27.1712567754711; Mon, 08 Apr 2024 02:15:54 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id n2-20020a056402434200b0056de7bee45bsm3854201edc.18.2024.04.08.02.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 02:15:53 -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 3/3] locking/atomic/x86: Introduce arch_try_cmpxchg64() for !CONFIG_X86_CMPXCHG64 Date: Mon, 8 Apr 2024 11:13:58 +0200 Message-ID: <20240408091547.90111-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408091547.90111-1-ubizjak@gmail.com> References: <20240408091547.90111-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit: 6d12c8d308e68 ("percpu: Wire up cmpxchg128") improved emulated cmpxchg8b_emu() library function to return success/failure in a ZF flag. Define arch_try_cmpxchg64() for !CONFIG_X86_CMPXCHG64 targets to override the generic archy_try_cmpxchg() with an optimized target specific implementation that handles ZF flag. The assembly code at the call sites improves from: bf56d: e8 fc ff ff ff call cmpxchg8b_emu bf572: 8b 74 24 28 mov 0x28(%esp),%esi bf576: 89 c3 mov %eax,%ebx bf578: 89 d1 mov %edx,%ecx bf57a: 8b 7c 24 2c mov 0x2c(%esp),%edi bf57e: 89 f0 mov %esi,%eax bf580: 89 fa mov %edi,%edx bf582: 31 d8 xor %ebx,%eax bf584: 31 ca xor %ecx,%edx bf586: 09 d0 or %edx,%eax bf588: 0f 84 e3 01 00 00 je bf771 <...> to: bf572: e8 fc ff ff ff call cmpxchg8b_emu bf577: 0f 84 b6 01 00 00 je bf733 <...> No functional changes 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/include/asm/cmpxchg_32.h b/arch/x86/include/asm/cmpxchg_32.h index fe40d0681ea8..9e0d330dd5d0 100644 --- a/arch/x86/include/asm/cmpxchg_32.h +++ b/arch/x86/include/asm/cmpxchg_32.h @@ -122,6 +122,34 @@ static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64 } #define arch_cmpxchg64_local arch_cmpxchg64_local +#define __arch_try_cmpxchg64_emu(_ptr, _oldp, _new) \ +({ \ + union __u64_halves o = { .full = *(_oldp), }, \ + n = { .full = (_new), }; \ + bool ret; \ + \ + asm volatile(ALTERNATIVE(LOCK_PREFIX_HERE \ + "call cmpxchg8b_emu", \ + "lock; 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(volatile u64 *ptr, u64 *oldp, u64 new) +{ + return __arch_try_cmpxchg64_emu(ptr, oldp, new); +} +#define arch_try_cmpxchg64 arch_try_cmpxchg64 + #endif #define system_has_cmpxchg64() boot_cpu_has(X86_FEATURE_CX8) -- 2.44.0