lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3971a3fd-c733-4864-851a-87dc9d3f686a@linux.intel.com>
Date: Sat, 11 Oct 2025 14:24:41 +0800
From: Baolu Lu <baolu.lu@...ux.intel.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
 Robin Murphy <robin.murphy@....com>, Kevin Tian <kevin.tian@...el.com>,
 Jason Gunthorpe <jgg@...dia.com>, Jann Horn <jannh@...gle.com>,
 Vasant Hegde <vasant.hegde@....com>, Thomas Gleixner <tglx@...utronix.de>,
 Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
 Dave Hansen <dave.hansen@...el.com>, Alistair Popple <apopple@...dia.com>,
 Peter Zijlstra <peterz@...radead.org>, Uladzislau Rezki <urezki@...il.com>,
 Jean-Philippe Brucker <jean-philippe@...aro.org>,
 Andy Lutomirski <luto@...nel.org>, Yi Lai <yi1.lai@...el.com>,
 iommu@...ts.linux.dev, security@...nel.org, x86@...nel.org,
 linux-mm@...ck.org, linux-kernel@...r.kernel.org,
 Dave Hansen <dave.hansen@...ux.intel.com>
Subject: Re: [PATCH v5 1/8] mm: Add a ptdesc flag to mark kernel page tables

On 10/9/25 03:56, Matthew Wilcox wrote:
> On Fri, Sep 19, 2025 at 01:39:59PM +0800, Lu Baolu wrote:
>> +static inline void ptdesc_set_kernel(struct ptdesc *ptdesc)
>> +{
>> +	struct folio *folio = ptdesc_folio(ptdesc);
>> +
>> +	folio_set_referenced(folio);
>> +}
> So this was the right way to do this at the time.  However, if you look
> at commit 522abd92279a this should now be ...
> 
>   enum pt_flags {
>   	PT_reserved = PG_reserved,
> +	PT_kernel = PG_referenced,
>   	/* High bits are used for zone/node/section */
>   };
> [...]
> 
> +static inline void ptdesc_set_kernel(struct ptdesc *ptdesc)
> +{
> +	set_bit(PT_kernel, &pt->pt_flags.f);
> +}

Thank you for the review comment. I updated the patch like the
following:

diff --git a/include/linux/mm.h b/include/linux/mm.h
index a3f97c551ad8..5abd427b6202 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2940,6 +2940,7 @@ static inline pmd_t *pmd_alloc(struct mm_struct 
*mm, pud_t *pud, unsigned long a
  #endif /* CONFIG_MMU */

  enum pt_flags {
+       PT_kernel = PG_referenced,
         PT_reserved = PG_reserved,
         /* High bits are used for zone/node/section */
  };
@@ -2965,6 +2966,46 @@ static inline bool pagetable_is_reserved(struct 
ptdesc *pt)
         return test_bit(PT_reserved, &pt->pt_flags.f);
  }

+/**
+ * ptdesc_set_kernel - Mark a ptdesc used to map the kernel
+ * @ptdesc: The ptdesc to be marked
+ *
+ * Kernel page tables often need special handling. Set a flag so that
+ * the handling code knows this ptdesc will not be used for userspace.
+ */
+static inline void ptdesc_set_kernel(struct ptdesc *ptdesc)
+{
+       set_bit(PT_kernel, &ptdesc->pt_flags.f);
+}
+
+/**
+ * ptdesc_clear_kernel - Mark a ptdesc as no longer used to map the kernel
+ * @ptdesc: The ptdesc to be unmarked
+ *
+ * Use when the ptdesc is no longer used to map the kernel and no longer
+ * needs special handling.
+ */
+static inline void ptdesc_clear_kernel(struct ptdesc *ptdesc)
+{
+       /*
+        * Note: the 'PG_referenced' bit does not strictly need to be
+        * cleared before freeing the page. But this is nice for
+        * symmetry.
+        */
+       clear_bit(PT_kernel, &ptdesc->pt_flags.f);
+}
+
+/**
+ * ptdesc_test_kernel - Check if a ptdesc is used to map the kernel
+ * @ptdesc: The ptdesc being tested
+ *
+ * Call to tell if the ptdesc used to map the kernel.
+ */
+static inline bool ptdesc_test_kernel(struct ptdesc *ptdesc)
+{
+       return test_bit(PT_kernel, &ptdesc->pt_flags.f);
+}
+
  /**
   * pagetable_alloc - Allocate pagetables
   * @gfp:    GFP flags

Thanks,
baolu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ