Skip to content

Commit 8d47332

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Radim Krčmář: - fix PPC XIVE interrupt delivery - fix x86 RCU breakage from asynchronous page faults when built without PREEMPT_COUNT - fix x86 build with -frecord-gcc-switches - fix x86 build without X86_LOCAL_APIC * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: add X86_LOCAL_APIC dependency x86/kvm: Move kvm_fastop_exception to .fixup section kvm/x86: Avoid async PF preempting the kernel incorrectly KVM: PPC: Book3S: Fix server always zero from kvmppc_xive_get_xive()
2 parents d109d83 + e42eef4 commit 8d47332

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

arch/powerpc/kvm/book3s_xive.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server,
622622
return -EINVAL;
623623
state = &sb->irq_state[idx];
624624
arch_spin_lock(&sb->lock);
625-
*server = state->guest_server;
625+
*server = state->act_server;
626626
*priority = state->guest_priority;
627627
arch_spin_unlock(&sb->lock);
628628

@@ -1331,7 +1331,7 @@ static int xive_get_source(struct kvmppc_xive *xive, long irq, u64 addr)
13311331
xive->saved_src_count++;
13321332

13331333
/* Convert saved state into something compatible with xics */
1334-
val = state->guest_server;
1334+
val = state->act_server;
13351335
prio = state->saved_scan_prio;
13361336

13371337
if (prio == MASKED) {
@@ -1507,7 +1507,6 @@ static int xive_set_source(struct kvmppc_xive *xive, long irq, u64 addr)
15071507
/* First convert prio and mark interrupt as untargetted */
15081508
act_prio = xive_prio_from_guest(guest_prio);
15091509
state->act_priority = MASKED;
1510-
state->guest_server = server;
15111510

15121511
/*
15131512
* We need to drop the lock due to the mutex below. Hopefully

arch/powerpc/kvm/book3s_xive.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct kvmppc_xive_irq_state {
3535
struct xive_irq_data *pt_data; /* XIVE Pass-through associated data */
3636

3737
/* Targetting as set by guest */
38-
u32 guest_server; /* Current guest selected target */
3938
u8 guest_priority; /* Guest set priority */
4039
u8 saved_priority; /* Saved priority when masking */
4140

arch/x86/include/asm/kvm_para.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
8888
bool kvm_para_available(void);
8989
unsigned int kvm_arch_para_features(void);
9090
void __init kvm_guest_init(void);
91-
void kvm_async_pf_task_wait(u32 token);
91+
void kvm_async_pf_task_wait(u32 token, int interrupt_kernel);
9292
void kvm_async_pf_task_wake(u32 token);
9393
u32 kvm_read_and_reset_pf_reason(void);
9494
extern void kvm_disable_steal_time(void);
@@ -103,7 +103,7 @@ static inline void kvm_spinlock_init(void)
103103

104104
#else /* CONFIG_KVM_GUEST */
105105
#define kvm_guest_init() do {} while (0)
106-
#define kvm_async_pf_task_wait(T) do {} while(0)
106+
#define kvm_async_pf_task_wait(T, I) do {} while(0)
107107
#define kvm_async_pf_task_wake(T) do {} while(0)
108108

109109
static inline bool kvm_para_available(void)

arch/x86/kernel/kvm.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b,
117117
return NULL;
118118
}
119119

120-
void kvm_async_pf_task_wait(u32 token)
120+
/*
121+
* @interrupt_kernel: Is this called from a routine which interrupts the kernel
122+
* (other than user space)?
123+
*/
124+
void kvm_async_pf_task_wait(u32 token, int interrupt_kernel)
121125
{
122126
u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
123127
struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
@@ -140,8 +144,10 @@ void kvm_async_pf_task_wait(u32 token)
140144

141145
n.token = token;
142146
n.cpu = smp_processor_id();
143-
n.halted = is_idle_task(current) || preempt_count() > 1 ||
144-
rcu_preempt_depth();
147+
n.halted = is_idle_task(current) ||
148+
(IS_ENABLED(CONFIG_PREEMPT_COUNT)
149+
? preempt_count() > 1 || rcu_preempt_depth()
150+
: interrupt_kernel);
145151
init_swait_queue_head(&n.wq);
146152
hlist_add_head(&n.link, &b->list);
147153
raw_spin_unlock(&b->lock);
@@ -269,7 +275,7 @@ do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
269275
case KVM_PV_REASON_PAGE_NOT_PRESENT:
270276
/* page is swapped out by the host. */
271277
prev_state = exception_enter();
272-
kvm_async_pf_task_wait((u32)read_cr2());
278+
kvm_async_pf_task_wait((u32)read_cr2(), !user_mode(regs));
273279
exception_exit(prev_state);
274280
break;
275281
case KVM_PV_REASON_PAGE_READY:

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config KVM
2323
depends on HIGH_RES_TIMERS
2424
# for TASKSTATS/TASK_DELAY_ACCT:
2525
depends on NET && MULTIUSER
26+
depends on X86_LOCAL_APIC
2627
select PREEMPT_NOTIFIERS
2728
select MMU_NOTIFIER
2829
select ANON_INODES

arch/x86/kvm/emulate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,10 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *));
425425
#op " %al \n\t" \
426426
FOP_RET
427427

428-
asm(".global kvm_fastop_exception \n"
429-
"kvm_fastop_exception: xor %esi, %esi; ret");
428+
asm(".pushsection .fixup, \"ax\"\n"
429+
".global kvm_fastop_exception \n"
430+
"kvm_fastop_exception: xor %esi, %esi; ret\n"
431+
".popsection");
430432

431433
FOP_START(setcc)
432434
FOP_SETCC(seto)

arch/x86/kvm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
38373837
case KVM_PV_REASON_PAGE_NOT_PRESENT:
38383838
vcpu->arch.apf.host_apf_reason = 0;
38393839
local_irq_disable();
3840-
kvm_async_pf_task_wait(fault_address);
3840+
kvm_async_pf_task_wait(fault_address, 0);
38413841
local_irq_enable();
38423842
break;
38433843
case KVM_PV_REASON_PAGE_READY:

0 commit comments

Comments
 (0)