Skip to contentSkip to conversation

x86/ioremap: clean up the mess in xxx_is_setup_data

PATCH Applied Baoquan He 4 participants 14 messages Nov 15, 2024 – Nov 16, 2024

Subsystems (4)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Baoquan He

author
#0 lore raw

cover x86/ioremap: clean up the mess in xxx_is_setup_data

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations. The code can be extracted and put into a helper function __memremap_is_setup_data().

And parameter 'size' is unused in implementation of memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data().

This patchset is made to clean them up. It sits on top of tip/x86/urgent commit 8d9ffb2fe65a ("x86/mm: Fix a kdump kernel failure on SME system when CONFIG_IMA_KEXEC=y")

Baoquan He (3):
x86/ioremap: introduce helper to check if physical address is in
setup_data
x86/ioremap: use helper to implement xxx_is_setup_data() x86/mm: clean up unused parameters of functions

 arch/x86/mm/ioremap.c | 117 +++++++++++++++---------------------------
 1 file changed, 41 insertions(+), 76 deletions(-)
Signature · 1 line
2.41.0
author
#1 lore raw

PATCH 1/3 x86/ioremap: introduce helper to check if physical address is in setup_data

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations.

Add helper __memremap_is_setup_data() to extract the common part, parameter 'early' is used to decide what kind of memremap/unmap APIs are called.

---
 arch/x86/mm/ioremap.c | 81 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
arch/x86/mm/ioremap.c +81 -0
index 8d29163568a7..5ef6182db630 100644
@@ -628,6 +628,87 @@ static bool memremap_is_efi_data(resource_size_t phys_addr,
 	return false;
 }
 
+#define SD_SIZE sizeof(struct setup_data)
+/*
+ * Examine the physical address to determine if it is boot data by checking
+ * it against the boot params setup_data chain.
+ */
+static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
+						bool early)
+{
+	struct setup_indirect *indirect;
+	struct setup_data *data;
+	u64 paddr, paddr_next;
+
+	paddr = boot_params.hdr.setup_data;
+	while (paddr) {
+		unsigned int len, size;
+
+		if (phys_addr == paddr)
+			return true;
+
+		if (early)
+			data = early_memremap_decrypted(paddr, SD_SIZE);
+		else
+			data = memremap(paddr, SD_SIZE,
+					MEMREMAP_WB | MEMREMAP_DEC);
+		if (!data) {
+			pr_warn("failed to memremap setup_data entry\n");
+			return false;
+		}
+
+		size = SD_SIZE;
+
+		paddr_next = data->next;
+		len = data->len;
+
+		if ((phys_addr > paddr) &&
+		    (phys_addr < (paddr + SD_SIZE + len))) {
+			if (early)
+				early_memunmap(data, SD_SIZE);
+			else
+				memunmap(data);
+			return true;
+		}
+
+		if (data->type == SETUP_INDIRECT) {
+			size += len;
+			if (early) {
+				early_memunmap(data, SD_SIZE);
+				data = early_memremap_decrypted(paddr, size);
+			} else {
+				memunmap(data);
+				data = memremap(paddr, size,
+						MEMREMAP_WB | MEMREMAP_DEC);
+			}
+			if (!data) {
+				pr_warn("failed to memremap indirect setup_data\n");
+				return false;
+			}
+
+			indirect = (struct setup_indirect *)data->data;
+
+			if (indirect->type != SETUP_INDIRECT) {
+				paddr = indirect->addr;
+				len = indirect->len;
+			}
+		}
+
+		if (early)
+			early_memunmap(data, size);
+		else
+			memunmap(data);
+
+		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
+			return true;
+
+		paddr = paddr_next;
+	}
+
+	return false;
+}
+#undef SD_SIZE
+
 /*
  * Examine the physical address to determine if it is boot data by checking
  * it against the boot params setup_data chain.
Signature · 1 line
2.41.0
merge bot Applied
#2 lore raw

[tip: x86/mm] x86/ioremap: Introduce helper to check if physical address is in setup_data

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

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

Commit-ID:     e1d30a1f6c2196de359ac7c2726ba07fcd389cc4
Gitweb:        https://git.kernel.org/tip/e1d30a1f6c2196de359ac7c2726ba07fcd389cc4
Author:        Baoquan He <[email protected]>
AuthorDate:    Fri, 15 Nov 2024 09:21:29 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Nov 2024 12:03:36 +01:00

x86/ioremap: Introduce helper to check if physical address is in setup_data

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations.

Add helper __memremap_is_setup_data() to extract the common part, parameter 'early' is used to decide what kind of memremap/unmap APIs are called.

---
 arch/x86/mm/ioremap.c | 81 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 81 insertions(+)
arch/x86/mm/ioremap.c +81 -0
index 8d29163..5ef6182 100644
@@ -628,6 +628,87 @@ static bool memremap_is_efi_data(resource_size_t phys_addr,
 	return false;
 }
 
+#define SD_SIZE sizeof(struct setup_data)
+/*
+ * Examine the physical address to determine if it is boot data by checking
+ * it against the boot params setup_data chain.
+ */
+static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
+						bool early)
+{
+	struct setup_indirect *indirect;
+	struct setup_data *data;
+	u64 paddr, paddr_next;
+
+	paddr = boot_params.hdr.setup_data;
+	while (paddr) {
+		unsigned int len, size;
+
+		if (phys_addr == paddr)
+			return true;
+
+		if (early)
+			data = early_memremap_decrypted(paddr, SD_SIZE);
+		else
+			data = memremap(paddr, SD_SIZE,
+					MEMREMAP_WB | MEMREMAP_DEC);
+		if (!data) {
+			pr_warn("failed to memremap setup_data entry\n");
+			return false;
+		}
+
+		size = SD_SIZE;
+
+		paddr_next = data->next;
+		len = data->len;
+
+		if ((phys_addr > paddr) &&
+		    (phys_addr < (paddr + SD_SIZE + len))) {
+			if (early)
+				early_memunmap(data, SD_SIZE);
+			else
+				memunmap(data);
+			return true;
+		}
+
+		if (data->type == SETUP_INDIRECT) {
+			size += len;
+			if (early) {
+				early_memunmap(data, SD_SIZE);
+				data = early_memremap_decrypted(paddr, size);
+			} else {
+				memunmap(data);
+				data = memremap(paddr, size,
+						MEMREMAP_WB | MEMREMAP_DEC);
+			}
+			if (!data) {
+				pr_warn("failed to memremap indirect setup_data\n");
+				return false;
+			}
+
+			indirect = (struct setup_indirect *)data->data;
+
+			if (indirect->type != SETUP_INDIRECT) {
+				paddr = indirect->addr;
+				len = indirect->len;
+			}
+		}
+
+		if (early)
+			early_memunmap(data, size);
+		else
+			memunmap(data);
+
+		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
+			return true;
+
+		paddr = paddr_next;
+	}
+
+	return false;
+}
+#undef SD_SIZE
+
 /*
  * Examine the physical address to determine if it is boot data by checking
  * it against the boot params setup_data chain.
#3 lore raw

Re: [PATCH 1/3] x86/ioremap: introduce helper to check if physical address is in setup_data

In reply to Baoquan He
Quoted 18 lines · Baoquan He

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations.

Add helper __memremap_is_setup_data() to extract the common part, parameter 'early' is used to decide what kind of memremap/unmap APIs are called.

---
 arch/x86/mm/ioremap.c | 81 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
arch/x86/mm/ioremap.c +0 -0
index 8d29163568a7..5ef6182db630 100644

arch/x86/mm/ioremap.c static bool memremap_is_efi_data(resource_size_t phys_addr, · line 636

Quoted 9 lines
arch/x86/mm/ioremap.c +6 -0
@@ -628,6 +628,87 @@ static bool memremap_is_efi_data(resource_size_t phys_addr,
 	return false;
 }
 
+#define SD_SIZE sizeof(struct setup_data)
+/*
+ * Examine the physical address to determine if it is boot data by checking
+ * it against the boot params setup_data chain.
+ */
+static bool __init __memremap_is_setup_data(resource_size_t phys_addr,

You should remove the __init for this helper since it is called by a function that is outside of __init.

Quoted 14 lines
arch/x86/mm/ioremap.c +14 -0
+						bool early)
+{
+	struct setup_indirect *indirect;
+	struct setup_data *data;
+	u64 paddr, paddr_next;
+
+	paddr = boot_params.hdr.setup_data;
+	while (paddr) {
+		unsigned int len, size;
+
+		if (phys_addr == paddr)
+			return true;
+
+		if (early)

arch/x86/mm/ioremap.c static bool memremap_is_efi_data(resource_size_t phys_addr, · line 660

Quoted 10 lines
arch/x86/mm/ioremap.c +10 -0
+			data = early_memremap_decrypted(paddr, SD_SIZE);
+		else
+			data = memremap(paddr, SD_SIZE,
+					MEMREMAP_WB | MEMREMAP_DEC);
+		if (!data) {
+			pr_warn("failed to memremap setup_data entry\n");
+			return false;
+		}
+
+		size = SD_SIZE;

Just me, but I would use sizeof(*data) here instead of using a #define that is later undefined below.

Thanks,
Tom

Quoted 54 lines
arch/x86/mm/ioremap.c +51 -0
+
+		paddr_next = data->next;
+		len = data->len;
+
+		if ((phys_addr > paddr) &&
+		    (phys_addr < (paddr + SD_SIZE + len))) {
+			if (early)
+				early_memunmap(data, SD_SIZE);
+			else
+				memunmap(data);
+			return true;
+		}
+
+		if (data->type == SETUP_INDIRECT) {
+			size += len;
+			if (early) {
+				early_memunmap(data, SD_SIZE);
+				data = early_memremap_decrypted(paddr, size);
+			} else {
+				memunmap(data);
+				data = memremap(paddr, size,
+						MEMREMAP_WB | MEMREMAP_DEC);
+			}
+			if (!data) {
+				pr_warn("failed to memremap indirect setup_data\n");
+				return false;
+			}
+
+			indirect = (struct setup_indirect *)data->data;
+
+			if (indirect->type != SETUP_INDIRECT) {
+				paddr = indirect->addr;
+				len = indirect->len;
+			}
+		}
+
+		if (early)
+			early_memunmap(data, size);
+		else
+			memunmap(data);
+
+		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
+			return true;
+
+		paddr = paddr_next;
+	}
+
+	return false;
+}
+#undef SD_SIZE
+
 /*
  * Examine the physical address to determine if it is boot data by checking
  * it against the boot params setup_data chain.
author
#4 lore raw

Re: [PATCH 1/3] x86/ioremap: introduce helper to check if physical address is in setup_data

Quoted 22 lines · Tom Lendacky
Quoted 21 lines · Baoquan He

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations.

Add helper __memremap_is_setup_data() to extract the common part, parameter 'early' is used to decide what kind of memremap/unmap APIs are called.

---
 arch/x86/mm/ioremap.c | 81 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
arch/x86/mm/ioremap.c +0 -0
index 8d29163568a7..5ef6182db630 100644
@@ -628,6 +628,87 @@ static bool memremap_is_efi_data(resource_size_t phys_addr,
 	return false;
 }
 
Quoted 9 lines

arch/x86/mm/ioremap.c static bool memremap_is_efi_data(resource_size_t phys_addr, · line 636

Quoted 6 lines
arch/x86/mm/ioremap.c +6 -0
+#define SD_SIZE sizeof(struct setup_data)
+/*
+ * Examine the physical address to determine if it is boot data by checking
+ * it against the boot params setup_data chain.
+ */
+static bool __init __memremap_is_setup_data(resource_size_t phys_addr,

You should remove the __init for this helper since it is called by a function that is outside of __init.

Removing __init for helper will trigger below warning. Then __ref need be added to helper __memremap_is_setup_data() to suppress it. Maybe the latter way should be taken since the helper need be called by a normal function?

WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x5f (section: .text) -> early_memunmap (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x167 (section: .text) -> early_memremap_decrypted (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x180 (section: .text) -> early_memunmap (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x1a9 (section: .text) -> early_memunmap (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x1b4 (section: .text) -> early_memremap_decrypted (section: .init.text)

Thanks
Baoquan

author
#5 lore raw

PATCH 2/3 x86/ioremap: use helper to implement xxx_is_setup_data()

In reply to Baoquan He

This simplifies codes a lot by removing the duplicated code handling.

And also remove the similar code comment above of them.

While at it, add __ref to memremap_is_setup_data() to avoid the section mismatch warning:

WARNING: modpost: vmlinux: section mismatch in reference: arch_memremap_can_ram_remap.cold+0x6 (section: .text.unlikely) -> __memremap_is_setup_data (section: .init.text)

---
 arch/x86/mm/ioremap.c | 119 ++----------------------------------------
 1 file changed, 3 insertions(+), 116 deletions(-)
arch/x86/mm/ioremap.c +3 -116
index 5ef6182db630..5d1b5e4a8756 100644
@@ -709,129 +709,16 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain.
- */
-static bool memremap_is_setup_data(resource_size_t phys_addr,
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
 				   unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = memremap(paddr, sizeof(*data),
-				MEMREMAP_WB | MEMREMAP_DEC);
-		if (!data) {
-			pr_warn("failed to memremap setup_data entry\n");
-			return false;
-		}
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			memunmap(data);
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			memunmap(data);
-			data = memremap(paddr, sizeof(*data) + len,
-					MEMREMAP_WB | MEMREMAP_DEC);
-			if (!data) {
-				pr_warn("failed to memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		memunmap(data);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, false);
 }
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain (early boot version).
- */
 static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
 						unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len, size;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = early_memremap_decrypted(paddr, sizeof(*data));
-		if (!data) {
-			pr_warn("failed to early memremap setup_data entry\n");
-			return false;
-		}
-
-		size = sizeof(*data);
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			early_memunmap(data, sizeof(*data));
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			size += len;
-			early_memunmap(data, sizeof(*data));
-			data = early_memremap_decrypted(paddr, size);
-			if (!data) {
-				pr_warn("failed to early memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		early_memunmap(data, size);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, true);
 }
 
 /*
Signature · 1 line
2.41.0
merge bot Applied
#6 lore raw

[tip: x86/mm] x86/ioremap: Use helper to implement xxx_is_setup_data()

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

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

Commit-ID:     ca9114c1fbb478f69e2e4508b3c126058c5d5521
Gitweb:        https://git.kernel.org/tip/ca9114c1fbb478f69e2e4508b3c126058c5d5521
Author:        Baoquan He <[email protected]>
AuthorDate:    Fri, 15 Nov 2024 09:21:30 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Nov 2024 12:03:36 +01:00

x86/ioremap: Use helper to implement xxx_is_setup_data()

This simplifies codes a lot by removing the duplicated code handling.

And also remove the similar code comment above of them.

While at it, add __ref to memremap_is_setup_data() to avoid the section mismatch warning:

WARNING: modpost: vmlinux: section mismatch in reference: arch_memremap_can_ram_remap.cold+0x6 (section: .text.unlikely) -> __memremap_is_setup_data (section: .init.text)

---
 arch/x86/mm/ioremap.c | 119 +----------------------------------------
 1 file changed, 3 insertions(+), 116 deletions(-)
arch/x86/mm/ioremap.c +3 -116
index 5ef6182..5d1b5e4 100644
@@ -709,129 +709,16 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain.
- */
-static bool memremap_is_setup_data(resource_size_t phys_addr,
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
 				   unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = memremap(paddr, sizeof(*data),
-				MEMREMAP_WB | MEMREMAP_DEC);
-		if (!data) {
-			pr_warn("failed to memremap setup_data entry\n");
-			return false;
-		}
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			memunmap(data);
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			memunmap(data);
-			data = memremap(paddr, sizeof(*data) + len,
-					MEMREMAP_WB | MEMREMAP_DEC);
-			if (!data) {
-				pr_warn("failed to memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		memunmap(data);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, false);
 }
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain (early boot version).
- */
 static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
 						unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len, size;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = early_memremap_decrypted(paddr, sizeof(*data));
-		if (!data) {
-			pr_warn("failed to early memremap setup_data entry\n");
-			return false;
-		}
-
-		size = sizeof(*data);
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			early_memunmap(data, sizeof(*data));
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			size += len;
-			early_memunmap(data, sizeof(*data));
-			data = early_memremap_decrypted(paddr, size);
-			if (!data) {
-				pr_warn("failed to early memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		early_memunmap(data, size);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, true);
 }
 
 /*
#7 lore raw

Re: [PATCH 2/3] x86/ioremap: use helper to implement xxx_is_setup_data()

In reply to Baoquan He
Quoted 1 line · Baoquan He

This simplifies codes a lot by removing the duplicated code handling.

You should probably squash this with the first patch.

Quoted 4 lines

And also remove the similar code comment above of them.

While at it, add __ref to memremap_is_setup_data() to avoid

The __ref shouldn't be needed if you remove the __init from the helper function.

Thanks,
Tom

Quoted 145 lines

the section mismatch warning:

WARNING: modpost: vmlinux: section mismatch in reference: arch_memremap_can_ram_remap.cold+0x6 (section: .text.unlikely) -> __memremap_is_setup_data (section: .init.text)

---
 arch/x86/mm/ioremap.c | 119 ++----------------------------------------
 1 file changed, 3 insertions(+), 116 deletions(-)
arch/x86/mm/ioremap.c +3 -116
index 5ef6182db630..5d1b5e4a8756 100644
@@ -709,129 +709,16 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain.
- */
-static bool memremap_is_setup_data(resource_size_t phys_addr,
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
 				   unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = memremap(paddr, sizeof(*data),
-				MEMREMAP_WB | MEMREMAP_DEC);
-		if (!data) {
-			pr_warn("failed to memremap setup_data entry\n");
-			return false;
-		}
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			memunmap(data);
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			memunmap(data);
-			data = memremap(paddr, sizeof(*data) + len,
-					MEMREMAP_WB | MEMREMAP_DEC);
-			if (!data) {
-				pr_warn("failed to memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		memunmap(data);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, false);
 }
 
-/*
- * Examine the physical address to determine if it is boot data by checking
- * it against the boot params setup_data chain (early boot version).
- */
 static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
 						unsigned long size)
 {
-	struct setup_indirect *indirect;
-	struct setup_data *data;
-	u64 paddr, paddr_next;
-
-	paddr = boot_params.hdr.setup_data;
-	while (paddr) {
-		unsigned int len, size;
-
-		if (phys_addr == paddr)
-			return true;
-
-		data = early_memremap_decrypted(paddr, sizeof(*data));
-		if (!data) {
-			pr_warn("failed to early memremap setup_data entry\n");
-			return false;
-		}
-
-		size = sizeof(*data);
-
-		paddr_next = data->next;
-		len = data->len;
-
-		if ((phys_addr > paddr) &&
-		    (phys_addr < (paddr + sizeof(struct setup_data) + len))) {
-			early_memunmap(data, sizeof(*data));
-			return true;
-		}
-
-		if (data->type == SETUP_INDIRECT) {
-			size += len;
-			early_memunmap(data, sizeof(*data));
-			data = early_memremap_decrypted(paddr, size);
-			if (!data) {
-				pr_warn("failed to early memremap indirect setup_data\n");
-				return false;
-			}
-
-			indirect = (struct setup_indirect *)data->data;
-
-			if (indirect->type != SETUP_INDIRECT) {
-				paddr = indirect->addr;
-				len = indirect->len;
-			}
-		}
-
-		early_memunmap(data, size);
-
-		if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
-			return true;
-
-		paddr = paddr_next;
-	}
-
-	return false;
+	return __memremap_is_setup_data(phys_addr, true);
 }
 
 /*
#8 lore raw

Re: [PATCH 2/3] x86/ioremap: use helper to implement xxx_is_setup_data()

Quoted 6 lines · Tom Lendacky
Quoted 1 line · Baoquan He

This simplifies codes a lot by removing the duplicated code handling.

You should probably squash this with the first patch.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

And also remove the similar code comment above of them.

While at it, add __ref to memremap_is_setup_data() to avoid

The __ref shouldn't be needed if you remove the __init from the helper function.

Yeah.

Baoquan, I've zapped these 3 commits from tip:x86/mm for now, mind resending them the init annotations fixed?

Thanks,

Ingo

author
#9 lore raw

Re: [PATCH 2/3] x86/ioremap: use helper to implement xxx_is_setup_data()

Quoted 13 lines · Ingo Molnar
Quoted 10 lines · Tom Lendacky
Quoted 1 line · Baoquan He

This simplifies codes a lot by removing the duplicated code handling.

You should probably squash this with the first patch.

Quoted 4 lines

And also remove the similar code comment above of them.

While at it, add __ref to memremap_is_setup_data() to avoid

Quoted 7 lines
Quoted 2 lines

The __ref shouldn't be needed if you remove the __init from the helper function.

Yeah.

Baoquan, I've zapped these 3 commits from tip:x86/mm for now, mind resending them the init annotations fixed?

Sure, will resend. Thanks.

author
#10 lore raw

PATCH 3/3 x86/mm: clean up unused parameters of functions

In reply to Baoquan He

For functions memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data(), their parameter 'size' is not used and sometime cause confusion. Remove it now.

---
 arch/x86/mm/ioremap.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
arch/x86/mm/ioremap.c +7 -10
index 5d1b5e4a8756..71b282e5a4a0 100644
@@ -593,8 +593,7 @@ static bool memremap_should_map_decrypted(resource_size_t phys_addr,
  * Examine the physical address to determine if it is EFI data. Check
  * it against the boot params structure and EFI tables and memory types.
  */
-static bool memremap_is_efi_data(resource_size_t phys_addr,
-				 unsigned long size)
+static bool memremap_is_efi_data(resource_size_t phys_addr)
 {
 	u64 paddr;
 
@@ -709,14 +708,12 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
-				   unsigned long size)
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, false);
 }
 
-static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
-						unsigned long size)
+static bool __init early_memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, true);
 }
@@ -739,8 +736,8 @@ bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
 		return false;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			return false;
 	}
 
@@ -765,8 +762,8 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
 	encrypted_prot = true;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (early_memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (early_memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			encrypted_prot = false;
 	}
 
Signature · 1 line
2.41.0
merge bot Applied
#11 lore raw

[tip: x86/mm] x86/mm: Clean up unused parameters of functions

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

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

Commit-ID:     390c9c9e48b821fc53b67dd93ae0f7a1f82a0469
Gitweb:        https://git.kernel.org/tip/390c9c9e48b821fc53b67dd93ae0f7a1f82a0469
Author:        Baoquan He <[email protected]>
AuthorDate:    Fri, 15 Nov 2024 09:21:31 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Nov 2024 12:03:36 +01:00

x86/mm: Clean up unused parameters of functions

For functions memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data(), their parameter 'size' is not used and sometime cause confusion. Remove it now.

---
 arch/x86/mm/ioremap.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
arch/x86/mm/ioremap.c +7 -10
index 5d1b5e4..71b282e 100644
@@ -593,8 +593,7 @@ static bool memremap_should_map_decrypted(resource_size_t phys_addr,
  * Examine the physical address to determine if it is EFI data. Check
  * it against the boot params structure and EFI tables and memory types.
  */
-static bool memremap_is_efi_data(resource_size_t phys_addr,
-				 unsigned long size)
+static bool memremap_is_efi_data(resource_size_t phys_addr)
 {
 	u64 paddr;
 
@@ -709,14 +708,12 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
-				   unsigned long size)
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, false);
 }
 
-static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
-						unsigned long size)
+static bool __init early_memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, true);
 }
@@ -739,8 +736,8 @@ bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
 		return false;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			return false;
 	}
 
@@ -765,8 +762,8 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
 	encrypted_prot = true;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (early_memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (early_memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			encrypted_prot = false;
 	}
 
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] x86/mm: clean up unused parameters of functions

In reply to Baoquan He
Quoted 5 lines · Baoquan He

For functions memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data(), their parameter 'size' is not used and sometime cause confusion. Remove it now.

Quoted 57 lines
---
 arch/x86/mm/ioremap.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
arch/x86/mm/ioremap.c +7 -10
index 5d1b5e4a8756..71b282e5a4a0 100644
@@ -593,8 +593,7 @@ static bool memremap_should_map_decrypted(resource_size_t phys_addr,
  * Examine the physical address to determine if it is EFI data. Check
  * it against the boot params structure and EFI tables and memory types.
  */
-static bool memremap_is_efi_data(resource_size_t phys_addr,
-				 unsigned long size)
+static bool memremap_is_efi_data(resource_size_t phys_addr)
 {
 	u64 paddr;
 
@@ -709,14 +708,12 @@ static bool __init __memremap_is_setup_data(resource_size_t phys_addr,
 }
 #undef SD_SIZE
 
-static bool __ref memremap_is_setup_data(resource_size_t phys_addr,
-				   unsigned long size)
+static bool __ref memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, false);
 }
 
-static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
-						unsigned long size)
+static bool __init early_memremap_is_setup_data(resource_size_t phys_addr)
 {
 	return __memremap_is_setup_data(phys_addr, true);
 }
@@ -739,8 +736,8 @@ bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
 		return false;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			return false;
 	}
 
@@ -765,8 +762,8 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
 	encrypted_prot = true;
 
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) {
-		if (early_memremap_is_setup_data(phys_addr, size) ||
-		    memremap_is_efi_data(phys_addr, size))
+		if (early_memremap_is_setup_data(phys_addr) ||
+		    memremap_is_efi_data(phys_addr))
 			encrypted_prot = false;
 	}
 
author
#13 lore raw
In reply to Baoquan He

Also CC kexec list.

Quoted 24 lines · Baoquan He

Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations. The code can be extracted and put into a helper function __memremap_is_setup_data().

And parameter 'size' is unused in implementation of memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data().

This patchset is made to clean them up. It sits on top of tip/x86/urgent commit 8d9ffb2fe65a ("x86/mm: Fix a kdump kernel failure on SME system when CONFIG_IMA_KEXEC=y")

Baoquan He (3):
x86/ioremap: introduce helper to check if physical address is in
setup_data
x86/ioremap: use helper to implement xxx_is_setup_data() x86/mm: clean up unused parameters of functions

 arch/x86/mm/ioremap.c | 117 +++++++++++++++---------------------------
 1 file changed, 41 insertions(+), 76 deletions(-)
Signature · 1 line
2.41.0