Received: by 10.223.185.116 with SMTP id b49csp566631wrg; Fri, 23 Feb 2018 03:21:04 -0800 (PST) X-Google-Smtp-Source: AH8x224houBO2BAGI/3UBwT+XikcY87oer+0iKKFfKwb+JEoS6N9VH2Jkdg/d0GA01CA1jAdDjXe X-Received: by 10.98.18.70 with SMTP id a67mr1419368pfj.213.1519384864516; Fri, 23 Feb 2018 03:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519384864; cv=none; d=google.com; s=arc-20160816; b=Ua1TX4GB2sHJrh+HbEg8+knQcjaWQ8mDD2B7tAgyoM7oEjL9Rf+3xSx5Fm6hbY6Vj3 UamlrFjEp05wscHbbaGpY8VUq9F50e3lGkOp+q6/Qbk6Q5hswSeespWqgOZ+GgGYHP8c cZuAzOw/P6dXBh359QUGqYSKEX7WieW0GuNslaJFd4knPrxqgGxEMvC3M3VdxfwW0Bsp woz0r2YbtvXh6DyetCqw9G8xE4jSyptMhSg5w4ocVkVHBNo6WNis5D28hkvoM8OQ603h W941yEIHnyosqng/zmKbRFWf8ADGpfR+kaDuwgtWSIW2aljiEo44B7p/LcFIEvfT/eJR 4PZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=2gRdOjFqNTtHI7uWP7OoW8uHSTXq7AwljTe9vk7ufsg=; b=SQs+oiuVyNa8fRbKfK2jAfFqKRG9bz9ZBOOZ6ePso8PC3MhIy+ZkCBGIDEtzUdXl/z gP7J7MuBkE7/pN+HNbvDKRMcjNPrL9ZkSfLmVBk3WVLSOTC1BOzOLSu2A00Xv2kaG8dH WhQBxP3QzQrKZKwVs71hSXk1pkSc3KFoX0uWZjpaGZ5lfJ+9pGZW1wKhcseUvErYGVG0 wPF5n+sz0eIGPRAxFhLgrjGhBgaEFUotAWJvSRfjXapQnlWuVBMELWtTx4sROxuOTkBG BftHlTotd5DkN7I+UVtGGMer8YiskLSnC6MraAEBjYNXXh7hbcKeyOnPAfgbCuUcIq/i tvqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si1393820pgc.638.2018.02.23.03.20.48; Fri, 23 Feb 2018 03:21:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751704AbeBWLTl (ORCPT + 99 others); Fri, 23 Feb 2018 06:19:41 -0500 Received: from mga04.intel.com ([192.55.52.120]:53962 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751559AbeBWLTi (ORCPT ); Fri, 23 Feb 2018 06:19:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 03:19:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,383,1515484800"; d="scan'208";a="19758523" Received: from debian.sh.intel.com ([10.67.104.164]) by orsmga007.jf.intel.com with ESMTP; 23 Feb 2018 03:19:36 -0800 From: Tiwei Bie To: mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: jasowang@redhat.com, wexu@redhat.com, jfreimann@redhat.com, tiwei.bie@intel.com Subject: [PATCH RFC 1/2] virtio: introduce packed ring defines Date: Fri, 23 Feb 2018 19:18:00 +0800 Message-Id: <20180223111801.15240-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180223111801.15240-1-tiwei.bie@intel.com> References: <20180223111801.15240-1-tiwei.bie@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Tiwei Bie --- include/uapi/linux/virtio_config.h | 18 +++++++++- include/uapi/linux/virtio_ring.h | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h index 308e2096291f..e3d077ef5207 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -49,7 +49,7 @@ * transport being used (eg. virtio_ring), the rest are per-device feature * bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 34 +#define VIRTIO_TRANSPORT_F_END 37 #ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've @@ -71,4 +71,20 @@ * this is for compatibility with legacy systems. */ #define VIRTIO_F_IOMMU_PLATFORM 33 + +/* This feature indicates support for the packed virtqueue layout. */ +#define VIRTIO_F_RING_PACKED 34 + +/* + * This feature indicates that all buffers are used by the device + * in the same order in which they have been made available. + */ +#define VIRTIO_F_IN_ORDER 35 + +/* + * This feature indicates that drivers pass extra data (besides + * identifying the Virtqueue) in their device notifications. + */ +#define VIRTIO_F_NOTIFICATION_DATA 36 + #endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */ diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h index 6d5d5faa989b..77b1d4aeef72 100644 --- a/include/uapi/linux/virtio_ring.h +++ b/include/uapi/linux/virtio_ring.h @@ -44,6 +44,9 @@ /* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 +#define VRING_DESC_F_AVAIL(b) ((b) << 7) +#define VRING_DESC_F_USED(b) ((b) << 15) + /* The Host uses this in used->flags to advise the Guest: don't kick me when * you add a buffer. It's unreliable, so it's simply an optimization. Guest * will still kick if it's out of buffers. */ @@ -104,6 +107,36 @@ struct vring { struct vring_used *used; }; +struct vring_packed_desc_event { + /* Descriptor Event Offset */ + __virtio16 desc_event_off : 15, + /* Descriptor Event Wrap Counter */ + desc_event_wrap : 1; + /* Descriptor Event Flags */ + __virtio16 desc_event_flags : 2; +}; + +struct vring_packed_desc { + /* Buffer Address. */ + __virtio64 addr; + /* Buffer Length. */ + __virtio32 len; + /* Buffer ID. */ + __virtio16 id; + /* The flags depending on descriptor type. */ + __virtio16 flags; +}; + +struct vring_packed { + unsigned int num; + + struct vring_packed_desc *desc; + + struct vring_packed_desc_event *driver; + + struct vring_packed_desc_event *device; +}; + /* Alignment requirements for vring elements. * When using pre-virtio 1.0 layout, these fall out naturally. */ @@ -171,4 +204,39 @@ static inline int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old) return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old); } +/* The standard layout for the packed ring is a continuous chunk of memory + * which looks like this. + * + * struct vring_packed + * { + * // The actual descriptors (16 bytes each) + * struct vring_packed_desc desc[num]; + * + * // Padding to the next align boundary. + * char pad[]; + * + * // Driver Event Suppression + * struct vring_packed_desc_event driver; + * + * // Device Event Suppression + * struct vring_packed_desc_event device; + * }; + */ + +static inline void vring_packed_init(struct vring_packed *vr, unsigned int num, + void *p, unsigned long align) +{ + vr->num = num; + vr->desc = p; + vr->driver = (void *)(((uintptr_t)p + sizeof(struct vring_packed_desc) + * num + align - 1) & ~(align - 1)); + vr->device = vr->driver + 1; +} + +static inline unsigned vring_packed_size(unsigned int num, unsigned long align) +{ + return ((sizeof(struct vring_packed_desc) * num + align - 1) + & ~(align - 1)) + sizeof(struct vring_packed_desc_event) * 2; +} + #endif /* _UAPI_LINUX_VIRTIO_RING_H */ -- 2.14.1