Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp1139564lqs; Wed, 6 Mar 2024 07:25:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMozShDyk5MP8bUn/Mu83uofG50tPDBir+wq9p/1i6xm7dbmb+L3fPNevmF9vOtBDpuWuyys2+56zJSbiB7Cn6fO/dWr7Tq9Lih1LoSw== X-Google-Smtp-Source: AGHT+IETPKnfeFm8nVU9QO8zDKutdFa6z/oxkGVI8Euexv/6YZQooAucavYhvX4/AhYS7xzILtiQ X-Received: by 2002:a05:6a00:4c85:b0:6e5:1196:6cf5 with SMTP id eb5-20020a056a004c8500b006e511966cf5mr8357827pfb.3.1709738716126; Wed, 06 Mar 2024 07:25:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709738716; cv=pass; d=google.com; s=arc-20160816; b=DmvozHDzoETixwv3JMgeIJ8vOWayquYkhLWQu2TCuKArXJuL1xugFF7sn2ARMbyHZ5 bqKBC60METq/3Ik1uTj/BACeIUAICrav9r0VVMTKgumW2zA3M+c25owr5KTcsht4IzsE KjFrqYPU1UurLH4/Hyb4XvKp1Ot5F+/GcppOCfEvzI2jL6yWV40duwWUSaxNVRYDKmzE pff9qAqbWmdkDOvuynfXbfrhEhsGd99uD7Mm7531x74uTQRL8f3yW+0GY4u0QoUQU9rv JMPoBBUo8ItEFfN8urFMILs+zNpht3TqBkkkHfezOrzMdq5ceLF+pDLG1XpdhE9DD/Og MRPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=fIvTJVUIdJQJ9kX091lLA1UUiyj0DrCYDF0OZlRU3Gg=; fh=n7DZUO13guBVzuqXbUfuLs70hv5QjUgrs32IcsYwwJM=; b=TNsC1sbhX4LP2vXmAel2DLaoXIqTKqO3Qivlnv0r04ca4YHAyUJxY7c1PM7dbsDp/x ltqZ/Siw50U7m9EO4fMYeKSwe7ViK0IDtUodoVOTrex/rqUSzneHDtg7cwfcGkP8ZLX6 QRXIxMgbzLS0n4UOPd1wvavhbRcDoGr6SsSjgGnsFNFtyPf2sYuhiNn0SurDeTHa8Qc7 JzRNccAnPXZOJrtWcUHghC0SuyiTSq+OPThIph0XUnaqRCnopDv4oI1+sG91tA6isV9Y G4bAEAlnBQX/FRn2biS3TRng0dOCVtoNnp/XIW9QNbZmiTu12eomKNdjLFTisDXDzMjc 3zfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c6JdyTqK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94147-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94147-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cm11-20020a056a00338b00b006e636e045b0si3595292pfb.8.2024.03.06.07.25.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 07:25:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94147-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=@kernel.org header.s=k20201202 header.b=c6JdyTqK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94147-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94147-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 97B8AB21F5E for ; Wed, 6 Mar 2024 15:22:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3952A1353E4; Wed, 6 Mar 2024 15:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c6JdyTqK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F1E45DF1D; Wed, 6 Mar 2024 15:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709738547; cv=none; b=ulEk7mAn1Q2kGpBp+HE27einJKGvCMOFfG/vcUa42VEQp2439Sy1BVyWHStx4dPym5zuxiBW2xyKMfW5VvE99lAe1n4aqTUj2f/YQ9NkUkZOzeiKSCvCguUZNNUH+/qNkMRMupqs3CsD6dZsoaWq7WpziDxGpPb1TGqzM5aZpMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709738547; c=relaxed/simple; bh=1LgluQv1M0MpfLZxjv6T5+z/3k7YjbHLdzNPN3vfxrQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vGQrb9o7FEaweItTyXV72QmO03s7dXmiJrHxkPE5N2+gQk17Lio93rjkPBocnFajD8PLG/gW3Po0vm2IZzlJJW4ZAbeplx3IFEl63Kyq0auQU6OShLHElbPf5IIJigt39oT9EaXMngIElcTn2rJf0Vr66zbUKRWhk0Fuo4LXADo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c6JdyTqK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 485FBC433F1; Wed, 6 Mar 2024 15:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709738546; bh=1LgluQv1M0MpfLZxjv6T5+z/3k7YjbHLdzNPN3vfxrQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=c6JdyTqKkKCGVZO+Af70uAEJ2llNw5TNzY1aRj2xHJxozsPCsV1pgOOSipXDvyvq6 GDThdToWSVOc2K8DbA+kXsJxWcmMSqGjFsbeFkXODveioXeAcIGuJDZ6AZcJjm9ayr HABbgzUMl+9BJSSxST3RY6mrbhlxactZcuGMjaIsYB80+X9bjUVUXxgyBbPl34vhvw GdnhXLPMMIGq6ToRkab8kNPm8wR/3/xKA0I9jxp99/AjIzOlf8flMBwF9jfLbWSbwJ rzw1wqDYtL4wT62bPQ3tTQWoO2vDAth/HtrW+NeAe3PGcG9agGH0tTqWXQ8eCOh038 qMXHTOGI4c1TA== Date: Wed, 6 Mar 2024 07:22:25 -0800 From: Jakub Kicinski To: Dragos Tatulea Cc: "almasrymina@google.com" , "davem@davemloft.net" , "herbert@gondor.apana.org.au" , Gal Pressman , "dsahern@kernel.org" , "steffen.klassert@secunet.com" , "linux-kernel@vger.kernel.org" , Leon Romanovsky , "pabeni@redhat.com" , "edumazet@google.com" , "ian.kumlien@gmail.com" , "Anatoli.Chechelnickiy@m.interpipe.biz" , "netdev@vger.kernel.org" Subject: Re: [RFC] net: esp: fix bad handling of pages from page_pool Message-ID: <20240306072225.4a61e57c@kernel.org> In-Reply-To: <7fc334b847dc4d90af796f84a8663de9f43ede5d.camel@nvidia.com> References: <20240304094950.761233-1-dtatulea@nvidia.com> <20240305190427.757b92b8@kernel.org> <7fc334b847dc4d90af796f84a8663de9f43ede5d.camel@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 6 Mar 2024 13:05:14 +0000 Dragos Tatulea wrote: > On Tue, 2024-03-05 at 19:04 -0800, Jakub Kicinski wrote: > > On Mon, 4 Mar 2024 11:48:52 +0200 Dragos Tatulea wrote: =20 > > > When the skb is reorganized during esp_output (!esp->inline), the pag= es > > > coming from the original skb fragments are supposed to be released ba= ck > > > to the system through put_page. But if the skb fragment pages are > > > originating from a page_pool, calling put_page on them will trigger a > > > page_pool leak which will eventually result in a crash. =20 > >=20 > > So it just does: skb_shinfo(skb)->nr_frags =3D 1; > > and assumes that's equivalent to owning a page ref on all the frags? > > =20 > My understanding is different: it sets nr_frags to 1 because it's swappin= g out > the old page frag in fragment 0 with the new xfrag page frag and will use= this > "new" skb from here. It does take a page reference for the xfrag page fra= g. Same understanding, I'm just bad at explaining :) > > Fix looks more or less good, we would need a new wrapper to avoid > > build issues without PAGE_POOL,=C2=A0 > > =20 > Ack. Which component would be best location for this wrapper: page_pool? 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. > > but I wonder if we wouldn't be better > > off changing the other side. Instead of "cutting off" the frags - > > walking them and dealing with various page types. Because Mina and co. > > will step onto this landmine as well. =20 > The page frags are still stored and used in the sg scatterlist. If we rel= ease > them at the moment when the skb is "cut off", the pages in the sg will be > invalid. At least that's my understanding. I was thinking something along the lines of: for each frag() if (is_pp_page()) { get_page(); page_pool_unref_page(1); } so that it's trivial to insert another check for "is this a zero-copy" page in there, and error our. But on reflection the zero copy check may be better placed in __skb_to_sgvec(), so ignore this. Just respin what you got with a new helper.