Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp345784pxj; Thu, 10 Jun 2021 02:07:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynz5FCnj83cXQjflOa1+/9reyayOHKudlMQXGPFqCi9QaKmQ6eesBNW2wMvO/shIiII/GN X-Received: by 2002:a17:906:f854:: with SMTP id ks20mr3492408ejb.67.1623316037416; Thu, 10 Jun 2021 02:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623316037; cv=none; d=google.com; s=arc-20160816; b=R8lpvsaEl4AIS8bAQ7ZORu4f+xN5oXjznmIwHO/5bPgMkT4gxyO6ZdKmTYORZEgRJr cwdBkFepQWbkHWjjTpIED3M0TcNciYXnosfT07mYwgNK+WyiGPZ6XsUBtg14b8a2Lou/ RmsSBYiKG3PYJyN9q6nTuFJ0ux4/ihHnQbQOWojdyQmmDPLyoMV6pes7+jSahuA2JStT Gttkg4U3DD1wzpBf+pRKCzL+j8r2lYyNEx74t7X8ITzgnOv3tXi/n6Z7jGtuJspeovcN NOBj1Tm0uuA6iVEFX3Re8Wr+uMeTFHsA/GDlHI9ozxRhOtuji+HIFniJlluDrSNDToSs ewiA== 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=3OrvGQveIDsGXb2Fmo6K6lcHqiuK7RhEdI4kF1LgsIA=; b=RZg0a6Q5ZNsQ6bIirwRtvuVJyBL1yl72Q25S93cnUodHtx7D7w94sWldqmg1l32QG7 RBloT4DF/djM4hL3gLyeiblVlZPGTPh10QUp55q4Ifzz8fpyxCjNfSrXEmh5vdybyp1G il3kMCZZjWW/vofkvkGcYtgJHJiJTdAH29lBhDfsSUujHZm3C5260VHjQ/ZWEFtbFZNS W6zZ9yirfYoawLb4uH0/4JVLw7e5+7FQNWA3KdV5oQRBGlX8imRz1rs5PaIuVG5EUxvZ YuA1jilhhHID8BtmLMEEVWOV+PZrTaPEVZVeLgSnmTchJ0lRJ3uCoJYDLnIPhoS+pr9U nlGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pvtJLauy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si2045016ejo.362.2021.06.10.02.06.54; Thu, 10 Jun 2021 02:07:17 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=pvtJLauy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbhFJJFB (ORCPT + 99 others); Thu, 10 Jun 2021 05:05:01 -0400 Received: from mail-ot1-f49.google.com ([209.85.210.49]:38636 "EHLO mail-ot1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbhFJJEx (ORCPT ); Thu, 10 Jun 2021 05:04:53 -0400 Received: by mail-ot1-f49.google.com with SMTP id j11-20020a9d738b0000b02903ea3c02ded8so13213889otk.5 for ; Thu, 10 Jun 2021 02:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3OrvGQveIDsGXb2Fmo6K6lcHqiuK7RhEdI4kF1LgsIA=; b=pvtJLauyJKFPxO+q8mK2qtn3JqB8gZmw5DuqaqwMquP8ATD5cS4N8fVPVRIM+CWFKK l2VyxisLie6n1Z0Mm0Z/ylt8qf3RBBbfeBJaEbYrhyI/9C4+syRD3d/uxnjvREmvmfaQ iMvtY2a7wTt/wE5NF7BRunETB/J8LJhq/NElG5ayfolyAi+FLasrE26kQHgACYI7xx9F OeNAXHeLsJ0HDrcd/4rvDh5my7KoVBLT4JrTShr0jc7iYxllgr6c6VjwxckBCrDr9eIQ zWZ0gGRTn6MLeIdrU2MYOnyzV4kw+ZTImVDAihSTSUsgn5NIjj0VzBJtJ8fHhQvfyXRt osmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3OrvGQveIDsGXb2Fmo6K6lcHqiuK7RhEdI4kF1LgsIA=; b=PWmE/YmXQJG1yHlZCnm/EPIMoUu31drIguEmP9TBD9Ibhp5m1+IhxfQ/CEjIpf+BpM uliKSiink/lEfQZmnhToCAR9BDdgrGGKtBWqlgH8yhG9bO2bMEKRs9HjpfRxtXxpxs6k OEFULA7Xvph66J8f/bU8mxZc55W86ZqyQ8e6kBCuo0lon3Ui0to0Qi3twFpbHxB0z8Py 1jxDlgEmO5YdcPSg1i1oZg+VXH+hN8HHBqEZOAr3lxPzNG4YNfUrrKVbbnTVd7Jc+wUz m5Mr0vK8ekG6GVQ8hvkTeAkdXteVmVhZp9HwEyT+VyqlVMnGGeyj/tdpmN8TigfP3BOS 3Ilg== X-Gm-Message-State: AOAM533lu71TMvuCDsL/UPDjnQTYvWtcxzadV3LShDW1Wdm9AHtAso9F 2JEwNDbrZ54tQ/fmpsd4hAyztjfP9djCXDnx7uWvtw== X-Received: by 2002:a05:6830:349b:: with SMTP id c27mr1601650otu.251.1623315705592; Thu, 10 Jun 2021 02:01:45 -0700 (PDT) MIME-Version: 1.0 References: <20210609122001.18277-1-mark.rutland@arm.com> <20210609122001.18277-2-mark.rutland@arm.com> In-Reply-To: <20210609122001.18277-2-mark.rutland@arm.com> From: Marco Elver Date: Thu, 10 Jun 2021 11:01:34 +0200 Message-ID: Subject: Re: [RFC PATCH 01/10] thread_info: add helpers to snapshot thread flags To: Mark Rutland 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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. Thanks, -- Marco