diff options
| author | Chris Zankel <chris@zankel.net> | 2016-01-21 00:16:13 -0500 |
|---|---|---|
| committer | Chris Zankel <chris@zankel.net> | 2016-01-21 00:16:13 -0500 |
| commit | d1208404dd477c142680437137c9996b95bfd508 (patch) | |
| tree | 0cba53f59f487c0de2b1a0d9fb1b11ae27de96ec /lib | |
| parent | afaa7c542cc9c4d8a99ba252a8ea5e8bc7c897e2 (diff) | |
| parent | afd2ff9b7e1b367172f18ba7f693dfb62bdcb2dc (diff) | |
Merge tag 'v4.4'
Linux 4.4
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/842/842.h | 2 | ||||
| -rw-r--r-- | lib/842/842_compress.c | 13 | ||||
| -rw-r--r-- | lib/842/842_decompress.c | 17 | ||||
| -rw-r--r-- | lib/Kconfig.debug | 12 | ||||
| -rw-r--r-- | lib/Kconfig.kasan | 3 | ||||
| -rw-r--r-- | lib/Makefile | 4 | ||||
| -rw-r--r-- | lib/btree.c | 2 | ||||
| -rw-r--r-- | lib/devres.c | 2 | ||||
| -rw-r--r-- | lib/digsig.c | 7 | ||||
| -rw-r--r-- | lib/div64.c | 2 | ||||
| -rw-r--r-- | lib/dma-debug.c | 14 | ||||
| -rw-r--r-- | lib/dynamic_debug.c | 8 | ||||
| -rw-r--r-- | lib/halfmd4.c | 3 | ||||
| -rw-r--r-- | lib/hexdump.c | 6 | ||||
| -rw-r--r-- | lib/idr.c | 4 | ||||
| -rw-r--r-- | lib/iommu-common.c | 10 | ||||
| -rw-r--r-- | lib/is_single_threaded.c | 5 | ||||
| -rw-r--r-- | lib/kasprintf.c | 16 | ||||
| -rw-r--r-- | lib/kobject.c | 42 | ||||
| -rw-r--r-- | lib/llist.c | 4 | ||||
| -rw-r--r-- | lib/mpi/longlong.h | 2 | ||||
| -rw-r--r-- | lib/mpi/mpicoder.c | 201 | ||||
| -rw-r--r-- | lib/nmi_backtrace.c | 11 | ||||
| -rw-r--r-- | lib/once.c | 62 | ||||
| -rw-r--r-- | lib/percpu_ida.c | 2 | ||||
| -rw-r--r-- | lib/proportions.c | 2 | ||||
| -rw-r--r-- | lib/radix-tree.c | 10 | ||||
| -rw-r--r-- | lib/random32.c | 37 | ||||
| -rw-r--r-- | lib/rhashtable.c | 70 | ||||
| -rw-r--r-- | lib/string.c | 2 | ||||
| -rw-r--r-- | lib/test-string_helpers.c | 36 | ||||
| -rw-r--r-- | lib/test_bpf.c | 30 | ||||
| -rw-r--r-- | lib/test_kasan.c | 69 | ||||
| -rw-r--r-- | lib/test_printf.c | 362 | ||||
| -rw-r--r-- | lib/vsprintf.c | 80 |
35 files changed, 1004 insertions, 148 deletions
diff --git a/lib/842/842.h b/lib/842/842.h index 7c200030acf7..e0a122bc1cdb 100644 --- a/lib/842/842.h +++ b/lib/842/842.h | |||
| @@ -76,6 +76,7 @@ | |||
| 76 | #include <linux/module.h> | 76 | #include <linux/module.h> |
| 77 | #include <linux/kernel.h> | 77 | #include <linux/kernel.h> |
| 78 | #include <linux/bitops.h> | 78 | #include <linux/bitops.h> |
| 79 | #include <linux/crc32.h> | ||
| 79 | #include <asm/unaligned.h> | 80 | #include <asm/unaligned.h> |
| 80 | 81 | ||
| 81 | #include <linux/sw842.h> | 82 | #include <linux/sw842.h> |
| @@ -98,6 +99,7 @@ | |||
| 98 | #define I2_BITS (8) | 99 | #define I2_BITS (8) |
| 99 | #define I4_BITS (9) | 100 | #define I4_BITS (9) |
| 100 | #define I8_BITS (8) | 101 | #define I8_BITS (8) |
| 102 | #define CRC_BITS (32) | ||
| 101 | 103 | ||
| 102 | #define REPEAT_BITS_MAX (0x3f) | 104 | #define REPEAT_BITS_MAX (0x3f) |
| 103 | #define SHORT_DATA_BITS_MAX (0x7) | 105 | #define SHORT_DATA_BITS_MAX (0x7) |
diff --git a/lib/842/842_compress.c b/lib/842/842_compress.c index 7ce68948e68c..4051339bdfbd 100644 --- a/lib/842/842_compress.c +++ b/lib/842/842_compress.c | |||
| @@ -490,6 +490,7 @@ int sw842_compress(const u8 *in, unsigned int ilen, | |||
| 490 | int ret; | 490 | int ret; |
| 491 | u64 last, next, pad, total; | 491 | u64 last, next, pad, total; |
| 492 | u8 repeat_count = 0; | 492 | u8 repeat_count = 0; |
| 493 | u32 crc; | ||
| 493 | 494 | ||
| 494 | BUILD_BUG_ON(sizeof(*p) > SW842_MEM_COMPRESS); | 495 | BUILD_BUG_ON(sizeof(*p) > SW842_MEM_COMPRESS); |
| 495 | 496 | ||
| @@ -580,6 +581,18 @@ skip_comp: | |||
| 580 | if (ret) | 581 | if (ret) |
| 581 | return ret; | 582 | return ret; |
| 582 | 583 | ||
| 584 | /* | ||
| 585 | * crc(0:31) is appended to target data starting with the next | ||
| 586 | * bit after End of stream template. | ||
| 587 | * nx842 calculates CRC for data in big-endian format. So doing | ||
| 588 | * same here so that sw842 decompression can be used for both | ||
| 589 | * compressed data. | ||
| 590 | */ | ||
| 591 | crc = crc32_be(0, in, ilen); | ||
| 592 | ret = add_bits(p, crc, CRC_BITS); | ||
| 593 | if (ret) | ||
| 594 | return ret; | ||
| 595 | |||
| 583 | if (p->bit) { | 596 | if (p->bit) { |
| 584 | p->out++; | 597 | p->out++; |
| 585 | p->olen--; | 598 | p->olen--; |
diff --git a/lib/842/842_decompress.c b/lib/842/842_decompress.c index 5446ff0c9ba0..8881dad2a6a0 100644 --- a/lib/842/842_decompress.c +++ b/lib/842/842_decompress.c | |||
| @@ -285,6 +285,7 @@ int sw842_decompress(const u8 *in, unsigned int ilen, | |||
| 285 | struct sw842_param p; | 285 | struct sw842_param p; |
| 286 | int ret; | 286 | int ret; |
| 287 | u64 op, rep, tmp, bytes, total; | 287 | u64 op, rep, tmp, bytes, total; |
| 288 | u64 crc; | ||
| 288 | 289 | ||
| 289 | p.in = (u8 *)in; | 290 | p.in = (u8 *)in; |
| 290 | p.bit = 0; | 291 | p.bit = 0; |
| @@ -375,6 +376,22 @@ int sw842_decompress(const u8 *in, unsigned int ilen, | |||
| 375 | } | 376 | } |
| 376 | } while (op != OP_END); | 377 | } while (op != OP_END); |
| 377 | 378 | ||
| 379 | /* | ||
| 380 | * crc(0:31) is saved in compressed data starting with the | ||
| 381 | * next bit after End of stream template. | ||
| 382 | */ | ||
| 383 | ret = next_bits(&p, &crc, CRC_BITS); | ||
| 384 | if (ret) | ||
| 385 | return ret; | ||
| 386 | |||
| 387 | /* | ||
| 388 | * Validate CRC saved in compressed data. | ||
| 389 | */ | ||
| 390 | if (crc != (u64)crc32_be(0, out, total - p.olen)) { | ||
| 391 | pr_debug("CRC mismatch for decompression\n"); | ||
| 392 | return -EINVAL; | ||
| 393 | } | ||
| 394 | |||
| 378 | if (unlikely((total - p.olen) > UINT_MAX)) | 395 | if (unlikely((total - p.olen) > UINT_MAX)) |
| 379 | return -ENOSPC; | 396 | return -ENOSPC; |
| 380 | 397 | ||
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1d1521c26302..8c15b29d5adc 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -312,6 +312,15 @@ config DEBUG_SECTION_MISMATCH | |||
| 312 | - Enable verbose reporting from modpost in order to help resolve | 312 | - Enable verbose reporting from modpost in order to help resolve |
| 313 | the section mismatches that are reported. | 313 | the section mismatches that are reported. |
| 314 | 314 | ||
| 315 | config SECTION_MISMATCH_WARN_ONLY | ||
| 316 | bool "Make section mismatch errors non-fatal" | ||
| 317 | default y | ||
| 318 | help | ||
| 319 | If you say N here, the build process will fail if there are any | ||
| 320 | section mismatch, instead of just throwing warnings. | ||
| 321 | |||
| 322 | If unsure, say Y. | ||
| 323 | |||
| 315 | # | 324 | # |
| 316 | # Select this config option from the architecture Kconfig, if it | 325 | # Select this config option from the architecture Kconfig, if it |
| 317 | # is preferred to always offer frame pointers as a config | 326 | # is preferred to always offer frame pointers as a config |
| @@ -1686,6 +1695,9 @@ config TEST_STRING_HELPERS | |||
| 1686 | config TEST_KSTRTOX | 1695 | config TEST_KSTRTOX |
| 1687 | tristate "Test kstrto*() family of functions at runtime" | 1696 | tristate "Test kstrto*() family of functions at runtime" |
| 1688 | 1697 | ||
| 1698 | config TEST_PRINTF | ||
| 1699 | tristate "Test printf() family of functions at runtime" | ||
| 1700 | |||
| 1689 | config TEST_RHASHTABLE | 1701 | config TEST_RHASHTABLE |
| 1690 | tristate "Perform selftest on resizable hash table" | 1702 | tristate "Perform selftest on resizable hash table" |
| 1691 | default n | 1703 | default n |
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 39f24d6721e5..0fee5acd5aa0 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan | |||
| @@ -15,8 +15,7 @@ config KASAN | |||
| 15 | global variables requires gcc 5.0 or later. | 15 | global variables requires gcc 5.0 or later. |
| 16 | This feature consumes about 1/8 of available memory and brings about | 16 | This feature consumes about 1/8 of available memory and brings about |
| 17 | ~x3 performance slowdown. | 17 | ~x3 performance slowdown. |
| 18 | For better error detection enable CONFIG_STACKTRACE, | 18 | For better error detection enable CONFIG_STACKTRACE. |
| 19 | and add slub_debug=U to boot cmdline. | ||
| 20 | 19 | ||
| 21 | choice | 20 | choice |
| 22 | prompt "Instrumentation type" | 21 | prompt "Instrumentation type" |
diff --git a/lib/Makefile b/lib/Makefile index 13a7c6ae3fec..7f1de26613d2 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -26,7 +26,8 @@ obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | |||
| 26 | bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ | 26 | bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ |
| 27 | gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ | 27 | gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ |
| 28 | bsearch.o find_bit.o llist.o memweight.o kfifo.o \ | 28 | bsearch.o find_bit.o llist.o memweight.o kfifo.o \ |
| 29 | percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o | 29 | percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o \ |
| 30 | once.o | ||
| 30 | obj-y += string_helpers.o | 31 | obj-y += string_helpers.o |
| 31 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o | 32 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o |
| 32 | obj-y += hexdump.o | 33 | obj-y += hexdump.o |
| @@ -41,6 +42,7 @@ obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o | |||
| 41 | obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o | 42 | obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o |
| 42 | obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o | 43 | obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o |
| 43 | obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o | 44 | obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o |
| 45 | obj-$(CONFIG_TEST_PRINTF) += test_printf.o | ||
| 44 | 46 | ||
| 45 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 47 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
| 46 | CFLAGS_kobject.o += -DDEBUG | 48 | CFLAGS_kobject.o += -DDEBUG |
diff --git a/lib/btree.c b/lib/btree.c index 4264871ea1a0..f93a945274af 100644 --- a/lib/btree.c +++ b/lib/btree.c | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | * | 5 | * |
| 6 | * Copyright (c) 2007-2008 Joern Engel <joern@logfs.org> | 6 | * Copyright (c) 2007-2008 Joern Engel <joern@logfs.org> |
| 7 | * Bits and pieces stolen from Peter Zijlstra's code, which is | 7 | * Bits and pieces stolen from Peter Zijlstra's code, which is |
| 8 | * Copyright 2007, Red Hat Inc. Peter Zijlstra <pzijlstr@redhat.com> | 8 | * Copyright 2007, Red Hat Inc. Peter Zijlstra |
| 9 | * GPLv2 | 9 | * GPLv2 |
| 10 | * | 10 | * |
| 11 | * see http://programming.kicks-ass.net/kernel-patches/vma_lookup/btree.patch | 11 | * see http://programming.kicks-ass.net/kernel-patches/vma_lookup/btree.patch |
diff --git a/lib/devres.c b/lib/devres.c index f13a2468ff39..8c85672639d3 100644 --- a/lib/devres.c +++ b/lib/devres.c | |||
| @@ -418,7 +418,7 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) | |||
| 418 | if (!iomap) | 418 | if (!iomap) |
| 419 | return; | 419 | return; |
| 420 | 420 | ||
| 421 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { | 421 | for (i = 0; i < PCIM_IOMAP_MAX; i++) { |
| 422 | if (!(mask & (1 << i))) | 422 | if (!(mask & (1 << i))) |
| 423 | continue; | 423 | continue; |
| 424 | 424 | ||
diff --git a/lib/digsig.c b/lib/digsig.c index ae05ea393fc8..07be6c1ef4e2 100644 --- a/lib/digsig.c +++ b/lib/digsig.c | |||
| @@ -79,12 +79,13 @@ static int digsig_verify_rsa(struct key *key, | |||
| 79 | unsigned char *out1 = NULL; | 79 | unsigned char *out1 = NULL; |
| 80 | const char *m; | 80 | const char *m; |
| 81 | MPI in = NULL, res = NULL, pkey[2]; | 81 | MPI in = NULL, res = NULL, pkey[2]; |
| 82 | uint8_t *p, *datap, *endp; | 82 | uint8_t *p, *datap; |
| 83 | struct user_key_payload *ukp; | 83 | const uint8_t *endp; |
| 84 | const struct user_key_payload *ukp; | ||
| 84 | struct pubkey_hdr *pkh; | 85 | struct pubkey_hdr *pkh; |
| 85 | 86 | ||
| 86 | down_read(&key->sem); | 87 | down_read(&key->sem); |
| 87 | ukp = key->payload.data; | 88 | ukp = user_key_payload(key); |
| 88 | 89 | ||
| 89 | if (ukp->datalen < sizeof(*pkh)) | 90 | if (ukp->datalen < sizeof(*pkh)) |
| 90 | goto err1; | 91 | goto err1; |
diff --git a/lib/div64.c b/lib/div64.c index 19ea7ed4b948..62a698a432bc 100644 --- a/lib/div64.c +++ b/lib/div64.c | |||
| @@ -162,7 +162,7 @@ s64 div64_s64(s64 dividend, s64 divisor) | |||
| 162 | { | 162 | { |
| 163 | s64 quot, t; | 163 | s64 quot, t; |
| 164 | 164 | ||
| 165 | quot = div64_u64(abs64(dividend), abs64(divisor)); | 165 | quot = div64_u64(abs(dividend), abs(divisor)); |
| 166 | t = (dividend ^ divisor) >> 63; | 166 | t = (dividend ^ divisor) >> 63; |
| 167 | 167 | ||
| 168 | return (quot ^ t) - t; | 168 | return (quot ^ t) - t; |
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index dace71fe41f7..d34bd24c2c84 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
| @@ -100,7 +100,7 @@ static LIST_HEAD(free_entries); | |||
| 100 | static DEFINE_SPINLOCK(free_entries_lock); | 100 | static DEFINE_SPINLOCK(free_entries_lock); |
| 101 | 101 | ||
| 102 | /* Global disable flag - will be set in case of an error */ | 102 | /* Global disable flag - will be set in case of an error */ |
| 103 | static u32 global_disable __read_mostly; | 103 | static bool global_disable __read_mostly; |
| 104 | 104 | ||
| 105 | /* Early initialization disable flag, set at the end of dma_debug_init */ | 105 | /* Early initialization disable flag, set at the end of dma_debug_init */ |
| 106 | static bool dma_debug_initialized __read_mostly; | 106 | static bool dma_debug_initialized __read_mostly; |
| @@ -1249,6 +1249,14 @@ static void check_sync(struct device *dev, | |||
| 1249 | dir2name[entry->direction], | 1249 | dir2name[entry->direction], |
| 1250 | dir2name[ref->direction]); | 1250 | dir2name[ref->direction]); |
| 1251 | 1251 | ||
| 1252 | if (ref->sg_call_ents && ref->type == dma_debug_sg && | ||
| 1253 | ref->sg_call_ents != entry->sg_call_ents) { | ||
| 1254 | err_printk(ref->dev, entry, "DMA-API: device driver syncs " | ||
| 1255 | "DMA sg list with different entry count " | ||
| 1256 | "[map count=%d] [sync count=%d]\n", | ||
| 1257 | entry->sg_call_ents, ref->sg_call_ents); | ||
| 1258 | } | ||
| 1259 | |||
| 1252 | out: | 1260 | out: |
| 1253 | put_hash_bucket(bucket, &flags); | 1261 | put_hash_bucket(bucket, &flags); |
| 1254 | } | 1262 | } |
| @@ -1456,7 +1464,7 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size, | |||
| 1456 | entry->type = dma_debug_coherent; | 1464 | entry->type = dma_debug_coherent; |
| 1457 | entry->dev = dev; | 1465 | entry->dev = dev; |
| 1458 | entry->pfn = page_to_pfn(virt_to_page(virt)); | 1466 | entry->pfn = page_to_pfn(virt_to_page(virt)); |
| 1459 | entry->offset = (size_t) virt & PAGE_MASK; | 1467 | entry->offset = (size_t) virt & ~PAGE_MASK; |
| 1460 | entry->size = size; | 1468 | entry->size = size; |
| 1461 | entry->dev_addr = dma_addr; | 1469 | entry->dev_addr = dma_addr; |
| 1462 | entry->direction = DMA_BIDIRECTIONAL; | 1470 | entry->direction = DMA_BIDIRECTIONAL; |
| @@ -1472,7 +1480,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size, | |||
| 1472 | .type = dma_debug_coherent, | 1480 | .type = dma_debug_coherent, |
| 1473 | .dev = dev, | 1481 | .dev = dev, |
| 1474 | .pfn = page_to_pfn(virt_to_page(virt)), | 1482 | .pfn = page_to_pfn(virt_to_page(virt)), |
| 1475 | .offset = (size_t) virt & PAGE_MASK, | 1483 | .offset = (size_t) virt & ~PAGE_MASK, |
| 1476 | .dev_addr = addr, | 1484 | .dev_addr = addr, |
| 1477 | .size = size, | 1485 | .size = size, |
| 1478 | .direction = DMA_BIDIRECTIONAL, | 1486 | .direction = DMA_BIDIRECTIONAL, |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index e491e02eff54..e3952e9c8ec0 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
| @@ -42,7 +42,7 @@ extern struct _ddebug __stop___verbose[]; | |||
| 42 | 42 | ||
| 43 | struct ddebug_table { | 43 | struct ddebug_table { |
| 44 | struct list_head link; | 44 | struct list_head link; |
| 45 | char *mod_name; | 45 | const char *mod_name; |
| 46 | unsigned int num_ddebugs; | 46 | unsigned int num_ddebugs; |
| 47 | struct _ddebug *ddebugs; | 47 | struct _ddebug *ddebugs; |
| 48 | }; | 48 | }; |
| @@ -841,12 +841,12 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, | |||
| 841 | const char *name) | 841 | const char *name) |
| 842 | { | 842 | { |
| 843 | struct ddebug_table *dt; | 843 | struct ddebug_table *dt; |
| 844 | char *new_name; | 844 | const char *new_name; |
| 845 | 845 | ||
| 846 | dt = kzalloc(sizeof(*dt), GFP_KERNEL); | 846 | dt = kzalloc(sizeof(*dt), GFP_KERNEL); |
| 847 | if (dt == NULL) | 847 | if (dt == NULL) |
| 848 | return -ENOMEM; | 848 | return -ENOMEM; |
| 849 | new_name = kstrdup(name, GFP_KERNEL); | 849 | new_name = kstrdup_const(name, GFP_KERNEL); |
| 850 | if (new_name == NULL) { | 850 | if (new_name == NULL) { |
| 851 | kfree(dt); | 851 | kfree(dt); |
| 852 | return -ENOMEM; | 852 | return -ENOMEM; |
| @@ -907,7 +907,7 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module) | |||
| 907 | static void ddebug_table_free(struct ddebug_table *dt) | 907 | static void ddebug_table_free(struct ddebug_table *dt) |
| 908 | { | 908 | { |
| 909 | list_del_init(&dt->link); | 909 | list_del_init(&dt->link); |
| 910 | kfree(dt->mod_name); | 910 | kfree_const(dt->mod_name); |
| 911 | kfree(dt); | 911 | kfree(dt); |
| 912 | } | 912 | } |
| 913 | 913 | ||
diff --git a/lib/halfmd4.c b/lib/halfmd4.c index a8fe6274a13c..137e861d9690 100644 --- a/lib/halfmd4.c +++ b/lib/halfmd4.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <linux/compiler.h> | 1 | #include <linux/compiler.h> |
| 2 | #include <linux/export.h> | 2 | #include <linux/export.h> |
| 3 | #include <linux/cryptohash.h> | 3 | #include <linux/cryptohash.h> |
| 4 | #include <linux/bitops.h> | ||
| 4 | 5 | ||
| 5 | /* F, G and H are basic MD4 functions: selection, majority, parity */ | 6 | /* F, G and H are basic MD4 functions: selection, majority, parity */ |
| 6 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) | 7 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) |
| @@ -14,7 +15,7 @@ | |||
| 14 | * Rotation is separate from addition to prevent recomputation | 15 | * Rotation is separate from addition to prevent recomputation |
| 15 | */ | 16 | */ |
| 16 | #define ROUND(f, a, b, c, d, x, s) \ | 17 | #define ROUND(f, a, b, c, d, x, s) \ |
| 17 | (a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s))) | 18 | (a += f(b, c, d) + x, a = rol32(a, s)) |
| 18 | #define K1 0 | 19 | #define K1 0 |
| 19 | #define K2 013240474631UL | 20 | #define K2 013240474631UL |
| 20 | #define K3 015666365641UL | 21 | #define K3 015666365641UL |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 8d74c20d8595..992457b1284c 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
| @@ -169,11 +169,15 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, | |||
| 169 | } | 169 | } |
| 170 | } else { | 170 | } else { |
| 171 | for (j = 0; j < len; j++) { | 171 | for (j = 0; j < len; j++) { |
| 172 | if (linebuflen < lx + 3) | 172 | if (linebuflen < lx + 2) |
| 173 | goto overflow2; | 173 | goto overflow2; |
| 174 | ch = ptr[j]; | 174 | ch = ptr[j]; |
| 175 | linebuf[lx++] = hex_asc_hi(ch); | 175 | linebuf[lx++] = hex_asc_hi(ch); |
| 176 | if (linebuflen < lx + 2) | ||
| 177 | goto overflow2; | ||
| 176 | linebuf[lx++] = hex_asc_lo(ch); | 178 | linebuf[lx++] = hex_asc_lo(ch); |
| 179 | if (linebuflen < lx + 2) | ||
| 180 | goto overflow2; | ||
| 177 | linebuf[lx++] = ' '; | 181 | linebuf[lx++] = ' '; |
| 178 | } | 182 | } |
| 179 | if (j) | 183 | if (j) |
| @@ -399,7 +399,7 @@ void idr_preload(gfp_t gfp_mask) | |||
| 399 | * allocation guarantee. Disallow usage from those contexts. | 399 | * allocation guarantee. Disallow usage from those contexts. |
| 400 | */ | 400 | */ |
| 401 | WARN_ON_ONCE(in_interrupt()); | 401 | WARN_ON_ONCE(in_interrupt()); |
| 402 | might_sleep_if(gfp_mask & __GFP_WAIT); | 402 | might_sleep_if(gfpflags_allow_blocking(gfp_mask)); |
| 403 | 403 | ||
| 404 | preempt_disable(); | 404 | preempt_disable(); |
| 405 | 405 | ||
| @@ -453,7 +453,7 @@ int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask) | |||
| 453 | struct idr_layer *pa[MAX_IDR_LEVEL + 1]; | 453 | struct idr_layer *pa[MAX_IDR_LEVEL + 1]; |
| 454 | int id; | 454 | int id; |
| 455 | 455 | ||
| 456 | might_sleep_if(gfp_mask & __GFP_WAIT); | 456 | might_sleep_if(gfpflags_allow_blocking(gfp_mask)); |
| 457 | 457 | ||
| 458 | /* sanity checks */ | 458 | /* sanity checks */ |
| 459 | if (WARN_ON_ONCE(start < 0)) | 459 | if (WARN_ON_ONCE(start < 0)) |
diff --git a/lib/iommu-common.c b/lib/iommu-common.c index b1c93e94ca7a..858dc1aae478 100644 --- a/lib/iommu-common.c +++ b/lib/iommu-common.c | |||
| @@ -11,10 +11,6 @@ | |||
| 11 | #include <linux/dma-mapping.h> | 11 | #include <linux/dma-mapping.h> |
| 12 | #include <linux/hash.h> | 12 | #include <linux/hash.h> |
| 13 | 13 | ||
| 14 | #ifndef DMA_ERROR_CODE | ||
| 15 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) | ||
| 16 | #endif | ||
| 17 | |||
| 18 | static unsigned long iommu_large_alloc = 15; | 14 | static unsigned long iommu_large_alloc = 15; |
| 19 | 15 | ||
| 20 | static DEFINE_PER_CPU(unsigned int, iommu_hash_common); | 16 | static DEFINE_PER_CPU(unsigned int, iommu_hash_common); |
| @@ -123,7 +119,7 @@ unsigned long iommu_tbl_range_alloc(struct device *dev, | |||
| 123 | /* Sanity check */ | 119 | /* Sanity check */ |
| 124 | if (unlikely(npages == 0)) { | 120 | if (unlikely(npages == 0)) { |
| 125 | WARN_ON_ONCE(1); | 121 | WARN_ON_ONCE(1); |
| 126 | return DMA_ERROR_CODE; | 122 | return IOMMU_ERROR_CODE; |
| 127 | } | 123 | } |
| 128 | 124 | ||
| 129 | if (largealloc) { | 125 | if (largealloc) { |
| @@ -206,7 +202,7 @@ unsigned long iommu_tbl_range_alloc(struct device *dev, | |||
| 206 | goto again; | 202 | goto again; |
| 207 | } else { | 203 | } else { |
| 208 | /* give up */ | 204 | /* give up */ |
| 209 | n = DMA_ERROR_CODE; | 205 | n = IOMMU_ERROR_CODE; |
| 210 | goto bail; | 206 | goto bail; |
| 211 | } | 207 | } |
| 212 | } | 208 | } |
| @@ -259,7 +255,7 @@ void iommu_tbl_range_free(struct iommu_map_table *iommu, u64 dma_addr, | |||
| 259 | unsigned long flags; | 255 | unsigned long flags; |
| 260 | unsigned long shift = iommu->table_shift; | 256 | unsigned long shift = iommu->table_shift; |
| 261 | 257 | ||
| 262 | if (entry == DMA_ERROR_CODE) /* use default addr->entry mapping */ | 258 | if (entry == IOMMU_ERROR_CODE) /* use default addr->entry mapping */ |
| 263 | entry = (dma_addr - iommu->table_map_base) >> shift; | 259 | entry = (dma_addr - iommu->table_map_base) >> shift; |
| 264 | pool = get_pool(iommu, entry); | 260 | pool = get_pool(iommu, entry); |
| 265 | 261 | ||
diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c index bd2bea963364..391fd23976a2 100644 --- a/lib/is_single_threaded.c +++ b/lib/is_single_threaded.c | |||
| @@ -36,8 +36,7 @@ bool current_is_single_threaded(void) | |||
| 36 | if (unlikely(p == task->group_leader)) | 36 | if (unlikely(p == task->group_leader)) |
| 37 | continue; | 37 | continue; |
| 38 | 38 | ||
| 39 | t = p; | 39 | for_each_thread(p, t) { |
| 40 | do { | ||
| 41 | if (unlikely(t->mm == mm)) | 40 | if (unlikely(t->mm == mm)) |
| 42 | goto found; | 41 | goto found; |
| 43 | if (likely(t->mm)) | 42 | if (likely(t->mm)) |
| @@ -48,7 +47,7 @@ bool current_is_single_threaded(void) | |||
| 48 | * forked before exiting. | 47 | * forked before exiting. |
| 49 | */ | 48 | */ |
| 50 | smp_rmb(); | 49 | smp_rmb(); |
| 51 | } while_each_thread(p, t); | 50 | } |
| 52 | } | 51 | } |
| 53 | ret = true; | 52 | ret = true; |
| 54 | found: | 53 | found: |
diff --git a/lib/kasprintf.c b/lib/kasprintf.c index 32f12150fc4f..f194e6e593e1 100644 --- a/lib/kasprintf.c +++ b/lib/kasprintf.c | |||
| @@ -31,6 +31,22 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) | |||
| 31 | } | 31 | } |
| 32 | EXPORT_SYMBOL(kvasprintf); | 32 | EXPORT_SYMBOL(kvasprintf); |
| 33 | 33 | ||
| 34 | /* | ||
| 35 | * If fmt contains no % (or is exactly %s), use kstrdup_const. If fmt | ||
| 36 | * (or the sole vararg) points to rodata, we will then save a memory | ||
| 37 | * allocation and string copy. In any case, the return value should be | ||
| 38 | * freed using kfree_const(). | ||
| 39 | */ | ||
| 40 | const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list ap) | ||
| 41 | { | ||
| 42 | if (!strchr(fmt, '%')) | ||
| 43 | return kstrdup_const(fmt, gfp); | ||
| 44 | if (!strcmp(fmt, "%s")) | ||
| 45 | return kstrdup_const(va_arg(ap, const char*), gfp); | ||
| 46 | return kvasprintf(gfp, fmt, ap); | ||
| 47 | } | ||
| 48 | EXPORT_SYMBOL(kvasprintf_const); | ||
| 49 | |||
| 34 | char *kasprintf(gfp_t gfp, const char *fmt, ...) | 50 | char *kasprintf(gfp_t gfp, const char *fmt, ...) |
| 35 | { | 51 | { |
| 36 | va_list ap; | 52 | va_list ap; |
diff --git a/lib/kobject.c b/lib/kobject.c index 3e3a5c3cb330..7cbccd2b4c72 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
| @@ -257,18 +257,32 @@ static int kobject_add_internal(struct kobject *kobj) | |||
| 257 | int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, | 257 | int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, |
| 258 | va_list vargs) | 258 | va_list vargs) |
| 259 | { | 259 | { |
| 260 | char *s; | 260 | const char *s; |
| 261 | 261 | ||
| 262 | if (kobj->name && !fmt) | 262 | if (kobj->name && !fmt) |
| 263 | return 0; | 263 | return 0; |
| 264 | 264 | ||
| 265 | s = kvasprintf(GFP_KERNEL, fmt, vargs); | 265 | s = kvasprintf_const(GFP_KERNEL, fmt, vargs); |
| 266 | if (!s) | 266 | if (!s) |
| 267 | return -ENOMEM; | 267 | return -ENOMEM; |
| 268 | 268 | ||
| 269 | /* ewww... some of these buggers have '/' in the name ... */ | 269 | /* |
| 270 | strreplace(s, '/', '!'); | 270 | * ewww... some of these buggers have '/' in the name ... If |
| 271 | kfree(kobj->name); | 271 | * that's the case, we need to make sure we have an actual |
| 272 | * allocated copy to modify, since kvasprintf_const may have | ||
| 273 | * returned something from .rodata. | ||
| 274 | */ | ||
| 275 | if (strchr(s, '/')) { | ||
| 276 | char *t; | ||
| 277 | |||
| 278 | t = kstrdup(s, GFP_KERNEL); | ||
| 279 | kfree_const(s); | ||
| 280 | if (!t) | ||
| 281 | return -ENOMEM; | ||
| 282 | strreplace(t, '/', '!'); | ||
| 283 | s = t; | ||
| 284 | } | ||
| 285 | kfree_const(kobj->name); | ||
| 272 | kobj->name = s; | 286 | kobj->name = s; |
| 273 | 287 | ||
| 274 | return 0; | 288 | return 0; |
| @@ -466,7 +480,7 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
| 466 | envp[0] = devpath_string; | 480 | envp[0] = devpath_string; |
| 467 | envp[1] = NULL; | 481 | envp[1] = NULL; |
| 468 | 482 | ||
| 469 | name = dup_name = kstrdup(new_name, GFP_KERNEL); | 483 | name = dup_name = kstrdup_const(new_name, GFP_KERNEL); |
| 470 | if (!name) { | 484 | if (!name) { |
| 471 | error = -ENOMEM; | 485 | error = -ENOMEM; |
| 472 | goto out; | 486 | goto out; |
| @@ -486,7 +500,7 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
| 486 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); | 500 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); |
| 487 | 501 | ||
| 488 | out: | 502 | out: |
| 489 | kfree(dup_name); | 503 | kfree_const(dup_name); |
| 490 | kfree(devpath_string); | 504 | kfree(devpath_string); |
| 491 | kfree(devpath); | 505 | kfree(devpath); |
| 492 | kobject_put(kobj); | 506 | kobject_put(kobj); |
| @@ -568,6 +582,7 @@ void kobject_del(struct kobject *kobj) | |||
| 568 | kobject_put(kobj->parent); | 582 | kobject_put(kobj->parent); |
| 569 | kobj->parent = NULL; | 583 | kobj->parent = NULL; |
| 570 | } | 584 | } |
| 585 | EXPORT_SYMBOL(kobject_del); | ||
| 571 | 586 | ||
| 572 | /** | 587 | /** |
| 573 | * kobject_get - increment refcount for object. | 588 | * kobject_get - increment refcount for object. |
| @@ -584,6 +599,7 @@ struct kobject *kobject_get(struct kobject *kobj) | |||
| 584 | } | 599 | } |
| 585 | return kobj; | 600 | return kobj; |
| 586 | } | 601 | } |
| 602 | EXPORT_SYMBOL(kobject_get); | ||
| 587 | 603 | ||
| 588 | static struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj) | 604 | static struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj) |
| 589 | { | 605 | { |
| @@ -632,7 +648,7 @@ static void kobject_cleanup(struct kobject *kobj) | |||
| 632 | /* free name if we allocated it */ | 648 | /* free name if we allocated it */ |
| 633 | if (name) { | 649 | if (name) { |
| 634 | pr_debug("kobject: '%s': free name\n", name); | 650 | pr_debug("kobject: '%s': free name\n", name); |
| 635 | kfree(name); | 651 | kfree_const(name); |
| 636 | } | 652 | } |
| 637 | } | 653 | } |
| 638 | 654 | ||
| @@ -675,6 +691,7 @@ void kobject_put(struct kobject *kobj) | |||
| 675 | kref_put(&kobj->kref, kobject_release); | 691 | kref_put(&kobj->kref, kobject_release); |
| 676 | } | 692 | } |
| 677 | } | 693 | } |
| 694 | EXPORT_SYMBOL(kobject_put); | ||
| 678 | 695 | ||
| 679 | static void dynamic_kobj_release(struct kobject *kobj) | 696 | static void dynamic_kobj_release(struct kobject *kobj) |
| 680 | { | 697 | { |
| @@ -803,6 +820,7 @@ int kset_register(struct kset *k) | |||
| 803 | kobject_uevent(&k->kobj, KOBJ_ADD); | 820 | kobject_uevent(&k->kobj, KOBJ_ADD); |
| 804 | return 0; | 821 | return 0; |
| 805 | } | 822 | } |
| 823 | EXPORT_SYMBOL(kset_register); | ||
| 806 | 824 | ||
| 807 | /** | 825 | /** |
| 808 | * kset_unregister - remove a kset. | 826 | * kset_unregister - remove a kset. |
| @@ -815,6 +833,7 @@ void kset_unregister(struct kset *k) | |||
| 815 | kobject_del(&k->kobj); | 833 | kobject_del(&k->kobj); |
| 816 | kobject_put(&k->kobj); | 834 | kobject_put(&k->kobj); |
| 817 | } | 835 | } |
| 836 | EXPORT_SYMBOL(kset_unregister); | ||
| 818 | 837 | ||
| 819 | /** | 838 | /** |
| 820 | * kset_find_obj - search for object in kset. | 839 | * kset_find_obj - search for object in kset. |
| @@ -1051,10 +1070,3 @@ void kobj_ns_drop(enum kobj_ns_type type, void *ns) | |||
| 1051 | kobj_ns_ops_tbl[type]->drop_ns(ns); | 1070 | kobj_ns_ops_tbl[type]->drop_ns(ns); |
| 1052 | spin_unlock(&kobj_ns_type_lock); | 1071 | spin_unlock(&kobj_ns_type_lock); |
| 1053 | } | 1072 | } |
| 1054 | |||
| 1055 | EXPORT_SYMBOL(kobject_get); | ||
| 1056 | EXPORT_SYMBOL(kobject_put); | ||
| 1057 | EXPORT_SYMBOL(kobject_del); | ||
| 1058 | |||
| 1059 | EXPORT_SYMBOL(kset_register); | ||
| 1060 | EXPORT_SYMBOL(kset_unregister); | ||
diff --git a/lib/llist.c b/lib/llist.c index 0b0e9779d675..ae5872b1df0c 100644 --- a/lib/llist.c +++ b/lib/llist.c | |||
| @@ -66,12 +66,12 @@ struct llist_node *llist_del_first(struct llist_head *head) | |||
| 66 | { | 66 | { |
| 67 | struct llist_node *entry, *old_entry, *next; | 67 | struct llist_node *entry, *old_entry, *next; |
| 68 | 68 | ||
| 69 | entry = head->first; | 69 | entry = smp_load_acquire(&head->first); |
| 70 | for (;;) { | 70 | for (;;) { |
| 71 | if (entry == NULL) | 71 | if (entry == NULL) |
| 72 | return NULL; | 72 | return NULL; |
| 73 | old_entry = entry; | 73 | old_entry = entry; |
| 74 | next = entry->next; | 74 | next = READ_ONCE(entry->next); |
| 75 | entry = cmpxchg(&head->first, old_entry, next); | 75 | entry = cmpxchg(&head->first, old_entry, next); |
| 76 | if (entry == old_entry) | 76 | if (entry == old_entry) |
| 77 | break; | 77 | break; |
diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h index a89d041592c8..b90e255c2a68 100644 --- a/lib/mpi/longlong.h +++ b/lib/mpi/longlong.h | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | 19 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 20 | * MA 02111-1307, USA. */ | 20 | * MA 02111-1307, USA. */ |
| 21 | 21 | ||
| 22 | #include <asm-generic/bitops/count_zeros.h> | 22 | #include <linux/count_zeros.h> |
| 23 | 23 | ||
| 24 | /* You have to define the following before including this file: | 24 | /* You have to define the following before including this file: |
| 25 | * | 25 | * |
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index 95c52a95259e..3db76b8c1115 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
| 22 | #include <asm-generic/bitops/count_zeros.h> | 22 | #include <linux/count_zeros.h> |
| 23 | #include "mpi-internal.h" | 23 | #include "mpi-internal.h" |
| 24 | 24 | ||
| 25 | #define MAX_EXTERN_MPI_BITS 16384 | 25 | #define MAX_EXTERN_MPI_BITS 16384 |
| @@ -319,3 +319,202 @@ int mpi_set_buffer(MPI a, const void *xbuffer, unsigned nbytes, int sign) | |||
| 319 | return 0; | 319 | return 0; |
| 320 | } | 320 | } |
| 321 | EXPORT_SYMBOL_GPL(mpi_set_buffer); | 321 | EXPORT_SYMBOL_GPL(mpi_set_buffer); |
| 322 | |||
| 323 | /** | ||
| 324 | * mpi_write_to_sgl() - Funnction exports MPI to an sgl (msb first) | ||
| 325 | * | ||
| 326 | * This function works in the same way as the mpi_read_buffer, but it | ||
| 327 | * takes an sgl instead of u8 * buf. | ||
| 328 | * | ||
| 329 | * @a: a multi precision integer | ||
| 330 | * @sgl: scatterlist to write to. Needs to be at least | ||
| 331 | * mpi_get_size(a) long. | ||
| 332 | * @nbytes: in/out param - it has the be set to the maximum number of | ||
| 333 | * bytes that can be written to sgl. This has to be at least | ||
| 334 | * the size of the integer a. On return it receives the actual | ||
| 335 | * length of the data written. | ||
| 336 | * @sign: if not NULL, it will be set to the sign of a. | ||
| 337 | * | ||
| 338 | * Return: 0 on success or error code in case of error | ||
| 339 | */ | ||
| 340 | int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, | ||
| 341 | int *sign) | ||
| 342 | { | ||
| 343 | u8 *p, *p2; | ||
| 344 | mpi_limb_t alimb, alimb2; | ||
| 345 | unsigned int n = mpi_get_size(a); | ||
| 346 | int i, x, y = 0, lzeros = 0, buf_len; | ||
| 347 | |||
| 348 | if (!nbytes || *nbytes < n) | ||
| 349 | return -EINVAL; | ||
| 350 | |||
| 351 | if (sign) | ||
| 352 | *sign = a->sign; | ||
| 353 | |||
| 354 | p = (void *)&a->d[a->nlimbs] - 1; | ||
| 355 | |||
| 356 | for (i = a->nlimbs * sizeof(alimb) - 1; i >= 0; i--, p--) { | ||
| 357 | if (!*p) | ||
| 358 | lzeros++; | ||
| 359 | else | ||
| 360 | break; | ||
| 361 | } | ||
| 362 | |||
| 363 | *nbytes = n - lzeros; | ||
| 364 | buf_len = sgl->length; | ||
| 365 | p2 = sg_virt(sgl); | ||
| 366 | |||
| 367 | for (i = a->nlimbs - 1; i >= 0; i--) { | ||
| 368 | alimb = a->d[i]; | ||
| 369 | p = (u8 *)&alimb2; | ||
| 370 | #if BYTES_PER_MPI_LIMB == 4 | ||
| 371 | *p++ = alimb >> 24; | ||
| 372 | *p++ = alimb >> 16; | ||
| 373 | *p++ = alimb >> 8; | ||
| 374 | *p++ = alimb; | ||
| 375 | #elif BYTES_PER_MPI_LIMB == 8 | ||
| 376 | *p++ = alimb >> 56; | ||
| 377 | *p++ = alimb >> 48; | ||
| 378 | *p++ = alimb >> 40; | ||
| 379 | *p++ = alimb >> 32; | ||
| 380 | *p++ = alimb >> 24; | ||
| 381 | *p++ = alimb >> 16; | ||
| 382 | *p++ = alimb >> 8; | ||
| 383 | *p++ = alimb; | ||
| 384 | #else | ||
| 385 | #error please implement for this limb size. | ||
| 386 | #endif | ||
| 387 | if (lzeros > 0) { | ||
| 388 | if (lzeros >= sizeof(alimb)) { | ||
| 389 | p -= sizeof(alimb); | ||
| 390 | continue; | ||
| 391 | } else { | ||
| 392 | mpi_limb_t *limb1 = (void *)p - sizeof(alimb); | ||
| 393 | mpi_limb_t *limb2 = (void *)p - sizeof(alimb) | ||
| 394 | + lzeros; | ||
| 395 | *limb1 = *limb2; | ||
| 396 | p -= lzeros; | ||
| 397 | y = lzeros; | ||
| 398 | } | ||
| 399 | lzeros -= sizeof(alimb); | ||
| 400 | } | ||
| 401 | |||
| 402 | p = p - (sizeof(alimb) - y); | ||
| 403 | |||
| 404 | for (x = 0; x < sizeof(alimb) - y; x++) { | ||
| 405 | if (!buf_len) { | ||
| 406 | sgl = sg_next(sgl); | ||
| 407 | if (!sgl) | ||
| 408 | return -EINVAL; | ||
| 409 | buf_len = sgl->length; | ||
| 410 | p2 = sg_virt(sgl); | ||
| 411 | } | ||
| 412 | *p2++ = *p++; | ||
| 413 | buf_len--; | ||
| 414 | } | ||
| 415 | y = 0; | ||
| 416 | } | ||
| 417 | return 0; | ||
| 418 | } | ||
| 419 | EXPORT_SYMBOL_GPL(mpi_write_to_sgl); | ||
| 420 | |||
| 421 | /* | ||
| 422 | * mpi_read_raw_from_sgl() - Function allocates an MPI and populates it with | ||
| 423 | * data from the sgl | ||
| 424 | * | ||
| 425 | * This function works in the same way as the mpi_read_raw_data, but it | ||
| 426 | * takes an sgl instead of void * buffer. i.e. it allocates | ||
| 427 | * a new MPI and reads the content of the sgl to the MPI. | ||
| 428 | * | ||
| 429 | * @sgl: scatterlist to read from | ||
| 430 | * @len: number of bytes to read | ||
| 431 | * | ||
| 432 | * Return: Pointer to a new MPI or NULL on error | ||
| 433 | */ | ||
| 434 | MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int len) | ||
| 435 | { | ||
| 436 | struct scatterlist *sg; | ||
| 437 | int x, i, j, z, lzeros, ents; | ||
| 438 | unsigned int nbits, nlimbs, nbytes; | ||
| 439 | mpi_limb_t a; | ||
| 440 | MPI val = NULL; | ||
| 441 | |||
| 442 | lzeros = 0; | ||
| 443 | ents = sg_nents(sgl); | ||
| 444 | |||
| 445 | for_each_sg(sgl, sg, ents, i) { | ||
| 446 | const u8 *buff = sg_virt(sg); | ||
| 447 | int len = sg->length; | ||
| 448 | |||
| 449 | while (len && !*buff) { | ||
| 450 | lzeros++; | ||
| 451 | len--; | ||
| 452 | buff++; | ||
| 453 | } | ||
| 454 | |||
| 455 | if (len && *buff) | ||
| 456 | break; | ||
| 457 | |||
| 458 | ents--; | ||
| 459 | lzeros = 0; | ||
| 460 | } | ||
| 461 | |||
| 462 | sgl = sg; | ||
| 463 | |||
| 464 | if (!ents) | ||
| 465 | nbytes = 0; | ||
| 466 | else | ||
| 467 | nbytes = len - lzeros; | ||
| 468 | |||
| 469 | nbits = nbytes * 8; | ||
| 470 | if (nbits > MAX_EXTERN_MPI_BITS) { | ||
| 471 | pr_info("MPI: mpi too large (%u bits)\n", nbits); | ||
| 472 | return NULL; | ||
| 473 | } | ||
| 474 | |||
| 475 | if (nbytes > 0) | ||
| 476 | nbits -= count_leading_zeros(*(u8 *)(sg_virt(sgl) + lzeros)); | ||
| 477 | else | ||
| 478 | nbits = 0; | ||
| 479 | |||
| 480 | nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB); | ||
| 481 | val = mpi_alloc(nlimbs); | ||
| 482 | if (!val) | ||
| 483 | return NULL; | ||
| 484 | |||
| 485 | val->nbits = nbits; | ||
| 486 | val->sign = 0; | ||
| 487 | val->nlimbs = nlimbs; | ||
| 488 | |||
| 489 | if (nbytes == 0) | ||
| 490 | return val; | ||
| 491 | |||
| 492 | j = nlimbs - 1; | ||
| 493 | a = 0; | ||
| 494 | z = 0; | ||
| 495 | x = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; | ||
| 496 | x %= BYTES_PER_MPI_LIMB; | ||
| 497 | |||
| 498 | for_each_sg(sgl, sg, ents, i) { | ||
| 499 | const u8 *buffer = sg_virt(sg) + lzeros; | ||
| 500 | int len = sg->length - lzeros; | ||
| 501 | int buf_shift = x; | ||
| 502 | |||
| 503 | if (sg_is_last(sg) && (len % BYTES_PER_MPI_LIMB)) | ||
| 504 | len += BYTES_PER_MPI_LIMB - (len % BYTES_PER_MPI_LIMB); | ||
| 505 | |||
| 506 | for (; x < len + buf_shift; x++) { | ||
| 507 | a <<= 8; | ||
| 508 | a |= *buffer++; | ||
| 509 | if (((z + x + 1) % BYTES_PER_MPI_LIMB) == 0) { | ||
| 510 | val->d[j--] = a; | ||
| 511 | a = 0; | ||
| 512 | } | ||
| 513 | } | ||
| 514 | z += x; | ||
| 515 | x = 0; | ||
| 516 | lzeros = 0; | ||
| 517 | } | ||
| 518 | return val; | ||
| 519 | } | ||
| 520 | EXPORT_SYMBOL_GPL(mpi_read_raw_from_sgl); | ||
diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c index 88d3d32e5923..6019c53c669e 100644 --- a/lib/nmi_backtrace.c +++ b/lib/nmi_backtrace.c | |||
| @@ -43,6 +43,12 @@ static void print_seq_line(struct nmi_seq_buf *s, int start, int end) | |||
| 43 | printk("%.*s", (end - start) + 1, buf); | 43 | printk("%.*s", (end - start) + 1, buf); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | /* | ||
| 47 | * When raise() is called it will be is passed a pointer to the | ||
| 48 | * backtrace_mask. Architectures that call nmi_cpu_backtrace() | ||
| 49 | * directly from their raise() functions may rely on the mask | ||
| 50 | * they are passed being updated as a side effect of this call. | ||
| 51 | */ | ||
| 46 | void nmi_trigger_all_cpu_backtrace(bool include_self, | 52 | void nmi_trigger_all_cpu_backtrace(bool include_self, |
| 47 | void (*raise)(cpumask_t *mask)) | 53 | void (*raise)(cpumask_t *mask)) |
| 48 | { | 54 | { |
| @@ -149,7 +155,10 @@ bool nmi_cpu_backtrace(struct pt_regs *regs) | |||
| 149 | /* Replace printk to write into the NMI seq */ | 155 | /* Replace printk to write into the NMI seq */ |
| 150 | this_cpu_write(printk_func, nmi_vprintk); | 156 | this_cpu_write(printk_func, nmi_vprintk); |
| 151 | pr_warn("NMI backtrace for cpu %d\n", cpu); | 157 | pr_warn("NMI backtrace for cpu %d\n", cpu); |
| 152 | show_regs(regs); | 158 | if (regs) |
| 159 | show_regs(regs); | ||
| 160 | else | ||
| 161 | dump_stack(); | ||
| 153 | this_cpu_write(printk_func, printk_func_save); | 162 | this_cpu_write(printk_func, printk_func_save); |
| 154 | 163 | ||
| 155 | cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask)); | 164 | cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask)); |
diff --git a/lib/once.c b/lib/once.c new file mode 100644 index 000000000000..05c8604627eb --- /dev/null +++ b/lib/once.c | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #include <linux/slab.h> | ||
| 2 | #include <linux/spinlock.h> | ||
| 3 | #include <linux/once.h> | ||
| 4 | #include <linux/random.h> | ||
| 5 | |||
| 6 | struct once_work { | ||
| 7 | struct work_struct work; | ||
| 8 | struct static_key *key; | ||
| 9 | }; | ||
| 10 | |||
| 11 | static void once_deferred(struct work_struct *w) | ||
| 12 | { | ||
| 13 | struct once_work *work; | ||
| 14 | |||
| 15 | work = container_of(w, struct once_work, work); | ||
| 16 | BUG_ON(!static_key_enabled(work->key)); | ||
| 17 | static_key_slow_dec(work->key); | ||
| 18 | kfree(work); | ||
| 19 | } | ||
| 20 | |||
| 21 | static void once_disable_jump(struct static_key *key) | ||
| 22 | { | ||
| 23 | struct once_work *w; | ||
| 24 | |||
| 25 | w = kmalloc(sizeof(*w), GFP_ATOMIC); | ||
| 26 | if (!w) | ||
| 27 | return; | ||
| 28 | |||
| 29 | INIT_WORK(&w->work, once_deferred); | ||
| 30 | w->key = key; | ||
| 31 | schedule_work(&w->work); | ||
| 32 | } | ||
| 33 | |||
| 34 | static DEFINE_SPINLOCK(once_lock); | ||
| 35 | |||
| 36 | bool __do_once_start(bool *done, unsigned long *flags) | ||
| 37 | __acquires(once_lock) | ||
| 38 | { | ||
| 39 | spin_lock_irqsave(&once_lock, *flags); | ||
| 40 | if (*done) { | ||
| 41 | spin_unlock_irqrestore(&once_lock, *flags); | ||
| 42 | /* Keep sparse happy by restoring an even lock count on | ||
| 43 | * this lock. In case we return here, we don't call into | ||
| 44 | * __do_once_done but return early in the DO_ONCE() macro. | ||
| 45 | */ | ||
| 46 | __acquire(once_lock); | ||
| 47 | return false; | ||
| 48 | } | ||
| 49 | |||
| 50 | return true; | ||
| 51 | } | ||
| 52 | EXPORT_SYMBOL(__do_once_start); | ||
| 53 | |||
| 54 | void __do_once_done(bool *done, struct static_key *once_key, | ||
| 55 | unsigned long *flags) | ||
| 56 | __releases(once_lock) | ||
| 57 | { | ||
| 58 | *done = true; | ||
| 59 | spin_unlock_irqrestore(&once_lock, *flags); | ||
| 60 | once_disable_jump(once_key); | ||
| 61 | } | ||
| 62 | EXPORT_SYMBOL(__do_once_done); | ||
diff --git a/lib/percpu_ida.c b/lib/percpu_ida.c index f75715131f20..6d40944960de 100644 --- a/lib/percpu_ida.c +++ b/lib/percpu_ida.c | |||
| @@ -135,7 +135,7 @@ static inline unsigned alloc_local_tag(struct percpu_ida_cpu *tags) | |||
| 135 | * TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, of course). | 135 | * TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, of course). |
| 136 | * | 136 | * |
| 137 | * @gfp indicates whether or not to wait until a free id is available (it's not | 137 | * @gfp indicates whether or not to wait until a free id is available (it's not |
| 138 | * used for internal memory allocations); thus if passed __GFP_WAIT we may sleep | 138 | * used for internal memory allocations); thus if passed __GFP_RECLAIM we may sleep |
| 139 | * however long it takes until another thread frees an id (same semantics as a | 139 | * however long it takes until another thread frees an id (same semantics as a |
| 140 | * mempool). | 140 | * mempool). |
| 141 | * | 141 | * |
diff --git a/lib/proportions.c b/lib/proportions.c index 6f724298f67a..efa54f259ea9 100644 --- a/lib/proportions.c +++ b/lib/proportions.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Floating proportions | 2 | * Floating proportions |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> | 4 | * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra |
| 5 | * | 5 | * |
| 6 | * Description: | 6 | * Description: |
| 7 | * | 7 | * |
diff --git a/lib/radix-tree.c b/lib/radix-tree.c index f9ebe1c82060..fcf5d98574ce 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c | |||
| @@ -188,7 +188,7 @@ radix_tree_node_alloc(struct radix_tree_root *root) | |||
| 188 | * preloading in the interrupt anyway as all the allocations have to | 188 | * preloading in the interrupt anyway as all the allocations have to |
| 189 | * be atomic. So just do normal allocation when in interrupt. | 189 | * be atomic. So just do normal allocation when in interrupt. |
| 190 | */ | 190 | */ |
| 191 | if (!(gfp_mask & __GFP_WAIT) && !in_interrupt()) { | 191 | if (!gfpflags_allow_blocking(gfp_mask) && !in_interrupt()) { |
| 192 | struct radix_tree_preload *rtp; | 192 | struct radix_tree_preload *rtp; |
| 193 | 193 | ||
| 194 | /* | 194 | /* |
| @@ -249,7 +249,7 @@ radix_tree_node_free(struct radix_tree_node *node) | |||
| 249 | * with preemption not disabled. | 249 | * with preemption not disabled. |
| 250 | * | 250 | * |
| 251 | * To make use of this facility, the radix tree must be initialised without | 251 | * To make use of this facility, the radix tree must be initialised without |
| 252 | * __GFP_WAIT being passed to INIT_RADIX_TREE(). | 252 | * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE(). |
| 253 | */ | 253 | */ |
| 254 | static int __radix_tree_preload(gfp_t gfp_mask) | 254 | static int __radix_tree_preload(gfp_t gfp_mask) |
| 255 | { | 255 | { |
| @@ -286,12 +286,12 @@ out: | |||
| 286 | * with preemption not disabled. | 286 | * with preemption not disabled. |
| 287 | * | 287 | * |
| 288 | * To make use of this facility, the radix tree must be initialised without | 288 | * To make use of this facility, the radix tree must be initialised without |
| 289 | * __GFP_WAIT being passed to INIT_RADIX_TREE(). | 289 | * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE(). |
| 290 | */ | 290 | */ |
| 291 | int radix_tree_preload(gfp_t gfp_mask) | 291 | int radix_tree_preload(gfp_t gfp_mask) |
| 292 | { | 292 | { |
| 293 | /* Warn on non-sensical use... */ | 293 | /* Warn on non-sensical use... */ |
| 294 | WARN_ON_ONCE(!(gfp_mask & __GFP_WAIT)); | 294 | WARN_ON_ONCE(!gfpflags_allow_blocking(gfp_mask)); |
| 295 | return __radix_tree_preload(gfp_mask); | 295 | return __radix_tree_preload(gfp_mask); |
| 296 | } | 296 | } |
| 297 | EXPORT_SYMBOL(radix_tree_preload); | 297 | EXPORT_SYMBOL(radix_tree_preload); |
| @@ -303,7 +303,7 @@ EXPORT_SYMBOL(radix_tree_preload); | |||
| 303 | */ | 303 | */ |
| 304 | int radix_tree_maybe_preload(gfp_t gfp_mask) | 304 | int radix_tree_maybe_preload(gfp_t gfp_mask) |
| 305 | { | 305 | { |
| 306 | if (gfp_mask & __GFP_WAIT) | 306 | if (gfpflags_allow_blocking(gfp_mask)) |
| 307 | return __radix_tree_preload(gfp_mask); | 307 | return __radix_tree_preload(gfp_mask); |
| 308 | /* Preloading doesn't help anything with this gfp mask, skip it */ | 308 | /* Preloading doesn't help anything with this gfp mask, skip it */ |
| 309 | preempt_disable(); | 309 | preempt_disable(); |
diff --git a/lib/random32.c b/lib/random32.c index 0bee183fa18f..12111910ccd0 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
| @@ -181,7 +181,7 @@ void prandom_seed(u32 entropy) | |||
| 181 | * No locking on the CPUs, but then somewhat random results are, well, | 181 | * No locking on the CPUs, but then somewhat random results are, well, |
| 182 | * expected. | 182 | * expected. |
| 183 | */ | 183 | */ |
| 184 | for_each_possible_cpu (i) { | 184 | for_each_possible_cpu(i) { |
| 185 | struct rnd_state *state = &per_cpu(net_rand_state, i); | 185 | struct rnd_state *state = &per_cpu(net_rand_state, i); |
| 186 | 186 | ||
| 187 | state->s1 = __seed(state->s1 ^ entropy, 2U); | 187 | state->s1 = __seed(state->s1 ^ entropy, 2U); |
| @@ -201,7 +201,7 @@ static int __init prandom_init(void) | |||
| 201 | prandom_state_selftest(); | 201 | prandom_state_selftest(); |
| 202 | 202 | ||
| 203 | for_each_possible_cpu(i) { | 203 | for_each_possible_cpu(i) { |
| 204 | struct rnd_state *state = &per_cpu(net_rand_state,i); | 204 | struct rnd_state *state = &per_cpu(net_rand_state, i); |
| 205 | u32 weak_seed = (i + jiffies) ^ random_get_entropy(); | 205 | u32 weak_seed = (i + jiffies) ^ random_get_entropy(); |
| 206 | 206 | ||
| 207 | prandom_seed_early(state, weak_seed, true); | 207 | prandom_seed_early(state, weak_seed, true); |
| @@ -238,13 +238,30 @@ static void __init __prandom_start_seed_timer(void) | |||
| 238 | add_timer(&seed_timer); | 238 | add_timer(&seed_timer); |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state) | ||
| 242 | { | ||
| 243 | int i; | ||
| 244 | |||
| 245 | for_each_possible_cpu(i) { | ||
| 246 | struct rnd_state *state = per_cpu_ptr(pcpu_state, i); | ||
| 247 | u32 seeds[4]; | ||
| 248 | |||
| 249 | get_random_bytes(&seeds, sizeof(seeds)); | ||
| 250 | state->s1 = __seed(seeds[0], 2U); | ||
| 251 | state->s2 = __seed(seeds[1], 8U); | ||
| 252 | state->s3 = __seed(seeds[2], 16U); | ||
| 253 | state->s4 = __seed(seeds[3], 128U); | ||
| 254 | |||
| 255 | prandom_warmup(state); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 241 | /* | 259 | /* |
| 242 | * Generate better values after random number generator | 260 | * Generate better values after random number generator |
| 243 | * is fully initialized. | 261 | * is fully initialized. |
| 244 | */ | 262 | */ |
| 245 | static void __prandom_reseed(bool late) | 263 | static void __prandom_reseed(bool late) |
| 246 | { | 264 | { |
| 247 | int i; | ||
| 248 | unsigned long flags; | 265 | unsigned long flags; |
| 249 | static bool latch = false; | 266 | static bool latch = false; |
| 250 | static DEFINE_SPINLOCK(lock); | 267 | static DEFINE_SPINLOCK(lock); |
| @@ -266,19 +283,7 @@ static void __prandom_reseed(bool late) | |||
| 266 | goto out; | 283 | goto out; |
| 267 | 284 | ||
| 268 | latch = true; | 285 | latch = true; |
| 269 | 286 | prandom_seed_full_state(&net_rand_state); | |
| 270 | for_each_possible_cpu(i) { | ||
| 271 | struct rnd_state *state = &per_cpu(net_rand_state,i); | ||
| 272 | u32 seeds[4]; | ||
| 273 | |||
| 274 | get_random_bytes(&seeds, sizeof(seeds)); | ||
| 275 | state->s1 = __seed(seeds[0], 2U); | ||
| 276 | state->s2 = __seed(seeds[1], 8U); | ||
| 277 | state->s3 = __seed(seeds[2], 16U); | ||
| 278 | state->s4 = __seed(seeds[3], 128U); | ||
| 279 | |||
| 280 | prandom_warmup(state); | ||
| 281 | } | ||
| 282 | out: | 287 | out: |
| 283 | spin_unlock_irqrestore(&lock, flags); | 288 | spin_unlock_irqrestore(&lock, flags); |
| 284 | } | 289 | } |
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index a54ff8949f91..51282f579760 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c | |||
| @@ -389,33 +389,31 @@ static bool rhashtable_check_elasticity(struct rhashtable *ht, | |||
| 389 | return false; | 389 | return false; |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | int rhashtable_insert_rehash(struct rhashtable *ht) | 392 | int rhashtable_insert_rehash(struct rhashtable *ht, |
| 393 | struct bucket_table *tbl) | ||
| 393 | { | 394 | { |
| 394 | struct bucket_table *old_tbl; | 395 | struct bucket_table *old_tbl; |
| 395 | struct bucket_table *new_tbl; | 396 | struct bucket_table *new_tbl; |
| 396 | struct bucket_table *tbl; | ||
| 397 | unsigned int size; | 397 | unsigned int size; |
| 398 | int err; | 398 | int err; |
| 399 | 399 | ||
| 400 | old_tbl = rht_dereference_rcu(ht->tbl, ht); | 400 | old_tbl = rht_dereference_rcu(ht->tbl, ht); |
| 401 | tbl = rhashtable_last_table(ht, old_tbl); | ||
| 402 | 401 | ||
| 403 | size = tbl->size; | 402 | size = tbl->size; |
| 404 | 403 | ||
| 404 | err = -EBUSY; | ||
| 405 | |||
| 405 | if (rht_grow_above_75(ht, tbl)) | 406 | if (rht_grow_above_75(ht, tbl)) |
| 406 | size *= 2; | 407 | size *= 2; |
| 407 | /* Do not schedule more than one rehash */ | 408 | /* Do not schedule more than one rehash */ |
| 408 | else if (old_tbl != tbl) | 409 | else if (old_tbl != tbl) |
| 409 | return -EBUSY; | 410 | goto fail; |
| 411 | |||
| 412 | err = -ENOMEM; | ||
| 410 | 413 | ||
| 411 | new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC); | 414 | new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC); |
| 412 | if (new_tbl == NULL) { | 415 | if (new_tbl == NULL) |
| 413 | /* Schedule async resize/rehash to try allocation | 416 | goto fail; |
| 414 | * non-atomic context. | ||
| 415 | */ | ||
| 416 | schedule_work(&ht->run_work); | ||
| 417 | return -ENOMEM; | ||
| 418 | } | ||
| 419 | 417 | ||
| 420 | err = rhashtable_rehash_attach(ht, tbl, new_tbl); | 418 | err = rhashtable_rehash_attach(ht, tbl, new_tbl); |
| 421 | if (err) { | 419 | if (err) { |
| @@ -426,12 +424,24 @@ int rhashtable_insert_rehash(struct rhashtable *ht) | |||
| 426 | schedule_work(&ht->run_work); | 424 | schedule_work(&ht->run_work); |
| 427 | 425 | ||
| 428 | return err; | 426 | return err; |
| 427 | |||
| 428 | fail: | ||
| 429 | /* Do not fail the insert if someone else did a rehash. */ | ||
| 430 | if (likely(rcu_dereference_raw(tbl->future_tbl))) | ||
| 431 | return 0; | ||
| 432 | |||
| 433 | /* Schedule async rehash to retry allocation in process context. */ | ||
| 434 | if (err == -ENOMEM) | ||
| 435 | schedule_work(&ht->run_work); | ||
| 436 | |||
| 437 | return err; | ||
| 429 | } | 438 | } |
| 430 | EXPORT_SYMBOL_GPL(rhashtable_insert_rehash); | 439 | EXPORT_SYMBOL_GPL(rhashtable_insert_rehash); |
| 431 | 440 | ||
| 432 | int rhashtable_insert_slow(struct rhashtable *ht, const void *key, | 441 | struct bucket_table *rhashtable_insert_slow(struct rhashtable *ht, |
| 433 | struct rhash_head *obj, | 442 | const void *key, |
| 434 | struct bucket_table *tbl) | 443 | struct rhash_head *obj, |
| 444 | struct bucket_table *tbl) | ||
| 435 | { | 445 | { |
| 436 | struct rhash_head *head; | 446 | struct rhash_head *head; |
| 437 | unsigned int hash; | 447 | unsigned int hash; |
| @@ -467,7 +477,12 @@ int rhashtable_insert_slow(struct rhashtable *ht, const void *key, | |||
| 467 | exit: | 477 | exit: |
| 468 | spin_unlock(rht_bucket_lock(tbl, hash)); | 478 | spin_unlock(rht_bucket_lock(tbl, hash)); |
| 469 | 479 | ||
| 470 | return err; | 480 | if (err == 0) |
| 481 | return NULL; | ||
| 482 | else if (err == -EAGAIN) | ||
| 483 | return tbl; | ||
| 484 | else | ||
| 485 | return ERR_PTR(err); | ||
| 471 | } | 486 | } |
| 472 | EXPORT_SYMBOL_GPL(rhashtable_insert_slow); | 487 | EXPORT_SYMBOL_GPL(rhashtable_insert_slow); |
| 473 | 488 | ||
| @@ -503,10 +518,11 @@ int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter) | |||
| 503 | if (!iter->walker) | 518 | if (!iter->walker) |
| 504 | return -ENOMEM; | 519 | return -ENOMEM; |
| 505 | 520 | ||
| 506 | mutex_lock(&ht->mutex); | 521 | spin_lock(&ht->lock); |
| 507 | iter->walker->tbl = rht_dereference(ht->tbl, ht); | 522 | iter->walker->tbl = |
| 523 | rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock)); | ||
| 508 | list_add(&iter->walker->list, &iter->walker->tbl->walkers); | 524 | list_add(&iter->walker->list, &iter->walker->tbl->walkers); |
| 509 | mutex_unlock(&ht->mutex); | 525 | spin_unlock(&ht->lock); |
| 510 | 526 | ||
| 511 | return 0; | 527 | return 0; |
| 512 | } | 528 | } |
| @@ -520,10 +536,10 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_init); | |||
| 520 | */ | 536 | */ |
| 521 | void rhashtable_walk_exit(struct rhashtable_iter *iter) | 537 | void rhashtable_walk_exit(struct rhashtable_iter *iter) |
| 522 | { | 538 | { |
| 523 | mutex_lock(&iter->ht->mutex); | 539 | spin_lock(&iter->ht->lock); |
| 524 | if (iter->walker->tbl) | 540 | if (iter->walker->tbl) |
| 525 | list_del(&iter->walker->list); | 541 | list_del(&iter->walker->list); |
| 526 | mutex_unlock(&iter->ht->mutex); | 542 | spin_unlock(&iter->ht->lock); |
| 527 | kfree(iter->walker); | 543 | kfree(iter->walker); |
| 528 | } | 544 | } |
| 529 | EXPORT_SYMBOL_GPL(rhashtable_walk_exit); | 545 | EXPORT_SYMBOL_GPL(rhashtable_walk_exit); |
| @@ -547,14 +563,12 @@ int rhashtable_walk_start(struct rhashtable_iter *iter) | |||
| 547 | { | 563 | { |
| 548 | struct rhashtable *ht = iter->ht; | 564 | struct rhashtable *ht = iter->ht; |
| 549 | 565 | ||
| 550 | mutex_lock(&ht->mutex); | 566 | rcu_read_lock(); |
| 551 | 567 | ||
| 568 | spin_lock(&ht->lock); | ||
| 552 | if (iter->walker->tbl) | 569 | if (iter->walker->tbl) |
| 553 | list_del(&iter->walker->list); | 570 | list_del(&iter->walker->list); |
| 554 | 571 | spin_unlock(&ht->lock); | |
| 555 | rcu_read_lock(); | ||
| 556 | |||
| 557 | mutex_unlock(&ht->mutex); | ||
| 558 | 572 | ||
| 559 | if (!iter->walker->tbl) { | 573 | if (!iter->walker->tbl) { |
| 560 | iter->walker->tbl = rht_dereference_rcu(ht->tbl, ht); | 574 | iter->walker->tbl = rht_dereference_rcu(ht->tbl, ht); |
| @@ -723,9 +737,6 @@ int rhashtable_init(struct rhashtable *ht, | |||
| 723 | if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) | 737 | if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) |
| 724 | return -EINVAL; | 738 | return -EINVAL; |
| 725 | 739 | ||
| 726 | if (params->nelem_hint) | ||
| 727 | size = rounded_hashtable_size(params); | ||
| 728 | |||
| 729 | memset(ht, 0, sizeof(*ht)); | 740 | memset(ht, 0, sizeof(*ht)); |
| 730 | mutex_init(&ht->mutex); | 741 | mutex_init(&ht->mutex); |
| 731 | spin_lock_init(&ht->lock); | 742 | spin_lock_init(&ht->lock); |
| @@ -745,6 +756,9 @@ int rhashtable_init(struct rhashtable *ht, | |||
| 745 | 756 | ||
| 746 | ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE); | 757 | ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE); |
| 747 | 758 | ||
| 759 | if (params->nelem_hint) | ||
| 760 | size = rounded_hashtable_size(&ht->p); | ||
| 761 | |||
| 748 | /* The maximum (not average) chain length grows with the | 762 | /* The maximum (not average) chain length grows with the |
| 749 | * size of the hash table, at a rate of (log N)/(log log N). | 763 | * size of the hash table, at a rate of (log N)/(log log N). |
| 750 | * The value of 16 is selected so that even if the hash | 764 | * The value of 16 is selected so that even if the hash |
diff --git a/lib/string.c b/lib/string.c index 84775ba873b9..0323c0d5629a 100644 --- a/lib/string.c +++ b/lib/string.c | |||
| @@ -904,7 +904,7 @@ void *memchr_inv(const void *start, int c, size_t bytes) | |||
| 904 | 904 | ||
| 905 | value64 = value; | 905 | value64 = value; |
| 906 | #if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 | 906 | #if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 |
| 907 | value64 *= 0x0101010101010101; | 907 | value64 *= 0x0101010101010101ULL; |
| 908 | #elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) | 908 | #elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) |
| 909 | value64 *= 0x01010101; | 909 | value64 *= 0x01010101; |
| 910 | value64 |= value64 << 32; | 910 | value64 |= value64 << 32; |
diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 8e376efd88a4..98866a770770 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c | |||
| @@ -326,6 +326,39 @@ out: | |||
| 326 | kfree(out_test); | 326 | kfree(out_test); |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | #define string_get_size_maxbuf 16 | ||
| 330 | #define test_string_get_size_one(size, blk_size, units, exp_result) \ | ||
| 331 | do { \ | ||
| 332 | BUILD_BUG_ON(sizeof(exp_result) >= string_get_size_maxbuf); \ | ||
| 333 | __test_string_get_size((size), (blk_size), (units), \ | ||
| 334 | (exp_result)); \ | ||
| 335 | } while (0) | ||
| 336 | |||
| 337 | |||
| 338 | static __init void __test_string_get_size(const u64 size, const u64 blk_size, | ||
| 339 | const enum string_size_units units, | ||
| 340 | const char *exp_result) | ||
| 341 | { | ||
| 342 | char buf[string_get_size_maxbuf]; | ||
| 343 | |||
| 344 | string_get_size(size, blk_size, units, buf, sizeof(buf)); | ||
| 345 | if (!memcmp(buf, exp_result, strlen(exp_result) + 1)) | ||
| 346 | return; | ||
| 347 | |||
| 348 | buf[sizeof(buf) - 1] = '\0'; | ||
| 349 | pr_warn("Test 'test_string_get_size_one' failed!\n"); | ||
| 350 | pr_warn("string_get_size(size = %llu, blk_size = %llu, units = %d\n", | ||
| 351 | size, blk_size, units); | ||
| 352 | pr_warn("expected: '%s', got '%s'\n", exp_result, buf); | ||
| 353 | } | ||
| 354 | |||
| 355 | static __init void test_string_get_size(void) | ||
| 356 | { | ||
| 357 | test_string_get_size_one(16384, 512, STRING_UNITS_2, "8.00 MiB"); | ||
| 358 | test_string_get_size_one(8192, 4096, STRING_UNITS_10, "32.7 MB"); | ||
| 359 | test_string_get_size_one(1, 512, STRING_UNITS_10, "512 B"); | ||
| 360 | } | ||
| 361 | |||
| 329 | static int __init test_string_helpers_init(void) | 362 | static int __init test_string_helpers_init(void) |
| 330 | { | 363 | { |
| 331 | unsigned int i; | 364 | unsigned int i; |
| @@ -344,6 +377,9 @@ static int __init test_string_helpers_init(void) | |||
| 344 | for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) | 377 | for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) |
| 345 | test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1); | 378 | test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1); |
| 346 | 379 | ||
| 380 | /* Test string_get_size() */ | ||
| 381 | test_string_get_size(); | ||
| 382 | |||
| 347 | return -EINVAL; | 383 | return -EINVAL; |
| 348 | } | 384 | } |
| 349 | module_init(test_string_helpers_init); | 385 | module_init(test_string_helpers_init); |
diff --git a/lib/test_bpf.c b/lib/test_bpf.c index d1377390b3ad..10cd1860e5b0 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c | |||
| @@ -5056,6 +5056,36 @@ static struct bpf_test tests[] = { | |||
| 5056 | { {0x1, 0x0 } }, | 5056 | { {0x1, 0x0 } }, |
| 5057 | }, | 5057 | }, |
| 5058 | { | 5058 | { |
| 5059 | "MOD default X", | ||
| 5060 | .u.insns = { | ||
| 5061 | /* | ||
| 5062 | * A = 0x42 | ||
| 5063 | * A = A mod X ; this halt the filter execution if X is 0 | ||
| 5064 | * ret 0x42 | ||
| 5065 | */ | ||
| 5066 | BPF_STMT(BPF_LD | BPF_IMM, 0x42), | ||
| 5067 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0), | ||
| 5068 | BPF_STMT(BPF_RET | BPF_K, 0x42), | ||
| 5069 | }, | ||
| 5070 | CLASSIC | FLAG_NO_DATA, | ||
| 5071 | {}, | ||
| 5072 | { {0x1, 0x0 } }, | ||
| 5073 | }, | ||
| 5074 | { | ||
| 5075 | "MOD default A", | ||
| 5076 | .u.insns = { | ||
| 5077 | /* | ||
| 5078 | * A = A mod 1 | ||
| 5079 | * ret A | ||
| 5080 | */ | ||
| 5081 | BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1), | ||
| 5082 | BPF_STMT(BPF_RET | BPF_A, 0x0), | ||
| 5083 | }, | ||
| 5084 | CLASSIC | FLAG_NO_DATA, | ||
| 5085 | {}, | ||
| 5086 | { {0x1, 0x0 } }, | ||
| 5087 | }, | ||
| 5088 | { | ||
| 5059 | "JMP EQ default A", | 5089 | "JMP EQ default A", |
| 5060 | .u.insns = { | 5090 | .u.insns = { |
| 5061 | /* | 5091 | /* |
diff --git a/lib/test_kasan.c b/lib/test_kasan.c index c1efb1b61017..c32f3b0048dc 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c | |||
| @@ -138,6 +138,71 @@ static noinline void __init kmalloc_oob_16(void) | |||
| 138 | kfree(ptr2); | 138 | kfree(ptr2); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | static noinline void __init kmalloc_oob_memset_2(void) | ||
| 142 | { | ||
| 143 | char *ptr; | ||
| 144 | size_t size = 8; | ||
| 145 | |||
| 146 | pr_info("out-of-bounds in memset2\n"); | ||
| 147 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 148 | if (!ptr) { | ||
| 149 | pr_err("Allocation failed\n"); | ||
| 150 | return; | ||
| 151 | } | ||
| 152 | |||
| 153 | memset(ptr+7, 0, 2); | ||
| 154 | kfree(ptr); | ||
| 155 | } | ||
| 156 | |||
| 157 | static noinline void __init kmalloc_oob_memset_4(void) | ||
| 158 | { | ||
| 159 | char *ptr; | ||
| 160 | size_t size = 8; | ||
| 161 | |||
| 162 | pr_info("out-of-bounds in memset4\n"); | ||
| 163 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 164 | if (!ptr) { | ||
| 165 | pr_err("Allocation failed\n"); | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 169 | memset(ptr+5, 0, 4); | ||
| 170 | kfree(ptr); | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | static noinline void __init kmalloc_oob_memset_8(void) | ||
| 175 | { | ||
| 176 | char *ptr; | ||
| 177 | size_t size = 8; | ||
| 178 | |||
| 179 | pr_info("out-of-bounds in memset8\n"); | ||
| 180 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 181 | if (!ptr) { | ||
| 182 | pr_err("Allocation failed\n"); | ||
| 183 | return; | ||
| 184 | } | ||
| 185 | |||
| 186 | memset(ptr+1, 0, 8); | ||
| 187 | kfree(ptr); | ||
| 188 | } | ||
| 189 | |||
| 190 | static noinline void __init kmalloc_oob_memset_16(void) | ||
| 191 | { | ||
| 192 | char *ptr; | ||
| 193 | size_t size = 16; | ||
| 194 | |||
| 195 | pr_info("out-of-bounds in memset16\n"); | ||
| 196 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 197 | if (!ptr) { | ||
| 198 | pr_err("Allocation failed\n"); | ||
| 199 | return; | ||
| 200 | } | ||
| 201 | |||
| 202 | memset(ptr+1, 0, 16); | ||
| 203 | kfree(ptr); | ||
| 204 | } | ||
| 205 | |||
| 141 | static noinline void __init kmalloc_oob_in_memset(void) | 206 | static noinline void __init kmalloc_oob_in_memset(void) |
| 142 | { | 207 | { |
| 143 | char *ptr; | 208 | char *ptr; |
| @@ -264,6 +329,10 @@ static int __init kmalloc_tests_init(void) | |||
| 264 | kmalloc_oob_krealloc_less(); | 329 | kmalloc_oob_krealloc_less(); |
| 265 | kmalloc_oob_16(); | 330 | kmalloc_oob_16(); |
| 266 | kmalloc_oob_in_memset(); | 331 | kmalloc_oob_in_memset(); |
| 332 | kmalloc_oob_memset_2(); | ||
| 333 | kmalloc_oob_memset_4(); | ||
| 334 | kmalloc_oob_memset_8(); | ||
| 335 | kmalloc_oob_memset_16(); | ||
| 267 | kmalloc_uaf(); | 336 | kmalloc_uaf(); |
| 268 | kmalloc_uaf_memset(); | 337 | kmalloc_uaf_memset(); |
| 269 | kmalloc_uaf2(); | 338 | kmalloc_uaf2(); |
diff --git a/lib/test_printf.c b/lib/test_printf.c new file mode 100644 index 000000000000..c5a666af9ba5 --- /dev/null +++ b/lib/test_printf.c | |||
| @@ -0,0 +1,362 @@ | |||
| 1 | /* | ||
| 2 | * Test cases for printf facility. | ||
| 3 | */ | ||
| 4 | |||
| 5 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 6 | |||
| 7 | #include <linux/init.h> | ||
| 8 | #include <linux/kernel.h> | ||
| 9 | #include <linux/module.h> | ||
| 10 | #include <linux/printk.h> | ||
| 11 | #include <linux/random.h> | ||
| 12 | #include <linux/slab.h> | ||
| 13 | #include <linux/string.h> | ||
| 14 | |||
| 15 | #include <linux/socket.h> | ||
| 16 | #include <linux/in.h> | ||
| 17 | |||
| 18 | #define BUF_SIZE 256 | ||
| 19 | #define FILL_CHAR '$' | ||
| 20 | |||
| 21 | #define PTR1 ((void*)0x01234567) | ||
| 22 | #define PTR2 ((void*)(long)(int)0xfedcba98) | ||
| 23 | |||
| 24 | #if BITS_PER_LONG == 64 | ||
| 25 | #define PTR1_ZEROES "000000000" | ||
| 26 | #define PTR1_SPACES " " | ||
| 27 | #define PTR1_STR "1234567" | ||
| 28 | #define PTR2_STR "fffffffffedcba98" | ||
| 29 | #define PTR_WIDTH 16 | ||
| 30 | #else | ||
| 31 | #define PTR1_ZEROES "0" | ||
| 32 | #define PTR1_SPACES " " | ||
| 33 | #define PTR1_STR "1234567" | ||
| 34 | #define PTR2_STR "fedcba98" | ||
| 35 | #define PTR_WIDTH 8 | ||
| 36 | #endif | ||
| 37 | #define PTR_WIDTH_STR stringify(PTR_WIDTH) | ||
| 38 | |||
| 39 | static unsigned total_tests __initdata; | ||
| 40 | static unsigned failed_tests __initdata; | ||
| 41 | static char *test_buffer __initdata; | ||
| 42 | |||
| 43 | static int __printf(4, 0) __init | ||
| 44 | do_test(int bufsize, const char *expect, int elen, | ||
| 45 | const char *fmt, va_list ap) | ||
| 46 | { | ||
| 47 | va_list aq; | ||
| 48 | int ret, written; | ||
| 49 | |||
| 50 | total_tests++; | ||
| 51 | |||
| 52 | memset(test_buffer, FILL_CHAR, BUF_SIZE); | ||
| 53 | va_copy(aq, ap); | ||
| 54 | ret = vsnprintf(test_buffer, bufsize, fmt, aq); | ||
| 55 | va_end(aq); | ||
| 56 | |||
| 57 | if (ret != elen) { | ||
| 58 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n", | ||
| 59 | bufsize, fmt, ret, elen); | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | |||
| 63 | if (!bufsize) { | ||
| 64 | if (memchr_inv(test_buffer, FILL_CHAR, BUF_SIZE)) { | ||
| 65 | pr_warn("vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n", | ||
| 66 | fmt); | ||
| 67 | return 1; | ||
| 68 | } | ||
| 69 | return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | written = min(bufsize-1, elen); | ||
| 73 | if (test_buffer[written]) { | ||
| 74 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n", | ||
| 75 | bufsize, fmt); | ||
| 76 | return 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | if (memcmp(test_buffer, expect, written)) { | ||
| 80 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n", | ||
| 81 | bufsize, fmt, test_buffer, written, expect); | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | static void __printf(3, 4) __init | ||
| 88 | __test(const char *expect, int elen, const char *fmt, ...) | ||
| 89 | { | ||
| 90 | va_list ap; | ||
| 91 | int rand; | ||
| 92 | char *p; | ||
| 93 | |||
| 94 | BUG_ON(elen >= BUF_SIZE); | ||
| 95 | |||
| 96 | va_start(ap, fmt); | ||
| 97 | |||
| 98 | /* | ||
| 99 | * Every fmt+args is subjected to four tests: Three where we | ||
| 100 | * tell vsnprintf varying buffer sizes (plenty, not quite | ||
| 101 | * enough and 0), and then we also test that kvasprintf would | ||
| 102 | * be able to print it as expected. | ||
| 103 | */ | ||
| 104 | failed_tests += do_test(BUF_SIZE, expect, elen, fmt, ap); | ||
| 105 | rand = 1 + prandom_u32_max(elen+1); | ||
| 106 | /* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */ | ||
| 107 | failed_tests += do_test(rand, expect, elen, fmt, ap); | ||
| 108 | failed_tests += do_test(0, expect, elen, fmt, ap); | ||
| 109 | |||
| 110 | p = kvasprintf(GFP_KERNEL, fmt, ap); | ||
| 111 | if (p) { | ||
| 112 | if (memcmp(p, expect, elen+1)) { | ||
| 113 | pr_warn("kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n", | ||
| 114 | fmt, p, expect); | ||
| 115 | failed_tests++; | ||
| 116 | } | ||
| 117 | kfree(p); | ||
| 118 | } | ||
| 119 | va_end(ap); | ||
| 120 | } | ||
| 121 | |||
| 122 | #define test(expect, fmt, ...) \ | ||
| 123 | __test(expect, strlen(expect), fmt, ##__VA_ARGS__) | ||
| 124 | |||
| 125 | static void __init | ||
| 126 | test_basic(void) | ||
| 127 | { | ||
| 128 | /* Work around annoying "warning: zero-length gnu_printf format string". */ | ||
| 129 | char nul = '\0'; | ||
| 130 | |||
| 131 | test("", &nul); | ||
| 132 | test("100%", "100%%"); | ||
| 133 | test("xxx%yyy", "xxx%cyyy", '%'); | ||
| 134 | __test("xxx\0yyy", 7, "xxx%cyyy", '\0'); | ||
| 135 | } | ||
| 136 | |||
| 137 | static void __init | ||
| 138 | test_number(void) | ||
| 139 | { | ||
| 140 | test("0x1234abcd ", "%#-12x", 0x1234abcd); | ||
| 141 | test(" 0x1234abcd", "%#12x", 0x1234abcd); | ||
| 142 | test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234); | ||
| 143 | } | ||
| 144 | |||
| 145 | static void __init | ||
| 146 | test_string(void) | ||
| 147 | { | ||
| 148 | test("", "%s%.0s", "", "123"); | ||
| 149 | test("ABCD|abc|123", "%s|%.3s|%.*s", "ABCD", "abcdef", 3, "123456"); | ||
| 150 | test("1 | 2|3 | 4|5 ", "%-3s|%3s|%-*s|%*s|%*s", "1", "2", 3, "3", 3, "4", -3, "5"); | ||
| 151 | /* | ||
| 152 | * POSIX and C99 say that a missing precision should be | ||
| 153 | * treated as a precision of 0. However, the kernel's printf | ||
| 154 | * implementation treats this case as if the . wasn't | ||
| 155 | * present. Let's add a test case documenting the current | ||
| 156 | * behaviour; should anyone ever feel the need to follow the | ||
| 157 | * standards more closely, this can be revisited. | ||
| 158 | */ | ||
| 159 | test("a||", "%.s|%.0s|%.*s", "a", "b", 0, "c"); | ||
| 160 | test("a | | ", "%-3.s|%-3.0s|%-3.*s", "a", "b", 0, "c"); | ||
| 161 | } | ||
| 162 | |||
| 163 | static void __init | ||
| 164 | plain(void) | ||
| 165 | { | ||
| 166 | test(PTR1_ZEROES PTR1_STR " " PTR2_STR, "%p %p", PTR1, PTR2); | ||
| 167 | /* | ||
| 168 | * The field width is overloaded for some %p extensions to | ||
| 169 | * pass another piece of information. For plain pointers, the | ||
| 170 | * behaviour is slightly odd: One cannot pass either the 0 | ||
| 171 | * flag nor a precision to %p without gcc complaining, and if | ||
| 172 | * one explicitly gives a field width, the number is no longer | ||
| 173 | * zero-padded. | ||
| 174 | */ | ||
| 175 | test("|" PTR1_STR PTR1_SPACES " | " PTR1_SPACES PTR1_STR "|", | ||
| 176 | "|%-*p|%*p|", PTR_WIDTH+2, PTR1, PTR_WIDTH+2, PTR1); | ||
| 177 | test("|" PTR2_STR " | " PTR2_STR "|", | ||
| 178 | "|%-*p|%*p|", PTR_WIDTH+2, PTR2, PTR_WIDTH+2, PTR2); | ||
| 179 | |||
| 180 | /* | ||
| 181 | * Unrecognized %p extensions are treated as plain %p, but the | ||
| 182 | * alphanumeric suffix is ignored (that is, does not occur in | ||
| 183 | * the output.) | ||
| 184 | */ | ||
| 185 | test("|"PTR1_ZEROES PTR1_STR"|", "|%p0y|", PTR1); | ||
| 186 | test("|"PTR2_STR"|", "|%p0y|", PTR2); | ||
| 187 | } | ||
| 188 | |||
| 189 | static void __init | ||
| 190 | symbol_ptr(void) | ||
| 191 | { | ||
| 192 | } | ||
| 193 | |||
| 194 | static void __init | ||
| 195 | kernel_ptr(void) | ||
| 196 | { | ||
| 197 | } | ||
| 198 | |||
| 199 | static void __init | ||
| 200 | struct_resource(void) | ||
| 201 | { | ||
| 202 | } | ||
| 203 | |||
| 204 | static void __init | ||
| 205 | addr(void) | ||
| 206 | { | ||
| 207 | } | ||
| 208 | |||
| 209 | static void __init | ||
| 210 | escaped_str(void) | ||
| 211 | { | ||
| 212 | } | ||
| 213 | |||
| 214 | static void __init | ||
| 215 | hex_string(void) | ||
| 216 | { | ||
| 217 | const char buf[3] = {0xc0, 0xff, 0xee}; | ||
| 218 | |||
| 219 | test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee", | ||
| 220 | "%3ph|%3phC|%3phD|%3phN", buf, buf, buf, buf); | ||
| 221 | test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee", | ||
| 222 | "%*ph|%*phC|%*phD|%*phN", 3, buf, 3, buf, 3, buf, 3, buf); | ||
| 223 | } | ||
| 224 | |||
| 225 | static void __init | ||
| 226 | mac(void) | ||
| 227 | { | ||
| 228 | const u8 addr[6] = {0x2d, 0x48, 0xd6, 0xfc, 0x7a, 0x05}; | ||
| 229 | |||
| 230 | test("2d:48:d6:fc:7a:05", "%pM", addr); | ||
| 231 | test("05:7a:fc:d6:48:2d", "%pMR", addr); | ||
| 232 | test("2d-48-d6-fc-7a-05", "%pMF", addr); | ||
| 233 | test("2d48d6fc7a05", "%pm", addr); | ||
| 234 | test("057afcd6482d", "%pmR", addr); | ||
| 235 | } | ||
| 236 | |||
| 237 | static void __init | ||
| 238 | ip4(void) | ||
| 239 | { | ||
| 240 | struct sockaddr_in sa; | ||
| 241 | |||
| 242 | sa.sin_family = AF_INET; | ||
| 243 | sa.sin_port = cpu_to_be16(12345); | ||
| 244 | sa.sin_addr.s_addr = cpu_to_be32(0x7f000001); | ||
| 245 | |||
| 246 | test("127.000.000.001|127.0.0.1", "%pi4|%pI4", &sa.sin_addr, &sa.sin_addr); | ||
| 247 | test("127.000.000.001|127.0.0.1", "%piS|%pIS", &sa, &sa); | ||
| 248 | sa.sin_addr.s_addr = cpu_to_be32(0x01020304); | ||
| 249 | test("001.002.003.004:12345|1.2.3.4:12345", "%piSp|%pISp", &sa, &sa); | ||
| 250 | } | ||
| 251 | |||
| 252 | static void __init | ||
| 253 | ip6(void) | ||
| 254 | { | ||
| 255 | } | ||
| 256 | |||
| 257 | static void __init | ||
| 258 | ip(void) | ||
| 259 | { | ||
| 260 | ip4(); | ||
| 261 | ip6(); | ||
| 262 | } | ||
| 263 | |||
| 264 | static void __init | ||
| 265 | uuid(void) | ||
| 266 | { | ||
| 267 | const char uuid[16] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, | ||
| 268 | 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}; | ||
| 269 | |||
| 270 | test("00010203-0405-0607-0809-0a0b0c0d0e0f", "%pUb", uuid); | ||
| 271 | test("00010203-0405-0607-0809-0A0B0C0D0E0F", "%pUB", uuid); | ||
| 272 | test("03020100-0504-0706-0809-0a0b0c0d0e0f", "%pUl", uuid); | ||
| 273 | test("03020100-0504-0706-0809-0A0B0C0D0E0F", "%pUL", uuid); | ||
| 274 | } | ||
| 275 | |||
| 276 | static void __init | ||
| 277 | dentry(void) | ||
| 278 | { | ||
| 279 | } | ||
| 280 | |||
| 281 | static void __init | ||
| 282 | struct_va_format(void) | ||
| 283 | { | ||
| 284 | } | ||
| 285 | |||
| 286 | static void __init | ||
| 287 | struct_clk(void) | ||
| 288 | { | ||
| 289 | } | ||
| 290 | |||
| 291 | static void __init | ||
| 292 | bitmap(void) | ||
| 293 | { | ||
| 294 | DECLARE_BITMAP(bits, 20); | ||
| 295 | const int primes[] = {2,3,5,7,11,13,17,19}; | ||
| 296 | int i; | ||
| 297 | |||
| 298 | bitmap_zero(bits, 20); | ||
| 299 | test("00000|00000", "%20pb|%*pb", bits, 20, bits); | ||
| 300 | test("|", "%20pbl|%*pbl", bits, 20, bits); | ||
| 301 | |||
| 302 | for (i = 0; i < ARRAY_SIZE(primes); ++i) | ||
| 303 | set_bit(primes[i], bits); | ||
| 304 | test("a28ac|a28ac", "%20pb|%*pb", bits, 20, bits); | ||
| 305 | test("2-3,5,7,11,13,17,19|2-3,5,7,11,13,17,19", "%20pbl|%*pbl", bits, 20, bits); | ||
| 306 | |||
| 307 | bitmap_fill(bits, 20); | ||
| 308 | test("fffff|fffff", "%20pb|%*pb", bits, 20, bits); | ||
| 309 | test("0-19|0-19", "%20pbl|%*pbl", bits, 20, bits); | ||
| 310 | } | ||
| 311 | |||
| 312 | static void __init | ||
| 313 | netdev_features(void) | ||
| 314 | { | ||
| 315 | } | ||
| 316 | |||
| 317 | static void __init | ||
| 318 | test_pointer(void) | ||
| 319 | { | ||
| 320 | plain(); | ||
| 321 | symbol_ptr(); | ||
| 322 | kernel_ptr(); | ||
| 323 | struct_resource(); | ||
| 324 | addr(); | ||
| 325 | escaped_str(); | ||
| 326 | hex_string(); | ||
| 327 | mac(); | ||
| 328 | ip(); | ||
| 329 | uuid(); | ||
| 330 | dentry(); | ||
| 331 | struct_va_format(); | ||
| 332 | struct_clk(); | ||
| 333 | bitmap(); | ||
| 334 | netdev_features(); | ||
| 335 | } | ||
| 336 | |||
| 337 | static int __init | ||
| 338 | test_printf_init(void) | ||
| 339 | { | ||
| 340 | test_buffer = kmalloc(BUF_SIZE, GFP_KERNEL); | ||
| 341 | if (!test_buffer) | ||
| 342 | return -ENOMEM; | ||
| 343 | |||
| 344 | test_basic(); | ||
| 345 | test_number(); | ||
| 346 | test_string(); | ||
| 347 | test_pointer(); | ||
| 348 | |||
| 349 | kfree(test_buffer); | ||
| 350 | |||
| 351 | if (failed_tests == 0) | ||
| 352 | pr_info("all %u tests passed\n", total_tests); | ||
| 353 | else | ||
| 354 | pr_warn("failed %u out of %u tests\n", failed_tests, total_tests); | ||
| 355 | |||
| 356 | return failed_tests ? -EINVAL : 0; | ||
| 357 | } | ||
| 358 | |||
| 359 | module_init(test_printf_init); | ||
| 360 | |||
| 361 | MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>"); | ||
| 362 | MODULE_LICENSE("GPL"); | ||
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 95cd63b43b99..f9cee8e1233c 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
| @@ -1449,6 +1449,8 @@ int kptr_restrict __read_mostly; | |||
| 1449 | * (legacy clock framework) of the clock | 1449 | * (legacy clock framework) of the clock |
| 1450 | * - 'Cr' For a clock, it prints the current rate of the clock | 1450 | * - 'Cr' For a clock, it prints the current rate of the clock |
| 1451 | * | 1451 | * |
| 1452 | * ** Please update also Documentation/printk-formats.txt when making changes ** | ||
| 1453 | * | ||
| 1452 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 1454 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
| 1453 | * function pointers are really function descriptors, which contain a | 1455 | * function pointers are really function descriptors, which contain a |
| 1454 | * pointer to the real address. | 1456 | * pointer to the real address. |
| @@ -1457,7 +1459,7 @@ static noinline_for_stack | |||
| 1457 | char *pointer(const char *fmt, char *buf, char *end, void *ptr, | 1459 | char *pointer(const char *fmt, char *buf, char *end, void *ptr, |
| 1458 | struct printf_spec spec) | 1460 | struct printf_spec spec) |
| 1459 | { | 1461 | { |
| 1460 | int default_width = 2 * sizeof(void *) + (spec.flags & SPECIAL ? 2 : 0); | 1462 | const int default_width = 2 * sizeof(void *); |
| 1461 | 1463 | ||
| 1462 | if (!ptr && *fmt != 'K') { | 1464 | if (!ptr && *fmt != 'K') { |
| 1463 | /* | 1465 | /* |
| @@ -1769,14 +1771,14 @@ qualifier: | |||
| 1769 | 1771 | ||
| 1770 | case 'n': | 1772 | case 'n': |
| 1771 | /* | 1773 | /* |
| 1772 | * Since %n poses a greater security risk than utility, treat | 1774 | * Since %n poses a greater security risk than |
| 1773 | * it as an invalid format specifier. Warn about its use so | 1775 | * utility, treat it as any other invalid or |
| 1774 | * that new instances don't get added. | 1776 | * unsupported format specifier. |
| 1775 | */ | 1777 | */ |
| 1776 | WARN_ONCE(1, "Please remove ignored %%n in '%s'\n", fmt); | ||
| 1777 | /* Fall-through */ | 1778 | /* Fall-through */ |
| 1778 | 1779 | ||
| 1779 | default: | 1780 | default: |
| 1781 | WARN_ONCE(1, "Please remove unsupported %%%c in format string\n", *fmt); | ||
| 1780 | spec->type = FORMAT_TYPE_INVALID; | 1782 | spec->type = FORMAT_TYPE_INVALID; |
| 1781 | return fmt - start; | 1783 | return fmt - start; |
| 1782 | } | 1784 | } |
| @@ -1811,41 +1813,16 @@ qualifier: | |||
| 1811 | * @fmt: The format string to use | 1813 | * @fmt: The format string to use |
| 1812 | * @args: Arguments for the format string | 1814 | * @args: Arguments for the format string |
| 1813 | * | 1815 | * |
| 1814 | * This function follows C99 vsnprintf, but has some extensions: | 1816 | * This function generally follows C99 vsnprintf, but has some |
| 1815 | * %pS output the name of a text symbol with offset | 1817 | * extensions and a few limitations: |
| 1816 | * %ps output the name of a text symbol without offset | 1818 | * |
| 1817 | * %pF output the name of a function pointer with its offset | 1819 | * %n is unsupported |
| 1818 | * %pf output the name of a function pointer without its offset | 1820 | * %p* is handled by pointer() |
| 1819 | * %pB output the name of a backtrace symbol with its offset | ||
| 1820 | * %pR output the address range in a struct resource with decoded flags | ||
| 1821 | * %pr output the address range in a struct resource with raw flags | ||
| 1822 | * %pb output the bitmap with field width as the number of bits | ||
| 1823 | * %pbl output the bitmap as range list with field width as the number of bits | ||
| 1824 | * %pM output a 6-byte MAC address with colons | ||
| 1825 | * %pMR output a 6-byte MAC address with colons in reversed order | ||
| 1826 | * %pMF output a 6-byte MAC address with dashes | ||
| 1827 | * %pm output a 6-byte MAC address without colons | ||
| 1828 | * %pmR output a 6-byte MAC address without colons in reversed order | ||
| 1829 | * %pI4 print an IPv4 address without leading zeros | ||
| 1830 | * %pi4 print an IPv4 address with leading zeros | ||
| 1831 | * %pI6 print an IPv6 address with colons | ||
| 1832 | * %pi6 print an IPv6 address without colons | ||
| 1833 | * %pI6c print an IPv6 address as specified by RFC 5952 | ||
| 1834 | * %pIS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address | ||
| 1835 | * %piS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address | ||
| 1836 | * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper | ||
| 1837 | * case. | ||
| 1838 | * %*pE[achnops] print an escaped buffer | ||
| 1839 | * %*ph[CDN] a variable-length hex string with a separator (supports up to 64 | ||
| 1840 | * bytes of the input) | ||
| 1841 | * %pC output the name (Common Clock Framework) or address (legacy clock | ||
| 1842 | * framework) of a clock | ||
| 1843 | * %pCn output the name (Common Clock Framework) or address (legacy clock | ||
| 1844 | * framework) of a clock | ||
| 1845 | * %pCr output the current rate of a clock | ||
| 1846 | * %n is ignored | ||
| 1847 | * | 1821 | * |
| 1848 | * ** Please update Documentation/printk-formats.txt when making changes ** | 1822 | * See pointer() or Documentation/printk-formats.txt for more |
| 1823 | * extensive description. | ||
| 1824 | * | ||
| 1825 | * ** Please update the documentation in both places when making changes ** | ||
| 1849 | * | 1826 | * |
| 1850 | * The return value is the number of characters which would | 1827 | * The return value is the number of characters which would |
| 1851 | * be generated for the given input, excluding the trailing | 1828 | * be generated for the given input, excluding the trailing |
| @@ -1944,10 +1921,15 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1944 | break; | 1921 | break; |
| 1945 | 1922 | ||
| 1946 | case FORMAT_TYPE_INVALID: | 1923 | case FORMAT_TYPE_INVALID: |
| 1947 | if (str < end) | 1924 | /* |
| 1948 | *str = '%'; | 1925 | * Presumably the arguments passed gcc's type |
| 1949 | ++str; | 1926 | * checking, but there is no safe or sane way |
| 1950 | break; | 1927 | * for us to continue parsing the format and |
| 1928 | * fetching from the va_list; the remaining | ||
| 1929 | * specifiers and arguments would be out of | ||
| 1930 | * sync. | ||
| 1931 | */ | ||
| 1932 | goto out; | ||
| 1951 | 1933 | ||
| 1952 | default: | 1934 | default: |
| 1953 | switch (spec.type) { | 1935 | switch (spec.type) { |
| @@ -1992,6 +1974,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
| 1992 | } | 1974 | } |
| 1993 | } | 1975 | } |
| 1994 | 1976 | ||
| 1977 | out: | ||
| 1995 | if (size > 0) { | 1978 | if (size > 0) { |
| 1996 | if (str < end) | 1979 | if (str < end) |
| 1997 | *str = '\0'; | 1980 | *str = '\0'; |
| @@ -2189,9 +2172,10 @@ do { \ | |||
| 2189 | 2172 | ||
| 2190 | switch (spec.type) { | 2173 | switch (spec.type) { |
| 2191 | case FORMAT_TYPE_NONE: | 2174 | case FORMAT_TYPE_NONE: |
| 2192 | case FORMAT_TYPE_INVALID: | ||
| 2193 | case FORMAT_TYPE_PERCENT_CHAR: | 2175 | case FORMAT_TYPE_PERCENT_CHAR: |
| 2194 | break; | 2176 | break; |
| 2177 | case FORMAT_TYPE_INVALID: | ||
| 2178 | goto out; | ||
| 2195 | 2179 | ||
| 2196 | case FORMAT_TYPE_WIDTH: | 2180 | case FORMAT_TYPE_WIDTH: |
| 2197 | case FORMAT_TYPE_PRECISION: | 2181 | case FORMAT_TYPE_PRECISION: |
| @@ -2253,6 +2237,7 @@ do { \ | |||
| 2253 | } | 2237 | } |
| 2254 | } | 2238 | } |
| 2255 | 2239 | ||
| 2240 | out: | ||
| 2256 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | 2241 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; |
| 2257 | #undef save_arg | 2242 | #undef save_arg |
| 2258 | } | 2243 | } |
| @@ -2286,7 +2271,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 2286 | char *str, *end; | 2271 | char *str, *end; |
| 2287 | const char *args = (const char *)bin_buf; | 2272 | const char *args = (const char *)bin_buf; |
| 2288 | 2273 | ||
| 2289 | if (WARN_ON_ONCE((int) size < 0)) | 2274 | if (WARN_ON_ONCE(size > INT_MAX)) |
| 2290 | return 0; | 2275 | return 0; |
| 2291 | 2276 | ||
| 2292 | str = buf; | 2277 | str = buf; |
| @@ -2375,12 +2360,14 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 2375 | break; | 2360 | break; |
| 2376 | 2361 | ||
| 2377 | case FORMAT_TYPE_PERCENT_CHAR: | 2362 | case FORMAT_TYPE_PERCENT_CHAR: |
| 2378 | case FORMAT_TYPE_INVALID: | ||
| 2379 | if (str < end) | 2363 | if (str < end) |
| 2380 | *str = '%'; | 2364 | *str = '%'; |
| 2381 | ++str; | 2365 | ++str; |
| 2382 | break; | 2366 | break; |
| 2383 | 2367 | ||
| 2368 | case FORMAT_TYPE_INVALID: | ||
| 2369 | goto out; | ||
| 2370 | |||
| 2384 | default: { | 2371 | default: { |
| 2385 | unsigned long long num; | 2372 | unsigned long long num; |
| 2386 | 2373 | ||
| @@ -2423,6 +2410,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
| 2423 | } /* switch(spec.type) */ | 2410 | } /* switch(spec.type) */ |
| 2424 | } /* while(*fmt) */ | 2411 | } /* while(*fmt) */ |
| 2425 | 2412 | ||
| 2413 | out: | ||
| 2426 | if (size > 0) { | 2414 | if (size > 0) { |
| 2427 | if (str < end) | 2415 | if (str < end) |
| 2428 | *str = '\0'; | 2416 | *str = '\0'; |
