On Tue, 9 Jul 2024 14:56:59 +0200 Christoph Schlameuss <schlameuss@xxxxxxxxxxxxx> wrote: > Add a uc_kvm fixture to create and destroy a ucontrol VM. > > * uc_sie_assertions asserts basic settings in the SIE as setup by the > kernel. > * uc_attr_mem_limit asserts the memory limit is max value and cannot be > set (not supported). > * uc_no_dirty_log asserts dirty log is not supported. > > Signed-off-by: Christoph Schlameuss <schlameuss@xxxxxxxxxxxxx> [...] > + > +/** > + * create VM with single vcpu, map kvm_run and SIE control block for easy access > + */ > +FIXTURE_SETUP(uc_kvm) > +{ > + struct kvm_s390_vm_cpu_processor info; > + int rc; > + > + require_ucontrol_admin(); > + > + self->kvm_fd = open_kvm_dev_path_or_exit(); > + self->vm_fd = ioctl(self->kvm_fd, KVM_CREATE_VM, KVM_VM_S390_UCONTROL); > + ASSERT_GE(self->vm_fd, 0); > + > + kvm_device_attr_get(self->vm_fd, KVM_S390_VM_CPU_MODEL, > + KVM_S390_VM_CPU_PROCESSOR, &info); > + TH_LOG("create VM 0x%llx", info.cpuid); > + > + self->vcpu_fd = ioctl(self->vm_fd, KVM_CREATE_VCPU, 0); > + ASSERT_GE(self->vcpu_fd, 0); > + > + self->kvm_run_size = ioctl(self->kvm_fd, KVM_GET_VCPU_MMAP_SIZE, NULL); > + ASSERT_GE(self->kvm_run_size, sizeof(struct kvm_run)) > + TH_LOG(KVM_IOCTL_ERROR(KVM_GET_VCPU_MMAP_SIZE, self->kvm_run_size)); > + self->run = (struct kvm_run *)mmap(NULL, self->kvm_run_size, > + PROT_READ | PROT_WRITE, MAP_SHARED, self->vcpu_fd, 0); > + ASSERT_NE(self->run, MAP_FAILED); > + /** > + * For virtual cpus that have been created with S390 user > + * controlled virtual machines, this line does not need to end like this, I guess? > + * the resulting vcpu fd can be memory mapped at page offset > + * KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map > + * of the virtual cpu's hardware control block. > + */ with the comment fixed: Reviewed-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx> [...]