Daniel Borkmann [Fri, 4 Oct 2019 17:41:12 +0000 (10:41 -0700)]
bpf: fix use after free in prog symbol exposure
commit
c751798aa224fadc5124b49eeb38fb468c0fa039 upstream.
syzkaller managed to trigger the warning in bpf_jit_free() which checks via
bpf_prog_kallsyms_verify_off() for potentially unlinked JITed BPF progs
in kallsyms, and subsequently trips over GPF when walking kallsyms entries:
[...]
8021q: adding VLAN 0 to HW filter on device batadv0
8021q: adding VLAN 0 to HW filter on device batadv0
WARNING: CPU: 0 PID: 9869 at kernel/bpf/core.c:810 bpf_jit_free+0x1e8/0x2a0
Kernel panic - not syncing: panic_on_warn set ...
CPU: 0 PID: 9869 Comm: kworker/0:7 Not tainted 5.0.0-rc8+ #1
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events bpf_prog_free_deferred
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x113/0x167 lib/dump_stack.c:113
panic+0x212/0x40b kernel/panic.c:214
__warn.cold.8+0x1b/0x38 kernel/panic.c:571
report_bug+0x1a4/0x200 lib/bug.c:186
fixup_bug arch/x86/kernel/traps.c:178 [inline]
do_error_trap+0x11b/0x200 arch/x86/kernel/traps.c:271
do_invalid_op+0x36/0x40 arch/x86/kernel/traps.c:290
invalid_op+0x14/0x20 arch/x86/entry/entry_64.S:973
RIP: 0010:bpf_jit_free+0x1e8/0x2a0
Code: 02 4c 89 e2 83 e2 07 38 d0 7f 08 84 c0 0f 85 86 00 00 00 48 ba 00 02 00 00 00 00 ad de 0f b6 43 02 49 39 d6 0f 84 5f fe ff ff <0f> 0b e9 58 fe ff ff 48 b8 00 00 00 00 00 fc ff df 4c 89 e2 48 c1
RSP: 0018:
ffff888092f67cd8 EFLAGS:
00010202
RAX:
0000000000000007 RBX:
ffffc90001947000 RCX:
ffffffff816e9d88
RDX:
dead000000000200 RSI:
0000000000000008 RDI:
ffff88808769f7f0
RBP:
ffff888092f67d00 R08:
fffffbfff1394059 R09:
fffffbfff1394058
R10:
fffffbfff1394058 R11:
ffffffff89ca02c7 R12:
ffffc90001947002
R13:
ffffc90001947020 R14:
ffffffff881eca80 R15:
ffff88808769f7e8
BUG: unable to handle kernel paging request at
fffffbfff400d000
#PF error: [normal kernel read fault]
PGD
21ffee067 P4D
21ffee067 PUD
21ffed067 PMD
9f942067 PTE 0
Oops: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 9869 Comm: kworker/0:7 Not tainted 5.0.0-rc8+ #1
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events bpf_prog_free_deferred
RIP: 0010:bpf_get_prog_addr_region kernel/bpf/core.c:495 [inline]
RIP: 0010:bpf_tree_comp kernel/bpf/core.c:558 [inline]
RIP: 0010:__lt_find include/linux/rbtree_latch.h:115 [inline]
RIP: 0010:latch_tree_find include/linux/rbtree_latch.h:208 [inline]
RIP: 0010:bpf_prog_kallsyms_find+0x107/0x2e0 kernel/bpf/core.c:632
Code: 00 f0 ff ff 44 38 c8 7f 08 84 c0 0f 85 fa 00 00 00 41 f6 45 02 01 75 02 0f 0b 48 39 da 0f 82 92 00 00 00 48 89 d8 48 c1 e8 03 <42> 0f b6 04 30 84 c0 74 08 3c 03 0f 8e 45 01 00 00 8b 03 48 c1 e0
[...]
Upon further debugging, it turns out that whenever we trigger this
issue, the kallsyms removal in bpf_prog_ksym_node_del() was /skipped/
but yet bpf_jit_free() reported that the entry is /in use/.
Problem is that symbol exposure via bpf_prog_kallsyms_add() but also
perf_event_bpf_event() were done /after/ bpf_prog_new_fd(). Once the
fd is exposed to the public, a parallel close request came in right
before we attempted to do the bpf_prog_kallsyms_add().
Given at this time the prog reference count is one, we start to rip
everything underneath us via bpf_prog_release() -> bpf_prog_put().
The memory is eventually released via deferred free, so we're seeing
that bpf_jit_free() has a kallsym entry because we added it from
bpf_prog_load() but /after/ bpf_prog_put() from the remote CPU.
Therefore, move both notifications /before/ we install the fd. The
issue was never seen between bpf_prog_alloc_id() and bpf_prog_new_fd()
because upon bpf_prog_get_fd_by_id() we'll take another reference to
the BPF prog, so we're still holding the original reference from the
bpf_prog_load().
Fixes:
6ee52e2a3fe4 ("perf, bpf: Introduce PERF_RECORD_BPF_EVENT")
Fixes:
74451e66d516 ("bpf: make jited programs visible in traces")
Reported-by: syzbot+bd3bba6ff3fcea7a6ec6@syzkaller.appspotmail.com
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Zubin Mithra <zsm@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Sami Tolvanen [Wed, 4 Sep 2019 21:56:40 +0000 (14:56 -0700)]
ANDROID: arm64: bpf: implement arch_bpf_jit_check_func
Implement arch_bpf_jit_check_func to check that pointers to jited BPF
functions are correctly aligned and point to the BPF JIT region. This
narrows down the attack surface on the stored pointer.
Bug:
140377409
Change-Id: I10c448eda6a8b0bf4c16ee591fc65974696216b9
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Sami Tolvanen [Wed, 4 Sep 2019 21:08:16 +0000 (14:08 -0700)]
ANDROID: bpf: validate bpf_func when BPF_JIT is enabled with CFI
With CONFIG_BPF_JIT, the kernel makes indirect calls to dynamically
generated code, which the compile-time Control-Flow Integrity (CFI)
checking cannot validate. This change adds basic sanity checking to
ensure we are jumping to a valid location, which narrows down the
attack surface on the stored pointer.
In addition, this change adds a weak arch_bpf_jit_check_func function,
which architectures that implement BPF JIT can override to perform
additional validation, such as verifying that the pointer points to
the correct memory region.
Bug:
140377409
Change-Id: I8ebac6637ab6bd9db44716b1c742add267298669
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Sami Tolvanen [Wed, 4 Sep 2019 19:38:57 +0000 (12:38 -0700)]
UPSTREAM: kcm: use BPF_PROG_RUN
Instead of invoking struct bpf_prog::bpf_func directly, use the
BPF_PROG_RUN macro.
Bug:
140377409
Change-Id: I26abeccc8d25af0f412935ed97aebb5c64f52a2a
(cherry picked from commit
a2c11b034142 ("kcm: use BPF_PROG_RUN"))
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Daniel Borkmann [Tue, 11 Dec 2018 11:14:12 +0000 (12:14 +0100)]
bpf: fix bpf_jit_limit knob for PAGE_SIZE >= 64K
[ Upstream commit
fdadd04931c2d7cd294dc5b2b342863f94be53a3 ]
Michael and Sandipan report:
Commit
ede95a63b5 introduced a bpf_jit_limit tuneable to limit BPF
JIT allocations. At compile time it defaults to PAGE_SIZE * 40000,
and is adjusted again at init time if MODULES_VADDR is defined.
For ppc64 kernels, MODULES_VADDR isn't defined, so we're stuck with
the compile-time default at boot-time, which is 0x9c400000 when
using 64K page size. This overflows the signed 32-bit bpf_jit_limit
value:
root@ubuntu:/tmp# cat /proc/sys/net/core/bpf_jit_limit
-
1673527296
and can cause various unexpected failures throughout the network
stack. In one case `strace dhclient eth0` reported:
setsockopt(5, SOL_SOCKET, SO_ATTACH_FILTER, {len=11, filter=0x105dd27f8},
16) = -1 ENOTSUPP (Unknown error 524)
and similar failures can be seen with tools like tcpdump. This doesn't
always reproduce however, and I'm not sure why. The more consistent
failure I've seen is an Ubuntu 18.04 KVM guest booted on a POWER9
host would time out on systemd/netplan configuring a virtio-net NIC
with no noticeable errors in the logs.
Given this and also given that in near future some architectures like
arm64 will have a custom area for BPF JIT image allocations we should
get rid of the BPF_JIT_LIMIT_DEFAULT fallback / default entirely. For
4.21, we have an overridable bpf_jit_alloc_exec(), bpf_jit_free_exec()
so therefore add another overridable bpf_jit_alloc_exec_limit() helper
function which returns the possible size of the memory area for deriving
the default heuristic in bpf_jit_charge_init().
Like bpf_jit_alloc_exec() and bpf_jit_free_exec(), the new
bpf_jit_alloc_exec_limit() assumes that module_alloc() is the default
JIT memory provider, and therefore in case archs implement their custom
module_alloc() we use MODULES_{END,_VADDR} for limits and otherwise for
vmalloc_exec() cases like on ppc64 we use VMALLOC_{END,_START}.
Additionally, for archs supporting large page sizes, we should change
the sysctl to be handled as long to not run into sysctl restrictions
in future.
Fixes:
ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")
Reported-by: Sandipan Das <sandipan@linux.ibm.com>
Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Daniel Borkmann [Fri, 16 Aug 2019 22:05:36 +0000 (23:05 +0100)]
bpf: add bpf_jit_limit knob to restrict unpriv allocations
commit
ede95a63b5e84ddeea6b0c473b36ab8bfd8c6ce3 upstream.
Rick reported that the BPF JIT could potentially fill the entire module
space with BPF programs from unprivileged users which would prevent later
attempts to load normal kernel modules or privileged BPF programs, for
example. If JIT was enabled but unsuccessful to generate the image, then
before commit
290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
we would always fall back to the BPF interpreter. Nowadays in the case
where the CONFIG_BPF_JIT_ALWAYS_ON could be set, then the load will abort
with a failure since the BPF interpreter was compiled out.
Add a global limit and enforce it for unprivileged users such that in case
of BPF interpreter compiled out we fail once the limit has been reached
or we fall back to BPF interpreter earlier w/o using module mem if latter
was compiled in. In a next step, fair share among unprivileged users can
be resolved in particular for the case where we would fail hard once limit
is reached.
Fixes:
290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
Fixes:
0a14842f5a3c ("net: filter: Just In Time compiler for x86-64")
Co-Developed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Jann Horn <jannh@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel Borkmann [Fri, 16 Aug 2019 22:05:20 +0000 (23:05 +0100)]
bpf: restrict access to core bpf sysctls
commit
2e4a30983b0f9b19b59e38bbf7427d7fdd480d98 upstream.
Given BPF reaches far beyond just networking these days, it was
never intended to allow setting and in some cases reading those
knobs out of a user namespace root running without CAP_SYS_ADMIN,
thus tighten such access.
Also the bpf_jit_enable = 2 debugging mode should only be allowed
if kptr_restrict is not set since it otherwise can leak addresses
to the kernel log. Dump a note to the kernel log that this is for
debugging JITs only when enabled.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
[bwh: Backported to 4.14: We don't have bpf_dump_raw_ok(), so drop the
condition based on it. This condition only made it a bit harder for a
privileged user to do something silly.]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel Borkmann [Fri, 16 Aug 2019 22:04:32 +0000 (23:04 +0100)]
bpf: get rid of pure_initcall dependency to enable jits
commit
fa9dd599b4dae841924b022768354cfde9affecb upstream.
Having a pure_initcall() callback just to permanently enable BPF
JITs under CONFIG_BPF_JIT_ALWAYS_ON is unnecessary and could leave
a small race window in future where JIT is still disabled on boot.
Since we know about the setting at compilation time anyway, just
initialize it properly there. Also consolidate all the individual
bpf_jit_enable variables into a single one and move them under one
location. Moreover, don't allow for setting unspecified garbage
values on them.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
[bwh: Backported to 4.14 as dependency of commit
2e4a30983b0f
"bpf: restrict access to core bpf sysctls":
- Adjust context]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Eric Dumazet [Fri, 19 Jul 2019 02:28:14 +0000 (19:28 -0700)]
tcp: fix tcp_set_congestion_control() use from bpf hook
[ Upstream commit
8d650cdedaabb33e85e9b7c517c0c71fcecc1de9 ]
Neal reported incorrect use of ns_capable() from bpf hook.
bpf_setsockopt(...TCP_CONGESTION...)
-> tcp_set_congestion_control()
-> ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)
-> ns_capable_common()
-> current_cred()
-> rcu_dereference_protected(current->cred, 1)
Accessing 'current' in bpf context makes no sense, since packets
are processed from softirq context.
As Neal stated : The capability check in tcp_set_congestion_control()
was written assuming a system call context, and then was reused from
a BPF call site.
The fix is to add a new parameter to tcp_set_congestion_control(),
so that the ns_capable() call is only performed under the right
context.
Fixes:
91b5b21c7c16 ("bpf: Add support for changing congestion control")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Lawrence Brakmo <brakmo@fb.com>
Reported-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Lawrence Brakmo <brakmo@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Valdis Klētnieks [Fri, 7 Jun 2019 02:39:27 +0000 (22:39 -0400)]
bpf: silence warning messages in core
[ Upstream commit
aee450cbe482a8c2f6fa5b05b178ef8b8ff107ca ]
Compiling kernel/bpf/core.c with W=1 causes a flood of warnings:
kernel/bpf/core.c:1198:65: warning: initialized field overwritten [-Woverride-init]
1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
| ^~~~
kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
1087 | INSN_3(ALU, ADD, X), \
| ^~~~~~
kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
| ^~~~~~~~~~~~
kernel/bpf/core.c:1198:65: note: (near initialization for 'public_insntable[12]')
1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
| ^~~~
kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
1087 | INSN_3(ALU, ADD, X), \
| ^~~~~~
kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
| ^~~~~~~~~~~~
98 copies of the above.
The attached patch silences the warnings, because we *know* we're overwriting
the default initializer. That leaves bpf/core.c with only 6 other warnings,
which become more visible in comparison.
Signed-off-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
John Fastabend [Fri, 24 May 2019 15:01:00 +0000 (08:01 -0700)]
bpf: sockmap, fix use after free from sleep in psock backlog workqueue
[ Upstream commit
bd95e678e0f6e18351ecdc147ca819145db9ed7b ]
Backlog work for psock (sk_psock_backlog) might sleep while waiting
for memory to free up when sending packets. However, while sleeping
the socket may be closed and removed from the map by the user space
side.
This breaks an assumption in sk_stream_wait_memory, which expects the
wait queue to be still there when it wakes up resulting in a
use-after-free shown below. To fix his mark sendmsg as MSG_DONTWAIT
to avoid the sleep altogether. We already set the flag for the
sendpage case but we missed the case were sendmsg is used.
Sockmap is currently the only user of skb_send_sock_locked() so only
the sockmap paths should be impacted.
==================================================================
BUG: KASAN: use-after-free in remove_wait_queue+0x31/0x70
Write of size 8 at addr
ffff888069a0c4e8 by task kworker/0:2/110
CPU: 0 PID: 110 Comm: kworker/0:2 Not tainted
5.0.0-rc2-00335-g28f9d1a3d4fe-dirty #14
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-2.fc27 04/01/2014
Workqueue: events sk_psock_backlog
Call Trace:
print_address_description+0x6e/0x2b0
? remove_wait_queue+0x31/0x70
kasan_report+0xfd/0x177
? remove_wait_queue+0x31/0x70
? remove_wait_queue+0x31/0x70
remove_wait_queue+0x31/0x70
sk_stream_wait_memory+0x4dd/0x5f0
? sk_stream_wait_close+0x1b0/0x1b0
? wait_woken+0xc0/0xc0
? tcp_current_mss+0xc5/0x110
tcp_sendmsg_locked+0x634/0x15d0
? tcp_set_state+0x2e0/0x2e0
? __kasan_slab_free+0x1d1/0x230
? kmem_cache_free+0x70/0x140
? sk_psock_backlog+0x40c/0x4b0
? process_one_work+0x40b/0x660
? worker_thread+0x82/0x680
? kthread+0x1b9/0x1e0
? ret_from_fork+0x1f/0x30
? check_preempt_curr+0xaf/0x130
? iov_iter_kvec+0x5f/0x70
? kernel_sendmsg_locked+0xa0/0xe0
skb_send_sock_locked+0x273/0x3c0
? skb_splice_bits+0x180/0x180
? start_thread+0xe0/0xe0
? update_min_vruntime.constprop.27+0x88/0xc0
sk_psock_backlog+0xb3/0x4b0
? strscpy+0xbf/0x1e0
process_one_work+0x40b/0x660
worker_thread+0x82/0x680
? process_one_work+0x660/0x660
kthread+0x1b9/0x1e0
? __kthread_create_on_node+0x250/0x250
ret_from_fork+0x1f/0x30
Fixes:
20bf50de3028c ("skbuff: Function to send an skbuf on a socket")
Reported-by: Jakub Sitnicki <jakub@cloudflare.com>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Chang-Hsien Tsai [Sun, 19 May 2019 09:05:44 +0000 (09:05 +0000)]
samples, bpf: fix to change the buffer size for read()
[ Upstream commit
f7c2d64bac1be2ff32f8e4f500c6e5429c1003e0 ]
If the trace for read is larger than 4096, the return
value sz will be 4096. This results in off-by-one error
on buf:
static char buf[4096];
ssize_t sz;
sz = read(trace_fd, buf, sizeof(buf));
if (sz > 0) {
buf[sz] = 0;
puts(buf);
}
Signed-off-by: Chang-Hsien Tsai <luke.tw@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Daniel Borkmann [Fri, 26 Apr 2019 19:48:22 +0000 (21:48 +0200)]
bpf, arm64: use more scalable stadd over ldxr / stxr loop in xadd
commit
34b8ab091f9ef57a2bb3c8c8359a0a03a8abf2f9 upstream.
Since ARMv8.1 supplement introduced LSE atomic instructions back in 2016,
lets add support for STADD and use that in favor of LDXR / STXR loop for
the XADD mapping if available. STADD is encoded as an alias for LDADD with
XZR as the destination register, therefore add LDADD to the instruction
encoder along with STADD as special case and use it in the JIT for CPUs
that advertise LSE atomics in CPUID register. If immediate offset in the
BPF XADD insn is 0, then use dst register directly instead of temporary
one.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Martin KaFai Lau [Fri, 31 May 2019 22:29:11 +0000 (15:29 -0700)]
bpf: udp: ipv6: Avoid running reuseport's bpf_prog from __udp6_lib_err
commit
4ac30c4b3659efac031818c418beb51e630d512d upstream.
__udp6_lib_err() may be called when handling icmpv6 message. For example,
the icmpv6 toobig(type=2). __udp6_lib_lookup() is then called
which may call reuseport_select_sock(). reuseport_select_sock() will
call into a bpf_prog (if there is one).
reuseport_select_sock() is expecting the skb->data pointing to the
transport header (udphdr in this case). For example, run_bpf_filter()
is pulling the transport header.
However, in the __udp6_lib_err() path, the skb->data is pointing to the
ipv6hdr instead of the udphdr.
One option is to pull and push the ipv6hdr in __udp6_lib_err().
Instead of doing this, this patch follows how the original
commit
538950a1b752 ("soreuseport: setsockopt SO_ATTACH_REUSEPORT_[CE]BPF")
was done in IPv4, which has passed a NULL skb pointer to
reuseport_select_sock().
Fixes:
538950a1b752 ("soreuseport: setsockopt SO_ATTACH_REUSEPORT_[CE]BPF")
Cc: Craig Gallek <kraig@google.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Craig Gallek <kraig@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Martin KaFai Lau [Fri, 31 May 2019 22:29:13 +0000 (15:29 -0700)]
bpf: udp: Avoid calling reuseport's bpf_prog from udp_gro
commit
257a525fe2e49584842c504a92c27097407f778f upstream.
When the commit
a6024562ffd7 ("udp: Add GRO functions to UDP socket")
added udp[46]_lib_lookup_skb to the udp_gro code path, it broke
the reuseport_select_sock() assumption that skb->data is pointing
to the transport header.
This patch follows an earlier __udp6_lib_err() fix by
passing a NULL skb to avoid calling the reuseport's bpf_prog.
Fixes:
a6024562ffd7 ("udp: Add GRO functions to UDP socket")
Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Naveen N. Rao [Wed, 12 Jun 2019 18:51:40 +0000 (00:21 +0530)]
powerpc/bpf: use unsigned division instruction for 64-bit operations
commit
758f2046ea040773ae8ea7f72dd3bbd8fa984501 upstream.
BPF_ALU64 div/mod operations are currently using signed division, unlike
BPF_ALU32 operations. Fix the same. DIV64 and MOD64 overflow tests pass
with this fix.
Fixes:
156d0e290e969c ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF")
Cc: stable@vger.kernel.org # v4.8+
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel T. Lee [Tue, 23 Apr 2019 20:24:56 +0000 (05:24 +0900)]
libbpf: fix samples/bpf build failure due to undefined UINT32_MAX
[ Upstream commit
32e621e55496a0009f44fe4914cd4a23cade4984 ]
Currently, building bpf samples will cause the following error.
./tools/lib/bpf/bpf.h:132:27: error: 'UINT32_MAX' undeclared here (not in a function) ..
#define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */
^
./samples/bpf/bpf_load.h:31:25: note: in expansion of macro 'BPF_LOG_BUF_SIZE'
extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
^~~~~~~~~~~~~~~~
Due to commit
4519efa6f8ea ("libbpf: fix BPF_LOG_BUF_SIZE off-by-one error")
hard-coded size of BPF_LOG_BUF_SIZE has been replaced with UINT32_MAX which is
defined in <stdint.h> header.
Even with this change, bpf selftests are running fine since these are built
with clang and it includes header(-idirafter) from clang/6.0.0/include.
(it has <stdint.h>)
clang -I. -I./include/uapi -I../../../include/uapi -idirafter /usr/local/include -idirafter /usr/include \
-idirafter /usr/lib/llvm-6.0/lib/clang/6.0.0/include -idirafter /usr/include/x86_64-linux-gnu \
-Wno-compare-distinct-pointer-types -O2 -target bpf -emit-llvm -c progs/test_sysctl_prog.c -o - | \
llc -march=bpf -mcpu=generic -filetype=obj -o /linux/tools/testing/selftests/bpf/test_sysctl_prog.o
But bpf samples are compiled with GCC, and it only searches and includes
headers declared at the target file. As '#include <stdint.h>' hasn't been
declared in tools/lib/bpf/bpf.h, it causes build failure of bpf samples.
gcc -Wp,-MD,./samples/bpf/.sockex3_user.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes \
-O2 -fomit-frame-pointer -std=gnu89 -I./usr/include -I./tools/lib/ -I./tools/testing/selftests/bpf/ \
-I./tools/ lib/ -I./tools/include -I./tools/perf -c -o ./samples/bpf/sockex3_user.o ./samples/bpf/sockex3_user.c;
This commit add declaration of '#include <stdint.h>' to tools/lib/bpf/bpf.h
to fix this problem.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Vineet Gupta [Thu, 2 May 2019 15:56:50 +0000 (08:56 -0700)]
tools/bpf: fix perf build error with uClibc (seen on ARC)
[ Upstream commit
ca31ca8247e2d3807ff5fa1d1760616a2292001c ]
When build perf for ARC recently, there was a build failure due to lack
of __NR_bpf.
| Auto-detecting system features:
|
| ... get_cpuid: [ OFF ]
| ... bpf: [ on ]
|
| # error __NR_bpf not defined. libbpf does not support your arch.
^~~~~
| bpf.c: In function 'sys_bpf':
| bpf.c:66:17: error: '__NR_bpf' undeclared (first use in this function)
| return syscall(__NR_bpf, cmd, attr, size);
| ^~~~~~~~
| sys_bpf
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Eric Dumazet [Mon, 13 May 2019 16:59:16 +0000 (09:59 -0700)]
bpf: devmap: fix use-after-free Read in __dev_map_entry_free
commit
2baae3545327632167c0180e9ca1d467416f1919 upstream.
synchronize_rcu() is fine when the rcu callbacks only need
to free memory (kfree_rcu() or direct kfree() call rcu call backs)
__dev_map_entry_free() is a bit more complex, so we need to make
sure that call queued __dev_map_entry_free() callbacks have completed.
sysbot report:
BUG: KASAN: use-after-free in dev_map_flush_old kernel/bpf/devmap.c:365
[inline]
BUG: KASAN: use-after-free in __dev_map_entry_free+0x2a8/0x300
kernel/bpf/devmap.c:379
Read of size 8 at addr
ffff8801b8da38c8 by task ksoftirqd/1/18
CPU: 1 PID: 18 Comm: ksoftirqd/1 Not tainted 4.17.0+ #39
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x1b9/0x294 lib/dump_stack.c:113
print_address_description+0x6c/0x20b mm/kasan/report.c:256
kasan_report_error mm/kasan/report.c:354 [inline]
kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412
__asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:433
dev_map_flush_old kernel/bpf/devmap.c:365 [inline]
__dev_map_entry_free+0x2a8/0x300 kernel/bpf/devmap.c:379
__rcu_reclaim kernel/rcu/rcu.h:178 [inline]
rcu_do_batch kernel/rcu/tree.c:2558 [inline]
invoke_rcu_callbacks kernel/rcu/tree.c:2818 [inline]
__rcu_process_callbacks kernel/rcu/tree.c:2785 [inline]
rcu_process_callbacks+0xe9d/0x1760 kernel/rcu/tree.c:2802
__do_softirq+0x2e0/0xaf5 kernel/softirq.c:284
run_ksoftirqd+0x86/0x100 kernel/softirq.c:645
smpboot_thread_fn+0x417/0x870 kernel/smpboot.c:164
kthread+0x345/0x410 kernel/kthread.c:240
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412
Allocated by task 6675:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc+0xc4/0xe0 mm/kasan/kasan.c:553
kmem_cache_alloc_trace+0x152/0x780 mm/slab.c:3620
kmalloc include/linux/slab.h:513 [inline]
kzalloc include/linux/slab.h:706 [inline]
dev_map_alloc+0x208/0x7f0 kernel/bpf/devmap.c:102
find_and_alloc_map kernel/bpf/syscall.c:129 [inline]
map_create+0x393/0x1010 kernel/bpf/syscall.c:453
__do_sys_bpf kernel/bpf/syscall.c:2351 [inline]
__se_sys_bpf kernel/bpf/syscall.c:2328 [inline]
__x64_sys_bpf+0x303/0x510 kernel/bpf/syscall.c:2328
do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Freed by task 26:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
__kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:521
kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
__cache_free mm/slab.c:3498 [inline]
kfree+0xd9/0x260 mm/slab.c:3813
dev_map_free+0x4fa/0x670 kernel/bpf/devmap.c:191
bpf_map_free_deferred+0xba/0xf0 kernel/bpf/syscall.c:262
process_one_work+0xc64/0x1b70 kernel/workqueue.c:2153
worker_thread+0x181/0x13a0 kernel/workqueue.c:2296
kthread+0x345/0x410 kernel/kthread.c:240
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412
The buggy address belongs to the object at
ffff8801b8da37c0
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 264 bytes inside of
512-byte region [
ffff8801b8da37c0,
ffff8801b8da39c0)
The buggy address belongs to the page:
page:
ffffea0006e368c0 count:1 mapcount:0 mapping:
ffff8801da800940
index:0xffff8801b8da3540
flags: 0x2fffc0000000100(slab)
raw:
02fffc0000000100 ffffea0007217b88 ffffea0006e30cc8 ffff8801da800940
raw:
ffff8801b8da3540 ffff8801b8da3040 0000000100000004 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8801b8da3780: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
ffff8801b8da3800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>
ffff8801b8da3880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8801b8da3900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801b8da3980: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
Fixes:
546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot+457d3e2ffbcf31aee5c0@syzkaller.appspotmail.com
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel Borkmann [Mon, 13 May 2019 23:18:56 +0000 (01:18 +0200)]
bpf, lru: avoid messing with eviction heuristics upon syscall lookup
commit
50b045a8c0ccf44f76640ac3eea8d80ca53979a3 upstream.
One of the biggest issues we face right now with picking LRU map over
regular hash table is that a map walk out of user space, for example,
to just dump the existing entries or to remove certain ones, will
completely mess up LRU eviction heuristics and wrong entries such
as just created ones will get evicted instead. The reason for this
is that we mark an entry as "in use" via bpf_lru_node_set_ref() from
system call lookup side as well. Thus upon walk, all entries are
being marked, so information of actual least recently used ones
are "lost".
In case of Cilium where it can be used (besides others) as a BPF
based connection tracker, this current behavior causes disruption
upon control plane changes that need to walk the map from user space
to evict certain entries. Discussion result from bpfconf [0] was that
we should simply just remove marking from system call side as no
good use case could be found where it's actually needed there.
Therefore this patch removes marking for regular LRU and per-CPU
flavor. If there ever should be a need in future, the behavior could
be selected via map creation flag, but due to mentioned reason we
avoid this here.
[0] http://vger.kernel.org/bpfconf.html
Fixes:
29ba732acbee ("bpf: Add BPF_MAP_TYPE_LRU_HASH")
Fixes:
8f8449384ec3 ("bpf: Add BPF_MAP_TYPE_LRU_PERCPU_HASH")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel Borkmann [Mon, 13 May 2019 23:18:55 +0000 (01:18 +0200)]
bpf: add map_lookup_elem_sys_only for lookups from syscall side
commit
c6110222c6f49ea68169f353565eb865488a8619 upstream.
Add a callback map_lookup_elem_sys_only() that map implementations
could use over map_lookup_elem() from system call side in case the
map implementation needs to handle the latter differently than from
the BPF data path. If map_lookup_elem_sys_only() is set, this will
be preferred pick for map lookups out of user space. This hook is
used in a follow-up fix for LRU map, but once development window
opens, we can convert other map types from map_lookup_elem() (here,
the one called upon BPF_MAP_LOOKUP_ELEM cmd is meant) over to use
the callback to simplify and clean up the latter.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Daniel Borkmann [Fri, 26 Apr 2019 19:48:21 +0000 (21:48 +0200)]
bpf, arm64: remove prefetch insn in xadd mapping
commit
8968c67a82ab7501bc3b9439c3624a49b42fe54c upstream.
Prefetch-with-intent-to-write is currently part of the XADD mapping in
the AArch64 JIT and follows the kernel's implementation of atomic_add.
This may interfere with other threads executing the LDXR/STXR loop,
leading to potential starvation and fairness issues. Drop the optional
prefetch instruction.
Fixes:
85f68fe89832 ("bpf, arm64: implement jiting of BPF_XADD")
Reported-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Kevin F. Haggerty [Fri, 19 Aug 2022 20:53:18 +0000 (14:53 -0600)]
mm: Drop Google's picks and put do_wp_page back in line with stable
This causes TEEGRIS to crash out and die. The user-visible result is
that the lockscreen pin is claimed to be incorrect, making the tablet
unusable. The device may be unlocked once upon boot, if done quickly
enough, but not after relocking or sitting long enough after boot.
This is a squash of:
* Revert "UPSTREAM: mm: reuse only-pte-mapped KSM page in do_wp_page()"
This reverts commit
2b438ad3d5bad3d42b772d79f1aed4e143fe4c75.
* Revert "UPSTREAM: mm/ksm: Remove reuse_ksm_page()"
This reverts commit
e374fe2602945f563e12ba9e3276f196523a4802.
* Revert "BACKPORT: mm: do_wp_page() simplification"
This reverts commit
32c2bf987549e56f11784b194a33b091fa3bc482.
* Revert "UPSTREAM: mm: fix misplaced unlock_page in do_wp_page()"
This reverts commit
ecff1109d781e1ef07f5b63658ce9429a0948f07.
Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
Change-Id: I83980aea81a0b667068acdf6ffc7d698ff1d51bf
Nolen Johnson [Wed, 24 Apr 2024 18:27:09 +0000 (14:27 -0400)]
arch: arm64: configs: kane_defcofig: Enable BPF JIT
Change-Id: Id5f427283aebed2bb1e93720d1f99507f97cb28c
Nolen Johnson [Mon, 22 Apr 2024 01:01:09 +0000 (21:01 -0400)]
drivers: misc: samsung: Fix strict-prototypes error
Change-Id: I363ceb1503d7caae7404dbd5f02356618c911b0c
Nolen Johnson [Wed, 17 Apr 2024 17:27:11 +0000 (13:27 -0400)]
arch: arm64: defconfig: kane/troika: savedefconfig
Change-Id: I5685c7eb16b9078834134aa52bac4900d1674267
Nolen Johnson [Tue, 26 Mar 2024 16:08:11 +0000 (12:08 -0400)]
defconfig: troika/kane: Enable BPF JIT
Change-Id: I7db7cc2d55cfcc4e897e0b257fd3bcf99b100184
Sami Tolvanen [Wed, 4 Sep 2019 21:08:16 +0000 (14:08 -0700)]
ANDROID: bpf: validate bpf_func when BPF_JIT is enabled with CFI
With CONFIG_BPF_JIT, the kernel makes indirect calls to dynamically
generated code, which the compile-time Control-Flow Integrity (CFI)
checking cannot validate. This change adds basic sanity checking to
ensure we are jumping to a valid location, which narrows down the
attack surface on the stored pointer.
In addition, this change adds a weak arch_bpf_jit_check_func function,
which architectures that implement BPF JIT can override to perform
additional validation, such as verifying that the pointer points to
the correct memory region.
Bug:
140377409
Change-Id: I8ebac6637ab6bd9db44716b1c742add267298669
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Cosmin Tanislav [Wed, 17 Apr 2024 14:29:32 +0000 (17:29 +0300)]
usb: gadget: configfs: fix build error
Change-Id: Ie4f5f5f703d565c9bd463ad2ceb18baa4d898dfb
Cosmin Tanislav [Wed, 17 Apr 2024 13:55:44 +0000 (16:55 +0300)]
Revert "lib/genalloc.c: fix allocation of aligned buffer from non-aligned chunk"
This reverts commit
525ef5687c35eda312a7add8a221580d0c4aee55.
Cosmin Tanislav [Wed, 17 Apr 2024 13:53:41 +0000 (16:53 +0300)]
Revert "pstore: Convert buf_lock to semaphore"
This reverts commit
f72ecfe93a80a1e83bc9b13f2c66c8af3fb456d8.
Youngmin Nam [Thu, 2 May 2019 08:43:32 +0000 (17:43 +0900)]
[COMMON] kernel: cpu: fix conflict
Change-Id: I1fa521368b3dffbd7bb572dac10e403c7bd07d2b
Signed-off-by: Youngmin Nam <youngmin.nam@samsung.com>
Cosmin Tanislav [Wed, 17 Apr 2024 15:39:44 +0000 (18:39 +0300)]
Revert "BACKPORT: sched/fair: Fix cpu_util_wake() for 'execl' type workloads"
This reverts commit
51164110fa6e8a0326c90f1dd8062f7179840403.
Youngtae Lee [Thu, 6 Sep 2018 00:57:15 +0000 (09:57 +0900)]
trace: events: sched: Add event "activated_cpus" for frt
Change-Id: I97802fb9f7bd0f3102ad3686848cc73bc4855966
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Park Bumgyu [Wed, 11 Apr 2018 01:13:17 +0000 (10:13 +0900)]
init/kconfig: FRT dependends on EMS
Change-Id: I5b241b766adc14a2169ec773ead76caba7187f03
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Mon, 21 Jan 2019 07:55:53 +0000 (16:55 +0900)]
[RAMEN9610-11191] sched: ems: check empty of gb-list
Change-Id: I942b1f9cb43f46c3e90511c58c77a5254d45f15c
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Tue, 24 Jul 2018 04:02:35 +0000 (13:02 +0900)]
cpu: fix prevent defect
Change-Id: I97b0f154cfd224b47f8266972bdfa488a0969e28
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Thu, 23 Aug 2018 06:51:04 +0000 (15:51 +0900)]
[RAMEN9610-9421][COMMON] cpufreq: acme: request prefer perf at cpufreq_min_limit
Change-Id: I6b78a333c52708b59bf84c664795e370d9d8de7c
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Daeyeong Lee [Tue, 20 Nov 2018 07:13:33 +0000 (16:13 +0900)]
[RAMEN9610-14454] [COMMON] sched: ems: Fix possibility of slab-out-of-bounds error
Change-Id: Ieeecdd4d811479d3e23d2638ff93069e75c5cedf
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Park Bumgyu [Mon, 20 Aug 2018 01:29:10 +0000 (10:29 +0900)]
[RAMEN9610-9421][COMMON] sched: ems: support prefer perf service
Change-Id: Ida3e81c598a22e984839533e62604ffd20c94dc3
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Mon, 13 Aug 2018 06:21:27 +0000 (15:21 +0900)]
[RAMEN9610-9421][COMMON] sched: ems: introduce ems service
Change-Id: I6e0cc8b8db43035c5c933ed292f443c9a67e4520
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Youngtae Lee [Mon, 15 Oct 2018 06:21:01 +0000 (15:21 +0900)]
[RAMEN9610-9418][COMMON] sched: frt: Fix zero dividing bug
Change-Id: Id738b19174de909113aa8c5224a3e57f1762073d
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Mon, 8 Oct 2018 06:57:12 +0000 (15:57 +0900)]
[RAMEN9610-9418][COMMON] sched: frt: fix cpumask warnning bug
Change-Id: I27eb08fdcbe6ce7b35a09a38b2aa2fb4b90e76a7
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Daeyeong Lee [Mon, 15 Oct 2018 06:38:00 +0000 (15:38 +0900)]
[RAMEN9610-9418][COMMON] sched: ems: Disable ontime when capacity of coregroup is zero
Change-Id: I22c3b9d97ca5b5f598436cfb06062b9cb24f2ff6
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 15 Oct 2018 06:36:06 +0000 (15:36 +0900)]
[RAMEN9610-9418][COMMON] sched: ems: Modify get_cpu_max_capacity not to access NULL point
Change-Id: I2a88779e24ba4f30d0423224d3cdc78aea6e586a
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Sangkyu Kim [Fri, 9 Nov 2018 09:49:41 +0000 (18:49 +0900)]
[RAMEN9610-9418][COMMON] ems: frt: fix initialize variable for check condition
Change-Id: I330d6250f3a8873ffd0bdbb1bca524db6ca56d7d
Signed-off-by: Sangkyu Kim <skwith.kim@samsung.com>
Youngtae Lee [Fri, 12 Oct 2018 02:27:15 +0000 (11:27 +0900)]
sched: rt: fix prevent
Change-Id: Ia34ab264f22a956c45a654d9e4d5e737c5629822
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Sangkyu Kim [Mon, 8 Oct 2018 11:18:04 +0000 (20:18 +0900)]
ems: frt: sync for latest
Change-Id: I6bfc7af78625019ad1e81823e257c11f4a124e11
Signed-off-by: Sangkyu Kim <skwith.kim@samsung.com>
Youngtae Lee [Mon, 17 Sep 2018 09:42:57 +0000 (18:42 +0900)]
ems: frt: Disable cache-hot
Change-Id: I8ee0adc10fbac465eef46bae604d301cc827cd25
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Fri, 14 Sep 2018 08:50:28 +0000 (17:50 +0900)]
ems: frt: Change cache-hot check conditon
Change-Id: I35f05c4843e548dee12d047e0cdbd7d7678a3e2a
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Thu, 13 Sep 2018 10:00:36 +0000 (19:00 +0900)]
ems: frt: Add exception condition for frt init
Change-Id: Ic69f786a4098e518fc043cc335339b6ef4822ba9
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Fri, 7 Sep 2018 05:20:14 +0000 (14:20 +0900)]
sched: frt: Fix loop condition to use domain pointer
Change-Id: Ie4646c26f21438c7bbaad84ff70ad1056e0f0912
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Thu, 6 Sep 2018 00:51:34 +0000 (09:51 +0900)]
ems: frt: Support activated_cpus to reflect system_idle
If cluster A is idle and cluster B slower than cluster A is also idle,
frt removes cpus of cluster A from prefer_cpus.
and then "find_idle_cpu" selects idle cpu among activated_cpus.
Change-Id: If321de699b11202c5156e2beb1e7dfa543acd223
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Soohyun Kim [Fri, 7 Sep 2018 00:03:45 +0000 (09:03 +0900)]
[COMMON] sched: ems: Disable ontime and lbt when using core control.
Change-Id: I390d6cebaa2db2ff692ea13da6658793edc48e62
Signed-off-by: Soohyun Kim <soohyuni.kim@samsung.com>
Youngtae Lee [Thu, 9 Aug 2018 02:11:05 +0000 (11:11 +0900)]
sched: rt: Refactoring select idle cpu and recessive cpu
Implement init code for sysfs, dt to
support multi min_thr to detect heavy rt task
change loop and condition for find_idle_cpu/find_recessive_cpu
Change-Id: I4ca5525c4275115c74f9c1577a8f716275526b9a
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 06:24:06 +0000 (15:24 +0900)]
[COMMON] sched: ems: Use get_cpu_max_capacity instead of get_cpu_mips
Change-Id: I911e849159eaf4b8941b919e0dbe1b7024b98236
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 06:18:48 +0000 (15:18 +0900)]
[COMMON] sched: ems: Modify ontime_can_migration condition
Change-Id: I8e4c0fd4843fd5b84f6a8d1340b11f7f1a1b800b
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 06:13:16 +0000 (15:13 +0900)]
[COMMON] sched: ems: Change how to select ontime target CPU
Change-Id: I2e36d26feb1858de6f8a912a9365627927f4e9f3
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 06:07:27 +0000 (15:07 +0900)]
[COMMON] sched: ems: Change ontime policy and algorithm
- If the task is above upper_boudnary of task's cpu,
Any coregroup with a higher mips than task's cpu can be a candidates.
- If there are multiple candidate coregroups,
calculate energy and select the most efficient CPU.
- If the task is below lower_boundary of task's cpu,
leave it to the core selection afterwards.
Change-Id: I38667d4382692115d74ec27eaa4169e6124bd749
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Wed, 1 Aug 2018 11:08:36 +0000 (20:08 +0900)]
[COMMON] sched: ems: Change calculate_energy function to an extern declaration
Change-Id: I3004c525cac85ef5747205494ac639dda8852857
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 05:45:36 +0000 (14:45 +0900)]
[COMMON] sched: ems: Modify ontime migration to apply to each cgroup individually.
Change-Id: I268c50933dbe11b81c89857c721745df3bf01b69
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 3 Sep 2018 05:34:54 +0000 (14:34 +0900)]
[COMMON] sched: ems: allow to disable up/down ontime migration
Change-Id: I9ba1208a89421829855c2070ba4d40695cc77fc3
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Youngtae Lee [Wed, 22 Aug 2018 01:59:43 +0000 (10:59 +0900)]
sched: frt: Fix condition to select idle_cpu and recessive_cpu
Fix bug that doesn't applying active_mask while selects
idle_cpu and recessive_cpu
Change-Id: I7b26ab2622f4d1288a7277a23a7d9668bc4e9526
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Youngtae Lee [Thu, 9 Aug 2018 02:11:05 +0000 (11:11 +0900)]
sched: rt: Refactoring select idle cpu and recessive cpu
Implement init code for sysfs, dt to
support multi min_thr to detect heavy rt task
change loop and condition for find_idle_cpu/find_recessive_cpu
Change-Id: I91e5199c9a86849025af7271c0e6aeeee6b3f966
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Park Bumgyu [Fri, 13 Apr 2018 02:30:57 +0000 (11:30 +0900)]
ems: clean up ems.h
Change-Id: I70a89c242ada635932d85cbdb9533ef07bcb3526
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Youngtae Lee [Fri, 6 Jul 2018 01:46:58 +0000 (10:46 +0900)]
sched: rt: Fix cpu_util_wake problem
Previous cpu_util_wake considers only cfs util.
But in rt task working case, it reads making wrong decisions so
frt_cpu_util_wake considers not only cfs util but also rt util.
Change-Id: I814cd8346b7e6260fa3cbefff773024bd74a42a1
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
Park Bumgyu [Thu, 9 Aug 2018 04:54:59 +0000 (13:54 +0900)]
sched: ems: update topology after energy table creation
Change-Id: I12c66b041b801c331d1b631b035bf99d07af763f
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Daeyeong Lee [Mon, 20 Aug 2018 07:03:26 +0000 (16:03 +0900)]
[COMMON] sched: ems: Consider sync cpu when ontime task wakeup
Change-Id: Ia77686fd9341ec427643c95bf82b1366a6303807
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
lakkyung.jung [Mon, 3 Sep 2018 04:37:55 +0000 (13:37 +0900)]
sched: ems: Fix calculate_energy bug
Change-Id: I13fda72d1a6529c245108da2d34bb6d40688d8cb
Signed-off-by: lakkyung.jung <lakkyung.jung@samsung.com>
Daeyeong Lee [Mon, 25 Jun 2018 11:07:30 +0000 (20:07 +0900)]
[COMMON] sched: ems: Modify select_eco_cpu algorithm
- Previous select_eco_cpu function choose mininum capacity cpu
as energy cpu as far as possible.
But there is many case that bigger cpu is better at power efficiency.
So modify select_eco_cpu function to search all active core.
Change-Id: Ibe3d2a9729e794ac395780fe4d5875f31575c972
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Park Bumgyu [Wed, 18 Jul 2018 01:32:01 +0000 (10:32 +0900)]
sched: ems: reinforce comment of wakeup balance
Change-Id: I8e0731eaa35ed746168955ede2501cad2c75ee42
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Wed, 18 Jul 2018 00:59:34 +0000 (09:59 +0900)]
sched: ems: remove group balancer
group balancer is not used anymore, similar function is supported
by task band. Remove group balancer.
Change-Id: I5ff7573a927f69144f477e5d64c32084d70188c7
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Mon, 2 Jul 2018 23:47:28 +0000 (08:47 +0900)]
sched: ems: declare task_of for common use in ems
Change-Id: I5c6ed6b9d3d0c15f17d871b3b69f0bc5e7a60b7d
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Thu, 5 Jul 2018 23:16:28 +0000 (08:16 +0900)]
sched: ems: use LOAD_AVG_MAX declared in sched-pelt.h
To follow the half-life time of task util, use the LOAD_AVG_MAX
declared in sched-pelt.h
Change-Id: I28fd88dd334d9c4999f97734d8d9c983af38100a
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Daeyeong Lee [Tue, 19 Jun 2018 06:19:07 +0000 (15:19 +0900)]
sched: ems: ontime: Use get_cpu_max_capacity instead of capacity_orig_of function.
Change-Id: I0ffb28f2680b9f3603a82eb0fbfbce8213c4c83f
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Park Bumgyu [Tue, 19 Jun 2018 06:10:01 +0000 (15:10 +0900)]
sched: ems: provide API for cpu max capacity
Change-Id: Iaef589d777ce55ab21f642f4f9333d753309069e
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Thu, 14 Jun 2018 05:42:44 +0000 (14:42 +0900)]
sched: fix wrong declaration of inline extern function.
To fix build error, remove inline term at extern declared function.
Change-Id: Id30ffd2f600b514b98cfe9ebd60d80a5fdc463c3
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Wed, 2 May 2018 02:27:23 +0000 (11:27 +0900)]
sched: ems: update cpu_scale when policy is updated
When policy->max is pressed, the performance of the cpu is
constrained. In the constrained state, the cpu capacity also
changes, and the overutil condition changes accordingly, so
the cpu scale is updated whenever policy is changed.
Change-Id: Ie6938e605d55cf700164a7512ffd6c41a747cbbc
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Daeyeong Lee [Mon, 18 Jun 2018 02:44:00 +0000 (11:44 +0900)]
sched: ems: ontime: Modify to initialize the boundary value by ratio
Change-Id: Iab4450579898d8b5d561d00f7c627d7c88ce88ab
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Thu, 14 Jun 2018 06:56:50 +0000 (15:56 +0900)]
sched: ems: Don't check lbt_bring_overutilize when wake balance
Change-Id: I2b3cd086d0a4329270c7b877967897ce4735e5a0
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Park Bumgyu [Thu, 14 Jun 2018 04:20:46 +0000 (13:20 +0900)]
sched: ems: support schedtune.boost in wakeup balance.
Change-Id: I18938f89a6cf1372c6be96e0d6c769960cd2918c
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Thu, 14 Jun 2018 00:43:16 +0000 (09:43 +0900)]
sched: ems: fix return type of task_util.
The variable type of util_avg is unsigned long. Fix return type
of task util to avoid data loss.
Change-Id: I463b9fa65f018f4d98804df6f3c62fbbb6ff0951
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Daeyeong Lee [Thu, 14 Jun 2018 01:17:52 +0000 (10:17 +0900)]
sched: ems: ontime: Modify to check whether fit_cpus is empty.
- There is a possibility of trouble, when fit_cpus is return with empty.
To prevent this situation, ontime_select_fit_cpus fucntion return
whether fit_cpus is empty or not.
Change-Id: Ibcadee7f1c7dd54e074509712ddb3ea05bfc82ef
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Johnlay Park [Tue, 12 Jun 2018 11:03:25 +0000 (20:03 +0900)]
sched: frt: Add the rt_rq load update.
Change-Id: I676ecfa2aec75c46144f78fc90981ff43c8833c0
Signed-off-by: Johnlay Park <jonglae.park@samsung.com>
Daeyeong Lee [Tue, 12 Jun 2018 06:15:42 +0000 (15:15 +0900)]
sched: ems: ontime: Use get_cpu_mips instead of capacity_orig_of.
- The value of capacity_orig_of can be changed at runtime.
Ontime feature need to use stable value that indicating performance of cpu.
So use get_cpu_mips instead of capacity_orig_of.
Change-Id: If249f6841cc26abce573459d8199004beccdeac8
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Park Bumgyu [Tue, 12 Jun 2018 06:12:22 +0000 (15:12 +0900)]
sched: ems: add function to get cpu mips.
Change-Id: I79918451a93bddf1effe7d8ed6a65a0176886012
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Tue, 12 Jun 2018 01:23:31 +0000 (10:23 +0900)]
sched: ems: prevent access to plugged out cpu.
Change-Id: Id9e0ac5cb1979cd8d3766f9fb1a7c0874a561e7b
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Park Bumgyu [Fri, 25 May 2018 05:01:52 +0000 (14:01 +0900)]
sched: ems: introduce task band
Change-Id: Ic3fbe3e80c8033f5c1c77f02cb0eeb6ee04d9630
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
Cosmin Tanislav [Tue, 16 Apr 2024 19:14:45 +0000 (22:14 +0300)]
Revert "sched: fair/ems: Add schedtune_util_est"
This reverts commit
0084cce86c169f068fe02aac9cbab499feb1c6a4.
lakkyung.jung [Fri, 4 May 2018 11:16:53 +0000 (20:16 +0900)]
sched: fair/ems: Add schedtune_util_est
Change-Id: I0a0f1723356683829ce709ec750f4f013aa1c75b
Signed-off-by: lakkyung.jung <lakkyung.jung@samsung.com>
lakkyung.jung [Fri, 4 May 2018 01:20:03 +0000 (10:20 +0900)]
sched: tune: Add utilest interface to schedtune.
Change-Id: I4e5313f7128f5aa599b7214eaf13679d1f9484ef
Signed-off-by: lakkyung.jung <lakkyung.jung@samsung.com>
lakkyung.jung [Mon, 16 Apr 2018 14:05:00 +0000 (23:05 +0900)]
sched: fair/ems: Add to apply util-est to wake up balance.
Change-Id: Ia3ff1303d3180612308399d0f311d6c278ddefa9
Signed-off-by: lakkyung.jung <lakkyung.jung@samsung.com>
Daeyeong Lee [Mon, 4 Jun 2018 06:57:36 +0000 (15:57 +0900)]
sched: ems: ontime: Rename ontime threshold to boundary.
Change-Id: I124f16d1cc884884fe0f58de5e871b53da6c1372
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Thu, 31 May 2018 07:41:40 +0000 (16:41 +0900)]
sched: ems: ontime: Clear unnecessary sequence to migrate ontime task.
Change-Id: I29083497168ad57712394d12ba98d1997f5a6cba
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Wed, 23 May 2018 06:10:24 +0000 (15:10 +0900)]
sched: ems: ontime: Change new entity's initial ontime load policy.
Change-Id: I4688cd1fb459ca74092b386356843b37d361b07a
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Fri, 18 May 2018 06:51:50 +0000 (15:51 +0900)]
sched: ems: ontime: Allow to migrate to active core within coverage ratio.
Change-Id: I501963c396772bdd5051e7c69e8d642bcbdfac59
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 14 May 2018 10:09:11 +0000 (19:09 +0900)]
sched: ems: ontime: Don't allow to down-migrate heaviest task.
Change-Id: I0daf9e82d69438155ce80c33a6a4709523462491
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Mon, 14 May 2018 01:52:03 +0000 (10:52 +0900)]
sched: ems: ontime: Use fit cpus when ontime migration.
Change-Id: Icea69935638628cb8dc41d38a47a9bc4046110b0
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Fri, 18 May 2018 02:01:56 +0000 (11:01 +0900)]
sched: ems: ontime: Use fit cpus when ontime task wake-up.
Change-Id: I143735486cb003fea16d80144bb67ffaeb2bf01e
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
Daeyeong Lee [Fri, 18 May 2018 01:58:30 +0000 (10:58 +0900)]
sched: ems: ontime: Add API to find fit cpus for heavy task.
Change-Id: I833b0c6997c40eb239836ba54385d3acb782b9ec
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>