Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1201406rwe; Thu, 25 Aug 2022 18:22:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR58VQFHwgY2q9XmDqcxSBD/03Cdg4ImkBvjbizTIQvidobIypg3D8ev6/LAyof/Ob+oXjrN X-Received: by 2002:a05:6a00:148c:b0:52e:a630:afc7 with SMTP id v12-20020a056a00148c00b0052ea630afc7mr1720263pfu.0.1661476960750; Thu, 25 Aug 2022 18:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661476960; cv=none; d=google.com; s=arc-20160816; b=AxEySR9fbqoHuCDu4CKsIPopj5j4Zo+ypqO3VOhf4aZEgPxqA+5XFSN1rhOC2eAFpL 6hSAgkCB07FoIwJ25tPGenzCmCHG8HO+lq2VI9wYw32uNME+rm8lSDJD+4QXctnl4n65 mhoCkeIM28516QKZTQWVdDcGpANtr/4rzgX0XQoAIvJoAXK/H/jO2jgW6lVeKvVr1P/Y xvM66vdvwulArJNFYyHCQHQXk+WRWzNvTbA0aFT0ZnlwEWgXhTpUNABvmTfzbJDFyxnJ Fk34SrBKVw4+RDBw+7EAoqkcH8QO+HaZV+F/zwYrCFuXr6St62qUIA6Cx5Zp2hxsKyqg 1uSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=HTlS4zyVXGxezxjAK9e4wtBj2fsd7iySMzLzaWceqHQ=; b=uys0LRXn/ms6eJd/5Ye6c9jntzVHfXCIX1AlS8o+mHG9VX9IPg1bBhZM64saMNWpZS LqHzm6cFwc9E/mImruSBINfiA0ExyUq6X1oJB6Wqm8f/e0je3ayIUk6ynw1/xn82fYhq 8o4OsYTxKN+rYe1SR9ZuDha9PCbBWqDyepMAfFvhxhGZ9D5nF5pRNkZu1QftltcyQO/p jxhgaDf1BDNO8yX9tR4zHfNoanznkOjFCHxY0GIypOdWdkiNqPvkCwvChjql064B1adU eTBvwYrj40NopAe18j/R1i8UnEskCT8LvVaaEQn4IxFVwnJlL8y1/UOQlehwTKpFATlG LyXQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x4-20020a170902820400b0016ccf06c2aesi358922pln.512.2022.08.25.18.22.29; Thu, 25 Aug 2022 18:22:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233266AbiHZA5s (ORCPT + 99 others); Thu, 25 Aug 2022 20:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiHZA5p (ORCPT ); Thu, 25 Aug 2022 20:57:45 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id B560CC8880 for ; Thu, 25 Aug 2022 17:57:44 -0700 (PDT) Received: (qmail 21882 invoked by uid 1000); 25 Aug 2022 20:57:43 -0400 Date: Thu, 25 Aug 2022 20:57:43 -0400 From: Alan Stern To: Mikulas Patocka Cc: Linus Torvalds , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH] wait_on_bit: add an acquire memory barrier Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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, Aug 25, 2022 at 05:03:40PM -0400, Mikulas Patocka wrote: > From: Mikulas Patocka > > There are several places in the kernel where wait_on_bit is not followed > by a memory barrier (for example, in drivers/md/dm-bufio.c:new_read). On > architectures with weak memory ordering, it may happen that memory > accesses that follow wait_on_bit are reordered before wait_on_bit and they > may return invalid data. > > Fix this class of bugs by introducing a new function "test_bit_acquire" > that works like test_bit, but has acquire memory ordering semantics. > > Signed-off-by: Mikulas Patocka ... > --- linux-2.6.orig/include/asm-generic/bitops/generic-non-atomic.h > +++ linux-2.6/include/asm-generic/bitops/generic-non-atomic.h > @@ -4,6 +4,7 @@ > #define __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H > > #include > +#include > > #ifndef _LINUX_BITOPS_H > #error only can be included directly > @@ -127,6 +128,18 @@ generic_test_bit(unsigned long nr, const > return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); > } > > +/** > + * generic_test_bit - Determine whether a bit is set with acquire semantics Trivial: Name in the kerneldoc isn't the same as the actual function name. (Also, "with acquire semantics" is supposed to modify "Determine", not "is set" -- we don't set bits using acquire semantics. You could change this to "Determine, with acquire semantics, whether a bit is set".) Alan Stern > + * @nr: bit number to test > + * @addr: Address to start counting from > + */ > +static __always_inline bool > +generic_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr) > +{ > + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); > + return 1UL & (smp_load_acquire(p) >> (nr & (BITS_PER_LONG-1))); > +}