Skip to contentSkip to conversation

x86/crash: Use set_memory_p instead of __set_memory_prot

PATCH Applied Coiby Xu 3 participants 7 messages Jan 6 – Jan 14

Subsystems (4)
lore
Share & tools
lore

Coiby Xu

author
#0 lore raw

PATCH 1/2 x86/crash: Use set_memory_p instead of __set_memory_prot

set_memory_p has been introduced since commit 030ad7af9437 ("x86/mm:
Regularize set_memory_p() parameters and make non-static"). There is no need to use __set_memory_prot.

---
 arch/x86/kernel/machine_kexec_64.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/kernel/machine_kexec_64.c +1 -4
index 201137b98fb8..0590d399d4f1 100644
@@ -673,10 +673,7 @@ static void kexec_mark_dm_crypt_keys(bool protect)
 		if (protect)
 			set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
 		else
-			__set_memory_prot(
-				(unsigned long)phys_to_virt(start_paddr),
-				nr_pages,
-				__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
+			set_memory_p((unsigned long)phys_to_virt(start_paddr), nr_pages);
 	}
 }
 

base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67

Signature · 1 line
2.52.0
author
#1 lore raw

PATCH 2/2 Reapply "x86/mm: Remove unused __set_memory_prot()"

This reverts commit e1e6cd01d93359e22be84a23c8bb24ee4e04e142 as __set_memory_prot is unsued (again) after set_memory_p is used instead for x86_64 kdump LUKS support (CONFIG_CRASH_DM_CRYPT).

---
 arch/x86/include/asm/set_memory.h |  2 --
 arch/x86/mm/pat/set_memory.c      | 13 -------------
 2 files changed, 15 deletions(-)
arch/x86/include/asm/set_memory.h +0 -2
index 61f56cdaccb5..8d9f1c9aaa4c 100644
@@ -4,7 +4,6 @@
 
 #include <asm/page.h>
 #include <asm-generic/set_memory.h>
-#include <asm/pgtable.h>
 
 #define set_memory_rox set_memory_rox
 int set_memory_rox(unsigned long addr, int numpages);
@@ -38,7 +37,6 @@ int set_memory_rox(unsigned long addr, int numpages);
  * The caller is required to take care of these.
  */
 
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot);
 int _set_memory_uc(unsigned long addr, int numpages);
 int _set_memory_wc(unsigned long addr, int numpages);
 int _set_memory_wt(unsigned long addr, int numpages);
arch/x86/mm/pat/set_memory.c +0 -13
index 6c6eb486f7a6..40581a720fe8 100644
@@ -2145,19 +2145,6 @@ static inline int cpa_clear_pages_array(struct page **pages, int numpages,
 		CPA_PAGES_ARRAY, pages);
 }
 
-/*
- * __set_memory_prot is an internal helper for callers that have been passed
- * a pgprot_t value from upper layers and a reservation has already been taken.
- * If you want to set the pgprot to a specific page protocol, use the
- * set_memory_xx() functions.
- */
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot)
-{
-	return change_page_attr_set_clr(&addr, numpages, prot,
-					__pgprot(~pgprot_val(prot)), 0, 0,
-					NULL);
-}
-
 int _set_memory_uc(unsigned long addr, int numpages)
 {
 	/*
Signature · 1 line
2.52.0
maintainer
#2 lore raw
In reply to Coiby Xu
Quoted 8 lines · Coiby Xu

set_memory_p has been introduced since commit 030ad7af9437 ("x86/mm:
Regularize set_memory_p() parameters and make non-static"). There is no need to use __set_memory_prot.

---
 arch/x86/kernel/machine_kexec_64.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Why aren't those a single patch?

---
From: Coiby Xu <[email protected]>
Date: Tue, 6 Jan 2026 17:50:58 +0800
Subject: [PATCH] x86/crash: Use set_memory_p() instead of __set_memory_prot()

set_memory_p() is available to use outside of its compilation unit since:

030ad7af9437 ("x86/mm: Regularize set_memory_p() parameters and make non-static").

There is no use for __set_memory_prot() anymore so drop it too.

[ bp: Massage commit message. ]

---
 arch/x86/include/asm/set_memory.h  |  1 -
 arch/x86/kernel/machine_kexec_64.c |  5 +----
 arch/x86/mm/pat/set_memory.c       | 13 -------------
 3 files changed, 1 insertion(+), 18 deletions(-)
arch/x86/include/asm/set_memory.h +0 -1
index 61f56cdaccb5..4362c26aa992 100644
@@ -38,7 +38,6 @@ int set_memory_rox(unsigned long addr, int numpages);
  * The caller is required to take care of these.
  */
 
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot);
 int _set_memory_uc(unsigned long addr, int numpages);
 int _set_memory_wc(unsigned long addr, int numpages);
 int _set_memory_wt(unsigned long addr, int numpages);
arch/x86/kernel/machine_kexec_64.c +1 -4
index 201137b98fb8..0590d399d4f1 100644
@@ -673,10 +673,7 @@ static void kexec_mark_dm_crypt_keys(bool protect)
 		if (protect)
 			set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
 		else
-			__set_memory_prot(
-				(unsigned long)phys_to_virt(start_paddr),
-				nr_pages,
-				__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
+			set_memory_p((unsigned long)phys_to_virt(start_paddr), nr_pages);
 	}
 }
 
arch/x86/mm/pat/set_memory.c +0 -13
index 6c6eb486f7a6..40581a720fe8 100644
@@ -2145,19 +2145,6 @@ static inline int cpa_clear_pages_array(struct page **pages, int numpages,
 		CPA_PAGES_ARRAY, pages);
 }
 
-/*
- * __set_memory_prot is an internal helper for callers that have been passed
- * a pgprot_t value from upper layers and a reservation has already been taken.
- * If you want to set the pgprot to a specific page protocol, use the
- * set_memory_xx() functions.
- */
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot)
-{
-	return change_page_attr_set_clr(&addr, numpages, prot,
-					__pgprot(~pgprot_val(prot)), 0, 0,
-					NULL);
-}
-
 int _set_memory_uc(unsigned long addr, int numpages)
 {
 	/*
Signature · 7 lines
2.51.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#3 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 8 lines · Coiby Xu

set_memory_p has been introduced since commit 030ad7af9437 ("x86/mm:
Regularize set_memory_p() parameters and make non-static"). There is no need to use __set_memory_prot.

---
 arch/x86/kernel/machine_kexec_64.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Why aren't those a single patch?

Hi Borislav,

I thought smaller patches are easier to review. But seems it's unnecessary for this case.

Thanks for squashing the two commits and also updating the commit message! I notice you also added a Link tag. Does it mean there is no need for me to re-send your new patch as v2?

Quoted 84 lines

---
From: Coiby Xu <[email protected]>
Date: Tue, 6 Jan 2026 17:50:58 +0800
Subject: [PATCH] x86/crash: Use set_memory_p() instead of __set_memory_prot()

set_memory_p() is available to use outside of its compilation unit since:

030ad7af9437 ("x86/mm: Regularize set_memory_p() parameters and make non-static").

There is no use for __set_memory_prot() anymore so drop it too.

[ bp: Massage commit message. ]

---

arch/x86/include/asm/set_memory.h  |  1 -
arch/x86/kernel/machine_kexec_64.c |  5 +----
arch/x86/mm/pat/set_memory.c       | 13 -------------
3 files changed, 1 insertion(+), 18 deletions(-)
arch/x86/include/asm/set_memory.h +0 -1
index 61f56cdaccb5..4362c26aa992 100644
@@ -38,7 +38,6 @@ int set_memory_rox(unsigned long addr, int numpages);
 * The caller is required to take care of these.
 */
 
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot);
 int _set_memory_uc(unsigned long addr, int numpages);
 int _set_memory_wc(unsigned long addr, int numpages);
 int _set_memory_wt(unsigned long addr, int numpages);
arch/x86/kernel/machine_kexec_64.c +1 -4
index 201137b98fb8..0590d399d4f1 100644
@@ -673,10 +673,7 @@ static void kexec_mark_dm_crypt_keys(bool protect)
 		if (protect)
 			set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
 		else
-			__set_memory_prot(
-				(unsigned long)phys_to_virt(start_paddr),
-				nr_pages,
-				__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
+			set_memory_p((unsigned long)phys_to_virt(start_paddr), nr_pages);
 	}
 }
 
arch/x86/mm/pat/set_memory.c +0 -13
index 6c6eb486f7a6..40581a720fe8 100644
@@ -2145,19 +2145,6 @@ static inline int cpa_clear_pages_array(struct page **pages, int numpages,
 		CPA_PAGES_ARRAY, pages);
 }
 
-/*
- * __set_memory_prot is an internal helper for callers that have been passed
- * a pgprot_t value from upper layers and a reservation has already been taken.
- * If you want to set the pgprot to a specific page protocol, use the
- * set_memory_xx() functions.
- */
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot)
-{
-	return change_page_attr_set_clr(&addr, numpages, prot,
-					__pgprot(~pgprot_val(prot)), 0, 0,
-					NULL);
-}
-
 int _set_memory_uc(unsigned long addr, int numpages)
 {
 	/*
Signature · 7 lines
2.51.0

-- 
Regards/Gruss,
   Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Signature · 2 lines
Best regards,
Coiby
maintainer
#4 lore raw
Quoted 2 lines · Coiby Xu

I thought smaller patches are easier to review. But seems it's unnecessary for this case.

Right, especially if the two patches do one logical thing - removing __set_memory_prot(). Then one patch is better.

Quoted 3 lines

Thanks for squashing the two commits and also updating the commit message! I notice you also added a Link tag. Does it mean there is no need for me to re-send your new patch as v2?

Yap, I can queue it, no need.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#5 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 2 lines · Coiby Xu

I thought smaller patches are easier to review. But seems it's unnecessary for this case.

Right, especially if the two patches do one logical thing - removing __set_memory_prot(). Then one patch is better.

I see, thanks for the explanation!

Quoted 6 lines
Quoted 4 lines

Thanks for squashing the two commits and also updating the commit message! I notice you also added a Link tag. Does it mean there is no need for me to re-send your new patch as v2?

Yap, I can queue it, no need.

Great, thanks for taking care of the patch!

Quoted 9 lines

Thx.

Signature · 4 lines
Regards/Gruss,
   Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Signature · 2 lines
Best regards,
Coiby
merge bot Applied
#6 lore raw

[tip: x86/cleanups] x86/crash: Use set_memory_p() instead of __set_memory_prot()

In reply to Coiby Xu
The following commit has been merged into the x86/cleanups branch of tip:

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     8a4e92b3260ae7664d0531e1b42c38d336e7717a
Gitweb:        https://git.kernel.org/tip/8a4e92b3260ae7664d0531e1b42c38d336e7717a
Author:        Coiby Xu <[email protected]>
AuthorDate:    Tue, 06 Jan 2026 17:50:58 +08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 13 Jan 2026 15:28:59 +01:00

x86/crash: Use set_memory_p() instead of __set_memory_prot()

set_memory_p() is available to use outside of its compilation unit since:

030ad7af9437 ("x86/mm: Regularize set_memory_p() parameters and make non-static").

There is no use for __set_memory_prot() anymore so drop it too.

[ bp: Massage commit message. ]

---
 arch/x86/include/asm/set_memory.h  |  1 -
 arch/x86/kernel/machine_kexec_64.c |  5 +----
 arch/x86/mm/pat/set_memory.c       | 13 -------------
 3 files changed, 1 insertion(+), 18 deletions(-)
arch/x86/include/asm/set_memory.h +0 -1
index 61f56cd..4362c26 100644
@@ -38,7 +38,6 @@ int set_memory_rox(unsigned long addr, int numpages);
  * The caller is required to take care of these.
  */
 
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot);
 int _set_memory_uc(unsigned long addr, int numpages);
 int _set_memory_wc(unsigned long addr, int numpages);
 int _set_memory_wt(unsigned long addr, int numpages);
arch/x86/kernel/machine_kexec_64.c +1 -4
index 201137b..0590d39 100644
@@ -673,10 +673,7 @@ static void kexec_mark_dm_crypt_keys(bool protect)
 		if (protect)
 			set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
 		else
-			__set_memory_prot(
-				(unsigned long)phys_to_virt(start_paddr),
-				nr_pages,
-				__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
+			set_memory_p((unsigned long)phys_to_virt(start_paddr), nr_pages);
 	}
 }
 
arch/x86/mm/pat/set_memory.c +0 -13
index 6c6eb48..40581a7 100644
@@ -2145,19 +2145,6 @@ static inline int cpa_clear_pages_array(struct page **pages, int numpages,
 		CPA_PAGES_ARRAY, pages);
 }
 
-/*
- * __set_memory_prot is an internal helper for callers that have been passed
- * a pgprot_t value from upper layers and a reservation has already been taken.
- * If you want to set the pgprot to a specific page protocol, use the
- * set_memory_xx() functions.
- */
-int __set_memory_prot(unsigned long addr, int numpages, pgprot_t prot)
-{
-	return change_page_attr_set_clr(&addr, numpages, prot,
-					__pgprot(~pgprot_val(prot)), 0, 0,
-					NULL);
-}
-
 int _set_memory_uc(unsigned long addr, int numpages)
 {
 	/*