From patchwork Mon Jan 22 20:12:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 864439 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="aSoQ20rM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zQNLt2sF9z9ryT for ; Tue, 23 Jan 2018 07:29:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751372AbeAVUNH (ORCPT ); Mon, 22 Jan 2018 15:13:07 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:47763 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751183AbeAVUNE (ORCPT ); Mon, 22 Jan 2018 15:13:04 -0500 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=+OscGvwgjFUHOhoyIFP8WWrYqikRxItnc4nituNAmcM=; b=aSoQ20rMZ4655qZAzdggDEO51 6VukM3eNqpSXx2z57mTOkdpUV00ZS6Uzmz39OBWwfzGAi1VkHRSsaPXHvMaWvhiZcsYqqH2hSelSg ieIcyMfkYWbdWKsLpEuxKUHWJ1NNL7V9KBftxvZSUtntoDZLl+Cr46l72U2yehkHt7KQ+uC/3OLa/ bLDoEDzrw8eXk53UeHJvU96GGPVZcA1wrAcevEXnffn6wzhEVssfM4ZkERABs/wgG6onDN2rEyMUF A5jVS+9ZOtthj/JlnSg8TCCFTbFGAT3YXUQ5mcUer51tEsIsnFVSPTK8AUe7tTN5Kd0z1WyP49SUQ PuTvbqgIA==; Received: from 178.114.226.247.wireless.dyn.drei.com ([178.114.226.247] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ediSk-0007WP-PH; Mon, 22 Jan 2018 20:13:03 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/36] aio: simplify cancellation Date: Mon, 22 Jan 2018 21:12:12 +0100 Message-Id: <20180122201243.31610-6-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180122201243.31610-1-hch@lst.de> References: <20180122201243.31610-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With the current aio code there is no need for the magic KIOCB_CANCELLED value, as a cancelation just kicks the driver to queue the completion ASAP, with all actual completion handling done in another thread. Given that both the completion path and cancelation take the context lock there is no need for magic cmpxchg loops either. Signed-off-by: Christoph Hellwig Acked-by: Jeff Moyer --- fs/aio.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index c32c315f05b5..2d40cf5dd4ec 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -156,19 +156,6 @@ struct kioctx { unsigned id; }; -/* - * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either - * cancelled or completed (this makes a certain amount of sense because - * successful cancellation - io_cancel() - does deliver the completion to - * userspace). - * - * And since most things don't implement kiocb cancellation and we'd really like - * kiocb completion to be lockless when possible, we use ki_cancel to - * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED - * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel(). - */ -#define KIOCB_CANCELLED ((void *) (~0ULL)) - struct aio_kiocb { union { struct kiocb rw; @@ -565,24 +552,18 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel) } EXPORT_SYMBOL(kiocb_set_cancel_fn); +/* + * Only cancel if there ws a ki_cancel function to start with, and we + * are the one how managed to clear it (to protect against simulatinious + * cancel calls). + */ static int kiocb_cancel(struct aio_kiocb *kiocb) { - kiocb_cancel_fn *old, *cancel; - - /* - * Don't want to set kiocb->ki_cancel = KIOCB_CANCELLED unless it - * actually has a cancel function, hence the cmpxchg() - */ - - cancel = READ_ONCE(kiocb->ki_cancel); - do { - if (!cancel || cancel == KIOCB_CANCELLED) - return -EINVAL; - - old = cancel; - cancel = cmpxchg(&kiocb->ki_cancel, old, KIOCB_CANCELLED); - } while (cancel != old); + kiocb_cancel_fn *cancel = kiocb->ki_cancel; + if (!cancel) + return -EINVAL; + kiocb->ki_cancel = NULL; return cancel(&kiocb->rw); }