162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci============================= 462306a36Sopenharmony_ciThe s390 DIAGNOSE call on KVM 562306a36Sopenharmony_ci============================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciKVM on s390 supports the DIAGNOSE call for making hypercalls, both for 862306a36Sopenharmony_cinative hypercalls and for selected hypercalls found on other s390 962306a36Sopenharmony_cihypervisors. 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciNote that bits are numbered as by the usual s390 convention (most significant 1262306a36Sopenharmony_cibit on the left). 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciGeneral remarks 1662306a36Sopenharmony_ci--------------- 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciDIAGNOSE calls by the guest cause a mandatory intercept. This implies 1962306a36Sopenharmony_ciall supported DIAGNOSE calls need to be handled by either KVM or its 2062306a36Sopenharmony_ciuserspace. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciAll DIAGNOSE calls supported by KVM use the RS-a format:: 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci -------------------------------------- 2562306a36Sopenharmony_ci | '83' | R1 | R3 | B2 | D2 | 2662306a36Sopenharmony_ci -------------------------------------- 2762306a36Sopenharmony_ci 0 8 12 16 20 31 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciThe second-operand address (obtained by the base/displacement calculation) 3062306a36Sopenharmony_ciis not used to address data. Instead, bits 48-63 of this address specify 3162306a36Sopenharmony_cithe function code, and bits 0-47 are ignored. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciThe supported DIAGNOSE function codes vary by the userspace used. For 3462306a36Sopenharmony_ciDIAGNOSE function codes not specific to KVM, please refer to the 3562306a36Sopenharmony_cidocumentation for the s390 hypervisors defining them. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciDIAGNOSE function code 'X'500' - KVM virtio functions 3962306a36Sopenharmony_ci----------------------------------------------------- 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciIf the function code specifies 0x500, various virtio-related functions 4262306a36Sopenharmony_ciare performed. 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciGeneral register 1 contains the virtio subfunction code. Supported 4562306a36Sopenharmony_civirtio subfunctions depend on KVM's userspace. Generally, userspace 4662306a36Sopenharmony_ciprovides either s390-virtio (subcodes 0-2) or virtio-ccw (subcode 3). 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciUpon completion of the DIAGNOSE instruction, general register 2 contains 4962306a36Sopenharmony_cithe function's return code, which is either a return code or a subcode 5062306a36Sopenharmony_cispecific value. 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciSubcode 0 - s390-virtio notification and early console printk 5362306a36Sopenharmony_ci Handled by userspace. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciSubcode 1 - s390-virtio reset 5662306a36Sopenharmony_ci Handled by userspace. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciSubcode 2 - s390-virtio set status 5962306a36Sopenharmony_ci Handled by userspace. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciSubcode 3 - virtio-ccw notification 6262306a36Sopenharmony_ci Handled by either userspace or KVM (ioeventfd case). 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci General register 2 contains a subchannel-identification word denoting 6562306a36Sopenharmony_ci the subchannel of the virtio-ccw proxy device to be notified. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci General register 3 contains the number of the virtqueue to be notified. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci General register 4 contains a 64bit identifier for KVM usage (the 7062306a36Sopenharmony_ci kvm_io_bus cookie). If general register 4 does not contain a valid 7162306a36Sopenharmony_ci identifier, it is ignored. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci After completion of the DIAGNOSE call, general register 2 may contain 7462306a36Sopenharmony_ci a 64bit identifier (in the kvm_io_bus cookie case), or a negative 7562306a36Sopenharmony_ci error value, if an internal error occurred. 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci See also the virtio standard for a discussion of this hypercall. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciDIAGNOSE function code 'X'501 - KVM breakpoint 8162306a36Sopenharmony_ci---------------------------------------------- 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciIf the function code specifies 0x501, breakpoint functions may be performed. 8462306a36Sopenharmony_ciThis function code is handled by userspace. 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciThis diagnose function code has no subfunctions and uses no parameters. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciDIAGNOSE function code 'X'9C - Voluntary Time Slice Yield 9062306a36Sopenharmony_ci--------------------------------------------------------- 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciGeneral register 1 contains the target CPU address. 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ciIn a guest of a hypervisor like LPAR, KVM or z/VM using shared host CPUs, 9562306a36Sopenharmony_ciDIAGNOSE with function code 0x9c may improve system performance by 9662306a36Sopenharmony_ciyielding the host CPU on which the guest CPU is running to be assigned 9762306a36Sopenharmony_cito another guest CPU, preferably the logical CPU containing the specified 9862306a36Sopenharmony_citarget CPU. 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciDIAG 'X'9C forwarding 10262306a36Sopenharmony_ci+++++++++++++++++++++ 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciThe guest may send a DIAGNOSE 0x9c in order to yield to a certain 10562306a36Sopenharmony_ciother vcpu. An example is a Linux guest that tries to yield to the vcpu 10662306a36Sopenharmony_cithat is currently holding a spinlock, but not running. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciHowever, on the host the real cpu backing the vcpu may itself not be 10962306a36Sopenharmony_cirunning. 11062306a36Sopenharmony_ciForwarding the DIAGNOSE 0x9c initially sent by the guest to yield to 11162306a36Sopenharmony_cithe backing cpu will hopefully cause that cpu, and thus subsequently 11262306a36Sopenharmony_cithe guest's vcpu, to be scheduled. 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cidiag9c_forwarding_hz 11662306a36Sopenharmony_ci KVM kernel parameter allowing to specify the maximum number of DIAGNOSE 11762306a36Sopenharmony_ci 0x9c forwarding per second in the purpose of avoiding a DIAGNOSE 0x9c 11862306a36Sopenharmony_ci forwarding storm. 11962306a36Sopenharmony_ci A value of 0 turns the forwarding off. 120