Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp116413imc; Sat, 9 Mar 2019 23:11:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxiNHDZcaXnqNsgH6i9uYx7Jk9ycjTDqx2DLv2dz8CrteCwj8TccUseC0RMDM0ZRzxa5Ttu X-Received: by 2002:a62:f598:: with SMTP id b24mr27027782pfm.72.1552201888471; Sat, 09 Mar 2019 23:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552201888; cv=none; d=google.com; s=arc-20160816; b=Biwp3scCdrcucgz+y+b3FOiB0xjTHQu28C5Y6A/EPaeJvUhEAzOFUeHPXzE4o1GEj2 Hvz17FLePnlGIraQwxYyiGs+Fg5SyARj57yAKeuq3kn+zuzgYNlyJUgXfZHSBHbSFZyV RKacUw7/n/UP6tUDoch18zJXJUKpBcynF259fXhpAYij/fi/+Z1NH3BZxHUEZZRT4Ruh /JliB/i72vOHJy5JMC3UCXXRoyzt1UZMKMg7W0BgRbsyjRSHrVbogTortUHaQTPdMfa5 OTyx50kjnIqXTt7s4yq3Cg7vEPt/OvFG+zuHcZkYjaXkssoHF6LyimPk0r/0kntz54sF K9Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rq2fwwF2sCIHj9W+Cv0bN151FzLjcImragWaeIQS/Bc=; b=V3KsnNBJ1h6wPVUBqvspWwQEjjSFabYzjbT7zC6qqFnyfinpo0ayUp/46A0HrCy+TZ GIO7MAM8sODbtY8sGCZfuaa+tVQ26UC3XCGyt1UFFh3mFNPmOgE/7neY7sxFKb5pkH7A P5Djm0DpxZgEvayhojzEeEB4CnJdi8LZF2N7mMKZD2ZyLk33kdV0+FRfEE9PjKFyRBTT t4c+l+S1QY5SiSUGGNJgY2sbIgrqqadXT+PVKN1n0Jy/e5+08bpHn3EcY57HgpZZKs1e SI+l5cPM044hgpwkntX+wyPvGYAjI8xY6P5pF4TeOfcUGA4KJAZQ/FdoPxYQ9kdsmivc XhXg== ARC-Authentication-Results: i=1; mx.google.com; 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 h10si2171429pgs.573.2019.03.09.23.11.12; Sat, 09 Mar 2019 23:11:28 -0800 (PST) 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; 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 S1726504AbfCJHKS (ORCPT + 99 others); Sun, 10 Mar 2019 03:10:18 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:35416 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfCJHKS (ORCPT ); Sun, 10 Mar 2019 03:10:18 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1h2sa6-000354-Hz; Sun, 10 Mar 2019 07:09:21 +0000 From: Al Viro To: Linus Torvalds Cc: Eric Dumazet , David Miller , Jason Baron , kgraul@linux.ibm.com, ktkhai@virtuozzo.com, kyeongdon.kim@lge.com, Linux List Kernel Mailing , Netdev , pabeni@redhat.com, syzkaller-bugs@googlegroups.com, xiyou.wangcong@gmail.com, Christoph Hellwig , zhengbin , bcrl@kvack.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, houtao1@huawei.com, yi.zhang@huawei.com Subject: [PATCH 3/8] aio: store event at final iocb_put() Date: Sun, 10 Mar 2019 07:08:17 +0000 Message-Id: <20190310070822.11564-3-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190310070822.11564-1-viro@ZenIV.linux.org.uk> References: <20190310070606.GA10138@ZenIV.linux.org.uk> <20190310070822.11564-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro Instead of having aio_complete() set ->ki_res.{res,res2}, do that explicitly in its callers, drop the reference (as aio_complete() used to do) and delay the rest until the final iocb_put(). Signed-off-by: Al Viro --- fs/aio.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 2249a7a1d6b3..b9c4c1894020 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1077,24 +1077,10 @@ static inline void iocb_destroy(struct aio_kiocb *iocb) kmem_cache_free(kiocb_cachep, iocb); } -static inline void iocb_put(struct aio_kiocb *iocb) -{ - if (refcount_dec_and_test(&iocb->ki_refcnt)) - iocb_destroy(iocb); -} - -static void aio_fill_event(struct io_event *ev, struct aio_kiocb *iocb, - long res, long res2) -{ - iocb->ki_res.res = res; - iocb->ki_res.res2 = res2; - *ev = iocb->ki_res; -} - /* aio_complete * Called when the io request on the given iocb is complete. */ -static void aio_complete(struct aio_kiocb *iocb, long res, long res2) +static void aio_complete(struct aio_kiocb *iocb) { struct kioctx *ctx = iocb->ki_ctx; struct aio_ring *ring; @@ -1118,14 +1104,14 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2) ev_page = kmap_atomic(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); event = ev_page + pos % AIO_EVENTS_PER_PAGE; - aio_fill_event(event, iocb, res, res2); + *event = iocb->ki_res; kunmap_atomic(ev_page); flush_dcache_page(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); - pr_debug("%p[%u]: %p: %p %Lx %lx %lx\n", + pr_debug("%p[%u]: %p: %p %Lx %Lx %Lx\n", ctx, tail, iocb, (void __user *)iocb->ki_res.obj, iocb->ki_res.data, - res, res2); + iocb->ki_res.res, iocb->ki_res.res2); /* after flagging the request as done, we * must never even look at it again @@ -1167,7 +1153,14 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2) if (waitqueue_active(&ctx->wait)) wake_up(&ctx->wait); - iocb_put(iocb); +} + +static inline void iocb_put(struct aio_kiocb *iocb) +{ + if (refcount_dec_and_test(&iocb->ki_refcnt)) { + aio_complete(iocb); + iocb_destroy(iocb); + } } /* aio_read_events_ring @@ -1441,7 +1434,9 @@ static void aio_complete_rw(struct kiocb *kiocb, long res, long res2) file_end_write(kiocb->ki_filp); } - aio_complete(iocb, res, res2); + iocb->ki_res.res = res; + iocb->ki_res.res2 = res2; + iocb_put(iocb); } static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) @@ -1589,11 +1584,10 @@ static ssize_t aio_write(struct kiocb *req, const struct iocb *iocb, static void aio_fsync_work(struct work_struct *work) { - struct fsync_iocb *req = container_of(work, struct fsync_iocb, work); - int ret; + struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); - ret = vfs_fsync(req->file, req->datasync); - aio_complete(container_of(req, struct aio_kiocb, fsync), ret, 0); + iocb->ki_res.res = vfs_fsync(iocb->fsync.file, iocb->fsync.datasync); + iocb_put(iocb); } static int aio_fsync(struct fsync_iocb *req, const struct iocb *iocb, @@ -1614,7 +1608,8 @@ static int aio_fsync(struct fsync_iocb *req, const struct iocb *iocb, static inline void aio_poll_complete(struct aio_kiocb *iocb, __poll_t mask) { - aio_complete(iocb, mangle_poll(mask), 0); + iocb->ki_res.res = mangle_poll(mask); + iocb_put(iocb); } static void aio_poll_complete_work(struct work_struct *work) -- 2.11.0