162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci====================
462306a36Sopenharmony_ciGeneric vm interface
562306a36Sopenharmony_ci====================
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciThe virtual machine "device" also accepts the ioctls KVM_SET_DEVICE_ATTR,
862306a36Sopenharmony_ciKVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same
962306a36Sopenharmony_cistruct kvm_device_attr as other devices, but targets VM-wide settings
1062306a36Sopenharmony_ciand controls.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciThe groups and attributes per virtual machine, if any, are architecture
1362306a36Sopenharmony_cispecific.
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci1. GROUP: KVM_S390_VM_MEM_CTRL
1662306a36Sopenharmony_ci==============================
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci:Architectures: s390
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci1.1. ATTRIBUTE: KVM_S390_VM_MEM_ENABLE_CMMA
2162306a36Sopenharmony_ci-------------------------------------------
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci:Parameters: none
2462306a36Sopenharmony_ci:Returns: -EBUSY if a vcpu is already defined, otherwise 0
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciEnables Collaborative Memory Management Assist (CMMA) for the virtual machine.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci1.2. ATTRIBUTE: KVM_S390_VM_MEM_CLR_CMMA
2962306a36Sopenharmony_ci----------------------------------------
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci:Parameters: none
3262306a36Sopenharmony_ci:Returns: -EINVAL if CMMA was not enabled;
3362306a36Sopenharmony_ci	  0 otherwise
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciClear the CMMA status for all guest pages, so any pages the guest marked
3662306a36Sopenharmony_cias unused are again used any may not be reclaimed by the host.
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci1.3. ATTRIBUTE KVM_S390_VM_MEM_LIMIT_SIZE
3962306a36Sopenharmony_ci-----------------------------------------
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci:Parameters: in attr->addr the address for the new limit of guest memory
4262306a36Sopenharmony_ci:Returns: -EFAULT if the given address is not accessible;
4362306a36Sopenharmony_ci	  -EINVAL if the virtual machine is of type UCONTROL;
4462306a36Sopenharmony_ci	  -E2BIG if the given guest memory is to big for that machine;
4562306a36Sopenharmony_ci	  -EBUSY if a vcpu is already defined;
4662306a36Sopenharmony_ci	  -ENOMEM if not enough memory is available for a new shadow guest mapping;
4762306a36Sopenharmony_ci	  0 otherwise.
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ciAllows userspace to query the actual limit and set a new limit for
5062306a36Sopenharmony_cithe maximum guest memory size. The limit will be rounded up to
5162306a36Sopenharmony_ci2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by
5262306a36Sopenharmony_cithe number of page table levels. In the case that there is no limit we will set
5362306a36Sopenharmony_cithe limit to KVM_S390_NO_MEM_LIMIT (U64_MAX).
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci2. GROUP: KVM_S390_VM_CPU_MODEL
5662306a36Sopenharmony_ci===============================
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci:Architectures: s390
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o)
6162306a36Sopenharmony_ci---------------------------------------------
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciAllows user space to retrieve machine and kvm specific cpu related information::
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci  struct kvm_s390_vm_cpu_machine {
6662306a36Sopenharmony_ci       __u64 cpuid;           # CPUID of host
6762306a36Sopenharmony_ci       __u32 ibc;             # IBC level range offered by host
6862306a36Sopenharmony_ci       __u8  pad[4];
6962306a36Sopenharmony_ci       __u64 fac_mask[256];   # set of cpu facilities enabled by KVM
7062306a36Sopenharmony_ci       __u64 fac_list[256];   # set of cpu facilities offered by host
7162306a36Sopenharmony_ci  }
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci:Parameters: address of buffer to store the machine related cpu data
7462306a36Sopenharmony_ci	     of type struct kvm_s390_vm_cpu_machine*
7562306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
7662306a36Sopenharmony_ci	    -ENOMEM if not enough memory is available to process the ioctl;
7762306a36Sopenharmony_ci	    0 in case of success.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w)
8062306a36Sopenharmony_ci===============================================
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciAllows user space to retrieve or request to change cpu related information for a vcpu::
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci  struct kvm_s390_vm_cpu_processor {
8562306a36Sopenharmony_ci       __u64 cpuid;           # CPUID currently (to be) used by this vcpu
8662306a36Sopenharmony_ci       __u16 ibc;             # IBC level currently (to be) used by this vcpu
8762306a36Sopenharmony_ci       __u8  pad[6];
8862306a36Sopenharmony_ci       __u64 fac_list[256];   # set of cpu facilities currently (to be) used
8962306a36Sopenharmony_ci			      # by this vcpu
9062306a36Sopenharmony_ci  }
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciKVM does not enforce or limit the cpu model data in any form. Take the information
9362306a36Sopenharmony_ciretrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration
9462306a36Sopenharmony_cisetups. Instruction interceptions triggered by additionally set facility bits that
9562306a36Sopenharmony_ciare not handled by KVM need to by implemented in the VM driver code.
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci:Parameters: address of buffer to store/set the processor related cpu
9862306a36Sopenharmony_ci	     data of type struct kvm_s390_vm_cpu_processor*.
9962306a36Sopenharmony_ci:Returns:  -EBUSY in case 1 or more vcpus are already activated (only in write case);
10062306a36Sopenharmony_ci	   -EFAULT if the given address is not accessible from kernel space;
10162306a36Sopenharmony_ci	   -ENOMEM if not enough memory is available to process the ioctl;
10262306a36Sopenharmony_ci	   0 in case of success.
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci.. _KVM_S390_VM_CPU_MACHINE_FEAT:
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci2.3. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_FEAT (r/o)
10762306a36Sopenharmony_ci--------------------------------------------------
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ciAllows user space to retrieve available cpu features. A feature is available if
11062306a36Sopenharmony_ciprovided by the hardware and supported by kvm. In theory, cpu features could
11162306a36Sopenharmony_cieven be completely emulated by kvm.
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci::
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci  struct kvm_s390_vm_cpu_feat {
11662306a36Sopenharmony_ci	__u64 feat[16]; # Bitmap (1 = feature available), MSB 0 bit numbering
11762306a36Sopenharmony_ci  };
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci:Parameters: address of a buffer to load the feature list from.
12062306a36Sopenharmony_ci:Returns:  -EFAULT if the given address is not accessible from kernel space;
12162306a36Sopenharmony_ci	   0 in case of success.
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci2.4. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_FEAT (r/w)
12462306a36Sopenharmony_ci----------------------------------------------------
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciAllows user space to retrieve or change enabled cpu features for all VCPUs of a
12762306a36Sopenharmony_ciVM. Features that are not available cannot be enabled.
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciSee :ref:`KVM_S390_VM_CPU_MACHINE_FEAT` for
13062306a36Sopenharmony_cia description of the parameter struct.
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci:Parameters: address of a buffer to store/load the feature list from.
13362306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
13462306a36Sopenharmony_ci	    -EINVAL if a cpu feature that is not available is to be enabled;
13562306a36Sopenharmony_ci	    -EBUSY if at least one VCPU has already been defined;
13662306a36Sopenharmony_ci	    0 in case of success.
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci.. _KVM_S390_VM_CPU_MACHINE_SUBFUNC:
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci2.5. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_SUBFUNC (r/o)
14162306a36Sopenharmony_ci-----------------------------------------------------
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciAllows user space to retrieve available cpu subfunctions without any filtering
14462306a36Sopenharmony_cidone by a set IBC. These subfunctions are indicated to the guest VCPU via
14562306a36Sopenharmony_ciquery or "test bit" subfunctions and used e.g. by cpacf functions, plo and ptff.
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ciA subfunction block is only valid if KVM_S390_VM_CPU_MACHINE contains the
14862306a36Sopenharmony_ciSTFL(E) bit introducing the affected instruction. If the affected instruction
14962306a36Sopenharmony_ciindicates subfunctions via a "query subfunction", the response block is
15062306a36Sopenharmony_cicontained in the returned struct. If the affected instruction
15162306a36Sopenharmony_ciindicates subfunctions via a "test bit" mechanism, the subfunction codes are
15262306a36Sopenharmony_cicontained in the returned struct in MSB 0 bit numbering.
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci::
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci  struct kvm_s390_vm_cpu_subfunc {
15762306a36Sopenharmony_ci       u8 plo[32];           # always valid (ESA/390 feature)
15862306a36Sopenharmony_ci       u8 ptff[16];          # valid with TOD-clock steering
15962306a36Sopenharmony_ci       u8 kmac[16];          # valid with Message-Security-Assist
16062306a36Sopenharmony_ci       u8 kmc[16];           # valid with Message-Security-Assist
16162306a36Sopenharmony_ci       u8 km[16];            # valid with Message-Security-Assist
16262306a36Sopenharmony_ci       u8 kimd[16];          # valid with Message-Security-Assist
16362306a36Sopenharmony_ci       u8 klmd[16];          # valid with Message-Security-Assist
16462306a36Sopenharmony_ci       u8 pckmo[16];         # valid with Message-Security-Assist-Extension 3
16562306a36Sopenharmony_ci       u8 kmctr[16];         # valid with Message-Security-Assist-Extension 4
16662306a36Sopenharmony_ci       u8 kmf[16];           # valid with Message-Security-Assist-Extension 4
16762306a36Sopenharmony_ci       u8 kmo[16];           # valid with Message-Security-Assist-Extension 4
16862306a36Sopenharmony_ci       u8 pcc[16];           # valid with Message-Security-Assist-Extension 4
16962306a36Sopenharmony_ci       u8 ppno[16];          # valid with Message-Security-Assist-Extension 5
17062306a36Sopenharmony_ci       u8 kma[16];           # valid with Message-Security-Assist-Extension 8
17162306a36Sopenharmony_ci       u8 kdsa[16];          # valid with Message-Security-Assist-Extension 9
17262306a36Sopenharmony_ci       u8 reserved[1792];    # reserved for future instructions
17362306a36Sopenharmony_ci  };
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci:Parameters: address of a buffer to load the subfunction blocks from.
17662306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
17762306a36Sopenharmony_ci	    0 in case of success.
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci2.6. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_SUBFUNC (r/w)
18062306a36Sopenharmony_ci-------------------------------------------------------
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ciAllows user space to retrieve or change cpu subfunctions to be indicated for
18362306a36Sopenharmony_ciall VCPUs of a VM. This attribute will only be available if kernel and
18462306a36Sopenharmony_cihardware support are in place.
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ciThe kernel uses the configured subfunction blocks for indication to
18762306a36Sopenharmony_cithe guest. A subfunction block will only be used if the associated STFL(E) bit
18862306a36Sopenharmony_cihas not been disabled by user space (so the instruction to be queried is
18962306a36Sopenharmony_ciactually available for the guest).
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ciAs long as no data has been written, a read will fail. The IBC will be used
19262306a36Sopenharmony_cito determine available subfunctions in this case, this will guarantee backward
19362306a36Sopenharmony_cicompatibility.
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ciSee :ref:`KVM_S390_VM_CPU_MACHINE_SUBFUNC` for a
19662306a36Sopenharmony_cidescription of the parameter struct.
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci:Parameters: address of a buffer to store/load the subfunction blocks from.
19962306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
20062306a36Sopenharmony_ci	    -EINVAL when reading, if there was no write yet;
20162306a36Sopenharmony_ci	    -EBUSY if at least one VCPU has already been defined;
20262306a36Sopenharmony_ci	    0 in case of success.
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci3. GROUP: KVM_S390_VM_TOD
20562306a36Sopenharmony_ci=========================
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci:Architectures: s390
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci3.1. ATTRIBUTE: KVM_S390_VM_TOD_HIGH
21062306a36Sopenharmony_ci------------------------------------
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ciAllows user space to set/get the TOD clock extension (u8) (superseded by
21362306a36Sopenharmony_ciKVM_S390_VM_TOD_EXT).
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci:Parameters: address of a buffer in user space to store the data (u8) to
21662306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
21762306a36Sopenharmony_ci	    -EINVAL if setting the TOD clock extension to != 0 is not supported
21862306a36Sopenharmony_ci	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci3.2. ATTRIBUTE: KVM_S390_VM_TOD_LOW
22162306a36Sopenharmony_ci-----------------------------------
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ciAllows user space to set/get bits 0-63 of the TOD clock register as defined in
22462306a36Sopenharmony_cithe POP (u64).
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci:Parameters: address of a buffer in user space to store the data (u64) to
22762306a36Sopenharmony_ci:Returns:    -EFAULT if the given address is not accessible from kernel space
22862306a36Sopenharmony_ci	     -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci3.3. ATTRIBUTE: KVM_S390_VM_TOD_EXT
23162306a36Sopenharmony_ci-----------------------------------
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ciAllows user space to set/get bits 0-63 of the TOD clock register as defined in
23462306a36Sopenharmony_cithe POP (u64). If the guest CPU model supports the TOD clock extension (u8), it
23562306a36Sopenharmony_cialso allows user space to get/set it. If the guest CPU model does not support
23662306a36Sopenharmony_ciit, it is stored as 0 and not allowed to be set to a value != 0.
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci:Parameters: address of a buffer in user space to store the data
23962306a36Sopenharmony_ci	     (kvm_s390_vm_tod_clock) to
24062306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
24162306a36Sopenharmony_ci	    -EINVAL if setting the TOD clock extension to != 0 is not supported
24262306a36Sopenharmony_ci	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci4. GROUP: KVM_S390_VM_CRYPTO
24562306a36Sopenharmony_ci============================
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci:Architectures: s390
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci4.1. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_AES_KW (w/o)
25062306a36Sopenharmony_ci------------------------------------------------------
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ciAllows user space to enable aes key wrapping, including generating a new
25362306a36Sopenharmony_ciwrapping key.
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci:Parameters: none
25662306a36Sopenharmony_ci:Returns:    0
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci4.2. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_DEA_KW (w/o)
25962306a36Sopenharmony_ci------------------------------------------------------
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ciAllows user space to enable dea key wrapping, including generating a new
26262306a36Sopenharmony_ciwrapping key.
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci:Parameters: none
26562306a36Sopenharmony_ci:Returns:    0
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci4.3. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_AES_KW (w/o)
26862306a36Sopenharmony_ci-------------------------------------------------------
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ciAllows user space to disable aes key wrapping, clearing the wrapping key.
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci:Parameters: none
27362306a36Sopenharmony_ci:Returns:    0
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci4.4. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_DEA_KW (w/o)
27662306a36Sopenharmony_ci-------------------------------------------------------
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ciAllows user space to disable dea key wrapping, clearing the wrapping key.
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci:Parameters: none
28162306a36Sopenharmony_ci:Returns:    0
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci5. GROUP: KVM_S390_VM_MIGRATION
28462306a36Sopenharmony_ci===============================
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci:Architectures: s390
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci5.1. ATTRIBUTE: KVM_S390_VM_MIGRATION_STOP (w/o)
28962306a36Sopenharmony_ci------------------------------------------------
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ciAllows userspace to stop migration mode, needed for PGSTE migration.
29262306a36Sopenharmony_ciSetting this attribute when migration mode is not active will have no
29362306a36Sopenharmony_cieffects.
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci:Parameters: none
29662306a36Sopenharmony_ci:Returns:    0
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci5.2. ATTRIBUTE: KVM_S390_VM_MIGRATION_START (w/o)
29962306a36Sopenharmony_ci-------------------------------------------------
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ciAllows userspace to start migration mode, needed for PGSTE migration.
30262306a36Sopenharmony_ciSetting this attribute when migration mode is already active will have
30362306a36Sopenharmony_cino effects.
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ciDirty tracking must be enabled on all memslots, else -EINVAL is returned. When
30662306a36Sopenharmony_cidirty tracking is disabled on any memslot, migration mode is automatically
30762306a36Sopenharmony_cistopped.
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci:Parameters: none
31062306a36Sopenharmony_ci:Returns:   -ENOMEM if there is not enough free memory to start migration mode;
31162306a36Sopenharmony_ci	    -EINVAL if the state of the VM is invalid (e.g. no memory defined);
31262306a36Sopenharmony_ci	    0 in case of success.
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_ci5.3. ATTRIBUTE: KVM_S390_VM_MIGRATION_STATUS (r/o)
31562306a36Sopenharmony_ci--------------------------------------------------
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ciAllows userspace to query the status of migration mode.
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci:Parameters: address of a buffer in user space to store the data (u64) to;
32062306a36Sopenharmony_ci	     the data itself is either 0 if migration mode is disabled or 1
32162306a36Sopenharmony_ci	     if it is enabled
32262306a36Sopenharmony_ci:Returns:   -EFAULT if the given address is not accessible from kernel space;
32362306a36Sopenharmony_ci	    0 in case of success.
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci6. GROUP: KVM_ARM_VM_SMCCC_CTRL
32662306a36Sopenharmony_ci===============================
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci:Architectures: arm64
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci6.1. ATTRIBUTE: KVM_ARM_VM_SMCCC_FILTER (w/o)
33162306a36Sopenharmony_ci---------------------------------------------
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci:Parameters: Pointer to a ``struct kvm_smccc_filter``
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_ci:Returns:
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci        ======  ===========================================
33862306a36Sopenharmony_ci        EEXIST  Range intersects with a previously inserted
33962306a36Sopenharmony_ci                or reserved range
34062306a36Sopenharmony_ci        EBUSY   A vCPU in the VM has already run
34162306a36Sopenharmony_ci        EINVAL  Invalid filter configuration
34262306a36Sopenharmony_ci        ENOMEM  Failed to allocate memory for the in-kernel
34362306a36Sopenharmony_ci                representation of the SMCCC filter
34462306a36Sopenharmony_ci        ======  ===========================================
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ciRequests the installation of an SMCCC call filter described as follows::
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci    enum kvm_smccc_filter_action {
34962306a36Sopenharmony_ci            KVM_SMCCC_FILTER_HANDLE = 0,
35062306a36Sopenharmony_ci            KVM_SMCCC_FILTER_DENY,
35162306a36Sopenharmony_ci            KVM_SMCCC_FILTER_FWD_TO_USER,
35262306a36Sopenharmony_ci    };
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci    struct kvm_smccc_filter {
35562306a36Sopenharmony_ci            __u32 base;
35662306a36Sopenharmony_ci            __u32 nr_functions;
35762306a36Sopenharmony_ci            __u8 action;
35862306a36Sopenharmony_ci            __u8 pad[15];
35962306a36Sopenharmony_ci    };
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ciThe filter is defined as a set of non-overlapping ranges. Each
36262306a36Sopenharmony_cirange defines an action to be applied to SMCCC calls within the range.
36362306a36Sopenharmony_ciUserspace can insert multiple ranges into the filter by using
36462306a36Sopenharmony_cisuccessive calls to this attribute.
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ciThe default configuration of KVM is such that all implemented SMCCC
36762306a36Sopenharmony_cicalls are allowed. Thus, the SMCCC filter can be defined sparsely
36862306a36Sopenharmony_ciby userspace, only describing ranges that modify the default behavior.
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ciThe range expressed by ``struct kvm_smccc_filter`` is
37162306a36Sopenharmony_ci[``base``, ``base + nr_functions``). The range is not allowed to wrap,
37262306a36Sopenharmony_cii.e. userspace cannot rely on ``base + nr_functions`` overflowing.
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ciThe SMCCC filter applies to both SMC and HVC calls initiated by the
37562306a36Sopenharmony_ciguest. The SMCCC filter gates the in-kernel emulation of SMCCC calls
37662306a36Sopenharmony_ciand as such takes effect before other interfaces that interact with
37762306a36Sopenharmony_ciSMCCC calls (e.g. hypercall bitmap registers).
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ciActions:
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci - ``KVM_SMCCC_FILTER_HANDLE``: Allows the guest SMCCC call to be
38262306a36Sopenharmony_ci   handled in-kernel. It is strongly recommended that userspace *not*
38362306a36Sopenharmony_ci   explicitly describe the allowed SMCCC call ranges.
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci - ``KVM_SMCCC_FILTER_DENY``: Rejects the guest SMCCC call in-kernel
38662306a36Sopenharmony_ci   and returns to the guest.
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci - ``KVM_SMCCC_FILTER_FWD_TO_USER``: The guest SMCCC call is forwarded
38962306a36Sopenharmony_ci   to userspace with an exit reason of ``KVM_EXIT_HYPERCALL``.
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ciThe ``pad`` field is reserved for future use and must be zero. KVM may
39262306a36Sopenharmony_cireturn ``-EINVAL`` if the field is nonzero.
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ciKVM reserves the 'Arm Architecture Calls' range of function IDs and
39562306a36Sopenharmony_ciwill reject attempts to define a filter for any portion of these ranges:
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ci        =========== ===============
39862306a36Sopenharmony_ci        Start       End (inclusive)
39962306a36Sopenharmony_ci        =========== ===============
40062306a36Sopenharmony_ci        0x8000_0000 0x8000_FFFF
40162306a36Sopenharmony_ci        0xC000_0000 0xC000_FFFF
40262306a36Sopenharmony_ci        =========== ===============
403