Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp43463lqi; Wed, 6 Mar 2024 09:32:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVM/dDtqVB9HNVic/zM7SWS2opnmoehzabXevD4TR40/q4Htu6jqWpYoZbUmXGO9cBQQA/Emjubf5wBxGcqPIuGjy09lJ3LIyr3qVYb5A== X-Google-Smtp-Source: AGHT+IFPqMkrid+ocY2vq6JYAIBcr3e2GsBL/AeBvTRCXPtY+jX19agkPLfpvj8QZY0CATYXBpB5 X-Received: by 2002:a05:6e02:1a8f:b0:365:aaca:d166 with SMTP id k15-20020a056e021a8f00b00365aacad166mr17539772ilv.28.1709746377390; Wed, 06 Mar 2024 09:32:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709746377; cv=pass; d=google.com; s=arc-20160816; b=z5FXiuQnHPYD9Hji+r9YWqCg6VI0FPFrRO4nI7qWAJEHcHZqaoPrLHX8pa+8ha6dfH T5qgiZFB3qp4UL62roArlOhGESI5UsZu33PvESCXlvwog1ksDPkCe6EbraDPwcoMylze N/rUXj1ou7u/sy3XQrELalVotuyOBmvex//T45KZezCD7la4eYIvC22U+uqiud+KVmGt 3pEnpQuDxYGNmCONh6phI+ceLZE2ywKsP6jkqz1AZhh2F4FsIUnXup/kNPmXG3UL0KGv mskaBdgcenZi1IBzZQg0qWYYOPLiQxDxi/4z+0cNHGjVl3jxOcCOAo7gDIhuYEvJo+of EdPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=w94diZ9iNEVg6u9UwjKj2DUh++QG9DmeQZBnfcZOhW8=; fh=fwvm7eoECCjljnQXhrWqjisU5lABakL5eTQbg45WVFo=; b=xXfmqyjA3WXI48UkfrVxSFH5bOn2MQKDImOLyPdTcJZU6N/Npp4bL/NEA401X9dQ8+ g+h3FwbugYx1Im9JnlsSDnv0xMaHWi6keQhwx4IX8Zl7iEq8sMOMwEf3Qt12NHVnaN+5 +t0liSW2oBvYU6bTGEXpNE5TCtgX4Ag8TBg9b3C7xkmMNklEaohm/+D5OiNDEgHJsxBK VDEtf3e8z21jRCenjLwa2IUPveLnVVcTqMJpx01tdqNDhCbgERphLOQlKS9N63D+9yb6 kD2tO10xTm1WZTdXy2r9LkGGnXYo8KRcXm31BhTYHFmhvTATjnOcxtn6feAKnu+EYzbD 7U2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZnOX00fc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s9-20020a635249000000b005dbf1fcc429si12089149pgl.162.2024.03.06.09.32.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 09:32:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZnOX00fc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4C9B7B238D8 for ; Wed, 6 Mar 2024 17:28:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45AB713BAE8; Wed, 6 Mar 2024 17:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZnOX00fc" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A29C8135401 for ; Wed, 6 Mar 2024 17:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709746081; cv=none; b=qXZdqwdNjyOuPgcL1HVv3ThKQofu7mv6oSJS9AifccKAkZpCFZNdtAvKnF/jv8l4qJMVf6JFSHnmORm7G0XSoah69bdoRQi/BCSWOLiMWqp5+hJjuudU5TEw2RVxZ7QiMmLn6jZ2pyxVJ19+TXxtamhxLDX6hHYQfUBqf4AdPng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709746081; c=relaxed/simple; bh=eX3/X50p4A7OOA8htCEucfM7TcgCP6daHV9nlBfFHEI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=gSQ5Niido9gy6+Cla+jMpNcDX8LUwx1UcO490mKtZyhjvcSRiS99zvqqU0M2o2tdNzvE2pUgDfrESWfL1GUiw6LB9Bu7EPjxygMVel5SB5CeuLTOcXPvmHVi3nwOYOXkt/PIC022zk7yj71giS7CFt5bQvKyLM4ThUamkQbSmsA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZnOX00fc; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-563cb3ba9daso1332156a12.3 for ; Wed, 06 Mar 2024 09:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709746078; x=1710350878; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=w94diZ9iNEVg6u9UwjKj2DUh++QG9DmeQZBnfcZOhW8=; b=ZnOX00fc9GvzypiOvC+omM8G+kx9tS08LA0Xd7fF6vEC4CtUQ5R/JecEBJl8DfDho7 ACUKMLpS1o4Bs2X4pKduni6AfwVIXN3ijkJrmqFGcJrjJZlpR3MzeyB1HJVUqZB3Pr/J UhSkYKKRXuPTkCCMNNeYf4C0W3G5EfUQpK5fyxMKPHtFYHboYLSnJZ0twFOSuIy1t36i yerD9rhU1nyYW5P7IltH1utiKMehW1J8S4JTx+eEK5EIeITVvV/zvwhyP6SsGjpOiN8y EDFrAXHPZ84unqUWuO1PUWUbNASJgiHVhCI7+dEWJFVNGP+0/QLWkfVFJ2exuZLh2BD2 gbBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709746078; x=1710350878; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w94diZ9iNEVg6u9UwjKj2DUh++QG9DmeQZBnfcZOhW8=; b=k7i1gZiOjgC8grtWnSuhZleIyunD1NPQixDgvf65muzJB0nyRJ3oTiUceSvBTUW9oq vwuNfn6tKyPrj8K+QJkmCcWSvStFmBeTGbnoRDP/D2r1Au9/N6BVgtZo4KKfWofwhw+E JAHJ6hwHm5kOut8RX68oMIf2ExSJnlnfBI3WKgq8UGILUuXOtIPqhv3nzUDqZGg62E+Y M4kg2qSng5bDYPQrcpyH+2UGp3o7znQ5C/y3c5vyMpk1j7Ezq1d7f4aTxaJny0R5jmV5 Tt6a0m7tpX5p4ri0ZgAwRJHphX7bkVC24cWp0aN7FlNTdaR5U7k7qhHVI2oBWYgWB12H SXuQ== X-Forwarded-Encrypted: i=1; AJvYcCXb3C9V3V0Y0Cx02zZ2ywT8wVaGSJjwsZBvnqqH+uFOcjGHrrm2TqbJMCM4b4fWsYnC7UJler1Ho/LxeVHN99dhDWmnNs+6cPvd2vpx X-Gm-Message-State: AOJu0YxxRTU+Fi20W/K2vbBdRGb4z05l8DD+vhZwHMaDCBFazJTz/p/C Mn/u9g2XSMrPvFjqyO57yecDhRsgoBkIjuJ7rdD4DySfFDCaJIgIa8UMk8h6PLxFqaBiCMy4dUk AcHHZCymDom7Y0LI0kH2tq9OteS0nUKS4T1CP X-Received: by 2002:a17:906:1c81:b0:a45:98f3:997e with SMTP id g1-20020a1709061c8100b00a4598f3997emr4847806ejh.7.1709746077588; Wed, 06 Mar 2024 09:27:57 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240304094950.761233-1-dtatulea@nvidia.com> <20240305190427.757b92b8@kernel.org> <7fc334b847dc4d90af796f84a8663de9f43ede5d.camel@nvidia.com> <20240306072225.4a61e57c@kernel.org> <320ef2399e48ba0a8a11a3b258b7ad88384f42fb.camel@nvidia.com> <20240306080931.2e24101b@kernel.org> <9a78b37abdf40daafd9936299ea2c08f936ad3d5.camel@nvidia.com> In-Reply-To: <9a78b37abdf40daafd9936299ea2c08f936ad3d5.camel@nvidia.com> From: Mina Almasry Date: Wed, 6 Mar 2024 09:27:45 -0800 Message-ID: Subject: Re: [RFC] net: esp: fix bad handling of pages from page_pool To: Dragos Tatulea Cc: "kuba@kernel.org" , "davem@davemloft.net" , "herbert@gondor.apana.org.au" , Gal Pressman , "dsahern@kernel.org" , "steffen.klassert@secunet.com" , "linux-kernel@vger.kernel.org" , "pabeni@redhat.com" , Leon Romanovsky , "edumazet@google.com" , "ian.kumlien@gmail.com" , "Anatoli.Chechelnickiy@m.interpipe.biz" , "netdev@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 6, 2024 at 9:10=E2=80=AFAM Dragos Tatulea = wrote: > > On Wed, 2024-03-06 at 08:40 -0800, Mina Almasry wrote: > > On Wed, Mar 6, 2024 at 8:09=E2=80=AFAM Jakub Kicinski = wrote: > > > > > > On Wed, 6 Mar 2024 16:00:46 +0000 Dragos Tatulea wrote: > > > > > Hm, that's a judgment call. > > > > > Part of me wants to put it next to napi_frag_unref(), since we > > > > > basically need to factor out the insides of this function. > > > > > When you post the patch the page pool crowd will give us > > > > > their opinions. > > > > > > > > Why not have napi_pp_put_page simply return false if CONFIG_PAGE_PO= OL is not > > > > set? > > > > > > Without LTO it may still be a function call. > > > Plus, subjectively, I think that it's a bit too much logic to encode = in > > > the caller (you must also check skb->pp_recycle, AFAIU) > > > Maybe we should make skb_pp_recycle() take struct page and move it to > > > skbuff.h ? Rename it to skb_page_unref() ? > > > > > > > Does the caller need to check skb->pp_recycle? pp_recycle seems like a > > redundant bit. We can tell whether the page is pp by checking > > is_pp_page(page). the pages in the frag must be pp pages when > > skb->pp_recycle is set and must be non pp pages when the > > skb->pp_recycle is not set, so it all seems redundant to me. > > > AFAIU we don't have to check for pp_recycle, at least not in this specifi= c case. > > > My fix would be something like: > > > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > > index d577e0bee18d..cc737b7b9860 100644 > > --- a/include/linux/skbuff.h > > +++ b/include/linux/skbuff.h > > @@ -3507,17 +3507,25 @@ int skb_cow_data_for_xdp(struct page_pool > > *pool, struct sk_buff **pskb, > > bool napi_pp_put_page(struct page *page, bool napi_safe); > > > > static inline void > > -napi_frag_unref(skb_frag_t *frag, bool recycle, bool napi_safe) > > +napi_page_unref(struct page *page, bool napi_safe) > > { > > - struct page *page =3D skb_frag_page(frag); > > - > > #ifdef CONFIG_PAGE_POOL > > - if (recycle && napi_pp_put_page(page, napi_safe)) > > + if (napi_pp_put_page(page, napi_safe)) > > return; > > #endif > > put_page(page); > > } > > > > +static inline void > > +napi_frag_unref(skb_frag_t *frag, bool recycle, bool napi_safe) > > +{ > > + struct page *page =3D skb_frag_page(frag); > > + > > + DEBUG_NET_WARN_ON(recycle !=3D is_pp_page(page)); > > + > > + napi_page_unref(page); > > +} > > + > > > > And then use napi_page_unref() in the callers to handle page pool & > > non-page pool gracefully without leaking page pool internals to the > > callers. > > > We'd also need to add is_pp_page() in the header with the changes above..= . > Gah, I did not realize skbuff.h doesn't have is_pp_page(). Sorry! > On that line of thought, unless these new APIs are useful for other use-c= ases, > why not keep it simple: > - Move is_pp_page() to skbuff.h. I prefer this. is_pp_page() is a one-liner anyway. > - Do a simple is_pp_page(page) ? page_pool_put_full_page(page):put_page(p= age) in > the caller? Checking skb->pp_recycle would not be needed. > IMHO page pool internals should not leak to the callers like this. There should be a helper that does the right thing for pp & non-pp pages so that the caller can use it without worrying about subtle pp concepts that they may miss at some callsites, but I'm fine either way if there is strong disagreement from others. > Thanks, > Dragos > > > > > Regarding stable would I need to send a separate fix that does the = raw pp page > > > > check without the API? > > > > > > You can put them in one patch, I reckon. > > > --=20 Thanks, Mina