Commit a0e2bf7c authored by Juergen Gross's avatar Juergen Gross Committed by Borislav Petkov
Browse files

x86/paravirt: Switch time pvops functions to use static_call()



The time pvops functions are the only ones left which might be
used in 32-bit mode and which return a 64-bit value.

Switch them to use the static_call() mechanism instead of pvops, as
this allows quite some simplification of the pvops implementation.

Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210311142319.4723-5-jgross@suse.com
parent 6ea312d9
Loading
Loading
Loading
Loading
+5 −9
Original line number Original line Diff line number Diff line
@@ -3,23 +3,19 @@
#define _ASM_ARM_PARAVIRT_H
#define _ASM_ARM_PARAVIRT_H


#ifdef CONFIG_PARAVIRT
#ifdef CONFIG_PARAVIRT
#include <linux/static_call_types.h>

struct static_key;
struct static_key;
extern struct static_key paravirt_steal_enabled;
extern struct static_key paravirt_steal_enabled;
extern struct static_key paravirt_steal_rq_enabled;
extern struct static_key paravirt_steal_rq_enabled;


struct pv_time_ops {
u64 dummy_steal_clock(int cpu);
	unsigned long long (*steal_clock)(int cpu);
};

struct paravirt_patch_template {
	struct pv_time_ops time;
};


extern struct paravirt_patch_template pv_ops;
DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);


static inline u64 paravirt_steal_clock(int cpu)
static inline u64 paravirt_steal_clock(int cpu)
{
{
	return pv_ops.time.steal_clock(cpu);
	return static_call(pv_steal_clock)(cpu);
}
}
#endif
#endif


+7 −2
Original line number Original line Diff line number Diff line
@@ -9,10 +9,15 @@
#include <linux/export.h>
#include <linux/export.h>
#include <linux/jump_label.h>
#include <linux/jump_label.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/static_call.h>
#include <asm/paravirt.h>
#include <asm/paravirt.h>


struct static_key paravirt_steal_enabled;
struct static_key paravirt_steal_enabled;
struct static_key paravirt_steal_rq_enabled;
struct static_key paravirt_steal_rq_enabled;


struct paravirt_patch_template pv_ops;
static u64 native_steal_clock(int cpu)
EXPORT_SYMBOL_GPL(pv_ops);
{
	return 0;
}

DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock);
+5 −9
Original line number Original line Diff line number Diff line
@@ -3,23 +3,19 @@
#define _ASM_ARM64_PARAVIRT_H
#define _ASM_ARM64_PARAVIRT_H


#ifdef CONFIG_PARAVIRT
#ifdef CONFIG_PARAVIRT
#include <linux/static_call_types.h>

struct static_key;
struct static_key;
extern struct static_key paravirt_steal_enabled;
extern struct static_key paravirt_steal_enabled;
extern struct static_key paravirt_steal_rq_enabled;
extern struct static_key paravirt_steal_rq_enabled;


struct pv_time_ops {
u64 dummy_steal_clock(int cpu);
	unsigned long long (*steal_clock)(int cpu);
};

struct paravirt_patch_template {
	struct pv_time_ops time;
};


extern struct paravirt_patch_template pv_ops;
DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);


static inline u64 paravirt_steal_clock(int cpu)
static inline u64 paravirt_steal_clock(int cpu)
{
{
	return pv_ops.time.steal_clock(cpu);
	return static_call(pv_steal_clock)(cpu);
}
}


int __init pv_time_init(void);
int __init pv_time_init(void);
+9 −4
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/reboot.h>
#include <linux/reboot.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/static_call.h>


#include <asm/paravirt.h>
#include <asm/paravirt.h>
#include <asm/pvclock-abi.h>
#include <asm/pvclock-abi.h>
@@ -26,8 +27,12 @@
struct static_key paravirt_steal_enabled;
struct static_key paravirt_steal_enabled;
struct static_key paravirt_steal_rq_enabled;
struct static_key paravirt_steal_rq_enabled;


struct paravirt_patch_template pv_ops;
static u64 native_steal_clock(int cpu)
EXPORT_SYMBOL_GPL(pv_ops);
{
	return 0;
}

DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock);


struct pv_time_stolen_time_region {
struct pv_time_stolen_time_region {
	struct pvclock_vcpu_stolen_time *kaddr;
	struct pvclock_vcpu_stolen_time *kaddr;
@@ -45,7 +50,7 @@ static int __init parse_no_stealacc(char *arg)
early_param("no-steal-acc", parse_no_stealacc);
early_param("no-steal-acc", parse_no_stealacc);


/* return stolen time in ns by asking the hypervisor */
/* return stolen time in ns by asking the hypervisor */
static u64 pv_steal_clock(int cpu)
static u64 para_steal_clock(int cpu)
{
{
	struct pv_time_stolen_time_region *reg;
	struct pv_time_stolen_time_region *reg;


@@ -150,7 +155,7 @@ int __init pv_time_init(void)
	if (ret)
	if (ret)
		return ret;
		return ret;


	pv_ops.time.steal_clock = pv_steal_clock;
	static_call_update(pv_steal_clock, para_steal_clock);


	static_key_slow_inc(&paravirt_steal_enabled);
	static_key_slow_inc(&paravirt_steal_enabled);
	if (steal_acc)
	if (steal_acc)
+1 −0
Original line number Original line Diff line number Diff line
@@ -777,6 +777,7 @@ if HYPERVISOR_GUEST


config PARAVIRT
config PARAVIRT
	bool "Enable paravirtualization code"
	bool "Enable paravirtualization code"
	depends on HAVE_STATIC_CALL
	help
	help
	  This changes the kernel so it can modify itself when it is run
	  This changes the kernel so it can modify itself when it is run
	  under a hypervisor, potentially improving performance significantly
	  under a hypervisor, potentially improving performance significantly
Loading