xref: /qemu/include/hw/s390x/storage-keys.h (revision c35622387efe39214ccd14fab0f280b6c53f1654)
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;
31*c3562238SDavid Hildenbrand 
32*c3562238SDavid Hildenbrand     /**
33*c3562238SDavid Hildenbrand      * @skeys_are_enabled:
34*c3562238SDavid Hildenbrand      *
35*c3562238SDavid Hildenbrand      * Check whether storage keys are enabled. If not enabled, they were not
36*c3562238SDavid Hildenbrand      * enabled lazily either by the guest via a storage key instruction or
37*c3562238SDavid Hildenbrand      * by the host during migration.
38*c3562238SDavid Hildenbrand      *
39*c3562238SDavid Hildenbrand      * If disabled, everything not explicitly triggered by the guest,
40*c3562238SDavid Hildenbrand      * such as outgoing migration or dirty/change tracking, should not touch
41*c3562238SDavid Hildenbrand      * storage keys and should not lazily enable it.
42*c3562238SDavid Hildenbrand      *
43*c3562238SDavid Hildenbrand      * @ks: the #S390SKeysState
44*c3562238SDavid Hildenbrand      *
45*c3562238SDavid Hildenbrand      * Returns false if not enabled and true if enabled.
46*c3562238SDavid Hildenbrand      */
475227b326SDavid Hildenbrand     bool (*skeys_are_enabled)(S390SKeysState *ks);
48*c3562238SDavid Hildenbrand 
49*c3562238SDavid Hildenbrand     /**
50*c3562238SDavid Hildenbrand      * @enable_skeys:
51*c3562238SDavid Hildenbrand      *
52*c3562238SDavid Hildenbrand      * Lazily enable storage keys. If this function is not implemented,
53*c3562238SDavid Hildenbrand      * setting a storage key will lazily enable storage keys implicitly
54*c3562238SDavid Hildenbrand      * instead. TCG guests have to make sure to flush the TLB of all CPUs
55*c3562238SDavid Hildenbrand      * if storage keys were not enabled before this call.
56*c3562238SDavid Hildenbrand      *
57*c3562238SDavid Hildenbrand      * @ks: the #S390SKeysState
58*c3562238SDavid Hildenbrand      *
59*c3562238SDavid Hildenbrand      * Returns false if not enabled before this call, and true if already
60*c3562238SDavid Hildenbrand      * enabled.
61*c3562238SDavid Hildenbrand      */
62*c3562238SDavid Hildenbrand     bool (*enable_skeys)(S390SKeysState *ks);
63*c3562238SDavid Hildenbrand 
64*c3562238SDavid Hildenbrand     /**
65*c3562238SDavid Hildenbrand      * @get_skeys:
66*c3562238SDavid Hildenbrand      *
67*c3562238SDavid Hildenbrand      * Get storage keys for the given PFN range. This call will fail if
68*c3562238SDavid Hildenbrand      * storage keys have not been lazily enabled yet.
69*c3562238SDavid Hildenbrand      *
70*c3562238SDavid Hildenbrand      * Callers have to validate that a GFN is valid before this call.
71*c3562238SDavid Hildenbrand      *
72*c3562238SDavid Hildenbrand      * @ks: the #S390SKeysState
73*c3562238SDavid Hildenbrand      * @start_gfn: the start GFN to get storage keys for
74*c3562238SDavid Hildenbrand      * @count: the number of storage keys to get
75*c3562238SDavid Hildenbrand      * @keys: the byte array where storage keys will be stored to
76*c3562238SDavid Hildenbrand      *
77*c3562238SDavid Hildenbrand      * Returns 0 on success, returns an error if getting a storage key failed.
78*c3562238SDavid Hildenbrand      */
790efe406cSJason J. Herne     int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t count,
800efe406cSJason J. Herne                      uint8_t *keys);
81*c3562238SDavid Hildenbrand     /**
82*c3562238SDavid Hildenbrand      * @set_skeys:
83*c3562238SDavid Hildenbrand      *
84*c3562238SDavid Hildenbrand      * Set storage keys for the given PFN range. This call will fail if
85*c3562238SDavid Hildenbrand      * storage keys have not been lazily enabled yet and implicit
86*c3562238SDavid Hildenbrand      * enablement is not supported.
87*c3562238SDavid Hildenbrand      *
88*c3562238SDavid Hildenbrand      * Callers have to validate that a GFN is valid before this call.
89*c3562238SDavid Hildenbrand      *
90*c3562238SDavid Hildenbrand      * @ks: the #S390SKeysState
91*c3562238SDavid Hildenbrand      * @start_gfn: the start GFN to set storage keys for
92*c3562238SDavid Hildenbrand      * @count: the number of storage keys to set
93*c3562238SDavid Hildenbrand      * @keys: the byte array where storage keys will be read from
94*c3562238SDavid Hildenbrand      *
95*c3562238SDavid Hildenbrand      * Returns 0 on success, returns an error if setting a storage key failed.
96*c3562238SDavid 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);
1140efe406cSJason J. Herne 
1150efe406cSJason J. Herne S390SKeysState *s390_get_skeys_device(void);
1160efe406cSJason J. Herne 
117a4538a5cSJason J. Herne void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
118a08f0081SJason J. Herne void hmp_info_skeys(Monitor *mon, const QDict *qdict);
119a08f0081SJason J. Herne 
1202a6a4076SMarkus Armbruster #endif /* S390_STORAGE_KEYS_H */
121