Gentoo Archives: gentoo-commits

From: John Helmert III <ajak@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/, app-emulation/qemu/files/
Date: Wed, 08 Dec 2021 01:23:09
Message-Id: 1638926471.aa5822554186cff978a26ec01ebe4a0806ad0ed4.ajak@gentoo
1 commit: aa5822554186cff978a26ec01ebe4a0806ad0ed4
2 Author: John Helmert III <ajak <AT> gentoo <DOT> org>
3 AuthorDate: Wed Dec 8 01:19:11 2021 +0000
4 Commit: John Helmert III <ajak <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 8 01:21:11 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=aa582255
7
8 app-emulation/qemu: add potential patch for data corruption bug
9
10 Bug: https://bugs.gentoo.org/815379
11 Signed-off-by: John Helmert III <ajak <AT> gentoo.org>
12
13 .../qemu/files/qemu-6.1.0-data-corruption.patch | 114 +++
14 app-emulation/qemu/qemu-6.1.0-r2.ebuild | 913 +++++++++++++++++++++
15 2 files changed, 1027 insertions(+)
16
17 diff --git a/app-emulation/qemu/files/qemu-6.1.0-data-corruption.patch b/app-emulation/qemu/files/qemu-6.1.0-data-corruption.patch
18 new file mode 100644
19 index 000000000000..25c788426a9c
20 --- /dev/null
21 +++ b/app-emulation/qemu/files/qemu-6.1.0-data-corruption.patch
22 @@ -0,0 +1,114 @@
23 +commit cc071629539dc1f303175a7e2d4ab854c0a8b20f
24 +Author: Paolo Bonzini <pbonzini@××××××.com>
25 +Date: Thu Sep 23 09:04:36 2021 -0400
26 +
27 + block: introduce max_hw_iov for use in scsi-generic
28 +
29 + Linux limits the size of iovecs to 1024 (UIO_MAXIOV in the kernel
30 + sources, IOV_MAX in POSIX). Because of this, on some host adapters
31 + requests with many iovecs are rejected with -EINVAL by the
32 + io_submit() or readv()/writev() system calls.
33 +
34 + In fact, the same limit applies to SG_IO as well. To fix both the
35 + EINVAL and the possible performance issues from using fewer iovecs
36 + than allowed by Linux (some HBAs have max_segments as low as 128),
37 + introduce a separate entry in BlockLimits to hold the max_segments
38 + value from sysfs. This new limit is used only for SG_IO and clamped
39 + to bs->bl.max_iov anyway, just like max_hw_transfer is clamped to
40 + bs->bl.max_transfer.
41 +
42 + Reported-by: Halil Pasic <pasic@×××××××××.com>
43 + Cc: Hanna Reitz <hreitz@××××××.com>
44 + Cc: Kevin Wolf <kwolf@××××××.com>
45 + Cc: qemu-block@××××××.org
46 + Cc: qemu-stable@××××××.org
47 + Fixes: 18473467d5 ("file-posix: try BLKSECTGET on block devices too, do not round to power of 2", 2021-06-25)
48 + Signed-off-by: Paolo Bonzini <pbonzini@××××××.com>
49 + Message-Id: <20210923130436.1187591-1-pbonzini@××××××.com>
50 + Signed-off-by: Kevin Wolf <kwolf@××××××.com>
51 +
52 +diff --git a/block/block-backend.c b/block/block-backend.c
53 +index 6140d133e2..ba2b5ebb10 100644
54 +--- a/block/block-backend.c
55 ++++ b/block/block-backend.c
56 +@@ -1986,6 +1986,12 @@ uint32_t blk_get_max_transfer(BlockBackend *blk)
57 + return ROUND_DOWN(max, blk_get_request_alignment(blk));
58 + }
59 +
60 ++int blk_get_max_hw_iov(BlockBackend *blk)
61 ++{
62 ++ return MIN_NON_ZERO(blk->root->bs->bl.max_hw_iov,
63 ++ blk->root->bs->bl.max_iov);
64 ++}
65 ++
66 + int blk_get_max_iov(BlockBackend *blk)
67 + {
68 + return blk->root->bs->bl.max_iov;
69 +diff --git a/block/file-posix.c b/block/file-posix.c
70 +index c62e42743d..53be0bdc1b 100644
71 +--- a/block/file-posix.c
72 ++++ b/block/file-posix.c
73 +@@ -1273,7 +1273,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
74 +
75 + ret = hdev_get_max_segments(s->fd, &st);
76 + if (ret > 0) {
77 +- bs->bl.max_iov = ret;
78 ++ bs->bl.max_hw_iov = ret;
79 + }
80 + }
81 + }
82 +diff --git a/block/io.c b/block/io.c
83 +index 18d345a87a..bb0a254def 100644
84 +--- a/block/io.c
85 ++++ b/block/io.c
86 +@@ -136,6 +136,7 @@ static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
87 + dst->min_mem_alignment = MAX(dst->min_mem_alignment,
88 + src->min_mem_alignment);
89 + dst->max_iov = MIN_NON_ZERO(dst->max_iov, src->max_iov);
90 ++ dst->max_hw_iov = MIN_NON_ZERO(dst->max_hw_iov, src->max_hw_iov);
91 + }
92 +
93 + typedef struct BdrvRefreshLimitsState {
94 +diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
95 +index 665baf900e..0306ccc7b1 100644
96 +--- a/hw/scsi/scsi-generic.c
97 ++++ b/hw/scsi/scsi-generic.c
98 +@@ -180,7 +180,7 @@ static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int len)
99 + page = r->req.cmd.buf[2];
100 + if (page == 0xb0) {
101 + uint64_t max_transfer = blk_get_max_hw_transfer(s->conf.blk);
102 +- uint32_t max_iov = blk_get_max_iov(s->conf.blk);
103 ++ uint32_t max_iov = blk_get_max_hw_iov(s->conf.blk);
104 +
105 + assert(max_transfer);
106 + max_transfer = MIN_NON_ZERO(max_transfer, max_iov * qemu_real_host_page_size)
107 +diff --git a/include/block/block_int.h b/include/block/block_int.h
108 +index ffe86068d4..f4c75e8ba9 100644
109 +--- a/include/block/block_int.h
110 ++++ b/include/block/block_int.h
111 +@@ -718,6 +718,13 @@ typedef struct BlockLimits {
112 + */
113 + uint64_t max_hw_transfer;
114 +
115 ++ /* Maximal number of scatter/gather elements allowed by the hardware.
116 ++ * Applies whenever transfers to the device bypass the kernel I/O
117 ++ * scheduler, for example with SG_IO. If larger than max_iov
118 ++ * or if zero, blk_get_max_hw_iov will fall back to max_iov.
119 ++ */
120 ++ int max_hw_iov;
121 ++
122 + /* memory alignment, in bytes so that no bounce buffer is needed */
123 + size_t min_mem_alignment;
124 +
125 +diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
126 +index 29d4fdbf63..82bae55161 100644
127 +--- a/include/sysemu/block-backend.h
128 ++++ b/include/sysemu/block-backend.h
129 +@@ -211,6 +211,7 @@ uint32_t blk_get_request_alignment(BlockBackend *blk);
130 + uint32_t blk_get_max_transfer(BlockBackend *blk);
131 + uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
132 + int blk_get_max_iov(BlockBackend *blk);
133 ++int blk_get_max_hw_iov(BlockBackend *blk);
134 + void blk_set_guest_block_size(BlockBackend *blk, int align);
135 + void *blk_try_blockalign(BlockBackend *blk, size_t size);
136 + void *blk_blockalign(BlockBackend *blk, size_t size);
137
138 diff --git a/app-emulation/qemu/qemu-6.1.0-r2.ebuild b/app-emulation/qemu/qemu-6.1.0-r2.ebuild
139 new file mode 100644
140 index 000000000000..3882becdca90
141 --- /dev/null
142 +++ b/app-emulation/qemu/qemu-6.1.0-r2.ebuild
143 @@ -0,0 +1,913 @@
144 +# Copyright 1999-2021 Gentoo Authors
145 +# Distributed under the terms of the GNU General Public License v2
146 +
147 +EAPI="7"
148 +
149 +PYTHON_COMPAT=( python3_{7,8,9,10} )
150 +PYTHON_REQ_USE="ncurses,readline"
151 +
152 +FIRMWARE_ABI_VERSION="6.1.0"
153 +
154 +inherit linux-info toolchain-funcs python-r1 udev fcaps readme.gentoo-r1 \
155 + pax-utils xdg-utils
156 +
157 +if [[ ${PV} = *9999* ]]; then
158 + EGIT_REPO_URI="https://git.qemu.org/git/qemu.git"
159 + EGIT_SUBMODULES=(
160 + meson
161 + tests/fp/berkeley-softfloat-3
162 + tests/fp/berkeley-testfloat-3
163 + ui/keycodemapdb
164 + )
165 + inherit git-r3
166 + SRC_URI=""
167 +else
168 + SRC_URI="https://download.qemu.org/${P}.tar.xz"
169 + KEYWORDS="~amd64 ~arm64 ~ppc ~ppc64 ~x86"
170 +fi
171 +
172 +DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
173 +HOMEPAGE="https://www.qemu.org https://www.linux-kvm.org"
174 +
175 +LICENSE="GPL-2 LGPL-2 BSD-2"
176 +SLOT="0"
177 +
178 +IUSE="accessibility +aio alsa bpf bzip2 capstone +caps +curl debug +doc
179 + +fdt fuse glusterfs gnutls gtk infiniband iscsi io-uring
180 + jack jemalloc +jpeg kernel_linux
181 + kernel_FreeBSD lzo multipath
182 + ncurses nfs nls numa opengl +oss +pin-upstream-blobs
183 + plugins +png pulseaudio python rbd sasl +seccomp sdl sdl-image selinux
184 + +slirp
185 + smartcard snappy spice ssh static static-user systemtap test udev usb
186 + usbredir vde +vhost-net vhost-user-fs virgl virtfs +vnc vte xattr xen
187 + xfs zstd"
188 +
189 +COMMON_TARGETS="
190 + aarch64
191 + alpha
192 + arm
193 + cris
194 + hppa
195 + i386
196 + m68k
197 + microblaze
198 + microblazeel
199 + mips
200 + mips64
201 + mips64el
202 + mipsel
203 + nios2
204 + or1k
205 + ppc
206 + ppc64
207 + riscv32
208 + riscv64
209 + s390x
210 + sh4
211 + sh4eb
212 + sparc
213 + sparc64
214 + x86_64
215 + xtensa
216 + xtensaeb
217 +"
218 +IUSE_SOFTMMU_TARGETS="
219 + ${COMMON_TARGETS}
220 + avr
221 + rx
222 + tricore
223 +"
224 +IUSE_USER_TARGETS="
225 + ${COMMON_TARGETS}
226 + aarch64_be
227 + armeb
228 + hexagon
229 + mipsn32
230 + mipsn32el
231 + ppc64abi32
232 + ppc64le
233 + sparc32plus
234 +"
235 +
236 +use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
237 +use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
238 +IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
239 +
240 +RESTRICT="!test? ( test )"
241 +# Allow no targets to be built so that people can get a tools-only build.
242 +# Block USE flag configurations known to not work.
243 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
244 + qemu_softmmu_targets_arm? ( fdt )
245 + qemu_softmmu_targets_microblaze? ( fdt )
246 + qemu_softmmu_targets_mips64el? ( fdt )
247 + qemu_softmmu_targets_ppc64? ( fdt )
248 + qemu_softmmu_targets_ppc? ( fdt )
249 + qemu_softmmu_targets_riscv32? ( fdt )
250 + qemu_softmmu_targets_riscv64? ( fdt )
251 + sdl-image? ( sdl )
252 + static? ( static-user !alsa !gtk !jack !opengl !pulseaudio !plugins !rbd !snappy !udev )
253 + static-user? ( !plugins )
254 + vhost-user-fs? ( caps seccomp )
255 + virgl? ( opengl )
256 + virtfs? ( caps xattr )
257 + vte? ( gtk )
258 + multipath? ( udev )
259 + plugins? ( !static !static-user )
260 +"
261 +
262 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
263 +# and user/softmmu targets (qemu-*, qemu-system-*).
264 +#
265 +# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
266 +#
267 +# The attr lib isn't always linked in (although the USE flag is always
268 +# respected). This is because qemu supports using the C library's API
269 +# when available rather than always using the external library.
270 +ALL_DEPEND="
271 + >=dev-libs/glib-2.0[static-libs(+)]
272 + sys-libs/zlib[static-libs(+)]
273 + python? ( ${PYTHON_DEPS} )
274 + systemtap? ( dev-util/systemtap )
275 + xattr? ( sys-apps/attr[static-libs(+)] )"
276 +
277 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
278 +# softmmu targets (qemu-system-*).
279 +SOFTMMU_TOOLS_DEPEND="
280 + dev-libs/libxml2[static-libs(+)]
281 + >=x11-libs/pixman-0.28.0[static-libs(+)]
282 + accessibility? (
283 + app-accessibility/brltty[api]
284 + app-accessibility/brltty[static-libs(+)]
285 + )
286 + aio? ( dev-libs/libaio[static-libs(+)] )
287 + alsa? ( >=media-libs/alsa-lib-1.0.13 )
288 + bpf? ( dev-libs/libbpf:= )
289 + bzip2? ( app-arch/bzip2[static-libs(+)] )
290 + capstone? ( dev-libs/capstone:= )
291 + caps? ( sys-libs/libcap-ng[static-libs(+)] )
292 + curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
293 + fdt? ( >=sys-apps/dtc-1.5.0[static-libs(+)] )
294 + fuse? ( >=sys-fs/fuse-3.1:3[static-libs(+)] )
295 + glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
296 + gnutls? (
297 + dev-libs/nettle:=[static-libs(+)]
298 + >=net-libs/gnutls-3.0:=[static-libs(+)]
299 + )
300 + gtk? (
301 + x11-libs/gtk+:3
302 + vte? ( x11-libs/vte:2.91 )
303 + )
304 + infiniband? (
305 + sys-fabric/libibumad:=[static-libs(+)]
306 + sys-fabric/libibverbs:=[static-libs(+)]
307 + sys-fabric/librdmacm:=[static-libs(+)]
308 + )
309 + iscsi? ( net-libs/libiscsi )
310 + io-uring? ( sys-libs/liburing:=[static-libs(+)] )
311 + jack? ( virtual/jack )
312 + jemalloc? ( dev-libs/jemalloc )
313 + jpeg? ( virtual/jpeg:0=[static-libs(+)] )
314 + lzo? ( dev-libs/lzo:2[static-libs(+)] )
315 + multipath? ( sys-fs/multipath-tools )
316 + ncurses? (
317 + sys-libs/ncurses:=[unicode(+)]
318 + sys-libs/ncurses:=[static-libs(+)]
319 + )
320 + nfs? ( >=net-fs/libnfs-1.9.3:=[static-libs(+)] )
321 + numa? ( sys-process/numactl[static-libs(+)] )
322 + opengl? (
323 + virtual/opengl
324 + media-libs/libepoxy[static-libs(+)]
325 + media-libs/mesa[static-libs(+)]
326 + media-libs/mesa[egl(+),gbm(+)]
327 + )
328 + png? ( media-libs/libpng:0=[static-libs(+)] )
329 + pulseaudio? ( media-sound/pulseaudio )
330 + rbd? ( sys-cluster/ceph )
331 + sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
332 + sdl? (
333 + media-libs/libsdl2[video]
334 + media-libs/libsdl2[static-libs(+)]
335 + )
336 + sdl-image? ( media-libs/sdl2-image[static-libs(+)] )
337 + seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
338 + slirp? ( net-libs/libslirp[static-libs(+)] )
339 + smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
340 + snappy? ( app-arch/snappy:= )
341 + spice? (
342 + >=app-emulation/spice-protocol-0.12.3
343 + >=app-emulation/spice-0.12.0[static-libs(+)]
344 + )
345 + ssh? ( >=net-libs/libssh-0.8.6[static-libs(+)] )
346 + udev? ( virtual/libudev:= )
347 + usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
348 + usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
349 + vde? ( net-misc/vde[static-libs(+)] )
350 + virgl? ( media-libs/virglrenderer[static-libs(+)] )
351 + virtfs? ( sys-libs/libcap )
352 + xen? ( app-emulation/xen-tools:= )
353 + xfs? ( sys-fs/xfsprogs[static-libs(+)] )
354 + zstd? ( >=app-arch/zstd-1.4.0[static-libs(+)] )
355 +"
356 +
357 +EDK2_OVMF_VERSION="202105"
358 +SEABIOS_VERSION="1.14.0"
359 +
360 +X86_FIRMWARE_DEPEND="
361 + pin-upstream-blobs? (
362 + ~sys-firmware/edk2-ovmf-${EDK2_OVMF_VERSION}[binary]
363 + ~sys-firmware/ipxe-1.21.1[binary,qemu]
364 + ~sys-firmware/seabios-${SEABIOS_VERSION}[binary,seavgabios]
365 + ~sys-firmware/sgabios-0.1_pre10[binary]
366 + )
367 + !pin-upstream-blobs? (
368 + >=sys-firmware/edk2-ovmf-${EDK2_OVMF_VERSION}
369 + sys-firmware/ipxe[qemu]
370 + >=sys-firmware/seabios-${SEABIOS_VERSION}[seavgabios]
371 + sys-firmware/sgabios
372 + )"
373 +PPC_FIRMWARE_DEPEND="
374 + pin-upstream-blobs? (
375 + ~sys-firmware/seabios-${SEABIOS_VERSION}[binary,seavgabios]
376 + )
377 + !pin-upstream-blobs? (
378 + >=sys-firmware/seabios-${SEABIOS_VERSION}[seavgabios]
379 + )
380 +"
381 +
382 +BDEPEND="
383 + $(python_gen_impl_dep)
384 + dev-lang/perl
385 + sys-apps/texinfo
386 + virtual/pkgconfig
387 + doc? (
388 + dev-python/sphinx[${PYTHON_USEDEP}]
389 + dev-python/sphinx_rtd_theme[${PYTHON_USEDEP}]
390 + )
391 + gtk? ( nls? ( sys-devel/gettext ) )
392 + test? (
393 + dev-libs/glib[utils]
394 + sys-devel/bc
395 + )
396 +"
397 +CDEPEND="
398 + !static? (
399 + ${ALL_DEPEND//\[static-libs(+)]}
400 + ${SOFTMMU_TOOLS_DEPEND//\[static-libs(+)]}
401 + )
402 + qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
403 + qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
404 + qemu_softmmu_targets_ppc? ( ${PPC_FIRMWARE_DEPEND} )
405 + qemu_softmmu_targets_ppc64? ( ${PPC_FIRMWARE_DEPEND} )
406 +"
407 +DEPEND="${CDEPEND}
408 + kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
409 + static? (
410 + ${ALL_DEPEND}
411 + ${SOFTMMU_TOOLS_DEPEND}
412 + )
413 + static-user? ( ${ALL_DEPEND} )"
414 +RDEPEND="${CDEPEND}
415 + acct-group/kvm
416 + selinux? ( sec-policy/selinux-qemu )"
417 +
418 +PATCHES=(
419 + "${FILESDIR}"/${PN}-2.11.1-capstone_include_path.patch
420 + "${FILESDIR}"/${PN}-5.2.0-disable-keymap.patch
421 + "${FILESDIR}"/${PN}-6.0.0-make.patch
422 + "${FILESDIR}"/${PN}-6.1.0-strings.patch
423 + "${FILESDIR}"/${P}-automagic-libbpf.patch
424 + "${FILESDIR}"/${P}-data-corruption.patch
425 +)
426 +
427 +QA_PREBUILT="
428 + usr/share/qemu/hppa-firmware.img
429 + usr/share/qemu/openbios-ppc
430 + usr/share/qemu/openbios-sparc64
431 + usr/share/qemu/openbios-sparc32
432 + usr/share/qemu/opensbi-riscv64-generic-fw_dynamic.elf
433 + usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.elf
434 + usr/share/qemu/palcode-clipper
435 + usr/share/qemu/s390-ccw.img
436 + usr/share/qemu/s390-netboot.img
437 + usr/share/qemu/u-boot.e500
438 +"
439 +
440 +QA_WX_LOAD="usr/bin/qemu-i386
441 + usr/bin/qemu-x86_64
442 + usr/bin/qemu-alpha
443 + usr/bin/qemu-arm
444 + usr/bin/qemu-cris
445 + usr/bin/qemu-m68k
446 + usr/bin/qemu-microblaze
447 + usr/bin/qemu-microblazeel
448 + usr/bin/qemu-mips
449 + usr/bin/qemu-mipsel
450 + usr/bin/qemu-or1k
451 + usr/bin/qemu-ppc
452 + usr/bin/qemu-ppc64
453 + usr/bin/qemu-ppc64abi32
454 + usr/bin/qemu-sh4
455 + usr/bin/qemu-sh4eb
456 + usr/bin/qemu-sparc
457 + usr/bin/qemu-sparc64
458 + usr/bin/qemu-armeb
459 + usr/bin/qemu-sparc32plus
460 + usr/bin/qemu-s390x
461 + usr/bin/qemu-unicore32
462 +"
463 +
464 +DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure you have the
465 +kernel module loaded before running kvm. The easiest way to ensure that the
466 +kernel module is loaded is to load it on boot.
467 + For AMD CPUs the module is called 'kvm-amd'.
468 + For Intel CPUs the module is called 'kvm-intel'.
469 +Please review /etc/conf.d/modules for how to load these.
470 +
471 +Make sure your user is in the 'kvm' group. Just run
472 + $ gpasswd -a <USER> kvm
473 +then have <USER> re-login.
474 +
475 +For brand new installs, the default permissions on /dev/kvm might not let
476 +you access it. You can tell udev to reset ownership/perms:
477 + $ udevadm trigger -c add /dev/kvm
478 +
479 +If you want to register binfmt handlers for qemu user targets:
480 +For openrc:
481 + # rc-update add qemu-binfmt
482 +For systemd:
483 + # ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf"
484 +
485 +pkg_pretend() {
486 + if use kernel_linux && kernel_is lt 2 6 25; then
487 + eerror "This version of KVM requires a host kernel of 2.6.25 or higher."
488 + elif use kernel_linux; then
489 + if ! linux_config_exists; then
490 + eerror "Unable to check your kernel for KVM support"
491 + else
492 + CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
493 + ERROR_KVM="You must enable KVM in your kernel to continue"
494 + ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
495 + ERROR_KVM_AMD+=" your kernel configuration."
496 + ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
497 + ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
498 + ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
499 + ERROR_TUN+=" into your kernel or loaded as a module to use the"
500 + ERROR_TUN+=" virtual network device if using -net tap."
501 + ERROR_BRIDGE="You will also need support for 802.1d"
502 + ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
503 + use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
504 + ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
505 + ERROR_VHOST_NET+=" support"
506 +
507 + if use amd64 || use x86 || use amd64-linux || use x86-linux; then
508 + if grep -q AuthenticAMD /proc/cpuinfo; then
509 + CONFIG_CHECK+=" ~KVM_AMD"
510 + elif grep -q GenuineIntel /proc/cpuinfo; then
511 + CONFIG_CHECK+=" ~KVM_INTEL"
512 + fi
513 + fi
514 +
515 + use python && CONFIG_CHECK+=" ~DEBUG_FS"
516 + ERROR_DEBUG_FS="debugFS support required for kvm_stat"
517 +
518 + # Now do the actual checks setup above
519 + check_extra_config
520 + fi
521 + fi
522 +
523 + if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
524 + eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
525 + eerror "instances are still pointing to it. Please update your"
526 + eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
527 + eerror "and the right system binary (e.g. qemu-system-x86_64)."
528 + die "update your virt configs to not use qemu-kvm"
529 + fi
530 +}
531 +
532 +# Sanity check to make sure target lists are kept up-to-date.
533 +check_targets() {
534 + local var=$1 mak=$2
535 + local detected sorted
536 +
537 + pushd "${S}"/configs/targets/ >/dev/null || die
538 +
539 + # Force C locale until glibc is updated. #564936
540 + detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
541 + sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
542 + if [[ ${sorted} != "${detected}" ]] ; then
543 + eerror "The ebuild needs to be kept in sync."
544 + eerror "${var}: ${sorted}"
545 + eerror "$(printf '%-*s' ${#var} configure): ${detected}"
546 + die "sync ${var} to the list of targets"
547 + fi
548 +
549 + popd >/dev/null
550 +}
551 +
552 +src_prepare() {
553 + check_targets IUSE_SOFTMMU_TARGETS softmmu
554 + check_targets IUSE_USER_TARGETS linux-user
555 +
556 + default
557 +
558 + # Use correct toolchain to fix cross-compiling
559 + tc-export AR AS LD NM OBJCOPY PKG_CONFIG RANLIB STRINGS
560 + export WINDRES=${CHOST}-windres
561 +
562 + # Verbose builds
563 + MAKEOPTS+=" V=1"
564 +
565 + # Remove bundled copy of libfdt
566 + rm -r dtc || die
567 +}
568 +
569 +##
570 +# configures qemu based on the build directory and the build type
571 +# we are using.
572 +#
573 +qemu_src_configure() {
574 + debug-print-function ${FUNCNAME} "$@"
575 +
576 + local buildtype=$1
577 + local builddir="${S}/${buildtype}-build"
578 +
579 + mkdir "${builddir}"
580 +
581 + local conf_opts=(
582 + --prefix=/usr
583 + --sysconfdir=/etc
584 + --bindir=/usr/bin
585 + --libdir=/usr/$(get_libdir)
586 + --datadir=/usr/share
587 + --docdir=/usr/share/doc/${PF}/html
588 + --mandir=/usr/share/man
589 + --localstatedir=/var
590 + --disable-bsd-user
591 + --disable-containers # bug #732972
592 + --disable-guest-agent
593 + --disable-strip
594 +
595 + # bug #746752: TCG interpreter has a few limitations:
596 + # - it does not support FPU
597 + # - it's generally slower on non-self-modifying code
598 + # It's advantage is support for host architectures
599 + # where native codegeneration is not implemented.
600 + # Gentoo has qemu keyworded only on targets with
601 + # native code generation available. Avoid the interpreter.
602 + --disable-tcg-interpreter
603 +
604 + --disable-werror
605 + # We support gnutls/nettle for crypto operations. It is possible
606 + # to use gcrypt when gnutls/nettle are disabled (but not when they
607 + # are enabled), but it's not really worth the hassle. Disable it
608 + # all the time to avoid automatically detecting it. #568856
609 + --disable-gcrypt
610 + --python="${PYTHON}"
611 + --cc="$(tc-getCC)"
612 + --cxx="$(tc-getCXX)"
613 + --host-cc="$(tc-getBUILD_CC)"
614 + $(use_enable debug debug-info)
615 + $(use_enable debug debug-tcg)
616 + $(use_enable doc docs)
617 + $(use_enable nls gettext)
618 + $(use_enable plugins)
619 + $(use_enable xattr attr)
620 + )
621 +
622 + # Disable options not used by user targets. This simplifies building
623 + # static user targets (USE=static-user) considerably.
624 + conf_notuser() {
625 + if [[ ${buildtype} == "user" ]] ; then
626 + echo "--disable-${2:-$1}"
627 + else
628 + use_enable "$@"
629 + fi
630 + }
631 + # Enable option only for softmmu build, but not 'user' or 'tools'
632 + conf_softmmu() {
633 + if [[ ${buildtype} == "softmmu" ]] ; then
634 + use_enable "$@"
635 + else
636 + echo "--disable-${2:-$1}"
637 + fi
638 + }
639 + # Enable option only for tools build, but not 'user' or 'softmmu'
640 + conf_tools() {
641 + if [[ ${buildtype} == "tools" ]] ; then
642 + use_enable "$@"
643 + else
644 + echo "--disable-${2:-$1}"
645 + fi
646 + }
647 + conf_opts+=(
648 + $(conf_notuser accessibility brlapi)
649 + $(conf_notuser aio linux-aio)
650 + $(conf_softmmu bpf)
651 + $(conf_notuser bzip2)
652 + $(conf_notuser capstone)
653 + $(conf_notuser caps cap-ng)
654 + $(conf_notuser curl)
655 + $(conf_notuser fdt)
656 + $(conf_notuser fuse)
657 + $(conf_notuser glusterfs)
658 + $(conf_notuser gnutls)
659 + $(conf_notuser gnutls nettle)
660 + $(conf_notuser gtk)
661 + $(conf_notuser infiniband rdma)
662 + $(conf_notuser iscsi libiscsi)
663 + $(conf_notuser io-uring linux-io-uring)
664 + $(conf_notuser jemalloc jemalloc)
665 + $(conf_notuser jpeg vnc-jpeg)
666 + $(conf_notuser kernel_linux kvm)
667 + $(conf_notuser lzo)
668 + $(conf_notuser multipath mpath)
669 + $(conf_notuser ncurses curses)
670 + $(conf_notuser nfs libnfs)
671 + $(conf_notuser numa)
672 + $(conf_notuser opengl)
673 + $(conf_notuser png vnc-png)
674 + $(conf_notuser rbd)
675 + $(conf_notuser sasl vnc-sasl)
676 + $(conf_notuser sdl)
677 + $(conf_softmmu sdl-image)
678 + $(conf_notuser seccomp)
679 + $(conf_notuser slirp slirp system)
680 + $(conf_notuser smartcard)
681 + $(conf_notuser snappy)
682 + $(conf_notuser spice)
683 + $(conf_notuser ssh libssh)
684 + $(conf_notuser udev libudev)
685 + $(conf_notuser usb libusb)
686 + $(conf_notuser usbredir usb-redir)
687 + $(conf_notuser vde)
688 + $(conf_notuser vhost-net)
689 + $(conf_notuser vhost-user-fs)
690 + $(conf_tools vhost-user-fs virtiofsd)
691 + $(conf_notuser virgl virglrenderer)
692 + $(conf_softmmu virtfs)
693 + $(conf_notuser vnc)
694 + $(conf_notuser vte)
695 + $(conf_notuser xen)
696 + $(conf_notuser xen xen-pci-passthrough)
697 + $(conf_notuser xfs xfsctl)
698 + # use prebuilt keymaps, bug #759604
699 + --disable-xkbcommon
700 + $(conf_notuser zstd)
701 + )
702 +
703 + if [[ ${buildtype} == "user" ]] ; then
704 + conf_opts+=( --disable-libxml2 )
705 + else
706 + conf_opts+=( --enable-libxml2 )
707 + fi
708 +
709 + if [[ ! ${buildtype} == "user" ]] ; then
710 + # audio options
711 + local audio_opts=(
712 + # Note: backend order matters here: #716202
713 + # We iterate from higher-level to lower level.
714 + $(usex pulseaudio pa "")
715 + $(usev jack)
716 + $(usev sdl)
717 + $(usev alsa)
718 + $(usev oss)
719 + )
720 + conf_opts+=(
721 + --audio-drv-list=$(printf "%s," "${audio_opts[@]}")
722 + )
723 + fi
724 +
725 + case ${buildtype} in
726 + user)
727 + conf_opts+=(
728 + --enable-linux-user
729 + --disable-system
730 + --disable-blobs
731 + --disable-tools
732 + )
733 + local static_flag="static-user"
734 + ;;
735 + softmmu)
736 + conf_opts+=(
737 + --disable-linux-user
738 + --enable-system
739 + --disable-tools
740 + )
741 + local static_flag="static"
742 + ;;
743 + tools)
744 + conf_opts+=(
745 + --disable-linux-user
746 + --disable-system
747 + --disable-blobs
748 + --enable-tools
749 + )
750 + local static_flag="static"
751 + ;;
752 + esac
753 +
754 + local targets="${buildtype}_targets"
755 + [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
756 +
757 + # Add support for SystemTAP
758 + use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
759 +
760 + # We always want to attempt to build with PIE support as it results
761 + # in a more secure binary. But it doesn't work with static or if
762 + # the current GCC doesn't have PIE support.
763 + if use ${static_flag}; then
764 + conf_opts+=( --static --disable-pie )
765 + else
766 + tc-enables-pie && conf_opts+=( --enable-pie )
767 + fi
768 +
769 + # Meson will not use a cross-file unless cross_prefix is set.
770 + tc-is-cross-compiler && conf_opts+=( --cross-prefix="${CHOST}-" )
771 +
772 + # Plumb through equivalent of EXTRA_ECONF to allow experiments
773 + # like bug #747928.
774 + conf_opts+=( ${EXTRA_CONF_QEMU} )
775 +
776 + echo "../configure ${conf_opts[*]}"
777 + cd "${builddir}"
778 + ../configure "${conf_opts[@]}" || die "configure failed"
779 +
780 + # FreeBSD's kernel does not support QEMU assigning/grabbing
781 + # host USB devices yet
782 + use kernel_FreeBSD && \
783 + sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
784 +}
785 +
786 +src_configure() {
787 + local target
788 +
789 + python_setup
790 +
791 + softmmu_targets= softmmu_bins=()
792 + user_targets= user_bins=()
793 +
794 + for target in ${IUSE_SOFTMMU_TARGETS} ; do
795 + if use "qemu_softmmu_targets_${target}"; then
796 + softmmu_targets+=",${target}-softmmu"
797 + softmmu_bins+=( "qemu-system-${target}" )
798 + fi
799 + done
800 +
801 + for target in ${IUSE_USER_TARGETS} ; do
802 + if use "qemu_user_targets_${target}"; then
803 + user_targets+=",${target}-linux-user"
804 + user_bins+=( "qemu-${target}" )
805 + fi
806 + done
807 +
808 + softmmu_targets=${softmmu_targets#,}
809 + user_targets=${user_targets#,}
810 +
811 + [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
812 + [[ -n ${user_targets} ]] && qemu_src_configure "user"
813 + qemu_src_configure "tools"
814 +}
815 +
816 +src_compile() {
817 + if [[ -n ${user_targets} ]]; then
818 + cd "${S}/user-build"
819 + default
820 + fi
821 +
822 + if [[ -n ${softmmu_targets} ]]; then
823 + cd "${S}/softmmu-build"
824 + default
825 + fi
826 +
827 + cd "${S}/tools-build"
828 + default
829 +}
830 +
831 +src_test() {
832 + if [[ -n ${softmmu_targets} ]]; then
833 + cd "${S}/softmmu-build"
834 + pax-mark m */qemu-system-* #515550
835 + emake check
836 + fi
837 +}
838 +
839 +qemu_python_install() {
840 + python_domodule "${S}/python/qemu"
841 +
842 + python_doscript "${S}/scripts/kvm/vmxcap"
843 + python_doscript "${S}/scripts/qmp/qmp-shell"
844 + python_doscript "${S}/scripts/qmp/qemu-ga-client"
845 +}
846 +
847 +# Generate binfmt support files.
848 +# - /etc/init.d/qemu-binfmt script which registers the user handlers (openrc)
849 +# - /usr/share/qemu/binfmt.d/qemu.conf (for use with systemd-binfmt)
850 +generate_initd() {
851 + local out="${T}/qemu-binfmt"
852 + local out_systemd="${T}/qemu.conf"
853 + local d="${T}/binfmt.d"
854 +
855 + einfo "Generating qemu binfmt scripts and configuration files"
856 +
857 + # Generate the debian fragments first.
858 + mkdir -p "${d}"
859 + "${S}"/scripts/qemu-binfmt-conf.sh \
860 + --debian \
861 + --exportdir "${d}" \
862 + --qemu-path "${EPREFIX}/usr/bin" \
863 + || die
864 + # Then turn the fragments into a shell script we can source.
865 + sed -E -i \
866 + -e 's:^([^ ]+) (.*)$:\1="\2":' \
867 + "${d}"/* || die
868 +
869 + # Generate the init.d script by assembling the fragments from above.
870 + local f qcpu package interpreter magic mask
871 + cat "${FILESDIR}"/qemu-binfmt.initd.head >"${out}" || die
872 + for f in "${d}"/qemu-* ; do
873 + source "${f}"
874 +
875 + # Normalize the cpu logic like we do in the init.d for the native cpu.
876 + qcpu=${package#qemu-}
877 + case ${qcpu} in
878 + arm*) qcpu="arm";;
879 + mips*) qcpu="mips";;
880 + ppc*) qcpu="ppc";;
881 + s390*) qcpu="s390";;
882 + sh*) qcpu="sh";;
883 + sparc*) qcpu="sparc";;
884 + esac
885 +
886 + # we use 'printf' here to be portable across 'sh'
887 + # implementations: #679168
888 + cat <<EOF >>"${out}"
889 + if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then
890 + printf '%s\n' ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
891 + fi
892 +EOF
893 +
894 + echo ":${package}:M::${magic}:${mask}:${interpreter}:OC" >>"${out_systemd}"
895 +
896 + done
897 + cat "${FILESDIR}"/qemu-binfmt.initd.tail >>"${out}" || die
898 +}
899 +
900 +src_install() {
901 + if [[ -n ${user_targets} ]]; then
902 + cd "${S}/user-build"
903 + emake DESTDIR="${ED}" install
904 +
905 + # Install binfmt handler init script for user targets.
906 + generate_initd
907 + doinitd "${T}/qemu-binfmt"
908 +
909 + # Install binfmt/qemu.conf.
910 + insinto "/usr/share/qemu/binfmt.d"
911 + doins "${T}/qemu.conf"
912 + fi
913 +
914 + if [[ -n ${softmmu_targets} ]]; then
915 + cd "${S}/softmmu-build"
916 + emake DESTDIR="${ED}" install
917 +
918 + # This might not exist if the test failed. #512010
919 + [[ -e check-report.html ]] && dodoc check-report.html
920 +
921 + if use kernel_linux; then
922 + udev_newrules "${FILESDIR}"/65-kvm.rules-r2 65-kvm.rules
923 + fi
924 +
925 + if use python; then
926 + python_foreach_impl qemu_python_install
927 + fi
928 + fi
929 +
930 + cd "${S}/tools-build"
931 + emake DESTDIR="${ED}" install
932 +
933 + # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
934 + pushd "${ED}"/usr/bin >/dev/null
935 + pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
936 + popd >/dev/null
937 +
938 + # Install config file example for qemu-bridge-helper
939 + insinto "/etc/qemu"
940 + doins "${FILESDIR}/bridge.conf"
941 +
942 + cd "${S}"
943 + dodoc MAINTAINERS docs/specs/pci-ids.txt
944 + newdoc pc-bios/README README.pc-bios
945 +
946 + # Disallow stripping of prebuilt firmware files.
947 + dostrip -x ${QA_PREBUILT}
948 +
949 + if [[ -n ${softmmu_targets} ]]; then
950 + # Remove SeaBIOS since we're using the SeaBIOS packaged one
951 + rm "${ED}/usr/share/qemu/bios.bin"
952 + rm "${ED}/usr/share/qemu/bios-256k.bin"
953 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
954 + dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
955 + dosym ../seabios/bios-256k.bin /usr/share/qemu/bios-256k.bin
956 + fi
957 +
958 + # Remove vgabios since we're using the seavgabios packaged one
959 + rm "${ED}/usr/share/qemu/vgabios.bin"
960 + rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
961 + rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
962 + rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
963 + rm "${ED}/usr/share/qemu/vgabios-virtio.bin"
964 + rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
965 + # PPC/PPC64 loads vgabios-stdvga
966 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 || use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64; then
967 + dosym ../seavgabios/vgabios-isavga.bin /usr/share/qemu/vgabios.bin
968 + dosym ../seavgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
969 + dosym ../seavgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
970 + dosym ../seavgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
971 + dosym ../seavgabios/vgabios-virtio.bin /usr/share/qemu/vgabios-virtio.bin
972 + dosym ../seavgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
973 + fi
974 +
975 + # Remove sgabios since we're using the sgabios packaged one
976 + rm "${ED}/usr/share/qemu/sgabios.bin"
977 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
978 + dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
979 + fi
980 +
981 + # Remove iPXE since we're using the iPXE packaged one
982 + rm "${ED}"/usr/share/qemu/pxe-*.rom
983 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
984 + dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
985 + dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
986 + dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
987 + dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
988 + dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
989 + dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
990 + fi
991 + fi
992 +
993 + DISABLE_AUTOFORMATTING=true
994 + readme.gentoo_create_doc
995 +}
996 +
997 +firmware_abi_change() {
998 + local pv
999 + for pv in ${REPLACING_VERSIONS}; do
1000 + if ver_test ${pv} -lt ${FIRMWARE_ABI_VERSION}; then
1001 + return 0
1002 + fi
1003 + done
1004 + return 1
1005 +}
1006 +
1007 +pkg_postinst() {
1008 + if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
1009 + udev_reload
1010 + fi
1011 +
1012 + xdg_icon_cache_update
1013 +
1014 + [[ -z ${EPREFIX} ]] && [[ -f ${EROOT}/usr/libexec/qemu-bridge-helper ]] && \
1015 + fcaps cap_net_admin ${EROOT}/usr/libexec/qemu-bridge-helper
1016 +
1017 + DISABLE_AUTOFORMATTING=true
1018 + readme.gentoo_print_elog
1019 +
1020 + if use pin-upstream-blobs && firmware_abi_change; then
1021 + ewarn "This version of qemu pins new versions of firmware blobs:"
1022 + ewarn " $(best_version sys-firmware/edk2-ovmf)"
1023 + ewarn " $(best_version sys-firmware/ipxe)"
1024 + ewarn " $(best_version sys-firmware/seabios)"
1025 + ewarn " $(best_version sys-firmware/sgabios)"
1026 + ewarn "This might break resume of hibernated guests (started with a different"
1027 + ewarn "firmware version) and live migration to/from qemu versions with different"
1028 + ewarn "firmware. Please (cold) restart all running guests. For functional"
1029 + ewarn "guest migration ensure that all"
1030 + ewarn "hosts run at least"
1031 + ewarn " app-emulation/qemu-${FIRMWARE_ABI_VERSION}."
1032 + fi
1033 +}
1034 +
1035 +pkg_info() {
1036 + echo "Using:"
1037 + echo " $(best_version app-emulation/spice-protocol)"
1038 + echo " $(best_version sys-firmware/edk2-ovmf)"
1039 + if has_version 'sys-firmware/edk2-ovmf[binary]'; then
1040 + echo " USE=binary"
1041 + else
1042 + echo " USE=''"
1043 + fi
1044 + echo " $(best_version sys-firmware/ipxe)"
1045 + echo " $(best_version sys-firmware/seabios)"
1046 + if has_version 'sys-firmware/seabios[binary]'; then
1047 + echo " USE=binary"
1048 + else
1049 + echo " USE=''"
1050 + fi
1051 + echo " $(best_version sys-firmware/sgabios)"
1052 +}
1053 +
1054 +pkg_postrm() {
1055 + xdg_icon_cache_update
1056 +}