From mboxrd@z Thu Jan 1 00:00:00 1970 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 D021815D5C7 for ; Wed, 24 Apr 2024 14:48:36 +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=1713970116; cv=none; b=lenCozVFVc5ZDBTMuGJlRsIw/n+HdCqWVsxfra5/CnWihwBuM7dTHDE2TTVTvP9uX0F4dpL5l+KbG1HoUzY0V0tMGVIlhhP+dKnKzdhKPmEY0iXWkgRZdiJXLfyq+rjYIwpyf5fOx8cdYtfZzYShoaEA6ibDj8MWWnVjnHnWhko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713970116; c=relaxed/simple; bh=MtcBXVBoT7WsAzim0Ux670NdL79KlExVL9cJiDbfnQ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OZjD9SWsqaO3TQwqVxMJMLr2Nv8YaWTXL21yRLd44lcDuUuDORUXfmZpOvcyfR4JiKUQZPnyDfPzjF+N13FLB0Sv2w0wgIh8VU9EgCiZ8KtHS5syaEAqubFtioRC6vUNfsQH/WikyWLFOLCR880eTzIveZ04WXBnYyoljdoJdIA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f2J8Mrve; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f2J8Mrve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D410C113CD; Wed, 24 Apr 2024 14:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713970116; bh=MtcBXVBoT7WsAzim0Ux670NdL79KlExVL9cJiDbfnQ0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f2J8MrveEpoVMmjQC1mQP7g4aeEj5b4LwQZPrzrkeDT1feMN5rpweBoEAov6iBmDR Qt6NfkpQVRXlcCC1Cf+SJMTA7bVZ7ca5e7oCQPdGdNHgJbflUNRcaUfQpsjS2Mix90 1A7mtLNoiaWpAEQU2peZeS+3lxLn3mZRIqGBt748zTaZBJ3jD1rLJYW/ev1NppHncx 8B+aJchG4gHUrM3SlZqEUKnyEF8/khq9lgVXSs9xH4FIa0UAcBqY6Wj5AHfLYBqiGe pvYnV2HI3tjWs+rqjviHSweY4NTnSsECIqtahhZ3X6BtFU1KZzkcpTC6TGAz089bk0 LA89AjznsB/Jw== Date: Wed, 24 Apr 2024 15:48:31 +0100 From: Simon Horman To: Petr Machata Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Ido Schimmel , Jiri Pirko , Alexander Zubkov , mlxsw@nvidia.com Subject: Re: [PATCH net 2/9] mlxsw: spectrum_acl_tcam: Fix race during rehash delayed work Message-ID: <20240424144831.GD42092@kernel.org> References: <1ec1d54edf2bad0a369e6b4fa030aba64e1f124b.1713797103.git.petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1ec1d54edf2bad0a369e6b4fa030aba64e1f124b.1713797103.git.petrm@nvidia.com> On Mon, Apr 22, 2024 at 05:25:55PM +0200, Petr Machata wrote: > From: Ido Schimmel > > The purpose of the rehash delayed work is to reduce the number of masks > (eRPs) used by an ACL region as the eRP bank is a global and limited > resource. > > This is done in three steps: > > 1. Creating a new set of masks and a new ACL region which will use the > new masks and to which the existing filters will be migrated to. The > new region is assigned to 'vregion->region' and the region from which > the filters are migrated from is assigned to 'vregion->region2'. > > 2. Migrating all the filters from the old region to the new region. > > 3. Destroying the old region and setting 'vregion->region2' to NULL. > > Only the second steps is performed under the 'vregion->lock' mutex > although its comments says that among other things it "Protects > consistency of region, region2 pointers". > > This is problematic as the first step can race with filter insertion > from user space that uses 'vregion->region', but under the mutex. > > Fix by holding the mutex across the entirety of the delayed work and not > only during the second step. > > Fixes: 2bffc5322fd8 ("mlxsw: spectrum_acl: Don't take mutex in mlxsw_sp_acl_tcam_vregion_rehash_work()") > Signed-off-by: Ido Schimmel > Tested-by: Alexander Zubkov > Reviewed-by: Petr Machata > Signed-off-by: Petr Machata Reviewed-by: Simon Horman