[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93c07dce-a64a-fa1a-f70c-9db22ca53f68@linux.ibm.com>
Date: Wed, 18 May 2022 12:51:33 +0200
From: Pierre Morel <pmorel@...ux.ibm.com>
To: David Hildenbrand <david@...hat.com>, kvm@...r.kernel.org
Cc: linux-s390@...r.kernel.org, linux-kernel@...r.kernel.org,
borntraeger@...ibm.com, frankja@...ux.ibm.com, cohuck@...hat.com,
thuth@...hat.com, imbrenda@...ux.ibm.com, hca@...ux.ibm.com,
gor@...ux.ibm.com, wintera@...ux.ibm.com, seiden@...ux.ibm.com,
nrb@...ux.ibm.com
Subject: Re: [PATCH v9 3/3] s390x: KVM: resetting the Topology-Change-Report
On 5/12/22 11:31, David Hildenbrand wrote:
> On 06.05.22 11:24, Pierre Morel wrote:
>> During a subsystem reset the Topology-Change-Report is cleared.
>> Let's give userland the possibility to clear the MTCR in the case
>> of a subsystem reset.
>>
>> To migrate the MTCR, let's give userland the possibility to
>> query the MTCR state.
>>
>> Signed-off-by: Pierre Morel <pmorel@...ux.ibm.com>
>> ---
>> arch/s390/include/uapi/asm/kvm.h | 5 ++
>> arch/s390/kvm/kvm-s390.c | 79 ++++++++++++++++++++++++++++++++
>> 2 files changed, 84 insertions(+)
>>
>> diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
>> index 7a6b14874d65..abdcf4069343 100644
>> --- a/arch/s390/include/uapi/asm/kvm.h
>> +++ b/arch/s390/include/uapi/asm/kvm.h
>> @@ -74,6 +74,7 @@ struct kvm_s390_io_adapter_req {
>> #define KVM_S390_VM_CRYPTO 2
>> #define KVM_S390_VM_CPU_MODEL 3
>> #define KVM_S390_VM_MIGRATION 4
>> +#define KVM_S390_VM_CPU_TOPOLOGY 5
>>
>> /* kvm attributes for mem_ctrl */
>> #define KVM_S390_VM_MEM_ENABLE_CMMA 0
>> @@ -171,6 +172,10 @@ struct kvm_s390_vm_cpu_subfunc {
>> #define KVM_S390_VM_MIGRATION_START 1
>> #define KVM_S390_VM_MIGRATION_STATUS 2
>>
>> +/* kvm attributes for cpu topology */
>> +#define KVM_S390_VM_CPU_TOPO_MTR_CLEAR 0
>> +#define KVM_S390_VM_CPU_TOPO_MTR_SET 1
>> +
>> /* for KVM_GET_REGS and KVM_SET_REGS */
>> struct kvm_regs {
>> /* general purpose regs for s390 */
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index c8bdce31464f..80a1244f0ead 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -1731,6 +1731,76 @@ static void kvm_s390_sca_set_mtcr(struct kvm *kvm)
>> ipte_unlock(kvm);
>> }
>>
>> +/**
>> + * kvm_s390_sca_clear_mtcr
>> + * @kvm: guest KVM description
>> + *
>> + * Is only relevant if the topology facility is present,
>> + * the caller should check KVM facility 11
>> + *
>> + * Updates the Multiprocessor Topology-Change-Report to signal
>> + * the guest with a topology change.
>> + */
>> +static void kvm_s390_sca_clear_mtcr(struct kvm *kvm)
>> +{
>> + struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */
>> +
>> + ipte_lock(kvm);
>> + sca->utility &= ~SCA_UTILITY_MTCR;
>
>
> One space too much.
>
> sca->utility &= ~SCA_UTILITY_MTCR;
>
>> + ipte_unlock(kvm);
>> +}
>> +
>> +static int kvm_s390_set_topology(struct kvm *kvm, struct kvm_device_attr *attr)
>> +{
>> + if (!test_kvm_facility(kvm, 11))
>> + return -ENXIO;
>> +
>> + switch (attr->attr) {
>> + case KVM_S390_VM_CPU_TOPO_MTR_SET:
>> + kvm_s390_sca_set_mtcr(kvm);
>> + break;
>> + case KVM_S390_VM_CPU_TOPO_MTR_CLEAR:
>> + kvm_s390_sca_clear_mtcr(kvm);
>> + break;
>> + }
>> + return 0;
>> +}
>> +
>> +/**
>> + * kvm_s390_sca_get_mtcr
>> + * @kvm: guest KVM description
>> + *
>> + * Is only relevant if the topology facility is present,
>> + * the caller should check KVM facility 11
>> + *
>> + * reports to QEMU the Multiprocessor Topology-Change-Report.
>> + */
>> +static int kvm_s390_sca_get_mtcr(struct kvm *kvm)
>> +{
>> + struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */
>> + int val;
>> +
>> + ipte_lock(kvm);
>> + val = !!(sca->utility & SCA_UTILITY_MTCR);
>> + ipte_unlock(kvm);
>> +
>> + return val;
>> +}
>> +
>> +static int kvm_s390_get_topology(struct kvm *kvm, struct kvm_device_attr *attr)
>> +{
>> + int mtcr;
>
> I think we prefer something like u16 when copying to user space.
I come back here.
I think I prefer to keep the int.
the u16 is more than the MTCR but the entire utility field, so what
should I do:
rename the function to kvm_s390_get_sca_utility() ?
and then should I modify the KVM_S390_VM_CPU_TOPOLOGY
to KVM_S390_VM_SCA_UTILITY ?
I do not like that, I do not think we should report/handle more
information than expected/needed.
I can mask the MTCR bit and return a u16 with bit 0 (0x8000) set
but I find this a little weird
I admit an int is may be not optimal.
logically I should report a bool but I do not like to report a bool
through the UAPI.
The more I think about it the more I think an int is OK.
Or in the case we want to spare memory space I can create a flag in a
u16 but it should theoretically be different than the firmware MTCR bit.
Could be 0x0001.
But still, it is only to leave during the copy_to_user where the copy of
an int may be as good or better than the copy of a u16.
So any more opinion on this?
Regards,
Pierre
>
>> +
>> + if (!test_kvm_facility(kvm, 11))
>> + return -ENXIO;
>> +
>> + mtcr = kvm_s390_sca_get_mtcr(kvm);
>> + if (copy_to_user((void __user *)attr->addr, &mtcr, sizeof(mtcr)))
>> + return -EFAULT;
>> +
>> + return 0;
>> +}
>
> You should probably add documentation, and document that only the last
> bit (0x1) has a meaning.
>
> Apart from that LGTM.
>
--
Pierre Morel
IBM Lab Boeblingen
Powered by blists - more mailing lists