public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jürgen Groß" <jgross@suse.com>
To: Alexey <sdl@nppct.ru>, Jakub Kicinski <kuba@kernel.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	xen-devel@lists.xenproject.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	lvc-project@linuxtesting.org, stable@vger.kernel.org
Subject: Re: [PATCH] xen-netfront: handle NULL returned by xdp_convert_buff_to_frame()
Date: Thu, 17 Apr 2025 12:23:56 +0200	[thread overview]
Message-ID: <4679ca25-572b-44aa-bc00-cb9dc1c0080c@suse.com> (raw)
In-Reply-To: <8264519a-d58a-486e-b3c5-dba400658513@nppct.ru>


[-- Attachment #1.1.1: Type: text/plain, Size: 2865 bytes --]

On 17.04.25 12:06, Alexey wrote:
> 
> On 17.04.2025 11:51, Juergen Gross wrote:
>> On 17.04.25 10:45, Alexey wrote:
>>>
>>> On 17.04.2025 10:12, Jürgen Groß wrote:
>>>> On 17.04.25 09:00, Alexey wrote:
>>>>>
>>>>> On 17.04.2025 03:58, Jakub Kicinski wrote:
>>>>>> On Mon, 14 Apr 2025 18:34:01 +0000 Alexey Nepomnyashih wrote:
>>>>>>>           get_page(pdata);
>>>>>> Please notice this get_page() here.
>>>>>>
>>>>>>>           xdpf = xdp_convert_buff_to_frame(xdp);
>>>>>>> +        if (unlikely(!xdpf)) {
>>>>>>> + trace_xdp_exception(queue->info->netdev, prog, act);
>>>>>>> +            break;
>>>>>>> +        }
>>>>> Do you mean that it would be better to move the get_page(pdata) call lower,
>>>>> after checking for NULL in xdpf, so that the reference count is only increased
>>>>> after a successful conversion?
>>>>
>>>> I think the error handling here is generally broken (or at least very
>>>> questionable).
>>>>
>>>> I suspect that in case of at least some errors the get_page() is leaking
>>>> even without this new patch.
>>>>
>>>> In case I'm wrong a comment reasoning why there is no leak should be
>>>> added.
>>>>
>>>>
>>>> Juergen
>>>
>>> I think pdata is freed in xdp_return_frame_rx_napi() -> __xdp_return()
>>
>> Agreed. But what if xennet_xdp_xmit() returns an error < 0?
>>
>> In this case xdp_return_frame_rx_napi() won't be called.
>>
>>
>> Juergen
> 
> Agreed. There is no explicit freed pdata in the calling function
> xennet_get_responses(). Without this, the page referenced by pdata
> could be leaked.
> 
> I suggest:
 >
 >  	case XDP_TX:
 > -		get_page(pdata);
 >  		xdpf = xdp_convert_buff_to_frame(xdp);
 > +		if (unlikely(!xdpf)) {
 > +			trace_xdp_exception(queue->info->netdev, prog, act);
 > +			break;
 > +		}
 > +		get_page(pdata);
 >  		err = xennet_xdp_xmit(queue->info->netdev, 1, &xdpf, 0);
 >  		if (unlikely(!err))
 >  			xdp_return_frame_rx_napi(xdpf);
 > -		else if (unlikely(err < 0))
 > +		else if (unlikely(err < 0)) {
 >  			trace_xdp_exception(queue->info->netdev, prog, act);
 > +			xdp_return_frame_rx_napi(xdpf);
 > +		}

Could you please merge the two if () blocks, as they share the
call of xdp_return_frame_rx_napi() now? Something like:

if (unlikely(err <= 0)) {
	if (err < 0)
		trace_xdp_exception(queue->info->netdev, prog, act);
	xdp_return_frame_rx_napi(xdpf);
}

 >  		break;
 >  	case XDP_REDIRECT:
 >  		get_page(pdata);
 >  		err = xdp_do_redirect(queue->info->netdev, xdp, prog);
 >  		*need_xdp_flush = true;
 > -		if (unlikely(err))
 > +		if (unlikely(err)) {
 >  			trace_xdp_exception(queue->info->netdev, prog, act);
 > +			__xdp_return(page_address(pdata), &xdp->mem, true, xdp);
 > +		}
 >  		break;


Juergen

P.S.: please don't use HTML in emails

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  parent reply	other threads:[~2025-04-17 10:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 18:34 [PATCH] xen-netfront: handle NULL returned by xdp_convert_buff_to_frame() Alexey Nepomnyashih
2025-04-17  0:58 ` Jakub Kicinski
2025-04-17  7:00   ` Alexey
2025-04-17  7:12     ` Jürgen Groß
2025-04-17  8:45       ` Alexey
2025-04-17  8:51         ` Juergen Gross
     [not found]           ` <8264519a-d58a-486e-b3c5-dba400658513@nppct.ru>
2025-04-17 10:23             ` Jürgen Groß [this message]
2025-04-17 11:19               ` Alexey
2025-04-17 13:22                 ` Jürgen Groß

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4679ca25-572b-44aa-bc00-cb9dc1c0080c@suse.com \
    --to=jgross@suse.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=netdev@vger.kernel.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=pabeni@redhat.com \
    --cc=sdl@nppct.ru \
    --cc=sstabellini@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox