Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2173590

Summary: bugs in emulation of BMI instructions (for libguestfs without KVM)
Product: Red Hat Enterprise Linux 9 Reporter: Paolo Bonzini <pbonzini>
Component: qemu-kvmAssignee: Paolo Bonzini <pbonzini>
qemu-kvm sub component: CPU Models QA Contact: liunana <nanliu>
Status: CLOSED ERRATA Docs Contact:
Severity: high    
Priority: high CC: chayang, jinzhao, juzhang, lersek, mrezanin, nanliu, nilal, pbonzini, pvlasin, rjones, virt-maint, ymankad, yoguo, zhguo
Version: 9.2Keywords: Regression, Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 9.2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-7.2.0-14.el9_2 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2179033 (view as bug list) Environment:
Last Closed: 2023-05-09 07:23:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2179033    
Attachments:
Description Flags
program to detect bug none

Description Paolo Bonzini 2023-02-27 10:32:13 UTC
Created attachment 1946691 [details]
program to detect bug

Description of problem:
RHEL supports use of QEMU with the Tiny Code Generator (TCG) instead of KVM in specific cases, such as running the libguestfs appliances in a VM without nested virtualization enabled.  In this case, libguestfs uses the "-cpu max" CPU model which uses all the instructions that TCG is able to emulate.

QEMU 7.2 included a rewrite of SSE and BMI instructions that unfortunately had a few bugs.  Because of the "-cpu max" CPU model, these instructions are always enabled.

The most common symptom is failure to do cryptographic operations, for example (without libguestfs) "curl" of an https URL will fail due to a bug in the ADCX and ADOX instructions.  Because the issue is in the translation of x86 instructions, it is impossible to provide a full set of affected programs; on the other hand, the patch is very safe because it only affects TCG and more specifically only the buggy instructions.

This is a regression.

Version-Release number of selected component (if applicable):
7.2.0-10.el9

How reproducible:
100%

Steps to Reproduce:
1. start a RHEL9 VM *without* using KVM and with the "-cpu max" command line option
2. compile the attached program and run it in the VM

Actual results:
The program detects an incorrect implementation of ADCX and ADOX

Expected results:
No error message.

Comment 3 Richard W.M. Jones 2023-02-27 11:30:41 UTC
Seems like you're intending to fix qemu, but we might also
change libguestfs (RHEL 9.2 only) to use a different -cpu flag.
However I'd also note that TCG is used by OpenStack and CNV
for testing and is "soft supported" for those cases too.

Comment 6 Paolo Bonzini 2023-03-01 09:12:20 UTC
> I met one error while compiling it inside guest. Did I miss some parameters?
> 
> # gcc test.c 
> test.c: In function ‘test_adox_adcx’:
> test.c:27:5: error: inconsistent operand constraints in an ‘asm’
>    27 |     asm("push %0; popf;"
>       |     ^~~

Yes, please add "-O2" (same on the host in fact).

Comment 8 liunana 2023-03-01 10:27:27 UTC
(In reply to Paolo Bonzini from comment #6)
> > I met one error while compiling it inside guest. Did I miss some parameters?
> > 
> > # gcc test.c 
> > test.c: In function ‘test_adox_adcx’:
> > test.c:27:5: error: inconsistent operand constraints in an ‘asm’
> >    27 |     asm("push %0; popf;"
> >       |     ^~~
> 
> Yes, please add "-O2" (same on the host in fact).

Thanks.

Reproduced this issue now while running the executable file with qemu-kvm-7.2.0-10.el9.x86_64.
# gcc test.c -O2
  a.out  test.c

# ./a.out 
0
1
a.out: test.c:34: test_adox_adcx: Assertion `out_adcx == in_c + adcx_operand - 1' failed.
Aborted (core dumped)

Comment 19 liunana 2023-03-20 14:54:12 UTC
Test PASS with qemu-kvm-7.2.0-14.el9_2.x86_64.

Test Env:
  host:  kernel-5.14.0-284.2.1.el9_2.x86_64
  guest: kernel-5.14.0-284.2.1.el9_2.x86_64

Test results.
# ./a.out 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


Mark Verified:Tested.

Comment 22 liunana 2023-03-22 02:09:47 UTC
Hi Yongkui,

Would you please help to do some sanity test on libguestfs side?
Thanks.


Best regards
Nana

Comment 23 YongkuiGuo 2023-03-22 02:35:56 UTC
Tested with the following packages on RHEL9.2 host:

libguestfs-1.50.1-3.el9.x86_64
qemu-kvm-7.2.0-14.el9_2.x86_64
kernel-5.14.0-289.el9.x86_64


Steps:

1.
$ LIBGUESTFS_BACKEND=direct LIBGUESTFS_BACKEND_SETTINGS=force_tcg libguestfs-test-tool
...
libguestfs: command: run: /usr/libexec/qemu-kvm
libguestfs: command: run: \ -display none
libguestfs: command: run: \ -help
libguestfs: command: run: /usr/libexec/qemu-kvm
libguestfs: command: run: \ -display none
libguestfs: command: run: \ -machine q35,accel=kvm:tcg
libguestfs: command: run: \ -device ?
libguestfs: command: run: echo '{ "execute": "qmp_capabilities" }' '{ "execute": "query-qmp-schema" }' '{ "execute": "quit" }'  | QEMU_AUDIO_DRV=none "/usr/libexec/qemu-kvm" -display none -machine "q35,accel=kvm:tcg" -qmp stdio
libguestfs: command: run: echo '{ "execute": "qmp_capabilities" }' '{ "execute": "query-kvm" }' '{ "execute": "quit" }'  | QEMU_AUDIO_DRV=none "/usr/libexec/qemu-kvm" -display none -machine "q35,accel=kvm:tcg" -qmp stdio
libguestfs: saving test results
libguestfs: qemu version: 7.2
libguestfs: qemu mandatory locking: yes
libguestfs: qemu KVM: enabled
libguestfs: finished testing qemu features
libguestfs: command: run: dmesg | grep -Eoh 'lpj=[[:digit:]]+'
libguestfs: read_lpj_from_dmesg: external command exited with error status 1
libguestfs: read_lpj_from_files: no boot messages files are readable
/usr/libexec/qemu-kvm \
    -global virtio-blk-pci.scsi=off \
    -no-user-config \
    -nodefaults \
    -display none \
    -machine q35,accel=tcg,graphics=off \
    -cpu max,la57=off \
    -m 1280 \
    -no-reboot \
    -rtc driftfix=slew \
    -no-hpet \
    -global kvm-pit.lost_tick_policy=discard \
    -kernel /var/tmp/.guestfs-1002/appliance.d/kernel \
    -initrd /var/tmp/.guestfs-1002/appliance.d/initrd \
    -object rng-random,filename=/dev/urandom,id=rng0 \
    -device virtio-rng-pci,rng=rng0 \
    -device virtio-scsi-pci,id=scsi \
    -drive file=/tmp/libguestfsjB8ZPO/scratch1.img,cache=unsafe,format=raw,id=hd0,if=none \
    -device scsi-hd,drive=hd0 \
    -drive file=/var/tmp/.guestfs-1002/appliance.d/root,snapshot=on,id=appliance,cache=unsafe,if=none \
    -device scsi-hd,drive=appliance \
    -device virtio-serial-pci \
    -serial stdio \
    -chardev socket,path=/run/user/0/libguestfsfk99Id/guestfsd.sock,id=channel0 \
    -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0 \
    -append "panic=1 console=ttyS0 edd=off udevtimeout=6000 udev.event-timeout=6000 no_timer_check printk.time=1 cgroup_disable=memory usbcore.nousb cryptomgr.notests tsc=reliable 8250.nr_uarts=1 root=UUID=3f0fe7b3-4257-4eb7-a56f-d1714f8d62bf selinux=0 guestfs_verbose=1 TERM=xterm-256color"
\x1bc\x1b[?7l\x1b[2J\x1b[0mSeaBIOS (version 1.16.1-1.el9)
Booting from ROM..\x1bc\x1b[?7l\x1b[2J[    0.000000] Linux version 5.14.0-289.el9.x86_64 (mockbuild.eng.bos.redhat.com) (gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4), GNU ld version 2.35.2-37.el9) #1 SMP PREEMPT_DYNAMIC Sun Mar 19 06:09:51 EDT 2023
...
===== TEST FINISHED OK =====

Sanity check passed on libguestfs side.

Comment 24 liunana 2023-03-22 02:51:56 UTC
Thanks!

Move this bug to verified according to Comment 19 and Comment 23.

Comment 26 errata-xmlrpc 2023-05-09 07:23:46 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: qemu-kvm security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:2162