Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3771490pxj; Mon, 24 May 2021 14:39:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjrXYsF6SAgihDLEHS1Pzc64iPeikOyk/VAKEuDEJZAR+Mv+SLj98YPiHBwUZ6GzD8FP8M X-Received: by 2002:a17:906:d1ce:: with SMTP id bs14mr25820087ejb.183.1621892352416; Mon, 24 May 2021 14:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621892352; cv=none; d=google.com; s=arc-20160816; b=zTFdELQgMaCIFZ1KMGV9o47i0pFAXzxjr/f0NEtsc1eerTbZQzWOJc+i5mPRv72vfo eZyLkN5+oojCq9T9TgknMZIh1lhCquZRJ27s1Xd/jSGCmsszjWm+ljTB4QxbwyqXUmXf hEl94obMyxlsOWxu/hh/zZur34rzIT3sA41MOMjwGZ8kiPkPsNyUmc+pJ5YB600+br55 GvwjhTQM5dFvi5y0Pc7rNtTKQxMuwSZ0zuIy21BzC0ExwZE9dUcj9dndl2NnQKRpv409 U41Y/bawtAEhi/8jVsfH0oXrE9BnXQ1rQlA2I7pAAfcfuJP7m+s6peBUGQG09DeUcXoW JaIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=U/aRjB9iDOAmxZjRjqRJteJvPvu/8HXDX+TtLEM8EgQ=; b=TtMEX+M3r/HK5CJjK05sDKZh14kJNPxKGa5rwhhxVpkzAP6jF1F5Pc3850FRXNhR1a 7CYgHuUEKx4rRv8O+tmu/TE4dYsIPmuHrKF41nj7fsJYzDunteS8rZlLQ7ytfOn5yXRe uBIgE8t6YfNi1wvuBR7ZFp9JFxhEhNQBdGBEdGx/t4tpErwfA+e/YBcL6wY0Rnz8j0qs A4XV+soNQ3aCrKBQJTO7yT5LB6YJ1eomyjwGlNXvS1Pmxq8aGv9tO97jXaCfTrRP9zq0 9n4oF6J09wZ+Ry2yGSxElSX8StJhzNxRFe/DC6JKqD01zQeGHuP2MQIthRCkUbcgN0VO C9Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gv410r2B; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si13775385ejo.378.2021.05.24.14.38.49; Mon, 24 May 2021 14:39:12 -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=@kernel.org header.s=k20201202 header.b=Gv410r2B; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233798AbhEXVSE (ORCPT + 99 others); Mon, 24 May 2021 17:18:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:37652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232960AbhEXVR7 (ORCPT ); Mon, 24 May 2021 17:17:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 12A3161411; Mon, 24 May 2021 21:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621890991; bh=mRnyDFN9b6UZo7ExIpoCS1Ag3C643iFCcpo734zRGCk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Gv410r2BRUDANSAPKB8ulTCmMz3xgrZs+zFG3qwTKFnj5tX7oM7oEsWRtUuFQjTHw KEZdiVT442rky6YopzQxT6EgGAYl/Qx1mNi2G/A+Khc9b5zxmoqGAEvYGpEy+MEeir lXZP3q3+POQ8YfUU0G5Ph8ht6iGaN5ckwqJ3x3XYMU/aaafJxK5cbMo7yop6llVmLN kP59n1m3Hl0csB/3KZyMrMM7qSgW8GdPFUk3WzXE2OgbuyVnCvbvBzxZ35EUZ/vBif 4O5GxIlWN0fseWNHD4GuUQwQW2zN0RM3F8Zr6VnZZaKk1OusutexIhpklZJOQeYeT6 UFlQVspooUKMg== Date: Mon, 24 May 2021 22:16:25 +0100 From: Will Deacon To: Qais Yousef Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , kernel-team@android.com Subject: Re: [PATCH v6 11/21] sched: Split the guts of sched_setaffinity() into a helper function Message-ID: <20210524211624.GG15545@willie-the-truck> References: <20210518094725.7701-1-will@kernel.org> <20210518094725.7701-12-will@kernel.org> <20210521164101.lwq5wr4mbb32co6l@e107158-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210521164101.lwq5wr4mbb32co6l@e107158-lin.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 21, 2021 at 05:41:01PM +0100, Qais Yousef wrote: > On 05/18/21 10:47, Will Deacon wrote: > > In preparation for replaying user affinity requests using a saved mask, > > split sched_setaffinity() up so that the initial task lookup and > > security checks are only performed when the request is coming directly > > from userspace. > > > > Signed-off-by: Will Deacon > > --- > > kernel/sched/core.c | 110 +++++++++++++++++++++++--------------------- > > 1 file changed, 58 insertions(+), 52 deletions(-) > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 9512623d5a60..808bbe669a6d 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -6788,9 +6788,61 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, > > return retval; > > } > > > > -long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) > > +static int > > +__sched_setaffinity(struct task_struct *p, const struct cpumask *mask) > > { > > + int retval; > > cpumask_var_t cpus_allowed, new_mask; > > + > > + if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) > > + return -ENOMEM; > > + > > + if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) > > + return -ENOMEM; > > Shouldn't we free cpus_allowed first? Oops, yes. Now fixed. Thanks, Will