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 7EE1EC25B06 for ; Mon, 15 Aug 2022 13:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbiHONhN (ORCPT ); Mon, 15 Aug 2022 09:37:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiHONhJ (ORCPT ); Mon, 15 Aug 2022 09:37:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 031AC18E02 for ; Mon, 15 Aug 2022 06:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660570628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=32k6I+/xYZGpQQqB1hUqbRU4UEx2mYMpvxUY9GY4ewM=; b=SQkTFh8CrHz9JnbRioGM0cn09LrJvV/yS9cAcQTyb7WxP6fjzUNi4Wi+5m7BOpnbnGyqMV Exlobd7dgHeWA7z11D5wUCVT4SJePu9DMSqKqhY2Y6EzUaiXRcAti7QGruMGTwyRHE2An6 s4o0L3BYgMdEoLROoWD+56tIwm+9MdU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-159-PHusKD7EP0-UqdTUxTXh2g-1; Mon, 15 Aug 2022 09:37:04 -0400 X-MC-Unique: PHusKD7EP0-UqdTUxTXh2g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06B28811E80; Mon, 15 Aug 2022 13:37:03 +0000 (UTC) Received: from [10.18.17.215] (dhcp-17-215.bos.redhat.com [10.18.17.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 577BB112131B; Mon, 15 Aug 2022 13:37:02 +0000 (UTC) Message-ID: Date: Mon, 15 Aug 2022 09:37:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask Content-Language: en-US To: Peter Zijlstra 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 References: <20220812203929.364341-1-longman@redhat.com> <20220812203929.364341-3-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/15/22 04:58, Peter Zijlstra wrote: > 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. > Right. pi_lock should be enough for read access. Will make the change. Thanks, Longman