diff mbox series

[v3,net,2/2] af_unix: Support POLLPRI for OOB.

Message ID 20220315183855.15190-3-kuniyu@amazon.co.jp (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series af_unix: Fix some OOB implementation. | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 3 maintainers not CCed: linux-kselftest@vger.kernel.org shuah@kernel.org viro@zeniv.linux.org.uk
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 47 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Iwashima, Kuniyuki March 15, 2022, 6:38 p.m. UTC
The commit 314001f0bf92 ("af_unix: Add OOB support") introduced OOB for
AF_UNIX, but it lacks some changes for POLLPRI.  Let's add the missing
piece.

In the selftest, normal datagrams are sent followed by OOB data, so this
commit replaces `POLLIN | POLLPRI` with just `POLLPRI` in the first test
case.

Fixes: 314001f0bf92 ("af_unix: Add OOB support")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
---
v2: https://lore.kernel.org/netdev/20220315054801.72035-1-kuniyu@amazon.co.jp/
  - Add READ_ONCE() to avoid a race reported by KCSAN (Eric)
  - Add IS_ENABLED(CONFIG_AF_UNIX_OOB) (Shoaib)

v1: https://lore.kernel.org/netdev/20220314052110.53634-1-kuniyu@amazon.co.jp/
---
net/unix/af_unix.c                                  | 10 +++++++---
 tools/testing/selftests/net/af_unix/test_unix_oob.c |  6 +++---
 2 files changed, 10 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski March 17, 2022, 2:46 a.m. UTC | #1
On Wed, 16 Mar 2022 03:38:55 +0900 Kuniyuki Iwashima wrote:
> The commit 314001f0bf92 ("af_unix: Add OOB support") introduced OOB for
> AF_UNIX, but it lacks some changes for POLLPRI.  Let's add the missing
> piece.
> 
> In the selftest, normal datagrams are sent followed by OOB data, so this
> commit replaces `POLLIN | POLLPRI` with just `POLLPRI` in the first test
> case.
> 
> Fixes: 314001f0bf92 ("af_unix: Add OOB support")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>

> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 0c37e5595aae..f94afaa5a696 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -2049,7 +2049,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
>   */
>  #define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768))
>  
> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>  static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other)
>  {
>  	struct unix_sock *ousk = unix_sk(other);
> @@ -2115,7 +2115,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
>  
>  	err = -EOPNOTSUPP;
>  	if (msg->msg_flags & MSG_OOB) {
> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>  		if (len)
>  			len--;
>  		else
> @@ -2186,7 +2186,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
>  		sent += size;
>  	}
>  
> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>  	if (msg->msg_flags & MSG_OOB) {
>  		err = queue_oob(sock, msg, other);
>  		if (err)

If we want to keep this change structured as a fix and backported we
should avoid making unnecessary changes. Fixes need to be minimal
as per stable rules. 

Could you make removal of the brackets a patch separate from this
series and targeted at net-next?
Iwashima, Kuniyuki March 17, 2022, 2:56 a.m. UTC | #2
From:   Jakub Kicinski <kuba@kernel.org>
Date:   Wed, 16 Mar 2022 19:46:14 -0700
> On Wed, 16 Mar 2022 03:38:55 +0900 Kuniyuki Iwashima wrote:
>> The commit 314001f0bf92 ("af_unix: Add OOB support") introduced OOB for
>> AF_UNIX, but it lacks some changes for POLLPRI.  Let's add the missing
>> piece.
>> 
>> In the selftest, normal datagrams are sent followed by OOB data, so this
>> commit replaces `POLLIN | POLLPRI` with just `POLLPRI` in the first test
>> case.
>> 
>> Fixes: 314001f0bf92 ("af_unix: Add OOB support")
>> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
> 
>> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
>> index 0c37e5595aae..f94afaa5a696 100644
>> --- a/net/unix/af_unix.c
>> +++ b/net/unix/af_unix.c
>> @@ -2049,7 +2049,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
>>   */
>>  #define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768))
>>  
>> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
>> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>>  static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other)
>>  {
>>  	struct unix_sock *ousk = unix_sk(other);
>> @@ -2115,7 +2115,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
>>  
>>  	err = -EOPNOTSUPP;
>>  	if (msg->msg_flags & MSG_OOB) {
>> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
>> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>>  		if (len)
>>  			len--;
>>  		else
>> @@ -2186,7 +2186,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
>>  		sent += size;
>>  	}
>>  
>> -#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
>> +#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
>>  	if (msg->msg_flags & MSG_OOB) {
>>  		err = queue_oob(sock, msg, other);
>>  		if (err)
> 
> If we want to keep this change structured as a fix and backported we
> should avoid making unnecessary changes. Fixes need to be minimal
> as per stable rules.

Exactly, I should have taken care of that more.
I'll will keep this in mind.
Sorry for bothering and thank you!


> 
> Could you make removal of the brackets a patch separate from this
> series and targeted at net-next?

Sure, I will submit v4 and separate one soon.
diff mbox series

Patch

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 0c37e5595aae..f94afaa5a696 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2049,7 +2049,7 @@  static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
  */
 #define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768))
 
-#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
 static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other)
 {
 	struct unix_sock *ousk = unix_sk(other);
@@ -2115,7 +2115,7 @@  static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
 
 	err = -EOPNOTSUPP;
 	if (msg->msg_flags & MSG_OOB) {
-#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
 		if (len)
 			len--;
 		else
@@ -2186,7 +2186,7 @@  static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
 		sent += size;
 	}
 
-#if (IS_ENABLED(CONFIG_AF_UNIX_OOB))
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
 	if (msg->msg_flags & MSG_OOB) {
 		err = queue_oob(sock, msg, other);
 		if (err)
@@ -3137,6 +3137,10 @@  static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
 		mask |= EPOLLIN | EPOLLRDNORM;
 	if (sk_is_readable(sk))
 		mask |= EPOLLIN | EPOLLRDNORM;
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
+	if (READ_ONCE(unix_sk(sk)->oob_skb))
+		mask |= EPOLLPRI;
+#endif
 
 	/* Connection-based need to check for termination and startup */
 	if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
diff --git a/tools/testing/selftests/net/af_unix/test_unix_oob.c b/tools/testing/selftests/net/af_unix/test_unix_oob.c
index 3dece8b29253..b57e91e1c3f2 100644
--- a/tools/testing/selftests/net/af_unix/test_unix_oob.c
+++ b/tools/testing/selftests/net/af_unix/test_unix_oob.c
@@ -218,10 +218,10 @@  main(int argc, char **argv)
 
 	/* Test 1:
 	 * veriyf that SIGURG is
-	 * delivered and 63 bytes are
-	 * read and oob is '@'
+	 * delivered, 63 bytes are
+	 * read, oob is '@', and POLLPRI works.
 	 */
-	wait_for_data(pfd, POLLIN | POLLPRI);
+	wait_for_data(pfd, POLLPRI);
 	read_oob(pfd, &oob);
 	len = read_data(pfd, buf, 1024);
 	if (!signal_recvd || len != 63 || oob != '@') {