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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B96A5CD3431 for ; Wed, 4 Sep 2024 11:43:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DC5C8D0254; Wed, 4 Sep 2024 07:43:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 464E68D0253; Wed, 4 Sep 2024 07:43:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3060D8D0254; Wed, 4 Sep 2024 07:43:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 104338D0253 for ; Wed, 4 Sep 2024 07:43:15 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B2A84412BA for ; Wed, 4 Sep 2024 11:43:14 +0000 (UTC) X-FDA: 82526869908.10.2CD44C7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 14BA518000C for ; Wed, 4 Sep 2024 11:43:12 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kDOCm13e; spf=pass (imf06.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725450169; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3BTxzmFXXtBSc6qofBMwvBr17mPhTOeoD6JUn7O6HBE=; b=hPhCcQGFq7BokdF0WrzhXYY5MeeW31py9daj9DJftee/5rQGBd4J5Ul+ZukblLlWOKWb7j WABbhDOqg4Xqr8L3GLeWZTo43Z+QLTcmfYG9XAd7ke76wAk5TuePvek69ayfxcTHZDVFkp jVBNvHE4YZT1+XdEyBfIBd7agxAGGpU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kDOCm13e; spf=pass (imf06.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725450169; a=rsa-sha256; cv=none; b=fljKOf6SSrNpalOpvrUw8NtafcN40LsEkH4TQWtZLm6RuaArNZke68w/9DdCUEfUTIk42o /FFrfkcY6XhEZPls1lBMlEnDRVryPItJtjKH7hVlJ8drFlhgPPHM14XuKPunagtX/hXb87 Dffg0NN9T9cTLNy4PtQi1aF1fBaDa+A= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C98F4A440EC; Wed, 4 Sep 2024 11:43:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2318C4CEC2; Wed, 4 Sep 2024 11:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725450190; bh=1R47JLECqfMcUivgiQR6XDvQF6Jb0RlGzKzhZ5bCKsk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kDOCm13euF7DxBt8JcfDA8RsjG4MZJhZ27+NJPvRYOHFOIFVEJc0l6JGicavkhqFp ocM/Hc7Ei/JeuUSqdamuIxsSmM5JmLH2Z52OgD5iztKVCIjp7sX8PLLUEu9j6MPmCH BYX7tb0KyzLaSS647l0ocymi+ZWWv+J7JXsEwNWQp+rJTW0T0DXaaa93jW3QN9FGLb biQUrzgmKdTHsim1RB78jWVNvmDQb4gv4JOoem65A64jZ/hpremFoloDb9L+1PbLXL pOr5XcN9nzcv5FCk0AbNAEX4DfKr02w9IdPgHqDsgUC/Z58ctJv9XU8IOftgkkb4Yv RQfwAY8aQDCkA== Date: Wed, 4 Sep 2024 12:43:02 +0100 From: Will Deacon To: Joey Gouly Cc: Catalin Marinas , linux-arm-kernel@lists.infradead.org, nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v5 06/30] arm64: context switch POR_EL0 register Message-ID: <20240904114301.GA13550@willie-the-truck> References: <20240822151113.1479789-7-joey.gouly@arm.com> <20240823144531.GH32156@willie-the-truck> <20240823170835.GA1181@willie-the-truck> <20240827113803.GB4318@willie-the-truck> <20240903145413.GB3669886@e124191.cambridge.arm.com> <20240904102254.GA13280@willie-the-truck> <20240904113221.GA3891700@e124191.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240904113221.GA3891700@e124191.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspam-User: X-Stat-Signature: yoq3i8wnwfq7t3yp396bo8joa3ppqrpq X-Rspamd-Queue-Id: 14BA518000C X-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4yFq1tG0SiEjboQBw5EKjl2pTz47OPetTxx5KmbsTSoR8KLC8HtoXB6ci8s0B5Ga23QIIDJbWxnz3wU2CekHtVsixTaJGtGP4nYn4nqqpOi6xQhWBynxL0yo4qMrPPDsxa8JqQO4p4YbMEwywkVp2GZtpZKidvWSkA+L9MgmZQL8lINF3irGpVIayoD8ZqzUsA+s60BCBRMEXQa2stWlxETCvb5rieXIdVXxXUkcK9M3qkokE4NvRT7NlFTDC/w585TQUN2qtneHRhfqwvxub6h8qhxt8YoOiKNsyH5vwQ5G2vKT1j X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Sep 04, 2024 at 12:32:21PM +0100, Joey Gouly wrote: > On Wed, Sep 04, 2024 at 11:22:54AM +0100, Will Deacon wrote: > > On Tue, Sep 03, 2024 at 03:54:13PM +0100, Joey Gouly wrote: > > > On Mon, Sep 02, 2024 at 08:08:08PM +0100, Catalin Marinas wrote: > > > > On Tue, Aug 27, 2024 at 12:38:04PM +0100, Will Deacon wrote: > > > > > On Fri, Aug 23, 2024 at 07:40:52PM +0100, Catalin Marinas wrote: > > > > > > On Fri, Aug 23, 2024 at 06:08:36PM +0100, Will Deacon wrote: > > > > > > > On Fri, Aug 23, 2024 at 05:41:06PM +0100, Catalin Marinas wrote: > > > > > > > > On Fri, Aug 23, 2024 at 03:45:32PM +0100, Will Deacon wrote: > > > > > > > > > On Thu, Aug 22, 2024 at 04:10:49PM +0100, Joey Gouly wrote: > > > > > > > > > > +static void permission_overlay_switch(struct task_struct *next) > > > > > > > > > > +{ > > > > > > > > > > + if (!system_supports_poe()) > > > > > > > > > > + return; > > > > > > > > > > + > > > > > > > > > > + current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); > > > > > > > > > > + if (current->thread.por_el0 != next->thread.por_el0) { > > > > > > > > > > + write_sysreg_s(next->thread.por_el0, SYS_POR_EL0); > > > > > > > > > > + /* ISB required for kernel uaccess routines when chaning POR_EL0 */ > > > > > > > > > > > > > > > > > > nit: typo "chaning". > > > > > > > > > > > > > > > > > > But more substantially, is this just to prevent spurious faults in the > > > > > > > > > context of a new thread using a stale value for POR_EL0? > > > > > > > > > > > > > > > > Not just prevent faults but enforce the permissions from the new > > > > > > > > thread's POR_EL0. The kernel may continue with a uaccess routine from > > > > > > > > here, we can't tell. > > > > [...] > > > > > > > So what do we actually gain by having the uaccess routines honour this? > > > > > > > > > > > > I guess where it matters is more like not accidentally faulting because > > > > > > the previous thread had more restrictive permissions. > > > > > > > > > > That's what I wondered initially, but won't the fault handler retry in > > > > > that case? > > > > > > > > Yes, it will retry and this should be fine (I assume you are only > > > > talking about the dropping ISB in the context switch). > > > > > > > > For the case of running with a more permissive stale POR_EL0, arguably it's > > > > slightly more predictable for the user but, OTOH, some syscalls like > > > > readv() could be routed through GUP with no checks. As with MTE, we > > > > don't guarantee uaccesses honour the user permissions. > > > > > > > > That said, at some point we should sanitise this path anyway and have a > > > > single ISB at the end. In the meantime, I'm fine with dropping the ISB > > > > here. > > > > > > > > > > commit 3141fb86bee8d48ae47cab1594dad54f974a8899 > > > Author: Joey Gouly > > > Date: Tue Sep 3 15:47:26 2024 +0100 > > > > > > fixup! arm64: context switch POR_EL0 register > > > > > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > > > index a3a61ecdb165..c224b0955f1a 100644 > > > --- a/arch/arm64/kernel/process.c > > > +++ b/arch/arm64/kernel/process.c > > > @@ -515,11 +515,8 @@ static void permission_overlay_switch(struct task_struct *next) > > > return; > > > > > > current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); > > > - if (current->thread.por_el0 != next->thread.por_el0) { > > > + if (current->thread.por_el0 != next->thread.por_el0) > > > write_sysreg_s(next->thread.por_el0, SYS_POR_EL0); > > > - /* ISB required for kernel uaccess routines when chaning POR_EL0 */ > > > - isb(); > > > - } > > > } > > > > What about the one in flush_poe()? I'm inclined to drop that as well. > > Yes I guess that one can be removed too. Catalin any comments? > > > > > > Will, do you want me to re-send the series with this and the permissions > > > diff from the other thread [1], > > > or you ok with applying them when you pull it in? > > > > I'll have a crack now, but if it fails miserably then I'll let you know. > > Thanks! Just to make sure, you should pick the patch up from > > https://lore.kernel.org/linux-arm-kernel/20240903152937.GA3768522@e124191.cambridge.arm.com/ > > Not the one I linked to in [1] in my previous e-mail. Right, there's quite a lot I need to do: - Uncorrupt your patches - Fix the conflict in the kvm selftests - Drop the unnecessary ISBs - Fix the ESR checking - Fix the el2_setup labels - Reorder the patches - Drop the patch that is already in kvmarm Working on it... Will