From patchwork Fri Sep 21 20:31:19 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: 10610933 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 06523161F for ; Fri, 21 Sep 2018 20:32:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAB182E7A5 for ; Fri, 21 Sep 2018 20:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF432E7AF; Fri, 21 Sep 2018 20:31:59 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 74A032E7A5 for ; Fri, 21 Sep 2018 20:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391321AbeIVCWa (ORCPT ); Fri, 21 Sep 2018 22:22:30 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:59231 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391458AbeIVCW3 (ORCPT ); Fri, 21 Sep 2018 22:22:29 -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=8eYc2rooetW8HduPVK5h2VAHhWZ+Oi8ZO560YW3RI40=; b=axeqdIGKUxuw xaIS/ZhhhN1ZlftQG0bpKXjjspki1ijOGkSGL9aRT9j12r/yNh5Q7lmn9LT4FLSEpTdACc6pU8M+8 mRHrXPbP66tU2u75a2kbHBbK/zB/x08mI/xYG/jQrHRIcTdFOA0ISBI3YjnYq7tenfInwpNVIRMW/ GCbLzL0eMjysCvvyjsW3CS/MABZ+uHtjtX67c6dQ+VpPHIgKO318cSpMI+Bm9aZx59bUqHt7ii3pV 63XQ+aczwsf1I6IQpTR56ye0G3uUfVsHl7m70OyW9Iyda1/6ro6/9vdkEbRD+LjXAIHcahZIbITeM qW/nqz11cQsNQoC0XSX1sA==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g3S5d-0009bZ-4s; Fri, 21 Sep 2018 22:31:49 +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 2A48DC0606; Fri, 21 Sep 2018 22:31:47 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Tejun Heo , Ming Lei , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v10 5/8] percpu-refcount: Introduce percpu_ref_resurrect() Date: Fri, 21 Sep 2018 13:31:19 -0700 Message-Id: <20180921203122.49743-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-goog In-Reply-To: <20180921203122.49743-1-bvanassche@acm.org> References: <20180921203122.49743-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: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5papScuQ7M8dLlvgAyC6v69602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3pt2tN//3H9/wWWXAe+sSUKuV W+g/h+X/wE+f/VWrtIrYydu6jMWuxOnqJFfJZuKREtVYAQYChUJlUgsyzPIQ46EECwro3zJKIDOp vGlwxNdCe+ttlbX5S0h77Rb1GYQ9WqYyTEbp1JLX9PcB11V50H+1d8OrKid08UD63WgFM2yEpXgo 3xVDR6tJKBagpKSYhvq/zpsT+mHbGXDupgVIcG61atAN6WpHBZeLlJUoXWm7sd8DEzjodhBhiuze WOzlUl+/eA28u899zK3bYNr+5VWvx4/5aan/L8AHYrKyAYObgPMHR0rnmzS+sioy5Yi/Lz/dsiah Q1DFoGJGH4QvNG7YtPNqKsP0aFdkpj9AZtjLcvZ+ooy9Vd1tXjyRxtLgputPNQCJecAfiZxXXg4j EKmAwTrzmCHomMs24PzTKAo9gK7/ebDoJ006fIc/+3LKjy+GqD0CyO+ujAYv9eSRCQkWEBM1Tk3W R5RtK0GPYPTgXjN1oyoyf+XOu18QZ+nNXYMpXUEzSop3xLQFMERj/FAuwDgglDTccTZknGyWQ/ln IKDFkcg0DoDn7tP2jpvL5Y4qqCmr2XZpuOqaj0inQEQsE9GFfAmaUtylwv5ObK16EipRzMVZ5Lqw Tx7Vvn9SXZ9LAb9O8CjnL3fBzOKr2SmMi9OuktJZaj0gU5NIZ9/G3rl5ysqiVTrohuKoegxdSz5L Tx3mBi7x+q+bEjyaggeYUOp7A73HI6oJg7w/Vof+JwdldeFSqHUTxSftFFnR/k9WvB7/Q3Npaopz pr/OPHx0ZoMvEl302DtcDE7WwzuOayc6G7ZwS5T/OPOAbPSOMDRcCgYQIezXimM8MMGBqcA6tMAE meOYmq5g47VHl5vxSDqQNw7Dj0UnCw1XZdqSxAsDGo1RL4iGb+yv0605xG0rgVFyVz7ZgDW8hBGN EiOUAwtoYoFTPtITORPU5/QZYCWMwdah5mm+W+O8ASRl0ycHL8+lTGBIVE9xbEkX79vG5s5tNcGy 4AEm7z1nBo1ZU0apuRO8rDZ8GamXvfC7sB1/rxbQicf/5tMwo2bfwweDZBmEJGbJuieYD0lHb0sw KYmA9i9TPOOUTGSbKboeYqAOu0ktdhnp1d3xEIjvhIIxL7hrJSk60SF3F6RYOYr2 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 Cc: Tejun Heo Cc: Christoph Hellwig Cc: Ming Lei Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Acked-by: Tejun Heo --- 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..17fe3e996ddc 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 have be dead but not 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);