From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: borntraeger@de.ibm.com, frankja@linux.ibm.com, thuth@redhat.com,
pasic@linux.ibm.com, david@redhat.com,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
scgl@linux.ibm.com, mimu@linux.ibm.com, nrb@linux.ibm.com
Subject: [PATCH v9 18/18] KVM: s390: pv: support for Destroy fast UVC
Date: Wed, 30 Mar 2022 14:26:05 +0200 [thread overview]
Message-ID: <20220330122605.247613-19-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20220330122605.247613-1-imbrenda@linux.ibm.com>
Add support for the Destroy Secure Configuration Fast Ultravisor call,
and take advantage of it for asynchronous destroy.
When supported, the protected guest is destroyed immediately using the
new UVC, leaving only the memory to be cleaned up asynchronously.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/include/asm/uv.h | 10 +++++++
arch/s390/kvm/pv.c | 57 ++++++++++++++++++++++++++++++++------
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h
index 6b2b33f19abe..b48334565415 100644
--- a/arch/s390/include/asm/uv.h
+++ b/arch/s390/include/asm/uv.h
@@ -34,6 +34,7 @@
#define UVC_CMD_INIT_UV 0x000f
#define UVC_CMD_CREATE_SEC_CONF 0x0100
#define UVC_CMD_DESTROY_SEC_CONF 0x0101
+#define UVC_CMD_DESTROY_SEC_CONF_FAST 0x0102
#define UVC_CMD_CREATE_SEC_CPU 0x0120
#define UVC_CMD_DESTROY_SEC_CPU 0x0121
#define UVC_CMD_CONV_TO_SEC_STOR 0x0200
@@ -76,6 +77,7 @@ enum uv_cmds_inst {
BIT_UVC_CMD_UNSHARE_ALL = 20,
BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
+ BIT_UVC_CMD_DESTROY_SEC_CONF_FAST = 23,
};
enum uv_feat_ind {
@@ -210,6 +212,14 @@ struct uv_cb_nodata {
u64 reserved20[4];
} __packed __aligned(8);
+/* Destroy Configuration Fast */
+struct uv_cb_destroy_fast {
+ struct uv_cb_header header;
+ u64 reserved08[2];
+ u64 handle;
+ u64 reserved20[5];
+} __packed __aligned(8);
+
/* Set Shared Access */
struct uv_cb_share {
struct uv_cb_header header;
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index 5111f1fc64ab..4ecc5658fa9a 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -187,6 +187,9 @@ static int kvm_s390_pv_cleanup_deferred(struct kvm *kvm, struct deferred_priv *d
u16 rc, rrc;
int cc;
+ /* It used the destroy-fast UVC, nothing left to do here */
+ if (!deferred->handle)
+ return 0;
cc = uv_cmd_nodata(deferred->handle, UVC_CMD_DESTROY_SEC_CONF, &rc, &rrc);
KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY VM: rc %x rrc %x", rc, rrc);
WARN_ONCE(cc, "protvirt destroy vm failed rc %x rrc %x", rc, rrc);
@@ -291,6 +294,32 @@ static void kvm_s390_clear_2g(struct kvm *kvm)
srcu_read_unlock(&kvm->srcu, srcu_idx);
}
+static int kvm_s390_pv_deinit_vm_fast(struct kvm *kvm, u16 *rc, u16 *rrc)
+{
+ struct uv_cb_destroy_fast uvcb = {
+ .header.cmd = UVC_CMD_DESTROY_SEC_CONF_FAST,
+ .header.len = sizeof(uvcb),
+ .handle = kvm_s390_pv_get_handle(kvm),
+ };
+ int cc;
+
+ cc = uv_call_sched(0, (u64)&uvcb);
+ *rc = uvcb.header.rc;
+ *rrc = uvcb.header.rrc;
+ WRITE_ONCE(kvm->arch.gmap->guest_handle, 0);
+ KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY VM FAST: rc %x rrc %x", *rc, *rrc);
+ WARN_ONCE(cc, "protvirt destroy vm fast failed rc %x rrc %x", *rc, *rrc);
+ /* Inteded memory leak on "impossible" error */
+ if (!cc)
+ kvm_s390_pv_dealloc_vm(kvm);
+ return cc ? -EIO : 0;
+}
+
+static inline bool is_destroy_fast_available(void)
+{
+ return test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CONF_FAST, uv_info.inst_calls_list);
+}
+
/**
* kvm_s390_pv_deinit_vm_async_prepare - Prepare a protected VM for
* asynchronous teardown.
@@ -312,6 +341,7 @@ static void kvm_s390_clear_2g(struct kvm *kvm)
int kvm_s390_pv_deinit_vm_async_prepare(struct kvm *kvm, u16 *rc, u16 *rrc)
{
struct deferred_priv *priv;
+ int res;
/*
* If an asynchronous deinitialization is already pending, refuse.
@@ -323,14 +353,20 @@ int kvm_s390_pv_deinit_vm_async_prepare(struct kvm *kvm, u16 *rc, u16 *rrc)
if (!priv)
return -ENOMEM;
- priv->stor_var = kvm->arch.pv.stor_var;
- priv->stor_base = kvm->arch.pv.stor_base;
- priv->handle = kvm_s390_pv_get_handle(kvm);
- priv->old_table = (unsigned long)kvm->arch.gmap->table;
- WRITE_ONCE(kvm->arch.gmap->guest_handle, 0);
- if (s390_replace_asce(kvm->arch.gmap)) {
- kfree(priv);
- return -ENOMEM;
+ if (is_destroy_fast_available()) {
+ res = kvm_s390_pv_deinit_vm_fast(kvm, rc, rrc);
+ if (res)
+ return res;
+ } else {
+ priv->stor_var = kvm->arch.pv.stor_var;
+ priv->stor_base = kvm->arch.pv.stor_base;
+ priv->handle = kvm_s390_pv_get_handle(kvm);
+ priv->old_table = (unsigned long)kvm->arch.gmap->table;
+ WRITE_ONCE(kvm->arch.gmap->guest_handle, 0);
+ if (s390_replace_asce(kvm->arch.gmap)) {
+ kfree(priv);
+ return -ENOMEM;
+ }
}
kvm_s390_clear_2g(kvm);
@@ -393,6 +429,7 @@ static void kvm_s390_pv_mmu_notifier_release(struct mmu_notifier *subscription,
{
struct kvm *kvm = container_of(subscription, struct kvm, arch.pv.mmu_notifier);
u16 dummy;
+ int r;
/*
* No locking is needed since this is the last thread of the last user of this
@@ -401,7 +438,9 @@ static void kvm_s390_pv_mmu_notifier_release(struct mmu_notifier *subscription,
* unregistered. This means that if this notifier runs, then the
* struct kvm is still valid.
*/
- kvm_s390_cpus_from_pv(kvm, &dummy, &dummy);
+ r = kvm_s390_cpus_from_pv(kvm, &dummy, &dummy);
+ if (!r)
+ kvm_s390_pv_deinit_vm_fast(kvm, &dummy, &dummy);
}
static const struct mmu_notifier_ops kvm_s390_pv_mmu_notifier_ops = {
--
2.34.1
prev parent reply other threads:[~2022-03-30 12:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 12:25 [PATCH v9 00/18] KVM: s390: pv: implement lazy destroy for reboot Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 01/18] KVM: s390: pv: leak the topmost page table when destroy fails Claudio Imbrenda
2022-03-31 13:13 ` Janosch Frank
2022-04-01 14:20 ` Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 02/18] KVM: s390: pv: handle secure storage violations for protected guests Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 03/18] KVM: s390: pv: handle secure storage exceptions for normal guests Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 04/18] KVM: s390: pv: refactor s390_reset_acc Claudio Imbrenda
2022-03-31 13:25 ` Janosch Frank
2022-04-01 14:25 ` Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 05/18] KVM: s390: pv: usage counter instead of flag Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 06/18] KVM: s390: pv: add export before import Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 07/18] KVM: s390: pv: module parameter to fence lazy destroy Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 08/18] KVM: s390: pv: clear the state without memset Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 09/18] KVM: s390: pv: Add kvm_s390_cpus_from_pv to kvm-s390.h and add documentation Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 10/18] KVM: s390: pv: add mmu_notifier Claudio Imbrenda
2022-03-31 13:29 ` Janosch Frank
2022-03-30 12:25 ` [PATCH v9 11/18] s390/mm: KVM: pv: when tearing down, try to destroy protected pages Claudio Imbrenda
2022-03-31 13:34 ` Janosch Frank
2022-04-01 15:03 ` Claudio Imbrenda
2022-03-30 12:25 ` [PATCH v9 12/18] KVM: s390: pv: refactoring of kvm_s390_pv_deinit_vm Claudio Imbrenda
2022-03-30 12:26 ` [PATCH v9 13/18] KVM: s390: pv: cleanup leftover protected VMs if needed Claudio Imbrenda
2022-03-31 14:02 ` Janosch Frank
2022-04-01 15:13 ` Claudio Imbrenda
2022-03-30 12:26 ` [PATCH v9 14/18] KVM: s390: pv: asynchronous destroy for reboot Claudio Imbrenda
2022-03-30 12:26 ` [PATCH v9 15/18] KVM: s390: pv: api documentation for asynchronous destroy Claudio Imbrenda
2022-03-30 12:26 ` [PATCH v9 16/18] KVM: s390: pv: add KVM_CAP_S390_PROTECTED_ASYNC_DISABLE Claudio Imbrenda
2022-03-30 12:26 ` [PATCH v9 17/18] KVM: s390: pv: avoid export before import if possible Claudio Imbrenda
2022-03-30 12:26 ` Claudio Imbrenda [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220330122605.247613-19-imbrenda@linux.ibm.com \
--to=imbrenda@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mimu@linux.ibm.com \
--cc=nrb@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=scgl@linux.ibm.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox