Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: s390: Add CPU dump functionality

The previous patch introduced the per-VM dump functions now let's
focus on dumping the VCPU state via the newly introduced
KVM_S390_PV_CPU_COMMAND ioctl which mirrors the VM UV ioctl and can be
extended with new commands later.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20220517163629.3443-8-frankja@linux.ibm.com
Message-Id: <20220517163629.3443-8-frankja@linux.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>

authored by

Janosch Frank and committed by
Christian Borntraeger
8aba0958 0460eb35

+90
+69
arch/s390/kvm/kvm-s390.c
··· 5096 5096 return -ENOIOCTLCMD; 5097 5097 } 5098 5098 5099 + static int kvm_s390_handle_pv_vcpu_dump(struct kvm_vcpu *vcpu, 5100 + struct kvm_pv_cmd *cmd) 5101 + { 5102 + struct kvm_s390_pv_dmp dmp; 5103 + void *data; 5104 + int ret; 5105 + 5106 + /* Dump initialization is a prerequisite */ 5107 + if (!vcpu->kvm->arch.pv.dumping) 5108 + return -EINVAL; 5109 + 5110 + if (copy_from_user(&dmp, (__u8 __user *)cmd->data, sizeof(dmp))) 5111 + return -EFAULT; 5112 + 5113 + /* We only handle this subcmd right now */ 5114 + if (dmp.subcmd != KVM_PV_DUMP_CPU) 5115 + return -EINVAL; 5116 + 5117 + /* CPU dump length is the same as create cpu storage donation. */ 5118 + if (dmp.buff_len != uv_info.guest_cpu_stor_len) 5119 + return -EINVAL; 5120 + 5121 + data = kvzalloc(uv_info.guest_cpu_stor_len, GFP_KERNEL); 5122 + if (!data) 5123 + return -ENOMEM; 5124 + 5125 + ret = kvm_s390_pv_dump_cpu(vcpu, data, &cmd->rc, &cmd->rrc); 5126 + 5127 + VCPU_EVENT(vcpu, 3, "PROTVIRT DUMP CPU %d rc %x rrc %x", 5128 + vcpu->vcpu_id, cmd->rc, cmd->rrc); 5129 + 5130 + if (ret) 5131 + ret = -EINVAL; 5132 + 5133 + /* On success copy over the dump data */ 5134 + if (!ret && copy_to_user((__u8 __user *)dmp.buff_addr, data, uv_info.guest_cpu_stor_len)) 5135 + ret = -EFAULT; 5136 + 5137 + kvfree(data); 5138 + return ret; 5139 + } 5140 + 5099 5141 long kvm_arch_vcpu_ioctl(struct file *filp, 5100 5142 unsigned int ioctl, unsigned long arg) 5101 5143 { ··· 5300 5258 r = kvm_s390_get_irq_state(vcpu, 5301 5259 (__u8 __user *) irq_state.buf, 5302 5260 irq_state.len); 5261 + break; 5262 + } 5263 + case KVM_S390_PV_CPU_COMMAND: { 5264 + struct kvm_pv_cmd cmd; 5265 + 5266 + r = -EINVAL; 5267 + if (!is_prot_virt_host()) 5268 + break; 5269 + 5270 + r = -EFAULT; 5271 + if (copy_from_user(&cmd, argp, sizeof(cmd))) 5272 + break; 5273 + 5274 + r = -EINVAL; 5275 + if (cmd.flags) 5276 + break; 5277 + 5278 + /* We only handle this cmd right now */ 5279 + if (cmd.cmd != KVM_PV_DUMP) 5280 + break; 5281 + 5282 + r = kvm_s390_handle_pv_vcpu_dump(vcpu, &cmd); 5283 + 5284 + /* Always copy over UV rc / rrc data */ 5285 + if (copy_to_user((__u8 __user *)argp, &cmd.rc, 5286 + sizeof(cmd.rc) + sizeof(cmd.rrc))) 5287 + r = -EFAULT; 5303 5288 break; 5304 5289 } 5305 5290 default:
+1
arch/s390/kvm/kvm-s390.h
··· 250 250 int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, 251 251 unsigned long tweak, u16 *rc, u16 *rrc); 252 252 int kvm_s390_pv_set_cpu_state(struct kvm_vcpu *vcpu, u8 state); 253 + int kvm_s390_pv_dump_cpu(struct kvm_vcpu *vcpu, void *buff, u16 *rc, u16 *rrc); 253 254 int kvm_s390_pv_dump_stor_state(struct kvm *kvm, void __user *buff_user, 254 255 u64 *gaddr, u64 buff_user_len, u16 *rc, u16 *rrc); 255 256 int kvm_s390_pv_dump_complete(struct kvm *kvm, void __user *buff_user,
+16
arch/s390/kvm/pv.c
··· 300 300 return 0; 301 301 } 302 302 303 + int kvm_s390_pv_dump_cpu(struct kvm_vcpu *vcpu, void *buff, u16 *rc, u16 *rrc) 304 + { 305 + struct uv_cb_dump_cpu uvcb = { 306 + .header.cmd = UVC_CMD_DUMP_CPU, 307 + .header.len = sizeof(uvcb), 308 + .cpu_handle = vcpu->arch.pv.handle, 309 + .dump_area_origin = (u64)buff, 310 + }; 311 + int cc; 312 + 313 + cc = uv_call_sched(0, (u64)&uvcb); 314 + *rc = uvcb.header.rc; 315 + *rrc = uvcb.header.rrc; 316 + return cc; 317 + } 318 + 303 319 /* Size of the cache for the storage state dump data. 1MB for now */ 304 320 #define DUMP_BUFF_LEN HPAGE_SIZE 305 321
+4
include/uapi/linux/kvm.h
··· 1664 1664 KVM_PV_DUMP_INIT, 1665 1665 KVM_PV_DUMP_CONFIG_STOR_STATE, 1666 1666 KVM_PV_DUMP_COMPLETE, 1667 + KVM_PV_DUMP_CPU, 1667 1668 }; 1668 1669 1669 1670 struct kvm_s390_pv_dmp { ··· 2168 2167 2169 2168 /* Available with KVM_CAP_XSAVE2 */ 2170 2169 #define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave) 2170 + 2171 + /* Available with KVM_CAP_S390_PROTECTED_DUMP */ 2172 + #define KVM_S390_PV_CPU_COMMAND _IOWR(KVMIO, 0xd0, struct kvm_pv_cmd) 2171 2173 2172 2174 #endif /* __LINUX_KVM_H */