2 * s390 storage key device
4 * Copyright 2015 IBM Corp.
5 * Author(s): Jason J. Herne <jjherne@linux.vnet.ibm.com>
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
12 #ifndef S390_STORAGE_KEYS_H
13 #define S390_STORAGE_KEYS_H
15 #include "hw/qdev-core.h"
16 #include "monitor/monitor.h"
17 #include "qom/object.h"
19 #define TYPE_S390_SKEYS "s390-skeys"
20 OBJECT_DECLARE_TYPE(S390SKeysState
, S390SKeysClass
, S390_SKEYS
)
22 struct S390SKeysState
{
23 DeviceState parent_obj
;
24 bool migration_enabled
;
29 struct S390SKeysClass
{
30 DeviceClass parent_class
;
35 * Check whether storage keys are enabled. If not enabled, they were not
36 * enabled lazily either by the guest via a storage key instruction or
37 * by the host during migration.
39 * If disabled, everything not explicitly triggered by the guest,
40 * such as outgoing migration or dirty/change tracking, should not touch
41 * storage keys and should not lazily enable it.
43 * @ks: the #S390SKeysState
45 * Returns false if not enabled and true if enabled.
47 bool (*skeys_are_enabled
)(S390SKeysState
*ks
);
52 * Lazily enable storage keys. If this function is not implemented,
53 * setting a storage key will lazily enable storage keys implicitly
54 * instead. TCG guests have to make sure to flush the TLB of all CPUs
55 * if storage keys were not enabled before this call.
57 * @ks: the #S390SKeysState
59 * Returns false if not enabled before this call, and true if already
62 bool (*enable_skeys
)(S390SKeysState
*ks
);
67 * Get storage keys for the given PFN range. This call will fail if
68 * storage keys have not been lazily enabled yet.
70 * Callers have to validate that a GFN is valid before this call.
72 * @ks: the #S390SKeysState
73 * @start_gfn: the start GFN to get storage keys for
74 * @count: the number of storage keys to get
75 * @keys: the byte array where storage keys will be stored to
77 * Returns 0 on success, returns an error if getting a storage key failed.
79 int (*get_skeys
)(S390SKeysState
*ks
, uint64_t start_gfn
, uint64_t count
,
84 * Set storage keys for the given PFN range. This call will fail if
85 * storage keys have not been lazily enabled yet and implicit
86 * enablement is not supported.
88 * Callers have to validate that a GFN is valid before this call.
90 * @ks: the #S390SKeysState
91 * @start_gfn: the start GFN to set storage keys for
92 * @count: the number of storage keys to set
93 * @keys: the byte array where storage keys will be read from
95 * Returns 0 on success, returns an error if setting a storage key failed.
97 int (*set_skeys
)(S390SKeysState
*ks
, uint64_t start_gfn
, uint64_t count
,
101 #define TYPE_KVM_S390_SKEYS "s390-skeys-kvm"
102 #define TYPE_QEMU_S390_SKEYS "s390-skeys-qemu"
103 typedef struct QEMUS390SKeysState QEMUS390SKeysState
;
104 DECLARE_INSTANCE_CHECKER(QEMUS390SKeysState
, QEMU_S390_SKEYS
,
105 TYPE_QEMU_S390_SKEYS
)
107 struct QEMUS390SKeysState
{
108 S390SKeysState parent_obj
;
113 void s390_skeys_init(void);
115 * @s390_skeys_get: See S390SKeysClass::get_skeys()
117 int s390_skeys_get(S390SKeysState
*ks
, uint64_t start_gfn
,
118 uint64_t count
, uint8_t *keys
);
120 * @s390_skeys_set: See S390SKeysClass::set_skeys()
122 int s390_skeys_set(S390SKeysState
*ks
, uint64_t start_gfn
,
123 uint64_t count
, uint8_t *keys
);
125 S390SKeysState
*s390_get_skeys_device(void);
127 void hmp_dump_skeys(Monitor
*mon
, const QDict
*qdict
);
128 void hmp_info_skeys(Monitor
*mon
, const QDict
*qdict
);
130 #endif /* S390_STORAGE_KEYS_H */