Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp663486yba; Wed, 24 Apr 2019 07:40:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwi1HWlNj7i0x7vVwg49BFa10OIYKDv1Q+Uh7bO21dxyfzWb3GBGQutDD4oFA006+mRP9oN X-Received: by 2002:aa7:9888:: with SMTP id r8mr33893353pfl.116.1556116800222; Wed, 24 Apr 2019 07:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556116800; cv=none; d=google.com; s=arc-20160816; b=OoqbtkENe29MxKNfpG01zoX1wc+DOJj+aZN5bhW3EDQLE8EoGg8d8pvd3cDCC8PIPr S+4mjq9MLqRsetDJP5pkXudno6jDyYTQGTivixEewmTVqJmqLfYmaPODBfcS9m8WEGSN bZr3U+u8oHUkJ8cn+mEKBg8jwH3X0Nbc2BEvFQhiFM7vGTqeTpRUX5XbcUAOaDtP98Jf QH8imrX6Zci1VWhQ6tcSrSsJ0wfepSbE4oI64VuvZQsomTr7YtPsU5IPFTpCGNZNlqXj /F6FivQ6fMSi2Cq4tpOeXnujddxRZAkx/dUSBTDYW426J6NJBcSKKBp3mOfbI5QXiXmF eHyQ== 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 :dkim-signature; bh=U5I1x5Rt6IA1uyb3qpcSQK4yq7MsvQ0nzkXRPHSbDsU=; b=Iddk61q4G+hVXxwBq0HgFAnUWdSSzgqyxG07bfBi+fo1coPGLUEIFpsEOuIr9J4DAP 9smc2PaRmqlkIzceIeW0ggc2xu0Gfe/efe+aRF6OGX2HjbCjPBMFMhQnqv9DWdksZ9f6 GO+KdsW4RoIAm8KDk2/TzIP8lHvCAxM8AdFiyZG8q7jUmkTJx5ben8IQBl89bkZArpR9 3QeaLLuegEzp1WJxv+vRDP4JcaOpQ/j1Wcffq1xcAZ7yzrM4jwPdWNbrRfqw9FwscOuE 3fRd2DzR1mbpqIuQuCSTOLU7SSTyTvmGIYqpNlH/dVn7RlvvlxVNggyXYLnusCoXZyRR zOYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z1HEoxMc; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si17473024pgi.372.2019.04.24.07.39.44; Wed, 24 Apr 2019 07:40:00 -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=@kernel.org header.s=default header.b=z1HEoxMc; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731663AbfDXOgt (ORCPT + 99 others); Wed, 24 Apr 2019 10:36:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:40374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731629AbfDXOgo (ORCPT ); Wed, 24 Apr 2019 10:36:44 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4828C21901; Wed, 24 Apr 2019 14:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556116603; bh=2ZLr2MBeGEAcRLUr9ojdOI8LqgkgqlZeQZAwNzN+EiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z1HEoxMc31JooNzXPYUv+XjhX9PeaLRDKIH8+Ko62gRpfPHkj79ocL/sjjr2HqhEQ KXPKCoP1uF4tUOtr7zOhBiGYjDQlotSW6fKLd2g7i110iX9kQeX26wNKiqSyeVwMca de1OQVvh+65JDBCo7NQkUHbhNNnVEEj3jCwLW5J8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , Sasha Levin , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 65/66] aio: store event at final iocb_put() Date: Wed, 24 Apr 2019 10:33:39 -0400 Message-Id: <20190424143341.27665-65-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190424143341.27665-1-sashal@kernel.org> References: <20190424143341.27665-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 2bb874c0d873d13bd9b9b9c6d7b7c4edab18c8b4 ] 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 Signed-off-by: Sasha Levin --- fs/aio.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 387b224217b5..82bf5dffb272 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1077,16 +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); -} - /* 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; @@ -1094,8 +1088,6 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2) unsigned tail, pos, head; unsigned long flags; - iocb->ki_res.res = res; - iocb->ki_res.res2 = res2; /* * Add a completion event to the ring buffer. Must be done holding * ctx->completion_lock to prevent other code from messing with the tail @@ -1161,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 @@ -1435,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) @@ -1583,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, @@ -1608,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.19.1