target/riscv: add RVV CSRs
v2 cover target/riscv: add RVV CSRs
Hi,
This version was rebased on top of Alistair's riscv-to-apply.next. A small tweak was needed in patch 4 due to changes in the branch.
I took the chance to update linux-headers to 6.7-rc5, although the differences from the rc3 headers from v1 were minimal.
All patches acked.
Changes from v1:
- rebased to Alistair's riscv-to-apply.next
- patch 1:
- updated headers to v6.7-rc5
- patch 4:
- use kvm_riscv_reg_id_ulong() instead of kvm_riscv_reg_id()
- v1 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Daniel Henrique Barboza (4):
linux-headers: Update to Linux v6.7-rc5
linux-headers: riscv: add ptrace.h target/riscv/kvm: do PR_RISCV_V_SET_CONTROL during realize() target/riscv/kvm: add RVV and Vector CSR regs
include/standard-headers/drm/drm_fourcc.h | 2 + include/standard-headers/linux/pci_regs.h | 24 ++- include/standard-headers/linux/vhost_types.h | 7 + .../standard-headers/linux/virtio_config.h | 5 + include/standard-headers/linux/virtio_pci.h | 11 ++ linux-headers/asm-arm64/kvm.h | 32 ++++ linux-headers/asm-generic/unistd.h | 14 +- linux-headers/asm-loongarch/bitsperlong.h | 1 + linux-headers/asm-loongarch/kvm.h | 108 +++++++++++ linux-headers/asm-loongarch/mman.h | 1 + linux-headers/asm-loongarch/unistd.h | 5 + linux-headers/asm-mips/unistd_n32.h | 4 + linux-headers/asm-mips/unistd_n64.h | 4 + linux-headers/asm-mips/unistd_o32.h | 4 + linux-headers/asm-powerpc/unistd_32.h | 4 + linux-headers/asm-powerpc/unistd_64.h | 4 + linux-headers/asm-riscv/kvm.h | 12 ++ linux-headers/asm-riscv/ptrace.h | 132 +++++++++++++ linux-headers/asm-s390/unistd_32.h | 4 + linux-headers/asm-s390/unistd_64.h | 4 + linux-headers/asm-x86/unistd_32.h | 4 + linux-headers/asm-x86/unistd_64.h | 3 + linux-headers/asm-x86/unistd_x32.h | 3 + linux-headers/linux/iommufd.h | 180 +++++++++++++++++- linux-headers/linux/kvm.h | 11 ++ linux-headers/linux/psp-sev.h | 1 + linux-headers/linux/stddef.h | 9 +- linux-headers/linux/userfaultfd.h | 9 +- linux-headers/linux/vfio.h | 47 +++-- linux-headers/linux/vhost.h | 8 + scripts/update-linux-headers.sh | 3 + target/riscv/kvm/kvm-cpu.c | 103 ++++++++++ 32 files changed, 736 insertions(+), 27 deletions(-) create mode 100644 linux-headers/asm-loongarch/bitsperlong.h create mode 100644 linux-headers/asm-loongarch/kvm.h create mode 100644 linux-headers/asm-loongarch/mman.h create mode 100644 linux-headers/asm-loongarch/unistd.h create mode 100644 linux-headers/asm-riscv/ptrace.h
Signature · 1 line
2.43.0
PATCH v2 1/4 linux-headers: Update to Linux v6.7-rc5
We'll add a new RISC-V linux-header file, but first let's update all headers.
Headers for 'asm-loongarch' were added in this update.
--- include/standard-headers/drm/drm_fourcc.h | 2 + include/standard-headers/linux/pci_regs.h | 24 ++- include/standard-headers/linux/vhost_types.h | 7 + .../standard-headers/linux/virtio_config.h | 5 + include/standard-headers/linux/virtio_pci.h | 11 ++ linux-headers/asm-arm64/kvm.h | 32 ++++ linux-headers/asm-generic/unistd.h | 14 +- linux-headers/asm-loongarch/bitsperlong.h | 1 + linux-headers/asm-loongarch/kvm.h | 108 +++++++++++ linux-headers/asm-loongarch/mman.h | 1 + linux-headers/asm-loongarch/unistd.h | 5 + linux-headers/asm-mips/unistd_n32.h | 4 + linux-headers/asm-mips/unistd_n64.h | 4 + linux-headers/asm-mips/unistd_o32.h | 4 + linux-headers/asm-powerpc/unistd_32.h | 4 + linux-headers/asm-powerpc/unistd_64.h | 4 + linux-headers/asm-riscv/kvm.h | 12 ++ linux-headers/asm-s390/unistd_32.h | 4 + linux-headers/asm-s390/unistd_64.h | 4 + linux-headers/asm-x86/unistd_32.h | 4 + linux-headers/asm-x86/unistd_64.h | 3 + linux-headers/asm-x86/unistd_x32.h | 3 + linux-headers/linux/iommufd.h | 180 +++++++++++++++++- linux-headers/linux/kvm.h | 11 ++ linux-headers/linux/psp-sev.h | 1 + linux-headers/linux/stddef.h | 9 +- linux-headers/linux/userfaultfd.h | 9 +- linux-headers/linux/vfio.h | 47 +++-- linux-headers/linux/vhost.h | 8 + 29 files changed, 498 insertions(+), 27 deletions(-) create mode 100644 linux-headers/asm-loongarch/bitsperlong.h create mode 100644 linux-headers/asm-loongarch/kvm.h create mode 100644 linux-headers/asm-loongarch/mman.h create mode 100644 linux-headers/asm-loongarch/unistd.h
include/standard-headers/drm/drm_fourcc.h +2 -0
@@ -322,6 +322,8 @@ extern "C" {* index 1 = Cr:Cb plane, [39:0] Cr1:Cb1:Cr0:Cb0 little endian */ #define DRM_FORMAT_NV15 fourcc_code('N', 'V', '1', '5')/* 2x2 subsampled Cr:Cb plane */ +#define DRM_FORMAT_NV20 fourcc_code('N', 'V', '2', '0')/* 2x1 subsampled Cr:Cb plane */ +#define DRM_FORMAT_NV30 fourcc_code('N', 'V', '3', '0')/* non-subsampled Cr:Cb plane */ /* * 2 plane YCbCr MSB aligned
include/standard-headers/linux/pci_regs.h +19 -5
@@ -80,6 +80,7 @@#define PCI_HEADER_TYPE_NORMAL 0#define PCI_HEADER_TYPE_BRIDGE 1#define PCI_HEADER_TYPE_CARDBUS 2 +#define PCI_HEADER_TYPE_MFD 0x80/* Multi-Function Device (possible) */ #define PCI_BIST 0x0f/* 8 bits */ #define PCI_BIST_CODE_MASK 0x0f/* Return result */
@@ -637,6 +638,7 @@#define PCI_EXP_RTCAP 0x1e/* Root Capabilities */ #define PCI_EXP_RTCAP_CRSVIS 0x0001/* CRS Software Visibility capability */ #define PCI_EXP_RTSTA 0x20/* Root Status */ +#define PCI_EXP_RTSTA_PME_RQ_ID 0x0000ffff/* PME Requester ID */ #define PCI_EXP_RTSTA_PME 0x00010000/* PME status */ #define PCI_EXP_RTSTA_PENDING 0x00020000/* PME pending */ /*
@@ -930,12 +932,13 @@/* Process Address Space ID */ #define PCI_PASID_CAP 0x04/* PASID feature register */ -#define PCI_PASID_CAP_EXEC 0x02/* Exec permissions Supported */ -#define PCI_PASID_CAP_PRIV 0x04/* Privilege Mode Supported */ +#define PCI_PASID_CAP_EXEC 0x0002/* Exec permissions Supported */ +#define PCI_PASID_CAP_PRIV 0x0004/* Privilege Mode Supported */ +#define PCI_PASID_CAP_WIDTH 0x1f00#define PCI_PASID_CTRL 0x06/* PASID control register */ -#define PCI_PASID_CTRL_ENABLE 0x01/* Enable bit */ -#define PCI_PASID_CTRL_EXEC 0x02/* Exec permissions Enable */ -#define PCI_PASID_CTRL_PRIV 0x04/* Privilege Mode Enable */ +#define PCI_PASID_CTRL_ENABLE 0x0001/* Enable bit */ +#define PCI_PASID_CTRL_EXEC 0x0002/* Exec permissions Enable */ +#define PCI_PASID_CTRL_PRIV 0x0004/* Privilege Mode Enable */ #define PCI_EXT_CAP_PASID_SIZEOF 8/* Single Root I/O Virtualization */
@@ -975,6 +978,8 @@#define PCI_LTR_VALUE_MASK 0x000003ff#define PCI_LTR_SCALE_MASK 0x00001c00#define PCI_LTR_SCALE_SHIFT 10 +#define PCI_LTR_NOSNOOP_VALUE 0x03ff0000/* Max No-Snoop Latency Value */ +#define PCI_LTR_NOSNOOP_SCALE 0x1c000000/* Scale for Max Value */ #define PCI_EXT_CAP_LTR_SIZEOF 8/* Access Control Service */
@@ -1042,9 +1047,16 @@#define PCI_EXP_DPC_STATUS 0x08/* DPC Status */ #define PCI_EXP_DPC_STATUS_TRIGGER 0x0001/* Trigger Status */ #define PCI_EXP_DPC_STATUS_TRIGGER_RSN 0x0006/* Trigger Reason */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_UNCOR 0x0000/* Uncorrectable error */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_NFE 0x0002/* Rcvd ERR_NONFATAL */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_FE 0x0004/* Rcvd ERR_FATAL */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_IN_EXT 0x0006/* Reason in Trig Reason Extension field */ #define PCI_EXP_DPC_STATUS_INTERRUPT 0x0008/* Interrupt Status */ #define PCI_EXP_DPC_RP_BUSY 0x0010/* Root Port Busy */ #define PCI_EXP_DPC_STATUS_TRIGGER_RSN_EXT 0x0060/* Trig Reason Extension */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_RP_PIO 0x0000/* RP PIO error */ +#define PCI_EXP_DPC_STATUS_TRIGGER_RSN_SW_TRIGGER 0x0020/* DPC SW Trigger bit */ +#define PCI_EXP_DPC_RP_PIO_FEP 0x1f00/* RP PIO First Err Ptr */ #define PCI_EXP_DPC_SOURCE_ID 0x0A/* DPC Source Identifier */
@@ -1088,6 +1100,8 @@#define PCI_L1SS_CTL1_LTR_L12_TH_VALUE 0x03ff0000/* LTR_L1.2_THRESHOLD_Value */ #define PCI_L1SS_CTL1_LTR_L12_TH_SCALE 0xe0000000/* LTR_L1.2_THRESHOLD_Scale */ #define PCI_L1SS_CTL2 0x0c/* Control 2 Register */ +#define PCI_L1SS_CTL2_T_PWR_ON_SCALE 0x00000003/* T_POWER_ON Scale */ +#define PCI_L1SS_CTL2_T_PWR_ON_VALUE 0x000000f8/* T_POWER_ON Value */ /* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */ #define PCI_DVSEC_HEADER1 0x4/* Designated Vendor-Specific Header1 */
include/standard-headers/linux/vhost_types.h +7 -0
@@ -185,5 +185,12 @@ struct vhost_vdpa_iova_range {* DRIVER_OK */ #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 +/* Device may expose the virtqueue's descriptor area, driver area and +* device area to a different group for ASID binding than where its +* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. +*/ +#define VHOST_BACKEND_F_DESC_ASID 0x7 +/* IOTLB don't flush memory mapping across device reset */ +#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8#endif
include/standard-headers/linux/virtio_config.h +5 -0
@@ -103,6 +103,11 @@*/ #define VIRTIO_F_NOTIFICATION_DATA 38 +/* This feature indicates that the driver uses the data provided by the device +* as a virtqueue identifier in available buffer notifications. +*/ +#define VIRTIO_F_NOTIF_CONFIG_DATA 39 +/* * This feature indicates that the driver can reset a queue individually. */
include/standard-headers/linux/virtio_pci.h +11 -0
@@ -166,6 +166,17 @@ struct virtio_pci_common_cfg {uint32_t queue_used_hi;/* read-write */ }; +/* +* Warning: do not use sizeof on this: use offsetofend for +* specific fields you need. +*/ +struct virtio_pci_modern_common_cfg { +struct virtio_pci_common_cfg cfg; + +uint16_t queue_notify_data;/* read-write */ +uint16_t queue_reset;/* read-write */ +}; +/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ struct virtio_pci_cfg_cap {struct virtio_pci_cap cap;
linux-headers/asm-arm64/kvm.h +32 -0
@@ -491,6 +491,38 @@ struct kvm_smccc_filter {#define KVM_HYPERCALL_EXIT_SMC (1U << 0)#define KVM_HYPERCALL_EXIT_16BIT (1U << 1) +/* +* Get feature ID registers userspace writable mask. +* +* From DDI0487J.a, D19.2.66 ("ID_AA64MMFR2_EL1, AArch64 Memory Model +* Feature Register 2"): +* +* "The Feature ID space is defined as the System register space in +* AArch64 with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, +* op2=={0-7}." +* +* This covers all currently known R/O registers that indicate +* anything useful feature wise, including the ID registers. +* +* If we ever need to introduce a new range, it will be described as +* such in the range field. +*/ +#define KVM_ARM_FEATURE_ID_RANGE_IDX (op0, op1, crn, crm, op2) \ + ({ \ + __u64 __op1 = (op1) & 3; \ + __op1 -= (__op1 == 3); \ + (__op1 << 6 | ((crm) & 7) << 3 | (op2)); \ + }) + +#define KVM_ARM_FEATURE_ID_RANGE 0 +#define KVM_ARM_FEATURE_ID_RANGE_SIZE (3 * 8 * 8) + +struct reg_mask_range { +__u64 addr;/* Pointer to mask array */ +__u32 range;/* Requested range */ +__u32 reserved[13 ]; +}; +#endif #endif /* __ARM_KVM_H__ */
linux-headers/asm-generic/unistd.h +10 -4
@@ -71,7 +71,7 @@ __SYSCALL(__NR_fremovexattr, sys_fremovexattr)#define __NR_getcwd 17 __SYSCALL(__NR_getcwd, sys_getcwd)#define __NR_lookup_dcookie 18 -__SC_COMP(__NR_lookup_dcookie, sys_lookup_dcookie, compat_sys_lookup_dcookie) +__SYSCALL(__NR_lookup_dcookie, sys_ni_syscall)#define __NR_eventfd2 19 __SYSCALL(__NR_eventfd2, sys_eventfd2)#define __NR_epoll_create1 20
@@ -816,15 +816,21 @@ __SYSCALL(__NR_process_mrelease, sys_process_mrelease) __SYSCALL(__NR_futex_waitv, sys_futex_waitv)#define __NR_set_mempolicy_home_node 450 __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) +#define __NR_map_shadow_stack 453 +__SYSCALL(__NR_map_shadow_stack, sys_map_shadow_stack) +#define __NR_futex_wake 454 +__SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 455 +__SYSCALL(__NR_futex_wait, sys_futex_wait) +#define __NR_futex_requeue 456 +__SYSCALL(__NR_futex_requeue, sys_futex_requeue)#undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 457/* * 32 bit systems traditionally used different
linux-headers/asm-loongarch/bitsperlong.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/bitsperlong.h>
linux-headers/asm-loongarch/kvm.h new file +108 -0
108 lines not on this page · raw message
linux-headers/asm-loongarch/mman.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/mman.h>
linux-headers/asm-loongarch/unistd.h new file +5 -0
@@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#define __ARCH_WANT_SYS_CLONE +#define __ARCH_WANT_SYS_CLONE3 + +#include <asm-generic/unistd.h>
linux-headers/asm-mips/unistd_n32.h +4 -0
@@ -381,5 +381,9 @@#define __NR_set_mempolicy_home_node (__NR_Linux + 450)#define __NR_cachestat (__NR_Linux + 451)#define __NR_fchmodat2 (__NR_Linux + 452) +#define __NR_map_shadow_stack (__NR_Linux + 453) +#define __NR_futex_wake (__NR_Linux + 454) +#define __NR_futex_wait (__NR_Linux + 455) +#define __NR_futex_requeue (__NR_Linux + 456)#endif /* _ASM_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +4 -0
@@ -357,5 +357,9 @@#define __NR_set_mempolicy_home_node (__NR_Linux + 450)#define __NR_cachestat (__NR_Linux + 451)#define __NR_fchmodat2 (__NR_Linux + 452) +#define __NR_map_shadow_stack (__NR_Linux + 453) +#define __NR_futex_wake (__NR_Linux + 454) +#define __NR_futex_wait (__NR_Linux + 455) +#define __NR_futex_requeue (__NR_Linux + 456)#endif /* _ASM_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +4 -0
@@ -427,5 +427,9 @@#define __NR_set_mempolicy_home_node (__NR_Linux + 450)#define __NR_cachestat (__NR_Linux + 451)#define __NR_fchmodat2 (__NR_Linux + 452) +#define __NR_map_shadow_stack (__NR_Linux + 453) +#define __NR_futex_wake (__NR_Linux + 454) +#define __NR_futex_wait (__NR_Linux + 455) +#define __NR_futex_requeue (__NR_Linux + 456)#endif /* _ASM_UNISTD_O32_H */
linux-headers/asm-powerpc/unistd_32.h +4 -0
@@ -434,6 +434,10 @@#define __NR_set_mempolicy_home_node 450#define __NR_cachestat 451#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +4 -0
@@ -406,6 +406,10 @@#define __NR_set_mempolicy_home_node 450#define __NR_cachestat 451#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-riscv/kvm.h +12 -0
@@ -80,6 +80,7 @@ struct kvm_riscv_csr {unsigned long sip;unsigned long satp;unsigned long scounteren; +unsigned long senvcfg; };/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -93,6 +94,11 @@ struct kvm_riscv_aia_csr {unsigned long iprio2h; }; +/* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_smstateen_csr { +unsigned long sstateen0; +}; +/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_timer {__u64 frequency;
@@ -131,6 +137,8 @@ enum KVM_RISCV_ISA_EXT_ID {KVM_RISCV_ISA_EXT_ZICSR ,KVM_RISCV_ISA_EXT_ZIFENCEI ,KVM_RISCV_ISA_EXT_ZIHPM , +KVM_RISCV_ISA_EXT_SMSTATEEN , +KVM_RISCV_ISA_EXT_ZICOND , KVM_RISCV_ISA_EXT_MAX, };
@@ -148,6 +156,7 @@ enum KVM_RISCV_SBI_EXT_ID {KVM_RISCV_SBI_EXT_PMU ,KVM_RISCV_SBI_EXT_EXPERIMENTAL ,KVM_RISCV_SBI_EXT_VENDOR , +KVM_RISCV_SBI_EXT_DBCN , KVM_RISCV_SBI_EXT_MAX, };
@@ -178,10 +187,13 @@ enum KVM_RISCV_SBI_EXT_ID {#define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT)#define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)#define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_CSR_SMSTATEEN (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)#define KVM_REG_RISCV_CSR_REG (name) \ (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))#define KVM_REG_RISCV_CSR_AIA_REG (name) \ (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long)) +#define KVM_REG_RISCV_CSR_SMSTATEEN_REG (name) \ + (offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long))/* Timer registers are mapped as type 4 */ #define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT)
linux-headers/asm-s390/unistd_32.h +4 -0
@@ -425,5 +425,9 @@#define __NR_set_mempolicy_home_node 450#define __NR_cachestat 451#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_S390_UNISTD_32_H */
linux-headers/asm-s390/unistd_64.h +4 -0
@@ -373,5 +373,9 @@#define __NR_set_mempolicy_home_node 450#define __NR_cachestat 451#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_S390_UNISTD_64_H */
linux-headers/asm-x86/unistd_32.h +4 -0
@@ -443,6 +443,10 @@#define __NR_set_mempolicy_home_node 450#define __NR_cachestat 451#define __NR_fchmodat2 452 +#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +3 -0
@@ -366,6 +366,9 @@#define __NR_cachestat 451#define __NR_fchmodat2 452#define __NR_map_shadow_stack 453 +#define __NR_futex_wake 454 +#define __NR_futex_wait 455 +#define __NR_futex_requeue 456#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +3 -0
@@ -318,6 +318,9 @@#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_futex_wake (__X32_SYSCALL_BIT + 454) +#define __NR_futex_wait (__X32_SYSCALL_BIT + 455) +#define __NR_futex_requeue (__X32_SYSCALL_BIT + 456)#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/iommufd.h +176 -4
233 lines not on this page · raw message
linux-headers/linux/kvm.h +11 -0
@@ -264,6 +264,7 @@ struct kvm_xen_exit {#define KVM_EXIT_RISCV_SBI 35#define KVM_EXIT_RISCV_CSR 36#define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_LOONGARCH_IOCSR 38/* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */
@@ -336,6 +337,13 @@ struct kvm_run {__u32 len;__u8 is_write; } mmio; +/* KVM_EXIT_LOONGARCH_IOCSR */ +struct { +__u64 phys_addr; +__u8 data[8 ]; +__u32 len; +__u8 is_write; + } iocsr_io;/* KVM_EXIT_HYPERCALL */ struct {__u64 nr;
@@ -1188,6 +1196,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_COUNTER_OFFSET 227#define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228#define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229 +#define KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES 230#ifdef KVM_CAP_IRQ_ROUTING
@@ -1358,6 +1367,7 @@ struct kvm_dirty_tlb {#define KVM_REG_ARM64 0x6000000000000000ULL#define KVM_REG_MIPS 0x7000000000000000ULL#define KVM_REG_RISCV 0x8000000000000000ULL +#define KVM_REG_LOONGARCH 0x9000000000000000ULL#define KVM_REG_SIZE_SHIFT 52#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
@@ -1558,6 +1568,7 @@ struct kvm_s390_ucas_mapping {#define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags)/* Available with KVM_CAP_COUNTER_OFFSET */ #define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_counter_offset) +#define KVM_ARM_GET_REG_WRITABLE_MASKS _IOR(KVMIO, 0xb6, struct reg_mask_range)/* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
linux-headers/linux/psp-sev.h +1 -0
@@ -68,6 +68,7 @@ typedef enum {SEV_RET_INVALID_PARAM ,SEV_RET_RESOURCE_LIMIT ,SEV_RET_SECURE_DATA_INVALID , +SEV_RET_INVALID_KEY =0x27 ,SEV_RET_MAX , } sev_ret_code;
linux-headers/linux/stddef.h +8 -1
@@ -27,8 +27,13 @@ union { \ struct { MEMBERS } ATTRS; \ struct TAG { MEMBERS } ATTRS NAME; \ - } + } ATTRS +#ifdef __cplusplus +/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ +#define __DECLARE_FLEX_ARRAY(T, member) \ + T member[0] +#else /** * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union *
@@ -49,3 +54,5 @@#ifndef __counted_by#define __counted_by (m)#endif + +#endif /* _LINUX_STDDEF_H */
linux-headers/linux/userfaultfd.h +8 -1
@@ -40,7 +40,8 @@ UFFD_FEATURE_EXACT_ADDRESS | \ UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ UFFD_FEATURE_WP_UNPOPULATED | \ - UFFD_FEATURE_POISON) + UFFD_FEATURE_POISON | \ + UFFD_FEATURE_WP_ASYNC)#define UFFD_API_IOCTLS \ ((__u64)1 << _UFFDIO_REGISTER | \ (__u64)1 << _UFFDIO_UNREGISTER | \
@@ -216,6 +217,11 @@ struct uffdio_api {* (i.e. empty ptes). This will be the default behavior for shmem * & hugetlbfs, so this flag only affects anonymous memory behavior * when userfault write-protection mode is registered. +* +* UFFD_FEATURE_WP_ASYNC indicates that userfaultfd write-protection +* asynchronous mode is supported in which the write fault is +* automatically resolved and write-protection is un-set. +* It implies UFFD_FEATURE_WP_UNPOPULATED. */ #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)#define UFFD_FEATURE_EVENT_FORK (1<<1)
@@ -232,6 +238,7 @@ struct uffdio_api {#define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12)#define UFFD_FEATURE_WP_UNPOPULATED (1<<13)#define UFFD_FEATURE_POISON (1<<14) +#define UFFD_FEATURE_WP_ASYNC (1<<15)__u64 features;__u64 ioctls;
linux-headers/linux/vfio.h +35 -12
102 lines not on this page · raw message
linux-headers/linux/vhost.h +8 -0
@@ -219,4 +219,12 @@*/ #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +/* Get the group for the descriptor table including driver & device areas +* of a virtqueue: read index, write group in num. +* The virtqueue index is stored in the index field of vhost_vring_state. +* The group ID of the descriptor table for this specific virtqueue +* is returned via num field of vhost_vring_state. +*/ +#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ + struct vhost_vring_state)#endif
Signature · 1 line
2.43.0
PATCH v2 2/4 linux-headers: riscv: add ptrace.h
In reply to Daniel Henrique BarbozaKVM vector support for RISC-V requires the linux-header ptrace.h.
--- linux-headers/asm-riscv/ptrace.h | 132 +++++++++++++++++++++++++++++++ scripts/update-linux-headers.sh | 3 + 2 files changed, 135 insertions(+) create mode 100644 linux-headers/asm-riscv/ptrace.h
linux-headers/asm-riscv/ptrace.h new file +132 -0
@@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* +* Copyright (C) 2012 Regents of the University of California +*/ + +#ifndef _ASM_RISCV_PTRACE_H +#define _ASM_RISCV_PTRACE_H + +#ifndef __ASSEMBLY__ + +#include <linux/types.h> + +#define PTRACE_GETFDPIC 33 + +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 + +/* +* User-mode register state for core dumps, ptrace, sigcontext +* +* This decouples struct pt_regs from the userspace ABI. +* struct user_regs_struct must form a prefix of struct pt_regs. +*/ +struct user_regs_struct { +unsigned long pc; +unsigned long ra; +unsigned long sp; +unsigned long gp; +unsigned long tp; +unsigned long t0; +unsigned long t1; +unsigned long t2; +unsigned long s0; +unsigned long s1; +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +unsigned long a4; +unsigned long a5; +unsigned long a6; +unsigned long a7; +unsigned long s2; +unsigned long s3; +unsigned long s4; +unsigned long s5; +unsigned long s6; +unsigned long s7; +unsigned long s8; +unsigned long s9; +unsigned long s10; +unsigned long s11; +unsigned long t3; +unsigned long t4; +unsigned long t5; +unsigned long t6; +}; + +struct __riscv_f_ext_state { +__u32 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_d_ext_state { +__u64 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_q_ext_state { +__u64 f[64 ] __attribute__((aligned (16 ))); +__u32 fcsr; +/* +* Reserved for expansion of sigcontext structure. Currently zeroed +* upon signal, and must be zero upon sigreturn. +*/ +__u32 reserved[3 ]; +}; + +struct __riscv_ctx_hdr { +__u32 magic; +__u32 size; +}; + +struct __riscv_extra_ext_header { +__u32 __padding[129 ] __attribute__((aligned (16 ))); +/* +* Reserved for expansion of sigcontext structure. Currently zeroed +* upon signal, and must be zero upon sigreturn. +*/ +__u32 reserved; +struct __riscv_ctx_hdr hdr; +}; + +union __riscv_fp_state { +struct __riscv_f_ext_state f; +struct __riscv_d_ext_state d; +struct __riscv_q_ext_state q; +}; + +struct __riscv_v_ext_state { +unsigned long vstart; +unsigned long vl; +unsigned long vtype; +unsigned long vcsr; +unsigned long vlenb; +void *datap; +/* +* In signal handler, datap will be set a correct user stack offset +* and vector registers will be copied to the address of datap +* pointer. +*/ +}; + +struct __riscv_v_regset_state { +unsigned long vstart; +unsigned long vl; +unsigned long vtype; +unsigned long vcsr; +unsigned long vlenb; +char vreg[]; +}; + +/* +* According to spec: The number of bits in a single vector register, +* VLEN >= ELEN, which must be a power of 2, and must be no greater than +* 2^16 = 65536bits = 8192bytes +*/ +#define RISCV_MAX_VLENB (8192) + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_PTRACE_H */
scripts/update-linux-headers.sh +3 -0
@@ -156,6 +156,9 @@ for arch in $ARCHLIST; do cp_portable "$tmpdir/bootparam.h" \ "$output/include/standard-headers/asm-$arch" fi + if [ $arch = riscv ]; then + cp "$tmpdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/" + fi done rm -rf "$output/linux-headers/linux"
Signature · 1 line
2.43.0
PATCH v2 3/4 target/riscv/kvm: do PR_RISCV_V_SET_CONTROL during realize()
In reply to Daniel Henrique BarbozaLinux RISC-V vector documentation (Document/arch/riscv/vector.rst) mandates a prctl() in order to allow an userspace thread to use the Vector extension from the host.
This is something to be done in realize() time, after init(), when we already decided whether we're using RVV or not. We don't have a realize() callback for KVM yet, so add kvm_cpu_realize() and enable RVV for the thread via PR_RISCV_V_SET_CONTROL.
--- target/riscv/kvm/kvm-cpu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
target/riscv/kvm/kvm-cpu.c +29 -0
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include <sys/ioctl.h> +#include <sys/prctl.h> #include <linux/kvm.h>
@@ -47,6 +48,9 @@#include "sysemu/runstate.h" #include "hw/riscv/numa.h" +#define PR_RISCV_V_SET_CONTROL 69 +#define PR_RISCV_V_VSTATE_CTRL_ON 2 +void riscv_kvm_aplic_request (void *opaque,int irq,int level) {kvm_set_irq (kvm_state, irq, !!level);
@@ -1490,11 +1494,36 @@ static void kvm_cpu_instance_init(CPUState *cs) } } +/* +* We'll get here via the following path: +* +* riscv_cpu_realize() +* -> cpu_exec_realizefn() +* -> kvm_cpu_realize() (via accel_cpu_common_realize()) +*/ +static bool kvm_cpu_realize (CPUState *cs,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (cs); +int ret; + +if (riscv_has_ext (&cpu->env,RVV )) { + ret =prctl (PR_RISCV_V_SET_CONTROL ,PR_RISCV_V_VSTATE_CTRL_ON ); +if (ret) { +error_setg (errp,"Error in prctl PR_RISCV_V_SET_CONTROL, code: %s" , +strerrorname_np (errno)); +return false; + } + } + +return true; +} +static void kvm_cpu_accel_class_init (ObjectClass *oc,void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); acc->cpu_instance_init = kvm_cpu_instance_init; + acc->cpu_target_realize = kvm_cpu_realize; }static const TypeInfo kvm_cpu_accel_type_info = {
Signature · 1 line
2.43.0
PATCH v2 4/4 target/riscv/kvm: add RVV and Vector CSR regs
In reply to Daniel Henrique BarbozaAdd support for RVV and Vector CSR KVM regs vstart, vl and vtype.
Support for vregs[] requires KVM side changes and an extra reg (vlenb) and will be added later.
--- target/riscv/kvm/kvm-cpu.c | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
target/riscv/kvm/kvm-cpu.c +74 -0
@@ -105,6 +105,10 @@ static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)#define RISCV_FP_D_REG (idx) kvm_riscv_reg_id_u64(KVM_REG_RISCV_FP_D, idx) +#define RISCV_VECTOR_CSR_REG (env, name) \ + kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_VECTOR, \ + KVM_REG_RISCV_VECTOR_CSR_REG(name)) +#define KVM_RISCV_GET_CSR (cs, env, csr, reg) \ do { \ int _ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \
@@ -158,6 +162,7 @@ static KVMCPUConfig kvm_misa_ext_cfgs[] = {KVM_MISA_CFG (RVH ,KVM_RISCV_ISA_EXT_H ),KVM_MISA_CFG (RVI ,KVM_RISCV_ISA_EXT_I ),KVM_MISA_CFG (RVM ,KVM_RISCV_ISA_EXT_M ), + KVM_MISA_CFG(RVV, KVM_RISCV_ISA_EXT_V), }; static void kvm_cpu_get_misa_ext_cfg(Object *obj, Visitor *v,
@@ -704,6 +709,65 @@ static void kvm_riscv_put_regs_timer(CPUState *cs) env->kvm_timer_dirty = false; } +static int kvm_riscv_get_regs_vector (CPUState *cs) +{ +CPURISCVState *env = &RISCV_CPU (cs)->env; +target_ulong reg; +int ret =0 ; + +if (!riscv_has_ext (env,RVV )) { +return 0 ; + } + + ret =kvm_get_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vstart), ®); +if (ret) { +return ret; + } + env->vstart = reg; + + ret =kvm_get_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vl), ®); +if (ret) { +return ret; + } + env->vl = reg; + + ret =kvm_get_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vtype), ®); +if (ret) { +return ret; + } + env->vtype = reg; + +return 0 ; +} + +static int kvm_riscv_put_regs_vector (CPUState *cs) +{ +CPURISCVState *env = &RISCV_CPU (cs)->env; +target_ulong reg; +int ret =0 ; + +if (!riscv_has_ext (env,RVV )) { +return 0 ; + } + + reg = env->vstart; + ret =kvm_set_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vstart), ®); +if (ret) { +return ret; + } + + reg = env->vl; + ret =kvm_set_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vl), ®); +if (ret) { +return ret; + } + + reg = env->vtype; + ret =kvm_set_one_reg (cs,RISCV_VECTOR_CSR_REG (env, vtype), ®); + +return ret; +} + typedef struct KVMScratchCPU { int kvmfd; int vmfd;
@@ -1001,6 +1065,11 @@ int kvm_arch_get_registers(CPUState *cs)return ret; } + ret =kvm_riscv_get_regs_vector (cs); +if (ret) { +return ret; + } +return ret; }
@@ -1041,6 +1110,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)return ret; } + ret =kvm_riscv_put_regs_vector (cs); +if (ret) { +return ret; + } +if (KVM_PUT_RESET_STATE == level) {RISCVCPU *cpu =RISCV_CPU (cs);if (cs->cpu_index ==0 ) {
Signature · 1 line
2.43.0
Alistair Francis
AppliedQuoted 19 lines · Daniel Henrique Barboza
Hi,
This version was rebased on top of Alistair's riscv-to-apply.next. A small tweak was needed in patch 4 due to changes in the branch.
I took the chance to update linux-headers to 6.7-rc5, although the differences from the rc3 headers from v1 were minimal.
All patches acked.
Changes from v1:
- rebased to Alistair's riscv-to-apply.next
- patch 1:
- updated headers to v6.7-rc5
- patch 4:
- usekvm_riscv_reg_id_ulong()instead ofkvm_riscv_reg_id()
- v1 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Quoted 5 lines
Daniel Henrique Barboza (4):
linux-headers: Update to Linux v6.7-rc5
linux-headers: riscv: addptrace.htarget/riscv/kvm: doPR_RISCV_V_SET_CONTROLduringrealize()target/riscv/kvm: add RVV and Vector CSR regs
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 44 lines
include/standard-headers/drm/drm_fourcc.h | 2 + include/standard-headers/linux/pci_regs.h | 24 ++- include/standard-headers/linux/vhost_types.h | 7 + .../standard-headers/linux/virtio_config.h | 5 + include/standard-headers/linux/virtio_pci.h | 11 ++ linux-headers/asm-arm64/kvm.h | 32 ++++ linux-headers/asm-generic/unistd.h | 14 +- linux-headers/asm-loongarch/bitsperlong.h | 1 + linux-headers/asm-loongarch/kvm.h | 108 +++++++++++ linux-headers/asm-loongarch/mman.h | 1 + linux-headers/asm-loongarch/unistd.h | 5 + linux-headers/asm-mips/unistd_n32.h | 4 + linux-headers/asm-mips/unistd_n64.h | 4 + linux-headers/asm-mips/unistd_o32.h | 4 + linux-headers/asm-powerpc/unistd_32.h | 4 + linux-headers/asm-powerpc/unistd_64.h | 4 + linux-headers/asm-riscv/kvm.h | 12 ++ linux-headers/asm-riscv/ptrace.h | 132 +++++++++++++ linux-headers/asm-s390/unistd_32.h | 4 + linux-headers/asm-s390/unistd_64.h | 4 + linux-headers/asm-x86/unistd_32.h | 4 + linux-headers/asm-x86/unistd_64.h | 3 + linux-headers/asm-x86/unistd_x32.h | 3 + linux-headers/linux/iommufd.h | 180 +++++++++++++++++- linux-headers/linux/kvm.h | 11 ++ linux-headers/linux/psp-sev.h | 1 + linux-headers/linux/stddef.h | 9 +- linux-headers/linux/userfaultfd.h | 9 +- linux-headers/linux/vfio.h | 47 +++-- linux-headers/linux/vhost.h | 8 + scripts/update-linux-headers.sh | 3 + target/riscv/kvm/kvm-cpu.c | 103 ++++++++++ 32 files changed, 736 insertions(+), 27 deletions(-) create mode 100644 linux-headers/asm-loongarch/bitsperlong.h create mode 100644 linux-headers/asm-loongarch/kvm.h create mode 100644 linux-headers/asm-loongarch/mman.h create mode 100644 linux-headers/asm-loongarch/unistd.h create mode 100644 linux-headers/asm-riscv/ptrace.h--
2.43.0