s390x/kvm: fixes and features
cover s390x/kvm: fixes and features
Conny, Alex, Christian,
a few more s390 patches:
Patch 1: encapsulates the HAS_DEVICE check into a generic function Patch 2: use the function introduced in Patch 1
Patch 3: introduces two new machine options for indicating the state of
AES/DEA key wrapping functions
Patch 4 and 5: remove dead code
Patch 6: fill in length for sei_nt2 event
regards
Jens
Dominik Dingel (3):
kvm: encapsulate HAS_DEVICE for vm attrs s390x/kvm: make use of generic vm attribute check s390x/ipl: remove dead code
Frank Blaschka (1):
s390x/pci: fix length in sei_nt2 event
Thomas Huth (1):
s390x/virtio-bus: Remove unused function s390_virtio_bus_console()
Tony Krowiak (1):
s390x: CPACF: Handle key wrap machine options
hw/s390x/ipl.c | 3 -- hw/s390x/s390-pci-bus.c | 1 + hw/s390x/s390-virtio-bus.c | 5 --- hw/s390x/s390-virtio-bus.h | 1 - hw/s390x/s390-virtio-ccw.c | 63 +++++++++++++++++++++++++++++++ include/sysemu/kvm.h | 12 ++++++ kvm-all.c | 21 +++++++++++ qemu-options.hx | 12 +++++- target-s390x/kvm.c | 93 +++++++++++++++++++++++++++++----------------- 9 files changed, 166 insertions(+), 45 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/6 kvm: encapsulate HAS_DEVICE for vm attrs
From: Dominik Dingel <[email protected]>
More and more virtual machine specifics between kvm and qemu will be transferred with vm attributes.
So we encapsulate the common logic in a generic function.
Additionally we need only to check during initialization if kvm supports virtual machine attributes.
--- include/sysemu/kvm.h | 12 ++++++++++++ kvm-all.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/sysemu/kvm.h +12 -0
@@ -225,6 +225,18 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...);int kvm_device_ioctl (int fd,int type, ...);/** +* kvm_vm_check_attr - check for existence of a specific vm attribute +* @s: The KVMState pointer +* @group: the group +* @attr: the attribute of that group to query for +* +* Returns: 1 if the attribute exists +* 0 if the attribute either does not exist or if the vm device +* interface is unavailable +*/ +int kvm_vm_check_attr (KVMState *s,uint32_t group,uint64_t attr); + +/** * kvm_create_device - create a KVM device for the device control API * @KVMState: The KVMState pointer * @type: The KVM device type (see Documentation/virtual/kvm/devices in the
kvm-all.c +21 -0
@@ -126,6 +126,7 @@ bool kvm_gsi_routing_allowed;bool kvm_gsi_direct_mapping;bool kvm_allowed;bool kvm_readonly_mem_allowed; +bool kvm_vm_attributes_allowed;static const KVMCapabilityInfo kvm_required_capabilites[] = {KVM_CAP_INFO (USER_MEMORY ),
@@ -1598,6 +1599,9 @@ static int kvm_init(MachineState *ms) kvm_resamplefds_allowed = (kvm_check_extension (s,KVM_CAP_IRQFD_RESAMPLE ) >0 ); + kvm_vm_attributes_allowed = + (kvm_check_extension (s,KVM_CAP_VM_ATTRIBUTES ) >0 ); + ret =kvm_arch_init (s);if (ret <0 ) { goto err;
@@ -1936,6 +1940,23 @@ int kvm_device_ioctl(int fd, int type, ...)return ret; } +int kvm_vm_check_attr (KVMState *s,uint32_t group,uint64_t attr) +{ +int ret; +struct kvm_device_attr attribute = { + .group = group, + .attr = attr, + }; + +if (!kvm_vm_attributes_allowed) { +return 0 ; + } + + ret =kvm_vm_ioctl (s,KVM_HAS_DEVICE_ATTR , &attribute); +/* kvm returns 0 on success for HAS_DEVICE_ATTR */ +return ret ?0 :1 ; +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/6] kvm: encapsulate HAS_DEVICE for vm attrs
Quoted 79 lines · Jens Freimann
From: Dominik Dingel <[email protected]>
More and more virtual machine specifics between kvm and qemu will be transferred with vm attributes.
So we encapsulate the common logic in a generic function.Additionally we need only to check during initialization if kvm supports virtual machine attributes.
Cc Paolo Bonzini <[email protected]>Suggested-by Thomas Huth <[email protected]>Reviewed-by Thomas Huth <[email protected]>Signed-off-by Dominik Dingel <[email protected]>Signed-off-by Jens Freimann <[email protected]>--- include/sysemu/kvm.h | 12 ++++++++++++ kvm-all.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+)include/sysemu/kvm.h +12
-0@@ -225,6 +225,18 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...);int kvm_device_ioctl (int fd,int type, ...);/** +* kvm_vm_check_attr - check for existence of a specific vm attribute +* @s: The KVMState pointer +* @group: the group +* @attr: the attribute of that group to query for +* +* Returns: 1 if the attribute exists +* 0 if the attribute either does not exist or if the vm device +* interface is unavailable +*/ +int kvm_vm_check_attr (KVMState *s,uint32_t group,uint64_t attr); + +/** * kvm_create_device - create a KVM device for the device control API * @KVMState: The KVMState pointer * @type: The KVM device type (see Documentation/virtual/kvm/devices in the kvm-all.c +14
-0@@ -126,6 +126,7 @@ bool kvm_gsi_routing_allowed;bool kvm_gsi_direct_mapping;bool kvm_allowed;bool kvm_readonly_mem_allowed; +bool kvm_vm_attributes_allowed;static const KVMCapabilityInfo kvm_required_capabilites[] = {KVM_CAP_INFO (USER_MEMORY ),@@ -1598,6 +1599,9 @@ static int kvm_init(MachineState *ms) kvm_resamplefds_allowed = (kvm_check_extension (s,KVM_CAP_IRQFD_RESAMPLE ) >0 ); + kvm_vm_attributes_allowed = + (kvm_check_extension (s,KVM_CAP_VM_ATTRIBUTES ) >0 ); + ret =kvm_arch_init (s);if (ret <0 ) { goto err;@@ -1936,6 +1940,23 @@ int kvm_device_ioctl(int fd, int type, ...)return ret; } +int kvm_vm_check_attr (KVMState *s,uint32_t group,uint64_t attr) +{ +int ret; +struct kvm_device_attr attribute = { + .group = group, + .attr = attr, + }; + +if (!kvm_vm_attributes_allowed) { +return 0 ;
kvm-all.c int kvm_device_ioctl(int fd, int type, ...) · line 1962
Quoted 10 lines
kvm-all.c +7
-0+ } + + ret =kvm_vm_ioctl (s,KVM_HAS_DEVICE_ATTR , &attribute); +/* kvm returns 0 on success for HAS_DEVICE_ATTR */ +return ret ?0 :1 ; +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );
PATCH 2/6 s390x/kvm: make use of generic vm attribute check
In reply to Jens FreimannFrom: Dominik Dingel <[email protected]>
By using the new introduced generic interface we can remove redundancies and clean up.
--- target-s390x/kvm.c | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-)
target-s390x/kvm.c +7 -35
@@ -55,6 +55,9 @@ do { } while (0)#endif +#define kvm_vm_check_mem_attr (s, attr) \ + kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr) +#define IPA0_DIAG 0x8300#define IPA0_SIGP 0xae00#define IPA0_B2 0xb200
@@ -122,16 +125,6 @@ static int cap_async_pf;static void *legacy_s390_alloc (size_t size,uint64_t *align); -static int kvm_s390_supports_mem_limit (KVMState *s) -{ -struct kvm_device_attr attr = { - .group =KVM_S390_VM_MEM_CTRL , - .attr =KVM_S390_VM_MEM_LIMIT_SIZE , - }; - -return (kvm_vm_ioctl (s,KVM_HAS_DEVICE_ATTR , &attr) ==0 ); -} -static int kvm_s390_query_mem_limit (KVMState *s,uint64_t *memory_limit) {struct kvm_device_attr attr = {
@@ -153,7 +146,7 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit) .addr = (uint64_t) &new_limit, }; -if (!kvm_s390_supports_mem_limit (s)) { +if (!kvm_vm_check_mem_attr (s,KVM_S390_VM_MEM_LIMIT_SIZE )) {return 0 ; }
@@ -167,26 +160,6 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)return kvm_vm_ioctl (s,KVM_SET_DEVICE_ATTR , &attr); } -static int kvm_s390_check_clear_cmma (KVMState *s) -{ -struct kvm_device_attr attr = { - .group =KVM_S390_VM_MEM_CTRL , - .attr =KVM_S390_VM_MEM_CLR_CMMA , - }; - -return kvm_vm_ioctl (s,KVM_HAS_DEVICE_ATTR , &attr); -} - -static int kvm_s390_check_enable_cmma (KVMState *s) -{ -struct kvm_device_attr attr = { - .group =KVM_S390_VM_MEM_CTRL , - .attr =KVM_S390_VM_MEM_ENABLE_CMMA , - }; - -return kvm_vm_ioctl (s,KVM_HAS_DEVICE_ATTR , &attr); -} -void kvm_s390_clear_cmma_callback (void *opaque) {int rc;
@@ -208,7 +181,8 @@ static void kvm_s390_enable_cmma(KVMState *s) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (kvm_s390_check_enable_cmma (s) ||kvm_s390_check_clear_cmma (s)) { +if (!kvm_vm_check_mem_attr (s,KVM_S390_VM_MEM_ENABLE_CMMA ) || + !kvm_vm_check_mem_attr (s,KVM_S390_VM_MEM_CLR_CMMA )) {return ; }
@@ -224,9 +198,7 @@ int kvm_arch_init(KVMState *s) cap_sync_regs =kvm_check_extension (s,KVM_CAP_SYNC_REGS ); cap_async_pf =kvm_check_extension (s,KVM_CAP_ASYNC_PF ); -if (kvm_check_extension (s,KVM_CAP_VM_ATTRIBUTES )) { -kvm_s390_enable_cmma (s); - } +kvm_s390_enable_cmma (s);if (!kvm_check_extension (s,KVM_CAP_S390_GMAP ) || !kvm_check_extension (s,KVM_CAP_S390_COW )) {
Signature · 1 line
2.1.4
PATCH 3/6 s390x: CPACF: Handle key wrap machine options
In reply to Jens FreimannFrom: Tony Krowiak <[email protected]>
Check for the aes_key_wrap and dea_key_wrap machine options and set the appropriate KVM device attribute(s) to tell the kernel to enable or disable the AES/DEA protected key functions for the guest domain.
This patch introduces two new machine options for indicating the state of AES/DEA key wrapping functions. This controls whether the guest will have access to the AES/DEA crypto functions.
aes_key_wrap="on | off" is changed to aes-key-wrap="on | off" dea_key_wrap="on | off" is changed to dea-key-wrap="on | off"
Check for the aes-key-wrap and dea-key-wrap machine options and set the appropriate KVM device attribute(s) to tell the kernel to enable or disable the AES/DEA protected key functions for the guest domain.
--- hw/s390x/s390-virtio-ccw.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 12 ++++++++- target-s390x/kvm.c | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +63 -0
@@ -22,6 +22,18 @@#define TYPE_S390_CCW_MACHINE "s390-ccw-machine" +#define S390_CCW_MACHINE (obj) \ + OBJECT_CHECK(S390CcwMachineState, (obj), TYPE_S390_CCW_MACHINE) + +typedef struct S390CcwMachineState { +/*< private >*/ +MachineState parent_obj; + +/*< public >*/ +bool aes_key_wrap; +bool dea_key_wrap; +}S390CcwMachineState ; +void io_subsystem_reset (void ) {DeviceState *css, *sclp, *flic;
@@ -207,9 +219,60 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) nc->nmi_monitor_handler = s390_nmi; } +static inline bool machine_get_aes_key_wrap (Object *obj,Error **errp) +{ +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + +return ms->aes_key_wrap; +} + +static inline void machine_set_aes_key_wrap (Object *obj,bool value, +Error **errp) +{ +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + + ms->aes_key_wrap = value; +} + +static inline bool machine_get_dea_key_wrap (Object *obj,Error **errp) +{ +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + +return ms->dea_key_wrap; +} + +static inline void machine_set_dea_key_wrap (Object *obj,bool value, +Error **errp) +{ +S390CcwMachineState *ms =S390_CCW_MACHINE (obj); + + ms->dea_key_wrap = value; +} + +static inline void s390_machine_initfn (Object *obj) +{ +object_property_add_bool (obj,"aes-key-wrap" , + machine_get_aes_key_wrap, + machine_set_aes_key_wrap,NULL ); +object_property_set_description (obj,"aes-key-wrap" , +"enable/disable AES key wrapping using the CPACF wrapping key" , +NULL ); +object_property_set_bool (obj, true,"aes-key-wrap" ,NULL ); + +object_property_add_bool (obj,"dea-key-wrap" , + machine_get_dea_key_wrap, + machine_set_dea_key_wrap,NULL ); +object_property_set_description (obj,"dea-key-wrap" , +"enable/disable DEA key wrapping using the CPACF wrapping key" , +NULL ); +object_property_set_bool (obj, true,"dea-key-wrap" ,NULL ); +} +static const TypeInfo ccw_machine_info = { .name =TYPE_S390_CCW_MACHINE , .parent =TYPE_MACHINE , + .instance_size =sizeof (S390CcwMachineState), + .instance_init = s390_machine_initfn, .class_init = ccw_machine_class_init, .interfaces = (InterfaceInfo []) { {TYPE_NMI },
qemu-options.hx +11 -1
@@ -37,7 +37,9 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n", + " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n" + " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" + " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n", QEMU_ARCH_ALL) STEXI @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -66,6 +68,14 @@ the host, de-duplicates identical memory pages among VMs instances (enabled by default). @item iommu=on|off Enables or disables emulated Intel IOMMU (VT-d) support. The default is off. +@item aes-key-wrap=on|off +Enables or disables AES key wrapping support on s390-ccw hosts. This feature +controls whether AES wrapping keys will be created to allow +execution of AES cryptographic functions. The default is on. +@item dea-key-wrap=on|off +Enables or disables DEA key wrapping support on s390-ccw hosts. This feature +controls whether DEA wrapping keys will be created to allow +execution of DEA cryptographic functions. The default is on. @end table ETEXI
target-s390x/kvm.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 4/6 s390x/virtio-bus: Remove unused function s390_virtio_bus_console()
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The function s390_virtio_bus_console() is completely unused and thus can be removed safely.
--- hw/s390x/s390-virtio-bus.c | 5 ----- hw/s390x/s390-virtio-bus.h | 1 - 2 files changed, 6 deletions(-)
hw/s390x/s390-virtio-bus.c +0 -5
@@ -422,11 +422,6 @@ void s390_virtio_device_update_status(VirtIOS390Device *dev)virtio_set_features (vdev, features); } -VirtIOS390Device *s390_virtio_bus_console (VirtIOS390Bus *bus) -{ -return bus->console; -} -/* Find a device by vring address */ VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus, ram_addr_t mem,
hw/s390x/s390-virtio-bus.h +0 -1
@@ -108,7 +108,6 @@ typedef struct VirtIOS390Bus {void s390_virtio_device_update_status (VirtIOS390Device *dev); -VirtIOS390Device *s390_virtio_bus_console (VirtIOS390Bus *bus);VirtIOS390Bus *s390_virtio_bus_init (ram_addr_t *ram_size); VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
Signature · 1 line
2.1.4
PATCH 5/6 s390x/ipl: remove dead code
In reply to Jens FreimannFrom: Dominik Dingel <[email protected]>
load_image_targphys already checks the max size and will return an error code. So the follow-on check will never trigger.
--- hw/s390x/ipl.c | 3 --- 1 file changed, 3 deletions(-)
hw/s390x/ipl.c +0 -3
@@ -124,9 +124,6 @@ static int s390_ipl_init(SysBusDevice *dev) bios_size =load_image_targphys (bios_filename,ZIPL_IMAGE_START ,4096 ); ipl->bios_start_addr =ZIPL_IMAGE_START ; -if (bios_size >4096 ) { -hw_error ("stage1 bootloader is > 4k\n" ); - } }g_free (bios_filename);
Signature · 1 line
2.1.4
PATCH 6/6 s390x/pci: fix length in sei_nt2 event
In reply to Jens FreimannFrom: Frank Blaschka <[email protected]>
The sei_nt2 event must contain the length of the event.
--- hw/s390x/s390-pci-bus.c | 1 + 1 file changed, 1 insertion(+)
hw/s390x/s390-pci-bus.c +1 -0
@@ -44,6 +44,7 @@ int chsc_sei_nt2_get_event(void *res)QTAILQ_REMOVE (&s->pending_sei, sei_cont, link); nt2_res->nt =2 ; nt2_res->cc = sei_cont->cc; + nt2_res->length =cpu_to_be16 (sizeof (ChscSeiNt2Res));switch (sei_cont->cc) {case 1 :/* error event */ eccdf = (PciCcdfErr *)nt2_res->ccdf;
Signature · 1 line
2.1.4
On Thu, Mar 12, 2015 at 01:53:48PM +0100, Jens Freimann wrote:
Sorry, please ignore the PREVIEW in the subject which I should have removed before sending the patches.
Jens
Quoted 42 lines
Conny, Alex, Christian,
a few more s390 patches:
Patch 1: encapsulates the
HAS_DEVICEcheck into a generic function Patch 2: use the function introduced in Patch 1
Patch 3: introduces two new machine options for indicating the state of
AES/DEA key wrapping functions
Patch 4 and 5: remove dead code
Patch 6: fill in length forsei_nt2eventregards
JensDominik Dingel (3):
kvm: encapsulateHAS_DEVICEfor vm attrs s390x/kvm: make use of generic vm attribute check s390x/ipl: remove dead codeFrank Blaschka (1):
s390x/pci: fix length insei_nt2eventThomas Huth (1):
s390x/virtio-bus: Remove unused functions390_virtio_bus_console()Tony Krowiak (1):
s390x: CPACF: Handle key wrap machine optionshw/s390x/ipl.c | 3 -- hw/s390x/s390-pci-bus.c | 1 + hw/s390x/s390-virtio-bus.c | 5 --- hw/s390x/s390-virtio-bus.h | 1 - hw/s390x/s390-virtio-ccw.c | 63 +++++++++++++++++++++++++++++++ include/sysemu/kvm.h | 12 ++++++ kvm-all.c | 21 +++++++++++ qemu-options.hx | 12 +++++- target-s390x/kvm.c | 93 +++++++++++++++++++++++++++++----------------- 9 files changed, 166 insertions(+), 45 deletions(-)Signature · 1 line
2.1.4
Cornelia Huck
AppliedQuoted 28 lines · On Thu, 12 Mar 2015 13:53:48 +0100 Jens Freimann <[email protected]>…
Conny, Alex, Christian,
a few more s390 patches:
Patch 1: encapsulates the
HAS_DEVICEcheck into a generic function Patch 2: use the function introduced in Patch 1
Patch 3: introduces two new machine options for indicating the state of
AES/DEA key wrapping functions
Patch 4 and 5: remove dead code
Patch 6: fill in length forsei_nt2eventregards
JensDominik Dingel (3):
kvm: encapsulateHAS_DEVICEfor vm attrs s390x/kvm: make use of generic vm attribute check s390x/ipl: remove dead codeFrank Blaschka (1):
s390x/pci: fix length insei_nt2eventThomas Huth (1):
s390x/virtio-bus: Remove unused functions390_virtio_bus_console()Tony Krowiak (1):
s390x: CPACF: Handle key wrap machine options
Quoted 11 lines
hw/s390x/ipl.c | 3 -- hw/s390x/s390-pci-bus.c | 1 + hw/s390x/s390-virtio-bus.c | 5 --- hw/s390x/s390-virtio-bus.h | 1 - hw/s390x/s390-virtio-ccw.c | 63 +++++++++++++++++++++++++++++++ include/sysemu/kvm.h | 12 ++++++ kvm-all.c | 21 +++++++++++ qemu-options.hx | 12 +++++- target-s390x/kvm.c | 93 +++++++++++++++++++++++++++++----------------- 9 files changed, 166 insertions(+), 45 deletions(-)
FWIW, there were some trivial conflicts with the machine state stuff, which I fixed up.
Applied to my s390-next branch.