From patchwork Thu Aug 3 13:45:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9879139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C04960360 for ; Thu, 3 Aug 2017 13:45:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2148128830 for ; Thu, 3 Aug 2017 13:45:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1651E28902; Thu, 3 Aug 2017 13:45:54 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 BAF3628830 for ; Thu, 3 Aug 2017 13:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751877AbdHCNpp (ORCPT ); Thu, 3 Aug 2017 09:45:45 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:36506 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751700AbdHCNpm (ORCPT ); Thu, 3 Aug 2017 09:45:42 -0400 Received: by mail-it0-f68.google.com with SMTP id r9so1312996ita.3 for ; Thu, 03 Aug 2017 06:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=XSa6da0Z0XBL0cI2SUHPMVzUg6BfjEgxljjS14+8x+A=; b=AaEP1HAXVekKE8saFPGo90Pp+et0fI0SGXll67/pz7KGI7VcIkOf0DPJxihBnTQ9W0 4cP2hno59kcVyDklmxnc25swqUByK+BYk0jheecOXa1qCo1JGgC29WA3m+pjibMNKtQN d8MDI9tjCk85J63d09vb5+h7vlcUpcunSYYFd2EXwl1w81bEi4Un1kDaN0SD8P57EM+p 9hP2LBgsmr7pmMO8YWGPu0C3FDxGMbVRzhQ0e/R21C9SvEr40OVzglXrI5zOf3Jj1GfX Q4/HYqKp66UOtqMa35J7IVKXM9tOoTscBZ4n8WpNT29efGpoRpvqBpwDOgzIeghOKnJL BZeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=XSa6da0Z0XBL0cI2SUHPMVzUg6BfjEgxljjS14+8x+A=; b=t2T6UDWZgId+HORrKY7B/+fhhC6KuQ1P6b5Sp3uL75yZIqlHEuReQdhbeDpIBYTrg1 1cDsmVp1gWH4FFHGMd5zOBL/Slo/WE4gB4dLaJKE3kB4AIxIvWvTf4M85GJsdffPM4W0 8Pke0hU0tBQEB6ZiEAIufFLGOVw858UY6FwDjm3rbxCBaIYDBfRI2pKd1al56dVWk/0J dV56Mar9mzp+DGSwJAY1Aid81r3PZKfRxrtZsToNBJW1IiuVDEzJogasDPAs6Y9/Mbok PGoHnnK/Kj9RQqPjA59NpJTGy8P4rBbM+pK0mAKIm5kgo+dWf2I7YtpdoezDFqyYMZfW rS8A== X-Gm-Message-State: AIVw111Zdd+s311YieRw5jD+bOAiRgVkPS64cEtxvbT/lHQ9AEOQvne2 jYi3zkZmRiH6pA== X-Received: by 10.36.89.140 with SMTP id p134mr1863807itb.20.1501767942183; Thu, 03 Aug 2017 06:45:42 -0700 (PDT) Received: from localhost.localdomain (50-108-95-251.adr01.mskg.mi.frontiernet.net. [50.108.95.251]) by smtp.gmail.com with ESMTPSA id q90sm5759547ioi.41.2017.08.03.06.45.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2017 06:45:41 -0700 (PDT) From: Trond Myklebust To: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH v2 07/28] NFS: Don't check request offset and size without holding a lock Date: Thu, 3 Aug 2017 09:45:02 -0400 Message-Id: <20170803134523.4922-8-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170803134523.4922-7-trond.myklebust@primarydata.com> References: <20170803134523.4922-1-trond.myklebust@primarydata.com> <20170803134523.4922-2-trond.myklebust@primarydata.com> <20170803134523.4922-3-trond.myklebust@primarydata.com> <20170803134523.4922-4-trond.myklebust@primarydata.com> <20170803134523.4922-5-trond.myklebust@primarydata.com> <20170803134523.4922-6-trond.myklebust@primarydata.com> <20170803134523.4922-7-trond.myklebust@primarydata.com> 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 Request offsets and sizes are not guaranteed to be stable unless you are holding the request locked. Signed-off-by: Trond Myklebust --- fs/nfs/write.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/nfs/write.c b/fs/nfs/write.c index c940e615f5dc..84b6818e5278 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -523,6 +523,17 @@ nfs_lock_and_join_requests(struct page *page) total_bytes = head->wb_bytes; for (subreq = head->wb_this_page; subreq != head; subreq = subreq->wb_this_page) { + if (!nfs_lock_request(subreq)) { + /* releases page group bit lock and + * inode spin lock and all references */ + ret = nfs_unroll_locks_and_wait(inode, head, + subreq); + + if (ret == 0) + goto try_again; + + return ERR_PTR(ret); + } /* * Subrequests are always contiguous, non overlapping * and in order - but may be repeated (mirrored writes). @@ -533,21 +544,10 @@ nfs_lock_and_join_requests(struct page *page) } else if (WARN_ON_ONCE(subreq->wb_offset < head->wb_offset || ((subreq->wb_offset + subreq->wb_bytes) > (head->wb_offset + total_bytes)))) { + nfs_unlock_request(subreq); nfs_unroll_locks_and_wait(inode, head, subreq); return ERR_PTR(-EIO); } - - if (!nfs_lock_request(subreq)) { - /* releases page group bit lock and - * inode spin lock and all references */ - ret = nfs_unroll_locks_and_wait(inode, head, - subreq); - - if (ret == 0) - goto try_again; - - return ERR_PTR(ret); - } } /* Now that all requests are locked, make sure they aren't on any list.