s390/uv: de-duplicate checks for Protected Host Virtualization
authorAlexander Egorenkov <egorenar@linux.ibm.com>
Fri, 25 Jun 2021 07:51:15 +0000 (09:51 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Tue, 27 Jul 2021 07:39:14 +0000 (09:39 +0200)
De-duplicate checks for Protected Host Virtualization in decompressor and
kernel.

Set prot_virt_host=0 in the decompressor in *any* of the following cases
and hand it over to the decompressed kernel:
* No explicit prot_virt=1 is given on the kernel command-line
* Protected Guest Virtualization is enabled
* Hardware support not present
* kdump or stand-alone dump

The decompressed kernel needs to use only is_prot_virt_host() instead of
performing again all checks done by the decompressor.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/boot/uv.c
arch/s390/kernel/uv.c

index 5aea68d6d75de07688907a8d3f1c21af64f6d02d..735f29f811627c20120b6e9832c1b39836761a37 100644 (file)
@@ -51,32 +51,34 @@ void uv_query_info(void)
 }
 
 #if IS_ENABLED(CONFIG_KVM)
-static bool has_uv_sec_stor_limit(void)
+void adjust_to_uv_max(unsigned long *vmax)
 {
-       /*
-        * keep these conditions in line with setup_uv()
-        */
-       if (!is_prot_virt_host())
-               return false;
-
-       if (is_prot_virt_guest())
-               return false;
-
-       if (!test_facility(158))
-               return false;
-
-       return !!uv_info.max_sec_stor_addr;
+       if (is_prot_virt_host() && uv_info.max_sec_stor_addr)
+               *vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr);
 }
 
-void adjust_to_uv_max(unsigned long *vmax)
+static int is_prot_virt_host_capable(void)
 {
-       if (has_uv_sec_stor_limit())
-               *vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr);
+       /* disable if no prot_virt=1 given on command-line */
+       if (!is_prot_virt_host())
+               return 0;
+       /* disable if protected guest virtualization is enabled */
+       if (is_prot_virt_guest())
+               return 0;
+       /* disable if no hardware support */
+       if (!test_facility(158))
+               return 0;
+       /* disable if kdump */
+       if (OLDMEM_BASE)
+               return 0;
+       /* disable if stand-alone dump */
+       if (ipl_block_valid && is_ipl_block_dump())
+               return 0;
+       return 1;
 }
 
 void sanitize_prot_virt_host(void)
 {
-       if (OLDMEM_BASE || (ipl_block_valid && is_ipl_block_dump()))
-               prot_virt_host = 0;
+       prot_virt_host = is_prot_virt_host_capable();
 }
 #endif
index aeb0a15bcbb7167bdf67c303534b3b5d1d752ee8..5a656c7b7a67aee4750be534dfd941cb49983ed0 100644 (file)
@@ -51,24 +51,9 @@ void __init setup_uv(void)
 {
        unsigned long uv_stor_base;
 
-       /*
-        * keep these conditions in line with has_uv_sec_stor_limit()
-        */
        if (!is_prot_virt_host())
                return;
 
-       if (is_prot_virt_guest()) {
-               prot_virt_host = 0;
-               pr_warn("Protected virtualization not available in protected guests.");
-               return;
-       }
-
-       if (!test_facility(158)) {
-               prot_virt_host = 0;
-               pr_warn("Protected virtualization not supported by the hardware.");
-               return;
-       }
-
        uv_stor_base = (unsigned long)memblock_alloc_try_nid(
                uv_info.uv_base_stor_len, SZ_1M, SZ_2G,
                MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE);