10efe406cSJason J. Herne /* 20efe406cSJason J. Herne * s390 storage key device 30efe406cSJason J. Herne * 40efe406cSJason J. Herne * Copyright 2015 IBM Corp. 50efe406cSJason J. Herne * Author(s): Jason J. Herne <jjherne@linux.vnet.ibm.com> 60efe406cSJason J. Herne * 70efe406cSJason J. Herne * This work is licensed under the terms of the GNU GPL, version 2 or (at 80efe406cSJason J. Herne * your option) any later version. See the COPYING file in the top-level 90efe406cSJason J. Herne * directory. 100efe406cSJason J. Herne */ 110efe406cSJason J. Herne 122a6a4076SMarkus Armbruster #ifndef S390_STORAGE_KEYS_H 132a6a4076SMarkus Armbruster #define S390_STORAGE_KEYS_H 140efe406cSJason J. Herne 15a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 16a4538a5cSJason J. Herne #include "monitor/monitor.h" 17db1015e9SEduardo Habkost #include "qom/object.h" 180efe406cSJason J. Herne 190efe406cSJason J. Herne #define TYPE_S390_SKEYS "s390-skeys" 20a489d195SEduardo Habkost OBJECT_DECLARE_TYPE(S390SKeysState, S390SKeysClass, S390_SKEYS) 210efe406cSJason J. Herne 22db1015e9SEduardo Habkost struct S390SKeysState { 230efe406cSJason J. Herne DeviceState parent_obj; 24db1015e9SEduardo Habkost }; 250efe406cSJason J. Herne 260efe406cSJason J. Herne 27db1015e9SEduardo Habkost struct S390SKeysClass { 280efe406cSJason J. Herne DeviceClass parent_class; 29c3562238SDavid Hildenbrand 30c3562238SDavid Hildenbrand /** 31c3562238SDavid Hildenbrand * @skeys_are_enabled: 32c3562238SDavid Hildenbrand * 33c3562238SDavid Hildenbrand * Check whether storage keys are enabled. If not enabled, they were not 34c3562238SDavid Hildenbrand * enabled lazily either by the guest via a storage key instruction or 35c3562238SDavid Hildenbrand * by the host during migration. 36c3562238SDavid Hildenbrand * 37c3562238SDavid Hildenbrand * If disabled, everything not explicitly triggered by the guest, 38c3562238SDavid Hildenbrand * such as outgoing migration or dirty/change tracking, should not touch 39c3562238SDavid Hildenbrand * storage keys and should not lazily enable it. 40c3562238SDavid Hildenbrand * 41c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 42c3562238SDavid Hildenbrand * 43c3562238SDavid Hildenbrand * Returns false if not enabled and true if enabled. 44c3562238SDavid Hildenbrand */ 455227b326SDavid Hildenbrand bool (*skeys_are_enabled)(S390SKeysState *ks); 46c3562238SDavid Hildenbrand 47c3562238SDavid Hildenbrand /** 48c3562238SDavid Hildenbrand * @enable_skeys: 49c3562238SDavid Hildenbrand * 50c3562238SDavid Hildenbrand * Lazily enable storage keys. If this function is not implemented, 51c3562238SDavid Hildenbrand * setting a storage key will lazily enable storage keys implicitly 52c3562238SDavid Hildenbrand * instead. TCG guests have to make sure to flush the TLB of all CPUs 53c3562238SDavid Hildenbrand * if storage keys were not enabled before this call. 54c3562238SDavid Hildenbrand * 55c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 56c3562238SDavid Hildenbrand * 57c3562238SDavid Hildenbrand * Returns false if not enabled before this call, and true if already 58c3562238SDavid Hildenbrand * enabled. 59c3562238SDavid Hildenbrand */ 60c3562238SDavid Hildenbrand bool (*enable_skeys)(S390SKeysState *ks); 61c3562238SDavid Hildenbrand 62c3562238SDavid Hildenbrand /** 63c3562238SDavid Hildenbrand * @get_skeys: 64c3562238SDavid Hildenbrand * 65c3562238SDavid Hildenbrand * Get storage keys for the given PFN range. This call will fail if 66c3562238SDavid Hildenbrand * storage keys have not been lazily enabled yet. 67c3562238SDavid Hildenbrand * 68c3562238SDavid Hildenbrand * Callers have to validate that a GFN is valid before this call. 69c3562238SDavid Hildenbrand * 70c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 71c3562238SDavid Hildenbrand * @start_gfn: the start GFN to get storage keys for 72c3562238SDavid Hildenbrand * @count: the number of storage keys to get 73c3562238SDavid Hildenbrand * @keys: the byte array where storage keys will be stored to 74c3562238SDavid Hildenbrand * 75c3562238SDavid Hildenbrand * Returns 0 on success, returns an error if getting a storage key failed. 76c3562238SDavid Hildenbrand */ 770efe406cSJason J. Herne int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, 780efe406cSJason J. Herne uint8_t *keys); 79c3562238SDavid Hildenbrand /** 80c3562238SDavid Hildenbrand * @set_skeys: 81c3562238SDavid Hildenbrand * 82c3562238SDavid Hildenbrand * Set storage keys for the given PFN range. This call will fail if 83c3562238SDavid Hildenbrand * storage keys have not been lazily enabled yet and implicit 84c3562238SDavid Hildenbrand * enablement is not supported. 85c3562238SDavid Hildenbrand * 86c3562238SDavid Hildenbrand * Callers have to validate that a GFN is valid before this call. 87c3562238SDavid Hildenbrand * 88c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 89c3562238SDavid Hildenbrand * @start_gfn: the start GFN to set storage keys for 90c3562238SDavid Hildenbrand * @count: the number of storage keys to set 91c3562238SDavid Hildenbrand * @keys: the byte array where storage keys will be read from 92c3562238SDavid Hildenbrand * 93c3562238SDavid Hildenbrand * Returns 0 on success, returns an error if setting a storage key failed. 94c3562238SDavid Hildenbrand */ 950efe406cSJason J. Herne int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, 960efe406cSJason J. Herne uint8_t *keys); 97db1015e9SEduardo Habkost }; 980efe406cSJason J. Herne 990efe406cSJason J. Herne #define TYPE_KVM_S390_SKEYS "s390-skeys-kvm" 1000efe406cSJason J. Herne #define TYPE_QEMU_S390_SKEYS "s390-skeys-qemu" 101db1015e9SEduardo Habkost typedef struct QEMUS390SKeysState QEMUS390SKeysState; 1028110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(QEMUS390SKeysState, QEMU_S390_SKEYS, 1038110fa1dSEduardo Habkost TYPE_QEMU_S390_SKEYS) 1040efe406cSJason J. Herne 105db1015e9SEduardo Habkost struct QEMUS390SKeysState { 1060efe406cSJason J. Herne S390SKeysState parent_obj; 1070efe406cSJason J. Herne uint8_t *keydata; 1080efe406cSJason J. Herne uint32_t key_count; 109db1015e9SEduardo Habkost }; 1100efe406cSJason J. Herne 1110efe406cSJason J. Herne void s390_skeys_init(void); 112b9268953SPhilippe Mathieu-Daudé /** 113b9268953SPhilippe Mathieu-Daudé * @s390_skeys_get: See S390SKeysClass::get_skeys() 114b9268953SPhilippe Mathieu-Daudé */ 115b9268953SPhilippe Mathieu-Daudé int s390_skeys_get(S390SKeysState *ks, uint64_t start_gfn, 116b9268953SPhilippe Mathieu-Daudé uint64_t count, uint8_t *keys); 117b9268953SPhilippe Mathieu-Daudé /** 118b9268953SPhilippe Mathieu-Daudé * @s390_skeys_set: See S390SKeysClass::set_skeys() 119b9268953SPhilippe Mathieu-Daudé */ 120b9268953SPhilippe Mathieu-Daudé int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn, 121b9268953SPhilippe Mathieu-Daudé uint64_t count, uint8_t *keys); 1220efe406cSJason J. Herne 1230efe406cSJason J. Herne S390SKeysState *s390_get_skeys_device(void); 1240efe406cSJason J. Herne 125*1b759bb0SPhilippe Mathieu-Daudé void s390_qmp_dump_skeys(const char *filename, Error **errp); 126a4538a5cSJason J. Herne void hmp_dump_skeys(Monitor *mon, const QDict *qdict); 127a08f0081SJason J. Herne void hmp_info_skeys(Monitor *mon, const QDict *qdict); 128a08f0081SJason J. Herne 1293f979fe1SPhilippe Mathieu-Daudé #define TYPE_DUMP_SKEYS_INTERFACE "dump-skeys-interface" 1303f979fe1SPhilippe Mathieu-Daudé 1313f979fe1SPhilippe Mathieu-Daudé typedef struct DumpSKeysInterface DumpSKeysInterface; 1323f979fe1SPhilippe Mathieu-Daudé DECLARE_CLASS_CHECKERS(DumpSKeysInterface, DUMP_SKEYS_INTERFACE, 1333f979fe1SPhilippe Mathieu-Daudé TYPE_DUMP_SKEYS_INTERFACE) 1343f979fe1SPhilippe Mathieu-Daudé 1353f979fe1SPhilippe Mathieu-Daudé struct DumpSKeysInterface { 1363f979fe1SPhilippe Mathieu-Daudé InterfaceClass parent_class; 1373f979fe1SPhilippe Mathieu-Daudé 1383f979fe1SPhilippe Mathieu-Daudé /** 1393f979fe1SPhilippe Mathieu-Daudé * @qmp_dump_skeys: Callback to dump guest's storage keys to @filename. 1403f979fe1SPhilippe Mathieu-Daudé */ 1413f979fe1SPhilippe Mathieu-Daudé void (*qmp_dump_skeys)(const char *filename, Error **errp); 1423f979fe1SPhilippe Mathieu-Daudé }; 1433f979fe1SPhilippe Mathieu-Daudé 1442a6a4076SMarkus Armbruster #endif /* S390_STORAGE_KEYS_H */ 145