All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05  5:24 ` Anshuman Khandual
  0 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
its performance for normal hotplug memory. While here, it also reorganizes
pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Veronika Kabatova <vkabatov@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org

Changes in V3:

- Validate the pfn before fetching mem_section with __pfn_to_section() in [PATCH 2/2]

Changes in V2:

https://lore.kernel.org/linux-mm/1612239114-28428-1-git-send-email-anshuman.khandual@arm.com/

- Dropped pfn_valid() bifurcation based on CONFIG_SPARSEMEM
- Used PFN_PHYS() and PHYS_PFN() instead of __pfn_to_phys() and __phys_to_pfn()
- Moved __pfn_to_section() inside #ifdef CONFIG_SPARSEMEM with a { } construct

Changes in V1:

https://lore.kernel.org/linux-mm/1611905986-20155-1-git-send-email-anshuman.khandual@arm.com/

- Test pfn_section_valid() for non boot memory

Changes in RFC:

https://lore.kernel.org/linux-arm-kernel/1608621144-4001-1-git-send-email-anshuman.khandual@arm.com/

Anshuman Khandual (2):
  arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  arm64/mm: Reorganize pfn_valid()

 arch/arm64/mm/init.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05  5:24 ` Anshuman Khandual
  0 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
its performance for normal hotplug memory. While here, it also reorganizes
pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Veronika Kabatova <vkabatov@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org

Changes in V3:

- Validate the pfn before fetching mem_section with __pfn_to_section() in [PATCH 2/2]

Changes in V2:

https://lore.kernel.org/linux-mm/1612239114-28428-1-git-send-email-anshuman.khandual@arm.com/

- Dropped pfn_valid() bifurcation based on CONFIG_SPARSEMEM
- Used PFN_PHYS() and PHYS_PFN() instead of __pfn_to_phys() and __phys_to_pfn()
- Moved __pfn_to_section() inside #ifdef CONFIG_SPARSEMEM with a { } construct

Changes in V1:

https://lore.kernel.org/linux-mm/1611905986-20155-1-git-send-email-anshuman.khandual@arm.com/

- Test pfn_section_valid() for non boot memory

Changes in RFC:

https://lore.kernel.org/linux-arm-kernel/1608621144-4001-1-git-send-email-anshuman.khandual@arm.com/

Anshuman Khandual (2):
  arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  arm64/mm: Reorganize pfn_valid()

 arch/arm64/mm/init.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:24 ` Anshuman Khandual
@ 2021-03-05  5:24   ` Anshuman Khandual
  -1 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

pfn_valid() validates a pfn but basically it checks for a valid struct page
backing for that pfn. It should always return positive for memory ranges
backed with struct page mapping. But currently pfn_valid() fails for all
ZONE_DEVICE based memory types even though they have struct page mapping.

pfn_valid() asserts that there is a memblock entry for a given pfn without
MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
that they do not have memblock entries. Hence memblock_is_map_memory() will
invariably fail via memblock_search() for a ZONE_DEVICE based address. This
eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
into the system via memremap_pages() called from a driver, their respective
memory sections will not have SECTION_IS_EARLY set.

Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
for firmware reserved memory regions. memblock_is_map_memory() can just be
skipped as its always going to be positive and that will be an optimization
for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
hotplugged memory too will not have SECTION_IS_EARLY set for their sections

Skipping memblock_is_map_memory() for all non early memory sections would
fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
performance for normal hotplug memory as well.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Acked-by: David Hildenbrand <david@redhat.com>
Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/arm64/mm/init.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 0ace5e68efba..5920c527845a 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
 
 	if (!valid_section(__pfn_to_section(pfn)))
 		return 0;
+
+	/*
+	 * ZONE_DEVICE memory does not have the memblock entries.
+	 * memblock_is_map_memory() check for ZONE_DEVICE based
+	 * addresses will always fail. Even the normal hotplugged
+	 * memory will never have MEMBLOCK_NOMAP flag set in their
+	 * memblock entries. Skip memblock search for all non early
+	 * memory sections covering all of hotplug memory including
+	 * both normal and ZONE_DEVICE based.
+	 */
+	if (!early_section(__pfn_to_section(pfn)))
+		return pfn_section_valid(__pfn_to_section(pfn), pfn);
 #endif
 	return memblock_is_map_memory(addr);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05  5:24   ` Anshuman Khandual
  0 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

pfn_valid() validates a pfn but basically it checks for a valid struct page
backing for that pfn. It should always return positive for memory ranges
backed with struct page mapping. But currently pfn_valid() fails for all
ZONE_DEVICE based memory types even though they have struct page mapping.

pfn_valid() asserts that there is a memblock entry for a given pfn without
MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
that they do not have memblock entries. Hence memblock_is_map_memory() will
invariably fail via memblock_search() for a ZONE_DEVICE based address. This
eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
into the system via memremap_pages() called from a driver, their respective
memory sections will not have SECTION_IS_EARLY set.

Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
for firmware reserved memory regions. memblock_is_map_memory() can just be
skipped as its always going to be positive and that will be an optimization
for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
hotplugged memory too will not have SECTION_IS_EARLY set for their sections

Skipping memblock_is_map_memory() for all non early memory sections would
fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
performance for normal hotplug memory as well.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Acked-by: David Hildenbrand <david@redhat.com>
Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/arm64/mm/init.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 0ace5e68efba..5920c527845a 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
 
 	if (!valid_section(__pfn_to_section(pfn)))
 		return 0;
+
+	/*
+	 * ZONE_DEVICE memory does not have the memblock entries.
+	 * memblock_is_map_memory() check for ZONE_DEVICE based
+	 * addresses will always fail. Even the normal hotplugged
+	 * memory will never have MEMBLOCK_NOMAP flag set in their
+	 * memblock entries. Skip memblock search for all non early
+	 * memory sections covering all of hotplug memory including
+	 * both normal and ZONE_DEVICE based.
+	 */
+	if (!early_section(__pfn_to_section(pfn)))
+		return pfn_section_valid(__pfn_to_section(pfn), pfn);
 #endif
 	return memblock_is_map_memory(addr);
 }
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid()
  2021-03-05  5:24 ` Anshuman Khandual
@ 2021-03-05  5:24   ` Anshuman Khandual
  -1 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

There are multiple instances of pfn_to_section_nr() and __pfn_to_section()
when CONFIG_SPARSEMEM is enabled. This can be optimized if memory section
is fetched earlier. This replaces the open coded PFN and ADDR conversion
with PFN_PHYS() and PHYS_PFN() helpers. While there, also add a comment.
This does not cause any functional change.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/arm64/mm/init.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 5920c527845a..3685e12aba9b 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -219,16 +219,26 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
 
 int pfn_valid(unsigned long pfn)
 {
-	phys_addr_t addr = pfn << PAGE_SHIFT;
+	phys_addr_t addr = PFN_PHYS(pfn);
 
-	if ((addr >> PAGE_SHIFT) != pfn)
+	/*
+	 * Ensure the upper PAGE_SHIFT bits are clear in the
+	 * pfn. Else it might lead to false positives when
+	 * some of the upper bits are set, but the lower bits
+	 * match a valid pfn.
+	 */
+	if (PHYS_PFN(addr) != pfn)
 		return 0;
 
 #ifdef CONFIG_SPARSEMEM
+{
+	struct mem_section *ms;
+
 	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
 		return 0;
 
-	if (!valid_section(__pfn_to_section(pfn)))
+	ms = __pfn_to_section(pfn);
+	if (!valid_section(ms))
 		return 0;
 
 	/*
@@ -240,8 +250,9 @@ int pfn_valid(unsigned long pfn)
 	 * memory sections covering all of hotplug memory including
 	 * both normal and ZONE_DEVICE based.
 	 */
-	if (!early_section(__pfn_to_section(pfn)))
-		return pfn_section_valid(__pfn_to_section(pfn), pfn);
+	if (!early_section(ms))
+		return pfn_section_valid(ms, pfn);
+}
 #endif
 	return memblock_is_map_memory(addr);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid()
@ 2021-03-05  5:24   ` Anshuman Khandual
  0 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:24 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Ard Biesheuvel,
	Mark Rutland, James Morse, Robin Murphy, Jérôme Glisse,
	Dan Williams, David Hildenbrand, Mike Rapoport,
	Veronika Kabatova

There are multiple instances of pfn_to_section_nr() and __pfn_to_section()
when CONFIG_SPARSEMEM is enabled. This can be optimized if memory section
is fetched earlier. This replaces the open coded PFN and ADDR conversion
with PFN_PHYS() and PHYS_PFN() helpers. While there, also add a comment.
This does not cause any functional change.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/arm64/mm/init.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 5920c527845a..3685e12aba9b 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -219,16 +219,26 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
 
 int pfn_valid(unsigned long pfn)
 {
-	phys_addr_t addr = pfn << PAGE_SHIFT;
+	phys_addr_t addr = PFN_PHYS(pfn);
 
-	if ((addr >> PAGE_SHIFT) != pfn)
+	/*
+	 * Ensure the upper PAGE_SHIFT bits are clear in the
+	 * pfn. Else it might lead to false positives when
+	 * some of the upper bits are set, but the lower bits
+	 * match a valid pfn.
+	 */
+	if (PHYS_PFN(addr) != pfn)
 		return 0;
 
 #ifdef CONFIG_SPARSEMEM
+{
+	struct mem_section *ms;
+
 	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
 		return 0;
 
-	if (!valid_section(__pfn_to_section(pfn)))
+	ms = __pfn_to_section(pfn);
+	if (!valid_section(ms))
 		return 0;
 
 	/*
@@ -240,8 +250,9 @@ int pfn_valid(unsigned long pfn)
 	 * memory sections covering all of hotplug memory including
 	 * both normal and ZONE_DEVICE based.
 	 */
-	if (!early_section(__pfn_to_section(pfn)))
-		return pfn_section_valid(__pfn_to_section(pfn), pfn);
+	if (!early_section(ms))
+		return pfn_section_valid(ms, pfn);
+}
 #endif
 	return memblock_is_map_memory(addr);
 }
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:24 ` Anshuman Khandual
@ 2021-03-05  5:38   ` Anshuman Khandual
  -1 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:38 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, Mark Rutland,
	James Morse, Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport, Veronika Kabatova


On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
> its performance for normal hotplug memory. While here, it also reorganizes
> pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Veronika Kabatova <vkabatov@redhat.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> 
> Changes in V3:
> 
> - Validate the pfn before fetching mem_section with __pfn_to_section() in [PATCH 2/2]

Hello Veronica,

Could you please help recreate the earlier failure [1] but with this
series applies on v5.12-rc1. Thank you.

[1] https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/

- Anshuman

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05  5:38   ` Anshuman Khandual
  0 siblings, 0 replies; 26+ messages in thread
From: Anshuman Khandual @ 2021-03-05  5:38 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, linux-mm
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, Mark Rutland,
	James Morse, Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport, Veronika Kabatova


On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
> its performance for normal hotplug memory. While here, it also reorganizes
> pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Veronika Kabatova <vkabatov@redhat.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> 
> Changes in V3:
> 
> - Validate the pfn before fetching mem_section with __pfn_to_section() in [PATCH 2/2]

Hello Veronica,

Could you please help recreate the earlier failure [1] but with this
series applies on v5.12-rc1. Thank you.

[1] https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/

- Anshuman

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:38   ` Anshuman Khandual
@ 2021-03-05 12:28     ` Veronika Kabatova
  -1 siblings, 0 replies; 26+ messages in thread
From: Veronika Kabatova @ 2021-03-05 12:28 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Catalin Marinas,
	Will Deacon, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport



----- Original Message -----
> From: "Anshuman Khandual" <anshuman.khandual@arm.com>
> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org
> Cc: "Catalin Marinas" <catalin.marinas@arm.com>, "Will Deacon" <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>,
> "Mark Rutland" <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>, "Robin Murphy" <robin.murphy@arm.com>,
> "Jérôme Glisse" <jglisse@redhat.com>, "Dan Williams" <dan.j.williams@intel.com>, "David Hildenbrand"
> <david@redhat.com>, "Mike Rapoport" <rppt@linux.ibm.com>, "Veronika Kabatova" <vkabatov@redhat.com>
> Sent: Friday, March 5, 2021 6:38:14 AM
> Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
> 
> 
> On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > This series fixes pfn_valid() for ZONE_DEVICE based memory and also
> > improves
> > its performance for normal hotplug memory. While here, it also reorganizes
> > pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> > 
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: Ard Biesheuvel <ardb@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: James Morse <james.morse@arm.com>
> > Cc: Robin Murphy <robin.murphy@arm.com>
> > Cc: Jérôme Glisse <jglisse@redhat.com>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: David Hildenbrand <david@redhat.com>
> > Cc: Mike Rapoport <rppt@linux.ibm.com>
> > Cc: Veronika Kabatova <vkabatov@redhat.com>
> > Cc: linux-arm-kernel@lists.infradead.org
> > Cc: linux-mm@kvack.org
> > Cc: linux-kernel@vger.kernel.org
> > 
> > Changes in V3:
> > 
> > - Validate the pfn before fetching mem_section with __pfn_to_section() in
> > [PATCH 2/2]
> 
> Hello Veronica,
> 
> Could you please help recreate the earlier failure [1] but with this
> series applies on v5.12-rc1. Thank you.
> 

Hello Anshuman,

the machine in question is currently loaned to a developer. I'll reach
out to them and will let you know once I have any results.


Veronika

> [1]
> https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/
> 
> - Anshuman
> 
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05 12:28     ` Veronika Kabatova
  0 siblings, 0 replies; 26+ messages in thread
From: Veronika Kabatova @ 2021-03-05 12:28 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Catalin Marinas,
	Will Deacon, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport



----- Original Message -----
> From: "Anshuman Khandual" <anshuman.khandual@arm.com>
> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org
> Cc: "Catalin Marinas" <catalin.marinas@arm.com>, "Will Deacon" <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>,
> "Mark Rutland" <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>, "Robin Murphy" <robin.murphy@arm.com>,
> "Jérôme Glisse" <jglisse@redhat.com>, "Dan Williams" <dan.j.williams@intel.com>, "David Hildenbrand"
> <david@redhat.com>, "Mike Rapoport" <rppt@linux.ibm.com>, "Veronika Kabatova" <vkabatov@redhat.com>
> Sent: Friday, March 5, 2021 6:38:14 AM
> Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
> 
> 
> On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > This series fixes pfn_valid() for ZONE_DEVICE based memory and also
> > improves
> > its performance for normal hotplug memory. While here, it also reorganizes
> > pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> > 
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: Ard Biesheuvel <ardb@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: James Morse <james.morse@arm.com>
> > Cc: Robin Murphy <robin.murphy@arm.com>
> > Cc: Jérôme Glisse <jglisse@redhat.com>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: David Hildenbrand <david@redhat.com>
> > Cc: Mike Rapoport <rppt@linux.ibm.com>
> > Cc: Veronika Kabatova <vkabatov@redhat.com>
> > Cc: linux-arm-kernel@lists.infradead.org
> > Cc: linux-mm@kvack.org
> > Cc: linux-kernel@vger.kernel.org
> > 
> > Changes in V3:
> > 
> > - Validate the pfn before fetching mem_section with __pfn_to_section() in
> > [PATCH 2/2]
> 
> Hello Veronica,
> 
> Could you please help recreate the earlier failure [1] but with this
> series applies on v5.12-rc1. Thank you.
> 

Hello Anshuman,

the machine in question is currently loaned to a developer. I'll reach
out to them and will let you know once I have any results.


Veronika

> [1]
> https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/
> 
> - Anshuman
> 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:24   ` Anshuman Khandual
@ 2021-03-05 18:13     ` Catalin Marinas
  -1 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-05 18:13 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> pfn_valid() validates a pfn but basically it checks for a valid struct page
> backing for that pfn. It should always return positive for memory ranges
> backed with struct page mapping. But currently pfn_valid() fails for all
> ZONE_DEVICE based memory types even though they have struct page mapping.
> 
> pfn_valid() asserts that there is a memblock entry for a given pfn without
> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> that they do not have memblock entries. Hence memblock_is_map_memory() will
> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> into the system via memremap_pages() called from a driver, their respective
> memory sections will not have SECTION_IS_EARLY set.
> 
> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> for firmware reserved memory regions. memblock_is_map_memory() can just be
> skipped as its always going to be positive and that will be an optimization
> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> 
> Skipping memblock_is_map_memory() for all non early memory sections would
> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> performance for normal hotplug memory as well.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Acked-by: David Hildenbrand <david@redhat.com>
> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  arch/arm64/mm/init.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 0ace5e68efba..5920c527845a 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>  
>  	if (!valid_section(__pfn_to_section(pfn)))
>  		return 0;
> +
> +	/*
> +	 * ZONE_DEVICE memory does not have the memblock entries.
> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> +	 * addresses will always fail. Even the normal hotplugged
> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> +	 * memblock entries. Skip memblock search for all non early
> +	 * memory sections covering all of hotplug memory including
> +	 * both normal and ZONE_DEVICE based.
> +	 */
> +	if (!early_section(__pfn_to_section(pfn)))
> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);

Would something like this work instead:

	if (online_device_section(ms))
		return 1;

to avoid the assumptions around early_section()?

-- 
Catalin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05 18:13     ` Catalin Marinas
  0 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-05 18:13 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> pfn_valid() validates a pfn but basically it checks for a valid struct page
> backing for that pfn. It should always return positive for memory ranges
> backed with struct page mapping. But currently pfn_valid() fails for all
> ZONE_DEVICE based memory types even though they have struct page mapping.
> 
> pfn_valid() asserts that there is a memblock entry for a given pfn without
> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> that they do not have memblock entries. Hence memblock_is_map_memory() will
> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> into the system via memremap_pages() called from a driver, their respective
> memory sections will not have SECTION_IS_EARLY set.
> 
> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> for firmware reserved memory regions. memblock_is_map_memory() can just be
> skipped as its always going to be positive and that will be an optimization
> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> 
> Skipping memblock_is_map_memory() for all non early memory sections would
> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> performance for normal hotplug memory as well.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Acked-by: David Hildenbrand <david@redhat.com>
> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  arch/arm64/mm/init.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 0ace5e68efba..5920c527845a 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>  
>  	if (!valid_section(__pfn_to_section(pfn)))
>  		return 0;
> +
> +	/*
> +	 * ZONE_DEVICE memory does not have the memblock entries.
> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> +	 * addresses will always fail. Even the normal hotplugged
> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> +	 * memblock entries. Skip memblock search for all non early
> +	 * memory sections covering all of hotplug memory including
> +	 * both normal and ZONE_DEVICE based.
> +	 */
> +	if (!early_section(__pfn_to_section(pfn)))
> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);

Would something like this work instead:

	if (online_device_section(ms))
		return 1;

to avoid the assumptions around early_section()?

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05 12:28     ` Veronika Kabatova
@ 2021-03-05 18:16       ` Veronika Kabatova
  -1 siblings, 0 replies; 26+ messages in thread
From: Veronika Kabatova @ 2021-03-05 18:16 UTC (permalink / raw)
  To: Anshuman Khandual, Will Deacon
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Catalin Marinas,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport



----- Original Message -----
> From: "Veronika Kabatova" <vkabatov@redhat.com>
> To: "Anshuman Khandual" <anshuman.khandual@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Catalin Marinas"
> <catalin.marinas@arm.com>, "Will Deacon" <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>, "Mark Rutland"
> <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>, "Robin Murphy" <robin.murphy@arm.com>, "Jérôme Glisse"
> <jglisse@redhat.com>, "Dan Williams" <dan.j.williams@intel.com>, "David Hildenbrand" <david@redhat.com>, "Mike
> Rapoport" <rppt@linux.ibm.com>
> Sent: Friday, March 5, 2021 1:28:40 PM
> Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
> 
> 
> 
> ----- Original Message -----
> > From: "Anshuman Khandual" <anshuman.khandual@arm.com>
> > To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org,
> > linux-mm@kvack.org
> > Cc: "Catalin Marinas" <catalin.marinas@arm.com>, "Will Deacon"
> > <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>,
> > "Mark Rutland" <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>,
> > "Robin Murphy" <robin.murphy@arm.com>,
> > "Jérôme Glisse" <jglisse@redhat.com>, "Dan Williams"
> > <dan.j.williams@intel.com>, "David Hildenbrand"
> > <david@redhat.com>, "Mike Rapoport" <rppt@linux.ibm.com>, "Veronika
> > Kabatova" <vkabatov@redhat.com>
> > Sent: Friday, March 5, 2021 6:38:14 AM
> > Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based
> > memory
> > 
> > 
> > On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > > This series fixes pfn_valid() for ZONE_DEVICE based memory and also
> > > improves
> > > its performance for normal hotplug memory. While here, it also
> > > reorganizes
> > > pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> > > 
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: James Morse <james.morse@arm.com>
> > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > Cc: Jérôme Glisse <jglisse@redhat.com>
> > > Cc: Dan Williams <dan.j.williams@intel.com>
> > > Cc: David Hildenbrand <david@redhat.com>
> > > Cc: Mike Rapoport <rppt@linux.ibm.com>
> > > Cc: Veronika Kabatova <vkabatov@redhat.com>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > Cc: linux-mm@kvack.org
> > > Cc: linux-kernel@vger.kernel.org
> > > 
> > > Changes in V3:
> > > 
> > > - Validate the pfn before fetching mem_section with __pfn_to_section() in
> > > [PATCH 2/2]
> > 
> > Hello Veronica,
> > 
> > Could you please help recreate the earlier failure [1] but with this
> > series applies on v5.12-rc1. Thank you.
> > 
> 
> Hello Anshuman,
> 
> the machine in question is currently loaned to a developer. I'll reach
> out to them and will let you know once I have any results.
> 

Hi,

I'm happy to report the kernel boots with these new patches. I used the
5.12.0-rc1 kernel (commit 280d542f6ffac0) as a base. The full console log
from the boot process is available at

https://gitlab.com/-/snippets/2086833

in case you want to take a look. Note that there are some call traces
starting around line 3220, but they are NOT introduced by these two
patches and are also present with the base mainline kernel.


Veronika

> 
> Veronika
> 
> > [1]
> > https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/
> > 
> > - Anshuman
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05 18:16       ` Veronika Kabatova
  0 siblings, 0 replies; 26+ messages in thread
From: Veronika Kabatova @ 2021-03-05 18:16 UTC (permalink / raw)
  To: Anshuman Khandual, Will Deacon
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Catalin Marinas,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport



----- Original Message -----
> From: "Veronika Kabatova" <vkabatov@redhat.com>
> To: "Anshuman Khandual" <anshuman.khandual@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Catalin Marinas"
> <catalin.marinas@arm.com>, "Will Deacon" <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>, "Mark Rutland"
> <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>, "Robin Murphy" <robin.murphy@arm.com>, "Jérôme Glisse"
> <jglisse@redhat.com>, "Dan Williams" <dan.j.williams@intel.com>, "David Hildenbrand" <david@redhat.com>, "Mike
> Rapoport" <rppt@linux.ibm.com>
> Sent: Friday, March 5, 2021 1:28:40 PM
> Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
> 
> 
> 
> ----- Original Message -----
> > From: "Anshuman Khandual" <anshuman.khandual@arm.com>
> > To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org,
> > linux-mm@kvack.org
> > Cc: "Catalin Marinas" <catalin.marinas@arm.com>, "Will Deacon"
> > <will@kernel.org>, "Ard Biesheuvel" <ardb@kernel.org>,
> > "Mark Rutland" <mark.rutland@arm.com>, "James Morse" <james.morse@arm.com>,
> > "Robin Murphy" <robin.murphy@arm.com>,
> > "Jérôme Glisse" <jglisse@redhat.com>, "Dan Williams"
> > <dan.j.williams@intel.com>, "David Hildenbrand"
> > <david@redhat.com>, "Mike Rapoport" <rppt@linux.ibm.com>, "Veronika
> > Kabatova" <vkabatov@redhat.com>
> > Sent: Friday, March 5, 2021 6:38:14 AM
> > Subject: Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based
> > memory
> > 
> > 
> > On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > > This series fixes pfn_valid() for ZONE_DEVICE based memory and also
> > > improves
> > > its performance for normal hotplug memory. While here, it also
> > > reorganizes
> > > pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> > > 
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: James Morse <james.morse@arm.com>
> > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > Cc: Jérôme Glisse <jglisse@redhat.com>
> > > Cc: Dan Williams <dan.j.williams@intel.com>
> > > Cc: David Hildenbrand <david@redhat.com>
> > > Cc: Mike Rapoport <rppt@linux.ibm.com>
> > > Cc: Veronika Kabatova <vkabatov@redhat.com>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > Cc: linux-mm@kvack.org
> > > Cc: linux-kernel@vger.kernel.org
> > > 
> > > Changes in V3:
> > > 
> > > - Validate the pfn before fetching mem_section with __pfn_to_section() in
> > > [PATCH 2/2]
> > 
> > Hello Veronica,
> > 
> > Could you please help recreate the earlier failure [1] but with this
> > series applies on v5.12-rc1. Thank you.
> > 
> 
> Hello Anshuman,
> 
> the machine in question is currently loaned to a developer. I'll reach
> out to them and will let you know once I have any results.
> 

Hi,

I'm happy to report the kernel boots with these new patches. I used the
5.12.0-rc1 kernel (commit 280d542f6ffac0) as a base. The full console log
from the boot process is available at

https://gitlab.com/-/snippets/2086833

in case you want to take a look. Note that there are some call traces
starting around line 3220, but they are NOT introduced by these two
patches and are also present with the base mainline kernel.


Veronika

> 
> Veronika
> 
> > [1]
> > https://lore.kernel.org/linux-arm-kernel/cki.8D1CB60FEC.K6NJMEFQPV@redhat.com/
> > 
> > - Anshuman
> > 
> > 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05 18:16       ` Veronika Kabatova
@ 2021-03-05 18:22         ` Catalin Marinas
  -1 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-05 18:22 UTC (permalink / raw)
  To: Veronika Kabatova
  Cc: Anshuman Khandual, Will Deacon, linux-arm-kernel, linux-kernel,
	linux-mm, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport

On Fri, Mar 05, 2021 at 01:16:28PM -0500, Veronika Kabatova wrote:
> > > On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > > > This series fixes pfn_valid() for ZONE_DEVICE based memory and
> > > > also improves its performance for normal hotplug memory. While
> > > > here, it also reorganizes pfn_valid() on CONFIG_SPARSEMEM. This
> > > > series is based on v5.12-rc1.
[...]
> > > Could you please help recreate the earlier failure [1] but with this
> > > series applies on v5.12-rc1. Thank you.
> > 
> > the machine in question is currently loaned to a developer. I'll reach
> > out to them and will let you know once I have any results.
> 
> I'm happy to report the kernel boots with these new patches. I used the
> 5.12.0-rc1 kernel (commit 280d542f6ffac0) as a base. The full console log
> from the boot process is available at
> 
> https://gitlab.com/-/snippets/2086833

That's great Veronika. Thanks for confirming.

-- 
Catalin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05 18:22         ` Catalin Marinas
  0 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-05 18:22 UTC (permalink / raw)
  To: Veronika Kabatova
  Cc: Anshuman Khandual, Will Deacon, linux-arm-kernel, linux-kernel,
	linux-mm, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	David Hildenbrand, Mike Rapoport

On Fri, Mar 05, 2021 at 01:16:28PM -0500, Veronika Kabatova wrote:
> > > On 3/5/21 10:54 AM, Anshuman Khandual wrote:
> > > > This series fixes pfn_valid() for ZONE_DEVICE based memory and
> > > > also improves its performance for normal hotplug memory. While
> > > > here, it also reorganizes pfn_valid() on CONFIG_SPARSEMEM. This
> > > > series is based on v5.12-rc1.
[...]
> > > Could you please help recreate the earlier failure [1] but with this
> > > series applies on v5.12-rc1. Thank you.
> > 
> > the machine in question is currently loaned to a developer. I'll reach
> > out to them and will let you know once I have any results.
> 
> I'm happy to report the kernel boots with these new patches. I used the
> 5.12.0-rc1 kernel (commit 280d542f6ffac0) as a base. The full console log
> from the boot process is available at
> 
> https://gitlab.com/-/snippets/2086833

That's great Veronika. Thanks for confirming.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05 18:13     ` Catalin Marinas
@ 2021-03-05 18:24       ` David Hildenbrand
  -1 siblings, 0 replies; 26+ messages in thread
From: David Hildenbrand @ 2021-03-05 18:24 UTC (permalink / raw)
  To: Catalin Marinas, Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, Mike Rapoport,
	Veronika Kabatova

On 05.03.21 19:13, Catalin Marinas wrote:
> On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
>> pfn_valid() validates a pfn but basically it checks for a valid struct page
>> backing for that pfn. It should always return positive for memory ranges
>> backed with struct page mapping. But currently pfn_valid() fails for all
>> ZONE_DEVICE based memory types even though they have struct page mapping.
>>
>> pfn_valid() asserts that there is a memblock entry for a given pfn without
>> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
>> that they do not have memblock entries. Hence memblock_is_map_memory() will
>> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
>> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
>> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
>> into the system via memremap_pages() called from a driver, their respective
>> memory sections will not have SECTION_IS_EARLY set.
>>
>> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
>> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
>> for firmware reserved memory regions. memblock_is_map_memory() can just be
>> skipped as its always going to be positive and that will be an optimization
>> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
>> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
>>
>> Skipping memblock_is_map_memory() for all non early memory sections would
>> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
>> performance for normal hotplug memory as well.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>> Acked-by: David Hildenbrand <david@redhat.com>
>> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>   arch/arm64/mm/init.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
>> index 0ace5e68efba..5920c527845a 100644
>> --- a/arch/arm64/mm/init.c
>> +++ b/arch/arm64/mm/init.c
>> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>>   
>>   	if (!valid_section(__pfn_to_section(pfn)))
>>   		return 0;
>> +
>> +	/*
>> +	 * ZONE_DEVICE memory does not have the memblock entries.
>> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
>> +	 * addresses will always fail. Even the normal hotplugged
>> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
>> +	 * memblock entries. Skip memblock search for all non early
>> +	 * memory sections covering all of hotplug memory including
>> +	 * both normal and ZONE_DEVICE based.
>> +	 */
>> +	if (!early_section(__pfn_to_section(pfn)))
>> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
> 
> Would something like this work instead:
> 
> 	if (online_device_section(ms))
> 		return 1;
> 
> to avoid the assumptions around early_section()?
> 

Please keep online section logic out of pfn valid logic. Tow different 
things. (and rather not diverge too much from generic pfn_valid() - we 
want to achieve the opposite in the long term, merging both implementations)

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-05 18:24       ` David Hildenbrand
  0 siblings, 0 replies; 26+ messages in thread
From: David Hildenbrand @ 2021-03-05 18:24 UTC (permalink / raw)
  To: Catalin Marinas, Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, Mike Rapoport,
	Veronika Kabatova

On 05.03.21 19:13, Catalin Marinas wrote:
> On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
>> pfn_valid() validates a pfn but basically it checks for a valid struct page
>> backing for that pfn. It should always return positive for memory ranges
>> backed with struct page mapping. But currently pfn_valid() fails for all
>> ZONE_DEVICE based memory types even though they have struct page mapping.
>>
>> pfn_valid() asserts that there is a memblock entry for a given pfn without
>> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
>> that they do not have memblock entries. Hence memblock_is_map_memory() will
>> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
>> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
>> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
>> into the system via memremap_pages() called from a driver, their respective
>> memory sections will not have SECTION_IS_EARLY set.
>>
>> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
>> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
>> for firmware reserved memory regions. memblock_is_map_memory() can just be
>> skipped as its always going to be positive and that will be an optimization
>> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
>> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
>>
>> Skipping memblock_is_map_memory() for all non early memory sections would
>> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
>> performance for normal hotplug memory as well.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>> Acked-by: David Hildenbrand <david@redhat.com>
>> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>   arch/arm64/mm/init.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
>> index 0ace5e68efba..5920c527845a 100644
>> --- a/arch/arm64/mm/init.c
>> +++ b/arch/arm64/mm/init.c
>> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>>   
>>   	if (!valid_section(__pfn_to_section(pfn)))
>>   		return 0;
>> +
>> +	/*
>> +	 * ZONE_DEVICE memory does not have the memblock entries.
>> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
>> +	 * addresses will always fail. Even the normal hotplugged
>> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
>> +	 * memblock entries. Skip memblock search for all non early
>> +	 * memory sections covering all of hotplug memory including
>> +	 * both normal and ZONE_DEVICE based.
>> +	 */
>> +	if (!early_section(__pfn_to_section(pfn)))
>> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
> 
> Would something like this work instead:
> 
> 	if (online_device_section(ms))
> 		return 1;
> 
> to avoid the assumptions around early_section()?
> 

Please keep online section logic out of pfn valid logic. Tow different 
things. (and rather not diverge too much from generic pfn_valid() - we 
want to achieve the opposite in the long term, merging both implementations)

-- 
Thanks,

David / dhildenb


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05 18:24       ` David Hildenbrand
@ 2021-03-08 11:29         ` Catalin Marinas
  -1 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 11:29 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Anshuman Khandual, linux-arm-kernel, linux-kernel, linux-mm,
	Will Deacon, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 07:24:21PM +0100, David Hildenbrand wrote:
> On 05.03.21 19:13, Catalin Marinas wrote:
> > On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> > > pfn_valid() validates a pfn but basically it checks for a valid struct page
> > > backing for that pfn. It should always return positive for memory ranges
> > > backed with struct page mapping. But currently pfn_valid() fails for all
> > > ZONE_DEVICE based memory types even though they have struct page mapping.
> > > 
> > > pfn_valid() asserts that there is a memblock entry for a given pfn without
> > > MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> > > that they do not have memblock entries. Hence memblock_is_map_memory() will
> > > invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> > > eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> > > to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> > > into the system via memremap_pages() called from a driver, their respective
> > > memory sections will not have SECTION_IS_EARLY set.
> > > 
> > > Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> > > regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> > > for firmware reserved memory regions. memblock_is_map_memory() can just be
> > > skipped as its always going to be positive and that will be an optimization
> > > for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> > > hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> > > 
> > > Skipping memblock_is_map_memory() for all non early memory sections would
> > > fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> > > performance for normal hotplug memory as well.
> > > 
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Acked-by: David Hildenbrand <david@redhat.com>
> > > Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> > > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> > > ---
> > >   arch/arm64/mm/init.c | 12 ++++++++++++
> > >   1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> > > index 0ace5e68efba..5920c527845a 100644
> > > --- a/arch/arm64/mm/init.c
> > > +++ b/arch/arm64/mm/init.c
> > > @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
> > >   	if (!valid_section(__pfn_to_section(pfn)))
> > >   		return 0;
> > > +
> > > +	/*
> > > +	 * ZONE_DEVICE memory does not have the memblock entries.
> > > +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> > > +	 * addresses will always fail. Even the normal hotplugged
> > > +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> > > +	 * memblock entries. Skip memblock search for all non early
> > > +	 * memory sections covering all of hotplug memory including
> > > +	 * both normal and ZONE_DEVICE based.
> > > +	 */
> > > +	if (!early_section(__pfn_to_section(pfn)))
> > > +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
> > 
> > Would something like this work instead:
> > 
> > 	if (online_device_section(ms))
> > 		return 1;
> > 
> > to avoid the assumptions around early_section()?
> 
> Please keep online section logic out of pfn valid logic. Tow different
> things. (and rather not diverge too much from generic pfn_valid() - we want
> to achieve the opposite in the long term, merging both implementations)

I think I misread the code. I was looking for a new flag to check like
SECTION_IS_DEVICE instead of assuming that !SECTION_IS_EARLY means
device or mhp.

Anyway, staring at this code for a bit more, I came to the conclusion
that the logic in Anshuman's patches is fairly robust - we only need to
check for memblock_is_map_memory() if early_section() as that's the only
case where we can have MEMBLOCK_NOMAP. Maybe the comment above should be
re-written a bit and avoid the ZONE_DEVICE and hotplugged memory
details altogether.

-- 
Catalin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-08 11:29         ` Catalin Marinas
  0 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 11:29 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Anshuman Khandual, linux-arm-kernel, linux-kernel, linux-mm,
	Will Deacon, Ard Biesheuvel, Mark Rutland, James Morse,
	Robin Murphy, Jérôme Glisse, Dan Williams,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 07:24:21PM +0100, David Hildenbrand wrote:
> On 05.03.21 19:13, Catalin Marinas wrote:
> > On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> > > pfn_valid() validates a pfn but basically it checks for a valid struct page
> > > backing for that pfn. It should always return positive for memory ranges
> > > backed with struct page mapping. But currently pfn_valid() fails for all
> > > ZONE_DEVICE based memory types even though they have struct page mapping.
> > > 
> > > pfn_valid() asserts that there is a memblock entry for a given pfn without
> > > MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> > > that they do not have memblock entries. Hence memblock_is_map_memory() will
> > > invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> > > eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> > > to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> > > into the system via memremap_pages() called from a driver, their respective
> > > memory sections will not have SECTION_IS_EARLY set.
> > > 
> > > Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> > > regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> > > for firmware reserved memory regions. memblock_is_map_memory() can just be
> > > skipped as its always going to be positive and that will be an optimization
> > > for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> > > hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> > > 
> > > Skipping memblock_is_map_memory() for all non early memory sections would
> > > fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> > > performance for normal hotplug memory as well.
> > > 
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Acked-by: David Hildenbrand <david@redhat.com>
> > > Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> > > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> > > ---
> > >   arch/arm64/mm/init.c | 12 ++++++++++++
> > >   1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> > > index 0ace5e68efba..5920c527845a 100644
> > > --- a/arch/arm64/mm/init.c
> > > +++ b/arch/arm64/mm/init.c
> > > @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
> > >   	if (!valid_section(__pfn_to_section(pfn)))
> > >   		return 0;
> > > +
> > > +	/*
> > > +	 * ZONE_DEVICE memory does not have the memblock entries.
> > > +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> > > +	 * addresses will always fail. Even the normal hotplugged
> > > +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> > > +	 * memblock entries. Skip memblock search for all non early
> > > +	 * memory sections covering all of hotplug memory including
> > > +	 * both normal and ZONE_DEVICE based.
> > > +	 */
> > > +	if (!early_section(__pfn_to_section(pfn)))
> > > +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
> > 
> > Would something like this work instead:
> > 
> > 	if (online_device_section(ms))
> > 		return 1;
> > 
> > to avoid the assumptions around early_section()?
> 
> Please keep online section logic out of pfn valid logic. Tow different
> things. (and rather not diverge too much from generic pfn_valid() - we want
> to achieve the opposite in the long term, merging both implementations)

I think I misread the code. I was looking for a new flag to check like
SECTION_IS_DEVICE instead of assuming that !SECTION_IS_EARLY means
device or mhp.

Anyway, staring at this code for a bit more, I came to the conclusion
that the logic in Anshuman's patches is fairly robust - we only need to
check for memblock_is_map_memory() if early_section() as that's the only
case where we can have MEMBLOCK_NOMAP. Maybe the comment above should be
re-written a bit and avoid the ZONE_DEVICE and hotplugged memory
details altogether.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:24   ` Anshuman Khandual
@ 2021-03-08 17:59     ` Catalin Marinas
  -1 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 17:59 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> pfn_valid() validates a pfn but basically it checks for a valid struct page
> backing for that pfn. It should always return positive for memory ranges
> backed with struct page mapping. But currently pfn_valid() fails for all
> ZONE_DEVICE based memory types even though they have struct page mapping.
> 
> pfn_valid() asserts that there is a memblock entry for a given pfn without
> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> that they do not have memblock entries. Hence memblock_is_map_memory() will
> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> into the system via memremap_pages() called from a driver, their respective
> memory sections will not have SECTION_IS_EARLY set.
> 
> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> for firmware reserved memory regions. memblock_is_map_memory() can just be
> skipped as its always going to be positive and that will be an optimization
> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> 
> Skipping memblock_is_map_memory() for all non early memory sections would
> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> performance for normal hotplug memory as well.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Acked-by: David Hildenbrand <david@redhat.com>
> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  arch/arm64/mm/init.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 0ace5e68efba..5920c527845a 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>  
>  	if (!valid_section(__pfn_to_section(pfn)))
>  		return 0;
> +
> +	/*
> +	 * ZONE_DEVICE memory does not have the memblock entries.
> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> +	 * addresses will always fail. Even the normal hotplugged
> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> +	 * memblock entries. Skip memblock search for all non early
> +	 * memory sections covering all of hotplug memory including
> +	 * both normal and ZONE_DEVICE based.
> +	 */
> +	if (!early_section(__pfn_to_section(pfn)))
> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
>  #endif
>  	return memblock_is_map_memory(addr);
>  }

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-08 17:59     ` Catalin Marinas
  0 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 17:59 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:57AM +0530, Anshuman Khandual wrote:
> pfn_valid() validates a pfn but basically it checks for a valid struct page
> backing for that pfn. It should always return positive for memory ranges
> backed with struct page mapping. But currently pfn_valid() fails for all
> ZONE_DEVICE based memory types even though they have struct page mapping.
> 
> pfn_valid() asserts that there is a memblock entry for a given pfn without
> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is
> that they do not have memblock entries. Hence memblock_is_map_memory() will
> invariably fail via memblock_search() for a ZONE_DEVICE based address. This
> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs
> to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged
> into the system via memremap_pages() called from a driver, their respective
> memory sections will not have SECTION_IS_EARLY set.
> 
> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> for firmware reserved memory regions. memblock_is_map_memory() can just be
> skipped as its always going to be positive and that will be an optimization
> for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal
> hotplugged memory too will not have SECTION_IS_EARLY set for their sections
> 
> Skipping memblock_is_map_memory() for all non early memory sections would
> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> performance for normal hotplug memory as well.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Acked-by: David Hildenbrand <david@redhat.com>
> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  arch/arm64/mm/init.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 0ace5e68efba..5920c527845a 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn)
>  
>  	if (!valid_section(__pfn_to_section(pfn)))
>  		return 0;
> +
> +	/*
> +	 * ZONE_DEVICE memory does not have the memblock entries.
> +	 * memblock_is_map_memory() check for ZONE_DEVICE based
> +	 * addresses will always fail. Even the normal hotplugged
> +	 * memory will never have MEMBLOCK_NOMAP flag set in their
> +	 * memblock entries. Skip memblock search for all non early
> +	 * memory sections covering all of hotplug memory including
> +	 * both normal and ZONE_DEVICE based.
> +	 */
> +	if (!early_section(__pfn_to_section(pfn)))
> +		return pfn_section_valid(__pfn_to_section(pfn), pfn);
>  #endif
>  	return memblock_is_map_memory(addr);
>  }

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid()
  2021-03-05  5:24   ` Anshuman Khandual
@ 2021-03-08 18:00     ` Catalin Marinas
  -1 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 18:00 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:58AM +0530, Anshuman Khandual wrote:
> There are multiple instances of pfn_to_section_nr() and __pfn_to_section()
> when CONFIG_SPARSEMEM is enabled. This can be optimized if memory section
> is fetched earlier. This replaces the open coded PFN and ADDR conversion
> with PFN_PHYS() and PHYS_PFN() helpers. While there, also add a comment.
> This does not cause any functional change.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid()
@ 2021-03-08 18:00     ` Catalin Marinas
  0 siblings, 0 replies; 26+ messages in thread
From: Catalin Marinas @ 2021-03-08 18:00 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Will Deacon,
	Ard Biesheuvel, Mark Rutland, James Morse, Robin Murphy,
	Jérôme Glisse, Dan Williams, David Hildenbrand,
	Mike Rapoport, Veronika Kabatova

On Fri, Mar 05, 2021 at 10:54:58AM +0530, Anshuman Khandual wrote:
> There are multiple instances of pfn_to_section_nr() and __pfn_to_section()
> when CONFIG_SPARSEMEM is enabled. This can be optimized if memory section
> is fetched earlier. This replaces the open coded PFN and ADDR conversion
> with PFN_PHYS() and PHYS_PFN() helpers. While there, also add a comment.
> This does not cause any functional change.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
  2021-03-05  5:24 ` Anshuman Khandual
@ 2021-03-08 19:16   ` Will Deacon
  -1 siblings, 0 replies; 26+ messages in thread
From: Will Deacon @ 2021-03-08 19:16 UTC (permalink / raw)
  To: Anshuman Khandual, linux-arm-kernel, linux-kernel, linux-mm
  Cc: catalin.marinas, kernel-team, Will Deacon, Dan Williams,
	James Morse, Robin Murphy, Veronika Kabatova, David Hildenbrand,
	Mike Rapoport, Mark Rutland, Ard Biesheuvel,
	Jérôme Glisse

On Fri, 5 Mar 2021 10:54:56 +0530, Anshuman Khandual wrote:
> This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
> its performance for normal hotplug memory. While here, it also reorganizes
> pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Veronika Kabatova <vkabatov@redhat.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
      https://git.kernel.org/arm64/c/eeb0753ba27b
[2/2] arm64/mm: Reorganize pfn_valid()
      https://git.kernel.org/arm64/c/093bbe211ea5

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
@ 2021-03-08 19:16   ` Will Deacon
  0 siblings, 0 replies; 26+ messages in thread
From: Will Deacon @ 2021-03-08 19:16 UTC (permalink / raw)
  To: Anshuman Khandual, linux-arm-kernel, linux-kernel, linux-mm
  Cc: catalin.marinas, kernel-team, Will Deacon, Dan Williams,
	James Morse, Robin Murphy, Veronika Kabatova, David Hildenbrand,
	Mike Rapoport, Mark Rutland, Ard Biesheuvel,
	Jérôme Glisse

On Fri, 5 Mar 2021 10:54:56 +0530, Anshuman Khandual wrote:
> This series fixes pfn_valid() for ZONE_DEVICE based memory and also improves
> its performance for normal hotplug memory. While here, it also reorganizes
> pfn_valid() on CONFIG_SPARSEMEM. This series is based on v5.12-rc1.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Jérôme Glisse <jglisse@redhat.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Veronika Kabatova <vkabatov@redhat.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory
      https://git.kernel.org/arm64/c/eeb0753ba27b
[2/2] arm64/mm: Reorganize pfn_valid()
      https://git.kernel.org/arm64/c/093bbe211ea5

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2021-03-08 19:17 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  5:24 [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory Anshuman Khandual
2021-03-05  5:24 ` Anshuman Khandual
2021-03-05  5:24 ` [PATCH V3 1/2] " Anshuman Khandual
2021-03-05  5:24   ` Anshuman Khandual
2021-03-05 18:13   ` Catalin Marinas
2021-03-05 18:13     ` Catalin Marinas
2021-03-05 18:24     ` David Hildenbrand
2021-03-05 18:24       ` David Hildenbrand
2021-03-08 11:29       ` Catalin Marinas
2021-03-08 11:29         ` Catalin Marinas
2021-03-08 17:59   ` Catalin Marinas
2021-03-08 17:59     ` Catalin Marinas
2021-03-05  5:24 ` [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid() Anshuman Khandual
2021-03-05  5:24   ` Anshuman Khandual
2021-03-08 18:00   ` Catalin Marinas
2021-03-08 18:00     ` Catalin Marinas
2021-03-05  5:38 ` [PATCH V3 0/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory Anshuman Khandual
2021-03-05  5:38   ` Anshuman Khandual
2021-03-05 12:28   ` Veronika Kabatova
2021-03-05 12:28     ` Veronika Kabatova
2021-03-05 18:16     ` Veronika Kabatova
2021-03-05 18:16       ` Veronika Kabatova
2021-03-05 18:22       ` Catalin Marinas
2021-03-05 18:22         ` Catalin Marinas
2021-03-08 19:16 ` Will Deacon
2021-03-08 19:16   ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.