Skip to content

Commit d7a0dab

Browse files
committed
Merge branch 'core-smp-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull core SMP updates from Ingo Molnar: "Two main change is generic vCPU pinning and physical CPU SMP-call support, for Xen to be able to perform certain calls on specific physical CPUs - by Juergen Gross" * 'core-smp-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: smp: Allocate smp_call_on_cpu() workqueue on stack too hwmon: Use smp_call_on_cpu() for dell-smm i8k dcdbas: Make use of smp_call_on_cpu() xen: Add xen_pin_vcpu() to support calling functions on a dedicated pCPU smp: Add function to execute a function synchronously on a CPU virt, sched: Add generic vCPU pinning support xen: Sync xen header
2 parents 4b97893 + 8db5494 commit d7a0dab

11 files changed

Lines changed: 274 additions & 59 deletions

File tree

‎MAINTAINERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8860,6 +8860,7 @@ S: Supported
88608860
F: Documentation/virtual/paravirt_ops.txt
88618861
F: arch/*/kernel/paravirt*
88628862
F: arch/*/include/asm/paravirt.h
8863+
F: include/linux/hypervisor.h
88638864

88648865
PARIDE DRIVERS FOR PARALLEL PORT IDE DEVICES
88658866
M: Tim Waugh <tim@cyberelk.net>

‎arch/x86/include/asm/hypervisor.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ struct hypervisor_x86 {
4343

4444
/* X2APIC detection (run once per boot) */
4545
bool (*x2apic_available)(void);
46+
47+
/* pin current vcpu to specified physical cpu (run rarely) */
48+
void (*pin_vcpu)(int);
4649
};
4750

4851
extern const struct hypervisor_x86 *x86_hyper;
@@ -56,6 +59,7 @@ extern const struct hypervisor_x86 x86_hyper_kvm;
5659
extern void init_hypervisor(struct cpuinfo_x86 *c);
5760
extern void init_hypervisor_platform(void);
5861
extern bool hypervisor_x2apic_available(void);
62+
extern void hypervisor_pin_vcpu(int cpu);
5963
#else
6064
static inline void init_hypervisor(struct cpuinfo_x86 *c) { }
6165
static inline void init_hypervisor_platform(void) { }

‎arch/x86/kernel/cpu/hypervisor.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ bool __init hypervisor_x2apic_available(void)
8686
x86_hyper->x2apic_available &&
8787
x86_hyper->x2apic_available();
8888
}
89+
90+
void hypervisor_pin_vcpu(int cpu)
91+
{
92+
if (!x86_hyper)
93+
return;
94+
95+
if (x86_hyper->pin_vcpu)
96+
x86_hyper->pin_vcpu(cpu);
97+
else
98+
WARN_ONCE(1, "vcpu pinning requested but not supported!\n");
99+
}

‎arch/x86/xen/enlighten.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,45 @@ static void xen_set_cpu_features(struct cpuinfo_x86 *c)
19251925
}
19261926
}
19271927

1928+
static void xen_pin_vcpu(int cpu)
1929+
{
1930+
static bool disable_pinning;
1931+
struct sched_pin_override pin_override;
1932+
int ret;
1933+
1934+
if (disable_pinning)
1935+
return;
1936+
1937+
pin_override.pcpu = cpu;
1938+
ret = HYPERVISOR_sched_op(SCHEDOP_pin_override, &pin_override);
1939+
1940+
/* Ignore errors when removing override. */
1941+
if (cpu < 0)
1942+
return;
1943+
1944+
switch (ret) {
1945+
case -ENOSYS:
1946+
pr_warn("Unable to pin on physical cpu %d. In case of problems consider vcpu pinning.\n",
1947+
cpu);
1948+
disable_pinning = true;
1949+
break;
1950+
case -EPERM:
1951+
WARN(1, "Trying to pin vcpu without having privilege to do so\n");
1952+
disable_pinning = true;
1953+
break;
1954+
case -EINVAL:
1955+
case -EBUSY:
1956+
pr_warn("Physical cpu %d not available for pinning. Check Xen cpu configuration.\n",
1957+
cpu);
1958+
break;
1959+
case 0:
1960+
break;
1961+
default:
1962+
WARN(1, "rc %d while trying to pin vcpu\n", ret);
1963+
disable_pinning = true;
1964+
}
1965+
}
1966+
19281967
const struct hypervisor_x86 x86_hyper_xen = {
19291968
.name = "Xen",
19301969
.detect = xen_platform,
@@ -1933,6 +1972,7 @@ const struct hypervisor_x86 x86_hyper_xen = {
19331972
#endif
19341973
.x2apic_available = xen_x2apic_para_available,
19351974
.set_cpu_features = xen_set_cpu_features,
1975+
.pin_vcpu = xen_pin_vcpu,
19361976
};
19371977
EXPORT_SYMBOL(x86_hyper_xen);
19381978

‎drivers/firmware/dcdbas.c‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/platform_device.h>
2424
#include <linux/dma-mapping.h>
2525
#include <linux/errno.h>
26+
#include <linux/cpu.h>
2627
#include <linux/gfp.h>
2728
#include <linux/init.h>
2829
#include <linux/kernel.h>
@@ -238,33 +239,14 @@ static ssize_t host_control_on_shutdown_store(struct device *dev,
238239
return count;
239240
}
240241

241-
/**
242-
* dcdbas_smi_request: generate SMI request
243-
*
244-
* Called with smi_data_lock.
245-
*/
246-
int dcdbas_smi_request(struct smi_cmd *smi_cmd)
242+
static int raise_smi(void *par)
247243
{
248-
cpumask_var_t old_mask;
249-
int ret = 0;
250-
251-
if (smi_cmd->magic != SMI_CMD_MAGIC) {
252-
dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
253-
__func__);
254-
return -EBADR;
255-
}
244+
struct smi_cmd *smi_cmd = par;
256245

257-
/* SMI requires CPU 0 */
258-
if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
259-
return -ENOMEM;
260-
261-
cpumask_copy(old_mask, &current->cpus_allowed);
262-
set_cpus_allowed_ptr(current, cpumask_of(0));
263246
if (smp_processor_id() != 0) {
264247
dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
265248
__func__);
266-
ret = -EBUSY;
267-
goto out;
249+
return -EBUSY;
268250
}
269251

270252
/* generate SMI */
@@ -280,9 +262,28 @@ int dcdbas_smi_request(struct smi_cmd *smi_cmd)
280262
: "memory"
281263
);
282264

283-
out:
284-
set_cpus_allowed_ptr(current, old_mask);
285-
free_cpumask_var(old_mask);
265+
return 0;
266+
}
267+
/**
268+
* dcdbas_smi_request: generate SMI request
269+
*
270+
* Called with smi_data_lock.
271+
*/
272+
int dcdbas_smi_request(struct smi_cmd *smi_cmd)
273+
{
274+
int ret;
275+
276+
if (smi_cmd->magic != SMI_CMD_MAGIC) {
277+
dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
278+
__func__);
279+
return -EBADR;
280+
}
281+
282+
/* SMI requires CPU 0 */
283+
get_online_cpus();
284+
ret = smp_call_on_cpu(0, raise_smi, smi_cmd, true);
285+
put_online_cpus();
286+
286287
return ret;
287288
}
288289

‎drivers/hwmon/dell-smm-hwmon.c‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2323

24+
#include <linux/cpu.h>
2425
#include <linux/delay.h>
2526
#include <linux/module.h>
2627
#include <linux/types.h>
@@ -36,6 +37,7 @@
3637
#include <linux/io.h>
3738
#include <linux/sched.h>
3839
#include <linux/ctype.h>
40+
#include <linux/smp.h>
3941

4042
#include <linux/i8k.h>
4143

@@ -134,11 +136,11 @@ static inline const char *i8k_get_dmi_data(int field)
134136
/*
135137
* Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
136138
*/
137-
static int i8k_smm(struct smm_regs *regs)
139+
static int i8k_smm_func(void *par)
138140
{
139141
int rc;
142+
struct smm_regs *regs = par;
140143
int eax = regs->eax;
141-
cpumask_var_t old_mask;
142144

143145
#ifdef DEBUG
144146
int ebx = regs->ebx;
@@ -149,16 +151,8 @@ static int i8k_smm(struct smm_regs *regs)
149151
#endif
150152

151153
/* SMM requires CPU 0 */
152-
if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
153-
return -ENOMEM;
154-
cpumask_copy(old_mask, &current->cpus_allowed);
155-
rc = set_cpus_allowed_ptr(current, cpumask_of(0));
156-
if (rc)
157-
goto out;
158-
if (smp_processor_id() != 0) {
159-
rc = -EBUSY;
160-
goto out;
161-
}
154+
if (smp_processor_id() != 0)
155+
return -EBUSY;
162156

163157
#if defined(CONFIG_X86_64)
164158
asm volatile("pushq %%rax\n\t"
@@ -216,10 +210,6 @@ static int i8k_smm(struct smm_regs *regs)
216210
if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
217211
rc = -EINVAL;
218212

219-
out:
220-
set_cpus_allowed_ptr(current, old_mask);
221-
free_cpumask_var(old_mask);
222-
223213
#ifdef DEBUG
224214
rettime = ktime_get();
225215
delta = ktime_sub(rettime, calltime);
@@ -231,6 +221,20 @@ static int i8k_smm(struct smm_regs *regs)
231221
return rc;
232222
}
233223

224+
/*
225+
* Call the System Management Mode BIOS.
226+
*/
227+
static int i8k_smm(struct smm_regs *regs)
228+
{
229+
int ret;
230+
231+
get_online_cpus();
232+
ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
233+
put_online_cpus();
234+
235+
return ret;
236+
}
237+
234238
/*
235239
* Read the fan status.
236240
*/

‎include/linux/hypervisor.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __LINUX_HYPEVISOR_H
2+
#define __LINUX_HYPEVISOR_H
3+
4+
/*
5+
* Generic Hypervisor support
6+
* Juergen Gross <jgross@suse.com>
7+
*/
8+
9+
#ifdef CONFIG_HYPERVISOR_GUEST
10+
#include <asm/hypervisor.h>
11+
#else
12+
static inline void hypervisor_pin_vcpu(int cpu)
13+
{
14+
}
15+
#endif
16+
17+
#endif /* __LINUX_HYPEVISOR_H */

‎include/linux/smp.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ extern void arch_enable_nonboot_cpus_end(void);
196196

197197
void smp_setup_processor_id(void);
198198

199+
int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
200+
bool phys);
201+
199202
/* SMP core functions */
200203
int smpcfd_prepare_cpu(unsigned int cpu);
201204
int smpcfd_dead_cpu(unsigned int cpu);

0 commit comments

Comments
 (0)