Skip to contentSkip to conversation

s390x (and one qtest) patches

GIT PULL Thomas Huth 5 participants 15 messages Sep 12, 2023 – Jan 11, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

The following changes since commit 9ef497755afc252fb8e060c9ea6b0987abfd20b6:

Merge tag 'pull-vfio-20230911' of https://github.com/legoater/qemu into staging (2023-09-11 09:13:08 -0400)

are available in the Git repository at:

https://gitlab.com/thuth/qemu.git tags/pull-request-2023-09-12

for you to fetch changes up to 82fdcd3e140c8d4c63f177ece554f90f2bccdf68:

tests/qtest/pflash: Clean up local variable shadowing (2023-09-12 12:07:31 +0200)

----------------------------------------------------------------
* Enable AP (crypto adapter) instructions for s390x PV-guests
* Allow NVME for s390x machines
* Update Linux headers to v6.6-rc1

----------------------------------------------------------------
Cédric Le Goater (1):

      kconfig: Add NVME to s390x machines

Janosch Frank (2):

      s390x/ap: fix missing subsystem reset registration
      s390x: do a subsystem reset before the unprotect on reboot

Philippe Mathieu-Daudé (1):
tests/qtest/pflash: Clean up local variable shadowing

Steffen Eiden (2):

      target/s390x/kvm: Refactor AP functionalities
      target/s390x: AP-passthrough for PV guests

Thomas Huth (1):
linux-headers: Update to Linux v6.6-rc1

 include/standard-headers/linux/fuse.h        |  63 ++++++++++-
 include/standard-headers/linux/vhost_types.h |   4 +
 include/standard-headers/linux/virtio_net.h  |  14 +++
 linux-headers/asm-arm64/bitsperlong.h        |  23 ++++
 linux-headers/asm-generic/unistd.h           |   5 +-
 linux-headers/asm-mips/unistd_n32.h          |   1 +
 linux-headers/asm-mips/unistd_n64.h          |   1 +
 linux-headers/asm-mips/unistd_o32.h          |   1 +
 linux-headers/asm-powerpc/unistd_32.h        |   1 +
 linux-headers/asm-powerpc/unistd_64.h        |   1 +
 linux-headers/asm-riscv/bitsperlong.h        |  13 +++
 linux-headers/asm-riscv/kvm.h                |  16 +++
 linux-headers/asm-s390/kvm.h                 |  16 +++
 linux-headers/asm-s390/unistd_32.h           |   1 +
 linux-headers/asm-s390/unistd_64.h           |   1 +
 linux-headers/asm-x86/mman.h                 |  10 +-
 linux-headers/asm-x86/unistd_32.h            |   1 +
 linux-headers/asm-x86/unistd_64.h            |   2 +
 linux-headers/asm-x86/unistd_x32.h           |   1 +
 linux-headers/linux/kvm.h                    |  13 ++-
 linux-headers/linux/stddef.h                 |   4 +
 linux-headers/linux/userfaultfd.h            |  25 ++++-
 linux-headers/linux/vfio.h                   | 150 ++++++++++++++++++++++++++-
 target/s390x/cpu_features.h                  |   1 +
 target/s390x/cpu_features_def.h.inc          |   4 +
 hw/s390x/s390-virtio-ccw.c                   |  11 ++
 target/s390x/cpu_models.c                    |   2 +
 target/s390x/gen-features.c                  |   2 +
 target/s390x/kvm/kvm.c                       |  94 +++++++++++++++--
 tests/qtest/pflash-cfi02-test.c              |   2 +-
 hw/nvme/Kconfig                              |   2 +-
 31 files changed, 460 insertions(+), 25 deletions(-)
#1 lore raw

[PULL 1/7] s390x/ap: fix missing subsystem reset registration

From: Janosch Frank <[email protected]>

A subsystem reset contains a reset of AP resources which has been missing. Adding the AP bridge to the list of device types that need reset fixes this issue.

Fixes a51b3153 ("s390x/ap: base Adjunct Processor (AP) object model")

Message-ID: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/s390-virtio-ccw.c +1 -0
index bfcf64d007..3dd0b2372d 100644
@@ -109,6 +109,7 @@ static const char *const reset_dev_types[] = {
     "s390-flic",
     "diag288",
     TYPE_S390_PCI_HOST_BRIDGE,
+    TYPE_AP_BRIDGE,
 };
 
 static void subsystem_reset(void)
Signature · 1 line
2.41.0
#2 lore raw

[PULL 3/7] linux-headers: Update to Linux v6.6-rc1

In reply to Thomas Huth

This update contains the required header changes for the "target/s390x: AP-passthrough for PV guests" patch from Steffen Eiden.

Message-ID: <[email protected]>

---
 include/standard-headers/linux/fuse.h        |  63 +++++++-
 include/standard-headers/linux/vhost_types.h |   4 +
 include/standard-headers/linux/virtio_net.h  |  14 ++
 linux-headers/asm-arm64/bitsperlong.h        |  23 +++
 linux-headers/asm-generic/unistd.h           |   5 +-
 linux-headers/asm-mips/unistd_n32.h          |   1 +
 linux-headers/asm-mips/unistd_n64.h          |   1 +
 linux-headers/asm-mips/unistd_o32.h          |   1 +
 linux-headers/asm-powerpc/unistd_32.h        |   1 +
 linux-headers/asm-powerpc/unistd_64.h        |   1 +
 linux-headers/asm-riscv/bitsperlong.h        |  13 ++
 linux-headers/asm-riscv/kvm.h                |  16 ++
 linux-headers/asm-s390/kvm.h                 |  16 ++
 linux-headers/asm-s390/unistd_32.h           |   1 +
 linux-headers/asm-s390/unistd_64.h           |   1 +
 linux-headers/asm-x86/mman.h                 |  10 +-
 linux-headers/asm-x86/unistd_32.h            |   1 +
 linux-headers/asm-x86/unistd_64.h            |   2 +
 linux-headers/asm-x86/unistd_x32.h           |   1 +
 linux-headers/linux/kvm.h                    |  13 +-
 linux-headers/linux/stddef.h                 |   4 +
 linux-headers/linux/userfaultfd.h            |  25 +++-
 linux-headers/linux/vfio.h                   | 150 ++++++++++++++++++-
 23 files changed, 351 insertions(+), 16 deletions(-)
include/standard-headers/linux/fuse.h +62 -1
index 35c131a107..6b9793842c 100644
@@ -206,6 +206,11 @@
  *  - add extension header
  *  - add FUSE_EXT_GROUPS
  *  - add FUSE_CREATE_SUPP_GROUP
+ *  - add FUSE_HAS_EXPIRE_ONLY
+ *
+ *  7.39
+ *  - add FUSE_DIRECT_IO_RELAX
+ *  - add FUSE_STATX and related structures
  */
 
 #ifndef _LINUX_FUSE_H
@@ -237,7 +242,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 38
+#define FUSE_KERNEL_MINOR_VERSION 39
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -264,6 +269,40 @@ struct fuse_attr {
 	uint32_t	flags;
 };
 
+/*
+ * The following structures are bit-for-bit compatible with the statx(2) ABI in
+ * Linux.
+ */
+struct fuse_sx_time {
+	int64_t		tv_sec;
+	uint32_t	tv_nsec;
+	int32_t		__reserved;
+};
+
+struct fuse_statx {
+	uint32_t	mask;
+	uint32_t	blksize;
+	uint64_t	attributes;
+	uint32_t	nlink;
+	uint32_t	uid;
+	uint32_t	gid;
+	uint16_t	mode;
+	uint16_t	__spare0[1];
+	uint64_t	ino;
+	uint64_t	size;
+	uint64_t	blocks;
+	uint64_t	attributes_mask;
+	struct fuse_sx_time	atime;
+	struct fuse_sx_time	btime;
+	struct fuse_sx_time	ctime;
+	struct fuse_sx_time	mtime;
+	uint32_t	rdev_major;
+	uint32_t	rdev_minor;
+	uint32_t	dev_major;
+	uint32_t	dev_minor;
+	uint64_t	__spare2[14];
+};
+
 struct fuse_kstatfs {
 	uint64_t	blocks;
 	uint64_t	bfree;
@@ -365,6 +404,9 @@ struct fuse_file_lock {
  * FUSE_HAS_INODE_DAX:  use per inode DAX
  * FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir,
  *			symlink and mknod (single group that matches parent)
+ * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
+ * FUSE_DIRECT_IO_RELAX: relax restrictions in FOPEN_DIRECT_IO mode, for now
+ *                       allow shared mmap
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -402,6 +444,8 @@ struct fuse_file_lock {
 #define FUSE_SECURITY_CTX	(1ULL << 32)
 #define FUSE_HAS_INODE_DAX	(1ULL << 33)
 #define FUSE_CREATE_SUPP_GROUP	(1ULL << 34)
+#define FUSE_HAS_EXPIRE_ONLY	(1ULL << 35)
+#define FUSE_DIRECT_IO_RELAX	(1ULL << 36)
 
 /**
  * CUSE INIT request/reply flags
@@ -568,6 +612,7 @@ enum fuse_opcode {
 	FUSE_REMOVEMAPPING	= 49,
 	FUSE_SYNCFS		= 50,
 	FUSE_TMPFILE		= 51,
+	FUSE_STATX		= 52,
 
 	/* CUSE specific operations */
 	CUSE_INIT		= 4096,
@@ -632,6 +677,22 @@ struct fuse_attr_out {
 	struct fuse_attr attr;
 };
 
+struct fuse_statx_in {
+	uint32_t	getattr_flags;
+	uint32_t	reserved;
+	uint64_t	fh;
+	uint32_t	sx_flags;
+	uint32_t	sx_mask;
+};
+
+struct fuse_statx_out {
+	uint64_t	attr_valid;	/* Cache timeout for the attributes */
+	uint32_t	attr_valid_nsec;
+	uint32_t	flags;
+	uint64_t	spare[2];
+	struct fuse_statx stat;
+};
+
 #define FUSE_COMPAT_MKNOD_IN_SIZE 8
 
 struct fuse_mknod_in {
include/standard-headers/linux/vhost_types.h +4 -0
index 6691a3ce24..5ad07e134a 100644
@@ -181,5 +181,9 @@ struct vhost_vdpa_iova_range {
 #define VHOST_BACKEND_F_SUSPEND  0x4
 /* Device can be resumed */
 #define VHOST_BACKEND_F_RESUME  0x5
+/* Device supports the driver enabling virtqueues both before and after
+ * DRIVER_OK
+ */
+#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK  0x6
 
 #endif
include/standard-headers/linux/virtio_net.h +14 -0
index 2325485f2c..0f88417742 100644
@@ -56,6 +56,7 @@
 #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
 					 * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
+#define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
 #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
 #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
 #define VIRTIO_NET_F_GUEST_USO6	55	/* Guest can handle USOv6 in. */
@@ -391,5 +392,18 @@ struct virtio_net_ctrl_coal_rx {
 };
 
 #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET		1
+#define VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET		2
+#define VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET		3
+
+struct virtio_net_ctrl_coal {
+	uint32_t max_packets;
+	uint32_t max_usecs;
+};
+
+struct  virtio_net_ctrl_coal_vq {
+	uint16_t vqn;
+	uint16_t reserved;
+	struct virtio_net_ctrl_coal coal;
+};
 
 #endif /* _LINUX_VIRTIO_NET_H */
linux-headers/asm-arm64/bitsperlong.h +23 -0
index 6dc0bb0c13..485d60bee2 100644
@@ -1 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_BITSPERLONG_H
+#define __ASM_BITSPERLONG_H
+
+#define __BITS_PER_LONG 64
+
 #include <asm-generic/bitsperlong.h>
+
+#endif	/* __ASM_BITSPERLONG_H */
linux-headers/asm-generic/unistd.h +4 -1
index fd6c1cb585..abe087c53b 100644
@@ -820,8 +820,11 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
 #define __NR_cachestat 451
 __SYSCALL(__NR_cachestat, sys_cachestat)
 
+#define __NR_fchmodat2 452
+__SYSCALL(__NR_fchmodat2, sys_fchmodat2)
+
 #undef __NR_syscalls
-#define __NR_syscalls 452
+#define __NR_syscalls 453
 
 /*
  * 32 bit systems traditionally used different
linux-headers/asm-mips/unistd_n32.h +1 -0
index 8233f061c4..46d8500654 100644
@@ -380,5 +380,6 @@
 #define __NR_futex_waitv (__NR_Linux + 449)
 #define __NR_set_mempolicy_home_node (__NR_Linux + 450)
 #define __NR_cachestat (__NR_Linux + 451)
+#define __NR_fchmodat2 (__NR_Linux + 452)
 
 #endif /* _ASM_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +1 -0
index a174edc768..c2f7ac673b 100644
@@ -356,5 +356,6 @@
 #define __NR_futex_waitv (__NR_Linux + 449)
 #define __NR_set_mempolicy_home_node (__NR_Linux + 450)
 #define __NR_cachestat (__NR_Linux + 451)
+#define __NR_fchmodat2 (__NR_Linux + 452)
 
 #endif /* _ASM_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +1 -0
index c1a5351d9b..757c68f2ad 100644
@@ -426,5 +426,6 @@
 #define __NR_futex_waitv (__NR_Linux + 449)
 #define __NR_set_mempolicy_home_node (__NR_Linux + 450)
 #define __NR_cachestat (__NR_Linux + 451)
+#define __NR_fchmodat2 (__NR_Linux + 452)
 
 #endif /* _ASM_UNISTD_O32_H */
linux-headers/asm-powerpc/unistd_32.h +1 -0
index 8206758691..8ef94bbac1 100644
@@ -433,6 +433,7 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
 
 
 #endif /* _ASM_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +1 -0
index 7be98c15f0..0e7ee43e88 100644
@@ -405,6 +405,7 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-riscv/bitsperlong.h +13 -0
index 6dc0bb0c13..cc5c45a9ce 100644
@@ -1 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2015 Regents of the University of California
+ */
+
+#ifndef _ASM_RISCV_BITSPERLONG_H
+#define _ASM_RISCV_BITSPERLONG_H
+
+#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8)
+
 #include <asm-generic/bitsperlong.h>
+
+#endif /* _ASM_RISCV_BITSPERLONG_H */
linux-headers/asm-riscv/kvm.h +16 -0
index 930fdc4101..992c5e4071 100644
@@ -55,6 +55,7 @@ struct kvm_riscv_config {
 	unsigned long marchid;
 	unsigned long mimpid;
 	unsigned long zicboz_block_size;
+	unsigned long satp_mode;
 };
 
 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -124,6 +125,12 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_SSAIA,
 	KVM_RISCV_ISA_EXT_V,
 	KVM_RISCV_ISA_EXT_SVNAPOT,
+	KVM_RISCV_ISA_EXT_ZBA,
+	KVM_RISCV_ISA_EXT_ZBS,
+	KVM_RISCV_ISA_EXT_ZICNTR,
+	KVM_RISCV_ISA_EXT_ZICSR,
+	KVM_RISCV_ISA_EXT_ZIFENCEI,
+	KVM_RISCV_ISA_EXT_ZIHPM,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
@@ -193,6 +200,15 @@ enum KVM_RISCV_SBI_EXT_ID {
 
 /* ISA Extension registers are mapped as type 7 */
 #define KVM_REG_RISCV_ISA_EXT		(0x07 << KVM_REG_RISCV_TYPE_SHIFT)
+#define KVM_REG_RISCV_ISA_SINGLE	(0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_ISA_MULTI_EN	(0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_ISA_MULTI_DIS	(0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_ISA_MULTI_REG(__ext_id)	\
+		((__ext_id) / __BITS_PER_LONG)
+#define KVM_REG_RISCV_ISA_MULTI_MASK(__ext_id)	\
+		(1UL << ((__ext_id) % __BITS_PER_LONG))
+#define KVM_REG_RISCV_ISA_MULTI_REG_LAST	\
+		KVM_REG_RISCV_ISA_MULTI_REG(KVM_RISCV_ISA_EXT_MAX - 1)
 
 /* SBI extension registers are mapped as type 8 */
 #define KVM_REG_RISCV_SBI_EXT		(0x08 << KVM_REG_RISCV_TYPE_SHIFT)
linux-headers/asm-s390/kvm.h +16 -0
index e2afd95420..023a2763a9 100644
@@ -159,6 +159,22 @@ struct kvm_s390_vm_cpu_subfunc {
 	__u8 reserved[1728];
 };
 
+#define KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST	6
+#define KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST	7
+
+#define KVM_S390_VM_CPU_UV_FEAT_NR_BITS	64
+struct kvm_s390_vm_cpu_uv_feat {
+	union {
+		struct {
+			__u64 : 4;
+			__u64 ap : 1;		/* bit 4 */
+			__u64 ap_intr : 1;	/* bit 5 */
+			__u64 : 58;
+		};
+		__u64 feat;
+	};
+};
+
 /* kvm attributes for crypto */
 #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW	0
 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW	1
linux-headers/asm-s390/unistd_32.h +1 -0
index ef772cc5f8..716fa368ca 100644
@@ -424,5 +424,6 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
 
 #endif /* _ASM_S390_UNISTD_32_H */
linux-headers/asm-s390/unistd_64.h +1 -0
index 32354a0459..b2a11b1d13 100644
@@ -372,5 +372,6 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
 
 #endif /* _ASM_S390_UNISTD_64_H */
linux-headers/asm-x86/mman.h +3 -7
index 775dbd3aff..46cdc941f9 100644
@@ -3,14 +3,10 @@
 #define _ASM_X86_MMAN_H
 
 #define MAP_32BIT	0x40		/* only give out 32bit addresses */
+#define MAP_ABOVE4G	0x80		/* only map above 4GB */
 
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-#define arch_calc_vm_prot_bits(prot, key) (		\
-		((key) & 0x1 ? VM_PKEY_BIT0 : 0) |      \
-		((key) & 0x2 ? VM_PKEY_BIT1 : 0) |      \
-		((key) & 0x4 ? VM_PKEY_BIT2 : 0) |      \
-		((key) & 0x8 ? VM_PKEY_BIT3 : 0))
-#endif
+/* Flags for map_shadow_stack(2) */
+#define SHADOW_STACK_SET_TOKEN	(1ULL << 0)	/* Set up a restore token in the shadow stack */
 
 #include <asm-generic/mman.h>
 
linux-headers/asm-x86/unistd_32.h +1 -0
index 37b32d8139..d749ad1c24 100644
@@ -442,6 +442,7 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
 
 
 #endif /* _ASM_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +2 -0
index 5b55d6729a..cea67282eb 100644
@@ -364,6 +364,8 @@
 #define __NR_futex_waitv 449
 #define __NR_set_mempolicy_home_node 450
 #define __NR_cachestat 451
+#define __NR_fchmodat2 452
+#define __NR_map_shadow_stack 453
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +1 -0
index e8a007543d..5b2e79bf4c 100644
@@ -317,6 +317,7 @@
 #define __NR_futex_waitv (__X32_SYSCALL_BIT + 449)
 #define __NR_set_mempolicy_home_node (__X32_SYSCALL_BIT + 450)
 #define __NR_cachestat (__X32_SYSCALL_BIT + 451)
+#define __NR_fchmodat2 (__X32_SYSCALL_BIT + 452)
 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
 #define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/kvm.h +10 -3
index 1f3f3333a4..0d74ee999a 100644
@@ -1414,9 +1414,16 @@ struct kvm_device_attr {
 	__u64	addr;		/* userspace address of attr data */
 };
 
-#define  KVM_DEV_VFIO_GROUP			1
-#define   KVM_DEV_VFIO_GROUP_ADD			1
-#define   KVM_DEV_VFIO_GROUP_DEL			2
+#define  KVM_DEV_VFIO_FILE			1
+
+#define   KVM_DEV_VFIO_FILE_ADD			1
+#define   KVM_DEV_VFIO_FILE_DEL			2
+
+/* KVM_DEV_VFIO_GROUP aliases are for compile time uapi compatibility */
+#define  KVM_DEV_VFIO_GROUP	KVM_DEV_VFIO_FILE
+
+#define   KVM_DEV_VFIO_GROUP_ADD	KVM_DEV_VFIO_FILE_ADD
+#define   KVM_DEV_VFIO_GROUP_DEL	KVM_DEV_VFIO_FILE_DEL
 #define   KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE		3
 
 enum kvm_device_type {
linux-headers/linux/stddef.h +4 -0
index bb6ea517ef..9bb07083ac 100644
@@ -45,3 +45,7 @@
 		TYPE NAME[]; \
 	}
 #endif
+
+#ifndef __counted_by
+#define __counted_by(m)
+#endif
linux-headers/linux/userfaultfd.h +22 -3
index 14e402263a..59978fbaae 100644
@@ -39,7 +39,8 @@
 			   UFFD_FEATURE_MINOR_SHMEM |		\
 			   UFFD_FEATURE_EXACT_ADDRESS |		\
 			   UFFD_FEATURE_WP_HUGETLBFS_SHMEM |	\
-			   UFFD_FEATURE_WP_UNPOPULATED)
+			   UFFD_FEATURE_WP_UNPOPULATED |	\
+			   UFFD_FEATURE_POISON)
 #define UFFD_API_IOCTLS				\
 	((__u64)1 << _UFFDIO_REGISTER |		\
 	 (__u64)1 << _UFFDIO_UNREGISTER |	\
@@ -49,12 +50,14 @@
 	 (__u64)1 << _UFFDIO_COPY |		\
 	 (__u64)1 << _UFFDIO_ZEROPAGE |		\
 	 (__u64)1 << _UFFDIO_WRITEPROTECT |	\
-	 (__u64)1 << _UFFDIO_CONTINUE)
+	 (__u64)1 << _UFFDIO_CONTINUE |		\
+	 (__u64)1 << _UFFDIO_POISON)
 #define UFFD_API_RANGE_IOCTLS_BASIC		\
 	((__u64)1 << _UFFDIO_WAKE |		\
 	 (__u64)1 << _UFFDIO_COPY |		\
+	 (__u64)1 << _UFFDIO_WRITEPROTECT |	\
 	 (__u64)1 << _UFFDIO_CONTINUE |		\
-	 (__u64)1 << _UFFDIO_WRITEPROTECT)
+	 (__u64)1 << _UFFDIO_POISON)
 
 /*
  * Valid ioctl command number range with this API is from 0x00 to
@@ -71,6 +74,7 @@
 #define _UFFDIO_ZEROPAGE		(0x04)
 #define _UFFDIO_WRITEPROTECT		(0x06)
 #define _UFFDIO_CONTINUE		(0x07)
+#define _UFFDIO_POISON			(0x08)
 #define _UFFDIO_API			(0x3F)
 
 /* userfaultfd ioctl ids */
@@ -91,6 +95,8 @@
 				      struct uffdio_writeprotect)
 #define UFFDIO_CONTINUE		_IOWR(UFFDIO, _UFFDIO_CONTINUE,	\
 				      struct uffdio_continue)
+#define UFFDIO_POISON		_IOWR(UFFDIO, _UFFDIO_POISON, \
+				      struct uffdio_poison)
 
 /* read() structure */
 struct uffd_msg {
@@ -225,6 +231,7 @@ struct uffdio_api {
 #define UFFD_FEATURE_EXACT_ADDRESS		(1<<11)
 #define UFFD_FEATURE_WP_HUGETLBFS_SHMEM		(1<<12)
 #define UFFD_FEATURE_WP_UNPOPULATED		(1<<13)
+#define UFFD_FEATURE_POISON			(1<<14)
 	__u64 features;
 
 	__u64 ioctls;
@@ -321,6 +328,18 @@ struct uffdio_continue {
 	__s64 mapped;
 };
 
+struct uffdio_poison {
+	struct uffdio_range range;
+#define UFFDIO_POISON_MODE_DONTWAKE		((__u64)1<<0)
+	__u64 mode;
+
+	/*
+	 * Fields below here are written by the ioctl and must be at the end:
+	 * the copy_from_user will not read past here.
+	 */
+	__s64 updated;
+};
+
 /*
  * Flags for the userfaultfd(2) system call itself.
  */
linux-headers/linux/vfio.h +149 -1

190 lines not on this page · raw message

Signature · 1 line
2.41.0
#3 lore raw

[PULL 4/7] target/s390x/kvm: Refactor AP functionalities

In reply to Thomas Huth

From: Steffen Eiden <[email protected]>

kvm_s390_set_attr() is a misleading name as it only sets attributes for the KVM_S390_VM_CRYPTO group. Therefore, rename it to kvm_s390_set_crypto_attr().

Add new functions ap_available() and ap_enabled() to avoid code duplication later.

Message-ID: <[email protected]>

---
 target/s390x/kvm/kvm.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
target/s390x/kvm/kvm.c +17 -7
index 852fbd0df7..f034b06abc 100644
@@ -240,7 +240,7 @@ static void kvm_s390_enable_cmma(void)
     trace_kvm_enable_cmma(rc);
 }
 
-static void kvm_s390_set_attr(uint64_t attr)
+static void kvm_s390_set_crypto_attr(uint64_t attr)
 {
     struct kvm_device_attr attribute = {
         .group = KVM_S390_VM_CRYPTO,
@@ -265,7 +265,7 @@ static void kvm_s390_init_aes_kw(void)
     }
 
     if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
-            kvm_s390_set_attr(attr);
+            kvm_s390_set_crypto_attr(attr);
     }
 }
 
@@ -279,7 +279,7 @@ static void kvm_s390_init_dea_kw(void)
     }
 
     if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
-            kvm_s390_set_attr(attr);
+            kvm_s390_set_crypto_attr(attr);
     }
 }
 
@@ -2288,6 +2288,17 @@ static int configure_cpu_subfunc(const S390FeatBitmap features)
     return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+static bool ap_available(void)
+{
+    return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+                             KVM_S390_VM_CRYPTO_ENABLE_APIE);
+}
+
+static bool ap_enabled(const S390FeatBitmap features)
+{
+    return test_bit(S390_FEAT_AP, features);
+}
+
 static int kvm_to_feat[][2] = {
     { KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
     { KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
@@ -2467,8 +2478,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         return;
     }
     /* for now, we can only provide the AP feature with HW support */
-    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
-        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+    if (ap_available()) {
         set_bit(S390_FEAT_AP, model->features);
     }
 
@@ -2494,7 +2504,7 @@ static void kvm_s390_configure_apie(bool interpret)
                                 KVM_S390_VM_CRYPTO_DISABLE_APIE;
 
     if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
-        kvm_s390_set_attr(attr);
+        kvm_s390_set_crypto_attr(attr);
     }
 }
 
@@ -2548,7 +2558,7 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
         kvm_s390_enable_cmma();
     }
 
-    if (test_bit(S390_FEAT_AP, model->features)) {
+    if (ap_enabled(model->features)) {
         kvm_s390_configure_apie(true);
     }
 }
Signature · 1 line
2.41.0
#4 lore raw

[PULL 6/7] kconfig: Add NVME to s390x machines

In reply to Thomas Huth

From: Cédric Le Goater <[email protected]>

We recently had issues with nvme devices on big endian platforms. Include their compilation on s390x to ease tests.

Message-ID: <[email protected]>

---
 hw/nvme/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/Kconfig +1 -1
index 8ac90942e5..cfa2ab0f9d 100644
@@ -1,4 +1,4 @@
 config NVME_PCI
     bool
-    default y if PCI_DEVICES
+    default y if PCI_DEVICES || PCIE_DEVICES
     depends on PCI
Signature · 1 line
2.41.0
#5 lore raw

[PULL 7/7] tests/qtest/pflash: Clean up local variable shadowing

In reply to Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Fix:

tests/qtest/pflash-cfi02-test.c: In function ‘test_geometry’:
tests/qtest/pflash-cfi02-test.c:409:22: warning: declaration of ‘byte_addr’ shadows a previous local [-Wshadow=compatible-local]

    409 |             uint64_t byte_addr = (uint64_t)i * c->sector_len[region];
        |                      ^~~~~~~~~
  tests/qtest/pflash-cfi02-test.c:342:14: note: shadowed declaration is here
    342 |     uint64_t byte_addr = 0;
        |              ^~~~~~~~~

Message-ID: <[email protected]>

---
 tests/qtest/pflash-cfi02-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/pflash-cfi02-test.c +1 -1
index 0b52c2ca5c..8c073efcb4 100644
@@ -406,7 +406,7 @@ static void test_geometry(const void *opaque)
 
     for (int region = 0; region < nb_erase_regions; ++region) {
         for (uint32_t i = 0; i < c->nb_blocs[region]; ++i) {
-            uint64_t byte_addr = (uint64_t)i * c->sector_len[region];
+            byte_addr = (uint64_t)i * c->sector_len[region];
             g_assert_cmphex(flash_read(c, byte_addr), ==, bank_mask(c));
         }
     }
Signature · 1 line
2.41.0
#6 lore raw

[PULL 5/7] target/s390x: AP-passthrough for PV guests

In reply to Thomas Huth

From: Steffen Eiden <[email protected]>

Enabling AP-passthrough(AP-pt) for PV-guest by using the new CPU features for PV-AP-pt of KVM.

As usual QEMU first checks which CPU features are available and then sets them if available and selected by user. An additional check is done to verify that PV-AP can only be enabled if "regular" AP-pt is enabled as well. Note that KVM itself does not enforce this restriction.

Message-ID: <[email protected]>

---
 target/s390x/cpu_features.h         |  1 +
 target/s390x/cpu_features_def.h.inc |  4 ++
 target/s390x/cpu_models.c           |  2 +
 target/s390x/gen-features.c         |  2 +
 target/s390x/kvm/kvm.c              | 70 +++++++++++++++++++++++++++++
 5 files changed, 79 insertions(+)
target/s390x/cpu_features.h +1 -0
index 87463f064d..a9bd68a2e1 100644
@@ -43,6 +43,7 @@ typedef enum {
     S390_FEAT_TYPE_KDSA,
     S390_FEAT_TYPE_SORTL,
     S390_FEAT_TYPE_DFLTCC,
+    S390_FEAT_TYPE_UV_FEAT_GUEST,
 } S390FeatType;
 
 /* Definition of a CPU feature */
target/s390x/cpu_features_def.h.inc +4 -0
index e3cfe63735..e68da9b8ff 100644
@@ -379,3 +379,7 @@ DEF_FEAT(DEFLATE_GHDT, "dfltcc-gdht", DFLTCC, 1, "DFLTCC GDHT")
 DEF_FEAT(DEFLATE_CMPR, "dfltcc-cmpr", DFLTCC, 2, "DFLTCC CMPR")
 DEF_FEAT(DEFLATE_XPND, "dfltcc-xpnd", DFLTCC, 4, "DFLTCC XPND")
 DEF_FEAT(DEFLATE_F0, "dfltcc-f0", DFLTCC, 192, "DFLTCC format 0 parameter-block")
+
+/* Features exposed via the UV-CALL instruction */
+DEF_FEAT(UV_FEAT_AP, "appv", UV_FEAT_GUEST, 4, "AP instructions installed for secure guests")
+DEF_FEAT(UV_FEAT_AP_INTR, "appvi", UV_FEAT_GUEST, 5, "AP instructions interruption support for secure guests")
target/s390x/cpu_models.c +2 -0
index 91ce896491..98f14c09c2 100644
@@ -483,6 +483,8 @@ static void check_consistency(const S390CPUModel *model)
         { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB },
         { S390_FEAT_NNPA, S390_FEAT_VECTOR },
         { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING },
+        { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
+        { S390_FEAT_UV_FEAT_AP_INTR, S390_FEAT_UV_FEAT_AP },
     };
     int i;
 
target/s390x/gen-features.c +2 -0
index 1e3b7c0dc9..2b2bfc3736 100644
@@ -576,6 +576,8 @@ static uint16_t full_GEN16_GA1[] = {
     S390_FEAT_RDP,
     S390_FEAT_PAI,
     S390_FEAT_PAIE,
+    S390_FEAT_UV_FEAT_AP,
+    S390_FEAT_UV_FEAT_AP_INTR,
 };
 
 
target/s390x/kvm/kvm.c +70 -0

93 lines not on this page · raw message

Signature · 1 line
2.41.0
#7 lore raw

[PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

In reply to Thomas Huth

From: Janosch Frank <[email protected]>

Bound APQNs have to be reset before tearing down the secure config via s390_machine_unprotect(). Otherwise the Ultravisor will return a error code.

So let's do a subsystem_reset() which includes a AP reset before the unprotect call. We'll do a full device_reset() afterwards which will reset some devices twice. That's ok since we can't move the device_reset() before the unprotect as it includes a CPU clear reset which the Ultravisor does not expect at that point in time.

Message-ID: <[email protected]>

---
 hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/s390x/s390-virtio-ccw.c +10 -0
index 3dd0b2372d..2d75f2131f 100644
@@ -438,10 +438,20 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
     switch (reset_type) {
     case S390_RESET_EXTERNAL:
     case S390_RESET_REIPL:
+        /*
+         * Reset the subsystem which includes a AP reset. If a PV
+         * guest had APQNs attached the AP reset is a prerequisite to
+         * unprotecting since the UV checks if all APQNs are reset.
+         */
+        subsystem_reset();
         if (s390_is_pv()) {
             s390_machine_unprotect(ms);
         }
 
+        /*
+         * Device reset includes CPU clear resets so this has to be
+         * done AFTER the unprotect call above.
+         */
         qemu_devices_reset(reason);
         s390_crypto_reset();
 
Signature · 1 line
2.41.0
#8 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

Quoted 26 lines · Thomas Huth

From: Janosch Frank <[email protected]>

Bound APQNs have to be reset before tearing down the secure config via s390_machine_unprotect(). Otherwise the Ultravisor will return a error code.

So let's do a subsystem_reset() which includes a AP reset before the unprotect call. We'll do a full device_reset() afterwards which will reset some devices twice. That's ok since we can't move the device_reset() before the unprotect as it includes a CPU clear reset which the Ultravisor does not expect at that point in time.

Message-ID: <[email protected]>

---
  hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
hw/s390x/s390-virtio-ccw.c +0 -0
index 3dd0b2372d..2d75f2131f 100644

hw/s390x/s390-virtio-ccw.c static void s390_machine_reset(MachineState *machine, ShutdownCause reason) · line 446

Quoted 9 lines
hw/s390x/s390-virtio-ccw.c +6 -0
@@ -438,10 +438,20 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
      switch (reset_type) {
      case S390_RESET_EXTERNAL:
      case S390_RESET_REIPL:
+        /*
+         * Reset the subsystem which includes a AP reset. If a PV
+         * guest had APQNs attached the AP reset is a prerequisite to
+         * unprotecting since the UV checks if all APQNs are reset.
+         */
+        subsystem_reset();

This commit introduced a regression with pass-though ISM devices.

After startup, a reboot will generate extra device resets (vfio-pci in this case) which break the pass-though ISM device in a subtle way, probably related to IOMMU mapping according to 03451953c79e ("s390x/pci: reset ISM passthrough devices on shutdown and system reset"). After poweroff, the device is left in a sort-of-a-use state on the host and the LPAR has to be rebooted to clear the invalid state of the device. To be noted, that standard PCI devices are immune to this change.

The extra resets should avoided in some ways, (a shutdown notifier and a reset callback are already registered for ISM devices by 03451953c79e) and, most important, once the VM terminates, the device resources should be cleared in the host kernel. So there seem to be two issues to address in mainline QEMU and in Linux AFAICT.

Thanks,

C.

Quoted 11 lines
hw/s390x/s390-virtio-ccw.c +4 -0
          if (s390_is_pv()) {
              s390_machine_unprotect(ms);
          }
 
+        /*
+         * Device reset includes CPU clear resets so this has to be
+         * done AFTER the unprotect call above.
+         */
          qemu_devices_reset(reason);
          s390_crypto_reset();
 
#9 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

Quoted 40 lines · Cédric Le Goater
Quoted 27 lines · Thomas Huth

From: Janosch Frank <[email protected]>

Bound APQNs have to be reset before tearing down the secure config via s390_machine_unprotect(). Otherwise the Ultravisor will return a error code.

So let's do a subsystem_reset() which includes a AP reset before the unprotect call. We'll do a full device_reset() afterwards which will reset some devices twice. That's ok since we can't move the device_reset() before the unprotect as it includes a CPU clear reset which the Ultravisor does not expect at that point in time.

Message-ID: <[email protected]>

---
  hw/s390x/s390-virtio-ccw.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
hw/s390x/s390-virtio-ccw.c +0 -0
index 3dd0b2372d..2d75f2131f 100644
@@ -438,10 +438,20 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
       switch (reset_type) {
Quoted 8 lines

      case S390_RESET_EXTERNAL:
      case S390_RESET_REIPL:
+        /*
+         * Reset the subsystem which includes a AP reset. If a PV +         * guest had APQNs attached the AP reset is a prerequisite to +         * unprotecting since the UV checks if all APQNs are reset. +         */
+        subsystem_reset();

This commit introduced a regression with pass-though ISM devices.

Quoted 2 lines

After startup, a reboot will generate extra device resets (vfio-pci in this case) which break the pass-though ISM device in a subtle way,

Hi Cedric, thanks for reporting this... I was able to reproduce just now, and it looks like ISM firmware is unhappy specifically with this susbystem_reset call added by ef1535901a0, not necessarily the multiple attempts at reset -- I verified that reverting ef1535901a0 resolves the ISM issue, but if I instead try reverting the older 03451953c79e while leaving ef1535901a0 in place then ISM devices still break on guest reboot.

Quoted 6 lines

probably related to IOMMU mapping according to 03451953c79e ("s390x/pci: reset ISM passthrough devices on shutdown and system reset"). After poweroff, the device is left in a sort-of-a-use state on the host and the LPAR has to be rebooted to clear the invalid state of the device. To be noted, that standard PCI devices are immune to this change.

As a bit of background, ISM firmware is very sensitive re: the contents of the (host) IOMMU and attempts at manipulation that it deems to be out-of-order; the point of 03451953c79e was to ensure that the device gets a reset before we attempt at unmapping anything that wasn't cleaned up in an orderly fashion by the (guest) ism driver at the time of shutdown/reset (e.g. underlying firmware may view guest SBAs in the IOMMU as still registered for use and will throw an error condition at attempts to remove their entries in the IOMMU without first going through an unregistration process).

The unmap that would make ISM upset would generally be coming out of vfio_listener_region_del where we just do one big vfio_dma_unmap -- a quick trace shows that the subsystem_reset call added by ef1535901a0 is causing the vfio_listener_region_del to once again trigger before the pci reset of the ISM device, effectively re-introducing the condition that 03451953c79e was trying to resolve.

Quoted 3 lines

The extra resets should avoided in some ways, (a shutdown notifier and a reset callback are already registered for ISM devices by 03451953c79e)

So as mentioned above, it's not the extra resets that are the issue, it's the order of operations. Basically, we need to drive pci_device_reset for any ISM device associated with the guest before we destroy the vfio memory listener (now triggered in this case via subsystem_reset). So if we must drive this subsystem_reset before we trigger the device reset callbacks then it might require a s390 pci bus routine that is called before or during subystem_reset just to reset the ISM devices associated with this guest first; I'm not sure yet.

As an aside: I wonder why we are always doing the subsystem_reset here unconditionally rather than only when s390_is_pv() since that seems to be the only case that requires it.

Quoted 3 lines

and, most important, once the VM terminates, the device resources should be cleared in the host kernel. So there seem to be two issues to address in mainline QEMU and in Linux AFAICT.

Because of the condition detected by ISM firmware as described above, the host device was placed in an error state and remains in that state. After shutting down the guest, you should be able to use zpcictl --reset on the affected host device(s) to clear the error condition and re-enable it for use.

Thanks,
Matt

#10 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

Quoted 54 lines · Matthew Rosato
Quoted 40 lines · Cédric Le Goater
Quoted 26 lines · Thomas Huth

From: Janosch Frank <[email protected]>

Bound APQNs have to be reset before tearing down the secure config via s390_machine_unprotect(). Otherwise the Ultravisor will return a error code.

So let's do a subsystem_reset() which includes a AP reset before the unprotect call. We'll do a full device_reset() afterwards which will reset some devices twice. That's ok since we can't move the device_reset() before the unprotect as it includes a CPU clear reset which the Ultravisor does not expect at that point in time.

Message-ID: <[email protected]>

---
   hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
   1 file changed, 10 insertions(+)
hw/s390x/s390-virtio-ccw.c +0 -0
index 3dd0b2372d..2d75f2131f 100644

hw/s390x/s390-virtio-ccw.c static void s390_machine_reset(MachineState *machine, ShutdownCause reason) · line 446

Quoted 9 lines
hw/s390x/s390-virtio-ccw.c +6 -0
@@ -438,10 +438,20 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
       switch (reset_type) {
       case S390_RESET_EXTERNAL:
       case S390_RESET_REIPL:
+        /*
+         * Reset the subsystem which includes a AP reset. If a PV
+         * guest had APQNs attached the AP reset is a prerequisite to
+         * unprotecting since the UV checks if all APQNs are reset.
+         */
+        subsystem_reset();

This commit introduced a regression with pass-though ISM devices.

Quoted 2 lines

After startup, a reboot will generate extra device resets (vfio-pci in this case) which break the pass-though ISM device in a subtle way,

Hi Cedric, thanks for reporting this... I was able to reproduce just now, and it looks like ISM firmware is unhappy specifically with this susbystem_reset call added by ef1535901a0, not necessarily the multiple attempts at reset -- I verified that reverting ef1535901a0 resolves the ISM issue, but if I instead try reverting the older 03451953c79e while leaving ef1535901a0 in place then ISM devices still break on guest reboot.

Quoted 6 lines

probably related to IOMMU mapping according to 03451953c79e ("s390x/pci: reset ISM passthrough devices on shutdown and system reset"). After poweroff, the device is left in a sort-of-a-use state on the host and the LPAR has to be rebooted to clear the invalid state of the device. To be noted, that standard PCI devices are immune to this change.

Quoted 3 lines

As a bit of background, ISM firmware is very sensitive re: the contents of the (host) IOMMU and attempts at manipulation that it deems to be out-of-order; the point of 03451953c79e was to ensure that the device gets a reset before we attempt at unmapping anything that wasn't cleaned up in an orderly fashion by the (guest) ism driver at the time of shutdown/reset (e.g. underlying firmware may view guest SBAs in the IOMMU as still registered for use and will throw an error condition at attempts to remove their entries in the IOMMU without first going through an unregistration process).

The unmap that would make ISM upset would generally be coming out of vfio_listener_region_del where we just do one big vfio_dma_unmap -- a quick trace shows that the subsystem_reset call added by ef1535901a0 is causing the vfio_listener_region_del to once again trigger before the pci reset of the ISM device, effectively re-introducing the condition that 03451953c79e was trying to resolve.

Yes. I saw the vfio_listener_region_del trace coming first and came to the conclusion it was related to IOMMU mappings.

Quoted 6 lines
Quoted 2 lines

The extra resets should avoided in some ways, (a shutdown notifier and a reset callback are already registered for ISM devices by 03451953c79e)

So as mentioned above, it's not the extra resets that are the issue, it's the order of operations. Basically, we need to drive pci_device_reset for any ISM device associated with the guest before we destroy the vfio memory listener (now triggered in this case via subsystem_reset). So if we must drive this subsystem_reset before we trigger the device reset callbacks then it might require a s390 pci bus routine that is called before or during subystem_reset just to reset the ISM devices associated with this guest first; I'm not sure yet.

As an aside: I wonder why we are always doing the subsystem_reset here unconditionally rather than only when s390_is_pv() since that seems to be the only case that requires it.

That would be a start to workaround the issue.

Quoted 5 lines
Quoted 3 lines

and, most important, once the VM terminates, the device resources should be cleared in the host kernel. So there seem to be two issues to address in mainline QEMU and in Linux AFAICT.

Because of the condition detected by ISM firmware as described above, the host device was placed in an error state and remains in that state.

OK. this condition is considered serious enough to be reported to a management level. This seems a bit excessive since the recovery can be handled by software, but manually. Are there any plans to address this problem ?

Quoted 1 line

After shutting down the guest, you should be able to use zpcictl --reset on the affected host device(s) to clear the error condition and re-enable it for use.

ok. That's better than reboot.

On a side note, I am also seeing :

[   73.989688] ------------[ cut here ]------------
[   73.989696] unexpected non zero alert.mask 0x20
[   73.989748] WARNING: CPU: 9 PID: 4503 at arch/s390/kvm/interrupt.c:3214 kvm_s390_gisa_destroy+0xd4/0xe8 [kvm]
[   73.989791] Modules linked in: vfio_pci vfio_pci_core irqbypass vhost_net vhost vhost_iotlb tap tun xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 nft_compat nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables nfnetlink 8021q garp mrp rfkill sunrpc ext4 mbcache jbd2 vfio_ap zcrypt_cex4 vfio_ccw mdev vfio_iommu_type1 vfio drm fuse i2c_core drm_panel_orientation_quirks xfs libcrc32c dm_service_time mlx5_core sd_mod t10_pi ghash_s390 sg prng des_s390 libdes sha3_512_s390 sha3_256_s390 mlxfw tls scm_block psample eadm_sch qeth_l2 bridge stp llc dasd_eckd_mod zfcp qeth dasd_mod scsi_transport_fc ccwgroup qdio dm_multipath dm_mirror dm_region_hash dm_log dm_mod pkey zcrypt kvm aes_s390
[   73.989825] CPU: 9 PID: 4503 Comm: worker Kdump: loaded Not tainted 6.7.0-clg-dirty #52
[   73.989827] Hardware name: IBM 3931 LA1 400 (LPAR)
[   73.989829] Krnl PSW : 0704c00180000000 000003ff7fcd2198 (kvm_s390_gisa_destroy+0xd8/0xe8 [kvm])
[   73.989845]            R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[   73.989847] Krnl GPRS: c0000000fffeffff 0000000700000027 0000000000000023 00000007df4249c8
[   73.989849]            000003800649b858 000003800649b850 00000007fcb9db00 0000000000000000
[   73.989851]            000000008ebae8c8 0000000083a8c4f0 0000000000b69900 000000008ebac000
[   73.989853]            000003ff903aef68 000003800649bd98 000003ff7fcd2194 000003800649b9f8
[   73.989859] Krnl Code: 000003ff7fcd2188: c02000024f88	larl	%r2,000003ff7fd1c098
                          000003ff7fcd218e: c0e5fffea360	brasl	%r14,000003ff7fca684e
                         #000003ff7fcd2194: af000000		mc	0,0
                         >000003ff7fcd2198: e310b7680204	lg	%r1,10088(%r11)
                          000003ff7fcd219e: a7f4ffae		brc	15,000003ff7fcd20fa
                          000003ff7fcd21a2: 0707		bcr	0,%r7
                          000003ff7fcd21a4: 0707		bcr	0,%r7
                          000003ff7fcd21a6: 0707		bcr	0,%r7
[   73.989929] Call Trace:
[   73.989931]  [<000003ff7fcd2198>] kvm_s390_gisa_destroy+0xd8/0xe8 [kvm]
[   73.989946] ([<000003ff7fcd2194>] kvm_s390_gisa_destroy+0xd4/0xe8 [kvm])
[   73.989960]  [<000003ff7fcc1578>] kvm_arch_destroy_vm+0x50/0x118 [kvm]
[   73.989974]  [<000003ff7fcb00a2>] kvm_destroy_vm+0x15a/0x260 [kvm]
[   73.989985]  [<000003ff7fcb021e>] kvm_vm_release+0x36/0x48 [kvm]
[   73.989996]  [<00000007de4f830c>] __fput+0x94/0x2d0
[   73.990009]  [<00000007de20d838>] task_work_run+0x88/0xe8
[   73.990013]  [<00000007de1e75e0>] do_exit+0x2e0/0x4e0
[   73.990016]  [<00000007de1e79c0>] do_group_exit+0x40/0xb8
[   73.990017]  [<00000007de1f96e8>] send_sig_info+0x0/0xa8
[   73.990021]  [<00000007de194b26>] arch_do_signal_or_restart+0x56/0x318
[   73.990025]  [<00000007de28bf12>] exit_to_user_mode_prepare+0x10a/0x1a0
[   73.990028]  [<00000007deb607d2>] __do_syscall+0x152/0x1f8
[   73.990032]  [<00000007deb70ac8>] system_call+0x70/0x98
[   73.990036] Last Breaking-Event-Address:
[   73.990037]  [<00000007de1e0c58>] __warn_printk+0x78/0xe8

Thanks,

C.

#11 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

Am 11.01.24 um 10:43 schrieb Cédric Le Goater:
[...]

Quoted 3 lines

On a side note, I am also seeing :

Michael?

Quoted 40 lines

[   73.989688] ------------[ cut here ]------------
[   73.989696] unexpected non zero alert.mask 0x20
[   73.989748] WARNING: CPU: 9 PID: 4503 at arch/s390/kvm/interrupt.c:3214 kvm_s390_gisa_destroy+0xd4/0xe8 [kvm]
[   73.989791] Modules linked in: vfio_pci vfio_pci_core irqbypass vhost_net vhost vhost_iotlb tap tun xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 nft_compat nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables nfnetlink 8021q garp mrp rfkill sunrpc ext4 mbcache jbd2 vfio_ap zcrypt_cex4 vfio_ccw mdev vfio_iommu_type1 vfio drm fuse i2c_core drm_panel_orientation_quirks xfs libcrc32c dm_service_time mlx5_core sd_mod t10_pi ghash_s390 sg prng des_s390 libdes sha3_512_s390 sha3_256_s390 mlxfw tls scm_block psample eadm_sch qeth_l2 bridge stp llc dasd_eckd_mod zfcp qeth dasd_mod scsi_transport_fc ccwgroup qdio dm_multipath dm_mirror dm_region_hash dm_log dm_mod pkey zcrypt kvm aes_s390 [   73.989825] CPU: 9 PID: 4503 Comm: worker Kdump: loaded Not tainted 6.7.0-clg-dirty #52
[   73.989827] Hardware name: IBM 3931 LA1 400 (LPAR)
[   73.989829] Krnl PSW : 0704c00180000000 000003ff7fcd2198 (kvm_s390_gisa_destroy+0xd8/0xe8 [kvm])
[   73.989845]            R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[   73.989847] Krnl GPRS: c0000000fffeffff 0000000700000027 0000000000000023 00000007df4249c8
[   73.989849]            000003800649b858 000003800649b850 00000007fcb9db00 0000000000000000
[   73.989851]            000000008ebae8c8 0000000083a8c4f0 0000000000b69900 000000008ebac000
[   73.989853]            000003ff903aef68 000003800649bd98 000003ff7fcd2194 000003800649b9f8
[   73.989859] Krnl Code: 000003ff7fcd2188: c02000024f88    larl    %r2,000003ff7fd1c098
                          000003ff7fcd218e: c0e5fffea360    brasl    %r14,000003ff7fca684e
                         #000003ff7fcd2194: af000000        mc    0,0
                         >000003ff7fcd2198: e310b7680204    lg    %r1,10088(%r11)
                          000003ff7fcd219e: a7f4ffae        brc    15,000003ff7fcd20fa
                          000003ff7fcd21a2: 0707        bcr    0,%r7
                          000003ff7fcd21a4: 0707        bcr    0,%r7
                          000003ff7fcd21a6: 0707        bcr    0,%r7
[   73.989929] Call Trace:
[   73.989931]  [<000003ff7fcd2198>] kvm_s390_gisa_destroy+0xd8/0xe8 [kvm]
[   73.989946] ([<000003ff7fcd2194>] kvm_s390_gisa_destroy+0xd4/0xe8 [kvm])
[   73.989960]  [<000003ff7fcc1578>] kvm_arch_destroy_vm+0x50/0x118 [kvm]
[   73.989974]  [<000003ff7fcb00a2>] kvm_destroy_vm+0x15a/0x260 [kvm]
[   73.989985]  [<000003ff7fcb021e>] kvm_vm_release+0x36/0x48 [kvm]
[   73.989996]  [<00000007de4f830c>] __fput+0x94/0x2d0
[   73.990009]  [<00000007de20d838>] task_work_run+0x88/0xe8
[   73.990013]  [<00000007de1e75e0>] do_exit+0x2e0/0x4e0
[   73.990016]  [<00000007de1e79c0>] do_group_exit+0x40/0xb8
[   73.990017]  [<00000007de1f96e8>] send_sig_info+0x0/0xa8
[   73.990021]  [<00000007de194b26>] arch_do_signal_or_restart+0x56/0x318
[   73.990025]  [<00000007de28bf12>] exit_to_user_mode_prepare+0x10a/0x1a0
[   73.990028]  [<00000007deb607d2>] __do_syscall+0x152/0x1f8
[   73.990032]  [<00000007deb70ac8>] system_call+0x70/0x98
[   73.990036] Last Breaking-Event-Address:
[   73.990037]  [<00000007de1e0c58>] __warn_printk+0x78/0xe8

#12 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

Quoted 10 lines · Christian Borntraeger

Am 11.01.24 um 10:43 schrieb Cédric Le Goater:
[...]

Quoted 3 lines

On a side note, I am also seeing :

Michael?

Hmm, it looks like this warning is tripping because we have a path in PCI passthrough where we don't unregister the gisc. This warning notices that at the time we destroy the VM (it believes that are still consumers of the guest ISC so the bit in the alert mask is still on) -- after cutting the warning the code forces the alerts off at least.

Not sure yet if that is directly related to the device going into error condition or if it is an independent issue, will have a look.

Quoted 40 lines
Quoted 40 lines

[   73.989688] ------------[ cut here ]------------
[   73.989696] unexpected non zero alert.mask 0x20
[   73.989748] WARNING: CPU: 9 PID: 4503 at arch/s390/kvm/interrupt.c:3214 kvm_s390_gisa_destroy+0xd4/0xe8 [kvm]
[   73.989791] Modules linked in: vfio_pci vfio_pci_core irqbypass vhost_net vhost vhost_iotlb tap tun xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 nft_compat nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables nfnetlink 8021q garp mrp rfkill sunrpc ext4 mbcache jbd2 vfio_ap zcrypt_cex4 vfio_ccw mdev vfio_iommu_type1 vfio drm fuse i2c_core drm_panel_orientation_quirks xfs libcrc32c dm_service_time mlx5_core sd_mod t10_pi ghash_s390 sg prng des_s390 libdes sha3_512_s390 sha3_256_s390 mlxfw tls scm_block psample eadm_sch qeth_l2 bridge stp llc dasd_eckd_mod zfcp qeth dasd_mod scsi_transport_fc ccwgroup qdio dm_multipath dm_mirror dm_region_hash dm_log dm_mod pkey zcrypt kvm aes_s390 [   73.989825] CPU: 9 PID: 4503 Comm: worker Kdump: loaded Not tainted 6.7.0-clg-dirty #52
[   73.989827] Hardware name: IBM 3931 LA1 400 (LPAR)
[   73.989829] Krnl PSW : 0704c00180000000 000003ff7fcd2198 (kvm_s390_gisa_destroy+0xd8/0xe8 [kvm])
[   73.989845]            R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[   73.989847] Krnl GPRS: c0000000fffeffff 0000000700000027 0000000000000023 00000007df4249c8
[   73.989849]            000003800649b858 000003800649b850 00000007fcb9db00 0000000000000000
[   73.989851]            000000008ebae8c8 0000000083a8c4f0 0000000000b69900 000000008ebac000
[   73.989853]            000003ff903aef68 000003800649bd98 000003ff7fcd2194 000003800649b9f8
[   73.989859] Krnl Code: 000003ff7fcd2188: c02000024f88    larl    %r2,000003ff7fd1c098
                           000003ff7fcd218e: c0e5fffea360    brasl    %r14,000003ff7fca684e
                          #000003ff7fcd2194: af000000        mc    0,0
                          >000003ff7fcd2198: e310b7680204    lg    %r1,10088(%r11)
                           000003ff7fcd219e: a7f4ffae        brc    15,000003ff7fcd20fa
                           000003ff7fcd21a2: 0707        bcr    0,%r7
                           000003ff7fcd21a4: 0707        bcr    0,%r7
                           000003ff7fcd21a6: 0707        bcr    0,%r7
[   73.989929] Call Trace:
[   73.989931]  [<000003ff7fcd2198>] kvm_s390_gisa_destroy+0xd8/0xe8 [kvm]
[   73.989946] ([<000003ff7fcd2194>] kvm_s390_gisa_destroy+0xd4/0xe8 [kvm])
[   73.989960]  [<000003ff7fcc1578>] kvm_arch_destroy_vm+0x50/0x118 [kvm]
[   73.989974]  [<000003ff7fcb00a2>] kvm_destroy_vm+0x15a/0x260 [kvm]
[   73.989985]  [<000003ff7fcb021e>] kvm_vm_release+0x36/0x48 [kvm]
[   73.989996]  [<00000007de4f830c>] __fput+0x94/0x2d0
[   73.990009]  [<00000007de20d838>] task_work_run+0x88/0xe8
[   73.990013]  [<00000007de1e75e0>] do_exit+0x2e0/0x4e0
[   73.990016]  [<00000007de1e79c0>] do_group_exit+0x40/0xb8
[   73.990017]  [<00000007de1f96e8>] send_sig_info+0x0/0xa8
[   73.990021]  [<00000007de194b26>] arch_do_signal_or_restart+0x56/0x318
[   73.990025]  [<00000007de28bf12>] exit_to_user_mode_prepare+0x10a/0x1a0
[   73.990028]  [<00000007deb607d2>] __do_syscall+0x152/0x1f8
[   73.990032]  [<00000007deb70ac8>] system_call+0x70/0x98
[   73.990036] Last Breaking-Event-Address:
[   73.990037]  [<00000007de1e0c58>] __warn_printk+0x78/0xe8

#13 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

In reply to Cédric Le Goater
Quoted 62 lines · Cédric Le Goater
Quoted 54 lines · Matthew Rosato
Quoted 40 lines · Cédric Le Goater
Quoted 26 lines · Thomas Huth

From: Janosch Frank <[email protected]>

Bound APQNs have to be reset before tearing down the secure config via s390_machine_unprotect(). Otherwise the Ultravisor will return a error code.

So let's do a subsystem_reset() which includes a AP reset before the unprotect call. We'll do a full device_reset() afterwards which will reset some devices twice. That's ok since we can't move the device_reset() before the unprotect as it includes a CPU clear reset which the Ultravisor does not expect at that point in time.

Message-ID: <[email protected]>

---
    hw/s390x/s390-virtio-ccw.c | 10 ++++++++++
    1 file changed, 10 insertions(+)
hw/s390x/s390-virtio-ccw.c +0 -0
index 3dd0b2372d..2d75f2131f 100644

hw/s390x/s390-virtio-ccw.c static void s390_machine_reset(MachineState *machine, ShutdownCause reason) · line 446

Quoted 9 lines
hw/s390x/s390-virtio-ccw.c +6 -0
@@ -438,10 +438,20 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
        switch (reset_type) {
        case S390_RESET_EXTERNAL:
        case S390_RESET_REIPL:
+        /*
+         * Reset the subsystem which includes a AP reset. If a PV
+         * guest had APQNs attached the AP reset is a prerequisite to
+         * unprotecting since the UV checks if all APQNs are reset.
+         */
+        subsystem_reset();

This commit introduced a regression with pass-though ISM devices.

Quoted 2 lines

After startup, a reboot will generate extra device resets (vfio-pci in this case) which break the pass-though ISM device in a subtle way,

Hi Cedric, thanks for reporting this... I was able to reproduce just now, and it looks like ISM firmware is unhappy specifically with this susbystem_reset call added by ef1535901a0, not necessarily the multiple attempts at reset -- I verified that reverting ef1535901a0 resolves the ISM issue, but if I instead try reverting the older 03451953c79e while leaving ef1535901a0 in place then ISM devices still break on guest reboot.

Quoted 6 lines

probably related to IOMMU mapping according to 03451953c79e ("s390x/pci: reset ISM passthrough devices on shutdown and system reset"). After poweroff, the device is left in a sort-of-a-use state on the host and the LPAR has to be rebooted to clear the invalid state of the device. To be noted, that standard PCI devices are immune to this change.

Quoted 3 lines

As a bit of background, ISM firmware is very sensitive re: the contents of the (host) IOMMU and attempts at manipulation that it deems to be out-of-order; the point of 03451953c79e was to ensure that the device gets a reset before we attempt at unmapping anything that wasn't cleaned up in an orderly fashion by the (guest) ism driver at the time of shutdown/reset (e.g. underlying firmware may view guest SBAs in the IOMMU as still registered for use and will throw an error condition at attempts to remove their entries in the IOMMU without first going through an unregistration process).

The unmap that would make ISM upset would generally be coming out of vfio_listener_region_del where we just do one big vfio_dma_unmap -- a quick trace shows that the subsystem_reset call added by ef1535901a0 is causing the vfio_listener_region_del to once again trigger before the pci reset of the ISM device, effectively re-introducing the condition that 03451953c79e was trying to resolve.

Yes. I saw the vfio_listener_region_del trace coming first and came to the conclusion it was related to IOMMU mappings.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

The extra resets should avoided in some ways, (a shutdown notifier and a reset callback are already registered for ISM devices by 03451953c79e)

So as mentioned above, it's not the extra resets that are the issue, it's the order of operations. Basically, we need to drive pci_device_reset for any ISM device associated with the guest before we destroy the vfio memory listener (now triggered in this case via subsystem_reset). So if we must drive this subsystem_reset before we trigger the device reset callbacks then it might require a s390 pci bus routine that is called before or during subystem_reset just to reset the ISM devices associated with this guest first; I'm not sure yet.

As an aside: I wonder why we are always doing the subsystem_reset here unconditionally rather than only when s390_is_pv() since that seems to be the only case that requires it.

That would be a start to workaround the issue.

I can have a look into that, I'm just a bit hesitant since there's an ominous feeling in my brain that tells me that there might have been a reason that I forgot after this patch was pulled.

#14 lore raw

Re: [PULL 2/7] s390x: do a subsystem reset before the unprotect on reboot

In reply to Cédric Le Goater
Quoted 4 lines · Cédric Le Goater

OK. this condition is considered serious enough to be reported to a management level. This seems a bit excessive since the recovery can be handled by software, but manually. Are there any plans to address this problem ?

Yes, eventually. Currently for drivers other than QEMU+vfio-pci we rely on automated PCI recovery to handle this event, but today we do not forward the event to QEMU when using vfio-pci because the code in vfio_err_notifier_handler will halt the guest. This leaves the device in an error state to be recovered manually. The intent is to eventually address this by triggering the guest to initiate the recovery action rather than halting the guest for s390.