Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1554182iol; Fri, 10 Jun 2022 09:46:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjvkowpJ67yoOVf8so6lVR27szCsxyYxmXIQkjqmR9D/KnufFuK83TOpCtFm3V5gj0gOBv X-Received: by 2002:a17:90b:1d90:b0:1e8:5a98:d591 with SMTP id pf16-20020a17090b1d9000b001e85a98d591mr621227pjb.126.1654879588300; Fri, 10 Jun 2022 09:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654879588; cv=none; d=google.com; s=arc-20160816; b=ypn2poEg+AoerZg0awFGDkQwxcC+yeIRjfe4gr3nkSOQOjJZgRDSy16l1oEQgPjB+r 14xEmtQ/7/Rn+viHTgtZDr78CSvYF++gc2CxaNGvQUm4Kr30UtBvwzlBkUdDGIDo3sXg gAMfJ24NlXpdAZSK6j7ZVVh7JILjhrx+ANle6Mc7hBWUPFzcFnxlCihb6WgId7QvNZnB KeQnkOLtz6WyFchwH7Oi3lMROBs9zLZJnq4IfSDOm/1nJWEq2BG4RFhKVLF/CJbTdJ6B zAzfF+xp+xPkowmsyLEoo/3P6SbMKUGurOcDPJ1RXLBtqjbNG+yDig2lWk/xYRaS/aiD rpbg== 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=bhv02q67MOioDvIeN4y+a/ybeIh94RUFpBdk0EW721Q=; b=NkhcPhmV1Kpo1i2O0KUpPXy7hmVxLzz/bHB6/c5RMN7sgL03MXuQMHO0oTLuaJLBav PIYdJxFVjU26+TvVY6aPHxIPrLjK0LRNeIrdjTTJ9PxSYr27i679VyuPwFyzcDCgoYZz U/Cyan1dtSwA/X2MVFiBZ9V1omIzNQRfVrx9K5YtksCXNjeOM7m1W49m/H+j1Rm+5WMP EShHFfVHLfN64DlOe79RyYZ5r7nRqwxETnTdqOwB7R7KhM0jscNOT3KULzNADWWb0pDs JbdsEa4kghUmYSer8Mua389SYdeHKppxJ302cP17pr6NlQcNsz6FMwma24gsFDcNQ+q2 Z26g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gTSqAdTJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a63770d000000b003facc630945si32104059pgc.135.2022.06.10.09.46.13; Fri, 10 Jun 2022 09:46:28 -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=@google.com header.s=20210112 header.b=gTSqAdTJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349740AbiFJQd6 (ORCPT + 99 others); Fri, 10 Jun 2022 12:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349255AbiFJQde (ORCPT ); Fri, 10 Jun 2022 12:33:34 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779D457111 for ; Fri, 10 Jun 2022 09:33:15 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id p13so47865327ybm.1 for ; Fri, 10 Jun 2022 09:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bhv02q67MOioDvIeN4y+a/ybeIh94RUFpBdk0EW721Q=; b=gTSqAdTJjftykkKV3LvI3BgIEdnFPO1tIX2Ja3yrYtQNH7qkYO5md+ofkXUFp0r5AW G6gcWOkM0lg+gYk1xVlJLK69IVjiD2uEY/paaLVpsJSAUJr3ix3CnTM3jTjnVHIGrITZ 8qOTeStSyYFo4Xt1uIWq/JcAZJafn7HdU8yhoSTqaMMSwSE/odkOqaPLeyUKWL5sO4fY YvCEOzFgGYsioj0kFMpYKr9Y6KDxyzq/x30hfjgDctRhz4XpICUW+ZTe11KlQpTSKF0Q MmwpTmp6Vj4zz6mr/A1YZvGF2iMEYWObj9GWEHshf9njpmcmcbzr60kAblJRSOIE1DnE +7SA== 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=bhv02q67MOioDvIeN4y+a/ybeIh94RUFpBdk0EW721Q=; b=5m0ZPBFOOvm0kvvlxU1ke/DOKs3/461Md8zuKkTdwmegoGmXxGUJr934rph1m9gwb/ wQ+99wkbOBoHB+S6bmjBbkiuP2TzlJIJq3ySzoOZa0VoF01Qw8d6mxvwgey9/3ITqs3Z 42b6JxJMNjuncj3BbTv1xm9FpMKIqy86f12HjgHOWO4x6tb63al7rUwO0wbolqJkmOWn doYivLSYN5uMorewWqGFX3dRVJ1jj7fZsQtdD9kwNZD/WkwBbipQ/nvMB7PSdIGDUct1 hVfC6GesD279UnVZFnrgFjOoQJMzgFA4e/KHfSCEi8KQfThnkvTab9D/NyLv8aiModX3 uDoQ== X-Gm-Message-State: AOAM530+Ey80ujXWhiTaoIMPgvib/HMCp61/SePF5MzKqhjulExnT18U +FdyljuGCKTixrbYJTjt20DESZyqad52TgLHgi3bZQ== X-Received: by 2002:a05:6902:102c:b0:663:32b8:4b24 with SMTP id x12-20020a056902102c00b0066332b84b24mr37019234ybt.1.1654878793763; Fri, 10 Jun 2022 09:33:13 -0700 (PDT) MIME-Version: 1.0 References: <20220610113427.908751-1-alexandr.lobakin@intel.com> <20220610113427.908751-3-alexandr.lobakin@intel.com> <22042c14bc6a437d9c6b235fbfa32c8a@intel.com> In-Reply-To: <22042c14bc6a437d9c6b235fbfa32c8a@intel.com> From: Marco Elver Date: Fri, 10 Jun 2022 18:32:36 +0200 Message-ID: Subject: Re: [PATCH v2 2/6] bitops: always define asm-generic non-atomic bitops To: "Luck, Tony" Cc: Andy Shevchenko , "Lobakin, Alexandr" , Arnd Bergmann , Yury Norov , Mark Rutland , Matt Turner , Brian Cain , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , "David S. Miller" , Kees Cook , "Peter Zijlstra (Intel)" , Borislav Petkov , Greg Kroah-Hartman , "linux-alpha@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-ia64@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-sh@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Fri, 10 Jun 2022 at 18:02, Luck, Tony wrote: > > > > +/** > > > + * generic_test_bit - Determine whether a bit is set > > > + * @nr: bit number to test > > > + * @addr: Address to start counting from > > > + */ > > > > Shouldn't we add in this or in separate patch a big NOTE to explain that this > > is actually atomic and must be kept as a such? > > "atomic" isn't really the right word. The volatile access makes sure that the > compiler does the test at the point that the source code asked, and doesn't > move it before/after other operations. It's listed in Documentation/atomic_bitops.txt. It is as "atomic" as READ_ONCE() or atomic_read() is. Though you are right that the "atomicity" of reading one bit is almost a given, because we can't really read half a bit. The main thing is that the compiler keeps it "atomic" and e.g. doesn't fuse the load with another or elide it completely, and then transforms the code in concurrency-unfriendly ways. Like READ_ONCE() and friends, test_bit(), unlike non-atomic bitops, may also be used to dependency-order some subsequent marked (viz. atomic) operations. > But there is no such thing as an atomic test_bit() operation: > > if (test_bit(5, addr)) { > /* some other CPU nukes bit 5 */ > > /* I know it was set when I looked, but now, could be anything */ The operation itself is atomic, because reading half a bit is impossible. Whether or not that bit is modified concurrently is a different problem. Thanks, -- Marco