From patchwork Wed Nov 29 20:19:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842724 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="D+mPufOz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjt2SGwz9s4s for ; Thu, 30 Nov 2017 07:20:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752625AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:38232 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751960AbdK2UTg (ORCPT ); Wed, 29 Nov 2017 15:19:36 -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=NHyrnzfCNl/QF0GIbQwwtXtoilmj5dGggghRUHm2BzU=; b=D+mPufOzZQhAsLOWL4UTkcQEv vVPXu+qOLLlDsgAjy/6PoxpbInAKYfmNEVKZKojyfV7I9BDZYJlyHOWs78p4ca/4gEK1ncs3UvKEQ lm/9i5+zUoUujFub0/4GKOPO5ToxDDXL4x0dLw4IMKJ1/030iUF/fGRe6SaA5ueC2FAfdFuf3WdOF fTDWh6e61oMmvlfiJt8lwqiDVs1JIwoqjcHw6cd93IfAJ/Fg79gkTvq2kLFcY7rHj6XB129K0dlSb sVuPkI6F4zbUNrOrqqNA6Gd/nSjw7iwJdeffHUTnjUoR66WnBtcl/im0zXe3GQivb2yjg6ijMiafg 1IneR3H1A==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pT-0006Mv-Hl; Wed, 29 Nov 2017 20:19:35 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 01/17] idr: Fix build Date: Wed, 29 Nov 2017 12:19:06 -0800 Message-Id: <20171129201922.24370-2-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox The IDR calls WARN_ON without including Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/idr.h b/include/linux/idr.h index 7c3a365f7e12..dd048cf456b7 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -13,6 +13,7 @@ #define __IDR_H__ #include +#include #include #include From patchwork Wed Nov 29 20:19:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842714 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="E/CmGKYb"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBj36Hg8z9s4s for ; Thu, 30 Nov 2017 07:19:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752764AbdK2UTp (ORCPT ); Wed, 29 Nov 2017 15:19:45 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:40271 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752726AbdK2UTm (ORCPT ); Wed, 29 Nov 2017 15:19:42 -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=cqk51HHL3xIkODbBP4DI0HBDbpO0DXoww0tPWO6opTI=; b=E/CmGKYbi7Hp2K2FKA1qVkECe X7PKcEi1aI2ol/a+EY23uo2PSpn7flI6SBYhwZ+RW4kwyEBVUJtOkV2at5ay0/W9LDFWUDNjNI4TJ QhugQoQYJ5v1wekO/IWhYt7OQXaMWbaTrOQEbPtsQ1WotoPQUQE3gYq+lerEaVODA2TmT89CDXi9V 1WjHRr8pNBhljH26j+XVuC5SfqSmPB2cChp96Kwn/3SESuWl7ApG/brVbDrYYKnqGl42+ldHxvjHx txZ2yGh6Euko+nuPmhGGJ10HunhVK61HtMmIoZhN78sBZwqvNmklpGubZvl2ckAim1aja41LTSrfs ykwy619wg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pT-0006N6-JV; Wed, 29 Nov 2017 20:19:35 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 02/17] radix tree test suite: Remove ARRAY_SIZE Date: Wed, 29 Nov 2017 12:19:07 -0800 Message-Id: <20171129201922.24370-3-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox This is now defined in tools/include/linux/kernel.h, so our definition generates a warning. Signed-off-by: Matthew Wilcox --- tools/testing/radix-tree/linux/kernel.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h index c3bc3f364f68..426f32f28547 100644 --- a/tools/testing/radix-tree/linux/kernel.h +++ b/tools/testing/radix-tree/linux/kernel.h @@ -17,6 +17,4 @@ #define pr_debug printk #define pr_cont printk -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - #endif /* _KERNEL_H */ From patchwork Wed Nov 29 20:19:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842712 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="hptQFfCV"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBhs6LpCz9s4s for ; Thu, 30 Nov 2017 07:19:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752672AbdK2UTi (ORCPT ); Wed, 29 Nov 2017 15:19:38 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:36604 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752014AbdK2UTg (ORCPT ); Wed, 29 Nov 2017 15:19:36 -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=5nV2U2BAMRLtlis2JXAwmUYdacm2HNUBUpzdEHSIHX8=; b=hptQFfCVDae8EDnb5jtwuDnQu liBsNKc1LtTKQgG3lcS92isU19tu2dQTi33jkKb/h6pl8kuAFqGDuX/RKgKErsLK+JXa4fJUdgE1Z fYvKf2VWzYYOLDqVFi2fMAZk5arQm1RkEAQftAO0Du9zthjMUXn/dak0CTV4LTCtrzScQ8XZ3Fcn7 aGFdxvUBnfZ+Ws4BxxssRSC7jrKR2zPXnvL00bljKa8PNNQvtI+P1MsMjB0bCQ+zK0Rti9DkpH25R aCEMmZJfT4d/I2TWjRiVUQCTSoa2tFCVPVj5vVBWw1E49Pa74CN02pqsJp0AOMd8mMJ6ruPZ66Baf eXM4d/NzQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pT-0006NA-Lc; Wed, 29 Nov 2017 20:19:35 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 03/17] idr test suite: Fix ida_test_random() Date: Wed, 29 Nov 2017 12:19:08 -0800 Message-Id: <20171129201922.24370-4-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox The test was checking the wrong errno; ida_get_new_above() returns EAGAIN, not ENOMEM on memory allocation failure. Double the number of threads to increase the chance that we actually exercise this path during the test suite (it was a bit sporadic before). Signed-off-by: Matthew Wilcox --- tools/testing/radix-tree/idr-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c index 30cd0b296f1a..193450b29bf0 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -380,7 +380,7 @@ void ida_check_random(void) do { ida_pre_get(&ida, GFP_KERNEL); err = ida_get_new_above(&ida, bit, &id); - } while (err == -ENOMEM); + } while (err == -EAGAIN); assert(!err); assert(id == bit); } @@ -489,7 +489,7 @@ static void *ida_random_fn(void *arg) void ida_thread_tests(void) { - pthread_t threads[10]; + pthread_t threads[20]; int i; for (i = 0; i < ARRAY_SIZE(threads); i++) From patchwork Wed Nov 29 20:19:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842716 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Ln/hd5ge"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjB5kpmz9s4s for ; Thu, 30 Nov 2017 07:19:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752742AbdK2UTn (ORCPT ); Wed, 29 Nov 2017 15:19:43 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:59810 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752437AbdK2UTl (ORCPT ); Wed, 29 Nov 2017 15:19:41 -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=4gRlw2zD+wsOu65sd1Z6lC/glHCjImQSRYcebA0lytA=; b=Ln/hd5geC0964qaR2KqVNS3hn gy1IrNXauWRmUKD9Lp3v92vhEx0tVCCy6OwGaGrSHQGs7BUXm4K/rDCYaLDZnBxhe1DH7Q5BDCUSQ m58lmmEzCHdOZHS1to+Ote46I7blbGvuf7smG1u64KAWGcQB9rZlKC+YSkahEK+5ZLO5qRbKfVbBH fzsPmJkC08x991KLg8V8AOuawz+a+V+AN3lOyqjk5lUwi4MphB9BqVi+ujKuf6peQ9YrEFN1F6zf4 kZbgL3VJpcqgwjokkMxc8MJJ6trT6TF/nsXm40b3GlysaY50JrsDXBPtZdNxXtGTe+wg52woCLIRd k7jR41plw==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006NJ-2y; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 04/17] IDR test suite: Check handling negative end correctly Date: Wed, 29 Nov 2017 12:19:09 -0800 Message-Id: <20171129201922.24370-5-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox One of the charming quirks of the idr_alloc() interface is that you can pass a negative end and it will be interpreted as "maximum". Ensure we don't break that. Signed-off-by: Matthew Wilcox --- tools/testing/radix-tree/idr-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c index 193450b29bf0..892ef8855b02 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -207,6 +207,7 @@ void idr_checks(void) assert(idr_alloc(&idr, item, i, i + 10, GFP_KERNEL) == i); } assert(idr_alloc(&idr, DUMMY_PTR, i - 2, i, GFP_KERNEL) == -ENOSPC); + assert(idr_alloc(&idr, DUMMY_PTR, i - 2, i + 10, GFP_KERNEL) == -ENOSPC); idr_for_each(&idr, item_idr_free, &idr); idr_destroy(&idr); From patchwork Wed Nov 29 20:19:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842718 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ZB4dk5t2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjN41k5z9s4s for ; Thu, 30 Nov 2017 07:20:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752823AbdK2UUH (ORCPT ); Wed, 29 Nov 2017 15:20:07 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:39850 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752127AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=kuP6zwRkf9BikXLn5KVSQ6R+9SnbWB4c7JOAVr9Tw2k=; b=ZB4dk5t2f2GUeKmfb1GMzYo6V ziQ1HP1nwwcmiH86sKCBR6XDYhdhdEVc9aNwOxNpFxcYDJYOLTtGgB3P+VSyS5JH0qMN8WSyeo0Is qYSVbIPacF+FgnX917pHiurU+BK7aZVAn0HHhRJzyKB7ItCToZmdToh/UNtwQxjYUguGi9qKKyCf4 VttrdqXfwIKKlJxIILHhq1tILkjuEV2aM1OM8zIt+YhTnw1NqOFOyRMMB2XM2sA0PFvHqJeYLK9Rt M2VVt6wPRABxxCrTa47WYI8xZqW/iZVEurCyfjejsKUVvxeWr8Ijmk2t5LzKDf1kVcnLtWzbFRkqA TmjhUR4nA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006NT-5I; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 05/17] idr: Delete idr_remove_ext function Date: Wed, 29 Nov 2017 12:19:10 -0800 Message-Id: <20171129201922.24370-6-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Simply changing idr_remove's 'id' argument to 'unsigned long' suffices for all callers. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 7 +------ net/sched/act_api.c | 2 +- net/sched/cls_basic.c | 6 +++--- net/sched/cls_bpf.c | 4 ++-- net/sched/cls_flower.c | 4 ++-- net/sched/cls_u32.c | 8 ++++---- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index dd048cf456b7..9a4042489ec6 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -140,16 +140,11 @@ void *idr_replace(struct idr *, void *, int id); void *idr_replace_ext(struct idr *idr, void *ptr, unsigned long id); void idr_destroy(struct idr *); -static inline void *idr_remove_ext(struct idr *idr, unsigned long id) +static inline void *idr_remove(struct idr *idr, unsigned long id) { return radix_tree_delete_item(&idr->idr_rt, id, NULL); } -static inline void *idr_remove(struct idr *idr, int id) -{ - return idr_remove_ext(idr, id); -} - static inline void idr_init(struct idr *idr) { INIT_RADIX_TREE(&idr->idr_rt, IDR_RT_MARKER); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 4d33a50a8a6d..bab81574a420 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -78,7 +78,7 @@ static void free_tcf(struct tc_action *p) static void tcf_idr_remove(struct tcf_idrinfo *idrinfo, struct tc_action *p) { spin_lock_bh(&idrinfo->lock); - idr_remove_ext(&idrinfo->action_idr, p->tcfa_index); + idr_remove(&idrinfo->action_idr, p->tcfa_index); spin_unlock_bh(&idrinfo->lock); gen_kill_estimator(&p->tcfa_rate_est); free_tcf(p); diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 5f169ded347e..d2193304bad0 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -120,7 +120,7 @@ static void basic_destroy(struct tcf_proto *tp) list_for_each_entry_safe(f, n, &head->flist, link) { list_del_rcu(&f->link); tcf_unbind_filter(tp, &f->res); - idr_remove_ext(&head->handle_idr, f->handle); + idr_remove(&head->handle_idr, f->handle); if (tcf_exts_get_net(&f->exts)) call_rcu(&f->rcu, basic_delete_filter); else @@ -137,7 +137,7 @@ static int basic_delete(struct tcf_proto *tp, void *arg, bool *last) list_del_rcu(&f->link); tcf_unbind_filter(tp, &f->res); - idr_remove_ext(&head->handle_idr, f->handle); + idr_remove(&head->handle_idr, f->handle); tcf_exts_get_net(&f->exts); call_rcu(&f->rcu, basic_delete_filter); *last = list_empty(&head->flist); @@ -224,7 +224,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr); if (err < 0) { if (!fold) - idr_remove_ext(&head->handle_idr, fnew->handle); + idr_remove(&head->handle_idr, fnew->handle); goto errout; } diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 6fe798c2df1a..b017d99fd7e1 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -299,7 +299,7 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog) { struct cls_bpf_head *head = rtnl_dereference(tp->root); - idr_remove_ext(&head->handle_idr, prog->handle); + idr_remove(&head->handle_idr, prog->handle); cls_bpf_stop_offload(tp, prog); list_del_rcu(&prog->link); tcf_unbind_filter(tp, &prog->res); @@ -542,7 +542,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, cls_bpf_free_parms(prog); errout_idr: if (!oldprog) - idr_remove_ext(&head->handle_idr, prog->handle); + idr_remove(&head->handle_idr, prog->handle); errout: tcf_exts_destroy(&prog->exts); kfree(prog); diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 543a3e875d05..3e89b0be1706 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -283,7 +283,7 @@ static void __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f) { struct cls_fl_head *head = rtnl_dereference(tp->root); - idr_remove_ext(&head->handle_idr, f->handle); + idr_remove(&head->handle_idr, f->handle); list_del_rcu(&f->list); if (!tc_skip_hw(f->flags)) fl_hw_destroy_filter(tp, f); @@ -972,7 +972,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, errout_idr: if (fnew->handle) - idr_remove_ext(&head->handle_idr, fnew->handle); + idr_remove(&head->handle_idr, fnew->handle); errout: tcf_exts_destroy(&fnew->exts); kfree(fnew); diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index ac152b4f4247..6fe4e3549ad3 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -591,7 +591,7 @@ static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht) rtnl_dereference(n->next)); tcf_unbind_filter(tp, &n->res); u32_remove_hw_knode(tp, n->handle); - idr_remove_ext(&ht->handle_idr, n->handle); + idr_remove(&ht->handle_idr, n->handle); if (tcf_exts_get_net(&n->exts)) call_rcu(&n->rcu, u32_delete_key_freepf_rcu); else @@ -617,7 +617,7 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht) if (phn == ht) { u32_clear_hw_hnode(tp, ht); idr_destroy(&ht->handle_idr); - idr_remove_ext(&tp_c->handle_idr, ht->handle); + idr_remove(&tp_c->handle_idr, ht->handle); RCU_INIT_POINTER(*hn, ht->next); kfree_rcu(ht, rcu); return 0; @@ -992,7 +992,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, err = u32_replace_hw_hnode(tp, ht, flags); if (err) { - idr_remove_ext(&tp_c->handle_idr, handle); + idr_remove(&tp_c->handle_idr, handle); kfree(ht); return err; } @@ -1120,7 +1120,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, #endif kfree(n); erridr: - idr_remove_ext(&ht->handle_idr, handle); + idr_remove(&ht->handle_idr, handle); return err; } From patchwork Wed Nov 29 20:19:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842725 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="fKYOrpO0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjx0mTlz9s4s for ; Thu, 30 Nov 2017 07:20:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752847AbdK2UUf (ORCPT ); Wed, 29 Nov 2017 15:20:35 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:45123 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752317AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=Yj7cAWa4I/MWwrL351Tyy8bq5K6zQSJ13VRd4/cbH+4=; b=fKYOrpO0o6OpZJ1kS7QaSi3sP 9+zntMAAFVF6rKruJPYeoQDa6F0RgiiUCdCBbVknAYCgGA1DrPWP5y7WxLP+98TXEj9vSvBiFDNkb orgHKtIoDZm30l5OKfdZlt6lFDTXL8oZthtHEM0pxt/oAsK8tdeNy3oNuTMqr6FpqauLoDhzGvSN+ MQTUMknNSl4+IoOmFQNYIDAI5Th+uqkUFyTidVlUxssxfIUNoIxhqehHWWSZh0aFgc9O9/FzIQ2yf QOmDYnOtZyqQpiShKFO+4ar3T3YtlD+AnjKT1QGMKzSAdBp6udBLsdTlvn/FYO35hrqIuo9lHN/MW /JNKQCosA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006NZ-8D; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 06/17] idr: Delete idr_replace_ext function Date: Wed, 29 Nov 2017 12:19:11 -0800 Message-Id: <20171129201922.24370-7-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Changing idr_replace's 'id' argument to 'unsigned long' works for all callers. Callers which passed a negative ID now get -ENOENT instead of -EINVAL. No callers relied on this error value. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 3 +-- lib/idr.c | 15 +++------------ net/sched/act_api.c | 2 +- net/sched/cls_basic.c | 2 +- net/sched/cls_bpf.c | 2 +- net/sched/cls_flower.c | 2 +- net/sched/cls_u32.c | 2 +- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 9a4042489ec6..90dbe7a3735c 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -136,8 +136,7 @@ int idr_for_each(const struct idr *, int (*fn)(int id, void *p, void *data), void *data); void *idr_get_next(struct idr *, int *nextid); void *idr_get_next_ext(struct idr *idr, unsigned long *nextid); -void *idr_replace(struct idr *, void *, int id); -void *idr_replace_ext(struct idr *idr, void *ptr, unsigned long id); +void *idr_replace(struct idr *, void *, unsigned long id); void idr_destroy(struct idr *); static inline void *idr_remove(struct idr *idr, unsigned long id) diff --git a/lib/idr.c b/lib/idr.c index 2593ce513a18..577bfd4fe5c2 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -147,18 +147,9 @@ EXPORT_SYMBOL(idr_get_next_ext); * the one being replaced!). * * Returns: the old value on success. %-ENOENT indicates that @id was not - * found. %-EINVAL indicates that @id or @ptr were not valid. + * found. %-EINVAL indicates that @ptr was not valid. */ -void *idr_replace(struct idr *idr, void *ptr, int id) -{ - if (id < 0) - return ERR_PTR(-EINVAL); - - return idr_replace_ext(idr, ptr, id); -} -EXPORT_SYMBOL(idr_replace); - -void *idr_replace_ext(struct idr *idr, void *ptr, unsigned long id) +void *idr_replace(struct idr *idr, void *ptr, unsigned long id) { struct radix_tree_node *node; void __rcu **slot = NULL; @@ -175,7 +166,7 @@ void *idr_replace_ext(struct idr *idr, void *ptr, unsigned long id) return entry; } -EXPORT_SYMBOL(idr_replace_ext); +EXPORT_SYMBOL(idr_replace); /** * DOC: IDA description diff --git a/net/sched/act_api.c b/net/sched/act_api.c index bab81574a420..7e901e855d68 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -348,7 +348,7 @@ void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a) struct tcf_idrinfo *idrinfo = tn->idrinfo; spin_lock_bh(&idrinfo->lock); - idr_replace_ext(&idrinfo->action_idr, a, a->tcfa_index); + idr_replace(&idrinfo->action_idr, a, a->tcfa_index); spin_unlock_bh(&idrinfo->lock); } EXPORT_SYMBOL(tcf_idr_insert); diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index d2193304bad0..147700afcf31 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -231,7 +231,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, *arg = fnew; if (fold) { - idr_replace_ext(&head->handle_idr, fnew, fnew->handle); + idr_replace(&head->handle_idr, fnew, fnew->handle); list_replace_rcu(&fold->link, &fnew->link); tcf_unbind_filter(tp, &fold->res); tcf_exts_get_net(&fold->exts); diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index b017d99fd7e1..1660fc8294ef 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -526,7 +526,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, prog->gen_flags |= TCA_CLS_FLAGS_NOT_IN_HW; if (oldprog) { - idr_replace_ext(&head->handle_idr, prog, handle); + idr_replace(&head->handle_idr, prog, handle); list_replace_rcu(&oldprog->link, &prog->link); tcf_unbind_filter(tp, &oldprog->res); tcf_exts_get_net(&oldprog->exts); diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 3e89b0be1706..ca71823bee03 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -958,7 +958,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, if (fold) { fnew->handle = handle; - idr_replace_ext(&head->handle_idr, fnew, fnew->handle); + idr_replace(&head->handle_idr, fnew, fnew->handle); list_replace_rcu(&fold->list, &fnew->list); tcf_unbind_filter(tp, &fold->res); tcf_exts_get_net(&fold->exts); diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 6fe4e3549ad3..9d48674a70e0 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -833,7 +833,7 @@ static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c, if (pins->handle == n->handle) break; - idr_replace_ext(&ht->handle_idr, n, n->handle); + idr_replace(&ht->handle_idr, n, n->handle); RCU_INIT_POINTER(n->next, pins->next); rcu_assign_pointer(*ins, n); } From patchwork Wed Nov 29 20:19:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842722 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="XiFR4QQC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjk6Ddhz9s4s for ; Thu, 30 Nov 2017 07:20:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752783AbdK2UUC (ORCPT ); Wed, 29 Nov 2017 15:20:02 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:42733 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752631AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=5CDy+ZSXl/77B4E1+r+ST+SIoKzc3BB8ksLwC5PEZho=; b=XiFR4QQCBFJ+6GZYmOWWBzfu6 jJu4agfjWf2jPvzmJqZaiLP1tWo+HrtUHJ2RBlRK8eaN9GcntSikvIlKORUoHQwzan/9GjTf0hU8o MzJcZR5E695e3m96LS0UKiUOqZAH6CL+KK7EpWBVS3rZ4izKOv7I0GN8/cYPciGRSbAwfSPsvb/6R e1e5nQfEh3FTdEvytd2Awih9xcrJAglIRey804sKbIlaQuwLBFe7cR9931DJYr7AyGHSbp9oOeJQu /VN5KuBzn9KenMYiXt4+NwscefAtpEb0oP3ooU4d2gYTNyoa1TTBWlT+nU0UBCDODFJHzCzHky7/r K3aZ98xrg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006Ni-Bi; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 07/17] idr: Delete idr_find_ext function Date: Wed, 29 Nov 2017 12:19:12 -0800 Message-Id: <20171129201922.24370-8-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Simply changing idr_remove's 'id' argument to 'unsigned long' works for all callers. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 7 +------ net/sched/act_api.c | 2 +- net/sched/cls_flower.c | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 90dbe7a3735c..12514ec0cd28 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -179,16 +179,11 @@ static inline void idr_preload_end(void) * This function can be called under rcu_read_lock(), given that the leaf * pointers lifetimes are correctly managed. */ -static inline void *idr_find_ext(const struct idr *idr, unsigned long id) +static inline void *idr_find(const struct idr *idr, unsigned long id) { return radix_tree_lookup(&idr->idr_rt, id); } -static inline void *idr_find(const struct idr *idr, int id) -{ - return idr_find_ext(idr, id); -} - /** * idr_for_each_entry - iterate over an idr's elements of a given type * @idr: idr handle diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 7e901e855d68..efb90b8a3bf0 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -222,7 +222,7 @@ static struct tc_action *tcf_idr_lookup(u32 index, struct tcf_idrinfo *idrinfo) struct tc_action *p = NULL; spin_lock_bh(&idrinfo->lock); - p = idr_find_ext(&idrinfo->action_idr, index); + p = idr_find(&idrinfo->action_idr, index); spin_unlock_bh(&idrinfo->lock); return p; diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index ca71823bee03..ec0dc92f6104 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -329,7 +329,7 @@ static void *fl_get(struct tcf_proto *tp, u32 handle) { struct cls_fl_head *head = rtnl_dereference(tp->root); - return idr_find_ext(&head->handle_idr, handle); + return idr_find(&head->handle_idr, handle); } static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = { From patchwork Wed Nov 29 20:19:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842723 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="DNrfcLfA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjq0jm9z9s4s for ; Thu, 30 Nov 2017 07:20:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752774AbdK2UUC (ORCPT ); Wed, 29 Nov 2017 15:20:02 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:36501 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752638AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=QCtMGLxDMFaBdoNDIy3ndl1vlazcAF0y6xiMtQ9W6g4=; b=DNrfcLfAXyMKWFfZZ2NZdY6vJ hWjVnvvCEYQT9spy5uc+VoMAz9acsHLvqNJ/+SuRnPeAbblxrDdDffkseUvcZvNV+ogdtgl3gj597 CeqOvNCBJKUnCtHTvQafMnOj1O/CYsOOawRsoYCqZBbGA1jXz0ERSZQQM5AMpwXHZB0zxpzYu2rMw J44NCAF6eSNL6VqML6baQiyHrkEguKq6NMeZtL3nKTnuj+cVHkxQ6aWD2g5nTZ3r0YLhlNnjwI8g2 KhKOwBCmxON7LdmYxoyGUWwGLGORrfwXnziR/fPGttSObpnIVgxqIGZeMWkf8CeylH8a1IwMw+BKq YKaBQg95Q==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006Nq-EU; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 08/17] idr: Add idr_alloc_u32 helper Date: Wed, 29 Nov 2017 12:19:13 -0800 Message-Id: <20171129201922.24370-9-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox All current users of idr_alloc_ext() actually want to allocate a u32 and it's a little painful for them to use idr_alloc_ext(). This convenience function makes it simple. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/idr.h b/include/linux/idr.h index 12514ec0cd28..9b2fd6f408b2 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -139,6 +139,35 @@ void *idr_get_next_ext(struct idr *idr, unsigned long *nextid); void *idr_replace(struct idr *, void *, unsigned long id); void idr_destroy(struct idr *); +/** + * idr_alloc_u32() - Allocate an ID. + * @idr: IDR handle. + * @ptr: Pointer to be associated with the new ID. + * @nextid: The new ID. + * @max: The maximum ID to allocate (inclusive). + * @gfp: Memory allocation flags. + * + * Allocates an unused ID in the range [*nextid, max] and updates the @nextid + * pointer with the newly assigned ID. Returns -ENOSPC and does not modify + * @nextid if there are no unused IDs in the range. + * + * The caller should provide their own locking to ensure that two concurrent + * modifications to the IDR are not possible. Read-only accesses to the + * IDR may be done under the RCU read lock or may exclude simultaneous + * writers. + * + * Return: 0 on success, -ENOMEM for memory allocation errors, -ENOSPC if + * there are no free IDs in the range. + */ +static inline int __must_check idr_alloc_u32(struct idr *idr, void *ptr, + u32 *nextid, unsigned long max, gfp_t gfp) +{ + unsigned long tmp = *nextid; + int ret = idr_alloc_ext(idr, ptr, &tmp, tmp, max + 1, gfp); + *nextid = tmp; + return ret; +} + static inline void *idr_remove(struct idr *idr, unsigned long id) { return radix_tree_delete_item(&idr->idr_rt, id, NULL); From patchwork Wed Nov 29 20:19:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842715 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="R2YYO5+s"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBj735Bqz9s4s for ; Thu, 30 Nov 2017 07:19:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752750AbdK2UTo (ORCPT ); Wed, 29 Nov 2017 15:19:44 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:51386 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752725AbdK2UTj (ORCPT ); Wed, 29 Nov 2017 15:19:39 -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=gFm/MfBZ2WK5aqMRZC4PP7DaJ9Uqba3Ch3db4tD/2pg=; b=R2YYO5+smHgfZmFXqLjX56eOL 4NlSuBau8s3auwMiFkQ1MKRGcxkQgQknT6BQqLFd62OAKiQRUlKHsWtiy4d0pmKmx8THUD3Ge8T6d R4tHkT/gc6aIwX2rR+WfvD1GA/nAb01j1mtP8s6ncpZhFbddhJeh2QH/45k0sYrpAsIK32HPx+81J uZBxlavNHgmm0ZLH/VxlncevZsUI97VQTAFze71TviJ//Ytj3lKOGtX9/YmpfJQRBxhqU6Tn6h+77 8EbcRsiDzFt/5Zl6eEB+yX6QE/6IIbL+8zR1bmBkzxXsBJaLTrVksXYkTyuWnONgxeaUF/unJE8Vt 5ueqCLGSA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006Nw-Gk; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 09/17] net sched actions: Convert to use idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:14 -0800 Message-Id: <20171129201922.24370-10-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Use the new helper. Also untangle the error path, and in so doing noticed that estimator generator failure would lead to us leaking an ID. Fix that bug. Signed-off-by: Matthew Wilcox --- net/sched/act_api.c | 60 ++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index efb90b8a3bf0..156302c110af 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -274,7 +274,6 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, struct tcf_idrinfo *idrinfo = tn->idrinfo; struct idr *idr = &idrinfo->action_idr; int err = -ENOMEM; - unsigned long idr_index; if (unlikely(!p)) return -ENOMEM; @@ -284,45 +283,28 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, if (cpustats) { p->cpu_bstats = netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu); - if (!p->cpu_bstats) { -err1: - kfree(p); - return err; - } - p->cpu_qstats = alloc_percpu(struct gnet_stats_queue); - if (!p->cpu_qstats) { -err2: - free_percpu(p->cpu_bstats); + if (!p->cpu_bstats) goto err1; - } + p->cpu_qstats = alloc_percpu(struct gnet_stats_queue); + if (!p->cpu_qstats) + goto err2; } spin_lock_init(&p->tcfa_lock); + idr_preload(GFP_KERNEL); + spin_lock_bh(&idrinfo->lock); /* user doesn't specify an index */ if (!index) { - idr_preload(GFP_KERNEL); - spin_lock_bh(&idrinfo->lock); - err = idr_alloc_ext(idr, NULL, &idr_index, 1, 0, - GFP_ATOMIC); - spin_unlock_bh(&idrinfo->lock); - idr_preload_end(); - if (err) { -err3: - free_percpu(p->cpu_qstats); - goto err2; - } - p->tcfa_index = idr_index; + index = 1; + err = idr_alloc_u32(idr, NULL, &index, UINT_MAX, GFP_ATOMIC); } else { - idr_preload(GFP_KERNEL); - spin_lock_bh(&idrinfo->lock); - err = idr_alloc_ext(idr, NULL, NULL, index, index + 1, - GFP_ATOMIC); - spin_unlock_bh(&idrinfo->lock); - idr_preload_end(); - if (err) - goto err3; - p->tcfa_index = index; + err = idr_alloc_u32(idr, NULL, &index, index, GFP_ATOMIC); } + spin_unlock_bh(&idrinfo->lock); + idr_preload_end(); + if (err) + goto err3; + p->tcfa_index = index; p->tcfa_tm.install = jiffies; p->tcfa_tm.lastuse = jiffies; p->tcfa_tm.firstuse = 0; @@ -330,9 +312,8 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, err = gen_new_estimator(&p->tcfa_bstats, p->cpu_bstats, &p->tcfa_rate_est, &p->tcfa_lock, NULL, est); - if (err) { - goto err3; - } + if (err) + goto err4; } p->idrinfo = idrinfo; @@ -340,6 +321,15 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, INIT_LIST_HEAD(&p->list); *a = p; return 0; +err4: + idr_remove(idr, index); +err3: + free_percpu(p->cpu_qstats); +err2: + free_percpu(p->cpu_bstats); +err1: + kfree(p); + return err; } EXPORT_SYMBOL(tcf_idr_create); From patchwork Wed Nov 29 20:19:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842728 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qViVEV5J"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBkF67SRz9s4s for ; Thu, 30 Nov 2017 07:20:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752849AbdK2UUv (ORCPT ); Wed, 29 Nov 2017 15:20:51 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:56536 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbdK2UTg (ORCPT ); Wed, 29 Nov 2017 15:19:36 -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=2cpD56NRa154fOx7ZTnQ8B5tmCJm1507x1BPy+y9Lq4=; b=qViVEV5JqDuInKL1HsEfxOrPw dT9MIVvJN8XGSUKM8GzJfSqAmRPETBks+f6sYSLVkLv2rzK3gbpu2BLZwnAPgPDIzdrzpSqj0E7Cp 30Fgk+L0+qFBB6uNzwtTWHk0uPDLvg7i+LsyBWWqWntLE6VdoNv1Rbc/VU1mWlLG0xN62a1DQzE1l 5f+vUEs2irN4Of5FmwKO60u/2b3NWc47GXttyrVo4Ck6WB0UmmEQuZsLT5oCK/TEBodDRheKLSkV+ KgFhpnhfkGiWUvdq8v9toLcHbZkD34Wzr3Tb4Pb5AQKg/eDCN4X/ZYtQiuqmSBUiL3ryoYZ+0Of72 30uFqyQig==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006O1-Ik; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 10/17] cls_basic: Convert to use idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:15 -0800 Message-Id: <20171129201922.24370-11-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Use the new helper which saves a temporary variable and a few lines of code. Signed-off-by: Matthew Wilcox --- net/sched/cls_basic.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 147700afcf31..c4b242fee8e4 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -182,7 +182,6 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, struct nlattr *tb[TCA_BASIC_MAX + 1]; struct basic_filter *fold = (struct basic_filter *) *arg; struct basic_filter *fnew; - unsigned long idr_index; if (tca[TCA_OPTIONS] == NULL) return -EINVAL; @@ -205,21 +204,17 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, if (err < 0) goto errout; - if (handle) { - fnew->handle = handle; - if (!fold) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (err) - goto errout; - } - } else { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - 1, 0x7FFFFFFF, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; + if (!handle) { + handle = 1; + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + INT_MAX, GFP_KERNEL); + } else if (!fold) { + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + handle, GFP_KERNEL); } + if (err) + goto errout; + fnew->handle = handle; err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr); if (err < 0) { From patchwork Wed Nov 29 20:19:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842729 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cxuP0OGQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBkL6zzBz9s4s for ; Thu, 30 Nov 2017 07:20:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752665AbdK2UUv (ORCPT ); Wed, 29 Nov 2017 15:20:51 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:50771 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752216AbdK2UTg (ORCPT ); Wed, 29 Nov 2017 15:19:36 -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=GYpTCgUlFe1cTn13Czct75kyxy2cEA5T+gpKvvFh9jw=; b=cxuP0OGQbQfclrIuxCcNsYFe4 y+Z5Hp1F9HNEOyaWneP3H+aoBj2LS08dAKV64q/vrtmddi8/bPXVmyhKjmwVdpTcWKjn6N6C0sz/h DYRaHq6t1QQCXajVOV2z3t2ZGRZVPjXIgOOOyF3+HwpeU2ikestcJEsoAbS6Wmp2SrBHpr/IJApLC rFsfTMYA10sa77Fcdh9s0tuf61dHw/0Wg4y8o5TRlDRUBX5xmADpzJqhFokrrhmN1FpXja96aAcON 9h2UcY6SovZGkD2JwPuCZVe0zCOnwEkN4EvUe2GtZ6EZuhymgzwemlggTlvH9gh2mEeXh0BRpOzNc X+Q1TnpXg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006OA-LH; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 11/17] cls_bpf: Convert to use idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:16 -0800 Message-Id: <20171129201922.24370-12-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Use the new helper. This has a modest reduction in both lines of code and compiled code size. Signed-off-by: Matthew Wilcox --- net/sched/cls_bpf.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 1660fc8294ef..db1dd4de7d6a 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -472,7 +472,6 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, struct cls_bpf_prog *oldprog = *arg; struct nlattr *tb[TCA_BPF_MAX + 1]; struct cls_bpf_prog *prog; - unsigned long idr_index; int ret; if (tca[TCA_OPTIONS] == NULL) @@ -499,21 +498,18 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, } if (handle == 0) { - ret = idr_alloc_ext(&head->handle_idr, prog, &idr_index, - 1, 0x7FFFFFFF, GFP_KERNEL); - if (ret) - goto errout; - prog->handle = idr_index; - } else { - if (!oldprog) { - ret = idr_alloc_ext(&head->handle_idr, prog, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (ret) - goto errout; - } - prog->handle = handle; + handle = 1; + ret = idr_alloc_u32(&head->handle_idr, prog, &handle, + INT_MAX, GFP_KERNEL); + } else if (!oldprog) { + ret = idr_alloc_u32(&head->handle_idr, prog, &handle, + handle, GFP_KERNEL); } + if (ret) + goto errout; + prog->handle = handle; + ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], ovr); if (ret < 0) goto errout_idr; From patchwork Wed Nov 29 20:19:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842726 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ThHkPOt3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBk10DjLz9s4s for ; Thu, 30 Nov 2017 07:20:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbdK2UUe (ORCPT ); Wed, 29 Nov 2017 15:20:34 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:41810 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752361AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=hI8QRXPX2uRnUSCymmfo3DEcRKLeRLV3RFLCMUJv2pM=; b=ThHkPOt3BFuT63fzVWJ+PVeOi hrMi0OGkIEU3h+K/BWaGuo7/AtDRPI9CfCG4u2mJD0RWiPaMeEnopBR1m+DvwCAj+Mw1FpKRrVNkg KiZi29rtwiWYFIMMRjBxkKGJeJbFqpqOzObG5BX2r5+1Wg+0aih8OA1M9MFi7j9UqscDDpeSUWLdu ctg88lFUk1oyVsUB/RuM8b3AU4mAdThbUyKPrDTDNClOo11JloVWkJFt59JyIFvNWlr4uEwqjC2yA 56ipNrJqZQR1vpNntgZ76kWm3K/Pkz/hYwLH6foonsw6OqjlR43kg13oTOH0NmyHo2PVqdoUrTLlS kCpV1eYBg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006OF-Nt; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 12/17] cls_flower: Convert to idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:17 -0800 Message-Id: <20171129201922.24370-13-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Use the new helper which saves a temporary variable and a few lines of code. Signed-off-by: Matthew Wilcox --- net/sched/cls_flower.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index ec0dc92f6104..adee3cf30bb3 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -858,7 +858,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, struct cls_fl_filter *fnew; struct nlattr **tb; struct fl_flow_mask mask = {}; - unsigned long idr_index; int err; if (!tca[TCA_OPTIONS]) @@ -889,21 +888,17 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout; if (!handle) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - 1, 0x80000000, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; - } - - /* user specifies a handle and it doesn't exist */ - if (handle && !fold) { - err = idr_alloc_ext(&head->handle_idr, fnew, &idr_index, - handle, handle + 1, GFP_KERNEL); - if (err) - goto errout; - fnew->handle = idr_index; + handle = 1; + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + INT_MAX, GFP_KERNEL); + } else if (!fold) { + /* user specifies a handle and it doesn't exist */ + err = idr_alloc_u32(&head->handle_idr, fnew, &handle, + handle, GFP_KERNEL); } + if (err) + goto errout; + fnew->handle = handle; if (tb[TCA_FLOWER_FLAGS]) { fnew->flags = nla_get_u32(tb[TCA_FLOWER_FLAGS]); @@ -957,7 +952,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, *arg = fnew; if (fold) { - fnew->handle = handle; idr_replace(&head->handle_idr, fnew, fnew->handle); list_replace_rcu(&fold->list, &fnew->list); tcf_unbind_filter(tp, &fold->res); From patchwork Wed Nov 29 20:19:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842727 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="vAXwtHhn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBk56XGsz9s4s for ; Thu, 30 Nov 2017 07:20:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752837AbdK2UUd (ORCPT ); Wed, 29 Nov 2017 15:20:33 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:36256 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752425AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=KBbViw4qeJZxMrF49hGWtdnDwK5OlhM8RzVTosEKOzA=; b=vAXwtHhn1YAXq808yl17XjT/l Qmy8WyG/zt6VVJk63/QQmLS0dzEoaIn0rX9Gs0rFtcxjGZ1rVlO+SIYbDsnbE79ViSgTPzJE45kOT Ndz/70JKzYilWTyUmt+vGQabd/eWlMMpeKY8eaMRoYkgaayeaxIYkfVpeU5CpUYjb36RvVPcHF+3v i4QE593xMT0UXfIjxqiACWSuQuQ+tmIEtVuaFWn1VR+LwOJQL0zrR49Zqwz2x5m06w3badkXvwuzq 3lqu+yNUhmzKI+EooXW30l0YLRZxtezMJ1OO7HGMqomVJ5ah4Oxyo7462LLby54ruCZ1P64iUqyOV lNu8+PNoQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006OM-Qn; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 13/17] cls_u32: Reinstate cyclic allocation Date: Wed, 29 Nov 2017 12:19:18 -0800 Message-Id: <20171129201922.24370-14-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Commit e7614370d6f0 ("net_sched: use idr to allocate u32 filter handles) converted htid allocation to use the IDR. The ID allocated by this scheme changes; it used to be cyclic, but now always allocates the lowest available. The IDR supports cyclic allocation, so just use the right function. Signed-off-by: Matthew Wilcox --- net/sched/cls_u32.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 9d48674a70e0..e65b47483dc0 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -316,19 +316,13 @@ static void *u32_get(struct tcf_proto *tp, u32 handle) return u32_lookup_key(ht, handle); } +/* Protected by rtnl lock */ static u32 gen_new_htid(struct tc_u_common *tp_c, struct tc_u_hnode *ptr) { - unsigned long idr_index; - int err; - - /* This is only used inside rtnl lock it is safe to increment - * without read _copy_ update semantics - */ - err = idr_alloc_ext(&tp_c->handle_idr, ptr, &idr_index, - 1, 0x7FF, GFP_KERNEL); - if (err) + int id = idr_alloc_cyclic(&tp_c->handle_idr, ptr, 1, 0x7FF, GFP_KERNEL); + if (id < 0) return 0; - return (u32)(idr_index | 0x800) << 20; + return (id | 0x800U) << 20; } static struct hlist_head *tc_u_common_hash; From patchwork Wed Nov 29 20:19:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842719 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Ct0G+A58"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjS5PM9z9s4s for ; Thu, 30 Nov 2017 07:20:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752819AbdK2UUG (ORCPT ); Wed, 29 Nov 2017 15:20:06 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:58185 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752499AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=OJpK+M/PDu2vxZJ5uWTXYci7HUqu3+CugB/J8Rm152E=; b=Ct0G+A58sec1tFv4grOiDT/xm QlRZrvyZYib3/g+qDwYQtPgIAoRK81QbxST6dHuG4LLzeB/Pd4VoiYeEDAy6gwyQT8n49xu3cPQxU grMLXLDTTgF2W8psBtlV0/zerei93BJeoNVK/+ZxNBCrlVg3m61CkKXA86mUZWJIvhorO7ZoXDcun jNjZhUQf4gDIo6rELIxB6Jj4mAxfv8wmAq45QUXXxkH3JzMX3oZQMmiLVQ4kSaH33UQRqoD6F3LKq rKa0Vjer+K4NDSz4MNwErkG9t7PqyPc6/y52gWZHg5v23cioLWNqaoRo8sK+WCE51c4dCohzLNGwV 2ENjxQW1w==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pU-0006OT-T9; Wed, 29 Nov 2017 20:19:36 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 14/17] cls_u32: Convert to idr_alloc_u32 Date: Wed, 29 Nov 2017 12:19:19 -0800 Message-Id: <20171129201922.24370-15-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox No real benefit to this classifier, but since we're allocating a u32 anyway, we should use this function. Signed-off-by: Matthew Wilcox --- net/sched/cls_u32.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index e65b47483dc0..e433d1adccc8 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -970,8 +970,8 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, return -ENOMEM; } } else { - err = idr_alloc_ext(&tp_c->handle_idr, ht, NULL, - handle, handle + 1, GFP_KERNEL); + err = idr_alloc_u32(&tp_c->handle_idr, ht, &handle, + handle, GFP_KERNEL); if (err) { kfree(ht); return err; @@ -1020,8 +1020,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (TC_U32_HTID(handle) && TC_U32_HTID(handle^htid)) return -EINVAL; handle = htid | TC_U32_NODE(handle); - err = idr_alloc_ext(&ht->handle_idr, NULL, NULL, - handle, handle + 1, + err = idr_alloc_u32(&ht->handle_idr, NULL, &handle, handle, GFP_KERNEL); if (err) return err; From patchwork Wed Nov 29 20:19:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842720 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="OsVEE5OS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjX3W9fz9s4s for ; Thu, 30 Nov 2017 07:20:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752659AbdK2UUF (ORCPT ); Wed, 29 Nov 2017 15:20:05 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:36823 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=fgDTdg4QHPvEI2Z/Wh7lkh9rIi/4syUZL/3DKO1BTSQ=; b=OsVEE5OSlLcKtg4E0OHMncXJh jw6MBxvs2FDfZWtHHt2L/rA44HFMmWs9nJzUKARpvs1sBO75zV9kWumcuEgFKepv2Op3ejAD1tZyw jmrOyFXPniglkNCGhOpUfiNFMdON6kfmcXT6zMEctFCmYgPCbsq9eBOp2182IFhBcdXUl3CsclNCG MsWdKHuBooXHG7MreudZroweCKa53j2vioOy3NFww5lA+qPdc5+0rwdaMw2TsmFlpQK1cgwEgRqP9 gmYE5szqvJwHaovX3AP9lRQOyySf1ARvWHQcMjVqUbcL3uyoQtsTxNePcVgduihOBPh9oRhhzN3/0 4WuJHcbbQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pV-0006Oc-0W; Wed, 29 Nov 2017 20:19:37 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 15/17] idr: Rename idr_alloc_ext to idr_alloc_ul Date: Wed, 29 Nov 2017 12:19:20 -0800 Message-Id: <20171129201922.24370-16-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox idr_alloc_ul fits better with other parts of the Linux kernel where we need to name a function based on the types it operates on. It uses a 'nextid' pointer argument instead of separate minimum ID and output assigned ID, (like idr_get_next), reducing the number of arguments by one. It also takes a 'max' argument rather than an 'end' argument (unlike idr_alloc, but the semantics of 'end' don't work for unsigned long arguments). And its return value is an errno, so mark it as __must_check. Includes kernel-doc for idr_alloc_ul, which idr_alloc_ext didn't have, and I realised we were missing a test-case where idr_alloc_cyclic wraps around INT_MAX. Chris Mi has promised to contribute test-cases for idr_alloc_ul. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 55 ++------------------- include/linux/radix-tree.h | 17 +------ lib/idr.c | 99 +++++++++++++++++++++++++++++-------- lib/radix-tree.c | 3 +- net/sched/cls_u32.c | 20 ++++---- tools/testing/radix-tree/idr-test.c | 17 +++++++ 6 files changed, 111 insertions(+), 100 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 9b2fd6f408b2..344380fd0887 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -13,7 +13,6 @@ #define __IDR_H__ #include -#include #include #include @@ -82,55 +81,9 @@ static inline void idr_set_cursor(struct idr *idr, unsigned int val) void idr_preload(gfp_t gfp_mask); -int idr_alloc_cmn(struct idr *idr, void *ptr, unsigned long *index, - unsigned long start, unsigned long end, gfp_t gfp, - bool ext); - -/** - * idr_alloc - allocate an id - * @idr: idr handle - * @ptr: pointer to be associated with the new id - * @start: the minimum id (inclusive) - * @end: the maximum id (exclusive) - * @gfp: memory allocation flags - * - * Allocates an unused ID in the range [start, end). Returns -ENOSPC - * if there are no unused IDs in that range. - * - * Note that @end is treated as max when <= 0. This is to always allow - * using @start + N as @end as long as N is inside integer range. - * - * Simultaneous modifications to the @idr are not allowed and should be - * prevented by the user, usually with a lock. idr_alloc() may be called - * concurrently with read-only accesses to the @idr, such as idr_find() and - * idr_for_each_entry(). - */ -static inline int idr_alloc(struct idr *idr, void *ptr, - int start, int end, gfp_t gfp) -{ - unsigned long id; - int ret; - - if (WARN_ON_ONCE(start < 0)) - return -EINVAL; - - ret = idr_alloc_cmn(idr, ptr, &id, start, end, gfp, false); - - if (ret) - return ret; - - return id; -} - -static inline int idr_alloc_ext(struct idr *idr, void *ptr, - unsigned long *index, - unsigned long start, - unsigned long end, - gfp_t gfp) -{ - return idr_alloc_cmn(idr, ptr, index, start, end, gfp, true); -} - +int idr_alloc(struct idr *, void *, int start, int end, gfp_t); +int __must_check idr_alloc_ul(struct idr *, void *, unsigned long *nextid, + unsigned long max, gfp_t); int idr_alloc_cyclic(struct idr *, void *entry, int start, int end, gfp_t); int idr_for_each(const struct idr *, int (*fn)(int id, void *p, void *data), void *data); @@ -163,7 +116,7 @@ static inline int __must_check idr_alloc_u32(struct idr *idr, void *ptr, u32 *nextid, unsigned long max, gfp_t gfp) { unsigned long tmp = *nextid; - int ret = idr_alloc_ext(idr, ptr, &tmp, tmp, max + 1, gfp); + int ret = idr_alloc_ul(idr, ptr, &tmp, max, gfp); *nextid = tmp; return ret; } diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index 23a9c89c7ad9..fc55ff31eca7 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h @@ -356,24 +356,9 @@ int radix_tree_split(struct radix_tree_root *, unsigned long index, int radix_tree_join(struct radix_tree_root *, unsigned long index, unsigned new_order, void *); -void __rcu **idr_get_free_cmn(struct radix_tree_root *root, +void __rcu **idr_get_free(struct radix_tree_root *root, struct radix_tree_iter *iter, gfp_t gfp, unsigned long max); -static inline void __rcu **idr_get_free(struct radix_tree_root *root, - struct radix_tree_iter *iter, - gfp_t gfp, - int end) -{ - return idr_get_free_cmn(root, iter, gfp, end > 0 ? end - 1 : INT_MAX); -} - -static inline void __rcu **idr_get_free_ext(struct radix_tree_root *root, - struct radix_tree_iter *iter, - gfp_t gfp, - unsigned long end) -{ - return idr_get_free_cmn(root, iter, gfp, end - 1); -} enum { RADIX_TREE_ITER_TAG_MASK = 0x0f, /* tag index in lower nybble */ diff --git a/lib/idr.c b/lib/idr.c index 577bfd4fe5c2..103afb97b4bd 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,32 +8,85 @@ DEFINE_PER_CPU(struct ida_bitmap *, ida_bitmap); static DEFINE_SPINLOCK(simple_ida_lock); -int idr_alloc_cmn(struct idr *idr, void *ptr, unsigned long *index, - unsigned long start, unsigned long end, gfp_t gfp, - bool ext) +/** + * idr_alloc_ul() - Allocate a large ID. + * @idr: IDR handle. + * @ptr: Pointer to be associated with the new ID. + * @nextid: Pointer to minimum and new ID. + * @max: The maximum ID to allocate (inclusive). + * @gfp: Memory allocation flags. + * + * Allocates an unused ID in the range [*nextid, max] and updates the @nextid + * pointer with the newly assigned ID. Note that @max differs by 1 from the + * @end parameter to idr_alloc(). + * + * The caller should provide their own locking to ensure that two concurrent + * modifications to the IDR are not possible. Read-only accesses to the + * IDR may be done under the RCU read lock or may exclude simultaneous + * writers. + * + * Return: 0 on success, -ENOMEM for memory allocation errors, -ENOSPC if + * there are no free IDs in the range. + */ +int idr_alloc_ul(struct idr *idr, void *ptr, unsigned long *nextid, + unsigned long max, gfp_t gfp) { struct radix_tree_iter iter; void __rcu **slot; if (WARN_ON_ONCE(radix_tree_is_internal_node(ptr))) return -EINVAL; + if (WARN_ON_ONCE(!(idr->idr_rt.gfp_mask & ROOT_IS_IDR))) + idr->idr_rt.gfp_mask |= IDR_RT_MARKER; - radix_tree_iter_init(&iter, start); - if (ext) - slot = idr_get_free_ext(&idr->idr_rt, &iter, gfp, end); - else - slot = idr_get_free(&idr->idr_rt, &iter, gfp, end); + radix_tree_iter_init(&iter, *nextid); + slot = idr_get_free(&idr->idr_rt, &iter, gfp, max); if (IS_ERR(slot)) return PTR_ERR(slot); radix_tree_iter_replace(&idr->idr_rt, &iter, slot, ptr); radix_tree_iter_tag_clear(&idr->idr_rt, &iter, IDR_FREE); - if (index) - *index = iter.index; + *nextid = iter.index; return 0; } -EXPORT_SYMBOL_GPL(idr_alloc_cmn); +EXPORT_SYMBOL_GPL(idr_alloc_ul); + +/** + * idr_alloc - allocate an id + * @idr: idr handle + * @ptr: pointer to be associated with the new id + * @start: the minimum id (inclusive) + * @end: the maximum id (exclusive) + * @gfp: memory allocation flags + * + * Allocates an unused ID in the range [start, end). Returns -ENOSPC + * if there are no unused IDs in that range. + * + * Note that @end is treated as max when <= 0. This is to always allow + * using @start + N as @end as long as N is inside integer range. + * + * Simultaneous modifications to the @idr are not allowed and should be + * prevented by the user, usually with a lock. idr_alloc() may be called + * concurrently with read-only accesses to the @idr, such as idr_find() and + * idr_for_each_entry(). + */ +int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp) +{ + unsigned long id = start; + int ret; + + if (WARN_ON_ONCE(start < 0)) + return -EINVAL; + + ret = idr_alloc_ul(idr, ptr, &id, end > 0 ? end - 1 : INT_MAX, gfp); + + if (ret) + return ret; + + return id; +} +EXPORT_SYMBOL_GPL(idr_alloc); /** * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion @@ -48,18 +102,21 @@ EXPORT_SYMBOL_GPL(idr_alloc_cmn); */ int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, gfp_t gfp) { - int id, curr = idr->idr_next; - - if (curr < start) - curr = start; + unsigned long id = idr->idr_next; + int err, max = end > 0 ? end - 1 : INT_MAX; - id = idr_alloc(idr, ptr, curr, end, gfp); - if ((id == -ENOSPC) && (curr > start)) - id = idr_alloc(idr, ptr, start, curr, gfp); + if ((int)id < start) + id = start; - if (id >= 0) - idr->idr_next = id + 1U; + err = idr_alloc_ul(idr, ptr, &id, max, gfp); + if ((err == -ENOSPC) && (id > start)) { + id = start; + err = idr_alloc_ul(idr, ptr, &id, max, gfp); + } + if (err) + return err; + idr->idr_next = id + 1; return id; } EXPORT_SYMBOL(idr_alloc_cyclic); @@ -226,7 +283,7 @@ EXPORT_SYMBOL(idr_replace); * bitmap, which is excessive. */ -#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS) +#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) /** * ida_get_new_above - allocate new ID above or equal to a start id diff --git a/lib/radix-tree.c b/lib/radix-tree.c index c8d55565fafa..0a7ae3288a24 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -2135,7 +2136,7 @@ int ida_pre_get(struct ida *ida, gfp_t gfp) } EXPORT_SYMBOL(ida_pre_get); -void __rcu **idr_get_free_cmn(struct radix_tree_root *root, +void __rcu **idr_get_free(struct radix_tree_root *root, struct radix_tree_iter *iter, gfp_t gfp, unsigned long max) { diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index e433d1adccc8..3b4523059862 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -730,19 +730,17 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last) static u32 gen_new_kid(struct tc_u_hnode *ht, u32 htid) { - unsigned long idr_index; - u32 start = htid | 0x800; - u32 max = htid | 0xFFF; - u32 min = htid; - - if (idr_alloc_ext(&ht->handle_idr, NULL, &idr_index, - start, max + 1, GFP_KERNEL)) { - if (idr_alloc_ext(&ht->handle_idr, NULL, &idr_index, - min + 1, max + 1, GFP_KERNEL)) - return max; + unsigned long index = htid | 0x800; + unsigned long max = htid | 0xFFF; + + if (idr_alloc_ul(&ht->handle_idr, NULL, &index, max, GFP_KERNEL)) { + index = htid + 1; + if (idr_alloc_ul(&ht->handle_idr, NULL, &index, max, + GFP_KERNEL)) + index = max; } - return (u32)idr_index; + return index; } static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c index 892ef8855b02..36437ade429c 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -215,6 +215,23 @@ void idr_checks(void) assert(idr_is_empty(&idr)); + idr_set_cursor(&idr, INT_MAX - 3UL); + for (i = INT_MAX - 3UL; i < INT_MAX + 3UL; i++) { + struct item *item; + unsigned int id; + if (i <= INT_MAX) + item = item_create(i, 0); + else + item = item_create(i - INT_MAX - 1, 0); + + id = idr_alloc_cyclic(&idr, item, 0, 0, GFP_KERNEL); + assert(id == item->index); + } + + idr_for_each(&idr, item_idr_free, &idr); + idr_destroy(&idr); + assert(idr_is_empty(&idr)); + for (i = 1; i < 10000; i++) { struct item *item = item_create(i, 0); assert(idr_alloc(&idr, item, 1, 20000, GFP_KERNEL) == i); From patchwork Wed Nov 29 20:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842721 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="bUH8Vnq1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjb5LDBz9s4s for ; Thu, 30 Nov 2017 07:20:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752802AbdK2UUE (ORCPT ); Wed, 29 Nov 2017 15:20:04 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:54730 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752556AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=OQn3Guui1MAselCC5zqxCNKp57if5GQ2N6XRc5zq0F8=; b=bUH8Vnq1bOc+krTtSuVLAUKXj m5kx8QjIVE9AOLjJFxCeeQsEAr/UM4rNadAiDMpNEW4vHjY469LZ9aWwqjGanS2C7efCJnegndshA 7AtikeDw7/LFSVHaZMxAKArc9tucekJUAOtLQM3wxtu47XrpfKerToQqBrlfYFf2cUykVUFE5XsVV yea60vgrKRwm38G3ayoSBelXeLVcAUeWgjbrQh+HIgPlf3a5p5ToJl4jhAeDbQ4+7nuk8uFJaeDul UsJzMfT6eGwXTTPJbLka7aK3ZERMy0MTo9thek4ZKbc8yR8yfejn89ClVlN7VjNqeTlURedQ5LmoA todo3v0cA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pV-0006Ok-2p; Wed, 29 Nov 2017 20:19:37 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 16/17] idr: Rename idr_for_each_entry_ext Date: Wed, 29 Nov 2017 12:19:21 -0800 Message-Id: <20171129201922.24370-17-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Match idr_alloc_ul with idr_get_next_ul and idr_for_each_entry_ul. Also add kernel-doc. Signed-off-by: Matthew Wilcox --- include/linux/idr.h | 17 ++++++++++++++--- lib/idr.c | 20 +++++++++++++++----- net/sched/act_api.c | 6 +++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 344380fd0887..91d27a9bcdf4 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -88,7 +88,7 @@ int idr_alloc_cyclic(struct idr *, void *entry, int start, int end, gfp_t); int idr_for_each(const struct idr *, int (*fn)(int id, void *p, void *data), void *data); void *idr_get_next(struct idr *, int *nextid); -void *idr_get_next_ext(struct idr *idr, unsigned long *nextid); +void *idr_get_next_ul(struct idr *, unsigned long *nextid); void *idr_replace(struct idr *, void *, unsigned long id); void idr_destroy(struct idr *); @@ -178,8 +178,19 @@ static inline void *idr_find(const struct idr *idr, unsigned long id) */ #define idr_for_each_entry(idr, entry, id) \ for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; ++id) -#define idr_for_each_entry_ext(idr, entry, id) \ - for (id = 0; ((entry) = idr_get_next_ext(idr, &(id))) != NULL; ++id) + +/** + * idr_for_each_entry_ul() - iterate over an IDR's elements of a given type. + * @idr: IDR handle. + * @entry: The type * to use as cursor. + * @id: Entry ID. + * + * @entry and @id do not need to be initialized before the loop, and + * after normal terminatinon @entry is left with the value NULL. This + * is convenient for a "not found" value. + */ +#define idr_for_each_entry_ul(idr, entry, id) \ + for (id = 0; ((entry) = idr_get_next_ul(idr, &(id))) != NULL; ++id) /** * idr_for_each_entry_continue - continue iteration over an idr's elements of a given type diff --git a/lib/idr.c b/lib/idr.c index 103afb97b4bd..772a24513d1e 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -155,9 +155,9 @@ int idr_for_each(const struct idr *idr, EXPORT_SYMBOL(idr_for_each); /** - * idr_get_next - Find next populated entry - * @idr: idr handle - * @nextid: Pointer to lowest possible ID to return + * idr_get_next() - Find next populated entry. + * @idr: IDR handle. + * @nextid: Pointer to lowest possible ID to return. * * Returns the next populated entry in the tree with an ID greater than * or equal to the value pointed to by @nextid. On exit, @nextid is updated @@ -178,7 +178,17 @@ void *idr_get_next(struct idr *idr, int *nextid) } EXPORT_SYMBOL(idr_get_next); -void *idr_get_next_ext(struct idr *idr, unsigned long *nextid) +/** + * idr_get_next_ul() - Find next populated entry. + * @idr: IDR handle. + * @nextid: Pointer to lowest possible ID to return. + * + * Returns the next populated entry in the tree with an ID greater than + * or equal to the value pointed to by @nextid. On exit, @nextid is updated + * to the ID of the found value. To use in a loop, the value pointed to by + * nextid must be incremented by the user. + */ +void *idr_get_next_ul(struct idr *idr, unsigned long *nextid) { struct radix_tree_iter iter; void __rcu **slot; @@ -190,7 +200,7 @@ void *idr_get_next_ext(struct idr *idr, unsigned long *nextid) *nextid = iter.index; return rcu_dereference_raw(*slot); } -EXPORT_SYMBOL(idr_get_next_ext); +EXPORT_SYMBOL(idr_get_next_ul); /** * idr_replace - replace pointer for given id diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 156302c110af..4133d91b7029 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -124,7 +124,7 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, s_i = cb->args[0]; - idr_for_each_entry_ext(idr, p, id) { + idr_for_each_entry_ul(idr, p, id) { index++; if (index < s_i) continue; @@ -181,7 +181,7 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, if (nla_put_string(skb, TCA_KIND, ops->kind)) goto nla_put_failure; - idr_for_each_entry_ext(idr, p, id) { + idr_for_each_entry_ul(idr, p, id) { ret = __tcf_idr_release(p, false, true); if (ret == ACT_P_DELETED) { module_put(ops->owner); @@ -351,7 +351,7 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops, int ret; unsigned long id = 1; - idr_for_each_entry_ext(idr, p, id) { + idr_for_each_entry_ul(idr, p, id) { ret = __tcf_idr_release(p, false, true); if (ret == ACT_P_DELETED) module_put(ops->owner); From patchwork Wed Nov 29 20:19:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 842717 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Q1Fxjn1y"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynBjJ6KkYz9s4s for ; Thu, 30 Nov 2017 07:20:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbdK2UUD (ORCPT ); Wed, 29 Nov 2017 15:20:03 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:46894 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752573AbdK2UTh (ORCPT ); Wed, 29 Nov 2017 15:19:37 -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=vUtX5QqPIbYt7qyM9K/eKM2STqRMLe6HwqHT3lSGIag=; b=Q1Fxjn1yFpskz/JU56WfGjpHw ftOdzTyEJXRqebV/+xoZ1FmVJss0KTHL7lAgw3AUJ4DbU1zeIwR2UxjyFJKO1qWVCzmffoyqWXN4M 8nm5fTZicm3lVcrhaL7/I2gfRSPNt/0qSSNFWxKwPiW6gFDheWMXnAtMjK1kASKyNEbeqg8tYtlZ2 yTo1ef094pmtQYCn3f5vybkVfPuCUduveSmo1s5JOMdvZQwUxpdqTaWwyYcgSCepv1s9C0oT64W14 DUMShLd3bXfTUWz4RnCmjsGCNO/Un7Xrnoaucsb7meCp+t2KLpIMqXx1tG+RsJaQ6WBD+rSwsZ+sZ pgPmRXyeg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eK8pV-0006Oo-5N; Wed, 29 Nov 2017 20:19:37 +0000 From: Matthew Wilcox To: willy@infradead.org, netdev@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH v2 17/17] idr: Warn if old iterators see large IDs Date: Wed, 29 Nov 2017 12:19:22 -0800 Message-Id: <20171129201922.24370-18-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171129201922.24370-1-willy@infradead.org> References: <20171129201922.24370-1-willy@infradead.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthew Wilcox Now that the IDR can be used to store large IDs, it is possible somebody might only partially convert their old code and use the iterators which can only handle IDs up to INT_MAX. It's probably unwise to show them a truncated ID, so settle for spewing warnings to dmesg, and terminating the iteration. Signed-off-by: Matthew Wilcox --- lib/idr.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/idr.c b/lib/idr.c index 772a24513d1e..1aaeb5a8c426 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -145,7 +145,11 @@ int idr_for_each(const struct idr *idr, void __rcu **slot; radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) { - int ret = fn(iter.index, rcu_dereference_raw(*slot), data); + int ret; + + if (WARN_ON_ONCE(iter.index > INT_MAX)) + break; + ret = fn(iter.index, rcu_dereference_raw(*slot), data); if (ret) return ret; } @@ -173,6 +177,9 @@ void *idr_get_next(struct idr *idr, int *nextid) if (!slot) return NULL; + if (WARN_ON_ONCE(iter.index > INT_MAX)) + return NULL; + *nextid = iter.index; return rcu_dereference_raw(*slot); }