github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/linux/socket_vnet.txt (about)

     1  # Copyright 2018 syzkaller project authors. All rights reserved.
     2  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  # AF_VSOCK support.
     5  
     6  include <linux/net.h>
     7  include <linux/socket.h>
     8  include <linux/virtio_vsock.h>
     9  include <uapi/linux/fcntl.h>
    10  include <uapi/linux/vhost.h>
    11  include <uapi/linux/vm_sockets.h>
    12  include <uapi/linux/virtio_net.h>
    13  include <uapi/linux/virtio_config.h>
    14  
    15  resource sock_vsock[sock]
    16  resource sock_vsock_stream[sock_vsock]
    17  resource sock_vsock_dgram[sock_vsock]
    18  
    19  resource fd_vhost[fd]
    20  resource vhost_vsock[fd_vhost]
    21  resource vhost_net[fd_vhost]
    22  
    23  socket$vsock_stream(domain const[AF_VSOCK], type const[SOCK_STREAM], proto const[0]) sock_vsock_stream
    24  bind$vsock_stream(fd sock_vsock_stream, addr ptr[in, sockaddr_vm], addrlen len[addr])
    25  connect$vsock_stream(fd sock_vsock_stream, addr ptr[in, sockaddr_vm], addrlen len[addr])
    26  accept4$vsock_stream(fd sock_vsock_stream, addr ptr[in, sockaddr_vm], addrlen len[addr], flags flags[accept_flags]) sock_vsock_stream
    27  setsockopt$SO_VM_SOCKETS_BUFFER_SIZE(fd sock_vsock_stream, level const[AF_VSOCK], opt const[SO_VM_SOCKETS_BUFFER_SIZE], val ptr[in, int64], len len[val])
    28  setsockopt$SO_VM_SOCKETS_BUFFER_MAX_SIZE(fd sock_vsock_stream, level const[AF_VSOCK], opt const[SO_VM_SOCKETS_BUFFER_MAX_SIZE], val ptr[in, int64], len len[val])
    29  setsockopt$SO_VM_SOCKETS_BUFFER_MIN_SIZE(fd sock_vsock_stream, level const[AF_VSOCK], opt const[SO_VM_SOCKETS_BUFFER_MIN_SIZE], val ptr[in, int64], len len[val])
    30  setsockopt$SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD(fd sock_vsock_stream, level const[AF_VSOCK], opt const[SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD], val ptr[in, timeval], len len[val])
    31  
    32  socket$vsock_dgram(domain const[AF_VSOCK], type const[SOCK_DGRAM], proto const[0]) sock_vsock_dgram
    33  bind$vsock_dgram(fd sock_vsock_dgram, addr ptr[in, sockaddr_vm], addrlen len[addr])
    34  connect$vsock_dgram(fd sock_vsock_dgram, addr ptr[in, sockaddr_vm], addrlen len[addr])
    35  
    36  openat$vsock(fd const[AT_FDCWD], file ptr[in, string["/dev/vsock"]], flags flags[open_flags], mode const[0]) fd
    37  
    38  openat$vhost_vsock(fd const[AT_FDCWD], file ptr[in, string["/dev/vhost-vsock"]], flags const[O_RDWR], mode const[0]) vhost_vsock
    39  ioctl$VHOST_VSOCK_SET_GUEST_CID(fd vhost_vsock, cmd const[VHOST_VSOCK_SET_GUEST_CID], arg ptr[in, vmaddr_cid64])
    40  ioctl$VHOST_VSOCK_SET_RUNNING(fd vhost_vsock, cmd const[VHOST_VSOCK_SET_RUNNING], arg ptr[in, bool32])
    41  
    42  openat$vnet(fd const[AT_FDCWD], file ptr[in, string["/dev/vhost-net"]], flags const[O_RDWR], mode const[0]) vhost_net
    43  write$vhost_msg(fd vhost_net, buf ptr[in, vhost_msg], size len[buf])
    44  write$vhost_msg_v2(fd vhost_net, buf ptr[in, vhost_msg_v2], size len[buf])
    45  ioctl$VHOST_NET_SET_BACKEND(fd vhost_net, cmd const[VHOST_NET_SET_BACKEND], arg ptr[in, vhost_vring_file])
    46  
    47  ioctl$VHOST_GET_FEATURES(fd fd_vhost, cmd const[VHOST_GET_FEATURES], arg ptr[out, int64])
    48  ioctl$VHOST_SET_FEATURES(fd fd_vhost, cmd const[VHOST_SET_FEATURES], arg ptr[in, flags[vhost_features, int64]])
    49  ioctl$VHOST_SET_OWNER(fd fd_vhost, cmd const[VHOST_SET_OWNER], arg const[0])
    50  ioctl$VHOST_RESET_OWNER(fd fd_vhost, cmd const[VHOST_RESET_OWNER], arg const[0])
    51  ioctl$VHOST_SET_MEM_TABLE(fd fd_vhost, cmd const[VHOST_SET_MEM_TABLE], arg ptr[in, vhost_memory])
    52  ioctl$VHOST_SET_LOG_BASE(fd fd_vhost, cmd const[VHOST_SET_LOG_BASE], arg ptr[in, ptr64[out, int8]])
    53  ioctl$VHOST_SET_LOG_FD(fd fd_vhost, cmd const[VHOST_SET_LOG_FD], arg ptr[in, fd_event[opt]])
    54  ioctl$VHOST_SET_VRING_NUM(fd fd_vhost, cmd const[VHOST_SET_VRING_NUM], arg ptr[in, vhost_vring_state])
    55  ioctl$VHOST_SET_VRING_BASE(fd fd_vhost, cmd const[VHOST_SET_VRING_BASE], arg ptr[in, vhost_vring_state])
    56  ioctl$VHOST_GET_VRING_BASE(fd fd_vhost, cmd const[VHOST_GET_VRING_BASE], arg ptr[out, vhost_vring_state])
    57  ioctl$VHOST_SET_VRING_ADDR(fd fd_vhost, cmd const[VHOST_SET_VRING_ADDR], arg ptr[in, vhost_vring_addr])
    58  ioctl$VHOST_SET_VRING_KICK(fd fd_vhost, cmd const[VHOST_SET_VRING_KICK], arg ptr[in, vhost_vring_file])
    59  ioctl$VHOST_SET_VRING_CALL(fd fd_vhost, cmd const[VHOST_SET_VRING_CALL], arg ptr[in, vhost_vring_file])
    60  ioctl$VHOST_SET_VRING_ERR(fd fd_vhost, cmd const[VHOST_SET_VRING_ERR], arg ptr[in, vhost_vring_file])
    61  ioctl$VHOST_SET_VRING_ENDIAN(fd fd_vhost, cmd const[VHOST_SET_VRING_ENDIAN], arg ptr[in, vhost_vring_state])
    62  ioctl$VHOST_GET_VRING_ENDIAN(fd fd_vhost, cmd const[VHOST_GET_VRING_ENDIAN], arg ptr[in, vhost_vring_state])
    63  ioctl$VHOST_SET_VRING_BUSYLOOP_TIMEOUT(fd fd_vhost, cmd const[VHOST_SET_VRING_BUSYLOOP_TIMEOUT], arg ptr[in, vhost_vring_state])
    64  
    65  ioctl$VHOST_VDPA_GET_DEVICE_ID(fd fd_vhost, cmd const[VHOST_VDPA_GET_DEVICE_ID], arg ptr[out, int32])
    66  ioctl$VHOST_VDPA_GET_STATUS(fd fd_vhost, cmd const[VHOST_VDPA_GET_STATUS], arg ptr[out, int8])
    67  ioctl$VHOST_VDPA_SET_STATUS(fd fd_vhost, cmd const[VHOST_VDPA_SET_STATUS], arg ptr[in, int8])
    68  ioctl$VHOST_VDPA_GET_CONFIG(fd fd_vhost, cmd const[VHOST_VDPA_GET_CONFIG], arg ptr[out, vhost_vdpa_config])
    69  ioctl$VHOST_VDPA_SET_CONFIG(fd fd_vhost, cmd const[VHOST_VDPA_SET_CONFIG], arg ptr[in, vhost_vdpa_config])
    70  ioctl$VHOST_VDPA_SET_VRING_ENABLE(fd fd_vhost, cmd const[VHOST_VDPA_SET_VRING_ENABLE], arg ptr[in, vhost_vring_state])
    71  ioctl$VHOST_VDPA_GET_VRING_NUM(fd fd_vhost, cmd const[VHOST_VDPA_GET_VRING_NUM], arg ptr[out, int16])
    72  ioctl$VHOST_VDPA_SET_CONFIG_CALL(fd fd_vhost, cmd const[VHOST_VDPA_SET_CONFIG_CALL], arg ptr[in, int32])
    73  ioctl$VHOST_VDPA_GET_IOVA_RANGE(fd fd_vhost, cmd const[VHOST_VDPA_GET_IOVA_RANGE], arg ptr[out, vhost_vdpa_iova_range])
    74  ioctl$VHOST_VDPA_GET_CONFIG_SIZE(fd fd_vhost, cmd const[VHOST_VDPA_GET_CONFIG_SIZE], arg ptr[out, int32])
    75  ioctl$VHOST_VDPA_GET_VQS_COUNT(fd fd_vhost, cmd const[VHOST_VDPA_GET_VQS_COUNT], arg ptr[out, int32])
    76  ioctl$VHOST_VDPA_GET_GROUP_NUM(fd fd_vhost, cmd const[VHOST_VDPA_GET_GROUP_NUM], arg ptr[out, int32])
    77  ioctl$VHOST_VDPA_GET_AS_NUM(fd fd_vhost, cmd const[VHOST_VDPA_GET_AS_NUM], arg ptr[out, int32])
    78  ioctl$VHOST_VDPA_GET_VRING_GROUP(fd fd_vhost, cmd const[VHOST_VDPA_GET_VRING_GROUP], arg ptr[inout, vhost_vring_state])
    79  ioctl$VHOST_VDPA_SET_GROUP_ASID(fd fd_vhost, cmd const[VHOST_VDPA_SET_GROUP_ASID], arg ptr[in, vhost_vring_state])
    80  
    81  sockaddr_vm {
    82  	svm_family	const[AF_VSOCK, int16]
    83  	svm_reserved1	const[0, int16]
    84  	svm_port	flags[vmaddr_port, int32]
    85  	svm_cid		vmaddr_cid
    86  	svm_zero	const[0, int32]
    87  }
    88  
    89  vmaddr_cid [
    90  	any	const[VMADDR_CID_ANY, int32]
    91  	hyper	const[VMADDR_CID_HYPERVISOR, int32]
    92  	local	const[VMADDR_CID_LOCAL, int32]
    93  	host	const[VMADDR_CID_HOST, int32]
    94  	my	proc[1234, 2, int32]
    95  ]
    96  
    97  vmaddr_cid64 {
    98  	cid	vmaddr_cid
    99  	pad	const[0, int32]
   100  } [align[8]]
   101  
   102  vhost_memory {
   103  	nregions	len[regions, int32]
   104  	padding		const[0, int32]
   105  	regions		array[vhost_memory_region]
   106  }
   107  
   108  vhost_memory_region {
   109  	guest_phys_addr	flags[kvm_guest_addrs, int64]
   110  	memory_size	bytesize[userspace_addr, int64]
   111  	userspace_addr	ptr64[out, array[int8]]
   112  	flags_padding	const[0, int64]
   113  }
   114  
   115  vhost_vring_state {
   116  	index	flags[vhost_vring_index, int32]
   117  	num	int32
   118  }
   119  
   120  vhost_vring_addr {
   121  	index		flags[vhost_vring_index, int32]
   122  	flags		int32[0:1]
   123  	desc_user_addr	ptr64[out, array[int8]]
   124  	used_user_addr	ptr64[out, array[int8]]
   125  	avail_user_addr	ptr64[out, array[int8]]
   126  	log_guest_addr	flags[kvm_guest_addrs, int64]
   127  }
   128  
   129  vhost_vring_file {
   130  	index	flags[vhost_vring_index, int32]
   131  	fd	fd_event[opt]
   132  }
   133  
   134  vhost_msg {
   135  	type	const[VHOST_IOTLB_MSG, int32]
   136  	iotlb	vhost_iotlb_msg
   137  } [size[VHOST_MSG_SIZE]]
   138  
   139  define VHOST_MSG_SIZE	sizeof(struct vhost_msg)
   140  
   141  vhost_msg_v2 {
   142  	type		const[VHOST_IOTLB_MSG_V2, int32]
   143  	reserved	const[0, int32]
   144  	iotlb		vhost_iotlb_msg
   145  } [size[VHOST_MSG_V2_SIZE]]
   146  
   147  vhost_vdpa_config {
   148  	off	int32
   149  	len	len[buf, int32]
   150  	buf	array[int8]
   151  }
   152  
   153  vhost_vdpa_iova_range {
   154  	first	int64
   155  	last	int64
   156  }
   157  
   158  define VHOST_MSG_V2_SIZE	sizeof(struct vhost_msg_v2)
   159  
   160  vhost_iotlb_msg {
   161  # TODO: is it host or guest address?
   162  	iova	ptr64[out, array[int8]]
   163  	size	len[iova, int64]
   164  	uaddr	ptr64[out, array[int8]]
   165  	perm	flags[vhost_iotlb_perm, int8]
   166  	type	flags[vhost_iotlb_type, int8]
   167  }
   168  
   169  vmaddr_port = VMADDR_PORT_ANY, 0, 10000, 10001
   170  vhost_features = VHOST_LOG_ALL, VIRTIO_NOTIFY_ON_EMPTY, VIRTIO_RING_F_INDIRECT_DESC, VIRTIO_RING_F_EVENT_IDX, VIRTIO_ANY_LAYOUT, VIRTIO_VERSION_1, VHOST_NET_VIRTIO_NET_HDR, VIRTIO_NET_MRG_RXBUF, VIRTIO_IOMMU_PLATFORM
   171  vhost_vring_index = VSOCK_VQ_RX, VSOCK_VQ_TX, VSOCK_VQ_EVENT, VSOCK_VQ_MAX
   172  vhost_iotlb_type = VHOST_IOTLB_MISS, VHOST_IOTLB_UPDATE, VHOST_IOTLB_INVALIDATE, VHOST_IOTLB_ACCESS_FAIL
   173  vhost_iotlb_perm = VHOST_ACCESS_RO, VHOST_ACCESS_WO, VHOST_ACCESS_RW
   174  kvm_guest_addrs = 0, 1, 2, 4, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0xd000, 0xf000, 0x100000, 0x10000
   175  
   176  define VHOST_LOG_ALL	1 << VHOST_F_LOG_ALL
   177  define VIRTIO_NOTIFY_ON_EMPTY	1 << VIRTIO_F_NOTIFY_ON_EMPTY
   178  define VIRTIO_RING_F_INDIRECT_DESC	1 << VIRTIO_RING_F_INDIRECT_DESC
   179  define VIRTIO_RING_F_EVENT_IDX	1 << VIRTIO_RING_F_EVENT_IDX
   180  define VIRTIO_ANY_LAYOUT	1 << VIRTIO_F_ANY_LAYOUT
   181  define VIRTIO_VERSION_1	1 << VIRTIO_F_VERSION_1
   182  define VHOST_NET_VIRTIO_NET_HDR	1 << VHOST_NET_F_VIRTIO_NET_HDR
   183  define VIRTIO_NET_MRG_RXBUF	1 << VIRTIO_NET_F_MRG_RXBUF
   184  define VIRTIO_IOMMU_PLATFORM	1 << VIRTIO_F_ACCESS_PLATFORM