Received: by 10.192.165.148 with SMTP id m20csp1105837imm; Wed, 2 May 2018 14:16:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrzEGDprKNIAa+ydPQvxicTgVn8c9gUTYBfXq6p3dRpoZbhtAmliiHXjFfCQNaIKD9DRgnl X-Received: by 2002:a63:8f16:: with SMTP id n22-v6mr16770525pgd.394.1525295798189; Wed, 02 May 2018 14:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525295798; cv=none; d=google.com; s=arc-20160816; b=CZM/7NYVf4bhvJd4yzbT4U05uB6BIzuVPaX5UJws6dfuI5i3+PIGl2Y1q3PBsVEo+/ aE1ORHiw2D351+IF/ZIFhFYId2uUcuCCXJRV3Gu1CI7LAgV8TowVlZ7cJZzc3VrK39TQ XFYTBjZ2RDh0Uby14qhz/CikueSq6RnEvmXyWb+v7UpcTJ3YFuS4L1LfsxrB0OuKtMcK 7E/sU9B9c18kiWiGtNGe28eaIE/+Hyi4BVrs3md8dGN1nCIb0vhMKYyZnneycd97DCZh uQT2DC9UdLl3F/UpRCucRCgkHbb5P+YunQLM7vxa2bswbUrL6SL7WaLNsGX49/kzkpCi rzvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=lmt3/VL6ZrF+0WvW5HjyVc4HztUB81w2cvRyx2+XBmg=; b=YwQfd6EBVnoTQURMKtKZg1AfePKInDlOS8ZpWcZl+fStRN9XdkzYfISkugLWrr1RGy TY32FSD+xwiqZHFTl7e8z2ufevyRCmNn+nayFKFnZiIwqVD/8en26h0tSCmf4L7XWpYr rNzzq/r6t4LpsgnCRzfeffhEYdsrDXJMq3iiP5KtJNj2qWSBAhQk8/71t9FEySl4PdG6 Y5cs9i+vIVfyuR/CW5NSnaZBGG+DYPatr9v6xu4sT+fwA1Ehy0PhSiBN8bxzwF6IEFUk vY/P3N4HbR7T8hcpzjwCIihTLjaQmG3W8XRghpi7atwnVLFvI51mfLwWJzaFHZ6JYMk9 4LjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TKzIE9lv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1-v6si12109883pld.168.2018.05.02.14.16.23; Wed, 02 May 2018 14:16:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TKzIE9lv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751802AbeEBVPQ (ORCPT + 99 others); Wed, 2 May 2018 17:15:16 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37880 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751594AbeEBVPL (ORCPT ); Wed, 2 May 2018 17:15:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lmt3/VL6ZrF+0WvW5HjyVc4HztUB81w2cvRyx2+XBmg=; b=TKzIE9lvGVTcMozn197VWw+Qe IOebXUKNg8vMUTgRfIB0J1idVqLvq52bsJTurtB6meeLNLxosvz1ansheaE7jnalN804yTQCxlBjW qDDc9bBQAcguLxUC0p+NizlnH3LcMTMeHmDQ9LNoZntjV5CeXenKtjrApfQlxN20sGrX5y0x8Xz4x qXpeKrh3rSdAshEm+c/l60nR06oUoIiYtml8YvGwz58ygLgU5y4a6uC/NxfT8RFhPlCFuQ9JupSBo YcbkbZ2ZxOSo+0Ac0RXykF1VJbBtnhrQYcNrbt2z88ho/gVAJMbSjmfhW7TWgHqkSN7GgS0Zvmsfd kgM1H8Wqw==; Received: from 089144213252.atnat0022.highway.a1.net ([89.144.213.252] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fDz5g-0007Ol-P1; Wed, 02 May 2018 21:15:09 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] aio: remove the extra get_file/fput pair in io_submit_one Date: Wed, 2 May 2018 23:14:45 +0200 Message-Id: <20180502211448.18276-5-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180502211448.18276-1-hch@lst.de> References: <20180502211448.18276-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we release the lockdep write protection token before calling into ->write_iter and thus never access the file pointer after an -EIOCBQUEUED return from ->write_iter or ->read_iter we don't need this extra reference. Signed-off-by: Christoph Hellwig --- fs/aio.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 18507743757a..e5866e2fc331 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1515,16 +1515,19 @@ static ssize_t aio_write(struct kiocb *req, struct iocb *iocb, bool vectored, return ret; ret = rw_verify_area(WRITE, file, &req->ki_pos, iov_iter_count(&iter)); if (!ret) { - req->ki_flags |= IOCB_WRITE; - file_start_write(file); - ret = aio_ret(req, call_write_iter(file, req, &iter)); /* - * We release freeze protection in aio_complete(). Fool lockdep - * by telling it the lock got released so that it doesn't - * complain about held lock when we return to userspace. + * Open-code file_start_write here to grab freeze protection, + * which will be released by another thread in aio_complete(). + * Fool lockdep by telling it the lock got released so that it + * doesn't complain about the held lock when we return to + * userspace. */ - if (S_ISREG(file_inode(file)->i_mode)) + if (S_ISREG(file_inode(file)->i_mode)) { + __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true); __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE); + } + req->ki_flags |= IOCB_WRITE; + ret = aio_ret(req, call_write_iter(file, req, &iter)); } kfree(iovec); return ret; @@ -1599,7 +1602,6 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, req->ki_user_iocb = user_iocb; req->ki_user_data = iocb->aio_data; - get_file(file); switch (iocb->aio_lio_opcode) { case IOCB_CMD_PREAD: ret = aio_read(&req->common, iocb, false, compat); @@ -1618,8 +1620,13 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, ret = -EINVAL; break; } - fput(file); + /* + * If ret is -EIOCBQUEUED, ownership of the file reference acquired + * above passed to the file system, which at this point might have + * dropped the reference, so we must be careful to not reference it + * once we have called into the file system. + */ if (ret && ret != -EIOCBQUEUED) goto out_put_req; return 0; -- 2.17.0