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=-15.5 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,USER_AGENT_SANE_1 autolearn=unavailable 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 0497CC63798 for ; Thu, 19 Nov 2020 11:07:23 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 7C331246EE for ; Thu, 19 Nov 2020 11:07:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NcGp1PCO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="1bOoK78r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C331246EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=r1d/P9aYcxlLYNFD51nj2A/JD5/nbakg+c6kKiXklYc=; b=NcGp1PCO/hH6El8svgCxQWhdD TnyiwKZwgO55Htpii/uBjskkOUuHkSZnMbOkz30/l+KrpKVMe6yylt8OqSoXOE+5Zvok9Nztsh2Ia KJqn5dDHbXZh7OOqYx1XR4gCQCoTx9Ud5ZhatQWh1mbZjQHufM87fq7ox4rsf1h61MZ+aZzcSVOJs ys3doayMzRjir4M7rAX5QAJLOOsusQzjzcQnNKfb6mgXHIgokdUeFCshrZGW4DKLB3YmrE6jtFB2T 84XwoDb+J0hIuep+CKTGAbrDP4zcsBfK6U/5bZ3pX3i6PszP+kWPakQJb1N/33Wop3WDspQE7fkTy 5UkhJM3fg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfhlX-0002yK-LU; Thu, 19 Nov 2020 11:06:15 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfhlT-0002xC-PJ for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 11:06:13 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B45DC246EE; Thu, 19 Nov 2020 11:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605783970; bh=1olbbRVpFSDdgOVTAb7nOB/GsIqWepxCIAnl/2QcUOY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1bOoK78rMWppAJaCZjoxWoQM+hZk44QoEbwpJXH2UoGsKdR3L8C7Bnoy9diDciCbr lskHGFiMdBgG9dEnf/rpk5/F3ZqVt7HK3sakNJOTCewJ5RdjJBj7SCxUIY8OpU2Uui jy8sydY+NQnzp4aIgIs2Xl1atp6h1m/x7/3+iZnY= Date: Thu, 19 Nov 2020 11:06:04 +0000 From: Will Deacon To: Quentin Perret Subject: Re: [PATCH v3 08/14] arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0 Message-ID: <20201119110603.GB3946@willie-the-truck> References: <20201113093720.21106-1-will@kernel.org> <20201113093720.21106-9-will@kernel.org> <20201119092407.GB2416649@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201119092407.GB2416649@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_060612_052958_E479C882 X-CRM114-Status: GOOD ( 29.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Marc Zyngier , kernel-team@android.com, Vincent Guittot , Juri Lelli , Ingo Molnar , Peter Zijlstra , Catalin Marinas , Johannes Weiner , linux-kernel@vger.kernel.org, Qais Yousef , Li Zefan , Greg Kroah-Hartman , Tejun Heo , Suren Baghdasaryan , Morten Rasmussen , linux-arm-kernel@lists.infradead.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 Thu, Nov 19, 2020 at 09:24:07AM +0000, Quentin Perret wrote: > On Friday 13 Nov 2020 at 09:37:13 (+0000), Will Deacon wrote: > > When exec'ing a 32-bit task on a system with mismatched support for > > 32-bit EL0, try to ensure that it starts life on a CPU that can actually > > run it. > > > > Signed-off-by: Will Deacon > > --- > > arch/arm64/kernel/process.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > > index 1540ab0fbf23..17b94007fed4 100644 > > --- a/arch/arm64/kernel/process.c > > +++ b/arch/arm64/kernel/process.c > > @@ -625,6 +625,16 @@ unsigned long arch_align_stack(unsigned long sp) > > return sp & ~0xf; > > } > > > > +static void adjust_compat_task_affinity(struct task_struct *p) > > +{ > > + const struct cpumask *mask = system_32bit_el0_cpumask(); > > + > > + if (restrict_cpus_allowed_ptr(p, mask)) > > + set_cpus_allowed_ptr(p, mask); > > My understanding of this call to set_cpus_allowed_ptr() is that you're > mimicking the hotplug vs affinity case behaviour in some ways. That is, > if a task is pinned to a CPU and userspace hotplugs that CPU, then the > kernel will reset the affinity of the task to the remaining online CPUs. Correct. It looks to the 32-bit application like all the 64-bit-only CPUs were hotplugged off at the point of the execve(). > I guess that is a sensible fallback path when userspace gives > contradictory commands to the kernel, but that most certainly deserves a > comment :) Good point, I'll add this: diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index dba94af1b840..687d6acf2f81 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -619,6 +619,16 @@ static void adjust_compat_task_affinity(struct task_struct *p) { const struct cpumask *mask = system_32bit_el0_cpumask(); + /* + * Restrict the CPU affinity mask for a 32-bit task so that it contains + * only the 32-bit-capable subset of its original CPU mask. If this is + * empty, then forcefully override it with the set of all + * 32-bit-capable CPUs that we know about. + * + * From the perspective of the task, this looks similar to what would + * happen if the 64-bit-only CPUs were hot-unplugged at the point of + * execve(). + */ if (restrict_cpus_allowed_ptr(p, mask)) set_cpus_allowed_ptr(p, mask); } Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel