Received: by 10.192.165.148 with SMTP id m20csp1143775imm; Wed, 2 May 2018 15:05:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo2NRkeR2e/stM+RwdzTyktoSEk3dEbKPwhVLYI58pXeBKKyLoNuEb9gM/HSfvNgqpeWD04 X-Received: by 10.98.201.92 with SMTP id k89mr20763832pfg.47.1525298735852; Wed, 02 May 2018 15:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525298735; cv=none; d=google.com; s=arc-20160816; b=wHUZ0CHSuwIoyhQ3Dw5411iiMExsX0gfzTmF6RrRpZHY/ly+oUTALXsTsLX6i0na47 ApYcx9I6qjzVhp2+KovOOCfMHfd57tS8kMna68jP4Y1Ly33M+QF80Ek24OChP+ttoR3t GGJypfThvxMN8HaL9Fm+Zjc4sBdD8bFacX/8SB/J0EukYUqpjMSrDZug4X38M5FAp9Hd pd/L98+opGSPz9kf9qYyucenvjlXz1QXpE7KP4vcyg8Xa1gK/WlD70f+7Dt7Ppc2X74u 9980DcYef5YGQHiikf9kBWxhOfGHmjGm0T2Gg5rwlci/cnwA8cFJfQMZZ5lLVtiQRkRv 1UzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=i62h6nzLbt9rN9Qg9xMe1JN/WD3Cs2AQJrIeQxbTVJo=; b=jT2vV48vBfKsQdHLGnCfyrZr2+u6IStkU+LIzrkOhbSSh8JRncv0CzlZk3p4Cm0s0J X+tKt+MJqoqXsw5sC7GlKHTWVFfzvj4zS2kRSKuJuEjiRJokq6FZblXZHRCW3EYyenlU 2m6ph5idm84xLA2ImknNeUykOLcsneamBRq70UisleL3EDjFRQdDc72L14WyU+7sQjmQ MO6F/5QDJvom/0QdRASVIvAszbogdh/DuR2qiZb2P9CIPRFPiplkfrAD+ADXEvYPzxp+ koEVAQwuDxuggTJmL3bwX6SbbVNK5kNMN8vaB5v31jC7dD7lKQ8JugmFchmS/kx2PLJa +M9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=vOLHhlu6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68-v6si12329315pla.452.2018.05.02.15.05.20; Wed, 02 May 2018 15:05:35 -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=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=vOLHhlu6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751432AbeEBWFJ (ORCPT + 99 others); Wed, 2 May 2018 18:05:09 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:54554 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148AbeEBWFG (ORCPT ); Wed, 2 May 2018 18:05:06 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w42M18PE023065; Wed, 2 May 2018 22:05:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=i62h6nzLbt9rN9Qg9xMe1JN/WD3Cs2AQJrIeQxbTVJo=; b=vOLHhlu6/TxSCA51VCGT0IJ40jyRieurTtjK3Y6mo/+2dR0jqkYB5zHujEcLsAzo1lrw gMhU8BfPW9ZAL98PWdKMMG8Lxj/X/QwKTzR1fgK+YFyPUN2vOyrv4WjgiiB+4VC6hvuM D+1ToDpQCgUczZqbm1Ck+7yv/LISqclCIEH63R6HIBGgtGnaS0N92e3zIkj0yvcL6vZ0 uyGi4yFpcKaQZGz8rSoGvy3/OgE/L027prvvkM3+XtcvhEMt19aa2qsIDczKfP8Fz0xH 2WrRC0UjJ3OKtSZ4on3oTk3y34NKLiVxFd99QaQ+gfO7bgSWy8d+3fLvw56pXKh4BLAs NQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2hmhmfq5f0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 May 2018 22:05:01 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w42M50Q5010869 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 May 2018 22:05:00 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w42M4x5i031268; Wed, 2 May 2018 22:04:59 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 May 2018 15:04:58 -0700 Date: Wed, 2 May 2018 15:04:57 -0700 From: "Darrick J. Wong" To: Christoph Hellwig Cc: viro@zeniv.linux.org.uk, Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/7] aio: remove the extra get_file/fput pair in io_submit_one Message-ID: <20180502220457.GB4116@magnolia> References: <20180502211448.18276-1-hch@lst.de> <20180502211448.18276-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180502211448.18276-5-hch@lst.de> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8881 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805020183 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 02, 2018 at 11:14:45PM +0200, Christoph Hellwig wrote: > 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 LGTM, Reviewed-by: Darrick J. Wong --D > --- > 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 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-api" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html