KVM: s390: refactor cpuflag handling
cover KVM: s390: refactor cpuflag handling
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(-)
Signature · 1 line
2.14.3
PATCH 1/4 KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
No need to make this function special. Move it to a header right away.
--- arch/s390/kvm/interrupt.c | 29 ++++++++++++----------------- arch/s390/kvm/kvm-s390.h | 5 +++++ 2 files changed, 17 insertions(+), 17 deletions(-)
arch/s390/kvm/interrupt.c +12 -17
@@ -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);
arch/s390/kvm/kvm-s390.h +5 -0
@@ -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 ;
Signature · 1 line
2.14.3
Re: [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
Quoted 7 lines · David Hildenbrand
No need to make this function special. Move it to a header right away.
Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/kvm/interrupt.c | 29 ++++++++++++----------------- arch/s390/kvm/kvm-s390.h | 5 +++++ 2 files changed, 17 insertions(+), 17 deletions(-)
Re: [PATCH v1 1/4] KVM: s390: rename __set_cpuflag() to kvm_s390_set_cpuflags()
In reply to David HildenbrandQuoted 7 lines · On Tue, 23 Jan 2018 18:05:28 +0100 David Hildenbrand <[email protected]> wrote:
No need to make this function special. Move it to a header right away.
Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/kvm/interrupt.c | 29 ++++++++++++----------------- arch/s390/kvm/kvm-s390.h | 5 +++++ 2 files changed, 17 insertions(+), 17 deletions(-)
PATCH 2/4 KVM: s390: reuse kvm_s390_set_cpuflags()
In reply to David HildenbrandUse it in all places where we set cpuflags.
--- 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(-)
arch/s390/kvm/interrupt.c +2 -2
@@ -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); }
arch/s390/kvm/kvm-s390.c +8 -9
@@ -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++) {
arch/s390/kvm/vsie.c +1 -1
@@ -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.
Signature · 1 line
2.14.3
Re: [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags()
Quoted 8 lines · David Hildenbrand
Use it in all places where we set cpuflags.
Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
Re: [PATCH v1 2/4] KVM: s390: reuse kvm_s390_set_cpuflags()
In reply to David HildenbrandQuoted 8 lines · On Tue, 23 Jan 2018 18:05:29 +0100 David Hildenbrand <[email protected]> wrote:
Use it in all places where we set cpuflags.
Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
PATCH 3/4 KVM: s390: introduce and use kvm_s390_clear_cpuflags()
In reply to David HildenbrandUse it just like kvm_s390_set_cpuflags().
--- 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(-)
arch/s390/kvm/interrupt.c +4 -4
@@ -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 );
arch/s390/kvm/kvm-s390.c +5 -6
@@ -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.
arch/s390/kvm/kvm-s390.h +5 -0
@@ -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 ;
arch/s390/kvm/priv.c +1 -1
@@ -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 );
arch/s390/kvm/vsie.c +1 -1
@@ -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 ); }
Signature · 1 line
2.14.3
Re: [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags()
Quoted 11 lines · David Hildenbrand
Use it just like
kvm_s390_set_cpuflags().Suggested-by Cornelia Huck <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
Re: [PATCH v1 3/4] KVM: s390: introduce and use kvm_s390_clear_cpuflags()
In reply to David HildenbrandQuoted 11 lines · On Tue, 23 Jan 2018 18:05:30 +0100 David Hildenbrand <[email protected]> wrote:
Use it just like
kvm_s390_set_cpuflags().Suggested-by Cornelia Huck <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
PATCH 4/4 KVM: s390: introduce and use kvm_s390_test_cpuflags()
In reply to David HildenbrandUse it just like kvm_s390_set_cpuflags() and kvm_s390_clear_cpuflags().
--- 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(-)
arch/s390/kvm/interrupt.c +1 -1
@@ -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 ());
arch/s390/kvm/kvm-s390.c +1 -1
@@ -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)
arch/s390/kvm/kvm-s390.h +6 -1
@@ -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)
arch/s390/kvm/priv.c +2 -2
@@ -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 |
arch/s390/kvm/sigp.c +5 -9
@@ -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 {
Signature · 1 line
2.14.3
Re: [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags()
Quoted 10 lines · David Hildenbrand
Use it just like
kvm_s390_set_cpuflags()andkvm_s390_clear_cpuflags().Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
Re: [PATCH v1 4/4] KVM: s390: introduce and use kvm_s390_test_cpuflags()
In reply to David HildenbrandQuoted 10 lines · On Tue, 23 Jan 2018 18:05:31 +0100 David Hildenbrand <[email protected]> wrote:
Use it just like
kvm_s390_set_cpuflags()andkvm_s390_clear_cpuflags().Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
Series applied. Thanks
Quoted 23 lines · David Hildenbrand
We already have
__set_cpuflag(), but its limited tointerrupt.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()tokvm_s390_set_cpuflags()
KVM: s390: reusekvm_s390_set_cpuflags()
KVM: s390: introduce and usekvm_s390_clear_cpuflags()
KVM: s390: introduce and usekvm_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(-)