Re: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types.
Hi Luigi, kernel test robot noticed the following build warnings: [auto build test WARNING on 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5] url: https://github.com/intel-lab-lkp/linux/commits/Luigi-Leonardi-via-B4-Relay/vsock-add-support-for-SIOCOUTQ-ioctl-for-all-vsock-socket-types/20240627-023902 base: 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5 patch link: https://lore.kernel.org/r/20240626-ioctl_next-v3-1-63be5bf19a40%40outlook.com patch subject: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types. config: i386-randconfig-141-20240628 (https://download.01.org/0day-ci/archive/20240628/202406282144.dxr5kwiu-...@intel.com/config) compiler: gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202406282144.dxr5kwiu-...@intel.com/ smatch warnings: net/vmw_vsock/af_vsock.c:1321 vsock_do_ioctl() warn: unsigned 'n_bytes' is never less than zero. vim +/n_bytes +1321 net/vmw_vsock/af_vsock.c 1295 1296 static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, 1297int __user *arg) 1298 { 1299 struct sock *sk = sock->sk; 1300 struct vsock_sock *vsk; 1301 int retval; 1302 1303 vsk = vsock_sk(sk); 1304 1305 switch (cmd) { 1306 case SIOCOUTQ: { 1307 size_t n_bytes; 1308 1309 if (!vsk->transport || !vsk->transport->unsent_bytes) { 1310 retval = -EOPNOTSUPP; 1311 break; 1312 } 1313 1314 if (vsk->transport->unsent_bytes) { 1315 if (sock_type_connectible(sk->sk_type) && sk->sk_state == TCP_LISTEN) { 1316 retval = -EINVAL; 1317 break; 1318 } 1319 1320 n_bytes = vsk->transport->unsent_bytes(vsk); > 1321 if (n_bytes < 0) { 1322 retval = n_bytes; 1323 break; 1324 } 1325 1326 retval = put_user(n_bytes, arg); 1327 } 1328 break; 1329 } 1330 default: 1331 retval = -ENOIOCTLCMD; 1332 } 1333 1334 return retval; 1335 } 1336 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types.
nit: in theory in this patch we don't support it for any of the transports, so I wouldn't confuse and take that part out of the title. WDYT with someting like: vsock: add support for SIOCOUTQ ioctl On Wed, Jun 26, 2024 at 02:08:35PM GMT, Luigi Leonardi via B4 Relay wrote: From: Luigi Leonardi Add support for ioctl(s) for SOCK_STREAM SOCK_SEQPACKET and SOCK_DGRAM in AF_VSOCK. The only ioctl available is SIOCOUTQ/TIOCOUTQ, which returns the number of unsent bytes in the socket. This information is transport-specific and is delegated to them using a callback. Suggested-by: Daan De Meyer Signed-off-by: Luigi Leonardi --- include/net/af_vsock.h | 3 +++ net/vmw_vsock/af_vsock.c | 60 +--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 535701efc1e5..7b5375ae7827 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -169,6 +169,9 @@ struct vsock_transport { void (*notify_buffer_size)(struct vsock_sock *, u64 *); int (*notify_set_rcvlowat)(struct vsock_sock *vsk, int val); + /* SIOCOUTQ ioctl */ + size_t (*unsent_bytes)(struct vsock_sock *vsk); If you want to return also errors, maybe better returning ssize_t. This should fix one of the error reported by kernel bots. + /* Shutdown. */ int (*shutdown)(struct vsock_sock *, int); diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 4b040285aa78..d6140d73d122 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -112,6 +112,7 @@ #include #include #include +#include static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr); static void vsock_sk_destruct(struct sock *sk); @@ -1292,6 +1293,59 @@ int vsock_dgram_recvmsg(struct socket *sock, struct msghdr *msg, } EXPORT_SYMBOL_GPL(vsock_dgram_recvmsg); +static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, + int __user *arg) +{ + struct sock *sk = sock->sk; + struct vsock_sock *vsk; + int retval; + + vsk = vsock_sk(sk); + + switch (cmd) { + case SIOCOUTQ: { + size_t n_bytes; + + if (!vsk->transport || !vsk->transport->unsent_bytes) { + retval = -EOPNOTSUPP; + break; + } + + if (vsk->transport->unsent_bytes) { This if is not necessary after the check we did earlier, right? Removing it should fix the other issue reported by the bot. + if (sock_type_connectible(sk->sk_type) && sk->sk_state == TCP_LISTEN) { + retval = -EINVAL; + break; + } + + n_bytes = vsk->transport->unsent_bytes(vsk); + if (n_bytes < 0) { + retval = n_bytes; + break; + } + + retval = put_user(n_bytes, arg); + } + break; + } + default: + retval = -ENOIOCTLCMD; + } + + return retval; +} + +static int vsock_ioctl(struct socket *sock, unsigned int cmd, + unsigned long arg) +{ + int ret; + + lock_sock(sock->sk); + ret = vsock_do_ioctl(sock, cmd, (int __user *)arg); + release_sock(sock->sk); + + return ret; +} + static const struct proto_ops vsock_dgram_ops = { .family = PF_VSOCK, .owner = THIS_MODULE, @@ -1302,7 +1356,7 @@ static const struct proto_ops vsock_dgram_ops = { .accept = sock_no_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = sock_no_listen, .shutdown = vsock_shutdown, .sendmsg = vsock_dgram_sendmsg, @@ -2286,7 +2340,7 @@ static const struct proto_ops vsock_stream_ops = { .accept = vsock_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = vsock_listen, .shutdown = vsock_shutdown, .setsockopt = vsock_connectible_setsockopt, @@ -2308,7 +2362,7 @@ static const struct proto_ops vsock_seqpacket_ops = { .accept = vsock_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = vsock_listen, .shutdown = vsock_shutdown, .setsockopt = vsock_connectible_setsockopt, -- 2.45.2
Re: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types.
Hi Luigi, kernel test robot noticed the following build warnings: [auto build test WARNING on 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5] url: https://github.com/intel-lab-lkp/linux/commits/Luigi-Leonardi-via-B4-Relay/vsock-add-support-for-SIOCOUTQ-ioctl-for-all-vsock-socket-types/20240627-023902 base: 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5 patch link: https://lore.kernel.org/r/20240626-ioctl_next-v3-1-63be5bf19a40%40outlook.com patch subject: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types. config: i386-randconfig-141-20240628 (https://download.01.org/0day-ci/archive/20240628/202406281355.d1jnvgbc-...@intel.com/config) compiler: gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202406281355.d1jnvgbc-...@intel.com/ smatch warnings: net/vmw_vsock/af_vsock.c:1321 vsock_do_ioctl() warn: unsigned 'n_bytes' is never less than zero. vim +/n_bytes +1321 net/vmw_vsock/af_vsock.c 1295 1296 static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, 1297int __user *arg) 1298 { 1299 struct sock *sk = sock->sk; 1300 struct vsock_sock *vsk; 1301 int retval; 1302 1303 vsk = vsock_sk(sk); 1304 1305 switch (cmd) { 1306 case SIOCOUTQ: { 1307 size_t n_bytes; 1308 1309 if (!vsk->transport || !vsk->transport->unsent_bytes) { 1310 retval = -EOPNOTSUPP; 1311 break; 1312 } 1313 1314 if (vsk->transport->unsent_bytes) { 1315 if (sock_type_connectible(sk->sk_type) && sk->sk_state == TCP_LISTEN) { 1316 retval = -EINVAL; 1317 break; 1318 } 1319 1320 n_bytes = vsk->transport->unsent_bytes(vsk); > 1321 if (n_bytes < 0) { 1322 retval = n_bytes; 1323 break; 1324 } 1325 1326 retval = put_user(n_bytes, arg); 1327 } 1328 break; 1329 } 1330 default: 1331 retval = -ENOIOCTLCMD; 1332 } 1333 1334 return retval; 1335 } 1336 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types.
Hi Luigi, kernel test robot noticed the following build warnings: [auto build test WARNING on 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5] url: https://github.com/intel-lab-lkp/linux/commits/Luigi-Leonardi-via-B4-Relay/vsock-add-support-for-SIOCOUTQ-ioctl-for-all-vsock-socket-types/20240627-023902 base: 50b70845fc5c22cf7e7d25b57d57b3dca1725aa5 patch link: https://lore.kernel.org/r/20240626-ioctl_next-v3-1-63be5bf19a40%40outlook.com patch subject: [PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types. config: i386-buildonly-randconfig-001-20240627 (https://download.01.org/0day-ci/archive/20240627/202406271827.aq9zylch-...@intel.com/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240627/202406271827.aq9zylch-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202406271827.aq9zylch-...@intel.com/ All warnings (new ones prefixed by >>): >> net/vmw_vsock/af_vsock.c:1314:7: warning: variable 'retval' is used >> uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] 1314 | if (vsk->transport->unsent_bytes) { | ^~~~ net/vmw_vsock/af_vsock.c:1334:9: note: uninitialized use occurs here 1334 | return retval; |^~ net/vmw_vsock/af_vsock.c:1314:3: note: remove the 'if' if its condition is always true 1314 | if (vsk->transport->unsent_bytes) { | ^ net/vmw_vsock/af_vsock.c:1301:12: note: initialize the variable 'retval' to silence this warning 1301 | int retval; | ^ |= 0 1 warning generated. vim +1314 net/vmw_vsock/af_vsock.c 1295 1296 static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, 1297int __user *arg) 1298 { 1299 struct sock *sk = sock->sk; 1300 struct vsock_sock *vsk; 1301 int retval; 1302 1303 vsk = vsock_sk(sk); 1304 1305 switch (cmd) { 1306 case SIOCOUTQ: { 1307 size_t n_bytes; 1308 1309 if (!vsk->transport || !vsk->transport->unsent_bytes) { 1310 retval = -EOPNOTSUPP; 1311 break; 1312 } 1313 > 1314 if (vsk->transport->unsent_bytes) { 1315 if (sock_type_connectible(sk->sk_type) && sk->sk_state == TCP_LISTEN) { 1316 retval = -EINVAL; 1317 break; 1318 } 1319 1320 n_bytes = vsk->transport->unsent_bytes(vsk); 1321 if (n_bytes < 0) { 1322 retval = n_bytes; 1323 break; 1324 } 1325 1326 retval = put_user(n_bytes, arg); 1327 } 1328 break; 1329 } 1330 default: 1331 retval = -ENOIOCTLCMD; 1332 } 1333 1334 return retval; 1335 } 1336 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
[PATCH net-next v3 1/3] vsock: add support for SIOCOUTQ ioctl for all vsock socket types.
From: Luigi Leonardi Add support for ioctl(s) for SOCK_STREAM SOCK_SEQPACKET and SOCK_DGRAM in AF_VSOCK. The only ioctl available is SIOCOUTQ/TIOCOUTQ, which returns the number of unsent bytes in the socket. This information is transport-specific and is delegated to them using a callback. Suggested-by: Daan De Meyer Signed-off-by: Luigi Leonardi --- include/net/af_vsock.h | 3 +++ net/vmw_vsock/af_vsock.c | 60 +--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 535701efc1e5..7b5375ae7827 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -169,6 +169,9 @@ struct vsock_transport { void (*notify_buffer_size)(struct vsock_sock *, u64 *); int (*notify_set_rcvlowat)(struct vsock_sock *vsk, int val); + /* SIOCOUTQ ioctl */ + size_t (*unsent_bytes)(struct vsock_sock *vsk); + /* Shutdown. */ int (*shutdown)(struct vsock_sock *, int); diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 4b040285aa78..d6140d73d122 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -112,6 +112,7 @@ #include #include #include +#include static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr); static void vsock_sk_destruct(struct sock *sk); @@ -1292,6 +1293,59 @@ int vsock_dgram_recvmsg(struct socket *sock, struct msghdr *msg, } EXPORT_SYMBOL_GPL(vsock_dgram_recvmsg); +static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, + int __user *arg) +{ + struct sock *sk = sock->sk; + struct vsock_sock *vsk; + int retval; + + vsk = vsock_sk(sk); + + switch (cmd) { + case SIOCOUTQ: { + size_t n_bytes; + + if (!vsk->transport || !vsk->transport->unsent_bytes) { + retval = -EOPNOTSUPP; + break; + } + + if (vsk->transport->unsent_bytes) { + if (sock_type_connectible(sk->sk_type) && sk->sk_state == TCP_LISTEN) { + retval = -EINVAL; + break; + } + + n_bytes = vsk->transport->unsent_bytes(vsk); + if (n_bytes < 0) { + retval = n_bytes; + break; + } + + retval = put_user(n_bytes, arg); + } + break; + } + default: + retval = -ENOIOCTLCMD; + } + + return retval; +} + +static int vsock_ioctl(struct socket *sock, unsigned int cmd, + unsigned long arg) +{ + int ret; + + lock_sock(sock->sk); + ret = vsock_do_ioctl(sock, cmd, (int __user *)arg); + release_sock(sock->sk); + + return ret; +} + static const struct proto_ops vsock_dgram_ops = { .family = PF_VSOCK, .owner = THIS_MODULE, @@ -1302,7 +1356,7 @@ static const struct proto_ops vsock_dgram_ops = { .accept = sock_no_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = sock_no_listen, .shutdown = vsock_shutdown, .sendmsg = vsock_dgram_sendmsg, @@ -2286,7 +2340,7 @@ static const struct proto_ops vsock_stream_ops = { .accept = vsock_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = vsock_listen, .shutdown = vsock_shutdown, .setsockopt = vsock_connectible_setsockopt, @@ -2308,7 +2362,7 @@ static const struct proto_ops vsock_seqpacket_ops = { .accept = vsock_accept, .getname = vsock_getname, .poll = vsock_poll, - .ioctl = sock_no_ioctl, + .ioctl = vsock_ioctl, .listen = vsock_listen, .shutdown = vsock_shutdown, .setsockopt = vsock_connectible_setsockopt, -- 2.45.2