Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp472182rdb; Thu, 15 Feb 2024 06:04:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhaIwALv8l+3BiTFgp1jTM4vJROymMuoxk9UwyBxiUH7UAVTdbZl3+Zvh9P0KPlK7s/0KcangTBGYRD1k0+i6YFn9uMVLVLUeevdAaAQ== X-Google-Smtp-Source: AGHT+IGAQkEfw1wrn/QaF3hIS3PkWZXNjWOW8RWyMPFuUj12jLx/bAhI3KLBdpW249JWwWwcZukh X-Received: by 2002:a67:e8d4:0:b0:46e:dc93:12 with SMTP id y20-20020a67e8d4000000b0046edc930012mr718317vsn.24.1708005840532; Thu, 15 Feb 2024 06:04:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708005840; cv=pass; d=google.com; s=arc-20160816; b=s7oDcF3J2WQznRPkvuRTCSUcUCT/idVJC+dnzvin294x5FaJzlr5ZfoOVcxd7iKxNA PLzSiry0ZjTlzByA8SKH9Fant+uiTZudz+Rto85N+zrDGNRXaBiCPsq9XLJ0HaOFMsG/ 5vWhP6Dkstu1huvJrrmpWH9QkG4suUdyXjkOc6WFxNd6KxdC+7USE6IbMeIKNk66Ck9w bTe+sO1FkKce1BEtFtJgIpBQzFFyNNLYLgjQftjZf1Q/kKdJ7anotUsq9kfMRrQXT5QJ Ef39F2G59bdojCQJ606AKZaaEltlhOJqa356hOO383sRSmm+XWfePxjpr91aoQJpfB3u cNzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bLg41PBwIDfC4cOMyvGi417/i5cujID83zbmEWIwlIk=; fh=NH5y3Xj5KXledzsMPEC0Fv1Cslh4ViX581F+mILmPp4=; b=QQK2jqXBkdhae0nkY9v6c5Nc5dSI21A6EYkuArIhFRdBL+PwYU+PPyczpZgkLn/7Tm 6YPtdatOkrhKuotyPh8HggWXtLxACbcVP5YMqBvaX3+kEYKDfHkKbU/041inBtKnYWz3 WjHs3z31lgUN3NaNyqn/884unIRMWRmBNBspqsEwxZvXJ1iXFygahUbo5G8Cgb0knHnY GF07hdonmazziOCKZVwqg0b8gdDneMivQTPUj6v87OaXXpe0JpvACCr55Y6vt7Oy8n1r Vvrqvgb078pNk7MlUbXuTnAMXHL7ExBld8oS6ZkE5q7ANCNWmIxv8p8I69qYMhJa7JOP /dQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fzl+ntlY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m25-20020a67fe59000000b0046b567b185esi159245vsr.812.2024.02.15.06.04.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:04:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fzl+ntlY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67043-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 09C0A1C24A20 for ; Thu, 15 Feb 2024 14:02:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DA71131E27; Thu, 15 Feb 2024 14:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fzl+ntlY" 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 A25AC130E40; Thu, 15 Feb 2024 14:01:59 +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=1708005719; cv=none; b=jn0BHbRLDV8+VELwKLAIv+F5Pciib5+VpQIDYPKsVbWhTldACOoFhzoiVOShB6YuKc9JkeX7LgI73g13L3KB1SjcpGp5tE36VE1HFUeZVCceUqvJOg/XgakNceN/O+FdezELnI+LpVkPXK/1AxoZFnl9lDECmxE3I623s/KDxI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708005719; c=relaxed/simple; bh=bLg41PBwIDfC4cOMyvGi417/i5cujID83zbmEWIwlIk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IlxoemJbP3zd+szDEpkuYST20RbiSnkGo5vGvrl8zQ888GS48+difW3FcfV3nX+6XphyH+lEunn97NvYIk+k8OHAVuRw0XdYa2WbjmyrpubIgE0C4ykcuphoBdbR76h2dz2jxcVwzLBBhA0+LjyinQZ9dTPcratQBlwhmeDer9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fzl+ntlY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6713C433F1; Thu, 15 Feb 2024 14:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708005719; bh=bLg41PBwIDfC4cOMyvGi417/i5cujID83zbmEWIwlIk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fzl+ntlYyRi/vtCED9/HzdjjUKeMuLr9Xu3bOqrjQ5gWQIM4YQ/D9HvtIVwT1LquD lRSotN4e6LZO7GdACZBD7qw95AA985TpebHFOL7Hv4ozL0zXnkzq772LDollgNmgTC FoG+w5AZlRJaSLuqCig0fykzd7jDyjGHa4VFwKEltF7TlZnPJCehNdNm4aOy2LLoyO cnCxuUTUl9IxPdRIIuR1oSuflBUmLySWf2kKVGLDPRlDRwfhCyr00V51ZxdGtphzUI vlQl0YVDLzs4SzH/FHM3ZfJQABlIly8uolOh3rSIqbceXeLlaThopuCq4l+2ZW3gkj JO9aBgk9l/VnQ== Date: Thu, 15 Feb 2024 15:01:55 +0100 From: Lorenzo Bianconi To: Alexander Lobakin Cc: Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] page_pool: disable direct recycling based on pool->cpuid on destroy Message-ID: References: <20240215113905.96817-1-aleksander.lobakin@intel.com> <87v86qc4qd.fsf@toke.dk> <8aa809c0-585f-4750-98d4-e19165c6ff73@intel.com> <15766d46-162c-4c99-84a0-7a4bc60c3289@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MN2cs1CvNJYC3dkc" Content-Disposition: inline In-Reply-To: <15766d46-162c-4c99-84a0-7a4bc60c3289@intel.com> --MN2cs1CvNJYC3dkc Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > From: Lorenzo Bianconi > Date: Thu, 15 Feb 2024 14:37:10 +0100 >=20 > >> From: Toke H=F8iland-J=F8rgensen > >> Date: Thu, 15 Feb 2024 13:05:30 +0100 > >> > >>> Alexander Lobakin writes: > >>> > >>>> Now that direct recycling is performed basing on pool->cpuid when se= t, > >>>> memory leaks are possible: > >>>> > >>>> 1. A pool is destroyed. > >>>> 2. Alloc cache is emptied (it's done only once). > >>>> 3. pool->cpuid is still set. > >>>> 4. napi_pp_put_page() does direct recycling basing on pool->cpuid. > >>>> 5. Now alloc cache is not empty, but it won't ever be freed. > >>> > >>> Did you actually manage to trigger this? pool->cpuid is only set for = the > >>> system page pool instance which is never destroyed; so this seems a v= ery > >>> theoretical concern? > >> > >> To both Lorenzo and Toke: > >> > >> Yes, system page pools are never destroyed, but we might latter use > >> cpuid in non-persistent PPs. Then there will be memory leaks. > >> I was able to trigger this by creating bpf/test_run page_pools with the > >> cpuid set to test direct recycling of live frames. > >=20 > > what about avoiding the page to be destroyed int this case? I do not li= ke the >=20 > I think I didn't get what you wanted to say here :s My assumption here was cpuid will be set just system page_pool so it is jus= t a matter of not running page_pool_destroy for them. Anyway in the future we c= ould allow to set cpuid even for non-system page_pool if the pool is linked to a given rx-queue and the queue is pinned to a given cpu. Regards, Lorenzo >=20 > Rewriting cpuid doesn't introduce any new checks on hotpath. Destroying > the pool is slowpath and we shouldn't hurt hotpath to handle it. >=20 > > idea of overwriting the cpuid field for it. >=20 > We also overwrite pp->p.napi field a couple lines below. It happens only > when destroying the pool, we don't care about the fields at this point. >=20 > >=20 > > Regards, > > Lorenzo > >=20 > >> > >>> > >>> I guess we could still do this in case we find other uses for setting > >>> the cpuid; I don't think the addition of the READ_ONCE() will have any > >>> measurable overhead on the common arches? > >> > >> READ_ONCE() is cheap, but I thought it's worth mentioning in the > >> commitmsg anyway :) > >> > >>> > >>> -Toke >=20 > Thanks, > Olek --MN2cs1CvNJYC3dkc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCZc4ZUwAKCRA6cBh0uS2t rIttAP9o5h37WPKS26lffxdmH29qGnoV/x0d8qqUkHSo3YRIyAD+MTT6z4V3J8bb fhu+Znf8NbyvyQVE13nMFnBjRxKKBw8= =bjmB -----END PGP SIGNATURE----- --MN2cs1CvNJYC3dkc--