* [PATCH v3 0/5] s390: Enable AP instructions for pv-guests
@ 2023-08-18 11:15 Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 1/5] s390x/ap: fix missing subsystem reset registration Steffen Eiden
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
This series enables general QEMU support for AP pass-through for Secure
Execution guests (pv-guests).
To enable AP-PT on pv-guests QEMU has to turn on the corresponding bits
in the KVM CPU-model[1] if the CPU firmware supports it. However, it
only makes sense to turn on AP-PT if the QEMU user enabled (general) AP
for that guest.
See: https://lore.kernel.org/linux-s390/c29750cc-fc64-2805-f583-c7be247de02e@linux.ibm.com/T/#t
The series consists of five patches:
1/2) fixes from Janosch for AP handling
3) update kvm-s390 header for this series (NOTFORMERGE)
4) small cleanup for kvm_s390_set_attr()
refactor code to add ap_available() and ap_enabled()
5) Add UV_CALL CPU model enablement
since v2:
- add fixes for AP from Janosch
- rename *UV_CALL* to UV_FEAT_GUEST (Janosch)
- early return on some functions (Janosch)
- add r-p from Michael (Patch 4)
- mark linux header update as NOTFORMERGE
since v1:
- removed the new features from the default gen16 model
- updated KVM-headers to match KVM series v3 [1]
- applied review comments from Thomas
Janosch Frank (2):
s390x/ap: fix missing subsystem reset registration
s390x: switch pv and subsystem reset ordering on reboot
Steffen Eiden (3):
NOTFORMERGE update linux-headers/asm-s390/kvm.h
target/s390x/kvm: Refactor AP functionalities
target/s390x: AP-passthrough for PV guests
hw/s390x/s390-virtio-ccw.c | 7 ++-
linux-headers/asm-s390/kvm.h | 16 +++++
target/s390x/cpu_features.h | 1 +
target/s390x/cpu_features_def.h.inc | 4 ++
target/s390x/cpu_models.c | 2 +
target/s390x/gen-features.c | 2 +
target/s390x/kvm/kvm.c | 95 ++++++++++++++++++++++++++---
7 files changed, 117 insertions(+), 10 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/5] s390x/ap: fix missing subsystem reset registration
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
@ 2023-08-18 11:15 ` Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 2/5] s390x: switch pv and subsystem reset ordering on reboot Steffen Eiden
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
From: Janosch Frank <frankja@linux.ibm.com>
A subsystem reset contains a reset of AP resources which has been
missing. Adding the AP bridge to the list of device types that need
reset fixes this issue.
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Fixes: a51b3153 ("s390x/ap: base Adjunct Processor (AP) object model")
---
hw/s390x/s390-virtio-ccw.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 4516d73ff5..4b36c9970e 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -109,6 +109,7 @@ static const char *const reset_dev_types[] = {
"s390-flic",
"diag288",
TYPE_S390_PCI_HOST_BRIDGE,
+ TYPE_AP_BRIDGE,
};
static void subsystem_reset(void)
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/5] s390x: switch pv and subsystem reset ordering on reboot
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 1/5] s390x/ap: fix missing subsystem reset registration Steffen Eiden
@ 2023-08-18 11:15 ` Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 3/5] NOTFORMERGE update linux-headers/asm-s390/kvm.h Steffen Eiden
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
From: Janosch Frank <frankja@linux.ibm.com>
Bound APQNs have to be reset before tearing down the secure config via
s390_machine_unprotect(). Otherwise the Ultravisor will return a error
code.
So let's switch the ordering around to make that happen.
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
hw/s390x/s390-virtio-ccw.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 4b36c9970e..795dd53d68 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -442,13 +442,13 @@ static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
switch (reset_type) {
case S390_RESET_EXTERNAL:
case S390_RESET_REIPL:
+ qemu_devices_reset(reason);
+ s390_crypto_reset();
+
if (s390_is_pv()) {
s390_machine_unprotect(ms);
}
- qemu_devices_reset(reason);
- s390_crypto_reset();
-
/* configure and start the ipl CPU only */
run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
break;
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 3/5] NOTFORMERGE update linux-headers/asm-s390/kvm.h
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 1/5] s390x/ap: fix missing subsystem reset registration Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 2/5] s390x: switch pv and subsystem reset ordering on reboot Steffen Eiden
@ 2023-08-18 11:15 ` Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests Steffen Eiden
4 siblings, 0 replies; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
Likely to be included in Linux 6.{6,7}
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
| 16 ++++++++++++++++
1 file changed, 16 insertions(+)
--git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index e2afd95420..023a2763a9 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -159,6 +159,22 @@ struct kvm_s390_vm_cpu_subfunc {
__u8 reserved[1728];
};
+#define KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST 6
+#define KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST 7
+
+#define KVM_S390_VM_CPU_UV_FEAT_NR_BITS 64
+struct kvm_s390_vm_cpu_uv_feat {
+ union {
+ struct {
+ __u64 : 4;
+ __u64 ap : 1; /* bit 4 */
+ __u64 ap_intr : 1; /* bit 5 */
+ __u64 : 58;
+ };
+ __u64 feat;
+ };
+};
+
/* kvm attributes for crypto */
#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0
#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
` (2 preceding siblings ...)
2023-08-18 11:15 ` [PATCH v3 3/5] NOTFORMERGE update linux-headers/asm-s390/kvm.h Steffen Eiden
@ 2023-08-18 11:15 ` Steffen Eiden
2023-08-21 7:57 ` Thomas Huth
2023-08-18 11:15 ` [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests Steffen Eiden
4 siblings, 1 reply; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
kvm_s390_set_attr() is a misleading name as it only sets attributes for
the KVM_S390_VM_CRYPTO group. Therefore, rename it to
kvm_s390_set_crypto_attr().
Add new functions ap_available() and ap_enabled() to avoid code
duplication later.
Reviewed-by: Michael Mueller <mimu@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
target/s390x/kvm/kvm.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
index a9e5880349..a7e2cdf668 100644
--- a/target/s390x/kvm/kvm.c
+++ b/target/s390x/kvm/kvm.c
@@ -250,7 +250,7 @@ static void kvm_s390_enable_cmma(void)
trace_kvm_enable_cmma(rc);
}
-static void kvm_s390_set_attr(uint64_t attr)
+static void kvm_s390_set_crypto_attr(uint64_t attr)
{
struct kvm_device_attr attribute = {
.group = KVM_S390_VM_CRYPTO,
@@ -275,7 +275,7 @@ static void kvm_s390_init_aes_kw(void)
}
if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
- kvm_s390_set_attr(attr);
+ kvm_s390_set_crypto_attr(attr);
}
}
@@ -289,7 +289,7 @@ static void kvm_s390_init_dea_kw(void)
}
if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
- kvm_s390_set_attr(attr);
+ kvm_s390_set_crypto_attr(attr);
}
}
@@ -2296,6 +2296,17 @@ static int configure_cpu_subfunc(const S390FeatBitmap features)
return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
}
+static bool ap_available(void)
+{
+ return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+ KVM_S390_VM_CRYPTO_ENABLE_APIE);
+}
+
+static bool ap_enabled(const S390FeatBitmap features)
+{
+ return test_bit(S390_FEAT_AP, features);
+}
+
static int kvm_to_feat[][2] = {
{ KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
{ KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
@@ -2475,8 +2486,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
return;
}
/* for now, we can only provide the AP feature with HW support */
- if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
- KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+ if (ap_available()) {
set_bit(S390_FEAT_AP, model->features);
}
@@ -2502,7 +2512,7 @@ static void kvm_s390_configure_apie(bool interpret)
KVM_S390_VM_CRYPTO_DISABLE_APIE;
if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
- kvm_s390_set_attr(attr);
+ kvm_s390_set_crypto_attr(attr);
}
}
@@ -2556,7 +2566,7 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
kvm_s390_enable_cmma();
}
- if (test_bit(S390_FEAT_AP, model->features)) {
+ if (ap_enabled(model->features)) {
kvm_s390_configure_apie(true);
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
` (3 preceding siblings ...)
2023-08-18 11:15 ` [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities Steffen Eiden
@ 2023-08-18 11:15 ` Steffen Eiden
2023-08-21 8:31 ` Thomas Huth
2023-08-23 8:55 ` Michael Mueller
4 siblings, 2 replies; 9+ messages in thread
From: Steffen Eiden @ 2023-08-18 11:15 UTC (permalink / raw)
To: qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
Enabling AP-passthrough(AP-pt) for PV-guest by using the new CPU
features for PV-AP-pt of KVM.
As usual QEMU first checks which CPU features are available and then
sets them if available and selected by user. An additional check is done
to verify that PV-AP can only be enabled if "regular" AP-pt is enabled
as well. Note that KVM itself does not enforce this restriction.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
target/s390x/cpu_features.h | 1 +
target/s390x/cpu_features_def.h.inc | 4 ++
target/s390x/cpu_models.c | 2 +
target/s390x/gen-features.c | 2 +
target/s390x/kvm/kvm.c | 71 +++++++++++++++++++++++++++++
5 files changed, 80 insertions(+)
diff --git a/target/s390x/cpu_features.h b/target/s390x/cpu_features.h
index 87463f064d..a9bd68a2e1 100644
--- a/target/s390x/cpu_features.h
+++ b/target/s390x/cpu_features.h
@@ -43,6 +43,7 @@ typedef enum {
S390_FEAT_TYPE_KDSA,
S390_FEAT_TYPE_SORTL,
S390_FEAT_TYPE_DFLTCC,
+ S390_FEAT_TYPE_UV_FEAT_GUEST,
} S390FeatType;
/* Definition of a CPU feature */
diff --git a/target/s390x/cpu_features_def.h.inc b/target/s390x/cpu_features_def.h.inc
index e3cfe63735..e68da9b8ff 100644
--- a/target/s390x/cpu_features_def.h.inc
+++ b/target/s390x/cpu_features_def.h.inc
@@ -379,3 +379,7 @@ DEF_FEAT(DEFLATE_GHDT, "dfltcc-gdht", DFLTCC, 1, "DFLTCC GDHT")
DEF_FEAT(DEFLATE_CMPR, "dfltcc-cmpr", DFLTCC, 2, "DFLTCC CMPR")
DEF_FEAT(DEFLATE_XPND, "dfltcc-xpnd", DFLTCC, 4, "DFLTCC XPND")
DEF_FEAT(DEFLATE_F0, "dfltcc-f0", DFLTCC, 192, "DFLTCC format 0 parameter-block")
+
+/* Features exposed via the UV-CALL instruction */
+DEF_FEAT(UV_FEAT_AP, "appv", UV_FEAT_GUEST, 4, "AP instructions installed for secure guests")
+DEF_FEAT(UV_FEAT_AP_INTR, "appvi", UV_FEAT_GUEST, 5, "AP instructions interruption support for secure guests")
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 42b52afdb4..65331c37a3 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -483,6 +483,8 @@ static void check_consistency(const S390CPUModel *model)
{ S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB },
{ S390_FEAT_NNPA, S390_FEAT_VECTOR },
{ S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING },
+ { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
+ { S390_FEAT_UV_FEAT_AP_INTR, S390_FEAT_UV_FEAT_AP },
};
int i;
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 1e3b7c0dc9..2b2bfc3736 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -576,6 +576,8 @@ static uint16_t full_GEN16_GA1[] = {
S390_FEAT_RDP,
S390_FEAT_PAI,
S390_FEAT_PAIE,
+ S390_FEAT_UV_FEAT_AP,
+ S390_FEAT_UV_FEAT_AP_INTR,
};
diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
index a7e2cdf668..937387a768 100644
--- a/target/s390x/kvm/kvm.c
+++ b/target/s390x/kvm/kvm.c
@@ -2307,6 +2307,42 @@ static bool ap_enabled(const S390FeatBitmap features)
return test_bit(S390_FEAT_AP, features);
}
+static bool uv_feat_supported(void)
+{
+ return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+ KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST);
+}
+
+static int query_uv_feat_guest(S390FeatBitmap features)
+{
+ struct kvm_s390_vm_cpu_uv_feat prop = {};
+ struct kvm_device_attr attr = {
+ .group = KVM_S390_VM_CPU_MODEL,
+ .attr = KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST,
+ .addr = (uint64_t) &prop,
+ };
+ int rc;
+
+ // AP support check is currently the only user of the UV feature test.
+ if (!(uv_feat_supported() && ap_available())) {
+ return 0;
+ }
+
+ rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+ if (rc) {
+ return rc;
+ }
+
+ if (prop.ap) {
+ set_bit(S390_FEAT_UV_FEAT_AP, features);
+ }
+ if (prop.ap_intr) {
+ set_bit(S390_FEAT_UV_FEAT_AP_INTR, features);
+ }
+
+ return 0;
+}
+
static int kvm_to_feat[][2] = {
{ KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
{ KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
@@ -2501,11 +2537,39 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
set_bit(S390_FEAT_DIAG_318, model->features);
}
+ /* Test for Ultravisor features that influence secure guest behavior */
+ query_uv_feat_guest(model->features);
+
/* strip of features that are not part of the maximum model */
bitmap_and(model->features, model->features, model->def->full_feat,
S390_FEAT_MAX);
}
+static int configure_uv_feat_guest(const S390FeatBitmap features)
+{
+
+ struct kvm_s390_vm_cpu_uv_feat uv_feat = {};
+ struct kvm_device_attr attribute = {
+ .group = KVM_S390_VM_CPU_MODEL,
+ .attr = KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST,
+ .addr = (__u64) &uv_feat,
+ };
+
+ // AP support check is currently the only user of the UV feature test.
+ if (!(uv_feat_supported() && ap_enabled(features))) {
+ return 0;
+ }
+
+ if (test_bit(S390_FEAT_UV_FEAT_AP, features)) {
+ uv_feat.ap = 1;
+ }
+ if (test_bit(S390_FEAT_UV_FEAT_AP_INTR, features)) {
+ uv_feat.ap_intr = 1;
+ }
+
+ return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attribute);
+}
+
static void kvm_s390_configure_apie(bool interpret)
{
uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
@@ -2569,6 +2633,13 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
if (ap_enabled(model->features)) {
kvm_s390_configure_apie(true);
}
+
+ /* configure UV-features for the guest indicated via query / test_bit */
+ rc = configure_uv_feat_guest(model->features);
+ if (rc) {
+ error_setg(errp, "KVM: Error configuring CPU UV features %d", rc);
+ return;
+ }
}
void kvm_s390_restart_interrupt(S390CPU *cpu)
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities
2023-08-18 11:15 ` [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities Steffen Eiden
@ 2023-08-21 7:57 ` Thomas Huth
0 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2023-08-21 7:57 UTC (permalink / raw)
To: Steffen Eiden, qemu-s390x, qemu-devel
Cc: Janosch Frank, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
On 18/08/2023 13.15, Steffen Eiden wrote:
> kvm_s390_set_attr() is a misleading name as it only sets attributes for
> the KVM_S390_VM_CRYPTO group. Therefore, rename it to
> kvm_s390_set_crypto_attr().
>
> Add new functions ap_available() and ap_enabled() to avoid code
> duplication later.
>
> Reviewed-by: Michael Mueller <mimu@linux.ibm.com>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> target/s390x/kvm/kvm.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests
2023-08-18 11:15 ` [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests Steffen Eiden
@ 2023-08-21 8:31 ` Thomas Huth
2023-08-23 8:55 ` Michael Mueller
1 sibling, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2023-08-21 8:31 UTC (permalink / raw)
To: Steffen Eiden, qemu-s390x, qemu-devel
Cc: Janosch Frank, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
On 18/08/2023 13.15, Steffen Eiden wrote:
> Enabling AP-passthrough(AP-pt) for PV-guest by using the new CPU
> features for PV-AP-pt of KVM.
>
> As usual QEMU first checks which CPU features are available and then
> sets them if available and selected by user. An additional check is done
> to verify that PV-AP can only be enabled if "regular" AP-pt is enabled
> as well. Note that KVM itself does not enforce this restriction.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
...
> diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
> index a7e2cdf668..937387a768 100644
> --- a/target/s390x/kvm/kvm.c
> +++ b/target/s390x/kvm/kvm.c
> @@ -2307,6 +2307,42 @@ static bool ap_enabled(const S390FeatBitmap features)
> return test_bit(S390_FEAT_AP, features);
> }
>
> +static bool uv_feat_supported(void)
> +{
> + return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
> + KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST);
> +}
> +
> +static int query_uv_feat_guest(S390FeatBitmap features)
> +{
> + struct kvm_s390_vm_cpu_uv_feat prop = {};
> + struct kvm_device_attr attr = {
> + .group = KVM_S390_VM_CPU_MODEL,
> + .attr = KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST,
> + .addr = (uint64_t) &prop,
> + };
> + int rc;
> +
> + // AP support check is currently the only user of the UV feature test.
Cosmetical nit: QEMU coding style mandates /* ... */ comments
> + if (!(uv_feat_supported() && ap_available())) {
> + return 0;
> + }
> +
> + rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
> + if (rc) {
> + return rc;
> + }
> +
> + if (prop.ap) {
> + set_bit(S390_FEAT_UV_FEAT_AP, features);
> + }
> + if (prop.ap_intr) {
> + set_bit(S390_FEAT_UV_FEAT_AP_INTR, features);
> + }
> +
> + return 0;
> +}
> +
> static int kvm_to_feat[][2] = {
> { KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
> { KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
> @@ -2501,11 +2537,39 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
> set_bit(S390_FEAT_DIAG_318, model->features);
> }
>
> + /* Test for Ultravisor features that influence secure guest behavior */
> + query_uv_feat_guest(model->features);
> +
> /* strip of features that are not part of the maximum model */
> bitmap_and(model->features, model->features, model->def->full_feat,
> S390_FEAT_MAX);
> }
>
> +static int configure_uv_feat_guest(const S390FeatBitmap features)
> +{
> +
Nit: Please remove the empty line.
> + struct kvm_s390_vm_cpu_uv_feat uv_feat = {};
> + struct kvm_device_attr attribute = {
> + .group = KVM_S390_VM_CPU_MODEL,
> + .attr = KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST,
> + .addr = (__u64) &uv_feat,
> + };
> +
> + // AP support check is currently the only user of the UV feature test.
Nit: /* ... */ comment, please
> + if (!(uv_feat_supported() && ap_enabled(features))) {
> + return 0;
> + }
> +
> + if (test_bit(S390_FEAT_UV_FEAT_AP, features)) {
> + uv_feat.ap = 1;
> + }
> + if (test_bit(S390_FEAT_UV_FEAT_AP_INTR, features)) {
> + uv_feat.ap_intr = 1;
> + }
> +
> + return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attribute);
> +}
> +
> static void kvm_s390_configure_apie(bool interpret)
> {
> uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
> @@ -2569,6 +2633,13 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
> if (ap_enabled(model->features)) {
> kvm_s390_configure_apie(true);
> }
> +
> + /* configure UV-features for the guest indicated via query / test_bit */
> + rc = configure_uv_feat_guest(model->features);
> + if (rc) {
> + error_setg(errp, "KVM: Error configuring CPU UV features %d", rc);
> + return;
> + }
> }
>
> void kvm_s390_restart_interrupt(S390CPU *cpu)
With the nits fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests
2023-08-18 11:15 ` [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests Steffen Eiden
2023-08-21 8:31 ` Thomas Huth
@ 2023-08-23 8:55 ` Michael Mueller
1 sibling, 0 replies; 9+ messages in thread
From: Michael Mueller @ 2023-08-23 8:55 UTC (permalink / raw)
To: Steffen Eiden, qemu-s390x, qemu-devel
Cc: Janosch Frank, Thomas Huth, David Hildenbrand, Michael Mueller,
Marc Hartmayer, Christian Borntraeger
On 18.08.23 13:15, Steffen Eiden wrote:
> Enabling AP-passthrough(AP-pt) for PV-guest by using the new CPU
> features for PV-AP-pt of KVM.
>
> As usual QEMU first checks which CPU features are available and then
> sets them if available and selected by user. An additional check is done
> to verify that PV-AP can only be enabled if "regular" AP-pt is enabled
> as well. Note that KVM itself does not enforce this restriction.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Michael Mueller <sMIMU@linux.ibm.com>
with the findings from Thomas H. integrated
> ---
> target/s390x/cpu_features.h | 1 +
> target/s390x/cpu_features_def.h.inc | 4 ++
> target/s390x/cpu_models.c | 2 +
> target/s390x/gen-features.c | 2 +
> target/s390x/kvm/kvm.c | 71 +++++++++++++++++++++++++++++
> 5 files changed, 80 insertions(+)
>
> diff --git a/target/s390x/cpu_features.h b/target/s390x/cpu_features.h
> index 87463f064d..a9bd68a2e1 100644
> --- a/target/s390x/cpu_features.h
> +++ b/target/s390x/cpu_features.h
> @@ -43,6 +43,7 @@ typedef enum {
> S390_FEAT_TYPE_KDSA,
> S390_FEAT_TYPE_SORTL,
> S390_FEAT_TYPE_DFLTCC,
> + S390_FEAT_TYPE_UV_FEAT_GUEST,
> } S390FeatType;
>
> /* Definition of a CPU feature */
> diff --git a/target/s390x/cpu_features_def.h.inc b/target/s390x/cpu_features_def.h.inc
> index e3cfe63735..e68da9b8ff 100644
> --- a/target/s390x/cpu_features_def.h.inc
> +++ b/target/s390x/cpu_features_def.h.inc
> @@ -379,3 +379,7 @@ DEF_FEAT(DEFLATE_GHDT, "dfltcc-gdht", DFLTCC, 1, "DFLTCC GDHT")
> DEF_FEAT(DEFLATE_CMPR, "dfltcc-cmpr", DFLTCC, 2, "DFLTCC CMPR")
> DEF_FEAT(DEFLATE_XPND, "dfltcc-xpnd", DFLTCC, 4, "DFLTCC XPND")
> DEF_FEAT(DEFLATE_F0, "dfltcc-f0", DFLTCC, 192, "DFLTCC format 0 parameter-block")
> +
> +/* Features exposed via the UV-CALL instruction */
> +DEF_FEAT(UV_FEAT_AP, "appv", UV_FEAT_GUEST, 4, "AP instructions installed for secure guests")
> +DEF_FEAT(UV_FEAT_AP_INTR, "appvi", UV_FEAT_GUEST, 5, "AP instructions interruption support for secure guests")
> diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
> index 42b52afdb4..65331c37a3 100644
> --- a/target/s390x/cpu_models.c
> +++ b/target/s390x/cpu_models.c
> @@ -483,6 +483,8 @@ static void check_consistency(const S390CPUModel *model)
> { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB },
> { S390_FEAT_NNPA, S390_FEAT_VECTOR },
> { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING },
> + { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
> + { S390_FEAT_UV_FEAT_AP_INTR, S390_FEAT_UV_FEAT_AP },
> };
> int i;
>
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index 1e3b7c0dc9..2b2bfc3736 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -576,6 +576,8 @@ static uint16_t full_GEN16_GA1[] = {
> S390_FEAT_RDP,
> S390_FEAT_PAI,
> S390_FEAT_PAIE,
> + S390_FEAT_UV_FEAT_AP,
> + S390_FEAT_UV_FEAT_AP_INTR,
> };
>
>
> diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
> index a7e2cdf668..937387a768 100644
> --- a/target/s390x/kvm/kvm.c
> +++ b/target/s390x/kvm/kvm.c
> @@ -2307,6 +2307,42 @@ static bool ap_enabled(const S390FeatBitmap features)
> return test_bit(S390_FEAT_AP, features);
> }
>
> +static bool uv_feat_supported(void)
> +{
> + return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
> + KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST);
> +}
> +
> +static int query_uv_feat_guest(S390FeatBitmap features)
> +{
> + struct kvm_s390_vm_cpu_uv_feat prop = {};
> + struct kvm_device_attr attr = {
> + .group = KVM_S390_VM_CPU_MODEL,
> + .attr = KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST,
> + .addr = (uint64_t) &prop,
> + };
> + int rc;
> +
> + // AP support check is currently the only user of the UV feature test.
> + if (!(uv_feat_supported() && ap_available())) {
> + return 0;
> + }
> +
> + rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
> + if (rc) {
> + return rc;
> + }
> +
> + if (prop.ap) {
> + set_bit(S390_FEAT_UV_FEAT_AP, features);
> + }
> + if (prop.ap_intr) {
> + set_bit(S390_FEAT_UV_FEAT_AP_INTR, features);
> + }
> +
> + return 0;
> +}
> +
> static int kvm_to_feat[][2] = {
> { KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
> { KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
> @@ -2501,11 +2537,39 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
> set_bit(S390_FEAT_DIAG_318, model->features);
> }
>
> + /* Test for Ultravisor features that influence secure guest behavior */
> + query_uv_feat_guest(model->features);
> +
> /* strip of features that are not part of the maximum model */
> bitmap_and(model->features, model->features, model->def->full_feat,
> S390_FEAT_MAX);
> }
>
> +static int configure_uv_feat_guest(const S390FeatBitmap features)
> +{
> +
> + struct kvm_s390_vm_cpu_uv_feat uv_feat = {};
> + struct kvm_device_attr attribute = {
> + .group = KVM_S390_VM_CPU_MODEL,
> + .attr = KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST,
> + .addr = (__u64) &uv_feat,
> + };
> +
> + // AP support check is currently the only user of the UV feature test.
> + if (!(uv_feat_supported() && ap_enabled(features))) {
> + return 0;
> + }
> +
> + if (test_bit(S390_FEAT_UV_FEAT_AP, features)) {
> + uv_feat.ap = 1;
> + }
> + if (test_bit(S390_FEAT_UV_FEAT_AP_INTR, features)) {
> + uv_feat.ap_intr = 1;
> + }
> +
> + return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attribute);
> +}
> +
> static void kvm_s390_configure_apie(bool interpret)
> {
> uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
> @@ -2569,6 +2633,13 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
> if (ap_enabled(model->features)) {
> kvm_s390_configure_apie(true);
> }
> +
> + /* configure UV-features for the guest indicated via query / test_bit */
> + rc = configure_uv_feat_guest(model->features);
> + if (rc) {
> + error_setg(errp, "KVM: Error configuring CPU UV features %d", rc);
> + return;
> + }
> }
>
> void kvm_s390_restart_interrupt(S390CPU *cpu)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-08-23 8:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18 11:15 [PATCH v3 0/5] s390: Enable AP instructions for pv-guests Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 1/5] s390x/ap: fix missing subsystem reset registration Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 2/5] s390x: switch pv and subsystem reset ordering on reboot Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 3/5] NOTFORMERGE update linux-headers/asm-s390/kvm.h Steffen Eiden
2023-08-18 11:15 ` [PATCH v3 4/5] target/s390x/kvm: Refactor AP functionalities Steffen Eiden
2023-08-21 7:57 ` Thomas Huth
2023-08-18 11:15 ` [PATCH v3 5/5] target/s390x: AP-passthrough for PV guests Steffen Eiden
2023-08-21 8:31 ` Thomas Huth
2023-08-23 8:55 ` Michael Mueller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.