| 1 | /* |
| 2 | * s390 storage key device |
| 3 | * |
| 4 | * Copyright 2015 IBM Corp. |
| 5 | * Author(s): Jason J. Herne <jjherne@linux.vnet.ibm.com> |
| 6 | * |
| 7 | * This work is licensed under the terms of the GNU GPL, version 2 or (at |
| 8 | * your option) any later version. See the COPYING file in the top-level |
| 9 | * directory. |
| 10 | */ |
| 11 | |
| 12 | #ifndef S390_STORAGE_KEYS_H |
| 13 | #define S390_STORAGE_KEYS_H |
| 14 | |
| 15 | #include "hw/core/qdev.h" |
| 16 | #include "qom/object.h" |
| 17 | |
| 18 | #define TYPE_S390_SKEYS "s390-skeys" |
| 19 | OBJECT_DECLARE_TYPE(S390SKeysState, S390SKeysClass, S390_SKEYS) |
| 20 | |
| 21 | struct S390SKeysState { |
| 22 | DeviceState parent_obj; |
| 23 | }; |
| 24 | |
| 25 | |
| 26 | struct S390SKeysClass { |
| 27 | DeviceClass parent_class; |
| 28 | |
| 29 | /** |
| 30 | * @skeys_are_enabled: |
| 31 | * |
| 32 | * Check whether storage keys are enabled. If not enabled, they were not |
| 33 | * enabled lazily either by the guest via a storage key instruction or |
| 34 | * by the host during migration. |
| 35 | * |
| 36 | * If disabled, everything not explicitly triggered by the guest, |
| 37 | * such as outgoing migration or dirty/change tracking, should not touch |
| 38 | * storage keys and should not lazily enable it. |
| 39 | * |
| 40 | * @ks: the #S390SKeysState |
| 41 | * |
| 42 | * Returns false if not enabled and true if enabled. |
| 43 | */ |
| 44 | bool (*skeys_are_enabled)(S390SKeysState *ks); |
| 45 | |
| 46 | /** |
| 47 | * @enable_skeys: |
| 48 | * |
| 49 | * Lazily enable storage keys. If this function is not implemented, |
| 50 | * setting a storage key will lazily enable storage keys implicitly |
| 51 | * instead. TCG guests have to make sure to flush the TLB of all CPUs |
| 52 | * if storage keys were not enabled before this call. |
| 53 | * |
| 54 | * @ks: the #S390SKeysState |
| 55 | * |
| 56 | * Returns false if not enabled before this call, and true if already |
| 57 | * enabled. |
| 58 | */ |
| 59 | bool (*enable_skeys)(S390SKeysState *ks); |
| 60 | |
| 61 | /** |
| 62 | * @get_skeys: |
| 63 | * |
| 64 | * Get storage keys for the given PFN range. This call will fail if |
| 65 | * storage keys have not been lazily enabled yet. |
| 66 | * |
| 67 | * Callers have to validate that a GFN is valid before this call. |
| 68 | * |
| 69 | * @ks: the #S390SKeysState |
| 70 | * @start_gfn: the start GFN to get storage keys for |
| 71 | * @count: the number of storage keys to get |
| 72 | * @keys: the byte array where storage keys will be stored to |
| 73 | * |
| 74 | * Returns 0 on success, returns an error if getting a storage key failed. |
| 75 | */ |
| 76 | int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, |
| 77 | uint8_t *keys); |
| 78 | /** |
| 79 | * @set_skeys: |
| 80 | * |
| 81 | * Set storage keys for the given PFN range. This call will fail if |
| 82 | * storage keys have not been lazily enabled yet and implicit |
| 83 | * enablement is not supported. |
| 84 | * |
| 85 | * Callers have to validate that a GFN is valid before this call. |
| 86 | * |
| 87 | * @ks: the #S390SKeysState |
| 88 | * @start_gfn: the start GFN to set storage keys for |
| 89 | * @count: the number of storage keys to set |
| 90 | * @keys: the byte array where storage keys will be read from |
| 91 | * |
| 92 | * Returns 0 on success, returns an error if setting a storage key failed. |
| 93 | */ |
| 94 | int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, |
| 95 | uint8_t *keys); |
| 96 | }; |
| 97 | |
| 98 | #define TYPE_KVM_S390_SKEYS "s390-skeys-kvm" |
| 99 | #define TYPE_QEMU_S390_SKEYS "s390-skeys-qemu" |
| 100 | typedef struct QEMUS390SKeysState QEMUS390SKeysState; |
| 101 | DECLARE_INSTANCE_CHECKER(QEMUS390SKeysState, QEMU_S390_SKEYS, |
| 102 | TYPE_QEMU_S390_SKEYS) |
| 103 | |
| 104 | struct QEMUS390SKeysState { |
| 105 | S390SKeysState parent_obj; |
| 106 | uint8_t *keydata; |
| 107 | uint32_t key_count; |
| 108 | }; |
| 109 | |
| 110 | void s390_skeys_init(void); |
| 111 | /** |
| 112 | * @s390_skeys_get: See S390SKeysClass::get_skeys() |
| 113 | */ |
| 114 | int s390_skeys_get(S390SKeysState *ks, uint64_t start_gfn, |
| 115 | uint64_t count, uint8_t *keys); |
| 116 | /** |
| 117 | * @s390_skeys_set: See S390SKeysClass::set_skeys() |
| 118 | */ |
| 119 | int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn, |
| 120 | uint64_t count, uint8_t *keys); |
| 121 | |
| 122 | S390SKeysState *s390_get_skeys_device(void); |
| 123 | |
| 124 | void s390_qmp_dump_skeys(const char *filename, Error **errp); |
| 125 | |
| 126 | #define TYPE_DUMP_SKEYS_INTERFACE "dump-skeys-interface" |
| 127 | |
| 128 | typedef struct DumpSKeysInterface DumpSKeysInterface; |
| 129 | DECLARE_CLASS_CHECKERS(DumpSKeysInterface, DUMP_SKEYS_INTERFACE, |
| 130 | TYPE_DUMP_SKEYS_INTERFACE) |
| 131 | |
| 132 | struct DumpSKeysInterface { |
| 133 | InterfaceClass parent_class; |
| 134 | |
| 135 | /** |
| 136 | * @qmp_dump_skeys: Callback to dump guest's storage keys to @filename. |
| 137 | */ |
| 138 | void (*qmp_dump_skeys)(const char *filename, Error **errp); |
| 139 | }; |
| 140 | |
| 141 | #endif /* S390_STORAGE_KEYS_H */ |