mm: security: ro protection for dynamic data
Subsystems (7)
v15 cover mm: security: ro protection for dynamic data
This patch-set introduces the possibility of protecting memory that has been allocated dynamically.
The memory is managed in pools: when a memory pool is turned into R/O, all the memory that is part of it, will become R/O.
A R/O pool can be destroyed, to recover its memory, but it cannot be turned back into R/W mode.
This is intentional. This feature is meant for data that doesn't need further modifications after initialization.
However the data might need to be released, for example as part of module unloading.
To do this, the memory must first be freed, then the pool can be destroyed.
An example is provided, in the form of self-testing.
Changes since v14:
[http://www.openwall.com/lists/kernel-hardening/2018/02/04/2]
- fix various warnings from sparse
- multiline comments
- fix naming of headers guards
- fix compilation of individual patches, for bisect
- split genalloc documentation about bitmap for allocation
- fix headers to match kerneldoc format for "Return:" field
- fix variable naming according to coding guidelines
- fix wrong default value for pmalloc Kconfig option
- refreshed integration of pmalloc with hardened usercopy
- removed unnecessary include that was causing compilation failures
- changed license of pmalloc documentation from GPL 2.0 to CC-BY-SA-4.0
Igor Stoppa (6):
genalloc: track beginning of allocations
genalloc: selftest
struct page: add field for vm_struct
Protectable Memory
Pmalloc: self-test
Documentation for Pmalloc
Documentation/core-api/index.rst | 1 + Documentation/core-api/pmalloc.rst | 114 ++++++++ include/linux/genalloc-selftest.h | 26 ++ include/linux/genalloc.h | 7 +- include/linux/mm_types.h | 1 + include/linux/pmalloc.h | 222 +++++++++++++++ include/linux/vmalloc.h | 1 + init/main.c | 2 + lib/Kconfig | 15 + lib/Makefile | 1 + lib/genalloc-selftest.c | 400 ++++++++++++++++++++++++++ lib/genalloc.c | 554 +++++++++++++++++++++++++++---------- mm/Kconfig | 15 + mm/Makefile | 2 + mm/pmalloc-selftest.c | 63 +++++ mm/pmalloc-selftest.h | 24 ++ mm/pmalloc.c | 499 +++++++++++++++++++++++++++++++++ mm/usercopy.c | 33 +++ mm/vmalloc.c | 18 +- 19 files changed, 1852 insertions(+), 146 deletions(-) create mode 100644 Documentation/core-api/pmalloc.rst create mode 100644 include/linux/genalloc-selftest.h create mode 100644 include/linux/pmalloc.h create mode 100644 lib/genalloc-selftest.c create mode 100644 mm/pmalloc-selftest.c create mode 100644 mm/pmalloc-selftest.h create mode 100644 mm/pmalloc.c
Signature · 1 line
2.14.1
PATCH v15 1/6 genalloc: track beginning of allocations
The genalloc library is only capable of tracking if a certain unit of allocation is in use or not.
It is not capable of discerning where the memory associated to an allocation request begins and where it ends.
The reason is that units of allocations are tracked by using a bitmap, where each bit represents that the unit is either allocated (1) or available (0).
The user of the API must keep track of how much space was requested, if it ever needs to be freed.
This can cause errors being undetected.
Examples:
* Only a subset of the memory provided to an allocation request is freed
* The memory from a subsequent allocation is freed
* The memory being freed doesn't start at the beginning of an allocation.
The bitmap is used because it allows to perform lockless read/write access, where this is supported by hw through cmpxchg. Similarly, it is possible to scan the bitmap for a sufficiently long sequence of zeros, to identify zones available for allocation.
This patch doubles the space reserved in the bitmap for each allocation, to track their beginning.
For details, see the documentation inside lib/genalloc.c
--- include/linux/genalloc.h | 4 +- lib/genalloc.c | 527 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 390 insertions(+), 141 deletions(-)
include/linux/genalloc.h +2 -2
@@ -32,7 +32,7 @@#include <linux/types.h> #include <linux/spinlock_types.h> -#include <linux/atomic.h> +#include <linux/slab.h> struct device ;struct device_node ;
@@ -76,7 +76,7 @@ struct gen_pool_chunk {phys_addr_t phys_addr;/* physical starting address of memory chunk */ unsigned long start_addr;/* start address of memory chunk */ unsigned long end_addr;/* end address of memory chunk (inclusive) */ -unsigned long bits[0 ];/* bitmap for allocating memory chunk */ +unsigned long entries[0 ];/* bitmap for allocating memory chunk */ };/*
lib/genalloc.c +388 -139
798 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [PATCH 1/6] genalloc: track beginning of allocations
Quoted 164 lines · Igor Stoppa
The genalloc library is only capable of tracking if a certain unit of allocation is in use or not.
It is not capable of discerning where the memory associated to an allocation request begins and where it ends.
The reason is that units of allocations are tracked by using a bitmap, where each bit represents that the unit is either allocated (1) or available (0).
The user of the API must keep track of how much space was requested, if it ever needs to be freed.
This can cause errors being undetected.
Examples:
* Only a subset of the memory provided to an allocation request is freed
* The memory from a subsequent allocation is freed
* The memory being freed doesn't start at the beginning of an allocation.The bitmap is used because it allows to perform lockless read/write access, where this is supported by hw through cmpxchg. Similarly, it is possible to scan the bitmap for a sufficiently long sequence of zeros, to identify zones available for allocation.
This patch doubles the space reserved in the bitmap for each allocation, to track their beginning.
For details, see the documentation inside
lib/genalloc.cSigned-off-by Igor Stoppa <[email protected]>--- include/linux/genalloc.h | 4 +- lib/genalloc.c | 527 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 390 insertions(+), 141 deletions(-)include/linux/genalloc.h +2
-2@@ -32,7 +32,7 @@#include <linux/types.h> #include <linux/spinlock_types.h> -#include <linux/atomic.h> +#include <linux/slab.h> struct device ;struct device_node ;@@ -76,7 +76,7 @@ struct gen_pool_chunk {phys_addr_t phys_addr;/* physical starting address of memory chunk */ unsigned long start_addr;/* start address of memory chunk */ unsigned long end_addr;/* end address of memory chunk (inclusive) */ -unsigned long bits[0 ];/* bitmap for allocating memory chunk */ +unsigned long entries[0 ];/* bitmap for allocating memory chunk */ };/* lib/genalloc.c +91
-0@@ -26,6 +26,74 @@* * This source code is licensed under the GNU General Public License, * Version 2. See the file COPYING for more details. +* +* +* +* Encoding of the bitmap tracking the allocations +* ----------------------------------------------- +* +* The bitmap is composed of units of allocations. +* +* Each unit of allocation is represented using 2 consecutive bits. +* +* This makes it possible to encode, for each unit of allocation, +* information about: +* - allocation status (busy/free) +* - beginning of a sequennce of allocation units (first / successive) +* +* +* Dictionary of allocation units (msb to the left, lsb to the right): +* +* 11: first allocation unit in the allocation +* 10: any subsequent allocation unit (if any) in the allocation +* 00: available allocation unit +* 01: invalid +* +* Example, using the same notation as above - MSb.......LSb: +* +* ...000010111100000010101011 <-- Read in this direction. +* \__|\__|\|\____|\______| +* | | | | \___ 4 used allocation units +* | | | \___________ 3 empty allocation units +* | | \_________________ 1 used allocation unit +* | \___________________ 2 used allocation units +* \_______________________ 2 empty allocation units +* +* The encoding allows for lockless operations, such as: +* - search for a sufficiently large range of allocation units +* - reservation of a selected range of allocation units +* - release of a specific allocation +* +* The alignment at which to perform the research for sequence of empty +* allocation units (marked as zeros in the bitmap) is 2^1. +* +* This means that an allocation can start only at even places +* (bit 0, bit 2, etc.) in the bitmap. +* +* Therefore, the number of zeroes to look for must be twice the number +* of desired allocation units. +* +* When it's time to free the memory associated to an allocation request, +* it's a matter of checking if the corresponding allocation unit is +* really the beginning of an allocation (both bits are set to 1). +* +* Looking for the ending can also be performed locklessly. +* It's sufficient to identify the first mapped allocation unit +* that is represented either as free (00) or busy (11). +* Even if the allocation status should change in the meanwhile, it +* doesn't matter, since it can only transition between free (00) and +* first-allocated (11). +* +* The parameter indicating to the *_free() function the size of the +* space that should be freed can be either set to 0, for automated +* assessment, or it can be specified explicitly. +* +* In case it is specified explicitly, the value is verified agaisnt what +* the library is tracking internally. +* +* If ever needed, the bitmap could be extended, assigning larger amounts +* of bits to each allocation unit (the increase must follow powers of 2), +* to track other properties of the allocations. */ #include <linux/slab.h> @@ -36,118 +104,230 @@#include <linux/genalloc.h> #include <linux/of_device.h> +#define ENTRY_ORDER 1UL +#define ENTRY_MASK ((1UL << ((ENTRY_ORDER) + 1UL)) - 1UL) +#define ENTRY_HEAD ENTRY_MASK +#define ENTRY_UNUSED 0UL +#define BITS_PER_ENTRY (1U << ENTRY_ORDER) +#define BITS_DIV_ENTRIES (x) ((x) >> ENTRY_ORDER) +#define ENTRIES_TO_BITS (x) ((x) << ENTRY_ORDER) +#define BITS_DIV_LONGS (x) ((x) / BITS_PER_LONG) +#define ENTRIES_DIV_LONGS (x) (BITS_DIV_LONGS(ENTRIES_TO_BITS(x))) + +#define ENTRIES_PER_LONG BITS_DIV_ENTRIES(BITS_PER_LONG) + +/* Binary pattern of 1010...1010 that spans one unsigned long. */ +#define MASK (~0UL / 3 * 2) + +/** +* get_bitmap_entry - extracts the specified entry from the bitmap +* @map: pointer to a bitmap +* @entry_index: the index of the desired entry in the bitmap +* +* Return: The requested bitmap. +*/ +static inline unsigned long get_bitmap_entry(unsigned long *map,
lib/genalloc.c line 139
Quoted 10 lines
lib/genalloc.c +10
-0+ int entry_index) +{ +return (map[ENTRIES_DIV_LONGS (entry_index)] >> +ENTRIES_TO_BITS (entry_index %ENTRIES_PER_LONG )) & +ENTRY_MASK ; +} + + +/** +* mem_to_units - convert references to memory into orders of allocation
Documentation/doc-guide/kernel-doc.rst recommends to to include brackets for function comments. I haven't noticed any difference in the resulting html, so I'm not sure if the brackets are actually required.
lib/genalloc.c line 143
Quoted 4 lines
lib/genalloc.c +4
-0+* @size: amount in bytes +* @order: power of 2 represented by each entry in the bitmap +* +* Returns the number of units representing the size.
Please s/Return/Return:/
Quoted 158 lines
lib/genalloc.c +83
-43+*/ +static inline unsigned long mem_to_units (unsigned long size, +unsigned long order) +{ +return (size + (1UL << order) -1 ) >> order; +} + +/** +* chunk_size - dimension of a chunk of memory, in bytes +* @chunk: pointer to the struct describing the chunk +* +* Return: The size of the chunk, in bytes. +*/ static inline size_t chunk_size (const struct gen_pool_chunk *chunk) {return chunk->end_addr - chunk->start_addr +1 ; } -static int set_bits_ll (unsigned long *addr,unsigned long mask_to_set) + +/** +* set_bits_ll - according to the mask, sets the bits specified by +* value, at the address specified. +* @addr: where to write +* @mask: filter to apply for the bits to alter +* @value: actual configuration of bits to store +* +* Return: 0 upon success, -EBUSY otherwise +*/ +static int set_bits_ll (unsigned long *addr, +unsigned long mask,unsigned long value) { -unsigned long val, nval; +unsigned long nval; +unsigned long present; +unsigned long target; nval = *addr;do { - val = nval; -if (val & mask_to_set) + present = nval; +if (present & mask)return -EBUSY ; + target = present | value;cpu_relax (); - }while ((nval =cmpxchg (addr, val, val | mask_to_set)) != val); - + }while ((nval =cmpxchg (addr, present, target)) != target);return 0 ; } -static int clear_bits_ll (unsigned long *addr,unsigned long mask_to_clear) + +/** +* clear_bits_ll - according to the mask, clears the bits specified by +* value, at the address specified. +* @addr: where to write +* @mask: filter to apply for the bits to alter +* @value: actual configuration of bits to clear +* +* Return: 0 upon success, -EBUSY otherwise +*/ +static int clear_bits_ll (unsigned long *addr, +unsigned long mask,unsigned long value) { -unsigned long val, nval; +unsigned long nval; +unsigned long present; +unsigned long target; nval = *addr; + present = nval; +if (unlikely ((present & mask) ^ value)) +return -EBUSY ;do { - val = nval; -if ((val & mask_to_clear) != mask_to_clear) + present = nval; +if (unlikely ((present & mask) ^ value))return -EBUSY ; + target = present & ~mask;cpu_relax (); - }while ((nval =cmpxchg (addr, val, val & ~mask_to_clear)) != val); - + }while ((nval =cmpxchg (addr, present, target)) != target);return 0 ; } -/* -* bitmap_set_ll - set the specified number of bits at the specified position + +/** +* get_boundary - verify that an allocation effectively +* starts at the given address, then measure its length. * @map: pointer to a bitmap -* @start: a bit position in @map -* @nr: number of bits to set +* @start_entry: the index of the first entry in the bitmap +* @nentries: number of entries to alter * -* Set @nr bits start from @start in @map lock-lessly. Several users -* can set/clear the same bitmap simultaneously without lock. If two -* users set the same bit, one user will return remain bits, otherwise -* return 0. +* Return: the length of an allocation, otherwise -EINVAL if the +* parameters do not refer to a correct allocation. */ -static int bitmap_set_ll (unsigned long *map,int start,int nr) +static int get_boundary (unsigned long *map,int start_entry,int nentries) { -unsigned long *p = map +BIT_WORD (start); -const int size = start + nr; -int bits_to_set =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_set =BITMAP_FIRST_WORD_MASK (start); - -while (nr - bits_to_set >=0 ) { -if (set_bits_ll (p, mask_to_set)) -return nr; - nr -= bits_to_set; - bits_to_set =BITS_PER_LONG ; - mask_to_set = ~0UL ; - p++; - } -if (nr) { - mask_to_set &=BITMAP_LAST_WORD_MASK (size); -if (set_bits_ll (p, mask_to_set)) -return nr; - } +int i; +unsigned long bitmap_entry; -return 0 ; + +if (unlikely (get_bitmap_entry (map, start_entry) !=ENTRY_HEAD )) +return -EINVAL ; +for (i = start_entry +1 ; i < nentries; i++) { + bitmap_entry =get_bitmap_entry (map, i); +if (bitmap_entry ==ENTRY_HEAD || + bitmap_entry ==ENTRY_UNUSED ) +return i; + } +return nentries - start_entry; } + +#define SET_BITS 1 +#define CLEAR_BITS 0 +/* -* bitmap_clear_ll - clear the specified number of bits at the specified position +* alter_bitmap_ll - set or clear the entries associated with an allocation +* @alteration: indicates if the bits selected should be set or cleared * @map: pointer to a bitmap -* @start: a bit position in @map -* @nr: number of bits to set +* @start: the index of the first entry in the bitmap +* @nentries: number of entries to alter
lib/genalloc.c line 264
Quoted 10 lines
lib/genalloc.c +5
-4+* +* The modification happens lock-lessly. +* Several users can write to the same map simultaneously, without lock. * -* Clear @nr bits start from @start in @map lock-lessly. Several users -* can set/clear the same bitmap simultaneously without lock. If two -* users clear the same bit, one user will return remain bits, -* otherwise return 0. +* Return: If two users alter the same bit, to one it will return +* remaining entries, to the other it will return 0.
And what if there are three or four concurrent users? ;-)
I believe that a more elaborate description about what happens with concurrent attempts to alter the bitmap would be really helpful.
Quoted 547 lines
lib/genalloc.c +195
-92*/ -static int bitmap_clear_ll (unsigned long *map,int start,int nr) +static int alter_bitmap_ll (bool alteration,unsigned long *map, +int start_entry,int nentries) { -unsigned long *p = map +BIT_WORD (start); -const int size = start + nr; -int bits_to_clear =BITS_PER_LONG - (start %BITS_PER_LONG ); -unsigned long mask_to_clear =BITMAP_FIRST_WORD_MASK (start); - -while (nr - bits_to_clear >=0 ) { -if (clear_bits_ll (p, mask_to_clear)) -return nr; - nr -= bits_to_clear; - bits_to_clear =BITS_PER_LONG ; - mask_to_clear = ~0UL ; - p++; - } -if (nr) { - mask_to_clear &=BITMAP_LAST_WORD_MASK (size); -if (clear_bits_ll (p, mask_to_clear)) -return nr; +unsigned long start_bit; +unsigned long end_bit; +unsigned long mask; +unsigned long value; +int nbits; +int bits_to_write; +int index; +int (*action)(unsigned long *addr, +unsigned long mask,unsigned long value); + + action = (alteration ==SET_BITS ) ? set_bits_ll : clear_bits_ll; + +/* +* Prepare for writing the initial part of the allocation, from +* starting entry, to the end of the UL bitmap element which +* contains it. It might be larger than the actual allocation. +*/ + start_bit =ENTRIES_TO_BITS (start_entry); + end_bit =ENTRIES_TO_BITS (start_entry + nentries); + nbits =ENTRIES_TO_BITS (nentries); + bits_to_write =BITS_PER_LONG - start_bit %BITS_PER_LONG ; + mask =BITMAP_FIRST_WORD_MASK (start_bit); +/* Mark the beginning of the allocation. */ + value =MASK | (1UL << (start_bit %BITS_PER_LONG )); + index =BITS_DIV_LONGS (start_bit); + +/* +* Writes entries to the bitmap, as long as the reminder is +* positive or zero. +* Might be skipped if the entries to write do not reach the end +* of a bitmap UL unit. +*/ +while (nbits >= bits_to_write) { +if (action (map + index, mask, value & mask)) +return BITS_DIV_ENTRIES (nbits); + nbits -= bits_to_write; + bits_to_write =BITS_PER_LONG ; + mask = ~0UL ; + value =MASK ; + index++; } +/* Takes care of the ending part of the entries to mark. */ +if (nbits >0 ) { + mask ^=BITMAP_FIRST_WORD_MASK ((end_bit) %BITS_PER_LONG ); + bits_to_write = nbits; +if (action (map + index, mask, value & mask)) +return BITS_DIV_ENTRIES (nbits); + }return 0 ; } +/** * gen_pool_create - create a new special memory pool -* @min_alloc_order: log base 2 of number of bytes each bitmap bit represents +* @min_alloc_order: log base 2 of number of bytes each bitmap entry represents * @nid: node id of the node the pool structure should be allocated on, or -1 * * Create a new special memory pool that can be used to manage special purpose * memory not managed by the regular kmalloc/kfree interface. +* +* Return: pointer to the pool, if successful, NULL otherwise */ struct gen_pool *gen_pool_create (int min_alloc_order,int nid) {@@ -177,16 +357,18 @@ EXPORT_SYMBOL(gen_pool_create);* * Add a new chunk of special memory to the specified pool. * -* Returns 0 on success or a -ve errno on failure. +* Return: 0 on success or a -ve errno on failure. */ int gen_pool_add_virt (struct gen_pool *pool,unsigned long virt,phys_addr_t phys,size_t size,int nid) {struct gen_pool_chunk *chunk; -int nbits = size >> pool->min_alloc_order; -int nbytes =sizeof (struct gen_pool_chunk ) + -BITS_TO_LONGS (nbits) *sizeof (long ); +int nentries; +int nbytes; + nentries = size >> pool->min_alloc_order; + nbytes =sizeof (struct gen_pool_chunk ) + +ENTRIES_DIV_LONGS (nentries) *sizeof (long ); chunk =kzalloc_node (nbytes,GFP_KERNEL , nid);if (unlikely (chunk ==NULL ))return -ENOMEM ;@@ -209,7 +391,7 @@ EXPORT_SYMBOL(gen_pool_add_virt);* @pool: pool to allocate from * @addr: starting address of memory * -* Returns the physical address on success, or -1 on error. +* Return: the physical address on success, or -1 on error. */ phys_addr_t gen_pool_virt_to_phys (struct gen_pool *pool,unsigned long addr) {@@ -248,7 +430,7 @@ void gen_pool_destroy(struct gen_pool *pool)list_del (&chunk->next_chunk); end_bit =chunk_size (chunk) >> order; - bit =find_next_bit (chunk->bits, end_bit,0 ); + bit =find_next_bit (chunk->entries, end_bit,0 );BUG_ON (bit < end_bit);kfree (chunk);@@ -267,6 +449,8 @@ EXPORT_SYMBOL(gen_pool_destroy);* Uses the pool allocation function (with first-fit algorithm by default). * Can not be used in NMI handler on architectures without * NMI-safe cmpxchg implementation. +* +* Return: address of the memory allocated, otherwise NULL */ unsigned long gen_pool_alloc (struct gen_pool *pool,size_t size) {@@ -285,6 +469,8 @@ EXPORT_SYMBOL(gen_pool_alloc);* Uses the pool allocation function (with first-fit algorithm by default). * Can not be used in NMI handler on architectures without * NMI-safe cmpxchg implementation. +* +* Return: address of the memory allocated, otherwise NULL */ unsigned long gen_pool_alloc_algo (struct gen_pool *pool,size_t size,genpool_algo_t algo,void *data)@@ -292,7 +478,7 @@ unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size,struct gen_pool_chunk *chunk;unsigned long addr =0 ;int order = pool->min_alloc_order; -int nbits, start_bit, end_bit, remain; +int nentries, start_entry, end_entry, remain;#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG BUG_ON (in_nmi ());@@ -301,29 +487,32 @@ unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size,if (size ==0 )return 0 ; - nbits = (size + (1UL << order) -1 ) >> order; + nentries =mem_to_units (size, order);rcu_read_lock ();list_for_each_entry_rcu (chunk, &pool->chunks, next_chunk) {if (size >atomic_long_read (&chunk->avail))continue ; - start_bit =0 ; - end_bit =chunk_size (chunk) >> order; + start_entry =0 ; + end_entry =chunk_size (chunk) >> order; retry: - start_bit =algo (chunk->bits, end_bit, start_bit, - nbits, data, pool); -if (start_bit >= end_bit) + start_entry =algo (chunk->entries, end_entry, start_entry, + nentries, data, pool); +if (start_entry >= end_entry)continue ; - remain =bitmap_set_ll (chunk->bits, start_bit, nbits); + remain =alter_bitmap_ll (SET_BITS , chunk->entries, + start_entry, nentries);if (remain) { - remain =bitmap_clear_ll (chunk->bits, start_bit, - nbits - remain); -BUG_ON (remain); + remain =alter_bitmap_ll (CLEAR_BITS , + chunk->entries, + start_entry, + nentries - remain); goto retry; } - addr = chunk->start_addr + ((unsigned long )start_bit << order); - size = nbits << order; + addr = chunk->start_addr + + ((unsigned long )start_entry << order); + size = nentries << order;atomic_long_sub (size, &chunk->avail);break ; }@@ -342,6 +531,8 @@ EXPORT_SYMBOL(gen_pool_alloc_algo);* Uses the pool allocation function (with first-fit algorithm by default). * Can not be used in NMI handler on architectures without * NMI-safe cmpxchg implementation. +* +* Return: address of the memory allocated, otherwise NULL */ void *gen_pool_dma_alloc (struct gen_pool *pool,size_t size,dma_addr_t *dma) {@@ -365,7 +556,7 @@ EXPORT_SYMBOL(gen_pool_dma_alloc);* gen_pool_free - free allocated special memory back to the pool * @pool: pool to free to * @addr: starting address of memory to free back to pool -* @size: size in bytes of memory to free +* @size: size in bytes of memory to free or 0, for auto-detection * * Free previously allocated special memory back to the specified * pool. Can not be used in NMI handler on architectures without @@ -375,22 +566,29 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) {struct gen_pool_chunk *chunk;int order = pool->min_alloc_order; -int start_bit, nbits, remain; +int start_entry, remaining_entries, nentries, remain; +int boundary;#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG BUG_ON (in_nmi ());#endif - nbits = (size + (1UL << order) -1 ) >> order;rcu_read_lock ();list_for_each_entry_rcu (chunk, &pool->chunks, next_chunk) {if (addr >= chunk->start_addr && addr <= chunk->end_addr) {BUG_ON (addr + size -1 > chunk->end_addr); - start_bit = (addr - chunk->start_addr) >> order; - remain =bitmap_clear_ll (chunk->bits, start_bit, nbits); + start_entry = (addr - chunk->start_addr) >> order; + remaining_entries = (chunk->end_addr - addr) >> order; + boundary =get_boundary (chunk->entries, start_entry, + remaining_entries); +BUG_ON (boundary <0 ); + nentries = boundary - start_entry; +BUG_ON (size && + (nentries !=mem_to_units (size, order))); + remain =alter_bitmap_ll (CLEAR_BITS , chunk->entries, + start_entry, nentries);BUG_ON (remain); - size = nbits << order; -atomic_long_add (size, &chunk->avail); +atomic_long_add (nentries << order, &chunk->avail);rcu_read_unlock ();return ; }@@ -428,8 +626,9 @@ EXPORT_SYMBOL(gen_pool_for_each_chunk);* @start: start address * @size: size of the region * -* Check if the range of addresses falls within the specified pool. Returns -* true if the entire range is contained in the pool and false otherwise. +* Check if the range of addresses falls within the specified pool. +* +* Return: true if the entire range is contained in the pool, false otherwise. */ bool addr_in_gen_pool (struct gen_pool *pool,unsigned long start,size_t size)@@ -455,7 +654,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,* gen_pool_avail - get available free space of the pool * @pool: pool to get available free space * -* Return available free space of the specified pool. +* Return: available free space of the specified pool. */ size_t gen_pool_avail (struct gen_pool *pool) {@@ -474,7 +673,7 @@ EXPORT_SYMBOL_GPL(gen_pool_avail);* gen_pool_size - get size in bytes of memory managed by the pool * @pool: pool to get size * -* Return size in bytes of memory managed by the pool. +* Return: size in bytes of memory managed by the pool. */ size_t gen_pool_size (struct gen_pool *pool) {@@ -517,17 +716,27 @@ EXPORT_SYMBOL(gen_pool_set_algo);* gen_pool_first_fit - find the first available region * of memory matching the size requirement (no alignment constraint) * @map: The address to base the search on -* @size: The bitmap size in bits -* @start: The bitnumber to start searching at -* @nr: The number of zeroed bits we're looking for +* @size: The number of allocation units in the bitmap +* @start: The allocation unit to start searching at +* @nr: The number of allocation units we're looking for * @data: additional data - unused * @pool: pool to find the fit region memory from +* +* Return: index of the memory allocated, otherwise the end of the range */ unsigned long gen_pool_first_fit (unsigned long *map,unsigned long size,unsigned long start,unsigned int nr,void *data,struct gen_pool *pool) { -return bitmap_find_next_zero_area (map, size, start, nr,0 ); +unsigned long align_mask; +unsigned long bit_index; + + align_mask =roundup_pow_of_two (BITS_PER_ENTRY ) -1 ; + bit_index =bitmap_find_next_zero_area (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (start), +ENTRIES_TO_BITS (nr), + align_mask); +return BITS_DIV_ENTRIES (bit_index); }EXPORT_SYMBOL (gen_pool_first_fit);@@ -535,11 +744,13 @@ EXPORT_SYMBOL(gen_pool_first_fit);* gen_pool_first_fit_align - find the first available region * of memory matching the size requirement (alignment constraint) * @map: The address to base the search on -* @size: The bitmap size in bits -* @start: The bitnumber to start searching at -* @nr: The number of zeroed bits we're looking for +* @size: The number of allocation units in the bitmap +* @start: The allocation unit to start searching at +* @nr: The number of allocation units we're looking for * @data: data for alignment * @pool: pool to get order from +* +* Return: index of the memory allocated, otherwise the end of the range */ unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size, unsigned long start, unsigned int nr, void *data,@@ -547,23 +758,32 @@ unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size, {struct genpool_data_align *alignment;unsigned long align_mask; +unsigned long bit_index;int order; alignment = data; order = pool->min_alloc_order; - align_mask = ((alignment->align + (1UL << order) -1 ) >> order) -1 ; -return bitmap_find_next_zero_area (map, size, start, nr, align_mask); + align_mask =roundup_pow_of_two ( +ENTRIES_TO_BITS (mem_to_units (alignment->align, + order))) -1 ; + bit_index =bitmap_find_next_zero_area (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (start), +ENTRIES_TO_BITS (nr), + align_mask); +return BITS_DIV_ENTRIES (bit_index); }EXPORT_SYMBOL (gen_pool_first_fit_align);/** * gen_pool_fixed_alloc - reserve a specific region * @map: The address to base the search on -* @size: The bitmap size in bits -* @start: The bitnumber to start searching at -* @nr: The number of zeroed bits we're looking for +* @size: The number of allocation units in the bitmap +* @start: The allocation unit to start searching at +* @nr: The number of allocation units we're looking for * @data: data for alignment * @pool: pool to get order from +* +* Return: index of the memory allocated, otherwise the end of the range */ unsigned long gen_pool_fixed_alloc(unsigned long *map, unsigned long size, unsigned long start, unsigned int nr, void *data,@@ -571,20 +791,23 @@ unsigned long gen_pool_fixed_alloc(unsigned long *map, unsigned long size, {struct genpool_data_fixed *fixed_data;int order; -unsigned long offset_bit; -unsigned long start_bit; +unsigned long offset; +unsigned long align_mask; +unsigned long bit_index; fixed_data = data; order = pool->min_alloc_order; - offset_bit = fixed_data->offset >> order;if (WARN_ON (fixed_data->offset & ((1UL << order) -1 )))return size; + offset = fixed_data->offset >> order; + align_mask =roundup_pow_of_two (BITS_PER_ENTRY ) -1 ; + bit_index =bitmap_find_next_zero_area (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (start + offset), +ENTRIES_TO_BITS (nr), align_mask); +if (bit_index !=ENTRIES_TO_BITS (offset)) +return size; - start_bit =bitmap_find_next_zero_area (map, size, - start + offset_bit, nr,0 ); -if (start_bit != offset_bit) - start_bit = size; -return start_bit; +return BITS_DIV_ENTRIES (bit_index); }EXPORT_SYMBOL (gen_pool_fixed_alloc);@@ -593,60 +816,84 @@ EXPORT_SYMBOL(gen_pool_fixed_alloc);* of memory matching the size requirement. The region will be aligned * to the order of the size specified. * @map: The address to base the search on -* @size: The bitmap size in bits -* @start: The bitnumber to start searching at -* @nr: The number of zeroed bits we're looking for +* @size: The number of allocation units in the bitmap +* @start: The allocation unit to start searching at +* @nr: The number of allocation units we're looking for * @data: additional data - unused * @pool: pool to find the fit region memory from +* +* Return: index of the memory allocated, otherwise the end of the range */ unsigned long gen_pool_first_fit_order_align (unsigned long *map,unsigned long size,unsigned long start,unsigned int nr,void *data,struct gen_pool *pool) { -unsigned long align_mask =roundup_pow_of_two (nr) -1 ; - -return bitmap_find_next_zero_area (map, size, start, nr, align_mask); +unsigned long align_mask; +unsigned long bit_index; + + align_mask =roundup_pow_of_two (ENTRIES_TO_BITS (nr)) -1 ; + bit_index =bitmap_find_next_zero_area (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (start), +ENTRIES_TO_BITS (nr), + align_mask); +return BITS_DIV_ENTRIES (bit_index); }EXPORT_SYMBOL (gen_pool_first_fit_order_align);/** * gen_pool_best_fit - find the best fitting region of memory -* macthing the size requirement (no alignment constraint) +* matching the size requirement (no alignment constraint) * @map: The address to base the search on -* @size: The bitmap size in bits -* @start: The bitnumber to start searching at -* @nr: The number of zeroed bits we're looking for +* @size: The number of allocation units in the bitmap +* @start: The allocation unit to start searching at +* @nr: The number of allocation units we're looking for * @data: additional data - unused * @pool: pool to find the fit region memory from * * Iterate over the bitmap to find the smallest free region * which we can allocate the memory. +* +* Return: index of the memory allocated, otherwise the end of the range */ unsigned long gen_pool_best_fit (unsigned long *map,unsigned long size,unsigned long start,unsigned int nr,void *data,struct gen_pool *pool) { -unsigned long start_bit = size; +unsigned long start_bit =ENTRIES_TO_BITS (size);unsigned long len = size +1 ;unsigned long index; +unsigned long align_mask; +unsigned long bit_index; - index =bitmap_find_next_zero_area (map, size, start, nr,0 ); + align_mask =roundup_pow_of_two (BITS_PER_ENTRY ) -1 ; + bit_index =bitmap_find_next_zero_area (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (start), +ENTRIES_TO_BITS (nr), + align_mask); + index =BITS_DIV_ENTRIES (bit_index);while (index < size) { -int next_bit =find_next_bit (map, size, index + nr); -if ((next_bit - index) < len) { - len = next_bit - index; - start_bit = index; +int next_bit; + + next_bit =find_next_bit (map,ENTRIES_TO_BITS (size), +ENTRIES_TO_BITS (index + nr)); +if ((BITS_DIV_ENTRIES (next_bit) - index) < len) { + len =BITS_DIV_ENTRIES (next_bit) - index; + start_bit =ENTRIES_TO_BITS (index);if (len == nr) -return start_bit; +return BITS_DIV_ENTRIES (start_bit); } - index =bitmap_find_next_zero_area (map, size, - next_bit +1 , nr,0 ); + bit_index = +bitmap_find_next_zero_area (map, +ENTRIES_TO_BITS (size), + next_bit +1 , +ENTRIES_TO_BITS (nr), + align_mask); + index =BITS_DIV_ENTRIES (bit_index); } -return start_bit; +return BITS_DIV_ENTRIES (start_bit); } -EXPORT_SYMBOL (gen_pool_best_fit);static void devm_gen_pool_release (struct device *dev,void *res) {@@ -672,7 +919,7 @@ static int devm_gen_pool_match(struct device *dev, void *res, void *data)* @dev: device to retrieve the gen_pool from * @name: name of a gen_pool or NULL, identifies a particular gen_pool on device * -* Returns the gen_pool for the device if one is present, or NULL. +* Return: the gen_pool for the device if one is present, or NULL. */ struct gen_pool *gen_pool_get (struct device *dev,const char *name) {@@ -696,6 +943,8 @@ EXPORT_SYMBOL_GPL(gen_pool_get);* Create a new special memory pool that can be used to manage special purpose * memory not managed by the regular kmalloc/kfree interface. The pool will be * automatically destroyed by the device management code. +* +* Return: the address of the pool, if successful, otherwise NULL */ struct gen_pool *devm_gen_pool_create (struct device *dev,int min_alloc_order,int nid,const char *name)@@ -743,7 +992,7 @@ EXPORT_SYMBOL(devm_gen_pool_create);* @propname: property name containing phandle(s) * @index: index into the phandle array * -* Returns the pool that contains the chunk starting at the physical +* Return: the pool that contains the chunk starting at the physical * address of the device tree node pointed at by the phandle property, * or NULL if not found. */ Signature · 7 lines
2.14.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 1/6] genalloc: track beginning of allocations
Quoted 1 line · Mike Rapoport
On Sun, Feb 11, 2018 at 05:19:15AM +0200, Igor Stoppa wrote:
[...]
Quoted 6 lines
Quoted 2 lines
+/**
+ *mem_to_units- convert references to memory into orders of allocation
Documentation/doc-guide/kernel-doc.rstrecommends to to include brackets for function comments. I haven't noticed any difference in the resulting html, so I'm not sure if the brackets are actually required.
This is what I see in the example from mailine docs:
/**
* foobar() - Brief description of foobar.
* @argument1: Description of parameter argument1 of foobar.
* @argument2: Description of parameter argument2 of foobar. *
* Longer description of foobar.
*
* Return: Description of return value of foobar. */
int foobar(int argument1, char *argument2)
What are you referring to?
[...]
Quoted 6 lines
Quoted 4 lines
+ * @size: amount in bytes
+ * @order: power of 2 represented by each entry in the bitmap
+ *
+ * Returns the number of units representing the size.Please s/Return/Return:/
:-( I thought I had fixed them all. thanks for spotting this.
[...]
Quoted 7 lines
Quoted 2 lines
+ * Return: If two users alter the same bit, to one it will return
+ * remaining entries, to the other it will return 0.And what if there are three or four concurrent users? ;-)
I believe that a more elaborate description about what happens with concurrent attempts to alter the bitmap would be really helpful.
ok
--
thanks, igor
Re: [PATCH 1/6] genalloc: track beginning of allocations
Quoted 27 lines · Igor Stoppa
Quoted 1 line · Mike Rapoport
On Sun, Feb 11, 2018 at 05:19:15AM +0200, Igor Stoppa wrote:
[...]
Quoted 6 lines
Quoted 2 lines
+/**
+ *mem_to_units- convert references to memory into orders of allocation
Documentation/doc-guide/kernel-doc.rstrecommends to to include brackets for function comments. I haven't noticed any difference in the resulting html, so I'm not sure if the brackets are actually required.This is what I see in the example from mailine docs:
/**
*foobar()- Brief description of foobar.
* @argument1: Description of parameter argument1 of foobar.
* @argument2: Description of parameter argument2 of foobar. *
* Longer description of foobar.
*
* Return: Description of return value of foobar. */
intfoobar(int argument1, char *argument2)
Quoted 1 line
What are you referring to?
I'm referring to "foobar() - brief description" vs "foobar - brief description".
The generated html looks exactly the same in the browser, so I don't know if the brackets are really required.
Quoted 26 lines
[...]
Quoted 6 lines
Quoted 4 lines
+ * @size: amount in bytes
+ * @order: power of 2 represented by each entry in the bitmap
+ *
+ * Returns the number of units representing the size.Please s/Return/Return:/
:-( I thought I had fixed them all. thanks for spotting this.
[...]
Quoted 7 lines
Quoted 2 lines
+ * Return: If two users alter the same bit, to one it will return
+ * remaining entries, to the other it will return 0.And what if there are three or four concurrent users? ;-)
I believe that a more elaborate description about what happens with concurrent attempts to alter the bitmap would be really helpful.
ok
--
thanks, igor
Signature · 2 lines
Sincerely yours, Mike.
kbuild test robot
build botRe: [PATCH 1/6] genalloc: track beginning of allocations
In reply to Igor StoppaThank you for the patch! Yet something to improve:
Hi Igor,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc1 next-20180212]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Igor-Stoppa/genalloc-track-beginning-of-allocations/20180212-192839
config: openrisc-allmodconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 6.0.0 20160327 (experimental)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=openrisc
All errors (new ones prefixed by >>):
WARNING: modpost: missing MODULE_LICENSE() in drivers/media/platform/mtk-vcodec/mtk-vcodec-common.o see include/linux/module.h for more information
WARNING: modpost: missing MODULE_LICENSE() in drivers/media/platform/tegra-cec/tegra_cec.o see include/linux/module.h for more information
>> ERROR: "gen_pool_best_fit" [drivers/tee/tee.ko] undefined!
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v15 2/6 genalloc: selftest
In reply to Igor StoppaIntroduce a set of macros for writing concise test cases for genalloc.
The test cases are meant to provide regression testing, when working on new functionality for genalloc.
Primarily they are meant to confirm that the various allocation strategy will continue to work as expected.
The execution of the self testing is controlled through a Kconfig option.
--- include/linux/genalloc-selftest.h | 26 +++ init/main.c | 2 + lib/Kconfig | 15 ++ lib/Makefile | 1 + lib/genalloc-selftest.c | 400 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 444 insertions(+) create mode 100644 include/linux/genalloc-selftest.h create mode 100644 lib/genalloc-selftest.c
include/linux/genalloc-selftest.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* genalloc-selftest.h +* +* (C) Copyright 2017 Huawei Technologies Co. Ltd. +* Author: Igor Stoppa <[email protected]> +*/ + + +#ifndef __LINUX_GENALLOC_SELFTEST_H +#define __LINUX_GENALLOC_SELFTEST_H + + +#ifdef CONFIG_GENERIC_ALLOCATOR_SELFTEST + +#include <linux/genalloc.h> + +void genalloc_selftest (void ); + +#else + +static inline void genalloc_selftest (void ){}; + +#endif + +#endif
init/main.c +2 -0
@@ -89,6 +89,7 @@#include <linux/io.h> #include <linux/cache.h> #include <linux/rodata_test.h> +#include <linux/genalloc-selftest.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -660,6 +661,7 @@ asmlinkage __visible void __init start_kernel(void)*/ mem_encrypt_init (); +genalloc_selftest ();#ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok &&page_to_pfn (virt_to_page ((void *)initrd_start)) < min_low_pfn) {
lib/Kconfig +15 -0
@@ -287,6 +287,21 @@ config DECOMPRESS_LZ4 config GENERIC_ALLOCATOR bool +config GENERIC_ALLOCATOR_SELFTEST + bool "genalloc tester" + default n + select GENERIC_ALLOCATOR + help + Enable automated testing of the generic allocator. + The testing is primarily for the tracking of allocated space. + +config GENERIC_ALLOCATOR_SELFTEST_VERBOSE + bool "make the genalloc tester more verbose" + default n + select GENERIC_ALLOCATOR_SELFTEST + help + More information will be displayed during the self-testing. + # # reed solomon support is select'ed if needed #
lib/Makefile +1 -0
@@ -108,6 +108,7 @@ obj-$(CONFIG_LIBCRC32C) += libcrc32c.o obj-$(CONFIG_CRC8) += crc8.o obj-$(CONFIG_XXHASH) += xxhash.o obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o +obj-$(CONFIG_GENERIC_ALLOCATOR_SELFTEST) += genalloc-selftest.o obj-$(CONFIG_842_COMPRESS) += 842/ obj-$(CONFIG_842_DECOMPRESS) += 842/
lib/genalloc-selftest.c new file +400 -0
400 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [PATCH 2/6] genalloc: selftest
Quoted 11 lines · Igor Stoppa
Introduce a set of macros for writing concise test cases for genalloc.
The test cases are meant to provide regression testing, when working on new functionality for genalloc.
Primarily they are meant to confirm that the various allocation strategy will continue to work as expected.
The execution of the self testing is controlled through a
Kconfigoption.Signed-off-by Igor Stoppa <[email protected]>
<snip>
include/linux/genalloc-selftest.h line 1
Quoted 4 lines
include/linux/genalloc-selftest.h new file +1
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0
nit... For a comment in .h this line should be instead its own comment as the first line:
Quoted 1 line
include/linux/genalloc-selftest.h new file +1
-0+/* SPDX-License-Identifier: GPL-2.0 */
<snip>
lib/genalloc-selftest.c line 1
Quoted 4 lines
lib/genalloc-selftest.c new file +1
-0@@ -0,0 +1,400 @@ +/* SPDX-License-Identifier: GPL-2.0
And for a comment in .c this line should use C++ style as the first line:
lib/genalloc-selftest.c line 2
Quoted 1 line
lib/genalloc-selftest.c new file +1
-0+// SPDX-License-Identifier: GPL-2.0
Please check the docs for this (I know this can feel surprising but this has been debated at great length on list)
Thank you!
Signature · 2 lines
Cordially Philippe Ombredanne
Randy Dunlap
reviewerRe: [PATCH 2/6] genalloc: selftest
Quoted 15 lines · Philippe Ombredanne
Quoted 11 lines · Igor Stoppa
Introduce a set of macros for writing concise test cases for genalloc.
The test cases are meant to provide regression testing, when working on new functionality for genalloc.
Primarily they are meant to confirm that the various allocation strategy will continue to work as expected.
The execution of the self testing is controlled through a
Kconfigoption.Signed-off-by Igor Stoppa <[email protected]><snip>
Quoted 8 lines
include/linux/genalloc-selftest.h line 1
Quoted 4 lines
include/linux/genalloc-selftest.h new file +1
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 nit... For a comment in .h this line should be instead its own comment as the first line:
Quoted 1 line
include/linux/genalloc-selftest.h new file +1
-0+/* SPDX-License-Identifier: GPL-2.0 */
Why are we treating header files (.h) differently than .c files? Either one can use the C++ "//" comment syntax.
Quoted 16 lines
<snip>
lib/genalloc-selftest.c line 1
Quoted 4 lines
lib/genalloc-selftest.c new file +1
-0@@ -0,0 +1,400 @@ +/* SPDX-License-Identifier: GPL-2.0 And for a comment in .c this line should use C++ style as the first line:
lib/genalloc-selftest.c line 2
Quoted 1 line
lib/genalloc-selftest.c new file +1
-0+// SPDX-License-Identifier: GPL-2.0 Please check the docs for this (I know this can feel surprising but this has been debated at great length on list)
Thank you!
Signature · 1 line
~Randy
Re: [PATCH 2/6] genalloc: selftest
Quoted 7 lines · Randy Dunlap
Quoted 3 lines · Philippe Ombredanne
nit... For a comment in .h this line should be instead its own comment as the first line:
Quoted 1 line
+/* SPDX-License-Identifier: GPL-2.0 */
Why are we treating header files (.h) differently than .c files? Either one can use the C++ "//" comment syntax.
This is now documented!
Documentation/process/license-rules.rst:
If a specific tool cannot handle the standard comment style, then the appropriate comment mechanism which the tool accepts shall be used. This is the reason for having the "/\* \*/" style comment in C header files. There was build breakage observed with generated .lds files where 'ld' failed to parse the C++ comment. This has been fixed by now, but there are still older assembler tools which cannot handle C++ style comments.
Personally, I find this disappointing. I find this:
// SPDX-License-Identifier: GPL-2.0+
/*
* XArray implementation
* Copyright (c) 2017 Microsoft Corporation
* Author: Matthew Wilcox <[email protected]> */
much less visually appealling than
/*
* XArray implementation
* Copyright (c) 2017 Microsoft Corporation
* Author: Matthew Wilcox <[email protected]>
* SPDX-License-Identifier: GPL-2.0+
*/
I can't see this variation making a tag extraction tool harder to write.
PATCH v15 3/6 struct page: add field for vm_struct
In reply to Igor StoppaWhen a page is used for virtual memory, it is often necessary to obtian a handler to the corresponding vm_struct, which refers to the virtually continuous area generated when invoking vmalloc.
The struct page has a "mapping" field, which can be re-used, to store a pointer to the parent area. This will avoid more expensive searches.
As example, the function find_vm_area is reimplemented, to take advantage of the newly introduced field.
--- include/linux/mm_types.h | 1 + mm/vmalloc.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-)
include/linux/mm_types.h +1 -0
@@ -84,6 +84,7 @@ struct page {void *s_mem;/* slab first object */ atomic_t compound_mapcount;/* first tail page */ /* page_deferred_list().next -- second tail page */ +struct vm_struct *area; };/* Second double word */
mm/vmalloc.c +13 -5
@@ -1466,13 +1466,16 @@ struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags,*/ struct vm_struct *find_vm_area (const void *addr) { -struct vmap_area *va; +struct page *page; - va =find_vmap_area ((unsigned long )addr); -if (va && va->flags &VM_VM_AREA ) -return va->vm; +if (unlikely (!is_vmalloc_addr (addr))) +return NULL ; -return NULL ; + page =vmalloc_to_page (addr); +if (unlikely (!page)) +return NULL ; + +return page->area; }/**
@@ -1536,6 +1539,7 @@ static void __vunmap(const void *addr, int deallocate_pages)struct page *page = area->pages[i];BUG_ON (!page); + page->area =NULL ;__free_pages (page,0 ); }
@@ -1744,6 +1748,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, const void *caller) {struct vm_struct *area; +unsigned int i;void *addr;unsigned long real_size = size;
@@ -1769,6 +1774,9 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,kmemleak_vmalloc (area, size, gfp_mask); +for (i =0 ; i < area->nr_pages; i++) + area->pages[i]->area = area; +return addr; fail:
Signature · 1 line
2.14.1
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 5 lines · Igor Stoppa
The struct page has a "mapping" field, which can be re-used, to store a pointer to the parent area. This will avoid more expensive searches.
As example, the function
find_vm_areais reimplemented, to take advantage of the newly introduced field.
Umm. Is it more efficient? You're replacing an rb-tree search with a page-table walk. You eliminate a spinlock, which is great, but is the page-table walk more efficient? I suppose it'll depend on the depth of the rb-tree, and (at least on x86), the page tables should already be in cache.
Unrelated to this patch, I'm working on a patch to give us page_type, and I think I'll allocate a bit to mark pages which are vmalloced.
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 4 lines · Matthew Wilcox
Quoted 3 lines · Igor Stoppa
The struct page has a "mapping" field, which can be re-used, to store a pointer to the parent area. This will avoid more expensive searches.
Quoted 8 lines
Quoted 2 lines
As example, the function
find_vm_areais reimplemented, to take advantage of the newly introduced field.Umm. Is it more efficient? You're replacing an rb-tree search with a page-table walk. You eliminate a spinlock, which is great, but is the page-table walk more efficient? I suppose it'll depend on the depth of the rb-tree, and (at least on x86), the page tables should already be in cache.
I thought the tradeoff favorable. How to verify it?
Quoted 2 lines
Unrelated to this patch, I'm working on a patch to give us
page_type, and I think I'll allocate a bit to mark pages which are vmalloced.
pmalloced too?
--
igor
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 10 lines · Igor Stoppa
Quoted 7 lines · Matthew Wilcox
Quoted 5 lines · Igor Stoppa
The struct page has a "mapping" field, which can be re-used, to store a pointer to the parent area. This will avoid more expensive searches.
As example, the function
find_vm_areais reimplemented, to take advantage of the newly introduced field.
Quoted 7 lines
Quoted 5 lines
Umm. Is it more efficient? You're replacing an rb-tree search with a page-table walk. You eliminate a spinlock, which is great, but is the page-table walk more efficient? I suppose it'll depend on the depth of the rb-tree, and (at least on x86), the page tables should already be in cache.
I thought the tradeoff favorable.
It turns out that it's probably not so favorable.
The patch relies on the function vmalloc_to_page ... which will return NULL when applied to huge mappings, while the original implementation will still work.
It was found while testing on a configuration with framebuffer.
So it seems unlikely that there is any gain to be had, from this perspective.
The use of the field still makes sense from the perspective of adding pmalloc support to hardened usercopy, but there is no more need for the field to exist as separate patch.
This patch can be simplified and merged with the pmalloc patch.
--
igor
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 3 lines · Igor Stoppa
The patch relies on the function
vmalloc_to_page... which will return NULL when applied to huge mappings, while the original implementation will still work.
Huh? vmalloc_to_page() should work for huge mappings...
Quoted 1 line
It was found while testing on a configuration with framebuffer.
... ah. You tried to use vmalloc_to_page() on something which wasn't backed by a struct page. That's *supposed* to return NULL, but my guess is that after this patch it returned garbage.
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 1 line · Matthew Wilcox
On Tue, Feb 20, 2018 at 09:53:30PM +0200, Igor Stoppa wrote:
[...]
Quoted 5 lines
Quoted 1 line
It was found while testing on a configuration with framebuffer.
... ah. You tried to use
vmalloc_to_page()on something which wasn't backed by a struct page. That's *supposed* to return NULL, but my guess is that after this patch it returned garbage.
it seems to return garbage also without this patch, but I need to clean up the code, try it again and possibly come up with a demo patch for triggering the problem.
I'll investigate it more. However it doesn't seem to be related to the functionality I need. So I plan to treat it as separate issue and leave find_vm_area untouched, at least in pmalloc scope.
--
igor
Re: [PATCH 3/6] struct page: add field for vm_struct
Quoted 7 lines · Igor Stoppa
it seems to return garbage also without this patch, but I need to clean up the code, try it again and possibly come up with a demo patch for triggering the problem.
I'll investigate it more. However it doesn't seem to be related to the functionality I need. So I plan to treat it as separate issue and leave
find_vm_areauntouched, at least in pmalloc scope.
Follow-up:
https://lkml.org/lkml/2018/2/22/427
--
igor
PATCH v15 4/6 Protectable Memory
In reply to Igor StoppaThe MMU available in many systems running Linux can often provide R/O protection to the memory pages it handles.
However, the MMU-based protection works efficiently only when said pages contain exclusively data that will not need further modifications.
Statically allocated variables can be segregated into a dedicated section, but this does not sit very well with dynamically allocated ones.
Dynamic allocation does not provide, currently, any means for grouping variables in memory pages that would contain exclusively data suitable for conversion to read only access mode.
The allocator here provided (pmalloc - protectable memory allocator) introduces the concept of pools of protectable memory.
A module can request a pool and then refer any allocation request to the pool handler it has received.
Once all the chunks of memory associated to a specific pool are initialized, the pool can be protected.
After this point, the pool can only be destroyed (it is up to the module to avoid any further references to the memory from the pool, after the destruction is invoked).
The latter case is mainly meant for releasing memory, when a module is unloaded.
A module can have as many pools as needed, for example to support the protection of data that is initialized in sufficiently distinct phases.
--- include/linux/genalloc.h | 3 + include/linux/pmalloc.h | 222 +++++++++++++++++++++ include/linux/vmalloc.h | 1 + lib/genalloc.c | 27 +++ mm/Kconfig | 6 + mm/Makefile | 1 + mm/pmalloc.c | 497 +++++++++++++++++++++++++++++++++++++++++++++++ mm/usercopy.c | 33 ++++ 8 files changed, 790 insertions(+) create mode 100644 include/linux/pmalloc.h create mode 100644 mm/pmalloc.c
include/linux/genalloc.h +3 -0
@@ -121,6 +121,9 @@ extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t,extern void *gen_pool_dma_alloc (struct gen_pool *pool,size_t size,dma_addr_t *dma);extern void gen_pool_free (struct gen_pool *,unsigned long ,size_t ); + +extern void gen_pool_flush_chunk (struct gen_pool *pool, +struct gen_pool_chunk *chunk);extern void gen_pool_for_each_chunk (struct gen_pool *,void (*)(struct gen_pool *,struct gen_pool_chunk *,void *),void *);extern size_t gen_pool_avail (struct gen_pool *);
include/linux/pmalloc.h new file +222 -0
222 lines not on this page · raw message
include/linux/vmalloc.h +1 -0
@@ -20,6 +20,7 @@ struct notifier_block; /* in notifier.h */#define VM_UNINITIALIZED 0x00000020/* vm_struct is not fully initialized */ #define VM_NO_GUARD 0x00000040/* don't add guard page */ #define VM_KASAN 0x00000080/* has allocated kasan shadow memory */ +#define VM_PMALLOC 0x00000100/* pmalloc area - see docs */ /* bits [20..32] reserved for arch specific ioremap internals */ /*
lib/genalloc.c +27 -0
@@ -598,6 +598,33 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) }EXPORT_SYMBOL (gen_pool_free); + +/** +* gen_pool_flush_chunk - drops all the allocations from a specific chunk +* @pool: the generic memory pool +* @chunk: The chunk to wipe clear. +* +* This is meant to be called only while destroying a pool. It's up to the +* caller to avoid races, but really, at this point the pool should have +* already been retired and have become unavailable for any other sort of +* operation. +*/ +void gen_pool_flush_chunk (struct gen_pool *pool, +struct gen_pool_chunk *chunk) +{ +size_t size; + +if (unlikely (!(pool && chunk))) +return ; + + size = chunk->end_addr +1 - chunk->start_addr; +memset (chunk->entries,0 , +DIV_ROUND_UP (size >> pool->min_alloc_order *BITS_PER_ENTRY , +BITS_PER_BYTE )); +atomic_long_set (&chunk->avail, size); +} + +/** * gen_pool_for_each_chunk - call func for every chunk of generic memory pool * @pool: the generic memory pool
mm/Kconfig +6 -0
@@ -760,3 +760,9 @@ config GUP_BENCHMARK performance of get_user_pages_fast(). See tools/testing/selftests/vm/gup_benchmark.c + +config PROTECTABLE_MEMORY + bool + depends on ARCH_HAS_SET_MEMORY + select GENERIC_ALLOCATOR + default y
mm/Makefile +1 -0
@@ -65,6 +65,7 @@ obj-$(CONFIG_SPARSEMEM) += sparse.o obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o obj-$(CONFIG_SLOB) += slob.o obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o +obj-$(CONFIG_PROTECTABLE_MEMORY) += pmalloc.o obj-$(CONFIG_KSM) += ksm.o obj-$(CONFIG_PAGE_POISONING) += page_poison.o obj-$(CONFIG_SLAB) += slab.o
mm/pmalloc.c new file +497 -0
497 lines not on this page · raw message
mm/usercopy.c +33 -0
@@ -240,6 +240,36 @@ static inline void check_heap_object(const void *ptr, unsigned long n, } } +#ifdef CONFIG_PROTECTABLE_MEMORY + +int is_pmalloc_object (const void *ptr,const unsigned long n); + +static void check_pmalloc_object (const void *ptr,unsigned long n, +bool to_user) +{ +int retv; + + retv =is_pmalloc_object (ptr, n); +if (unlikely (retv)) { +if (unlikely (!to_user)) +usercopy_abort ("pmalloc" , +"trying to write to pmalloc object" , + to_user, (const unsigned long )ptr, n); +if (retv <0 ) +usercopy_abort ("pmalloc" , +"invalid pmalloc object" , + to_user, (const unsigned long )ptr, n); + } +} + +#else + +static void check_pmalloc_object (const void *ptr,unsigned long n, +bool to_user) +{ +} +#endif +/* * Validates that the given object is: * - not bogus address
@@ -277,5 +307,8 @@ void __check_object_size(const void *ptr, unsigned long n, bool to_user)/* Check for object in kernel to avoid text exposure. */ check_kernel_text_object ((const unsigned long )ptr, n, to_user); + +/* Check if object is from a pmalloc chunk. */ +check_pmalloc_object (ptr, n, to_user); }EXPORT_SYMBOL (__check_object_size);
Signature · 1 line
2.14.1
Re: [PATCH 4/6] Protectable Memory
Quoted 119 lines · Igor Stoppa
The MMU available in many systems running Linux can often provide R/O protection to the memory pages it handles.
However, the MMU-based protection works efficiently only when said pages contain exclusively data that will not need further modifications.
Statically allocated variables can be segregated into a dedicated section, but this does not sit very well with dynamically allocated ones.
Dynamic allocation does not provide, currently, any means for grouping variables in memory pages that would contain exclusively data suitable for conversion to read only access mode.
The allocator here provided (pmalloc - protectable memory allocator) introduces the concept of pools of protectable memory.
A module can request a pool and then refer any allocation request to the pool handler it has received.
Once all the chunks of memory associated to a specific pool are initialized, the pool can be protected.
After this point, the pool can only be destroyed (it is up to the module to avoid any further references to the memory from the pool, after the destruction is invoked).
The latter case is mainly meant for releasing memory, when a module is unloaded.
A module can have as many pools as needed, for example to support the protection of data that is initialized in sufficiently distinct phases.
Signed-off-by Igor Stoppa <[email protected]>--- include/linux/genalloc.h | 3 + include/linux/pmalloc.h | 222 +++++++++++++++++++++ include/linux/vmalloc.h | 1 + lib/genalloc.c | 27 +++ mm/Kconfig | 6 + mm/Makefile | 1 + mm/pmalloc.c | 497 +++++++++++++++++++++++++++++++++++++++++++++++ mm/usercopy.c | 33 ++++ 8 files changed, 790 insertions(+) create mode 100644 include/linux/pmalloc.h create mode 100644 mm/pmalloc.cinclude/linux/genalloc.h +3
-0@@ -121,6 +121,9 @@ extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t,extern void *gen_pool_dma_alloc (struct gen_pool *pool,size_t size,dma_addr_t *dma);extern void gen_pool_free (struct gen_pool *,unsigned long ,size_t ); + +extern void gen_pool_flush_chunk (struct gen_pool *pool, +struct gen_pool_chunk *chunk);extern void gen_pool_for_each_chunk (struct gen_pool *,void (*)(struct gen_pool *,struct gen_pool_chunk *,void *),void *);extern size_t gen_pool_avail (struct gen_pool *);include/linux/pmalloc.h new file +52
-0@@ -0,0 +1,222 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* pmalloc.h: Header for Protectable Memory Allocator +* +* (C) Copyright 2017 Huawei Technologies Co. Ltd. +* Author: Igor Stoppa <[email protected]> +*/ + +#ifndef _LINUX_PMALLOC_H +#define _LINUX_PMALLOC_H + + +#include <linux/genalloc.h> +#include <linux/string.h> + +#define PMALLOC_DEFAULT_ALLOC_ORDER (-1) + +/* +* Library for dynamic allocation of pools of memory that can be, +* after initialization, marked as read-only. +* +* This is intended to complement __read_only_after_init, for those cases +* where either it is not possible to know the initialization value before +* init is completed, or the amount of data is variable and can be +* determined only at run-time. +* +* ***WARNING*** +* The user of the API is expected to synchronize: +* 1) allocation, +* 2) writes to the allocated memory, +* 3) write protection of the pool, +* 4) freeing of the allocated memory, and +* 5) destruction of the pool. +* +* For a non-threaded scenario, this type of locking is not even required. +* +* Even if the library were to provide support for locking, point 2) +* would still depend on the user taking the lock. +*/ + + +/** +* pmalloc_create_pool - create a new protectable memory pool +* @name: the name of the pool, enforced to be unique +* @min_alloc_order: log2 of the minimum allocation size obtainable +* from the pool +* +* Creates a new (empty) memory pool for allocation of protectable +* memory. Memory will be allocated upon request (through pmalloc). +* +* Return: pointer to the new pool upon success, otherwise a NULL. +*/
include/linux/pmalloc.h line 62
Quoted 10 lines
include/linux/pmalloc.h new file +10
-0+struct gen_pool *pmalloc_create_pool (const char *name, +int min_alloc_order); + +/** +* is_pmalloc_object - validates the existence of an alleged object +* @ptr: address of the object +* @n: size of the object, in bytes +* +* Return: 0 if the object does not belong to pmalloc, 1 if it belongs to +* pmalloc, -1 if it partially overlaps pmalloc meory, but incorectly.
typo: ^ memory
Quoted 710 lines
include/linux/pmalloc.h new file +160
-0+*/ +int is_pmalloc_object (const void *ptr,const unsigned long n); + +/** +* pmalloc_prealloc - tries to allocate a memory chunk of the requested size +* @pool: handle to the pool to be used for memory allocation +* @size: amount of memory (in bytes) requested +* +* Prepares a chunk of the requested size. +* This is intended to both minimize latency in later memory requests and +* avoid sleeping during allocation. +* Memory allocated with prealloc is stored in one single chunk, as +* opposed to what is allocated on-demand when pmalloc runs out of free +* space already existing in the pool and has to invoke vmalloc. +* One additional advantage of pre-allocating larger chunks of memory is +* that the total slack tends to be smaller. +* +* Return: true if the vmalloc call was successful, false otherwise. +*/ +bool pmalloc_prealloc (struct gen_pool *pool,size_t size); + +/** +* pmalloc - allocate protectable memory from a pool +* @pool: handle to the pool to be used for memory allocation +* @size: amount of memory (in bytes) requested +* @gfp: flags for page allocation +* +* Allocates memory from an unprotected pool. If the pool doesn't have +* enough memory, and the request did not include GFP_ATOMIC, an attempt +* is made to add a new chunk of memory to the pool +* (a multiple of PAGE_SIZE), in order to fit the new request. +* Otherwise, NULL is returned. +* +* Return: pointer to the memory requested upon success, NULL otherwise +* (either no memory available or pool already read-only). +*/ +void *pmalloc (struct gen_pool *pool,size_t size,gfp_t gfp); + + +/** +* pzalloc - zero-initialized version of pmalloc +* @pool: handle to the pool to be used for memory allocation +* @size: amount of memory (in bytes) requested +* @gfp: flags for page allocation +* +* Executes pmalloc, initializing the memory requested to 0, +* before returning the pointer to it. +* +* Return: pointer to the zeroed memory requested, upon success, NULL +* otherwise (either no memory available or pool already read-only). +*/ +static inline void *pzalloc (struct gen_pool *pool,size_t size,gfp_t gfp) +{ +return pmalloc (pool, size, gfp | __GFP_ZERO); +} + +/** +* pmalloc_array - allocates an array according to the parameters +* @pool: handle to the pool to be used for memory allocation +* @n: number of elements in the array +* @size: amount of memory (in bytes) requested for each element +* @flags: flags for page allocation +* +* Executes pmalloc, if it has a chance to succeed. +* +* Return: either NULL or the pmalloc result. +*/ +static inline void *pmalloc_array (struct gen_pool *pool,size_t n, +size_t size,gfp_t flags) +{ +if (unlikely (!(pool && n && size))) +return NULL ; +return pmalloc (pool, n * size, flags); +} + +/** +* pcalloc - allocates a 0-initialized array according to the parameters +* @pool: handle to the pool to be used for memory allocation +* @n: number of elements in the array +* @size: amount of memory (in bytes) requested +* @flags: flags for page allocation +* +* Executes pmalloc_array, if it has a chance to succeed. +* +* Return: either NULL or the pmalloc result. +*/ +static inline void *pcalloc (struct gen_pool *pool,size_t n, +size_t size,gfp_t flags) +{ +return pmalloc_array (pool, n, size, flags | __GFP_ZERO); +} + +/** +* pstrdup - duplicate a string, using pmalloc as allocator +* @pool: handle to the pool to be used for memory allocation +* @s: string to duplicate +* @gfp: flags for page allocation +* +* Generates a copy of the given string, allocating sufficient memory +* from the given pmalloc pool. +* +* Return: pointer to the replica, NULL in case of error. +*/ +static inline char *pstrdup (struct gen_pool *pool,const char *s,gfp_t gfp) +{ +size_t len; +char *buf; + +if (unlikely (pool ==NULL || s ==NULL )) +return NULL ; + + len =strlen (s) +1 ; + buf =pmalloc (pool, len, gfp); +if (likely (buf)) +strncpy (buf, s, len); +return buf; +} + +/** +* pmalloc_protect_pool - turn a read/write pool read-only +* @pool: the pool to protect +* +* Write-protects all the memory chunks assigned to the pool. +* This prevents any further allocation. +* +* Return: 0 upon success, -EINVAL in abnormal cases. +*/ +int pmalloc_protect_pool (struct gen_pool *pool); + +/** +* pfree - mark as unused memory that was previously in use +* @pool: handle to the pool to be used for memory allocation +* @addr: the beginning of the memory area to be freed +* +* The behavior of pfree is different, depending on the state of the +* protection. +* If the pool is not yet protected, the memory is marked as unused and +* will be available for further allocations. +* If the pool is already protected, the memory is marked as unused, but +* it will still be impossible to perform further allocation, because of +* the existing protection. +* The freed memory, in this case, will be truly released only when the +* pool is destroyed. +*/ +static inline void pfree (struct gen_pool *pool,const void *addr) +{ +gen_pool_free (pool, (unsigned long )addr,0 ); +} + +/** +* pmalloc_destroy_pool - destroys a pool and all the associated memory +* @pool: the pool to destroy +* +* All the memory that was allocated through pmalloc in the pool will be freed. +* +* Returns 0 upon success, -EINVAL in abnormal cases. +*/ +int pmalloc_destroy_pool (struct gen_pool *pool); + +#endif include/linux/vmalloc.h +1
-0@@ -20,6 +20,7 @@ struct notifier_block; /* in notifier.h */#define VM_UNINITIALIZED 0x00000020/* vm_struct is not fully initialized */ #define VM_NO_GUARD 0x00000040/* don't add guard page */ #define VM_KASAN 0x00000080/* has allocated kasan shadow memory */ +#define VM_PMALLOC 0x00000100/* pmalloc area - see docs */ /* bits [20..32] reserved for arch specific ioremap internals */ /* lib/genalloc.c +27
-0@@ -598,6 +598,33 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) }EXPORT_SYMBOL (gen_pool_free); + +/** +* gen_pool_flush_chunk - drops all the allocations from a specific chunk +* @pool: the generic memory pool +* @chunk: The chunk to wipe clear. +* +* This is meant to be called only while destroying a pool. It's up to the +* caller to avoid races, but really, at this point the pool should have +* already been retired and have become unavailable for any other sort of +* operation. +*/ +void gen_pool_flush_chunk (struct gen_pool *pool, +struct gen_pool_chunk *chunk) +{ +size_t size; + +if (unlikely (!(pool && chunk))) +return ; + + size = chunk->end_addr +1 - chunk->start_addr; +memset (chunk->entries,0 , +DIV_ROUND_UP (size >> pool->min_alloc_order *BITS_PER_ENTRY , +BITS_PER_BYTE )); +atomic_long_set (&chunk->avail, size); +} + +/** * gen_pool_for_each_chunk - call func for every chunk of generic memory pool * @pool: the generic memory pool mm/Kconfig +6
-0@@ -760,3 +760,9 @@ config GUP_BENCHMARK performance of get_user_pages_fast(). See tools/testing/selftests/vm/gup_benchmark.c + +config PROTECTABLE_MEMORY + bool + depends on ARCH_HAS_SET_MEMORY + select GENERIC_ALLOCATOR + default ymm/Makefile +1
-0@@ -65,6 +65,7 @@ obj-$(CONFIG_SPARSEMEM) += sparse.o obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o obj-$(CONFIG_SLOB) += slob.o obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o +obj-$(CONFIG_PROTECTABLE_MEMORY) += pmalloc.o obj-$(CONFIG_KSM) += ksm.o obj-$(CONFIG_PAGE_POISONING) += page_poison.o obj-$(CONFIG_SLAB) += slab.omm/pmalloc.c new file +468
-0@@ -0,0 +1,497 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* pmalloc.c: Protectable Memory Allocator +* +* (C) Copyright 2017 Huawei Technologies Co. Ltd. +* Author: Igor Stoppa <[email protected]> +*/ + +#include <linux/printk.h> +#include <linux/init.h> +#include <linux/mm.h> +#include <linux/vmalloc.h> +#include <linux/genalloc.h> +#include <linux/kernel.h> +#include <linux/log2.h> +#include <linux/slab.h> +#include <linux/device.h> +#include <linux/atomic.h> +#include <linux/rculist.h> +#include <linux/set_memory.h> +#include <asm/cacheflush.h> +#include <asm/page.h> + +#include <linux/pmalloc.h> +/* +* pmalloc_data contains the data specific to a pmalloc pool, +* in a format compatible with the design of gen_alloc. +* Some of the fields are used for exposing the corresponding parameter +* to userspace, through sysfs. +*/ +struct pmalloc_data { +struct gen_pool *pool;/* Link back to the associated pool. */ +bool protected;/* Status of the pool: RO or RW. */ +struct kobj_attribute attr_protected;/* Sysfs attribute. */ +struct kobj_attribute attr_avail;/* Sysfs attribute. */ +struct kobj_attribute attr_size;/* Sysfs attribute. */ +struct kobj_attribute attr_chunks;/* Sysfs attribute. */ +struct kobject *pool_kobject; +struct list_head node;/* list of pools */ +}; + +static LIST_HEAD (pmalloc_final_list); +static LIST_HEAD (pmalloc_tmp_list); +static struct list_head *pmalloc_list = &pmalloc_tmp_list; +static DEFINE_MUTEX (pmalloc_mutex); +static struct kobject *pmalloc_kobject; + +static ssize_t pmalloc_pool_show_protected (struct kobject *dev, +struct kobj_attribute *attr, +char *buf) +{ +struct pmalloc_data *data; + + data = container_of(attr, struct pmalloc_data, attr_protected); +if (data->protected) +return sprintf (buf,"protected\n" ); +else +return sprintf (buf,"unprotected\n" ); +} + +static ssize_t pmalloc_pool_show_avail (struct kobject *dev, +struct kobj_attribute *attr, +char *buf) +{ +struct pmalloc_data *data; + + data = container_of(attr, struct pmalloc_data, attr_avail); +return sprintf (buf,"%lu\n" , + (unsigned long )gen_pool_avail (data->pool)); +} + +static ssize_t pmalloc_pool_show_size (struct kobject *dev, +struct kobj_attribute *attr, +char *buf) +{ +struct pmalloc_data *data; + + data = container_of(attr, struct pmalloc_data, attr_size); +return sprintf (buf,"%lu\n" , + (unsigned long )gen_pool_size (data->pool)); +} + +static void pool_chunk_number (struct gen_pool *pool, +struct gen_pool_chunk *chunk,void *data) +{ +unsigned long *counter = data; + + (*counter)++; +} + +static ssize_t pmalloc_pool_show_chunks (struct kobject *dev, +struct kobj_attribute *attr, +char *buf) +{ +struct pmalloc_data *data; +unsigned long chunks_num =0 ; + + data = container_of(attr, struct pmalloc_data, attr_chunks); +gen_pool_for_each_chunk (data->pool, pool_chunk_number, &chunks_num); +return sprintf (buf,"%lu\n" , chunks_num); +} + +/* Exposes the pool and its attributes through sysfs. */ +static struct kobject *pmalloc_connect (struct pmalloc_data *data) +{ +const struct attribute *attrs[] = { + &data->attr_protected.attr, + &data->attr_avail.attr, + &data->attr_size.attr, + &data->attr_chunks.attr, +NULL + }; +struct kobject *kobj; + + kobj =kobject_create_and_add (data->pool->name, pmalloc_kobject); +if (unlikely (!kobj)) +return NULL ; + +if (unlikely (sysfs_create_files (kobj, attrs) <0 )) { +kobject_put (kobj); + kobj =NULL ; + } +return kobj; +} + +/* Removes the pool and its attributes from sysfs. */ +static void pmalloc_disconnect (struct pmalloc_data *data, +struct kobject *kobj) +{ +const struct attribute *attrs[] = { + &data->attr_protected.attr, + &data->attr_avail.attr, + &data->attr_size.attr, + &data->attr_chunks.attr, +NULL + }; + +sysfs_remove_files (kobj, attrs); +kobject_put (kobj); +} + +/* Declares an attribute of the pool. */ +#define pmalloc_attr_init (data, attr_name) \ +do { \ + sysfs_attr_init(&data->attr_##attr_name.attr); \ + data->attr_##attr_name.attr.name = #attr_name; \ + data->attr_##attr_name.attr.mode = VERIFY_OCTAL_PERMISSIONS(0400); \ + data->attr_##attr_name.show = pmalloc_pool_show_##attr_name; \ +} while (0) + +struct gen_pool *pmalloc_create_pool (const char *name,int min_alloc_order) +{ +struct gen_pool *pool; +const char *pool_name; +struct pmalloc_data *data; + +if (!name) { +WARN_ON (1 ); +return NULL ; + } + +if (min_alloc_order <0 ) + min_alloc_order =ilog2 (sizeof (unsigned long )); + + pool =gen_pool_create (min_alloc_order,NUMA_NO_NODE ); +if (unlikely (!pool)) +return NULL ; + +mutex_lock (&pmalloc_mutex); +list_for_each_entry (data, pmalloc_list, node) +if (!strcmp (name, data->pool->name)) + goto same_name_err; + + pool_name =kstrdup (name,GFP_KERNEL ); +if (unlikely (!pool_name)) + goto name_alloc_err; + + data =kzalloc (sizeof (struct pmalloc_data ),GFP_KERNEL ); +if (unlikely (!data)) + goto data_alloc_err; + + data->protected = false; + data->pool = pool; +pmalloc_attr_init (data, protected); +pmalloc_attr_init (data, avail); +pmalloc_attr_init (data, size); +pmalloc_attr_init (data, chunks); + pool->data = data; + pool->name = pool_name; + +list_add (&data->node, pmalloc_list); +if (pmalloc_list == &pmalloc_final_list) + data->pool_kobject =pmalloc_connect (data); +mutex_unlock (&pmalloc_mutex); +return pool; + +data_alloc_err: +kfree (pool_name); +name_alloc_err: +same_name_err: +mutex_unlock (&pmalloc_mutex); +gen_pool_destroy (pool); +return NULL ; +} + +static inline int check_alloc_params (struct gen_pool *pool,size_t req_size) +{ +struct pmalloc_data *data; + +if (unlikely (!req_size || !pool)) +return -1 ; + + data = pool->data; + +if (data ==NULL ) +return -1 ; + +if (unlikely (data->protected)) { +WARN_ON (1 ); +return -1 ; + } +return 0 ; +} + + +static inline bool chunk_tagging (void *chunk,bool tag) +{ +struct vm_struct *area; +struct page *page; + +if (!is_vmalloc_addr (chunk)) +return false; + + page =vmalloc_to_page (chunk); +if (unlikely (!page)) +return false; + + area = page->area; +if (tag) + area->flags |=VM_PMALLOC ; +else + area->flags &= ~VM_PMALLOC ; +return true; +} + + +static inline bool tag_chunk (void *chunk) +{ +return chunk_tagging (chunk, true); +} + + +static inline bool untag_chunk (void *chunk) +{ +return chunk_tagging (chunk, false); +} + +enum { +INVALID_PMALLOC_OBJECT =-1 , +NOT_PMALLOC_OBJECT =0 , +VALID_PMALLOC_OBJECT =1 , +}; + +int is_pmalloc_object (const void *ptr,const unsigned long n) +{ +struct vm_struct *area; +struct page *page; +unsigned long area_start; +unsigned long area_end; +unsigned long object_start; +unsigned long object_end; + + +/* is_pmalloc_object gets called pretty late, so chances are high +* that the object is indeed of vmalloc type +*/ +if (unlikely (!is_vmalloc_addr (ptr))) +return NOT_PMALLOC_OBJECT ; + + page =vmalloc_to_page (ptr); +if (unlikely (!page)) +return NOT_PMALLOC_OBJECT ; + + area = page->area; + +if (likely (!(area->flags &VM_PMALLOC ))) +return NOT_PMALLOC_OBJECT ; + + area_start = (unsigned long )area->addr; + area_end = area_start + area->nr_pages *PAGE_SIZE -1 ; + object_start = (unsigned long )ptr; + object_end = object_start + n -1 ; + +if (likely ((area_start <= object_start) && + (object_end <= area_end))) +return VALID_PMALLOC_OBJECT ; +else +return INVALID_PMALLOC_OBJECT ; +} + + +bool pmalloc_prealloc (struct gen_pool *pool,size_t size) +{ +void *chunk; +size_t chunk_size; +bool add_error; + +if (check_alloc_params (pool, size)) +return false; + +/* Expand pool */ + chunk_size =roundup (size,PAGE_SIZE ); + chunk =vmalloc (chunk_size); +if (unlikely (chunk ==NULL )) +return false; + +/* Locking is already done inside gen_pool_add */ + add_error =gen_pool_add (pool, (unsigned long )chunk, chunk_size, +NUMA_NO_NODE ); +if (unlikely (add_error !=0 )) + goto abort; + +return true; +abort: +vfree_atomic (chunk); +return false; + +} + +void *pmalloc (struct gen_pool *pool,size_t size,gfp_t gfp) +{ +void *chunk; +size_t chunk_size; +bool add_error; +unsigned long retval; + +if (check_alloc_params (pool, size)) +return NULL ; + +retry_alloc_from_pool: + retval =gen_pool_alloc (pool, size); +if (retval) + goto return_allocation; + +if (unlikely ((gfp & __GFP_ATOMIC))) { +if (unlikely ((gfp & __GFP_NOFAIL))) + goto retry_alloc_from_pool; +else +return NULL ; + } + +/* Expand pool */ + chunk_size =roundup (size,PAGE_SIZE ); + chunk =vmalloc (chunk_size); +if (unlikely (!chunk)) { +if (unlikely ((gfp & __GFP_NOFAIL))) + goto retry_alloc_from_pool; +else +return NULL ; + } +if (unlikely (!tag_chunk (chunk))) + goto free; + +/* Locking is already done inside gen_pool_add */ + add_error =gen_pool_add (pool, (unsigned long )chunk, chunk_size, +NUMA_NO_NODE ); +if (unlikely (add_error)) + goto abort; + + retval =gen_pool_alloc (pool, size); +if (retval) { +return_allocation: + *(size_t *)retval = size; +if (gfp & __GFP_ZERO) +memset ((void *)retval,0 , size); +return (void *)retval; + } +/* Here there is no test for __GFP_NO_FAIL because, in case of +* concurrent allocation, one thread might add a chunk to the +* pool and this memory could be allocated by another thread, +* before the first thread gets a chance to use it. +* As long as vmalloc succeeds, it's ok to retry. +*/ + goto retry_alloc_from_pool; +abort: +untag_chunk (chunk); +free: +vfree_atomic (chunk); +return NULL ; +} + +static void pmalloc_chunk_set_protection (struct gen_pool *pool, + +struct gen_pool_chunk *chunk, +void *data) +{ +const bool *flag = data; +size_t chunk_size = chunk->end_addr +1 - chunk->start_addr; +unsigned long pages = chunk_size /PAGE_SIZE ; + +BUG_ON (chunk_size & (PAGE_SIZE -1 )); + +if (*flag) +set_memory_ro (chunk->start_addr, pages); +else +set_memory_rw (chunk->start_addr, pages); +} + +static int pmalloc_pool_set_protection (struct gen_pool *pool,bool protection) +{ +struct pmalloc_data *data; +struct gen_pool_chunk *chunk; + +if (unlikely (!pool)) +return -EINVAL ; + + data = pool->data; + +if (unlikely (!data)) +return -EINVAL ; + +if (unlikely (data->protected == protection)) { +WARN_ON (1 ); +return 0 ; + } + + data->protected = protection; +list_for_each_entry (chunk, &(pool)->chunks, next_chunk) +pmalloc_chunk_set_protection (pool, chunk, &protection); +return 0 ; +} + +int pmalloc_protect_pool (struct gen_pool *pool) +{ +return pmalloc_pool_set_protection (pool, true); +} + + +static void pmalloc_chunk_free (struct gen_pool *pool, +struct gen_pool_chunk *chunk,void *data) +{ +untag_chunk (chunk); +gen_pool_flush_chunk (pool, chunk); +vfree_atomic ((void *)chunk->start_addr); +} + + +int pmalloc_destroy_pool (struct gen_pool *pool) +{ +struct pmalloc_data *data; + +if (unlikely (pool ==NULL )) +return -EINVAL ; + + data = pool->data; + +if (unlikely (data ==NULL )) +return -EINVAL ; + +mutex_lock (&pmalloc_mutex); +list_del (&data->node); +mutex_unlock (&pmalloc_mutex); + +if (likely (data->pool_kobject)) +pmalloc_disconnect (data, data->pool_kobject); + +pmalloc_pool_set_protection (pool, false); +gen_pool_for_each_chunk (pool, pmalloc_chunk_free,NULL );
mm/pmalloc.c line 478
Quoted 10 lines
mm/pmalloc.c new file +10
-0+gen_pool_destroy (pool); +kfree (data); +return 0 ; +} + +/** +* When the sysfs is ready to receive registrations, connect all the +* pools previously created. Also enable further pools to be connected +* right away. +*/
This does not seem as kernel-doc comment. Please either remove the second * from the opening comment mark or reformat the comment.
Quoted 78 lines
mm/pmalloc.c new file +19
-0+static int __init pmalloc_late_init (void ) +{ +struct pmalloc_data *data, *n; + + pmalloc_kobject =kobject_create_and_add ("pmalloc" , kernel_kobj); + +mutex_lock (&pmalloc_mutex); + pmalloc_list = &pmalloc_final_list; + +if (likely (pmalloc_kobject !=NULL )) { +list_for_each_entry_safe (data, n, &pmalloc_tmp_list, node) { +list_move (&data->node, &pmalloc_final_list); +pmalloc_connect (data); + } + } +mutex_unlock (&pmalloc_mutex); +return 0 ; +} +late_initcall (pmalloc_late_init);mm/usercopy.c +33
-0@@ -240,6 +240,36 @@ static inline void check_heap_object(const void *ptr, unsigned long n, } } +#ifdef CONFIG_PROTECTABLE_MEMORY + +int is_pmalloc_object (const void *ptr,const unsigned long n); + +static void check_pmalloc_object (const void *ptr,unsigned long n, +bool to_user) +{ +int retv; + + retv =is_pmalloc_object (ptr, n); +if (unlikely (retv)) { +if (unlikely (!to_user)) +usercopy_abort ("pmalloc" , +"trying to write to pmalloc object" , + to_user, (const unsigned long )ptr, n); +if (retv <0 ) +usercopy_abort ("pmalloc" , +"invalid pmalloc object" , + to_user, (const unsigned long )ptr, n); + } +} + +#else + +static void check_pmalloc_object (const void *ptr,unsigned long n, +bool to_user) +{ +} +#endif +/* * Validates that the given object is: * - not bogus address @@ -277,5 +307,8 @@ void __check_object_size(const void *ptr, unsigned long n, bool to_user)/* Check for object in kernel to avoid text exposure. */ check_kernel_text_object ((const unsigned long )ptr, n, to_user); + +/* Check if object is from a pmalloc chunk. */ +check_pmalloc_object (ptr, n, to_user); }EXPORT_SYMBOL (__check_object_size);Signature · 7 lines
2.14.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 4/6] Protectable Memory
Quoted 6 lines · Mike Rapoport
Quoted 2 lines · Igor Stoppa
+ * Return: 0 if the object does not belong to pmalloc, 1 if it belongs to
+ * pmalloc, -1 if it partially overlaps pmalloc meory, but incorectly.typo: ^ memory
thanks :-(
[...]
Quoted 8 lines
Quoted 5 lines
+/**
+ * When the sysfs is ready to receive registrations, connect all the
+ * pools previously created. Also enable further pools to be connected
+ * right away.
+ */This does not seem as kernel-doc comment. Please either remove the second * from the opening comment mark or reformat the comment.
For this too, I thought I had caught them all, but I was wrong ...
I didn't find any mention of automated checking for comments. Is there such tool?
--
thanks, igor
Re: [PATCH 4/6] Protectable Memory
Quoted 18 lines · Igor Stoppa
Quoted 6 lines · Mike Rapoport
Quoted 2 lines · Igor Stoppa
+ * Return: 0 if the object does not belong to pmalloc, 1 if it belongs to
+ * pmalloc, -1 if it partially overlaps pmalloc meory, but incorectly.typo: ^ memory
thanks :-(
[...]
Quoted 6 lines
Quoted 5 lines
+/**
+ * When the sysfs is ready to receive registrations, connect all the
+ * pools previously created. Also enable further pools to be connected
+ * right away.
+ */
Quoted 7 lines
Quoted 2 lines
This does not seem as kernel-doc comment. Please either remove the second * from the opening comment mark or reformat the comment.
For this too, I thought I had caught them all, but I was wrong ...
I didn't find any mention of automated checking for comments. Is there such tool?
I don't know if there is a tool. I couldn't find anything in scripts, maybe somebody have such tool out of tree.
For now, I've added mm-api.rst that includes all mm .c files and run 'make htmldocs' which spits plenty of warnings and errors.
Quoted 3 lines
--
thanks, igor
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 4/6] Protectable Memory
Quoted 24 lines · Mike Rapoport
Quoted 23 lines · Igor Stoppa
Quoted 6 lines · Mike Rapoport
Quoted 2 lines · Igor Stoppa
+ * Return: 0 if the object does not belong to pmalloc, 1 if it belongs to
+ * pmalloc, -1 if it partially overlaps pmalloc meory, but incorectly.typo: ^ memory
thanks :-(
[...]
Quoted 8 lines
Quoted 5 lines
+/**
+ * When the sysfs is ready to receive registrations, connect all the
+ * pools previously created. Also enable further pools to be connected
+ * right away.
+ */This does not seem as kernel-doc comment. Please either remove the second * from the opening comment mark or reformat the comment.
For this too, I thought I had caught them all, but I was wrong ...
Quoted 8 lines
Quoted 2 lines
I didn't find any mention of automated checking for comments. Is there such tool?
I don't know if there is a tool. I couldn't find anything in scripts, maybe somebody have such tool out of tree.
For now, I've added
mm-api.rstthat includes all mm .c files and run 'make htmldocs' which spits plenty of warnings and errors.
Actually, you can run 'scripts/kernel-doc -v -none <filename>' to check comments starting with '/**'. I afraid it won't catch formatted blocks that start with '/*'
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 4/6] Protectable Memory
Quoted 1 line · Mike Rapoport
'
scripts/kernel-doc-v -none
That has a quite interesting behavior.
I run it on genalloc.c while I am in the process of adding the brackets to the function names in the kernel-doc description.
The brackets confuse the script and it fails to output the name of the function in the log:
lib/genalloc.c:123: info: Scanning doc for get_bitmap_entry lib/genalloc.c:139: info: Scanning doc for lib/genalloc.c:152: info: Scanning doc for lib/genalloc.c:164: info: Scanning doc for
The first function does not have the brackets.
The others do. So what should I do with the missing brackets? Add them, according to the kernel docs, or leave them out?
I'd lean toward adding them.
--
igor
Re: [PATCH 4/6] Protectable Memory
Quoted 20 lines · Igor Stoppa
Quoted 1 line · Mike Rapoport
'
scripts/kernel-doc-v -noneThat has a quite interesting behavior.
I run it on
genalloc.cwhile I am in the process of adding the brackets to the function names in the kernel-doc description.The brackets confuse the script and it fails to output the name of the function in the log:
lib/genalloc.c:123: info: Scanning doc forget_bitmap_entrylib/genalloc.c:139: info: Scanning doc forlib/genalloc.c:152: info: Scanning doc forlib/genalloc.c:164: info: Scanning doc for
Quoted 3 lines
The first function does not have the brackets.
The others do. So what should I do with the missing brackets? Add them, according to the kernel docs, or leave them out?
Seems that kernel-doc does not consider () as a valid match for the identifier :)
Can you please check with the below patch?
Quoted 4 lines
I'd lean toward adding them.
--
igor
Signature · 2 lines
Sincerely yours, Mike.
Quoted 1 line
From
35255bc2d7d2a63be4f78a7bf4eec83ab0dc4f3fMon Sep 17 00:00:00 2001
From: Mike Rapoport <[email protected]>
Date: Mon, 12 Feb 2018 17:19:04 +0200
Subject: [PATCH] scripts: kernel_doc: fixup reporting of function identifiers
When function description includes brackets after the function name as suggested by Documentation/doc-guide/kernel-doc, the kernel-doc script omits the function name from "Scanning doc for" report. Extending match for identifier name with optional brackets fixes this issue.
--- scripts/kernel-doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kernel-doc +1 -1
@@ -1873,7 +1873,7 @@ sub process_file($) { } elsif (/$doc_decl/o) { $identifier = $1; - if (/\s*([\w\s]+?)\s*-/) { + if (/\s*([\w\s]+?)(\(\))?\s*-/) { $identifier = $1; }
Signature · 1 line
2.7.4
Re: [PATCH 4/6] Protectable Memory
On 12/02/18 17:31, Mike Rapoport wrote:
[...]
Quoted 4 lines
Seems that kernel-doc does not consider () as a valid match for the identifier :)
Can you please check with the below patch?
yes, it works now, than you!
--
igor
PATCH v15 5/6 Pmalloc: self-test
In reply to Igor StoppaAdd basic self-test functionality for pmalloc.
--- mm/Kconfig | 9 ++++++++ mm/Makefile | 1 + mm/pmalloc-selftest.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ mm/pmalloc-selftest.h | 24 ++++++++++++++++++++ mm/pmalloc.c | 2 ++ 5 files changed, 99 insertions(+) create mode 100644 mm/pmalloc-selftest.c create mode 100644 mm/pmalloc-selftest.h
mm/Kconfig +9 -0
@@ -766,3 +766,12 @@ config PROTECTABLE_MEMORY depends on ARCH_HAS_SET_MEMORY select GENERIC_ALLOCATOR default y + +config PROTECTABLE_MEMORY_SELFTEST + bool "Run self test for pmalloc memory allocator" + depends on ARCH_HAS_SET_MEMORY + select PROTECTABLE_MEMORY + default n + help + Tries to verify that pmalloc works correctly and that the memory + is effectively protected.
mm/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o obj-$(CONFIG_SLOB) += slob.o obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o obj-$(CONFIG_PROTECTABLE_MEMORY) += pmalloc.o +obj-$(CONFIG_PROTECTABLE_MEMORY_SELFTEST) += pmalloc-selftest.o obj-$(CONFIG_KSM) += ksm.o obj-$(CONFIG_PAGE_POISONING) += page_poison.o obj-$(CONFIG_SLAB) += slab.o
mm/pmalloc-selftest.c new file +63 -0
63 lines not on this page · raw message
mm/pmalloc-selftest.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* pmalloc-selftest.h +* +* (C) Copyright 2018 Huawei Technologies Co. Ltd. +* Author: Igor Stoppa <[email protected]> +*/ + + +#ifndef __MM_PMALLOC_SELFTEST_H +#define __MM_PMALLOC_SELFTEST_H + + +#ifdef CONFIG_PROTECTABLE_MEMORY_SELFTEST + +void pmalloc_selftest (void ); + +#else + +static inline void pmalloc_selftest (void ){}; + +#endif + +#endif
mm/pmalloc.c +2 -0
@@ -22,6 +22,7 @@#include <asm/page.h> #include <linux/pmalloc.h> +#include "pmalloc-selftest.h" /* * pmalloc_data contains the data specific to a pmalloc pool, * in a format compatible with the design of gen_alloc.
@@ -492,6 +493,7 @@ static int __init pmalloc_late_init(void) } }mutex_unlock (&pmalloc_mutex); +pmalloc_selftest ();return 0 ; }late_initcall (pmalloc_late_init);
Signature · 1 line
2.14.1
kbuild test robot
build botRe: [PATCH 5/6] Pmalloc: self-test
Thank you for the patch! Yet something to improve:
Hi Igor,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc1 next-20180212]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Igor-Stoppa/genalloc-track-beginning-of-allocations/20180212-192839
config: arm-allnoconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All errors (new ones prefixed by >>):
mm/pmalloc.o: In function `pmalloc_prealloc':
>> pmalloc.c:(.text+0x268): undefined reference to `vfree_atomic'
mm/pmalloc.o: In function `pmalloc':
pmalloc.c:(.text+0x2ac): undefined reference to vfree_atomic' mm/pmalloc.o: In function pmalloc_chunk_free':
pmalloc.c:(.text+0x86): undefined reference to `vfree_atomic'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v15 6/6 Documentation for Pmalloc
In reply to Igor StoppaDetailed documentation about the protectable memory allocator.
--- Documentation/core-api/index.rst | 1 + Documentation/core-api/pmalloc.rst | 114 +++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 Documentation/core-api/pmalloc.rst
Documentation/core-api/index.rst +1 -0
@@ -25,6 +25,7 @@ Core utilities genalloc errseq printk-formats + pmalloc Interfaces for kernel debugging ===============================
Documentation/core-api/pmalloc.rst new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [PATCH 6/6] Documentation for Pmalloc
Documentation/core-api/pmalloc.rst line 1
Quoted 2 lines · Igor Stoppa
Documentation/core-api/pmalloc.rst new file +1
-0@@ -0,0 +1,114 @@ +SPDX-License-Identifier: CC-BY-SA-4.0
You need the '.. ' before the 'SPDX'. SeeDocumentation/process/license-rules.rst
Re: [PATCH 6/6] Documentation for Pmalloc
Quoted 6 lines · Matthew Wilcox
Documentation/core-api/pmalloc.rst line 1
Quoted 2 lines · Igor Stoppa
Documentation/core-api/pmalloc.rst new file +1
-0@@ -0,0 +1,114 @@ +SPDX-License-Identifier: CC-BY-SA-4.0You need the '.. ' before the 'SPDX'. See
Documentation/process/license-rules.rst
yes, sorry, I thought I had understood how it works, but clearly I hadn't :-(
--
igor