From patchwork Tue Aug 14 21:25:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10566149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51379157B for ; Tue, 14 Aug 2018 21:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43D8428E2B for ; Tue, 14 Aug 2018 21:26:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3784A292A2; Tue, 14 Aug 2018 21:26:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C755E28E2B for ; Tue, 14 Aug 2018 21:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730631AbeHOAPG (ORCPT ); Tue, 14 Aug 2018 20:15:06 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:33983 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727870AbeHOAPG (ORCPT ); Tue, 14 Aug 2018 20:15:06 -0400 Received: by mail-io0-f194.google.com with SMTP id l7-v6so19793798ioj.1 for ; Tue, 14 Aug 2018 14:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E/0X7reVtTlpcJx3IYnpBKAOa1f2SJ5uCrHYnCfC/a4=; b=nH6VFFPsmr32M4V3AHmv+XmAVku3Jkjak0o5aTOxPyno5AjOGC6DRmwLy4vD9EvpW7 1ZfvGEe7c7T332yFSp8b6HWeibpDp+OlzIuMiGpxEEMbIw7uQD0Orc+80ve/CyMLpmy9 sfVcTRR5az33mTohnMPSOXRsCH664/HskQySlcXHQK7/7Set3jCrH4TEbTZKjOtUeVI2 H9IfsD0y3Ikudz855/25isiiz9LoN+UaiJ/QMKS6owwkr4G11df/CeF8vkfQk7C0kxx7 kGDauM+ioVGR6+Xg1LIpzyASbPyhDAu17PZVxSylBi0pHOfHqku0luPMPunINUz2zdkE sM7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E/0X7reVtTlpcJx3IYnpBKAOa1f2SJ5uCrHYnCfC/a4=; b=QnZu9AY/Sv/cuaMR0dDKnJiBkkGP/FSIE0KjKrin7958BNJHdmNbOcxGZLr6USqBUQ FLXxjRhBlMOvOv+PpazpcOo9OZGVJsBfz2GlleM0SaL9YYm5risHvw4tVpRO2wLwt13A 6jc6aPPTK7Mz0syoQtAR4iIIE5QbyWUXPEgDDagW0V/NytefvFb88J6ZGXHvf5iFCV8a RLlBA+J6ssgmuP7+7fd3TJ661jGvYuaaulvks5gccyhvwqBC2fpyeKgzvpGIXmDP4FFU ElgvV3zXC+jqmMVstXRuO1p2oByOH6Y8x/ErMO4AzHIflHw3DLN5MIb3b3qH2QF6OR4n gEbQ== X-Gm-Message-State: AOUpUlGtOY9MG8GfhQCRqh0B7GPeBjlrJrBMF3k9myKizQ6ZbKL1Zpmh xDAx1fj5tiz9pzWWjLJFtw== X-Google-Smtp-Source: AA+uWPxxHXJXlMYLdUwVSDWTkDRBoB4NLyh15rtm1qgMD4Y6Qh1SZzc5/bxrF1ASyEuLoqrwAEwA0g== X-Received: by 2002:a6b:9651:: with SMTP id y78-v6mr20461809iod.283.1534281960358; Tue, 14 Aug 2018 14:26:00 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-124-244-228.alma.mi.frontiernet.net. [50.124.244.228]) by smtp.gmail.com with ESMTPSA id t64-v6sm117228ita.13.2018.08.14.14.25.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Aug 2018 14:25:59 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker , Jia-Ju Bai Cc: linux-nfs@vger.kernel.org Subject: [PATCH] NFSv4: Fix locking in pnfs_generic_recover_commit_reqs Date: Tue, 14 Aug 2018 17:25:37 -0400 Message-Id: <20180814212537.76245-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The use of the inode->i_lock was converted to a mutex, but we forgot to remove the old inode unlock/lock() pair that allowed the layout segment to be put inside the loop. Reported-by: Jia-Ju Bai Fixes: e824f99adaaf1 ("NFSv4: Use a mutex to protect the per-inode commit...") Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Trond Myklebust --- fs/nfs/pnfs_nfs.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c index 32ba2d471853..d5e4d3cd8c7f 100644 --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -61,7 +61,7 @@ EXPORT_SYMBOL_GPL(pnfs_generic_commit_release); /* The generic layer is about to remove the req from the commit list. * If this will make the bucket empty, it will need to put the lseg reference. - * Note this must be called holding i_lock + * Note this must be called holding nfsi->commit_mutex */ void pnfs_generic_clear_request_commit(struct nfs_page *req, @@ -149,9 +149,7 @@ void pnfs_generic_recover_commit_reqs(struct list_head *dst, if (list_empty(&b->written)) { freeme = b->wlseg; b->wlseg = NULL; - spin_unlock(&cinfo->inode->i_lock); pnfs_put_lseg(freeme); - spin_lock(&cinfo->inode->i_lock); goto restart; } } @@ -167,7 +165,7 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx) LIST_HEAD(pages); int i; - spin_lock(&cinfo->inode->i_lock); + mutex_lock(&NFS_I(cinfo->inode)->commit_mutex); for (i = idx; i < fl_cinfo->nbuckets; i++) { bucket = &fl_cinfo->buckets[i]; if (list_empty(&bucket->committing)) @@ -177,12 +175,12 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx) list_for_each(pos, &bucket->committing) cinfo->ds->ncommitting--; list_splice_init(&bucket->committing, &pages); - spin_unlock(&cinfo->inode->i_lock); + mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex); nfs_retry_commit(&pages, freeme, cinfo, i); pnfs_put_lseg(freeme); - spin_lock(&cinfo->inode->i_lock); + mutex_lock(&NFS_I(cinfo->inode)->commit_mutex); } - spin_unlock(&cinfo->inode->i_lock); + mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex); } static unsigned int @@ -222,13 +220,13 @@ void pnfs_fetch_commit_bucket_list(struct list_head *pages, struct list_head *pos; bucket = &cinfo->ds->buckets[data->ds_commit_index]; - spin_lock(&cinfo->inode->i_lock); + mutex_lock(&NFS_I(cinfo->inode)->commit_mutex); list_for_each(pos, &bucket->committing) cinfo->ds->ncommitting--; list_splice_init(&bucket->committing, pages); data->lseg = bucket->clseg; bucket->clseg = NULL; - spin_unlock(&cinfo->inode->i_lock); + mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex); }