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 44B74C3DA49 for ; Tue, 23 Jul 2024 14:52:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B256E6B00B4; Tue, 23 Jul 2024 10:52:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD41C6B00B5; Tue, 23 Jul 2024 10:52:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99BEA6B00B6; Tue, 23 Jul 2024 10:52:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7A5766B00B4 for ; Tue, 23 Jul 2024 10:52:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 30A6A1A0181 for ; Tue, 23 Jul 2024 14:52:28 +0000 (UTC) X-FDA: 82371308376.30.39FB4D7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id A70F740037 for ; Tue, 23 Jul 2024 14:52:25 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hwc+93ye; spf=pass (imf01.hostedemail.com: domain of will@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721746300; 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=kRbpolxxuwAkZM8dDACgsT186UBEQ9LfVwixImu7+Cg=; b=cpz4AuIY/qEx6QTE1cyjjjd92SLzDauMEhsY8EDDxmuXU4WMoQ0xCAlc4l5o1BJ+pCQOn2 0FZrg/eFncNtjfvrReI2KBI4ml4LNilThUK69cdWTHahQ/+6Tz/ymMbWffYSVBzEzO+QND GMYy9ZX1O+gYcURU8uKnm6tVyNP4bZk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721746300; a=rsa-sha256; cv=none; b=GocEdlUbfp9IUxd6ID9g4M4JgUuZZbLfrKiwTbgEUyAC4O6jxJe6ei+Ba8MVeXsarHO+dx WGbMWPYGQr+jgXmPCZwIw/1G9jpyEO3hf+rWFvnIMhohCXdm+NNeOfhfQRuJY42sBzEOYG 7exPC82YJ8qBgtyPpTaO4R82jtz/KyM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hwc+93ye; spf=pass (imf01.hostedemail.com: domain of will@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F287BCE100F; Tue, 23 Jul 2024 14:52:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5473C4AF0C; Tue, 23 Jul 2024 14:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721746339; bh=VmnqdqKrCSERHIJ0PvMmGjnUHXIweS/FQWmsghwZbII=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hwc+93yeX5UV1/+k3tTab46N7ZDq0h3tDis+AbYCW6zO6s6Kg5YYCT8hj7fx/RSqz L0vpArbLio8Hti2WaRX3QCvv5YZnNj693B6ndRzJcvHmeC+IX68eWTWeJvwt442hOo vwQCx/Yf014Q8KvMr7YcwSBhmjBr3YG/saAwRXxq7oZxRS3h0eltbmQK6ISJtid53X lAv3nm5Zm/vlBGodG3xpLV9M0Mjxo9YES4kh/nIS+dEjM1Y/ak5CwEz1q4iXxH3KrQ bav3DJHKd88Zcz0BjQnFfnKGyniHTO6ArU5UOsvtFtKh9PSGsbQQcvlQ5iOOOn6W6q vDDPdW0E+3FJQ== Date: Tue, 23 Jul 2024 15:52:14 +0100 From: Will Deacon To: Ard Biesheuvel Cc: Asahi Lina , linux-mm@kvack.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Catalin Marinas , ryan.roberts@arm.com, mark.rutland@arm.com Subject: Re: LPA2 on non-LPA2 hardware broken with 16K pages Message-ID: <20240723145214.GA26403@willie-the-truck> References: <50360968-13fb-4e6f-8f52-1725b3177215@asahilina.net> <20240718131428.GA21243@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: A70F740037 X-Stat-Signature: qwagmfbc15c66cbanh7ckyk6xajusz5u X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721746345-622304 X-HE-Meta: U2FsdGVkX19ggGM6FcvYhmJRSCirgIysfFBDg1D0/4fe8jasYLnrPrtzGRcebTgQthS3lWEZDjqnCxGwDiHofpq8Hs1XnWebizHsozD6k4kKmQxiXA+EV2CaqpK2Mi7cZe0U/M/4mwqB/Y/Vzzf43VBgH4lSjCIdk/WRj9tk+N/emmNWFyWiYeAzv+MxKOw1QQO1uZXkQk6QtkEPDSWT5w6qmSre22RIc1WGfYEV2pS9Qk9p0chjsahfYdTDvvoXMOmlMfIh4Bi9HN0FmsKIEvoob2tVQhClxSy7aVGyfr31gLk9CAwsc5XBiuES9KpVTfCoR3H1KIdSGpZldBxy9s4eUnS/H0OkKzGz5NXVRQd7tGTkWumfVAGJvFY/sWEjGLst0FxlLLrCgkNL6LdeM6tq0zI5pWhrV/IZKHstxZvWhdTzrvv9x5aQxiLNUzn7XC/gw/9xYrLELyfKfH9y+uwieyAb4SjaPO78zhH1fV5UqOkLJEthg4HRVDox0WNy/eSdkwOyptYpuYs88j1MBxqDWBEB2neo17ymxHfJtpqzYzoaHAUW5wJgimAERRWizZvmDX1nJ36JWxe8fewU1gRsNBur1NNh7QUaKMIt0mlujfbTAcypBTeBiC0JRURmO+vuFbmNVtNKyGaEyIFgGQ22feV6q0lxRUbjgvTnrtBt6NdwINNL9PNyPKZ1GgqB1HOOKS+Xsva4kMcshLL0TgZKTHCqoqoKDMd2mnIAMt+bb87tj1z9/CjNdB9KmJ8J1XZ7fvEdYKgTNVQZAZqi3d4Epc4lHmhoHEmyMd99sal6XRJEXIGtp2+aX+XVX9yy/x3BPCdKtWABzb6SgJ0JwIqagZtMfl/8Kx8eE7r5DZl1y+TSnAG8DDozAxlAEe4Q9E7XpGdhj0MBMM7ZfXZyLG8hdig+y5wguHYzUjwzreO5YKzWXmkhetGZDrrqcDX64q8iPGEseh6iba1Fx81 IU40h5Qm 10kfkrVbx+qCCdQJwB0nGEdOXJvO99uGh9NeokuaChC43qk6lw2Ehvl7CvEKzatmkVoB2dqvseW19XkQH1leGwU3cBlrG04wuSUmNR6qz86GVc/R6vv4PueNiM09pu+7RaUT7jSBH8QZOcx6aS2JiYsQw5uJPsO5lDejzpWwPFtuPwkDfTTD8FqoXCg== 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: Hey Ard, On Fri, Jul 19, 2024 at 11:02:29AM -0700, Ard Biesheuvel wrote: > Thanks for the cc, and thanks to Lina for the excellent diagnosis - > this is really helpful. > > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > > index f8efbc128446..3afe624a39e1 100644 > > --- a/arch/arm64/include/asm/pgtable.h > > +++ b/arch/arm64/include/asm/pgtable.h > > @@ -1065,6 +1065,13 @@ static inline bool pgtable_l5_enabled(void) { return false; } > > > > #define p4d_offset_kimg(dir,addr) ((p4d_t *)dir) > > > > +static inline > > +p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, unsigned long addr) > > This is in the wrong place, I think - we already define this for the > 5-level case (around line 1760). Hmm, I'm a bit confused. In my tree, we have one definition at line 1012, which is for the 5-level case (i.e. guarded by '#if CONFIG_PGTABLE_LEVELS > 4'). I'm adding a new one at line 1065, which puts it in the '#else' block and means we use an override instead of the problematic generic version when we're folding. > We'll need to introduce another version for the 4-level case, so > perhaps, to reduce the risk of confusion, we might define it as > > static inline > p4d_t *p4d_offset_lockless_folded(pgd_t *pgdp, pgd_t pgd, unsigned long addr) > { > ... > } > #ifdef __PAGETABLE_P4D_FOLDED > #define p4d_offset_lockless p4d_offset_lockless_folded > #endif Renaming will definitely make this easier on the eye, so I'll do that. I don't think I need the 'ifdef' though. > > +{ > > We might add > > if (pgtable_l4_enabled()) > pgdp = &pgd; > > here to preserve the existing 'lockless' behavior when PUDs are not > folded. The code still needs to be 'lockless' for the 5-level case, so I don't think this is necessary. Yes, we'll load the same entry multiple times, but it should be fine because they're in the context of a different (albeit folded) level. > > + return p4d_offset(pgdp, addr); > > +} > > +#define p4d_offset_lockless p4d_offset_lockless > > + > > #endif /* CONFIG_PGTABLE_LEVELS > 4 */ > > > > I suggest we also add something like the below so we can catch these > issues more easily > > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -874,9 +874,26 @@ static inline phys_addr_t p4d_page_paddr(p4d_t p4d) > > static inline pud_t *p4d_to_folded_pud(p4d_t *p4dp, unsigned long addr) > { > + /* > + * The transformation below does not work correctly for descriptors > + * copied to the stack. > + */ > + VM_WARN_ON((u64)p4dp >= VMALLOC_START && !__is_kernel((u64)p4dp)); Hmm, this is a bit coarse. Does it work properly with the fixmap? Will