[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241019002232.43313-1-kuniyu@amazon.com>
Date: Fri, 18 Oct 2024 17:22:32 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <denkenz@...il.com>
CC: <agross@...nel.org>, <almasrymina@...gle.com>, <asml.silence@...il.com>,
<axboe@...nel.dk>, <davem@...emloft.net>, <edumazet@...gle.com>,
<krisman@...e.de>, <kuba@...nel.org>, <kuniyu@...zon.com>,
<linux-arm-msm@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<manivannan.sadhasivam@...aro.org>, <marcel@...tmann.org>,
<netdev@...r.kernel.org>, <pabeni@...hat.com>
Subject: Re: [RFC PATCH v1 04/10] net: qrtr: Report sender endpoint in aux data
From: Denis Kenzior <denkenz@...il.com>
Date: Fri, 18 Oct 2024 13:18:22 -0500
> @@ -1234,6 +1247,78 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
> return rc;
> }
>
> +static int qrtr_setsockopt(struct socket *sock, int level, int optname,
> + sockptr_t optval, unsigned int optlen)
> +{
> + struct qrtr_sock *ipc = qrtr_sk(sock->sk);
> + struct sock *sk = sock->sk;
> + unsigned int val = 0;
> + int rc = 0;
> +
> + if (level != SOL_QRTR)
> + return -ENOPROTOOPT;
> +
> + if (optlen >= sizeof(val) &&
> + copy_from_sockptr(&val, optval, sizeof(val)))
> + return -EFAULT;
> +
> + lock_sock(sk);
This seems unnecessary to me.
sk_setsockopt(), do_ip_setsockopt(), and do_ipv6_setsockopt() do not
hold lock_sock() for assign_bit().
Also, QRTR_BIND_ENDPOINT in a later patch will not need lock_sock()
neither. The value is u32, so you can use WRITE_ONCE() here and
READ_ONCE() in getsockopt().
> +
> + switch (optname) {
> + case QRTR_REPORT_ENDPOINT:
> + assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
> + break;
> + default:
> + rc = -ENOPROTOOPT;
> + }
> +
> + release_sock(sk);
> +
> + return rc;
> +}
> +
> +static int qrtr_getsockopt(struct socket *sock, int level, int optname,
> + char __user *optval, int __user *optlen)
> +{
> + struct qrtr_sock *ipc = qrtr_sk(sock->sk);
> + struct sock *sk = sock->sk;
> + unsigned int val;
> + int len;
> + int rc = 0;
> +
> + if (level != SOL_QRTR)
> + return -ENOPROTOOPT;
> +
> + if (get_user(len, optlen))
> + return -EFAULT;
> +
> + if (len < sizeof(val))
> + return -EINVAL;
> +
> + lock_sock(sk);
Same remark.
> +
> + switch (optname) {
> + case QRTR_REPORT_ENDPOINT:
> + val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
> + break;
> + default:
> + rc = -ENOPROTOOPT;
> + }
> +
> + release_sock(sk);
> +
> + if (rc)
> + return rc;
> +
> + len = sizeof(int);
> +
> + if (put_user(len, optlen) ||
> + copy_to_user(optval, &val, len))
> + rc = -EFAULT;
> +
> + return rc;
> +}
> +
> static int qrtr_release(struct socket *sock)
> {
> struct sock *sk = sock->sk;
Powered by blists - more mailing lists