Skip to content

Commit

Permalink
x86/rtc: Replace paravirt rtc check with platform legacy quirk
Browse files Browse the repository at this point in the history
We have 4 types of x86 platforms that disable RTC:

  * Intel MID
  * Lguest - uses paravirt
  * Xen dom-U - uses paravirt
  * x86 on legacy systems annotated with an ACPI legacy flag

We can consolidate all of these into a platform specific legacy
quirk set early in boot through i386_start_kernel() and through
x86_64_start_reservations(). This deals with the RTC quirks which
we can rely on through the hardware subarch, the ACPI check can
be dealt with separately.

For Xen things are bit more complex given that the @X86_SUBARCH_XEN
x86_hardware_subarch is shared on for Xen which uses the PV path for
both domU and dom0. Since the semantics for differentiating between
the two are Xen specific we provide a platform helper to help override
default legacy features -- x86_platform.set_legacy_features(). Use
of this helper is highly discouraged, its only purpose should be
to account for the lack of semantics available within your given
x86_hardware_subarch.

As per 0-day, this bumps the vmlinux size using i386-tinyconfig as
follows:

TOTAL   TEXT   init.text    x86_early_init_platform_quirks()
+70     +62    +62          +43

Only 8 bytes overhead total, as the main increase in size is
all removed via __init.

Suggested-by: Ingo Molnar <[email protected]>
Signed-off-by: Luis R. Rodriguez <[email protected]>
Reviewed-by: Juergen Gross <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
mcgrof authored and Ingo Molnar committed Apr 22, 2016
1 parent 907bb65 commit 8d152e7
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ endif
head-y := arch/x86/kernel/head_$(BITS).o
head-y += arch/x86/kernel/head$(BITS).o
head-y += arch/x86/kernel/head.o
head-y += arch/x86/kernel/platform-quirks.o

libs-y += arch/x86/lib/

Expand Down
6 changes: 0 additions & 6 deletions arch/x86/include/asm/paravirt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ static inline int paravirt_enabled(void)
return pv_info.paravirt_enabled;
}

static inline int paravirt_has_feature(unsigned int feature)
{
WARN_ON_ONCE(!pv_info.paravirt_enabled);
return (pv_info.features & feature);
}

static inline void load_sp0(struct tss_struct *tss,
struct thread_struct *thread)
{
Expand Down
5 changes: 0 additions & 5 deletions arch/x86/include/asm/paravirt_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ struct pv_info {
#endif

int paravirt_enabled;
unsigned int features; /* valid only if paravirt_enabled is set */
const char *name;
};

#define paravirt_has(x) paravirt_has_feature(PV_SUPPORTED_##x)
/* Supported features */
#define PV_SUPPORTED_RTC (1<<0)

struct pv_init_ops {
/*
* Patch may replace one of the defined code sequences with
Expand Down
1 change: 0 additions & 1 deletion arch/x86/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ static inline unsigned long current_top_of_stack(void)
#else
#define __cpuid native_cpuid
#define paravirt_enabled() 0
#define paravirt_has(x) 0

static inline void load_sp0(struct tss_struct *tss,
struct thread_struct *thread)
Expand Down
21 changes: 21 additions & 0 deletions arch/x86/include/asm/x86_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ struct x86_cpuinit_ops {

struct timespec;

/**
* struct x86_legacy_features - legacy x86 features
*
* @rtc: this device has a CMOS real-time clock present
*/
struct x86_legacy_features {
int rtc;
};

/**
* struct x86_platform_ops - platform specific runtime functions
* @calibrate_tsc: calibrate TSC
Expand All @@ -152,6 +161,14 @@ struct timespec;
* @save_sched_clock_state: save state for sched_clock() on suspend
* @restore_sched_clock_state: restore state for sched_clock() on resume
* @apic_post_init: adjust apic if neeeded
* @legacy: legacy features
* @set_legacy_features: override legacy features. Use of this callback
* is highly discouraged. You should only need
* this if your hardware platform requires further
* custom fine tuning far beyong what may be
* possible in x86_early_init_platform_quirks() by
* only using the current x86_hardware_subarch
* semantics.
*/
struct x86_platform_ops {
unsigned long (*calibrate_tsc)(void);
Expand All @@ -165,6 +182,8 @@ struct x86_platform_ops {
void (*save_sched_clock_state)(void);
void (*restore_sched_clock_state)(void);
void (*apic_post_init)(void);
struct x86_legacy_features legacy;
void (*set_legacy_features)(void);
};

struct pci_dev;
Expand All @@ -186,6 +205,8 @@ extern struct x86_cpuinit_ops x86_cpuinit;
extern struct x86_platform_ops x86_platform;
extern struct x86_msi_ops x86_msi;
extern struct x86_io_apic_ops x86_io_apic_ops;

extern void x86_early_init_platform_quirks(void);
extern void x86_init_noop(void);
extern void x86_init_uint_noop(unsigned int unused);

Expand Down
6 changes: 5 additions & 1 deletion arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# Makefile for the linux kernel.
#

extra-y := head_$(BITS).o head$(BITS).o head.o vmlinux.lds
extra-y := head_$(BITS).o
extra-y += head$(BITS).o
extra-y += head.o
extra-y += platform-quirks.o
extra-y += vmlinux.lds

CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)

Expand Down
2 changes: 2 additions & 0 deletions arch/x86/kernel/head32.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ asmlinkage __visible void __init i386_start_kernel(void)
cr4_init_shadow();
sanitize_boot_params(&boot_params);

x86_early_init_platform_quirks();

/* Call the subarch specific early setup function */
switch (boot_params.hdr.hardware_subarch) {
case X86_SUBARCH_INTEL_MID:
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/head64.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void __init x86_64_start_reservations(char *real_mode_data)
if (!boot_params.hdr.version)
copy_bootdata(__va(real_mode_data));

x86_early_init_platform_quirks();
reserve_ebda_region();

switch (boot_params.hdr.hardware_subarch) {
Expand Down
21 changes: 21 additions & 0 deletions arch/x86/kernel/platform-quirks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <linux/kernel.h>
#include <linux/init.h>

#include <asm/setup.h>
#include <asm/bios_ebda.h>

void __init x86_early_init_platform_quirks(void)
{
x86_platform.legacy.rtc = 1;

switch (boot_params.hdr.hardware_subarch) {
case X86_SUBARCH_XEN:
case X86_SUBARCH_LGUEST:
case X86_SUBARCH_INTEL_MID:
x86_platform.legacy.rtc = 0;
break;
}

if (x86_platform.set_legacy_features)
x86_platform.set_legacy_features();
}
7 changes: 2 additions & 5 deletions arch/x86/kernel/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <asm/time.h>
#include <asm/intel-mid.h>
#include <asm/rtc.h>
#include <asm/setup.h>

#ifdef CONFIG_X86_32
/*
Expand Down Expand Up @@ -188,10 +189,6 @@ static __init int add_rtc_cmos(void)
if (of_have_populated_dt())
return 0;

/* Intel MID platforms don't have ioport rtc */
if (intel_mid_identify_cpu())
return -ENODEV;

#ifdef CONFIG_ACPI
if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) {
/* This warning can likely go away again in a year or two. */
Expand All @@ -200,7 +197,7 @@ static __init int add_rtc_cmos(void)
}
#endif

if (paravirt_enabled() && !paravirt_has(RTC))
if (!x86_platform.legacy.rtc)
return -ENODEV;

platform_device_register(&rtc_device);
Expand Down
1 change: 0 additions & 1 deletion arch/x86/lguest/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,6 @@ __init void lguest_init(void)
pv_info.kernel_rpl = 1;
/* Everyone except Xen runs with this set. */
pv_info.shared_kernel_pmd = 1;
pv_info.features = 0;

/*
* We set up all the lguest overrides for sensitive operations. These
Expand Down
10 changes: 7 additions & 3 deletions arch/x86/xen/enlighten.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,6 @@ static const struct pv_info xen_info __initconst = {
#ifdef CONFIG_X86_64
.extra_user_64bit_cs = FLAT_USER_CS64,
#endif
.features = 0,
.name = "Xen",
};

Expand Down Expand Up @@ -1506,6 +1505,11 @@ static void __init xen_pvh_early_guest_init(void)
}
#endif /* CONFIG_XEN_PVH */

static void __init xen_dom0_set_legacy_features(void)
{
x86_platform.legacy.rtc = 1;
}

/* First C function to be called on Xen boot */
asmlinkage __visible void __init xen_start_kernel(void)
{
Expand All @@ -1527,8 +1531,6 @@ asmlinkage __visible void __init xen_start_kernel(void)

/* Install Xen paravirt ops */
pv_info = xen_info;
if (xen_initial_domain())
pv_info.features |= PV_SUPPORTED_RTC;
pv_init_ops = xen_init_ops;
if (!xen_pvh_domain()) {
pv_cpu_ops = xen_cpu_ops;
Expand Down Expand Up @@ -1688,6 +1690,8 @@ asmlinkage __visible void __init xen_start_kernel(void)
.u.firmware_info.type = XEN_FW_KBD_SHIFT_FLAGS,
};

x86_platform.set_legacy_features =
xen_dom0_set_legacy_features;
xen_init_vga(info, xen_start_info->console.dom0.info_size);
xen_start_info->console.domU.mfn = 0;
xen_start_info->console.domU.evtchn = 0;
Expand Down

0 comments on commit 8d152e7

Please sign in to comment.