All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/4] KVM: s390: refactor cpuflag handling
@ 2018-01-23 17:05 David Hildenbrand
  2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: David Hildenbrand @ 2018-01-23 17:05 UTC (permalink / raw)
  To: KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck

We already have __set_cpuflag(), but its limited to interrupt.c. Conny
suggested __clear_cpuflag(). I went one step further and introduce
- kvm_s390_set_cpuflags()
- kvm_s390_clear_cpuflags()
- kvm_s390_test_cpuflags()

All applicable places are converted to use the new helpers. This beautifies
the code at a couple of places quite a bit.

David Hildenbrand (4):
  KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
  KVM: s390: reuse kvm_s390_set_cpuflags()
  KVM: s390: introduce and use kvm_s390_clear_cpuflags()
  KVM: s390: introduce and use kvm_s390_test_cpuflags()

 arch/s390/kvm/interrupt.c | 43 +++++++++++++++++++------------------------
 arch/s390/kvm/kvm-s390.c  | 30 ++++++++++++++----------------
 arch/s390/kvm/kvm-s390.h  | 17 ++++++++++++++++-
 arch/s390/kvm/priv.c      |  6 +++---
 arch/s390/kvm/sigp.c      | 14 +++++---------
 arch/s390/kvm/vsie.c      |  4 ++--
 6 files changed, 59 insertions(+), 55 deletions(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
  2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
@ 2018-01-23 17:05 ` David Hildenbrand
  2018-01-23 17:43   ` Thomas Huth
  2018-01-24 16:30   ` Cornelia Huck
  2018-01-23 17:05 ` [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags() David Hildenbrand
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: David Hildenbrand @ 2018-01-23 17:05 UTC (permalink / raw)
  To: KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck, David Hildenbrand

No need to make this function special. Move it to a header right away.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/kvm/interrupt.c | 29 ++++++++++++-----------------
 arch/s390/kvm/kvm-s390.h  |  5 +++++
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index f8eb2cfa763a..96ea3b80b67a 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -301,17 +301,12 @@ static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
 	}
 }
 
-static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag)
-{
-	atomic_or(flag, &vcpu->arch.sie_block->cpuflags);
-}
-
 static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
 {
 	if (!(pending_irqs(vcpu) & IRQ_PEND_IO_MASK))
 		return;
 	else if (psw_ioint_disabled(vcpu))
-		__set_cpuflag(vcpu, CPUSTAT_IO_INT);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT);
 	else
 		vcpu->arch.sie_block->lctl |= LCTL_CR6;
 }
@@ -321,7 +316,7 @@ static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
 	if (!(pending_irqs(vcpu) & IRQ_PEND_EXT_MASK))
 		return;
 	if (psw_extint_disabled(vcpu))
-		__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	else
 		vcpu->arch.sie_block->lctl |= LCTL_CR0;
 }
@@ -339,7 +334,7 @@ static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu)
 static void set_intercept_indicators_stop(struct kvm_vcpu *vcpu)
 {
 	if (kvm_s390_is_stop_irq_pending(vcpu))
-		__set_cpuflag(vcpu, CPUSTAT_STOP_INT);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOP_INT);
 }
 
 /* Set interception request for non-deliverable interrupts */
@@ -1227,7 +1222,7 @@ static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
 
 	li->irq.ext = irq->u.ext;
 	set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs);
-	__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	return 0;
 }
 
@@ -1252,7 +1247,7 @@ static int __inject_extcall(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
 	if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs))
 		return -EBUSY;
 	*extcall = irq->u.extcall;
-	__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	return 0;
 }
 
@@ -1296,7 +1291,7 @@ static int __inject_sigp_stop(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
 	if (test_and_set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs))
 		return -EBUSY;
 	stop->flags = irq->u.stop.flags;
-	__set_cpuflag(vcpu, CPUSTAT_STOP_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOP_INT);
 	return 0;
 }
 
@@ -1328,7 +1323,7 @@ static int __inject_sigp_emergency(struct kvm_vcpu *vcpu,
 
 	set_bit(irq->u.emerg.code, li->sigp_emerg_pending);
 	set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs);
-	__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	return 0;
 }
 
@@ -1372,7 +1367,7 @@ static int __inject_ckc(struct kvm_vcpu *vcpu)
 				   0, 0);
 
 	set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
-	__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	return 0;
 }
 
@@ -1385,7 +1380,7 @@ static int __inject_cpu_timer(struct kvm_vcpu *vcpu)
 				   0, 0);
 
 	set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
-	__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
 	return 0;
 }
 
@@ -1568,13 +1563,13 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
 	/* make the VCPU drop out of the SIE, or wake it up if sleeping */
 	switch (type) {
 	case KVM_S390_MCHK:
-		__set_cpuflag(dst_vcpu, CPUSTAT_STOP_INT);
+		kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT);
 		break;
 	case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
-		__set_cpuflag(dst_vcpu, CPUSTAT_IO_INT);
+		kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT);
 		break;
 	default:
-		__set_cpuflag(dst_vcpu, CPUSTAT_EXT_INT);
+		kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_EXT_INT);
 		break;
 	}
 	kvm_s390_vcpu_wakeup(dst_vcpu);
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 8877116f0159..a9f2c8d1833d 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -47,6 +47,11 @@ do { \
 	  d_args); \
 } while (0)
 
+static inline void kvm_s390_set_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
+{
+	atomic_or(flags, &vcpu->arch.sie_block->cpuflags);
+}
+
 static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
 {
 	return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags()
  2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
  2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
@ 2018-01-23 17:05 ` David Hildenbrand
  2018-01-23 17:44   ` Thomas Huth
  2018-01-24 16:35   ` Cornelia Huck
  2018-01-23 17:05 ` [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags() David Hildenbrand
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: David Hildenbrand @ 2018-01-23 17:05 UTC (permalink / raw)
  To: KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck, David Hildenbrand

Use it in all places where we set cpuflags.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/kvm/interrupt.c |  4 ++--
 arch/s390/kvm/kvm-s390.c  | 17 ++++++++---------
 arch/s390/kvm/vsie.c      |  2 +-
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 96ea3b80b67a..404a127b1921 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -101,7 +101,7 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id)
 		/* another external call is pending */
 		return -EBUSY;
 	}
-	atomic_or(CPUSTAT_ECALL_PEND, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_ECALL_PEND);
 	return 0;
 }
 
@@ -277,7 +277,7 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
 
 static void __set_cpu_idle(struct kvm_vcpu *vcpu)
 {
-	atomic_or(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
 	set_bit(vcpu->vcpu_id, vcpu->kvm->arch.float_int.idle_mask);
 }
 
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index de16c224319c..5680b12add68 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2316,7 +2316,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 
 	gmap_enable(vcpu->arch.enabled_gmap);
-	atomic_or(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_RUNNING);
 	if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu))
 		__start_cpu_timer_accounting(vcpu);
 	vcpu->cpu = cpu;
@@ -2423,9 +2423,9 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 						    CPUSTAT_STOPPED);
 
 	if (test_kvm_facility(vcpu->kvm, 78))
-		atomic_or(CPUSTAT_GED2, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_GED2);
 	else if (test_kvm_facility(vcpu->kvm, 8))
-		atomic_or(CPUSTAT_GED, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_GED);
 
 	kvm_s390_vcpu_setup_model(vcpu);
 
@@ -2462,7 +2462,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 	vcpu->arch.sie_block->riccbd = (unsigned long) &vcpu->run->s.regs.riccb;
 
 	if (sclp.has_kss)
-		atomic_or(CPUSTAT_KSS, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_KSS);
 	else
 		vcpu->arch.sie_block->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
 
@@ -2565,7 +2565,7 @@ static void kvm_s390_vcpu_request_handled(struct kvm_vcpu *vcpu)
  * return immediately. */
 void exit_sie(struct kvm_vcpu *vcpu)
 {
-	atomic_or(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOP_INT);
 	while (vcpu->arch.sie_block->prog0c & PROG_IN_SIE)
 		cpu_relax();
 }
@@ -2840,7 +2840,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 	if (dbg->control & KVM_GUESTDBG_ENABLE) {
 		vcpu->guest_debug = dbg->control;
 		/* enforce guest PER */
-		atomic_or(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_set_cpuflags(vcpu, CPUSTAT_P);
 
 		if (dbg->control & KVM_GUESTDBG_USE_HW_BP)
 			rc = kvm_s390_import_bp_data(vcpu, dbg);
@@ -2941,8 +2941,7 @@ static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
 	if (kvm_check_request(KVM_REQ_ENABLE_IBS, vcpu)) {
 		if (!ibs_enabled(vcpu)) {
 			trace_kvm_s390_enable_disable_ibs(vcpu->vcpu_id, 1);
-			atomic_or(CPUSTAT_IBS,
-					&vcpu->arch.sie_block->cpuflags);
+			kvm_s390_set_cpuflags(vcpu, CPUSTAT_IBS);
 		}
 		goto retry;
 	}
@@ -3627,7 +3626,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)
 	/* SIGP STOP and SIGP STOP AND STORE STATUS has been fully processed */
 	kvm_s390_clear_stop_irq(vcpu);
 
-	atomic_or(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOPPED);
 	__disable_ibs_on_vcpu(vcpu);
 
 	for (i = 0; i < online_vcpus; i++) {
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 5d6ae0326d9e..902b5befb691 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -894,7 +894,7 @@ static void register_shadow_scb(struct kvm_vcpu *vcpu,
 	 * External calls have to lead to a kick of the vcpu and
 	 * therefore the vsie -> Simulate Wait state.
 	 */
-	atomic_or(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
 	/*
 	 * We have to adjust the g3 epoch by the g2 epoch. The epoch will
 	 * automatically be adjusted on tod clock changes via kvm_sync_clock.
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags()
  2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
  2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
  2018-01-23 17:05 ` [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags() David Hildenbrand
@ 2018-01-23 17:05 ` David Hildenbrand
  2018-01-23 17:46   ` Thomas Huth
  2018-01-24 16:38   ` Cornelia Huck
  2018-01-23 17:05 ` [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags() David Hildenbrand
  2018-01-24 16:43 ` [PATCH v1 0/4] KVM: s390: refactor cpuflag handling Christian Borntraeger
  4 siblings, 2 replies; 14+ messages in thread
From: David Hildenbrand @ 2018-01-23 17:05 UTC (permalink / raw)
  To: KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck, David Hildenbrand

Use it just like kvm_s390_set_cpuflags().

Suggested-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/kvm/interrupt.c |  8 ++++----
 arch/s390/kvm/kvm-s390.c  | 11 +++++------
 arch/s390/kvm/kvm-s390.h  |  5 +++++
 arch/s390/kvm/priv.c      |  2 +-
 arch/s390/kvm/vsie.c      |  2 +-
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 404a127b1921..8687aed9a268 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -111,7 +111,7 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu)
 
 	if (!kvm_s390_use_sca_entries())
 		return;
-	atomic_andnot(CPUSTAT_ECALL_PEND, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_ECALL_PEND);
 	read_lock(&vcpu->kvm->arch.sca_lock);
 	if (vcpu->kvm->arch.use_esca) {
 		struct esca_block *sca = vcpu->kvm->arch.sca;
@@ -283,14 +283,14 @@ static void __set_cpu_idle(struct kvm_vcpu *vcpu)
 
 static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
 {
-	atomic_andnot(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT);
 	clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.float_int.idle_mask);
 }
 
 static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
 {
-	atomic_andnot(CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT,
-		    &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_IO_INT | CPUSTAT_EXT_INT |
+				      CPUSTAT_STOP_INT);
 	vcpu->arch.sie_block->lctl = 0x0000;
 	vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW | ICTL_STCTL | ICTL_PINT);
 
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 5680b12add68..d27a247799f0 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2327,7 +2327,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 	vcpu->cpu = -1;
 	if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu))
 		__stop_cpu_timer_accounting(vcpu);
-	atomic_andnot(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_RUNNING);
 	vcpu->arch.enabled_gmap = gmap_get_enabled();
 	gmap_disable(vcpu->arch.enabled_gmap);
 
@@ -2845,14 +2845,14 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 		if (dbg->control & KVM_GUESTDBG_USE_HW_BP)
 			rc = kvm_s390_import_bp_data(vcpu, dbg);
 	} else {
-		atomic_andnot(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_clear_cpuflags(vcpu, CPUSTAT_P);
 		vcpu->arch.guestdbg.last_bp = 0;
 	}
 
 	if (rc) {
 		vcpu->guest_debug = 0;
 		kvm_s390_clear_bp_data(vcpu);
-		atomic_andnot(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags);
+		kvm_s390_clear_cpuflags(vcpu, CPUSTAT_P);
 	}
 
 out:
@@ -2949,8 +2949,7 @@ static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
 	if (kvm_check_request(KVM_REQ_DISABLE_IBS, vcpu)) {
 		if (ibs_enabled(vcpu)) {
 			trace_kvm_s390_enable_disable_ibs(vcpu->vcpu_id, 0);
-			atomic_andnot(CPUSTAT_IBS,
-					  &vcpu->arch.sie_block->cpuflags);
+			kvm_s390_clear_cpuflags(vcpu, CPUSTAT_IBS);
 		}
 		goto retry;
 	}
@@ -3600,7 +3599,7 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)
 		__disable_ibs_on_all_vcpus(vcpu->kvm);
 	}
 
-	atomic_andnot(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_STOPPED);
 	/*
 	 * Another VCPU might have used IBS while we were offline.
 	 * Let's play safe and flush the VCPU at startup.
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index a9f2c8d1833d..f727313a706f 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -52,6 +52,11 @@ static inline void kvm_s390_set_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
 	atomic_or(flags, &vcpu->arch.sie_block->cpuflags);
 }
 
+static inline void kvm_s390_clear_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
+{
+	atomic_andnot(flags, &vcpu->arch.sie_block->cpuflags);
+}
+
 static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
 {
 	return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED;
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 572496c688cc..de4b13eca3ab 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -210,7 +210,7 @@ int kvm_s390_skey_check_enable(struct kvm_vcpu *vcpu)
 	VCPU_EVENT(vcpu, 3, "enabling storage keys for guest: %d", rc);
 	if (!rc) {
 		if (atomic_read(&sie_block->cpuflags) & CPUSTAT_KSS)
-			atomic_andnot(CPUSTAT_KSS, &sie_block->cpuflags);
+			kvm_s390_clear_cpuflags(vcpu, CPUSTAT_KSS);
 		else
 			sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE |
 					     ICTL_RRBE);
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 902b5befb691..35c94b6632db 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -916,7 +916,7 @@ static void register_shadow_scb(struct kvm_vcpu *vcpu,
  */
 static void unregister_shadow_scb(struct kvm_vcpu *vcpu)
 {
-	atomic_andnot(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT);
 	WRITE_ONCE(vcpu->arch.vsie_block, NULL);
 }
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags()
  2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
                   ` (2 preceding siblings ...)
  2018-01-23 17:05 ` [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags() David Hildenbrand
@ 2018-01-23 17:05 ` David Hildenbrand
  2018-01-23 17:52   ` Thomas Huth
  2018-01-24 16:43   ` Cornelia Huck
  2018-01-24 16:43 ` [PATCH v1 0/4] KVM: s390: refactor cpuflag handling Christian Borntraeger
  4 siblings, 2 replies; 14+ messages in thread
From: David Hildenbrand @ 2018-01-23 17:05 UTC (permalink / raw)
  To: KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck, David Hildenbrand

Use it just like kvm_s390_set_cpuflags() and kvm_s390_clear_cpuflags().

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/kvm/interrupt.c |  2 +-
 arch/s390/kvm/kvm-s390.c  |  2 +-
 arch/s390/kvm/kvm-s390.h  |  7 ++++++-
 arch/s390/kvm/priv.c      |  4 ++--
 arch/s390/kvm/sigp.c      | 14 +++++---------
 5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 8687aed9a268..4b483b48436a 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -36,7 +36,7 @@ static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id)
 {
 	int c, scn;
 
-	if (!(atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_ECALL_PEND))
+	if (!kvm_s390_test_cpuflags(vcpu, CPUSTAT_ECALL_PEND))
 		return 0;
 
 	BUG_ON(!kvm_s390_use_sca_entries());
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index d27a247799f0..0bd0e284e355 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2905,7 +2905,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
 
 static bool ibs_enabled(struct kvm_vcpu *vcpu)
 {
-	return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_IBS;
+	return kvm_s390_test_cpuflags(vcpu, CPUSTAT_IBS);
 }
 
 static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index f727313a706f..f110fa96807e 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -57,9 +57,14 @@ static inline void kvm_s390_clear_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
 	atomic_andnot(flags, &vcpu->arch.sie_block->cpuflags);
 }
 
+static inline bool kvm_s390_test_cpuflags(struct kvm_vcpu *vcpu, u32 flags)
+{
+	return (atomic_read(&vcpu->arch.sie_block->cpuflags) & flags) == flags;
+}
+
 static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
 {
-	return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED;
+	return kvm_s390_test_cpuflags(vcpu, CPUSTAT_STOPPED);
 }
 
 static inline int is_vcpu_idle(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index de4b13eca3ab..c11528faabf1 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -203,13 +203,13 @@ int kvm_s390_skey_check_enable(struct kvm_vcpu *vcpu)
 
 	trace_kvm_s390_skey_related_inst(vcpu);
 	if (!(sie_block->ictl & (ICTL_ISKE | ICTL_SSKE | ICTL_RRBE)) &&
-	    !(atomic_read(&sie_block->cpuflags) & CPUSTAT_KSS))
+	    !kvm_s390_test_cpuflags(vcpu, CPUSTAT_KSS))
 		return rc;
 
 	rc = s390_enable_skey();
 	VCPU_EVENT(vcpu, 3, "enabling storage keys for guest: %d", rc);
 	if (!rc) {
-		if (atomic_read(&sie_block->cpuflags) & CPUSTAT_KSS)
+		if (kvm_s390_test_cpuflags(vcpu, CPUSTAT_KSS))
 			kvm_s390_clear_cpuflags(vcpu, CPUSTAT_KSS);
 		else
 			sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE |
diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
index 5cafd1e2651b..683036c1c92a 100644
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -20,19 +20,18 @@
 static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
 			u64 *reg)
 {
-	int cpuflags;
+	const bool stopped = kvm_s390_test_cpuflags(dst_vcpu, CPUSTAT_STOPPED);
 	int rc;
 	int ext_call_pending;
 
-	cpuflags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
 	ext_call_pending = kvm_s390_ext_call_pending(dst_vcpu);
-	if (!(cpuflags & CPUSTAT_STOPPED) && !ext_call_pending)
+	if (!stopped && !ext_call_pending)
 		rc = SIGP_CC_ORDER_CODE_ACCEPTED;
 	else {
 		*reg &= 0xffffffff00000000UL;
 		if (ext_call_pending)
 			*reg |= SIGP_STATUS_EXT_CALL_PENDING;
-		if (cpuflags & CPUSTAT_STOPPED)
+		if (stopped)
 			*reg |= SIGP_STATUS_STOPPED;
 		rc = SIGP_CC_STATUS_STORED;
 	}
@@ -205,11 +204,9 @@ static int __sigp_store_status_at_addr(struct kvm_vcpu *vcpu,
 				       struct kvm_vcpu *dst_vcpu,
 				       u32 addr, u64 *reg)
 {
-	int flags;
 	int rc;
 
-	flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
-	if (!(flags & CPUSTAT_STOPPED)) {
+	if (!kvm_s390_test_cpuflags(dst_vcpu, CPUSTAT_STOPPED)) {
 		*reg &= 0xffffffff00000000UL;
 		*reg |= SIGP_STATUS_INCORRECT_STATE;
 		return SIGP_CC_STATUS_STORED;
@@ -236,8 +233,7 @@ static int __sigp_sense_running(struct kvm_vcpu *vcpu,
 		return SIGP_CC_STATUS_STORED;
 	}
 
-	if (atomic_read(&dst_vcpu->arch.sie_block->cpuflags) &
-	    CPUSTAT_RUNNING) {
+	if (kvm_s390_test_cpuflags(dst_vcpu, CPUSTAT_RUNNING)) {
 		/* running */
 		rc = SIGP_CC_ORDER_CODE_ACCEPTED;
 	} else {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
@ 2018-01-23 17:43   ` Thomas Huth
  2018-01-24 16:30   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2018-01-23 17:43 UTC (permalink / raw)
  To: David Hildenbrand, KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck

On 23.01.2018 18:05, David Hildenbrand wrote:
> No need to make this function special. Move it to a header right away.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c | 29 ++++++++++++-----------------
>  arch/s390/kvm/kvm-s390.h  |  5 +++++
>  2 files changed, 17 insertions(+), 17 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags() David Hildenbrand
@ 2018-01-23 17:44   ` Thomas Huth
  2018-01-24 16:35   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2018-01-23 17:44 UTC (permalink / raw)
  To: David Hildenbrand, KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck

On 23.01.2018 18:05, David Hildenbrand wrote:
> Use it in all places where we set cpuflags.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  4 ++--
>  arch/s390/kvm/kvm-s390.c  | 17 ++++++++---------
>  arch/s390/kvm/vsie.c      |  2 +-
>  3 files changed, 11 insertions(+), 12 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags() David Hildenbrand
@ 2018-01-23 17:46   ` Thomas Huth
  2018-01-24 16:38   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2018-01-23 17:46 UTC (permalink / raw)
  To: David Hildenbrand, KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck

On 23.01.2018 18:05, David Hildenbrand wrote:
> Use it just like kvm_s390_set_cpuflags().
> 
> Suggested-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  8 ++++----
>  arch/s390/kvm/kvm-s390.c  | 11 +++++------
>  arch/s390/kvm/kvm-s390.h  |  5 +++++
>  arch/s390/kvm/priv.c      |  2 +-
>  arch/s390/kvm/vsie.c      |  2 +-
>  5 files changed, 16 insertions(+), 12 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags() David Hildenbrand
@ 2018-01-23 17:52   ` Thomas Huth
  2018-01-24 16:43   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2018-01-23 17:52 UTC (permalink / raw)
  To: David Hildenbrand, KVM; +Cc: linux-s390, Christian Borntraeger, Cornelia Huck

On 23.01.2018 18:05, David Hildenbrand wrote:
> Use it just like kvm_s390_set_cpuflags() and kvm_s390_clear_cpuflags().
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  2 +-
>  arch/s390/kvm/kvm-s390.c  |  2 +-
>  arch/s390/kvm/kvm-s390.h  |  7 ++++++-
>  arch/s390/kvm/priv.c      |  4 ++--
>  arch/s390/kvm/sigp.c      | 14 +++++---------
>  5 files changed, 15 insertions(+), 14 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
  2018-01-23 17:43   ` Thomas Huth
@ 2018-01-24 16:30   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Cornelia Huck @ 2018-01-24 16:30 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: KVM, linux-s390, Christian Borntraeger

On Tue, 23 Jan 2018 18:05:28 +0100
David Hildenbrand <david@redhat.com> wrote:

> No need to make this function special. Move it to a header right away.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c | 29 ++++++++++++-----------------
>  arch/s390/kvm/kvm-s390.h  |  5 +++++
>  2 files changed, 17 insertions(+), 17 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags() David Hildenbrand
  2018-01-23 17:44   ` Thomas Huth
@ 2018-01-24 16:35   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Cornelia Huck @ 2018-01-24 16:35 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: KVM, linux-s390, Christian Borntraeger

On Tue, 23 Jan 2018 18:05:29 +0100
David Hildenbrand <david@redhat.com> wrote:

> Use it in all places where we set cpuflags.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  4 ++--
>  arch/s390/kvm/kvm-s390.c  | 17 ++++++++---------
>  arch/s390/kvm/vsie.c      |  2 +-
>  3 files changed, 11 insertions(+), 12 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags() David Hildenbrand
  2018-01-23 17:46   ` Thomas Huth
@ 2018-01-24 16:38   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Cornelia Huck @ 2018-01-24 16:38 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: KVM, linux-s390, Christian Borntraeger

On Tue, 23 Jan 2018 18:05:30 +0100
David Hildenbrand <david@redhat.com> wrote:

> Use it just like kvm_s390_set_cpuflags().
> 
> Suggested-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  8 ++++----
>  arch/s390/kvm/kvm-s390.c  | 11 +++++------
>  arch/s390/kvm/kvm-s390.h  |  5 +++++
>  arch/s390/kvm/priv.c      |  2 +-
>  arch/s390/kvm/vsie.c      |  2 +-
>  5 files changed, 16 insertions(+), 12 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags()
  2018-01-23 17:05 ` [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags() David Hildenbrand
  2018-01-23 17:52   ` Thomas Huth
@ 2018-01-24 16:43   ` Cornelia Huck
  1 sibling, 0 replies; 14+ messages in thread
From: Cornelia Huck @ 2018-01-24 16:43 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: KVM, linux-s390, Christian Borntraeger

On Tue, 23 Jan 2018 18:05:31 +0100
David Hildenbrand <david@redhat.com> wrote:

> Use it just like kvm_s390_set_cpuflags() and kvm_s390_clear_cpuflags().
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/kvm/interrupt.c |  2 +-
>  arch/s390/kvm/kvm-s390.c  |  2 +-
>  arch/s390/kvm/kvm-s390.h  |  7 ++++++-
>  arch/s390/kvm/priv.c      |  4 ++--
>  arch/s390/kvm/sigp.c      | 14 +++++---------
>  5 files changed, 15 insertions(+), 14 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v1 0/4] KVM: s390: refactor cpuflag handling
  2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
                   ` (3 preceding siblings ...)
  2018-01-23 17:05 ` [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags() David Hildenbrand
@ 2018-01-24 16:43 ` Christian Borntraeger
  4 siblings, 0 replies; 14+ messages in thread
From: Christian Borntraeger @ 2018-01-24 16:43 UTC (permalink / raw)
  To: David Hildenbrand, KVM; +Cc: linux-s390, Cornelia Huck

Series applied. Thanks

On 01/23/2018 06:05 PM, David Hildenbrand wrote:
> We already have __set_cpuflag(), but its limited to interrupt.c. Conny
> suggested __clear_cpuflag(). I went one step further and introduce
> - kvm_s390_set_cpuflags()
> - kvm_s390_clear_cpuflags()
> - kvm_s390_test_cpuflags()
> 
> All applicable places are converted to use the new helpers. This beautifies
> the code at a couple of places quite a bit.
> 
> David Hildenbrand (4):
>   KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
>   KVM: s390: reuse kvm_s390_set_cpuflags()
>   KVM: s390: introduce and use kvm_s390_clear_cpuflags()
>   KVM: s390: introduce and use kvm_s390_test_cpuflags()
> 
>  arch/s390/kvm/interrupt.c | 43 +++++++++++++++++++------------------------
>  arch/s390/kvm/kvm-s390.c  | 30 ++++++++++++++----------------
>  arch/s390/kvm/kvm-s390.h  | 17 ++++++++++++++++-
>  arch/s390/kvm/priv.c      |  6 +++---
>  arch/s390/kvm/sigp.c      | 14 +++++---------
>  arch/s390/kvm/vsie.c      |  4 ++--
>  6 files changed, 59 insertions(+), 55 deletions(-)
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-01-24 16:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23 17:05 [PATCH v1 0/4] KVM: s390: refactor cpuflag handling David Hildenbrand
2018-01-23 17:05 ` [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags() David Hildenbrand
2018-01-23 17:43   ` Thomas Huth
2018-01-24 16:30   ` Cornelia Huck
2018-01-23 17:05 ` [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags() David Hildenbrand
2018-01-23 17:44   ` Thomas Huth
2018-01-24 16:35   ` Cornelia Huck
2018-01-23 17:05 ` [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags() David Hildenbrand
2018-01-23 17:46   ` Thomas Huth
2018-01-24 16:38   ` Cornelia Huck
2018-01-23 17:05 ` [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags() David Hildenbrand
2018-01-23 17:52   ` Thomas Huth
2018-01-24 16:43   ` Cornelia Huck
2018-01-24 16:43 ` [PATCH v1 0/4] KVM: s390: refactor cpuflag handling Christian Borntraeger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.