Skip to content

Commit ef68c8f

Browse files
Jan BeulichIngo Molnar
authored andcommitted
x86: Serialize EFI time accesses on rtc_lock
The EFI specification requires that callers of the time related runtime functions serialize with other CMOS accesses in the kernel, as the EFI time functions may choose to also use the legacy CMOS RTC. Besides fixing a latent bug, this is a prerequisite to safely enable the rtc-efi driver for x86, which ought to be preferred over rtc-cmos on all EFI platforms. Signed-off-by: Jan Beulich <jbeulich@novell.com> Acked-by: Matthew Garrett <mjg59@srcf.ucam.org> Cc: <mjg@redhat.com> Link: http://lkml.kernel.org/r/4E257E33020000780004E319@nat28.tlf.novell.com Signed-off-by: Ingo Molnar <mingo@elte.hu> Cc: Matthew Garrett <mjg@redhat.com>
1 parent ac619f4 commit ef68c8f

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

  • arch/x86/platform/efi

‎arch/x86/platform/efi/efi.c‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,50 @@ early_param("add_efi_memmap", setup_add_efi_memmap);
7979

8080
static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
8181
{
82-
return efi_call_virt2(get_time, tm, tc);
82+
unsigned long flags;
83+
efi_status_t status;
84+
85+
spin_lock_irqsave(&rtc_lock, flags);
86+
status = efi_call_virt2(get_time, tm, tc);
87+
spin_unlock_irqrestore(&rtc_lock, flags);
88+
return status;
8389
}
8490

8591
static efi_status_t virt_efi_set_time(efi_time_t *tm)
8692
{
87-
return efi_call_virt1(set_time, tm);
93+
unsigned long flags;
94+
efi_status_t status;
95+
96+
spin_lock_irqsave(&rtc_lock, flags);
97+
status = efi_call_virt1(set_time, tm);
98+
spin_unlock_irqrestore(&rtc_lock, flags);
99+
return status;
88100
}
89101

90102
static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
91103
efi_bool_t *pending,
92104
efi_time_t *tm)
93105
{
94-
return efi_call_virt3(get_wakeup_time,
95-
enabled, pending, tm);
106+
unsigned long flags;
107+
efi_status_t status;
108+
109+
spin_lock_irqsave(&rtc_lock, flags);
110+
status = efi_call_virt3(get_wakeup_time,
111+
enabled, pending, tm);
112+
spin_unlock_irqrestore(&rtc_lock, flags);
113+
return status;
96114
}
97115

98116
static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
99117
{
100-
return efi_call_virt2(set_wakeup_time,
101-
enabled, tm);
118+
unsigned long flags;
119+
efi_status_t status;
120+
121+
spin_lock_irqsave(&rtc_lock, flags);
122+
status = efi_call_virt2(set_wakeup_time,
123+
enabled, tm);
124+
spin_unlock_irqrestore(&rtc_lock, flags);
125+
return status;
102126
}
103127

104128
static efi_status_t virt_efi_get_variable(efi_char16_t *name,
@@ -164,11 +188,14 @@ static efi_status_t __init phys_efi_set_virtual_address_map(
164188
static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
165189
efi_time_cap_t *tc)
166190
{
191+
unsigned long flags;
167192
efi_status_t status;
168193

194+
spin_lock_irqsave(&rtc_lock, flags);
169195
efi_call_phys_prelog();
170196
status = efi_call_phys2(efi_phys.get_time, tm, tc);
171197
efi_call_phys_epilog();
198+
spin_unlock_irqrestore(&rtc_lock, flags);
172199
return status;
173200
}
174201

0 commit comments

Comments
 (0)