Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/files/, app-emulation/qemu/
Date: Sat, 04 Jun 2022 03:01:46
Message-Id: 1654311689.a2440aa2b4c8ceaf4195e30f6b4888ede061d8dd.sam@gentoo
1 commit: a2440aa2b4c8ceaf4195e30f6b4888ede061d8dd
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jun 4 02:59:28 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sat Jun 4 03:01:29 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a2440aa2
7
8 app-emulation/qemu: backport virtio-iscsi CPU usage fix; FORTIFY_SOURCE=3 fixes
9
10 - Backport virtio-iscsi CPU usage fix;
11 - Don't force -D_FORTIFY_SOURCE=2 (we patch it into toolchain so need to set it,
12 and by doing -U... -D...=2, it prevents usage of =3)
13 - Backport FORTIFY_SOURCE=3 crash fix
14
15 Closes: https://bugs.gentoo.org/849587
16 Closes: https://bugs.gentoo.org/849500
17 Signed-off-by: Sam James <sam <AT> gentoo.org>
18
19 .../qemu-7.0.0-pci-overflow-fortify-source-3.patch | 94 +++++++++++
20 .../qemu/files/qemu-7.0.0-virtio-scsi-fixes.patch | 182 +++++++++++++++++++++
21 .../{qemu-9999.ebuild => qemu-7.0.0-r2.ebuild} | 38 +++--
22 app-emulation/qemu/qemu-9999.ebuild | 36 ++--
23 4 files changed, 322 insertions(+), 28 deletions(-)
24
25 diff --git a/app-emulation/qemu/files/qemu-7.0.0-pci-overflow-fortify-source-3.patch b/app-emulation/qemu/files/qemu-7.0.0-pci-overflow-fortify-source-3.patch
26 new file mode 100644
27 index 000000000000..767f66243fcc
28 --- /dev/null
29 +++ b/app-emulation/qemu/files/qemu-7.0.0-pci-overflow-fortify-source-3.patch
30 @@ -0,0 +1,94 @@
31 +https://bugs.gentoo.org/849587
32 +https://bugzilla.opensuse.org/show_bug.cgi?id=1199924
33 +https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg06183.html
34 +
35 +From qemu-devel Tue May 31 11:47:07 2022
36 +From: Claudio Fontana <cfontana () suse ! de>
37 +Date: Tue, 31 May 2022 11:47:07 +0000
38 +To: qemu-devel
39 +Subject: [PATCH] pci: fix overflow in snprintf string formatting
40 +Message-Id: <20220531114707.18830-1-cfontana () suse ! de>
41 +X-MARC-Message: https://marc.info/?l=qemu-devel&m=165399772310578
42 +
43 +the code in pcibus_get_fw_dev_path contained the potential for a
44 +stack buffer overflow of 1 byte, potentially writing to the stack an
45 +extra NUL byte.
46 +
47 +This overflow could happen if the PCI slot is >= 0x10000000,
48 +and the PCI function is >= 0x10000000, due to the size parameter
49 +of snprintf being incorrectly calculated in the call:
50 +
51 + if (PCI_FUNC(d->devfn))
52 + snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
53 +
54 +since the off obtained from a previous call to snprintf is added
55 +instead of subtracted from the total available size of the buffer.
56 +
57 +Without the accurate size guard from snprintf, we end up writing in the
58 +worst case:
59 +
60 +name (32) + "@" (1) + SLOT (8) + "," (1) + FUNC (8) + term NUL (1) = 51 bytes
61 +
62 +In order to provide something more robust, replace all of the code in
63 +pcibus_get_fw_dev_path with a single call to g_strdup_printf,
64 +so there is no need to rely on manual calculations.
65 +
66 +Found by compiling QEMU with FORTIFY_SOURCE=3 as the error:
67 +
68 +*** buffer overflow detected ***: terminated
69 +
70 +Thread 1 "qemu-system-x86" received signal SIGABRT, Aborted.
71 +[Switching to Thread 0x7ffff642c380 (LWP 121307)]
72 +0x00007ffff71ff55c in __pthread_kill_implementation () from /lib64/libc.so.6
73 +(gdb) bt
74 + #0 0x00007ffff71ff55c in __pthread_kill_implementation () at /lib64/libc.so.6
75 + #1 0x00007ffff71ac6f6 in raise () at /lib64/libc.so.6
76 + #2 0x00007ffff7195814 in abort () at /lib64/libc.so.6
77 + #3 0x00007ffff71f279e in __libc_message () at /lib64/libc.so.6
78 + #4 0x00007ffff729767a in __fortify_fail () at /lib64/libc.so.6
79 + #5 0x00007ffff7295c36 in () at /lib64/libc.so.6
80 + #6 0x00007ffff72957f5 in __snprintf_chk () at /lib64/libc.so.6
81 + #7 0x0000555555b1c1fd in pcibus_get_fw_dev_path ()
82 + #8 0x0000555555f2bde4 in qdev_get_fw_dev_path_helper.constprop ()
83 + #9 0x0000555555f2bd86 in qdev_get_fw_dev_path_helper.constprop ()
84 + #10 0x00005555559a6e5d in get_boot_device_path ()
85 + #11 0x00005555559a712c in get_boot_devices_list ()
86 + #12 0x0000555555b1a3d0 in fw_cfg_machine_reset ()
87 + #13 0x0000555555bf4c2d in pc_machine_reset ()
88 + #14 0x0000555555c66988 in qemu_system_reset ()
89 + #15 0x0000555555a6dff6 in qdev_machine_creation_done ()
90 + #16 0x0000555555c79186 in qmp_x_exit_preconfig.part ()
91 + #17 0x0000555555c7b459 in qemu_init ()
92 + #18 0x0000555555960a29 in main ()
93 +
94 +Found-by: Dario Faggioli <Dario Faggioli <dfaggioli@××××.com>
95 +Found-by: Martin LiÅ¡ka <martin.liska@××××.com>
96 +Cc: qemu-stable@××××××.org
97 +Signed-off-by: Claudio Fontana <cfontana@××××.de>
98 +--- a/hw/pci/pci.c
99 ++++ b/hw/pci/pci.c
100 +@@ -2640,15 +2640,15 @@ static char *pci_dev_fw_name(DeviceState *dev, char *buf, int len)
101 + static char *pcibus_get_fw_dev_path(DeviceState *dev)
102 + {
103 + PCIDevice *d = (PCIDevice *)dev;
104 +- char path[50], name[33];
105 +- int off;
106 +-
107 +- off = snprintf(path, sizeof(path), "%s@%x",
108 +- pci_dev_fw_name(dev, name, sizeof name),
109 +- PCI_SLOT(d->devfn));
110 +- if (PCI_FUNC(d->devfn))
111 +- snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
112 +- return g_strdup(path);
113 ++ char name[33];
114 ++ int has_func = !!PCI_FUNC(d->devfn);
115 ++
116 ++ return g_strdup_printf("%s@%x%s%.*x",
117 ++ pci_dev_fw_name(dev, name, sizeof(name)),
118 ++ PCI_SLOT(d->devfn),
119 ++ has_func ? "," : "",
120 ++ has_func,
121 ++ PCI_FUNC(d->devfn));
122 + }
123 +
124 + static char *pcibus_get_dev_path(DeviceState *dev)
125
126 diff --git a/app-emulation/qemu/files/qemu-7.0.0-virtio-scsi-fixes.patch b/app-emulation/qemu/files/qemu-7.0.0-virtio-scsi-fixes.patch
127 new file mode 100644
128 index 000000000000..9ec6ede80896
129 --- /dev/null
130 +++ b/app-emulation/qemu/files/qemu-7.0.0-virtio-scsi-fixes.patch
131 @@ -0,0 +1,182 @@
132 +https://bugs.gentoo.org/849500
133 +https://gitlab.com/qemu-project/qemu/-/commit/2f743ef6366c2df4ef51ef3ae318138cdc0125ab.patch
134 +https://gitlab.com/qemu-project/qemu/-/commit/38738f7dbbda90fbc161757b7f4be35b52205552.patch
135 +
136 +From: Stefan Hajnoczi <stefanha@××××××.com>
137 +Date: Wed, 27 Apr 2022 15:35:36 +0100
138 +Subject: [PATCH] virtio-scsi: fix ctrl and event handler functions in
139 + dataplane mode
140 +
141 +Commit f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare
142 +virtio_scsi_handle_cmd for dataplane") prepared the virtio-scsi cmd
143 +virtqueue handler function to be used in both the dataplane and
144 +non-datpalane code paths.
145 +
146 +It failed to convert the ctrl and event virtqueue handler functions,
147 +which are not designed to be called from the dataplane code path but
148 +will be since the ioeventfd is set up for those virtqueues when
149 +dataplane starts.
150 +
151 +Convert the ctrl and event virtqueue handler functions now so they
152 +operate correctly when called from the dataplane code path. Avoid code
153 +duplication by extracting this code into a helper function.
154 +
155 +Fixes: f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare virtio_scsi_handle_cmd for dataplane")
156 +Signed-off-by: Stefan Hajnoczi <stefanha@××××××.com>
157 +Reviewed-by: Paolo Bonzini <pbonzini@××××××.com>
158 +Message-id: 20220427143541.119567-2-stefanha@××××××.com
159 +[Fixed s/by used/be used/ typo pointed out by Michael Tokarev
160 +<mjt@×××××××.ru>.
161 +--Stefan]
162 +Signed-off-by: Stefan Hajnoczi <stefanha@××××××.com>
163 +--- a/hw/scsi/virtio-scsi.c
164 ++++ b/hw/scsi/virtio-scsi.c
165 +@@ -472,16 +472,32 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq)
166 + return progress;
167 + }
168 +
169 ++/*
170 ++ * If dataplane is configured but not yet started, do so now and return true on
171 ++ * success.
172 ++ *
173 ++ * Dataplane is started by the core virtio code but virtqueue handler functions
174 ++ * can also be invoked when a guest kicks before DRIVER_OK, so this helper
175 ++ * function helps us deal with manually starting ioeventfd in that case.
176 ++ */
177 ++static bool virtio_scsi_defer_to_dataplane(VirtIOSCSI *s)
178 ++{
179 ++ if (!s->ctx || s->dataplane_started) {
180 ++ return false;
181 ++ }
182 ++
183 ++ virtio_device_start_ioeventfd(&s->parent_obj.parent_obj);
184 ++ return !s->dataplane_fenced;
185 ++}
186 ++
187 + static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
188 + {
189 + VirtIOSCSI *s = (VirtIOSCSI *)vdev;
190 +
191 +- if (s->ctx) {
192 +- virtio_device_start_ioeventfd(vdev);
193 +- if (!s->dataplane_fenced) {
194 +- return;
195 +- }
196 ++ if (virtio_scsi_defer_to_dataplane(s)) {
197 ++ return;
198 + }
199 ++
200 + virtio_scsi_acquire(s);
201 + virtio_scsi_handle_ctrl_vq(s, vq);
202 + virtio_scsi_release(s);
203 +@@ -720,12 +736,10 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
204 + /* use non-QOM casts in the data path */
205 + VirtIOSCSI *s = (VirtIOSCSI *)vdev;
206 +
207 +- if (s->ctx && !s->dataplane_started) {
208 +- virtio_device_start_ioeventfd(vdev);
209 +- if (!s->dataplane_fenced) {
210 +- return;
211 +- }
212 ++ if (virtio_scsi_defer_to_dataplane(s)) {
213 ++ return;
214 + }
215 ++
216 + virtio_scsi_acquire(s);
217 + virtio_scsi_handle_cmd_vq(s, vq);
218 + virtio_scsi_release(s);
219 +@@ -855,12 +869,10 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
220 + {
221 + VirtIOSCSI *s = VIRTIO_SCSI(vdev);
222 +
223 +- if (s->ctx) {
224 +- virtio_device_start_ioeventfd(vdev);
225 +- if (!s->dataplane_fenced) {
226 +- return;
227 +- }
228 ++ if (virtio_scsi_defer_to_dataplane(s)) {
229 ++ return;
230 + }
231 ++
232 + virtio_scsi_acquire(s);
233 + virtio_scsi_handle_event_vq(s, vq);
234 + virtio_scsi_release(s);
235 +GitLab
236 +
237 +From: Stefan Hajnoczi <stefanha@××××××.com>
238 +Date: Wed, 27 Apr 2022 15:35:37 +0100
239 +Subject: [PATCH] virtio-scsi: don't waste CPU polling the event virtqueue
240 +
241 +The virtio-scsi event virtqueue is not emptied by its handler function.
242 +This is typical for rx virtqueues where the device uses buffers when
243 +some event occurs (e.g. a packet is received, an error condition
244 +happens, etc).
245 +
246 +Polling non-empty virtqueues wastes CPU cycles. We are not waiting for
247 +new buffers to become available, we are waiting for an event to occur,
248 +so it's a misuse of CPU resources to poll for buffers.
249 +
250 +Introduce the new virtio_queue_aio_attach_host_notifier_no_poll() API,
251 +which is identical to virtio_queue_aio_attach_host_notifier() except
252 +that it does not poll the virtqueue.
253 +
254 +Before this patch the following command-line consumed 100% CPU in the
255 +IOThread polling and calling virtio_scsi_handle_event():
256 +
257 + $ qemu-system-x86_64 -M accel=kvm -m 1G -cpu host \
258 + --object iothread,id=iothread0 \
259 + --device virtio-scsi-pci,iothread=iothread0 \
260 + --blockdev file,filename=test.img,aio=native,cache.direct=on,node-name=drive0 \
261 + --device scsi-hd,drive=drive0
262 +
263 +After this patch CPU is no longer wasted.
264 +
265 +Reported-by: Nir Soffer <nsoffer@××××××.com>
266 +Signed-off-by: Stefan Hajnoczi <stefanha@××××××.com>
267 +Tested-by: Nir Soffer <nsoffer@××××××.com>
268 +Message-id: 20220427143541.119567-3-stefanha@××××××.com
269 +Signed-off-by: Stefan Hajnoczi <stefanha@××××××.com>
270 +--- a/hw/scsi/virtio-scsi-dataplane.c
271 ++++ b/hw/scsi/virtio-scsi-dataplane.c
272 +@@ -138,7 +138,7 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev)
273 +
274 + aio_context_acquire(s->ctx);
275 + virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, s->ctx);
276 +- virtio_queue_aio_attach_host_notifier(vs->event_vq, s->ctx);
277 ++ virtio_queue_aio_attach_host_notifier_no_poll(vs->event_vq, s->ctx);
278 +
279 + for (i = 0; i < vs->conf.num_queues; i++) {
280 + virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], s->ctx);
281 +--- a/hw/virtio/virtio.c
282 ++++ b/hw/virtio/virtio.c
283 +@@ -3534,6 +3534,19 @@ void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx)
284 + virtio_queue_host_notifier_aio_poll_end);
285 + }
286 +
287 ++/*
288 ++ * Same as virtio_queue_aio_attach_host_notifier() but without polling. Use
289 ++ * this for rx virtqueues and similar cases where the virtqueue handler
290 ++ * function does not pop all elements. When the virtqueue is left non-empty
291 ++ * polling consumes CPU cycles and should not be used.
292 ++ */
293 ++void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioContext *ctx)
294 ++{
295 ++ aio_set_event_notifier(ctx, &vq->host_notifier, true,
296 ++ virtio_queue_host_notifier_read,
297 ++ NULL, NULL);
298 ++}
299 ++
300 + void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx)
301 + {
302 + aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, NULL);
303 +--- a/include/hw/virtio/virtio.h
304 ++++ b/include/hw/virtio/virtio.h
305 +@@ -317,6 +317,7 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
306 + void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled);
307 + void virtio_queue_host_notifier_read(EventNotifier *n);
308 + void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx);
309 ++void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioContext *ctx);
310 + void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
311 + VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
312 + VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
313 +GitLab
314
315 diff --git a/app-emulation/qemu/qemu-9999.ebuild b/app-emulation/qemu/qemu-7.0.0-r2.ebuild
316 similarity index 96%
317 copy from app-emulation/qemu/qemu-9999.ebuild
318 copy to app-emulation/qemu/qemu-7.0.0-r2.ebuild
319 index 23c0cb89295f..f048b6385812 100644
320 --- a/app-emulation/qemu/qemu-9999.ebuild
321 +++ b/app-emulation/qemu/qemu-7.0.0-r2.ebuild
322 @@ -6,12 +6,12 @@ EAPI=8
323 PYTHON_COMPAT=( python3_{8,9,10} )
324 PYTHON_REQ_USE="ncurses,readline"
325
326 -FIRMWARE_ABI_VERSION="6.2.0"
327 +FIRMWARE_ABI_VERSION="7.0.0"
328
329 inherit linux-info toolchain-funcs python-r1 udev fcaps readme.gentoo-r1 \
330 pax-utils xdg-utils
331
332 -if [[ ${PV} = *9999* ]]; then
333 +if [[ ${PV} == *9999* ]]; then
334 EGIT_REPO_URI="https://gitlab.com/qemu-project/qemu.git/"
335 EGIT_SUBMODULES=(
336 meson
337 @@ -22,8 +22,10 @@ if [[ ${PV} = *9999* ]]; then
338 inherit git-r3
339 SRC_URI=""
340 else
341 - SRC_URI="https://download.qemu.org/${P}.tar.xz"
342 + MY_P="${PN}-${PV/_rc/-rc}"
343 + SRC_URI="https://download.qemu.org/${MY_P}.tar.xz"
344 KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86"
345 + S="${WORKDIR}/${MY_P}"
346 fi
347
348 DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
349 @@ -147,7 +149,7 @@ SOFTMMU_TOOLS_DEPEND="
350 capstone? ( dev-libs/capstone:= )
351 caps? ( sys-libs/libcap-ng[static-libs(+)] )
352 curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
353 - fdt? ( >=sys-apps/dtc-1.5.0[static-libs(+)] )
354 + fdt? ( >=sys-apps/dtc-1.5.1[static-libs(+)] )
355 fuse? ( >=sys-fs/fuse-3.1:3[static-libs(+)] )
356 glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
357 gnutls? (
358 @@ -163,7 +165,7 @@ SOFTMMU_TOOLS_DEPEND="
359 io-uring? ( sys-libs/liburing:=[static-libs(+)] )
360 jack? ( virtual/jack )
361 jemalloc? ( dev-libs/jemalloc )
362 - jpeg? ( virtual/jpeg:0=[static-libs(+)] )
363 + jpeg? ( media-libs/libjpeg-turbo:=[static-libs(+)] )
364 lzo? ( dev-libs/lzo:2[static-libs(+)] )
365 multipath? ( sys-fs/multipath-tools )
366 ncurses? (
367 @@ -277,6 +279,8 @@ PATCHES=(
368 "${FILESDIR}"/${PN}-6.0.0-make.patch
369 "${FILESDIR}"/${PN}-6.1.0-strings.patch
370 "${FILESDIR}"/${PN}-7.0.0-also-build-virtfs-proxy-helper.patch
371 + "${FILESDIR}"/${P}-virtio-scsi-fixes.patch
372 + "${FILESDIR}"/${P}-pci-overflow-fortify-source-3.patch
373 )
374
375 QA_PREBUILT="
376 @@ -416,6 +420,11 @@ src_prepare() {
377 # Verbose builds
378 MAKEOPTS+=" V=1"
379
380 + # We already force -D_FORTIFY_SOURCE=2 (or 3) in our toolchain, but
381 + # this setting (-U then -D..=2) will prevent us from trying out 3, so
382 + # drop it. No change to level of protection b/c we patch our toolchain.
383 + sed -i -e 's/-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2//' configure || die
384 +
385 # Remove bundled copy of libfdt
386 rm -r dtc || die
387 }
388 @@ -430,7 +439,7 @@ qemu_src_configure() {
389 local buildtype=$1
390 local builddir="${S}/${buildtype}-build"
391
392 - mkdir "${builddir}"
393 + mkdir "${builddir}" || die
394
395 local conf_opts=(
396 --prefix=/usr
397 @@ -466,6 +475,7 @@ qemu_src_configure() {
398 --cc="$(tc-getCC)"
399 --cxx="$(tc-getCXX)"
400 --host-cc="$(tc-getBUILD_CC)"
401 +
402 $(use_enable alsa)
403 $(use_enable debug debug-info)
404 $(use_enable debug debug-tcg)
405 @@ -671,22 +681,22 @@ src_configure() {
406
407 src_compile() {
408 if [[ -n ${user_targets} ]]; then
409 - cd "${S}/user-build"
410 + cd "${S}/user-build" || die
411 default
412 fi
413
414 if [[ -n ${softmmu_targets} ]]; then
415 - cd "${S}/softmmu-build"
416 + cd "${S}/softmmu-build" || die
417 default
418 fi
419
420 - cd "${S}/tools-build"
421 + cd "${S}/tools-build" || die
422 default
423 }
424
425 src_test() {
426 if [[ -n ${softmmu_targets} ]]; then
427 - cd "${S}/softmmu-build"
428 + cd "${S}/softmmu-build" || die
429 pax-mark m */qemu-system-* #515550
430 emake check
431 fi
432 @@ -783,19 +793,19 @@ src_install() {
433 fi
434 fi
435
436 - cd "${S}/tools-build"
437 + cd "${S}/tools-build" || die
438 emake DESTDIR="${ED}" install
439
440 # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
441 - pushd "${ED}"/usr/bin >/dev/null
442 + pushd "${ED}"/usr/bin >/dev/null || die
443 pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
444 - popd >/dev/null
445 + popd >/dev/null || die
446
447 # Install config file example for qemu-bridge-helper
448 insinto "/etc/qemu"
449 doins "${FILESDIR}/bridge.conf"
450
451 - cd "${S}"
452 + cd "${S}" || die
453 dodoc MAINTAINERS docs/specs/pci-ids.txt
454 newdoc pc-bios/README README.pc-bios
455
456
457 diff --git a/app-emulation/qemu/qemu-9999.ebuild b/app-emulation/qemu/qemu-9999.ebuild
458 index 23c0cb89295f..b9d896ec56bc 100644
459 --- a/app-emulation/qemu/qemu-9999.ebuild
460 +++ b/app-emulation/qemu/qemu-9999.ebuild
461 @@ -6,12 +6,12 @@ EAPI=8
462 PYTHON_COMPAT=( python3_{8,9,10} )
463 PYTHON_REQ_USE="ncurses,readline"
464
465 -FIRMWARE_ABI_VERSION="6.2.0"
466 +FIRMWARE_ABI_VERSION="7.0.0"
467
468 inherit linux-info toolchain-funcs python-r1 udev fcaps readme.gentoo-r1 \
469 pax-utils xdg-utils
470
471 -if [[ ${PV} = *9999* ]]; then
472 +if [[ ${PV} == *9999* ]]; then
473 EGIT_REPO_URI="https://gitlab.com/qemu-project/qemu.git/"
474 EGIT_SUBMODULES=(
475 meson
476 @@ -22,8 +22,10 @@ if [[ ${PV} = *9999* ]]; then
477 inherit git-r3
478 SRC_URI=""
479 else
480 - SRC_URI="https://download.qemu.org/${P}.tar.xz"
481 + MY_P="${PN}-${PV/_rc/-rc}"
482 + SRC_URI="https://download.qemu.org/${MY_P}.tar.xz"
483 KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86"
484 + S="${WORKDIR}/${MY_P}"
485 fi
486
487 DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
488 @@ -147,7 +149,7 @@ SOFTMMU_TOOLS_DEPEND="
489 capstone? ( dev-libs/capstone:= )
490 caps? ( sys-libs/libcap-ng[static-libs(+)] )
491 curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
492 - fdt? ( >=sys-apps/dtc-1.5.0[static-libs(+)] )
493 + fdt? ( >=sys-apps/dtc-1.5.1[static-libs(+)] )
494 fuse? ( >=sys-fs/fuse-3.1:3[static-libs(+)] )
495 glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
496 gnutls? (
497 @@ -163,7 +165,7 @@ SOFTMMU_TOOLS_DEPEND="
498 io-uring? ( sys-libs/liburing:=[static-libs(+)] )
499 jack? ( virtual/jack )
500 jemalloc? ( dev-libs/jemalloc )
501 - jpeg? ( virtual/jpeg:0=[static-libs(+)] )
502 + jpeg? ( media-libs/libjpeg-turbo:=[static-libs(+)] )
503 lzo? ( dev-libs/lzo:2[static-libs(+)] )
504 multipath? ( sys-fs/multipath-tools )
505 ncurses? (
506 @@ -416,6 +418,11 @@ src_prepare() {
507 # Verbose builds
508 MAKEOPTS+=" V=1"
509
510 + # We already force -D_FORTIFY_SOURCE=2 (or 3) in our toolchain, but
511 + # this setting (-U then -D..=2) will prevent us from trying out 3, so
512 + # drop it. No change to level of protection b/c we patch our toolchain.
513 + sed -i -e 's/-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2//' configure || die
514 +
515 # Remove bundled copy of libfdt
516 rm -r dtc || die
517 }
518 @@ -430,7 +437,7 @@ qemu_src_configure() {
519 local buildtype=$1
520 local builddir="${S}/${buildtype}-build"
521
522 - mkdir "${builddir}"
523 + mkdir "${builddir}" || die
524
525 local conf_opts=(
526 --prefix=/usr
527 @@ -466,6 +473,7 @@ qemu_src_configure() {
528 --cc="$(tc-getCC)"
529 --cxx="$(tc-getCXX)"
530 --host-cc="$(tc-getBUILD_CC)"
531 +
532 $(use_enable alsa)
533 $(use_enable debug debug-info)
534 $(use_enable debug debug-tcg)
535 @@ -671,22 +679,22 @@ src_configure() {
536
537 src_compile() {
538 if [[ -n ${user_targets} ]]; then
539 - cd "${S}/user-build"
540 + cd "${S}/user-build" || die
541 default
542 fi
543
544 if [[ -n ${softmmu_targets} ]]; then
545 - cd "${S}/softmmu-build"
546 + cd "${S}/softmmu-build" || die
547 default
548 fi
549
550 - cd "${S}/tools-build"
551 + cd "${S}/tools-build" || die
552 default
553 }
554
555 src_test() {
556 if [[ -n ${softmmu_targets} ]]; then
557 - cd "${S}/softmmu-build"
558 + cd "${S}/softmmu-build" || die
559 pax-mark m */qemu-system-* #515550
560 emake check
561 fi
562 @@ -783,19 +791,19 @@ src_install() {
563 fi
564 fi
565
566 - cd "${S}/tools-build"
567 + cd "${S}/tools-build" || die
568 emake DESTDIR="${ED}" install
569
570 # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
571 - pushd "${ED}"/usr/bin >/dev/null
572 + pushd "${ED}"/usr/bin >/dev/null || die
573 pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
574 - popd >/dev/null
575 + popd >/dev/null || die
576
577 # Install config file example for qemu-bridge-helper
578 insinto "/etc/qemu"
579 doins "${FILESDIR}/bridge.conf"
580
581 - cd "${S}"
582 + cd "${S}" || die
583 dodoc MAINTAINERS docs/specs/pci-ids.txt
584 newdoc pc-bios/README README.pc-bios