Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1125797ybh; Tue, 10 Mar 2020 15:19:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs4KAXSCncOCGfQAsybBwLyrUlqvQbu222HX4vaDYnScAxjyg95Gk+wPMlcQtypSG6yt/eM X-Received: by 2002:aca:ea0a:: with SMTP id i10mr2828953oih.12.1583878778182; Tue, 10 Mar 2020 15:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583878778; cv=none; d=google.com; s=arc-20160816; b=qUzdut30B1t4BHWZiGmzd7EgWzVHk9lowrKWfDVmsGFn166Jynl2qxP2Ri9M+r/hGY hWSvGMoHmP0VD9uI+JGNgn93yR0B5Prb1wbB2AZOt6C9WD9BGfwk7kSu9TvS1g/3piTD ICzXynlZ3ye3z3Xfuew9ooJyfJUUUSmu5dZ0g3fFbrx57iJQWfKndnZWJEGHd8PkFe+E XflF/VLvrLPMpXtw/RB2OpsLZOPp5EL8KcsqYKguy7pMS2PRC9fDf5EoDFpqOdtA1eAr oCX5PtWrH/FsDum7tTxYlsO+710ahDzl0drQUvO9q8t6y4gA7z74dk2eXikK9atjopJO iH/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HVBtSACsOO/j2fq3aUXvURF13Z2lci6QGNbXcyMVHjo=; b=NoiR2exM4xaslsq2NxqvTJcRft3J+3bUKUIzi9lqmAXejoDTuzqJA6OaTFvIcrHZFL yBZQYQnLH2vSw1q3t/oG+krPyExjIRZuBwXdcbLqdvKTt40wa3HL5+CwFU/d7EjNVQdv yeTuC6zWMT0X5I15ZkUiDTgQXGFq7YlnUymgG657TrIMkmbazFvxDiWNsTenZjHsLZ2n aNaK3VRPR8BJJa0366OD3JKsl3g0LYO0VO6PZHiv6KsKvJFtHgw7gCL2xuj7XnfUSFhE UvKzf8HT2FP4zl3bBBu/TSUH9Px29KwfQwgTpq0b7swDUEYWgMJiq5PGxDyGg7BZT2e/ dw+A== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v15si3887oth.307.2020.03.10.15.19.25; Tue, 10 Mar 2020 15:19:38 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbgCJWSB (ORCPT + 99 others); Tue, 10 Mar 2020 18:18:01 -0400 Received: from mga01.intel.com ([192.55.52.88]:2024 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727311AbgCJWSA (ORCPT ); Tue, 10 Mar 2020 18:18:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Mar 2020 15:18:00 -0700 X-IronPort-AV: E=Sophos;i="5.70,538,1574150400"; d="scan'208";a="277130850" Received: from jbrandeb-desk.jf.intel.com ([10.166.244.152]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Mar 2020 15:17:59 -0700 From: Jesse Brandeburg To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: Jesse Brandeburg , x86@kernel.org, linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk, andriy.shevchenko@intel.com, dan.j.williams@intel.com, peterz@infradead.org Subject: [PATCH v6 2/2] lib: make a test module with set/clear bit Date: Tue, 10 Mar 2020 15:17:47 -0700 Message-Id: <20200310221747.2848474-2-jesse.brandeburg@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200310221747.2848474-1-jesse.brandeburg@intel.com> References: <20200310221747.2848474-1-jesse.brandeburg@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test some bit clears/sets to make sure assembly doesn't change, and that the set_bit and clear_bit functions work and don't cause sparse warnings. Instruct Kbuild to build this file with extra warning level -Wextra, to catch new issues, and also doesn't hurt to build with C=1. This was used to test changes to arch/x86/include/asm/bitops.h. In particular, sparse (C=1) was very concerned when the last bit before a natural boundary, like 7, or 31, was being tested, as this causes sign extension (0xffffff7f) for instance when clearing bit 7. Recommended usage: make defconfig scripts/config -m CONFIG_TEST_BITOPS make modules_prepare make C=1 W=1 lib/test_bitops.ko objdump -S -d lib/test_bitops.ko insmod lib/test_bitops.ko rmmod lib/test_bitops.ko , there should be no compiler/sparse warnings and no error messages in log. Signed-off-by: Jesse Brandeburg Reviewed-by: Andy Shevchenko --- v5: no change v4: Slight change to bitops_fun last member, as suggested by Andy, added his reviewed-by too. Added module load/unload to usage. Added copyright. v3: Update the test to fail if bits aren't cleared, and make the test reproduce the original issue without patch 1/2, showing that the issue is fixed in patch 1/2. Thanks PeterZ! v2: Correct CC: list --- lib/Kconfig.debug | 13 +++++++ lib/Makefile | 2 + lib/test_bitops.c | 60 ++++++++++++++++++++++++++++++ tools/testing/selftests/lib/config | 1 + 4 files changed, 76 insertions(+) create mode 100644 lib/test_bitops.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 69def4a9df00..61a5d00ea064 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1947,6 +1947,19 @@ config TEST_LKM If unsure, say N. +config TEST_BITOPS + tristate "Test module for compilation of clear_bit/set_bit operations" + depends on m + help + This builds the "test_bitops" module that is much like the + TEST_LKM module except that it does a basic exercise of the + clear_bit and set_bit macros to make sure there are no compiler + warnings from C=1 sparse checker or -Wextra compilations. It has + no dependencies and doesn't run or load unless explicitly requested + by name. for example: modprobe test_bitops. + + If unsure, say N. + config TEST_VMALLOC tristate "Test module for stress/performance analysis of vmalloc allocator" default n diff --git a/lib/Makefile b/lib/Makefile index 611872c06926..b18db565b355 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -89,6 +89,8 @@ obj-$(CONFIG_TEST_OBJAGG) += test_objagg.o obj-$(CONFIG_TEST_STACKINIT) += test_stackinit.o obj-$(CONFIG_TEST_BLACKHOLE_DEV) += test_blackhole_dev.o obj-$(CONFIG_TEST_MEMINIT) += test_meminit.o +obj-$(CONFIG_TEST_BITOPS) += test_bitops.o +CFLAGS_test_bitops.o += -Werror obj-$(CONFIG_TEST_LIVEPATCH) += livepatch/ diff --git a/lib/test_bitops.c b/lib/test_bitops.c new file mode 100644 index 000000000000..fd50b3ae4a14 --- /dev/null +++ b/lib/test_bitops.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 Intel Corporation + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include + +/* a tiny module only meant to test set/clear_bit */ + +/* use an enum because thats the most common BITMAP usage */ +enum bitops_fun { + BITOPS_4 = 4, + BITOPS_7 = 7, + BITOPS_11 = 11, + BITOPS_31 = 31, + BITOPS_88 = 88, + BITOPS_LAST = 255, + BITOPS_LENGTH = 256 +}; + +static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH); + +static int __init test_bitops_startup(void) +{ + pr_warn("Loaded test module\n"); + set_bit(BITOPS_4, g_bitmap); + set_bit(BITOPS_7, g_bitmap); + set_bit(BITOPS_11, g_bitmap); + set_bit(BITOPS_31, g_bitmap); + set_bit(BITOPS_88, g_bitmap); + return 0; +} + +static void __exit test_bitops_unstartup(void) +{ + int bit_set; + + clear_bit(BITOPS_4, g_bitmap); + clear_bit(BITOPS_7, g_bitmap); + clear_bit(BITOPS_11, g_bitmap); + clear_bit(BITOPS_31, g_bitmap); + clear_bit(BITOPS_88, g_bitmap); + + bit_set = find_first_bit(g_bitmap, BITOPS_LAST); + if (bit_set != BITOPS_LAST) + pr_err("ERROR: FOUND SET BIT %d\n", bit_set); + + pr_warn("Unloaded test module\n"); +} + +module_init(test_bitops_startup); +module_exit(test_bitops_unstartup); + +MODULE_AUTHOR("Jesse Brandeburg "); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Bit testing module"); diff --git a/tools/testing/selftests/lib/config b/tools/testing/selftests/lib/config index 14a77ea4a8da..b80ee3f6e265 100644 --- a/tools/testing/selftests/lib/config +++ b/tools/testing/selftests/lib/config @@ -2,3 +2,4 @@ CONFIG_TEST_PRINTF=m CONFIG_TEST_BITMAP=m CONFIG_PRIME_NUMBERS=m CONFIG_TEST_STRSCPY=m +CONFIG_TEST_BITOPS=m -- 2.24.1