[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c169ed6d-7712-c8bc-d132-449afe9a753c@linux.ibm.com>
Date: Fri, 19 Nov 2021 09:27:26 +0100
From: Janosch Frank <frankja@...ux.ibm.com>
To: Janis Schoetterl-Glausch <scgl@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>
Cc: David Hildenbrand <david@...hat.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
kvm@...r.kernel.org, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/3] KVM: s390: gaccess: Refactor gpa and length
calculation
On 10/28/21 15:55, Janis Schoetterl-Glausch wrote:
> Improve readability be renaming the length variable and
> not calculating the offset manually.
>
> Signed-off-by: Janis Schoetterl-Glausch <scgl@...ux.ibm.com>
Reviewed-by: Janosch Frank <frankja@...ux.ibm.com>
> ---
> arch/s390/kvm/gaccess.c | 32 +++++++++++++++++---------------
> 1 file changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
> index 6af59c59cc1b..0d11cea92603 100644
> --- a/arch/s390/kvm/gaccess.c
> +++ b/arch/s390/kvm/gaccess.c
> @@ -831,7 +831,8 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
> unsigned long len, enum gacc_mode mode)
> {
> psw_t *psw = &vcpu->arch.sie_block->gpsw;
> - unsigned long _len, nr_pages, gpa, idx;
> + unsigned long nr_pages, gpa, idx;
> + unsigned int fragment_len;
> unsigned long pages_array[2];
> unsigned long *pages;
> int need_ipte_lock;
> @@ -855,15 +856,15 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
> ipte_lock(vcpu);
> rc = guest_page_range(vcpu, ga, ar, pages, nr_pages, asce, mode);
> for (idx = 0; idx < nr_pages && !rc; idx++) {
> - gpa = *(pages + idx) + (ga & ~PAGE_MASK);
> - _len = min(PAGE_SIZE - (gpa & ~PAGE_MASK), len);
> + gpa = pages[idx] + offset_in_page(ga);
> + fragment_len = min(PAGE_SIZE - offset_in_page(gpa), len);
> if (mode == GACC_STORE)
> - rc = kvm_write_guest(vcpu->kvm, gpa, data, _len);
> + rc = kvm_write_guest(vcpu->kvm, gpa, data, fragment_len);
> else
> - rc = kvm_read_guest(vcpu->kvm, gpa, data, _len);
> - len -= _len;
> - ga += _len;
> - data += _len;
> + rc = kvm_read_guest(vcpu->kvm, gpa, data, fragment_len);
> + len -= fragment_len;
> + ga += fragment_len;
> + data += fragment_len;
> }
> if (need_ipte_lock)
> ipte_unlock(vcpu);
> @@ -875,19 +876,20 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
> int access_guest_real(struct kvm_vcpu *vcpu, unsigned long gra,
> void *data, unsigned long len, enum gacc_mode mode)
> {
> - unsigned long _len, gpa;
> + unsigned int fragment_len;
> + unsigned long gpa;
> int rc = 0;
>
> while (len && !rc) {
> gpa = kvm_s390_real_to_abs(vcpu, gra);
> - _len = min(PAGE_SIZE - (gpa & ~PAGE_MASK), len);
> + fragment_len = min(PAGE_SIZE - offset_in_page(gpa), len);
> if (mode)
> - rc = write_guest_abs(vcpu, gpa, data, _len);
> + rc = write_guest_abs(vcpu, gpa, data, fragment_len);
> else
> - rc = read_guest_abs(vcpu, gpa, data, _len);
> - len -= _len;
> - gra += _len;
> - data += _len;
> + rc = read_guest_abs(vcpu, gpa, data, fragment_len);
> + len -= fragment_len;
> + gra += fragment_len;
> + data += fragment_len;
> }
> return rc;
> }
>
Powered by blists - more mailing lists