qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

s390x: kvm: Fix number of cpu reports for stsi 3.2.2

The cpu number reporting is handled by KVM and QEMU only fills in the
VM name, uuid and other values.

Unfortunately KVM doesn't report reserved cpus and doesn't even know
they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the
3.2.2 sysib. To be consistent, we use the same code to retrieve the cpu
numbers as the STSI TCG code in target/s390x/misc_helper.c:HELPER(stsi).

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-Id: <20200331110123.3774-1-frankja@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>

authored by

Janosch Frank and committed by
Cornelia Huck
edd075ae 2833ad48

+16 -1
+16 -1
target/s390x/kvm.c
··· 1768 1768 1769 1769 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) 1770 1770 { 1771 + const MachineState *ms = MACHINE(qdev_get_machine()); 1772 + uint16_t conf_cpus = 0, reserved_cpus = 0; 1771 1773 SysIB_322 sysib; 1772 - int del; 1774 + int del, i; 1773 1775 1774 1776 if (s390_cpu_virt_mem_read(cpu, addr, ar, &sysib, sizeof(sysib))) { 1775 1777 return; ··· 1789 1791 memset(sysib.ext_names[del], 0, 1790 1792 sizeof(sysib.ext_names[0]) * (sysib.count - del)); 1791 1793 } 1794 + 1795 + /* count the cpus and split them into configured and reserved ones */ 1796 + for (i = 0; i < ms->possible_cpus->len; i++) { 1797 + if (ms->possible_cpus->cpus[i].cpu) { 1798 + conf_cpus++; 1799 + } else { 1800 + reserved_cpus++; 1801 + } 1802 + } 1803 + sysib.vm[0].total_cpus = conf_cpus + reserved_cpus; 1804 + sysib.vm[0].conf_cpus = conf_cpus; 1805 + sysib.vm[0].reserved_cpus = reserved_cpus; 1806 + 1792 1807 /* Insert short machine name in EBCDIC, padded with blanks */ 1793 1808 if (qemu_name) { 1794 1809 memset(sysib.vm[0].name, 0x40, sizeof(sysib.vm[0].name));