lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <667eed8350f89_2185b294e2@willemb.c.googlers.com.notmuch>
Date: Fri, 28 Jun 2024 13:06:11 -0400
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Pavel Begunkov <asml.silence@...il.com>, 
 io-uring@...r.kernel.org, 
 netdev@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>, 
 asml.silence@...il.com, 
 "David S . Miller" <davem@...emloft.net>, 
 Jakub Kicinski <kuba@...nel.org>, 
 David Ahern <dsahern@...nel.org>, 
 Eric Dumazet <edumazet@...gle.com>, 
 Willem de Bruijn <willemdebruijn.kernel@...il.com>
Subject: Re: [PATCH net-next 3/5] net: batch zerocopy_fill_skb_from_iter
 accounting

Pavel Begunkov wrote:
> Instead of accounting every page range against the socket separately, do
> it in batch based on the change in skb->truesize. It's also moved into
> __zerocopy_sg_from_iter(), so that zerocopy_fill_skb_from_iter() is
> simpler and responsible for setting frags but not the accounting.
> 
> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>

Reviewed-by: Willem de Bruijn <willemb@...gle.com>

> ---
>  net/core/datagram.c | 31 ++++++++++++++++++-------------
>  1 file changed, 18 insertions(+), 13 deletions(-)
> 
> diff --git a/net/core/datagram.c b/net/core/datagram.c
> index 7f7d5da2e406..2b24d69b1e94 100644
> --- a/net/core/datagram.c
> +++ b/net/core/datagram.c
> @@ -610,7 +610,7 @@ int skb_copy_datagram_from_iter(struct sk_buff *skb, int offset,
>  }
>  EXPORT_SYMBOL(skb_copy_datagram_from_iter);
>  
> -static int zerocopy_fill_skb_from_iter(struct sock *sk, struct sk_buff *skb,
> +static int zerocopy_fill_skb_from_iter(struct sk_buff *skb,
>  					struct iov_iter *from, size_t length)
>  {
>  	int frag = skb_shinfo(skb)->nr_frags;
> @@ -621,7 +621,6 @@ static int zerocopy_fill_skb_from_iter(struct sock *sk, struct sk_buff *skb,
>  		int refs, order, n = 0;
>  		size_t start;
>  		ssize_t copied;
> -		unsigned long truesize;
>  
>  		if (frag == MAX_SKB_FRAGS)
>  			return -EMSGSIZE;

Does the existing code then incorrectly not unwind sk_wmem_queued_add
and sk_mem_charge if returning with error from the second or later
loop..

> @@ -633,17 +632,9 @@ static int zerocopy_fill_skb_from_iter(struct sock *sk, struct sk_buff *skb,
>  
>  		length -= copied;
>  
> -		truesize = PAGE_ALIGN(copied + start);
>  		skb->data_len += copied;
>  		skb->len += copied;
> -		skb->truesize += truesize;
> -		if (sk && sk->sk_type == SOCK_STREAM) {
> -			sk_wmem_queued_add(sk, truesize);
> -			if (!skb_zcopy_pure(skb))
> -				sk_mem_charge(sk, truesize);
> -		} else {
> -			refcount_add(truesize, &skb->sk->sk_wmem_alloc);
> -		}
> +		skb->truesize += PAGE_ALIGN(copied + start);
>  
>  		head = compound_head(pages[n]);
>  		order = compound_order(head);
> @@ -691,10 +682,24 @@ int __zerocopy_sg_from_iter(struct msghdr *msg, struct sock *sk,
>  			    struct sk_buff *skb, struct iov_iter *from,
>  			    size_t length)
>  {
> +	unsigned long orig_size = skb->truesize;
> +	unsigned long truesize;
> +	int ret;
> +
>  	if (msg && msg->msg_ubuf && msg->sg_from_iter)
>  		return msg->sg_from_iter(sk, skb, from, length);
> -	else
> -		return zerocopy_fill_skb_from_iter(sk, skb, from, length);
> +
> +	ret = zerocopy_fill_skb_from_iter(skb, from, length);
> +	truesize = skb->truesize - orig_size;
> +
> +	if (sk && sk->sk_type == SOCK_STREAM) {
> +		sk_wmem_queued_add(sk, truesize);
> +		if (!skb_zcopy_pure(skb))
> +			sk_mem_charge(sk, truesize);
> +	} else {
> +		refcount_add(truesize, &skb->sk->sk_wmem_alloc);
> +	}
> +	return ret;
>  }
>  EXPORT_SYMBOL(__zerocopy_sg_from_iter);
>  
> -- 
> 2.44.0
> 



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ