From patchwork Wed Sep 26 21:01:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10616829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A021D15A6 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 928602B870 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90F642B86C; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1832F2B879 for ; Wed, 26 Sep 2018 21:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727124AbeI0DQk (ORCPT ); Wed, 26 Sep 2018 23:16:40 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:44823 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbeI0DQk (ORCPT ); Wed, 26 Sep 2018 23:16:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=IF2qX/VHgwfR5z/Fh0rti5j8s+5Wa+vP3yUmJLbaJ14=; b=QQ8HtB4T0V/5 GOqkrUxbdoC/YjC4RCU/TVsjMfCnYTtLBwWhCqzhGJ0ToWm7DDpcjnF5ehjo0ZToXdZEY7yLvFAKm qE7tN+LEOa9xpEpgb4vzPQSWi4PwADnTxsj1wx1VWxjKFqRPMbuKY9IsUvvp1Ti4uWFM9XeNRbXhy 3+b2qOUL4EvEpaysxxJ4XhuklO1AOrRL5wo+DeRMlcWJS9H5S+yWfw/pdUJOMCZWUe6QrBgolqTUO rjIHWodKmvCDKn2GzV/CPWuwGllSmLteHQGDbPdWST7b1JEhusIL+2amvx6R3yBirlhv/fW64dZWA 863RlqKGb8TmhXEwMNYWyg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g5GwG-000Chy-Qe; Wed, 26 Sep 2018 23:01:41 +0200 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 39A98C070B; Wed, 26 Sep 2018 23:01:28 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v11 5/8] percpu-refcount: Introduce percpu_ref_resurrect() Date: Wed, 26 Sep 2018 14:01:07 -0700 Message-Id: <20180926210110.20362-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20180926210110.20362-1-bvanassche@acm.org> References: <20180926210110.20362-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00930287330497) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5sTkyRxkXLtrs6iLERTcNJV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMzOveuRed9T7jhw/gvmQMah2BgHj1qqhphqeY tp8kfYc/OC96MFmLMn3a2CpBH+gVn+aqqhGehaqtjJG3CJ2yQxgb4qHU7qdjHk+p65BWNojnx8ye plRO3sLIqUlSH7OGvdxBh33r2iOnQNRiYFbeuI/apDCv4F6+gjF5H/I+cgmEcU1f8H19rtY8rZ5d 9L6w6J2bQL19VsxDRzkjBksh9sU0mfwm4D7Y6hdTgZY2kGtYIRYrgwmNBHQ/PlvDLtE2X4Lmr1Eh eh1oAvdyPjNZzZkHtDUeNUPQBvuvTgeocAejtRu5bPC8zl5GPOV9RgMxYWA4ryBb6FrOHzigF4y0 YSOV7QtxJNU+igS6jZCzGqp4kWEmSuvVokrtS84c/atNgYaek/ieoycx5b/lM6HtBzqsOfS1M5Vy YnCojwm7ad63wOzweEy7wCy4L5c/QhZ1rKEHWRD4jzLpim6oa19OKIalL4LoE8AgSzw+KJWjcRvn 9G9MXx3ddMlEc1je9VmHE1+Q9DR4YbQGRn/SCFVSMcnBwnfP7vEWuFdTNkRGVKAamUdylUIKhf3z 2GAHxH7IGHvMFS9R5GM5ovW4ogvVUp7MRJS/jV5z2CK2GM2WgFNgOzqC6O9vDGfG0JRx6xblTX5z omQNzPsffpxoygoK9pWfl7pZaq2OSE6KmBLM5Hfxb5tGDl/EOfj7AjBtUminERWeKKG4PAQYNyav p7c49FtiVj2dQIdtpWb9DGpHRP1rFy3c7RPTULYRp5fhF+0VbDpbQ5kQMtyxYtYunIjNerY1bFNu qLdtH2eYxHCMBe9y2DNwOgV373pfDhBQ21Od6Pt9Zuh5sUny4SJzXtd/yv52d5ii37lsoiY4WlOu gNPAUNUBeQhuaAL6LSHgXSKR50oTLts/mAi3bdTt+kCc099R/pB2d6wxTH4NIgbaz2LZtslouRgY aQdXViPmaVJWcESf3l4QIqLeDGPNdpzYInX9F8/OraGqi3c39Zt9mfMSWy9Woxn8mOOntMfLY7+D hYot+jIbIy+j2P+LZ+1+Cg== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function will be used in a later patch to switch the struct request_queue q_usage_counter from killed back to live. In contrast to percpu_ref_reinit(), this new function does not require that the refcount is zero. Signed-off-by: Bart Van Assche Acked-by: Tejun Heo Reviewed-by: Ming Lei Cc: Christoph Hellwig Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn --- include/linux/percpu-refcount.h | 1 + lib/percpu-refcount.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 009cdf3d65b6..b297cd1cd4f1 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -108,6 +108,7 @@ void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref); void percpu_ref_switch_to_percpu(struct percpu_ref *ref); void percpu_ref_kill_and_confirm(struct percpu_ref *ref, percpu_ref_func_t *confirm_kill); +void percpu_ref_resurrect(struct percpu_ref *ref); void percpu_ref_reinit(struct percpu_ref *ref); /** diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c index 9f96fa7bc000..de10b8c0bff6 100644 --- a/lib/percpu-refcount.c +++ b/lib/percpu-refcount.c @@ -356,11 +356,35 @@ EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm); */ void percpu_ref_reinit(struct percpu_ref *ref) { + WARN_ON_ONCE(!percpu_ref_is_zero(ref)); + + percpu_ref_resurrect(ref); +} +EXPORT_SYMBOL_GPL(percpu_ref_reinit); + +/** + * percpu_ref_resurrect - modify a percpu refcount from dead to live + * @ref: perpcu_ref to resurrect + * + * Modify @ref so that it's in the same state as before percpu_ref_kill() was + * called. @ref must be dead but must not yet have exited. + * + * If @ref->release() frees @ref then the caller is responsible for + * guaranteeing that @ref->release() does not get called while this + * function is in progress. + * + * Note that percpu_ref_tryget[_live]() are safe to perform on @ref while + * this function is in progress. + */ +void percpu_ref_resurrect(struct percpu_ref *ref) +{ + unsigned long __percpu *percpu_count; unsigned long flags; spin_lock_irqsave(&percpu_ref_switch_lock, flags); - WARN_ON_ONCE(!percpu_ref_is_zero(ref)); + WARN_ON_ONCE(!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)); + WARN_ON_ONCE(__ref_is_percpu(ref, &percpu_count)); ref->percpu_count_ptr &= ~__PERCPU_REF_DEAD; percpu_ref_get(ref); @@ -368,4 +392,4 @@ void percpu_ref_reinit(struct percpu_ref *ref) spin_unlock_irqrestore(&percpu_ref_switch_lock, flags); } -EXPORT_SYMBOL_GPL(percpu_ref_reinit); +EXPORT_SYMBOL_GPL(percpu_ref_resurrect);