From patchwork Thu Jul 6 17:37:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEDCFEB64DC for ; Thu, 6 Jul 2023 17:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231580AbjGFRit (ORCPT ); Thu, 6 Jul 2023 13:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjGFRij (ORCPT ); Thu, 6 Jul 2023 13:38:39 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9679F1BF1 for ; Thu, 6 Jul 2023 10:38:32 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-78666f06691so34087439f.0 for ; Thu, 06 Jul 2023 10:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665112; x=1691257112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u69JnhfX2LqGFM+BjoI6Leri8ZBQcCNEYkxpvBK9Bxs=; b=ISm/IRIRqKzyXonMscesPb9dfm5K8g5okz9vHd7cOugMMi5HNDWCAmBab3qT2e4L/W 1eOjQ/yAmX7B/h99tH7LXFVFDPUsUWVwVzTw0x/Ij+5J6WRDyVVRnqyykxyGApkRazr/ Pqej9vqYAkBKi35Ry32hhK7BFFohemr4bKDrF10vFDe76gce0aQH930eMoIJLkPiQ096 PkS0xInvPwVUjtVTrokmpYtz7nXxD8X0ko8TjuCRm8iNsqLRD1HdlHQZJrfIet0OCHip QzoIr8YPaplJHCbt60Ia42sj1xPapn5jb2CRP6L21Er1QNE34U28qR5acos87a2J2ZgE Rq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665112; x=1691257112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u69JnhfX2LqGFM+BjoI6Leri8ZBQcCNEYkxpvBK9Bxs=; b=jeAsOoRNoJlJywzZW34RUQbDcqI6vhGnb7t3C7EBOsb8qUliPMygquyyHC0b5Rwbkw npSxjE39ntlVbIVkznDn9h0/xEfI1fmIcQBi9+NOwLIKt+kRFt+QenygAQt7aTWZGBuW mlm0s+zqwCYE+ejZD8YxkuCOKBIJe6hHhBo7eNhoQCq+lasOPEy1cr+3GoeQvP+3HOGG ThkcHwFfgih/CVXAYUiCuMYtgDX9/9vr7c8jIDxnTya9AUuP8bMcNekkJrg295cuY90O lrSmWOTn7YScDrwhcrtXsPzmODXYD0K3JfQgv8G6puKqdsGwqDqSzAEm6x8jJifAilEu RLyg== X-Gm-Message-State: ABy/qLZLEZXjOkLDyHUgLcx1mpqw+V20qE3l651vFb9VLES9qzKOmCv3 cOpyK2nM8OTImQ8v7+4Jmmo/yQ== X-Google-Smtp-Source: APBJJlELrDhtqluwmq+oqRelIkyqEF9HTysILtJ7azsJkdW4v0+g4YROXu2/tLm0azvMRphEw35TuA== X-Received: by 2002:a5e:c910:0:b0:77e:3d2f:d1f4 with SMTP id z16-20020a5ec910000000b0077e3d2fd1f4mr2778341iol.15.1688665111678; Thu, 06 Jul 2023 10:38:31 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:31 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 1/8] Sync-up headers with Linux-6.4 Date: Thu, 6 Jul 2023 23:07:57 +0530 Message-Id: <20230706173804.1237348-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We sync-up Linux headers to get latest KVM RISC-V headers having SBI extension enable/disable, Zbb, Zicboz, and Ssaia support. Signed-off-by: Anup Patel --- arm/aarch64/include/asm/kvm.h | 38 ++++++++++++ include/linux/kvm.h | 57 +++++++++++------- include/linux/virtio_blk.h | 105 ++++++++++++++++++++++++++++++++++ include/linux/virtio_config.h | 6 ++ include/linux/virtio_net.h | 5 ++ riscv/include/asm/kvm.h | 56 +++++++++++++++++- x86/include/asm/kvm.h | 50 ++++++++++++---- 7 files changed, 286 insertions(+), 31 deletions(-) diff --git a/arm/aarch64/include/asm/kvm.h b/arm/aarch64/include/asm/kvm.h index 316917b..f7ddd73 100644 --- a/arm/aarch64/include/asm/kvm.h +++ b/arm/aarch64/include/asm/kvm.h @@ -43,6 +43,7 @@ #define __KVM_HAVE_VCPU_EVENTS #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +#define KVM_DIRTY_LOG_PAGE_OFFSET 64 #define KVM_REG_SIZE(id) \ (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) @@ -108,6 +109,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_HAS_EL2 7 /* Support nested virtualization */ struct kvm_vcpu_init { __u32 target; @@ -196,6 +198,15 @@ struct kvm_arm_copy_mte_tags { __u64 reserved[2]; }; +/* + * Counter/Timer offset structure. Describe the virtual/physical offset. + * To be used with KVM_ARM_SET_COUNTER_OFFSET. + */ +struct kvm_arm_counter_offset { + __u64 counter_offset; + __u64 reserved; +}; + #define KVM_ARM_TAGS_TO_GUEST 0 #define KVM_ARM_TAGS_FROM_GUEST 1 @@ -370,6 +381,10 @@ enum { #endif }; +/* Device Control API on vm fd */ +#define KVM_ARM_VM_SMCCC_CTRL 0 +#define KVM_ARM_VM_SMCCC_FILTER 0 + /* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 @@ -409,6 +424,8 @@ enum { #define KVM_ARM_VCPU_TIMER_CTRL 1 #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 +#define KVM_ARM_VCPU_TIMER_IRQ_HVTIMER 2 +#define KVM_ARM_VCPU_TIMER_IRQ_HPTIMER 3 #define KVM_ARM_VCPU_PVTIME_CTRL 2 #define KVM_ARM_VCPU_PVTIME_IPA 0 @@ -467,6 +484,27 @@ enum { /* run->fail_entry.hardware_entry_failure_reason codes. */ #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) +enum kvm_smccc_filter_action { + KVM_SMCCC_FILTER_HANDLE = 0, + KVM_SMCCC_FILTER_DENY, + KVM_SMCCC_FILTER_FWD_TO_USER, + +#ifdef __KERNEL__ + NR_SMCCC_FILTER_ACTIONS +#endif +}; + +struct kvm_smccc_filter { + __u32 base; + __u32 nr_functions; + __u8 action; + __u8 pad[15]; +}; + +/* arm64-specific KVM_EXIT_HYPERCALL flags */ +#define KVM_HYPERCALL_EXIT_SMC (1U << 0) +#define KVM_HYPERCALL_EXIT_16BIT (1U << 1) + #endif #endif /* __ARM_KVM_H__ */ diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 0d5d441..737318b 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -86,14 +86,6 @@ struct kvm_debug_guest { /* *** End of deprecated interfaces *** */ -/* for KVM_CREATE_MEMORY_REGION */ -struct kvm_memory_region { - __u32 slot; - __u32 flags; - __u64 guest_phys_addr; - __u64 memory_size; /* bytes */ -}; - /* for KVM_SET_USER_MEMORY_REGION */ struct kvm_userspace_memory_region { __u32 slot; @@ -104,9 +96,9 @@ struct kvm_userspace_memory_region { }; /* - * The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace, - * other bits are reserved for kvm internal use which are defined in - * include/linux/kvm_host.h. + * The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for + * userspace, other bits are reserved for kvm internal use which are defined + * in include/linux/kvm_host.h. */ #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) #define KVM_MEM_READONLY (1UL << 1) @@ -349,8 +341,13 @@ struct kvm_run { __u64 nr; __u64 args[6]; __u64 ret; - __u32 longmode; - __u32 pad; + + union { +#ifndef __KERNEL__ + __u32 longmode; +#endif + __u64 flags; + }; } hypercall; /* KVM_EXIT_TPR_ACCESS */ struct { @@ -485,6 +482,9 @@ struct kvm_run { #define KVM_MSR_EXIT_REASON_INVAL (1 << 0) #define KVM_MSR_EXIT_REASON_UNKNOWN (1 << 1) #define KVM_MSR_EXIT_REASON_FILTER (1 << 2) +#define KVM_MSR_EXIT_REASON_VALID_MASK (KVM_MSR_EXIT_REASON_INVAL | \ + KVM_MSR_EXIT_REASON_UNKNOWN | \ + KVM_MSR_EXIT_REASON_FILTER) __u32 reason; /* kernel -> user */ __u32 index; /* kernel -> user */ __u64 data; /* kernel <-> user */ @@ -588,6 +588,8 @@ struct kvm_s390_mem_op { struct { __u8 ar; /* the access register number */ __u8 key; /* access key, ignored if flag unset */ + __u8 pad1[6]; /* ignored */ + __u64 old_addr; /* ignored if cmpxchg flag unset */ }; __u32 sida_offset; /* offset into the sida */ __u8 reserved[32]; /* ignored */ @@ -600,11 +602,17 @@ struct kvm_s390_mem_op { #define KVM_S390_MEMOP_SIDA_WRITE 3 #define KVM_S390_MEMOP_ABSOLUTE_READ 4 #define KVM_S390_MEMOP_ABSOLUTE_WRITE 5 +#define KVM_S390_MEMOP_ABSOLUTE_CMPXCHG 6 + /* flags for kvm_s390_mem_op->flags */ #define KVM_S390_MEMOP_F_CHECK_ONLY (1ULL << 0) #define KVM_S390_MEMOP_F_INJECT_EXCEPTION (1ULL << 1) #define KVM_S390_MEMOP_F_SKEY_PROTECTION (1ULL << 2) +/* flags specifying extension support via KVM_CAP_S390_MEM_OP_EXTENSION */ +#define KVM_S390_MEMOP_EXTENSION_CAP_BASE (1 << 0) +#define KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG (1 << 1) + /* for KVM_INTERRUPT */ struct kvm_interrupt { /* in */ @@ -1178,6 +1186,10 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_ZPCI_OP 221 #define KVM_CAP_S390_CPU_TOPOLOGY 222 #define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 +#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224 +#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 +#define KVM_CAP_COUNTER_OFFSET 227 #ifdef KVM_CAP_IRQ_ROUTING @@ -1267,6 +1279,7 @@ struct kvm_x86_mce { #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3) #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4) #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) +#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) struct kvm_xen_hvm_config { __u32 flags; @@ -1437,20 +1450,14 @@ struct kvm_vfio_spapr_tce { __s32 tablefd; }; -/* - * ioctls for VM fds - */ -#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) /* * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns * a vcpu fd. */ #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) -/* KVM_SET_MEMORY_ALIAS is obsolete: */ -#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias) #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44) -#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) +#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) /* deprecated */ #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46, \ struct kvm_userspace_memory_region) #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) @@ -1542,6 +1549,8 @@ struct kvm_s390_ucas_mapping { #define KVM_SET_PMU_EVENT_FILTER _IOW(KVMIO, 0xb2, struct kvm_pmu_event_filter) #define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb3) #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) /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) @@ -1740,6 +1749,8 @@ enum pv_cmd_id { KVM_PV_UNSHARE_ALL, KVM_PV_INFO, KVM_PV_DUMP, + KVM_PV_ASYNC_CLEANUP_PREPARE, + KVM_PV_ASYNC_CLEANUP_PERFORM, }; struct kvm_pv_cmd { @@ -1770,8 +1781,10 @@ struct kvm_xen_hvm_attr { union { __u8 long_mode; __u8 vector; + __u8 runstate_update_flag; struct { __u64 gfn; +#define KVM_XEN_INVALID_GFN ((__u64)-1) } shared_info; struct { __u32 send_port; @@ -1803,6 +1816,7 @@ struct kvm_xen_hvm_attr { } u; }; + /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO */ #define KVM_XEN_ATTR_TYPE_LONG_MODE 0x0 #define KVM_XEN_ATTR_TYPE_SHARED_INFO 0x1 @@ -1810,6 +1824,8 @@ struct kvm_xen_hvm_attr { /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */ #define KVM_XEN_ATTR_TYPE_EVTCHN 0x3 #define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4 +/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */ +#define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 0x5 /* Per-vCPU Xen attributes */ #define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr) @@ -1826,6 +1842,7 @@ struct kvm_xen_vcpu_attr { __u16 pad[3]; union { __u64 gpa; +#define KVM_XEN_INVALID_GPA ((__u64)-1) __u64 pad[8]; struct { __u64 state; diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index 58e70b2..3744e4d 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -41,6 +41,7 @@ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ #define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ +#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -137,6 +138,16 @@ struct virtio_blk_config { /* Secure erase commands must be aligned to this number of sectors. */ __virtio32 secure_erase_sector_alignment; + /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ + struct virtio_blk_zoned_characteristics { + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; + __u8 model; + __u8 unused2[3]; + } zoned; } __attribute__((packed)); /* @@ -174,6 +185,27 @@ struct virtio_blk_config { /* Secure erase command */ #define VIRTIO_BLK_T_SECURE_ERASE 14 +/* Zone append command */ +#define VIRTIO_BLK_T_ZONE_APPEND 15 + +/* Report zones command */ +#define VIRTIO_BLK_T_ZONE_REPORT 16 + +/* Open zone command */ +#define VIRTIO_BLK_T_ZONE_OPEN 18 + +/* Close zone command */ +#define VIRTIO_BLK_T_ZONE_CLOSE 20 + +/* Finish zone command */ +#define VIRTIO_BLK_T_ZONE_FINISH 22 + +/* Reset zone command */ +#define VIRTIO_BLK_T_ZONE_RESET 24 + +/* Reset All zones command */ +#define VIRTIO_BLK_T_ZONE_RESET_ALL 26 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 @@ -193,6 +225,72 @@ struct virtio_blk_outhdr { __virtio64 sector; }; +/* + * Supported zoned device models. + */ + +/* Regular block device */ +#define VIRTIO_BLK_Z_NONE 0 +/* Host-managed zoned device */ +#define VIRTIO_BLK_Z_HM 1 +/* Host-aware zoned device */ +#define VIRTIO_BLK_Z_HA 2 + +/* + * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply. + */ +struct virtio_blk_zone_descriptor { + /* Zone capacity */ + __virtio64 z_cap; + /* The starting sector of the zone */ + __virtio64 z_start; + /* Zone write pointer position in sectors */ + __virtio64 z_wp; + /* Zone type */ + __u8 z_type; + /* Zone state */ + __u8 z_state; + __u8 reserved[38]; +}; + +struct virtio_blk_zone_report { + __virtio64 nr_zones; + __u8 reserved[56]; + struct virtio_blk_zone_descriptor zones[]; +}; + +/* + * Supported zone types. + */ + +/* Conventional zone */ +#define VIRTIO_BLK_ZT_CONV 1 +/* Sequential Write Required zone */ +#define VIRTIO_BLK_ZT_SWR 2 +/* Sequential Write Preferred zone */ +#define VIRTIO_BLK_ZT_SWP 3 + +/* + * Zone states that are available for zones of all types. + */ + +/* Not a write pointer (conventional zones only) */ +#define VIRTIO_BLK_ZS_NOT_WP 0 +/* Empty */ +#define VIRTIO_BLK_ZS_EMPTY 1 +/* Implicitly Open */ +#define VIRTIO_BLK_ZS_IOPEN 2 +/* Explicitly Open */ +#define VIRTIO_BLK_ZS_EOPEN 3 +/* Closed */ +#define VIRTIO_BLK_ZS_CLOSED 4 +/* Read-Only */ +#define VIRTIO_BLK_ZS_RDONLY 13 +/* Full */ +#define VIRTIO_BLK_ZS_FULL 14 +/* Offline */ +#define VIRTIO_BLK_ZS_OFFLINE 15 + /* Unmap this range (only valid for write zeroes command) */ #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 @@ -219,4 +317,11 @@ struct virtio_scsi_inhdr { #define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_UNSUPP 2 + +/* Error codes that are specific to zoned block devices */ +#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3 +#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4 +#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5 +#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6 + #endif /* _LINUX_VIRTIO_BLK_H */ diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 3c05162..2c712c6 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -99,6 +99,12 @@ */ #define VIRTIO_F_SR_IOV 37 +/* + * This feature indicates that the driver passes extra data (besides + * identifying the virtqueue) in its device notifications. + */ +#define VIRTIO_F_NOTIFICATION_DATA 38 + /* * This feature indicates that the driver can reset a queue individually. */ diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 6cb842e..12c1c96 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -57,7 +57,11 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ #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. */ +#define VIRTIO_NET_F_HOST_USO 56 /* Host can handle USO in. */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ +#define VIRTIO_NET_F_GUEST_HDRLEN 59 /* Guest provides the exact hdr_len value. */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ #define VIRTIO_NET_F_STANDBY 62 /* Act as standby for another device @@ -130,6 +134,7 @@ struct virtio_net_hdr_v1 { #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ +#define VIRTIO_NET_HDR_GSO_UDP_L4 5 /* GSO frame, IPv4& IPv6 UDP (USO) */ #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ __u8 gso_type; __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ diff --git a/riscv/include/asm/kvm.h b/riscv/include/asm/kvm.h index 8985ff2..f92790c 100644 --- a/riscv/include/asm/kvm.h +++ b/riscv/include/asm/kvm.h @@ -12,6 +12,7 @@ #ifndef __ASSEMBLY__ #include +#include #include #define __KVM_HAVE_READONLY_MEM @@ -49,6 +50,10 @@ struct kvm_sregs { struct kvm_riscv_config { unsigned long isa; unsigned long zicbom_block_size; + unsigned long mvendorid; + unsigned long marchid; + unsigned long mimpid; + unsigned long zicboz_block_size; }; /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ @@ -61,7 +66,7 @@ struct kvm_riscv_core { #define KVM_RISCV_MODE_S 1 #define KVM_RISCV_MODE_U 0 -/* CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +/* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_csr { unsigned long sstatus; unsigned long sie; @@ -75,6 +80,17 @@ struct kvm_riscv_csr { unsigned long scounteren; }; +/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_aia_csr { + unsigned long siselect; + unsigned long iprio1; + unsigned long iprio2; + unsigned long sieh; + unsigned long siph; + unsigned long iprio1h; + unsigned long iprio2h; +}; + /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_timer { __u64 frequency; @@ -102,9 +118,29 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_SVINVAL, KVM_RISCV_ISA_EXT_ZIHINTPAUSE, KVM_RISCV_ISA_EXT_ZICBOM, + KVM_RISCV_ISA_EXT_ZICBOZ, + KVM_RISCV_ISA_EXT_ZBB, + KVM_RISCV_ISA_EXT_SSAIA, KVM_RISCV_ISA_EXT_MAX, }; +/* + * SBI extension IDs specific to KVM. This is not the same as the SBI + * extension IDs defined by the RISC-V SBI specification. + */ +enum KVM_RISCV_SBI_EXT_ID { + KVM_RISCV_SBI_EXT_V01 = 0, + KVM_RISCV_SBI_EXT_TIME, + KVM_RISCV_SBI_EXT_IPI, + KVM_RISCV_SBI_EXT_RFENCE, + KVM_RISCV_SBI_EXT_SRST, + KVM_RISCV_SBI_EXT_HSM, + KVM_RISCV_SBI_EXT_PMU, + KVM_RISCV_SBI_EXT_EXPERIMENTAL, + KVM_RISCV_SBI_EXT_VENDOR, + KVM_RISCV_SBI_EXT_MAX, +}; + /* Possible states for kvm_riscv_timer */ #define KVM_RISCV_TIMER_STATE_OFF 0 #define KVM_RISCV_TIMER_STATE_ON 1 @@ -115,6 +151,8 @@ enum KVM_RISCV_ISA_EXT_ID { /* If you need to interpret the index values, here is the key: */ #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 #define KVM_REG_RISCV_TYPE_SHIFT 24 +#define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000 +#define KVM_REG_RISCV_SUBTYPE_SHIFT 16 /* Config registers are mapped as type 1 */ #define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT) @@ -128,8 +166,12 @@ enum KVM_RISCV_ISA_EXT_ID { /* Control and status registers are mapped as type 3 */ #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_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)) /* Timer registers are mapped as type 4 */ #define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT) @@ -149,6 +191,18 @@ enum KVM_RISCV_ISA_EXT_ID { /* ISA Extension registers are mapped as type 7 */ #define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT) +/* SBI extension registers are mapped as type 8 */ +#define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_SBI_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_REG(__ext_id) \ + ((__ext_id) / __BITS_PER_LONG) +#define KVM_REG_RISCV_SBI_MULTI_MASK(__ext_id) \ + (1UL << ((__ext_id) % __BITS_PER_LONG)) +#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ + KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) + #endif #endif /* __LINUX_KVM_RISCV_H */ diff --git a/x86/include/asm/kvm.h b/x86/include/asm/kvm.h index 46de10a..1a6a1f9 100644 --- a/x86/include/asm/kvm.h +++ b/x86/include/asm/kvm.h @@ -9,6 +9,7 @@ #include #include +#include #define KVM_PIO_PAGE_OFFSET 1 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 @@ -53,14 +54,6 @@ /* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 -struct kvm_memory_alias { - __u32 slot; /* this has a different namespace than memory slots */ - __u32 flags; - __u64 guest_phys_addr; - __u64 memory_size; - __u64 target_phys_addr; -}; - /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */ struct kvm_pic_state { __u8 last_irr; /* edge detection */ @@ -214,6 +207,8 @@ struct kvm_msr_list { struct kvm_msr_filter_range { #define KVM_MSR_FILTER_READ (1 << 0) #define KVM_MSR_FILTER_WRITE (1 << 1) +#define KVM_MSR_FILTER_RANGE_VALID_MASK (KVM_MSR_FILTER_READ | \ + KVM_MSR_FILTER_WRITE) __u32 flags; __u32 nmsrs; /* number of msrs in bitmap */ __u32 base; /* MSR index the bitmap starts at */ @@ -222,8 +217,11 @@ struct kvm_msr_filter_range { #define KVM_MSR_FILTER_MAX_RANGES 16 struct kvm_msr_filter { +#ifndef __KERNEL__ #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0) +#endif #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) +#define KVM_MSR_FILTER_VALID_MASK (KVM_MSR_FILTER_DEFAULT_DENY) __u32 flags; struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES]; }; @@ -510,8 +508,8 @@ struct kvm_nested_state { * KVM_{GET,PUT}_NESTED_STATE ioctl values. */ union { - struct kvm_vmx_nested_state_data vmx[0]; - struct kvm_svm_nested_state_data svm[0]; + __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx); + __DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm); } data; }; @@ -528,8 +526,40 @@ struct kvm_pmu_event_filter { #define KVM_PMU_EVENT_ALLOW 0 #define KVM_PMU_EVENT_DENY 1 +#define KVM_PMU_EVENT_FLAG_MASKED_EVENTS BIT(0) +#define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS) + +/* + * Masked event layout. + * Bits Description + * ---- ----------- + * 7:0 event select (low bits) + * 15:8 umask match + * 31:16 unused + * 35:32 event select (high bits) + * 36:54 unused + * 55 exclude bit + * 63:56 umask mask + */ + +#define KVM_PMU_ENCODE_MASKED_ENTRY(event_select, mask, match, exclude) \ + (((event_select) & 0xFFULL) | (((event_select) & 0XF00ULL) << 24) | \ + (((mask) & 0xFFULL) << 56) | \ + (((match) & 0xFFULL) << 8) | \ + ((__u64)(!!(exclude)) << 55)) + +#define KVM_PMU_MASKED_ENTRY_EVENT_SELECT \ + (GENMASK_ULL(7, 0) | GENMASK_ULL(35, 32)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK (GENMASK_ULL(63, 56)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MATCH (GENMASK_ULL(15, 8)) +#define KVM_PMU_MASKED_ENTRY_EXCLUDE (BIT_ULL(55)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK_SHIFT (56) + /* for KVM_{GET,SET,HAS}_DEVICE_ATTR */ #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */ #define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */ +/* x86-specific KVM_EXIT_HYPERCALL flags. */ +#define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) + #endif /* _ASM_X86_KVM_H */ From patchwork Thu Jul 6 17:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AAD8EB64D9 for ; Thu, 6 Jul 2023 17:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbjGFRi7 (ORCPT ); Thu, 6 Jul 2023 13:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbjGFRir (ORCPT ); Thu, 6 Jul 2023 13:38:47 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BBED1FE8 for ; Thu, 6 Jul 2023 10:38:37 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-345df4e68afso3549645ab.0 for ; Thu, 06 Jul 2023 10:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665116; x=1691257116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I4RvkKA5HMlJ9jiuvmt347v/0/0kHBcwrduLKYcFeXM=; b=a/wMiLR/Fj10x0KocTj8ukW8achJVs0fD21O8+oelLoE1eJAqX/bnE7SjMbhi2xfW6 OlRQMdnmIEvTfbOr/UNp6X9FF6dZ6bX0j6/HD5U8IzoZcBlNSX1i+vP/qrEL6G5Yu1wZ 1VNNOXceekZUs/DNt1DWVDxUTZowuXM2FfUTCGLwHzet0s1LAs3ZLn0CBr9rOdLq+Zgn 34zW05zHOyD8MP7CKxwljz3pBYxSIbOzxz0XyjKwoJm9zRKdfMTw5OhTqPVCOESj+WPh aw1XexQ3AdkMKAUC6/9bmBhi43OGo0mlD/G3FHHQDk1Nj799dagrd7Gp6kUxOWff/Fu3 IGiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665116; x=1691257116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I4RvkKA5HMlJ9jiuvmt347v/0/0kHBcwrduLKYcFeXM=; b=Bt08ZbdiQVrHVAX6RRRB67Tw21bmKja+m0oobY1f9re1/vSEvEunDNj9dNhBO8qAdG vIfOiftZpxfUKgBpJ6fTyHb9OzLITOKaLlGu/mCuat/M8ODeQ7m9I/FGrB7okpue4FR/ MKLaOkfzeiJh7raQ+5bGjfV0QWi3UhyDB4wJyLrlcIy2VEHtfGfp6A924zCFdnOrkADY feUQbp2fUUcztGu5aeuUjaj4QrAT2w4J6/9UXJw2fFkmwxDRqHD6fTcafa6Yh7e8ehoI gzKt7alkmMkxU8+GR22L02NNra6Chj55ek6ZX3swmtYRBoCULDkI1+ajjmp+pAOjOBuD 9mNw== X-Gm-Message-State: ABy/qLbkenR7txrzGWA0sxV07/gRLLiQS6LK+q8I1LZCj6RHLXqXkGxs OJLxGE2eGEF8NiJ5Wql2U6COqg== X-Google-Smtp-Source: APBJJlHPi63G4ghKH2j2yUusZJg9UQGqLOCn/QM9/Ch6a2hDUV8cfzA7Y7DbI7AAWZEVbGqbBJ9oPg== X-Received: by 2002:a92:c6cf:0:b0:345:ab58:5afd with SMTP id v15-20020a92c6cf000000b00345ab585afdmr2752499ilm.16.1688665116617; Thu, 06 Jul 2023 10:38:36 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:36 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Date: Thu, 6 Jul 2023 23:07:58 +0530 Message-Id: <20230706173804.1237348-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We add command-line parameter to set custom mvendorid, marchid, and mimpid so that users can show fake CPU type to Guest/VM which does not match underlying Host CPU. Signed-off-by: Anup Patel --- riscv/include/kvm/kvm-config-arch.h | 12 ++++++++++++ riscv/kvm-cpu.c | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index 188125c..e64e3ca 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -5,6 +5,9 @@ struct kvm_config_arch { const char *dump_dtb_filename; + u64 custom_mvendorid; + u64 custom_marchid; + u64 custom_mimpid; bool ext_disabled[KVM_RISCV_ISA_EXT_MAX]; }; @@ -12,6 +15,15 @@ struct kvm_config_arch { pfx, \ OPT_STRING('\0', "dump-dtb", &(cfg)->dump_dtb_filename, \ ".dtb file", "Dump generated .dtb to specified file"),\ + OPT_U64('\0', "custom-mvendorid", \ + &(cfg)->custom_mvendorid, \ + "Show custom mvendorid to Guest VCPU"), \ + OPT_U64('\0', "custom-marchid", \ + &(cfg)->custom_marchid, \ + "Show custom marchid to Guest VCPU"), \ + OPT_U64('\0', "custom-mimpid", \ + &(cfg)->custom_mimpid, \ + "Show custom mimpid to Guest VCPU"), \ OPT_BOOLEAN('\0', "disable-sstc", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC], \ "Disable Sstc Extension"), \ diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index f98bd7a..89122b4 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -22,7 +22,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) { struct kvm_cpu *vcpu; u64 timebase = 0; - unsigned long isa = 0; + unsigned long isa = 0, id = 0; int coalesced_offset, mmap_size; struct kvm_one_reg reg; @@ -64,6 +64,30 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) die("KVM_SET_ONE_REG failed (config.isa)"); + if (kvm->cfg.arch.custom_mvendorid) { + id = kvm->cfg.arch.custom_mvendorid; + reg.id = RISCV_CONFIG_REG(mvendorid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.mvendorid)"); + } + + if (kvm->cfg.arch.custom_marchid) { + id = kvm->cfg.arch.custom_marchid; + reg.id = RISCV_CONFIG_REG(marchid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.marchid)"); + } + + if (kvm->cfg.arch.custom_mimpid) { + id = kvm->cfg.arch.custom_mimpid; + reg.id = RISCV_CONFIG_REG(mimpid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.mimpid)"); + } + /* Populate the vcpu structure. */ vcpu->kvm = kvm; vcpu->cpu_id = cpu_id; From patchwork Thu Jul 6 17:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFE04EB64DC for ; Thu, 6 Jul 2023 17:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbjGFRjB (ORCPT ); Thu, 6 Jul 2023 13:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232370AbjGFRis (ORCPT ); Thu, 6 Jul 2023 13:38:48 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76FA51FF6 for ; Thu, 6 Jul 2023 10:38:42 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-78362f57500so36301139f.3 for ; Thu, 06 Jul 2023 10:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665122; x=1691257122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eHiYWY9bvHP4MwqbxGKa7jevzatL3qS57fs5xuP7yzI=; b=QqXcNqYV7oepKX1/VnAtaKDmB61v3PAZ498kFFi88MRFs7kNuY+dsH/Ml2bSuDLIYE xkb8rKDSQ9s0+M4JQ/9QuHj9Eusv+R5X2LG7J7qA0PCHtmSyD9Dinrk2AWz7d2QptLen zDFVHWX/Bkt5YYqV3724i5ltXpLlwwB6xX+Y/WaxaSJWhFAtD3x7gD+Iq4Pc9IVU5+Ph wzhDJCqKTbhHFGaMrfqoNVK3Wf2chHqbpOufE90NrI/HrzPkPQLayoGye55bARhsP1eV 5DtD61ULECGypbX5Ngz71jV89ntMjjMp9q5m8HpwKtmWywdUHNjELg9hvl3rEyFBb2Qs sabw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665122; x=1691257122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eHiYWY9bvHP4MwqbxGKa7jevzatL3qS57fs5xuP7yzI=; b=UxUJqri6G5SIR+w/zXEOoyuXkn0D7J6V0A8esh3HWOfmklpcDDM9k1aqYq6QheYL2c JNCUrxHaqW5wgxYrCqy86lTGRy//mjyibka3QSOUMdR1L2rR/iodvlf4yX++OoUqEjt+ tNwWvwmMce4lnRJGBFSraoCFBnNXGuKpbYHcKZITZF/5x4reEbQ+i5nG7KhJ75OQFupz l2xY7l7HAp69zSPaAr2s5DHpvrcPhQ2eEaNnmr83iHKd1SWxvHGwuVAQJ5Ed4dgoE/Rw neV7mD7CbxF9ojvA3SjI0BoOFGX4pQ7DgDqK8hYUJJdhuj++tgrGcsaPFrCtzRJsXTIA +k4Q== X-Gm-Message-State: ABy/qLbVkOwLbFiXJIiHG+dTvu0F123C4AmU87j9/VDaHpu3EU+YvrDu s56ivzKUDNqjZYJumUvQVjXfxg== X-Google-Smtp-Source: APBJJlF+x52u3bATUQTIfIIEjKzcfrwQYrY5gTLGRu0TdM9NSjBoWpzw66njm1qIN+2oAYcA3vTLeg== X-Received: by 2002:a05:6602:2774:b0:786:3f74:c244 with SMTP id l20-20020a056602277400b007863f74c244mr3042389ioe.17.1688665121735; Thu, 06 Jul 2023 10:38:41 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:41 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 3/8] riscv: Allow disabling SBI extensions for Guest Date: Thu, 6 Jul 2023 23:07:59 +0530 Message-Id: <20230706173804.1237348-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We add "--disable-sbi-" options to disable various SBI extensions visible to the Guest. This allows users to disable deprecated/redundant SBI extensions. Signed-off-by: Anup Patel --- riscv/include/kvm/kvm-config-arch.h | 30 ++++++++++++++++++++++++++++- riscv/include/kvm/kvm-cpu-arch.h | 19 +++++++++++------- riscv/kvm-cpu.c | 19 +++++++++++++++++- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index e64e3ca..56676e3 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -9,6 +9,7 @@ struct kvm_config_arch { u64 custom_marchid; u64 custom_mimpid; bool ext_disabled[KVM_RISCV_ISA_EXT_MAX]; + bool sbi_ext_disabled[KVM_RISCV_SBI_EXT_MAX]; }; #define OPT_ARCH_RUN(pfx, cfg) \ @@ -38,6 +39,33 @@ struct kvm_config_arch { "Disable Zicbom Extension"), \ OPT_BOOLEAN('\0', "disable-zihintpause", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE],\ - "Disable Zihintpause Extension"), + "Disable Zihintpause Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-legacy", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_V01], \ + "Disable SBI Legacy Extensions"), \ + OPT_BOOLEAN('\0', "disable-sbi-time", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_TIME], \ + "Disable SBI Time Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-ipi", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_IPI], \ + "Disable SBI IPI Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-rfence", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_RFENCE], \ + "Disable SBI RFence Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-srst", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_SRST], \ + "Disable SBI SRST Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-hsm", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_HSM], \ + "Disable SBI HSM Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-pmu", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_PMU], \ + "Disable SBI PMU Extension"), \ + OPT_BOOLEAN('\0', "disable-sbi-experimental", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_EXPERIMENTAL],\ + "Disable SBI Experimental Extensions"), \ + OPT_BOOLEAN('\0', "disable-sbi-vendor", \ + &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_VENDOR], \ + "Disable SBI Vendor Extensions"), #endif /* KVM__KVM_CONFIG_ARCH_H */ diff --git a/riscv/include/kvm/kvm-cpu-arch.h b/riscv/include/kvm/kvm-cpu-arch.h index e014839..1e9a7b0 100644 --- a/riscv/include/kvm/kvm-cpu-arch.h +++ b/riscv/include/kvm/kvm-cpu-arch.h @@ -7,9 +7,10 @@ #include "kvm/kvm.h" -static inline __u64 __kvm_reg_id(__u64 type, __u64 idx, __u64 size) +static inline __u64 __kvm_reg_id(__u64 type, __u64 subtype, + __u64 idx, __u64 size) { - return KVM_REG_RISCV | type | idx | size; + return KVM_REG_RISCV | type | subtype | idx | size; } #if __riscv_xlen == 64 @@ -18,25 +19,29 @@ static inline __u64 __kvm_reg_id(__u64 type, __u64 idx, __u64 size) #define KVM_REG_SIZE_ULONG KVM_REG_SIZE_U32 #endif -#define RISCV_CONFIG_REG(name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, \ +#define RISCV_CONFIG_REG(name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, 0, \ KVM_REG_RISCV_CONFIG_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_ISA_EXT_REG(id) __kvm_reg_id(KVM_REG_RISCV_ISA_EXT, \ +#define RISCV_ISA_EXT_REG(id) __kvm_reg_id(KVM_REG_RISCV_ISA_EXT, 0, \ id, KVM_REG_SIZE_ULONG) -#define RISCV_CORE_REG(name) __kvm_reg_id(KVM_REG_RISCV_CORE, \ +#define RISCV_CORE_REG(name) __kvm_reg_id(KVM_REG_RISCV_CORE, 0, \ KVM_REG_RISCV_CORE_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_CSR_REG(name) __kvm_reg_id(KVM_REG_RISCV_CSR, \ +#define RISCV_CSR_REG(name) __kvm_reg_id(KVM_REG_RISCV_CSR, 0, \ KVM_REG_RISCV_CSR_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_TIMER_REG(name) __kvm_reg_id(KVM_REG_RISCV_TIMER, \ +#define RISCV_TIMER_REG(name) __kvm_reg_id(KVM_REG_RISCV_TIMER, 0, \ KVM_REG_RISCV_TIMER_REG(name), \ KVM_REG_SIZE_U64) +#define RISCV_SBI_EXT_REG(subtype, id) \ + __kvm_reg_id(KVM_REG_RISCV_SBI_EXT, subtype, \ + id, KVM_REG_SIZE_ULONG) + struct kvm_cpu { pthread_t thread; diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index 89122b4..540baec 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -23,7 +23,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) struct kvm_cpu *vcpu; u64 timebase = 0; unsigned long isa = 0, id = 0; - int coalesced_offset, mmap_size; + unsigned long masks[KVM_REG_RISCV_SBI_MULTI_REG_LAST + 1] = { 0 }; + int i, coalesced_offset, mmap_size; struct kvm_one_reg reg; vcpu = calloc(1, sizeof(struct kvm_cpu)); @@ -88,6 +89,22 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) die("KVM_SET_ONE_REG failed (config.mimpid)"); } + for (i = 0; i < KVM_RISCV_SBI_EXT_MAX; i++) { + if (!kvm->cfg.arch.sbi_ext_disabled[i]) + continue; + masks[KVM_REG_RISCV_SBI_MULTI_REG(i)] |= + KVM_REG_RISCV_SBI_MULTI_MASK(i); + } + for (i = 0; i <= KVM_REG_RISCV_SBI_MULTI_REG_LAST; i++) { + if (!masks[i]) + continue; + + reg.id = RISCV_SBI_EXT_REG(KVM_REG_RISCV_SBI_MULTI_DIS, i); + reg.addr = (unsigned long)&masks[i]; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (sbi_ext %d)", i); + } + /* Populate the vcpu structure. */ vcpu->kvm = kvm; vcpu->cpu_id = cpu_id; From patchwork Thu Jul 6 17:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44876EB64D9 for ; Thu, 6 Jul 2023 17:39:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbjGFRjF (ORCPT ); Thu, 6 Jul 2023 13:39:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbjGFRix (ORCPT ); Thu, 6 Jul 2023 13:38:53 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DD612108 for ; Thu, 6 Jul 2023 10:38:47 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-76c64da0e46so34295739f.0 for ; Thu, 06 Jul 2023 10:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665127; x=1691257127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ur/4nc0WWZqL23flua+8noNR16SuSLq+XhY4yLBLAT8=; b=mlDe1KkQEhdZ43yhPQMieB0kT72hWPFQGa3i146VWbtpFy7rTAkCslnHTVk6JQ+HGA OzC0WhPsP9KtHr4YxSJ65+Tk5OueI9rjhFVhyxKgYUEbnpNZuCEluAt3EJTh2TmVI5nB 4wc6R+kFHMYUKzv19RBGHUxSofoxAQRyeYaHuT5h6bE737Pz/P3SzlrrwMc/tEaYOJZ0 dUYvO521r+ks7YvTG08jVBjF39/OrFJNrpx34sjPFjO+HRQEUV1h+ifTUTPBqAlZzQ3I pmTi8r1I/DAIRkSMWrIKb6J3oe87iORIsYxbDSwMgRPtzNGXP+V3w2zGTrHw1sWuLv2f gzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665127; x=1691257127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ur/4nc0WWZqL23flua+8noNR16SuSLq+XhY4yLBLAT8=; b=Ckgbz2sHiQu/N/qP99omkmbROUszZ2AUEfVtuWLgSHRtVkfRdBx4NP6J4ZdCdkzGXs VxqIb/2LP3r7Y9kIsHnY+HYz0NykTTrnOQ8A5k03nM3Oam/mqRuZAilTR2zs/Cly5VOs nMOtflWIeHih555OmHNZ9BiBTYNjO6J+8O6R60UbOs0TjW6gH1NXwDT68hGm3mNf4HBB tnpursEb8wsl9HRGjv3N4AYes0FQO+YBiZnos0Da2KNmGx2OgS9cF4lsBxWBfExC9o3Y ulreWdOZfx/oCYtUF/jhtAAU3/cdGUGkAJn0T5yItuoD8hSaahtPN5wi7SJUMG5i96BK C9mw== X-Gm-Message-State: ABy/qLY0toPyQ852uoia9oMV4XWYQE6vf7kDpCJaMXf7EED8T0p+93n2 G4/2DRoK70uNQsxWjSN/xoL8Og== X-Google-Smtp-Source: APBJJlEMDZl4DmMf0qoBSalbRnBjZSFumP5Iwjd9jWeED+ZkP1pelDswvjypqt97iZM0Fcx/Q8Dc/Q== X-Received: by 2002:a6b:4102:0:b0:786:267e:bd4 with SMTP id n2-20020a6b4102000000b00786267e0bd4mr2630097ioa.10.1688665126900; Thu, 06 Jul 2023 10:38:46 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:46 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 4/8] riscv: Sort the ISA extension array alphabetically Date: Thu, 6 Jul 2023 23:08:00 +0530 Message-Id: <20230706173804.1237348-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let us follow alphabetical order for listing ISA extensions in the isa_info_arr[] array. Signed-off-by: Anup Patel --- riscv/fdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/riscv/fdt.c b/riscv/fdt.c index 3cdb95c..977e962 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -15,11 +15,12 @@ struct isa_ext_info { }; struct isa_ext_info isa_info_arr[] = { - {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, + /* sorted alphabetically */ {"sstc", KVM_RISCV_ISA_EXT_SSTC}, {"svinval", KVM_RISCV_ISA_EXT_SVINVAL}, - {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, + {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM}, + {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, }; static void dump_fdt(const char *dtb_file, void *fdt) From patchwork Thu Jul 6 17:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3FB7EB64DC for ; Thu, 6 Jul 2023 17:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbjGFRjI (ORCPT ); Thu, 6 Jul 2023 13:39:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjGFRjC (ORCPT ); Thu, 6 Jul 2023 13:39:02 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1184C210C for ; Thu, 6 Jul 2023 10:38:53 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-76c64da0e46so34299739f.0 for ; Thu, 06 Jul 2023 10:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665132; x=1691257132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jPQWdMrB3vJlDcEi+yFf+uGq+ry4kW1YJbGepQr4/gM=; b=ChscjS7xi5bWmvQTkCoaq5iCQEbC5OT6Xz3XIIzxZUMAfpHKTvMjKVhf6LQNlPdWj6 TH9OpwTyo5iLGye2nNSnWhH2GrlYlxzlvL2a7csv4BtK6aQQ3U4uLv5wqz7gM/VuTCsF UFA04oojXHHalyFp0TGhjDGUoiS/2IOq/StS/2uOMZ18LxqLyjc+ZtHHDjCorEoJD/k8 pKUbKswxqWsB8FVYwWGMM8q1Zy53vk5lAzdy0I9H49PKwHxHmVt5Pc/TemhIn0zBylD4 1dhOMdpJR5U4vCDN19mwnKJgyXT0YGDzgAVX8ZHytbaJzMcax1LksRojqcD/SlCUr8ZM +N7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665132; x=1691257132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jPQWdMrB3vJlDcEi+yFf+uGq+ry4kW1YJbGepQr4/gM=; b=YkZ+j0w38YROfcKvLpBoVjaplEHn20TX+AEHqoM65D7c+7jg3UQKfHyaBD4yUkwUzS /lb3RWfmksLOjCBXK2zLg/NVwuL998US0GTt/kvqNjuJX66r2VjiKGDvoa4eUG0vkFJq WnP8SA6LTWfTBJKIUqBLwpz4moEz+ci7DrCcVWFcZ9JtyHEbNMRlgvPN+YPm0XyL8wQe RYXSqN+gik2mVom9ByCwrFETpwmezVHyXoNZyKG4/rnkk/4PvN/Tw94qoiCCxqzxOHYA Yx0sdmbDOZUvSsnLci7cRfL+3Bo3RKiYhzTluNuDhoQdC3DaaDco/PMmQieC688yq+7z qgeQ== X-Gm-Message-State: ABy/qLZzUQuCOotGTKmw87+rKhBorR8DVlad0dqKvb8gMCoAe8rgGkko 7A5l/D3goxsLdWE46XnHeRNKaA== X-Google-Smtp-Source: APBJJlFfZyjnNopBMKmNevv6TQ/29A1wln9nnX8dJFl55R0cckpdRWcJmQr4+RgdeLoztFzWF3cQKg== X-Received: by 2002:a5d:9e1a:0:b0:783:491a:13fe with SMTP id h26-20020a5d9e1a000000b00783491a13femr2743227ioh.5.1688665132238; Thu, 06 Jul 2023 10:38:52 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:52 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 5/8] riscv: Add zbb extension support Date: Thu, 6 Jul 2023 23:08:01 +0530 Message-Id: <20230706173804.1237348-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The zbb extension allows software to use basic bitmanip instructions. Let us add the zbb extension to the Guest device tree whenever it is supported by the host. Signed-off-by: Anup Patel --- riscv/fdt.c | 1 + riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/riscv/fdt.c b/riscv/fdt.c index 977e962..17d6757 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -19,6 +19,7 @@ struct isa_ext_info isa_info_arr[] = { {"sstc", KVM_RISCV_ISA_EXT_SSTC}, {"svinval", KVM_RISCV_ISA_EXT_SVINVAL}, {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, + {"zbb", KVM_RISCV_ISA_EXT_ZBB}, {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM}, {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, }; diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index 56676e3..8448b1a 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -34,6 +34,9 @@ struct kvm_config_arch { OPT_BOOLEAN('\0', "disable-svpbmt", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SVPBMT], \ "Disable Svpbmt Extension"), \ + OPT_BOOLEAN('\0', "disable-zbb", \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZBB], \ + "Disable Zbb Extension"), \ OPT_BOOLEAN('\0', "disable-zicbom", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM], \ "Disable Zicbom Extension"), \ From patchwork Thu Jul 6 17:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC3E8EB64DD for ; Thu, 6 Jul 2023 17:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjGFRjK (ORCPT ); Thu, 6 Jul 2023 13:39:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbjGFRjG (ORCPT ); Thu, 6 Jul 2023 13:39:06 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 052F2125 for ; Thu, 6 Jul 2023 10:38:58 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7835ffc53bfso22487939f.1 for ; Thu, 06 Jul 2023 10:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665137; x=1691257137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4HjOxqUEAXA51EuHpHwbjwPyrknL5nW6rIhKCbZ+yO0=; b=flyuRw4Ma0QXbEBJiwGKuEp8NPPcV0uiK6v72h1HT8thNv2UUvMF09S63JzVahFL2h fTXjQDCuFf3+G5SKkqUNKdSzYUf+8VLrGSABOTcI4mp5eGS12xFEMJArBzhWPob485m6 +JmhR6nhOapqglmUE50YHnVzs7f/9N29Gs40ORr0a2MqayP4wQ8zt80zSEkb4sMzM1aP NSPZL24ufaoPzDiR0XjlAf+t6+RFhj4VZ4LVCYZZXamY1kZoC5YZVEYEWe4VQdm5Hv6W wpX26HSPf/YO8j94uuM7Tt6pmbK3mXXRcSi014ARRpp65D+y952Q5uPnWsPHD/nDa4El IvvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665137; x=1691257137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4HjOxqUEAXA51EuHpHwbjwPyrknL5nW6rIhKCbZ+yO0=; b=lg6+gtA1b1h53pnSljoWQXSo1XvxVEgqldUKL1c/tR7/8FhQXVZOfZAq/Icf6M4yoJ 34LoMbc0vx1gEeRyrZCXd8HXPVnvZukLEppw/VefIaGAa4nVX4m5ct5yXsgfYhZLiagq DfPg3c356++3VkBhT7n9Xkh95luc4gP6oP7IXHsQl3Y3fBUJw5Hj8sxtA5Hvf7BHTOY6 ThwtOpHsErkFFw3uVfQOZH1wuINcEizIQyoXPZRBJAFpDFvoN7Ch5nmBJHmd7JKw3b5g MQfUpP9ECPq1gor9kyapF8BHHk9Z5ppS2ojLum0opiC4uTVbw6nskG7yajRKGT0tEXDV nvbA== X-Gm-Message-State: ABy/qLZCqE79kIpWSuS+AwYlCyJlCrk6TER4soro3mG6lWqawtxD43iX SEsPU8tw1DlhqUa3De9NWoa6eQ== X-Google-Smtp-Source: APBJJlHzMMHGkMCSj7hjlckvZBsIn/FnBpZZWMrjnB//Ak8uvHz6+gU5aWbYIzmM6KUfzgQDCaTEhQ== X-Received: by 2002:a05:6602:3990:b0:783:42bc:cc5f with SMTP id bw16-20020a056602399000b0078342bccc5fmr4171514iob.8.1688665137172; Thu, 06 Jul 2023 10:38:57 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:56 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 6/8] riscv: Add Zicboz extension support Date: Thu, 6 Jul 2023 23:08:02 +0530 Message-Id: <20230706173804.1237348-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Andrew Jones When the Zicboz extension is available expose it to the guest. Also provide the guest the size of the cache block through DT. Signed-off-by: Andrew Jones Signed-off-by: Anup Patel --- riscv/fdt.c | 12 +++++++++++- riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/riscv/fdt.c b/riscv/fdt.c index 17d6757..a76dc37 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -21,6 +21,7 @@ struct isa_ext_info isa_info_arr[] = { {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, {"zbb", KVM_RISCV_ISA_EXT_ZBB}, {"zicbom", KVM_RISCV_ISA_EXT_ZICBOM}, + {"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ}, {"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE}, }; @@ -47,7 +48,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm) int cpu, pos, i, index, valid_isa_len; const char *valid_isa_order = "IEMAFDQCLBJTPVNSUHKORWXYZG"; int arr_sz = ARRAY_SIZE(isa_info_arr); - unsigned long cbom_blksz = 0; + unsigned long cbom_blksz = 0, cboz_blksz = 0; _FDT(fdt_begin_node(fdt, "cpus")); _FDT(fdt_property_cell(fdt, "#address-cells", 0x1)); @@ -97,6 +98,13 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm) die("KVM_GET_ONE_REG failed (config.zicbom_block_size)"); } + if (isa_info_arr[i].ext_id == KVM_RISCV_ISA_EXT_ZICBOZ && !cboz_blksz) { + reg.id = RISCV_CONFIG_REG(zicboz_block_size); + reg.addr = (unsigned long)&cboz_blksz; + if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, ®) < 0) + die("KVM_GET_ONE_REG failed (config.zicboz_block_size)"); + } + if ((strlen(isa_info_arr[i].name) + pos + 1) >= CPU_ISA_MAX_LEN) { pr_warning("Insufficient space to append ISA exension\n"); break; @@ -118,6 +126,8 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm) _FDT(fdt_property_string(fdt, "riscv,isa", cpu_isa)); if (cbom_blksz) _FDT(fdt_property_cell(fdt, "riscv,cbom-block-size", cbom_blksz)); + if (cboz_blksz) + _FDT(fdt_property_cell(fdt, "riscv,cboz-block-size", cboz_blksz)); _FDT(fdt_property_cell(fdt, "reg", cpu)); _FDT(fdt_property_string(fdt, "status", "okay")); diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index 8448b1a..b12605d 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -40,6 +40,9 @@ struct kvm_config_arch { OPT_BOOLEAN('\0', "disable-zicbom", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM], \ "Disable Zicbom Extension"), \ + OPT_BOOLEAN('\0', "disable-zicboz", \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOZ], \ + "Disable Zicboz Extension"), \ OPT_BOOLEAN('\0', "disable-zihintpause", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE],\ "Disable Zihintpause Extension"), \ From patchwork Thu Jul 6 17:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F34E3EB64D9 for ; Thu, 6 Jul 2023 17:39:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230195AbjGFRjU (ORCPT ); Thu, 6 Jul 2023 13:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjGFRjS (ORCPT ); Thu, 6 Jul 2023 13:39:18 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D16341FF3 for ; Thu, 6 Jul 2023 10:39:02 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-777a4c8e8f4so37119539f.3 for ; Thu, 06 Jul 2023 10:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665142; x=1691257142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vLxp3S0f1awUfUEHEN2CCeWxyqxQ+kK0R236OPFTD+Q=; b=TEWDlG4oUegNL2J0vzFjS+W9KildvxTVcRfhBu7LbYWaIns006vSrEuXG1HdDMRWa8 Rpz6hRxot/rbtP56LfycyOJuoS/WyjoAY4Fu4Oq4gywwbgpm3M2FxKH3cIP5YtHE+qM1 +gmZVNWbqWXCQdnC6IvkjPZUc8FN3ce4GZ7z0/u9ZhhdlDejGfOuXCap/NH5Fr+ZuxLV f6LZV0l1wc1huObk84uXk/Hh+x2YnVGaM/vBpCtCMqsUURaL9rA7Ehp8VHodHIDN4z22 FDkdlYPG6NANdIuxQfWKTBduVE2Y5FHb+xIugoZocwJZ639HjMQq9QmBojXdf1VR8d+g 4dHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665142; x=1691257142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vLxp3S0f1awUfUEHEN2CCeWxyqxQ+kK0R236OPFTD+Q=; b=FoZgb9EcfZFYg/FcREvfTDnuynXa0f8k/q+oU/HtFRRuKs2A6RdBqcWCRxyxzyd3yK KOCwocxN8ldmMHSxF/dfltikdpEbBRRtTj+xrSikCOGevZ94odx+/fIezZhItJYLiovG VEnnHOCvk1/bG7fw3eY9oe2qukHn6/r2JKvAUyokZ/wZAQnwUBfFEFVZEEN6SOykw6am CluKys+9B0JOWRLQDGfkJu1ZuBRCVAHPrFILZv0BQEamOqgVqZ/+euN0bjTaqAHx2fVO kPbmQPHThpsODLPSPXJSQTf8r/xlyoeZuyPXZfCO9HQEmcmRb9QirukuV3FNsEVcQ2pU zS2w== X-Gm-Message-State: ABy/qLYd8FSjbZe6RWfGviPrAEB9HqgjPkzt1Z1LfNVfZ4MHu9wBLF2z nXH9l9W95mhH2DliCpYkHRSlOw== X-Google-Smtp-Source: APBJJlFtADMUQS1jcq2ft4S/AVTrWLbxD9UF9L5+As8nlmdRCGnOWyRxrQJYo70BO2clMqPfsmpFqw== X-Received: by 2002:a5e:891a:0:b0:785:ff35:f340 with SMTP id k26-20020a5e891a000000b00785ff35f340mr4337782ioj.14.1688665141990; Thu, 06 Jul 2023 10:39:01 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:39:01 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 7/8] riscv: Add Ssaia extension support Date: Thu, 6 Jul 2023 23:08:03 +0530 Message-Id: <20230706173804.1237348-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When the Ssaia extension is available expose it to the guest. Signed-off-by: Anup Patel --- riscv/fdt.c | 1 + riscv/include/kvm/kvm-config-arch.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/riscv/fdt.c b/riscv/fdt.c index a76dc37..df71ed4 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -16,6 +16,7 @@ struct isa_ext_info { struct isa_ext_info isa_info_arr[] = { /* sorted alphabetically */ + {"ssaia", KVM_RISCV_ISA_EXT_SSAIA}, {"sstc", KVM_RISCV_ISA_EXT_SSTC}, {"svinval", KVM_RISCV_ISA_EXT_SVINVAL}, {"svpbmt", KVM_RISCV_ISA_EXT_SVPBMT}, diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index b12605d..b0a7e25 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -25,6 +25,9 @@ struct kvm_config_arch { OPT_U64('\0', "custom-mimpid", \ &(cfg)->custom_mimpid, \ "Show custom mimpid to Guest VCPU"), \ + OPT_BOOLEAN('\0', "disable-ssaia", \ + &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSAIA], \ + "Disable Ssaia Extension"), \ OPT_BOOLEAN('\0', "disable-sstc", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC], \ "Disable Sstc Extension"), \ From patchwork Thu Jul 6 17:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13304033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E83AFEB64DC for ; Thu, 6 Jul 2023 17:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231849AbjGFRj2 (ORCPT ); Thu, 6 Jul 2023 13:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbjGFRj0 (ORCPT ); Thu, 6 Jul 2023 13:39:26 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0B501FE6 for ; Thu, 6 Jul 2023 10:39:07 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-78666994bc2so34611439f.0 for ; Thu, 06 Jul 2023 10:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665147; x=1691257147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UIYA8beJZmA2NMdlgIpBmajMkuQ+bKy8H3Ug9/MSXpA=; b=YiUseGS++NnZP5HYtNORUhBq4BPckrWLkmidqcclaQe4tMk9YoaIBfE+vG/OMmIKvI fwk3URZqqS99ijG8L5cbuJADwqXO1xLkS1mfVKz87qiUcedEkGpgoiZkz6+5LsNRv+Fq TKh9iDvmkrNf+LkbVsRl5+Qj6JD3NNIy8mV+/VQaQFduUVjvYRn2KS3j9QQ7UhZwBpR0 f3Xj7qHHIhVTp12qVxEYPifnk8WCahxoCUmyQdfadBV/0Xs14MHZ8Cu70AsSsfEsY880 cAfJ/Zg3NtWnqWxAVzlUO03DC+w0fbMqE/VVPEQzHRf135Kfi0GyVJQsQGcVxyf0VjGl cAQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665147; x=1691257147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UIYA8beJZmA2NMdlgIpBmajMkuQ+bKy8H3Ug9/MSXpA=; b=FNIsbBDdwITlHj2j3z3SsTb8vh0fDFvZp1PpM4tDKpI5UAb473GvnRarLOsLrBNJfu ZdhRQN1yUrt8WVuyuQLh8R7yibCMEYfE6N0bVCpYYYGcfY9aotw++MlC6v8ekvooWuin pjnj5S4k+xs4IiuzT4qkzPkVTgJJvHKpSdKYAIes+TTeBgNhv40fm1/XEDij0W11vwEn b+xjCNaa3WBowShBr7hx2IMgdjzKGgXQKBGvOeUGYIyLOeaZR6K5e3A9oLM8DhQumdVe YrcEcmpRieJDuUnHkKhRaHLUelY29yLlw2V0lQYdKh17XG88PmaHZeagqN4Nh2jEl40d gQ3w== X-Gm-Message-State: ABy/qLYOTOMO3uk92L0MPMvwyF7x3GNJjwYM5gJuVlZYVPB2oC3ZCakZ O1PGtXRwb/vdR0Bk05PvdIbWAA== X-Google-Smtp-Source: APBJJlGO5febAOpcUaBoLA4EyZCXXCdSIHwz/JG901yWz0oqePeSfgIHDeICDdFHW2H3bHgKg5QiIw== X-Received: by 2002:a5d:9eda:0:b0:783:58f4:2e2e with SMTP id a26-20020a5d9eda000000b0078358f42e2emr2274826ioe.0.1688665146895; Thu, 06 Jul 2023 10:39:06 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:39:06 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 8/8] riscv: Fix guest RAM alloc size computation for RV32 Date: Thu, 6 Jul 2023 23:08:04 +0530 Message-Id: <20230706173804.1237348-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently, we ensure that guest RAM alloc size is at least 2M for THP which works well for RV64 but breaks hugepage support for RV32. To fix this, we use 4M as hugepage size for RV32. Fixes: 867159a7963b ("riscv: Implement Guest/VM arch functions") Signed-off-by: Anup Patel --- riscv/kvm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/riscv/kvm.c b/riscv/kvm.c index 4d6f5cb..8daad94 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -61,16 +61,25 @@ void kvm__arch_set_cmdline(char *cmdline, bool video) { } +#if __riscv_xlen == 64 +#define HUGEPAGE_SIZE SZ_2M +#else +#define HUGEPAGE_SIZE SZ_4M +#endif + void kvm__arch_init(struct kvm *kvm) { /* * Allocate guest memory. We must align our buffer to 64K to * correlate with the maximum guest page size for virtio-mmio. - * If using THP, then our minimal alignment becomes 2M. - * 2M trumps 64K, so let's go with that. + * If using THP, then our minimal alignment becomes hugepage + * size. The hugepage size is always greater than 64K, so + * let's go with that. */ kvm->ram_size = min(kvm->cfg.ram_size, (u64)RISCV_MAX_MEMORY(kvm)); - kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M; + kvm->arch.ram_alloc_size = kvm->ram_size; + if (!kvm->cfg.hugetlbfs_path) + kvm->arch.ram_alloc_size += HUGEPAGE_SIZE; kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm, kvm->cfg.hugetlbfs_path, kvm->arch.ram_alloc_size);