Received: by 10.223.164.202 with SMTP id h10csp5652444wrb; Tue, 21 Nov 2017 13:18:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMZcEfwK1RwCIig9+jYsFwGE/q03ffZ5hDn3NR6yObCEmeu4BFphj9a6uw7StViJu8CuANqd X-Received: by 10.98.130.4 with SMTP id w4mr16424881pfd.238.1511299095419; Tue, 21 Nov 2017 13:18:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511299095; cv=none; d=google.com; s=arc-20160816; b=RaAdN4HU2xJ9nqKU1GOzcyzc07RxJp8cav1FViyfkB4EmRLEEy9lALmgqK4O+2Pxbq 5a0IxdIDdEr/YYFJG/Hbysn+G3rymE7kLAtKSyfv9sXciOstFgsm3IRjjd57/KMcO8Ii 8IQ0htAf8mtsPc6domJSCAq1+0KG8Apwe7IKMi9XPJAo0l08XrkakEWvuHjKjLVMdUK3 cINW+D8kbpqfoswgS2ift9uS91IzTUIV4pFhjG/WKjGw2kffPlxMRm2mgELMjTSYnint umXjmCTm2MpFzrgtQSRk85F1euMTKYw0zBPqGmKHBUF3/GRbkMxcUmr9OYHFIcUTGfep DDNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=jIUx4ag7ZC+kTjhn7bWnWOC00yKkqmOjVafbK22lJkU=; b=FQJn9CAh3V0qUgQq8Ng6GNqmJvo6cxfozYZOrkyYkmPaVJNYxiDfwCmNwzl184XEjs eN6I47f0FWLbxy/bWpgdw+28Cwcmgeel41t7T6y4rODk8490fKbL96Jj282NhDlNmKRy E7JuoDW96b6g5idcZQ1usTMrFw4Lxy4qCpjMGu5dlbhM6d+GoGa/TWeuMkRWVqosIbNi ZRfu3wLNDeM/496dAXMHOrgMSrMRFXb1GcqExOuQpr+MIgo7xM08OoJSwwhZYkh4ajlw gZz2lIbBEnWP2W//+JIrVFXDIFbz+Wv8TBIrVGI8fPrw5v1fAv4J5jMj8IU9x7v8b+8S 6Svg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=KxOQWvKI; 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 w34si11891267pla.356.2017.11.21.13.18.03; Tue, 21 Nov 2017 13:18:15 -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=KxOQWvKI; 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 S1751571AbdKUVQP (ORCPT + 76 others); Tue, 21 Nov 2017 16:16:15 -0500 Received: from mail-by2nam01on0081.outbound.protection.outlook.com ([104.47.34.81]:14240 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751483AbdKUVQL (ORCPT ); Tue, 21 Nov 2017 16:16:11 -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=jIUx4ag7ZC+kTjhn7bWnWOC00yKkqmOjVafbK22lJkU=; b=KxOQWvKIzNo/NyTuT6GyJNeNYWTcVCowOaMjR8e/tTCFpmtq/RFn7bHjR6mhujmjM8oNPhBVBC9kO+MoiLYKLaEL8m0Tm1V9cHVqMSbu/6EWJyTxE6rOox9ARKaeXBpQdBf2qbxO53zrDm1nOT2irvihV9pD/uccHoM/2QlOD/g= Received: from localhost (50.233.148.156) by MWHPR0701MB3836.namprd07.prod.outlook.com (2603:10b6:301:7f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Tue, 21 Nov 2017 21:16:05 +0000 Date: Wed, 22 Nov 2017 00:15:48 +0300 From: Yury Norov To: Matthew Wilcox Cc: "linux-kernel@vger.kernel.org" , Andrew Morton , Ben Hutchings , David Decotigny , "David S . Miller" , Rasmus Villemoes , Geert Uytterhoeven Subject: Re: [PATCH RFC] lib: simplify bitmap_from_u32array API Message-ID: <20171121211548.xhnkdys567l6jdtr@yury-thinkpad> References: <20171115174056.26537-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: HE1PR0102CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::26) To MWHPR0701MB3836.namprd07.prod.outlook.com (2603:10b6:301:7f::29) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25c7dd59-ed06-43f9-071b-08d531251528 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600019)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603258);SRVR:MWHPR0701MB3836; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3836;3:oDKoL3Ugi/0XGsrSa5DG6eKmbrKGMTVbUOs77kvFxUmojjFYDzztWPBHvGRu7U+ug4oxXbOO5NhaSbdbKf4V/OiMeWyDaoKF1wkUAOLgtNhcq16jGyMKLhCumPx6CVBlfo7Dd/vg3HMyh3auobYdHJuWR9DCboY7LxvCbR/WQGwRPwvlJWl9YO6xt4S6i5d3OyMwUK7U3a5n9ti7YSIj8Ie5o7LFI0psbixnYE4YpiooB1Roo2F6Tc+EQsWIRMAg;25:Z+mf5y/T8vcnuq34/T+MbG9cbRymodFUSabMYuFE0rVUZtoWkHRdjDapvPQS8MQfORwhf0eCPRY+XOKyMAm28r/TCU4X+hDumYTE/nTreWjaWG+ztFjqQwOqI1cTVAoKFvSRACKQDkQ904v4lbQ/NQccM3vyBf3aM5GrZHFl6yTvh2GE0zq38iHUo/b8jerpa+0gqaSi8VLsCW65wtbw6FPP0vvZHXXy+rYXNEyslGjflRfvACaEqY8WMURSWG81BM4Nk/EMDlexjuOb6eY6ZGy/JEfXjDO9egbVy6mQnGdEYyfeDXSDNC00+9Hlm1rg9BCTYT2e6VyTWNviyEwCyw==;31:aKLlxlMZllRYidBl6Q/xBo2cEFXyU0PaGDduJf0UKif6TWSZKruXEvnXAUlidwDC1gfa8WDp0YgXPGDtoy9DTVDD3jWbFR6pzul7m2SIqy++oNtgvlNnrglI2li9vlkcQ4Si68LTuYpjfOh9ZIOOv1qw8ITs8eOY/yBRXSJ4XdwHKQ4NxtZEfxGOpy6nFJNSmyB2ZqBA2cnYipaMDTfWG+9qDZTCQhwNLjZ6Hx2i+DY= X-MS-TrafficTypeDiagnostic: MWHPR0701MB3836: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; X-Microsoft-Exchange-Diagnostics: 1;MWHPR0701MB3836;20:hB4gEka59r8sfo7sT2ZjnQX1Kl+T5Bu9iM4rIHId/gr03vt1oNjd9SHhaCacz2dw19nQMZoXRuq5dTUT1nuJx8S0akye4KPHI7gb6EdfNCnYR6oO5HbW8lDWn9lYDS81Nk9K8Mr9ZJJV11MT8QK5f53+you9Pbw9+4B6jL8+wAmO5+3o8v/QT9VxpVJ66pm7x+Tkyc7WcPdtUZub/+RPn+km1hCV46mK3TeifJGJjnlearkDdUL/yQWpKxYq9QJEMH6VtELHgxEan12LtROUIDCox6tHjeuU0XU7mUhCNS+9Me94TdDDCRbwfXfjJfBqaRlNnQUmTJEDV6QVk5wHwsVqF6KtbCZ/aNE2B/BLgXqm5HOwDR1CRiGD0YB9PHuvSzEvzh4kAndbMFJBDzmGXDpCFkcbn6GPsOd+dul1iUr1pnLYVN4AuGEHRzflKU7p9U41jqviyGOi1ZWiMboUClMzQDmwBXuL69Ory7rZKez9ptJWOyc9nr2zBFYjQaq5cVeOnMAEvo79PLL9V9wEDkrZtllrpEYV4Dx+tIxknohHVWEpSgsu11XGx/FjikJRQGYFXoED6F9p8X+2cLNdMqfntBICxIreSuXUnzk27kg=;4:/t9++QXtnOzOouqYUsSjbfezixrq4g5w6iff2pqf/Gq/uPihkEOrb9oPZ46i00+POIJzrobSqCMANAvi9mVlNL1bWsZjr8KqPDOKApl5RmFdD1sHFH6OouoeuJfVaK8b4+ZIvjkGKy1lc9fOAVKZwtuCbj3AtgqxaWqUOCqWgJkg+mn+NvmLiKM8bhRHTSsw46Ub7H1BwV4LEu6wna3Bzi3fEMk11vj2STyzOBIuH1ZU8nnX8zFTlxqqgRX7JaCGk54vpi0lbJtUmh6Xy/O8SA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3231022)(93006095)(3002001)(100000703101)(100105400095)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR0701MB3836;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR0701MB3836; X-Forefront-PRVS: 049897979A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6069001)(7916004)(376002)(346002)(24454002)(199003)(189002)(8666007)(316002)(25786009)(6246003)(5660300001)(83506002)(6496006)(15760500003)(23676004)(478600001)(33716001)(52146003)(4326008)(53936002)(58126008)(54906003)(9686003)(66066001)(72206003)(6486002)(8676002)(6666003)(2950100002)(1511001)(6916009)(189998001)(42882006)(8936002)(76506005)(2561002)(53546010)(76176999)(81166006)(575784001)(81156014)(16526018)(54356999)(50986999)(2906002)(229853002)(47776003)(3846002)(68736007)(97736004)(6116002)(7736002)(1076002)(305945005)(33646002)(2870700001)(106356001)(50466002)(101416001)(2421001)(105586002)(2486003);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR0701MB3836;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjA3MDFNQjM4MzY7MjM6Yk1uaEhBZ2hGTGZtbXdwS0xqS2lqUVIr?= =?utf-8?B?a082eENzZnhPR1FKbFp1Z2h1MlpGT3pERjB2dFI5dHNCS1NjakQxS3Q1Y2I0?= =?utf-8?B?QlN2VUVnNDIyaWdsV3lVVzkvSWZxeDkrTFMwYVNoMUJBTVZqa3JFT0hqczlr?= =?utf-8?B?N2M5YmoxbXZySnQydnF2TGVYNkFBOEdVa1p0bE9EUkJ1Qlh3T3BBaVVxSW9w?= =?utf-8?B?RXY5YlpJVGFKdUJMQ2VFUW1JU0swV3JJK3Y1am1jNmVaNENxNHJLcjFCZ0pi?= =?utf-8?B?UG5TL3ArM0FUS3BMNWNHZll2YjNDdSsvSENjTTRDam9GbmQwUTU4cXNnaVdn?= =?utf-8?B?V3lxbEdvdHNkU1NlQ3Jua09KYWhRdnZ0L2d4M0ZhdC9ObjE1c3prUzlrb0tu?= =?utf-8?B?ckpyWVllcGRQOFR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fRchkn5e4crn5W851bsJhZXbdKmZ1k1Y0Z3VcuJ0b2wVN/1gKPf92ZFYvgbNcMtj+YZHv/sBwKrWZQ=;5:BiS33uJIAXjIsWkrXhDda7kvNb4hG2MNyKNIYGOD3OSPSHb18u5Wf6amPtDa6Ad+FczZYVGyN2Jyev3Y0S8ta6RD1AFPxza9udT/2YthjqTI05pNiBFvrx1Xyw+ZbH34tf0fnUOYfep7bqSCh7v67IJuH36AEASy1zCfKAVpIQo=;24:V341z8dBD/lcizZ3MzuITL0PihN1SIV8xR40Ya0rHyECLZ49vzT7yLz59phN0YtCr5TPJOKKQP1iKy/nhwCIgxOUGfWVo3tH9jD8D2PynNk=;7:k6AWAYAMT2NONcp5nJPq2Lu+Zwu7Xb+UXXjvFnOC22SRATdl/i5YTayqj72JasZC6g/8PdKuOZnneWTqgbOMHqFLvMqSeXxx3ZLLUcjI0y1QtJlYGDtD0Yn1ETanYGIoo7A9+BAlRe455D3lDETLE9idCM7Ljxffo6zKsHHHrKz/x3wSHsNfOuv/WBMbwg7EGedDuH+vDaPuGbRmmIfeO59bk0T9gfDB4WfYvEzm5kMm6PwuZZrPsy6ITmCsZnu4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2017 21:16:05.6445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25c7dd59-ed06-43f9-071b-08d531251528 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0701MB3836 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Matthew, [+ Geert Uytterhoeven) On Wed, Nov 15, 2017 at 07:24:15PM +0000, Matthew Wilcox wrote: > I certainly approve. The name sucks too ???? Yep. I changed it, didn't resist. > > @@ -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) > > I think this should read: > + * bitmap_from_u32array(dst, buf, bits) Copy 'bits' from buf to dst Ack > Also, on LE systems, shouldn't we just use memcpy() for the first bits/8 bytes? Yes, but I did prefer to keep logic common for LE and BE arches. We can switch to memcpy 32-bit LE and BE versions, see my thoughts below. >From 6ab70ff5ea32ecc5c9e77cc4b84e6dd3843e5d8f Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Tue, 21 Nov 2017 22:42:57 +0300 Subject: [PATCH 1/2] bitmap: new bitmap_copy_safe and bitmap_{from,to}_arr32 'Safe' in bitmap_copy_safe stands for clearing tail bits in bitmap beyond last bit till the end of last word. It is useful for hardening API when bitmap is assumed to be exposed to userspace. bitmap_{from,to}_arr32 functions are replacements for bitmap_{from,to}_u32array. They don't take unneeded nwords argument, and so simpler in implementation and understanding. This patch suggests optimization for 32-bit systems - aliasing bitmap_{from,to}_arr32 to bitmap_copy_safe. Other possible optimization is to map 64-bit LE bitmap_{from,to}_arr32 to more generic function(s). But I didn't end up with the function that would be helpful by itself, and can be used to alias 64-bit LE bitmap_{from,to}_arr32, like bitmap_copy_safe does. So I preferred to leave things as is. Since this is RFC, I would like to ask people here for ideas. :) The following patch switches kernel to new API and introduces new test. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 31 +++++++++++++++++++++++++++++ lib/bitmap.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 19748a5b0e77..1fa0de16b0a7 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -62,6 +62,8 @@ * 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 */ /* @@ -219,6 +221,35 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, } } +/* + * Copy bitmap and clear tail bits in last word. + */ +static inline void bitmap_copy_safe(unsigned long *dst, + const unsigned long *src, unsigned int nbits) +{ + bitmap_copy(dst, src, nbits); + if (nbits % BITS_PER_LONG) + dst[nbits / BITS_PER_LONG] &= BITMAP_LAST_WORD_MASK(nbits); +} + +/* + * On 32-bit systems bitmaps are represented as u32 arrays internally, and + * therefore conversion is not needed when copying data from/to arrays of u32. + */ +#if BITS_PER_LONG == 64 +extern void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, + unsigned int nbits); +extern void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, + unsigned int nbits); +#else +#define bitmap_from_arr32(bitmap, buf, nbits) \ + bitmap_copy_safe((unsigned long *) (bitmap), \ + (const unsigned long *) (buf), (nbits)) +#define bitmap_to_arr32(buf, bitmap, nbits) \ + bitmap_copy_safe((unsigned long *) (buf), \ + (const unsigned long *) (bitmap), (nbits)) +#endif + static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { diff --git a/lib/bitmap.c b/lib/bitmap.c index c82c61b66e16..b0f79074ae84 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1212,3 +1212,57 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n } EXPORT_SYMBOL(bitmap_copy_le); #endif + +#if BITS_PER_LONG == 64 +/** + * bitmap_from_arr32 - copy the contents of a u32 array of bits to bitmap + * @bitmap: array of unsigned longs, the destination bitmap, non NULL + * @buf: array of u32 (in host byte order), the source bitmap, non NULL + * @nbits: number of bits in @bitmap + */ +void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, + unsigned int nbits) +{ + unsigned int i, halfwords; + + if (!nbits) + return; + + halfwords = DIV_ROUND_UP(nbits, 32); + for (i = 0; i < halfwords; i++) { + bitmap[i/2] = (unsigned long) buf[i]; + if (++i < halfwords) + bitmap[i/2] |= ((unsigned long) buf[i]) << 32; + } + + /* Clear tail bits in last word beyond nbits. */ + bitmap[(halfwords - 1) / 2] &= BITMAP_LAST_WORD_MASK(nbits); +} +EXPORT_SYMBOL(bitmap_from_arr32); + +/** + * bitmap_to_arr32 - copy the contents of bitmap to a u32 array of bits + * @buf: array of u32 (in host byte order), the dest bitmap, non NULL + * @bitmap: array of unsigned longs, the source bitmap, non NULL + * @nbits: number of bits in @bitmap + */ +void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits) +{ + unsigned int i, halfwords; + + if (!nbits) + return; + + halfwords = DIV_ROUND_UP(nbits, 32); + for (i = 0; i < halfwords; i++) { + buf[i] = (u32) (bitmap[i/2] & UINT_MAX); + if (++i < halfwords) + buf[i] = (u32) (bitmap[i/2] >> 32); + } + + /* Clear tail bits in last element of array beyond nbits. */ + buf[halfwords - 1] &= (u32) (UINT_MAX >> ((-nbits) & 31)); +} +EXPORT_SYMBOL(bitmap_to_arr32); + +#endif -- 2.11.0 From 1584165437354470018@xxx Wed Nov 15 20:31:30 +0000 2017 X-GM-THRID: 1584156130360803324 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread