Commit Graph

503 Commits

Author SHA1 Message Date
luckyqiu a4cb9df8d6 net: csig toa patch
toa patch from csig luckyqiu@tencent.com

Signed-off-by: luckyqiu <luckyqiu@tencent.com>
2022-02-22 12:36:39 +08:00
luckyqiu 5fea831880 net: csig toa patch
toa patch from csig luckyqiu@tencent.com

Signed-off-by: luckyqiu <luckyqiu@tencent.com>
2022-02-22 10:11:18 +08:00
Menglong Dong 732ef51851 bpf: fix compile error when CGROUP_BPF disabled
Following functions are missed when CGROUP_BPF disabled, and compile
will fail:

BPF_CGROUP_RUN_PROG_TW_CLOSE
BPF_CGROUP_RUN_PROG_UDP_UNHASH
BPF_CGROUP_RUN_PROG_INET_POST_AUTOBIND

Fix it by define them while CGROUP_BPF disabled.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-21 17:22:51 +08:00
Menglong Dong 4c22274eac net: bpf: introduce BPF_CGROUP_UDP_UNHASH eBPF hook
Add new cgroup based eBPF hook 'BPF_CGROUP_UDP_UNHASH' which is called
when UDP sock unhashed. This is used to monitor the release of UDP
sock.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-17 12:58:28 +08:00
Menglong Dong 57a8318a7a net: bpf: use return of BPF_SOCK_OPS_TCP_{CONNECT, LISTEN}_CB
Use the return value of BPF_SOCK_OPS_TCP_CONNECT_CB and
BPF_SOCK_OPS_TCP_LISTEN_CB to determine if the connect() and listen()
should continue.

This is used by eBPF program to check the address and port, and
see if listen() or connect() is allowed.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-17 12:58:28 +08:00
Menglong Dong e22ef12b56 net: bpf: add BPF_CGROUP_TWSK_CLOSE for tcp timewait sock close
For now, 'BPF_SOCK_OPS_STATE_CB' of sock_ops can be used to monitor
the state change of TCP sock. However, once tcp sock change to timewait
sock, 'TCP_CLOSE' event will be passed to the eBPF program, and it's
hard to capture the finish of a TCP connect.

Add 'BPF_CGROUP_TWSK_CLOSE', which will be called when timewait sock
close.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-17 12:58:28 +08:00
Menglong Dong 4c07420add net: bpf: introduce BPF_CGROUP_INET_POST_AUTOBIND attach type
Add new cgroup based eBPF type 'BPF_CGROUP_INET4_POST_AUTOBIND', which
is called after the success of port binding in inet_autobind().

The return value is used to determine if this port is usable, therefore
users have the chance to reject the autobind operation.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-17 12:58:28 +08:00
Menglong Dong 4ab848ee2e net: bpf: handle return value of BPF_CGROUP_RUN_PROG_INET{4,6}_POST_BIND()
The return value of BPF_CGROUP_RUN_PROG_INET{4,6}_POST_BIND() in
__inet_bind() is not handled properly. While the return value
is non-zero, it will set inet_saddr and inet_rcv_saddr to 0 and
exit:

        err = BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk);
        if (err) {
                inet->inet_saddr = inet->inet_rcv_saddr = 0;
                goto out_release_sock;
        }

Let's take UDP for example and see what will happen. For UDP
socket, it will be added to 'udp_prot.h.udp_table->hash' and
'udp_prot.h.udp_table->hash2' after the sk->sk_prot->get_port()
called success. If 'inet->inet_rcv_saddr' is specified here,
then 'sk' will be in the 'hslot2' of 'hash2' that it don't belong
to (because inet_saddr is changed to 0), and UDP packet received
will not be passed to this sock. If 'inet->inet_rcv_saddr' is not
specified here, the sock will work fine, as it can receive packet
properly, which is wired, as the 'bind()' is already failed.

To undo the get_port() operation, introduce the 'put_port' field
for 'struct proto'. For TCP proto, it is inet_put_port(); For UDP
proto, it is udp_lib_unhash(); For icmp proto, it is
ping_unhash().

Therefore, after sys_bind() fail caused by
BPF_CGROUP_RUN_PROG_INET4_POST_BIND(), it will be unbinded, which
means that it can try to be binded to another port.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-02-16 19:17:40 +08:00
katrinzhou 1796147360 fix unknown data type error
Signed-off-by: katrinzhou <katrinzhou@tencent.com>
2022-02-16 19:14:39 +08:00
zgpeng fd57c9e500 Make CFS bandwidth controller burstable
Accumulate unused quota from previous periods, thus accumulated
bandwidth runtime can be used in the following periods. During
accumulation, take care of runtime overflow. Previous non-burstable
CFS bandwidth controller only assign quota to runtime, that saves a lot.

A sysctl parameter cpu_qos_cfs_bw_burst_enabled is introduced as a
switch for burst. It is disabled by default.

Signed-off-by: Huaixin Chang <changhuaixin@linux.alibaba.com>
Signed-off-by: Shanpei Chen <shanpeic@linux.alibaba.com>
2021-12-30 14:50:28 +08:00
Martynas Pumputis 3c3cff42f4 net: retrieve netns cookie via getsocketopt
It's getting more common to run nested container environments for
testing cloud software. One of such examples is Kind [1] which runs a
Kubernetes cluster in Docker containers on a single host. Each container
acts as a Kubernetes node, and thus can run any Pod (aka container)
inside the former. This approach simplifies testing a lot, as it
eliminates complicated VM setups.

Unfortunately, such a setup breaks some functionality when cgroupv2 BPF
programs are used for load-balancing. The load-balancer BPF program
needs to detect whether a request originates from the host netns or a
container netns in order to allow some access, e.g. to a service via a
loopback IP address. Typically, the programs detect this by comparing
netns cookies with the one of the init ns via a call to
bpf_get_netns_cookie(NULL). However, in nested environments the latter
cannot be used given the Kubernetes node's netns is outside the init ns.
To fix this, we need to pass the Kubernetes node netns cookie to the
program in a different way: by extending getsockopt() with a
SO_NETNS_COOKIE option, the orchestrator which runs in the Kubernetes
node netns can retrieve the cookie and pass it to the program instead.

Thus, this is following up on Eric's commit 3d368ab87cf6 ("net:
initialize net->net_cookie at netns setup") to allow retrieval via
SO_NETNS_COOKIE.  This is also in line in how we retrieve socket cookie
via SO_COOKIE.

  [1] https://kind.sigs.k8s.io/

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
Cc: Eric Dumazet <edumazet@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-30 14:50:11 +08:00
John Fastabend b6b0376175 bpf, sk_msg: Add get socket storage helpers
Add helpers to use local socket storage.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/159033907577.12355.14740125020572756560.stgit@john-Precision-5820-Tower
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2021-12-30 14:50:11 +08:00
Eric Dumazet ad06a1e2bb net: initialize net->net_cookie at netns setup
It is simpler to make net->net_cookie a plain u64
written once in setup_net() instead of looping
and using atomic64 helpers.

Lorenz Bauer wants to add SO_NETNS_COOKIE socket option
and this patch would makes his patch series simpler.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-30 14:50:11 +08:00
Daniel Borkmann 3945c7126a bpf, net: Rework cookie generator as per-cpu one
With its use in BPF, the cookie generator can be called very frequently
in particular when used out of cgroup v2 hooks (e.g. connect / sendmsg)
and attached to the root cgroup, for example, when used in v1/v2 mixed
environments. In particular, when there's a high churn on sockets in the
system there can be many parallel requests to the bpf_get_socket_cookie()
and bpf_get_netns_cookie() helpers which then cause contention on the
atomic counter.

As similarly done in f991bd2e1421 ("fs: introduce a per-cpu last_ino
allocator"), add a small helper library that both can use for the 64 bit
counters. Given this can be called from different contexts, we also need
to deal with potential nested calls even though in practice they are
considered extremely rare. One idea as suggested by Eric Dumazet was
to use a reverse counter for this situation since we don't expect 64 bit
overflows anyways; that way, we can avoid bigger gaps in the 64 bit
counter space compared to just batch-wise increase. Even on machines
with small number of cores (e.g. 4) the cookie generation shrinks from
min/max/med/avg (ns) of 22/50/40/38.9 down to 10/35/14/17.3 when run
in parallel from multiple CPUs.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Link: https://lore.kernel.org/bpf/8a80b8d27d3c49f9a14e1d5213c19d8be87d1dc8.1601477936.git.daniel@iogearbox.net
2021-12-30 14:50:11 +08:00
Daniel Borkmann 3c5ec1d024 bpf, net: Fix build issue when net ns not configured
Fix a redefinition of 'net_gen_cookie' error that was overlooked
when net ns is not configured.

Fixes: f318903c0bf4 ("bpf: Add netns cookie and enable it for bpf cgroup hooks")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2021-12-30 14:50:11 +08:00
Mungerjiang 733bc46d36 net:add sysctl to enable/disable forced caps
Turning on GSO by default will make some services (such as TGW) not work properly,
  so turn off GSO by default.Buf for some benchmarks (such as redis), turning on GSO
  will improve performance.Therefore, a sysctl is provided to user.

  Signed-off-by: mungerjiang<mungerjiang@tencent.com>
2021-12-30 14:50:01 +08:00
Mungerjiang 3d73f1c3c6 tcp: switch to GSO being always on
upstream:0a6b2a1dc2a2105f178255fe495eb914b09cb37a

    Oleksandr Natalenko reported performance issues with BBR without FQ
    packet scheduler that were root caused to lack of SG and GSO/TSO on
    his configuration.

    In this mode, TCP internal pacing has to setup a high resolution timer
    for each MSS sent.

    We could implement in TCP a strategy similar to the one adopted
    in commit fefa569a9d4b ("net_sched: sch_fq: account for schedule/timers drifts")
    or decide to finally switch TCP stack to a GSO only mode.

    This has many benefits :

    1) Most TCP developments are done with TSO in mind.
    2) Less high-resolution timers needs to be armed for TCP-pacing
    3) GSO can benefit of xmit_more hint
    4) Receiver GRO is more effective (as if TSO was used for real on sender)
       -> Lower ACK traffic
    5) Write queues have less overhead (one skb holds about 64KB of payload)
    6) SACK coalescing just works.
    7) rtx rb-tree contains less packets, SACK is cheaper.

    This patch implements the minimum patch, but we can remove some legacy
    code as follow ups.

    Tested:

    On 40Gbit link, one netperf -t TCP_STREAM

    BBR+fq:
    sg on:  26 Gbits/sec
    sg off: 15.7 Gbits/sec   (was 2.3 Gbit before patch)

    BBR+pfifo_fast:
    sg on:  24.2 Gbits/sec
    sg off: 14.9 Gbits/sec  (was 0.66 Gbit before patch !!! )

    BBR+fq_codel:
    sg on:  24.4 Gbits/sec
    sg off: 15 Gbits/sec  (was 0.66 Gbit before patch !!! )

    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reported-by: Oleksandr Natalenko <oleksandr@natalenko.name>
    Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-30 14:50:01 +08:00
Mungerjiang 05e8e4dd54 locking/qspinlock: Rename mcs lock/unlock macros and make them more generic
The mcs unlock macro (arch_mcs_lock_handoff) should accept the value to be
	stored into the lock argument as another argument. This allows using the
	same macro in cases where the value to be stored when passing the lock is
	different from 1.

	Signed-off-by: Alex Kogan <alex.kogan@oracle.com>
	Reviewed-by: Steve Sistare <steven.sistare@oracle.com>
	Reviewed-by: Waiman Long <longman@redhat.com>
2021-12-20 11:43:06 +08:00
Peng Hao 146ec6c502 ext4: introduce direct I/O write using iomap infrastructure
commit: 378f32bab3714f04c4e0c3aee4129f6703805550

This patch introduces a new direct I/O write path which makes use of
the iomap infrastructure.

All direct I/O writes are now passed from the ->write_iter() callback
through to the new direct I/O handler ext4_dio_write_iter(). This
function is responsible for calling into the iomap infrastructure via
iomap_dio_rw().

Code snippets from the existing direct I/O write code within
ext4_file_write_iter() such as, checking whether the I/O request is
unaligned asynchronous I/O, or whether the write will result in an
overwrite have effectively been moved out and into the new direct I/O
->write_iter() handler.
The block mapping flags that are eventually passed down to
ext4_map_blocks() from the *_get_block_*() suite of routines have been
taken out and introduced within ext4_iomap_alloc().

For inode extension cases, ext4_handle_inode_extension() is
effectively the function responsible for performing such metadata
updates. This is called after iomap_dio_rw() has returned so that we
can safely determine whether we need to potentially truncate any
allocated blocks that may have been prepared for this direct I/O
write. We don't perform the inode extension, or truncate operations
from the ->end_io() handler as we don't have the original I/O 'length'
available there. The ->end_io() however is responsible fo converting
allocated unwritten extents to written extents.

In the instance of a short write, we fallback and complete the
remainder of the I/O using buffered I/O via
ext4_buffered_write_iter().

The existing buffer_head direct I/O implementation has been removed as
it's now redundant.

[ Fix up ext4_dio_write_iter() per Jan's comments at
  https://lore.kernel.org/r/20191105135932.GN22379@quack2.suse.cz -- TYT ]

Signed-off-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ritesh Harjani <riteshh@linux.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-11-30 10:40:21 +08:00
markwhwu ad9aa4da1e tcp: Change the TCP_PINGPONG_THRESH macro to a variable
The TCP_PINGPONG_THRESH parameter affects nginx performance.
When the default value is set to 1, the requested QPS is 13% higher than when it is set to 3

Use sysctl -w net.core.tcp_pingpong_thresh=%d to change the default value

Signed-off-by: Mark Whwu <markwhwu@tencent.com>
2021-10-29 08:50:28 +00:00
Bin Lai f91939a5b3 sli/cpu: introduce sli max latency metrics
Sli max latency is lightweight latency monitor metrics, the monitor
tool could get the data with a little overhead. And the accuracy of
the metrics is controlled by the sampling frequency of the monitor
tool. When the performance jitter was occurred in the system, we can
get some help from these lateny metris.

Signed-off-by: Bin Lai <robinlai@tencent.com>
Reviewed-by: benbjiang<benbjiang@tencent.com>
Reviewed-by: Mengmeng Chen <bauerchen@tencent.com>
Reviewed-by: mungerjiang <mungerjiang@tencent.com>
2021-10-29 06:51:52 +00:00
mungerjiang 95a8c85b7f sli/cpu: introduce longsys check
When a process is running in the system space, it cann't be preempted until
it return to userspace, even if the process should be reschedule and other
process was ready to run(because the server system close the kernel preempt
by default). This schedule delay may impact the performance of waiting process,
therefor we introduce the longsys check to collect the schedule delay information
of process. The longsys indication could help us spot the possible performance
jitter in the system.

Signed-off-by: Munger jiang <mungerjiang@tencent.com>
Signed-off-by: Bin Lai <robinlai@tencent.com>
Reviewed-by: benbjiang<benbjiang@tencent.com>
Reviewed-by: Bauerchen <bauerchen@tencent.com>
2021-10-29 06:51:52 +00:00
mungerjiang a76d37e2f4 sli: enable sli in cgroup v1
Signed-off-by: Munger jiang <mungerjiang@tencent.com>
Reviewed-by: Bauerchen <bauerchen@tencent.com>
2021-10-29 06:51:52 +00:00
Bin Lai b879b1b64b sli: Introduce memory and sched latency stat infrastructure
Signed-off-by: Munger jiang <mungerjiang@tencent.com>
2021-10-29 06:51:52 +00:00
Bauerchen c07a089a0f tqos/mbuf: export mbuf interface to cpuacct subsys
In cgroup V1, mbuf only exist in cpuacct subsys, so we may need a help
function to store buffer just according process task_struct.

Signed-off-by: Bauerchen <bauerchen@tencent.com>
Reviewed-by: mungerjiang<mungerjiang@tencent.com>
Reviewed-by: benbjiang<benbjiang@tencent.com>
2021-10-29 06:51:52 +00:00
Bauerchen 7795ccbf82 tqos/mbuf: write a help function to get cgroup struct from task_struct.
In order to support cgroup V1 with mbuf and sli, we need a special
cgroup structure, cpuacct subsys cgroup is nice.

We only prepare mbuf and sli for cpuacct cgroup in V1. so first find cpuacct
cgroup and if return NULl or root, just find df1_cgrp.

Signed-off-by: Bauerchen <bauerchen@tencent.com>
Reviewed-by: mungerjiang<mungerjiang@tencent.com>
Reviewed-by: mungerjiang<mungerjiang@tencent.com>
2021-10-29 06:51:52 +00:00
Bauerchen 7600f2ca44 tqos/rqm: Tencent Quality Monitor Buffer
Providing back up buffer for Quality Monitor, can be used to catch key
context when abnormal jitters occur. And application can also use it
to detect system env exception.

Signed-off-by: Bauerchen <bauerchen@tencent.com>
Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Bin Lai <robinlai@tencent.com>
2021-10-29 06:51:52 +00:00
Hongbo Li 589e8a96bc getsockopt: add SO_MARK2 to get the MARK of flow
add SO_MARK2 to get the MARK of flow
backport from tkernel2:
commit c6f2e27f7ad0b97ae0c162f70b6e0375f2270f27

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
Signed-off-by: brookxu <brookxu@tencent.com>
2021-10-29 06:51:37 +00:00
Peng Hao 3df720cae4 mm/lru: revise the comments of lru_lock
Use this new function to replace repeated same code, no func change.

When testing for relock we can avoid the need for RCU locking if we simply
compare the page pgdat and memcg pointers versus those that the lruvec is
holding. By doing this we can avoid the extra pointer walks and accesses of
the memory cgroup.

In addition we can avoid the checks entirely if lruvec is currently NULL.

Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
2021-10-29 06:51:21 +00:00
Peng Hao 1b7478d8d0 mm/lru: replace pgdat lru_lock with lruvec lock
This patch moves per node lru_lock into lruvec, thus bring a lru_lock for
each of memcg per node. So on a large machine, each of memcg don't
have to suffer from per node pgdat->lru_lock competition. They could go
fast with their self lru_lock.

After move memcg charge before lru inserting, page isolation could
serialize page's memcg, then per memcg lruvec lock is stable and could
replace per node lru lock.

In func isolate_migratepages_block, compact_unlock_should_abort and
lock_page_lruvec_irqsave are open coded to work with compact_control.
Also add a debug func in locking which may give some clues if there are
sth out of hands.

Daniel Jordan's testing show 62% improvement on modified readtwice case
on his 2P * 10 core * 2 HT broadwell box.
https://lore.kernel.org/lkml/20200915165807.kpp7uhiw7l3loofu@ca-dmjordan1.us.oracle.com/

On a large machine with memcg enabled but not used, the page's lruvec
seeking pass a few pointers, that may lead to lru_lock holding time
increase and a bit regression.

Hugh Dickins helped on patch polish, thanks!
[flyingpeng: compatibility modification]

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
2021-10-29 06:51:21 +00:00
Peng Hao 821adde85c mm: memcontrol: charge swapin pages on instantiation
Right now, users that are otherwise memory controlled can easily escape
their containment and allocate significant amounts of memory that they're
not being charged for.  That's because swap readahead pages are not being
charged until somebody actually faults them into their page table.  This
can be exploited with MADV_WILLNEED, which triggers arbitrary readahead
allocations without charging the pages.

There are additional problems with the delayed charging of swap pages:

1. To implement refault/workingset detection for anonymous pages, we
   need to have a target LRU available at swapin time, but the LRU is not
   determinable until the page has been charged.

2. To implement per-cgroup LRU locking, we need page->mem_cgroup to be
   stable when the page is isolated from the LRU; otherwise, the locks
   change under us.  But swapcache gets charged after it's already on the
   LRU, and even if we cannot isolate it ourselves (since charging is not
   exactly optional).

The previous patch ensured we always maintain cgroup ownership records for
swap pages.  This patch moves the swapcache charging point from the fault
handler to swapin time to fix all of the above problems.

v2: simplify swapin error checking (Joonsoo)

[hughd@google.com: fix livelock in __read_swap_cache_async()]
[flyingpeng: port New API]
  Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2005212246080.8458@eggly.anvils
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
2021-10-29 06:51:21 +00:00
Peng Hao f784a238c7 mm/compaction: do page isolation first in compaction
Currently, compaction would get the lru_lock and then do page isolation
 which works fine with pgdat->lru_lock, since any page isoltion would
 compete for the lru_lock. If we want to change to memcg lru_lock, we
 have to isolate the page before getting lru_lock, thus isoltion would
 block page's memcg change which relay on page isoltion too. Then we
 could safely use per memcg lru_lock later.

 The new page isolation use previous introduced TestClearPageLRU() +
 pgdat lru locking which will be changed to memcg lru lock later.

 Hugh Dickins <hughd@google.com> fixed following bugs in this patch's
 early version:

 Fix lots of crashes under compaction load: isolate_migratepages_block()
 must clean up appropriately when rejecting a page, setting PageLRU again
 if it had been cleared; and a put_page() after get_page_unless_zero()
 cannot safely be done while holding locked_lruvec - it may turn out to
 be the final put_page(), which will take an lruvec lock when PageLRU.
 And move __isolate_lru_page_prepare back after get_page_unless_zero to
 make trylock_page() safe:
 trylock_page() is not safe to use at this time: its setting PG_locked
 can race with the page being freed or allocated ("Bad page"), and can
 also erase flags being set by one of those "sole owners" of a freshly
 allocated page who use non-atomic __SetPageFlag().

Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
2021-10-29 06:51:21 +00:00
Peng Hao 4702fd8039 mm/lru: introduce TestClearPageLRU
Currently lru_lock still guards both lru list and page's lru bit, that's
ok. but if we want to use specific lruvec lock on the page, we need to
pin down the page's lruvec/memcg during locking. Just taking lruvec
lock first may be undermined by the page's memcg charge/migration. To
fix this problem, we could clear the lru bit out of locking and use
it as pin down action to block the page isolation in memcg changing.

So now a standard steps of page isolation is following:
	1, get_page(); 	       #pin the page avoid to be free
	2, TestClearPageLRU(); #block other isolation like memcg change
	3, spin_lock on lru_lock; #serialize lru list access
	4, delete page from lru list;
The step 2 could be optimzed/replaced in scenarios which page is
unlikely be accessed or be moved between memcgs.

This patch start with the first part: TestClearPageLRU, which combines
PageLRU check and ClearPageLRU into a macro func TestClearPageLRU. This
function will be used as page isolation precondition to prevent other
isolations some where else. Then there are may !PageLRU page on lru
list, need to remove BUG() checking accordingly.

There 2 rules for lru bit now:
1, the lru bit still indicate if a page on lru list, just in some
   temporary moment(isolating), the page may have no lru bit when
   it's on lru list.  but the page still must be on lru list when the
   lru bit set.
2, have to remove lru bit before delete it from lru list.

As Andrew Morton mentioned this change would dirty cacheline for page
isn't on LRU. But the lost would be acceptable in Rong Chen
<rong.a.chen@intel.com> report:
https://lore.kernel.org/lkml/20200304090301.GB5972@shao2-debian/

[flyingpeng: compatibility code porting]
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
2021-10-29 06:51:21 +00:00
Peng Hao b18f5a48c9 Add VM_WARN_ON_ONCE_PAGE() macro.
Since readahead page is charged on memcg too, in theory we don't have to
check this exception now. Before safely remove them all, add a warning
for the unexpected !memcg.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
2021-10-29 06:51:21 +00:00
Peng Hao e1c207b3e7 fuse: add a dev ioctl for recovery
For a simple read-only file system, as long as the connection
 is not broken, the recovery of the user-mode read-only file
 system process can be realized by putting the request of the
 processing list back into the pending list.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
2021-10-13 04:21:54 +00:00
linuszeng 06d37efeef mm: pagecache limit per cgroup support
Signed-off-by: Chen Xiaoguang <xiaoggchen@tencent.com>
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
Reviewed-by: Bin Lai <robinlai@tencent.com>
Reviewed-by: bauerchen <bauerchen@tencent.com>
2021-10-11 14:11:13 +08:00
Fuhai Wang a3472379b7 Revert "tcp: switch to GSO being always on"
This reverts upstream commit 0a6b2a1dc2a2105f178255fe495eb914b09cb37a.
2021-09-24 16:40:43 +08:00
caelli 298d9fcc44 ovl: check return value before using lookup_one_len_unlocked
[commit]: 1434a65ea625c51317ccdf06dabf4bd27d20fa10

After calling lookup_one_len_unlocked inside ovl_lookup_positive_unlocked,
the return dentry pointer is used before checking validity, which may represent
error code.

Signed-off-by: caelli <caelli@tencent.com>
Reviewed-by: benbjiang <benbjiang@tencent.com>
Reviewed-by: mengensun <mengensun@tencent.com>
2021-08-18 07:27:21 +00:00
Ingo Molnar 6d928aeddf compiler.h: Move instrumentation_begin()/end() to new <linux/instrumentation.h> header
commit d19e789f068b3d633cbac430764962f404198022 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Linus pointed out that compiler.h - which is a key header that gets included in every
single one of the 28,000+ kernel files during a kernel build - was bloated in:

  655389666643: ("vmlinux.lds.h: Create section for protection against instrumentation")

Linus noted:

 > I have pulled this, but do we really want to add this to a header file
 > that is _so_ core that it gets included for basically every single
 > file built?
 >
 > I don't even see those instrumentation_begin/end() things used
 > anywhere right now.
 >
 > It seems excessive. That 53 lines is maybe not a lot, but it pushed
 > that header file to over 12kB, and while it's mostly comments, it's
 > extra IO and parsing basically for _every_ single file compiled in the
 > kernel.
 >
 > For what appears to be absolutely zero upside right now, and I really
 > don't see why this should be in such a core header file!

Move these primitives into a new header: <linux/instrumentation.h>, and include that
header in the headers that make use of it.

Unfortunately one of these headers is asm-generic/bug.h, which does get included
in a lot of places, similarly to compiler.h. So the de-bloating effect isn't as
good as we'd like it to be - but at least the interfaces are defined separately.

No change to functionality intended.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200604071921.GA1361070@gmail.com
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
(cherry picked from commit d19e789f068b3d633cbac430764962f404198022)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Peter Zijlstra 2be3d3ef5b x86, kcsan: Add __no_kcsan to noinstr
commit 5ddbc4082e1072eeeae52ff561a88620a05be08f upstream.
Backport summary: for 5.4 kernel fsgsbase support.

The 'noinstr' function attribute means no-instrumentation, this should
very much include *SAN. Because lots of that is broken at present,
only include KCSAN for now, as that is limited to clang11, which has
sane function attribute behaviour.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
(cherry picked from commit 5ddbc4082e1072eeeae52ff561a88620a05be08f)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Denise Cheng ed00a88eb6 kabi: fix kabi reserve place bug
change place of some reserve words because they are placed under dynamic array

Signed-off-by: Denise Cheng <denisecheng@tencent.com>
2021-08-05 09:25:30 +00:00
Kaixu Xia 38e331e321 locking/percpu-rwsem: Use this_cpu_{inc,dec}() for read_count
The __this_cpu*() accessors are (in general) IRQ-unsafe which, given
that percpu-rwsem is a blocking primitive, should be just fine.

However, file_end_write() is used from IRQ context and will cause
load-store issues on architectures where the per-cpu accessors are not
natively irq-safe.

Fix it by using the IRQ-safe this_cpu_*() for operations on
read_count. This will generate more expensive code on a number of
platforms, which might cause a performance regression for some of the
other percpu-rwsem users.

If any such is reported, we can consider alternative solutions.

Fixes: 70fe2f48152e ("aio: fix freeze protection of aio writes")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lkml.kernel.org/r/20200915140750.137881-1-houtao1@huawei.com
2021-07-15 15:53:01 +08:00
Fan Du 15675d9235 mm: Add 'mprotect' hook to struct vm_operations_struct
Upstream commit id:
95bb7c42ac8a94ce3d0eb059ad64430390351ccb

Background
==========

1. SGX enclave pages are populated with data by copying from normal memory
   via ioctl() (SGX_IOC_ENCLAVE_ADD_PAGES), which will be added later in
   this series.
2. It is desirable to be able to restrict those normal memory data sources.
   For instance, to ensure that the source data is executable before
   copying data to an executable enclave page.
3. Enclave page permissions are dynamic (just like normal permissions) and
   can be adjusted at runtime with mprotect().

This creates a problem because the original data source may have long since
vanished at the time when enclave page permissions are established (mmap()
or mprotect()).

The solution (elsewhere in this series) is to force enclave creators to
declare their paging permission *intent* up front to the ioctl().  This
intent can be immediately compared to the source data’s mapping and
rejected if necessary.

The “intent” is also stashed off for later comparison with enclave
PTEs. This ensures that any future mmap()/mprotect() operations
performed by the enclave creator or done on behalf of the enclave
can be compared with the earlier declared permissions.

Problem
=======

There is an existing mmap() hook which allows SGX to perform this
permission comparison at mmap() time.  However, there is no corresponding
->mprotect() hook.

Solution
========

Add a vm_ops->mprotect() hook so that mprotect() operations which are
inconsistent with any page's stashed intent can be rejected by the driver.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Co-developed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Jethro Beekman <jethro@fortanix.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Acked-by: Hillf Danton <hdanton@sina.com>
Cc: linux-mm@kvack.org
Link: https://lkml.kernel.org/r/20201112220135.165028-11-jarkko@kernel.org
2021-07-12 08:56:46 +00:00
denisecheng 320a3efd01 kabi: reserve space for kabi
Signed-off-by: denisecheng <denisecheng@tencent.com>
Signed-off-by: denisecheng <denisecheng@tencent.com>
2021-06-23 07:24:18 +00:00
Kaixu Xia d253516e87 Revert "modules: mark ref_module static"
This reverts commit af16ca3bc7.
2021-05-21 10:00:22 +08:00
Kaixu Xia d75c0e3a62 Revert "modules: mark find_symbol static"
This reverts commit d102b9453d.
2021-05-21 10:00:12 +08:00
Kaixu Xia b47921f414 Revert "modules: mark each_symbol_section static"
This reverts commit 76acd9d24f.
2021-05-21 10:00:03 +08:00
Kaixu Xia c08c9f8424 Revert "modules: rename the licence field in struct symsearch to license"
This reverts commit ae76e6b5ef.
2021-05-21 09:59:29 +08:00
Kaixu Xia d074d452b3 Revert "modules: return licensing information from find_symbol"
This reverts commit 95f888c25e.
2021-05-21 09:59:19 +08:00
Kaixu Xia bc971dc752 Revert "modules: inherit TAINT_PROPRIETARY_MODULE"
This reverts commit bcd7de3c8b.
2021-05-21 09:59:08 +08:00