blob: 3ff9d94b802fd8484028e89d22e555f5f7dd15c4 [file] [log] [blame]
Jason J. Herne0efe4062015-06-26 11:54:51 -04001/*
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
Peter Maydell96154952016-01-26 18:17:00 +000012#include "qemu/osdep.h"
Jason J. Herne0efe4062015-06-26 11:54:51 -040013#include "hw/s390x/storage-keys.h"
14#include "sysemu/kvm.h"
15#include "qemu/error-report.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020016#include "qemu/module.h"
Jason J. Herne0efe4062015-06-26 11:54:51 -040017
David Hildenbrand5227b322021-09-03 17:55:13 +020018static bool kvm_s390_skeys_are_enabled(S390SKeysState *ss)
Jason J. Herne0efe4062015-06-26 11:54:51 -040019{
20 S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
21 uint8_t single_key;
22 int r;
23
24 r = skeyclass->get_skeys(ss, 0, 1, &single_key);
25 if (r != 0 && r != KVM_S390_GET_SKEYS_NONE) {
Markus Armbruster9af9e0f2015-12-18 16:35:19 +010026 error_report("S390_GET_KEYS error %d", r);
Jason J. Herne0efe4062015-06-26 11:54:51 -040027 }
28 return (r == 0);
29}
30
31static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn,
32 uint64_t count, uint8_t *keys)
33{
34 struct kvm_s390_skeys args = {
35 .start_gfn = start_gfn,
36 .count = count,
37 .skeydata_addr = (__u64)keys
38 };
39
40 return kvm_vm_ioctl(kvm_state, KVM_S390_GET_SKEYS, &args);
41}
42
43static int kvm_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn,
44 uint64_t count, uint8_t *keys)
45{
46 struct kvm_s390_skeys args = {
47 .start_gfn = start_gfn,
48 .count = count,
49 .skeydata_addr = (__u64)keys
50 };
51
52 return kvm_vm_ioctl(kvm_state, KVM_S390_SET_SKEYS, &args);
53}
54
55static void kvm_s390_skeys_class_init(ObjectClass *oc, void *data)
56{
57 S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
Thomas Huth574ee062017-08-24 12:08:48 +020058 DeviceClass *dc = DEVICE_CLASS(oc);
Jason J. Herne0efe4062015-06-26 11:54:51 -040059
David Hildenbrand5227b322021-09-03 17:55:13 +020060 skeyclass->skeys_are_enabled = kvm_s390_skeys_are_enabled;
Jason J. Herne0efe4062015-06-26 11:54:51 -040061 skeyclass->get_skeys = kvm_s390_skeys_get;
62 skeyclass->set_skeys = kvm_s390_skeys_set;
Thomas Huth574ee062017-08-24 12:08:48 +020063
64 /* Reason: Internal device (only one skeys device for the whole memory) */
65 dc->user_creatable = false;
Jason J. Herne0efe4062015-06-26 11:54:51 -040066}
67
68static const TypeInfo kvm_s390_skeys_info = {
69 .name = TYPE_KVM_S390_SKEYS,
70 .parent = TYPE_S390_SKEYS,
71 .instance_size = sizeof(S390SKeysState),
72 .class_init = kvm_s390_skeys_class_init,
73 .class_size = sizeof(S390SKeysClass),
74};
75
76static void kvm_s390_skeys_register_types(void)
77{
78 type_register_static(&kvm_s390_skeys_info);
79}
80
81type_init(kvm_s390_skeys_register_types)