KVM: s390: gaccess: Refactor gpa and length calculation
Improve readability by renaming the length variable and not calculating the offset manually. Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-Id: <20211126164549.7046-2-scgl@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
This commit is contained in:
committed by
Janosch Frank
parent
49ae248b61
commit
416e7f0c9d
@ -831,8 +831,9 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
|
|||||||
unsigned long len, enum gacc_mode mode)
|
unsigned long len, enum gacc_mode mode)
|
||||||
{
|
{
|
||||||
psw_t *psw = &vcpu->arch.sie_block->gpsw;
|
psw_t *psw = &vcpu->arch.sie_block->gpsw;
|
||||||
unsigned long _len, nr_pages, gpa, idx;
|
unsigned long nr_pages, gpa, idx;
|
||||||
unsigned long pages_array[2];
|
unsigned long pages_array[2];
|
||||||
|
unsigned int fragment_len;
|
||||||
unsigned long *pages;
|
unsigned long *pages;
|
||||||
int need_ipte_lock;
|
int need_ipte_lock;
|
||||||
union asce asce;
|
union asce asce;
|
||||||
@ -855,15 +856,15 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
|
|||||||
ipte_lock(vcpu);
|
ipte_lock(vcpu);
|
||||||
rc = guest_page_range(vcpu, ga, ar, pages, nr_pages, asce, mode);
|
rc = guest_page_range(vcpu, ga, ar, pages, nr_pages, asce, mode);
|
||||||
for (idx = 0; idx < nr_pages && !rc; idx++) {
|
for (idx = 0; idx < nr_pages && !rc; idx++) {
|
||||||
gpa = *(pages + idx) + (ga & ~PAGE_MASK);
|
gpa = pages[idx] + offset_in_page(ga);
|
||||||
_len = min(PAGE_SIZE - (gpa & ~PAGE_MASK), len);
|
fragment_len = min(PAGE_SIZE - offset_in_page(gpa), len);
|
||||||
if (mode == GACC_STORE)
|
if (mode == GACC_STORE)
|
||||||
rc = kvm_write_guest(vcpu->kvm, gpa, data, _len);
|
rc = kvm_write_guest(vcpu->kvm, gpa, data, fragment_len);
|
||||||
else
|
else
|
||||||
rc = kvm_read_guest(vcpu->kvm, gpa, data, _len);
|
rc = kvm_read_guest(vcpu->kvm, gpa, data, fragment_len);
|
||||||
len -= _len;
|
len -= fragment_len;
|
||||||
ga += _len;
|
ga += fragment_len;
|
||||||
data += _len;
|
data += fragment_len;
|
||||||
}
|
}
|
||||||
if (need_ipte_lock)
|
if (need_ipte_lock)
|
||||||
ipte_unlock(vcpu);
|
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,
|
int access_guest_real(struct kvm_vcpu *vcpu, unsigned long gra,
|
||||||
void *data, unsigned long len, enum gacc_mode mode)
|
void *data, unsigned long len, enum gacc_mode mode)
|
||||||
{
|
{
|
||||||
unsigned long _len, gpa;
|
unsigned int fragment_len;
|
||||||
|
unsigned long gpa;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
while (len && !rc) {
|
while (len && !rc) {
|
||||||
gpa = kvm_s390_real_to_abs(vcpu, gra);
|
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)
|
if (mode)
|
||||||
rc = write_guest_abs(vcpu, gpa, data, _len);
|
rc = write_guest_abs(vcpu, gpa, data, fragment_len);
|
||||||
else
|
else
|
||||||
rc = read_guest_abs(vcpu, gpa, data, _len);
|
rc = read_guest_abs(vcpu, gpa, data, fragment_len);
|
||||||
len -= _len;
|
len -= fragment_len;
|
||||||
gra += _len;
|
gra += fragment_len;
|
||||||
data += _len;
|
data += fragment_len;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user