From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:42828 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752997AbeBTQ7r (ORCPT ); Tue, 20 Feb 2018 11:59:47 -0500 Received: by mail-pg0-f65.google.com with SMTP id y8so7319298pgr.9 for ; Tue, 20 Feb 2018 08:59:47 -0800 (PST) Subject: Re: [net PATCH 3/4] virtio_net: fix memory leak in XDP_REDIRECT To: Jesper Dangaard Brouer , Jason Wang Cc: "Michael S. Tsirkin" , netdev@vger.kernel.org, Alexei Starovoitov , Saeed Mahameed , Daniel Borkmann , "David S. Miller" , Tariq Toukan References: <151913348634.28247.17519468037896960567.stgit@firesoul> <151913353504.28247.963049986131113639.stgit@firesoul> From: John Fastabend Message-ID: <2dd5f441-d6e7-368c-743f-af8f720685f8@gmail.com> Date: Tue, 20 Feb 2018 08:59:45 -0800 MIME-Version: 1.0 In-Reply-To: <151913353504.28247.963049986131113639.stgit@firesoul> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org List-ID: On 02/20/2018 05:32 AM, Jesper Dangaard Brouer wrote: > XDP_REDIRECT calling xdp_do_redirect() can fail for multiple reasons > (which can be inspected by tracepoints). The current semantics is that > on failure the driver calling xdp_do_redirect() must handle freeing or > recycling the page associated with this frame. This can be seen as an > optimization, as drivers usually have an optimized XDP_DROP code path > for frame recycling in place already. > > The virtio_net driver didn't handle when xdp_do_redirect() failed. > This caused a memory leak as the page refcnt wasn't decremented on > failures. > > The function __virtnet_xdp_xmit() did handle one type of failure, > when the xmit queue virtqueue_add_outbuf() is full, which "hides" > releasing a refcnt on the page. Instead the function __virtnet_xdp_xmit() > must follow API of xdp_do_redirect(), which on errors leave it up to > the caller to free the page, of the failed send operation. > > Fixes: 186b3c998c50 ("virtio-net: support XDP_REDIRECT") > Signed-off-by: Jesper Dangaard Brouer > --- Acked-by: John Fastabend