From 7f33565b256697727fec7fc86bc1ca07683d7c81 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Fri, 25 Jun 2021 09:51:15 +0200 Subject: [PATCH] s390/uv: de-duplicate checks for Protected Host Virtualization 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 Reviewed-by: Vasily Gorbik Signed-off-by: Heiko Carstens --- arch/s390/boot/uv.c | 40 +++++++++++++++++++++------------------- arch/s390/kernel/uv.c | 15 --------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/arch/s390/boot/uv.c b/arch/s390/boot/uv.c index 5aea68d6d75d..735f29f81162 100644 --- a/arch/s390/boot/uv.c +++ b/arch/s390/boot/uv.c @@ -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 diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index aeb0a15bcbb7..5a656c7b7a67 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -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); -- 2.25.1