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 118E2C35FF1 for ; Thu, 13 Mar 2025 22:09:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75540280003; Thu, 13 Mar 2025 18:09:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70541280001; Thu, 13 Mar 2025 18:09:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CEE6280003; Thu, 13 Mar 2025 18:09:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3D556280001 for ; Thu, 13 Mar 2025 18:09:33 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C38F3160667 for ; Thu, 13 Mar 2025 22:09:33 +0000 (UTC) X-FDA: 83217920226.21.1AADC0C Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf03.hostedemail.com (Postfix) with ESMTP id D857020003 for ; Thu, 13 Mar 2025 22:09:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gG3BYre5; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741903772; 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=qBTdqPoSu12tr2nwPV4fS9a5AhyEHy3PWKSx5nynuP4=; b=rp0Ow+YXjtxPm4K/laMHvfMYpnZ36NdjwYVP7EhrMOjUbiRVPYwLdIN+ysrMfK2BQdNxvR GVzwws6WSHrBOnheDID+HMIGlQdsIlNXNSXuutUeUx5pPivQDeF5+nPcPTR1Ptwkz8/5ve ZhwBhGjvfXSm6y/1tQ7S+qrGXqToDpg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741903772; a=rsa-sha256; cv=none; b=ewOCd+FWLhHECUbLosIm5S/mUnPfacrI25zV0UA4Fh/V74gIN54QuvAkxtmz0gzGBCyWbl J0o6NvNw5ojtG89HD0BNeH2DpBIMcam+65FsamRfuon+f4SitO0uLjIBW6MHyLk3YCAP1X QCI98MjsHubOQovCh2IoiP1P55TOJPA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gG3BYre5; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev Date: Thu, 13 Mar 2025 22:09:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741903769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qBTdqPoSu12tr2nwPV4fS9a5AhyEHy3PWKSx5nynuP4=; b=gG3BYre5CXeXwVtjnP98NCfeQAW4t3+UtIOii5OAdw77tDTPVXV5nZV50BADminjqDl/Fq R01mlCJbe5hRikV+DcZdpDtrpqcpKlXpjTp0oZkRPKyPDbSon+nD9kohRpfn7FjWfctv6n dbGl+j3ghGXWqfhaqp2b0sCmu4mj2GA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Brendan Jackman Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Andrew Morton , David Rientjes , Vlastimil Babka , David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport , Junaid Shahid , Reiji Watanabe , Patrick Bellasi Subject: Re: [PATCH RFC 03/11] x86/mm: Add lookup_pgtable_in_pgd() Message-ID: References: <20250313-asi-page-alloc-v1-0-04972e046cea@google.com> <20250313-asi-page-alloc-v1-3-04972e046cea@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250313-asi-page-alloc-v1-3-04972e046cea@google.com> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D857020003 X-Stat-Signature: 1wpxy3y1gk6rks4qc8ygdauq889sdmia X-HE-Tag: 1741903771-796864 X-HE-Meta: U2FsdGVkX19beXRNViTIjuebqhbaozSN1pHAUe99nP72bBYHmhBK94a0NPfXRbORjmNGdW9Pmdo+eG9eInmzFOuvVvm/hLIAaZMDJeal38C6wqGWNmlMb21QmWt2rEL9dlxSNm9Gn5dgUmxY+LOmUB1Tmr0CsbnUSLNr5oNb+wB3rzjLelNKHlCjA09wxvJT3EyVRKk29911j0UMI18IprMO0xSU1CgOVVVe9FYTiHFY/qnV63Ook8GUYkhFWGtPiaVKqI+q+dsWmUtob6h/vJdGX0zS7NoXcIz/fs7Qax1UKUDx2nzk3oOu0DPK7g0wkv9vvDHiVOooeuKbyEOXSo5qmd1oLl3hTMCelmyuY1SwH31kMheGpqe453lR1js1KQPezwY1yDFZcOOJvgBAHya7ooEB74nATJ7sCr5e8cE/l3+qstBeEymmKNoGrUrLgl1h8W5us9xVGwa7m0obVhbO/ovnpxYkvmEdAA/vATgWyJ8vs6eSXo0aGuV9Xow4XO9cryVh1n2lpGzWLXadOxzo+QqpbnL07rnWM52HBZkDGpl7PBK+AYmCEK9YAWu2MPnbRTO1oD7MD5T4d254Cp8Cp6D7NeO4htHhFFVdF20fCuE2Mh6VvRlXFAtzBdKraXVs89PXuJVvOXgmDUwredHOE9/I4AYJyIGMG5ytSQ02F78wneyYToBaq9tgTrKToc6cA0pg+kKOs5MrckGbrc/uLfhtj0oDxLe2PoMXCDA6lapxHQL2Br7jP+xnZHxj4eDm7lFqoKdhxQLhLdsMOMm4f1f1RKiPCDt8eEoaZ2UhMRz552FOpIcsUHAZvdIKtSk9kALE5NwGyFKKcsUROReBpRwbmZwtlD1HlPpmi/ZUBUnFETSFYQjzHfdfBS4VEUWhFWLz1zTu/QgPb5qTqC8f5cdp3z3DELa46ReuY6o4ODNNMNVgSeH0bw5lnaNr8dCBJdErQbw5MGzKteb 1wiOV+Ro FxnXnJBrKlVRar/u14L8AVineEHm+lmFOUrbigchyGhGLwgAGI/rxF/zC78yzjy82O1enqO1ZEKwRvDciQlaNRrvsHTfYB1SIyTl98yDp4296A7TUiSldGEUCHVAnFtCBVxUxF38WOnjPHts3masekDXXTOYNTi7u0Kg8saMA7iOIkmlo26otfBzvD8msanlPAu+lrjeBZOQ/8PtLBxEdBn6YxYlCsSgh5ub2AfyQhud7OzwjyuHkCZqB1MddS6/u3/ocwN/Va5I3EYbNgCDex0UHCkZEE7wupSP4 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 Thu, Mar 13, 2025 at 06:11:22PM +0000, Brendan Jackman wrote: > This is the same thing as lookup_address_in_pgd(), but it returns the > pagetable unconditionally instead of returning NULL when the pagetable > is none. This will be used for looking up and modifying pages that are > *_none() in order to map memory into the ASI restricted address space. > > For a [PATCH], if this logic is needed, the surrounding code should > probably first be somewhat refactored. It now looks pretty repetitive, > and it's confusing that lookup_address_in_pgd() returns NULL when > pmd_none() but note when pte_none(). For now here's something that > works. My first instinct reading this is that lookup_address_in_pgd() should be calling lookup_pgtable_in_pgd(), but I didn't look too closely. > > Signed-off-by: Brendan Jackman > --- > arch/x86/include/asm/pgtable_types.h | 2 ++ > arch/x86/mm/pat/set_memory.c | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h > index 4b804531b03c3ce5cc48f0a75cb75d58b985777a..e09b509e525534f31c986d705e07b25dd9c04cb7 100644 > --- a/arch/x86/include/asm/pgtable_types.h > +++ b/arch/x86/include/asm/pgtable_types.h > @@ -572,6 +572,8 @@ extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, > unsigned int *level); > pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address, > unsigned int *level, bool *nx, bool *rw); > +extern pte_t *lookup_pgtable_in_pgd(pgd_t *pgd, unsigned long address, > + unsigned int *level); > extern pmd_t *lookup_pmd_address(unsigned long address); > extern phys_addr_t slow_virt_to_phys(void *__address); > extern int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > index ef4514d64c0524e5854fa106e3f37ff1e1ba10a2..d066bf2c9e93e126757bd32a7a666db89b2488b6 100644 > --- a/arch/x86/mm/pat/set_memory.c > +++ b/arch/x86/mm/pat/set_memory.c > @@ -658,6 +658,40 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star > return new; > } > > +/* > + * Lookup the page table entry for a virtual address in a specific pgd. Return > + * the pointer to the entry, without implying that any mapping actually exists > + * (the returned value may be zero). > + */ > +pte_t *lookup_pgtable_in_pgd(pgd_t *pgd, unsigned long address, unsigned int *level) > +{ > + p4d_t *p4d; > + pud_t *pud; > + pmd_t *pmd; > + > + *level = PG_LEVEL_256T; > + if (pgd_none(*pgd)) > + return (pte_t *)pgd; > + > + *level = PG_LEVEL_512G; > + p4d = p4d_offset(pgd, address); > + if (p4d_none(*p4d) || p4d_leaf(*p4d) || !p4d_present(*p4d)) > + return (pte_t *)p4d; > + > + *level = PG_LEVEL_1G; > + pud = pud_offset(p4d, address); > + if (pud_none(*pud) || pud_leaf(*pud) || !pud_present(*pud)) > + return (pte_t *)pud; > + > + *level = PG_LEVEL_2M; > + pmd = pmd_offset(pud, address); > + if (pmd_none(*pmd) || pmd_leaf(*pmd) || !pmd_present(*pmd)) > + return (pte_t *)pmd; > + > + *level = PG_LEVEL_4K; > + return pte_offset_kernel(pmd, address); > +} > + > /* > * Lookup the page table entry for a virtual address in a specific pgd. > * Return a pointer to the entry (or NULL if the entry does not exist), > > -- > 2.49.0.rc1.451.g8f38331e32-goog >