4.14.20-stable review
Subsystems (3)
Greg Kroah-Hartman
maintainercover 4.14.20-stable review
This is the start of the stable review cycle for the 4.14.20 release. There are 195 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat Feb 17 15:16:22 UTC 2018. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.20-rc1.gz
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-4.14.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <[email protected]>
Linux 4.14.20-rc1
Uma Krishnan <[email protected]>
scsi: cxlflash: Reset command ioasc
James Smart <[email protected]>
scsi: lpfc: Fix crash after bad bar setup on driver attachment
Bart Van Assche <[email protected]>
scsi: core: Ensure that the SCSI error handler gets woken up
Steven Rostedt (VMware) <[email protected]>
ftrace: Remove incorrect setting of glob search field
Eric Biggers <[email protected]>
devpts: fix error handling in devpts_mntget()
Eric W. Biederman <[email protected]>
mn10300/misalignment: Use SIGSEGV SEGV_MAPERR to report a failed user copy
Amir Goldstein <[email protected]>
ovl: take mnt_want_write() for removing impure xattr
Amir Goldstein <[email protected]>
ovl: fix failure to fsync lower dir
Toshi Kani <[email protected]>
acpi, nfit: fix register dimm error handling
Greg Kroah-Hartman <[email protected]>
ACPI: sbshc: remove raw pointer from printk() message
Imre Deak <[email protected]>
drm/i915: Avoid PPS HW/SW state mismatch due to rounding
Yan Markman <[email protected]>
arm64: dts: marvell: add Ethernet aliases
Peter Zijlstra <[email protected]>
objtool: Fix switch-table detection
Nikolay Borisov <[email protected]>
btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker
Andrey Ryabinin <[email protected]>
lib/ubsan: add type mismatch handler for new GCC/Clang
Andrew Morton <[email protected]>
lib/ubsan.c: s/missaligned/misaligned/
Daniel Lezcano <[email protected]>
clocksource/drivers/stm32: Fix kernel panic with multiple timers
Ming Lei <[email protected]>
blk-mq: quiesce queue before freeing queue
Bart Van Assche <[email protected]>
pktcdvd: Fix a recently introduced NULL pointer dereference
Bart Van Assche <[email protected]>
pktcdvd: Fix pkt_setup_dev() error path
Peter Rosin <[email protected]>
pinctrl: sx150x: Add a static gpio/pinctrl pin range mapping
Peter Rosin <[email protected]>
pinctrl: sx150x: Register pinctrl before adding the gpiochip
Peter Rosin <[email protected]>
pinctrl: sx150x: Unregister the pinctrl on release
Dmitry Mastykin <[email protected]>
pinctrl: mcp23s08: fix irq setup order
Mika Westerberg <[email protected]>
pinctrl: intel: Initialize GPIO properly when used through irqchip
James Hogan <[email protected]>
EDAC, octeon: Fix an uninitialized variable warning
Max Filippov <[email protected]>
xtensa: fix futex_atomic_cmpxchg_inatomic
Mikulas Patocka <[email protected]>
alpha: fix formating of stack content
Mikulas Patocka <[email protected]>
alpha: fix reboot on Avanti platform
Michael Cree <[email protected]>
alpha: Fix mixed up args in EXC macro in futex operations
Arnd Bergmann <[email protected]>
alpha: osf_sys.c: fix put_tv32 regression
Mikulas Patocka <[email protected]>
alpha: fix crash if pthread_create races with signal delivery
Eric W. Biederman <[email protected]>
signal/sh: Ensure si_signo is initialized in do_divide_error
Eric W. Biederman <[email protected]>
signal/openrisc: Fix do_unaligned_access to send the proper signal
John Garry <[email protected]>
ipmi: use dynamic memory for DMI driver override
Hans de Goede <[email protected]>
Bluetooth: btusb: Restore QCA Rome suspend/resume fix with a "rewritten" version
Kai-Heng Feng <[email protected]>
Revert "Bluetooth: btusb: fix QCA Rome suspend/resume"
Hans de Goede <[email protected]>
Bluetooth: btsdio: Do not bind to non-removable BCM43341
Hans de Goede <[email protected]>
HID: quirks: Fix keyboard + touchpad on Toshiba Click Mini not working
Eric Biggers <[email protected]>
pipe: fix off-by-one error when checking buffer limits
Eric Biggers <[email protected]>
pipe: actually allow root to exceed the pipe buffer limits
Eric Biggers <[email protected]>
kernel/relay.c: revert "kernel/relay.c: fix potential memory leak"
Rasmus Villemoes <[email protected]>
kernel/async.c: revert "async: simplify lowest_in_progress()"
Heiko Carstens <[email protected]>
fs/proc/kcore.c: use probe_kernel_read() instead of memcpy()
Mauro Carvalho Chehab <[email protected]>
media: cxusb, dib0700: ignore XC2028_I2C_FLUSH
Mauro Carvalho Chehab <[email protected]>
media: ts2020: avoid integer overflows on 32 bit machines
Arnd Bergmann <[email protected]>
media: dvb-frontends: fix i2c access helpers for KASAN
Arnd Bergmann <[email protected]>
kasan: rework Kconfig settings
Andrey Konovalov <[email protected]>
kasan: don't emit builtin calls when sanitization is off
Liu Bo <[email protected]>
Btrfs: raid56: iterate raid56 internal bio with bio_for_each_segment_all
Martin Kaiser <[email protected]>
watchdog: imx2_wdt: restore previous timeout after suspend+resume
Takashi Iwai <[email protected]>
ASoC: skl: Fix kernel warning due to zero NHTL entry
John Keeping <[email protected]>
ASoC: rockchip: i2s: fix playback after runtime resume
Ulf Magnusson <[email protected]>
KVM: PPC: Book3S PR: Fix broken select due to misspelling
James Morse <[email protected]>
KVM: arm/arm64: Handle CPU_PM_ENTER_FAILED
Paul Mackerras <[email protected]>
KVM: PPC: Book3S HV: Drop locks before reading guest memory
Paul Mackerras <[email protected]>
KVM: PPC: Book3S HV: Make sure we don't re-enter guest without XIVE loaded
Liran Alon <[email protected]>
KVM: nVMX: Fix bug of injecting L2 exception into L1
Liran Alon <[email protected]>
KVM: nVMX: Fix races when sending nested PI while dest enters/leaves L2
Marc Zyngier <[email protected]>
arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls
LEROY Christophe <[email protected]>
crypto: talitos - fix Kernel Oops on hashing an empty file
Eric Biggers <[email protected]>
crypto: sha512-mb - initialize pending lengths correctly
Horia Geantă <[email protected]>
crypto: caam - fix endless loop when DECO acquire fails
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs
Daniel Mentz <[email protected]>
media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: avoid sizeof(type)
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: fix the indentation
Hans Verkuil <[email protected]>
media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF
Hans Verkuil <[email protected]>
media: v4l2-ioctl.c: don't copy back the result for -ENOTTY
Hans Verkuil <[email protected]>
media: v4l2-ioctl.c: use check_fmt for enum/g/s/try_fmt
Eric Biggers <[email protected]>
crypto: hash - prevent using keyed hashes without setting key
Eric Biggers <[email protected]>
crypto: hash - annotate algorithms taking optional key
Eric Biggers <[email protected]>
crypto: poly1305 - remove ->setkey() method
Eric Biggers <[email protected]>
crypto: mcryptd - pass through absence of ->setkey()
Eric Biggers <[email protected]>
crypto: cryptd - pass through absence of ->setkey()
Eric Biggers <[email protected]>
crypto: hash - introduce crypto_hash_alg_has_setkey()
Mika Westerberg <[email protected]>
ahci: Add Intel Cannon Lake PCH-H PCI ID
Hans de Goede <[email protected]>
ahci: Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI
Hans de Goede <[email protected]>
ahci: Annotate PCI ids for mobile Intel chipsets as such
Ivan Vecera <[email protected]>
kernfs: fix regression in kernfs_fop_write caused by wrong type
Trond Myklebust <[email protected]>
NFS: Fix a race between mmap() and O_DIRECT
Eric Biggers <[email protected]>
NFS: reject request for id_legacy key without auxdata
J. Bruce Fields <[email protected]>
NFS: commit direct writes even if they fail partially
Trond Myklebust <[email protected]>
NFS: Fix nfsstat breakage due to LOOKUPP
Trond Myklebust <[email protected]>
NFS: Add a cond_resched() to nfs_commit_release_pages()
Tigran Mkrtchyan <[email protected]>
nfs41: do not return ENOMEM on LAYOUTUNAVAILABLE
Scott Mayhew <[email protected]>
nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds
Eric Biggers <[email protected]>
ubifs: free the encrypted symlink target
Bradley Bolen <[email protected]>
ubi: block: Fix locking for idr_alloc/idr_remove
Sascha Hauer <[email protected]>
ubi: fastmap: Erase outdated anchor PEBs during attach
Clay McClure <[email protected]>
ubi: Fix race condition between ubi volume creation and udev
Miquel Raynal <[email protected]>
mtd: nand: sunxi: Fix ECC strength choice
Miquel Raynal <[email protected]>
mtd: nand: Fix nand_do_read_oob() return value
Kamal Dasu <[email protected]>
mtd: nand: brcmnand: Disable prefetch by default
Arnd Bergmann <[email protected]>
mtd: cfi: convert inline functions to macros
Marc Zyngier <[email protected]>
arm64: Kill PSCI_GET_VERSION as a variant-2 workaround
Marc Zyngier <[email protected]>
arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support
Marc Zyngier <[email protected]>
arm/arm64: smccc: Implement SMCCC v1.1 inline primitive
Marc Zyngier <[email protected]>
arm/arm64: smccc: Make function identifiers an unsigned quantity
Marc Zyngier <[email protected]>
firmware/psci: Expose SMCCC version through psci_ops
Marc Zyngier <[email protected]>
firmware/psci: Expose PSCI conduit
Marc Zyngier <[email protected]>
arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling
Marc Zyngier <[email protected]>
arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support
Marc Zyngier <[email protected]>
arm/arm64: KVM: Turn kvm_psci_version into a static inline
Marc Zyngier <[email protected]>
arm64: KVM: Make PSCI_VERSION a fast path
Marc Zyngier <[email protected]>
arm/arm64: KVM: Advertise SMCCC v1.1
Marc Zyngier <[email protected]>
arm/arm64: KVM: Implement PSCI 1.0 support
Marc Zyngier <[email protected]>
arm/arm64: KVM: Add smccc accessors to PSCI code
Marc Zyngier <[email protected]>
arm/arm64: KVM: Add PSCI_VERSION helper
Marc Zyngier <[email protected]>
arm/arm64: KVM: Consolidate the PSCI include files
Marc Zyngier <[email protected]>
arm64: KVM: Increment PC after handling an SMC trap
Jayachandran C <[email protected]>
arm64: Branch predictor hardening for Cavium ThunderX2
Shanker Donthineni <[email protected]>
arm64: Implement branch predictor hardening for Falkor
Will Deacon <[email protected]>
arm64: Implement branch predictor hardening for affected Cortex-A CPUs
Will Deacon <[email protected]>
arm64: cputype: Add missing MIDR values for Cortex-A72 and Cortex-A75
Will Deacon <[email protected]>
arm64: entry: Apply BP hardening for suspicious interrupts from EL0
Will Deacon <[email protected]>
arm64: entry: Apply BP hardening for high-priority synchronous exceptions
Marc Zyngier <[email protected]>
arm64: KVM: Use per-CPU vector when BP hardening is enabled
Marc Zyngier <[email protected]>
arm64: Move BP hardening to check_and_switch_context
Will Deacon <[email protected]>
arm64: Add skeleton to harden the branch predictor against aliasing attacks
Marc Zyngier <[email protected]>
arm64: Move post_ttbr_update_workaround to C code
Will Deacon <[email protected]>
drivers/firmware: Expose psci_get_version through psci_ops structure
Will Deacon <[email protected]>
arm64: cpufeature: Pass capability structure to ->enable callback
Suzuki K Poulose <[email protected]>
arm64: Run enable method for errata work arounds on late CPUs
James Morse <[email protected]>
arm64: cpufeature: __this_cpu_has_cap() shouldn't stop early
Will Deacon <[email protected]>
arm64: futex: Mask __user pointers prior to dereference
Will Deacon <[email protected]>
arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user
Will Deacon <[email protected]>
arm64: uaccess: Don't bother eliding access_ok checks in __{get, put}_user
Will Deacon <[email protected]>
arm64: uaccess: Prevent speculative use of the current addr_limit
Will Deacon <[email protected]>
arm64: entry: Ensure branch through syscall table is bounded under speculation
Robin Murphy <[email protected]>
arm64: Use pointer masking to limit uaccess speculation
Robin Murphy <[email protected]>
arm64: Make USER_DS an inclusive limit
Robin Murphy <[email protected]>
arm64: Implement array_index_mask_nospec()
Will Deacon <[email protected]>
arm64: barrier: Add CSDB macros to control data-value prediction
Will Deacon <[email protected]>
arm64: idmap: Use "awx" flags for .idmap.text .pushsection directives
Will Deacon <[email protected]>
arm64: entry: Reword comment about post_ttbr_update_workaround
Marc Zyngier <[email protected]>
arm64: Force KPTI to be disabled on Cavium ThunderX
Will Deacon <[email protected]>
arm64: kpti: Add ->enable callback to remap swapper using nG mappings
Will Deacon <[email protected]>
arm64: mm: Permit transitioning from Global to Non-Global without BBM
Will Deacon <[email protected]>
arm64: kpti: Make use of nG dependent on arm64_kernel_unmapped_at_el0()
Jayachandran C <[email protected]>
arm64: Turn on KPTI only on CPUs that need it
Jayachandran C <[email protected]>
arm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs
Catalin Marinas <[email protected]>
arm64: kpti: Fix the interaction between ASID switching and software PAN
Will Deacon <[email protected]>
arm64: mm: Introduce TTBR_ASID_MASK for getting at the ASID in the TTBR
Suzuki K Poulose <[email protected]>
arm64: capabilities: Handle duplicate entries for a capability
Will Deacon <[email protected]>
arm64: Take into account ID_AA64PFR0_EL1.CSV3
Will Deacon <[email protected]>
arm64: Kconfig: Reword UNMAP_KERNEL_AT_EL0 kconfig entry
Will Deacon <[email protected]>
arm64: Kconfig: Add CONFIG_UNMAP_KERNEL_AT_EL0
Will Deacon <[email protected]>
arm64: use RET instruction for exiting the trampoline
Will Deacon <[email protected]>
arm64: kaslr: Put kernel vectors address in separate data page
Will Deacon <[email protected]>
arm64: entry: Add fake CPU feature for unmapping the kernel at EL0
Will Deacon <[email protected]>
arm64: tls: Avoid unconditional zeroing of tpidrro_el0 for native tasks
Stephen Boyd <[email protected]>
arm64: cpu_errata: Add Kryo to Falkor 1003 errata
Will Deacon <[email protected]>
arm64: erratum: Work around Falkor erratum #E1003 in trampoline code
Will Deacon <[email protected]>
arm64: entry: Hook up entry trampoline to exception vectors
Will Deacon <[email protected]>
arm64: entry: Explicitly pass exception level to kernel_ventry macro
Will Deacon <[email protected]>
arm64: mm: Map entry trampoline into trampoline and kernel page tables
Will Deacon <[email protected]>
arm64: entry: Add exception trampoline page for exceptions from EL0
Will Deacon <[email protected]>
arm64: mm: Invalidate both kernel and user ASIDs when performing TLBI
Will Deacon <[email protected]>
arm64: mm: Add arm64_kernel_unmapped_at_el0 helper
Will Deacon <[email protected]>
arm64: mm: Allocate ASIDs in pairs
Will Deacon <[email protected]>
arm64: mm: Fix and re-enable ARM64_SW_TTBR0_PAN
Will Deacon <[email protected]>
arm64: mm: Rename post_ttbr0_update_workaround
Will Deacon <[email protected]>
arm64: mm: Remove pre_ttbr0_update_workaround for Falkor erratum #E1003
Will Deacon <[email protected]>
arm64: mm: Move ASID from TTBR0 to TTBR1
Will Deacon <[email protected]>
arm64: mm: Temporarily disable ARM64_SW_TTBR0_PAN
Will Deacon <[email protected]>
arm64: mm: Use non-global mappings for kernel space
Yury Norov <[email protected]>
arm64: move TASK_* definitions to <asm/processor.h>
Arvind Yadav <[email protected]>
media: hdpvr: Fix an error handling path in hdpvr_probe()
Malcolm Priestley <[email protected]>
media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner
Malcolm Priestley <[email protected]>
media: dvb-usb-v2: lmedm04: Improve logic checking of warm start
Mohamed Ghannam <[email protected]>
dccp: CVE-2017-8824: use-after-free in DCCP code
Ville Syrjälä <[email protected]>
drm/i915: Fix deadlock in i830_disable_pipe()
Ville Syrjälä <[email protected]>
drm/i915: Redo plane sanitation during readout
Ville Syrjälä <[email protected]>
drm/i915: Add .get_hw_state() method for planes
Steven Rostedt (VMware) <[email protected]>
sched/rt: Up the root domain ref count when passing it around via IPIs
Steven Rostedt (VMware) <[email protected]>
sched/rt: Use container_of() to get root domain in rto_push_irq_work_func()
Haozhong Zhang <[email protected]>
KVM MMU: check pending exception before injecting APF
Shanker Donthineni <[email protected]>
arm64: Add software workaround for Falkor erratum 1041
Shanker Donthineni <[email protected]>
arm64: Define cputype macros for Falkor CPU
Rasmus Villemoes <[email protected]>
watchdog: gpio_wdt: set WDOG_HW_RUNNING in gpio_wdt_stop
Omar Sandoval <[email protected]>
sched/wait: Fix add_wait_queue() behavioral change
Yang Shunyong <[email protected]>
dmaengine: dmatest: fix container_of member in dmatest_callback
Andrew-sh Cheng <[email protected]>
cpufreq: mediatek: add mediatek related projects into blacklist
Aurelien Aptel <[email protected]>
CIFS: zero sensitive data when freeing
Daniel N Pettersson <[email protected]>
cifs: Fix autonegotiate security settings mismatch
Matthew Wilcox <[email protected]>
cifs: Fix missing put_xid in cifs_file_strict_mmap
Michal Suchanek <[email protected]>
powerpc/pseries: include linux/types.h in asm/hvcall.h
Matt Redfearn <[email protected]>
watchdog: indydog: Add dependency on SGI_HAS_INDYDOG
-------------
Diffstat:
Documentation/arm64/silicon-errata.txt | 3 +- Makefile | 7 +- arch/alpha/include/asm/futex.h | 8 +- arch/alpha/kernel/osf_sys.c | 4 +- arch/alpha/kernel/pci_impl.h | 3 +- arch/alpha/kernel/process.c | 3 +- arch/alpha/kernel/traps.c | 13 +- arch/arm/crypto/crc32-ce-glue.c | 2 + arch/arm/include/asm/kvm_host.h | 6 + arch/arm/include/asm/kvm_mmu.h | 10 + arch/arm/include/asm/kvm_psci.h | 27 - arch/arm/kvm/handle_exit.c | 17 +- arch/arm64/Kconfig | 56 +- arch/arm64/boot/dts/marvell/armada-7040-db.dts | 6 + arch/arm64/boot/dts/marvell/armada-8040-db.dts | 7 + arch/arm64/boot/dts/marvell/armada-8040-mcbin.dts | 6 + arch/arm64/crypto/crc32-ce-glue.c | 2 + arch/arm64/include/asm/asm-uaccess.h | 36 +- arch/arm64/include/asm/assembler.h | 54 +- arch/arm64/include/asm/barrier.h | 23 + arch/arm64/include/asm/cpucaps.h | 5 +- arch/arm64/include/asm/cputype.h | 11 + arch/arm64/include/asm/efi.h | 12 +- arch/arm64/include/asm/fixmap.h | 5 + arch/arm64/include/asm/futex.h | 9 +- arch/arm64/include/asm/kvm_asm.h | 2 + arch/arm64/include/asm/kvm_host.h | 5 + arch/arm64/include/asm/kvm_mmu.h | 38 + arch/arm64/include/asm/kvm_psci.h | 27 - arch/arm64/include/asm/memory.h | 15 - arch/arm64/include/asm/mmu.h | 48 + arch/arm64/include/asm/mmu_context.h | 12 +- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/pgtable-prot.h | 35 +- arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/include/asm/proc-fns.h | 6 - arch/arm64/include/asm/processor.h | 24 + arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/include/asm/tlbflush.h | 16 +- arch/arm64/include/asm/uaccess.h | 181 +++- arch/arm64/kernel/Makefile | 4 + arch/arm64/kernel/arm64ksyms.c | 4 +- arch/arm64/kernel/asm-offsets.c | 6 +- arch/arm64/kernel/bpi.S | 83 ++ arch/arm64/kernel/cpu-reset.S | 3 +- arch/arm64/kernel/cpu_errata.c | 239 ++++- arch/arm64/kernel/cpufeature.c | 138 ++- arch/arm64/kernel/efi-entry.S | 2 + arch/arm64/kernel/entry.S | 230 ++++- arch/arm64/kernel/head.S | 3 +- arch/arm64/kernel/process.c | 12 +- arch/arm64/kernel/relocate_kernel.S | 1 + arch/arm64/kernel/sleep.S | 2 +- arch/arm64/kernel/vmlinux.lds.S | 22 +- arch/arm64/kvm/handle_exit.c | 14 +- arch/arm64/kvm/hyp-init.S | 1 + arch/arm64/kvm/hyp/entry.S | 12 + arch/arm64/kvm/hyp/hyp-entry.S | 20 +- arch/arm64/kvm/hyp/switch.c | 13 +- arch/arm64/lib/clear_user.S | 10 +- arch/arm64/lib/copy_from_user.S | 4 +- arch/arm64/lib/copy_in_user.S | 9 +- arch/arm64/lib/copy_to_user.S | 4 +- arch/arm64/mm/cache.S | 4 +- arch/arm64/mm/context.c | 48 +- arch/arm64/mm/fault.c | 36 +- arch/arm64/mm/mmu.c | 35 + arch/arm64/mm/proc.S | 223 ++++- arch/arm64/xen/hypercall.S | 4 +- arch/mn10300/mm/misalignment.c | 2 +- arch/openrisc/kernel/traps.c | 10 +- arch/powerpc/crypto/crc32c-vpmsum_glue.c | 1 + arch/powerpc/include/asm/hvcall.h | 1 + arch/powerpc/kvm/Kconfig | 2 +- arch/powerpc/kvm/book3s_hv.c | 16 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 40 +- arch/s390/crypto/crc32-vx.c | 3 + arch/sh/kernel/traps_32.c | 3 +- arch/sparc/crypto/crc32c_glue.c | 1 + arch/x86/crypto/crc32-pclmul_glue.c | 1 + arch/x86/crypto/crc32c-intel_glue.c | 1 + arch/x86/crypto/poly1305_glue.c | 1 - .../x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c | 10 +- arch/x86/kvm/mmu.c | 3 +- arch/x86/kvm/vmx.c | 6 +- arch/x86/kvm/x86.h | 1 + arch/xtensa/include/asm/futex.h | 23 +- block/blk-core.c | 9 + crypto/ahash.c | 33 +- crypto/algif_hash.c | 52 +- crypto/crc32_generic.c | 1 + crypto/crc32c_generic.c | 1 + crypto/cryptd.c | 10 +- crypto/mcryptd.c | 10 +- crypto/poly1305_generic.c | 17 +- crypto/shash.c | 25 +- drivers/acpi/nfit/core.c | 3 + drivers/acpi/sbshc.c | 4 +- drivers/ata/ahci.c | 37 +- drivers/block/pktcdvd.c | 12 +- drivers/bluetooth/btsdio.c | 9 + drivers/bluetooth/btusb.c | 20 +- drivers/char/ipmi/ipmi_dmi.c | 5 +- drivers/clocksource/timer-stm32.c | 7 +- drivers/cpufreq/cpufreq-dt-platdev.c | 8 + drivers/crypto/bfin_crc.c | 3 +- drivers/crypto/caam/ctrl.c | 8 +- drivers/crypto/stm32/stm32_crc32.c | 2 + drivers/crypto/talitos.c | 4 + drivers/dma/dmatest.c | 2 +- drivers/edac/octeon_edac-lmc.c | 1 + drivers/firmware/psci.c | 57 +- drivers/gpu/drm/i915/intel_display.c | 303 +++--- drivers/gpu/drm/i915/intel_dp.c | 6 + drivers/gpu/drm/i915/intel_drv.h | 2 + drivers/gpu/drm/i915/intel_sprite.c | 83 ++ drivers/hid/hid-core.c | 12 +- drivers/media/dvb-frontends/ascot2e.c | 4 +- drivers/media/dvb-frontends/cxd2841er.c | 4 +- drivers/media/dvb-frontends/helene.c | 4 +- drivers/media/dvb-frontends/horus3a.c | 4 +- drivers/media/dvb-frontends/itd1000.c | 5 +- drivers/media/dvb-frontends/mt312.c | 5 +- drivers/media/dvb-frontends/stb0899_drv.c | 3 +- drivers/media/dvb-frontends/stb6100.c | 6 +- drivers/media/dvb-frontends/stv0367.c | 4 +- drivers/media/dvb-frontends/stv090x.c | 4 +- drivers/media/dvb-frontends/stv6110x.c | 4 +- drivers/media/dvb-frontends/ts2020.c | 4 +- drivers/media/dvb-frontends/zl10039.c | 4 +- drivers/media/usb/dvb-usb-v2/lmedm04.c | 39 +- drivers/media/usb/dvb-usb/cxusb.c | 2 + drivers/media/usb/dvb-usb/dib0700_devices.c | 1 + drivers/media/usb/hdpvr/hdpvr-core.c | 26 +- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1032 ++++++++++++-------- drivers/media/v4l2-core/v4l2-ioctl.c | 145 ++- drivers/mtd/nand/brcmnand/brcmnand.c | 13 +- drivers/mtd/nand/nand_base.c | 5 +- drivers/mtd/nand/sunxi_nand.c | 8 +- drivers/mtd/ubi/block.c | 42 +- drivers/mtd/ubi/vmt.c | 15 +- drivers/mtd/ubi/wl.c | 77 +- drivers/pinctrl/intel/pinctrl-intel.c | 23 +- drivers/pinctrl/pinctrl-mcp23s08.c | 8 +- drivers/pinctrl/pinctrl-sx150x.c | 40 +- drivers/scsi/cxlflash/main.c | 1 + drivers/scsi/hosts.c | 6 + drivers/scsi/lpfc/lpfc_init.c | 84 +- drivers/scsi/scsi_error.c | 18 +- drivers/scsi/scsi_lib.c | 39 +- .../lustre/lnet/libcfs/linux/linux-crypto-adler.c | 1 + drivers/watchdog/Kconfig | 2 +- drivers/watchdog/gpio_wdt.c | 3 +- drivers/watchdog/imx2_wdt.c | 20 +- fs/btrfs/inode.c | 11 +- fs/btrfs/raid56.c | 11 +- fs/cifs/cifsencrypt.c | 3 +- fs/cifs/connect.c | 6 +- fs/cifs/file.c | 26 +- fs/cifs/misc.c | 14 +- fs/cifs/smb2pdu.c | 3 +- fs/devpts/inode.c | 4 +- fs/kernfs/file.c | 2 +- fs/nfs/direct.c | 4 +- fs/nfs/filelayout/filelayout.c | 4 +- fs/nfs/io.c | 2 +- fs/nfs/nfs4idmap.c | 6 +- fs/nfs/nfs4xdr.c | 64 +- fs/nfs/pnfs.c | 4 +- fs/nfs/write.c | 2 + fs/overlayfs/readdir.c | 17 +- fs/pipe.c | 15 +- fs/proc/kcore.c | 18 +- fs/ubifs/dir.c | 10 +- include/crypto/hash.h | 34 +- include/crypto/internal/hash.h | 2 + include/crypto/poly1305.h | 2 - include/kvm/arm_psci.h | 51 + include/linux/arm-smccc.h | 165 +++- include/linux/crypto.h | 8 + include/linux/mtd/map.h | 130 ++- include/linux/nfs4.h | 12 +- include/linux/psci.h | 14 + include/scsi/scsi_host.h | 2 + include/uapi/linux/psci.h | 3 + kernel/async.c | 20 +- kernel/relay.c | 1 - kernel/sched/rt.c | 24 +- kernel/sched/sched.h | 2 + kernel/sched/topology.c | 13 + kernel/sched/wait.c | 2 +- kernel/trace/ftrace.c | 1 - lib/Kconfig.debug | 2 +- lib/Kconfig.kasan | 11 + lib/ubsan.c | 50 +- lib/ubsan.h | 14 + net/dccp/proto.c | 5 + scripts/Makefile.kasan | 5 + scripts/Makefile.lib | 2 +- sound/soc/intel/skylake/skl-nhlt.c | 3 +- sound/soc/rockchip/rockchip_i2s.c | 6 + tools/objtool/check.c | 41 +- tools/objtool/check.h | 1 + virt/kvm/arm/arm.c | 11 +- virt/kvm/arm/psci.c | 143 ++- 205 files changed, 3889 insertions(+), 1627 deletions(-)
Greg Kroah-Hartman
maintainerPATCH 1/195 watchdog: indydog: Add dependency on SGI_HAS_INDYDOG
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit 24f8d233074badd4c18e4dafd2fb97d65838afed upstream.
Commit da2a68b3eb47 ("watchdog: Enable COMPILE_TEST where possible") enabled building the Indy watchdog driver when COMPILE_TEST is enabled. However, the driver makes reference to symbols that are only defined for certain platforms are selected in the config. These platforms select SGI_HAS_INDYDOG. Without this, link time errors result, for example when building a MIPS allyesconfig.
drivers/watchdog/indydog.o: In function `indydog_write':
indydog.c:(.text+0x18): undefined reference to sgimc' indydog.c:(.text+0x1c): undefined reference to sgimc' drivers/watchdog/indydog.o: In function `indydog_start':
indydog.c:(.text+0x54): undefined reference to sgimc' indydog.c:(.text+0x58): undefined reference to sgimc' drivers/watchdog/indydog.o: In function `indydog_stop':
indydog.c:(.text+0xa4): undefined reference to sgimc' drivers/watchdog/indydog.o:indydog.c:(.text+0xa8): more undefined references to sgimc' follow
make: *** [Makefile:1005: vmlinux] Error 1
Fix this by ensuring that CONFIG_INDIDOG can only be selected when the necessary dependent platform symbols are built in.
--- drivers/watchdog/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/Kconfig +1 -1
@@ -1451,7 +1451,7 @@ config RC32434_WDT config INDYDOG tristate "Indy/I2 Hardware Watchdog" - depends on SGI_HAS_INDYDOG || (MIPS && COMPILE_TEST) + depends on SGI_HAS_INDYDOG help Hardware driver for the Indy's/I2's watchdog. This is a watchdog timer that will reboot the machine after a 60 second
Greg Kroah-Hartman
maintainerPATCH 2/195 powerpc/pseries: include linux/types.h in asm/hvcall.h
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Suchanek <[email protected]>
commit 1b689a95ce7427075f9ac9fb4aea1af530742b7f upstream.
Commit 6e032b350cd1 ("powerpc/powernv: Check device-tree for RFI flush settings") uses u64 in asm/hvcall.h without including linux/types.h
This breaks hvcall.h users that do not include the header themselves.
--- arch/powerpc/include/asm/hvcall.h | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/hvcall.h +1 -0
@@ -353,6 +353,7 @@#define PROC_TABLE_GTSE 0x01#ifndef __ASSEMBLY__ +#include <linux/types.h> /** * plpar_hcall_norets: - Make a pseries hypervisor call with no return arguments
Greg Kroah-Hartman
maintainerPATCH 4/195 cifs: Fix autonegotiate security settings mismatch
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel N Pettersson <[email protected]>
commit 9aca7e454415f7878b28524e76bebe1170911a88 upstream.
Autonegotiation gives a security settings mismatch error if the SMB server selects an SMBv3 dialect that isn't SMB3.02. The exact error is "protocol revalidation - security settings mismatch".
This can be tested using Samba v4.2 or by setting the global Samba setting max protocol = SMB3_00.
The check that fails in smb3_validate_negotiate is the dialect verification of the negotiate info response. This is because it tries to verify against the protocol_id in the global smbdefault_values. The protocol_id in smbdefault_values is SMB3.02.
In SMB2_negotiate the protocol_id in smbdefault_values isn't updated, it is global so it probably shouldn't be, but server->dialect is.
This patch changes the check in smb3_validate_negotiate to use server->dialect instead of server->vals->protocol_id. The patch works with autonegotiate and when using a specific version in the vers mount option.
--- fs/cifs/smb2pdu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/cifs/smb2pdu.c +1 -2
@@ -733,8 +733,7 @@ int smb3_validate_negotiate(const unsign }/* check validate negotiate info response matches what we got earlier */ -if (pneg_rsp->Dialect != -cpu_to_le16 (tcon->ses->server->vals->protocol_id)) +if (pneg_rsp->Dialect !=cpu_to_le16 (tcon->ses->server->dialect)) goto vneg_out;if (pneg_rsp->SecurityMode !=cpu_to_le16 (tcon->ses->server->sec_mode))
Greg Kroah-Hartman
maintainerPATCH 5/195 CIFS: zero sensitive data when freeing
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aurelien Aptel <[email protected]>
commit 97f4b7276b829a8927ac903a119bef2f963ccc58 upstream.
also replaces memset()+kfree() by kzfree().
--- fs/cifs/cifsencrypt.c | 3 +-- fs/cifs/connect.c | 6 +++--- fs/cifs/misc.c | 14 ++++---------- 3 files changed, 8 insertions(+), 15 deletions(-)
fs/cifs/cifsencrypt.c +1 -2
@@ -325,9 +325,8 @@ int calc_lanman_hash(const char *passwor {int i;int rc; -char password_with_pad[CIFS_ENCPWD_SIZE ]; +char password_with_pad[CIFS_ENCPWD_SIZE ] = {0 }; -memset (password_with_pad,0 ,CIFS_ENCPWD_SIZE );if (password)strncpy (password_with_pad, password,CIFS_ENCPWD_SIZE );
fs/cifs/connect.c +3 -3
@@ -1707,7 +1707,7 @@ cifs_parse_mount_options(const char *mou tmp_end++;if (!(tmp_end < end && tmp_end[1 ] == delim)) {/* No it is not. Set the password to NULL */ -kfree (vol->password); +kzfree (vol->password); vol->password =NULL ;break ; }
@@ -1745,7 +1745,7 @@ cifs_parse_mount_options(const char *mou options = end; } -kfree (vol->password); +kzfree (vol->password);/* Now build new password string */ temp_len =strlen (value); vol->password =kzalloc (temp_len+1 ,GFP_KERNEL );
@@ -4235,7 +4235,7 @@ cifs_construct_tcon(struct cifs_sb_inforeset_cifs_unix_caps (0 , tcon,NULL , vol_info); out:kfree (vol_info->username); -kfree (vol_info->password); +kzfree (vol_info->password);kfree (vol_info);return tcon;
fs/cifs/misc.c +4 -10
@@ -98,14 +98,11 @@ sesInfoFree(struct cifs_ses *buf_to_freekfree (buf_to_free->serverOS);kfree (buf_to_free->serverDomain);kfree (buf_to_free->serverNOS); -if (buf_to_free->password) { -memset (buf_to_free->password,0 ,strlen (buf_to_free->password)); -kfree (buf_to_free->password); - } +kzfree (buf_to_free->password);kfree (buf_to_free->user_name);kfree (buf_to_free->domainName); -kfree (buf_to_free->auth_key.response); -kfree (buf_to_free); +kzfree (buf_to_free->auth_key.response); +kzfree (buf_to_free); } struct cifs_tcon *
@@ -136,10 +133,7 @@ tconInfoFree(struct cifs_tcon *buf_to_fr }atomic_dec (&tconInfoAllocCount);kfree (buf_to_free->nativeFileSystem); -if (buf_to_free->password) { -memset (buf_to_free->password,0 ,strlen (buf_to_free->password)); -kfree (buf_to_free->password); - } +kzfree (buf_to_free->password);kfree (buf_to_free); }
Greg Kroah-Hartman
maintainerPATCH 6/195 cpufreq: mediatek: add mediatek related projects into blacklist
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew-sh Cheng <[email protected]>
commit 6066998cbd2b1012a8d5bc9a2957cfd0ad53150e upstream.
mediatek projects will use mediate-cpufreq.c as cpufreq driver, instead of using cpufreq_dt.c
Add mediatek related projects into cpufreq-dt blacklist
--- drivers/cpufreq/cpufreq-dt-platdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/cpufreq/cpufreq-dt-platdev.c +8 -0
@@ -111,6 +111,14 @@ static const struct of_device_id blackli { .compatible = "marvell,armadaxp", }, + { .compatible = "mediatek,mt2701", }, + { .compatible = "mediatek,mt2712", }, + { .compatible = "mediatek,mt7622", }, + { .compatible = "mediatek,mt7623", }, + { .compatible = "mediatek,mt817x", }, + { .compatible = "mediatek,mt8173", }, + { .compatible = "mediatek,mt8176", }, + { .compatible = "nvidia,tegra124", }, { .compatible = "st,stih407", },
Greg Kroah-Hartman
maintainerPATCH 7/195 dmaengine: dmatest: fix container_of member in dmatest_callback
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Shunyong <[email protected]>
commit 66b3bd2356e0a1531c71a3dcf96944621e25c17c upstream.
The type of arg passed to dmatest_callback is struct dmatest_done. It refers to test_done in struct dmatest_thread, not done_wait.
--- drivers/dma/dmatest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmatest.c +1 -1
@@ -355,7 +355,7 @@ static void dmatest_callback(void *arg) {struct dmatest_done *done = arg;struct dmatest_thread *thread = - container_of(arg, struct dmatest_thread, done_wait); + container_of(done, struct dmatest_thread, test_done);if (!thread->done) { done->done = true;wake_up_all (done->wait);
Greg Kroah-Hartman
maintainerPATCH 10/195 arm64: Define cputype macros for Falkor CPU
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shanker Donthineni <[email protected]>
commit c622cc013cece073722592cff1ac6643a33b1622 upstream.
Add cputype definition macros for Qualcomm Datacenter Technologies Falkor CPU in cputype.h. It's unfortunate that the first revision of the Falkor CPU used the wrong part number 0x800, got fixed in v2 chip with part number 0xC00, and would be used the same value for future revisions.
--- arch/arm64/include/asm/cputype.h | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/include/asm/cputype.h +2 -0
@@ -91,6 +91,7 @@#define BRCM_CPU_PART_VULCAN 0x516#define QCOM_CPU_PART_FALKOR_V1 0x800 +#define QCOM_CPU_PART_FALKOR 0xC00#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
@@ -99,6 +100,7 @@#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)#define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1) +#define MIDR_QCOM_FALKOR MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR)#ifndef __ASSEMBLY__
Greg Kroah-Hartman
maintainerPATCH 11/195 arm64: Add software workaround for Falkor erratum 1041
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shanker Donthineni <[email protected]>
commit 932b50c7c1c65e6f23002e075b97ee083c4a9e71 upstream.
The ARM architecture defines the memory locations that are permitted to be accessed as the result of a speculative instruction fetch from an exception level for which all stages of translation are disabled. Specifically, the core is permitted to speculatively fetch from the 4KB region containing the current program counter 4K and next 4K.
When translation is changed from enabled to disabled for the running exception level (SCTLR_ELn[M] changed from a value of 1 to 0), the Falkor core may errantly speculatively access memory locations outside of the 4KB region permitted by the architecture. The errant memory access may lead to one of the following unexpected behaviors.
1) A System Error Interrupt (SEI) being raised by the Falkor core due to the errant memory access attempting to access a region of memory that is protected by a slave-side memory protection unit.
2) Unpredictable device behavior due to a speculative read from device memory. This behavior may only occur if the instruction cache is disabled prior to or coincident with translation being changed from enabled to disabled.
The conditions leading to this erratum will not occur when either of the following occur:
1) A higher exception level disables translation of a lower exception level (e.g. EL2 changing SCTLR_EL1[M] from a value of 1 to 0).
2) An exception level disabling its stage-1 translation if its stage-2 translation is enabled (e.g. EL1 changing SCTLR_EL1[M] from a value of 1 to 0 when HCR_EL2[VM] has a value of 1).
To avoid the errant behavior, software must execute an ISB immediately prior to executing the MSR that will change SCTLR_ELn[M] from 1 to 0.
--- Documentation/arm64/silicon-errata.txt | 1 + arch/arm64/Kconfig | 10 ++++++++++ arch/arm64/include/asm/assembler.h | 10 ++++++++++ arch/arm64/kernel/cpu-reset.S | 1 + arch/arm64/kernel/efi-entry.S | 2 ++ arch/arm64/kernel/head.S | 1 + arch/arm64/kernel/relocate_kernel.S | 1 + arch/arm64/kvm/hyp-init.S | 1 + 8 files changed, 27 insertions(+)
Documentation/arm64/silicon-errata.txt +1 -0
@@ -74,3 +74,4 @@ stable kernels. | Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003 | | Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009 | | Qualcomm Tech. | QDF2400 ITS | E0065 | QCOM_QDF2400_ERRATUM_0065 | +| Qualcomm Tech. | Falkor v{1,2} | E1041 | QCOM_FALKOR_ERRATUM_1041 |
arch/arm64/Kconfig +10 -0
@@ -539,6 +539,16 @@ config QCOM_QDF2400_ERRATUM_0065 If unsure, say Y. +config QCOM_FALKOR_ERRATUM_E1041 + bool "Falkor E1041: Speculative instruction fetches might cause errant memory access" + default y + help + Falkor CPU may speculatively fetch instructions from an improper + memory location when MMU translation is changed from SCTLR_ELn[M]=1 + to SCTLR_ELn[M]=0. Prefix an ISB instruction to fix the problem. + + If unsure, say Y. + endmenu
arch/arm64/include/asm/assembler.h +10 -0
@@ -499,4 +499,14 @@ alternative_else_nop_endif #endif .endm +/** + * Errata workaround prior to disable MMU. Insert an ISB immediately prior + * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0. + */ + .macro pre_disable_mmu_workaround +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041 + isb +#endif + .endm + #endif /* __ASM_ASSEMBLER_H */
arch/arm64/kernel/cpu-reset.S +1 -0
@@ -37,6 +37,7 @@ ENTRY(__cpu_soft_restart) mrs x12, sctlr_el1 ldr x13, =SCTLR_ELx_FLAGS bic x12, x12, x13 + pre_disable_mmu_workaround msr sctlr_el1, x12 isb
arch/arm64/kernel/efi-entry.S +2 -0
@@ -96,6 +96,7 @@ ENTRY(entry) mrs x0, sctlr_el2 bic x0, x0, #1 << 0 // clear SCTLR.M bic x0, x0, #1 << 2 // clear SCTLR.C + pre_disable_mmu_workaround msr sctlr_el2, x0 isb b 2f
@@ -103,6 +104,7 @@ ENTRY(entry) mrs x0, sctlr_el1 bic x0, x0, #1 << 0 // clear SCTLR.M bic x0, x0, #1 << 2 // clear SCTLR.C + pre_disable_mmu_workaround msr sctlr_el1, x0 isb 2:
arch/arm64/kernel/head.S +1 -0
@@ -732,6 +732,7 @@ __primary_switch: * to take into account by discarding the current kernel mapping and * creating a new one. */ + pre_disable_mmu_workaround msr sctlr_el1, x20 // disable the MMU isb bl __create_page_tables // recreate kernel mapping
arch/arm64/kernel/relocate_kernel.S +1 -0
@@ -45,6 +45,7 @@ ENTRY(arm64_relocate_new_kernel) mrs x0, sctlr_el2 ldr x1, =SCTLR_ELx_FLAGS bic x0, x0, x1 + pre_disable_mmu_workaround msr sctlr_el2, x0 isb 1:
arch/arm64/kvm/hyp-init.S +1 -0
@@ -151,6 +151,7 @@ reset: mrs x5, sctlr_el2 ldr x6, =SCTLR_ELx_FLAGS bic x5, x5, x6 // Clear SCTL_M and etc + pre_disable_mmu_workaround msr sctlr_el2, x5 isb
Greg Kroah-Hartman
maintainerPATCH 12/195 KVM MMU: check pending exception before injecting APF
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haozhong Zhang <[email protected]>
commit 2a266f23550be997d783f27e704b9b40c4010292 upstream.
For example, when two APF's for page ready happen after one exit and the first one becomes pending, the second one will result in #DF. Instead, just handle the second page fault synchronously.
Message-ID: <CAOxpaSUBf8QoOZQ1p4KfUp0jq76OKfGY4Uxs-Gg8ngReD99xww@mail.gmail.com>
--- arch/x86/kvm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu.c +2 -1
@@ -3784,7 +3784,8 @@ static int kvm_arch_setup_async_pf(strucbool kvm_can_do_async_pf (struct kvm_vcpu *vcpu) {if (unlikely (!lapic_in_kernel (vcpu) || -kvm_event_needs_reinjection (vcpu))) +kvm_event_needs_reinjection (vcpu) || + vcpu->arch.exception.pending))return false;if (!vcpu->arch.apf.delivery_as_pf_vmexit &&is_guest_mode (vcpu))
Greg Kroah-Hartman
maintainerPATCH 13/195 sched/rt: Use container_of() to get root domain in rto_push_irq_work_func()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt (VMware) <[email protected]>
commit ad0f1d9d65938aec72a698116cd73a980916895e upstream.
When the rto_push_irq_work_func() is called, it looks at the RT overloaded bitmask in the root domain via the runqueue (rq->rd). The problem is that during CPU up and down, nothing here stops rq->rd from changing between taking the rq->rd->rto_lock and releasing it. That means the lock that is released is not the same lock that was taken.
Instead of using this_rq()->rd to get the root domain, as the irq work is part of the root domain, we can simply get the root domain from the irq work that is passed to the routine:
container_of(work, struct root_domain, rto_push_work)
This keeps the root domain consistent.
--- kernel/sched/rt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
kernel/sched/rt.c +8 -7
@@ -1907,9 +1907,8 @@ static void push_rt_tasks(struct rq *rq)* the rt_loop_next will cause the iterator to perform another scan. * */ -static int rto_next_cpu (struct rq *rq) +static int rto_next_cpu (struct root_domain *rd) { -struct root_domain *rd = rq->rd;int next;int cpu;
@@ -1985,7 +1984,7 @@ static void tell_cpu_to_push(struct rq ** Otherwise it is finishing up and an ipi needs to be sent. */ if (rq->rd->rto_cpu <0 ) - cpu =rto_next_cpu (rq); + cpu =rto_next_cpu (rq->rd);raw_spin_unlock (&rq->rd->rto_lock);
@@ -1998,6 +1997,8 @@ static void tell_cpu_to_push(struct rq */* Called from hardirq context */ void rto_push_irq_work_func (struct irq_work *work) { +struct root_domain *rd = + container_of(work, struct root_domain, rto_push_work);struct rq *rq;int cpu;
@@ -2013,18 +2014,18 @@ void rto_push_irq_work_func(struct irq_w raw_spin_unlock(&rq->lock); } -raw_spin_lock (&rq->rd->rto_lock); +raw_spin_lock (&rd->rto_lock);/* Pass the IPI to the next rt overloaded queue */ - cpu =rto_next_cpu (rq); + cpu =rto_next_cpu (rd); -raw_spin_unlock (&rq->rd->rto_lock); +raw_spin_unlock (&rd->rto_lock);if (cpu <0 )return ;/* Try the next RT overloaded CPU */ -irq_work_queue_on (&rq->rd->rto_push_work, cpu); +irq_work_queue_on (&rd->rto_push_work, cpu); }#endif /* HAVE_RT_PUSH_IPI */
Greg Kroah-Hartman
maintainerPATCH 14/195 sched/rt: Up the root domain ref count when passing it around via IPIs
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt (VMware) <[email protected]>
commit 364f56653708ba8bcdefd4f0da2a42904baa8eeb upstream.
When issuing an IPI RT push, where an IPI is sent to each CPU that has more than one RT task scheduled on it, it references the root domain's rto_mask, that contains all the CPUs within the root domain that has more than one RT task in the runable state. The problem is, after the IPIs are initiated, the rq->lock is released. This means that the root domain that is associated to the run queue could be freed while the IPIs are going around.
Add a sched_get_rd() and a sched_put_rd() that will increment and decrement the root domain's ref count respectively. This way when initiating the IPIs, the scheduler will up the root domain's ref count before releasing the rq->lock, ensuring that the root domain does not go away until the IPI round is complete.
--- kernel/sched/rt.c | 9 +++++++-- kernel/sched/sched.h | 2 ++ kernel/sched/topology.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-)
kernel/sched/rt.c +7 -2
@@ -1990,8 +1990,11 @@ static void tell_cpu_to_push(struct rq *rto_start_unlock (&rq->rd->rto_loop_start); -if (cpu >=0 ) +if (cpu >=0 ) { +/* Make sure the rd does not get freed while pushing */ +sched_get_rd (rq->rd);irq_work_queue_on (&rq->rd->rto_push_work, cpu); + } }/* Called from hardirq context */
@@ -2021,8 +2024,10 @@ void rto_push_irq_work_func(struct irq_wraw_spin_unlock (&rd->rto_lock); -if (cpu <0 ) +if (cpu <0 ) { +sched_put_rd (rd);return ; + }/* Try the next RT overloaded CPU */ irq_work_queue_on (&rd->rto_push_work, cpu);
kernel/sched/sched.h +2 -0
@@ -661,6 +661,8 @@ extern struct mutex sched_domains_mutex;extern void init_defrootdomain (void );extern int sched_init_domains (const struct cpumask *cpu_map);extern void rq_attach_root (struct rq *rq,struct root_domain *rd); +extern void sched_get_rd (struct root_domain *rd); +extern void sched_put_rd (struct root_domain *rd);#ifdef HAVE_RT_PUSH_IPI extern void rto_push_irq_work_func (struct irq_work *work);
kernel/sched/topology.c +13 -0
@@ -258,6 +258,19 @@ void rq_attach_root(struct rq *rq, struccall_rcu_sched (&old_rd->rcu, free_rootdomain); } +void sched_get_rd (struct root_domain *rd) +{ +atomic_inc (&rd->refcount); +} + +void sched_put_rd (struct root_domain *rd) +{ +if (!atomic_dec_and_test (&rd->refcount)) +return ; + +call_rcu_sched (&rd->rcu, free_rootdomain); +} +static int init_rootdomain (struct root_domain *rd) {if (!zalloc_cpumask_var (&rd->span,GFP_KERNEL ))
Greg Kroah-Hartman
maintainerPATCH 15/195 drm/i915: Add .get_hw_state() method for planes
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ville Syrjälä <[email protected]>
commit d87ce76402950b8e4d5117276d44465658e886a4 upstream.
Add a .get_hw_state() method for planes, returning true or false depending on whether the plane is enabled. Use it to rewrite the plane enabled/disabled asserts in platform agnostic fashion.
We do lose the pre-gen4 plane<->pipe mapping checks, but since we're supposed sanitize that anyway it doesn't really matter.
v2: Reoder patches to not depend on enum old_plane_id
Just call assert_plane_disabled() from assert_planes_disabled()
v3: Deal with disabled power wells in .get_hw_state()
v4: Rebase due skl primary plane code removal
--- drivers/gpu/drm/i915/intel_display.c | 188 ++++++++++++++++------------------- drivers/gpu/drm/i915/intel_drv.h | 2 drivers/gpu/drm/i915/intel_sprite.c | 83 +++++++++++++++ 3 files changed, 175 insertions(+), 98 deletions(-)
drivers/gpu/drm/i915/intel_display.c +90 -98
@@ -1211,23 +1211,6 @@ void assert_panel_unlocked(struct drm_i9 pipe_name(pipe)); } -static void assert_cursor (struct drm_i915_private *dev_priv, -enum pipe pipe,bool state) -{ -bool cur_state; - -if (IS_I845G (dev_priv) ||IS_I865G (dev_priv)) - cur_state =I915_READ (CURCNTR (PIPE_A )) &CURSOR_ENABLE ; -else - cur_state =I915_READ (CURCNTR (pipe)) &CURSOR_MODE ; - -I915_STATE_WARN (cur_state != state, -"cursor on pipe %c assertion failure (expected %s, current %s)\n" , -pipe_name (pipe),onoff (state),onoff (cur_state)); -} -#define assert_cursor_enabled (d, p) assert_cursor(d, p, true) -#define assert_cursor_disabled (d, p) assert_cursor(d, p, false) -void assert_pipe (struct drm_i915_private *dev_priv,enum pipe pipe,bool state) {
@@ -1255,77 +1238,25 @@ void assert_pipe(struct drm_i915_private pipe_name(pipe), onoff(state), onoff(cur_state)); } -static void assert_plane (struct drm_i915_private *dev_priv, -enum plane plane,bool state) +static void assert_plane (struct intel_plane *plane,bool state) { -u32 val; -bool cur_state; +bool cur_state = plane->get_hw_state (plane); - val =I915_READ (DSPCNTR (plane)); - cur_state = !!(val &DISPLAY_PLANE_ENABLE );I915_STATE_WARN (cur_state != state, -"plane %c assertion failure (expected %s, current %s)\n" , -plane_name (plane),onoff (state),onoff (cur_state)); +"%s assertion failure (expected %s, current %s)\n" , + plane->base.name,onoff (state),onoff (cur_state)); } -#define assert_plane_enabled (d, p) assert_plane(d, p, true) -#define assert_plane_disabled (d, p) assert_plane(d, p, false) - -static void assert_planes_disabled (struct drm_i915_private *dev_priv, -enum pipe pipe) -{ -int i; - -/* Primary planes are fixed to pipes on gen4+ */ -if (INTEL_GEN (dev_priv) >=4 ) { -u32 val =I915_READ (DSPCNTR (pipe)); -I915_STATE_WARN (val &DISPLAY_PLANE_ENABLE , -"plane %c assertion failure, should be disabled but not\n" , -plane_name (pipe)); -return ; - } - -/* Need to check both planes against the pipe */ -for_each_pipe (dev_priv, i) { -u32 val =I915_READ (DSPCNTR (i)); -enum pipe cur_pipe = (val &DISPPLANE_SEL_PIPE_MASK ) >> -DISPPLANE_SEL_PIPE_SHIFT ; -I915_STATE_WARN ((val &DISPLAY_PLANE_ENABLE ) && pipe == cur_pipe, -"plane %c assertion failure, should be off on pipe %c but is still active\n" , -plane_name (i),pipe_name (pipe)); - } -} +#define assert_plane_enabled (p) assert_plane(p, true) +#define assert_plane_disabled (p) assert_plane(p, false) -static void assert_sprites_disabled (struct drm_i915_private *dev_priv, -enum pipe pipe) +static void assert_planes_disabled (struct intel_crtc *crtc) { -int sprite; +struct drm_i915_private *dev_priv =to_i915 (crtc->base.dev); +struct intel_plane *plane; -if (INTEL_GEN (dev_priv) >=9 ) { -for_each_sprite (dev_priv, pipe, sprite) { -u32 val =I915_READ (PLANE_CTL (pipe, sprite)); -I915_STATE_WARN (val &PLANE_CTL_ENABLE , -"plane %d assertion failure, should be off on pipe %c but is still active\n" , - sprite,pipe_name (pipe)); - } - }else if (IS_VALLEYVIEW (dev_priv) ||IS_CHERRYVIEW (dev_priv)) { -for_each_sprite (dev_priv, pipe, sprite) { -u32 val =I915_READ (SPCNTR (pipe,PLANE_SPRITE0 + sprite)); -I915_STATE_WARN (val &SP_ENABLE , -"sprite %c assertion failure, should be off on pipe %c but is still active\n" , -sprite_name (pipe, sprite),pipe_name (pipe)); - } - }else if (INTEL_GEN (dev_priv) >=7 ) { -u32 val =I915_READ (SPRCTL (pipe)); -I915_STATE_WARN (val &SPRITE_ENABLE , -"sprite %c assertion failure, should be off on pipe %c but is still active\n" , -plane_name (pipe),pipe_name (pipe)); - }else if (INTEL_GEN (dev_priv) >=5 ||IS_G4X (dev_priv)) { -u32 val =I915_READ (DVSCNTR (pipe)); -I915_STATE_WARN (val &DVS_ENABLE , -"sprite %c assertion failure, should be off on pipe %c but is still active\n" , -plane_name (pipe),pipe_name (pipe)); - } +for_each_intel_plane_on_crtc (&dev_priv->drm, crtc, plane) +assert_plane_disabled (plane); }static void assert_vblank_disabled (struct drm_crtc *crtc)
@@ -1926,9 +1857,7 @@ static void intel_enable_pipe(struct intDRM_DEBUG_KMS ("enabling pipe %c\n" ,pipe_name (pipe)); -assert_planes_disabled (dev_priv, pipe); -assert_cursor_disabled (dev_priv, pipe); -assert_sprites_disabled (dev_priv, pipe); +assert_planes_disabled (crtc);/* * A pipe without a PLL won't actually be able to drive bits from
@@ -1997,9 +1926,7 @@ static void intel_disable_pipe(struct in* Make sure planes won't keep trying to pump pixels to us, * or we might hang the display. */ -assert_planes_disabled (dev_priv, pipe); -assert_cursor_disabled (dev_priv, pipe); -assert_sprites_disabled (dev_priv, pipe); +assert_planes_disabled (crtc); reg =PIPECONF (cpu_transcoder); val =I915_READ (reg);
@@ -3397,6 +3324,31 @@ static void i9xx_disable_primary_plane(sspin_unlock_irqrestore (&dev_priv->uncore.lock, irqflags); } +static bool i9xx_plane_get_hw_state (struct intel_plane *primary) +{ + +struct drm_i915_private *dev_priv =to_i915 (primary->base.dev); +enum intel_display_power_domain power_domain; +enum plane plane = primary->plane; +enum pipe pipe = primary->pipe; +bool ret; + +/* +* Not 100% correct for planes that can move between pipes, +* but that's only the case for gen2-4 which don't have any +* display power wells. +*/ + power_domain =POWER_DOMAIN_PIPE (pipe); +if (!intel_display_power_get_if_enabled (dev_priv, power_domain)) +return false; + + ret =I915_READ (DSPCNTR (plane)) &DISPLAY_PLANE_ENABLE ; + +intel_display_power_put (dev_priv, power_domain); + +return ret; +} +static u32 intel_fb_stride_alignment (const struct drm_framebuffer *fb,int plane) {
@@ -4973,7 +4925,8 @@ void hsw_enable_ips(struct intel_crtc *c* a vblank wait. */ -assert_plane_enabled (dev_priv, crtc->plane); +assert_plane_enabled (to_intel_plane (crtc->base.primary)); +if (IS_BROADWELL (dev_priv)) {mutex_lock (&dev_priv->rps.hw_lock);WARN_ON (sandybridge_pcode_write (dev_priv,DISPLAY_IPS_CONTROL ,0xc0000000 ));
@@ -5005,7 +4958,8 @@ void hsw_disable_ips(struct intel_crtc *if (!crtc->config->ips_enabled)return ; -assert_plane_enabled (dev_priv, crtc->plane); +assert_plane_enabled (to_intel_plane (crtc->base.primary)); +if (IS_BROADWELL (dev_priv)) {mutex_lock (&dev_priv->rps.hw_lock);WARN_ON (sandybridge_pcode_write (dev_priv,DISPLAY_IPS_CONTROL ,0 ));
@@ -9577,6 +9531,23 @@ static void i845_disable_cursor(struct ii845_update_cursor (plane,NULL ,NULL ); } +static bool i845_cursor_get_hw_state (struct intel_plane *plane) +{ +struct drm_i915_private *dev_priv =to_i915 (plane->base.dev); +enum intel_display_power_domain power_domain; +bool ret; + + power_domain =POWER_DOMAIN_PIPE (PIPE_A ); +if (!intel_display_power_get_if_enabled (dev_priv, power_domain)) +return false; + + ret =I915_READ (CURCNTR (PIPE_A )) &CURSOR_ENABLE ; + +intel_display_power_put (dev_priv, power_domain); + +return ret; +} +static u32 i9xx_cursor_ctl (const struct intel_crtc_state *crtc_state,const struct intel_plane_state *plane_state) {
@@ -9770,6 +9741,28 @@ static void i9xx_disable_cursor(struct ii9xx_update_cursor (plane,NULL ,NULL ); } +static bool i9xx_cursor_get_hw_state (struct intel_plane *plane) +{ +struct drm_i915_private *dev_priv =to_i915 (plane->base.dev); +enum intel_display_power_domain power_domain; +enum pipe pipe = plane->pipe; +bool ret; + +/* +* Not 100% correct for planes that can move between pipes, +* but that's only the case for gen2-3 which don't have any +* display power wells. +*/ + power_domain =POWER_DOMAIN_PIPE (pipe); +if (!intel_display_power_get_if_enabled (dev_priv, power_domain)) +return false; + + ret =I915_READ (CURCNTR (pipe)) &CURSOR_MODE ; + +intel_display_power_put (dev_priv, power_domain); + +return ret; +}/* VESA 640x480x72Hz mode to set on the pipe */ static struct drm_display_mode load_detect_mode = {
@@ -13240,6 +13233,7 @@ intel_primary_plane_create(struct drm_i9 primary->update_plane = skylake_update_primary_plane; primary->disable_plane = skylake_disable_primary_plane; + primary->get_hw_state = skl_plane_get_hw_state; }else if (INTEL_GEN (dev_priv) >=9 ) { intel_primary_formats = skl_primary_formats; num_formats =ARRAY_SIZE (skl_primary_formats);
@@ -13250,6 +13244,7 @@ intel_primary_plane_create(struct drm_i9 primary->update_plane = skylake_update_primary_plane; primary->disable_plane = skylake_disable_primary_plane; + primary->get_hw_state = skl_plane_get_hw_state; }else if (INTEL_GEN (dev_priv) >=4 ) { intel_primary_formats = i965_primary_formats; num_formats =ARRAY_SIZE (i965_primary_formats);
@@ -13257,6 +13252,7 @@ intel_primary_plane_create(struct drm_i9 primary->update_plane = i9xx_update_primary_plane; primary->disable_plane = i9xx_disable_primary_plane; + primary->get_hw_state = i9xx_plane_get_hw_state; }else { intel_primary_formats = i8xx_primary_formats; num_formats =ARRAY_SIZE (i8xx_primary_formats);
@@ -13264,6 +13260,7 @@ intel_primary_plane_create(struct drm_i9 primary->update_plane = i9xx_update_primary_plane; primary->disable_plane = i9xx_disable_primary_plane; + primary->get_hw_state = i9xx_plane_get_hw_state; }if (INTEL_GEN (dev_priv) >=9 )
@@ -13353,10 +13350,12 @@ intel_cursor_plane_create(struct drm_i91if (IS_I845G (dev_priv) ||IS_I865G (dev_priv)) { cursor->update_plane = i845_update_cursor; cursor->disable_plane = i845_disable_cursor; + cursor->get_hw_state = i845_cursor_get_hw_state; cursor->check_plane = i845_check_cursor; }else { cursor->update_plane = i9xx_update_cursor; cursor->disable_plane = i9xx_disable_cursor; + cursor->get_hw_state = i9xx_cursor_get_hw_state; cursor->check_plane = i9xx_check_cursor; }
@@ -14704,8 +14703,8 @@ void i830_disable_pipe(struct drm_i915_pDRM_DEBUG_KMS ("disabling pipe %c due to force quirk\n" ,pipe_name (pipe)); -assert_plane_disabled (dev_priv,PLANE_A ); -assert_plane_disabled (dev_priv,PLANE_B ); +assert_planes_disabled (intel_get_crtc_for_pipe (dev_priv,PIPE_A )); +assert_planes_disabled (intel_get_crtc_for_pipe (dev_priv,PIPE_B ));I915_WRITE (PIPECONF (pipe),0 );POSTING_READ (PIPECONF (pipe));
@@ -14918,20 +14917,13 @@ void i915_redisable_vga(struct drm_i915_intel_display_power_put (dev_priv,POWER_DOMAIN_VGA ); } -static bool primary_get_hw_state (struct intel_plane *plane) -{ -struct drm_i915_private *dev_priv =to_i915 (plane->base.dev); - -return I915_READ (DSPCNTR (plane->plane)) &DISPLAY_PLANE_ENABLE ; -} -/* FIXME read out full plane state for all planes */ static void readout_plane_state (struct intel_crtc *crtc) {struct intel_plane *primary =to_intel_plane (crtc->base.primary);bool visible; - visible = crtc->active &&primary_get_hw_state (primary); + visible = crtc->active && primary->get_hw_state (primary); intel_set_plane_visible(to_intel_crtc_state(crtc->base.state), to_intel_plane_state(primary->base.state),
drivers/gpu/drm/i915/intel_drv.h +2 -0
@@ -863,6 +863,7 @@ struct intel_plane { const struct intel_plane_state *plane_state);void (*disable_plane)(struct intel_plane *plane,struct intel_crtc *crtc); +bool (*get_hw_state)(struct intel_plane *plane);int (*check_plane)(struct intel_plane *plane,struct intel_crtc_state *crtc_state,struct intel_plane_state *state);
@@ -1885,6 +1886,7 @@ int intel_sprite_set_colorkey(struct drm struct drm_file *file_priv);void intel_pipe_update_start (struct intel_crtc *crtc);void intel_pipe_update_end (struct intel_crtc *crtc); +bool skl_plane_get_hw_state (struct intel_plane *plane);/* intel_tv.c */ void intel_tv_init (struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/intel_sprite.c +83 -0
137 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 16/195 drm/i915: Redo plane sanitation during readout
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ville Syrjälä <[email protected]>
commit 23ac12732825901b3fc6ac720958d8bff9a0d6ec upstream.
Unify the plane disabling during state readout by pulling the code into a new helper intel_plane_disable_noatomic(). We'll also read out the state of all planes, so that we know which planes really need to be diabled.
Additonally we change the plane<->pipe mapping sanitation to work by simply disabling the offending planes instead of entire pipes. And we do it before we otherwise sanitize the crtcs, which means we don't have to worry about misassigned planes during crtc sanitation anymore.
v2: Reoder patches to not depend on enum old_plane_id
v3: s/for_each_pipe/for_each_intel_crtc/
Cc: Thierry Reding <[email protected]>
Cc: Alex Villacís Lasso <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103223
--- drivers/gpu/drm/i915/intel_display.c | 114 +++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 49 deletions(-)
drivers/gpu/drm/i915/intel_display.c +65 -49
@@ -2756,6 +2756,23 @@ intel_set_plane_visible(struct intel_crt crtc_state->active_planes); } +static void intel_plane_disable_noatomic (struct intel_crtc *crtc, +struct intel_plane *plane) +{ +struct intel_crtc_state *crtc_state = +to_intel_crtc_state (crtc->base.state); +struct intel_plane_state *plane_state = +to_intel_plane_state (plane->base.state); + +intel_set_plane_visible (crtc_state, plane_state, false); + +if (plane->id ==PLANE_PRIMARY ) +intel_pre_disable_primary_noatomic (&crtc->base); + +trace_intel_disable_plane (&plane->base, crtc); + plane->disable_plane (plane, crtc); +} +static void intel_find_initial_plane_obj (struct intel_crtc *intel_crtc,struct intel_initial_plane_config *plane_config)
@@ -2813,12 +2830,7 @@ intel_find_initial_plane_obj(struct inte* simplest solution is to just disable the primary plane now and * pretend the BIOS never had it enabled. */ -intel_set_plane_visible (to_intel_crtc_state (crtc_state), -to_intel_plane_state (plane_state), - false); -intel_pre_disable_primary_noatomic (&intel_crtc->base); -trace_intel_disable_plane (primary, intel_crtc); - intel_plane->disable_plane (intel_plane, intel_crtc); +intel_plane_disable_noatomic (intel_crtc, intel_plane);return ;
@@ -5954,6 +5966,7 @@ static void intel_crtc_disable_noatomic(struct intel_crtc *intel_crtc =to_intel_crtc (crtc);struct drm_i915_private *dev_priv =to_i915 (crtc->dev);enum intel_display_power_domain domain; +struct intel_plane *plane;u64 domains;struct drm_atomic_state *state;struct intel_crtc_state *crtc_state;
@@ -5962,11 +5975,12 @@ static void intel_crtc_disable_noatomic(if (!intel_crtc->active)return ; -if (crtc->primary->state->visible) { -intel_pre_disable_primary_noatomic (crtc); +for_each_intel_plane_on_crtc (&dev_priv->drm, intel_crtc, plane) { +const struct intel_plane_state *plane_state = +to_intel_plane_state (plane->base.state); -intel_crtc_disable_planes (crtc,1 <<drm_plane_index (crtc->primary)); - crtc->primary->state->visible = false; +if (plane_state->base.visible) +intel_plane_disable_noatomic (intel_crtc, plane); } state =drm_atomic_state_alloc (crtc->dev);
@@ -14715,22 +14729,36 @@ void i830_disable_pipe(struct drm_i915_pPOSTING_READ (DPLL (pipe)); } -static bool -intel_check_plane_mapping (struct intel_crtc *crtc) +static bool intel_plane_mapping_ok (struct intel_crtc *crtc, +struct intel_plane *primary) {struct drm_i915_private *dev_priv =to_i915 (crtc->base.dev); -u32 val; +enum plane plane = primary->plane; +u32 val =I915_READ (DSPCNTR (plane)); -if (INTEL_INFO (dev_priv)->num_pipes ==1 ) -return true; +return (val &DISPLAY_PLANE_ENABLE ) ==0 || + (val &DISPPLANE_SEL_PIPE_MASK ) ==DISPPLANE_SEL_PIPE (crtc->pipe); +} - val =I915_READ (DSPCNTR (!crtc->plane)); +static void +intel_sanitize_plane_mapping (struct drm_i915_private *dev_priv) +{ +struct intel_crtc *crtc; -if ((val &DISPLAY_PLANE_ENABLE ) && - (!!(val &DISPPLANE_SEL_PIPE_MASK ) == crtc->pipe)) -return false; +if (INTEL_GEN (dev_priv) >=4 ) +return ; -return true; +for_each_intel_crtc (&dev_priv->drm, crtc) { +struct intel_plane *plane = +to_intel_plane (crtc->base.primary); + +if (intel_plane_mapping_ok (crtc, plane)) +continue ; + +DRM_DEBUG_KMS ("%s attached to the wrong pipe, disabling plane\n" , + plane->base.name); +intel_plane_disable_noatomic (crtc, plane); + } }static bool intel_crtc_has_encoders (struct intel_crtc *crtc)
@@ -14786,33 +14814,15 @@ static void intel_sanitize_crtc(struct i/* Disable everything but the primary plane */ for_each_intel_plane_on_crtc (dev, crtc, plane) { -if (plane->base.type ==DRM_PLANE_TYPE_PRIMARY ) -continue ; +const struct intel_plane_state *plane_state = +to_intel_plane_state (plane->base.state); -trace_intel_disable_plane (&plane->base, crtc); - plane->disable_plane (plane, crtc); +if (plane_state->base.visible && + plane->base.type !=DRM_PLANE_TYPE_PRIMARY ) +intel_plane_disable_noatomic (crtc, plane); } } -/* We need to sanitize the plane -> pipe mapping first because this will -* disable the crtc (and hence change the state) if it is wrong. Note -* that gen4+ has a fixed plane -> pipe mapping. */ -if (INTEL_GEN (dev_priv) <4 && !intel_check_plane_mapping (crtc)) { -bool plane; - -DRM_DEBUG_KMS ("[CRTC:%d:%s] wrong plane connection detected!\n" , - crtc->base.base.id, crtc->base.name); - -/* Pipe has the wrong plane attached and the plane is active. -* Temporarily change the plane mapping and disable everything -* ... */ - plane = crtc->plane; - crtc->base.primary->state->visible = true; - crtc->plane = !plane; -intel_crtc_disable_noatomic (&crtc->base, ctx); - crtc->plane = plane; - } -/* Adjust the state of the output pipe according to whether we * have active connectors/encoders. */ if (crtc->active && !intel_crtc_has_encoders (crtc))
@@ -14920,14 +14930,18 @@ void i915_redisable_vga(struct drm_i915_/* FIXME read out full plane state for all planes */ static void readout_plane_state (struct intel_crtc *crtc) { -struct intel_plane *primary =to_intel_plane (crtc->base.primary); -bool visible; +struct drm_i915_private *dev_priv =to_i915 (crtc->base.dev); +struct intel_crtc_state *crtc_state = +to_intel_crtc_state (crtc->base.state); +struct intel_plane *plane; - visible = crtc->active && primary->get_hw_state (primary); +for_each_intel_plane_on_crtc (&dev_priv->drm, crtc, plane) { +struct intel_plane_state *plane_state = +to_intel_plane_state (plane->base.state); +bool visible = plane->get_hw_state (plane); -intel_set_plane_visible (to_intel_crtc_state (crtc->base.state), -to_intel_plane_state (primary->base.state), - visible); +intel_set_plane_visible (crtc_state, plane_state, visible); + } }static void intel_modeset_readout_hw_state (struct drm_device *dev)
@@ -15129,6 +15143,8 @@ intel_modeset_setup_hw_state(struct drm_/* HW state is read out, now we need to sanitize this mess. */ get_encoder_power_domains (dev_priv); +intel_sanitize_plane_mapping (dev_priv); +for_each_intel_encoder (dev, encoder) {intel_sanitize_encoder (encoder); }
Greg Kroah-Hartman
maintainerPATCH 17/195 drm/i915: Fix deadlock in i830_disable_pipe()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ville Syrjälä <[email protected]>
commit 4488496d58200c7511842e049a4cc891d928da56 upstream.
i830_disable_pipe() gets called from the power well code, and thus we're already holding the power domain mutex. That means we can't call plane->get_hw_state() as it will also try to grab the same mutex and will thus deadlock.
Replace the assert_plane() calls (which calls ->get_hw_state()) with just raw register reads in i830_disable_pipe(). As a bonus we can now get a warning if plane C is enabled even though we don't even expose it as a drm plane.
v2: Do a separate WARN_ON() for each plane (Chris)
--- drivers/gpu/drm/i915/intel_display.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +5 -2
@@ -14717,8 +14717,11 @@ void i830_disable_pipe(struct drm_i915_pDRM_DEBUG_KMS ("disabling pipe %c due to force quirk\n" ,pipe_name (pipe)); -assert_planes_disabled (intel_get_crtc_for_pipe (dev_priv,PIPE_A )); -assert_planes_disabled (intel_get_crtc_for_pipe (dev_priv,PIPE_B )); +WARN_ON (I915_READ (DSPCNTR (PLANE_A )) &DISPLAY_PLANE_ENABLE ); +WARN_ON (I915_READ (DSPCNTR (PLANE_B )) &DISPLAY_PLANE_ENABLE ); +WARN_ON (I915_READ (DSPCNTR (PLANE_C )) &DISPLAY_PLANE_ENABLE ); +WARN_ON (I915_READ (CURCNTR (PIPE_A )) &CURSOR_MODE ); +WARN_ON (I915_READ (CURCNTR (PIPE_B )) &CURSOR_MODE );I915_WRITE (PIPECONF (pipe),0 );POSTING_READ (PIPECONF (pipe));
Greg Kroah-Hartman
maintainerPATCH 18/195 dccp: CVE-2017-8824: use-after-free in DCCP code
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohamed Ghannam <[email protected]>
commit 69c64866ce072dea1d1e59a0d61e0f66c0dffb76 upstream.
Whenever the sock object is in DCCP_CLOSED state, dccp_disconnect() must free dccps_hc_tx_ccid and dccps_hc_rx_ccid and set to NULL.
--- net/dccp/proto.c | 5 +++++ 1 file changed, 5 insertions(+)
net/dccp/proto.c +5 -0
@@ -259,6 +259,7 @@ int dccp_disconnect(struct sock *sk, int {struct inet_connection_sock *icsk =inet_csk (sk);struct inet_sock *inet =inet_sk (sk); +struct dccp_sock *dp =dccp_sk (sk);int err =0 ;const int old_state = sk->sk_state;
@@ -278,6 +279,10 @@ int dccp_disconnect(struct sock *sk, int sk->sk_err =ECONNRESET ;dccp_clear_xmit_timers (sk); +ccid_hc_rx_delete (dp->dccps_hc_rx_ccid, sk); +ccid_hc_tx_delete (dp->dccps_hc_tx_ccid, sk); + dp->dccps_hc_rx_ccid =NULL ; + dp->dccps_hc_tx_ccid =NULL ;__skb_queue_purge (&sk->sk_receive_queue);__skb_queue_purge (&sk->sk_write_queue);
Greg Kroah-Hartman
maintainerPATCH 20/195 media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Malcolm Priestley <[email protected]>
commit 7bf7a7116ed313c601307f7e585419369926ab05 upstream.
When the tuner was split from m88rs2000 the attach function is in wrong place.
Move to dm04_lme2510_tuner to trap errors on failure and removing a call to lme_coldreset.
Prevents driver starting up without any tuner connected.
Fixes to trap for ts2020 fail.
LME2510(C): FE Found M88RS2000
ts2020: probe of 0-0060 failed with error -11
...
LME2510(C): TUN Found RS2000 tuner
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN
--- drivers/media/usb/dvb-usb-v2/lmedm04.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +6 -7
@@ -1076,8 +1076,6 @@ static int dm04_lme2510_frontend_attach(if (adap->fe[0 ]) {info ("FE Found M88RS2000" ); -dvb_attach (ts2020_attach, adap->fe[0 ], &ts2020_config, - &d->i2c_adap); st->i2c_tuner_gate_w =5 ; st->i2c_tuner_gate_r =5 ; st->i2c_tuner_addr =0x60 ;
@@ -1143,17 +1141,18 @@ static int dm04_lme2510_tuner(struct dvb ret = st->tuner_config;break ;case TUNER_RS2000 : - ret = st->tuner_config; +if (dvb_attach (ts2020_attach, adap->fe[0 ], + &ts2020_config, &d->i2c_adap)) + ret = st->tuner_config;break ;default :break ; } -if (ret) +if (ret) {info ("TUN Found %s tuner" , tun_msg[ret]); -else { -info ("TUN No tuner found --- resetting device" ); -lme_coldreset (d); + }else { +info ("TUN No tuner found" );return -ENODEV ; }
Greg Kroah-Hartman
maintainerPATCH 21/195 media: hdpvr: Fix an error handling path in hdpvr_probe()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arvind Yadav <[email protected]>
commit c0f71bbb810237a38734607ca4599632f7f5d47f upstream.
Here, hdpvr_register_videodev() is responsible for setup and register a video device. Also defining and initializing a worker. hdpvr_register_videodev() is calling by hdpvr_probe at last. So no need to flush any work here.
Unregister v4l2, free buffers and memory. If hdpvr_probe() will fail.
--- drivers/media/usb/hdpvr/hdpvr-core.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/media/usb/hdpvr/hdpvr-core.c +15 -11
@@ -292,7 +292,7 @@ static int hdpvr_probe(struct usb_interf/* register v4l2_device early so it can be used for printks */ if (v4l2_device_register (&interface->dev, &dev->v4l2_dev)) {dev_err (&interface->dev,"v4l2_device_register failed\n" ); - goto error; + goto error_free_dev; }mutex_init (&dev->io_mutex);
@@ -301,7 +301,7 @@ static int hdpvr_probe(struct usb_interf dev->usbc_buf =kmalloc (64 ,GFP_KERNEL );if (!dev->usbc_buf) {v4l2_err (&dev->v4l2_dev,"Out of memory\n" ); - goto error; + goto error_v4l2_unregister; }init_waitqueue_head (&dev->wait_buffer);
@@ -339,13 +339,13 @@ static int hdpvr_probe(struct usb_interf }if (!dev->bulk_in_endpointAddr) {v4l2_err (&dev->v4l2_dev,"Could not find bulk-in endpoint\n" ); - goto error; + goto error_put_usb; }/* init the device */ if (hdpvr_device_init (dev)) {v4l2_err (&dev->v4l2_dev,"device init failed\n" ); - goto error; + goto error_put_usb; }mutex_lock (&dev->io_mutex);
@@ -353,7 +353,7 @@ static int hdpvr_probe(struct usb_interfmutex_unlock (&dev->io_mutex);v4l2_err (&dev->v4l2_dev,"allocating transfer buffers failed\n" ); - goto error; + goto error_put_usb; }mutex_unlock (&dev->io_mutex);
@@ -361,7 +361,7 @@ static int hdpvr_probe(struct usb_interf retval =hdpvr_register_i2c_adapter (dev);if (retval <0 ) {v4l2_err (&dev->v4l2_dev,"i2c adapter register failed\n" ); - goto error; + goto error_free_buffers; } client =hdpvr_register_ir_rx_i2c (dev);
@@ -394,13 +394,17 @@ static int hdpvr_probe(struct usb_interf reg_fail:#if IS_ENABLED (CONFIG_I2C )i2c_del_adapter (&dev->i2c_adapter); +error_free_buffers:#endif +hdpvr_free_buffers (dev); +error_put_usb: +usb_put_dev (dev->udev); +kfree (dev->usbc_buf); +error_v4l2_unregister: +v4l2_device_unregister (&dev->v4l2_dev); +error_free_dev: +kfree (dev); error: -if (dev) { -flush_work (&dev->worker); -/* this frees allocated memory */ -hdpvr_delete (dev); - }return retval; }
Greg Kroah-Hartman
maintainerPATCH 22/195 arm64: move TASK_* definitions to <asm/processor.h>
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yury Norov <[email protected]>
Commit eef94a3d09aa upstream.
ILP32 series [1] introduces the dependency on <asm/is_compat.h> for TASK_SIZE macro. Which in turn requires <asm/thread_info.h>, and <asm/thread_info.h> include <asm/memory.h>, giving a circular dependency, because TASK_SIZE is currently located in <asm/memory.h>.
In other architectures, TASK_SIZE is defined in <asm/processor.h>, and moving TASK_SIZE there fixes the problem.
Discussion: https://patchwork.kernel.org/patch/9929107/
[1] https://github.com/norov/linux/tree/ilp32-next
--- arch/arm64/include/asm/memory.h | 15 --------------- arch/arm64/include/asm/processor.h | 21 +++++++++++++++++++++ arch/arm64/kernel/entry.S | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-)
arch/arm64/include/asm/memory.h +0 -15
@@ -61,8 +61,6 @@* KIMAGE_VADDR - the virtual address of the start of the kernel image * VA_BITS - the maximum number of bits for virtual addresses. * VA_START - the first kernel virtual address. -* TASK_SIZE - the maximum size of a user space task. -* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. */ #define VA_BITS (CONFIG_ARM64_VA_BITS)#define VA_START (UL(0xffffffffffffffff) - \
@@ -77,19 +75,6 @@#define PCI_IO_END (VMEMMAP_START - SZ_2M)#define PCI_IO_START (PCI_IO_END - PCI_IO_SIZE)#define FIXADDR_TOP (PCI_IO_START - SZ_2M) -#define TASK_SIZE_64 (UL(1) << VA_BITS) - -#ifdef CONFIG_COMPAT -#define TASK_SIZE_32 UL(0x100000000) -#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ - TASK_SIZE_32 : TASK_SIZE_64) -#define TASK_SIZE_OF (tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ - TASK_SIZE_32 : TASK_SIZE_64) -#else -#define TASK_SIZE TASK_SIZE_64 -#endif /* CONFIG_COMPAT */ - -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4))#define KERNEL_START _text#define KERNEL_END _end
arch/arm64/include/asm/processor.h +21 -0
@@ -19,6 +19,10 @@#ifndef __ASM_PROCESSOR_H#define __ASM_PROCESSOR_H +#define TASK_SIZE_64 (UL(1) << VA_BITS) + +#ifndef __ASSEMBLY__ +/* * Default implementation of macro that returns current * instruction pointer ("program counter").
@@ -37,6 +41,22 @@#include <asm/ptrace.h> #include <asm/types.h> +/* +* TASK_SIZE - the maximum size of a user space task. +* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. +*/ +#ifdef CONFIG_COMPAT +#define TASK_SIZE_32 UL(0x100000000) +#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ + TASK_SIZE_32 : TASK_SIZE_64) +#define TASK_SIZE_OF (tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ + TASK_SIZE_32 : TASK_SIZE_64) +#else +#define TASK_SIZE TASK_SIZE_64 +#endif /* CONFIG_COMPAT */ + +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) +#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000
@@ -194,4 +214,5 @@ static inline void spin_lock_prefetch(coint cpu_enable_pan (void *__unused);int cpu_enable_cache_maint_trap (void *__unused); +#endif /* __ASSEMBLY__ */ #endif /* __ASM_PROCESSOR_H */
arch/arm64/kernel/entry.S +1 -1
@@ -28,7 +28,7 @@ #include <asm/errno.h> #include <asm/esr.h> #include <asm/irq.h> -#include <asm/memory.h> +#include <asm/processor.h> #include <asm/ptrace.h> #include <asm/thread_info.h> #include <asm/asm-uaccess.h>
Greg Kroah-Hartman
maintainerPATCH 23/195 arm64: mm: Use non-global mappings for kernel space
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit e046eb0c9bf2 upstream.
In preparation for unmapping the kernel whilst running in userspace, make the kernel mappings non-global so we can avoid expensive TLB invalidation on kernel exit to userspace.
--- arch/arm64/include/asm/kernel-pgtable.h | 12 ++++++++++-- arch/arm64/include/asm/pgtable-prot.h | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-)
arch/arm64/include/asm/kernel-pgtable.h +10 -2
@@ -78,8 +78,16 @@/* * Initial memory map attributes. */ -#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define _SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define _SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define SWAPPER_PTE_FLAGS (_SWAPPER_PTE_FLAGS | PTE_NG) +#define SWAPPER_PMD_FLAGS (_SWAPPER_PMD_FLAGS | PMD_SECT_NG) +#else +#define SWAPPER_PTE_FLAGS _SWAPPER_PTE_FLAGS +#define SWAPPER_PMD_FLAGS _SWAPPER_PMD_FLAGS +#endif #if ARM64_SWAPPER_USES_SECTION_MAPS #define SWAPPER_MM_MMUFLAGS (PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
arch/arm64/include/asm/pgtable-prot.h +15 -6
@@ -34,8 +34,16 @@#include <asm/pgtable-types.h> -#define PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define PROT_DEFAULT (_PROT_DEFAULT | PTE_NG) +#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_SECT_NG) +#else +#define PROT_DEFAULT _PROT_DEFAULT +#define PROT_SECT_DEFAULT _PROT_SECT_DEFAULT +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))#define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
@@ -48,6 +56,7 @@#define PROT_SECT_NORMAL_EXEC (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))#define _PAGE_DEFAULT (PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) +#define _HYP_PAGE_DEFAULT (_PAGE_DEFAULT & ~PTE_NG)#define PAGE_KERNEL __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE)#define PAGE_KERNEL_RO __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_RDONLY)
@@ -55,15 +64,15 @@#define PAGE_KERNEL_EXEC __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE)#define PAGE_KERNEL_EXEC_CONT __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_CONT) -#define PAGE_HYP __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN) -#define PAGE_HYP_EXEC __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY) -#define PAGE_HYP_RO __pgprot(_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY | PTE_HYP_XN) +#define PAGE_HYP __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN) +#define PAGE_HYP_EXEC __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY) +#define PAGE_HYP_RO __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY | PTE_HYP_XN)#define PAGE_HYP_DEVICE __pgprot(PROT_DEVICE_nGnRE | PTE_HYP)#define PAGE_S2 __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_S2_RDONLY)#define PAGE_S2_DEVICE __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_UXN) -#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_PXN | PTE_UXN) +#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)#define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)#define PAGE_SHARED_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_WRITE)#define PAGE_READONLY __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
Greg Kroah-Hartman
maintainerPATCH 24/195 arm64: mm: Temporarily disable ARM64_SW_TTBR0_PAN
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 376133b7edc2 upstream.
We're about to rework the way ASIDs are allocated, switch_mm is implemented and low-level kernel entry/exit is handled, so keep the ARM64_SW_TTBR0_PAN code out of the way whilst we do the heavy lifting.
It will be re-enabled in a subsequent patch.
--- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/Kconfig +1 -0
@@ -882,6 +882,7 @@ endif config ARM64_SW_TTBR0_PAN bool "Emulate Privileged Access Never using TTBR0_EL1 switching" + depends on BROKEN # Temporary while switch_mm is reworked help Enabling this option prevents the kernel from accessing user-space memory directly by pointing TTBR0_EL1 to a reserved
Greg Kroah-Hartman
maintainerPATCH 25/195 arm64: mm: Move ASID from TTBR0 to TTBR1
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 7655abb95386 upstream.
In preparation for mapping kernelspace and userspace with different ASIDs, move the ASID to TTBR1 and update switch_mm to context-switch TTBR0 via an invalid mapping (the zero page).
--- arch/arm64/include/asm/mmu_context.h | 7 +++++++ arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/proc-fns.h | 6 ------ arch/arm64/mm/proc.S | 9 ++++++--- 4 files changed, 14 insertions(+), 9 deletions(-)
arch/arm64/include/asm/mmu_context.h +7 -0
@@ -57,6 +57,13 @@ static inline void cpu_set_reserved_ttbrisb (); } +static inline void cpu_switch_mm (pgd_t *pgd,struct mm_struct *mm) +{ +BUG_ON (pgd == swapper_pg_dir); +cpu_set_reserved_ttbr0 (); +cpu_do_switch_mm (virt_to_phys (pgd),mm); +} +/* * TCR.T0SZ value to use when the ID map is active. Usually equals * TCR_T0SZ(VA_BITS), unless system RAM is positioned very high in
arch/arm64/include/asm/pgtable-hwdef.h +1 -0
@@ -272,6 +272,7 @@#define TCR_TG1_4K (UL(2) << TCR_TG1_SHIFT)#define TCR_TG1_64K (UL(3) << TCR_TG1_SHIFT) +#define TCR_A1 (UL(1) << 22)#define TCR_ASID16 (UL(1) << 36)#define TCR_TBI0 (UL(1) << 37)#define TCR_HA (UL(1) << 39)
arch/arm64/include/asm/proc-fns.h +0 -6
@@ -35,12 +35,6 @@ extern u64 cpu_do_resume(phys_addr_t ptr#include <asm/memory.h> -#define cpu_switch_mm (pgd,mm) \ -do { \ - BUG_ON(pgd == swapper_pg_dir); \ - cpu_do_switch_mm(virt_to_phys(pgd),mm); \ -} while (0) -#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* __ASM_PROCFNS_H */
arch/arm64/mm/proc.S +6 -3
@@ -139,9 +139,12 @@ ENDPROC(cpu_do_resume) */ ENTRY(cpu_do_switch_mm) pre_ttbr0_update_workaround x0, x2, x3 + mrs x2, ttbr1_el1 mmid x1, x1 // get mm->context.id - bfi x0, x1, #48, #16 // set the ASID - msr ttbr0_el1, x0 // set TTBR0 + bfi x2, x1, #48, #16 // set the ASID + msr ttbr1_el1, x2 // in TTBR1 (since TCR.A1 is set) + isb + msr ttbr0_el1, x0 // now update TTBR0 isb post_ttbr0_update_workaround ret
@@ -225,7 +228,7 @@ ENTRY(__cpu_setup) * both user and kernel. */ ldr x10, =TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ - TCR_TG_FLAGS | TCR_ASID16 | TCR_TBI0 + TCR_TG_FLAGS | TCR_ASID16 | TCR_TBI0 | TCR_A1 tcr_set_idmap_t0sz x10, x9 /*
Greg Kroah-Hartman
maintainerPATCH 26/195 arm64: mm: Remove pre_ttbr0_update_workaround for Falkor erratum #E1003
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 85d13c001497 upstream.
The pre_ttbr0_update_workaround hook is called prior to context-switching TTBR0 because Falkor erratum E1003 can cause TLB allocation with the wrong ASID if both the ASID and the base address of the TTBR are updated at the same time.
With the ASID sitting safely in TTBR1, we no longer update things atomically, so we can remove the pre_ttbr0_update_workaround macro as it's no longer required. The erratum infrastructure and documentation is left around for #E1003, as it will be required by the entry trampoline code in a future patch.
--- arch/arm64/include/asm/assembler.h | 22 ---------------------- arch/arm64/include/asm/mmu_context.h | 2 -- arch/arm64/mm/context.c | 11 ----------- arch/arm64/mm/proc.S | 1 - 4 files changed, 36 deletions(-)
arch/arm64/include/asm/assembler.h +0 -22
@@ -25,7 +25,6 @@#include <asm/asm-offsets.h> #include <asm/cpufeature.h> -#include <asm/mmu_context.h> #include <asm/page.h> #include <asm/pgtable-hwdef.h> #include <asm/ptrace.h>
@@ -465,27 +464,6 @@ alternative_endif .endm/* - * Errata workaround prior to TTBR0_EL1 update - * - * val: TTBR value with new BADDR, preserved - * tmp0: temporary register, clobbered - * tmp1: other temporary register, clobbered - */ - .macro pre_ttbr0_update_workaround, val, tmp0, tmp1 -#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 -alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003 - mrs \tmp0, ttbr0_el1 - mov \tmp1, #FALKOR_RESERVED_ASID - bfi \tmp0, \tmp1, #48, #16 // reserved ASID + old BADDR - msr ttbr0_el1, \tmp0 - isb - bfi \tmp0, \val, #0, #48 // reserved ASID + new BADDR - msr ttbr0_el1, \tmp0 - isb -alternative_else_nop_endif -#endif - .endm -/* * Errata workaround post TTBR0_EL1 update. */
arch/arm64/include/asm/mmu_context.h +0 -2
@@ -19,8 +19,6 @@#ifndef __ASM_MMU_CONTEXT_H#define __ASM_MMU_CONTEXT_H -#define FALKOR_RESERVED_ASID 1 -#ifndef __ASSEMBLY__#include <linux/compiler.h>
arch/arm64/mm/context.c +0 -11
@@ -79,13 +79,6 @@ void verify_cpu_asid_bits(void) } } -static void set_reserved_asid_bits (void ) -{ -if (IS_ENABLED (CONFIG_QCOM_FALKOR_ERRATUM_1003 ) && -cpus_have_const_cap (ARM64_WORKAROUND_QCOM_FALKOR_E1003 )) -__set_bit (FALKOR_RESERVED_ASID , asid_map); -} -static void flush_context (unsigned int cpu) {int i;
@@ -94,8 +87,6 @@ static void flush_context(unsigned int c/* Update the list of reserved ASIDs and the ASID bitmap. */ bitmap_clear (asid_map,0 ,NUM_USER_ASIDS ); -set_reserved_asid_bits (); -/* * Ensure the generation bump is observed before we xchg the * active_asids.
@@ -250,8 +241,6 @@ static int asids_init(void)panic ("Failed to allocate bitmap for %lu ASIDs\n" ,NUM_USER_ASIDS ); -set_reserved_asid_bits (); -pr_info ("ASID allocator initialised with %lu entries\n" ,NUM_USER_ASIDS );return 0 ; }
arch/arm64/mm/proc.S +0 -1
@@ -138,7 +138,6 @@ ENDPROC(cpu_do_resume) * - pgd_phys - physical address of new TTB */ ENTRY(cpu_do_switch_mm) - pre_ttbr0_update_workaround x0, x2, x3 mrs x2, ttbr1_el1 mmid x1, x1 // get mm->context.id bfi x2, x1, #48, #16 // set the ASID
Greg Kroah-Hartman
maintainerPATCH 27/195 arm64: mm: Rename post_ttbr0_update_workaround
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 158d495899ce upstream.
The post_ttbr0_update_workaround hook applies to any change to TTBRx_EL1. Since we're using TTBR1 for the ASID, rename the hook to make it clearer as to what it's doing.
--- arch/arm64/include/asm/assembler.h | 5 ++--- arch/arm64/kernel/entry.S | 2 +- arch/arm64/mm/proc.S | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-)
arch/arm64/include/asm/assembler.h +2 -3
@@ -464,10 +464,9 @@ alternative_endif .endm /* -/* - * Errata workaround post TTBR0_EL1 update. + * Errata workaround post TTBRx_EL1 update. */ - .macro post_ttbr0_update_workaround + .macro post_ttbr_update_workaround#ifdef CONFIG_CAVIUM_ERRATUM_27456 alternative_if ARM64_WORKAROUND_CAVIUM_27456ic iallu
arch/arm64/kernel/entry.S +1 -1
@@ -255,7 +255,7 @@ alternative_else_nop_endif * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache * corruption). */ - post_ttbr0_update_workaround + post_ttbr_update_workaround .endif 1: .if \el != 0
arch/arm64/mm/proc.S +1 -1
@@ -145,7 +145,7 @@ ENTRY(cpu_do_switch_mm) isb msr ttbr0_el1, x0 // now update TTBR0 isb - post_ttbr0_update_workaround + post_ttbr_update_workaround ret ENDPROC(cpu_do_switch_mm)
Greg Kroah-Hartman
maintainerPATCH 29/195 arm64: mm: Allocate ASIDs in pairs
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 0c8ea531b774 upstream.
In preparation for separate kernel/user ASIDs, allocate them in pairs for each mm_struct. The bottom bit distinguishes the two: if it is set, then the ASID will map only userspace.
--- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/mm/context.c | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-)
arch/arm64/include/asm/mmu.h +1 -0
@@ -17,6 +17,7 @@#define __ASM_MMU_H#define MMCF_AARCH32 0x1/* mm context flag for AArch32 executables */ +#define USER_ASID_FLAG (UL(1) << 48) typedef struct { atomic64_t id;
arch/arm64/mm/context.c +17 -8
@@ -39,7 +39,16 @@ static cpumask_t tlb_flush_pending;#define ASID_MASK (~GENMASK(asid_bits - 1, 0))#define ASID_FIRST_VERSION (1UL << asid_bits) -#define NUM_USER_ASIDS ASID_FIRST_VERSION + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define NUM_USER_ASIDS (ASID_FIRST_VERSION >> 1) +#define asid2idx (asid) (((asid) & ~ASID_MASK) >> 1) +#define idx2asid (idx) (((idx) << 1) & ~ASID_MASK) +#else +#define NUM_USER_ASIDS (ASID_FIRST_VERSION) +#define asid2idx (asid) ((asid) & ~ASID_MASK) +#define idx2asid (idx) asid2idx(idx) +#endif /* Get the ASIDBits supported by the current CPU */ static u32 get_cpu_asid_bits (void )
@@ -104,7 +113,7 @@ static void flush_context(unsigned int c*/ if (asid ==0 ) asid =per_cpu (reserved_asids, i); -__set_bit (asid & ~ASID_MASK , asid_map); +__set_bit (asid2idx (asid), asid_map);per_cpu (reserved_asids, i) = asid; }
@@ -156,16 +165,16 @@ static u64 new_context(struct mm_struct* We had a valid ASID in a previous life, so try to re-use * it if possible. */ - asid &= ~ASID_MASK ; -if (!__test_and_set_bit (asid, asid_map)) +if (!__test_and_set_bit (asid2idx (asid), asid_map))return newasid; }/* * Allocate a free ASID. If we can't find one, take a note of the -* currently active ASIDs and mark the TLBs as requiring flushes. -* We always count from ASID #1, as we use ASID #0 when setting a -* reserved TTBR0 for the init_mm. +* currently active ASIDs and mark the TLBs as requiring flushes. We +* always count from ASID #2 (index 1), as we use ASID #0 when setting +* a reserved TTBR0 for the init_mm and we allocate ASIDs in even/odd +* pairs. */ asid =find_next_zero_bit (asid_map,NUM_USER_ASIDS , cur_idx);if (asid !=NUM_USER_ASIDS )
@@ -182,7 +191,7 @@ static u64 new_context(struct mm_struct set_asid:__set_bit (asid, asid_map); cur_idx = asid; -return asid | generation; +return idx2asid (asid) | generation; }void check_and_switch_context (struct mm_struct *mm,unsigned int cpu)
Greg Kroah-Hartman
maintainerPATCH 30/195 arm64: mm: Add arm64_kernel_unmapped_at_el0 helper
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit fc0e1299da54 upstream.
In order for code such as TLB invalidation to operate efficiently when the decision to map the kernel at EL0 is determined at runtime, this patch introduces a helper function, arm64_kernel_unmapped_at_el0, to determine whether or not the kernel is mapped whilst running in userspace.
Currently, this just reports the value of CONFIG_UNMAP_KERNEL_AT_EL0, but will later be hooked up to a fake CPU capability using a static key.
--- arch/arm64/include/asm/mmu.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/include/asm/mmu.h +8 -0
@@ -19,6 +19,8 @@#define MMCF_AARCH32 0x1/* mm context flag for AArch32 executables */ #define USER_ASID_FLAG (UL(1) << 48) +#ifndef __ASSEMBLY__ + typedef struct { atomic64_t id; void *vdso;
@@ -32,6 +34,11 @@ typedef struct {*/ #define ASID (mm) ((mm)->context.id.counter & 0xffff) +static inline bool arm64_kernel_unmapped_at_el0 (void ) +{ +return IS_ENABLED (CONFIG_UNMAP_KERNEL_AT_EL0 ); +} +extern void paging_init (void );extern void bootmem_init (void );extern void __iomem *early_io_map (phys_addr_t phys,unsigned long virt);
@@ -42,4 +49,5 @@ extern void create_pgd_mapping(struct mmextern void *fixmap_remap_fdt (phys_addr_t dt_phys);extern void mark_linear_text_alias_ro (void ); +#endif /* !__ASSEMBLY__ */ #endif
Greg Kroah-Hartman
maintainerPATCH 31/195 arm64: mm: Invalidate both kernel and user ASIDs when performing TLBI
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 9b0de864b5bc upstream.
Since an mm has both a kernel and a user ASID, we need to ensure that broadcast TLB maintenance targets both address spaces so that things like CoW continue to work with the uaccess primitives in the kernel.
--- arch/arm64/include/asm/tlbflush.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
arch/arm64/include/asm/tlbflush.h +14 -2
@@ -23,6 +23,7 @@#include <linux/sched.h> #include <asm/cputype.h> +#include <asm/mmu.h> /* * Raw TLBI operations.
@@ -54,6 +55,11 @@#define __tlbi (op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0) +#define __tlbi_user (op, arg) do { \ + if (arm64_kernel_unmapped_at_el0()) \ + __tlbi(op, (arg) | USER_ASID_FLAG); \ +} while (0) +/* * TLB Management * ==============
@@ -115,6 +121,7 @@ static inline void flush_tlb_mm(struct mdsb (ishst);__tlbi (aside1is, asid); +__tlbi_user (aside1is, asid);dsb (ish); }
@@ -125,6 +132,7 @@ static inline void flush_tlb_page(structdsb (ishst);__tlbi (vale1is, addr); +__tlbi_user (vale1is, addr);dsb (ish); }
@@ -151,10 +159,13 @@ static inline void __flush_tlb_range(strdsb (ishst);for (addr = start; addr < end; addr +=1 << (PAGE_SHIFT -12 )) { -if (last_level) +if (last_level) {__tlbi (vale1is, addr); -else +__tlbi_user (vale1is, addr); + }else {__tlbi (vae1is, addr); +__tlbi_user (vae1is, addr); + } }dsb (ish); }
@@ -194,6 +205,7 @@ static inline void __flush_tlb_pgtable(sunsigned long addr = uaddr >>12 | (ASID (mm) <<48 );__tlbi (vae1is, addr); +__tlbi_user (vae1is, addr);dsb (ish); }
Greg Kroah-Hartman
maintainerPATCH 32/195 arm64: entry: Add exception trampoline page for exceptions from EL0
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit c7b9adaf85f8 upstream.
To allow unmapping of the kernel whilst running at EL0, we need to point the exception vectors at an entry trampoline that can map/unmap the kernel on entry/exit respectively.
This patch adds the trampoline page, although it is not yet plugged into the vector table and is therefore unused.
--- arch/arm64/kernel/entry.S | 86 ++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 17 +++++++ 2 files changed, 103 insertions(+)
arch/arm64/kernel/entry.S +86 -0
@@ -28,6 +28,8 @@ #include <asm/errno.h> #include <asm/esr.h> #include <asm/irq.h> +#include <asm/memory.h> +#include <asm/mmu.h> #include <asm/processor.h> #include <asm/ptrace.h> #include <asm/thread_info.h>
@@ -895,6 +897,90 @@ __ni_sys_trace: .popsection // .entry.text +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +/* + * Exception vectors trampoline. + */ + .pushsection ".entry.tramp.text", "ax" + + .macro tramp_map_kernel, tmp + mrs \tmp, ttbr1_el1 + sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE) + bic \tmp, \tmp, #USER_ASID_FLAG + msr ttbr1_el1, \tmp + .endm + + .macro tramp_unmap_kernel, tmp + mrs \tmp, ttbr1_el1 + add \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE) + orr \tmp, \tmp, #USER_ASID_FLAG + msr ttbr1_el1, \tmp + /* + * We avoid running the post_ttbr_update_workaround here because the + * user and kernel ASIDs don't have conflicting mappings, so any + * "blessing" as described in: + * + * http://lkml.kernel.org/r/[email protected] + * + * will not hurt correctness. Whilst this may partially defeat the + * point of using split ASIDs in the first place, it avoids + * the hit of invalidating the entire I-cache on every return to + * userspace. + */ + .endm + + .macro tramp_ventry, regsize = 64 + .align 7 +1: + .if \regsize == 64 + msr tpidrro_el0, x30 // Restored in kernel_ventry + .endif + tramp_map_kernel x30 + ldr x30, =vectors + prfm plil1strm, [x30, #(1b - tramp_vectors)] + msr vbar_el1, x30 + add x30, x30, #(1b - tramp_vectors) + isb + br x30 + .endm + + .macro tramp_exit, regsize = 64 + adr x30, tramp_vectors + msr vbar_el1, x30 + tramp_unmap_kernel x30 + .if \regsize == 64 + mrs x30, far_el1 + .endif + eret + .endm + + .align 11 +ENTRY(tramp_vectors) + .space 0x400 + + tramp_ventry + tramp_ventry + tramp_ventry + tramp_ventry + + tramp_ventry 32 + tramp_ventry 32 + tramp_ventry 32 + tramp_ventry 32 +END(tramp_vectors) + +ENTRY(tramp_exit_native) + tramp_exit +END(tramp_exit_native) + +ENTRY(tramp_exit_compat) + tramp_exit 32 +END(tramp_exit_compat) + + .ltorg + .popsection // .entry.tramp.text +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ + /* * Special system call wrappers. */
arch/arm64/kernel/vmlinux.lds.S +17 -0
@@ -57,6 +57,17 @@ jiffies = jiffies_64; #define HIBERNATE_TEXT #endif +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define TRAMP_TEXT \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__entry_tramp_text_start) = .; \ + *(.entry.tramp.text) \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__entry_tramp_text_end) = .; +#else +#define TRAMP_TEXT +#endif + /* * The size of the PE/COFF section that covers the kernel image, which * runs from stext to _edata, must be a round multiple of the PE/COFF
@@ -113,6 +124,7 @@ SECTIONS HYPERVISOR_TEXT IDMAP_TEXT HIBERNATE_TEXT + TRAMP_TEXT *(.fixup) *(.gnu.warning) . = ALIGN(16);
@@ -214,6 +226,11 @@ SECTIONS . += RESERVED_TTBR0_SIZE; #endif +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + tramp_pg_dir = .; + . += PAGE_SIZE; +#endif + __pecoff_data_size = ABSOLUTE(. - __initdata_begin); _end = .;
Greg Kroah-Hartman
maintainerPATCH 33/195 arm64: mm: Map entry trampoline into trampoline and kernel page tables
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 51a0048beb44 upstream.
The exception entry trampoline needs to be mapped at the same virtual address in both the trampoline page table (which maps nothing else) and also the kernel page table, so that we can swizzle TTBR1_EL1 on exceptions from and return to EL0.
This patch maps the trampoline at a fixed virtual address in the fixmap area of the kernel virtual address space, which allows the kernel proper to be randomized with respect to the trampoline when KASLR is enabled.
--- arch/arm64/include/asm/fixmap.h | 4 ++++ arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/kernel/asm-offsets.c | 6 +++++- arch/arm64/mm/mmu.c | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-)
arch/arm64/include/asm/fixmap.h +4 -0
@@ -58,6 +58,10 @@ enum fixed_addresses { FIX_APEI_GHES_NMI,#endif /* CONFIG_ACPI_APEI_GHES */ +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + FIX_ENTRY_TRAMP_TEXT, +#define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT)) +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ __end_of_permanent_fixed_addresses,/*
arch/arm64/include/asm/pgtable.h +1 -0
@@ -684,6 +684,7 @@ static inline void pmdp_set_wrprotect(stextern pgd_t swapper_pg_dir[PTRS_PER_PGD ];extern pgd_t idmap_pg_dir[PTRS_PER_PGD ]; +extern pgd_t tramp_pg_dir[PTRS_PER_PGD ];/* * Encode and decode a swap entry:
arch/arm64/kernel/asm-offsets.c +5 -1
@@ -24,6 +24,7 @@#include <linux/kvm_host.h> #include <linux/suspend.h> #include <asm/cpufeature.h> +#include <asm/fixmap.h> #include <asm/thread_info.h> #include <asm/memory.h> #include <asm/smp_plat.h>
@@ -148,11 +149,14 @@ int main(void)DEFINE (ARM_SMCCC_RES_X2_OFFS , offsetof(struct arm_smccc_res , a2));DEFINE (ARM_SMCCC_QUIRK_ID_OFFS , offsetof(struct arm_smccc_quirk , id));DEFINE (ARM_SMCCC_QUIRK_STATE_OFFS , offsetof(struct arm_smccc_quirk , state)); -BLANK ();DEFINE (HIBERN_PBE_ORIG , offsetof(struct pbe , orig_address));DEFINE (HIBERN_PBE_ADDR , offsetof(struct pbe , address));DEFINE (HIBERN_PBE_NEXT , offsetof(struct pbe , next));DEFINE (ARM64_FTR_SYSVAL , offsetof(struct arm64_ftr_reg , sys_val)); +BLANK (); +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +DEFINE (TRAMP_VALIAS ,TRAMP_VALIAS ); +#endif return 0 ; }
arch/arm64/mm/mmu.c +23 -0
@@ -525,6 +525,29 @@ static int __init parse_rodata(char *arg }early_param ("rodata" , parse_rodata); +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +static int __init map_entry_trampoline (void ) +{ +extern char __entry_tramp_text_start[]; + +pgprot_t prot = rodata_enabled ?PAGE_KERNEL_ROX :PAGE_KERNEL_EXEC ; +phys_addr_t pa_start =__pa_symbol (__entry_tramp_text_start); + +/* The trampoline is always mapped and can therefore be global */ +pgprot_val (prot) &= ~PTE_NG ; + +/* Map only the text into the trampoline page table */ +memset (tramp_pg_dir,0 ,PGD_SIZE ); +__create_pgd_mapping (tramp_pg_dir, pa_start,TRAMP_VALIAS ,PAGE_SIZE , + prot, pgd_pgtable_alloc,0 ); + +/* ...as well as the kernel page table */ +__set_fixmap (FIX_ENTRY_TRAMP_TEXT , pa_start, prot); +return 0 ; +} +core_initcall (map_entry_trampoline); +#endif +/* * Create fine-grained mappings for the kernel. */
Greg Kroah-Hartman
maintainerPATCH 34/195 arm64: entry: Explicitly pass exception level to kernel_ventry macro
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 5b1f7fe41909 upstream.
We will need to treat exceptions from EL0 differently in kernel_ventry, so rework the macro to take the exception level as an argument and construct the branch target using that.
--- arch/arm64/kernel/entry.S | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
arch/arm64/kernel/entry.S +25 -25
@@ -71,7 +71,7 @@ #define BAD_FIQ 2 #define BAD_ERROR 3 - .macro kernel_ventry label + .macro kernel_ventry, el, label, regsize = 64 .align 7 sub sp, sp, #S_FRAME_SIZE #ifdef CONFIG_VMAP_STACK
@@ -84,7 +84,7 @@ tbnz x0, #THREAD_SHIFT, 0f sub x0, sp, x0 // x0'' = sp' - x0' = (sp + x0) - sp = x0 sub sp, sp, x0 // sp'' = sp' - x0 = (sp + x0) - x0 = sp - b \label + b el\()\el\()_\label 0: /*
@@ -116,7 +116,7 @@ sub sp, sp, x0 mrs x0, tpidrro_el0 #endif - b \label + b el\()\el\()_\label .endm .macro kernel_entry, el, regsize = 64
@@ -367,31 +367,31 @@ tsk .req x28 // current thread_info .align 11 ENTRY(vectors) - kernel_ventry el1_sync_invalid // Synchronous EL1t - kernel_ventry el1_irq_invalid // IRQ EL1t - kernel_ventry el1_fiq_invalid // FIQ EL1t - kernel_ventry el1_error_invalid // Error EL1t - - kernel_ventry el1_sync // Synchronous EL1h - kernel_ventry el1_irq // IRQ EL1h - kernel_ventry el1_fiq_invalid // FIQ EL1h - kernel_ventry el1_error_invalid // Error EL1h - - kernel_ventry el0_sync // Synchronous 64-bit EL0 - kernel_ventry el0_irq // IRQ 64-bit EL0 - kernel_ventry el0_fiq_invalid // FIQ 64-bit EL0 - kernel_ventry el0_error_invalid // Error 64-bit EL0 + kernel_ventry 1, sync_invalid // Synchronous EL1t + kernel_ventry 1, irq_invalid // IRQ EL1t + kernel_ventry 1, fiq_invalid // FIQ EL1t + kernel_ventry 1, error_invalid // Error EL1t + + kernel_ventry 1, sync // Synchronous EL1h + kernel_ventry 1, irq // IRQ EL1h + kernel_ventry 1, fiq_invalid // FIQ EL1h + kernel_ventry 1, error_invalid // Error EL1h + + kernel_ventry 0, sync // Synchronous 64-bit EL0 + kernel_ventry 0, irq // IRQ 64-bit EL0 + kernel_ventry 0, fiq_invalid // FIQ 64-bit EL0 + kernel_ventry 0, error_invalid // Error 64-bit EL0 #ifdef CONFIG_COMPAT - kernel_ventry el0_sync_compat // Synchronous 32-bit EL0 - kernel_ventry el0_irq_compat // IRQ 32-bit EL0 - kernel_ventry el0_fiq_invalid_compat // FIQ 32-bit EL0 - kernel_ventry el0_error_invalid_compat // Error 32-bit EL0 + kernel_ventry 0, sync_compat, 32 // Synchronous 32-bit EL0 + kernel_ventry 0, irq_compat, 32 // IRQ 32-bit EL0 + kernel_ventry 0, fiq_invalid_compat, 32 // FIQ 32-bit EL0 + kernel_ventry 0, error_invalid_compat, 32 // Error 32-bit EL0 #else - kernel_ventry el0_sync_invalid // Synchronous 32-bit EL0 - kernel_ventry el0_irq_invalid // IRQ 32-bit EL0 - kernel_ventry el0_fiq_invalid // FIQ 32-bit EL0 - kernel_ventry el0_error_invalid // Error 32-bit EL0 + kernel_ventry 0, sync_invalid, 32 // Synchronous 32-bit EL0 + kernel_ventry 0, irq_invalid, 32 // IRQ 32-bit EL0 + kernel_ventry 0, fiq_invalid, 32 // FIQ 32-bit EL0 + kernel_ventry 0, error_invalid, 32 // Error 32-bit EL0 #endif END(vectors)
Greg Kroah-Hartman
maintainerPATCH 35/195 arm64: entry: Hook up entry trampoline to exception vectors
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 4bf3286d29f3 upstream.
Hook up the entry trampoline to our exception vectors so that all exceptions from and returns to EL0 go via the trampoline, which swizzles the vector base register accordingly. Transitioning to and from the kernel clobbers x30, so we use tpidrro_el0 and far_el1 as scratch registers for native tasks.
--- arch/arm64/kernel/entry.S | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
arch/arm64/kernel/entry.S +36 -3
@@ -73,6 +73,17 @@ .macro kernel_ventry, el, label, regsize = 64 .align 7 +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + .if \el == 0 + .if \regsize == 64 + mrs x30, tpidrro_el0 + msr tpidrro_el0, xzr + .else + mov x30, xzr + .endif + .endif +#endif + sub sp, sp, #S_FRAME_SIZE #ifdef CONFIG_VMAP_STACK /*
@@ -119,6 +130,11 @@ b el\()\el\()_\label .endm + .macro tramp_alias, dst, sym + mov_q \dst, TRAMP_VALIAS + add \dst, \dst, #(\sym - .entry.tramp.text) + .endm + .macro kernel_entry, el, regsize = 64 .if \regsize == 32 mov w0, w0 // zero upper 32 bits of x0
@@ -269,18 +285,20 @@ alternative_else_nop_endif .if \el == 0 ldr x23, [sp, #S_SP] // load return stack pointer msr sp_el0, x23 + tst x22, #PSR_MODE32_BIT // native task? + b.eq 3f + #ifdef CONFIG_ARM64_ERRATUM_845719 alternative_if ARM64_WORKAROUND_845719 - tbz x22, #4, 1f #ifdef CONFIG_PID_IN_CONTEXTIDR mrs x29, contextidr_el1 msr contextidr_el1, x29 #else msr contextidr_el1, xzr #endif -1: alternative_else_nop_endif #endif +3: .endif msr elr_el1, x21 // set up the return data
@@ -302,7 +320,22 @@ alternative_else_nop_endif ldp x28, x29, [sp, #16 * 14] ldr lr, [sp, #S_LR] add sp, sp, #S_FRAME_SIZE // restore sp - eret // return to kernel + +#ifndef CONFIG_UNMAP_KERNEL_AT_EL0 + eret +#else + .if \el == 0 + bne 4f + msr far_el1, x30 + tramp_alias x30, tramp_exit_native + br x30 +4: + tramp_alias x30, tramp_exit_compat + br x30 + .else + eret + .endif +#endif .endm .macro irq_stack_entry
Greg Kroah-Hartman
maintainerPATCH 36/195 arm64: erratum: Work around Falkor erratum #E1003 in trampoline code
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit d1777e686ad1 upstream.
We rely on an atomic swizzling of TTBR1 when transitioning from the entry trampoline to the kernel proper on an exception. We can't rely on this atomicity in the face of Falkor erratum #E1003, so on affected cores we can issue a TLB invalidation to invalidate the walk cache prior to jumping into the kernel. There is still the possibility of a TLB conflict here due to conflicting walk cache entries prior to the invalidation, but this doesn't appear to be the case on these CPUs in practice.
--- arch/arm64/Kconfig | 17 +++++------------ arch/arm64/kernel/entry.S | 12 ++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-)
arch/arm64/Kconfig +5 -12
@@ -504,20 +504,13 @@ config CAVIUM_ERRATUM_30115 config QCOM_FALKOR_ERRATUM_1003 bool "Falkor E1003: Incorrect translation due to ASID change" default y - select ARM64_PAN if ARM64_SW_TTBR0_PAN help On Falkor v1, an incorrect ASID may be cached in the TLB when ASID - and BADDR are changed together in TTBRx_EL1. The workaround for this - issue is to use a reserved ASID in cpu_do_switch_mm() before - switching to the new ASID. Saying Y here selects ARM64_PAN if - ARM64_SW_TTBR0_PAN is selected. This is done because implementing and - maintaining the E1003 workaround in the software PAN emulation code - would be an unnecessary complication. The affected Falkor v1 CPU - implements ARMv8.1 hardware PAN support and using hardware PAN - support versus software PAN emulation is mutually exclusive at - runtime. - - If unsure, say Y. + and BADDR are changed together in TTBRx_EL1. Since we keep the ASID + in TTBR1_EL1, this situation only occurs in the entry trampoline and + then only for entries in the walk cache, since the leaf translation + is unchanged. Work around the erratum by invalidating the walk cache + entries for the trampoline before entering the kernel proper. config QCOM_FALKOR_ERRATUM_1009 bool "Falkor E1009: Prematurely complete a DSB after a TLBI"
arch/arm64/kernel/entry.S +12 -0
@@ -941,6 +941,18 @@ __ni_sys_trace: sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE) bic \tmp, \tmp, #USER_ASID_FLAG msr ttbr1_el1, \tmp +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003 + /* ASID already in \tmp[63:48] */ + movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12) + movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12) + /* 2MB boundary containing the vectors, so we nobble the walk cache */ + movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12) + isb + tlbi vae1, \tmp + dsb nsh +alternative_else_nop_endif +#endif /* CONFIG_QCOM_FALKOR_ERRATUM_1003 */ .endm .macro tramp_unmap_kernel, tmp
Greg Kroah-Hartman
maintainerPATCH 38/195 arm64: tls: Avoid unconditional zeroing of tpidrro_el0 for native tasks
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 18011eac28c7 upstream.
When unmapping the kernel at EL0, we use tpidrro_el0 as a scratch register during exception entry from native tasks and subsequently zero it in the kernel_ventry macro. We can therefore avoid zeroing tpidrro_el0 in the context-switch path for native tasks using the entry trampoline.
--- arch/arm64/kernel/process.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/arm64/kernel/process.c +5 -7
@@ -314,16 +314,14 @@ void tls_preserve_current_state(void)static void tls_thread_switch (struct task_struct *next) { -unsigned long tpidr, tpidrro; -tls_preserve_current_state (); - tpidr = *task_user_tls (next); - tpidrro =is_compat_thread (task_thread_info (next)) ? - next->thread.tp_value :0 ; +if (is_compat_thread (task_thread_info (next))) +write_sysreg (next->thread.tp_value, tpidrro_el0); +else if (!arm64_kernel_unmapped_at_el0 ()) +write_sysreg (0 , tpidrro_el0); -write_sysreg (tpidr, tpidr_el0); -write_sysreg (tpidrro, tpidrro_el0); +write_sysreg (*task_user_tls (next), tpidr_el0); }/* Restore the UAO state depending on next's addr_limit */
Greg Kroah-Hartman
maintainerPATCH 39/195 arm64: entry: Add fake CPU feature for unmapping the kernel at EL0
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit ea1e3de85e94 upstream.
Allow explicit disabling of the entry trampoline on the kernel command line (kpti=off) by adding a fake CPU feature (ARM64_UNMAP_KERNEL_AT_EL0) that can be used to toggle the alternative sequences in our entry code and avoid use of the trampoline altogether if desired. This also allows us to make use of a static key in arm64_kernel_unmapped_at_el0().
--- arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/mmu.h | 3 +- arch/arm64/kernel/cpufeature.c | 41 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/entry.S | 9 ++++---- 4 files changed, 50 insertions(+), 6 deletions(-)
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -40,7 +40,8 @@#define ARM64_WORKAROUND_858921 19#define ARM64_WORKAROUND_CAVIUM_30115 20#define ARM64_HAS_DCPOP 21 +#define ARM64_UNMAP_KERNEL_AT_EL0 23 -#define ARM64_NCAPS 22 +#define ARM64_NCAPS 24#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/mmu.h +2 -1
@@ -36,7 +36,8 @@ typedef struct {static inline bool arm64_kernel_unmapped_at_el0 (void ) { -return IS_ENABLED (CONFIG_UNMAP_KERNEL_AT_EL0 ); +return IS_ENABLED (CONFIG_UNMAP_KERNEL_AT_EL0 ) && +cpus_have_const_cap (ARM64_UNMAP_KERNEL_AT_EL0 ); }extern void paging_init (void );
arch/arm64/kernel/cpufeature.c +41 -0
53 lines not on this page · raw message
arch/arm64/kernel/entry.S +5 -4
@@ -74,6 +74,7 @@ .macro kernel_ventry, el, label, regsize = 64 .align 7 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +alternative_if ARM64_UNMAP_KERNEL_AT_EL0 .if \el == 0 .if \regsize == 64 mrs x30, tpidrro_el0
@@ -82,6 +83,7 @@ mov x30, xzr .endif .endif +alternative_else_nop_endif #endif sub sp, sp, #S_FRAME_SIZE
@@ -321,10 +323,9 @@ alternative_else_nop_endif ldr lr, [sp, #S_LR] add sp, sp, #S_FRAME_SIZE // restore sp -#ifndef CONFIG_UNMAP_KERNEL_AT_EL0 - eret -#else .if \el == 0 +alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 bne 4f msr far_el1, x30 tramp_alias x30, tramp_exit_native
@@ -332,10 +333,10 @@ alternative_else_nop_endif 4: tramp_alias x30, tramp_exit_compat br x30 +#endif .else eret .endif -#endif .endm .macro irq_stack_entry
Greg Kroah-Hartman
maintainerPATCH 40/195 arm64: kaslr: Put kernel vectors address in separate data page
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 6c27c4082f4f upstream.
The literal pool entry for identifying the vectors base is the only piece of information in the trampoline page that identifies the true location of the kernel.
This patch moves it into a page-aligned region of the .rodata section and maps this adjacent to the trampoline text via an additional fixmap entry, which protects against any accidental leakage of the trampoline contents.
--- arch/arm64/include/asm/fixmap.h | 1 + arch/arm64/kernel/entry.S | 14 ++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 5 ++++- arch/arm64/mm/mmu.c | 10 +++++++++- 4 files changed, 28 insertions(+), 2 deletions(-)
arch/arm64/include/asm/fixmap.h +1 -0
@@ -59,6 +59,7 @@ enum fixed_addresses {#endif /* CONFIG_ACPI_APEI_GHES */ #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +FIX_ENTRY_TRAMP_DATA ,FIX_ENTRY_TRAMP_TEXT , #define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT))#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
arch/arm64/kernel/entry.S +14 -0
@@ -982,7 +982,13 @@ alternative_else_nop_endif msr tpidrro_el0, x30 // Restored in kernel_ventry .endif tramp_map_kernel x30 +#ifdef CONFIG_RANDOMIZE_BASE + adr x30, tramp_vectors + PAGE_SIZE +alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003 + ldr x30, [x30] +#else ldr x30, =vectors +#endif prfm plil1strm, [x30, #(1b - tramp_vectors)] msr vbar_el1, x30 add x30, x30, #(1b - tramp_vectors)
@@ -1025,6 +1031,14 @@ END(tramp_exit_compat) .ltorg .popsection // .entry.tramp.text +#ifdef CONFIG_RANDOMIZE_BASE + .pushsection ".rodata", "a" + .align PAGE_SHIFT + .globl __entry_tramp_data_start +__entry_tramp_data_start: + .quad vectors + .popsection // .rodata +#endif /* CONFIG_RANDOMIZE_BASE */ #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ /*
arch/arm64/kernel/vmlinux.lds.S +4 -1
@@ -251,7 +251,10 @@ ASSERT(__idmap_text_end - (__idmap_text_ ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) <= SZ_4K, "Hibernate exit text too big or misaligned") #endif - +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, + "Entry trampoline text too big") +#endif /* * If padding is applied before .head.text, virt<->phys conversions will fail. */
arch/arm64/mm/mmu.c +9 -1
@@ -541,8 +541,16 @@ static int __init map_entry_trampoline(v__create_pgd_mapping (tramp_pg_dir, pa_start,TRAMP_VALIAS ,PAGE_SIZE , prot, pgd_pgtable_alloc,0 ); -/* ...as well as the kernel page table */ +/* Map both the text and data into the kernel page table */ __set_fixmap (FIX_ENTRY_TRAMP_TEXT , pa_start, prot); +if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) { +extern char __entry_tramp_data_start[]; + +__set_fixmap (FIX_ENTRY_TRAMP_DATA , +__pa_symbol (__entry_tramp_data_start), +PAGE_KERNEL_RO ); + } +return 0 ; }core_initcall (map_entry_trampoline);
Greg Kroah-Hartman
maintainerPATCH 42/195 arm64: Kconfig: Add CONFIG_UNMAP_KERNEL_AT_EL0
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 084eb77cd3a8 upstream.
Add a Kconfig entry to control use of the entry trampoline, which allows us to unmap the kernel whilst running in userspace and improve the robustness of KASLR.
--- arch/arm64/Kconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/Kconfig +13 -0
@@ -806,6 +806,19 @@ config FORCE_MAX_ZONEORDER However for 4K, we choose a higher default value, 11 as opposed to 10, giving us 4M allocations matching the default size used by generic code. +config UNMAP_KERNEL_AT_EL0 + bool "Unmap kernel when running in userspace (aka \"KAISER\")" + default y + help + Some attacks against KASLR make use of the timing difference between + a permission fault which could arise from a page table entry that is + present in the TLB, and a translation fault which always requires a + page table walk. This option defends against these attacks by unmapping + the kernel whilst running in userspace, therefore forcing translation + faults for all of kernel space. + + If unsure, say Y. + menuconfig ARMV8_DEPRECATED bool "Emulate deprecated/obsolete ARMv8 instructions" depends on COMPAT
Greg Kroah-Hartman
maintainerPATCH 43/195 arm64: Kconfig: Reword UNMAP_KERNEL_AT_EL0 kconfig entry
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 0617052ddde3 upstream.
Although CONFIG_UNMAP_KERNEL_AT_EL0 does make KASLR more robust, it's actually more useful as a mitigation against speculation attacks that can leak arbitrary kernel data to userspace through speculation.
Reword the Kconfig help message to reflect this, and make the option depend on EXPERT so that it is on by default for the majority of users.
--- arch/arm64/Kconfig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
arch/arm64/Kconfig +6 -7
@@ -807,15 +807,14 @@ config FORCE_MAX_ZONEORDER 4M allocations matching the default size used by generic code. config UNMAP_KERNEL_AT_EL0 - bool "Unmap kernel when running in userspace (aka \"KAISER\")" + bool "Unmap kernel when running in userspace (aka \"KAISER\")" if EXPERT default y help - Some attacks against KASLR make use of the timing difference between - a permission fault which could arise from a page table entry that is - present in the TLB, and a translation fault which always requires a - page table walk. This option defends against these attacks by unmapping - the kernel whilst running in userspace, therefore forcing translation - faults for all of kernel space. + Speculation attacks against some high-performance processors can + be used to bypass MMU permission checks and leak kernel data to + userspace. This can be defended against by unmapping the kernel + when running in userspace, mapping it back in on exception entry + via a trampoline page in the vector table. If unsure, say Y.
Greg Kroah-Hartman
maintainerPATCH 44/195 arm64: Take into account ID_AA64PFR0_EL1.CSV3
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 179a56f6f9fb upstream.
For non-KASLR kernels where the KPTI behaviour has not been overridden on the command line we can use ID_AA64PFR0_EL1.CSV3 to determine whether or not we should unmap the kernel whilst running at EL0.
--- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +1 -0
@@ -332,6 +332,7 @@#define ID_AA64ISAR1_DPB_SHIFT 0/* id_aa64pfr0 */ +#define ID_AA64PFR0_CSV3_SHIFT 60#define ID_AA64PFR0_GIC_SHIFT 24#define ID_AA64PFR0_ASIMD_SHIFT 20#define ID_AA64PFR0_FP_SHIFT 16
arch/arm64/kernel/cpufeature.c +7 -1
@@ -125,6 +125,7 @@ static const struct arm64_ftr_bits ftr_i };static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { +ARM64_FTR_BITS (FTR_HIDDEN ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_CSV3_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_HIDDEN ,FTR_STRICT ,FTR_EXACT ,ID_AA64PFR0_GIC_SHIFT ,4 ,0 ),S_ARM64_FTR_BITS (FTR_VISIBLE ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_ASIMD_SHIFT ,4 ,ID_AA64PFR0_ASIMD_NI ),S_ARM64_FTR_BITS (FTR_VISIBLE ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_FP_SHIFT ,4 ,ID_AA64PFR0_FP_NI ),
@@ -802,6 +803,8 @@ static int __kpti_forced; /* 0: not forcstatic bool unmap_kernel_at_el0 (const struct arm64_cpu_capabilities *entry,int __unused) { +u64 pfr0 =read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ); +/* Forced on command line? */ if (__kpti_forced) { pr_info_once("kernel page table isolation forced %s by command line option\n",
@@ -813,7 +816,9 @@ static bool unmap_kernel_at_el0(const stif (IS_ENABLED (CONFIG_RANDOMIZE_BASE ))return true; -return false; +/* Defer to CPU feature registers */ +return !cpuid_feature_extract_unsigned_field (pfr0, +ID_AA64PFR0_CSV3_SHIFT ); }static int __init parse_kpti (char *str)
@@ -918,6 +923,7 @@ static const struct arm64_cpu_capabiliti },#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 { + .desc = "Kernel page table isolation (KPTI)", .capability = ARM64_UNMAP_KERNEL_AT_EL0, .def_scope = SCOPE_SYSTEM, .matches = unmap_kernel_at_el0,
Greg Kroah-Hartman
maintainerPATCH 45/195 arm64: capabilities: Handle duplicate entries for a capability
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suzuki K Poulose <[email protected]>
Commit 67948af41f2e upstream.
Sometimes a single capability could be listed multiple times with differing matches(), e.g, CPU errata for different MIDR versions. This breaks verify_local_cpu_feature() and this_cpu_has_cap() as we stop checking for a capability on a CPU with the first entry in the given table, which is not sufficient. Make sure we run the checks for all entries of the same capability. We do this by fixing __this_cpu_has_cap() to run through all the entries in the given table for a match and reuse it for verify_local_cpu_feature().
--- arch/arm64/kernel/cpufeature.c | 44 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
arch/arm64/kernel/cpufeature.c +23 -21
@@ -1047,6 +1047,26 @@ static void __init setup_elf_hwcaps(conscap_set_elf_hwcap (hwcaps); } +/* +* Check if the current CPU has a given feature capability. +* Should be called from non-preemptible context. +*/ +static bool __this_cpu_has_cap (const struct arm64_cpu_capabilities *cap_array, +unsigned int cap) +{ +const struct arm64_cpu_capabilities *caps; + +if (WARN_ON (preemptible ())) +return false; + +for (caps = cap_array; caps->desc; caps++) +if (caps->capability == cap && + caps->matches && + caps->matches (caps,SCOPE_LOCAL_CPU )) +return true; +return false; +} +void update_cpu_capabilities (const struct arm64_cpu_capabilities *caps,const char *info) {
@@ -1125,8 +1145,9 @@ verify_local_elf_hwcaps(const struct arm }static void -verify_local_cpu_features (const struct arm64_cpu_capabilities *caps) +verify_local_cpu_features (const struct arm64_cpu_capabilities *caps_list) { +const struct arm64_cpu_capabilities *caps = caps_list;for (; caps->matches; caps++) {if (!cpus_have_cap (caps->capability))continue ;
@@ -1134,7 +1155,7 @@ verify_local_cpu_features(const struct a* If the new CPU misses an advertised feature, we cannot proceed * further, park the cpu. */ -if (!caps->matches (caps,SCOPE_LOCAL_CPU )) { +if (!__this_cpu_has_cap (caps_list, caps->capability)) {pr_crit ("CPU%d: missing feature: %s\n" ,smp_processor_id (), caps->desc);cpu_die_early ();
@@ -1195,25 +1216,6 @@ static void __init mark_const_caps_readystatic_branch_enable (&arm64_const_caps_ready); } -/* -* Check if the current CPU has a given feature capability. -* Should be called from non-preemptible context. -*/ -static bool __this_cpu_has_cap (const struct arm64_cpu_capabilities *cap_array, -unsigned int cap) -{ -const struct arm64_cpu_capabilities *caps; - -if (WARN_ON (preemptible ())) -return false; - -for (caps = cap_array; caps->desc; caps++) -if (caps->capability == cap && caps->matches) -return caps->matches (caps,SCOPE_LOCAL_CPU ); - -return false; -} -extern const struct arm64_cpu_capabilities arm64_errata[];bool this_cpu_has_cap (unsigned int cap)
Greg Kroah-Hartman
maintainerPATCH 46/195 arm64: mm: Introduce TTBR_ASID_MASK for getting at the ASID in the TTBR
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit b519538dfefc upstream.
There are now a handful of open-coded masks to extract the ASID from a TTBR value, so introduce a TTBR_ASID_MASK and use that instead.
--- arch/arm64/include/asm/asm-uaccess.h | 3 ++- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/include/asm/uaccess.h | 4 ++-- arch/arm64/kernel/entry.S | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-)
arch/arm64/include/asm/asm-uaccess.h +2 -1
@@ -4,6 +4,7 @@#include <asm/alternative.h> #include <asm/kernel-pgtable.h> +#include <asm/mmu.h> #include <asm/sysreg.h> #include <asm/assembler.h>
@@ -17,7 +18,7 @@ msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1 isb sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE - bic \tmp1, \tmp1, #(0xffff << 48) + bic \tmp1, \tmp1, #TTBR_ASID_MASK msr ttbr1_el1, \tmp1 // set reserved ASID isb .endm
arch/arm64/include/asm/mmu.h +1 -0
@@ -18,6 +18,7 @@#define MMCF_AARCH32 0x1/* mm context flag for AArch32 executables */ #define USER_ASID_FLAG (UL(1) << 48) +#define TTBR_ASID_MASK (UL(0xffff) << 48)#ifndef __ASSEMBLY__
arch/arm64/include/asm/uaccess.h +2 -2
@@ -112,7 +112,7 @@ static inline void __uaccess_ttbr0_disabwrite_sysreg (ttbr +SWAPPER_DIR_SIZE , ttbr0_el1);isb ();/* Set reserved ASID */ - ttbr &= ~(0xffffUL <<48 ); + ttbr &= ~TTBR_ASID_MASK ;write_sysreg (ttbr, ttbr1_el1);isb (); }
@@ -131,7 +131,7 @@ static inline void __uaccess_ttbr0_enabl/* Restore active ASID */ ttbr1 =read_sysreg (ttbr1_el1); - ttbr1 |= ttbr0 & (0xffffUL <<48 ); + ttbr1 |= ttbr0 &TTBR_ASID_MASK ;write_sysreg (ttbr1, ttbr1_el1);isb ();
arch/arm64/kernel/entry.S +1 -1
@@ -205,7 +205,7 @@ alternative_else_nop_endif .if \el != 0 mrs x21, ttbr1_el1 - tst x21, #0xffff << 48 // Check for the reserved ASID + tst x21, #TTBR_ASID_MASK // Check for the reserved ASID orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR b.eq 1f // TTBR0 access already disabled and x23, x23, #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
Greg Kroah-Hartman
maintainerPATCH 47/195 arm64: kpti: Fix the interaction between ASID switching and software PAN
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
Commit 6b88a32c7af6 upstream.
With ARM64_SW_TTBR0_PAN enabled, the exception entry code checks the active ASID to decide whether user access was enabled (non-zero ASID) when the exception was taken. On return from exception, if user access was previously disabled, it re-instates TTBR0_EL1 from the per-thread saved value (updated in switch_mm() or efi_set_pgd()).
Commit 7655abb95386 ("arm64: mm: Move ASID from TTBR0 to TTBR1") makes a TTBR0_EL1 + ASID switching non-atomic. Subsequently, commit 27a921e75711 ("arm64: mm: Fix and re-enable ARM64_SW_TTBR0_PAN") changes the __uaccess_ttbr0_disable() function and asm macro to first write the reserved TTBR0_EL1 followed by the ASID=0 update in TTBR1_EL1. If an exception occurs between these two, the exception return code will re-instate a valid TTBR0_EL1. Similar scenario can happen in cpu_switch_mm() between setting the reserved TTBR0_EL1 and the ASID update in cpu_do_switch_mm().
This patch reverts the entry.S check for ASID == 0 to TTBR0_EL1 and disables the interrupts around the TTBR0_EL1 and ASID switching code in __uaccess_ttbr0_disable(). It also ensures that, when returning from the EFI runtime services, efi_set_pgd() doesn't leave a non-zero ASID in TTBR1_EL1 by using uaccess_ttbr0_{enable,disable}.
The accesses to current_thread_info()->ttbr0 are updated to use READ_ONCE/WRITE_ONCE.
As a safety measure, __uaccess_ttbr0_enable() always masks out any existing non-zero ASID TTBR1_EL1 before writing in the new ASID.
--- arch/arm64/include/asm/asm-uaccess.h | 12 +++++++----- arch/arm64/include/asm/efi.h | 12 +++++++----- arch/arm64/include/asm/mmu_context.h | 3 ++- arch/arm64/include/asm/uaccess.h | 9 ++++++--- arch/arm64/kernel/entry.S | 2 +- arch/arm64/lib/clear_user.S | 2 +- arch/arm64/lib/copy_from_user.S | 2 +- arch/arm64/lib/copy_in_user.S | 2 +- arch/arm64/lib/copy_to_user.S | 2 +- arch/arm64/mm/cache.S | 2 +- arch/arm64/mm/proc.S | 3 +++ arch/arm64/xen/hypercall.S | 2 +- 12 files changed, 32 insertions(+), 21 deletions(-)
arch/arm64/include/asm/asm-uaccess.h +7 -5
@@ -14,11 +14,11 @@#ifdef CONFIG_ARM64_SW_TTBR0_PAN .macro __uaccess_ttbr0_disable, tmp1 mrs \tmp1, ttbr1_el1 // swapper_pg_dir + bic \tmp1, \tmp1, #TTBR_ASID_MASK add \tmp1, \tmp1, #SWAPPER_DIR_SIZE // reserved_ttbr0 at the end of swapper_pg_dir msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1 isb sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE - bic \tmp1, \tmp1, #TTBR_ASID_MASK msr ttbr1_el1, \tmp1 // set reserved ASID isb .endm
@@ -35,9 +35,11 @@ isb .endm - .macro uaccess_ttbr0_disable, tmp1 + .macro uaccess_ttbr0_disable, tmp1, tmp2 alternative_if_not ARM64_HAS_PAN + save_and_disable_irq \tmp2 // avoid preemption __uaccess_ttbr0_disable \tmp1 + restore_irq \tmp2 alternative_else_nop_endif .endm
@@ -49,7 +51,7 @@ alternative_if_not ARM64_HAS_PAN alternative_else_nop_endif .endm #else - .macro uaccess_ttbr0_disable, tmp1 + .macro uaccess_ttbr0_disable, tmp1, tmp2 .endm .macro uaccess_ttbr0_enable, tmp1, tmp2, tmp3
@@ -59,8 +61,8 @@ alternative_else_nop_endif/* * These macros are no-ops when UAO is present. */ - .macro uaccess_disable_not_uao, tmp1 - uaccess_ttbr0_disable \tmp1 + .macro uaccess_disable_not_uao, tmp1, tmp2 + uaccess_ttbr0_disable \tmp1, \tmp2 alternative_if ARM64_ALT_PAN_NOT_UAO SET_PSTATE_PAN(1) alternative_else_nop_endif
arch/arm64/include/asm/efi.h +7 -5
@@ -121,19 +121,21 @@ static inline void efi_set_pgd(struct mmif (mm != current->active_mm) {/* * Update the current thread's saved ttbr0 since it is -* restored as part of a return from exception. Set -* the hardware TTBR0_EL1 using cpu_switch_mm() -* directly to enable potential errata workarounds. +* restored as part of a return from exception. Enable +* access to the valid TTBR0_EL1 and invoke the errata +* workaround directly since there is no return from +* exception when invoking the EFI run-time services. */ update_saved_ttbr0 (current, mm); -cpu_switch_mm (mm->pgd, mm); +uaccess_ttbr0_enable (); +post_ttbr_update_workaround (); }else {/* * Defer the switch to the current thread's TTBR0_EL1 * until uaccess_enable(). Restore the current * thread's saved ttbr0 corresponding to its active_mm */ -cpu_set_reserved_ttbr0 (); +uaccess_ttbr0_disable ();update_saved_ttbr0 (current, current->active_mm); } }
arch/arm64/include/asm/mmu_context.h +2 -1
@@ -175,7 +175,7 @@ static inline void update_saved_ttbr0(st else ttbr =virt_to_phys (mm->pgd) |ASID (mm) <<48 ; -task_thread_info (tsk)->ttbr0 = ttbr; +WRITE_ONCE (task_thread_info (tsk)->ttbr0, ttbr); }#else static inline void update_saved_ttbr0(struct task_struct *tsk,
@@ -230,6 +230,7 @@ switch_mm(struct mm_struct *prev, struct#define activate_mm (prev,next) switch_mm(prev, next, current)void verify_cpu_asid_bits (void ); +void post_ttbr_update_workaround (void );#endif /* !__ASSEMBLY__ */
arch/arm64/include/asm/uaccess.h +6 -3
@@ -105,16 +105,18 @@ static inline void set_fs(mm_segment_t f#ifdef CONFIG_ARM64_SW_TTBR0_PAN static inline void __uaccess_ttbr0_disable (void ) { -unsigned long ttbr; +unsigned long flags, ttbr; +local_irq_save (flags); ttbr =read_sysreg (ttbr1_el1); + ttbr &= ~TTBR_ASID_MASK ;/* reserved_ttbr0 placed at the end of swapper_pg_dir */ write_sysreg (ttbr +SWAPPER_DIR_SIZE , ttbr0_el1);isb ();/* Set reserved ASID */ - ttbr &= ~TTBR_ASID_MASK ;write_sysreg (ttbr, ttbr1_el1);isb (); +local_irq_restore (flags); }static inline void __uaccess_ttbr0_enable (void )
@@ -127,10 +129,11 @@ static inline void __uaccess_ttbr0_enabl* roll-over and an update of 'ttbr0'. */ local_irq_save (flags); - ttbr0 =current_thread_info ()->ttbr0; + ttbr0 =READ_ONCE (current_thread_info ()->ttbr0);/* Restore active ASID */ ttbr1 =read_sysreg (ttbr1_el1); + ttbr1 &= ~TTBR_ASID_MASK ;/* safety measure */ ttbr1 |= ttbr0 &TTBR_ASID_MASK ;write_sysreg (ttbr1, ttbr1_el1);isb ();
arch/arm64/kernel/entry.S +1 -1
@@ -204,7 +204,7 @@ alternative_if ARM64_HAS_PAN alternative_else_nop_endif .if \el != 0 - mrs x21, ttbr1_el1 + mrs x21, ttbr0_el1 tst x21, #TTBR_ASID_MASK // Check for the reserved ASID orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR b.eq 1f // TTBR0 access already disabled
arch/arm64/lib/clear_user.S +1 -1
@@ -50,7 +50,7 @@ uao_user_alternative 9f, strh, sttrh, wz b.mi 5f uao_user_alternative 9f, strb, sttrb, wzr, x0, 0 5: mov x0, #0 - uaccess_disable_not_uao x2 + uaccess_disable_not_uao x2, x3 ret ENDPROC(__clear_user)
arch/arm64/lib/copy_from_user.S +1 -1
@@ -67,7 +67,7 @@ ENTRY(__arch_copy_from_user) uaccess_enable_not_uao x3, x4, x5 add end, x0, x2 #include "copy_template.S" - uaccess_disable_not_uao x3 + uaccess_disable_not_uao x3, x4 mov x0, #0 // Nothing to copy ret ENDPROC(__arch_copy_from_user)
arch/arm64/lib/copy_in_user.S +1 -1
@@ -68,7 +68,7 @@ ENTRY(raw_copy_in_user) uaccess_enable_not_uao x3, x4, x5 add end, x0, x2 #include "copy_template.S" - uaccess_disable_not_uao x3 + uaccess_disable_not_uao x3, x4 mov x0, #0 ret ENDPROC(raw_copy_in_user)
arch/arm64/lib/copy_to_user.S +1 -1
@@ -66,7 +66,7 @@ ENTRY(__arch_copy_to_user) uaccess_enable_not_uao x3, x4, x5 add end, x0, x2 #include "copy_template.S" - uaccess_disable_not_uao x3 + uaccess_disable_not_uao x3, x4 mov x0, #0 ret ENDPROC(__arch_copy_to_user)
arch/arm64/mm/cache.S +1 -1
@@ -72,7 +72,7 @@ USER(9f, ic ivau, x4 ) // invalidate I isb mov x0, #0 1: - uaccess_ttbr0_disable x1 + uaccess_ttbr0_disable x1, x2 ret 9: mov x0, #-EFAULT
arch/arm64/mm/proc.S +3 -0
@@ -140,6 +140,9 @@ ENDPROC(cpu_do_resume) ENTRY(cpu_do_switch_mm) mrs x2, ttbr1_el1 mmid x1, x1 // get mm->context.id +#ifdef CONFIG_ARM64_SW_TTBR0_PAN + bfi x0, x1, #48, #16 // set the ASID field in TTBR0 +#endif bfi x2, x1, #48, #16 // set the ASID msr ttbr1_el1, x2 // in TTBR1 (since TCR.A1 is set) isb
arch/arm64/xen/hypercall.S +1 -1
@@ -107,6 +107,6 @@ ENTRY(privcmd_call) /* * Disable userspace access from kernel once the hyp call completed. */ - uaccess_ttbr0_disable x6 + uaccess_ttbr0_disable x6, x7 ret ENDPROC(privcmd_call);
Greg Kroah-Hartman
maintainerPATCH 48/195 arm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jayachandran C <[email protected]>
Commit 0d90718871fe upstream.
Add the older Broadcom ID as well as the new Cavium ID for ThunderX2 CPUs.
--- arch/arm64/include/asm/cputype.h | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/include/asm/cputype.h +3 -0
@@ -87,6 +87,7 @@#define CAVIUM_CPU_PART_THUNDERX 0x0A1#define CAVIUM_CPU_PART_THUNDERX_81XX 0x0A2#define CAVIUM_CPU_PART_THUNDERX_83XX 0x0A3 +#define CAVIUM_CPU_PART_THUNDERX2 0x0AF#define BRCM_CPU_PART_VULCAN 0x516
@@ -100,6 +101,8 @@#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX) +#define MIDR_CAVIUM_THUNDERX2 MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX2) +#define MIDR_BRCM_VULCAN MIDR_CPU_MODEL(ARM_CPU_IMP_BRCM, BRCM_CPU_PART_VULCAN)#define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1)#define MIDR_QCOM_FALKOR MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR)#define MIDR_QCOM_KRYO MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO)
Greg Kroah-Hartman
maintainerPATCH 49/195 arm64: Turn on KPTI only on CPUs that need it
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jayachandran C <[email protected]>
Commit 0ba2e29c7fc1 upstream.
Whitelist Broadcom Vulcan/Cavium ThunderX2 processors in unmap_kernel_at_el0(). These CPUs are not vulnerable to CVE-2017-5754 and do not need KPTI when KASLR is off.
--- arch/arm64/kernel/cpufeature.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/kernel/cpufeature.c +7 -0
@@ -816,6 +816,13 @@ static bool unmap_kernel_at_el0(const stif (IS_ENABLED (CONFIG_RANDOMIZE_BASE ))return true; +/* Don't force KPTI for CPUs that are not vulnerable */ +switch (read_cpuid_id () &MIDR_CPU_MODEL_MASK ) { +case MIDR_CAVIUM_THUNDERX2 : +case MIDR_BRCM_VULCAN : +return false; + } +/* Defer to CPU feature registers */ return !cpuid_feature_extract_unsigned_field (pfr0,ID_AA64PFR0_CSV3_SHIFT );
Greg Kroah-Hartman
maintainerPATCH 50/195 arm64: kpti: Make use of nG dependent on arm64_kernel_unmapped_at_el0()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 41acec624087 upstream.
To allow systems which do not require kpti to continue running with global kernel mappings (which appears to be a requirement for Cavium ThunderX due to a CPU erratum), make the use of nG in the kernel page tables dependent on arm64_kernel_unmapped_at_el0(), which is resolved at runtime.
--- arch/arm64/include/asm/kernel-pgtable.h | 12 ++---------- arch/arm64/include/asm/pgtable-prot.h | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 26 deletions(-)
arch/arm64/include/asm/kernel-pgtable.h +2 -10
@@ -78,16 +78,8 @@/* * Initial memory map attributes. */ -#define _SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define _SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) - -#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 -#define SWAPPER_PTE_FLAGS (_SWAPPER_PTE_FLAGS | PTE_NG) -#define SWAPPER_PMD_FLAGS (_SWAPPER_PMD_FLAGS | PMD_SECT_NG) -#else -#define SWAPPER_PTE_FLAGS _SWAPPER_PTE_FLAGS -#define SWAPPER_PMD_FLAGS _SWAPPER_PMD_FLAGS -#endif +#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) +#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)#if ARM64_SWAPPER_USES_SECTION_MAPS #define SWAPPER_MM_MMUFLAGS (PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
arch/arm64/include/asm/pgtable-prot.h +14 -16
@@ -37,13 +37,11 @@#define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)#define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) -#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 -#define PROT_DEFAULT (_PROT_DEFAULT | PTE_NG) -#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_SECT_NG) -#else -#define PROT_DEFAULT _PROT_DEFAULT -#define PROT_SECT_DEFAULT _PROT_SECT_DEFAULT -#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ +#define PTE_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PTE_NG : 0) +#define PMD_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PMD_SECT_NG : 0) + +#define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG) +#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG)#define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))#define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
@@ -55,22 +53,22 @@#define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))#define PROT_SECT_NORMAL_EXEC (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL)) -#define _PAGE_DEFAULT (PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) -#define _HYP_PAGE_DEFAULT (_PAGE_DEFAULT & ~PTE_NG) +#define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) +#define _HYP_PAGE_DEFAULT _PAGE_DEFAULT -#define PAGE_KERNEL __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE) -#define PAGE_KERNEL_RO __pgprot(_PAGE_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_RDONLY) -#define PAGE_KERNEL_ROX __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_RDONLY) -#define PAGE_KERNEL_EXEC __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE) -#define PAGE_KERNEL_EXEC_CONT __pgprot(_PAGE_DEFAULT | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_CONT) +#define PAGE_KERNEL __pgprot(PROT_NORMAL) +#define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY) +#define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY) +#define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN) +#define PAGE_KERNEL_EXEC_CONT __pgprot((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)#define PAGE_HYP __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_HYP_XN)#define PAGE_HYP_EXEC __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY)#define PAGE_HYP_RO __pgprot(_HYP_PAGE_DEFAULT | PTE_HYP | PTE_RDONLY | PTE_HYP_XN)#define PAGE_HYP_DEVICE __pgprot(PROT_DEVICE_nGnRE | PTE_HYP) -#define PAGE_S2 __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_S2_RDONLY) -#define PAGE_S2_DEVICE __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_UXN) +#define PAGE_S2 __pgprot(_PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_S2_RDONLY) +#define PAGE_S2_DEVICE __pgprot(_PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_UXN)#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)#define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
Greg Kroah-Hartman
maintainerPATCH 51/195 arm64: mm: Permit transitioning from Global to Non-Global without BBM
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 4e6020565596 upstream.
Break-before-make is not needed when transitioning from Global to Non-Global mappings, provided that the contiguous hint is not being used.
--- arch/arm64/mm/mmu.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/mm/mmu.c +4 -0
@@ -117,6 +117,10 @@ static bool pgattr_change_is_safe(u64 olif ((old | new) &PTE_CONT )return false; +/* Transitioning from Global to Non-Global is safe */ +if (((old ^ new) ==PTE_NG ) && (new &PTE_NG )) +return true; +return ((old ^ new) & ~mask) ==0 ; }
Greg Kroah-Hartman
maintainerPATCH 52/195 arm64: kpti: Add ->enable callback to remap swapper using nG mappings
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit f992b4dfd58b upstream.
Defaulting to global mappings for kernel space is generally good for performance and appears to be necessary for Cavium ThunderX. If we subsequently decide that we need to enable kpti, then we need to rewrite our existing page table entries to be non-global. This is fiddly, and made worse by the possible use of contiguous mappings, which require a strict break-before-make sequence.
Since the enable callback runs on each online CPU from stop_machine context, we can have all CPUs enter the idmap, where secondaries can wait for the primary CPU to rewrite swapper with its MMU off. It's all fairly horrible, but at least it only runs once.
--- arch/arm64/include/asm/assembler.h | 4 arch/arm64/kernel/cpufeature.c | 25 ++++ arch/arm64/mm/proc.S | 201 +++++++++++++++++++++++++++++++++++-- 3 files changed, 223 insertions(+), 7 deletions(-)
arch/arm64/include/asm/assembler.h +4 -0
@@ -486,4 +486,8 @@ alternative_else_nop_endif#endif .endm + .macro pte_to_phys, phys, pte + and \phys, \pte, #(((1 << (48 - PAGE_SHIFT)) - 1) << PAGE_SHIFT) + .endm +#endif /* __ASM_ASSEMBLER_H */
arch/arm64/kernel/cpufeature.c +25 -0
@@ -828,6 +828,30 @@ static bool unmap_kernel_at_el0(const st ID_AA64PFR0_CSV3_SHIFT); } +static int kpti_install_ng_mappings (void *__unused) +{ +typedef void (kpti_remap_fn )(int ,int ,phys_addr_t ); +extern kpti_remap_fn idmap_kpti_install_ng_mappings; +kpti_remap_fn *remap_fn; + +static bool kpti_applied = false; +int cpu =smp_processor_id (); + +if (kpti_applied) +return 0 ; + + remap_fn = (void *)__pa_symbol (idmap_kpti_install_ng_mappings); + +cpu_install_idmap (); +remap_fn (cpu,num_online_cpus (),__pa_symbol (swapper_pg_dir)); +cpu_uninstall_idmap (); + +if (!cpu) + kpti_applied = true; + +return 0 ; +} +static int __init parse_kpti (char *str) {bool enabled;
@@ -934,6 +958,7 @@ static const struct arm64_cpu_capabiliti .capability = ARM64_UNMAP_KERNEL_AT_EL0, .def_scope = SCOPE_SYSTEM, .matches = unmap_kernel_at_el0, + .enable = kpti_install_ng_mappings, },#endif {
arch/arm64/mm/proc.S +194 -7
219 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 53/195 arm64: Force KPTI to be disabled on Cavium ThunderX
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 6dc52b15c4a4 upstream.
Cavium ThunderX's erratum 27456 results in a corruption of icache entries that are loaded from memory that is mapped as non-global (i.e. ASID-tagged).
As KPTI is based on memory being mapped non-global, let's prevent it from kicking in if this erratum is detected.
--- arch/arm64/kernel/cpufeature.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
arch/arm64/kernel/cpufeature.c +14 -3
@@ -803,12 +803,23 @@ static int __kpti_forced; /* 0: not forcstatic bool unmap_kernel_at_el0 (const struct arm64_cpu_capabilities *entry,int __unused) { +char const *str ="command line option" ;u64 pfr0 =read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ); -/* Forced on command line? */ +/* +* For reasons that aren't entirely clear, enabling KPTI on Cavium +* ThunderX leads to apparent I-cache corruption of kernel text, which +* ends as well as you might imagine. Don't even try. +*/ +if (cpus_have_const_cap (ARM64_WORKAROUND_CAVIUM_27456 )) { + str ="ARM64_WORKAROUND_CAVIUM_27456" ; + __kpti_forced =-1 ; + } + +/* Forced? */ if (__kpti_forced) { -pr_info_once ("kernel page table isolation forced %s by command line option\n" , - __kpti_forced >0 ?"ON" :"OFF" ); +pr_info_once ("kernel page table isolation forced %s by %s\n" , + __kpti_forced >0 ?"ON" :"OFF" , str);return __kpti_forced >0 ; }
Greg Kroah-Hartman
maintainerPATCH 54/195 arm64: entry: Reword comment about post_ttbr_update_workaround
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit f167211a93ac upstream.
We don't fully understand the Cavium ThunderX erratum, but it appears that mapping the kernel as nG can lead to horrible consequences such as attempting to execute userspace from kernel context. Since kpti isn't enabled for these CPUs anyway, simplify the comment justifying the lack of post_ttbr_update_workaround in the exception trampoline.
--- arch/arm64/kernel/entry.S | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
arch/arm64/kernel/entry.S +3 -10
@@ -962,16 +962,9 @@ alternative_else_nop_endif orr \tmp, \tmp, #USER_ASID_FLAG msr ttbr1_el1, \tmp /* - * We avoid running the post_ttbr_update_workaround here because the - * user and kernel ASIDs don't have conflicting mappings, so any - * "blessing" as described in: - * - * http://lkml.kernel.org/r/[email protected] - * - * will not hurt correctness. Whilst this may partially defeat the - * point of using split ASIDs in the first place, it avoids - * the hit of invalidating the entire I-cache on every return to - * userspace. + * We avoid running the post_ttbr_update_workaround here because + * it's only needed by Cavium ThunderX, which requires KPTI to be + * disabled. */ .endm
Greg Kroah-Hartman
maintainerPATCH 55/195 arm64: idmap: Use "awx" flags for .idmap.text .pushsection directives
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 439e70e27a51 upstream.
The identity map is mapped as both writeable and executable by the SWAPPER_MM_MMUFLAGS and this is relied upon by the kpti code to manage a synchronisation flag. Update the .pushsection flags to reflect the actual mapping attributes.
--- arch/arm64/kernel/cpu-reset.S | 2 +- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/sleep.S | 2 +- arch/arm64/mm/proc.S | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-)
arch/arm64/kernel/cpu-reset.S +1 -1
@@ -16,7 +16,7 @@ #include <asm/virt.h> .text -.pushsection .idmap.text, "ax" +.pushsection .idmap.text, "awx" /* * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for
arch/arm64/kernel/head.S +1 -1
@@ -371,7 +371,7 @@ ENDPROC(__primary_switched) * end early head section, begin head code that is also used for * hotplug and needs to have the same protections as the text region */ - .section ".idmap.text","ax" + .section ".idmap.text","awx" ENTRY(kimage_vaddr) .quad _text - TEXT_OFFSET
arch/arm64/kernel/sleep.S +1 -1
@@ -96,7 +96,7 @@ ENTRY(__cpu_suspend_enter) ret ENDPROC(__cpu_suspend_enter) - .pushsection ".idmap.text", "ax" + .pushsection ".idmap.text", "awx" ENTRY(cpu_resume) bl el2_setup // if in EL2 drop to EL1 cleanly bl __cpu_setup
arch/arm64/mm/proc.S +4 -4
@@ -86,7 +86,7 @@ ENDPROC(cpu_do_suspend) * * x0: Address of context pointer */ - .pushsection ".idmap.text", "ax" + .pushsection ".idmap.text", "awx" ENTRY(cpu_do_resume) ldp x2, x3, [x0] ldp x4, x5, [x0, #16]
@@ -152,7 +152,7 @@ ENTRY(cpu_do_switch_mm) ret ENDPROC(cpu_do_switch_mm) - .pushsection ".idmap.text", "ax" + .pushsection ".idmap.text", "awx" .macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2 adrp \tmp1, empty_zero_page
@@ -185,7 +185,7 @@ ENDPROC(idmap_cpu_replace_ttbr1) .popsection #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 - .pushsection ".idmap.text", "ax" + .pushsection ".idmap.text", "awx" .macro __idmap_kpti_get_pgtable_ent, type dc cvac, cur_\()\type\()p // Ensure any existing dirty
@@ -373,7 +373,7 @@ ENDPROC(idmap_kpti_install_ng_mappings) * Initialise the processor for turning the MMU on. Return in x0 the * value of the SCTLR_EL1 register. */ - .pushsection ".idmap.text", "ax" + .pushsection ".idmap.text", "awx" ENTRY(__cpu_setup) tlbi vmalle1 // Invalidate local TLB dsb nsh
Greg Kroah-Hartman
maintainerPATCH 56/195 arm64: barrier: Add CSDB macros to control data-value prediction
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 669474e772b9 upstream.
For CPUs capable of data value prediction, CSDB waits for any outstanding predictions to architecturally resolve before allowing speculative execution to continue. Provide macros to expose it to the arch code.
--- arch/arm64/include/asm/assembler.h | 7 +++++++ arch/arm64/include/asm/barrier.h | 2 ++ 2 files changed, 9 insertions(+)
arch/arm64/include/asm/assembler.h +7 -0
@@ -96,6 +96,13 @@ .endm /* + * Value prediction barrier + */ + .macro csdb + hint #20 + .endm + +/* * NOP sequence */ .macro nops, num
arch/arm64/include/asm/barrier.h +2 -0
@@ -31,6 +31,8 @@#define dmb (opt) asm volatile("dmb " #opt : : : "memory")#define dsb (opt) asm volatile("dsb " #opt : : : "memory") +#define csdb () asm volatile("hint #20" : : : "memory") +#define mb () dsb(sy)#define rmb () dsb(ld)#define wmb () dsb(st)
Greg Kroah-Hartman
maintainerPATCH 58/195 arm64: Make USER_DS an inclusive limit
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robin Murphy <[email protected]>
Commit 51369e398d0d upstream.
Currently, USER_DS represents an exclusive limit while KERNEL_DS is inclusive. In order to do some clever trickery for speculation-safe masking, we need them both to behave equivalently - there aren't enough bits to make KERNEL_DS exclusive, so we have precisely one option. This also happens to correct a longstanding false negative for a range ending on the very top byte of kernel memory.
Mark Rutland points out that we've actually got the semantics of addresses vs. segments muddled up in most of the places we need to amend, so shuffle the {USER,KERNEL}_DS definitions around such that we can correct those properly instead of just pasting "-1"s everywhere.
--- arch/arm64/include/asm/processor.h | 3 ++ arch/arm64/include/asm/uaccess.h | 45 +++++++++++++++++++++---------------- arch/arm64/kernel/entry.S | 4 +-- arch/arm64/mm/fault.c | 4 +-- 4 files changed, 33 insertions(+), 23 deletions(-)
arch/arm64/include/asm/processor.h +3 -0
@@ -21,6 +21,9 @@#define TASK_SIZE_64 (UL(1) << VA_BITS) +#define KERNEL_DS UL(-1) +#define USER_DS (TASK_SIZE_64 - 1) +#ifndef __ASSEMBLY__/*
arch/arm64/include/asm/uaccess.h +26 -19
65 lines not on this page · raw message
arch/arm64/kernel/entry.S +2 -2
@@ -167,10 +167,10 @@ alternative_else_nop_endif .else add x21, sp, #S_FRAME_SIZE get_thread_info tsk - /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */ + /* Save the task's original addr_limit and set USER_DS */ ldr x20, [tsk, #TSK_TI_ADDR_LIMIT] str x20, [sp, #S_ORIG_ADDR_LIMIT] - mov x20, #TASK_SIZE_64 + mov x20, #USER_DS str x20, [tsk, #TSK_TI_ADDR_LIMIT] /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */ .endif /* \el == 0 */
arch/arm64/mm/fault.c +2 -2
@@ -242,7 +242,7 @@ static inline bool is_permission_fault(uif (fsc_type == ESR_ELx_FSC_PERM)return true; -if (addr <USER_DS &&system_uses_ttbr0_pan ()) +if (addr <TASK_SIZE &&system_uses_ttbr0_pan ())return fsc_type == ESR_ELx_FSC_FAULT && (regs->pstate &PSR_PAN_BIT );
@@ -426,7 +426,7 @@ static int __kprobes do_page_fault(unsig mm_flags |=FAULT_FLAG_WRITE ; } -if (addr <USER_DS &&is_permission_fault (esr, regs, addr)) { +if (addr <TASK_SIZE &&is_permission_fault (esr, regs, addr)) {/* regs->orig_addr_limit may be 0 if we entered from EL0 */ if (regs->orig_addr_limit ==KERNEL_DS )die ("Accessing user space memory with fs=KERNEL_DS" , regs, esr);
Greg Kroah-Hartman
maintainerPATCH 59/195 arm64: Use pointer masking to limit uaccess speculation
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robin Murphy <[email protected]>
Commit 4d8efc2d5ee4 upstream.
Similarly to x86, mitigate speculation past an access_ok() check by masking the pointer against the address limit before use.
Even if we don't expect speculative writes per se, it is plausible that a CPU may still speculate at least as far as fetching a cache line for writing, hence we also harden put_user() and clear_user() for peace of mind.
--- arch/arm64/include/asm/uaccess.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
arch/arm64/include/asm/uaccess.h +23 -3
@@ -216,6 +216,26 @@ static inline void uaccess_enable_not_ua }/* +* Sanitise a uaccess pointer such that it becomes NULL if above the +* current addr_limit. +*/ +#define uaccess_mask_ptr (ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) +static inline void __user *__uaccess_mask_ptr (const void __user *ptr) +{ +void __user *safe_ptr; + + asmvolatile ( +" bics xzr, %1, %2\n" +" csel %0, %1, xzr, eq\n" + :"=&r" (safe_ptr) + :"r" (ptr),"r" (current_thread_info ()->addr_limit) + :"cc" ); + +csdb (); +return safe_ptr; +} + +/* * The "__xxx" versions of the user access functions do not verify the address * space - it must have been done previously with a separate "access_ok()" * call.
@@ -285,7 +305,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \might_fault (); \access_ok (VERIFY_READ , __p,sizeof (*__p)) ? \ -__get_user ((x), __p) : \ + __p =uaccess_mask_ptr (__p),__get_user ((x), __p) : \ ((x) =0 , -EFAULT ); \ })
@@ -349,7 +369,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \might_fault (); \access_ok (VERIFY_WRITE , __p,sizeof (*__p)) ? \ -__put_user ((x), __p) : \ + __p =uaccess_mask_ptr (__p),__put_user ((x), __p) : \ -EFAULT ; \ })
@@ -365,7 +385,7 @@ extern unsigned long __must_check __cleastatic inline unsigned long __must_check clear_user (void __user *to,unsigned long n) {if (access_ok (VERIFY_WRITE , to, n)) - n =__clear_user (to, n); + n =__clear_user (__uaccess_mask_ptr (to), n);return n; }
Greg Kroah-Hartman
maintainerPATCH 60/195 arm64: entry: Ensure branch through syscall table is bounded under speculation
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 6314d90e6493 upstream.
In a similar manner to array_index_mask_nospec, this patch introduces an assembly macro (mask_nospec64) which can be used to bound a value under speculation. This macro is then used to ensure that the indirect branch through the syscall table is bounded under speculation, with out-of-range addresses speculating as calls to sys_io_setup (0).
--- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 2 ++ 2 files changed, 13 insertions(+)
arch/arm64/include/asm/assembler.h +11 -0
@@ -103,6 +103,17 @@ .endm /* + * Sanitise a 64-bit bounded index wrt speculation, returning zero if out + * of bounds. + */ + .macro mask_nospec64, idx, limit, tmp + sub \tmp, \idx, \limit + bic \tmp, \tmp, \idx + and \idx, \idx, \tmp, asr #63 + csdb + .endm + +/* * NOP sequence */ .macro nops, num
arch/arm64/kernel/entry.S +2 -0
@@ -376,6 +376,7 @@ alternative_insn eret, nop, ARM64_UNMAP_ * x7 is reserved for the system call number in 32-bit mode. */ wsc_nr .req w25 // number of system calls +xsc_nr .req x25 // number of system calls (zero-extended) wscno .req w26 // syscall number xscno .req x26 // syscall number (zero-extended) stbl .req x27 // syscall table pointer
@@ -884,6 +885,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp wscno, wsc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 xscno, xsc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, xscno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall
Greg Kroah-Hartman
maintainerPATCH 61/195 arm64: uaccess: Prevent speculative use of the current addr_limit
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit c2f0ad4fc089 upstream.
A mispredicted conditional call to set_fs could result in the wrong addr_limit being forwarded under speculation to a subsequent access_ok check, potentially forming part of a spectre-v1 attack using uaccess routines.
This patch prevents this forwarding from taking place, but putting heavy barriers in set_fs after writing the addr_limit.
--- arch/arm64/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/include/asm/uaccess.h +7 -0
@@ -42,6 +42,13 @@ static inline void set_fs(mm_segment_t f {current_thread_info ()->addr_limit = fs; +/* +* Prevent a mispredicted conditional call to set_fs from forwarding +* the wrong address limit to access_ok under speculation. +*/ +dsb (nsh); +isb (); +/* On user-mode return, check fs is correct */ set_thread_flag (TIF_FSCHECK );
Greg Kroah-Hartman
maintainerPATCH 63/195 arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit f71c2ffcb20d upstream.
Like we've done for get_user and put_user, ensure that user pointers are masked before invoking the underlying __arch_{clear,copy_*}_user operations.
--- arch/arm64/include/asm/uaccess.h | 29 ++++++++++++++++++++++------- arch/arm64/kernel/arm64ksyms.c | 4 ++-- arch/arm64/lib/clear_user.S | 6 +++--- arch/arm64/lib/copy_in_user.S | 5 +++-- 4 files changed, 30 insertions(+), 14 deletions(-)
arch/arm64/include/asm/uaccess.h +22 -7
@@ -391,20 +391,35 @@ do { \#define put_user __put_userextern unsigned long __must_check __arch_copy_from_user (void *to,const void __user *from,unsigned long n); -#define raw_copy_from_user __arch_copy_from_user +#define raw_copy_from_user (to, from, n) \ +({ \ + __arch_copy_from_user((to), __uaccess_mask_ptr(from), (n)); \ +}) +extern unsigned long __must_check __arch_copy_to_user (void __user *to,const void *from,unsigned long n); -#define raw_copy_to_user __arch_copy_to_user -extern unsigned long __must_check raw_copy_in_user (void __user *to,const void __user *from,unsigned long n); -extern unsigned long __must_check __clear_user (void __user *addr,unsigned long n); +#define raw_copy_to_user (to, from, n) \ +({ \ + __arch_copy_to_user(__uaccess_mask_ptr(to), (from), (n)); \ +}) + +extern unsigned long __must_check __arch_copy_in_user (void __user *to,const void __user *from,unsigned long n); +#define raw_copy_in_user (to, from, n) \ +({ \ + __arch_copy_in_user(__uaccess_mask_ptr(to), \ + __uaccess_mask_ptr(from), (n)); \ +}) +#define INLINE_COPY_TO_USER #define INLINE_COPY_FROM_USER -static inline unsigned long __must_check clear_user (void __user *to,unsigned long n) +extern unsigned long __must_check __arch_clear_user (void __user *to,unsigned long n); +static inline unsigned long __must_check __clear_user (void __user *to,unsigned long n) {if (access_ok (VERIFY_WRITE , to, n)) - n =__clear_user (__uaccess_mask_ptr (to), n); + n =__arch_clear_user (__uaccess_mask_ptr (to), n);return n; } +#define clear_user __clear_userextern long strncpy_from_user (char *dest,const char __user *src,long count);
@@ -418,7 +433,7 @@ extern unsigned long __must_check __copystatic inline int __copy_from_user_flushcache (void *dst,const void __user *src,unsigned size) {kasan_check_write (dst, size); -return __copy_user_flushcache (dst, src, size); +return __copy_user_flushcache (dst,__uaccess_mask_ptr (src), size); }#endif
arch/arm64/kernel/arm64ksyms.c +2 -2
@@ -37,8 +37,8 @@ EXPORT_SYMBOL(clear_page);/* user mem (segment) */ EXPORT_SYMBOL (__arch_copy_from_user);EXPORT_SYMBOL (__arch_copy_to_user); -EXPORT_SYMBOL (__clear_user); -EXPORT_SYMBOL (raw_copy_in_user); +EXPORT_SYMBOL (__arch_clear_user); +EXPORT_SYMBOL (__arch_copy_in_user);/* physical memory */ EXPORT_SYMBOL (memstart_addr);
arch/arm64/lib/clear_user.S +3 -3
@@ -21,7 +21,7 @@ .text -/* Prototype: int __clear_user(void *addr, size_t sz) +/* Prototype: int __arch_clear_user(void *addr, size_t sz) * Purpose : clear some user memory * Params : addr - user memory address to clear * : sz - number of bytes to clear
@@ -29,7 +29,7 @@ * * Alignment fixed up by hardware. */ -ENTRY(__clear_user) +ENTRY(__arch_clear_user) uaccess_enable_not_uao x2, x3, x4 mov x2, x1 // save the size for fixup return subs x1, x1, #8
@@ -52,7 +52,7 @@ uao_user_alternative 9f, strb, sttrb, wz 5: mov x0, #0 uaccess_disable_not_uao x2, x3 ret -ENDPROC(__clear_user) +ENDPROC(__arch_clear_user) .section .fixup,"ax" .align 2
arch/arm64/lib/copy_in_user.S +3 -2
@@ -64,14 +64,15 @@ .endm end .req x5 -ENTRY(raw_copy_in_user) + +ENTRY(__arch_copy_in_user) uaccess_enable_not_uao x3, x4, x5 add end, x0, x2 #include "copy_template.S" uaccess_disable_not_uao x3, x4 mov x0, #0 ret -ENDPROC(raw_copy_in_user) +ENDPROC(__arch_copy_in_user) .section .fixup,"ax" .align 2
Greg Kroah-Hartman
maintainerPATCH 64/195 arm64: futex: Mask __user pointers prior to dereference
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 91b2d3442f6a upstream.
The arm64 futex code has some explicit dereferencing of user pointers where performing atomic operations in response to a futex command. This patch uses masking to limit any speculative futex operations to within the user address space.
--- arch/arm64/include/asm/futex.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/include/asm/futex.h +6 -3
@@ -48,9 +48,10 @@ do { \ }while (0 ) static inline int -arch_futex_atomic_op_inuser (int op,int oparg,int *oval,u32 __user *uaddr) +arch_futex_atomic_op_inuser (int op,int oparg,int *oval,u32 __user *_uaddr) {int oldval =0 , ret, tmp; +u32 __user *uaddr =__uaccess_mask_ptr (_uaddr);pagefault_disable ();
@@ -88,15 +89,17 @@ arch_futex_atomic_op_inuser(int op, int }static inline int -futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *uaddr, +futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *_uaddr,u32 oldval,u32 newval) {int ret =0 ;u32 val, tmp; +u32 __user *uaddr; -if (!access_ok (VERIFY_WRITE , uaddr,sizeof (u32))) +if (!access_ok (VERIFY_WRITE , _uaddr,sizeof (u32)))return -EFAULT ; + uaddr =__uaccess_mask_ptr (_uaddr);uaccess_enable (); asmvolatile ("// futex_atomic_cmpxchg_inatomic\n" " prfm pstl1strm, %2\n"
Greg Kroah-Hartman
maintainerPATCH 65/195 arm64: cpufeature: __this_cpu_has_cap() shouldnt stop early
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Morse <[email protected]>
Commit edf298cfce47 upstream.
this_cpu_has_cap() tests caps->desc not caps->matches, so it stops walking the list when it finds a 'silent' feature, instead of walking to the end of the list.
Prior to v4.6's 644c2ae198412 ("arm64: cpufeature: Test 'matches' pointer to find the end of the list") we always tested desc to find the end of a capability list. This was changed for dubious things like PAN_NOT_UAO. v4.7's e3661b128e53e ("arm64: Allow a capability to be checked on single CPU") added this_cpu_has_cap() using the old desc style test.
--- arch/arm64/kernel/cpufeature.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/kernel/cpufeature.c +1 -2
@@ -1102,9 +1102,8 @@ static bool __this_cpu_has_cap(const strif (WARN_ON (preemptible ()))return false; -for (caps = cap_array; caps->desc; caps++) +for (caps = cap_array; caps->matches; caps++)if (caps->capability == cap && - caps->matches && caps->matches (caps,SCOPE_LOCAL_CPU ))return true;return false;
Greg Kroah-Hartman
maintainerPATCH 67/195 arm64: cpufeature: Pass capability structure to ->enable callback
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 0a0d111d40fd upstream.
In order to invoke the CPU capability ->matches callback from the ->enable callback for applying local-CPU workarounds, we need a handle on the capability structure.
This patch passes a pointer to the capability structure to the ->enable callback.
--- arch/arm64/kernel/cpufeature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/cpufeature.c +2 -2
@@ -1144,7 +1144,7 @@ void __init enable_cpu_capabilities(cons* uses an IPI, giving us a PSTATE that disappears when * we return. */ -stop_machine (caps->enable,NULL , cpu_online_mask); +stop_machine (caps->enable, (void *)caps, cpu_online_mask); } } }
@@ -1203,7 +1203,7 @@ verify_local_cpu_features(const struct acpu_die_early (); }if (caps->enable) - caps->enable (NULL ); + caps->enable ((void *)caps); } }
Greg Kroah-Hartman
maintainerPATCH 68/195 drivers/firmware: Expose psci_get_version through psci_ops structure
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit d68e3ba5303f upstream.
Entry into recent versions of ARM Trusted Firmware will invalidate the CPU branch predictor state in order to protect against aliasing attacks.
This patch exposes the PSCI "VERSION" function via psci_ops, so that it can be invoked outside of the PSCI driver where necessary.
--- drivers/firmware/psci.c | 2 ++ include/linux/psci.h | 1 + 2 files changed, 3 insertions(+)
drivers/firmware/psci.c +2 -0
@@ -496,6 +496,8 @@ static void __init psci_init_migrate(voistatic void __init psci_0_2_set_functions (void ) {pr_info ("Using standard PSCI v0.2 function IDs\n" ); + psci_ops.get_version = psci_get_version; + psci_function_id[PSCI_FN_CPU_SUSPEND ] = PSCI_FN_NATIVE(0_2, CPU_SUSPEND); psci_ops.cpu_suspend = psci_cpu_suspend;
include/linux/psci.h +1 -0
@@ -26,6 +26,7 @@ int psci_cpu_init_idle(unsigned int cpu)int psci_cpu_suspend_enter (unsigned long index);struct psci_operations { +u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);int (*cpu_off)(u32 state);int (*cpu_on)(unsigned long cpuid,unsigned long entry_point);
Greg Kroah-Hartman
maintainerPATCH 69/195 arm64: Move post_ttbr_update_workaround to C code
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 95e3de3590e3 upstream.
We will soon need to invoke a CPU-specific function pointer after changing page tables, so move post_ttbr_update_workaround out into C code to make this possible.
--- arch/arm64/include/asm/assembler.h | 13 ------------- arch/arm64/kernel/entry.S | 2 +- arch/arm64/mm/context.c | 9 +++++++++ arch/arm64/mm/proc.S | 3 +-- 4 files changed, 11 insertions(+), 16 deletions(-)
arch/arm64/include/asm/assembler.h +0 -13
@@ -481,19 +481,6 @@ alternative_endif mrs \rd, sp_el0 .endm -/* - * Errata workaround post TTBRx_EL1 update. - */ - .macro post_ttbr_update_workaround -#ifdef CONFIG_CAVIUM_ERRATUM_27456 -alternative_if ARM64_WORKAROUND_CAVIUM_27456 - ic iallu - dsb nsh -isb -alternative_else_nop_endif -#endif - .endm -/** * Errata workaround prior to disable MMU. Insert an ISB immediately prior * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0.
arch/arm64/kernel/entry.S +1 -1
@@ -275,7 +275,7 @@ alternative_else_nop_endif * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache * corruption). */ - post_ttbr_update_workaround + bl post_ttbr_update_workaround .endif 1: .if \el != 0
arch/arm64/mm/context.c +9 -0
@@ -235,6 +235,15 @@ switch_mm_fastpath:cpu_switch_mm (mm->pgd, mm); } +/* Errata workaround post TTBRx_EL1 update. */ +asmlinkage void post_ttbr_update_workaround(void) +{ + asm(ALTERNATIVE("nop; nop; nop", +"ic iallu; dsb nsh; isb" , +ARM64_WORKAROUND_CAVIUM_27456 , + CONFIG_CAVIUM_ERRATUM_27456)); +} +static int asids_init (void ) { asid_bits =get_cpu_asid_bits ();
arch/arm64/mm/proc.S +1 -2
@@ -148,8 +148,7 @@ ENTRY(cpu_do_switch_mm) isb msr ttbr0_el1, x0 // now update TTBR0 isb - post_ttbr_update_workaround - ret + b post_ttbr_update_workaround // Back to C code... ENDPROC(cpu_do_switch_mm) .pushsection ".idmap.text", "awx"
Greg Kroah-Hartman
maintainerPATCH 70/195 arm64: Add skeleton to harden the branch predictor against aliasing attacks
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 0f15adbb2861 upstream.
Aliasing attacks against CPU branch predictors can allow an attacker to redirect speculative control flow on some CPUs and potentially divulge information from one context to another.
This patch adds initial skeleton code behind a new Kconfig option to enable implementation-specific mitigations against these attacks for CPUs that are affected.
--- arch/arm64/Kconfig | 17 ++++++++ arch/arm64/include/asm/cpucaps.h | 3 + arch/arm64/include/asm/mmu.h | 37 +++++++++++++++++++ arch/arm64/include/asm/sysreg.h | 1 arch/arm64/kernel/Makefile | 4 ++ arch/arm64/kernel/bpi.S | 55 ++++++++++++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 74 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/cpufeature.c | 1 arch/arm64/kernel/entry.S | 8 ++-- arch/arm64/mm/context.c | 2 + arch/arm64/mm/fault.c | 17 ++++++++ 11 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/kernel/bpi.S
arch/arm64/Kconfig +17 -0
@@ -818,6 +818,23 @@ config UNMAP_KERNEL_AT_EL0 If unsure, say Y. +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT + default y + help + Speculation attacks against some high-performance processors rely on + being able to manipulate the branch predictor for a victim context by + executing aliasing branches in the attacker context. Such attacks + can be partially mitigated against by clearing internal branch + predictor state and limiting the prediction logic in some situations. + + This config option will take CPU-specific actions to harden the + branch predictor against aliasing attacks and may rely on specific + instruction sequences or control bits being set by the system + firmware. + + If unsure, say Y. + menuconfig ARMV8_DEPRECATED bool "Emulate deprecated/obsolete ARMv8 instructions" depends on COMPAT
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -41,7 +41,8 @@#define ARM64_WORKAROUND_CAVIUM_30115 20#define ARM64_HAS_DCPOP 21#define ARM64_UNMAP_KERNEL_AT_EL0 23 +#define ARM64_HARDEN_BRANCH_PREDICTOR 24 -#define ARM64_NCAPS 24 +#define ARM64_NCAPS 25#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/mmu.h +37 -0
@@ -41,6 +41,43 @@ static inline bool arm64_kernel_unmappedcpus_have_const_cap (ARM64_UNMAP_KERNEL_AT_EL0 ); } +typedef void (*bp_hardening_cb_t )(void ); + +struct bp_hardening_data { +int hyp_vectors_slot; +bp_hardening_cb_t fn; +}; + +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +extern char __bp_harden_hyp_vecs_start[], __bp_harden_hyp_vecs_end[]; + +DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); + +static inline struct bp_hardening_data *arm64_get_bp_hardening_data (void ) +{ +return this_cpu_ptr (&bp_hardening_data); +} + +static inline void arm64_apply_bp_hardening (void ) +{ +struct bp_hardening_data *d; + +if (!cpus_have_const_cap (ARM64_HARDEN_BRANCH_PREDICTOR )) +return ; + + d =arm64_get_bp_hardening_data (); +if (d->fn) + d->fn (); +} +#else +static inline struct bp_hardening_data *arm64_get_bp_hardening_data (void ) +{ +return NULL ; +} + +static inline void arm64_apply_bp_hardening (void ) { } +#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ +extern void paging_init (void );extern void bootmem_init (void );extern void __iomem *early_io_map (phys_addr_t phys,unsigned long virt);
arch/arm64/include/asm/sysreg.h +1 -0
@@ -333,6 +333,7 @@/* id_aa64pfr0 */ #define ID_AA64PFR0_CSV3_SHIFT 60 +#define ID_AA64PFR0_CSV2_SHIFT 56#define ID_AA64PFR0_GIC_SHIFT 24#define ID_AA64PFR0_ASIMD_SHIFT 20#define ID_AA64PFR0_FP_SHIFT 16
arch/arm64/kernel/Makefile +4 -0
@@ -55,6 +55,10 @@ arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o +ifeq ($(CONFIG_KVM),y) +arm64-obj-$(CONFIG_HARDEN_BRANCH_PREDICTOR) += bpi.o +endif + obj-y += $(arm64-obj-y) vdso/ probes/ obj-m += $(arm64-obj-m) head-y := head.o
arch/arm64/kernel/bpi.S new file +55 -0
55 lines not on this page · raw message
arch/arm64/kernel/cpu_errata.c +74 -0
80 lines not on this page · raw message
arch/arm64/kernel/cpufeature.c +1 -0
@@ -126,6 +126,7 @@ static const struct arm64_ftr_bits ftr_istatic const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {ARM64_FTR_BITS (FTR_HIDDEN ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_CSV3_SHIFT ,4 ,0 ), +ARM64_FTR_BITS (FTR_HIDDEN ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_CSV2_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_HIDDEN ,FTR_STRICT ,FTR_EXACT ,ID_AA64PFR0_GIC_SHIFT ,4 ,0 ),S_ARM64_FTR_BITS (FTR_VISIBLE ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_ASIMD_SHIFT ,4 ,ID_AA64PFR0_ASIMD_NI ),S_ARM64_FTR_BITS (FTR_VISIBLE ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_FP_SHIFT ,4 ,ID_AA64PFR0_FP_NI ),
arch/arm64/kernel/entry.S +5 -3
@@ -724,13 +724,15 @@ el0_ia: * Instruction abort handling */ mrs x26, far_el1 - // enable interrupts before calling the main handler - enable_dbg_and_irq + enable_dbg +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif ct_user_exit mov x0, x26 mov x1, x25 mov x2, sp - bl do_mem_abort + bl do_el0_ia_bp_hardening b ret_to_user el0_fpsimd_acc: /*
arch/arm64/mm/context.c +2 -0
@@ -242,6 +242,8 @@ asmlinkage void post_ttbr_update_workaro"ic iallu; dsb nsh; isb" ,ARM64_WORKAROUND_CAVIUM_27456 , CONFIG_CAVIUM_ERRATUM_27456)); + +arm64_apply_bp_hardening (); }static int asids_init (void )
arch/arm64/mm/fault.c +17 -0
@@ -751,6 +751,23 @@ asmlinkage void __exception do_mem_abortarm64_notify_die ("" , regs, &info, esr); } +asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr, +unsigned int esr, +struct pt_regs *regs) +{ +/* +* We've taken an instruction abort from userspace and not yet +* re-enabled IRQs. If the address is a kernel address, apply +* BP hardening prior to enabling IRQs and pre-emption. +*/ +if (addr >TASK_SIZE ) +arm64_apply_bp_hardening (); + +local_irq_enable (); +do_mem_abort (addr, esr, regs); +} + +/* * Handle stack alignment exceptions. */
Greg Kroah-Hartman
maintainerPATCH 71/195 arm64: Move BP hardening to check_and_switch_context
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit a8e4c0a919ae upstream.
We call arm64_apply_bp_hardening() from post_ttbr_update_workaround, which has the unexpected consequence of being triggered on every exception return to userspace when ARM64_SW_TTBR0_PAN is selected, even if no context switch actually occured.
This is a bit suboptimal, and it would be more logical to only invalidate the branch predictor when we actually switch to a different mm.
In order to solve this, move the call to arm64_apply_bp_hardening() into check_and_switch_context(), where we're guaranteed to pick a different mm context.
--- arch/arm64/mm/context.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/context.c +3 -2
@@ -227,6 +227,9 @@ void check_and_switch_context(struct mm_raw_spin_unlock_irqrestore (&cpu_asid_lock, flags); switch_mm_fastpath: + +arm64_apply_bp_hardening (); +/* * Defer TTBR0_EL1 setting for user threads to uaccess_enable() when * emulating PAN.
@@ -242,8 +245,6 @@ asmlinkage void post_ttbr_update_workaro"ic iallu; dsb nsh; isb" ,ARM64_WORKAROUND_CAVIUM_27456 , CONFIG_CAVIUM_ERRATUM_27456)); - -arm64_apply_bp_hardening (); }static int asids_init (void )
Greg Kroah-Hartman
maintainerPATCH 72/195 arm64: KVM: Use per-CPU vector when BP hardening is enabled
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 6840bdd73d07 upstream.
Now that we have per-CPU vectors, let's plug then in the KVM/arm64 code.
--- arch/arm/include/asm/kvm_mmu.h | 10 ++++++++++ arch/arm64/include/asm/kvm_mmu.h | 38 ++++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/switch.c | 2 +- virt/kvm/arm/arm.c | 8 +++++++- 4 files changed, 56 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_mmu.h +10 -0
@@ -221,6 +221,16 @@ static inline unsigned int kvm_get_vmid_return 8 ; } +static inline void *kvm_get_hyp_vector (void ) +{ +return kvm_ksym_ref (__kvm_hyp_vector); +} + +static inline int kvm_map_vectors (void ) +{ +return 0 ; +} +#endif /* !__ASSEMBLY__ */ #endif /* __ARM_KVM_MMU_H__ */
arch/arm64/include/asm/kvm_mmu.h +38 -0
@@ -309,5 +309,43 @@ static inline unsigned int kvm_get_vmid_return (cpuid_feature_extract_unsigned_field (reg,ID_AA64MMFR1_VMIDBITS_SHIFT ) ==2 ) ?16 :8 ; } +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +#include <asm/mmu.h> + +static inline void *kvm_get_hyp_vector (void ) +{ +struct bp_hardening_data *data =arm64_get_bp_hardening_data (); +void *vect =kvm_ksym_ref (__kvm_hyp_vector); + +if (data->fn) { + vect = __bp_harden_hyp_vecs_start + + data->hyp_vectors_slot *SZ_2K ; + +if (!has_vhe ()) + vect =lm_alias (vect); + } + +return vect; +} + +static inline int kvm_map_vectors (void ) +{ +return create_hyp_mappings (kvm_ksym_ref (__bp_harden_hyp_vecs_start), +kvm_ksym_ref (__bp_harden_hyp_vecs_end), +PAGE_HYP_EXEC ); +} + +#else +static inline void *kvm_get_hyp_vector (void ) +{ +return kvm_ksym_ref (__kvm_hyp_vector); +} + +static inline int kvm_map_vectors (void ) +{ +return 0 ; +} +#endif +#endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */
arch/arm64/kvm/hyp/switch.c +1 -1
@@ -51,7 +51,7 @@ static void __hyp_text __activate_traps_ val &= ~CPACR_EL1_FPEN ;write_sysreg (val, cpacr_el1); -write_sysreg (__kvm_hyp_vector, vbar_el1); +write_sysreg (kvm_get_hyp_vector (), vbar_el1); } static void __hyp_text __activate_traps_nvhe(void)
virt/kvm/arm/arm.c +7 -1
@@ -1139,7 +1139,7 @@ static void cpu_init_hyp_mode(void *dumm pgd_ptr =kvm_mmu_get_httbr (); stack_page =__this_cpu_read (kvm_arm_hyp_stack_page); hyp_stack_ptr = stack_page +PAGE_SIZE ; - vector_ptr = (unsigned long )kvm_ksym_ref (__kvm_hyp_vector); + vector_ptr = (unsigned long )kvm_get_hyp_vector ();__cpu_init_hyp_mode (pgd_ptr, hyp_stack_ptr, vector_ptr);__cpu_init_stage2 ();
@@ -1384,6 +1384,12 @@ static int init_hyp_mode(void) goto out_err; } + err =kvm_map_vectors (); +if (err) { +kvm_err ("Cannot map vectors\n" ); + goto out_err; + } +/* * Map the Hyp stack pages */
Greg Kroah-Hartman
maintainerPATCH 73/195 arm64: entry: Apply BP hardening for high-priority synchronous exceptions
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 5dfc6ed27710 upstream.
Software-step and PC alignment fault exceptions have higher priority than instruction abort exceptions, so apply the BP hardening hooks there too if the user PC appears to reside in kernel space.
--- arch/arm64/kernel/entry.S | 6 ++++-- arch/arm64/mm/fault.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-)
arch/arm64/kernel/entry.S +4 -2
@@ -759,8 +759,10 @@ el0_sp_pc: * Stack or PC alignment exception handling */ mrs x26, far_el1 - // enable interrupts before calling the main handler - enable_dbg_and_irq + enable_dbg +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif ct_user_exit mov x0, x26 mov x1, x25
arch/arm64/mm/fault.c +9 -0
@@ -778,6 +778,12 @@ asmlinkage void __exception do_sp_pc_abostruct siginfo info;struct task_struct *tsk = current; +if (user_mode (regs)) { +if (instruction_pointer (regs) >TASK_SIZE ) +arm64_apply_bp_hardening (); +local_irq_enable (); + } +if (show_unhandled_signals &&unhandled_signal (tsk,SIGBUS )) pr_info_ratelimited("%s[%d]: %s exception: pc=%p sp=%p\n", tsk->comm, task_pid_nr(tsk),
@@ -837,6 +843,9 @@ asmlinkage int __exception do_debug_exceif (interrupts_enabled (regs))trace_hardirqs_off (); +if (user_mode (regs) &&instruction_pointer (regs) >TASK_SIZE ) +arm64_apply_bp_hardening (); +if (!inf->fn (addr, esr, regs)) { rv =1 ; }else {
Greg Kroah-Hartman
maintainerPATCH 74/195 arm64: entry: Apply BP hardening for suspicious interrupts from EL0
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit 30d88c0e3ace upstream.
It is possible to take an IRQ from EL0 following a branch to a kernel address in such a way that the IRQ is prioritised over the instruction abort. Whilst an attacker would need to get the stars to align here, it might be sufficient with enough calibration so perform BP hardening in the rare case that we see a kernel address in the ELR when handling an IRQ from EL0.
--- arch/arm64/kernel/entry.S | 5 +++++ arch/arm64/mm/fault.c | 6 ++++++ 2 files changed, 11 insertions(+)
arch/arm64/kernel/entry.S +5 -0
@@ -821,6 +821,11 @@ el0_irq_naked: #endif ct_user_exit +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + tbz x22, #55, 1f + bl do_el0_irq_bp_hardening +1: +#endif irq_handler #ifdef CONFIG_TRACE_IRQFLAGS
arch/arm64/mm/fault.c +6 -0
@@ -751,6 +751,12 @@ asmlinkage void __exception do_mem_abortarm64_notify_die ("" , regs, &info, esr); } +asmlinkage void __exception do_el0_irq_bp_hardening(void) +{ +/* PC has already been checked in entry.S */ +arm64_apply_bp_hardening (); +} + asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr,unsigned int esr,struct pt_regs *regs)
Greg Kroah-Hartman
maintainerPATCH 75/195 arm64: cputype: Add missing MIDR values for Cortex-A72 and Cortex-A75
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit a65d219fe5dc upstream.
Hook up MIDR values for the Cortex-A72 and Cortex-A75 CPUs, since they will soon need MIDR matches for hardening the branch predictor.
--- arch/arm64/include/asm/cputype.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/include/asm/cputype.h +4 -0
@@ -79,8 +79,10 @@#define ARM_CPU_PART_AEM_V8 0xD0F#define ARM_CPU_PART_FOUNDATION 0xD00#define ARM_CPU_PART_CORTEX_A57 0xD07 +#define ARM_CPU_PART_CORTEX_A72 0xD08#define ARM_CPU_PART_CORTEX_A53 0xD03#define ARM_CPU_PART_CORTEX_A73 0xD09 +#define ARM_CPU_PART_CORTEX_A75 0xD0A#define APM_CPU_PART_POTENZA 0x000
@@ -97,7 +99,9 @@#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57) +#define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)#define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73) +#define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)
Greg Kroah-Hartman
maintainerPATCH 76/195 arm64: Implement branch predictor hardening for affected Cortex-A CPUs
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
Commit aa6acde65e03 upstream.
Cortex-A57, A72, A73 and A75 are susceptible to branch predictor aliasing and can theoretically be attacked by malicious code.
This patch implements a PSCI-based mitigation for these CPUs when available. The call into firmware will invalidate the branch predictor state, preventing any malicious entries from affecting other victim contexts.
--- arch/arm64/kernel/bpi.S | 24 +++++++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
arch/arm64/kernel/bpi.S +24 -0
@@ -53,3 +53,27 @@ ENTRY(__bp_harden_hyp_vecs_start) vectors __kvm_hyp_vector .endr ENTRY(__bp_harden_hyp_vecs_end) +ENTRY(__psci_hyp_bp_inval_start) + sub sp, sp, #(8 * 18) + stp x16, x17, [sp, #(16 * 0)] + stp x14, x15, [sp, #(16 * 1)] + stp x12, x13, [sp, #(16 * 2)] + stp x10, x11, [sp, #(16 * 3)] + stp x8, x9, [sp, #(16 * 4)] + stp x6, x7, [sp, #(16 * 5)] + stp x4, x5, [sp, #(16 * 6)] + stp x2, x3, [sp, #(16 * 7)] + stp x0, x1, [sp, #(16 * 8)] + mov x0, #0x84000000 + smc #0 + ldp x16, x17, [sp, #(16 * 0)] + ldp x14, x15, [sp, #(16 * 1)] + ldp x12, x13, [sp, #(16 * 2)] + ldp x10, x11, [sp, #(16 * 3)] + ldp x8, x9, [sp, #(16 * 4)] + ldp x6, x7, [sp, #(16 * 5)] + ldp x4, x5, [sp, #(16 * 6)] + ldp x2, x3, [sp, #(16 * 7)] + ldp x0, x1, [sp, #(16 * 8)] + add sp, sp, #(8 * 18) +ENTRY(__psci_hyp_bp_inval_end)
arch/arm64/kernel/cpu_errata.c +42 -0
66 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 77/195 arm64: Implement branch predictor hardening for Falkor
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shanker Donthineni <[email protected]>
Commit ec82b567a74f upstream.
Falkor is susceptible to branch predictor aliasing and can theoretically be attacked by malicious code. This patch implements a mitigation for these attacks, preventing any malicious entries from affecting other victim contexts.
--- arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/kvm_asm.h | 2 + arch/arm64/kernel/bpi.S | 8 +++++++ arch/arm64/kernel/cpu_errata.c | 40 +++++++++++++++++++++++++++++++++++++-- arch/arm64/kvm/hyp/entry.S | 12 +++++++++++ arch/arm64/kvm/hyp/switch.c | 8 +++++++ 6 files changed, 70 insertions(+), 3 deletions(-)
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -42,7 +42,8 @@#define ARM64_HAS_DCPOP 21#define ARM64_UNMAP_KERNEL_AT_EL0 23#define ARM64_HARDEN_BRANCH_PREDICTOR 24 +#define ARM64_HARDEN_BP_POST_GUEST_EXIT 25 -#define ARM64_NCAPS 25 +#define ARM64_NCAPS 26#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/kvm_asm.h +2 -0
@@ -66,6 +66,8 @@ extern u32 __kvm_get_mdcr_el2(void);extern u32 __init_stage2_translation (void ); +extern void __qcom_hyp_sanitize_btac_predictors (void ); +#endif #endif /* __ARM_KVM_ASM_H__ */
arch/arm64/kernel/bpi.S +8 -0
@@ -77,3 +77,11 @@ ENTRY(__psci_hyp_bp_inval_start) ldp x0, x1, [sp, #(16 * 8)] add sp, sp, #(8 * 18) ENTRY(__psci_hyp_bp_inval_end) + +ENTRY(__qcom_hyp_sanitize_link_stack_start) + stp x29, x30, [sp, #-16]! + .rept 16 + bl . + 4 + .endr + ldp x29, x30, [sp], #16 +ENTRY(__qcom_hyp_sanitize_link_stack_end)
arch/arm64/kernel/cpu_errata.c +38 -2
@@ -68,6 +68,8 @@ DEFINE_PER_CPU_READ_MOSTLY(struct bp_har#ifdef CONFIG_KVM extern char __psci_hyp_bp_inval_start[], __psci_hyp_bp_inval_end[]; +extern char __qcom_hyp_sanitize_link_stack_start[]; +extern char __qcom_hyp_sanitize_link_stack_end[];static void __copy_hyp_vect_bpi (int slot,const char *hyp_vecs_start,const char *hyp_vecs_end)
@@ -110,8 +112,10 @@ static void __install_bp_hardening_cb(bpspin_unlock (&bp_lock); }#else -#define __psci_hyp_bp_inval_start NULL -#define __psci_hyp_bp_inval_end NULL +#define __psci_hyp_bp_inval_start NULL +#define __psci_hyp_bp_inval_end NULL +#define __qcom_hyp_sanitize_link_stack_start NULL +#define __qcom_hyp_sanitize_link_stack_end NULL static void __install_bp_hardening_cb(bp_hardening_cb_t fn, const char *hyp_vecs_start,
@@ -152,6 +156,29 @@ static int enable_psci_bp_hardening(void return 0; } + +static void qcom_link_stack_sanitization (void ) +{ +u64 tmp; + + asmvolatile ("mov %0, x30 \n" +".rept 16 \n" +"bl . + 4 \n" +".endr \n" +"mov x30, %0 \n" + :"=&r" (tmp)); +} + +static int qcom_enable_link_stack_sanitization (void *data) +{ +const struct arm64_cpu_capabilities *entry = data; + +install_bp_hardening_cb (entry, qcom_link_stack_sanitization, + __qcom_hyp_sanitize_link_stack_start, + __qcom_hyp_sanitize_link_stack_end); + +return 0 ; +}#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ #define MIDR_RANGE (model, min, max) \
@@ -323,6 +350,15 @@ const struct arm64_cpu_capabilities arm6 MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), .enable = enable_psci_bp_hardening, }, + { + .capability =ARM64_HARDEN_BRANCH_PREDICTOR , +MIDR_ALL_VERSIONS (MIDR_QCOM_FALKOR_V1 ), + .enable = qcom_enable_link_stack_sanitization, + }, + { + .capability =ARM64_HARDEN_BP_POST_GUEST_EXIT , + MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR_V1), + }, #endif { }
arch/arm64/kvm/hyp/entry.S +12 -0
@@ -196,3 +196,15 @@ alternative_endif eret ENDPROC(__fpsimd_guest_restore) + +ENTRY(__qcom_hyp_sanitize_btac_predictors) + /** + * Call SMC64 with Silicon provider serviceID 23<<8 (0xc2001700) + * 0xC2000000-0xC200FFFF: assigned to SiP Service Calls + * b15-b0: contains SiP functionID + */ + movz x0, #0x1700 + movk x0, #0xc200, lsl #16 + smc #0 + ret +ENDPROC(__qcom_hyp_sanitize_btac_predictors)
arch/arm64/kvm/hyp/switch.c +8 -0
@@ -364,6 +364,14 @@ again:/* 0 falls through to be handled out of EL2 */ } +if (cpus_have_const_cap (ARM64_HARDEN_BP_POST_GUEST_EXIT )) { +u32 midr =read_cpuid_id (); + +/* Apply BTAC predictors mitigation to all Falkor chips */ +if ((midr &MIDR_CPU_MODEL_MASK ) ==MIDR_QCOM_FALKOR_V1 ) +__qcom_hyp_sanitize_btac_predictors (); + } + fp_enabled =__fpsimd_enabled ();__sysreg_save_guest_state (guest_ctxt);
Greg Kroah-Hartman
maintainerPATCH 78/195 arm64: Branch predictor hardening for Cavium ThunderX2
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jayachandran C <[email protected]>
Commit f3d795d9b360 upstream.
Use PSCI based mitigation for speculative execution attacks targeting the branch predictor. We use the same mechanism as the one used for Cortex-A CPUs, we expect the PSCI version call to have a side effect of clearing the BTBs.
--- arch/arm64/kernel/cpu_errata.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/kernel/cpu_errata.c +10 -0
@@ -359,6 +359,16 @@ const struct arm64_cpu_capabilities arm6 .capability = ARM64_HARDEN_BP_POST_GUEST_EXIT, MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR_V1), }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), + .enable = enable_psci_bp_hardening, + }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), + .enable = enable_psci_bp_hardening, + }, #endif { }
Greg Kroah-Hartman
maintainerPATCH 80/195 arm/arm64: KVM: Consolidate the PSCI include files
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 1a2fb94e6a77 upstream.
As we're about to update the PSCI support, and because I'm lazy, let's move the PSCI include file to include/kvm so that both ARM architectures can find it.
--- arch/arm/include/asm/kvm_psci.h | 27 --------------------------- arch/arm/kvm/handle_exit.c | 2 +- arch/arm64/include/asm/kvm_psci.h | 27 --------------------------- arch/arm64/kvm/handle_exit.c | 3 ++- include/kvm/arm_psci.h | 27 +++++++++++++++++++++++++++ virt/kvm/arm/arm.c | 2 +- virt/kvm/arm/psci.c | 3 ++- 7 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 arch/arm/include/asm/kvm_psci.h rename arch/arm64/include/asm/kvm_psci.h => include/kvm/arm_psci.h (89%)
arch/arm/include/asm/kvm_psci.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* Copyright (C) 2012 - ARM Ltd -* Author: Marc Zyngier <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ARM_KVM_PSCI_H__ -#define __ARM_KVM_PSCI_H__ - -#define KVM_ARM_PSCI_0_1 1 -#define KVM_ARM_PSCI_0_2 2 - -int kvm_psci_version (struct kvm_vcpu *vcpu); -int kvm_psci_call (struct kvm_vcpu *vcpu); - -#endif /* __ARM_KVM_PSCI_H__ */
arch/arm/kvm/handle_exit.c +1 -1
@@ -21,7 +21,7 @@#include <asm/kvm_emulate.h> #include <asm/kvm_coproc.h> #include <asm/kvm_mmu.h> -#include <asm/kvm_psci.h> +#include <kvm/arm_psci.h> #include <trace/events/kvm.h> #include "trace.h"
arch/arm64/include/asm/kvm_psci.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* Copyright (C) 2012,2013 - ARM Ltd -* Author: Marc Zyngier <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ARM64_KVM_PSCI_H__ -#define __ARM64_KVM_PSCI_H__ - -#define KVM_ARM_PSCI_0_1 1 -#define KVM_ARM_PSCI_0_2 2 - -int kvm_psci_version (struct kvm_vcpu *vcpu); -int kvm_psci_call (struct kvm_vcpu *vcpu); - -#endif /* __ARM64_KVM_PSCI_H__ */
arch/arm64/kvm/handle_exit.c +2 -1
@@ -22,12 +22,13 @@#include <linux/kvm.h> #include <linux/kvm_host.h> +#include <kvm/arm_psci.h> +#include <asm/esr.h> #include <asm/kvm_asm.h> #include <asm/kvm_coproc.h> #include <asm/kvm_emulate.h> #include <asm/kvm_mmu.h> -#include <asm/kvm_psci.h> #define CREATE_TRACE_POINTS #include "trace.h"
include/kvm/arm_psci.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2012,2013 - ARM Ltd +* Author: Marc Zyngier <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __KVM_ARM_PSCI_H__ +#define __KVM_ARM_PSCI_H__ + +#define KVM_ARM_PSCI_0_1 1 +#define KVM_ARM_PSCI_0_2 2 + +int kvm_psci_version (struct kvm_vcpu *vcpu); +int kvm_psci_call (struct kvm_vcpu *vcpu); + +#endif /* __KVM_ARM_PSCI_H__ */
virt/kvm/arm/arm.c +1 -1
@@ -29,6 +29,7 @@#include <linux/kvm.h> #include <trace/events/kvm.h> #include <kvm/arm_pmu.h> +#include <kvm/arm_psci.h> #define CREATE_TRACE_POINTS #include "trace.h"
@@ -44,7 +45,6 @@#include <asm/kvm_mmu.h> #include <asm/kvm_emulate.h> #include <asm/kvm_coproc.h> -#include <asm/kvm_psci.h> #include <asm/sections.h> #ifdef REQUIRES_VIRT
virt/kvm/arm/psci.c +2 -1
@@ -21,9 +21,10 @@#include <asm/cputype.h> #include <asm/kvm_emulate.h> -#include <asm/kvm_psci.h> #include <asm/kvm_host.h> +#include <kvm/arm_psci.h> +#include <uapi/linux/psci.h> /*
Greg Kroah-Hartman
maintainerPATCH 81/195 arm/arm64: KVM: Add PSCI_VERSION helper
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit d0a144f12a7c upstream.
As we're about to trigger a PSCI version explosion, it doesn't hurt to introduce a PSCI_VERSION helper that is going to be used everywhere.
--- include/kvm/arm_psci.h | 6 ++++-- include/uapi/linux/psci.h | 3 +++ virt/kvm/arm/psci.c | 4 +--- 3 files changed, 8 insertions(+), 5 deletions(-)
include/kvm/arm_psci.h +4 -2
@@ -18,8 +18,10 @@#ifndef __KVM_ARM_PSCI_H__#define __KVM_ARM_PSCI_H__ -#define KVM_ARM_PSCI_0_1 1 -#define KVM_ARM_PSCI_0_2 2 +#include <uapi/linux/psci.h> + +#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1) +#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2)int kvm_psci_version (struct kvm_vcpu *vcpu);int kvm_psci_call (struct kvm_vcpu *vcpu);
include/uapi/linux/psci.h +3 -0
@@ -88,6 +88,9 @@ (((ver) & PSCI_VERSION_MAJOR_MASK) >> PSCI_VERSION_MAJOR_SHIFT)#define PSCI_VERSION_MINOR (ver) \ ((ver) & PSCI_VERSION_MINOR_MASK) +#define PSCI_VERSION (maj, min) \ + ((((maj) << PSCI_VERSION_MAJOR_SHIFT) & PSCI_VERSION_MAJOR_MASK) | \ + ((min) & PSCI_VERSION_MINOR_MASK))/* PSCI features decoding (>=1.0) */ #define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT 1
virt/kvm/arm/psci.c +1 -3
@@ -25,8 +25,6 @@#include <kvm/arm_psci.h> -#include <uapi/linux/psci.h> -/* * This is an implementation of the Power State Coordination Interface * as described in ARM document number ARM DEN 0022A.
@@ -222,7 +220,7 @@ static int kvm_psci_0_2_call(struct kvm_* Bits[31:16] = Major Version = 0 * Bits[15:0] = Minor Version = 2 */ - val =2 ; + val =KVM_ARM_PSCI_0_2 ;break ;case PSCI_0_2_FN_CPU_SUSPEND :case PSCI_0_2_FN64_CPU_SUSPEND :
Greg Kroah-Hartman
maintainerPATCH 82/195 arm/arm64: KVM: Add smccc accessors to PSCI code
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 84684fecd7ea upstream.
Instead of open coding the accesses to the various registers, let's add explicit SMCCC accessors.
--- virt/kvm/arm/psci.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-)
virt/kvm/arm/psci.c +42 -10
@@ -32,6 +32,38 @@#define AFFINITY_MASK (level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1) +static u32 smccc_get_function (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,0 ); +} + +static unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,1 ); +} + +static unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,2 ); +} + +static unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,3 ); +} + +static void smccc_set_retval (struct kvm_vcpu *vcpu, +unsigned long a0, +unsigned long a1, +unsigned long a2, +unsigned long a3) +{ +vcpu_set_reg (vcpu,0 , a0); +vcpu_set_reg (vcpu,1 , a1); +vcpu_set_reg (vcpu,2 , a2); +vcpu_set_reg (vcpu,3 , a3); +} +static unsigned long psci_affinity_mask (unsigned long affinity_level) {if (affinity_level <=3 )
@@ -77,7 +109,7 @@ static unsigned long kvm_psci_vcpu_on(stunsigned long context_id;phys_addr_t target_pc; - cpu_id =vcpu_get_reg (source_vcpu,1 ) &MPIDR_HWID_BITMASK ; + cpu_id =smccc_get_arg1 (source_vcpu) &MPIDR_HWID_BITMASK ;if (vcpu_mode_is_32bit (source_vcpu)) cpu_id &= ~((u32 )0 );
@@ -96,8 +128,8 @@ static unsigned long kvm_psci_vcpu_on(streturn PSCI_RET_INVALID_PARAMS ; } - target_pc =vcpu_get_reg (source_vcpu,2 ); - context_id =vcpu_get_reg (source_vcpu,3 ); + target_pc =smccc_get_arg2 (source_vcpu); + context_id =smccc_get_arg3 (source_vcpu);kvm_reset_vcpu (vcpu);
@@ -116,7 +148,7 @@ static unsigned long kvm_psci_vcpu_on(st* NOTE: We always update r0 (or x0) because for PSCI v0.1 * the general puspose registers are undefined upon CPU_ON. */ -vcpu_set_reg (vcpu,0 , context_id); +smccc_set_retval (vcpu, context_id,0 ,0 ,0 ); vcpu->arch.power_off = false;smp_mb ();/* Make sure the above is visible */
@@ -136,8 +168,8 @@ static unsigned long kvm_psci_vcpu_affinstruct kvm *kvm = vcpu->kvm;struct kvm_vcpu *tmp; - target_affinity =vcpu_get_reg (vcpu,1 ); - lowest_affinity_level =vcpu_get_reg (vcpu,2 ); + target_affinity =smccc_get_arg1 (vcpu); + lowest_affinity_level =smccc_get_arg2 (vcpu);/* Determine target affinity mask */ target_affinity_mask =psci_affinity_mask (lowest_affinity_level);
@@ -210,7 +242,7 @@ int kvm_psci_version(struct kvm_vcpu *vcstatic int kvm_psci_0_2_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -unsigned long psci_fn =vcpu_get_reg (vcpu,0 ) & ~((u32 )0 ); +u32 psci_fn =smccc_get_function (vcpu);unsigned long val;int ret =1 ;
@@ -277,14 +309,14 @@ static int kvm_psci_0_2_call(struct kvm_break ; } -vcpu_set_reg (vcpu,0 , val); +smccc_set_retval (vcpu, val,0 ,0 ,0 );return ret; }static int kvm_psci_0_1_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -unsigned long psci_fn =vcpu_get_reg (vcpu,0 ) & ~((u32 )0 ); +u32 psci_fn =smccc_get_function (vcpu);unsigned long val;switch (psci_fn) {
@@ -302,7 +334,7 @@ static int kvm_psci_0_1_call(struct kvm_break ; } -vcpu_set_reg (vcpu,0 , val); +smccc_set_retval (vcpu, val,0 ,0 ,0 );return 1 ; }
Greg Kroah-Hartman
maintainerPATCH 83/195 arm/arm64: KVM: Implement PSCI 1.0 support
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 58e0b2239a4d upstream.
PSCI 1.0 can be trivially implemented by providing the FEATURES call on top of PSCI 0.2 and returning 1.0 as the PSCI version.
We happily ignore everything else, as they are either optional or are clarifications that do not require any additional change.
PSCI 1.0 is now the default until we decide to add a userspace selection API.
--- include/kvm/arm_psci.h | 3 +++ virt/kvm/arm/psci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-)
include/kvm/arm_psci.h +3 -0
@@ -22,6 +22,9 @@#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2) +#define KVM_ARM_PSCI_1_0 PSCI_VERSION(1, 0) + +#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0int kvm_psci_version (struct kvm_vcpu *vcpu);int kvm_psci_call (struct kvm_vcpu *vcpu);
virt/kvm/arm/psci.c +44 -1
63 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 84/195 arm/arm64: KVM: Advertise SMCCC v1.1
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 09e6be12effd upstream.
The new SMC Calling Convention (v1.1) allows for a reduced overhead when calling into the firmware, and provides a new feature discovery mechanism.
Make it visible to KVM guests.
--- arch/arm/kvm/handle_exit.c | 2 +- arch/arm64/kvm/handle_exit.c | 2 +- include/kvm/arm_psci.h | 2 +- include/linux/arm-smccc.h | 13 +++++++++++++ virt/kvm/arm/psci.c | 24 +++++++++++++++++++++++- 5 files changed, 39 insertions(+), 4 deletions(-)
arch/arm/kvm/handle_exit.c +1 -1
@@ -36,7 +36,7 @@ static int handle_hvc(struct kvm_vcpu *v kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; - ret =kvm_psci_call (vcpu); + ret =kvm_hvc_call_handler (vcpu);if (ret <0 ) {kvm_inject_undefined (vcpu);return 1 ;
arch/arm64/kvm/handle_exit.c +1 -1
@@ -43,7 +43,7 @@ static int handle_hvc(struct kvm_vcpu *v kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; - ret =kvm_psci_call (vcpu); + ret =kvm_hvc_call_handler (vcpu);if (ret <0 ) {vcpu_set_reg (vcpu,0 , ~0UL );return 1 ;
include/kvm/arm_psci.h +1 -1
@@ -27,6 +27,6 @@#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0int kvm_psci_version (struct kvm_vcpu *vcpu); -int kvm_psci_call (struct kvm_vcpu *vcpu); +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu);#endif /* __KVM_ARM_PSCI_H__ */
include/linux/arm-smccc.h +13 -0
@@ -60,6 +60,19 @@#define ARM_SMCCC_QUIRK_NONE 0#define ARM_SMCCC_QUIRK_QCOM_A6 1/* Save/restore register a6 */ +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 + +#define ARM_SMCCC_VERSION_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0) + +#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 1) +#ifndef __ASSEMBLY__#include <linux/linkage.h>
virt/kvm/arm/psci.c +23 -1
@@ -15,6 +15,7 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <linux/arm-smccc.h> #include <linux/preempt.h> #include <linux/kvm_host.h> #include <linux/wait.h>
@@ -339,6 +340,7 @@ static int kvm_psci_1_0_call(struct kvm_case PSCI_0_2_FN_SYSTEM_OFF :case PSCI_0_2_FN_SYSTEM_RESET :case PSCI_1_0_FN_PSCI_FEATURES : +case ARM_SMCCC_VERSION_FUNC_ID : val =0 ;break ;default :
@@ -393,7 +395,7 @@ static int kvm_psci_0_1_call(struct kvm_* Errors: * -EINVAL: Unrecognized PSCI function */ -int kvm_psci_call (struct kvm_vcpu *vcpu) +static int kvm_psci_call (struct kvm_vcpu *vcpu) {switch (kvm_psci_version (vcpu)) {case KVM_ARM_PSCI_1_0 :
@@ -406,3 +408,23 @@ int kvm_psci_call(struct kvm_vcpu *vcpu)return -EINVAL ; }; } + +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu) +{ +u32 func_id =smccc_get_function (vcpu); +u32 val =PSCI_RET_NOT_SUPPORTED ; + +switch (func_id) { +case ARM_SMCCC_VERSION_FUNC_ID : + val =ARM_SMCCC_VERSION_1_1 ; +break ; +case ARM_SMCCC_ARCH_FEATURES_FUNC_ID : +/* Nothing supported yet */ +break ; +default : +return kvm_psci_call (vcpu); + } + +smccc_set_retval (vcpu, val,0 ,0 ,0 ); +return 1 ; +}
Greg Kroah-Hartman
maintainerPATCH 85/195 arm64: KVM: Make PSCI_VERSION a fast path
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 90348689d500 upstream.
For those CPUs that require PSCI to perform a BP invalidation, going all the way to the PSCI code for not much is a waste of precious cycles. Let's terminate that call as early as possible.
--- arch/arm64/kvm/hyp/switch.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/kvm/hyp/switch.c +13 -0
@@ -17,6 +17,7 @@#include <linux/types.h> #include <linux/jump_label.h> +#include <uapi/linux/psci.h> #include <asm/kvm_asm.h> #include <asm/kvm_emulate.h>
@@ -322,6 +323,18 @@ again:if (exit_code ==ARM_EXCEPTION_TRAP && !__populate_fault_info (vcpu)) goto again; +if (exit_code ==ARM_EXCEPTION_TRAP && + (kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC64 || +kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC32) && +vcpu_get_reg (vcpu,0 ) ==PSCI_0_2_FN_PSCI_VERSION ) { +u64 val =PSCI_RET_NOT_SUPPORTED ; +if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) + val =2 ; + +vcpu_set_reg (vcpu,0 , val); + goto again; + } +if (static_branch_unlikely (&vgic_v2_cpuif_trap) && exit_code ==ARM_EXCEPTION_TRAP ) {bool valid;
Greg Kroah-Hartman
maintainerPATCH 86/195 arm/arm64: KVM: Turn kvm_psci_version into a static inline
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit a4097b351118 upstream.
We're about to need kvm_psci_version in HYP too. So let's turn it into a static inline, and pass the kvm structure as a second parameter (so that HYP can do a kern_hyp_va on it).
--- arch/arm64/kvm/hyp/switch.c | 18 +++++++++++------- include/kvm/arm_psci.h | 21 ++++++++++++++++++++- virt/kvm/arm/psci.c | 12 ++---------- 3 files changed, 33 insertions(+), 18 deletions(-)
arch/arm64/kvm/hyp/switch.c +11 -7
@@ -19,6 +19,8 @@#include <linux/jump_label.h> #include <uapi/linux/psci.h> +#include <kvm/arm_psci.h> +#include <asm/kvm_asm.h> #include <asm/kvm_emulate.h> #include <asm/kvm_hyp.h>
@@ -325,14 +327,16 @@ again:if (exit_code ==ARM_EXCEPTION_TRAP && (kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC64 || -kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC32) && -vcpu_get_reg (vcpu,0 ) ==PSCI_0_2_FN_PSCI_VERSION ) { -u64 val =PSCI_RET_NOT_SUPPORTED ; -if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) - val =2 ; +kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC32)) { +u32 val =vcpu_get_reg (vcpu,0 ); -vcpu_set_reg (vcpu,0 , val); - goto again; +if (val ==PSCI_0_2_FN_PSCI_VERSION ) { + val =kvm_psci_version (vcpu,kern_hyp_va (vcpu->kvm)); +if (unlikely (val ==KVM_ARM_PSCI_0_1 )) + val =PSCI_RET_NOT_SUPPORTED ; +vcpu_set_reg (vcpu,0 , val); + goto again; + } } if (static_branch_unlikely(&vgic_v2_cpuif_trap) &&
include/kvm/arm_psci.h +20 -1
@@ -18,6 +18,7 @@#ifndef __KVM_ARM_PSCI_H__#define __KVM_ARM_PSCI_H__ +#include <linux/kvm_host.h> #include <uapi/linux/psci.h> #define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)
@@ -26,7 +27,25 @@#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0 -int kvm_psci_version (struct kvm_vcpu *vcpu); +/* +* We need the KVM pointer independently from the vcpu as we can call +* this from HYP, and need to apply kern_hyp_va on it... +*/ +static inline int kvm_psci_version (struct kvm_vcpu *vcpu,struct kvm *kvm) +{ +/* +* Our PSCI implementation stays the same across versions from +* v0.2 onward, only adding the few mandatory functions (such +* as FEATURES with 1.0) that are required by newer +* revisions. It is thus safe to return the latest. +*/ +if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) +return KVM_ARM_PSCI_LATEST ; + +return KVM_ARM_PSCI_0_1 ; +} + +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu);#endif /* __KVM_ARM_PSCI_H__ */
virt/kvm/arm/psci.c +2 -10
@@ -123,7 +123,7 @@ static unsigned long kvm_psci_vcpu_on(stif (!vcpu)return PSCI_RET_INVALID_PARAMS ;if (!vcpu->arch.power_off) { -if (kvm_psci_version (source_vcpu) !=KVM_ARM_PSCI_0_1 ) +if (kvm_psci_version (source_vcpu, kvm) !=KVM_ARM_PSCI_0_1 )return PSCI_RET_ALREADY_ON ;else return PSCI_RET_INVALID_PARAMS ;
@@ -232,14 +232,6 @@ static void kvm_psci_system_reset(structkvm_prepare_system_event (vcpu,KVM_SYSTEM_EVENT_RESET ); } -int kvm_psci_version (struct kvm_vcpu *vcpu) -{ -if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) -return KVM_ARM_PSCI_LATEST ; - -return KVM_ARM_PSCI_0_1 ; -} -static int kvm_psci_0_2_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
@@ -397,7 +389,7 @@ static int kvm_psci_0_1_call(struct kvm_*/ static int kvm_psci_call (struct kvm_vcpu *vcpu) { -switch (kvm_psci_version (vcpu)) { +switch (kvm_psci_version (vcpu, vcpu->kvm)) {case KVM_ARM_PSCI_1_0 :return kvm_psci_1_0_call (vcpu);case KVM_ARM_PSCI_0_2 :
Greg Kroah-Hartman
maintainerPATCH 87/195 arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 6167ec5c9145 upstream.
A new feature of SMCCC 1.1 is that it offers firmware-based CPU workarounds. In particular, SMCCC_ARCH_WORKAROUND_1 provides BP hardening for CVE-2017-5715.
If the host has some mitigation for this issue, report that we deal with it using SMCCC_ARCH_WORKAROUND_1, as we apply the host workaround on every guest exit.
--- arch/arm/include/asm/kvm_host.h | 6 ++++++ arch/arm64/include/asm/kvm_host.h | 5 +++++ include/linux/arm-smccc.h | 5 +++++ virt/kvm/arm/psci.c | 9 ++++++++- 4 files changed, 24 insertions(+), 1 deletion(-)
arch/arm/include/asm/kvm_host.h +6 -0
@@ -293,4 +293,10 @@ int kvm_arm_vcpu_arch_get_attr(struct kvint kvm_arm_vcpu_arch_has_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr); +static inline bool kvm_arm_harden_branch_predictor (void ) +{ +/* No way to detect it yet, pretend it is not there. */ +return false; +} +#endif /* __ARM_KVM_HOST_H__ */
arch/arm64/include/asm/kvm_host.h +5 -0
@@ -384,4 +384,9 @@ static inline void __cpu_init_stage2(voi "PARange is %d bits, unsupported configuration!", parange); } +static inline bool kvm_arm_harden_branch_predictor (void ) +{ +return cpus_have_const_cap (ARM64_HARDEN_BRANCH_PREDICTOR ); +} +#endif /* __ARM64_KVM_HOST_H__ */
include/linux/arm-smccc.h +5 -0
@@ -73,6 +73,11 @@ ARM_SMCCC_SMC_32, \ 0, 1) +#define ARM_SMCCC_ARCH_WORKAROUND_1 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x8000) +#ifndef __ASSEMBLY__#include <linux/linkage.h>
virt/kvm/arm/psci.c +8 -1
@@ -405,13 +405,20 @@ int kvm_hvc_call_handler(struct kvm_vcpu {u32 func_id =smccc_get_function (vcpu);u32 val =PSCI_RET_NOT_SUPPORTED ; +u32 feature;switch (func_id) {case ARM_SMCCC_VERSION_FUNC_ID : val =ARM_SMCCC_VERSION_1_1 ;break ;case ARM_SMCCC_ARCH_FEATURES_FUNC_ID : -/* Nothing supported yet */ + feature =smccc_get_arg1 (vcpu); +switch (feature) { +case ARM_SMCCC_ARCH_WORKAROUND_1 : +if (kvm_arm_harden_branch_predictor ()) + val =0 ; +break ; + }break ;default :return kvm_psci_call (vcpu);
Greg Kroah-Hartman
maintainerPATCH 88/195 arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit f72af90c3783 upstream.
We want SMCCC_ARCH_WORKAROUND_1 to be fast. As fast as possible. So let's intercept it as early as we can by testing for the function call number as soon as we've identified a HVC call coming from the guest.
--- arch/arm64/kvm/hyp/hyp-entry.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/hyp-entry.S +18 -2
@@ -15,6 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <linux/arm-smccc.h> #include <linux/linkage.h> #include <asm/alternative.h>
@@ -64,10 +65,11 @@ alternative_endif lsr x0, x1, #ESR_ELx_EC_SHIFT cmp x0, #ESR_ELx_EC_HVC64 + ccmp x0, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap - mrs x1, vttbr_el2 // If vttbr is valid, the 64bit guest - cbnz x1, el1_trap // called HVC + mrs x1, vttbr_el2 // If vttbr is valid, the guest + cbnz x1, el1_hvc_guest // called HVC /* Here, we're pretty sure the host called HVC. */ ldp x0, x1, [sp], #16
@@ -100,6 +102,20 @@ alternative_endif eret +el1_hvc_guest: + /* + * Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1. + * The workaround has already been applied on the host, + * so let's quickly get back to the guest. We don't bother + * restoring x1, as it can be clobbered anyway. + */ + ldr x1, [sp] // Guest's x0 + eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1 + cbnz w1, el1_trap + mov x0, x1 + add sp, sp, #16 + eret + el1_trap: /* * x0: ESR_EC
Greg Kroah-Hartman
maintainerPATCH 89/195 firmware/psci: Expose PSCI conduit
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 09a8d6d48499 upstream.
In order to call into the firmware to apply workarounds, it is useful to find out whether we're using HVC or SMC. Let's expose this through the psci_ops.
--- drivers/firmware/psci.c | 28 +++++++++++++++++++++++----- include/linux/psci.h | 7 +++++++ 2 files changed, 30 insertions(+), 5 deletions(-)
drivers/firmware/psci.c +23 -5
@@ -59,7 +59,9 @@ bool psci_tos_resident_on(int cpu)return cpu == resident_cpu; } -struct psci_operations psci_ops; +struct psci_operations psci_ops = { + .conduit =PSCI_CONDUIT_NONE , +};typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long );
@@ -210,6 +212,22 @@ static unsigned long psci_migrate_info_u 0, 0, 0); } +static void set_conduit (enum psci_conduit conduit) +{ +switch (conduit) { +case PSCI_CONDUIT_HVC : + invoke_psci_fn = __invoke_psci_fn_hvc; +break ; +case PSCI_CONDUIT_SMC : + invoke_psci_fn = __invoke_psci_fn_smc; +break ; +default : +WARN (1 ,"Unexpected PSCI conduit %d\n" , conduit); + } + + psci_ops.conduit = conduit; +} +static int get_set_conduit_method (struct device_node *np) {const char *method;
@@ -222,9 +240,9 @@ static int get_set_conduit_method(struct }if (!strcmp ("hvc" , method)) { - invoke_psci_fn = __invoke_psci_fn_hvc; +set_conduit (PSCI_CONDUIT_HVC ); }else if (!strcmp ("smc" , method)) { - invoke_psci_fn = __invoke_psci_fn_smc; +set_conduit (PSCI_CONDUIT_SMC ); }else {pr_warn ("invalid \"method\" property: %s\n" , method);return -EINVAL ;
@@ -654,9 +672,9 @@ int __init psci_acpi_init(void)pr_info ("probing for conduit method from ACPI.\n" );if (acpi_psci_use_hvc ()) - invoke_psci_fn = __invoke_psci_fn_hvc; +set_conduit (PSCI_CONDUIT_HVC );else - invoke_psci_fn = __invoke_psci_fn_smc; +set_conduit (PSCI_CONDUIT_SMC );return psci_probe (); }
include/linux/psci.h +7 -0
@@ -25,6 +25,12 @@ bool psci_tos_resident_on(int cpu);int psci_cpu_init_idle (unsigned int cpu);int psci_cpu_suspend_enter (unsigned long index); +enum psci_conduit { +PSCI_CONDUIT_NONE , +PSCI_CONDUIT_SMC , +PSCI_CONDUIT_HVC , +}; +struct psci_operations {u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);
@@ -34,6 +40,7 @@ struct psci_operations {int (*affinity_info)(unsigned long target_affinity,unsigned long lowest_affinity_level);int (*migrate_info_type)(void ); +enum psci_conduit conduit; };extern struct psci_operations psci_ops;
Greg Kroah-Hartman
maintainerPATCH 90/195 firmware/psci: Expose SMCCC version through psci_ops
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit e78eef554a91 upstream.
Since PSCI 1.0 allows the SMCCC version to be (indirectly) probed, let's do that at boot time, and expose the version of the calling convention as part of the psci_ops structure.
--- drivers/firmware/psci.c | 27 +++++++++++++++++++++++++++ include/linux/psci.h | 6 ++++++ 2 files changed, 33 insertions(+)
drivers/firmware/psci.c +27 -0
@@ -61,6 +61,7 @@ bool psci_tos_resident_on(int cpu)struct psci_operations psci_ops = { .conduit =PSCI_CONDUIT_NONE , + .smccc_version =SMCCC_VERSION_1_0 , }; typedef unsigned long (psci_fn)(unsigned long, unsigned long,
@@ -511,6 +512,31 @@ static void __init psci_init_migrate(voipr_info ("Trusted OS resident on physical CPU 0x%lx\n" , cpuid); } +static void __init psci_init_smccc (void ) +{ +u32 ver =ARM_SMCCC_VERSION_1_0 ; +int feature; + + feature =psci_features (ARM_SMCCC_VERSION_FUNC_ID ); + +if (feature !=PSCI_RET_NOT_SUPPORTED ) { +u32 ret; + ret =invoke_psci_fn (ARM_SMCCC_VERSION_FUNC_ID ,0 ,0 ,0 ); +if (ret ==ARM_SMCCC_VERSION_1_1 ) { + psci_ops.smccc_version =SMCCC_VERSION_1_1 ; + ver = ret; + } + } + +/* +* Conveniently, the SMCCC and PSCI versions are encoded the +* same way. No, this isn't accidental. +*/ +pr_info ("SMC Calling Convention v%d.%d\n" , +PSCI_VERSION_MAJOR (ver),PSCI_VERSION_MINOR (ver)); + +} +static void __init psci_0_2_set_functions (void ) {pr_info ("Using standard PSCI v0.2 function IDs\n" );
@@ -559,6 +585,7 @@ static int __init psci_probe(void)psci_init_migrate ();if (PSCI_VERSION_MAJOR (ver) >=1 ) { +psci_init_smccc ();psci_init_cpu_suspend ();psci_init_system_suspend (); }
include/linux/psci.h +6 -0
@@ -31,6 +31,11 @@ enum psci_conduit { PSCI_CONDUIT_HVC, }; +enum smccc_version { +SMCCC_VERSION_1_0 , +SMCCC_VERSION_1_1 , +}; +struct psci_operations {u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);
@@ -41,6 +46,7 @@ struct psci_operations { unsigned long lowest_affinity_level);int (*migrate_info_type)(void );enum psci_conduit conduit; +enum smccc_version smccc_version; };extern struct psci_operations psci_ops;
Greg Kroah-Hartman
maintainerPATCH 91/195 arm/arm64: smccc: Make function identifiers an unsigned quantity
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit ded4c39e93f3 upstream.
Function identifiers are a 32bit, unsigned quantity. But we never tell so to the compiler, resulting in the following:
4ac: b26187e0 mov x0, #0xffffffff80000001
We thus rely on the firmware narrowing it for us, which is not always a reasonable expectation.
--- include/linux/arm-smccc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/arm-smccc.h +4 -2
@@ -14,14 +14,16 @@#ifndef __LINUX_ARM_SMCCC_H#define __LINUX_ARM_SMCCC_H +#include <uapi/linux/const.h> +/* * This file provides common defines for ARM SMC Calling Convention as * specified in * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html */ -#define ARM_SMCCC_STD_CALL 0 -#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_STD_CALL _AC(0,U) +#define ARM_SMCCC_FAST_CALL _AC(1,U)#define ARM_SMCCC_TYPE_SHIFT 31#define ARM_SMCCC_SMC_32 0
Greg Kroah-Hartman
maintainerPATCH 92/195 arm/arm64: smccc: Implement SMCCC v1.1 inline primitive
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit f2d3b2e8759a upstream.
One of the major improvement of SMCCC v1.1 is that it only clobbers the first 4 registers, both on 32 and 64bit. This means that it becomes very easy to provide an inline version of the SMC call primitive, and avoid performing a function call to stash the registers that would otherwise be clobbered by SMCCC v1.0.
--- include/linux/arm-smccc.h | 141 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+)
include/linux/arm-smccc.h +141 -0
@@ -150,5 +150,146 @@ asmlinkage void __arm_smccc_hvc(unsigned#define arm_smccc_hvc_quirk (...) __arm_smccc_hvc(__VA_ARGS__) +/* SMCCC v1.1 implementation madness follows */ +#ifdef CONFIG_ARM64 + +#define SMCCC_SMC_INST "smc #0" +#define SMCCC_HVC_INST "hvc #0" + +#elif defined(CONFIG_ARM ) +#include <asm/opcodes-sec.h> +#include <asm/opcodes-virt.h> + +#define SMCCC_SMC_INST __SMC(0) +#define SMCCC_HVC_INST __HVC(0) + +#endif + +#define ___count_args (_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x + +#define __count_args (...) \ + ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) + +#define __constraint_write_0 \ + "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_1 \ + "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_2 \ + "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3) +#define __constraint_write_3 \ + "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3) +#define __constraint_write_4 __constraint_write_3 +#define __constraint_write_5 __constraint_write_4 +#define __constraint_write_6 __constraint_write_5 +#define __constraint_write_7 __constraint_write_6 + +#define __constraint_read_0 +#define __constraint_read_1 +#define __constraint_read_2 +#define __constraint_read_3 +#define __constraint_read_4 "r" (r4) +#define __constraint_read_5 __constraint_read_4, "r" (r5) +#define __constraint_read_6 __constraint_read_5, "r" (r6) +#define __constraint_read_7 __constraint_read_6, "r" (r7) + +#define __declare_arg_0 (a0, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register unsigned long r1 asm("r1"); \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_1 (a0, a1, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_2 (a0, a1, a2, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register unsigned long r3 asm("r3") + +#define __declare_arg_3 (a0, a1, a2, a3, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register typeof(a3) r3 asm("r3") = a3 + +#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ + __declare_arg_3(a0, a1, a2, a3, res); \ + register typeof(a4) r4 asm("r4") = a4 + +#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ + __declare_arg_4(a0, a1, a2, a3, a4, res); \ + register typeof(a5) r5 asm("r5") = a5 + +#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ + __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ + register typeof(a6) r6 asm("r6") = a6 + +#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ + __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ + register typeof(a7) r7 asm("r7") = a7 + +#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__) +#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__) + +#define ___constraints (count) \ + : __constraint_write_ ## count \ + : __constraint_read_ ## count \ + : "memory" +#define __constraints (count) ___constraints(count) + +/* +* We have an output list that is not necessarily used, and GCC feels +* entitled to optimise the whole sequence away. "volatile" is what +* makes it stick. +*/ +#define __arm_smccc_1_1 (inst, ...) \ + do { \ + __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ + asm volatile(inst "\n" \ + __constraints(__count_args(__VA_ARGS__))); \ + if (___res) \ + *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + } while (0) + +/* +* arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call +* +* This is a variadic macro taking one to eight source arguments, and +* an optional return structure. +* +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 3 +* +* This macro is used to make SMC calls following SMC Calling Convention v1.1. +* The content of the supplied param are copied to registers 0 to 7 prior +* to the SMC instruction. The return values are updated with the content +* from register 0 to 3 on return from the SMC instruction if not NULL. +*/ +#define arm_smccc_1_1_smc (...) __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__) + +/* +* arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call +* +* This is a variadic macro taking one to eight source arguments, and +* an optional return structure. +* +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 3 +* +* This macro is used to make HVC calls following SMC Calling Convention v1.1. +* The content of the supplied param are copied to registers 0 to 7 prior +* to the HVC instruction. The return values are updated with the content +* from register 0 to 3 on return from the HVC instruction if not NULL. +*/ +#define arm_smccc_1_1_hvc (...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) +#endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/
Greg Kroah-Hartman
maintainerPATCH 93/195 arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit b092201e0020 upstream.
Add the detection and runtime code for ARM_SMCCC_ARCH_WORKAROUND_1. It is lovely. Really.
--- arch/arm64/kernel/bpi.S | 20 ++++++++++++ arch/arm64/kernel/cpu_errata.c | 68 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-)
arch/arm64/kernel/bpi.S +20 -0
@@ -17,6 +17,7 @@ */ #include <linux/linkage.h> +#include <linux/arm-smccc.h> .macro ventry target .rept 31
@@ -85,3 +86,22 @@ ENTRY(__qcom_hyp_sanitize_link_stack_sta .endr ldp x29, x30, [sp], #16 ENTRY(__qcom_hyp_sanitize_link_stack_end) + +.macro smccc_workaround_1 inst + sub sp, sp, #(8 * 4) + stp x2, x3, [sp, #(8 * 0)] + stp x0, x1, [sp, #(8 * 2)] + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 + \inst #0 + ldp x2, x3, [sp, #(8 * 0)] + ldp x0, x1, [sp, #(8 * 2)] + add sp, sp, #(8 * 4) +.endm + +ENTRY(__smccc_workaround_1_smc_start) + smccc_workaround_1 smc +ENTRY(__smccc_workaround_1_smc_end) + +ENTRY(__smccc_workaround_1_hvc_start) + smccc_workaround_1 hvc +ENTRY(__smccc_workaround_1_hvc_end)
arch/arm64/kernel/cpu_errata.c +67 -1
96 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 94/195 arm64: Kill PSCI_GET_VERSION as a variant-2 workaround
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
Commit 3a0a397ff5ff upstream.
Now that we've standardised on SMCCC v1.1 to perform the branch prediction invalidation, let's drop the previous band-aid. If vendors haven't updated their firmware to do SMCCC 1.1, they haven't updated PSCI either, so we don't loose anything.
--- arch/arm64/kernel/bpi.S | 24 --------------------- arch/arm64/kernel/cpu_errata.c | 45 +++++++++++------------------------------ arch/arm64/kvm/hyp/switch.c | 14 ------------ 3 files changed, 13 insertions(+), 70 deletions(-)
arch/arm64/kernel/bpi.S +0 -24
@@ -54,30 +54,6 @@ ENTRY(__bp_harden_hyp_vecs_start) vectors __kvm_hyp_vector .endr ENTRY(__bp_harden_hyp_vecs_end) -ENTRY(__psci_hyp_bp_inval_start) - sub sp, sp, #(8 * 18) - stp x16, x17, [sp, #(16 * 0)] - stp x14, x15, [sp, #(16 * 1)] - stp x12, x13, [sp, #(16 * 2)] - stp x10, x11, [sp, #(16 * 3)] - stp x8, x9, [sp, #(16 * 4)] - stp x6, x7, [sp, #(16 * 5)] - stp x4, x5, [sp, #(16 * 6)] - stp x2, x3, [sp, #(16 * 7)] - stp x0, x1, [sp, #(16 * 8)] - mov x0, #0x84000000 - smc #0 - ldp x16, x17, [sp, #(16 * 0)] - ldp x14, x15, [sp, #(16 * 1)] - ldp x12, x13, [sp, #(16 * 2)] - ldp x10, x11, [sp, #(16 * 3)] - ldp x8, x9, [sp, #(16 * 4)] - ldp x6, x7, [sp, #(16 * 5)] - ldp x4, x5, [sp, #(16 * 6)] - ldp x2, x3, [sp, #(16 * 7)] - ldp x0, x1, [sp, #(16 * 8)] - add sp, sp, #(8 * 18) -ENTRY(__psci_hyp_bp_inval_end) ENTRY(__qcom_hyp_sanitize_link_stack_start) stp x29, x30, [sp, #-16]!
arch/arm64/kernel/cpu_errata.c +13 -32
121 lines not on this page · raw message
arch/arm64/kvm/hyp/switch.c +0 -14
@@ -325,20 +325,6 @@ again:if (exit_code ==ARM_EXCEPTION_TRAP && !__populate_fault_info (vcpu)) goto again; -if (exit_code ==ARM_EXCEPTION_TRAP && - (kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC64 || -kvm_vcpu_trap_get_class (vcpu) == ESR_ELx_EC_HVC32)) { -u32 val =vcpu_get_reg (vcpu,0 ); - -if (val ==PSCI_0_2_FN_PSCI_VERSION ) { - val =kvm_psci_version (vcpu,kern_hyp_va (vcpu->kvm)); -if (unlikely (val ==KVM_ARM_PSCI_0_1 )) - val =PSCI_RET_NOT_SUPPORTED ; -vcpu_set_reg (vcpu,0 , val); - goto again; - } - } -if (static_branch_unlikely (&vgic_v2_cpuif_trap) && exit_code ==ARM_EXCEPTION_TRAP ) {bool valid;
Greg Kroah-Hartman
maintainerPATCH 95/195 mtd: cfi: convert inline functions to macros
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 9e343e87d2c4c707ef8fae2844864d4dde3a2d13 upstream.
The map_word_() functions, dating back to linux-2.6.8, try to perform bitwise operations on a 'map_word' structure. This may have worked with compilers that were current then (gcc-3.4 or earlier), but end up being rather inefficient on any version I could try now (gcc-4.4 or higher). Specifically we hit a problem analyzed in gcc PR81715 where we fail to reuse the stack space for local variables.
This can be seen immediately in the stack consumption for cfi_staa_erase_varsize() and other functions that (with CONFIG_KASAN) can be up to 2200 bytes. Changing the inline functions into macros brings this down to 1280 bytes. Without KASAN, the same problem exists, but the stack consumption is lower to start with, my patch shrinks it from 920 to 496 bytes on with arm-linux-gnueabi-gcc-5.4, and saves around 1KB in .text size for cfi_cmdset_0020.c, as it avoids copying map_word structures for each call to one of these helpers.
With the latest gcc-8 snapshot, the problem is fixed in upstream gcc, but nobody uses that yet, so we should still work around it in mainline kernels and probably backport the workaround to stable kernels as well. We had a couple of other functions that suffered from the same gcc bug, and all of those had a simpler workaround involving dummy variables in the inline function. Unfortunately that did not work here, the macro hack was the best I could come up with.
It would also be helpful to have someone to a little performance testing on the patch, to see how much it helps in terms of CPU utilitzation.
--- include/linux/mtd/map.h | 130 ++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 69 deletions(-)
include/linux/mtd/map.h +61 -69
@@ -270,75 +270,67 @@ void map_destroy(struct mtd_info *mtd);#define INVALIDATE_CACHED_RANGE (map, from, size) \ do { if (map->inval_cache) map->inval_cache(map, from, size); } while (0) - -static inline int map_word_equal (struct map_info *map,map_word val1,map_word val2) -{ -int i; - -for (i =0 ; i <map_words (map); i++) { -if (val1.x[i] != val2.x[i]) -return 0 ; - } - -return 1 ; -} - -static inline map_word map_word_and (struct map_info *map,map_word val1,map_word val2) -{ -map_word r; -int i; - -for (i =0 ; i <map_words (map); i++) - r.x[i] = val1.x[i] & val2.x[i]; - -return r; -} - -static inline map_word map_word_clr (struct map_info *map,map_word val1,map_word val2) -{ -map_word r; -int i; - -for (i =0 ; i <map_words (map); i++) - r.x[i] = val1.x[i] & ~val2.x[i]; - -return r; -} - -static inline map_word map_word_or (struct map_info *map,map_word val1,map_word val2) -{ -map_word r; -int i; - -for (i =0 ; i <map_words (map); i++) - r.x[i] = val1.x[i] | val2.x[i]; - -return r; -} - -static inline int map_word_andequal (struct map_info *map,map_word val1,map_word val2,map_word val3) -{ -int i; - -for (i =0 ; i <map_words (map); i++) { -if ((val1.x[i] & val2.x[i]) != val3.x[i]) -return 0 ; - } - -return 1 ; -} - -static inline int map_word_bitsset (struct map_info *map,map_word val1,map_word val2) -{ -int i; - -for (i =0 ; i <map_words (map); i++) { -if (val1.x[i] & val2.x[i]) -return 1 ; - } - -return 0 ; -} +#define map_word_equal (map, val1, val2) \ +({ \ + int i, ret = 1; \ + for (i = 0; i < map_words(map); i++) \ + if ((val1).x[i] != (val2).x[i]) { \ + ret = 0; \ + break; \ + } \ + ret; \ +}) + +#define map_word_and (map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] & (val2).x[i]; \ + r; \ +}) + +#define map_word_clr (map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] & ~(val2).x[i]; \ + r; \ +}) + +#define map_word_or (map, val1, val2) \ +({ \ + map_word r; \ + int i; \ + for (i = 0; i < map_words(map); i++) \ + r.x[i] = (val1).x[i] | (val2).x[i]; \ + r; \ +}) + +#define map_word_andequal (map, val1, val2, val3) \ +({ \ + int i, ret = 1; \ + for (i = 0; i < map_words(map); i++) { \ + if (((val1).x[i] & (val2).x[i]) != (val2).x[i]) { \ + ret = 0; \ + break; \ + } \ + } \ + ret; \ +}) + +#define map_word_bitsset (map, val1, val2) \ +({ \ + int i, ret = 0; \ + for (i = 0; i < map_words(map); i++) { \ + if ((val1).x[i] & (val2).x[i]) { \ + ret = 1; \ + break; \ + } \ + } \ + ret; \ +})static inline map_word map_word_load (struct map_info *map,const void *ptr) {
Greg Kroah-Hartman
maintainerPATCH 96/195 mtd: nand: brcmnand: Disable prefetch by default
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kamal Dasu <[email protected]>
commit f953f0f89663c39f08f4baaa8a4a881401b65654 upstream.
Brcm nand controller prefetch feature needs to be disabled by default. Enabling affects performance on random reads as well as dma reads.
--- drivers/mtd/nand/brcmnand/brcmnand.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +3 -10
@@ -2193,16 +2193,9 @@ static int brcmnand_setup_dev(struct brcif (ctrl->nand_version >=0x0702 ) tmp |=ACC_CONTROL_RD_ERASED ; tmp &= ~ACC_CONTROL_FAST_PGM_RDIN ; -if (ctrl->features &BRCMNAND_HAS_PREFETCH ) { -/* -* FIXME: Flash DMA + prefetch may see spurious erased-page ECC -* errors -*/ -if (has_flash_dma (ctrl)) - tmp &= ~ACC_CONTROL_PREFETCH ; -else - tmp |=ACC_CONTROL_PREFETCH ; - } +if (ctrl->features &BRCMNAND_HAS_PREFETCH ) + tmp &= ~ACC_CONTROL_PREFETCH ; +nand_writereg (ctrl, offs, tmp);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 97/195 mtd: nand: Fix nand_do_read_oob() return value
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit 87e89ce8d0d14f573c068c61bec2117751fb5103 upstream.
Starting from commit 041e4575f034 ("mtd: nand: handle ECC errors in OOB"), nand_do_read_oob() (from the NAND core) did return 0 or a negative error, and the MTD layer expected it.
However, the trend for the NAND layer is now to return an error or a positive number of bitflips. Deciding which status to return to the user belongs to the MTD layer.
Commit e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()") brought this logic to the mtd_read_oob() function while the return value coming from nand_do_read_oob() (called by the ->_read_oob() hook) was left unchanged.
--- drivers/mtd/nand/nand_base.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +4 -1
@@ -2201,6 +2201,7 @@ EXPORT_SYMBOL(nand_write_oob_syndrome);static int nand_do_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) { +unsigned int max_bitflips =0 ;int page, realpage, chipnr;struct nand_chip *chip =mtd_to_nand (mtd);struct mtd_ecc_stats stats;
@@ -2258,6 +2259,8 @@ static int nand_do_read_oob(struct mtd_inand_wait_ready (mtd); } + max_bitflips = max_t(unsigned int, max_bitflips, ret); + readlen -= len;if (!readlen)break ;
@@ -2283,7 +2286,7 @@ static int nand_do_read_oob(struct mtd_iif (mtd->ecc_stats.failed - stats.failed)return -EBADMSG ; -return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN :0 ; +return max_bitflips; }/**
Greg Kroah-Hartman
maintainerPATCH 98/195 mtd: nand: sunxi: Fix ECC strength choice
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit f4c6cd1a7f2275d5bc0e494b21fff26f8dde80f0 upstream.
When the requested ECC strength does not exactly match the strengths supported by the ECC engine, the driver is selecting the closest strength meeting the 'selected_strength > requested_strength' constraint. Fix the fact that, in this particular case, ecc->strength value was not updated to match the 'selected_strength'.
For instance, one can encounter this issue when no ECC requirement is filled in the device tree while the NAND chip minimum requirement is not a strength/step_size combo natively supported by the ECC engine.
--- drivers/mtd/nand/sunxi_nand.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mtd/nand/sunxi_nand.c +7 -1
@@ -1853,8 +1853,14 @@ static int sunxi_nand_hw_common_ecc_ctrl/* Add ECC info retrieval from DT */ for (i =0 ; i <ARRAY_SIZE (strengths); i++) { -if (ecc->strength <= strengths[i]) +if (ecc->strength <= strengths[i]) { +/* +* Update ecc->strength value with the actual strength +* that will be used by the ECC engine. +*/ + ecc->strength = strengths[i];break ; + } }if (i >=ARRAY_SIZE (strengths)) {
Greg Kroah-Hartman
maintainerPATCH 99/195 ubi: Fix race condition between ubi volume creation and udev
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Clay McClure <[email protected]>
commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.
Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi device creation and udev"), we should make the volume active before registering it.
--- drivers/mtd/ubi/vmt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/ubi/vmt.c +10 -5
@@ -270,6 +270,12 @@ int ubi_create_volume(struct ubi_device vol->last_eb_bytes = vol->usable_leb_size; } +/* Make volume "available" before it becomes accessible via sysfs */ +spin_lock (&ubi->volumes_lock); + ubi->volumes[vol_id] = vol; + ubi->vol_count +=1 ; +spin_unlock (&ubi->volumes_lock); +/* Register character device for the volume */ cdev_init (&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner =THIS_MODULE ;
@@ -298,11 +304,6 @@ int ubi_create_volume(struct ubi_deviceif (err) goto out_sysfs; -spin_lock (&ubi->volumes_lock); - ubi->volumes[vol_id] = vol; - ubi->vol_count +=1 ; -spin_unlock (&ubi->volumes_lock); -ubi_volume_notify (ubi, vol,UBI_VOLUME_ADDED );self_check_volumes (ubi);return err;
@@ -315,6 +316,10 @@ out_sysfs:*/ cdev_device_del (&vol->cdev, &vol->dev); out_mapping: +spin_lock (&ubi->volumes_lock); + ubi->volumes[vol_id] =NULL ; + ubi->vol_count -=1 ; +spin_unlock (&ubi->volumes_lock);ubi_eba_destroy_table (eba_tbl); out_acc:spin_lock (&ubi->volumes_lock);
Greg Kroah-Hartman
maintainerPATCH 101/195 ubi: block: Fix locking for idr_alloc/idr_remove
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Bolen <[email protected]>
commit 7f29ae9f977bcdc3654e68bc36d170223c52fd48 upstream.
This fixes a race with idr_alloc where gd->first_minor can be set to the same value for two simultaneous calls to ubiblock_create. Each instance calls device_add_disk with the same first_minor. device_add_disk calls bdi_register_owner which generates several warnings.
WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2'
WARNING: CPU: 1 PID: 179 at kernel-source/lib/kobject.c:240 kobject_add_internal+0x1ec/0x2f8
kobject_add_internal failed for 252:2 with -EEXIST, don't try to register things with the same name in the same directory
WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x88
sysfs: cannot create duplicate filename '/dev/block/252:2'
However, device_add_disk does not error out when bdi_register_owner returns an error. Control continues until reaching blk_register_queue. It then BUGs.
kernel BUG at kernel-source/fs/sysfs/group.c:113! [<c01e26cc>] (internal_create_group) from [<c01e2950>] (sysfs_create_group+0x20/0x24)
[<c01e2950>] (sysfs_create_group) from [<c00e3d38>] (blk_trace_init_sysfs+0x18/0x20)
[<c00e3d38>] (blk_trace_init_sysfs) from [<c02bdfbc>] (blk_register_queue+0xd8/0x154)
[<c02bdfbc>] (blk_register_queue) from [<c02cec84>] (device_add_disk+0x194/0x44c)
[<c02cec84>] (device_add_disk) from [<c0436ec8>] (ubiblock_create+0x284/0x2e0)
[<c0436ec8>] (ubiblock_create) from [<c0427bb8>] (vol_cdev_ioctl+0x450/0x554)
[<c0427bb8>] (vol_cdev_ioctl) from [<c0189110>] (vfs_ioctl+0x30/0x44) [<c0189110>] (vfs_ioctl) from [<c01892e0>] (do_vfs_ioctl+0xa0/0x790) [<c01892e0>] (do_vfs_ioctl) from [<c0189a14>] (SyS_ioctl+0x44/0x68) [<c0189a14>] (SyS_ioctl) from [<c0010640>] (ret_fast_syscall+0x0/0x34)
Locking idr_alloc/idr_remove removes the race and keeps gd->first_minor unique.
--- drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)
drivers/mtd/ubi/block.c +26 -16
@@ -99,6 +99,8 @@ struct ubiblock {/* Linked list of all ubiblock instances */ static LIST_HEAD (ubiblock_devices); +static DEFINE_IDR (ubiblock_minor_idr); +/* Protects ubiblock_devices and ubiblock_minor_idr */ static DEFINE_MUTEX (devices_mutex);static int ubiblock_major;
@@ -351,8 +353,6 @@ static const struct blk_mq_ops ubiblock_ .init_request = ubiblock_init_request, }; -static DEFINE_IDR (ubiblock_minor_idr); -int ubiblock_create (struct ubi_volume_info *vi) {struct ubiblock *dev;
@@ -365,14 +365,15 @@ int ubiblock_create(struct ubi_volume_in/* Check that the volume isn't already handled */ mutex_lock (&devices_mutex);if (find_dev_nolock (vi->ubi_num, vi->vol_id)) { -mutex_unlock (&devices_mutex); -return -EEXIST ; + ret = -EEXIST ; + goto out_unlock; } -mutex_unlock (&devices_mutex); dev =kzalloc (sizeof (struct ubiblock ),GFP_KERNEL ); -if (!dev) -return -ENOMEM ; +if (!dev) { + ret = -ENOMEM ; + goto out_unlock; + }mutex_init (&dev->dev_mutex);
@@ -437,14 +438,13 @@ int ubiblock_create(struct ubi_volume_in goto out_free_queue; } -mutex_lock (&devices_mutex);list_add_tail (&dev->list, &ubiblock_devices); -mutex_unlock (&devices_mutex);/* Must be the last step: anyone can call file ops from now on */ add_disk (dev->gd);dev_info (disk_to_dev (dev->gd),"created from ubi%d:%d(%s)" , dev->ubi_num, dev->vol_id, vi->name); +mutex_unlock (&devices_mutex);return 0 ; out_free_queue:
@@ -457,6 +457,8 @@ out_put_disk:put_disk (dev->gd); out_free_dev:kfree (dev); +out_unlock: +mutex_unlock (&devices_mutex);return ret; }
@@ -478,30 +480,36 @@ static void ubiblock_cleanup(struct ubibint ubiblock_remove (struct ubi_volume_info *vi) {struct ubiblock *dev; +int ret;mutex_lock (&devices_mutex); dev =find_dev_nolock (vi->ubi_num, vi->vol_id);if (!dev) { -mutex_unlock (&devices_mutex); -return -ENODEV ; + ret = -ENODEV ; + goto out_unlock; }/* Found a device, let's lock it so we can check if it's busy */ mutex_lock (&dev->dev_mutex);if (dev->refcnt >0 ) { -mutex_unlock (&dev->dev_mutex); -mutex_unlock (&devices_mutex); -return -EBUSY ; + ret = -EBUSY ; + goto out_unlock_dev; }/* Remove from device list */ list_del (&dev->list); -mutex_unlock (&devices_mutex); -ubiblock_cleanup (dev);mutex_unlock (&dev->dev_mutex); +mutex_unlock (&devices_mutex); +kfree (dev);return 0 ; + +out_unlock_dev: +mutex_unlock (&dev->dev_mutex); +out_unlock: +mutex_unlock (&devices_mutex); +return ret; }static int ubiblock_resize (struct ubi_volume_info *vi)
@@ -630,6 +638,7 @@ static void ubiblock_remove_all(void)struct ubiblock *next;struct ubiblock *dev; +mutex_lock (&devices_mutex);list_for_each_entry_safe (dev, next, &ubiblock_devices, list) {/* The module is being forcefully removed */ WARN_ON (dev->desc);
@@ -638,6 +647,7 @@ static void ubiblock_remove_all(void)ubiblock_cleanup (dev);kfree (dev); } +mutex_unlock (&devices_mutex); }int __init ubiblock_init (void )
Greg Kroah-Hartman
maintainerPATCH 102/195 ubifs: free the encrypted symlink target
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 6b46d444146eb8d0b99562795cea8086639d7282 upstream.
ubifs_symlink() forgot to free the kmalloc()'ed buffer holding the encrypted symlink target, creating a memory leak. Fix it.
(UBIFS could actually encrypt directly into ui->data, removing the temporary buffer, but that is left for the patch that switches to use the symlink helper functions.)
--- fs/ubifs/dir.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/ubifs/dir.c +4 -6
@@ -1216,10 +1216,8 @@ static int ubifs_symlink(struct inode *d ostr.len = disk_link.len; err =fscrypt_fname_usr_to_disk (inode, &istr, &ostr); -if (err) { -kfree (sd); +if (err) goto out_inode; - } sd->len =cpu_to_le16 (ostr.len); disk_link.name = (char *)sd;
@@ -1251,11 +1249,10 @@ static int ubifs_symlink(struct inode *d goto out_cancel;mutex_unlock (&dir_ui->ui_mutex); -ubifs_release_budget (c, &req);insert_inode_hash (inode);d_instantiate (dentry, inode); -fscrypt_free_filename (&nm); -return 0 ; + err =0 ; + goto out_fname; out_cancel: dir->i_size -= sz_change;
@@ -1268,6 +1265,7 @@ out_fname:fscrypt_free_filename (&nm); out_budg:ubifs_release_budget (c, &req); +kfree (sd);return err; }
Greg Kroah-Hartman
maintainerPATCH 103/195 nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Scott Mayhew <[email protected]>
commit ba4a76f703ab7eb72941fdaac848502073d6e9ee upstream.
Currently when falling back to doing I/O through the MDS (via pnfs_{read|write}_through_mds), the client frees the nfs_pgio_header without releasing the reference taken on the dreq
via pnfs_generic_pg_{read|write}pages -> nfs_pgheader_init -> nfs_direct_pgio_init. It then takes another reference on the dreq via nfs_generic_pg_pgios -> nfs_pgheader_init -> nfs_direct_pgio_init and as a result the requester will become stuck in inode_dio_wait. Once that happens, other processes accessing the inode will become stuck as well.
Ensure that pnfs_read_through_mds() and pnfs_write_through_mds() clean up correctly by calling hdr->completion_ops->completion() instead of calling hdr->release() directly.
This can be reproduced (sometimes) by performing "storage failover takeover" commands on NetApp filer while doing direct I/O from a client.
This can also be reproduced using SystemTap to simulate a failure while doing direct I/O from a client (from Dave Wysochanski <[email protected]>):
stap -v -g -e 'probe module("nfs_layout_nfsv41_files").function("nfs4_fl_prepare_ds").return { $return=NULL; exit(); }'
--- fs/nfs/pnfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/pnfs.c +2 -2
@@ -2237,7 +2237,7 @@ pnfs_write_through_mds(struct nfs_pageionfs_pageio_reset_write_mds (desc); mirror->pg_recoalesce =1 ; } - hdr->release (hdr); + hdr->completion_ops->completion (hdr); } static enum pnfs_try_status
@@ -2360,7 +2360,7 @@ pnfs_read_through_mds(struct nfs_pageio_nfs_pageio_reset_read_mds (desc); mirror->pg_recoalesce =1 ; } - hdr->release (hdr); + hdr->completion_ops->completion (hdr); }/*
Greg Kroah-Hartman
maintainerPATCH 104/195 nfs41: do not return ENOMEM on LAYOUTUNAVAILABLE
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tigran Mkrtchyan <[email protected]>
commit 7ff4cff637aa0bd2abbd81f53b2a6206c50afd95 upstream.
A pNFS server may return LAYOUTUNAVAILABLE error on LAYOUTGET for files which don't have any layout. In this situation pnfs_update_layout currently returns NULL. As this NULL is converted into ENOMEM, IO requests fails instead of falling back to MDS.
Do not return ENOMEM on LAYOUTUNAVAILABLE and let client retry through MDS.
Fixes 8d40b0f14846f. I will suggest to backport this fix to affected stable branches.
--- fs/nfs/filelayout/filelayout.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/nfs/filelayout/filelayout.c +1 -3
@@ -895,9 +895,7 @@ fl_pnfs_update_layout(struct inode *ino, lseg =pnfs_update_layout (ino, ctx, pos, count, iomode, strict_iomode, gfp_flags); -if (!lseg) - lseg =ERR_PTR (-ENOMEM ); -if (IS_ERR (lseg)) +if (IS_ERR_OR_NULL (lseg)) goto out; lo =NFS_I (ino)->layout;
Greg Kroah-Hartman
maintainerPATCH 105/195 NFS: Add a cond_resched() to nfs_commit_release_pages()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit 7f1bda447c9bd48b415acedba6b830f61591601f upstream.
The commit list can get very large, and so we need a cond_resched() in nfs_commit_release_pages() in order to ensure we don't hog the CPU for excessive periods of time.
--- fs/nfs/write.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/write.c +2 -0
@@ -1836,6 +1836,8 @@ static void nfs_commit_release_pages(strset_bit (NFS_CONTEXT_RESEND_WRITES , &req->wb_context->flags); next:nfs_unlock_and_release_request (req); +/* Latency breaker */ +cond_resched (); } nfss =NFS_SERVER (data->inode);if (atomic_long_read (&nfss->writeback) <NFS_CONGESTION_OFF_THRESH )
Greg Kroah-Hartman
maintainerPATCH 106/195 NFS: Fix nfsstat breakage due to LOOKUPP
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit 8634ef5e05311f32d7f2aee06f6b27a8834a3bd6 upstream.
The LOOKUPP operation was inserted into the nfs4_procedures array rather than being appended, which put /proc/net/rpc/nfs out of whack, and broke the nfsstat utility.
Fix by moving the LOOKUPP operation to the end of the array, and by ensuring that it keeps the same length whether or not NFSV4.1 and NFSv4.2 are compiled in.
--- fs/nfs/nfs4xdr.c | 64 ++++++++++++++++++++++++++++++--------------------- include/linux/nfs4.h | 12 ++++++--- 2 files changed, 46 insertions(+), 30 deletions(-)
fs/nfs/nfs4xdr.c +38 -26
@@ -7668,6 +7668,22 @@ nfs4_stat_to_errno(int stat) .p_name = #proc, \ } +#if defined(CONFIG_NFS_V4_1 ) +#define PROC41 (proc, argtype, restype) \ + PROC(proc, argtype, restype) +#else +#define PROC41 (proc, argtype, restype) \ + STUB(proc) +#endif + +#if defined(CONFIG_NFS_V4_2 ) +#define PROC42 (proc, argtype, restype) \ + PROC(proc, argtype, restype) +#else +#define PROC42 (proc, argtype, restype) \ + STUB(proc) +#endif +const struct rpc_procinfo nfs4_procedures[] = {PROC (READ , enc_read, dec_read),PROC (WRITE , enc_write, dec_write),
@@ -7688,7 +7704,6 @@ const struct rpc_procinfo nfs4_procedurePROC (ACCESS , enc_access, dec_access),PROC (GETATTR , enc_getattr, dec_getattr),PROC (LOOKUP , enc_lookup, dec_lookup), -PROC (LOOKUPP , enc_lookupp, dec_lookupp),PROC (LOOKUP_ROOT , enc_lookup_root, dec_lookup_root),PROC (REMOVE , enc_remove, dec_remove), PROC(RENAME, enc_rename, dec_rename),
@@ -7707,33 +7722,30 @@ const struct rpc_procinfo nfs4_procedurePROC (RELEASE_LOCKOWNER , enc_release_lockowner, dec_release_lockowner),PROC (SECINFO , enc_secinfo, dec_secinfo),PROC (FSID_PRESENT , enc_fsid_present, dec_fsid_present), -#if defined(CONFIG_NFS_V4_1 ) -PROC (EXCHANGE_ID , enc_exchange_id, dec_exchange_id), -PROC (CREATE_SESSION , enc_create_session, dec_create_session), -PROC (DESTROY_SESSION , enc_destroy_session, dec_destroy_session), -PROC (SEQUENCE , enc_sequence, dec_sequence), -PROC (GET_LEASE_TIME , enc_get_lease_time, dec_get_lease_time), -PROC (RECLAIM_COMPLETE , enc_reclaim_complete, dec_reclaim_complete), -PROC (GETDEVICEINFO , enc_getdeviceinfo, dec_getdeviceinfo), -PROC (LAYOUTGET , enc_layoutget, dec_layoutget), -PROC (LAYOUTCOMMIT , enc_layoutcommit, dec_layoutcommit), -PROC (LAYOUTRETURN , enc_layoutreturn, dec_layoutreturn), -PROC (SECINFO_NO_NAME , enc_secinfo_no_name, dec_secinfo_no_name), -PROC (TEST_STATEID , enc_test_stateid, dec_test_stateid), -PROC (FREE_STATEID , enc_free_stateid, dec_free_stateid), +PROC41 (EXCHANGE_ID , enc_exchange_id, dec_exchange_id), +PROC41 (CREATE_SESSION , enc_create_session, dec_create_session), +PROC41 (DESTROY_SESSION , enc_destroy_session, dec_destroy_session), +PROC41 (SEQUENCE , enc_sequence, dec_sequence), +PROC41 (GET_LEASE_TIME , enc_get_lease_time, dec_get_lease_time), +PROC41 (RECLAIM_COMPLETE ,enc_reclaim_complete, dec_reclaim_complete), +PROC41 (GETDEVICEINFO , enc_getdeviceinfo, dec_getdeviceinfo), +PROC41 (LAYOUTGET , enc_layoutget, dec_layoutget), +PROC41 (LAYOUTCOMMIT , enc_layoutcommit, dec_layoutcommit), +PROC41 (LAYOUTRETURN , enc_layoutreturn, dec_layoutreturn), +PROC41 (SECINFO_NO_NAME , enc_secinfo_no_name, dec_secinfo_no_name), +PROC41 (TEST_STATEID , enc_test_stateid, dec_test_stateid), +PROC41 (FREE_STATEID , enc_free_stateid, dec_free_stateid),STUB (GETDEVICELIST ), -PROC (BIND_CONN_TO_SESSION , +PROC41 (BIND_CONN_TO_SESSION , enc_bind_conn_to_session, dec_bind_conn_to_session), -PROC (DESTROY_CLIENTID , enc_destroy_clientid, dec_destroy_clientid), -#endif /* CONFIG_NFS_V4_1 */ -#ifdef CONFIG_NFS_V4_2 -PROC (SEEK , enc_seek, dec_seek), -PROC (ALLOCATE , enc_allocate, dec_allocate), -PROC (DEALLOCATE , enc_deallocate, dec_deallocate), -PROC (LAYOUTSTATS , enc_layoutstats, dec_layoutstats), -PROC (CLONE , enc_clone, dec_clone), - PROC(COPY, enc_copy, dec_copy), -#endif /* CONFIG_NFS_V4_2 */ +PROC41 (DESTROY_CLIENTID ,enc_destroy_clientid, dec_destroy_clientid), +PROC42 (SEEK , enc_seek, dec_seek), +PROC42 (ALLOCATE , enc_allocate, dec_allocate), +PROC42 (DEALLOCATE , enc_deallocate, dec_deallocate), +PROC42 (LAYOUTSTATS , enc_layoutstats, dec_layoutstats), +PROC42 (CLONE , enc_clone, dec_clone), +PROC42 (COPY , enc_copy, dec_copy), + PROC(LOOKUPP, enc_lookupp, dec_lookupp), };static unsigned int nfs_version4_counts[ARRAY_SIZE (nfs4_procedures)];
include/linux/nfs4.h +8 -4
@@ -457,7 +457,12 @@ enum lock_type4 {#define NFS4_DEBUG 1 -/* Index of predefined Linux client operations */ +/* +* Index of predefined Linux client operations +* +* To ensure that /proc/net/rpc/nfs remains correctly ordered, please +* append only to this enum when adding new client operations. +*/ enum {NFSPROC4_CLNT_NULL =0 ,/* Unused */
@@ -480,7 +485,6 @@ enum {NFSPROC4_CLNT_ACCESS ,NFSPROC4_CLNT_GETATTR ,NFSPROC4_CLNT_LOOKUP , -NFSPROC4_CLNT_LOOKUPP ,NFSPROC4_CLNT_LOOKUP_ROOT ,NFSPROC4_CLNT_REMOVE , NFSPROC4_CLNT_RENAME,
@@ -500,7 +504,6 @@ enum {NFSPROC4_CLNT_SECINFO ,NFSPROC4_CLNT_FSID_PRESENT , -/* nfs41 */ NFSPROC4_CLNT_EXCHANGE_ID ,NFSPROC4_CLNT_CREATE_SESSION , NFSPROC4_CLNT_DESTROY_SESSION,
@@ -518,13 +521,14 @@ enum {NFSPROC4_CLNT_BIND_CONN_TO_SESSION ,NFSPROC4_CLNT_DESTROY_CLIENTID , -/* nfs42 */ NFSPROC4_CLNT_SEEK ,NFSPROC4_CLNT_ALLOCATE ,NFSPROC4_CLNT_DEALLOCATE ,NFSPROC4_CLNT_LAYOUTSTATS ,NFSPROC4_CLNT_CLONE ,NFSPROC4_CLNT_COPY , + + NFSPROC4_CLNT_LOOKUPP, };/* nfs41 types */
Greg Kroah-Hartman
maintainerPATCH 107/195 NFS: commit direct writes even if they fail partially
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: J. Bruce Fields <[email protected]>
commit 1b8d97b0a837beaf48a8449955b52c650a7114b4 upstream.
If some of the WRITE calls making up an O_DIRECT write syscall fail, we neglect to commit, even if some of the WRITEs succeed.
We also depend on the commit code to free the reference count on the nfs_page taken in the "if (request_commit)" case at the end of nfs_direct_write_completion(). The problem was originally noticed because ENOSPC's encountered partway through a write would result in a closed file being sillyrenamed when it should have been unlinked.
--- fs/nfs/direct.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/nfs/direct.c +1 -3
@@ -775,10 +775,8 @@ static void nfs_direct_write_completion(spin_lock (&dreq->lock); -if (test_bit (NFS_IOHDR_ERROR , &hdr->flags)) { - dreq->flags =0 ; +if (test_bit (NFS_IOHDR_ERROR , &hdr->flags)) dreq->error = hdr->error; - }if (dreq->error ==0 ) {nfs_direct_good_bytes (dreq, hdr);if (nfs_write_need_commit (hdr)) {
Greg Kroah-Hartman
maintainerPATCH 108/195 NFS: reject request for id_legacy key without auxdata
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 49686cbbb3ebafe42e63868222f269d8053ead00 upstream.
nfs_idmap_legacy_upcall() is supposed to be called with 'aux' pointing to a 'struct idmap', via the call to request_key_with_auxdata() in nfs_idmap_request_key().
However it can also be reached via the request_key() system call in which case 'aux' will be NULL, causing a NULL pointer dereference in nfs_idmap_prepare_pipe_upcall(), assuming that the key description is valid enough to get that far.
Fix this by making nfs_idmap_legacy_upcall() negate the key if no auxdata is provided.
As usual, this bug was found by syzkaller. A simple reproducer using the command-line keyctl program is:
keyctl request2 id_legacy uid:0 '' @s
--- fs/nfs/nfs4idmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/nfs4idmap.c +5 -1
@@ -568,9 +568,13 @@ static int nfs_idmap_legacy_upcall(strucstruct idmap_msg *im;struct idmap *idmap = (struct idmap *)aux;struct key *key = cons->key; -int ret = -ENOMEM ; +int ret = -ENOKEY ; + +if (!aux) + goto out1;/* msg and im are freed in idmap_pipe_destroy_msg */ + ret = -ENOMEM ; data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data) goto out1;
Greg Kroah-Hartman
maintainerPATCH 109/195 NFS: Fix a race between mmap() and O_DIRECT
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit e231c6879cfd44e4fffd384bb6dd7d313249a523 upstream.
When locking the file in order to do O_DIRECT on it, we must unmap any mmapped ranges on the pagecache so that we can flush out the dirty data.
--- fs/nfs/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/io.c +1 -1
@@ -99,7 +99,7 @@ static void nfs_block_buffered(struct nf {if (!test_bit (NFS_INO_ODIRECT , &nfsi->flags)) {set_bit (NFS_INO_ODIRECT , &nfsi->flags); -nfs_wb_all (inode); +nfs_sync_mapping (inode->i_mapping); } }
Greg Kroah-Hartman
maintainerPATCH 110/195 kernfs: fix regression in kernfs_fop_write caused by wrong type
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
commit ba87977a49913129962af8ac35b0e13e0fa4382d upstream.
Commit b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file") changes type of local variable 'len' from ssize_t to size_t. This change caused that the *ppos value is updated also when the previous write callback failed.
Mentioned snippet:
...
len = ops->write(...); <- return value can be negative
...
if (len > 0) <- true here in this case
*ppos += len;
...
--- fs/kernfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/file.c +1 -1
@@ -275,7 +275,7 @@ static ssize_t kernfs_fop_write(struct f {struct kernfs_open_file *of =kernfs_of (file);const struct kernfs_ops *ops; -size_t len; +ssize_t len;char *buf;if (of->atomic_write_len) {
Greg Kroah-Hartman
maintainerPATCH 111/195 ahci: Annotate PCI ids for mobile Intel chipsets as such
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit ca1b4974bd237f2373b0e980b11957aac3499b56 upstream.
Intel uses different SATA PCI ids for the Desktop and Mobile SKUs of their chipsets. For older models the comment describing which chipset the PCI id is for, aksi indicates when we're dealing with a mobile SKU. Extend the comments for recent chipsets to also indicate mobile SKUs.
The information this commit adds comes from Intel's chipset datasheets.
This commit is a preparation patch for allowing a different default sata link powermanagement policy for mobile chipsets.
--- drivers/ata/ahci.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/ata/ahci.c +16 -16
@@ -267,9 +267,9 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0x3b23), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x3b24), board_ahci }, /* PCH RAID */ { PCI_VDEVICE(INTEL, 0x3b25), board_ahci }, /* PCH RAID */ - { PCI_VDEVICE(INTEL, 0x3b29), board_ahci }, /* PCH AHCI */ + { PCI_VDEVICE(INTEL, 0x3b29), board_ahci }, /* PCH M AHCI */ { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */ - { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */ + { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH M RAID */ { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x19b0), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b1), board_ahci }, /* DNV AHCI */
@@ -292,9 +292,9 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0x19cE), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19cF), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */ - { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT AHCI */ + { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT M AHCI */ { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */ - { PCI_VDEVICE(INTEL, 0x1c05), board_ahci }, /* CPT RAID */ + { PCI_VDEVICE(INTEL, 0x1c05), board_ahci }, /* CPT M RAID */ { PCI_VDEVICE(INTEL, 0x1c06), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1c07), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1d02), board_ahci }, /* PBG AHCI */
@@ -303,20 +303,20 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* PBG RAID */ { PCI_VDEVICE(INTEL, 0x2323), board_ahci }, /* DH89xxCC AHCI */ { PCI_VDEVICE(INTEL, 0x1e02), board_ahci }, /* Panther Point AHCI */ - { PCI_VDEVICE(INTEL, 0x1e03), board_ahci }, /* Panther Point AHCI */ + { PCI_VDEVICE(INTEL, 0x1e03), board_ahci }, /* Panther Point M AHCI */ { PCI_VDEVICE(INTEL, 0x1e04), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e05), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e06), board_ahci }, /* Panther Point RAID */ - { PCI_VDEVICE(INTEL, 0x1e07), board_ahci }, /* Panther Point RAID */ + { PCI_VDEVICE(INTEL, 0x1e07), board_ahci }, /* Panther Point M RAID */ { PCI_VDEVICE(INTEL, 0x1e0e), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x8c02), board_ahci }, /* Lynx Point AHCI */ - { PCI_VDEVICE(INTEL, 0x8c03), board_ahci }, /* Lynx Point AHCI */ + { PCI_VDEVICE(INTEL, 0x8c03), board_ahci }, /* Lynx Point M AHCI */ { PCI_VDEVICE(INTEL, 0x8c04), board_ahci }, /* Lynx Point RAID */ - { PCI_VDEVICE(INTEL, 0x8c05), board_ahci }, /* Lynx Point RAID */ + { PCI_VDEVICE(INTEL, 0x8c05), board_ahci }, /* Lynx Point M RAID */ { PCI_VDEVICE(INTEL, 0x8c06), board_ahci }, /* Lynx Point RAID */ - { PCI_VDEVICE(INTEL, 0x8c07), board_ahci }, /* Lynx Point RAID */ + { PCI_VDEVICE(INTEL, 0x8c07), board_ahci }, /* Lynx Point M RAID */ { PCI_VDEVICE(INTEL, 0x8c0e), board_ahci }, /* Lynx Point RAID */ - { PCI_VDEVICE(INTEL, 0x8c0f), board_ahci }, /* Lynx Point RAID */ + { PCI_VDEVICE(INTEL, 0x8c0f), board_ahci }, /* Lynx Point M RAID */ { PCI_VDEVICE(INTEL, 0x9c02), board_ahci }, /* Lynx Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9c03), board_ahci }, /* Lynx Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9c04), board_ahci }, /* Lynx Point-LP RAID */
@@ -357,21 +357,21 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0x9c87), board_ahci }, /* Wildcat Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c8f), board_ahci }, /* Wildcat Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x8c82), board_ahci }, /* 9 Series AHCI */ - { PCI_VDEVICE(INTEL, 0x8c83), board_ahci }, /* 9 Series AHCI */ + { PCI_VDEVICE(INTEL, 0x8c83), board_ahci }, /* 9 Series M AHCI */ { PCI_VDEVICE(INTEL, 0x8c84), board_ahci }, /* 9 Series RAID */ - { PCI_VDEVICE(INTEL, 0x8c85), board_ahci }, /* 9 Series RAID */ + { PCI_VDEVICE(INTEL, 0x8c85), board_ahci }, /* 9 Series M RAID */ { PCI_VDEVICE(INTEL, 0x8c86), board_ahci }, /* 9 Series RAID */ - { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */ + { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series M RAID */ { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */ - { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */ + { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series M RAID */ { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */ { PCI_VDEVICE(INTEL, 0xa102), board_ahci }, /* Sunrise Point-H AHCI */ - { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */ + { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H M AHCI */ { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0xa106), board_ahci }, /* Sunrise Point-H RAID */ - { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */ + { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H M RAID */ { PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Lewisburg AHCI*/
Greg Kroah-Hartman
maintainerPATCH 112/195 ahci: Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 998008b779e424bd7513c434d0ab9c1268459009 upstream.
Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI SATA controllers. This commit is a preparation patch for allowing a different default sata link powermanagement policy for mobile chipsets.
--- drivers/ata/ahci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ata/ahci.c +4 -0
@@ -385,6 +385,10 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/ + { PCI_VDEVICE(INTEL, 0x0f22), board_ahci }, /* Bay Trail AHCI */ + { PCI_VDEVICE(INTEL, 0x0f23), board_ahci }, /* Bay Trail AHCI */ + { PCI_VDEVICE(INTEL, 0x22a3), board_ahci }, /* Cherry Trail AHCI */ + { PCI_VDEVICE(INTEL, 0x5ae3), board_ahci }, /* Apollo Lake AHCI *//* JMicron 360/1/3/5/6, match class to avoid IDE function */ { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
Greg Kroah-Hartman
maintainerPATCH 114/195 crypto: hash - introduce crypto_hash_alg_has_setkey()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit cd6ed77ad5d223dc6299fb58f62e0f5267f7e2ba upstream.
Templates that use an shash spawn can use crypto_shash_alg_has_setkey() to determine whether the underlying algorithm requires a key or not. But there was no corresponding function for ahash spawns. Add it.
Note that the new function actually has to support both shash and ahash algorithms, since the ahash API can be used with either.
--- crypto/ahash.c | 11 +++++++++++ include/crypto/internal/hash.h | 2 ++ 2 files changed, 13 insertions(+)
crypto/ahash.c +11 -0
@@ -655,5 +655,16 @@ struct hash_alg_common *ahash_attr_alg(s }EXPORT_SYMBOL_GPL (ahash_attr_alg); +bool crypto_hash_alg_has_setkey (struct hash_alg_common *halg) +{ +struct crypto_alg *alg = &halg->base; + +if (alg->cra_type != &crypto_ahash_type) +return crypto_shash_alg_has_setkey (__crypto_shash_alg (alg)); + +return __crypto_ahash_alg (alg)->setkey !=NULL ; +} +EXPORT_SYMBOL_GPL (crypto_hash_alg_has_setkey); +MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Asynchronous cryptographic hash type" );
include/crypto/internal/hash.h +2 -0
@@ -90,6 +90,8 @@ static inline bool crypto_shash_alg_has_return alg->setkey != shash_no_setkey; } +bool crypto_hash_alg_has_setkey (struct hash_alg_common *halg); +int crypto_init_ahash_spawn (struct crypto_ahash_spawn *spawn,struct hash_alg_common *alg,struct crypto_instance *inst);
Greg Kroah-Hartman
maintainerPATCH 116/195 crypto: mcryptd - pass through absence of ->setkey()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit fa59b92d299f2787e6bae1ff078ee0982e80211f upstream.
When the mcryptd template is used to wrap an unkeyed hash algorithm, don't install a ->setkey() method to the mcryptd instance. This change is necessary for mcryptd to keep working with unkeyed hash algorithms once we start enforcing that ->setkey() is called when present.
--- crypto/mcryptd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/mcryptd.c +2 -1
@@ -535,7 +535,8 @@ static int mcryptd_create_hash(struct cr inst->alg.finup = mcryptd_hash_finup_enqueue; inst->alg.export = mcryptd_hash_export; inst->alg.import = mcryptd_hash_import; - inst->alg.setkey = mcryptd_hash_setkey; +if (crypto_hash_alg_has_setkey (halg)) + inst->alg.setkey = mcryptd_hash_setkey; inst->alg.digest = mcryptd_hash_digest_enqueue; err =ahash_register_instance (tmpl, inst);
Greg Kroah-Hartman
maintainerPATCH 117/195 crypto: poly1305 - remove ->setkey() method
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a16e772e664b9a261424107784804cffc8894977 upstream.
Since Poly1305 requires a nonce per invocation, the Linux kernel implementations of Poly1305 don't use the crypto API's keying mechanism and instead expect the key and nonce as the first 32 bytes of the data. But ->setkey() is still defined as a stub returning an error code. This prevents Poly1305 from being used through AF_ALG and will also break it completely once we start enforcing that all crypto API users (not just AF_ALG) call ->setkey() if present.
Fix it by removing crypto_poly1305_setkey(), leaving ->setkey as NULL.
--- arch/x86/crypto/poly1305_glue.c | 1 - crypto/poly1305_generic.c | 17 +++++------------ include/crypto/poly1305.h | 2 -- 3 files changed, 5 insertions(+), 15 deletions(-)
arch/x86/crypto/poly1305_glue.c +0 -1
@@ -164,7 +164,6 @@ static struct shash_alg alg = { .init = poly1305_simd_init, .update = poly1305_simd_update, .final = crypto_poly1305_final, - .setkey = crypto_poly1305_setkey, .descsize = sizeof(struct poly1305_simd_desc_ctx), .base = { .cra_name = "poly1305",
crypto/poly1305_generic.c +5 -12
@@ -47,17 +47,6 @@ int crypto_poly1305_init(struct shash_de }EXPORT_SYMBOL_GPL (crypto_poly1305_init); -int crypto_poly1305_setkey (struct crypto_shash *tfm, -const u8 *key,unsigned int keylen) -{ -/* Poly1305 requires a unique key for each tag, which implies that -* we can't set it on the tfm that gets accessed by multiple users -* simultaneously. Instead we expect the key as the first 32 bytes in -* the update() call. */ -return -ENOTSUPP ; -} -EXPORT_SYMBOL_GPL (crypto_poly1305_setkey); -static void poly1305_setrkey (struct poly1305_desc_ctx *dctx,const u8 *key) {/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
@@ -76,6 +65,11 @@ static void poly1305_setskey(struct poly dctx->s[3 ] =get_unaligned_le32 (key +12 ); } +/* +* Poly1305 requires a unique key for each tag, which implies that we can't set +* it on the tfm that gets accessed by multiple users simultaneously. Instead we +* expect the key as the first 32 bytes in the update() call. +*/ unsigned int crypto_poly1305_setdesckey (struct poly1305_desc_ctx *dctx,const u8 *src,unsigned int srclen) {
@@ -281,7 +275,6 @@ static struct shash_alg poly1305_alg = { .init = crypto_poly1305_init, .update = crypto_poly1305_update, .final = crypto_poly1305_final, - .setkey = crypto_poly1305_setkey, .descsize = sizeof(struct poly1305_desc_ctx), .base = { .cra_name = "poly1305",
include/crypto/poly1305.h +0 -2
@@ -31,8 +31,6 @@ struct poly1305_desc_ctx { };int crypto_poly1305_init (struct shash_desc *desc); -int crypto_poly1305_setkey (struct crypto_shash *tfm, -const u8 *key,unsigned int keylen);unsigned int crypto_poly1305_setdesckey (struct poly1305_desc_ctx *dctx,const u8 *src,unsigned int srclen); int crypto_poly1305_update(struct shash_desc *desc,
Greg Kroah-Hartman
maintainerPATCH 118/195 crypto: hash - annotate algorithms taking optional key
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a208fa8f33031b9e0aba44c7d1b7e68eb0cbd29e upstream.
We need to consistently enforce that keyed hashes cannot be used without setting the key. To do this we need a reliable way to determine whether a given hash algorithm is keyed or not. AF_ALG currently does this by checking for the presence of a ->setkey() method. However, this is actually slightly broken because the CRC-32 algorithms implement ->setkey() but can also be used without a key. (The CRC-32 "key" is not actually a cryptographic key but rather represents the initial state. If not overridden, then a default initial state is used.)
Prepare to fix this by introducing a flag CRYPTO_ALG_OPTIONAL_KEY which indicates that the algorithm has a ->setkey() method, but it is not required to be called. Then set it on all the CRC-32 algorithms.
The same also applies to the Adler-32 implementation in Lustre.
Also, the cryptd and mcryptd templates have to pass through the flag from their underlying algorithm.
--- arch/arm/crypto/crc32-ce-glue.c | 2 ++ arch/arm64/crypto/crc32-ce-glue.c | 2 ++ arch/powerpc/crypto/crc32c-vpmsum_glue.c | 1 + arch/s390/crypto/crc32-vx.c | 3 +++ arch/sparc/crypto/crc32c_glue.c | 1 + arch/x86/crypto/crc32-pclmul_glue.c | 1 + arch/x86/crypto/crc32c-intel_glue.c | 1 + crypto/crc32_generic.c | 1 + crypto/crc32c_generic.c | 1 + crypto/cryptd.c | 7 +++---- crypto/mcryptd.c | 7 +++---- drivers/crypto/bfin_crc.c | 3 ++- drivers/crypto/stm32/stm32_crc32.c | 2 ++ drivers/staging/lustre/lnet/libcfs/linux/linux-crypto-adler.c | 1 + include/linux/crypto.h | 6 ++++++ 15 files changed, 30 insertions(+), 9 deletions(-)
arch/arm/crypto/crc32-ce-glue.c +2 -0
@@ -188,6 +188,7 @@ static struct shash_alg crc32_pmull_algs .base.cra_name = "crc32", .base.cra_driver_name = "crc32-arm-ce", .base.cra_priority = 200, + .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize = 1, .base.cra_module = THIS_MODULE, }, {
@@ -203,6 +204,7 @@ static struct shash_alg crc32_pmull_algs .base.cra_name = "crc32c", .base.cra_driver_name = "crc32c-arm-ce", .base.cra_priority = 200, + .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize = 1, .base.cra_module = THIS_MODULE, } };
arch/arm64/crypto/crc32-ce-glue.c +2 -0
@@ -185,6 +185,7 @@ static struct shash_alg crc32_pmull_algs .base.cra_name = "crc32", .base.cra_driver_name = "crc32-arm64-ce", .base.cra_priority = 200, + .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize = 1, .base.cra_module = THIS_MODULE, }, {
@@ -200,6 +201,7 @@ static struct shash_alg crc32_pmull_algs .base.cra_name = "crc32c", .base.cra_driver_name = "crc32c-arm64-ce", .base.cra_priority = 200, + .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize = 1, .base.cra_module = THIS_MODULE, } };
arch/powerpc/crypto/crc32c-vpmsum_glue.c +1 -0
@@ -141,6 +141,7 @@ static struct shash_alg alg = { .cra_name = "crc32c", .cra_driver_name = "crc32c-vpmsum", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE,
arch/s390/crypto/crc32-vx.c +3 -0
@@ -238,6 +238,7 @@ static struct shash_alg crc32_vx_algs[] .cra_name = "crc32", .cra_driver_name = "crc32-vx", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CRC32_BLOCK_SIZE, .cra_ctxsize = sizeof(struct crc_ctx), .cra_module = THIS_MODULE,
@@ -258,6 +259,7 @@ static struct shash_alg crc32_vx_algs[] .cra_name = "crc32be", .cra_driver_name = "crc32be-vx", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CRC32_BLOCK_SIZE, .cra_ctxsize = sizeof(struct crc_ctx), .cra_module = THIS_MODULE,
@@ -278,6 +280,7 @@ static struct shash_alg crc32_vx_algs[] .cra_name = "crc32c", .cra_driver_name = "crc32c-vx", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CRC32_BLOCK_SIZE, .cra_ctxsize = sizeof(struct crc_ctx), .cra_module = THIS_MODULE,
arch/sparc/crypto/crc32c_glue.c +1 -0
@@ -133,6 +133,7 @@ static struct shash_alg alg = { .cra_name = "crc32c", .cra_driver_name = "crc32c-sparc64", .cra_priority = SPARC_CR_OPCODE_PRIORITY, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_alignmask = 7,
arch/x86/crypto/crc32-pclmul_glue.c +1 -0
@@ -162,6 +162,7 @@ static struct shash_alg alg = { .cra_name = "crc32", .cra_driver_name = "crc32-pclmul", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE,
arch/x86/crypto/crc32c-intel_glue.c +1 -0
@@ -226,6 +226,7 @@ static struct shash_alg alg = { .cra_name = "crc32c", .cra_driver_name = "crc32c-intel", .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE,
crypto/crc32_generic.c +1 -0
@@ -133,6 +133,7 @@ static struct shash_alg alg = { .cra_name = "crc32", .cra_driver_name = "crc32-generic", .cra_priority = 100, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE,
crypto/crc32c_generic.c +1 -0
@@ -146,6 +146,7 @@ static struct shash_alg alg = { .cra_name = "crc32c", .cra_driver_name = "crc32c-generic", .cra_priority = 100, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_alignmask = 3, .cra_ctxsize = sizeof(struct chksum_ctx),
crypto/cryptd.c +3 -4
@@ -895,10 +895,9 @@ static int cryptd_create_hash(struct cryif (err) goto out_free_inst; - type =CRYPTO_ALG_ASYNC ; -if (alg->cra_flags &CRYPTO_ALG_INTERNAL ) - type |=CRYPTO_ALG_INTERNAL ; - inst->alg.halg.base.cra_flags = type; + inst->alg.halg.base.cra_flags =CRYPTO_ALG_ASYNC | + (alg->cra_flags & (CRYPTO_ALG_INTERNAL | +CRYPTO_ALG_OPTIONAL_KEY )); inst->alg.halg.digestsize = salg->digestsize; inst->alg.halg.statesize = salg->statesize;
crypto/mcryptd.c +3 -4
@@ -517,10 +517,9 @@ static int mcryptd_create_hash(struct crif (err) goto out_free_inst; - type =CRYPTO_ALG_ASYNC ; -if (alg->cra_flags &CRYPTO_ALG_INTERNAL ) - type |=CRYPTO_ALG_INTERNAL ; - inst->alg.halg.base.cra_flags = type; + inst->alg.halg.base.cra_flags =CRYPTO_ALG_ASYNC | + (alg->cra_flags & (CRYPTO_ALG_INTERNAL | +CRYPTO_ALG_OPTIONAL_KEY )); inst->alg.halg.digestsize = halg->digestsize; inst->alg.halg.statesize = halg->statesize;
drivers/crypto/bfin_crc.c +2 -1
@@ -494,7 +494,8 @@ static struct ahash_alg algs = { .cra_driver_name = DRIVER_NAME, .cra_priority = 100, .cra_flags =CRYPTO_ALG_TYPE_AHASH | - CRYPTO_ALG_ASYNC, +CRYPTO_ALG_ASYNC | + CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(struct bfin_crypto_crc_ctx), .cra_alignmask = 3,
drivers/crypto/stm32/stm32_crc32.c +2 -0
@@ -208,6 +208,7 @@ static struct shash_alg algs[] = { .cra_name = "crc32", .cra_driver_name = DRIVER_NAME, .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_alignmask = 3, .cra_ctxsize = sizeof(struct stm32_crc_ctx),
@@ -229,6 +230,7 @@ static struct shash_alg algs[] = { .cra_name = "crc32c", .cra_driver_name = DRIVER_NAME, .cra_priority = 200, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_alignmask = 3, .cra_ctxsize = sizeof(struct stm32_crc_ctx),
drivers/staging/lustre/lnet/libcfs/linux/linux-crypto-adler.c +1 -0
@@ -119,6 +119,7 @@ static struct shash_alg alg = { .cra_name = "adler32", .cra_driver_name = "adler32-zlib", .cra_priority = 100, + .cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE,
include/linux/crypto.h +6 -0
@@ -106,6 +106,12 @@#define CRYPTO_ALG_INTERNAL 0x00002000/* +* Set if the algorithm has a ->setkey() method but can be used without +* calling it first, i.e. there is a default key. +*/ +#define CRYPTO_ALG_OPTIONAL_KEY 0x00004000 + +/* * Transform masks and values (for crt_flags). */ #define CRYPTO_TFM_REQ_MASK 0x000fff00
Greg Kroah-Hartman
maintainerPATCH 119/195 crypto: hash - prevent using keyed hashes without setting key
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9fa68f620041be04720d0cbfb1bd3ddfc6310b24 upstream.
Currently, almost none of the keyed hash algorithms check whether a key has been set before proceeding. Some algorithms are okay with this and will effectively just use a key of all 0's or some other bogus default. However, others will severely break, as demonstrated using "hmac(sha3-512-generic)", the unkeyed use of which causes a kernel crash via a (potentially exploitable) stack buffer overflow.
A while ago, this problem was solved for AF_ALG by pairing each hash transform with a 'has_key' bool. However, there are still other places in the kernel where userspace can specify an arbitrary hash algorithm by name, and the kernel uses it as unkeyed hash without checking whether it is really unkeyed. Examples of this include:
- KEYCTL_DH_COMPUTE, via the KDF extension
- dm-verity
- dm-crypt, via the ESSIV support
- dm-integrity, via the "internal hash" mode with no key given
- drbd (Distributed Replicated Block Device)
This bug is especially bad for KEYCTL_DH_COMPUTE as that requires no privileges to call.
Fix the bug for all users by adding a flag CRYPTO_TFM_NEED_KEY to the ->crt_flags of each hash transform that indicates whether the transform still needs to be keyed or not. Then, make the hash init, import, and digest functions return -ENOKEY if the key is still needed.
The new flag also replaces the 'has_key' bool which algif_hash was previously using, thereby simplifying the algif_hash implementation.
--- crypto/ahash.c | 22 ++++++++++++++++---- crypto/algif_hash.c | 52 ++++++++++--------------------------------------- crypto/shash.c | 25 +++++++++++++++++++---- include/crypto/hash.h | 34 ++++++++++++++++++++++---------- include/linux/crypto.h | 2 + 5 files changed, 75 insertions(+), 60 deletions(-)
crypto/ahash.c +17 -5
@@ -193,11 +193,18 @@ int crypto_ahash_setkey(struct crypto_ah unsigned int keylen) {unsigned long alignmask =crypto_ahash_alignmask (tfm); +int err;if ((unsigned long )key & alignmask) -return ahash_setkey_unaligned (tfm, key, keylen); + err =ahash_setkey_unaligned (tfm, key, keylen); +else + err = tfm->setkey (tfm, key, keylen); + +if (err) +return err; -return tfm->setkey (tfm, key, keylen); +crypto_ahash_clear_flags (tfm,CRYPTO_TFM_NEED_KEY ); +return 0 ; }EXPORT_SYMBOL_GPL (crypto_ahash_setkey);
@@ -370,7 +377,12 @@ EXPORT_SYMBOL_GPL(crypto_ahash_finup);int crypto_ahash_digest (struct ahash_request *req) { -return crypto_ahash_op (req,crypto_ahash_reqtfm (req)->digest); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_ahash_op (req, tfm->digest); }EXPORT_SYMBOL_GPL (crypto_ahash_digest);
@@ -456,7 +468,6 @@ static int crypto_ahash_init_tfm(structstruct ahash_alg *alg =crypto_ahash_alg (hash); hash->setkey = ahash_nosetkey; - hash->has_setkey = false; hash->export = ahash_no_export; hash->import = ahash_no_import;
@@ -471,7 +482,8 @@ static int crypto_ahash_init_tfm(structif (alg->setkey) { hash->setkey = alg->setkey; - hash->has_setkey = true; +if (!(alg->halg.base.cra_flags &CRYPTO_ALG_OPTIONAL_KEY )) +crypto_ahash_set_flags (hash,CRYPTO_TFM_NEED_KEY ); }if (alg->export) hash->export = alg->export;
crypto/algif_hash.c +11 -41
104 lines not on this page · raw message
crypto/shash.c +21 -4
@@ -58,11 +58,18 @@ int crypto_shash_setkey(struct crypto_sh {struct shash_alg *shash =crypto_shash_alg (tfm);unsigned long alignmask =crypto_shash_alignmask (tfm); +int err;if ((unsigned long )key & alignmask) -return shash_setkey_unaligned (tfm, key, keylen); + err =shash_setkey_unaligned (tfm, key, keylen); +else + err = shash->setkey (tfm, key, keylen); + +if (err) +return err; -return shash->setkey (tfm, key, keylen); +crypto_shash_clear_flags (tfm,CRYPTO_TFM_NEED_KEY ); +return 0 ; }EXPORT_SYMBOL_GPL (crypto_shash_setkey);
@@ -181,6 +188,9 @@ int crypto_shash_digest(struct shash_desstruct shash_alg *shash =crypto_shash_alg (tfm);unsigned long alignmask =crypto_shash_alignmask (tfm); +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; +if (((unsigned long )data | (unsigned long )out) & alignmask)return shash_digest_unaligned (desc, data, len, out);
@@ -360,7 +370,8 @@ int crypto_init_shash_ops_async(struct c crt->digest = shash_async_digest; crt->setkey = shash_async_setkey; - crt->has_setkey = alg->setkey != shash_no_setkey; +crypto_ahash_set_flags (crt,crypto_shash_get_flags (shash) & +CRYPTO_TFM_NEED_KEY );if (alg->export) crt->export = shash_async_export;
@@ -375,8 +386,14 @@ int crypto_init_shash_ops_async(struct cstatic int crypto_shash_init_tfm (struct crypto_tfm *tfm) {struct crypto_shash *hash =__crypto_shash_cast (tfm); +struct shash_alg *alg =crypto_shash_alg (hash); + + hash->descsize = alg->descsize; + +if (crypto_shash_alg_has_setkey (alg) && + !(alg->base.cra_flags &CRYPTO_ALG_OPTIONAL_KEY )) +crypto_shash_set_flags (hash,CRYPTO_TFM_NEED_KEY ); - hash->descsize =crypto_shash_alg (hash)->descsize;return 0 ; }
include/crypto/hash.h +24 -10
@@ -205,7 +205,6 @@ struct crypto_ahash { unsigned int keylen);unsigned int reqsize; -bool has_setkey;struct crypto_tfm base; };
@@ -405,11 +404,6 @@ static inline void *ahash_request_ctx(stint crypto_ahash_setkey (struct crypto_ahash *tfm,const u8 *key,unsigned int keylen); -static inline bool crypto_ahash_has_setkey (struct crypto_ahash *tfm) -{ -return tfm->has_setkey; -} -/** * crypto_ahash_finup() - update and finalize message digest * @req: reference to the ahash_request handle that holds all information
@@ -481,7 +475,12 @@ static inline int crypto_ahash_export(st*/ static inline int crypto_ahash_import (struct ahash_request *req,const void *in) { -return crypto_ahash_reqtfm (req)->import (req, in); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return tfm->import (req, in); }/**
@@ -498,7 +497,12 @@ static inline int crypto_ahash_import(st*/ static inline int crypto_ahash_init (struct ahash_request *req) { -return crypto_ahash_reqtfm (req)->init (req); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); + +if (crypto_ahash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return tfm->init (req); }/**
@@ -851,7 +855,12 @@ static inline int crypto_shash_export(st*/ static inline int crypto_shash_import (struct shash_desc *desc,const void *in) { -return crypto_shash_alg (desc->tfm)->import (desc, in); +struct crypto_shash *tfm = desc->tfm; + +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_shash_alg (tfm)->import (desc, in); }/**
@@ -867,7 +876,12 @@ static inline int crypto_shash_import(st*/ static inline int crypto_shash_init (struct shash_desc *desc) { -return crypto_shash_alg (desc->tfm)->init (desc); +struct crypto_shash *tfm = desc->tfm; + +if (crypto_shash_get_flags (tfm) &CRYPTO_TFM_NEED_KEY ) +return -ENOKEY ; + +return crypto_shash_alg (tfm)->init (desc); }/**
include/linux/crypto.h +2 -0
@@ -114,6 +114,8 @@/* * Transform masks and values (for crt_flags). */ +#define CRYPTO_TFM_NEED_KEY 0x00000001 +#define CRYPTO_TFM_REQ_MASK 0x000fff00#define CRYPTO_TFM_RES_MASK 0xfff00000
Greg Kroah-Hartman
maintainerPATCH 120/195 media: v4l2-ioctl.c: use check_fmt for enum/g/s/try_fmt
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit b2469c814fbc8f1f19676dd4912717b798df511e upstream.
Don't duplicate the buffer type checks in enum/g/s/try_fmt. The check_fmt function does that already.
It is hard to keep the checks in sync for all these functions and in fact the check for VBI was wrong in the _fmt functions as it allowed SDR types as well. This caused a v4l2-compliance failure for /dev/swradio0 using vivid.
This simplifies the code and keeps the check in one place and fixes the SDR/VBI bug.
--- drivers/media/v4l2-core/v4l2-ioctl.c | 140 +++++++++++++---------------------- 1 file changed, 54 insertions(+), 86 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +54 -86
@@ -1308,52 +1308,50 @@ static int v4l_enum_fmt(const struct v4l struct file *file, void *fh, void *arg) { struct v4l2_fmtdesc *p = arg; -struct video_device *vfd =video_devdata (file); -bool is_vid = vfd->vfl_type ==VFL_TYPE_GRABBER ; -bool is_sdr = vfd->vfl_type ==VFL_TYPE_SDR ; -bool is_tch = vfd->vfl_type ==VFL_TYPE_TOUCH ; -bool is_rx = vfd->vfl_dir !=VFL_DIR_TX ; -bool is_tx = vfd->vfl_dir !=VFL_DIR_RX ; -int ret = -EINVAL ; +int ret =check_fmt (file, p->type); + +if (ret) +return ret; + ret = -EINVAL ;switch (p->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE : -if (unlikely (!is_rx || (!is_vid && !is_tch) || !ops->vidioc_enum_fmt_vid_cap)) +if (unlikely (!ops->vidioc_enum_fmt_vid_cap))break ; ret = ops->vidioc_enum_fmt_vid_cap (file, fh, arg);break ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_cap_mplane)) +if (unlikely (!ops->vidioc_enum_fmt_vid_cap_mplane))break ; ret = ops->vidioc_enum_fmt_vid_cap_mplane (file, fh, arg);break ;case V4L2_BUF_TYPE_VIDEO_OVERLAY : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_overlay)) +if (unlikely (!ops->vidioc_enum_fmt_vid_overlay))break ; ret = ops->vidioc_enum_fmt_vid_overlay (file, fh, arg);break ;case V4L2_BUF_TYPE_VIDEO_OUTPUT : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out)) +if (unlikely (!ops->vidioc_enum_fmt_vid_out))break ; ret = ops->vidioc_enum_fmt_vid_out (file, fh, arg);break ;case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out_mplane)) +if (unlikely (!ops->vidioc_enum_fmt_vid_out_mplane))break ; ret = ops->vidioc_enum_fmt_vid_out_mplane (file, fh, arg);break ;case V4L2_BUF_TYPE_SDR_CAPTURE : -if (unlikely (!is_rx || !is_sdr || !ops->vidioc_enum_fmt_sdr_cap)) +if (unlikely (!ops->vidioc_enum_fmt_sdr_cap))break ; ret = ops->vidioc_enum_fmt_sdr_cap (file, fh, arg);break ;case V4L2_BUF_TYPE_SDR_OUTPUT : -if (unlikely (!is_tx || !is_sdr || !ops->vidioc_enum_fmt_sdr_out)) +if (unlikely (!ops->vidioc_enum_fmt_sdr_out))break ; ret = ops->vidioc_enum_fmt_sdr_out (file, fh, arg);break ;case V4L2_BUF_TYPE_META_CAPTURE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_enum_fmt_meta_cap)) +if (unlikely (!ops->vidioc_enum_fmt_meta_cap))break ; ret = ops->vidioc_enum_fmt_meta_cap (file, fh, arg);break ;
@@ -1367,13 +1365,10 @@ static int v4l_g_fmt(const struct v4l2_i struct file *file, void *fh, void *arg) { struct v4l2_format *p = arg; -struct video_device *vfd =video_devdata (file); -bool is_vid = vfd->vfl_type ==VFL_TYPE_GRABBER ; -bool is_sdr = vfd->vfl_type ==VFL_TYPE_SDR ; -bool is_tch = vfd->vfl_type ==VFL_TYPE_TOUCH ; -bool is_rx = vfd->vfl_dir !=VFL_DIR_TX ; -bool is_tx = vfd->vfl_dir !=VFL_DIR_RX ; -int ret; +int ret =check_fmt (file, p->type); + +if (ret) +return ret;/* * fmt can't be cleared for these overlay types due to the 'clips'
@@ -1401,7 +1396,7 @@ static int v4l_g_fmt(const struct v4l2_iswitch (p->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE : -if (unlikely (!is_rx || (!is_vid && !is_tch) || !ops->vidioc_g_fmt_vid_cap)) +if (unlikely (!ops->vidioc_g_fmt_vid_cap))break ; p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ; ret = ops->vidioc_g_fmt_vid_cap (file, fh, arg);
@@ -1409,23 +1404,15 @@ static int v4l_g_fmt(const struct v4l2_i p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ;return ret;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap_mplane)) -break ;return ops->vidioc_g_fmt_vid_cap_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OVERLAY : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_overlay)) -break ;return ops->vidioc_g_fmt_vid_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_g_fmt_vbi_cap)) -break ;return ops->vidioc_g_fmt_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_cap)) -break ;return ops->vidioc_g_fmt_sliced_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out)) +if (unlikely (!ops->vidioc_g_fmt_vid_out))break ; p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ; ret = ops->vidioc_g_fmt_vid_out (file, fh, arg);
@@ -1433,32 +1420,18 @@ static int v4l_g_fmt(const struct v4l2_i p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ;return ret;case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_mplane)) -break ;return ops->vidioc_g_fmt_vid_out_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_overlay)) -break ;return ops->vidioc_g_fmt_vid_out_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_g_fmt_vbi_out)) -break ;return ops->vidioc_g_fmt_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_out)) -break ;return ops->vidioc_g_fmt_sliced_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SDR_CAPTURE : -if (unlikely (!is_rx || !is_sdr || !ops->vidioc_g_fmt_sdr_cap)) -break ;return ops->vidioc_g_fmt_sdr_cap (file, fh, arg);case V4L2_BUF_TYPE_SDR_OUTPUT : -if (unlikely (!is_tx || !is_sdr || !ops->vidioc_g_fmt_sdr_out)) -break ;return ops->vidioc_g_fmt_sdr_out (file, fh, arg);case V4L2_BUF_TYPE_META_CAPTURE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_g_fmt_meta_cap)) -break ;return ops->vidioc_g_fmt_meta_cap (file, fh, arg); }return -EINVAL ;
@@ -1484,12 +1457,10 @@ static int v4l_s_fmt(const struct v4l2_i {struct v4l2_format *p = arg;struct video_device *vfd =video_devdata (file); -bool is_vid = vfd->vfl_type ==VFL_TYPE_GRABBER ; -bool is_sdr = vfd->vfl_type ==VFL_TYPE_SDR ; -bool is_tch = vfd->vfl_type ==VFL_TYPE_TOUCH ; -bool is_rx = vfd->vfl_dir !=VFL_DIR_TX ; -bool is_tx = vfd->vfl_dir !=VFL_DIR_RX ; -int ret; +int ret =check_fmt (file, p->type); + +if (ret) +return ret; ret =v4l_enable_media_source (vfd);if (ret)
@@ -1498,37 +1469,37 @@ static int v4l_s_fmt(const struct v4l2_iswitch (p->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE : -if (unlikely (!is_rx || (!is_vid && !is_tch) || !ops->vidioc_s_fmt_vid_cap)) +if (unlikely (!ops->vidioc_s_fmt_vid_cap))break ;CLEAR_AFTER_FIELD (p, fmt.pix); ret = ops->vidioc_s_fmt_vid_cap (file, fh, arg);/* just in case the driver zeroed it again */ p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ; -if (is_tch) +if (vfd->vfl_type ==VFL_TYPE_TOUCH )v4l_pix_format_touch (&p->fmt.pix);return ret;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap_mplane)) +if (unlikely (!ops->vidioc_s_fmt_vid_cap_mplane))break ;CLEAR_AFTER_FIELD (p, fmt.pix_mp.xfer_func);return ops->vidioc_s_fmt_vid_cap_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OVERLAY : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_overlay)) +if (unlikely (!ops->vidioc_s_fmt_vid_overlay))break ;CLEAR_AFTER_FIELD (p, fmt.win);return ops->vidioc_s_fmt_vid_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_s_fmt_vbi_cap)) +if (unlikely (!ops->vidioc_s_fmt_vbi_cap))break ;CLEAR_AFTER_FIELD (p, fmt.vbi);return ops->vidioc_s_fmt_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_cap)) +if (unlikely (!ops->vidioc_s_fmt_sliced_vbi_cap))break ;CLEAR_AFTER_FIELD (p, fmt.sliced);return ops->vidioc_s_fmt_sliced_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out)) +if (unlikely (!ops->vidioc_s_fmt_vid_out))break ;CLEAR_AFTER_FIELD (p, fmt.pix); ret = ops->vidioc_s_fmt_vid_out (file, fh, arg);
@@ -1536,37 +1507,37 @@ static int v4l_s_fmt(const struct v4l2_i p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ;return ret;case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_mplane)) +if (unlikely (!ops->vidioc_s_fmt_vid_out_mplane))break ;CLEAR_AFTER_FIELD (p, fmt.pix_mp.xfer_func);return ops->vidioc_s_fmt_vid_out_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_overlay)) +if (unlikely (!ops->vidioc_s_fmt_vid_out_overlay))break ;CLEAR_AFTER_FIELD (p, fmt.win);return ops->vidioc_s_fmt_vid_out_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_s_fmt_vbi_out)) +if (unlikely (!ops->vidioc_s_fmt_vbi_out))break ;CLEAR_AFTER_FIELD (p, fmt.vbi);return ops->vidioc_s_fmt_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_out)) +if (unlikely (!ops->vidioc_s_fmt_sliced_vbi_out))break ;CLEAR_AFTER_FIELD (p, fmt.sliced);return ops->vidioc_s_fmt_sliced_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SDR_CAPTURE : -if (unlikely (!is_rx || !is_sdr || !ops->vidioc_s_fmt_sdr_cap)) +if (unlikely (!ops->vidioc_s_fmt_sdr_cap))break ;CLEAR_AFTER_FIELD (p, fmt.sdr);return ops->vidioc_s_fmt_sdr_cap (file, fh, arg);case V4L2_BUF_TYPE_SDR_OUTPUT : -if (unlikely (!is_tx || !is_sdr || !ops->vidioc_s_fmt_sdr_out)) +if (unlikely (!ops->vidioc_s_fmt_sdr_out))break ;CLEAR_AFTER_FIELD (p, fmt.sdr);return ops->vidioc_s_fmt_sdr_out (file, fh, arg);case V4L2_BUF_TYPE_META_CAPTURE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_s_fmt_meta_cap)) +if (unlikely (!ops->vidioc_s_fmt_meta_cap))break ;CLEAR_AFTER_FIELD (p, fmt.meta);return ops->vidioc_s_fmt_meta_cap (file, fh, arg);
@@ -1578,19 +1549,16 @@ static int v4l_try_fmt(const struct v4l2 struct file *file, void *fh, void *arg) { struct v4l2_format *p = arg; -struct video_device *vfd =video_devdata (file); -bool is_vid = vfd->vfl_type ==VFL_TYPE_GRABBER ; -bool is_sdr = vfd->vfl_type ==VFL_TYPE_SDR ; -bool is_tch = vfd->vfl_type ==VFL_TYPE_TOUCH ; -bool is_rx = vfd->vfl_dir !=VFL_DIR_TX ; -bool is_tx = vfd->vfl_dir !=VFL_DIR_RX ; -int ret; +int ret =check_fmt (file, p->type); + +if (ret) +return ret;v4l_sanitize_format (p);switch (p->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE : -if (unlikely (!is_rx || (!is_vid && !is_tch) || !ops->vidioc_try_fmt_vid_cap)) +if (unlikely (!ops->vidioc_try_fmt_vid_cap))break ;CLEAR_AFTER_FIELD (p, fmt.pix); ret = ops->vidioc_try_fmt_vid_cap (file, fh, arg);
@@ -1598,27 +1566,27 @@ static int v4l_try_fmt(const struct v4l2 p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ;return ret;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap_mplane)) +if (unlikely (!ops->vidioc_try_fmt_vid_cap_mplane))break ;CLEAR_AFTER_FIELD (p, fmt.pix_mp.xfer_func);return ops->vidioc_try_fmt_vid_cap_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OVERLAY : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_overlay)) +if (unlikely (!ops->vidioc_try_fmt_vid_overlay))break ;CLEAR_AFTER_FIELD (p, fmt.win);return ops->vidioc_try_fmt_vid_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_try_fmt_vbi_cap)) +if (unlikely (!ops->vidioc_try_fmt_vbi_cap))break ;CLEAR_AFTER_FIELD (p, fmt.vbi);return ops->vidioc_try_fmt_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE : -if (unlikely (!is_rx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_cap)) +if (unlikely (!ops->vidioc_try_fmt_sliced_vbi_cap))break ;CLEAR_AFTER_FIELD (p, fmt.sliced);return ops->vidioc_try_fmt_sliced_vbi_cap (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out)) +if (unlikely (!ops->vidioc_try_fmt_vid_out))break ;CLEAR_AFTER_FIELD (p, fmt.pix); ret = ops->vidioc_try_fmt_vid_out (file, fh, arg);
@@ -1626,37 +1594,37 @@ static int v4l_try_fmt(const struct v4l2 p->fmt.pix.priv =V4L2_PIX_FMT_PRIV_MAGIC ;return ret;case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_mplane)) +if (unlikely (!ops->vidioc_try_fmt_vid_out_mplane))break ;CLEAR_AFTER_FIELD (p, fmt.pix_mp.xfer_func);return ops->vidioc_try_fmt_vid_out_mplane (file, fh, arg);case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY : -if (unlikely (!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_overlay)) +if (unlikely (!ops->vidioc_try_fmt_vid_out_overlay))break ;CLEAR_AFTER_FIELD (p, fmt.win);return ops->vidioc_try_fmt_vid_out_overlay (file, fh, arg);case V4L2_BUF_TYPE_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_try_fmt_vbi_out)) +if (unlikely (!ops->vidioc_try_fmt_vbi_out))break ;CLEAR_AFTER_FIELD (p, fmt.vbi);return ops->vidioc_try_fmt_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -if (unlikely (!is_tx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_out)) +if (unlikely (!ops->vidioc_try_fmt_sliced_vbi_out))break ;CLEAR_AFTER_FIELD (p, fmt.sliced);return ops->vidioc_try_fmt_sliced_vbi_out (file, fh, arg);case V4L2_BUF_TYPE_SDR_CAPTURE : -if (unlikely (!is_rx || !is_sdr || !ops->vidioc_try_fmt_sdr_cap)) +if (unlikely (!ops->vidioc_try_fmt_sdr_cap))break ;CLEAR_AFTER_FIELD (p, fmt.sdr);return ops->vidioc_try_fmt_sdr_cap (file, fh, arg);case V4L2_BUF_TYPE_SDR_OUTPUT : -if (unlikely (!is_tx || !is_sdr || !ops->vidioc_try_fmt_sdr_out)) +if (unlikely (!ops->vidioc_try_fmt_sdr_out))break ;CLEAR_AFTER_FIELD (p, fmt.sdr);return ops->vidioc_try_fmt_sdr_out (file, fh, arg);case V4L2_BUF_TYPE_META_CAPTURE : -if (unlikely (!is_rx || !is_vid || !ops->vidioc_try_fmt_meta_cap)) +if (unlikely (!ops->vidioc_try_fmt_meta_cap))break ;CLEAR_AFTER_FIELD (p, fmt.meta);return ops->vidioc_try_fmt_meta_cap (file, fh, arg);
Greg Kroah-Hartman
maintainerPATCH 121/195 media: v4l2-ioctl.c: dont copy back the result for -ENOTTY
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 181a4a2d5a0a7b43cab08a70710d727e7764ccdd upstream.
If the ioctl returned -ENOTTY, then don't bother copying back the result as there is no point.
--- drivers/media/v4l2-core/v4l2-ioctl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ioctl.c +4 -1
@@ -2892,8 +2892,11 @@ video_usercopy(struct file *file, unsign/* Handles IOCTL */ err =func (file, cmd, parg); -if (err == -ENOIOCTLCMD ) +if (err == -ENOTTY || err == -ENOIOCTLCMD ) { err = -ENOTTY ; + goto out; + } +if (err ==0 ) {if (cmd ==VIDIOC_DQBUF )trace_v4l2_dqbuf (video_devdata (file)->minor, parg);
Greg Kroah-Hartman
maintainerPATCH 122/195 media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 3ee6d040719ae09110e5cdf24d5386abe5d1b776 upstream.
The result of the VIDIOC_PREPARE_BUF ioctl was never copied back to userspace since it was missing in the switch.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +1 -0
@@ -1052,6 +1052,7 @@ static long do_video_ioctl(struct file * err =put_v4l2_create32 (&karg.v2crt, up);break ; +case VIDIOC_PREPARE_BUF :case VIDIOC_QUERYBUF :case VIDIOC_QBUF :case VIDIOC_DQBUF :
Greg Kroah-Hartman
maintainerPATCH 123/195 media: v4l2-compat-ioctl32.c: fix the indentation
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit b7b957d429f601d6d1942122b339474f31191d75 upstream.
The indentation of this source is all over the place. Fix this. This patch only changes whitespace.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 212 +++++++++++++------------- 1 file changed, 107 insertions(+), 105 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +107 -105
@@ -49,12 +49,12 @@ struct v4l2_window32 {static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) {if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_window32 )) || -copy_from_user (&kp->w, &up->w,sizeof (up->w)) || -get_user (kp->field, &up->field) || -get_user (kp->chromakey, &up->chromakey) || -get_user (kp->clipcount, &up->clipcount) || -get_user (kp->global_alpha, &up->global_alpha)) -return -EFAULT ; +copy_from_user (&kp->w, &up->w,sizeof (up->w)) || +get_user (kp->field, &up->field) || +get_user (kp->chromakey, &up->chromakey) || +get_user (kp->clipcount, &up->clipcount) || +get_user (kp->global_alpha, &up->global_alpha)) +return -EFAULT ;if (kp->clipcount >2048 )return -EINVAL ;if (kp->clipcount) {
@@ -84,11 +84,11 @@ static int get_v4l2_window32(struct v4l2static int put_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) {if (copy_to_user (&up->w, &kp->w,sizeof (kp->w)) || -put_user (kp->field, &up->field) || -put_user (kp->chromakey, &up->chromakey) || -put_user (kp->clipcount, &up->clipcount) || -put_user (kp->global_alpha, &up->global_alpha)) -return -EFAULT ; +put_user (kp->field, &up->field) || +put_user (kp->chromakey, &up->chromakey) || +put_user (kp->clipcount, &up->clipcount) || +put_user (kp->global_alpha, &up->global_alpha)) +return -EFAULT ;return 0 ; }
@@ -100,7 +100,7 @@ static inline int get_v4l2_pix_format(st }static inline int get_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) +struct v4l2_pix_format_mplane __user *up) {if (copy_from_user (kp, up,sizeof (struct v4l2_pix_format_mplane )))return -EFAULT ;
@@ -115,7 +115,7 @@ static inline int put_v4l2_pix_format(st }static inline int put_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) +struct v4l2_pix_format_mplane __user *up) {if (copy_to_user (up, kp,sizeof (struct v4l2_pix_format_mplane )))return -EFAULT ;
@@ -238,7 +238,7 @@ static int __get_v4l2_format32(struct v4return get_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta);default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type); + kp->type);return -EINVAL ; } }
@@ -287,7 +287,7 @@ static int __put_v4l2_format32(struct v4return put_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta);default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type); + kp->type);return -EINVAL ; } }
@@ -321,7 +321,7 @@ static int get_v4l2_standard32(struct v4 {/* other fields are not set by the user, nor used by the driver */ if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_standard32 )) || -get_user (kp->index, &up->index)) +get_user (kp->index, &up->index))return -EFAULT ;return 0 ; }
@@ -329,13 +329,14 @@ static int get_v4l2_standard32(struct v4static int put_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_standard32 )) || -put_user (kp->index, &up->index) || -put_user (kp->id, &up->id) || -copy_to_user (up->name, kp->name,24 ) || -copy_to_user (&up->frameperiod, &kp->frameperiod,sizeof (kp->frameperiod)) || -put_user (kp->framelines, &up->framelines) || -copy_to_user (up->reserved, kp->reserved,4 *sizeof (__u32))) -return -EFAULT ; +put_user (kp->index, &up->index) || +put_user (kp->id, &up->id) || +copy_to_user (up->name, kp->name,24 ) || +copy_to_user (&up->frameperiod, &kp->frameperiod, +sizeof (kp->frameperiod)) || +put_user (kp->framelines, &up->framelines) || +copy_to_user (up->reserved, kp->reserved,4 *sizeof (__u32))) +return -EFAULT ;return 0 ; }
@@ -375,14 +376,14 @@ struct v4l2_buffer32 { };static int get_v4l2_plane32 (struct v4l2_plane __user *up,struct v4l2_plane32 __user *up32, -enum v4l2_memory memory) +enum v4l2_memory memory) {void __user *up_pln;compat_long_t p;if (copy_in_user (up, up32,2 *sizeof (__u32)) || -copy_in_user (&up->data_offset, &up32->data_offset, -sizeof (__u32))) +copy_in_user (&up->data_offset, &up32->data_offset, +sizeof (__u32)))return -EFAULT ;if (memory ==V4L2_MEMORY_USERPTR ) {
@@ -396,7 +397,7 @@ static int get_v4l2_plane32(struct v4l2_return -EFAULT ; }else {if (copy_in_user (&up->m.mem_offset, &up32->m.mem_offset, -sizeof (__u32))) +sizeof (__u32)))return -EFAULT ; }
@@ -404,23 +405,23 @@ static int get_v4l2_plane32(struct v4l2_ }static int put_v4l2_plane32 (struct v4l2_plane __user *up,struct v4l2_plane32 __user *up32, -enum v4l2_memory memory) +enum v4l2_memory memory) {if (copy_in_user (up32, up,2 *sizeof (__u32)) || -copy_in_user (&up32->data_offset, &up->data_offset, -sizeof (__u32))) +copy_in_user (&up32->data_offset, &up->data_offset, +sizeof (__u32)))return -EFAULT ;/* For MMAP, driver might've set up the offset, so copy it back. * USERPTR stays the same (was userspace-provided), so no copying. */ if (memory ==V4L2_MEMORY_MMAP )if (copy_in_user (&up32->m.mem_offset, &up->m.mem_offset, -sizeof (__u32))) +sizeof (__u32)))return -EFAULT ;/* For DMABUF, driver might've set up the fd, so copy it back. */ if (memory ==V4L2_MEMORY_DMABUF )if (copy_in_user (&up32->m.fd, &up->m.fd, -sizeof (int ))) +sizeof (int )))return -EFAULT ;return 0 ;
@@ -434,19 +435,19 @@ static int get_v4l2_buffer32(struct v4l2int ret;if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_buffer32 )) || -get_user (kp->index, &up->index) || -get_user (kp->type, &up->type) || -get_user (kp->flags, &up->flags) || -get_user (kp->memory, &up->memory) || -get_user (kp->length, &up->length)) -return -EFAULT ; +get_user (kp->index, &up->index) || +get_user (kp->type, &up->type) || +get_user (kp->flags, &up->flags) || +get_user (kp->memory, &up->memory) || +get_user (kp->length, &up->length)) +return -EFAULT ;if (V4L2_TYPE_IS_OUTPUT (kp->type))if (get_user (kp->bytesused, &up->bytesused) || -get_user (kp->field, &up->field) || -get_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -get_user (kp->timestamp.tv_usec, - &up->timestamp.tv_usec)) +get_user (kp->field, &up->field) || +get_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || +get_user (kp->timestamp.tv_usec, + &up->timestamp.tv_usec))return -EFAULT ;if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) {
@@ -466,7 +467,7 @@ static int get_v4l2_buffer32(struct v4l2 uplane32 =compat_ptr (p);if (!access_ok (VERIFY_READ , uplane32, - kp->length *sizeof (struct v4l2_plane32 ))) + kp->length *sizeof (struct v4l2_plane32 )))return -EFAULT ;/* We don't really care if userspace decides to kill itself
@@ -490,12 +491,12 @@ static int get_v4l2_buffer32(struct v4l2break ;case V4L2_MEMORY_USERPTR : { -compat_long_t tmp; +compat_long_t tmp; -if (get_user (tmp, &up->m.userptr)) -return -EFAULT ; +if (get_user (tmp, &up->m.userptr)) +return -EFAULT ; - kp->m.userptr = (unsigned long )compat_ptr (tmp); + kp->m.userptr = (unsigned long )compat_ptr (tmp); }break ;case V4L2_MEMORY_OVERLAY :
@@ -521,22 +522,23 @@ static int put_v4l2_buffer32(struct v4l2int ret;if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_buffer32 )) || -put_user (kp->index, &up->index) || -put_user (kp->type, &up->type) || -put_user (kp->flags, &up->flags) || -put_user (kp->memory, &up->memory)) -return -EFAULT ; +put_user (kp->index, &up->index) || +put_user (kp->type, &up->type) || +put_user (kp->flags, &up->flags) || +put_user (kp->memory, &up->memory)) +return -EFAULT ;if (put_user (kp->bytesused, &up->bytesused) || -put_user (kp->field, &up->field) || -put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -put_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec) || -copy_to_user (&up->timecode, &kp->timecode,sizeof (struct v4l2_timecode )) || -put_user (kp->sequence, &up->sequence) || -put_user (kp->reserved2, &up->reserved2) || -put_user (kp->reserved, &up->reserved) || -put_user (kp->length, &up->length)) -return -EFAULT ; +put_user (kp->field, &up->field) || +put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || +put_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec) || +copy_to_user (&up->timecode, &kp->timecode, +sizeof (struct v4l2_timecode )) || +put_user (kp->sequence, &up->sequence) || +put_user (kp->reserved2, &up->reserved2) || +put_user (kp->reserved, &up->reserved) || +put_user (kp->length, &up->length)) +return -EFAULT ;if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) { num_planes = kp->length;
@@ -600,11 +602,11 @@ static int get_v4l2_framebuffer32(structu32 tmp;if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_framebuffer32 )) || -get_user (tmp, &up->base) || -get_user (kp->capability, &up->capability) || -get_user (kp->flags, &up->flags) || -copy_from_user (&kp->fmt, &up->fmt,sizeof (up->fmt))) -return -EFAULT ; +get_user (tmp, &up->base) || +get_user (kp->capability, &up->capability) || +get_user (kp->flags, &up->flags) || +copy_from_user (&kp->fmt, &up->fmt,sizeof (up->fmt))) +return -EFAULT ; kp->base = (__force void *)compat_ptr (tmp);return 0 ; }
@@ -614,11 +616,11 @@ static int put_v4l2_framebuffer32(structu32 tmp = (u32)((unsigned long )kp->base);if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_framebuffer32 )) || -put_user (tmp, &up->base) || -put_user (kp->capability, &up->capability) || -put_user (kp->flags, &up->flags) || -copy_to_user (&up->fmt, &kp->fmt,sizeof (up->fmt))) -return -EFAULT ; +put_user (tmp, &up->base) || +put_user (kp->capability, &up->capability) || +put_user (kp->flags, &up->flags) || +copy_to_user (&up->fmt, &kp->fmt,sizeof (up->fmt))) +return -EFAULT ;return 0 ; }
@@ -694,12 +696,12 @@ static int get_v4l2_ext_controls32(struccompat_caddr_t p;if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_ext_controls32 )) || -get_user (kp->which, &up->which) || -get_user (kp->count, &up->count) || -get_user (kp->error_idx, &up->error_idx) || -copy_from_user (kp->reserved, up->reserved, -sizeof (kp->reserved))) -return -EFAULT ; +get_user (kp->which, &up->which) || +get_user (kp->count, &up->count) || +get_user (kp->error_idx, &up->error_idx) || +copy_from_user (kp->reserved, up->reserved, +sizeof (kp->reserved))) +return -EFAULT ;if (kp->count ==0 ) { kp->controls =NULL ;return 0 ;
@@ -710,7 +712,7 @@ static int get_v4l2_ext_controls32(strucreturn -EFAULT ; ucontrols =compat_ptr (p);if (!access_ok (VERIFY_READ , ucontrols, - kp->count *sizeof (struct v4l2_ext_control32 ))) + kp->count *sizeof (struct v4l2_ext_control32 )))return -EFAULT ; kcontrols =compat_alloc_user_space (kp->count *sizeof (struct v4l2_ext_control ));
@@ -746,11 +748,11 @@ static int put_v4l2_ext_controls32(struccompat_caddr_t p;if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_ext_controls32 )) || -put_user (kp->which, &up->which) || -put_user (kp->count, &up->count) || -put_user (kp->error_idx, &up->error_idx) || -copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) -return -EFAULT ; +put_user (kp->which, &up->which) || +put_user (kp->count, &up->count) || +put_user (kp->error_idx, &up->error_idx) || +copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) +return -EFAULT ;if (!kp->count)return 0 ;
@@ -758,7 +760,7 @@ static int put_v4l2_ext_controls32(strucreturn -EFAULT ; ucontrols =compat_ptr (p);if (!access_ok (VERIFY_WRITE , ucontrols, - n *sizeof (struct v4l2_ext_control32 ))) + n *sizeof (struct v4l2_ext_control32 )))return -EFAULT ;while (--n >=0 ) {
@@ -796,15 +798,15 @@ struct v4l2_event32 {static int put_v4l2_event32 (struct v4l2_event *kp,struct v4l2_event32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_event32 )) || -put_user (kp->type, &up->type) || -copy_to_user (&up->u, &kp->u,sizeof (kp->u)) || -put_user (kp->pending, &up->pending) || -put_user (kp->sequence, &up->sequence) || -put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -put_user (kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) || -put_user (kp->id, &up->id) || -copy_to_user (up->reserved, kp->reserved,8 *sizeof (__u32))) -return -EFAULT ; +put_user (kp->type, &up->type) || +copy_to_user (&up->u, &kp->u,sizeof (kp->u)) || +put_user (kp->pending, &up->pending) || +put_user (kp->sequence, &up->sequence) || +put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || +put_user (kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) || +put_user (kp->id, &up->id) || +copy_to_user (up->reserved, kp->reserved,8 *sizeof (__u32))) +return -EFAULT ;return 0 ; }
@@ -821,12 +823,12 @@ static int get_v4l2_edid32(struct v4l2_eu32 tmp;if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_edid32 )) || -get_user (kp->pad, &up->pad) || -get_user (kp->start_block, &up->start_block) || -get_user (kp->blocks, &up->blocks) || -get_user (tmp, &up->edid) || -copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved))) -return -EFAULT ; +get_user (kp->pad, &up->pad) || +get_user (kp->start_block, &up->start_block) || +get_user (kp->blocks, &up->blocks) || +get_user (tmp, &up->edid) || +copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved))) +return -EFAULT ; kp->edid = (__force u8 *)compat_ptr (tmp);return 0 ; }
@@ -836,12 +838,12 @@ static int put_v4l2_edid32(struct v4l2_eu32 tmp = (u32)((unsigned long )kp->edid);if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_edid32 )) || -put_user (kp->pad, &up->pad) || -put_user (kp->start_block, &up->start_block) || -put_user (kp->blocks, &up->blocks) || -put_user (tmp, &up->edid) || -copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) -return -EFAULT ; +put_user (kp->pad, &up->pad) || +put_user (kp->start_block, &up->start_block) || +put_user (kp->blocks, &up->blocks) || +put_user (tmp, &up->edid) || +copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) +return -EFAULT ;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 124/195 media: v4l2-compat-ioctl32.c: move helper functions to __get/put_v4l2_format32
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 486c521510c44a04cd756a9267e7d1e271c8a4ba upstream.
These helper functions do not really help. Move the code to the __get/put_v4l2_format32 functions.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 124 +++++--------------------- 1 file changed, 24 insertions(+), 100 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +24 -100
@@ -92,92 +92,6 @@ static int put_v4l2_window32(struct v4l2return 0 ; } -static inline int get_v4l2_pix_format (struct v4l2_pix_format *kp,struct v4l2_pix_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_pix_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_pix_format_mplane ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_pix_format (struct v4l2_pix_format *kp,struct v4l2_pix_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_pix_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_pix_format_mplane ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_vbi_format (struct v4l2_vbi_format *kp,struct v4l2_vbi_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_vbi_format (struct v4l2_vbi_format *kp,struct v4l2_vbi_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_sliced_vbi_format (struct v4l2_sliced_vbi_format *kp,struct v4l2_sliced_vbi_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_sliced_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_sliced_vbi_format (struct v4l2_sliced_vbi_format *kp,struct v4l2_sliced_vbi_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_sliced_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_sdr_format (struct v4l2_sdr_format *kp,struct v4l2_sdr_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_sdr_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_sdr_format (struct v4l2_sdr_format *kp,struct v4l2_sdr_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_sdr_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_meta_format (struct v4l2_meta_format *kp,struct v4l2_meta_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_meta_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_meta_format (struct v4l2_meta_format *kp,struct v4l2_meta_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_meta_format ))) -return -EFAULT ; -return 0 ; -} -struct v4l2_format32 {__u32 type;/* enum v4l2_buf_type */ union {
@@ -217,25 +131,30 @@ static int __get_v4l2_format32(struct v4switch (kp->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return get_v4l2_pix_format (&kp->fmt.pix, &up->fmt.pix); +return copy_from_user (&kp->fmt.pix, &up->fmt.pix, +sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return get_v4l2_pix_format_mplane (&kp->fmt.pix_mp, - &up->fmt.pix_mp); +return copy_from_user (&kp->fmt.pix_mp, &up->fmt.pix_mp, +sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY :return get_v4l2_window32 (&kp->fmt.win, &up->fmt.win);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return get_v4l2_vbi_format (&kp->fmt.vbi, &up->fmt.vbi); +return copy_from_user (&kp->fmt.vbi, &up->fmt.vbi, +sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return get_v4l2_sliced_vbi_format (&kp->fmt.sliced, &up->fmt.sliced); +return copy_from_user (&kp->fmt.sliced, &up->fmt.sliced, +sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return get_v4l2_sdr_format (&kp->fmt.sdr, &up->fmt.sdr); +return copy_from_user (&kp->fmt.sdr, &up->fmt.sdr, +sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return get_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta); +return copy_from_user (&kp->fmt.meta, &up->fmt.meta, +sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , kp->type);
@@ -266,25 +185,30 @@ static int __put_v4l2_format32(struct v4switch (kp->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return put_v4l2_pix_format (&kp->fmt.pix, &up->fmt.pix); +return copy_to_user (&up->fmt.pix, &kp->fmt.pix, +sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return put_v4l2_pix_format_mplane (&kp->fmt.pix_mp, - &up->fmt.pix_mp); +return copy_to_user (&up->fmt.pix_mp, &kp->fmt.pix_mp, +sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY :return put_v4l2_window32 (&kp->fmt.win, &up->fmt.win);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return put_v4l2_vbi_format (&kp->fmt.vbi, &up->fmt.vbi); +return copy_to_user (&up->fmt.vbi, &kp->fmt.vbi, +sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return put_v4l2_sliced_vbi_format (&kp->fmt.sliced, &up->fmt.sliced); +return copy_to_user (&up->fmt.sliced, &kp->fmt.sliced, +sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return put_v4l2_sdr_format (&kp->fmt.sdr, &up->fmt.sdr); +return copy_to_user (&up->fmt.sdr, &kp->fmt.sdr, +sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return put_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta); +return copy_to_user (&up->fmt.meta, &kp->fmt.meta, +sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , kp->type);
Greg Kroah-Hartman
maintainerPATCH 125/195 media: v4l2-compat-ioctl32.c: avoid sizeof(type)
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 333b1e9f96ce05f7498b581509bb30cde03018bf upstream.
Instead of doing sizeof(struct foo) use sizeof(*up). There even were cases where 4 * sizeof(__u32) was used instead of sizeof(kp->reserved), which is very dangerous when the size of the reserved array changes.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 79 +++++++++++--------------- 1 file changed, 36 insertions(+), 43 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +36 -43
@@ -48,7 +48,7 @@ struct v4l2_window32 {static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || copy_from_user(&kp->w, &up->w, sizeof(up->w)) || get_user(kp->field, &up->field) || get_user(kp->chromakey, &up->chromakey) ||
@@ -66,7 +66,7 @@ static int get_v4l2_window32(struct v4l2if (get_user (p, &up->clips))return -EFAULT ; uclips =compat_ptr (p); - kclips =compat_alloc_user_space (n *sizeof (struct v4l2_clip )); + kclips =compat_alloc_user_space (n *sizeof (*kclips)); kp->clips = kclips;while (--n >=0 ) {if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c)))
@@ -164,14 +164,14 @@ static int __get_v4l2_format32(struct v4static int get_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) { -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_format32 ))) +if (!access_ok (VERIFY_READ , up,sizeof (*up)))return -EFAULT ;return __get_v4l2_format32 (kp, up); }static int get_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) { -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_create_buffers32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||copy_from_user (kp, up, offsetof(struct v4l2_create_buffers32 , format)))return -EFAULT ;return __get_v4l2_format32 (&kp->format, &up->format);
@@ -218,14 +218,14 @@ static int __put_v4l2_format32(struct v4static int put_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_format32 ))) +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)))return -EFAULT ;return __put_v4l2_format32 (kp, up); }static int put_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_create_buffers32 )) || +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) ||copy_to_user (up, kp, offsetof(struct v4l2_create_buffers32 , format)) ||copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved)))return -EFAULT ;
@@ -244,7 +244,7 @@ struct v4l2_standard32 {static int get_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) {/* other fields are not set by the user, nor used by the driver */ -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_standard32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||get_user (kp->index, &up->index))return -EFAULT ;return 0 ;
@@ -252,14 +252,14 @@ static int get_v4l2_standard32(struct v4static int put_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_standard32 )) || +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) ||put_user (kp->index, &up->index) ||put_user (kp->id, &up->id) || -copy_to_user (up->name, kp->name,24 ) || +copy_to_user (up->name, kp->name,sizeof (up->name)) ||copy_to_user (&up->frameperiod, &kp->frameperiod,sizeof (kp->frameperiod)) ||put_user (kp->framelines, &up->framelines) || -copy_to_user (up->reserved, kp->reserved,4 *sizeof (__u32))) +copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved)))return -EFAULT ;return 0 ; }
@@ -307,7 +307,7 @@ static int get_v4l2_plane32(struct v4l2_if (copy_in_user (up, up32,2 *sizeof (__u32)) ||copy_in_user (&up->data_offset, &up32->data_offset, -sizeof (__u32))) +sizeof (up->data_offset)))return -EFAULT ;if (memory ==V4L2_MEMORY_USERPTR ) {
@@ -317,11 +317,11 @@ static int get_v4l2_plane32(struct v4l2_if (put_user ((unsigned long )up_pln, &up->m.userptr))return -EFAULT ; }else if (memory ==V4L2_MEMORY_DMABUF ) { -if (copy_in_user (&up->m.fd, &up32->m.fd,sizeof (int ))) +if (copy_in_user (&up->m.fd, &up32->m.fd,sizeof (up32->m.fd)))return -EFAULT ; }else {if (copy_in_user (&up->m.mem_offset, &up32->m.mem_offset, -sizeof (__u32))) +sizeof (up32->m.mem_offset)))return -EFAULT ; }
@@ -333,19 +333,19 @@ static int put_v4l2_plane32(struct v4l2_ {if (copy_in_user (up32, up,2 *sizeof (__u32)) ||copy_in_user (&up32->data_offset, &up->data_offset, -sizeof (__u32))) +sizeof (up->data_offset)))return -EFAULT ;/* For MMAP, driver might've set up the offset, so copy it back. * USERPTR stays the same (was userspace-provided), so no copying. */ if (memory ==V4L2_MEMORY_MMAP )if (copy_in_user (&up32->m.mem_offset, &up->m.mem_offset, -sizeof (__u32))) +sizeof (up->m.mem_offset)))return -EFAULT ;/* For DMABUF, driver might've set up the fd, so copy it back. */ if (memory ==V4L2_MEMORY_DMABUF )if (copy_in_user (&up32->m.fd, &up->m.fd, -sizeof (int ))) +sizeof (up->m.fd)))return -EFAULT ;return 0 ;
@@ -358,7 +358,7 @@ static int get_v4l2_buffer32(struct v4l2compat_caddr_t p;int ret; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(kp->index, &up->index) || get_user(kp->type, &up->type) || get_user(kp->flags, &up->flags) ||
@@ -370,8 +370,7 @@ static int get_v4l2_buffer32(struct v4l2if (get_user (kp->bytesused, &up->bytesused) ||get_user (kp->field, &up->field) ||get_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -get_user (kp->timestamp.tv_usec, - &up->timestamp.tv_usec)) +get_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec))return -EFAULT ;if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) {
@@ -391,13 +390,12 @@ static int get_v4l2_buffer32(struct v4l2 uplane32 =compat_ptr (p);if (!access_ok (VERIFY_READ , uplane32, - kp->length *sizeof (struct v4l2_plane32 ))) + kp->length *sizeof (*uplane32)))return -EFAULT ;/* We don't really care if userspace decides to kill itself * by passing a very big num_planes value */ - uplane =compat_alloc_user_space (kp->length * -sizeof (struct v4l2_plane )); + uplane =compat_alloc_user_space (kp->length *sizeof (*uplane)); kp->m.planes = (__force struct v4l2_plane *)uplane;for (num_planes =0 ; num_planes < kp->length; num_planes++) {
@@ -445,7 +443,7 @@ static int put_v4l2_buffer32(struct v4l2int num_planes;int ret; - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->index, &up->index) || put_user(kp->type, &up->type) || put_user(kp->flags, &up->flags) ||
@@ -456,8 +454,7 @@ static int put_v4l2_buffer32(struct v4l2put_user (kp->field, &up->field) ||put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||put_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec) || -copy_to_user (&up->timecode, &kp->timecode, -sizeof (struct v4l2_timecode )) || +copy_to_user (&up->timecode, &kp->timecode,sizeof (kp->timecode)) ||put_user (kp->sequence, &up->sequence) ||put_user (kp->reserved2, &up->reserved2) || put_user(kp->reserved, &up->reserved) ||
@@ -525,7 +522,7 @@ static int get_v4l2_framebuffer32(struct {u32 tmp; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(tmp, &up->base) || get_user(kp->capability, &up->capability) || get_user(kp->flags, &up->flags) ||
@@ -539,7 +536,7 @@ static int put_v4l2_framebuffer32(struct {u32 tmp = (u32)((unsigned long )kp->base); - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(tmp, &up->base) || put_user(kp->capability, &up->capability) || put_user(kp->flags, &up->flags) ||
@@ -564,14 +561,14 @@ struct v4l2_input32 {Otherwise it is identical to the 32-bit version. */ static inline int get_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) { -if (copy_from_user (kp, up,sizeof (struct v4l2_input32 ))) +if (copy_from_user (kp, up,sizeof (*up)))return -EFAULT ;return 0 ; }static inline int put_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) { -if (copy_to_user (up, kp,sizeof (struct v4l2_input32 ))) +if (copy_to_user (up, kp,sizeof (*up)))return -EFAULT ;return 0 ; }
@@ -619,12 +616,11 @@ static int get_v4l2_ext_controls32(strucunsigned int n;compat_caddr_t p; -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_ext_controls32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||get_user (kp->which, &up->which) ||get_user (kp->count, &up->count) ||get_user (kp->error_idx, &up->error_idx) || -copy_from_user (kp->reserved, up->reserved, -sizeof (kp->reserved))) +copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved)))return -EFAULT ;if (kp->count ==0 ) { kp->controls =NULL ;
@@ -635,11 +631,9 @@ static int get_v4l2_ext_controls32(strucif (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_READ , ucontrols, - kp->count *sizeof (struct v4l2_ext_control32 ))) +if (!access_ok (VERIFY_READ , ucontrols, kp->count *sizeof (*ucontrols)))return -EFAULT ; - kcontrols =compat_alloc_user_space (kp->count * -sizeof (struct v4l2_ext_control )); + kcontrols =compat_alloc_user_space (kp->count *sizeof (*kcontrols)); kp->controls = (__force struct v4l2_ext_control *)kcontrols;for (n =0 ; n < kp->count; n++) {u32 id;
@@ -671,7 +665,7 @@ static int put_v4l2_ext_controls32(strucint n = kp->count;compat_caddr_t p; - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->which, &up->which) || put_user(kp->count, &up->count) || put_user(kp->error_idx, &up->error_idx) ||
@@ -683,8 +677,7 @@ static int put_v4l2_ext_controls32(strucif (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_WRITE , ucontrols, - n *sizeof (struct v4l2_ext_control32 ))) +if (!access_ok (VERIFY_WRITE , ucontrols, n *sizeof (*ucontrols)))return -EFAULT ;while (--n >=0 ) {
@@ -721,7 +714,7 @@ struct v4l2_event32 {static int put_v4l2_event32 (struct v4l2_event *kp,struct v4l2_event32 __user *up) { - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_event32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->type, &up->type) || copy_to_user(&up->u, &kp->u, sizeof(kp->u)) || put_user(kp->pending, &up->pending) ||
@@ -729,7 +722,7 @@ static int put_v4l2_event32(struct v4l2_put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||put_user (kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||put_user (kp->id, &up->id) || - copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32))) + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved))) return -EFAULT;return 0 ; }
@@ -746,7 +739,7 @@ static int get_v4l2_edid32(struct v4l2_e {u32 tmp; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_edid32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(kp->pad, &up->pad) || get_user(kp->start_block, &up->start_block) || get_user(kp->blocks, &up->blocks) ||
@@ -761,7 +754,7 @@ static int put_v4l2_edid32(struct v4l2_e {u32 tmp = (u32)((unsigned long )kp->edid); - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_edid32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->pad, &up->pad) || put_user(kp->start_block, &up->start_block) || put_user(kp->blocks, &up->blocks) ||
Greg Kroah-Hartman
maintainerPATCH 127/195 media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit b8c601e8af2d08f733d74defa8465303391bb930 upstream.
ctrl_is_pointer just hardcoded two known string controls, but that caused problems when using e.g. custom controls that use a pointer for the payload.
Reimplement this function: it now finds the v4l2_ctrl (if the driver uses the control framework) or it calls vidioc_query_ext_ctrl (if the driver implements that directly).
In both cases it can now check if the control is a pointer control or not.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 59 +++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +39 -20
@@ -18,6 +18,8 @@#include <linux/videodev2.h> #include <linux/v4l2-subdev.h> #include <media/v4l2-dev.h> +#include <media/v4l2-fh.h> +#include <media/v4l2-ctrls.h> #include <media/v4l2-ioctl.h> static long native_ioctl (struct file *file,unsigned int cmd,unsigned long arg)
@@ -601,24 +603,39 @@ struct v4l2_ext_control32 { }; } __attribute__ ((packed)); -/* The following function really belong in v4l2-common, but that causes -a circular dependency between modules. We need to think about this, but -for now this will do. */ - -/* Return non-zero if this control is a pointer type. Currently only -type STRING is a pointer type. */ -static inline int ctrl_is_pointer (u32 id) -{ -switch (id) { -case V4L2_CID_RDS_TX_PS_NAME : -case V4L2_CID_RDS_TX_RADIO_TEXT : -return 1 ; -default : -return 0 ; +/* Return true if this control is a pointer type. */ +static inline bool ctrl_is_pointer (struct file *file,u32 id) +{ +struct video_device *vdev =video_devdata (file); +struct v4l2_fh *fh =NULL ; +struct v4l2_ctrl_handler *hdl =NULL ; +struct v4l2_query_ext_ctrl qec = { id }; +const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops; + +if (test_bit (V4L2_FL_USES_V4L2_FH , &vdev->flags)) + fh = file->private_data; + +if (fh && fh->ctrl_handler) + hdl = fh->ctrl_handler; +else if (vdev->ctrl_handler) + hdl = vdev->ctrl_handler; + +if (hdl) { +struct v4l2_ctrl *ctrl =v4l2_ctrl_find (hdl, id); + +return ctrl && ctrl->is_ptr; } + +if (!ops->vidioc_query_ext_ctrl) +return false; + +return !ops->vidioc_query_ext_ctrl (file, fh, &qec) && + (qec.flags &V4L2_CTRL_FLAG_HAS_PAYLOAD ); } -static int get_v4l2_ext_controls32 (struct v4l2_ext_controls *kp,struct v4l2_ext_controls32 __user *up) +static int get_v4l2_ext_controls32 (struct file *file, +struct v4l2_ext_controls *kp, +struct v4l2_ext_controls32 __user *up) {struct v4l2_ext_control32 __user *ucontrols;struct v4l2_ext_control __user *kcontrols;
@@ -651,7 +668,7 @@ static int get_v4l2_ext_controls32(strucreturn -EFAULT ;if (get_user (id, &kcontrols->id))return -EFAULT ; -if (ctrl_is_pointer (id)) { +if (ctrl_is_pointer (file, id)) {void __user *s;if (get_user (p, &ucontrols->string))
@@ -666,7 +683,9 @@ static int get_v4l2_ext_controls32(strucreturn 0 ; } -static int put_v4l2_ext_controls32 (struct v4l2_ext_controls *kp,struct v4l2_ext_controls32 __user *up) +static int put_v4l2_ext_controls32 (struct file *file, +struct v4l2_ext_controls *kp, +struct v4l2_ext_controls32 __user *up) {struct v4l2_ext_control32 __user *ucontrols; struct v4l2_ext_control __user *kcontrols =
@@ -698,7 +717,7 @@ static int put_v4l2_ext_controls32(struc/* Do not modify the pointer when copying a pointer control. The contents of the pointer was changed, not the pointer itself. */ -if (ctrl_is_pointer (id)) +if (ctrl_is_pointer (file, id)) size -=sizeof (ucontrols->value64);if (copy_in_user (ucontrols, kcontrols, size))return -EFAULT ;
@@ -912,7 +931,7 @@ static long do_video_ioctl(struct file *case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : - err =get_v4l2_ext_controls32 (&karg.v2ecs, up); + err =get_v4l2_ext_controls32 (file, &karg.v2ecs, up); compatible_arg =0 ;break ;case VIDIOC_DQEVENT :
@@ -939,7 +958,7 @@ static long do_video_ioctl(struct file *case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : -if (put_v4l2_ext_controls32 (&karg.v2ecs, up)) +if (put_v4l2_ext_controls32 (file, &karg.v2ecs, up)) err = -EFAULT ;break ;case VIDIOC_S_EDID :
Greg Kroah-Hartman
maintainerPATCH 128/195 media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit a751be5b142ef6bcbbb96d9899516f4d9c8d0ef4 upstream.
put_v4l2_window32() didn't copy back the clip list to userspace. Drivers can update the clip rectangles, so this should be done.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 59 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 19 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +40 -19
@@ -50,6 +50,11 @@ struct v4l2_window32 {static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { +struct v4l2_clip32 __user *uclips; +struct v4l2_clip __user *kclips; +compat_caddr_t p; +u32 n; + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || copy_from_user(&kp->w, &up->w, sizeof(up->w)) || get_user(kp->field, &up->field) ||
@@ -59,38 +64,54 @@ static int get_v4l2_window32(struct v4l2return -EFAULT ;if (kp->clipcount >2048 )return -EINVAL ; -if (kp->clipcount) { -struct v4l2_clip32 __user *uclips; -struct v4l2_clip __user *kclips; -int n = kp->clipcount; -compat_caddr_t p; +if (!kp->clipcount) { + kp->clips =NULL ; +return 0 ; + } -if (get_user (p, &up->clips)) + n = kp->clipcount; +if (get_user (p, &up->clips)) +return -EFAULT ; + uclips =compat_ptr (p); + kclips =compat_alloc_user_space (n *sizeof (*kclips)); + kp->clips = kclips; +while (n--) { +if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c)))return -EFAULT ; - uclips =compat_ptr (p); - kclips =compat_alloc_user_space (n *sizeof (*kclips)); - kp->clips = kclips; -while (--n >=0 ) { -if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c))) -return -EFAULT ; -if (put_user (n ? kclips +1 :NULL , &kclips->next)) -return -EFAULT ; - uclips +=1 ; - kclips +=1 ; - } - }else - kp->clips =NULL ; +if (put_user (n ? kclips +1 :NULL , &kclips->next)) +return -EFAULT ; + uclips++; + kclips++; + }return 0 ; }static int put_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { +struct v4l2_clip __user *kclips = kp->clips; +struct v4l2_clip32 __user *uclips; +u32 n = kp->clipcount; +compat_caddr_t p; +if (copy_to_user (&up->w, &kp->w,sizeof (kp->w)) ||put_user (kp->field, &up->field) ||put_user (kp->chromakey, &up->chromakey) ||put_user (kp->clipcount, &up->clipcount) ||put_user (kp->global_alpha, &up->global_alpha))return -EFAULT ; + +if (!kp->clipcount) +return 0 ; + +if (get_user (p, &up->clips)) +return -EFAULT ; + uclips =compat_ptr (p); +while (n--) { +if (copy_in_user (&uclips->c, &kclips->c,sizeof (uclips->c))) +return -EFAULT ; + uclips++; + kclips++; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 129/195 media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 169f24ca68bf0f247d111aef07af00dd3a02ae88 upstream.
There is nothing wrong with using an unknown buffer type. So stop spamming the kernel log whenever this happens. The kernel will just return -EINVAL to signal this.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +0 -4
@@ -179,8 +179,6 @@ static int __get_v4l2_format32(struct v4return copy_from_user (&kp->fmt.meta, &up->fmt.meta,sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default : -pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type);return -EINVAL ; } }
@@ -233,8 +231,6 @@ static int __put_v4l2_format32(struct v4return copy_to_user (&up->fmt.meta, &kp->fmt.meta,sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default : -pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type);return -EINVAL ; } }
Greg Kroah-Hartman
maintainerPATCH 130/195 media: v4l2-compat-ioctl32.c: dont copy back the result for certain errors
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit d83a8243aaefe62ace433e4384a4f077bed86acb upstream.
Some ioctls need to copy back the result even if the ioctl returned an error. However, don't do this for the error code -ENOTTY. It makes no sense in that cases.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +3 -0
@@ -968,6 +968,9 @@ static long do_video_ioctl(struct file *set_fs (old_fs); } +if (err == -ENOTTY ) +return err; +/* Special case: even after an error we need to put the results back for these ioctls since the error_idx will contain information on which control failed. */