mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
s390/cpufeature: Convert MACHINE_HAS_GS to cpu_has_gs()
Convert MACHINE_HAS_... to cpu_has_...() which uses test_facility() instead of testing the machine_flags lowcore member if the feature is present. test_facility() generates better code since it results in a static branch without accessing memory. The branch is patched via alternatives by the decompressor depending on the availability of the required facility. Reviewed-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
This commit is contained in:
committed by
Vasily Gorbik
parent
15a36036e7
commit
42805261fc
@@ -22,6 +22,7 @@ enum {
|
||||
|
||||
int cpu_have_feature(unsigned int nr);
|
||||
|
||||
#define cpu_has_gs() test_facility(133)
|
||||
#define cpu_has_rdp() test_facility(194)
|
||||
#define cpu_has_seq_insn() test_facility(85)
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#define MACHINE_FLAG_TLB_LC BIT(12)
|
||||
#define MACHINE_FLAG_TLB_GUEST BIT(14)
|
||||
#define MACHINE_FLAG_NX BIT(15)
|
||||
#define MACHINE_FLAG_GS BIT(16)
|
||||
#define MACHINE_FLAG_SCC BIT(17)
|
||||
#define MACHINE_FLAG_PCI_MIO BIT(18)
|
||||
|
||||
@@ -90,7 +89,6 @@ extern unsigned long mio_wb_bit_mask;
|
||||
#define MACHINE_HAS_TLB_LC (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_LC)
|
||||
#define MACHINE_HAS_TLB_GUEST (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_GUEST)
|
||||
#define MACHINE_HAS_NX (get_lowcore()->machine_flags & MACHINE_FLAG_NX)
|
||||
#define MACHINE_HAS_GS (get_lowcore()->machine_flags & MACHINE_FLAG_GS)
|
||||
#define MACHINE_HAS_SCC (get_lowcore()->machine_flags & MACHINE_FLAG_SCC)
|
||||
#define MACHINE_HAS_PCI_MIO (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO)
|
||||
|
||||
|
||||
@@ -255,8 +255,6 @@ static __init void detect_machine_facilities(void)
|
||||
system_ctl_set_bit(0, CR0_VECTOR_BIT);
|
||||
if (test_facility(130))
|
||||
get_lowcore()->machine_flags |= MACHINE_FLAG_NX;
|
||||
if (test_facility(133))
|
||||
get_lowcore()->machine_flags |= MACHINE_FLAG_GS;
|
||||
if (test_facility(139) && (tod_clock_base.tod >> 63)) {
|
||||
/* Enabled signed clock comparator comparisons */
|
||||
get_lowcore()->machine_flags |= MACHINE_FLAG_SCC;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
*/
|
||||
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/syscalls.h>
|
||||
#include <linux/signal.h>
|
||||
@@ -109,7 +110,7 @@ static int gs_broadcast(void)
|
||||
SYSCALL_DEFINE2(s390_guarded_storage, int, command,
|
||||
struct gs_cb __user *, gs_cb)
|
||||
{
|
||||
if (!MACHINE_HAS_GS)
|
||||
if (!cpu_has_gs())
|
||||
return -EOPNOTSUPP;
|
||||
switch (command) {
|
||||
case GS_ENABLE:
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/ftrace.h>
|
||||
#include <linux/debug_locks.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <asm/guarded_storage.h>
|
||||
#include <asm/pfault.h>
|
||||
#include <asm/cio.h>
|
||||
@@ -94,7 +95,7 @@ static noinline void __machine_kdump(void *image)
|
||||
mcesa = __va(get_lowcore()->mcesad & MCESA_ORIGIN_MASK);
|
||||
if (cpu_has_vx())
|
||||
save_vx_regs((__vector128 *) mcesa->vector_save_area);
|
||||
if (MACHINE_HAS_GS) {
|
||||
if (cpu_has_gs()) {
|
||||
local_ctl_store(2, &cr2_old.reg);
|
||||
cr2_new = cr2_old;
|
||||
cr2_new.gse = 1;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/kernel_stat.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/entry-common.h>
|
||||
@@ -45,7 +46,7 @@ static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
|
||||
|
||||
static inline int nmi_needs_mcesa(void)
|
||||
{
|
||||
return cpu_has_vx() || MACHINE_HAS_GS;
|
||||
return cpu_has_vx() || cpu_has_gs();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -61,7 +62,7 @@ void __init nmi_alloc_mcesa_early(u64 *mcesad)
|
||||
if (!nmi_needs_mcesa())
|
||||
return;
|
||||
*mcesad = __pa(&boot_mcesa);
|
||||
if (MACHINE_HAS_GS)
|
||||
if (cpu_has_gs())
|
||||
*mcesad |= ilog2(MCESA_MAX_SIZE);
|
||||
}
|
||||
|
||||
@@ -73,14 +74,14 @@ int nmi_alloc_mcesa(u64 *mcesad)
|
||||
*mcesad = 0;
|
||||
if (!nmi_needs_mcesa())
|
||||
return 0;
|
||||
size = MACHINE_HAS_GS ? MCESA_MAX_SIZE : MCESA_MIN_SIZE;
|
||||
size = cpu_has_gs() ? MCESA_MAX_SIZE : MCESA_MIN_SIZE;
|
||||
origin = kmalloc(size, GFP_KERNEL);
|
||||
if (!origin)
|
||||
return -ENOMEM;
|
||||
/* The pointer is stored with mcesa_bits ORed in */
|
||||
kmemleak_not_leak(origin);
|
||||
*mcesad = __pa(origin);
|
||||
if (MACHINE_HAS_GS)
|
||||
if (cpu_has_gs())
|
||||
*mcesad |= ilog2(MCESA_MAX_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/stop_machine.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/random.h>
|
||||
@@ -244,7 +245,7 @@ static int __init setup_hwcaps(void)
|
||||
elf_hwcap |= HWCAP_NNPA;
|
||||
|
||||
/* guarded storage */
|
||||
if (MACHINE_HAS_GS)
|
||||
if (cpu_has_gs())
|
||||
elf_hwcap |= HWCAP_GS;
|
||||
|
||||
if (MACHINE_HAS_PCI_MIO)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/sched/task_stack.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/smp.h>
|
||||
#include <linux/errno.h>
|
||||
@@ -75,7 +76,7 @@ void update_cr_regs(struct task_struct *task)
|
||||
}
|
||||
}
|
||||
/* Take care of enable/disable of guarded storage. */
|
||||
if (MACHINE_HAS_GS) {
|
||||
if (cpu_has_gs()) {
|
||||
cr2_new.gse = 0;
|
||||
if (task->thread.gs_cb)
|
||||
cr2_new.gse = 1;
|
||||
@@ -1033,7 +1034,7 @@ static int s390_gs_cb_get(struct task_struct *target,
|
||||
{
|
||||
struct gs_cb *data = target->thread.gs_cb;
|
||||
|
||||
if (!MACHINE_HAS_GS)
|
||||
if (!cpu_has_gs())
|
||||
return -ENODEV;
|
||||
if (!data)
|
||||
return -ENODATA;
|
||||
@@ -1050,7 +1051,7 @@ static int s390_gs_cb_set(struct task_struct *target,
|
||||
struct gs_cb gs_cb = { }, *data = NULL;
|
||||
int rc;
|
||||
|
||||
if (!MACHINE_HAS_GS)
|
||||
if (!cpu_has_gs())
|
||||
return -ENODEV;
|
||||
if (!target->thread.gs_cb) {
|
||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
||||
@@ -1087,7 +1088,7 @@ static int s390_gs_bc_get(struct task_struct *target,
|
||||
{
|
||||
struct gs_cb *data = target->thread.gs_bc_cb;
|
||||
|
||||
if (!MACHINE_HAS_GS)
|
||||
if (!cpu_has_gs())
|
||||
return -ENODEV;
|
||||
if (!data)
|
||||
return -ENODATA;
|
||||
@@ -1101,7 +1102,7 @@ static int s390_gs_bc_set(struct task_struct *target,
|
||||
{
|
||||
struct gs_cb *data = target->thread.gs_bc_cb;
|
||||
|
||||
if (!MACHINE_HAS_GS)
|
||||
if (!cpu_has_gs())
|
||||
return -ENODEV;
|
||||
if (!data) {
|
||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#define KMSG_COMPONENT "cpu"
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/memblock.h>
|
||||
#include <linux/export.h>
|
||||
@@ -561,10 +562,10 @@ int smp_store_status(int cpu)
|
||||
if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_STATUS_AT_ADDRESS,
|
||||
pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
|
||||
return -EIO;
|
||||
if (!cpu_has_vx() && !MACHINE_HAS_GS)
|
||||
if (!cpu_has_vx() && !cpu_has_gs())
|
||||
return 0;
|
||||
pa = lc->mcesad & MCESA_ORIGIN_MASK;
|
||||
if (MACHINE_HAS_GS)
|
||||
if (cpu_has_gs())
|
||||
pa |= lc->mcesad & MCESA_LC_MASK;
|
||||
if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_ADDITIONAL_STATUS,
|
||||
pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define KMSG_COMPONENT "kvm-s390"
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/kvm_host.h>
|
||||
#include <linux/hrtimer.h>
|
||||
@@ -577,7 +578,7 @@ static int __write_machine_check(struct kvm_vcpu *vcpu,
|
||||
/* take care of lazy register loading */
|
||||
kvm_s390_fpu_store(vcpu->run);
|
||||
save_access_regs(vcpu->run->s.regs.acrs);
|
||||
if (MACHINE_HAS_GS && vcpu->arch.gs_enabled)
|
||||
if (cpu_has_gs() && vcpu->arch.gs_enabled)
|
||||
save_gs_cb(current->thread.gs_cb);
|
||||
|
||||
/* Extended save area */
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <linux/mman.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/timer.h>
|
||||
@@ -5171,7 +5172,7 @@ static void sync_regs_fmt2(struct kvm_vcpu *vcpu)
|
||||
vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
|
||||
vcpu->arch.sie_block->fpf |= kvm_run->s.regs.bpbc ? FPF_BPBC : 0;
|
||||
}
|
||||
if (MACHINE_HAS_GS) {
|
||||
if (cpu_has_gs()) {
|
||||
preempt_disable();
|
||||
local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT);
|
||||
if (current->thread.gs_cb) {
|
||||
@@ -5237,7 +5238,7 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
|
||||
kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea;
|
||||
kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
|
||||
kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
|
||||
if (MACHINE_HAS_GS) {
|
||||
if (cpu_has_gs()) {
|
||||
preempt_disable();
|
||||
local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT);
|
||||
if (vcpu->arch.gs_enabled)
|
||||
|
||||
Reference in New Issue
Block a user