From patchwork Thu Jul 11 12:54:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 2826317 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52E20C0AB2 for ; Thu, 11 Jul 2013 12:54:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98339200C7 for ; Thu, 11 Jul 2013 12:54:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D87DF20169 for ; Thu, 11 Jul 2013 12:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932149Ab3GKMyM (ORCPT ); Thu, 11 Jul 2013 08:54:12 -0400 Received: from mail-la0-f46.google.com ([209.85.215.46]:64908 "EHLO mail-la0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932140Ab3GKMyM (ORCPT ); Thu, 11 Jul 2013 08:54:12 -0400 Received: by mail-la0-f46.google.com with SMTP id eg20so6699790lab.5 for ; Thu, 11 Jul 2013 05:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=h+gblltyueoSjMtM2jnVV9XhpRMUaMrVnbpnqlq4jTc=; b=V408QEd0aBiPO+x2bKmibeizwJu8Ezny3XyERydSn8oij4qPYoFNHQBqikGq1sdOiU RQwkwWFEjU/56jAAWMBAXCQfpMIq6ItmCXHUi4pMggCopV/m2/cT+M5d77HrT1ArRhHY w36UZUdvqgwZq5vVjnWoBLNyH/bz8tQtMSU/rL4Qy+zvj3WcHUhLXuryyp4e1oUoAyeU gs3xQW8Sgw6w1mZj4rK7COMSqqWcvLxaldSaETuaCelU786jeLls9ZHmBo1lsyhgeE2H EPGvdWbNBhO6FuxmEqF3y4pmo0mHOsxWRK/e7F4cdcuaAGd5z3DpJ836R+yngzDBaJtB RsGQ== X-Received: by 10.152.121.106 with SMTP id lj10mr17765605lab.27.1373547250518; Thu, 11 Jul 2013 05:54:10 -0700 (PDT) Received: from localhost.localdomain (PPPoE-78-29-83-145.san.ru. [78.29.83.145]) by mx.google.com with ESMTPSA id u1sm12744046lag.5.2013.07.11.05.54.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Jul 2013 05:54:09 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH] CIFS: Fix a deadlock when a file is reopened Date: Thu, 11 Jul 2013 16:54:04 +0400 Message-Id: <1373547244-5048-1-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 If we request reading or writing on a file that needs to be reopened, it causes the deadlock: we are already holding rw semaphore for reading and then we try to acquire it for writing in cifs_relock_file. Fix this by acquiring the semaphore for reading in cifs_relock_file due to we don't make any changes in locks and don't need a write access. Signed-off-by: Pavel Shilovsky Acked-by: Jeff Layton --- fs/cifs/file.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index b149ae4..be24f09 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -561,11 +561,10 @@ cifs_relock_file(struct cifsFileInfo *cfile) struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); int rc = 0; - /* we are going to update can_cache_brlcks here - need a write access */ - down_write(&cinode->lock_sem); + down_read(&cinode->lock_sem); if (cinode->can_cache_brlcks) { - /* can cache locks - no need to push them */ - up_write(&cinode->lock_sem); + /* can cache locks - no need to relock */ + up_read(&cinode->lock_sem); return rc; } @@ -576,7 +575,7 @@ cifs_relock_file(struct cifsFileInfo *cfile) else rc = tcon->ses->server->ops->push_mand_locks(cfile); - up_write(&cinode->lock_sem); + up_read(&cinode->lock_sem); return rc; }