Skip to content

Commit 3637897

Browse files
bp3tk0vIngo Molnar
authored andcommitted
x86/paravirt: Clean up native_patch()
When CONFIG_PARAVIRT_SPINLOCKS=n, it generates a warning: arch/x86/kernel/paravirt_patch_64.c: In function ‘native_patch’: arch/x86/kernel/paravirt_patch_64.c:89:1: warning: label ‘patch_site’ defined but not used [-Wunused-label] patch_site: ... but those labels can simply be removed by directly calling the respective functions there. Get rid of local variables too, while at it. Also, simplify function flow for better readability. Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: virtualization@lists.linux-foundation.org Link: http://lkml.kernel.org/r/20180911091510.GA12094@zn.tnic Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b7a5eb6 commit 3637897

File tree

2 files changed

+33
-57
lines changed

2 files changed

+33
-57
lines changed

arch/x86/kernel/paravirt_patch_32.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ extern bool pv_is_native_vcpu_is_preempted(void);
3434

3535
unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
3636
{
37-
const unsigned char *start, *end;
38-
unsigned ret;
39-
4037
#define PATCH_SITE(ops, x) \
41-
case PARAVIRT_PATCH(ops.x): \
42-
start = start_##ops##_##x; \
43-
end = end_##ops##_##x; \
44-
goto patch_site
38+
case PARAVIRT_PATCH(ops.x): \
39+
return paravirt_patch_insns(ibuf, len, start_##ops##_##x, end_##ops##_##x)
40+
4541
switch (type) {
4642
#ifdef CONFIG_PARAVIRT_XXL
4743
PATCH_SITE(irq, irq_disable);
@@ -54,32 +50,24 @@ unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
5450
PATCH_SITE(mmu, write_cr3);
5551
#endif
5652
#if defined(CONFIG_PARAVIRT_SPINLOCKS)
57-
case PARAVIRT_PATCH(lock.queued_spin_unlock):
58-
if (pv_is_native_spin_unlock()) {
59-
start = start_lock_queued_spin_unlock;
60-
end = end_lock_queued_spin_unlock;
61-
goto patch_site;
62-
}
63-
goto patch_default;
53+
case PARAVIRT_PATCH(lock.queued_spin_unlock):
54+
if (pv_is_native_spin_unlock())
55+
return paravirt_patch_insns(ibuf, len,
56+
start_lock_queued_spin_unlock,
57+
end_lock_queued_spin_unlock);
58+
break;
6459

65-
case PARAVIRT_PATCH(lock.vcpu_is_preempted):
66-
if (pv_is_native_vcpu_is_preempted()) {
67-
start = start_lock_vcpu_is_preempted;
68-
end = end_lock_vcpu_is_preempted;
69-
goto patch_site;
70-
}
71-
goto patch_default;
60+
case PARAVIRT_PATCH(lock.vcpu_is_preempted):
61+
if (pv_is_native_vcpu_is_preempted())
62+
return paravirt_patch_insns(ibuf, len,
63+
start_lock_vcpu_is_preempted,
64+
end_lock_vcpu_is_preempted);
65+
break;
7266
#endif
7367

7468
default:
75-
patch_default: __maybe_unused
76-
ret = paravirt_patch_default(type, ibuf, addr, len);
77-
break;
78-
79-
patch_site:
80-
ret = paravirt_patch_insns(ibuf, len, start, end);
8169
break;
8270
}
8371
#undef PATCH_SITE
84-
return ret;
72+
return paravirt_patch_default(type, ibuf, addr, len);
8573
}

arch/x86/kernel/paravirt_patch_64.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ extern bool pv_is_native_vcpu_is_preempted(void);
4242

4343
unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
4444
{
45-
const unsigned char *start, *end;
46-
unsigned ret;
47-
4845
#define PATCH_SITE(ops, x) \
49-
case PARAVIRT_PATCH(ops.x): \
50-
start = start_##ops##_##x; \
51-
end = end_##ops##_##x; \
52-
goto patch_site
53-
switch(type) {
46+
case PARAVIRT_PATCH(ops.x): \
47+
return paravirt_patch_insns(ibuf, len, start_##ops##_##x, end_##ops##_##x)
48+
49+
switch (type) {
5450
#ifdef CONFIG_PARAVIRT_XXL
5551
PATCH_SITE(irq, restore_fl);
5652
PATCH_SITE(irq, save_fl);
@@ -64,32 +60,24 @@ unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
6460
PATCH_SITE(mmu, write_cr3);
6561
#endif
6662
#if defined(CONFIG_PARAVIRT_SPINLOCKS)
67-
case PARAVIRT_PATCH(lock.queued_spin_unlock):
68-
if (pv_is_native_spin_unlock()) {
69-
start = start_lock_queued_spin_unlock;
70-
end = end_lock_queued_spin_unlock;
71-
goto patch_site;
72-
}
73-
goto patch_default;
63+
case PARAVIRT_PATCH(lock.queued_spin_unlock):
64+
if (pv_is_native_spin_unlock())
65+
return paravirt_patch_insns(ibuf, len,
66+
start_lock_queued_spin_unlock,
67+
end_lock_queued_spin_unlock);
68+
break;
7469

75-
case PARAVIRT_PATCH(lock.vcpu_is_preempted):
76-
if (pv_is_native_vcpu_is_preempted()) {
77-
start = start_lock_vcpu_is_preempted;
78-
end = end_lock_vcpu_is_preempted;
79-
goto patch_site;
80-
}
81-
goto patch_default;
70+
case PARAVIRT_PATCH(lock.vcpu_is_preempted):
71+
if (pv_is_native_vcpu_is_preempted())
72+
return paravirt_patch_insns(ibuf, len,
73+
start_lock_vcpu_is_preempted,
74+
end_lock_vcpu_is_preempted);
75+
break;
8276
#endif
8377

8478
default:
85-
patch_default: __maybe_unused
86-
ret = paravirt_patch_default(type, ibuf, addr, len);
87-
break;
88-
89-
patch_site:
90-
ret = paravirt_patch_insns(ibuf, len, start, end);
9179
break;
9280
}
9381
#undef PATCH_SITE
94-
return ret;
82+
return paravirt_patch_default(type, ibuf, addr, len);
9583
}

0 commit comments

Comments
 (0)