Commit Graph

8898 Commits

Author SHA1 Message Date
ruippan aa325043ed The system would hang up when the Phytium S2500 communicates with some BMCs after several rounds of transactions, unless we reset the controller timeout counter manually by calling firmware through SMC.
[bugzilla]
https://gitee.com/openeuler/kernel/issues/I4RK58

Signed-off-by: ruippan <ruippan@tencent.com>
2023-06-16 15:33:56 +08:00
Jianping Liu bb73d0802d arm64/config: open CONFIG_IOSCHED_BFQ and CONFIG_BFQ_GROUP_IOSCHED 2022-06-12 16:39:22 +08:00
samuelliao 2a9d284c73 block: fix zero ioutil if io stall or disk enter blocked state
Since commit 5b18b5a737
    block: delete part_round_stats and switch to less precise counting,
io_ticks don't advance if io stall, iostat will show 0% io util.
This patch add back the logical, advance io_ticks if inflight > 0.
show 100% ioutil if io stall. This patch also show 100% ioutil if
queue quiesced, eg: scsi device blocked.

Signed-off-by: samuelliao <samuelliao@tencent.com>
2022-03-16 10:28:02 +08:00
Jeffle Xu 91ee03cd09 block: fix inflight statistics of part0
upstream commit:
	b0d97557ebfc block: fix inflight statistics of part0
without intermit commit:
	a926c7afffcc block: Consider only dispatched requests
	 	     for inflight statistic

The inflight of partition 0 doesn't include inflight IOs to all
sub-partitions, since currently mq calculates inflight of specific
partition by simply camparing the value of the partition pointer.

Thus the following case is possible:

$ cat /sys/block/vda/inflight
       0        0
$ cat /sys/block/vda/vda1/inflight
       0      128

While single queue device (on a previous version, e.g. v3.10) has no
this issue:

$cat /sys/block/sda/sda3/inflight
       0       33
$cat /sys/block/sda/inflight
       0       33

Partition 0 should be specially handled since it represents the whole
disk. This issue is introduced since commit bf0ddaba65dd ("blk-mq: fix
sysfs inflight counter").

Besides, this patch can also fix the inflight statistics of part 0 in
/proc/diskstats. Before this patch, the inflight statistics of part 0
doesn't include that of sub partitions. (I have marked the 'inflight'
field with asterisk.)

$cat /proc/diskstats
 259       0 nvme0n1 45974469 0 367814768 6445794 1 0 1 0 *0* 111062 6445794 0 0 0 0 0 0
 259       2 nvme0n1p1 45974058 0 367797952 6445727 0 0 0 0 *33* 111001 6445727 0 0 0 0 0 0

This is introduced since commit f299b7c7a9de ("blk-mq: provide internal
in-flight variant").

Fixes: bf0ddaba65dd ("blk-mq: fix sysfs inflight counter")
Fixes: f299b7c7a9de ("blk-mq: provide internal in-flight variant")
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[axboe: adapt for 5.11 partition change]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: samuelliao <samuelliao@tencent.com>
2022-03-16 10:28:02 +08:00
Fuhai Wang 6a0f0233f8 irqchip: phytium2500: fixed interrupts are concentrated in one cpu 2021-10-19 08:40:52 +00:00
Fuhai Wang cdbc9c0b3f arm/config: set CONFIG_SCSI_MPT3SAS as module
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2021-10-19 07:18:46 +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
Kim Phillips 5dbc635ccc perf/amd/uncore: Add support for Family 19h L3 PMU
Family 19h introduces change in slice, core and thread specification in
its L3 Performance Event Select (ChL3PmcCfg) h/w register. The change is
incompatible with Family 17h's version of the register.

Introduce a new path in l3_thread_slice_mask() to do things differently
for Family 19h vs. Family 17h, otherwise the new hardware doesn't get
programmed correctly.

Instead of a linear core--thread bitmask, Family 19h takes an encoded
core number, and a separate thread mask. There are new bits that are set
for all cores and all slices, of which only the latter is used, since
the driver counts events for all slices on behalf of the specified CPU.

Also update amd_uncore_init() to base its L2/NB vs. L3/Data Fabric mode
decision based on Family 17h or above, not just 17h and 18h: the Family
19h Data Fabric PMC is compatible with the Family 17h DF PMC.

 [ bp: Touchups. ]

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200313231024.17601-3-kim.phillips@amd.com
2021-09-23 19:21:43 +08:00
Kim Phillips 971d56019a perf/amd/uncore: Make L3 thread mask code more readable
Convert the l3_thread_slice_mask() function to use the more readable
topology_* helper functions, more intuitive variable names like shift
and thread_mask, and BIT_ULL().

No functional changes.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200313231024.17601-2-kim.phillips@amd.com
2021-09-23 19:21:41 +08:00
Kim Phillips b51242b0d7 perf/amd/uncore: Prepare L3 thread mask code for Family 19h
In order to better accommodate the upcoming Family 19h, given
the 80-char line limit, move the existing code into a new
l3_thread_slice_mask() function.

No functional changes.

 [ bp: Touchups. ]

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200313231024.17601-1-kim.phillips@amd.com
2021-09-23 19:21:39 +08:00
Kaixu Xia c5d5d77ee8 EDAC/amd64: Drop some family checks for newer systems
commit dcd01394ce7cd7d25bb15c81ad2e804d8090611f upstream

In general, "pvt->umc != NULL" is used to check if the system is Family
17h+. However, there are a few places that are using direct family
checks.

Replace the remaining family checks with a check for "pvt->umc != NULL".

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200110015651.14887-6-Yazen.Ghannam@amd.com
2021-09-23 19:21:36 +08:00
Yazen Ghannam 2841a3ef53 EDAC/mce_amd: Always load on SMCA systems
MCA error decoding on SMCA systems is not dependent on family. Return
success early if the system supports the SMCA feature.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200110015651.14887-3-Yazen.Ghannam@amd.com
2021-09-23 19:21:33 +08:00
Yazen Ghannam 2035f3ff5c x86/MCE/AMD, EDAC/mce_amd: Add new Load Store unit McaType
Add support for a new version of the Load Store unit bank type as
indicated by its McaType value, which will be present in future SMCA
systems.

Add the new (HWID, MCATYPE) tuple. Reuse the same name, since this is
logically the same to the user.

Also, add the new error descriptions to edac_mce_amd.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200110015651.14887-2-Yazen.Ghannam@amd.com
2021-09-23 19:21:30 +08:00
Kaixu Xia b405c696bc EDAC/amd64: Add family ops for Family 19h Models 00h-0Fh
commit 2eb61c91c3e2738218e55f2eaf7e78a4435c233d upstream

Add family ops to support AMD Family 19h systems. Existing Family 17h
functions can be used. Also, add Family 19h to the list of families to
automatically load the module.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200110015651.14887-5-Yazen.Ghannam@amd.com
2021-09-23 19:21:21 +08:00
Kaixu Xia 47f5d67346 config: set timer frequency to 1000 HZ by default 2021-09-22 17:46:37 +08:00
Fuhai Wang d8c6333085 sgx: fix softlockup when sgx_encl_release
error log:
 watchdog: BUG: soft lockup - CPU#32 stuck for 21s! [pal-sgx:37428]
 Modules linked in: veth xt_conntrack xt_MASQUERADE nf_conntrack_netlink nft_counter xt_addrtype nft_compat nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 overlay edac_core crc32_pclmul ghash_clmulni_intel aesni_intel crypto_simd cryptd glue_helper virtio_balloon nf_tables nfnetlink sunrpc sch_fq_codel binfmt_misc ip_tables crc32c_intel virtio_net sr_mod net_failover failover cdrom floppy autofs4
 CPU: 32 PID: 37428 Comm: pal-sgx Kdump: loaded Tainted: G             L    5.4.119-1-tlinux4-0006 #1
 Hardware name: Smdbmds KVM, BIOS seabios-1.9.1-qemu-project.org 04/01/2014
 RIP: 0010:native_queued_spin_lock_slowpath+0x1a/0x1d0
 Code: bc ff ff ff 5e 5a 5d c3 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 55 8b 05 64 78 b5 01 48 89 e5 85 c0 7e 19 ba 01 00 00 00 8b 07 <85> c0 75 0a f0 0f b1 17 85 c0 75 f2 5d c3 f3 90 eb ec 81 fe 00 01
 RSP: 0018:ffffc90018267cf8 EFLAGS: 00000202 ORIG_RAX: ffffffffffffff13
 RAX: 0000000000000001 RBX: ffffc935ac5816e0 RCX: 0000000000000000
 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffffffff83117240
 RBP: ffffc90018267cf8 R08: 0000000000000003 R09: 0000000000177799
 R10: ffff88ad59cf15c0 R11: 0000000000000001 R12: ffffffff83117240
 R13: ffff88adb82f0040 R14: ffffffffffffffff R15: 0000000000000000
 FS:  0000000000000000(0000) GS:ffff88e996840000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00007f481e8e7ff8 CR3: 00000031729ba001 CR4: 0000000000370ee0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 Call Trace:
 _raw_spin_lock+0x1f/0x30
 sgx_unmark_page_reclaimable+0x22/0x90
 sgx_encl_release+0x75/0x1d0
 sgx_release+0xe6/0x100
 __fput+0xbb/0x250
 ____fput+0xe/0x10
 task_work_run+0x91/0xb0
 do_exit+0x39c/0xb90
 ? kick_process+0x3d/0x40
 ? signal_wake_up_state+0x28/0x30
 do_group_exit+0x43/0xb0
 __x64_sys_exit_group+0x18/0x20
 do_syscall_64+0x5a/0x170
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2021-09-10 17:07:18 +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
Max Gurtovoy 26ed31d84e nvme-pci: initialize tagset numa value to the value of the ctrl
upstream: d4ec47f120537c75184c3dc939d3b2e1bcc8b260

Both admin's and drive's tagsets should be set according the numa node
of the controller.

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2021-08-18 07:22:38 +00:00
Max Gurtovoy 5584b66319 nvme-pci: override the value of the controller's numa node
upsteam: 635333e400e2e678258ea45232415cdadadd7818

Set the node value according to the PCI device numa node.

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2021-08-18 07:22:38 +00:00
Fuhai Wang c8816db521 tcp: fix sysctls showed in none init_net netns
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2021-08-18 07:22:38 +00:00
Fuhai Wang 947b472829 scsi: smartpqi: compat for tk4
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2021-08-17 06:30:07 +00:00
Fuhai Wang ff579791c7 scsi: smartpqi: update driver version to v2.1.8-040
url: https://download.adaptec.com/raid/aac/linux/smartpqi_src_v2.1.8-040.tgz

Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2021-08-17 06:30:07 +00:00
Lai Jiangshan 0526dafa15 x86/entry/64: Remove unneeded kernel CR3 switching
commit c75890700455113c366f795f3d22ee03623835e8 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

When native_load_gs_index() fails on .Lgs_change, CR3 must be kernel
CR3. No need to switch it.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200419144049.1906-2-laijs@linux.alibaba.com

(cherry picked from commit c75890700455113c366f795f3d22ee03623835e8)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Tony Luck fffbcf290c x86/speculation/swapgs: Check FSGSBASE in enabling SWAPGS mitigation
commit 978e1342c3c4d7b20808fd5875d9ac0d57db22ee upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Before enabling FSGSBASE the kernel could safely assume that the content
of GS base was a user address. Thus any speculative access as the result
of a mispredicted branch controlling the execution of SWAPGS would be to
a user address. So systems with speculation-proof SMAP did not need to
add additional LFENCE instructions to mitigate.

With FSGSBASE enabled a hostile user can set GS base to a kernel address.
So they can make the kernel speculatively access data they wish to leak
via a side channel. This means that SMAP provides no protection.

Add FSGSBASE as an additional condition to enable the fence-based SWAPGS
mitigation.

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200528201402.1708239-9-sashal@kernel.org

(cherry picked from commit 978e1342c3c4d7b20808fd5875d9ac0d57db22ee)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 3cbbfad519 selftests/x86: Add a syscall_arg_fault_64 test for negative GSBASE
commit a5d25e01c8146ad8846da4760422e12242fceafe upstream.
Backport summary: for 5.4 kernel fsgsbase support.

If the kernel erroneously allows WRGSBASE and user code writes a
negative value, paranoid_entry will get confused. Check for this by
writing a negative value to GSBASE and doing SYSENTER with TF set. A
successful run looks like:

    [RUN]	SYSENTER with TF, invalid state, and GSBASE < 0
    [SKIP]	Illegal instruction

A failed run causes a kernel hang, and I believe it's because we
double-fault and then get a never ending series of page faults and,
when we exhaust the double fault stack we double fault again,
starting the process over.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/f4f71efc91b9eae5e3dae21c9aee1c70cf5f370e.1590620529.git.luto@kernel.org
(cherry picked from commit a5d25e01c8146ad8846da4760422e12242fceafe)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 6407a0dead x86/process/64: Use FSBSBASE in switch_to() if available
commit 673903495c85137791d5820d690229efe09c8f7b upstream.
Backport summary: for 5.4 kernel fsgsbase support.

With the new FSGSBASE instructions, FS and GSABSE can be efficiently read
and writen in __switch_to().  Use that capability to preserve the full
state.

This will enable user code to do whatever it wants with the new
instructions without any kernel-induced gotchas.  (There can still be
architectural gotchas: movl %gs,%eax; movl %eax,%gs may change GSBASE if
WRGSBASE was used, but users are expected to read the CPU manual before
doing things like that.)

This is a considerable speedup.  It seems to save about 100 cycles
per context switch compared to the baseline 4.6-rc1 behavior on a
Skylake laptop. This is mostly due to avoiding the WRMSR operation.

[ chang: 5~10% performance improvements were seen with a context switch
  benchmark that ran threads with different FS/GSBASE values (to the
  baseline 4.16). Minor edit on the changelog. ]

[ tglx: Masaage changelog ]

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Link: https://lkml.kernel.org/r/1557309753-24073-8-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-6-sashal@kernel.org

(cherry picked from commit 673903495c85137791d5820d690229efe09c8f7b)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 112a934e82 x86/ptrace: Fix 32-bit PTRACE_SETREGS vs fsbase and gsbase
commit 40c45904f818c1f6555294ca27afc5fda4f09e68 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Debuggers expect that doing PTRACE_GETREGS, then poking at a tracee
and maybe letting it run for a while, then doing PTRACE_SETREGS will
put the tracee back where it was.  In the specific case of a 32-bit
tracer and tracee, the PTRACE_GETREGS/SETREGS data structure doesn't
have fs_base or gs_base fields, so FSBASE and GSBASE fields are
never stored anywhere.  Everything used to still work because
nonzero FS or GS would result full reloads of the segment registers
when the tracee resumes, and the bases associated with FS==0 or
GS==0 are irrelevant to 32-bit code.

Adding FSGSBASE support broke this: when FSGSBASE is enabled, FSBASE
and GSBASE are now restored independently of FS and GS for all tasks
when context-switched in.  This means that, if a 32-bit tracer
restores a previous state using PTRACE_SETREGS but the tracee's
pre-restore and post-restore bases don't match, then the tracee is
resumed with the wrong base.

Fix it by explicitly loading the base when a 32-bit tracer pokes FS
or GS on a 64-bit kernel.

Also add a test case.

Fixes: 673903495c85 ("x86/process/64: Use FSBSBASE in switch_to() if available")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/229cc6a50ecbb701abd50fe4ddaf0eda888898cd.1593192140.git.luto@kernel.org

(cherry picked from commit 40c45904f818c1f6555294ca27afc5fda4f09e68)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 3dfbd400a3 selftests/x86: Use __builtin_ia32_read/writeeflags
commit 9297e602adf8d5587d83941c48e4dbae46c8df5f upstream.
Backport summary: for 5.4 kernel fsgsbase support.

The asm to read and write EFLAGS from userspace is horrible.  The
compiler builtins are now available on all supported compilers, so
use them instead.

(The compiler builtins are also unnecessarily ugly, but that's a
 more manageable level of ugliness.)

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/aee4b1cdfc56083eb779ce927b7d3459aad2af76.1604346818.git.luto@kernel.org
(cherry picked from commit 9297e602adf8d5587d83941c48e4dbae46c8df5f)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Thomas Gleixner aed5777e16 Documentation/x86/64: Add documentation for GS/FS addressing mode
commit 82c0c7d24c1a034d94af4595dbd3910d7336a6dc upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Explain how the GS/FS based addressing can be utilized in user space
applications along with the differences between the generic prctl() based
GS/FS base control and the FSGSBASE version available on newer CPUs.

Originally-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200528201402.1708239-15-sashal@kernel.org

(cherry picked from commit 82c0c7d24c1a034d94af4595dbd3910d7336a6dc)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski ad9cda4e0c selftests/x86: Consolidate and fix get/set_eflags() helpers
commit cced0b24bb545bfe74fea96de84adc23c0146b05 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

There are several copies of get_eflags() and set_eflags() and they all are
buggy.  Consolidate them and fix them.  The fixes are:

Add memory clobbers.  These are probably unnecessary but they make sure
that the compiler doesn't move something past one of these calls when it
shouldn't.

Respect the redzone on x86_64.  There has no failure been observed related
to this, but it's definitely a bug.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/982ce58ae8dea2f1e57093ee894760e35267e751.1593191971.git.luto@kernel.org

(cherry picked from commit cced0b24bb545bfe74fea96de84adc23c0146b05)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Borislav Petkov 612a08cfb9 x86/entry/64: Correct the comment over SAVE_AND_SET_GSBASE
commit 0b2c605fa4ee3117c00b97b7af67791576b28f88 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Add the proper explanation why an LFENCE is not needed in the FSGSBASE
case.

Fixes: c82965f9e530 ("x86/entry/64: Handle FSGSBASE enabled paranoid entry/exit")
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200821090710.GE12181@zn.tnic
(cherry picked from commit 0b2c605fa4ee3117c00b97b7af67791576b28f88)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Sean Christopherson cd154cf947 x86/entry/64: Do not use RDPID in paranoid entry to accomodate KVM
commit 6a3ea3e68b8a8a26c4aaac03432ed92269c9a14e upstream.
Backport summary: for 5.4 kernel fsgsbase support.

KVM has an optmization to avoid expensive MRS read/writes on
VMENTER/EXIT. It caches the MSR values and restores them either when
leaving the run loop, on preemption or when going out to user space.

The affected MSRs are not required for kernel context operations. This
changed with the recently introduced mechanism to handle FSGSBASE in the
paranoid entry code which has to retrieve the kernel GSBASE value by
accessing per CPU memory. The mechanism needs to retrieve the CPU number
and uses either LSL or RDPID if the processor supports it.

Unfortunately RDPID uses MSR_TSC_AUX which is in the list of cached and
lazily restored MSRs, which means between the point where the guest value
is written and the point of restore, MSR_TSC_AUX contains a random number.

If an NMI or any other exception which uses the paranoid entry path happens
in such a context, then RDPID returns the random guest MSR_TSC_AUX value.

As a consequence this reads from the wrong memory location to retrieve the
kernel GSBASE value. Kernel GS is used to for all regular this_cpu_*()
operations. If the GSBASE in the exception handler points to the per CPU
memory of a different CPU then this has the obvious consequences of data
corruption and crashes.

As the paranoid entry path is the only place which accesses MSR_TSX_AUX
(via RDPID) and the fallback via LSL is not significantly slower, remove
the RDPID alternative from the entry path and always use LSL.

The alternative would be to write MSR_TSC_AUX on every VMENTER and VMEXIT
which would be inflicting massive overhead on that code path.

[ tglx: Rewrote changelog ]

Fixes: eaad981291ee3 ("x86/entry/64: Introduce the FIND_PERCPU_BASE macro")
Reported-by: Tom Lendacky <thomas.lendacky@amd.com>
Debugged-by: Tom Lendacky <thomas.lendacky@amd.com>
Suggested-by: Andy Lutomirski <luto@kernel.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200821105229.18938-1-pbonzini@redhat.com
(cherry picked from commit 6a3ea3e68b8a8a26c4aaac03432ed92269c9a14e)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski be2c541692 x86/fsgsbase: Fix Xen PV support
commit d029bff60aa6c7eab281d52602b6a7a971615324 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

On Xen PV, SWAPGS doesn't work.  Teach __rdfsbase_inactive() and
__wrgsbase_inactive() to use rdmsrl()/wrmsrl() on Xen PV.  The Xen
pvop code will understand this and issue the correct hypercalls.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/f07c08f178fe9711915862b656722a207cd52c28.1593192140.git.luto@kernel.org

(cherry picked from commit d029bff60aa6c7eab281d52602b6a7a971615324)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +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
Borislav Petkov 42e93d02c4 x86/fsgsbase: Replace static_cpu_has() with boot_cpu_has()
commit 5f1dd4dda5c8796c405e856aaa11e187f6885924 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

ptrace and prctl() are not really fast paths to warrant the use of
static_cpu_has() and cause alternatives patching for no good reason.
Replace with boot_cpu_has() which is simple and fast enough.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200818103715.32736-1-bp@alien8.de
(cherry picked from commit 5f1dd4dda5c8796c405e856aaa11e187f6885924)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 5cfaa84294 selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests
commit 716572b0003ef67a4889bd7d85baf5099c5a0248 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Setting GS to 1, 2, or 3 causes a nonsensical part of the IRET microcode
to change GS back to zero on a return from kernel mode to user mode. The
result is that these tests fail randomly depending on when interrupts
happen. Detect when this happens and let the test pass.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/7567fd44a1d60a9424f25b19a998f12149993b0d.1604346596.git.luto@kernel.org
(cherry picked from commit 716572b0003ef67a4889bd7d85baf5099c5a0248)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 0a274afbdd selftests/x86/fsgsbase: Add a missing memory constraint
commit 8e259031c67a5ea0666428edb64c89e8c6ebd18e upstream.
Backport summary: for 5.4 kernel fsgsbase support.

The manual call to set_thread_area() via int $0x80 was missing any
indication that the descriptor was a pointer, causing gcc to
occasionally generate wrong code.  Add the missing constraint.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/432968af67259ca92d68b774a731aff468eae610.1593192140.git.luto@kernel.org

(cherry picked from commit 8e259031c67a5ea0666428edb64c89e8c6ebd18e)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski bf378adf19 selftests/x86/fsgsbase: Fix a comment in the ptrace_write_gsbase test
commit 979c2c4247cafd8a91628a7306b6871efbd12fdb upstream.
Backport summary: for 5.4 kernel fsgsbase support.

A comment was unclear.  Fix it.

Fixes: 5e7ec8578fa3 ("selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/901034a91a40169ec84f1f699ea86704dff762e4.1593192140.git.luto@kernel.org

(cherry picked from commit 979c2c4247cafd8a91628a7306b6871efbd12fdb)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae fb351b7b49 selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE
commit 5e7ec8578fa3dada50c50f5b234fa8d154b76349 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

This validates that GS selector and base are independently preserved in
ptrace commands.

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200528201402.1708239-17-sashal@kernel.org

(cherry picked from commit 5e7ec8578fa3dada50c50f5b234fa8d154b76349)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae a04cecb243 selftests/x86/fsgsbase: Test GS selector on ptracer-induced GS base write
commit 291fd83569e10f3d305cd8adb62f6ec00f759dc6 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

The test validates that the selector is not changed when a ptracer writes
the ptracee's GS base.

Originally-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200528201402.1708239-16-sashal@kernel.org

(cherry picked from commit 291fd83569e10f3d305cd8adb62f6ec00f759dc6)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae f7db241bb0 x86/ptrace: Prevent ptrace from clearing the FS/GS selector
commit fddf8ba1e48860211c9639d00883833b42fcc1e0 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

When a ptracer writes a ptracee's FS/GSBASE with a different value, the
selector is also cleared. This behavior is not correct as the selector
should be preserved.

Update only the base value and leave the selector intact. To simplify the
code further remove the conditional checking for the same value as this
code is not performance critical.

The only recognizable downside of this change is when the selector is
already nonzero on write. The base will be reloaded according to the
selector. But the case is highly unexpected in real usages.

[ tglx: Massage changelog ]

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/9040CFCD-74BD-4C17-9A01-B9B713CF6B10@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-2-sashal@kernel.org

(cherry picked from commit fddf8ba1e48860211c9639d00883833b42fcc1e0)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 1cb7ca388e x86/ptrace: Document FSBASE and GSBASE ABI oddities
commit 56f2ab41b652251f336a0f471b1033afeaedd161 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit 56f2ab41b652251f336a0f471b1033afeaedd161)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andi Kleen 379ea53cc1 x86/elf: Enumerate kernel FSGSBASE capability in AT_HWCAP2
commit 742c45c3ecc9255e15eddbbcee44fd8de401cf1c upstream.
Backport summary: for 5.4 kernel fsgsbase support.

The kernel needs to explicitly enable FSGSBASE. So, the application needs
to know if it can safely use these instructions. Just looking at the CPUID
bit is not enough because it may be running in a kernel that does not
enable the instructions.

One way for the application would be to just try and catch the SIGILL.
But that is difficult to do in libraries which may not want to overwrite
the signal handlers of the main application.

Enumerate the enabled FSGSBASE capability in bit 1 of AT_HWCAP2 in the ELF
aux vector. AT_HWCAP2 is already used by PPC for similar purposes.

The application can access it open coded or by using the getauxval()
function in newer versions of glibc.

[ tglx: Massaged changelog ]

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-18-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-14-sashal@kernel.org

(cherry picked from commit 742c45c3ecc9255e15eddbbcee44fd8de401cf1c)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Andy Lutomirski 4c7481853c x86/cpu: Enable FSGSBASE on 64bit by default and add a chicken bit
commit b745cfba44c152c34363eea9e052367b6b1d652b upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Now that FSGSBASE is fully supported, remove unsafe_fsgsbase, enable
FSGSBASE by default, and add nofsgsbase to disable it.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Link: https://lkml.kernel.org/r/1557309753-24073-17-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-13-sashal@kernel.org

(cherry picked from commit b745cfba44c152c34363eea9e052367b6b1d652b)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae 10e76dd6e4 x86/entry/64: Handle FSGSBASE enabled paranoid entry/exit
commit c82965f9e53005c1c62632c468968293262056cb upstream.
Backport summary: for 5.4 kernel fsgsbase support.

Without FSGSBASE, user space cannot change GSBASE other than through a
PRCTL. The kernel enforces that the user space GSBASE value is postive as
negative values are used for detecting the kernel space GSBASE value in the
paranoid entry code.

If FSGSBASE is enabled, user space can set arbitrary GSBASE values without
kernel intervention, including negative ones, which breaks the paranoid
entry assumptions.

To avoid this, paranoid entry needs to unconditionally save the current
GSBASE value independent of the interrupted context, retrieve and write the
kernel GSBASE and unconditionally restore the saved value on exit. The
restore happens either in paranoid_exit or in the special exit path of the
NMI low level code.

All other entry code pathes which use unconditional SWAPGS are not affected
as they do not depend on the actual content.

[ tglx: Massaged changelogs and comments ]

Suggested-by: H. Peter Anvin <hpa@zytor.com>
Suggested-by: Andy Lutomirski <luto@kernel.org>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-13-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-12-sashal@kernel.org

(cherry picked from commit c82965f9e53005c1c62632c468968293262056cb)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae 59dad666b4 x86/entry/64: Introduce the FIND_PERCPU_BASE macro
commit eaad981291ee36efee15a5e515d4598ae94ace07 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

GSBASE is used to find per-CPU data in the kernel. But when GSBASE is
unknown, the per-CPU base can be found from the per_cpu_offset table with a
CPU NR.  The CPU NR is extracted from the limit field of the CPUNODE entry
in GDT, or by the RDPID instruction. This is a prerequisite for using
FSGSBASE in the low level entry code.

Also, add the GAS-compatible RDPID macro as binutils 2.23 do not support
it. Support is added in version 2.27.

[ tglx: Massaged changelog ]

Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-12-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-11-sashal@kernel.org

(cherry picked from commit eaad981291ee36efee15a5e515d4598ae94ace07)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae ff43646213 x86/entry/64: Switch CR3 before SWAPGS in paranoid entry
commit 96b2371413e8f636a5f25c42a933af21c35a2a41 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

When FSGSBASE is enabled, the GSBASE handling in paranoid entry will need
to retrieve the kernel GSBASE which requires that the kernel page table is
active.

As the CR3 switch to the kernel page tables (PTI is active) does not depend
on kernel GSBASE, move the CR3 switch in front of the GSBASE handling.

Comment the EBX content while at it.

No functional change.

[ tglx: Rewrote changelog and comments ]

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-11-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-10-sashal@kernel.org

(cherry picked from commit 96b2371413e8f636a5f25c42a933af21c35a2a41)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00
Chang S. Bae ea57bf323e x86/process/64: Use FSGSBASE instructions on thread copy and ptrace
commit 005f141e5d5e05d3986539567d0bc5aa2f4dc640 upstream.
Backport summary: for 5.4 kernel fsgsbase support.

When FSGSBASE is enabled, copying threads and reading fsbase and gsbase
using ptrace must read the actual values.

When copying a thread, use save_fsgs() and copy the saved values.  For
ptrace, the bases must be read from memory regardless of the selector if
FSGSBASE is enabled.

[ tglx: Invoke __rdgsbase_inactive() with interrupts disabled ]
[ luto: Massage changelog ]

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-9-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-8-sashal@kernel.org

(cherry picked from commit 005f141e5d5e05d3986539567d0bc5aa2f4dc640)
Signed-off-by: Ethan Zhao <Haifeng.Zhao@intel.com>
2021-08-17 06:29:11 +00:00