* [PATCH] um: make personality(PER_LINUX32) work on x86_64
@ 2024-08-13 23:47 Maciej Żenczykowski
2024-08-19 12:23 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Maciej Żenczykowski @ 2024-08-13 23:47 UTC (permalink / raw)
To: Maciej Żenczykowski
Cc: Linux Kernel Mailing List, Maciej Żenczykowski,
Richard Weinberger, Anton Ivanov, Johannes Berg, linux-um
Without this patch:
#!/usr/bin/python3
import ctypes
import os
personality = ctypes.CDLL(None).personality
personality.restype = ctypes.c_int
personality.argtypes = [ctypes.c_ulong]
PER_LINUX32=8
personality(PER_LINUX32)
print(os.uname().machine)
returns:
x86_64
instead of the desired:
i686
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-um@lists.infradead.org
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
arch/um/include/asm/Kbuild | 1 -
arch/um/include/asm/compat.h | 12 ++++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 arch/um/include/asm/compat.h
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index b2d834a29f3a..0b961dd089ab 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
generic-y += bpf_perf_event.h
generic-y += bug.h
-generic-y += compat.h
generic-y += current.h
generic-y += device.h
generic-y += dma-mapping.h
diff --git a/arch/um/include/asm/compat.h b/arch/um/include/asm/compat.h
new file mode 100644
index 000000000000..110319031dcf
--- /dev/null
+++ b/arch/um/include/asm/compat.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __UM_COMPAT_H
+#define __UM_COMPAT_H
+
+#include <asm-generic/compat.h>
+
+#if defined(CONFIG_UML_X86) && defined(CONFIG_64BIT)
+/* From arch/x86/include/asm/compat.h */
+#define COMPAT_UTS_MACHINE "i686\0\0"
+#endif
+
+#endif
--
2.46.0.76.ge559c4bf1a-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] um: make personality(PER_LINUX32) work on x86_64
2024-08-13 23:47 [PATCH] um: make personality(PER_LINUX32) work on x86_64 Maciej Żenczykowski
@ 2024-08-19 12:23 ` Johannes Berg
2024-08-19 18:46 ` Maciej Żenczykowski
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2024-08-19 12:23 UTC (permalink / raw)
To: Maciej Żenczykowski, Maciej Żenczykowski
Cc: Linux Kernel Mailing List, Richard Weinberger, Anton Ivanov,
linux-um
On Tue, 2024-08-13 at 16:47 -0700, Maciej Żenczykowski wrote:
> Without this patch:
> #!/usr/bin/python3
> import ctypes
> import os
> personality = ctypes.CDLL(None).personality
> personality.restype = ctypes.c_int
> personality.argtypes = [ctypes.c_ulong]
> PER_LINUX32=8
> personality(PER_LINUX32)
> print(os.uname().machine)
> returns:
> x86_64
> instead of the desired:
> i686
>
But ... why should it work? UML has no 32-bit compat support anyway.
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] um: make personality(PER_LINUX32) work on x86_64
2024-08-19 12:23 ` Johannes Berg
@ 2024-08-19 18:46 ` Maciej Żenczykowski
2024-08-28 12:58 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Maciej Żenczykowski @ 2024-08-19 18:46 UTC (permalink / raw)
To: Johannes Berg
Cc: Linux Kernel Mailing List, Richard Weinberger, Anton Ivanov,
linux-um
On Mon, Aug 19, 2024 at 5:23 AM Johannes Berg <johannes@sipsolutions.net> wrote:
>
> On Tue, 2024-08-13 at 16:47 -0700, Maciej Żenczykowski wrote:
> > Without this patch:
> > #!/usr/bin/python3
> > import ctypes
> > import os
> > personality = ctypes.CDLL(None).personality
> > personality.restype = ctypes.c_int
> > personality.argtypes = [ctypes.c_ulong]
> > PER_LINUX32=8
> > personality(PER_LINUX32)
> > print(os.uname().machine)
> > returns:
> > x86_64
> > instead of the desired:
> > i686
> >
>
> But ... why should it work? UML has no 32-bit compat support anyway.
Well, that's certainly a fair point.
On 'native' x86_64 this works even for 64-bit processes though.
I wonder if that, in itself, is a feature or a bug...
In my case I was writing some debug code (to print the environment
some test code is running in, since I think it was failing due to
running 32-bit code in PER_LINUX32 on 64-bit arm) and testing (the
test code) on x86_64 UML. I was surprised to discover the difference
in UML vs my host desktop.
> johannes
--
Maciej Żenczykowski, Kernel Networking Developer @ Google
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] um: make personality(PER_LINUX32) work on x86_64
2024-08-19 18:46 ` Maciej Żenczykowski
@ 2024-08-28 12:58 ` Johannes Berg
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2024-08-28 12:58 UTC (permalink / raw)
To: Maciej Żenczykowski
Cc: Linux Kernel Mailing List, Richard Weinberger, Anton Ivanov,
linux-um, x86
On Mon, 2024-08-19 at 11:46 -0700, Maciej Żenczykowski wrote:
> On Mon, Aug 19, 2024 at 5:23 AM Johannes Berg <johannes@sipsolutions.net> wrote:
> >
> > On Tue, 2024-08-13 at 16:47 -0700, Maciej Żenczykowski wrote:
> > > Without this patch:
> > > #!/usr/bin/python3
> > > import ctypes
> > > import os
> > > personality = ctypes.CDLL(None).personality
> > > personality.restype = ctypes.c_int
> > > personality.argtypes = [ctypes.c_ulong]
> > > PER_LINUX32=8
> > > personality(PER_LINUX32)
> > > print(os.uname().machine)
> > > returns:
> > > x86_64
> > > instead of the desired:
> > > i686
> > >
> >
> > But ... why should it work? UML has no 32-bit compat support anyway.
>
> Well, that's certainly a fair point.
> On 'native' x86_64 this works even for 64-bit processes though.
> I wonder if that, in itself, is a feature or a bug...
>
> In my case I was writing some debug code (to print the environment
> some test code is running in, since I think it was failing due to
> running 32-bit code in PER_LINUX32 on 64-bit arm) and testing (the
> test code) on x86_64 UML. I was surprised to discover the difference
> in UML vs my host desktop.
>
Alright, I have no idea. This doesn't really seem to do anything else,
so I'm not sure what the point is... It _was_ introduced for compat
though, but obviously the binary doesn't suddenly change to a 32-bit
binary when you do this :)
Maybe the x86 maintainers have any other comments?
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-28 13:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 23:47 [PATCH] um: make personality(PER_LINUX32) work on x86_64 Maciej Żenczykowski
2024-08-19 12:23 ` Johannes Berg
2024-08-19 18:46 ` Maciej Żenczykowski
2024-08-28 12:58 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox