ACPI, APEI, GHES, printk support for recoverable error via NMI
Subsystems (4)
RFC 1/2 lib, Make gen_pool memory allocator lockless
In reply to Huang YingThis version of the gen_pool memory allocator supports lockless operation.
This makes it safe to use in NMI handlers and other special unblockable contexts that could otherwise deadlock on locks. This is implemented by using atomic operations and retries on any conflicts. The disadvantage is that there may be livelocks in extreme cases. For better scalability, one gen_pool allocator can be used for each CPU.
The lockless operation only works if there is enough memory available. If new memory is added to the pool a lock has to be still taken. So any user relying on locklessness has to ensure that sufficient memory is preallocated.
The basic atomic operation of this allocator is cmpxchg on long. On architectures that don't have NMI-safe cmpxchg implementation, the allocator can NOT be used in NMI handler. So code uses the allocator in NMI handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.
--- include/linux/bitmap.h | 1 include/linux/genalloc.h | 46 +++++++- lib/bitmap.c | 2 lib/genalloc.c | 254 ++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 248 insertions(+), 55 deletions(-)
include/linux/bitmap.h +1 -0
@@ -142,6 +142,7 @@ extern void bitmap_release_region(unsignextern int bitmap_allocate_region (unsigned long *bitmap,int pos,int order);extern void bitmap_copy_le (void *dst,const unsigned long *src,int nbits); +#define BITMAP_FIRST_WORD_MASK (start) (~0UL << ((start) % BITS_PER_LONG))#define BITMAP_LAST_WORD_MASK (nbits) \ ( \ ((nbits) % BITS_PER_LONG) ? \
include/linux/genalloc.h +40 -6
70 lines not on this page · raw message
lib/bitmap.c +0 -2
@@ -271,8 +271,6 @@ int __bitmap_weight(const unsigned long }EXPORT_SYMBOL (__bitmap_weight); -#define BITMAP_FIRST_WORD_MASK (start) (~0UL << ((start) % BITS_PER_LONG)) -void bitmap_set (unsigned long *map,int start,int nr) {unsigned long *p = map +BIT_WORD (start);
lib/genalloc.c +207 -47
328 lines not on this page · raw message
RFC 2/2 ACPI, APEI, GHES, printk support for recoverable error via NMI
In reply to Huang YingSome APEI GHES recoverable errors are reported via NMI, but printk is not safe in NMI context.
To solve the issue, a lock-less memory allocator is used to allocate memory in NMI handler, save the error record into the allocated memory, put the error record into a lock-less list. On the other hand, a irq_work is used to delay the operation from NMI context to IRQ context. The irq_work IRQ handler will remove nodes from lock-less list, printk the error record and do some further processing include recovery operation, then free the memory.
--- drivers/acpi/apei/Kconfig | 1 drivers/acpi/apei/ghes.c | 186 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 174 insertions(+), 13 deletions(-)
drivers/acpi/apei/Kconfig +1 -0
@@ -11,6 +11,7 @@ config ACPI_APEI_GHES tristate "APEI Generic Hardware Error Source" depends on ACPI_APEI && X86 select ACPI_HED + select GENERIC_ALLOCATOR help Generic Hardware Error Source provides a way to report platform hardware errors (such as that from chipset). It
drivers/acpi/apei/ghes.c +173 -13
319 lines not on this page · raw message
cover ACPI, APEI, GHES, printk support for recoverable error via NMI
This patchset is based on the lockless list patchset.
[RFC 1/2] lib, Make gen_pool memory allocator lockless
[RFC 2/2] ACPI, APEI, GHES, printk support for recoverable error via NMI
Luck, Tony
reviewerRE: [RFC 1/2] lib, Make gen_pool memory allocator lockless
In reply to Huang Ying+static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set) +{
+ unsigned long val, nval;
+
+ nval = *addr;
+ do {
+ val = nval;
+ if (val & mask_to_set)
+ return -EBUSY;
+ } while ((nval = cmpxchg(addr, val, val | mask_to_set)) != val);
+
+ return 0;
+}
Spin loops like this should have a call to cpu_relax(), shouldn't they?
-Tony
RE: [RFC 1/2] lib, Make gen_pool memory allocator lockless
Quoted 14 lines · Tony
lib/genalloc.c +13
-0+static int set_bits_ll (unsigned long *addr,unsigned long mask_to_set) +{ +unsigned long val, nval; + + nval = *addr; +do { + val = nval; +if (val & mask_to_set) +return -EBUSY ; + }while ((nval =cmpxchg (addr, val, val | mask_to_set)) != val); + +return 0 ; +}
Quoted 1 line
Spin loops like this should have a call to
cpu_relax(), shouldn't they?
Thanks! Sounds reasonable to me. Will change it.
Best Regards,
Huang Ying