From: Janosch Frank <frankja@linux.ibm.com>
To: Thomas Huth <thuth@redhat.com>, kvm@vger.kernel.org
Cc: borntraeger@de.ibm.com, linux-s390@vger.kernel.org,
david@redhat.com, cohuck@redhat.com
Subject: Re: [PATCH v6] KVM: s390: Add new reset vcpu API
Date: Fri, 10 Jan 2020 12:39:37 +0100 [thread overview]
Message-ID: <ef959649-56f4-6f5f-2bca-0d0e1cebed5c@linux.ibm.com> (raw)
In-Reply-To: <9b9c3e09-e3ec-0ef2-0aef-a31ff34df33b@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 5787 bytes --]
On 1/10/20 11:36 AM, Thomas Huth wrote:
> On 10/01/2020 11.19, Janosch Frank wrote:
>> The architecture states that we need to reset local IRQs for all CPU
>> resets. Because the old reset interface did not support the normal CPU
>> reset we never did that on a normal reset.
>>
>> Let's implement an interface for the missing normal and clear resets
>> and reset all local IRQs, registers and control structures as stated
>> in the architecture.
>>
>> Userspace might already reset the registers via the vcpu run struct,
>> but as we need the interface for the interrupt clearing part anyway,
>> we implement the resets fully and don't rely on userspace to reset the
>> rest.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
> [...]
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index d9e6bf3d54f0..4936f9499291 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
>> case KVM_CAP_S390_CMMA_MIGRATION:
>> case KVM_CAP_S390_AIS:
>> case KVM_CAP_S390_AIS_MIGRATION:
>> + case KVM_CAP_S390_VCPU_RESETS:
>> r = 1;
>> break;
>> case KVM_CAP_S390_HPAGE_1M:
>> @@ -2844,35 +2845,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
>>
>> }
>>
>> -static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu)
>> -{
>> - /* this equals initial cpu reset in pop, but we don't switch to ESA */
>> - vcpu->arch.sie_block->gpsw.mask = 0UL;
>> - vcpu->arch.sie_block->gpsw.addr = 0UL;
>> - kvm_s390_set_prefix(vcpu, 0);
>> - kvm_s390_set_cpu_timer(vcpu, 0);
>> - vcpu->arch.sie_block->ckc = 0UL;
>> - vcpu->arch.sie_block->todpr = 0;
>> - memset(vcpu->arch.sie_block->gcr, 0, 16 * sizeof(__u64));
>> - vcpu->arch.sie_block->gcr[0] = CR0_UNUSED_56 |
>> - CR0_INTERRUPT_KEY_SUBMASK |
>> - CR0_MEASUREMENT_ALERT_SUBMASK;
>> - vcpu->arch.sie_block->gcr[14] = CR14_UNUSED_32 |
>> - CR14_UNUSED_33 |
>> - CR14_EXTERNAL_DAMAGE_SUBMASK;
>> - /* make sure the new fpc will be lazily loaded */
>> - save_fpu_regs();
>> - current->thread.fpu.fpc = 0;
>> - vcpu->arch.sie_block->gbea = 1;
>> - vcpu->arch.sie_block->pp = 0;
>> - vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
>> - vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
>> - kvm_clear_async_pf_completion_queue(vcpu);
>> - if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
>> - kvm_s390_vcpu_stop(vcpu);
>> - kvm_s390_clear_local_irqs(vcpu);
>> -}
>> -
>> void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
>> {
>> mutex_lock(&vcpu->kvm->lock);
>> @@ -3287,10 +3259,78 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>> return r;
>> }
>>
>> -static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
>> +static void kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
>> {
>> - kvm_s390_vcpu_initial_reset(vcpu);
>> - return 0;
>> + vcpu->arch.sie_block->gpsw.mask = ~PSW_MASK_RI;
>> + vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
>> + memset(vcpu->run->s.regs.riccb, 0, sizeof(vcpu->run->s.regs.riccb));
>> +
>> + kvm_clear_async_pf_completion_queue(vcpu);
>> + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
>> + kvm_s390_vcpu_stop(vcpu);
>> + kvm_s390_clear_local_irqs(vcpu);
>> +}
>> +
>> +static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
>> +{
>> + /* Initial reset is a superset of the normal reset */
>> + kvm_arch_vcpu_ioctl_normal_reset(vcpu);
>> +
>> + /* this equals initial cpu reset in pop, but we don't switch to ESA */
>> + vcpu->arch.sie_block->gpsw.mask = 0UL;
>> + vcpu->arch.sie_block->gpsw.addr = 0UL;
>> + kvm_s390_set_prefix(vcpu, 0);
>> + kvm_s390_set_cpu_timer(vcpu, 0);
>> + vcpu->arch.sie_block->ckc = 0UL;
>> + vcpu->arch.sie_block->todpr = 0;
>> + memset(vcpu->arch.sie_block->gcr, 0, 16 * sizeof(__u64));
>> + vcpu->arch.sie_block->gcr[0] = CR0_UNUSED_56 |
>> + CR0_INTERRUPT_KEY_SUBMASK |
>> + CR0_MEASUREMENT_ALERT_SUBMASK;
>> + vcpu->arch.sie_block->gcr[14] = CR14_UNUSED_32 |
>> + CR14_UNUSED_33 |
>> + CR14_EXTERNAL_DAMAGE_SUBMASK;
>> + /* make sure the new fpc will be lazily loaded */
>> + save_fpu_regs();
>> + current->thread.fpu.fpc = 0;
>> + vcpu->arch.sie_block->gbea = 1;
>> + vcpu->arch.sie_block->pp = 0;
>> + vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
>> +}
>> +
>> +static void kvm_arch_vcpu_ioctl_clear_reset(struct kvm_vcpu *vcpu)
>> +{
>> + struct kvm_sync_regs *regs = &vcpu->run->s.regs;
>> +
>> + /* Clear reset is a superset of the initial reset */
>> + kvm_arch_vcpu_ioctl_normal_reset(vcpu);
>> +
>> + memset(®s->gprs, 0, sizeof(regs->gprs));
>> + /*
>> + * Will be picked up via save_fpu_regs() in the initial reset
>> + * fallthrough.
>
> The word "fallthrough" now likely should be removed from the comment.
>
> Also, I'm not an expert in this lazy-fpu stuff, but don't you rather
> have to deal with current->thread.fpu.regs here instead?
Yes, I'll need to fix that.
>
>> + */
>> + memset(®s->vrs, 0, sizeof(regs->vrs));
>> + memset(®s->acrs, 0, sizeof(regs->acrs));
>> +
>> + regs->etoken = 0;
>> + regs->etoken_extension = 0;
>> +
>> + memset(®s->gscb, 0, sizeof(regs->gscb));
>> + if (MACHINE_HAS_GS) {
>> + preempt_disable();
>> + __ctl_set_bit(2, 4);
>> + if (current->thread.gs_cb) {
>> + vcpu->arch.host_gscb = current->thread.gs_cb;
>> + save_gs_cb(vcpu->arch.host_gscb);
>> + }
>> + if (vcpu->arch.gs_enabled) {
>> + current->thread.gs_cb = (struct gs_cb *)
>> + &vcpu->run->s.regs.gscb;
>> + restore_gs_cb(current->thread.gs_cb);
>> + }
>> + preempt_enable();
>> + }
>> }
>
> Thomas
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2020-01-10 11:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 10:19 [PATCH v6] KVM: s390: Add new reset vcpu API Janosch Frank
2020-01-10 10:28 ` Cornelia Huck
2020-01-10 10:36 ` Thomas Huth
2020-01-10 11:39 ` Janosch Frank [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ef959649-56f4-6f5f-2bca-0d0e1cebed5c@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox