No description
Find a file
Hou Tao 9f483179e6 bpf: Disable preemption when increasing per-cpu map_locked
[ Upstream commit 2775da2162 ]

Per-cpu htab->map_locked is used to prohibit the concurrent accesses
from both NMI and non-NMI contexts. But since commit 74d862b682
("sched: Make migrate_disable/enable() independent of RT"),
migrate_disable() is also preemptible under CONFIG_PREEMPT case, so now
map_locked also disallows concurrent updates from normal contexts
(e.g. userspace processes) unexpectedly as shown below:

process A                      process B

htab_map_update_elem()
  htab_lock_bucket()
    migrate_disable()
    /* return 1 */
    __this_cpu_inc_return()
    /* preempted by B */

                               htab_map_update_elem()
                                 /* the same bucket as A */
                                 htab_lock_bucket()
                                   migrate_disable()
                                   /* return 2, so lock fails */
                                   __this_cpu_inc_return()
                                   return -EBUSY

A fix that seems feasible is using in_nmi() in htab_lock_bucket() and
only checking the value of map_locked for nmi context. But it will
re-introduce dead-lock on bucket lock if htab_lock_bucket() is re-entered
through non-tracing program (e.g. fentry program).

One cannot use preempt_disable() to fix this issue as htab_use_raw_lock
being false causes the bucket lock to be a spin lock which can sleep and
does not work with preempt_disable().

Therefore, use migrate_disable() when using the spinlock instead of
preempt_disable() and defer fixing concurrent updates to when the kernel
has its own BPF memory allocator.

Fixes: 74d862b682 ("sched: Make migrate_disable/enable() independent of RT")
Reviewed-by: Hao Luo <haoluo@google.com>
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20220831042629.130006-2-houtao@huaweicloud.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-21 12:38:05 +02:00
arch x86/resctrl: Fix to restore to original value when re-enabling hardware prefetch register 2022-10-21 12:38:05 +02:00
block blk-wbt: call rq_qos_add() after wb_normal is initialized 2022-10-21 12:37:54 +02:00
certs certs: make system keyring depend on built-in x509 parser 2022-09-24 04:31:18 +09:00
crypto
Documentation fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE 2022-10-21 12:37:47 +02:00
drivers spi: mt7621: Fix an error message in mt7621_spi_probe() 2022-10-21 12:38:04 +02:00
fs NFSD: Fix handling of oversized NFSv4 COMPOUND requests 2022-10-21 12:38:01 +02:00
include bpf: Fix reference state management for synchronous callbacks 2022-10-21 12:38:03 +02:00
init arm64 fixes for -rc3 2022-08-26 11:32:53 -07:00
io_uring io_uring: correct pinned_vm accounting 2022-10-21 12:37:34 +02:00
ipc
kernel bpf: Disable preemption when increasing per-cpu map_locked 2022-10-21 12:38:05 +02:00
lib Makefile.debug: re-enable debug info for .S files 2022-09-24 11:19:19 +09:00
LICENSES
mm mm/mmap: undo ->mmap() when arch_validate_flags() fails 2022-10-21 12:37:42 +02:00
net xsk: Fix backpressure mechanism on Tx 2022-10-21 12:38:05 +02:00
samples
scripts selinux: use "grep -E" instead of "egrep" 2022-10-21 12:37:58 +02:00
security ima: fix blocking of security.ima xattrs of unsupported algorithms 2022-10-21 12:37:58 +02:00
sound ASoC: wcd934x: fix order of Slimbus unprepare/disable 2022-10-21 12:37:38 +02:00
tools selftests/xsk: Add missing close() on netns fd 2022-10-21 12:38:05 +02:00
usr
virt KVM: Drop unnecessary initialization of "ops" in kvm_ioctl_create_device() 2022-08-19 04:05:43 -04:00
.clang-format
.cocciconfig
.get_maintainer.ignore get_maintainer: add Alan to .get_maintainer.ignore 2022-08-20 15:17:44 -07:00
.gitattributes
.gitignore
.mailmap Qualcomm ARM64 DTS fixes for 6.0 2022-09-23 16:44:37 +02:00
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS One MAINTAINERS update, two MM fixes, both cc:stable 2022-10-01 09:13:29 -07:00
Makefile Linux 6.0.2 2022-10-15 08:02:59 +02:00
README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.