* [PATCH v2 1/3] um: virt-pci: fix 32-bit compile
@ 2021-09-15 18:30 Johannes Berg
2021-09-15 18:30 ` [PATCH v2 2/3] lib/logic_iomem: fix 32-bit build Johannes Berg
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Johannes Berg @ 2021-09-15 18:30 UTC (permalink / raw)
To: linux-um; +Cc: Johannes Berg, Al Viro
From: Johannes Berg <johannes.berg@intel.com>
There were a few 32-bit compile warnings that of course
turned into errors with -Werror, fix the 32-bit build.
Fixes: 68f5d3f3b654 ("um: add PCI over virtio emulation driver")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
arch/um/drivers/virt-pci.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/um/drivers/virt-pci.c b/arch/um/drivers/virt-pci.c
index c08066633023..0ab58016db22 100644
--- a/arch/um/drivers/virt-pci.c
+++ b/arch/um/drivers/virt-pci.c
@@ -181,15 +181,15 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,
/* buf->data is maximum size - we may only use parts of it */
struct um_pci_message_buffer *buf;
u8 *data;
- unsigned long ret = ~0ULL;
+ unsigned long ret = ULONG_MAX;
if (!dev)
- return ~0ULL;
+ return ULONG_MAX;
buf = get_cpu_var(um_pci_msg_bufs);
data = buf->data;
- memset(data, 0xff, sizeof(data));
+ memset(buf->data, 0xff, sizeof(buf->data));
switch (size) {
case 1:
@@ -304,7 +304,7 @@ static unsigned long um_pci_bar_read(void *priv, unsigned int offset,
/* buf->data is maximum size - we may only use parts of it */
struct um_pci_message_buffer *buf;
u8 *data;
- unsigned long ret = ~0ULL;
+ unsigned long ret = ULONG_MAX;
buf = get_cpu_var(um_pci_msg_bufs);
data = buf->data;
--
2.31.1
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] lib/logic_iomem: fix 32-bit build
2021-09-15 18:30 [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Johannes Berg
@ 2021-09-15 18:30 ` Johannes Berg
2021-09-15 18:30 ` [PATCH v2 3/3] lib/logic_iomem: fix operation on 32-bit Johannes Berg
2021-09-15 18:42 ` [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Geert Uytterhoeven
2 siblings, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2021-09-15 18:30 UTC (permalink / raw)
To: linux-um; +Cc: Johannes Berg, Al Viro
From: Johannes Berg <johannes.berg@intel.com>
On a 32-bit build, the (unsigned long long) casts throw warnings
(or errors) due to being to a different integer size. Cast to
uintptr_t first (with the __force for sparse) and then further
to get the consistent print on 32 and 64-bit.
Fixes: ca2e334232b6 ("lib: add iomem emulation (logic_iomem)")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
lib/logic_iomem.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/logic_iomem.c b/lib/logic_iomem.c
index 9bdfde0c0f86..54fa601f3300 100644
--- a/lib/logic_iomem.c
+++ b/lib/logic_iomem.c
@@ -79,7 +79,7 @@ static void __iomem *real_ioremap(phys_addr_t offset, size_t size)
static void real_iounmap(void __iomem *addr)
{
WARN(1, "invalid iounmap for addr 0x%llx\n",
- (unsigned long long __force)addr);
+ (unsigned long long)(uintptr_t __force)addr);
}
#endif /* CONFIG_LOGIC_IOMEM_FALLBACK */
@@ -173,7 +173,7 @@ EXPORT_SYMBOL(iounmap);
static u##sz real_raw_read ## op(const volatile void __iomem *addr) \
{ \
WARN(1, "Invalid read" #op " at address %llx\n", \
- (unsigned long long __force)addr); \
+ (unsigned long long)(uintptr_t __force)addr); \
return (u ## sz)~0ULL; \
} \
\
@@ -181,7 +181,8 @@ static void real_raw_write ## op(u ## sz val, \
volatile void __iomem *addr) \
{ \
WARN(1, "Invalid writeq" #op " of 0x%llx at address %llx\n", \
- (unsigned long long)val, (unsigned long long __force)addr);\
+ (unsigned long long)val, \
+ (unsigned long long)(uintptr_t __force)addr);\
} \
MAKE_FALLBACK(b, 8);
@@ -194,14 +195,14 @@ MAKE_FALLBACK(q, 64);
static void real_memset_io(volatile void __iomem *addr, int value, size_t size)
{
WARN(1, "Invalid memset_io at address 0x%llx\n",
- (unsigned long long __force)addr);
+ (unsigned long long)(uintptr_t __force)addr);
}
static void real_memcpy_fromio(void *buffer, const volatile void __iomem *addr,
size_t size)
{
WARN(1, "Invalid memcpy_fromio at address 0x%llx\n",
- (unsigned long long __force)addr);
+ (unsigned long long)(uintptr_t __force)addr);
memset(buffer, 0xff, size);
}
@@ -210,7 +211,7 @@ static void real_memcpy_toio(volatile void __iomem *addr, const void *buffer,
size_t size)
{
WARN(1, "Invalid memcpy_toio at address 0x%llx\n",
- (unsigned long long __force)addr);
+ (unsigned long long)(uintptr_t __force)addr);
}
#endif /* CONFIG_LOGIC_IOMEM_FALLBACK */
--
2.31.1
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] lib/logic_iomem: fix operation on 32-bit
2021-09-15 18:30 [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Johannes Berg
2021-09-15 18:30 ` [PATCH v2 2/3] lib/logic_iomem: fix 32-bit build Johannes Berg
@ 2021-09-15 18:30 ` Johannes Berg
2021-09-15 18:42 ` [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Geert Uytterhoeven
2 siblings, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2021-09-15 18:30 UTC (permalink / raw)
To: linux-um; +Cc: Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
On 32-bit, the first entry might be at 0/NULL, but that's
strange and leads to issues, e.g. where we check "if (ret)".
Use a IOREMAP_BIAS/IOREMAP_MASK of 0x80000000UL to avoid
this. This then requires reducing the number of areas (via
MAX_AREAS), but we still have 128 areas, which is enough.
Fixes: ca2e334232b6 ("lib: add iomem emulation (logic_iomem)")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
lib/logic_iomem.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/logic_iomem.c b/lib/logic_iomem.c
index 54fa601f3300..549b22d4bcde 100644
--- a/lib/logic_iomem.c
+++ b/lib/logic_iomem.c
@@ -21,15 +21,15 @@ struct logic_iomem_area {
#define AREA_SHIFT 24
#define MAX_AREA_SIZE (1 << AREA_SHIFT)
-#define MAX_AREAS ((1ULL<<32) / MAX_AREA_SIZE)
+#define MAX_AREAS ((1U << 31) / MAX_AREA_SIZE)
#define AREA_BITS ((MAX_AREAS - 1) << AREA_SHIFT)
#define AREA_MASK (MAX_AREA_SIZE - 1)
#ifdef CONFIG_64BIT
#define IOREMAP_BIAS 0xDEAD000000000000UL
#define IOREMAP_MASK 0xFFFFFFFF00000000UL
#else
-#define IOREMAP_BIAS 0
-#define IOREMAP_MASK 0
+#define IOREMAP_BIAS 0x80000000UL
+#define IOREMAP_MASK 0x80000000UL
#endif
static DEFINE_MUTEX(regions_mtx);
--
2.31.1
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/3] um: virt-pci: fix 32-bit compile
2021-09-15 18:30 [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Johannes Berg
2021-09-15 18:30 ` [PATCH v2 2/3] lib/logic_iomem: fix 32-bit build Johannes Berg
2021-09-15 18:30 ` [PATCH v2 3/3] lib/logic_iomem: fix operation on 32-bit Johannes Berg
@ 2021-09-15 18:42 ` Geert Uytterhoeven
2021-09-15 19:06 ` Johannes Berg
2 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2021-09-15 18:42 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-um, Johannes Berg, Al Viro
Hi Johannes,
On Wed, Sep 15, 2021 at 8:30 PM Johannes Berg <johannes@sipsolutions.net> wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> There were a few 32-bit compile warnings that of course
> turned into errors with -Werror, fix the 32-bit build.
>
> Fixes: 68f5d3f3b654 ("um: add PCI over virtio emulation driver")
> Reported-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Thanks for your patch!
> --- a/arch/um/drivers/virt-pci.c
> +++ b/arch/um/drivers/virt-pci.c
> @@ -181,15 +181,15 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,
> /* buf->data is maximum size - we may only use parts of it */
> struct um_pci_message_buffer *buf;
> u8 *data;
> - unsigned long ret = ~0ULL;
> + unsigned long ret = ULONG_MAX;
Why not just drop the last "L"? ;-)
>
> if (!dev)
> - return ~0ULL;
> + return ULONG_MAX;
>
> buf = get_cpu_var(um_pci_msg_bufs);
> data = buf->data;
>
> - memset(data, 0xff, sizeof(data));
> + memset(buf->data, 0xff, sizeof(buf->data));
The first change is not needed.
The second change is a genuine bug fix, also on 64-bit, which should be
submitted separately, and backported to stable.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/3] um: virt-pci: fix 32-bit compile
2021-09-15 18:42 ` [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Geert Uytterhoeven
@ 2021-09-15 19:06 ` Johannes Berg
0 siblings, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2021-09-15 19:06 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linux-um, Al Viro
On Wed, 2021-09-15 at 20:42 +0200, Geert Uytterhoeven wrote:
>
> > - unsigned long ret = ~0ULL;
> > + unsigned long ret = ULONG_MAX;
>
> Why not just drop the last "L"? ;-)
>
> >
> > if (!dev)
> > - return ~0ULL;
> > + return ULONG_MAX;
>
> The first change is not needed.
True, but it seemed inconsistent without that.
> > - memset(data, 0xff, sizeof(data));
> > + memset(buf->data, 0xff, sizeof(buf->data));
> The second change is a genuine bug fix, also on 64-bit, which should be
> submitted separately, and backported to stable.
It's kind of a bug, I agree. However:
On 64-bit platforms, the pointer size is 8 bytes, and thus all the data
is memset to 0xff as needed.
On 32-bit platforms, we cannot do 64-bit reads (there's no ioread64 on
32-bit), and thus we can only ever need four 0xff bytes (for a failing
32-bit read), matching the pointer size, so it ends up being correct as
well.
johannes
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-15 19:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 18:30 [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Johannes Berg
2021-09-15 18:30 ` [PATCH v2 2/3] lib/logic_iomem: fix 32-bit build Johannes Berg
2021-09-15 18:30 ` [PATCH v2 3/3] lib/logic_iomem: fix operation on 32-bit Johannes Berg
2021-09-15 18:42 ` [PATCH v2 1/3] um: virt-pci: fix 32-bit compile Geert Uytterhoeven
2021-09-15 19:06 ` Johannes Berg
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.