On Tue, Aug 13, 2024 at 09:21:12AM +0200, Janosch Frank wrote:
> On 8/7/24 5:45 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 <schlame...@linux.ibm.com>
> > ---
> >   .../selftests/kvm/s390x/ucontrol_test.c       | 167 +++++++++++++++++-
> >   1 file changed, 166 insertions(+), 1 deletion(-)
> > 
> 
> [...]
> 
> > +static void init_st_pt(FIXTURE_DATA(uc_kvm) * self)
> > +{
> > +   struct kvm_sync_regs *sync_regs = &self->run->s.regs;
> > +   u64 first_pt_addr, ste, s_addr, pte;
> > +   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, VM_MEM_TABLE_SIZE);
> > +
> > +   first_pt_addr = self->pgd + (VM_MEM_TABLE_SIZE * VM_MEM_MAX_M);
> > +   /* for each segment in the VM */
> > +   for (si = 0; si < VM_MEM_MAX_M; si++) {
> > +           /* build segment table entry (ste) */
> > +           ste = (first_pt_addr + (VM_MEM_TABLE_SIZE * si)) & ~0x7fful;
> > +           /* store ste in st */
> > +           phd[si] = ste;
> > +
> > +           se_addr = gpa2hva(self, phd[si]);
> > +           s_addr = self->base_gpa + (si * SZ_1M);
> > +           memset(se_addr, 0xff, VM_MEM_TABLE_SIZE);
> > +           /* for each page in the segment (VM) */
> > +           for (pi = 0; pi < (SZ_1M / PAGE_SIZE); pi++) {
> > +                   /* build page table entry (pte) */
> > +                   pte = (s_addr + (pi * PAGE_SIZE)) & ~0xffful;
> > +                   /* store pte in pt */
> > +                   ((u64 *)se_addr)[pi] = pte;
> > +           }
> > +   }
> > +   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);
> > +
> > +   /* PASCE TT=00 for segment table */
> > +   sync_regs->crs[1] = self->pgd | 0x3;
> > +   run->kvm_dirty_regs |= KVM_SYNC_CRS;
> > +}
> 
> Having a closer look at this I don't understand why we need to setup DAT in
> the guest. Also, the guest's memory easily fits in a couple of segment
> entries so you could set the table length TL in the ASCE to one page instead
> of 4.
> 

I did only create the tables to be able to switch the DAT on and with that use a
PSW that is a bit more normal.
Switching the DAT off will work fine for the tests here without loosing any
coverage in KVM. So I will remove it here and in the skey test.

Reply via email to