xref: /openbmc/qemu/include/hw/s390x/storage-keys.h (revision 76bccf3c)
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/qdev-core.h"
16 #include "monitor/monitor.h"
17 #include "qom/object.h"
18 
19 #define TYPE_S390_SKEYS "s390-skeys"
20 OBJECT_DECLARE_TYPE(S390SKeysState, S390SKeysClass, S390_SKEYS)
21 
22 struct S390SKeysState {
23     DeviceState parent_obj;
24     bool migration_enabled;
25 
26 };
27 
28 
29 struct S390SKeysClass {
30     DeviceClass parent_class;
31 
32     /**
33      * @skeys_are_enabled:
34      *
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.
38      *
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.
42      *
43      * @ks: the #S390SKeysState
44      *
45      * Returns false if not enabled and true if enabled.
46      */
47     bool (*skeys_are_enabled)(S390SKeysState *ks);
48 
49     /**
50      * @enable_skeys:
51      *
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.
56      *
57      * @ks: the #S390SKeysState
58      *
59      * Returns false if not enabled before this call, and true if already
60      * enabled.
61      */
62     bool (*enable_skeys)(S390SKeysState *ks);
63 
64     /**
65      * @get_skeys:
66      *
67      * Get storage keys for the given PFN range. This call will fail if
68      * storage keys have not been lazily enabled yet.
69      *
70      * Callers have to validate that a GFN is valid before this call.
71      *
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
76      *
77      * Returns 0 on success, returns an error if getting a storage key failed.
78      */
79     int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count,
80                      uint8_t *keys);
81     /**
82      * @set_skeys:
83      *
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.
87      *
88      * Callers have to validate that a GFN is valid before this call.
89      *
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
94      *
95      * Returns 0 on success, returns an error if setting a storage key failed.
96      */
97     int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count,
98                      uint8_t *keys);
99 };
100 
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)
106 
107 struct QEMUS390SKeysState {
108     S390SKeysState parent_obj;
109     uint8_t *keydata;
110     uint32_t key_count;
111 };
112 
113 void s390_skeys_init(void);
114 /**
115  * @s390_skeys_get: See S390SKeysClass::get_skeys()
116  */
117 int s390_skeys_get(S390SKeysState *ks, uint64_t start_gfn,
118                    uint64_t count, uint8_t *keys);
119 /**
120  * @s390_skeys_set: See S390SKeysClass::set_skeys()
121  */
122 int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn,
123                    uint64_t count, uint8_t *keys);
124 
125 S390SKeysState *s390_get_skeys_device(void);
126 
127 void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
128 void hmp_info_skeys(Monitor *mon, const QDict *qdict);
129 
130 #endif /* S390_STORAGE_KEYS_H */
131