Re: [PATCH v4 07/10] selftests: kvm: s390: Add uc_map_unmap VM test case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 6 Aug 2024 15:13:34 +0200
Janosch Frank <frankja@xxxxxxxxxxxxx> wrote:

> On 8/2/24 5:59 PM, Christoph Schlameuss wrote:
> > Add a test case verifying basic running and interaction of ucontrol VMs.
> > Fill the segment and page tables for allocated memory and map memory on
> > first access.
> > 
> > * uc_map_unmap
> >    Store and load data to mapped and unmapped memory and use pic segment
> >    translation handling to map memory on access.
> > 
> > Signed-off-by: Christoph Schlameuss <schlameuss@xxxxxxxxxxxxx>
> > ---
> >   .../selftests/kvm/s390x/ucontrol_test.c       | 165 +++++++++++++++++-
> >   1 file changed, 164 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/kvm/s390x/ucontrol_test.c b/tools/testing/selftests/kvm/s390x/ucontrol_test.c
> > index 030c59010fe1..72ad30fbe4ac 100644
> > --- a/tools/testing/selftests/kvm/s390x/ucontrol_test.c
> > +++ b/tools/testing/selftests/kvm/s390x/ucontrol_test.c
> > @@ -16,7 +16,13 @@
> >   #include <linux/capability.h>
> >   #include <linux/sizes.h>  
> 
> [...]
> 
> > +#define VM_MEM_MAX (VM_MEM_SIZE + VM_MEM_EXT_SIZE)  
> 
> You defined this but never use it.
> Instead you're still adding up VM_MEM_SIZE and VM_MEM_EXT_SIZE.
> 

I will remove that.

> > +
> > +#define PAGES_PER_SEGMENT 4  
> 
> You mean pages per segment table?
> 

Yes, I did name this analog to the existing PAGES_PER_REGION from
"tools/testing/selftests/kvm/lib/s390x/processor.c".
If you think that would be useful in the future we could also pull both
constants into "processor.h".

> [...]
> 
> > +/* initialize segment and page tables for uc_kvm tests */
> > +static void init_st_pt(FIXTURE_DATA(uc_kvm) * self)
> > +{
> > +	struct kvm_sync_regs *sync_regs = &self->run->s.regs;
> > +	struct kvm_run *run = self->run;
> > +	void *se_addr;
> > +	int si, pi;
> > +	u64 *phd;
> > +
> > +	/* set PASCE addr */
> > +	self->pgd = self->base_gpa + SZ_1M;
> > +	phd = gpa2hva(self, self->pgd);
> > +	memset(phd, 0xff, PAGES_PER_SEGMENT * PAGE_SIZE);
> > +
> > +	for (si = 0; si < ((VM_MEM_SIZE + VM_MEM_EXT_SIZE) / SZ_1M); si++) {
> > +		/* create ste */
> > +		phd[si] = (self->pgd
> > +			+ (PAGES_PER_SEGMENT * PAGE_SIZE
> > +				* ((VM_MEM_SIZE + VM_MEM_EXT_SIZE) / SZ_1M))
> > +			+ (PAGES_PER_SEGMENT * PAGE_SIZE * si)) & ~0x7fful;
> > +		se_addr = gpa2hva(self, phd[si]);
> > +		memset(se_addr, 0xff, PAGES_PER_SEGMENT * PAGE_SIZE);
> > +		for (pi = 0; pi < (SZ_1M / PAGE_SIZE); pi++) {
> > +			/* create pte */
> > +			((u64 *)se_addr)[pi] = (self->base_gpa
> > +				+ (si * SZ_1M) + (pi * PAGE_SIZE)) & ~0xffful;
> > +		}  
> 
> That's barely readable, can you split that into functions or make it 
> more readable in some other way?
> 

I will tinker a bit to make this readable.

> > +	}
> > +	pr_debug("segment table entry %p (0x%lx) --> %p\n",
> > +		 phd, phd[0], gpa2hva(self, (phd[0] & ~0x7fful)));
> > +	print_hex_bytes("st", (u64)phd, 64);
> > +	print_hex_bytes("pt", (u64)gpa2hva(self, phd[0]), 128);
> > +	print_hex_bytes("pt+", (u64)
> > +			gpa2hva(self, phd[0] + (PAGES_PER_SEGMENT * PAGE_SIZE
> > +			* ((VM_MEM_SIZE + VM_MEM_EXT_SIZE) / SZ_1M)) - 0x64), 128);
> > +
> > +	/* PASCE TT=00 for segment table */
> > +	sync_regs->crs[1] = self->pgd | 0x3;
> > +	run->kvm_dirty_regs |= KVM_SYNC_CRS;
> > +}
> > +  
> 





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux