···478478 /sys/devices/system/cpu/vulnerabilities/meltdown479479 /sys/devices/system/cpu/vulnerabilities/spectre_v1480480 /sys/devices/system/cpu/vulnerabilities/spectre_v2481481+ /sys/devices/system/cpu/vulnerabilities/spec_store_bypass481482Date: January 2018482483Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>483484Description: Information about CPU vulnerabilities
+45
Documentation/admin-guide/kernel-parameters.txt
···26802680 allow data leaks with this option, which is equivalent26812681 to spectre_v2=off.2682268226832683+ nospec_store_bypass_disable26842684+ [HW] Disable all mitigations for the Speculative Store Bypass vulnerability26852685+26832686 noxsave [BUGS=X86] Disables x86 extended register state save26842687 and restore using xsave. The kernel will fallback to26852688 enabling legacy floating-point and sse state.···4027402440284025 Not specifying this option is equivalent to40294026 spectre_v2=auto.40274027+40284028+ spec_store_bypass_disable=40294029+ [HW] Control Speculative Store Bypass (SSB) Disable mitigation40304030+ (Speculative Store Bypass vulnerability)40314031+40324032+ Certain CPUs are vulnerable to an exploit against a40334033+ a common industry wide performance optimization known40344034+ as "Speculative Store Bypass" in which recent stores40354035+ to the same memory location may not be observed by40364036+ later loads during speculative execution. The idea40374037+ is that such stores are unlikely and that they can40384038+ be detected prior to instruction retirement at the40394039+ end of a particular speculation execution window.40404040+40414041+ In vulnerable processors, the speculatively forwarded40424042+ store can be used in a cache side channel attack, for40434043+ example to read memory to which the attacker does not40444044+ directly have access (e.g. inside sandboxed code).40454045+40464046+ This parameter controls whether the Speculative Store40474047+ Bypass optimization is used.40484048+40494049+ on - Unconditionally disable Speculative Store Bypass40504050+ off - Unconditionally enable Speculative Store Bypass40514051+ auto - Kernel detects whether the CPU model contains an40524052+ implementation of Speculative Store Bypass and40534053+ picks the most appropriate mitigation. If the40544054+ CPU is not vulnerable, "off" is selected. If the40554055+ CPU is vulnerable the default mitigation is40564056+ architecture and Kconfig dependent. See below.40574057+ prctl - Control Speculative Store Bypass per thread40584058+ via prctl. Speculative Store Bypass is enabled40594059+ for a process by default. The state of the control40604060+ is inherited on fork.40614061+ seccomp - Same as "prctl" above, but all seccomp threads40624062+ will disable SSB unless they explicitly opt out.40634063+40644064+ Not specifying this option is equivalent to40654065+ spec_store_bypass_disable=auto.40664066+40674067+ Default mitigations:40684068+ X86: If CONFIG_SECCOMP=y "seccomp", otherwise "prctl"4030406940314070 spia_io_base= [HW,MTD]40324071 spia_fio_base=
···5757 - txd2-skew-ps : Skew control of TX data 2 pad5858 - txd3-skew-ps : Skew control of TX data 3 pad59596060+ - micrel,force-master:6161+ Boolean, force phy to master mode. Only set this option if the phy6262+ reference clock provided at CLK125_NDO pin is used as MAC reference6363+ clock because the clock jitter in slave mode is to high (errata#2).6464+ Attention: The link partner must be configurable as slave otherwise6565+ no link will be established.6666+6067Examples:61686269 mdio {
+1-1
Documentation/i2c/busses/i2c-ocores
···2233Supported adapters:44 * OpenCores.org I2C controller by Richard Herveille (see datasheet link)55- Datasheet: http://www.opencores.org/projects.cgi/web/i2c/overview55+ https://opencores.org/project/i2c/overview6677Author: Peter Korsgaard <jacmet@sunsite.dk>88
-6
Documentation/networking/ppp_generic.txt
···300300The ioctl calls available on an instance of /dev/ppp attached to a301301channel are:302302303303-* PPPIOCDETACH detaches the instance from the channel. This ioctl is304304- deprecated since the same effect can be achieved by closing the305305- instance. In order to prevent possible races this ioctl will fail306306- with an EINVAL error if more than one file descriptor refers to this307307- instance (i.e. as a result of dup(), dup2() or fork()).308308-309303* PPPIOCCONNECT connects this channel to a PPP interface. The310304 argument should point to an int containing the interface unit311305 number. It will return an EINVAL error if the channel is already
+1
Documentation/userspace-api/index.rst
···1919 no_new_privs2020 seccomp_filter2121 unshare2222+ spec_ctrl22232324.. only:: subproject and html2425
+94
Documentation/userspace-api/spec_ctrl.rst
···11+===================22+Speculation Control33+===================44+55+Quite some CPUs have speculation-related misfeatures which are in66+fact vulnerabilities causing data leaks in various forms even across77+privilege domains.88+99+The kernel provides mitigation for such vulnerabilities in various1010+forms. Some of these mitigations are compile-time configurable and some1111+can be supplied on the kernel command line.1212+1313+There is also a class of mitigations which are very expensive, but they can1414+be restricted to a certain set of processes or tasks in controlled1515+environments. The mechanism to control these mitigations is via1616+:manpage:`prctl(2)`.1717+1818+There are two prctl options which are related to this:1919+2020+ * PR_GET_SPECULATION_CTRL2121+2222+ * PR_SET_SPECULATION_CTRL2323+2424+PR_GET_SPECULATION_CTRL2525+-----------------------2626+2727+PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature2828+which is selected with arg2 of prctl(2). The return value uses bits 0-3 with2929+the following meaning:3030+3131+==== ===================== ===================================================3232+Bit Define Description3333+==== ===================== ===================================================3434+0 PR_SPEC_PRCTL Mitigation can be controlled per task by3535+ PR_SET_SPECULATION_CTRL.3636+1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is3737+ disabled.3838+2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is3939+ enabled.4040+3 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A4141+ subsequent prctl(..., PR_SPEC_ENABLE) will fail.4242+==== ===================== ===================================================4343+4444+If all bits are 0 the CPU is not affected by the speculation misfeature.4545+4646+If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is4747+available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation4848+misfeature will fail.4949+5050+PR_SET_SPECULATION_CTRL5151+-----------------------5252+5353+PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which5454+is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand5555+in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or5656+PR_SPEC_FORCE_DISABLE.5757+5858+Common error codes5959+------------------6060+======= =================================================================6161+Value Meaning6262+======= =================================================================6363+EINVAL The prctl is not implemented by the architecture or unused6464+ prctl(2) arguments are not 0.6565+6666+ENODEV arg2 is selecting a not supported speculation misfeature.6767+======= =================================================================6868+6969+PR_SET_SPECULATION_CTRL error codes7070+-----------------------------------7171+======= =================================================================7272+Value Meaning7373+======= =================================================================7474+0 Success7575+7676+ERANGE arg3 is incorrect, i.e. it's neither PR_SPEC_ENABLE nor7777+ PR_SPEC_DISABLE nor PR_SPEC_FORCE_DISABLE.7878+7979+ENXIO Control of the selected speculation misfeature is not possible.8080+ See PR_GET_SPECULATION_CTRL.8181+8282+EPERM Speculation was disabled with PR_SPEC_FORCE_DISABLE and caller8383+ tried to enable it again.8484+======= =================================================================8585+8686+Speculation misfeature controls8787+-------------------------------8888+- PR_SPEC_STORE_BYPASS: Speculative Store Bypass8989+9090+ Invocations:9191+ * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, 0, 0, 0);9292+ * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);9393+ * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);9494+ * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);
+19-11
MAINTAINERS
···23322332F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt2333233323342334ATHEROS ATH GENERIC UTILITIES23352335-M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>23352335+M: Kalle Valo <kvalo@codeaurora.org>23362336L: linux-wireless@vger.kernel.org23372337S: Supported23382338F: drivers/net/wireless/ath/*···23472347F: drivers/net/wireless/ath/ath5k/2348234823492349ATHEROS ATH6KL WIRELESS DRIVER23502350-M: Kalle Valo <kvalo@qca.qualcomm.com>23502350+M: Kalle Valo <kvalo@codeaurora.org>23512351L: linux-wireless@vger.kernel.org23522352W: http://wireless.kernel.org/en/users/Drivers/ath6kl23532353T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git···53945394F: drivers/iommu/exynos-iommu.c5395539553965396EZchip NPS platform support53975397-M: Elad Kanfi <eladkan@mellanox.com>53985397M: Vineet Gupta <vgupta@synopsys.com>53995398S: Supported54005399F: arch/arc/plat-eznps···65096510F: drivers/net/ethernet/huawei/hinic/6510651165116512HUGETLB FILESYSTEM65126512-M: Nadia Yvette Chambers <nyc@holomorphy.com>65136513+M: Mike Kravetz <mike.kravetz@oracle.com>65146514+L: linux-mm@kvack.org65136515S: Maintained65146516F: fs/hugetlbfs/65176517+F: mm/hugetlb.c65186518+F: include/linux/hugetlb.h65196519+F: Documentation/admin-guide/mm/hugetlbpage.rst65206520+F: Documentation/vm/hugetlbfs_reserv.rst65216521+F: Documentation/ABI/testing/sysfs-kernel-mm-hugepages6515652265166523HVA ST MEDIA DRIVER65176524M: Jean-Christophe Trotin <jean-christophe.trotin@st.com>···90329027F: drivers/net/ethernet/mellanox/mlx5/core/en_*9033902890349029MELLANOX ETHERNET INNOVA DRIVER90359035-M: Ilan Tayari <ilant@mellanox.com>90369030R: Boris Pismenny <borisp@mellanox.com>90379031L: netdev@vger.kernel.org90389032S: Supported···90419037F: include/linux/mlx5/mlx5_ifc_fpga.h9042903890439039MELLANOX ETHERNET INNOVA IPSEC DRIVER90449044-M: Ilan Tayari <ilant@mellanox.com>90459040R: Boris Pismenny <borisp@mellanox.com>90469041L: netdev@vger.kernel.org90479042S: Supported···9096909390979094MELLANOX MLX5 core VPI driver90989095M: Saeed Mahameed <saeedm@mellanox.com>90999099-M: Matan Barak <matanb@mellanox.com>91009096M: Leon Romanovsky <leonro@mellanox.com>91019097L: netdev@vger.kernel.org91029098L: linux-rdma@vger.kernel.org···91069104F: include/linux/mlx5/9107910591089106MELLANOX MLX5 IB driver91099109-M: Matan Barak <matanb@mellanox.com>91109107M: Leon Romanovsky <leonro@mellanox.com>91119108L: linux-rdma@vger.kernel.org91129109W: http://www.mellanox.com···98399838F: net/netfilter/xt_SECMARK.c9840983998419840NETWORKING [TLS]98429842-M: Ilya Lesokhin <ilyal@mellanox.com>98439841M: Aviad Yehezkel <aviadye@mellanox.com>98449842M: Dave Watson <davejwatson@fb.com>98459843L: netdev@vger.kernel.org···1163811638F: drivers/media/tuners/qt1010*11639116391164011640QUALCOMM ATHEROS ATH10K WIRELESS DRIVER1164111641-M: Kalle Valo <kvalo@qca.qualcomm.com>1164111641+M: Kalle Valo <kvalo@codeaurora.org>1164211642L: ath10k@lists.infradead.org1164311643W: http://wireless.kernel.org/en/users/Drivers/ath10k1164411644T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git···1168911689F: drivers/media/platform/qcom/venus/11690116901169111691QUALCOMM WCN36XX WIRELESS DRIVER1169211692-M: Eugene Krasnikov <k.eugene.e@gmail.com>1169211692+M: Kalle Valo <kvalo@codeaurora.org>1169311693L: wcn36xx@lists.infradead.org1169411694W: http://wireless.kernel.org/en/users/Drivers/wcn36xx1169511695T: git git://github.com/KrasnikovEugene/wcn36xx.git···1551815518L: linux-kernel@vger.kernel.org1551915519S: Supported1552015520F: drivers/char/xillybus/1552115521+1552215522+XLP9XX I2C DRIVER1552315523+M: George Cherian <george.cherian@cavium.com>1552415524+M: Jan Glauber <jglauber@cavium.com>1552515525+L: linux-i2c@vger.kernel.org1552615526+W: http://www.cavium.com1552715527+S: Supported1552815528+F: drivers/i2c/busses/i2c-xlp9xx.c15521155291552215530XRA1403 GPIO EXPANDER1552315531M: Nandor Han <nandor.han@ge.com>
+7-4
Makefile
···22VERSION = 433PATCHLEVEL = 1744SUBLEVEL = 055-EXTRAVERSION = -rc655+EXTRAVERSION =66NAME = Merciless Moray7788# *DOCUMENTATION*···500500RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))501501export RETPOLINE_CFLAGS502502503503+KBUILD_CFLAGS += $(call cc-option,-fno-PIE)504504+KBUILD_AFLAGS += $(call cc-option,-fno-PIE)505505+503506# check for 'asm goto'504507ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)505508 CC_HAVE_ASM_GOTO := 1···624621# Defaults to vmlinux, but the arch makefile usually adds further targets625622all: vmlinux626623627627-KBUILD_CFLAGS += $(call cc-option,-fno-PIE)628628-KBUILD_AFLAGS += $(call cc-option,-fno-PIE)629629-CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)624624+CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \625625+ $(call cc-option,-fno-tree-loop-im) \626626+ $(call cc-disable-warning,maybe-uninitialized,)630627export CFLAGS_GCOV CFLAGS_KCOV631628632629# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
+1
arch/alpha/Kconfig
···211211config ALPHA_JENSEN212212 bool "Jensen"213213 depends on BROKEN214214+ select DMA_DIRECT_OPS214215 help215216 DEC PC 150 AXP (aka Jensen): This is a very old Digital system - one216217 of the first-generation Alpha systems. A number of these systems
···51515252 leds {5353 /* The LEDs use PG0~2 pins, which conflict with MMC1 */5454- status = "disbaled";5454+ status = "disabled";5555 };5656};5757
+1-1
arch/arm/mach-ep93xx/core.c
···323323324324/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */325325static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {326326- .dev_id = "i2c-gpio",326326+ .dev_id = "i2c-gpio.0",327327 .table = {328328 /* Use local offsets on gpiochip/port "G" */329329 GPIO_LOOKUP_IDX("G", 1, NULL, 0,
···466466void __init dma_contiguous_remap(void)467467{468468 int i;469469-470470- if (!dma_mmu_remap_num)471471- return;472472-473473- /* call flush_cache_all() since CMA area would be large enough */474474- flush_cache_all();475469 for (i = 0; i < dma_mmu_remap_num; i++) {476470 phys_addr_t start = dma_mmu_remap[i].base;477471 phys_addr_t end = start + dma_mmu_remap[i].size;···498504 flush_tlb_kernel_range(__phys_to_virt(start),499505 __phys_to_virt(end));500506501501- /*502502- * All the memory in CMA region will be on ZONE_MOVABLE.503503- * If that zone is considered as highmem, the memory in CMA504504- * region is also considered as highmem even if it's505505- * physical address belong to lowmem. In this case,506506- * re-mapping isn't required.507507- */508508- if (!is_highmem_idx(ZONE_MOVABLE))509509- iotable_init(&map, 1);507507+ iotable_init(&map, 1);510508 }511509}512510
-1
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
···299299 /* GPIO blocks 16 thru 19 do not appear to be routed to pins */300300301301 dwmmc_0: dwmmc0@f723d000 {302302- max-frequency = <150000000>;303302 cap-mmc-highspeed;304303 mmc-hs200-1_8v;305304 non-removable;
···7575 /* arm-smccc */7676EXPORT_SYMBOL(__arm_smccc_smc);7777EXPORT_SYMBOL(__arm_smccc_hvc);7878+7979+ /* tishift.S */8080+extern long long __ashlti3(long long a, int b);8181+EXPORT_SYMBOL(__ashlti3);8282+extern long long __ashrti3(long long a, int b);8383+EXPORT_SYMBOL(__ashrti3);8484+extern long long __lshrti3(long long a, int b);8585+EXPORT_SYMBOL(__lshrti3);
+2-13
arch/arm64/lib/tishift.S
···11-/*22- * Copyright (C) 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.11+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)32 *44- * This program is free software; you can redistribute it and/or modify55- * it under the terms of the GNU General Public License version 2 as66- * published by the Free Software Foundation.77- *88- * This program is distributed in the hope that it will be useful,99- * but WITHOUT ANY WARRANTY; without even the implied warranty of1010- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111- * GNU General Public License for more details.1212- *1313- * You should have received a copy of the GNU General Public License1414- * along with this program. If not, see <http://www.gnu.org/licenses/>.33+ * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.154 */165176#include <linux/linkage.h>
+51
arch/arm64/mm/fault.c
···293293static void __do_user_fault(struct siginfo *info, unsigned int esr)294294{295295 current->thread.fault_address = (unsigned long)info->si_addr;296296+297297+ /*298298+ * If the faulting address is in the kernel, we must sanitize the ESR.299299+ * From userspace's point of view, kernel-only mappings don't exist300300+ * at all, so we report them as level 0 translation faults.301301+ * (This is not quite the way that "no mapping there at all" behaves:302302+ * an alignment fault not caused by the memory type would take303303+ * precedence over translation fault for a real access to empty304304+ * space. Unfortunately we can't easily distinguish "alignment fault305305+ * not caused by memory type" from "alignment fault caused by memory306306+ * type", so we ignore this wrinkle and just return the translation307307+ * fault.)308308+ */309309+ if (current->thread.fault_address >= TASK_SIZE) {310310+ switch (ESR_ELx_EC(esr)) {311311+ case ESR_ELx_EC_DABT_LOW:312312+ /*313313+ * These bits provide only information about the314314+ * faulting instruction, which userspace knows already.315315+ * We explicitly clear bits which are architecturally316316+ * RES0 in case they are given meanings in future.317317+ * We always report the ESR as if the fault was taken318318+ * to EL1 and so ISV and the bits in ISS[23:14] are319319+ * clear. (In fact it always will be a fault to EL1.)320320+ */321321+ esr &= ESR_ELx_EC_MASK | ESR_ELx_IL |322322+ ESR_ELx_CM | ESR_ELx_WNR;323323+ esr |= ESR_ELx_FSC_FAULT;324324+ break;325325+ case ESR_ELx_EC_IABT_LOW:326326+ /*327327+ * Claim a level 0 translation fault.328328+ * All other bits are architecturally RES0 for faults329329+ * reported with that DFSC value, so we clear them.330330+ */331331+ esr &= ESR_ELx_EC_MASK | ESR_ELx_IL;332332+ esr |= ESR_ELx_FSC_FAULT;333333+ break;334334+ default:335335+ /*336336+ * This should never happen (entry.S only brings us337337+ * into this code for insn and data aborts from a lower338338+ * exception level). Fail safe by not providing an ESR339339+ * context record at all.340340+ */341341+ WARN(1, "ESR 0x%x is not DABT or IABT from EL0\n", esr);342342+ esr = 0;343343+ break;344344+ }345345+ }346346+296347 current->thread.fault_code = esr;297348 arm64_force_sig_info(info, esr_to_fault_info(esr)->name, current);298349}
+10-6
arch/arm64/mm/mmu.c
···933933{934934 pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT |935935 pgprot_val(mk_sect_prot(prot)));936936+ pud_t new_pud = pfn_pud(__phys_to_pfn(phys), sect_prot);936937937937- /* ioremap_page_range doesn't honour BBM */938938- if (pud_present(READ_ONCE(*pudp)))938938+ /* Only allow permission changes for now */939939+ if (!pgattr_change_is_safe(READ_ONCE(pud_val(*pudp)),940940+ pud_val(new_pud)))939941 return 0;940942941943 BUG_ON(phys & ~PUD_MASK);942942- set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot));944944+ set_pud(pudp, new_pud);943945 return 1;944946}945947···949947{950948 pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT |951949 pgprot_val(mk_sect_prot(prot)));950950+ pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), sect_prot);952951953953- /* ioremap_page_range doesn't honour BBM */954954- if (pmd_present(READ_ONCE(*pmdp)))952952+ /* Only allow permission changes for now */953953+ if (!pgattr_change_is_safe(READ_ONCE(pmd_val(*pmdp)),954954+ pmd_val(new_pmd)))955955 return 0;956956957957 BUG_ON(phys & ~PMD_MASK);958958- set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot));958958+ set_pmd(pmdp, new_pmd);959959 return 1;960960}961961
···721721 if (value & ~known_bits)722722 return -EOPNOTSUPP;723723724724+ /* Setting FRE without FR is not supported. */725725+ if ((value & (PR_FP_MODE_FR | PR_FP_MODE_FRE)) == PR_FP_MODE_FRE)726726+ return -EOPNOTSUPP;727727+724728 /* Avoid inadvertently triggering emulation */725729 if ((value & PR_FP_MODE_FR) && raw_cpu_has_fpu &&726730 !(raw_current_cpu_data.fpu_id & MIPS_FPIR_F64))
+19-5
arch/mips/kernel/ptrace.c
···463463/*464464 * Copy the floating-point context to the supplied NT_PRFPREG buffer.465465 * Choose the appropriate helper for general registers, and then copy466466- * the FCSR register separately.466466+ * the FCSR and FIR registers separately.467467 */468468static int fpr_get(struct task_struct *target,469469 const struct user_regset *regset,···471471 void *kbuf, void __user *ubuf)472472{473473 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);474474+ const int fir_pos = fcr31_pos + sizeof(u32);474475 int err;475476476477 if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))···484483 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,485484 &target->thread.fpu.fcr31,486485 fcr31_pos, fcr31_pos + sizeof(u32));486486+ if (err)487487+ return err;488488+489489+ err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,490490+ &boot_cpu_data.fpu_id,491491+ fir_pos, fir_pos + sizeof(u32));487492488493 return err;489494}···538531/*539532 * Copy the supplied NT_PRFPREG buffer to the floating-point context.540533 * Choose the appropriate helper for general registers, and then copy541541- * the FCSR register separately.534534+ * the FCSR register separately. Ignore the incoming FIR register535535+ * contents though, as the register is read-only.542536 *543537 * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0',544538 * which is supposed to have been guaranteed by the kernel before···553545 const void *kbuf, const void __user *ubuf)554546{555547 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);548548+ const int fir_pos = fcr31_pos + sizeof(u32);556549 u32 fcr31;557550 int err;558551···580571581572 ptrace_setfcr31(target, fcr31);582573 }574574+575575+ if (count > 0)576576+ err = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,577577+ fir_pos,578578+ fir_pos + sizeof(u32));583579584580 return err;585581}···807793 fregs = get_fpu_regs(child);808794809795#ifdef CONFIG_32BIT810810- if (test_thread_flag(TIF_32BIT_FPREGS)) {796796+ if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {811797 /*812798 * The odd registers are actually the high813799 * order bits of the values stored in the even···818804 break;819805 }820806#endif821821- tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);807807+ tmp = get_fpr64(&fregs[addr - FPR_BASE], 0);822808 break;823809 case PC:824810 tmp = regs->cp0_epc;···902888903889 init_fp_ctx(child);904890#ifdef CONFIG_32BIT905905- if (test_thread_flag(TIF_32BIT_FPREGS)) {891891+ if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {906892 /*907893 * The odd registers are actually the high908894 * order bits of the values stored in the even
+3-3
arch/mips/kernel/ptrace32.c
···9999 break;100100 }101101 fregs = get_fpu_regs(child);102102- if (test_thread_flag(TIF_32BIT_FPREGS)) {102102+ if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {103103 /*104104 * The odd registers are actually the high105105 * order bits of the values stored in the even···109109 addr & 1);110110 break;111111 }112112- tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);112112+ tmp = get_fpr64(&fregs[addr - FPR_BASE], 0);113113 break;114114 case PC:115115 tmp = regs->cp0_epc;···212212 sizeof(child->thread.fpu));213213 child->thread.fpu.fcr31 = 0;214214 }215215- if (test_thread_flag(TIF_32BIT_FPREGS)) {215215+ if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {216216 /*217217 * The odd registers are actually the high218218 * order bits of the values stored in the even
···851851 /*852852 * Either no secondary cache or the available caches don't have the853853 * subset property so we have to flush the primary caches854854- * explicitly854854+ * explicitly.855855+ * If we would need IPI to perform an INDEX-type operation, then856856+ * we have to use the HIT-type alternative as IPI cannot be used857857+ * here due to interrupts possibly being disabled.855858 */856856- if (size >= dcache_size) {859859+ if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {857860 r4k_blast_dcache();858861 } else {859862 R4600_HIT_CACHEOP_WAR_IMPL;···893890 return;894891 }895892896896- if (size >= dcache_size) {893893+ if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {897894 r4k_blast_dcache();898895 } else {899896 R4600_HIT_CACHEOP_WAR_IMPL;
···5757 isb5858 mtsr $r4, $L1_PPTB ! load page table pointer\n"59596060-/* set NTC0 cacheable/writeback, mutliple page size in use */6161- mfsr $r3, $MMU_CTL6262- li $r0, #~MMU_CTL_mskNTC06363- and $r3, $r3, $r06464-#ifdef CONFIG_ANDES_PAGE_SIZE_4KB6565- ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0))6060+#ifdef CONFIG_CPU_DCACHE_DISABLE6161+ #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_NON6662#else6767- ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)|MMU_CTL_D8KB)6363+ #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH6464+ #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WT6565+ #else6666+ #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WB6767+ #endif6868+#endif6969+7070+/* set NTC cacheability, mutliple page size in use */7171+ mfsr $r3, $MMU_CTL7272+#if CONFIG_MEMORY_START >= 0xc00000007373+ ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC3)7474+#elif CONFIG_MEMORY_START >= 0x800000007575+ ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC2)7676+#elif CONFIG_MEMORY_START >= 0x400000007777+ ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC1)7878+#else7979+ ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC0)8080+#endif8181+8282+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB8383+ ori $r3, $r3, #(MMU_CTL_mskMPZIU)8484+#else8585+ ori $r3, $r3, #(MMU_CTL_mskMPZIU|MMU_CTL_D8KB)6886#endif6987#ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS7088 li $r0, #MMU_CTL_UNA
+3
arch/nds32/kernel/setup.c
···293293 /* paging_init() sets up the MMU and marks all pages as reserved */294294 paging_init();295295296296+ /* invalidate all TLB entries because the new mapping is created */297297+ __nds32__tlbop_flua();298298+296299 /* use generic way to parse */297300 parse_early_param();298301
···69269222: ld r8,VCORE_TB_OFFSET(r5)693693 cmpdi r8,0694694 beq 37f695695+ std r8, VCORE_TB_OFFSET_APPL(r5)695696 mftb r6 /* current host timebase */696697 add r8,r8,r6697698 mtspr SPRN_TBU40,r8 /* update upper 40 bits */···941940ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300)9429418:943942944944- /*945945- * Set the decrementer to the guest decrementer.946946- */947947- ld r8,VCPU_DEC_EXPIRES(r4)948948- /* r8 is a host timebase value here, convert to guest TB */949949- ld r5,HSTATE_KVM_VCORE(r13)950950- ld r6,VCORE_TB_OFFSET(r5)951951- add r8,r8,r6952952- mftb r7953953- subf r3,r7,r8954954- mtspr SPRN_DEC,r3955955-956943 ld r5, VCPU_SPRG0(r4)957944 ld r6, VCPU_SPRG1(r4)958945 ld r7, VCPU_SPRG2(r4)···9931004 ld r8,VCORE_LPCR(r5)9941005 mtspr SPRN_LPCR,r89951006 isync10071007+10081008+ /*10091009+ * Set the decrementer to the guest decrementer.10101010+ */10111011+ ld r8,VCPU_DEC_EXPIRES(r4)10121012+ /* r8 is a host timebase value here, convert to guest TB */10131013+ ld r5,HSTATE_KVM_VCORE(r13)10141014+ ld r6,VCORE_TB_OFFSET_APPL(r5)10151015+ add r8,r8,r610161016+ mftb r710171017+ subf r3,r7,r810181018+ mtspr SPRN_DEC,r399610199971020 /* Check if HDEC expires soon */9981021 mfspr r3, SPRN_HDEC···1598159715991598guest_bypass:16001599 stw r12, STACK_SLOT_TRAP(r1)16011601- mr r3, r1216001600+16011601+ /* Save DEC */16021602+ /* Do this before kvmhv_commence_exit so we know TB is guest TB */16031603+ ld r3, HSTATE_KVM_VCORE(r13)16041604+ mfspr r5,SPRN_DEC16051605+ mftb r616061606+ /* On P9, if the guest has large decr enabled, don't sign extend */16071607+BEGIN_FTR_SECTION16081608+ ld r4, VCORE_LPCR(r3)16091609+ andis. r4, r4, LPCR_LD@h16101610+ bne 16f16111611+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)16121612+ extsw r5,r516131613+16: add r5,r5,r616141614+ /* r5 is a guest timebase value here, convert to host TB */16151615+ ld r4,VCORE_TB_OFFSET_APPL(r3)16161616+ subf r5,r4,r516171617+ std r5,VCPU_DEC_EXPIRES(r9)16181618+16021619 /* Increment exit count, poke other threads to exit */16201620+ mr r3, r1216031621 bl kvmhv_commence_exit16041622 nop16051623 ld r9, HSTATE_KVM_VCPU(r13)···16581638 add r4,r4,r616591639 mtspr SPRN_PURR,r316601640 mtspr SPRN_SPURR,r416611661-16621662- /* Save DEC */16631663- ld r3, HSTATE_KVM_VCORE(r13)16641664- mfspr r5,SPRN_DEC16651665- mftb r616661666- /* On P9, if the guest has large decr enabled, don't sign extend */16671667-BEGIN_FTR_SECTION16681668- ld r4, VCORE_LPCR(r3)16691669- andis. r4, r4, LPCR_LD@h16701670- bne 16f16711671-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)16721672- extsw r5,r516731673-16: add r5,r5,r616741674- /* r5 is a guest timebase value here, convert to host TB */16751675- ld r4,VCORE_TB_OFFSET(r3)16761676- subf r5,r4,r516771677- std r5,VCPU_DEC_EXPIRES(r9)1678164116791642BEGIN_FTR_SECTION16801643 b 8f···19081905 cmpwi cr2, r0, 019091906 beq cr2, 4f1910190719081908+ /*19091909+ * Radix: do eieio; tlbsync; ptesync sequence in case we19101910+ * interrupted the guest between a tlbie and a ptesync.19111911+ */19121912+ eieio19131913+ tlbsync19141914+ ptesync19151915+19111916 /* Radix: Handle the case where the guest used an illegal PID */19121917 LOAD_REG_ADDR(r4, mmu_base_pid)19131918 lwz r3, VCPU_GUEST_PID(r9)···202820172029201827:20302019 /* Subtract timebase offset from timebase */20312031- ld r8,VCORE_TB_OFFSET(r5)20202020+ ld r8, VCORE_TB_OFFSET_APPL(r5)20322021 cmpdi r8,020332022 beq 17f20232023+ li r0, 020242024+ std r0, VCORE_TB_OFFSET_APPL(r5)20342025 mftb r6 /* current guest timebase */20352026 subf r8,r8,r620362027 mtspr SPRN_TBU40,r8 /* update upper 40 bits */···27132700 add r3, r3, r527142701 ld r4, HSTATE_KVM_VCPU(r13)27152702 ld r5, HSTATE_KVM_VCORE(r13)27162716- ld r6, VCORE_TB_OFFSET(r5)27032703+ ld r6, VCORE_TB_OFFSET_APPL(r5)27172704 subf r3, r6, r3 /* convert to host TB value */27182705 std r3, VCPU_DEC_EXPIRES(r4)27192706···28122799 /* Restore guest decrementer */28132800 ld r3, VCPU_DEC_EXPIRES(r4)28142801 ld r5, HSTATE_KVM_VCORE(r13)28152815- ld r6, VCORE_TB_OFFSET(r5)28022802+ ld r6, VCORE_TB_OFFSET_APPL(r5)28162803 add r3, r3, r6 /* convert host TB to guest TB value */28172804 mftb r728182805 subf r3, r7, r3···36193606 */36203607kvmhv_start_timing:36213608 ld r5, HSTATE_KVM_VCORE(r13)36223622- lbz r6, VCORE_IN_GUEST(r5)36233623- cmpwi r6, 036243624- beq 5f /* if in guest, need to */36253625- ld r6, VCORE_TB_OFFSET(r5) /* subtract timebase offset */36263626-5: mftb r536273627- subf r5, r6, r536093609+ ld r6, VCORE_TB_OFFSET_APPL(r5)36103610+ mftb r536113611+ subf r5, r6, r5 /* subtract current timebase offset */36283612 std r3, VCPU_CUR_ACTIVITY(r4)36293613 std r5, VCPU_ACTIVITY_START(r4)36303614 blr···36323622 */36333623kvmhv_accumulate_time:36343624 ld r5, HSTATE_KVM_VCORE(r13)36353635- lbz r8, VCORE_IN_GUEST(r5)36363636- cmpwi r8, 036373637- beq 4f /* if in guest, need to */36383638- ld r8, VCORE_TB_OFFSET(r5) /* subtract timebase offset */36393639-4: ld r5, VCPU_CUR_ACTIVITY(r4)36253625+ ld r8, VCORE_TB_OFFSET_APPL(r5)36263626+ ld r5, VCPU_CUR_ACTIVITY(r4)36403627 ld r6, VCPU_ACTIVITY_START(r4)36413628 std r3, VCPU_CUR_ACTIVITY(r4)36423629 mftb r736433643- subf r7, r8, r736303630+ subf r7, r8, r7 /* subtract current timebase offset */36443631 std r7, VCPU_ACTIVITY_START(r4)36453632 cmpdi r5, 036463633 beqlr
+101-7
arch/powerpc/kvm/book3s_xive_template.c
···1111#define XGLUE(a,b) a##b1212#define GLUE(a,b) XGLUE(a,b)13131414+/* Dummy interrupt used when taking interrupts out of a queue in H_CPPR */1515+#define XICS_DUMMY 11616+1417static void GLUE(X_PFX,ack_pending)(struct kvmppc_xive_vcpu *xc)1518{1619 u8 cppr;···208205 goto skip_ipi;209206 }210207208208+ /* If it's the dummy interrupt, continue searching */209209+ if (hirq == XICS_DUMMY)210210+ goto skip_ipi;211211+211212 /* If fetching, update queue pointers */212213 if (scan_type == scan_fetch) {213214 q->idx = idx;···392385 __x_writeb(prio, __x_tima + TM_SPC_SET_OS_PENDING);393386}394387388388+static void GLUE(X_PFX,scan_for_rerouted_irqs)(struct kvmppc_xive *xive,389389+ struct kvmppc_xive_vcpu *xc)390390+{391391+ unsigned int prio;392392+393393+ /* For each priority that is now masked */394394+ for (prio = xc->cppr; prio < KVMPPC_XIVE_Q_COUNT; prio++) {395395+ struct xive_q *q = &xc->queues[prio];396396+ struct kvmppc_xive_irq_state *state;397397+ struct kvmppc_xive_src_block *sb;398398+ u32 idx, toggle, entry, irq, hw_num;399399+ struct xive_irq_data *xd;400400+ __be32 *qpage;401401+ u16 src;402402+403403+ idx = q->idx;404404+ toggle = q->toggle;405405+ qpage = READ_ONCE(q->qpage);406406+ if (!qpage)407407+ continue;408408+409409+ /* For each interrupt in the queue */410410+ for (;;) {411411+ entry = be32_to_cpup(qpage + idx);412412+413413+ /* No more ? */414414+ if ((entry >> 31) == toggle)415415+ break;416416+ irq = entry & 0x7fffffff;417417+418418+ /* Skip dummies and IPIs */419419+ if (irq == XICS_DUMMY || irq == XICS_IPI)420420+ goto next;421421+ sb = kvmppc_xive_find_source(xive, irq, &src);422422+ if (!sb)423423+ goto next;424424+ state = &sb->irq_state[src];425425+426426+ /* Has it been rerouted ? */427427+ if (xc->server_num == state->act_server)428428+ goto next;429429+430430+ /*431431+ * Allright, it *has* been re-routed, kill it from432432+ * the queue.433433+ */434434+ qpage[idx] = cpu_to_be32((entry & 0x80000000) | XICS_DUMMY);435435+436436+ /* Find the HW interrupt */437437+ kvmppc_xive_select_irq(state, &hw_num, &xd);438438+439439+ /* If it's not an LSI, set PQ to 11 the EOI will force a resend */440440+ if (!(xd->flags & XIVE_IRQ_FLAG_LSI))441441+ GLUE(X_PFX,esb_load)(xd, XIVE_ESB_SET_PQ_11);442442+443443+ /* EOI the source */444444+ GLUE(X_PFX,source_eoi)(hw_num, xd);445445+446446+ next:447447+ idx = (idx + 1) & q->msk;448448+ if (idx == 0)449449+ toggle ^= 1;450450+ }451451+ }452452+}453453+395454X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr)396455{397456 struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;457457+ struct kvmppc_xive *xive = vcpu->kvm->arch.xive;398458 u8 old_cppr;399459400460 pr_devel("H_CPPR(cppr=%ld)\n", cppr);···481407 */482408 smp_mb();483409484484- /*485485- * We are masking less, we need to look for pending things486486- * to deliver and set VP pending bits accordingly to trigger487487- * a new interrupt otherwise we might miss MFRR changes for488488- * which we have optimized out sending an IPI signal.489489- */490490- if (cppr > old_cppr)410410+ if (cppr > old_cppr) {411411+ /*412412+ * We are masking less, we need to look for pending things413413+ * to deliver and set VP pending bits accordingly to trigger414414+ * a new interrupt otherwise we might miss MFRR changes for415415+ * which we have optimized out sending an IPI signal.416416+ */491417 GLUE(X_PFX,push_pending_to_hw)(xc);418418+ } else {419419+ /*420420+ * We are masking more, we need to check the queue for any421421+ * interrupt that has been routed to another CPU, take422422+ * it out (replace it with the dummy) and retrigger it.423423+ *424424+ * This is necessary since those interrupts may otherwise425425+ * never be processed, at least not until this CPU restores426426+ * its CPPR.427427+ *428428+ * This is in theory racy vs. HW adding new interrupts to429429+ * the queue. In practice this works because the interesting430430+ * cases are when the guest has done a set_xive() to move the431431+ * interrupt away, which flushes the xive, followed by the432432+ * target CPU doing a H_CPPR. So any new interrupt coming into433433+ * the queue must still be routed to us and isn't a source434434+ * of concern.435435+ */436436+ GLUE(X_PFX,scan_for_rerouted_irqs)(xive, xc);437437+ }492438493439 /* Apply new CPPR */494440 xc->hw_cppr = cppr;
···710710 fwnmi_init();711711712712 pseries_setup_rfi_flush();713713+ setup_stf_barrier();713714714715 /* By default, only probe PCI (can be overridden by rtas_pci) */715716 pci_add_flags(PCI_PROBE_ONLY);
+1-1
arch/s390/kvm/vsie.c
···578578579579 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL;580580 if (gpa && (scb_s->ecb & ECB_TE)) {581581- if (!(gpa & ~0x1fffU)) {581581+ if (!(gpa & ~0x1fffUL)) {582582 rc = set_validity_icpt(scb_s, 0x0080U);583583 goto unpin;584584 }
···4242#define MSR_IA32_SPEC_CTRL 0x00000048 /* Speculation Control */4343#define SPEC_CTRL_IBRS (1 << 0) /* Indirect Branch Restricted Speculation */4444#define SPEC_CTRL_STIBP (1 << 1) /* Single Thread Indirect Branch Predictors */4545+#define SPEC_CTRL_SSBD_SHIFT 2 /* Speculative Store Bypass Disable bit */4646+#define SPEC_CTRL_SSBD (1 << SPEC_CTRL_SSBD_SHIFT) /* Speculative Store Bypass Disable */45474648#define MSR_IA32_PRED_CMD 0x00000049 /* Prediction Command */4749#define PRED_CMD_IBPB (1 << 0) /* Indirect Branch Prediction Barrier */···7068#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a7169#define ARCH_CAP_RDCL_NO (1 << 0) /* Not susceptible to Meltdown */7270#define ARCH_CAP_IBRS_ALL (1 << 1) /* Enhanced IBRS support */7171+#define ARCH_CAP_SSB_NO (1 << 4) /*7272+ * Not susceptible to Speculative Store Bypass7373+ * attack, so no Speculative Store Bypass7474+ * control required.7575+ */73767477#define MSR_IA32_BBL_CR_CTL 0x000001197578#define MSR_IA32_BBL_CR_CTL3 0x0000011e···346339#define MSR_AMD64_SEV 0xc0010131347340#define MSR_AMD64_SEV_ENABLED_BIT 0348341#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)342342+343343+#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f349344350345/* Fam 17h MSRs */351346#define MSR_F17H_IRPERF 0xc00000e9
+30-13
arch/x86/include/asm/nospec-branch.h
···217217 SPECTRE_V2_IBRS,218218};219219220220+/* The Speculative Store Bypass disable variants */221221+enum ssb_mitigation {222222+ SPEC_STORE_BYPASS_NONE,223223+ SPEC_STORE_BYPASS_DISABLE,224224+ SPEC_STORE_BYPASS_PRCTL,225225+ SPEC_STORE_BYPASS_SECCOMP,226226+};227227+220228extern char __indirect_thunk_start[];221229extern char __indirect_thunk_end[];222230···249241#endif250242}251243252252-#define alternative_msr_write(_msr, _val, _feature) \253253- asm volatile(ALTERNATIVE("", \254254- "movl %[msr], %%ecx\n\t" \255255- "movl %[val], %%eax\n\t" \256256- "movl $0, %%edx\n\t" \257257- "wrmsr", \258258- _feature) \259259- : : [msr] "i" (_msr), [val] "i" (_val) \260260- : "eax", "ecx", "edx", "memory")244244+static __always_inline245245+void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature)246246+{247247+ asm volatile(ALTERNATIVE("", "wrmsr", %c[feature])248248+ : : "c" (msr),249249+ "a" ((u32)val),250250+ "d" ((u32)(val >> 32)),251251+ [feature] "i" (feature)252252+ : "memory");253253+}261254262255static inline void indirect_branch_prediction_barrier(void)263256{264264- alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB,265265- X86_FEATURE_USE_IBPB);257257+ u64 val = PRED_CMD_IBPB;258258+259259+ alternative_msr_write(MSR_IA32_PRED_CMD, val, X86_FEATURE_USE_IBPB);266260}261261+262262+/* The Intel SPEC CTRL MSR base value cache */263263+extern u64 x86_spec_ctrl_base;267264268265/*269266 * With retpoline, we must use IBRS to restrict branch prediction···278265 */279266#define firmware_restrict_branch_speculation_start() \280267do { \268268+ u64 val = x86_spec_ctrl_base | SPEC_CTRL_IBRS; \269269+ \281270 preempt_disable(); \282282- alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS, \271271+ alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \283272 X86_FEATURE_USE_IBRS_FW); \284273} while (0)285274286275#define firmware_restrict_branch_speculation_end() \287276do { \288288- alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, \277277+ u64 val = x86_spec_ctrl_base; \278278+ \279279+ alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \289280 X86_FEATURE_USE_IBRS_FW); \290281 preempt_enable(); \291282} while (0)
+80
arch/x86/include/asm/spec-ctrl.h
···11+/* SPDX-License-Identifier: GPL-2.0 */22+#ifndef _ASM_X86_SPECCTRL_H_33+#define _ASM_X86_SPECCTRL_H_44+55+#include <linux/thread_info.h>66+#include <asm/nospec-branch.h>77+88+/*99+ * On VMENTER we must preserve whatever view of the SPEC_CTRL MSR1010+ * the guest has, while on VMEXIT we restore the host view. This1111+ * would be easier if SPEC_CTRL were architecturally maskable or1212+ * shadowable for guests but this is not (currently) the case.1313+ * Takes the guest view of SPEC_CTRL MSR as a parameter and also1414+ * the guest's version of VIRT_SPEC_CTRL, if emulated.1515+ */1616+extern void x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool guest);1717+1818+/**1919+ * x86_spec_ctrl_set_guest - Set speculation control registers for the guest2020+ * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL2121+ * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL2222+ * (may get translated to MSR_AMD64_LS_CFG bits)2323+ *2424+ * Avoids writing to the MSR if the content/bits are the same2525+ */2626+static inline2727+void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)2828+{2929+ x86_virt_spec_ctrl(guest_spec_ctrl, guest_virt_spec_ctrl, true);3030+}3131+3232+/**3333+ * x86_spec_ctrl_restore_host - Restore host speculation control registers3434+ * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL3535+ * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL3636+ * (may get translated to MSR_AMD64_LS_CFG bits)3737+ *3838+ * Avoids writing to the MSR if the content/bits are the same3939+ */4040+static inline4141+void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)4242+{4343+ x86_virt_spec_ctrl(guest_spec_ctrl, guest_virt_spec_ctrl, false);4444+}4545+4646+/* AMD specific Speculative Store Bypass MSR data */4747+extern u64 x86_amd_ls_cfg_base;4848+extern u64 x86_amd_ls_cfg_ssbd_mask;4949+5050+static inline u64 ssbd_tif_to_spec_ctrl(u64 tifn)5151+{5252+ BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);5353+ return (tifn & _TIF_SSBD) >> (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);5454+}5555+5656+static inline unsigned long ssbd_spec_ctrl_to_tif(u64 spec_ctrl)5757+{5858+ BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);5959+ return (spec_ctrl & SPEC_CTRL_SSBD) << (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);6060+}6161+6262+static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn)6363+{6464+ return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL;6565+}6666+6767+#ifdef CONFIG_SMP6868+extern void speculative_store_bypass_ht_init(void);6969+#else7070+static inline void speculative_store_bypass_ht_init(void) { }7171+#endif7272+7373+extern void speculative_store_bypass_update(unsigned long tif);7474+7575+static inline void speculative_store_bypass_update_current(void)7676+{7777+ speculative_store_bypass_update(current_thread_info()->flags);7878+}7979+8080+#endif
···1010#include <asm/processor.h>1111#include <asm/apic.h>1212#include <asm/cpu.h>1313+#include <asm/spec-ctrl.h>1314#include <asm/smp.h>1415#include <asm/pci-direct.h>1516#include <asm/delay.h>···555554 rdmsrl(MSR_FAM10H_NODE_ID, value);556555 nodes_per_socket = ((value >> 3) & 7) + 1;557556 }557557+558558+ if (c->x86 >= 0x15 && c->x86 <= 0x17) {559559+ unsigned int bit;560560+561561+ switch (c->x86) {562562+ case 0x15: bit = 54; break;563563+ case 0x16: bit = 33; break;564564+ case 0x17: bit = 10; break;565565+ default: return;566566+ }567567+ /*568568+ * Try to cache the base value so further operations can569569+ * avoid RMW. If that faults, do not enable SSBD.570570+ */571571+ if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &x86_amd_ls_cfg_base)) {572572+ setup_force_cpu_cap(X86_FEATURE_LS_CFG_SSBD);573573+ setup_force_cpu_cap(X86_FEATURE_SSBD);574574+ x86_amd_ls_cfg_ssbd_mask = 1ULL << bit;575575+ }576576+ }558577}559578560579static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)···812791813792static void init_amd_zn(struct cpuinfo_x86 *c)814793{794794+ set_cpu_cap(c, X86_FEATURE_ZEN);815795 /*816796 * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects817797 * all up to and including B1.
+383-16
arch/x86/kernel/cpu/bugs.c
···1212#include <linux/utsname.h>1313#include <linux/cpu.h>1414#include <linux/module.h>1515+#include <linux/nospec.h>1616+#include <linux/prctl.h>15171616-#include <asm/nospec-branch.h>1818+#include <asm/spec-ctrl.h>1719#include <asm/cmdline.h>1820#include <asm/bugs.h>1921#include <asm/processor.h>···2927#include <asm/intel-family.h>30283129static void __init spectre_v2_select_mitigation(void);3030+static void __init ssb_select_mitigation(void);3131+3232+/*3333+ * Our boot-time value of the SPEC_CTRL MSR. We read it once so that any3434+ * writes to SPEC_CTRL contain whatever reserved bits have been set.3535+ */3636+u64 __ro_after_init x86_spec_ctrl_base;3737+EXPORT_SYMBOL_GPL(x86_spec_ctrl_base);3838+3939+/*4040+ * The vendor and possibly platform specific bits which can be modified in4141+ * x86_spec_ctrl_base.4242+ */4343+static u64 __ro_after_init x86_spec_ctrl_mask = SPEC_CTRL_IBRS;4444+4545+/*4646+ * AMD specific MSR info for Speculative Store Bypass control.4747+ * x86_amd_ls_cfg_ssbd_mask is initialized in identify_boot_cpu().4848+ */4949+u64 __ro_after_init x86_amd_ls_cfg_base;5050+u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask;32513352void __init check_bugs(void)3453{···6037 print_cpu_info(&boot_cpu_data);6138 }62394040+ /*4141+ * Read the SPEC_CTRL MSR to account for reserved bits which may4242+ * have unknown values. AMD64_LS_CFG MSR is cached in the early AMD4343+ * init code as it is not enumerated and depends on the family.4444+ */4545+ if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))4646+ rdmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);4747+4848+ /* Allow STIBP in MSR_SPEC_CTRL if supported */4949+ if (boot_cpu_has(X86_FEATURE_STIBP))5050+ x86_spec_ctrl_mask |= SPEC_CTRL_STIBP;5151+6352 /* Select the proper spectre mitigation before patching alternatives */6453 spectre_v2_select_mitigation();5454+5555+ /*5656+ * Select proper mitigation for any exposure to the Speculative Store5757+ * Bypass vulnerability.5858+ */5959+ ssb_select_mitigation();65606661#ifdef CONFIG_X86_326762 /*···13493#undef pr_fmt13594#define pr_fmt(fmt) "Spectre V2 : " fmt13695137137-static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE;9696+static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =9797+ SPECTRE_V2_NONE;9898+9999+void100100+x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)101101+{102102+ u64 msrval, guestval, hostval = x86_spec_ctrl_base;103103+ struct thread_info *ti = current_thread_info();104104+105105+ /* Is MSR_SPEC_CTRL implemented ? */106106+ if (static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) {107107+ /*108108+ * Restrict guest_spec_ctrl to supported values. Clear the109109+ * modifiable bits in the host base value and or the110110+ * modifiable bits from the guest value.111111+ */112112+ guestval = hostval & ~x86_spec_ctrl_mask;113113+ guestval |= guest_spec_ctrl & x86_spec_ctrl_mask;114114+115115+ /* SSBD controlled in MSR_SPEC_CTRL */116116+ if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))117117+ hostval |= ssbd_tif_to_spec_ctrl(ti->flags);118118+119119+ if (hostval != guestval) {120120+ msrval = setguest ? guestval : hostval;121121+ wrmsrl(MSR_IA32_SPEC_CTRL, msrval);122122+ }123123+ }124124+125125+ /*126126+ * If SSBD is not handled in MSR_SPEC_CTRL on AMD, update127127+ * MSR_AMD64_L2_CFG or MSR_VIRT_SPEC_CTRL if supported.128128+ */129129+ if (!static_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&130130+ !static_cpu_has(X86_FEATURE_VIRT_SSBD))131131+ return;132132+133133+ /*134134+ * If the host has SSBD mitigation enabled, force it in the host's135135+ * virtual MSR value. If its not permanently enabled, evaluate136136+ * current's TIF_SSBD thread flag.137137+ */138138+ if (static_cpu_has(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE))139139+ hostval = SPEC_CTRL_SSBD;140140+ else141141+ hostval = ssbd_tif_to_spec_ctrl(ti->flags);142142+143143+ /* Sanitize the guest value */144144+ guestval = guest_virt_spec_ctrl & SPEC_CTRL_SSBD;145145+146146+ if (hostval != guestval) {147147+ unsigned long tif;148148+149149+ tif = setguest ? ssbd_spec_ctrl_to_tif(guestval) :150150+ ssbd_spec_ctrl_to_tif(hostval);151151+152152+ speculative_store_bypass_update(tif);153153+ }154154+}155155+EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl);156156+157157+static void x86_amd_ssb_disable(void)158158+{159159+ u64 msrval = x86_amd_ls_cfg_base | x86_amd_ls_cfg_ssbd_mask;160160+161161+ if (boot_cpu_has(X86_FEATURE_VIRT_SSBD))162162+ wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, SPEC_CTRL_SSBD);163163+ else if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))164164+ wrmsrl(MSR_AMD64_LS_CFG, msrval);165165+}138166139167#ifdef RETPOLINE140168static bool spectre_v2_bad_module;···422312}423313424314#undef pr_fmt315315+#define pr_fmt(fmt) "Speculative Store Bypass: " fmt316316+317317+static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;318318+319319+/* The kernel command line selection */320320+enum ssb_mitigation_cmd {321321+ SPEC_STORE_BYPASS_CMD_NONE,322322+ SPEC_STORE_BYPASS_CMD_AUTO,323323+ SPEC_STORE_BYPASS_CMD_ON,324324+ SPEC_STORE_BYPASS_CMD_PRCTL,325325+ SPEC_STORE_BYPASS_CMD_SECCOMP,326326+};327327+328328+static const char *ssb_strings[] = {329329+ [SPEC_STORE_BYPASS_NONE] = "Vulnerable",330330+ [SPEC_STORE_BYPASS_DISABLE] = "Mitigation: Speculative Store Bypass disabled",331331+ [SPEC_STORE_BYPASS_PRCTL] = "Mitigation: Speculative Store Bypass disabled via prctl",332332+ [SPEC_STORE_BYPASS_SECCOMP] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",333333+};334334+335335+static const struct {336336+ const char *option;337337+ enum ssb_mitigation_cmd cmd;338338+} ssb_mitigation_options[] = {339339+ { "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */340340+ { "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */341341+ { "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */342342+ { "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */343343+ { "seccomp", SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */344344+};345345+346346+static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)347347+{348348+ enum ssb_mitigation_cmd cmd = SPEC_STORE_BYPASS_CMD_AUTO;349349+ char arg[20];350350+ int ret, i;351351+352352+ if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable")) {353353+ return SPEC_STORE_BYPASS_CMD_NONE;354354+ } else {355355+ ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable",356356+ arg, sizeof(arg));357357+ if (ret < 0)358358+ return SPEC_STORE_BYPASS_CMD_AUTO;359359+360360+ for (i = 0; i < ARRAY_SIZE(ssb_mitigation_options); i++) {361361+ if (!match_option(arg, ret, ssb_mitigation_options[i].option))362362+ continue;363363+364364+ cmd = ssb_mitigation_options[i].cmd;365365+ break;366366+ }367367+368368+ if (i >= ARRAY_SIZE(ssb_mitigation_options)) {369369+ pr_err("unknown option (%s). Switching to AUTO select\n", arg);370370+ return SPEC_STORE_BYPASS_CMD_AUTO;371371+ }372372+ }373373+374374+ return cmd;375375+}376376+377377+static enum ssb_mitigation __init __ssb_select_mitigation(void)378378+{379379+ enum ssb_mitigation mode = SPEC_STORE_BYPASS_NONE;380380+ enum ssb_mitigation_cmd cmd;381381+382382+ if (!boot_cpu_has(X86_FEATURE_SSBD))383383+ return mode;384384+385385+ cmd = ssb_parse_cmdline();386386+ if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) &&387387+ (cmd == SPEC_STORE_BYPASS_CMD_NONE ||388388+ cmd == SPEC_STORE_BYPASS_CMD_AUTO))389389+ return mode;390390+391391+ switch (cmd) {392392+ case SPEC_STORE_BYPASS_CMD_AUTO:393393+ case SPEC_STORE_BYPASS_CMD_SECCOMP:394394+ /*395395+ * Choose prctl+seccomp as the default mode if seccomp is396396+ * enabled.397397+ */398398+ if (IS_ENABLED(CONFIG_SECCOMP))399399+ mode = SPEC_STORE_BYPASS_SECCOMP;400400+ else401401+ mode = SPEC_STORE_BYPASS_PRCTL;402402+ break;403403+ case SPEC_STORE_BYPASS_CMD_ON:404404+ mode = SPEC_STORE_BYPASS_DISABLE;405405+ break;406406+ case SPEC_STORE_BYPASS_CMD_PRCTL:407407+ mode = SPEC_STORE_BYPASS_PRCTL;408408+ break;409409+ case SPEC_STORE_BYPASS_CMD_NONE:410410+ break;411411+ }412412+413413+ /*414414+ * We have three CPU feature flags that are in play here:415415+ * - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible.416416+ * - X86_FEATURE_SSBD - CPU is able to turn off speculative store bypass417417+ * - X86_FEATURE_SPEC_STORE_BYPASS_DISABLE - engage the mitigation418418+ */419419+ if (mode == SPEC_STORE_BYPASS_DISABLE) {420420+ setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE);421421+ /*422422+ * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses423423+ * a completely different MSR and bit dependent on family.424424+ */425425+ switch (boot_cpu_data.x86_vendor) {426426+ case X86_VENDOR_INTEL:427427+ x86_spec_ctrl_base |= SPEC_CTRL_SSBD;428428+ x86_spec_ctrl_mask |= SPEC_CTRL_SSBD;429429+ wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);430430+ break;431431+ case X86_VENDOR_AMD:432432+ x86_amd_ssb_disable();433433+ break;434434+ }435435+ }436436+437437+ return mode;438438+}439439+440440+static void ssb_select_mitigation(void)441441+{442442+ ssb_mode = __ssb_select_mitigation();443443+444444+ if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))445445+ pr_info("%s\n", ssb_strings[ssb_mode]);446446+}447447+448448+#undef pr_fmt449449+#define pr_fmt(fmt) "Speculation prctl: " fmt450450+451451+static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)452452+{453453+ bool update;454454+455455+ if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&456456+ ssb_mode != SPEC_STORE_BYPASS_SECCOMP)457457+ return -ENXIO;458458+459459+ switch (ctrl) {460460+ case PR_SPEC_ENABLE:461461+ /* If speculation is force disabled, enable is not allowed */462462+ if (task_spec_ssb_force_disable(task))463463+ return -EPERM;464464+ task_clear_spec_ssb_disable(task);465465+ update = test_and_clear_tsk_thread_flag(task, TIF_SSBD);466466+ break;467467+ case PR_SPEC_DISABLE:468468+ task_set_spec_ssb_disable(task);469469+ update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);470470+ break;471471+ case PR_SPEC_FORCE_DISABLE:472472+ task_set_spec_ssb_disable(task);473473+ task_set_spec_ssb_force_disable(task);474474+ update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);475475+ break;476476+ default:477477+ return -ERANGE;478478+ }479479+480480+ /*481481+ * If being set on non-current task, delay setting the CPU482482+ * mitigation until it is next scheduled.483483+ */484484+ if (task == current && update)485485+ speculative_store_bypass_update_current();486486+487487+ return 0;488488+}489489+490490+int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,491491+ unsigned long ctrl)492492+{493493+ switch (which) {494494+ case PR_SPEC_STORE_BYPASS:495495+ return ssb_prctl_set(task, ctrl);496496+ default:497497+ return -ENODEV;498498+ }499499+}500500+501501+#ifdef CONFIG_SECCOMP502502+void arch_seccomp_spec_mitigate(struct task_struct *task)503503+{504504+ if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)505505+ ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);506506+}507507+#endif508508+509509+static int ssb_prctl_get(struct task_struct *task)510510+{511511+ switch (ssb_mode) {512512+ case SPEC_STORE_BYPASS_DISABLE:513513+ return PR_SPEC_DISABLE;514514+ case SPEC_STORE_BYPASS_SECCOMP:515515+ case SPEC_STORE_BYPASS_PRCTL:516516+ if (task_spec_ssb_force_disable(task))517517+ return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;518518+ if (task_spec_ssb_disable(task))519519+ return PR_SPEC_PRCTL | PR_SPEC_DISABLE;520520+ return PR_SPEC_PRCTL | PR_SPEC_ENABLE;521521+ default:522522+ if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))523523+ return PR_SPEC_ENABLE;524524+ return PR_SPEC_NOT_AFFECTED;525525+ }526526+}527527+528528+int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)529529+{530530+ switch (which) {531531+ case PR_SPEC_STORE_BYPASS:532532+ return ssb_prctl_get(task);533533+ default:534534+ return -ENODEV;535535+ }536536+}537537+538538+void x86_spec_ctrl_setup_ap(void)539539+{540540+ if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))541541+ wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);542542+543543+ if (ssb_mode == SPEC_STORE_BYPASS_DISABLE)544544+ x86_amd_ssb_disable();545545+}425546426547#ifdef CONFIG_SYSFS548548+549549+static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,550550+ char *buf, unsigned int bug)551551+{552552+ if (!boot_cpu_has_bug(bug))553553+ return sprintf(buf, "Not affected\n");554554+555555+ switch (bug) {556556+ case X86_BUG_CPU_MELTDOWN:557557+ if (boot_cpu_has(X86_FEATURE_PTI))558558+ return sprintf(buf, "Mitigation: PTI\n");559559+560560+ break;561561+562562+ case X86_BUG_SPECTRE_V1:563563+ return sprintf(buf, "Mitigation: __user pointer sanitization\n");564564+565565+ case X86_BUG_SPECTRE_V2:566566+ return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],567567+ boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",568568+ boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",569569+ spectre_v2_module_string());570570+571571+ case X86_BUG_SPEC_STORE_BYPASS:572572+ return sprintf(buf, "%s\n", ssb_strings[ssb_mode]);573573+574574+ default:575575+ break;576576+ }577577+578578+ return sprintf(buf, "Vulnerable\n");579579+}580580+427581ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)428582{429429- if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))430430- return sprintf(buf, "Not affected\n");431431- if (boot_cpu_has(X86_FEATURE_PTI))432432- return sprintf(buf, "Mitigation: PTI\n");433433- return sprintf(buf, "Vulnerable\n");583583+ return cpu_show_common(dev, attr, buf, X86_BUG_CPU_MELTDOWN);434584}435585436586ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)437587{438438- if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1))439439- return sprintf(buf, "Not affected\n");440440- return sprintf(buf, "Mitigation: __user pointer sanitization\n");588588+ return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V1);441589}442590443591ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)444592{445445- if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))446446- return sprintf(buf, "Not affected\n");593593+ return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V2);594594+}447595448448- return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],449449- boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",450450- boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",451451- spectre_v2_module_string());596596+ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *attr, char *buf)597597+{598598+ return cpu_show_common(dev, attr, buf, X86_BUG_SPEC_STORE_BYPASS);452599}453600#endif
+52-15
arch/x86/kernel/cpu/common.c
···757757 * and they also have a different bit for STIBP support. Also,758758 * a hypervisor might have set the individual AMD bits even on759759 * Intel CPUs, for finer-grained selection of what's available.760760- *761761- * We use the AMD bits in 0x8000_0008 EBX as the generic hardware762762- * features, which are visible in /proc/cpuinfo and used by the763763- * kernel. So set those accordingly from the Intel bits.764760 */765761 if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {766762 set_cpu_cap(c, X86_FEATURE_IBRS);767763 set_cpu_cap(c, X86_FEATURE_IBPB);764764+ set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);768765 }766766+769767 if (cpu_has(c, X86_FEATURE_INTEL_STIBP))770768 set_cpu_cap(c, X86_FEATURE_STIBP);769769+770770+ if (cpu_has(c, X86_FEATURE_SPEC_CTRL_SSBD) ||771771+ cpu_has(c, X86_FEATURE_VIRT_SSBD))772772+ set_cpu_cap(c, X86_FEATURE_SSBD);773773+774774+ if (cpu_has(c, X86_FEATURE_AMD_IBRS)) {775775+ set_cpu_cap(c, X86_FEATURE_IBRS);776776+ set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);777777+ }778778+779779+ if (cpu_has(c, X86_FEATURE_AMD_IBPB))780780+ set_cpu_cap(c, X86_FEATURE_IBPB);781781+782782+ if (cpu_has(c, X86_FEATURE_AMD_STIBP)) {783783+ set_cpu_cap(c, X86_FEATURE_STIBP);784784+ set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);785785+ }771786}772787773788void get_cpu_cap(struct cpuinfo_x86 *c)···942927 {}943928};944929945945-static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c)930930+/* Only list CPUs which speculate but are non susceptible to SSB */931931+static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {932932+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 },933933+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },934934+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT2 },935935+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_MERRIFIELD },936936+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_CORE_YONAH },937937+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL },938938+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM },939939+ { X86_VENDOR_AMD, 0x12, },940940+ { X86_VENDOR_AMD, 0x11, },941941+ { X86_VENDOR_AMD, 0x10, },942942+ { X86_VENDOR_AMD, 0xf, },943943+ {}944944+};945945+946946+static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)946947{947948 u64 ia32_cap = 0;948949949949- if (x86_match_cpu(cpu_no_meltdown))950950- return false;950950+ if (x86_match_cpu(cpu_no_speculation))951951+ return;952952+953953+ setup_force_cpu_bug(X86_BUG_SPECTRE_V1);954954+ setup_force_cpu_bug(X86_BUG_SPECTRE_V2);951955952956 if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))953957 rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);954958959959+ if (!x86_match_cpu(cpu_no_spec_store_bypass) &&960960+ !(ia32_cap & ARCH_CAP_SSB_NO))961961+ setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS);962962+963963+ if (x86_match_cpu(cpu_no_meltdown))964964+ return;965965+955966 /* Rogue Data Cache Load? No! */956967 if (ia32_cap & ARCH_CAP_RDCL_NO)957957- return false;968968+ return;958969959959- return true;970970+ setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);960971}961972962973/*···10339921034993 setup_force_cpu_cap(X86_FEATURE_ALWAYS);103599410361036- if (!x86_match_cpu(cpu_no_speculation)) {10371037- if (cpu_vulnerable_to_meltdown(c))10381038- setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);10391039- setup_force_cpu_bug(X86_BUG_SPECTRE_V1);10401040- setup_force_cpu_bug(X86_BUG_SPECTRE_V2);10411041- }995995+ cpu_set_bug_bits(c);10429961043997 fpu__init_system(c);1044998···13951359#endif13961360 mtrr_ap_init();13971361 validate_apic_and_package_id(c);13621362+ x86_spec_ctrl_setup_ap();13981363}1399136414001365static __init int setup_noclflush(char *arg)
+2
arch/x86/kernel/cpu/cpu.h
···50505151unsigned int aperfmperf_get_khz(int cpu);52525353+extern void x86_spec_ctrl_setup_ap(void);5454+5355#endif /* ARCH_X86_CPU_H */
···3838#include <asm/switch_to.h>3939#include <asm/desc.h>4040#include <asm/prctl.h>4141+#include <asm/spec-ctrl.h>41424243/*4344 * per-CPU TSS segments. Threads are completely 'soft' on Linux,···279278 }280279}281280281281+#ifdef CONFIG_SMP282282+283283+struct ssb_state {284284+ struct ssb_state *shared_state;285285+ raw_spinlock_t lock;286286+ unsigned int disable_state;287287+ unsigned long local_state;288288+};289289+290290+#define LSTATE_SSB 0291291+292292+static DEFINE_PER_CPU(struct ssb_state, ssb_state);293293+294294+void speculative_store_bypass_ht_init(void)295295+{296296+ struct ssb_state *st = this_cpu_ptr(&ssb_state);297297+ unsigned int this_cpu = smp_processor_id();298298+ unsigned int cpu;299299+300300+ st->local_state = 0;301301+302302+ /*303303+ * Shared state setup happens once on the first bringup304304+ * of the CPU. It's not destroyed on CPU hotunplug.305305+ */306306+ if (st->shared_state)307307+ return;308308+309309+ raw_spin_lock_init(&st->lock);310310+311311+ /*312312+ * Go over HT siblings and check whether one of them has set up the313313+ * shared state pointer already.314314+ */315315+ for_each_cpu(cpu, topology_sibling_cpumask(this_cpu)) {316316+ if (cpu == this_cpu)317317+ continue;318318+319319+ if (!per_cpu(ssb_state, cpu).shared_state)320320+ continue;321321+322322+ /* Link it to the state of the sibling: */323323+ st->shared_state = per_cpu(ssb_state, cpu).shared_state;324324+ return;325325+ }326326+327327+ /*328328+ * First HT sibling to come up on the core. Link shared state of329329+ * the first HT sibling to itself. The siblings on the same core330330+ * which come up later will see the shared state pointer and link331331+ * themself to the state of this CPU.332332+ */333333+ st->shared_state = st;334334+}335335+336336+/*337337+ * Logic is: First HT sibling enables SSBD for both siblings in the core338338+ * and last sibling to disable it, disables it for the whole core. This how339339+ * MSR_SPEC_CTRL works in "hardware":340340+ *341341+ * CORE_SPEC_CTRL = THREAD0_SPEC_CTRL | THREAD1_SPEC_CTRL342342+ */343343+static __always_inline void amd_set_core_ssb_state(unsigned long tifn)344344+{345345+ struct ssb_state *st = this_cpu_ptr(&ssb_state);346346+ u64 msr = x86_amd_ls_cfg_base;347347+348348+ if (!static_cpu_has(X86_FEATURE_ZEN)) {349349+ msr |= ssbd_tif_to_amd_ls_cfg(tifn);350350+ wrmsrl(MSR_AMD64_LS_CFG, msr);351351+ return;352352+ }353353+354354+ if (tifn & _TIF_SSBD) {355355+ /*356356+ * Since this can race with prctl(), block reentry on the357357+ * same CPU.358358+ */359359+ if (__test_and_set_bit(LSTATE_SSB, &st->local_state))360360+ return;361361+362362+ msr |= x86_amd_ls_cfg_ssbd_mask;363363+364364+ raw_spin_lock(&st->shared_state->lock);365365+ /* First sibling enables SSBD: */366366+ if (!st->shared_state->disable_state)367367+ wrmsrl(MSR_AMD64_LS_CFG, msr);368368+ st->shared_state->disable_state++;369369+ raw_spin_unlock(&st->shared_state->lock);370370+ } else {371371+ if (!__test_and_clear_bit(LSTATE_SSB, &st->local_state))372372+ return;373373+374374+ raw_spin_lock(&st->shared_state->lock);375375+ st->shared_state->disable_state--;376376+ if (!st->shared_state->disable_state)377377+ wrmsrl(MSR_AMD64_LS_CFG, msr);378378+ raw_spin_unlock(&st->shared_state->lock);379379+ }380380+}381381+#else382382+static __always_inline void amd_set_core_ssb_state(unsigned long tifn)383383+{384384+ u64 msr = x86_amd_ls_cfg_base | ssbd_tif_to_amd_ls_cfg(tifn);385385+386386+ wrmsrl(MSR_AMD64_LS_CFG, msr);387387+}388388+#endif389389+390390+static __always_inline void amd_set_ssb_virt_state(unsigned long tifn)391391+{392392+ /*393393+ * SSBD has the same definition in SPEC_CTRL and VIRT_SPEC_CTRL,394394+ * so ssbd_tif_to_spec_ctrl() just works.395395+ */396396+ wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, ssbd_tif_to_spec_ctrl(tifn));397397+}398398+399399+static __always_inline void intel_set_ssb_state(unsigned long tifn)400400+{401401+ u64 msr = x86_spec_ctrl_base | ssbd_tif_to_spec_ctrl(tifn);402402+403403+ wrmsrl(MSR_IA32_SPEC_CTRL, msr);404404+}405405+406406+static __always_inline void __speculative_store_bypass_update(unsigned long tifn)407407+{408408+ if (static_cpu_has(X86_FEATURE_VIRT_SSBD))409409+ amd_set_ssb_virt_state(tifn);410410+ else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD))411411+ amd_set_core_ssb_state(tifn);412412+ else413413+ intel_set_ssb_state(tifn);414414+}415415+416416+void speculative_store_bypass_update(unsigned long tif)417417+{418418+ preempt_disable();419419+ __speculative_store_bypass_update(tif);420420+ preempt_enable();421421+}422422+282423void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,283424 struct tss_struct *tss)284425{···452309453310 if ((tifp ^ tifn) & _TIF_NOCPUID)454311 set_cpuid_faulting(!!(tifn & _TIF_NOCPUID));312312+313313+ if ((tifp ^ tifn) & _TIF_SSBD)314314+ __speculative_store_bypass_update(tifn);455315}456316457317/*
+5
arch/x86/kernel/smpboot.c
···7979#include <asm/qspinlock.h>8080#include <asm/intel-family.h>8181#include <asm/cpu_device_id.h>8282+#include <asm/spec-ctrl.h>82838384/* Number of siblings per CPU package */8485int smp_num_siblings = 1;···244243 * Check TSC synchronization with the boot CPU:245244 */246245 check_tsc_sync_target();246246+247247+ speculative_store_bypass_ht_init();247248248249 /*249250 * Lock vector_lock, set CPU online and bring the vector···12951292 set_mtrr_aps_delayed_init();1296129312971294 smp_quirk_init_udelay();12951295+12961296+ speculative_store_bypass_ht_init();12981297}1299129813001299void arch_enable_nonboot_cpus_begin(void)
+19-7
arch/x86/kvm/cpuid.c
···379379380380 /* cpuid 0x80000008.ebx */381381 const u32 kvm_cpuid_8000_0008_ebx_x86_features =382382- F(IBPB) | F(IBRS);382382+ F(AMD_IBPB) | F(AMD_IBRS) | F(VIRT_SSBD);383383384384 /* cpuid 0xC0000001.edx */385385 const u32 kvm_cpuid_C000_0001_edx_x86_features =···408408 /* cpuid 7.0.edx*/409409 const u32 kvm_cpuid_7_0_edx_x86_features =410410 F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |411411- F(ARCH_CAPABILITIES);411411+ F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);412412413413 /* all calls to cpuid_count() should be made on the same cpu */414414 get_cpu();···495495 entry->ecx &= ~F(PKU);496496 entry->edx &= kvm_cpuid_7_0_edx_x86_features;497497 cpuid_mask(&entry->edx, CPUID_7_EDX);498498+ /*499499+ * We emulate ARCH_CAPABILITIES in software even500500+ * if the host doesn't support it.501501+ */502502+ entry->edx |= F(ARCH_CAPABILITIES);498503 } else {499504 entry->ebx = 0;500505 entry->ecx = 0;···652647 g_phys_as = phys_as;653648 entry->eax = g_phys_as | (virt_as << 8);654649 entry->edx = 0;655655- /* IBRS and IBPB aren't necessarily present in hardware cpuid */656656- if (boot_cpu_has(X86_FEATURE_IBPB))657657- entry->ebx |= F(IBPB);658658- if (boot_cpu_has(X86_FEATURE_IBRS))659659- entry->ebx |= F(IBRS);650650+ /*651651+ * IBRS, IBPB and VIRT_SSBD aren't necessarily present in652652+ * hardware cpuid653653+ */654654+ if (boot_cpu_has(X86_FEATURE_AMD_IBPB))655655+ entry->ebx |= F(AMD_IBPB);656656+ if (boot_cpu_has(X86_FEATURE_AMD_IBRS))657657+ entry->ebx |= F(AMD_IBRS);658658+ if (boot_cpu_has(X86_FEATURE_VIRT_SSBD))659659+ entry->ebx |= F(VIRT_SSBD);660660 entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;661661 cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX);662662+ if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))663663+ entry->ebx |= F(VIRT_SSBD);662664 break;663665 }664666 case 0x80000019:
···1522152215231523static void advance_periodic_target_expiration(struct kvm_lapic *apic)15241524{15251525- apic->lapic_timer.tscdeadline +=15261526- nsec_to_cycles(apic->vcpu, apic->lapic_timer.period);15251525+ ktime_t now = ktime_get();15261526+ u64 tscl = rdtsc();15271527+ ktime_t delta;15281528+15291529+ /*15301530+ * Synchronize both deadlines to the same time source or15311531+ * differences in the periods (caused by differences in the15321532+ * underlying clocks or numerical approximation errors) will15331533+ * cause the two to drift apart over time as the errors15341534+ * accumulate.15351535+ */15271536 apic->lapic_timer.target_expiration =15281537 ktime_add_ns(apic->lapic_timer.target_expiration,15291538 apic->lapic_timer.period);15391539+ delta = ktime_sub(apic->lapic_timer.target_expiration, now);15401540+ apic->lapic_timer.tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +15411541+ nsec_to_cycles(apic->vcpu, delta);15301542}1531154315321544static void start_sw_period(struct kvm_lapic *apic)
+44-22
arch/x86/kvm/svm.c
···4949#include <asm/debugreg.h>5050#include <asm/kvm_para.h>5151#include <asm/irq_remapping.h>5252-#include <asm/nospec-branch.h>5252+#include <asm/spec-ctrl.h>53535454#include <asm/virtext.h>5555#include "trace.h"···213213 } host;214214215215 u64 spec_ctrl;216216+ /*217217+ * Contains guest-controlled bits of VIRT_SPEC_CTRL, which will be218218+ * translated into the appropriate L2_CFG bits on the host to219219+ * perform speculative control.220220+ */221221+ u64 virt_spec_ctrl;216222217223 u32 *msrpm;218224···2066206020672061 vcpu->arch.microcode_version = 0x01000065;20682062 svm->spec_ctrl = 0;20632063+ svm->virt_spec_ctrl = 0;2069206420702065 if (!init_event) {20712066 svm->vcpu.arch.apic_base = APIC_DEFAULT_PHYS_BASE |···41154108 break;41164109 case MSR_IA32_SPEC_CTRL:41174110 if (!msr_info->host_initiated &&41184118- !guest_cpuid_has(vcpu, X86_FEATURE_IBRS))41114111+ !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS))41194112 return 1;4120411341214114 msr_info->data = svm->spec_ctrl;41154115+ break;41164116+ case MSR_AMD64_VIRT_SPEC_CTRL:41174117+ if (!msr_info->host_initiated &&41184118+ !guest_cpuid_has(vcpu, X86_FEATURE_VIRT_SSBD))41194119+ return 1;41204120+41214121+ msr_info->data = svm->virt_spec_ctrl;41224122 break;41234123 case MSR_F15H_IC_CFG: {41244124···42174203 break;42184204 case MSR_IA32_SPEC_CTRL:42194205 if (!msr->host_initiated &&42204220- !guest_cpuid_has(vcpu, X86_FEATURE_IBRS))42064206+ !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS))42214207 return 1;4222420842234209 /* The STIBP bit doesn't fault even if it's not advertised */···42444230 break;42454231 case MSR_IA32_PRED_CMD:42464232 if (!msr->host_initiated &&42474247- !guest_cpuid_has(vcpu, X86_FEATURE_IBPB))42334233+ !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBPB))42484234 return 1;4249423542504236 if (data & ~PRED_CMD_IBPB)···42574243 if (is_guest_mode(vcpu))42584244 break;42594245 set_msr_interception(svm->msrpm, MSR_IA32_PRED_CMD, 0, 1);42464246+ break;42474247+ case MSR_AMD64_VIRT_SPEC_CTRL:42484248+ if (!msr->host_initiated &&42494249+ !guest_cpuid_has(vcpu, X86_FEATURE_VIRT_SSBD))42504250+ return 1;42514251+42524252+ if (data & ~SPEC_CTRL_SSBD)42534253+ return 1;42544254+42554255+ svm->virt_spec_ctrl = data;42604256 break;42614257 case MSR_STAR:42624258 svm->vmcb->save.star = data;···55815557 * is no need to worry about the conditional branch over the wrmsr55825558 * being speculatively taken.55835559 */55845584- if (svm->spec_ctrl)55855585- native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);55605560+ x86_spec_ctrl_set_guest(svm->spec_ctrl, svm->virt_spec_ctrl);5586556155875562 asm volatile (55885563 "push %%" _ASM_BP "; \n\t"···56755652#endif56765653 );5677565456555655+ /* Eliminate branch target predictions from guest mode */56565656+ vmexit_fill_RSB();56575657+56585658+#ifdef CONFIG_X86_6456595659+ wrmsrl(MSR_GS_BASE, svm->host.gs_base);56605660+#else56615661+ loadsegment(fs, svm->host.fs);56625662+#ifndef CONFIG_X86_32_LAZY_GS56635663+ loadsegment(gs, svm->host.gs);56645664+#endif56655665+#endif56665666+56785667 /*56795668 * We do not use IBRS in the kernel. If this vCPU has used the56805669 * SPEC_CTRL MSR it may have left it on; save the value and···57055670 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))57065671 svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);5707567257085708- if (svm->spec_ctrl)57095709- native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);57105710-57115711- /* Eliminate branch target predictions from guest mode */57125712- vmexit_fill_RSB();57135713-57145714-#ifdef CONFIG_X86_6457155715- wrmsrl(MSR_GS_BASE, svm->host.gs_base);57165716-#else57175717- loadsegment(fs, svm->host.fs);57185718-#ifndef CONFIG_X86_32_LAZY_GS57195719- loadsegment(gs, svm->host.gs);57205720-#endif57215721-#endif56735673+ x86_spec_ctrl_restore_host(svm->spec_ctrl, svm->virt_spec_ctrl);5722567457235675 reload_tss(vcpu);57245676···58085786 return false;58095787}5810578858115811-static bool svm_has_high_real_mode_segbase(void)57895789+static bool svm_has_emulated_msr(int index)58125790{58135791 return true;58145792}···70347012 .hardware_enable = svm_hardware_enable,70357013 .hardware_disable = svm_hardware_disable,70367014 .cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr,70377037- .cpu_has_high_real_mode_segbase = svm_has_high_real_mode_segbase,70157015+ .has_emulated_msr = svm_has_emulated_msr,7038701670397017 .vcpu_create = svm_create_vcpu,70407018 .vcpu_free = svm_free_vcpu,
+19-12
arch/x86/kvm/vmx.c
···5151#include <asm/apic.h>5252#include <asm/irq_remapping.h>5353#include <asm/mmu_context.h>5454-#include <asm/nospec-branch.h>5454+#include <asm/spec-ctrl.h>5555#include <asm/mshyperv.h>56565757#include "trace.h"···35293529 return kvm_get_msr_common(vcpu, msr_info);35303530 case MSR_IA32_SPEC_CTRL:35313531 if (!msr_info->host_initiated &&35323532- !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) &&35333532 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))35343533 return 1;35353534···36473648 break;36483649 case MSR_IA32_SPEC_CTRL:36493650 if (!msr_info->host_initiated &&36503650- !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) &&36513651 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))36523652 return 1;3653365336543654 /* The STIBP bit doesn't fault even if it's not advertised */36553655- if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP))36553655+ if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP | SPEC_CTRL_SSBD))36563656 return 1;3657365736583658 vmx->spec_ctrl = data;···36773679 break;36783680 case MSR_IA32_PRED_CMD:36793681 if (!msr_info->host_initiated &&36803680- !guest_cpuid_has(vcpu, X86_FEATURE_IBPB) &&36813682 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))36823683 return 1;36833684···94859488}94869489STACK_FRAME_NON_STANDARD(vmx_handle_external_intr);9487949094889488-static bool vmx_has_high_real_mode_segbase(void)94919491+static bool vmx_has_emulated_msr(int index)94899492{94909490- return enable_unrestricted_guest || emulate_invalid_guest_state;94939493+ switch (index) {94949494+ case MSR_IA32_SMBASE:94959495+ /*94969496+ * We cannot do SMM unless we can run the guest in big94979497+ * real mode.94989498+ */94999499+ return enable_unrestricted_guest || emulate_invalid_guest_state;95009500+ case MSR_AMD64_VIRT_SPEC_CTRL:95019501+ /* This is AMD only. */95029502+ return false;95039503+ default:95049504+ return true;95059505+ }94919506}9492950794939508static bool vmx_mpx_supported(void)···97319722 * is no need to worry about the conditional branch over the wrmsr97329723 * being speculatively taken.97339724 */97349734- if (vmx->spec_ctrl)97359735- native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);97259725+ x86_spec_ctrl_set_guest(vmx->spec_ctrl, 0);9736972697379727 vmx->__launched = vmx->loaded_vmcs->launched;97389728···98799871 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))98809872 vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);9881987398829882- if (vmx->spec_ctrl)98839883- native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);98749874+ x86_spec_ctrl_restore_host(vmx->spec_ctrl, 0);9884987598859876 /* Eliminate branch target predictions from guest mode */98869877 vmexit_fill_RSB();···1263912632 .hardware_enable = hardware_enable,1264012633 .hardware_disable = hardware_disable,1264112634 .cpu_has_accelerated_tpr = report_flexpriority,1264212642- .cpu_has_high_real_mode_segbase = vmx_has_high_real_mode_segbase,1263512635+ .has_emulated_msr = vmx_has_emulated_msr,12643126361264412637 .vm_init = vmx_vm_init,1264512638 .vm_alloc = vmx_vm_alloc,
+12-18
arch/x86/kvm/x86.c
···10611061 MSR_SMI_COUNT,10621062 MSR_PLATFORM_INFO,10631063 MSR_MISC_FEATURES_ENABLES,10641064+ MSR_AMD64_VIRT_SPEC_CTRL,10641065};1065106610661067static unsigned num_emulated_msrs;···29072906 * fringe case that is not enabled except via specific settings29082907 * of the module parameters.29092908 */29102910- r = kvm_x86_ops->cpu_has_high_real_mode_segbase();29092909+ r = kvm_x86_ops->has_emulated_msr(MSR_IA32_SMBASE);29112910 break;29122911 case KVM_CAP_VAPIC:29132912 r = !kvm_x86_ops->cpu_has_accelerated_tpr();···46074606 num_msrs_to_save = j;4608460746094608 for (i = j = 0; i < ARRAY_SIZE(emulated_msrs); i++) {46104610- switch (emulated_msrs[i]) {46114611- case MSR_IA32_SMBASE:46124612- if (!kvm_x86_ops->cpu_has_high_real_mode_segbase())46134613- continue;46144614- break;46154615- default:46164616- break;46174617- }46094609+ if (!kvm_x86_ops->has_emulated_msr(emulated_msrs[i]))46104610+ continue;4618461146194612 if (j < i)46204613 emulated_msrs[j] = emulated_msrs[i];···66716676 unsigned long nr, a0, a1, a2, a3, ret;66726677 int op_64_bit;6673667866746674- if (kvm_hv_hypercall_enabled(vcpu->kvm)) {66756675- if (!kvm_hv_hypercall(vcpu))66766676- return 0;66776677- goto out;66786678- }66796679+ if (kvm_hv_hypercall_enabled(vcpu->kvm))66806680+ return kvm_hv_hypercall(vcpu);6679668166806682 nr = kvm_register_read(vcpu, VCPU_REGS_RAX);66816683 a0 = kvm_register_read(vcpu, VCPU_REGS_RBX);···6693670166946702 if (kvm_x86_ops->get_cpl(vcpu) != 0) {66956703 ret = -KVM_EPERM;66966696- goto out_error;67046704+ goto out;66976705 }6698670666996707 switch (nr) {···67136721 ret = -KVM_ENOSYS;67146722 break;67156723 }67166716-out_error:67246724+out:67176725 if (!op_64_bit)67186726 ret = (u32)ret;67196727 kvm_register_write(vcpu, VCPU_REGS_RAX, ret);6720672867216721-out:67226729 ++vcpu->stat.hypercalls;67236730 return kvm_skip_emulated_instruction(vcpu);67246731}···79767985{79777986 struct msr_data apic_base_msr;79787987 int mmu_reset_needed = 0;79887988+ int cpuid_update_needed = 0;79797989 int pending_vec, max_bits, idx;79807990 struct desc_ptr dt;79817991 int ret = -EINVAL;···80158023 vcpu->arch.cr0 = sregs->cr0;8016802480178025 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;80268026+ cpuid_update_needed |= ((kvm_read_cr4(vcpu) ^ sregs->cr4) &80278027+ (X86_CR4_OSXSAVE | X86_CR4_PKE));80188028 kvm_x86_ops->set_cr4(vcpu, sregs->cr4);80198019- if (sregs->cr4 & (X86_CR4_OSXSAVE | X86_CR4_PKE))80298029+ if (cpuid_update_needed)80208030 kvm_update_cpuid(vcpu);8021803180228032 idx = srcu_read_lock(&vcpu->kvm->srcu);
···44934493 /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */44944494 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, },4495449544964496+ /* Some Sandisk SSDs lock up hard with NCQ enabled. Reported on44974497+ SD7SN6S256G and SD8SN8U256G */44984498+ { "SanDisk SD[78]SN*G", NULL, ATA_HORKAGE_NONCQ, },44994499+44964500 /* devices which puke on READ_NATIVE_MAX */44974501 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, },44984502 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },···45534549 ATA_HORKAGE_ZERO_AFTER_TRIM |45544550 ATA_HORKAGE_NOLPM, },4555455145564556- /* This specific Samsung model/firmware-rev does not handle LPM well */45524552+ /* These specific Samsung models/firmware-revs do not handle LPM well */45574553 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM, },45544554+ { "SAMSUNG SSD PM830 mSATA *", "CXM13D1Q", ATA_HORKAGE_NOLPM, },4558455545594556 /* Sandisk devices which are known to not handle LPM well */45604557 { "SanDisk SD7UB3Q*G1001", NULL, ATA_HORKAGE_NOLPM, },4561455845624559 /* devices that don't properly handle queued TRIM commands */45604560+ { "Micron_M500IT_*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM |45614561+ ATA_HORKAGE_ZERO_AFTER_TRIM, },45634562 { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |45644563 ATA_HORKAGE_ZERO_AFTER_TRIM, },45654564 { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
+2-2
drivers/atm/zatm.c
···11511151}115211521153115311541154-static unsigned char eprom_try_esi(struct atm_dev *dev, unsigned short cmd,11551155- int offset, int swap)11541154+static int eprom_try_esi(struct atm_dev *dev, unsigned short cmd, int offset,11551155+ int swap)11561156{11571157 unsigned char buf[ZEPROM_SIZE];11581158 struct zatm_dev *zatm_dev;
···45554555 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {45564556 struct amdgpu_crtc *acrtc = NULL;45574557 struct amdgpu_dm_connector *aconnector = NULL;45584558- struct drm_connector_state *new_con_state = NULL;45594559- struct dm_connector_state *dm_conn_state = NULL;45584558+ struct drm_connector_state *drm_new_conn_state = NULL, *drm_old_conn_state = NULL;45594559+ struct dm_connector_state *dm_new_conn_state = NULL, *dm_old_conn_state = NULL;45604560 struct drm_plane_state *new_plane_state = NULL;4561456145624562 new_stream = NULL;···45774577 /* TODO This hack should go away */45784578 if (aconnector && enable) {45794579 // Make sure fake sink is created in plug-in scenario45804580- new_con_state = drm_atomic_get_connector_state(state,45804580+ drm_new_conn_state = drm_atomic_get_new_connector_state(state,45814581 &aconnector->base);45824582+ drm_old_conn_state = drm_atomic_get_old_connector_state(state,45834583+ &aconnector->base);4582458445834583- if (IS_ERR(new_con_state)) {45844584- ret = PTR_ERR_OR_ZERO(new_con_state);45854585+45864586+ if (IS_ERR(drm_new_conn_state)) {45874587+ ret = PTR_ERR_OR_ZERO(drm_new_conn_state);45854588 break;45864589 }4587459045884588- dm_conn_state = to_dm_connector_state(new_con_state);45914591+ dm_new_conn_state = to_dm_connector_state(drm_new_conn_state);45924592+ dm_old_conn_state = to_dm_connector_state(drm_old_conn_state);4589459345904594 new_stream = create_stream_for_sink(aconnector,45914595 &new_crtc_state->mode,45924592- dm_conn_state);45964596+ dm_new_conn_state);4593459745944598 /*45954599 * we can have no stream on ACTION_SET if a display···46994695 * We want to do dc stream updates that do not require a47004696 * full modeset below.47014697 */47024702- if (!enable || !aconnector || modereset_required(new_crtc_state))46984698+ if (!(enable && aconnector && new_crtc_state->enable &&46994699+ new_crtc_state->active))47034700 continue;47044701 /*47054702 * Given above conditions, the dc state cannot be NULL because:47064706- * 1. We're attempting to enable a CRTC. Which has a...47074707- * 2. Valid connector attached, and47084708- * 3. User does not want to reset it (disable or mark inactive,47094709- * which can happen on a CRTC that's already disabled).47104710- * => It currently exists.47034703+ * 1. We're in the process of enabling CRTCs (just been added47044704+ * to the dc context, or already is on the context)47054705+ * 2. Has a valid connector attached, and47064706+ * 3. Is currently active and enabled.47074707+ * => The dc stream state currently exists.47114708 */47124709 BUG_ON(dm_new_crtc_state->stream == NULL);4713471047144714- /* Color managment settings */47154715- if (dm_new_crtc_state->base.color_mgmt_changed) {47114711+ /* Scaling or underscan settings */47124712+ if (is_scaling_state_different(dm_old_conn_state, dm_new_conn_state))47134713+ update_stream_scaling_settings(47144714+ &new_crtc_state->mode, dm_new_conn_state, dm_new_crtc_state->stream);47154715+47164716+ /*47174717+ * Color management settings. We also update color properties47184718+ * when a modeset is needed, to ensure it gets reprogrammed.47194719+ */47204720+ if (dm_new_crtc_state->base.color_mgmt_changed ||47214721+ drm_atomic_crtc_needs_modeset(new_crtc_state)) {47164722 ret = amdgpu_dm_set_regamma_lut(dm_new_crtc_state);47174723 if (ret)47184724 goto fail;
···8282 struct dispc_clock_info *dispc_cinfo)8383{8484 int i;8585- struct sdi_clk_calc_ctx ctx = { .sdi = sdi };8585+ struct sdi_clk_calc_ctx ctx;86868787 /*8888 * DSS fclk gives us very few possibilities, so finding a good pixel···9595 bool ok;96969797 memset(&ctx, 0, sizeof(ctx));9898+9999+ ctx.sdi = sdi;100100+98101 if (pclk > 1000 * i * i * i)99102 ctx.pck_min = max(pclk - 1000 * i * i * i, 0lu);100103 else
···866866 spin_lock_irqsave(&par->dirty.lock, flags);867867 par->dirty.active = true;868868 spin_unlock_irqrestore(&par->dirty.lock, flags);869869-869869+870870+ /*871871+ * Need to reschedule a dirty update, because otherwise that's872872+ * only done in dirty_mark() if the previous coalesced873873+ * dirty region was empty.874874+ */875875+ schedule_delayed_work(&par->local_work, 0);876876+870877 return 0;871871-}872872-873873-/**874874- * vmw_fb_refresh - Refresh fb display875875- *876876- * @vmw_priv: Pointer to device private877877- *878878- * Call into kms to show the fbdev display(s).879879- */880880-void vmw_fb_refresh(struct vmw_private *vmw_priv)881881-{882882- if (!vmw_priv->fb_info)883883- return;884884-885885- vmw_fb_set_par(vmw_priv->fb_info);886878}
+31-17
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
···329329 struct rpc_channel channel;330330 char *msg, *reply = NULL;331331 size_t reply_len = 0;332332- int ret = 0;333333-334332335333 if (!vmw_msg_enabled)336334 return -ENODEV;···342344 return -ENOMEM;343345 }344346345345- if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||346346- vmw_send_msg(&channel, msg) ||347347- vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||348348- vmw_close_channel(&channel)) {349349- DRM_ERROR("Failed to get %s", guest_info_param);347347+ if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))348348+ goto out_open;350349351351- ret = -EINVAL;352352- }350350+ if (vmw_send_msg(&channel, msg) ||351351+ vmw_recv_msg(&channel, (void *) &reply, &reply_len))352352+ goto out_msg;353353354354+ vmw_close_channel(&channel);354355 if (buffer && reply && reply_len > 0) {355356 /* Remove reply code, which are the first 2 characters of356357 * the reply···366369 kfree(reply);367370 kfree(msg);368371369369- return ret;372372+ return 0;373373+374374+out_msg:375375+ vmw_close_channel(&channel);376376+ kfree(reply);377377+out_open:378378+ *length = 0;379379+ kfree(msg);380380+ DRM_ERROR("Failed to get %s", guest_info_param);381381+382382+ return -EINVAL;370383}371384372385···407400 return -ENOMEM;408401 }409402410410- if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||411411- vmw_send_msg(&channel, msg) ||412412- vmw_close_channel(&channel)) {413413- DRM_ERROR("Failed to send log\n");403403+ if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))404404+ goto out_open;414405415415- ret = -EINVAL;416416- }406406+ if (vmw_send_msg(&channel, msg))407407+ goto out_msg;417408409409+ vmw_close_channel(&channel);418410 kfree(msg);419411420420- return ret;412412+ return 0;413413+414414+out_msg:415415+ vmw_close_channel(&channel);416416+out_open:417417+ kfree(msg);418418+ DRM_ERROR("Failed to send log\n");419419+420420+ return -EINVAL;421421}
+17-8
drivers/gpu/drm/vmwgfx/vmwgfx_msg.h
···135135136136#else137137138138-/* In the 32-bit version of this macro, we use "m" because there is no139139- * more register left for bp138138+/*139139+ * In the 32-bit version of this macro, we store bp in a memory location140140+ * because we've ran out of registers.141141+ * Now we can't reference that memory location while we've modified142142+ * %esp or %ebp, so we first push it on the stack, just before we push143143+ * %ebp, and then when we need it we read it from the stack where we144144+ * just pushed it.140145 */141146#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \142147 port_num, magic, bp, \143148 eax, ebx, ecx, edx, si, di) \144149({ \145145- asm volatile ("push %%ebp;" \146146- "mov %12, %%ebp;" \150150+ asm volatile ("push %12;" \151151+ "push %%ebp;" \152152+ "mov 0x04(%%esp), %%ebp;" \147153 "rep outsb;" \148148- "pop %%ebp;" : \154154+ "pop %%ebp;" \155155+ "add $0x04, %%esp;" : \149156 "=a"(eax), \150157 "=b"(ebx), \151158 "=c"(ecx), \···174167 port_num, magic, bp, \175168 eax, ebx, ecx, edx, si, di) \176169({ \177177- asm volatile ("push %%ebp;" \178178- "mov %12, %%ebp;" \170170+ asm volatile ("push %12;" \171171+ "push %%ebp;" \172172+ "mov 0x04(%%esp), %%ebp;" \179173 "rep insb;" \180180- "pop %%ebp" : \174174+ "pop %%ebp;" \175175+ "add $0x04, %%esp;" : \181176 "=a"(eax), \182177 "=b"(ebx), \183178 "=c"(ecx), \
+3-3
drivers/hwtracing/intel_th/msu.c
···733733 /* Reset the page to write-back before releasing */734734 set_memory_wb((unsigned long)win->block[i].bdesc, 1);735735#endif736736- dma_free_coherent(msc_dev(msc), size, win->block[i].bdesc,737737- win->block[i].addr);736736+ dma_free_coherent(msc_dev(msc)->parent->parent, size,737737+ win->block[i].bdesc, win->block[i].addr);738738 }739739 kfree(win);740740···769769 /* Reset the page to write-back before releasing */770770 set_memory_wb((unsigned long)win->block[i].bdesc, 1);771771#endif772772- dma_free_coherent(msc_dev(win->msc), PAGE_SIZE,772772+ dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE,773773 win->block[i].bdesc, win->block[i].addr);774774 }775775
···11/*22 * i2c-ocores.c: I2C bus driver for OpenCores I2C controller33- * (http://www.opencores.org/projects.cgi/web/i2c/overview).33+ * (https://opencores.org/project/i2c/overview)44 *55 * Peter Korsgaard <jacmet@sunsite.dk>66 *
+1
drivers/iio/adc/Kconfig
···158158 depends on ARCH_AT91 || COMPILE_TEST159159 depends on HAS_IOMEM160160 depends on HAS_DMA161161+ select IIO_BUFFER161162 select IIO_TRIGGERED_BUFFER162163 help163164 Say yes here to build support for Atmel SAMA5D2 ADC which is
+24-51
drivers/iio/adc/ad7793.c
···348348static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,349349 33, 0, 17, 16, 12, 10, 8, 6, 4};350350351351-static ssize_t ad7793_read_frequency(struct device *dev,352352- struct device_attribute *attr,353353- char *buf)354354-{355355- struct iio_dev *indio_dev = dev_to_iio_dev(dev);356356- struct ad7793_state *st = iio_priv(indio_dev);357357-358358- return sprintf(buf, "%d\n",359359- st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);360360-}361361-362362-static ssize_t ad7793_write_frequency(struct device *dev,363363- struct device_attribute *attr,364364- const char *buf,365365- size_t len)366366-{367367- struct iio_dev *indio_dev = dev_to_iio_dev(dev);368368- struct ad7793_state *st = iio_priv(indio_dev);369369- long lval;370370- int i, ret;371371-372372- ret = kstrtol(buf, 10, &lval);373373- if (ret)374374- return ret;375375-376376- if (lval == 0)377377- return -EINVAL;378378-379379- for (i = 0; i < 16; i++)380380- if (lval == st->chip_info->sample_freq_avail[i])381381- break;382382- if (i == 16)383383- return -EINVAL;384384-385385- ret = iio_device_claim_direct_mode(indio_dev);386386- if (ret)387387- return ret;388388- st->mode &= ~AD7793_MODE_RATE(-1);389389- st->mode |= AD7793_MODE_RATE(i);390390- ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), st->mode);391391- iio_device_release_direct_mode(indio_dev);392392-393393- return len;394394-}395395-396396-static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,397397- ad7793_read_frequency,398398- ad7793_write_frequency);399399-400351static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(401352 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");402353···375424 ad7793_show_scale_available, NULL, 0);376425377426static struct attribute *ad7793_attributes[] = {378378- &iio_dev_attr_sampling_frequency.dev_attr.attr,379427 &iio_const_attr_sampling_frequency_available.dev_attr.attr,380428 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,381429 NULL···385435};386436387437static struct attribute *ad7797_attributes[] = {388388- &iio_dev_attr_sampling_frequency.dev_attr.attr,389438 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,390439 NULL391440};···454505 *val -= offset;455506 }456507 return IIO_VAL_INT;508508+ case IIO_CHAN_INFO_SAMP_FREQ:509509+ *val = st->chip_info510510+ ->sample_freq_avail[AD7793_MODE_RATE(st->mode)];511511+ return IIO_VAL_INT;457512 }458513 return -EINVAL;459514}···494541 ad7793_calibrate_all(st);495542 break;496543 }544544+ break;545545+ case IIO_CHAN_INFO_SAMP_FREQ:546546+ if (!val) {547547+ ret = -EINVAL;548548+ break;549549+ }550550+551551+ for (i = 0; i < 16; i++)552552+ if (val == st->chip_info->sample_freq_avail[i])553553+ break;554554+555555+ if (i == 16) {556556+ ret = -EINVAL;557557+ break;558558+ }559559+560560+ st->mode &= ~AD7793_MODE_RATE(-1);561561+ st->mode |= AD7793_MODE_RATE(i);562562+ ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode),563563+ st->mode);497564 break;498565 default:499566 ret = -EINVAL;
···144144 * Leave as soon as if exact resolution if reached.145145 * Otherwise the higher resolution below 32 bits is kept.146146 */147147+ fl->res = 0;147148 for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {148149 for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {149150 if (fast)···194193 }195194 }196195197197- if (!fl->fosr)196196+ if (!fl->res)198197 return -EINVAL;199198200199 return 0;···771770 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);772771 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];773772 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];774774- unsigned int spi_freq = adc->spi_freq;773773+ unsigned int spi_freq;775774 int ret = -EINVAL;776775777776 switch (mask) {···785784 case IIO_CHAN_INFO_SAMP_FREQ:786785 if (!val)787786 return -EINVAL;788788- if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)787787+788788+ switch (ch->src) {789789+ case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:789790 spi_freq = adc->dfsdm->spi_master_freq;791791+ break;792792+ case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING:793793+ case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING:794794+ spi_freq = adc->dfsdm->spi_master_freq / 2;795795+ break;796796+ default:797797+ spi_freq = adc->spi_freq;798798+ }790799791800 if (spi_freq % val)792801 dev_warn(&indio_dev->dev,
+1-1
drivers/iio/buffer/industrialio-buffer-dma.c
···587587 * Should be used as the set_length callback for iio_buffer_access_ops588588 * struct for DMA buffers.589589 */590590-int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length)590590+int iio_dma_buffer_set_length(struct iio_buffer *buffer, unsigned int length)591591{592592 /* Avoid an invalid state */593593 if (length < 2)
+9-2
drivers/iio/buffer/kfifo_buf.c
···2222#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)23232424static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,2525- int bytes_per_datum, int length)2525+ size_t bytes_per_datum, unsigned int length)2626{2727 if ((length == 0) || (bytes_per_datum == 0))2828+ return -EINVAL;2929+3030+ /*3131+ * Make sure we don't overflow an unsigned int after kfifo rounds up to3232+ * the next power of 2.3333+ */3434+ if (roundup_pow_of_two(length) > UINT_MAX / bytes_per_datum)2835 return -EINVAL;29363037 return __kfifo_alloc((struct __kfifo *)&buf->kf, length,···7467 return 0;7568}76697777-static int iio_set_length_kfifo(struct iio_buffer *r, int length)7070+static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length)7871{7972 /* Avoid an invalid state */8073 if (length < 2)
···20932093 if (netif_is_bond_slave(netdev))20942094 netdev = netdev_master_upper_dev_get(netdev);2095209520962096- neigh = dst_neigh_lookup(dst, &dst_addr);20962096+ neigh = dst_neigh_lookup(dst, dst_addr.sin6_addr.in6_u.u6_addr32);2097209720982098 rcu_read_lock();20992099 if (neigh) {
+2-2
drivers/infiniband/hw/i40iw/i40iw_hw.c
···331331 switch (info->ae_id) {332332 case I40IW_AE_LLP_FIN_RECEIVED:333333 if (qp->term_flags)334334- continue;334334+ break;335335 if (atomic_inc_return(&iwqp->close_timer_started) == 1) {336336 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSE_WAIT;337337 if ((iwqp->hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) &&···360360 break;361361 case I40IW_AE_LLP_CONNECTION_RESET:362362 if (atomic_read(&iwqp->close_timer_started))363363- continue;363363+ break;364364 i40iw_cm_disconn(iwqp);365365 break;366366 case I40IW_AE_QP_SUSPEND_COMPLETE:
···484484 return 1;485485}486486487487-static int first_med_bfreg(void)488488-{489489- return 1;490490-}491491-492487enum {493488 /* this is the first blue flame register in the array of bfregs assigned494489 * to a processes. Since we do not use it for blue flame but rather···507512 NUM_NON_BLUE_FLAME_BFREGS;508513509514 return n >= 0 ? n : 0;515515+}516516+517517+static int first_med_bfreg(struct mlx5_ib_dev *dev,518518+ struct mlx5_bfreg_info *bfregi)519519+{520520+ return num_med_bfreg(dev, bfregi) ? 1 : -ENOMEM;510521}511522512523static int first_hi_bfreg(struct mlx5_ib_dev *dev,···542541static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev,543542 struct mlx5_bfreg_info *bfregi)544543{545545- int minidx = first_med_bfreg();544544+ int minidx = first_med_bfreg(dev, bfregi);546545 int i;547546548548- for (i = first_med_bfreg(); i < first_hi_bfreg(dev, bfregi); i++) {547547+ if (minidx < 0)548548+ return minidx;549549+550550+ for (i = minidx; i < first_hi_bfreg(dev, bfregi); i++) {549551 if (bfregi->count[i] < bfregi->count[minidx])550552 minidx = i;551553 if (!bfregi->count[minidx])
+30-32
drivers/infiniband/hw/qedr/verbs.c
···401401{402402 struct qedr_ucontext *ucontext = get_qedr_ucontext(context);403403 struct qedr_dev *dev = get_qedr_dev(context->device);404404- unsigned long vm_page = vma->vm_pgoff << PAGE_SHIFT;405405- u64 unmapped_db = dev->db_phys_addr;404404+ unsigned long phys_addr = vma->vm_pgoff << PAGE_SHIFT;406405 unsigned long len = (vma->vm_end - vma->vm_start);407407- int rc = 0;408408- bool found;406406+ unsigned long dpi_start;407407+408408+ dpi_start = dev->db_phys_addr + (ucontext->dpi * ucontext->dpi_size);409409410410 DP_DEBUG(dev, QEDR_MSG_INIT,411411- "qedr_mmap called vm_page=0x%lx vm_pgoff=0x%lx unmapped_db=0x%llx db_size=%x, len=%lx\n",412412- vm_page, vma->vm_pgoff, unmapped_db, dev->db_size, len);413413- if (vma->vm_start & (PAGE_SIZE - 1)) {414414- DP_ERR(dev, "Vma_start not page aligned = %ld\n",415415- vma->vm_start);411411+ "mmap invoked with vm_start=0x%pK, vm_end=0x%pK,vm_pgoff=0x%pK; dpi_start=0x%pK dpi_size=0x%x\n",412412+ (void *)vma->vm_start, (void *)vma->vm_end,413413+ (void *)vma->vm_pgoff, (void *)dpi_start, ucontext->dpi_size);414414+415415+ if ((vma->vm_start & (PAGE_SIZE - 1)) || (len & (PAGE_SIZE - 1))) {416416+ DP_ERR(dev,417417+ "failed mmap, adrresses must be page aligned: start=0x%pK, end=0x%pK\n",418418+ (void *)vma->vm_start, (void *)vma->vm_end);416419 return -EINVAL;417420 }418421419419- found = qedr_search_mmap(ucontext, vm_page, len);420420- if (!found) {421421- DP_ERR(dev, "Vma_pgoff not found in mapped array = %ld\n",422422+ if (!qedr_search_mmap(ucontext, phys_addr, len)) {423423+ DP_ERR(dev, "failed mmap, vm_pgoff=0x%lx is not authorized\n",422424 vma->vm_pgoff);423425 return -EINVAL;424426 }425427426426- DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping doorbell bar\n");427427-428428- if ((vm_page >= unmapped_db) && (vm_page <= (unmapped_db +429429- dev->db_size))) {430430- DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping doorbell bar\n");431431- if (vma->vm_flags & VM_READ) {432432- DP_ERR(dev, "Trying to map doorbell bar for read\n");433433- return -EPERM;434434- }435435-436436- vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);437437-438438- rc = io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,439439- PAGE_SIZE, vma->vm_page_prot);440440- } else {441441- DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping chains\n");442442- rc = remap_pfn_range(vma, vma->vm_start,443443- vma->vm_pgoff, len, vma->vm_page_prot);428428+ if (phys_addr < dpi_start ||429429+ ((phys_addr + len) > (dpi_start + ucontext->dpi_size))) {430430+ DP_ERR(dev,431431+ "failed mmap, pages are outside of dpi; page address=0x%pK, dpi_start=0x%pK, dpi_size=0x%x\n",432432+ (void *)phys_addr, (void *)dpi_start,433433+ ucontext->dpi_size);434434+ return -EINVAL;444435 }445445- DP_DEBUG(dev, QEDR_MSG_INIT, "qedr_mmap return code: %d\n", rc);446446- return rc;436436+437437+ if (vma->vm_flags & VM_READ) {438438+ DP_ERR(dev, "failed mmap, cannot map doorbell bar for read\n");439439+ return -EINVAL;440440+ }441441+442442+ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);443443+ return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, len,444444+ vma->vm_page_prot);447445}448446449447struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
+1-9
drivers/infiniband/sw/rxe/rxe_verbs.c
···761761 unsigned int mask;762762 unsigned int length = 0;763763 int i;764764- int must_sched;765764766765 while (wr) {767766 mask = wr_opcode_mask(wr->opcode, qp);···790791 wr = wr->next;791792 }792793793793- /*794794- * Must sched in case of GSI QP because ib_send_mad() hold irq lock,795795- * and the requester call ip_local_out_sk() that takes spin_lock_bh.796796- */797797- must_sched = (qp_type(qp) == IB_QPT_GSI) ||798798- (queue_count(qp->sq.queue) > 1);799799-800800- rxe_run_task(&qp->req.task, must_sched);794794+ rxe_run_task(&qp->req.task, 1);801795 if (unlikely(qp->req.state == QP_STATE_ERROR))802796 rxe_run_task(&qp->comp.task, 1);803797
+108-73
drivers/input/misc/xen-kbdfront.c
···6363static void xenkbd_handle_motion_event(struct xenkbd_info *info,6464 struct xenkbd_motion *motion)6565{6666+ if (unlikely(!info->ptr))6767+ return;6868+6669 input_report_rel(info->ptr, REL_X, motion->rel_x);6770 input_report_rel(info->ptr, REL_Y, motion->rel_y);6871 if (motion->rel_z)···7673static void xenkbd_handle_position_event(struct xenkbd_info *info,7774 struct xenkbd_position *pos)7875{7676+ if (unlikely(!info->ptr))7777+ return;7878+7979 input_report_abs(info->ptr, ABS_X, pos->abs_x);8080 input_report_abs(info->ptr, ABS_Y, pos->abs_y);8181 if (pos->rel_z)···10296 pr_warn("unhandled keycode 0x%x\n", key->keycode);10397 return;10498 }9999+100100+ if (unlikely(!dev))101101+ return;105102106103 input_event(dev, EV_KEY, key->keycode, value);107104 input_sync(dev);···201192 const struct xenbus_device_id *id)202193{203194 int ret, i;204204- unsigned int abs, touch;195195+ bool with_mtouch, with_kbd, with_ptr;205196 struct xenkbd_info *info;206197 struct input_dev *kbd, *ptr, *mtouch;207198···220211 if (!info->page)221212 goto error_nomem;222213223223- /* Set input abs params to match backend screen res */224224- abs = xenbus_read_unsigned(dev->otherend,225225- XENKBD_FIELD_FEAT_ABS_POINTER, 0);226226- ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend,227227- XENKBD_FIELD_WIDTH,228228- ptr_size[KPARAM_X]);229229- ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend,230230- XENKBD_FIELD_HEIGHT,231231- ptr_size[KPARAM_Y]);232232- if (abs) {233233- ret = xenbus_write(XBT_NIL, dev->nodename,234234- XENKBD_FIELD_REQ_ABS_POINTER, "1");235235- if (ret) {236236- pr_warn("xenkbd: can't request abs-pointer\n");237237- abs = 0;238238- }239239- }214214+ /*215215+ * The below are reverse logic, e.g. if the feature is set, then216216+ * do not expose the corresponding virtual device.217217+ */218218+ with_kbd = !xenbus_read_unsigned(dev->otherend,219219+ XENKBD_FIELD_FEAT_DSBL_KEYBRD, 0);240220241241- touch = xenbus_read_unsigned(dev->nodename,242242- XENKBD_FIELD_FEAT_MTOUCH, 0);243243- if (touch) {221221+ with_ptr = !xenbus_read_unsigned(dev->otherend,222222+ XENKBD_FIELD_FEAT_DSBL_POINTER, 0);223223+224224+ /* Direct logic: if set, then create multi-touch device. */225225+ with_mtouch = xenbus_read_unsigned(dev->otherend,226226+ XENKBD_FIELD_FEAT_MTOUCH, 0);227227+ if (with_mtouch) {244228 ret = xenbus_write(XBT_NIL, dev->nodename,245229 XENKBD_FIELD_REQ_MTOUCH, "1");246230 if (ret) {247231 pr_warn("xenkbd: can't request multi-touch");248248- touch = 0;232232+ with_mtouch = 0;249233 }250234 }251235252236 /* keyboard */253253- kbd = input_allocate_device();254254- if (!kbd)255255- goto error_nomem;256256- kbd->name = "Xen Virtual Keyboard";257257- kbd->phys = info->phys;258258- kbd->id.bustype = BUS_PCI;259259- kbd->id.vendor = 0x5853;260260- kbd->id.product = 0xffff;237237+ if (with_kbd) {238238+ kbd = input_allocate_device();239239+ if (!kbd)240240+ goto error_nomem;241241+ kbd->name = "Xen Virtual Keyboard";242242+ kbd->phys = info->phys;243243+ kbd->id.bustype = BUS_PCI;244244+ kbd->id.vendor = 0x5853;245245+ kbd->id.product = 0xffff;261246262262- __set_bit(EV_KEY, kbd->evbit);263263- for (i = KEY_ESC; i < KEY_UNKNOWN; i++)264264- __set_bit(i, kbd->keybit);265265- for (i = KEY_OK; i < KEY_MAX; i++)266266- __set_bit(i, kbd->keybit);247247+ __set_bit(EV_KEY, kbd->evbit);248248+ for (i = KEY_ESC; i < KEY_UNKNOWN; i++)249249+ __set_bit(i, kbd->keybit);250250+ for (i = KEY_OK; i < KEY_MAX; i++)251251+ __set_bit(i, kbd->keybit);267252268268- ret = input_register_device(kbd);269269- if (ret) {270270- input_free_device(kbd);271271- xenbus_dev_fatal(dev, ret, "input_register_device(kbd)");272272- goto error;253253+ ret = input_register_device(kbd);254254+ if (ret) {255255+ input_free_device(kbd);256256+ xenbus_dev_fatal(dev, ret,257257+ "input_register_device(kbd)");258258+ goto error;259259+ }260260+ info->kbd = kbd;273261 }274274- info->kbd = kbd;275262276263 /* pointing device */277277- ptr = input_allocate_device();278278- if (!ptr)279279- goto error_nomem;280280- ptr->name = "Xen Virtual Pointer";281281- ptr->phys = info->phys;282282- ptr->id.bustype = BUS_PCI;283283- ptr->id.vendor = 0x5853;284284- ptr->id.product = 0xfffe;264264+ if (with_ptr) {265265+ unsigned int abs;285266286286- if (abs) {287287- __set_bit(EV_ABS, ptr->evbit);288288- input_set_abs_params(ptr, ABS_X, 0, ptr_size[KPARAM_X], 0, 0);289289- input_set_abs_params(ptr, ABS_Y, 0, ptr_size[KPARAM_Y], 0, 0);290290- } else {291291- input_set_capability(ptr, EV_REL, REL_X);292292- input_set_capability(ptr, EV_REL, REL_Y);267267+ /* Set input abs params to match backend screen res */268268+ abs = xenbus_read_unsigned(dev->otherend,269269+ XENKBD_FIELD_FEAT_ABS_POINTER, 0);270270+ ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend,271271+ XENKBD_FIELD_WIDTH,272272+ ptr_size[KPARAM_X]);273273+ ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend,274274+ XENKBD_FIELD_HEIGHT,275275+ ptr_size[KPARAM_Y]);276276+ if (abs) {277277+ ret = xenbus_write(XBT_NIL, dev->nodename,278278+ XENKBD_FIELD_REQ_ABS_POINTER, "1");279279+ if (ret) {280280+ pr_warn("xenkbd: can't request abs-pointer\n");281281+ abs = 0;282282+ }283283+ }284284+285285+ ptr = input_allocate_device();286286+ if (!ptr)287287+ goto error_nomem;288288+ ptr->name = "Xen Virtual Pointer";289289+ ptr->phys = info->phys;290290+ ptr->id.bustype = BUS_PCI;291291+ ptr->id.vendor = 0x5853;292292+ ptr->id.product = 0xfffe;293293+294294+ if (abs) {295295+ __set_bit(EV_ABS, ptr->evbit);296296+ input_set_abs_params(ptr, ABS_X, 0,297297+ ptr_size[KPARAM_X], 0, 0);298298+ input_set_abs_params(ptr, ABS_Y, 0,299299+ ptr_size[KPARAM_Y], 0, 0);300300+ } else {301301+ input_set_capability(ptr, EV_REL, REL_X);302302+ input_set_capability(ptr, EV_REL, REL_Y);303303+ }304304+ input_set_capability(ptr, EV_REL, REL_WHEEL);305305+306306+ __set_bit(EV_KEY, ptr->evbit);307307+ for (i = BTN_LEFT; i <= BTN_TASK; i++)308308+ __set_bit(i, ptr->keybit);309309+310310+ ret = input_register_device(ptr);311311+ if (ret) {312312+ input_free_device(ptr);313313+ xenbus_dev_fatal(dev, ret,314314+ "input_register_device(ptr)");315315+ goto error;316316+ }317317+ info->ptr = ptr;293318 }294294- input_set_capability(ptr, EV_REL, REL_WHEEL);295295-296296- __set_bit(EV_KEY, ptr->evbit);297297- for (i = BTN_LEFT; i <= BTN_TASK; i++)298298- __set_bit(i, ptr->keybit);299299-300300- ret = input_register_device(ptr);301301- if (ret) {302302- input_free_device(ptr);303303- xenbus_dev_fatal(dev, ret, "input_register_device(ptr)");304304- goto error;305305- }306306- info->ptr = ptr;307319308320 /* multi-touch device */309309- if (touch) {321321+ if (with_mtouch) {310322 int num_cont, width, height;311323312324 mtouch = input_allocate_device();313325 if (!mtouch)314326 goto error_nomem;315327316316- num_cont = xenbus_read_unsigned(info->xbdev->nodename,328328+ num_cont = xenbus_read_unsigned(info->xbdev->otherend,317329 XENKBD_FIELD_MT_NUM_CONTACTS,318330 1);319319- width = xenbus_read_unsigned(info->xbdev->nodename,331331+ width = xenbus_read_unsigned(info->xbdev->otherend,320332 XENKBD_FIELD_MT_WIDTH,321333 XENFB_WIDTH);322322- height = xenbus_read_unsigned(info->xbdev->nodename,334334+ height = xenbus_read_unsigned(info->xbdev->otherend,323335 XENKBD_FIELD_MT_HEIGHT,324336 XENFB_HEIGHT);325337···374344 }375345 info->mtouch_cur_contact_id = -1;376346 info->mtouch = mtouch;347347+ }348348+349349+ if (!(with_kbd || with_ptr || with_mtouch)) {350350+ ret = -ENXIO;351351+ goto error;377352 }378353379354 ret = xenkbd_connect_backend(dev, info);
+11-11
drivers/input/mouse/elan_i2c_smbus.c
···130130 bool max_baseline, u8 *value)131131{132132 int error;133133- u8 val[3];133133+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};134134135135 error = i2c_smbus_read_block_data(client,136136 max_baseline ?···149149 bool iap, u8 *version)150150{151151 int error;152152- u8 val[3];152152+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};153153154154 error = i2c_smbus_read_block_data(client,155155 iap ? ETP_SMBUS_IAP_VERSION_CMD :···170170 u8 *clickpad)171171{172172 int error;173173- u8 val[3];173173+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};174174175175 error = i2c_smbus_read_block_data(client,176176 ETP_SMBUS_SM_VERSION_CMD, val);···188188static int elan_smbus_get_product_id(struct i2c_client *client, u16 *id)189189{190190 int error;191191- u8 val[3];191191+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};192192193193 error = i2c_smbus_read_block_data(client,194194 ETP_SMBUS_UNIQUEID_CMD, val);···205205 bool iap, u16 *csum)206206{207207 int error;208208- u8 val[3];208208+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};209209210210 error = i2c_smbus_read_block_data(client,211211 iap ? ETP_SMBUS_FW_CHECKSUM_CMD :···226226{227227 int ret;228228 int error;229229- u8 val[3];229229+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};230230231231 ret = i2c_smbus_read_block_data(client, ETP_SMBUS_RANGE_CMD, val);232232 if (ret != 3) {···246246{247247 int ret;248248 int error;249249- u8 val[3];249249+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};250250251251 ret = i2c_smbus_read_block_data(client, ETP_SMBUS_RESOLUTION_CMD, val);252252 if (ret != 3) {···267267{268268 int ret;269269 int error;270270- u8 val[3];270270+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};271271272272 ret = i2c_smbus_read_block_data(client, ETP_SMBUS_XY_TRACENUM_CMD, val);273273 if (ret != 3) {···294294{295295 int error;296296 u16 constant;297297- u8 val[3];297297+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};298298299299 error = i2c_smbus_read_block_data(client, ETP_SMBUS_IAP_CTRL_CMD, val);300300 if (error < 0) {···345345 int len;346346 int error;347347 enum tp_mode mode;348348- u8 val[3];348348+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};349349 u8 cmd[4] = {0x0F, 0x78, 0x00, 0x06};350350 u16 password;351351···419419 struct device *dev = &client->dev;420420 int error;421421 u16 result;422422- u8 val[3];422422+ u8 val[I2C_SMBUS_BLOCK_MAX] = {0};423423424424 /*425425 * Due to the limitation of smbus protocol limiting
···2020 int max_length, divas_xdi_copy_to_user_fn_t cp_fn);21212222int diva_xdi_write(void *adapter, void *os_handle, const void __user *src,2323- int length, divas_xdi_copy_from_user_fn_t cp_fn);2323+ int length, void *msg,2424+ divas_xdi_copy_from_user_fn_t cp_fn);24252526void *diva_xdi_open_adapter(void *os_handle, const void __user *src,2626- int length,2727+ int length, void *msg,2728 divas_xdi_copy_from_user_fn_t cp_fn);28292930void diva_xdi_close_adapter(void *adapter, void *os_handle);
+11-7
drivers/isdn/hardware/eicon/divasmain.c
···591591static ssize_t divas_write(struct file *file, const char __user *buf,592592 size_t count, loff_t *ppos)593593{594594+ diva_xdi_um_cfg_cmd_t msg;594595 int ret = -EINVAL;595596596597 if (!file->private_data) {597598 file->private_data = diva_xdi_open_adapter(file, buf,598598- count,599599+ count, &msg,599600 xdi_copy_from_user);600600- }601601- if (!file->private_data) {602602- return (-ENODEV);601601+ if (!file->private_data)602602+ return (-ENODEV);603603+ ret = diva_xdi_write(file->private_data, file,604604+ buf, count, &msg, xdi_copy_from_user);605605+ } else {606606+ ret = diva_xdi_write(file->private_data, file,607607+ buf, count, NULL, xdi_copy_from_user);603608 }604609605605- ret = diva_xdi_write(file->private_data, file,606606- buf, count, xdi_copy_from_user);607610 switch (ret) {608611 case -1: /* Message should be removed from rx mailbox first */609612 ret = -EBUSY;···625622static ssize_t divas_read(struct file *file, char __user *buf,626623 size_t count, loff_t *ppos)627624{625625+ diva_xdi_um_cfg_cmd_t msg;628626 int ret = -EINVAL;629627630628 if (!file->private_data) {631629 file->private_data = diva_xdi_open_adapter(file, buf,632632- count,630630+ count, &msg,633631 xdi_copy_from_user);634632 }635633 if (!file->private_data) {
+20-4
drivers/mfd/cros_ec_spi.c
···419419 /* Verify that EC can process command */420420 for (i = 0; i < len; i++) {421421 rx_byte = rx_buf[i];422422+ /*423423+ * Seeing the PAST_END, RX_BAD_DATA, or NOT_READY424424+ * markers are all signs that the EC didn't fully425425+ * receive our command. e.g., if the EC is flashing426426+ * itself, it can't respond to any commands and instead427427+ * clocks out EC_SPI_PAST_END from its SPI hardware428428+ * buffer. Similar occurrences can happen if the AP is429429+ * too slow to clock out data after asserting CS -- the430430+ * EC will abort and fill its buffer with431431+ * EC_SPI_RX_BAD_DATA.432432+ *433433+ * In all cases, these errors should be safe to retry.434434+ * Report -EAGAIN and let the caller decide what to do435435+ * about that.436436+ */422437 if (rx_byte == EC_SPI_PAST_END ||423438 rx_byte == EC_SPI_RX_BAD_DATA ||424439 rx_byte == EC_SPI_NOT_READY) {425425- ret = -EREMOTEIO;440440+ ret = -EAGAIN;426441 break;427442 }428443 }···446431 if (!ret)447432 ret = cros_ec_spi_receive_packet(ec_dev,448433 ec_msg->insize + sizeof(*response));449449- else434434+ else if (ret != -EAGAIN)450435 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);451436452437 final_ret = terminate_request(ec_dev);···552537 /* Verify that EC can process command */553538 for (i = 0; i < len; i++) {554539 rx_byte = rx_buf[i];540540+ /* See comments in cros_ec_pkt_xfer_spi() */555541 if (rx_byte == EC_SPI_PAST_END ||556542 rx_byte == EC_SPI_RX_BAD_DATA ||557543 rx_byte == EC_SPI_NOT_READY) {558558- ret = -EREMOTEIO;544544+ ret = -EAGAIN;559545 break;560546 }561547 }···565549 if (!ret)566550 ret = cros_ec_spi_receive_response(ec_dev,567551 ec_msg->insize + EC_MSG_TX_PROTO_BYTES);568568- else552552+ else if (ret != -EAGAIN)569553 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);570554571555 final_ret = terminate_request(ec_dev);
···354354 /* Locate the first rule available */355355 if (fs->location == RX_CLS_LOC_ANY)356356 rule_index = find_first_zero_bit(priv->cfp.used,357357- bcm_sf2_cfp_rule_size(priv));357357+ priv->num_cfp_rules);358358 else359359 rule_index = fs->location;360360+361361+ if (rule_index > bcm_sf2_cfp_rule_size(priv))362362+ return -ENOSPC;360363361364 layout = &udf_tcpip4_layout;362365 /* We only use one UDF slice for now */···565562 * first half because the HW search is by incrementing addresses.566563 */567564 if (fs->location == RX_CLS_LOC_ANY)568568- rule_index[0] = find_first_zero_bit(priv->cfp.used,569569- bcm_sf2_cfp_rule_size(priv));565565+ rule_index[1] = find_first_zero_bit(priv->cfp.used,566566+ priv->num_cfp_rules);570567 else571571- rule_index[0] = fs->location;568568+ rule_index[1] = fs->location;569569+ if (rule_index[1] > bcm_sf2_cfp_rule_size(priv))570570+ return -ENOSPC;572571573572 /* Flag it as used (cleared on error path) such that we can immediately574573 * obtain a second one to chain from.575574 */576576- set_bit(rule_index[0], priv->cfp.used);575575+ set_bit(rule_index[1], priv->cfp.used);577576578578- rule_index[1] = find_first_zero_bit(priv->cfp.used,579579- bcm_sf2_cfp_rule_size(priv));580580- if (rule_index[1] > bcm_sf2_cfp_rule_size(priv)) {577577+ rule_index[0] = find_first_zero_bit(priv->cfp.used,578578+ priv->num_cfp_rules);579579+ if (rule_index[0] > bcm_sf2_cfp_rule_size(priv)) {581580 ret = -ENOSPC;582581 goto out_err;583582 }···717712 /* Flag the second half rule as being used now, return it as the718713 * location, and flag it as unique while dumping rules719714 */720720- set_bit(rule_index[1], priv->cfp.used);715715+ set_bit(rule_index[0], priv->cfp.used);721716 set_bit(rule_index[1], priv->cfp.unique);722717 fs->location = rule_index[1];723718724719 return ret;725720726721out_err:727727- clear_bit(rule_index[0], priv->cfp.used);722722+ clear_bit(rule_index[1], priv->cfp.used);728723 return ret;729724}730725···790785 int ret;791786 u32 reg;792787793793- /* Refuse deletion of unused rules, and the default reserved rule */794794- if (!test_bit(loc, priv->cfp.used) || loc == 0)795795- return -EINVAL;796796-797788 /* Indicate which rule we want to read */798789 bcm_sf2_cfp_rule_addr_set(priv, loc);799790···826825{827826 u32 next_loc = 0;828827 int ret;828828+829829+ /* Refuse deleting unused rules, and those that are not unique since830830+ * that could leave IPv6 rules with one of the chained rule in the831831+ * table.832832+ */833833+ if (!test_bit(loc, priv->cfp.unique) || loc == 0)834834+ return -EINVAL;829835830836 ret = bcm_sf2_cfp_rule_del_one(priv, port, loc, &next_loc);831837 if (ret)
···11+// SPDX-License-Identifier: GPL-2.0+12/*23 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.34 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
+1-13
drivers/net/ethernet/freescale/fec_ptp.c
···11+// SPDX-License-Identifier: GPL-2.012/*23 * Fast Ethernet Controller (ENET) PTP driver for MX6x.34 *45 * Copyright (C) 2012 Freescale Semiconductor, Inc.55- *66- * This program is free software; you can redistribute it and/or modify it77- * under the terms and conditions of the GNU General Public License,88- * version 2, as published by the Free Software Foundation.99- *1010- * This program is distributed in the hope it will be useful, but WITHOUT1111- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1212- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1313- * more details.1414- *1515- * You should have received a copy of the GNU General Public License along with1616- * this program; if not, write to the Free Software Foundation, Inc.,1717- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.186 */197208#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+32-18
drivers/net/ethernet/ibm/ibmvnic.c
···192192 if (adapter->fw_done_rc) {193193 dev_err(dev, "Couldn't map long term buffer,rc = %d\n",194194 adapter->fw_done_rc);195195+ dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);195196 return -1;196197 }197198 return 0;···796795 struct ibmvnic_adapter *adapter = netdev_priv(netdev);797796 unsigned long timeout = msecs_to_jiffies(30000);798797 int retry_count = 0;798798+ bool retry;799799 int rc;800800801801 do {802802+ retry = false;802803 if (retry_count > IBMVNIC_MAX_QUEUES) {803804 netdev_warn(netdev, "Login attempts exceeded\n");804805 return -1;···824821 retry_count++;825822 release_sub_crqs(adapter, 1);826823824824+ retry = true;825825+ netdev_dbg(netdev,826826+ "Received partial success, retrying...\n");827827 adapter->init_done_rc = 0;828828 reinit_completion(&adapter->init_done);829829 send_cap_queries(adapter);···854848 netdev_warn(netdev, "Adapter login failed\n");855849 return -1;856850 }857857- } while (adapter->init_done_rc == PARTIALSUCCESS);851851+ } while (retry);858852859853 /* handle pending MAC address changes after successful login */860854 if (adapter->mac_change_pending) {···18271821 if (rc)18281822 return rc;18291823 }18241824+ ibmvnic_disable_irqs(adapter);18301825 }18311831-18321832- ibmvnic_disable_irqs(adapter);18331826 adapter->state = VNIC_CLOSED;1834182718351828 if (reset_state == VNIC_CLOSED)···26222617{26232618 struct device *dev = &adapter->vdev->dev;26242619 unsigned long rc;26252625- u64 val;2626262026272621 if (scrq->hw_irq > 0x100000000ULL) {26282622 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);26292623 return 1;26302624 }2631262526322632- val = (0xff000000) | scrq->hw_irq;26332633- rc = plpar_hcall_norets(H_EOI, val);26342634- if (rc)26352635- dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",26362636- val, rc);26262626+ if (adapter->resetting &&26272627+ adapter->reset_reason == VNIC_RESET_MOBILITY) {26282628+ u64 val = (0xff000000) | scrq->hw_irq;26292629+26302630+ rc = plpar_hcall_norets(H_EOI, val);26312631+ if (rc)26322632+ dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",26332633+ val, rc);26342634+ }2637263526382636 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,26392637 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);···45944586 release_crq_queue(adapter);45954587 }4596458845974597- rc = init_stats_buffers(adapter);45984598- if (rc)45994599- return rc;46004600-46014601- rc = init_stats_token(adapter);46024602- if (rc)46034603- return rc;46044604-46054589 return rc;46064590}46074591···46624662 goto ibmvnic_init_fail;46634663 } while (rc == EAGAIN);4664466446654665+ rc = init_stats_buffers(adapter);46664666+ if (rc)46674667+ goto ibmvnic_init_fail;46684668+46694669+ rc = init_stats_token(adapter);46704670+ if (rc)46714671+ goto ibmvnic_stats_fail;46724672+46654673 netdev->mtu = adapter->req_mtu - ETH_HLEN;46664674 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;46674675 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;4668467646694677 rc = device_create_file(&dev->dev, &dev_attr_failover);46704678 if (rc)46714671- goto ibmvnic_init_fail;46794679+ goto ibmvnic_dev_file_err;4672468046734681 netif_carrier_off(netdev);46744682 rc = register_netdev(netdev);···4694468646954687ibmvnic_register_fail:46964688 device_remove_file(&dev->dev, &dev_attr_failover);46894689+46904690+ibmvnic_dev_file_err:46914691+ release_stats_token(adapter);46924692+46934693+ibmvnic_stats_fail:46944694+ release_stats_buffers(adapter);4697469546984696ibmvnic_init_fail:46994697 release_sub_crqs(adapter, 1);
···237237 context->buf.sg[0].data = &context->command;238238239239 spin_lock_irqsave(&fdev->ipsec->pending_cmds_lock, flags);240240- list_add_tail(&context->list, &fdev->ipsec->pending_cmds);240240+ res = mlx5_fpga_sbu_conn_sendmsg(fdev->ipsec->conn, &context->buf);241241+ if (!res)242242+ list_add_tail(&context->list, &fdev->ipsec->pending_cmds);241243 spin_unlock_irqrestore(&fdev->ipsec->pending_cmds_lock, flags);242244243243- res = mlx5_fpga_sbu_conn_sendmsg(fdev->ipsec->conn, &context->buf);244245 if (res) {245245- mlx5_fpga_warn(fdev, "Failure sending IPSec command: %d\n",246246- res);247247- spin_lock_irqsave(&fdev->ipsec->pending_cmds_lock, flags);248248- list_del(&context->list);249249- spin_unlock_irqrestore(&fdev->ipsec->pending_cmds_lock, flags);246246+ mlx5_fpga_warn(fdev, "Failed to send IPSec command: %d\n", res);250247 kfree(context);251248 return ERR_PTR(res);252249 }250250+253251 /* Context will be freed by wait func after completion */254252 return context;255253}
+5
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
···44334433 NL_SET_ERR_MSG_MOD(extack, "Can not put a VLAN on an OVS port");44344434 return -EINVAL;44354435 }44364436+ if (is_vlan_dev(upper_dev) &&44374437+ vlan_dev_vlan_id(upper_dev) == 1) {44384438+ NL_SET_ERR_MSG_MOD(extack, "Creating a VLAN device with VID 1 is unsupported: VLAN 1 carries untagged traffic");44394439+ return -EINVAL;44404440+ }44364441 break;44374442 case NETDEV_CHANGEUPPER:44384443 upper_dev = info->upper_dev;
+1-1
drivers/net/ethernet/natsemi/sonic.c
···8484 for (i = 0; i < SONIC_NUM_RRS; i++) {8585 dma_addr_t laddr = dma_map_single(lp->device, skb_put(lp->rx_skb[i], SONIC_RBSIZE),8686 SONIC_RBSIZE, DMA_FROM_DEVICE);8787- if (!laddr) {8787+ if (dma_mapping_error(lp->device, laddr)) {8888 while(i > 0) { /* free any that were mapped successfully */8989 i--;9090 dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
···16741674 if (ret)16751675 goto unreg_napi;1676167616771677- if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)))16781678- dev_warn(&pdev->dev, "Failed to enable 64-bit DMA\n");16771677+ if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)))16781678+ dev_warn(&pdev->dev, "Failed to set DMA mask\n");1679167916801680 ret = register_netdev(ndev);16811681 if (ret) {
···5656 /* The register must be written to both the Shadow Register Select and5757 * the Shadow Read Register Selector5858 */5959- phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum |5959+ phy_write(phydev, MII_BCM54XX_AUX_CTL, MII_BCM54XX_AUXCTL_SHDWSEL_MASK |6060 regnum << MII_BCM54XX_AUXCTL_SHDWSEL_READ_SHIFT);6161 return phy_read(phydev, MII_BCM54XX_AUX_CTL);6262}
···573573 ksz9031_of_load_skew_values(phydev, of_node,574574 MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,575575 tx_data_skews, 4);576576+577577+ /* Silicon Errata Sheet (DS80000691D or DS80000692D):578578+ * When the device links in the 1000BASE-T slave mode only,579579+ * the optional 125MHz reference output clock (CLK125_NDO)580580+ * has wide duty cycle variation.581581+ *582582+ * The optional CLK125_NDO clock does not meet the RGMII583583+ * 45/55 percent (min/max) duty cycle requirement and therefore584584+ * cannot be used directly by the MAC side for clocking585585+ * applications that have setup/hold time requirements on586586+ * rising and falling clock edges.587587+ *588588+ * Workaround:589589+ * Force the phy to be the master to receive a stable clock590590+ * which meets the duty cycle requirement.591591+ */592592+ if (of_property_read_bool(of_node, "micrel,force-master")) {593593+ result = phy_read(phydev, MII_CTRL1000);594594+ if (result < 0)595595+ goto err_force_master;596596+597597+ /* enable master mode, config & prefer master */598598+ result |= CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER;599599+ result = phy_write(phydev, MII_CTRL1000, result);600600+ if (result < 0)601601+ goto err_force_master;602602+ }576603 }577604578605 return ksz9031_center_flp_timing(phydev);606606+607607+err_force_master:608608+ phydev_err(phydev, "failed to force the phy to master mode\n");609609+ return result;579610}580611581612#define KSZ8873MLL_GLOBAL_CONTROL_4 0x06
+5-22
drivers/net/ppp/ppp_generic.c
···605605606606 if (cmd == PPPIOCDETACH) {607607 /*608608- * We have to be careful here... if the file descriptor609609- * has been dup'd, we could have another process in the610610- * middle of a poll using the same file *, so we had611611- * better not free the interface data structures -612612- * instead we fail the ioctl. Even in this case, we613613- * shut down the interface if we are the owner of it.614614- * Actually, we should get rid of PPPIOCDETACH, userland615615- * (i.e. pppd) could achieve the same effect by closing616616- * this fd and reopening /dev/ppp.608608+ * PPPIOCDETACH is no longer supported as it was heavily broken,609609+ * and is only known to have been used by pppd older than610610+ * ppp-2.4.2 (released November 2003).617611 */612612+ pr_warn_once("%s (%d) used obsolete PPPIOCDETACH ioctl\n",613613+ current->comm, current->pid);618614 err = -EINVAL;619619- if (pf->kind == INTERFACE) {620620- ppp = PF_TO_PPP(pf);621621- rtnl_lock();622622- if (file == ppp->owner)623623- unregister_netdevice(ppp->dev);624624- rtnl_unlock();625625- }626626- if (atomic_long_read(&file->f_count) < 2) {627627- ppp_release(NULL, file);628628- err = 0;629629- } else630630- pr_warn("PPPIOCDETACH file->f_count=%ld\n",631631- atomic_long_read(&file->f_count));632615 goto out;633616 }634617
+36-25
drivers/net/tun.c
···681681 skb_queue_purge(&tfile->sk.sk_error_queue);682682}683683684684-static void tun_cleanup_tx_ring(struct tun_file *tfile)685685-{686686- if (tfile->tx_ring.queue) {687687- ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);688688- xdp_rxq_info_unreg(&tfile->xdp_rxq);689689- memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring));690690- }691691-}692692-693684static void __tun_detach(struct tun_file *tfile, bool clean)694685{695686 struct tun_file *ntfile;···727736 tun->dev->reg_state == NETREG_REGISTERED)728737 unregister_netdevice(tun->dev);729738 }730730- tun_cleanup_tx_ring(tfile);739739+ if (tun)740740+ xdp_rxq_info_unreg(&tfile->xdp_rxq);741741+ ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);731742 sock_put(&tfile->sk);732743 }733744}···776783 tun_napi_del(tun, tfile);777784 /* Drop read queue */778785 tun_queue_purge(tfile);786786+ xdp_rxq_info_unreg(&tfile->xdp_rxq);779787 sock_put(&tfile->sk);780780- tun_cleanup_tx_ring(tfile);781788 }782789 list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) {783790 tun_enable_queue(tfile);784791 tun_queue_purge(tfile);792792+ xdp_rxq_info_unreg(&tfile->xdp_rxq);785793 sock_put(&tfile->sk);786786- tun_cleanup_tx_ring(tfile);787794 }788795 BUG_ON(tun->numdisabled != 0);789796···827834 }828835829836 if (!tfile->detached &&830830- ptr_ring_init(&tfile->tx_ring, dev->tx_queue_len, GFP_KERNEL)) {837837+ ptr_ring_resize(&tfile->tx_ring, dev->tx_queue_len,838838+ GFP_KERNEL, tun_ptr_free)) {831839 err = -ENOMEM;832840 goto out;833841 }···14231429 dev->max_mtu = MAX_MTU - dev->hard_header_len;14241430}1425143114321432+static bool tun_sock_writeable(struct tun_struct *tun, struct tun_file *tfile)14331433+{14341434+ struct sock *sk = tfile->socket.sk;14351435+14361436+ return (tun->dev->flags & IFF_UP) && sock_writeable(sk);14371437+}14381438+14261439/* Character device part */1427144014281441/* Poll */···14521451 if (!ptr_ring_empty(&tfile->tx_ring))14531452 mask |= EPOLLIN | EPOLLRDNORM;1454145314551455- if (tun->dev->flags & IFF_UP &&14561456- (sock_writeable(sk) ||14571457- (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&14581458- sock_writeable(sk))))14541454+ /* Make sure SOCKWQ_ASYNC_NOSPACE is set if not writable to14551455+ * guarantee EPOLLOUT to be raised by either here or14561456+ * tun_sock_write_space(). Then process could get notification14571457+ * after it writes to a down device and meets -EIO.14581458+ */14591459+ if (tun_sock_writeable(tun, tfile) ||14601460+ (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&14611461+ tun_sock_writeable(tun, tfile)))14591462 mask |= EPOLLOUT | EPOLLWRNORM;1460146314611464 if (tun->dev->reg_state != NETREG_REGISTERED)···16501645 else16511646 *skb_xdp = 0;1652164716531653- preempt_disable();16481648+ local_bh_disable();16541649 rcu_read_lock();16551650 xdp_prog = rcu_dereference(tun->xdp_prog);16561651 if (xdp_prog && !*skb_xdp) {···16751670 if (err)16761671 goto err_redirect;16771672 rcu_read_unlock();16781678- preempt_enable();16731673+ local_bh_enable();16791674 return NULL;16801675 case XDP_TX:16811676 get_page(alloc_frag->page);···16841679 goto err_redirect;16851680 tun_xdp_flush(tun->dev);16861681 rcu_read_unlock();16871687- preempt_enable();16821682+ local_bh_enable();16881683 return NULL;16891684 case XDP_PASS:16901685 delta = orig_data - xdp.data;···17031698 skb = build_skb(buf, buflen);17041699 if (!skb) {17051700 rcu_read_unlock();17061706- preempt_enable();17011701+ local_bh_enable();17071702 return ERR_PTR(-ENOMEM);17081703 }17091704···17131708 alloc_frag->offset += buflen;1714170917151710 rcu_read_unlock();17161716- preempt_enable();17111711+ local_bh_enable();1717171217181713 return skb;17191714···17211716 put_page(alloc_frag->page);17221717err_xdp:17231718 rcu_read_unlock();17241724- preempt_enable();17191719+ local_bh_enable();17251720 this_cpu_inc(tun->pcpu_stats->rx_dropped);17261721 return NULL;17271722}···19171912 struct bpf_prog *xdp_prog;19181913 int ret;1919191419151915+ local_bh_disable();19201916 rcu_read_lock();19211917 xdp_prog = rcu_dereference(tun->xdp_prog);19221918 if (xdp_prog) {19231919 ret = do_xdp_generic(xdp_prog, skb);19241920 if (ret != XDP_PASS) {19251921 rcu_read_unlock();19221922+ local_bh_enable();19261923 return total_len;19271924 }19281925 }19291926 rcu_read_unlock();19271927+ local_bh_enable();19301928 }1931192919321930 rcu_read_lock();···32273219 &tun_proto, 0);32283220 if (!tfile)32293221 return -ENOMEM;32223222+ if (ptr_ring_init(&tfile->tx_ring, 0, GFP_KERNEL)) {32233223+ sk_free(&tfile->sk);32243224+ return -ENOMEM;32253225+ }32263226+32303227 RCU_INIT_POINTER(tfile->tun, NULL);32313228 tfile->flags = 0;32323229 tfile->ifindex = 0;···32513238 INIT_LIST_HEAD(&tfile->next);3252323932533240 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY);32543254-32553255- memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring));3256324132573242 return 0;32583243}
···707707 void *data;708708 u32 act;709709710710+ /* Transient failure which in theory could occur if711711+ * in-flight packets from before XDP was enabled reach712712+ * the receive path after XDP is loaded.713713+ */714714+ if (unlikely(hdr->hdr.gso_type))715715+ goto err_xdp;716716+710717 /* This happens when rx buffer size is underestimated711718 * or headroom is not enough because of the buffer712719 * was refilled before XDP is set. This should only···733726 } else {734727 xdp_page = page;735728 }736736-737737- /* Transient failure which in theory could occur if738738- * in-flight packets from before XDP was enabled reach739739- * the receive path after XDP is loaded. In practice I740740- * was not able to create this condition.741741- */742742- if (unlikely(hdr->hdr.gso_type))743743- goto err_xdp;744729745730 /* Allow consuming headroom but reserve enough space to push746731 * the descriptor on if we get an XDP_TX return code.···774775 }775776 *xdp_xmit = true;776777 if (unlikely(xdp_page != page))777777- goto err_xdp;778778+ put_page(page);778779 rcu_read_unlock();779780 goto xdp_xmit;780781 case XDP_REDIRECT:···786787 }787788 *xdp_xmit = true;788789 if (unlikely(xdp_page != page))789789- goto err_xdp;790790+ put_page(page);790791 rcu_read_unlock();791792 goto xdp_xmit;792793 default:···874875 rcu_read_unlock();875876err_skb:876877 put_page(page);877877- while (--num_buf) {878878+ while (num_buf-- > 1) {878879 buf = virtqueue_get_buf(rq->vq, &len);879880 if (unlikely(!buf)) {880881 pr_debug("%s: rx error: %d buffers missing\n",
+47-25
drivers/net/vmxnet3/vmxnet3_drv.c
···369369370370 gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;371371 while (VMXNET3_TCD_GET_GEN(&gdesc->tcd) == tq->comp_ring.gen) {372372+ /* Prevent any &gdesc->tcd field from being (speculatively)373373+ * read before (&gdesc->tcd)->gen is read.374374+ */375375+ dma_rmb();376376+372377 completed += vmxnet3_unmap_pkt(VMXNET3_TCD_GET_TXIDX(373378 &gdesc->tcd), tq, adapter->pdev,374379 adapter);···11081103 gdesc->txd.tci = skb_vlan_tag_get(skb);11091104 }1110110511061106+ /* Ensure that the write to (&gdesc->txd)->gen will be observed after11071107+ * all other writes to &gdesc->txd.11081108+ */11091109+ dma_wmb();11101110+11111111 /* finally flips the GEN bit of the SOP desc. */11121112 gdesc->dword[2] = cpu_to_le32(le32_to_cpu(gdesc->dword[2]) ^11131113 VMXNET3_TXD_GEN);···13081298 */13091299 break;13101300 }13011301+13021302+ /* Prevent any rcd field from being (speculatively) read before13031303+ * rcd->gen is read.13041304+ */13051305+ dma_rmb();13061306+13111307 BUG_ON(rcd->rqID != rq->qid && rcd->rqID != rq->qid2 &&13121308 rcd->rqID != rq->dataRingQid);13131309 idx = rcd->rxdIdx;···15441528 ring->next2comp = idx;15451529 num_to_alloc = vmxnet3_cmd_ring_desc_avail(ring);15461530 ring = rq->rx_ring + ring_idx;15311531+15321532+ /* Ensure that the writes to rxd->gen bits will be observed15331533+ * after all other writes to rxd objects.15341534+ */15351535+ dma_wmb();15361536+15471537 while (num_to_alloc) {15481538 vmxnet3_getRxDesc(rxd, &ring->base[ring->next2fill].rxd,15491539 &rxCmdDesc);···27102688/* ==================== initialization and cleanup routines ============ */2711268927122690static int27132713-vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64)26912691+vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter)27142692{27152693 int err;27162694 unsigned long mmio_start, mmio_len;···27222700 return err;27232701 }2724270227252725- if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {27262726- if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {27272727- dev_err(&pdev->dev,27282728- "pci_set_consistent_dma_mask failed\n");27292729- err = -EIO;27302730- goto err_set_mask;27312731- }27322732- *dma64 = true;27332733- } else {27342734- if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {27352735- dev_err(&pdev->dev,27362736- "pci_set_dma_mask failed\n");27372737- err = -EIO;27382738- goto err_set_mask;27392739- }27402740- *dma64 = false;27412741- }27422742-27432703 err = pci_request_selected_regions(pdev, (1 << 2) - 1,27442704 vmxnet3_driver_name);27452705 if (err) {27462706 dev_err(&pdev->dev,27472707 "Failed to request region for adapter: error %d\n", err);27482748- goto err_set_mask;27082708+ goto err_enable_device;27492709 }2750271027512711 pci_set_master(pdev);···27552751 iounmap(adapter->hw_addr0);27562752err_ioremap:27572753 pci_release_selected_regions(pdev, (1 << 2) - 1);27582758-err_set_mask:27542754+err_enable_device:27592755 pci_disable_device(pdev);27602756 return err;27612757}···32583254#endif32593255 };32603256 int err;32613261- bool dma64 = false; /* stupid gcc */32573257+ bool dma64;32623258 u32 ver;32633259 struct net_device *netdev;32643260 struct vmxnet3_adapter *adapter;···33043300 adapter->rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;33053301 adapter->rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;3306330233033303+ if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {33043304+ if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {33053305+ dev_err(&pdev->dev,33063306+ "pci_set_consistent_dma_mask failed\n");33073307+ err = -EIO;33083308+ goto err_set_mask;33093309+ }33103310+ dma64 = true;33113311+ } else {33123312+ if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {33133313+ dev_err(&pdev->dev,33143314+ "pci_set_dma_mask failed\n");33153315+ err = -EIO;33163316+ goto err_set_mask;33173317+ }33183318+ dma64 = false;33193319+ }33203320+33073321 spin_lock_init(&adapter->cmd_lock);33083322 adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter,33093323 sizeof(struct vmxnet3_adapter),···33293307 if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) {33303308 dev_err(&pdev->dev, "Failed to map dma\n");33313309 err = -EFAULT;33323332- goto err_dma_map;33103310+ goto err_set_mask;33333311 }33343312 adapter->shared = dma_alloc_coherent(33353313 &adapter->pdev->dev,···33803358 }33813359#endif /* VMXNET3_RSS */3382336033833383- err = vmxnet3_alloc_pci_resources(adapter, &dma64);33613361+ err = vmxnet3_alloc_pci_resources(adapter);33843362 if (err < 0)33853363 goto err_alloc_pci;33863364···35263504err_alloc_shared:35273505 dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa,35283506 sizeof(struct vmxnet3_adapter), PCI_DMA_TODEVICE);35293529-err_dma_map:35073507+err_set_mask:35303508 free_netdev(netdev);35313509 return err;35323510}
+5-3
drivers/net/vmxnet3/vmxnet3_int.h
···6969/*7070 * Version numbers7171 */7272-#define VMXNET3_DRIVER_VERSION_STRING "1.4.14.0-k"7272+#define VMXNET3_DRIVER_VERSION_STRING "1.4.16.0-k"73737474-/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */7575-#define VMXNET3_DRIVER_VERSION_NUM 0x01040e007474+/* Each byte of this 32-bit integer encodes a version number in7575+ * VMXNET3_DRIVER_VERSION_STRING.7676+ */7777+#define VMXNET3_DRIVER_VERSION_NUM 0x0104100076787779#if defined(CONFIG_PCI_MSI)7880 /* RSS only makes sense if MSI-X is supported. */
+5-5
drivers/net/wireless/intel/iwlwifi/pcie/trans.c
···15901590 struct iwl_trans *trans)15911591{15921592 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);15931593- int max_irqs, num_irqs, i, ret, nr_online_cpus;15931593+ int max_irqs, num_irqs, i, ret;15941594 u16 pci_cmd;1595159515961596 if (!trans->cfg->mq_rx_supported)15971597 goto enable_msi;1598159815991599- nr_online_cpus = num_online_cpus();16001600- max_irqs = min_t(u32, nr_online_cpus + 2, IWL_MAX_RX_HW_QUEUES);15991599+ max_irqs = min_t(u32, num_online_cpus() + 2, IWL_MAX_RX_HW_QUEUES);16011600 for (i = 0; i < max_irqs; i++)16021601 trans_pcie->msix_entries[i].entry = i;16031602···16221623 * Two interrupts less: non rx causes shared with FBQ and RSS.16231624 * More than two interrupts: we will use fewer RSS queues.16241625 */16251625- if (num_irqs <= nr_online_cpus) {16261626+ if (num_irqs <= max_irqs - 2) {16261627 trans_pcie->trans->num_rx_queues = num_irqs + 1;16271628 trans_pcie->shared_vec_mask = IWL_SHARED_IRQ_NON_RX |16281629 IWL_SHARED_IRQ_FIRST_RSS;16291629- } else if (num_irqs == nr_online_cpus + 1) {16301630+ } else if (num_irqs == max_irqs - 1) {16301631 trans_pcie->trans->num_rx_queues = num_irqs;16311632 trans_pcie->shared_vec_mask = IWL_SHARED_IRQ_NON_RX;16321633 } else {16331634 trans_pcie->trans->num_rx_queues = num_irqs - 1;16341635 }16361636+ WARN_ON(trans_pcie->trans->num_rx_queues > IWL_MAX_RX_HW_QUEUES);1635163716361638 trans_pcie->alloc_vecs = num_irqs;16371639 trans_pcie->msix_enabled = true;
+2-2
drivers/net/wireless/mac80211_hwsim.c
···33403340static int hwsim_dump_radio_nl(struct sk_buff *skb,33413341 struct netlink_callback *cb)33423342{33433343- int last_idx = cb->args[0];33433343+ int last_idx = cb->args[0] - 1;33443344 struct mac80211_hwsim_data *data = NULL;33453345 int res = 0;33463346 void *hdr;···33683368 last_idx = data->idx;33693369 }3370337033713371- cb->args[0] = last_idx;33713371+ cb->args[0] = last_idx + 1;3372337233733373 /* list changed, but no new element sent, set interrupted flag */33743374 if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) {
+3-4
drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
···372372373373 /*374374 * Determine IFS values375375- * - Use TXOP_BACKOFF for probe and management frames except beacons375375+ * - Use TXOP_BACKOFF for management frames except beacons376376 * - Use TXOP_SIFS for fragment bursts377377 * - Use TXOP_HTTXOP for everything else378378 *379379 * Note: rt2800 devices won't use CTS protection (if used)380380 * for frames not transmitted with TXOP_HTTXOP381381 */382382- if ((ieee80211_is_mgmt(hdr->frame_control) &&383383- !ieee80211_is_beacon(hdr->frame_control)) ||384384- (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))382382+ if (ieee80211_is_mgmt(hdr->frame_control) &&383383+ !ieee80211_is_beacon(hdr->frame_control))385384 txdesc->u.ht.txop = TXOP_BACKOFF;386385 else if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT))387386 txdesc->u.ht.txop = TXOP_SIFS;
···1264126412651265static void ext2_truncate_blocks(struct inode *inode, loff_t offset)12661266{12671267- /*12681268- * XXX: it seems like a bug here that we don't allow12691269- * IS_APPEND inode to have blocks-past-i_size trimmed off.12701270- * review and fix this.12711271- *12721272- * Also would be nice to be able to handle IO errors and such,12731273- * but that's probably too much to ask.12741274- */12751267 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||12761268 S_ISLNK(inode->i_mode)))12771269 return;12781270 if (ext2_inode_is_fast_symlink(inode))12791279- return;12801280- if (IS_APPEND(inode) || IS_IMMUTABLE(inode))12811271 return;1282127212831273 dax_sem_down_write(EXT2_I(inode));
+2-4
fs/ext2/namei.c
···4141{4242 int err = ext2_add_link(dentry, inode);4343 if (!err) {4444- unlock_new_inode(inode);4545- d_instantiate(dentry, inode);4444+ d_instantiate_new(dentry, inode);4645 return 0;4746 }4847 inode_dec_link_count(inode);···254255 if (err)255256 goto out_fail;256257257257- unlock_new_inode(inode);258258- d_instantiate(dentry, inode);258258+ d_instantiate_new(dentry, inode);259259out:260260 return err;261261
+2-4
fs/ext4/namei.c
···24112411 int err = ext4_add_entry(handle, dentry, inode);24122412 if (!err) {24132413 ext4_mark_inode_dirty(handle, inode);24142414- unlock_new_inode(inode);24152415- d_instantiate(dentry, inode);24142414+ d_instantiate_new(dentry, inode);24162415 return 0;24172416 }24182417 drop_nlink(inode);···26502651 err = ext4_mark_inode_dirty(handle, dir);26512652 if (err)26522653 goto out_clear_inode;26532653- unlock_new_inode(inode);26542654- d_instantiate(dentry, inode);26542654+ d_instantiate_new(dentry, inode);26552655 if (IS_DIRSYNC(dir))26562656 ext4_handle_sync(handle);26572657
+4-8
fs/f2fs/namei.c
···294294295295 alloc_nid_done(sbi, ino);296296297297- d_instantiate(dentry, inode);298298- unlock_new_inode(inode);297297+ d_instantiate_new(dentry, inode);299298300299 if (IS_DIRSYNC(dir))301300 f2fs_sync_fs(sbi->sb, 1);···596597 err = page_symlink(inode, disk_link.name, disk_link.len);597598598599err_out:599599- d_instantiate(dentry, inode);600600- unlock_new_inode(inode);600600+ d_instantiate_new(dentry, inode);601601602602 /*603603 * Let's flush symlink data in order to avoid broken symlink as much as···659661660662 alloc_nid_done(sbi, inode->i_ino);661663662662- d_instantiate(dentry, inode);663663- unlock_new_inode(inode);664664+ d_instantiate_new(dentry, inode);664665665666 if (IS_DIRSYNC(dir))666667 f2fs_sync_fs(sbi->sb, 1);···710713711714 alloc_nid_done(sbi, inode->i_ino);712715713713- d_instantiate(dentry, inode);714714- unlock_new_inode(inode);716716+ d_instantiate_new(dentry, inode);715717716718 if (IS_DIRSYNC(dir))717719 f2fs_sync_fs(sbi->sb, 1);
···709709 if (m->count + width >= m->size)710710 goto overflow;711711712712- if (num < 10) {713713- m->buf[m->count++] = num + '0';714714- return;715715- }716716-717712 len = num_to_str(m->buf + m->count, m->size - m->count, num, width);718713 if (!len)719714 goto overflow;
+24-6
fs/super.c
···121121 sb = container_of(shrink, struct super_block, s_shrink);122122123123 /*124124- * Don't call trylock_super as it is a potential125125- * scalability bottleneck. The counts could get updated126126- * between super_cache_count and super_cache_scan anyway.127127- * Call to super_cache_count with shrinker_rwsem held128128- * ensures the safety of call to list_lru_shrink_count() and129129- * s_op->nr_cached_objects().124124+ * We don't call trylock_super() here as it is a scalability bottleneck,125125+ * so we're exposed to partial setup state. The shrinker rwsem does not126126+ * protect filesystem operations backing list_lru_shrink_count() or127127+ * s_op->nr_cached_objects(). Counts can change between128128+ * super_cache_count and super_cache_scan, so we really don't need locks129129+ * here.130130+ *131131+ * However, if we are currently mounting the superblock, the underlying132132+ * filesystem might be in a state of partial construction and hence it133133+ * is dangerous to access it. trylock_super() uses a SB_BORN check to134134+ * avoid this situation, so do the same here. The memory barrier is135135+ * matched with the one in mount_fs() as we don't hold locks here.130136 */137137+ if (!(sb->s_flags & SB_BORN))138138+ return 0;139139+ smp_rmb();140140+131141 if (sb->s_op && sb->s_op->nr_cached_objects)132142 total_objects = sb->s_op->nr_cached_objects(sb, sc);133143···12821272 sb = root->d_sb;12831273 BUG_ON(!sb);12841274 WARN_ON(!sb->s_bdi);12751275+12761276+ /*12771277+ * Write barrier is for super_cache_count(). We place it before setting12781278+ * SB_BORN as the data dependency between the two functions is the12791279+ * superblock structure contents that we just set up, not the SB_BORN12801280+ * flag.12811281+ */12821282+ smp_wmb();12851283 sb->s_flags |= SB_BORN;1286128412871285 error = security_sb_kern_mount(sb, flags, secdata);
+3-3
fs/sysfs/mount.c
···2525{2626 struct dentry *root;2727 void *ns;2828- bool new_sb;2828+ bool new_sb = false;29293030 if (!(flags & SB_KERNMOUNT)) {3131 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))···3535 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);3636 root = kernfs_mount_ns(fs_type, flags, sysfs_root,3737 SYSFS_MAGIC, &new_sb, ns);3838- if (IS_ERR(root) || !new_sb)3838+ if (!new_sb)3939 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);4040- else if (new_sb)4040+ else if (!IS_ERR(root))4141 root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE;42424343 return root;
···142142struct bpf_insn_aux_data {143143 union {144144 enum bpf_reg_type ptr_type; /* pointer type for load/store insns */145145- struct bpf_map *map_ptr; /* pointer for call insn into lookup_elem */145145+ unsigned long map_state; /* pointer/poison value for maps */146146 s32 call_imm; /* saved imm field of call insn */147147 };148148 int ctx_field_size; /* the ctx field size for load insn, maybe 0 */149149+ int sanitize_stack_off; /* stack slot to be cleared */149150 bool seen; /* this insn was processed by the verifier */150151};151152
···5353 int (*request_update)(struct iio_buffer *buffer);54545555 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);5656- int (*set_length)(struct iio_buffer *buffer, int length);5656+ int (*set_length)(struct iio_buffer *buffer, unsigned int length);57575858 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);5959 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);···7272 */7373struct iio_buffer {7474 /** @length: Number of datums in buffer. */7575- int length;7575+ unsigned int length;76767777 /** @bytes_per_datum: Size of individual datum including timestamp. */7878- int bytes_per_datum;7878+ size_t bytes_per_datum;79798080 /**8181 * @access: Buffer access functions associated with the
+3
include/linux/memory_hotplug.h
···216216void mem_hotplug_begin(void);217217void mem_hotplug_done(void);218218219219+extern void set_zone_contiguous(struct zone *zone);220220+extern void clear_zone_contiguous(struct zone *zone);221221+219222#else /* ! CONFIG_MEMORY_HOTPLUG */220223#define pfn_to_online_page(pfn) \221224({ \
+1-11
include/linux/mlx5/driver.h
···12861286static inline const struct cpumask *12871287mlx5_get_vector_affinity_hint(struct mlx5_core_dev *dev, int vector)12881288{12891289- struct irq_desc *desc;12901290- unsigned int irq;12911291- int eqn;12921292- int err;12931293-12941294- err = mlx5_vector2eqn(dev, vector, &eqn, &irq);12951295- if (err)12961296- return NULL;12971297-12981298- desc = irq_to_desc(irq);12991299- return desc->affinity_hint;12891289+ return dev->priv.irq_info[vector].mask;13001290}1301129113021292#endif /* MLX5_DRIVER_H */
-1
include/linux/mm.h
···2109210921102110extern void zone_pcp_update(struct zone *zone);21112111extern void zone_pcp_reset(struct zone *zone);21122112-extern void setup_zone_pageset(struct zone *zone);2113211221142113/* page_alloc.c */21152114extern int min_free_kbytes;
+5-3
include/linux/node.h
···3232typedef void (*node_registration_func_t)(struct node *);33333434#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)3535-extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages);3535+extern int link_mem_sections(int nid, unsigned long start_pfn,3636+ unsigned long nr_pages, bool check_nid);3637#else3737-static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)3838+static inline int link_mem_sections(int nid, unsigned long start_pfn,3939+ unsigned long nr_pages, bool check_nid)3840{3941 return 0;4042}···5957 if (error)6058 return error;6159 /* link memory sections under this node */6262- error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages);6060+ error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages, true);6361 }64626563 return error;
+10
include/linux/nospec.h
···77#define _LINUX_NOSPEC_H88#include <asm/barrier.h>991010+struct task_struct;1111+1012/**1113 * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise1214 * @index: array element index···5755 \5856 (typeof(_i)) (_i & _mask); \5957})5858+5959+/* Speculation control prctl */6060+int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which);6161+int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,6262+ unsigned long ctrl);6363+/* Speculation control for seccomp enforced mitigation */6464+void arch_seccomp_spec_mitigate(struct task_struct *task);6565+6066#endif /* _LINUX_NOSPEC_H */
+9-1
include/linux/sched.h
···14331433#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */14341434#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */14351435#define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */14361436-14361436+#define PFA_SPEC_SSB_DISABLE 3 /* Speculative Store Bypass disabled */14371437+#define PFA_SPEC_SSB_FORCE_DISABLE 4 /* Speculative Store Bypass force disabled*/1437143814381439#define TASK_PFA_TEST(name, func) \14391440 static inline bool task_##func(struct task_struct *p) \···14581457TASK_PFA_TEST(SPREAD_SLAB, spread_slab)14591458TASK_PFA_SET(SPREAD_SLAB, spread_slab)14601459TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)14601460+14611461+TASK_PFA_TEST(SPEC_SSB_DISABLE, spec_ssb_disable)14621462+TASK_PFA_SET(SPEC_SSB_DISABLE, spec_ssb_disable)14631463+TASK_PFA_CLEAR(SPEC_SSB_DISABLE, spec_ssb_disable)14641464+14651465+TASK_PFA_TEST(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)14661466+TASK_PFA_SET(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)1461146714621468static inline void14631469current_restore_flags(unsigned long orig_flags, unsigned long flags)
···106106#define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle) /* get idle time */107107#define PPPIOCNEWUNIT _IOWR('t', 62, int) /* create new ppp unit */108108#define PPPIOCATTACH _IOW('t', 61, int) /* attach to ppp unit */109109-#define PPPIOCDETACH _IOW('t', 60, int) /* detach from ppp unit/chan */109109+#define PPPIOCDETACH _IOW('t', 60, int) /* obsolete, do not use */110110#define PPPIOCSMRRU _IOW('t', 59, int) /* set multilink MRU */111111#define PPPIOCCONNECT _IOW('t', 58, int) /* connect channel to unit */112112#define PPPIOCDISCONN _IO('t', 57) /* disconnect channel */
+12
include/uapi/linux/prctl.h
···207207# define PR_SVE_VL_LEN_MASK 0xffff208208# define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */209209210210+/* Per task speculation control */211211+#define PR_GET_SPECULATION_CTRL 52212212+#define PR_SET_SPECULATION_CTRL 53213213+/* Speculation control variants */214214+# define PR_SPEC_STORE_BYPASS 0215215+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */216216+# define PR_SPEC_NOT_AFFECTED 0217217+# define PR_SPEC_PRCTL (1UL << 0)218218+# define PR_SPEC_ENABLE (1UL << 1)219219+# define PR_SPEC_DISABLE (1UL << 2)220220+# define PR_SPEC_FORCE_DISABLE (1UL << 3)221221+210222#endif /* _LINUX_PRCTL_H */
+3-2
include/uapi/linux/seccomp.h
···1717#define SECCOMP_GET_ACTION_AVAIL 218181919/* Valid flags for SECCOMP_SET_MODE_FILTER */2020-#define SECCOMP_FILTER_FLAG_TSYNC 12121-#define SECCOMP_FILTER_FLAG_LOG 22020+#define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)2121+#define SECCOMP_FILTER_FLAG_LOG (1UL << 1)2222+#define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)22232324/*2425 * All BPF programs must return a 32-bit value.
+8
include/xen/interface/io/displif.h
···189189 *190190 *----------------------------- Connector settings ----------------------------191191 *192192+ * unique-id193193+ * Values: <string>194194+ *195195+ * After device instance initialization each connector is assigned a196196+ * unique ID, so it can be identified by the backend by this ID.197197+ * This can be UUID or such.198198+ *192199 * resolution193200 * Values: <width, uint32_t>x<height, uint32_t>194201 *···375368#define XENDISPL_FIELD_EVT_CHANNEL "evt-event-channel"376369#define XENDISPL_FIELD_RESOLUTION "resolution"377370#define XENDISPL_FIELD_BE_ALLOC "be-alloc"371371+#define XENDISPL_FIELD_UNIQUE_ID "unique-id"378372379373/*380374 ******************************************************************************
+59-19
include/xen/interface/io/kbdif.h
···5151 * corresponding entries in XenStore and puts 1 as the value of the entry.5252 * If a feature is not supported then 0 must be set or feature entry omitted.5353 *5454+ * feature-disable-keyboard5555+ * Values: <uint>5656+ *5757+ * If there is no need to expose a virtual keyboard device by the5858+ * frontend then this must be set to 1.5959+ *6060+ * feature-disable-pointer6161+ * Values: <uint>6262+ *6363+ * If there is no need to expose a virtual pointer device by the6464+ * frontend then this must be set to 1.6565+ *5466 * feature-abs-pointer5567 * Values: <uint>5668 *···7462 *7563 * Backends, which support reporting of multi-touch events7664 * should set this to 1.6565+ *6666+ * feature-raw-pointer6767+ * Values: <uint>6868+ *6969+ * Backends, which support reporting raw (unscaled) absolute coordinates7070+ * for pointer devices should set this to 1. Raw (unscaled) values have7171+ * a range of [0, 0x7fff].7272+ *7373+ *----------------------- Device Instance Parameters ------------------------7474+ *7575+ * unique-id7676+ * Values: <string>7777+ *7878+ * After device instance initialization it is assigned a unique ID,7979+ * so every instance of the frontend can be identified by the backend8080+ * by this ID. This can be UUID or such.7781 *7882 *------------------------- Pointer Device Parameters ------------------------7983 *···10375 * Values: <uint>10476 *10577 * Maximum Y coordinate (height) to be used by the frontend7878+ * while reporting input events, pixels, [0; UINT32_MAX].7979+ *8080+ *----------------------- Multi-touch Device Parameters ----------------------8181+ *8282+ * multi-touch-num-contacts8383+ * Values: <uint>8484+ *8585+ * Number of simultaneous touches reported.8686+ *8787+ * multi-touch-width8888+ * Values: <uint>8989+ *9090+ * Width of the touch area to be used by the frontend9191+ * while reporting input events, pixels, [0; UINT32_MAX].9292+ *9393+ * multi-touch-height9494+ * Values: <uint>9595+ *9696+ * Height of the touch area to be used by the frontend10697 * while reporting input events, pixels, [0; UINT32_MAX].10798 *10899 *****************************************************************************···14598 *14699 * Request backend to report multi-touch events.147100 *101101+ * request-raw-pointer102102+ * Values: <uint>103103+ *104104+ * Request backend to report raw unscaled absolute pointer coordinates.105105+ * This option is only valid if request-abs-pointer is also set.106106+ * Raw unscaled coordinates have the range [0, 0x7fff]107107+ *148108 *----------------------- Request Transport Parameters -----------------------149109 *150110 * event-channel···171117 *172118 * OBSOLETE, not recommended for use.173119 * PFN of the shared page.174174- *175175- *----------------------- Multi-touch Device Parameters -----------------------176176- *177177- * multi-touch-num-contacts178178- * Values: <uint>179179- *180180- * Number of simultaneous touches reported.181181- *182182- * multi-touch-width183183- * Values: <uint>184184- *185185- * Width of the touch area to be used by the frontend186186- * while reporting input events, pixels, [0; UINT32_MAX].187187- *188188- * multi-touch-height189189- * Values: <uint>190190- *191191- * Height of the touch area to be used by the frontend192192- * while reporting input events, pixels, [0; UINT32_MAX].193120 */194121195122/*···198163199164#define XENKBD_DRIVER_NAME "vkbd"200165166166+#define XENKBD_FIELD_FEAT_DSBL_KEYBRD "feature-disable-keyboard"167167+#define XENKBD_FIELD_FEAT_DSBL_POINTER "feature-disable-pointer"201168#define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer"169169+#define XENKBD_FIELD_FEAT_RAW_POINTER "feature-raw-pointer"202170#define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch"203171#define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer"172172+#define XENKBD_FIELD_REQ_RAW_POINTER "request-raw-pointer"204173#define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch"205174#define XENKBD_FIELD_RING_GREF "page-gref"206175#define XENKBD_FIELD_EVT_CHANNEL "event-channel"···213174#define XENKBD_FIELD_MT_WIDTH "multi-touch-width"214175#define XENKBD_FIELD_MT_HEIGHT "multi-touch-height"215176#define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts"177177+#define XENKBD_FIELD_UNIQUE_ID "unique-id"216178217179/* OBSOLETE, not recommended for use */218180#define XENKBD_FIELD_RING_REF "page-ref"
+4-6
include/xen/interface/io/sndif.h
···278278 * defined under the same device.279279 *280280 * unique-id281281- * Values: <uint32_t>281281+ * Values: <string>282282 *283283- * After stream initialization it is assigned a unique ID (within the front284284- * driver), so every stream of the frontend can be identified by the285285- * backend by this ID. This is not equal to stream-idx as the later is286286- * zero based within the device, but this index is contigous within the287287- * driver.283283+ * After stream initialization it is assigned a unique ID, so every284284+ * stream of the frontend can be identified by the backend by this ID.285285+ * This can be UUID or such.288286 *289287 *-------------------- Stream Request Transport Parameters --------------------290288 *
···1363136313641364 if (addr) {13651365 if (addr & (shmlba - 1)) {13661366- /*13671367- * Round down to the nearest multiple of shmlba.13681368- * For sane do_mmap_pgoff() parameters, avoid13691369- * round downs that trigger nil-page and MAP_FIXED.13701370- */13711371- if ((shmflg & SHM_RND) && addr >= shmlba)13721372- addr &= ~(shmlba - 1);13731373- else13661366+ if (shmflg & SHM_RND) {13671367+ addr &= ~(shmlba - 1); /* round down */13681368+13691369+ /*13701370+ * Ensure that the round-down is non-nil13711371+ * when remapping. This can happen for13721372+ * cases when addr < shmlba.13731373+ */13741374+ if (!addr && (shmflg & SHM_REMAP))13751375+ goto out;13761376+ } else13741377#ifndef __ARCH_FORCE_SHMLBA13751378 if (addr & ~PAGE_MASK)13761379#endif
+80-30
kernel/bpf/core.c
···218218 return 0;219219}220220221221-static void bpf_adj_branches(struct bpf_prog *prog, u32 pos, u32 delta)221221+static int bpf_adj_delta_to_imm(struct bpf_insn *insn, u32 pos, u32 delta,222222+ u32 curr, const bool probe_pass)222223{224224+ const s64 imm_min = S32_MIN, imm_max = S32_MAX;225225+ s64 imm = insn->imm;226226+227227+ if (curr < pos && curr + imm + 1 > pos)228228+ imm += delta;229229+ else if (curr > pos + delta && curr + imm + 1 <= pos + delta)230230+ imm -= delta;231231+ if (imm < imm_min || imm > imm_max)232232+ return -ERANGE;233233+ if (!probe_pass)234234+ insn->imm = imm;235235+ return 0;236236+}237237+238238+static int bpf_adj_delta_to_off(struct bpf_insn *insn, u32 pos, u32 delta,239239+ u32 curr, const bool probe_pass)240240+{241241+ const s32 off_min = S16_MIN, off_max = S16_MAX;242242+ s32 off = insn->off;243243+244244+ if (curr < pos && curr + off + 1 > pos)245245+ off += delta;246246+ else if (curr > pos + delta && curr + off + 1 <= pos + delta)247247+ off -= delta;248248+ if (off < off_min || off > off_max)249249+ return -ERANGE;250250+ if (!probe_pass)251251+ insn->off = off;252252+ return 0;253253+}254254+255255+static int bpf_adj_branches(struct bpf_prog *prog, u32 pos, u32 delta,256256+ const bool probe_pass)257257+{258258+ u32 i, insn_cnt = prog->len + (probe_pass ? delta : 0);223259 struct bpf_insn *insn = prog->insnsi;224224- u32 i, insn_cnt = prog->len;225225- bool pseudo_call;226226- u8 code;227227- int off;260260+ int ret = 0;228261229262 for (i = 0; i < insn_cnt; i++, insn++) {230230- code = insn->code;231231- if (BPF_CLASS(code) != BPF_JMP)232232- continue;233233- if (BPF_OP(code) == BPF_EXIT)234234- continue;235235- if (BPF_OP(code) == BPF_CALL) {236236- if (insn->src_reg == BPF_PSEUDO_CALL)237237- pseudo_call = true;238238- else239239- continue;240240- } else {241241- pseudo_call = false;263263+ u8 code;264264+265265+ /* In the probing pass we still operate on the original,266266+ * unpatched image in order to check overflows before we267267+ * do any other adjustments. Therefore skip the patchlet.268268+ */269269+ if (probe_pass && i == pos) {270270+ i += delta + 1;271271+ insn++;242272 }243243- off = pseudo_call ? insn->imm : insn->off;244244-245245- /* Adjust offset of jmps if we cross boundaries. */246246- if (i < pos && i + off + 1 > pos)247247- off += delta;248248- else if (i > pos + delta && i + off + 1 <= pos + delta)249249- off -= delta;250250-251251- if (pseudo_call)252252- insn->imm = off;253253- else254254- insn->off = off;273273+ code = insn->code;274274+ if (BPF_CLASS(code) != BPF_JMP ||275275+ BPF_OP(code) == BPF_EXIT)276276+ continue;277277+ /* Adjust offset of jmps if we cross patch boundaries. */278278+ if (BPF_OP(code) == BPF_CALL) {279279+ if (insn->src_reg != BPF_PSEUDO_CALL)280280+ continue;281281+ ret = bpf_adj_delta_to_imm(insn, pos, delta, i,282282+ probe_pass);283283+ } else {284284+ ret = bpf_adj_delta_to_off(insn, pos, delta, i,285285+ probe_pass);286286+ }287287+ if (ret)288288+ break;255289 }290290+291291+ return ret;256292}257293258294struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,259295 const struct bpf_insn *patch, u32 len)260296{261297 u32 insn_adj_cnt, insn_rest, insn_delta = len - 1;298298+ const u32 cnt_max = S16_MAX;262299 struct bpf_prog *prog_adj;263300264301 /* Since our patchlet doesn't expand the image, we're done. */···305268 }306269307270 insn_adj_cnt = prog->len + insn_delta;271271+272272+ /* Reject anything that would potentially let the insn->off273273+ * target overflow when we have excessive program expansions.274274+ * We need to probe here before we do any reallocation where275275+ * we afterwards may not fail anymore.276276+ */277277+ if (insn_adj_cnt > cnt_max &&278278+ bpf_adj_branches(prog, off, insn_delta, true))279279+ return NULL;308280309281 /* Several new instructions need to be inserted. Make room310282 * for them. Likely, there's no need for a new allocation as···340294 sizeof(*patch) * insn_rest);341295 memcpy(prog_adj->insnsi + off, patch, sizeof(*patch) * len);342296343343- bpf_adj_branches(prog_adj, off, insn_delta);297297+ /* We are guaranteed to not fail at this point, otherwise298298+ * the ship has sailed to reverse to the original state. An299299+ * overflow cannot happen at this point.300300+ */301301+ BUG_ON(bpf_adj_branches(prog_adj, off, insn_delta, false));344302345303 return prog_adj;346304}
+9-9
kernel/bpf/sockmap.c
···17031703 * we increment the refcnt. If this is the case abort with an17041704 * error.17051705 */17061706- verdict = bpf_prog_inc_not_zero(stab->bpf_verdict);17061706+ verdict = bpf_prog_inc_not_zero(verdict);17071707 if (IS_ERR(verdict))17081708 return PTR_ERR(verdict);1709170917101710- parse = bpf_prog_inc_not_zero(stab->bpf_parse);17101710+ parse = bpf_prog_inc_not_zero(parse);17111711 if (IS_ERR(parse)) {17121712 bpf_prog_put(verdict);17131713 return PTR_ERR(parse);···17151715 }1716171617171717 if (tx_msg) {17181718- tx_msg = bpf_prog_inc_not_zero(stab->bpf_tx_msg);17181718+ tx_msg = bpf_prog_inc_not_zero(tx_msg);17191719 if (IS_ERR(tx_msg)) {17201720- if (verdict)17211721- bpf_prog_put(verdict);17221722- if (parse)17201720+ if (parse && verdict) {17231721 bpf_prog_put(parse);17221722+ bpf_prog_put(verdict);17231723+ }17241724 return PTR_ERR(tx_msg);17251725 }17261726 }···18051805out_free:18061806 smap_release_sock(psock, sock);18071807out_progs:18081808- if (verdict)18091809- bpf_prog_put(verdict);18101810- if (parse)18081808+ if (parse && verdict) {18111809 bpf_prog_put(parse);18101810+ bpf_prog_put(verdict);18111811+ }18121812 if (tx_msg)18131813 bpf_prog_put(tx_msg);18141814 write_unlock_bh(&sock->sk_callback_lock);
+120-25
kernel/bpf/verifier.c
···156156#define BPF_COMPLEXITY_LIMIT_INSNS 131072157157#define BPF_COMPLEXITY_LIMIT_STACK 1024158158159159-#define BPF_MAP_PTR_POISON ((void *)0xeB9F + POISON_POINTER_DELTA)159159+#define BPF_MAP_PTR_UNPRIV 1UL160160+#define BPF_MAP_PTR_POISON ((void *)((0xeB9FUL << 1) + \161161+ POISON_POINTER_DELTA))162162+#define BPF_MAP_PTR(X) ((struct bpf_map *)((X) & ~BPF_MAP_PTR_UNPRIV))163163+164164+static bool bpf_map_ptr_poisoned(const struct bpf_insn_aux_data *aux)165165+{166166+ return BPF_MAP_PTR(aux->map_state) == BPF_MAP_PTR_POISON;167167+}168168+169169+static bool bpf_map_ptr_unpriv(const struct bpf_insn_aux_data *aux)170170+{171171+ return aux->map_state & BPF_MAP_PTR_UNPRIV;172172+}173173+174174+static void bpf_map_ptr_store(struct bpf_insn_aux_data *aux,175175+ const struct bpf_map *map, bool unpriv)176176+{177177+ BUILD_BUG_ON((unsigned long)BPF_MAP_PTR_POISON & BPF_MAP_PTR_UNPRIV);178178+ unpriv |= bpf_map_ptr_unpriv(aux);179179+ aux->map_state = (unsigned long)map |180180+ (unpriv ? BPF_MAP_PTR_UNPRIV : 0UL);181181+}160182161183struct bpf_call_arg_meta {162184 struct bpf_map *map_ptr;···1000978 */1001979static int check_stack_write(struct bpf_verifier_env *env,1002980 struct bpf_func_state *state, /* func where register points to */10031003- int off, int size, int value_regno)981981+ int off, int size, int value_regno, int insn_idx)1004982{1005983 struct bpf_func_state *cur; /* state of the current function */1006984 int i, slot = -off - 1, spi = slot / BPF_REG_SIZE, err;···10391017 state->stack[spi].spilled_ptr = cur->regs[value_regno];10401018 state->stack[spi].spilled_ptr.live |= REG_LIVE_WRITTEN;1041101910421042- for (i = 0; i < BPF_REG_SIZE; i++)10201020+ for (i = 0; i < BPF_REG_SIZE; i++) {10211021+ if (state->stack[spi].slot_type[i] == STACK_MISC &&10221022+ !env->allow_ptr_leaks) {10231023+ int *poff = &env->insn_aux_data[insn_idx].sanitize_stack_off;10241024+ int soff = (-spi - 1) * BPF_REG_SIZE;10251025+10261026+ /* detected reuse of integer stack slot with a pointer10271027+ * which means either llvm is reusing stack slot or10281028+ * an attacker is trying to exploit CVE-2018-363910291029+ * (speculative store bypass)10301030+ * Have to sanitize that slot with preemptive10311031+ * store of zero.10321032+ */10331033+ if (*poff && *poff != soff) {10341034+ /* disallow programs where single insn stores10351035+ * into two different stack slots, since verifier10361036+ * cannot sanitize them10371037+ */10381038+ verbose(env,10391039+ "insn %d cannot access two stack slots fp%d and fp%d",10401040+ insn_idx, *poff, soff);10411041+ return -EINVAL;10421042+ }10431043+ *poff = soff;10441044+ }10431045 state->stack[spi].slot_type[i] = STACK_SPILL;10461046+ }10441047 } else {10451048 u8 type = STACK_MISC;10461049···1741169417421695 if (t == BPF_WRITE)17431696 err = check_stack_write(env, state, off, size,17441744- value_regno);16971697+ value_regno, insn_idx);17451698 else17461699 err = check_stack_read(env, state, off, size,17471700 value_regno);···23802333 return 0;23812334}2382233523362336+static int23372337+record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,23382338+ int func_id, int insn_idx)23392339+{23402340+ struct bpf_insn_aux_data *aux = &env->insn_aux_data[insn_idx];23412341+23422342+ if (func_id != BPF_FUNC_tail_call &&23432343+ func_id != BPF_FUNC_map_lookup_elem)23442344+ return 0;23452345+ if (meta->map_ptr == NULL) {23462346+ verbose(env, "kernel subsystem misconfigured verifier\n");23472347+ return -EINVAL;23482348+ }23492349+23502350+ if (!BPF_MAP_PTR(aux->map_state))23512351+ bpf_map_ptr_store(aux, meta->map_ptr,23522352+ meta->map_ptr->unpriv_array);23532353+ else if (BPF_MAP_PTR(aux->map_state) != meta->map_ptr)23542354+ bpf_map_ptr_store(aux, BPF_MAP_PTR_POISON,23552355+ meta->map_ptr->unpriv_array);23562356+ return 0;23572357+}23582358+23832359static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn_idx)23842360{23852361 const struct bpf_func_proto *fn = NULL;···24572387 err = check_func_arg(env, BPF_REG_2, fn->arg2_type, &meta);24582388 if (err)24592389 return err;24602460- if (func_id == BPF_FUNC_tail_call) {24612461- if (meta.map_ptr == NULL) {24622462- verbose(env, "verifier bug\n");24632463- return -EINVAL;24642464- }24652465- env->insn_aux_data[insn_idx].map_ptr = meta.map_ptr;24662466- }24672390 err = check_func_arg(env, BPF_REG_3, fn->arg3_type, &meta);24682391 if (err)24692392 return err;···24642401 if (err)24652402 return err;24662403 err = check_func_arg(env, BPF_REG_5, fn->arg5_type, &meta);24042404+ if (err)24052405+ return err;24062406+24072407+ err = record_func_map(env, &meta, func_id, insn_idx);24672408 if (err)24682409 return err;24692410···24952428 } else if (fn->ret_type == RET_VOID) {24962429 regs[BPF_REG_0].type = NOT_INIT;24972430 } else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL) {24982498- struct bpf_insn_aux_data *insn_aux;24992499-25002431 regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;25012432 /* There is no offset yet applied, variable or fixed */25022433 mark_reg_known_zero(env, regs, BPF_REG_0);···25102445 }25112446 regs[BPF_REG_0].map_ptr = meta.map_ptr;25122447 regs[BPF_REG_0].id = ++env->id_gen;25132513- insn_aux = &env->insn_aux_data[insn_idx];25142514- if (!insn_aux->map_ptr)25152515- insn_aux->map_ptr = meta.map_ptr;25162516- else if (insn_aux->map_ptr != meta.map_ptr)25172517- insn_aux->map_ptr = BPF_MAP_PTR_POISON;25182448 } else {25192449 verbose(env, "unknown return type %d of func %s#%d\n",25202450 fn->ret_type, func_id_name(func_id), func_id);···52295169 else52305170 continue;5231517151725172+ if (type == BPF_WRITE &&51735173+ env->insn_aux_data[i + delta].sanitize_stack_off) {51745174+ struct bpf_insn patch[] = {51755175+ /* Sanitize suspicious stack slot with zero.51765176+ * There are no memory dependencies for this store,51775177+ * since it's only using frame pointer and immediate51785178+ * constant of zero51795179+ */51805180+ BPF_ST_MEM(BPF_DW, BPF_REG_FP,51815181+ env->insn_aux_data[i + delta].sanitize_stack_off,51825182+ 0),51835183+ /* the original STX instruction will immediately51845184+ * overwrite the same stack slot with appropriate value51855185+ */51865186+ *insn,51875187+ };51885188+51895189+ cnt = ARRAY_SIZE(patch);51905190+ new_prog = bpf_patch_insn_data(env, i + delta, patch, cnt);51915191+ if (!new_prog)51925192+ return -ENOMEM;51935193+51945194+ delta += cnt - 1;51955195+ env->prog = new_prog;51965196+ insn = new_prog->insnsi + i + delta;51975197+ continue;51985198+ }51995199+52325200 if (env->insn_aux_data[i + delta].ptr_type != PTR_TO_CTX)52335201 continue;52345202···55055417 struct bpf_insn *insn = prog->insnsi;55065418 const struct bpf_func_proto *fn;55075419 const int insn_cnt = prog->len;54205420+ struct bpf_insn_aux_data *aux;55085421 struct bpf_insn insn_buf[16];55095422 struct bpf_prog *new_prog;55105423 struct bpf_map *map_ptr;···55805491 insn->imm = 0;55815492 insn->code = BPF_JMP | BPF_TAIL_CALL;5582549354945494+ aux = &env->insn_aux_data[i + delta];54955495+ if (!bpf_map_ptr_unpriv(aux))54965496+ continue;54975497+55835498 /* instead of changing every JIT dealing with tail_call55845499 * emit two extra insns:55855500 * if (index >= max_entries) goto out;55865501 * index &= array->index_mask;55875502 * to avoid out-of-bounds cpu speculation55885503 */55895589- map_ptr = env->insn_aux_data[i + delta].map_ptr;55905590- if (map_ptr == BPF_MAP_PTR_POISON) {55045504+ if (bpf_map_ptr_poisoned(aux)) {55915505 verbose(env, "tail_call abusing map_ptr\n");55925506 return -EINVAL;55935507 }55945594- if (!map_ptr->unpriv_array)55955595- continue;55085508+55095509+ map_ptr = BPF_MAP_PTR(aux->map_state);55965510 insn_buf[0] = BPF_JMP_IMM(BPF_JGE, BPF_REG_3,55975511 map_ptr->max_entries, 2);55985512 insn_buf[1] = BPF_ALU32_IMM(BPF_AND, BPF_REG_3,···56195527 */56205528 if (prog->jit_requested && BITS_PER_LONG == 64 &&56215529 insn->imm == BPF_FUNC_map_lookup_elem) {56225622- map_ptr = env->insn_aux_data[i + delta].map_ptr;56235623- if (map_ptr == BPF_MAP_PTR_POISON ||56245624- !map_ptr->ops->map_gen_lookup)55305530+ aux = &env->insn_aux_data[i + delta];55315531+ if (bpf_map_ptr_poisoned(aux))55325532+ goto patch_call_imm;55335533+55345534+ map_ptr = BPF_MAP_PTR(aux->map_state);55355535+ if (!map_ptr->ops->map_gen_lookup)56255536 goto patch_call_imm;5626553756275538 cnt = map_ptr->ops->map_gen_lookup(map_ptr, insn_buf);
+2-4
kernel/kthread.c
···193193194194void kthread_park_complete(struct task_struct *k)195195{196196- complete(&to_kthread(k)->parked);196196+ complete_all(&to_kthread(k)->parked);197197}198198199199static int kthread(void *_create)···459459 if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))460460 __kthread_bind(k, kthread->cpu, TASK_PARKED);461461462462+ reinit_completion(&kthread->parked);462463 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);463464 wake_up_state(k, TASK_PARKED);464465}···483482484483 if (WARN_ON(k->flags & PF_EXITING))485484 return -ENOSYS;486486-487487- if (WARN_ON_ONCE(test_bit(KTHREAD_SHOULD_PARK, &kthread->flags)))488488- return -EBUSY;489485490486 set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);491487 if (k != current) {
+31-14
kernel/sched/core.c
···881881}882882883883#ifdef CONFIG_SMP884884+885885+static inline bool is_per_cpu_kthread(struct task_struct *p)886886+{887887+ if (!(p->flags & PF_KTHREAD))888888+ return false;889889+890890+ if (p->nr_cpus_allowed != 1)891891+ return false;892892+893893+ return true;894894+}895895+896896+/*897897+ * Per-CPU kthreads are allowed to run on !actie && online CPUs, see898898+ * __set_cpus_allowed_ptr() and select_fallback_rq().899899+ */900900+static inline bool is_cpu_allowed(struct task_struct *p, int cpu)901901+{902902+ if (!cpumask_test_cpu(cpu, &p->cpus_allowed))903903+ return false;904904+905905+ if (is_per_cpu_kthread(p))906906+ return cpu_online(cpu);907907+908908+ return cpu_active(cpu);909909+}910910+884911/*885912 * This is how migration works:886913 *···965938static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,966939 struct task_struct *p, int dest_cpu)967940{968968- if (p->flags & PF_KTHREAD) {969969- if (unlikely(!cpu_online(dest_cpu)))970970- return rq;971971- } else {972972- if (unlikely(!cpu_active(dest_cpu)))973973- return rq;974974- }975975-976941 /* Affinity changed (again). */977977- if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))942942+ if (!is_cpu_allowed(p, dest_cpu))978943 return rq;979944980945 update_rq_clock(rq);···14951476 for (;;) {14961477 /* Any allowed, online CPU? */14971478 for_each_cpu(dest_cpu, &p->cpus_allowed) {14981498- if (!(p->flags & PF_KTHREAD) && !cpu_active(dest_cpu))14791479+ if (!is_cpu_allowed(p, dest_cpu))14991480 continue;15001500- if (!cpu_online(dest_cpu))15011501- continue;14811481+15021482 goto out;15031483 }15041484···15601542 * [ this allows ->select_task() to simply return task_cpu(p) and15611543 * not worry about this generic constraint ]15621544 */15631563- if (unlikely(!cpumask_test_cpu(cpu, &p->cpus_allowed) ||15641564- !cpu_online(cpu)))15451545+ if (unlikely(!is_cpu_allowed(p, cpu)))15651546 cpu = select_fallback_rq(task_cpu(p), p);1566154715671548 return cpu;
···983983}984984985985/*986986- * See rt task throttoling, which is the only time a skip986986+ * See rt task throttling, which is the only time a skip987987 * request is cancelled.988988 */989989static inline void rq_clock_cancel_skipupdate(struct rq *rq)
···3939#include <trace/events/cma.h>40404141#include "cma.h"4242-#include "internal.h"43424443struct cma cma_areas[MAX_CMA_AREAS];4544unsigned cma_area_count;···109110 if (!cma->bitmap)110111 return -ENOMEM;111112113113+ WARN_ON_ONCE(!pfn_valid(pfn));114114+ zone = page_zone(pfn_to_page(pfn));115115+112116 do {113117 unsigned j;114118115119 base_pfn = pfn;116116- if (!pfn_valid(base_pfn))117117- goto err;118118-119119- zone = page_zone(pfn_to_page(base_pfn));120120 for (j = pageblock_nr_pages; j; --j, pfn++) {121121- if (!pfn_valid(pfn))122122- goto err;123123-121121+ WARN_ON_ONCE(!pfn_valid(pfn));124122 /*125125- * In init_cma_reserved_pageblock(), present_pages126126- * is adjusted with assumption that all pages in127127- * the pageblock come from a single zone.123123+ * alloc_contig_range requires the pfn range124124+ * specified to be in the same zone. Make this125125+ * simple by forcing the entire CMA resv range126126+ * to be in the same zone.128127 */129128 if (page_zone(pfn_to_page(pfn)) != zone)130130- goto err;129129+ goto not_in_zone;131130 }132131 init_cma_reserved_pageblock(pfn_to_page(base_pfn));133132 } while (--i);···139142140143 return 0;141144142142-err:145145+not_in_zone:143146 pr_err("CMA area %s could not be activated\n", cma->name);144147 kfree(cma->bitmap);145148 cma->count = 0;···149152static int __init cma_init_reserved_areas(void)150153{151154 int i;152152- struct zone *zone;153153- pg_data_t *pgdat;154154-155155- if (!cma_area_count)156156- return 0;157157-158158- for_each_online_pgdat(pgdat) {159159- unsigned long start_pfn = UINT_MAX, end_pfn = 0;160160-161161- zone = &pgdat->node_zones[ZONE_MOVABLE];162162-163163- /*164164- * In this case, we cannot adjust the zone range165165- * since it is now maximum node span and we don't166166- * know original zone range.167167- */168168- if (populated_zone(zone))169169- continue;170170-171171- for (i = 0; i < cma_area_count; i++) {172172- if (pfn_to_nid(cma_areas[i].base_pfn) !=173173- pgdat->node_id)174174- continue;175175-176176- start_pfn = min(start_pfn, cma_areas[i].base_pfn);177177- end_pfn = max(end_pfn, cma_areas[i].base_pfn +178178- cma_areas[i].count);179179- }180180-181181- if (!end_pfn)182182- continue;183183-184184- zone->zone_start_pfn = start_pfn;185185- zone->spanned_pages = end_pfn - start_pfn;186186- }187155188156 for (i = 0; i < cma_area_count; i++) {189157 int ret = cma_activate_area(&cma_areas[i]);···157195 return ret;158196 }159197160160- /*161161- * Reserved pages for ZONE_MOVABLE are now activated and162162- * this would change ZONE_MOVABLE's managed page counter and163163- * the other zones' present counter. We need to re-calculate164164- * various zone information that depends on this initialization.165165- */166166- build_all_zonelists(NULL);167167- for_each_populated_zone(zone) {168168- if (zone_idx(zone) == ZONE_MOVABLE) {169169- zone_pcp_reset(zone);170170- setup_zone_pageset(zone);171171- } else172172- zone_pcp_update(zone);173173-174174- set_zone_contiguous(zone);175175- }176176-177177- /*178178- * We need to re-init per zone wmark by calling179179- * init_per_zone_wmark_min() but doesn't call here because it is180180- * registered on core_initcall and it will be called later than us.181181- */182182-183198 return 0;184199}185185-pure_initcall(cma_init_reserved_areas);200200+core_initcall(cma_init_reserved_areas);186201187202/**188203 * cma_init_reserved_mem() - create custom contiguous area from reserved memory
+3-1
mm/compaction.c
···14501450 * if compaction succeeds.14511451 * For costly orders, we require low watermark instead of min for14521452 * compaction to proceed to increase its chances.14531453+ * ALLOC_CMA is used, as pages in CMA pageblocks are considered14541454+ * suitable migration targets14531455 */14541456 watermark = (order > PAGE_ALLOC_COSTLY_ORDER) ?14551457 low_wmark_pages(zone) : min_wmark_pages(zone);14561458 watermark += compact_gap(order);14571459 if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx,14581458- 0, wmark_target))14601460+ ALLOC_CMA, wmark_target))14591461 return COMPACT_SKIPPED;1460146214611463 return COMPACT_CONTINUE;
+1-1
mm/huge_memory.c
···24312431 __split_huge_page_tail(head, i, lruvec, list);24322432 /* Some pages can be beyond i_size: drop them from page cache */24332433 if (head[i].index >= end) {24342434- __ClearPageDirty(head + i);24342434+ ClearPageDirty(head + i);24352435 __delete_from_page_cache(head + i, NULL);24362436 if (IS_ENABLED(CONFIG_SHMEM) && PageSwapBacked(head))24372437 shmem_uncharge(head->mapping->host, 1);
+1-3
mm/internal.h
···168168 gfp_t gfp_flags);169169extern int user_min_free_kbytes;170170171171-extern void set_zone_contiguous(struct zone *zone);172172-extern void clear_zone_contiguous(struct zone *zone);173173-174171#if defined CONFIG_COMPACTION || defined CONFIG_CMA175172176173/*···495498#define ALLOC_HARDER 0x10 /* try to alloc harder */496499#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */497500#define ALLOC_CPUSET 0x40 /* check for correct cpuset */501501+#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */498502499503enum ttu_flags;500504struct tlbflush_unmap_batch;
+63-3
mm/kasan/kasan.c
···792792DEFINE_ASAN_SET_SHADOW(f8);793793794794#ifdef CONFIG_MEMORY_HOTPLUG795795+static bool shadow_mapped(unsigned long addr)796796+{797797+ pgd_t *pgd = pgd_offset_k(addr);798798+ p4d_t *p4d;799799+ pud_t *pud;800800+ pmd_t *pmd;801801+ pte_t *pte;802802+803803+ if (pgd_none(*pgd))804804+ return false;805805+ p4d = p4d_offset(pgd, addr);806806+ if (p4d_none(*p4d))807807+ return false;808808+ pud = pud_offset(p4d, addr);809809+ if (pud_none(*pud))810810+ return false;811811+812812+ /*813813+ * We can't use pud_large() or pud_huge(), the first one is814814+ * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse815815+ * pud_bad(), if pud is bad then it's bad because it's huge.816816+ */817817+ if (pud_bad(*pud))818818+ return true;819819+ pmd = pmd_offset(pud, addr);820820+ if (pmd_none(*pmd))821821+ return false;822822+823823+ if (pmd_bad(*pmd))824824+ return true;825825+ pte = pte_offset_kernel(pmd, addr);826826+ return !pte_none(*pte);827827+}828828+795829static int __meminit kasan_mem_notifier(struct notifier_block *nb,796830 unsigned long action, void *data)797831{···847813 case MEM_GOING_ONLINE: {848814 void *ret;849815816816+ /*817817+ * If shadow is mapped already than it must have been mapped818818+ * during the boot. This could happen if we onlining previously819819+ * offlined memory.820820+ */821821+ if (shadow_mapped(shadow_start))822822+ return NOTIFY_OK;823823+850824 ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start,851825 shadow_end, GFP_KERNEL,852826 PAGE_KERNEL, VM_NO_GUARD,···866824 kmemleak_ignore(ret);867825 return NOTIFY_OK;868826 }869869- case MEM_OFFLINE:870870- vfree((void *)shadow_start);827827+ case MEM_CANCEL_ONLINE:828828+ case MEM_OFFLINE: {829829+ struct vm_struct *vm;830830+831831+ /*832832+ * shadow_start was either mapped during boot by kasan_init()833833+ * or during memory online by __vmalloc_node_range().834834+ * In the latter case we can use vfree() to free shadow.835835+ * Non-NULL result of the find_vm_area() will tell us if836836+ * that was the second case.837837+ *838838+ * Currently it's not possible to free shadow mapped839839+ * during boot by kasan_init(). It's because the code840840+ * to do that hasn't been written yet. So we'll just841841+ * leak the memory.842842+ */843843+ vm = find_vm_area((void *)shadow_start);844844+ if (vm)845845+ vfree((void *)shadow_start);846846+ }871847 }872848873849 return NOTIFY_OK;···898838 return 0;899839}900840901901-module_init(kasan_memhotplug_init);841841+core_initcall(kasan_memhotplug_init);902842#endif
+1-1
mm/memory_hotplug.c
···11581158 * nodes have to go through register_node.11591159 * TODO clean up this mess.11601160 */11611161- ret = link_mem_sections(nid, start_pfn, nr_pages);11611161+ ret = link_mem_sections(nid, start_pfn, nr_pages, false);11621162register_fail:11631163 /*11641164 * If sysfs file of new node can't create, cpu on the node
+40-59
mm/page_alloc.c
···17431743}1744174417451745#ifdef CONFIG_CMA17461746-static void __init adjust_present_page_count(struct page *page, long count)17471747-{17481748- struct zone *zone = page_zone(page);17491749-17501750- /* We don't need to hold a lock since it is boot-up process */17511751- zone->present_pages += count;17521752-}17531753-17541746/* Free whole pageblock and set its migration type to MIGRATE_CMA. */17551747void __init init_cma_reserved_pageblock(struct page *page)17561748{17571749 unsigned i = pageblock_nr_pages;17581758- unsigned long pfn = page_to_pfn(page);17591750 struct page *p = page;17601760- int nid = page_to_nid(page);17611761-17621762- /*17631763- * ZONE_MOVABLE will steal present pages from other zones by17641764- * changing page links so page_zone() is changed. Before that,17651765- * we need to adjust previous zone's page count first.17661766- */17671767- adjust_present_page_count(page, -pageblock_nr_pages);1768175117691752 do {17701753 __ClearPageReserved(p);17711754 set_page_count(p, 0);17721772-17731773- /* Steal pages from other zones */17741774- set_page_links(p, ZONE_MOVABLE, nid, pfn);17751775- } while (++p, ++pfn, --i);17761776-17771777- adjust_present_page_count(page, pageblock_nr_pages);17551755+ } while (++p, --i);1778175617791757 set_pageblock_migratetype(page, MIGRATE_CMA);17801758···28672889 * exists.28682890 */28692891 watermark = min_wmark_pages(zone) + (1UL << order);28702870- if (!zone_watermark_ok(zone, 0, watermark, 0, 0))28922892+ if (!zone_watermark_ok(zone, 0, watermark, 0, ALLOC_CMA))28712893 return 0;2872289428732895 __mod_zone_freepage_state(zone, -(1UL << order), mt);···31433165 }314431663145316731683168+#ifdef CONFIG_CMA31693169+ /* If allocation can't use CMA areas don't use free CMA pages */31703170+ if (!(alloc_flags & ALLOC_CMA))31713171+ free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES);31723172+#endif31733173+31463174 /*31473175 * Check watermarks for an order-0 allocation request. If these31483176 * are not met, then a high-order request also cannot go ahead···31753191 }3176319231773193#ifdef CONFIG_CMA31783178- if (!list_empty(&area->free_list[MIGRATE_CMA]))31943194+ if ((alloc_flags & ALLOC_CMA) &&31953195+ !list_empty(&area->free_list[MIGRATE_CMA])) {31793196 return true;31973197+ }31803198#endif31813199 if (alloc_harder &&31823200 !list_empty(&area->free_list[MIGRATE_HIGHATOMIC]))···31983212 unsigned long mark, int classzone_idx, unsigned int alloc_flags)31993213{32003214 long free_pages = zone_page_state(z, NR_FREE_PAGES);32153215+ long cma_pages = 0;32163216+32173217+#ifdef CONFIG_CMA32183218+ /* If allocation can't use CMA areas don't use free CMA pages */32193219+ if (!(alloc_flags & ALLOC_CMA))32203220+ cma_pages = zone_page_state(z, NR_FREE_CMA_PAGES);32213221+#endif3201322232023223 /*32033224 * Fast check for order-0 only. If this fails then the reserves···32133220 * the caller is !atomic then it'll uselessly search the free32143221 * list. That corner case is then slower but it is harmless.32153222 */32163216- if (!order && free_pages > mark + z->lowmem_reserve[classzone_idx])32233223+ if (!order && (free_pages - cma_pages) > mark + z->lowmem_reserve[classzone_idx])32173224 return true;3218322532193226 return __zone_watermark_ok(z, order, mark, classzone_idx, alloc_flags,···38493856 } else if (unlikely(rt_task(current)) && !in_interrupt())38503857 alloc_flags |= ALLOC_HARDER;3851385838593859+#ifdef CONFIG_CMA38603860+ if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE)38613861+ alloc_flags |= ALLOC_CMA;38623862+#endif38523863 return alloc_flags;38533864}38543865···4318432143194322 if (should_fail_alloc_page(gfp_mask, order))43204323 return false;43244324+43254325+ if (IS_ENABLED(CONFIG_CMA) && ac->migratetype == MIGRATE_MOVABLE)43264326+ *alloc_flags |= ALLOC_CMA;4321432743224328 return true;43234329}···62046204{62056205 enum zone_type j;62066206 int nid = pgdat->node_id;62076207- unsigned long node_end_pfn = 0;6208620762096208 pgdat_resize_init(pgdat);62106209#ifdef CONFIG_NUMA_BALANCING···62316232 struct zone *zone = pgdat->node_zones + j;62326233 unsigned long size, realsize, freesize, memmap_pages;62336234 unsigned long zone_start_pfn = zone->zone_start_pfn;62346234- unsigned long movable_size = 0;6235623562366236 size = zone->spanned_pages;62376237 realsize = freesize = zone->present_pages;62386238- if (zone_end_pfn(zone) > node_end_pfn)62396239- node_end_pfn = zone_end_pfn(zone);62406240-6241623862426239 /*62436240 * Adjust freesize so that it accounts for how much memory···62826287 zone_seqlock_init(zone);62836288 zone_pcp_init(zone);6284628962856285- /*62866286- * The size of the CMA area is unknown now so we need to62876287- * prepare the memory for the usemap at maximum.62886288- */62896289- if (IS_ENABLED(CONFIG_CMA) && j == ZONE_MOVABLE &&62906290- pgdat->node_spanned_pages) {62916291- movable_size = node_end_pfn - pgdat->node_start_pfn;62926292- }62936293-62946294- if (!size && !movable_size)62906290+ if (!size)62956291 continue;6296629262976293 set_pageblock_order();62986298- if (movable_size) {62996299- zone->zone_start_pfn = pgdat->node_start_pfn;63006300- zone->spanned_pages = movable_size;63016301- setup_usemap(pgdat, zone,63026302- pgdat->node_start_pfn, movable_size);63036303- init_currently_empty_zone(zone,63046304- pgdat->node_start_pfn, movable_size);63056305- } else {63066306- setup_usemap(pgdat, zone, zone_start_pfn, size);63076307- init_currently_empty_zone(zone, zone_start_pfn, size);63086308- }62946294+ setup_usemap(pgdat, zone, zone_start_pfn, size);62956295+ init_currently_empty_zone(zone, zone_start_pfn, size);63096296 memmap_init(size, nid, j, zone_start_pfn);63106297 }63116298}···75987621 unsigned long pfn, iter, found;7599762276007623 /*76017601- * For avoiding noise data, lru_add_drain_all() should be called76027602- * If ZONE_MOVABLE, the zone never contains unmovable pages76247624+ * TODO we could make this much more efficient by not checking every76257625+ * page in the range if we know all of them are in MOVABLE_ZONE and76267626+ * that the movable zone guarantees that pages are migratable but76277627+ * the later is not the case right now unfortunatelly. E.g. movablecore76287628+ * can still lead to having bootmem allocations in zone_movable.76037629 */76047604- if (zone_idx(zone) == ZONE_MOVABLE)76057605- return false;7606763076077631 /*76087632 * CMA allocations (alloc_contig_range) really need to mark isolate···76247646 page = pfn_to_page(check);7625764776267648 if (PageReserved(page))76277627- return true;76497649+ goto unmovable;7628765076297651 /*76307652 * Hugepages are not in LRU lists, but they're movable.···76747696 * page at boot.76757697 */76767698 if (found > count)76777677- return true;76997699+ goto unmovable;76787700 }76797701 return false;77027702+unmovable:77037703+ WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE);77047704+ return true;76807705}7681770676827707bool is_pageblock_removable_nolock(struct page *page)···79327951}79337952#endif7934795379357935-#if defined CONFIG_MEMORY_HOTPLUG || defined CONFIG_CMA79547954+#ifdef CONFIG_MEMORY_HOTPLUG79367955/*79377956 * The zone indicated has a new number of managed_pages; batch sizes and percpu79387957 * page high values need to be recalulated.
···862862 struct batadv_orig_node_vlan *vlan;863863 u8 *tt_change_ptr;864864865865- rcu_read_lock();865865+ spin_lock_bh(&orig_node->vlan_list_lock);866866 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {867867 num_vlan++;868868 num_entries += atomic_read(&vlan->tt.num_entries);···900900 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;901901902902out:903903- rcu_read_unlock();903903+ spin_unlock_bh(&orig_node->vlan_list_lock);904904 return tvlv_len;905905}906906···931931 struct batadv_tvlv_tt_vlan_data *tt_vlan;932932 struct batadv_softif_vlan *vlan;933933 u16 num_vlan = 0;934934- u16 num_entries = 0;934934+ u16 vlan_entries = 0;935935+ u16 total_entries = 0;935936 u16 tvlv_len;936937 u8 *tt_change_ptr;937938 int change_offset;938939939939- rcu_read_lock();940940+ spin_lock_bh(&bat_priv->softif_vlan_list_lock);940941 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {942942+ vlan_entries = atomic_read(&vlan->tt.num_entries);943943+ if (vlan_entries < 1)944944+ continue;945945+941946 num_vlan++;942942- num_entries += atomic_read(&vlan->tt.num_entries);947947+ total_entries += vlan_entries;943948 }944949945950 change_offset = sizeof(**tt_data);···952947953948 /* if tt_len is negative, allocate the space needed by the full table */954949 if (*tt_len < 0)955955- *tt_len = batadv_tt_len(num_entries);950950+ *tt_len = batadv_tt_len(total_entries);956951957952 tvlv_len = *tt_len;958953 tvlv_len += change_offset;···969964970965 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);971966 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {967967+ vlan_entries = atomic_read(&vlan->tt.num_entries);968968+ if (vlan_entries < 1)969969+ continue;970970+972971 tt_vlan->vid = htons(vlan->vid);973972 tt_vlan->crc = htonl(vlan->tt.crc);974973···983974 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;984975985976out:986986- rcu_read_unlock();977977+ spin_unlock_bh(&bat_priv->softif_vlan_list_lock);987978 return tvlv_len;988979}989980···15471538 * handled by a given originator15481539 * @entry: the TT global entry to check15491540 * @orig_node: the originator to search in the list15411541+ * @flags: a pointer to store TT flags for the given @entry received15421542+ * from @orig_node15501543 *15511544 * find out if an orig_node is already in the list of a tt_global_entry.15521545 *···15561545 */15571546static bool15581547batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,15591559- const struct batadv_orig_node *orig_node)15481548+ const struct batadv_orig_node *orig_node,15491549+ u8 *flags)15601550{15611551 struct batadv_tt_orig_list_entry *orig_entry;15621552 bool found = false;···15651553 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);15661554 if (orig_entry) {15671555 found = true;15561556+15571557+ if (flags)15581558+ *flags = orig_entry->flags;15591559+15681560 batadv_tt_orig_list_entry_put(orig_entry);15691561 }15701562···17471731 if (!(common->flags & BATADV_TT_CLIENT_TEMP))17481732 goto out;17491733 if (batadv_tt_global_entry_has_orig(tt_global_entry,17501750- orig_node))17341734+ orig_node, NULL))17511735 goto out_remove;17521736 batadv_tt_global_del_orig_list(tt_global_entry);17531737 goto add_orig_entry;···28962880}2897288128982882/**28992899- * batadv_tt_local_valid() - verify that given tt entry is a valid one28832883+ * batadv_tt_local_valid() - verify local tt entry and get flags29002884 * @entry_ptr: to be checked local tt entry29012885 * @data_ptr: not used but definition required to satisfy the callback prototype28862886+ * @flags: a pointer to store TT flags for this client to28872887+ *28882888+ * Checks the validity of the given local TT entry. If it is, then the provided28892889+ * flags pointer is updated.29022890 *29032891 * Return: true if the entry is a valid, false otherwise.29042892 */29052905-static bool batadv_tt_local_valid(const void *entry_ptr, const void *data_ptr)28932893+static bool batadv_tt_local_valid(const void *entry_ptr,28942894+ const void *data_ptr,28952895+ u8 *flags)29062896{29072897 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;2908289829092899 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)29102900 return false;29012901+29022902+ if (flags)29032903+ *flags = tt_common_entry->flags;29042904+29112905 return true;29122906}2913290729082908+/**29092909+ * batadv_tt_global_valid() - verify global tt entry and get flags29102910+ * @entry_ptr: to be checked global tt entry29112911+ * @data_ptr: an orig_node object (may be NULL)29122912+ * @flags: a pointer to store TT flags for this client to29132913+ *29142914+ * Checks the validity of the given global TT entry. If it is, then the provided29152915+ * flags pointer is updated either with the common (summed) TT flags if data_ptr29162916+ * is NULL or the specific, per originator TT flags otherwise.29172917+ *29182918+ * Return: true if the entry is a valid, false otherwise.29192919+ */29142920static bool batadv_tt_global_valid(const void *entry_ptr,29152915- const void *data_ptr)29212921+ const void *data_ptr,29222922+ u8 *flags)29162923{29172924 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;29182925 const struct batadv_tt_global_entry *tt_global_entry;···29492910 struct batadv_tt_global_entry,29502911 common);2951291229522952- return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node);29132913+ return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node,29142914+ flags);29532915}2954291629552917/**···29602920 * @hash: hash table containing the tt entries29612921 * @tt_len: expected tvlv tt data buffer length in number of bytes29622922 * @tvlv_buff: pointer to the buffer to fill with the TT data29632963- * @valid_cb: function to filter tt change entries29232923+ * @valid_cb: function to filter tt change entries and to return TT flags29642924 * @cb_data: data passed to the filter function as argument29252925+ *29262926+ * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb29272927+ * is not provided then this becomes a no-op.29652928 */29662929static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,29672930 struct batadv_hashtable *hash,29682931 void *tvlv_buff, u16 tt_len,29692932 bool (*valid_cb)(const void *,29702970- const void *),29332933+ const void *,29342934+ u8 *flags),29712935 void *cb_data)29722936{29732937 struct batadv_tt_common_entry *tt_common_entry;29742938 struct batadv_tvlv_tt_change *tt_change;29752939 struct hlist_head *head;29762940 u16 tt_tot, tt_num_entries = 0;29412941+ u8 flags;29422942+ bool ret;29772943 u32 i;2978294429792945 tt_tot = batadv_tt_entries(tt_len);29802946 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff;29472947+29482948+ if (!valid_cb)29492949+ return;2981295029822951 rcu_read_lock();29832952 for (i = 0; i < hash->size; i++) {···29972948 if (tt_tot == tt_num_entries)29982949 break;2999295030003000- if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data)))29512951+ ret = valid_cb(tt_common_entry, cb_data, &flags);29522952+ if (!ret)30012953 continue;3002295430032955 ether_addr_copy(tt_change->addr, tt_common_entry->addr);30043004- tt_change->flags = tt_common_entry->flags;29562956+ tt_change->flags = flags;30052957 tt_change->vid = htons(tt_common_entry->vid);30062958 memset(tt_change->reserved, 0,30072959 sizeof(tt_change->reserved));
+2-2
net/bridge/netfilter/ebt_stp.c
···161161 /* Make sure the match only receives stp frames */162162 if (!par->nft_compat &&163163 (!ether_addr_equal(e->destmac, eth_stp_addr) ||164164- !is_broadcast_ether_addr(e->destmsk) ||165165- !(e->bitmask & EBT_DESTMAC)))164164+ !(e->bitmask & EBT_DESTMAC) ||165165+ !is_broadcast_ether_addr(e->destmsk)))166166 return -EINVAL;167167168168 return 0;
+2-1
net/bridge/netfilter/ebtables.c
···19541954 int off, pad = 0;19551955 unsigned int size_kern, match_size = mwt->match_size;1956195619571957- strlcpy(name, mwt->u.name, sizeof(name));19571957+ if (strscpy(name, mwt->u.name, sizeof(name)) < 0)19581958+ return -EINVAL;1958195919591960 if (state->buf_kern_start)19601961 dst = state->buf_kern_start + state->buf_kern_offset;
···10451045 if (copy > length)10461046 copy = length;1047104710481048- if (!(rt->dst.dev->features&NETIF_F_SG)) {10481048+ if (!(rt->dst.dev->features&NETIF_F_SG) &&10491049+ skb_tailroom(skb) >= copy) {10491050 unsigned int off;1050105110511052 off = skb->len;
-2
net/ipv4/ip_sockglue.c
···505505 int err;506506 int copied;507507508508- WARN_ON_ONCE(sk->sk_family == AF_INET6);509509-510508 err = -EAGAIN;511509 skb = sock_dequeue_err_skb(sk);512510 if (!skb)
+4-4
net/ipv4/ip_tunnel.c
···328328329329 if (tdev) {330330 hlen = tdev->hard_header_len + tdev->needed_headroom;331331- mtu = tdev->mtu;331331+ mtu = min(tdev->mtu, IP_MAX_MTU);332332 }333333334334 dev->needed_headroom = t_hlen + hlen;···362362 nt = netdev_priv(dev);363363 t_hlen = nt->hlen + sizeof(struct iphdr);364364 dev->min_mtu = ETH_MIN_MTU;365365- dev->max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen;365365+ dev->max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;366366 ip_tunnel_add(itn, nt);367367 return nt;368368···930930{931931 struct ip_tunnel *tunnel = netdev_priv(dev);932932 int t_hlen = tunnel->hlen + sizeof(struct iphdr);933933- int max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen;933933+ int max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;934934935935 if (new_mtu < ETH_MIN_MTU)936936 return -EINVAL;···1107110711081108 mtu = ip_tunnel_bind_dev(dev);11091109 if (tb[IFLA_MTU]) {11101110- unsigned int max = 0xfff8 - dev->hard_header_len - nt->hlen;11101110+ unsigned int max = IP_MAX_MTU - dev->hard_header_len - nt->hlen;1111111111121112 mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU,11131113 (unsigned int)(max - sizeof(struct iphdr)));
···15031503 if (copy > length)15041504 copy = length;1505150515061506- if (!(rt->dst.dev->features&NETIF_F_SG)) {15061506+ if (!(rt->dst.dev->features&NETIF_F_SG) &&15071507+ skb_tailroom(skb) >= copy) {15071508 unsigned int off;1508150915091510 off = skb->len;
···585585EXPORT_SYMBOL(nf_nat_decode_session_hook);586586#endif587587588588-static void __net_init __netfilter_net_init(struct nf_hook_entries **e, int max)588588+static void __net_init589589+__netfilter_net_init(struct nf_hook_entries __rcu **e, int max)589590{590591 int h;591592
+6-11
net/netfilter/ipvs/ip_vs_conn.c
···232232static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)233233{234234 unsigned int hash;235235- bool ret;235235+ bool ret = false;236236+237237+ if (cp->flags & IP_VS_CONN_F_ONE_PACKET)238238+ return refcount_dec_if_one(&cp->refcnt);236239237240 hash = ip_vs_conn_hashkey_conn(cp);238241···243240 spin_lock(&cp->lock);244241245242 if (cp->flags & IP_VS_CONN_F_HASHED) {246246- ret = false;247243 /* Decrease refcnt and unlink conn only if we are last user */248244 if (refcount_dec_if_one(&cp->refcnt)) {249245 hlist_del_rcu(&cp->c_list);250246 cp->flags &= ~IP_VS_CONN_F_HASHED;251247 ret = true;252248 }253253- } else254254- ret = refcount_read(&cp->refcnt) ? false : true;249249+ }255250256251 spin_unlock(&cp->lock);257252 ct_write_unlock_bh(hash);···455454}456455EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto);457456458458-static void __ip_vs_conn_put_notimer(struct ip_vs_conn *cp)459459-{460460- __ip_vs_conn_put(cp);461461- ip_vs_conn_expire(&cp->timer);462462-}463463-464457/*465458 * Put back the conn and restart its timer with its timeout466459 */···473478 (refcount_read(&cp->refcnt) == 1) &&474479 !timer_pending(&cp->timer))475480 /* expire connection immediately */476476- __ip_vs_conn_put_notimer(cp);481481+ ip_vs_conn_expire(&cp->timer);477482 else478483 __ip_vs_conn_put_timer(cp);479484}
···183183 struct xt_match *m;184184 int err = -ENOENT;185185186186+ if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)187187+ return ERR_PTR(-EINVAL);188188+186189 mutex_lock(&xt[af].mutex);187190 list_for_each_entry(m, &xt[af].match, list) {188191 if (strcmp(m->name, name) == 0) {···231228{232229 struct xt_target *t;233230 int err = -ENOENT;231231+232232+ if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)233233+ return ERR_PTR(-EINVAL);234234235235 mutex_lock(&xt[af].mutex);236236 list_for_each_entry(t, &xt[af].target, list) {
+3-1
net/packet/af_packet.c
···29032903 if (skb == NULL)29042904 goto out_unlock;2905290529062906- skb_set_network_header(skb, reserve);29062906+ skb_reset_network_header(skb);2907290729082908 err = -EINVAL;29092909 if (sock->type == SOCK_DGRAM) {29102910 offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);29112911 if (unlikely(offset < 0))29122912 goto out_free;29132913+ } else if (reserve) {29142914+ skb_reserve(skb, -reserve);29132915 }2914291629152917 /* Returns -EFAULT on error */
+2
net/sched/act_vlan.c
···161161 case htons(ETH_P_8021AD):162162 break;163163 default:164164+ if (exists)165165+ tcf_idr_release(*a, bind);164166 return -EPROTONOSUPPORT;165167 }166168 } else {
+1-1
net/sched/cls_api.c
···15881588 return ret;15891589 ok_count = ret;1590159015911591- if (!exts)15911591+ if (!exts || ok_count)15921592 return ok_count;15931593 ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop);15941594 if (ret < 0)
+1-1
net/sched/cls_flower.c
···977977 return 0;978978979979errout_idr:980980- if (fnew->handle)980980+ if (!fold)981981 idr_remove(&head->handle_idr, fnew->handle);982982errout:983983 tcf_exts_destroy(&fnew->exts);
+3-2
net/sched/sch_red.c
···222222 extack);223223 if (IS_ERR(child))224224 return PTR_ERR(child);225225+226226+ /* child is fifo, no need to check for noop_qdisc */227227+ qdisc_hash_add(child, true);225228 }226229227227- if (child != &noop_qdisc)228228- qdisc_hash_add(child, true);229230 sch_tree_lock(sch);230231 q->flags = ctl->flags;231232 q->limit = ctl->limit;
+3-2
net/sched/sch_tbf.c
···383383 err = PTR_ERR(child);384384 goto done;385385 }386386+387387+ /* child is fifo, no need to check for noop_qdisc */388388+ qdisc_hash_add(child, true);386389 }387390388391 sch_tree_lock(sch);···394391 q->qdisc->qstats.backlog);395392 qdisc_destroy(q->qdisc);396393 q->qdisc = child;397397- if (child != &noop_qdisc)398398- qdisc_hash_add(child, true);399394 }400395 q->limit = qopt->limit;401396 if (tb[TCA_TBF_PBURST])
···50415041 $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;50425042 $tmp_stmt =~ s/\#+\s*$arg\b//g;50435043 $tmp_stmt =~ s/\b$arg\s*\#\#//g;50445044- my $use_cnt = $tmp_stmt =~ s/\b$arg\b//g;50445044+ my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;50455045 if ($use_cnt > 1) {50465046 CHK("MACRO_ARG_REUSE",50475047 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
+16-4
security/selinux/hooks.c
···15681568 /* Called from d_instantiate or d_splice_alias. */15691569 dentry = dget(opt_dentry);15701570 } else {15711571- /* Called from selinux_complete_init, try to find a dentry. */15711571+ /*15721572+ * Called from selinux_complete_init, try to find a dentry.15731573+ * Some filesystems really want a connected one, so try15741574+ * that first. We could split SECURITY_FS_USE_XATTR in15751575+ * two, depending upon that...15761576+ */15721577 dentry = d_find_alias(inode);15781578+ if (!dentry)15791579+ dentry = d_find_any_alias(inode);15731580 }15741581 if (!dentry) {15751582 /*···16811674 if ((sbsec->flags & SE_SBGENFS) && !S_ISLNK(inode->i_mode)) {16821675 /* We must have a dentry to determine the label on16831676 * procfs inodes */16841684- if (opt_dentry)16771677+ if (opt_dentry) {16851678 /* Called from d_instantiate or16861679 * d_splice_alias. */16871680 dentry = dget(opt_dentry);16881688- else16811681+ } else {16891682 /* Called from selinux_complete_init, try to16901690- * find a dentry. */16831683+ * find a dentry. Some filesystems really want16841684+ * a connected one, so try that first.16851685+ */16911686 dentry = d_find_alias(inode);16871687+ if (!dentry)16881688+ dentry = d_find_any_alias(inode);16891689+ }16921690 /*16931691 * This can be hit on boot when a file is accessed16941692 * before the policy is loaded. When we load policy we
···111111A structure defining the number of CPUs.112112113113struct nr_cpus {114114- uint32_t nr_cpus_online;115114 uint32_t nr_cpus_available; /* CPUs not yet onlined */115115+ uint32_t nr_cpus_online;116116};117117118118 HEADER_CPUDESC = 8,···153153 HEADER_CPU_TOPOLOGY = 13,154154155155String lists defining the core and CPU threads topology.156156+The string lists are followed by a variable length array157157+which contains core_id and socket_id of each cpu.158158+The number of entries can be determined by the size of the159159+section minus the sizes of both string lists.156160157161struct {158162 struct perf_header_string_list cores; /* Variable length */159163 struct perf_header_string_list threads; /* Variable length */164164+ struct {165165+ uint32_t core_id;166166+ uint32_t socket_id;167167+ } cpus[nr]; /* Variable length records */160168};161169162170Example:
+24-6
tools/perf/tests/topology.c
···7070 session = perf_session__new(&data, false, NULL);7171 TEST_ASSERT_VAL("can't get session", session);72727373+ /* On platforms with large numbers of CPUs process_cpu_topology()7474+ * might issue an error while reading the perf.data file section7575+ * HEADER_CPU_TOPOLOGY and the cpu_topology_map pointed to by member7676+ * cpu is a NULL pointer.7777+ * Example: On s3907878+ * CPU 0 is on core_id 0 and physical_package_id 67979+ * CPU 1 is on core_id 1 and physical_package_id 38080+ *8181+ * Core_id and physical_package_id are platform and architecture8282+ * dependend and might have higher numbers than the CPU id.8383+ * This actually depends on the configuration.8484+ *8585+ * In this case process_cpu_topology() prints error message:8686+ * "socket_id number is too big. You may need to upgrade the8787+ * perf tool."8888+ *8989+ * This is the reason why this test might be skipped.9090+ */9191+ if (!session->header.env.cpu)9292+ return TEST_SKIP;9393+7394 for (i = 0; i < session->header.env.nr_cpus_avail; i++) {7495 if (!cpu_map__has(map, i))7596 continue;···11695{11796 char path[PATH_MAX];11897 struct cpu_map *map;119119- int ret = -1;9898+ int ret = TEST_FAIL;12099121100 TEST_ASSERT_VAL("can't get templ file", !get_temp(path));122101···131110 goto free_path;132111 }133112134134- if (check_cpu_topology(path, map))135135- goto free_map;136136- ret = 0;137137-138138-free_map:113113+ ret = check_cpu_topology(path, map);139114 cpu_map__put(map);115115+140116free_path:141117 unlink(path);142118 return ret;
+3-3
tools/perf/util/bpf-loader.c
···6666 }67676868 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);6969- if (IS_ERR(obj)) {6969+ if (IS_ERR_OR_NULL(obj)) {7070 pr_debug("bpf: failed to load buffer\n");7171 return ERR_PTR(-EINVAL);7272 }···102102 pr_debug("bpf: successfull builtin compilation\n");103103 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);104104105105- if (!IS_ERR(obj) && llvm_param.dump_obj)105105+ if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)106106 llvm__dump_obj(filename, obj_buf, obj_buf_sz);107107108108 free(obj_buf);109109 } else110110 obj = bpf_object__open(filename);111111112112- if (IS_ERR(obj)) {112112+ if (IS_ERR_OR_NULL(obj)) {113113 pr_debug("bpf: failed to load %s\n", filename);114114 return obj;115115 }
+10-2
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
···9696 /* Nothing to do, might as well just return */9797 if (decoder->packet_count == 0)9898 return 0;9999+ /*100100+ * The queueing process in function cs_etm_decoder__buffer_packet()101101+ * increments the tail *before* using it. This is somewhat counter102102+ * intuitive but it has the advantage of centralizing tail management103103+ * at a single location. Because of that we need to follow the same104104+ * heuristic with the head, i.e we increment it before using its105105+ * value. Otherwise the first element of the packet queue is not106106+ * used.107107+ */108108+ decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1);99109100110 *packet = decoder->packet_buffer[decoder->head];101101-102102- decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1);103111104112 decoder->packet_count--;105113
+1
tools/perf/util/evsel.h
···127127 bool precise_max;128128 bool ignore_missing_thread;129129 bool forced_leader;130130+ bool use_uncore_alias;130131 /* parse modifier helper */131132 int exclude_GH;132133 int nr_members;
+127-3
tools/perf/util/parse-events.c
···1219121912201220int parse_events_add_pmu(struct parse_events_state *parse_state,12211221 struct list_head *list, char *name,12221222- struct list_head *head_config, bool auto_merge_stats)12221222+ struct list_head *head_config,12231223+ bool auto_merge_stats,12241224+ bool use_alias)12231225{12241226 struct perf_event_attr attr;12251227 struct perf_pmu_info info;12261228 struct perf_pmu *pmu;12271229 struct perf_evsel *evsel;12281230 struct parse_events_error *err = parse_state->error;12311231+ bool use_uncore_alias;12291232 LIST_HEAD(config_terms);1230123312311234 pmu = perf_pmu__find(name);···12471244 memset(&attr, 0, sizeof(attr));12481245 }1249124612471247+ use_uncore_alias = (pmu->is_uncore && use_alias);12481248+12501249 if (!head_config) {12511250 attr.type = pmu->type;12521251 evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats);12531252 if (evsel) {12541253 evsel->pmu_name = name;12541254+ evsel->use_uncore_alias = use_uncore_alias;12551255 return 0;12561256 } else {12571257 return -ENOMEM;···12881282 evsel->metric_expr = info.metric_expr;12891283 evsel->metric_name = info.metric_name;12901284 evsel->pmu_name = name;12851285+ evsel->use_uncore_alias = use_uncore_alias;12911286 }1292128712931288 return evsel ? 0 : -ENOMEM;···13241317 list_add_tail(&term->list, head);1325131813261319 if (!parse_events_add_pmu(parse_state, list,13271327- pmu->name, head, true)) {13201320+ pmu->name, head,13211321+ true, true)) {13281322 pr_debug("%s -> %s/%s/\n", str,13291323 pmu->name, alias->str);13301324 ok++;···13471339 return parse_events__modifier_event(list, event_mod, true);13481340}1349134113501350-void parse_events__set_leader(char *name, struct list_head *list)13421342+/*13431343+ * Check if the two uncore PMUs are from the same uncore block13441344+ * The format of the uncore PMU name is uncore_#blockname_#pmuidx13451345+ */13461346+static bool is_same_uncore_block(const char *pmu_name_a, const char *pmu_name_b)13471347+{13481348+ char *end_a, *end_b;13491349+13501350+ end_a = strrchr(pmu_name_a, '_');13511351+ end_b = strrchr(pmu_name_b, '_');13521352+13531353+ if (!end_a || !end_b)13541354+ return false;13551355+13561356+ if ((end_a - pmu_name_a) != (end_b - pmu_name_b))13571357+ return false;13581358+13591359+ return (strncmp(pmu_name_a, pmu_name_b, end_a - pmu_name_a) == 0);13601360+}13611361+13621362+static int13631363+parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list,13641364+ struct parse_events_state *parse_state)13651365+{13661366+ struct perf_evsel *evsel, *leader;13671367+ uintptr_t *leaders;13681368+ bool is_leader = true;13691369+ int i, nr_pmu = 0, total_members, ret = 0;13701370+13711371+ leader = list_first_entry(list, struct perf_evsel, node);13721372+ evsel = list_last_entry(list, struct perf_evsel, node);13731373+ total_members = evsel->idx - leader->idx + 1;13741374+13751375+ leaders = calloc(total_members, sizeof(uintptr_t));13761376+ if (WARN_ON(!leaders))13771377+ return 0;13781378+13791379+ /*13801380+ * Going through the whole group and doing sanity check.13811381+ * All members must use alias, and be from the same uncore block.13821382+ * Also, storing the leader events in an array.13831383+ */13841384+ __evlist__for_each_entry(list, evsel) {13851385+13861386+ /* Only split the uncore group which members use alias */13871387+ if (!evsel->use_uncore_alias)13881388+ goto out;13891389+13901390+ /* The events must be from the same uncore block */13911391+ if (!is_same_uncore_block(leader->pmu_name, evsel->pmu_name))13921392+ goto out;13931393+13941394+ if (!is_leader)13951395+ continue;13961396+ /*13971397+ * If the event's PMU name starts to repeat, it must be a new13981398+ * event. That can be used to distinguish the leader from13991399+ * other members, even they have the same event name.14001400+ */14011401+ if ((leader != evsel) && (leader->pmu_name == evsel->pmu_name)) {14021402+ is_leader = false;14031403+ continue;14041404+ }14051405+ /* The name is always alias name */14061406+ WARN_ON(strcmp(leader->name, evsel->name));14071407+14081408+ /* Store the leader event for each PMU */14091409+ leaders[nr_pmu++] = (uintptr_t) evsel;14101410+ }14111411+14121412+ /* only one event alias */14131413+ if (nr_pmu == total_members) {14141414+ parse_state->nr_groups--;14151415+ goto handled;14161416+ }14171417+14181418+ /*14191419+ * An uncore event alias is a joint name which means the same event14201420+ * runs on all PMUs of a block.14211421+ * Perf doesn't support mixed events from different PMUs in the same14221422+ * group. The big group has to be split into multiple small groups14231423+ * which only include the events from the same PMU.14241424+ *14251425+ * Here the uncore event aliases must be from the same uncore block.14261426+ * The number of PMUs must be same for each alias. The number of new14271427+ * small groups equals to the number of PMUs.14281428+ * Setting the leader event for corresponding members in each group.14291429+ */14301430+ i = 0;14311431+ __evlist__for_each_entry(list, evsel) {14321432+ if (i >= nr_pmu)14331433+ i = 0;14341434+ evsel->leader = (struct perf_evsel *) leaders[i++];14351435+ }14361436+14371437+ /* The number of members and group name are same for each group */14381438+ for (i = 0; i < nr_pmu; i++) {14391439+ evsel = (struct perf_evsel *) leaders[i];14401440+ evsel->nr_members = total_members / nr_pmu;14411441+ evsel->group_name = name ? strdup(name) : NULL;14421442+ }14431443+14441444+ /* Take the new small groups into account */14451445+ parse_state->nr_groups += nr_pmu - 1;14461446+14471447+handled:14481448+ ret = 1;14491449+out:14501450+ free(leaders);14511451+ return ret;14521452+}14531453+14541454+void parse_events__set_leader(char *name, struct list_head *list,14551455+ struct parse_events_state *parse_state)13511456{13521457 struct perf_evsel *leader;13531458···14681347 WARN_ONCE(true, "WARNING: failed to set leader: empty list");14691348 return;14701349 }13501350+13511351+ if (parse_events__set_leader_for_uncore_aliase(name, list, parse_state))13521352+ return;1471135314721354 __perf_evlist__set_leader(list);14731355 leader = list_entry(list->next, struct perf_evsel, node);
···2323#include <unistd.h>2424#include <numa.h>25252626+#include "../kselftest.h"2727+2628static const int PORT = 8888;27292830static void build_rcv_group(int *rcv_fd, size_t len, int family, int proto)···231229 int *rcv_fd, nodes;232230233231 if (numa_available() < 0)234234- error(1, errno, "no numa api support");232232+ ksft_exit_skip("no numa api support\n");235233236234 nodes = numa_max_node() + 1;237235
+19-3
tools/testing/selftests/seccomp/seccomp_bpf.c
···134134#endif135135136136#ifndef SECCOMP_FILTER_FLAG_TSYNC137137-#define SECCOMP_FILTER_FLAG_TSYNC 1137137+#define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)138138#endif139139140140#ifndef SECCOMP_FILTER_FLAG_LOG141141-#define SECCOMP_FILTER_FLAG_LOG 2141141+#define SECCOMP_FILTER_FLAG_LOG (1UL << 1)142142+#endif143143+144144+#ifndef SECCOMP_FILTER_FLAG_SPEC_ALLOW145145+#define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)142146#endif143147144148#ifndef PTRACE_SECCOMP_GET_METADATA···20762072TEST(detect_seccomp_filter_flags)20772073{20782074 unsigned int flags[] = { SECCOMP_FILTER_FLAG_TSYNC,20792079- SECCOMP_FILTER_FLAG_LOG };20752075+ SECCOMP_FILTER_FLAG_LOG,20762076+ SECCOMP_FILTER_FLAG_SPEC_ALLOW };20802077 unsigned int flag, all_flags;20812078 int i;20822079 long ret;2083208020842081 /* Test detection of known-good filter flags */20852082 for (i = 0, all_flags = 0; i < ARRAY_SIZE(flags); i++) {20832083+ int bits = 0;20842084+20862085 flag = flags[i];20862086+ /* Make sure the flag is a single bit! */20872087+ while (flag) {20882088+ if (flag & 0x1)20892089+ bits ++;20902090+ flag >>= 1;20912091+ }20922092+ ASSERT_EQ(1, bits);20932093+ flag = flags[i];20942094+20872095 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL);20882096 ASSERT_NE(ENOSYS, errno) {20892097 TH_LOG("Kernel does not support seccomp syscall!");