From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965071AbbESO3u (ORCPT ); Tue, 19 May 2015 10:29:50 -0400 Received: from imap.thunk.org ([74.207.234.97]:45136 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932166AbbESO3s (ORCPT ); Tue, 19 May 2015 10:29:48 -0400 Date: Tue, 19 May 2015 10:29:43 -0400 From: "Theodore Ts'o" To: Jaegeuk Kim Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH] f2fs crypto: add rwsem to avoid data races Message-ID: <20150519142943.GE20421@thunk.org> Mail-Followup-To: Theodore Ts'o , Jaegeuk Kim , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <1432013801-39069-1-git-send-email-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432013801-39069-1-git-send-email-jaegeuk@kernel.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 18, 2015 at 10:36:41PM -0700, Jaegeuk Kim wrote: > Previoulsy, fi->i_crypt_info was not covered by any lock, resulting in > memory leak. > > This patch adds a rwsem to avoid leaking objects on i_crypt_info. > > Signed-off-by: Jaegeuk Kim I'm not sure we need an rwsem to fix this issue. In terms of serializing the creation and deletion of the structure, it should be possible to use an cmpxchg() on the pointer itself. (e.g., if we lose the race on the creation side, we just release our structure and use the one that the winner allocated). If we do end up needing to serialize access to the tfm in the i_crypt_info object for datapath reads/writes, then we might need a mutex, but I think that should be it, no? - Ted