Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753730AbdL1PAy (ORCPT ); Thu, 28 Dec 2017 10:00:54 -0500 Received: from mail-dm3nam03on0070.outbound.protection.outlook.com ([104.47.41.70]:63603 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753688AbdL1PAu (ORCPT ); Thu, 28 Dec 2017 10:00:50 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andrew Morton , Ben Hutchings , David Decotigny , "David S . Miller" , Geert Uytterhoeven , Matthew Wilcox , Rasmus Villemoes Subject: [PATCH 2/2] bitmap: replace bitmap_{from,to}_u32array Date: Thu, 28 Dec 2017 18:00:19 +0300 Message-Id: <20171228150019.27953-2-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171228150019.27953-1-ynorov@caviumnetworks.com> References: <20171228150019.27953-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [42.107.80.171] X-ClientProxiedBy: DB3PR0202CA0035.eurprd02.prod.outlook.com (2603:10a6:8:1::48) To CY4PR0701MB3827.namprd07.prod.outlook.com (2603:10b6:910:94::33) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f8ad405a-810c-414b-ab2f-08d54e03c788 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060);SRVR:CY4PR0701MB3827; X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3827;3:bhQk3sQAmuzogkchZPvxgnJqpd8+czesaznBV09ctS0hXW4t/tyutpn5UwWcwejoE2AS/w6H+EOl+vApu9+QQBL4tcITicwTT+sMoR+EGOy3ofX8yVhA6AjhDH64NQI52wBLpExGcwpLrI1iH5lDir0tvigKGbBY61JPFENNl/7P1ZqiFLKkU4iyF6XTNEHQgFnqa6H2Jt9nOJptJFFEvMj3B5lZfBKob+j9wSsBT4RdN8NfYnGWFVjtT2r3DhJb;25:x7Sx8iKvmhPUOB1JmICdTmYwXHQXMpss7FPHnO617gVwEnZc3kfBvn97CGpOK6eWR9dYgwHqrXH0HDsBY/GrM6ml6omu80kw6oRcwKfDWKHjYwWvfq88MJjlg5gqxKV3/Q0UEtjJyMXyhgwSr6Gj/FLeQ5m0msckWZaRbypDNcMz2GKQ9MD2jNO/DGBTcMZK8ye4dDVrGIBZPgKVAMfQijNxITe9CpWcSO6jWrY3eQtylJjHBD5qrnghrRLKFXDSFatUY6xkjbd4TkUgf8pFbDf4zoiMWZLi/36ocB/QLRJJMbbYWKrx5io2z3z5HpbO4O8U8xD7mQj/bbd45GUTAw==;31:llBOAriLRLDhQrUWGlU34xhydV9rSs1dhoUwRSt8/dChDFLJmnJRq809Q7v9hhJwAsohkKQPLno6Xed/mG6vKPi13XV5W5jKl3mcyQUymVgh1wchTXoov6BAzaV4NggjNEk2vWecVuQ7WhjHGCJWSqiV/qYdkwdnNYrJI5fjBpsIAXQ86bnnqopPTNgeYADp9UGvHB55+OQMiLban0VwXMQWoIBC4ATB4g1rcMn6Y/g= X-MS-TrafficTypeDiagnostic: CY4PR0701MB3827: X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3827;20:G4+xcXOZqOIqfQ9Y7+2ICwV2HwcaWR/bCST1Fsp8FGLpSSUowz14xOzQC4r5O8YfwjRhaZ8M8NwbMLz98FAmquwGEe9Fer3JWdm86C78B7hj3jzwTzyu0EtF+A/C1veHQy44FkD71sqZmOugydAh82Ksix841ovlBBUDcvJnVkP7YIVF3nvqpe0p6b/V5Vn2WFu5GhWvt+9lpNgu3P21YYkrLM3zAqOiIL+aFIHb+Ab+5j3kotjjflcItw7Q/Dz+uCmaodnI50FO78Oqy++J39YG9h58ZddMgVrG7ditXeduLZP57bw863mi7aMsF292aPqe+tUpm3fGOJGF/swqL0+EpsqAz9Xdo3o2FWrRLNjEo4I83W2fk2NaEkWGfZ9pZKsRiW+i7TklXobBZ/yZEk5tMr5cpgH41TmocVFDv8c2zM+P9ij28d8QsWiWB4ECNwT7GPlYUwK+PQT+FPWGFVNfeiw6KOwyqrP6d+QcMHOr6uVi0c1wxSVaV1Xpk5ZI6NTqL1D4NfQVsAd6VN8QqfTP3zLe+yiO5FBFaqy1WfH3Gj8JDoTMA6/zl09YkKe+HIyLLAkSnqCeT+jcCI1lEDPSpMtoFl8TCrbx/HuevAg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(89211679590171)(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(3231023)(944501075)(93006095)(3002001)(10201501046)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(6072148)(201708071742011);SRVR:CY4PR0701MB3827;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR0701MB3827; X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3827;4:nwKFgevO97tJGV5GULkE6qfzFkkWULtEJH9QsaiQg6/69q7ONRrD4CxahJDS0O0iTNyUh8CJfm9vTsHeewmW4NPVmP6unORyOc5bXolt/xYf+lsce6Q27mkpqxX3W9BUsDVurQRTytNj6yr+C5bjUTaSlji1mTG2oToNX9Xk04b921T7roH9eWs99dW/5rMLdKar/Y5TXJEK+FPSxkQkLMKhc1f8jq8NuAowImrzVaxJiqA/5OzWxHtFPEPbmmh993ZAqQjdj/jSQEGshwUSCUhvU68CPAW7coaj31AHig4fzjBv/GyRoQTyZy0D8UOx3Riqy5/72iKghU2EIqtXLg== X-Forefront-PRVS: 05352A48BE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(346002)(39380400002)(396003)(376002)(39860400002)(366004)(189003)(199004)(6486002)(2950100002)(3846002)(6116002)(68736007)(8936002)(66066001)(316002)(76176011)(51416003)(48376002)(478600001)(5660300001)(6496006)(6666003)(6916009)(42882006)(1076002)(52116002)(50466002)(47776003)(25786009)(2361001)(5009440100003)(97736004)(106356001)(2351001)(386003)(72206003)(81166006)(8676002)(16526018)(8666007)(4326008)(575784001)(59450400001)(81156014)(105586002)(305945005)(16586007)(76506005)(45080400002)(7736002)(50226002)(2906002)(36756003)(54906003)(53936002)(142933001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR0701MB3827;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR0701MB3827;23:33ZNKokvqjIycvYNiOkcY8xgfj8+pBNh2rfp7He?= =?us-ascii?Q?kcPYKXrAaHZE8LLoAZxKUCFCA45ZUZHmMHEQHm9lYVZJhzE8eH0WL0stvvx4?= =?us-ascii?Q?C9Muoe6sQWoaPHEAr3c0Dn5fWArybCGjtHXgwfU3UP6CrfoBt9QDMrobgIbU?= =?us-ascii?Q?+oljAlWzttYpUigpPbP3LdklWDeNbJskQWeRLoCvj/Ek2rEZebrMWs70WF8D?= =?us-ascii?Q?d0EsKnOrsMsu7p91pe44fpsz1SD+L/3xGOD3AfOcIj5UX7sMq1o2iXd+8grM?= =?us-ascii?Q?zDqNVng9tx5TQOmdyD+VsQHzEDxzGfjPr3sQhusj3TqGWx8O5Ul7mZT726r2?= =?us-ascii?Q?h5hktwsiwx6S2huoF2coFBx3qRlQreTypIw6flG8794r7Nz5us6yRz6nq+nG?= =?us-ascii?Q?QLtwCWNBr6CCEeUNc/DVtFCi4+AmAQ9Ghxh5yb0qf75CmycfzOelQdH8wh9q?= =?us-ascii?Q?7Y9Mj87e2Pck34VyYla3h8IJ9hIrrpABs4Fa+511o+gbTZRuWn5viEpuaiG9?= =?us-ascii?Q?48c/fmKcA8D4WabqwWYOqYwxqBPuVnz8hyNizWlm9eC5cXirUFnvXKE+I4TP?= =?us-ascii?Q?iW6qKVZM6FC/rLWzisFXi3gztN9rfrO7wS0Pg24ZIUKVrEHGQ3OFGQ8Y/+8h?= =?us-ascii?Q?97me5Awf2CAVW+c40eLk2oViWLyo0QxBdGta0AkI5w6QNWkHyHUnl01nreBC?= =?us-ascii?Q?DhWuQpoq3CS4f4HBe7S/aQMdC0as6kwCNngAr4sDINsSokngedchB/yyUx87?= =?us-ascii?Q?dMaqE+ehS3yK/77716EISdveAzFnwPDHS+LPKHoaTrECTvl26PFJ+TCpXAOH?= =?us-ascii?Q?eY31O3wormnAAqeOcL2vTgoANqaAINYYOwYjdkWULdX1UoIlr9mBDtuf/rX8?= =?us-ascii?Q?sg2wmw/5pJlhuHdeQVb3EGv+galLu3Xzjp5UKF1djkoSAzkx2mOacBnIXGon?= =?us-ascii?Q?411mHePrC3PZ5GfV4tKOkRVLQNinuWtwJHqpA5BMmEqo6wYqr8p506TZbFoQ?= =?us-ascii?Q?0CRTJDveWvgboUFD2rjmB+SJVrHMFXwLRmDx2QIFu+WKmkulfAZXY837gUNN?= =?us-ascii?Q?cpB6vIjGgb7Ti6oqth/Iu0LO/m6pu8a1+QFK8VM6tCNdzJzTi9iZPNJ4Xl5B?= =?us-ascii?Q?TxpvH+ri5phuRcIIi8CFnxlx2sVAAND1EbTdUtITkEeRISYd4tFUEnWbLonu?= =?us-ascii?Q?DwOXxWb+wHC51eb6NBVWuJGxSxVX6dcMiSCOByH8am72OJJ7SZlZSn+iGyBE?= =?us-ascii?Q?2oz2kOo21e+HL6N0YlyXzTnCR/QzfuRvhevF2q7/HC7sDUmud9PtfawcWYFU?= =?us-ascii?Q?bhe4o2uDHGpIBNOFtctMr3UoFdnYUgOxknDIBuI0U1CS3?= X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3827;6:gAiHXbEKY1fUFbWRwdkOlOxGkb2L9zDJZEut60tW3q3iMWvMKzDFu4VgQewrhaZmVTwc+o4EZtis45+tIWZl2XWzXcPeiYjBRnRFmgUVv7yGA8TtqrHhqli/T1rlo/HJ8+J66qH0GY0duCPWYjVmR3yFHas45NFQUpY1KVa+TysrC+ogziT2JuDKAhgQMjvH/9ius16InZOCCB5Ed3mujMIS4qCaHzjlgEJ45KX+jYGoiWQYHrzVhL0eMiMELzg1FGIid5AQjiUu01WiIXxftEj4AbOfBMarWfWRGV4Z7Jwfqz43KjjfWGnAeaDCzq5En1VAbJKCRQiCZpczVvvOkJax5PsTMJ0Fn4BtaQPo8Wc=;5:+OP+Vbpg1JSNByMbnmwKSF6jAaakMgpYbpVzRaGuHixqmBn+pRGPrkEYC16VM5UBbf9xkOBYtYSe3aVanwIy4ExdX+dVlJm+ks1bK7wSL07Xz/5HUBvwxSL3dLcMuzetYwgQ8rbJagq73Rw9LGj/r9r2B5eFqH52J9PpM89yEd0=;24:cUfsET+nQ7WrZvahFAD5NTuhR4fAqKeBDfXTZZPoFmhtS69z6VkSw62pfEAs8yVjI0h4oaxN/vkKze5Eg/gdpwagccQOy3zNTN+z9TByL6A=;7:0q//bhiyo9/5RYDgTqeRtsEDdcEO5r3wHilJGQ6uu6Vr0/cBuRi7W4ySu4tjNDzwwtxKW1OkbHo7OAoLycGVmzS1095cEDZNIuWwCyAPG2JDvZND3VRLh3IiJRxwHFZRork7XqrMP5YZlLBinBh6PqdK8ZEDZy8d/XjIUYcLhYvyUQPWe27fMcLMLTbUryBJUtsiWUT7hXmQkQ2OWYu1AgQGShu95NGm9WDEcJeUC0RBa788XuJAZP1jV2l4kDur SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Dec 2017 15:00:47.3378 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8ad405a-810c-414b-ab2f-08d54e03c788 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3827 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 16807 Lines: 503 with bitmap_{from,to}_arr32 over the kernel. Additionally to it: * __check_eq_bitmap() now takes single nbits argument. * __check_eq_u32_array is not used in new test but may be used in future. So I don't remove it here, but annotate as __used. Tested on arm64 and 32-bit BE mips. CC: Andrew Morton CC: Ben Hutchings CC: David Decotigny , CC: David S. Miller , CC: Geert Uytterhoeven CC: Matthew Wilcox CC: Rasmus Villemoes Signed-off-by: Yury Norov --- arch/arm64/kernel/perf_event.c | 5 +- include/linux/bitmap.h | 11 +-- lib/bitmap.c | 87 ----------------- lib/test_bitmap.c | 206 +++++++---------------------------------- net/core/ethtool.c | 53 +++++------ 5 files changed, 55 insertions(+), 307 deletions(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 3affca3dd96a..75b220ba73a3 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -925,9 +925,8 @@ static void __armv8pmu_probe_pmu(void *info) pmceid[0] = read_sysreg(pmceid0_el0); pmceid[1] = read_sysreg(pmceid1_el0); - bitmap_from_u32array(cpu_pmu->pmceid_bitmap, - ARMV8_PMUV3_MAX_COMMON_EVENTS, pmceid, - ARRAY_SIZE(pmceid)); + bitmap_from_arr32(cpu_pmu->pmceid_bitmap, + pmceid, ARMV8_PMUV3_MAX_COMMON_EVENTS); } static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 748eba1622b9..757af9bc4d36 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -64,8 +64,6 @@ * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region * bitmap_release_region(bitmap, pos, order) Free specified bit region * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region - * bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words) - * bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words) * bitmap_from_arr32(dst, buf, nbits) Copy nbits from u32[] buf to dst * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst * @@ -176,14 +174,7 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig, extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); -extern unsigned int bitmap_from_u32array(unsigned long *bitmap, - unsigned int nbits, - const u32 *buf, - unsigned int nwords); -extern unsigned int bitmap_to_u32array(u32 *buf, - unsigned int nwords, - const unsigned long *bitmap, - unsigned int nbits); + #ifdef __BIG_ENDIAN extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits); #else diff --git a/lib/bitmap.c b/lib/bitmap.c index 47fe6441562c..9e498c77ed0e 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1106,93 +1106,6 @@ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) EXPORT_SYMBOL(bitmap_allocate_region); /** - * bitmap_from_u32array - copy the contents of a u32 array of bits to bitmap - * @bitmap: array of unsigned longs, the destination bitmap, non NULL - * @nbits: number of bits in @bitmap - * @buf: array of u32 (in host byte order), the source bitmap, non NULL - * @nwords: number of u32 words in @buf - * - * copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining - * bits between nword and nbits in @bitmap (if any) are cleared. In - * last word of @bitmap, the bits beyond nbits (if any) are kept - * unchanged. - * - * Return the number of bits effectively copied. - */ -unsigned int -bitmap_from_u32array(unsigned long *bitmap, unsigned int nbits, - const u32 *buf, unsigned int nwords) -{ - unsigned int dst_idx, src_idx; - - for (src_idx = dst_idx = 0; dst_idx < BITS_TO_LONGS(nbits); ++dst_idx) { - unsigned long part = 0; - - if (src_idx < nwords) - part = buf[src_idx++]; - -#if BITS_PER_LONG == 64 - if (src_idx < nwords) - part |= ((unsigned long) buf[src_idx++]) << 32; -#endif - - if (dst_idx < nbits/BITS_PER_LONG) - bitmap[dst_idx] = part; - else { - unsigned long mask = BITMAP_LAST_WORD_MASK(nbits); - - bitmap[dst_idx] = (bitmap[dst_idx] & ~mask) - | (part & mask); - } - } - - return min_t(unsigned int, nbits, 32*nwords); -} -EXPORT_SYMBOL(bitmap_from_u32array); - -/** - * bitmap_to_u32array - copy the contents of bitmap to a u32 array of bits - * @buf: array of u32 (in host byte order), the dest bitmap, non NULL - * @nwords: number of u32 words in @buf - * @bitmap: array of unsigned longs, the source bitmap, non NULL - * @nbits: number of bits in @bitmap - * - * copy min(nbits, 32*nwords) bits from @bitmap to @buf. Remaining - * bits after nbits in @buf (if any) are cleared. - * - * Return the number of bits effectively copied. - */ -unsigned int -bitmap_to_u32array(u32 *buf, unsigned int nwords, - const unsigned long *bitmap, unsigned int nbits) -{ - unsigned int dst_idx = 0, src_idx = 0; - - while (dst_idx < nwords) { - unsigned long part = 0; - - if (src_idx < BITS_TO_LONGS(nbits)) { - part = bitmap[src_idx]; - if (src_idx >= nbits/BITS_PER_LONG) - part &= BITMAP_LAST_WORD_MASK(nbits); - src_idx++; - } - - buf[dst_idx++] = part & 0xffffffffUL; - -#if BITS_PER_LONG == 64 - if (dst_idx < nwords) { - part >>= 32; - buf[dst_idx++] = part & 0xffffffffUL; - } -#endif - } - - return min_t(unsigned int, nbits, 32*nwords); -} -EXPORT_SYMBOL(bitmap_to_u32array); - -/** * bitmap_copy_le - copy a bitmap, putting the bits into little-endian order. * @dst: destination buffer * @src: bitmap to copy diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index aa1f2669bdd5..de7ef2996a07 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -23,7 +23,7 @@ __check_eq_uint(const char *srcfile, unsigned int line, const unsigned int exp_uint, unsigned int x) { if (exp_uint != x) { - pr_warn("[%s:%u] expected %u, got %u\n", + pr_err("[%s:%u] expected %u, got %u\n", srcfile, line, exp_uint, x); return false; } @@ -33,19 +33,13 @@ __check_eq_uint(const char *srcfile, unsigned int line, static bool __init __check_eq_bitmap(const char *srcfile, unsigned int line, - const unsigned long *exp_bmap, unsigned int exp_nbits, - const unsigned long *bmap, unsigned int nbits) + const unsigned long *exp_bmap, const unsigned long *bmap, + unsigned int nbits) { - if (exp_nbits != nbits) { - pr_warn("[%s:%u] bitmap length mismatch: expected %u, got %u\n", - srcfile, line, exp_nbits, nbits); - return false; - } - if (!bitmap_equal(exp_bmap, bmap, nbits)) { pr_warn("[%s:%u] bitmaps contents differ: expected \"%*pbl\", got \"%*pbl\"\n", srcfile, line, - exp_nbits, exp_bmap, nbits, bmap); + nbits, exp_bmap, nbits, bmap); return false; } return true; @@ -69,6 +63,10 @@ __check_eq_pbl(const char *srcfile, unsigned int line, static bool __init __check_eq_u32_array(const char *srcfile, unsigned int line, const u32 *exp_arr, unsigned int exp_len, + const u32 *arr, unsigned int len) __used; +static bool __init +__check_eq_u32_array(const char *srcfile, unsigned int line, + const u32 *exp_arr, unsigned int exp_len, const u32 *arr, unsigned int len) { if (exp_len != len) { @@ -255,171 +253,29 @@ static void __init test_bitmap_parselist(void) } } -static void __init test_bitmap_u32_array_conversions(void) +static void __init test_bitmap_arr32(void) { - DECLARE_BITMAP(bmap1, 1024); - DECLARE_BITMAP(bmap2, 1024); - u32 exp_arr[32], arr[32]; - unsigned nbits; - - for (nbits = 0 ; nbits < 257 ; ++nbits) { - const unsigned int used_u32s = DIV_ROUND_UP(nbits, 32); - unsigned int i, rv; - - bitmap_zero(bmap1, nbits); - bitmap_set(bmap1, nbits, 1024 - nbits); /* garbage */ - - memset(arr, 0xff, sizeof(arr)); - rv = bitmap_to_u32array(arr, used_u32s, bmap1, nbits); - expect_eq_uint(nbits, rv); - - memset(exp_arr, 0xff, sizeof(exp_arr)); - memset(exp_arr, 0, used_u32s*sizeof(*exp_arr)); - expect_eq_u32_array(exp_arr, 32, arr, 32); - - bitmap_fill(bmap2, 1024); - rv = bitmap_from_u32array(bmap2, nbits, arr, used_u32s); - expect_eq_uint(nbits, rv); - expect_eq_bitmap(bmap1, 1024, bmap2, 1024); - - for (i = 0 ; i < nbits ; ++i) { - /* - * test conversion bitmap -> u32[] - */ - - bitmap_zero(bmap1, 1024); - __set_bit(i, bmap1); - bitmap_set(bmap1, nbits, 1024 - nbits); /* garbage */ - - memset(arr, 0xff, sizeof(arr)); - rv = bitmap_to_u32array(arr, used_u32s, bmap1, nbits); - expect_eq_uint(nbits, rv); - - /* 1st used u32 words contain expected bit set, the - * remaining words are left unchanged (0xff) - */ - memset(exp_arr, 0xff, sizeof(exp_arr)); - memset(exp_arr, 0, used_u32s*sizeof(*exp_arr)); - exp_arr[i/32] = (1U<<(i%32)); - expect_eq_u32_array(exp_arr, 32, arr, 32); - - - /* same, with longer array to fill - */ - memset(arr, 0xff, sizeof(arr)); - rv = bitmap_to_u32array(arr, 32, bmap1, nbits); - expect_eq_uint(nbits, rv); - - /* 1st used u32 words contain expected bit set, the - * remaining words are all 0s - */ - memset(exp_arr, 0, sizeof(exp_arr)); - exp_arr[i/32] = (1U<<(i%32)); - expect_eq_u32_array(exp_arr, 32, arr, 32); - - /* - * test conversion u32[] -> bitmap - */ - - /* the 1st nbits of bmap2 are identical to - * bmap1, the remaining bits of bmap2 are left - * unchanged (all 1s) - */ - bitmap_fill(bmap2, 1024); - rv = bitmap_from_u32array(bmap2, nbits, - exp_arr, used_u32s); - expect_eq_uint(nbits, rv); - - expect_eq_bitmap(bmap1, 1024, bmap2, 1024); - - /* same, with more bits to fill - */ - memset(arr, 0xff, sizeof(arr)); /* garbage */ - memset(arr, 0, used_u32s*sizeof(u32)); - arr[i/32] = (1U<<(i%32)); - - bitmap_fill(bmap2, 1024); - rv = bitmap_from_u32array(bmap2, 1024, arr, used_u32s); - expect_eq_uint(used_u32s*32, rv); - - /* the 1st nbits of bmap2 are identical to - * bmap1, the remaining bits of bmap2 are cleared - */ - bitmap_zero(bmap1, 1024); - __set_bit(i, bmap1); - expect_eq_bitmap(bmap1, 1024, bmap2, 1024); - - - /* - * test short conversion bitmap -> u32[] (1 - * word too short) - */ - if (used_u32s > 1) { - bitmap_zero(bmap1, 1024); - __set_bit(i, bmap1); - bitmap_set(bmap1, nbits, - 1024 - nbits); /* garbage */ - memset(arr, 0xff, sizeof(arr)); - - rv = bitmap_to_u32array(arr, used_u32s - 1, - bmap1, nbits); - expect_eq_uint((used_u32s - 1)*32, rv); - - /* 1st used u32 words contain expected - * bit set, the remaining words are - * left unchanged (0xff) - */ - memset(exp_arr, 0xff, sizeof(exp_arr)); - memset(exp_arr, 0, - (used_u32s-1)*sizeof(*exp_arr)); - if ((i/32) < (used_u32s - 1)) - exp_arr[i/32] = (1U<<(i%32)); - expect_eq_u32_array(exp_arr, 32, arr, 32); - } - - /* - * test short conversion u32[] -> bitmap (3 - * bits too short) - */ - if (nbits > 3) { - memset(arr, 0xff, sizeof(arr)); /* garbage */ - memset(arr, 0, used_u32s*sizeof(*arr)); - arr[i/32] = (1U<<(i%32)); - - bitmap_zero(bmap1, 1024); - rv = bitmap_from_u32array(bmap1, nbits - 3, - arr, used_u32s); - expect_eq_uint(nbits - 3, rv); - - /* we are expecting the bit < nbits - - * 3 (none otherwise), and the rest of - * bmap1 unchanged (0-filled) - */ - bitmap_zero(bmap2, 1024); - if (i < nbits - 3) - __set_bit(i, bmap2); - expect_eq_bitmap(bmap2, 1024, bmap1, 1024); - - /* do the same with bmap1 initially - * 1-filled - */ - - bitmap_fill(bmap1, 1024); - rv = bitmap_from_u32array(bmap1, nbits - 3, - arr, used_u32s); - expect_eq_uint(nbits - 3, rv); - - /* we are expecting the bit < nbits - - * 3 (none otherwise), and the rest of - * bmap1 unchanged (1-filled) - */ - bitmap_zero(bmap2, 1024); - if (i < nbits - 3) - __set_bit(i, bmap2); - bitmap_set(bmap2, nbits-3, 1024 - nbits + 3); - expect_eq_bitmap(bmap2, 1024, bmap1, 1024); - } - } + unsigned int nbits, next_bit, len = sizeof(exp) * 8; + u32 arr[sizeof(exp) / 4]; + DECLARE_BITMAP(bmap2, len); + + memset(arr, 0xa5, sizeof(arr)); + + for (nbits = 0; nbits < len; ++nbits) { + bitmap_to_arr32(arr, exp, nbits); + bitmap_from_arr32(bmap2, arr, nbits); + expect_eq_bitmap(bmap2, exp, nbits); + + next_bit = find_next_bit(bmap2, + round_up(nbits, BITS_PER_LONG), nbits); + if (next_bit < round_up(nbits, BITS_PER_LONG)) + pr_err("bitmap_copy_arr32(nbits == %d:" + " tail is not safely cleared: %d\n", + nbits, next_bit); + + if (nbits < len - 32) + expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)], + 0xa5a5a5a5); } } @@ -454,7 +310,7 @@ static void noinline __init test_mem_optimisations(void) static int __init test_bitmap_init(void) { test_zero_fill_copy(); - test_bitmap_u32_array_conversions(); + test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); diff --git a/net/core/ethtool.c b/net/core/ethtool.c index f8fcf450a36e..76f6ae37dd15 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -615,18 +615,15 @@ static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to, return -EFAULT; memcpy(&to->base, &link_usettings.base, sizeof(to->base)); - bitmap_from_u32array(to->link_modes.supported, - __ETHTOOL_LINK_MODE_MASK_NBITS, - link_usettings.link_modes.supported, - __ETHTOOL_LINK_MODE_MASK_NU32); - bitmap_from_u32array(to->link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS, - link_usettings.link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NU32); - bitmap_from_u32array(to->link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS, - link_usettings.link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NU32); + bitmap_from_arr32(to->link_modes.supported, + link_usettings.link_modes.supported, + __ETHTOOL_LINK_MODE_MASK_NBITS); + bitmap_from_arr32(to->link_modes.advertising, + link_usettings.link_modes.advertising, + __ETHTOOL_LINK_MODE_MASK_NBITS); + bitmap_from_arr32(to->link_modes.lp_advertising, + link_usettings.link_modes.lp_advertising, + __ETHTOOL_LINK_MODE_MASK_NBITS); return 0; } @@ -642,18 +639,15 @@ store_link_ksettings_for_user(void __user *to, struct ethtool_link_usettings link_usettings; memcpy(&link_usettings.base, &from->base, sizeof(link_usettings)); - bitmap_to_u32array(link_usettings.link_modes.supported, - __ETHTOOL_LINK_MODE_MASK_NU32, - from->link_modes.supported, - __ETHTOOL_LINK_MODE_MASK_NBITS); - bitmap_to_u32array(link_usettings.link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NU32, - from->link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS); - bitmap_to_u32array(link_usettings.link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NU32, - from->link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS); + bitmap_to_arr32(link_usettings.link_modes.supported, + from->link_modes.supported, + __ETHTOOL_LINK_MODE_MASK_NU32); + bitmap_to_arr32(link_usettings.link_modes.advertising, + from->link_modes.advertising, + __ETHTOOL_LINK_MODE_MASK_NU32); + bitmap_to_arr32(link_usettings.link_modes.lp_advertising, + from->link_modes.lp_advertising, + __ETHTOOL_LINK_MODE_MASK_NU32); if (copy_to_user(to, &link_usettings, sizeof(link_usettings))) return -EFAULT; @@ -2359,10 +2353,8 @@ static int ethtool_get_per_queue_coalesce(struct net_device *dev, useraddr += sizeof(*per_queue_opt); - bitmap_from_u32array(queue_mask, - MAX_NUM_QUEUE, - per_queue_opt->queue_mask, - DIV_ROUND_UP(MAX_NUM_QUEUE, 32)); + bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, + MAX_NUM_QUEUE); for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; @@ -2394,10 +2386,7 @@ static int ethtool_set_per_queue_coalesce(struct net_device *dev, useraddr += sizeof(*per_queue_opt); - bitmap_from_u32array(queue_mask, - MAX_NUM_QUEUE, - per_queue_opt->queue_mask, - DIV_ROUND_UP(MAX_NUM_QUEUE, 32)); + bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, MAX_NUM_QUEUE); n_queue = bitmap_weight(queue_mask, MAX_NUM_QUEUE); tmp = backup = kmalloc_array(n_queue, sizeof(*backup), GFP_KERNEL); if (!backup) -- 2.11.0