Received: by 10.223.164.202 with SMTP id h10csp921553wrb; Wed, 15 Nov 2017 10:03:34 -0800 (PST) X-Google-Smtp-Source: AGs4zMbEIlTO7Zw5MivVAJvKoydj4cxwiYueXGEX1KaSuu8tVGYE7GIaQya/GCUpuUNnaKVqd/Wm X-Received: by 10.101.74.193 with SMTP id c1mr781083pgu.369.1510769014334; Wed, 15 Nov 2017 10:03:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510769014; cv=none; d=google.com; s=arc-20160816; b=ynLo3Nb0KsVJzNUdo6gLRUsJciS3jsYey66bw1jFBhX5q881Ur1uBTfFy9sTc7q2nF L7lNfLsEUvgnOA7l0ScPyAYN/t1m1r9AJiItDLOSlfAlohZnGUqXTtx6HXVYiYjqh25R f3hUIe4JekzMWVVGaQR+icmf4mNPShiQ8qRjIJVwUQMqOmfp33ua1BOgPpNokie/h9Lg dFW3rG3fC4+yhF/x1Om8JTu1T/8jsijW+2CwFpoVWqwDoN0MULNOwbeDCAL9SNeBzOnK wiB8pCCa5DvY1NA/OiTNK8Tj4F4QAfLWszzOUO/UGTkLPF69P668EIZdoPlshTJKN5Jm /2ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=XCXA5W8GERIM3Va3E1VSpeLy1oRAnufrhMHM64pKlfA=; b=opzGfJ2c74WBhxgEYjBlsz/NkX2CvecBS9NmpH2TbAjtoWTVAlih4wpOjvFYQcUO8H NjRyjv+lr3kzMipIvL6lvEazGI4HC01KCZUWn2Q45y8KD+nk0UF+C7YSCR44Dn2EXiK7 ozjB39vm2a7qoBm7X8aydxm7w1zpp+hdwIZxhnbS5ByDfIj+0A+XqyIkWglOfCYwSTSB WMt3uznz52iC+Ul8FJUwSOmxpFY2BSf4xXoDeta0MVQSJiD34JuW8ccf0cMem78AvOSb YGUXmk6DIdLr5haO6mTToqugsAudpyZGNo4vzU8ZcObZEdXmAwVvr5eyr53BlLzujLJZ 7m5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=dGJEblBy; 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 a8si18254531ple.684.2017.11.15.10.03.20; Wed, 15 Nov 2017 10:03:34 -0800 (PST) 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=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=dGJEblBy; 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 S933005AbdKORlW (ORCPT + 90 others); Wed, 15 Nov 2017 12:41:22 -0500 Received: from mail-bn3nam01on0079.outbound.protection.outlook.com ([104.47.33.79]:14464 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932960AbdKORlO (ORCPT ); Wed, 15 Nov 2017 12:41:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XCXA5W8GERIM3Va3E1VSpeLy1oRAnufrhMHM64pKlfA=; b=dGJEblBy5GgqrmRrhsSx7YO63r/2wROrG2GpGZ6K5Qw+Ym0JnJfp4oG6qP9aCzvE4Lbbg11vzo9xtx6jbmfA4I8RKEBCJO7hRuvLoB8b1bwiigbyxL6lRqS5+GjDcAI3f+cxgzj0BKVtN0z7GVBZcM/Xu63BQY4H4/LIPt7TkbQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; Received: from localhost (50.233.148.156) by CY4PR0701MB3827.namprd07.prod.outlook.com (2603:10b6:910:94::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Wed, 15 Nov 2017 17:41:11 +0000 From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andrew Morton , Ben Hutchings , David Decotigny , "David S . Miller" , Matthew Wilcox , Rasmus Villemoes Subject: [PATCH RFC] lib: simplify bitmap_from_u32array API Date: Wed, 15 Nov 2017 20:40:56 +0300 Message-Id: <20171115174056.26537-1-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: DB3PR0202CA0013.eurprd02.prod.outlook.com (2603:10a6:8:1::26) To CY4PR0701MB3827.namprd07.prod.outlook.com (2603:10b6:910:94::33) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: efccf076-bbee-45f2-9b5f-08d52c501054 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199);SRVR:CY4PR0701MB3827; X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3827;3:xpgWswllCEbfARGX8YWMmgjkTlC8LFntgv7phx9x0U3+cfIHqucPyJ8QM0jEO/X9x7ehXbriG/CtfNpO4OpD04LG1xc1hwZfXKHA0GsVTQHvw/OEKPASdXLdgFMD3bLtFREP7lsDW0BgeLIUdFShva2aqegtcMzResn281YxXlw1HfC6aYciV+s9rzVrB2L3lC6zHBiH4CA/zfeP4SJyYb9jQnjDOXQHKvH90zht50JknjN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0UHHSLHBAej32JT/SRGuq2I6ISzPsY82aIsfhHypKEnXXNE9K/T2QkA+lxpm/emQ/zc+XKN25kXcKzEAWPkARkM5UPz2LBbygGjtwLuFjdJHV5Nxgr93aBtxggU9pXigXi8878ZFseX7eaLH6uaR0FLN0BfEtxQ3MLNHKKzcK7dHIUB+SVkB1c/36fFppGYuiPs4OiZnLvw7CZ1i5afmC2xltguxss=;4:8JooCKn45HPXj2lzIcxNRPze7Cs1VfY5WexVAHULcoo/eIQVzToShfrakcvVBQyzVK8UcprliVlwzHp9ZPqtrHoJCDZujdTSAaEmaNL+7bKcUYQpvwb3WoFdr8dJZeY0yFGMufzv0v128FDLKhzT8VjJwxbItSXWUOlPY+vOU7mLI4N/AloTCtUcHRHr3p0jg8ZnUVCKWxKXF/zfOzZd/dstGNWKwgxo36pGU4LkgjgMEnHDnudQqEUHHG8dqgwJyv6+bFg6+lF/OdMZkySMry7f9Ehp73NtT/0ehvPF3gv7f0TSuXkhuP+k6gRi9h+s X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(89211679590171); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(100000703101)(100105400095)(3231022)(10201501046)(3002001)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR0701MB3827;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR0701MB3827; X-Forefront-PRVS: 0492FD61DD X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(6009001)(346002)(376002)(189002)(199003)(43544003)(42882006)(6916009)(66066001)(50466002)(189998001)(48376002)(575784001)(15760500003)(6496005)(6666003)(25786009)(6486002)(316002)(305945005)(105586002)(97736004)(2351001)(47776003)(2361001)(54906003)(106356001)(7736002)(1076002)(5003940100001)(16586007)(5660300001)(53936002)(33646002)(76506005)(2906002)(50986999)(45080400002)(8936002)(50226002)(68736007)(101416001)(72206003)(3846002)(6116002)(4326008)(8666007)(8676002)(36756003)(478600001)(81166006)(81156014)(16526018)(88384005);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR0701MB3827;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR0701MB3827;23:/XmnR2rb7ewkWbRg5uADvZSmqv9IvsUqZMe3P8K?= =?us-ascii?Q?9RDGtUiPAWtcePgl1HHS3rZe9Gg8h8WdtwMI1ceP9F6UKL2NagVf0ihgINTK?= =?us-ascii?Q?8BkFjE4yXZ6V2ky+UH3x5h9fzsuLBL0ypGrClmUAsD6LHBVmyEeoteNtfnU7?= =?us-ascii?Q?l6DeMaJGeqqaY/589f+AzYQ/tWDnSqS/g7+s4fMhhcOdTKSf6DYaftiD+qQn?= =?us-ascii?Q?NMbhYiuZHDC3pbs+Y5sct2eAM4PqZBFzUzj0G5ruvjnLGBTL83P4ILcSEE9E?= =?us-ascii?Q?NRRIAZJ0SfB/mGSu8I2WDRQLsaJG0BrXosIw+wp/UqSn1ZlS1kBTMhwRX9Dx?= =?us-ascii?Q?2WQp46jjloZ2VRBn0gVlWVgb/Bjdj90ht/b/ZapDd2RWnrIxJaS4RAMw9zoC?= =?us-ascii?Q?236nA3t5iCmwzQD4TlY4SmVL94C6JQVIEt5b2D5+YKYZJGWUncE3URtfj16G?= =?us-ascii?Q?I0ESnH2bmvutM6k+fKsdQ3AF9xFuuLr1MteUBYu+8HEw6JShRiv+GDNUwHGL?= =?us-ascii?Q?pH5L4sty5fELBiyCec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Z+VsQJb5q44IcCUWinJZaNmwdYVkn+HkSSQsUldVDaKT7iAbary4x42SFDQijMSq8FBB5y7yW6hgdzMk45/jtiZy8rgGUr7C2ZpDNW82q7XUZudJS4rhW7KusV5Spdy5wpuvX1A2kk2e2cqyuxMXYfWHsSvJFfp4PsG3pwLtbY1lvfr+YjeGlMQirRwVQRQpEuj7Plx/oTCA83HbrLp3XcjVpmj033qf3cpkSfB5W7c4RhTI=;5:uBU9xFoLAiMVxPKGk8tnjznWAgOC3BMd5clNOFpqCdgKDsxv+g7B6AB0f9VYkYOeJX1e7EmQb3DLfCiG2MNQPL+T2+Gh1pv7T6k0zU44v4F0rURtj3iG8PS8avTR7+U/rFkSIzksB2YIMJi23IXtp7tG8qiV7dTGkDheFTO9O0o=;24:b3xZ95rRBIG9fgtbjtGpXmR9tx7mX8yuJRWEVQtyPfZLIm80jYyyf5sBFtmWZPiq09t92uzX706Gyx+epVAFZQzGQgJsL10JZ1N7GVnW7pg=;7:SigSbL01k7TLNPArxAWD+Lkm9Tyi3f+RFpKh4HM4HrdXPoP06slyj+U5LGIjJ6ZetdBz9ySd64TGiqJqlc3jiYDAPVfMA3zyDNHm6b+O892Z0sgXT06WekA9b51BsqI53nrcZPNlV2lmqCDmo6WBg6lbkexUxs3cxnlxev1MZQNCj2kMUze+dQvB4zmBk4lnmTNuIlRU5VZLZhjSnglCDhZYa+K1M73eHzPxV1fvsKQgBgq5G1Av2dzJVgdjdxi7 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2017 17:41:11.2966 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: efccf076-bbee-45f2-9b5f-08d52c501054 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org and make it looking like standard copy function: bitmap_from_u32array(dst, src, size). Currently bitmap_from_u32array() takes 4 arguments: - unsigned long *bitmap, which is destination; - unsigned int nbits, the length of destination bitmap, in bits; - const u32 *buf, the source; and - unsigned int nwords, the length of source buffer in ints. In description to the function it is detailed like: * copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining * bits between nword and nbits in @bitmap (if any) are cleared. Having two size arguments looks unneeded and potentially dangerous. It is unneeded because normally user of copy-like function should take care of the size of destination and make it big enough to fit source data. And it is dangerous because function may hide possible error if user doesn't provide big enough bitmap, and data becomes silently dropped. That's why all copy-like functions have 1 argument for size of copying data, and I don't see any reason to make bitmap_from_u32array() different. One exception that comes in mind is strncpy() which also provides size of destination in arguments, but it's strongly argued by the possibility of taking broken strings in source, which is not the case of bitmap_from_u32array(). There is no many real users of bitmap_from_u32array(), and they all very clearly provide size of destination matched with the size of source, so additional functionality is not used. Like this: bitmap_from_u32array(to->link_modes.supported, __ETHTOOL_LINK_MODE_MASK_NBITS, link_usettings.link_modes.supported, __ETHTOOL_LINK_MODE_MASK_NU32); Where: #define __ETHTOOL_LINK_MODE_MASK_NU32 \ DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32) This patch demonstrates how the code will look with simplified API. If this simplification will be found useful, I'll send complete version that also reworks bitmap_to_u32array() and fixes corresponding test in lib/test_bitmap.c. I also expect that internal logic of functions will be simplified. Boot-tested on arm64. Signed-off-by: Yury Norov CC: Andrew Morton CC: Ben Hutchings CC: David Decotigny CC: David S. Miller CC: Matthew Wilcox CC: Rasmus Villemoes --- arch/arm64/kernel/perf_event.c | 5 ++--- include/linux/bitmap.h | 7 +++---- lib/bitmap.c | 19 +++++++------------ net/core/ethtool.c | 21 +++++++-------------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 9eaef51f83ff..70f4fd1952b6 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -931,9 +931,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_u32array(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 19748a5b0e77..b3c4bc04a466 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -60,7 +60,7 @@ * 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_from_u32array(dst, buf, nbits) *dst = *buf (nwords 32b words) * bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words) */ @@ -165,10 +165,9 @@ 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, +extern void *bitmap_from_u32array(unsigned long *bitmap, const u32 *buf, - unsigned int nwords); + unsigned int nbits); extern unsigned int bitmap_to_u32array(u32 *buf, unsigned int nwords, const unsigned long *bitmap, diff --git a/lib/bitmap.c b/lib/bitmap.c index c82c61b66e16..9d99f2f81281 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1108,22 +1108,17 @@ EXPORT_SYMBOL(bitmap_allocate_region); * @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. + * copy nbits bits from @buf to @bitmap. In last word of @bitmap, the bits + * beyond nbits (if any) are kept unchanged. */ -unsigned int -bitmap_from_u32array(unsigned long *bitmap, unsigned int nbits, - const u32 *buf, unsigned int nwords) +void *bitmap_from_u32array(unsigned long *bitmap, const u32 *buf, + unsigned int nbits) { unsigned int dst_idx, src_idx; + unsigned int nwords = BITS_TO_LONGS(nbits); - for (src_idx = dst_idx = 0; dst_idx < BITS_TO_LONGS(nbits); ++dst_idx) { + for (src_idx = dst_idx = 0; dst_idx < nwords; ++dst_idx) { unsigned long part = 0; if (src_idx < nwords) @@ -1144,7 +1139,7 @@ bitmap_from_u32array(unsigned long *bitmap, unsigned int nbits, } } - return min_t(unsigned int, nbits, 32*nwords); + return bitmap; } EXPORT_SYMBOL(bitmap_from_u32array); diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 9a9a3d77e327..6ee127bb04e5 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -600,17 +600,14 @@ static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to, 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); + __ETHTOOL_LINK_MODE_MASK_NBITS); bitmap_from_u32array(to->link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS, link_usettings.link_modes.advertising, - __ETHTOOL_LINK_MODE_MASK_NU32); + __ETHTOOL_LINK_MODE_MASK_NBITS); bitmap_from_u32array(to->link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NBITS, link_usettings.link_modes.lp_advertising, - __ETHTOOL_LINK_MODE_MASK_NU32); + __ETHTOOL_LINK_MODE_MASK_NBITS); return 0; } @@ -2343,10 +2340,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_u32array(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 }; @@ -2378,10 +2373,8 @@ 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_u32array(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 From 1584787231269125845@xxx Wed Nov 22 17:14:39 +0000 2017 X-GM-THRID: 1584785590923131463 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread