xref: /openbmc/linux/Documentation/virt/kvm/arm/pvtime.rst (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
16a745848SSteven Price.. SPDX-License-Identifier: GPL-2.0
26a745848SSteven Price
36a745848SSteven PriceParavirtualized time support for arm64
46a745848SSteven Price======================================
56a745848SSteven Price
66a745848SSteven PriceArm specification DEN0057/A defines a standard for paravirtualised time
76a745848SSteven Pricesupport for AArch64 guests:
86a745848SSteven Price
96a745848SSteven Pricehttps://developer.arm.com/docs/den0057/a
106a745848SSteven Price
116a745848SSteven PriceKVM/arm64 implements the stolen time part of this specification by providing
126a745848SSteven Pricesome hypervisor service calls to support a paravirtualized guest obtaining a
136a745848SSteven Priceview of the amount of time stolen from its execution.
146a745848SSteven Price
156a745848SSteven PriceTwo new SMCCC compatible hypercalls are defined:
166a745848SSteven Price
176a745848SSteven Price* PV_TIME_FEATURES: 0xC5000020
186a745848SSteven Price* PV_TIME_ST:       0xC5000021
196a745848SSteven Price
206a745848SSteven PriceThese are only available in the SMC64/HVC64 calling convention as
216a745848SSteven Priceparavirtualized time is not available to 32 bit Arm guests. The existence of
2294558543SKeqian Zhuthe PV_TIME_FEATURES hypercall should be probed using the SMCCC 1.1
2394558543SKeqian ZhuARCH_FEATURES mechanism before calling it.
246a745848SSteven Price
256a745848SSteven PricePV_TIME_FEATURES
26*83f8a81dSUsama Arif
27*83f8a81dSUsama Arif    ============= ========    =================================================
286a745848SSteven Price    Function ID:  (uint32)    0xC5000020
296a745848SSteven Price    PV_call_id:   (uint32)    The function to query for support.
306a745848SSteven Price                              Currently only PV_TIME_ST is supported.
316a745848SSteven Price    Return value: (int64)     NOT_SUPPORTED (-1) or SUCCESS (0) if the relevant
326a745848SSteven Price                              PV-time feature is supported by the hypervisor.
33*83f8a81dSUsama Arif    ============= ========    =================================================
346a745848SSteven Price
356a745848SSteven PricePV_TIME_ST
36*83f8a81dSUsama Arif
37*83f8a81dSUsama Arif    ============= ========    ==============================================
386a745848SSteven Price    Function ID:  (uint32)    0xC5000021
396a745848SSteven Price    Return value: (int64)     IPA of the stolen time data structure for this
406a745848SSteven Price                              VCPU. On failure:
416a745848SSteven Price                              NOT_SUPPORTED (-1)
42*83f8a81dSUsama Arif    ============= ========    ==============================================
436a745848SSteven Price
446a745848SSteven PriceThe IPA returned by PV_TIME_ST should be mapped by the guest as normal memory
456a745848SSteven Pricewith inner and outer write back caching attributes, in the inner shareable
466a745848SSteven Pricedomain. A total of 16 bytes from the IPA returned are guaranteed to be
476a745848SSteven Pricemeaningfully filled by the hypervisor (see structure below).
486a745848SSteven Price
496a745848SSteven PricePV_TIME_ST returns the structure for the calling VCPU.
506a745848SSteven Price
516a745848SSteven PriceStolen Time
526a745848SSteven Price-----------
536a745848SSteven Price
546a745848SSteven PriceThe structure pointed to by the PV_TIME_ST hypercall is as follows:
556a745848SSteven Price
566a745848SSteven Price+-------------+-------------+-------------+----------------------------+
576a745848SSteven Price| Field       | Byte Length | Byte Offset | Description                |
586a745848SSteven Price+=============+=============+=============+============================+
596a745848SSteven Price| Revision    |      4      |      0      | Must be 0 for version 1.0  |
606a745848SSteven Price+-------------+-------------+-------------+----------------------------+
616a745848SSteven Price| Attributes  |      4      |      4      | Must be 0                  |
626a745848SSteven Price+-------------+-------------+-------------+----------------------------+
636a745848SSteven Price| Stolen time |      8      |      8      | Stolen time in unsigned    |
646a745848SSteven Price|             |             |             | nanoseconds indicating how |
656a745848SSteven Price|             |             |             | much time this VCPU thread |
666a745848SSteven Price|             |             |             | was involuntarily not      |
676a745848SSteven Price|             |             |             | running on a physical CPU. |
686a745848SSteven Price+-------------+-------------+-------------+----------------------------+
696a745848SSteven Price
706a745848SSteven PriceAll values in the structure are stored little-endian.
716a745848SSteven Price
726a745848SSteven PriceThe structure will be updated by the hypervisor prior to scheduling a VCPU. It
736a745848SSteven Pricewill be present within a reserved region of the normal memory given to the
746a745848SSteven Priceguest. The guest should not attempt to write into this memory. There is a
756a745848SSteven Pricestructure per VCPU of the guest.
766a745848SSteven Price
776a745848SSteven PriceIt is advisable that one or more 64k pages are set aside for the purpose of
786a745848SSteven Pricethese structures and not used for other purposes, this enables the guest to map
796a745848SSteven Pricethe region using 64k pages and avoids conflicting attributes with other memory.
806a745848SSteven Price
81*83f8a81dSUsama ArifFor the user space interface see
82*83f8a81dSUsama Arif:ref:`Documentation/virt/kvm/devices/vcpu.rst <kvm_arm_vcpu_pvtime_ctrl>`.