diff mbox series

[net-next,03/15] l2tp: have l2tp_ip_destroy_sock use ip_flush_pending_frames

Message ID 8491d89e8ae68206971f35c572190ac8b7882c1d.1722265212.git.jchapman@katalix.com (mailing list archive)
State Accepted
Commit ed8ebee6def7b7b760bd4fd90c03b9e86622701c
Delegated to: Netdev Maintainers
Headers show
Series l2tp: simplify tunnel and session cleanup | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 42 this patch: 42
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 43 this patch: 43
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 43 this patch: 43
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-29--18-00 (tests: 703)

Commit Message

James Chapman July 29, 2024, 3:38 p.m. UTC
Use the recently exported ip_flush_pending_frames instead of a
free-coded version and lock the socket while we call it.

Signed-off-by: James Chapman <jchapman@katalix.com>
Signed-off-by: Tom Parkin <tparkin@katalix.com>
---
 net/l2tp/l2tp_ip.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Cong Wang Aug. 11, 2024, 10:40 p.m. UTC | #1
On Mon, Jul 29, 2024 at 04:38:02PM +0100, James Chapman wrote:
> Use the recently exported ip_flush_pending_frames instead of a
> free-coded version and lock the socket while we call it.

Hmm? Isn't skb_queue_purge() closer to the original code?

This is clearly not a trivial cleanup, so what are you trying to fix?

> 
> Signed-off-by: James Chapman <jchapman@katalix.com>
> Signed-off-by: Tom Parkin <tparkin@katalix.com>
> ---
>  net/l2tp/l2tp_ip.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
> index 78243f993cda..f21dcbf3efd5 100644
> --- a/net/l2tp/l2tp_ip.c
> +++ b/net/l2tp/l2tp_ip.c
> @@ -236,10 +236,10 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
>  static void l2tp_ip_destroy_sock(struct sock *sk)
>  {
>  	struct l2tp_tunnel *tunnel;
> -	struct sk_buff *skb;
>  
> -	while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
> -		kfree_skb(skb);
> +	lock_sock(sk);


Are you sure you really want this sock lock?

> +	ip_flush_pending_frames(sk);

So who sets inet_sk(sk)->cork.base for l2tp socket?

Thanks.
James Chapman Aug. 12, 2024, 3:28 p.m. UTC | #2
On 11/08/2024 23:40, Cong Wang wrote:
> On Mon, Jul 29, 2024 at 04:38:02PM +0100, James Chapman wrote:
>> Use the recently exported ip_flush_pending_frames instead of a
>> free-coded version and lock the socket while we call it.
> 
> Hmm? Isn't skb_queue_purge() closer to the original code?

It is, but I thought l2tp_ip should also be calling ip_cork_release, 
even if it doesn't use cork. Having looked again, prompted by your 
comments below, I realise I made a mistake.

> This is clearly not a trivial cleanup, so what are you trying to fix?

This commit wasn't to fix a specific problem. I'm trying to make l2tp 
easier to maintain tbh.

>> Signed-off-by: James Chapman <jchapman@katalix.com>
>> Signed-off-by: Tom Parkin <tparkin@katalix.com>
>> ---
>>   net/l2tp/l2tp_ip.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
>> index 78243f993cda..f21dcbf3efd5 100644
>> --- a/net/l2tp/l2tp_ip.c
>> +++ b/net/l2tp/l2tp_ip.c
>> @@ -236,10 +236,10 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
>>   static void l2tp_ip_destroy_sock(struct sock *sk)
>>   {
>>   	struct l2tp_tunnel *tunnel;
>> -	struct sk_buff *skb;
>>   
>> -	while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
>> -		kfree_skb(skb);
>> +	lock_sock(sk);
> 
> 
> Are you sure you really want this sock lock?

Hmm, you're right, it is unnecessary. I note l2tp_ip6 has similar 
unnecessary lock.

>> +	ip_flush_pending_frames(sk);
> 
> So who sets inet_sk(sk)->cork.base for l2tp socket?

I missed this. Thanks for catching it.

Since this series has already been applied to net-next, I'll work on a 
patch to address the issues raised.
diff mbox series

Patch

diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 78243f993cda..f21dcbf3efd5 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -236,10 +236,10 @@  static void l2tp_ip_close(struct sock *sk, long timeout)
 static void l2tp_ip_destroy_sock(struct sock *sk)
 {
 	struct l2tp_tunnel *tunnel;
-	struct sk_buff *skb;
 
-	while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
-		kfree_skb(skb);
+	lock_sock(sk);
+	ip_flush_pending_frames(sk);
+	release_sock(sk);
 
 	tunnel = l2tp_sk_to_tunnel(sk);
 	if (tunnel) {