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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B1FDC00140 for ; Mon, 15 Aug 2022 08:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241108AbiHOI7H (ORCPT ); Mon, 15 Aug 2022 04:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230468AbiHOI7E (ORCPT ); Mon, 15 Aug 2022 04:59:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 882B820F52; Mon, 15 Aug 2022 01:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=X1Kk26FPg2jYHPvOS2s86o6tg2NoWayeOGSNjQIPE58=; b=rrsHTcvocEIu0njvXEnAoUncHw AS8nABWuqLfAfD9VJMaEUGdsPEJ6kYvuCMWpfsWtcOVdcgS0yDq2so/auNex1lo3b1l6EBiz2H7h5 NRkFPzXHaXQvqlbKU5ttS02AFmeez9M8vGC1NNAV0wFw0S4T3yJdCPkBjDsW2KQfslXbjE/NEqssj f9cq4h6K4C70MeFyHRLsAX+QmnXpXTHZi7RP1qjvmoqokKDoIZbCmo/IK3DvgtjQ0IK5zuO60R3rS 7U9oklNwG/wZSAIno6+HiHbYyQZ1M8VkmMjRq/p84b3nPW99Z97XtmaKhTucauSBDxImFJUpG0LrD VM5HOJpA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNVvw-005Zjh-Lw; Mon, 15 Aug 2022 08:58:52 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id D8FEE980153; Mon, 15 Aug 2022 10:58:51 +0200 (CEST) Date: Mon, 15 Aug 2022 10:58:51 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tejun Heo , Zefan Li , Johannes Weiner , Will Deacon , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH v3 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask Message-ID: References: <20220812203929.364341-1-longman@redhat.com> <20220812203929.364341-3-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220812203929.364341-3-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 12, 2022 at 04:39:28PM -0400, Waiman Long wrote: > Since accessing the content of the user_cpus_ptr requires lock protection > to ensure its validity, provide a helper function copy_user_cpus_mask() > to facilitate its reading. Sure, but this is atrocious. > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -2619,6 +2619,24 @@ void release_user_cpus_ptr(struct task_struct *p) > kfree(clear_user_cpus_ptr(p)); > } > > +/* > + * Return the copied mask pointer or NULL if user mask not available. > + */ > +struct cpumask *copy_user_cpus_mask(struct task_struct *p, > + struct cpumask *user_mask) > +{ > + struct rq_flags rf; > + struct rq *rq = task_rq_lock(p, &rf); > + struct cpumask *mask = NULL; > + > + if (p->user_cpus_ptr) { > + cpumask_copy(user_mask, p->user_cpus_ptr); > + mask = user_mask; > + } > + task_rq_unlock(rq, p, &rf); > + return mask; > +} For reading the mask you only need one of those locks, and I would suggest p->pi_lock is much less contended than rq->lock.