Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp649257ioo; Thu, 26 May 2022 11:18:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNzPVQz9giDCi18Cm0p57H7tfpDSiblPd5FRaUJoQV2HeQBdwj6Spd6d1YsRLw5INu4SG/ X-Received: by 2002:a17:902:c412:b0:161:af8b:f472 with SMTP id k18-20020a170902c41200b00161af8bf472mr38571178plk.56.1653589096448; Thu, 26 May 2022 11:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653589096; cv=none; d=google.com; s=arc-20160816; b=yHns0j/cBnPsiSvfh7U9UOD6zFsIl/1MFIt/NFI79YnSBGmAHS+SLjfLWNm6NQclns Zs6n4ucLGStLwvJ6riJCQCgk/Q4Y3vd6F9QrR+HpAHMGIPGw7rJKTheWEMUSa2n0gBrm Q8A7f0YCWxhlwoSpEDuewNkweJa1IgB+fo/84DhpwA8pm+bHVorQhYvMHuRMdzRxFvSr MiZS2LTz5wCSsgFGgq/7sL2VNmVprt+vtLyHzWaceJ630k9bWsMB/d8TJFPeXc0OT1P5 /iftfhUwGp1+nUsqOisw0BVrQpROjsUVeJAXh5rNxDWO7HamujhMsH3jCamGdUrw3ZZZ G1Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=h+o2YcuR2VIuL1UcC5E0Jvkv57l2f8KjFuaXh67xM/k=; b=HC54TRjtXsvteUB4PIbnErf9DiwWc9FgpWzcYnaxG+CR+3dhbGb4DBnHJv7LkaRbCE b5vcdKLzZgivAmDgDpWNsn7HOj9t+qOfhOAquB+aDLfE7km7gdCqklkuiSMvLbVcuNfl SBpmVhTSVjzH/D10xKMzNufg0yYZyMjlu9gY/6ui/DJFYJY5DIJi5Ur/Ck8IDlV9Vrj9 95L6+7gr1MCqswB4hyhlLCFZc0Hpw6BaFuRs1gV7V38m7Tk/UFKEXp8jkZmMQm9vOedw LlyZmCtY9Wv12GuPLKzqKmGCBTIjM5FWuiJKcz2/8RkgVVAiovCirZtwYmhv+FK7ibs8 5Ifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JYxigCBp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j62-20020a638b41000000b0039f0abb51a1si3573909pge.1.2022.05.26.11.18.04; Thu, 26 May 2022 11:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JYxigCBp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346846AbiEZJMo (ORCPT + 99 others); Thu, 26 May 2022 05:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344454AbiEZJMi (ORCPT ); Thu, 26 May 2022 05:12:38 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B78386B09A for ; Thu, 26 May 2022 02:12:36 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id s5so1160317qvo.12 for ; Thu, 26 May 2022 02:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h+o2YcuR2VIuL1UcC5E0Jvkv57l2f8KjFuaXh67xM/k=; b=JYxigCBpH8ZBGuIF6XPxWncLxt4T9ombQz+1bTQhxmfqLCyZtjAbkj/phuGtv3T6rF il3/VxueO45ALW2WgNwuURLOiMvOyQrB0bIYiiuePMpbIclxu9Bjm9im4kDhHqdrESzX 0OYw9hnhdk4efGRrvdw79p/v7ps5IzYrsClYaPbtVw8k0gGUVMGZYXdvLbJaG8TyOAzy I8Q4GnivoWW4eUyVk9/RGp0XusvSJL4dE34Wnv27kQ5C3Gs7bkGteT0cOegbLZILYb9+ vdZ4H9EkDUNknA3bzk+QA7gCxh/xUYCuu3BR2OO+DRxK9St6DZ6giJQ6DgBu55kLFaKd Uw/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h+o2YcuR2VIuL1UcC5E0Jvkv57l2f8KjFuaXh67xM/k=; b=FNZecuqJHk6Gv5MVVOrA4LnV7picwy7hnOhHf09hC4T483Az2mV76oPZWKL109vONB HAwz/D5IQsi97Ca3+hgRn4F92xB6R4Ist+zcG1qfB08jw4dcW9guxuM6gnYV1xoJsBRU TwcpxaTlx3HWbkL9IA3N1IdaDX0cKjZpbO3Nq/AHRlMw7VLvny280y2UHvLxTNG/2WIC D0O4ztLSaHT1QVO+chAC4ZthBFRsjjRNKOJsvJXGUnO/E9UzJXNMKucCl6csXpoblL5/ 0d9o2yB/PcQRIHsJqxKYHQrdG5Th7OwVp04KfeZMLgqt1eyM2fj7ReS6xOTuilcYLdkr L1tA== X-Gm-Message-State: AOAM53330fRbV1kWX2bUdLGsGD7RnGS/iHWSsjt6ag4Q6rZy0vy+x5oR MZx60MPG+/8pM1CkoGMPqyuMP+Otuj4RFlk1irw= X-Received: by 2002:a05:6214:20e6:b0:45d:403f:7a90 with SMTP id 6-20020a05621420e600b0045d403f7a90mr29051949qvk.1.1653556355924; Thu, 26 May 2022 02:12:35 -0700 (PDT) MIME-Version: 1.0 References: <20220525144013.6481-1-ubizjak@gmail.com> <20220525144013.6481-3-ubizjak@gmail.com> <48001b3d732b418eb5f36def228c2c9d@AcuMS.aculab.com> In-Reply-To: <48001b3d732b418eb5f36def228c2c9d@AcuMS.aculab.com> From: Uros Bizjak Date: Thu, 26 May 2022 11:12:24 +0200 Message-ID: Subject: Re: [PATCH 2/2] locking/lockref/x86: Enable ARCH_USE_CMPXCHG_LOCKREF for X86_32 && X86_CMPXCHG64 To: David Laight Cc: Linus Torvalds , "the arch/x86 maintainers" , Linux Kernel Mailing List , Peter Zijlstra , Thomas Gleixner , "Waiman.Long@hp.com" , Paul McKenney Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 26, 2022 at 10:30 AM David Laight wrote: > > From: Linus Torvalds > > Sent: 25 May 2022 17:30 > > > > On Wed, May 25, 2022 at 7:40 AM Uros Bizjak wrote: > > > > > > + select ARCH_USE_CMPXCHG_LOCKREF if X86_64 || (X86_32 && X86_CMPXCHG64) > > > > Ugh. That looks pointlessly complicated. X86_64 already enables > > X86_CMPXCHG64 afaik, so you can just say > > > > select ARCH_USE_CMPXCHG_LOCKREF if X86_CMPXCHG64 > > > > which is much clearer: CMPXCHG_LOCKREF needs CMPXCHG64, and the > > Kconfig option says exactly that. > > > > That said, this also makes me wonder if we should just make cmpxchg8b > > requirement unconditional. > > > > Googling around, it looks like Windows NT stopped booting on CPUs > > without cmpxchg8b in version 5.1. That was in 2001. > > > > Here we are, 21 years later, and we still ostensibly try to support > > CPUs without it, but I doubt it's worth it. > > > > So maybe time to just say "we require cmpxchg8b". > > > > In fact, I think we have effectively done that already for years, since we have > > > > config X86_CMPXCHG64 > > def_bool y > > depends on X86_PAE || ... > > > > iow, enabling X86_PAE will force-enable CMPXCHG8B due to the wider > > page table entries. > > > > And I would assume that all distros basically do that anyway (but I do > > not have a 32-bit distro around to check). > > > > It would mean that we would finally drop support for i486 (and > > possibly some Pentium clones, but afaik a number of them did actually > > support cmpxchg8b even if they didn't report it in cpuid). > > Perhaps there could be a non-smp implementation of cmpxchg8b > that just disables interrupts? > > While I have used a dual 486 I doubt Linux would run ever > have on it. The same is probably true for old dual Pentiums. > > I think there are still some 486-class embedded cpu that include > a few of the newer instructions (usually things like rdtsc). > But they won't be smp. The above solution is already implemented when X86_CMPXCHG64 is not defined. Please see arch/x86/include/asm/cmpxchg_32.h, where in this case we have: #define arch_cmpxchg64(ptr, o, n) \ ({ \ __typeof__(*(ptr)) __ret; \ __typeof__(*(ptr)) __old = (o); \ __typeof__(*(ptr)) __new = (n); \ alternative_io(LOCK_PREFIX_HERE \ "call cmpxchg8b_emu", \ "lock; cmpxchg8b (%%esi)" , \ X86_FEATURE_CX8, \ "=A" (__ret), \ "S" ((ptr)), "0" (__old), \ "b" ((unsigned int)__new), \ "c" ((unsigned int)(__new>>32)) \ : "memory"); \ __ret; }) Without CX8, the code will be patched to the call to cmpxchg8b_emu, defined in arch/x86/lib/cmpxchg8b_emu.S. I think that the solution with CONFIG_X86_CMPXCHG64 is quite good. When defined, arch_cmpxchg64 defines the real CMPXCHG8B instruction. Without the config flag, the above definition is compiled in and the code is patched to either the call or the real instruction during runtime. Also, the config flag makes difference only in arch/x86/include/asm/cmpxchg_32.h, and with try_cmpxchg64 fallbacks, one can still use cmpxchg64/try_cmpxchg64 even when the HW doesn't support CMPXCHG8B natively. Uros.