Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp97136imm; Thu, 21 Jun 2018 14:38:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ4rhGbSt8ISac40rEL5HSEe+YVyI5EePzW3vupbY64BysKI0hxu0Err9Hf7KHo88UD6ea0 X-Received: by 2002:a17:902:a5:: with SMTP id a34-v6mr30637015pla.80.1529617081883; Thu, 21 Jun 2018 14:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529617081; cv=none; d=google.com; s=arc-20160816; b=NcqJtDRXWip6lO4n2gdL0cIx9faWoLZVgdNOVaA4B33YBYuOJe2kB6omG5PEjcy1t4 QMz0LuJU7iofFso8u+dA7KZNfKOk19XWJxo0je78uPAUXkV8zGnrqTV7M1r3D3YvUJxS iSiBPL5D1qqyKTy0eFaSQWphkKAjXZQpfm+a0r7VfRMG8oCkGX1KngsYOaEQaW5rQUu+ 54jEniLwTZ4423k2Q6fXVuwWPOPwXQ585Ue24l9j1zTL0lckMKB3XgrDlnmlUWNuEhjO sa0wMSmYtuVLhCGtsPuRg/4xp9DYYGM1VtuAHunHNwJqeYV1FllgXSroAahe9A0M9q4r Qflg== 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=KA7I3lyTaAWE3lEhD4aIwohmIUjTSstkt8bvM8SVfWI=; b=z0/TqW6i4cT7ijJ4EBi9Bda4EeKZxbWehZy9C/KWaZm2GgADFvjRzsa7SXuLYk7Onk ZSjhk7eLM/b9nYWx1xt3AQZjokZBPEq7buM35eQU5vuSm+ZpyaqWsgi8VGvh3vkEJ2ow n9iTUJAbh2t1W8T2RdbnVAYcG527b4CTOOvS1EW8vtGQiIbFcWPIWcrQkUnY+sGsQ8O6 b+KmHPvMsYwvr63Cj7Cnsxy89lxhTm0ydVQwdkvsPoxM5XGjn8TBwfw43e89v6OYHkw0 BwT6mqo+10eJc7znL+iJVMoh7p9c5opWjmn3pWTg2TccZJdSnRIRKhBwBLiISBtqcNP3 pP1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=sTsAWKBz; 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 c14-v6si5706530pls.32.2018.06.21.14.37.46; Thu, 21 Jun 2018 14:38:01 -0700 (PDT) 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=sTsAWKBz; 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 S933915AbeFUV3G (ORCPT + 99 others); Thu, 21 Jun 2018 17:29:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41722 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933883AbeFUV3A (ORCPT ); Thu, 21 Jun 2018 17:29:00 -0400 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=KA7I3lyTaAWE3lEhD4aIwohmIUjTSstkt8bvM8SVfWI=; b=sTsAWKBzRlb6Fu4GhWV3JZPSh Eq/Ca82ma+LDT6gLuvI4wQyxT9MpjpBrfy/4SQHYhlVTkBzS1MDcHJf+6lE/uloycMCqci0CfJ37Y pEw/WmbNSn+OPkXmuPPwDQNEjJGz1i+KEp2Cxhzpvn3HbUcO4U4A38PG+v1/OT6yZHOGIKKV5TORn zv8diVkx8HBDgMWffZNMy9L5/ZyZmPKUJNdGun5TQzbT8IkccyqWNksNe41s4xQzH4PpAh9lLCZEw O5Vxo2Z9erz9ICobd8/iXJ6iliIiWkWGPlxToJFu4j+Y1gdx4yiHDCE3WP8mJzOGFWgwNrEHSZOmw O0EaLK0vw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78W-0001Zw-2b; Thu, 21 Jun 2018 21:29:00 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 02/26] ida: Lock the IDA in ida_destroy Date: Thu, 21 Jun 2018 14:28:11 -0700 Message-Id: <20180621212835.5636-3-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180621212835.5636-1-willy@infradead.org> References: <20180621212835.5636-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The user has no need to handle locking between ida_simple_get() and ida_simple_remove(). They shouldn't be forced to think about whether ida_destroy() might be called at the same time as any of their other IDA manipulation calls. Improve the documnetation while I'm in here. Signed-off-by: Matthew Wilcox --- lib/idr.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index ed9c169c12bd..352c6160e2e0 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -523,25 +523,30 @@ void ida_remove(struct ida *ida, int id) EXPORT_SYMBOL(ida_remove); /** - * ida_destroy - Free the contents of an ida - * @ida: ida handle + * ida_destroy() - Free all IDs. + * @ida: IDA handle. + * + * Calling this function frees all IDs and releases all resources used + * by an IDA. When this call returns, the IDA is empty and can be reused + * or freed. If the IDA is already empty, there is no need to call this + * function. * - * Calling this function releases all resources associated with an IDA. When - * this call returns, the IDA is empty and can be reused or freed. The caller - * should not allow ida_remove() or ida_get_new_above() to be called at the - * same time. + * Context: Any context. */ void ida_destroy(struct ida *ida) { + unsigned long flags; struct radix_tree_iter iter; void __rcu **slot; + xa_lock_irqsave(&ida->ida_rt, flags); radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) { struct ida_bitmap *bitmap = rcu_dereference_raw(*slot); if (!radix_tree_exception(bitmap)) kfree(bitmap); radix_tree_iter_delete(&ida->ida_rt, &iter, slot); } + xa_unlock_irqrestore(&ida->ida_rt, flags); } EXPORT_SYMBOL(ida_destroy); -- 2.17.1