History

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio/vhost updates from Michael Tsirkin: "Features, fixes, cleanups: - discard in virtio blk - misc fixes and cleanups" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: correct the related warning message vhost: split structs into a separate header file virtio: remove deprecated VIRTIO_PCI_CONFIG() vhost/vsock: switch to a mutex for vhost_vsock_hash virtio_blk: add discard and write zeroes support

Linus Torvalds committed 7 years ago

Commit d548e652 parents 77d0b19 a691ffb7 files · +279 −125Browse files

Showing the changes to include/uapi/linux (3 of 7 files). Show all

Unified · Split

3 files
  1. include/uapi/linux/vhost.h +2 −111
  2. include/uapi/linux/vhost_types.h +128 −0
  3. include/uapi/linux/virtio_blk.h +54 −0
include/uapi/linux/vhost.h+2−111
@@ -11,94 +11,9 @@ · 10 unmodified lines
1111 * device configuration.
1212 */
1313
14+#include <linux/vhost_types.h>
1415 #include <linux/types.h>
15−#include <linux/compiler.h>
1616 #include <linux/ioctl.h>
17−#include <linux/virtio_config.h>
18−#include <linux/virtio_ring.h>
19−
20−struct vhost_vring_state {
21− unsigned int index;
22− unsigned int num;
23−};
24−
25−struct vhost_vring_file {
26− unsigned int index;
27− int fd; /* Pass -1 to unbind from file. */
28−
29−};
30−
31−struct vhost_vring_addr {
32− unsigned int index;
33− /* Option flags. */
34− unsigned int flags;
35− /* Flag values: */
36− /* Whether log address is valid. If set enables logging. */
37−#define VHOST_VRING_F_LOG 0
38−
39− /* Start of array of descriptors (virtually contiguous) */
40− __u64 desc_user_addr;
41− /* Used structure address. Must be 32 bit aligned */
42− __u64 used_user_addr;
43− /* Available structure address. Must be 16 bit aligned */
44− __u64 avail_user_addr;
45− /* Logging support. */
46− /* Log writes to used structure, at offset calculated from specified
47− * address. Address must be 32 bit aligned. */
48− __u64 log_guest_addr;
49−};
50−
51−/* no alignment requirement */
52−struct vhost_iotlb_msg {
53− __u64 iova;
54− __u64 size;
55− __u64 uaddr;
56−#define VHOST_ACCESS_RO 0x1
57−#define VHOST_ACCESS_WO 0x2
58−#define VHOST_ACCESS_RW 0x3
59− __u8 perm;
60−#define VHOST_IOTLB_MISS 1
61−#define VHOST_IOTLB_UPDATE 2
62−#define VHOST_IOTLB_INVALIDATE 3
63−#define VHOST_IOTLB_ACCESS_FAIL 4
64− __u8 type;
65−};
66−
67−#define VHOST_IOTLB_MSG 0x1
68−#define VHOST_IOTLB_MSG_V2 0x2
69−
70−struct vhost_msg {
71− int type;
72− union {
73− struct vhost_iotlb_msg iotlb;
74− __u8 padding[64];
75− };
76−};
77−
78−struct vhost_msg_v2 {
79− __u32 type;
80− __u32 reserved;
81− union {
82− struct vhost_iotlb_msg iotlb;
83− __u8 padding[64];
84− };
85−};
86−
87−struct vhost_memory_region {
88− __u64 guest_phys_addr;
89− __u64 memory_size; /* bytes */
90− __u64 userspace_addr;
91− __u64 flags_padding; /* No flags are currently specified. */
92−};
93−
94−/* All region addresses and sizes must be 4K aligned. */
95−#define VHOST_PAGE_SIZE 0x1000
96−
97−struct vhost_memory {
98− __u32 nregions;
99− __u32 padding;
100− struct vhost_memory_region regions[0];
101−};
10217
10318 /* ioctls */
10419
@@ -186,31 +101,7 @@ struct vhost_memory { · 81 unmodified lines
186101 * device. This can be used to stop the ring (e.g. for migration). */
187102 #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
188103
189−/* Feature bits */
190−/* Log all write descriptors. Can be changed while device is active. */
191−#define VHOST_F_LOG_ALL 26
192−/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
193−#define VHOST_NET_F_VIRTIO_NET_HDR 27
194−
195−/* VHOST_SCSI specific definitions */
196−
197−/*
198− * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
199− *
200− * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
201− * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
202− * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
203− * All the targets under vhost_wwpn can be seen and used by guset.
204− */
205−
206−#define VHOST_SCSI_ABI_VERSION 1
207−
208−struct vhost_scsi_target {
209− int abi_version;
210− char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
211− unsigned short vhost_tpgt;
212− unsigned short reserved;
213−};
104+/* VHOST_SCSI specific defines */
214105
215106 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
216107 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
include/uapi/linux/vhost_types.h+128−0
@@ -0,0 +1,128 @@
1+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+#ifndef _LINUX_VHOST_TYPES_H
3+#define _LINUX_VHOST_TYPES_H
4+/* Userspace interface for in-kernel virtio accelerators. */
5+
6+/* vhost is used to reduce the number of system calls involved in virtio.
7+ *
8+ * Existing virtio net code is used in the guest without modification.
9+ *
10+ * This header includes interface used by userspace hypervisor for
11+ * device configuration.
12+ */
13+
14+#include <linux/types.h>
15+#include <linux/compiler.h>
16+#include <linux/virtio_config.h>
17+#include <linux/virtio_ring.h>
18+
19+struct vhost_vring_state {
20+ unsigned int index;
21+ unsigned int num;
22+};
23+
24+struct vhost_vring_file {
25+ unsigned int index;
26+ int fd; /* Pass -1 to unbind from file. */
27+
28+};
29+
30+struct vhost_vring_addr {
31+ unsigned int index;
32+ /* Option flags. */
33+ unsigned int flags;
34+ /* Flag values: */
35+ /* Whether log address is valid. If set enables logging. */
36+#define VHOST_VRING_F_LOG 0
37+
38+ /* Start of array of descriptors (virtually contiguous) */
39+ __u64 desc_user_addr;
40+ /* Used structure address. Must be 32 bit aligned */
41+ __u64 used_user_addr;
42+ /* Available structure address. Must be 16 bit aligned */
43+ __u64 avail_user_addr;
44+ /* Logging support. */
45+ /* Log writes to used structure, at offset calculated from specified
46+ * address. Address must be 32 bit aligned. */
47+ __u64 log_guest_addr;
48+};
49+
50+/* no alignment requirement */
51+struct vhost_iotlb_msg {
52+ __u64 iova;
53+ __u64 size;
54+ __u64 uaddr;
55+#define VHOST_ACCESS_RO 0x1
56+#define VHOST_ACCESS_WO 0x2
57+#define VHOST_ACCESS_RW 0x3
58+ __u8 perm;
59+#define VHOST_IOTLB_MISS 1
60+#define VHOST_IOTLB_UPDATE 2
61+#define VHOST_IOTLB_INVALIDATE 3
62+#define VHOST_IOTLB_ACCESS_FAIL 4
63+ __u8 type;
64+};
65+
66+#define VHOST_IOTLB_MSG 0x1
67+#define VHOST_IOTLB_MSG_V2 0x2
68+
69+struct vhost_msg {
70+ int type;
71+ union {
72+ struct vhost_iotlb_msg iotlb;
73+ __u8 padding[64];
74+ };
75+};
76+
77+struct vhost_msg_v2 {
78+ __u32 type;
79+ __u32 reserved;
80+ union {
81+ struct vhost_iotlb_msg iotlb;
82+ __u8 padding[64];
83+ };
84+};
85+
86+struct vhost_memory_region {
87+ __u64 guest_phys_addr;
88+ __u64 memory_size; /* bytes */
89+ __u64 userspace_addr;
90+ __u64 flags_padding; /* No flags are currently specified. */
91+};
92+
93+/* All region addresses and sizes must be 4K aligned. */
94+#define VHOST_PAGE_SIZE 0x1000
95+
96+struct vhost_memory {
97+ __u32 nregions;
98+ __u32 padding;
99+ struct vhost_memory_region regions[0];
100+};
101+
102+/* VHOST_SCSI specific definitions */
103+
104+/*
105+ * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
106+ *
107+ * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
108+ * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
109+ * ABI Rev 1: January 2013. Ignore vhost_tpgt field in struct vhost_scsi_target.
110+ * All the targets under vhost_wwpn can be seen and used by guset.
111+ */
112+
113+#define VHOST_SCSI_ABI_VERSION 1
114+
115+struct vhost_scsi_target {
116+ int abi_version;
117+ char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
118+ unsigned short vhost_tpgt;
119+ unsigned short reserved;
120+};
121+
122+/* Feature bits */
123+/* Log all write descriptors. Can be changed while device is active. */
124+#define VHOST_F_LOG_ALL 26
125+/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
126+#define VHOST_NET_F_VIRTIO_NET_HDR 27
127+
128+#endif
include/uapi/linux/virtio_blk.h+54−0
@@ -38,6 +38,8 @@ · 37 unmodified lines
3838 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
3939 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
4040 #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */
41+#define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */
42+#define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */
4143
4244 /* Legacy feature bits */
4345 #ifndef VIRTIO_BLK_NO_LEGACY
@@ -86,6 +88,39 @@ struct virtio_blk_config { · 42 unmodified lines
8688
8789 /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
8890 __u16 num_queues;
91+
92+ /* the next 3 entries are guarded by VIRTIO_BLK_F_DISCARD */
93+ /*
94+ * The maximum discard sectors (in 512-byte sectors) for
95+ * one segment.
96+ */
97+ __u32 max_discard_sectors;
98+ /*
99+ * The maximum number of discard segments in a
100+ * discard command.
101+ */
102+ __u32 max_discard_seg;
103+ /* Discard commands must be aligned to this number of sectors. */
104+ __u32 discard_sector_alignment;
105+
106+ /* the next 3 entries are guarded by VIRTIO_BLK_F_WRITE_ZEROES */
107+ /*
108+ * The maximum number of write zeroes sectors (in 512-byte sectors) in
109+ * one segment.
110+ */
111+ __u32 max_write_zeroes_sectors;
112+ /*
113+ * The maximum number of segments in a write zeroes
114+ * command.
115+ */
116+ __u32 max_write_zeroes_seg;
117+ /*
118+ * Set if a VIRTIO_BLK_T_WRITE_ZEROES request may result in the
119+ * deallocation of one or more of the sectors.
120+ */
121+ __u8 write_zeroes_may_unmap;
122+
123+ __u8 unused1[3];
89124 } __attribute__((packed));
90125
91126 /*
@@ -114,6 +149,12 @@ struct virtio_blk_config { · 22 unmodified lines
114149 /* Get device ID command */
115150 #define VIRTIO_BLK_T_GET_ID 8
116151
152+/* Discard command */
153+#define VIRTIO_BLK_T_DISCARD 11
154+
155+/* Write zeroes command */
156+#define VIRTIO_BLK_T_WRITE_ZEROES 13
157+
117158 #ifndef VIRTIO_BLK_NO_LEGACY
118159 /* Barrier before this op. */
119160 #define VIRTIO_BLK_T_BARRIER 0x80000000
@@ -133,6 +174,19 @@ struct virtio_blk_outhdr { · 13 unmodified lines
133174 __virtio64 sector;
134175 };
135176
177+/* Unmap this range (only valid for write zeroes command) */
178+#define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001
179+
180+/* Discard/write zeroes range for each request. */
181+struct virtio_blk_discard_write_zeroes {
182+ /* discard/write zeroes start sector */
183+ __le64 sector;
184+ /* number of discard/write zeroes sectors */
185+ __le32 num_sectors;
186+ /* flags for this range */
187+ __le32 flags;
188+};
189+
136190 #ifndef VIRTIO_BLK_NO_LEGACY
137191 struct virtio_scsi_inhdr {
138192 __virtio32 errors;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t