Skip to content

Commit ecdc5d8

Browse files
Vasily GorbikChristian Borntraeger
authored andcommitted
s390/protvirt: introduce host side setup
Add "prot_virt" command line option which controls if the kernel protected VMs support is enabled at early boot time. This has to be done early, because it needs large amounts of memory and will disable some features like STP time sync for the lpar. Extend ultravisor info definitions and expose it via uv_info struct filled in during startup. Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> [borntraeger@de.ibm.com: patch merging, splitting, fixing] Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent 11a48a5 commit ecdc5d8

7 files changed

Lines changed: 122 additions & 7 deletions

File tree

‎Documentation/admin-guide/kernel-parameters.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,6 +3795,11 @@
37953795
before loading.
37963796
See Documentation/admin-guide/blockdev/ramdisk.rst.
37973797

3798+
prot_virt= [S390] enable hosting protected virtual machines
3799+
isolated from the hypervisor (if hardware supports
3800+
that).
3801+
Format: <bool>
3802+
37983803
psi= [KNL] Enable or disable pressure stall information
37993804
tracking.
38003805
Format: <bool>

‎arch/s390/boot/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
3737
obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o
3838
obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
3939
obj-y += version.o pgm_check_info.o ctype.o text_dma.o
40-
obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o
40+
obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o
4141
obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o
4242
obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
4343
targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)

‎arch/s390/boot/uv.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
#include <asm/facility.h>
44
#include <asm/sections.h>
55

6+
/* will be used in arch/s390/kernel/uv.c */
7+
#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
68
int __bootdata_preserved(prot_virt_guest);
9+
#endif
10+
#if IS_ENABLED(CONFIG_KVM)
11+
struct uv_info __bootdata_preserved(uv_info);
12+
#endif
713

814
void uv_query_info(void)
915
{
@@ -19,7 +25,21 @@ void uv_query_info(void)
1925
if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != 0x100)
2026
return;
2127

28+
if (IS_ENABLED(CONFIG_KVM)) {
29+
memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
30+
uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
31+
uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
32+
uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len;
33+
uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len;
34+
uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
35+
uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
36+
uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
37+
uv_info.max_guest_cpus = uvcb.max_guest_cpus;
38+
}
39+
40+
#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
2241
if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list) &&
2342
test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list))
2443
prot_virt_guest = 1;
44+
#endif
2545
}

‎arch/s390/include/asm/uv.h‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ struct uv_cb_qui {
4444
struct uv_cb_header header;
4545
u64 reserved08;
4646
u64 inst_calls_list[4];
47-
u64 reserved30[15];
47+
u64 reserved30[2];
48+
u64 uv_base_stor_len;
49+
u64 reserved48;
50+
u64 conf_base_phys_stor_len;
51+
u64 conf_base_virt_stor_len;
52+
u64 conf_virt_var_stor_len;
53+
u64 cpu_stor_len;
54+
u32 reserved70[3];
55+
u32 max_num_sec_conf;
56+
u64 max_guest_stor_addr;
57+
u8 reserved88[158 - 136];
58+
u16 max_guest_cpus;
59+
u8 reserveda0[200 - 160];
4860
} __packed __aligned(8);
4961

5062
struct uv_cb_share {
@@ -69,6 +81,20 @@ static inline int uv_call(unsigned long r1, unsigned long r2)
6981
return cc;
7082
}
7183

84+
struct uv_info {
85+
unsigned long inst_calls_list[4];
86+
unsigned long uv_base_stor_len;
87+
unsigned long guest_base_stor_len;
88+
unsigned long guest_virt_base_stor_len;
89+
unsigned long guest_virt_var_stor_len;
90+
unsigned long guest_cpu_stor_len;
91+
unsigned long max_sec_stor_addr;
92+
unsigned int max_num_sec_conf;
93+
unsigned short max_guest_cpus;
94+
};
95+
96+
extern struct uv_info uv_info;
97+
7298
#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
7399
extern int prot_virt_guest;
74100

@@ -121,11 +147,26 @@ static inline int uv_remove_shared(unsigned long addr)
121147
return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
122148
}
123149

124-
void uv_query_info(void);
125150
#else
126151
#define is_prot_virt_guest() 0
127152
static inline int uv_set_shared(unsigned long addr) { return 0; }
128153
static inline int uv_remove_shared(unsigned long addr) { return 0; }
154+
#endif
155+
156+
#if IS_ENABLED(CONFIG_KVM)
157+
extern int prot_virt_host;
158+
159+
static inline int is_prot_virt_host(void)
160+
{
161+
return prot_virt_host;
162+
}
163+
#else
164+
#define is_prot_virt_host() 0
165+
#endif
166+
167+
#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || IS_ENABLED(CONFIG_KVM)
168+
void uv_query_info(void);
169+
#else
129170
static inline void uv_query_info(void) {}
130171
#endif
131172

‎arch/s390/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o
7878
obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_diag.o
7979

8080
obj-$(CONFIG_TRACEPOINTS) += trace.o
81+
obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o
8182

8283
# vdso
8384
obj-y += vdso64/

‎arch/s390/kernel/setup.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ char elf_platform[ELF_PLATFORM_SIZE];
9292

9393
unsigned long int_hwcap = 0;
9494

95-
#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
96-
int __bootdata_preserved(prot_virt_guest);
97-
#endif
98-
9995
int __bootdata(noexec_disabled);
10096
int __bootdata(memory_end_set);
10197
unsigned long __bootdata(memory_end);

‎arch/s390/kernel/uv.c‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Common Ultravisor functions and initialization
4+
*
5+
* Copyright IBM Corp. 2019, 2020
6+
*/
7+
#define KMSG_COMPONENT "prot_virt"
8+
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9+
10+
#include <linux/kernel.h>
11+
#include <linux/types.h>
12+
#include <linux/sizes.h>
13+
#include <linux/bitmap.h>
14+
#include <linux/memblock.h>
15+
#include <asm/facility.h>
16+
#include <asm/sections.h>
17+
#include <asm/uv.h>
18+
19+
/* the bootdata_preserved fields come from ones in arch/s390/boot/uv.c */
20+
#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
21+
int __bootdata_preserved(prot_virt_guest);
22+
#endif
23+
24+
#if IS_ENABLED(CONFIG_KVM)
25+
int prot_virt_host;
26+
EXPORT_SYMBOL(prot_virt_host);
27+
struct uv_info __bootdata_preserved(uv_info);
28+
EXPORT_SYMBOL(uv_info);
29+
30+
static int __init prot_virt_setup(char *val)
31+
{
32+
bool enabled;
33+
int rc;
34+
35+
rc = kstrtobool(val, &enabled);
36+
if (!rc && enabled)
37+
prot_virt_host = 1;
38+
39+
if (is_prot_virt_guest() && prot_virt_host) {
40+
prot_virt_host = 0;
41+
pr_warn("Protected virtualization not available in protected guests.");
42+
}
43+
44+
if (prot_virt_host && !test_facility(158)) {
45+
prot_virt_host = 0;
46+
pr_warn("Protected virtualization not supported by the hardware.");
47+
}
48+
49+
return rc;
50+
}
51+
early_param("prot_virt", prot_virt_setup);
52+
#endif

0 commit comments

Comments
 (0)