Received: by 10.223.176.46 with SMTP id f43csp3345144wra; Mon, 22 Jan 2018 12:30:38 -0800 (PST) X-Google-Smtp-Source: AH8x227PUTyw2n1SM8xBWXVzf4LpX6IYEARt7np0TiJg0saXOTg9xt6GKigfLJsvldlrw8/w8bFp X-Received: by 10.107.15.89 with SMTP id x86mr224405ioi.38.1516653038335; Mon, 22 Jan 2018 12:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516653038; cv=none; d=google.com; s=arc-20160816; b=0QvdwOoCJwqinE6pgbfCSF3pJ8k5YWOMXFcvc3e1kzwK5f5z8P++mj4hwn5EkTKTWv ccXob5vx6RCxx/IBegKr51h0qZHHdGP8Kig4IAsQd6sHju89iL0+JCIscJ4NrTnPH0KL p83NVA0vCBw7Krcj2K9kC61wPtEj4PipxXHBFMaPUn+uPMpMlefxwDPOWgQpUNupZ77Z rNo5SPgpzC0eTBEfY1t1azX5MO/P50Kvl4c8HeR4W6jXhRNh9Kk/kgnurx4EUYitFowO 8obmPNsdFndx9BQvqLzVvsKjKiG2WjCAF7st3872JbzvOoZ0zLY8JAhLRFq6or8Wp59u iFrg== 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=+OscGvwgjFUHOhoyIFP8WWrYqikRxItnc4nituNAmcM=; b=px+8qgqA6BGWcsYql7350H/97Y3kGB/psQoIhBc1FqQ+TONnKQySS76vQka2MSxewH IVzoboloCBgSlnhzamweCOJ8GmtRrOav0r/tJ1dG3KNpnpzVYiWCkmgRyO2JhY/frysw Brg9CT6gjcoIhcdESesr+M8sdGsjvydwnvwm/aMnk3VADTPtJRzIJn56CcGSG3ueFukq LY+G2daa25PY5sHnC1kFFZMLrug5K32Q3kvWroLeKB9HkOlz5gKYBPHHLKxJAcjJePQJ KmmK58gU/oSCt8F7cTqX2ym6fyjS2xz0bHEI2Cpy8q8arOLqrFR/h1Qf4gjhhnZjkJIo RDIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aSoQ20rM; 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 x4si6631887itg.87.2018.01.22.12.30.25; Mon, 22 Jan 2018 12:30:38 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aSoQ20rM; 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 S1751187AbeAVUNI (ORCPT + 99 others); Mon, 22 Jan 2018 15:13:08 -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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); } -- 2.14.2