Skip to content

Commit d56b65a

Browse files
committed
Merge branch 'bitmap-for-next' of https://github.com/norov/linux.git
2 parents b472d09 + bdcb37a commit d56b65a

File tree

10 files changed

+700
-754
lines changed

10 files changed

+700
-754
lines changed

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,12 +3554,14 @@ R: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
35543554
R: Rasmus Villemoes <linux@rasmusvillemoes.dk>
35553555
S: Maintained
35563556
F: include/linux/bitfield.h
3557+
F: include/linux/bitmap-str.h
35573558
F: include/linux/bitmap.h
35583559
F: include/linux/bits.h
35593560
F: include/linux/cpumask.h
35603561
F: include/linux/find.h
35613562
F: include/linux/nodemask.h
35623563
F: include/vdso/bits.h
3564+
F: lib/bitmap-str.c
35633565
F: lib/bitmap.c
35643566
F: lib/cpumask.c
35653567
F: lib/cpumask_kunit.c

include/linux/bitmap-str.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __LINUX_BITMAP_STR_H
3+
#define __LINUX_BITMAP_STR_H
4+
5+
int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, unsigned long *dst, int nbits);
6+
int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits);
7+
extern int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp,
8+
int nmaskbits, loff_t off, size_t count);
9+
extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp,
10+
int nmaskbits, loff_t off, size_t count);
11+
int bitmap_parse(const char *buf, unsigned int buflen, unsigned long *dst, int nbits);
12+
int bitmap_parselist(const char *buf, unsigned long *maskp, int nmaskbits);
13+
int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
14+
unsigned long *dst, int nbits);
15+
16+
#endif /* __LINUX_BITMAP_STR_H */

include/linux/bitmap.h

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
#include <linux/align.h>
88
#include <linux/bitops.h>
9+
#include <linux/errno.h>
910
#include <linux/find.h>
1011
#include <linux/limits.h>
1112
#include <linux/string.h>
1213
#include <linux/types.h>
14+
#include <linux/bitmap-str.h>
1315

1416
struct device;
1517

@@ -200,14 +202,6 @@ bitmap_find_next_zero_area(unsigned long *map,
200202
align_mask, 0);
201203
}
202204

203-
int bitmap_parse(const char *buf, unsigned int buflen,
204-
unsigned long *dst, int nbits);
205-
int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
206-
unsigned long *dst, int nbits);
207-
int bitmap_parselist(const char *buf, unsigned long *maskp,
208-
int nmaskbits);
209-
int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
210-
unsigned long *dst, int nbits);
211205
void bitmap_remap(unsigned long *dst, const unsigned long *src,
212206
const unsigned long *old, const unsigned long *new, unsigned int nbits);
213207
int bitmap_bitremap(int oldbit,
@@ -216,23 +210,6 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig,
216210
const unsigned long *relmap, unsigned int bits);
217211
void bitmap_fold(unsigned long *dst, const unsigned long *orig,
218212
unsigned int sz, unsigned int nbits);
219-
int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
220-
void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
221-
int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
222-
223-
#ifdef __BIG_ENDIAN
224-
void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits);
225-
#else
226-
#define bitmap_copy_le bitmap_copy
227-
#endif
228-
int bitmap_print_to_pagebuf(bool list, char *buf,
229-
const unsigned long *maskp, int nmaskbits);
230-
231-
extern int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp,
232-
int nmaskbits, loff_t off, size_t count);
233-
234-
extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp,
235-
int nmaskbits, loff_t off, size_t count);
236213

237214
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
238215
#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
@@ -518,6 +495,66 @@ static inline void bitmap_next_set_region(unsigned long *bitmap,
518495
*re = find_next_zero_bit(bitmap, end, *rs + 1);
519496
}
520497

498+
/**
499+
* bitmap_release_region - release allocated bitmap region
500+
* @bitmap: array of unsigned longs corresponding to the bitmap
501+
* @pos: beginning of bit region to release
502+
* @order: region size (log base 2 of number of bits) to release
503+
*
504+
* This is the complement to __bitmap_find_free_region() and releases
505+
* the found region (by clearing it in the bitmap).
506+
*/
507+
static inline void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order)
508+
{
509+
bitmap_clear(bitmap, pos, BIT(order));
510+
}
511+
512+
/**
513+
* bitmap_allocate_region - allocate bitmap region
514+
* @bitmap: array of unsigned longs corresponding to the bitmap
515+
* @pos: beginning of bit region to allocate
516+
* @order: region size (log base 2 of number of bits) to allocate
517+
*
518+
* Allocate (set bits in) a specified region of a bitmap.
519+
*
520+
* Returns: 0 on success, or %-EBUSY if specified region wasn't
521+
* free (not all bits were zero).
522+
*/
523+
static inline int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order)
524+
{
525+
unsigned int len = BIT(order);
526+
527+
if (find_next_bit(bitmap, pos + len, pos) < pos + len)
528+
return -EBUSY;
529+
bitmap_set(bitmap, pos, len);
530+
return 0;
531+
}
532+
533+
/**
534+
* bitmap_find_free_region - find a contiguous aligned mem region
535+
* @bitmap: array of unsigned longs corresponding to the bitmap
536+
* @bits: number of bits in the bitmap
537+
* @order: region size (log base 2 of number of bits) to find
538+
*
539+
* Find a region of free (zero) bits in a @bitmap of @bits bits and
540+
* allocate them (set them to one). Only consider regions of length
541+
* a power (@order) of two, aligned to that power of two, which
542+
* makes the search algorithm much faster.
543+
*
544+
* Returns: the bit offset in bitmap of the allocated region,
545+
* or -errno on failure.
546+
*/
547+
static inline int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order)
548+
{
549+
unsigned int pos, end; /* scans bitmap by regions of size order */
550+
551+
for (pos = 0; (end = pos + BIT(order)) <= bits; pos = end) {
552+
if (!bitmap_allocate_region(bitmap, pos, order))
553+
return pos;
554+
}
555+
return -ENOMEM;
556+
}
557+
521558
/**
522559
* BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
523560
* @n: u64 value

include/linux/buildid.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#ifndef _LINUX_BUILDID_H
33
#define _LINUX_BUILDID_H
44

5-
#include <linux/mm_types.h>
5+
#include <linux/types.h>
66

77
#define BUILD_ID_SIZE_MAX 20
88

9+
struct vm_area_struct;
910
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
1011
__u32 *size);
1112
int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);

0 commit comments

Comments
 (0)