[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/13] hw/s390x/s390-skeys: use memory mapping to detect which
From: |
David Hildenbrand |
Subject: |
[PATCH v2 09/13] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to migrate |
Date: |
Wed, 11 Aug 2021 11:05:23 +0200 |
Let's use the guest_phys_blocks API to get physical memory regions
that are well defined inside our physical address space and migrate the
storage keys of these.
This is a preparation for having memory besides initial ram defined in
the guest physical address space, for example, via memory devices. We
get rid of the ms->ram_size dependency.
Please note that we will usually have very little (--> 1) physical
ranges. With virtio-mem might have significantly more ranges in the
future. If that turns out to be a problem (e.g., total memory
footprint of the list), we could look into a memory mapping
API that avoids creation of a list and instead triggers a callback for
each range.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/s390x/s390-skeys.c | 70 ++++++++++++++++++++++++++-----------------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 9a8d60d1d9..250685a95a 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -17,6 +17,7 @@
#include "qapi/qapi-commands-misc-target.h"
#include "qapi/qmp/qdict.h"
#include "qemu/error-report.h"
+#include "sysemu/memory_mapping.h"
#include "sysemu/kvm.h"
#include "migration/qemu-file-types.h"
#include "migration/register.h"
@@ -257,10 +258,9 @@ static void s390_storage_keys_save(QEMUFile *f, void
*opaque)
{
S390SKeysState *ss = S390_SKEYS(opaque);
S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
- MachineState *ms = MACHINE(qdev_get_machine());
- uint64_t pages_left = ms->ram_size / TARGET_PAGE_SIZE;
- uint64_t read_count, eos = S390_SKEYS_SAVE_FLAG_EOS;
- vaddr cur_gfn = 0;
+ GuestPhysBlockList guest_phys_blocks;
+ GuestPhysBlock *block;
+ uint64_t pages, gfn;
int error = 0;
uint8_t *buf;
@@ -274,36 +274,52 @@ static void s390_storage_keys_save(QEMUFile *f, void
*opaque)
goto end_stream;
}
- /* We only support initial memory. Standby memory is not handled yet. */
- qemu_put_be64(f, (cur_gfn * TARGET_PAGE_SIZE) |
S390_SKEYS_SAVE_FLAG_SKEYS);
- qemu_put_be64(f, pages_left);
-
- while (pages_left) {
- read_count = MIN(pages_left, S390_SKEYS_BUFFER_SIZE);
-
- if (!error) {
- error = skeyclass->get_skeys(ss, cur_gfn, read_count, buf);
- if (error) {
- /*
- * If error: we want to fill the stream with valid data instead
- * of stopping early so we pad the stream with 0x00 values and
- * use S390_SKEYS_SAVE_FLAG_ERROR to indicate failure to the
- * reading side.
- */
- error_report("S390_GET_KEYS error %d", error);
- memset(buf, 0, S390_SKEYS_BUFFER_SIZE);
- eos = S390_SKEYS_SAVE_FLAG_ERROR;
+ guest_phys_blocks_init(&guest_phys_blocks);
+ guest_phys_blocks_append(&guest_phys_blocks);
+
+ /* Send each contiguous physical memory range separately. */
+ QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
+ assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE));
+ assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE));
+
+ gfn = block->target_start / TARGET_PAGE_SIZE;
+ pages = (block->target_end - block->target_start) / TARGET_PAGE_SIZE;
+ qemu_put_be64(f, block->target_start | S390_SKEYS_SAVE_FLAG_SKEYS);
+ qemu_put_be64(f, pages);
+
+ while (pages) {
+ const uint64_t cur_pages = MIN(pages, S390_SKEYS_BUFFER_SIZE);
+
+ if (!error) {
+ error = skeyclass->get_skeys(ss, gfn, cur_pages, buf);
+ if (error) {
+ /*
+ * Create a valid stream with all 0x00 and indicate
+ * S390_SKEYS_SAVE_FLAG_ERROR to the destination.
+ */
+ error_report("S390_GET_KEYS error %d", error);
+ memset(buf, 0, S390_SKEYS_BUFFER_SIZE);
+ }
}
+
+ qemu_put_buffer(f, buf, cur_pages);
+ gfn += cur_pages;
+ pages -= cur_pages;
}
- qemu_put_buffer(f, buf, read_count);
- cur_gfn += read_count;
- pages_left -= read_count;
+ if (error) {
+ break;
+ }
}
+ guest_phys_blocks_free(&guest_phys_blocks);
g_free(buf);
end_stream:
- qemu_put_be64(f, eos);
+ if (error) {
+ qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_ERROR);
+ } else {
+ qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_EOS);
+ }
}
static int s390_storage_keys_load(QEMUFile *f, void *opaque, int version_id)
--
2.31.1
- [PATCH v2 01/13] s390x/tcg: wrap address for RRBE, (continued)
- [PATCH v2 01/13] s390x/tcg: wrap address for RRBE, David Hildenbrand, 2021/08/11
- [PATCH v2 02/13] s390x/tcg: fix ignoring bit 63 when setting the storage key in SSKE, David Hildenbrand, 2021/08/11
- [PATCH v2 03/13] s390x/tcg: convert real to absolute address for RRBE, SSKE and ISKE, David Hildenbrand, 2021/08/11
- [PATCH v2 04/13] s390x/tcg: check for addressing exceptions for RRBE, SSKE and ISKE, David Hildenbrand, 2021/08/11
- [PATCH v2 05/13] s390x/mmu_helper: no need to pass access type to mmu_translate_asce(), David Hildenbrand, 2021/08/11
- [PATCH v2 06/13] s390x/mmu_helper: fixup mmu_translate() documentation, David Hildenbrand, 2021/08/11
- [PATCH v2 07/13] s390x/mmu_helper: move address validation into mmu_translate*(), David Hildenbrand, 2021/08/11
- [PATCH v2 08/13] s390x/mmu_helper: avoid setting the storage key if nothing changed, David Hildenbrand, 2021/08/11
- [PATCH v2 09/13] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to migrate,
David Hildenbrand <=
- [PATCH v2 10/13] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to dump, David Hildenbrand, 2021/08/11
- [PATCH v2 11/13] hw/s390x/s390-skeys: check if an address is valid before dumping the key, David Hildenbrand, 2021/08/11
- [PATCH v2 12/13] hw/s390x/s390-skeys: rename skeys_enabled to skeys_are_enabled, David Hildenbrand, 2021/08/11
- [PATCH v2 13/13] hw/s390x/s390-skeys: lazy storage key enablement under TCG, David Hildenbrand, 2021/08/11