2023-03-29 07:21:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

On 32-bit without LPAE:

kernel/dma/debug.c: In function ‘debug_dma_dump_mappings’:
kernel/dma/debug.c:537:7: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
kernel/dma/debug.c: In function ‘dump_show’:
kernel/dma/debug.c:568:59: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 11 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]

Fixes: bd89d69a529fbef3 ("dma-debug: add cacheline to user/kernel space dump messages")
Reported-by: kernel test robot <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reported-by: [email protected]
Signed-off-by: Geert Uytterhoeven <[email protected]>
---
kernel/dma/debug.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 676142072d997b6a..f190651bcaddc9e9 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -534,11 +534,11 @@ void debug_dma_dump_mappings(struct device *dev)
if (!dev || dev == entry->dev) {
cln = to_cacheline_number(entry);
dev_info(entry->dev,
- "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
+ "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
type2name[entry->type], idx,
phys_addr(entry), entry->pfn,
entry->dev_addr, entry->size,
- cln, dir2name[entry->direction],
+ &cln, dir2name[entry->direction],
maperr2str[entry->map_err_type]);
}
}
@@ -565,13 +565,13 @@ static int dump_show(struct seq_file *seq, void *v)
list_for_each_entry(entry, &bucket->list, list) {
cln = to_cacheline_number(entry);
seq_printf(seq,
- "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
+ "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
dev_driver_string(entry->dev),
dev_name(entry->dev),
type2name[entry->type], idx,
phys_addr(entry), entry->pfn,
entry->dev_addr, entry->size,
- cln, dir2name[entry->direction],
+ &cln, dir2name[entry->direction],
maperr2str[entry->map_err_type]);
}
spin_unlock_irqrestore(&bucket->lock, flags);
--
2.34.1


2023-03-29 15:19:00

by Jerry Snitselaar

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

On Wed, Mar 29, 2023 at 09:14:05AM +0200, Geert Uytterhoeven wrote:
> On 32-bit without LPAE:
>
> kernel/dma/debug.c: In function ‘debug_dma_dump_mappings’:
> kernel/dma/debug.c:537:7: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
> kernel/dma/debug.c: In function ‘dump_show’:
> kernel/dma/debug.c:568:59: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 11 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
>
> Fixes: bd89d69a529fbef3 ("dma-debug: add cacheline to user/kernel space dump messages")
> Reported-by: kernel test robot <[email protected]>
> Link: https://lore.kernel.org/r/[email protected]
> Reported-by: [email protected]
> Signed-off-by: Geert Uytterhoeven <[email protected]>
> ---
> kernel/dma/debug.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
> index 676142072d997b6a..f190651bcaddc9e9 100644
> --- a/kernel/dma/debug.c
> +++ b/kernel/dma/debug.c
> @@ -534,11 +534,11 @@ void debug_dma_dump_mappings(struct device *dev)
> if (!dev || dev == entry->dev) {
> cln = to_cacheline_number(entry);
> dev_info(entry->dev,
> - "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
> + "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
> type2name[entry->type], idx,
> phys_addr(entry), entry->pfn,
> entry->dev_addr, entry->size,
> - cln, dir2name[entry->direction],
> + &cln, dir2name[entry->direction],

Won't this just print out the address of cln declared at the beginning of debug_dma_dump_mappings() each time, instead of the value
returned from to_cacheline_entry() ?

> maperr2str[entry->map_err_type]);
> }
> }
> @@ -565,13 +565,13 @@ static int dump_show(struct seq_file *seq, void *v)
> list_for_each_entry(entry, &bucket->list, list) {
> cln = to_cacheline_number(entry);
> seq_printf(seq,
> - "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
> + "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
> dev_driver_string(entry->dev),
> dev_name(entry->dev),
> type2name[entry->type], idx,
> phys_addr(entry), entry->pfn,
> entry->dev_addr, entry->size,
> - cln, dir2name[entry->direction],
> + &cln, dir2name[entry->direction],

same for dump_show()

> maperr2str[entry->map_err_type]);
> }
> spin_unlock_irqrestore(&bucket->lock, flags);
> --
> 2.34.1
>

2023-03-29 15:37:18

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

Hi Jerry,

On Wed, Mar 29, 2023 at 5:03 PM Jerry Snitselaar <[email protected]> wrote:
> On Wed, Mar 29, 2023 at 09:14:05AM +0200, Geert Uytterhoeven wrote:
> > On 32-bit without LPAE:
> >
> > kernel/dma/debug.c: In function ‘debug_dma_dump_mappings’:
> > kernel/dma/debug.c:537:7: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
> > kernel/dma/debug.c: In function ‘dump_show’:
> > kernel/dma/debug.c:568:59: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 11 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
> >
> > Fixes: bd89d69a529fbef3 ("dma-debug: add cacheline to user/kernel space dump messages")
> > Reported-by: kernel test robot <[email protected]>
> > Link: https://lore.kernel.org/r/[email protected]
> > Reported-by: [email protected]
> > Signed-off-by: Geert Uytterhoeven <[email protected]>
=
> > --- a/kernel/dma/debug.c
> > +++ b/kernel/dma/debug.c
> > @@ -534,11 +534,11 @@ void debug_dma_dump_mappings(struct device *dev)
> > if (!dev || dev == entry->dev) {
> > cln = to_cacheline_number(entry);
> > dev_info(entry->dev,
> > - "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
> > + "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
> > type2name[entry->type], idx,
> > phys_addr(entry), entry->pfn,
> > entry->dev_addr, entry->size,
> > - cln, dir2name[entry->direction],
> > + &cln, dir2name[entry->direction],
>
> Won't this just print out the address of cln declared at the beginning of debug_dma_dump_mappings() each time, instead of the value
> returned from to_cacheline_entry() ?

The physical address is passed by reference, cfr.
https://elixir.bootlin.com/linux/latest/source/Documentation/core-api/printk-formats.rst#L231

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-03-29 15:40:15

by Jerry Snitselaar

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

On Wed, Mar 29, 2023 at 05:34:23PM +0200, Geert Uytterhoeven wrote:
> Hi Jerry,
>
> On Wed, Mar 29, 2023 at 5:03 PM Jerry Snitselaar <[email protected]> wrote:
> > On Wed, Mar 29, 2023 at 09:14:05AM +0200, Geert Uytterhoeven wrote:
> > > On 32-bit without LPAE:
> > >
> > > kernel/dma/debug.c: In function ‘debug_dma_dump_mappings’:
> > > kernel/dma/debug.c:537:7: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
> > > kernel/dma/debug.c: In function ‘dump_show’:
> > > kernel/dma/debug.c:568:59: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 11 has type ‘phys_addr_t’ {aka ‘unsigned int’} [-Wformat=]
> > >
> > > Fixes: bd89d69a529fbef3 ("dma-debug: add cacheline to user/kernel space dump messages")
> > > Reported-by: kernel test robot <[email protected]>
> > > Link: https://lore.kernel.org/r/[email protected]
> > > Reported-by: [email protected]
> > > Signed-off-by: Geert Uytterhoeven <[email protected]>
> =
> > > --- a/kernel/dma/debug.c
> > > +++ b/kernel/dma/debug.c
> > > @@ -534,11 +534,11 @@ void debug_dma_dump_mappings(struct device *dev)
> > > if (!dev || dev == entry->dev) {
> > > cln = to_cacheline_number(entry);
> > > dev_info(entry->dev,
> > > - "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%llx %s %s\n",
> > > + "%s idx %d P=%llx N=%lx D=%llx L=%llx cln=%pa %s %s\n",
> > > type2name[entry->type], idx,
> > > phys_addr(entry), entry->pfn,
> > > entry->dev_addr, entry->size,
> > > - cln, dir2name[entry->direction],
> > > + &cln, dir2name[entry->direction],
> >
> > Won't this just print out the address of cln declared at the beginning of debug_dma_dump_mappings() each time, instead of the value
> > returned from to_cacheline_entry() ?
>
> The physical address is passed by reference, cfr.
> https://elixir.bootlin.com/linux/latest/source/Documentation/core-api/printk-formats.rst#L231
>
> Gr{oetje,eeting}s,
>
> Geert

Got it. Thanks Geert

snits

>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds

2023-03-29 23:51:29

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

I've applied this as it is the first fix I got into my mailbox for it.

Arnd sent one a little later, which uses %pap instead of %pa, which
confused me a bit. The documentation seems to allow both without
any recommendation which one to use, which confuses me even further.

2023-03-30 06:52:43

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

On Thu, Mar 30, 2023, at 01:50, Christoph Hellwig wrote:
> I've applied this as it is the first fix I got into my mailbox for it.
>
> Arnd sent one a little later, which uses %pap instead of %pa, which
> confused me a bit. The documentation seems to allow both without
> any recommendation which one to use, which confuses me even further.

Indeed, I wasn't aware of this either, apparently aaf07621b8bb
("vsprintf: add %pad extension for dma_addr_t use") introduced the
%pap form at the same time as %pad but made it the same as the already
existing %pa. I also see that the %pa form is a lot more common than
%pap, so it's probably better to go with %pa for new users anyway.

Arnd

2023-03-30 07:13:01

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH -next] dma-debug: Use %pa to format phys_addr_t

Hi Christoph,

On Thu, Mar 30, 2023 at 1:50 AM Christoph Hellwig <[email protected]> wrote:
> I've applied this as it is the first fix I got into my mailbox for it.

Thank you!

> Arnd sent one a little later, which uses %pap instead of %pa, which
> confused me a bit. The documentation seems to allow both without
> any recommendation which one to use, which confuses me even further.

The "%pa" class supports two variants: "%pad" (for dma_addr_t) and
"%pap" (for phys_addr_t). "%pa" is a shortcut for the latter, cfr.
https://elixir.bootlin.com/linux/latest/source/lib/vsprintf.c#L1792

The default exists because "%pa" was fist, cfr. commit aaf07621b8bbfdc0
("vsprintf: add %pad extension for dma_addr_t use"), and I don't think
we can easily remove it. The default is shorter (saves one byte, even
compared to %llx"), so why not use it?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds