From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19883C4338F for ; Tue, 27 Jul 2021 16:25:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7BC461BA1 for ; Tue, 27 Jul 2021 16:25:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D7BC461BA1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DSbZ3m2s7wmD9uR6SBBpypjp1LogjQC0KI/3rM0vcl4=; b=xunwU3A2gjxe8k K3LCUw8UDcueP6pxuHISePHv/zcD8LaJyx/GJi6m+fBbSGzTpPDqR09veg8vTAhTW447fi66Cvd5D MjSYB3C16NH3UpWbVoQPtVF5uBlsXbAsRHU2kgha5b4swfuIhbUrjt4OZlW1U36hMxDz1euT8xKVk EKzJnled6wxP110A8O84YM9ETKew01jPWUoCKe0R3wV7yHZHUgRlLgU3sG+16nUJoXGRSEX+WbWd9 y1Zx7BxnzFda/Bf+jJ2VRe+VOeLWMK7RGepg/IyNdfZEsDOBV1Ua+uDhmlIJ9jgGUb/qXThCxdqNG AK8GW/Du+aytDCwgI/Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Prf-00FND8-CS; Tue, 27 Jul 2021 16:23:31 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Prc-00FNCJ-8R for linux-arm-kernel@lists.infradead.org; Tue, 27 Jul 2021 16:23:29 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id C769E61B93; Tue, 27 Jul 2021 16:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627403007; bh=Kmx4YqSFfCeTWZsfTwDQpSXyGw2cgAovhs1crpCknaM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=jrp4mUDoOskJf03UesWUpSZrUCr8fNLu7wyCmLjT2jhdI7FNnXF/FRx5bUVlV9jwN gpLaLz0UJvVdBAInSPa2WYJPd2wXERH+GY26jqaa0YQZQKjUmL/inD+2gAINZEAvt1 FnI9tScDStvOpzQLhxnykVE15zUXqCRZqloNfIPE9+Idnjn4J6SN9kxppw0h4B+puN 4/9Q7zfvPqFJ8KTvESzj8oAJwypWGhl4g0qVHgKwP7ewWqHG20rZe8ldPkV4UAKaPU DGsUdVc7bsAtQYsWEB7mtLLJcp8KAI9CeGc61UcnHdb5GS8saiOcvE/Hcr8V56QjQI nlsl1RnEGJJsg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 902E55C099F; Tue, 27 Jul 2021 09:23:27 -0700 (PDT) Date: Tue, 27 Jul 2021 09:23:27 -0700 From: "Paul E. McKenney" To: Valentin Schneider Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rt-users@vger.kernel.org, Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Steven Rostedt , Daniel Bristot de Oliveira , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Anshuman Khandual , Vincenzo Frascino , Steven Price , Ard Biesheuvel Subject: Re: [PATCH 1/3] sched: Introduce is_pcpu_safe() Message-ID: <20210727162327.GA4397@paulmck-ThinkPad-P17-Gen-1> References: <20210721115118.729943-1-valentin.schneider@arm.com> <20210721115118.729943-2-valentin.schneider@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210721115118.729943-2-valentin.schneider@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210727_092328_358803_2F1F4C7E X-CRM114-Status: GOOD ( 21.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: paulmck@kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jul 21, 2021 at 12:51:16PM +0100, Valentin Schneider wrote: > Some areas use preempt_disable() + preempt_enable() to safely access > per-CPU data. The PREEMPT_RT folks have shown this can also be done by > keeping preemption enabled and instead disabling migration (and acquiring a > sleepable lock, if relevant). > > Introduce a helper which checks whether the current task can safely access > per-CPU data, IOW if the task's context guarantees the accesses will target > a single CPU. This accounts for preemption, CPU affinity, and migrate > disable - note that the CPU affinity check also mandates the presence of > PF_NO_SETAFFINITY, as otherwise userspace could concurrently render the > upcoming per-CPU access(es) unsafe. > > Signed-off-by: Valentin Schneider Acked-by: Paul E. McKenney > --- > include/linux/sched.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index efdbdf654876..7ce2d5c1ad55 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1707,6 +1707,16 @@ static inline bool is_percpu_thread(void) > #endif > } > > +/* Is the current task guaranteed not to be migrated elsewhere? */ > +static inline bool is_pcpu_safe(void) > +{ > +#ifdef CONFIG_SMP > + return !preemptible() || is_percpu_thread() || current->migration_disabled; > +#else > + return true; > +#endif > +} > + > /* Per-process atomic flags. */ > #define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */ > #define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */ > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel