···895895S: Warrendale, Pennsylvania 15086896896S: USA897897898898+N: Ludovic Desroches899899+E: ludovic.desroches@microchip.com900900+D: Maintainer for ARM/Microchip (AT91) SoC support901901+D: Author of ADC, pinctrl, XDMA and SDHCI drivers for this platform902902+S: France903903+898904N: Martin Devera899905E: devik@cdi.cz900906W: http://luxik.cdi.cz/~devik/qos/
+33-17
Documentation/admin-guide/hw-vuln/spectre.rst
···6060Spectre variant 1 attacks take advantage of speculative execution of6161conditional branches, while Spectre variant 2 attacks use speculative6262execution of indirect branches to leak privileged memory.6363-See :ref:`[1] <spec_ref1>` :ref:`[5] <spec_ref5>` :ref:`[7] <spec_ref7>`6464-:ref:`[10] <spec_ref10>` :ref:`[11] <spec_ref11>`.6363+See :ref:`[1] <spec_ref1>` :ref:`[5] <spec_ref5>` :ref:`[6] <spec_ref6>`6464+:ref:`[7] <spec_ref7>` :ref:`[10] <spec_ref10>` :ref:`[11] <spec_ref11>`.65656666Spectre variant 1 (Bounds Check Bypass)6767---------------------------------------···130130steer its indirect branch speculations to gadget code, and measure the131131speculative execution's side effects left in level 1 cache to infer the132132victim's data.133133+134134+Yet another variant 2 attack vector is for the attacker to poison the135135+Branch History Buffer (BHB) to speculatively steer an indirect branch136136+to a specific Branch Target Buffer (BTB) entry, even if the entry isn't137137+associated with the source address of the indirect branch. Specifically,138138+the BHB might be shared across privilege levels even in the presence of139139+Enhanced IBRS.140140+141141+Currently the only known real-world BHB attack vector is via142142+unprivileged eBPF. Therefore, it's highly recommended to not enable143143+unprivileged eBPF, especially when eIBRS is used (without retpolines).144144+For a full mitigation against BHB attacks, it's recommended to use145145+retpolines (or eIBRS combined with retpolines).133146134147Attack scenarios135148----------------···377364378365 - Kernel status:379366380380- ==================================== =================================381381- 'Not affected' The processor is not vulnerable382382- 'Vulnerable' Vulnerable, no mitigation383383- 'Mitigation: Full generic retpoline' Software-focused mitigation384384- 'Mitigation: Full AMD retpoline' AMD-specific software mitigation385385- 'Mitigation: Enhanced IBRS' Hardware-focused mitigation386386- ==================================== =================================367367+ ======================================== =================================368368+ 'Not affected' The processor is not vulnerable369369+ 'Mitigation: None' Vulnerable, no mitigation370370+ 'Mitigation: Retpolines' Use Retpoline thunks371371+ 'Mitigation: LFENCE' Use LFENCE instructions372372+ 'Mitigation: Enhanced IBRS' Hardware-focused mitigation373373+ 'Mitigation: Enhanced IBRS + Retpolines' Hardware-focused + Retpolines374374+ 'Mitigation: Enhanced IBRS + LFENCE' Hardware-focused + LFENCE375375+ ======================================== =================================387376388377 - Firmware status: Show if Indirect Branch Restricted Speculation (IBRS) is389378 used to protect against Spectre variant 2 attacks when calling firmware (x86 only).···598583599584 Specific mitigations can also be selected manually:600585601601- retpoline602602- replace indirect branches603603- retpoline,generic604604- google's original retpoline605605- retpoline,amd606606- AMD-specific minimal thunk586586+ retpoline auto pick between generic,lfence587587+ retpoline,generic Retpolines588588+ retpoline,lfence LFENCE; indirect branch589589+ retpoline,amd alias for retpoline,lfence590590+ eibrs enhanced IBRS591591+ eibrs,retpoline enhanced IBRS + Retpolines592592+ eibrs,lfence enhanced IBRS + LFENCE607593608594 Not specifying this option is equivalent to609595 spectre_v2=auto.···615599 spectre_v2=off. Spectre variant 1 mitigations616600 cannot be disabled.617601618618-For spectre_v2_user see :doc:`/admin-guide/kernel-parameters`.602602+For spectre_v2_user see Documentation/admin-guide/kernel-parameters.txt619603620604Mitigation selection guide621605--------------------------···697681698682.. _spec_ref6:699683700700-[6] `Software techniques for managing speculation on AMD processors <https://developer.amd.com/wp-content/resources/90343-B_SoftwareTechniquesforManagingSpeculation_WP_7-18Update_FNL.pdf>`_.684684+[6] `Software techniques for managing speculation on AMD processors <https://developer.amd.com/wp-content/resources/Managing-Speculation-on-AMD-Processors.pdf>`_.701685702686ARM white papers:703687
+6-2
Documentation/admin-guide/kernel-parameters.txt
···53615361 Specific mitigations can also be selected manually:5362536253635363 retpoline - replace indirect branches53645364- retpoline,generic - google's original retpoline53655365- retpoline,amd - AMD-specific minimal thunk53645364+ retpoline,generic - Retpolines53655365+ retpoline,lfence - LFENCE; indirect branch53665366+ retpoline,amd - alias for retpoline,lfence53675367+ eibrs - enhanced IBRS53685368+ eibrs,retpoline - enhanced IBRS + Retpolines53695369+ eibrs,lfence - enhanced IBRS + LFENCE5366537053675371 Not specifying this option is equivalent to53685372 spectre_v2=auto.
+1-1
Documentation/admin-guide/mm/pagemap.rst
···2323 * Bit 56 page exclusively mapped (since 4.2)2424 * Bit 57 pte is uffd-wp write-protected (since 5.13) (see2525 :ref:`Documentation/admin-guide/mm/userfaultfd.rst <userfaultfd>`)2626- * Bits 57-60 zero2626+ * Bits 58-60 zero2727 * Bit 61 page is file-page or shared-anon (since 3.5)2828 * Bit 62 page swapped2929 * Bit 63 page present
-8
Documentation/core-api/dma-attributes.rst
···130130subsystem that the buffer is fully accessible at the elevated privilege131131level (and ideally inaccessible or at least read-only at the132132lesser-privileged levels).133133-134134-DMA_ATTR_OVERWRITE135135-------------------136136-137137-This is a hint to the DMA-mapping subsystem that the device is expected to138138-overwrite the entire mapped size, thus the caller does not require any of the139139-previous buffer contents to be preserved. This allows bounce-buffering140140-implementations to optimise DMA_FROM_DEVICE transfers.
···8899maintainers:1010 - Alexandre Belloni <alexandre.belloni@bootlin.com>1111- - Ludovic Desroches <ludovic.desroches@microchip.com>1111+ - Claudiu Beznea <claudiu.beznea@microchip.com>1212+ - Nicolas Ferre <nicolas.ferre@microchip.com>12131314description: |1415 Boards with a SoC of the Atmel AT91 or SMART family shall have the following
···88 - compatible: Should contain a chip-specific compatible string,99 Chip-specific strings are of the form "fsl,<chip>-dcfg",1010 The following <chip>s are known to be supported:1111- ls1012a, ls1021a, ls1043a, ls1046a, ls2080a.1111+ ls1012a, ls1021a, ls1043a, ls1046a, ls2080a, lx2160a12121313 - reg : should contain base address and length of DCFG memory-mapped registers1414
···3030#include <linux/atomic.h>3131#include <asm/cacheflush.h>3232#include <asm/exception.h>3333+#include <asm/spectre.h>3334#include <asm/unistd.h>3435#include <asm/traps.h>3536#include <asm/ptrace.h>···790789}791790#endif792791792792+#ifndef CONFIG_CPU_V7M793793+static void copy_from_lma(void *vma, void *lma_start, void *lma_end)794794+{795795+ memcpy(vma, lma_start, lma_end - lma_start);796796+}797797+798798+static void flush_vectors(void *vma, size_t offset, size_t size)799799+{800800+ unsigned long start = (unsigned long)vma + offset;801801+ unsigned long end = start + size;802802+803803+ flush_icache_range(start, end);804804+}805805+806806+#ifdef CONFIG_HARDEN_BRANCH_HISTORY807807+int spectre_bhb_update_vectors(unsigned int method)808808+{809809+ extern char __vectors_bhb_bpiall_start[], __vectors_bhb_bpiall_end[];810810+ extern char __vectors_bhb_loop8_start[], __vectors_bhb_loop8_end[];811811+ void *vec_start, *vec_end;812812+813813+ if (system_state >= SYSTEM_FREEING_INITMEM) {814814+ pr_err("CPU%u: Spectre BHB workaround too late - system vulnerable\n",815815+ smp_processor_id());816816+ return SPECTRE_VULNERABLE;817817+ }818818+819819+ switch (method) {820820+ case SPECTRE_V2_METHOD_LOOP8:821821+ vec_start = __vectors_bhb_loop8_start;822822+ vec_end = __vectors_bhb_loop8_end;823823+ break;824824+825825+ case SPECTRE_V2_METHOD_BPIALL:826826+ vec_start = __vectors_bhb_bpiall_start;827827+ vec_end = __vectors_bhb_bpiall_end;828828+ break;829829+830830+ default:831831+ pr_err("CPU%u: unknown Spectre BHB state %d\n",832832+ smp_processor_id(), method);833833+ return SPECTRE_VULNERABLE;834834+ }835835+836836+ copy_from_lma(vectors_page, vec_start, vec_end);837837+ flush_vectors(vectors_page, 0, vec_end - vec_start);838838+839839+ return SPECTRE_MITIGATED;840840+}841841+#endif842842+793843void __init early_trap_init(void *vectors_base)794844{795795-#ifndef CONFIG_CPU_V7M796796- unsigned long vectors = (unsigned long)vectors_base;797845 extern char __stubs_start[], __stubs_end[];798846 extern char __vectors_start[], __vectors_end[];799847 unsigned i;···863813 * into the vector page, mapped at 0xffff0000, and ensure these864814 * are visible to the instruction stream.865815 */866866- memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);867867- memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);816816+ copy_from_lma(vectors_base, __vectors_start, __vectors_end);817817+ copy_from_lma(vectors_base + 0x1000, __stubs_start, __stubs_end);868818869819 kuser_init(vectors_base);870820871871- flush_icache_range(vectors, vectors + PAGE_SIZE * 2);821821+ flush_vectors(vectors_base, 0, PAGE_SIZE * 2);822822+}872823#else /* ifndef CONFIG_CPU_V7M */824824+void __init early_trap_init(void *vectors_base)825825+{873826 /*874827 * on V7-M there is no need to copy the vector table to a dedicated875828 * memory area. The address is configurable and so a table in the kernel876829 * image can be used.877830 */878878-#endif879831}832832+#endif
+1
arch/arm/mach-mstar/Kconfig
···33 depends on ARCH_MULTI_V744 select ARM_GIC55 select ARM_HEAVY_MB66+ select HAVE_ARM_ARCH_TIMER67 select MST_IRQ78 select MSTAR_MSC313_MPLL89 help
+11
arch/arm/mm/Kconfig
···830830831831config CPU_SPECTRE832832 bool833833+ select GENERIC_CPU_VULNERABILITIES833834834835config HARDEN_BRANCH_PREDICTOR835836 bool "Harden the branch predictor against aliasing attacks" if EXPERT···850849 the system firmware.851850852851 If unsure, say Y.852852+853853+config HARDEN_BRANCH_HISTORY854854+ bool "Harden Spectre style attacks against branch history" if EXPERT855855+ depends on CPU_SPECTRE856856+ default y857857+ help858858+ Speculation attacks against some high-performance processors can859859+ make use of branch history to influence future speculation. When860860+ taking an exception, a sequence of branches overwrites the branch861861+ history, or branch history is invalidated.853862854863config TLS_REG_EMUL855864 bool
+2
arch/arm/mm/mmu.c
···212212static int __init early_cachepolicy(char *p)213213{214214 pr_warn("cachepolicy kernel parameter not supported without cp15\n");215215+ return 0;215216}216217early_param("cachepolicy", early_cachepolicy);217218218219static int __init noalign_setup(char *__unused)219220{220221 pr_warn("noalign kernel parameter not supported without cp15\n");222222+ return 1;221223}222224__setup("noalign", noalign_setup);223225
+175-35
arch/arm/mm/proc-v7-bugs.c
···66#include <asm/cp15.h>77#include <asm/cputype.h>88#include <asm/proc-fns.h>99+#include <asm/spectre.h>910#include <asm/system_misc.h>1111+1212+#ifdef CONFIG_ARM_PSCI1313+static int __maybe_unused spectre_v2_get_cpu_fw_mitigation_state(void)1414+{1515+ struct arm_smccc_res res;1616+1717+ arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,1818+ ARM_SMCCC_ARCH_WORKAROUND_1, &res);1919+2020+ switch ((int)res.a0) {2121+ case SMCCC_RET_SUCCESS:2222+ return SPECTRE_MITIGATED;2323+2424+ case SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED:2525+ return SPECTRE_UNAFFECTED;2626+2727+ default:2828+ return SPECTRE_VULNERABLE;2929+ }3030+}3131+#else3232+static int __maybe_unused spectre_v2_get_cpu_fw_mitigation_state(void)3333+{3434+ return SPECTRE_VULNERABLE;3535+}3636+#endif10371138#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR1239DEFINE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn);···6336 arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);6437}65386666-static void cpu_v7_spectre_init(void)3939+static unsigned int spectre_v2_install_workaround(unsigned int method)6740{6841 const char *spectre_v2_method = NULL;6942 int cpu = smp_processor_id();70437144 if (per_cpu(harden_branch_predictor_fn, cpu))7272- return;4545+ return SPECTRE_MITIGATED;4646+4747+ switch (method) {4848+ case SPECTRE_V2_METHOD_BPIALL:4949+ per_cpu(harden_branch_predictor_fn, cpu) =5050+ harden_branch_predictor_bpiall;5151+ spectre_v2_method = "BPIALL";5252+ break;5353+5454+ case SPECTRE_V2_METHOD_ICIALLU:5555+ per_cpu(harden_branch_predictor_fn, cpu) =5656+ harden_branch_predictor_iciallu;5757+ spectre_v2_method = "ICIALLU";5858+ break;5959+6060+ case SPECTRE_V2_METHOD_HVC:6161+ per_cpu(harden_branch_predictor_fn, cpu) =6262+ call_hvc_arch_workaround_1;6363+ cpu_do_switch_mm = cpu_v7_hvc_switch_mm;6464+ spectre_v2_method = "hypervisor";6565+ break;6666+6767+ case SPECTRE_V2_METHOD_SMC:6868+ per_cpu(harden_branch_predictor_fn, cpu) =6969+ call_smc_arch_workaround_1;7070+ cpu_do_switch_mm = cpu_v7_smc_switch_mm;7171+ spectre_v2_method = "firmware";7272+ break;7373+ }7474+7575+ if (spectre_v2_method)7676+ pr_info("CPU%u: Spectre v2: using %s workaround\n",7777+ smp_processor_id(), spectre_v2_method);7878+7979+ return SPECTRE_MITIGATED;8080+}8181+#else8282+static unsigned int spectre_v2_install_workaround(unsigned int method)8383+{8484+ pr_info("CPU%u: Spectre V2: workarounds disabled by configuration\n",8585+ smp_processor_id());8686+8787+ return SPECTRE_VULNERABLE;8888+}8989+#endif9090+9191+static void cpu_v7_spectre_v2_init(void)9292+{9393+ unsigned int state, method = 0;73947495 switch (read_cpuid_part()) {7596 case ARM_CPU_PART_CORTEX_A8:···12651 case ARM_CPU_PART_CORTEX_A17:12752 case ARM_CPU_PART_CORTEX_A73:12853 case ARM_CPU_PART_CORTEX_A75:129129- per_cpu(harden_branch_predictor_fn, cpu) =130130- harden_branch_predictor_bpiall;131131- spectre_v2_method = "BPIALL";5454+ state = SPECTRE_MITIGATED;5555+ method = SPECTRE_V2_METHOD_BPIALL;13256 break;1335713458 case ARM_CPU_PART_CORTEX_A15:13559 case ARM_CPU_PART_BRAHMA_B15:136136- per_cpu(harden_branch_predictor_fn, cpu) =137137- harden_branch_predictor_iciallu;138138- spectre_v2_method = "ICIALLU";6060+ state = SPECTRE_MITIGATED;6161+ method = SPECTRE_V2_METHOD_ICIALLU;13962 break;14063141141-#ifdef CONFIG_ARM_PSCI14264 case ARM_CPU_PART_BRAHMA_B53:14365 /* Requires no workaround */6666+ state = SPECTRE_UNAFFECTED;14467 break;6868+14569 default:14670 /* Other ARM CPUs require no workaround */147147- if (read_cpuid_implementor() == ARM_CPU_IMP_ARM)7171+ if (read_cpuid_implementor() == ARM_CPU_IMP_ARM) {7272+ state = SPECTRE_UNAFFECTED;14873 break;149149- fallthrough;150150- /* Cortex A57/A72 require firmware workaround */151151- case ARM_CPU_PART_CORTEX_A57:152152- case ARM_CPU_PART_CORTEX_A72: {153153- struct arm_smccc_res res;7474+ }15475155155- arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,156156- ARM_SMCCC_ARCH_WORKAROUND_1, &res);157157- if ((int)res.a0 != 0)158158- return;7676+ fallthrough;7777+7878+ /* Cortex A57/A72 require firmware workaround */7979+ case ARM_CPU_PART_CORTEX_A57:8080+ case ARM_CPU_PART_CORTEX_A72:8181+ state = spectre_v2_get_cpu_fw_mitigation_state();8282+ if (state != SPECTRE_MITIGATED)8383+ break;1598416085 switch (arm_smccc_1_1_get_conduit()) {16186 case SMCCC_CONDUIT_HVC:162162- per_cpu(harden_branch_predictor_fn, cpu) =163163- call_hvc_arch_workaround_1;164164- cpu_do_switch_mm = cpu_v7_hvc_switch_mm;165165- spectre_v2_method = "hypervisor";8787+ method = SPECTRE_V2_METHOD_HVC;16688 break;1678916890 case SMCCC_CONDUIT_SMC:169169- per_cpu(harden_branch_predictor_fn, cpu) =170170- call_smc_arch_workaround_1;171171- cpu_do_switch_mm = cpu_v7_smc_switch_mm;172172- spectre_v2_method = "firmware";9191+ method = SPECTRE_V2_METHOD_SMC;17392 break;1749317594 default:9595+ state = SPECTRE_VULNERABLE;17696 break;17797 }17898 }179179-#endif9999+100100+ if (state == SPECTRE_MITIGATED)101101+ state = spectre_v2_install_workaround(method);102102+103103+ spectre_v2_update_state(state, method);104104+}105105+106106+#ifdef CONFIG_HARDEN_BRANCH_HISTORY107107+static int spectre_bhb_method;108108+109109+static const char *spectre_bhb_method_name(int method)110110+{111111+ switch (method) {112112+ case SPECTRE_V2_METHOD_LOOP8:113113+ return "loop";114114+115115+ case SPECTRE_V2_METHOD_BPIALL:116116+ return "BPIALL";117117+118118+ default:119119+ return "unknown";120120+ }121121+}122122+123123+static int spectre_bhb_install_workaround(int method)124124+{125125+ if (spectre_bhb_method != method) {126126+ if (spectre_bhb_method) {127127+ pr_err("CPU%u: Spectre BHB: method disagreement, system vulnerable\n",128128+ smp_processor_id());129129+130130+ return SPECTRE_VULNERABLE;131131+ }132132+133133+ if (spectre_bhb_update_vectors(method) == SPECTRE_VULNERABLE)134134+ return SPECTRE_VULNERABLE;135135+136136+ spectre_bhb_method = method;180137 }181138182182- if (spectre_v2_method)183183- pr_info("CPU%u: Spectre v2: using %s workaround\n",184184- smp_processor_id(), spectre_v2_method);139139+ pr_info("CPU%u: Spectre BHB: using %s workaround\n",140140+ smp_processor_id(), spectre_bhb_method_name(method));141141+142142+ return SPECTRE_MITIGATED;185143}186144#else187187-static void cpu_v7_spectre_init(void)145145+static int spectre_bhb_install_workaround(int method)188146{147147+ return SPECTRE_VULNERABLE;189148}190149#endif150150+151151+static void cpu_v7_spectre_bhb_init(void)152152+{153153+ unsigned int state, method = 0;154154+155155+ switch (read_cpuid_part()) {156156+ case ARM_CPU_PART_CORTEX_A15:157157+ case ARM_CPU_PART_BRAHMA_B15:158158+ case ARM_CPU_PART_CORTEX_A57:159159+ case ARM_CPU_PART_CORTEX_A72:160160+ state = SPECTRE_MITIGATED;161161+ method = SPECTRE_V2_METHOD_LOOP8;162162+ break;163163+164164+ case ARM_CPU_PART_CORTEX_A73:165165+ case ARM_CPU_PART_CORTEX_A75:166166+ state = SPECTRE_MITIGATED;167167+ method = SPECTRE_V2_METHOD_BPIALL;168168+ break;169169+170170+ default:171171+ state = SPECTRE_UNAFFECTED;172172+ break;173173+ }174174+175175+ if (state == SPECTRE_MITIGATED)176176+ state = spectre_bhb_install_workaround(method);177177+178178+ spectre_v2_update_state(state, method);179179+}191180192181static __maybe_unused bool cpu_v7_check_auxcr_set(bool *warned,193182 u32 mask, const char *msg)···281142void cpu_v7_ca8_ibe(void)282143{283144 if (check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6)))284284- cpu_v7_spectre_init();145145+ cpu_v7_spectre_v2_init();285146}286147287148void cpu_v7_ca15_ibe(void)288149{289150 if (check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0)))290290- cpu_v7_spectre_init();151151+ cpu_v7_spectre_v2_init();291152}292153293154void cpu_v7_bugs_init(void)294155{295295- cpu_v7_spectre_init();156156+ cpu_v7_spectre_v2_init();157157+ cpu_v7_spectre_bhb_init();296158}
+9-3
arch/arm64/Kconfig
···12521252 def_bool y12531253 depends on ARM_PMU1254125412551255-config ARCH_HAS_FILTER_PGPROT12561256- def_bool y12571257-12581255# Supported by clang >= 7.012591256config CC_HAVE_SHADOW_CALL_STACK12601257 def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18)···13791382 via a trampoline page in the vector table.1380138313811384 If unsure, say Y.13851385+13861386+config MITIGATE_SPECTRE_BRANCH_HISTORY13871387+ bool "Mitigate Spectre style attacks against branch history" if EXPERT13881388+ default y13891389+ help13901390+ Speculation attacks against some high-performance processors can13911391+ make use of branch history to influence future speculation.13921392+ When taking an exception from user-space, a sequence of branches13931393+ or a firmware call overwrites the branch history.1382139413831395config RODATA_FULL_DEFAULT_ENABLED13841396 bool "Apply r/o permissions of VM areas also to their linear aliases"
···18181919 aliases {2020 spi0 = &spi0;2121+ ethernet0 = ð0;2122 ethernet1 = ð1;2223 mmc0 = &sdhci0;2324 mmc1 = &sdhci1;···139138 /*140139 * U-Boot port for Turris Mox has a bug which always expects that "ranges" DT property141140 * contains exactly 2 ranges with 3 (child) address cells, 2 (parent) address cells and142142- * 2 size cells and also expects that the second range starts at 16 MB offset. If these141141+ * 2 size cells and also expects that the second range starts at 16 MB offset. Also it142142+ * expects that first range uses same address for PCI (child) and CPU (parent) cells (so143143+ * no remapping) and that this address is the lowest from all specified ranges. If these143144 * conditions are not met then U-Boot crashes during loading kernel DTB file. PCIe address144145 * space is 128 MB long, so the best split between MEM and IO is to use fixed 16 MB window145146 * for IO and the rest 112 MB (64+32+16) for MEM, despite that maximal IO size is just 64 kB.···150147 * https://source.denx.de/u-boot/u-boot/-/commit/cb2ddb291ee6fcbddd6d8f4ff49089dfe580f5d7151148 * https://source.denx.de/u-boot/u-boot/-/commit/c64ac3b3185aeb3846297ad7391fc6df8ecd73bf152149 * https://source.denx.de/u-boot/u-boot/-/commit/4a82fca8e330157081fc132a591ebd99ba02ee33150150+ * Bug related to requirement of same child and parent addresses for first range is fixed151151+ * in U-Boot version 2022.04 by following commit:152152+ * https://source.denx.de/u-boot/u-boot/-/commit/1fd54253bca7d43d046bba4853fe5fafd034bc17153153 */154154 #address-cells = <3>;155155 #size-cells = <2>;
···11+/* SPDX-License-Identifier: GPL-2.0-only */22+/*33+ * Copyright (C) 2022 ARM Ltd.44+ */55+#ifndef __ASM_VECTORS_H66+#define __ASM_VECTORS_H77+88+#include <linux/bug.h>99+#include <linux/percpu.h>1010+1111+#include <asm/fixmap.h>1212+1313+extern char vectors[];1414+extern char tramp_vectors[];1515+extern char __bp_harden_el1_vectors[];1616+1717+/*1818+ * Note: the order of this enum corresponds to two arrays in entry.S:1919+ * tramp_vecs and __bp_harden_el1_vectors. By default the canonical2020+ * 'full fat' vectors are used directly.2121+ */2222+enum arm64_bp_harden_el1_vectors {2323+#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY2424+ /*2525+ * Perform the BHB loop mitigation, before branching to the canonical2626+ * vectors.2727+ */2828+ EL1_VECTOR_BHB_LOOP,2929+3030+ /*3131+ * Make the SMC call for firmware mitigation, before branching to the3232+ * canonical vectors.3333+ */3434+ EL1_VECTOR_BHB_FW,3535+3636+ /*3737+ * Use the ClearBHB instruction, before branching to the canonical3838+ * vectors.3939+ */4040+ EL1_VECTOR_BHB_CLEAR_INSN,4141+#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */4242+4343+ /*4444+ * Remap the kernel before branching to the canonical vectors.4545+ */4646+ EL1_VECTOR_KPTI,4747+};4848+4949+#ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY5050+#define EL1_VECTOR_BHB_LOOP -15151+#define EL1_VECTOR_BHB_FW -15252+#define EL1_VECTOR_BHB_CLEAR_INSN -15353+#endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */5454+5555+/* The vectors to use on return from EL0. e.g. to remap the kernel */5656+DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);5757+5858+#ifndef CONFIG_UNMAP_KERNEL_AT_EL05959+#define TRAMP_VALIAS 06060+#endif6161+6262+static inline const char *6363+arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)6464+{6565+ if (arm64_kernel_unmapped_at_el0())6666+ return (char *)TRAMP_VALIAS + SZ_2K * slot;6767+6868+ WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);6969+7070+ return __bp_harden_el1_vectors + SZ_2K * slot;7171+}7272+7373+#endif /* __ASM_VECTORS_H */
···7373#include <linux/mm.h>7474#include <linux/cpu.h>7575#include <linux/kasan.h>7676+#include <linux/percpu.h>7777+7678#include <asm/cpu.h>7779#include <asm/cpufeature.h>7880#include <asm/cpu_ops.h>···8785#include <asm/smp.h>8886#include <asm/sysreg.h>8987#include <asm/traps.h>8888+#include <asm/vectors.h>9089#include <asm/virt.h>91909291/* Kernel representation of AT_HWCAP and AT_HWCAP2 */···112109113110bool arm64_use_ng_mappings = false;114111EXPORT_SYMBOL(arm64_use_ng_mappings);112112+113113+DEFINE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector) = vectors;115114116115/*117116 * Permit PER_LINUX32 and execve() of 32-bit binaries even if not all CPUs···231226};232227233228static const struct arm64_ftr_bits ftr_id_aa64isar2[] = {229229+ ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_HIGHER_SAFE, ID_AA64ISAR2_CLEARBHB_SHIFT, 4, 0),234230 ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64ISAR2_RPRES_SHIFT, 4, 0),235231 ARM64_FTR_END,236232};···15951589 kpti_remap_fn *remap_fn;1596159015971591 int cpu = smp_processor_id();15921592+15931593+ if (__this_cpu_read(this_cpu_vector) == vectors) {15941594+ const char *v = arm64_get_bp_hardening_vector(EL1_VECTOR_KPTI);15951595+15961596+ __this_cpu_write(this_cpu_vector, v);15971597+ }1598159815991599 /*16001600 * We don't need to rewrite the page-tables if either we've done
+157-57
arch/arm64/kernel/entry.S
···37373838 .macro kernel_ventry, el:req, ht:req, regsize:req, label:req3939 .align 74040-#ifdef CONFIG_UNMAP_KERNEL_AT_EL04040+.Lventry_start\@:4141 .if \el == 04242-alternative_if ARM64_UNMAP_KERNEL_AT_EL04242+ /*4343+ * This must be the first instruction of the EL0 vector entries. It is4444+ * skipped by the trampoline vectors, to trigger the cleanup.4545+ */4646+ b .Lskip_tramp_vectors_cleanup\@4347 .if \regsize == 644448 mrs x30, tpidrro_el04549 msr tpidrro_el0, xzr4650 .else4751 mov x30, xzr4852 .endif4949-alternative_else_nop_endif5353+.Lskip_tramp_vectors_cleanup\@:5054 .endif5151-#endif52555356 sub sp, sp, #PT_REGS_SIZE5457#ifdef CONFIG_VMAP_STACK···9895 mrs x0, tpidrro_el09996#endif10097 b el\el\ht\()_\regsize\()_\label9898+.org .Lventry_start\@ + 128 // Did we overflow the ventry slot?10199 .endm102100103103- .macro tramp_alias, dst, sym101101+ .macro tramp_alias, dst, sym, tmp104102 mov_q \dst, TRAMP_VALIAS105105- add \dst, \dst, #(\sym - .entry.tramp.text)103103+ adr_l \tmp, \sym104104+ add \dst, \dst, \tmp105105+ adr_l \tmp, .entry.tramp.text106106+ sub \dst, \dst, \tmp106107 .endm107108108109 /*···123116 tbnz \tmp2, #TIF_SSBD, .L__asm_ssbd_skip\@124117 mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2125118 mov w1, #\state126126-alternative_cb spectre_v4_patch_fw_mitigation_conduit119119+alternative_cb smccc_patch_fw_mitigation_conduit127120 nop // Patched to SMC/HVC #0128121alternative_cb_end129122.L__asm_ssbd_skip\@:···420413 ldp x24, x25, [sp, #16 * 12]421414 ldp x26, x27, [sp, #16 * 13]422415 ldp x28, x29, [sp, #16 * 14]423423- ldr lr, [sp, #S_LR]424424- add sp, sp, #PT_REGS_SIZE // restore sp425416426417 .if \el == 0427427-alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0418418+alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0419419+ ldr lr, [sp, #S_LR]420420+ add sp, sp, #PT_REGS_SIZE // restore sp421421+ eret422422+alternative_else_nop_endif428423#ifdef CONFIG_UNMAP_KERNEL_AT_EL0429424 bne 4f430430- msr far_el1, x30431431- tramp_alias x30, tramp_exit_native425425+ msr far_el1, x29426426+ tramp_alias x30, tramp_exit_native, x29432427 br x304334284:434434- tramp_alias x30, tramp_exit_compat429429+ tramp_alias x30, tramp_exit_compat, x29435430 br x30436431#endif437432 .else433433+ ldr lr, [sp, #S_LR]434434+ add sp, sp, #PT_REGS_SIZE // restore sp435435+438436 /* Ensure any device/NC reads complete */439437 alternative_insn nop, "dmb sy", ARM64_WORKAROUND_1508412440438···606594607595 .popsection // .entry.text608596609609-#ifdef CONFIG_UNMAP_KERNEL_AT_EL0610610-/*611611- * Exception vectors trampoline.612612- */613613- .pushsection ".entry.tramp.text", "ax"614614-615597 // Move from tramp_pg_dir to swapper_pg_dir616598 .macro tramp_map_kernel, tmp617599 mrs \tmp, ttbr1_el1···639633 */640634 .endm641635642642- .macro tramp_ventry, regsize = 64636636+ .macro tramp_data_page dst637637+ adr_l \dst, .entry.tramp.text638638+ sub \dst, \dst, PAGE_SIZE639639+ .endm640640+641641+ .macro tramp_data_read_var dst, var642642+#ifdef CONFIG_RANDOMIZE_BASE643643+ tramp_data_page \dst644644+ add \dst, \dst, #:lo12:__entry_tramp_data_\var645645+ ldr \dst, [\dst]646646+#else647647+ ldr \dst, =\var648648+#endif649649+ .endm650650+651651+#define BHB_MITIGATION_NONE 0652652+#define BHB_MITIGATION_LOOP 1653653+#define BHB_MITIGATION_FW 2654654+#define BHB_MITIGATION_INSN 3655655+656656+ .macro tramp_ventry, vector_start, regsize, kpti, bhb643657 .align 76446581:645659 .if \regsize == 64646660 msr tpidrro_el0, x30 // Restored in kernel_ventry647661 .endif662662+663663+ .if \bhb == BHB_MITIGATION_LOOP664664+ /*665665+ * This sequence must appear before the first indirect branch. i.e. the666666+ * ret out of tramp_ventry. It appears here because x30 is free.667667+ */668668+ __mitigate_spectre_bhb_loop x30669669+ .endif // \bhb == BHB_MITIGATION_LOOP670670+671671+ .if \bhb == BHB_MITIGATION_INSN672672+ clearbhb673673+ isb674674+ .endif // \bhb == BHB_MITIGATION_INSN675675+676676+ .if \kpti == 1648677 /*649678 * Defend against branch aliasing attacks by pushing a dummy650679 * entry onto the return stack and using a RET instruction to···689648 b .6906492:691650 tramp_map_kernel x30692692-#ifdef CONFIG_RANDOMIZE_BASE693693- adr x30, tramp_vectors + PAGE_SIZE694651alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003695695- ldr x30, [x30]696696-#else697697- ldr x30, =vectors698698-#endif652652+ tramp_data_read_var x30, vectors699653alternative_if_not ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM700700- prfm plil1strm, [x30, #(1b - tramp_vectors)]654654+ prfm plil1strm, [x30, #(1b - \vector_start)]701655alternative_else_nop_endif656656+702657 msr vbar_el1, x30703703- add x30, x30, #(1b - tramp_vectors)704658 isb659659+ .else660660+ ldr x30, =vectors661661+ .endif // \kpti == 1662662+663663+ .if \bhb == BHB_MITIGATION_FW664664+ /*665665+ * The firmware sequence must appear before the first indirect branch.666666+ * i.e. the ret out of tramp_ventry. But it also needs the stack to be667667+ * mapped to save/restore the registers the SMC clobbers.668668+ */669669+ __mitigate_spectre_bhb_fw670670+ .endif // \bhb == BHB_MITIGATION_FW671671+672672+ add x30, x30, #(1b - \vector_start + 4)705673 ret674674+.org 1b + 128 // Did we overflow the ventry slot?706675 .endm707676708677 .macro tramp_exit, regsize = 64709709- adr x30, tramp_vectors678678+ tramp_data_read_var x30, this_cpu_vector679679+ get_this_cpu_offset x29680680+ ldr x30, [x30, x29]681681+710682 msr vbar_el1, x30711711- tramp_unmap_kernel x30683683+ ldr lr, [sp, #S_LR]684684+ tramp_unmap_kernel x29712685 .if \regsize == 64713713- mrs x30, far_el1686686+ mrs x29, far_el1714687 .endif688688+ add sp, sp, #PT_REGS_SIZE // restore sp715689 eret716690 sb717691 .endm718692719719- .align 11720720-SYM_CODE_START_NOALIGN(tramp_vectors)693693+ .macro generate_tramp_vector, kpti, bhb694694+.Lvector_start\@:721695 .space 0x400722696723723- tramp_ventry724724- tramp_ventry725725- tramp_ventry726726- tramp_ventry697697+ .rept 4698698+ tramp_ventry .Lvector_start\@, 64, \kpti, \bhb699699+ .endr700700+ .rept 4701701+ tramp_ventry .Lvector_start\@, 32, \kpti, \bhb702702+ .endr703703+ .endm727704728728- tramp_ventry 32729729- tramp_ventry 32730730- tramp_ventry 32731731- tramp_ventry 32705705+#ifdef CONFIG_UNMAP_KERNEL_AT_EL0706706+/*707707+ * Exception vectors trampoline.708708+ * The order must match __bp_harden_el1_vectors and the709709+ * arm64_bp_harden_el1_vectors enum.710710+ */711711+ .pushsection ".entry.tramp.text", "ax"712712+ .align 11713713+SYM_CODE_START_NOALIGN(tramp_vectors)714714+#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY715715+ generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_LOOP716716+ generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_FW717717+ generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_INSN718718+#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */719719+ generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_NONE732720SYM_CODE_END(tramp_vectors)733721734722SYM_CODE_START(tramp_exit_native)···774704 .pushsection ".rodata", "a"775705 .align PAGE_SHIFT776706SYM_DATA_START(__entry_tramp_data_start)707707+__entry_tramp_data_vectors:777708 .quad vectors709709+#ifdef CONFIG_ARM_SDE_INTERFACE710710+__entry_tramp_data___sdei_asm_handler:711711+ .quad __sdei_asm_handler712712+#endif /* CONFIG_ARM_SDE_INTERFACE */713713+__entry_tramp_data_this_cpu_vector:714714+ .quad this_cpu_vector778715SYM_DATA_END(__entry_tramp_data_start)779716 .popsection // .rodata780717#endif /* CONFIG_RANDOMIZE_BASE */781718#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */719719+720720+/*721721+ * Exception vectors for spectre mitigations on entry from EL1 when722722+ * kpti is not in use.723723+ */724724+ .macro generate_el1_vector, bhb725725+.Lvector_start\@:726726+ kernel_ventry 1, t, 64, sync // Synchronous EL1t727727+ kernel_ventry 1, t, 64, irq // IRQ EL1t728728+ kernel_ventry 1, t, 64, fiq // FIQ EL1h729729+ kernel_ventry 1, t, 64, error // Error EL1t730730+731731+ kernel_ventry 1, h, 64, sync // Synchronous EL1h732732+ kernel_ventry 1, h, 64, irq // IRQ EL1h733733+ kernel_ventry 1, h, 64, fiq // FIQ EL1h734734+ kernel_ventry 1, h, 64, error // Error EL1h735735+736736+ .rept 4737737+ tramp_ventry .Lvector_start\@, 64, 0, \bhb738738+ .endr739739+ .rept 4740740+ tramp_ventry .Lvector_start\@, 32, 0, \bhb741741+ .endr742742+ .endm743743+744744+/* The order must match tramp_vecs and the arm64_bp_harden_el1_vectors enum. */745745+ .pushsection ".entry.text", "ax"746746+ .align 11747747+SYM_CODE_START(__bp_harden_el1_vectors)748748+#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY749749+ generate_el1_vector bhb=BHB_MITIGATION_LOOP750750+ generate_el1_vector bhb=BHB_MITIGATION_FW751751+ generate_el1_vector bhb=BHB_MITIGATION_INSN752752+#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */753753+SYM_CODE_END(__bp_harden_el1_vectors)754754+ .popsection755755+782756783757/*784758 * Register switch for AArch64. The callee-saved registers need to be saved···949835 * Remember whether to unmap the kernel on exit.950836 */9518371: str x4, [x1, #(SDEI_EVENT_INTREGS + S_SDEI_TTBR1)]952952-953953-#ifdef CONFIG_RANDOMIZE_BASE954954- adr x4, tramp_vectors + PAGE_SIZE955955- add x4, x4, #:lo12:__sdei_asm_trampoline_next_handler956956- ldr x4, [x4]957957-#else958958- ldr x4, =__sdei_asm_handler959959-#endif838838+ tramp_data_read_var x4, __sdei_asm_handler960839 br x4961840SYM_CODE_END(__sdei_asm_entry_trampoline)962841NOKPROBE(__sdei_asm_entry_trampoline)···972865NOKPROBE(__sdei_asm_exit_trampoline)973866 .ltorg974867.popsection // .entry.tramp.text975975-#ifdef CONFIG_RANDOMIZE_BASE976976-.pushsection ".rodata", "a"977977-SYM_DATA_START(__sdei_asm_trampoline_next_handler)978978- .quad __sdei_asm_handler979979-SYM_DATA_END(__sdei_asm_trampoline_next_handler)980980-.popsection // .rodata981981-#endif /* CONFIG_RANDOMIZE_BASE */982868#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */983869984870/*···1081981alternative_else_nop_endif10829821083983#ifdef CONFIG_UNMAP_KERNEL_AT_EL010841084- tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline984984+ tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x31085985 br x51086986#endif1087987SYM_CODE_END(__sdei_asm_handler)
+4
arch/arm64/kernel/image-vars.h
···6666KVM_NVHE_ALIAS(kvm_update_va_mask);6767KVM_NVHE_ALIAS(kvm_get_kimage_voffset);6868KVM_NVHE_ALIAS(kvm_compute_final_ctr_el0);6969+KVM_NVHE_ALIAS(spectre_bhb_patch_loop_iter);7070+KVM_NVHE_ALIAS(spectre_bhb_patch_loop_mitigation_enable);7171+KVM_NVHE_ALIAS(spectre_bhb_patch_wa3);7272+KVM_NVHE_ALIAS(spectre_bhb_patch_clearbhb);69737074/* Global kernel state accessed by nVHE hyp code. */7175KVM_NVHE_ALIAS(kvm_vgic_global_state);
+386-5
arch/arm64/kernel/proton-pack.c
···1818 */19192020#include <linux/arm-smccc.h>2121+#include <linux/bpf.h>2122#include <linux/cpu.h>2223#include <linux/device.h>2324#include <linux/nospec.h>2425#include <linux/prctl.h>2526#include <linux/sched/task_stack.h>26272828+#include <asm/debug-monitors.h>2729#include <asm/insn.h>2830#include <asm/spectre.h>2931#include <asm/traps.h>3232+#include <asm/vectors.h>3033#include <asm/virt.h>31343235/*···9996 return ret;10097}101989999+static const char *get_bhb_affected_string(enum mitigation_state bhb_state)100100+{101101+ switch (bhb_state) {102102+ case SPECTRE_UNAFFECTED:103103+ return "";104104+ default:105105+ case SPECTRE_VULNERABLE:106106+ return ", but not BHB";107107+ case SPECTRE_MITIGATED:108108+ return ", BHB";109109+ }110110+}111111+112112+static bool _unprivileged_ebpf_enabled(void)113113+{114114+#ifdef CONFIG_BPF_SYSCALL115115+ return !sysctl_unprivileged_bpf_disabled;116116+#else117117+ return false;118118+#endif119119+}120120+102121ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,103122 char *buf)104123{124124+ enum mitigation_state bhb_state = arm64_get_spectre_bhb_state();125125+ const char *bhb_str = get_bhb_affected_string(bhb_state);126126+ const char *v2_str = "Branch predictor hardening";127127+105128 switch (spectre_v2_state) {106129 case SPECTRE_UNAFFECTED:107107- return sprintf(buf, "Not affected\n");130130+ if (bhb_state == SPECTRE_UNAFFECTED)131131+ return sprintf(buf, "Not affected\n");132132+133133+ /*134134+ * Platforms affected by Spectre-BHB can't report135135+ * "Not affected" for Spectre-v2.136136+ */137137+ v2_str = "CSV2";138138+ fallthrough;108139 case SPECTRE_MITIGATED:109109- return sprintf(buf, "Mitigation: Branch predictor hardening\n");140140+ if (bhb_state == SPECTRE_MITIGATED && _unprivileged_ebpf_enabled())141141+ return sprintf(buf, "Vulnerable: Unprivileged eBPF enabled\n");142142+143143+ return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str);110144 case SPECTRE_VULNERABLE:111145 fallthrough;112146 default:···594554 * Patch a NOP in the Spectre-v4 mitigation code with an SMC/HVC instruction595555 * to call into firmware to adjust the mitigation state.596556 */597597-void __init spectre_v4_patch_fw_mitigation_conduit(struct alt_instr *alt,598598- __le32 *origptr,599599- __le32 *updptr, int nr_inst)557557+void __init smccc_patch_fw_mitigation_conduit(struct alt_instr *alt,558558+ __le32 *origptr,559559+ __le32 *updptr, int nr_inst)600560{601561 u32 insn;602562···810770 return -ENODEV;811771 }812772}773773+774774+/*775775+ * Spectre BHB.776776+ *777777+ * A CPU is either:778778+ * - Mitigated by a branchy loop a CPU specific number of times, and listed779779+ * in our "loop mitigated list".780780+ * - Mitigated in software by the firmware Spectre v2 call.781781+ * - Has the ClearBHB instruction to perform the mitigation.782782+ * - Has the 'Exception Clears Branch History Buffer' (ECBHB) feature, so no783783+ * software mitigation in the vectors is needed.784784+ * - Has CSV2.3, so is unaffected.785785+ */786786+static enum mitigation_state spectre_bhb_state;787787+788788+enum mitigation_state arm64_get_spectre_bhb_state(void)789789+{790790+ return spectre_bhb_state;791791+}792792+793793+enum bhb_mitigation_bits {794794+ BHB_LOOP,795795+ BHB_FW,796796+ BHB_HW,797797+ BHB_INSN,798798+};799799+static unsigned long system_bhb_mitigations;800800+801801+/*802802+ * This must be called with SCOPE_LOCAL_CPU for each type of CPU, before any803803+ * SCOPE_SYSTEM call will give the right answer.804804+ */805805+u8 spectre_bhb_loop_affected(int scope)806806+{807807+ u8 k = 0;808808+ static u8 max_bhb_k;809809+810810+ if (scope == SCOPE_LOCAL_CPU) {811811+ static const struct midr_range spectre_bhb_k32_list[] = {812812+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A78),813813+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A78C),814814+ MIDR_ALL_VERSIONS(MIDR_CORTEX_X1),815815+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A710),816816+ MIDR_ALL_VERSIONS(MIDR_CORTEX_X2),817817+ MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2),818818+ MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1),819819+ {},820820+ };821821+ static const struct midr_range spectre_bhb_k24_list[] = {822822+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A76),823823+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A77),824824+ MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1),825825+ {},826826+ };827827+ static const struct midr_range spectre_bhb_k8_list[] = {828828+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),829829+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),830830+ {},831831+ };832832+833833+ if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k32_list))834834+ k = 32;835835+ else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k24_list))836836+ k = 24;837837+ else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k8_list))838838+ k = 8;839839+840840+ max_bhb_k = max(max_bhb_k, k);841841+ } else {842842+ k = max_bhb_k;843843+ }844844+845845+ return k;846846+}847847+848848+static enum mitigation_state spectre_bhb_get_cpu_fw_mitigation_state(void)849849+{850850+ int ret;851851+ struct arm_smccc_res res;852852+853853+ arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,854854+ ARM_SMCCC_ARCH_WORKAROUND_3, &res);855855+856856+ ret = res.a0;857857+ switch (ret) {858858+ case SMCCC_RET_SUCCESS:859859+ return SPECTRE_MITIGATED;860860+ case SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED:861861+ return SPECTRE_UNAFFECTED;862862+ default:863863+ fallthrough;864864+ case SMCCC_RET_NOT_SUPPORTED:865865+ return SPECTRE_VULNERABLE;866866+ }867867+}868868+869869+static bool is_spectre_bhb_fw_affected(int scope)870870+{871871+ static bool system_affected;872872+ enum mitigation_state fw_state;873873+ bool has_smccc = arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_NONE;874874+ static const struct midr_range spectre_bhb_firmware_mitigated_list[] = {875875+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),876876+ MIDR_ALL_VERSIONS(MIDR_CORTEX_A75),877877+ {},878878+ };879879+ bool cpu_in_list = is_midr_in_range_list(read_cpuid_id(),880880+ spectre_bhb_firmware_mitigated_list);881881+882882+ if (scope != SCOPE_LOCAL_CPU)883883+ return system_affected;884884+885885+ fw_state = spectre_bhb_get_cpu_fw_mitigation_state();886886+ if (cpu_in_list || (has_smccc && fw_state == SPECTRE_MITIGATED)) {887887+ system_affected = true;888888+ return true;889889+ }890890+891891+ return false;892892+}893893+894894+static bool supports_ecbhb(int scope)895895+{896896+ u64 mmfr1;897897+898898+ if (scope == SCOPE_LOCAL_CPU)899899+ mmfr1 = read_sysreg_s(SYS_ID_AA64MMFR1_EL1);900900+ else901901+ mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);902902+903903+ return cpuid_feature_extract_unsigned_field(mmfr1,904904+ ID_AA64MMFR1_ECBHB_SHIFT);905905+}906906+907907+bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry,908908+ int scope)909909+{910910+ WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());911911+912912+ if (supports_csv2p3(scope))913913+ return false;914914+915915+ if (supports_clearbhb(scope))916916+ return true;917917+918918+ if (spectre_bhb_loop_affected(scope))919919+ return true;920920+921921+ if (is_spectre_bhb_fw_affected(scope))922922+ return true;923923+924924+ return false;925925+}926926+927927+static void this_cpu_set_vectors(enum arm64_bp_harden_el1_vectors slot)928928+{929929+ const char *v = arm64_get_bp_hardening_vector(slot);930930+931931+ if (slot < 0)932932+ return;933933+934934+ __this_cpu_write(this_cpu_vector, v);935935+936936+ /*937937+ * When KPTI is in use, the vectors are switched when exiting to938938+ * user-space.939939+ */940940+ if (arm64_kernel_unmapped_at_el0())941941+ return;942942+943943+ write_sysreg(v, vbar_el1);944944+ isb();945945+}946946+947947+void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *entry)948948+{949949+ bp_hardening_cb_t cpu_cb;950950+ enum mitigation_state fw_state, state = SPECTRE_VULNERABLE;951951+ struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data);952952+953953+ if (!is_spectre_bhb_affected(entry, SCOPE_LOCAL_CPU))954954+ return;955955+956956+ if (arm64_get_spectre_v2_state() == SPECTRE_VULNERABLE) {957957+ /* No point mitigating Spectre-BHB alone. */958958+ } else if (!IS_ENABLED(CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY)) {959959+ pr_info_once("spectre-bhb mitigation disabled by compile time option\n");960960+ } else if (cpu_mitigations_off()) {961961+ pr_info_once("spectre-bhb mitigation disabled by command line option\n");962962+ } else if (supports_ecbhb(SCOPE_LOCAL_CPU)) {963963+ state = SPECTRE_MITIGATED;964964+ set_bit(BHB_HW, &system_bhb_mitigations);965965+ } else if (supports_clearbhb(SCOPE_LOCAL_CPU)) {966966+ /*967967+ * Ensure KVM uses the indirect vector which will have ClearBHB968968+ * added.969969+ */970970+ if (!data->slot)971971+ data->slot = HYP_VECTOR_INDIRECT;972972+973973+ this_cpu_set_vectors(EL1_VECTOR_BHB_CLEAR_INSN);974974+ state = SPECTRE_MITIGATED;975975+ set_bit(BHB_INSN, &system_bhb_mitigations);976976+ } else if (spectre_bhb_loop_affected(SCOPE_LOCAL_CPU)) {977977+ /*978978+ * Ensure KVM uses the indirect vector which will have the979979+ * branchy-loop added. A57/A72-r0 will already have selected980980+ * the spectre-indirect vector, which is sufficient for BHB981981+ * too.982982+ */983983+ if (!data->slot)984984+ data->slot = HYP_VECTOR_INDIRECT;985985+986986+ this_cpu_set_vectors(EL1_VECTOR_BHB_LOOP);987987+ state = SPECTRE_MITIGATED;988988+ set_bit(BHB_LOOP, &system_bhb_mitigations);989989+ } else if (is_spectre_bhb_fw_affected(SCOPE_LOCAL_CPU)) {990990+ fw_state = spectre_bhb_get_cpu_fw_mitigation_state();991991+ if (fw_state == SPECTRE_MITIGATED) {992992+ /*993993+ * Ensure KVM uses one of the spectre bp_hardening994994+ * vectors. The indirect vector doesn't include the EL3995995+ * call, so needs upgrading to996996+ * HYP_VECTOR_SPECTRE_INDIRECT.997997+ */998998+ if (!data->slot || data->slot == HYP_VECTOR_INDIRECT)999999+ data->slot += 1;10001000+10011001+ this_cpu_set_vectors(EL1_VECTOR_BHB_FW);10021002+10031003+ /*10041004+ * The WA3 call in the vectors supersedes the WA1 call10051005+ * made during context-switch. Uninstall any firmware10061006+ * bp_hardening callback.10071007+ */10081008+ cpu_cb = spectre_v2_get_sw_mitigation_cb();10091009+ if (__this_cpu_read(bp_hardening_data.fn) != cpu_cb)10101010+ __this_cpu_write(bp_hardening_data.fn, NULL);10111011+10121012+ state = SPECTRE_MITIGATED;10131013+ set_bit(BHB_FW, &system_bhb_mitigations);10141014+ }10151015+ }10161016+10171017+ update_mitigation_state(&spectre_bhb_state, state);10181018+}10191019+10201020+/* Patched to NOP when enabled */10211021+void noinstr spectre_bhb_patch_loop_mitigation_enable(struct alt_instr *alt,10221022+ __le32 *origptr,10231023+ __le32 *updptr, int nr_inst)10241024+{10251025+ BUG_ON(nr_inst != 1);10261026+10271027+ if (test_bit(BHB_LOOP, &system_bhb_mitigations))10281028+ *updptr++ = cpu_to_le32(aarch64_insn_gen_nop());10291029+}10301030+10311031+/* Patched to NOP when enabled */10321032+void noinstr spectre_bhb_patch_fw_mitigation_enabled(struct alt_instr *alt,10331033+ __le32 *origptr,10341034+ __le32 *updptr, int nr_inst)10351035+{10361036+ BUG_ON(nr_inst != 1);10371037+10381038+ if (test_bit(BHB_FW, &system_bhb_mitigations))10391039+ *updptr++ = cpu_to_le32(aarch64_insn_gen_nop());10401040+}10411041+10421042+/* Patched to correct the immediate */10431043+void noinstr spectre_bhb_patch_loop_iter(struct alt_instr *alt,10441044+ __le32 *origptr, __le32 *updptr, int nr_inst)10451045+{10461046+ u8 rd;10471047+ u32 insn;10481048+ u16 loop_count = spectre_bhb_loop_affected(SCOPE_SYSTEM);10491049+10501050+ BUG_ON(nr_inst != 1); /* MOV -> MOV */10511051+10521052+ if (!IS_ENABLED(CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY))10531053+ return;10541054+10551055+ insn = le32_to_cpu(*origptr);10561056+ rd = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RD, insn);10571057+ insn = aarch64_insn_gen_movewide(rd, loop_count, 0,10581058+ AARCH64_INSN_VARIANT_64BIT,10591059+ AARCH64_INSN_MOVEWIDE_ZERO);10601060+ *updptr++ = cpu_to_le32(insn);10611061+}10621062+10631063+/* Patched to mov WA3 when supported */10641064+void noinstr spectre_bhb_patch_wa3(struct alt_instr *alt,10651065+ __le32 *origptr, __le32 *updptr, int nr_inst)10661066+{10671067+ u8 rd;10681068+ u32 insn;10691069+10701070+ BUG_ON(nr_inst != 1); /* MOV -> MOV */10711071+10721072+ if (!IS_ENABLED(CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY) ||10731073+ !test_bit(BHB_FW, &system_bhb_mitigations))10741074+ return;10751075+10761076+ insn = le32_to_cpu(*origptr);10771077+ rd = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RD, insn);10781078+10791079+ insn = aarch64_insn_gen_logical_immediate(AARCH64_INSN_LOGIC_ORR,10801080+ AARCH64_INSN_VARIANT_32BIT,10811081+ AARCH64_INSN_REG_ZR, rd,10821082+ ARM_SMCCC_ARCH_WORKAROUND_3);10831083+ if (WARN_ON_ONCE(insn == AARCH64_BREAK_FAULT))10841084+ return;10851085+10861086+ *updptr++ = cpu_to_le32(insn);10871087+}10881088+10891089+/* Patched to NOP when not supported */10901090+void __init spectre_bhb_patch_clearbhb(struct alt_instr *alt,10911091+ __le32 *origptr, __le32 *updptr, int nr_inst)10921092+{10931093+ BUG_ON(nr_inst != 2);10941094+10951095+ if (test_bit(BHB_INSN, &system_bhb_mitigations))10961096+ return;10971097+10981098+ *updptr++ = cpu_to_le32(aarch64_insn_gen_nop());10991099+ *updptr++ = cpu_to_le32(aarch64_insn_gen_nop());11001100+}11011101+11021102+#ifdef CONFIG_BPF_SYSCALL11031103+#define EBPF_WARN "Unprivileged eBPF is enabled, data leaks possible via Spectre v2 BHB attacks!\n"11041104+void unpriv_ebpf_notify(int new_state)11051105+{11061106+ if (spectre_v2_state == SPECTRE_VULNERABLE ||11071107+ spectre_bhb_state != SPECTRE_MITIGATED)11081108+ return;11091109+11101110+ if (!new_state)11111111+ pr_err("WARNING: %s", EBPF_WARN);11121112+}11131113+#endif
+1-1
arch/arm64/kernel/vmlinux.lds.S
···341341 <= SZ_4K, "Hibernate exit text too big or misaligned")342342#endif343343#ifdef CONFIG_UNMAP_KERNEL_AT_EL0344344-ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,344344+ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,345345 "Entry trampoline text too big")346346#endif347347#ifdef CONFIG_KVM
+1-4
arch/arm64/kvm/arm.c
···14911491 base = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs));14921492 kvm_init_vector_slot(base, HYP_VECTOR_SPECTRE_DIRECT);1493149314941494- if (!cpus_have_const_cap(ARM64_SPECTRE_V3A))14951495- return 0;14961496-14971497- if (!has_vhe()) {14941494+ if (kvm_system_needs_idmapped_vectors() && !has_vhe()) {14981495 err = create_hyp_exec_mappings(__pa_symbol(__bp_harden_hyp_vecs),14991496 __BP_HARDEN_HYP_VECS_SZ, &base);15001497 if (err)
···107107 break;108108 }109109 break;110110+ case ARM_SMCCC_ARCH_WORKAROUND_3:111111+ switch (arm64_get_spectre_bhb_state()) {112112+ case SPECTRE_VULNERABLE:113113+ break;114114+ case SPECTRE_MITIGATED:115115+ val[0] = SMCCC_RET_SUCCESS;116116+ break;117117+ case SPECTRE_UNAFFECTED:118118+ val[0] = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;119119+ break;120120+ }121121+ break;110122 case ARM_SMCCC_HV_PV_TIME_FEATURES:111123 val[0] = SMCCC_RET_SUCCESS;112124 break;
+18-3
arch/arm64/kvm/psci.c
···4646 * specification (ARM DEN 0022A). This means all suspend states4747 * for KVM will preserve the register state.4848 */4949- kvm_vcpu_halt(vcpu);5050- kvm_clear_request(KVM_REQ_UNHALT, vcpu);4949+ kvm_vcpu_wfi(vcpu);51505251 return PSCI_RET_SUCCESS;5352}···405406406407int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu)407408{408408- return 3; /* PSCI version and two workaround registers */409409+ return 4; /* PSCI version and three workaround registers */409410}410411411412int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)···417418 return -EFAULT;418419419420 if (put_user(KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, uindices++))421421+ return -EFAULT;422422+423423+ if (put_user(KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3, uindices++))420424 return -EFAULT;421425422426 return 0;···461459 case SPECTRE_VULNERABLE:462460 return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL;463461 }462462+ break;463463+ case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3:464464+ switch (arm64_get_spectre_bhb_state()) {465465+ case SPECTRE_VULNERABLE:466466+ return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL;467467+ case SPECTRE_MITIGATED:468468+ return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_AVAIL;469469+ case SPECTRE_UNAFFECTED:470470+ return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_REQUIRED;471471+ }472472+ return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL;464473 }465474466475 return -EINVAL;···488475 break;489476 case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1:490477 case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2:478478+ case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3:491479 val = get_kernel_wa_level(reg->id) & KVM_REG_FEATURE_LEVEL_MASK;492480 break;493481 default:···534520 }535521536522 case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1:523523+ case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3:537524 if (val & ~KVM_REG_FEATURE_LEVEL_MASK)538525 return -EINVAL;539526
+17
arch/arm64/mm/mmap.c
···7788#include <linux/io.h>99#include <linux/memblock.h>1010+#include <linux/mm.h>1011#include <linux/types.h>11121313+#include <asm/cpufeature.h>1214#include <asm/page.h>13151416/*···4038{4139 return !(((pfn << PAGE_SHIFT) + size) & ~PHYS_MASK);4240}4141+4242+static int __init adjust_protection_map(void)4343+{4444+ /*4545+ * With Enhanced PAN we can honour the execute-only permissions as4646+ * there is no PAN override with such mappings.4747+ */4848+ if (cpus_have_const_cap(ARM64_HAS_EPAN)) {4949+ protection_map[VM_EXEC] = PAGE_EXECONLY;5050+ protection_map[VM_EXEC | VM_SHARED] = PAGE_EXECONLY;5151+ }5252+5353+ return 0;5454+}5555+arch_initcall(adjust_protection_map);
+9-3
arch/arm64/mm/mmu.c
···617617#ifdef CONFIG_UNMAP_KERNEL_AT_EL0618618static int __init map_entry_trampoline(void)619619{620620+ int i;621621+620622 pgprot_t prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;621623 phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start);622624···627625628626 /* Map only the text into the trampoline page table */629627 memset(tramp_pg_dir, 0, PGD_SIZE);630630- __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE,631631- prot, __pgd_pgtable_alloc, 0);628628+ __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS,629629+ entry_tramp_text_size(), prot,630630+ __pgd_pgtable_alloc, NO_BLOCK_MAPPINGS);632631633632 /* Map both the text and data into the kernel page table */634634- __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot);633633+ for (i = 0; i < DIV_ROUND_UP(entry_tramp_text_size(), PAGE_SIZE); i++)634634+ __set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i,635635+ pa_start + i * PAGE_SIZE, prot);636636+635637 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {636638 extern char __entry_tramp_data_start[];637639
···351351 cpu = smp_processor_id();352352 cpu_data[cpu].udelay_val = loops_per_jiffy;353353354354+ set_cpu_sibling_map(cpu);355355+ set_cpu_core_map(cpu);356356+354357 cpumask_set_cpu(cpu, &cpu_coherent_mask);355358 notify_cpu_starting(cpu);356359···364361365362 /* The CPU is running and counters synchronised, now mark it online */366363 set_cpu_online(cpu, true);367367-368368- set_cpu_sibling_map(cpu);369369- set_cpu_core_map(cpu);370364371365 calculate_cpu_foreign_map();372366
···202202/*203203 * The current system page and segment sizes204204 */205205-extern int mmu_linear_psize;206205extern int mmu_virtual_psize;207206extern int mmu_vmalloc_psize;208207extern int mmu_io_psize;···212213#define mmu_virtual_psize MMU_PAGE_4K213214#endif214215#endif216216+extern int mmu_linear_psize;215217extern int mmu_vmemmap_psize;216218217219/* MMU initialization */
···2233config RISCV_ERRATA_ALTERNATIVE44 bool "RISC-V alternative scheme"55+ depends on !XIP_KERNEL56 default y67 help78 This Kconfig allows the kernel to automatically patch the
+2-2
arch/riscv/Kconfig.socs
···1414 select CLK_SIFIVE1515 select CLK_SIFIVE_PRCI1616 select SIFIVE_PLIC1717- select RISCV_ERRATA_ALTERNATIVE1818- select ERRATA_SIFIVE1717+ select RISCV_ERRATA_ALTERNATIVE if !XIP_KERNEL1818+ select ERRATA_SIFIVE if !XIP_KERNEL1919 help2020 This enables support for SiFive SoC platform hardware.2121
···389389 *390390 * CALL *%\reg391391 *392392- * It also tries to inline spectre_v2=retpoline,amd when size permits.392392+ * It also tries to inline spectre_v2=retpoline,lfence when size permits.393393 */394394static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)395395{···407407 BUG_ON(reg == 4);408408409409 if (cpu_feature_enabled(X86_FEATURE_RETPOLINE) &&410410- !cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD))410410+ !cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE))411411 return -1;412412413413 op = insn->opcode.bytes[0];···438438 }439439440440 /*441441- * For RETPOLINE_AMD: prepend the indirect CALL/JMP with an LFENCE.441441+ * For RETPOLINE_LFENCE: prepend the indirect CALL/JMP with an LFENCE.442442 */443443- if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {443443+ if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {444444 bytes[i++] = 0x0f;445445 bytes[i++] = 0xae;446446 bytes[i++] = 0xe8; /* LFENCE */
+157-49
arch/x86/kernel/cpu/bugs.c
···1616#include <linux/prctl.h>1717#include <linux/sched/smt.h>1818#include <linux/pgtable.h>1919+#include <linux/bpf.h>19202021#include <asm/spec-ctrl.h>2122#include <asm/cmdline.h>···651650static inline const char *spectre_v2_module_string(void) { return ""; }652651#endif653652653653+#define SPECTRE_V2_LFENCE_MSG "WARNING: LFENCE mitigation is not recommended for this CPU, data leaks possible!\n"654654+#define SPECTRE_V2_EIBRS_EBPF_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!\n"655655+#define SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS+LFENCE mitigation and SMT, data leaks possible via Spectre v2 BHB attacks!\n"656656+657657+#ifdef CONFIG_BPF_SYSCALL658658+void unpriv_ebpf_notify(int new_state)659659+{660660+ if (new_state)661661+ return;662662+663663+ /* Unprivileged eBPF is enabled */664664+665665+ switch (spectre_v2_enabled) {666666+ case SPECTRE_V2_EIBRS:667667+ pr_err(SPECTRE_V2_EIBRS_EBPF_MSG);668668+ break;669669+ case SPECTRE_V2_EIBRS_LFENCE:670670+ if (sched_smt_active())671671+ pr_err(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);672672+ break;673673+ default:674674+ break;675675+ }676676+}677677+#endif678678+654679static inline bool match_option(const char *arg, int arglen, const char *opt)655680{656681 int len = strlen(opt);···691664 SPECTRE_V2_CMD_FORCE,692665 SPECTRE_V2_CMD_RETPOLINE,693666 SPECTRE_V2_CMD_RETPOLINE_GENERIC,694694- SPECTRE_V2_CMD_RETPOLINE_AMD,667667+ SPECTRE_V2_CMD_RETPOLINE_LFENCE,668668+ SPECTRE_V2_CMD_EIBRS,669669+ SPECTRE_V2_CMD_EIBRS_RETPOLINE,670670+ SPECTRE_V2_CMD_EIBRS_LFENCE,695671};696672697673enum spectre_v2_user_cmd {···767737 return SPECTRE_V2_USER_CMD_AUTO;768738}769739740740+static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)741741+{742742+ return (mode == SPECTRE_V2_EIBRS ||743743+ mode == SPECTRE_V2_EIBRS_RETPOLINE ||744744+ mode == SPECTRE_V2_EIBRS_LFENCE);745745+}746746+770747static void __init771748spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)772749{···841804 */842805 if (!boot_cpu_has(X86_FEATURE_STIBP) ||843806 !smt_possible ||844844- spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)807807+ spectre_v2_in_eibrs_mode(spectre_v2_enabled))845808 return;846809847810 /*···861824862825static const char * const spectre_v2_strings[] = {863826 [SPECTRE_V2_NONE] = "Vulnerable",864864- [SPECTRE_V2_RETPOLINE_GENERIC] = "Mitigation: Full generic retpoline",865865- [SPECTRE_V2_RETPOLINE_AMD] = "Mitigation: Full AMD retpoline",866866- [SPECTRE_V2_IBRS_ENHANCED] = "Mitigation: Enhanced IBRS",827827+ [SPECTRE_V2_RETPOLINE] = "Mitigation: Retpolines",828828+ [SPECTRE_V2_LFENCE] = "Mitigation: LFENCE",829829+ [SPECTRE_V2_EIBRS] = "Mitigation: Enhanced IBRS",830830+ [SPECTRE_V2_EIBRS_LFENCE] = "Mitigation: Enhanced IBRS + LFENCE",831831+ [SPECTRE_V2_EIBRS_RETPOLINE] = "Mitigation: Enhanced IBRS + Retpolines",867832};868833869834static const struct {···876837 { "off", SPECTRE_V2_CMD_NONE, false },877838 { "on", SPECTRE_V2_CMD_FORCE, true },878839 { "retpoline", SPECTRE_V2_CMD_RETPOLINE, false },879879- { "retpoline,amd", SPECTRE_V2_CMD_RETPOLINE_AMD, false },840840+ { "retpoline,amd", SPECTRE_V2_CMD_RETPOLINE_LFENCE, false },841841+ { "retpoline,lfence", SPECTRE_V2_CMD_RETPOLINE_LFENCE, false },880842 { "retpoline,generic", SPECTRE_V2_CMD_RETPOLINE_GENERIC, false },843843+ { "eibrs", SPECTRE_V2_CMD_EIBRS, false },844844+ { "eibrs,lfence", SPECTRE_V2_CMD_EIBRS_LFENCE, false },845845+ { "eibrs,retpoline", SPECTRE_V2_CMD_EIBRS_RETPOLINE, false },881846 { "auto", SPECTRE_V2_CMD_AUTO, false },882847};883848···918875 }919876920877 if ((cmd == SPECTRE_V2_CMD_RETPOLINE ||921921- cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||922922- cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) &&878878+ cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||879879+ cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ||880880+ cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||881881+ cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&923882 !IS_ENABLED(CONFIG_RETPOLINE)) {924924- pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option);883883+ pr_err("%s selected but not compiled in. Switching to AUTO select\n",884884+ mitigation_options[i].option);885885+ return SPECTRE_V2_CMD_AUTO;886886+ }887887+888888+ if ((cmd == SPECTRE_V2_CMD_EIBRS ||889889+ cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||890890+ cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&891891+ !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {892892+ pr_err("%s selected but CPU doesn't have eIBRS. Switching to AUTO select\n",893893+ mitigation_options[i].option);894894+ return SPECTRE_V2_CMD_AUTO;895895+ }896896+897897+ if ((cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||898898+ cmd == SPECTRE_V2_CMD_EIBRS_LFENCE) &&899899+ !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {900900+ pr_err("%s selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n",901901+ mitigation_options[i].option);925902 return SPECTRE_V2_CMD_AUTO;926903 }927904928905 spec_v2_print_cond(mitigation_options[i].option,929906 mitigation_options[i].secure);930907 return cmd;908908+}909909+910910+static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void)911911+{912912+ if (!IS_ENABLED(CONFIG_RETPOLINE)) {913913+ pr_err("Kernel not compiled with retpoline; no mitigation available!");914914+ return SPECTRE_V2_NONE;915915+ }916916+917917+ return SPECTRE_V2_RETPOLINE;931918}932919933920static void __init spectre_v2_select_mitigation(void)···980907 case SPECTRE_V2_CMD_FORCE:981908 case SPECTRE_V2_CMD_AUTO:982909 if (boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {983983- mode = SPECTRE_V2_IBRS_ENHANCED;984984- /* Force it so VMEXIT will restore correctly */985985- x86_spec_ctrl_base |= SPEC_CTRL_IBRS;986986- wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);987987- goto specv2_set_mode;910910+ mode = SPECTRE_V2_EIBRS;911911+ break;988912 }989989- if (IS_ENABLED(CONFIG_RETPOLINE))990990- goto retpoline_auto;913913+914914+ mode = spectre_v2_select_retpoline();991915 break;992992- case SPECTRE_V2_CMD_RETPOLINE_AMD:993993- if (IS_ENABLED(CONFIG_RETPOLINE))994994- goto retpoline_amd;916916+917917+ case SPECTRE_V2_CMD_RETPOLINE_LFENCE:918918+ pr_err(SPECTRE_V2_LFENCE_MSG);919919+ mode = SPECTRE_V2_LFENCE;995920 break;921921+996922 case SPECTRE_V2_CMD_RETPOLINE_GENERIC:997997- if (IS_ENABLED(CONFIG_RETPOLINE))998998- goto retpoline_generic;923923+ mode = SPECTRE_V2_RETPOLINE;999924 break;925925+1000926 case SPECTRE_V2_CMD_RETPOLINE:10011001- if (IS_ENABLED(CONFIG_RETPOLINE))10021002- goto retpoline_auto;927927+ mode = spectre_v2_select_retpoline();928928+ break;929929+930930+ case SPECTRE_V2_CMD_EIBRS:931931+ mode = SPECTRE_V2_EIBRS;932932+ break;933933+934934+ case SPECTRE_V2_CMD_EIBRS_LFENCE:935935+ mode = SPECTRE_V2_EIBRS_LFENCE;936936+ break;937937+938938+ case SPECTRE_V2_CMD_EIBRS_RETPOLINE:939939+ mode = SPECTRE_V2_EIBRS_RETPOLINE;1003940 break;1004941 }10051005- pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!");10061006- return;100794210081008-retpoline_auto:10091009- if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||10101010- boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {10111011- retpoline_amd:10121012- if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {10131013- pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");10141014- goto retpoline_generic;10151015- }10161016- mode = SPECTRE_V2_RETPOLINE_AMD;10171017- setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD);10181018- setup_force_cpu_cap(X86_FEATURE_RETPOLINE);10191019- } else {10201020- retpoline_generic:10211021- mode = SPECTRE_V2_RETPOLINE_GENERIC;10221022- setup_force_cpu_cap(X86_FEATURE_RETPOLINE);943943+ if (mode == SPECTRE_V2_EIBRS && unprivileged_ebpf_enabled())944944+ pr_err(SPECTRE_V2_EIBRS_EBPF_MSG);945945+946946+ if (spectre_v2_in_eibrs_mode(mode)) {947947+ /* Force it so VMEXIT will restore correctly */948948+ x86_spec_ctrl_base |= SPEC_CTRL_IBRS;949949+ wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);1023950 }102495110251025-specv2_set_mode:952952+ switch (mode) {953953+ case SPECTRE_V2_NONE:954954+ case SPECTRE_V2_EIBRS:955955+ break;956956+957957+ case SPECTRE_V2_LFENCE:958958+ case SPECTRE_V2_EIBRS_LFENCE:959959+ setup_force_cpu_cap(X86_FEATURE_RETPOLINE_LFENCE);960960+ fallthrough;961961+962962+ case SPECTRE_V2_RETPOLINE:963963+ case SPECTRE_V2_EIBRS_RETPOLINE:964964+ setup_force_cpu_cap(X86_FEATURE_RETPOLINE);965965+ break;966966+ }967967+1026968 spectre_v2_enabled = mode;1027969 pr_info("%s\n", spectre_v2_strings[mode]);1028970···1063975 * the CPU supports Enhanced IBRS, kernel might un-intentionally not1064976 * enable IBRS around firmware calls.1065977 */10661066- if (boot_cpu_has(X86_FEATURE_IBRS) && mode != SPECTRE_V2_IBRS_ENHANCED) {978978+ if (boot_cpu_has(X86_FEATURE_IBRS) && !spectre_v2_in_eibrs_mode(mode)) {1067979 setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW);1068980 pr_info("Enabling Restricted Speculation for firmware calls\n");1069981 }···11321044void cpu_bugs_smt_update(void)11331045{11341046 mutex_lock(&spec_ctrl_mutex);10471047+10481048+ if (sched_smt_active() && unprivileged_ebpf_enabled() &&10491049+ spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)10501050+ pr_warn_once(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);1135105111361052 switch (spectre_v2_user_stibp) {11371053 case SPECTRE_V2_USER_NONE:···1776168417771685static char *stibp_state(void)17781686{17791779- if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)16871687+ if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))17801688 return "";1781168917821690 switch (spectre_v2_user_stibp) {···18061714 return "";18071715}1808171617171717+static ssize_t spectre_v2_show_state(char *buf)17181718+{17191719+ if (spectre_v2_enabled == SPECTRE_V2_LFENCE)17201720+ return sprintf(buf, "Vulnerable: LFENCE\n");17211721+17221722+ if (spectre_v2_enabled == SPECTRE_V2_EIBRS && unprivileged_ebpf_enabled())17231723+ return sprintf(buf, "Vulnerable: eIBRS with unprivileged eBPF\n");17241724+17251725+ if (sched_smt_active() && unprivileged_ebpf_enabled() &&17261726+ spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)17271727+ return sprintf(buf, "Vulnerable: eIBRS+LFENCE with unprivileged eBPF and SMT\n");17281728+17291729+ return sprintf(buf, "%s%s%s%s%s%s\n",17301730+ spectre_v2_strings[spectre_v2_enabled],17311731+ ibpb_state(),17321732+ boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",17331733+ stibp_state(),17341734+ boot_cpu_has(X86_FEATURE_RSB_CTXSW) ? ", RSB filling" : "",17351735+ spectre_v2_module_string());17361736+}17371737+18091738static ssize_t srbds_show_state(char *buf)18101739{18111740 return sprintf(buf, "%s\n", srbds_strings[srbds_mitigation]);···18521739 return sprintf(buf, "%s\n", spectre_v1_strings[spectre_v1_mitigation]);1853174018541741 case X86_BUG_SPECTRE_V2:18551855- return sprintf(buf, "%s%s%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],18561856- ibpb_state(),18571857- boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",18581858- stibp_state(),18591859- boot_cpu_has(X86_FEATURE_RSB_CTXSW) ? ", RSB filling" : "",18601860- spectre_v2_module_string());17421742+ return spectre_v2_show_state(buf);1861174318621744 case X86_BUG_SPEC_STORE_BYPASS:18631745 return sprintf(buf, "%s\n", ssb_strings[ssb_mode]);
+48-9
arch/x86/kernel/cpu/sgx/encl.c
···1313#include "sgx.h"14141515/*1616+ * Calculate byte offset of a PCMD struct associated with an enclave page. PCMD's1717+ * follow right after the EPC data in the backing storage. In addition to the1818+ * visible enclave pages, there's one extra page slot for SECS, before PCMD1919+ * structs.2020+ */2121+static inline pgoff_t sgx_encl_get_backing_page_pcmd_offset(struct sgx_encl *encl,2222+ unsigned long page_index)2323+{2424+ pgoff_t epc_end_off = encl->size + sizeof(struct sgx_secs);2525+2626+ return epc_end_off + page_index * sizeof(struct sgx_pcmd);2727+}2828+2929+/*3030+ * Free a page from the backing storage in the given page index.3131+ */3232+static inline void sgx_encl_truncate_backing_page(struct sgx_encl *encl, unsigned long page_index)3333+{3434+ struct inode *inode = file_inode(encl->backing);3535+3636+ shmem_truncate_range(inode, PFN_PHYS(page_index), PFN_PHYS(page_index) + PAGE_SIZE - 1);3737+}3838+3939+/*1640 * ELDU: Load an EPC page as unblocked. For more info, see "OS Management of EPC1741 * Pages" in the SDM.1842 */···4622{4723 unsigned long va_offset = encl_page->desc & SGX_ENCL_PAGE_VA_OFFSET_MASK;4824 struct sgx_encl *encl = encl_page->encl;2525+ pgoff_t page_index, page_pcmd_off;4926 struct sgx_pageinfo pginfo;5027 struct sgx_backing b;5151- pgoff_t page_index;2828+ bool pcmd_page_empty;2929+ u8 *pcmd_page;5230 int ret;53315432 if (secs_page)···5832 else5933 page_index = PFN_DOWN(encl->size);60343535+ page_pcmd_off = sgx_encl_get_backing_page_pcmd_offset(encl, page_index);3636+6137 ret = sgx_encl_get_backing(encl, page_index, &b);6238 if (ret)6339 return ret;64406541 pginfo.addr = encl_page->desc & PAGE_MASK;6642 pginfo.contents = (unsigned long)kmap_atomic(b.contents);6767- pginfo.metadata = (unsigned long)kmap_atomic(b.pcmd) +6868- b.pcmd_offset;4343+ pcmd_page = kmap_atomic(b.pcmd);4444+ pginfo.metadata = (unsigned long)pcmd_page + b.pcmd_offset;69457046 if (secs_page)7147 pginfo.secs = (u64)sgx_get_epc_virt_addr(secs_page);···8355 ret = -EFAULT;8456 }85578686- kunmap_atomic((void *)(unsigned long)(pginfo.metadata - b.pcmd_offset));5858+ memset(pcmd_page + b.pcmd_offset, 0, sizeof(struct sgx_pcmd));5959+6060+ /*6161+ * The area for the PCMD in the page was zeroed above. Check if the6262+ * whole page is now empty meaning that all PCMD's have been zeroed:6363+ */6464+ pcmd_page_empty = !memchr_inv(pcmd_page, 0, PAGE_SIZE);6565+6666+ kunmap_atomic(pcmd_page);8767 kunmap_atomic((void *)(unsigned long)pginfo.contents);88688969 sgx_encl_put_backing(&b, false);7070+7171+ sgx_encl_truncate_backing_page(encl, page_index);7272+7373+ if (pcmd_page_empty)7474+ sgx_encl_truncate_backing_page(encl, PFN_DOWN(page_pcmd_off));90759176 return ret;9277}···620579int sgx_encl_get_backing(struct sgx_encl *encl, unsigned long page_index,621580 struct sgx_backing *backing)622581{623623- pgoff_t pcmd_index = PFN_DOWN(encl->size) + 1 + (page_index >> 5);582582+ pgoff_t page_pcmd_off = sgx_encl_get_backing_page_pcmd_offset(encl, page_index);624583 struct page *contents;625584 struct page *pcmd;626585···628587 if (IS_ERR(contents))629588 return PTR_ERR(contents);630589631631- pcmd = sgx_encl_get_backing_page(encl, pcmd_index);590590+ pcmd = sgx_encl_get_backing_page(encl, PFN_DOWN(page_pcmd_off));632591 if (IS_ERR(pcmd)) {633592 put_page(contents);634593 return PTR_ERR(pcmd);···637596 backing->page_index = page_index;638597 backing->contents = contents;639598 backing->pcmd = pcmd;640640- backing->pcmd_offset =641641- (page_index & (PAGE_SIZE / sizeof(struct sgx_pcmd) - 1)) *642642- sizeof(struct sgx_pcmd);599599+ backing->pcmd_offset = page_pcmd_off & (PAGE_SIZE - 1);643600644601 return 0;645602}
···91919292static int __init get_setup_data_size(int nr, size_t *size)9393{9494- int i = 0;9494+ u64 pa_data = boot_params.hdr.setup_data, pa_next;9595+ struct setup_indirect *indirect;9596 struct setup_data *data;9696- u64 pa_data = boot_params.hdr.setup_data;9797+ int i = 0;9898+ u32 len;979998100 while (pa_data) {99101 data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);100102 if (!data)101103 return -ENOMEM;104104+ pa_next = data->next;105105+102106 if (nr == i) {103103- if (data->type == SETUP_INDIRECT &&104104- ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT)105105- *size = ((struct setup_indirect *)data->data)->len;106106- else107107+ if (data->type == SETUP_INDIRECT) {108108+ len = sizeof(*data) + data->len;109109+ memunmap(data);110110+ data = memremap(pa_data, len, MEMREMAP_WB);111111+ if (!data)112112+ return -ENOMEM;113113+114114+ indirect = (struct setup_indirect *)data->data;115115+116116+ if (indirect->type != SETUP_INDIRECT)117117+ *size = indirect->len;118118+ else119119+ *size = data->len;120120+ } else {107121 *size = data->len;122122+ }108123109124 memunmap(data);110125 return 0;111126 }112127113113- pa_data = data->next;128128+ pa_data = pa_next;114129 memunmap(data);115130 i++;116131 }···135120static ssize_t type_show(struct kobject *kobj,136121 struct kobj_attribute *attr, char *buf)137122{123123+ struct setup_indirect *indirect;124124+ struct setup_data *data;138125 int nr, ret;139126 u64 paddr;140140- struct setup_data *data;127127+ u32 len;141128142129 ret = kobj_to_setup_data_nr(kobj, &nr);143130 if (ret)···152135 if (!data)153136 return -ENOMEM;154137155155- if (data->type == SETUP_INDIRECT)156156- ret = sprintf(buf, "0x%x\n", ((struct setup_indirect *)data->data)->type);157157- else138138+ if (data->type == SETUP_INDIRECT) {139139+ len = sizeof(*data) + data->len;140140+ memunmap(data);141141+ data = memremap(paddr, len, MEMREMAP_WB);142142+ if (!data)143143+ return -ENOMEM;144144+145145+ indirect = (struct setup_indirect *)data->data;146146+147147+ ret = sprintf(buf, "0x%x\n", indirect->type);148148+ } else {158149 ret = sprintf(buf, "0x%x\n", data->type);150150+ }151151+159152 memunmap(data);160153 return ret;161154}···176149 char *buf,177150 loff_t off, size_t count)178151{152152+ struct setup_indirect *indirect;153153+ struct setup_data *data;179154 int nr, ret = 0;180155 u64 paddr, len;181181- struct setup_data *data;182156 void *p;183157184158 ret = kobj_to_setup_data_nr(kobj, &nr);···193165 if (!data)194166 return -ENOMEM;195167196196- if (data->type == SETUP_INDIRECT &&197197- ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) {198198- paddr = ((struct setup_indirect *)data->data)->addr;199199- len = ((struct setup_indirect *)data->data)->len;168168+ if (data->type == SETUP_INDIRECT) {169169+ len = sizeof(*data) + data->len;170170+ memunmap(data);171171+ data = memremap(paddr, len, MEMREMAP_WB);172172+ if (!data)173173+ return -ENOMEM;174174+175175+ indirect = (struct setup_indirect *)data->data;176176+177177+ if (indirect->type != SETUP_INDIRECT) {178178+ paddr = indirect->addr;179179+ len = indirect->len;180180+ } else {181181+ /*182182+ * Even though this is technically undefined, return183183+ * the data as though it is a normal setup_data struct.184184+ * This will at least allow it to be inspected.185185+ */186186+ paddr += sizeof(*data);187187+ len = data->len;188188+ }200189 } else {201190 paddr += sizeof(*data);202191 len = data->len;
+3-1
arch/x86/kernel/kvm.c
···463463 return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&464464 !kvm_para_has_hint(KVM_HINTS_REALTIME) &&465465 kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&466466+ !boot_cpu_has(X86_FEATURE_MWAIT) &&466467 (num_possible_cpus() != 1));467468}468469···478477 return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&479478 !kvm_para_has_hint(KVM_HINTS_REALTIME) &&480479 kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&480480+ !boot_cpu_has(X86_FEATURE_MWAIT) &&481481 (num_possible_cpus() != 1));482482}483483···624622625623 /* Make sure other vCPUs get a chance to run if they need to. */626624 for_each_cpu(cpu, mask) {627627- if (vcpu_is_preempted(cpu)) {625625+ if (!idle_cpu(cpu) && vcpu_is_preempted(cpu)) {628626 kvm_hypercall1(KVM_HC_SCHED_YIELD, per_cpu(x86_cpu_to_apicid, cpu));629627 break;630628 }
+3
arch/x86/kernel/kvmclock.c
···239239240240static int __init kvm_setup_vsyscall_timeinfo(void)241241{242242+ if (!kvm_para_available() || !kvmclock)243243+ return 0;244244+242245 kvmclock_init_mem();243246244247#ifdef CONFIG_X86_64
+8-5
arch/x86/kernel/module.c
···273273 retpolines = s;274274 }275275276276+ /*277277+ * See alternative_instructions() for the ordering rules between the278278+ * various patching types.279279+ */280280+ if (para) {281281+ void *pseg = (void *)para->sh_addr;282282+ apply_paravirt(pseg, pseg + para->sh_size);283283+ }276284 if (retpolines) {277285 void *rseg = (void *)retpolines->sh_addr;278286 apply_retpolines(rseg, rseg + retpolines->sh_size);···296288 alternatives_smp_module_add(me, me->name,297289 lseg, lseg + locks->sh_size,298290 tseg, tseg + text->sh_size);299299- }300300-301301- if (para) {302302- void *pseg = (void *)para->sh_addr;303303- apply_paravirt(pseg, pseg + para->sh_size);304291 }305292306293 /* make jump label nops */
+27-7
arch/x86/kernel/setup.c
···369369370370static void __init memblock_x86_reserve_range_setup_data(void)371371{372372+ struct setup_indirect *indirect;372373 struct setup_data *data;373373- u64 pa_data;374374+ u64 pa_data, pa_next;375375+ u32 len;374376375377 pa_data = boot_params.hdr.setup_data;376378 while (pa_data) {377379 data = early_memremap(pa_data, sizeof(*data));380380+ if (!data) {381381+ pr_warn("setup: failed to memremap setup_data entry\n");382382+ return;383383+ }384384+385385+ len = sizeof(*data);386386+ pa_next = data->next;387387+378388 memblock_reserve(pa_data, sizeof(*data) + data->len);379389380380- if (data->type == SETUP_INDIRECT &&381381- ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT)382382- memblock_reserve(((struct setup_indirect *)data->data)->addr,383383- ((struct setup_indirect *)data->data)->len);390390+ if (data->type == SETUP_INDIRECT) {391391+ len += data->len;392392+ early_memunmap(data, sizeof(*data));393393+ data = early_memremap(pa_data, len);394394+ if (!data) {395395+ pr_warn("setup: failed to memremap indirect setup_data\n");396396+ return;397397+ }384398385385- pa_data = data->next;386386- early_memunmap(data, sizeof(*data));399399+ indirect = (struct setup_indirect *)data->data;400400+401401+ if (indirect->type != SETUP_INDIRECT)402402+ memblock_reserve(indirect->addr, indirect->len);403403+ }404404+405405+ pa_data = pa_next;406406+ early_memunmap(data, len);387407 }388408}389409
···246246 src = &prev->host_state;247247 dest = &vmx->loaded_vmcs->host_state;248248249249- vmx_set_vmcs_host_state(dest, src->cr3, src->fs_sel, src->gs_sel,250250- src->fs_base, src->gs_base);249249+ vmx_set_host_fs_gs(dest, src->fs_sel, src->gs_sel, src->fs_base, src->gs_base);251250 dest->ldt_sel = src->ldt_sel;252251#ifdef CONFIG_X86_64253252 dest->ds_sel = src->ds_sel;···30553056static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)30563057{30573058 struct vcpu_vmx *vmx = to_vmx(vcpu);30583058- unsigned long cr4;30593059+ unsigned long cr3, cr4;30593060 bool vm_fail;3060306130613062 if (!nested_early_check)···30773078 * there is no need to preserve other bits or save/restore the field.30783079 */30793080 vmcs_writel(GUEST_RFLAGS, 0);30813081+30823082+ cr3 = __get_current_cr3_fast();30833083+ if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) {30843084+ vmcs_writel(HOST_CR3, cr3);30853085+ vmx->loaded_vmcs->host_state.cr3 = cr3;30863086+ }3080308730813088 cr4 = cr4_read_shadow();30823089 if (unlikely(cr4 != vmx->loaded_vmcs->host_state.cr4)) {
+17-11
arch/x86/kvm/vmx/vmx.c
···10801080 wrmsrl(MSR_IA32_RTIT_CTL, vmx->pt_desc.host.ctl);10811081}1082108210831083-void vmx_set_vmcs_host_state(struct vmcs_host_state *host, unsigned long cr3,10841084- u16 fs_sel, u16 gs_sel,10851085- unsigned long fs_base, unsigned long gs_base)10831083+void vmx_set_host_fs_gs(struct vmcs_host_state *host, u16 fs_sel, u16 gs_sel,10841084+ unsigned long fs_base, unsigned long gs_base)10861085{10871087- if (unlikely(cr3 != host->cr3)) {10881088- vmcs_writel(HOST_CR3, cr3);10891089- host->cr3 = cr3;10901090- }10911086 if (unlikely(fs_sel != host->fs_sel)) {10921087 if (!(fs_sel & 7))10931088 vmcs_write16(HOST_FS_SELECTOR, fs_sel);···11771182 gs_base = segment_base(gs_sel);11781183#endif1179118411801180- vmx_set_vmcs_host_state(host_state, __get_current_cr3_fast(),11811181- fs_sel, gs_sel, fs_base, gs_base);11821182-11851185+ vmx_set_host_fs_gs(host_state, fs_sel, gs_sel, fs_base, gs_base);11831186 vmx->guest_state_loaded = true;11841187}11851188···67846791static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)67856792{67866793 struct vcpu_vmx *vmx = to_vmx(vcpu);67876787- unsigned long cr4;67946794+ unsigned long cr3, cr4;6788679567896796 /* Record the guest's net vcpu time for enforced NMI injections. */67906797 if (unlikely(!enable_vnmi &&···68266833 if (kvm_register_is_dirty(vcpu, VCPU_REGS_RIP))68276834 vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);68286835 vcpu->arch.regs_dirty = 0;68366836+68376837+ /*68386838+ * Refresh vmcs.HOST_CR3 if necessary. This must be done immediately68396839+ * prior to VM-Enter, as the kernel may load a new ASID (PCID) any time68406840+ * it switches back to the current->mm, which can occur in KVM context68416841+ * when switching to a temporary mm to patch kernel code, e.g. if KVM68426842+ * toggles a static key while handling a VM-Exit.68436843+ */68446844+ cr3 = __get_current_cr3_fast();68456845+ if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) {68466846+ vmcs_writel(HOST_CR3, cr3);68476847+ vmx->loaded_vmcs->host_state.cr3 = cr3;68486848+ }6829684968306850 cr4 = cr4_read_shadow();68316851 if (unlikely(cr4 != vmx->loaded_vmcs->host_state.cr4)) {
+2-3
arch/x86/kvm/vmx/vmx.h
···374374void free_vpid(int vpid);375375void vmx_set_constant_host_state(struct vcpu_vmx *vmx);376376void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu);377377-void vmx_set_vmcs_host_state(struct vmcs_host_state *host, unsigned long cr3,378378- u16 fs_sel, u16 gs_sel,379379- unsigned long fs_base, unsigned long gs_base);377377+void vmx_set_host_fs_gs(struct vmcs_host_state *host, u16 fs_sel, u16 gs_sel,378378+ unsigned long fs_base, unsigned long gs_base);380379int vmx_get_cpl(struct kvm_vcpu *vcpu);381380bool vmx_emulation_required(struct kvm_vcpu *vcpu);382381unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu);
+13-12
arch/x86/kvm/x86.c
···91809180 likely(!pic_in_kernel(vcpu->kvm));91819181}9182918291839183+/* Called within kvm->srcu read side. */91839184static void post_kvm_run_save(struct kvm_vcpu *vcpu)91849185{91859186 struct kvm_run *kvm_run = vcpu->run;···91899188 kvm_run->cr8 = kvm_get_cr8(vcpu);91909189 kvm_run->apic_base = kvm_get_apic_base(vcpu);9191919091929192- /*91939193- * The call to kvm_ready_for_interrupt_injection() may end up in91949194- * kvm_xen_has_interrupt() which may require the srcu lock to be91959195- * held, to protect against changes in the vcpu_info address.91969196- */91979197- vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);91989191 kvm_run->ready_for_interrupt_injection =91999192 pic_in_kernel(vcpu->kvm) ||92009193 kvm_vcpu_ready_for_interrupt_injection(vcpu);92019201- srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);9202919492039195 if (is_smm(vcpu))92049196 kvm_run->flags |= KVM_RUN_X86_SMM;···98099815EXPORT_SYMBOL_GPL(__kvm_request_immediate_exit);9810981698119817/*98189818+ * Called within kvm->srcu read side.98129819 * Returns 1 to let vcpu_run() continue the guest execution loop without98139820 * exiting to the userspace. Otherwise, the value will be returned to the98149821 * userspace.···1018810193 return r;1018910194}10190101951019610196+/* Called within kvm->srcu read side. */1019110197static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu)1019210198{1019310199 bool hv_timer;···1024810252 !vcpu->arch.apf.halted);1024910253}10250102541025510255+/* Called within kvm->srcu read side. */1025110256static int vcpu_run(struct kvm_vcpu *vcpu)1025210257{1025310258 int r;1025410259 struct kvm *kvm = vcpu->kvm;10255102601025610256- vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);1025710261 vcpu->arch.l1tf_flush_l1d = true;10258102621025910263 for (;;) {···1028110285 if (__xfer_to_guest_mode_work_pending()) {1028210286 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);1028310287 r = xfer_to_guest_mode_handle_work(vcpu);1028810288+ vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);1028410289 if (r)1028510290 return r;1028610286- vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);1028710291 }1028810292 }1028910289-1029010290- srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);10291102931029210294 return r;1029310295}···1039210398int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)1039310399{1039410400 struct kvm_run *kvm_run = vcpu->run;1040110401+ struct kvm *kvm = vcpu->kvm;1039510402 int r;10396104031039710404 vcpu_load(vcpu);···1040010405 kvm_run->flags = 0;1040110406 kvm_load_guest_fpu(vcpu);10402104071040810408+ vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);1040310409 if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_UNINITIALIZED)) {1040410410 if (kvm_run->immediate_exit) {1040510411 r = -EINTR;···1041110415 * use before KVM has ever run the vCPU.1041210416 */1041310417 WARN_ON_ONCE(kvm_lapic_hv_timer_in_use(vcpu));1041810418+1041910419+ srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);1041410420 kvm_vcpu_block(vcpu);1042110421+ vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);1042210422+1041510423 if (kvm_apic_accept_events(vcpu) < 0) {1041610424 r = 0;1041710425 goto out;···1047510475 if (kvm_run->kvm_valid_regs)1047610476 store_regs(vcpu);1047710477 post_kvm_run_save(vcpu);1047810478- kvm_sigset_deactivate(vcpu);1047810478+ srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);10479104791048010480+ kvm_sigset_deactivate(vcpu);1048010481 vcpu_put(vcpu);1048110482 return r;1048210483}
···238238 if (buf[1] > 7)239239 return 1;240240241241- i = 0;241241+ i = 2;242242 shift = 0;243243 value = 0;244244 while (*esc && i < LCD2S_CHARACTER_SIZE + 2) {···298298 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA))299299 return -EIO;300300301301+ lcd2s = devm_kzalloc(&i2c->dev, sizeof(*lcd2s), GFP_KERNEL);302302+ if (!lcd2s)303303+ return -ENOMEM;304304+301305 /* Test, if the display is responding */302306 err = lcd2s_i2c_smbus_write_byte(i2c, LCD2S_CMD_DISPLAY_OFF);303307 if (err < 0)···311307 if (!lcd)312308 return -ENOMEM;313309314314- lcd2s = kzalloc(sizeof(struct lcd2s_data), GFP_KERNEL);315315- if (!lcd2s) {316316- err = -ENOMEM;317317- goto fail1;318318- }319319-320310 lcd->drvdata = lcd2s;321311 lcd2s->i2c = i2c;322312 lcd2s->charlcd = lcd;···319321 err = device_property_read_u32(&i2c->dev, "display-height-chars",320322 &lcd->height);321323 if (err)322322- goto fail2;324324+ goto fail1;323325324326 err = device_property_read_u32(&i2c->dev, "display-width-chars",325327 &lcd->width);326328 if (err)327327- goto fail2;329329+ goto fail1;328330329331 lcd->ops = &lcd2s_ops;330332331333 err = charlcd_register(lcd2s->charlcd);332334 if (err)333333- goto fail2;335335+ goto fail1;334336335337 i2c_set_clientdata(i2c, lcd2s);336338 return 0;337339338338-fail2:339339- kfree(lcd2s);340340fail1:341341- kfree(lcd);341341+ charlcd_free(lcd2s->charlcd);342342 return err;343343}344344···345349 struct lcd2s_data *lcd2s = i2c_get_clientdata(i2c);346350347351 charlcd_unregister(lcd2s->charlcd);348348- kfree(lcd2s->charlcd);352352+ charlcd_free(lcd2s->charlcd);349353 return 0;350354}351355
+9-11
drivers/block/virtio_blk.c
···7676 */7777 refcount_t refs;78787979- /* What host tells us, plus 2 for header & tailer. */8080- unsigned int sg_elems;8181-8279 /* Ida index - used to track minor number allocations. */8380 int index;8481···318321 bool notify = false;319322 blk_status_t status;320323 int err;321321-322322- BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);323324324325 status = virtblk_setup_cmd(vblk->vdev, req, vbr);325326 if (unlikely(status))···778783 /* Prevent integer overflows and honor max vq size */779784 sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2);780785781781- /* We need extra sg elements at head and tail. */782782- sg_elems += 2;783786 vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL);784787 if (!vblk) {785788 err = -ENOMEM;···789796 mutex_init(&vblk->vdev_mutex);790797791798 vblk->vdev = vdev;792792- vblk->sg_elems = sg_elems;793799794800 INIT_WORK(&vblk->config_work, virtblk_config_changed_work);795801···845853 set_disk_ro(vblk->disk, 1);846854847855 /* We can handle whatever the host told us to handle. */848848- blk_queue_max_segments(q, vblk->sg_elems-2);856856+ blk_queue_max_segments(q, sg_elems);849857850858 /* No real sector limit. */851859 blk_queue_max_hw_sectors(q, -1U);···917925918926 virtio_cread(vdev, struct virtio_blk_config, max_discard_seg,919927 &v);928928+929929+ /*930930+ * max_discard_seg == 0 is out of spec but we always931931+ * handled it.932932+ */933933+ if (!v)934934+ v = sg_elems;920935 blk_queue_max_discard_segments(q,921921- min_not_zero(v,922922- MAX_DISCARD_SEGMENTS));936936+ min(v, MAX_DISCARD_SEGMENTS));923937924938 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);925939 }
+37-26
drivers/block/xen-blkfront.c
···12881288 rinfo->ring_ref[i] = GRANT_INVALID_REF;12891289 }12901290 }12911291- free_pages((unsigned long)rinfo->ring.sring, get_order(info->nr_ring_pages * XEN_PAGE_SIZE));12911291+ free_pages_exact(rinfo->ring.sring,12921292+ info->nr_ring_pages * XEN_PAGE_SIZE);12921293 rinfo->ring.sring = NULL;1293129412941295 if (rinfo->irq)···13731372 return BLKIF_RSP_OKAY;13741373}1375137413761376-static bool blkif_completion(unsigned long *id,13771377- struct blkfront_ring_info *rinfo,13781378- struct blkif_response *bret)13751375+/*13761376+ * Return values:13771377+ * 1 response processed.13781378+ * 0 missing further responses.13791379+ * -1 error while processing.13801380+ */13811381+static int blkif_completion(unsigned long *id,13821382+ struct blkfront_ring_info *rinfo,13831383+ struct blkif_response *bret)13791384{13801385 int i = 0;13811386 struct scatterlist *sg;···1404139714051398 /* Wait the second response if not yet here. */14061399 if (s2->status < REQ_DONE)14071407- return false;14001400+ return 0;1408140114091402 bret->status = blkif_get_final_status(s->status,14101403 s2->status);···14551448 }14561449 /* Add the persistent grant into the list of free grants */14571450 for (i = 0; i < num_grant; i++) {14581458- if (gnttab_query_foreign_access(s->grants_used[i]->gref)) {14511451+ if (!gnttab_try_end_foreign_access(s->grants_used[i]->gref)) {14591452 /*14601453 * If the grant is still mapped by the backend (the14611454 * backend has chosen to make this grant persistent)14621455 * we add it at the head of the list, so it will be14631456 * reused first.14641457 */14651465- if (!info->feature_persistent)14661466- pr_alert_ratelimited("backed has not unmapped grant: %u\n",14671467- s->grants_used[i]->gref);14581458+ if (!info->feature_persistent) {14591459+ pr_alert("backed has not unmapped grant: %u\n",14601460+ s->grants_used[i]->gref);14611461+ return -1;14621462+ }14681463 list_add(&s->grants_used[i]->node, &rinfo->grants);14691464 rinfo->persistent_gnts_c++;14701465 } else {14711466 /*14721472- * If the grant is not mapped by the backend we end the14731473- * foreign access and add it to the tail of the list,14741474- * so it will not be picked again unless we run out of14751475- * persistent grants.14671467+ * If the grant is not mapped by the backend we add it14681468+ * to the tail of the list, so it will not be picked14691469+ * again unless we run out of persistent grants.14761470 */14771477- gnttab_end_foreign_access(s->grants_used[i]->gref, 0, 0UL);14781471 s->grants_used[i]->gref = GRANT_INVALID_REF;14791472 list_add_tail(&s->grants_used[i]->node, &rinfo->grants);14801473 }14811474 }14821475 if (s->req.operation == BLKIF_OP_INDIRECT) {14831476 for (i = 0; i < INDIRECT_GREFS(num_grant); i++) {14841484- if (gnttab_query_foreign_access(s->indirect_grants[i]->gref)) {14851485- if (!info->feature_persistent)14861486- pr_alert_ratelimited("backed has not unmapped grant: %u\n",14871487- s->indirect_grants[i]->gref);14771477+ if (!gnttab_try_end_foreign_access(s->indirect_grants[i]->gref)) {14781478+ if (!info->feature_persistent) {14791479+ pr_alert("backed has not unmapped grant: %u\n",14801480+ s->indirect_grants[i]->gref);14811481+ return -1;14821482+ }14881483 list_add(&s->indirect_grants[i]->node, &rinfo->grants);14891484 rinfo->persistent_gnts_c++;14901485 } else {14911486 struct page *indirect_page;1492148714931493- gnttab_end_foreign_access(s->indirect_grants[i]->gref, 0, 0UL);14941488 /*14951489 * Add the used indirect page back to the list of14961490 * available pages for indirect grefs.···15061498 }15071499 }1508150015091509- return true;15011501+ return 1;15101502}1511150315121504static irqreturn_t blkif_interrupt(int irq, void *dev_id)···15721564 }1573156515741566 if (bret.operation != BLKIF_OP_DISCARD) {15671567+ int ret;15681568+15751569 /*15761570 * We may need to wait for an extra response if the15771571 * I/O request is split in 215781572 */15791579- if (!blkif_completion(&id, rinfo, &bret))15731573+ ret = blkif_completion(&id, rinfo, &bret);15741574+ if (!ret)15801575 continue;15761576+ if (unlikely(ret < 0))15771577+ goto err;15811578 }1582157915831580 if (add_id_to_freelist(rinfo, id)) {···16891676 for (i = 0; i < info->nr_ring_pages; i++)16901677 rinfo->ring_ref[i] = GRANT_INVALID_REF;1691167816921692- sring = (struct blkif_sring *)__get_free_pages(GFP_NOIO | __GFP_HIGH,16931693- get_order(ring_size));16791679+ sring = alloc_pages_exact(ring_size, GFP_NOIO);16941680 if (!sring) {16951681 xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");16961682 return -ENOMEM;···1699168717001688 err = xenbus_grant_ring(dev, rinfo->ring.sring, info->nr_ring_pages, gref);17011689 if (err < 0) {17021702- free_pages((unsigned long)sring, get_order(ring_size));16901690+ free_pages_exact(sring, ring_size);17031691 rinfo->ring.sring = NULL;17041692 goto fail;17051693 }···25442532 list_for_each_entry_safe(gnt_list_entry, tmp, &rinfo->grants,25452533 node) {25462534 if (gnt_list_entry->gref == GRANT_INVALID_REF ||25472547- gnttab_query_foreign_access(gnt_list_entry->gref))25352535+ !gnttab_try_end_foreign_access(gnt_list_entry->gref))25482536 continue;2549253725502538 list_del(&gnt_list_entry->node);25512551- gnttab_end_foreign_access(gnt_list_entry->gref, 0, 0UL);25522539 rinfo->persistent_gnts_c--;25532540 gnt_list_entry->gref = GRANT_INVALID_REF;25542541 list_add_tail(&gnt_list_entry->node, &rinfo->grants);
+7
drivers/char/virtio_console.c
···19571957 list_del(&portdev->list);19581958 spin_unlock_irq(&pdrvdata_lock);1959195919601960+ /* Device is going away, exit any polling for buffers */19611961+ virtio_break_device(vdev);19621962+ if (use_multiport(portdev))19631963+ flush_work(&portdev->control_work);19641964+ else19651965+ flush_work(&portdev->config_work);19661966+19601967 /* Disable interrupts for vqs */19611968 virtio_reset_device(vdev);19621969 /* Finish up work that's lined up */
+2
drivers/clk/Kconfig
···231231232232config COMMON_CLK_LAN966X233233 bool "Generic Clock Controller driver for LAN966X SoC"234234+ depends on HAS_IOMEM235235+ depends on OF234236 help235237 This driver provides support for Generic Clock Controller(GCK) on236238 LAN966X SoC. GCK generates and supplies clock to various peripherals
+4-1
drivers/clk/qcom/dispcc-sc7180.c
···11// SPDX-License-Identifier: GPL-2.0-only22/*33- * Copyright (c) 2019, The Linux Foundation. All rights reserved.33+ * Copyright (c) 2019, 2022, The Linux Foundation. All rights reserved.44 */5566#include <linux/clk-provider.h>···625625626626static struct gdsc mdss_gdsc = {627627 .gdscr = 0x3000,628628+ .en_rest_wait_val = 0x2,629629+ .en_few_wait_val = 0x2,630630+ .clk_dis_wait_val = 0xf,628631 .pd = {629632 .name = "mdss_gdsc",630633 },
+4-1
drivers/clk/qcom/dispcc-sc7280.c
···11// SPDX-License-Identifier: GPL-2.0-only22/*33- * Copyright (c) 2021, The Linux Foundation. All rights reserved.33+ * Copyright (c) 2021-2022, The Linux Foundation. All rights reserved.44 */5566#include <linux/clk-provider.h>···787787788788static struct gdsc disp_cc_mdss_core_gdsc = {789789 .gdscr = 0x1004,790790+ .en_rest_wait_val = 0x2,791791+ .en_few_wait_val = 0x2,792792+ .clk_dis_wait_val = 0xf,790793 .pd = {791794 .name = "disp_cc_mdss_core_gdsc",792795 },
+4-1
drivers/clk/qcom/dispcc-sm8250.c
···11// SPDX-License-Identifier: GPL-2.022/*33- * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.33+ * Copyright (c) 2018-2020, 2022, The Linux Foundation. All rights reserved.44 */5566#include <linux/clk-provider.h>···1126112611271127static struct gdsc mdss_gdsc = {11281128 .gdscr = 0x3000,11291129+ .en_rest_wait_val = 0x2,11301130+ .en_few_wait_val = 0x2,11311131+ .clk_dis_wait_val = 0xf,11291132 .pd = {11301133 .name = "mdss_gdsc",11311134 },
+21-5
drivers/clk/qcom/gdsc.c
···11// SPDX-License-Identifier: GPL-2.0-only22/*33- * Copyright (c) 2015, 2017-2018, The Linux Foundation. All rights reserved.33+ * Copyright (c) 2015, 2017-2018, 2022, The Linux Foundation. All rights reserved.44 */5566#include <linux/bitops.h>···3535#define CFG_GDSCR_OFFSET 0x436363737/* Wait 2^n CXO cycles between all states. Here, n=2 (4 cycles). */3838-#define EN_REST_WAIT_VAL (0x2 << 20)3939-#define EN_FEW_WAIT_VAL (0x8 << 16)4040-#define CLK_DIS_WAIT_VAL (0x2 << 12)3838+#define EN_REST_WAIT_VAL 0x23939+#define EN_FEW_WAIT_VAL 0x84040+#define CLK_DIS_WAIT_VAL 0x24141+4242+/* Transition delay shifts */4343+#define EN_REST_WAIT_SHIFT 204444+#define EN_FEW_WAIT_SHIFT 164545+#define CLK_DIS_WAIT_SHIFT 1241464247#define RETAIN_MEM BIT(14)4348#define RETAIN_PERIPH BIT(13)···385380 */386381 mask = HW_CONTROL_MASK | SW_OVERRIDE_MASK |387382 EN_REST_WAIT_MASK | EN_FEW_WAIT_MASK | CLK_DIS_WAIT_MASK;388388- val = EN_REST_WAIT_VAL | EN_FEW_WAIT_VAL | CLK_DIS_WAIT_VAL;383383+384384+ if (!sc->en_rest_wait_val)385385+ sc->en_rest_wait_val = EN_REST_WAIT_VAL;386386+ if (!sc->en_few_wait_val)387387+ sc->en_few_wait_val = EN_FEW_WAIT_VAL;388388+ if (!sc->clk_dis_wait_val)389389+ sc->clk_dis_wait_val = CLK_DIS_WAIT_VAL;390390+391391+ val = sc->en_rest_wait_val << EN_REST_WAIT_SHIFT |392392+ sc->en_few_wait_val << EN_FEW_WAIT_SHIFT |393393+ sc->clk_dis_wait_val << CLK_DIS_WAIT_SHIFT;394394+389395 ret = regmap_update_bits(sc->regmap, sc->gdscr, mask, val);390396 if (ret)391397 return ret;
+7-1
drivers/clk/qcom/gdsc.h
···11/* SPDX-License-Identifier: GPL-2.0-only */22/*33- * Copyright (c) 2015, 2017-2018, The Linux Foundation. All rights reserved.33+ * Copyright (c) 2015, 2017-2018, 2022, The Linux Foundation. All rights reserved.44 */5566#ifndef __QCOM_GDSC_H__···2222 * @cxcs: offsets of branch registers to toggle mem/periph bits in2323 * @cxc_count: number of @cxcs2424 * @pwrsts: Possible powerdomain power states2525+ * @en_rest_wait_val: transition delay value for receiving enr ack signal2626+ * @en_few_wait_val: transition delay value for receiving enf ack signal2727+ * @clk_dis_wait_val: transition delay value for halting clock2528 * @resets: ids of resets associated with this gdsc2629 * @reset_count: number of @resets2730 * @rcdev: reset controller···3936 unsigned int clamp_io_ctrl;4037 unsigned int *cxcs;4138 unsigned int cxc_count;3939+ unsigned int en_rest_wait_val;4040+ unsigned int en_few_wait_val;4141+ unsigned int clk_dis_wait_val;4242 const u8 pwrsts;4343/* Powerdomain allowable state bitfields */4444#define PWRSTS_OFF BIT(0)
+1-2
drivers/clocksource/timer-ti-dm-systimer.c
···241241 bool quirk_unreliable_oscillator = false;242242243243 /* Quirk unreliable 32 KiHz oscillator with incomplete dts */244244- if (of_machine_is_compatible("ti,omap3-beagle-ab4") ||245245- of_machine_is_compatible("timll,omap3-devkit8000")) {244244+ if (of_machine_is_compatible("ti,omap3-beagle-ab4")) {246245 quirk_unreliable_oscillator = true;247246 counter_32k = -ENODEV;248247 }
···25252626static u32 hartid;27272828-static u32 get_boot_hartid_from_fdt(void)2828+static int get_boot_hartid_from_fdt(void)2929{3030 const void *fdt;3131 int chosen_node, len;···33333434 fdt = get_efi_config_table(DEVICE_TREE_GUID);3535 if (!fdt)3636- return U32_MAX;3636+ return -EINVAL;37373838 chosen_node = fdt_path_offset(fdt, "/chosen");3939 if (chosen_node < 0)4040- return U32_MAX;4040+ return -EINVAL;41414242 prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len);4343 if (!prop || len != sizeof(u32))4444- return U32_MAX;4444+ return -EINVAL;45454646- return fdt32_to_cpu(*prop);4646+ hartid = fdt32_to_cpu(*prop);4747+ return 0;4748}48494950efi_status_t check_platform_features(void)5051{5151- hartid = get_boot_hartid_from_fdt();5252- if (hartid == U32_MAX) {5252+ int ret;5353+5454+ ret = get_boot_hartid_from_fdt();5555+ if (ret) {5356 efi_err("/chosen/boot-hartid missing or invalid!\n");5457 return EFI_UNSUPPORTED;5558 }
+4-1
drivers/firmware/efi/vars.c
···742742{743743 const struct efivar_operations *ops;744744 efi_status_t status;745745+ unsigned long varsize;745746746747 if (!__efivars)747748 return -EINVAL;···765764 return efivar_entry_set_nonblocking(name, vendor, attributes,766765 size, data);767766767767+ varsize = size + ucs2_strsize(name, 1024);768768 if (!block) {769769 if (down_trylock(&efivars_lock))770770 return -EBUSY;771771+ status = check_var_size_nonblocking(attributes, varsize);771772 } else {772773 if (down_interruptible(&efivars_lock))773774 return -EINTR;775775+ status = check_var_size(attributes, varsize);774776 }775777776776- status = check_var_size(attributes, size + ucs2_strsize(name, 1024));777778 if (status != EFI_SUCCESS) {778779 up(&efivars_lock);779780 return -ENOSPC;
+2-2
drivers/gpio/gpio-sim.c
···547547 *548548 * So we need to store the pointer to the parent struct here. We can549549 * dereference it anywhere we need with no checks and no locking as550550- * it's guaranteed to survive the childred and protected by configfs550550+ * it's guaranteed to survive the children and protected by configfs551551 * locks.552552 *553553 * Same for other structures.···13221322 kfree(hog);13231323}1324132413251325-struct configfs_item_operations gpio_sim_hog_config_item_ops = {13251325+static struct configfs_item_operations gpio_sim_hog_config_item_ops = {13261326 .release = gpio_sim_hog_config_item_release,13271327};13281328
···11/*22 * Digital I/O driver for Technologic Systems I2C FPGA Core33 *44- * Copyright (C) 2015 Technologic Systems44+ * Copyright (C) 2015, 2018 Technologic Systems55 * Copyright (C) 2016 Savoir-Faire Linux66 *77 * This program is free software; you can redistribute it and/or···5555{5656 struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);57575858- /*5959- * This will clear the output enable bit, the other bits are6060- * dontcare when this is cleared5858+ /* Only clear the OE bit here, requires a RMW. Prevents potential issue5959+ * with OE and data getting to the physical pin at different times.6160 */6262- return regmap_write(priv->regmap, offset, 0);6161+ return regmap_update_bits(priv->regmap, offset, TS4900_GPIO_OE, 0);6362}64636564static int ts4900_gpio_direction_output(struct gpio_chip *chip,6665 unsigned int offset, int value)6766{6867 struct ts4900_gpio_priv *priv = gpiochip_get_data(chip);6868+ unsigned int reg;6969 int ret;7070+7171+ /* If changing from an input to an output, we need to first set the7272+ * proper data bit to what is requested and then set OE bit. This7373+ * prevents a glitch that can occur on the IO line7474+ */7575+ regmap_read(priv->regmap, offset, ®);7676+ if (!(reg & TS4900_GPIO_OE)) {7777+ if (value)7878+ reg = TS4900_GPIO_OUT;7979+ else8080+ reg &= ~TS4900_GPIO_OUT;8181+8282+ regmap_write(priv->regmap, offset, reg);8383+ }70847185 if (value)7286 ret = regmap_write(priv->regmap, offset, TS4900_GPIO_OE |
+4-2
drivers/gpio/gpiolib-acpi.c
···307307 if (IS_ERR(desc))308308 return desc;309309310310- ret = gpio_set_debounce_timeout(desc, agpio->debounce_timeout);310310+ /* ACPI uses hundredths of milliseconds units */311311+ ret = gpio_set_debounce_timeout(desc, agpio->debounce_timeout * 10);311312 if (ret)312313 dev_warn(chip->parent,313314 "Failed to set debounce-timeout for pin 0x%04X, err %d\n",···10361035 if (ret < 0)10371036 return ret;1038103710391039- ret = gpio_set_debounce_timeout(desc, info.debounce);10381038+ /* ACPI uses hundredths of milliseconds units */10391039+ ret = gpio_set_debounce_timeout(desc, info.debounce * 10);10401040 if (ret)10411041 return ret;10421042
+10-10
drivers/gpio/gpiolib.c
···17011701 */17021702int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset)17031703{17041704-#ifdef CONFIG_PINCTRL17051705- if (list_empty(&gc->gpiodev->pin_ranges))17061706- return 0;17071707-#endif17081708-17091704 return pinctrl_gpio_request(gc->gpiodev->base + offset);17101705}17111706EXPORT_SYMBOL_GPL(gpiochip_generic_request);···17121717 */17131718void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset)17141719{17151715-#ifdef CONFIG_PINCTRL17161716- if (list_empty(&gc->gpiodev->pin_ranges))17171717- return;17181718-#endif17191719-17201720 pinctrl_gpio_free(gc->gpiodev->base + offset);17211721}17221722EXPORT_SYMBOL_GPL(gpiochip_generic_free);···22172227 return gpio_set_config_with_argument_optional(desc, bias, arg);22182228}2219222922302230+/**22312231+ * gpio_set_debounce_timeout() - Set debounce timeout22322232+ * @desc: GPIO descriptor to set the debounce timeout22332233+ * @debounce: Debounce timeout in microseconds22342234+ *22352235+ * The function calls the certain GPIO driver to set debounce timeout22362236+ * in the hardware.22372237+ *22382238+ * Returns 0 on success, or negative error code otherwise.22392239+ */22202240int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce)22212241{22222242 return gpio_set_config_with_argument_optional(desc,
+2-1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
···777777 amdgpu_vm_eviction_lock(vm);778778 ret = !vm->evicting;779779 amdgpu_vm_eviction_unlock(vm);780780- return ret;780780+781781+ return ret && list_empty(&vm->evicted);781782}782783783784/**
+1
drivers/gpu/drm/arm/Kconfig
···66 depends on DRM && OF && (ARM || ARM64 || COMPILE_TEST)77 depends on COMMON_CLK88 select DRM_KMS_HELPER99+ select DRM_GEM_CMA_HELPER910 help1011 Choose this option if you have an ARM High Definition Colour LCD1112 controller.
+3-2
drivers/gpu/drm/bridge/ti-sn65dsi86.c
···1802180218031803static void ti_sn65dsi86_runtime_disable(void *data)18041804{18051805+ pm_runtime_dont_use_autosuspend(data);18051806 pm_runtime_disable(data);18061807}18071808···18621861 "failed to get reference clock\n");1863186218641863 pm_runtime_enable(dev);18641864+ pm_runtime_set_autosuspend_delay(pdata->dev, 500);18651865+ pm_runtime_use_autosuspend(pdata->dev);18651866 ret = devm_add_action_or_reset(dev, ti_sn65dsi86_runtime_disable, dev);18661867 if (ret)18671868 return ret;18681868- pm_runtime_set_autosuspend_delay(pdata->dev, 500);18691869- pm_runtime_use_autosuspend(pdata->dev);1870186918711870 ti_sn65dsi86_debugfs_init(pdata);18721871
···108108 /* Comet Lake V PCH is based on KBP, which is SPT compatible */109109 return PCH_SPT;110110 case INTEL_PCH_ICP_DEVICE_ID_TYPE:111111+ case INTEL_PCH_ICP2_DEVICE_ID_TYPE:111112 drm_dbg_kms(&dev_priv->drm, "Found Ice Lake PCH\n");112113 drm_WARN_ON(&dev_priv->drm, !IS_ICELAKE(dev_priv));113114 return PCH_ICP;···124123 !IS_GEN9_BC(dev_priv));125124 return PCH_TGP;126125 case INTEL_PCH_JSP_DEVICE_ID_TYPE:127127- case INTEL_PCH_JSP2_DEVICE_ID_TYPE:128126 drm_dbg_kms(&dev_priv->drm, "Found Jasper Lake PCH\n");129127 drm_WARN_ON(&dev_priv->drm, !IS_JSL_EHL(dev_priv));130128 return PCH_JSP;
···106106 depends on PM107107 select VIDEOMODE_HELPERS108108 select DRM_DP_AUX_BUS109109+ select DRM_DP_HELPER109110 help110111 DRM panel driver for dumb eDP panels that need at most a regulator and111112 a GPIO to be powered up. Optionally a backlight can be attached so
+4-4
drivers/gpu/drm/sun4i/sun8i_mixer.h
···111111/* format 13 is semi-planar YUV411 VUVU */112112#define SUN8I_MIXER_FBFMT_YUV411 14113113/* format 15 doesn't exist */114114-/* format 16 is P010 YVU */115115-#define SUN8I_MIXER_FBFMT_P010_YUV 17116116-/* format 18 is P210 YVU */117117-#define SUN8I_MIXER_FBFMT_P210_YUV 19114114+#define SUN8I_MIXER_FBFMT_P010_YUV 16115115+/* format 17 is P010 YVU */116116+#define SUN8I_MIXER_FBFMT_P210_YUV 18117117+/* format 19 is P210 YVU */118118/* format 20 is packed YVU444 10-bit */119119/* format 21 is packed YUV444 10-bit */120120
···992992 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;993993 case 0x0cf: map_key_clear(KEY_VOICECOMMAND); break;994994995995+ case 0x0d8: map_key_clear(KEY_DICTATE); break;995996 case 0x0d9: map_key_clear(KEY_EMOJI_PICKER); break;996997997998 case 0x0e0: map_abs_clear(ABS_VOLUME); break;···10831082 case 0x28c: map_key_clear(KEY_SEND); break;1084108310851084 case 0x29d: map_key_clear(KEY_KBD_LAYOUT_NEXT); break;10851085+10861086+ case 0x2a2: map_key_clear(KEY_ALL_APPLICATIONS); break;1086108710871088 case 0x2c7: map_key_clear(KEY_KBDINPUTASSIST_PREV); break;10881089 case 0x2c8: map_key_clear(KEY_KBDINPUTASSIST_NEXT); break;
+1
drivers/hid/hid-logitech-dj.c
···10681068 workitem.reports_supported |= STD_KEYBOARD;10691069 break;10701070 case 0x0f:10711071+ case 0x11:10711072 device_type = "eQUAD Lightspeed 1.2";10721073 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);10731074 workitem.reports_supported |= STD_KEYBOARD;
+4
drivers/hid/hid-nintendo.c
···21282128 spin_lock_init(&ctlr->lock);21292129 ctlr->rumble_queue = alloc_workqueue("hid-nintendo-rumble_wq",21302130 WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);21312131+ if (!ctlr->rumble_queue) {21322132+ ret = -ENOMEM;21332133+ goto err;21342134+ }21312135 INIT_WORK(&ctlr->rumble_worker, joycon_rumble_worker);2132213621332137 ret = hid_parse(hdev);
···556556557557config KEYBOARD_SAMSUNG558558 tristate "Samsung keypad support"559559- depends on HAVE_CLK559559+ depends on HAS_IOMEM && HAVE_CLK560560 select INPUT_MATRIXKMAP561561 help562562 Say Y here if you want to use the keypad on your Samsung mobile
+23-41
drivers/input/mouse/elan_i2c_core.c
···186186 return 0;187187}188188189189-static int elan_enable_power(struct elan_tp_data *data)189189+static int elan_set_power(struct elan_tp_data *data, bool on)190190{191191 int repeat = ETP_RETRY_COUNT;192192 int error;193193194194- error = regulator_enable(data->vcc);195195- if (error) {196196- dev_err(&data->client->dev,197197- "failed to enable regulator: %d\n", error);198198- return error;199199- }200200-201194 do {202202- error = data->ops->power_control(data->client, true);195195+ error = data->ops->power_control(data->client, on);203196 if (error >= 0)204197 return 0;205198206199 msleep(30);207200 } while (--repeat > 0);208201209209- dev_err(&data->client->dev, "failed to enable power: %d\n", error);210210- return error;211211-}212212-213213-static int elan_disable_power(struct elan_tp_data *data)214214-{215215- int repeat = ETP_RETRY_COUNT;216216- int error;217217-218218- do {219219- error = data->ops->power_control(data->client, false);220220- if (!error) {221221- error = regulator_disable(data->vcc);222222- if (error) {223223- dev_err(&data->client->dev,224224- "failed to disable regulator: %d\n",225225- error);226226- /* Attempt to power the chip back up */227227- data->ops->power_control(data->client, true);228228- break;229229- }230230-231231- return 0;232232- }233233-234234- msleep(30);235235- } while (--repeat > 0);236236-237237- dev_err(&data->client->dev, "failed to disable power: %d\n", error);202202+ dev_err(&data->client->dev, "failed to set power %s: %d\n",203203+ on ? "on" : "off", error);238204 return error;239205}240206···13651399 /* Enable wake from IRQ */13661400 data->irq_wake = (enable_irq_wake(client->irq) == 0);13671401 } else {13681368- ret = elan_disable_power(data);14021402+ ret = elan_set_power(data, false);14031403+ if (ret)14041404+ goto err;14051405+14061406+ ret = regulator_disable(data->vcc);14071407+ if (ret) {14081408+ dev_err(dev, "error %d disabling regulator\n", ret);14091409+ /* Attempt to power the chip back up */14101410+ elan_set_power(data, true);14111411+ }13691412 }1370141314141414+err:13711415 mutex_unlock(&data->sysfs_mutex);13721416 return ret;13731417}···13881412 struct elan_tp_data *data = i2c_get_clientdata(client);13891413 int error;1390141413911391- if (device_may_wakeup(dev) && data->irq_wake) {14151415+ if (!device_may_wakeup(dev)) {14161416+ error = regulator_enable(data->vcc);14171417+ if (error) {14181418+ dev_err(dev, "error %d enabling regulator\n", error);14191419+ goto err;14201420+ }14211421+ } else if (data->irq_wake) {13921422 disable_irq_wake(client->irq);13931423 data->irq_wake = false;13941424 }1395142513961396- error = elan_enable_power(data);14261426+ error = elan_set_power(data, true);13971427 if (error) {13981428 dev_err(dev, "power up when resuming failed: %d\n", error);13991429 goto err;
+17-17
drivers/input/touchscreen/goodix.c
···1818#include <linux/delay.h>1919#include <linux/irq.h>2020#include <linux/interrupt.h>2121+#include <linux/platform_data/x86/soc.h>2122#include <linux/slab.h>2223#include <linux/acpi.h>2324#include <linux/of.h>···806805}807806808807#ifdef ACPI_GPIO_SUPPORT809809-#include <asm/cpu_device_id.h>810810-#include <asm/intel-family.h>811811-812812-static const struct x86_cpu_id baytrail_cpu_ids[] = {813813- { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, X86_FEATURE_ANY, },814814- {}815815-};816816-817817-static inline bool is_byt(void)818818-{819819- const struct x86_cpu_id *id = x86_match_cpu(baytrail_cpu_ids);820820-821821- return !!id;822822-}823823-824808static const struct acpi_gpio_params first_gpio = { 0, 0, false };825809static const struct acpi_gpio_params second_gpio = { 1, 0, false };826810···864878 const struct acpi_gpio_mapping *gpio_mapping = NULL;865879 struct device *dev = &ts->client->dev;866880 LIST_HEAD(resources);867867- int ret;881881+ int irq, ret;868882869883 ts->gpio_count = 0;870884 ts->gpio_int_idx = -1;···876890 }877891878892 acpi_dev_free_resource_list(&resources);893893+894894+ /*895895+ * CHT devices should have a GpioInt + a regular GPIO ACPI resource.896896+ * Some CHT devices have a bug (where the also is bogus Interrupt897897+ * resource copied from a previous BYT based generation). i2c-core-acpi898898+ * will use the non-working Interrupt resource, fix this up.899899+ */900900+ if (soc_intel_is_cht() && ts->gpio_count == 2 && ts->gpio_int_idx != -1) {901901+ irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0);902902+ if (irq > 0 && irq != ts->client->irq) {903903+ dev_warn(dev, "Overriding IRQ %d -> %d\n", ts->client->irq, irq);904904+ ts->client->irq = irq;905905+ }906906+ }879907880908 if (ts->gpio_count == 2 && ts->gpio_int_idx == 0) {881909 ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;···903903 dev_info(dev, "Using ACPI INTI and INTO methods for IRQ pin access\n");904904 ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_METHOD;905905 gpio_mapping = acpi_goodix_reset_only_gpios;906906- } else if (is_byt() && ts->gpio_count == 2 && ts->gpio_int_idx == -1) {906906+ } else if (soc_intel_is_byt() && ts->gpio_count == 2 && ts->gpio_int_idx == -1) {907907 dev_info(dev, "No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n");908908 ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;909909 gpio_mapping = acpi_goodix_int_last_gpios;
···658658}659659660660/*661661+ * This function restarts event logging in case the IOMMU experienced662662+ * an event log buffer overflow.663663+ */664664+void amd_iommu_restart_event_logging(struct amd_iommu *iommu)665665+{666666+ iommu_feature_disable(iommu, CONTROL_EVT_LOG_EN);667667+ iommu_feature_enable(iommu, CONTROL_EVT_LOG_EN);668668+}669669+670670+/*661671 * This function resets the command buffer if the IOMMU stopped fetching662672 * commands from it.663673 */
+6-6
drivers/iommu/amd/io_pgtable.c
···492492493493 dom = container_of(pgtable, struct protection_domain, iop);494494495495- /* Update data structure */496496- amd_iommu_domain_clr_pt_root(dom);497497-498498- /* Make changes visible to IOMMUs */499499- amd_iommu_domain_update(dom);500500-501495 /* Page-table is not visible to IOMMU anymore, so free it */502496 BUG_ON(pgtable->mode < PAGE_MODE_NONE ||503497 pgtable->mode > PAGE_MODE_6_LEVEL);504498505499 free_sub_pt(pgtable->root, pgtable->mode, &freelist);500500+501501+ /* Update data structure */502502+ amd_iommu_domain_clr_pt_root(dom);503503+504504+ /* Make changes visible to IOMMUs */505505+ amd_iommu_domain_update(dom);506506507507 put_pages_list(&freelist);508508}
+8-2
drivers/iommu/amd/iommu.c
···764764#endif /* !CONFIG_IRQ_REMAP */765765766766#define AMD_IOMMU_INT_MASK \767767- (MMIO_STATUS_EVT_INT_MASK | \767767+ (MMIO_STATUS_EVT_OVERFLOW_INT_MASK | \768768+ MMIO_STATUS_EVT_INT_MASK | \768769 MMIO_STATUS_PPR_INT_MASK | \769770 MMIO_STATUS_GALOG_INT_MASK)770771···775774 u32 status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET);776775777776 while (status & AMD_IOMMU_INT_MASK) {778778- /* Enable EVT and PPR and GA interrupts again */777777+ /* Enable interrupt sources again */779778 writel(AMD_IOMMU_INT_MASK,780779 iommu->mmio_base + MMIO_STATUS_OFFSET);781780···795794 iommu_poll_ga_log(iommu);796795 }797796#endif797797+798798+ if (status & MMIO_STATUS_EVT_OVERFLOW_INT_MASK) {799799+ pr_info_ratelimited("IOMMU event log overflow\n");800800+ amd_iommu_restart_event_logging(iommu);801801+ }798802799803 /*800804 * Hardware bug: ERBT1312
+1-1
drivers/iommu/intel/iommu.c
···27382738 spin_unlock_irqrestore(&device_domain_lock, flags);2739273927402740 /* PASID table is mandatory for a PCI device in scalable mode. */27412741- if (dev && dev_is_pci(dev) && sm_supported(iommu)) {27412741+ if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {27422742 ret = intel_pasid_alloc_table(dev);27432743 if (ret) {27442744 dev_err(dev, "PASID table allocation failed\n");
···20052005 }20062006 /* Allocate memory for FIFOS */20072007 /* the memory needs to be on a 32k boundary within the first 4G */20082008- dma_set_mask(&hc->pdev->dev, 0xFFFF8000);20082008+ if (dma_set_mask(&hc->pdev->dev, 0xFFFF8000)) {20092009+ printk(KERN_WARNING20102010+ "HFC-PCI: No usable DMA configuration!\n");20112011+ return -EIO;20122012+ }20092013 buffer = dma_alloc_coherent(&hc->pdev->dev, 0x8000, &hc->hw.dmahandle,20102014 GFP_KERNEL);20112015 /* We silently assume the address is okay if nonzero */
+3-3
drivers/isdn/mISDN/dsp_pipeline.c
···192192int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)193193{194194 int found = 0;195195- char *dup, *tok, *name, *args;195195+ char *dup, *next, *tok, *name, *args;196196 struct dsp_element_entry *entry, *n;197197 struct dsp_pipeline_entry *pipeline_entry;198198 struct mISDN_dsp_element *elem;···203203 if (!list_empty(&pipeline->list))204204 _dsp_pipeline_destroy(pipeline);205205206206- dup = kstrdup(cfg, GFP_ATOMIC);206206+ dup = next = kstrdup(cfg, GFP_ATOMIC);207207 if (!dup)208208 return 0;209209- while ((tok = strsep(&dup, "|"))) {209209+ while ((tok = strsep(&next, "|"))) {210210 if (!strlen(tok))211211 continue;212212 name = strsep(&tok, "(");
···17871787 struct es58x_device *es58x_dev = es58x_priv(netdev)->es58x_dev;17881788 int ret;1789178917901790- if (atomic_inc_return(&es58x_dev->opened_channel_cnt) == 1) {17901790+ if (!es58x_dev->opened_channel_cnt) {17911791 ret = es58x_alloc_rx_urbs(es58x_dev);17921792 if (ret)17931793 return ret;···18051805 if (ret)18061806 goto free_urbs;1807180718081808+ es58x_dev->opened_channel_cnt++;18081809 netif_start_queue(netdev);1809181018101811 return ret;1811181218121813 free_urbs:18131813- if (atomic_dec_and_test(&es58x_dev->opened_channel_cnt))18141814+ if (!es58x_dev->opened_channel_cnt)18141815 es58x_free_urbs(es58x_dev);18151816 netdev_err(netdev, "%s: Could not open the network device: %pe\n",18161817 __func__, ERR_PTR(ret));···1846184518471846 es58x_flush_pending_tx_msg(netdev);1848184718491849- if (atomic_dec_and_test(&es58x_dev->opened_channel_cnt))18481848+ es58x_dev->opened_channel_cnt--;18491849+ if (!es58x_dev->opened_channel_cnt)18501850 es58x_free_urbs(es58x_dev);1851185118521852 return 0;···22172215 init_usb_anchor(&es58x_dev->tx_urbs_idle);22182216 init_usb_anchor(&es58x_dev->tx_urbs_busy);22192217 atomic_set(&es58x_dev->tx_urbs_idle_cnt, 0);22202220- atomic_set(&es58x_dev->opened_channel_cnt, 0);22212218 usb_set_intfdata(intf, es58x_dev);2222221922232220 es58x_dev->rx_pipe = usb_rcvbulkpipe(es58x_dev->udev,
+5-3
drivers/net/can/usb/etas_es58x/es58x_core.h
···373373 * queue wake/stop logic should prevent this URB from getting374374 * empty. Please refer to es58x_get_tx_urb() for more details.375375 * @tx_urbs_idle_cnt: number of urbs in @tx_urbs_idle.376376- * @opened_channel_cnt: number of channels opened (c.f. es58x_open()377377- * and es58x_stop()).378376 * @ktime_req_ns: kernel timestamp when es58x_set_realtime_diff_ns()379377 * was called.380378 * @realtime_diff_ns: difference in nanoseconds between the clocks of···382384 * in RX branches.383385 * @rx_max_packet_size: Maximum length of bulk-in URB.384386 * @num_can_ch: Number of CAN channel (i.e. number of elements of @netdev).387387+ * @opened_channel_cnt: number of channels opened. Free of race388388+ * conditions because its two users (net_device_ops:ndo_open()389389+ * and net_device_ops:ndo_close()) guarantee that the network390390+ * stack big kernel lock (a.k.a. rtnl_mutex) is being hold.385391 * @rx_cmd_buf_len: Length of @rx_cmd_buf.386392 * @rx_cmd_buf: The device might split the URB commands in an387393 * arbitrary amount of pieces. This buffer is used to concatenate···408406 struct usb_anchor tx_urbs_busy;409407 struct usb_anchor tx_urbs_idle;410408 atomic_t tx_urbs_idle_cnt;411411- atomic_t opened_channel_cnt;412409413410 u64 ktime_req_ns;414411 s64 realtime_diff_ns;···416415417416 u16 rx_max_packet_size;418417 u8 num_can_ch;418418+ u8 opened_channel_cnt;419419420420 u16 rx_cmd_buf_len;421421 union es58x_urb_cmd rx_cmd_buf;
+5-5
drivers/net/can/usb/gs_usb.c
···191191struct gs_usb {192192 struct gs_can *canch[GS_MAX_INTF];193193 struct usb_anchor rx_submitted;194194- atomic_t active_channels;195194 struct usb_device *udev;195195+ u8 active_channels;196196};197197198198/* 'allocate' a tx context.···589589 if (rc)590590 return rc;591591592592- if (atomic_add_return(1, &parent->active_channels) == 1) {592592+ if (!parent->active_channels) {593593 for (i = 0; i < GS_MAX_RX_URBS; i++) {594594 struct urb *urb;595595 u8 *buf;···690690691691 dev->can.state = CAN_STATE_ERROR_ACTIVE;692692693693+ parent->active_channels++;693694 if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))694695 netif_start_queue(netdev);695696···706705 netif_stop_queue(netdev);707706708707 /* Stop polling */709709- if (atomic_dec_and_test(&parent->active_channels))708708+ parent->active_channels--;709709+ if (!parent->active_channels)710710 usb_kill_anchored_urbs(&parent->rx_submitted);711711712712 /* Stop sending URBs */···985983 }986984987985 init_usb_anchor(&dev->rx_submitted);988988-989989- atomic_set(&dev->active_channels, 0);990986991987 usb_set_intfdata(intf, dev);992988 dev->udev = interface_to_usbdev(intf);
+1-1
drivers/net/dsa/mt7530.c
···2936293629372937 phylink_set_port_modes(mask);2938293829392939- if (state->interface != PHY_INTERFACE_MODE_TRGMII ||29392939+ if (state->interface != PHY_INTERFACE_MODE_TRGMII &&29402940 !phy_interface_mode_is_8023z(state->interface)) {29412941 phylink_set(mask, 10baseT_Half);29422942 phylink_set(mask, 10baseT_Full);
+5-5
drivers/net/ethernet/8390/mcf8390.c
···405405static int mcf8390_probe(struct platform_device *pdev)406406{407407 struct net_device *dev;408408- struct resource *mem, *irq;408408+ struct resource *mem;409409 resource_size_t msize;410410- int ret;410410+ int ret, irq;411411412412- irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);413413- if (irq == NULL) {412412+ irq = platform_get_irq(pdev, 0);413413+ if (irq < 0) {414414 dev_err(&pdev->dev, "no IRQ specified?\n");415415 return -ENXIO;416416 }···433433 SET_NETDEV_DEV(dev, &pdev->dev);434434 platform_set_drvdata(pdev, dev);435435436436- dev->irq = irq->start;436436+ dev->irq = irq;437437 dev->base_addr = mem->start;438438439439 ret = mcf8390_init(dev);
···15731573 if (work_done < budget) {15741574 napi_complete_done(napi, work_done);1575157515761576- /* Packets received while interrupts were disabled */15761576+ /* RSR bits only seem to propagate to raise interrupts when15771577+ * interrupts are enabled at the time, so if bits are already15781578+ * set due to packets received while interrupts were disabled,15791579+ * they will not cause another interrupt to be generated when15801580+ * interrupts are re-enabled.15811581+ * Check for this case here. This has been seen to happen15821582+ * around 30% of the time under heavy network load.15831583+ */15771584 status = macb_readl(bp, RSR);15781585 if (status) {15791586 if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)···15881581 napi_reschedule(napi);15891582 } else {15901583 queue_writel(queue, IER, bp->rx_intr_mask);15841584+15851585+ /* In rare cases, packets could have been received in15861586+ * the window between the check above and re-enabling15871587+ * interrupts. Therefore, a double-check is required15881588+ * to avoid losing a wakeup. This can potentially race15891589+ * with the interrupt handler doing the same actions15901590+ * if an interrupt is raised just after enabling them,15911591+ * but this should be harmless.15921592+ */15931593+ status = macb_readl(bp, RSR);15941594+ if (unlikely(status)) {15951595+ queue_writel(queue, IDR, bp->rx_intr_mask);15961596+ if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)15971597+ queue_writel(queue, ISR, MACB_BIT(RCOMP));15981598+ napi_schedule(napi);15991599+ }15911600 }15921601 }15931602
+2
drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
···36133613 MAC_STATS_ACCUM_SECS : (MAC_STATS_ACCUM_SECS * 10);36143614 adapter->params.pci.vpd_cap_addr =36153615 pci_find_capability(adapter->pdev, PCI_CAP_ID_VPD);36163616+ if (!adapter->params.pci.vpd_cap_addr)36173617+ return -ENODEV;36163618 ret = get_vpd_params(adapter, &adapter->params.vpd);36173619 if (ret < 0)36183620 return ret;
+1
drivers/net/ethernet/freescale/gianfar_ethtool.c
···14641464 ptp_node = of_find_compatible_node(NULL, NULL, "fsl,etsec-ptp");14651465 if (ptp_node) {14661466 ptp_dev = of_find_device_by_node(ptp_node);14671467+ of_node_put(ptp_node);14671468 if (ptp_dev)14681469 ptp = platform_get_drvdata(ptp_dev);14691470 }
+155-28
drivers/net/ethernet/ibm/ibmvnic.c
···22132213}2214221422152215/*22162216+ * Initialize the init_done completion and return code values. We22172217+ * can get a transport event just after registering the CRQ and the22182218+ * tasklet will use this to communicate the transport event. To ensure22192219+ * we don't miss the notification/error, initialize these _before_22202220+ * regisering the CRQ.22212221+ */22222222+static inline void reinit_init_done(struct ibmvnic_adapter *adapter)22232223+{22242224+ reinit_completion(&adapter->init_done);22252225+ adapter->init_done_rc = 0;22262226+}22272227+22282228+/*22162229 * do_reset returns zero if we are able to keep processing reset events, or22172230 * non-zero if we hit a fatal error and must halt.22182231 */···23302317 * we are coming from the probed state.23312318 */23322319 adapter->state = VNIC_PROBED;23202320+23212321+ reinit_init_done(adapter);2333232223342323 if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) {23352324 rc = init_crq_queue(adapter);···24762461 */24772462 adapter->state = VNIC_PROBED;2478246324792479- reinit_completion(&adapter->init_done);24642464+ reinit_init_done(adapter);24652465+24802466 rc = init_crq_queue(adapter);24812467 if (rc) {24822468 netdev_err(adapter->netdev,···26182602static void __ibmvnic_reset(struct work_struct *work)26192603{26202604 struct ibmvnic_adapter *adapter;26212621- bool saved_state = false;26052605+ unsigned int timeout = 5000;26222606 struct ibmvnic_rwi *tmprwi;26072607+ bool saved_state = false;26232608 struct ibmvnic_rwi *rwi;26242609 unsigned long flags;26252625- u32 reset_state;26102610+ struct device *dev;26112611+ bool need_reset;26262612 int num_fails = 0;26132613+ u32 reset_state;26272614 int rc = 0;2628261526292616 adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);26172617+ dev = &adapter->vdev->dev;2630261826312631- if (test_and_set_bit_lock(0, &adapter->resetting)) {26192619+ /* Wait for ibmvnic_probe() to complete. If probe is taking too long26202620+ * or if another reset is in progress, defer work for now. If probe26212621+ * eventually fails it will flush and terminate our work.26222622+ *26232623+ * Three possibilities here:26242624+ * 1. Adpater being removed - just return26252625+ * 2. Timed out on probe or another reset in progress - delay the work26262626+ * 3. Completed probe - perform any resets in queue26272627+ */26282628+ if (adapter->state == VNIC_PROBING &&26292629+ !wait_for_completion_timeout(&adapter->probe_done, timeout)) {26302630+ dev_err(dev, "Reset thread timed out on probe");26322631 queue_delayed_work(system_long_wq,26332632 &adapter->ibmvnic_delayed_reset,26342633 IBMVNIC_RESET_DELAY);26352634 return;26362635 }26362636+26372637+ /* adapter is done with probe (i.e state is never VNIC_PROBING now) */26382638+ if (adapter->state == VNIC_REMOVING)26392639+ return;26402640+26412641+ /* ->rwi_list is stable now (no one else is removing entries) */26422642+26432643+ /* ibmvnic_probe() may have purged the reset queue after we were26442644+ * scheduled to process a reset so there maybe no resets to process.26452645+ * Before setting the ->resetting bit though, we have to make sure26462646+ * that there is infact a reset to process. Otherwise we may race26472647+ * with ibmvnic_open() and end up leaving the vnic down:26482648+ *26492649+ * __ibmvnic_reset() ibmvnic_open()26502650+ * ----------------- --------------26512651+ *26522652+ * set ->resetting bit26532653+ * find ->resetting bit is set26542654+ * set ->state to IBMVNIC_OPEN (i.e26552655+ * assume reset will open device)26562656+ * return26572657+ * find reset queue empty26582658+ * return26592659+ *26602660+ * Neither performed vnic login/open and vnic stays down26612661+ *26622662+ * If we hold the lock and conditionally set the bit, either we26632663+ * or ibmvnic_open() will complete the open.26642664+ */26652665+ need_reset = false;26662666+ spin_lock(&adapter->rwi_lock);26672667+ if (!list_empty(&adapter->rwi_list)) {26682668+ if (test_and_set_bit_lock(0, &adapter->resetting)) {26692669+ queue_delayed_work(system_long_wq,26702670+ &adapter->ibmvnic_delayed_reset,26712671+ IBMVNIC_RESET_DELAY);26722672+ } else {26732673+ need_reset = true;26742674+ }26752675+ }26762676+ spin_unlock(&adapter->rwi_lock);26772677+26782678+ if (!need_reset)26792679+ return;2637268026382681 rwi = get_next_rwi(adapter);26392682 while (rwi) {···28102735 __ibmvnic_reset(&adapter->ibmvnic_reset);28112736}2812273727382738+static void flush_reset_queue(struct ibmvnic_adapter *adapter)27392739+{27402740+ struct list_head *entry, *tmp_entry;27412741+27422742+ if (!list_empty(&adapter->rwi_list)) {27432743+ list_for_each_safe(entry, tmp_entry, &adapter->rwi_list) {27442744+ list_del(entry);27452745+ kfree(list_entry(entry, struct ibmvnic_rwi, list));27462746+ }27472747+ }27482748+}27492749+28132750static int ibmvnic_reset(struct ibmvnic_adapter *adapter,28142751 enum ibmvnic_reset_reason reason)28152752{28162816- struct list_head *entry, *tmp_entry;28172817- struct ibmvnic_rwi *rwi, *tmp;28182753 struct net_device *netdev = adapter->netdev;27542754+ struct ibmvnic_rwi *rwi, *tmp;28192755 unsigned long flags;28202756 int ret;28212757···28422756 (adapter->failover_pending && reason != VNIC_RESET_FAILOVER)) {28432757 ret = EBUSY;28442758 netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n");28452845- goto err;28462846- }28472847-28482848- if (adapter->state == VNIC_PROBING) {28492849- netdev_warn(netdev, "Adapter reset during probe\n");28502850- adapter->init_done_rc = -EAGAIN;28512851- ret = EAGAIN;28522759 goto err;28532760 }28542761···28622783 /* if we just received a transport event,28632784 * flush reset queue and process this reset28642785 */28652865- if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) {28662866- list_for_each_safe(entry, tmp_entry, &adapter->rwi_list)28672867- list_del(entry);28682868- }27862786+ if (adapter->force_reset_recovery)27872787+ flush_reset_queue(adapter);27882788+28692789 rwi->reset_reason = reason;28702790 list_add_tail(&rwi->list, &adapter->rwi_list);28712791 netdev_dbg(adapter->netdev, "Scheduling reset (reason %s)\n",···53995321 }5400532254015323 if (!completion_done(&adapter->init_done)) {54025402- complete(&adapter->init_done);54035324 if (!adapter->init_done_rc)54045325 adapter->init_done_rc = -EAGAIN;53265326+ complete(&adapter->init_done);54055327 }5406532854075329 break;···54245346 adapter->fw_done_rc = -EIO;54255347 complete(&adapter->fw_done);54265348 }53495349+53505350+ /* if we got here during crq-init, retry crq-init */53515351+ if (!completion_done(&adapter->init_done)) {53525352+ adapter->init_done_rc = -EAGAIN;53535353+ complete(&adapter->init_done);53545354+ }53555355+54275356 if (!completion_done(&adapter->stats_done))54285357 complete(&adapter->stats_done);54295358 if (test_bit(0, &adapter->resetting))···5747566257485663 adapter->from_passive_init = false;5749566457505750- if (reset)57515751- reinit_completion(&adapter->init_done);57525752-57535753- adapter->init_done_rc = 0;57545665 rc = ibmvnic_send_crq_init(adapter);57555666 if (rc) {57565667 dev_err(dev, "Send crq init failed with error %d\n", rc);···5760567957615680 if (adapter->init_done_rc) {57625681 release_crq_queue(adapter);56825682+ dev_err(dev, "CRQ-init failed, %d\n", adapter->init_done_rc);57635683 return adapter->init_done_rc;57645684 }5765568557665686 if (adapter->from_passive_init) {57675687 adapter->state = VNIC_OPEN;57685688 adapter->from_passive_init = false;56895689+ dev_err(dev, "CRQ-init failed, passive-init\n");57695690 return -EINVAL;57705691 }57715692···58075724 struct ibmvnic_adapter *adapter;58085725 struct net_device *netdev;58095726 unsigned char *mac_addr_p;57275727+ unsigned long flags;58105728 bool init_success;58115729 int rc;58125730···58525768 spin_lock_init(&adapter->rwi_lock);58535769 spin_lock_init(&adapter->state_lock);58545770 mutex_init(&adapter->fw_lock);57715771+ init_completion(&adapter->probe_done);58555772 init_completion(&adapter->init_done);58565773 init_completion(&adapter->fw_done);58575774 init_completion(&adapter->reset_done);···5863577858645779 init_success = false;58655780 do {57815781+ reinit_init_done(adapter);57825782+57835783+ /* clear any failovers we got in the previous pass57845784+ * since we are reinitializing the CRQ57855785+ */57865786+ adapter->failover_pending = false;57875787+57885788+ /* If we had already initialized CRQ, we may have one or57895789+ * more resets queued already. Discard those and release57905790+ * the CRQ before initializing the CRQ again.57915791+ */57925792+ release_crq_queue(adapter);57935793+57945794+ /* Since we are still in PROBING state, __ibmvnic_reset()57955795+ * will not access the ->rwi_list and since we released CRQ,57965796+ * we won't get _new_ transport events. But there maybe an57975797+ * ongoing ibmvnic_reset() call. So serialize access to57985798+ * rwi_list. If we win the race, ibvmnic_reset() could add57995799+ * a reset after we purged but thats ok - we just may end58005800+ * up with an extra reset (i.e similar to having two or more58015801+ * resets in the queue at once).58025802+ * CHECK.58035803+ */58045804+ spin_lock_irqsave(&adapter->rwi_lock, flags);58055805+ flush_reset_queue(adapter);58065806+ spin_unlock_irqrestore(&adapter->rwi_lock, flags);58075807+58665808 rc = init_crq_queue(adapter);58675809 if (rc) {58685810 dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n",···59215809 goto ibmvnic_dev_file_err;5922581059235811 netif_carrier_off(netdev);59245924- rc = register_netdev(netdev);59255925- if (rc) {59265926- dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);59275927- goto ibmvnic_register_fail;59285928- }59295929- dev_info(&dev->dev, "ibmvnic registered\n");5930581259315813 if (init_success) {59325814 adapter->state = VNIC_PROBED;···5933582759345828 adapter->wait_for_reset = false;59355829 adapter->last_reset_time = jiffies;58305830+58315831+ rc = register_netdev(netdev);58325832+ if (rc) {58335833+ dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);58345834+ goto ibmvnic_register_fail;58355835+ }58365836+ dev_info(&dev->dev, "ibmvnic registered\n");58375837+58385838+ complete(&adapter->probe_done);58395839+59365840 return 0;5937584159385842ibmvnic_register_fail:···59575841ibmvnic_init_fail:59585842 release_sub_crqs(adapter, 1);59595843 release_crq_queue(adapter);58445844+58455845+ /* cleanup worker thread after releasing CRQ so we don't get58465846+ * transport events (i.e new work items for the worker thread).58475847+ */58485848+ adapter->state = VNIC_REMOVING;58495849+ complete(&adapter->probe_done);58505850+ flush_work(&adapter->ibmvnic_reset);58515851+ flush_delayed_work(&adapter->ibmvnic_delayed_reset);58525852+58535853+ flush_reset_queue(adapter);58545854+59605855 mutex_destroy(&adapter->fw_lock);59615856 free_netdev(netdev);59625857
···20502050 bool blocked = false;20512051 int i = 0;2052205220532053+ /* Check the PHY (LCD) reset flag */20542054+ if (hw->phy.reset_disable)20552055+ return true;20562056+20532057 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&20542058 (i++ < 30))20552059 usleep_range(10000, 11000);···41404136 return ret_val;4141413741424138 if (!(data & valid_csum_mask)) {41434143- e_dbg("NVM Checksum Invalid\n");41394139+ e_dbg("NVM Checksum valid bit not set\n");4144414041454145- if (hw->mac.type < e1000_pch_cnp) {41414141+ if (hw->mac.type < e1000_pch_tgp) {41464142 data |= valid_csum_mask;41474143 ret_val = e1000_write_nvm(hw, word, 1, &data);41484144 if (ret_val)
···10101111#define I40E_VIRTCHNL_SUPPORTED_QTYPES 212121313-#define I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED 101414-1513#define I40E_VLAN_PRIORITY_SHIFT 131614#define I40E_VLAN_MASK 0xFFF1715#define I40E_PRIORITY_MASK 0xE000···9092 u8 num_queue_pairs; /* num of qps assigned to VF vsis */9193 u8 num_req_queues; /* num of requested qps */9294 u64 num_mdd_events; /* num of mdd events detected */9393- /* num of continuous malformed or invalid msgs detected */9494- u64 num_invalid_msgs;9595- u64 num_valid_msgs; /* num of valid msgs detected */96959796 unsigned long vf_caps; /* vf's adv. capabilities */9897 unsigned long vf_states; /* vf's runtime states */
+6-1
drivers/net/ethernet/intel/iavf/iavf.h
···201201 __IAVF_RUNNING, /* opened, working */202202};203203204204+enum iavf_critical_section_t {205205+ __IAVF_IN_REMOVE_TASK, /* device being removed */206206+};207207+204208#define IAVF_CLOUD_FIELD_OMAC 0x01205209#define IAVF_CLOUD_FIELD_IMAC 0x02206210#define IAVF_CLOUD_FIELD_IVLAN 0x04···250246 struct list_head mac_filter_list;251247 struct mutex crit_lock;252248 struct mutex client_lock;253253- struct mutex remove_lock;254249 /* Lock to protect accesses to MAC and VLAN lists */255250 spinlock_t mac_vlan_list_lock;256251 char misc_vector_name[IFNAMSIZ + 9];···287284#define IAVF_FLAG_LEGACY_RX BIT(15)288285#define IAVF_FLAG_REINIT_ITR_NEEDED BIT(16)289286#define IAVF_FLAG_QUEUES_DISABLED BIT(17)287287+#define IAVF_FLAG_SETUP_NETDEV_FEATURES BIT(18)288288+#define IAVF_FLAG_REINIT_MSIX_NEEDED BIT(20)290289/* duplicates for common code */291290#define IAVF_FLAG_DCB_ENABLED 0292291 /* flags for admin queue service task */
+117-55
drivers/net/ethernet/intel/iavf/iavf_main.c
···302302 rd32(hw, IAVF_VFINT_ICR01);303303 rd32(hw, IAVF_VFINT_ICR0_ENA1);304304305305- /* schedule work on the private workqueue */306306- queue_work(iavf_wq, &adapter->adminq_task);305305+ if (adapter->state != __IAVF_REMOVE)306306+ /* schedule work on the private workqueue */307307+ queue_work(iavf_wq, &adapter->adminq_task);307308308309 return IRQ_HANDLED;309310}···11371136 rss->state = IAVF_ADV_RSS_DEL_REQUEST;11381137 spin_unlock_bh(&adapter->adv_rss_lock);1139113811401140- if (!(adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) &&11411141- adapter->state != __IAVF_RESETTING) {11391139+ if (!(adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)) {11421140 /* cancel any current operation */11431141 adapter->current_op = VIRTCHNL_OP_UNKNOWN;11441142 /* Schedule operations to close down the HW. Don't wait···21202120 "Requested %d queues, but PF only gave us %d.\n",21212121 num_req_queues,21222122 adapter->vsi_res->num_queue_pairs);21232123- adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;21232123+ adapter->flags |= IAVF_FLAG_REINIT_MSIX_NEEDED;21242124 adapter->num_req_queues = adapter->vsi_res->num_queue_pairs;21252125 iavf_schedule_reset(adapter);21262126···23742374 struct iavf_hw *hw = &adapter->hw;23752375 u32 reg_val;2376237623772377- if (!mutex_trylock(&adapter->crit_lock))23772377+ if (!mutex_trylock(&adapter->crit_lock)) {23782378+ if (adapter->state == __IAVF_REMOVE)23792379+ return;23802380+23782381 goto restart_watchdog;23822382+ }2379238323802384 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)23812385 iavf_change_state(adapter, __IAVF_COMM_FAILED);2382238623832383- if (adapter->flags & IAVF_FLAG_RESET_NEEDED &&23842384- adapter->state != __IAVF_RESETTING) {23852385- iavf_change_state(adapter, __IAVF_RESETTING);23872387+ if (adapter->flags & IAVF_FLAG_RESET_NEEDED) {23862388 adapter->aq_required = 0;23872389 adapter->current_op = VIRTCHNL_OP_UNKNOWN;23902390+ mutex_unlock(&adapter->crit_lock);23912391+ queue_work(iavf_wq, &adapter->reset_task);23922392+ return;23882393 }2389239423902395 switch (adapter->state) {···24242419 msecs_to_jiffies(1));24252420 return;24262421 case __IAVF_INIT_FAILED:24222422+ if (test_bit(__IAVF_IN_REMOVE_TASK,24232423+ &adapter->crit_section)) {24242424+ /* Do not update the state and do not reschedule24252425+ * watchdog task, iavf_remove should handle this state24262426+ * as it can loop forever24272427+ */24282428+ mutex_unlock(&adapter->crit_lock);24292429+ return;24302430+ }24272431 if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) {24282432 dev_err(&adapter->pdev->dev,24292433 "Failed to communicate with PF; waiting before retry\n");···24492435 queue_delayed_work(iavf_wq, &adapter->watchdog_task, HZ);24502436 return;24512437 case __IAVF_COMM_FAILED:24382438+ if (test_bit(__IAVF_IN_REMOVE_TASK,24392439+ &adapter->crit_section)) {24402440+ /* Set state to __IAVF_INIT_FAILED and perform remove24412441+ * steps. Remove IAVF_FLAG_PF_COMMS_FAILED so the task24422442+ * doesn't bring the state back to __IAVF_COMM_FAILED.24432443+ */24442444+ iavf_change_state(adapter, __IAVF_INIT_FAILED);24452445+ adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED;24462446+ mutex_unlock(&adapter->crit_lock);24472447+ return;24482448+ }24522449 reg_val = rd32(hw, IAVF_VFGEN_RSTAT) &24532450 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;24542451 if (reg_val == VIRTCHNL_VFR_VFACTIVE ||···25322507 schedule_delayed_work(&adapter->client_task, msecs_to_jiffies(5));25332508 mutex_unlock(&adapter->crit_lock);25342509restart_watchdog:25352535- queue_work(iavf_wq, &adapter->adminq_task);25102510+ if (adapter->state >= __IAVF_DOWN)25112511+ queue_work(iavf_wq, &adapter->adminq_task);25362512 if (adapter->aq_required)25372513 queue_delayed_work(iavf_wq, &adapter->watchdog_task,25382514 msecs_to_jiffies(20));···26272601 /* When device is being removed it doesn't make sense to run the reset26282602 * task, just return in such a case.26292603 */26302630- if (mutex_is_locked(&adapter->remove_lock))26312631- return;26042604+ if (!mutex_trylock(&adapter->crit_lock)) {26052605+ if (adapter->state != __IAVF_REMOVE)26062606+ queue_work(iavf_wq, &adapter->reset_task);2632260726332633- if (iavf_lock_timeout(&adapter->crit_lock, 200)) {26342634- schedule_work(&adapter->reset_task);26352608 return;26362609 }26102610+26372611 while (!mutex_trylock(&adapter->client_lock))26382612 usleep_range(500, 1000);26392613 if (CLIENT_ENABLED(adapter)) {···26882662 reg_val);26892663 iavf_disable_vf(adapter);26902664 mutex_unlock(&adapter->client_lock);26652665+ mutex_unlock(&adapter->crit_lock);26912666 return; /* Do not attempt to reinit. It's dead, Jim. */26922667 }26932668···26972670 * ndo_open() returning, so we can't assume it means all our open26982671 * tasks have finished, since we're not holding the rtnl_lock here.26992672 */27002700- running = ((adapter->state == __IAVF_RUNNING) ||27012701- (adapter->state == __IAVF_RESETTING));26732673+ running = adapter->state == __IAVF_RUNNING;2702267427032675 if (running) {27042676 netdev->flags &= ~IFF_UP;···27272701 err);27282702 adapter->aq_required = 0;2729270327302730- if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) {27042704+ if ((adapter->flags & IAVF_FLAG_REINIT_MSIX_NEEDED) ||27052705+ (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED)) {27312706 err = iavf_reinit_interrupt_scheme(adapter);27322707 if (err)27332708 goto reset_err;···28002773 if (err)28012774 goto reset_err;2802277528032803- if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) {27762776+ if ((adapter->flags & IAVF_FLAG_REINIT_MSIX_NEEDED) ||27772777+ (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED)) {28042778 err = iavf_request_traffic_irqs(adapter, netdev->name);28052779 if (err)28062780 goto reset_err;2807278128082808- adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;27822782+ adapter->flags &= ~IAVF_FLAG_REINIT_MSIX_NEEDED;28092783 }2810278428112785 iavf_configure(adapter);···28212793 iavf_change_state(adapter, __IAVF_DOWN);28222794 wake_up(&adapter->down_waitqueue);28232795 }27962796+27972797+ adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;27982798+28242799 mutex_unlock(&adapter->client_lock);28252800 mutex_unlock(&adapter->crit_lock);28262801···28572826 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)28582827 goto out;2859282828292829+ if (!mutex_trylock(&adapter->crit_lock)) {28302830+ if (adapter->state == __IAVF_REMOVE)28312831+ return;28322832+28332833+ queue_work(iavf_wq, &adapter->adminq_task);28342834+ goto out;28352835+ }28362836+28602837 event.buf_len = IAVF_MAX_AQ_BUF_SIZE;28612838 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);28622839 if (!event.msg_buf)28632840 goto out;2864284128652865- if (iavf_lock_timeout(&adapter->crit_lock, 200))28662866- goto freedom;28672842 do {28682843 ret = iavf_clean_arq_element(hw, &event, &pending);28692844 v_op = (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);···28852848 } while (pending);28862849 mutex_unlock(&adapter->crit_lock);2887285028512851+ if ((adapter->flags & IAVF_FLAG_SETUP_NETDEV_FEATURES)) {28522852+ if (adapter->netdev_registered ||28532853+ !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {28542854+ struct net_device *netdev = adapter->netdev;28552855+28562856+ rtnl_lock();28572857+ netdev_update_features(netdev);28582858+ rtnl_unlock();28592859+ /* Request VLAN offload settings */28602860+ if (VLAN_V2_ALLOWED(adapter))28612861+ iavf_set_vlan_offload_features28622862+ (adapter, 0, netdev->features);28632863+28642864+ iavf_set_queue_vlan_tag_loc(adapter);28652865+ }28662866+28672867+ adapter->flags &= ~IAVF_FLAG_SETUP_NETDEV_FEATURES;28682868+ }28882869 if ((adapter->flags &28892870 (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED)) ||28902871 adapter->state == __IAVF_RESETTING)···38553800 struct iavf_adapter *adapter = netdev_priv(netdev);38563801 int status;3857380238583858- if (adapter->state <= __IAVF_DOWN_PENDING)38593859- return 0;38033803+ mutex_lock(&adapter->crit_lock);3860380438613861- while (!mutex_trylock(&adapter->crit_lock))38623862- usleep_range(500, 1000);38053805+ if (adapter->state <= __IAVF_DOWN_PENDING) {38063806+ mutex_unlock(&adapter->crit_lock);38073807+ return 0;38083808+ }3863380938643810 set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);38653811 if (CLIENT_ENABLED(adapter))···39093853 iavf_notify_client_l2_params(&adapter->vsi);39103854 adapter->flags |= IAVF_FLAG_SERVICE_CLIENT_REQUESTED;39113855 }39123912- adapter->flags |= IAVF_FLAG_RESET_NEEDED;39133913- queue_work(iavf_wq, &adapter->reset_task);38563856+38573857+ if (netif_running(netdev)) {38583858+ adapter->flags |= IAVF_FLAG_RESET_NEEDED;38593859+ queue_work(iavf_wq, &adapter->reset_task);38603860+ }3914386139153862 return 0;39163863}···44904431 */44914432 mutex_init(&adapter->crit_lock);44924433 mutex_init(&adapter->client_lock);44934493- mutex_init(&adapter->remove_lock);44944434 mutex_init(&hw->aq.asq_mutex);44954435 mutex_init(&hw->aq.arq_mutex);44964436···46054547static void iavf_remove(struct pci_dev *pdev)46064548{46074549 struct iavf_adapter *adapter = iavf_pdev_to_adapter(pdev);46084608- enum iavf_state_t prev_state = adapter->last_state;46094550 struct net_device *netdev = adapter->netdev;46104551 struct iavf_fdir_fltr *fdir, *fdirtmp;46114552 struct iavf_vlan_filter *vlf, *vlftmp;···46134556 struct iavf_cloud_filter *cf, *cftmp;46144557 struct iavf_hw *hw = &adapter->hw;46154558 int err;46164616- /* Indicate we are in remove and not to run reset_task */46174617- mutex_lock(&adapter->remove_lock);46184618- cancel_work_sync(&adapter->reset_task);45594559+45604560+ set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);45614561+ /* Wait until port initialization is complete.45624562+ * There are flows where register/unregister netdev may race.45634563+ */45644564+ while (1) {45654565+ mutex_lock(&adapter->crit_lock);45664566+ if (adapter->state == __IAVF_RUNNING ||45674567+ adapter->state == __IAVF_DOWN ||45684568+ adapter->state == __IAVF_INIT_FAILED) {45694569+ mutex_unlock(&adapter->crit_lock);45704570+ break;45714571+ }45724572+45734573+ mutex_unlock(&adapter->crit_lock);45744574+ usleep_range(500, 1000);45754575+ }46194576 cancel_delayed_work_sync(&adapter->watchdog_task);46204620- cancel_delayed_work_sync(&adapter->client_task);45774577+46214578 if (adapter->netdev_registered) {46224622- unregister_netdev(netdev);45794579+ rtnl_lock();45804580+ unregister_netdevice(netdev);46234581 adapter->netdev_registered = false;45824582+ rtnl_unlock();46244583 }46254584 if (CLIENT_ALLOWED(adapter)) {46264585 err = iavf_lan_del_device(adapter);···46454572 err);46464573 }4647457445754575+ mutex_lock(&adapter->crit_lock);45764576+ dev_info(&adapter->pdev->dev, "Remove device\n");45774577+ iavf_change_state(adapter, __IAVF_REMOVE);45784578+46484579 iavf_request_reset(adapter);46494580 msleep(50);46504581 /* If the FW isn't responding, kick it once, but only once. */···46564579 iavf_request_reset(adapter);46574580 msleep(50);46584581 }46594659- if (iavf_lock_timeout(&adapter->crit_lock, 5000))46604660- dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__);4661458246624662- dev_info(&adapter->pdev->dev, "Removing device\n");45834583+ iavf_misc_irq_disable(adapter);46634584 /* Shut down all the garbage mashers on the detention level */46644664- iavf_change_state(adapter, __IAVF_REMOVE);45854585+ cancel_work_sync(&adapter->reset_task);45864586+ cancel_delayed_work_sync(&adapter->watchdog_task);45874587+ cancel_work_sync(&adapter->adminq_task);45884588+ cancel_delayed_work_sync(&adapter->client_task);45894589+46654590 adapter->aq_required = 0;46664591 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;4667459246684593 iavf_free_all_tx_resources(adapter);46694594 iavf_free_all_rx_resources(adapter);46704670- iavf_misc_irq_disable(adapter);46714595 iavf_free_misc_irq(adapter);46724672-46734673- /* In case we enter iavf_remove from erroneous state, free traffic irqs46744674- * here, so as to not cause a kernel crash, when calling46754675- * iavf_reset_interrupt_capability.46764676- */46774677- if ((adapter->last_state == __IAVF_RESETTING &&46784678- prev_state != __IAVF_DOWN) ||46794679- (adapter->last_state == __IAVF_RUNNING &&46804680- !(netdev->flags & IFF_UP)))46814681- iavf_free_traffic_irqs(adapter);4682459646834597 iavf_reset_interrupt_capability(adapter);46844598 iavf_free_q_vectors(adapter);46854685-46864686- cancel_delayed_work_sync(&adapter->watchdog_task);46874687-46884688- cancel_work_sync(&adapter->adminq_task);4689459946904600 iavf_free_rss(adapter);46914601···46854621 mutex_destroy(&adapter->client_lock);46864622 mutex_unlock(&adapter->crit_lock);46874623 mutex_destroy(&adapter->crit_lock);46884688- mutex_unlock(&adapter->remove_lock);46894689- mutex_destroy(&adapter->remove_lock);4690462446914625 iounmap(hw->hw_addr);46924626 pci_release_regions(pdev);
+41-23
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
···18351835}1836183618371837/**18381838+ * iavf_netdev_features_vlan_strip_set - update vlan strip status18391839+ * @netdev: ptr to netdev being adjusted18401840+ * @enable: enable or disable vlan strip18411841+ *18421842+ * Helper function to change vlan strip status in netdev->features.18431843+ */18441844+static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,18451845+ const bool enable)18461846+{18471847+ if (enable)18481848+ netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;18491849+ else18501850+ netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;18511851+}18521852+18531853+/**18381854 * iavf_virtchnl_completion18391855 * @adapter: adapter structure18401856 * @v_opcode: opcode sent by PF···20732057 }20742058 break;20752059 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:20602060+ dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");20612061+ /* Vlan stripping could not be enabled by ethtool.20622062+ * Disable it in netdev->features.20632063+ */20642064+ iavf_netdev_features_vlan_strip_set(netdev, false);20652065+ break;20762066 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:20772067 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");20682068+ /* Vlan stripping could not be disabled by ethtool.20692069+ * Enable it in netdev->features.20702070+ */20712071+ iavf_netdev_features_vlan_strip_set(netdev, true);20782072 break;20792073 default:20802074 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",···21722146 sizeof(adapter->vlan_v2_caps)));2173214721742148 iavf_process_config(adapter);21752175-21762176- /* unlock crit_lock before acquiring rtnl_lock as other21772177- * processes holding rtnl_lock could be waiting for the same21782178- * crit_lock21792179- */21802180- mutex_unlock(&adapter->crit_lock);21812181- /* VLAN capabilities can change during VFR, so make sure to21822182- * update the netdev features with the new capabilities21832183- */21842184- rtnl_lock();21852185- netdev_update_features(netdev);21862186- rtnl_unlock();21872187- if (iavf_lock_timeout(&adapter->crit_lock, 10000))21882188- dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n",21892189- __FUNCTION__);21902190-21912191- /* Request VLAN offload settings */21922192- if (VLAN_V2_ALLOWED(adapter))21932193- iavf_set_vlan_offload_features(adapter, 0,21942194- netdev->features);21952195-21962196- iavf_set_queue_vlan_tag_loc(adapter);21972197-21492149+ adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;21982150 }21992151 break;22002152 case VIRTCHNL_OP_ENABLE_QUEUES:···23372333 }23382334 spin_unlock_bh(&adapter->adv_rss_lock);23392335 }23362336+ break;23372337+ case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:23382338+ /* PF enabled vlan strip on this VF.23392339+ * Update netdev->features if needed to be in sync with ethtool.23402340+ */23412341+ if (!v_retval)23422342+ iavf_netdev_features_vlan_strip_set(netdev, true);23432343+ break;23442344+ case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:23452345+ /* PF disabled vlan strip on this VF.23462346+ * Update netdev->features if needed to be in sync with ethtool.23472347+ */23482348+ if (!v_retval)23492349+ iavf_netdev_features_vlan_strip_set(netdev, false);23402350 break;23412351 default:23422352 if (adapter->current_op && (v_opcode != adapter->current_op))
+11-1
drivers/net/ethernet/intel/ice/ice.h
···483483 ICE_FLAG_MDD_AUTO_RESET_VF,484484 ICE_FLAG_LINK_LENIENT_MODE_ENA,485485 ICE_FLAG_PLUG_AUX_DEV,486486+ ICE_FLAG_MTU_CHANGED,486487 ICE_PF_FLAGS_NBITS /* must be last */487488};488489···898897 */899898static inline void ice_clear_rdma_cap(struct ice_pf *pf)900899{901901- ice_unplug_aux_dev(pf);900900+ /* We can directly unplug aux device here only if the flag bit901901+ * ICE_FLAG_PLUG_AUX_DEV is not set because ice_unplug_aux_dev()902902+ * could race with ice_plug_aux_dev() called from903903+ * ice_service_task(). In this case we only clear that bit now and904904+ * aux device will be unplugged later once ice_plug_aux_device()905905+ * called from ice_service_task() finishes (see ice_service_task()).906906+ */907907+ if (!test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))908908+ ice_unplug_aux_dev(pf);909909+902910 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);903911 clear_bit(ICE_FLAG_AUX_ENA, pf->flags);904912}
+1-1
drivers/net/ethernet/intel/ice/ice_ethtool.c
···22982298 if (err)22992299 goto done;2300230023012301- curr_link_speed = pi->phy.link_info.link_speed;23012301+ curr_link_speed = pi->phy.curr_user_speed_req;23022302 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);2303230323042304 /* If speed didn't get set, set it to what it currently is.
+26-17
drivers/net/ethernet/intel/ice/ice_main.c
···22552255 return;22562256 }2257225722582258- if (test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))22582258+ if (test_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags)) {22592259+ /* Plug aux device per request */22592260 ice_plug_aux_dev(pf);22612261+22622262+ /* Mark plugging as done but check whether unplug was22632263+ * requested during ice_plug_aux_dev() call22642264+ * (e.g. from ice_clear_rdma_cap()) and if so then22652265+ * plug aux device.22662266+ */22672267+ if (!test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))22682268+ ice_unplug_aux_dev(pf);22692269+ }22702270+22712271+ if (test_and_clear_bit(ICE_FLAG_MTU_CHANGED, pf->flags)) {22722272+ struct iidc_event *event;22732273+22742274+ event = kzalloc(sizeof(*event), GFP_KERNEL);22752275+ if (event) {22762276+ set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);22772277+ ice_send_event_to_aux(pf, event);22782278+ kfree(event);22792279+ }22802280+ }2260228122612282 ice_clean_adminq_subtask(pf);22622283 ice_check_media_subtask(pf);···30443023 struct iidc_event *event;3045302430463025 ena_mask &= ~ICE_AUX_CRIT_ERR;30473047- event = kzalloc(sizeof(*event), GFP_KERNEL);30263026+ event = kzalloc(sizeof(*event), GFP_ATOMIC);30483027 if (event) {30493028 set_bit(IIDC_EVENT_CRIT_ERR, event->type);30503029 /* report the entire OICR value to AUX driver */···68436822 struct ice_netdev_priv *np = netdev_priv(netdev);68446823 struct ice_vsi *vsi = np->vsi;68456824 struct ice_pf *pf = vsi->back;68466846- struct iidc_event *event;68476825 u8 count = 0;68486826 int err = 0;68496827···68776857 return -EBUSY;68786858 }6879685968806880- event = kzalloc(sizeof(*event), GFP_KERNEL);68816881- if (!event)68826882- return -ENOMEM;68836883-68846884- set_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);68856885- ice_send_event_to_aux(pf, event);68866886- clear_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);68876887-68886860 netdev->mtu = (unsigned int)new_mtu;6889686168906862 /* if VSI is up, bring it down and then back up */···68846872 err = ice_down(vsi);68856873 if (err) {68866874 netdev_err(netdev, "change MTU if_down err %d\n", err);68876887- goto event_after;68756875+ return err;68886876 }6889687768906878 err = ice_up(vsi);68916879 if (err) {68926880 netdev_err(netdev, "change MTU if_up err %d\n", err);68936893- goto event_after;68816881+ return err;68946882 }68956883 }6896688468976885 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);68986898-event_after:68996899- set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);69006900- ice_send_event_to_aux(pf, event);69016901- kfree(event);68866886+ set_bit(ICE_FLAG_MTU_CHANGED, pf->flags);6902688769036888 return err;69046889}
-18
drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c
···2182218221832183 dev = ice_pf_to_dev(pf);2184218421852185- /* single place to detect unsuccessful return values */21862186- if (v_retval) {21872187- vf->num_inval_msgs++;21882188- dev_info(dev, "VF %d failed opcode %d, retval: %d\n", vf->vf_id,21892189- v_opcode, v_retval);21902190- if (vf->num_inval_msgs > ICE_DFLT_NUM_INVAL_MSGS_ALLOWED) {21912191- dev_err(dev, "Number of invalid messages exceeded for VF %d\n",21922192- vf->vf_id);21932193- dev_err(dev, "Use PF Control I/F to enable the VF\n");21942194- set_bit(ICE_VF_STATE_DIS, vf->vf_states);21952195- return -EIO;21962196- }21972197- } else {21982198- vf->num_valid_msgs++;21992199- /* reset the invalid counter, if a valid message is received. */22002200- vf->num_inval_msgs = 0;22012201- }22022202-22032185 aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,22042186 msg, msglen, NULL);22052187 if (aq_ret && pf->hw.mailboxq.sq_last_status != ICE_AQ_RC_ENOSYS) {
-3
drivers/net/ethernet/intel/ice/ice_virtchnl_pf.h
···1414#define ICE_MAX_MACADDR_PER_VF 1815151616/* Malicious Driver Detection */1717-#define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED 101817#define ICE_MDD_EVENTS_THRESHOLD 3019182019/* Static VF transaction/status register def */···133134 unsigned int max_tx_rate; /* Maximum Tx bandwidth limit in Mbps */134135 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */135136136136- u64 num_inval_msgs; /* number of continuous invalid msgs */137137- u64 num_valid_msgs; /* number of valid msgs detected */138137 unsigned long vf_caps; /* VF's adv. capabilities */139138 u8 num_req_qs; /* num of queue pairs requested by VF */140139 u16 num_mac;
···554554 dev_info(prestera_dev(sw), "using random base mac address\n");555555 }556556 of_node_put(base_mac_np);557557+ of_node_put(np);557558558559 return prestera_hw_switch_mac_set(sw, sw->base_mac);559560}
···5858 struct sparx5 *sparx5 = port->sparx5;5959 int ret;60606161- /* Make the port a member of the VLAN */6262- set_bit(port->portno, sparx5->vlan_mask[vid]);6363- ret = sparx5_vlant_set_mask(sparx5, vid);6464- if (ret)6565- return ret;6666-6767- /* Default ingress vlan classification */6868- if (pvid)6969- port->pvid = vid;7070-7161 /* Untagged egress vlan classification */7262 if (untagged && port->vid != vid) {7363 if (port->vid) {···6878 }6979 port->vid = vid;7080 }8181+8282+ /* Make the port a member of the VLAN */8383+ set_bit(port->portno, sparx5->vlan_mask[vid]);8484+ ret = sparx5_vlant_set_mask(sparx5, vid);8585+ if (ret)8686+ return ret;8787+8888+ /* Default ingress vlan classification */8989+ if (pvid)9090+ port->pvid = vid;71917292 sparx5_vlan_port_apply(sparx5, port);7393
+4-1
drivers/net/ethernet/nxp/lpc_eth.c
···14711471{14721472 struct net_device *ndev = platform_get_drvdata(pdev);14731473 struct netdata_local *pldat;14741474+ int ret;1474147514751476 if (device_may_wakeup(&pdev->dev))14761477 disable_irq_wake(ndev->irq);···14811480 pldat = netdev_priv(ndev);1482148114831482 /* Enable interface clock */14841484- clk_enable(pldat->clk);14831483+ ret = clk_enable(pldat->clk);14841484+ if (ret)14851485+ return ret;1485148614861487 /* Reset and initialize */14871488 __lpc_eth_reset(pldat);
···233233 return;234234235235 for (i = 0; i < shadow->nr_grants; i++) {236236- if (unlikely(gnttab_query_foreign_access(shadow->gref[i]))) {236236+ if (unlikely(!gnttab_try_end_foreign_access(shadow->gref[i]))) {237237 shost_printk(KERN_ALERT, info->host, KBUILD_MODNAME238238 "grant still in use by backend\n");239239 BUG();240240 }241241- gnttab_end_foreign_access(shadow->gref[i], 0, 0UL);242241 }243242244243 kfree(shadow->sg);
···147147 * memory mapped space.148148 * The BRG clock is the QE clock divided by 2.149149 * It was set up long ago during the initial boot phase and is150150- * is given to us.150150+ * given to us.151151 * Baud rate clocks are zero-based in the driver code (as that maps152152 * to port numbers). Documentation uses 1-based numbering.153153 */···421421422422 for (i = 0; i < be32_to_cpu(ucode->count); i++)423423 iowrite32be(be32_to_cpu(code[i]), &qe_immr->iram.idata);424424-424424+425425 /* Set I-RAM Ready Register */426426 iowrite32be(QE_IRAM_READY, &qe_immr->iram.iready);427427}
+2
drivers/soc/fsl/qe/qe_io.c
···3535 if (ret)3636 return ret;3737 par_io = ioremap(res.start, resource_size(&res));3838+ if (!par_io)3939+ return -ENOMEM;38403941 if (!of_property_read_u32(np, "num-ports", &num_ports))4042 num_par_io_ports = num_ports;
···102102since mlme_priv is a shared resource between many threads,103103like ISR/Call-Back functions, the OID handlers, and even timer functions.104104105105-106105Each struct __queue has its own locks, already.107107-Other items are protected by mlme_priv.lock.106106+Other items in mlme_priv are protected by mlme_priv.lock, while items in107107+xmit_priv are protected by xmit_priv.lock.108108109109To avoid possible dead lock, any thread trying to modifiying mlme_priv110110SHALL not lock up more than one locks at a time!111111112112+The only exception is that queue functions which take the __queue.lock113113+may be called with the xmit_priv.lock held. In this case the order114114+MUST always be first lock xmit_priv.lock and then call any queue functions115115+which take __queue.lock.112116*/113117114118
+3-1
drivers/tee/optee/ffa_abi.c
···869869 optee_supp_init(&optee->supp);870870 ffa_dev_set_drvdata(ffa_dev, optee);871871 ctx = teedev_open(optee->teedev);872872- if (IS_ERR(ctx))872872+ if (IS_ERR(ctx)) {873873+ rc = PTR_ERR(ctx);873874 goto err_rhashtable_free;875875+ }874876 optee->ctx = ctx;875877 rc = optee_notif_init(optee, OPTEE_DEFAULT_MAX_NOTIF_VALUE);876878 if (rc)
+3-1
drivers/tee/optee/smc_abi.c
···1417141714181418 platform_set_drvdata(pdev, optee);14191419 ctx = teedev_open(optee->teedev);14201420- if (IS_ERR(ctx))14201420+ if (IS_ERR(ctx)) {14211421+ rc = PTR_ERR(ctx);14211422 goto err_supp_uninit;14231423+ }14221424 optee->ctx = ctx;14231425 rc = optee_notif_init(optee, max_notif_value);14241426 if (rc)
+3-2
drivers/thermal/thermal_netlink.c
···419419 for (i = 0; i < tz->trips; i++) {420420421421 enum thermal_trip_type type;422422- int temp, hyst;422422+ int temp, hyst = 0;423423424424 tz->ops->get_trip_type(tz, i, &type);425425 tz->ops->get_trip_temp(tz, i, &temp);426426- tz->ops->get_trip_hyst(tz, i, &hyst);426426+ if (tz->ops->get_trip_hyst)427427+ tz->ops->get_trip_hyst(tz, i, &hyst);427428428429 if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID, i) ||429430 nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, type) ||
+18-8
drivers/usb/host/xen-hcd.c
···716716 return 0;717717}718718719719-static void xenhcd_gnttab_done(struct usb_shadow *shadow)719719+static void xenhcd_gnttab_done(struct xenhcd_info *info, unsigned int id)720720{721721+ struct usb_shadow *shadow = info->shadow + id;721722 int nr_segs = 0;722723 int i;723724···727726 if (xenusb_pipeisoc(shadow->req.pipe))728727 nr_segs += shadow->req.u.isoc.nr_frame_desc_segs;729728730730- for (i = 0; i < nr_segs; i++)731731- gnttab_end_foreign_access(shadow->req.seg[i].gref, 0, 0UL);729729+ for (i = 0; i < nr_segs; i++) {730730+ if (!gnttab_try_end_foreign_access(shadow->req.seg[i].gref))731731+ xenhcd_set_error(info, "backend didn't release grant");732732+ }732733733734 shadow->req.nr_buffer_segs = 0;734735 shadow->req.u.isoc.nr_frame_desc_segs = 0;···844841 list_for_each_entry_safe(urbp, tmp, &info->in_progress_list, list) {845842 req_id = urbp->req_id;846843 if (!urbp->unlinked) {847847- xenhcd_gnttab_done(&info->shadow[req_id]);844844+ xenhcd_gnttab_done(info, req_id);845845+ if (info->error)846846+ return;848847 if (urbp->urb->status == -EINPROGRESS)849848 /* not dequeued */850849 xenhcd_giveback_urb(info, urbp->urb,···947942 rp = info->urb_ring.sring->rsp_prod;948943 if (RING_RESPONSE_PROD_OVERFLOW(&info->urb_ring, rp)) {949944 xenhcd_set_error(info, "Illegal index on urb-ring");950950- spin_unlock_irqrestore(&info->lock, flags);951951- return 0;945945+ goto err;952946 }953947 rmb(); /* ensure we see queued responses up to "rp" */954948···956952 id = res.id;957953 if (id >= XENUSB_URB_RING_SIZE) {958954 xenhcd_set_error(info, "Illegal data on urb-ring");959959- continue;955955+ goto err;960956 }961957962958 if (likely(xenusb_pipesubmit(info->shadow[id].req.pipe))) {963963- xenhcd_gnttab_done(&info->shadow[id]);959959+ xenhcd_gnttab_done(info, id);960960+ if (info->error)961961+ goto err;964962 urb = info->shadow[id].urb;965963 if (likely(urb)) {966964 urb->actual_length = res.actual_length;···984978 spin_unlock_irqrestore(&info->lock, flags);985979986980 return more_to_do;981981+982982+ err:983983+ spin_unlock_irqrestore(&info->lock, flags);984984+ return 0;987985}988986989987static int xenhcd_conn_notify(struct xenhcd_info *info)
+32-2
drivers/vdpa/mlx5/net/mlx5_vnet.c
···1563156315641564 switch (cmd) {15651565 case VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET:15661566+ /* This mq feature check aligns with pre-existing userspace15671567+ * implementation.15681568+ *15691569+ * Without it, an untrusted driver could fake a multiqueue config15701570+ * request down to a non-mq device that may cause kernel to15711571+ * panic due to uninitialized resources for extra vqs. Even with15721572+ * a well behaving guest driver, it is not expected to allow15731573+ * changing the number of vqs on a non-mq device.15741574+ */15751575+ if (!MLX5_FEATURE(mvdev, VIRTIO_NET_F_MQ))15761576+ break;15771577+15661578 read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)&mq, sizeof(mq));15671579 if (read != sizeof(mq))15681580 break;1569158115701582 newqps = mlx5vdpa16_to_cpu(mvdev, mq.virtqueue_pairs);15831583+ if (newqps < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN ||15841584+ newqps > mlx5_vdpa_max_qps(mvdev->max_vqs))15851585+ break;15861586+15711587 if (ndev->cur_num_vqs == 2 * newqps) {15721588 status = VIRTIO_NET_OK;15731589 break;···19131897 return ndev->mvdev.mlx_features;19141898}1915189919161916-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)19001900+static int verify_driver_features(struct mlx5_vdpa_dev *mvdev, u64 features)19171901{19021902+ /* Minimum features to expect */19181903 if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))19191904 return -EOPNOTSUPP;19051905+19061906+ /* Double check features combination sent down by the driver.19071907+ * Fail invalid features due to absence of the depended feature.19081908+ *19091909+ * Per VIRTIO v1.1 specification, section 5.1.3.1 Feature bit19101910+ * requirements: "VIRTIO_NET_F_MQ Requires VIRTIO_NET_F_CTRL_VQ".19111911+ * By failing the invalid features sent down by untrusted drivers,19121912+ * we're assured the assumption made upon is_index_valid() and19131913+ * is_ctrl_vq_idx() will not be compromised.19141914+ */19151915+ if ((features & (BIT_ULL(VIRTIO_NET_F_MQ) | BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) ==19161916+ BIT_ULL(VIRTIO_NET_F_MQ))19171917+ return -EINVAL;1920191819211919 return 0;19221920}···2007197720081978 print_features(mvdev, features, true);2009197920102010- err = verify_min_features(mvdev, features);19801980+ err = verify_driver_features(mvdev, features);20111981 if (err)20121982 return err;20131983
+1-1
drivers/vdpa/vdpa.c
···393393 * If it does happen we assume a legacy guest.394394 */395395 if (!vdev->features_valid)396396- vdpa_set_features(vdev, 0, true);396396+ vdpa_set_features_unlocked(vdev, 0);397397 ops->get_config(vdev, offset, buf, len);398398}399399
···5757 if (last < start)5858 return -EFAULT;59596060+ /* If the range being mapped is [0, ULONG_MAX], split it into two entries6161+ * otherwise its size would overflow u64.6262+ */6363+ if (start == 0 && last == ULONG_MAX) {6464+ u64 mid = last / 2;6565+6666+ vhost_iotlb_add_range_ctx(iotlb, start, mid, addr, perm, opaque);6767+ addr += mid + 1;6868+ start = mid + 1;6969+ }7070+6071 if (iotlb->limit &&6172 iotlb->nmaps == iotlb->limit &&6273 iotlb->flags & VHOST_IOTLB_FLAG_RETIRE) {
+1-1
drivers/vhost/vdpa.c
···286286 if (copy_from_user(&features, featurep, sizeof(features)))287287 return -EFAULT;288288289289- if (vdpa_set_features(vdpa, features, false))289289+ if (vdpa_set_features(vdpa, features))290290 return -EINVAL;291291292292 return 0;
+7-2
drivers/vhost/vhost.c
···11701170 goto done;11711171 }1172117211731173+ if (msg.size == 0) {11741174+ ret = -EINVAL;11751175+ goto done;11761176+ }11771177+11731178 if (dev->msg_handler)11741179 ret = dev->msg_handler(dev, &msg);11751180 else···19861981 return 0;19871982}1988198319891989-static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event)19841984+static int vhost_update_avail_event(struct vhost_virtqueue *vq)19901985{19911986 if (vhost_put_avail_event(vq))19921987 return -EFAULT;···25322527 return false;25332528 }25342529 } else {25352535- r = vhost_update_avail_event(vq, vq->avail_idx);25302530+ r = vhost_update_avail_event(vq);25362531 if (r) {25372532 vq_err(vq, "Failed to update avail event index at %p: %d\n",25382533 vhost_avail_event(vq), r);
-1
drivers/virtio/Kconfig
···105105106106config VIRTIO_MEM107107 tristate "Virtio mem driver"108108- default m109108 depends on X86_64110109 depends on VIRTIO111110 depends on MEMORY_HOTPLUG
+38-18
drivers/virtio/virtio.c
···166166}167167EXPORT_SYMBOL_GPL(virtio_add_status);168168169169-int virtio_finalize_features(struct virtio_device *dev)169169+/* Do some validation, then set FEATURES_OK */170170+static int virtio_features_ok(struct virtio_device *dev)170171{171171- int ret = dev->config->finalize_features(dev);172172 unsigned status;173173+ int ret;173174174175 might_sleep();175175- if (ret)176176- return ret;177176178177 ret = arch_has_restricted_virtio_memory_access();179178 if (ret) {···201202 }202203 return 0;203204}204204-EXPORT_SYMBOL_GPL(virtio_finalize_features);205205206206+/**207207+ * virtio_reset_device - quiesce device for removal208208+ * @dev: the device to reset209209+ *210210+ * Prevents device from sending interrupts and accessing memory.211211+ *212212+ * Generally used for cleanup during driver / device removal.213213+ *214214+ * Once this has been invoked, caller must ensure that215215+ * virtqueue_notify / virtqueue_kick are not in progress.216216+ *217217+ * Note: this guarantees that vq callbacks are not in progress, however caller218218+ * is responsible for preventing access from other contexts, such as a system219219+ * call/workqueue/bh. Invoking virtio_break_device then flushing any such220220+ * contexts is one way to handle that.221221+ * */206222void virtio_reset_device(struct virtio_device *dev)207223{208224 dev->config->reset(dev);···259245 driver_features_legacy = driver_features;260246 }261247262262- /*263263- * Some devices detect legacy solely via F_VERSION_1. Write264264- * F_VERSION_1 to force LE config space accesses before FEATURES_OK for265265- * these when needed.266266- */267267- if (drv->validate && !virtio_legacy_is_little_endian()268268- && device_features & BIT_ULL(VIRTIO_F_VERSION_1)) {269269- dev->features = BIT_ULL(VIRTIO_F_VERSION_1);270270- dev->config->finalize_features(dev);271271- }272272-273248 if (device_features & (1ULL << VIRTIO_F_VERSION_1))274249 dev->features = driver_features & device_features;275250 else···269266 if (device_features & (1ULL << i))270267 __virtio_set_bit(dev, i);271268269269+ err = dev->config->finalize_features(dev);270270+ if (err)271271+ goto err;272272+272273 if (drv->validate) {274274+ u64 features = dev->features;275275+273276 err = drv->validate(dev);274277 if (err)275278 goto err;279279+280280+ /* Did validation change any features? Then write them again. */281281+ if (features != dev->features) {282282+ err = dev->config->finalize_features(dev);283283+ if (err)284284+ goto err;285285+ }276286 }277287278278- err = virtio_finalize_features(dev);288288+ err = virtio_features_ok(dev);279289 if (err)280290 goto err;281291···512496 /* We have a driver! */513497 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);514498515515- ret = virtio_finalize_features(dev);499499+ ret = dev->config->finalize_features(dev);500500+ if (ret)501501+ goto err;502502+503503+ ret = virtio_features_ok(dev);516504 if (ret)517505 goto err;518506
+1-1
drivers/virtio/virtio_vdpa.c
···317317 /* Give virtio_ring a chance to accept features. */318318 vring_transport_features(vdev);319319320320- return vdpa_set_features(vdpa, vdev->features, false);320320+ return vdpa_set_features(vdpa, vdev->features);321321}322322323323static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
+7-18
drivers/xen/gntalloc.c
···169169 __del_gref(gref);170170 }171171172172- /* It's possible for the target domain to map the just-allocated grant173173- * references by blindly guessing their IDs; if this is done, then174174- * __del_gref will leave them in the queue_gref list. They need to be175175- * added to the global list so that we can free them when they are no176176- * longer referenced.177177- */178178- if (unlikely(!list_empty(&queue_gref)))179179- list_splice_tail(&queue_gref, &gref_list);180172 mutex_unlock(&gref_mutex);181173 return rc;182174}183175184176static void __del_gref(struct gntalloc_gref *gref)185177{178178+ unsigned long addr;179179+186180 if (gref->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {187181 uint8_t *tmp = kmap(gref->page);188182 tmp[gref->notify.pgoff] = 0;···190196 gref->notify.flags = 0;191197192198 if (gref->gref_id) {193193- if (gnttab_query_foreign_access(gref->gref_id))194194- return;195195-196196- if (!gnttab_end_foreign_access_ref(gref->gref_id, 0))197197- return;198198-199199- gnttab_free_grant_reference(gref->gref_id);199199+ if (gref->page) {200200+ addr = (unsigned long)page_to_virt(gref->page);201201+ gnttab_end_foreign_access(gref->gref_id, 0, addr);202202+ } else203203+ gnttab_free_grant_reference(gref->gref_id);200204 }201205202206 gref_size--;203207 list_del(&gref->next_gref);204204-205205- if (gref->page)206206- __free_page(gref->page);207208208209 kfree(gref);209210}
+39-32
drivers/xen/grant-table.c
···134134 */135135 unsigned long (*end_foreign_transfer_ref)(grant_ref_t ref);136136 /*137137- * Query the status of a grant entry. Ref parameter is reference of138138- * queried grant entry, return value is the status of queried entry.139139- * Detailed status(writing/reading) can be gotten from the return value140140- * by bit operations.137137+ * Read the frame number related to a given grant reference.141138 */142142- int (*query_foreign_access)(grant_ref_t ref);139139+ unsigned long (*read_frame)(grant_ref_t ref);143140};144141145142struct unmap_refs_callback_data {···281284}282285EXPORT_SYMBOL_GPL(gnttab_grant_foreign_access);283286284284-static int gnttab_query_foreign_access_v1(grant_ref_t ref)285285-{286286- return gnttab_shared.v1[ref].flags & (GTF_reading|GTF_writing);287287-}288288-289289-static int gnttab_query_foreign_access_v2(grant_ref_t ref)290290-{291291- return grstatus[ref] & (GTF_reading|GTF_writing);292292-}293293-294294-int gnttab_query_foreign_access(grant_ref_t ref)295295-{296296- return gnttab_interface->query_foreign_access(ref);297297-}298298-EXPORT_SYMBOL_GPL(gnttab_query_foreign_access);299299-300287static int gnttab_end_foreign_access_ref_v1(grant_ref_t ref, int readonly)301288{302289 u16 flags, nflags;···334353}335354EXPORT_SYMBOL_GPL(gnttab_end_foreign_access_ref);336355356356+static unsigned long gnttab_read_frame_v1(grant_ref_t ref)357357+{358358+ return gnttab_shared.v1[ref].frame;359359+}360360+361361+static unsigned long gnttab_read_frame_v2(grant_ref_t ref)362362+{363363+ return gnttab_shared.v2[ref].full_page.frame;364364+}365365+337366struct deferred_entry {338367 struct list_head list;339368 grant_ref_t ref;···373382 spin_unlock_irqrestore(&gnttab_list_lock, flags);374383 if (_gnttab_end_foreign_access_ref(entry->ref, entry->ro)) {375384 put_free_entry(entry->ref);376376- if (entry->page) {377377- pr_debug("freeing g.e. %#x (pfn %#lx)\n",378378- entry->ref, page_to_pfn(entry->page));379379- put_page(entry->page);380380- } else381381- pr_info("freeing g.e. %#x\n", entry->ref);385385+ pr_debug("freeing g.e. %#x (pfn %#lx)\n",386386+ entry->ref, page_to_pfn(entry->page));387387+ put_page(entry->page);382388 kfree(entry);383389 entry = NULL;384390 } else {···400412static void gnttab_add_deferred(grant_ref_t ref, bool readonly,401413 struct page *page)402414{403403- struct deferred_entry *entry = kmalloc(sizeof(*entry), GFP_ATOMIC);415415+ struct deferred_entry *entry;416416+ gfp_t gfp = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL;404417 const char *what = KERN_WARNING "leaking";418418+419419+ entry = kmalloc(sizeof(*entry), gfp);420420+ if (!page) {421421+ unsigned long gfn = gnttab_interface->read_frame(ref);422422+423423+ page = pfn_to_page(gfn_to_pfn(gfn));424424+ get_page(page);425425+ }405426406427 if (entry) {407428 unsigned long flags;···432435 what, ref, page ? page_to_pfn(page) : -1);433436}434437438438+int gnttab_try_end_foreign_access(grant_ref_t ref)439439+{440440+ int ret = _gnttab_end_foreign_access_ref(ref, 0);441441+442442+ if (ret)443443+ put_free_entry(ref);444444+445445+ return ret;446446+}447447+EXPORT_SYMBOL_GPL(gnttab_try_end_foreign_access);448448+435449void gnttab_end_foreign_access(grant_ref_t ref, int readonly,436450 unsigned long page)437451{438438- if (gnttab_end_foreign_access_ref(ref, readonly)) {439439- put_free_entry(ref);452452+ if (gnttab_try_end_foreign_access(ref)) {440453 if (page != 0)441454 put_page(virt_to_page(page));442455 } else···14241417 .update_entry = gnttab_update_entry_v1,14251418 .end_foreign_access_ref = gnttab_end_foreign_access_ref_v1,14261419 .end_foreign_transfer_ref = gnttab_end_foreign_transfer_ref_v1,14271427- .query_foreign_access = gnttab_query_foreign_access_v1,14201420+ .read_frame = gnttab_read_frame_v1,14281421};1429142214301423static const struct gnttab_ops gnttab_v2_ops = {···14361429 .update_entry = gnttab_update_entry_v2,14371430 .end_foreign_access_ref = gnttab_end_foreign_access_ref_v2,14381431 .end_foreign_transfer_ref = gnttab_end_foreign_transfer_ref_v2,14391439- .query_foreign_access = gnttab_query_foreign_access_v2,14321432+ .read_frame = gnttab_read_frame_v2,14401433};1441143414421435static bool gnttab_need_v2(void)
···379379 unsigned int nr_pages, grant_ref_t *grefs)380380{381381 int err;382382- int i, j;382382+ unsigned int i;383383+ grant_ref_t gref_head;384384+385385+ err = gnttab_alloc_grant_references(nr_pages, &gref_head);386386+ if (err) {387387+ xenbus_dev_fatal(dev, err, "granting access to ring page");388388+ return err;389389+ }383390384391 for (i = 0; i < nr_pages; i++) {385392 unsigned long gfn;···396389 else397390 gfn = virt_to_gfn(vaddr);398391399399- err = gnttab_grant_foreign_access(dev->otherend_id, gfn, 0);400400- if (err < 0) {401401- xenbus_dev_fatal(dev, err,402402- "granting access to ring page");403403- goto fail;404404- }405405- grefs[i] = err;392392+ grefs[i] = gnttab_claim_grant_reference(&gref_head);393393+ gnttab_grant_foreign_access_ref(grefs[i], dev->otherend_id,394394+ gfn, 0);406395407396 vaddr = vaddr + XEN_PAGE_SIZE;408397 }409398410399 return 0;411411-412412-fail:413413- for (j = 0; j < i; j++)414414- gnttab_end_foreign_access_ref(grefs[j], 0);415415- return err;416400}417401EXPORT_SYMBOL_GPL(xenbus_grant_ring);418402
+8-1
fs/afs/write.c
···703703 struct folio *folio;704704 struct page *head_page;705705 ssize_t ret;706706- int n;706706+ int n, skips = 0;707707708708 _enter("%llx,%llx,", start, end);709709···754754#ifdef CONFIG_AFS_FSCACHE755755 folio_wait_fscache(folio);756756#endif757757+ } else {758758+ start += folio_size(folio);757759 }758760 folio_put(folio);761761+ if (wbc->sync_mode == WB_SYNC_NONE) {762762+ if (skips >= 5 || need_resched())763763+ break;764764+ skips++;765765+ }759766 continue;760767 }761768
+18-7
fs/binfmt_elf.c
···11351135 * is then page aligned.11361136 */11371137 load_bias = ELF_PAGESTART(load_bias - vaddr);11381138- }1139113811401140- /*11411141- * Calculate the entire size of the ELF mapping (total_size).11421142- * (Note that load_addr_set is set to true later once the11431143- * initial mapping is performed.)11441144- */11451145- if (!load_addr_set) {11391139+ /*11401140+ * Calculate the entire size of the ELF mapping11411141+ * (total_size), used for the initial mapping,11421142+ * due to load_addr_set which is set to true later11431143+ * once the initial mapping is performed.11441144+ *11451145+ * Note that this is only sensible when the LOAD11461146+ * segments are contiguous (or overlapping). If11471147+ * used for LOADs that are far apart, this would11481148+ * cause the holes between LOADs to be mapped,11491149+ * running the risk of having the mapping fail,11501150+ * as it would be larger than the ELF file itself.11511151+ *11521152+ * As a result, only ET_DYN does this, since11531153+ * some ET_EXEC (e.g. ia64) may have large virtual11541154+ * memory holes between LOADs.11551155+ *11561156+ */11461157 total_size = total_mapping_size(elf_phdata,11471158 elf_ex->e_phnum);11481159 if (!total_size) {
+10
fs/btrfs/ctree.h
···602602 /* Indicate that we want the transaction kthread to commit right now. */603603 BTRFS_FS_COMMIT_TRANS,604604605605+ /* Indicate we have half completed snapshot deletions pending. */606606+ BTRFS_FS_UNFINISHED_DROPS,607607+605608#if BITS_PER_LONG == 32606609 /* Indicate if we have error/warn message printed on 32bit systems */607610 BTRFS_FS_32BIT_ERROR,···11091106 BTRFS_ROOT_QGROUP_FLUSHING,11101107 /* We started the orphan cleanup for this root. */11111108 BTRFS_ROOT_ORPHAN_CLEANUP,11091109+ /* This root has a drop operation that was started previously. */11101110+ BTRFS_ROOT_UNFINISHED_DROP,11121111};11121112+11131113+static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)11141114+{11151115+ clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);11161116+}1113111711141118/*11151119 * Record swapped tree blocks of a subvolume tree for delayed subtree trace
+10
fs/btrfs/disk-io.c
···3813381338143814 set_bit(BTRFS_FS_OPEN, &fs_info->flags);3815381538163816+ /* Kick the cleaner thread so it'll start deleting snapshots. */38173817+ if (test_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags))38183818+ wake_up_process(fs_info->cleaner_kthread);38193819+38163820clear_oneshot:38173821 btrfs_clear_oneshot_options(fs_info);38183822 return 0;···45414537 * still try to wake up the cleaner.45424538 */45434539 kthread_park(fs_info->cleaner_kthread);45404540+45414541+ /*45424542+ * If we had UNFINISHED_DROPS we could still be processing them, so45434543+ * clear that bit and wake up relocation so it can stop.45444544+ */45454545+ btrfs_wake_unfinished_drop(fs_info);4544454645454547 /* wait for the qgroup rescan worker to stop */45464548 btrfs_qgroup_wait_for_completion(fs_info, false);
+10
fs/btrfs/extent-tree.c
···56225622 int ret;56235623 int level;56245624 bool root_dropped = false;56255625+ bool unfinished_drop = false;5625562656265627 btrfs_debug(fs_info, "Drop subvolume %llu", root->root_key.objectid);56275628···56655664 * already dropped.56665665 */56675666 set_bit(BTRFS_ROOT_DELETING, &root->state);56675667+ unfinished_drop = test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state);56685668+56685669 if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) {56695670 level = btrfs_header_level(root->node);56705671 path->nodes[level] = btrfs_lock_root_node(root);···58415838 kfree(wc);58425839 btrfs_free_path(path);58435840out:58415841+ /*58425842+ * We were an unfinished drop root, check to see if there are any58435843+ * pending, and if not clear and wake up any waiters.58445844+ */58455845+ if (!err && unfinished_drop)58465846+ btrfs_maybe_wake_unfinished_drop(fs_info);58475847+58445848 /*58455849 * So if we need to stop dropping the snapshot for whatever reason we58465850 * need to make sure to add it back to the dead root list so that we
+13-3
fs/btrfs/extent_io.c
···68416841{68426842 struct btrfs_fs_info *fs_info = eb->fs_info;6843684368446844+ /*68456845+ * If we are using the commit root we could potentially clear a page68466846+ * Uptodate while we're using the extent buffer that we've previously68476847+ * looked up. We don't want to complain in this case, as the page was68486848+ * valid before, we just didn't write it out. Instead we want to catch68496849+ * the case where we didn't actually read the block properly, which68506850+ * would have !PageUptodate && !PageError, as we clear PageError before68516851+ * reading.68526852+ */68446853 if (fs_info->sectorsize < PAGE_SIZE) {68456845- bool uptodate;68546854+ bool uptodate, error;6846685568476856 uptodate = btrfs_subpage_test_uptodate(fs_info, page,68486857 eb->start, eb->len);68496849- WARN_ON(!uptodate);68586858+ error = btrfs_subpage_test_error(fs_info, page, eb->start, eb->len);68596859+ WARN_ON(!uptodate && !error);68506860 } else {68516851- WARN_ON(!PageUptodate(page));68616861+ WARN_ON(!PageUptodate(page) && !PageError(page));68526862 }68536863}68546864
+28
fs/btrfs/inode.c
···76007600 }7601760176027602 len = min(len, em->len - (start - em->start));76037603+76047604+ /*76057605+ * If we have a NOWAIT request and the range contains multiple extents76067606+ * (or a mix of extents and holes), then we return -EAGAIN to make the76077607+ * caller fallback to a context where it can do a blocking (without76087608+ * NOWAIT) request. This way we avoid doing partial IO and returning76097609+ * success to the caller, which is not optimal for writes and for reads76107610+ * it can result in unexpected behaviour for an application.76117611+ *76127612+ * When doing a read, because we use IOMAP_DIO_PARTIAL when calling76137613+ * iomap_dio_rw(), we can end up returning less data then what the caller76147614+ * asked for, resulting in an unexpected, and incorrect, short read.76157615+ * That is, the caller asked to read N bytes and we return less than that,76167616+ * which is wrong unless we are crossing EOF. This happens if we get a76177617+ * page fault error when trying to fault in pages for the buffer that is76187618+ * associated to the struct iov_iter passed to iomap_dio_rw(), and we76197619+ * have previously submitted bios for other extents in the range, in76207620+ * which case iomap_dio_rw() may return us EIOCBQUEUED if not all of76217621+ * those bios have completed by the time we get the page fault error,76227622+ * which we return back to our caller - we should only return EIOCBQUEUED76237623+ * after we have submitted bios for all the extents in the range.76247624+ */76257625+ if ((flags & IOMAP_NOWAIT) && len < length) {76267626+ free_extent_map(em);76277627+ ret = -EAGAIN;76287628+ goto unlock_err;76297629+ }76307630+76037631 if (write) {76047632 ret = btrfs_get_blocks_direct_write(&em, inode, dio_data,76057633 start, len);
+8-1
fs/btrfs/qgroup.c
···11971197 goto out;1198119811991199 /*12001200+ * Unlock the qgroup_ioctl_lock mutex before waiting for the rescan worker to12011201+ * complete. Otherwise we can deadlock because btrfs_remove_qgroup() needs12021202+ * to lock that mutex while holding a transaction handle and the rescan12031203+ * worker needs to commit a transaction.12041204+ */12051205+ mutex_unlock(&fs_info->qgroup_ioctl_lock);12061206+12071207+ /*12001208 * Request qgroup rescan worker to complete and wait for it. This wait12011209 * must be done before transaction start for quota disable since it may12021210 * deadlock with transaction by the qgroup rescan worker.12031211 */12041212 clear_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);12051213 btrfs_qgroup_wait_for_completion(fs_info, false);12061206- mutex_unlock(&fs_info->qgroup_ioctl_lock);1207121412081215 /*12091216 * 1 For the root item
+13
fs/btrfs/relocation.c
···39603960 int rw = 0;39613961 int err = 0;3962396239633963+ /*39643964+ * This only gets set if we had a half-deleted snapshot on mount. We39653965+ * cannot allow relocation to start while we're still trying to clean up39663966+ * these pending deletions.39673967+ */39683968+ ret = wait_on_bit(&fs_info->flags, BTRFS_FS_UNFINISHED_DROPS, TASK_INTERRUPTIBLE);39693969+ if (ret)39703970+ return ret;39713971+39723972+ /* We may have been woken up by close_ctree, so bail if we're closing. */39733973+ if (btrfs_fs_closing(fs_info))39743974+ return -EINTR;39753975+39633976 bg = btrfs_lookup_block_group(fs_info, group_start);39643977 if (!bg)39653978 return -ENOENT;
+15
fs/btrfs/root-tree.c
···278278279279 WARN_ON(!test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state));280280 if (btrfs_root_refs(&root->root_item) == 0) {281281+ struct btrfs_key drop_key;282282+283283+ btrfs_disk_key_to_cpu(&drop_key, &root->root_item.drop_progress);284284+ /*285285+ * If we have a non-zero drop_progress then we know we286286+ * made it partly through deleting this snapshot, and287287+ * thus we need to make sure we block any balance from288288+ * happening until this snapshot is completely dropped.289289+ */290290+ if (drop_key.objectid != 0 || drop_key.type != 0 ||291291+ drop_key.offset != 0) {292292+ set_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);293293+ set_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state);294294+ }295295+281296 set_bit(BTRFS_ROOT_DEAD_TREE, &root->state);282297 btrfs_add_dead_root(root);283298 }
+1-1
fs/btrfs/subpage.c
···736736 * Since we own the page lock, no one else could touch subpage::writers737737 * and we are safe to do several atomic operations without spinlock.738738 */739739- if (atomic_read(&subpage->writers))739739+ if (atomic_read(&subpage->writers) == 0)740740 /* No writers, locked by plain lock_page() */741741 return unlock_page(page);742742
+63-2
fs/btrfs/transaction.c
···854854static noinline void wait_for_commit(struct btrfs_transaction *commit,855855 const enum btrfs_trans_state min_state)856856{857857- wait_event(commit->commit_wait, commit->state >= min_state);857857+ struct btrfs_fs_info *fs_info = commit->fs_info;858858+ u64 transid = commit->transid;859859+ bool put = false;860860+861861+ while (1) {862862+ wait_event(commit->commit_wait, commit->state >= min_state);863863+ if (put)864864+ btrfs_put_transaction(commit);865865+866866+ if (min_state < TRANS_STATE_COMPLETED)867867+ break;868868+869869+ /*870870+ * A transaction isn't really completed until all of the871871+ * previous transactions are completed, but with fsync we can872872+ * end up with SUPER_COMMITTED transactions before a COMPLETED873873+ * transaction. Wait for those.874874+ */875875+876876+ spin_lock(&fs_info->trans_lock);877877+ commit = list_first_entry_or_null(&fs_info->trans_list,878878+ struct btrfs_transaction,879879+ list);880880+ if (!commit || commit->transid > transid) {881881+ spin_unlock(&fs_info->trans_lock);882882+ break;883883+ }884884+ refcount_inc(&commit->use_count);885885+ put = true;886886+ spin_unlock(&fs_info->trans_lock);887887+ }858888}859889860890int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)···13501320}1351132113521322/*13231323+ * If we had a pending drop we need to see if there are any others left in our13241324+ * dead roots list, and if not clear our bit and wake any waiters.13251325+ */13261326+void btrfs_maybe_wake_unfinished_drop(struct btrfs_fs_info *fs_info)13271327+{13281328+ /*13291329+ * We put the drop in progress roots at the front of the list, so if the13301330+ * first entry doesn't have UNFINISHED_DROP set we can wake everybody13311331+ * up.13321332+ */13331333+ spin_lock(&fs_info->trans_lock);13341334+ if (!list_empty(&fs_info->dead_roots)) {13351335+ struct btrfs_root *root = list_first_entry(&fs_info->dead_roots,13361336+ struct btrfs_root,13371337+ root_list);13381338+ if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state)) {13391339+ spin_unlock(&fs_info->trans_lock);13401340+ return;13411341+ }13421342+ }13431343+ spin_unlock(&fs_info->trans_lock);13441344+13451345+ btrfs_wake_unfinished_drop(fs_info);13461346+}13471347+13481348+/*13531349 * dead roots are old snapshots that need to be deleted. This allocates13541350 * a dirty root struct and adds it into the list of dead roots that need to13551351 * be deleted···13871331 spin_lock(&fs_info->trans_lock);13881332 if (list_empty(&root->root_list)) {13891333 btrfs_grab_root(root);13901390- list_add_tail(&root->root_list, &fs_info->dead_roots);13341334+13351335+ /* We want to process the partially complete drops first. */13361336+ if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state))13371337+ list_add(&root->root_list, &fs_info->dead_roots);13381338+ else13391339+ list_add_tail(&root->root_list, &fs_info->dead_roots);13911340 }13921341 spin_unlock(&fs_info->trans_lock);13931342}
···16821682 */16831683 for (slot = 0; slot < nritems; slot++) {16841684 u32 item_end_expected;16851685+ u64 item_data_end;16851686 int ret;1686168716871688 btrfs_item_key_to_cpu(leaf, &key, slot);···16971696 return -EUCLEAN;16981697 }1699169816991699+ item_data_end = (u64)btrfs_item_offset(leaf, slot) +17001700+ btrfs_item_size(leaf, slot);17001701 /*17011702 * Make sure the offset and ends are right, remember that the17021703 * item data starts at the end of the leaf and grows towards the···17091706 else17101707 item_end_expected = btrfs_item_offset(leaf,17111708 slot - 1);17121712- if (unlikely(btrfs_item_data_end(leaf, slot) != item_end_expected)) {17091709+ if (unlikely(item_data_end != item_end_expected)) {17131710 generic_err(leaf, slot,17141714- "unexpected item end, have %u expect %u",17151715- btrfs_item_data_end(leaf, slot),17161716- item_end_expected);17111711+ "unexpected item end, have %llu expect %u",17121712+ item_data_end, item_end_expected);17171713 return -EUCLEAN;17181714 }17191715···17211719 * just in case all the items are consistent to each other, but17221720 * all point outside of the leaf.17231721 */17241724- if (unlikely(btrfs_item_data_end(leaf, slot) >17251725- BTRFS_LEAF_DATA_SIZE(fs_info))) {17221722+ if (unlikely(item_data_end > BTRFS_LEAF_DATA_SIZE(fs_info))) {17261723 generic_err(leaf, slot,17271727- "slot end outside of leaf, have %u expect range [0, %u]",17281728- btrfs_item_data_end(leaf, slot),17291729- BTRFS_LEAF_DATA_SIZE(fs_info));17241724+ "slot end outside of leaf, have %llu expect range [0, %u]",17251725+ item_data_end, BTRFS_LEAF_DATA_SIZE(fs_info));17301726 return -EUCLEAN;17311727 }17321728
+49-12
fs/btrfs/tree-log.c
···13621362 inode, name, namelen);13631363 kfree(name);13641364 iput(dir);13651365+ /*13661366+ * Whenever we need to check if a name exists or not, we13671367+ * check the subvolume tree. So after an unlink we must13681368+ * run delayed items, so that future checks for a name13691369+ * during log replay see that the name does not exists13701370+ * anymore.13711371+ */13721372+ if (!ret)13731373+ ret = btrfs_run_delayed_items(trans);13651374 if (ret)13661375 goto out;13671376 goto again;···16231614 */16241615 if (!ret && inode->i_nlink == 0)16251616 inc_nlink(inode);16171617+ /*16181618+ * Whenever we need to check if a name exists or16191619+ * not, we check the subvolume tree. So after an16201620+ * unlink we must run delayed items, so that future16211621+ * checks for a name during log replay see that the16221622+ * name does not exists anymore.16231623+ */16241624+ if (!ret)16251625+ ret = btrfs_run_delayed_items(trans);16261626 }16271627 if (ret < 0)16281628 goto out;···4653463546544636/*46554637 * Log all prealloc extents beyond the inode's i_size to make sure we do not46564656- * lose them after doing a fast fsync and replaying the log. We scan the46384638+ * lose them after doing a full/fast fsync and replaying the log. We scan the46574639 * subvolume's root instead of iterating the inode's extent map tree because46584640 * otherwise we can log incorrect extent items based on extent map conversion.46594641 * That can happen due to the fact that extent maps are merged when they···54325414 struct btrfs_log_ctx *ctx,54335415 bool *need_log_inode_item)54345416{54175417+ const u64 i_size = i_size_read(&inode->vfs_inode);54355418 struct btrfs_root *root = inode->root;54365419 int ins_start_slot = 0;54375420 int ins_nr = 0;···54535434 if (min_key->type > max_key->type)54545435 break;5455543654565456- if (min_key->type == BTRFS_INODE_ITEM_KEY)54375437+ if (min_key->type == BTRFS_INODE_ITEM_KEY) {54575438 *need_log_inode_item = false;54585458-54595459- if ((min_key->type == BTRFS_INODE_REF_KEY ||54605460- min_key->type == BTRFS_INODE_EXTREF_KEY) &&54615461- inode->generation == trans->transid &&54625462- !recursive_logging) {54395439+ } else if (min_key->type == BTRFS_EXTENT_DATA_KEY &&54405440+ min_key->offset >= i_size) {54415441+ /*54425442+ * Extents at and beyond eof are logged with54435443+ * btrfs_log_prealloc_extents().54445444+ * Only regular files have BTRFS_EXTENT_DATA_KEY keys,54455445+ * and no keys greater than that, so bail out.54465446+ */54475447+ break;54485448+ } else if ((min_key->type == BTRFS_INODE_REF_KEY ||54495449+ min_key->type == BTRFS_INODE_EXTREF_KEY) &&54505450+ inode->generation == trans->transid &&54515451+ !recursive_logging) {54635452 u64 other_ino = 0;54645453 u64 other_parent = 0;54655454···54985471 btrfs_release_path(path);54995472 goto next_key;55005473 }55015501- }55025502-55035503- /* Skip xattrs, we log them later with btrfs_log_all_xattrs() */55045504- if (min_key->type == BTRFS_XATTR_ITEM_KEY) {54745474+ } else if (min_key->type == BTRFS_XATTR_ITEM_KEY) {54755475+ /* Skip xattrs, logged later with btrfs_log_all_xattrs() */55055476 if (ins_nr == 0)55065477 goto next_slot;55075478 ret = copy_items(trans, inode, dst_path, path,···55525527 break;55535528 }55545529 }55555555- if (ins_nr)55305530+ if (ins_nr) {55565531 ret = copy_items(trans, inode, dst_path, path, ins_start_slot,55575532 ins_nr, inode_only, logged_isize);55335533+ if (ret)55345534+ return ret;55355535+ }55365536+55375537+ if (inode_only == LOG_INODE_ALL && S_ISREG(inode->vfs_inode.i_mode)) {55385538+ /*55395539+ * Release the path because otherwise we might attempt to double55405540+ * lock the same leaf with btrfs_log_prealloc_extents() below.55415541+ */55425542+ btrfs_release_path(path);55435543+ ret = btrfs_log_prealloc_extents(trans, inode, dst_path);55445544+ }5558554555595546 return ret;55605547}
+1-1
fs/cachefiles/interface.c
···254254 ret = cachefiles_inject_write_error();255255 if (ret == 0)256256 ret = vfs_fallocate(file, FALLOC_FL_ZERO_RANGE,257257- new_size, dio_size);257257+ new_size, dio_size - new_size);258258 if (ret < 0) {259259 trace_cachefiles_io_error(object, file_inode(file), ret,260260 cachefiles_trace_fallocate_error);
+20-3
fs/cachefiles/xattr.c
···2828static const char cachefiles_xattr_cache[] =2929 XATTR_USER_PREFIX "CacheFiles.cache";30303131+struct cachefiles_vol_xattr {3232+ __be32 reserved; /* Reserved, should be 0 */3333+ __u8 data[]; /* netfs volume coherency data */3434+} __packed;3535+3136/*3237 * set the state xattr on a cache file3338 */···190185 */191186bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)192187{188188+ struct cachefiles_vol_xattr *buf;193189 unsigned int len = volume->vcookie->coherency_len;194190 const void *p = volume->vcookie->coherency;195191 struct dentry *dentry = volume->dentry;···198192199193 _enter("%x,#%d", volume->vcookie->debug_id, len);200194195195+ len += sizeof(*buf);196196+ buf = kmalloc(len, GFP_KERNEL);197197+ if (!buf)198198+ return false;199199+ buf->reserved = cpu_to_be32(0);200200+ memcpy(buf->data, p, len);201201+201202 ret = cachefiles_inject_write_error();202203 if (ret == 0)203204 ret = vfs_setxattr(&init_user_ns, dentry, cachefiles_xattr_cache,204204- p, len, 0);205205+ buf, len, 0);205206 if (ret < 0) {206207 trace_cachefiles_vfs_error(NULL, d_inode(dentry), ret,207208 cachefiles_trace_setxattr_error);···222209 cachefiles_coherency_vol_set_ok);223210 }224211212212+ kfree(buf);225213 _leave(" = %d", ret);226214 return ret == 0;227215}···232218 */233219int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)234220{235235- struct cachefiles_xattr *buf;221221+ struct cachefiles_vol_xattr *buf;236222 struct dentry *dentry = volume->dentry;237223 unsigned int len = volume->vcookie->coherency_len;238224 const void *p = volume->vcookie->coherency;···242228243229 _enter("");244230231231+ len += sizeof(*buf);245232 buf = kmalloc(len, GFP_KERNEL);246233 if (!buf)247234 return -ENOMEM;···260245 "Failed to read xattr with error %zd", xlen);261246 }262247 why = cachefiles_coherency_vol_check_xattr;263263- } else if (memcmp(buf->data, p, len) != 0) {248248+ } else if (buf->reserved != cpu_to_be32(0)) {249249+ why = cachefiles_coherency_vol_check_resv;250250+ } else if (memcmp(buf->data, p, len - sizeof(*buf)) != 0) {264251 why = cachefiles_coherency_vol_check_cmp;265252 } else {266253 why = cachefiles_coherency_vol_check_ok;
+1-1
fs/erofs/internal.h
···325325 unsigned char z_algorithmtype[2];326326 unsigned char z_logical_clusterbits;327327 unsigned long z_tailextent_headlcn;328328- unsigned int z_idataoff;328328+ erofs_off_t z_idataoff;329329 unsigned short z_idata_size;330330 };331331#endif /* CONFIG_EROFS_FS_ZIP */
+11-1
fs/fuse/dev.c
···941941942942 while (count) {943943 if (cs->write && cs->pipebufs && page) {944944- return fuse_ref_page(cs, page, offset, count);944944+ /*945945+ * Can't control lifetime of pipe buffers, so always946946+ * copy user pages.947947+ */948948+ if (cs->req->args->user_pages) {949949+ err = fuse_copy_fill(cs);950950+ if (err)951951+ return err;952952+ } else {953953+ return fuse_ref_page(cs, page, offset, count);954954+ }945955 } else if (!cs->len) {946956 if (cs->move_pages && page &&947957 offset == 0 && count == PAGE_SIZE) {
···2323#include <linux/exportfs.h>2424#include <linux/posix_acl.h>2525#include <linux/pid_namespace.h>2626+#include <uapi/linux/magic.h>26272728MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");2829MODULE_DESCRIPTION("Filesystem in Userspace");···5049MODULE_PARM_DESC(max_user_congthresh,5150 "Global limit for the maximum congestion threshold an "5251 "unprivileged user can set");5353-5454-#define FUSE_SUPER_MAGIC 0x6573554655525653#define FUSE_DEFAULT_BLKSIZE 5125754
+6-3
fs/fuse/ioctl.c
···394394 args.out_args[1].value = ptr;395395396396 err = fuse_simple_request(fm, &args);397397- if (!err && outarg.flags & FUSE_IOCTL_RETRY)398398- err = -EIO;399399-397397+ if (!err) {398398+ if (outarg.result < 0)399399+ err = outarg.result;400400+ else if (outarg.flags & FUSE_IOCTL_RETRY)401401+ err = -EIO;402402+ }400403 return err;401404}402405
+7-4
fs/pipe.c
···253253 */254254 was_full = pipe_full(pipe->head, pipe->tail, pipe->max_usage);255255 for (;;) {256256- unsigned int head = pipe->head;256256+ /* Read ->head with a barrier vs post_one_notification() */257257+ unsigned int head = smp_load_acquire(&pipe->head);257258 unsigned int tail = pipe->tail;258259 unsigned int mask = pipe->ring_size - 1;259260···832831 int i;833832834833#ifdef CONFIG_WATCH_QUEUE835835- if (pipe->watch_queue) {834834+ if (pipe->watch_queue)836835 watch_queue_clear(pipe->watch_queue);837837- put_watch_queue(pipe->watch_queue);838838- }839836#endif840837841838 (void) account_pipe_buffers(pipe->user, pipe->nr_accounted, 0);···843844 if (buf->ops)844845 pipe_buf_release(pipe, buf);845846 }847847+#ifdef CONFIG_WATCH_QUEUE848848+ if (pipe->watch_queue)849849+ put_watch_queue(pipe->watch_queue);850850+#endif846851 if (pipe->tmp_page)847852 __free_page(pipe->tmp_page);848853 kfree(pipe->bufs);
+5-4
fs/proc/task_mmu.c
···309309310310 name = arch_vma_name(vma);311311 if (!name) {312312- const char *anon_name;312312+ struct anon_vma_name *anon_name;313313314314 if (!mm) {315315 name = "[vdso]";···327327 goto done;328328 }329329330330- anon_name = vma_anon_name(vma);330330+ anon_name = anon_vma_name(vma);331331 if (anon_name) {332332 seq_pad(m, ' ');333333- seq_printf(m, "[anon:%s]", anon_name);333333+ seq_printf(m, "[anon:%s]", anon_name->name);334334 }335335 }336336···15971597 * Bits 5-54 swap offset if swapped15981598 * Bit 55 pte is soft-dirty (see Documentation/admin-guide/mm/soft-dirty.rst)15991599 * Bit 56 page exclusively mapped16001600- * Bits 57-60 zero16001600+ * Bit 57 pte is uffd-wp write-protected16011601+ * Bits 58-60 zero16011602 * Bit 61 page is file-page or shared-anon16021603 * Bit 62 page swapped16031604 * Bit 63 page present
···6262#define DMA_ATTR_PRIVILEGED (1UL << 9)63636464/*6565- * This is a hint to the DMA-mapping subsystem that the device is expected6666- * to overwrite the entire mapped size, thus the caller does not require any6767- * of the previous buffer contents to be preserved. This allows6868- * bounce-buffering implementations to optimise DMA_FROM_DEVICE transfers.6969- */7070-#define DMA_ATTR_OVERWRITE (1UL << 10)7171-7272-/*7365 * A dma_addr_t can hold any valid DMA or bus address for the platform. It can7466 * be given to a device to use as a DMA source or target. It is specific to a7567 * given device and there may be a translation between the CPU physical address
···26262626extern struct vm_area_struct *vma_merge(struct mm_struct *,26272627 struct vm_area_struct *prev, unsigned long addr, unsigned long end,26282628 unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,26292629- struct mempolicy *, struct vm_userfaultfd_ctx, const char *);26292629+ struct mempolicy *, struct vm_userfaultfd_ctx, struct anon_vma_name *);26302630extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);26312631extern int __split_vma(struct mm_struct *, struct vm_area_struct *,26322632 unsigned long addr, int new_below);···3372337233733373#ifdef CONFIG_ANON_VMA_NAME33743374int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,33753375- unsigned long len_in, const char *name);33753375+ unsigned long len_in,33763376+ struct anon_vma_name *anon_name);33763377#else33773378static inline int33783379madvise_set_anon_name(struct mm_struct *mm, unsigned long start,33793379- unsigned long len_in, const char *name) {33803380+ unsigned long len_in, struct anon_vma_name *anon_name) {33803381 return 0;33813382}33823383#endif
+70-29
include/linux/mm_inline.h
···140140141141#ifdef CONFIG_ANON_VMA_NAME142142/*143143- * mmap_lock should be read-locked when calling vma_anon_name() and while using144144- * the returned pointer.143143+ * mmap_lock should be read-locked when calling anon_vma_name(). Caller should144144+ * either keep holding the lock while using the returned pointer or it should145145+ * raise anon_vma_name refcount before releasing the lock.145146 */146146-extern const char *vma_anon_name(struct vm_area_struct *vma);147147-148148-/*149149- * mmap_lock should be read-locked for orig_vma->vm_mm.150150- * mmap_lock should be write-locked for new_vma->vm_mm or new_vma should be151151- * isolated.152152- */153153-extern void dup_vma_anon_name(struct vm_area_struct *orig_vma,154154- struct vm_area_struct *new_vma);155155-156156-/*157157- * mmap_lock should be write-locked or vma should have been isolated under158158- * write-locked mmap_lock protection.159159- */160160-extern void free_vma_anon_name(struct vm_area_struct *vma);147147+extern struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma);148148+extern struct anon_vma_name *anon_vma_name_alloc(const char *name);149149+extern void anon_vma_name_free(struct kref *kref);161150162151/* mmap_lock should be read-locked */163163-static inline bool is_same_vma_anon_name(struct vm_area_struct *vma,164164- const char *name)152152+static inline void anon_vma_name_get(struct anon_vma_name *anon_name)165153{166166- const char *vma_name = vma_anon_name(vma);154154+ if (anon_name)155155+ kref_get(&anon_name->kref);156156+}167157168168- /* either both NULL, or pointers to same string */169169- if (vma_name == name)158158+static inline void anon_vma_name_put(struct anon_vma_name *anon_name)159159+{160160+ if (anon_name)161161+ kref_put(&anon_name->kref, anon_vma_name_free);162162+}163163+164164+static inline165165+struct anon_vma_name *anon_vma_name_reuse(struct anon_vma_name *anon_name)166166+{167167+ /* Prevent anon_name refcount saturation early on */168168+ if (kref_read(&anon_name->kref) < REFCOUNT_MAX) {169169+ anon_vma_name_get(anon_name);170170+ return anon_name;171171+172172+ }173173+ return anon_vma_name_alloc(anon_name->name);174174+}175175+176176+static inline void dup_anon_vma_name(struct vm_area_struct *orig_vma,177177+ struct vm_area_struct *new_vma)178178+{179179+ struct anon_vma_name *anon_name = anon_vma_name(orig_vma);180180+181181+ if (anon_name)182182+ new_vma->anon_name = anon_vma_name_reuse(anon_name);183183+}184184+185185+static inline void free_anon_vma_name(struct vm_area_struct *vma)186186+{187187+ /*188188+ * Not using anon_vma_name because it generates a warning if mmap_lock189189+ * is not held, which might be the case here.190190+ */191191+ if (!vma->vm_file)192192+ anon_vma_name_put(vma->anon_name);193193+}194194+195195+static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1,196196+ struct anon_vma_name *anon_name2)197197+{198198+ if (anon_name1 == anon_name2)170199 return true;171200172172- return name && vma_name && !strcmp(name, vma_name);201201+ return anon_name1 && anon_name2 &&202202+ !strcmp(anon_name1->name, anon_name2->name);173203}204204+174205#else /* CONFIG_ANON_VMA_NAME */175175-static inline const char *vma_anon_name(struct vm_area_struct *vma)206206+static inline struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma)176207{177208 return NULL;178209}179179-static inline void dup_vma_anon_name(struct vm_area_struct *orig_vma,180180- struct vm_area_struct *new_vma) {}181181-static inline void free_vma_anon_name(struct vm_area_struct *vma) {}182182-static inline bool is_same_vma_anon_name(struct vm_area_struct *vma,183183- const char *name)210210+211211+static inline struct anon_vma_name *anon_vma_name_alloc(const char *name)212212+{213213+ return NULL;214214+}215215+216216+static inline void anon_vma_name_get(struct anon_vma_name *anon_name) {}217217+static inline void anon_vma_name_put(struct anon_vma_name *anon_name) {}218218+static inline void dup_anon_vma_name(struct vm_area_struct *orig_vma,219219+ struct vm_area_struct *new_vma) {}220220+static inline void free_anon_vma_name(struct vm_area_struct *vma) {}221221+222222+static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1,223223+ struct anon_vma_name *anon_name2)184224{185225 return true;186226}227227+187228#endif /* CONFIG_ANON_VMA_NAME */188229189230static inline void init_tlb_flush_pending(struct mm_struct *mm)
+4-1
include/linux/mm_types.h
···416416 struct rb_node rb;417417 unsigned long rb_subtree_last;418418 } shared;419419- /* Serialized by mmap_sem. */419419+ /*420420+ * Serialized by mmap_sem. Never use directly because it is421421+ * valid only when vm_file is NULL. Use anon_vma_name instead.422422+ */420423 struct anon_vma_name *anon_name;421424 };422425
···6464 * Returns the first 64 feature bits (all we currently need).6565 * @finalize_features: confirm what device features we'll be using.6666 * vdev: the virtio_device6767- * This gives the final feature bits for the device: it can change6767+ * This sends the driver feature bits to the device: it can change6868 * the dev->feature bits if it wants.6969+ * Note: despite the name this can be called any number of times.6970 * Returns 0 on success or error status7071 * @bus_name: return the bus name associated with the device (optional)7172 * vdev: the virtio_device
+2-1
include/linux/watch_queue.h
···2828struct watch_filter {2929 union {3030 struct rcu_head rcu;3131- unsigned long type_filter[2]; /* Bitmask of accepted types */3131+ /* Bitmask of accepted types */3232+ DECLARE_BITMAP(type_filter, WATCH_TYPE__NR);3233 };3334 u32 nr_filters; /* Number of filters */3435 struct watch_type_filter filters[];
···14891489/* Extended advertising support */14901490#define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))1491149114921492+/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:14931493+ *14941494+ * C24: Mandatory if the LE Controller supports Connection State and either14951495+ * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported14961496+ */14971497+#define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \14981498+ ext_adv_capable(dev))14991499+14921500/* ----- HCI protocols ----- */14931501#define HCI_PROTO_DEFER 0x0114941502
···511511 int ifindex;512512 __u8 flags;513513};514514+/* This flag was exposed without any kernel code that supporting it.515515+ * Unfortunately, strongswan has the code that uses sets this flag,516516+ * which makes impossible to reuse this bit.517517+ *518518+ * So leave it here to make sure that it won't be reused by mistake.519519+ */514520#define XFRM_OFFLOAD_IPV6 1515521#define XFRM_OFFLOAD_INBOUND 2516522
+17-2
include/xen/grant_table.h
···104104 * access has been ended, free the given page too. Access will be ended105105 * immediately iff the grant entry is not in use, otherwise it will happen106106 * some time later. page may be 0, in which case no freeing will occur.107107+ * Note that the granted page might still be accessed (read or write) by the108108+ * other side after gnttab_end_foreign_access() returns, so even if page was109109+ * specified as 0 it is not allowed to just reuse the page for other110110+ * purposes immediately. gnttab_end_foreign_access() will take an additional111111+ * reference to the granted page in this case, which is dropped only after112112+ * the grant is no longer in use.113113+ * This requires that multi page allocations for areas subject to114114+ * gnttab_end_foreign_access() are done via alloc_pages_exact() (and freeing115115+ * via free_pages_exact()) in order to avoid high order pages.107116 */108117void gnttab_end_foreign_access(grant_ref_t ref, int readonly,109118 unsigned long page);119119+120120+/*121121+ * End access through the given grant reference, iff the grant entry is122122+ * no longer in use. In case of success ending foreign access, the123123+ * grant reference is deallocated.124124+ * Return 1 if the grant entry was freed, 0 if it is still in use.125125+ */126126+int gnttab_try_end_foreign_access(grant_ref_t ref);110127111128int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);112129113130unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);114131unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);115115-116116-int gnttab_query_foreign_access(grant_ref_t ref);117132118133/*119134 * operations on reserved batches of grant references
+1-1
kernel/configs/debug.config
···1616#1717# Compile-time checks and compiler options1818#1919-CONFIG_DEBUG_INFO=y1919+CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y2020CONFIG_DEBUG_SECTION_MISMATCH=y2121CONFIG_FRAME_WARN=20482222CONFIG_SECTION_MISMATCH_WARN_ONLY=y
+15-8
kernel/dma/swiotlb.c
···627627 for (i = 0; i < nr_slots(alloc_size + offset); i++)628628 mem->slots[index + i].orig_addr = slot_addr(orig_addr, i);629629 tlb_addr = slot_addr(mem->start, index) + offset;630630- if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&631631- (!(attrs & DMA_ATTR_OVERWRITE) || dir == DMA_TO_DEVICE ||632632- dir == DMA_BIDIRECTIONAL))633633- swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE);630630+ /*631631+ * When dir == DMA_FROM_DEVICE we could omit the copy from the orig632632+ * to the tlb buffer, if we knew for sure the device will633633+ * overwirte the entire current content. But we don't. Thus634634+ * unconditional bounce may prevent leaking swiotlb content (i.e.635635+ * kernel memory) to user-space.636636+ */637637+ swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE);634638 return tlb_addr;635639}636640···701697void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_addr,702698 size_t size, enum dma_data_direction dir)703699{704704- if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)705705- swiotlb_bounce(dev, tlb_addr, size, DMA_TO_DEVICE);706706- else707707- BUG_ON(dir != DMA_FROM_DEVICE);700700+ /*701701+ * Unconditional bounce is necessary to avoid corruption on702702+ * sync_*_for_cpu or dma_ummap_* when the device didn't overwrite703703+ * the whole lengt of the bounce buffer.704704+ */705705+ swiotlb_bounce(dev, tlb_addr, size, DMA_TO_DEVICE);706706+ BUG_ON(!valid_dma_direction(dir));708707}709708710709void swiotlb_sync_single_for_cpu(struct device *dev, phys_addr_t tlb_addr,
···310310 local_irq_restore(flags);311311}312312313313-static void blk_trace_free(struct blk_trace *bt)313313+static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)314314{315315 relay_close(bt->rchan);316316- debugfs_remove(bt->dir);316316+317317+ /*318318+ * If 'bt->dir' is not set, then both 'dropped' and 'msg' are created319319+ * under 'q->debugfs_dir', thus lookup and remove them.320320+ */321321+ if (!bt->dir) {322322+ debugfs_remove(debugfs_lookup("dropped", q->debugfs_dir));323323+ debugfs_remove(debugfs_lookup("msg", q->debugfs_dir));324324+ } else {325325+ debugfs_remove(bt->dir);326326+ }317327 free_percpu(bt->sequence);318328 free_percpu(bt->msg_data);319329 kfree(bt);···345335 mutex_unlock(&blk_probe_mutex);346336}347337348348-static void blk_trace_cleanup(struct blk_trace *bt)338338+static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)349339{350340 synchronize_rcu();351351- blk_trace_free(bt);341341+ blk_trace_free(q, bt);352342 put_probe_ref();353343}354344···362352 return -EINVAL;363353364354 if (bt->trace_state != Blktrace_running)365365- blk_trace_cleanup(bt);355355+ blk_trace_cleanup(q, bt);366356367357 return 0;368358}···582572 ret = 0;583573err:584574 if (ret)585585- blk_trace_free(bt);575575+ blk_trace_free(q, bt);586576 return ret;587577}588578···1626161616271617 put_probe_ref();16281618 synchronize_rcu();16291629- blk_trace_free(bt);16191619+ blk_trace_free(q, bt);16301620 return 0;16311621}16321622···16571647 return 0;1658164816591649free_bt:16601660- blk_trace_free(bt);16501650+ blk_trace_free(q, bt);16611651 return ret;16621652}16631653
+2-2
kernel/trace/ftrace.c
···7790779077917791/**77927792 * register_ftrace_function - register a function for profiling77937793- * @ops - ops structure that holds the function for profiling.77937793+ * @ops: ops structure that holds the function for profiling.77947794 *77957795 * Register a function to be called by all functions in the77967796 * kernel.···7817781778187818/**78197819 * unregister_ftrace_function - unregister a function for profiling.78207820- * @ops - ops structure that holds the function to unregister78207820+ * @ops: ops structure that holds the function to unregister78217821 *78227822 * Unregister a function that was added to be called by ftrace profiling.78237823 */
···22892289 /*22902290 * For backward compatibility, if field_name22912291 * was "cpu", then we treat this the same as22922292- * common_cpu.22922292+ * common_cpu. This also works for "CPU".22932293 */22942294- if (strcmp(field_name, "cpu") == 0) {22942294+ if (field && field->filter_type == FILTER_CPU) {22952295 *flags |= HIST_FIELD_FL_CPU;22962296 } else {22972297 hist_err(tr, HIST_ERR_FIELD_NOT_FOUND,···4832483248334833 if (hist_field->flags & HIST_FIELD_FL_STACKTRACE)48344834 cmp_fn = tracing_map_cmp_none;48354835- else if (!field)48354835+ else if (!field || hist_field->flags & HIST_FIELD_FL_CPU)48364836 cmp_fn = tracing_map_cmp_num(hist_field->size,48374837 hist_field->is_signed);48384838 else if (is_string_field(field))
···13871387 }1388138813891389 /*13901390+ * In some cases, notably when running on a nohz_full CPU with13911391+ * a stopped tick PREEMPT_RCU has no way to account for QSs.13921392+ * This will eventually cause unwarranted noise as PREEMPT_RCU13931393+ * will force preemption as the means of ending the current13941394+ * grace period. We avoid this problem by calling13951395+ * rcu_momentary_dyntick_idle(), which performs a zero duration13961396+ * EQS allowing PREEMPT_RCU to end the current grace period.13971397+ * This call shouldn't be wrapped inside an RCU critical13981398+ * section.13991399+ *14001400+ * Note that in non PREEMPT_RCU kernels QSs are handled through14011401+ * cond_resched()14021402+ */14031403+ if (IS_ENABLED(CONFIG_PREEMPT_RCU)) {14041404+ local_irq_disable();14051405+ rcu_momentary_dyntick_idle();14061406+ local_irq_enable();14071407+ }14081408+14091409+ /*13901410 * For the non-preemptive kernel config: let threads runs, if13911411 * they so wish.13921412 */···22182198 * the last instance, and the workload can stop.22192199 */22202200 if (osnoise_has_registered_instances())22012201+ return;22022202+22032203+ /*22042204+ * If callbacks were already disabled in a previous stop22052205+ * call, there is no need to disable then again.22062206+ *22072207+ * For instance, this happens when tracing is stopped via:22082208+ * echo 0 > tracing_on22092209+ * echo nop > current_tracer.22102210+ */22112211+ if (!trace_osnoise_callback_enabled)22212212 return;2222221322232214 trace_osnoise_callback_enabled = false;
+13-1
kernel/user_namespace.c
···5858 cred->user_ns = user_ns;5959}60606161+static unsigned long enforced_nproc_rlimit(void)6262+{6363+ unsigned long limit = RLIM_INFINITY;6464+6565+ /* Is RLIMIT_NPROC currently enforced? */6666+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) ||6767+ (current_user_ns() != &init_user_ns))6868+ limit = rlimit(RLIMIT_NPROC);6969+7070+ return limit;7171+}7272+6173/*6274 * Create a new user namespace, deriving the creator from the user in the6375 * passed credentials, and replacing that user with the new root user for the···134122 for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++) {135123 ns->ucount_max[i] = INT_MAX;136124 }137137- set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC));125125+ set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_NPROC, enforced_nproc_rlimit());138126 set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MSGQUEUE, rlimit(RLIMIT_MSGQUEUE));139127 set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_SIGPENDING, rlimit(RLIMIT_SIGPENDING));140128 set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK));
+11-11
kernel/watch_queue.c
···5454 bit += page->index;55555656 set_bit(bit, wqueue->notes_bitmap);5757+ generic_pipe_buf_release(pipe, buf);5758}58595960// No try_steal function => no stealing···113112 buf->offset = offset;114113 buf->len = len;115114 buf->flags = PIPE_BUF_FLAG_WHOLE;116116- pipe->head = head + 1;115115+ smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */117116118117 if (!test_and_clear_bit(note, wqueue->notes_bitmap)) {119118 spin_unlock_irq(&pipe->rd_wait.lock);···220219 struct page **pages;221220 unsigned long *bitmap;222221 unsigned long user_bufs;223223- unsigned int bmsize;224222 int ret, i, nr_pages;225223226224 if (!wqueue)···243243 goto error;244244 }245245246246- ret = pipe_resize_ring(pipe, nr_notes);246246+ nr_notes = nr_pages * WATCH_QUEUE_NOTES_PER_PAGE;247247+ ret = pipe_resize_ring(pipe, roundup_pow_of_two(nr_notes));247248 if (ret < 0)248249 goto error;249250···259258 pages[i]->index = i * WATCH_QUEUE_NOTES_PER_PAGE;260259 }261260262262- bmsize = (nr_notes + BITS_PER_LONG - 1) / BITS_PER_LONG;263263- bmsize *= sizeof(unsigned long);264264- bitmap = kmalloc(bmsize, GFP_KERNEL);261261+ bitmap = bitmap_alloc(nr_notes, GFP_KERNEL);265262 if (!bitmap)266263 goto error_p;267264268268- memset(bitmap, 0xff, bmsize);265265+ bitmap_fill(bitmap, nr_notes);269266 wqueue->notes = pages;270267 wqueue->notes_bitmap = bitmap;271268 wqueue->nr_pages = nr_pages;272272- wqueue->nr_notes = nr_pages * WATCH_QUEUE_NOTES_PER_PAGE;269269+ wqueue->nr_notes = nr_notes;273270 return 0;274271275272error_p:···319320 tf[i].info_mask & WATCH_INFO_LENGTH)320321 goto err_filter;321322 /* Ignore any unknown types */322322- if (tf[i].type >= sizeof(wfilter->type_filter) * 8)323323+ if (tf[i].type >= WATCH_TYPE__NR)323324 continue;324325 nr_filter++;325326 }···335336336337 q = wfilter->filters;337338 for (i = 0; i < filter.nr_filters; i++) {338338- if (tf[i].type >= sizeof(wfilter->type_filter) * BITS_PER_LONG)339339+ if (tf[i].type >= WATCH_TYPE__NR)339340 continue;340341341342 q->type = tf[i].type;···370371371372 for (i = 0; i < wqueue->nr_pages; i++)372373 __free_page(wqueue->notes[i]);374374+ bitmap_free(wqueue->notes_bitmap);373375374376 wfilter = rcu_access_pointer(wqueue->filter);375377 if (wfilter)···566566 rcu_read_lock();567567 spin_lock_bh(&wqueue->lock);568568569569- /* Prevent new additions and prevent notifications from happening */569569+ /* Prevent new notifications from being stored. */570570 wqueue->defunct = true;571571572572 while (!hlist_empty(&wqueue->watches)) {
-1
lib/Kconfig
···4545config HAVE_ARCH_BITREVERSE4646 bool4747 default n4848- depends on BITREVERSE4948 help5049 This option enables the use of hardware bit-reversal instructions on5150 architectures which support such operations.
+22-41
mm/gup.c
···17291729 * @uaddr: start of address range17301730 * @size: length of address range17311731 *17321732- * Faults in an address range using get_user_pages, i.e., without triggering17331733- * hardware page faults. This is primarily useful when we already know that17341734- * some or all of the pages in the address range aren't in memory.17321732+ * Faults in an address range for writing. This is primarily useful when we17331733+ * already know that some or all of the pages in the address range aren't in17341734+ * memory.17351735 *17361736- * Other than fault_in_writeable(), this function is non-destructive.17361736+ * Unlike fault_in_writeable(), this function is non-destructive.17371737 *17381738 * Note that we don't pin or otherwise hold the pages referenced that we fault17391739 * in. There's no guarantee that they'll stay in memory for any duration of···17441744 */17451745size_t fault_in_safe_writeable(const char __user *uaddr, size_t size)17461746{17471747- unsigned long start = (unsigned long)untagged_addr(uaddr);17481748- unsigned long end, nstart, nend;17471747+ unsigned long start = (unsigned long)uaddr, end;17491748 struct mm_struct *mm = current->mm;17501750- struct vm_area_struct *vma = NULL;17511751- int locked = 0;17491749+ bool unlocked = false;1752175017531753- nstart = start & PAGE_MASK;17541754- end = PAGE_ALIGN(start + size);17551755- if (end < nstart)17561756- end = 0;17571757- for (; nstart != end; nstart = nend) {17581758- unsigned long nr_pages;17591759- long ret;17601760-17611761- if (!locked) {17621762- locked = 1;17631763- mmap_read_lock(mm);17641764- vma = find_vma(mm, nstart);17651765- } else if (nstart >= vma->vm_end)17661766- vma = vma->vm_next;17671767- if (!vma || vma->vm_start >= end)17681768- break;17691769- nend = end ? min(end, vma->vm_end) : vma->vm_end;17701770- if (vma->vm_flags & (VM_IO | VM_PFNMAP))17711771- continue;17721772- if (nstart < vma->vm_start)17731773- nstart = vma->vm_start;17741774- nr_pages = (nend - nstart) / PAGE_SIZE;17751775- ret = __get_user_pages_locked(mm, nstart, nr_pages,17761776- NULL, NULL, &locked,17771777- FOLL_TOUCH | FOLL_WRITE);17781778- if (ret <= 0)17791779- break;17801780- nend = nstart + ret * PAGE_SIZE;17811781- }17821782- if (locked)17831783- mmap_read_unlock(mm);17841784- if (nstart == end)17511751+ if (unlikely(size == 0))17851752 return 0;17861786- return size - min_t(size_t, nstart - start, size);17531753+ end = PAGE_ALIGN(start + size);17541754+ if (end < start)17551755+ end = 0;17561756+17571757+ mmap_read_lock(mm);17581758+ do {17591759+ if (fixup_user_fault(mm, start, FAULT_FLAG_WRITE, &unlocked))17601760+ break;17611761+ start = (start + PAGE_SIZE) & PAGE_MASK;17621762+ } while (start != end);17631763+ mmap_read_unlock(mm);17641764+17651765+ if (size > (unsigned long)uaddr - start)17661766+ return size - ((unsigned long)uaddr - start);17671767+ return 0;17871768}17881769EXPORT_SYMBOL(fault_in_safe_writeable);17891770
+34-58
mm/madvise.c
···6565}66666767#ifdef CONFIG_ANON_VMA_NAME6868-static struct anon_vma_name *anon_vma_name_alloc(const char *name)6868+struct anon_vma_name *anon_vma_name_alloc(const char *name)6969{7070 struct anon_vma_name *anon_name;7171 size_t count;···8181 return anon_name;8282}83838484-static void vma_anon_name_free(struct kref *kref)8484+void anon_vma_name_free(struct kref *kref)8585{8686 struct anon_vma_name *anon_name =8787 container_of(kref, struct anon_vma_name, kref);8888 kfree(anon_name);8989}90909191-static inline bool has_vma_anon_name(struct vm_area_struct *vma)9191+struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma)9292{9393- return !vma->vm_file && vma->anon_name;9494-}9595-9696-const char *vma_anon_name(struct vm_area_struct *vma)9797-{9898- if (!has_vma_anon_name(vma))9999- return NULL;100100-10193 mmap_assert_locked(vma->vm_mm);10294103103- return vma->anon_name->name;104104-}9595+ if (vma->vm_file)9696+ return NULL;10597106106-void dup_vma_anon_name(struct vm_area_struct *orig_vma,107107- struct vm_area_struct *new_vma)108108-{109109- if (!has_vma_anon_name(orig_vma))110110- return;111111-112112- kref_get(&orig_vma->anon_name->kref);113113- new_vma->anon_name = orig_vma->anon_name;114114-}115115-116116-void free_vma_anon_name(struct vm_area_struct *vma)117117-{118118- struct anon_vma_name *anon_name;119119-120120- if (!has_vma_anon_name(vma))121121- return;122122-123123- anon_name = vma->anon_name;124124- vma->anon_name = NULL;125125- kref_put(&anon_name->kref, vma_anon_name_free);9898+ return vma->anon_name;12699}127100128101/* mmap_lock should be write-locked */129129-static int replace_vma_anon_name(struct vm_area_struct *vma, const char *name)102102+static int replace_anon_vma_name(struct vm_area_struct *vma,103103+ struct anon_vma_name *anon_name)130104{131131- const char *anon_name;105105+ struct anon_vma_name *orig_name = anon_vma_name(vma);132106133133- if (!name) {134134- free_vma_anon_name(vma);107107+ if (!anon_name) {108108+ vma->anon_name = NULL;109109+ anon_vma_name_put(orig_name);135110 return 0;136111 }137112138138- anon_name = vma_anon_name(vma);139139- if (anon_name) {140140- /* Same name, nothing to do here */141141- if (!strcmp(name, anon_name))142142- return 0;113113+ if (anon_vma_name_eq(orig_name, anon_name))114114+ return 0;143115144144- free_vma_anon_name(vma);145145- }146146- vma->anon_name = anon_vma_name_alloc(name);147147- if (!vma->anon_name)148148- return -ENOMEM;116116+ vma->anon_name = anon_vma_name_reuse(anon_name);117117+ anon_vma_name_put(orig_name);149118150119 return 0;151120}152121#else /* CONFIG_ANON_VMA_NAME */153153-static int replace_vma_anon_name(struct vm_area_struct *vma, const char *name)122122+static int replace_anon_vma_name(struct vm_area_struct *vma,123123+ struct anon_vma_name *anon_name)154124{155155- if (name)125125+ if (anon_name)156126 return -EINVAL;157127158128 return 0;···131161/*132162 * Update the vm_flags on region of a vma, splitting it or merging it as133163 * necessary. Must be called with mmap_sem held for writing;164164+ * Caller should ensure anon_name stability by raising its refcount even when165165+ * anon_name belongs to a valid vma because this function might free that vma.134166 */135167static int madvise_update_vma(struct vm_area_struct *vma,136168 struct vm_area_struct **prev, unsigned long start,137169 unsigned long end, unsigned long new_flags,138138- const char *name)170170+ struct anon_vma_name *anon_name)139171{140172 struct mm_struct *mm = vma->vm_mm;141173 int error;142174 pgoff_t pgoff;143175144144- if (new_flags == vma->vm_flags && is_same_vma_anon_name(vma, name)) {176176+ if (new_flags == vma->vm_flags && anon_vma_name_eq(anon_vma_name(vma), anon_name)) {145177 *prev = vma;146178 return 0;147179 }···151179 pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);152180 *prev = vma_merge(mm, *prev, start, end, new_flags, vma->anon_vma,153181 vma->vm_file, pgoff, vma_policy(vma),154154- vma->vm_userfaultfd_ctx, name);182182+ vma->vm_userfaultfd_ctx, anon_name);155183 if (*prev) {156184 vma = *prev;157185 goto success;···181209 */182210 vma->vm_flags = new_flags;183211 if (!vma->vm_file) {184184- error = replace_vma_anon_name(vma, name);212212+ error = replace_anon_vma_name(vma, anon_name);185213 if (error)186214 return error;187215 }···947975 unsigned long behavior)948976{949977 int error;978978+ struct anon_vma_name *anon_name;950979 unsigned long new_flags = vma->vm_flags;951980952981 switch (behavior) {···10131040 break;10141041 }1015104210431043+ anon_name = anon_vma_name(vma);10441044+ anon_vma_name_get(anon_name);10161045 error = madvise_update_vma(vma, prev, start, end, new_flags,10171017- vma_anon_name(vma));10461046+ anon_name);10471047+ anon_vma_name_put(anon_name);1018104810191049out:10201050 /*···12011225static int madvise_vma_anon_name(struct vm_area_struct *vma,12021226 struct vm_area_struct **prev,12031227 unsigned long start, unsigned long end,12041204- unsigned long name)12281228+ unsigned long anon_name)12051229{12061230 int error;12071231···12101234 return -EBADF;1211123512121236 error = madvise_update_vma(vma, prev, start, end, vma->vm_flags,12131213- (const char *)name);12371237+ (struct anon_vma_name *)anon_name);1214123812151239 /*12161240 * madvise() returns EAGAIN if kernel resources, such as···12221246}1223124712241248int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,12251225- unsigned long len_in, const char *name)12491249+ unsigned long len_in, struct anon_vma_name *anon_name)12261250{12271251 unsigned long end;12281252 unsigned long len;···12421266 if (end == start)12431267 return 0;1244126812451245- return madvise_walk_vmas(mm, start, end, (unsigned long)name,12691269+ return madvise_walk_vmas(mm, start, end, (unsigned long)anon_name,12461270 madvise_vma_anon_name);12471271}12481272#endif /* CONFIG_ANON_VMA_NAME */
+29-13
mm/memfd.c
···3131static void memfd_tag_pins(struct xa_state *xas)3232{3333 struct page *page;3434- unsigned int tagged = 0;3434+ int latency = 0;3535+ int cache_count;35363637 lru_add_drain();37383839 xas_lock_irq(xas);3940 xas_for_each(xas, page, ULONG_MAX) {4040- if (xa_is_value(page))4141- continue;4242- page = find_subpage(page, xas->xa_index);4343- if (page_count(page) - page_mapcount(page) > 1)4444- xas_set_mark(xas, MEMFD_TAG_PINNED);4141+ cache_count = 1;4242+ if (!xa_is_value(page) &&4343+ PageTransHuge(page) && !PageHuge(page))4444+ cache_count = HPAGE_PMD_NR;45454646- if (++tagged % XA_CHECK_SCHED)4646+ if (!xa_is_value(page) &&4747+ page_count(page) - total_mapcount(page) != cache_count)4848+ xas_set_mark(xas, MEMFD_TAG_PINNED);4949+ if (cache_count != 1)5050+ xas_set(xas, page->index + cache_count);5151+5252+ latency += cache_count;5353+ if (latency < XA_CHECK_SCHED)4754 continue;5555+ latency = 0;48564957 xas_pause(xas);5058 xas_unlock_irq(xas);···81738274 error = 0;8375 for (scan = 0; scan <= LAST_SCAN; scan++) {8484- unsigned int tagged = 0;7676+ int latency = 0;7777+ int cache_count;85788679 if (!xas_marked(&xas, MEMFD_TAG_PINNED))8780 break;···9687 xas_lock_irq(&xas);9788 xas_for_each_marked(&xas, page, ULONG_MAX, MEMFD_TAG_PINNED) {9889 bool clear = true;9999- if (xa_is_value(page))100100- continue;101101- page = find_subpage(page, xas.xa_index);102102- if (page_count(page) - page_mapcount(page) != 1) {9090+9191+ cache_count = 1;9292+ if (!xa_is_value(page) &&9393+ PageTransHuge(page) && !PageHuge(page))9494+ cache_count = HPAGE_PMD_NR;9595+9696+ if (!xa_is_value(page) && cache_count !=9797+ page_count(page) - total_mapcount(page)) {10398 /*10499 * On the last scan, we clean up all those tags105100 * we inserted; but make a note that we still···116103 }117104 if (clear)118105 xas_clear_mark(&xas, MEMFD_TAG_PINNED);119119- if (++tagged % XA_CHECK_SCHED)106106+107107+ latency += cache_count;108108+ if (latency < XA_CHECK_SCHED)120109 continue;110110+ latency = 0;121111122112 xas_pause(&xas);123113 xas_unlock_irq(&xas);
···7777{7878 struct hci_dev *hdev;7979 struct mgmt_hdr *hdr;8080- int len = skb->len;8080+ int len;81818282 if (!skb)8383 return -EINVAL;84848585+ len = skb->len;8586 hdev = bt_cb(skb)->mgmt.hdev;86878788 /* Time stamp */
+25
net/core/gro.c
···9393EXPORT_SYMBOL(dev_remove_offload);94949595/**9696+ * skb_eth_gso_segment - segmentation handler for ethernet protocols.9797+ * @skb: buffer to segment9898+ * @features: features for the output path (see dev->features)9999+ * @type: Ethernet Protocol ID100100+ */101101+struct sk_buff *skb_eth_gso_segment(struct sk_buff *skb,102102+ netdev_features_t features, __be16 type)103103+{104104+ struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);105105+ struct packet_offload *ptype;106106+107107+ rcu_read_lock();108108+ list_for_each_entry_rcu(ptype, &offload_base, list) {109109+ if (ptype->type == type && ptype->callbacks.gso_segment) {110110+ segs = ptype->callbacks.gso_segment(skb, features);111111+ break;112112+ }113113+ }114114+ rcu_read_unlock();115115+116116+ return segs;117117+}118118+EXPORT_SYMBOL(skb_eth_gso_segment);119119+120120+/**96121 * skb_mac_gso_segment - mac layer segmentation handler.97122 * @skb: buffer to segment98123 * @features: features for the output path (see dev->features)
···11531153 struct sk_psock *psock;11541154 struct bpf_prog *prog;11551155 int ret = __SK_DROP;11561156- int len = skb->len;11561156+ int len = orig_len;1157115711581158 /* clone here so sk_eat_skb() in tcp_read_sock does not drop our data */11591159 skb = skb_clone(skb, GFP_ATOMIC);
+2-1
net/core/xdp.c
···357357 if (IS_ERR(xdp_alloc))358358 return PTR_ERR(xdp_alloc);359359360360- trace_mem_connect(xdp_alloc, xdp_rxq);360360+ if (trace_mem_connect_enabled() && xdp_alloc)361361+ trace_mem_connect(xdp_alloc, xdp_rxq);361362 return 0;362363}363364
···3737#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)3838#define IEEE80211_AUTH_MAX_TRIES 33939#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)4040+#define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)4041#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)4142#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)4243#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)···30123011 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||30133012 (auth_transaction == 1 &&30143013 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||30153015- status_code == WLAN_STATUS_SAE_PK))))30143014+ status_code == WLAN_STATUS_SAE_PK)))) {30153015+ /* waiting for userspace now */30163016+ ifmgd->auth_data->waiting = true;30173017+ ifmgd->auth_data->timeout =30183018+ jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;30193019+ ifmgd->auth_data->timeout_started = true;30203020+ run_again(sdata, ifmgd->auth_data->timeout);30163021 goto notify_driver;30223022+ }3017302330183024 sdata_info(sdata, "%pM denied authentication (status %d)\n",30193025 mgmt->sa, status_code);···4611460346124604 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&46134605 time_after(jiffies, ifmgd->auth_data->timeout)) {46144614- if (ifmgd->auth_data->done) {46064606+ if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {46154607 /*46164616- * ok ... we waited for assoc but userspace didn't,46174617- * so let's just kill the auth data46084608+ * ok ... we waited for assoc or continuation but46094609+ * userspace didn't do it, so kill the auth data46184610 */46194611 ieee80211_destroy_auth_data(sdata, false);46204612 } else if (ieee80211_auth(sdata)) {
+5-9
net/mac80211/rx.c
···26072607 * address, so that the authenticator (e.g. hostapd) will see26082608 * the frame, but bridge won't forward it anywhere else. Note26092609 * that due to earlier filtering, the only other address can26102610- * be the PAE group address.26102610+ * be the PAE group address, unless the hardware allowed them26112611+ * through in 802.3 offloaded mode.26112612 */26122613 if (unlikely(skb->protocol == sdata->control_port_protocol &&26132614 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))···29232922 ether_addr_equal(sdata->vif.addr, hdr->addr3))29242923 return RX_CONTINUE;2925292429262926- ac = ieee80211_select_queue_80211(sdata, skb, hdr);29252925+ ac = ieee802_1d_to_ac[skb->priority];29272926 q = sdata->vif.hw_queue[ac];29282927 if (ieee80211_queue_stopped(&local->hw, q)) {29292928 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);29302929 return RX_DROP_MONITOR;29312930 }29322932- skb_set_queue_mapping(skb, q);29312931+ skb_set_queue_mapping(skb, ac);2933293229342933 if (!--mesh_hdr->ttl) {29352934 if (!is_multicast_ether_addr(hdr->addr1))···4515451445164515 /* deliver to local stack */45174516 skb->protocol = eth_type_trans(skb, fast_rx->dev);45184518- memset(skb->cb, 0, sizeof(skb->cb));45194519- if (rx->list)45204520- list_add_tail(&skb->list, rx->list);45214521- else45224522- netif_receive_skb(skb);45234523-45174517+ ieee80211_deliver_skb_to_local_stack(skb, rx);45244518}4525451945264520static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
+16-2
net/mptcp/protocol.c
···466466static void mptcp_set_datafin_timeout(const struct sock *sk)467467{468468 struct inet_connection_sock *icsk = inet_csk(sk);469469+ u32 retransmits;469470470470- mptcp_sk(sk)->timer_ival = min(TCP_RTO_MAX,471471- TCP_RTO_MIN << icsk->icsk_retransmits);471471+ retransmits = min_t(u32, icsk->icsk_retransmits,472472+ ilog2(TCP_RTO_MAX / TCP_RTO_MIN));473473+474474+ mptcp_sk(sk)->timer_ival = TCP_RTO_MIN << retransmits;472475}473476474477static void __mptcp_set_timeout(struct sock *sk, long tout)···32973294 return 0;3298329532993296 delta = msk->write_seq - v;32973297+ if (__mptcp_check_fallback(msk) && msk->first) {32983298+ struct tcp_sock *tp = tcp_sk(msk->first);32993299+33003300+ /* the first subflow is disconnected after close - see33013301+ * __mptcp_close_ssk(). tcp_disconnect() moves the write_seq33023302+ * so ignore that status, too.33033303+ */33043304+ if (!((1 << msk->first->sk_state) &33053305+ (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE)))33063306+ delta += READ_ONCE(tp->write_seq) - tp->snd_una;33073307+ }33003308 if (delta > INT_MAX)33013309 delta = INT_MAX;33023310
+3-2
net/netfilter/core.c
···428428 p = nf_entry_dereference(*pp);429429 new_hooks = nf_hook_entries_grow(p, reg);430430431431- if (!IS_ERR(new_hooks))431431+ if (!IS_ERR(new_hooks)) {432432+ hooks_validate(new_hooks);432433 rcu_assign_pointer(*pp, new_hooks);434434+ }433435434436 mutex_unlock(&nf_hook_mutex);435437 if (IS_ERR(new_hooks))436438 return PTR_ERR(new_hooks);437439438438- hooks_validate(new_hooks);439440#ifdef CONFIG_NETFILTER_INGRESS440441 if (nf_ingress_hook(reg, pf))441442 net_inc_ingress_queue();
···106106 printinfo("Nesting level(s): %d\n", nested);107107108108 epollfdp = calloc(nested, sizeof(int));109109- if (!epollfd)109109+ if (!epollfdp)110110 err(EXIT_FAILURE, "calloc");111111112112 for (i = 0; i < nested; i++) {
+5-3
tools/perf/util/parse-events.c
···16481648{16491649 struct parse_events_term *term;16501650 struct list_head *list = NULL;16511651+ struct list_head *orig_head = NULL;16511652 struct perf_pmu *pmu = NULL;16521653 int ok = 0;16531654 char *config;···16751674 }16761675 list_add_tail(&term->list, head);1677167616781678-16791677 /* Add it for all PMUs that support the alias */16801678 list = malloc(sizeof(struct list_head));16811679 if (!list)···1687168716881688 list_for_each_entry(alias, &pmu->aliases, list) {16891689 if (!strcasecmp(alias->name, str)) {16901690+ parse_events_copy_term_list(head, &orig_head);16901691 if (!parse_events_add_pmu(parse_state, list,16911691- pmu->name, head,16921692+ pmu->name, orig_head,16921693 true, true)) {16931694 pr_debug("%s -> %s/%s/\n", str,16941695 pmu->name, alias->str);16951696 ok++;16961697 }16981698+ parse_events_terms__delete(orig_head);16971699 }16981700 }16991701 }···21952193 for (i = 0; i < ARRAY_SIZE(symbols); i++, tmp++) {21962194 tmp->type = symbols[i].type;21972195 tmp->symbol = strdup(symbols[i].symbol);21982198- if (!list->symbol)21962196+ if (!tmp->symbol)21992197 goto err_free;22002198 }22012199
···366366{367367 struct kvm_vm *vm;368368 unsigned int i;369369+ int ret;369370 int nr_vcpus = test_args.nr_vcpus;370371371372 vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);···383382384383 ucall_init(vm, NULL);385384 test_init_timer_irq(vm);386386- vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);385385+ ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);386386+ if (ret < 0) {387387+ print_skip("Failed to create vgic-v3");388388+ exit(KSFT_SKIP);389389+ }387390388391 /* Make all the test's cmdline args visible to the guest */389392 sync_global_to_guest(vm, test_args);
···11+// SPDX-License-Identifier: GPL-2.022+33+#include <stdio.h>44+#include <stdlib.h>55+#include <fcntl.h>66+#include <string.h>77+#include <unistd.h>88+#include <signal.h>99+1010+#include <arpa/inet.h>1111+#include <sys/socket.h>1212+1313+#define PORT 123451414+#define RUNTIME 101515+1616+static struct {1717+ unsigned int timeout;1818+ unsigned int port;1919+} opts = {2020+ .timeout = RUNTIME,2121+ .port = PORT,2222+};2323+2424+static void handler(int sig)2525+{2626+ _exit(sig == SIGALRM ? 0 : 1);2727+}2828+2929+static void set_timeout(void)3030+{3131+ struct sigaction action = {3232+ .sa_handler = handler,3333+ };3434+3535+ sigaction(SIGALRM, &action, NULL);3636+3737+ alarm(opts.timeout);3838+}3939+4040+static void do_connect(const struct sockaddr_in *dst)4141+{4242+ int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);4343+4444+ if (s >= 0)4545+ fcntl(s, F_SETFL, O_NONBLOCK);4646+4747+ connect(s, (struct sockaddr *)dst, sizeof(*dst));4848+ close(s);4949+}5050+5151+static void do_accept(const struct sockaddr_in *src)5252+{5353+ int c, one = 1, s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);5454+5555+ if (s < 0)5656+ return;5757+5858+ setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));5959+ setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));6060+6161+ bind(s, (struct sockaddr *)src, sizeof(*src));6262+6363+ listen(s, 16);6464+6565+ c = accept(s, NULL, NULL);6666+ if (c >= 0)6767+ close(c);6868+6969+ close(s);7070+}7171+7272+static int accept_loop(void)7373+{7474+ struct sockaddr_in src = {7575+ .sin_family = AF_INET,7676+ .sin_port = htons(opts.port),7777+ };7878+7979+ inet_pton(AF_INET, "127.0.0.1", &src.sin_addr);8080+8181+ set_timeout();8282+8383+ for (;;)8484+ do_accept(&src);8585+8686+ return 1;8787+}8888+8989+static int connect_loop(void)9090+{9191+ struct sockaddr_in dst = {9292+ .sin_family = AF_INET,9393+ .sin_port = htons(opts.port),9494+ };9595+9696+ inet_pton(AF_INET, "127.0.0.1", &dst.sin_addr);9797+9898+ set_timeout();9999+100100+ for (;;)101101+ do_connect(&dst);102102+103103+ return 1;104104+}105105+106106+static void parse_opts(int argc, char **argv)107107+{108108+ int c;109109+110110+ while ((c = getopt(argc, argv, "t:p:")) != -1) {111111+ switch (c) {112112+ case 't':113113+ opts.timeout = atoi(optarg);114114+ break;115115+ case 'p':116116+ opts.port = atoi(optarg);117117+ break;118118+ }119119+ }120120+}121121+122122+int main(int argc, char *argv[])123123+{124124+ pid_t p;125125+126126+ parse_opts(argc, argv);127127+128128+ p = fork();129129+ if (p < 0)130130+ return 111;131131+132132+ if (p > 0)133133+ return accept_loop();134134+135135+ return connect_loop();136136+}
+19
tools/testing/selftests/netfilter/nft_queue.sh
···113113 chain output {114114 type filter hook output priority $prio; policy accept;115115 tcp dport 12345 queue num 3116116+ tcp sport 23456 queue num 3116117 jump nfq117118 }118119 chain post {···297296 wait 2>/dev/null298297}299298299299+test_tcp_localhost_connectclose()300300+{301301+ tmpfile=$(mktemp) || exit 1302302+303303+ ip netns exec ${nsrouter} ./connect_close -p 23456 -t $timeout &304304+305305+ ip netns exec ${nsrouter} ./nf-queue -q 3 -t $timeout &306306+ local nfqpid=$!307307+308308+ sleep 1309309+ rm -f "$tmpfile"310310+311311+ wait $rpid312312+ [ $? -eq 0 ] && echo "PASS: tcp via loopback with connect/close"313313+ wait 2>/dev/null314314+}315315+300316test_tcp_localhost_requeue()301317{302318ip netns exec ${nsrouter} nft -f /dev/stdin <<EOF···442424443425test_tcp_forward444426test_tcp_localhost427427+test_tcp_localhost_connectclose445428test_tcp_localhost_requeue446429test_icmp_vrf447430
+19-7
tools/testing/selftests/vm/hugepage-mremap.c
···33 * hugepage-mremap:44 *55 * Example of remapping huge page memory in a user application using the66- * mremap system call. Code assumes a hugetlbfs filesystem is mounted77- * at './huge'. The amount of memory used by this test is decided by a command88- * line argument in MBs. If missing, the default amount is 10MB.66+ * mremap system call. The path to a file in a hugetlbfs filesystem must77+ * be passed as the last argument to this test. The amount of memory used88+ * by this test in MBs can optionally be passed as an argument. If no memory99+ * amount is passed, the default amount is 10MB.910 *1011 * To make sure the test triggers pmd sharing and goes through the 'unshare'1112 * path in the mremap code use 1GB (1024) or more.···2625#define DEFAULT_LENGTH_MB 10UL2726#define MB_TO_BYTES(x) (x * 1024 * 1024)28272929-#define FILE_NAME "huge/hugepagefile"3028#define PROTECTION (PROT_READ | PROT_WRITE | PROT_EXEC)3129#define FLAGS (MAP_SHARED | MAP_ANONYMOUS)3230···107107108108int main(int argc, char *argv[])109109{110110+ size_t length;111111+112112+ if (argc != 2 && argc != 3) {113113+ printf("Usage: %s [length_in_MB] <hugetlb_file>\n", argv[0]);114114+ exit(1);115115+ }116116+110117 /* Read memory length as the first arg if valid, otherwise fallback to111111- * the default length. Any additional args are ignored.118118+ * the default length.112119 */113113- size_t length = argc > 1 ? (size_t)atoi(argv[1]) : 0UL;120120+ if (argc == 3)121121+ length = argc > 2 ? (size_t)atoi(argv[1]) : 0UL;114122115123 length = length > 0 ? length : DEFAULT_LENGTH_MB;116124 length = MB_TO_BYTES(length);117125118126 int ret = 0;119127120120- int fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755);128128+ /* last arg is the hugetlb file name */129129+ int fd = open(argv[argc-1], O_CREAT | O_RDWR, 0755);121130122131 if (fd < 0) {123132 perror("Open failed");···177168 ret = read_bytes(addr, length);178169179170 munmap(addr, length);171171+172172+ close(fd);173173+ unlink(argv[argc-1]);180174181175 return ret;182176}