Skip to content

Commit 55c171a

Browse files
cohuckGleb Natapov
authored and
Gleb Natapov
committed
KVM: s390: Handle hosts not supporting s390-virtio.
Running under a kvm host does not necessarily imply the presence of a page mapped above the main memory with the virtio information; however, the code includes a hard coded access to that page. Instead, check for the presence of the page and exit gracefully before we hit an addressing exception if it does not exist. Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Reviewed-by: Alexander Graf <agraf@suse.de> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> cc: stable@vger.kernel.org Signed-off-by: Gleb Natapov <gleb@redhat.com>
1 parent d4b06c2 commit 55c171a

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

drivers/s390/kvm/kvm_virtio.c

+30-8
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,26 @@ static void kvm_extint_handler(struct ext_code ext_code,
421421
}
422422
}
423423

424+
/*
425+
* For s390-virtio, we expect a page above main storage containing
426+
* the virtio configuration. Try to actually load from this area
427+
* in order to figure out if the host provides this page.
428+
*/
429+
static int __init test_devices_support(unsigned long addr)
430+
{
431+
int ret = -EIO;
432+
433+
asm volatile(
434+
"0: lura 0,%1\n"
435+
"1: xgr %0,%0\n"
436+
"2:\n"
437+
EX_TABLE(0b,2b)
438+
EX_TABLE(1b,2b)
439+
: "+d" (ret)
440+
: "a" (addr)
441+
: "0", "cc");
442+
return ret;
443+
}
424444
/*
425445
* Init function for virtio
426446
* devices are in a single page above top of "normal" mem
@@ -432,21 +452,23 @@ static int __init kvm_devices_init(void)
432452
if (!MACHINE_IS_KVM)
433453
return -ENODEV;
434454

455+
if (test_devices_support(real_memory_size) < 0)
456+
return -ENODEV;
457+
458+
rc = vmem_add_mapping(real_memory_size, PAGE_SIZE);
459+
if (rc)
460+
return rc;
461+
462+
kvm_devices = (void *) real_memory_size;
463+
435464
kvm_root = root_device_register("kvm_s390");
436465
if (IS_ERR(kvm_root)) {
437466
rc = PTR_ERR(kvm_root);
438467
printk(KERN_ERR "Could not register kvm_s390 root device");
468+
vmem_remove_mapping(real_memory_size, PAGE_SIZE);
439469
return rc;
440470
}
441471

442-
rc = vmem_add_mapping(real_memory_size, PAGE_SIZE);
443-
if (rc) {
444-
root_device_unregister(kvm_root);
445-
return rc;
446-
}
447-
448-
kvm_devices = (void *) real_memory_size;
449-
450472
INIT_WORK(&hotplug_work, hotplug_devices);
451473

452474
service_subclass_irq_register();

0 commit comments

Comments
 (0)