Received: by 10.223.148.5 with SMTP id 5csp6282482wrq; Wed, 17 Jan 2018 11:42:27 -0800 (PST) X-Google-Smtp-Source: ACJfBouT7SISFECYzZRkTsjnSuoHR4F4rcAnnIQzNvgH/wodC8NHeAlDGHsubT8y4XvOaR5N0TU/ X-Received: by 10.84.133.131 with SMTP id f3mr43453444plf.280.1516218147532; Wed, 17 Jan 2018 11:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516218147; cv=none; d=google.com; s=arc-20160816; b=XSksqJXIINuyPrhICLnisg7wDcXZiVOZz+LokiN+p0F05yB0TCChVQ+gAiud0gT5Wb 6pnj4TRVECbk/lKW85q8GB6CswQ3Xjs5HMJfzp8k+9EXKS5zJbVpR35tHQrYTy/HqCPf TIEQfuuCGb0Sc3LCIFcFqRCHsBczGhlqHXXNhtaEl35djg2yYJp2IBvZ6yiiTgdnak0b SGBW7pc4esfOnltUO35jMJoW0oUnWFtrf+Zw7z1RlSurMqjDxnhGFfUmYC5be3bWWili zsOV8pxrkiLm1KSLS/OMAXqM7SB9t4xi42oPQnTgYYbQdJpEF0neAc6yqpdDMgLXKAsT OTgQ== 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=m4Ne6RBUjKzZ5OLdBQjJ/47VP7U7QyzRCNWM04Hm459zSQL8pm3QGghbVONQefSnCx aTZt4gXtc30p0u2YeeISgCmsu3/EsqzTAcszW/TTYTqYcEg6g/SP4WuRseyExdYAHIRo Pxkzlmr6/wSKZ69y/820GPWKh07Jbxa88SuLGoihxxl8qJcYjjmBmGCOIeTo+gVdBbgI 31nVitEyHvdZqwP3YgHe3SRe5FDv7AInNVISLwUe22AR9V5PCPWX5K5CPt0FwEr/ymk7 Kvr6CE5t8GaB7+fwKVY8q98aHrk5wqHCDVrchB/UtXml99XuZgkOlAmSoLIx4CoO8/+f aa0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=N2XZvoGR; 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 y24si4967305pfa.194.2018.01.17.11.42.13; Wed, 17 Jan 2018 11:42:27 -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=N2XZvoGR; 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 S1753163AbeAQT2H (ORCPT + 99 others); Wed, 17 Jan 2018 14:28:07 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:50225 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753117AbeAQT2E (ORCPT ); Wed, 17 Jan 2018 14:28: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=N2XZvoGRWPslbaJGKkNks9zYO ogvmDqmZtkS0nxv30755YKX33D8jNl1+NCvCddB7NMaqNPA64/1UQwHH8eXGM1n7W/+SpHHiImtve TnI73bugnnE81KN24cadi7nbfux8dLyZvfGmE2MX/Hagg62kuT21uC6efCNJfdj/5iHlyklxjDiTx uVTr8phXWT/uQbpnquRL5ENwPiDDRN6vvFroKrxLo5BGEECsrICn5/rFIY4qUxZRlGoaGHICZ//P/ g7VT2aeZ6pCLR4oAXrHu8IiVOYDGJcka8eU7MVIBRM6SbItufcVV5MFzO8C3Z6s3QNG9i5IvPCSX0 TxA6cK+Fw==; Received: from 77.117.185.35.wireless.dyn.drei.com ([77.117.185.35] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ebtNS-0002yS-5z; Wed, 17 Jan 2018 19:28:02 +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: Wed, 17 Jan 2018 20:27:11 +0100 Message-Id: <20180117192742.710-6-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180117192742.710-1-hch@lst.de> References: <20180117192742.710-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