summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/qemu
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu')
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-Add-enable-disable-udev.patch29
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-linux-user-x86_64-Handle-the-vsyscall-page-in-open_s.patch56
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-qemu-Add-addition-environment-space-to-boot-loader-q.patch (renamed from meta/recipes-devtools/qemu/qemu/0003-qemu-Add-addition-environment-space-to-boot-loader-q.patch)16
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-qemu-Add-missing-wacom-HID-descriptor.patch141
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-tests-meson.build-use-relative-path-to-refer-to-file.patch34
-rw-r--r--meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch355
-rw-r--r--meta/recipes-devtools/qemu/qemu/0002-linux-user-loongarch64-Remove-TARGET_FORCE_SHMLBA.patch43
-rw-r--r--meta/recipes-devtools/qemu/qemu/0003-apic-fixup-fallthrough-to-PIC.patch (renamed from meta/recipes-devtools/qemu/qemu/0007-apic-fixup-fallthrough-to-PIC.patch)12
-rw-r--r--meta/recipes-devtools/qemu/qemu/0003-linux-user-Add-strace-for-shmat.patch71
-rw-r--r--meta/recipes-devtools/qemu/qemu/0004-configure-Add-pkg-config-handling-for-libgcrypt.patch29
-rw-r--r--meta/recipes-devtools/qemu/qemu/0004-linux-user-Rewrite-target_shmat.patch236
-rw-r--r--meta/recipes-devtools/qemu/qemu/0004-qemu-disable-Valgrind.patch34
-rw-r--r--meta/recipes-devtools/qemu/qemu/0005-qemu-Do-not-include-file-if-not-exists.patch (renamed from meta/recipes-devtools/qemu/qemu/0001-qemu-Do-not-include-file-if-not-exists.patch)15
-rw-r--r--meta/recipes-devtools/qemu/qemu/0005-tests-tcg-Check-that-shmat-does-not-break-proc-self-.patch85
-rw-r--r--meta/recipes-devtools/qemu/qemu/0006-chardev-connect-socket-to-a-spawned-command.patch243
-rw-r--r--meta/recipes-devtools/qemu/qemu/0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch (renamed from meta/recipes-devtools/qemu/qemu/mmap2.patch)35
-rw-r--r--meta/recipes-devtools/qemu/qemu/0007-qemu-Determinism-fixes.patch31
-rw-r--r--meta/recipes-devtools/qemu/qemu/0008-tests-meson.build-use-relative-path-to-refer-to-file.patch41
-rw-r--r--meta/recipes-devtools/qemu/qemu/0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch46
-rw-r--r--meta/recipes-devtools/qemu/qemu/0010-configure-Add-pkg-config-handling-for-libgcrypt.patch84
-rw-r--r--meta/recipes-devtools/qemu/qemu/0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch40
-rw-r--r--meta/recipes-devtools/qemu/qemu/0011-linux-user-workaround-for-missing-MAP_FIXED_NOREPLAC.patch282
-rw-r--r--meta/recipes-devtools/qemu/qemu/0012-linux-user-workaround-for-missing-MAP_SHARED_VALIDAT.patch51
-rw-r--r--meta/recipes-devtools/qemu/qemu/4a8579ad8629b57a43daa62e46cc7af6e1078116.patch60
-rw-r--r--meta/recipes-devtools/qemu/qemu/CVE-2023-6683.patch91
-rw-r--r--meta/recipes-devtools/qemu/qemu/cross.patch30
-rw-r--r--meta/recipes-devtools/qemu/qemu/determinism.patch41
-rw-r--r--meta/recipes-devtools/qemu/qemu/fixedmeson.patch20
-rw-r--r--meta/recipes-devtools/qemu/qemu/mingwfix.patch21
-rw-r--r--meta/recipes-devtools/qemu/qemu/mmap.patch29
-rw-r--r--meta/recipes-devtools/qemu/qemu/no-pip.patch45
-rw-r--r--meta/recipes-devtools/qemu/qemu/qemu-guest-agent.init75
-rw-r--r--meta/recipes-devtools/qemu/qemu/qemu-guest-agent.udev2
33 files changed, 1703 insertions, 720 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0001-Add-enable-disable-udev.patch b/meta/recipes-devtools/qemu/qemu/0001-Add-enable-disable-udev.patch
deleted file mode 100644
index c99adee8a9..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0001-Add-enable-disable-udev.patch
+++ /dev/null
@@ -1,29 +0,0 @@
1From b921e5204030845dc7c9d16d5f66d965e8d05367 Mon Sep 17 00:00:00 2001
2From: Jeremy Puhlman <jpuhlman@mvista.com>
3Date: Thu, 19 Mar 2020 11:54:26 -0700
4Subject: [PATCH] Add enable/disable libudev
5
6Upstream-Status: Pending
7Signed-off-by: Jeremy Puhlman <jpuhlman@mvista.com>
8
9[update patch context]
10Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
11---
12 configure | 4 ++++
13 1 file changed, 4 insertions(+)
14
15Index: qemu-5.2.0/configure
16===================================================================
17--- qemu-5.2.0.orig/configure
18+++ qemu-5.2.0/configure
19@@ -1525,6 +1525,10 @@ for opt do
20 ;;
21 --disable-libdaxctl) libdaxctl=no
22 ;;
23+ --enable-libudev) libudev="yes"
24+ ;;
25+ --disable-libudev) libudev="no"
26+ ;;
27 *)
28 echo "ERROR: unknown option $opt"
29 echo "Try '$0 --help' for more information"
diff --git a/meta/recipes-devtools/qemu/qemu/0001-linux-user-x86_64-Handle-the-vsyscall-page-in-open_s.patch b/meta/recipes-devtools/qemu/qemu/0001-linux-user-x86_64-Handle-the-vsyscall-page-in-open_s.patch
new file mode 100644
index 0000000000..2eaebe883c
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0001-linux-user-x86_64-Handle-the-vsyscall-page-in-open_s.patch
@@ -0,0 +1,56 @@
1From 4517e2046610722879761bcdb60edbb2b929c848 Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Wed, 28 Feb 2024 10:25:14 -1000
4Subject: [PATCH 1/5] linux-user/x86_64: Handle the vsyscall page in
5 open_self_maps_{2,4}
6
7This is the only case in which we expect to have no host memory backing
8for a guest memory page, because in general linux user processes cannot
9map any pages in the top half of the 64-bit address space.
10
11Upstream-Status: Submitted [https://www.mail-archive.com/qemu-devel@nongnu.org/msg1026793.html]
12
13Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2170
14Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
15Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
16---
17 linux-user/syscall.c | 16 ++++++++++++++++
18 1 file changed, 16 insertions(+)
19
20diff --git a/linux-user/syscall.c b/linux-user/syscall.c
21index a114f29a8..8307a8a61 100644
22--- a/linux-user/syscall.c
23+++ b/linux-user/syscall.c
24@@ -7922,6 +7922,10 @@ static void open_self_maps_4(const struct open_self_maps_data *d,
25 path = "[heap]";
26 } else if (start == info->vdso) {
27 path = "[vdso]";
28+#ifdef TARGET_X86_64
29+ } else if (start == TARGET_VSYSCALL_PAGE) {
30+ path = "[vsyscall]";
31+#endif
32 }
33
34 /* Except null device (MAP_ANON), adjust offset for this fragment. */
35@@ -8010,6 +8014,18 @@ static int open_self_maps_2(void *opaque, target_ulong guest_start,
36 uintptr_t host_start = (uintptr_t)g2h_untagged(guest_start);
37 uintptr_t host_last = (uintptr_t)g2h_untagged(guest_end - 1);
38
39+#ifdef TARGET_X86_64
40+ /*
41+ * Because of the extremely high position of the page within the guest
42+ * virtual address space, this is not backed by host memory at all.
43+ * Therefore the loop below would fail. This is the only instance
44+ * of not having host backing memory.
45+ */
46+ if (guest_start == TARGET_VSYSCALL_PAGE) {
47+ return open_self_maps_3(opaque, guest_start, guest_end, flags);
48+ }
49+#endif
50+
51 while (1) {
52 IntervalTreeNode *n =
53 interval_tree_iter_first(d->host_maps, host_start, host_start);
54--
552.34.1
56
diff --git a/meta/recipes-devtools/qemu/qemu/0003-qemu-Add-addition-environment-space-to-boot-loader-q.patch b/meta/recipes-devtools/qemu/qemu/0001-qemu-Add-addition-environment-space-to-boot-loader-q.patch
index fd54f96b03..c65508017d 100644
--- a/meta/recipes-devtools/qemu/qemu/0003-qemu-Add-addition-environment-space-to-boot-loader-q.patch
+++ b/meta/recipes-devtools/qemu/qemu/0001-qemu-Add-addition-environment-space-to-boot-loader-q.patch
@@ -1,7 +1,7 @@
1From ce1eceab2350d27960ec254650717085f6a11c9a Mon Sep 17 00:00:00 2001 1From de64af82950a6908f9407dfc92b83c17e2af3eab Mon Sep 17 00:00:00 2001
2From: Jason Wessel <jason.wessel@windriver.com> 2From: Jason Wessel <jason.wessel@windriver.com>
3Date: Fri, 28 Mar 2014 17:42:43 +0800 3Date: Fri, 28 Mar 2014 17:42:43 +0800
4Subject: [PATCH] qemu: Add addition environment space to boot loader 4Subject: [PATCH 01/12] qemu: Add addition environment space to boot loader
5 qemu-system-mips 5 qemu-system-mips
6 6
7Upstream-Status: Inappropriate - OE uses deep paths 7Upstream-Status: Inappropriate - OE uses deep paths
@@ -18,13 +18,13 @@ Signed-off-by: Roy Li <rongqing.li@windriver.com>
18 hw/mips/malta.c | 2 +- 18 hw/mips/malta.c | 2 +-
19 1 file changed, 1 insertion(+), 1 deletion(-) 19 1 file changed, 1 insertion(+), 1 deletion(-)
20 20
21Index: qemu-5.2.0/hw/mips/malta.c 21Index: qemu-8.0.0/hw/mips/malta.c
22=================================================================== 22===================================================================
23--- qemu-5.2.0.orig/hw/mips/malta.c 23--- qemu-8.0.0.orig/hw/mips/malta.c
24+++ qemu-5.2.0/hw/mips/malta.c 24+++ qemu-8.0.0/hw/mips/malta.c
25@@ -62,7 +62,7 @@ 25@@ -64,7 +64,7 @@
26 26 #define ENVP_PADDR 0x2000
27 #define ENVP_ADDR 0x80002000l 27 #define ENVP_VADDR cpu_mips_phys_to_kseg0(NULL, ENVP_PADDR)
28 #define ENVP_NB_ENTRIES 16 28 #define ENVP_NB_ENTRIES 16
29-#define ENVP_ENTRY_SIZE 256 29-#define ENVP_ENTRY_SIZE 256
30+#define ENVP_ENTRY_SIZE 1024 30+#define ENVP_ENTRY_SIZE 1024
diff --git a/meta/recipes-devtools/qemu/qemu/0001-qemu-Add-missing-wacom-HID-descriptor.patch b/meta/recipes-devtools/qemu/qemu/0001-qemu-Add-missing-wacom-HID-descriptor.patch
deleted file mode 100644
index 8ce12bdb43..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0001-qemu-Add-missing-wacom-HID-descriptor.patch
+++ /dev/null
@@ -1,141 +0,0 @@
1From 883feb43129dc39b491e492c7ccfe89aefe53c44 Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Thu, 27 Nov 2014 14:04:29 +0000
4Subject: [PATCH] qemu: Add missing wacom HID descriptor
5
6The USB wacom device is missing a HID descriptor which causes it
7to fail to operate with recent kernels (e.g. 3.17).
8
9This patch adds a HID desriptor to the device, based upon one from
10real wcom device.
11
12Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
13
14Upstream-Status: Submitted
152014/11/27
16
17[update patch context]
18Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
19---
20 hw/usb/dev-wacom.c | 94 +++++++++++++++++++++++++++++++++++++++++++++-
21 1 file changed, 93 insertions(+), 1 deletion(-)
22
23Index: qemu-5.2.0/hw/usb/dev-wacom.c
24===================================================================
25--- qemu-5.2.0.orig/hw/usb/dev-wacom.c
26+++ qemu-5.2.0/hw/usb/dev-wacom.c
27@@ -69,6 +69,89 @@ static const USBDescStrings desc_strings
28 [STR_SERIALNUMBER] = "1",
29 };
30
31+static const uint8_t qemu_tablet_hid_report_descriptor[] = {
32+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
33+ 0x09, 0x02, /* Usage (Mouse) */
34+ 0xa1, 0x01, /* Collection (Application) */
35+ 0x85, 0x01, /* Report ID (1) */
36+ 0x09, 0x01, /* Usage (Pointer) */
37+ 0xa1, 0x00, /* Collection (Physical) */
38+ 0x05, 0x09, /* Usage Page (Button) */
39+ 0x19, 0x01, /* Usage Minimum (1) */
40+ 0x29, 0x05, /* Usage Maximum (5) */
41+ 0x15, 0x00, /* Logical Minimum (0) */
42+ 0x25, 0x01, /* Logical Maximum (1) */
43+ 0x95, 0x05, /* Report Count (5) */
44+ 0x75, 0x01, /* Report Size (1) */
45+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
46+ 0x95, 0x01, /* Report Count (1) */
47+ 0x75, 0x03, /* Report Size (3) */
48+ 0x81, 0x01, /* Input (Constant) */
49+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
50+ 0x09, 0x30, /* Usage (X) */
51+ 0x09, 0x31, /* Usage (Y) */
52+ 0x15, 0x81, /* Logical Minimum (-127) */
53+ 0x25, 0x7f, /* Logical Maximum (127) */
54+ 0x75, 0x08, /* Report Size (8) */
55+ 0x95, 0x02, /* Report Count (2) */
56+ 0x81, 0x06, /* Input (Data, Variable, Relative) */
57+ 0xc0, /* End Collection */
58+ 0xc0, /* End Collection */
59+ 0x05, 0x0d, /* Usage Page (Digitizer) */
60+ 0x09, 0x01, /* Usage (Digitizer) */
61+ 0xa1, 0x01, /* Collection (Application) */
62+ 0x85, 0x02, /* Report ID (2) */
63+ 0xa1, 0x00, /* Collection (Physical) */
64+ 0x06, 0x00, 0xff, /* Usage Page (Vendor 0xff00) */
65+ 0x09, 0x01, /* Usage (Digitizer) */
66+ 0x15, 0x00, /* Logical Minimum (0) */
67+ 0x26, 0xff, 0x00, /* Logical Maximum (255) */
68+ 0x75, 0x08, /* Report Size (8) */
69+ 0x95, 0x08, /* Report Count (8) */
70+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
71+ 0xc0, /* End Collection */
72+ 0x09, 0x01, /* Usage (Digitizer) */
73+ 0x85, 0x02, /* Report ID (2) */
74+ 0x95, 0x01, /* Report Count (1) */
75+ 0xb1, 0x02, /* FEATURE (2) */
76+ 0xc0, /* End Collection */
77+ 0x06, 0x00, 0xff, /* Usage Page (Vendor 0xff00) */
78+ 0x09, 0x01, /* Usage (Digitizer) */
79+ 0xa1, 0x01, /* Collection (Application) */
80+ 0x85, 0x02, /* Report ID (2) */
81+ 0x05, 0x0d, /* Usage Page (Digitizer) */
82+ 0x09, 0x22, /* Usage (Finger) */
83+ 0xa1, 0x00, /* Collection (Physical) */
84+ 0x06, 0x00, 0xff, /* Usage Page (Vendor 0xff00) */
85+ 0x09, 0x01, /* Usage (Digitizer) */
86+ 0x15, 0x00, /* Logical Minimum (0) */
87+ 0x26, 0xff, 0x00, /* Logical Maximum */
88+ 0x75, 0x08, /* Report Size (8) */
89+ 0x95, 0x02, /* Report Count (2) */
90+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
91+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
92+ 0x09, 0x30, /* Usage (X) */
93+ 0x35, 0x00, /* Physical Minimum */
94+ 0x46, 0xe0, 0x2e, /* Physical Maximum */
95+ 0x26, 0xe0, 0x01, /* Logical Maximum */
96+ 0x75, 0x10, /* Report Size (16) */
97+ 0x95, 0x01, /* Report Count (1) */
98+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
99+ 0x09, 0x31, /* Usage (Y) */
100+ 0x46, 0x40, 0x1f, /* Physical Maximum */
101+ 0x26, 0x40, 0x01, /* Logical Maximum */
102+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
103+ 0x06, 0x00, 0xff, /* Usage Page (Vendor 0xff00) */
104+ 0x09, 0x01, /* Usage (Digitizer) */
105+ 0x26, 0xff, 0x00, /* Logical Maximum */
106+ 0x75, 0x08, /* Report Size (8) */
107+ 0x95, 0x0d, /* Report Count (13) */
108+ 0x81, 0x02, /* Input (Data, Variable, Absolute) */
109+ 0xc0, /* End Collection */
110+ 0xc0, /* End Collection */
111+};
112+
113+
114 static const USBDescIface desc_iface_wacom = {
115 .bInterfaceNumber = 0,
116 .bNumEndpoints = 1,
117@@ -86,7 +169,7 @@ static const USBDescIface desc_iface_wac
118 0x00, /* u8 country_code */
119 0x01, /* u8 num_descriptors */
120 USB_DT_REPORT, /* u8 type: Report */
121- 0x6e, 0, /* u16 len */
122+ sizeof(qemu_tablet_hid_report_descriptor), 0, /* u16 len */
123 },
124 },
125 },
126@@ -266,6 +349,15 @@ static void usb_wacom_handle_control(USB
127 }
128
129 switch (request) {
130+ case InterfaceRequest | USB_REQ_GET_DESCRIPTOR:
131+ switch (value >> 8) {
132+ case 0x22:
133+ memcpy(data, qemu_tablet_hid_report_descriptor,
134+ sizeof(qemu_tablet_hid_report_descriptor));
135+ p->actual_length = sizeof(qemu_tablet_hid_report_descriptor);
136+ break;
137+ }
138+ break;
139 case WACOM_SET_REPORT:
140 if (s->mouse_grabbed) {
141 qemu_remove_mouse_event_handler(s->eh_entry);
diff --git a/meta/recipes-devtools/qemu/qemu/0001-tests-meson.build-use-relative-path-to-refer-to-file.patch b/meta/recipes-devtools/qemu/qemu/0001-tests-meson.build-use-relative-path-to-refer-to-file.patch
deleted file mode 100644
index 5cb5757c37..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0001-tests-meson.build-use-relative-path-to-refer-to-file.patch
+++ /dev/null
@@ -1,34 +0,0 @@
1From a4bdc0416134477e4eae386db04b1de7491163bb Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Thu, 14 Jan 2021 06:33:04 +0000
4Subject: [PATCH] tests/meson.build: use relative path to refer to files
5
6Fix error like:
7Fatal error: can't create tests/ptimer-test.p/..._qemu-5.2.0_hw_core_ptimer.c.o: File name too long
8
9when build path is too long, use meson.source_root() will make this
10filename too long. Fixed by using relative path to refer to files
11
12Upstream-Status: Submitted [send to qemu-devel]
13
14Signed-off-by: Changqing Li <changqing.li@windriver.com>
15---
16 tests/meson.build | 2 +-
17 1 files changed, 1 insertions(+), 1 deletion(-)
18
19diff --git a/tests/meson.build b/tests/meson.build
20index afeb6be..54684b5 100644
21--- a/tests/meson.build
22+++ b/tests/meson.build
23@@ -113,7 +113,7 @@ tests = {
24 'test-keyval': [testqapi],
25 'test-logging': [],
26 'test-uuid': [],
27- 'ptimer-test': ['ptimer-test-stubs.c', meson.source_root() / 'hw/core/ptimer.c'],
28+ 'ptimer-test': ['ptimer-test-stubs.c', '../hw/core/ptimer.c'],
29 'test-qapi-util': [],
30 }
31
32--
332.29.2
34
diff --git a/meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch b/meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch
new file mode 100644
index 0000000000..ceae67be64
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch
@@ -0,0 +1,355 @@
1From 71f14902256e3c3529710b713e1ea43100bf4c40 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 17 Dec 2022 08:37:46 -0800
4Subject: [PATCH 2/2] linux-user: Replace use of lfs64 related functions and
5 macros
6
7Builds defines -D_FILE_OFFSET_BITS=64 which makes the original functions
8anf macros behave same as their 64 suffixed counterparts. This also
9helps in compiling with latest musl C library, where these macros and
10functions are no more available under _GNU_SOURCE feature macro
11
12Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg02841.html]
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14Cc: Laurent Vivier <laurent@vivier.eu>
15---
16 linux-user/syscall.c | 153 +++++++++++--------------------------------
17 1 file changed, 39 insertions(+), 114 deletions(-)
18
19Index: qemu-8.0.0/linux-user/syscall.c
20===================================================================
21--- qemu-8.0.0.orig/linux-user/syscall.c
22+++ qemu-8.0.0/linux-user/syscall.c
23@@ -761,8 +761,8 @@ safe_syscall6(ssize_t, copy_file_range,
24 */
25 #define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__)
26 /* Similarly for fcntl. Note that callers must always:
27- * pass the F_GETLK64 etc constants rather than the unsuffixed F_GETLK
28- * use the flock64 struct rather than unsuffixed flock
29+ * pass the F_GETLK etc constants rather than the unsuffixed F_GETLK
30+ * use the flock struct rather than unsuffixed flock
31 * This will then work and use a 64-bit offset for both 32-bit and 64-bit hosts.
32 */
33 #ifdef __NR_fcntl64
34@@ -6813,13 +6813,13 @@ static int target_to_host_fcntl_cmd(int
35 ret = cmd;
36 break;
37 case TARGET_F_GETLK:
38- ret = F_GETLK64;
39+ ret = F_GETLK;
40 break;
41 case TARGET_F_SETLK:
42- ret = F_SETLK64;
43+ ret = F_SETLK;
44 break;
45 case TARGET_F_SETLKW:
46- ret = F_SETLKW64;
47+ ret = F_SETLKW;
48 break;
49 case TARGET_F_GETOWN:
50 ret = F_GETOWN;
51@@ -6833,17 +6833,6 @@ static int target_to_host_fcntl_cmd(int
52 case TARGET_F_SETSIG:
53 ret = F_SETSIG;
54 break;
55-#if TARGET_ABI_BITS == 32
56- case TARGET_F_GETLK64:
57- ret = F_GETLK64;
58- break;
59- case TARGET_F_SETLK64:
60- ret = F_SETLK64;
61- break;
62- case TARGET_F_SETLKW64:
63- ret = F_SETLKW64;
64- break;
65-#endif
66 case TARGET_F_SETLEASE:
67 ret = F_SETLEASE;
68 break;
69@@ -6895,8 +6884,8 @@ static int target_to_host_fcntl_cmd(int
70 * them to 5, 6 and 7 before making the syscall(). Since we make the
71 * syscall directly, adjust to what is supported by the kernel.
72 */
73- if (ret >= F_GETLK64 && ret <= F_SETLKW64) {
74- ret -= F_GETLK64 - 5;
75+ if (ret >= F_GETLK && ret <= F_SETLKW) {
76+ ret -= F_GETLK - 5;
77 }
78 #endif
79
80@@ -6929,55 +6918,11 @@ static int host_to_target_flock(int type
81 return type;
82 }
83
84-static inline abi_long copy_from_user_flock(struct flock64 *fl,
85- abi_ulong target_flock_addr)
86-{
87- struct target_flock *target_fl;
88- int l_type;
89-
90- if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
91- return -TARGET_EFAULT;
92- }
93-
94- __get_user(l_type, &target_fl->l_type);
95- l_type = target_to_host_flock(l_type);
96- if (l_type < 0) {
97- return l_type;
98- }
99- fl->l_type = l_type;
100- __get_user(fl->l_whence, &target_fl->l_whence);
101- __get_user(fl->l_start, &target_fl->l_start);
102- __get_user(fl->l_len, &target_fl->l_len);
103- __get_user(fl->l_pid, &target_fl->l_pid);
104- unlock_user_struct(target_fl, target_flock_addr, 0);
105- return 0;
106-}
107-
108-static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr,
109- const struct flock64 *fl)
110-{
111- struct target_flock *target_fl;
112- short l_type;
113-
114- if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
115- return -TARGET_EFAULT;
116- }
117-
118- l_type = host_to_target_flock(fl->l_type);
119- __put_user(l_type, &target_fl->l_type);
120- __put_user(fl->l_whence, &target_fl->l_whence);
121- __put_user(fl->l_start, &target_fl->l_start);
122- __put_user(fl->l_len, &target_fl->l_len);
123- __put_user(fl->l_pid, &target_fl->l_pid);
124- unlock_user_struct(target_fl, target_flock_addr, 1);
125- return 0;
126-}
127-
128-typedef abi_long from_flock64_fn(struct flock64 *fl, abi_ulong target_addr);
129-typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 *fl);
130+typedef abi_long from_flock_fn(struct flock *fl, abi_ulong target_addr);
131+typedef abi_long to_flock_fn(abi_ulong target_addr, const struct flock *fl);
132
133 #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32
134-struct target_oabi_flock64 {
135+struct target_oabi_flock {
136 abi_short l_type;
137 abi_short l_whence;
138 abi_llong l_start;
139@@ -6985,10 +6930,10 @@ struct target_oabi_flock64 {
140 abi_int l_pid;
141 } QEMU_PACKED;
142
143-static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
144+static inline abi_long copy_from_user_oabi_flock(struct flock *fl,
145 abi_ulong target_flock_addr)
146 {
147- struct target_oabi_flock64 *target_fl;
148+ struct target_oabi_flock *target_fl;
149 int l_type;
150
151 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
152@@ -7009,10 +6954,10 @@ static inline abi_long copy_from_user_oa
153 return 0;
154 }
155
156-static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr,
157- const struct flock64 *fl)
158+static inline abi_long copy_to_user_oabi_flock(abi_ulong target_flock_addr,
159+ const struct flock *fl)
160 {
161- struct target_oabi_flock64 *target_fl;
162+ struct target_oabi_flock *target_fl;
163 short l_type;
164
165 if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
166@@ -7030,10 +6975,10 @@ static inline abi_long copy_to_user_oabi
167 }
168 #endif
169
170-static inline abi_long copy_from_user_flock64(struct flock64 *fl,
171+static inline abi_long copy_from_user_flock(struct flock *fl,
172 abi_ulong target_flock_addr)
173 {
174- struct target_flock64 *target_fl;
175+ struct target_flock *target_fl;
176 int l_type;
177
178 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
179@@ -7054,10 +6999,10 @@ static inline abi_long copy_from_user_fl
180 return 0;
181 }
182
183-static inline abi_long copy_to_user_flock64(abi_ulong target_flock_addr,
184- const struct flock64 *fl)
185+static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr,
186+ const struct flock *fl)
187 {
188- struct target_flock64 *target_fl;
189+ struct target_flock *target_fl;
190 short l_type;
191
192 if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
193@@ -7076,7 +7021,7 @@ static inline abi_long copy_to_user_floc
194
195 static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
196 {
197- struct flock64 fl64;
198+ struct flock fl64;
199 #ifdef F_GETOWN_EX
200 struct f_owner_ex fox;
201 struct target_f_owner_ex *target_fox;
202@@ -7089,6 +7034,7 @@ static abi_long do_fcntl(int fd, int cmd
203
204 switch(cmd) {
205 case TARGET_F_GETLK:
206+ case TARGET_F_OFD_GETLK:
207 ret = copy_from_user_flock(&fl64, arg);
208 if (ret) {
209 return ret;
210@@ -7098,32 +7044,11 @@ static abi_long do_fcntl(int fd, int cmd
211 ret = copy_to_user_flock(arg, &fl64);
212 }
213 break;
214-
215 case TARGET_F_SETLK:
216 case TARGET_F_SETLKW:
217- ret = copy_from_user_flock(&fl64, arg);
218- if (ret) {
219- return ret;
220- }
221- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
222- break;
223-
224- case TARGET_F_GETLK64:
225- case TARGET_F_OFD_GETLK:
226- ret = copy_from_user_flock64(&fl64, arg);
227- if (ret) {
228- return ret;
229- }
230- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
231- if (ret == 0) {
232- ret = copy_to_user_flock64(arg, &fl64);
233- }
234- break;
235- case TARGET_F_SETLK64:
236- case TARGET_F_SETLKW64:
237 case TARGET_F_OFD_SETLK:
238 case TARGET_F_OFD_SETLKW:
239- ret = copy_from_user_flock64(&fl64, arg);
240+ ret = copy_from_user_flock(&fl64, arg);
241 if (ret) {
242 return ret;
243 }
244@@ -7348,7 +7273,7 @@ static inline abi_long target_truncate64
245 arg2 = arg3;
246 arg3 = arg4;
247 }
248- return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
249+ return get_errno(truncate(arg1, target_offset64(arg2, arg3)));
250 }
251 #endif
252
253@@ -7362,7 +7287,7 @@ static inline abi_long target_ftruncate6
254 arg2 = arg3;
255 arg3 = arg4;
256 }
257- return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
258+ return get_errno(ftruncate(arg1, target_offset64(arg2, arg3)));
259 }
260 #endif
261
262@@ -8598,7 +8523,7 @@ static int do_getdents(abi_long dirfd, a
263 void *tdirp;
264 int hlen, hoff, toff;
265 int hreclen, treclen;
266- off64_t prev_diroff = 0;
267+ off_t prev_diroff = 0;
268
269 hdirp = g_try_malloc(count);
270 if (!hdirp) {
271@@ -8651,7 +8576,7 @@ static int do_getdents(abi_long dirfd, a
272 * Return what we have, resetting the file pointer to the
273 * location of the first record not returned.
274 */
275- lseek64(dirfd, prev_diroff, SEEK_SET);
276+ lseek(dirfd, prev_diroff, SEEK_SET);
277 break;
278 }
279
280@@ -8685,7 +8610,7 @@ static int do_getdents64(abi_long dirfd,
281 void *tdirp;
282 int hlen, hoff, toff;
283 int hreclen, treclen;
284- off64_t prev_diroff = 0;
285+ off_t prev_diroff = 0;
286
287 hdirp = g_try_malloc(count);
288 if (!hdirp) {
289@@ -8727,7 +8652,7 @@ static int do_getdents64(abi_long dirfd,
290 * Return what we have, resetting the file pointer to the
291 * location of the first record not returned.
292 */
293- lseek64(dirfd, prev_diroff, SEEK_SET);
294+ lseek(dirfd, prev_diroff, SEEK_SET);
295 break;
296 }
297
298@@ -11158,7 +11083,7 @@ static abi_long do_syscall1(CPUArchState
299 return -TARGET_EFAULT;
300 }
301 }
302- ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
303+ ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5)));
304 unlock_user(p, arg2, ret);
305 return ret;
306 case TARGET_NR_pwrite64:
307@@ -11175,7 +11100,7 @@ static abi_long do_syscall1(CPUArchState
308 return -TARGET_EFAULT;
309 }
310 }
311- ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
312+ ret = get_errno(pwrite(arg1, p, arg3, target_offset64(arg4, arg5)));
313 unlock_user(p, arg2, 0);
314 return ret;
315 #endif
316@@ -11998,14 +11923,14 @@ static abi_long do_syscall1(CPUArchState
317 case TARGET_NR_fcntl64:
318 {
319 int cmd;
320- struct flock64 fl;
321- from_flock64_fn *copyfrom = copy_from_user_flock64;
322- to_flock64_fn *copyto = copy_to_user_flock64;
323+ struct flock fl;
324+ from_flock_fn *copyfrom = copy_from_user_flock;
325+ to_flock_fn *copyto = copy_to_user_flock;
326
327 #ifdef TARGET_ARM
328 if (!cpu_env->eabi) {
329- copyfrom = copy_from_user_oabi_flock64;
330- copyto = copy_to_user_oabi_flock64;
331+ copyfrom = copy_from_user_oabi_flock;
332+ copyto = copy_to_user_oabi_flock;
333 }
334 #endif
335
336@@ -12015,7 +11940,7 @@ static abi_long do_syscall1(CPUArchState
337 }
338
339 switch(arg2) {
340- case TARGET_F_GETLK64:
341+ case TARGET_F_GETLK:
342 ret = copyfrom(&fl, arg3);
343 if (ret) {
344 break;
345@@ -12026,8 +11951,8 @@ static abi_long do_syscall1(CPUArchState
346 }
347 break;
348
349- case TARGET_F_SETLK64:
350- case TARGET_F_SETLKW64:
351+ case TARGET_F_SETLK:
352+ case TARGET_F_SETLKW:
353 ret = copyfrom(&fl, arg3);
354 if (ret) {
355 break;
diff --git a/meta/recipes-devtools/qemu/qemu/0002-linux-user-loongarch64-Remove-TARGET_FORCE_SHMLBA.patch b/meta/recipes-devtools/qemu/qemu/0002-linux-user-loongarch64-Remove-TARGET_FORCE_SHMLBA.patch
new file mode 100644
index 0000000000..3f01aaa644
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0002-linux-user-loongarch64-Remove-TARGET_FORCE_SHMLBA.patch
@@ -0,0 +1,43 @@
1From 5bf65b24414d3ff8339f6f1beb221c7c35c91e5d Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Wed, 28 Feb 2024 10:25:15 -1000
4Subject: [PATCH 2/5] linux-user/loongarch64: Remove TARGET_FORCE_SHMLBA
5
6The kernel abi was changed with
7
8 commit d23b77953f5a4fbf94c05157b186aac2a247ae32
9 Author: Huacai Chen <chenhuacai@kernel.org>
10 Date: Wed Jan 17 12:43:08 2024 +0800
11
12 LoongArch: Change SHMLBA from SZ_64K to PAGE_SIZE
13
14during the v6.8 cycle.
15
16Upstream-Status: Submitted [https://www.mail-archive.com/qemu-devel@nongnu.org/msg1026793.html]
17
18Reviewed-by: Song Gao <gaosong@loongson.cn>
19Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
20Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
21---
22 linux-user/loongarch64/target_syscall.h | 7 -------
23 1 file changed, 7 deletions(-)
24
25diff --git a/linux-user/loongarch64/target_syscall.h b/linux-user/loongarch64/target_syscall.h
26index 8b5de5212..39f229bb9 100644
27--- a/linux-user/loongarch64/target_syscall.h
28+++ b/linux-user/loongarch64/target_syscall.h
29@@ -38,11 +38,4 @@ struct target_pt_regs {
30 #define TARGET_MCL_FUTURE 2
31 #define TARGET_MCL_ONFAULT 4
32
33-#define TARGET_FORCE_SHMLBA
34-
35-static inline abi_ulong target_shmlba(CPULoongArchState *env)
36-{
37- return 64 * KiB;
38-}
39-
40 #endif
41--
422.34.1
43
diff --git a/meta/recipes-devtools/qemu/qemu/0007-apic-fixup-fallthrough-to-PIC.patch b/meta/recipes-devtools/qemu/qemu/0003-apic-fixup-fallthrough-to-PIC.patch
index 294cf5129f..e85f8202e9 100644
--- a/meta/recipes-devtools/qemu/qemu/0007-apic-fixup-fallthrough-to-PIC.patch
+++ b/meta/recipes-devtools/qemu/qemu/0003-apic-fixup-fallthrough-to-PIC.patch
@@ -1,7 +1,7 @@
1From a59a98d100123030a4145e7efe3b8a001920a9f1 Mon Sep 17 00:00:00 2001 1From dc2a8ccd440ee3741b61606eafed3f7e092f4312 Mon Sep 17 00:00:00 2001
2From: Mark Asselstine <mark.asselstine@windriver.com> 2From: Mark Asselstine <mark.asselstine@windriver.com>
3Date: Tue, 26 Feb 2013 11:43:28 -0500 3Date: Tue, 26 Feb 2013 11:43:28 -0500
4Subject: [PATCH] apic: fixup fallthrough to PIC 4Subject: [PATCH 03/12] apic: fixup fallthrough to PIC
5 5
6Commit 0e21e12bb311c4c1095d0269dc2ef81196ccb60a [Don't route PIC 6Commit 0e21e12bb311c4c1095d0269dc2ef81196ccb60a [Don't route PIC
7interrupts through the local APIC if the local APIC config says so.] 7interrupts through the local APIC if the local APIC config says so.]
@@ -29,11 +29,11 @@ Signed-off-by: He Zhe <zhe.he@windriver.com>
29 hw/intc/apic.c | 2 +- 29 hw/intc/apic.c | 2 +-
30 1 file changed, 1 insertion(+), 1 deletion(-) 30 1 file changed, 1 insertion(+), 1 deletion(-)
31 31
32Index: qemu-5.2.0/hw/intc/apic.c 32Index: qemu-8.0.0/hw/intc/apic.c
33=================================================================== 33===================================================================
34--- qemu-5.2.0.orig/hw/intc/apic.c 34--- qemu-8.0.0.orig/hw/intc/apic.c
35+++ qemu-5.2.0/hw/intc/apic.c 35+++ qemu-8.0.0/hw/intc/apic.c
36@@ -605,7 +605,7 @@ int apic_accept_pic_intr(DeviceState *de 36@@ -607,7 +607,7 @@ int apic_accept_pic_intr(DeviceState *de
37 APICCommonState *s = APIC(dev); 37 APICCommonState *s = APIC(dev);
38 uint32_t lvt0; 38 uint32_t lvt0;
39 39
diff --git a/meta/recipes-devtools/qemu/qemu/0003-linux-user-Add-strace-for-shmat.patch b/meta/recipes-devtools/qemu/qemu/0003-linux-user-Add-strace-for-shmat.patch
new file mode 100644
index 0000000000..0c601c804a
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0003-linux-user-Add-strace-for-shmat.patch
@@ -0,0 +1,71 @@
1From e8f06676c6c88e12cd5f4f81a839b7111c683596 Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Wed, 28 Feb 2024 10:25:16 -1000
4Subject: [PATCH 3/5] linux-user: Add strace for shmat
5
6Upstream-Status: Submitted [https://www.mail-archive.com/qemu-devel@nongnu.org/msg1026793.html]
7
8Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
10---
11 linux-user/strace.c | 23 +++++++++++++++++++++++
12 linux-user/strace.list | 2 +-
13 2 files changed, 24 insertions(+), 1 deletion(-)
14
15diff --git a/linux-user/strace.c b/linux-user/strace.c
16index cf26e5526..47d6ec326 100644
17--- a/linux-user/strace.c
18+++ b/linux-user/strace.c
19@@ -670,6 +670,25 @@ print_semctl(CPUArchState *cpu_env, const struct syscallname *name,
20 }
21 #endif
22
23+static void
24+print_shmat(CPUArchState *cpu_env, const struct syscallname *name,
25+ abi_long arg0, abi_long arg1, abi_long arg2,
26+ abi_long arg3, abi_long arg4, abi_long arg5)
27+{
28+ static const struct flags shmat_flags[] = {
29+ FLAG_GENERIC(SHM_RND),
30+ FLAG_GENERIC(SHM_REMAP),
31+ FLAG_GENERIC(SHM_RDONLY),
32+ FLAG_GENERIC(SHM_EXEC),
33+ };
34+
35+ print_syscall_prologue(name);
36+ print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
37+ print_pointer(arg1, 0);
38+ print_flags(shmat_flags, arg2, 1);
39+ print_syscall_epilogue(name);
40+}
41+
42 #ifdef TARGET_NR_ipc
43 static void
44 print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
45@@ -683,6 +702,10 @@ print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
46 print_ipc_cmd(arg3);
47 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
48 break;
49+ case IPCOP_shmat:
50+ print_shmat(cpu_env, &(const struct syscallname){ .name = "shmat" },
51+ arg1, arg4, arg2, 0, 0, 0);
52+ break;
53 default:
54 qemu_log(("%s("
55 TARGET_ABI_FMT_ld ","
56diff --git a/linux-user/strace.list b/linux-user/strace.list
57index 6655d4f26..dfd4237d1 100644
58--- a/linux-user/strace.list
59+++ b/linux-user/strace.list
60@@ -1398,7 +1398,7 @@
61 { TARGET_NR_sgetmask, "sgetmask" , NULL, NULL, NULL },
62 #endif
63 #ifdef TARGET_NR_shmat
64-{ TARGET_NR_shmat, "shmat" , NULL, NULL, print_syscall_ret_addr },
65+{ TARGET_NR_shmat, "shmat" , NULL, print_shmat, print_syscall_ret_addr },
66 #endif
67 #ifdef TARGET_NR_shmctl
68 { TARGET_NR_shmctl, "shmctl" , NULL, NULL, NULL },
69--
702.34.1
71
diff --git a/meta/recipes-devtools/qemu/qemu/0004-configure-Add-pkg-config-handling-for-libgcrypt.patch b/meta/recipes-devtools/qemu/qemu/0004-configure-Add-pkg-config-handling-for-libgcrypt.patch
new file mode 100644
index 0000000000..f981a64a54
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0004-configure-Add-pkg-config-handling-for-libgcrypt.patch
@@ -0,0 +1,29 @@
1From d8265abdce5dc2bf74b3fccdf2b7257b4f3894f0 Mon Sep 17 00:00:00 2001
2From: He Zhe <zhe.he@windriver.com>
3Date: Wed, 28 Aug 2019 19:56:28 +0800
4Subject: [PATCH 04/12] configure: Add pkg-config handling for libgcrypt
5
6libgcrypt may also be controlled by pkg-config, this patch adds pkg-config
7handling for libgcrypt.
8
9Upstream-Status: Denied [https://lists.nongnu.org/archive/html/qemu-devel/2019-08/msg06333.html]
10
11Signed-off-by: He Zhe <zhe.he@windriver.com>
12
13---
14 meson.build | 2 +-
15 1 file changed, 1 insertion(+), 1 deletion(-)
16
17Index: qemu-8.1.0/meson.build
18===================================================================
19--- qemu-8.1.0.orig/meson.build
20+++ qemu-8.1.0/meson.build
21@@ -1481,7 +1481,7 @@ endif
22 if not gnutls_crypto.found()
23 if (not get_option('gcrypt').auto() or have_system) and not get_option('nettle').enabled()
24 gcrypt = dependency('libgcrypt', version: '>=1.8',
25- method: 'config-tool',
26+ method: 'pkg-config',
27 required: get_option('gcrypt'))
28 # Debian has removed -lgpg-error from libgcrypt-config
29 # as it "spreads unnecessary dependencies" which in
diff --git a/meta/recipes-devtools/qemu/qemu/0004-linux-user-Rewrite-target_shmat.patch b/meta/recipes-devtools/qemu/qemu/0004-linux-user-Rewrite-target_shmat.patch
new file mode 100644
index 0000000000..88c3ed40b0
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0004-linux-user-Rewrite-target_shmat.patch
@@ -0,0 +1,236 @@
1From cb48d5d1592e63ebd0d4a3e300ef98e38e6306d7 Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Wed, 28 Feb 2024 10:25:17 -1000
4Subject: [PATCH 4/5] linux-user: Rewrite target_shmat
5
6Handle combined host and guest alignment requirements.
7Handle host and guest page size differences.
8Handle SHM_EXEC.
9
10Upstream-Status: Submitted [https://www.mail-archive.com/qemu-devel@nongnu.org/msg1026793.html]
11
12Resolves: https://gitlab.com/qemu-project/qemu/-/issues/115
13Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
15---
16 linux-user/mmap.c | 166 +++++++++++++++++++++++++++++++++++++---------
17 1 file changed, 133 insertions(+), 33 deletions(-)
18
19diff --git a/linux-user/mmap.c b/linux-user/mmap.c
20index 18fb3aaf7..6a2f649bb 100644
21--- a/linux-user/mmap.c
22+++ b/linux-user/mmap.c
23@@ -1062,69 +1062,161 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env)
24 }
25 #endif
26
27+#if defined(__arm__) || defined(__mips__) || defined(__sparc__)
28+#define HOST_FORCE_SHMLBA 1
29+#else
30+#define HOST_FORCE_SHMLBA 0
31+#endif
32+
33 abi_ulong target_shmat(CPUArchState *cpu_env, int shmid,
34 abi_ulong shmaddr, int shmflg)
35 {
36 CPUState *cpu = env_cpu(cpu_env);
37- abi_ulong raddr;
38 struct shmid_ds shm_info;
39 int ret;
40- abi_ulong shmlba;
41+ int h_pagesize;
42+ int t_shmlba, h_shmlba, m_shmlba;
43+ size_t t_len, h_len, m_len;
44
45 /* shmat pointers are always untagged */
46
47- /* find out the length of the shared memory segment */
48+ /*
49+ * Because we can't use host shmat() unless the address is sufficiently
50+ * aligned for the host, we'll need to check both.
51+ * TODO: Could be fixed with softmmu.
52+ */
53+ t_shmlba = target_shmlba(cpu_env);
54+ h_pagesize = qemu_real_host_page_size();
55+ h_shmlba = (HOST_FORCE_SHMLBA ? SHMLBA : h_pagesize);
56+ m_shmlba = MAX(t_shmlba, h_shmlba);
57+
58+ if (shmaddr) {
59+ if (shmaddr & (m_shmlba - 1)) {
60+ if (shmflg & SHM_RND) {
61+ /*
62+ * The guest is allowing the kernel to round the address.
63+ * Assume that the guest is ok with us rounding to the
64+ * host required alignment too. Anyway if we don't, we'll
65+ * get an error from the kernel.
66+ */
67+ shmaddr &= ~(m_shmlba - 1);
68+ if (shmaddr == 0 && (shmflg & SHM_REMAP)) {
69+ return -TARGET_EINVAL;
70+ }
71+ } else {
72+ int require = TARGET_PAGE_SIZE;
73+#ifdef TARGET_FORCE_SHMLBA
74+ require = t_shmlba;
75+#endif
76+ /*
77+ * Include host required alignment, as otherwise we cannot
78+ * use host shmat at all.
79+ */
80+ require = MAX(require, h_shmlba);
81+ if (shmaddr & (require - 1)) {
82+ return -TARGET_EINVAL;
83+ }
84+ }
85+ }
86+ } else {
87+ if (shmflg & SHM_REMAP) {
88+ return -TARGET_EINVAL;
89+ }
90+ }
91+ /* All rounding now manually concluded. */
92+ shmflg &= ~SHM_RND;
93+
94+ /* Find out the length of the shared memory segment. */
95 ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info));
96 if (is_error(ret)) {
97 /* can't get length, bail out */
98 return ret;
99 }
100+ t_len = TARGET_PAGE_ALIGN(shm_info.shm_segsz);
101+ h_len = ROUND_UP(shm_info.shm_segsz, h_pagesize);
102+ m_len = MAX(t_len, h_len);
103
104- shmlba = target_shmlba(cpu_env);
105-
106- if (shmaddr & (shmlba - 1)) {
107- if (shmflg & SHM_RND) {
108- shmaddr &= ~(shmlba - 1);
109- } else {
110- return -TARGET_EINVAL;
111- }
112- }
113- if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) {
114+ if (!guest_range_valid_untagged(shmaddr, m_len)) {
115 return -TARGET_EINVAL;
116 }
117
118 WITH_MMAP_LOCK_GUARD() {
119- void *host_raddr;
120+ bool mapped = false;
121+ void *want, *test;
122 abi_ulong last;
123
124- if (shmaddr) {
125- host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
126+ if (!shmaddr) {
127+ shmaddr = mmap_find_vma(0, m_len, m_shmlba);
128+ if (shmaddr == -1) {
129+ return -TARGET_ENOMEM;
130+ }
131+ mapped = !reserved_va;
132+ } else if (shmflg & SHM_REMAP) {
133+ /*
134+ * If host page size > target page size, the host shmat may map
135+ * more memory than the guest expects. Reject a mapping that
136+ * would replace memory in the unexpected gap.
137+ * TODO: Could be fixed with softmmu.
138+ */
139+ if (t_len < h_len &&
140+ !page_check_range_empty(shmaddr + t_len,
141+ shmaddr + h_len - 1)) {
142+ return -TARGET_EINVAL;
143+ }
144 } else {
145- abi_ulong mmap_start;
146+ if (!page_check_range_empty(shmaddr, shmaddr + m_len - 1)) {
147+ return -TARGET_EINVAL;
148+ }
149+ }
150
151- /* In order to use the host shmat, we need to honor host SHMLBA. */
152- mmap_start = mmap_find_vma(0, shm_info.shm_segsz,
153- MAX(SHMLBA, shmlba));
154+ /* All placement is now complete. */
155+ want = (void *)g2h_untagged(shmaddr);
156
157- if (mmap_start == -1) {
158- return -TARGET_ENOMEM;
159+ /*
160+ * Map anonymous pages across the entire range, then remap with
161+ * the shared memory. This is required for a number of corner
162+ * cases for which host and guest page sizes differ.
163+ */
164+ if (h_len != t_len) {
165+ int mmap_p = PROT_READ | (shmflg & SHM_RDONLY ? 0 : PROT_WRITE);
166+ int mmap_f = MAP_PRIVATE | MAP_ANONYMOUS
167+ | (reserved_va || (shmflg & SHM_REMAP)
168+ ? MAP_FIXED : MAP_FIXED_NOREPLACE);
169+
170+ test = mmap(want, m_len, mmap_p, mmap_f, -1, 0);
171+ if (unlikely(test != want)) {
172+ /* shmat returns EINVAL not EEXIST like mmap. */
173+ ret = (test == MAP_FAILED && errno != EEXIST
174+ ? get_errno(-1) : -TARGET_EINVAL);
175+ if (mapped) {
176+ do_munmap(want, m_len);
177+ }
178+ return ret;
179 }
180- host_raddr = shmat(shmid, g2h_untagged(mmap_start),
181- shmflg | SHM_REMAP);
182+ mapped = true;
183 }
184
185- if (host_raddr == (void *)-1) {
186- return get_errno(-1);
187+ if (reserved_va || mapped) {
188+ shmflg |= SHM_REMAP;
189+ }
190+ test = shmat(shmid, want, shmflg);
191+ if (test == MAP_FAILED) {
192+ ret = get_errno(-1);
193+ if (mapped) {
194+ do_munmap(want, m_len);
195+ }
196+ return ret;
197 }
198- raddr = h2g(host_raddr);
199- last = raddr + shm_info.shm_segsz - 1;
200+ assert(test == want);
201
202- page_set_flags(raddr, last,
203+ last = shmaddr + m_len - 1;
204+ page_set_flags(shmaddr, last,
205 PAGE_VALID | PAGE_RESET | PAGE_READ |
206- (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE));
207+ (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE) |
208+ (shmflg & SHM_EXEC ? PAGE_EXEC : 0));
209
210- shm_region_rm_complete(raddr, last);
211- shm_region_add(raddr, last);
212+ shm_region_rm_complete(shmaddr, last);
213+ shm_region_add(shmaddr, last);
214 }
215
216 /*
217@@ -1138,7 +1230,15 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid,
218 tb_flush(cpu);
219 }
220
221- return raddr;
222+ if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
223+ FILE *f = qemu_log_trylock();
224+ if (f) {
225+ fprintf(f, "page layout changed following shmat\n");
226+ page_dump(f);
227+ qemu_log_unlock(f);
228+ }
229+ }
230+ return shmaddr;
231 }
232
233 abi_long target_shmdt(abi_ulong shmaddr)
234--
2352.34.1
236
diff --git a/meta/recipes-devtools/qemu/qemu/0004-qemu-disable-Valgrind.patch b/meta/recipes-devtools/qemu/qemu/0004-qemu-disable-Valgrind.patch
deleted file mode 100644
index a0bd1c5ebc..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0004-qemu-disable-Valgrind.patch
+++ /dev/null
@@ -1,34 +0,0 @@
1From 4127296bb1046cdf73994ba69dc913d8c02fd74f Mon Sep 17 00:00:00 2001
2From: Ross Burton <ross.burton@intel.com>
3Date: Tue, 20 Oct 2015 22:19:08 +0100
4Subject: [PATCH] qemu: disable Valgrind
5
6There isn't an option to enable or disable valgrind support, so disable it to avoid non-deterministic builds.
7
8Upstream-Status: Inappropriate
9Signed-off-by: Ross Burton <ross.burton@intel.com>
10
11---
12 configure | 9 ---------
13 1 file changed, 9 deletions(-)
14
15Index: qemu-5.2.0/configure
16===================================================================
17--- qemu-5.2.0.orig/configure
18+++ qemu-5.2.0/configure
19@@ -5001,15 +5001,6 @@ fi
20 # check if we have valgrind/valgrind.h
21
22 valgrind_h=no
23-cat > $TMPC << EOF
24-#include <valgrind/valgrind.h>
25-int main(void) {
26- return 0;
27-}
28-EOF
29-if compile_prog "" "" ; then
30- valgrind_h=yes
31-fi
32
33 ########################################
34 # check if environ is declared
diff --git a/meta/recipes-devtools/qemu/qemu/0001-qemu-Do-not-include-file-if-not-exists.patch b/meta/recipes-devtools/qemu/qemu/0005-qemu-Do-not-include-file-if-not-exists.patch
index 3fe9aa6eb5..38aa4c3bbe 100644
--- a/meta/recipes-devtools/qemu/qemu/0001-qemu-Do-not-include-file-if-not-exists.patch
+++ b/meta/recipes-devtools/qemu/qemu/0005-qemu-Do-not-include-file-if-not-exists.patch
@@ -1,7 +1,7 @@
1From 34247f83095f8cdcdc1f9d7f0c6ffbd46b25d979 Mon Sep 17 00:00:00 2001 1From f39e7bfc5ed07b5ecaeb705c4eae4855ca120d47 Mon Sep 17 00:00:00 2001
2From: Oleksiy Obitotskyy <oobitots@cisco.com> 2From: Oleksiy Obitotskyy <oobitots@cisco.com>
3Date: Wed, 25 Mar 2020 21:21:35 +0200 3Date: Wed, 25 Mar 2020 21:21:35 +0200
4Subject: [PATCH] qemu: Do not include file if not exists 4Subject: [PATCH 05/12] qemu: Do not include file if not exists
5 5
6Script configure checks for if_alg.h and check failed but 6Script configure checks for if_alg.h and check failed but
7if_alg.h still included. 7if_alg.h still included.
@@ -11,15 +11,16 @@ Signed-off-by: Oleksiy Obitotskyy <oobitots@cisco.com>
11 11
12[update patch context] 12[update patch context]
13Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com> 13Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
14
14--- 15---
15 linux-user/syscall.c | 2 ++ 16 linux-user/syscall.c | 2 ++
16 1 file changed, 2 insertions(+) 17 1 file changed, 2 insertions(+)
17 18
18Index: qemu-5.2.0/linux-user/syscall.c 19Index: qemu-8.0.0/linux-user/syscall.c
19=================================================================== 20===================================================================
20--- qemu-5.2.0.orig/linux-user/syscall.c 21--- qemu-8.0.0.orig/linux-user/syscall.c
21+++ qemu-5.2.0/linux-user/syscall.c 22+++ qemu-8.0.0/linux-user/syscall.c
22@@ -109,7 +109,9 @@ 23@@ -115,7 +115,9 @@
23 #include <linux/blkpg.h> 24 #include <linux/blkpg.h>
24 #include <netpacket/packet.h> 25 #include <netpacket/packet.h>
25 #include <linux/netlink.h> 26 #include <linux/netlink.h>
@@ -28,4 +29,4 @@ Index: qemu-5.2.0/linux-user/syscall.c
28+#endif 29+#endif
29 #include <linux/rtc.h> 30 #include <linux/rtc.h>
30 #include <sound/asound.h> 31 #include <sound/asound.h>
31 #ifdef CONFIG_BTRFS 32 #ifdef HAVE_BTRFS_H
diff --git a/meta/recipes-devtools/qemu/qemu/0005-tests-tcg-Check-that-shmat-does-not-break-proc-self-.patch b/meta/recipes-devtools/qemu/qemu/0005-tests-tcg-Check-that-shmat-does-not-break-proc-self-.patch
new file mode 100644
index 0000000000..5afb35ea0c
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0005-tests-tcg-Check-that-shmat-does-not-break-proc-self-.patch
@@ -0,0 +1,85 @@
1From 1234063488134ad1f541f56dd30caa7896905f06 Mon Sep 17 00:00:00 2001
2From: Ilya Leoshkevich <iii@linux.ibm.com>
3Date: Wed, 28 Feb 2024 10:25:18 -1000
4Subject: [PATCH 5/5] tests/tcg: Check that shmat() does not break
5 /proc/self/maps
6
7Add a regression test for a recently fixed issue, where shmat()
8desynced the guest and the host view of the address space and caused
9open("/proc/self/maps") to SEGV.
10
11Upstream-Status: Submitted [https://www.mail-archive.com/qemu-devel@nongnu.org/msg1026793.html]
12
13Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14Message-Id: <jwyuvao4apydvykmsnvacwshdgy3ixv7qvkh4dbxm3jkwgnttw@k4wpaayou7oq>
15Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
16Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
17---
18 tests/tcg/multiarch/linux/linux-shmat-maps.c | 55 ++++++++++++++++++++
19 1 file changed, 55 insertions(+)
20 create mode 100644 tests/tcg/multiarch/linux/linux-shmat-maps.c
21
22diff --git a/tests/tcg/multiarch/linux/linux-shmat-maps.c b/tests/tcg/multiarch/linux/linux-shmat-maps.c
23new file mode 100644
24index 000000000..0ccf7a973
25--- /dev/null
26+++ b/tests/tcg/multiarch/linux/linux-shmat-maps.c
27@@ -0,0 +1,55 @@
28+/*
29+ * Test that shmat() does not break /proc/self/maps.
30+ *
31+ * SPDX-License-Identifier: GPL-2.0-or-later
32+ */
33+#include <assert.h>
34+#include <fcntl.h>
35+#include <stdlib.h>
36+#include <sys/ipc.h>
37+#include <sys/shm.h>
38+#include <unistd.h>
39+
40+int main(void)
41+{
42+ char buf[128];
43+ int err, fd;
44+ int shmid;
45+ ssize_t n;
46+ void *p;
47+
48+ shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
49+ assert(shmid != -1);
50+
51+ /*
52+ * The original bug required a non-NULL address, which skipped the
53+ * mmap_find_vma step, which could result in a host mapping smaller
54+ * than the target mapping. Choose an address at random.
55+ */
56+ p = shmat(shmid, (void *)0x800000, SHM_RND);
57+ if (p == (void *)-1) {
58+ /*
59+ * Because we are now running the testcase for all guests for which
60+ * we have a cross-compiler, the above random address might conflict
61+ * with the guest executable in some way. Rather than stopping,
62+ * continue with a system supplied address, which should never fail.
63+ */
64+ p = shmat(shmid, NULL, 0);
65+ assert(p != (void *)-1);
66+ }
67+
68+ fd = open("/proc/self/maps", O_RDONLY);
69+ assert(fd != -1);
70+ do {
71+ n = read(fd, buf, sizeof(buf));
72+ assert(n >= 0);
73+ } while (n != 0);
74+ close(fd);
75+
76+ err = shmdt(p);
77+ assert(err == 0);
78+ err = shmctl(shmid, IPC_RMID, NULL);
79+ assert(err == 0);
80+
81+ return EXIT_SUCCESS;
82+}
83--
842.34.1
85
diff --git a/meta/recipes-devtools/qemu/qemu/0006-chardev-connect-socket-to-a-spawned-command.patch b/meta/recipes-devtools/qemu/qemu/0006-chardev-connect-socket-to-a-spawned-command.patch
deleted file mode 100644
index 201125c1f4..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0006-chardev-connect-socket-to-a-spawned-command.patch
+++ /dev/null
@@ -1,243 +0,0 @@
1From bcc63f775e265df69963a4ad7805b8678ace68f0 Mon Sep 17 00:00:00 2001
2From: Alistair Francis <alistair.francis@xilinx.com>
3Date: Thu, 21 Dec 2017 11:35:16 -0800
4Subject: [PATCH] chardev: connect socket to a spawned command
5
6The command is started in a shell (sh -c) with stdin connect to QEMU
7via a Unix domain stream socket. QEMU then exchanges data via its own
8end of the socket, just like it normally does.
9
10"-chardev socket" supports some ways of connecting via protocols like
11telnet, but that is only a subset of the functionality supported by
12tools socat. To use socat instead, for example to connect via a socks
13proxy, use:
14
15 -chardev 'socket,id=socat,cmd=exec socat FD:0 SOCKS4A:socks-proxy.localdomain:example.com:9999,,socksuser=nobody' \
16 -device usb-serial,chardev=socat
17
18Beware that commas in the command must be escaped as double commas.
19
20Or interactively in the console:
21 (qemu) chardev-add socket,id=cat,cmd=cat
22 (qemu) device_add usb-serial,chardev=cat
23 ^ac
24 # cat >/dev/ttyUSB0
25 hello
26 hello
27
28Another usage is starting swtpm from inside QEMU. swtpm will
29automatically shut down once it looses the connection to the parent
30QEMU, so there is no risk of lingering processes:
31
32 -chardev 'socket,id=chrtpm0,cmd=exec swtpm socket --terminate --ctrl type=unixio,,clientfd=0 --tpmstate dir=... --log file=swtpm.log' \
33 -tpmdev emulator,id=tpm0,chardev=chrtpm0 \
34 -device tpm-tis,tpmdev=tpm0
35
36The patch was discussed upstream, but QEMU developers believe that the
37code calling QEMU should be responsible for managing additional
38processes. In OE-core, that would imply enhancing runqemu and
39oeqa. This patch is a simpler solution.
40
41Because it is not going upstream, the patch was written so that it is
42as simple as possible.
43
44Upstream-Status: Inappropriate [embedded specific]
45
46Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
47
48---
49 chardev/char-socket.c | 101 ++++++++++++++++++++++++++++++++++++++++++
50 chardev/char.c | 3 ++
51 qapi/char.json | 5 +++
52 3 files changed, 109 insertions(+)
53
54Index: qemu-5.2.0/chardev/char-socket.c
55===================================================================
56--- qemu-5.2.0.orig/chardev/char-socket.c
57+++ qemu-5.2.0/chardev/char-socket.c
58@@ -1308,6 +1308,67 @@ static bool qmp_chardev_validate_socket(
59 return true;
60 }
61
62+#ifndef _WIN32
63+static void chardev_open_socket_cmd(Chardev *chr,
64+ const char *cmd,
65+ Error **errp)
66+{
67+ int fds[2] = { -1, -1 };
68+ QIOChannelSocket *sioc = NULL;
69+ pid_t pid = -1;
70+ const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
71+
72+ /*
73+ * We need a Unix domain socket for commands like swtpm and a single
74+ * connection, therefore we cannot use qio_channel_command_new_spawn()
75+ * without patching it first. Duplicating the functionality is easier.
76+ */
77+ if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds)) {
78+ error_setg_errno(errp, errno, "Error creating socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC)");
79+ goto error;
80+ }
81+
82+ pid = qemu_fork(errp);
83+ if (pid < 0) {
84+ goto error;
85+ }
86+
87+ if (!pid) {
88+ /* child */
89+ dup2(fds[1], STDIN_FILENO);
90+ execv(argv[0], (char * const *)argv);
91+ _exit(1);
92+ }
93+
94+ /*
95+ * Hand over our end of the socket pair to the qio channel.
96+ *
97+ * We don't reap the child because it is expected to keep
98+ * running. We also don't support the "reconnect" option for the
99+ * same reason.
100+ */
101+ sioc = qio_channel_socket_new_fd(fds[0], errp);
102+ if (!sioc) {
103+ goto error;
104+ }
105+ fds[0] = -1;
106+
107+ g_free(chr->filename);
108+ chr->filename = g_strdup_printf("cmd:%s", cmd);
109+ tcp_chr_new_client(chr, sioc);
110+
111+ error:
112+ if (fds[0] >= 0) {
113+ close(fds[0]);
114+ }
115+ if (fds[1] >= 0) {
116+ close(fds[1]);
117+ }
118+ if (sioc) {
119+ object_unref(OBJECT(sioc));
120+ }
121+}
122+#endif
123
124 static void qmp_chardev_open_socket(Chardev *chr,
125 ChardevBackend *backend,
126@@ -1316,6 +1377,9 @@ static void qmp_chardev_open_socket(Char
127 {
128 SocketChardev *s = SOCKET_CHARDEV(chr);
129 ChardevSocket *sock = backend->u.socket.data;
130+#ifndef _WIN32
131+ const char *cmd = sock->cmd;
132+#endif
133 bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
134 bool is_listen = sock->has_server ? sock->server : true;
135 bool is_telnet = sock->has_telnet ? sock->telnet : false;
136@@ -1381,6 +1445,14 @@ static void qmp_chardev_open_socket(Char
137
138 update_disconnected_filename(s);
139
140+#ifndef _WIN32
141+ if (cmd) {
142+ chardev_open_socket_cmd(chr, cmd, errp);
143+
144+ /* everything ready (or failed permanently) before we return */
145+ *be_opened = true;
146+ } else
147+#endif
148 if (s->is_listen) {
149 if (qmp_chardev_open_socket_server(chr, is_telnet || is_tn3270,
150 is_waitconnect, errp) < 0) {
151@@ -1400,6 +1472,9 @@ static void qemu_chr_parse_socket(QemuOp
152 const char *host = qemu_opt_get(opts, "host");
153 const char *port = qemu_opt_get(opts, "port");
154 const char *fd = qemu_opt_get(opts, "fd");
155+#ifndef _WIN32
156+ const char *cmd = qemu_opt_get(opts, "cmd");
157+#endif
158 #ifdef CONFIG_LINUX
159 bool tight = qemu_opt_get_bool(opts, "tight", true);
160 bool abstract = qemu_opt_get_bool(opts, "abstract", false);
161@@ -1407,6 +1482,20 @@ static void qemu_chr_parse_socket(QemuOp
162 SocketAddressLegacy *addr;
163 ChardevSocket *sock;
164
165+#ifndef _WIN32
166+ if (cmd) {
167+ /*
168+ * Here we have to ensure that no options are set which are incompatible with
169+ * spawning a command, otherwise unmodified code that doesn't know about
170+ * command spawning (like socket_reconnect_timeout()) might get called.
171+ */
172+ if (path || sock->server || sock->has_telnet || sock->has_tn3270 || sock->reconnect || host || port || sock->tls_creds) {
173+ error_setg(errp, "chardev: socket: cmd does not support any additional options");
174+ return;
175+ }
176+ } else
177+#endif
178+
179 if ((!!path + !!fd + !!host) != 1) {
180 error_setg(errp,
181 "Exactly one of 'path', 'fd' or 'host' required");
182@@ -1448,13 +1537,24 @@ static void qemu_chr_parse_socket(QemuOp
183 sock->tls_creds = g_strdup(qemu_opt_get(opts, "tls-creds"));
184 sock->has_tls_authz = qemu_opt_get(opts, "tls-authz");
185 sock->tls_authz = g_strdup(qemu_opt_get(opts, "tls-authz"));
186+#ifndef _WIN32
187+ sock->cmd = g_strdup(cmd);
188+#endif
189
190 addr = g_new0(SocketAddressLegacy, 1);
191+#ifndef _WIN32
192+ if (path || cmd) {
193+#else
194 if (path) {
195+#endif
196 UnixSocketAddress *q_unix;
197 addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
198 q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
199+#ifndef _WIN32
200+ q_unix->path = cmd ? g_strdup_printf("cmd:%s", cmd) : g_strdup(path);
201+#else
202 q_unix->path = g_strdup(path);
203+#endif
204 #ifdef CONFIG_LINUX
205 q_unix->has_tight = true;
206 q_unix->tight = tight;
207Index: qemu-5.2.0/chardev/char.c
208===================================================================
209--- qemu-5.2.0.orig/chardev/char.c
210+++ qemu-5.2.0/chardev/char.c
211@@ -839,6 +839,9 @@ QemuOptsList qemu_chardev_opts = {
212 .name = "path",
213 .type = QEMU_OPT_STRING,
214 },{
215+ .name = "cmd",
216+ .type = QEMU_OPT_STRING,
217+ },{
218 .name = "host",
219 .type = QEMU_OPT_STRING,
220 },{
221Index: qemu-5.2.0/qapi/char.json
222===================================================================
223--- qemu-5.2.0.orig/qapi/char.json
224+++ qemu-5.2.0/qapi/char.json
225@@ -250,6 +250,10 @@
226 #
227 # @addr: socket address to listen on (server=true)
228 # or connect to (server=false)
229+# @cmd: command to run via "sh -c" with stdin as one end of
230+# a AF_UNIX SOCK_DSTREAM socket pair. The other end
231+# is used by the chardev. Either an addr or a cmd can
232+# be specified, but not both.
233 # @tls-creds: the ID of the TLS credentials object (since 2.6)
234 # @tls-authz: the ID of the QAuthZ authorization object against which
235 # the client's x509 distinguished name will be validated. This
236@@ -276,6 +280,7 @@
237 ##
238 { 'struct': 'ChardevSocket',
239 'data': { 'addr': 'SocketAddressLegacy',
240+ '*cmd': 'str',
241 '*tls-creds': 'str',
242 '*tls-authz' : 'str',
243 '*server': 'bool',
diff --git a/meta/recipes-devtools/qemu/qemu/mmap2.patch b/meta/recipes-devtools/qemu/qemu/0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch
index 1652131757..5d1d7c6881 100644
--- a/meta/recipes-devtools/qemu/qemu/mmap2.patch
+++ b/meta/recipes-devtools/qemu/qemu/0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch
@@ -1,3 +1,9 @@
1From 375cae3dd6151ef33cae8f243f6a2c2da6c0c356 Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Fri, 8 Jan 2021 17:27:06 +0000
4Subject: [PATCH 06/12] qemu: Add some user space mmap tweaks to address musl
5 32 bit
6
1When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an 7When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an
2infinite loop of mremap calls of ever decreasing/increasing addresses. 8infinite loop of mremap calls of ever decreasing/increasing addresses.
3 9
@@ -13,27 +19,30 @@ rather than ENOMEM so adjust the other part of the test to this.
13Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html] 19Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html]
14Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org 20Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
15 21
16Index: qemu-5.2.0/linux-user/mmap.c 22---
23 linux-user/mmap.c | 10 +++++++---
24 1 file changed, 7 insertions(+), 3 deletions(-)
25
26Index: qemu-8.0.0/linux-user/mmap.c
17=================================================================== 27===================================================================
18--- qemu-5.2.0.orig/linux-user/mmap.c 28--- qemu-8.0.0.orig/linux-user/mmap.c
19+++ qemu-5.2.0/linux-user/mmap.c 29+++ qemu-8.0.0/linux-user/mmap.c
20@@ -722,12 +722,14 @@ abi_long target_mremap(abi_ulong old_add 30@@ -776,12 +776,16 @@ abi_long target_mremap(abi_ulong old_add
21 int prot; 31 int prot;
22 void *host_addr; 32 void *host_addr;
23 33
24- if (!guest_range_valid(old_addr, old_size) || 34- if (!guest_range_valid_untagged(old_addr, old_size) ||
25- ((flags & MREMAP_FIXED) && 35- ((flags & MREMAP_FIXED) &&
26- !guest_range_valid(new_addr, new_size)) || 36+ if (!guest_range_valid_untagged(old_addr, old_size)) {
27- ((flags & MREMAP_MAYMOVE) == 0 &&
28- !guest_range_valid(old_addr, new_size))) {
29- errno = ENOMEM;
30+ if (!guest_range_valid(old_addr, old_size)) {
31+ errno = EFAULT; 37+ errno = EFAULT;
32+ return -1; 38+ return -1;
33+ } 39+ }
34+ 40+
35+ if (((flags & MREMAP_FIXED) && !guest_range_valid(new_addr, new_size)) || 41+ if (((flags & MREMAP_FIXED) &&
36+ ((flags & MREMAP_MAYMOVE) == 0 && !guest_range_valid(old_addr, new_size))) { 42 !guest_range_valid_untagged(new_addr, new_size)) ||
43 ((flags & MREMAP_MAYMOVE) == 0 &&
44 !guest_range_valid_untagged(old_addr, new_size))) {
45- errno = ENOMEM;
37+ errno = EINVAL; 46+ errno = EINVAL;
38 return -1; 47 return -1;
39 } 48 }
diff --git a/meta/recipes-devtools/qemu/qemu/0007-qemu-Determinism-fixes.patch b/meta/recipes-devtools/qemu/qemu/0007-qemu-Determinism-fixes.patch
new file mode 100644
index 0000000000..d3f965e070
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0007-qemu-Determinism-fixes.patch
@@ -0,0 +1,31 @@
1From 50bab5c2605b609ea7ea154f57a9be96d656725a Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Mon, 1 Mar 2021 13:00:47 +0000
4Subject: [PATCH 07/12] qemu: Determinism fixes
5
6When sources are included within debug information, a couple of areas of the
7qemu build are not reproducible due to either full buildpaths or timestamps.
8
9Replace the full paths with relative ones. I couldn't figure out how to get
10meson to pass relative paths but we can fix that in the script.
11
12Upstream-Status: Pending [some version of all/part of this may be accepted]
13RP 2021/3/1
14
15---
16 scripts/decodetree.py | 2 +-
17 1 file changed, 1 insertion(+), 1 deletion(-)
18
19Index: qemu-8.0.0/scripts/decodetree.py
20===================================================================
21--- qemu-8.0.0.orig/scripts/decodetree.py
22+++ qemu-8.0.0/scripts/decodetree.py
23@@ -1328,7 +1328,7 @@ def main():
24 toppat = ExcMultiPattern(0)
25
26 for filename in args:
27- input_file = filename
28+ input_file = os.path.relpath(filename)
29 f = open(filename, 'rt', encoding='utf-8')
30 parse_file(f, toppat)
31 f.close()
diff --git a/meta/recipes-devtools/qemu/qemu/0008-tests-meson.build-use-relative-path-to-refer-to-file.patch b/meta/recipes-devtools/qemu/qemu/0008-tests-meson.build-use-relative-path-to-refer-to-file.patch
new file mode 100644
index 0000000000..a84364ccc1
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0008-tests-meson.build-use-relative-path-to-refer-to-file.patch
@@ -0,0 +1,41 @@
1From 2bf9388b801d4389e2d57e95a7897bfc1c42786e Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Thu, 14 Jan 2021 06:33:04 +0000
4Subject: [PATCH 08/12] tests/meson.build: use relative path to refer to files
5
6Fix error like:
7Fatal error: can't create tests/ptimer-test.p/..._qemu-5.2.0_hw_core_ptimer.c.o: File name too long
8
9when build path is too long, use meson.source_root() will make this
10filename too long. Fixed by using relative path to refer to files
11
12Upstream-Status: Submitted [send to qemu-devel]
13
14Signed-off-by: Changqing Li <changqing.li@windriver.com>
15
16---
17 tests/unit/meson.build | 4 ++--
18 1 file changed, 2 insertions(+), 2 deletions(-)
19
20Index: qemu-8.0.0/tests/unit/meson.build
21===================================================================
22--- qemu-8.0.0.orig/tests/unit/meson.build
23+++ qemu-8.0.0/tests/unit/meson.build
24@@ -46,7 +46,7 @@ tests = {
25 'test-keyval': [testqapi],
26 'test-logging': [],
27 'test-uuid': [],
28- 'ptimer-test': ['ptimer-test-stubs.c', meson.project_source_root() / 'hw/core/ptimer.c'],
29+ 'ptimer-test': ['ptimer-test-stubs.c', '../../hw/core/ptimer.c'],
30 'test-qapi-util': [],
31 'test-interval-tree': [],
32 'test-xs-node': [qom],
33@@ -136,7 +136,7 @@ if have_system
34 'test-util-sockets': ['socket-helpers.c'],
35 'test-base64': [],
36 'test-bufferiszero': [],
37- 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine-smp.c'],
38+ 'test-smp-parse': [qom, '../../hw/core/machine-smp.c'],
39 'test-vmstate': [migration, io],
40 'test-yank': ['socket-helpers.c', qom, io, chardev]
41 }
diff --git a/meta/recipes-devtools/qemu/qemu/0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch b/meta/recipes-devtools/qemu/qemu/0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch
new file mode 100644
index 0000000000..4de6cc2445
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch
@@ -0,0 +1,46 @@
1From ebf4bb2f51da83af0c61480414cfa156f7308b34 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 21 Mar 2022 10:09:38 -0700
4Subject: [PATCH 09/12] Define MAP_SYNC and MAP_SHARED_VALIDATE on needed linux
5 systems
6
7linux only wires MAP_SYNC and MAP_SHARED_VALIDATE for architectures
8which include asm-generic/mman.h and mips/powerpc are not including this
9file in linux/mman.h, therefore these should be defined for such
10architectures on Linux as well. This fixes build on mips/musl/linux
11
12Upstream-Status: Submitted [https://lists.nongnu.org/archive/html/qemu-devel/2022-03/msg05298.html]
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14Cc: Zhang Yi <yi.z.zhang@linux.intel.com>
15Cc: Michael S. Tsirkin <mst@redhat.com>
16
17---
18 util/mmap-alloc.c | 10 +++++++---
19 1 file changed, 7 insertions(+), 3 deletions(-)
20
21Index: qemu-8.0.0/util/mmap-alloc.c
22===================================================================
23--- qemu-8.0.0.orig/util/mmap-alloc.c
24+++ qemu-8.0.0/util/mmap-alloc.c
25@@ -10,14 +10,18 @@
26 * later. See the COPYING file in the top-level directory.
27 */
28
29+#include "qemu/osdep.h"
30 #ifdef CONFIG_LINUX
31 #include <linux/mman.h>
32-#else /* !CONFIG_LINUX */
33+#endif /* CONFIG_LINUX */
34+
35+#ifndef MAP_SYNC
36 #define MAP_SYNC 0x0
37+#endif /* MAP_SYNC */
38+#ifndef MAP_SHARED_VALIDATE
39 #define MAP_SHARED_VALIDATE 0x0
40-#endif /* CONFIG_LINUX */
41+#endif /* MAP_SHARED_VALIDATE */
42
43-#include "qemu/osdep.h"
44 #include "qemu/mmap-alloc.h"
45 #include "qemu/host-utils.h"
46 #include "qemu/cutils.h"
diff --git a/meta/recipes-devtools/qemu/qemu/0010-configure-Add-pkg-config-handling-for-libgcrypt.patch b/meta/recipes-devtools/qemu/qemu/0010-configure-Add-pkg-config-handling-for-libgcrypt.patch
deleted file mode 100644
index c5d206b91b..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0010-configure-Add-pkg-config-handling-for-libgcrypt.patch
+++ /dev/null
@@ -1,84 +0,0 @@
1From c207607cdf3996ad9783c3bffbcd3d65e74c0158 Mon Sep 17 00:00:00 2001
2From: He Zhe <zhe.he@windriver.com>
3Date: Wed, 28 Aug 2019 19:56:28 +0800
4Subject: [PATCH] configure: Add pkg-config handling for libgcrypt
5
6libgcrypt may also be controlled by pkg-config, this patch adds pkg-config
7handling for libgcrypt.
8
9Upstream-Status: Denied [https://lists.nongnu.org/archive/html/qemu-devel/2019-08/msg06333.html]
10
11Signed-off-by: He Zhe <zhe.he@windriver.com>
12
13---
14 configure | 48 ++++++++++++++++++++++++++++++++++++++++--------
15 1 file changed, 40 insertions(+), 8 deletions(-)
16
17Index: qemu-5.2.0/configure
18===================================================================
19--- qemu-5.2.0.orig/configure
20+++ qemu-5.2.0/configure
21@@ -2956,6 +2956,30 @@ has_libgcrypt() {
22 return 0
23 }
24
25+has_libgcrypt_pkgconfig() {
26+ if ! has $pkg_config ; then
27+ return 1
28+ fi
29+
30+ if ! $pkg_config --list-all | grep libgcrypt > /dev/null 2>&1 ; then
31+ return 1
32+ fi
33+
34+ if test -n "$cross_prefix" ; then
35+ host=$($pkg_config --variable=host libgcrypt)
36+ if test "${host%-gnu}-" != "${cross_prefix%-gnu}" ; then
37+ print_error "host($host) does not match cross_prefix($cross_prefix)"
38+ return 1
39+ fi
40+ fi
41+
42+ if ! $pkg_config --atleast-version=1.5.0 libgcrypt ; then
43+ print_error "libgcrypt version is $($pkg_config --modversion libgcrypt)"
44+ return 1
45+ fi
46+
47+ return 0
48+}
49
50 if test "$nettle" != "no"; then
51 pass="no"
52@@ -2994,7 +3018,14 @@ fi
53
54 if test "$gcrypt" != "no"; then
55 pass="no"
56- if has_libgcrypt; then
57+ if has_libgcrypt_pkgconfig; then
58+ gcrypt_cflags=$($pkg_config --cflags libgcrypt)
59+ if test "$static" = "yes" ; then
60+ gcrypt_libs=$($pkg_config --libs --static libgcrypt)
61+ else
62+ gcrypt_libs=$($pkg_config --libs libgcrypt)
63+ fi
64+ elif has_libgcrypt; then
65 gcrypt_cflags=$(libgcrypt-config --cflags)
66 gcrypt_libs=$(libgcrypt-config --libs)
67 # Debian has removed -lgpg-error from libgcrypt-config
68@@ -3004,12 +3035,12 @@ if test "$gcrypt" != "no"; then
69 then
70 gcrypt_libs="$gcrypt_libs -lgpg-error"
71 fi
72+ fi
73
74- # Link test to make sure the given libraries work (e.g for static).
75- write_c_skeleton
76- if compile_prog "" "$gcrypt_libs" ; then
77+ # Link test to make sure the given libraries work (e.g for static).
78+ write_c_skeleton
79+ if compile_prog "" "$gcrypt_libs" ; then
80 pass="yes"
81- fi
82 fi
83 if test "$pass" = "yes"; then
84 gcrypt="yes"
diff --git a/meta/recipes-devtools/qemu/qemu/0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch b/meta/recipes-devtools/qemu/qemu/0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch
new file mode 100644
index 0000000000..6caf35b634
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch
@@ -0,0 +1,40 @@
1CVE: CVE-2022-1050
2Upstream-Status: Submitted [https://lore.kernel.org/qemu-devel/20220403095234.2210-1-yuval.shaia.ml@gmail.com/]
3Signed-off-by: Ross Burton <ross.burton@arm.com>
4
5From dbdef95c272e8f3ec037c3db4197c66002e30995 Mon Sep 17 00:00:00 2001
6From: Yuval Shaia <yuval.shaia.ml@gmail.com>
7Date: Sun, 3 Apr 2022 12:52:34 +0300
8Subject: [PATCH] hw/pvrdma: Protect against buggy or malicious guest driver
9
10Guest driver might execute HW commands when shared buffers are not yet
11allocated.
12This could happen on purpose (malicious guest) or because of some other
13guest/host address mapping error.
14We need to protect againts such case.
15
16Fixes: CVE-2022-1050
17
18Reported-by: Raven <wxhusst@gmail.com>
19Signed-off-by: Yuval Shaia <yuval.shaia.ml@gmail.com>
20---
21 hw/rdma/vmw/pvrdma_cmd.c | 6 ++++++
22 1 file changed, 6 insertions(+)
23
24Index: qemu-8.0.0/hw/rdma/vmw/pvrdma_cmd.c
25===================================================================
26--- qemu-8.0.0.orig/hw/rdma/vmw/pvrdma_cmd.c
27+++ qemu-8.0.0/hw/rdma/vmw/pvrdma_cmd.c
28@@ -782,6 +782,12 @@ int pvrdma_exec_cmd(PVRDMADev *dev)
29 goto out;
30 }
31
32+ if (!dsr_info->dsr) {
33+ /* Buggy or malicious guest driver */
34+ rdma_error_report("Exec command without dsr, req or rsp buffers");
35+ goto out;
36+ }
37+
38 if (dsr_info->req->hdr.cmd >= sizeof(cmd_handlers) /
39 sizeof(struct cmd_handler)) {
40 rdma_error_report("Unsupported command");
diff --git a/meta/recipes-devtools/qemu/qemu/0011-linux-user-workaround-for-missing-MAP_FIXED_NOREPLAC.patch b/meta/recipes-devtools/qemu/qemu/0011-linux-user-workaround-for-missing-MAP_FIXED_NOREPLAC.patch
new file mode 100644
index 0000000000..cc53b1eedd
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0011-linux-user-workaround-for-missing-MAP_FIXED_NOREPLAC.patch
@@ -0,0 +1,282 @@
1From fa9bcabe2387bb230ef82d62827ad6f93b8a1e61 Mon Sep 17 00:00:00 2001
2From: Frederic Konrad <fkonrad@amd.com>
3Date: Wed, 17 Jan 2024 18:15:06 +0000
4Subject: [PATCH 1/2] linux-user/*: workaround for missing MAP_FIXED_NOREPLACE
5
6QEMU v8.1.0 recently requires MAP_FIXED_NOREPLACE flags implementation for mmap.
7
8This is missing from ubuntu 18.04, thus this patch catches the mmap calls which
9could use that new flag and forwards them to mmap when MAP_FIXED_NOREPLACE
10flag isn't set or emulates them by checking the returned address w.r.t the
11requested address.
12
13Signed-off-by: Frederic Konrad <fkonrad@amd.com>
14Signed-off-by: Francisco Iglesias <francisco.iglesias@amd.com>
15
16Upstream-Status: Inappropriate [OE specific]
17
18The upstream only supports the last two major releases of an OS. The ones
19they have declared all have kernel 4.17 or newer.
20
21See:
22https://xilinx.slack.com/archives/D04G2647CTV/p1705074697942019
23
24https://www.qemu.org/docs/master/about/build-platforms.html
25
26 The project aims to support the most recent major version at all times for up
27 to five years after its initial release. Support for the previous major
28 version will be dropped 2 years after the new major version is released or
29 when the vendor itself drops support, whichever comes first.
30
31Signed-off-by: Mark Hatle <mark.hatle@amd.com>
32---
33 linux-user/elfload.c | 7 +++--
34 linux-user/meson.build | 1 +
35 linux-user/mmap-fixed.c | 63 +++++++++++++++++++++++++++++++++++++++++
36 linux-user/mmap-fixed.h | 39 +++++++++++++++++++++++++
37 linux-user/mmap.c | 31 +++++++++++---------
38 linux-user/syscall.c | 1 +
39 6 files changed, 125 insertions(+), 17 deletions(-)
40 create mode 100644 linux-user/mmap-fixed.c
41 create mode 100644 linux-user/mmap-fixed.h
42
43Index: qemu-8.2.1/linux-user/elfload.c
44===================================================================
45--- qemu-8.2.1.orig/linux-user/elfload.c
46+++ qemu-8.2.1/linux-user/elfload.c
47@@ -22,6 +22,7 @@
48 #include "qemu/error-report.h"
49 #include "target_signal.h"
50 #include "accel/tcg/debuginfo.h"
51+#include "mmap-fixed.h"
52
53 #ifdef TARGET_ARM
54 #include "target/arm/cpu-features.h"
55@@ -2765,9 +2766,9 @@ static abi_ulong create_elf_tables(abi_u
56 static int pgb_try_mmap(uintptr_t addr, uintptr_t addr_last, bool keep)
57 {
58 size_t size = addr_last - addr + 1;
59- void *p = mmap((void *)addr, size, PROT_NONE,
60- MAP_ANONYMOUS | MAP_PRIVATE |
61- MAP_NORESERVE | MAP_FIXED_NOREPLACE, -1, 0);
62+ void *p = mmap_fixed_noreplace((void *)addr, size, PROT_NONE,
63+ MAP_ANONYMOUS | MAP_PRIVATE |
64+ MAP_NORESERVE | MAP_FIXED_NOREPLACE, -1, 0);
65 int ret;
66
67 if (p == MAP_FAILED) {
68Index: qemu-8.2.1/linux-user/meson.build
69===================================================================
70--- qemu-8.2.1.orig/linux-user/meson.build
71+++ qemu-8.2.1/linux-user/meson.build
72@@ -14,6 +14,7 @@ linux_user_ss.add(files(
73 'linuxload.c',
74 'main.c',
75 'mmap.c',
76+ 'mmap-fixed.c',
77 'signal.c',
78 'strace.c',
79 'syscall.c',
80Index: qemu-8.2.1/linux-user/mmap-fixed.c
81===================================================================
82--- /dev/null
83+++ qemu-8.2.1/linux-user/mmap-fixed.c
84@@ -0,0 +1,63 @@
85+/*
86+ * Workaround for MAP_FIXED_NOREPLACE
87+ *
88+ * Copyright (c) 2024, Advanced Micro Devices, Inc.
89+ * Developed by Fred Konrad <fkonrad@amd.com>
90+ *
91+ * Permission is hereby granted, free of charge, to any person obtaining a copy
92+ * of this software and associated documentation files (the "Software"), to deal
93+ * in the Software without restriction, including without limitation the rights
94+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95+ * copies of the Software, and to permit persons to whom the Software is
96+ * furnished to do so, subject to the following conditions:
97+ *
98+ * The above copyright notice and this permission notice shall be included in
99+ * all copies or substantial portions of the Software.
100+ *
101+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
104+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107+ * THE SOFTWARE.
108+ */
109+
110+#include <sys/mman.h>
111+#include <errno.h>
112+
113+#ifndef MAP_FIXED_NOREPLACE
114+#include "mmap-fixed.h"
115+
116+void *mmap_fixed_noreplace(void *addr, size_t len, int prot, int flags,
117+ int fd, off_t offset)
118+{
119+ void *retaddr;
120+
121+ if (!(flags & MAP_FIXED_NOREPLACE)) {
122+ /* General case, use the regular mmap. */
123+ return mmap(addr, len, prot, flags, fd, offset);
124+ }
125+
126+ /* Since MAP_FIXED_NOREPLACE is not implemented, try to emulate it. */
127+ flags = flags & ~(MAP_FIXED_NOREPLACE | MAP_FIXED);
128+ retaddr = mmap(addr, len, prot, flags, fd, offset);
129+ if ((retaddr == addr) || (retaddr == MAP_FAILED)) {
130+ /*
131+ * Either the map worked and we get the good address so it can be
132+ * returned, or it failed and would have failed the same with
133+ * MAP_FIXED*, in which case return MAP_FAILED.
134+ */
135+ return retaddr;
136+ } else {
137+ /*
138+ * Page has been mapped but not at the requested address.. unmap it and
139+ * return EEXIST.
140+ */
141+ munmap(retaddr, len);
142+ errno = EEXIST;
143+ return MAP_FAILED;
144+ }
145+}
146+
147+#endif
148Index: qemu-8.2.1/linux-user/mmap-fixed.h
149===================================================================
150--- /dev/null
151+++ qemu-8.2.1/linux-user/mmap-fixed.h
152@@ -0,0 +1,39 @@
153+/*
154+ * Workaround for MAP_FIXED_NOREPLACE
155+ *
156+ * Copyright (c) 2024, Advanced Micro Devices, Inc.
157+ * Developed by Fred Konrad <fkonrad@amd.com>
158+ *
159+ * Permission is hereby granted, free of charge, to any person obtaining a copy
160+ * of this software and associated documentation files (the "Software"), to deal
161+ * in the Software without restriction, including without limitation the rights
162+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
163+ * copies of the Software, and to permit persons to whom the Software is
164+ * furnished to do so, subject to the following conditions:
165+ *
166+ * The above copyright notice and this permission notice shall be included in
167+ * all copies or substantial portions of the Software.
168+ *
169+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
170+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
172+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
173+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
174+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
175+ * THE SOFTWARE.
176+ */
177+
178+#ifndef MMAP_FIXED_H
179+#define MMAP_FIXED_H
180+
181+#ifndef MAP_FIXED_NOREPLACE
182+#define MAP_FIXED_NOREPLACE 0x100000
183+
184+void *mmap_fixed_noreplace(void *addr, size_t len, int prot, int flags,
185+ int fd, off_t offset);
186+
187+#else /* MAP_FIXED_NOREPLACE */
188+#define mmap_fixed_noreplace mmap
189+#endif /* MAP_FIXED_NOREPLACE */
190+
191+#endif /* MMAP_FIXED_H */
192Index: qemu-8.2.1/linux-user/mmap.c
193===================================================================
194--- qemu-8.2.1.orig/linux-user/mmap.c
195+++ qemu-8.2.1/linux-user/mmap.c
196@@ -25,6 +25,7 @@
197 #include "user-mmap.h"
198 #include "target_mman.h"
199 #include "qemu/interval-tree.h"
200+#include "mmap-fixed.h"
201
202 #ifdef TARGET_ARM
203 #include "target/arm/cpu-features.h"
204@@ -273,7 +274,7 @@ int target_mprotect(abi_ulong start, abi
205 static int do_munmap(void *addr, size_t len)
206 {
207 if (reserved_va) {
208- void *ptr = mmap(addr, len, PROT_NONE,
209+ void *ptr = mmap_fixed_noreplace(addr, len, PROT_NONE,
210 MAP_FIXED | MAP_ANONYMOUS
211 | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
212 return ptr == addr ? 0 : -1;
213@@ -319,9 +320,9 @@ static bool mmap_frag(abi_ulong real_sta
214 * outside of the fragment we need to map. Allocate a new host
215 * page to cover, discarding whatever else may have been present.
216 */
217- void *p = mmap(host_start, qemu_host_page_size,
218- target_to_host_prot(prot),
219- flags | MAP_ANONYMOUS, -1, 0);
220+ void *p = mmap_fixed_noreplace(host_start, qemu_host_page_size,
221+ target_to_host_prot(prot),
222+ flags | MAP_ANONYMOUS, -1, 0);
223 if (p != host_start) {
224 if (p != MAP_FAILED) {
225 munmap(p, qemu_host_page_size);
226@@ -420,8 +421,9 @@ abi_ulong mmap_find_vma(abi_ulong start,
227 * - mremap() with MREMAP_FIXED flag
228 * - shmat() with SHM_REMAP flag
229 */
230- ptr = mmap(g2h_untagged(addr), size, PROT_NONE,
231- MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
232+ ptr = mmap_fixed_noreplace(g2h_untagged(addr), size, PROT_NONE,
233+ MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE,
234+ -1, 0);
235
236 /* ENOMEM, if host address space has no memory */
237 if (ptr == MAP_FAILED) {
238@@ -615,16 +617,16 @@ abi_long target_mmap(abi_ulong start, ab
239 * especially important if qemu_host_page_size >
240 * qemu_real_host_page_size.
241 */
242- p = mmap(g2h_untagged(start), host_len, host_prot,
243- flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
244+ p = mmap_fixed_noreplace(g2h_untagged(start), host_len, host_prot,
245+ flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
246 if (p == MAP_FAILED) {
247 goto fail;
248 }
249 /* update start so that it points to the file position at 'offset' */
250 host_start = (uintptr_t)p;
251 if (!(flags & MAP_ANONYMOUS)) {
252- p = mmap(g2h_untagged(start), len, host_prot,
253- flags | MAP_FIXED, fd, host_offset);
254+ p = mmap_fixed_noreplace(g2h_untagged(start), len, host_prot,
255+ flags | MAP_FIXED, fd, host_offset);
256 if (p == MAP_FAILED) {
257 munmap(g2h_untagged(start), host_len);
258 goto fail;
259@@ -749,8 +751,9 @@ abi_long target_mmap(abi_ulong start, ab
260 len1 = real_last - real_start + 1;
261 want_p = g2h_untagged(real_start);
262
263- p = mmap(want_p, len1, target_to_host_prot(target_prot),
264- flags, fd, offset1);
265+ p = mmap_fixed_noreplace(want_p, len1,
266+ target_to_host_prot(target_prot),
267+ flags, fd, offset1);
268 if (p != want_p) {
269 if (p != MAP_FAILED) {
270 munmap(p, len1);
271Index: qemu-8.2.1/linux-user/syscall.c
272===================================================================
273--- qemu-8.2.1.orig/linux-user/syscall.c
274+++ qemu-8.2.1/linux-user/syscall.c
275@@ -145,6 +145,7 @@
276 #include "qapi/error.h"
277 #include "fd-trans.h"
278 #include "cpu_loop-common.h"
279+#include "mmap-fixed.h"
280
281 #ifndef CLONE_IO
282 #define CLONE_IO 0x80000000 /* Clone io context */
diff --git a/meta/recipes-devtools/qemu/qemu/0012-linux-user-workaround-for-missing-MAP_SHARED_VALIDAT.patch b/meta/recipes-devtools/qemu/qemu/0012-linux-user-workaround-for-missing-MAP_SHARED_VALIDAT.patch
new file mode 100644
index 0000000000..48034a4680
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0012-linux-user-workaround-for-missing-MAP_SHARED_VALIDAT.patch
@@ -0,0 +1,51 @@
1From 5c73e53997df800a742f9cd7355f3045861984bb Mon Sep 17 00:00:00 2001
2From: Frederic Konrad <fkonrad@amd.com>
3Date: Thu, 18 Jan 2024 10:43:44 +0000
4Subject: [PATCH 2/2] linux-user/*: workaround for missing MAP_SHARED_VALIDATE
5
6QEMU v8.1.0 recently requires MAP_SHARED_VALIDATE flags implementation for mmap.
7
8This is missing from the Ubuntu 18.04 compiler but looks like to be in the
9kernel source.
10
11Signed-off-by: Frederic Konrad <fkonrad@amd.com>
12Signed-off-by: Francisco Iglesias <francisco.iglesias@amd.com>
13
14Upstream-Status: Inappropriate [OE specific]
15
16The upstream only supports the last two major releases of an OS. The ones
17they have declared all have kernel 4.17 or newer.
18
19See:
20https://xilinx.slack.com/archives/D04G2647CTV/p1705074697942019
21
22https://www.qemu.org/docs/master/about/build-platforms.html
23
24 The project aims to support the most recent major version at all times for up
25 to five years after its initial release. Support for the previous major
26 version will be dropped 2 years after the new major version is released or
27 when the vendor itself drops support, whichever comes first.
28
29Signed-off-by: Mark Hatle <mark.hatle@amd.com>
30---
31 linux-user/mmap-fixed.h | 4 ++++
32 1 file changed, 4 insertions(+)
33
34diff --git a/linux-user/mmap-fixed.h b/linux-user/mmap-fixed.h
35index ef6eef5114..ec86586c1f 100644
36--- a/linux-user/mmap-fixed.h
37+++ b/linux-user/mmap-fixed.h
38@@ -26,6 +26,10 @@
39 #ifndef MMAP_FIXED_H
40 #define MMAP_FIXED_H
41
42+#ifndef MAP_SHARED_VALIDATE
43+#define MAP_SHARED_VALIDATE 0x03
44+#endif
45+
46 #ifndef MAP_FIXED_NOREPLACE
47 #define MAP_FIXED_NOREPLACE 0x100000
48
49--
502.34.1
51
diff --git a/meta/recipes-devtools/qemu/qemu/4a8579ad8629b57a43daa62e46cc7af6e1078116.patch b/meta/recipes-devtools/qemu/qemu/4a8579ad8629b57a43daa62e46cc7af6e1078116.patch
new file mode 100644
index 0000000000..5ad859ebe6
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/4a8579ad8629b57a43daa62e46cc7af6e1078116.patch
@@ -0,0 +1,60 @@
1From 4a8579ad8629b57a43daa62e46cc7af6e1078116 Mon Sep 17 00:00:00 2001
2From: Richard Henderson <richard.henderson@linaro.org>
3Date: Tue, 13 Feb 2024 10:20:27 -1000
4Subject: [PATCH] linux-user: Split out do_munmap
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Upstream-Status: Submitted [https://gitlab.com/rth7680/qemu/-/commit/4a8579ad8629b57a43daa62e46cc7af6e1078116]
10
11Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13---
14 linux-user/mmap.c | 23 ++++++++++++++++-------
15 1 file changed, 16 insertions(+), 7 deletions(-)
16
17diff --git a/linux-user/mmap.c b/linux-user/mmap.c
18index 1bbfeb25b14..8ebcca44444 100644
19--- a/linux-user/mmap.c
20+++ b/linux-user/mmap.c
21@@ -267,6 +267,21 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
22 return ret;
23 }
24
25+/*
26+ * Perform munmap on behalf of the target, with host parameters.
27+ * If reserved_va, we must replace the memory reservation.
28+ */
29+static int do_munmap(void *addr, size_t len)
30+{
31+ if (reserved_va) {
32+ void *ptr = mmap(addr, len, PROT_NONE,
33+ MAP_FIXED | MAP_ANONYMOUS
34+ | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
35+ return ptr == addr ? 0 : -1;
36+ }
37+ return munmap(addr, len);
38+}
39+
40 /* map an incomplete host page */
41 static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last,
42 int prot, int flags, int fd, off_t offset)
43@@ -854,13 +869,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
44 real_len = real_last - real_start + 1;
45 host_start = g2h_untagged(real_start);
46
47- if (reserved_va) {
48- void *ptr = mmap(host_start, real_len, PROT_NONE,
49- MAP_FIXED | MAP_ANONYMOUS
50- | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
51- return ptr == host_start ? 0 : -1;
52- }
53- return munmap(host_start, real_len);
54+ return do_munmap(host_start, real_len);
55 }
56
57 int target_munmap(abi_ulong start, abi_ulong len)
58--
59GitLab
60
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2023-6683.patch b/meta/recipes-devtools/qemu/qemu/CVE-2023-6683.patch
new file mode 100644
index 0000000000..732cb6af18
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/CVE-2023-6683.patch
@@ -0,0 +1,91 @@
1From 405484b29f6548c7b86549b0f961b906337aa68a Mon Sep 17 00:00:00 2001
2From: Fiona Ebner <f.ebner@proxmox.com>
3Date: Wed, 24 Jan 2024 11:57:48 +0100
4Subject: [PATCH] ui/clipboard: mark type as not available when there is no
5 data
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10With VNC, a client can send a non-extended VNC_MSG_CLIENT_CUT_TEXT
11message with len=0. In qemu_clipboard_set_data(), the clipboard info
12will be updated setting data to NULL (because g_memdup(data, size)
13returns NULL when size is 0). If the client does not set the
14VNC_ENCODING_CLIPBOARD_EXT feature when setting up the encodings, then
15the 'request' callback for the clipboard peer is not initialized.
16Later, because data is NULL, qemu_clipboard_request() can be reached
17via vdagent_chr_write() and vdagent_clipboard_recv_request() and
18there, the clipboard owner's 'request' callback will be attempted to
19be called, but that is a NULL pointer.
20
21In particular, this can happen when using the KRDC (22.12.3) VNC
22client.
23
24Another scenario leading to the same issue is with two clients (say
25noVNC and KRDC):
26
27The noVNC client sets the extension VNC_FEATURE_CLIPBOARD_EXT and
28initializes its cbpeer.
29
30The KRDC client does not, but triggers a vnc_client_cut_text() (note
31it's not the _ext variant)). There, a new clipboard info with it as
32the 'owner' is created and via qemu_clipboard_set_data() is called,
33which in turn calls qemu_clipboard_update() with that info.
34
35In qemu_clipboard_update(), the notifier for the noVNC client will be
36called, i.e. vnc_clipboard_notify() and also set vs->cbinfo for the
37noVNC client. The 'owner' in that clipboard info is the clipboard peer
38for the KRDC client, which did not initialize the 'request' function.
39That sounds correct to me, it is the owner of that clipboard info.
40
41Then when noVNC sends a VNC_MSG_CLIENT_CUT_TEXT message (it did set
42the VNC_FEATURE_CLIPBOARD_EXT feature correctly, so a check for it
43passes), that clipboard info is passed to qemu_clipboard_request() and
44the original segfault still happens.
45
46Fix the issue by handling updates with size 0 differently. In
47particular, mark in the clipboard info that the type is not available.
48
49While at it, switch to g_memdup2(), because g_memdup() is deprecated.
50
51Cc: qemu-stable@nongnu.org
52Fixes: CVE-2023-6683
53Reported-by: Markus Frank <m.frank@proxmox.com>
54Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
55Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
56Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
57Tested-by: Markus Frank <m.frank@proxmox.com>
58Message-ID: <20240124105749.204610-1-f.ebner@proxmox.com>
59
60CVE: CVE-2023-6683
61
62Upstream-Status: Backport [https://github.com/qemu/qemu/commit/405484b29f6548c7b86549b0f961b906337aa68a]
63Signed-off-by: Simone Weiß <simone.p.weiss@posteo.com>
64
65---
66 ui/clipboard.c | 12 +++++++++---
67 1 file changed, 9 insertions(+), 3 deletions(-)
68
69diff --git a/ui/clipboard.c b/ui/clipboard.c
70index 3d14bffaf80f..b3f6fa3c9e1f 100644
71--- a/ui/clipboard.c
72+++ b/ui/clipboard.c
73@@ -163,9 +163,15 @@ void qemu_clipboard_set_data(QemuClipboardPeer *peer,
74 }
75
76 g_free(info->types[type].data);
77- info->types[type].data = g_memdup(data, size);
78- info->types[type].size = size;
79- info->types[type].available = true;
80+ if (size) {
81+ info->types[type].data = g_memdup2(data, size);
82+ info->types[type].size = size;
83+ info->types[type].available = true;
84+ } else {
85+ info->types[type].data = NULL;
86+ info->types[type].size = 0;
87+ info->types[type].available = false;
88+ }
89
90 if (update) {
91 qemu_clipboard_update(info);
diff --git a/meta/recipes-devtools/qemu/qemu/cross.patch b/meta/recipes-devtools/qemu/qemu/cross.patch
deleted file mode 100644
index 438c1ad086..0000000000
--- a/meta/recipes-devtools/qemu/qemu/cross.patch
+++ /dev/null
@@ -1,30 +0,0 @@
1We need to be able to trigger configure's cross code but we don't want
2to set cross_prefix as it does other things we don't want. Patch things
3so we can do what we need in the target config case.
4
5Upstream-Status: Inappropriate [may be rewritten in a way upstream may accept?]
6Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
7
8
9Index: qemu-5.2.0/configure
10===================================================================
11--- qemu-5.2.0.orig/configure
12+++ qemu-5.2.0/configure
13@@ -6973,7 +6973,6 @@ if has $sdl2_config; then
14 fi
15 echo "strip = [$(meson_quote $strip)]" >> $cross
16 echo "windres = [$(meson_quote $windres)]" >> $cross
17-if test -n "$cross_prefix"; then
18 cross_arg="--cross-file config-meson.cross"
19 echo "[host_machine]" >> $cross
20 if test "$mingw32" = "yes" ; then
21@@ -6999,9 +6998,6 @@ if test -n "$cross_prefix"; then
22 else
23 echo "endian = 'little'" >> $cross
24 fi
25-else
26- cross_arg="--native-file config-meson.cross"
27-fi
28 mv $cross config-meson.cross
29
30 rm -rf meson-private meson-info meson-logs
diff --git a/meta/recipes-devtools/qemu/qemu/determinism.patch b/meta/recipes-devtools/qemu/qemu/determinism.patch
deleted file mode 100644
index cb1c907777..0000000000
--- a/meta/recipes-devtools/qemu/qemu/determinism.patch
+++ /dev/null
@@ -1,41 +0,0 @@
1When sources are included within debug information, a couple of areas of the
2qemu build are not reproducible due to either full buildpaths or timestamps.
3
4Replace the full paths with relative ones. I couldn't figure out how to get
5meson to pass relative paths but we can fix that in the script.
6
7For the keymaps, omit the timestamps as they don't matter to us.
8
9Upstream-Status: Pending [some version of all/part of this may be accepted]
10RP 2021/3/1
11
12Index: qemu-5.2.0/scripts/decodetree.py
13===================================================================
14--- qemu-5.2.0.orig/scripts/decodetree.py
15+++ qemu-5.2.0/scripts/decodetree.py
16@@ -1303,8 +1303,8 @@ def main():
17 toppat = ExcMultiPattern(0)
18
19 for filename in args:
20- input_file = filename
21- f = open(filename, 'r')
22+ input_file = os.path.relpath(filename)
23+ f = open(input_file, 'r')
24 parse_file(f, toppat)
25 f.close()
26
27Index: qemu-5.2.0/ui/keycodemapdb/tools/keymap-gen
28===================================================================
29--- qemu-5.2.0.orig/ui/keycodemapdb/tools/keymap-gen
30+++ qemu-5.2.0/ui/keycodemapdb/tools/keymap-gen
31@@ -317,9 +317,8 @@ class LanguageGenerator(object):
32 raise NotImplementedError()
33
34 def generate_header(self, database, args):
35- today = time.strftime("%Y-%m-%d %H:%M")
36 self._boilerplate([
37- "This file is auto-generated from keymaps.csv on %s" % today,
38+ "This file is auto-generated from keymaps.csv",
39 "Database checksum sha256(%s)" % database.mapchecksum,
40 "To re-generate, run:",
41 " %s" % args,
diff --git a/meta/recipes-devtools/qemu/qemu/fixedmeson.patch b/meta/recipes-devtools/qemu/qemu/fixedmeson.patch
new file mode 100644
index 0000000000..9047f66dc3
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/fixedmeson.patch
@@ -0,0 +1,20 @@
1Upstream-Status: Inappropriate [workaround, would need a real fix for upstream]
2
3Index: qemu-8.2.0/configure
4===================================================================
5--- qemu-8.2.0.orig/configure
6+++ qemu-8.2.0/configure
7@@ -955,12 +955,7 @@ fi
8 $mkvenv ensuregroup --dir "${source_path}/python/wheels" \
9 ${source_path}/pythondeps.toml meson || exit 1
10
11-# At this point, we expect Meson to be installed and available.
12-# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
13-# We ignore PATH completely here: we want to use the venv's Meson
14-# *exclusively*.
15-
16-meson="$(cd pyvenv/bin; pwd)/meson"
17+meson=`which meson`
18
19 # Conditionally ensure Sphinx is installed.
20
diff --git a/meta/recipes-devtools/qemu/qemu/mingwfix.patch b/meta/recipes-devtools/qemu/qemu/mingwfix.patch
deleted file mode 100644
index 8d76cef638..0000000000
--- a/meta/recipes-devtools/qemu/qemu/mingwfix.patch
+++ /dev/null
@@ -1,21 +0,0 @@
1OE assumes that mingw files are in a unix like file layout. The
2'flattening' done by configure in qemu for mingw32 breaks things
3for us. We are discussing with upstream but for now, hack this to
4disable it and use the unix like layout everywhere.
5
6Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
7Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01073.html]
8
9Index: qemu-5.2.0/configure
10===================================================================
11--- qemu-5.2.0.orig/configure
12+++ qemu-5.2.0/configure
13@@ -1541,7 +1541,7 @@ libdir="${libdir:-$prefix/lib}"
14 libexecdir="${libexecdir:-$prefix/libexec}"
15 includedir="${includedir:-$prefix/include}"
16
17-if test "$mingw32" = "yes" ; then
18+if test "$mingw32" = "dontwantthis" ; then
19 mandir="$prefix"
20 datadir="$prefix"
21 docdir="$prefix"
diff --git a/meta/recipes-devtools/qemu/qemu/mmap.patch b/meta/recipes-devtools/qemu/qemu/mmap.patch
deleted file mode 100644
index edd9734f30..0000000000
--- a/meta/recipes-devtools/qemu/qemu/mmap.patch
+++ /dev/null
@@ -1,29 +0,0 @@
1If mremap() is called without the MREMAP_MAYMOVE flag with a start address
2just before the end of memory (reserved_va) where new_size would exceed
3GUEST_ADD_MAX, the assert(end - 1 <= GUEST_ADDR_MAX) in page_set_flags()
4would trigger.
5
6Add an extra guard to the guest_range_valid() checks to prevent this and
7avoid asserting binaries when reserved_va is set.
8
9This meant a test case now gives the same behaviour regardless of whether
10reserved_va is set or not.
11
12Upstream-Status: Backport [https://github.com/qemu/qemu/commit/ccc5ccc17f8cfbfd87d9aede5d12a2d47c56e712]
13Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
14
15Index: qemu-5.2.0/linux-user/mmap.c
16===================================================================
17--- qemu-5.2.0.orig/linux-user/mmap.c
18+++ qemu-5.2.0/linux-user/mmap.c
19@@ -727,7 +727,9 @@ abi_long target_mremap(abi_ulong old_add
20
21 if (!guest_range_valid(old_addr, old_size) ||
22 ((flags & MREMAP_FIXED) &&
23- !guest_range_valid(new_addr, new_size))) {
24+ !guest_range_valid(new_addr, new_size)) ||
25+ ((flags & MREMAP_MAYMOVE) == 0 &&
26+ !guest_range_valid(old_addr, new_size))) {
27 errno = ENOMEM;
28 return -1;
29 }
diff --git a/meta/recipes-devtools/qemu/qemu/no-pip.patch b/meta/recipes-devtools/qemu/qemu/no-pip.patch
new file mode 100644
index 0000000000..92b2edbe9f
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/no-pip.patch
@@ -0,0 +1,45 @@
1qemu: Ensure pip and the python venv aren't used for meson
2
3Qemu wants to use a supported python version and a specific meson version
4to "help" users and uses pip and creates a venv to do this. This is a nightmare
5for us. Our versions stay up to date and should be supported so we don't
6really need/want this wrapping. Tweak things to disable it.
7
8There was breakage from the wrapper shown by:
9
10bitbake qemu-system-native
11<add DISTRO_FEATURES:remove = "opengl" to local.conf>
12bitbake qemu-system-native -c configure
13
14which would crash. The issue is the change in configuration removes pieces
15from the sysroot but pyc files remainm as do pieces of pip which causes
16problems.
17
18Ideally we'd convince upstream to allow some way to disable the venv on
19the understanding that if/when it breaks, we keep the pieces. The patch
20as it stands is a workaround.
21
22Upstream-Status: Inappropriate [oe specific]
23Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
24
25Index: qemu-8.2.0/configure
26===================================================================
27--- qemu-8.2.0.orig/configure
28+++ qemu-8.2.0/configure
29@@ -937,7 +937,7 @@ python="$(command -v "$python")"
30 echo "python determined to be '$python'"
31 echo "python version: $($python --version)"
32
33-python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
34+python=python3
35 if test "$?" -ne 0 ; then
36 error_exit "python venv creation failed"
37 fi
38@@ -945,6 +945,7 @@ fi
39 # Suppress writing compiled files
40 python="$python -B"
41 mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
42+mkvenv=true
43
44 # Finish preparing the virtual environment using vendored .whl files
45
diff --git a/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.init b/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.init
new file mode 100644
index 0000000000..5ebaaddeae
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.init
@@ -0,0 +1,75 @@
1# SPDX-License-Identifier: GPL-2.0-only
2# Initially written by: Michael Tokarev <mjt@tls.msk.ru>
3# For QEMU Debian downstream package
4
5set -e
6
7. /etc/init.d/functions
8
9PATH=/sbin:/usr/sbin:/bin:/usr/bin
10DESC="QEMU Guest Agent"
11NAME=qemu-ga
12DAEMON=@bindir@/$NAME
13PIDFILE=/var/run/$NAME.pid
14
15# config
16DAEMON_ARGS=""
17# default transport
18TRANSPORT=virtio-serial:/dev/virtio-ports/org.qemu.guest_agent.0
19NO_START=0
20
21test ! -r /etc/default/qemu-guest-agent || . /etc/default/qemu-guest-agent
22test "$NO_START" = "0" || exit 0
23test -x "$DAEMON" || exit 0
24
25#
26# Function that checks whenever system has necessary environment
27# It also splits $TRANSPORT into $method and $path
28#
29do_check_transport() {
30 method=${TRANSPORT%%:*};
31 path=${TRANSPORT#*:}
32 case "$method" in
33 virtio-serial | isa-serial)
34 if [ ! -e "$path" ]; then
35 echo "$NAME: transport endpoint not found, not starting"
36 return 1
37 fi
38 ;;
39 esac
40}
41
42case "$1" in
43 start)
44 do_check_transport || exit 0
45 echo -n "Starting $DESC: "
46 start-stop-daemon -S -p $PIDFILE -x "$DAEMON" -- \
47 $DAEMON_ARGS -d -m "$method" -p "$path"
48 echo "$NAME."
49 ;;
50 stop)
51 echo -n "Stopping $DESC: "
52 start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
53 echo "$NAME."
54 ;;
55 status)
56 status "$DAEMON"
57 exit $?
58 ;;
59 restart|force-reload)
60 do_check_transport || exit 0
61 echo -n "Restarting $DESC: "
62 start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
63 sleep 1
64 start-stop-daemon -S -p $PIDFILE -x "$DAEMON" -- \
65 $DAEMON_ARGS -d -m "$method" -p "$path"
66 echo "$NAME."
67 ;;
68 *)
69 N=/etc/init.d/$NAME
70 echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
71 exit 1
72 ;;
73esac
74
75exit 0
diff --git a/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.udev b/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.udev
new file mode 100644
index 0000000000..47097057e3
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.udev
@@ -0,0 +1,2 @@
1SUBSYSTEM=="virtio-ports", ATTR{name}=="org.qemu.guest_agent.0", \
2 TAG+="systemd", ENV{SYSTEMD_WANTS}="qemu-guest-agent.service"