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; 249ef40173SJason J. Herne bool migration_enabled; 250efe406cSJason J. Herne 26db1015e9SEduardo Habkost }; 270efe406cSJason J. Herne 280efe406cSJason J. Herne 29db1015e9SEduardo Habkost struct S390SKeysClass { 300efe406cSJason J. Herne DeviceClass parent_class; 31c3562238SDavid Hildenbrand 32c3562238SDavid Hildenbrand /** 33c3562238SDavid Hildenbrand * @skeys_are_enabled: 34c3562238SDavid Hildenbrand * 35c3562238SDavid Hildenbrand * Check whether storage keys are enabled. If not enabled, they were not 36c3562238SDavid Hildenbrand * enabled lazily either by the guest via a storage key instruction or 37c3562238SDavid Hildenbrand * by the host during migration. 38c3562238SDavid Hildenbrand * 39c3562238SDavid Hildenbrand * If disabled, everything not explicitly triggered by the guest, 40c3562238SDavid Hildenbrand * such as outgoing migration or dirty/change tracking, should not touch 41c3562238SDavid Hildenbrand * storage keys and should not lazily enable it. 42c3562238SDavid Hildenbrand * 43c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 44c3562238SDavid Hildenbrand * 45c3562238SDavid Hildenbrand * Returns false if not enabled and true if enabled. 46c3562238SDavid Hildenbrand */ 475227b326SDavid Hildenbrand bool (*skeys_are_enabled)(S390SKeysState *ks); 48c3562238SDavid Hildenbrand 49c3562238SDavid Hildenbrand /** 50c3562238SDavid Hildenbrand * @enable_skeys: 51c3562238SDavid Hildenbrand * 52c3562238SDavid Hildenbrand * Lazily enable storage keys. If this function is not implemented, 53c3562238SDavid Hildenbrand * setting a storage key will lazily enable storage keys implicitly 54c3562238SDavid Hildenbrand * instead. TCG guests have to make sure to flush the TLB of all CPUs 55c3562238SDavid Hildenbrand * if storage keys were not enabled before this call. 56c3562238SDavid Hildenbrand * 57c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 58c3562238SDavid Hildenbrand * 59c3562238SDavid Hildenbrand * Returns false if not enabled before this call, and true if already 60c3562238SDavid Hildenbrand * enabled. 61c3562238SDavid Hildenbrand */ 62c3562238SDavid Hildenbrand bool (*enable_skeys)(S390SKeysState *ks); 63c3562238SDavid Hildenbrand 64c3562238SDavid Hildenbrand /** 65c3562238SDavid Hildenbrand * @get_skeys: 66c3562238SDavid Hildenbrand * 67c3562238SDavid Hildenbrand * Get storage keys for the given PFN range. This call will fail if 68c3562238SDavid Hildenbrand * storage keys have not been lazily enabled yet. 69c3562238SDavid Hildenbrand * 70c3562238SDavid Hildenbrand * Callers have to validate that a GFN is valid before this call. 71c3562238SDavid Hildenbrand * 72c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 73c3562238SDavid Hildenbrand * @start_gfn: the start GFN to get storage keys for 74c3562238SDavid Hildenbrand * @count: the number of storage keys to get 75c3562238SDavid Hildenbrand * @keys: the byte array where storage keys will be stored to 76c3562238SDavid Hildenbrand * 77c3562238SDavid Hildenbrand * Returns 0 on success, returns an error if getting a storage key failed. 78c3562238SDavid Hildenbrand */ 790efe406cSJason J. Herne int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, 800efe406cSJason J. Herne uint8_t *keys); 81c3562238SDavid Hildenbrand /** 82c3562238SDavid Hildenbrand * @set_skeys: 83c3562238SDavid Hildenbrand * 84c3562238SDavid Hildenbrand * Set storage keys for the given PFN range. This call will fail if 85c3562238SDavid Hildenbrand * storage keys have not been lazily enabled yet and implicit 86c3562238SDavid Hildenbrand * enablement is not supported. 87c3562238SDavid Hildenbrand * 88c3562238SDavid Hildenbrand * Callers have to validate that a GFN is valid before this call. 89c3562238SDavid Hildenbrand * 90c3562238SDavid Hildenbrand * @ks: the #S390SKeysState 91c3562238SDavid Hildenbrand * @start_gfn: the start GFN to set storage keys for 92c3562238SDavid Hildenbrand * @count: the number of storage keys to set 93c3562238SDavid Hildenbrand * @keys: the byte array where storage keys will be read from 94c3562238SDavid Hildenbrand * 95c3562238SDavid Hildenbrand * Returns 0 on success, returns an error if setting a storage key failed. 96c3562238SDavid Hildenbrand */ 970efe406cSJason J. Herne int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count, 980efe406cSJason J. Herne uint8_t *keys); 99db1015e9SEduardo Habkost }; 1000efe406cSJason J. Herne 1010efe406cSJason J. Herne #define TYPE_KVM_S390_SKEYS "s390-skeys-kvm" 1020efe406cSJason J. Herne #define TYPE_QEMU_S390_SKEYS "s390-skeys-qemu" 103db1015e9SEduardo Habkost typedef struct QEMUS390SKeysState QEMUS390SKeysState; 1048110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(QEMUS390SKeysState, QEMU_S390_SKEYS, 1058110fa1dSEduardo Habkost TYPE_QEMU_S390_SKEYS) 1060efe406cSJason J. Herne 107db1015e9SEduardo Habkost struct QEMUS390SKeysState { 1080efe406cSJason J. Herne S390SKeysState parent_obj; 1090efe406cSJason J. Herne uint8_t *keydata; 1100efe406cSJason J. Herne uint32_t key_count; 111db1015e9SEduardo Habkost }; 1120efe406cSJason J. Herne 1130efe406cSJason J. Herne void s390_skeys_init(void); 114*b9268953SPhilippe Mathieu-Daudé /** 115*b9268953SPhilippe Mathieu-Daudé * @s390_skeys_get: See S390SKeysClass::get_skeys() 116*b9268953SPhilippe Mathieu-Daudé */ 117*b9268953SPhilippe Mathieu-Daudé int s390_skeys_get(S390SKeysState *ks, uint64_t start_gfn, 118*b9268953SPhilippe Mathieu-Daudé uint64_t count, uint8_t *keys); 119*b9268953SPhilippe Mathieu-Daudé /** 120*b9268953SPhilippe Mathieu-Daudé * @s390_skeys_set: See S390SKeysClass::set_skeys() 121*b9268953SPhilippe Mathieu-Daudé */ 122*b9268953SPhilippe Mathieu-Daudé int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn, 123*b9268953SPhilippe Mathieu-Daudé uint64_t count, uint8_t *keys); 1240efe406cSJason J. Herne 1250efe406cSJason J. Herne S390SKeysState *s390_get_skeys_device(void); 1260efe406cSJason J. Herne 127a4538a5cSJason J. Herne void hmp_dump_skeys(Monitor *mon, const QDict *qdict); 128a08f0081SJason J. Herne void hmp_info_skeys(Monitor *mon, const QDict *qdict); 129a08f0081SJason J. Herne 1302a6a4076SMarkus Armbruster #endif /* S390_STORAGE_KEYS_H */ 131