* [PATCH] x86: asm/io.h: Harden virt_to_phys/isa_virt_to_bus prototypes
@ 2023-04-14 9:40 Stanislav Kinsburskii
2023-04-22 9:02 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Stanislav Kinsburskii @ 2023-04-14 9:40 UTC (permalink / raw)
Cc: Stanislav Kinsburskii, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Geert Uytterhoeven, Arnd Bergmann, Chris Down, Helge Deller,
Omar Sandoval, linux-kernel
From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
These two helper functions - virt_to_phys and isa_virt_to_bus - don't need the
address pointer to be mutable.
In the same time expecting it to be mutable leads to the following build
warning for constant pointers:
warning: passing argument 1 of ‘virt_to_phys’ discards ‘const’ qualifier from pointer target type
Signed-off-by: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: x86@kernel.org
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Geert Uytterhoeven <geert@linux-m68k.org>
CC: Arnd Bergmann <arnd@arndb.de>
CC: Chris Down <chris@chrisdown.name>
CC: Helge Deller <deller@gmx.de>
CC: Omar Sandoval <osandov@fb.com>
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/io.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index e9025640f634..0e6f5b48f517 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -128,7 +128,7 @@ extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
* this function
*/
-static inline phys_addr_t virt_to_phys(volatile void *address)
+static inline phys_addr_t virt_to_phys(const volatile void *address)
{
return __pa(address);
}
@@ -163,7 +163,7 @@ static inline void *phys_to_virt(phys_addr_t address)
* However, we truncate the address to unsigned int to avoid undesirable
* promotions in legacy drivers.
*/
-static inline unsigned int isa_virt_to_bus(volatile void *address)
+static inline unsigned int isa_virt_to_bus(const volatile void *address)
{
return (unsigned int)virt_to_phys(address);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: asm/io.h: Harden virt_to_phys/isa_virt_to_bus prototypes
2023-04-22 9:02 ` Arnd Bergmann
@ 2023-04-15 3:23 ` Stanislav Kinsburskii
0 siblings, 0 replies; 3+ messages in thread
From: Stanislav Kinsburskii @ 2023-04-15 3:23 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Stanislav Kinsburskii, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Geert Uytterhoeven, Chris Down, Helge Deller, Omar Sandoval,
linux-kernel
On Sat, Apr 22, 2023 at 11:02:33AM +0200, Arnd Bergmann wrote:
> On Fri, Apr 14, 2023, at 11:40, Stanislav Kinsburskii wrote:
> > From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
> >
> > These two helper functions - virt_to_phys and isa_virt_to_bus - don't need the
> > address pointer to be mutable.
> >
> > In the same time expecting it to be mutable leads to the following build
> > warning for constant pointers:
> >
> > warning: passing argument 1 of ‘virt_to_phys’ discards ‘const’
> > qualifier from pointer target type
> >
>
> The change looks fine, and this is clearly useful for spreading
> more 'const' annotations, but I have two concerns:
>
> - I'd really like this to be done consistently across architectures,
> so at least the asm-generic/io.h version should get the same
> annotation, or ideally all of them in one patch.
>
Sure, let me come up with the a series to cover other architectures.
> - I would not describe this change itself as "hardening", as it
> also does the opposite, when you have a pointer that is actually
> "const" but converting it through virt_to_phys() and back
> through phys_to_virt() ends up losing the annotation.
>
Indeen, I didn't think about this way.
Let me then just state what the change does (i.e. "Make virt_to_phys to
allow unmutable pointers"), unless you have a better option to advice.
Thanks,
Stanislav
> Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: asm/io.h: Harden virt_to_phys/isa_virt_to_bus prototypes
2023-04-14 9:40 [PATCH] x86: asm/io.h: Harden virt_to_phys/isa_virt_to_bus prototypes Stanislav Kinsburskii
@ 2023-04-22 9:02 ` Arnd Bergmann
2023-04-15 3:23 ` Stanislav Kinsburskii
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2023-04-22 9:02 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: Stanislav Kinsburskii, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Geert Uytterhoeven, Chris Down, Helge Deller, Omar Sandoval,
linux-kernel
On Fri, Apr 14, 2023, at 11:40, Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
>
> These two helper functions - virt_to_phys and isa_virt_to_bus - don't need the
> address pointer to be mutable.
>
> In the same time expecting it to be mutable leads to the following build
> warning for constant pointers:
>
> warning: passing argument 1 of ‘virt_to_phys’ discards ‘const’
> qualifier from pointer target type
>
The change looks fine, and this is clearly useful for spreading
more 'const' annotations, but I have two concerns:
- I'd really like this to be done consistently across architectures,
so at least the asm-generic/io.h version should get the same
annotation, or ideally all of them in one patch.
- I would not describe this change itself as "hardening", as it
also does the opposite, when you have a pointer that is actually
"const" but converting it through virt_to_phys() and back
through phys_to_virt() ends up losing the annotation.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-26 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 9:40 [PATCH] x86: asm/io.h: Harden virt_to_phys/isa_virt_to_bus prototypes Stanislav Kinsburskii
2023-04-22 9:02 ` Arnd Bergmann
2023-04-15 3:23 ` Stanislav Kinsburskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®