Bug 2111301

Summary: swtpm.pid still exists after destroying the guest
Product: Red Hat Enterprise Linux 9 Reporter: yafu <yafu>
Component: libvirtAssignee: Martin Kletzander <mkletzan>
libvirt sub component: General QA Contact: Yanqiu Zhang <yanqzhan>
Status: CLOSED ERRATA Docs Contact:
Severity: high    
Priority: high CC: jdenemar, lmen, virt-maint, xuzhang, yanqzhan
Version: 9.1Keywords: AutomationTriaged, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-8.7.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:26:34 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: 8.7.0
Embargoed:

Description yafu 2022-07-27 02:38:45 UTC
Description of problem:
The pid file of swtpm process still exists after destroying the guest

Version-Release number of selected component (if applicable):
libvirt-8.5.0-2.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Prepare a running guest with with tpm device:
#virsh dumpxml avocado-vt-vm1
...
 <tpm model='tpm-crb'>
      <backend type='emulator' version='2.0'/>
      <alias name='tpm0'/>
    </tpm>
...  

2.Check the pid file of swtpm process:
# ll /run/libvirt/qemu/swtpm/
...
-rw-r--r--. 1 root root 6 Jul 26 04:52 100-avocado-vt-vm1-swtpm.pid


3.Destroy the guest:
#virsh destroy avocado-vt-vm1

4.Check the pid file of swtpm process again, the pid file still exists:
ll /run/libvirt/qemu/swtpm/
...
-rw-r--r--. 1 root root 6 Jul 26 04:52 100-avocado-vt-vm1-swtpm.pid

5.Start and destroy the guest 1000 times, libvirt will left 1000 swtpm.pid files;

Actual results:
swtpm.pid still exists after destroying the guest

Expected results:
swtpm.pid file should be removed after guest destroyed and the swtpm process exit.

Additional info:

Comment 2 Yanqiu Zhang 2022-09-16 11:46:26 UTC
Tested with:
libvirt-8.7.0-1.el9.x86_64
qemu-kvm-7.1.0-1.el9.x86_64

Steps:
# virsh start avocado-vt-vm1 
Domain 'avocado-vt-vm1' started

# ll /run/libvirt/qemu/swtpm/
total 4
-rw-r--r--. 1 root root 5 Sep 16 07:37 4-avocado-vt-vm1-swtpm.pid
srw-------. 1 qemu qemu 0 Sep 16 07:37 4-avocado-vt-vm1-swtpm.sock

# virsh destroy avocado-vt-vm1 
Domain 'avocado-vt-vm1' destroyed

# ll /run/libvirt/qemu/swtpm/
total 0

Comment 5 Yanqiu Zhang 2022-09-28 07:59:53 UTC
Additional tests on same version:
1. for session mode:
$ ll /home/test/.cache/libvirt/qemu/run/swtpm/
total 4
-rw-r--r--. 1 test test 6 Sep 28 02:58 3-vm-session-swtpm.pid
srw-------. 1 test test 0 Sep 28 02:58 3-vm-session-swtpm.sock

$ virsh destroy vm-session
Domain 'vm-session' destroyed

$ ll /home/test/.cache/libvirt/qemu/run/swtpm/
total 0

2.Kill swtpm process:
# kill -9 `pidof swtpm`
# ll /run/libvirt/qemu/swtpm/
total 4
-rw-r--r--. 1 root root 4 Sep 28 03:12 2-avocado-vt-vm1-swtpm.pid
srw-------. 1 qemu qemu 0 Sep 28 03:12 2-avocado-vt-vm1-swtpm.sock

# virsh destroy avocado-vt-vm1 
Domain 'avocado-vt-vm1' destroyed

# ll /run/libvirt/qemu/swtpm/
total 0

3. Auto regression test passed for vtpm function:
https://libvirt-jenkins.rhev-ci-vms.eng.rdu2.redhat.com/job/libvirt-RHEL-9.2-runtest-x86_64-function-tpm_emulator/6/testReport/


Combined with comment 2 results, mark bug as verified.

Comment 8 errata-xmlrpc 2023-05-09 07:26:34 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 (libvirt 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/RHBA-2023:2171