Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp559834img; Thu, 28 Feb 2019 04:17:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IaIpZZq9xdUJ/JuFFPQjkoeeDx6RBSbWTqgPtZZDDcjbIYzhTcYtNvtnL3mte/saaVfz71B X-Received: by 2002:a62:1f5d:: with SMTP id f90mr59374pff.104.1551356267514; Thu, 28 Feb 2019 04:17:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551356267; cv=none; d=google.com; s=arc-20160816; b=i4x8JnmvSfw97yjKJ1oz13CIqxWAZ4/daREqu0lGeM28VAZzLEMf0jq95dnvIAkISN C0wzegYyYo5KRcIGSAQPmYNSwjCeW63Yq1MfWXceRqEzoS/EFILdm+yHdqvusT6THLup 24TEu90ixy4loF+ZCoh1Tt9nOcTfIvSeQ85P+SRMnHXi5r7FwBoBNh91CNJ1LF6oiF8T J5lhksznbN5iSpmxukSg9zYJL0xD3umKl95wZkV8UEa8NM1oU3ND75hSpmaLKGXLTKOA ibRKodWnTG6PrdVD/U06/bWH2xrRzc3tvpLW347F0YCRxqirnvonPwNsVJCVj4h7vajt gk7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=J/J1MSXx9cQdRmsSirz39zI9QcpvNHmD9bXjozAd+MM=; b=kj6UGL2HEej50fATbEQdTW6vqtP+S5WLN3+aJzkG9f0ndQtNcqURVGbUY2NCwxfgRh ooiSZZ49dOJo16yD09o4aEf6VDlZDlNqx1OX4fANJ3M9Kv+K5RXCTXRMiFFa/ujXONwI FisRPCfNIrTkXZTLuzj3AUdJ4DAwr5v45gtGHev6vAFSkGTt3OiDLUkhx+pFTjnUNRje fChiKcgKwdGqr8i5gcO150HoOaoz7+gh0w9t8eElprrie/+XyWLFsVs2WstaLJvaga3T vVXF817FjLdJjIcqN9Q0oELN4yVQiBHlG+wSR+DrnQbv4wPd5Aq3lYj/MB9Om/rip5iC Bn+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u18si8915294pgk.440.2019.02.28.04.17.32; Thu, 28 Feb 2019 04:17:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731415AbfB1LWK convert rfc822-to-8bit (ORCPT + 99 others); Thu, 28 Feb 2019 06:22:10 -0500 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:56035 "EHLO SMTP.EU.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730797AbfB1LWK (ORCPT ); Thu, 28 Feb 2019 06:22:10 -0500 X-IronPort-AV: E=Sophos;i="5.58,423,1544486400"; d="scan'208";a="86582568" From: Paul Durrant To: Wei Liu CC: Igor Druzhinin , "xen-devel@lists.xenproject.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Wei Liu , "davem@davemloft.net" Subject: RE: [PATCH] xen-netback: fix occasional leak of grant ref mappings under memory pressure Thread-Topic: [PATCH] xen-netback: fix occasional leak of grant ref mappings under memory pressure Thread-Index: AQHUzwnalyGnLUhGt0OYo7x3WDkwmKX09AIQgAAHGACAABYNsA== Date: Thu, 28 Feb 2019 11:21:57 +0000 Message-ID: References: <1551319382-32595-1-git-send-email-igor.druzhinin@citrix.com> <8424fba34a1f43908a6dae3a9308863b@AMSPEX02CL02.citrite.net> <20190228110136.somjads2f5ivqhju@zion.uk.xensource.com> In-Reply-To: <20190228110136.somjads2f5ivqhju@zion.uk.xensource.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Wei Liu [mailto:wei.liu2@citrix.com] > Sent: 28 February 2019 11:02 > To: Paul Durrant > Cc: Igor Druzhinin ; xen-devel@lists.xenproject.org; > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; Wei Liu ; > davem@davemloft.net > Subject: Re: [PATCH] xen-netback: fix occasional leak of grant ref mappings under memory pressure > > On Thu, Feb 28, 2019 at 09:46:57AM +0000, Paul Durrant wrote: > > > -----Original Message----- > > > From: Igor Druzhinin [mailto:igor.druzhinin@citrix.com] > > > Sent: 28 February 2019 02:03 > > > To: xen-devel@lists.xenproject.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org > > > Cc: Wei Liu ; Paul Durrant ; davem@davemloft.net; > Igor > > > Druzhinin > > > Subject: [PATCH] xen-netback: fix occasional leak of grant ref mappings under memory pressure > > > > > > Zero-copy callback flag is not yet set on frag list skb at the moment > > > xenvif_handle_frag_list() returns -ENOMEM. This eventually results in > > > leaking grant ref mappings since xenvif_zerocopy_callback() is never > > > called for these fragments. Those eventually build up and cause Xen > > > to kill Dom0 as the slots get reused for new mappings. > > > > > > That behavior is observed under certain workloads where sudden spikes > > > of page cache usage for writes coexist with active atomic skb allocations. > > > > > > Signed-off-by: Igor Druzhinin > > > --- > > > drivers/net/xen-netback/netback.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c > > > index 80aae3a..2023317 100644 > > > --- a/drivers/net/xen-netback/netback.c > > > +++ b/drivers/net/xen-netback/netback.c > > > @@ -1146,9 +1146,12 @@ static int xenvif_tx_submit(struct xenvif_queue *queue) > > > > > > if (unlikely(skb_has_frag_list(skb))) { > > > if (xenvif_handle_frag_list(queue, skb)) { > > > + struct sk_buff *nskb = > > > + skb_shinfo(skb)->frag_list; > > > if (net_ratelimit()) > > > netdev_err(queue->vif->dev, > > > "Not enough memory to consolidate frag_list!\n"); > > > + xenvif_skb_zerocopy_prepare(queue, nskb); > > > xenvif_skb_zerocopy_prepare(queue, skb); > > > kfree_skb(skb); > > > continue; > > > > Whilst this fix will do the job, I think it would be better to get rid of the kfree_skb() from > inside xenvif_handle_frag_list() and always deal with it here rather than having it happen in two > different places. Something like the following... > > +1 for having only one place. > > > > > ---8<--- > > diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c > > index 80aae3a32c2a..093c7b860772 100644 > > --- a/drivers/net/xen-netback/netback.c > > +++ b/drivers/net/xen-netback/netback.c > > @@ -1027,13 +1027,13 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue, > > /* Consolidate skb with a frag_list into a brand new one with local pages on > > * frags. Returns 0 or -ENOMEM if can't allocate new pages. > > */ > > -static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff *skb) > > +static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff *diff --git > a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c > > index 80aae3a32c2a..093c7b860772 100644 > > --- a/drivers/net/xen-netback/netback.c > > +++ b/drivers/net/xen-netback/netback.c > > @@ -1027,13 +1027,13 @@ static void xenvif_tx_build_gops(struct xenvif_queue *qu > > eue, > > /* Consolidate skb with a frag_list into a brand new one with local pages on > > * frags. Returns 0 or -ENOMEM if can't allocate new pages. > > */ > > -static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff * > > skb) > > +static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff * > > skb, > > + struct sk_buff *nskb) > > { > > unsigned int offset = skb_headlen(skb); > > skb_frag_t frags[MAX_SKB_FRAGS]; > > int i, f; > > struct ubuf_info *uarg; > > - struct sk_buff *nskb = skb_shinfo(skb)->frag_list; > > > > queue->stats.tx_zerocopy_sent += 2; > > queue->stats.tx_frag_overflow++; > > @@ -1072,11 +1072,6 @@ static int xenvif_handle_frag_list(struct xenvif_queue *q > > ueue, struct sk_buff *s > > skb_frag_size_set(&frags[i], len); > > } > > > > - /* Copied all the bits from the frag list -- free it. */ > > - skb_frag_list_init(skb); > > - xenvif_skb_zerocopy_prepare(queue, nskb); > > - kfree_skb(nskb); > > - > > /* Release all the original (foreign) frags. */ > > for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) > > skb_frag_unref(skb, f); > > @@ -1145,7 +1140,11 @@ static int xenvif_tx_submit(struct xenvif_queue *queue) > > xenvif_fill_frags(queue, skb); > > > > if (unlikely(skb_has_frag_list(skb))) { > > - if (xenvif_handle_frag_list(queue, skb)) { > > + struct sk_buff *nskb = skb_shinfo(skb)->frag_list; > > + > > + xenvif_skb_zerocopy_prepare(queue, nskb); > > + > > + if (xenvif_handle_frag_list(queue, skb, nskb)) { > > if (net_ratelimit()) > > netdev_err(queue->vif->dev, > > "Not enough memory to consolidate frag_list!\n"); > > @@ -1153,6 +1152,10 @@ static int xenvif_tx_submit(struct xenvif_queue *queue) > > kfree_skb(skb); > > continue; > > } > > + > > + /* Copied all the bits from the frag list. */ > > + skb_frag_list_init(skb); > > + kfree(nskb); > > I think you want kfree_skb here? No. nskb is the frag list... it is unlinked from skb by the call to skb_frag_list_init() and then it can be freed on its own. The skb is what we need to retain, because that now contains all the data. Cheers, Paul > > Wei. > > > } > > > > skb->dev = queue->vif->dev; > > ---8<--- > > > > What do you think? > > > > Paul > > > > > -- > > > 2.7.4 > >