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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 73932C63697 for ; Thu, 19 Nov 2020 16:49:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08C19238E6 for ; Thu, 19 Nov 2020 16:49:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="eta835dk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbgKSQtD (ORCPT ); Thu, 19 Nov 2020 11:49:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:58146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727872AbgKSQtC (ORCPT ); Thu, 19 Nov 2020 11:49:02 -0500 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 BCB9F2222A; Thu, 19 Nov 2020 16:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605804541; bh=ns5wbhzeg4dC+prdvUnrFedGYQBDPfSDGGmE4SbJ3+Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eta835dkweaJOJWk+x5fJSzaMhHso83BKyz95Plc9rIVVdCgqlGnbf7WRksirWXWY Cy1gXw49m8aDDLvuDnvwSKwh/WkPXLCh7d5V4iroJ/XYC1D1tOKmqtg8FGX/w442qm 26RnQbEr+8NB3BcUcIqD5gGKgQrmbq3vJUnLoC90= Date: Thu, 19 Nov 2020 16:48:55 +0000 From: Will Deacon To: Peter Zijlstra Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , kernel-team@android.com Subject: Re: [PATCH v3 08/14] arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0 Message-ID: <20201119164853.GF4582@willie-the-truck> References: <20201113093720.21106-1-will@kernel.org> <20201113093720.21106-9-will@kernel.org> <20201119161448.GR3121392@hirez.programming.kicks-ass.net> <20201119162822.GA4582@willie-the-truck> <20201119164203.GU3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201119164203.GU3121392@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 05:42:03PM +0100, Peter Zijlstra wrote: > On Thu, Nov 19, 2020 at 04:28:23PM +0000, Will Deacon wrote: > > On Thu, Nov 19, 2020 at 05:14:48PM +0100, Peter Zijlstra wrote: > > > On Fri, Nov 13, 2020 at 09:37:13AM +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); > > > > > > This silently destroys user state, at the very least that ought to go > > > with a WARN or something. Ideally SIGKILL though. What's to stop someone > > > from doing a sched_setaffinity() right after the execve, same problem. > > > So why bother.. > > > > It's no different to CPU hot-unplug though, is it? From the perspective of > > the 32-bit task, the 64-bit-only cores were hot-unplugged at the point of > > execve(). Calls to sched_setaffinity() for 32-bit tasks will reject attempts > > to include 64-bit-only cores. > > select_fallback_rq() has a printk() in to at least notify things went > bad. But I don't particularly like the current hotplug semantics; I've > wanted to disallow the hotplug when it would result in this case, but > computing that is tricky. It's one of those things that's forever on the > todo list ... :/ I know that feeling... I can add a printk() in the case where we override the mask (I think taking the subset is ok), since I agree that it would be better if userspace had had the foresight to avoid the situation in the first place. > > I initially wanted to punt this all to userspace, but one of the big > > problems with that is when a 64-bit task is running on a CPU only capable > > of running 64-bit tasks and it execve()s a 32-bit task. At the point, we > > have to do something because we can't even run the new task for it to do > > a sched_affinity() call (and we also can't deliver SIGILL). > > Userspace can see that one coming though... I suppose you can simply > make the execve fail before the point of no return. If we could open up all the 32-bit apps out there and fix them, then I'd be more sympathetic, but the reality is that we need to run existing binaries on these stupid systems and exec'ing 32-bit payloads from 64-bit tasks is something that we need to continue to support. If it makes things any better, all of this stuff is off by default and gated on a cmdline option. Will 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 282AFC63697 for ; Thu, 19 Nov 2020 16:59:25 +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 602D0241A6 for ; Thu, 19 Nov 2020 16:59:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qLUACdHe"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="eta835dk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 602D0241A6 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=6E6pH/eK8MTdDISy3BOh1Yc2WqYPRPXfeqlPUpjnVjk=; b=qLUACdHe0DwjQD8YpzYlhnYI1 YmzyBwJfbpFZvN04t6STMl0JIN1nU8bEbkE3oSvafqvyP/Y14gc+MdSd0bQcBnVCQ170+jRliaX/K ovKXMgBl7GyHgWqUv4SActA1Finkoxs0zOtz16CL6UlL3kvedRrOd76+IZ+20MYIcEFNtoOuVONXg L+55rgY0Kfm2RDiY6mhfSb9oq8LoZOK8rX5N1k1yX9bD17IC1SfqMOnXz7ho4I8kAbJNHpl482WLg ztjyCnyP5XoWqfnVGz68ItmMKSdekjihVHE92OrEZVsz5Wcpx+yg7j2o7NUPQyvkzqa98ZfNh2qPG t1AE7Z7+A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfnEd-0005Nf-LT; Thu, 19 Nov 2020 16:56:42 +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 1kfn7H-00023W-Vc for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:49:06 +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 BCB9F2222A; Thu, 19 Nov 2020 16:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605804541; bh=ns5wbhzeg4dC+prdvUnrFedGYQBDPfSDGGmE4SbJ3+Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eta835dkweaJOJWk+x5fJSzaMhHso83BKyz95Plc9rIVVdCgqlGnbf7WRksirWXWY Cy1gXw49m8aDDLvuDnvwSKwh/WkPXLCh7d5V4iroJ/XYC1D1tOKmqtg8FGX/w442qm 26RnQbEr+8NB3BcUcIqD5gGKgQrmbq3vJUnLoC90= Date: Thu, 19 Nov 2020 16:48:55 +0000 From: Will Deacon To: Peter Zijlstra Subject: Re: [PATCH v3 08/14] arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0 Message-ID: <20201119164853.GF4582@willie-the-truck> References: <20201113093720.21106-1-will@kernel.org> <20201113093720.21106-9-will@kernel.org> <20201119161448.GR3121392@hirez.programming.kicks-ass.net> <20201119162822.GA4582@willie-the-truck> <20201119164203.GU3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201119164203.GU3121392@hirez.programming.kicks-ass.net> 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_114904_603644_0461C52E X-CRM114-Status: GOOD ( 37.01 ) 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 , Quentin Perret , Catalin Marinas , Johannes Weiner , linux-kernel@vger.kernel.org, Qais Yousef , Ingo Molnar , 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 05:42:03PM +0100, Peter Zijlstra wrote: > On Thu, Nov 19, 2020 at 04:28:23PM +0000, Will Deacon wrote: > > On Thu, Nov 19, 2020 at 05:14:48PM +0100, Peter Zijlstra wrote: > > > On Fri, Nov 13, 2020 at 09:37:13AM +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); > > > > > > This silently destroys user state, at the very least that ought to go > > > with a WARN or something. Ideally SIGKILL though. What's to stop someone > > > from doing a sched_setaffinity() right after the execve, same problem. > > > So why bother.. > > > > It's no different to CPU hot-unplug though, is it? From the perspective of > > the 32-bit task, the 64-bit-only cores were hot-unplugged at the point of > > execve(). Calls to sched_setaffinity() for 32-bit tasks will reject attempts > > to include 64-bit-only cores. > > select_fallback_rq() has a printk() in to at least notify things went > bad. But I don't particularly like the current hotplug semantics; I've > wanted to disallow the hotplug when it would result in this case, but > computing that is tricky. It's one of those things that's forever on the > todo list ... :/ I know that feeling... I can add a printk() in the case where we override the mask (I think taking the subset is ok), since I agree that it would be better if userspace had had the foresight to avoid the situation in the first place. > > I initially wanted to punt this all to userspace, but one of the big > > problems with that is when a 64-bit task is running on a CPU only capable > > of running 64-bit tasks and it execve()s a 32-bit task. At the point, we > > have to do something because we can't even run the new task for it to do > > a sched_affinity() call (and we also can't deliver SIGILL). > > Userspace can see that one coming though... I suppose you can simply > make the execve fail before the point of no return. If we could open up all the 32-bit apps out there and fix them, then I'd be more sympathetic, but the reality is that we need to run existing binaries on these stupid systems and exec'ing 32-bit payloads from 64-bit tasks is something that we need to continue to support. If it makes things any better, all of this stuff is off by default and gated on a cmdline option. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel