From patchwork Wed May 10 08:37:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236628 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 2BF77C7EE24 for ; Wed, 10 May 2023 08:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236777AbjEJIjf (ORCPT ); Wed, 10 May 2023 04:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236755AbjEJIjM (ORCPT ); Wed, 10 May 2023 04:39:12 -0400 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCB783E3 for ; Wed, 10 May 2023 01:38:09 -0700 (PDT) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-195c61067beso4068197fac.1 for ; Wed, 10 May 2023 01:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707888; x=1686299888; 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=IUXvVkj/TWWNeHEWN4Kt0imMoJ+SpUpeOYQamoYpdQ/yMwU2bYA8soklnIWXHwAJLF jhVRc/MzKQVXsJbgwwJ+yIXa0G2/ANbletAn3dYbegwIF9wOwp2MIWzF5H8zLM8rfkPp QS0jUTfFT57X/Ua9QetyL8I0CdzqckKfCu40ozykK9kFwakfbvKHinmcqsZhxIcxhSWE 7iuWarTb+Jdqt/waJ5p355MbinQ6Z7rT+y2V9sq64RiiqJtbvFkfrrm1flU/1N5Ku+kd e6nTKUx3wodbiDJen0vLXXNOXrLTg5+SJdQS5HXfZk4xTF3YwQJhOo9DtMpUx8KIFwcS FLnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707888; x=1686299888; 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=Ma6vyCUhGX1YHEOkKZoMf/2ZsI+grm9+qGPE0dnmWpLtED0OO62v01mlsxOAIjlOJe JcPs8MVd18dyEenWrnI2lNVrgQasblAxeljDX1lsLeLXm9EvZVLPNM7vH3lFucHqIrTv 1NCqHF82iHppGHBoIA1gG7pYzcTxhwGz/bOzTMCR9aVYbtg+EpSn3sW6Ne29PQLDH841 uCGzrDlBlyKs859uyLagqNaBKCkII8xEsjf29rL6YdApxeX5Q8QAUOae6QExOrGDZfK0 TLBjsRYo4z09E5hSx57s2pYCG+zKvUebgmGr2aMSxPuij6x/neae6RbXmBKZrU7eIeXo aHog== X-Gm-Message-State: AC+VfDznPoZLNv+SBnmuOxxTjB4/+mnqRSWrK8cY4hdrIxIfS8XMbUQn nuewQOI5VMxEk2YG66oJT112FQ== X-Google-Smtp-Source: ACHHUZ7Kz2EUjlNpHiuSsapVN8dDjYgETy+VYgQ8FgHK6P/wtSByajislMVFrXtBpCxmHlv0iBXb9Q== X-Received: by 2002:a05:6870:a247:b0:184:57fb:6183 with SMTP id g7-20020a056870a24700b0018457fb6183mr6929287oai.17.1683707887768; Wed, 10 May 2023 01:38:07 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:07 -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: [PATCH kvmtool 1/8] Sync-up headers with Linux-6.4-rc1 Date: Wed, 10 May 2023 14:07:41 +0530 Message-Id: <20230510083748.1056704-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236626 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 66A8BC7EE22 for ; Wed, 10 May 2023 08:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236754AbjEJIjc (ORCPT ); Wed, 10 May 2023 04:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236756AbjEJIjM (ORCPT ); Wed, 10 May 2023 04:39:12 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F2E7295 for ; Wed, 10 May 2023 01:38:14 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6ab028260f8so2271747a34.3 for ; Wed, 10 May 2023 01:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707894; x=1686299894; 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=DTQ0yY9TJi7yvJqp5vPKDUqpu6nKpgJaTTOwcreSy88+V9VkyMdk8e9HcPVPqkVEp6 zXeFQa9vMSM2N/c9jc7bLreMAXnHohtxZgT13jgSxQnw+hIxNhgTvnwSGBP6bBeOlRVO zif7/pw3wBfO5ai3QBu3ZMCjpF8SHIuKCLzp8WpCNllH2fU5+k1ox583JHSsdiEqueK0 vSeFcjq9o9mH+7jpmUup1zcp6ziUZTAdeLSAlsVM4kSh97kuHHh/kNIIbu5xf/h+zasA +/Ty5a14nmbjk5CqcRgtBf9CEgStm5L7iCYyXvi/cRCvUi0a6V6bEGEjIsBBwGWQ8Nse e/mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707894; x=1686299894; 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=GVan1RkIXooK+Bl+QJg/w+8j5Ma6r7yDcD2FXKyU3ouVmm0Rq52dryafIm/WuX1SJi h7/jicbiNlHXj+lR3puZxcGY+Fzg2pQ5Y7hm/y+kpr4jHYnrLEo6Mb2dwRnEs1SRxE4E PJaAdrWOHGLcy3IGJzNLkbExgh8W05kZhRSp4kBXOC6oHm8I3TD7eevhZo2ItV9fU78N cHY0sZacqarieJtf7IgFsO2t9fKlyqXbz3IKgpryqlX7MAm/NlML+dBh4egDiuMkvFrh c/mzlX9rJ1UyEFyJFcY2e2cpvf2Qip6Cka0achdfgLFGLBV+rTlDDTBfJIP+rCGYfsaI KBVA== X-Gm-Message-State: AC+VfDwceh/q+woFg1sj6uPYKNuaFQPPKPmd8ohsGBHvNvFALfP1X9OG PJHWOyu4HD1OaqB9cSZH8tzQEA== X-Google-Smtp-Source: ACHHUZ6/tMvYvyRRTVtNNnKEidxzHrU87OtybXKSJHZcPBMLLRjj2Jl/l7tXINaB99wPaocChgzxuQ== X-Received: by 2002:a05:6830:1256:b0:6ab:1a07:e61a with SMTP id s22-20020a056830125600b006ab1a07e61amr2497994otp.9.1683707893810; Wed, 10 May 2023 01:38:13 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:13 -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: [PATCH kvmtool 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Date: Wed, 10 May 2023 14:07:42 +0530 Message-Id: <20230510083748.1056704-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236627 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 395E0C77B7C for ; Wed, 10 May 2023 08:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236772AbjEJIjd (ORCPT ); Wed, 10 May 2023 04:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236757AbjEJIjM (ORCPT ); Wed, 10 May 2023 04:39:12 -0400 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 708B930DA for ; Wed, 10 May 2023 01:38:20 -0700 (PDT) Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-54fd9c0e435so487098eaf.2 for ; Wed, 10 May 2023 01:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707900; x=1686299900; 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=iRWoDJGTbUH5F8l/MHWDwQM+SSBdN7lawEl0Fzcmel9PB5WrdETIX629TQhUSqGKPs S8axxbDC/ScyDzmj73GHUiH8X5QcF9mx1GXTHG+l+3fipncFc8Fdvf0eWfTbYD9kIj44 oShEmtUyzbL//iYOjgOhaorwzNXLSW0FH5BdpWFVaLd3HSfVfmq1I/sAu/ttfG9Y/A6U B/F69EhGryKi5xSiHKUnJcWpL4fa1K1/bq8D7CR4FemM9NEPr5I8Y44qq3iyXiJOksQm JK89lgClXqRzFmWU0I5TE8jkZpGCbS9dizF0DCyUkdWiWdx2UC3d1VS3w4qoCRSrEc57 KeRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707900; x=1686299900; 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=TAVV5uNHz8D9PFvK782XkHDy1gG95oaKlKYsaBpIlPydtkE1mal9WRg1gyrywf6I0K N3Qj/7YOhrhX+3pYDYiHUgR+jYSxY5V4PbF4SLYRwvL2cmzc9ZUkrW/MTuMC5BP8tAkv J9p5N2ad4eFQ4jkEm8BCApc6/CwSFemVL+gFyTpJDT/9OEmVQtZXhv4WNmuJGCl8w8H7 YjoTLXqlRsyGGoRQ6+C1OWlwcDbySIQA6bncZxABch46ZRBJ0jM2VbdhelshBbQsbxgK KNKRPfXPnw092+TBflvGNZ6w3f9Z/B2GTHan/83H6D4VKHbrcYh7O4qIGlzugQp612L1 C5KA== X-Gm-Message-State: AC+VfDz3XCTj4fPdKuei/AKGoYuTMOSR4RSf7B5Chvf8qqIP07aH5aRv 53FGjK0ng6L/zgNiaztJMoKWaw== X-Google-Smtp-Source: ACHHUZ70OA6WXyp3aPEqzfo8HfSG3/T6byheGDBK/16lSDEPYBV+uJKTnUYL2rIpCRwsqy0q3E/xDg== X-Received: by 2002:a05:6820:291:b0:54f:51f3:48b0 with SMTP id q17-20020a056820029100b0054f51f348b0mr2722934ood.7.1683707899629; Wed, 10 May 2023 01:38:19 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:19 -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: [PATCH kvmtool 3/8] riscv: Allow disabling SBI extensions for Guest Date: Wed, 10 May 2023 14:07:43 +0530 Message-Id: <20230510083748.1056704-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236629 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 6F49AC77B7C for ; Wed, 10 May 2023 08:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236719AbjEJIjh (ORCPT ); Wed, 10 May 2023 04:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236706AbjEJIjM (ORCPT ); Wed, 10 May 2023 04:39:12 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 476F2127 for ; Wed, 10 May 2023 01:38:26 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6ab0a21dd01so1174187a34.0 for ; Wed, 10 May 2023 01:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707905; x=1686299905; 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=o79i6XdcYTSEeO4/8WCPaSWURNUD/nK2evnFN04SOMKw5I7HMIAGvkHo9wTvCNeRfM 7wUPG8TfxJZbQxr/MZYSfPJxXpIW+e8V2M6Cwj7wxUVTsxTVw+l2+QsI6vtds31CU8mZ 9BKuVxyaD2pFBUmJSAOh9vdPy5+Ts7DGQrzNMgYpEEMoN1ab77VeUCtqw+DwzggwCcI8 Ki0qLmYWu2Nh7mEQ/NqyOnMSg+BgRgHMqCoVxZY0nuZScoH9y15pWJyRCTOATnEykS1c /xI2TprKygvct8ZvgOuTLGduvFRYjI/S8Ae1o4kh02ef+BWSdzrO0LL+hnve8Fohv9XQ v8Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707905; x=1686299905; 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=P37TbIe7ZMc3LQ2U+QLTdpGm8ahSC2CeB32iH7km23RfzuIOcdWOwibXpBeuXUzPTi 9ACVu/ufgtMN7HUyAZKQtfREK11NNRILO0HFeH5EY7aLOaGgRulUacxwVhBWvgxj9j9m 2XF1i+DfwOREA3g08REYaB+jBQYAQcz4Q1fe/jZeBMnRiwp5wcHHSIo49WAmjkV9dmFO t+FFRrAnkP4d2Z1rP5VcTWEoWC1fPNWDEet7jiG53cb0ekFKI3Tru/wzcl4t9ljUvAyn pSiwsWrmtTqYZxe2y6qS/n5c9+qVW/uu+Lrfzx/jcvjlKPumFeuVE4PGJAS0G5JVhNdu 4YGA== X-Gm-Message-State: AC+VfDwLAJD2WwuR6/URZazXyWipPsR1OjJhCPpuRGU5d0n83XYrYeSj a+yZC8v1X/Zv+dWLYmXahEDuGg== X-Google-Smtp-Source: ACHHUZ4gbtEuQJOc5ozA/3ihYRfRjHth4EwBBYn8mebF9Gi4q2yR6qCZ148yx0CeXrpMfusPraIc7A== X-Received: by 2002:a05:6830:13c9:b0:6a6:814:478c with SMTP id e9-20020a05683013c900b006a60814478cmr2613226otq.28.1683707905486; Wed, 10 May 2023 01:38:25 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:25 -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: [PATCH kvmtool 4/8] riscv: Sort the ISA extension array alphabetically Date: Wed, 10 May 2023 14:07:44 +0530 Message-Id: <20230510083748.1056704-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236631 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 8F456C77B7C for ; Wed, 10 May 2023 08:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236653AbjEJIjk (ORCPT ); Wed, 10 May 2023 04:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235606AbjEJIjN (ORCPT ); Wed, 10 May 2023 04:39:13 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 536BAE76 for ; Wed, 10 May 2023 01:38:32 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6ab13810d34so1502848a34.0 for ; Wed, 10 May 2023 01:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707911; x=1686299911; 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=JxCgASziri3weB4Vu1dJjlEzQBoDekv7AMkt4P2rTJf3OfOSBxFNyITmnUtPMvrpIi RA2JDlm+UsV+6lxNoIftjTbPE/pf4G8oZf3wNouGisjOJzLHV7qjDGrgMw141IzlgRMY MrZSY+cXlUblAjyu61nNjpw0PITtIwVAZdRNmeadIN3XxcnnzNUOOgMXTXgK3IQ4dCmx MO2gQ4YdWzX7kk/G2cNE6bAFL4aI8phwRkYYzynoUvJZ79pNsOmzf7lZZlyxWz6wi0EB cD5RpNVdXYGjok39W6dsUdkvOJ/xYwJniZ4QcHULtkNmOvBZpdM0gneTVU1ggygW5Z5s 0oMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707911; x=1686299911; 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=AWmIUuUXLW6v4dFjGuADvyH/tbKh7ag2hobAH1M0Kq+DcLOAkfrmnZPA4SC/0Qv08c 104tN7X3w2O4y0RDisOu8TDR9Jkuxa5Zc9z7FcoSCDd8dTOrVPjcGEBQTcSpPDzn6bXk WrWIXFL01D48cjposQo1kJeM2D1/DatbV+UEnslMYtwQGtva1cdrX1Xc/g++qLah2OVL mgBLJfZPZimBARumBYF2LZVRUX8wzG6TogafI+CqtqPxbIAqMAJ+qHTRuAsywFc4UnHd rrN87cOtB1LCkmc3AnqKulTjcdV6WtJ7s6HSBU0JIfVPXwlmWCu3zVH0Gx10soOpltUA s4bg== X-Gm-Message-State: AC+VfDyQTXSCmSmoJxf9dKCLUlQOhDEz4Pf8iO6ICgfbxTD7eG3qMau7 vbqQWUnXl47C2Zii1kpoK4SoTQZZibDqjcZRjUE= X-Google-Smtp-Source: ACHHUZ5vghWiHKJMTwFxxDpmAaPOUSO7RWEiLkUF6ExcD3o52ijUX+uEgKjYkFf+IvjSadfu6qv5eQ== X-Received: by 2002:a9d:7489:0:b0:6a7:b2d1:9bb1 with SMTP id t9-20020a9d7489000000b006a7b2d19bb1mr2514672otk.38.1683707911431; Wed, 10 May 2023 01:38:31 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01: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: [PATCH kvmtool 5/8] riscv: Add zbb extension support Date: Wed, 10 May 2023 14:07:45 +0530 Message-Id: <20230510083748.1056704-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236630 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 D190DC7EE22 for ; Wed, 10 May 2023 08:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236781AbjEJIji (ORCPT ); Wed, 10 May 2023 04:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236708AbjEJIjN (ORCPT ); Wed, 10 May 2023 04:39:13 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0A410FA for ; Wed, 10 May 2023 01:38:38 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-54fd9c0e435so487151eaf.2 for ; Wed, 10 May 2023 01:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707917; x=1686299917; 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=Pu/9nf7xq52NNfN/MAIwXlNcUSEkFblEW6bag2Zzfhwgsg+HX3zR0qKWF7hQafK1WC mBYsb8/ptNBksaJV0/RGlvUW05N07jYw149VNQUj/DhkA2oEX+R/jxgcLbThRjO1zCC5 yqRGFTfGzMguJbw/S0xS0hyz/kSjiFPHi8JgLf6L48mobFmFD0kzxL4AXp98aGQL70yb WcfKu3JhEcKhdVek6RSomsQR4VtVaEuG7kjQHv3PmnfNtaQ95syYTul1jzCRubE0KyuP O8v44cdQF1GPCYu40z06RSDZye8XnX5cI52FtpwPKLP8/k7fRoZqHfFbm1i/r4d8upBn G1Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707917; x=1686299917; 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=Xrk9WdBLIP490UrXY973B4P9D96QfP5ZI7l4qoC/8RqGiTo1ZMwXkeDZV2WZsNt7EQ kLJ3Js0OoiyWIw/+K50i2FgPoX3Uylk/ccttrE79xY3U0TKqCg+0OG4uVnjG5JAUhq13 jF/c6Skyto+1C3DV2VyJrYzeElylyt5BlliTm2pk4G8bYVcTSrKO8ZX2wSpTnBtiYR/l SYGfffGjbYARgFNcxIkVucbxsLDz8WRyFGx1YoZfrb84ki2ia0x3oDOFlYrsuXx9anuL hE5X1cIbVE1bUrHVFGUPwcWhkocT9/1hcF1l6Sgz1z4eb7GTVAlgPw996IB+XQkRNibR CH/w== X-Gm-Message-State: AC+VfDxXUdN4I1FeXmHZ3/ZwwEseDoLIxetAg/RdAm+0XZxUweeJlOtI a/oyIIhvnVyqzYbVf2xR69qXkw== X-Google-Smtp-Source: ACHHUZ7AviZeS/UgPri0IkvH2z3CmhkH5XtCxoC8/0bfZGpaDbBjFNyhHyUcDOW1vbmh4yVbElWUMg== X-Received: by 2002:a4a:301a:0:b0:547:6a79:18cb with SMTP id q26-20020a4a301a000000b005476a7918cbmr2344887oof.9.1683707917543; Wed, 10 May 2023 01:38:37 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:37 -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: [PATCH kvmtool 6/8] riscv: Add Zicboz extension support Date: Wed, 10 May 2023 14:07:46 +0530 Message-Id: <20230510083748.1056704-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236632 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 DEA13C7EE24 for ; Wed, 10 May 2023 08:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236605AbjEJIjm (ORCPT ); Wed, 10 May 2023 04:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236420AbjEJIjO (ORCPT ); Wed, 10 May 2023 04:39:14 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9DAC1713 for ; Wed, 10 May 2023 01:38:44 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6ab0a942f46so1955933a34.2 for ; Wed, 10 May 2023 01:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707924; x=1686299924; 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=LioKhy+D0FIZ7nGQpjXQKDSDc4LsX67rcXpsrCBcczNORM9Yj6a5lM5AQpT4zky1VB s6isWlzB8Lpg92pUzqwLMQLeCR7YqkPdrKFLMv0Omy+ZIpuNFZLDRCLPBNdPcpW80qO9 MolcVS5CU7TE1ypjAeNAHQeCNQpnrmj4c7diIQdp+ff59y+QNuEX2fQ1rDKq3hexo1CS Wa927LRS2DTiYS6IrMV6OA+zoLAQYdnMfUjVrgQUlNeyKDNjQDhiEg12Yqge4AG7J7NZ HP5oy0bk9EumBV0uMFuZ3udCAEhY5HHHiHxdWCH6XIqZlyQkAQBNPN4lFd5fHYcDW6a0 w0fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707924; x=1686299924; 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=dBTZthaCYyphJTpcd5Anuaenma+zmX+lM6YD37yIfuxVwPJhLkgN3JX0gcJIgbK6Iz yoprnqWFmENLHf1zODzG3LrGktavwmJS7nSvTAkCsyPZVozVIlGehk2UtSEQ6f5TEJhn rbi4ydPKPR3fj8qAuXZAKPmx0VFXiusMod0kurQx8YzDm5nra3KPmsm4cm4cqLPaipWw AQrm73GeKqIGL8fATUl6UrqStupj8Y3iYb7GlOJH9m+2qC92GMQXNR89OctkZJd8NBS3 D733CyfvM9VzldkY4V2QDykCxKTPq1WhdNydqJYQ5JaSETIU+IL2D8J5o93B0rUbwdDu ZTuA== X-Gm-Message-State: AC+VfDzQGZzXJ9XjYIcXvc2mxQheXpiZNsgTdwWUHhR3JW/qtzgis4RP ScjqZTs0hnJC3oB8pCCitYfGwQ== X-Google-Smtp-Source: ACHHUZ7vniKGbmrZ1k4vNnbCDyzT137B/5VmjbIiqx0sjLRC6bECiSL2I1h9SAtb+3h/XWIgO8zIvg== X-Received: by 2002:a9d:76c8:0:b0:6a6:389f:ad9c with SMTP id p8-20020a9d76c8000000b006a6389fad9cmr2397800otl.28.1683707923997; Wed, 10 May 2023 01:38:43 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:43 -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: [PATCH kvmtool 7/8] riscv: Add Ssaia extension support Date: Wed, 10 May 2023 14:07:47 +0530 Message-Id: <20230510083748.1056704-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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 Wed May 10 08:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13236633 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 C4FBFC77B7C for ; Wed, 10 May 2023 08:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236688AbjEJIjo (ORCPT ); Wed, 10 May 2023 04:39:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236751AbjEJIjP (ORCPT ); Wed, 10 May 2023 04:39:15 -0400 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA83A5FF1 for ; Wed, 10 May 2023 01:38:51 -0700 (PDT) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-18b1c643219so2801048fac.2 for ; Wed, 10 May 2023 01:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683707930; x=1686299930; 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=D4cGe8gY8Xl3/CpkIKCO0Hhk6J+mhlPUcRZFd3Nvjx4WDq8fvK2yfQNxMs0PaEtTQg 5bfTsjF+JKHFOzavodeQj1JeaRm92L0toCyZufL+tSxgUT9XJNlc8d+RSA3u+NblFukD nHeEtGM66fy2IQvWpcrRj9MwQimjWy9hm7cqtnXV+7V1XQ4vJzq3V5zziB+1x/TopweM Oc2TkRa/lRv1ktSz5CAMMoaq7KOP3NOh6nYMxF/qm+nsuQb1Hbv7u+cE/XNZflZ4KwGF BgmdCJYO5ZMrrsXBpxl7WvGI0P+hXB3IDxhhd0B3rUmYg5g8GvUdddbjxkuEqEwQlmDE vNoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683707930; x=1686299930; 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=KYfyHKrLnyMLyM/kTv9jme4tYFenpXgmuzZYQqX+0smDp54RctWpi2rLrC/DfrvLzY oDtL6OVzmRlOoov1FAVnetDoziK6wm3623uXqB5QefKa32EhR//WvC7CsHyA3AP3axlO 3xDKMJD+NqNBFUyZcuv6LiUDrrAitQDTP+0tIT9zxy9+CUL7mZBJTbSURZx8Pmb0JZWj TnvtMiZTA9u8mLfZiIJhv45kaQPFnIjqI8mld6HNlH/T+rHCNGvTbxapSU0DggXjD4Y3 s77lT87rOsOp7992+KWgp9chmOaEZjM3yflbNMUnZg65ZUAFZu5EZzovqJNiaYWkZbye 1XIQ== X-Gm-Message-State: AC+VfDy7xIiqny4pelrnqap8+2qrq+sTtHzSeHqrmjCQifU+tXM2adlU 7E3m+7laRXigDy7XL/NOS/pKKw== X-Google-Smtp-Source: ACHHUZ6sogvBjtHFRozzhu5KwT2UIUSBvh8ixz3U327hzB/z7lrXqT0sHh0Yq4hoI4D8o71Tde7M6g== X-Received: by 2002:a05:6870:d501:b0:184:5f08:a130 with SMTP id b1-20020a056870d50100b001845f08a130mr6271903oan.33.1683707930140; Wed, 10 May 2023 01:38:50 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n12-20020a9d64cc000000b006a65be836acsm6049711otl.16.2023.05.10.01.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 01:38:49 -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: [PATCH kvmtool 8/8] riscv: Fix guest RAM alloc size computation for RV32 Date: Wed, 10 May 2023 14:07:48 +0530 Message-Id: <20230510083748.1056704-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510083748.1056704-1-apatel@ventanamicro.com> References: <20230510083748.1056704-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);