* [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding
@ 2020-03-06 10:19 qiwuchen55
2020-03-11 2:10 ` John Hubbard
0 siblings, 1 reply; 4+ messages in thread
From: qiwuchen55 @ 2020-03-06 10:19 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, chenqiwu
From: chenqiwu <chenqiwu@xiaomi.com>
Use wrapped macros instead of open-coding for better code
readability.
Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
mm/sparse.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/sparse.c b/mm/sparse.c
index 42c18a3..9b14164 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -385,8 +385,8 @@ static void __init check_usemap_section_nr(int nid,
old_pgdat_snr = NR_MEM_SECTIONS;
}
- usemap_snr = pfn_to_section_nr(__pa(usage) >> PAGE_SHIFT);
- pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT);
+ usemap_snr = pfn_to_section_nr(virt_to_pfn(usage));
+ pgdat_snr = pfn_to_section_nr(virt_to_pfn(pgdat));
if (usemap_snr == pgdat_snr)
return;
@@ -677,7 +677,7 @@ struct page * __meminit populate_section_memmap(unsigned long pfn,
return NULL;
got_map_page:
- ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
+ ret = (struct page *)page_to_virt(page);
got_map_ptr:
return ret;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding
2020-03-06 10:19 [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding qiwuchen55
@ 2020-03-11 2:10 ` John Hubbard
2020-03-11 8:01 ` chenqiwu
0 siblings, 1 reply; 4+ messages in thread
From: John Hubbard @ 2020-03-11 2:10 UTC (permalink / raw)
To: qiwuchen55, akpm; +Cc: linux-mm, chenqiwu
On 3/6/20 2:19 AM, qiwuchen55@gmail.com wrote:
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> Use wrapped macros instead of open-coding for better code
> readability.
>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
This breaks my x86 (64-bit) build:
mm/sparse.c: In function ‘check_usemap_section_nr’:
mm/sparse.c:389:33: error: implicit declaration of function ‘virt_to_pfn’; did you mean ‘virt_to_phys’? [-Werror=implicit-function-declaration]
389 | usemap_snr = pfn_to_section_nr(virt_to_pfn(usage));
| ^~~~~~~~~~~
| virt_to_phys
...and I think the reason is that the arch/x86/include/asm/page.h does not
have virt_to_pfn(). For that reason, I'm concerned that the following fix,
which fixes up x86, may not completely correct for the patch.
Here's a compile-tested (only, and only on x86 64-bit) fix:
diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
index 7555b48803a8..982bc76bf13c 100644
--- a/arch/x86/include/asm/page.h
+++ b/arch/x86/include/asm/page.h
@@ -62,6 +62,9 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
#define __boot_va(x) __va(x)
#define __boot_pa(x) __pa(x)
+#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
+#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
+
/*
* virt_to_page(kaddr) returns a valid pointer if and only if
* virt_addr_valid(kaddr) returns true.
thanks,
--
John Hubbard
NVIDIA
> ---
> mm/sparse.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 42c18a3..9b14164 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -385,8 +385,8 @@ static void __init check_usemap_section_nr(int nid,
> old_pgdat_snr = NR_MEM_SECTIONS;
> }
>
> - usemap_snr = pfn_to_section_nr(__pa(usage) >> PAGE_SHIFT);
> - pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT);
> + usemap_snr = pfn_to_section_nr(virt_to_pfn(usage));
> + pgdat_snr = pfn_to_section_nr(virt_to_pfn(pgdat));
> if (usemap_snr == pgdat_snr)
> return;
>
> @@ -677,7 +677,7 @@ struct page * __meminit populate_section_memmap(unsigned long pfn,
>
> return NULL;
> got_map_page:
> - ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
> + ret = (struct page *)page_to_virt(page);
> got_map_ptr:
>
> return ret;
>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding
2020-03-11 2:10 ` John Hubbard
@ 2020-03-11 8:01 ` chenqiwu
2020-03-12 1:09 ` John Hubbard
0 siblings, 1 reply; 4+ messages in thread
From: chenqiwu @ 2020-03-11 8:01 UTC (permalink / raw)
To: John Hubbard; +Cc: akpm, linux-mm, chenqiwu
On Tue, Mar 10, 2020 at 07:10:10PM -0700, John Hubbard wrote:
> On 3/6/20 2:19 AM, qiwuchen55@gmail.com wrote:
> > From: chenqiwu <chenqiwu@xiaomi.com>
> >
> > Use wrapped macros instead of open-coding for better code
> > readability.
> >
> > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
>
>
> This breaks my x86 (64-bit) build:
>
> mm/sparse.c: In function ‘check_usemap_section_nr’:
> mm/sparse.c:389:33: error: implicit declaration of function ‘virt_to_pfn’; did you mean ‘virt_to_phys’? [-Werror=implicit-function-declaration]
> 389 | usemap_snr = pfn_to_section_nr(virt_to_pfn(usage));
> | ^~~~~~~~~~~
> | virt_to_phys
>
>
> ...and I think the reason is that the arch/x86/include/asm/page.h does not
> have virt_to_pfn(). For that reason, I'm concerned that the following fix,
> which fixes up x86, may not completely correct for the patch.
>
> Here's a compile-tested (only, and only on x86 64-bit) fix:
>
> diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
> index 7555b48803a8..982bc76bf13c 100644
> --- a/arch/x86/include/asm/page.h
> +++ b/arch/x86/include/asm/page.h
> @@ -62,6 +62,9 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
> #define __boot_va(x) __va(x)
> #define __boot_pa(x) __pa(x)
>
> +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
> +#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
> +
> /*
> * virt_to_page(kaddr) returns a valid pointer if and only if
> * virt_addr_valid(kaddr) returns true.
>
>
> thanks,
> --
> John Hubbard
> NVIDIA
Hi John,
I tested this patch only on arm64 build, not sure if any other build
breakings. But I think any architecture is worth to support virt_to_pfn()
API. Could you please send your compile-tested patch to x86 upstream?
Thanks
Qiwu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding
2020-03-11 8:01 ` chenqiwu
@ 2020-03-12 1:09 ` John Hubbard
0 siblings, 0 replies; 4+ messages in thread
From: John Hubbard @ 2020-03-12 1:09 UTC (permalink / raw)
To: chenqiwu; +Cc: akpm, linux-mm, chenqiwu
On 3/11/20 1:01 AM, chenqiwu wrote:
...
>
> Hi John,
> I tested this patch only on arm64 build, not sure if any other build
> breakings. But I think any architecture is worth to support virt_to_pfn()
If a patch causes a build break (on any architecture), it normally should not
be merged into any maintainer's git tree. That's why the patch submission
checklist, here:
https://www.kernel.org/doc/html/latest/process/submit-checklist.html
...requests "Builds on multiple CPU architectures".
We don't all always do all of the steps there, but it is still a good baseline
checklist. And conversely, if you routinely skip key steps such as cross-compilation,
then reviewers have a lot more to worry about when looking at your patch submissions,
so that potentially slows down approvals.
> API. Could you please send your compile-tested patch to x86 upstream?
>
I don't think that will help in this case, unless of course there is something
wrong with my build setup, and I'm seeing a problem that no one else sees.
thanks,
--
John Hubbard
NVIDIA
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-12 1:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 10:19 [RESEND PATCH] mm/sparsemem: use wrapped macros instead of open-coding qiwuchen55
2020-03-11 2:10 ` John Hubbard
2020-03-11 8:01 ` chenqiwu
2020-03-12 1:09 ` John Hubbard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).