From patchwork Sat Mar 7 16:09:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 5959551 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A50969F318 for ; Sat, 7 Mar 2015 16:11:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C92BF20374 for ; Sat, 7 Mar 2015 16:10:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EBD3C2020F for ; Sat, 7 Mar 2015 16:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbbCGQK5 (ORCPT ); Sat, 7 Mar 2015 11:10:57 -0500 Received: from cdptpa-outbound-snat.email.rr.com ([107.14.166.231]:63258 "EHLO cdptpa-oedge-vip.email.rr.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751958AbbCGQKF (ORCPT ); Sat, 7 Mar 2015 11:10:05 -0500 Received: from [107.15.97.250] ([107.15.97.250:42858] helo=tlielax.poochiereds.net) by cdptpa-oedge02 (envelope-from ) (ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTP id AE/D9-08648-9D22BF45; Sat, 07 Mar 2015 16:10:02 +0000 From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: bfields@fieldses.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] locks: use cmpxchg to assign i_flctx pointer Date: Sat, 7 Mar 2015 11:09:59 -0500 Message-Id: <1425744599-4934-5-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1425744599-4934-1-git-send-email-jeff.layton@primarydata.com> References: <1425744599-4934-1-git-send-email-jeff.layton@primarydata.com> X-RR-Connecting-IP: 107.14.168.130:25 X-Cloudmark-Score: 0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP During the v3.20/v4.0 cycle, I had originally had the code manage the inode->i_flctx pointer using a compare-and-swap operation instead of the i_lock. Sasha Levin though hit a problem while testing trinity that made me believe that that wasn't safe. I now think though that I completely misread the problem, even though it seemed like it went away when we started using the i_lock to protect this pointer. The issue was likely the same race that Kirill Shutemov hit while testing the pre-rc1 v4.0 kernel and that Linus spotted. Due to the way that the spinlock was dropped in the middle of flock_lock_file, you could end up with multiple flock locks for the same struct file on the inode. Reinstate the use of a CAS operation to assign this pointer since it's likely to be more efficient and gets the i_lock completely out of the file locking business. Signed-off-by: Jeff Layton --- fs/locks.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 4347f3dc17cc..22c0785c00ed 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -223,14 +223,7 @@ locks_get_lock_context(struct inode *inode, int type) * Assign the pointer if it's not already assigned. If it is, then * free the context we just allocated. */ - spin_lock(&inode->i_lock); - if (likely(!inode->i_flctx)) { - inode->i_flctx = new; - new = NULL; - } - spin_unlock(&inode->i_lock); - - if (new) + if (cmpxchg(&inode->i_flctx, NULL, new)) kmem_cache_free(flctx_cache, new); out: return inode->i_flctx;