diff options
161 files changed, 4478 insertions, 799 deletions
diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt index 9f41d05be3be..f9463b492f44 100644 --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt | |||
| @@ -9,6 +9,7 @@ document for it just like any other devices. | |||
| 9 | 9 | ||
| 10 | Compatible Vendor / Chip | 10 | Compatible Vendor / Chip |
| 11 | ========== ============= | 11 | ========== ============= |
| 12 | abracon,abb5zes3 AB-RTCMC-32.768kHz-B5ZE-S3: Real Time Clock/Calendar Module with I2C Interface | ||
| 12 | ad,ad7414 SMBus/I2C Digital Temperature Sensor in 6-Pin SOT with SMBus Alert and Over Temperature Pin | 13 | ad,ad7414 SMBus/I2C Digital Temperature Sensor in 6-Pin SOT with SMBus Alert and Over Temperature Pin |
| 13 | ad,adm9240 ADM9240: Complete System Hardware Monitor for uProcessor-Based Systems | 14 | ad,adm9240 ADM9240: Complete System Hardware Monitor for uProcessor-Based Systems |
| 14 | adi,adt7461 +/-1C TDM Extended Temp Range I.C | 15 | adi,adt7461 +/-1C TDM Extended Temp Range I.C |
diff --git a/Documentation/devicetree/bindings/rtc/armada-380-rtc.txt b/Documentation/devicetree/bindings/rtc/armada-380-rtc.txt new file mode 100644 index 000000000000..2eb9d4ee7dc0 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/armada-380-rtc.txt | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | * Real Time Clock of the Armada 38x SoCs | ||
| 2 | |||
| 3 | RTC controller for the Armada 38x SoCs | ||
| 4 | |||
| 5 | Required properties: | ||
| 6 | - compatible : Should be "marvell,armada-380-rtc" | ||
| 7 | - reg: a list of base address and size pairs, one for each entry in | ||
| 8 | reg-names | ||
| 9 | - reg names: should contain: | ||
| 10 | * "rtc" for the RTC registers | ||
| 11 | * "rtc-soc" for the SoC related registers and among them the one | ||
| 12 | related to the interrupt. | ||
| 13 | - interrupts: IRQ line for the RTC. | ||
| 14 | |||
| 15 | Example: | ||
| 16 | |||
| 17 | rtc@a3800 { | ||
| 18 | compatible = "marvell,armada-380-rtc"; | ||
| 19 | reg = <0xa3800 0x20>, <0x184a0 0x0c>; | ||
| 20 | reg-names = "rtc", "rtc-soc"; | ||
| 21 | interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>; | ||
| 22 | }; | ||
diff --git a/Documentation/devicetree/bindings/rtc/isil,isl12057.txt b/Documentation/devicetree/bindings/rtc/isil,isl12057.txt new file mode 100644 index 000000000000..501c39ceae79 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/isil,isl12057.txt | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | Intersil ISL12057 I2C RTC/Alarm chip | ||
| 2 | |||
| 3 | ISL12057 is a trivial I2C device (it has simple device tree bindings, | ||
| 4 | consisting of a compatible field, an address and possibly an interrupt | ||
| 5 | line). | ||
| 6 | |||
| 7 | Nonetheless, it also supports an option boolean property | ||
| 8 | ("isil,irq2-can-wakeup-machine") to handle the specific use-case found | ||
| 9 | on at least three in-tree users of the chip (NETGEAR ReadyNAS 102, 104 | ||
| 10 | and 2120 ARM-based NAS); On those devices, the IRQ#2 pin of the chip | ||
| 11 | (associated with the alarm supported by the driver) is not connected | ||
| 12 | to the SoC but to a PMIC. It allows the device to be powered up when | ||
| 13 | RTC alarm rings. In order to mark the device has a wakeup source and | ||
| 14 | get access to the 'wakealarm' sysfs entry, this specific property can | ||
| 15 | be set when the IRQ#2 pin of the chip is not connected to the SoC but | ||
| 16 | can wake up the device. | ||
| 17 | |||
| 18 | Required properties supported by the device: | ||
| 19 | |||
| 20 | - "compatible": must be "isil,isl12057" | ||
| 21 | - "reg": I2C bus address of the device | ||
| 22 | |||
| 23 | Optional properties: | ||
| 24 | |||
| 25 | - "isil,irq2-can-wakeup-machine": mark the chip as a wakeup source, | ||
| 26 | independently of the availability of an IRQ line connected to the | ||
| 27 | SoC. | ||
| 28 | |||
| 29 | - "interrupt-parent", "interrupts": for passing the interrupt line | ||
| 30 | of the SoC connected to IRQ#2 of the RTC chip. | ||
| 31 | |||
| 32 | |||
| 33 | Example isl12057 node without IRQ#2 pin connected (no alarm support): | ||
| 34 | |||
| 35 | isl12057: isl12057@68 { | ||
| 36 | compatible = "isil,isl12057"; | ||
| 37 | reg = <0x68>; | ||
| 38 | }; | ||
| 39 | |||
| 40 | |||
| 41 | Example isl12057 node with IRQ#2 pin connected to main SoC via MPP6 (note | ||
| 42 | that the pinctrl-related properties below are given for completeness and | ||
| 43 | may not be required or may be different depending on your system or | ||
| 44 | SoC, and the main function of the MPP used as IRQ line, i.e. | ||
| 45 | "interrupt-parent" and "interrupts" are usually sufficient): | ||
| 46 | |||
| 47 | pinctrl { | ||
| 48 | ... | ||
| 49 | |||
| 50 | rtc_alarm_pin: rtc_alarm_pin { | ||
| 51 | marvell,pins = "mpp6"; | ||
| 52 | marvell,function = "gpio"; | ||
| 53 | }; | ||
| 54 | |||
| 55 | ... | ||
| 56 | |||
| 57 | }; | ||
| 58 | |||
| 59 | ... | ||
| 60 | |||
| 61 | isl12057: isl12057@68 { | ||
| 62 | compatible = "isil,isl12057"; | ||
| 63 | reg = <0x68>; | ||
| 64 | pinctrl-0 = <&rtc_alarm_pin>; | ||
| 65 | pinctrl-names = "default"; | ||
| 66 | interrupt-parent = <&gpio0>; | ||
| 67 | interrupts = <6 IRQ_TYPE_EDGE_FALLING>; | ||
| 68 | }; | ||
| 69 | |||
| 70 | |||
| 71 | Example isl12057 node without IRQ#2 pin connected to the SoC but to a | ||
| 72 | PMIC, allowing the device to be started based on configured alarm: | ||
| 73 | |||
| 74 | isl12057: isl12057@68 { | ||
| 75 | compatible = "isil,isl12057"; | ||
| 76 | reg = <0x68>; | ||
| 77 | isil,irq2-can-wakeup-machine; | ||
| 78 | }; | ||
diff --git a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt new file mode 100644 index 000000000000..5cbc0b145a61 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | NXP PCF2123 SPI Real Time Clock | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: should be: "nxp,rtc-pcf2123" | ||
| 5 | - reg: should be the SPI slave chipselect address | ||
| 6 | |||
| 7 | Optional properties: | ||
| 8 | - spi-cs-high: PCF2123 needs chipselect high | ||
| 9 | |||
| 10 | Example: | ||
| 11 | |||
| 12 | rtc: nxp,rtc-pcf2123@3 { | ||
| 13 | compatible = "nxp,rtc-pcf2123" | ||
| 14 | reg = <3> | ||
| 15 | spi-cs-high; | ||
| 16 | }; | ||
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 7075698abd8c..797e6b024241 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt | |||
| @@ -4,6 +4,7 @@ This isn't an exhaustive list, but you should add new prefixes to it before | |||
| 4 | using them to avoid name-space collisions. | 4 | using them to avoid name-space collisions. |
| 5 | 5 | ||
| 6 | abilis Abilis Systems | 6 | abilis Abilis Systems |
| 7 | abcn Abracon Corporation | ||
| 7 | active-semi Active-Semi International Inc | 8 | active-semi Active-Semi International Inc |
| 8 | ad Avionic Design GmbH | 9 | ad Avionic Design GmbH |
| 9 | adapteva Adapteva, Inc. | 10 | adapteva Adapteva, Inc. |
diff --git a/Documentation/kasan.txt b/Documentation/kasan.txt new file mode 100644 index 000000000000..092fc10961fe --- /dev/null +++ b/Documentation/kasan.txt | |||
| @@ -0,0 +1,170 @@ | |||
| 1 | Kernel address sanitizer | ||
| 2 | ================ | ||
| 3 | |||
| 4 | 0. Overview | ||
| 5 | =========== | ||
| 6 | |||
| 7 | Kernel Address sanitizer (KASan) is a dynamic memory error detector. It provides | ||
| 8 | a fast and comprehensive solution for finding use-after-free and out-of-bounds | ||
| 9 | bugs. | ||
| 10 | |||
| 11 | KASan uses compile-time instrumentation for checking every memory access, | ||
| 12 | therefore you will need a certain version of GCC > 4.9.2 | ||
| 13 | |||
| 14 | Currently KASan is supported only for x86_64 architecture and requires that the | ||
| 15 | kernel be built with the SLUB allocator. | ||
| 16 | |||
| 17 | 1. Usage | ||
| 18 | ========= | ||
| 19 | |||
| 20 | To enable KASAN configure kernel with: | ||
| 21 | |||
| 22 | CONFIG_KASAN = y | ||
| 23 | |||
| 24 | and choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. Outline/inline | ||
| 25 | is compiler instrumentation types. The former produces smaller binary the | ||
| 26 | latter is 1.1 - 2 times faster. Inline instrumentation requires GCC 5.0 or | ||
| 27 | latter. | ||
| 28 | |||
| 29 | Currently KASAN works only with the SLUB memory allocator. | ||
| 30 | For better bug detection and nicer report, enable CONFIG_STACKTRACE and put | ||
| 31 | at least 'slub_debug=U' in the boot cmdline. | ||
| 32 | |||
| 33 | To disable instrumentation for specific files or directories, add a line | ||
| 34 | similar to the following to the respective kernel Makefile: | ||
| 35 | |||
| 36 | For a single file (e.g. main.o): | ||
| 37 | KASAN_SANITIZE_main.o := n | ||
| 38 | |||
| 39 | For all files in one directory: | ||
| 40 | KASAN_SANITIZE := n | ||
| 41 | |||
| 42 | 1.1 Error reports | ||
| 43 | ========== | ||
| 44 | |||
| 45 | A typical out of bounds access report looks like this: | ||
| 46 | |||
| 47 | ================================================================== | ||
| 48 | BUG: AddressSanitizer: out of bounds access in kmalloc_oob_right+0x65/0x75 [test_kasan] at addr ffff8800693bc5d3 | ||
| 49 | Write of size 1 by task modprobe/1689 | ||
| 50 | ============================================================================= | ||
| 51 | BUG kmalloc-128 (Not tainted): kasan error | ||
| 52 | ----------------------------------------------------------------------------- | ||
| 53 | |||
| 54 | Disabling lock debugging due to kernel taint | ||
| 55 | INFO: Allocated in kmalloc_oob_right+0x3d/0x75 [test_kasan] age=0 cpu=0 pid=1689 | ||
| 56 | __slab_alloc+0x4b4/0x4f0 | ||
| 57 | kmem_cache_alloc_trace+0x10b/0x190 | ||
| 58 | kmalloc_oob_right+0x3d/0x75 [test_kasan] | ||
| 59 | init_module+0x9/0x47 [test_kasan] | ||
| 60 | do_one_initcall+0x99/0x200 | ||
| 61 | load_module+0x2cb3/0x3b20 | ||
| 62 | SyS_finit_module+0x76/0x80 | ||
| 63 | system_call_fastpath+0x12/0x17 | ||
| 64 | INFO: Slab 0xffffea0001a4ef00 objects=17 used=7 fp=0xffff8800693bd728 flags=0x100000000004080 | ||
| 65 | INFO: Object 0xffff8800693bc558 @offset=1368 fp=0xffff8800693bc720 | ||
| 66 | |||
| 67 | Bytes b4 ffff8800693bc548: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ | ||
| 68 | Object ffff8800693bc558: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 69 | Object ffff8800693bc568: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 70 | Object ffff8800693bc578: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 71 | Object ffff8800693bc588: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 72 | Object ffff8800693bc598: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 73 | Object ffff8800693bc5a8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 74 | Object ffff8800693bc5b8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk | ||
| 75 | Object ffff8800693bc5c8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. | ||
| 76 | Redzone ffff8800693bc5d8: cc cc cc cc cc cc cc cc ........ | ||
| 77 | Padding ffff8800693bc718: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ | ||
| 78 | CPU: 0 PID: 1689 Comm: modprobe Tainted: G B 3.18.0-rc1-mm1+ #98 | ||
| 79 | Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014 | ||
| 80 | ffff8800693bc000 0000000000000000 ffff8800693bc558 ffff88006923bb78 | ||
| 81 | ffffffff81cc68ae 00000000000000f3 ffff88006d407600 ffff88006923bba8 | ||
| 82 | ffffffff811fd848 ffff88006d407600 ffffea0001a4ef00 ffff8800693bc558 | ||
| 83 | Call Trace: | ||
| 84 | [<ffffffff81cc68ae>] dump_stack+0x46/0x58 | ||
| 85 | [<ffffffff811fd848>] print_trailer+0xf8/0x160 | ||
| 86 | [<ffffffffa00026a7>] ? kmem_cache_oob+0xc3/0xc3 [test_kasan] | ||
| 87 | [<ffffffff811ff0f5>] object_err+0x35/0x40 | ||
| 88 | [<ffffffffa0002065>] ? kmalloc_oob_right+0x65/0x75 [test_kasan] | ||
| 89 | [<ffffffff8120b9fa>] kasan_report_error+0x38a/0x3f0 | ||
| 90 | [<ffffffff8120a79f>] ? kasan_poison_shadow+0x2f/0x40 | ||
| 91 | [<ffffffff8120b344>] ? kasan_unpoison_shadow+0x14/0x40 | ||
| 92 | [<ffffffff8120a79f>] ? kasan_poison_shadow+0x2f/0x40 | ||
| 93 | [<ffffffffa00026a7>] ? kmem_cache_oob+0xc3/0xc3 [test_kasan] | ||
| 94 | [<ffffffff8120a995>] __asan_store1+0x75/0xb0 | ||
| 95 | [<ffffffffa0002601>] ? kmem_cache_oob+0x1d/0xc3 [test_kasan] | ||
| 96 | [<ffffffffa0002065>] ? kmalloc_oob_right+0x65/0x75 [test_kasan] | ||
| 97 | [<ffffffffa0002065>] kmalloc_oob_right+0x65/0x75 [test_kasan] | ||
| 98 | [<ffffffffa00026b0>] init_module+0x9/0x47 [test_kasan] | ||
| 99 | [<ffffffff810002d9>] do_one_initcall+0x99/0x200 | ||
| 100 | [<ffffffff811e4e5c>] ? __vunmap+0xec/0x160 | ||
| 101 | [<ffffffff81114f63>] load_module+0x2cb3/0x3b20 | ||
| 102 | [<ffffffff8110fd70>] ? m_show+0x240/0x240 | ||
| 103 | [<ffffffff81115f06>] SyS_finit_module+0x76/0x80 | ||
| 104 | [<ffffffff81cd3129>] system_call_fastpath+0x12/0x17 | ||
| 105 | Memory state around the buggy address: | ||
| 106 | ffff8800693bc300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc | ||
| 107 | ffff8800693bc380: fc fc 00 00 00 00 00 00 00 00 00 00 00 00 00 fc | ||
| 108 | ffff8800693bc400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc | ||
| 109 | ffff8800693bc480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc | ||
| 110 | ffff8800693bc500: fc fc fc fc fc fc fc fc fc fc fc 00 00 00 00 00 | ||
| 111 | >ffff8800693bc580: 00 00 00 00 00 00 00 00 00 00 03 fc fc fc fc fc | ||
| 112 | ^ | ||
| 113 | ffff8800693bc600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc | ||
| 114 | ffff8800693bc680: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc | ||
| 115 | ffff8800693bc700: fc fc fc fc fb fb fb fb fb fb fb fb fb fb fb fb | ||
| 116 | ffff8800693bc780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb | ||
| 117 | ffff8800693bc800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb | ||
| 118 | ================================================================== | ||
| 119 | |||
| 120 | First sections describe slub object where bad access happened. | ||
| 121 | See 'SLUB Debug output' section in Documentation/vm/slub.txt for details. | ||
| 122 | |||
| 123 | In the last section the report shows memory state around the accessed address. | ||
| 124 | Reading this part requires some more understanding of how KASAN works. | ||
| 125 | |||
| 126 | Each 8 bytes of memory are encoded in one shadow byte as accessible, | ||
| 127 | partially accessible, freed or they can be part of a redzone. | ||
| 128 | We use the following encoding for each shadow byte: 0 means that all 8 bytes | ||
| 129 | of the corresponding memory region are accessible; number N (1 <= N <= 7) means | ||
| 130 | that the first N bytes are accessible, and other (8 - N) bytes are not; | ||
| 131 | any negative value indicates that the entire 8-byte word is inaccessible. | ||
| 132 | We use different negative values to distinguish between different kinds of | ||
| 133 | inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h). | ||
| 134 | |||
| 135 | In the report above the arrows point to the shadow byte 03, which means that | ||
| 136 | the accessed address is partially accessible. | ||
| 137 | |||
| 138 | |||
| 139 | 2. Implementation details | ||
| 140 | ======================== | ||
| 141 | |||
| 142 | From a high level, our approach to memory error detection is similar to that | ||
| 143 | of kmemcheck: use shadow memory to record whether each byte of memory is safe | ||
| 144 | to access, and use compile-time instrumentation to check shadow memory on each | ||
| 145 | memory access. | ||
| 146 | |||
| 147 | AddressSanitizer dedicates 1/8 of kernel memory to its shadow memory | ||
| 148 | (e.g. 16TB to cover 128TB on x86_64) and uses direct mapping with a scale and | ||
| 149 | offset to translate a memory address to its corresponding shadow address. | ||
| 150 | |||
| 151 | Here is the function witch translate an address to its corresponding shadow | ||
| 152 | address: | ||
| 153 | |||
| 154 | static inline void *kasan_mem_to_shadow(const void *addr) | ||
| 155 | { | ||
| 156 | return ((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) | ||
| 157 | + KASAN_SHADOW_OFFSET; | ||
| 158 | } | ||
| 159 | |||
| 160 | where KASAN_SHADOW_SCALE_SHIFT = 3. | ||
| 161 | |||
| 162 | Compile-time instrumentation used for checking memory accesses. Compiler inserts | ||
| 163 | function calls (__asan_load*(addr), __asan_store*(addr)) before each memory | ||
| 164 | access of size 1, 2, 4, 8 or 16. These functions check whether memory access is | ||
| 165 | valid or not by checking corresponding shadow memory. | ||
| 166 | |||
| 167 | GCC 5.0 has possibility to perform inline instrumentation. Instead of making | ||
| 168 | function calls GCC directly inserts the code to check the shadow memory. | ||
| 169 | This option significantly enlarges kernel but it gives x1.1-x2 performance | ||
| 170 | boost over outline instrumented kernel. | ||
diff --git a/Documentation/video4linux/v4l2-pci-skeleton.c b/Documentation/video4linux/v4l2-pci-skeleton.c index 006721e43b2a..7bd1b975bfd2 100644 --- a/Documentation/video4linux/v4l2-pci-skeleton.c +++ b/Documentation/video4linux/v4l2-pci-skeleton.c | |||
| @@ -42,7 +42,6 @@ | |||
| 42 | MODULE_DESCRIPTION("V4L2 PCI Skeleton Driver"); | 42 | MODULE_DESCRIPTION("V4L2 PCI Skeleton Driver"); |
| 43 | MODULE_AUTHOR("Hans Verkuil"); | 43 | MODULE_AUTHOR("Hans Verkuil"); |
| 44 | MODULE_LICENSE("GPL v2"); | 44 | MODULE_LICENSE("GPL v2"); |
| 45 | MODULE_DEVICE_TABLE(pci, skeleton_pci_tbl); | ||
| 46 | 45 | ||
| 47 | /** | 46 | /** |
| 48 | * struct skeleton - All internal data for one instance of device | 47 | * struct skeleton - All internal data for one instance of device |
| @@ -95,6 +94,7 @@ static const struct pci_device_id skeleton_pci_tbl[] = { | |||
| 95 | /* { PCI_DEVICE(PCI_VENDOR_ID_, PCI_DEVICE_ID_) }, */ | 94 | /* { PCI_DEVICE(PCI_VENDOR_ID_, PCI_DEVICE_ID_) }, */ |
| 96 | { 0, } | 95 | { 0, } |
| 97 | }; | 96 | }; |
| 97 | MODULE_DEVICE_TABLE(pci, skeleton_pci_tbl); | ||
| 98 | 98 | ||
| 99 | /* | 99 | /* |
| 100 | * HDTV: this structure has the capabilities of the HDTV receiver. | 100 | * HDTV: this structure has the capabilities of the HDTV receiver. |
diff --git a/Documentation/x86/x86_64/mm.txt b/Documentation/x86/x86_64/mm.txt index 052ee643a32e..05712ac83e38 100644 --- a/Documentation/x86/x86_64/mm.txt +++ b/Documentation/x86/x86_64/mm.txt | |||
| @@ -12,6 +12,8 @@ ffffc90000000000 - ffffe8ffffffffff (=45 bits) vmalloc/ioremap space | |||
| 12 | ffffe90000000000 - ffffe9ffffffffff (=40 bits) hole | 12 | ffffe90000000000 - ffffe9ffffffffff (=40 bits) hole |
| 13 | ffffea0000000000 - ffffeaffffffffff (=40 bits) virtual memory map (1TB) | 13 | ffffea0000000000 - ffffeaffffffffff (=40 bits) virtual memory map (1TB) |
| 14 | ... unused hole ... | 14 | ... unused hole ... |
| 15 | ffffec0000000000 - fffffc0000000000 (=44 bits) kasan shadow memory (16TB) | ||
| 16 | ... unused hole ... | ||
| 15 | ffffff0000000000 - ffffff7fffffffff (=39 bits) %esp fixup stacks | 17 | ffffff0000000000 - ffffff7fffffffff (=39 bits) %esp fixup stacks |
| 16 | ... unused hole ... | 18 | ... unused hole ... |
| 17 | ffffffff80000000 - ffffffffa0000000 (=512 MB) kernel text mapping, from phys 0 | 19 | ffffffff80000000 - ffffffffa0000000 (=512 MB) kernel text mapping, from phys 0 |
diff --git a/MAINTAINERS b/MAINTAINERS index debe74cde67b..cd8383e26ac8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -1173,6 +1173,7 @@ M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> | |||
| 1173 | L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) | 1173 | L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) |
| 1174 | S: Maintained | 1174 | S: Maintained |
| 1175 | F: arch/arm/mach-mvebu/ | 1175 | F: arch/arm/mach-mvebu/ |
| 1176 | F: drivers/rtc/armada38x-rtc | ||
| 1176 | 1177 | ||
| 1177 | ARM/Marvell Berlin SoC support | 1178 | ARM/Marvell Berlin SoC support |
| 1178 | M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> | 1179 | M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> |
| @@ -423,7 +423,7 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE | |||
| 423 | export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS | 423 | export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS |
| 424 | 424 | ||
| 425 | export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS | 425 | export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS |
| 426 | export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV | 426 | export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KASAN |
| 427 | export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE | 427 | export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE |
| 428 | export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE | 428 | export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE |
| 429 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL | 429 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL |
| @@ -781,6 +781,7 @@ ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y) | |||
| 781 | KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO | 781 | KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO |
| 782 | endif | 782 | endif |
| 783 | 783 | ||
| 784 | include $(srctree)/scripts/Makefile.kasan | ||
| 784 | include $(srctree)/scripts/Makefile.extrawarn | 785 | include $(srctree)/scripts/Makefile.extrawarn |
| 785 | 786 | ||
| 786 | # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments | 787 | # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments |
diff --git a/arch/arm/boot/dts/armada-370-netgear-rn102.dts b/arch/arm/boot/dts/armada-370-netgear-rn102.dts index 4e24932c6e30..1c83b7ce0982 100644 --- a/arch/arm/boot/dts/armada-370-netgear-rn102.dts +++ b/arch/arm/boot/dts/armada-370-netgear-rn102.dts | |||
| @@ -87,6 +87,7 @@ | |||
| 87 | isl12057: isl12057@68 { | 87 | isl12057: isl12057@68 { |
| 88 | compatible = "isil,isl12057"; | 88 | compatible = "isil,isl12057"; |
| 89 | reg = <0x68>; | 89 | reg = <0x68>; |
| 90 | isil,irq2-can-wakeup-machine; | ||
| 90 | }; | 91 | }; |
| 91 | 92 | ||
| 92 | g762: g762@3e { | 93 | g762: g762@3e { |
diff --git a/arch/arm/boot/dts/armada-370-netgear-rn104.dts b/arch/arm/boot/dts/armada-370-netgear-rn104.dts index 30586e47986a..5fbfe02964dc 100644 --- a/arch/arm/boot/dts/armada-370-netgear-rn104.dts +++ b/arch/arm/boot/dts/armada-370-netgear-rn104.dts | |||
| @@ -93,6 +93,7 @@ | |||
| 93 | isl12057: isl12057@68 { | 93 | isl12057: isl12057@68 { |
| 94 | compatible = "isil,isl12057"; | 94 | compatible = "isil,isl12057"; |
| 95 | reg = <0x68>; | 95 | reg = <0x68>; |
| 96 | isil,irq2-can-wakeup-machine; | ||
| 96 | }; | 97 | }; |
| 97 | 98 | ||
| 98 | g762: g762@3e { | 99 | g762: g762@3e { |
diff --git a/arch/arm/boot/dts/armada-38x.dtsi b/arch/arm/boot/dts/armada-38x.dtsi index 74391dace9e7..2a9f4caac643 100644 --- a/arch/arm/boot/dts/armada-38x.dtsi +++ b/arch/arm/boot/dts/armada-38x.dtsi | |||
| @@ -381,6 +381,13 @@ | |||
| 381 | clocks = <&gateclk 4>; | 381 | clocks = <&gateclk 4>; |
| 382 | }; | 382 | }; |
| 383 | 383 | ||
| 384 | rtc@a3800 { | ||
| 385 | compatible = "marvell,armada-380-rtc"; | ||
| 386 | reg = <0xa3800 0x20>, <0x184a0 0x0c>; | ||
| 387 | reg-names = "rtc", "rtc-soc"; | ||
| 388 | interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>; | ||
| 389 | }; | ||
| 390 | |||
| 384 | sata@a8000 { | 391 | sata@a8000 { |
| 385 | compatible = "marvell,armada-380-ahci"; | 392 | compatible = "marvell,armada-380-ahci"; |
| 386 | reg = <0xa8000 0x2000>; | 393 | reg = <0xa8000 0x2000>; |
diff --git a/arch/arm/boot/dts/armada-xp-netgear-rn2120.dts b/arch/arm/boot/dts/armada-xp-netgear-rn2120.dts index d81430aa4ab3..fc8bdfcd2348 100644 --- a/arch/arm/boot/dts/armada-xp-netgear-rn2120.dts +++ b/arch/arm/boot/dts/armada-xp-netgear-rn2120.dts | |||
| @@ -100,6 +100,7 @@ | |||
| 100 | isl12057: isl12057@68 { | 100 | isl12057: isl12057@68 { |
| 101 | compatible = "isil,isl12057"; | 101 | compatible = "isil,isl12057"; |
| 102 | reg = <0x68>; | 102 | reg = <0x68>; |
| 103 | isil,irq2-can-wakeup-machine; | ||
| 103 | }; | 104 | }; |
| 104 | 105 | ||
| 105 | /* Controller for rear fan #1 of 3 (Protechnic | 106 | /* Controller for rear fan #1 of 3 (Protechnic |
diff --git a/arch/arm/configs/mvebu_v7_defconfig b/arch/arm/configs/mvebu_v7_defconfig index 627accea72fb..2400b9f52403 100644 --- a/arch/arm/configs/mvebu_v7_defconfig +++ b/arch/arm/configs/mvebu_v7_defconfig | |||
| @@ -112,6 +112,7 @@ CONFIG_LEDS_TRIGGER_HEARTBEAT=y | |||
| 112 | CONFIG_RTC_CLASS=y | 112 | CONFIG_RTC_CLASS=y |
| 113 | CONFIG_RTC_DRV_S35390A=y | 113 | CONFIG_RTC_DRV_S35390A=y |
| 114 | CONFIG_RTC_DRV_MV=y | 114 | CONFIG_RTC_DRV_MV=y |
| 115 | CONFIG_RTC_DRV_ARMADA38X=y | ||
| 115 | CONFIG_DMADEVICES=y | 116 | CONFIG_DMADEVICES=y |
| 116 | CONFIG_MV_XOR=y | 117 | CONFIG_MV_XOR=y |
| 117 | # CONFIG_IOMMU_SUPPORT is not set | 118 | # CONFIG_IOMMU_SUPPORT is not set |
diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index bea7db9e5b80..2e11961f65ae 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c | |||
| @@ -41,7 +41,7 @@ | |||
| 41 | void *module_alloc(unsigned long size) | 41 | void *module_alloc(unsigned long size) |
| 42 | { | 42 | { |
| 43 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, | 43 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, |
| 44 | GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE, | 44 | GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, |
| 45 | __builtin_return_address(0)); | 45 | __builtin_return_address(0)); |
| 46 | } | 46 | } |
| 47 | #endif | 47 | #endif |
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index 9b6f71db2709..67bf4107f6ef 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c | |||
| @@ -35,8 +35,8 @@ | |||
| 35 | void *module_alloc(unsigned long size) | 35 | void *module_alloc(unsigned long size) |
| 36 | { | 36 | { |
| 37 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, | 37 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, |
| 38 | GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE, | 38 | GFP_KERNEL, PAGE_KERNEL_EXEC, 0, |
| 39 | __builtin_return_address(0)); | 39 | NUMA_NO_NODE, __builtin_return_address(0)); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | enum aarch64_reloc_op { | 42 | enum aarch64_reloc_op { |
diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c index f295f9abba4b..965ab42fabb0 100644 --- a/arch/ia64/kernel/topology.c +++ b/arch/ia64/kernel/topology.c | |||
| @@ -217,14 +217,12 @@ static ssize_t show_number_of_sets(struct cache_info *this_leaf, char *buf) | |||
| 217 | 217 | ||
| 218 | static ssize_t show_shared_cpu_map(struct cache_info *this_leaf, char *buf) | 218 | static ssize_t show_shared_cpu_map(struct cache_info *this_leaf, char *buf) |
| 219 | { | 219 | { |
| 220 | ssize_t len; | ||
| 221 | cpumask_t shared_cpu_map; | 220 | cpumask_t shared_cpu_map; |
| 222 | 221 | ||
| 223 | cpumask_and(&shared_cpu_map, | 222 | cpumask_and(&shared_cpu_map, |
| 224 | &this_leaf->shared_cpu_map, cpu_online_mask); | 223 | &this_leaf->shared_cpu_map, cpu_online_mask); |
| 225 | len = cpumask_scnprintf(buf, NR_CPUS+1, &shared_cpu_map); | 224 | return scnprintf(buf, PAGE_SIZE, "%*pb\n", |
| 226 | len += sprintf(buf+len, "\n"); | 225 | cpumask_pr_args(&shared_cpu_map)); |
| 227 | return len; | ||
| 228 | } | 226 | } |
| 229 | 227 | ||
| 230 | static ssize_t show_type(struct cache_info *this_leaf, char *buf) | 228 | static ssize_t show_type(struct cache_info *this_leaf, char *buf) |
diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index 2a52568dbcd6..1833f5171ccd 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c | |||
| @@ -47,7 +47,7 @@ static DEFINE_SPINLOCK(dbe_lock); | |||
| 47 | void *module_alloc(unsigned long size) | 47 | void *module_alloc(unsigned long size) |
| 48 | { | 48 | { |
| 49 | return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END, | 49 | return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END, |
| 50 | GFP_KERNEL, PAGE_KERNEL, NUMA_NO_NODE, | 50 | GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, |
| 51 | __builtin_return_address(0)); | 51 | __builtin_return_address(0)); |
| 52 | } | 52 | } |
| 53 | #endif | 53 | #endif |
diff --git a/arch/mips/netlogic/common/smp.c b/arch/mips/netlogic/common/smp.c index 4fde7ac76cc9..e743bdd6e20c 100644 --- a/arch/mips/netlogic/common/smp.c +++ b/arch/mips/netlogic/common/smp.c | |||
| @@ -162,7 +162,6 @@ void __init nlm_smp_setup(void) | |||
| 162 | unsigned int boot_cpu; | 162 | unsigned int boot_cpu; |
| 163 | int num_cpus, i, ncore, node; | 163 | int num_cpus, i, ncore, node; |
| 164 | volatile u32 *cpu_ready = nlm_get_boot_data(BOOT_CPU_READY); | 164 | volatile u32 *cpu_ready = nlm_get_boot_data(BOOT_CPU_READY); |
| 165 | char buf[64]; | ||
| 166 | 165 | ||
| 167 | boot_cpu = hard_smp_processor_id(); | 166 | boot_cpu = hard_smp_processor_id(); |
| 168 | cpumask_clear(&phys_cpu_present_mask); | 167 | cpumask_clear(&phys_cpu_present_mask); |
| @@ -189,10 +188,10 @@ void __init nlm_smp_setup(void) | |||
| 189 | } | 188 | } |
| 190 | } | 189 | } |
| 191 | 190 | ||
| 192 | cpumask_scnprintf(buf, ARRAY_SIZE(buf), &phys_cpu_present_mask); | 191 | pr_info("Physical CPU mask: %*pb\n", |
| 193 | pr_info("Physical CPU mask: %s\n", buf); | 192 | cpumask_pr_args(&phys_cpu_present_mask)); |
| 194 | cpumask_scnprintf(buf, ARRAY_SIZE(buf), cpu_possible_mask); | 193 | pr_info("Possible CPU mask: %*pb\n", |
| 195 | pr_info("Possible CPU mask: %s\n", buf); | 194 | cpumask_pr_args(cpu_possible_mask)); |
| 196 | 195 | ||
| 197 | /* check with the cores we have woken up */ | 196 | /* check with the cores we have woken up */ |
| 198 | for (ncore = 0, i = 0; i < NLM_NR_NODES; i++) | 197 | for (ncore = 0, i = 0; i < NLM_NR_NODES; i++) |
| @@ -209,7 +208,6 @@ static int nlm_parse_cpumask(cpumask_t *wakeup_mask) | |||
| 209 | { | 208 | { |
| 210 | uint32_t core0_thr_mask, core_thr_mask; | 209 | uint32_t core0_thr_mask, core_thr_mask; |
| 211 | int threadmode, i, j; | 210 | int threadmode, i, j; |
| 212 | char buf[64]; | ||
| 213 | 211 | ||
| 214 | core0_thr_mask = 0; | 212 | core0_thr_mask = 0; |
| 215 | for (i = 0; i < NLM_THREADS_PER_CORE; i++) | 213 | for (i = 0; i < NLM_THREADS_PER_CORE; i++) |
| @@ -244,8 +242,7 @@ static int nlm_parse_cpumask(cpumask_t *wakeup_mask) | |||
| 244 | return threadmode; | 242 | return threadmode; |
| 245 | 243 | ||
| 246 | unsupp: | 244 | unsupp: |
| 247 | cpumask_scnprintf(buf, ARRAY_SIZE(buf), wakeup_mask); | 245 | panic("Unsupported CPU mask %*pb", cpumask_pr_args(wakeup_mask)); |
| 248 | panic("Unsupported CPU mask %s", buf); | ||
| 249 | return 0; | 246 | return 0; |
| 250 | } | 247 | } |
| 251 | 248 | ||
diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index 5822e8e200e6..3c63a820fcda 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c | |||
| @@ -219,7 +219,7 @@ void *module_alloc(unsigned long size) | |||
| 219 | * init_data correctly */ | 219 | * init_data correctly */ |
| 220 | return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, | 220 | return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, |
| 221 | GFP_KERNEL | __GFP_HIGHMEM, | 221 | GFP_KERNEL | __GFP_HIGHMEM, |
| 222 | PAGE_KERNEL_RWX, NUMA_NO_NODE, | 222 | PAGE_KERNEL_RWX, 0, NUMA_NO_NODE, |
| 223 | __builtin_return_address(0)); | 223 | __builtin_return_address(0)); |
| 224 | } | 224 | } |
| 225 | 225 | ||
diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c index 40198d50b4c2..ae77b7e59889 100644 --- a/arch/powerpc/kernel/cacheinfo.c +++ b/arch/powerpc/kernel/cacheinfo.c | |||
| @@ -607,19 +607,16 @@ static ssize_t shared_cpu_map_show(struct kobject *k, struct kobj_attribute *att | |||
| 607 | { | 607 | { |
| 608 | struct cache_index_dir *index; | 608 | struct cache_index_dir *index; |
| 609 | struct cache *cache; | 609 | struct cache *cache; |
| 610 | int len; | 610 | int ret; |
| 611 | int n = 0; | ||
| 612 | 611 | ||
| 613 | index = kobj_to_cache_index_dir(k); | 612 | index = kobj_to_cache_index_dir(k); |
| 614 | cache = index->cache; | 613 | cache = index->cache; |
| 615 | len = PAGE_SIZE - 2; | ||
| 616 | 614 | ||
| 617 | if (len > 1) { | 615 | ret = scnprintf(buf, PAGE_SIZE - 1, "%*pb\n", |
| 618 | n = cpumask_scnprintf(buf, len, &cache->shared_cpu_map); | 616 | cpumask_pr_args(&cache->shared_cpu_map)); |
| 619 | buf[n++] = '\n'; | 617 | buf[ret++] = '\n'; |
| 620 | buf[n] = '\0'; | 618 | buf[ret] = '\0'; |
| 621 | } | 619 | return ret; |
| 622 | return n; | ||
| 623 | } | 620 | } |
| 624 | 621 | ||
| 625 | static struct kobj_attribute cache_shared_cpu_map_attr = | 622 | static struct kobj_attribute cache_shared_cpu_map_attr = |
diff --git a/arch/powerpc/sysdev/xics/ics-opal.c b/arch/powerpc/sysdev/xics/ics-opal.c index 4ba554ec8eaf..68c7e5cc98e0 100644 --- a/arch/powerpc/sysdev/xics/ics-opal.c +++ b/arch/powerpc/sysdev/xics/ics-opal.c | |||
| @@ -131,10 +131,8 @@ static int ics_opal_set_affinity(struct irq_data *d, | |||
| 131 | 131 | ||
| 132 | wanted_server = xics_get_irq_server(d->irq, cpumask, 1); | 132 | wanted_server = xics_get_irq_server(d->irq, cpumask, 1); |
| 133 | if (wanted_server < 0) { | 133 | if (wanted_server < 0) { |
| 134 | char cpulist[128]; | 134 | pr_warning("%s: No online cpus in the mask %*pb for irq %d\n", |
| 135 | cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask); | 135 | __func__, cpumask_pr_args(cpumask), d->irq); |
| 136 | pr_warning("%s: No online cpus in the mask %s for irq %d\n", | ||
| 137 | __func__, cpulist, d->irq); | ||
| 138 | return -1; | 136 | return -1; |
| 139 | } | 137 | } |
| 140 | server = ics_opal_mangle_server(wanted_server); | 138 | server = ics_opal_mangle_server(wanted_server); |
diff --git a/arch/powerpc/sysdev/xics/ics-rtas.c b/arch/powerpc/sysdev/xics/ics-rtas.c index bc81335b2cbc..0af97deb83f3 100644 --- a/arch/powerpc/sysdev/xics/ics-rtas.c +++ b/arch/powerpc/sysdev/xics/ics-rtas.c | |||
| @@ -140,11 +140,8 @@ static int ics_rtas_set_affinity(struct irq_data *d, | |||
| 140 | 140 | ||
| 141 | irq_server = xics_get_irq_server(d->irq, cpumask, 1); | 141 | irq_server = xics_get_irq_server(d->irq, cpumask, 1); |
| 142 | if (irq_server == -1) { | 142 | if (irq_server == -1) { |
| 143 | char cpulist[128]; | 143 | pr_warning("%s: No online cpus in the mask %*pb for irq %d\n", |
| 144 | cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask); | 144 | __func__, cpumask_pr_args(cpumask), d->irq); |
| 145 | printk(KERN_WARNING | ||
| 146 | "%s: No online cpus in the mask %s for irq %d\n", | ||
| 147 | __func__, cpulist, d->irq); | ||
| 148 | return -1; | 145 | return -1; |
| 149 | } | 146 | } |
| 150 | 147 | ||
diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index 409d152585be..36154a2f1814 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c | |||
| @@ -50,7 +50,7 @@ void *module_alloc(unsigned long size) | |||
| 50 | if (PAGE_ALIGN(size) > MODULES_LEN) | 50 | if (PAGE_ALIGN(size) > MODULES_LEN) |
| 51 | return NULL; | 51 | return NULL; |
| 52 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, | 52 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, |
| 53 | GFP_KERNEL, PAGE_KERNEL, NUMA_NO_NODE, | 53 | GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, |
| 54 | __builtin_return_address(0)); | 54 | __builtin_return_address(0)); |
| 55 | } | 55 | } |
| 56 | #endif | 56 | #endif |
diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c index 97655e0fd243..192a617a32f3 100644 --- a/arch/sparc/kernel/module.c +++ b/arch/sparc/kernel/module.c | |||
| @@ -29,7 +29,7 @@ static void *module_map(unsigned long size) | |||
| 29 | if (PAGE_ALIGN(size) > MODULES_LEN) | 29 | if (PAGE_ALIGN(size) > MODULES_LEN) |
| 30 | return NULL; | 30 | return NULL; |
| 31 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, | 31 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, |
| 32 | GFP_KERNEL, PAGE_KERNEL, NUMA_NO_NODE, | 32 | GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, |
| 33 | __builtin_return_address(0)); | 33 | __builtin_return_address(0)); |
| 34 | } | 34 | } |
| 35 | #else | 35 | #else |
diff --git a/arch/tile/kernel/hardwall.c b/arch/tile/kernel/hardwall.c index c4646bb99342..2fd1694ac1d0 100644 --- a/arch/tile/kernel/hardwall.c +++ b/arch/tile/kernel/hardwall.c | |||
| @@ -909,11 +909,8 @@ static void hardwall_destroy(struct hardwall_info *info) | |||
| 909 | static int hardwall_proc_show(struct seq_file *sf, void *v) | 909 | static int hardwall_proc_show(struct seq_file *sf, void *v) |
| 910 | { | 910 | { |
| 911 | struct hardwall_info *info = sf->private; | 911 | struct hardwall_info *info = sf->private; |
| 912 | char buf[256]; | ||
| 913 | 912 | ||
| 914 | int rc = cpulist_scnprintf(buf, sizeof(buf), &info->cpumask); | 913 | seq_printf(sf, "%*pbl\n", cpumask_pr_args(&info->cpumask)); |
| 915 | buf[rc++] = '\n'; | ||
| 916 | seq_write(sf, buf, rc); | ||
| 917 | return 0; | 914 | return 0; |
| 918 | } | 915 | } |
| 919 | 916 | ||
diff --git a/arch/tile/kernel/proc.c b/arch/tile/kernel/proc.c index 6829a9508649..7983e9868df6 100644 --- a/arch/tile/kernel/proc.c +++ b/arch/tile/kernel/proc.c | |||
| @@ -45,10 +45,9 @@ static int show_cpuinfo(struct seq_file *m, void *v) | |||
| 45 | int n = ptr_to_cpu(v); | 45 | int n = ptr_to_cpu(v); |
| 46 | 46 | ||
| 47 | if (n == 0) { | 47 | if (n == 0) { |
| 48 | char buf[NR_CPUS*5]; | ||
| 49 | cpulist_scnprintf(buf, sizeof(buf), cpu_online_mask); | ||
| 50 | seq_printf(m, "cpu count\t: %d\n", num_online_cpus()); | 48 | seq_printf(m, "cpu count\t: %d\n", num_online_cpus()); |
| 51 | seq_printf(m, "cpu list\t: %s\n", buf); | 49 | seq_printf(m, "cpu list\t: %*pbl\n", |
| 50 | cpumask_pr_args(cpu_online_mask)); | ||
| 52 | seq_printf(m, "model name\t: %s\n", chip_model); | 51 | seq_printf(m, "model name\t: %s\n", chip_model); |
| 53 | seq_printf(m, "flags\t\t:\n"); /* nothing for now */ | 52 | seq_printf(m, "flags\t\t:\n"); /* nothing for now */ |
| 54 | seq_printf(m, "cpu MHz\t\t: %llu.%06llu\n", | 53 | seq_printf(m, "cpu MHz\t\t: %llu.%06llu\n", |
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c index 864eea69556d..f1f579914952 100644 --- a/arch/tile/kernel/setup.c +++ b/arch/tile/kernel/setup.c | |||
| @@ -215,12 +215,11 @@ early_param("mem", setup_mem); /* compatibility with x86 */ | |||
| 215 | 215 | ||
| 216 | static int __init setup_isolnodes(char *str) | 216 | static int __init setup_isolnodes(char *str) |
| 217 | { | 217 | { |
| 218 | char buf[MAX_NUMNODES * 5]; | ||
| 219 | if (str == NULL || nodelist_parse(str, isolnodes) != 0) | 218 | if (str == NULL || nodelist_parse(str, isolnodes) != 0) |
| 220 | return -EINVAL; | 219 | return -EINVAL; |
| 221 | 220 | ||
| 222 | nodelist_scnprintf(buf, sizeof(buf), isolnodes); | 221 | pr_info("Set isolnodes value to '%*pbl'\n", |
| 223 | pr_info("Set isolnodes value to '%s'\n", buf); | 222 | nodemask_pr_args(&isolnodes)); |
| 224 | return 0; | 223 | return 0; |
| 225 | } | 224 | } |
| 226 | early_param("isolnodes", setup_isolnodes); | 225 | early_param("isolnodes", setup_isolnodes); |
| @@ -1315,11 +1314,9 @@ early_param("disabled_cpus", disabled_cpus); | |||
| 1315 | 1314 | ||
| 1316 | void __init print_disabled_cpus(void) | 1315 | void __init print_disabled_cpus(void) |
| 1317 | { | 1316 | { |
| 1318 | if (!cpumask_empty(&disabled_map)) { | 1317 | if (!cpumask_empty(&disabled_map)) |
| 1319 | char buf[100]; | 1318 | pr_info("CPUs not available for Linux: %*pbl\n", |
| 1320 | cpulist_scnprintf(buf, sizeof(buf), &disabled_map); | 1319 | cpumask_pr_args(&disabled_map)); |
| 1321 | pr_info("CPUs not available for Linux: %s\n", buf); | ||
| 1322 | } | ||
| 1323 | } | 1320 | } |
| 1324 | 1321 | ||
| 1325 | static void __init setup_cpu_maps(void) | 1322 | static void __init setup_cpu_maps(void) |
diff --git a/arch/tile/mm/homecache.c b/arch/tile/mm/homecache.c index 0029b3fb651b..40ca30a9fee3 100644 --- a/arch/tile/mm/homecache.c +++ b/arch/tile/mm/homecache.c | |||
| @@ -115,7 +115,6 @@ void flush_remote(unsigned long cache_pfn, unsigned long cache_control, | |||
| 115 | struct cpumask cache_cpumask_copy, tlb_cpumask_copy; | 115 | struct cpumask cache_cpumask_copy, tlb_cpumask_copy; |
| 116 | struct cpumask *cache_cpumask, *tlb_cpumask; | 116 | struct cpumask *cache_cpumask, *tlb_cpumask; |
| 117 | HV_PhysAddr cache_pa; | 117 | HV_PhysAddr cache_pa; |
| 118 | char cache_buf[NR_CPUS*5], tlb_buf[NR_CPUS*5]; | ||
| 119 | 118 | ||
| 120 | mb(); /* provided just to simplify "magic hypervisor" mode */ | 119 | mb(); /* provided just to simplify "magic hypervisor" mode */ |
| 121 | 120 | ||
| @@ -149,13 +148,12 @@ void flush_remote(unsigned long cache_pfn, unsigned long cache_control, | |||
| 149 | asids, asidcount); | 148 | asids, asidcount); |
| 150 | if (rc == 0) | 149 | if (rc == 0) |
| 151 | return; | 150 | return; |
| 152 | cpumask_scnprintf(cache_buf, sizeof(cache_buf), &cache_cpumask_copy); | ||
| 153 | cpumask_scnprintf(tlb_buf, sizeof(tlb_buf), &tlb_cpumask_copy); | ||
| 154 | 151 | ||
| 155 | pr_err("hv_flush_remote(%#llx, %#lx, %p [%s], %#lx, %#lx, %#lx, %p [%s], %p, %d) = %d\n", | 152 | pr_err("hv_flush_remote(%#llx, %#lx, %p [%*pb], %#lx, %#lx, %#lx, %p [%*pb], %p, %d) = %d\n", |
| 156 | cache_pa, cache_control, cache_cpumask, cache_buf, | 153 | cache_pa, cache_control, cache_cpumask, |
| 157 | (unsigned long)tlb_va, tlb_length, tlb_pgsize, | 154 | cpumask_pr_args(&cache_cpumask_copy), |
| 158 | tlb_cpumask, tlb_buf, asids, asidcount, rc); | 155 | (unsigned long)tlb_va, tlb_length, tlb_pgsize, tlb_cpumask, |
| 156 | cpumask_pr_args(&tlb_cpumask_copy), asids, asidcount, rc); | ||
| 159 | panic("Unsafe to continue."); | 157 | panic("Unsafe to continue."); |
| 160 | } | 158 | } |
| 161 | 159 | ||
diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c index be240cc4978d..ace32d7d3864 100644 --- a/arch/tile/mm/init.c +++ b/arch/tile/mm/init.c | |||
| @@ -353,15 +353,13 @@ static int __init setup_ktext(char *str) | |||
| 353 | 353 | ||
| 354 | /* Neighborhood ktext pages on specified mask */ | 354 | /* Neighborhood ktext pages on specified mask */ |
| 355 | else if (cpulist_parse(str, &ktext_mask) == 0) { | 355 | else if (cpulist_parse(str, &ktext_mask) == 0) { |
| 356 | char buf[NR_CPUS * 5]; | ||
| 357 | cpulist_scnprintf(buf, sizeof(buf), &ktext_mask); | ||
| 358 | if (cpumask_weight(&ktext_mask) > 1) { | 356 | if (cpumask_weight(&ktext_mask) > 1) { |
| 359 | ktext_small = 1; | 357 | ktext_small = 1; |
| 360 | pr_info("ktext: using caching neighborhood %s with small pages\n", | 358 | pr_info("ktext: using caching neighborhood %*pbl with small pages\n", |
| 361 | buf); | 359 | cpumask_pr_args(&ktext_mask)); |
| 362 | } else { | 360 | } else { |
| 363 | pr_info("ktext: caching on cpu %s with one huge page\n", | 361 | pr_info("ktext: caching on cpu %*pbl with one huge page\n", |
| 364 | buf); | 362 | cpumask_pr_args(&ktext_mask)); |
| 365 | } | 363 | } |
| 366 | } | 364 | } |
| 367 | 365 | ||
| @@ -492,11 +490,9 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base) | |||
| 492 | struct cpumask bad; | 490 | struct cpumask bad; |
| 493 | cpumask_andnot(&bad, &ktext_mask, cpu_possible_mask); | 491 | cpumask_andnot(&bad, &ktext_mask, cpu_possible_mask); |
| 494 | cpumask_and(&ktext_mask, &ktext_mask, cpu_possible_mask); | 492 | cpumask_and(&ktext_mask, &ktext_mask, cpu_possible_mask); |
| 495 | if (!cpumask_empty(&bad)) { | 493 | if (!cpumask_empty(&bad)) |
| 496 | char buf[NR_CPUS * 5]; | 494 | pr_info("ktext: not using unavailable cpus %*pbl\n", |
| 497 | cpulist_scnprintf(buf, sizeof(buf), &bad); | 495 | cpumask_pr_args(&bad)); |
| 498 | pr_info("ktext: not using unavailable cpus %s\n", buf); | ||
| 499 | } | ||
| 500 | if (cpumask_empty(&ktext_mask)) { | 496 | if (cpumask_empty(&ktext_mask)) { |
| 501 | pr_warn("ktext: no valid cpus; caching on %d\n", | 497 | pr_warn("ktext: no valid cpus; caching on %d\n", |
| 502 | smp_processor_id()); | 498 | smp_processor_id()); |
diff --git a/arch/unicore32/kernel/module.c b/arch/unicore32/kernel/module.c index dc41f6dfedb6..e191b3448bd3 100644 --- a/arch/unicore32/kernel/module.c +++ b/arch/unicore32/kernel/module.c | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | void *module_alloc(unsigned long size) | 25 | void *module_alloc(unsigned long size) |
| 26 | { | 26 | { |
| 27 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, | 27 | return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, |
| 28 | GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE, | 28 | GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, |
| 29 | __builtin_return_address(0)); | 29 | __builtin_return_address(0)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 33ce9a344e38..eb1cf898ed3c 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
| @@ -85,6 +85,7 @@ config X86 | |||
| 85 | select HAVE_CMPXCHG_LOCAL | 85 | select HAVE_CMPXCHG_LOCAL |
| 86 | select HAVE_CMPXCHG_DOUBLE | 86 | select HAVE_CMPXCHG_DOUBLE |
| 87 | select HAVE_ARCH_KMEMCHECK | 87 | select HAVE_ARCH_KMEMCHECK |
| 88 | select HAVE_ARCH_KASAN if X86_64 && SPARSEMEM_VMEMMAP | ||
| 88 | select HAVE_USER_RETURN_NOTIFIER | 89 | select HAVE_USER_RETURN_NOTIFIER |
| 89 | select ARCH_BINFMT_ELF_RANDOMIZE_PIE | 90 | select ARCH_BINFMT_ELF_RANDOMIZE_PIE |
| 90 | select HAVE_ARCH_JUMP_LABEL | 91 | select HAVE_ARCH_JUMP_LABEL |
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index 3db07f30636f..57bbf2fb21f6 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile | |||
| @@ -14,6 +14,8 @@ | |||
| 14 | # Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. | 14 | # Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. |
| 15 | # The number is the same as you would ordinarily press at bootup. | 15 | # The number is the same as you would ordinarily press at bootup. |
| 16 | 16 | ||
| 17 | KASAN_SANITIZE := n | ||
| 18 | |||
| 17 | SVGA_MODE := -DSVGA_MODE=NORMAL_VGA | 19 | SVGA_MODE := -DSVGA_MODE=NORMAL_VGA |
| 18 | 20 | ||
| 19 | targets := vmlinux.bin setup.bin setup.elf bzImage | 21 | targets := vmlinux.bin setup.bin setup.elf bzImage |
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index ad754b4411f7..843feb3eb20b 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile | |||
| @@ -16,6 +16,8 @@ | |||
| 16 | # (see scripts/Makefile.lib size_append) | 16 | # (see scripts/Makefile.lib size_append) |
| 17 | # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all | 17 | # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all |
| 18 | 18 | ||
| 19 | KASAN_SANITIZE := n | ||
| 20 | |||
| 19 | targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ | 21 | targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ |
| 20 | vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 | 22 | vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 |
| 21 | 23 | ||
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 92b9a5f2aed6..ef17683484e9 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c | |||
| @@ -13,8 +13,7 @@ | |||
| 13 | #include <asm/setup.h> | 13 | #include <asm/setup.h> |
| 14 | #include <asm/desc.h> | 14 | #include <asm/desc.h> |
| 15 | 15 | ||
| 16 | #undef memcpy /* Use memcpy from misc.c */ | 16 | #include "../string.h" |
| 17 | |||
| 18 | #include "eboot.h" | 17 | #include "eboot.h" |
| 19 | 18 | ||
| 20 | static efi_system_table_t *sys_table; | 19 | static efi_system_table_t *sys_table; |
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 24e3e569a13c..04477d68403f 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | * we just keep it from happening | 7 | * we just keep it from happening |
| 8 | */ | 8 | */ |
| 9 | #undef CONFIG_PARAVIRT | 9 | #undef CONFIG_PARAVIRT |
| 10 | #undef CONFIG_KASAN | ||
| 10 | #ifdef CONFIG_X86_32 | 11 | #ifdef CONFIG_X86_32 |
| 11 | #define _ASM_X86_DESC_H 1 | 12 | #define _ASM_X86_DESC_H 1 |
| 12 | #endif | 13 | #endif |
diff --git a/arch/x86/include/asm/kasan.h b/arch/x86/include/asm/kasan.h new file mode 100644 index 000000000000..8b22422fbad8 --- /dev/null +++ b/arch/x86/include/asm/kasan.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #ifndef _ASM_X86_KASAN_H | ||
| 2 | #define _ASM_X86_KASAN_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Compiler uses shadow offset assuming that addresses start | ||
| 6 | * from 0. Kernel addresses don't start from 0, so shadow | ||
| 7 | * for kernel really starts from compiler's shadow offset + | ||
| 8 | * 'kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT | ||
| 9 | */ | ||
| 10 | #define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ | ||
| 11 | (0xffff800000000000ULL >> 3)) | ||
| 12 | /* 47 bits for kernel address -> (47 - 3) bits for shadow */ | ||
| 13 | #define KASAN_SHADOW_END (KASAN_SHADOW_START + (1ULL << (47 - 3))) | ||
| 14 | |||
| 15 | #ifndef __ASSEMBLY__ | ||
| 16 | |||
| 17 | extern pte_t kasan_zero_pte[]; | ||
| 18 | extern pte_t kasan_zero_pmd[]; | ||
| 19 | extern pte_t kasan_zero_pud[]; | ||
| 20 | |||
| 21 | #ifdef CONFIG_KASAN | ||
| 22 | void __init kasan_map_early_shadow(pgd_t *pgd); | ||
| 23 | void __init kasan_init(void); | ||
| 24 | #else | ||
| 25 | static inline void kasan_map_early_shadow(pgd_t *pgd) { } | ||
| 26 | static inline void kasan_init(void) { } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
| 30 | |||
| 31 | #endif | ||
diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h index 75450b2c7be4..4edd53b79a81 100644 --- a/arch/x86/include/asm/page_64_types.h +++ b/arch/x86/include/asm/page_64_types.h | |||
| @@ -1,17 +1,23 @@ | |||
| 1 | #ifndef _ASM_X86_PAGE_64_DEFS_H | 1 | #ifndef _ASM_X86_PAGE_64_DEFS_H |
| 2 | #define _ASM_X86_PAGE_64_DEFS_H | 2 | #define _ASM_X86_PAGE_64_DEFS_H |
| 3 | 3 | ||
| 4 | #define THREAD_SIZE_ORDER 2 | 4 | #ifdef CONFIG_KASAN |
| 5 | #define KASAN_STACK_ORDER 1 | ||
| 6 | #else | ||
| 7 | #define KASAN_STACK_ORDER 0 | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER) | ||
| 5 | #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) | 11 | #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) |
| 6 | #define CURRENT_MASK (~(THREAD_SIZE - 1)) | 12 | #define CURRENT_MASK (~(THREAD_SIZE - 1)) |
| 7 | 13 | ||
| 8 | #define EXCEPTION_STACK_ORDER 0 | 14 | #define EXCEPTION_STACK_ORDER (0 + KASAN_STACK_ORDER) |
| 9 | #define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) | 15 | #define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) |
| 10 | 16 | ||
| 11 | #define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) | 17 | #define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) |
| 12 | #define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER) | 18 | #define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER) |
| 13 | 19 | ||
| 14 | #define IRQ_STACK_ORDER 2 | 20 | #define IRQ_STACK_ORDER (2 + KASAN_STACK_ORDER) |
| 15 | #define IRQ_STACK_SIZE (PAGE_SIZE << IRQ_STACK_ORDER) | 21 | #define IRQ_STACK_SIZE (PAGE_SIZE << IRQ_STACK_ORDER) |
| 16 | 22 | ||
| 17 | #define DOUBLEFAULT_STACK 1 | 23 | #define DOUBLEFAULT_STACK 1 |
diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h index 19e2c468fc2c..e4661196994e 100644 --- a/arch/x86/include/asm/string_64.h +++ b/arch/x86/include/asm/string_64.h | |||
| @@ -27,11 +27,12 @@ static __always_inline void *__inline_memcpy(void *to, const void *from, size_t | |||
| 27 | function. */ | 27 | function. */ |
| 28 | 28 | ||
| 29 | #define __HAVE_ARCH_MEMCPY 1 | 29 | #define __HAVE_ARCH_MEMCPY 1 |
| 30 | extern void *__memcpy(void *to, const void *from, size_t len); | ||
| 31 | |||
| 30 | #ifndef CONFIG_KMEMCHECK | 32 | #ifndef CONFIG_KMEMCHECK |
| 31 | #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 | 33 | #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 |
| 32 | extern void *memcpy(void *to, const void *from, size_t len); | 34 | extern void *memcpy(void *to, const void *from, size_t len); |
| 33 | #else | 35 | #else |
| 34 | extern void *__memcpy(void *to, const void *from, size_t len); | ||
| 35 | #define memcpy(dst, src, len) \ | 36 | #define memcpy(dst, src, len) \ |
| 36 | ({ \ | 37 | ({ \ |
| 37 | size_t __len = (len); \ | 38 | size_t __len = (len); \ |
| @@ -53,9 +54,11 @@ extern void *__memcpy(void *to, const void *from, size_t len); | |||
| 53 | 54 | ||
| 54 | #define __HAVE_ARCH_MEMSET | 55 | #define __HAVE_ARCH_MEMSET |
| 55 | void *memset(void *s, int c, size_t n); | 56 | void *memset(void *s, int c, size_t n); |
| 57 | void *__memset(void *s, int c, size_t n); | ||
| 56 | 58 | ||
| 57 | #define __HAVE_ARCH_MEMMOVE | 59 | #define __HAVE_ARCH_MEMMOVE |
| 58 | void *memmove(void *dest, const void *src, size_t count); | 60 | void *memmove(void *dest, const void *src, size_t count); |
| 61 | void *__memmove(void *dest, const void *src, size_t count); | ||
| 59 | 62 | ||
| 60 | int memcmp(const void *cs, const void *ct, size_t count); | 63 | int memcmp(const void *cs, const void *ct, size_t count); |
| 61 | size_t strlen(const char *s); | 64 | size_t strlen(const char *s); |
| @@ -63,6 +66,19 @@ char *strcpy(char *dest, const char *src); | |||
| 63 | char *strcat(char *dest, const char *src); | 66 | char *strcat(char *dest, const char *src); |
| 64 | int strcmp(const char *cs, const char *ct); | 67 | int strcmp(const char *cs, const char *ct); |
| 65 | 68 | ||
| 69 | #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) | ||
| 70 | |||
| 71 | /* | ||
| 72 | * For files that not instrumented (e.g. mm/slub.c) we | ||
| 73 | * should use not instrumented version of mem* functions. | ||
| 74 | */ | ||
| 75 | |||
| 76 | #undef memcpy | ||
| 77 | #define memcpy(dst, src, len) __memcpy(dst, src, len) | ||
| 78 | #define memmove(dst, src, len) __memmove(dst, src, len) | ||
| 79 | #define memset(s, c, n) __memset(s, c, n) | ||
| 80 | #endif | ||
| 81 | |||
| 66 | #endif /* __KERNEL__ */ | 82 | #endif /* __KERNEL__ */ |
| 67 | 83 | ||
| 68 | #endif /* _ASM_X86_STRING_64_H */ | 84 | #endif /* _ASM_X86_STRING_64_H */ |
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 732223496968..cdb1b70ddad0 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
| @@ -16,6 +16,10 @@ CFLAGS_REMOVE_ftrace.o = -pg | |||
| 16 | CFLAGS_REMOVE_early_printk.o = -pg | 16 | CFLAGS_REMOVE_early_printk.o = -pg |
| 17 | endif | 17 | endif |
| 18 | 18 | ||
| 19 | KASAN_SANITIZE_head$(BITS).o := n | ||
| 20 | KASAN_SANITIZE_dumpstack.o := n | ||
| 21 | KASAN_SANITIZE_dumpstack_$(BITS).o := n | ||
| 22 | |||
| 19 | CFLAGS_irq.o := -I$(src)/../include/asm/trace | 23 | CFLAGS_irq.o := -I$(src)/../include/asm/trace |
| 20 | 24 | ||
| 21 | obj-y := process_$(BITS).o signal.o entry_$(BITS).o | 25 | obj-y := process_$(BITS).o signal.o entry_$(BITS).o |
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index c7035073dfc1..659643376dbf 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c | |||
| @@ -952,20 +952,18 @@ static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf, | |||
| 952 | static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf, | 952 | static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf, |
| 953 | int type, char *buf) | 953 | int type, char *buf) |
| 954 | { | 954 | { |
| 955 | ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; | 955 | const struct cpumask *mask = to_cpumask(this_leaf->shared_cpu_map); |
| 956 | int n = 0; | 956 | int ret; |
| 957 | 957 | ||
| 958 | if (len > 1) { | 958 | if (type) |
| 959 | const struct cpumask *mask; | 959 | ret = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", |
| 960 | 960 | cpumask_pr_args(mask)); | |
| 961 | mask = to_cpumask(this_leaf->shared_cpu_map); | 961 | else |
| 962 | n = type ? | 962 | ret = scnprintf(buf, PAGE_SIZE - 1, "%*pb", |
| 963 | cpulist_scnprintf(buf, len-2, mask) : | 963 | cpumask_pr_args(mask)); |
| 964 | cpumask_scnprintf(buf, len-2, mask); | 964 | buf[ret++] = '\n'; |
| 965 | buf[n++] = '\n'; | 965 | buf[ret] = '\0'; |
| 966 | buf[n] = '\0'; | 966 | return ret; |
| 967 | } | ||
| 968 | return n; | ||
| 969 | } | 967 | } |
| 970 | 968 | ||
| 971 | static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf, | 969 | static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf, |
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index b74ebc7c4402..cf3df1d8d039 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c | |||
| @@ -265,7 +265,10 @@ int __die(const char *str, struct pt_regs *regs, long err) | |||
| 265 | printk("SMP "); | 265 | printk("SMP "); |
| 266 | #endif | 266 | #endif |
| 267 | #ifdef CONFIG_DEBUG_PAGEALLOC | 267 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 268 | printk("DEBUG_PAGEALLOC"); | 268 | printk("DEBUG_PAGEALLOC "); |
| 269 | #endif | ||
| 270 | #ifdef CONFIG_KASAN | ||
| 271 | printk("KASAN"); | ||
| 269 | #endif | 272 | #endif |
| 270 | printk("\n"); | 273 | printk("\n"); |
| 271 | if (notify_die(DIE_OOPS, str, regs, err, | 274 | if (notify_die(DIE_OOPS, str, regs, err, |
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index eda1a865641e..efcddfaf05f9 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <asm/bios_ebda.h> | 27 | #include <asm/bios_ebda.h> |
| 28 | #include <asm/bootparam_utils.h> | 28 | #include <asm/bootparam_utils.h> |
| 29 | #include <asm/microcode.h> | 29 | #include <asm/microcode.h> |
| 30 | #include <asm/kasan.h> | ||
| 30 | 31 | ||
| 31 | /* | 32 | /* |
| 32 | * Manage page tables very early on. | 33 | * Manage page tables very early on. |
| @@ -46,7 +47,7 @@ static void __init reset_early_page_tables(void) | |||
| 46 | 47 | ||
| 47 | next_early_pgt = 0; | 48 | next_early_pgt = 0; |
| 48 | 49 | ||
| 49 | write_cr3(__pa(early_level4_pgt)); | 50 | write_cr3(__pa_nodebug(early_level4_pgt)); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | /* Create a new PMD entry */ | 53 | /* Create a new PMD entry */ |
| @@ -59,7 +60,7 @@ int __init early_make_pgtable(unsigned long address) | |||
| 59 | pmdval_t pmd, *pmd_p; | 60 | pmdval_t pmd, *pmd_p; |
| 60 | 61 | ||
| 61 | /* Invalid address or early pgt is done ? */ | 62 | /* Invalid address or early pgt is done ? */ |
| 62 | if (physaddr >= MAXMEM || read_cr3() != __pa(early_level4_pgt)) | 63 | if (physaddr >= MAXMEM || read_cr3() != __pa_nodebug(early_level4_pgt)) |
| 63 | return -1; | 64 | return -1; |
| 64 | 65 | ||
| 65 | again: | 66 | again: |
| @@ -158,6 +159,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) | |||
| 158 | /* Kill off the identity-map trampoline */ | 159 | /* Kill off the identity-map trampoline */ |
| 159 | reset_early_page_tables(); | 160 | reset_early_page_tables(); |
| 160 | 161 | ||
| 162 | kasan_map_early_shadow(early_level4_pgt); | ||
| 163 | |||
| 161 | /* clear bss before set_intr_gate with early_idt_handler */ | 164 | /* clear bss before set_intr_gate with early_idt_handler */ |
| 162 | clear_bss(); | 165 | clear_bss(); |
| 163 | 166 | ||
| @@ -179,6 +182,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) | |||
| 179 | /* set init_level4_pgt kernel high mapping*/ | 182 | /* set init_level4_pgt kernel high mapping*/ |
| 180 | init_level4_pgt[511] = early_level4_pgt[511]; | 183 | init_level4_pgt[511] = early_level4_pgt[511]; |
| 181 | 184 | ||
| 185 | kasan_map_early_shadow(init_level4_pgt); | ||
| 186 | |||
| 182 | x86_64_start_reservations(real_mode_data); | 187 | x86_64_start_reservations(real_mode_data); |
| 183 | } | 188 | } |
| 184 | 189 | ||
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index a468c0a65c42..6fd514d9f69a 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S | |||
| @@ -514,8 +514,38 @@ ENTRY(phys_base) | |||
| 514 | /* This must match the first entry in level2_kernel_pgt */ | 514 | /* This must match the first entry in level2_kernel_pgt */ |
| 515 | .quad 0x0000000000000000 | 515 | .quad 0x0000000000000000 |
| 516 | 516 | ||
| 517 | #ifdef CONFIG_KASAN | ||
| 518 | #define FILL(VAL, COUNT) \ | ||
| 519 | .rept (COUNT) ; \ | ||
| 520 | .quad (VAL) ; \ | ||
| 521 | .endr | ||
| 522 | |||
| 523 | NEXT_PAGE(kasan_zero_pte) | ||
| 524 | FILL(kasan_zero_page - __START_KERNEL_map + _KERNPG_TABLE, 512) | ||
| 525 | NEXT_PAGE(kasan_zero_pmd) | ||
| 526 | FILL(kasan_zero_pte - __START_KERNEL_map + _KERNPG_TABLE, 512) | ||
| 527 | NEXT_PAGE(kasan_zero_pud) | ||
| 528 | FILL(kasan_zero_pmd - __START_KERNEL_map + _KERNPG_TABLE, 512) | ||
| 529 | |||
| 530 | #undef FILL | ||
| 531 | #endif | ||
| 532 | |||
| 533 | |||
| 517 | #include "../../x86/xen/xen-head.S" | 534 | #include "../../x86/xen/xen-head.S" |
| 518 | 535 | ||
| 519 | __PAGE_ALIGNED_BSS | 536 | __PAGE_ALIGNED_BSS |
| 520 | NEXT_PAGE(empty_zero_page) | 537 | NEXT_PAGE(empty_zero_page) |
| 521 | .skip PAGE_SIZE | 538 | .skip PAGE_SIZE |
| 539 | |||
| 540 | #ifdef CONFIG_KASAN | ||
| 541 | /* | ||
| 542 | * This page used as early shadow. We don't use empty_zero_page | ||
| 543 | * at early stages, stack instrumentation could write some garbage | ||
| 544 | * to this page. | ||
| 545 | * Latter we reuse it as zero shadow for large ranges of memory | ||
| 546 | * that allowed to access, but not instrumented by kasan | ||
| 547 | * (vmalloc/vmemmap ...). | ||
| 548 | */ | ||
| 549 | NEXT_PAGE(kasan_zero_page) | ||
| 550 | .skip PAGE_SIZE | ||
| 551 | #endif | ||
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index e69f9882bf95..d1ac80b72c72 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/fs.h> | 24 | #include <linux/fs.h> |
| 25 | #include <linux/string.h> | 25 | #include <linux/string.h> |
| 26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/kasan.h> | ||
| 27 | #include <linux/bug.h> | 28 | #include <linux/bug.h> |
| 28 | #include <linux/mm.h> | 29 | #include <linux/mm.h> |
| 29 | #include <linux/gfp.h> | 30 | #include <linux/gfp.h> |
| @@ -83,13 +84,22 @@ static unsigned long int get_module_load_offset(void) | |||
| 83 | 84 | ||
| 84 | void *module_alloc(unsigned long size) | 85 | void *module_alloc(unsigned long size) |
| 85 | { | 86 | { |
| 87 | void *p; | ||
| 88 | |||
| 86 | if (PAGE_ALIGN(size) > MODULES_LEN) | 89 | if (PAGE_ALIGN(size) > MODULES_LEN) |
| 87 | return NULL; | 90 | return NULL; |
| 88 | return __vmalloc_node_range(size, 1, | 91 | |
| 92 | p = __vmalloc_node_range(size, MODULE_ALIGN, | ||
| 89 | MODULES_VADDR + get_module_load_offset(), | 93 | MODULES_VADDR + get_module_load_offset(), |
| 90 | MODULES_END, GFP_KERNEL | __GFP_HIGHMEM, | 94 | MODULES_END, GFP_KERNEL | __GFP_HIGHMEM, |
| 91 | PAGE_KERNEL_EXEC, NUMA_NO_NODE, | 95 | PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, |
| 92 | __builtin_return_address(0)); | 96 | __builtin_return_address(0)); |
| 97 | if (p && (kasan_module_alloc(p, size) < 0)) { | ||
| 98 | vfree(p); | ||
| 99 | return NULL; | ||
| 100 | } | ||
| 101 | |||
| 102 | return p; | ||
| 93 | } | 103 | } |
| 94 | 104 | ||
| 95 | #ifdef CONFIG_X86_32 | 105 | #ifdef CONFIG_X86_32 |
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index c4648adadd7d..27d200929864 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c | |||
| @@ -89,6 +89,7 @@ | |||
| 89 | #include <asm/cacheflush.h> | 89 | #include <asm/cacheflush.h> |
| 90 | #include <asm/processor.h> | 90 | #include <asm/processor.h> |
| 91 | #include <asm/bugs.h> | 91 | #include <asm/bugs.h> |
| 92 | #include <asm/kasan.h> | ||
| 92 | 93 | ||
| 93 | #include <asm/vsyscall.h> | 94 | #include <asm/vsyscall.h> |
| 94 | #include <asm/cpu.h> | 95 | #include <asm/cpu.h> |
| @@ -1174,6 +1175,8 @@ void __init setup_arch(char **cmdline_p) | |||
| 1174 | 1175 | ||
| 1175 | x86_init.paging.pagetable_init(); | 1176 | x86_init.paging.pagetable_init(); |
| 1176 | 1177 | ||
| 1178 | kasan_init(); | ||
| 1179 | |||
| 1177 | if (boot_cpu_data.cpuid_level >= 0) { | 1180 | if (boot_cpu_data.cpuid_level >= 0) { |
| 1178 | /* A CPU has %cr4 if and only if it has CPUID */ | 1181 | /* A CPU has %cr4 if and only if it has CPUID */ |
| 1179 | mmu_cr4_features = read_cr4(); | 1182 | mmu_cr4_features = read_cr4(); |
diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c index 040681928e9d..37d8fa4438f0 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c | |||
| @@ -50,13 +50,19 @@ EXPORT_SYMBOL(csum_partial); | |||
| 50 | #undef memset | 50 | #undef memset |
| 51 | #undef memmove | 51 | #undef memmove |
| 52 | 52 | ||
| 53 | extern void *__memset(void *, int, __kernel_size_t); | ||
| 54 | extern void *__memcpy(void *, const void *, __kernel_size_t); | ||
| 55 | extern void *__memmove(void *, const void *, __kernel_size_t); | ||
| 53 | extern void *memset(void *, int, __kernel_size_t); | 56 | extern void *memset(void *, int, __kernel_size_t); |
| 54 | extern void *memcpy(void *, const void *, __kernel_size_t); | 57 | extern void *memcpy(void *, const void *, __kernel_size_t); |
| 55 | extern void *__memcpy(void *, const void *, __kernel_size_t); | 58 | extern void *memmove(void *, const void *, __kernel_size_t); |
| 59 | |||
| 60 | EXPORT_SYMBOL(__memset); | ||
| 61 | EXPORT_SYMBOL(__memcpy); | ||
| 62 | EXPORT_SYMBOL(__memmove); | ||
| 56 | 63 | ||
| 57 | EXPORT_SYMBOL(memset); | 64 | EXPORT_SYMBOL(memset); |
| 58 | EXPORT_SYMBOL(memcpy); | 65 | EXPORT_SYMBOL(memcpy); |
| 59 | EXPORT_SYMBOL(__memcpy); | ||
| 60 | EXPORT_SYMBOL(memmove); | 66 | EXPORT_SYMBOL(memmove); |
| 61 | 67 | ||
| 62 | #ifndef CONFIG_DEBUG_VIRTUAL | 68 | #ifndef CONFIG_DEBUG_VIRTUAL |
diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S index 56313a326188..89b53c9968e7 100644 --- a/arch/x86/lib/memcpy_64.S +++ b/arch/x86/lib/memcpy_64.S | |||
| @@ -53,6 +53,8 @@ | |||
| 53 | .Lmemcpy_e_e: | 53 | .Lmemcpy_e_e: |
| 54 | .previous | 54 | .previous |
| 55 | 55 | ||
| 56 | .weak memcpy | ||
| 57 | |||
| 56 | ENTRY(__memcpy) | 58 | ENTRY(__memcpy) |
| 57 | ENTRY(memcpy) | 59 | ENTRY(memcpy) |
| 58 | CFI_STARTPROC | 60 | CFI_STARTPROC |
| @@ -199,8 +201,8 @@ ENDPROC(__memcpy) | |||
| 199 | * only outcome... | 201 | * only outcome... |
| 200 | */ | 202 | */ |
| 201 | .section .altinstructions, "a" | 203 | .section .altinstructions, "a" |
| 202 | altinstruction_entry memcpy,.Lmemcpy_c,X86_FEATURE_REP_GOOD,\ | 204 | altinstruction_entry __memcpy,.Lmemcpy_c,X86_FEATURE_REP_GOOD,\ |
| 203 | .Lmemcpy_e-.Lmemcpy_c,.Lmemcpy_e-.Lmemcpy_c | 205 | .Lmemcpy_e-.Lmemcpy_c,.Lmemcpy_e-.Lmemcpy_c |
| 204 | altinstruction_entry memcpy,.Lmemcpy_c_e,X86_FEATURE_ERMS, \ | 206 | altinstruction_entry __memcpy,.Lmemcpy_c_e,X86_FEATURE_ERMS, \ |
| 205 | .Lmemcpy_e_e-.Lmemcpy_c_e,.Lmemcpy_e_e-.Lmemcpy_c_e | 207 | .Lmemcpy_e_e-.Lmemcpy_c_e,.Lmemcpy_e_e-.Lmemcpy_c_e |
| 206 | .previous | 208 | .previous |
diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S index 65268a6104f4..9c4b530575da 100644 --- a/arch/x86/lib/memmove_64.S +++ b/arch/x86/lib/memmove_64.S | |||
| @@ -24,7 +24,10 @@ | |||
| 24 | * Output: | 24 | * Output: |
| 25 | * rax: dest | 25 | * rax: dest |
| 26 | */ | 26 | */ |
| 27 | .weak memmove | ||
| 28 | |||
| 27 | ENTRY(memmove) | 29 | ENTRY(memmove) |
| 30 | ENTRY(__memmove) | ||
| 28 | CFI_STARTPROC | 31 | CFI_STARTPROC |
| 29 | 32 | ||
| 30 | /* Handle more 32 bytes in loop */ | 33 | /* Handle more 32 bytes in loop */ |
| @@ -220,4 +223,5 @@ ENTRY(memmove) | |||
| 220 | .Lmemmove_end_forward-.Lmemmove_begin_forward, \ | 223 | .Lmemmove_end_forward-.Lmemmove_begin_forward, \ |
| 221 | .Lmemmove_end_forward_efs-.Lmemmove_begin_forward_efs | 224 | .Lmemmove_end_forward_efs-.Lmemmove_begin_forward_efs |
| 222 | .previous | 225 | .previous |
| 226 | ENDPROC(__memmove) | ||
| 223 | ENDPROC(memmove) | 227 | ENDPROC(memmove) |
diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S index 2dcb3808cbda..6f44935c6a60 100644 --- a/arch/x86/lib/memset_64.S +++ b/arch/x86/lib/memset_64.S | |||
| @@ -56,6 +56,8 @@ | |||
| 56 | .Lmemset_e_e: | 56 | .Lmemset_e_e: |
| 57 | .previous | 57 | .previous |
| 58 | 58 | ||
| 59 | .weak memset | ||
| 60 | |||
| 59 | ENTRY(memset) | 61 | ENTRY(memset) |
| 60 | ENTRY(__memset) | 62 | ENTRY(__memset) |
| 61 | CFI_STARTPROC | 63 | CFI_STARTPROC |
| @@ -147,8 +149,8 @@ ENDPROC(__memset) | |||
| 147 | * feature to implement the right patch order. | 149 | * feature to implement the right patch order. |
| 148 | */ | 150 | */ |
| 149 | .section .altinstructions,"a" | 151 | .section .altinstructions,"a" |
| 150 | altinstruction_entry memset,.Lmemset_c,X86_FEATURE_REP_GOOD,\ | 152 | altinstruction_entry __memset,.Lmemset_c,X86_FEATURE_REP_GOOD,\ |
| 151 | .Lfinal-memset,.Lmemset_e-.Lmemset_c | 153 | .Lfinal-__memset,.Lmemset_e-.Lmemset_c |
| 152 | altinstruction_entry memset,.Lmemset_c_e,X86_FEATURE_ERMS, \ | 154 | altinstruction_entry __memset,.Lmemset_c_e,X86_FEATURE_ERMS, \ |
| 153 | .Lfinal-memset,.Lmemset_e_e-.Lmemset_c_e | 155 | .Lfinal-__memset,.Lmemset_e_e-.Lmemset_c_e |
| 154 | .previous | 156 | .previous |
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index ecfdc46a024a..c4cc74006c61 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile | |||
| @@ -20,6 +20,9 @@ obj-$(CONFIG_HIGHMEM) += highmem_32.o | |||
| 20 | 20 | ||
| 21 | obj-$(CONFIG_KMEMCHECK) += kmemcheck/ | 21 | obj-$(CONFIG_KMEMCHECK) += kmemcheck/ |
| 22 | 22 | ||
| 23 | KASAN_SANITIZE_kasan_init_$(BITS).o := n | ||
| 24 | obj-$(CONFIG_KASAN) += kasan_init_$(BITS).o | ||
| 25 | |||
| 23 | obj-$(CONFIG_MMIOTRACE) += mmiotrace.o | 26 | obj-$(CONFIG_MMIOTRACE) += mmiotrace.o |
| 24 | mmiotrace-y := kmmio.o pf_in.o mmio-mod.o | 27 | mmiotrace-y := kmmio.o pf_in.o mmio-mod.o |
| 25 | obj-$(CONFIG_MMIOTRACE_TEST) += testmmiotrace.o | 28 | obj-$(CONFIG_MMIOTRACE_TEST) += testmmiotrace.o |
diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c new file mode 100644 index 000000000000..4860906c6b9f --- /dev/null +++ b/arch/x86/mm/kasan_init_64.c | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | #include <linux/bootmem.h> | ||
| 2 | #include <linux/kasan.h> | ||
| 3 | #include <linux/kdebug.h> | ||
| 4 | #include <linux/mm.h> | ||
| 5 | #include <linux/sched.h> | ||
| 6 | #include <linux/vmalloc.h> | ||
| 7 | |||
| 8 | #include <asm/tlbflush.h> | ||
| 9 | #include <asm/sections.h> | ||
| 10 | |||
| 11 | extern pgd_t early_level4_pgt[PTRS_PER_PGD]; | ||
| 12 | extern struct range pfn_mapped[E820_X_MAX]; | ||
| 13 | |||
| 14 | extern unsigned char kasan_zero_page[PAGE_SIZE]; | ||
| 15 | |||
| 16 | static int __init map_range(struct range *range) | ||
| 17 | { | ||
| 18 | unsigned long start; | ||
| 19 | unsigned long end; | ||
| 20 | |||
| 21 | start = (unsigned long)kasan_mem_to_shadow(pfn_to_kaddr(range->start)); | ||
| 22 | end = (unsigned long)kasan_mem_to_shadow(pfn_to_kaddr(range->end)); | ||
| 23 | |||
| 24 | /* | ||
| 25 | * end + 1 here is intentional. We check several shadow bytes in advance | ||
| 26 | * to slightly speed up fastpath. In some rare cases we could cross | ||
| 27 | * boundary of mapped shadow, so we just map some more here. | ||
| 28 | */ | ||
| 29 | return vmemmap_populate(start, end + 1, NUMA_NO_NODE); | ||
| 30 | } | ||
| 31 | |||
| 32 | static void __init clear_pgds(unsigned long start, | ||
| 33 | unsigned long end) | ||
| 34 | { | ||
| 35 | for (; start < end; start += PGDIR_SIZE) | ||
| 36 | pgd_clear(pgd_offset_k(start)); | ||
| 37 | } | ||
| 38 | |||
| 39 | void __init kasan_map_early_shadow(pgd_t *pgd) | ||
| 40 | { | ||
| 41 | int i; | ||
| 42 | unsigned long start = KASAN_SHADOW_START; | ||
| 43 | unsigned long end = KASAN_SHADOW_END; | ||
| 44 | |||
| 45 | for (i = pgd_index(start); start < end; i++) { | ||
| 46 | pgd[i] = __pgd(__pa_nodebug(kasan_zero_pud) | ||
| 47 | | _KERNPG_TABLE); | ||
| 48 | start += PGDIR_SIZE; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | static int __init zero_pte_populate(pmd_t *pmd, unsigned long addr, | ||
| 53 | unsigned long end) | ||
| 54 | { | ||
| 55 | pte_t *pte = pte_offset_kernel(pmd, addr); | ||
| 56 | |||
| 57 | while (addr + PAGE_SIZE <= end) { | ||
| 58 | WARN_ON(!pte_none(*pte)); | ||
| 59 | set_pte(pte, __pte(__pa_nodebug(kasan_zero_page) | ||
| 60 | | __PAGE_KERNEL_RO)); | ||
| 61 | addr += PAGE_SIZE; | ||
| 62 | pte = pte_offset_kernel(pmd, addr); | ||
| 63 | } | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | static int __init zero_pmd_populate(pud_t *pud, unsigned long addr, | ||
| 68 | unsigned long end) | ||
| 69 | { | ||
| 70 | int ret = 0; | ||
| 71 | pmd_t *pmd = pmd_offset(pud, addr); | ||
| 72 | |||
| 73 | while (IS_ALIGNED(addr, PMD_SIZE) && addr + PMD_SIZE <= end) { | ||
| 74 | WARN_ON(!pmd_none(*pmd)); | ||
| 75 | set_pmd(pmd, __pmd(__pa_nodebug(kasan_zero_pte) | ||
| 76 | | __PAGE_KERNEL_RO)); | ||
| 77 | addr += PMD_SIZE; | ||
| 78 | pmd = pmd_offset(pud, addr); | ||
| 79 | } | ||
| 80 | if (addr < end) { | ||
| 81 | if (pmd_none(*pmd)) { | ||
| 82 | void *p = vmemmap_alloc_block(PAGE_SIZE, NUMA_NO_NODE); | ||
| 83 | if (!p) | ||
| 84 | return -ENOMEM; | ||
| 85 | set_pmd(pmd, __pmd(__pa_nodebug(p) | _KERNPG_TABLE)); | ||
| 86 | } | ||
| 87 | ret = zero_pte_populate(pmd, addr, end); | ||
| 88 | } | ||
| 89 | return ret; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | static int __init zero_pud_populate(pgd_t *pgd, unsigned long addr, | ||
| 94 | unsigned long end) | ||
| 95 | { | ||
| 96 | int ret = 0; | ||
| 97 | pud_t *pud = pud_offset(pgd, addr); | ||
| 98 | |||
| 99 | while (IS_ALIGNED(addr, PUD_SIZE) && addr + PUD_SIZE <= end) { | ||
| 100 | WARN_ON(!pud_none(*pud)); | ||
| 101 | set_pud(pud, __pud(__pa_nodebug(kasan_zero_pmd) | ||
| 102 | | __PAGE_KERNEL_RO)); | ||
| 103 | addr += PUD_SIZE; | ||
| 104 | pud = pud_offset(pgd, addr); | ||
| 105 | } | ||
| 106 | |||
| 107 | if (addr < end) { | ||
| 108 | if (pud_none(*pud)) { | ||
| 109 | void *p = vmemmap_alloc_block(PAGE_SIZE, NUMA_NO_NODE); | ||
| 110 | if (!p) | ||
| 111 | return -ENOMEM; | ||
| 112 | set_pud(pud, __pud(__pa_nodebug(p) | _KERNPG_TABLE)); | ||
| 113 | } | ||
| 114 | ret = zero_pmd_populate(pud, addr, end); | ||
| 115 | } | ||
| 116 | return ret; | ||
| 117 | } | ||
| 118 | |||
| 119 | static int __init zero_pgd_populate(unsigned long addr, unsigned long end) | ||
| 120 | { | ||
| 121 | int ret = 0; | ||
| 122 | pgd_t *pgd = pgd_offset_k(addr); | ||
| 123 | |||
| 124 | while (IS_ALIGNED(addr, PGDIR_SIZE) && addr + PGDIR_SIZE <= end) { | ||
| 125 | WARN_ON(!pgd_none(*pgd)); | ||
| 126 | set_pgd(pgd, __pgd(__pa_nodebug(kasan_zero_pud) | ||
| 127 | | __PAGE_KERNEL_RO)); | ||
| 128 | addr += PGDIR_SIZE; | ||
| 129 | pgd = pgd_offset_k(addr); | ||
| 130 | } | ||
| 131 | |||
| 132 | if (addr < end) { | ||
| 133 | if (pgd_none(*pgd)) { | ||
| 134 | void *p = vmemmap_alloc_block(PAGE_SIZE, NUMA_NO_NODE); | ||
| 135 | if (!p) | ||
| 136 | return -ENOMEM; | ||
| 137 | set_pgd(pgd, __pgd(__pa_nodebug(p) | _KERNPG_TABLE)); | ||
| 138 | } | ||
| 139 | ret = zero_pud_populate(pgd, addr, end); | ||
| 140 | } | ||
| 141 | return ret; | ||
| 142 | } | ||
| 143 | |||
| 144 | |||
| 145 | static void __init populate_zero_shadow(const void *start, const void *end) | ||
| 146 | { | ||
| 147 | if (zero_pgd_populate((unsigned long)start, (unsigned long)end)) | ||
| 148 | panic("kasan: unable to map zero shadow!"); | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | #ifdef CONFIG_KASAN_INLINE | ||
| 153 | static int kasan_die_handler(struct notifier_block *self, | ||
| 154 | unsigned long val, | ||
| 155 | void *data) | ||
| 156 | { | ||
| 157 | if (val == DIE_GPF) { | ||
| 158 | pr_emerg("CONFIG_KASAN_INLINE enabled"); | ||
| 159 | pr_emerg("GPF could be caused by NULL-ptr deref or user memory access"); | ||
| 160 | } | ||
| 161 | return NOTIFY_OK; | ||
| 162 | } | ||
| 163 | |||
| 164 | static struct notifier_block kasan_die_notifier = { | ||
| 165 | .notifier_call = kasan_die_handler, | ||
| 166 | }; | ||
| 167 | #endif | ||
| 168 | |||
| 169 | void __init kasan_init(void) | ||
| 170 | { | ||
| 171 | int i; | ||
| 172 | |||
| 173 | #ifdef CONFIG_KASAN_INLINE | ||
| 174 | register_die_notifier(&kasan_die_notifier); | ||
| 175 | #endif | ||
| 176 | |||
| 177 | memcpy(early_level4_pgt, init_level4_pgt, sizeof(early_level4_pgt)); | ||
| 178 | load_cr3(early_level4_pgt); | ||
| 179 | |||
| 180 | clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); | ||
| 181 | |||
| 182 | populate_zero_shadow((void *)KASAN_SHADOW_START, | ||
| 183 | kasan_mem_to_shadow((void *)PAGE_OFFSET)); | ||
| 184 | |||
| 185 | for (i = 0; i < E820_X_MAX; i++) { | ||
| 186 | if (pfn_mapped[i].end == 0) | ||
| 187 | break; | ||
| 188 | |||
| 189 | if (map_range(&pfn_mapped[i])) | ||
| 190 | panic("kasan: unable to allocate shadow!"); | ||
| 191 | } | ||
| 192 | populate_zero_shadow(kasan_mem_to_shadow((void *)PAGE_OFFSET + MAXMEM), | ||
| 193 | kasan_mem_to_shadow((void *)__START_KERNEL_map)); | ||
| 194 | |||
| 195 | vmemmap_populate((unsigned long)kasan_mem_to_shadow(_stext), | ||
| 196 | (unsigned long)kasan_mem_to_shadow(_end), | ||
| 197 | NUMA_NO_NODE); | ||
| 198 | |||
| 199 | populate_zero_shadow(kasan_mem_to_shadow((void *)MODULES_END), | ||
| 200 | (void *)KASAN_SHADOW_END); | ||
| 201 | |||
| 202 | memset(kasan_zero_page, 0, PAGE_SIZE); | ||
| 203 | |||
| 204 | load_cr3(init_level4_pgt); | ||
| 205 | init_task.kasan_depth = 0; | ||
| 206 | } | ||
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 1a883705a12a..cd4785bbacb9 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c | |||
| @@ -794,7 +794,6 @@ int early_cpu_to_node(int cpu) | |||
| 794 | void debug_cpumask_set_cpu(int cpu, int node, bool enable) | 794 | void debug_cpumask_set_cpu(int cpu, int node, bool enable) |
| 795 | { | 795 | { |
| 796 | struct cpumask *mask; | 796 | struct cpumask *mask; |
| 797 | char buf[64]; | ||
| 798 | 797 | ||
| 799 | if (node == NUMA_NO_NODE) { | 798 | if (node == NUMA_NO_NODE) { |
| 800 | /* early_cpu_to_node() already emits a warning and trace */ | 799 | /* early_cpu_to_node() already emits a warning and trace */ |
| @@ -812,10 +811,9 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable) | |||
| 812 | else | 811 | else |
| 813 | cpumask_clear_cpu(cpu, mask); | 812 | cpumask_clear_cpu(cpu, mask); |
| 814 | 813 | ||
| 815 | cpulist_scnprintf(buf, sizeof(buf), mask); | 814 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %*pbl\n", |
| 816 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", | ||
| 817 | enable ? "numa_add_cpu" : "numa_remove_cpu", | 815 | enable ? "numa_add_cpu" : "numa_remove_cpu", |
| 818 | cpu, node, buf); | 816 | cpu, node, cpumask_pr_args(mask)); |
| 819 | return; | 817 | return; |
| 820 | } | 818 | } |
| 821 | 819 | ||
diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c index c6b146e67116..7488cafab955 100644 --- a/arch/x86/platform/uv/uv_nmi.c +++ b/arch/x86/platform/uv/uv_nmi.c | |||
| @@ -273,20 +273,6 @@ static inline void uv_clear_nmi(int cpu) | |||
| 273 | } | 273 | } |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | /* Print non-responding cpus */ | ||
| 277 | static void uv_nmi_nr_cpus_pr(char *fmt) | ||
| 278 | { | ||
| 279 | static char cpu_list[1024]; | ||
| 280 | int len = sizeof(cpu_list); | ||
| 281 | int c = cpumask_weight(uv_nmi_cpu_mask); | ||
| 282 | int n = cpulist_scnprintf(cpu_list, len, uv_nmi_cpu_mask); | ||
| 283 | |||
| 284 | if (n >= len-1) | ||
| 285 | strcpy(&cpu_list[len - 6], "...\n"); | ||
| 286 | |||
| 287 | printk(fmt, c, cpu_list); | ||
| 288 | } | ||
| 289 | |||
| 290 | /* Ping non-responding cpus attemping to force them into the NMI handler */ | 276 | /* Ping non-responding cpus attemping to force them into the NMI handler */ |
| 291 | static void uv_nmi_nr_cpus_ping(void) | 277 | static void uv_nmi_nr_cpus_ping(void) |
| 292 | { | 278 | { |
| @@ -371,16 +357,19 @@ static void uv_nmi_wait(int master) | |||
| 371 | break; | 357 | break; |
| 372 | 358 | ||
| 373 | /* if not all made it in, send IPI NMI to them */ | 359 | /* if not all made it in, send IPI NMI to them */ |
| 374 | uv_nmi_nr_cpus_pr(KERN_ALERT | 360 | pr_alert("UV: Sending NMI IPI to %d non-responding CPUs: %*pbl\n", |
| 375 | "UV: Sending NMI IPI to %d non-responding CPUs: %s\n"); | 361 | cpumask_weight(uv_nmi_cpu_mask), |
| 362 | cpumask_pr_args(uv_nmi_cpu_mask)); | ||
| 363 | |||
| 376 | uv_nmi_nr_cpus_ping(); | 364 | uv_nmi_nr_cpus_ping(); |
| 377 | 365 | ||
| 378 | /* if all cpus are in, then done */ | 366 | /* if all cpus are in, then done */ |
| 379 | if (!uv_nmi_wait_cpus(0)) | 367 | if (!uv_nmi_wait_cpus(0)) |
| 380 | break; | 368 | break; |
| 381 | 369 | ||
| 382 | uv_nmi_nr_cpus_pr(KERN_ALERT | 370 | pr_alert("UV: %d CPUs not in NMI loop: %*pbl\n", |
| 383 | "UV: %d CPUs not in NMI loop: %s\n"); | 371 | cpumask_weight(uv_nmi_cpu_mask), |
| 372 | cpumask_pr_args(uv_nmi_cpu_mask)); | ||
| 384 | } while (0); | 373 | } while (0); |
| 385 | 374 | ||
| 386 | pr_alert("UV: %d of %d CPUs in NMI\n", | 375 | pr_alert("UV: %d of %d CPUs in NMI\n", |
diff --git a/arch/x86/realmode/Makefile b/arch/x86/realmode/Makefile index 94f7fbe97b08..e02c2c6c56a5 100644 --- a/arch/x86/realmode/Makefile +++ b/arch/x86/realmode/Makefile | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | # for more details. | 6 | # for more details. |
| 7 | # | 7 | # |
| 8 | # | 8 | # |
| 9 | 9 | KASAN_SANITIZE := n | |
| 10 | subdir- := rm | 10 | subdir- := rm |
| 11 | 11 | ||
| 12 | obj-y += init.o | 12 | obj-y += init.o |
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile index 7c0d7be176a5..2730d775ef9a 100644 --- a/arch/x86/realmode/rm/Makefile +++ b/arch/x86/realmode/rm/Makefile | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | # for more details. | 6 | # for more details. |
| 7 | # | 7 | # |
| 8 | # | 8 | # |
| 9 | KASAN_SANITIZE := n | ||
| 9 | 10 | ||
| 10 | always := realmode.bin realmode.relocs | 11 | always := realmode.bin realmode.relocs |
| 11 | 12 | ||
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile index 09297c8e1fcd..7b9be9822724 100644 --- a/arch/x86/vdso/Makefile +++ b/arch/x86/vdso/Makefile | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | KBUILD_CFLAGS += $(DISABLE_LTO) | 5 | KBUILD_CFLAGS += $(DISABLE_LTO) |
| 6 | KASAN_SANITIZE := n | ||
| 6 | 7 | ||
| 7 | VDSO64-$(CONFIG_X86_64) := y | 8 | VDSO64-$(CONFIG_X86_64) := y |
| 8 | VDSOX32-$(CONFIG_X86_X32_ABI) := y | 9 | VDSOX32-$(CONFIG_X86_X32_ABI) := y |
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c index 06370ccea9e9..28fc57ef5b86 100644 --- a/arch/xtensa/kernel/setup.c +++ b/arch/xtensa/kernel/setup.c | |||
| @@ -574,12 +574,9 @@ void machine_power_off(void) | |||
| 574 | static int | 574 | static int |
| 575 | c_show(struct seq_file *f, void *slot) | 575 | c_show(struct seq_file *f, void *slot) |
| 576 | { | 576 | { |
| 577 | char buf[NR_CPUS * 5]; | ||
| 578 | |||
| 579 | cpulist_scnprintf(buf, sizeof(buf), cpu_online_mask); | ||
| 580 | /* high-level stuff */ | 577 | /* high-level stuff */ |
| 581 | seq_printf(f, "CPU count\t: %u\n" | 578 | seq_printf(f, "CPU count\t: %u\n" |
| 582 | "CPU list\t: %s\n" | 579 | "CPU list\t: %*pbl\n" |
| 583 | "vendor_id\t: Tensilica\n" | 580 | "vendor_id\t: Tensilica\n" |
| 584 | "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n" | 581 | "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n" |
| 585 | "core ID\t\t: " XCHAL_CORE_ID "\n" | 582 | "core ID\t\t: " XCHAL_CORE_ID "\n" |
| @@ -588,7 +585,7 @@ c_show(struct seq_file *f, void *slot) | |||
| 588 | "cpu MHz\t\t: %lu.%02lu\n" | 585 | "cpu MHz\t\t: %lu.%02lu\n" |
| 589 | "bogomips\t: %lu.%02lu\n", | 586 | "bogomips\t: %lu.%02lu\n", |
| 590 | num_online_cpus(), | 587 | num_online_cpus(), |
| 591 | buf, | 588 | cpumask_pr_args(cpu_online_mask), |
| 592 | XCHAL_BUILD_UNIQUE_ID, | 589 | XCHAL_BUILD_UNIQUE_ID, |
| 593 | XCHAL_HAVE_BE ? "big" : "little", | 590 | XCHAL_HAVE_BE ? "big" : "little", |
| 594 | ccount_freq/1000000, | 591 | ccount_freq/1000000, |
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index f829a4c71749..f160ea44a86d 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
| @@ -245,7 +245,7 @@ static ssize_t print_cpus_offline(struct device *dev, | |||
| 245 | if (!alloc_cpumask_var(&offline, GFP_KERNEL)) | 245 | if (!alloc_cpumask_var(&offline, GFP_KERNEL)) |
| 246 | return -ENOMEM; | 246 | return -ENOMEM; |
| 247 | cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask); | 247 | cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask); |
| 248 | n = cpulist_scnprintf(buf, len, offline); | 248 | n = scnprintf(buf, len, "%*pbl", cpumask_pr_args(offline)); |
| 249 | free_cpumask_var(offline); | 249 | free_cpumask_var(offline); |
| 250 | 250 | ||
| 251 | /* display offline cpus >= nr_cpu_ids */ | 251 | /* display offline cpus >= nr_cpu_ids */ |
diff --git a/drivers/base/node.c b/drivers/base/node.c index a3b82e9c7f20..36fabe43cd44 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
| @@ -605,7 +605,8 @@ static ssize_t print_nodes_state(enum node_states state, char *buf) | |||
| 605 | { | 605 | { |
| 606 | int n; | 606 | int n; |
| 607 | 607 | ||
| 608 | n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]); | 608 | n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", |
| 609 | nodemask_pr_args(&node_states[state])); | ||
| 609 | buf[n++] = '\n'; | 610 | buf[n++] = '\n'; |
| 610 | buf[n] = '\0'; | 611 | buf[n] = '\0'; |
| 611 | return n; | 612 | return n; |
diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c index 0ce5e2d65a06..84fd66057dad 100644 --- a/drivers/bus/arm-cci.c +++ b/drivers/bus/arm-cci.c | |||
| @@ -806,8 +806,8 @@ static int cci_pmu_event_init(struct perf_event *event) | |||
| 806 | static ssize_t pmu_attr_cpumask_show(struct device *dev, | 806 | static ssize_t pmu_attr_cpumask_show(struct device *dev, |
| 807 | struct device_attribute *attr, char *buf) | 807 | struct device_attribute *attr, char *buf) |
| 808 | { | 808 | { |
| 809 | int n = cpulist_scnprintf(buf, PAGE_SIZE - 2, &pmu->cpus); | 809 | int n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", |
| 810 | 810 | cpumask_pr_args(&pmu->cpus)); | |
| 811 | buf[n++] = '\n'; | 811 | buf[n++] = '\n'; |
| 812 | buf[n] = '\0'; | 812 | buf[n] = '\0'; |
| 813 | return n; | 813 | return n; |
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index d48ac71c6c8b..642cf37124d3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c | |||
| @@ -2048,7 +2048,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw) | |||
| 2048 | goto fail_out; | 2048 | goto fail_out; |
| 2049 | } | 2049 | } |
| 2050 | 2050 | ||
| 2051 | clk->name = kstrdup(hw->init->name, GFP_KERNEL); | 2051 | clk->name = kstrdup_const(hw->init->name, GFP_KERNEL); |
| 2052 | if (!clk->name) { | 2052 | if (!clk->name) { |
| 2053 | pr_err("%s: could not allocate clk->name\n", __func__); | 2053 | pr_err("%s: could not allocate clk->name\n", __func__); |
| 2054 | ret = -ENOMEM; | 2054 | ret = -ENOMEM; |
| @@ -2075,7 +2075,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw) | |||
| 2075 | 2075 | ||
| 2076 | /* copy each string name in case parent_names is __initdata */ | 2076 | /* copy each string name in case parent_names is __initdata */ |
| 2077 | for (i = 0; i < clk->num_parents; i++) { | 2077 | for (i = 0; i < clk->num_parents; i++) { |
| 2078 | clk->parent_names[i] = kstrdup(hw->init->parent_names[i], | 2078 | clk->parent_names[i] = kstrdup_const(hw->init->parent_names[i], |
| 2079 | GFP_KERNEL); | 2079 | GFP_KERNEL); |
| 2080 | if (!clk->parent_names[i]) { | 2080 | if (!clk->parent_names[i]) { |
| 2081 | pr_err("%s: could not copy parent_names\n", __func__); | 2081 | pr_err("%s: could not copy parent_names\n", __func__); |
| @@ -2090,10 +2090,10 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw) | |||
| 2090 | 2090 | ||
| 2091 | fail_parent_names_copy: | 2091 | fail_parent_names_copy: |
| 2092 | while (--i >= 0) | 2092 | while (--i >= 0) |
| 2093 | kfree(clk->parent_names[i]); | 2093 | kfree_const(clk->parent_names[i]); |
| 2094 | kfree(clk->parent_names); | 2094 | kfree(clk->parent_names); |
| 2095 | fail_parent_names: | 2095 | fail_parent_names: |
| 2096 | kfree(clk->name); | 2096 | kfree_const(clk->name); |
| 2097 | fail_name: | 2097 | fail_name: |
| 2098 | kfree(clk); | 2098 | kfree(clk); |
| 2099 | fail_out: | 2099 | fail_out: |
| @@ -2112,10 +2112,10 @@ static void __clk_release(struct kref *ref) | |||
| 2112 | 2112 | ||
| 2113 | kfree(clk->parents); | 2113 | kfree(clk->parents); |
| 2114 | while (--i >= 0) | 2114 | while (--i >= 0) |
| 2115 | kfree(clk->parent_names[i]); | 2115 | kfree_const(clk->parent_names[i]); |
| 2116 | 2116 | ||
| 2117 | kfree(clk->parent_names); | 2117 | kfree(clk->parent_names); |
| 2118 | kfree(clk->name); | 2118 | kfree_const(clk->name); |
| 2119 | kfree(clk); | 2119 | kfree(clk); |
| 2120 | } | 2120 | } |
| 2121 | 2121 | ||
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 8902f52e0998..280bc0a63365 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile | |||
| @@ -19,6 +19,7 @@ KBUILD_CFLAGS := $(cflags-y) \ | |||
| 19 | $(call cc-option,-fno-stack-protector) | 19 | $(call cc-option,-fno-stack-protector) |
| 20 | 20 | ||
| 21 | GCOV_PROFILE := n | 21 | GCOV_PROFILE := n |
| 22 | KASAN_SANITIZE := n | ||
| 22 | 23 | ||
| 23 | lib-y := efi-stub-helper.o | 24 | lib-y := efi-stub-helper.o |
| 24 | lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o | 25 | lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o |
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 2be10984a67a..47437b16b186 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h | |||
| @@ -5,6 +5,10 @@ | |||
| 5 | /* error code which can't be mistaken for valid address */ | 5 | /* error code which can't be mistaken for valid address */ |
| 6 | #define EFI_ERROR (~0UL) | 6 | #define EFI_ERROR (~0UL) |
| 7 | 7 | ||
| 8 | #undef memcpy | ||
| 9 | #undef memset | ||
| 10 | #undef memmove | ||
| 11 | |||
| 8 | void efi_char16_printk(efi_system_table_t *, efi_char16_t *); | 12 | void efi_char16_printk(efi_system_table_t *, efi_char16_t *); |
| 9 | 13 | ||
| 10 | efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, | 14 | efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, |
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index e27a25892db4..387c51f4b4e4 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c | |||
| @@ -1399,8 +1399,8 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun | |||
| 1399 | 1399 | ||
| 1400 | static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf) | 1400 | static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf) |
| 1401 | { | 1401 | { |
| 1402 | size_t len = bitmap_scnlistprintf(buf, PAGE_SIZE - 2, | 1402 | size_t len = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", |
| 1403 | atkbd->force_release_mask, ATKBD_KEYMAP_SIZE); | 1403 | ATKBD_KEYMAP_SIZE, atkbd->force_release_mask); |
| 1404 | 1404 | ||
| 1405 | buf[len++] = '\n'; | 1405 | buf[len++] = '\n'; |
| 1406 | buf[len] = '\0'; | 1406 | buf[len] = '\0'; |
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 883d6aed5b9a..ddf4045de084 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
| @@ -190,7 +190,7 @@ static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata, | |||
| 190 | __set_bit(bdata->button->code, bits); | 190 | __set_bit(bdata->button->code, bits); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | ret = bitmap_scnlistprintf(buf, PAGE_SIZE - 2, bits, n_events); | 193 | ret = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", n_events, bits); |
| 194 | buf[ret++] = '\n'; | 194 | buf[ret++] = '\n'; |
| 195 | buf[ret] = '\0'; | 195 | buf[ret] = '\0'; |
| 196 | 196 | ||
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c index 932b93a14965..0a816859aca5 100644 --- a/drivers/net/ethernet/emulex/benet/be_main.c +++ b/drivers/net/ethernet/emulex/benet/be_main.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | #include <net/vxlan.h> | 26 | #include <net/vxlan.h> |
| 27 | 27 | ||
| 28 | MODULE_VERSION(DRV_VER); | 28 | MODULE_VERSION(DRV_VER); |
| 29 | MODULE_DEVICE_TABLE(pci, be_dev_ids); | ||
| 30 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); | 29 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
| 31 | MODULE_AUTHOR("Emulex Corporation"); | 30 | MODULE_AUTHOR("Emulex Corporation"); |
| 32 | MODULE_LICENSE("GPL"); | 31 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/net/ethernet/tile/tilegx.c b/drivers/net/ethernet/tile/tilegx.c index 049747f558c9..bea8cd2bb56c 100644 --- a/drivers/net/ethernet/tile/tilegx.c +++ b/drivers/net/ethernet/tile/tilegx.c | |||
| @@ -292,7 +292,6 @@ static inline int mpipe_instance(struct net_device *dev) | |||
| 292 | */ | 292 | */ |
| 293 | static bool network_cpus_init(void) | 293 | static bool network_cpus_init(void) |
| 294 | { | 294 | { |
| 295 | char buf[1024]; | ||
| 296 | int rc; | 295 | int rc; |
| 297 | 296 | ||
| 298 | if (network_cpus_string == NULL) | 297 | if (network_cpus_string == NULL) |
| @@ -314,8 +313,8 @@ static bool network_cpus_init(void) | |||
| 314 | return false; | 313 | return false; |
| 315 | } | 314 | } |
| 316 | 315 | ||
| 317 | cpulist_scnprintf(buf, sizeof(buf), &network_cpus_map); | 316 | pr_info("Linux network CPUs: %*pbl\n", |
| 318 | pr_info("Linux network CPUs: %s\n", buf); | 317 | cpumask_pr_args(&network_cpus_map)); |
| 319 | return true; | 318 | return true; |
| 320 | } | 319 | } |
| 321 | 320 | ||
diff --git a/drivers/net/ethernet/tile/tilepro.c b/drivers/net/ethernet/tile/tilepro.c index fb12d31cfcf6..3d8f60d9643e 100644 --- a/drivers/net/ethernet/tile/tilepro.c +++ b/drivers/net/ethernet/tile/tilepro.c | |||
| @@ -2410,9 +2410,8 @@ static int __init network_cpus_setup(char *str) | |||
| 2410 | if (cpumask_empty(&network_cpus_map)) { | 2410 | if (cpumask_empty(&network_cpus_map)) { |
| 2411 | pr_warn("Ignoring network_cpus='%s'\n", str); | 2411 | pr_warn("Ignoring network_cpus='%s'\n", str); |
| 2412 | } else { | 2412 | } else { |
| 2413 | char buf[1024]; | 2413 | pr_info("Linux network CPUs: %*pbl\n", |
| 2414 | cpulist_scnprintf(buf, sizeof(buf), &network_cpus_map); | 2414 | cpumask_pr_args(&network_cpus_map)); |
| 2415 | pr_info("Linux network CPUs: %s\n", buf); | ||
| 2416 | network_cpus_used = true; | 2415 | network_cpus_used = true; |
| 2417 | } | 2416 | } |
| 2418 | } | 2417 | } |
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c index 8cef1edcc621..dc79afd7e151 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c | |||
| @@ -291,26 +291,15 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf, | |||
| 291 | { | 291 | { |
| 292 | struct ath9k_htc_priv *priv = file->private_data; | 292 | struct ath9k_htc_priv *priv = file->private_data; |
| 293 | char buf[512]; | 293 | char buf[512]; |
| 294 | unsigned int len = 0; | 294 | unsigned int len; |
| 295 | 295 | ||
| 296 | spin_lock_bh(&priv->tx.tx_lock); | 296 | spin_lock_bh(&priv->tx.tx_lock); |
| 297 | 297 | len = scnprintf(buf, sizeof(buf), | |
| 298 | len += scnprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : "); | 298 | "TX slot bitmap : %*pb\n" |
| 299 | 299 | "Used slots : %d\n", | |
| 300 | len += bitmap_scnprintf(buf + len, sizeof(buf) - len, | 300 | MAX_TX_BUF_NUM, priv->tx.tx_slot, |
| 301 | priv->tx.tx_slot, MAX_TX_BUF_NUM); | 301 | bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); |
| 302 | |||
| 303 | len += scnprintf(buf + len, sizeof(buf) - len, "\n"); | ||
| 304 | |||
| 305 | len += scnprintf(buf + len, sizeof(buf) - len, | ||
| 306 | "Used slots : %d\n", | ||
| 307 | bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); | ||
| 308 | |||
| 309 | spin_unlock_bh(&priv->tx.tx_lock); | 302 | spin_unlock_bh(&priv->tx.tx_lock); |
| 310 | |||
| 311 | if (len > sizeof(buf)) | ||
| 312 | len = sizeof(buf); | ||
| 313 | |||
| 314 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | 303 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 315 | } | 304 | } |
| 316 | 305 | ||
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c index 1c0af9cd9a85..6808db433283 100644 --- a/drivers/net/wireless/ath/carl9170/debug.c +++ b/drivers/net/wireless/ath/carl9170/debug.c | |||
| @@ -214,14 +214,10 @@ DEBUGFS_DECLARE_RO_FILE(name, _read_bufsize) | |||
| 214 | static char *carl9170_debugfs_mem_usage_read(struct ar9170 *ar, char *buf, | 214 | static char *carl9170_debugfs_mem_usage_read(struct ar9170 *ar, char *buf, |
| 215 | size_t bufsize, ssize_t *len) | 215 | size_t bufsize, ssize_t *len) |
| 216 | { | 216 | { |
| 217 | ADD(buf, *len, bufsize, "jar: ["); | ||
| 218 | |||
| 219 | spin_lock_bh(&ar->mem_lock); | 217 | spin_lock_bh(&ar->mem_lock); |
| 220 | 218 | ||
| 221 | *len += bitmap_scnprintf(&buf[*len], bufsize - *len, | 219 | ADD(buf, *len, bufsize, "jar: [%*pb]\n", |
| 222 | ar->mem_bitmap, ar->fw.mem_blocks); | 220 | ar->fw.mem_blocks, ar->mem_bitmap); |
| 223 | |||
| 224 | ADD(buf, *len, bufsize, "]\n"); | ||
| 225 | 221 | ||
| 226 | ADD(buf, *len, bufsize, "cookies: used:%3d / total:%3d, allocs:%d\n", | 222 | ADD(buf, *len, bufsize, "cookies: used:%3d / total:%3d, allocs:%d\n", |
| 227 | bitmap_weight(ar->mem_bitmap, ar->fw.mem_blocks), | 223 | bitmap_weight(ar->mem_bitmap, ar->fw.mem_blocks), |
| @@ -316,17 +312,13 @@ static char *carl9170_debugfs_ampdu_state_read(struct ar9170 *ar, char *buf, | |||
| 316 | cnt, iter->tid, iter->bsn, iter->snx, iter->hsn, | 312 | cnt, iter->tid, iter->bsn, iter->snx, iter->hsn, |
| 317 | iter->max, iter->state, iter->counter); | 313 | iter->max, iter->state, iter->counter); |
| 318 | 314 | ||
| 319 | ADD(buf, *len, bufsize, "\tWindow: ["); | 315 | ADD(buf, *len, bufsize, "\tWindow: [%*pb,W]\n", |
| 320 | 316 | CARL9170_BAW_BITS, iter->bitmap); | |
| 321 | *len += bitmap_scnprintf(&buf[*len], bufsize - *len, | ||
| 322 | iter->bitmap, CARL9170_BAW_BITS); | ||
| 323 | 317 | ||
| 324 | #define BM_STR_OFF(offset) \ | 318 | #define BM_STR_OFF(offset) \ |
| 325 | ((CARL9170_BAW_BITS - (offset) - 1) / 4 + \ | 319 | ((CARL9170_BAW_BITS - (offset) - 1) / 4 + \ |
| 326 | (CARL9170_BAW_BITS - (offset) - 1) / 32 + 1) | 320 | (CARL9170_BAW_BITS - (offset) - 1) / 32 + 1) |
| 327 | 321 | ||
| 328 | ADD(buf, *len, bufsize, ",W]\n"); | ||
| 329 | |||
| 330 | offset = BM_STR_OFF(0); | 322 | offset = BM_STR_OFF(0); |
| 331 | ADD(buf, *len, bufsize, "\tBase Seq: %*s\n", offset, "T"); | 323 | ADD(buf, *len, bufsize, "\tBase Seq: %*s\n", offset, "T"); |
| 332 | 324 | ||
| @@ -448,12 +440,8 @@ static char *carl9170_debugfs_vif_dump_read(struct ar9170 *ar, char *buf, | |||
| 448 | ADD(buf, *len, bufsize, "registered VIFs:%d \\ %d\n", | 440 | ADD(buf, *len, bufsize, "registered VIFs:%d \\ %d\n", |
| 449 | ar->vifs, ar->fw.vif_num); | 441 | ar->vifs, ar->fw.vif_num); |
| 450 | 442 | ||
| 451 | ADD(buf, *len, bufsize, "VIF bitmap: ["); | 443 | ADD(buf, *len, bufsize, "VIF bitmap: [%*pb]\n", |
| 452 | 444 | ar->fw.vif_num, &ar->vif_bitmap); | |
| 453 | *len += bitmap_scnprintf(&buf[*len], bufsize - *len, | ||
| 454 | &ar->vif_bitmap, ar->fw.vif_num); | ||
| 455 | |||
| 456 | ADD(buf, *len, bufsize, "]\n"); | ||
| 457 | 445 | ||
| 458 | rcu_read_lock(); | 446 | rcu_read_lock(); |
| 459 | list_for_each_entry_rcu(iter, &ar->vif_list, list) { | 447 | list_for_each_entry_rcu(iter, &ar->vif_list, list) { |
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index f15cddfeb897..3bc9ddbe5cf7 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -153,6 +153,17 @@ config RTC_DRV_88PM80X | |||
| 153 | This driver can also be built as a module. If so, the module | 153 | This driver can also be built as a module. If so, the module |
| 154 | will be called rtc-88pm80x. | 154 | will be called rtc-88pm80x. |
| 155 | 155 | ||
| 156 | config RTC_DRV_ABB5ZES3 | ||
| 157 | depends on I2C | ||
| 158 | select REGMAP_I2C | ||
| 159 | tristate "Abracon AB-RTCMC-32.768kHz-B5ZE-S3" | ||
| 160 | help | ||
| 161 | If you say yes here you get support for the Abracon | ||
| 162 | AB-RTCMC-32.768kHz-B5ZE-S3 I2C RTC chip. | ||
| 163 | |||
| 164 | This driver can also be built as a module. If so, the module | ||
| 165 | will be called rtc-ab-b5ze-s3. | ||
| 166 | |||
| 156 | config RTC_DRV_AS3722 | 167 | config RTC_DRV_AS3722 |
| 157 | tristate "ams AS3722 RTC driver" | 168 | tristate "ams AS3722 RTC driver" |
| 158 | depends on MFD_AS3722 | 169 | depends on MFD_AS3722 |
| @@ -1269,6 +1280,16 @@ config RTC_DRV_MV | |||
| 1269 | This driver can also be built as a module. If so, the module | 1280 | This driver can also be built as a module. If so, the module |
| 1270 | will be called rtc-mv. | 1281 | will be called rtc-mv. |
| 1271 | 1282 | ||
| 1283 | config RTC_DRV_ARMADA38X | ||
| 1284 | tristate "Armada 38x Marvell SoC RTC" | ||
| 1285 | depends on ARCH_MVEBU | ||
| 1286 | help | ||
| 1287 | If you say yes here you will get support for the in-chip RTC | ||
| 1288 | that can be found in the Armada 38x Marvell's SoC device | ||
| 1289 | |||
| 1290 | This driver can also be built as a module. If so, the module | ||
| 1291 | will be called armada38x-rtc. | ||
| 1292 | |||
| 1272 | config RTC_DRV_PS3 | 1293 | config RTC_DRV_PS3 |
| 1273 | tristate "PS3 RTC" | 1294 | tristate "PS3 RTC" |
| 1274 | depends on PPC_PS3 | 1295 | depends on PPC_PS3 |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index c8ef3e1e6ccd..99ded8b75e95 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -24,6 +24,8 @@ obj-$(CONFIG_RTC_DRV_88PM860X) += rtc-88pm860x.o | |||
| 24 | obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o | 24 | obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o |
| 25 | obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o | 25 | obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o |
| 26 | obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o | 26 | obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o |
| 27 | obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o | ||
| 28 | obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o | ||
| 27 | obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o | 29 | obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o |
| 28 | obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o | 30 | obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o |
| 29 | obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o | 31 | obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o |
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c new file mode 100644 index 000000000000..cfc2ef98d393 --- /dev/null +++ b/drivers/rtc/rtc-ab-b5ze-s3.c | |||
| @@ -0,0 +1,1035 @@ | |||
| 1 | /* | ||
| 2 | * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3 | ||
| 3 | * I2C RTC / Alarm chip | ||
| 4 | * | ||
| 5 | * Copyright (C) 2014, Arnaud EBALARD <arno@natisbad.org> | ||
| 6 | * | ||
| 7 | * Detailed datasheet of the chip is available here: | ||
| 8 | * | ||
| 9 | * http://www.abracon.com/realtimeclock/AB-RTCMC-32.768kHz-B5ZE-S3-Application-Manual.pdf | ||
| 10 | * | ||
| 11 | * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c). | ||
| 12 | * | ||
| 13 | * This program is free software; you can redistribute it and/or modify | ||
| 14 | * it under the terms of the GNU General Public License as published by | ||
| 15 | * the Free Software Foundation; either version 2 of the License, or | ||
| 16 | * (at your option) any later version. | ||
| 17 | * | ||
| 18 | * This program is distributed in the hope that it will be useful, | ||
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | * GNU General Public License for more details. | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <linux/module.h> | ||
| 25 | #include <linux/mutex.h> | ||
| 26 | #include <linux/rtc.h> | ||
| 27 | #include <linux/i2c.h> | ||
| 28 | #include <linux/bcd.h> | ||
| 29 | #include <linux/of.h> | ||
| 30 | #include <linux/regmap.h> | ||
| 31 | #include <linux/interrupt.h> | ||
| 32 | |||
| 33 | #define DRV_NAME "rtc-ab-b5ze-s3" | ||
| 34 | |||
| 35 | /* Control section */ | ||
| 36 | #define ABB5ZES3_REG_CTRL1 0x00 /* Control 1 register */ | ||
| 37 | #define ABB5ZES3_REG_CTRL1_CIE BIT(0) /* Pulse interrupt enable */ | ||
| 38 | #define ABB5ZES3_REG_CTRL1_AIE BIT(1) /* Alarm interrupt enable */ | ||
| 39 | #define ABB5ZES3_REG_CTRL1_SIE BIT(2) /* Second interrupt enable */ | ||
| 40 | #define ABB5ZES3_REG_CTRL1_PM BIT(3) /* 24h/12h mode */ | ||
| 41 | #define ABB5ZES3_REG_CTRL1_SR BIT(4) /* Software reset */ | ||
| 42 | #define ABB5ZES3_REG_CTRL1_STOP BIT(5) /* RTC circuit enable */ | ||
| 43 | #define ABB5ZES3_REG_CTRL1_CAP BIT(7) | ||
| 44 | |||
| 45 | #define ABB5ZES3_REG_CTRL2 0x01 /* Control 2 register */ | ||
| 46 | #define ABB5ZES3_REG_CTRL2_CTBIE BIT(0) /* Countdown timer B int. enable */ | ||
| 47 | #define ABB5ZES3_REG_CTRL2_CTAIE BIT(1) /* Countdown timer A int. enable */ | ||
| 48 | #define ABB5ZES3_REG_CTRL2_WTAIE BIT(2) /* Watchdog timer A int. enable */ | ||
| 49 | #define ABB5ZES3_REG_CTRL2_AF BIT(3) /* Alarm interrupt status */ | ||
| 50 | #define ABB5ZES3_REG_CTRL2_SF BIT(4) /* Second interrupt status */ | ||
| 51 | #define ABB5ZES3_REG_CTRL2_CTBF BIT(5) /* Countdown timer B int. status */ | ||
| 52 | #define ABB5ZES3_REG_CTRL2_CTAF BIT(6) /* Countdown timer A int. status */ | ||
| 53 | #define ABB5ZES3_REG_CTRL2_WTAF BIT(7) /* Watchdog timer A int. status */ | ||
| 54 | |||
| 55 | #define ABB5ZES3_REG_CTRL3 0x02 /* Control 3 register */ | ||
| 56 | #define ABB5ZES3_REG_CTRL3_PM2 BIT(7) /* Power Management bit 2 */ | ||
| 57 | #define ABB5ZES3_REG_CTRL3_PM1 BIT(6) /* Power Management bit 1 */ | ||
| 58 | #define ABB5ZES3_REG_CTRL3_PM0 BIT(5) /* Power Management bit 0 */ | ||
| 59 | #define ABB5ZES3_REG_CTRL3_BSF BIT(3) /* Battery switchover int. status */ | ||
| 60 | #define ABB5ZES3_REG_CTRL3_BLF BIT(2) /* Battery low int. status */ | ||
| 61 | #define ABB5ZES3_REG_CTRL3_BSIE BIT(1) /* Battery switchover int. enable */ | ||
| 62 | #define ABB5ZES3_REG_CTRL3_BLIE BIT(0) /* Battery low int. enable */ | ||
| 63 | |||
| 64 | #define ABB5ZES3_CTRL_SEC_LEN 3 | ||
| 65 | |||
| 66 | /* RTC section */ | ||
| 67 | #define ABB5ZES3_REG_RTC_SC 0x03 /* RTC Seconds register */ | ||
| 68 | #define ABB5ZES3_REG_RTC_SC_OSC BIT(7) /* Clock integrity status */ | ||
| 69 | #define ABB5ZES3_REG_RTC_MN 0x04 /* RTC Minutes register */ | ||
| 70 | #define ABB5ZES3_REG_RTC_HR 0x05 /* RTC Hours register */ | ||
| 71 | #define ABB5ZES3_REG_RTC_HR_PM BIT(5) /* RTC Hours PM bit */ | ||
| 72 | #define ABB5ZES3_REG_RTC_DT 0x06 /* RTC Date register */ | ||
| 73 | #define ABB5ZES3_REG_RTC_DW 0x07 /* RTC Day of the week register */ | ||
| 74 | #define ABB5ZES3_REG_RTC_MO 0x08 /* RTC Month register */ | ||
| 75 | #define ABB5ZES3_REG_RTC_YR 0x09 /* RTC Year register */ | ||
| 76 | |||
| 77 | #define ABB5ZES3_RTC_SEC_LEN 7 | ||
| 78 | |||
| 79 | /* Alarm section (enable bits are all active low) */ | ||
| 80 | #define ABB5ZES3_REG_ALRM_MN 0x0A /* Alarm - minute register */ | ||
| 81 | #define ABB5ZES3_REG_ALRM_MN_AE BIT(7) /* Minute enable */ | ||
| 82 | #define ABB5ZES3_REG_ALRM_HR 0x0B /* Alarm - hours register */ | ||
| 83 | #define ABB5ZES3_REG_ALRM_HR_AE BIT(7) /* Hour enable */ | ||
| 84 | #define ABB5ZES3_REG_ALRM_DT 0x0C /* Alarm - date register */ | ||
| 85 | #define ABB5ZES3_REG_ALRM_DT_AE BIT(7) /* Date (day of the month) enable */ | ||
| 86 | #define ABB5ZES3_REG_ALRM_DW 0x0D /* Alarm - day of the week reg. */ | ||
| 87 | #define ABB5ZES3_REG_ALRM_DW_AE BIT(7) /* Day of the week enable */ | ||
| 88 | |||
| 89 | #define ABB5ZES3_ALRM_SEC_LEN 4 | ||
| 90 | |||
| 91 | /* Frequency offset section */ | ||
| 92 | #define ABB5ZES3_REG_FREQ_OF 0x0E /* Frequency offset register */ | ||
| 93 | #define ABB5ZES3_REG_FREQ_OF_MODE 0x0E /* Offset mode: 2 hours / minute */ | ||
| 94 | |||
| 95 | /* CLOCKOUT section */ | ||
| 96 | #define ABB5ZES3_REG_TIM_CLK 0x0F /* Timer & Clockout register */ | ||
| 97 | #define ABB5ZES3_REG_TIM_CLK_TAM BIT(7) /* Permanent/pulsed timer A/int. 2 */ | ||
| 98 | #define ABB5ZES3_REG_TIM_CLK_TBM BIT(6) /* Permanent/pulsed timer B */ | ||
| 99 | #define ABB5ZES3_REG_TIM_CLK_COF2 BIT(5) /* Clkout Freq bit 2 */ | ||
| 100 | #define ABB5ZES3_REG_TIM_CLK_COF1 BIT(4) /* Clkout Freq bit 1 */ | ||
| 101 | #define ABB5ZES3_REG_TIM_CLK_COF0 BIT(3) /* Clkout Freq bit 0 */ | ||
| 102 | #define ABB5ZES3_REG_TIM_CLK_TAC1 BIT(2) /* Timer A: - 01 : countdown */ | ||
| 103 | #define ABB5ZES3_REG_TIM_CLK_TAC0 BIT(1) /* - 10 : timer */ | ||
| 104 | #define ABB5ZES3_REG_TIM_CLK_TBC BIT(0) /* Timer B enable */ | ||
| 105 | |||
| 106 | /* Timer A Section */ | ||
| 107 | #define ABB5ZES3_REG_TIMA_CLK 0x10 /* Timer A clock register */ | ||
| 108 | #define ABB5ZES3_REG_TIMA_CLK_TAQ2 BIT(2) /* Freq bit 2 */ | ||
| 109 | #define ABB5ZES3_REG_TIMA_CLK_TAQ1 BIT(1) /* Freq bit 1 */ | ||
| 110 | #define ABB5ZES3_REG_TIMA_CLK_TAQ0 BIT(0) /* Freq bit 0 */ | ||
| 111 | #define ABB5ZES3_REG_TIMA 0x11 /* Timer A register */ | ||
| 112 | |||
| 113 | #define ABB5ZES3_TIMA_SEC_LEN 2 | ||
| 114 | |||
| 115 | /* Timer B Section */ | ||
| 116 | #define ABB5ZES3_REG_TIMB_CLK 0x12 /* Timer B clock register */ | ||
| 117 | #define ABB5ZES3_REG_TIMB_CLK_TBW2 BIT(6) | ||
| 118 | #define ABB5ZES3_REG_TIMB_CLK_TBW1 BIT(5) | ||
| 119 | #define ABB5ZES3_REG_TIMB_CLK_TBW0 BIT(4) | ||
| 120 | #define ABB5ZES3_REG_TIMB_CLK_TAQ2 BIT(2) | ||
| 121 | #define ABB5ZES3_REG_TIMB_CLK_TAQ1 BIT(1) | ||
| 122 | #define ABB5ZES3_REG_TIMB_CLK_TAQ0 BIT(0) | ||
| 123 | #define ABB5ZES3_REG_TIMB 0x13 /* Timer B register */ | ||
| 124 | #define ABB5ZES3_TIMB_SEC_LEN 2 | ||
| 125 | |||
| 126 | #define ABB5ZES3_MEM_MAP_LEN 0x14 | ||
| 127 | |||
| 128 | struct abb5zes3_rtc_data { | ||
| 129 | struct rtc_device *rtc; | ||
| 130 | struct regmap *regmap; | ||
| 131 | struct mutex lock; | ||
| 132 | |||
| 133 | int irq; | ||
| 134 | |||
| 135 | bool battery_low; | ||
| 136 | bool timer_alarm; /* current alarm is via timer A */ | ||
| 137 | }; | ||
| 138 | |||
| 139 | /* | ||
| 140 | * Try and match register bits w/ fixed null values to see whether we | ||
| 141 | * are dealing with an ABB5ZES3. Note: this function is called early | ||
| 142 | * during init and hence does need mutex protection. | ||
| 143 | */ | ||
| 144 | static int abb5zes3_i2c_validate_chip(struct regmap *regmap) | ||
| 145 | { | ||
| 146 | u8 regs[ABB5ZES3_MEM_MAP_LEN]; | ||
| 147 | static const u8 mask[ABB5ZES3_MEM_MAP_LEN] = { 0x00, 0x00, 0x10, 0x00, | ||
| 148 | 0x80, 0xc0, 0xc0, 0xf8, | ||
| 149 | 0xe0, 0x00, 0x00, 0x40, | ||
| 150 | 0x40, 0x78, 0x00, 0x00, | ||
| 151 | 0xf8, 0x00, 0x88, 0x00 }; | ||
| 152 | int ret, i; | ||
| 153 | |||
| 154 | ret = regmap_bulk_read(regmap, 0, regs, ABB5ZES3_MEM_MAP_LEN); | ||
| 155 | if (ret) | ||
| 156 | return ret; | ||
| 157 | |||
| 158 | for (i = 0; i < ABB5ZES3_MEM_MAP_LEN; ++i) { | ||
| 159 | if (regs[i] & mask[i]) /* check if bits are cleared */ | ||
| 160 | return -ENODEV; | ||
| 161 | } | ||
| 162 | |||
| 163 | return 0; | ||
| 164 | } | ||
| 165 | |||
| 166 | /* Clear alarm status bit. */ | ||
| 167 | static int _abb5zes3_rtc_clear_alarm(struct device *dev) | ||
| 168 | { | ||
| 169 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 170 | int ret; | ||
| 171 | |||
| 172 | ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL2, | ||
| 173 | ABB5ZES3_REG_CTRL2_AF, 0); | ||
| 174 | if (ret) | ||
| 175 | dev_err(dev, "%s: clearing alarm failed (%d)\n", __func__, ret); | ||
| 176 | |||
| 177 | return ret; | ||
| 178 | } | ||
| 179 | |||
| 180 | /* Enable or disable alarm (i.e. alarm interrupt generation) */ | ||
| 181 | static int _abb5zes3_rtc_update_alarm(struct device *dev, bool enable) | ||
| 182 | { | ||
| 183 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 184 | int ret; | ||
| 185 | |||
| 186 | ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL1, | ||
| 187 | ABB5ZES3_REG_CTRL1_AIE, | ||
| 188 | enable ? ABB5ZES3_REG_CTRL1_AIE : 0); | ||
| 189 | if (ret) | ||
| 190 | dev_err(dev, "%s: writing alarm INT failed (%d)\n", | ||
| 191 | __func__, ret); | ||
| 192 | |||
| 193 | return ret; | ||
| 194 | } | ||
| 195 | |||
| 196 | /* Enable or disable timer (watchdog timer A interrupt generation) */ | ||
| 197 | static int _abb5zes3_rtc_update_timer(struct device *dev, bool enable) | ||
| 198 | { | ||
| 199 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 200 | int ret; | ||
| 201 | |||
| 202 | ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL2, | ||
| 203 | ABB5ZES3_REG_CTRL2_WTAIE, | ||
| 204 | enable ? ABB5ZES3_REG_CTRL2_WTAIE : 0); | ||
| 205 | if (ret) | ||
| 206 | dev_err(dev, "%s: writing timer INT failed (%d)\n", | ||
| 207 | __func__, ret); | ||
| 208 | |||
| 209 | return ret; | ||
| 210 | } | ||
| 211 | |||
| 212 | /* | ||
| 213 | * Note: we only read, so regmap inner lock protection is sufficient, i.e. | ||
| 214 | * we do not need driver's main lock protection. | ||
| 215 | */ | ||
| 216 | static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 217 | { | ||
| 218 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 219 | u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN]; | ||
| 220 | int ret; | ||
| 221 | |||
| 222 | /* | ||
| 223 | * As we need to read CTRL1 register anyway to access 24/12h | ||
| 224 | * mode bit, we do a single bulk read of both control and RTC | ||
| 225 | * sections (they are consecutive). This also ease indexing | ||
| 226 | * of register values after bulk read. | ||
| 227 | */ | ||
| 228 | ret = regmap_bulk_read(data->regmap, ABB5ZES3_REG_CTRL1, regs, | ||
| 229 | sizeof(regs)); | ||
| 230 | if (ret) { | ||
| 231 | dev_err(dev, "%s: reading RTC time failed (%d)\n", | ||
| 232 | __func__, ret); | ||
| 233 | goto err; | ||
| 234 | } | ||
| 235 | |||
| 236 | /* If clock integrity is not guaranteed, do not return a time value */ | ||
| 237 | if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) { | ||
| 238 | ret = -ENODATA; | ||
| 239 | goto err; | ||
| 240 | } | ||
| 241 | |||
| 242 | tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F); | ||
| 243 | tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]); | ||
| 244 | |||
| 245 | if (regs[ABB5ZES3_REG_CTRL1] & ABB5ZES3_REG_CTRL1_PM) { /* 12hr mode */ | ||
| 246 | tm->tm_hour = bcd2bin(regs[ABB5ZES3_REG_RTC_HR] & 0x1f); | ||
| 247 | if (regs[ABB5ZES3_REG_RTC_HR] & ABB5ZES3_REG_RTC_HR_PM) /* PM */ | ||
| 248 | tm->tm_hour += 12; | ||
| 249 | } else { /* 24hr mode */ | ||
| 250 | tm->tm_hour = bcd2bin(regs[ABB5ZES3_REG_RTC_HR]); | ||
| 251 | } | ||
| 252 | |||
| 253 | tm->tm_mday = bcd2bin(regs[ABB5ZES3_REG_RTC_DT]); | ||
| 254 | tm->tm_wday = bcd2bin(regs[ABB5ZES3_REG_RTC_DW]); | ||
| 255 | tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ | ||
| 256 | tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; | ||
| 257 | |||
| 258 | ret = rtc_valid_tm(tm); | ||
| 259 | |||
| 260 | err: | ||
| 261 | return ret; | ||
| 262 | } | ||
| 263 | |||
| 264 | static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
| 265 | { | ||
| 266 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 267 | u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN]; | ||
| 268 | int ret; | ||
| 269 | |||
| 270 | /* | ||
| 271 | * Year register is 8-bit wide and bcd-coded, i.e records values | ||
| 272 | * between 0 and 99. tm_year is an offset from 1900 and we are | ||
| 273 | * interested in the 2000-2099 range, so any value less than 100 | ||
| 274 | * is invalid. | ||
| 275 | */ | ||
| 276 | if (tm->tm_year < 100) | ||
| 277 | return -EINVAL; | ||
| 278 | |||
| 279 | regs[ABB5ZES3_REG_RTC_SC] = bin2bcd(tm->tm_sec); /* MSB=0 clears OSC */ | ||
| 280 | regs[ABB5ZES3_REG_RTC_MN] = bin2bcd(tm->tm_min); | ||
| 281 | regs[ABB5ZES3_REG_RTC_HR] = bin2bcd(tm->tm_hour); /* 24-hour format */ | ||
| 282 | regs[ABB5ZES3_REG_RTC_DT] = bin2bcd(tm->tm_mday); | ||
| 283 | regs[ABB5ZES3_REG_RTC_DW] = bin2bcd(tm->tm_wday); | ||
| 284 | regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1); | ||
| 285 | regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100); | ||
| 286 | |||
| 287 | mutex_lock(&data->lock); | ||
| 288 | ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC, | ||
| 289 | regs + ABB5ZES3_REG_RTC_SC, | ||
| 290 | ABB5ZES3_RTC_SEC_LEN); | ||
| 291 | mutex_unlock(&data->lock); | ||
| 292 | |||
| 293 | |||
| 294 | return ret; | ||
| 295 | } | ||
| 296 | |||
| 297 | /* | ||
| 298 | * Set provided TAQ and Timer A registers (TIMA_CLK and TIMA) based on | ||
| 299 | * given number of seconds. | ||
| 300 | */ | ||
| 301 | static inline void sec_to_timer_a(u8 secs, u8 *taq, u8 *timer_a) | ||
| 302 | { | ||
| 303 | *taq = ABB5ZES3_REG_TIMA_CLK_TAQ1; /* 1Hz */ | ||
| 304 | *timer_a = secs; | ||
| 305 | } | ||
| 306 | |||
| 307 | /* | ||
| 308 | * Return current number of seconds in Timer A. As we only use | ||
| 309 | * timer A with a 1Hz freq, this is what we expect to have. | ||
| 310 | */ | ||
| 311 | static inline int sec_from_timer_a(u8 *secs, u8 taq, u8 timer_a) | ||
| 312 | { | ||
| 313 | if (taq != ABB5ZES3_REG_TIMA_CLK_TAQ1) /* 1Hz */ | ||
| 314 | return -EINVAL; | ||
| 315 | |||
| 316 | *secs = timer_a; | ||
| 317 | |||
| 318 | return 0; | ||
| 319 | } | ||
| 320 | |||
| 321 | /* | ||
| 322 | * Read alarm currently configured via a watchdog timer using timer A. This | ||
| 323 | * is done by reading current RTC time and adding remaining timer time. | ||
| 324 | */ | ||
| 325 | static int _abb5zes3_rtc_read_timer(struct device *dev, | ||
| 326 | struct rtc_wkalrm *alarm) | ||
| 327 | { | ||
| 328 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 329 | struct rtc_time rtc_tm, *alarm_tm = &alarm->time; | ||
| 330 | u8 regs[ABB5ZES3_TIMA_SEC_LEN + 1]; | ||
| 331 | unsigned long rtc_secs; | ||
| 332 | unsigned int reg; | ||
| 333 | u8 timer_secs; | ||
| 334 | int ret; | ||
| 335 | |||
| 336 | /* | ||
| 337 | * Instead of doing two separate calls, because they are consecutive, | ||
| 338 | * we grab both clockout register and Timer A section. The latter is | ||
| 339 | * used to decide if timer A is enabled (as a watchdog timer). | ||
| 340 | */ | ||
| 341 | ret = regmap_bulk_read(data->regmap, ABB5ZES3_REG_TIM_CLK, regs, | ||
| 342 | ABB5ZES3_TIMA_SEC_LEN + 1); | ||
| 343 | if (ret) { | ||
| 344 | dev_err(dev, "%s: reading Timer A section failed (%d)\n", | ||
| 345 | __func__, ret); | ||
| 346 | goto err; | ||
| 347 | } | ||
| 348 | |||
| 349 | /* get current time ... */ | ||
| 350 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); | ||
| 351 | if (ret) | ||
| 352 | goto err; | ||
| 353 | |||
| 354 | /* ... convert to seconds ... */ | ||
| 355 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 356 | if (ret) | ||
| 357 | goto err; | ||
| 358 | |||
| 359 | /* ... add remaining timer A time ... */ | ||
| 360 | ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]); | ||
| 361 | if (ret) | ||
| 362 | goto err; | ||
| 363 | |||
| 364 | /* ... and convert back. */ | ||
| 365 | rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm); | ||
| 366 | |||
| 367 | ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, ®); | ||
| 368 | if (ret) { | ||
| 369 | dev_err(dev, "%s: reading ctrl reg failed (%d)\n", | ||
| 370 | __func__, ret); | ||
| 371 | goto err; | ||
| 372 | } | ||
| 373 | |||
| 374 | alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE); | ||
| 375 | |||
| 376 | err: | ||
| 377 | return ret; | ||
| 378 | } | ||
| 379 | |||
| 380 | /* Read alarm currently configured via a RTC alarm registers. */ | ||
| 381 | static int _abb5zes3_rtc_read_alarm(struct device *dev, | ||
| 382 | struct rtc_wkalrm *alarm) | ||
| 383 | { | ||
| 384 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 385 | struct rtc_time rtc_tm, *alarm_tm = &alarm->time; | ||
| 386 | unsigned long rtc_secs, alarm_secs; | ||
| 387 | u8 regs[ABB5ZES3_ALRM_SEC_LEN]; | ||
| 388 | unsigned int reg; | ||
| 389 | int ret; | ||
| 390 | |||
| 391 | ret = regmap_bulk_read(data->regmap, ABB5ZES3_REG_ALRM_MN, regs, | ||
| 392 | ABB5ZES3_ALRM_SEC_LEN); | ||
| 393 | if (ret) { | ||
| 394 | dev_err(dev, "%s: reading alarm section failed (%d)\n", | ||
| 395 | __func__, ret); | ||
| 396 | goto err; | ||
| 397 | } | ||
| 398 | |||
| 399 | alarm_tm->tm_sec = 0; | ||
| 400 | alarm_tm->tm_min = bcd2bin(regs[0] & 0x7f); | ||
| 401 | alarm_tm->tm_hour = bcd2bin(regs[1] & 0x3f); | ||
| 402 | alarm_tm->tm_mday = bcd2bin(regs[2] & 0x3f); | ||
| 403 | alarm_tm->tm_wday = -1; | ||
| 404 | |||
| 405 | /* | ||
| 406 | * The alarm section does not store year/month. We use the ones in rtc | ||
| 407 | * section as a basis and increment month and then year if needed to get | ||
| 408 | * alarm after current time. | ||
| 409 | */ | ||
| 410 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); | ||
| 411 | if (ret) | ||
| 412 | goto err; | ||
| 413 | |||
| 414 | alarm_tm->tm_year = rtc_tm.tm_year; | ||
| 415 | alarm_tm->tm_mon = rtc_tm.tm_mon; | ||
| 416 | |||
| 417 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 418 | if (ret) | ||
| 419 | goto err; | ||
| 420 | |||
| 421 | ret = rtc_tm_to_time(alarm_tm, &alarm_secs); | ||
| 422 | if (ret) | ||
| 423 | goto err; | ||
| 424 | |||
| 425 | if (alarm_secs < rtc_secs) { | ||
| 426 | if (alarm_tm->tm_mon == 11) { | ||
| 427 | alarm_tm->tm_mon = 0; | ||
| 428 | alarm_tm->tm_year += 1; | ||
| 429 | } else { | ||
| 430 | alarm_tm->tm_mon += 1; | ||
| 431 | } | ||
| 432 | } | ||
| 433 | |||
| 434 | ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL1, ®); | ||
| 435 | if (ret) { | ||
| 436 | dev_err(dev, "%s: reading ctrl reg failed (%d)\n", | ||
| 437 | __func__, ret); | ||
| 438 | goto err; | ||
| 439 | } | ||
| 440 | |||
| 441 | alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE); | ||
| 442 | |||
| 443 | err: | ||
| 444 | return ret; | ||
| 445 | } | ||
| 446 | |||
| 447 | /* | ||
| 448 | * As the Alarm mechanism supported by the chip is only accurate to the | ||
| 449 | * minute, we use the watchdog timer mechanism provided by timer A | ||
| 450 | * (up to 256 seconds w/ a second accuracy) for low alarm values (below | ||
| 451 | * 4 minutes). Otherwise, we use the common alarm mechanism provided | ||
| 452 | * by the chip. In order for that to work, we keep track of currently | ||
| 453 | * configured timer type via 'timer_alarm' flag in our private data | ||
| 454 | * structure. | ||
| 455 | */ | ||
| 456 | static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 457 | { | ||
| 458 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 459 | int ret; | ||
| 460 | |||
| 461 | mutex_lock(&data->lock); | ||
| 462 | if (data->timer_alarm) | ||
| 463 | ret = _abb5zes3_rtc_read_timer(dev, alarm); | ||
| 464 | else | ||
| 465 | ret = _abb5zes3_rtc_read_alarm(dev, alarm); | ||
| 466 | mutex_unlock(&data->lock); | ||
| 467 | |||
| 468 | return ret; | ||
| 469 | } | ||
| 470 | |||
| 471 | /* | ||
| 472 | * Set alarm using chip alarm mechanism. It is only accurate to the | ||
| 473 | * minute (not the second). The function expects alarm interrupt to | ||
| 474 | * be disabled. | ||
| 475 | */ | ||
| 476 | static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 477 | { | ||
| 478 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 479 | struct rtc_time *alarm_tm = &alarm->time; | ||
| 480 | unsigned long rtc_secs, alarm_secs; | ||
| 481 | u8 regs[ABB5ZES3_ALRM_SEC_LEN]; | ||
| 482 | struct rtc_time rtc_tm; | ||
| 483 | int ret, enable = 1; | ||
| 484 | |||
| 485 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); | ||
| 486 | if (ret) | ||
| 487 | goto err; | ||
| 488 | |||
| 489 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 490 | if (ret) | ||
| 491 | goto err; | ||
| 492 | |||
| 493 | ret = rtc_tm_to_time(alarm_tm, &alarm_secs); | ||
| 494 | if (ret) | ||
| 495 | goto err; | ||
| 496 | |||
| 497 | /* If alarm time is before current time, disable the alarm */ | ||
| 498 | if (!alarm->enabled || alarm_secs <= rtc_secs) { | ||
| 499 | enable = 0; | ||
| 500 | } else { | ||
| 501 | /* | ||
| 502 | * Chip only support alarms up to one month in the future. Let's | ||
| 503 | * return an error if we get something after that limit. | ||
| 504 | * Comparison is done by incrementing rtc_tm month field by one | ||
| 505 | * and checking alarm value is still below. | ||
| 506 | */ | ||
| 507 | if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ | ||
| 508 | rtc_tm.tm_mon = 0; | ||
| 509 | rtc_tm.tm_year += 1; | ||
| 510 | } else { | ||
| 511 | rtc_tm.tm_mon += 1; | ||
| 512 | } | ||
| 513 | |||
| 514 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 515 | if (ret) | ||
| 516 | goto err; | ||
| 517 | |||
| 518 | if (alarm_secs > rtc_secs) { | ||
| 519 | dev_err(dev, "%s: alarm maximum is one month in the " | ||
| 520 | "future (%d)\n", __func__, ret); | ||
| 521 | ret = -EINVAL; | ||
| 522 | goto err; | ||
| 523 | } | ||
| 524 | } | ||
| 525 | |||
| 526 | /* | ||
| 527 | * Program all alarm registers but DW one. For each register, setting | ||
| 528 | * MSB to 0 enables associated alarm. | ||
| 529 | */ | ||
| 530 | regs[0] = bin2bcd(alarm_tm->tm_min) & 0x7f; | ||
| 531 | regs[1] = bin2bcd(alarm_tm->tm_hour) & 0x3f; | ||
| 532 | regs[2] = bin2bcd(alarm_tm->tm_mday) & 0x3f; | ||
| 533 | regs[3] = ABB5ZES3_REG_ALRM_DW_AE; /* do not match day of the week */ | ||
| 534 | |||
| 535 | ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_ALRM_MN, regs, | ||
| 536 | ABB5ZES3_ALRM_SEC_LEN); | ||
| 537 | if (ret < 0) { | ||
| 538 | dev_err(dev, "%s: writing ALARM section failed (%d)\n", | ||
| 539 | __func__, ret); | ||
| 540 | goto err; | ||
| 541 | } | ||
| 542 | |||
| 543 | /* Record currently configured alarm is not a timer */ | ||
| 544 | data->timer_alarm = 0; | ||
| 545 | |||
| 546 | /* Enable or disable alarm interrupt generation */ | ||
| 547 | ret = _abb5zes3_rtc_update_alarm(dev, enable); | ||
| 548 | |||
| 549 | err: | ||
| 550 | return ret; | ||
| 551 | } | ||
| 552 | |||
| 553 | /* | ||
| 554 | * Set alarm using timer watchdog (via timer A) mechanism. The function expects | ||
| 555 | * timer A interrupt to be disabled. | ||
| 556 | */ | ||
| 557 | static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, | ||
| 558 | u8 secs) | ||
| 559 | { | ||
| 560 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 561 | u8 regs[ABB5ZES3_TIMA_SEC_LEN]; | ||
| 562 | u8 mask = ABB5ZES3_REG_TIM_CLK_TAC0 | ABB5ZES3_REG_TIM_CLK_TAC1; | ||
| 563 | int ret = 0; | ||
| 564 | |||
| 565 | /* Program given number of seconds to Timer A registers */ | ||
| 566 | sec_to_timer_a(secs, ®s[0], ®s[1]); | ||
| 567 | ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_TIMA_CLK, regs, | ||
| 568 | ABB5ZES3_TIMA_SEC_LEN); | ||
| 569 | if (ret < 0) { | ||
| 570 | dev_err(dev, "%s: writing timer section failed\n", __func__); | ||
| 571 | goto err; | ||
| 572 | } | ||
| 573 | |||
| 574 | /* Configure Timer A as a watchdog timer */ | ||
| 575 | ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_TIM_CLK, | ||
| 576 | mask, ABB5ZES3_REG_TIM_CLK_TAC1); | ||
| 577 | if (ret) | ||
| 578 | dev_err(dev, "%s: failed to update timer\n", __func__); | ||
| 579 | |||
| 580 | /* Record currently configured alarm is a timer */ | ||
| 581 | data->timer_alarm = 1; | ||
| 582 | |||
| 583 | /* Enable or disable timer interrupt generation */ | ||
| 584 | ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled); | ||
| 585 | |||
| 586 | err: | ||
| 587 | return ret; | ||
| 588 | } | ||
| 589 | |||
| 590 | /* | ||
| 591 | * The chip has an alarm which is only accurate to the minute. In order to | ||
| 592 | * handle alarms below that limit, we use the watchdog timer function of | ||
| 593 | * timer A. More precisely, the timer method is used for alarms below 240 | ||
| 594 | * seconds. | ||
| 595 | */ | ||
| 596 | static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 597 | { | ||
| 598 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 599 | struct rtc_time *alarm_tm = &alarm->time; | ||
| 600 | unsigned long rtc_secs, alarm_secs; | ||
| 601 | struct rtc_time rtc_tm; | ||
| 602 | int ret; | ||
| 603 | |||
| 604 | mutex_lock(&data->lock); | ||
| 605 | ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); | ||
| 606 | if (ret) | ||
| 607 | goto err; | ||
| 608 | |||
| 609 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 610 | if (ret) | ||
| 611 | goto err; | ||
| 612 | |||
| 613 | ret = rtc_tm_to_time(alarm_tm, &alarm_secs); | ||
| 614 | if (ret) | ||
| 615 | goto err; | ||
| 616 | |||
| 617 | /* Let's first disable both the alarm and the timer interrupts */ | ||
| 618 | ret = _abb5zes3_rtc_update_alarm(dev, false); | ||
| 619 | if (ret < 0) { | ||
| 620 | dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__, | ||
| 621 | ret); | ||
| 622 | goto err; | ||
| 623 | } | ||
| 624 | ret = _abb5zes3_rtc_update_timer(dev, false); | ||
| 625 | if (ret < 0) { | ||
| 626 | dev_err(dev, "%s: unable to disable timer (%d)\n", __func__, | ||
| 627 | ret); | ||
| 628 | goto err; | ||
| 629 | } | ||
| 630 | |||
| 631 | data->timer_alarm = 0; | ||
| 632 | |||
| 633 | /* | ||
| 634 | * Let's now configure the alarm; if we are expected to ring in | ||
| 635 | * more than 240s, then we setup an alarm. Otherwise, a timer. | ||
| 636 | */ | ||
| 637 | if ((alarm_secs > rtc_secs) && ((alarm_secs - rtc_secs) <= 240)) | ||
| 638 | ret = _abb5zes3_rtc_set_timer(dev, alarm, | ||
| 639 | alarm_secs - rtc_secs); | ||
| 640 | else | ||
| 641 | ret = _abb5zes3_rtc_set_alarm(dev, alarm); | ||
| 642 | |||
| 643 | err: | ||
| 644 | mutex_unlock(&data->lock); | ||
| 645 | |||
| 646 | if (ret) | ||
| 647 | dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__, | ||
| 648 | ret); | ||
| 649 | |||
| 650 | return ret; | ||
| 651 | } | ||
| 652 | |||
| 653 | /* Enable or disable battery low irq generation */ | ||
| 654 | static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap, | ||
| 655 | bool enable) | ||
| 656 | { | ||
| 657 | return regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, | ||
| 658 | ABB5ZES3_REG_CTRL3_BLIE, | ||
| 659 | enable ? ABB5ZES3_REG_CTRL3_BLIE : 0); | ||
| 660 | } | ||
| 661 | |||
| 662 | /* | ||
| 663 | * Check current RTC status and enable/disable what needs to be. Return 0 if | ||
| 664 | * everything went ok and a negative value upon error. Note: this function | ||
| 665 | * is called early during init and hence does need mutex protection. | ||
| 666 | */ | ||
| 667 | static int abb5zes3_rtc_check_setup(struct device *dev) | ||
| 668 | { | ||
| 669 | struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); | ||
| 670 | struct regmap *regmap = data->regmap; | ||
| 671 | unsigned int reg; | ||
| 672 | int ret; | ||
| 673 | u8 mask; | ||
| 674 | |||
| 675 | /* | ||
| 676 | * By default, the devices generates a 32.768KHz signal on IRQ#1 pin. It | ||
| 677 | * is disabled here to prevent polluting the interrupt line and | ||
| 678 | * uselessly triggering the IRQ handler we install for alarm and battery | ||
| 679 | * low events. Note: this is done before clearing int. status below | ||
| 680 | * in this function. | ||
| 681 | * We also disable all timers and set timer interrupt to permanent (not | ||
| 682 | * pulsed). | ||
| 683 | */ | ||
| 684 | mask = (ABB5ZES3_REG_TIM_CLK_TBC | ABB5ZES3_REG_TIM_CLK_TAC0 | | ||
| 685 | ABB5ZES3_REG_TIM_CLK_TAC1 | ABB5ZES3_REG_TIM_CLK_COF0 | | ||
| 686 | ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 | | ||
| 687 | ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM); | ||
| 688 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask, | ||
| 689 | ABB5ZES3_REG_TIM_CLK_COF0 | ABB5ZES3_REG_TIM_CLK_COF1 | | ||
| 690 | ABB5ZES3_REG_TIM_CLK_COF2); | ||
| 691 | if (ret < 0) { | ||
| 692 | dev_err(dev, "%s: unable to initialize clkout register (%d)\n", | ||
| 693 | __func__, ret); | ||
| 694 | return ret; | ||
| 695 | } | ||
| 696 | |||
| 697 | /* | ||
| 698 | * Each component of the alarm (MN, HR, DT, DW) can be enabled/disabled | ||
| 699 | * individually by clearing/setting MSB of each associated register. So, | ||
| 700 | * we set all alarm enable bits to disable current alarm setting. | ||
| 701 | */ | ||
| 702 | mask = (ABB5ZES3_REG_ALRM_MN_AE | ABB5ZES3_REG_ALRM_HR_AE | | ||
| 703 | ABB5ZES3_REG_ALRM_DT_AE | ABB5ZES3_REG_ALRM_DW_AE); | ||
| 704 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL2, mask, mask); | ||
| 705 | if (ret < 0) { | ||
| 706 | dev_err(dev, "%s: unable to disable alarm setting (%d)\n", | ||
| 707 | __func__, ret); | ||
| 708 | return ret; | ||
| 709 | } | ||
| 710 | |||
| 711 | /* Set Control 1 register (RTC enabled, 24hr mode, all int. disabled) */ | ||
| 712 | mask = (ABB5ZES3_REG_CTRL1_CIE | ABB5ZES3_REG_CTRL1_AIE | | ||
| 713 | ABB5ZES3_REG_CTRL1_SIE | ABB5ZES3_REG_CTRL1_PM | | ||
| 714 | ABB5ZES3_REG_CTRL1_CAP | ABB5ZES3_REG_CTRL1_STOP); | ||
| 715 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL1, mask, 0); | ||
| 716 | if (ret < 0) { | ||
| 717 | dev_err(dev, "%s: unable to initialize CTRL1 register (%d)\n", | ||
| 718 | __func__, ret); | ||
| 719 | return ret; | ||
| 720 | } | ||
| 721 | |||
| 722 | /* | ||
| 723 | * Set Control 2 register (timer int. disabled, alarm status cleared). | ||
| 724 | * WTAF is read-only and cleared automatically by reading the register. | ||
| 725 | */ | ||
| 726 | mask = (ABB5ZES3_REG_CTRL2_CTBIE | ABB5ZES3_REG_CTRL2_CTAIE | | ||
| 727 | ABB5ZES3_REG_CTRL2_WTAIE | ABB5ZES3_REG_CTRL2_AF | | ||
| 728 | ABB5ZES3_REG_CTRL2_SF | ABB5ZES3_REG_CTRL2_CTBF | | ||
| 729 | ABB5ZES3_REG_CTRL2_CTAF); | ||
| 730 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL2, mask, 0); | ||
| 731 | if (ret < 0) { | ||
| 732 | dev_err(dev, "%s: unable to initialize CTRL2 register (%d)\n", | ||
| 733 | __func__, ret); | ||
| 734 | return ret; | ||
| 735 | } | ||
| 736 | |||
| 737 | /* | ||
| 738 | * Enable battery low detection function and battery switchover function | ||
| 739 | * (standard mode). Disable associated interrupts. Clear battery | ||
| 740 | * switchover flag but not battery low flag. The latter is checked | ||
| 741 | * later below. | ||
| 742 | */ | ||
| 743 | mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 | | ||
| 744 | ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE | | ||
| 745 | ABB5ZES3_REG_CTRL3_BSIE| ABB5ZES3_REG_CTRL3_BSF); | ||
| 746 | ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0); | ||
| 747 | if (ret < 0) { | ||
| 748 | dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n", | ||
| 749 | __func__, ret); | ||
| 750 | return ret; | ||
| 751 | } | ||
| 752 | |||
| 753 | /* Check oscillator integrity flag */ | ||
| 754 | ret = regmap_read(regmap, ABB5ZES3_REG_RTC_SC, ®); | ||
| 755 | if (ret < 0) { | ||
| 756 | dev_err(dev, "%s: unable to read osc. integrity flag (%d)\n", | ||
| 757 | __func__, ret); | ||
| 758 | return ret; | ||
| 759 | } | ||
| 760 | |||
| 761 | if (reg & ABB5ZES3_REG_RTC_SC_OSC) { | ||
| 762 | dev_err(dev, "clock integrity not guaranteed. Osc. has stopped " | ||
| 763 | "or has been interrupted.\n"); | ||
| 764 | dev_err(dev, "change battery (if not already done) and " | ||
| 765 | "then set time to reset osc. failure flag.\n"); | ||
| 766 | } | ||
| 767 | |||
| 768 | /* | ||
| 769 | * Check battery low flag at startup: this allows reporting battery | ||
| 770 | * is low at startup when IRQ line is not connected. Note: we record | ||
| 771 | * current status to avoid reenabling this interrupt later in probe | ||
| 772 | * function if battery is low. | ||
| 773 | */ | ||
| 774 | ret = regmap_read(regmap, ABB5ZES3_REG_CTRL3, ®); | ||
| 775 | if (ret < 0) { | ||
| 776 | dev_err(dev, "%s: unable to read battery low flag (%d)\n", | ||
| 777 | __func__, ret); | ||
| 778 | return ret; | ||
| 779 | } | ||
| 780 | |||
| 781 | data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF; | ||
| 782 | if (data->battery_low) { | ||
| 783 | dev_err(dev, "RTC battery is low; please, consider " | ||
| 784 | "changing it!\n"); | ||
| 785 | |||
| 786 | ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false); | ||
| 787 | if (ret) | ||
| 788 | dev_err(dev, "%s: disabling battery low interrupt " | ||
| 789 | "generation failed (%d)\n", __func__, ret); | ||
| 790 | } | ||
| 791 | |||
| 792 | return ret; | ||
| 793 | } | ||
| 794 | |||
| 795 | static int abb5zes3_rtc_alarm_irq_enable(struct device *dev, | ||
| 796 | unsigned int enable) | ||
| 797 | { | ||
| 798 | struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 799 | int ret = 0; | ||
| 800 | |||
| 801 | if (rtc_data->irq) { | ||
| 802 | mutex_lock(&rtc_data->lock); | ||
| 803 | if (rtc_data->timer_alarm) | ||
| 804 | ret = _abb5zes3_rtc_update_timer(dev, enable); | ||
| 805 | else | ||
| 806 | ret = _abb5zes3_rtc_update_alarm(dev, enable); | ||
| 807 | mutex_unlock(&rtc_data->lock); | ||
| 808 | } | ||
| 809 | |||
| 810 | return ret; | ||
| 811 | } | ||
| 812 | |||
| 813 | static irqreturn_t _abb5zes3_rtc_interrupt(int irq, void *data) | ||
| 814 | { | ||
| 815 | struct i2c_client *client = data; | ||
| 816 | struct device *dev = &client->dev; | ||
| 817 | struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 818 | struct rtc_device *rtc = rtc_data->rtc; | ||
| 819 | u8 regs[ABB5ZES3_CTRL_SEC_LEN]; | ||
| 820 | int ret, handled = IRQ_NONE; | ||
| 821 | |||
| 822 | ret = regmap_bulk_read(rtc_data->regmap, 0, regs, | ||
| 823 | ABB5ZES3_CTRL_SEC_LEN); | ||
| 824 | if (ret) { | ||
| 825 | dev_err(dev, "%s: unable to read control section (%d)!\n", | ||
| 826 | __func__, ret); | ||
| 827 | return handled; | ||
| 828 | } | ||
| 829 | |||
| 830 | /* | ||
| 831 | * Check battery low detection flag and disable battery low interrupt | ||
| 832 | * generation if flag is set (interrupt can only be cleared when | ||
| 833 | * battery is replaced). | ||
| 834 | */ | ||
| 835 | if (regs[ABB5ZES3_REG_CTRL3] & ABB5ZES3_REG_CTRL3_BLF) { | ||
| 836 | dev_err(dev, "RTC battery is low; please change it!\n"); | ||
| 837 | |||
| 838 | _abb5zes3_rtc_battery_low_irq_enable(rtc_data->regmap, false); | ||
| 839 | |||
| 840 | handled = IRQ_HANDLED; | ||
| 841 | } | ||
| 842 | |||
| 843 | /* Check alarm flag */ | ||
| 844 | if (regs[ABB5ZES3_REG_CTRL2] & ABB5ZES3_REG_CTRL2_AF) { | ||
| 845 | dev_dbg(dev, "RTC alarm!\n"); | ||
| 846 | |||
| 847 | rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF); | ||
| 848 | |||
| 849 | /* Acknowledge and disable the alarm */ | ||
| 850 | _abb5zes3_rtc_clear_alarm(dev); | ||
| 851 | _abb5zes3_rtc_update_alarm(dev, 0); | ||
| 852 | |||
| 853 | handled = IRQ_HANDLED; | ||
| 854 | } | ||
| 855 | |||
| 856 | /* Check watchdog Timer A flag */ | ||
| 857 | if (regs[ABB5ZES3_REG_CTRL2] & ABB5ZES3_REG_CTRL2_WTAF) { | ||
| 858 | dev_dbg(dev, "RTC timer!\n"); | ||
| 859 | |||
| 860 | rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF); | ||
| 861 | |||
| 862 | /* | ||
| 863 | * Acknowledge and disable the alarm. Note: WTAF | ||
| 864 | * flag had been cleared when reading CTRL2 | ||
| 865 | */ | ||
| 866 | _abb5zes3_rtc_update_timer(dev, 0); | ||
| 867 | |||
| 868 | rtc_data->timer_alarm = 0; | ||
| 869 | |||
| 870 | handled = IRQ_HANDLED; | ||
| 871 | } | ||
| 872 | |||
| 873 | return handled; | ||
| 874 | } | ||
| 875 | |||
| 876 | static const struct rtc_class_ops rtc_ops = { | ||
| 877 | .read_time = _abb5zes3_rtc_read_time, | ||
| 878 | .set_time = abb5zes3_rtc_set_time, | ||
| 879 | .read_alarm = abb5zes3_rtc_read_alarm, | ||
| 880 | .set_alarm = abb5zes3_rtc_set_alarm, | ||
| 881 | .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, | ||
| 882 | }; | ||
| 883 | |||
| 884 | static struct regmap_config abb5zes3_rtc_regmap_config = { | ||
| 885 | .reg_bits = 8, | ||
| 886 | .val_bits = 8, | ||
| 887 | }; | ||
| 888 | |||
| 889 | static int abb5zes3_probe(struct i2c_client *client, | ||
| 890 | const struct i2c_device_id *id) | ||
| 891 | { | ||
| 892 | struct abb5zes3_rtc_data *data = NULL; | ||
| 893 | struct device *dev = &client->dev; | ||
| 894 | struct regmap *regmap; | ||
| 895 | int ret; | ||
| 896 | |||
| 897 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | | ||
| 898 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
| 899 | I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
| 900 | ret = -ENODEV; | ||
| 901 | goto err; | ||
| 902 | } | ||
| 903 | |||
| 904 | regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config); | ||
| 905 | if (IS_ERR(regmap)) { | ||
| 906 | ret = PTR_ERR(regmap); | ||
| 907 | dev_err(dev, "%s: regmap allocation failed: %d\n", | ||
| 908 | __func__, ret); | ||
| 909 | goto err; | ||
| 910 | } | ||
| 911 | |||
| 912 | ret = abb5zes3_i2c_validate_chip(regmap); | ||
| 913 | if (ret) | ||
| 914 | goto err; | ||
| 915 | |||
| 916 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); | ||
| 917 | if (!data) { | ||
| 918 | ret = -ENOMEM; | ||
| 919 | goto err; | ||
| 920 | } | ||
| 921 | |||
| 922 | mutex_init(&data->lock); | ||
| 923 | data->regmap = regmap; | ||
| 924 | dev_set_drvdata(dev, data); | ||
| 925 | |||
| 926 | ret = abb5zes3_rtc_check_setup(dev); | ||
| 927 | if (ret) | ||
| 928 | goto err; | ||
| 929 | |||
| 930 | if (client->irq > 0) { | ||
| 931 | ret = devm_request_threaded_irq(dev, client->irq, NULL, | ||
| 932 | _abb5zes3_rtc_interrupt, | ||
| 933 | IRQF_SHARED|IRQF_ONESHOT, | ||
| 934 | DRV_NAME, client); | ||
| 935 | if (!ret) { | ||
| 936 | device_init_wakeup(dev, true); | ||
| 937 | data->irq = client->irq; | ||
| 938 | dev_dbg(dev, "%s: irq %d used by RTC\n", __func__, | ||
| 939 | client->irq); | ||
| 940 | } else { | ||
| 941 | dev_err(dev, "%s: irq %d unavailable (%d)\n", | ||
| 942 | __func__, client->irq, ret); | ||
| 943 | goto err; | ||
| 944 | } | ||
| 945 | } | ||
| 946 | |||
| 947 | data->rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops, | ||
| 948 | THIS_MODULE); | ||
| 949 | ret = PTR_ERR_OR_ZERO(data->rtc); | ||
| 950 | if (ret) { | ||
| 951 | dev_err(dev, "%s: unable to register RTC device (%d)\n", | ||
| 952 | __func__, ret); | ||
| 953 | goto err; | ||
| 954 | } | ||
| 955 | |||
| 956 | /* Enable battery low detection interrupt if battery not already low */ | ||
| 957 | if (!data->battery_low && data->irq) { | ||
| 958 | ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true); | ||
| 959 | if (ret) { | ||
| 960 | dev_err(dev, "%s: enabling battery low interrupt " | ||
| 961 | "generation failed (%d)\n", __func__, ret); | ||
| 962 | goto err; | ||
| 963 | } | ||
| 964 | } | ||
| 965 | |||
| 966 | err: | ||
| 967 | if (ret && data && data->irq) | ||
| 968 | device_init_wakeup(dev, false); | ||
| 969 | return ret; | ||
| 970 | } | ||
| 971 | |||
| 972 | static int abb5zes3_remove(struct i2c_client *client) | ||
| 973 | { | ||
| 974 | struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(&client->dev); | ||
| 975 | |||
| 976 | if (rtc_data->irq > 0) | ||
| 977 | device_init_wakeup(&client->dev, false); | ||
| 978 | |||
| 979 | return 0; | ||
| 980 | } | ||
| 981 | |||
| 982 | #ifdef CONFIG_PM_SLEEP | ||
| 983 | static int abb5zes3_rtc_suspend(struct device *dev) | ||
| 984 | { | ||
| 985 | struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 986 | |||
| 987 | if (device_may_wakeup(dev)) | ||
| 988 | return enable_irq_wake(rtc_data->irq); | ||
| 989 | |||
| 990 | return 0; | ||
| 991 | } | ||
| 992 | |||
| 993 | static int abb5zes3_rtc_resume(struct device *dev) | ||
| 994 | { | ||
| 995 | struct abb5zes3_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 996 | |||
| 997 | if (device_may_wakeup(dev)) | ||
| 998 | return disable_irq_wake(rtc_data->irq); | ||
| 999 | |||
| 1000 | return 0; | ||
| 1001 | } | ||
| 1002 | #endif | ||
| 1003 | |||
| 1004 | static SIMPLE_DEV_PM_OPS(abb5zes3_rtc_pm_ops, abb5zes3_rtc_suspend, | ||
| 1005 | abb5zes3_rtc_resume); | ||
| 1006 | |||
| 1007 | #ifdef CONFIG_OF | ||
| 1008 | static const struct of_device_id abb5zes3_dt_match[] = { | ||
| 1009 | { .compatible = "abracon,abb5zes3" }, | ||
| 1010 | { }, | ||
| 1011 | }; | ||
| 1012 | #endif | ||
| 1013 | |||
| 1014 | static const struct i2c_device_id abb5zes3_id[] = { | ||
| 1015 | { "abb5zes3", 0 }, | ||
| 1016 | { } | ||
| 1017 | }; | ||
| 1018 | MODULE_DEVICE_TABLE(i2c, abb5zes3_id); | ||
| 1019 | |||
| 1020 | static struct i2c_driver abb5zes3_driver = { | ||
| 1021 | .driver = { | ||
| 1022 | .name = DRV_NAME, | ||
| 1023 | .owner = THIS_MODULE, | ||
| 1024 | .pm = &abb5zes3_rtc_pm_ops, | ||
| 1025 | .of_match_table = of_match_ptr(abb5zes3_dt_match), | ||
| 1026 | }, | ||
| 1027 | .probe = abb5zes3_probe, | ||
| 1028 | .remove = abb5zes3_remove, | ||
| 1029 | .id_table = abb5zes3_id, | ||
| 1030 | }; | ||
| 1031 | module_i2c_driver(abb5zes3_driver); | ||
| 1032 | |||
| 1033 | MODULE_AUTHOR("Arnaud EBALARD <arno@natisbad.org>"); | ||
| 1034 | MODULE_DESCRIPTION("Abracon AB-RTCMC-32.768kHz-B5ZE-S3 RTC/Alarm driver"); | ||
| 1035 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c new file mode 100644 index 000000000000..43e04af39e09 --- /dev/null +++ b/drivers/rtc/rtc-armada38x.c | |||
| @@ -0,0 +1,320 @@ | |||
| 1 | /* | ||
| 2 | * RTC driver for the Armada 38x Marvell SoCs | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Marvell | ||
| 5 | * | ||
| 6 | * Gregory Clement <gregory.clement@free-electrons.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation; either version 2 of the | ||
| 11 | * License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/delay.h> | ||
| 16 | #include <linux/io.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/of.h> | ||
| 19 | #include <linux/platform_device.h> | ||
| 20 | #include <linux/rtc.h> | ||
| 21 | |||
| 22 | #define RTC_STATUS 0x0 | ||
| 23 | #define RTC_STATUS_ALARM1 BIT(0) | ||
| 24 | #define RTC_STATUS_ALARM2 BIT(1) | ||
| 25 | #define RTC_IRQ1_CONF 0x4 | ||
| 26 | #define RTC_IRQ1_AL_EN BIT(0) | ||
| 27 | #define RTC_IRQ1_FREQ_EN BIT(1) | ||
| 28 | #define RTC_IRQ1_FREQ_1HZ BIT(2) | ||
| 29 | #define RTC_TIME 0xC | ||
| 30 | #define RTC_ALARM1 0x10 | ||
| 31 | |||
| 32 | #define SOC_RTC_INTERRUPT 0x8 | ||
| 33 | #define SOC_RTC_ALARM1 BIT(0) | ||
| 34 | #define SOC_RTC_ALARM2 BIT(1) | ||
| 35 | #define SOC_RTC_ALARM1_MASK BIT(2) | ||
| 36 | #define SOC_RTC_ALARM2_MASK BIT(3) | ||
| 37 | |||
| 38 | struct armada38x_rtc { | ||
| 39 | struct rtc_device *rtc_dev; | ||
| 40 | void __iomem *regs; | ||
| 41 | void __iomem *regs_soc; | ||
| 42 | spinlock_t lock; | ||
| 43 | int irq; | ||
| 44 | }; | ||
| 45 | |||
| 46 | /* | ||
| 47 | * According to the datasheet, the OS should wait 5us after every | ||
| 48 | * register write to the RTC hard macro so that the required update | ||
| 49 | * can occur without holding off the system bus | ||
| 50 | */ | ||
| 51 | static void rtc_delayed_write(u32 val, struct armada38x_rtc *rtc, int offset) | ||
| 52 | { | ||
| 53 | writel(val, rtc->regs + offset); | ||
| 54 | udelay(5); | ||
| 55 | } | ||
| 56 | |||
| 57 | static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 58 | { | ||
| 59 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 60 | unsigned long time, time_check, flags; | ||
| 61 | |||
| 62 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 63 | |||
| 64 | time = readl(rtc->regs + RTC_TIME); | ||
| 65 | /* | ||
| 66 | * WA for failing time set attempts. As stated in HW ERRATA if | ||
| 67 | * more than one second between two time reads is detected | ||
| 68 | * then read once again. | ||
| 69 | */ | ||
| 70 | time_check = readl(rtc->regs + RTC_TIME); | ||
| 71 | if ((time_check - time) > 1) | ||
| 72 | time_check = readl(rtc->regs + RTC_TIME); | ||
| 73 | |||
| 74 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 75 | |||
| 76 | rtc_time_to_tm(time_check, tm); | ||
| 77 | |||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
| 82 | { | ||
| 83 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 84 | int ret = 0; | ||
| 85 | unsigned long time, flags; | ||
| 86 | |||
| 87 | ret = rtc_tm_to_time(tm, &time); | ||
| 88 | |||
| 89 | if (ret) | ||
| 90 | goto out; | ||
| 91 | /* | ||
| 92 | * Setting the RTC time not always succeeds. According to the | ||
| 93 | * errata we need to first write on the status register and | ||
| 94 | * then wait for 100ms before writing to the time register to be | ||
| 95 | * sure that the data will be taken into account. | ||
| 96 | */ | ||
| 97 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 98 | |||
| 99 | rtc_delayed_write(0, rtc, RTC_STATUS); | ||
| 100 | |||
| 101 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 102 | |||
| 103 | msleep(100); | ||
| 104 | |||
| 105 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 106 | |||
| 107 | rtc_delayed_write(time, rtc, RTC_TIME); | ||
| 108 | |||
| 109 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 110 | out: | ||
| 111 | return ret; | ||
| 112 | } | ||
| 113 | |||
| 114 | static int armada38x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 115 | { | ||
| 116 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 117 | unsigned long time, flags; | ||
| 118 | u32 val; | ||
| 119 | |||
| 120 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 121 | |||
| 122 | time = readl(rtc->regs + RTC_ALARM1); | ||
| 123 | val = readl(rtc->regs + RTC_IRQ1_CONF) & RTC_IRQ1_AL_EN; | ||
| 124 | |||
| 125 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 126 | |||
| 127 | alrm->enabled = val ? 1 : 0; | ||
| 128 | rtc_time_to_tm(time, &alrm->time); | ||
| 129 | |||
| 130 | return 0; | ||
| 131 | } | ||
| 132 | |||
| 133 | static int armada38x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
| 134 | { | ||
| 135 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 136 | unsigned long time, flags; | ||
| 137 | int ret = 0; | ||
| 138 | u32 val; | ||
| 139 | |||
| 140 | ret = rtc_tm_to_time(&alrm->time, &time); | ||
| 141 | |||
| 142 | if (ret) | ||
| 143 | goto out; | ||
| 144 | |||
| 145 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 146 | |||
| 147 | rtc_delayed_write(time, rtc, RTC_ALARM1); | ||
| 148 | |||
| 149 | if (alrm->enabled) { | ||
| 150 | rtc_delayed_write(RTC_IRQ1_AL_EN, rtc, RTC_IRQ1_CONF); | ||
| 151 | val = readl(rtc->regs_soc + SOC_RTC_INTERRUPT); | ||
| 152 | writel(val | SOC_RTC_ALARM1_MASK, | ||
| 153 | rtc->regs_soc + SOC_RTC_INTERRUPT); | ||
| 154 | } | ||
| 155 | |||
| 156 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 157 | |||
| 158 | out: | ||
| 159 | return ret; | ||
| 160 | } | ||
| 161 | |||
| 162 | static int armada38x_rtc_alarm_irq_enable(struct device *dev, | ||
| 163 | unsigned int enabled) | ||
| 164 | { | ||
| 165 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 166 | unsigned long flags; | ||
| 167 | |||
| 168 | spin_lock_irqsave(&rtc->lock, flags); | ||
| 169 | |||
| 170 | if (enabled) | ||
| 171 | rtc_delayed_write(RTC_IRQ1_AL_EN, rtc, RTC_IRQ1_CONF); | ||
| 172 | else | ||
| 173 | rtc_delayed_write(0, rtc, RTC_IRQ1_CONF); | ||
| 174 | |||
| 175 | spin_unlock_irqrestore(&rtc->lock, flags); | ||
| 176 | |||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | static irqreturn_t armada38x_rtc_alarm_irq(int irq, void *data) | ||
| 181 | { | ||
| 182 | struct armada38x_rtc *rtc = data; | ||
| 183 | u32 val; | ||
| 184 | int event = RTC_IRQF | RTC_AF; | ||
| 185 | |||
| 186 | dev_dbg(&rtc->rtc_dev->dev, "%s:irq(%d)\n", __func__, irq); | ||
| 187 | |||
| 188 | spin_lock(&rtc->lock); | ||
| 189 | |||
| 190 | val = readl(rtc->regs_soc + SOC_RTC_INTERRUPT); | ||
| 191 | |||
| 192 | writel(val & ~SOC_RTC_ALARM1, rtc->regs_soc + SOC_RTC_INTERRUPT); | ||
| 193 | val = readl(rtc->regs + RTC_IRQ1_CONF); | ||
| 194 | /* disable all the interrupts for alarm 1 */ | ||
| 195 | rtc_delayed_write(0, rtc, RTC_IRQ1_CONF); | ||
| 196 | /* Ack the event */ | ||
| 197 | rtc_delayed_write(RTC_STATUS_ALARM1, rtc, RTC_STATUS); | ||
| 198 | |||
| 199 | spin_unlock(&rtc->lock); | ||
| 200 | |||
| 201 | if (val & RTC_IRQ1_FREQ_EN) { | ||
| 202 | if (val & RTC_IRQ1_FREQ_1HZ) | ||
| 203 | event |= RTC_UF; | ||
| 204 | else | ||
| 205 | event |= RTC_PF; | ||
| 206 | } | ||
| 207 | |||
| 208 | rtc_update_irq(rtc->rtc_dev, 1, event); | ||
| 209 | |||
| 210 | return IRQ_HANDLED; | ||
| 211 | } | ||
| 212 | |||
| 213 | static struct rtc_class_ops armada38x_rtc_ops = { | ||
| 214 | .read_time = armada38x_rtc_read_time, | ||
| 215 | .set_time = armada38x_rtc_set_time, | ||
| 216 | .read_alarm = armada38x_rtc_read_alarm, | ||
| 217 | .set_alarm = armada38x_rtc_set_alarm, | ||
| 218 | .alarm_irq_enable = armada38x_rtc_alarm_irq_enable, | ||
| 219 | }; | ||
| 220 | |||
| 221 | static __init int armada38x_rtc_probe(struct platform_device *pdev) | ||
| 222 | { | ||
| 223 | struct resource *res; | ||
| 224 | struct armada38x_rtc *rtc; | ||
| 225 | int ret; | ||
| 226 | |||
| 227 | rtc = devm_kzalloc(&pdev->dev, sizeof(struct armada38x_rtc), | ||
| 228 | GFP_KERNEL); | ||
| 229 | if (!rtc) | ||
| 230 | return -ENOMEM; | ||
| 231 | |||
| 232 | spin_lock_init(&rtc->lock); | ||
| 233 | |||
| 234 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc"); | ||
| 235 | rtc->regs = devm_ioremap_resource(&pdev->dev, res); | ||
| 236 | if (IS_ERR(rtc->regs)) | ||
| 237 | return PTR_ERR(rtc->regs); | ||
| 238 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc-soc"); | ||
| 239 | rtc->regs_soc = devm_ioremap_resource(&pdev->dev, res); | ||
| 240 | if (IS_ERR(rtc->regs_soc)) | ||
| 241 | return PTR_ERR(rtc->regs_soc); | ||
| 242 | |||
| 243 | rtc->irq = platform_get_irq(pdev, 0); | ||
| 244 | |||
| 245 | if (rtc->irq < 0) { | ||
| 246 | dev_err(&pdev->dev, "no irq\n"); | ||
| 247 | return rtc->irq; | ||
| 248 | } | ||
| 249 | if (devm_request_irq(&pdev->dev, rtc->irq, armada38x_rtc_alarm_irq, | ||
| 250 | 0, pdev->name, rtc) < 0) { | ||
| 251 | dev_warn(&pdev->dev, "Interrupt not available.\n"); | ||
| 252 | rtc->irq = -1; | ||
| 253 | /* | ||
| 254 | * If there is no interrupt available then we can't | ||
| 255 | * use the alarm | ||
| 256 | */ | ||
| 257 | armada38x_rtc_ops.set_alarm = NULL; | ||
| 258 | armada38x_rtc_ops.alarm_irq_enable = NULL; | ||
| 259 | } | ||
| 260 | platform_set_drvdata(pdev, rtc); | ||
| 261 | if (rtc->irq != -1) | ||
| 262 | device_init_wakeup(&pdev->dev, 1); | ||
| 263 | |||
| 264 | rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, | ||
| 265 | &armada38x_rtc_ops, THIS_MODULE); | ||
| 266 | if (IS_ERR(rtc->rtc_dev)) { | ||
| 267 | ret = PTR_ERR(rtc->rtc_dev); | ||
| 268 | dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); | ||
| 269 | return ret; | ||
| 270 | } | ||
| 271 | return 0; | ||
| 272 | } | ||
| 273 | |||
| 274 | #ifdef CONFIG_PM_SLEEP | ||
| 275 | static int armada38x_rtc_suspend(struct device *dev) | ||
| 276 | { | ||
| 277 | if (device_may_wakeup(dev)) { | ||
| 278 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 279 | |||
| 280 | return enable_irq_wake(rtc->irq); | ||
| 281 | } | ||
| 282 | |||
| 283 | return 0; | ||
| 284 | } | ||
| 285 | |||
| 286 | static int armada38x_rtc_resume(struct device *dev) | ||
| 287 | { | ||
| 288 | if (device_may_wakeup(dev)) { | ||
| 289 | struct armada38x_rtc *rtc = dev_get_drvdata(dev); | ||
| 290 | |||
| 291 | return disable_irq_wake(rtc->irq); | ||
| 292 | } | ||
| 293 | |||
| 294 | return 0; | ||
| 295 | } | ||
| 296 | #endif | ||
| 297 | |||
| 298 | static SIMPLE_DEV_PM_OPS(armada38x_rtc_pm_ops, | ||
| 299 | armada38x_rtc_suspend, armada38x_rtc_resume); | ||
| 300 | |||
| 301 | #ifdef CONFIG_OF | ||
| 302 | static const struct of_device_id armada38x_rtc_of_match_table[] = { | ||
| 303 | { .compatible = "marvell,armada-380-rtc", }, | ||
| 304 | {} | ||
| 305 | }; | ||
| 306 | #endif | ||
| 307 | |||
| 308 | static struct platform_driver armada38x_rtc_driver = { | ||
| 309 | .driver = { | ||
| 310 | .name = "armada38x-rtc", | ||
| 311 | .pm = &armada38x_rtc_pm_ops, | ||
| 312 | .of_match_table = of_match_ptr(armada38x_rtc_of_match_table), | ||
| 313 | }, | ||
| 314 | }; | ||
| 315 | |||
| 316 | module_platform_driver_probe(armada38x_rtc_driver, armada38x_rtc_probe); | ||
| 317 | |||
| 318 | MODULE_DESCRIPTION("Marvell Armada 38x RTC driver"); | ||
| 319 | MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>"); | ||
| 320 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 6b9aaf1afc72..2183fd2750ab 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c | |||
| @@ -313,7 +313,7 @@ static const struct rtc_class_ops at91_rtc_ops = { | |||
| 313 | .alarm_irq_enable = at91_rtc_alarm_irq_enable, | 313 | .alarm_irq_enable = at91_rtc_alarm_irq_enable, |
| 314 | }; | 314 | }; |
| 315 | 315 | ||
| 316 | static struct regmap_config gpbr_regmap_config = { | 316 | static const struct regmap_config gpbr_regmap_config = { |
| 317 | .reg_bits = 32, | 317 | .reg_bits = 32, |
| 318 | .val_bits = 32, | 318 | .val_bits = 32, |
| 319 | .reg_stride = 4, | 319 | .reg_stride = 4, |
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c index 42f5570f42f8..c666eab98273 100644 --- a/drivers/rtc/rtc-imxdi.c +++ b/drivers/rtc/rtc-imxdi.c | |||
| @@ -50,22 +50,58 @@ | |||
| 50 | #define DCAMR_UNSET 0xFFFFFFFF /* doomsday - 1 sec */ | 50 | #define DCAMR_UNSET 0xFFFFFFFF /* doomsday - 1 sec */ |
| 51 | 51 | ||
| 52 | #define DCR 0x10 /* Control Reg */ | 52 | #define DCR 0x10 /* Control Reg */ |
| 53 | #define DCR_TDCHL (1 << 30) /* Tamper-detect configuration hard lock */ | ||
| 54 | #define DCR_TDCSL (1 << 29) /* Tamper-detect configuration soft lock */ | ||
| 55 | #define DCR_KSSL (1 << 27) /* Key-select soft lock */ | ||
| 56 | #define DCR_MCHL (1 << 20) /* Monotonic-counter hard lock */ | ||
| 57 | #define DCR_MCSL (1 << 19) /* Monotonic-counter soft lock */ | ||
| 58 | #define DCR_TCHL (1 << 18) /* Timer-counter hard lock */ | ||
| 59 | #define DCR_TCSL (1 << 17) /* Timer-counter soft lock */ | ||
| 60 | #define DCR_FSHL (1 << 16) /* Failure state hard lock */ | ||
| 53 | #define DCR_TCE (1 << 3) /* Time Counter Enable */ | 61 | #define DCR_TCE (1 << 3) /* Time Counter Enable */ |
| 62 | #define DCR_MCE (1 << 2) /* Monotonic Counter Enable */ | ||
| 54 | 63 | ||
| 55 | #define DSR 0x14 /* Status Reg */ | 64 | #define DSR 0x14 /* Status Reg */ |
| 56 | #define DSR_WBF (1 << 10) /* Write Busy Flag */ | 65 | #define DSR_WTD (1 << 23) /* Wire-mesh tamper detected */ |
| 57 | #define DSR_WNF (1 << 9) /* Write Next Flag */ | 66 | #define DSR_ETBD (1 << 22) /* External tamper B detected */ |
| 58 | #define DSR_WCF (1 << 8) /* Write Complete Flag */ | 67 | #define DSR_ETAD (1 << 21) /* External tamper A detected */ |
| 68 | #define DSR_EBD (1 << 20) /* External boot detected */ | ||
| 69 | #define DSR_SAD (1 << 19) /* SCC alarm detected */ | ||
| 70 | #define DSR_TTD (1 << 18) /* Temperatur tamper detected */ | ||
| 71 | #define DSR_CTD (1 << 17) /* Clock tamper detected */ | ||
| 72 | #define DSR_VTD (1 << 16) /* Voltage tamper detected */ | ||
| 73 | #define DSR_WBF (1 << 10) /* Write Busy Flag (synchronous) */ | ||
| 74 | #define DSR_WNF (1 << 9) /* Write Next Flag (synchronous) */ | ||
| 75 | #define DSR_WCF (1 << 8) /* Write Complete Flag (synchronous)*/ | ||
| 59 | #define DSR_WEF (1 << 7) /* Write Error Flag */ | 76 | #define DSR_WEF (1 << 7) /* Write Error Flag */ |
| 60 | #define DSR_CAF (1 << 4) /* Clock Alarm Flag */ | 77 | #define DSR_CAF (1 << 4) /* Clock Alarm Flag */ |
| 78 | #define DSR_MCO (1 << 3) /* monotonic counter overflow */ | ||
| 79 | #define DSR_TCO (1 << 2) /* time counter overflow */ | ||
| 61 | #define DSR_NVF (1 << 1) /* Non-Valid Flag */ | 80 | #define DSR_NVF (1 << 1) /* Non-Valid Flag */ |
| 62 | #define DSR_SVF (1 << 0) /* Security Violation Flag */ | 81 | #define DSR_SVF (1 << 0) /* Security Violation Flag */ |
| 63 | 82 | ||
| 64 | #define DIER 0x18 /* Interrupt Enable Reg */ | 83 | #define DIER 0x18 /* Interrupt Enable Reg (synchronous) */ |
| 65 | #define DIER_WNIE (1 << 9) /* Write Next Interrupt Enable */ | 84 | #define DIER_WNIE (1 << 9) /* Write Next Interrupt Enable */ |
| 66 | #define DIER_WCIE (1 << 8) /* Write Complete Interrupt Enable */ | 85 | #define DIER_WCIE (1 << 8) /* Write Complete Interrupt Enable */ |
| 67 | #define DIER_WEIE (1 << 7) /* Write Error Interrupt Enable */ | 86 | #define DIER_WEIE (1 << 7) /* Write Error Interrupt Enable */ |
| 68 | #define DIER_CAIE (1 << 4) /* Clock Alarm Interrupt Enable */ | 87 | #define DIER_CAIE (1 << 4) /* Clock Alarm Interrupt Enable */ |
| 88 | #define DIER_SVIE (1 << 0) /* Security-violation Interrupt Enable */ | ||
| 89 | |||
| 90 | #define DMCR 0x1c /* DryIce Monotonic Counter Reg */ | ||
| 91 | |||
| 92 | #define DTCR 0x28 /* DryIce Tamper Configuration Reg */ | ||
| 93 | #define DTCR_MOE (1 << 9) /* monotonic overflow enabled */ | ||
| 94 | #define DTCR_TOE (1 << 8) /* time overflow enabled */ | ||
| 95 | #define DTCR_WTE (1 << 7) /* wire-mesh tamper enabled */ | ||
| 96 | #define DTCR_ETBE (1 << 6) /* external B tamper enabled */ | ||
| 97 | #define DTCR_ETAE (1 << 5) /* external A tamper enabled */ | ||
| 98 | #define DTCR_EBE (1 << 4) /* external boot tamper enabled */ | ||
| 99 | #define DTCR_SAIE (1 << 3) /* SCC enabled */ | ||
| 100 | #define DTCR_TTE (1 << 2) /* temperature tamper enabled */ | ||
| 101 | #define DTCR_CTE (1 << 1) /* clock tamper enabled */ | ||
| 102 | #define DTCR_VTE (1 << 0) /* voltage tamper enabled */ | ||
| 103 | |||
| 104 | #define DGPR 0x3c /* DryIce General Purpose Reg */ | ||
| 69 | 105 | ||
| 70 | /** | 106 | /** |
| 71 | * struct imxdi_dev - private imxdi rtc data | 107 | * struct imxdi_dev - private imxdi rtc data |
| @@ -313,7 +349,7 @@ static irqreturn_t dryice_norm_irq(int irq, void *dev_id) | |||
| 313 | dier = __raw_readl(imxdi->ioaddr + DIER); | 349 | dier = __raw_readl(imxdi->ioaddr + DIER); |
| 314 | 350 | ||
| 315 | /* handle write complete and write error cases */ | 351 | /* handle write complete and write error cases */ |
| 316 | if ((dier & DIER_WCIE)) { | 352 | if (dier & DIER_WCIE) { |
| 317 | /*If the write wait queue is empty then there is no pending | 353 | /*If the write wait queue is empty then there is no pending |
| 318 | operations. It means the interrupt is for DryIce -Security. | 354 | operations. It means the interrupt is for DryIce -Security. |
| 319 | IRQ must be returned as none.*/ | 355 | IRQ must be returned as none.*/ |
| @@ -322,7 +358,7 @@ static irqreturn_t dryice_norm_irq(int irq, void *dev_id) | |||
| 322 | 358 | ||
| 323 | /* DSR_WCF clears itself on DSR read */ | 359 | /* DSR_WCF clears itself on DSR read */ |
| 324 | dsr = __raw_readl(imxdi->ioaddr + DSR); | 360 | dsr = __raw_readl(imxdi->ioaddr + DSR); |
| 325 | if ((dsr & (DSR_WCF | DSR_WEF))) { | 361 | if (dsr & (DSR_WCF | DSR_WEF)) { |
| 326 | /* mask the interrupt */ | 362 | /* mask the interrupt */ |
| 327 | di_int_disable(imxdi, DIER_WCIE); | 363 | di_int_disable(imxdi, DIER_WCIE); |
| 328 | 364 | ||
| @@ -335,7 +371,7 @@ static irqreturn_t dryice_norm_irq(int irq, void *dev_id) | |||
| 335 | } | 371 | } |
| 336 | 372 | ||
| 337 | /* handle the alarm case */ | 373 | /* handle the alarm case */ |
| 338 | if ((dier & DIER_CAIE)) { | 374 | if (dier & DIER_CAIE) { |
| 339 | /* DSR_WCF clears itself on DSR read */ | 375 | /* DSR_WCF clears itself on DSR read */ |
| 340 | dsr = __raw_readl(imxdi->ioaddr + DSR); | 376 | dsr = __raw_readl(imxdi->ioaddr + DSR); |
| 341 | if (dsr & DSR_CAF) { | 377 | if (dsr & DSR_CAF) { |
diff --git a/drivers/rtc/rtc-isl12057.c b/drivers/rtc/rtc-isl12057.c index 6e1fcfb5d7e6..b8f862953f7f 100644 --- a/drivers/rtc/rtc-isl12057.c +++ b/drivers/rtc/rtc-isl12057.c | |||
| @@ -79,8 +79,10 @@ | |||
| 79 | #define ISL12057_MEM_MAP_LEN 0x10 | 79 | #define ISL12057_MEM_MAP_LEN 0x10 |
| 80 | 80 | ||
| 81 | struct isl12057_rtc_data { | 81 | struct isl12057_rtc_data { |
| 82 | struct rtc_device *rtc; | ||
| 82 | struct regmap *regmap; | 83 | struct regmap *regmap; |
| 83 | struct mutex lock; | 84 | struct mutex lock; |
| 85 | int irq; | ||
| 84 | }; | 86 | }; |
| 85 | 87 | ||
| 86 | static void isl12057_rtc_regs_to_tm(struct rtc_time *tm, u8 *regs) | 88 | static void isl12057_rtc_regs_to_tm(struct rtc_time *tm, u8 *regs) |
| @@ -160,14 +162,47 @@ static int isl12057_i2c_validate_chip(struct regmap *regmap) | |||
| 160 | return 0; | 162 | return 0; |
| 161 | } | 163 | } |
| 162 | 164 | ||
| 163 | static int isl12057_rtc_read_time(struct device *dev, struct rtc_time *tm) | 165 | static int _isl12057_rtc_clear_alarm(struct device *dev) |
| 166 | { | ||
| 167 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 168 | int ret; | ||
| 169 | |||
| 170 | ret = regmap_update_bits(data->regmap, ISL12057_REG_SR, | ||
| 171 | ISL12057_REG_SR_A1F, 0); | ||
| 172 | if (ret) | ||
| 173 | dev_err(dev, "%s: clearing alarm failed (%d)\n", __func__, ret); | ||
| 174 | |||
| 175 | return ret; | ||
| 176 | } | ||
| 177 | |||
| 178 | static int _isl12057_rtc_update_alarm(struct device *dev, int enable) | ||
| 179 | { | ||
| 180 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 181 | int ret; | ||
| 182 | |||
| 183 | ret = regmap_update_bits(data->regmap, ISL12057_REG_INT, | ||
| 184 | ISL12057_REG_INT_A1IE, | ||
| 185 | enable ? ISL12057_REG_INT_A1IE : 0); | ||
| 186 | if (ret) | ||
| 187 | dev_err(dev, "%s: changing alarm interrupt flag failed (%d)\n", | ||
| 188 | __func__, ret); | ||
| 189 | |||
| 190 | return ret; | ||
| 191 | } | ||
| 192 | |||
| 193 | /* | ||
| 194 | * Note: as we only read from device and do not perform any update, there is | ||
| 195 | * no need for an equivalent function which would try and get driver's main | ||
| 196 | * lock. Here, it is safe for everyone if we just use regmap internal lock | ||
| 197 | * on the device when reading. | ||
| 198 | */ | ||
| 199 | static int _isl12057_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 164 | { | 200 | { |
| 165 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | 201 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); |
| 166 | u8 regs[ISL12057_RTC_SEC_LEN]; | 202 | u8 regs[ISL12057_RTC_SEC_LEN]; |
| 167 | unsigned int sr; | 203 | unsigned int sr; |
| 168 | int ret; | 204 | int ret; |
| 169 | 205 | ||
| 170 | mutex_lock(&data->lock); | ||
| 171 | ret = regmap_read(data->regmap, ISL12057_REG_SR, &sr); | 206 | ret = regmap_read(data->regmap, ISL12057_REG_SR, &sr); |
| 172 | if (ret) { | 207 | if (ret) { |
| 173 | dev_err(dev, "%s: unable to read oscillator status flag (%d)\n", | 208 | dev_err(dev, "%s: unable to read oscillator status flag (%d)\n", |
| @@ -187,8 +222,6 @@ static int isl12057_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 187 | __func__, ret); | 222 | __func__, ret); |
| 188 | 223 | ||
| 189 | out: | 224 | out: |
| 190 | mutex_unlock(&data->lock); | ||
| 191 | |||
| 192 | if (ret) | 225 | if (ret) |
| 193 | return ret; | 226 | return ret; |
| 194 | 227 | ||
| @@ -197,6 +230,168 @@ out: | |||
| 197 | return rtc_valid_tm(tm); | 230 | return rtc_valid_tm(tm); |
| 198 | } | 231 | } |
| 199 | 232 | ||
| 233 | static int isl12057_rtc_update_alarm(struct device *dev, int enable) | ||
| 234 | { | ||
| 235 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 236 | int ret; | ||
| 237 | |||
| 238 | mutex_lock(&data->lock); | ||
| 239 | ret = _isl12057_rtc_update_alarm(dev, enable); | ||
| 240 | mutex_unlock(&data->lock); | ||
| 241 | |||
| 242 | return ret; | ||
| 243 | } | ||
| 244 | |||
| 245 | static int isl12057_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 246 | { | ||
| 247 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 248 | struct rtc_time rtc_tm, *alarm_tm = &alarm->time; | ||
| 249 | unsigned long rtc_secs, alarm_secs; | ||
| 250 | u8 regs[ISL12057_A1_SEC_LEN]; | ||
| 251 | unsigned int ir; | ||
| 252 | int ret; | ||
| 253 | |||
| 254 | mutex_lock(&data->lock); | ||
| 255 | ret = regmap_bulk_read(data->regmap, ISL12057_REG_A1_SC, regs, | ||
| 256 | ISL12057_A1_SEC_LEN); | ||
| 257 | if (ret) { | ||
| 258 | dev_err(dev, "%s: reading alarm section failed (%d)\n", | ||
| 259 | __func__, ret); | ||
| 260 | goto err_unlock; | ||
| 261 | } | ||
| 262 | |||
| 263 | alarm_tm->tm_sec = bcd2bin(regs[0] & 0x7f); | ||
| 264 | alarm_tm->tm_min = bcd2bin(regs[1] & 0x7f); | ||
| 265 | alarm_tm->tm_hour = bcd2bin(regs[2] & 0x3f); | ||
| 266 | alarm_tm->tm_mday = bcd2bin(regs[3] & 0x3f); | ||
| 267 | alarm_tm->tm_wday = -1; | ||
| 268 | |||
| 269 | /* | ||
| 270 | * The alarm section does not store year/month. We use the ones in rtc | ||
| 271 | * section as a basis and increment month and then year if needed to get | ||
| 272 | * alarm after current time. | ||
| 273 | */ | ||
| 274 | ret = _isl12057_rtc_read_time(dev, &rtc_tm); | ||
| 275 | if (ret) | ||
| 276 | goto err_unlock; | ||
| 277 | |||
| 278 | alarm_tm->tm_year = rtc_tm.tm_year; | ||
| 279 | alarm_tm->tm_mon = rtc_tm.tm_mon; | ||
| 280 | |||
| 281 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 282 | if (ret) | ||
| 283 | goto err_unlock; | ||
| 284 | |||
| 285 | ret = rtc_tm_to_time(alarm_tm, &alarm_secs); | ||
| 286 | if (ret) | ||
| 287 | goto err_unlock; | ||
| 288 | |||
| 289 | if (alarm_secs < rtc_secs) { | ||
| 290 | if (alarm_tm->tm_mon == 11) { | ||
| 291 | alarm_tm->tm_mon = 0; | ||
| 292 | alarm_tm->tm_year += 1; | ||
| 293 | } else { | ||
| 294 | alarm_tm->tm_mon += 1; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | ret = regmap_read(data->regmap, ISL12057_REG_INT, &ir); | ||
| 299 | if (ret) { | ||
| 300 | dev_err(dev, "%s: reading alarm interrupt flag failed (%d)\n", | ||
| 301 | __func__, ret); | ||
| 302 | goto err_unlock; | ||
| 303 | } | ||
| 304 | |||
| 305 | alarm->enabled = !!(ir & ISL12057_REG_INT_A1IE); | ||
| 306 | |||
| 307 | err_unlock: | ||
| 308 | mutex_unlock(&data->lock); | ||
| 309 | |||
| 310 | return ret; | ||
| 311 | } | ||
| 312 | |||
| 313 | static int isl12057_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 314 | { | ||
| 315 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 316 | struct rtc_time *alarm_tm = &alarm->time; | ||
| 317 | unsigned long rtc_secs, alarm_secs; | ||
| 318 | u8 regs[ISL12057_A1_SEC_LEN]; | ||
| 319 | struct rtc_time rtc_tm; | ||
| 320 | int ret, enable = 1; | ||
| 321 | |||
| 322 | mutex_lock(&data->lock); | ||
| 323 | ret = _isl12057_rtc_read_time(dev, &rtc_tm); | ||
| 324 | if (ret) | ||
| 325 | goto err_unlock; | ||
| 326 | |||
| 327 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 328 | if (ret) | ||
| 329 | goto err_unlock; | ||
| 330 | |||
| 331 | ret = rtc_tm_to_time(alarm_tm, &alarm_secs); | ||
| 332 | if (ret) | ||
| 333 | goto err_unlock; | ||
| 334 | |||
| 335 | /* If alarm time is before current time, disable the alarm */ | ||
| 336 | if (!alarm->enabled || alarm_secs <= rtc_secs) { | ||
| 337 | enable = 0; | ||
| 338 | } else { | ||
| 339 | /* | ||
| 340 | * Chip only support alarms up to one month in the future. Let's | ||
| 341 | * return an error if we get something after that limit. | ||
| 342 | * Comparison is done by incrementing rtc_tm month field by one | ||
| 343 | * and checking alarm value is still below. | ||
| 344 | */ | ||
| 345 | if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ | ||
| 346 | rtc_tm.tm_mon = 0; | ||
| 347 | rtc_tm.tm_year += 1; | ||
| 348 | } else { | ||
| 349 | rtc_tm.tm_mon += 1; | ||
| 350 | } | ||
| 351 | |||
| 352 | ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); | ||
| 353 | if (ret) | ||
| 354 | goto err_unlock; | ||
| 355 | |||
| 356 | if (alarm_secs > rtc_secs) { | ||
| 357 | dev_err(dev, "%s: max for alarm is one month (%d)\n", | ||
| 358 | __func__, ret); | ||
| 359 | ret = -EINVAL; | ||
| 360 | goto err_unlock; | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | /* Disable the alarm before modifying it */ | ||
| 365 | ret = _isl12057_rtc_update_alarm(dev, 0); | ||
| 366 | if (ret < 0) { | ||
| 367 | dev_err(dev, "%s: unable to disable the alarm (%d)\n", | ||
| 368 | __func__, ret); | ||
| 369 | goto err_unlock; | ||
| 370 | } | ||
| 371 | |||
| 372 | /* Program alarm registers */ | ||
| 373 | regs[0] = bin2bcd(alarm_tm->tm_sec) & 0x7f; | ||
| 374 | regs[1] = bin2bcd(alarm_tm->tm_min) & 0x7f; | ||
| 375 | regs[2] = bin2bcd(alarm_tm->tm_hour) & 0x3f; | ||
| 376 | regs[3] = bin2bcd(alarm_tm->tm_mday) & 0x3f; | ||
| 377 | |||
| 378 | ret = regmap_bulk_write(data->regmap, ISL12057_REG_A1_SC, regs, | ||
| 379 | ISL12057_A1_SEC_LEN); | ||
| 380 | if (ret < 0) { | ||
| 381 | dev_err(dev, "%s: writing alarm section failed (%d)\n", | ||
| 382 | __func__, ret); | ||
| 383 | goto err_unlock; | ||
| 384 | } | ||
| 385 | |||
| 386 | /* Enable or disable alarm */ | ||
| 387 | ret = _isl12057_rtc_update_alarm(dev, enable); | ||
| 388 | |||
| 389 | err_unlock: | ||
| 390 | mutex_unlock(&data->lock); | ||
| 391 | |||
| 392 | return ret; | ||
| 393 | } | ||
| 394 | |||
| 200 | static int isl12057_rtc_set_time(struct device *dev, struct rtc_time *tm) | 395 | static int isl12057_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 201 | { | 396 | { |
| 202 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | 397 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); |
| @@ -262,12 +457,85 @@ static int isl12057_check_rtc_status(struct device *dev, struct regmap *regmap) | |||
| 262 | return 0; | 457 | return 0; |
| 263 | } | 458 | } |
| 264 | 459 | ||
| 460 | #ifdef CONFIG_OF | ||
| 461 | /* | ||
| 462 | * One would expect the device to be marked as a wakeup source only | ||
| 463 | * when an IRQ pin of the RTC is routed to an interrupt line of the | ||
| 464 | * CPU. In practice, such an IRQ pin can be connected to a PMIC and | ||
| 465 | * this allows the device to be powered up when RTC alarm rings. This | ||
| 466 | * is for instance the case on ReadyNAS 102, 104 and 2120. On those | ||
| 467 | * devices with no IRQ driectly connected to the SoC, the RTC chip | ||
| 468 | * can be forced as a wakeup source by stating that explicitly in | ||
| 469 | * the device's .dts file using the "isil,irq2-can-wakeup-machine" | ||
| 470 | * boolean property. This will guarantee 'wakealarm' sysfs entry is | ||
| 471 | * available on the device. | ||
| 472 | * | ||
| 473 | * The function below returns 1, i.e. the capability of the chip to | ||
| 474 | * wakeup the device, based on IRQ availability or if the boolean | ||
| 475 | * property has been set in the .dts file. Otherwise, it returns 0. | ||
| 476 | */ | ||
| 477 | |||
| 478 | static bool isl12057_can_wakeup_machine(struct device *dev) | ||
| 479 | { | ||
| 480 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 481 | |||
| 482 | return (data->irq || of_property_read_bool(dev->of_node, | ||
| 483 | "isil,irq2-can-wakeup-machine")); | ||
| 484 | } | ||
| 485 | #else | ||
| 486 | static bool isl12057_can_wakeup_machine(struct device *dev) | ||
| 487 | { | ||
| 488 | struct isl12057_rtc_data *data = dev_get_drvdata(dev); | ||
| 489 | |||
| 490 | return !!data->irq; | ||
| 491 | } | ||
| 492 | #endif | ||
| 493 | |||
| 494 | static int isl12057_rtc_alarm_irq_enable(struct device *dev, | ||
| 495 | unsigned int enable) | ||
| 496 | { | ||
| 497 | struct isl12057_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 498 | int ret = -ENOTTY; | ||
| 499 | |||
| 500 | if (rtc_data->irq) | ||
| 501 | ret = isl12057_rtc_update_alarm(dev, enable); | ||
| 502 | |||
| 503 | return ret; | ||
| 504 | } | ||
| 505 | |||
| 506 | static irqreturn_t isl12057_rtc_interrupt(int irq, void *data) | ||
| 507 | { | ||
| 508 | struct i2c_client *client = data; | ||
| 509 | struct isl12057_rtc_data *rtc_data = dev_get_drvdata(&client->dev); | ||
| 510 | struct rtc_device *rtc = rtc_data->rtc; | ||
| 511 | int ret, handled = IRQ_NONE; | ||
| 512 | unsigned int sr; | ||
| 513 | |||
| 514 | ret = regmap_read(rtc_data->regmap, ISL12057_REG_SR, &sr); | ||
| 515 | if (!ret && (sr & ISL12057_REG_SR_A1F)) { | ||
| 516 | dev_dbg(&client->dev, "RTC alarm!\n"); | ||
| 517 | |||
| 518 | rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF); | ||
| 519 | |||
| 520 | /* Acknowledge and disable the alarm */ | ||
| 521 | _isl12057_rtc_clear_alarm(&client->dev); | ||
| 522 | _isl12057_rtc_update_alarm(&client->dev, 0); | ||
| 523 | |||
| 524 | handled = IRQ_HANDLED; | ||
| 525 | } | ||
| 526 | |||
| 527 | return handled; | ||
| 528 | } | ||
| 529 | |||
| 265 | static const struct rtc_class_ops rtc_ops = { | 530 | static const struct rtc_class_ops rtc_ops = { |
| 266 | .read_time = isl12057_rtc_read_time, | 531 | .read_time = _isl12057_rtc_read_time, |
| 267 | .set_time = isl12057_rtc_set_time, | 532 | .set_time = isl12057_rtc_set_time, |
| 533 | .read_alarm = isl12057_rtc_read_alarm, | ||
| 534 | .set_alarm = isl12057_rtc_set_alarm, | ||
| 535 | .alarm_irq_enable = isl12057_rtc_alarm_irq_enable, | ||
| 268 | }; | 536 | }; |
| 269 | 537 | ||
| 270 | static struct regmap_config isl12057_rtc_regmap_config = { | 538 | static const struct regmap_config isl12057_rtc_regmap_config = { |
| 271 | .reg_bits = 8, | 539 | .reg_bits = 8, |
| 272 | .val_bits = 8, | 540 | .val_bits = 8, |
| 273 | }; | 541 | }; |
| @@ -277,7 +545,6 @@ static int isl12057_probe(struct i2c_client *client, | |||
| 277 | { | 545 | { |
| 278 | struct device *dev = &client->dev; | 546 | struct device *dev = &client->dev; |
| 279 | struct isl12057_rtc_data *data; | 547 | struct isl12057_rtc_data *data; |
| 280 | struct rtc_device *rtc; | ||
| 281 | struct regmap *regmap; | 548 | struct regmap *regmap; |
| 282 | int ret; | 549 | int ret; |
| 283 | 550 | ||
| @@ -310,9 +577,70 @@ static int isl12057_probe(struct i2c_client *client, | |||
| 310 | data->regmap = regmap; | 577 | data->regmap = regmap; |
| 311 | dev_set_drvdata(dev, data); | 578 | dev_set_drvdata(dev, data); |
| 312 | 579 | ||
| 313 | rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops, THIS_MODULE); | 580 | if (client->irq > 0) { |
| 314 | return PTR_ERR_OR_ZERO(rtc); | 581 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
| 582 | isl12057_rtc_interrupt, | ||
| 583 | IRQF_SHARED|IRQF_ONESHOT, | ||
| 584 | DRV_NAME, client); | ||
| 585 | if (!ret) | ||
| 586 | data->irq = client->irq; | ||
| 587 | else | ||
| 588 | dev_err(dev, "%s: irq %d unavailable (%d)\n", __func__, | ||
| 589 | client->irq, ret); | ||
| 590 | } | ||
| 591 | |||
| 592 | if (isl12057_can_wakeup_machine(dev)) | ||
| 593 | device_init_wakeup(dev, true); | ||
| 594 | |||
| 595 | data->rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops, | ||
| 596 | THIS_MODULE); | ||
| 597 | ret = PTR_ERR_OR_ZERO(data->rtc); | ||
| 598 | if (ret) { | ||
| 599 | dev_err(dev, "%s: unable to register RTC device (%d)\n", | ||
| 600 | __func__, ret); | ||
| 601 | goto err; | ||
| 602 | } | ||
| 603 | |||
| 604 | /* We cannot support UIE mode if we do not have an IRQ line */ | ||
| 605 | if (!data->irq) | ||
| 606 | data->rtc->uie_unsupported = 1; | ||
| 607 | |||
| 608 | err: | ||
| 609 | return ret; | ||
| 610 | } | ||
| 611 | |||
| 612 | static int isl12057_remove(struct i2c_client *client) | ||
| 613 | { | ||
| 614 | if (isl12057_can_wakeup_machine(&client->dev)) | ||
| 615 | device_init_wakeup(&client->dev, false); | ||
| 616 | |||
| 617 | return 0; | ||
| 618 | } | ||
| 619 | |||
| 620 | #ifdef CONFIG_PM_SLEEP | ||
| 621 | static int isl12057_rtc_suspend(struct device *dev) | ||
| 622 | { | ||
| 623 | struct isl12057_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 624 | |||
| 625 | if (rtc_data->irq && device_may_wakeup(dev)) | ||
| 626 | return enable_irq_wake(rtc_data->irq); | ||
| 627 | |||
| 628 | return 0; | ||
| 629 | } | ||
| 630 | |||
| 631 | static int isl12057_rtc_resume(struct device *dev) | ||
| 632 | { | ||
| 633 | struct isl12057_rtc_data *rtc_data = dev_get_drvdata(dev); | ||
| 634 | |||
| 635 | if (rtc_data->irq && device_may_wakeup(dev)) | ||
| 636 | return disable_irq_wake(rtc_data->irq); | ||
| 637 | |||
| 638 | return 0; | ||
| 315 | } | 639 | } |
| 640 | #endif | ||
| 641 | |||
| 642 | static SIMPLE_DEV_PM_OPS(isl12057_rtc_pm_ops, isl12057_rtc_suspend, | ||
| 643 | isl12057_rtc_resume); | ||
| 316 | 644 | ||
| 317 | #ifdef CONFIG_OF | 645 | #ifdef CONFIG_OF |
| 318 | static const struct of_device_id isl12057_dt_match[] = { | 646 | static const struct of_device_id isl12057_dt_match[] = { |
| @@ -331,9 +659,11 @@ static struct i2c_driver isl12057_driver = { | |||
| 331 | .driver = { | 659 | .driver = { |
| 332 | .name = DRV_NAME, | 660 | .name = DRV_NAME, |
| 333 | .owner = THIS_MODULE, | 661 | .owner = THIS_MODULE, |
| 662 | .pm = &isl12057_rtc_pm_ops, | ||
| 334 | .of_match_table = of_match_ptr(isl12057_dt_match), | 663 | .of_match_table = of_match_ptr(isl12057_dt_match), |
| 335 | }, | 664 | }, |
| 336 | .probe = isl12057_probe, | 665 | .probe = isl12057_probe, |
| 666 | .remove = isl12057_remove, | ||
| 337 | .id_table = isl12057_id, | 667 | .id_table = isl12057_id, |
| 338 | }; | 668 | }; |
| 339 | module_i2c_driver(isl12057_driver); | 669 | module_i2c_driver(isl12057_driver); |
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c index d1953bb244c5..8a7556cbcb7f 100644 --- a/drivers/rtc/rtc-pcf2123.c +++ b/drivers/rtc/rtc-pcf2123.c | |||
| @@ -38,6 +38,7 @@ | |||
| 38 | #include <linux/errno.h> | 38 | #include <linux/errno.h> |
| 39 | #include <linux/init.h> | 39 | #include <linux/init.h> |
| 40 | #include <linux/kernel.h> | 40 | #include <linux/kernel.h> |
| 41 | #include <linux/of.h> | ||
| 41 | #include <linux/string.h> | 42 | #include <linux/string.h> |
| 42 | #include <linux/slab.h> | 43 | #include <linux/slab.h> |
| 43 | #include <linux/rtc.h> | 44 | #include <linux/rtc.h> |
| @@ -340,10 +341,19 @@ static int pcf2123_remove(struct spi_device *spi) | |||
| 340 | return 0; | 341 | return 0; |
| 341 | } | 342 | } |
| 342 | 343 | ||
| 344 | #ifdef CONFIG_OF | ||
| 345 | static const struct of_device_id pcf2123_dt_ids[] = { | ||
| 346 | { .compatible = "nxp,rtc-pcf2123", }, | ||
| 347 | { /* sentinel */ } | ||
| 348 | }; | ||
| 349 | MODULE_DEVICE_TABLE(of, pcf2123_dt_ids); | ||
| 350 | #endif | ||
| 351 | |||
| 343 | static struct spi_driver pcf2123_driver = { | 352 | static struct spi_driver pcf2123_driver = { |
| 344 | .driver = { | 353 | .driver = { |
| 345 | .name = "rtc-pcf2123", | 354 | .name = "rtc-pcf2123", |
| 346 | .owner = THIS_MODULE, | 355 | .owner = THIS_MODULE, |
| 356 | .of_match_table = of_match_ptr(pcf2123_dt_ids), | ||
| 347 | }, | 357 | }, |
| 348 | .probe = pcf2123_probe, | 358 | .probe = pcf2123_probe, |
| 349 | .remove = pcf2123_remove, | 359 | .remove = pcf2123_remove, |
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c index df42257668ac..91ca0bc1b484 100644 --- a/drivers/rtc/rtc-rk808.c +++ b/drivers/rtc/rtc-rk808.c | |||
| @@ -67,15 +67,21 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm) | |||
| 67 | /* Force an update of the shadowed registers right now */ | 67 | /* Force an update of the shadowed registers right now */ |
| 68 | ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, | 68 | ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, |
| 69 | BIT_RTC_CTRL_REG_RTC_GET_TIME, | 69 | BIT_RTC_CTRL_REG_RTC_GET_TIME, |
| 70 | 0); | 70 | BIT_RTC_CTRL_REG_RTC_GET_TIME); |
| 71 | if (ret) { | 71 | if (ret) { |
| 72 | dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); | 72 | dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); |
| 73 | return ret; | 73 | return ret; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | /* | ||
| 77 | * After we set the GET_TIME bit, the rtc time can't be read | ||
| 78 | * immediately. So we should wait up to 31.25 us, about one cycle of | ||
| 79 | * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer | ||
| 80 | * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency. | ||
| 81 | */ | ||
| 76 | ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, | 82 | ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, |
| 77 | BIT_RTC_CTRL_REG_RTC_GET_TIME, | 83 | BIT_RTC_CTRL_REG_RTC_GET_TIME, |
| 78 | BIT_RTC_CTRL_REG_RTC_GET_TIME); | 84 | 0); |
| 79 | if (ret) { | 85 | if (ret) { |
| 80 | dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); | 86 | dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); |
| 81 | return ret; | 87 | return ret; |
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index f3193406776c..96241b20fd2c 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c | |||
| @@ -48,7 +48,6 @@ static unsigned int be_iopoll_budget = 10; | |||
| 48 | static unsigned int be_max_phys_size = 64; | 48 | static unsigned int be_max_phys_size = 64; |
| 49 | static unsigned int enable_msix = 1; | 49 | static unsigned int enable_msix = 1; |
| 50 | 50 | ||
| 51 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); | ||
| 52 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); | 51 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); |
| 53 | MODULE_VERSION(BUILD_STR); | 52 | MODULE_VERSION(BUILD_STR); |
| 54 | MODULE_AUTHOR("Emulex Corporation"); | 53 | MODULE_AUTHOR("Emulex Corporation"); |
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 113232135d27..1f8e2dc9c616 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
| @@ -4658,10 +4658,10 @@ static ssize_t map_show(struct device_driver *ddp, char *buf) | |||
| 4658 | return scnprintf(buf, PAGE_SIZE, "0-%u\n", | 4658 | return scnprintf(buf, PAGE_SIZE, "0-%u\n", |
| 4659 | sdebug_store_sectors); | 4659 | sdebug_store_sectors); |
| 4660 | 4660 | ||
| 4661 | count = bitmap_scnlistprintf(buf, PAGE_SIZE, map_storep, map_size); | 4661 | count = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", |
| 4662 | 4662 | (int)map_size, map_storep); | |
| 4663 | buf[count++] = '\n'; | 4663 | buf[count++] = '\n'; |
| 4664 | buf[count++] = 0; | 4664 | buf[count] = '\0'; |
| 4665 | 4665 | ||
| 4666 | return count; | 4666 | return count; |
| 4667 | } | 4667 | } |
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c index ba61dae9e4d2..774b89d28fae 100644 --- a/drivers/usb/host/whci/debug.c +++ b/drivers/usb/host/whci/debug.c | |||
| @@ -86,17 +86,14 @@ static void qset_print(struct seq_file *s, struct whc_qset *qset) | |||
| 86 | static int di_print(struct seq_file *s, void *p) | 86 | static int di_print(struct seq_file *s, void *p) |
| 87 | { | 87 | { |
| 88 | struct whc *whc = s->private; | 88 | struct whc *whc = s->private; |
| 89 | char buf[72]; | ||
| 90 | int d; | 89 | int d; |
| 91 | 90 | ||
| 92 | for (d = 0; d < whc->n_devices; d++) { | 91 | for (d = 0; d < whc->n_devices; d++) { |
| 93 | struct di_buf_entry *di = &whc->di_buf[d]; | 92 | struct di_buf_entry *di = &whc->di_buf[d]; |
| 94 | 93 | ||
| 95 | bitmap_scnprintf(buf, sizeof(buf), | ||
| 96 | (unsigned long *)di->availability_info, UWB_NUM_MAS); | ||
| 97 | |||
| 98 | seq_printf(s, "DI[%d]\n", d); | 94 | seq_printf(s, "DI[%d]\n", d); |
| 99 | seq_printf(s, " availability: %s\n", buf); | 95 | seq_printf(s, " availability: %*pb\n", |
| 96 | UWB_NUM_MAS, (unsigned long *)di->availability_info); | ||
| 100 | seq_printf(s, " %c%c key idx: %d dev addr: %d\n", | 97 | seq_printf(s, " %c%c key idx: %d dev addr: %d\n", |
| 101 | (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ', | 98 | (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ', |
| 102 | (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ', | 99 | (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ', |
diff --git a/drivers/usb/wusbcore/reservation.c b/drivers/usb/wusbcore/reservation.c index d5efd0f07d2b..7b1b2e2fb673 100644 --- a/drivers/usb/wusbcore/reservation.c +++ b/drivers/usb/wusbcore/reservation.c | |||
| @@ -49,14 +49,13 @@ static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv) | |||
| 49 | struct wusbhc *wusbhc = rsv->pal_priv; | 49 | struct wusbhc *wusbhc = rsv->pal_priv; |
| 50 | struct device *dev = wusbhc->dev; | 50 | struct device *dev = wusbhc->dev; |
| 51 | struct uwb_mas_bm mas; | 51 | struct uwb_mas_bm mas; |
| 52 | char buf[72]; | ||
| 53 | 52 | ||
| 54 | dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); | 53 | dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); |
| 55 | switch (rsv->state) { | 54 | switch (rsv->state) { |
| 56 | case UWB_RSV_STATE_O_ESTABLISHED: | 55 | case UWB_RSV_STATE_O_ESTABLISHED: |
| 57 | uwb_rsv_get_usable_mas(rsv, &mas); | 56 | uwb_rsv_get_usable_mas(rsv, &mas); |
| 58 | bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS); | 57 | dev_dbg(dev, "established reservation: %*pb\n", |
| 59 | dev_dbg(dev, "established reservation: %s\n", buf); | 58 | UWB_NUM_MAS, mas.bm); |
| 60 | wusbhc_bwa_set(wusbhc, rsv->stream, &mas); | 59 | wusbhc_bwa_set(wusbhc, rsv->stream, &mas); |
| 61 | break; | 60 | break; |
| 62 | case UWB_RSV_STATE_NONE: | 61 | case UWB_RSV_STATE_NONE: |
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c index a80c5d284b59..c7ecdbe19a32 100644 --- a/drivers/usb/wusbcore/wa-rpipe.c +++ b/drivers/usb/wusbcore/wa-rpipe.c | |||
| @@ -496,10 +496,9 @@ void wa_rpipes_destroy(struct wahc *wa) | |||
| 496 | struct device *dev = &wa->usb_iface->dev; | 496 | struct device *dev = &wa->usb_iface->dev; |
| 497 | 497 | ||
| 498 | if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) { | 498 | if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) { |
| 499 | char buf[256]; | ||
| 500 | WARN_ON(1); | 499 | WARN_ON(1); |
| 501 | bitmap_scnprintf(buf, sizeof(buf), wa->rpipe_bm, wa->rpipes); | 500 | dev_err(dev, "BUG: pipes not released on exit: %*pb\n", |
| 502 | dev_err(dev, "BUG: pipes not released on exit: %s\n", buf); | 501 | wa->rpipes, wa->rpipe_bm); |
| 503 | } | 502 | } |
| 504 | kfree(wa->rpipe_bm); | 503 | kfree(wa->rpipe_bm); |
| 505 | } | 504 | } |
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c index 3e1ba51d1a43..94f401ab859f 100644 --- a/drivers/usb/wusbcore/wusbhc.c +++ b/drivers/usb/wusbcore/wusbhc.c | |||
| @@ -496,11 +496,8 @@ static void __exit wusbcore_exit(void) | |||
| 496 | { | 496 | { |
| 497 | clear_bit(0, wusb_cluster_id_table); | 497 | clear_bit(0, wusb_cluster_id_table); |
| 498 | if (!bitmap_empty(wusb_cluster_id_table, CLUSTER_IDS)) { | 498 | if (!bitmap_empty(wusb_cluster_id_table, CLUSTER_IDS)) { |
| 499 | char buf[256]; | 499 | printk(KERN_ERR "BUG: WUSB Cluster IDs not released on exit: %*pb\n", |
| 500 | bitmap_scnprintf(buf, sizeof(buf), wusb_cluster_id_table, | 500 | CLUSTER_IDS, wusb_cluster_id_table); |
| 501 | CLUSTER_IDS); | ||
| 502 | printk(KERN_ERR "BUG: WUSB Cluster IDs not released " | ||
| 503 | "on exit: %s\n", buf); | ||
| 504 | WARN_ON(1); | 501 | WARN_ON(1); |
| 505 | } | 502 | } |
| 506 | usb_unregister_notify(&wusb_usb_notifier); | 503 | usb_unregister_notify(&wusb_usb_notifier); |
diff --git a/drivers/uwb/drp.c b/drivers/uwb/drp.c index 05b7bd762254..8fc1b787dced 100644 --- a/drivers/uwb/drp.c +++ b/drivers/uwb/drp.c | |||
| @@ -619,11 +619,9 @@ static void uwb_drp_handle_alien_drp(struct uwb_rc *rc, struct uwb_ie_drp *drp_i | |||
| 619 | struct device *dev = &rc->uwb_dev.dev; | 619 | struct device *dev = &rc->uwb_dev.dev; |
| 620 | struct uwb_mas_bm mas; | 620 | struct uwb_mas_bm mas; |
| 621 | struct uwb_cnflt_alien *cnflt; | 621 | struct uwb_cnflt_alien *cnflt; |
| 622 | char buf[72]; | ||
| 623 | unsigned long delay_us = UWB_MAS_LENGTH_US * UWB_MAS_PER_ZONE; | 622 | unsigned long delay_us = UWB_MAS_LENGTH_US * UWB_MAS_PER_ZONE; |
| 624 | 623 | ||
| 625 | uwb_drp_ie_to_bm(&mas, drp_ie); | 624 | uwb_drp_ie_to_bm(&mas, drp_ie); |
| 626 | bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS); | ||
| 627 | 625 | ||
| 628 | list_for_each_entry(cnflt, &rc->cnflt_alien_list, rc_node) { | 626 | list_for_each_entry(cnflt, &rc->cnflt_alien_list, rc_node) { |
| 629 | if (bitmap_equal(cnflt->mas.bm, mas.bm, UWB_NUM_MAS)) { | 627 | if (bitmap_equal(cnflt->mas.bm, mas.bm, UWB_NUM_MAS)) { |
diff --git a/drivers/uwb/uwb-debug.c b/drivers/uwb/uwb-debug.c index 6ec45beb7af5..0b1e5a9449b5 100644 --- a/drivers/uwb/uwb-debug.c +++ b/drivers/uwb/uwb-debug.c | |||
| @@ -217,7 +217,6 @@ static int reservations_print(struct seq_file *s, void *p) | |||
| 217 | struct uwb_dev_addr devaddr; | 217 | struct uwb_dev_addr devaddr; |
| 218 | char owner[UWB_ADDR_STRSIZE], target[UWB_ADDR_STRSIZE]; | 218 | char owner[UWB_ADDR_STRSIZE], target[UWB_ADDR_STRSIZE]; |
| 219 | bool is_owner; | 219 | bool is_owner; |
| 220 | char buf[72]; | ||
| 221 | 220 | ||
| 222 | uwb_dev_addr_print(owner, sizeof(owner), &rsv->owner->dev_addr); | 221 | uwb_dev_addr_print(owner, sizeof(owner), &rsv->owner->dev_addr); |
| 223 | if (rsv->target.type == UWB_RSV_TARGET_DEV) { | 222 | if (rsv->target.type == UWB_RSV_TARGET_DEV) { |
| @@ -234,8 +233,7 @@ static int reservations_print(struct seq_file *s, void *p) | |||
| 234 | owner, target, uwb_rsv_state_str(rsv->state)); | 233 | owner, target, uwb_rsv_state_str(rsv->state)); |
| 235 | seq_printf(s, " stream: %d type: %s\n", | 234 | seq_printf(s, " stream: %d type: %s\n", |
| 236 | rsv->stream, uwb_rsv_type_str(rsv->type)); | 235 | rsv->stream, uwb_rsv_type_str(rsv->type)); |
| 237 | bitmap_scnprintf(buf, sizeof(buf), rsv->mas.bm, UWB_NUM_MAS); | 236 | seq_printf(s, " %*pb\n", UWB_NUM_MAS, rsv->mas.bm); |
| 238 | seq_printf(s, " %s\n", buf); | ||
| 239 | } | 237 | } |
| 240 | 238 | ||
| 241 | mutex_unlock(&rc->rsvs_mutex); | 239 | mutex_unlock(&rc->rsvs_mutex); |
| @@ -259,14 +257,10 @@ static const struct file_operations reservations_fops = { | |||
| 259 | static int drp_avail_print(struct seq_file *s, void *p) | 257 | static int drp_avail_print(struct seq_file *s, void *p) |
| 260 | { | 258 | { |
| 261 | struct uwb_rc *rc = s->private; | 259 | struct uwb_rc *rc = s->private; |
| 262 | char buf[72]; | 260 | |
| 263 | 261 | seq_printf(s, "global: %*pb\n", UWB_NUM_MAS, rc->drp_avail.global); | |
| 264 | bitmap_scnprintf(buf, sizeof(buf), rc->drp_avail.global, UWB_NUM_MAS); | 262 | seq_printf(s, "local: %*pb\n", UWB_NUM_MAS, rc->drp_avail.local); |
| 265 | seq_printf(s, "global: %s\n", buf); | 263 | seq_printf(s, "pending: %*pb\n", UWB_NUM_MAS, rc->drp_avail.pending); |
| 266 | bitmap_scnprintf(buf, sizeof(buf), rc->drp_avail.local, UWB_NUM_MAS); | ||
| 267 | seq_printf(s, "local: %s\n", buf); | ||
| 268 | bitmap_scnprintf(buf, sizeof(buf), rc->drp_avail.pending, UWB_NUM_MAS); | ||
| 269 | seq_printf(s, "pending: %s\n", buf); | ||
| 270 | 264 | ||
| 271 | return 0; | 265 | return 0; |
| 272 | } | 266 | } |
diff --git a/fs/dcache.c b/fs/dcache.c index d04be762b216..7d34f04ec7aa 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
| @@ -38,6 +38,8 @@ | |||
| 38 | #include <linux/prefetch.h> | 38 | #include <linux/prefetch.h> |
| 39 | #include <linux/ratelimit.h> | 39 | #include <linux/ratelimit.h> |
| 40 | #include <linux/list_lru.h> | 40 | #include <linux/list_lru.h> |
| 41 | #include <linux/kasan.h> | ||
| 42 | |||
| 41 | #include "internal.h" | 43 | #include "internal.h" |
| 42 | #include "mount.h" | 44 | #include "mount.h" |
| 43 | 45 | ||
| @@ -1429,6 +1431,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) | |||
| 1429 | } | 1431 | } |
| 1430 | atomic_set(&p->u.count, 1); | 1432 | atomic_set(&p->u.count, 1); |
| 1431 | dname = p->name; | 1433 | dname = p->name; |
| 1434 | if (IS_ENABLED(CONFIG_DCACHE_WORD_ACCESS)) | ||
| 1435 | kasan_unpoison_shadow(dname, | ||
| 1436 | round_up(name->len + 1, sizeof(unsigned long))); | ||
| 1432 | } else { | 1437 | } else { |
| 1433 | dname = dentry->d_iname; | 1438 | dname = dentry->d_iname; |
| 1434 | } | 1439 | } |
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index d77f94491352..1e009cad8d5c 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
| @@ -1639,9 +1639,9 @@ fetch_events: | |||
| 1639 | 1639 | ||
| 1640 | spin_lock_irqsave(&ep->lock, flags); | 1640 | spin_lock_irqsave(&ep->lock, flags); |
| 1641 | } | 1641 | } |
| 1642 | __remove_wait_queue(&ep->wq, &wait); | ||
| 1643 | 1642 | ||
| 1644 | set_current_state(TASK_RUNNING); | 1643 | __remove_wait_queue(&ep->wq, &wait); |
| 1644 | __set_current_state(TASK_RUNNING); | ||
| 1645 | } | 1645 | } |
| 1646 | check_events: | 1646 | check_events: |
| 1647 | /* Is it worth to try to dig for events ? */ | 1647 | /* Is it worth to try to dig for events ? */ |
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 2d881b381d2b..6acc9648f986 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c | |||
| @@ -411,8 +411,9 @@ void kernfs_put(struct kernfs_node *kn) | |||
| 411 | 411 | ||
| 412 | if (kernfs_type(kn) == KERNFS_LINK) | 412 | if (kernfs_type(kn) == KERNFS_LINK) |
| 413 | kernfs_put(kn->symlink.target_kn); | 413 | kernfs_put(kn->symlink.target_kn); |
| 414 | if (!(kn->flags & KERNFS_STATIC_NAME)) | 414 | |
| 415 | kfree(kn->name); | 415 | kfree_const(kn->name); |
| 416 | |||
| 416 | if (kn->iattr) { | 417 | if (kn->iattr) { |
| 417 | if (kn->iattr->ia_secdata) | 418 | if (kn->iattr->ia_secdata) |
| 418 | security_release_secctx(kn->iattr->ia_secdata, | 419 | security_release_secctx(kn->iattr->ia_secdata, |
| @@ -506,15 +507,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, | |||
| 506 | const char *name, umode_t mode, | 507 | const char *name, umode_t mode, |
| 507 | unsigned flags) | 508 | unsigned flags) |
| 508 | { | 509 | { |
| 509 | char *dup_name = NULL; | ||
| 510 | struct kernfs_node *kn; | 510 | struct kernfs_node *kn; |
| 511 | int ret; | 511 | int ret; |
| 512 | 512 | ||
| 513 | if (!(flags & KERNFS_STATIC_NAME)) { | 513 | name = kstrdup_const(name, GFP_KERNEL); |
| 514 | name = dup_name = kstrdup(name, GFP_KERNEL); | 514 | if (!name) |
| 515 | if (!name) | 515 | return NULL; |
| 516 | return NULL; | ||
| 517 | } | ||
| 518 | 516 | ||
| 519 | kn = kmem_cache_zalloc(kernfs_node_cache, GFP_KERNEL); | 517 | kn = kmem_cache_zalloc(kernfs_node_cache, GFP_KERNEL); |
| 520 | if (!kn) | 518 | if (!kn) |
| @@ -538,7 +536,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, | |||
| 538 | err_out2: | 536 | err_out2: |
| 539 | kmem_cache_free(kernfs_node_cache, kn); | 537 | kmem_cache_free(kernfs_node_cache, kn); |
| 540 | err_out1: | 538 | err_out1: |
| 541 | kfree(dup_name); | 539 | kfree_const(name); |
| 542 | return NULL; | 540 | return NULL; |
| 543 | } | 541 | } |
| 544 | 542 | ||
| @@ -1264,7 +1262,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, | |||
| 1264 | /* rename kernfs_node */ | 1262 | /* rename kernfs_node */ |
| 1265 | if (strcmp(kn->name, new_name) != 0) { | 1263 | if (strcmp(kn->name, new_name) != 0) { |
| 1266 | error = -ENOMEM; | 1264 | error = -ENOMEM; |
| 1267 | new_name = kstrdup(new_name, GFP_KERNEL); | 1265 | new_name = kstrdup_const(new_name, GFP_KERNEL); |
| 1268 | if (!new_name) | 1266 | if (!new_name) |
| 1269 | goto out; | 1267 | goto out; |
| 1270 | } else { | 1268 | } else { |
| @@ -1285,9 +1283,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, | |||
| 1285 | 1283 | ||
| 1286 | kn->ns = new_ns; | 1284 | kn->ns = new_ns; |
| 1287 | if (new_name) { | 1285 | if (new_name) { |
| 1288 | if (!(kn->flags & KERNFS_STATIC_NAME)) | 1286 | old_name = kn->name; |
| 1289 | old_name = kn->name; | ||
| 1290 | kn->flags &= ~KERNFS_STATIC_NAME; | ||
| 1291 | kn->name = new_name; | 1287 | kn->name = new_name; |
| 1292 | } | 1288 | } |
| 1293 | 1289 | ||
| @@ -1297,7 +1293,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, | |||
| 1297 | kernfs_link_sibling(kn); | 1293 | kernfs_link_sibling(kn); |
| 1298 | 1294 | ||
| 1299 | kernfs_put(old_parent); | 1295 | kernfs_put(old_parent); |
| 1300 | kfree(old_name); | 1296 | kfree_const(old_name); |
| 1301 | 1297 | ||
| 1302 | error = 0; | 1298 | error = 0; |
| 1303 | out: | 1299 | out: |
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index ddc9f9612f16..b684e8a132e6 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c | |||
| @@ -901,7 +901,6 @@ const struct file_operations kernfs_file_fops = { | |||
| 901 | * @ops: kernfs operations for the file | 901 | * @ops: kernfs operations for the file |
| 902 | * @priv: private data for the file | 902 | * @priv: private data for the file |
| 903 | * @ns: optional namespace tag of the file | 903 | * @ns: optional namespace tag of the file |
| 904 | * @name_is_static: don't copy file name | ||
| 905 | * @key: lockdep key for the file's active_ref, %NULL to disable lockdep | 904 | * @key: lockdep key for the file's active_ref, %NULL to disable lockdep |
| 906 | * | 905 | * |
| 907 | * Returns the created node on success, ERR_PTR() value on error. | 906 | * Returns the created node on success, ERR_PTR() value on error. |
| @@ -911,7 +910,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, | |||
| 911 | umode_t mode, loff_t size, | 910 | umode_t mode, loff_t size, |
| 912 | const struct kernfs_ops *ops, | 911 | const struct kernfs_ops *ops, |
| 913 | void *priv, const void *ns, | 912 | void *priv, const void *ns, |
| 914 | bool name_is_static, | ||
| 915 | struct lock_class_key *key) | 913 | struct lock_class_key *key) |
| 916 | { | 914 | { |
| 917 | struct kernfs_node *kn; | 915 | struct kernfs_node *kn; |
| @@ -919,8 +917,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, | |||
| 919 | int rc; | 917 | int rc; |
| 920 | 918 | ||
| 921 | flags = KERNFS_FILE; | 919 | flags = KERNFS_FILE; |
| 922 | if (name_is_static) | ||
| 923 | flags |= KERNFS_STATIC_NAME; | ||
| 924 | 920 | ||
| 925 | kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags); | 921 | kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags); |
| 926 | if (!kn) | 922 | if (!kn) |
diff --git a/fs/namespace.c b/fs/namespace.c index cd1e9681a0cf..6dae553dd69c 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
| @@ -201,7 +201,7 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
| 201 | goto out_free_cache; | 201 | goto out_free_cache; |
| 202 | 202 | ||
| 203 | if (name) { | 203 | if (name) { |
| 204 | mnt->mnt_devname = kstrdup(name, GFP_KERNEL); | 204 | mnt->mnt_devname = kstrdup_const(name, GFP_KERNEL); |
| 205 | if (!mnt->mnt_devname) | 205 | if (!mnt->mnt_devname) |
| 206 | goto out_free_id; | 206 | goto out_free_id; |
| 207 | } | 207 | } |
| @@ -234,7 +234,7 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
| 234 | 234 | ||
| 235 | #ifdef CONFIG_SMP | 235 | #ifdef CONFIG_SMP |
| 236 | out_free_devname: | 236 | out_free_devname: |
| 237 | kfree(mnt->mnt_devname); | 237 | kfree_const(mnt->mnt_devname); |
| 238 | #endif | 238 | #endif |
| 239 | out_free_id: | 239 | out_free_id: |
| 240 | mnt_free_id(mnt); | 240 | mnt_free_id(mnt); |
| @@ -568,7 +568,7 @@ int sb_prepare_remount_readonly(struct super_block *sb) | |||
| 568 | 568 | ||
| 569 | static void free_vfsmnt(struct mount *mnt) | 569 | static void free_vfsmnt(struct mount *mnt) |
| 570 | { | 570 | { |
| 571 | kfree(mnt->mnt_devname); | 571 | kfree_const(mnt->mnt_devname); |
| 572 | #ifdef CONFIG_SMP | 572 | #ifdef CONFIG_SMP |
| 573 | free_percpu(mnt->mnt_pcp); | 573 | free_percpu(mnt->mnt_pcp); |
| 574 | #endif | 574 | #endif |
diff --git a/fs/proc/array.c b/fs/proc/array.c index a3ccf4c4ce70..1295a00ca316 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
| @@ -316,12 +316,10 @@ static inline void task_context_switch_counts(struct seq_file *m, | |||
| 316 | 316 | ||
| 317 | static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) | 317 | static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) |
| 318 | { | 318 | { |
| 319 | seq_puts(m, "Cpus_allowed:\t"); | 319 | seq_printf(m, "Cpus_allowed:\t%*pb\n", |
| 320 | seq_cpumask(m, &task->cpus_allowed); | 320 | cpumask_pr_args(&task->cpus_allowed)); |
| 321 | seq_putc(m, '\n'); | 321 | seq_printf(m, "Cpus_allowed_list:\t%*pbl\n", |
| 322 | seq_puts(m, "Cpus_allowed_list:\t"); | 322 | cpumask_pr_args(&task->cpus_allowed)); |
| 323 | seq_cpumask_list(m, &task->cpus_allowed); | ||
| 324 | seq_putc(m, '\n'); | ||
| 325 | } | 323 | } |
| 326 | 324 | ||
| 327 | int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, | 325 | int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, |
diff --git a/fs/seq_file.c b/fs/seq_file.c index dbf3a59c86bb..555f82155be8 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
| @@ -539,38 +539,6 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc) | |||
| 539 | return res; | 539 | return res; |
| 540 | } | 540 | } |
| 541 | 541 | ||
| 542 | int seq_bitmap(struct seq_file *m, const unsigned long *bits, | ||
| 543 | unsigned int nr_bits) | ||
| 544 | { | ||
| 545 | if (m->count < m->size) { | ||
| 546 | int len = bitmap_scnprintf(m->buf + m->count, | ||
| 547 | m->size - m->count, bits, nr_bits); | ||
| 548 | if (m->count + len < m->size) { | ||
| 549 | m->count += len; | ||
| 550 | return 0; | ||
| 551 | } | ||
| 552 | } | ||
| 553 | seq_set_overflow(m); | ||
| 554 | return -1; | ||
| 555 | } | ||
| 556 | EXPORT_SYMBOL(seq_bitmap); | ||
| 557 | |||
| 558 | int seq_bitmap_list(struct seq_file *m, const unsigned long *bits, | ||
| 559 | unsigned int nr_bits) | ||
| 560 | { | ||
| 561 | if (m->count < m->size) { | ||
| 562 | int len = bitmap_scnlistprintf(m->buf + m->count, | ||
| 563 | m->size - m->count, bits, nr_bits); | ||
| 564 | if (m->count + len < m->size) { | ||
| 565 | m->count += len; | ||
| 566 | return 0; | ||
| 567 | } | ||
| 568 | } | ||
| 569 | seq_set_overflow(m); | ||
| 570 | return -1; | ||
| 571 | } | ||
| 572 | EXPORT_SYMBOL(seq_bitmap_list); | ||
| 573 | |||
| 574 | static void *single_start(struct seq_file *p, loff_t *pos) | 542 | static void *single_start(struct seq_file *p, loff_t *pos) |
| 575 | { | 543 | { |
| 576 | return NULL + (*pos == 0); | 544 | return NULL + (*pos == 0); |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index dfe928a9540f..7c2867b44141 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
| @@ -295,7 +295,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, | |||
| 295 | key = attr->key ?: (struct lock_class_key *)&attr->skey; | 295 | key = attr->key ?: (struct lock_class_key *)&attr->skey; |
| 296 | #endif | 296 | #endif |
| 297 | kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops, | 297 | kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops, |
| 298 | (void *)attr, ns, true, key); | 298 | (void *)attr, ns, key); |
| 299 | if (IS_ERR(kn)) { | 299 | if (IS_ERR(kn)) { |
| 300 | if (PTR_ERR(kn) == -EEXIST) | 300 | if (PTR_ERR(kn) == -EEXIST) |
| 301 | sysfs_warn_dup(parent, attr->name); | 301 | sysfs_warn_dup(parent, attr->name); |
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index bee5d683074d..ac78910d7416 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h | |||
| @@ -478,6 +478,7 @@ | |||
| 478 | #define KERNEL_CTORS() . = ALIGN(8); \ | 478 | #define KERNEL_CTORS() . = ALIGN(8); \ |
| 479 | VMLINUX_SYMBOL(__ctors_start) = .; \ | 479 | VMLINUX_SYMBOL(__ctors_start) = .; \ |
| 480 | *(.ctors) \ | 480 | *(.ctors) \ |
| 481 | *(SORT(.init_array.*)) \ | ||
| 481 | *(.init_array) \ | 482 | *(.init_array) \ |
| 482 | VMLINUX_SYMBOL(__ctors_end) = .; | 483 | VMLINUX_SYMBOL(__ctors_end) = .; |
| 483 | #else | 484 | #else |
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 5f5c00de39f0..dbfbf4990005 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
| @@ -52,16 +52,13 @@ | |||
| 52 | * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) | 52 | * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) |
| 53 | * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap | 53 | * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap |
| 54 | * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz | 54 | * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz |
| 55 | * bitmap_scnprintf(buf, len, src, nbits) Print bitmap src to buf | ||
| 56 | * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf | 55 | * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf |
| 57 | * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf | 56 | * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf |
| 58 | * bitmap_scnlistprintf(buf, len, src, nbits) Print bitmap src as list to buf | ||
| 59 | * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf | 57 | * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf |
| 60 | * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf | 58 | * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf |
| 61 | * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region | 59 | * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region |
| 62 | * bitmap_release_region(bitmap, pos, order) Free specified bit region | 60 | * bitmap_release_region(bitmap, pos, order) Free specified bit region |
| 63 | * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region | 61 | * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region |
| 64 | * bitmap_print_to_pagebuf(list, buf, mask, nbits) Print bitmap src as list/hex | ||
| 65 | */ | 62 | */ |
| 66 | 63 | ||
| 67 | /* | 64 | /* |
| @@ -96,10 +93,10 @@ extern int __bitmap_equal(const unsigned long *bitmap1, | |||
| 96 | const unsigned long *bitmap2, unsigned int nbits); | 93 | const unsigned long *bitmap2, unsigned int nbits); |
| 97 | extern void __bitmap_complement(unsigned long *dst, const unsigned long *src, | 94 | extern void __bitmap_complement(unsigned long *dst, const unsigned long *src, |
| 98 | unsigned int nbits); | 95 | unsigned int nbits); |
| 99 | extern void __bitmap_shift_right(unsigned long *dst, | 96 | extern void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
| 100 | const unsigned long *src, int shift, int bits); | 97 | unsigned int shift, unsigned int nbits); |
| 101 | extern void __bitmap_shift_left(unsigned long *dst, | 98 | extern void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
| 102 | const unsigned long *src, int shift, int bits); | 99 | unsigned int shift, unsigned int nbits); |
| 103 | extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, | 100 | extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, |
| 104 | const unsigned long *bitmap2, unsigned int nbits); | 101 | const unsigned long *bitmap2, unsigned int nbits); |
| 105 | extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, | 102 | extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
| @@ -147,14 +144,10 @@ bitmap_find_next_zero_area(unsigned long *map, | |||
| 147 | align_mask, 0); | 144 | align_mask, 0); |
| 148 | } | 145 | } |
| 149 | 146 | ||
| 150 | extern int bitmap_scnprintf(char *buf, unsigned int len, | ||
| 151 | const unsigned long *src, int nbits); | ||
| 152 | extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user, | 147 | extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user, |
| 153 | unsigned long *dst, int nbits); | 148 | unsigned long *dst, int nbits); |
| 154 | extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, | 149 | extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, |
| 155 | unsigned long *dst, int nbits); | 150 | unsigned long *dst, int nbits); |
| 156 | extern int bitmap_scnlistprintf(char *buf, unsigned int len, | ||
| 157 | const unsigned long *src, int nbits); | ||
| 158 | extern int bitmap_parselist(const char *buf, unsigned long *maskp, | 151 | extern int bitmap_parselist(const char *buf, unsigned long *maskp, |
| 159 | int nmaskbits); | 152 | int nmaskbits); |
| 160 | extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, | 153 | extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, |
| @@ -170,7 +163,11 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig, | |||
| 170 | extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); | 163 | extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); |
| 171 | extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); | 164 | extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); |
| 172 | extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); | 165 | extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); |
| 173 | extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); | 166 | #ifdef __BIG_ENDIAN |
| 167 | extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits); | ||
| 168 | #else | ||
| 169 | #define bitmap_copy_le bitmap_copy | ||
| 170 | #endif | ||
| 174 | extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits); | 171 | extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits); |
| 175 | extern int bitmap_print_to_pagebuf(bool list, char *buf, | 172 | extern int bitmap_print_to_pagebuf(bool list, char *buf, |
| 176 | const unsigned long *maskp, int nmaskbits); | 173 | const unsigned long *maskp, int nmaskbits); |
| @@ -309,22 +306,22 @@ static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) | |||
| 309 | return __bitmap_weight(src, nbits); | 306 | return __bitmap_weight(src, nbits); |
| 310 | } | 307 | } |
| 311 | 308 | ||
| 312 | static inline void bitmap_shift_right(unsigned long *dst, | 309 | static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
| 313 | const unsigned long *src, int n, int nbits) | 310 | unsigned int shift, int nbits) |
| 314 | { | 311 | { |
| 315 | if (small_const_nbits(nbits)) | 312 | if (small_const_nbits(nbits)) |
| 316 | *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> n; | 313 | *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift; |
| 317 | else | 314 | else |
| 318 | __bitmap_shift_right(dst, src, n, nbits); | 315 | __bitmap_shift_right(dst, src, shift, nbits); |
| 319 | } | 316 | } |
| 320 | 317 | ||
| 321 | static inline void bitmap_shift_left(unsigned long *dst, | 318 | static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
| 322 | const unsigned long *src, int n, int nbits) | 319 | unsigned int shift, unsigned int nbits) |
| 323 | { | 320 | { |
| 324 | if (small_const_nbits(nbits)) | 321 | if (small_const_nbits(nbits)) |
| 325 | *dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits); | 322 | *dst = (*src << shift) & BITMAP_LAST_WORD_MASK(nbits); |
| 326 | else | 323 | else |
| 327 | __bitmap_shift_left(dst, src, n, nbits); | 324 | __bitmap_shift_left(dst, src, shift, nbits); |
| 328 | } | 325 | } |
| 329 | 326 | ||
| 330 | static inline int bitmap_parse(const char *buf, unsigned int buflen, | 327 | static inline int bitmap_parse(const char *buf, unsigned int buflen, |
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 02ae99e8e6d3..cdf13ca7cac3 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h | |||
| @@ -66,6 +66,7 @@ | |||
| 66 | #define __deprecated __attribute__((deprecated)) | 66 | #define __deprecated __attribute__((deprecated)) |
| 67 | #define __packed __attribute__((packed)) | 67 | #define __packed __attribute__((packed)) |
| 68 | #define __weak __attribute__((weak)) | 68 | #define __weak __attribute__((weak)) |
| 69 | #define __alias(symbol) __attribute__((alias(#symbol))) | ||
| 69 | 70 | ||
| 70 | /* | 71 | /* |
| 71 | * it doesn't make sense on ARM (currently the only user of __naked) to trace | 72 | * it doesn't make sense on ARM (currently the only user of __naked) to trace |
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index d1a558239b1a..769e19864632 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h | |||
| @@ -85,3 +85,7 @@ | |||
| 85 | #define __HAVE_BUILTIN_BSWAP16__ | 85 | #define __HAVE_BUILTIN_BSWAP16__ |
| 86 | #endif | 86 | #endif |
| 87 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ | 87 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ |
| 88 | |||
| 89 | #if GCC_VERSION >= 40902 | ||
| 90 | #define KASAN_ABI_VERSION 3 | ||
| 91 | #endif | ||
diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h index c8c565952548..efee493714eb 100644 --- a/include/linux/compiler-gcc5.h +++ b/include/linux/compiler-gcc5.h | |||
| @@ -63,3 +63,5 @@ | |||
| 63 | #define __HAVE_BUILTIN_BSWAP64__ | 63 | #define __HAVE_BUILTIN_BSWAP64__ |
| 64 | #define __HAVE_BUILTIN_BSWAP16__ | 64 | #define __HAVE_BUILTIN_BSWAP16__ |
| 65 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ | 65 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ |
| 66 | |||
| 67 | #define KASAN_ABI_VERSION 4 | ||
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index ff9044286d88..086549a665e2 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h | |||
| @@ -22,6 +22,14 @@ typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; | |||
| 22 | */ | 22 | */ |
| 23 | #define cpumask_bits(maskp) ((maskp)->bits) | 23 | #define cpumask_bits(maskp) ((maskp)->bits) |
| 24 | 24 | ||
| 25 | /** | ||
| 26 | * cpumask_pr_args - printf args to output a cpumask | ||
| 27 | * @maskp: cpumask to be printed | ||
| 28 | * | ||
| 29 | * Can be used to provide arguments for '%*pb[l]' when printing a cpumask. | ||
| 30 | */ | ||
| 31 | #define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp) | ||
| 32 | |||
| 25 | #if NR_CPUS == 1 | 33 | #if NR_CPUS == 1 |
| 26 | #define nr_cpu_ids 1 | 34 | #define nr_cpu_ids 1 |
| 27 | #else | 35 | #else |
| @@ -539,21 +547,6 @@ static inline void cpumask_copy(struct cpumask *dstp, | |||
| 539 | #define cpumask_of(cpu) (get_cpu_mask(cpu)) | 547 | #define cpumask_of(cpu) (get_cpu_mask(cpu)) |
| 540 | 548 | ||
| 541 | /** | 549 | /** |
| 542 | * cpumask_scnprintf - print a cpumask into a string as comma-separated hex | ||
| 543 | * @buf: the buffer to sprintf into | ||
| 544 | * @len: the length of the buffer | ||
| 545 | * @srcp: the cpumask to print | ||
| 546 | * | ||
| 547 | * If len is zero, returns zero. Otherwise returns the length of the | ||
| 548 | * (nul-terminated) @buf string. | ||
| 549 | */ | ||
| 550 | static inline int cpumask_scnprintf(char *buf, int len, | ||
| 551 | const struct cpumask *srcp) | ||
| 552 | { | ||
| 553 | return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits); | ||
| 554 | } | ||
| 555 | |||
| 556 | /** | ||
| 557 | * cpumask_parse_user - extract a cpumask from a user string | 550 | * cpumask_parse_user - extract a cpumask from a user string |
| 558 | * @buf: the buffer to extract from | 551 | * @buf: the buffer to extract from |
| 559 | * @len: the length of the buffer | 552 | * @len: the length of the buffer |
| @@ -564,7 +557,7 @@ static inline int cpumask_scnprintf(char *buf, int len, | |||
| 564 | static inline int cpumask_parse_user(const char __user *buf, int len, | 557 | static inline int cpumask_parse_user(const char __user *buf, int len, |
| 565 | struct cpumask *dstp) | 558 | struct cpumask *dstp) |
| 566 | { | 559 | { |
| 567 | return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits); | 560 | return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpu_ids); |
| 568 | } | 561 | } |
| 569 | 562 | ||
| 570 | /** | 563 | /** |
| @@ -579,23 +572,7 @@ static inline int cpumask_parselist_user(const char __user *buf, int len, | |||
| 579 | struct cpumask *dstp) | 572 | struct cpumask *dstp) |
| 580 | { | 573 | { |
| 581 | return bitmap_parselist_user(buf, len, cpumask_bits(dstp), | 574 | return bitmap_parselist_user(buf, len, cpumask_bits(dstp), |
| 582 | nr_cpumask_bits); | 575 | nr_cpu_ids); |
| 583 | } | ||
| 584 | |||
| 585 | /** | ||
| 586 | * cpulist_scnprintf - print a cpumask into a string as comma-separated list | ||
| 587 | * @buf: the buffer to sprintf into | ||
| 588 | * @len: the length of the buffer | ||
| 589 | * @srcp: the cpumask to print | ||
| 590 | * | ||
| 591 | * If len is zero, returns zero. Otherwise returns the length of the | ||
| 592 | * (nul-terminated) @buf string. | ||
| 593 | */ | ||
| 594 | static inline int cpulist_scnprintf(char *buf, int len, | ||
| 595 | const struct cpumask *srcp) | ||
| 596 | { | ||
| 597 | return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp), | ||
| 598 | nr_cpumask_bits); | ||
| 599 | } | 576 | } |
| 600 | 577 | ||
| 601 | /** | 578 | /** |
| @@ -610,7 +587,7 @@ static inline int cpumask_parse(const char *buf, struct cpumask *dstp) | |||
| 610 | char *nl = strchr(buf, '\n'); | 587 | char *nl = strchr(buf, '\n'); |
| 611 | unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf); | 588 | unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf); |
| 612 | 589 | ||
| 613 | return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits); | 590 | return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpu_ids); |
| 614 | } | 591 | } |
| 615 | 592 | ||
| 616 | /** | 593 | /** |
| @@ -622,7 +599,7 @@ static inline int cpumask_parse(const char *buf, struct cpumask *dstp) | |||
| 622 | */ | 599 | */ |
| 623 | static inline int cpulist_parse(const char *buf, struct cpumask *dstp) | 600 | static inline int cpulist_parse(const char *buf, struct cpumask *dstp) |
| 624 | { | 601 | { |
| 625 | return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits); | 602 | return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpu_ids); |
| 626 | } | 603 | } |
| 627 | 604 | ||
| 628 | /** | 605 | /** |
| @@ -817,7 +794,7 @@ static inline ssize_t | |||
| 817 | cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask) | 794 | cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask) |
| 818 | { | 795 | { |
| 819 | return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask), | 796 | return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask), |
| 820 | nr_cpumask_bits); | 797 | nr_cpu_ids); |
| 821 | } | 798 | } |
| 822 | 799 | ||
| 823 | /* | 800 | /* |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index d3d43ecf148c..696d22312b31 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
| @@ -175,6 +175,13 @@ extern struct task_group root_task_group; | |||
| 175 | # define INIT_NUMA_BALANCING(tsk) | 175 | # define INIT_NUMA_BALANCING(tsk) |
| 176 | #endif | 176 | #endif |
| 177 | 177 | ||
| 178 | #ifdef CONFIG_KASAN | ||
| 179 | # define INIT_KASAN(tsk) \ | ||
| 180 | .kasan_depth = 1, | ||
| 181 | #else | ||
| 182 | # define INIT_KASAN(tsk) | ||
| 183 | #endif | ||
| 184 | |||
| 178 | /* | 185 | /* |
| 179 | * INIT_TASK is used to set up the first task table, touch at | 186 | * INIT_TASK is used to set up the first task table, touch at |
| 180 | * your own risk!. Base=0, limit=0x1fffff (=2MB) | 187 | * your own risk!. Base=0, limit=0x1fffff (=2MB) |
| @@ -250,6 +257,7 @@ extern struct task_group root_task_group; | |||
| 250 | INIT_RT_MUTEXES(tsk) \ | 257 | INIT_RT_MUTEXES(tsk) \ |
| 251 | INIT_VTIME(tsk) \ | 258 | INIT_VTIME(tsk) \ |
| 252 | INIT_NUMA_BALANCING(tsk) \ | 259 | INIT_NUMA_BALANCING(tsk) \ |
| 260 | INIT_KASAN(tsk) \ | ||
| 253 | } | 261 | } |
| 254 | 262 | ||
| 255 | 263 | ||
diff --git a/include/linux/kasan.h b/include/linux/kasan.h new file mode 100644 index 000000000000..72ba725ddf9c --- /dev/null +++ b/include/linux/kasan.h | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | #ifndef _LINUX_KASAN_H | ||
| 2 | #define _LINUX_KASAN_H | ||
| 3 | |||
| 4 | #include <linux/types.h> | ||
| 5 | |||
| 6 | struct kmem_cache; | ||
| 7 | struct page; | ||
| 8 | |||
| 9 | #ifdef CONFIG_KASAN | ||
| 10 | |||
| 11 | #define KASAN_SHADOW_SCALE_SHIFT 3 | ||
| 12 | #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) | ||
| 13 | |||
| 14 | #include <asm/kasan.h> | ||
| 15 | #include <linux/sched.h> | ||
| 16 | |||
| 17 | static inline void *kasan_mem_to_shadow(const void *addr) | ||
| 18 | { | ||
| 19 | return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) | ||
| 20 | + KASAN_SHADOW_OFFSET; | ||
| 21 | } | ||
| 22 | |||
| 23 | /* Enable reporting bugs after kasan_disable_current() */ | ||
| 24 | static inline void kasan_enable_current(void) | ||
| 25 | { | ||
| 26 | current->kasan_depth++; | ||
| 27 | } | ||
| 28 | |||
| 29 | /* Disable reporting bugs for current task */ | ||
| 30 | static inline void kasan_disable_current(void) | ||
| 31 | { | ||
| 32 | current->kasan_depth--; | ||
| 33 | } | ||
| 34 | |||
| 35 | void kasan_unpoison_shadow(const void *address, size_t size); | ||
| 36 | |||
| 37 | void kasan_alloc_pages(struct page *page, unsigned int order); | ||
| 38 | void kasan_free_pages(struct page *page, unsigned int order); | ||
| 39 | |||
| 40 | void kasan_poison_slab(struct page *page); | ||
| 41 | void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); | ||
| 42 | void kasan_poison_object_data(struct kmem_cache *cache, void *object); | ||
| 43 | |||
| 44 | void kasan_kmalloc_large(const void *ptr, size_t size); | ||
| 45 | void kasan_kfree_large(const void *ptr); | ||
| 46 | void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size); | ||
| 47 | void kasan_krealloc(const void *object, size_t new_size); | ||
| 48 | |||
| 49 | void kasan_slab_alloc(struct kmem_cache *s, void *object); | ||
| 50 | void kasan_slab_free(struct kmem_cache *s, void *object); | ||
| 51 | |||
| 52 | #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) | ||
| 53 | |||
| 54 | int kasan_module_alloc(void *addr, size_t size); | ||
| 55 | void kasan_module_free(void *addr); | ||
| 56 | |||
| 57 | #else /* CONFIG_KASAN */ | ||
| 58 | |||
| 59 | #define MODULE_ALIGN 1 | ||
| 60 | |||
| 61 | static inline void kasan_unpoison_shadow(const void *address, size_t size) {} | ||
| 62 | |||
| 63 | static inline void kasan_enable_current(void) {} | ||
| 64 | static inline void kasan_disable_current(void) {} | ||
| 65 | |||
| 66 | static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} | ||
| 67 | static inline void kasan_free_pages(struct page *page, unsigned int order) {} | ||
| 68 | |||
| 69 | static inline void kasan_poison_slab(struct page *page) {} | ||
| 70 | static inline void kasan_unpoison_object_data(struct kmem_cache *cache, | ||
| 71 | void *object) {} | ||
| 72 | static inline void kasan_poison_object_data(struct kmem_cache *cache, | ||
| 73 | void *object) {} | ||
| 74 | |||
| 75 | static inline void kasan_kmalloc_large(void *ptr, size_t size) {} | ||
| 76 | static inline void kasan_kfree_large(const void *ptr) {} | ||
| 77 | static inline void kasan_kmalloc(struct kmem_cache *s, const void *object, | ||
| 78 | size_t size) {} | ||
| 79 | static inline void kasan_krealloc(const void *object, size_t new_size) {} | ||
| 80 | |||
| 81 | static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {} | ||
| 82 | static inline void kasan_slab_free(struct kmem_cache *s, void *object) {} | ||
| 83 | |||
| 84 | static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } | ||
| 85 | static inline void kasan_module_free(void *addr) {} | ||
| 86 | |||
| 87 | #endif /* CONFIG_KASAN */ | ||
| 88 | |||
| 89 | #endif /* LINUX_KASAN_H */ | ||
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index d4e01b358341..71ecdab1671b 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h | |||
| @@ -43,7 +43,6 @@ enum kernfs_node_flag { | |||
| 43 | KERNFS_HAS_SEQ_SHOW = 0x0040, | 43 | KERNFS_HAS_SEQ_SHOW = 0x0040, |
| 44 | KERNFS_HAS_MMAP = 0x0080, | 44 | KERNFS_HAS_MMAP = 0x0080, |
| 45 | KERNFS_LOCKDEP = 0x0100, | 45 | KERNFS_LOCKDEP = 0x0100, |
| 46 | KERNFS_STATIC_NAME = 0x0200, | ||
| 47 | KERNFS_SUICIDAL = 0x0400, | 46 | KERNFS_SUICIDAL = 0x0400, |
| 48 | KERNFS_SUICIDED = 0x0800, | 47 | KERNFS_SUICIDED = 0x0800, |
| 49 | }; | 48 | }; |
| @@ -291,7 +290,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, | |||
| 291 | umode_t mode, loff_t size, | 290 | umode_t mode, loff_t size, |
| 292 | const struct kernfs_ops *ops, | 291 | const struct kernfs_ops *ops, |
| 293 | void *priv, const void *ns, | 292 | void *priv, const void *ns, |
| 294 | bool name_is_static, | ||
| 295 | struct lock_class_key *key); | 293 | struct lock_class_key *key); |
| 296 | struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, | 294 | struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, |
| 297 | const char *name, | 295 | const char *name, |
| @@ -369,8 +367,7 @@ kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, | |||
| 369 | static inline struct kernfs_node * | 367 | static inline struct kernfs_node * |
| 370 | __kernfs_create_file(struct kernfs_node *parent, const char *name, | 368 | __kernfs_create_file(struct kernfs_node *parent, const char *name, |
| 371 | umode_t mode, loff_t size, const struct kernfs_ops *ops, | 369 | umode_t mode, loff_t size, const struct kernfs_ops *ops, |
| 372 | void *priv, const void *ns, bool name_is_static, | 370 | void *priv, const void *ns, struct lock_class_key *key) |
| 373 | struct lock_class_key *key) | ||
| 374 | { return ERR_PTR(-ENOSYS); } | 371 | { return ERR_PTR(-ENOSYS); } |
| 375 | 372 | ||
| 376 | static inline struct kernfs_node * | 373 | static inline struct kernfs_node * |
| @@ -439,7 +436,7 @@ kernfs_create_file_ns(struct kernfs_node *parent, const char *name, | |||
| 439 | key = (struct lock_class_key *)&ops->lockdep_key; | 436 | key = (struct lock_class_key *)&ops->lockdep_key; |
| 440 | #endif | 437 | #endif |
| 441 | return __kernfs_create_file(parent, name, mode, size, ops, priv, ns, | 438 | return __kernfs_create_file(parent, name, mode, size, ops, priv, ns, |
| 442 | false, key); | 439 | key); |
| 443 | } | 440 | } |
| 444 | 441 | ||
| 445 | static inline struct kernfs_node * | 442 | static inline struct kernfs_node * |
diff --git a/include/linux/module.h b/include/linux/module.h index b653d7c0a05a..42999fe2dbd0 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
| @@ -135,7 +135,7 @@ void trim_init_extable(struct module *m); | |||
| 135 | #ifdef MODULE | 135 | #ifdef MODULE |
| 136 | /* Creates an alias so file2alias.c can find device table. */ | 136 | /* Creates an alias so file2alias.c can find device table. */ |
| 137 | #define MODULE_DEVICE_TABLE(type, name) \ | 137 | #define MODULE_DEVICE_TABLE(type, name) \ |
| 138 | extern const struct type##_device_id __mod_##type##__##name##_device_table \ | 138 | extern const typeof(name) __mod_##type##__##name##_device_table \ |
| 139 | __attribute__ ((unused, alias(__stringify(name)))) | 139 | __attribute__ ((unused, alias(__stringify(name)))) |
| 140 | #else /* !MODULE */ | 140 | #else /* !MODULE */ |
| 141 | #define MODULE_DEVICE_TABLE(type, name) | 141 | #define MODULE_DEVICE_TABLE(type, name) |
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 21cef483dc1b..6e85889cf9ab 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h | |||
| @@ -8,14 +8,13 @@ | |||
| 8 | * See detailed comments in the file linux/bitmap.h describing the | 8 | * See detailed comments in the file linux/bitmap.h describing the |
| 9 | * data type on which these nodemasks are based. | 9 | * data type on which these nodemasks are based. |
| 10 | * | 10 | * |
| 11 | * For details of nodemask_scnprintf() and nodemask_parse_user(), | 11 | * For details of nodemask_parse_user(), see bitmap_parse_user() in |
| 12 | * see bitmap_scnprintf() and bitmap_parse_user() in lib/bitmap.c. | 12 | * lib/bitmap.c. For details of nodelist_parse(), see bitmap_parselist(), |
| 13 | * For details of nodelist_scnprintf() and nodelist_parse(), see | 13 | * also in bitmap.c. For details of node_remap(), see bitmap_bitremap in |
| 14 | * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c. | 14 | * lib/bitmap.c. For details of nodes_remap(), see bitmap_remap in |
| 15 | * For details of node_remap(), see bitmap_bitremap in lib/bitmap.c. | 15 | * lib/bitmap.c. For details of nodes_onto(), see bitmap_onto in |
| 16 | * For details of nodes_remap(), see bitmap_remap in lib/bitmap.c. | 16 | * lib/bitmap.c. For details of nodes_fold(), see bitmap_fold in |
| 17 | * For details of nodes_onto(), see bitmap_onto in lib/bitmap.c. | 17 | * lib/bitmap.c. |
| 18 | * For details of nodes_fold(), see bitmap_fold in lib/bitmap.c. | ||
| 19 | * | 18 | * |
| 20 | * The available nodemask operations are: | 19 | * The available nodemask operations are: |
| 21 | * | 20 | * |
| @@ -52,9 +51,7 @@ | |||
| 52 | * NODE_MASK_NONE Initializer - no bits set | 51 | * NODE_MASK_NONE Initializer - no bits set |
| 53 | * unsigned long *nodes_addr(mask) Array of unsigned long's in mask | 52 | * unsigned long *nodes_addr(mask) Array of unsigned long's in mask |
| 54 | * | 53 | * |
| 55 | * int nodemask_scnprintf(buf, len, mask) Format nodemask for printing | ||
| 56 | * int nodemask_parse_user(ubuf, ulen, mask) Parse ascii string as nodemask | 54 | * int nodemask_parse_user(ubuf, ulen, mask) Parse ascii string as nodemask |
| 57 | * int nodelist_scnprintf(buf, len, mask) Format nodemask as list for printing | ||
| 58 | * int nodelist_parse(buf, map) Parse ascii string as nodelist | 55 | * int nodelist_parse(buf, map) Parse ascii string as nodelist |
| 59 | * int node_remap(oldbit, old, new) newbit = map(old, new)(oldbit) | 56 | * int node_remap(oldbit, old, new) newbit = map(old, new)(oldbit) |
| 60 | * void nodes_remap(dst, src, old, new) *dst = map(old, new)(src) | 57 | * void nodes_remap(dst, src, old, new) *dst = map(old, new)(src) |
| @@ -98,6 +95,14 @@ | |||
| 98 | typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; | 95 | typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; |
| 99 | extern nodemask_t _unused_nodemask_arg_; | 96 | extern nodemask_t _unused_nodemask_arg_; |
| 100 | 97 | ||
| 98 | /** | ||
| 99 | * nodemask_pr_args - printf args to output a nodemask | ||
| 100 | * @maskp: nodemask to be printed | ||
| 101 | * | ||
| 102 | * Can be used to provide arguments for '%*pb[l]' when printing a nodemask. | ||
| 103 | */ | ||
| 104 | #define nodemask_pr_args(maskp) MAX_NUMNODES, (maskp)->bits | ||
| 105 | |||
| 101 | /* | 106 | /* |
| 102 | * The inline keyword gives the compiler room to decide to inline, or | 107 | * The inline keyword gives the compiler room to decide to inline, or |
| 103 | * not inline a function as it sees best. However, as these functions | 108 | * not inline a function as it sees best. However, as these functions |
| @@ -304,14 +309,6 @@ static inline int __first_unset_node(const nodemask_t *maskp) | |||
| 304 | 309 | ||
| 305 | #define nodes_addr(src) ((src).bits) | 310 | #define nodes_addr(src) ((src).bits) |
| 306 | 311 | ||
| 307 | #define nodemask_scnprintf(buf, len, src) \ | ||
| 308 | __nodemask_scnprintf((buf), (len), &(src), MAX_NUMNODES) | ||
| 309 | static inline int __nodemask_scnprintf(char *buf, int len, | ||
| 310 | const nodemask_t *srcp, int nbits) | ||
| 311 | { | ||
| 312 | return bitmap_scnprintf(buf, len, srcp->bits, nbits); | ||
| 313 | } | ||
| 314 | |||
| 315 | #define nodemask_parse_user(ubuf, ulen, dst) \ | 312 | #define nodemask_parse_user(ubuf, ulen, dst) \ |
| 316 | __nodemask_parse_user((ubuf), (ulen), &(dst), MAX_NUMNODES) | 313 | __nodemask_parse_user((ubuf), (ulen), &(dst), MAX_NUMNODES) |
| 317 | static inline int __nodemask_parse_user(const char __user *buf, int len, | 314 | static inline int __nodemask_parse_user(const char __user *buf, int len, |
| @@ -320,14 +317,6 @@ static inline int __nodemask_parse_user(const char __user *buf, int len, | |||
| 320 | return bitmap_parse_user(buf, len, dstp->bits, nbits); | 317 | return bitmap_parse_user(buf, len, dstp->bits, nbits); |
| 321 | } | 318 | } |
| 322 | 319 | ||
| 323 | #define nodelist_scnprintf(buf, len, src) \ | ||
| 324 | __nodelist_scnprintf((buf), (len), &(src), MAX_NUMNODES) | ||
| 325 | static inline int __nodelist_scnprintf(char *buf, int len, | ||
| 326 | const nodemask_t *srcp, int nbits) | ||
| 327 | { | ||
| 328 | return bitmap_scnlistprintf(buf, len, srcp->bits, nbits); | ||
| 329 | } | ||
| 330 | |||
| 331 | #define nodelist_parse(buf, dst) __nodelist_parse((buf), &(dst), MAX_NUMNODES) | 320 | #define nodelist_parse(buf, dst) __nodelist_parse((buf), &(dst), MAX_NUMNODES) |
| 332 | static inline int __nodelist_parse(const char *buf, nodemask_t *dstp, int nbits) | 321 | static inline int __nodelist_parse(const char *buf, nodemask_t *dstp, int nbits) |
| 333 | { | 322 | { |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 048b91b983ed..41c60e5302d7 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -1664,6 +1664,9 @@ struct task_struct { | |||
| 1664 | unsigned long timer_slack_ns; | 1664 | unsigned long timer_slack_ns; |
| 1665 | unsigned long default_timer_slack_ns; | 1665 | unsigned long default_timer_slack_ns; |
| 1666 | 1666 | ||
| 1667 | #ifdef CONFIG_KASAN | ||
| 1668 | unsigned int kasan_depth; | ||
| 1669 | #endif | ||
| 1667 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 1670 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1668 | /* Index of current stored address in ret_stack */ | 1671 | /* Index of current stored address in ret_stack */ |
| 1669 | int curr_ret_stack; | 1672 | int curr_ret_stack; |
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h index 9aafe0e24c68..fb7eb9ccb1cd 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h | |||
| @@ -125,9 +125,6 @@ extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem, | |||
| 125 | unsigned int len); | 125 | unsigned int len); |
| 126 | extern int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc); | 126 | extern int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc); |
| 127 | 127 | ||
| 128 | extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp, | ||
| 129 | int nmaskbits); | ||
| 130 | |||
| 131 | #ifdef CONFIG_BINARY_PRINTF | 128 | #ifdef CONFIG_BINARY_PRINTF |
| 132 | extern int | 129 | extern int |
| 133 | seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary); | 130 | seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary); |
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index cf6a9daaaf6d..afbb1fd77c77 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h | |||
| @@ -126,31 +126,6 @@ int seq_path(struct seq_file *, const struct path *, const char *); | |||
| 126 | int seq_dentry(struct seq_file *, struct dentry *, const char *); | 126 | int seq_dentry(struct seq_file *, struct dentry *, const char *); |
| 127 | int seq_path_root(struct seq_file *m, const struct path *path, | 127 | int seq_path_root(struct seq_file *m, const struct path *path, |
| 128 | const struct path *root, const char *esc); | 128 | const struct path *root, const char *esc); |
| 129 | int seq_bitmap(struct seq_file *m, const unsigned long *bits, | ||
| 130 | unsigned int nr_bits); | ||
| 131 | static inline int seq_cpumask(struct seq_file *m, const struct cpumask *mask) | ||
| 132 | { | ||
| 133 | return seq_bitmap(m, cpumask_bits(mask), nr_cpu_ids); | ||
| 134 | } | ||
| 135 | |||
| 136 | static inline int seq_nodemask(struct seq_file *m, nodemask_t *mask) | ||
| 137 | { | ||
| 138 | return seq_bitmap(m, mask->bits, MAX_NUMNODES); | ||
| 139 | } | ||
| 140 | |||
| 141 | int seq_bitmap_list(struct seq_file *m, const unsigned long *bits, | ||
| 142 | unsigned int nr_bits); | ||
| 143 | |||
| 144 | static inline int seq_cpumask_list(struct seq_file *m, | ||
| 145 | const struct cpumask *mask) | ||
| 146 | { | ||
| 147 | return seq_bitmap_list(m, cpumask_bits(mask), nr_cpu_ids); | ||
| 148 | } | ||
| 149 | |||
| 150 | static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask) | ||
| 151 | { | ||
| 152 | return seq_bitmap_list(m, mask->bits, MAX_NUMNODES); | ||
| 153 | } | ||
| 154 | 129 | ||
| 155 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); | 130 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); |
| 156 | int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t); | 131 | int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t); |
diff --git a/include/linux/slab.h b/include/linux/slab.h index ed2ffaab59ea..76f1feeabd38 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
| @@ -104,6 +104,7 @@ | |||
| 104 | (unsigned long)ZERO_SIZE_PTR) | 104 | (unsigned long)ZERO_SIZE_PTR) |
| 105 | 105 | ||
| 106 | #include <linux/kmemleak.h> | 106 | #include <linux/kmemleak.h> |
| 107 | #include <linux/kasan.h> | ||
| 107 | 108 | ||
| 108 | struct mem_cgroup; | 109 | struct mem_cgroup; |
| 109 | /* | 110 | /* |
| @@ -325,7 +326,10 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s, | |||
| 325 | static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s, | 326 | static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s, |
| 326 | gfp_t flags, size_t size) | 327 | gfp_t flags, size_t size) |
| 327 | { | 328 | { |
| 328 | return kmem_cache_alloc(s, flags); | 329 | void *ret = kmem_cache_alloc(s, flags); |
| 330 | |||
| 331 | kasan_kmalloc(s, ret, size); | ||
| 332 | return ret; | ||
| 329 | } | 333 | } |
| 330 | 334 | ||
| 331 | static __always_inline void * | 335 | static __always_inline void * |
| @@ -333,7 +337,10 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s, | |||
| 333 | gfp_t gfpflags, | 337 | gfp_t gfpflags, |
| 334 | int node, size_t size) | 338 | int node, size_t size) |
| 335 | { | 339 | { |
| 336 | return kmem_cache_alloc_node(s, gfpflags, node); | 340 | void *ret = kmem_cache_alloc_node(s, gfpflags, node); |
| 341 | |||
| 342 | kasan_kmalloc(s, ret, size); | ||
| 343 | return ret; | ||
| 337 | } | 344 | } |
| 338 | #endif /* CONFIG_TRACING */ | 345 | #endif /* CONFIG_TRACING */ |
| 339 | 346 | ||
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index 9abf04ed0999..33885118523c 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h | |||
| @@ -110,4 +110,23 @@ static inline void sysfs_slab_remove(struct kmem_cache *s) | |||
| 110 | } | 110 | } |
| 111 | #endif | 111 | #endif |
| 112 | 112 | ||
| 113 | |||
| 114 | /** | ||
| 115 | * virt_to_obj - returns address of the beginning of object. | ||
| 116 | * @s: object's kmem_cache | ||
| 117 | * @slab_page: address of slab page | ||
| 118 | * @x: address within object memory range | ||
| 119 | * | ||
| 120 | * Returns address of the beginning of object | ||
| 121 | */ | ||
| 122 | static inline void *virt_to_obj(struct kmem_cache *s, | ||
| 123 | const void *slab_page, | ||
| 124 | const void *x) | ||
| 125 | { | ||
| 126 | return (void *)x - ((x - slab_page) % s->size); | ||
| 127 | } | ||
| 128 | |||
| 129 | void object_err(struct kmem_cache *s, struct page *page, | ||
| 130 | u8 *object, char *reason); | ||
| 131 | |||
| 113 | #endif /* _LINUX_SLUB_DEF_H */ | 132 | #endif /* _LINUX_SLUB_DEF_H */ |
diff --git a/include/linux/string.h b/include/linux/string.h index b9bc9a5d9e21..e40099e585c9 100644 --- a/include/linux/string.h +++ b/include/linux/string.h | |||
| @@ -112,7 +112,10 @@ extern void * memchr(const void *,int,__kernel_size_t); | |||
| 112 | #endif | 112 | #endif |
| 113 | void *memchr_inv(const void *s, int c, size_t n); | 113 | void *memchr_inv(const void *s, int c, size_t n); |
| 114 | 114 | ||
| 115 | extern void kfree_const(const void *x); | ||
| 116 | |||
| 115 | extern char *kstrdup(const char *s, gfp_t gfp); | 117 | extern char *kstrdup(const char *s, gfp_t gfp); |
| 118 | extern const char *kstrdup_const(const char *s, gfp_t gfp); | ||
| 116 | extern char *kstrndup(const char *s, size_t len, gfp_t gfp); | 119 | extern char *kstrndup(const char *s, size_t len, gfp_t gfp); |
| 117 | extern void *kmemdup(const void *src, size_t len, gfp_t gfp); | 120 | extern void *kmemdup(const void *src, size_t len, gfp_t gfp); |
| 118 | 121 | ||
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index b87696fdf06a..7d7acb35603d 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h | |||
| @@ -16,6 +16,7 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */ | |||
| 16 | #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */ | 16 | #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */ |
| 17 | #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */ | 17 | #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */ |
| 18 | #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */ | 18 | #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */ |
| 19 | #define VM_NO_GUARD 0x00000040 /* don't add guard page */ | ||
| 19 | /* bits [20..32] reserved for arch specific ioremap internals */ | 20 | /* bits [20..32] reserved for arch specific ioremap internals */ |
| 20 | 21 | ||
| 21 | /* | 22 | /* |
| @@ -75,7 +76,9 @@ extern void *vmalloc_32_user(unsigned long size); | |||
| 75 | extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot); | 76 | extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot); |
| 76 | extern void *__vmalloc_node_range(unsigned long size, unsigned long align, | 77 | extern void *__vmalloc_node_range(unsigned long size, unsigned long align, |
| 77 | unsigned long start, unsigned long end, gfp_t gfp_mask, | 78 | unsigned long start, unsigned long end, gfp_t gfp_mask, |
| 78 | pgprot_t prot, int node, const void *caller); | 79 | pgprot_t prot, unsigned long vm_flags, int node, |
| 80 | const void *caller); | ||
| 81 | |||
| 79 | extern void vfree(const void *addr); | 82 | extern void vfree(const void *addr); |
| 80 | 83 | ||
| 81 | extern void *vmap(struct page **pages, unsigned int count, | 84 | extern void *vmap(struct page **pages, unsigned int count, |
| @@ -96,8 +99,12 @@ void vmalloc_sync_all(void); | |||
| 96 | 99 | ||
| 97 | static inline size_t get_vm_area_size(const struct vm_struct *area) | 100 | static inline size_t get_vm_area_size(const struct vm_struct *area) |
| 98 | { | 101 | { |
| 99 | /* return actual size without guard page */ | 102 | if (!(area->flags & VM_NO_GUARD)) |
| 100 | return area->size - PAGE_SIZE; | 103 | /* return actual size without guard page */ |
| 104 | return area->size - PAGE_SIZE; | ||
| 105 | else | ||
| 106 | return area->size; | ||
| 107 | |||
| 101 | } | 108 | } |
| 102 | 109 | ||
| 103 | extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags); | 110 | extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags); |
diff --git a/init/Kconfig b/init/Kconfig index 1354ac09b516..058e3671fa11 100644 --- a/init/Kconfig +++ b/init/Kconfig | |||
| @@ -1287,22 +1287,6 @@ source "usr/Kconfig" | |||
| 1287 | 1287 | ||
| 1288 | endif | 1288 | endif |
| 1289 | 1289 | ||
| 1290 | config INIT_FALLBACK | ||
| 1291 | bool "Fall back to defaults if init= parameter is bad" | ||
| 1292 | default y | ||
| 1293 | help | ||
| 1294 | If enabled, the kernel will try the default init binaries if an | ||
| 1295 | explicit request from the init= parameter fails. | ||
| 1296 | |||
| 1297 | This can have unexpected effects. For example, booting | ||
| 1298 | with init=/sbin/kiosk_app will run /sbin/init or even /bin/sh | ||
| 1299 | if /sbin/kiosk_app cannot be executed. | ||
| 1300 | |||
| 1301 | The default value of Y is consistent with historical behavior. | ||
| 1302 | Selecting N is likely to be more appropriate for most uses, | ||
| 1303 | especially on kiosks and on kernels that are intended to be | ||
| 1304 | run under the control of a script. | ||
| 1305 | |||
| 1306 | config CC_OPTIMIZE_FOR_SIZE | 1290 | config CC_OPTIMIZE_FOR_SIZE |
| 1307 | bool "Optimize for size" | 1291 | bool "Optimize for size" |
| 1308 | help | 1292 | help |
diff --git a/init/main.c b/init/main.c index 179ada15d08a..6f0f1c5ff8cc 100644 --- a/init/main.c +++ b/init/main.c | |||
| @@ -953,13 +953,8 @@ static int __ref kernel_init(void *unused) | |||
| 953 | ret = run_init_process(execute_command); | 953 | ret = run_init_process(execute_command); |
| 954 | if (!ret) | 954 | if (!ret) |
| 955 | return 0; | 955 | return 0; |
| 956 | #ifndef CONFIG_INIT_FALLBACK | ||
| 957 | panic("Requested init %s failed (error %d).", | 956 | panic("Requested init %s failed (error %d).", |
| 958 | execute_command, ret); | 957 | execute_command, ret); |
| 959 | #else | ||
| 960 | pr_err("Failed to execute %s (error %d). Attempting defaults...\n", | ||
| 961 | execute_command, ret); | ||
| 962 | #endif | ||
| 963 | } | 958 | } |
| 964 | if (!try_to_run_init_process("/sbin/init") || | 959 | if (!try_to_run_init_process("/sbin/init") || |
| 965 | !try_to_run_init_process("/etc/init") || | 960 | !try_to_run_init_process("/etc/init") || |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d5f6ec251fb2..29a7b2cc593e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -3077,7 +3077,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft) | |||
| 3077 | #endif | 3077 | #endif |
| 3078 | kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), | 3078 | kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), |
| 3079 | cgroup_file_mode(cft), 0, cft->kf_ops, cft, | 3079 | cgroup_file_mode(cft), 0, cft->kf_ops, cft, |
| 3080 | NULL, false, key); | 3080 | NULL, key); |
| 3081 | if (IS_ERR(kn)) | 3081 | if (IS_ERR(kn)) |
| 3082 | return PTR_ERR(kn); | 3082 | return PTR_ERR(kn); |
| 3083 | 3083 | ||
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index c54a1dae6c11..1d1fe9361d29 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
| @@ -1707,40 +1707,27 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v) | |||
| 1707 | { | 1707 | { |
| 1708 | struct cpuset *cs = css_cs(seq_css(sf)); | 1708 | struct cpuset *cs = css_cs(seq_css(sf)); |
| 1709 | cpuset_filetype_t type = seq_cft(sf)->private; | 1709 | cpuset_filetype_t type = seq_cft(sf)->private; |
| 1710 | ssize_t count; | ||
| 1711 | char *buf, *s; | ||
| 1712 | int ret = 0; | 1710 | int ret = 0; |
| 1713 | 1711 | ||
| 1714 | count = seq_get_buf(sf, &buf); | ||
| 1715 | s = buf; | ||
| 1716 | |||
| 1717 | spin_lock_irq(&callback_lock); | 1712 | spin_lock_irq(&callback_lock); |
| 1718 | 1713 | ||
| 1719 | switch (type) { | 1714 | switch (type) { |
| 1720 | case FILE_CPULIST: | 1715 | case FILE_CPULIST: |
| 1721 | s += cpulist_scnprintf(s, count, cs->cpus_allowed); | 1716 | seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->cpus_allowed)); |
| 1722 | break; | 1717 | break; |
| 1723 | case FILE_MEMLIST: | 1718 | case FILE_MEMLIST: |
| 1724 | s += nodelist_scnprintf(s, count, cs->mems_allowed); | 1719 | seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->mems_allowed)); |
| 1725 | break; | 1720 | break; |
| 1726 | case FILE_EFFECTIVE_CPULIST: | 1721 | case FILE_EFFECTIVE_CPULIST: |
| 1727 | s += cpulist_scnprintf(s, count, cs->effective_cpus); | 1722 | seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->effective_cpus)); |
| 1728 | break; | 1723 | break; |
| 1729 | case FILE_EFFECTIVE_MEMLIST: | 1724 | case FILE_EFFECTIVE_MEMLIST: |
| 1730 | s += nodelist_scnprintf(s, count, cs->effective_mems); | 1725 | seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems)); |
| 1731 | break; | 1726 | break; |
| 1732 | default: | 1727 | default: |
| 1733 | ret = -EINVAL; | 1728 | ret = -EINVAL; |
| 1734 | goto out_unlock; | ||
| 1735 | } | 1729 | } |
| 1736 | 1730 | ||
| 1737 | if (s < buf + count - 1) { | ||
| 1738 | *s++ = '\n'; | ||
| 1739 | seq_commit(sf, s - buf); | ||
| 1740 | } else { | ||
| 1741 | seq_commit(sf, -1); | ||
| 1742 | } | ||
| 1743 | out_unlock: | ||
| 1744 | spin_unlock_irq(&callback_lock); | 1731 | spin_unlock_irq(&callback_lock); |
| 1745 | return ret; | 1732 | return ret; |
| 1746 | } | 1733 | } |
| @@ -2610,8 +2597,6 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1, | |||
| 2610 | return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed); | 2597 | return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed); |
| 2611 | } | 2598 | } |
| 2612 | 2599 | ||
| 2613 | #define CPUSET_NODELIST_LEN (256) | ||
| 2614 | |||
| 2615 | /** | 2600 | /** |
| 2616 | * cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed | 2601 | * cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed |
| 2617 | * @tsk: pointer to task_struct of some task. | 2602 | * @tsk: pointer to task_struct of some task. |
| @@ -2621,23 +2606,16 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1, | |||
| 2621 | */ | 2606 | */ |
| 2622 | void cpuset_print_task_mems_allowed(struct task_struct *tsk) | 2607 | void cpuset_print_task_mems_allowed(struct task_struct *tsk) |
| 2623 | { | 2608 | { |
| 2624 | /* Statically allocated to prevent using excess stack. */ | ||
| 2625 | static char cpuset_nodelist[CPUSET_NODELIST_LEN]; | ||
| 2626 | static DEFINE_SPINLOCK(cpuset_buffer_lock); | ||
| 2627 | struct cgroup *cgrp; | 2609 | struct cgroup *cgrp; |
| 2628 | 2610 | ||
| 2629 | spin_lock(&cpuset_buffer_lock); | ||
| 2630 | rcu_read_lock(); | 2611 | rcu_read_lock(); |
| 2631 | 2612 | ||
| 2632 | cgrp = task_cs(tsk)->css.cgroup; | 2613 | cgrp = task_cs(tsk)->css.cgroup; |
| 2633 | nodelist_scnprintf(cpuset_nodelist, CPUSET_NODELIST_LEN, | ||
| 2634 | tsk->mems_allowed); | ||
| 2635 | pr_info("%s cpuset=", tsk->comm); | 2614 | pr_info("%s cpuset=", tsk->comm); |
| 2636 | pr_cont_cgroup_name(cgrp); | 2615 | pr_cont_cgroup_name(cgrp); |
| 2637 | pr_cont(" mems_allowed=%s\n", cpuset_nodelist); | 2616 | pr_cont(" mems_allowed=%*pbl\n", nodemask_pr_args(&tsk->mems_allowed)); |
| 2638 | 2617 | ||
| 2639 | rcu_read_unlock(); | 2618 | rcu_read_unlock(); |
| 2640 | spin_unlock(&cpuset_buffer_lock); | ||
| 2641 | } | 2619 | } |
| 2642 | 2620 | ||
| 2643 | /* | 2621 | /* |
| @@ -2715,10 +2693,8 @@ out: | |||
| 2715 | /* Display task mems_allowed in /proc/<pid>/status file. */ | 2693 | /* Display task mems_allowed in /proc/<pid>/status file. */ |
| 2716 | void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task) | 2694 | void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task) |
| 2717 | { | 2695 | { |
| 2718 | seq_puts(m, "Mems_allowed:\t"); | 2696 | seq_printf(m, "Mems_allowed:\t%*pb\n", |
| 2719 | seq_nodemask(m, &task->mems_allowed); | 2697 | nodemask_pr_args(&task->mems_allowed)); |
| 2720 | seq_puts(m, "\n"); | 2698 | seq_printf(m, "Mems_allowed_list:\t%*pbl\n", |
| 2721 | seq_puts(m, "Mems_allowed_list:\t"); | 2699 | nodemask_pr_args(&task->mems_allowed)); |
| 2722 | seq_nodemask_list(m, &task->mems_allowed); | ||
| 2723 | seq_puts(m, "\n"); | ||
| 2724 | } | 2700 | } |
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 9dc9bfd8a678..df2f4642d1e7 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c | |||
| @@ -46,10 +46,9 @@ static int show_irq_affinity(int type, struct seq_file *m, void *v) | |||
| 46 | mask = desc->pending_mask; | 46 | mask = desc->pending_mask; |
| 47 | #endif | 47 | #endif |
| 48 | if (type) | 48 | if (type) |
| 49 | seq_cpumask_list(m, mask); | 49 | seq_printf(m, "%*pbl\n", cpumask_pr_args(mask)); |
| 50 | else | 50 | else |
| 51 | seq_cpumask(m, mask); | 51 | seq_printf(m, "%*pb\n", cpumask_pr_args(mask)); |
| 52 | seq_putc(m, '\n'); | ||
| 53 | return 0; | 52 | return 0; |
| 54 | } | 53 | } |
| 55 | 54 | ||
| @@ -67,8 +66,7 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v) | |||
| 67 | cpumask_copy(mask, desc->affinity_hint); | 66 | cpumask_copy(mask, desc->affinity_hint); |
| 68 | raw_spin_unlock_irqrestore(&desc->lock, flags); | 67 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 69 | 68 | ||
| 70 | seq_cpumask(m, mask); | 69 | seq_printf(m, "%*pb\n", cpumask_pr_args(mask)); |
| 71 | seq_putc(m, '\n'); | ||
| 72 | free_cpumask_var(mask); | 70 | free_cpumask_var(mask); |
| 73 | 71 | ||
| 74 | return 0; | 72 | return 0; |
| @@ -186,8 +184,7 @@ static const struct file_operations irq_affinity_list_proc_fops = { | |||
| 186 | 184 | ||
| 187 | static int default_affinity_show(struct seq_file *m, void *v) | 185 | static int default_affinity_show(struct seq_file *m, void *v) |
| 188 | { | 186 | { |
| 189 | seq_cpumask(m, irq_default_affinity); | 187 | seq_printf(m, "%*pb\n", cpumask_pr_args(irq_default_affinity)); |
| 190 | seq_putc(m, '\n'); | ||
| 191 | return 0; | 188 | return 0; |
| 192 | } | 189 | } |
| 193 | 190 | ||
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2ca272f8f62e..c90e417bb963 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
| @@ -869,7 +869,8 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt) | |||
| 869 | { | 869 | { |
| 870 | struct kprobe *_p; | 870 | struct kprobe *_p; |
| 871 | 871 | ||
| 872 | unoptimize_kprobe(p, false); /* Try to unoptimize */ | 872 | /* Try to unoptimize */ |
| 873 | unoptimize_kprobe(p, kprobes_all_disarmed); | ||
| 873 | 874 | ||
| 874 | if (!kprobe_queued(p)) { | 875 | if (!kprobe_queued(p)) { |
| 875 | arch_disarm_kprobe(p); | 876 | arch_disarm_kprobe(p); |
| @@ -1571,7 +1572,13 @@ static struct kprobe *__disable_kprobe(struct kprobe *p) | |||
| 1571 | 1572 | ||
| 1572 | /* Try to disarm and disable this/parent probe */ | 1573 | /* Try to disarm and disable this/parent probe */ |
| 1573 | if (p == orig_p || aggr_kprobe_disabled(orig_p)) { | 1574 | if (p == orig_p || aggr_kprobe_disabled(orig_p)) { |
| 1574 | disarm_kprobe(orig_p, true); | 1575 | /* |
| 1576 | * If kprobes_all_disarmed is set, orig_p | ||
| 1577 | * should have already been disarmed, so | ||
| 1578 | * skip unneed disarming process. | ||
| 1579 | */ | ||
| 1580 | if (!kprobes_all_disarmed) | ||
| 1581 | disarm_kprobe(orig_p, true); | ||
| 1575 | orig_p->flags |= KPROBE_FLAG_DISABLED; | 1582 | orig_p->flags |= KPROBE_FLAG_DISABLED; |
| 1576 | } | 1583 | } |
| 1577 | } | 1584 | } |
| @@ -2320,6 +2327,12 @@ static void arm_all_kprobes(void) | |||
| 2320 | if (!kprobes_all_disarmed) | 2327 | if (!kprobes_all_disarmed) |
| 2321 | goto already_enabled; | 2328 | goto already_enabled; |
| 2322 | 2329 | ||
| 2330 | /* | ||
| 2331 | * optimize_kprobe() called by arm_kprobe() checks | ||
| 2332 | * kprobes_all_disarmed, so set kprobes_all_disarmed before | ||
| 2333 | * arm_kprobe. | ||
| 2334 | */ | ||
| 2335 | kprobes_all_disarmed = false; | ||
| 2323 | /* Arming kprobes doesn't optimize kprobe itself */ | 2336 | /* Arming kprobes doesn't optimize kprobe itself */ |
| 2324 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 2337 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
| 2325 | head = &kprobe_table[i]; | 2338 | head = &kprobe_table[i]; |
| @@ -2328,7 +2341,6 @@ static void arm_all_kprobes(void) | |||
| 2328 | arm_kprobe(p); | 2341 | arm_kprobe(p); |
| 2329 | } | 2342 | } |
| 2330 | 2343 | ||
| 2331 | kprobes_all_disarmed = false; | ||
| 2332 | printk(KERN_INFO "Kprobes globally enabled\n"); | 2344 | printk(KERN_INFO "Kprobes globally enabled\n"); |
| 2333 | 2345 | ||
| 2334 | already_enabled: | 2346 | already_enabled: |
diff --git a/kernel/module.c b/kernel/module.c index 82dc1f899e6d..8426ad48362c 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -56,6 +56,7 @@ | |||
| 56 | #include <linux/async.h> | 56 | #include <linux/async.h> |
| 57 | #include <linux/percpu.h> | 57 | #include <linux/percpu.h> |
| 58 | #include <linux/kmemleak.h> | 58 | #include <linux/kmemleak.h> |
| 59 | #include <linux/kasan.h> | ||
| 59 | #include <linux/jump_label.h> | 60 | #include <linux/jump_label.h> |
| 60 | #include <linux/pfn.h> | 61 | #include <linux/pfn.h> |
| 61 | #include <linux/bsearch.h> | 62 | #include <linux/bsearch.h> |
| @@ -1813,6 +1814,7 @@ static void unset_module_init_ro_nx(struct module *mod) { } | |||
| 1813 | void __weak module_memfree(void *module_region) | 1814 | void __weak module_memfree(void *module_region) |
| 1814 | { | 1815 | { |
| 1815 | vfree(module_region); | 1816 | vfree(module_region); |
| 1817 | kasan_module_free(module_region); | ||
| 1816 | } | 1818 | } |
| 1817 | 1819 | ||
| 1818 | void __weak module_arch_cleanup(struct module *mod) | 1820 | void __weak module_arch_cleanup(struct module *mod) |
diff --git a/kernel/padata.c b/kernel/padata.c index 161402f0b517..b38bea9c466a 100644 --- a/kernel/padata.c +++ b/kernel/padata.c | |||
| @@ -917,15 +917,10 @@ static ssize_t show_cpumask(struct padata_instance *pinst, | |||
| 917 | else | 917 | else |
| 918 | cpumask = pinst->cpumask.pcpu; | 918 | cpumask = pinst->cpumask.pcpu; |
| 919 | 919 | ||
| 920 | len = bitmap_scnprintf(buf, PAGE_SIZE, cpumask_bits(cpumask), | 920 | len = snprintf(buf, PAGE_SIZE, "%*pb\n", |
| 921 | nr_cpu_ids); | 921 | nr_cpu_ids, cpumask_bits(cpumask)); |
| 922 | if (PAGE_SIZE - len < 2) | ||
| 923 | len = -EINVAL; | ||
| 924 | else | ||
| 925 | len += sprintf(buf + len, "\n"); | ||
| 926 | |||
| 927 | mutex_unlock(&pinst->lock); | 922 | mutex_unlock(&pinst->lock); |
| 928 | return len; | 923 | return len < PAGE_SIZE ? len : -EINVAL; |
| 929 | } | 924 | } |
| 930 | 925 | ||
| 931 | static ssize_t store_cpumask(struct padata_instance *pinst, | 926 | static ssize_t store_cpumask(struct padata_instance *pinst, |
diff --git a/kernel/profile.c b/kernel/profile.c index 54bf5ba26420..a7bcd28d6e9f 100644 --- a/kernel/profile.c +++ b/kernel/profile.c | |||
| @@ -422,8 +422,7 @@ void profile_tick(int type) | |||
| 422 | 422 | ||
| 423 | static int prof_cpu_mask_proc_show(struct seq_file *m, void *v) | 423 | static int prof_cpu_mask_proc_show(struct seq_file *m, void *v) |
| 424 | { | 424 | { |
| 425 | seq_cpumask(m, prof_cpu_mask); | 425 | seq_printf(m, "%*pb\n", cpumask_pr_args(prof_cpu_mask)); |
| 426 | seq_putc(m, '\n'); | ||
| 427 | return 0; | 426 | return 0; |
| 428 | } | 427 | } |
| 429 | 428 | ||
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 2e850a51bb8f..0d7bbe3095ad 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h | |||
| @@ -49,7 +49,6 @@ DEFINE_PER_CPU(char, rcu_cpu_has_work); | |||
| 49 | static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */ | 49 | static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */ |
| 50 | static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */ | 50 | static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */ |
| 51 | static bool __read_mostly rcu_nocb_poll; /* Offload kthread are to poll. */ | 51 | static bool __read_mostly rcu_nocb_poll; /* Offload kthread are to poll. */ |
| 52 | static char __initdata nocb_buf[NR_CPUS * 5]; | ||
| 53 | #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ | 52 | #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ |
| 54 | 53 | ||
| 55 | /* | 54 | /* |
| @@ -2386,8 +2385,8 @@ void __init rcu_init_nohz(void) | |||
| 2386 | cpumask_and(rcu_nocb_mask, cpu_possible_mask, | 2385 | cpumask_and(rcu_nocb_mask, cpu_possible_mask, |
| 2387 | rcu_nocb_mask); | 2386 | rcu_nocb_mask); |
| 2388 | } | 2387 | } |
| 2389 | cpulist_scnprintf(nocb_buf, sizeof(nocb_buf), rcu_nocb_mask); | 2388 | pr_info("\tOffload RCU callbacks from CPUs: %*pbl.\n", |
| 2390 | pr_info("\tOffload RCU callbacks from CPUs: %s.\n", nocb_buf); | 2389 | cpumask_pr_args(rcu_nocb_mask)); |
| 2391 | if (rcu_nocb_poll) | 2390 | if (rcu_nocb_poll) |
| 2392 | pr_info("\tPoll for callbacks from no-CBs CPUs.\n"); | 2391 | pr_info("\tPoll for callbacks from no-CBs CPUs.\n"); |
| 2393 | 2392 | ||
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1f37fe7f77a4..13049aac05a6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
| @@ -5462,9 +5462,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 5462 | struct cpumask *groupmask) | 5462 | struct cpumask *groupmask) |
| 5463 | { | 5463 | { |
| 5464 | struct sched_group *group = sd->groups; | 5464 | struct sched_group *group = sd->groups; |
| 5465 | char str[256]; | ||
| 5466 | 5465 | ||
| 5467 | cpulist_scnprintf(str, sizeof(str), sched_domain_span(sd)); | ||
| 5468 | cpumask_clear(groupmask); | 5466 | cpumask_clear(groupmask); |
| 5469 | 5467 | ||
| 5470 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); | 5468 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); |
| @@ -5477,7 +5475,8 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 5477 | return -1; | 5475 | return -1; |
| 5478 | } | 5476 | } |
| 5479 | 5477 | ||
| 5480 | printk(KERN_CONT "span %s level %s\n", str, sd->name); | 5478 | printk(KERN_CONT "span %*pbl level %s\n", |
| 5479 | cpumask_pr_args(sched_domain_span(sd)), sd->name); | ||
| 5481 | 5480 | ||
| 5482 | if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) { | 5481 | if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
| 5483 | printk(KERN_ERR "ERROR: domain->span does not contain " | 5482 | printk(KERN_ERR "ERROR: domain->span does not contain " |
| @@ -5522,9 +5521,8 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 5522 | 5521 | ||
| 5523 | cpumask_or(groupmask, groupmask, sched_group_cpus(group)); | 5522 | cpumask_or(groupmask, groupmask, sched_group_cpus(group)); |
| 5524 | 5523 | ||
| 5525 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); | 5524 | printk(KERN_CONT " %*pbl", |
| 5526 | 5525 | cpumask_pr_args(sched_group_cpus(group))); | |
| 5527 | printk(KERN_CONT " %s", str); | ||
| 5528 | if (group->sgc->capacity != SCHED_CAPACITY_SCALE) { | 5526 | if (group->sgc->capacity != SCHED_CAPACITY_SCALE) { |
| 5529 | printk(KERN_CONT " (cpu_capacity = %d)", | 5527 | printk(KERN_CONT " (cpu_capacity = %d)", |
| 5530 | group->sgc->capacity); | 5528 | group->sgc->capacity); |
diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c index a476bea17fbc..87e2c9f0c33e 100644 --- a/kernel/sched/stats.c +++ b/kernel/sched/stats.c | |||
| @@ -15,11 +15,6 @@ | |||
| 15 | static int show_schedstat(struct seq_file *seq, void *v) | 15 | static int show_schedstat(struct seq_file *seq, void *v) |
| 16 | { | 16 | { |
| 17 | int cpu; | 17 | int cpu; |
| 18 | int mask_len = DIV_ROUND_UP(NR_CPUS, 32) * 9; | ||
| 19 | char *mask_str = kmalloc(mask_len, GFP_KERNEL); | ||
| 20 | |||
| 21 | if (mask_str == NULL) | ||
| 22 | return -ENOMEM; | ||
| 23 | 18 | ||
| 24 | if (v == (void *)1) { | 19 | if (v == (void *)1) { |
| 25 | seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION); | 20 | seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION); |
| @@ -50,9 +45,8 @@ static int show_schedstat(struct seq_file *seq, void *v) | |||
| 50 | for_each_domain(cpu, sd) { | 45 | for_each_domain(cpu, sd) { |
| 51 | enum cpu_idle_type itype; | 46 | enum cpu_idle_type itype; |
| 52 | 47 | ||
| 53 | cpumask_scnprintf(mask_str, mask_len, | 48 | seq_printf(seq, "domain%d %*pb", dcount++, |
| 54 | sched_domain_span(sd)); | 49 | cpumask_pr_args(sched_domain_span(sd))); |
| 55 | seq_printf(seq, "domain%d %s", dcount++, mask_str); | ||
| 56 | for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES; | 50 | for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES; |
| 57 | itype++) { | 51 | itype++) { |
| 58 | seq_printf(seq, " %u %u %u %u %u %u %u %u", | 52 | seq_printf(seq, " %u %u %u %u %u %u %u %u", |
| @@ -76,7 +70,6 @@ static int show_schedstat(struct seq_file *seq, void *v) | |||
| 76 | rcu_read_unlock(); | 70 | rcu_read_unlock(); |
| 77 | #endif | 71 | #endif |
| 78 | } | 72 | } |
| 79 | kfree(mask_str); | ||
| 80 | return 0; | 73 | return 0; |
| 81 | } | 74 | } |
| 82 | 75 | ||
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 1363d58f07e9..a4c4edac4528 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c | |||
| @@ -326,13 +326,6 @@ static int tick_nohz_cpu_down_callback(struct notifier_block *nfb, | |||
| 326 | return NOTIFY_OK; | 326 | return NOTIFY_OK; |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | /* | ||
| 330 | * Worst case string length in chunks of CPU range seems 2 steps | ||
| 331 | * separations: 0,2,4,6,... | ||
| 332 | * This is NR_CPUS + sizeof('\0') | ||
| 333 | */ | ||
| 334 | static char __initdata nohz_full_buf[NR_CPUS + 1]; | ||
| 335 | |||
| 336 | static int tick_nohz_init_all(void) | 329 | static int tick_nohz_init_all(void) |
| 337 | { | 330 | { |
| 338 | int err = -1; | 331 | int err = -1; |
| @@ -393,8 +386,8 @@ void __init tick_nohz_init(void) | |||
| 393 | context_tracking_cpu_set(cpu); | 386 | context_tracking_cpu_set(cpu); |
| 394 | 387 | ||
| 395 | cpu_notifier(tick_nohz_cpu_down_callback, 0); | 388 | cpu_notifier(tick_nohz_cpu_down_callback, 0); |
| 396 | cpulist_scnprintf(nohz_full_buf, sizeof(nohz_full_buf), tick_nohz_full_mask); | 389 | pr_info("NO_HZ: Full dynticks CPUs: %*pbl.\n", |
| 397 | pr_info("NO_HZ: Full dynticks CPUs: %s.\n", nohz_full_buf); | 390 | cpumask_pr_args(tick_nohz_full_mask)); |
| 398 | } | 391 | } |
| 399 | #endif | 392 | #endif |
| 400 | 393 | ||
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 77b8dc528006..62c6506d663f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -3353,12 +3353,12 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf, | |||
| 3353 | 3353 | ||
| 3354 | mutex_lock(&tracing_cpumask_update_lock); | 3354 | mutex_lock(&tracing_cpumask_update_lock); |
| 3355 | 3355 | ||
| 3356 | len = cpumask_scnprintf(mask_str, count, tr->tracing_cpumask); | 3356 | len = snprintf(mask_str, count, "%*pb\n", |
| 3357 | if (count - len < 2) { | 3357 | cpumask_pr_args(tr->tracing_cpumask)); |
| 3358 | if (len >= count) { | ||
| 3358 | count = -EINVAL; | 3359 | count = -EINVAL; |
| 3359 | goto out_err; | 3360 | goto out_err; |
| 3360 | } | 3361 | } |
| 3361 | len += sprintf(mask_str + len, "\n"); | ||
| 3362 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); | 3362 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3363 | 3363 | ||
| 3364 | out_err: | 3364 | out_err: |
diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c index f8b45d8792f9..e694c9f9efa4 100644 --- a/kernel/trace/trace_seq.c +++ b/kernel/trace/trace_seq.c | |||
| @@ -120,7 +120,7 @@ void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, | |||
| 120 | 120 | ||
| 121 | __trace_seq_init(s); | 121 | __trace_seq_init(s); |
| 122 | 122 | ||
| 123 | seq_buf_bitmask(&s->seq, maskp, nmaskbits); | 123 | seq_buf_printf(&s->seq, "%*pb", nmaskbits, maskp); |
| 124 | 124 | ||
| 125 | if (unlikely(seq_buf_has_overflowed(&s->seq))) { | 125 | if (unlikely(seq_buf_has_overflowed(&s->seq))) { |
| 126 | s->seq.len = save_len; | 126 | s->seq.len = save_len; |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index beeeac9e0e3e..f28849394791 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
| @@ -3083,10 +3083,9 @@ static ssize_t wq_cpumask_show(struct device *dev, | |||
| 3083 | int written; | 3083 | int written; |
| 3084 | 3084 | ||
| 3085 | mutex_lock(&wq->mutex); | 3085 | mutex_lock(&wq->mutex); |
| 3086 | written = cpumask_scnprintf(buf, PAGE_SIZE, wq->unbound_attrs->cpumask); | 3086 | written = scnprintf(buf, PAGE_SIZE, "%*pb\n", |
| 3087 | cpumask_pr_args(wq->unbound_attrs->cpumask)); | ||
| 3087 | mutex_unlock(&wq->mutex); | 3088 | mutex_unlock(&wq->mutex); |
| 3088 | |||
| 3089 | written += scnprintf(buf + written, PAGE_SIZE - written, "\n"); | ||
| 3090 | return written; | 3089 | return written; |
| 3091 | } | 3090 | } |
| 3092 | 3091 | ||
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 79a9bb67aeaf..ecb3516f6546 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -651,6 +651,8 @@ config DEBUG_STACKOVERFLOW | |||
| 651 | 651 | ||
| 652 | source "lib/Kconfig.kmemcheck" | 652 | source "lib/Kconfig.kmemcheck" |
| 653 | 653 | ||
| 654 | source "lib/Kconfig.kasan" | ||
| 655 | |||
| 654 | endmenu # "Memory Debugging" | 656 | endmenu # "Memory Debugging" |
| 655 | 657 | ||
| 656 | config DEBUG_SHIRQ | 658 | config DEBUG_SHIRQ |
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan new file mode 100644 index 000000000000..4fecaedc80a2 --- /dev/null +++ b/lib/Kconfig.kasan | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | config HAVE_ARCH_KASAN | ||
| 2 | bool | ||
| 3 | |||
| 4 | if HAVE_ARCH_KASAN | ||
| 5 | |||
| 6 | config KASAN | ||
| 7 | bool "KASan: runtime memory debugger" | ||
| 8 | depends on SLUB_DEBUG | ||
| 9 | select CONSTRUCTORS | ||
| 10 | help | ||
| 11 | Enables kernel address sanitizer - runtime memory debugger, | ||
| 12 | designed to find out-of-bounds accesses and use-after-free bugs. | ||
| 13 | This is strictly debugging feature. It consumes about 1/8 | ||
| 14 | of available memory and brings about ~x3 performance slowdown. | ||
| 15 | For better error detection enable CONFIG_STACKTRACE, | ||
| 16 | and add slub_debug=U to boot cmdline. | ||
| 17 | |||
| 18 | config KASAN_SHADOW_OFFSET | ||
| 19 | hex | ||
| 20 | default 0xdffffc0000000000 if X86_64 | ||
| 21 | |||
| 22 | choice | ||
| 23 | prompt "Instrumentation type" | ||
| 24 | depends on KASAN | ||
| 25 | default KASAN_OUTLINE | ||
| 26 | |||
| 27 | config KASAN_OUTLINE | ||
| 28 | bool "Outline instrumentation" | ||
| 29 | help | ||
| 30 | Before every memory access compiler insert function call | ||
| 31 | __asan_load*/__asan_store*. These functions performs check | ||
| 32 | of shadow memory. This is slower than inline instrumentation, | ||
| 33 | however it doesn't bloat size of kernel's .text section so | ||
| 34 | much as inline does. | ||
| 35 | |||
| 36 | config KASAN_INLINE | ||
| 37 | bool "Inline instrumentation" | ||
| 38 | help | ||
| 39 | Compiler directly inserts code checking shadow memory before | ||
| 40 | memory accesses. This is faster than outline (in some workloads | ||
| 41 | it gives about x2 boost over outline instrumentation), but | ||
| 42 | make kernel's .text size much bigger. | ||
| 43 | |||
| 44 | endchoice | ||
| 45 | |||
| 46 | config TEST_KASAN | ||
| 47 | tristate "Module for testing kasan for bug detection" | ||
| 48 | depends on m && KASAN | ||
| 49 | help | ||
| 50 | This is a test module doing various nasty things like | ||
| 51 | out of bounds accesses, use after free. It is useful for testing | ||
| 52 | kernel debugging features like kernel address sanitizer. | ||
| 53 | |||
| 54 | endif | ||
diff --git a/lib/Makefile b/lib/Makefile index e456defd1021..87eb3bffc283 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -32,12 +32,13 @@ obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o | |||
| 32 | obj-y += hexdump.o | 32 | obj-y += hexdump.o |
| 33 | obj-$(CONFIG_TEST_HEXDUMP) += test-hexdump.o | 33 | obj-$(CONFIG_TEST_HEXDUMP) += test-hexdump.o |
| 34 | obj-y += kstrtox.o | 34 | obj-y += kstrtox.o |
| 35 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | ||
| 36 | obj-$(CONFIG_TEST_LKM) += test_module.o | ||
| 37 | obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o | ||
| 38 | obj-$(CONFIG_TEST_BPF) += test_bpf.o | 35 | obj-$(CONFIG_TEST_BPF) += test_bpf.o |
| 39 | obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o | 36 | obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o |
| 37 | obj-$(CONFIG_TEST_KASAN) += test_kasan.o | ||
| 38 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | ||
| 39 | obj-$(CONFIG_TEST_LKM) += test_module.o | ||
| 40 | obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o | 40 | obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o |
| 41 | obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o | ||
| 41 | 42 | ||
| 42 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 43 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
| 43 | CFLAGS_kobject.o += -DDEBUG | 44 | CFLAGS_kobject.o += -DDEBUG |
diff --git a/lib/bitmap.c b/lib/bitmap.c index ad161a6c82db..d456f4c15a9f 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
| @@ -104,18 +104,18 @@ EXPORT_SYMBOL(__bitmap_complement); | |||
| 104 | * @dst : destination bitmap | 104 | * @dst : destination bitmap |
| 105 | * @src : source bitmap | 105 | * @src : source bitmap |
| 106 | * @shift : shift by this many bits | 106 | * @shift : shift by this many bits |
| 107 | * @bits : bitmap size, in bits | 107 | * @nbits : bitmap size, in bits |
| 108 | * | 108 | * |
| 109 | * Shifting right (dividing) means moving bits in the MS -> LS bit | 109 | * Shifting right (dividing) means moving bits in the MS -> LS bit |
| 110 | * direction. Zeros are fed into the vacated MS positions and the | 110 | * direction. Zeros are fed into the vacated MS positions and the |
| 111 | * LS bits shifted off the bottom are lost. | 111 | * LS bits shifted off the bottom are lost. |
| 112 | */ | 112 | */ |
| 113 | void __bitmap_shift_right(unsigned long *dst, | 113 | void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
| 114 | const unsigned long *src, int shift, int bits) | 114 | unsigned shift, unsigned nbits) |
| 115 | { | 115 | { |
| 116 | int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG; | 116 | unsigned k, lim = BITS_TO_LONGS(nbits); |
| 117 | int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; | 117 | unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; |
| 118 | unsigned long mask = (1UL << left) - 1; | 118 | unsigned long mask = BITMAP_LAST_WORD_MASK(nbits); |
| 119 | for (k = 0; off + k < lim; ++k) { | 119 | for (k = 0; off + k < lim; ++k) { |
| 120 | unsigned long upper, lower; | 120 | unsigned long upper, lower; |
| 121 | 121 | ||
| @@ -127,17 +127,15 @@ void __bitmap_shift_right(unsigned long *dst, | |||
| 127 | upper = 0; | 127 | upper = 0; |
| 128 | else { | 128 | else { |
| 129 | upper = src[off + k + 1]; | 129 | upper = src[off + k + 1]; |
| 130 | if (off + k + 1 == lim - 1 && left) | 130 | if (off + k + 1 == lim - 1) |
| 131 | upper &= mask; | 131 | upper &= mask; |
| 132 | upper <<= (BITS_PER_LONG - rem); | ||
| 132 | } | 133 | } |
| 133 | lower = src[off + k]; | 134 | lower = src[off + k]; |
| 134 | if (left && off + k == lim - 1) | 135 | if (off + k == lim - 1) |
| 135 | lower &= mask; | 136 | lower &= mask; |
| 136 | dst[k] = lower >> rem; | 137 | lower >>= rem; |
| 137 | if (rem) | 138 | dst[k] = lower | upper; |
| 138 | dst[k] |= upper << (BITS_PER_LONG - rem); | ||
| 139 | if (left && k == lim - 1) | ||
| 140 | dst[k] &= mask; | ||
| 141 | } | 139 | } |
| 142 | if (off) | 140 | if (off) |
| 143 | memset(&dst[lim - off], 0, off*sizeof(unsigned long)); | 141 | memset(&dst[lim - off], 0, off*sizeof(unsigned long)); |
| @@ -150,18 +148,19 @@ EXPORT_SYMBOL(__bitmap_shift_right); | |||
| 150 | * @dst : destination bitmap | 148 | * @dst : destination bitmap |
| 151 | * @src : source bitmap | 149 | * @src : source bitmap |
| 152 | * @shift : shift by this many bits | 150 | * @shift : shift by this many bits |
| 153 | * @bits : bitmap size, in bits | 151 | * @nbits : bitmap size, in bits |
| 154 | * | 152 | * |
| 155 | * Shifting left (multiplying) means moving bits in the LS -> MS | 153 | * Shifting left (multiplying) means moving bits in the LS -> MS |
| 156 | * direction. Zeros are fed into the vacated LS bit positions | 154 | * direction. Zeros are fed into the vacated LS bit positions |
| 157 | * and those MS bits shifted off the top are lost. | 155 | * and those MS bits shifted off the top are lost. |
| 158 | */ | 156 | */ |
| 159 | 157 | ||
| 160 | void __bitmap_shift_left(unsigned long *dst, | 158 | void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
| 161 | const unsigned long *src, int shift, int bits) | 159 | unsigned int shift, unsigned int nbits) |
| 162 | { | 160 | { |
| 163 | int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG; | 161 | int k; |
| 164 | int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; | 162 | unsigned int lim = BITS_TO_LONGS(nbits); |
| 163 | unsigned int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; | ||
| 165 | for (k = lim - off - 1; k >= 0; --k) { | 164 | for (k = lim - off - 1; k >= 0; --k) { |
| 166 | unsigned long upper, lower; | 165 | unsigned long upper, lower; |
| 167 | 166 | ||
| @@ -170,17 +169,11 @@ void __bitmap_shift_left(unsigned long *dst, | |||
| 170 | * word below and make them the bottom rem bits of result. | 169 | * word below and make them the bottom rem bits of result. |
| 171 | */ | 170 | */ |
| 172 | if (rem && k > 0) | 171 | if (rem && k > 0) |
| 173 | lower = src[k - 1]; | 172 | lower = src[k - 1] >> (BITS_PER_LONG - rem); |
| 174 | else | 173 | else |
| 175 | lower = 0; | 174 | lower = 0; |
| 176 | upper = src[k]; | 175 | upper = src[k] << rem; |
| 177 | if (left && k == lim - 1) | 176 | dst[k + off] = lower | upper; |
| 178 | upper &= (1UL << left) - 1; | ||
| 179 | dst[k + off] = upper << rem; | ||
| 180 | if (rem) | ||
| 181 | dst[k + off] |= lower >> (BITS_PER_LONG - rem); | ||
| 182 | if (left && k + off == lim - 1) | ||
| 183 | dst[k + off] &= (1UL << left) - 1; | ||
| 184 | } | 177 | } |
| 185 | if (off) | 178 | if (off) |
| 186 | memset(dst, 0, off*sizeof(unsigned long)); | 179 | memset(dst, 0, off*sizeof(unsigned long)); |
| @@ -377,45 +370,6 @@ EXPORT_SYMBOL(bitmap_find_next_zero_area_off); | |||
| 377 | #define BASEDEC 10 /* fancier cpuset lists input in decimal */ | 370 | #define BASEDEC 10 /* fancier cpuset lists input in decimal */ |
| 378 | 371 | ||
| 379 | /** | 372 | /** |
| 380 | * bitmap_scnprintf - convert bitmap to an ASCII hex string. | ||
| 381 | * @buf: byte buffer into which string is placed | ||
| 382 | * @buflen: reserved size of @buf, in bytes | ||
| 383 | * @maskp: pointer to bitmap to convert | ||
| 384 | * @nmaskbits: size of bitmap, in bits | ||
| 385 | * | ||
| 386 | * Exactly @nmaskbits bits are displayed. Hex digits are grouped into | ||
| 387 | * comma-separated sets of eight digits per set. Returns the number of | ||
| 388 | * characters which were written to *buf, excluding the trailing \0. | ||
| 389 | */ | ||
| 390 | int bitmap_scnprintf(char *buf, unsigned int buflen, | ||
| 391 | const unsigned long *maskp, int nmaskbits) | ||
| 392 | { | ||
| 393 | int i, word, bit, len = 0; | ||
| 394 | unsigned long val; | ||
| 395 | const char *sep = ""; | ||
| 396 | int chunksz; | ||
| 397 | u32 chunkmask; | ||
| 398 | |||
| 399 | chunksz = nmaskbits & (CHUNKSZ - 1); | ||
| 400 | if (chunksz == 0) | ||
| 401 | chunksz = CHUNKSZ; | ||
| 402 | |||
| 403 | i = ALIGN(nmaskbits, CHUNKSZ) - CHUNKSZ; | ||
| 404 | for (; i >= 0; i -= CHUNKSZ) { | ||
| 405 | chunkmask = ((1ULL << chunksz) - 1); | ||
| 406 | word = i / BITS_PER_LONG; | ||
| 407 | bit = i % BITS_PER_LONG; | ||
| 408 | val = (maskp[word] >> bit) & chunkmask; | ||
| 409 | len += scnprintf(buf+len, buflen-len, "%s%0*lx", sep, | ||
| 410 | (chunksz+3)/4, val); | ||
| 411 | chunksz = CHUNKSZ; | ||
| 412 | sep = ","; | ||
| 413 | } | ||
| 414 | return len; | ||
| 415 | } | ||
| 416 | EXPORT_SYMBOL(bitmap_scnprintf); | ||
| 417 | |||
| 418 | /** | ||
| 419 | * __bitmap_parse - convert an ASCII hex string into a bitmap. | 373 | * __bitmap_parse - convert an ASCII hex string into a bitmap. |
| 420 | * @buf: pointer to buffer containing string. | 374 | * @buf: pointer to buffer containing string. |
| 421 | * @buflen: buffer size in bytes. If string is smaller than this | 375 | * @buflen: buffer size in bytes. If string is smaller than this |
| @@ -528,65 +482,6 @@ int bitmap_parse_user(const char __user *ubuf, | |||
| 528 | } | 482 | } |
| 529 | EXPORT_SYMBOL(bitmap_parse_user); | 483 | EXPORT_SYMBOL(bitmap_parse_user); |
| 530 | 484 | ||
| 531 | /* | ||
| 532 | * bscnl_emit(buf, buflen, rbot, rtop, bp) | ||
| 533 | * | ||
| 534 | * Helper routine for bitmap_scnlistprintf(). Write decimal number | ||
| 535 | * or range to buf, suppressing output past buf+buflen, with optional | ||
| 536 | * comma-prefix. Return len of what was written to *buf, excluding the | ||
| 537 | * trailing \0. | ||
| 538 | */ | ||
| 539 | static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len) | ||
| 540 | { | ||
| 541 | if (len > 0) | ||
| 542 | len += scnprintf(buf + len, buflen - len, ","); | ||
| 543 | if (rbot == rtop) | ||
| 544 | len += scnprintf(buf + len, buflen - len, "%d", rbot); | ||
| 545 | else | ||
| 546 | len += scnprintf(buf + len, buflen - len, "%d-%d", rbot, rtop); | ||
| 547 | return len; | ||
| 548 | } | ||
| 549 | |||
| 550 | /** | ||
| 551 | * bitmap_scnlistprintf - convert bitmap to list format ASCII string | ||
| 552 | * @buf: byte buffer into which string is placed | ||
| 553 | * @buflen: reserved size of @buf, in bytes | ||
| 554 | * @maskp: pointer to bitmap to convert | ||
| 555 | * @nmaskbits: size of bitmap, in bits | ||
| 556 | * | ||
| 557 | * Output format is a comma-separated list of decimal numbers and | ||
| 558 | * ranges. Consecutively set bits are shown as two hyphen-separated | ||
| 559 | * decimal numbers, the smallest and largest bit numbers set in | ||
| 560 | * the range. Output format is compatible with the format | ||
| 561 | * accepted as input by bitmap_parselist(). | ||
| 562 | * | ||
| 563 | * The return value is the number of characters which were written to *buf | ||
| 564 | * excluding the trailing '\0', as per ISO C99's scnprintf. | ||
| 565 | */ | ||
| 566 | int bitmap_scnlistprintf(char *buf, unsigned int buflen, | ||
| 567 | const unsigned long *maskp, int nmaskbits) | ||
| 568 | { | ||
| 569 | int len = 0; | ||
| 570 | /* current bit is 'cur', most recently seen range is [rbot, rtop] */ | ||
| 571 | int cur, rbot, rtop; | ||
| 572 | |||
| 573 | if (buflen == 0) | ||
| 574 | return 0; | ||
| 575 | buf[0] = 0; | ||
| 576 | |||
| 577 | rbot = cur = find_first_bit(maskp, nmaskbits); | ||
| 578 | while (cur < nmaskbits) { | ||
| 579 | rtop = cur; | ||
| 580 | cur = find_next_bit(maskp, nmaskbits, cur+1); | ||
| 581 | if (cur >= nmaskbits || cur > rtop + 1) { | ||
| 582 | len = bscnl_emit(buf, buflen, rbot, rtop, len); | ||
| 583 | rbot = cur; | ||
| 584 | } | ||
| 585 | } | ||
| 586 | return len; | ||
| 587 | } | ||
| 588 | EXPORT_SYMBOL(bitmap_scnlistprintf); | ||
| 589 | |||
| 590 | /** | 485 | /** |
| 591 | * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string | 486 | * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string |
| 592 | * @list: indicates whether the bitmap must be list | 487 | * @list: indicates whether the bitmap must be list |
| @@ -605,8 +500,8 @@ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, | |||
| 605 | int n = 0; | 500 | int n = 0; |
| 606 | 501 | ||
| 607 | if (len > 1) { | 502 | if (len > 1) { |
| 608 | n = list ? bitmap_scnlistprintf(buf, len, maskp, nmaskbits) : | 503 | n = list ? scnprintf(buf, len, "%*pbl", nmaskbits, maskp) : |
| 609 | bitmap_scnprintf(buf, len, maskp, nmaskbits); | 504 | scnprintf(buf, len, "%*pb", nmaskbits, maskp); |
| 610 | buf[n++] = '\n'; | 505 | buf[n++] = '\n'; |
| 611 | buf[n] = '\0'; | 506 | buf[n] = '\0'; |
| 612 | } | 507 | } |
| @@ -1191,16 +1086,17 @@ EXPORT_SYMBOL(bitmap_allocate_region); | |||
| 1191 | * | 1086 | * |
| 1192 | * Require nbits % BITS_PER_LONG == 0. | 1087 | * Require nbits % BITS_PER_LONG == 0. |
| 1193 | */ | 1088 | */ |
| 1194 | void bitmap_copy_le(void *dst, const unsigned long *src, int nbits) | 1089 | #ifdef __BIG_ENDIAN |
| 1090 | void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits) | ||
| 1195 | { | 1091 | { |
| 1196 | unsigned long *d = dst; | 1092 | unsigned int i; |
| 1197 | int i; | ||
| 1198 | 1093 | ||
| 1199 | for (i = 0; i < nbits/BITS_PER_LONG; i++) { | 1094 | for (i = 0; i < nbits/BITS_PER_LONG; i++) { |
| 1200 | if (BITS_PER_LONG == 64) | 1095 | if (BITS_PER_LONG == 64) |
| 1201 | d[i] = cpu_to_le64(src[i]); | 1096 | dst[i] = cpu_to_le64(src[i]); |
| 1202 | else | 1097 | else |
| 1203 | d[i] = cpu_to_le32(src[i]); | 1098 | dst[i] = cpu_to_le32(src[i]); |
| 1204 | } | 1099 | } |
| 1205 | } | 1100 | } |
| 1206 | EXPORT_SYMBOL(bitmap_copy_le); | 1101 | EXPORT_SYMBOL(bitmap_copy_le); |
| 1102 | #endif | ||
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c index 71fcfcd96410..d83a372fa76f 100644 --- a/lib/gen_crc32table.c +++ b/lib/gen_crc32table.c | |||
| @@ -109,7 +109,7 @@ int main(int argc, char** argv) | |||
| 109 | 109 | ||
| 110 | if (CRC_LE_BITS > 1) { | 110 | if (CRC_LE_BITS > 1) { |
| 111 | crc32init_le(); | 111 | crc32init_le(); |
| 112 | printf("static u32 __cacheline_aligned " | 112 | printf("static const u32 ____cacheline_aligned " |
| 113 | "crc32table_le[%d][%d] = {", | 113 | "crc32table_le[%d][%d] = {", |
| 114 | LE_TABLE_ROWS, LE_TABLE_SIZE); | 114 | LE_TABLE_ROWS, LE_TABLE_SIZE); |
| 115 | output_table(crc32table_le, LE_TABLE_ROWS, | 115 | output_table(crc32table_le, LE_TABLE_ROWS, |
| @@ -119,7 +119,7 @@ int main(int argc, char** argv) | |||
| 119 | 119 | ||
| 120 | if (CRC_BE_BITS > 1) { | 120 | if (CRC_BE_BITS > 1) { |
| 121 | crc32init_be(); | 121 | crc32init_be(); |
| 122 | printf("static u32 __cacheline_aligned " | 122 | printf("static const u32 ____cacheline_aligned " |
| 123 | "crc32table_be[%d][%d] = {", | 123 | "crc32table_be[%d][%d] = {", |
| 124 | BE_TABLE_ROWS, BE_TABLE_SIZE); | 124 | BE_TABLE_ROWS, BE_TABLE_SIZE); |
| 125 | output_table(crc32table_be, LE_TABLE_ROWS, | 125 | output_table(crc32table_be, LE_TABLE_ROWS, |
| @@ -128,7 +128,7 @@ int main(int argc, char** argv) | |||
| 128 | } | 128 | } |
| 129 | if (CRC_LE_BITS > 1) { | 129 | if (CRC_LE_BITS > 1) { |
| 130 | crc32cinit_le(); | 130 | crc32cinit_le(); |
| 131 | printf("static u32 __cacheline_aligned " | 131 | printf("static const u32 ____cacheline_aligned " |
| 132 | "crc32ctable_le[%d][%d] = {", | 132 | "crc32ctable_le[%d][%d] = {", |
| 133 | LE_TABLE_ROWS, LE_TABLE_SIZE); | 133 | LE_TABLE_ROWS, LE_TABLE_SIZE); |
| 134 | output_table(crc32ctable_le, LE_TABLE_ROWS, | 134 | output_table(crc32ctable_le, LE_TABLE_ROWS, |
diff --git a/lib/genalloc.c b/lib/genalloc.c index 0fe1cbe87700..d214866eeea2 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
| @@ -586,6 +586,8 @@ struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order, | |||
| 586 | struct gen_pool **ptr, *pool; | 586 | struct gen_pool **ptr, *pool; |
| 587 | 587 | ||
| 588 | ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL); | 588 | ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL); |
| 589 | if (!ptr) | ||
| 590 | return NULL; | ||
| 589 | 591 | ||
| 590 | pool = gen_pool_create(min_alloc_order, nid); | 592 | pool = gen_pool_create(min_alloc_order, nid); |
| 591 | if (pool) { | 593 | if (pool) { |
diff --git a/lib/seq_buf.c b/lib/seq_buf.c index 4eedfedb9e31..88c0854bd752 100644 --- a/lib/seq_buf.c +++ b/lib/seq_buf.c | |||
| @@ -91,42 +91,6 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...) | |||
| 91 | return ret; | 91 | return ret; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | /** | ||
| 95 | * seq_buf_bitmask - write a bitmask array in its ASCII representation | ||
| 96 | * @s: seq_buf descriptor | ||
| 97 | * @maskp: points to an array of unsigned longs that represent a bitmask | ||
| 98 | * @nmaskbits: The number of bits that are valid in @maskp | ||
| 99 | * | ||
| 100 | * Writes a ASCII representation of a bitmask string into @s. | ||
| 101 | * | ||
| 102 | * Returns zero on success, -1 on overflow. | ||
| 103 | */ | ||
| 104 | int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp, | ||
| 105 | int nmaskbits) | ||
| 106 | { | ||
| 107 | unsigned int len = seq_buf_buffer_left(s); | ||
| 108 | int ret; | ||
| 109 | |||
| 110 | WARN_ON(s->size == 0); | ||
| 111 | |||
| 112 | /* | ||
| 113 | * Note, because bitmap_scnprintf() only returns the number of bytes | ||
| 114 | * written and not the number that would be written, we use the last | ||
| 115 | * byte of the buffer to let us know if we overflowed. There's a small | ||
| 116 | * chance that the bitmap could have fit exactly inside the buffer, but | ||
| 117 | * it's not that critical if that does happen. | ||
| 118 | */ | ||
| 119 | if (len > 1) { | ||
| 120 | ret = bitmap_scnprintf(s->buffer + s->len, len, maskp, nmaskbits); | ||
| 121 | if (ret < len) { | ||
| 122 | s->len += ret; | ||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | seq_buf_set_overflow(s); | ||
| 127 | return -1; | ||
| 128 | } | ||
| 129 | |||
| 130 | #ifdef CONFIG_BINARY_PRINTF | 94 | #ifdef CONFIG_BINARY_PRINTF |
| 131 | /** | 95 | /** |
| 132 | * seq_buf_bprintf - Write the printf string from binary arguments | 96 | * seq_buf_bprintf - Write the printf string from binary arguments |
diff --git a/lib/string.c b/lib/string.c index 3206d0178296..cdd97f431ae2 100644 --- a/lib/string.c +++ b/lib/string.c | |||
| @@ -313,12 +313,12 @@ EXPORT_SYMBOL(strchrnul); | |||
| 313 | */ | 313 | */ |
| 314 | char *strrchr(const char *s, int c) | 314 | char *strrchr(const char *s, int c) |
| 315 | { | 315 | { |
| 316 | const char *p = s + strlen(s); | 316 | const char *last = NULL; |
| 317 | do { | 317 | do { |
| 318 | if (*p == (char)c) | 318 | if (*s == (char)c) |
| 319 | return (char *)p; | 319 | last = s; |
| 320 | } while (--p >= s); | 320 | } while (*s++); |
| 321 | return NULL; | 321 | return (char *)last; |
| 322 | } | 322 | } |
| 323 | EXPORT_SYMBOL(strrchr); | 323 | EXPORT_SYMBOL(strrchr); |
| 324 | #endif | 324 | #endif |
diff --git a/lib/test_kasan.c b/lib/test_kasan.c new file mode 100644 index 000000000000..098c08eddfab --- /dev/null +++ b/lib/test_kasan.c | |||
| @@ -0,0 +1,277 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 4 | * Author: Andrey Ryabinin <a.ryabinin@samsung.com> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | */ | ||
| 11 | |||
| 12 | #define pr_fmt(fmt) "kasan test: %s " fmt, __func__ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/printk.h> | ||
| 16 | #include <linux/slab.h> | ||
| 17 | #include <linux/string.h> | ||
| 18 | #include <linux/module.h> | ||
| 19 | |||
| 20 | static noinline void __init kmalloc_oob_right(void) | ||
| 21 | { | ||
| 22 | char *ptr; | ||
| 23 | size_t size = 123; | ||
| 24 | |||
| 25 | pr_info("out-of-bounds to right\n"); | ||
| 26 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 27 | if (!ptr) { | ||
| 28 | pr_err("Allocation failed\n"); | ||
| 29 | return; | ||
| 30 | } | ||
| 31 | |||
| 32 | ptr[size] = 'x'; | ||
| 33 | kfree(ptr); | ||
| 34 | } | ||
| 35 | |||
| 36 | static noinline void __init kmalloc_oob_left(void) | ||
| 37 | { | ||
| 38 | char *ptr; | ||
| 39 | size_t size = 15; | ||
| 40 | |||
| 41 | pr_info("out-of-bounds to left\n"); | ||
| 42 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 43 | if (!ptr) { | ||
| 44 | pr_err("Allocation failed\n"); | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | |||
| 48 | *ptr = *(ptr - 1); | ||
| 49 | kfree(ptr); | ||
| 50 | } | ||
| 51 | |||
| 52 | static noinline void __init kmalloc_node_oob_right(void) | ||
| 53 | { | ||
| 54 | char *ptr; | ||
| 55 | size_t size = 4096; | ||
| 56 | |||
| 57 | pr_info("kmalloc_node(): out-of-bounds to right\n"); | ||
| 58 | ptr = kmalloc_node(size, GFP_KERNEL, 0); | ||
| 59 | if (!ptr) { | ||
| 60 | pr_err("Allocation failed\n"); | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | ptr[size] = 0; | ||
| 65 | kfree(ptr); | ||
| 66 | } | ||
| 67 | |||
| 68 | static noinline void __init kmalloc_large_oob_rigth(void) | ||
| 69 | { | ||
| 70 | char *ptr; | ||
| 71 | size_t size = KMALLOC_MAX_CACHE_SIZE + 10; | ||
| 72 | |||
| 73 | pr_info("kmalloc large allocation: out-of-bounds to right\n"); | ||
| 74 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 75 | if (!ptr) { | ||
| 76 | pr_err("Allocation failed\n"); | ||
| 77 | return; | ||
| 78 | } | ||
| 79 | |||
| 80 | ptr[size] = 0; | ||
| 81 | kfree(ptr); | ||
| 82 | } | ||
| 83 | |||
| 84 | static noinline void __init kmalloc_oob_krealloc_more(void) | ||
| 85 | { | ||
| 86 | char *ptr1, *ptr2; | ||
| 87 | size_t size1 = 17; | ||
| 88 | size_t size2 = 19; | ||
| 89 | |||
| 90 | pr_info("out-of-bounds after krealloc more\n"); | ||
| 91 | ptr1 = kmalloc(size1, GFP_KERNEL); | ||
| 92 | ptr2 = krealloc(ptr1, size2, GFP_KERNEL); | ||
| 93 | if (!ptr1 || !ptr2) { | ||
| 94 | pr_err("Allocation failed\n"); | ||
| 95 | kfree(ptr1); | ||
| 96 | return; | ||
| 97 | } | ||
| 98 | |||
| 99 | ptr2[size2] = 'x'; | ||
| 100 | kfree(ptr2); | ||
| 101 | } | ||
| 102 | |||
| 103 | static noinline void __init kmalloc_oob_krealloc_less(void) | ||
| 104 | { | ||
| 105 | char *ptr1, *ptr2; | ||
| 106 | size_t size1 = 17; | ||
| 107 | size_t size2 = 15; | ||
| 108 | |||
| 109 | pr_info("out-of-bounds after krealloc less\n"); | ||
| 110 | ptr1 = kmalloc(size1, GFP_KERNEL); | ||
| 111 | ptr2 = krealloc(ptr1, size2, GFP_KERNEL); | ||
| 112 | if (!ptr1 || !ptr2) { | ||
| 113 | pr_err("Allocation failed\n"); | ||
| 114 | kfree(ptr1); | ||
| 115 | return; | ||
| 116 | } | ||
| 117 | ptr2[size1] = 'x'; | ||
| 118 | kfree(ptr2); | ||
| 119 | } | ||
| 120 | |||
| 121 | static noinline void __init kmalloc_oob_16(void) | ||
| 122 | { | ||
| 123 | struct { | ||
| 124 | u64 words[2]; | ||
| 125 | } *ptr1, *ptr2; | ||
| 126 | |||
| 127 | pr_info("kmalloc out-of-bounds for 16-bytes access\n"); | ||
| 128 | ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL); | ||
| 129 | ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL); | ||
| 130 | if (!ptr1 || !ptr2) { | ||
| 131 | pr_err("Allocation failed\n"); | ||
| 132 | kfree(ptr1); | ||
| 133 | kfree(ptr2); | ||
| 134 | return; | ||
| 135 | } | ||
| 136 | *ptr1 = *ptr2; | ||
| 137 | kfree(ptr1); | ||
| 138 | kfree(ptr2); | ||
| 139 | } | ||
| 140 | |||
| 141 | static noinline void __init kmalloc_oob_in_memset(void) | ||
| 142 | { | ||
| 143 | char *ptr; | ||
| 144 | size_t size = 666; | ||
| 145 | |||
| 146 | pr_info("out-of-bounds in memset\n"); | ||
| 147 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 148 | if (!ptr) { | ||
| 149 | pr_err("Allocation failed\n"); | ||
| 150 | return; | ||
| 151 | } | ||
| 152 | |||
| 153 | memset(ptr, 0, size+5); | ||
| 154 | kfree(ptr); | ||
| 155 | } | ||
| 156 | |||
| 157 | static noinline void __init kmalloc_uaf(void) | ||
| 158 | { | ||
| 159 | char *ptr; | ||
| 160 | size_t size = 10; | ||
| 161 | |||
| 162 | pr_info("use-after-free\n"); | ||
| 163 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 164 | if (!ptr) { | ||
| 165 | pr_err("Allocation failed\n"); | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 169 | kfree(ptr); | ||
| 170 | *(ptr + 8) = 'x'; | ||
| 171 | } | ||
| 172 | |||
| 173 | static noinline void __init kmalloc_uaf_memset(void) | ||
| 174 | { | ||
| 175 | char *ptr; | ||
| 176 | size_t size = 33; | ||
| 177 | |||
| 178 | pr_info("use-after-free in memset\n"); | ||
| 179 | ptr = kmalloc(size, GFP_KERNEL); | ||
| 180 | if (!ptr) { | ||
| 181 | pr_err("Allocation failed\n"); | ||
| 182 | return; | ||
| 183 | } | ||
| 184 | |||
| 185 | kfree(ptr); | ||
| 186 | memset(ptr, 0, size); | ||
| 187 | } | ||
| 188 | |||
| 189 | static noinline void __init kmalloc_uaf2(void) | ||
| 190 | { | ||
| 191 | char *ptr1, *ptr2; | ||
| 192 | size_t size = 43; | ||
| 193 | |||
| 194 | pr_info("use-after-free after another kmalloc\n"); | ||
| 195 | ptr1 = kmalloc(size, GFP_KERNEL); | ||
| 196 | if (!ptr1) { | ||
| 197 | pr_err("Allocation failed\n"); | ||
| 198 | return; | ||
| 199 | } | ||
| 200 | |||
| 201 | kfree(ptr1); | ||
| 202 | ptr2 = kmalloc(size, GFP_KERNEL); | ||
| 203 | if (!ptr2) { | ||
| 204 | pr_err("Allocation failed\n"); | ||
| 205 | return; | ||
| 206 | } | ||
| 207 | |||
| 208 | ptr1[40] = 'x'; | ||
| 209 | kfree(ptr2); | ||
| 210 | } | ||
| 211 | |||
| 212 | static noinline void __init kmem_cache_oob(void) | ||
| 213 | { | ||
| 214 | char *p; | ||
| 215 | size_t size = 200; | ||
| 216 | struct kmem_cache *cache = kmem_cache_create("test_cache", | ||
| 217 | size, 0, | ||
| 218 | 0, NULL); | ||
| 219 | if (!cache) { | ||
| 220 | pr_err("Cache allocation failed\n"); | ||
| 221 | return; | ||
| 222 | } | ||
| 223 | pr_info("out-of-bounds in kmem_cache_alloc\n"); | ||
| 224 | p = kmem_cache_alloc(cache, GFP_KERNEL); | ||
| 225 | if (!p) { | ||
| 226 | pr_err("Allocation failed\n"); | ||
| 227 | kmem_cache_destroy(cache); | ||
| 228 | return; | ||
| 229 | } | ||
| 230 | |||
| 231 | *p = p[size]; | ||
| 232 | kmem_cache_free(cache, p); | ||
| 233 | kmem_cache_destroy(cache); | ||
| 234 | } | ||
| 235 | |||
| 236 | static char global_array[10]; | ||
| 237 | |||
| 238 | static noinline void __init kasan_global_oob(void) | ||
| 239 | { | ||
| 240 | volatile int i = 3; | ||
| 241 | char *p = &global_array[ARRAY_SIZE(global_array) + i]; | ||
| 242 | |||
| 243 | pr_info("out-of-bounds global variable\n"); | ||
| 244 | *(volatile char *)p; | ||
| 245 | } | ||
| 246 | |||
| 247 | static noinline void __init kasan_stack_oob(void) | ||
| 248 | { | ||
| 249 | char stack_array[10]; | ||
| 250 | volatile int i = 0; | ||
| 251 | char *p = &stack_array[ARRAY_SIZE(stack_array) + i]; | ||
| 252 | |||
| 253 | pr_info("out-of-bounds on stack\n"); | ||
| 254 | *(volatile char *)p; | ||
| 255 | } | ||
| 256 | |||
| 257 | static int __init kmalloc_tests_init(void) | ||
| 258 | { | ||
| 259 | kmalloc_oob_right(); | ||
| 260 | kmalloc_oob_left(); | ||
| 261 | kmalloc_node_oob_right(); | ||
| 262 | kmalloc_large_oob_rigth(); | ||
| 263 | kmalloc_oob_krealloc_more(); | ||
| 264 | kmalloc_oob_krealloc_less(); | ||
| 265 | kmalloc_oob_16(); | ||
| 266 | kmalloc_oob_in_memset(); | ||
| 267 | kmalloc_uaf(); | ||
| 268 | kmalloc_uaf_memset(); | ||
| 269 | kmalloc_uaf2(); | ||
| 270 | kmem_cache_oob(); | ||
| 271 | kasan_stack_oob(); | ||
| 272 | kasan_global_oob(); | ||
| 273 | return -EAGAIN; | ||
| 274 | } | ||
| 275 | |||
| 276 | module_init(kmalloc_tests_init); | ||
| 277 | MODULE_LICENSE("GPL"); | ||
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 602d2081e713..b235c96167d3 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
| @@ -794,6 +794,87 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec, | |||
| 794 | } | 794 | } |
| 795 | 795 | ||
| 796 | static noinline_for_stack | 796 | static noinline_for_stack |
| 797 | char *bitmap_string(char *buf, char *end, unsigned long *bitmap, | ||
| 798 | struct printf_spec spec, const char *fmt) | ||
| 799 | { | ||
| 800 | const int CHUNKSZ = 32; | ||
| 801 | int nr_bits = max_t(int, spec.field_width, 0); | ||
| 802 | int i, chunksz; | ||
| 803 | bool first = true; | ||
| 804 | |||
| 805 | /* reused to print numbers */ | ||
| 806 | spec = (struct printf_spec){ .flags = SMALL | ZEROPAD, .base = 16 }; | ||
| 807 | |||
| 808 | chunksz = nr_bits & (CHUNKSZ - 1); | ||
| 809 | if (chunksz == 0) | ||
| 810 | chunksz = CHUNKSZ; | ||
| 811 | |||
| 812 | i = ALIGN(nr_bits, CHUNKSZ) - CHUNKSZ; | ||
| 813 | for (; i >= 0; i -= CHUNKSZ) { | ||
| 814 | u32 chunkmask, val; | ||
| 815 | int word, bit; | ||
| 816 | |||
| 817 | chunkmask = ((1ULL << chunksz) - 1); | ||
| 818 | word = i / BITS_PER_LONG; | ||
| 819 | bit = i % BITS_PER_LONG; | ||
| 820 | val = (bitmap[word] >> bit) & chunkmask; | ||
| 821 | |||
| 822 | if (!first) { | ||
| 823 | if (buf < end) | ||
| 824 | *buf = ','; | ||
| 825 | buf++; | ||
| 826 | } | ||
| 827 | first = false; | ||
| 828 | |||
| 829 | spec.field_width = DIV_ROUND_UP(chunksz, 4); | ||
| 830 | buf = number(buf, end, val, spec); | ||
| 831 | |||
| 832 | chunksz = CHUNKSZ; | ||
| 833 | } | ||
| 834 | return buf; | ||
| 835 | } | ||
| 836 | |||
| 837 | static noinline_for_stack | ||
| 838 | char *bitmap_list_string(char *buf, char *end, unsigned long *bitmap, | ||
| 839 | struct printf_spec spec, const char *fmt) | ||
| 840 | { | ||
| 841 | int nr_bits = max_t(int, spec.field_width, 0); | ||
| 842 | /* current bit is 'cur', most recently seen range is [rbot, rtop] */ | ||
| 843 | int cur, rbot, rtop; | ||
| 844 | bool first = true; | ||
| 845 | |||
| 846 | /* reused to print numbers */ | ||
| 847 | spec = (struct printf_spec){ .base = 10 }; | ||
| 848 | |||
| 849 | rbot = cur = find_first_bit(bitmap, nr_bits); | ||
| 850 | while (cur < nr_bits) { | ||
| 851 | rtop = cur; | ||
| 852 | cur = find_next_bit(bitmap, nr_bits, cur + 1); | ||
| 853 | if (cur < nr_bits && cur <= rtop + 1) | ||
| 854 | continue; | ||
| 855 | |||
| 856 | if (!first) { | ||
| 857 | if (buf < end) | ||
| 858 | *buf = ','; | ||
| 859 | buf++; | ||
| 860 | } | ||
| 861 | first = false; | ||
| 862 | |||
| 863 | buf = number(buf, end, rbot, spec); | ||
| 864 | if (rbot < rtop) { | ||
| 865 | if (buf < end) | ||
| 866 | *buf = '-'; | ||
| 867 | buf++; | ||
| 868 | |||
| 869 | buf = number(buf, end, rtop, spec); | ||
| 870 | } | ||
| 871 | |||
| 872 | rbot = cur; | ||
| 873 | } | ||
| 874 | return buf; | ||
| 875 | } | ||
| 876 | |||
| 877 | static noinline_for_stack | ||
| 797 | char *mac_address_string(char *buf, char *end, u8 *addr, | 878 | char *mac_address_string(char *buf, char *end, u8 *addr, |
| 798 | struct printf_spec spec, const char *fmt) | 879 | struct printf_spec spec, const char *fmt) |
| 799 | { | 880 | { |
| @@ -1258,6 +1339,10 @@ int kptr_restrict __read_mostly; | |||
| 1258 | * - 'B' For backtraced symbolic direct pointers with offset | 1339 | * - 'B' For backtraced symbolic direct pointers with offset |
| 1259 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] | 1340 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] |
| 1260 | * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] | 1341 | * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] |
| 1342 | * - 'b[l]' For a bitmap, the number of bits is determined by the field | ||
| 1343 | * width which must be explicitly specified either as part of the | ||
| 1344 | * format string '%32b[l]' or through '%*b[l]', [l] selects | ||
| 1345 | * range-list format instead of hex format | ||
| 1261 | * - 'M' For a 6-byte MAC address, it prints the address in the | 1346 | * - 'M' For a 6-byte MAC address, it prints the address in the |
| 1262 | * usual colon-separated hex notation | 1347 | * usual colon-separated hex notation |
| 1263 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons | 1348 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons |
| @@ -1354,6 +1439,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
| 1354 | return resource_string(buf, end, ptr, spec, fmt); | 1439 | return resource_string(buf, end, ptr, spec, fmt); |
| 1355 | case 'h': | 1440 | case 'h': |
| 1356 | return hex_string(buf, end, ptr, spec, fmt); | 1441 | return hex_string(buf, end, ptr, spec, fmt); |
| 1442 | case 'b': | ||
| 1443 | switch (fmt[1]) { | ||
| 1444 | case 'l': | ||
| 1445 | return bitmap_list_string(buf, end, ptr, spec, fmt); | ||
| 1446 | default: | ||
| 1447 | return bitmap_string(buf, end, ptr, spec, fmt); | ||
| 1448 | } | ||
| 1357 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ | 1449 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ |
| 1358 | case 'm': /* Contiguous: 000102030405 */ | 1450 | case 'm': /* Contiguous: 000102030405 */ |
| 1359 | /* [mM]F (FDDI) */ | 1451 | /* [mM]F (FDDI) */ |
| @@ -1689,6 +1781,8 @@ qualifier: | |||
| 1689 | * %pB output the name of a backtrace symbol with its offset | 1781 | * %pB output the name of a backtrace symbol with its offset |
| 1690 | * %pR output the address range in a struct resource with decoded flags | 1782 | * %pR output the address range in a struct resource with decoded flags |
| 1691 | * %pr output the address range in a struct resource with raw flags | 1783 | * %pr output the address range in a struct resource with raw flags |
| 1784 | * %pb output the bitmap with field width as the number of bits | ||
| 1785 | * %pbl output the bitmap as range list with field width as the number of bits | ||
| 1692 | * %pM output a 6-byte MAC address with colons | 1786 | * %pM output a 6-byte MAC address with colons |
| 1693 | * %pMR output a 6-byte MAC address with colons in reversed order | 1787 | * %pMR output a 6-byte MAC address with colons in reversed order |
| 1694 | * %pMF output a 6-byte MAC address with dashes | 1788 | * %pMF output a 6-byte MAC address with dashes |
diff --git a/mm/Makefile b/mm/Makefile index 3548460ab7b6..088c68e9ec35 100644 --- a/mm/Makefile +++ b/mm/Makefile | |||
| @@ -2,6 +2,9 @@ | |||
| 2 | # Makefile for the linux memory manager. | 2 | # Makefile for the linux memory manager. |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | KASAN_SANITIZE_slab_common.o := n | ||
| 6 | KASAN_SANITIZE_slub.o := n | ||
| 7 | |||
| 5 | mmu-y := nommu.o | 8 | mmu-y := nommu.o |
| 6 | mmu-$(CONFIG_MMU) := gup.o highmem.o memory.o mincore.o \ | 9 | mmu-$(CONFIG_MMU) := gup.o highmem.o memory.o mincore.o \ |
| 7 | mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \ | 10 | mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \ |
| @@ -49,6 +52,7 @@ obj-$(CONFIG_PAGE_POISONING) += debug-pagealloc.o | |||
| 49 | obj-$(CONFIG_SLAB) += slab.o | 52 | obj-$(CONFIG_SLAB) += slab.o |
| 50 | obj-$(CONFIG_SLUB) += slub.o | 53 | obj-$(CONFIG_SLUB) += slub.o |
| 51 | obj-$(CONFIG_KMEMCHECK) += kmemcheck.o | 54 | obj-$(CONFIG_KMEMCHECK) += kmemcheck.o |
| 55 | obj-$(CONFIG_KASAN) += kasan/ | ||
| 52 | obj-$(CONFIG_FAILSLAB) += failslab.o | 56 | obj-$(CONFIG_FAILSLAB) += failslab.o |
| 53 | obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o | 57 | obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o |
| 54 | obj-$(CONFIG_FS_XIP) += filemap_xip.o | 58 | obj-$(CONFIG_FS_XIP) += filemap_xip.o |
diff --git a/mm/compaction.c b/mm/compaction.c index d50d6de6f1b6..8c0d9459b54a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/sysfs.h> | 16 | #include <linux/sysfs.h> |
| 17 | #include <linux/balloon_compaction.h> | 17 | #include <linux/balloon_compaction.h> |
| 18 | #include <linux/page-isolation.h> | 18 | #include <linux/page-isolation.h> |
| 19 | #include <linux/kasan.h> | ||
| 19 | #include "internal.h" | 20 | #include "internal.h" |
| 20 | 21 | ||
| 21 | #ifdef CONFIG_COMPACTION | 22 | #ifdef CONFIG_COMPACTION |
| @@ -72,6 +73,7 @@ static void map_pages(struct list_head *list) | |||
| 72 | list_for_each_entry(page, list, lru) { | 73 | list_for_each_entry(page, list, lru) { |
| 73 | arch_alloc_page(page, 0); | 74 | arch_alloc_page(page, 0); |
| 74 | kernel_map_pages(page, 1, 1); | 75 | kernel_map_pages(page, 1, 1); |
| 76 | kasan_alloc_pages(page, 0); | ||
| 75 | } | 77 | } |
| 76 | } | 78 | } |
| 77 | 79 | ||
diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile new file mode 100644 index 000000000000..bd837b8c2f41 --- /dev/null +++ b/mm/kasan/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | KASAN_SANITIZE := n | ||
| 2 | |||
| 3 | CFLAGS_REMOVE_kasan.o = -pg | ||
| 4 | # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 | ||
| 5 | # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 | ||
| 6 | CFLAGS_kasan.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) | ||
| 7 | |||
| 8 | obj-y := kasan.o report.o | ||
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c new file mode 100644 index 000000000000..78fee632a7ee --- /dev/null +++ b/mm/kasan/kasan.c | |||
| @@ -0,0 +1,516 @@ | |||
| 1 | /* | ||
| 2 | * This file contains shadow memory manipulation code. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 5 | * Author: Andrey Ryabinin <a.ryabinin@samsung.com> | ||
| 6 | * | ||
| 7 | * Some of code borrowed from https://github.com/xairy/linux by | ||
| 8 | * Andrey Konovalov <adech.fo@gmail.com> | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License version 2 as | ||
| 12 | * published by the Free Software Foundation. | ||
| 13 | * | ||
| 14 | */ | ||
| 15 | |||
| 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 17 | #define DISABLE_BRANCH_PROFILING | ||
| 18 | |||
| 19 | #include <linux/export.h> | ||
| 20 | #include <linux/init.h> | ||
| 21 | #include <linux/kernel.h> | ||
| 22 | #include <linux/memblock.h> | ||
| 23 | #include <linux/memory.h> | ||
| 24 | #include <linux/mm.h> | ||
| 25 | #include <linux/module.h> | ||
| 26 | #include <linux/printk.h> | ||
| 27 | #include <linux/sched.h> | ||
| 28 | #include <linux/slab.h> | ||
| 29 | #include <linux/stacktrace.h> | ||
| 30 | #include <linux/string.h> | ||
| 31 | #include <linux/types.h> | ||
| 32 | #include <linux/kasan.h> | ||
| 33 | |||
| 34 | #include "kasan.h" | ||
| 35 | #include "../slab.h" | ||
| 36 | |||
| 37 | /* | ||
| 38 | * Poisons the shadow memory for 'size' bytes starting from 'addr'. | ||
| 39 | * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. | ||
| 40 | */ | ||
| 41 | static void kasan_poison_shadow(const void *address, size_t size, u8 value) | ||
| 42 | { | ||
| 43 | void *shadow_start, *shadow_end; | ||
| 44 | |||
| 45 | shadow_start = kasan_mem_to_shadow(address); | ||
| 46 | shadow_end = kasan_mem_to_shadow(address + size); | ||
| 47 | |||
| 48 | memset(shadow_start, value, shadow_end - shadow_start); | ||
| 49 | } | ||
| 50 | |||
| 51 | void kasan_unpoison_shadow(const void *address, size_t size) | ||
| 52 | { | ||
| 53 | kasan_poison_shadow(address, size, 0); | ||
| 54 | |||
| 55 | if (size & KASAN_SHADOW_MASK) { | ||
| 56 | u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); | ||
| 57 | *shadow = size & KASAN_SHADOW_MASK; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | /* | ||
| 63 | * All functions below always inlined so compiler could | ||
| 64 | * perform better optimizations in each of __asan_loadX/__assn_storeX | ||
| 65 | * depending on memory access size X. | ||
| 66 | */ | ||
| 67 | |||
| 68 | static __always_inline bool memory_is_poisoned_1(unsigned long addr) | ||
| 69 | { | ||
| 70 | s8 shadow_value = *(s8 *)kasan_mem_to_shadow((void *)addr); | ||
| 71 | |||
| 72 | if (unlikely(shadow_value)) { | ||
| 73 | s8 last_accessible_byte = addr & KASAN_SHADOW_MASK; | ||
| 74 | return unlikely(last_accessible_byte >= shadow_value); | ||
| 75 | } | ||
| 76 | |||
| 77 | return false; | ||
| 78 | } | ||
| 79 | |||
| 80 | static __always_inline bool memory_is_poisoned_2(unsigned long addr) | ||
| 81 | { | ||
| 82 | u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); | ||
| 83 | |||
| 84 | if (unlikely(*shadow_addr)) { | ||
| 85 | if (memory_is_poisoned_1(addr + 1)) | ||
| 86 | return true; | ||
| 87 | |||
| 88 | if (likely(((addr + 1) & KASAN_SHADOW_MASK) != 0)) | ||
| 89 | return false; | ||
| 90 | |||
| 91 | return unlikely(*(u8 *)shadow_addr); | ||
| 92 | } | ||
| 93 | |||
| 94 | return false; | ||
| 95 | } | ||
| 96 | |||
| 97 | static __always_inline bool memory_is_poisoned_4(unsigned long addr) | ||
| 98 | { | ||
| 99 | u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); | ||
| 100 | |||
| 101 | if (unlikely(*shadow_addr)) { | ||
| 102 | if (memory_is_poisoned_1(addr + 3)) | ||
| 103 | return true; | ||
| 104 | |||
| 105 | if (likely(((addr + 3) & KASAN_SHADOW_MASK) >= 3)) | ||
| 106 | return false; | ||
| 107 | |||
| 108 | return unlikely(*(u8 *)shadow_addr); | ||
| 109 | } | ||
| 110 | |||
| 111 | return false; | ||
| 112 | } | ||
| 113 | |||
| 114 | static __always_inline bool memory_is_poisoned_8(unsigned long addr) | ||
| 115 | { | ||
| 116 | u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); | ||
| 117 | |||
| 118 | if (unlikely(*shadow_addr)) { | ||
| 119 | if (memory_is_poisoned_1(addr + 7)) | ||
| 120 | return true; | ||
| 121 | |||
| 122 | if (likely(((addr + 7) & KASAN_SHADOW_MASK) >= 7)) | ||
| 123 | return false; | ||
| 124 | |||
| 125 | return unlikely(*(u8 *)shadow_addr); | ||
| 126 | } | ||
| 127 | |||
| 128 | return false; | ||
| 129 | } | ||
| 130 | |||
| 131 | static __always_inline bool memory_is_poisoned_16(unsigned long addr) | ||
| 132 | { | ||
| 133 | u32 *shadow_addr = (u32 *)kasan_mem_to_shadow((void *)addr); | ||
| 134 | |||
| 135 | if (unlikely(*shadow_addr)) { | ||
| 136 | u16 shadow_first_bytes = *(u16 *)shadow_addr; | ||
| 137 | s8 last_byte = (addr + 15) & KASAN_SHADOW_MASK; | ||
| 138 | |||
| 139 | if (unlikely(shadow_first_bytes)) | ||
| 140 | return true; | ||
| 141 | |||
| 142 | if (likely(!last_byte)) | ||
| 143 | return false; | ||
| 144 | |||
| 145 | return memory_is_poisoned_1(addr + 15); | ||
| 146 | } | ||
| 147 | |||
| 148 | return false; | ||
| 149 | } | ||
| 150 | |||
| 151 | static __always_inline unsigned long bytes_is_zero(const u8 *start, | ||
| 152 | size_t size) | ||
| 153 | { | ||
| 154 | while (size) { | ||
| 155 | if (unlikely(*start)) | ||
| 156 | return (unsigned long)start; | ||
| 157 | start++; | ||
| 158 | size--; | ||
| 159 | } | ||
| 160 | |||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | |||
| 164 | static __always_inline unsigned long memory_is_zero(const void *start, | ||
| 165 | const void *end) | ||
| 166 | { | ||
| 167 | unsigned int words; | ||
| 168 | unsigned long ret; | ||
| 169 | unsigned int prefix = (unsigned long)start % 8; | ||
| 170 | |||
| 171 | if (end - start <= 16) | ||
| 172 | return bytes_is_zero(start, end - start); | ||
| 173 | |||
| 174 | if (prefix) { | ||
| 175 | prefix = 8 - prefix; | ||
| 176 | ret = bytes_is_zero(start, prefix); | ||
| 177 | if (unlikely(ret)) | ||
| 178 | return ret; | ||
| 179 | start += prefix; | ||
| 180 | } | ||
| 181 | |||
| 182 | words = (end - start) / 8; | ||
| 183 | while (words) { | ||
| 184 | if (unlikely(*(u64 *)start)) | ||
| 185 | return bytes_is_zero(start, 8); | ||
| 186 | start += 8; | ||
| 187 | words--; | ||
| 188 | } | ||
| 189 | |||
| 190 | return bytes_is_zero(start, (end - start) % 8); | ||
| 191 | } | ||
| 192 | |||
| 193 | static __always_inline bool memory_is_poisoned_n(unsigned long addr, | ||
| 194 | size_t size) | ||
| 195 | { | ||
| 196 | unsigned long ret; | ||
| 197 | |||
| 198 | ret = memory_is_zero(kasan_mem_to_shadow((void *)addr), | ||
| 199 | kasan_mem_to_shadow((void *)addr + size - 1) + 1); | ||
| 200 | |||
| 201 | if (unlikely(ret)) { | ||
| 202 | unsigned long last_byte = addr + size - 1; | ||
| 203 | s8 *last_shadow = (s8 *)kasan_mem_to_shadow((void *)last_byte); | ||
| 204 | |||
| 205 | if (unlikely(ret != (unsigned long)last_shadow || | ||
| 206 | ((last_byte & KASAN_SHADOW_MASK) >= *last_shadow))) | ||
| 207 | return true; | ||
| 208 | } | ||
| 209 | return false; | ||
| 210 | } | ||
| 211 | |||
| 212 | static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) | ||
| 213 | { | ||
| 214 | if (__builtin_constant_p(size)) { | ||
| 215 | switch (size) { | ||
| 216 | case 1: | ||
| 217 | return memory_is_poisoned_1(addr); | ||
| 218 | case 2: | ||
| 219 | return memory_is_poisoned_2(addr); | ||
| 220 | case 4: | ||
| 221 | return memory_is_poisoned_4(addr); | ||
| 222 | case 8: | ||
| 223 | return memory_is_poisoned_8(addr); | ||
| 224 | case 16: | ||
| 225 | return memory_is_poisoned_16(addr); | ||
| 226 | default: | ||
| 227 | BUILD_BUG(); | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | return memory_is_poisoned_n(addr, size); | ||
| 232 | } | ||
| 233 | |||
| 234 | |||
| 235 | static __always_inline void check_memory_region(unsigned long addr, | ||
| 236 | size_t size, bool write) | ||
| 237 | { | ||
| 238 | struct kasan_access_info info; | ||
| 239 | |||
| 240 | if (unlikely(size == 0)) | ||
| 241 | return; | ||
| 242 | |||
| 243 | if (unlikely((void *)addr < | ||
| 244 | kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { | ||
| 245 | info.access_addr = (void *)addr; | ||
| 246 | info.access_size = size; | ||
| 247 | info.is_write = write; | ||
| 248 | info.ip = _RET_IP_; | ||
| 249 | kasan_report_user_access(&info); | ||
| 250 | return; | ||
| 251 | } | ||
| 252 | |||
| 253 | if (likely(!memory_is_poisoned(addr, size))) | ||
| 254 | return; | ||
| 255 | |||
| 256 | kasan_report(addr, size, write, _RET_IP_); | ||
| 257 | } | ||
| 258 | |||
| 259 | void __asan_loadN(unsigned long addr, size_t size); | ||
| 260 | void __asan_storeN(unsigned long addr, size_t size); | ||
| 261 | |||
| 262 | #undef memset | ||
| 263 | void *memset(void *addr, int c, size_t len) | ||
| 264 | { | ||
| 265 | __asan_storeN((unsigned long)addr, len); | ||
| 266 | |||
| 267 | return __memset(addr, c, len); | ||
| 268 | } | ||
| 269 | |||
| 270 | #undef memmove | ||
| 271 | void *memmove(void *dest, const void *src, size_t len) | ||
| 272 | { | ||
| 273 | __asan_loadN((unsigned long)src, len); | ||
| 274 | __asan_storeN((unsigned long)dest, len); | ||
| 275 | |||
| 276 | return __memmove(dest, src, len); | ||
| 277 | } | ||
| 278 | |||
| 279 | #undef memcpy | ||
| 280 | void *memcpy(void *dest, const void *src, size_t len) | ||
| 281 | { | ||
| 282 | __asan_loadN((unsigned long)src, len); | ||
| 283 | __asan_storeN((unsigned long)dest, len); | ||
| 284 | |||
| 285 | return __memcpy(dest, src, len); | ||
| 286 | } | ||
| 287 | |||
| 288 | void kasan_alloc_pages(struct page *page, unsigned int order) | ||
| 289 | { | ||
| 290 | if (likely(!PageHighMem(page))) | ||
| 291 | kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order); | ||
| 292 | } | ||
| 293 | |||
| 294 | void kasan_free_pages(struct page *page, unsigned int order) | ||
| 295 | { | ||
| 296 | if (likely(!PageHighMem(page))) | ||
| 297 | kasan_poison_shadow(page_address(page), | ||
| 298 | PAGE_SIZE << order, | ||
| 299 | KASAN_FREE_PAGE); | ||
| 300 | } | ||
| 301 | |||
| 302 | void kasan_poison_slab(struct page *page) | ||
| 303 | { | ||
| 304 | kasan_poison_shadow(page_address(page), | ||
| 305 | PAGE_SIZE << compound_order(page), | ||
| 306 | KASAN_KMALLOC_REDZONE); | ||
| 307 | } | ||
| 308 | |||
| 309 | void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) | ||
| 310 | { | ||
| 311 | kasan_unpoison_shadow(object, cache->object_size); | ||
| 312 | } | ||
| 313 | |||
| 314 | void kasan_poison_object_data(struct kmem_cache *cache, void *object) | ||
| 315 | { | ||
| 316 | kasan_poison_shadow(object, | ||
| 317 | round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE), | ||
| 318 | KASAN_KMALLOC_REDZONE); | ||
| 319 | } | ||
| 320 | |||
| 321 | void kasan_slab_alloc(struct kmem_cache *cache, void *object) | ||
| 322 | { | ||
| 323 | kasan_kmalloc(cache, object, cache->object_size); | ||
| 324 | } | ||
| 325 | |||
| 326 | void kasan_slab_free(struct kmem_cache *cache, void *object) | ||
| 327 | { | ||
| 328 | unsigned long size = cache->object_size; | ||
| 329 | unsigned long rounded_up_size = round_up(size, KASAN_SHADOW_SCALE_SIZE); | ||
| 330 | |||
| 331 | /* RCU slabs could be legally used after free within the RCU period */ | ||
| 332 | if (unlikely(cache->flags & SLAB_DESTROY_BY_RCU)) | ||
| 333 | return; | ||
| 334 | |||
| 335 | kasan_poison_shadow(object, rounded_up_size, KASAN_KMALLOC_FREE); | ||
| 336 | } | ||
| 337 | |||
| 338 | void kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size) | ||
| 339 | { | ||
| 340 | unsigned long redzone_start; | ||
| 341 | unsigned long redzone_end; | ||
| 342 | |||
| 343 | if (unlikely(object == NULL)) | ||
| 344 | return; | ||
| 345 | |||
| 346 | redzone_start = round_up((unsigned long)(object + size), | ||
| 347 | KASAN_SHADOW_SCALE_SIZE); | ||
| 348 | redzone_end = round_up((unsigned long)object + cache->object_size, | ||
| 349 | KASAN_SHADOW_SCALE_SIZE); | ||
| 350 | |||
| 351 | kasan_unpoison_shadow(object, size); | ||
| 352 | kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, | ||
| 353 | KASAN_KMALLOC_REDZONE); | ||
| 354 | } | ||
| 355 | EXPORT_SYMBOL(kasan_kmalloc); | ||
| 356 | |||
| 357 | void kasan_kmalloc_large(const void *ptr, size_t size) | ||
| 358 | { | ||
| 359 | struct page *page; | ||
| 360 | unsigned long redzone_start; | ||
| 361 | unsigned long redzone_end; | ||
| 362 | |||
| 363 | if (unlikely(ptr == NULL)) | ||
| 364 | return; | ||
| 365 | |||
| 366 | page = virt_to_page(ptr); | ||
| 367 | redzone_start = round_up((unsigned long)(ptr + size), | ||
| 368 | KASAN_SHADOW_SCALE_SIZE); | ||
| 369 | redzone_end = (unsigned long)ptr + (PAGE_SIZE << compound_order(page)); | ||
| 370 | |||
| 371 | kasan_unpoison_shadow(ptr, size); | ||
| 372 | kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, | ||
| 373 | KASAN_PAGE_REDZONE); | ||
| 374 | } | ||
| 375 | |||
| 376 | void kasan_krealloc(const void *object, size_t size) | ||
| 377 | { | ||
| 378 | struct page *page; | ||
| 379 | |||
| 380 | if (unlikely(object == ZERO_SIZE_PTR)) | ||
| 381 | return; | ||
| 382 | |||
| 383 | page = virt_to_head_page(object); | ||
| 384 | |||
| 385 | if (unlikely(!PageSlab(page))) | ||
| 386 | kasan_kmalloc_large(object, size); | ||
| 387 | else | ||
| 388 | kasan_kmalloc(page->slab_cache, object, size); | ||
| 389 | } | ||
| 390 | |||
| 391 | void kasan_kfree_large(const void *ptr) | ||
| 392 | { | ||
| 393 | struct page *page = virt_to_page(ptr); | ||
| 394 | |||
| 395 | kasan_poison_shadow(ptr, PAGE_SIZE << compound_order(page), | ||
| 396 | KASAN_FREE_PAGE); | ||
| 397 | } | ||
| 398 | |||
| 399 | int kasan_module_alloc(void *addr, size_t size) | ||
| 400 | { | ||
| 401 | void *ret; | ||
| 402 | size_t shadow_size; | ||
| 403 | unsigned long shadow_start; | ||
| 404 | |||
| 405 | shadow_start = (unsigned long)kasan_mem_to_shadow(addr); | ||
| 406 | shadow_size = round_up(size >> KASAN_SHADOW_SCALE_SHIFT, | ||
| 407 | PAGE_SIZE); | ||
| 408 | |||
| 409 | if (WARN_ON(!PAGE_ALIGNED(shadow_start))) | ||
| 410 | return -EINVAL; | ||
| 411 | |||
| 412 | ret = __vmalloc_node_range(shadow_size, 1, shadow_start, | ||
| 413 | shadow_start + shadow_size, | ||
| 414 | GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, | ||
| 415 | PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, | ||
| 416 | __builtin_return_address(0)); | ||
| 417 | return ret ? 0 : -ENOMEM; | ||
| 418 | } | ||
| 419 | |||
| 420 | void kasan_module_free(void *addr) | ||
| 421 | { | ||
| 422 | vfree(kasan_mem_to_shadow(addr)); | ||
| 423 | } | ||
| 424 | |||
| 425 | static void register_global(struct kasan_global *global) | ||
| 426 | { | ||
| 427 | size_t aligned_size = round_up(global->size, KASAN_SHADOW_SCALE_SIZE); | ||
| 428 | |||
| 429 | kasan_unpoison_shadow(global->beg, global->size); | ||
| 430 | |||
| 431 | kasan_poison_shadow(global->beg + aligned_size, | ||
| 432 | global->size_with_redzone - aligned_size, | ||
| 433 | KASAN_GLOBAL_REDZONE); | ||
| 434 | } | ||
| 435 | |||
| 436 | void __asan_register_globals(struct kasan_global *globals, size_t size) | ||
| 437 | { | ||
| 438 | int i; | ||
| 439 | |||
| 440 | for (i = 0; i < size; i++) | ||
| 441 | register_global(&globals[i]); | ||
| 442 | } | ||
| 443 | EXPORT_SYMBOL(__asan_register_globals); | ||
| 444 | |||
| 445 | void __asan_unregister_globals(struct kasan_global *globals, size_t size) | ||
| 446 | { | ||
| 447 | } | ||
| 448 | EXPORT_SYMBOL(__asan_unregister_globals); | ||
| 449 | |||
| 450 | #define DEFINE_ASAN_LOAD_STORE(size) \ | ||
| 451 | void __asan_load##size(unsigned long addr) \ | ||
| 452 | { \ | ||
| 453 | check_memory_region(addr, size, false); \ | ||
| 454 | } \ | ||
| 455 | EXPORT_SYMBOL(__asan_load##size); \ | ||
| 456 | __alias(__asan_load##size) \ | ||
| 457 | void __asan_load##size##_noabort(unsigned long); \ | ||
| 458 | EXPORT_SYMBOL(__asan_load##size##_noabort); \ | ||
| 459 | void __asan_store##size(unsigned long addr) \ | ||
| 460 | { \ | ||
| 461 | check_memory_region(addr, size, true); \ | ||
| 462 | } \ | ||
| 463 | EXPORT_SYMBOL(__asan_store##size); \ | ||
| 464 | __alias(__asan_store##size) \ | ||
| 465 | void __asan_store##size##_noabort(unsigned long); \ | ||
| 466 | EXPORT_SYMBOL(__asan_store##size##_noabort) | ||
| 467 | |||
| 468 | DEFINE_ASAN_LOAD_STORE(1); | ||
| 469 | DEFINE_ASAN_LOAD_STORE(2); | ||
| 470 | DEFINE_ASAN_LOAD_STORE(4); | ||
| 471 | DEFINE_ASAN_LOAD_STORE(8); | ||
| 472 | DEFINE_ASAN_LOAD_STORE(16); | ||
| 473 | |||
| 474 | void __asan_loadN(unsigned long addr, size_t size) | ||
| 475 | { | ||
| 476 | check_memory_region(addr, size, false); | ||
| 477 | } | ||
| 478 | EXPORT_SYMBOL(__asan_loadN); | ||
| 479 | |||
| 480 | __alias(__asan_loadN) | ||
| 481 | void __asan_loadN_noabort(unsigned long, size_t); | ||
| 482 | EXPORT_SYMBOL(__asan_loadN_noabort); | ||
| 483 | |||
| 484 | void __asan_storeN(unsigned long addr, size_t size) | ||
| 485 | { | ||
| 486 | check_memory_region(addr, size, true); | ||
| 487 | } | ||
| 488 | EXPORT_SYMBOL(__asan_storeN); | ||
| 489 | |||
| 490 | __alias(__asan_storeN) | ||
| 491 | void __asan_storeN_noabort(unsigned long, size_t); | ||
| 492 | EXPORT_SYMBOL(__asan_storeN_noabort); | ||
| 493 | |||
| 494 | /* to shut up compiler complaints */ | ||
| 495 | void __asan_handle_no_return(void) {} | ||
| 496 | EXPORT_SYMBOL(__asan_handle_no_return); | ||
| 497 | |||
| 498 | #ifdef CONFIG_MEMORY_HOTPLUG | ||
| 499 | static int kasan_mem_notifier(struct notifier_block *nb, | ||
| 500 | unsigned long action, void *data) | ||
| 501 | { | ||
| 502 | return (action == MEM_GOING_ONLINE) ? NOTIFY_BAD : NOTIFY_OK; | ||
| 503 | } | ||
| 504 | |||
| 505 | static int __init kasan_memhotplug_init(void) | ||
| 506 | { | ||
| 507 | pr_err("WARNING: KASan doesn't support memory hot-add\n"); | ||
| 508 | pr_err("Memory hot-add will be disabled\n"); | ||
| 509 | |||
| 510 | hotplug_memory_notifier(kasan_mem_notifier, 0); | ||
| 511 | |||
| 512 | return 0; | ||
| 513 | } | ||
| 514 | |||
| 515 | module_init(kasan_memhotplug_init); | ||
| 516 | #endif | ||
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h new file mode 100644 index 000000000000..4986b0acab21 --- /dev/null +++ b/mm/kasan/kasan.h | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | #ifndef __MM_KASAN_KASAN_H | ||
| 2 | #define __MM_KASAN_KASAN_H | ||
| 3 | |||
| 4 | #include <linux/kasan.h> | ||
| 5 | |||
| 6 | #define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) | ||
| 7 | #define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) | ||
| 8 | |||
| 9 | #define KASAN_FREE_PAGE 0xFF /* page was freed */ | ||
| 10 | #define KASAN_FREE_PAGE 0xFF /* page was freed */ | ||
| 11 | #define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */ | ||
| 12 | #define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */ | ||
| 13 | #define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */ | ||
| 14 | #define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */ | ||
| 15 | |||
| 16 | /* | ||
| 17 | * Stack redzone shadow values | ||
| 18 | * (Those are compiler's ABI, don't change them) | ||
| 19 | */ | ||
| 20 | #define KASAN_STACK_LEFT 0xF1 | ||
| 21 | #define KASAN_STACK_MID 0xF2 | ||
| 22 | #define KASAN_STACK_RIGHT 0xF3 | ||
| 23 | #define KASAN_STACK_PARTIAL 0xF4 | ||
| 24 | |||
| 25 | /* Don't break randconfig/all*config builds */ | ||
| 26 | #ifndef KASAN_ABI_VERSION | ||
| 27 | #define KASAN_ABI_VERSION 1 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | struct kasan_access_info { | ||
| 31 | const void *access_addr; | ||
| 32 | const void *first_bad_addr; | ||
| 33 | size_t access_size; | ||
| 34 | bool is_write; | ||
| 35 | unsigned long ip; | ||
| 36 | }; | ||
| 37 | |||
| 38 | /* The layout of struct dictated by compiler */ | ||
| 39 | struct kasan_source_location { | ||
| 40 | const char *filename; | ||
| 41 | int line_no; | ||
| 42 | int column_no; | ||
| 43 | }; | ||
| 44 | |||
| 45 | /* The layout of struct dictated by compiler */ | ||
| 46 | struct kasan_global { | ||
| 47 | const void *beg; /* Address of the beginning of the global variable. */ | ||
| 48 | size_t size; /* Size of the global variable. */ | ||
| 49 | size_t size_with_redzone; /* Size of the variable + size of the red zone. 32 bytes aligned */ | ||
| 50 | const void *name; | ||
| 51 | const void *module_name; /* Name of the module where the global variable is declared. */ | ||
| 52 | unsigned long has_dynamic_init; /* This needed for C++ */ | ||
| 53 | #if KASAN_ABI_VERSION >= 4 | ||
| 54 | struct kasan_source_location *location; | ||
| 55 | #endif | ||
| 56 | }; | ||
| 57 | |||
| 58 | void kasan_report_error(struct kasan_access_info *info); | ||
| 59 | void kasan_report_user_access(struct kasan_access_info *info); | ||
| 60 | |||
| 61 | static inline const void *kasan_shadow_to_mem(const void *shadow_addr) | ||
| 62 | { | ||
| 63 | return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) | ||
| 64 | << KASAN_SHADOW_SCALE_SHIFT); | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline bool kasan_enabled(void) | ||
| 68 | { | ||
| 69 | return !current->kasan_depth; | ||
| 70 | } | ||
| 71 | |||
| 72 | void kasan_report(unsigned long addr, size_t size, | ||
| 73 | bool is_write, unsigned long ip); | ||
| 74 | |||
| 75 | #endif | ||
diff --git a/mm/kasan/report.c b/mm/kasan/report.c new file mode 100644 index 000000000000..680ceedf810a --- /dev/null +++ b/mm/kasan/report.c | |||
| @@ -0,0 +1,269 @@ | |||
| 1 | /* | ||
| 2 | * This file contains error reporting code. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 5 | * Author: Andrey Ryabinin <a.ryabinin@samsung.com> | ||
| 6 | * | ||
| 7 | * Some of code borrowed from https://github.com/xairy/linux by | ||
| 8 | * Andrey Konovalov <adech.fo@gmail.com> | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License version 2 as | ||
| 12 | * published by the Free Software Foundation. | ||
| 13 | * | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/kernel.h> | ||
| 17 | #include <linux/mm.h> | ||
| 18 | #include <linux/printk.h> | ||
| 19 | #include <linux/sched.h> | ||
| 20 | #include <linux/slab.h> | ||
| 21 | #include <linux/stacktrace.h> | ||
| 22 | #include <linux/string.h> | ||
| 23 | #include <linux/types.h> | ||
| 24 | #include <linux/kasan.h> | ||
| 25 | |||
| 26 | #include <asm/sections.h> | ||
| 27 | |||
| 28 | #include "kasan.h" | ||
| 29 | #include "../slab.h" | ||
| 30 | |||
| 31 | /* Shadow layout customization. */ | ||
| 32 | #define SHADOW_BYTES_PER_BLOCK 1 | ||
| 33 | #define SHADOW_BLOCKS_PER_ROW 16 | ||
| 34 | #define SHADOW_BYTES_PER_ROW (SHADOW_BLOCKS_PER_ROW * SHADOW_BYTES_PER_BLOCK) | ||
| 35 | #define SHADOW_ROWS_AROUND_ADDR 2 | ||
| 36 | |||
| 37 | static const void *find_first_bad_addr(const void *addr, size_t size) | ||
| 38 | { | ||
| 39 | u8 shadow_val = *(u8 *)kasan_mem_to_shadow(addr); | ||
| 40 | const void *first_bad_addr = addr; | ||
| 41 | |||
| 42 | while (!shadow_val && first_bad_addr < addr + size) { | ||
| 43 | first_bad_addr += KASAN_SHADOW_SCALE_SIZE; | ||
| 44 | shadow_val = *(u8 *)kasan_mem_to_shadow(first_bad_addr); | ||
| 45 | } | ||
| 46 | return first_bad_addr; | ||
| 47 | } | ||
| 48 | |||
| 49 | static void print_error_description(struct kasan_access_info *info) | ||
| 50 | { | ||
| 51 | const char *bug_type = "unknown crash"; | ||
| 52 | u8 shadow_val; | ||
| 53 | |||
| 54 | info->first_bad_addr = find_first_bad_addr(info->access_addr, | ||
| 55 | info->access_size); | ||
| 56 | |||
| 57 | shadow_val = *(u8 *)kasan_mem_to_shadow(info->first_bad_addr); | ||
| 58 | |||
| 59 | switch (shadow_val) { | ||
| 60 | case KASAN_FREE_PAGE: | ||
| 61 | case KASAN_KMALLOC_FREE: | ||
| 62 | bug_type = "use after free"; | ||
| 63 | break; | ||
| 64 | case KASAN_PAGE_REDZONE: | ||
| 65 | case KASAN_KMALLOC_REDZONE: | ||
| 66 | case KASAN_GLOBAL_REDZONE: | ||
| 67 | case 0 ... KASAN_SHADOW_SCALE_SIZE - 1: | ||
| 68 | bug_type = "out of bounds access"; | ||
| 69 | break; | ||
| 70 | case KASAN_STACK_LEFT: | ||
| 71 | case KASAN_STACK_MID: | ||
| 72 | case KASAN_STACK_RIGHT: | ||
| 73 | case KASAN_STACK_PARTIAL: | ||
| 74 | bug_type = "out of bounds on stack"; | ||
| 75 | break; | ||
| 76 | } | ||
| 77 | |||
| 78 | pr_err("BUG: KASan: %s in %pS at addr %p\n", | ||
| 79 | bug_type, (void *)info->ip, | ||
| 80 | info->access_addr); | ||
| 81 | pr_err("%s of size %zu by task %s/%d\n", | ||
| 82 | info->is_write ? "Write" : "Read", | ||
| 83 | info->access_size, current->comm, task_pid_nr(current)); | ||
| 84 | } | ||
| 85 | |||
| 86 | static inline bool kernel_or_module_addr(const void *addr) | ||
| 87 | { | ||
| 88 | return (addr >= (void *)_stext && addr < (void *)_end) | ||
| 89 | || (addr >= (void *)MODULES_VADDR | ||
| 90 | && addr < (void *)MODULES_END); | ||
| 91 | } | ||
| 92 | |||
| 93 | static inline bool init_task_stack_addr(const void *addr) | ||
| 94 | { | ||
| 95 | return addr >= (void *)&init_thread_union.stack && | ||
| 96 | (addr <= (void *)&init_thread_union.stack + | ||
| 97 | sizeof(init_thread_union.stack)); | ||
| 98 | } | ||
| 99 | |||
| 100 | static void print_address_description(struct kasan_access_info *info) | ||
| 101 | { | ||
| 102 | const void *addr = info->access_addr; | ||
| 103 | |||
| 104 | if ((addr >= (void *)PAGE_OFFSET) && | ||
| 105 | (addr < high_memory)) { | ||
| 106 | struct page *page = virt_to_head_page(addr); | ||
| 107 | |||
| 108 | if (PageSlab(page)) { | ||
| 109 | void *object; | ||
| 110 | struct kmem_cache *cache = page->slab_cache; | ||
| 111 | void *last_object; | ||
| 112 | |||
| 113 | object = virt_to_obj(cache, page_address(page), addr); | ||
| 114 | last_object = page_address(page) + | ||
| 115 | page->objects * cache->size; | ||
| 116 | |||
| 117 | if (unlikely(object > last_object)) | ||
| 118 | object = last_object; /* we hit into padding */ | ||
| 119 | |||
| 120 | object_err(cache, page, object, | ||
| 121 | "kasan: bad access detected"); | ||
| 122 | return; | ||
| 123 | } | ||
| 124 | dump_page(page, "kasan: bad access detected"); | ||
| 125 | } | ||
| 126 | |||
| 127 | if (kernel_or_module_addr(addr)) { | ||
| 128 | if (!init_task_stack_addr(addr)) | ||
| 129 | pr_err("Address belongs to variable %pS\n", addr); | ||
| 130 | } | ||
| 131 | |||
| 132 | dump_stack(); | ||
| 133 | } | ||
| 134 | |||
| 135 | static bool row_is_guilty(const void *row, const void *guilty) | ||
| 136 | { | ||
| 137 | return (row <= guilty) && (guilty < row + SHADOW_BYTES_PER_ROW); | ||
| 138 | } | ||
| 139 | |||
| 140 | static int shadow_pointer_offset(const void *row, const void *shadow) | ||
| 141 | { | ||
| 142 | /* The length of ">ff00ff00ff00ff00: " is | ||
| 143 | * 3 + (BITS_PER_LONG/8)*2 chars. | ||
| 144 | */ | ||
| 145 | return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 + | ||
| 146 | (shadow - row) / SHADOW_BYTES_PER_BLOCK + 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | static void print_shadow_for_address(const void *addr) | ||
| 150 | { | ||
| 151 | int i; | ||
| 152 | const void *shadow = kasan_mem_to_shadow(addr); | ||
| 153 | const void *shadow_row; | ||
| 154 | |||
| 155 | shadow_row = (void *)round_down((unsigned long)shadow, | ||
| 156 | SHADOW_BYTES_PER_ROW) | ||
| 157 | - SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW; | ||
| 158 | |||
| 159 | pr_err("Memory state around the buggy address:\n"); | ||
| 160 | |||
| 161 | for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) { | ||
| 162 | const void *kaddr = kasan_shadow_to_mem(shadow_row); | ||
| 163 | char buffer[4 + (BITS_PER_LONG/8)*2]; | ||
| 164 | |||
| 165 | snprintf(buffer, sizeof(buffer), | ||
| 166 | (i == 0) ? ">%p: " : " %p: ", kaddr); | ||
| 167 | |||
| 168 | kasan_disable_current(); | ||
| 169 | print_hex_dump(KERN_ERR, buffer, | ||
| 170 | DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1, | ||
| 171 | shadow_row, SHADOW_BYTES_PER_ROW, 0); | ||
| 172 | kasan_enable_current(); | ||
| 173 | |||
| 174 | if (row_is_guilty(shadow_row, shadow)) | ||
| 175 | pr_err("%*c\n", | ||
| 176 | shadow_pointer_offset(shadow_row, shadow), | ||
| 177 | '^'); | ||
| 178 | |||
| 179 | shadow_row += SHADOW_BYTES_PER_ROW; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | static DEFINE_SPINLOCK(report_lock); | ||
| 184 | |||
| 185 | void kasan_report_error(struct kasan_access_info *info) | ||
| 186 | { | ||
| 187 | unsigned long flags; | ||
| 188 | |||
| 189 | spin_lock_irqsave(&report_lock, flags); | ||
| 190 | pr_err("=================================" | ||
| 191 | "=================================\n"); | ||
| 192 | print_error_description(info); | ||
| 193 | print_address_description(info); | ||
| 194 | print_shadow_for_address(info->first_bad_addr); | ||
| 195 | pr_err("=================================" | ||
| 196 | "=================================\n"); | ||
| 197 | spin_unlock_irqrestore(&report_lock, flags); | ||
| 198 | } | ||
| 199 | |||
| 200 | void kasan_report_user_access(struct kasan_access_info *info) | ||
| 201 | { | ||
| 202 | unsigned long flags; | ||
| 203 | |||
| 204 | spin_lock_irqsave(&report_lock, flags); | ||
| 205 | pr_err("=================================" | ||
| 206 | "=================================\n"); | ||
| 207 | pr_err("BUG: KASan: user-memory-access on address %p\n", | ||
| 208 | info->access_addr); | ||
| 209 | pr_err("%s of size %zu by task %s/%d\n", | ||
| 210 | info->is_write ? "Write" : "Read", | ||
| 211 | info->access_size, current->comm, task_pid_nr(current)); | ||
| 212 | dump_stack(); | ||
| 213 | pr_err("=================================" | ||
| 214 | "=================================\n"); | ||
| 215 | spin_unlock_irqrestore(&report_lock, flags); | ||
| 216 | } | ||
| 217 | |||
| 218 | void kasan_report(unsigned long addr, size_t size, | ||
| 219 | bool is_write, unsigned long ip) | ||
| 220 | { | ||
| 221 | struct kasan_access_info info; | ||
| 222 | |||
| 223 | if (likely(!kasan_enabled())) | ||
| 224 | return; | ||
| 225 | |||
| 226 | info.access_addr = (void *)addr; | ||
| 227 | info.access_size = size; | ||
| 228 | info.is_write = is_write; | ||
| 229 | info.ip = ip; | ||
| 230 | kasan_report_error(&info); | ||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | #define DEFINE_ASAN_REPORT_LOAD(size) \ | ||
| 235 | void __asan_report_load##size##_noabort(unsigned long addr) \ | ||
| 236 | { \ | ||
| 237 | kasan_report(addr, size, false, _RET_IP_); \ | ||
| 238 | } \ | ||
| 239 | EXPORT_SYMBOL(__asan_report_load##size##_noabort) | ||
| 240 | |||
| 241 | #define DEFINE_ASAN_REPORT_STORE(size) \ | ||
| 242 | void __asan_report_store##size##_noabort(unsigned long addr) \ | ||
| 243 | { \ | ||
| 244 | kasan_report(addr, size, true, _RET_IP_); \ | ||
| 245 | } \ | ||
| 246 | EXPORT_SYMBOL(__asan_report_store##size##_noabort) | ||
| 247 | |||
| 248 | DEFINE_ASAN_REPORT_LOAD(1); | ||
| 249 | DEFINE_ASAN_REPORT_LOAD(2); | ||
| 250 | DEFINE_ASAN_REPORT_LOAD(4); | ||
| 251 | DEFINE_ASAN_REPORT_LOAD(8); | ||
| 252 | DEFINE_ASAN_REPORT_LOAD(16); | ||
| 253 | DEFINE_ASAN_REPORT_STORE(1); | ||
| 254 | DEFINE_ASAN_REPORT_STORE(2); | ||
| 255 | DEFINE_ASAN_REPORT_STORE(4); | ||
| 256 | DEFINE_ASAN_REPORT_STORE(8); | ||
| 257 | DEFINE_ASAN_REPORT_STORE(16); | ||
| 258 | |||
| 259 | void __asan_report_load_n_noabort(unsigned long addr, size_t size) | ||
| 260 | { | ||
| 261 | kasan_report(addr, size, false, _RET_IP_); | ||
| 262 | } | ||
| 263 | EXPORT_SYMBOL(__asan_report_load_n_noabort); | ||
| 264 | |||
| 265 | void __asan_report_store_n_noabort(unsigned long addr, size_t size) | ||
| 266 | { | ||
| 267 | kasan_report(addr, size, true, _RET_IP_); | ||
| 268 | } | ||
| 269 | EXPORT_SYMBOL(__asan_report_store_n_noabort); | ||
diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 3cda50c1e394..5405aff5a590 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c | |||
| @@ -98,6 +98,7 @@ | |||
| 98 | #include <asm/processor.h> | 98 | #include <asm/processor.h> |
| 99 | #include <linux/atomic.h> | 99 | #include <linux/atomic.h> |
| 100 | 100 | ||
| 101 | #include <linux/kasan.h> | ||
| 101 | #include <linux/kmemcheck.h> | 102 | #include <linux/kmemcheck.h> |
| 102 | #include <linux/kmemleak.h> | 103 | #include <linux/kmemleak.h> |
| 103 | #include <linux/memory_hotplug.h> | 104 | #include <linux/memory_hotplug.h> |
| @@ -1113,7 +1114,10 @@ static bool update_checksum(struct kmemleak_object *object) | |||
| 1113 | if (!kmemcheck_is_obj_initialized(object->pointer, object->size)) | 1114 | if (!kmemcheck_is_obj_initialized(object->pointer, object->size)) |
| 1114 | return false; | 1115 | return false; |
| 1115 | 1116 | ||
| 1117 | kasan_disable_current(); | ||
| 1116 | object->checksum = crc32(0, (void *)object->pointer, object->size); | 1118 | object->checksum = crc32(0, (void *)object->pointer, object->size); |
| 1119 | kasan_enable_current(); | ||
| 1120 | |||
| 1117 | return object->checksum != old_csum; | 1121 | return object->checksum != old_csum; |
| 1118 | } | 1122 | } |
| 1119 | 1123 | ||
| @@ -1164,7 +1168,9 @@ static void scan_block(void *_start, void *_end, | |||
| 1164 | BYTES_PER_POINTER)) | 1168 | BYTES_PER_POINTER)) |
| 1165 | continue; | 1169 | continue; |
| 1166 | 1170 | ||
| 1171 | kasan_disable_current(); | ||
| 1167 | pointer = *ptr; | 1172 | pointer = *ptr; |
| 1173 | kasan_enable_current(); | ||
| 1168 | 1174 | ||
| 1169 | object = find_and_get_object(pointer, 1); | 1175 | object = find_and_get_object(pointer, 1); |
| 1170 | if (!object) | 1176 | if (!object) |
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index c75f4dcec808..4721046a134a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c | |||
| @@ -2817,8 +2817,7 @@ void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) | |||
| 2817 | p += snprintf(p, buffer + maxlen - p, "relative"); | 2817 | p += snprintf(p, buffer + maxlen - p, "relative"); |
| 2818 | } | 2818 | } |
| 2819 | 2819 | ||
| 2820 | if (!nodes_empty(nodes)) { | 2820 | if (!nodes_empty(nodes)) |
| 2821 | p += snprintf(p, buffer + maxlen - p, ":"); | 2821 | p += scnprintf(p, buffer + maxlen - p, ":%*pbl", |
| 2822 | p += nodelist_scnprintf(p, buffer + maxlen - p, nodes); | 2822 | nodemask_pr_args(&nodes)); |
| 2823 | } | ||
| 2824 | } | 2823 | } |
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cb4758263f6b..a47f0b229a1a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <linux/compiler.h> | 25 | #include <linux/compiler.h> |
| 26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/kmemcheck.h> | 27 | #include <linux/kmemcheck.h> |
| 28 | #include <linux/kasan.h> | ||
| 28 | #include <linux/module.h> | 29 | #include <linux/module.h> |
| 29 | #include <linux/suspend.h> | 30 | #include <linux/suspend.h> |
| 30 | #include <linux/pagevec.h> | 31 | #include <linux/pagevec.h> |
| @@ -787,6 +788,7 @@ static bool free_pages_prepare(struct page *page, unsigned int order) | |||
| 787 | 788 | ||
| 788 | trace_mm_page_free(page, order); | 789 | trace_mm_page_free(page, order); |
| 789 | kmemcheck_free_shadow(page, order); | 790 | kmemcheck_free_shadow(page, order); |
| 791 | kasan_free_pages(page, order); | ||
| 790 | 792 | ||
| 791 | if (PageAnon(page)) | 793 | if (PageAnon(page)) |
| 792 | page->mapping = NULL; | 794 | page->mapping = NULL; |
| @@ -970,6 +972,7 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags, | |||
| 970 | 972 | ||
| 971 | arch_alloc_page(page, order); | 973 | arch_alloc_page(page, order); |
| 972 | kernel_map_pages(page, 1 << order, 1); | 974 | kernel_map_pages(page, 1 << order, 1); |
| 975 | kasan_alloc_pages(page, order); | ||
| 973 | 976 | ||
| 974 | if (gfp_flags & __GFP_ZERO) | 977 | if (gfp_flags & __GFP_ZERO) |
| 975 | prep_zero_page(page, order, gfp_flags); | 978 | prep_zero_page(page, order, gfp_flags); |
diff --git a/mm/percpu.c b/mm/percpu.c index d39e2f4e335c..73c97a5f4495 100644 --- a/mm/percpu.c +++ b/mm/percpu.c | |||
| @@ -1528,7 +1528,6 @@ static void pcpu_dump_alloc_info(const char *lvl, | |||
| 1528 | int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, | 1528 | int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, |
| 1529 | void *base_addr) | 1529 | void *base_addr) |
| 1530 | { | 1530 | { |
| 1531 | static char cpus_buf[4096] __initdata; | ||
| 1532 | static int smap[PERCPU_DYNAMIC_EARLY_SLOTS] __initdata; | 1531 | static int smap[PERCPU_DYNAMIC_EARLY_SLOTS] __initdata; |
| 1533 | static int dmap[PERCPU_DYNAMIC_EARLY_SLOTS] __initdata; | 1532 | static int dmap[PERCPU_DYNAMIC_EARLY_SLOTS] __initdata; |
| 1534 | size_t dyn_size = ai->dyn_size; | 1533 | size_t dyn_size = ai->dyn_size; |
| @@ -1541,12 +1540,11 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, | |||
| 1541 | int *unit_map; | 1540 | int *unit_map; |
| 1542 | int group, unit, i; | 1541 | int group, unit, i; |
| 1543 | 1542 | ||
| 1544 | cpumask_scnprintf(cpus_buf, sizeof(cpus_buf), cpu_possible_mask); | ||
| 1545 | |||
| 1546 | #define PCPU_SETUP_BUG_ON(cond) do { \ | 1543 | #define PCPU_SETUP_BUG_ON(cond) do { \ |
| 1547 | if (unlikely(cond)) { \ | 1544 | if (unlikely(cond)) { \ |
| 1548 | pr_emerg("PERCPU: failed to initialize, %s", #cond); \ | 1545 | pr_emerg("PERCPU: failed to initialize, %s", #cond); \ |
| 1549 | pr_emerg("PERCPU: cpu_possible_mask=%s\n", cpus_buf); \ | 1546 | pr_emerg("PERCPU: cpu_possible_mask=%*pb\n", \ |
| 1547 | cpumask_pr_args(cpu_possible_mask)); \ | ||
| 1550 | pcpu_dump_alloc_info(KERN_EMERG, ai); \ | 1548 | pcpu_dump_alloc_info(KERN_EMERG, ai); \ |
| 1551 | BUG(); \ | 1549 | BUG(); \ |
| 1552 | } \ | 1550 | } \ |
diff --git a/mm/slab_common.c b/mm/slab_common.c index 1a1cc89acaa3..999bb3424d44 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
| @@ -295,8 +295,8 @@ unsigned long calculate_alignment(unsigned long flags, | |||
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | static struct kmem_cache * | 297 | static struct kmem_cache * |
| 298 | do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align, | 298 | do_kmem_cache_create(const char *name, size_t object_size, size_t size, |
| 299 | unsigned long flags, void (*ctor)(void *), | 299 | size_t align, unsigned long flags, void (*ctor)(void *), |
| 300 | struct mem_cgroup *memcg, struct kmem_cache *root_cache) | 300 | struct mem_cgroup *memcg, struct kmem_cache *root_cache) |
| 301 | { | 301 | { |
| 302 | struct kmem_cache *s; | 302 | struct kmem_cache *s; |
| @@ -363,7 +363,7 @@ kmem_cache_create(const char *name, size_t size, size_t align, | |||
| 363 | unsigned long flags, void (*ctor)(void *)) | 363 | unsigned long flags, void (*ctor)(void *)) |
| 364 | { | 364 | { |
| 365 | struct kmem_cache *s; | 365 | struct kmem_cache *s; |
| 366 | char *cache_name; | 366 | const char *cache_name; |
| 367 | int err; | 367 | int err; |
| 368 | 368 | ||
| 369 | get_online_cpus(); | 369 | get_online_cpus(); |
| @@ -390,7 +390,7 @@ kmem_cache_create(const char *name, size_t size, size_t align, | |||
| 390 | if (s) | 390 | if (s) |
| 391 | goto out_unlock; | 391 | goto out_unlock; |
| 392 | 392 | ||
| 393 | cache_name = kstrdup(name, GFP_KERNEL); | 393 | cache_name = kstrdup_const(name, GFP_KERNEL); |
| 394 | if (!cache_name) { | 394 | if (!cache_name) { |
| 395 | err = -ENOMEM; | 395 | err = -ENOMEM; |
| 396 | goto out_unlock; | 396 | goto out_unlock; |
| @@ -401,7 +401,7 @@ kmem_cache_create(const char *name, size_t size, size_t align, | |||
| 401 | flags, ctor, NULL, NULL); | 401 | flags, ctor, NULL, NULL); |
| 402 | if (IS_ERR(s)) { | 402 | if (IS_ERR(s)) { |
| 403 | err = PTR_ERR(s); | 403 | err = PTR_ERR(s); |
| 404 | kfree(cache_name); | 404 | kfree_const(cache_name); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | out_unlock: | 407 | out_unlock: |
| @@ -607,7 +607,7 @@ void memcg_destroy_kmem_caches(struct mem_cgroup *memcg) | |||
| 607 | void slab_kmem_cache_release(struct kmem_cache *s) | 607 | void slab_kmem_cache_release(struct kmem_cache *s) |
| 608 | { | 608 | { |
| 609 | destroy_memcg_params(s); | 609 | destroy_memcg_params(s); |
| 610 | kfree(s->name); | 610 | kfree_const(s->name); |
| 611 | kmem_cache_free(kmem_cache, s); | 611 | kmem_cache_free(kmem_cache, s); |
| 612 | } | 612 | } |
| 613 | 613 | ||
| @@ -898,6 +898,7 @@ void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) | |||
| 898 | page = alloc_kmem_pages(flags, order); | 898 | page = alloc_kmem_pages(flags, order); |
| 899 | ret = page ? page_address(page) : NULL; | 899 | ret = page ? page_address(page) : NULL; |
| 900 | kmemleak_alloc(ret, size, 1, flags); | 900 | kmemleak_alloc(ret, size, 1, flags); |
| 901 | kasan_kmalloc_large(ret, size); | ||
| 901 | return ret; | 902 | return ret; |
| 902 | } | 903 | } |
| 903 | EXPORT_SYMBOL(kmalloc_order); | 904 | EXPORT_SYMBOL(kmalloc_order); |
| @@ -1077,8 +1078,10 @@ static __always_inline void *__do_krealloc(const void *p, size_t new_size, | |||
| 1077 | if (p) | 1078 | if (p) |
| 1078 | ks = ksize(p); | 1079 | ks = ksize(p); |
| 1079 | 1080 | ||
| 1080 | if (ks >= new_size) | 1081 | if (ks >= new_size) { |
| 1082 | kasan_krealloc((void *)p, new_size); | ||
| 1081 | return (void *)p; | 1083 | return (void *)p; |
| 1084 | } | ||
| 1082 | 1085 | ||
| 1083 | ret = kmalloc_track_caller(new_size, flags); | 1086 | ret = kmalloc_track_caller(new_size, flags); |
| 1084 | if (ret && p) | 1087 | if (ret && p) |
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/proc_fs.h> | 20 | #include <linux/proc_fs.h> |
| 21 | #include <linux/notifier.h> | 21 | #include <linux/notifier.h> |
| 22 | #include <linux/seq_file.h> | 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/kasan.h> | ||
| 23 | #include <linux/kmemcheck.h> | 24 | #include <linux/kmemcheck.h> |
| 24 | #include <linux/cpu.h> | 25 | #include <linux/cpu.h> |
| 25 | #include <linux/cpuset.h> | 26 | #include <linux/cpuset.h> |
| @@ -468,12 +469,30 @@ static char *slub_debug_slabs; | |||
| 468 | static int disable_higher_order_debug; | 469 | static int disable_higher_order_debug; |
| 469 | 470 | ||
| 470 | /* | 471 | /* |
| 472 | * slub is about to manipulate internal object metadata. This memory lies | ||
| 473 | * outside the range of the allocated object, so accessing it would normally | ||
| 474 | * be reported by kasan as a bounds error. metadata_access_enable() is used | ||
| 475 | * to tell kasan that these accesses are OK. | ||
| 476 | */ | ||
| 477 | static inline void metadata_access_enable(void) | ||
| 478 | { | ||
| 479 | kasan_disable_current(); | ||
| 480 | } | ||
| 481 | |||
| 482 | static inline void metadata_access_disable(void) | ||
| 483 | { | ||
| 484 | kasan_enable_current(); | ||
| 485 | } | ||
| 486 | |||
| 487 | /* | ||
| 471 | * Object debugging | 488 | * Object debugging |
| 472 | */ | 489 | */ |
| 473 | static void print_section(char *text, u8 *addr, unsigned int length) | 490 | static void print_section(char *text, u8 *addr, unsigned int length) |
| 474 | { | 491 | { |
| 492 | metadata_access_enable(); | ||
| 475 | print_hex_dump(KERN_ERR, text, DUMP_PREFIX_ADDRESS, 16, 1, addr, | 493 | print_hex_dump(KERN_ERR, text, DUMP_PREFIX_ADDRESS, 16, 1, addr, |
| 476 | length, 1); | 494 | length, 1); |
| 495 | metadata_access_disable(); | ||
| 477 | } | 496 | } |
| 478 | 497 | ||
| 479 | static struct track *get_track(struct kmem_cache *s, void *object, | 498 | static struct track *get_track(struct kmem_cache *s, void *object, |
| @@ -503,7 +522,9 @@ static void set_track(struct kmem_cache *s, void *object, | |||
| 503 | trace.max_entries = TRACK_ADDRS_COUNT; | 522 | trace.max_entries = TRACK_ADDRS_COUNT; |
| 504 | trace.entries = p->addrs; | 523 | trace.entries = p->addrs; |
| 505 | trace.skip = 3; | 524 | trace.skip = 3; |
| 525 | metadata_access_enable(); | ||
| 506 | save_stack_trace(&trace); | 526 | save_stack_trace(&trace); |
| 527 | metadata_access_disable(); | ||
| 507 | 528 | ||
| 508 | /* See rant in lockdep.c */ | 529 | /* See rant in lockdep.c */ |
| 509 | if (trace.nr_entries != 0 && | 530 | if (trace.nr_entries != 0 && |
| @@ -629,7 +650,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p) | |||
| 629 | dump_stack(); | 650 | dump_stack(); |
| 630 | } | 651 | } |
| 631 | 652 | ||
| 632 | static void object_err(struct kmem_cache *s, struct page *page, | 653 | void object_err(struct kmem_cache *s, struct page *page, |
| 633 | u8 *object, char *reason) | 654 | u8 *object, char *reason) |
| 634 | { | 655 | { |
| 635 | slab_bug(s, "%s", reason); | 656 | slab_bug(s, "%s", reason); |
| @@ -677,7 +698,9 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, | |||
| 677 | u8 *fault; | 698 | u8 *fault; |
| 678 | u8 *end; | 699 | u8 *end; |
| 679 | 700 | ||
| 701 | metadata_access_enable(); | ||
| 680 | fault = memchr_inv(start, value, bytes); | 702 | fault = memchr_inv(start, value, bytes); |
| 703 | metadata_access_disable(); | ||
| 681 | if (!fault) | 704 | if (!fault) |
| 682 | return 1; | 705 | return 1; |
| 683 | 706 | ||
| @@ -770,7 +793,9 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page) | |||
| 770 | if (!remainder) | 793 | if (!remainder) |
| 771 | return 1; | 794 | return 1; |
| 772 | 795 | ||
| 796 | metadata_access_enable(); | ||
| 773 | fault = memchr_inv(end - remainder, POISON_INUSE, remainder); | 797 | fault = memchr_inv(end - remainder, POISON_INUSE, remainder); |
| 798 | metadata_access_disable(); | ||
| 774 | if (!fault) | 799 | if (!fault) |
| 775 | return 1; | 800 | return 1; |
| 776 | while (end > fault && end[-1] == POISON_INUSE) | 801 | while (end > fault && end[-1] == POISON_INUSE) |
| @@ -1226,11 +1251,13 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node, | |||
| 1226 | static inline void kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags) | 1251 | static inline void kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags) |
| 1227 | { | 1252 | { |
| 1228 | kmemleak_alloc(ptr, size, 1, flags); | 1253 | kmemleak_alloc(ptr, size, 1, flags); |
| 1254 | kasan_kmalloc_large(ptr, size); | ||
| 1229 | } | 1255 | } |
| 1230 | 1256 | ||
| 1231 | static inline void kfree_hook(const void *x) | 1257 | static inline void kfree_hook(const void *x) |
| 1232 | { | 1258 | { |
| 1233 | kmemleak_free(x); | 1259 | kmemleak_free(x); |
| 1260 | kasan_kfree_large(x); | ||
| 1234 | } | 1261 | } |
| 1235 | 1262 | ||
| 1236 | static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, | 1263 | static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, |
| @@ -1253,6 +1280,7 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s, | |||
| 1253 | kmemcheck_slab_alloc(s, flags, object, slab_ksize(s)); | 1280 | kmemcheck_slab_alloc(s, flags, object, slab_ksize(s)); |
| 1254 | kmemleak_alloc_recursive(object, s->object_size, 1, s->flags, flags); | 1281 | kmemleak_alloc_recursive(object, s->object_size, 1, s->flags, flags); |
| 1255 | memcg_kmem_put_cache(s); | 1282 | memcg_kmem_put_cache(s); |
| 1283 | kasan_slab_alloc(s, object); | ||
| 1256 | } | 1284 | } |
| 1257 | 1285 | ||
| 1258 | static inline void slab_free_hook(struct kmem_cache *s, void *x) | 1286 | static inline void slab_free_hook(struct kmem_cache *s, void *x) |
| @@ -1276,6 +1304,8 @@ static inline void slab_free_hook(struct kmem_cache *s, void *x) | |||
| 1276 | #endif | 1304 | #endif |
| 1277 | if (!(s->flags & SLAB_DEBUG_OBJECTS)) | 1305 | if (!(s->flags & SLAB_DEBUG_OBJECTS)) |
| 1278 | debug_check_no_obj_freed(x, s->object_size); | 1306 | debug_check_no_obj_freed(x, s->object_size); |
| 1307 | |||
| 1308 | kasan_slab_free(s, x); | ||
| 1279 | } | 1309 | } |
| 1280 | 1310 | ||
| 1281 | /* | 1311 | /* |
| @@ -1370,8 +1400,11 @@ static void setup_object(struct kmem_cache *s, struct page *page, | |||
| 1370 | void *object) | 1400 | void *object) |
| 1371 | { | 1401 | { |
| 1372 | setup_object_debug(s, page, object); | 1402 | setup_object_debug(s, page, object); |
| 1373 | if (unlikely(s->ctor)) | 1403 | if (unlikely(s->ctor)) { |
| 1404 | kasan_unpoison_object_data(s, object); | ||
| 1374 | s->ctor(object); | 1405 | s->ctor(object); |
| 1406 | kasan_poison_object_data(s, object); | ||
| 1407 | } | ||
| 1375 | } | 1408 | } |
| 1376 | 1409 | ||
| 1377 | static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node) | 1410 | static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node) |
| @@ -1404,6 +1437,8 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node) | |||
| 1404 | if (unlikely(s->flags & SLAB_POISON)) | 1437 | if (unlikely(s->flags & SLAB_POISON)) |
| 1405 | memset(start, POISON_INUSE, PAGE_SIZE << order); | 1438 | memset(start, POISON_INUSE, PAGE_SIZE << order); |
| 1406 | 1439 | ||
| 1440 | kasan_poison_slab(page); | ||
| 1441 | |||
| 1407 | for_each_object_idx(p, idx, s, start, page->objects) { | 1442 | for_each_object_idx(p, idx, s, start, page->objects) { |
| 1408 | setup_object(s, page, p); | 1443 | setup_object(s, page, p); |
| 1409 | if (likely(idx < page->objects)) | 1444 | if (likely(idx < page->objects)) |
| @@ -2497,6 +2532,7 @@ void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size) | |||
| 2497 | { | 2532 | { |
| 2498 | void *ret = slab_alloc(s, gfpflags, _RET_IP_); | 2533 | void *ret = slab_alloc(s, gfpflags, _RET_IP_); |
| 2499 | trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags); | 2534 | trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags); |
| 2535 | kasan_kmalloc(s, ret, size); | ||
| 2500 | return ret; | 2536 | return ret; |
| 2501 | } | 2537 | } |
| 2502 | EXPORT_SYMBOL(kmem_cache_alloc_trace); | 2538 | EXPORT_SYMBOL(kmem_cache_alloc_trace); |
| @@ -2523,6 +2559,8 @@ void *kmem_cache_alloc_node_trace(struct kmem_cache *s, | |||
| 2523 | 2559 | ||
| 2524 | trace_kmalloc_node(_RET_IP_, ret, | 2560 | trace_kmalloc_node(_RET_IP_, ret, |
| 2525 | size, s->size, gfpflags, node); | 2561 | size, s->size, gfpflags, node); |
| 2562 | |||
| 2563 | kasan_kmalloc(s, ret, size); | ||
| 2526 | return ret; | 2564 | return ret; |
| 2527 | } | 2565 | } |
| 2528 | EXPORT_SYMBOL(kmem_cache_alloc_node_trace); | 2566 | EXPORT_SYMBOL(kmem_cache_alloc_node_trace); |
| @@ -2908,6 +2946,7 @@ static void early_kmem_cache_node_alloc(int node) | |||
| 2908 | init_object(kmem_cache_node, n, SLUB_RED_ACTIVE); | 2946 | init_object(kmem_cache_node, n, SLUB_RED_ACTIVE); |
| 2909 | init_tracking(kmem_cache_node, n); | 2947 | init_tracking(kmem_cache_node, n); |
| 2910 | #endif | 2948 | #endif |
| 2949 | kasan_kmalloc(kmem_cache_node, n, sizeof(struct kmem_cache_node)); | ||
| 2911 | init_kmem_cache_node(n); | 2950 | init_kmem_cache_node(n); |
| 2912 | inc_slabs_node(kmem_cache_node, node, page->objects); | 2951 | inc_slabs_node(kmem_cache_node, node, page->objects); |
| 2913 | 2952 | ||
| @@ -3280,6 +3319,8 @@ void *__kmalloc(size_t size, gfp_t flags) | |||
| 3280 | 3319 | ||
| 3281 | trace_kmalloc(_RET_IP_, ret, size, s->size, flags); | 3320 | trace_kmalloc(_RET_IP_, ret, size, s->size, flags); |
| 3282 | 3321 | ||
| 3322 | kasan_kmalloc(s, ret, size); | ||
| 3323 | |||
| 3283 | return ret; | 3324 | return ret; |
| 3284 | } | 3325 | } |
| 3285 | EXPORT_SYMBOL(__kmalloc); | 3326 | EXPORT_SYMBOL(__kmalloc); |
| @@ -3323,12 +3364,14 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) | |||
| 3323 | 3364 | ||
| 3324 | trace_kmalloc_node(_RET_IP_, ret, size, s->size, flags, node); | 3365 | trace_kmalloc_node(_RET_IP_, ret, size, s->size, flags, node); |
| 3325 | 3366 | ||
| 3367 | kasan_kmalloc(s, ret, size); | ||
| 3368 | |||
| 3326 | return ret; | 3369 | return ret; |
| 3327 | } | 3370 | } |
| 3328 | EXPORT_SYMBOL(__kmalloc_node); | 3371 | EXPORT_SYMBOL(__kmalloc_node); |
| 3329 | #endif | 3372 | #endif |
| 3330 | 3373 | ||
| 3331 | size_t ksize(const void *object) | 3374 | static size_t __ksize(const void *object) |
| 3332 | { | 3375 | { |
| 3333 | struct page *page; | 3376 | struct page *page; |
| 3334 | 3377 | ||
| @@ -3344,6 +3387,15 @@ size_t ksize(const void *object) | |||
| 3344 | 3387 | ||
| 3345 | return slab_ksize(page->slab_cache); | 3388 | return slab_ksize(page->slab_cache); |
| 3346 | } | 3389 | } |
| 3390 | |||
| 3391 | size_t ksize(const void *object) | ||
| 3392 | { | ||
| 3393 | size_t size = __ksize(object); | ||
| 3394 | /* We assume that ksize callers could use whole allocated area, | ||
| 3395 | so we need unpoison this area. */ | ||
| 3396 | kasan_krealloc(object, size); | ||
| 3397 | return size; | ||
| 3398 | } | ||
| 3347 | EXPORT_SYMBOL(ksize); | 3399 | EXPORT_SYMBOL(ksize); |
| 3348 | 3400 | ||
| 3349 | void kfree(const void *x) | 3401 | void kfree(const void *x) |
| @@ -4108,20 +4160,16 @@ static int list_locations(struct kmem_cache *s, char *buf, | |||
| 4108 | 4160 | ||
| 4109 | if (num_online_cpus() > 1 && | 4161 | if (num_online_cpus() > 1 && |
| 4110 | !cpumask_empty(to_cpumask(l->cpus)) && | 4162 | !cpumask_empty(to_cpumask(l->cpus)) && |
| 4111 | len < PAGE_SIZE - 60) { | 4163 | len < PAGE_SIZE - 60) |
| 4112 | len += sprintf(buf + len, " cpus="); | 4164 | len += scnprintf(buf + len, PAGE_SIZE - len - 50, |
| 4113 | len += cpulist_scnprintf(buf + len, | 4165 | " cpus=%*pbl", |
| 4114 | PAGE_SIZE - len - 50, | 4166 | cpumask_pr_args(to_cpumask(l->cpus))); |
| 4115 | to_cpumask(l->cpus)); | ||
| 4116 | } | ||
| 4117 | 4167 | ||
| 4118 | if (nr_online_nodes > 1 && !nodes_empty(l->nodes) && | 4168 | if (nr_online_nodes > 1 && !nodes_empty(l->nodes) && |
| 4119 | len < PAGE_SIZE - 60) { | 4169 | len < PAGE_SIZE - 60) |
| 4120 | len += sprintf(buf + len, " nodes="); | 4170 | len += scnprintf(buf + len, PAGE_SIZE - len - 50, |
| 4121 | len += nodelist_scnprintf(buf + len, | 4171 | " nodes=%*pbl", |
| 4122 | PAGE_SIZE - len - 50, | 4172 | nodemask_pr_args(&l->nodes)); |
| 4123 | l->nodes); | ||
| 4124 | } | ||
| 4125 | 4173 | ||
| 4126 | len += sprintf(buf + len, "\n"); | 4174 | len += sprintf(buf + len, "\n"); |
| 4127 | } | 4175 | } |
| @@ -12,10 +12,30 @@ | |||
| 12 | #include <linux/hugetlb.h> | 12 | #include <linux/hugetlb.h> |
| 13 | #include <linux/vmalloc.h> | 13 | #include <linux/vmalloc.h> |
| 14 | 14 | ||
| 15 | #include <asm/sections.h> | ||
| 15 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
| 16 | 17 | ||
| 17 | #include "internal.h" | 18 | #include "internal.h" |
| 18 | 19 | ||
| 20 | static inline int is_kernel_rodata(unsigned long addr) | ||
| 21 | { | ||
| 22 | return addr >= (unsigned long)__start_rodata && | ||
| 23 | addr < (unsigned long)__end_rodata; | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * kfree_const - conditionally free memory | ||
| 28 | * @x: pointer to the memory | ||
| 29 | * | ||
| 30 | * Function calls kfree only if @x is not in .rodata section. | ||
| 31 | */ | ||
| 32 | void kfree_const(const void *x) | ||
| 33 | { | ||
| 34 | if (!is_kernel_rodata((unsigned long)x)) | ||
| 35 | kfree(x); | ||
| 36 | } | ||
| 37 | EXPORT_SYMBOL(kfree_const); | ||
| 38 | |||
| 19 | /** | 39 | /** |
| 20 | * kstrdup - allocate space for and copy an existing string | 40 | * kstrdup - allocate space for and copy an existing string |
| 21 | * @s: the string to duplicate | 41 | * @s: the string to duplicate |
| @@ -38,6 +58,24 @@ char *kstrdup(const char *s, gfp_t gfp) | |||
| 38 | EXPORT_SYMBOL(kstrdup); | 58 | EXPORT_SYMBOL(kstrdup); |
| 39 | 59 | ||
| 40 | /** | 60 | /** |
| 61 | * kstrdup_const - conditionally duplicate an existing const string | ||
| 62 | * @s: the string to duplicate | ||
| 63 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory | ||
| 64 | * | ||
| 65 | * Function returns source string if it is in .rodata section otherwise it | ||
| 66 | * fallbacks to kstrdup. | ||
| 67 | * Strings allocated by kstrdup_const should be freed by kfree_const. | ||
| 68 | */ | ||
| 69 | const char *kstrdup_const(const char *s, gfp_t gfp) | ||
| 70 | { | ||
| 71 | if (is_kernel_rodata((unsigned long)s)) | ||
| 72 | return s; | ||
| 73 | |||
| 74 | return kstrdup(s, gfp); | ||
| 75 | } | ||
| 76 | EXPORT_SYMBOL(kstrdup_const); | ||
| 77 | |||
| 78 | /** | ||
| 41 | * kstrndup - allocate space for and copy an existing string | 79 | * kstrndup - allocate space for and copy an existing string |
| 42 | * @s: the string to duplicate | 80 | * @s: the string to duplicate |
| 43 | * @max: read at most @max chars from @s | 81 | * @max: read at most @max chars from @s |
diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 39c338896416..35b25e1340ca 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c | |||
| @@ -1324,10 +1324,8 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, | |||
| 1324 | if (unlikely(!area)) | 1324 | if (unlikely(!area)) |
| 1325 | return NULL; | 1325 | return NULL; |
| 1326 | 1326 | ||
| 1327 | /* | 1327 | if (!(flags & VM_NO_GUARD)) |
| 1328 | * We always allocate a guard page. | 1328 | size += PAGE_SIZE; |
| 1329 | */ | ||
| 1330 | size += PAGE_SIZE; | ||
| 1331 | 1329 | ||
| 1332 | va = alloc_vmap_area(size, align, start, end, node, gfp_mask); | 1330 | va = alloc_vmap_area(size, align, start, end, node, gfp_mask); |
| 1333 | if (IS_ERR(va)) { | 1331 | if (IS_ERR(va)) { |
| @@ -1621,6 +1619,7 @@ fail: | |||
| 1621 | * @end: vm area range end | 1619 | * @end: vm area range end |
| 1622 | * @gfp_mask: flags for the page level allocator | 1620 | * @gfp_mask: flags for the page level allocator |
| 1623 | * @prot: protection mask for the allocated pages | 1621 | * @prot: protection mask for the allocated pages |
| 1622 | * @vm_flags: additional vm area flags (e.g. %VM_NO_GUARD) | ||
| 1624 | * @node: node to use for allocation or NUMA_NO_NODE | 1623 | * @node: node to use for allocation or NUMA_NO_NODE |
| 1625 | * @caller: caller's return address | 1624 | * @caller: caller's return address |
| 1626 | * | 1625 | * |
| @@ -1630,7 +1629,8 @@ fail: | |||
| 1630 | */ | 1629 | */ |
| 1631 | void *__vmalloc_node_range(unsigned long size, unsigned long align, | 1630 | void *__vmalloc_node_range(unsigned long size, unsigned long align, |
| 1632 | unsigned long start, unsigned long end, gfp_t gfp_mask, | 1631 | unsigned long start, unsigned long end, gfp_t gfp_mask, |
| 1633 | pgprot_t prot, int node, const void *caller) | 1632 | pgprot_t prot, unsigned long vm_flags, int node, |
| 1633 | const void *caller) | ||
| 1634 | { | 1634 | { |
| 1635 | struct vm_struct *area; | 1635 | struct vm_struct *area; |
| 1636 | void *addr; | 1636 | void *addr; |
| @@ -1640,8 +1640,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, | |||
| 1640 | if (!size || (size >> PAGE_SHIFT) > totalram_pages) | 1640 | if (!size || (size >> PAGE_SHIFT) > totalram_pages) |
| 1641 | goto fail; | 1641 | goto fail; |
| 1642 | 1642 | ||
| 1643 | area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED, | 1643 | area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | |
| 1644 | start, end, node, gfp_mask, caller); | 1644 | vm_flags, start, end, node, gfp_mask, caller); |
| 1645 | if (!area) | 1645 | if (!area) |
| 1646 | goto fail; | 1646 | goto fail; |
| 1647 | 1647 | ||
| @@ -1690,7 +1690,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align, | |||
| 1690 | int node, const void *caller) | 1690 | int node, const void *caller) |
| 1691 | { | 1691 | { |
| 1692 | return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, | 1692 | return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, |
| 1693 | gfp_mask, prot, node, caller); | 1693 | gfp_mask, prot, 0, node, caller); |
| 1694 | } | 1694 | } |
| 1695 | 1695 | ||
| 1696 | void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) | 1696 | void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) |
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 999341244434..f2aa73bfb0e4 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c | |||
| @@ -614,8 +614,7 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue, | |||
| 614 | { | 614 | { |
| 615 | struct rps_map *map; | 615 | struct rps_map *map; |
| 616 | cpumask_var_t mask; | 616 | cpumask_var_t mask; |
| 617 | size_t len = 0; | 617 | int i, len; |
| 618 | int i; | ||
| 619 | 618 | ||
| 620 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) | 619 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
| 621 | return -ENOMEM; | 620 | return -ENOMEM; |
| @@ -626,17 +625,11 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue, | |||
| 626 | for (i = 0; i < map->len; i++) | 625 | for (i = 0; i < map->len; i++) |
| 627 | cpumask_set_cpu(map->cpus[i], mask); | 626 | cpumask_set_cpu(map->cpus[i], mask); |
| 628 | 627 | ||
| 629 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); | 628 | len = snprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask)); |
| 630 | if (PAGE_SIZE - len < 3) { | ||
| 631 | rcu_read_unlock(); | ||
| 632 | free_cpumask_var(mask); | ||
| 633 | return -EINVAL; | ||
| 634 | } | ||
| 635 | rcu_read_unlock(); | 629 | rcu_read_unlock(); |
| 636 | |||
| 637 | free_cpumask_var(mask); | 630 | free_cpumask_var(mask); |
| 638 | len += sprintf(buf + len, "\n"); | 631 | |
| 639 | return len; | 632 | return len < PAGE_SIZE ? len : -EINVAL; |
| 640 | } | 633 | } |
| 641 | 634 | ||
| 642 | static ssize_t store_rps_map(struct netdev_rx_queue *queue, | 635 | static ssize_t store_rps_map(struct netdev_rx_queue *queue, |
| @@ -1090,8 +1083,7 @@ static ssize_t show_xps_map(struct netdev_queue *queue, | |||
| 1090 | struct xps_dev_maps *dev_maps; | 1083 | struct xps_dev_maps *dev_maps; |
| 1091 | cpumask_var_t mask; | 1084 | cpumask_var_t mask; |
| 1092 | unsigned long index; | 1085 | unsigned long index; |
| 1093 | size_t len = 0; | 1086 | int i, len; |
| 1094 | int i; | ||
| 1095 | 1087 | ||
| 1096 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) | 1088 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
| 1097 | return -ENOMEM; | 1089 | return -ENOMEM; |
| @@ -1117,15 +1109,9 @@ static ssize_t show_xps_map(struct netdev_queue *queue, | |||
| 1117 | } | 1109 | } |
| 1118 | rcu_read_unlock(); | 1110 | rcu_read_unlock(); |
| 1119 | 1111 | ||
| 1120 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); | 1112 | len = snprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask)); |
| 1121 | if (PAGE_SIZE - len < 3) { | ||
| 1122 | free_cpumask_var(mask); | ||
| 1123 | return -EINVAL; | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | free_cpumask_var(mask); | 1113 | free_cpumask_var(mask); |
| 1127 | len += sprintf(buf + len, "\n"); | 1114 | return len < PAGE_SIZE ? len : -EINVAL; |
| 1128 | return len; | ||
| 1129 | } | 1115 | } |
| 1130 | 1116 | ||
| 1131 | static ssize_t store_xps_map(struct netdev_queue *queue, | 1117 | static ssize_t store_xps_map(struct netdev_queue *queue, |
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index eaa51ddf2368..433424804284 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c | |||
| @@ -155,7 +155,7 @@ write_unlock: | |||
| 155 | rcu_read_unlock(); | 155 | rcu_read_unlock(); |
| 156 | 156 | ||
| 157 | len = min(sizeof(kbuf) - 1, *lenp); | 157 | len = min(sizeof(kbuf) - 1, *lenp); |
| 158 | len = cpumask_scnprintf(kbuf, len, mask); | 158 | len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask)); |
| 159 | if (!len) { | 159 | if (!len) { |
| 160 | *lenp = 0; | 160 | *lenp = 0; |
| 161 | goto done; | 161 | goto done; |
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan new file mode 100644 index 000000000000..631619b2b118 --- /dev/null +++ b/scripts/Makefile.kasan | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | ifdef CONFIG_KASAN | ||
| 2 | ifdef CONFIG_KASAN_INLINE | ||
| 3 | call_threshold := 10000 | ||
| 4 | else | ||
| 5 | call_threshold := 0 | ||
| 6 | endif | ||
| 7 | |||
| 8 | CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address | ||
| 9 | |||
| 10 | CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ | ||
| 11 | -fasan-shadow-offset=$(CONFIG_KASAN_SHADOW_OFFSET) \ | ||
| 12 | --param asan-stack=1 --param asan-globals=1 \ | ||
| 13 | --param asan-instrumentation-with-call-threshold=$(call_threshold)) | ||
| 14 | |||
| 15 | ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) | ||
| 16 | $(warning Cannot use CONFIG_KASAN: \ | ||
| 17 | -fsanitize=kernel-address is not supported by compiler) | ||
| 18 | else | ||
| 19 | ifeq ($(CFLAGS_KASAN),) | ||
| 20 | $(warning CONFIG_KASAN: compiler does not support all options.\ | ||
| 21 | Trying minimal configuration) | ||
| 22 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) | ||
| 23 | endif | ||
| 24 | endif | ||
| 25 | endif | ||
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 511755200634..044eb4f89a91 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
| @@ -119,6 +119,16 @@ _c_flags += $(if $(patsubst n%,, \ | |||
| 119 | $(CFLAGS_GCOV)) | 119 | $(CFLAGS_GCOV)) |
| 120 | endif | 120 | endif |
| 121 | 121 | ||
| 122 | # | ||
| 123 | # Enable address sanitizer flags for kernel except some files or directories | ||
| 124 | # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) | ||
| 125 | # | ||
| 126 | ifeq ($(CONFIG_KASAN),y) | ||
| 127 | _c_flags += $(if $(patsubst n%,, \ | ||
| 128 | $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ | ||
| 129 | $(CFLAGS_KASAN)) | ||
| 130 | endif | ||
| 131 | |||
| 122 | # If building the kernel in a separate objtree expand all occurrences | 132 | # If building the kernel in a separate objtree expand all occurrences |
| 123 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). | 133 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). |
| 124 | 134 | ||
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f0bb6d60c07b..d12435992dea 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -278,6 +278,7 @@ our $Attribute = qr{ | |||
| 278 | __noreturn| | 278 | __noreturn| |
| 279 | __used| | 279 | __used| |
| 280 | __cold| | 280 | __cold| |
| 281 | __pure| | ||
| 281 | __noclone| | 282 | __noclone| |
| 282 | __deprecated| | 283 | __deprecated| |
| 283 | __read_mostly| | 284 | __read_mostly| |
| @@ -298,6 +299,7 @@ our $Binary = qr{(?i)0b[01]+$Int_type?}; | |||
| 298 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; | 299 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; |
| 299 | our $Int = qr{[0-9]+$Int_type?}; | 300 | our $Int = qr{[0-9]+$Int_type?}; |
| 300 | our $Octal = qr{0[0-7]+$Int_type?}; | 301 | our $Octal = qr{0[0-7]+$Int_type?}; |
| 302 | our $String = qr{"[X\t]*"}; | ||
| 301 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; | 303 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; |
| 302 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; | 304 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; |
| 303 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; | 305 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; |
| @@ -337,6 +339,11 @@ our $UTF8 = qr{ | |||
| 337 | | $NON_ASCII_UTF8 | 339 | | $NON_ASCII_UTF8 |
| 338 | }x; | 340 | }x; |
| 339 | 341 | ||
| 342 | our $typeOtherOSTypedefs = qr{(?x: | ||
| 343 | u_(?:char|short|int|long) | # bsd | ||
| 344 | u(?:nchar|short|int|long) # sysv | ||
| 345 | )}; | ||
| 346 | |||
| 340 | our $typeTypedefs = qr{(?x: | 347 | our $typeTypedefs = qr{(?x: |
| 341 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| | 348 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| |
| 342 | atomic_t | 349 | atomic_t |
| @@ -473,6 +480,7 @@ sub build_types { | |||
| 473 | (?:$Modifier\s+|const\s+)* | 480 | (?:$Modifier\s+|const\s+)* |
| 474 | (?: | 481 | (?: |
| 475 | (?:typeof|__typeof__)\s*\([^\)]*\)| | 482 | (?:typeof|__typeof__)\s*\([^\)]*\)| |
| 483 | (?:$typeOtherOSTypedefs\b)| | ||
| 476 | (?:$typeTypedefs\b)| | 484 | (?:$typeTypedefs\b)| |
| 477 | (?:${all}\b) | 485 | (?:${all}\b) |
| 478 | ) | 486 | ) |
| @@ -490,6 +498,7 @@ sub build_types { | |||
| 490 | (?: | 498 | (?: |
| 491 | (?:typeof|__typeof__)\s*\([^\)]*\)| | 499 | (?:typeof|__typeof__)\s*\([^\)]*\)| |
| 492 | (?:$typeTypedefs\b)| | 500 | (?:$typeTypedefs\b)| |
| 501 | (?:$typeOtherOSTypedefs\b)| | ||
| 493 | (?:${allWithAttr}\b) | 502 | (?:${allWithAttr}\b) |
| 494 | ) | 503 | ) |
| 495 | (?:\s+$Modifier|\s+const)* | 504 | (?:\s+$Modifier|\s+const)* |
| @@ -517,7 +526,7 @@ our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; | |||
| 517 | 526 | ||
| 518 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; | 527 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; |
| 519 | our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*}; | 528 | our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*}; |
| 520 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; | 529 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)}; |
| 521 | 530 | ||
| 522 | our $declaration_macros = qr{(?x: | 531 | our $declaration_macros = qr{(?x: |
| 523 | (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,2}\s*\(| | 532 | (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,2}\s*\(| |
| @@ -632,6 +641,8 @@ sub git_commit_info { | |||
| 632 | $output =~ s/^\s*//gm; | 641 | $output =~ s/^\s*//gm; |
| 633 | my @lines = split("\n", $output); | 642 | my @lines = split("\n", $output); |
| 634 | 643 | ||
| 644 | return ($id, $desc) if ($#lines < 0); | ||
| 645 | |||
| 635 | if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { | 646 | if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { |
| 636 | # Maybe one day convert this block of bash into something that returns | 647 | # Maybe one day convert this block of bash into something that returns |
| 637 | # all matching commit ids, but it's very slow... | 648 | # all matching commit ids, but it's very slow... |
| @@ -2159,6 +2170,13 @@ sub process { | |||
| 2159 | } | 2170 | } |
| 2160 | } | 2171 | } |
| 2161 | 2172 | ||
| 2173 | # Check email subject for common tools that don't need to be mentioned | ||
| 2174 | if ($in_header_lines && | ||
| 2175 | $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) { | ||
| 2176 | WARN("EMAIL_SUBJECT", | ||
| 2177 | "A patch subject line should describe the change not the tool that found it\n" . $herecurr); | ||
| 2178 | } | ||
| 2179 | |||
| 2162 | # Check for old stable address | 2180 | # Check for old stable address |
| 2163 | if ($line =~ /^\s*cc:\s*.*<?\bstable\@kernel\.org\b>?.*$/i) { | 2181 | if ($line =~ /^\s*cc:\s*.*<?\bstable\@kernel\.org\b>?.*$/i) { |
| 2164 | ERROR("STABLE_ADDRESS", | 2182 | ERROR("STABLE_ADDRESS", |
| @@ -2171,21 +2189,49 @@ sub process { | |||
| 2171 | "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); | 2189 | "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); |
| 2172 | } | 2190 | } |
| 2173 | 2191 | ||
| 2174 | # Check for improperly formed commit descriptions | 2192 | # Check for git id commit length and improperly formed commit descriptions |
| 2175 | if ($in_commit_log && | 2193 | if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { |
| 2176 | $line =~ /\bcommit\s+[0-9a-f]{5,}/i && | ||
| 2177 | !($line =~ /\b[Cc]ommit [0-9a-f]{12,40} \("/ || | ||
| 2178 | ($line =~ /\b[Cc]ommit [0-9a-f]{12,40}\s*$/ && | ||
| 2179 | defined $rawlines[$linenr] && | ||
| 2180 | $rawlines[$linenr] =~ /^\s*\("/))) { | ||
| 2181 | $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i; | ||
| 2182 | my $init_char = $1; | 2194 | my $init_char = $1; |
| 2183 | my $orig_commit = lc($2); | 2195 | my $orig_commit = lc($2); |
| 2184 | my $id = '01234567890ab'; | 2196 | my $short = 1; |
| 2185 | my $desc = 'commit description'; | 2197 | my $long = 0; |
| 2186 | ($id, $desc) = git_commit_info($orig_commit, $id, $desc); | 2198 | my $case = 1; |
| 2187 | ERROR("GIT_COMMIT_ID", | 2199 | my $space = 1; |
| 2188 | "Please use 12 or more chars for the git commit ID like: '${init_char}ommit $id (\"$desc\")'\n" . $herecurr); | 2200 | my $hasdesc = 0; |
| 2201 | my $hasparens = 0; | ||
| 2202 | my $id = '0123456789ab'; | ||
| 2203 | my $orig_desc = "commit description"; | ||
| 2204 | my $description = ""; | ||
| 2205 | |||
| 2206 | $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i); | ||
| 2207 | $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); | ||
| 2208 | $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); | ||
| 2209 | $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); | ||
| 2210 | if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { | ||
| 2211 | $orig_desc = $1; | ||
| 2212 | $hasparens = 1; | ||
| 2213 | } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && | ||
| 2214 | defined $rawlines[$linenr] && | ||
| 2215 | $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { | ||
| 2216 | $orig_desc = $1; | ||
| 2217 | $hasparens = 1; | ||
| 2218 | } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && | ||
| 2219 | defined $rawlines[$linenr] && | ||
| 2220 | $rawlines[$linenr] =~ /^\s*[^"]+"\)/) { | ||
| 2221 | $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i; | ||
| 2222 | $orig_desc = $1; | ||
| 2223 | $rawlines[$linenr] =~ /^\s*([^"]+)"\)/; | ||
| 2224 | $orig_desc .= " " . $1; | ||
| 2225 | $hasparens = 1; | ||
| 2226 | } | ||
| 2227 | |||
| 2228 | ($id, $description) = git_commit_info($orig_commit, | ||
| 2229 | $id, $orig_desc); | ||
| 2230 | |||
| 2231 | if ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens) { | ||
| 2232 | ERROR("GIT_COMMIT_ID", | ||
| 2233 | "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr); | ||
| 2234 | } | ||
| 2189 | } | 2235 | } |
| 2190 | 2236 | ||
| 2191 | # Check for added, moved or deleted files | 2237 | # Check for added, moved or deleted files |
| @@ -2355,6 +2401,13 @@ sub process { | |||
| 2355 | "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n"); | 2401 | "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n"); |
| 2356 | } | 2402 | } |
| 2357 | 2403 | ||
| 2404 | # discourage the use of boolean for type definition attributes of Kconfig options | ||
| 2405 | if ($realfile =~ /Kconfig/ && | ||
| 2406 | $line =~ /^\+\s*\bboolean\b/) { | ||
| 2407 | WARN("CONFIG_TYPE_BOOLEAN", | ||
| 2408 | "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); | ||
| 2409 | } | ||
| 2410 | |||
| 2358 | if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && | 2411 | if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && |
| 2359 | ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { | 2412 | ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { |
| 2360 | my $flag = $1; | 2413 | my $flag = $1; |
| @@ -2499,7 +2552,7 @@ sub process { | |||
| 2499 | } | 2552 | } |
| 2500 | } | 2553 | } |
| 2501 | 2554 | ||
| 2502 | if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;\({\[\<\>])/ && | 2555 | if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && |
| 2503 | (!defined($1) || $1 !~ /sizeof\s*/)) { | 2556 | (!defined($1) || $1 !~ /sizeof\s*/)) { |
| 2504 | if (CHK("SPACING", | 2557 | if (CHK("SPACING", |
| 2505 | "No space is necessary after a cast\n" . $herecurr) && | 2558 | "No space is necessary after a cast\n" . $herecurr) && |
| @@ -3124,6 +3177,7 @@ sub process { | |||
| 3124 | $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && | 3177 | $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && |
| 3125 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && | 3178 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && |
| 3126 | $line !~ /\b$typeTypedefs\b/ && | 3179 | $line !~ /\b$typeTypedefs\b/ && |
| 3180 | $line !~ /\b$typeOtherOSTypedefs\b/ && | ||
| 3127 | $line !~ /\b__bitwise(?:__|)\b/) { | 3181 | $line !~ /\b__bitwise(?:__|)\b/) { |
| 3128 | WARN("NEW_TYPEDEFS", | 3182 | WARN("NEW_TYPEDEFS", |
| 3129 | "do not add new typedefs\n" . $herecurr); | 3183 | "do not add new typedefs\n" . $herecurr); |
| @@ -3200,7 +3254,7 @@ sub process { | |||
| 3200 | # check for uses of printk_ratelimit | 3254 | # check for uses of printk_ratelimit |
| 3201 | if ($line =~ /\bprintk_ratelimit\s*\(/) { | 3255 | if ($line =~ /\bprintk_ratelimit\s*\(/) { |
| 3202 | WARN("PRINTK_RATELIMITED", | 3256 | WARN("PRINTK_RATELIMITED", |
| 3203 | "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr); | 3257 | "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr); |
| 3204 | } | 3258 | } |
| 3205 | 3259 | ||
| 3206 | # printk should use KERN_* levels. Note that follow on printk's on the | 3260 | # printk should use KERN_* levels. Note that follow on printk's on the |
| @@ -3646,7 +3700,22 @@ sub process { | |||
| 3646 | $op eq '*' or $op eq '/' or | 3700 | $op eq '*' or $op eq '/' or |
| 3647 | $op eq '%') | 3701 | $op eq '%') |
| 3648 | { | 3702 | { |
| 3649 | if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { | 3703 | if ($check) { |
| 3704 | if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) { | ||
| 3705 | if (CHK("SPACING", | ||
| 3706 | "spaces preferred around that '$op' $at\n" . $hereptr)) { | ||
| 3707 | $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; | ||
| 3708 | $fix_elements[$n + 2] =~ s/^\s+//; | ||
| 3709 | $line_fixed = 1; | ||
| 3710 | } | ||
| 3711 | } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) { | ||
| 3712 | if (CHK("SPACING", | ||
| 3713 | "space preferred before that '$op' $at\n" . $hereptr)) { | ||
| 3714 | $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]); | ||
| 3715 | $line_fixed = 1; | ||
| 3716 | } | ||
| 3717 | } | ||
| 3718 | } elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { | ||
| 3650 | if (ERROR("SPACING", | 3719 | if (ERROR("SPACING", |
| 3651 | "need consistent spacing around '$op' $at\n" . $hereptr)) { | 3720 | "need consistent spacing around '$op' $at\n" . $hereptr)) { |
| 3652 | $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; | 3721 | $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; |
| @@ -4251,6 +4320,7 @@ sub process { | |||
| 4251 | $ctx = $dstat; | 4320 | $ctx = $dstat; |
| 4252 | 4321 | ||
| 4253 | $dstat =~ s/\\\n.//g; | 4322 | $dstat =~ s/\\\n.//g; |
| 4323 | $dstat =~ s/$;/ /g; | ||
| 4254 | 4324 | ||
| 4255 | if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) { | 4325 | if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) { |
| 4256 | my $stmts = $2; | 4326 | my $stmts = $2; |
| @@ -4417,12 +4487,18 @@ sub process { | |||
| 4417 | 4487 | ||
| 4418 | # check for unnecessary blank lines around braces | 4488 | # check for unnecessary blank lines around braces |
| 4419 | if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) { | 4489 | if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) { |
| 4420 | CHK("BRACES", | 4490 | if (CHK("BRACES", |
| 4421 | "Blank lines aren't necessary before a close brace '}'\n" . $hereprev); | 4491 | "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) && |
| 4492 | $fix && $prevrawline =~ /^\+/) { | ||
| 4493 | fix_delete_line($fixlinenr - 1, $prevrawline); | ||
| 4494 | } | ||
| 4422 | } | 4495 | } |
| 4423 | if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { | 4496 | if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { |
| 4424 | CHK("BRACES", | 4497 | if (CHK("BRACES", |
| 4425 | "Blank lines aren't necessary after an open brace '{'\n" . $hereprev); | 4498 | "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) && |
| 4499 | $fix) { | ||
| 4500 | fix_delete_line($fixlinenr, $rawline); | ||
| 4501 | } | ||
| 4426 | } | 4502 | } |
| 4427 | 4503 | ||
| 4428 | # no volatiles please | 4504 | # no volatiles please |
| @@ -4545,7 +4621,7 @@ sub process { | |||
| 4545 | } | 4621 | } |
| 4546 | 4622 | ||
| 4547 | # check for logging functions with KERN_<LEVEL> | 4623 | # check for logging functions with KERN_<LEVEL> |
| 4548 | if ($line !~ /printk\s*\(/ && | 4624 | if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ && |
| 4549 | $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) { | 4625 | $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) { |
| 4550 | my $level = $1; | 4626 | my $level = $1; |
| 4551 | if (WARN("UNNECESSARY_KERN_LEVEL", | 4627 | if (WARN("UNNECESSARY_KERN_LEVEL", |
| @@ -4804,7 +4880,8 @@ sub process { | |||
| 4804 | # check for seq_printf uses that could be seq_puts | 4880 | # check for seq_printf uses that could be seq_puts |
| 4805 | if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) { | 4881 | if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) { |
| 4806 | my $fmt = get_quoted_string($line, $rawline); | 4882 | my $fmt = get_quoted_string($line, $rawline); |
| 4807 | if ($fmt ne "" && $fmt !~ /[^\\]\%/) { | 4883 | $fmt =~ s/%%//g; |
| 4884 | if ($fmt !~ /%/) { | ||
| 4808 | if (WARN("PREFER_SEQ_PUTS", | 4885 | if (WARN("PREFER_SEQ_PUTS", |
| 4809 | "Prefer seq_puts to seq_printf\n" . $herecurr) && | 4886 | "Prefer seq_puts to seq_printf\n" . $herecurr) && |
| 4810 | $fix) { | 4887 | $fix) { |
| @@ -5089,6 +5166,12 @@ sub process { | |||
| 5089 | } | 5166 | } |
| 5090 | } | 5167 | } |
| 5091 | 5168 | ||
| 5169 | # check for uses of __DATE__, __TIME__, __TIMESTAMP__ | ||
| 5170 | while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) { | ||
| 5171 | ERROR("DATE_TIME", | ||
| 5172 | "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr); | ||
| 5173 | } | ||
| 5174 | |||
| 5092 | # check for use of yield() | 5175 | # check for use of yield() |
| 5093 | if ($line =~ /\byield\s*\(\s*\)/) { | 5176 | if ($line =~ /\byield\s*\(\s*\)/) { |
| 5094 | WARN("YIELD", | 5177 | WARN("YIELD", |
| @@ -5140,8 +5223,9 @@ sub process { | |||
| 5140 | "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); | 5223 | "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); |
| 5141 | } | 5224 | } |
| 5142 | 5225 | ||
| 5143 | # check for various ops structs, ensure they are const. | 5226 | # check for various structs that are normally const (ops, kgdb, device_tree) |
| 5144 | my $struct_ops = qr{acpi_dock_ops| | 5227 | my $const_structs = qr{ |
| 5228 | acpi_dock_ops| | ||
| 5145 | address_space_operations| | 5229 | address_space_operations| |
| 5146 | backlight_ops| | 5230 | backlight_ops| |
| 5147 | block_device_operations| | 5231 | block_device_operations| |
| @@ -5164,6 +5248,7 @@ sub process { | |||
| 5164 | mtrr_ops| | 5248 | mtrr_ops| |
| 5165 | neigh_ops| | 5249 | neigh_ops| |
| 5166 | nlmsvc_binding| | 5250 | nlmsvc_binding| |
| 5251 | of_device_id| | ||
| 5167 | pci_raw_ops| | 5252 | pci_raw_ops| |
| 5168 | pipe_buf_operations| | 5253 | pipe_buf_operations| |
| 5169 | platform_hibernation_ops| | 5254 | platform_hibernation_ops| |
| @@ -5179,7 +5264,7 @@ sub process { | |||
| 5179 | usb_mon_operations| | 5264 | usb_mon_operations| |
| 5180 | wd_ops}x; | 5265 | wd_ops}x; |
| 5181 | if ($line !~ /\bconst\b/ && | 5266 | if ($line !~ /\bconst\b/ && |
| 5182 | $line =~ /\bstruct\s+($struct_ops)\b/) { | 5267 | $line =~ /\bstruct\s+($const_structs)\b/) { |
| 5183 | WARN("CONST_STRUCT", | 5268 | WARN("CONST_STRUCT", |
| 5184 | "struct $1 should normally be const\n" . | 5269 | "struct $1 should normally be const\n" . |
| 5185 | $herecurr); | 5270 | $herecurr); |
| @@ -5204,6 +5289,13 @@ sub process { | |||
| 5204 | "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); | 5289 | "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); |
| 5205 | } | 5290 | } |
| 5206 | 5291 | ||
| 5292 | # likely/unlikely comparisons similar to "(likely(foo) > 0)" | ||
| 5293 | if ($^V && $^V ge 5.10.0 && | ||
| 5294 | $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) { | ||
| 5295 | WARN("LIKELY_MISUSE", | ||
| 5296 | "Using $1 should generally have parentheses around the comparison\n" . $herecurr); | ||
| 5297 | } | ||
| 5298 | |||
| 5207 | # whine mightly about in_atomic | 5299 | # whine mightly about in_atomic |
| 5208 | if ($line =~ /\bin_atomic\s*\(/) { | 5300 | if ($line =~ /\bin_atomic\s*\(/) { |
| 5209 | if ($realfile =~ m@^drivers/@) { | 5301 | if ($realfile =~ m@^drivers/@) { |
| @@ -5255,6 +5347,9 @@ sub process { | |||
| 5255 | length($val) ne 4)) { | 5347 | length($val) ne 4)) { |
| 5256 | ERROR("NON_OCTAL_PERMISSIONS", | 5348 | ERROR("NON_OCTAL_PERMISSIONS", |
| 5257 | "Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); | 5349 | "Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); |
| 5350 | } elsif ($val =~ /^$Octal$/ && (oct($val) & 02)) { | ||
| 5351 | ERROR("EXPORTED_WORLD_WRITABLE", | ||
| 5352 | "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); | ||
| 5258 | } | 5353 | } |
| 5259 | } | 5354 | } |
| 5260 | } | 5355 | } |
diff --git a/scripts/module-common.lds b/scripts/module-common.lds index bec15f908fc6..73a2c7da0e55 100644 --- a/scripts/module-common.lds +++ b/scripts/module-common.lds | |||
| @@ -16,4 +16,7 @@ SECTIONS { | |||
| 16 | __kcrctab_unused 0 : { *(SORT(___kcrctab_unused+*)) } | 16 | __kcrctab_unused 0 : { *(SORT(___kcrctab_unused+*)) } |
| 17 | __kcrctab_unused_gpl 0 : { *(SORT(___kcrctab_unused_gpl+*)) } | 17 | __kcrctab_unused_gpl 0 : { *(SORT(___kcrctab_unused_gpl+*)) } |
| 18 | __kcrctab_gpl_future 0 : { *(SORT(___kcrctab_gpl_future+*)) } | 18 | __kcrctab_gpl_future 0 : { *(SORT(___kcrctab_gpl_future+*)) } |
| 19 | |||
| 20 | . = ALIGN(8); | ||
| 21 | .init_array 0 : { *(SORT(.init_array.*)) *(.init_array) } | ||
| 19 | } | 22 | } |
