Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp93929imm; Thu, 21 Jun 2018 14:34:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL4KpJTgCpodjYl0+URFIajjsZGCEM5o+v6qu9r9moUs7woISeMMx+VohXmyHABNzVdK8Ds X-Received: by 2002:a17:902:d716:: with SMTP id w22-v6mr30056158ply.98.1529616844802; Thu, 21 Jun 2018 14:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616844; cv=none; d=google.com; s=arc-20160816; b=cqFp/WhM6naNfHIXxuwG4rPdmGqnWVCaGSa+qea92tNze+q81pxndq+c7lEhlZuEO2 rjRrD47+6uE+qk+FXW66O8CIyUb5ECyyAs5ss/fZ4uyTX/EiHptujcGZ7C1BLeCA9kos ksQH/G2zyF/JIHQWH6HUnY/l2YPmm69yO9kma6/NgugDd9I0KcnmyqXfY3B67iDur8N2 20v0zVsV0sdoUMWbucTnodIv3OcmitNjjbYBg8qhjkedJHCSikU8Yrw09I4NaDAocqH3 hylQ1sBHTjnZyyJybzXDdbzuhHv46DX2OhYEYeuuWSbm40/RMKAv7BhOVpW5aDY+N97q u9aw== 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=HNmaM8ejrAD4rksJ/dN/SH3rhwSSjX8xB4d6SnU8CqA=; b=Z83vm8rCiCPvdztmnRZcrP4UBFwi32ZP6qap+ZWr+IoTZdrmdNybtJuUqMRQ3xp/8F oMs4242aB4bz5TMXXkZoOF8VocLaRXRFIJMv4y58KbT4aCneUTuqlmQQcaZGKrKCptJe uw16Ho+hME7ujCIn7GzdptN696uvUTgT99oD5s1Vl/5BRbrlUACyux/9BC3s2lufq04D IZc9uf5DMbd35ejfDT0jvQ3GFLNqMpzU26U6j7Ol7q0CcldKpkhksjhx/1LAVaoIevoO WKr0FBnNaD0KK0TjZQlwLAdnxwkL4LtbONY3g/DIR04IZA7wAqc3gUb0CD/TdgDD1mDV 10qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=pwA4IRM2; 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 m6-v6si4690922pgu.644.2018.06.21.14.33.50; Thu, 21 Jun 2018 14:34:04 -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=pwA4IRM2; 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 S933823AbeFUVbo (ORCPT + 99 others); Thu, 21 Jun 2018 17:31:44 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41828 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933980AbeFUV3L (ORCPT ); Thu, 21 Jun 2018 17:29:11 -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=HNmaM8ejrAD4rksJ/dN/SH3rhwSSjX8xB4d6SnU8CqA=; b=pwA4IRM22wm/ctNTG2OhLT88V xArq7pYvXUgpI90BtkyYs0rp12IPxBEvNQ1RFydC1nLCpYXCxCHUNjA2IgOSF+ldQbZMs4k+weuGU 32wP0SqcACk0QP+Apy4YtfdYbEj9DMCI58kkHllXgjpIh5SPl7uhlcgb5YGmWw833lE+SgZBrcgGN pW1eASQl2O/2ogeyadUtw4L5ySOe/KcrcYXyRNZnRJ8FmfO2KQj/9WeCdo9BfITgINp3MOISE3i9d GGTkKMl4KzIBBjDFWGtPN0R/i0HJmJfH34JLS5Dj+m5jMlFgMXf/8tfa6tLxvp6vMRZEYoTExpcrc BFLkLA+2A==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78h-0001d3-4x; Thu, 21 Jun 2018 21:29:11 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Andrew Morton Subject: [PATCH 23/26] test_ida: Convert check_ida_conv to new API Date: Thu, 21 Jun 2018 14:28:32 -0700 Message-Id: <20180621212835.5636-24-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 Move as much as possible to kernel space; leave the parts in user space that rely on checking memory allocation failures to detect the transition between an exceptional entry and a bitmap. Signed-off-by: Matthew Wilcox --- lib/test_ida.c | 31 ++++++++++++++++ tools/testing/radix-tree/idr-test.c | 56 ++++++----------------------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/lib/test_ida.c b/lib/test_ida.c index e8ab544032f9..15e013800171 100644 --- a/lib/test_ida.c +++ b/lib/test_ida.c @@ -65,6 +65,36 @@ static void ida_check_max(struct ida *ida) } } +/* + * Check handling of conversions between exceptional entries and full bitmaps. + */ +static void ida_check_conv(struct ida *ida) +{ + unsigned long i; + int id; + + for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) { + IDA_BUG_ON(ida, ida_alloc_min(ida, i + 1, GFP_KERNEL) != i + 1); + IDA_BUG_ON(ida, ida_alloc_min(ida, i + BITS_PER_LONG, + GFP_KERNEL) != i + BITS_PER_LONG); + ida_free(ida, i + 1); + ida_free(ida, i + BITS_PER_LONG); + IDA_BUG_ON(ida, !ida_is_empty(ida)); + } + + for (i = 0; i < IDA_BITMAP_BITS * 2; i++) + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); + for (i = IDA_BITMAP_BITS * 2; i > 0; i--) + ida_free(ida, i - 1); + IDA_BUG_ON(ida, !ida_is_empty(ida)); + + for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); + for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) + ida_free(ida, i - 1); + IDA_BUG_ON(ida, !ida_is_empty(ida)); +} + static int ida_checks(void) { DEFINE_IDA(ida); @@ -74,6 +104,7 @@ static int ida_checks(void) ida_check_leaf(&ida, 1024); ida_check_leaf(&ida, 1024 * 64); ida_check_max(&ida); + ida_check_conv(&ida); printk("IDA: %u of %u tests passed\n", tests_passed, tests_run); return (tests_run != tests_passed) ? 0 : -EINVAL; diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c index bd9699327f95..f948e38b9a6b 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -339,59 +339,23 @@ void ida_check_nomem(void) /* * Check handling of conversions between exceptional entries and full bitmaps. */ -void ida_check_conv(void) +void ida_check_conv_user(void) { DEFINE_IDA(ida); - int id; unsigned long i; - for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) { - assert(ida_pre_get(&ida, GFP_KERNEL)); - assert(!ida_get_new_above(&ida, i + 1, &id)); - assert(id == i + 1); - assert(!ida_get_new_above(&ida, i + BITS_PER_LONG, &id)); - assert(id == i + BITS_PER_LONG); - ida_remove(&ida, i + 1); - ida_remove(&ida, i + BITS_PER_LONG); - assert(ida_is_empty(&ida)); - } - - assert(ida_pre_get(&ida, GFP_KERNEL)); - - for (i = 0; i < IDA_BITMAP_BITS * 2; i++) { - assert(ida_pre_get(&ida, GFP_KERNEL)); - assert(!ida_get_new(&ida, &id)); - assert(id == i); - } - - for (i = IDA_BITMAP_BITS * 2; i > 0; i--) { - ida_remove(&ida, i - 1); - } - assert(ida_is_empty(&ida)); - - for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) { - assert(ida_pre_get(&ida, GFP_KERNEL)); - assert(!ida_get_new(&ida, &id)); - assert(id == i); - } - - for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) { - ida_remove(&ida, i - 1); - } - assert(ida_is_empty(&ida)); - radix_tree_cpu_dead(1); for (i = 0; i < 1000000; i++) { - int err = ida_get_new(&ida, &id); - if (err == -EAGAIN) { - assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2)); - assert(ida_pre_get(&ida, GFP_KERNEL)); - err = ida_get_new(&ida, &id); + int id = ida_alloc(&ida, GFP_NOWAIT); + if (id == -ENOMEM) { + IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) != + (BITS_PER_LONG - 2)); + id = ida_alloc(&ida, GFP_KERNEL); } else { - assert((i % IDA_BITMAP_BITS) != (BITS_PER_LONG - 2)); + IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) == + (BITS_PER_LONG - 2)); } - assert(!err); - assert(id == i); + IDA_BUG_ON(&ida, id != i); } ida_destroy(&ida); } @@ -507,7 +471,7 @@ void user_ida_checks(void) ida_destroy(&ida); assert(ida_is_empty(&ida)); - ida_check_conv(); + ida_check_conv_user(); ida_check_random(); ida_simple_get_remove_test(); -- 2.17.1