Commit 6c377b02 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

Merge tag 'kvm-s390-next-5.13-1' of...

Merge tag 'kvm-s390-next-5.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD

KVM: s390: Updates for 5.13

- properly handle MVPG in nesting KVM (vsie)
- allow to forward the yield_to hypercall (diagnose 9c)
- fixes
parents 657f1d86 c3171e94
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -84,3 +84,36 @@ If the function code specifies 0x501, breakpoint functions may be performed.
This function code is handled by userspace.

This diagnose function code has no subfunctions and uses no parameters.


DIAGNOSE function code 'X'9C - Voluntary Time Slice Yield
---------------------------------------------------------

General register 1 contains the target CPU address.

In a guest of a hypervisor like LPAR, KVM or z/VM using shared host CPUs,
DIAGNOSE with function code 0x9c may improve system performance by
yielding the host CPU on which the guest CPU is running to be assigned
to another guest CPU, preferably the logical CPU containing the specified
target CPU.


DIAG 'X'9C forwarding
+++++++++++++++++++++

The guest may send a DIAGNOSE 0x9c in order to yield to a certain
other vcpu. An example is a Linux guest that tries to yield to the vcpu
that is currently holding a spinlock, but not running.

However, on the host the real cpu backing the vcpu may itself not be
running.
Forwarding the DIAGNOSE 0x9c initially sent by the guest to yield to
the backing cpu will hopefully cause that cpu, and thus subsequently
the guest's vcpu, to be scheduled.


diag9c_forwarding_hz
    KVM kernel parameter allowing to specify the maximum number of DIAGNOSE
    0x9c forwarding per second in the purpose of avoiding a DIAGNOSE 0x9c
    forwarding storm.
    A value of 0 turns the forwarding off.
+1 −0
Original line number Diff line number Diff line
@@ -454,6 +454,7 @@ struct kvm_vcpu_stat {
	u64 diagnose_44;
	u64 diagnose_9c;
	u64 diagnose_9c_ignored;
	u64 diagnose_9c_forward;
	u64 diagnose_258;
	u64 diagnose_308;
	u64 diagnose_500;
+1 −0
Original line number Diff line number Diff line
@@ -63,5 +63,6 @@ extern void __noreturn cpu_die(void);
extern void __cpu_die(unsigned int cpu);
extern int __cpu_disable(void);
extern void schedule_mcck_handler(void);
void notrace smp_yield_cpu(int cpu);

#endif /* __ASM_SMP_H */
+1 −0
Original line number Diff line number Diff line
@@ -429,6 +429,7 @@ void notrace smp_yield_cpu(int cpu)
	asm volatile("diag %0,0,0x9c"
		     : : "d" (pcpu_devices[cpu].address));
}
EXPORT_SYMBOL_GPL(smp_yield_cpu);

/*
 * Send cpus emergency shutdown signal. This gives the cpus the
+28 −3
Original line number Diff line number Diff line
@@ -150,6 +150,19 @@ static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
	return 0;
}

static int forward_cnt;
static unsigned long cur_slice;

static int diag9c_forwarding_overrun(void)
{
	/* Reset the count on a new slice */
	if (time_after(jiffies, cur_slice)) {
		cur_slice = jiffies;
		forward_cnt = diag9c_forwarding_hz / HZ;
	}
	return forward_cnt-- <= 0 ? 1 : 0;
}

static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
{
	struct kvm_vcpu *tcpu;
@@ -167,10 +180,22 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
	if (!tcpu)
		goto no_yield;

	/* target already running */
	if (READ_ONCE(tcpu->cpu) >= 0)
	/* target guest VCPU already running */
	if (READ_ONCE(tcpu->cpu) >= 0) {
		if (!diag9c_forwarding_hz || diag9c_forwarding_overrun())
			goto no_yield;

		/* target host CPU already running */
		if (!vcpu_is_preempted(tcpu->cpu))
			goto no_yield;
		smp_yield_cpu(tcpu->cpu);
		VCPU_EVENT(vcpu, 5,
			   "diag time slice end directed to %d: yield forwarded",
			   tid);
		vcpu->stat.diagnose_9c_forward++;
		return 0;
	}

	if (kvm_vcpu_yield_to(tcpu) <= 0)
		goto no_yield;

Loading