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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8447BC433EF for ; Thu, 19 May 2022 09:46:25 +0000 (UTC) Received: from localhost ([::1]:46010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nrcjg-0002ND-F8 for qemu-devel@archiver.kernel.org; Thu, 19 May 2022 05:46:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrch5-00007a-D0 for qemu-devel@nongnu.org; Thu, 19 May 2022 05:43:43 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:33377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nrch1-0001Ll-A6 for qemu-devel@nongnu.org; Thu, 19 May 2022 05:43:41 -0400 Received: by mail-wr1-x430.google.com with SMTP id f2so6375758wrc.0 for ; Thu, 19 May 2022 02:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ITuhYzPNjki87UzX57XMuqrDeH5baLCMtZlx7izlx0Q=; b=KvWjVe8R4FWNad65Qm6ZgBQSMQU2Ci6KkCEVZPkhC5meyD/7x+WxPsz8qlwuy7o3wo KbabhqPSi6Oh+zLFk/JNN+kkJQ7H8dTOiRpA43kVRTgmP9tS/TYQHO0rJZrJWfxuRRuR QOhU8hVt2OFKzit/LTS3lYXFdbfI1EG5EH3fLw3YGVNIzDUdFhjlO0HpazN/M0Chu78K 9rLiHJD/iNpq9ODBbAOKK4WD4jD/yAJ5xoqWVNDkO4M7ghA0lK7wEbQFmtpiTRZTBaNA IFc7R7Xue3Vkb6ch9SaavaN7Vd80pZbYpaG8P6YvwFOV4tpJsXbKVA7B30ijMcFmdEfR tTJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ITuhYzPNjki87UzX57XMuqrDeH5baLCMtZlx7izlx0Q=; b=iuZ1Jxl7d5ZMCmBANBlv6GqtuQLre61h9lazJKW6wa8Lrsjwwz8IYOgw2+CBbfcGO9 uT2tJYXNSMHBlxtY6xxogn0wEkLV2kYUC959ivRQTp9xR0tLEebFdky+z4LyUub4zMH3 uI8nY/lnq6kjFtDUKT0qAAQVc1+oD140tp8gpqvFUMz/Xx5OAfYnhIzZku9uNjfTEVc/ Ev83g84tWJ7xxsuo06IQ/NpbXmE2lZkPQbMTPrKJ8Aw2I7zDIfGfc0EjoJXFjGOuv3zY +EwKal7t6ITdtsV07sQ5NwRbBISsGfgy3UqgrNOuR5aEsQrtR0mEMW5kod0/IwbebE9v F2tw== X-Gm-Message-State: AOAM531fCWEMFXxuD/lSsip1WXciWc74rBk7jXL//uWiB0AIQYVYcyQN 6ZiPMKVe1c3WuSP8Im/QmMzLp3NBiHl7qw== X-Google-Smtp-Source: ABdhPJw1owyBwEng/X2k9dd9ORwQu0wpoPYkKGpaxxHvhgzEwfLiOJKrAjOOtkL9swyP3FtAzVuppw== X-Received: by 2002:a05:6000:18a4:b0:20c:5603:c0bf with SMTP id b4-20020a05600018a400b0020c5603c0bfmr3147222wri.145.1652953417774; Thu, 19 May 2022 02:43:37 -0700 (PDT) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b497:0:8edd:b6b5:d314:5955]) by smtp.gmail.com with ESMTPSA id r1-20020a05600c434100b003942a244ecesm3525029wme.19.2022.05.19.02.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 02:43:37 -0700 (PDT) From: Usama Arif To: qemu-devel@nongnu.org Cc: mst@redhat.com, stefanha@redhat.com, ndragazis@arrikto.com, fam.zheng@bytedance.com, liangma@liangbit.com, Usama Arif , Wei Wang Subject: [RFC 1/2] vhost-user: share the vhost-user protocol related structures Date: Thu, 19 May 2022 10:43:22 +0100 Message-Id: <20220519094323.3109598-2-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220519094323.3109598-1-usama.arif@bytedance.com> References: <20220519094323.3109598-1-usama.arif@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=usama.arif@bytedance.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Put the vhost-user protocol related data structures to vhost-user.h, so that they can be used in other implementations (e.g. a backend implementation). Signed-off-by: Wei Wang Signed-off-by: Usama Arif --- hw/virtio/vhost-user.c | 160 -------------------------------- include/hw/virtio/vhost-user.h | 163 +++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 160 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index b040c1ad2b..cf06c3604c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -21,7 +21,6 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" -#include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" #include "trace.h" @@ -37,10 +36,6 @@ #include #endif -#define VHOST_MEMORY_BASELINE_NREGIONS 8 -#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_SLAVE_MAX_FDS 8 - /* * Set maximum number of RAM slots supported to * the maximum number supported by the target @@ -59,11 +54,6 @@ #define VHOST_USER_MAX_RAM_SLOTS 512 #endif -/* - * Maximum size of virtio device config space - */ -#define VHOST_USER_MAX_CONFIG_SIZE 256 - enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_MQ = 0, VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1, @@ -84,157 +74,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_MAX }; -#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1) - -typedef enum VhostUserRequest { - VHOST_USER_NONE = 0, - VHOST_USER_GET_FEATURES = 1, - VHOST_USER_SET_FEATURES = 2, - VHOST_USER_SET_OWNER = 3, - VHOST_USER_RESET_OWNER = 4, - VHOST_USER_SET_MEM_TABLE = 5, - VHOST_USER_SET_LOG_BASE = 6, - VHOST_USER_SET_LOG_FD = 7, - VHOST_USER_SET_VRING_NUM = 8, - VHOST_USER_SET_VRING_ADDR = 9, - VHOST_USER_SET_VRING_BASE = 10, - VHOST_USER_GET_VRING_BASE = 11, - VHOST_USER_SET_VRING_KICK = 12, - VHOST_USER_SET_VRING_CALL = 13, - VHOST_USER_SET_VRING_ERR = 14, - VHOST_USER_GET_PROTOCOL_FEATURES = 15, - VHOST_USER_SET_PROTOCOL_FEATURES = 16, - VHOST_USER_GET_QUEUE_NUM = 17, - VHOST_USER_SET_VRING_ENABLE = 18, - VHOST_USER_SEND_RARP = 19, - VHOST_USER_NET_SET_MTU = 20, - VHOST_USER_SET_SLAVE_REQ_FD = 21, - VHOST_USER_IOTLB_MSG = 22, - VHOST_USER_SET_VRING_ENDIAN = 23, - VHOST_USER_GET_CONFIG = 24, - VHOST_USER_SET_CONFIG = 25, - VHOST_USER_CREATE_CRYPTO_SESSION = 26, - VHOST_USER_CLOSE_CRYPTO_SESSION = 27, - VHOST_USER_POSTCOPY_ADVISE = 28, - VHOST_USER_POSTCOPY_LISTEN = 29, - VHOST_USER_POSTCOPY_END = 30, - VHOST_USER_GET_INFLIGHT_FD = 31, - VHOST_USER_SET_INFLIGHT_FD = 32, - VHOST_USER_GPU_SET_SOCKET = 33, - VHOST_USER_RESET_DEVICE = 34, - /* Message number 35 reserved for VHOST_USER_VRING_KICK. */ - VHOST_USER_GET_MAX_MEM_SLOTS = 36, - VHOST_USER_ADD_MEM_REG = 37, - VHOST_USER_REM_MEM_REG = 38, - VHOST_USER_MAX -} VhostUserRequest; - -typedef enum VhostUserSlaveRequest { - VHOST_USER_SLAVE_NONE = 0, - VHOST_USER_SLAVE_IOTLB_MSG = 1, - VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, - VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, - VHOST_USER_SLAVE_MAX -} VhostUserSlaveRequest; - -typedef struct VhostUserMemoryRegion { - uint64_t guest_phys_addr; - uint64_t memory_size; - uint64_t userspace_addr; - uint64_t mmap_offset; -} VhostUserMemoryRegion; - -typedef struct VhostUserMemory { - uint32_t nregions; - uint32_t padding; - VhostUserMemoryRegion regions[VHOST_MEMORY_BASELINE_NREGIONS]; -} VhostUserMemory; - -typedef struct VhostUserMemRegMsg { - uint64_t padding; - VhostUserMemoryRegion region; -} VhostUserMemRegMsg; - -typedef struct VhostUserLog { - uint64_t mmap_size; - uint64_t mmap_offset; -} VhostUserLog; - -typedef struct VhostUserConfig { - uint32_t offset; - uint32_t size; - uint32_t flags; - uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; -} VhostUserConfig; - -#define VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN 512 -#define VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN 64 - -typedef struct VhostUserCryptoSession { - /* session id for success, -1 on errors */ - int64_t session_id; - CryptoDevBackendSymSessionInfo session_setup_data; - uint8_t key[VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN]; - uint8_t auth_key[VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN]; -} VhostUserCryptoSession; - -static VhostUserConfig c __attribute__ ((unused)); -#define VHOST_USER_CONFIG_HDR_SIZE (sizeof(c.offset) \ - + sizeof(c.size) \ - + sizeof(c.flags)) - -typedef struct VhostUserVringArea { - uint64_t u64; - uint64_t size; - uint64_t offset; -} VhostUserVringArea; - -typedef struct VhostUserInflight { - uint64_t mmap_size; - uint64_t mmap_offset; - uint16_t num_queues; - uint16_t queue_size; -} VhostUserInflight; - -typedef struct { - VhostUserRequest request; - -#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) -#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3) - uint32_t flags; - uint32_t size; /* the following payload size */ -} QEMU_PACKED VhostUserHeader; - -typedef union { -#define VHOST_USER_VRING_IDX_MASK (0xff) -#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) - uint64_t u64; - struct vhost_vring_state state; - struct vhost_vring_addr addr; - VhostUserMemory memory; - VhostUserMemRegMsg mem_reg; - VhostUserLog log; - struct vhost_iotlb_msg iotlb; - VhostUserConfig config; - VhostUserCryptoSession session; - VhostUserVringArea area; - VhostUserInflight inflight; -} VhostUserPayload; - -typedef struct VhostUserMsg { - VhostUserHeader hdr; - VhostUserPayload payload; -} QEMU_PACKED VhostUserMsg; - static VhostUserMsg m __attribute__ ((unused)); -#define VHOST_USER_HDR_SIZE (sizeof(VhostUserHeader)) - -#define VHOST_USER_PAYLOAD_SIZE (sizeof(VhostUserPayload)) - -/* The version of the protocol we support */ -#define VHOST_USER_VERSION (0x1) - struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */ diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index c6e693cd3f..892020a45d 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -10,6 +10,169 @@ #include "chardev/char-fe.h" #include "hw/virtio/virtio.h" +#include +#include "sysemu/cryptodev.h" + +#define VHOST_MEMORY_BASELINE_NREGIONS 8 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_SLAVE_MAX_FDS 8 + +/* + * Maximum size of virtio device config space + */ +#define VHOST_USER_MAX_CONFIG_SIZE 256 + +#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1) + +#define VHOST_MEMORY_MAX_NREGIONS 8 + +typedef enum VhostUserRequest { + VHOST_USER_NONE = 0, + VHOST_USER_GET_FEATURES = 1, + VHOST_USER_SET_FEATURES = 2, + VHOST_USER_SET_OWNER = 3, + VHOST_USER_RESET_OWNER = 4, + VHOST_USER_SET_MEM_TABLE = 5, + VHOST_USER_SET_LOG_BASE = 6, + VHOST_USER_SET_LOG_FD = 7, + VHOST_USER_SET_VRING_NUM = 8, + VHOST_USER_SET_VRING_ADDR = 9, + VHOST_USER_SET_VRING_BASE = 10, + VHOST_USER_GET_VRING_BASE = 11, + VHOST_USER_SET_VRING_KICK = 12, + VHOST_USER_SET_VRING_CALL = 13, + VHOST_USER_SET_VRING_ERR = 14, + VHOST_USER_GET_PROTOCOL_FEATURES = 15, + VHOST_USER_SET_PROTOCOL_FEATURES = 16, + VHOST_USER_GET_QUEUE_NUM = 17, + VHOST_USER_SET_VRING_ENABLE = 18, + VHOST_USER_SEND_RARP = 19, + VHOST_USER_NET_SET_MTU = 20, + VHOST_USER_SET_SLAVE_REQ_FD = 21, + VHOST_USER_IOTLB_MSG = 22, + VHOST_USER_SET_VRING_ENDIAN = 23, + VHOST_USER_GET_CONFIG = 24, + VHOST_USER_SET_CONFIG = 25, + VHOST_USER_CREATE_CRYPTO_SESSION = 26, + VHOST_USER_CLOSE_CRYPTO_SESSION = 27, + VHOST_USER_POSTCOPY_ADVISE = 28, + VHOST_USER_POSTCOPY_LISTEN = 29, + VHOST_USER_POSTCOPY_END = 30, + VHOST_USER_GET_INFLIGHT_FD = 31, + VHOST_USER_SET_INFLIGHT_FD = 32, + VHOST_USER_GPU_SET_SOCKET = 33, + VHOST_USER_RESET_DEVICE = 34, + /* Message number 35 reserved for VHOST_USER_VRING_KICK. */ + VHOST_USER_GET_MAX_MEM_SLOTS = 36, + VHOST_USER_ADD_MEM_REG = 37, + VHOST_USER_REM_MEM_REG = 38, + VHOST_USER_MAX +} VhostUserRequest; + +typedef enum VhostUserSlaveRequest { + VHOST_USER_SLAVE_NONE = 0, + VHOST_USER_SLAVE_IOTLB_MSG = 1, + VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, + VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, + VHOST_USER_SLAVE_MAX +} VhostUserSlaveRequest; + +typedef struct VhostUserMemoryRegion { + uint64_t guest_phys_addr; + uint64_t memory_size; + uint64_t userspace_addr; + uint64_t mmap_offset; +} VhostUserMemoryRegion; + +typedef struct VhostUserMemory { + uint32_t nregions; + uint32_t padding; + VhostUserMemoryRegion regions[VHOST_MEMORY_BASELINE_NREGIONS]; +} VhostUserMemory; + +typedef struct VhostUserMemRegMsg { + uint64_t padding; + VhostUserMemoryRegion region; +} VhostUserMemRegMsg; + +typedef struct VhostUserLog { + uint64_t mmap_size; + uint64_t mmap_offset; +} VhostUserLog; + +typedef struct VhostUserConfig { + uint32_t offset; + uint32_t size; + uint32_t flags; + uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; +} VhostUserConfig; + +#define VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN 512 +#define VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN 64 + +typedef struct VhostUserCryptoSession { + /* session id for success, -1 on errors */ + int64_t session_id; + CryptoDevBackendSymSessionInfo session_setup_data; + uint8_t key[VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN]; + uint8_t auth_key[VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN]; +} VhostUserCryptoSession; + +static VhostUserConfig c __attribute__ ((unused)); +#define VHOST_USER_CONFIG_HDR_SIZE (sizeof(c.offset) \ + + sizeof(c.size) \ + + sizeof(c.flags)) + +typedef struct VhostUserVringArea { + uint64_t u64; + uint64_t size; + uint64_t offset; +} VhostUserVringArea; + +typedef struct VhostUserInflight { + uint64_t mmap_size; + uint64_t mmap_offset; + uint16_t num_queues; + uint16_t queue_size; +} VhostUserInflight; + +typedef struct { + VhostUserRequest request; + +#define VHOST_USER_VERSION_MASK (0x3) +#define VHOST_USER_REPLY_MASK (0x1<<2) +#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3) + uint32_t flags; + uint32_t size; /* the following payload size */ +} QEMU_PACKED VhostUserHeader; + +typedef union { +#define VHOST_USER_VRING_IDX_MASK (0xff) +#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) + uint64_t u64; + struct vhost_vring_state state; + struct vhost_vring_addr addr; + VhostUserMemory memory; + VhostUserMemRegMsg mem_reg; + VhostUserLog log; + struct vhost_iotlb_msg iotlb; + VhostUserConfig config; + VhostUserCryptoSession session; + VhostUserVringArea area; + VhostUserInflight inflight; +} VhostUserPayload; + +typedef struct VhostUserMsg { + VhostUserHeader hdr; + VhostUserPayload payload; +} QEMU_PACKED VhostUserMsg; + +#define VHOST_USER_HDR_SIZE (sizeof(VhostUserHeader)) + +#define VHOST_USER_PAYLOAD_SIZE (sizeof(VhostUserPayload)) + +/* The version of the protocol we support */ +#define VHOST_USER_VERSION (0x1) /** * VhostUserHostNotifier - notifier information for one queue -- 2.25.1