Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp416686pxj; Fri, 11 Jun 2021 02:20:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzktkt5Mj1QLPAdvwR0DmnBvy8X3zDoBLl9w7qChTC3rn+ydDWGor4os2FT1ofEjAjwn7Wj X-Received: by 2002:a17:906:1982:: with SMTP id g2mr2834370ejd.184.1623403252791; Fri, 11 Jun 2021 02:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623403252; cv=none; d=google.com; s=arc-20160816; b=W/cSHKQ+8WlQOhBhdMH0MCpobwRNKWYDUhuZr6RHpXjW8wjZ/P4+lyGwHPTPP9tj4j tOZNA/t61MclHtO60+b+T3gG9ePmCvNIrK+dk2HR83FTprJBvL/IPe/Lcw2aVBsvtfO0 SaWb4lQ9Ssg3tmw7c4KVCJw6MJF3ONrGqsvInLRY9jxK1rn7YXVTJdr283gLBguL6zU5 0NzxcAyF9cdvj085eAGfONjwPIDVkon+TSFlwRGIN14qh4WJPLO5Dj0DC715tPwYXDvP t3eHQ+7l3Hry0Q/LoGc8dyFC90rMAV7a9UXj1vxXS6JPvGin//srbd5nOzc4/1pf3AD0 /cUg== 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=VRsxyhUzNq+bximvKKHZ6Ie96yF5VpZWocAQ4FUjmQA=; b=SrS6dycpLOhWWod3J0uzY2TTdvJ6CY3s9mjDXqU/KKLBFc8bclV6Ck62ERobemIMs9 JBm7KEEWnzisfLFk/cUgvGxf0LgTA/l+WweCiT2NWBdF7txx1iKsCG2YzKQ12y9BMKi3 QPnAG0zehpeMzNk8+whUhsQ8mC74yGZTK8f97PtuVx3vHWEGhmsrMEiZPQK/9+3MevnA DIHCdSli5iwWkSeLS0GyXPQAwUfXaBDwbQB8aDm2vAqXF2L06s1re6QCvGPmuJiGEoob 5zvTq+vZQQJWbhPrNIBCB0ohNLQBVu6qESpTP9EIKuM7VJ5l8vdhp/xrMBOyXLQKFdkV obOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t26si4331300edf.425.2021.06.11.02.20.28; Fri, 11 Jun 2021 02:20:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbhFKJTf (ORCPT + 99 others); Fri, 11 Jun 2021 05:19:35 -0400 Received: from foss.arm.com ([217.140.110.172]:52752 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231229AbhFKJTf (ORCPT ); Fri, 11 Jun 2021 05:19:35 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 202D114BF; Fri, 11 Jun 2021 02:17:37 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.8.83]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64C8D3F719; Fri, 11 Jun 2021 02:17:32 -0700 (PDT) Date: Fri, 11 Jun 2021 10:17:24 +0100 From: Mark Rutland To: Marco Elver Cc: LKML , Benjamin Herrenschmidt , Boqun Feng , Borislav Petkov , Catalin Marinas , Dmitry Vyukov , Ivan Kokshaysky , jonas@southpole.se, juri.lelli@redhat.com, Russell King - ARM Linux admin , Andy Lutomirski , Matt Turner , Ingo Molnar , Michal Simek , Michael Ellerman , "Paul E. McKenney" , Paul Mackerras , Peter Zijlstra , Richard Henderson , shorne@gmail.com, stefan.kristiansson@saunalahti.fi, Thomas Gleixner , vincent.guittot@linaro.org, Will Deacon Subject: Re: [RFC PATCH 01/10] thread_info: add helpers to snapshot thread flags Message-ID: <20210611091724.GA78056@C02TD0UTHF1T.local> References: <20210609122001.18277-1-mark.rutland@arm.com> <20210609122001.18277-2-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 10, 2021 at 11:01:34AM +0200, Marco Elver wrote: > On Wed, 9 Jun 2021 at 14:20, Mark Rutland wrote: > > > > We have common helpers to manipulate individual thread flags, but where > > code wants to check several flags at once, it must open code reading > > current_thread_info()->flags and operating on a snapshot. > > > > As some flags can be set remotely it's necessary to use READ_ONCE() to > > get a consistent snapshot even when IRQs are disabled, but some code > > forgets to do this. Generally this is unlike to cause a problem in > > practice, but it is somewhat unsound, and KCSAN will legitimately warn > > that there is a data race. > > > > To make it easier to do the right thing, and to highlight that > > concurrent modification is possible, let's add a new helpers to snapshot > > the flags, which should be used in preference to plain reads. > > Subsequent patches will move existing code to use the new helpers. > > > > Signed-off-by: Mark Rutland > > Cc: Boqun Feng > > Cc: Dmitry Vyukov > > Cc: Marco Elver > > Cc: Paul E. McKenney > > Cc: Peter Zijlstra > > Cc: Will Deacon > > Acked-by: Marco Elver Thanks! > > --- > > include/linux/thread_info.h | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h > > index 157762db9d4b..f3769842046d 100644 > > --- a/include/linux/thread_info.h > > +++ b/include/linux/thread_info.h > > @@ -117,6 +117,11 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) > > return test_bit(flag, (unsigned long *)&ti->flags); > > } > > > > +static inline unsigned long read_ti_thread_flags(struct thread_info *ti) > > +{ > > + return READ_ONCE(ti->flags); > > +} > > + > > Are some of the callers 'noinstr'? I haven't seen it in this series > yet, but if yes, then not inlining (which some compilers may do with > heavier instrumentation) might cause issues and this could be > __always_inline. That's a very good point; I agree it should be __always_inline, and I'll fix that up for the next spin. Thanks, Mark.