2020-06-16 07:49:58

by Zong Li

[permalink] [raw]
Subject: [PATCH 0/2] Add STRICT_DEVMEM support on RISC-V

This patchset include two parts, the first one is that register System
RAM as iomem resources, it is needed for page_is_ram API which checks
the specified address whether registered as System RAM in iomem_resource
list. The second patch is that add devmem_is_allowed to support
STRICT_DEVMEM, and it would invoke page_is_ram to check the addresses.

Zong Li (2):
riscv: Register System RAM as iomem resources
riscv: Support CONFIG_STRICT_DEVMEM

arch/riscv/Kconfig | 1 +
arch/riscv/include/asm/io.h | 2 ++
arch/riscv/mm/init.c | 41 +++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+)

--
2.27.0


2020-06-16 07:50:08

by Zong Li

[permalink] [raw]
Subject: [PATCH 1/2] riscv: Register System RAM as iomem resources

Add System RAM to /proc/iomem, various tools expect it such as kdump.
It is also needed for page_is_ram API which checks the specified address
whether registered as System RAM in iomem_resource list.

Signed-off-by: Zong Li <[email protected]>
---
arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index f4adb3684f3d..bbe816e03b2f 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -517,6 +517,27 @@ void mark_rodata_ro(void)
}
#endif

+void __init resource_init(void)
+{
+ struct memblock_region *region;
+
+ for_each_memblock(memory, region) {
+ struct resource *res;
+
+ res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
+ if (!res)
+ panic("%s: Failed to allocate %zu bytes\n", __func__,
+ sizeof(struct resource));
+
+ res->name = "System RAM";
+ res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
+ res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
+ res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
+
+ request_resource(&iomem_resource, res);
+ }
+}
+
void __init paging_init(void)
{
setup_vm_final();
@@ -524,6 +545,7 @@ void __init paging_init(void)
sparse_init();
setup_zero_page();
zone_sizes_init();
+ resource_init();
}

#ifdef CONFIG_SPARSEMEM_VMEMMAP
--
2.27.0

2020-06-16 11:59:51

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [PATCH 1/2] riscv: Register System RAM as iomem resources

Στις 2020-06-16 10:45, Zong Li έγραψε:
> Add System RAM to /proc/iomem, various tools expect it such as kdump.
> It is also needed for page_is_ram API which checks the specified
> address
> whether registered as System RAM in iomem_resource list.
>
> Signed-off-by: Zong Li <[email protected]>
> ---
> arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index f4adb3684f3d..bbe816e03b2f 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -517,6 +517,27 @@ void mark_rodata_ro(void)
> }
> #endif
>
> +void __init resource_init(void)
> +{
> + struct memblock_region *region;
> +
> + for_each_memblock(memory, region) {
> + struct resource *res;
> +
> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
> + if (!res)
> + panic("%s: Failed to allocate %zu bytes\n", __func__,
> + sizeof(struct resource));
> +
> + res->name = "System RAM";
> + res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
> 1;
> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> +
> + request_resource(&iomem_resource, res);
> + }
> +}
> +
> void __init paging_init(void)
> {
> setup_vm_final();
> @@ -524,6 +545,7 @@ void __init paging_init(void)
> sparse_init();
> setup_zero_page();
> zone_sizes_init();
> + resource_init();
> }
>
> #ifdef CONFIG_SPARSEMEM_VMEMMAP


I already have a patch for registering System RAM as an iomem resource
on my kexec/kdump series. Since I don't care about System RAM regions
being accurately exposed to userspace (I parse the current device tree
instead) I just use memblock_start_of_DRAM/end_of_DRAM. This approach
from arm64 codebase is better since it also handles the case of sparse
memory regions but in order to be useful for kdump we need to add the
various segments of the kernel image as child nodes to their respective
region for kexec-tools. I'll re-spin my patchset anyway so I'll extend
it to better handle System RAM regions.

2020-06-17 01:26:04

by Zong Li

[permalink] [raw]
Subject: Re: [PATCH 1/2] riscv: Register System RAM as iomem resources

On Tue, Jun 16, 2020 at 7:52 PM Nick Kossifidis <[email protected]> wrote:
>
> Στις 2020-06-16 10:45, Zong Li έγραψε:
> > Add System RAM to /proc/iomem, various tools expect it such as kdump.
> > It is also needed for page_is_ram API which checks the specified
> > address
> > whether registered as System RAM in iomem_resource list.
> >
> > Signed-off-by: Zong Li <[email protected]>
> > ---
> > arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
> > 1 file changed, 22 insertions(+)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index f4adb3684f3d..bbe816e03b2f 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -517,6 +517,27 @@ void mark_rodata_ro(void)
> > }
> > #endif
> >
> > +void __init resource_init(void)
> > +{
> > + struct memblock_region *region;
> > +
> > + for_each_memblock(memory, region) {
> > + struct resource *res;
> > +
> > + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
> > + if (!res)
> > + panic("%s: Failed to allocate %zu bytes\n", __func__,
> > + sizeof(struct resource));
> > +
> > + res->name = "System RAM";
> > + res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
> > + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
> > 1;
> > + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> > +
> > + request_resource(&iomem_resource, res);
> > + }
> > +}
> > +
> > void __init paging_init(void)
> > {
> > setup_vm_final();
> > @@ -524,6 +545,7 @@ void __init paging_init(void)
> > sparse_init();
> > setup_zero_page();
> > zone_sizes_init();
> > + resource_init();
> > }
> >
> > #ifdef CONFIG_SPARSEMEM_VMEMMAP
>
>
> I already have a patch for registering System RAM as an iomem resource
> on my kexec/kdump series. Since I don't care about System RAM regions
> being accurately exposed to userspace (I parse the current device tree
> instead) I just use memblock_start_of_DRAM/end_of_DRAM. This approach
> from arm64 codebase is better since it also handles the case of sparse
> memory regions but in order to be useful for kdump we need to add the
> various segments of the kernel image as child nodes to their respective
> region for kexec-tools. I'll re-spin my patchset anyway so I'll extend
> it to better handle System RAM regions.

OK, great, I would remove this patch here and only reserve the second
patch in the next version.

2020-07-09 18:28:22

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH 1/2] riscv: Register System RAM as iomem resources

On Tue, 16 Jun 2020 00:45:46 PDT (-0700), [email protected] wrote:
> Add System RAM to /proc/iomem, various tools expect it such as kdump.
> It is also needed for page_is_ram API which checks the specified address
> whether registered as System RAM in iomem_resource list.
>
> Signed-off-by: Zong Li <[email protected]>
> ---
> arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index f4adb3684f3d..bbe816e03b2f 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -517,6 +517,27 @@ void mark_rodata_ro(void)
> }
> #endif
>
> +void __init resource_init(void)
> +{
> + struct memblock_region *region;
> +
> + for_each_memblock(memory, region) {
> + struct resource *res;
> +
> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
> + if (!res)
> + panic("%s: Failed to allocate %zu bytes\n", __func__,
> + sizeof(struct resource));
> +
> + res->name = "System RAM";
> + res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;

Looks like everyone else is checking MEMBLOCK_NOMAP before registering memory
regions. I've added that and put this on for-next. Thanks!

commit 11dc632bf515874c84887727614e8044452f1f28
gpg: Signature made Thu 09 Jul 2020 11:24:08 AM PDT
gpg: using RSA key 2B3C3747446843B24A943A7A2E1319F35FBB1889
gpg: issuer "[email protected]"
gpg: Good signature from "Palmer Dabbelt <[email protected]>" [ultimate]
gpg: aka "Palmer Dabbelt <[email protected]>" [ultimate]
Author: Zong Li <[email protected]>
Date: Tue Jun 16 15:45:46 2020 +0800

riscv: Register System RAM as iomem resources

Add System RAM to /proc/iomem, various tools expect it such as kdump.
It is also needed for page_is_ram API which checks the specified address
whether registered as System RAM in iomem_resource list.

Signed-off-by: Zong Li <[email protected]>
[Palmer: check MEMBLOCK_NOMAP]
Signed-off-by: Palmer Dabbelt <[email protected]>

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index f4adb3684f3d..8b78fd23713e 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -517,6 +517,32 @@ void mark_rodata_ro(void)
}
#endif

+void __init resource_init(void)
+{
+ struct memblock_region *region;
+
+ for_each_memblock(memory, region) {
+ struct resource *res;
+
+ res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
+ if (!res)
+ panic("%s: Failed to allocate %zu bytes\n", __func__,
+ sizeof(struct resource));
+
+ if (memblock_is_nomap(region) {
+ res->name = "reserved";
+ res->flags = IORESOURCE_MEM;
+ } else {
+ res->name = "System RAM";
+ res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
+ }
+ res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
+ res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
+
+ request_resource(&iomem_resource, res);
+ }
+}
+
void __init paging_init(void)
{
setup_vm_final();
@@ -524,6 +550,7 @@ void __init paging_init(void)
sparse_init();
setup_zero_page();
zone_sizes_init();
+ resource_init();
}

#ifdef CONFIG_SPARSEMEM_VMEMMAP


> +
> + request_resource(&iomem_resource, res);
> + }
> +}
> +
> void __init paging_init(void)
> {
> setup_vm_final();
> @@ -524,6 +545,7 @@ void __init paging_init(void)
> sparse_init();
> setup_zero_page();
> zone_sizes_init();
> + resource_init();
> }
>
> #ifdef CONFIG_SPARSEMEM_VMEMMAP

2020-07-10 02:06:36

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [PATCH 1/2] riscv: Register System RAM as iomem resources

Στις 2020-07-09 21:27, Palmer Dabbelt έγραψε:
> On Tue, 16 Jun 2020 00:45:46 PDT (-0700), [email protected] wrote:
>> Add System RAM to /proc/iomem, various tools expect it such as kdump.
>> It is also needed for page_is_ram API which checks the specified
>> address
>> whether registered as System RAM in iomem_resource list.
>>
>> Signed-off-by: Zong Li <[email protected]>
>> ---
>> arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
>> 1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> index f4adb3684f3d..bbe816e03b2f 100644
>> --- a/arch/riscv/mm/init.c
>> +++ b/arch/riscv/mm/init.c
>> @@ -517,6 +517,27 @@ void mark_rodata_ro(void)
>> }
>> #endif
>>
>> +void __init resource_init(void)
>> +{
>> + struct memblock_region *region;
>> +
>> + for_each_memblock(memory, region) {
>> + struct resource *res;
>> +
>> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
>> + if (!res)
>> + panic("%s: Failed to allocate %zu bytes\n", __func__,
>> + sizeof(struct resource));
>> +
>> + res->name = "System RAM";
>> + res->start =
>> __pfn_to_phys(memblock_region_memory_base_pfn(region));
>> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
>> 1;
>> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
>
> Looks like everyone else is checking MEMBLOCK_NOMAP before registering
> memory
> regions. I've added that and put this on for-next. Thanks!
>
> commit 11dc632bf515874c84887727614e8044452f1f28
> gpg: Signature made Thu 09 Jul 2020 11:24:08 AM PDT
> gpg: using RSA key
> 2B3C3747446843B24A943A7A2E1319F35FBB1889
> gpg: issuer "[email protected]"
> gpg: Good signature from "Palmer Dabbelt <[email protected]>"
> [ultimate]
> gpg: aka "Palmer Dabbelt <[email protected]>"
> [ultimate]
> Author: Zong Li <[email protected]>
> Date: Tue Jun 16 15:45:46 2020 +0800
>
> riscv: Register System RAM as iomem resources
> Add System RAM to /proc/iomem, various tools expect it such as
> kdump.
> It is also needed for page_is_ram API which checks the specified
> address
> whether registered as System RAM in iomem_resource list.
> Signed-off-by: Zong Li <[email protected]>
> [Palmer: check MEMBLOCK_NOMAP]
> Signed-off-by: Palmer Dabbelt <[email protected]>
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index f4adb3684f3d..8b78fd23713e 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -517,6 +517,32 @@ void mark_rodata_ro(void)
> }
> #endif
>
> +void __init resource_init(void)
> +{
> + struct memblock_region *region;
> +
> + for_each_memblock(memory, region) {
> + struct resource *res;
> +
> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
> + if (!res)
> + panic("%s: Failed to allocate %zu bytes\n", __func__,
> + sizeof(struct resource));
> +
> + if (memblock_is_nomap(region) {
> + res->name = "reserved";
> + res->flags = IORESOURCE_MEM;
> + } else {
> + res->name = "System RAM";
> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> + }
> + res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
> 1;
> +
> + request_resource(&iomem_resource, res);
> + }
> +}
> +
> void __init paging_init(void)
> {
> setup_vm_final();
> @@ -524,6 +550,7 @@ void __init paging_init(void)
> sparse_init();
> setup_zero_page();
> zone_sizes_init();
> + resource_init();
> }
>
> #ifdef CONFIG_SPARSEMEM_VMEMMAP
>
>
>> +
>> + request_resource(&iomem_resource, res);
>> + }
>> +}
>> +
>> void __init paging_init(void)
>> {
>> setup_vm_final();
>> @@ -524,6 +545,7 @@ void __init paging_init(void)
>> sparse_init();
>> setup_zero_page();
>> zone_sizes_init();
>> + resource_init();
>> }
>>
>> #ifdef CONFIG_SPARSEMEM_VMEMMAP
>
> _______________________________________________
> linux-riscv mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-riscv

Zong Li sent a newer version of this series without this patch, since
I'm handling this on the kexec/kdump series as well where other sections
needed for kdump are also registered.