1f58f084eSCornelia HuckAdjunct Processor (AP) Device 2f58f084eSCornelia Huck============================= 3f58f084eSCornelia Huck 4f58f084eSCornelia Huck.. contents:: 5f58f084eSCornelia Huck 6f58f084eSCornelia HuckIntroduction 7f58f084eSCornelia Huck------------ 8f58f084eSCornelia Huck 9f58f084eSCornelia HuckThe IBM Adjunct Processor (AP) Cryptographic Facility is comprised 10f58f084eSCornelia Huckof three AP instructions and from 1 to 256 PCIe cryptographic adapter cards. 11f58f084eSCornelia HuckThese AP devices provide cryptographic functions to all CPUs assigned to a 12f58f084eSCornelia Hucklinux system running in an IBM Z system LPAR. 13f58f084eSCornelia Huck 14f58f084eSCornelia HuckOn s390x, AP adapter cards are exposed via the AP bus. This document 15f58f084eSCornelia Huckdescribes how those cards may be made available to KVM guests using the 16f58f084eSCornelia HuckVFIO mediated device framework. 17f58f084eSCornelia Huck 18f58f084eSCornelia HuckAP Architectural Overview 19f58f084eSCornelia Huck------------------------- 20f58f084eSCornelia Huck 21f58f084eSCornelia HuckIn order understand the terminology used in the rest of this document, let's 22f58f084eSCornelia Huckstart with some definitions: 23f58f084eSCornelia Huck 24f58f084eSCornelia Huck* AP adapter 25f58f084eSCornelia Huck 26f58f084eSCornelia Huck An AP adapter is an IBM Z adapter card that can perform cryptographic 27f58f084eSCornelia Huck functions. There can be from 0 to 256 adapters assigned to an LPAR depending 28f58f084eSCornelia Huck on the machine model. Adapters assigned to the LPAR in which a linux host is 29f58f084eSCornelia Huck running will be available to the linux host. Each adapter is identified by a 30f58f084eSCornelia Huck number from 0 to 255; however, the maximum adapter number allowed is 31f58f084eSCornelia Huck determined by machine model. When installed, an AP adapter is accessed by 32f58f084eSCornelia Huck AP instructions executed by any CPU. 33f58f084eSCornelia Huck 34f58f084eSCornelia Huck* AP domain 35f58f084eSCornelia Huck 36f58f084eSCornelia Huck An adapter is partitioned into domains. Each domain can be thought of as 37f58f084eSCornelia Huck a set of hardware registers for processing AP instructions. An adapter can 38f58f084eSCornelia Huck hold up to 256 domains; however, the maximum domain number allowed is 39f58f084eSCornelia Huck determined by machine model. Each domain is identified by a number from 0 to 40f58f084eSCornelia Huck 255. Domains can be further classified into two types: 41f58f084eSCornelia Huck 42f58f084eSCornelia Huck * Usage domains are domains that can be accessed directly to process AP 43f58f084eSCornelia Huck commands 44f58f084eSCornelia Huck 45f58f084eSCornelia Huck * Control domains are domains that are accessed indirectly by AP 46f58f084eSCornelia Huck commands sent to a usage domain to control or change the domain; for 47f58f084eSCornelia Huck example, to set a secure private key for the domain. 48f58f084eSCornelia Huck 49f58f084eSCornelia Huck* AP Queue 50f58f084eSCornelia Huck 51f58f084eSCornelia Huck An AP queue is the means by which an AP command-request message is sent to an 52f58f084eSCornelia Huck AP usage domain inside a specific AP. An AP queue is identified by a tuple 53f58f084eSCornelia Huck comprised of an AP adapter ID (APID) and an AP queue index (APQI). The 54f58f084eSCornelia Huck APQI corresponds to a given usage domain number within the adapter. This tuple 55f58f084eSCornelia Huck forms an AP Queue Number (APQN) uniquely identifying an AP queue. AP 56f58f084eSCornelia Huck instructions include a field containing the APQN to identify the AP queue to 57f58f084eSCornelia Huck which the AP command-request message is to be sent for processing. 58f58f084eSCornelia Huck 59f58f084eSCornelia Huck* AP Instructions: 60f58f084eSCornelia Huck 61f58f084eSCornelia Huck There are three AP instructions: 62f58f084eSCornelia Huck 63f58f084eSCornelia Huck * NQAP: to enqueue an AP command-request message to a queue 64f58f084eSCornelia Huck * DQAP: to dequeue an AP command-reply message from a queue 65f58f084eSCornelia Huck * PQAP: to administer the queues 66f58f084eSCornelia Huck 67f58f084eSCornelia Huck AP instructions identify the domain that is targeted to process the AP 68f58f084eSCornelia Huck command; this must be one of the usage domains. An AP command may modify a 69f58f084eSCornelia Huck domain that is not one of the usage domains, but the modified domain 70f58f084eSCornelia Huck must be one of the control domains. 71f58f084eSCornelia Huck 72f58f084eSCornelia HuckStart Interpretive Execution (SIE) Instruction 73f58f084eSCornelia Huck---------------------------------------------- 74f58f084eSCornelia Huck 75f58f084eSCornelia HuckA KVM guest is started by executing the Start Interpretive Execution (SIE) 76f58f084eSCornelia Huckinstruction. The SIE state description is a control block that contains the 77f58f084eSCornelia Huckstate information for a KVM guest and is supplied as input to the SIE 78f58f084eSCornelia Huckinstruction. The SIE state description contains a satellite control block called 79f58f084eSCornelia Huckthe Crypto Control Block (CRYCB). The CRYCB contains three fields to identify 80f58f084eSCornelia Huckthe adapters, usage domains and control domains assigned to the KVM guest: 81f58f084eSCornelia Huck 82f58f084eSCornelia Huck* The AP Mask (APM) field is a bit mask that identifies the AP adapters assigned 83f58f084eSCornelia Huck to the KVM guest. Each bit in the mask, from left to right, corresponds to 84f58f084eSCornelia Huck an APID from 0-255. If a bit is set, the corresponding adapter is valid for 85f58f084eSCornelia Huck use by the KVM guest. 86f58f084eSCornelia Huck 87f58f084eSCornelia Huck* The AP Queue Mask (AQM) field is a bit mask identifying the AP usage domains 88f58f084eSCornelia Huck assigned to the KVM guest. Each bit in the mask, from left to right, 89f58f084eSCornelia Huck corresponds to an AP queue index (APQI) from 0-255. If a bit is set, the 90f58f084eSCornelia Huck corresponding queue is valid for use by the KVM guest. 91f58f084eSCornelia Huck 92f58f084eSCornelia Huck* The AP Domain Mask field is a bit mask that identifies the AP control domains 93f58f084eSCornelia Huck assigned to the KVM guest. The ADM bit mask controls which domains can be 94f58f084eSCornelia Huck changed by an AP command-request message sent to a usage domain from the 95f58f084eSCornelia Huck guest. Each bit in the mask, from left to right, corresponds to a domain from 96f58f084eSCornelia Huck 0-255. If a bit is set, the corresponding domain can be modified by an AP 97f58f084eSCornelia Huck command-request message sent to a usage domain. 98f58f084eSCornelia Huck 99f58f084eSCornelia HuckIf you recall from the description of an AP Queue, AP instructions include 100f58f084eSCornelia Huckan APQN to identify the AP adapter and AP queue to which an AP command-request 101f58f084eSCornelia Huckmessage is to be sent (NQAP and PQAP instructions), or from which a 102f58f084eSCornelia Huckcommand-reply message is to be received (DQAP instruction). The validity of an 103f58f084eSCornelia HuckAPQN is defined by the matrix calculated from the APM and AQM; it is the 104f58f084eSCornelia Huckcross product of all assigned adapter numbers (APM) with all assigned queue 105f58f084eSCornelia Huckindexes (AQM). For example, if adapters 1 and 2 and usage domains 5 and 6 are 106f58f084eSCornelia Huckassigned to a guest, the APQNs (1,5), (1,6), (2,5) and (2,6) will be valid for 107f58f084eSCornelia Huckthe guest. 108f58f084eSCornelia Huck 109f58f084eSCornelia HuckThe APQNs can provide secure key functionality - i.e., a private key is stored 110f58f084eSCornelia Huckon the adapter card for each of its domains - so each APQN must be assigned to 111f58f084eSCornelia Huckat most one guest or the linux host. 112f58f084eSCornelia Huck 113f58f084eSCornelia HuckExample 1: Valid configuration 114f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 115f58f084eSCornelia Huck 116f58f084eSCornelia Huck+----------+--------+--------+ 117f58f084eSCornelia Huck| | Guest1 | Guest2 | 118f58f084eSCornelia Huck+==========+========+========+ 119f58f084eSCornelia Huck| adapters | 1, 2 | 1, 2 | 120f58f084eSCornelia Huck+----------+--------+--------+ 121f58f084eSCornelia Huck| domains | 5, 6 | 7 | 122f58f084eSCornelia Huck+----------+--------+--------+ 123f58f084eSCornelia Huck 124f58f084eSCornelia HuckThis is valid because both guests have a unique set of APQNs: 125f58f084eSCornelia Huck 126f58f084eSCornelia Huck* Guest1 has APQNs (1,5), (1,6), (2,5) and (2,6); 127f58f084eSCornelia Huck* Guest2 has APQNs (1,7) and (2,7). 128f58f084eSCornelia Huck 129f58f084eSCornelia HuckExample 2: Valid configuration 130f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 131f58f084eSCornelia Huck 132f58f084eSCornelia Huck+----------+--------+--------+ 133f58f084eSCornelia Huck| | Guest1 | Guest2 | 134f58f084eSCornelia Huck+==========+========+========+ 135f58f084eSCornelia Huck| adapters | 1, 2 | 3, 4 | 136f58f084eSCornelia Huck+----------+--------+--------+ 137f58f084eSCornelia Huck| domains | 5, 6 | 5, 6 | 138f58f084eSCornelia Huck+----------+--------+--------+ 139f58f084eSCornelia Huck 140f58f084eSCornelia HuckThis is also valid because both guests have a unique set of APQNs: 141f58f084eSCornelia Huck 142f58f084eSCornelia Huck* Guest1 has APQNs (1,5), (1,6), (2,5), (2,6); 143f58f084eSCornelia Huck* Guest2 has APQNs (3,5), (3,6), (4,5), (4,6) 144f58f084eSCornelia Huck 145f58f084eSCornelia HuckExample 3: Invalid configuration 146f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 147f58f084eSCornelia Huck 148f58f084eSCornelia Huck+----------+--------+--------+ 149f58f084eSCornelia Huck| | Guest1 | Guest2 | 150f58f084eSCornelia Huck+==========+========+========+ 151f58f084eSCornelia Huck| adapters | 1, 2 | 1 | 152f58f084eSCornelia Huck+----------+--------+--------+ 153f58f084eSCornelia Huck| domains | 5, 6 | 6, 7 | 154f58f084eSCornelia Huck+----------+--------+--------+ 155f58f084eSCornelia Huck 156f58f084eSCornelia HuckThis is an invalid configuration because both guests have access to 157f58f084eSCornelia HuckAPQN (1,6). 158f58f084eSCornelia Huck 159f58f084eSCornelia HuckAP Matrix Configuration on Linux Host 160f58f084eSCornelia Huck------------------------------------- 161f58f084eSCornelia Huck 162f58f084eSCornelia HuckA linux system is a guest of the LPAR in which it is running and has access to 163f58f084eSCornelia Huckthe AP resources configured for the LPAR. The LPAR's AP matrix is 164f58f084eSCornelia Huckconfigured via its Activation Profile which can be edited on the HMC. When the 165f58f084eSCornelia Hucklinux system is started, the AP bus will detect the AP devices assigned to the 166f58f084eSCornelia HuckLPAR and create the following in sysfs:: 167f58f084eSCornelia Huck 168f58f084eSCornelia Huck /sys/bus/ap 169f58f084eSCornelia Huck ... [devices] 170f58f084eSCornelia Huck ...... xx.yyyy 171f58f084eSCornelia Huck ...... ... 172f58f084eSCornelia Huck ...... cardxx 173f58f084eSCornelia Huck ...... ... 174f58f084eSCornelia Huck 175f58f084eSCornelia HuckWhere: 176f58f084eSCornelia Huck 177f58f084eSCornelia Huck``cardxx`` 178f58f084eSCornelia Huck is AP adapter number xx (in hex) 179f58f084eSCornelia Huck 180f58f084eSCornelia Huck``xx.yyyy`` 181f58f084eSCornelia Huck is an APQN with xx specifying the APID and yyyy specifying the APQI 182f58f084eSCornelia Huck 183f58f084eSCornelia HuckFor example, if AP adapters 5 and 6 and domains 4, 71 (0x47), 171 (0xab) and 184f58f084eSCornelia Huck255 (0xff) are configured for the LPAR, the sysfs representation on the linux 185f58f084eSCornelia Huckhost system would look like this:: 186f58f084eSCornelia Huck 187f58f084eSCornelia Huck /sys/bus/ap 188f58f084eSCornelia Huck ... [devices] 189f58f084eSCornelia Huck ...... 05.0004 190f58f084eSCornelia Huck ...... 05.0047 191f58f084eSCornelia Huck ...... 05.00ab 192f58f084eSCornelia Huck ...... 05.00ff 193f58f084eSCornelia Huck ...... 06.0004 194f58f084eSCornelia Huck ...... 06.0047 195f58f084eSCornelia Huck ...... 06.00ab 196f58f084eSCornelia Huck ...... 06.00ff 197f58f084eSCornelia Huck ...... card05 198f58f084eSCornelia Huck ...... card06 199f58f084eSCornelia Huck 200f58f084eSCornelia HuckA set of default device drivers are also created to control each type of AP 201f58f084eSCornelia Huckdevice that can be assigned to the LPAR on which a linux host is running:: 202f58f084eSCornelia Huck 203f58f084eSCornelia Huck /sys/bus/ap 204f58f084eSCornelia Huck ... [drivers] 205f58f084eSCornelia Huck ...... [cex2acard] for Crypto Express 2/3 accelerator cards 206f58f084eSCornelia Huck ...... [cex2aqueue] for AP queues served by Crypto Express 2/3 207f58f084eSCornelia Huck accelerator cards 208f58f084eSCornelia Huck ...... [cex4card] for Crypto Express 4/5/6 accelerator and coprocessor 209f58f084eSCornelia Huck cards 210f58f084eSCornelia Huck ...... [cex4queue] for AP queues served by Crypto Express 4/5/6 211f58f084eSCornelia Huck accelerator and coprocessor cards 212f58f084eSCornelia Huck ...... [pcixcccard] for Crypto Express 2/3 coprocessor cards 213f58f084eSCornelia Huck ...... [pcixccqueue] for AP queues served by Crypto Express 2/3 214f58f084eSCornelia Huck coprocessor cards 215f58f084eSCornelia Huck 216f58f084eSCornelia HuckBinding AP devices to device drivers 217f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 218f58f084eSCornelia Huck 219f58f084eSCornelia HuckThere are two sysfs files that specify bitmasks marking a subset of the APQN 220f58f084eSCornelia Huckrange as 'usable by the default AP queue device drivers' or 'not usable by the 221f58f084eSCornelia Huckdefault device drivers' and thus available for use by the alternate device 222f58f084eSCornelia Huckdriver(s). The sysfs locations of the masks are:: 223f58f084eSCornelia Huck 224f58f084eSCornelia Huck /sys/bus/ap/apmask 225f58f084eSCornelia Huck /sys/bus/ap/aqmask 226f58f084eSCornelia Huck 227f58f084eSCornelia HuckThe ``apmask`` is a 256-bit mask that identifies a set of AP adapter IDs 228f58f084eSCornelia Huck(APID). Each bit in the mask, from left to right (i.e., from most significant 229f58f084eSCornelia Huckto least significant bit in big endian order), corresponds to an APID from 230f58f084eSCornelia Huck0-255. If a bit is set, the APID is marked as usable only by the default AP 231f58f084eSCornelia Huckqueue device drivers; otherwise, the APID is usable by the vfio_ap 232f58f084eSCornelia Huckdevice driver. 233f58f084eSCornelia Huck 234f58f084eSCornelia HuckThe ``aqmask`` is a 256-bit mask that identifies a set of AP queue indexes 235f58f084eSCornelia Huck(APQI). Each bit in the mask, from left to right (i.e., from most significant 236f58f084eSCornelia Huckto least significant bit in big endian order), corresponds to an APQI from 237f58f084eSCornelia Huck0-255. If a bit is set, the APQI is marked as usable only by the default AP 238f58f084eSCornelia Huckqueue device drivers; otherwise, the APQI is usable by the vfio_ap device 239f58f084eSCornelia Huckdriver. 240f58f084eSCornelia Huck 241f58f084eSCornelia HuckTake, for example, the following mask:: 242f58f084eSCornelia Huck 243f58f084eSCornelia Huck 0x7dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 244f58f084eSCornelia Huck 245f58f084eSCornelia HuckIt indicates: 246f58f084eSCornelia Huck 247f58f084eSCornelia Huck 1, 2, 3, 4, 5, and 7-255 belong to the default drivers' pool, and 0 and 6 248f58f084eSCornelia Huck belong to the vfio_ap device driver's pool. 249f58f084eSCornelia Huck 250f58f084eSCornelia HuckThe APQN of each AP queue device assigned to the linux host is checked by the 251f58f084eSCornelia HuckAP bus against the set of APQNs derived from the cross product of APIDs 252f58f084eSCornelia Huckand APQIs marked as usable only by the default AP queue device drivers. If a 253f58f084eSCornelia Huckmatch is detected, only the default AP queue device drivers will be probed; 254f58f084eSCornelia Huckotherwise, the vfio_ap device driver will be probed. 255f58f084eSCornelia Huck 256f58f084eSCornelia HuckBy default, the two masks are set to reserve all APQNs for use by the default 257f58f084eSCornelia HuckAP queue device drivers. There are two ways the default masks can be changed: 258f58f084eSCornelia Huck 259f58f084eSCornelia Huck 1. The sysfs mask files can be edited by echoing a string into the 260f58f084eSCornelia Huck respective sysfs mask file in one of two formats: 261f58f084eSCornelia Huck 262f58f084eSCornelia Huck * An absolute hex string starting with 0x - like "0x12345678" - sets 263f58f084eSCornelia Huck the mask. If the given string is shorter than the mask, it is padded 264f58f084eSCornelia Huck with 0s on the right; for example, specifying a mask value of 0x41 is 265f58f084eSCornelia Huck the same as specifying:: 266f58f084eSCornelia Huck 267f58f084eSCornelia Huck 0x4100000000000000000000000000000000000000000000000000000000000000 268f58f084eSCornelia Huck 269f58f084eSCornelia Huck Keep in mind that the mask reads from left to right (i.e., most 270f58f084eSCornelia Huck significant to least significant bit in big endian order), so the mask 271f58f084eSCornelia Huck above identifies device numbers 1 and 7 (``01000001``). 272f58f084eSCornelia Huck 273f58f084eSCornelia Huck If the string is longer than the mask, the operation is terminated with 274f58f084eSCornelia Huck an error (EINVAL). 275f58f084eSCornelia Huck 276f58f084eSCornelia Huck * Individual bits in the mask can be switched on and off by specifying 277f58f084eSCornelia Huck each bit number to be switched in a comma separated list. Each bit 278f58f084eSCornelia Huck number string must be prepended with a (``+``) or minus (``-``) to indicate 279f58f084eSCornelia Huck the corresponding bit is to be switched on (``+``) or off (``-``). Some 280f58f084eSCornelia Huck valid values are:: 281f58f084eSCornelia Huck 282f58f084eSCornelia Huck "+0" switches bit 0 on 283f58f084eSCornelia Huck "-13" switches bit 13 off 284f58f084eSCornelia Huck "+0x41" switches bit 65 on 285f58f084eSCornelia Huck "-0xff" switches bit 255 off 286f58f084eSCornelia Huck 287f58f084eSCornelia Huck The following example:: 288f58f084eSCornelia Huck 289f58f084eSCornelia Huck +0,-6,+0x47,-0xf0 290f58f084eSCornelia Huck 291f58f084eSCornelia Huck Switches bits 0 and 71 (0x47) on 292f58f084eSCornelia Huck Switches bits 6 and 240 (0xf0) off 293f58f084eSCornelia Huck 294f58f084eSCornelia Huck Note that the bits not specified in the list remain as they were before 295f58f084eSCornelia Huck the operation. 296f58f084eSCornelia Huck 297f58f084eSCornelia Huck 2. The masks can also be changed at boot time via parameters on the kernel 298f58f084eSCornelia Huck command line like this:: 299f58f084eSCornelia Huck 300f58f084eSCornelia Huck ap.apmask=0xffff ap.aqmask=0x40 301f58f084eSCornelia Huck 302f58f084eSCornelia Huck This would create the following masks: 303f58f084eSCornelia Huck 304f58f084eSCornelia Huck apmask:: 305f58f084eSCornelia Huck 306f58f084eSCornelia Huck 0xffff000000000000000000000000000000000000000000000000000000000000 307f58f084eSCornelia Huck 308f58f084eSCornelia Huck aqmask:: 309f58f084eSCornelia Huck 310f58f084eSCornelia Huck 0x4000000000000000000000000000000000000000000000000000000000000000 311f58f084eSCornelia Huck 312f58f084eSCornelia Huck Resulting in these two pools:: 313f58f084eSCornelia Huck 314f58f084eSCornelia Huck default drivers pool: adapter 0-15, domain 1 315f58f084eSCornelia Huck alternate drivers pool: adapter 16-255, domains 0, 2-255 316f58f084eSCornelia Huck 317f58f084eSCornelia HuckConfiguring an AP matrix for a linux guest 318f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 319f58f084eSCornelia Huck 320f58f084eSCornelia HuckThe sysfs interfaces for configuring an AP matrix for a guest are built on the 321f58f084eSCornelia HuckVFIO mediated device framework. To configure an AP matrix for a guest, a 322f58f084eSCornelia Huckmediated matrix device must first be created for the ``/sys/devices/vfio_ap/matrix`` 323f58f084eSCornelia Huckdevice. When the vfio_ap device driver is loaded, it registers with the VFIO 324f58f084eSCornelia Huckmediated device framework. When the driver registers, the sysfs interfaces for 325f58f084eSCornelia Huckcreating mediated matrix devices is created:: 326f58f084eSCornelia Huck 327f58f084eSCornelia Huck /sys/devices 328f58f084eSCornelia Huck ... [vfio_ap] 329f58f084eSCornelia Huck ......[matrix] 330f58f084eSCornelia Huck ......... [mdev_supported_types] 331f58f084eSCornelia Huck ............ [vfio_ap-passthrough] 332f58f084eSCornelia Huck ............... create 333f58f084eSCornelia Huck ............... [devices] 334f58f084eSCornelia Huck 335f58f084eSCornelia HuckA mediated AP matrix device is created by writing a UUID to the attribute file 336f58f084eSCornelia Hucknamed ``create``, for example:: 337f58f084eSCornelia Huck 338f58f084eSCornelia Huck uuidgen > create 339f58f084eSCornelia Huck 340f58f084eSCornelia Huckor 341f58f084eSCornelia Huck 342f58f084eSCornelia Huck:: 343f58f084eSCornelia Huck 344f58f084eSCornelia Huck echo $uuid > create 345f58f084eSCornelia Huck 346f58f084eSCornelia HuckWhen a mediated AP matrix device is created, a sysfs directory named after 347f58f084eSCornelia Huckthe UUID is created in the ``devices`` subdirectory:: 348f58f084eSCornelia Huck 349f58f084eSCornelia Huck /sys/devices 350f58f084eSCornelia Huck ... [vfio_ap] 351f58f084eSCornelia Huck ......[matrix] 352f58f084eSCornelia Huck ......... [mdev_supported_types] 353f58f084eSCornelia Huck ............ [vfio_ap-passthrough] 354f58f084eSCornelia Huck ............... create 355f58f084eSCornelia Huck ............... [devices] 356f58f084eSCornelia Huck .................. [$uuid] 357f58f084eSCornelia Huck 358f58f084eSCornelia HuckThere will also be three sets of attribute files created in the mediated 359f58f084eSCornelia Huckmatrix device's sysfs directory to configure an AP matrix for the 360f58f084eSCornelia HuckKVM guest:: 361f58f084eSCornelia Huck 362f58f084eSCornelia Huck /sys/devices 363f58f084eSCornelia Huck ... [vfio_ap] 364f58f084eSCornelia Huck ......[matrix] 365f58f084eSCornelia Huck ......... [mdev_supported_types] 366f58f084eSCornelia Huck ............ [vfio_ap-passthrough] 367f58f084eSCornelia Huck ............... create 368f58f084eSCornelia Huck ............... [devices] 369f58f084eSCornelia Huck .................. [$uuid] 370f58f084eSCornelia Huck ..................... assign_adapter 371f58f084eSCornelia Huck ..................... assign_control_domain 372f58f084eSCornelia Huck ..................... assign_domain 373f58f084eSCornelia Huck ..................... matrix 374f58f084eSCornelia Huck ..................... unassign_adapter 375f58f084eSCornelia Huck ..................... unassign_control_domain 376f58f084eSCornelia Huck ..................... unassign_domain 377f58f084eSCornelia Huck 378f58f084eSCornelia Huck``assign_adapter`` 379f58f084eSCornelia Huck To assign an AP adapter to the mediated matrix device, its APID is written 380f58f084eSCornelia Huck to the ``assign_adapter`` file. This may be done multiple times to assign more 381f58f084eSCornelia Huck than one adapter. The APID may be specified using conventional semantics 382f58f084eSCornelia Huck as a decimal, hexadecimal, or octal number. For example, to assign adapters 383f58f084eSCornelia Huck 4, 5 and 16 to a mediated matrix device in decimal, hexadecimal and octal 384f58f084eSCornelia Huck respectively:: 385f58f084eSCornelia Huck 386f58f084eSCornelia Huck echo 4 > assign_adapter 387f58f084eSCornelia Huck echo 0x5 > assign_adapter 388f58f084eSCornelia Huck echo 020 > assign_adapter 389f58f084eSCornelia Huck 390f58f084eSCornelia Huck In order to successfully assign an adapter: 391f58f084eSCornelia Huck 392f58f084eSCornelia Huck * The adapter number specified must represent a value from 0 up to the 393f58f084eSCornelia Huck maximum adapter number allowed by the machine model. If an adapter number 394f58f084eSCornelia Huck higher than the maximum is specified, the operation will terminate with 395f58f084eSCornelia Huck an error (ENODEV). 396f58f084eSCornelia Huck 397f58f084eSCornelia Huck * All APQNs that can be derived from the adapter ID being assigned and the 398f58f084eSCornelia Huck IDs of the previously assigned domains must be bound to the vfio_ap device 399f58f084eSCornelia Huck driver. If no domains have yet been assigned, then there must be at least 400f58f084eSCornelia Huck one APQN with the specified APID bound to the vfio_ap driver. If no such 401f58f084eSCornelia Huck APQNs are bound to the driver, the operation will terminate with an 402f58f084eSCornelia Huck error (EADDRNOTAVAIL). 403f58f084eSCornelia Huck 404f58f084eSCornelia Huck * No APQN that can be derived from the adapter ID and the IDs of the 405f58f084eSCornelia Huck previously assigned domains can be assigned to another mediated matrix 406f58f084eSCornelia Huck device. If an APQN is assigned to another mediated matrix device, the 407f58f084eSCornelia Huck operation will terminate with an error (EADDRINUSE). 408f58f084eSCornelia Huck 409f58f084eSCornelia Huck``unassign_adapter`` 410f58f084eSCornelia Huck To unassign an AP adapter, its APID is written to the ``unassign_adapter`` 411f58f084eSCornelia Huck file. This may also be done multiple times to unassign more than one adapter. 412f58f084eSCornelia Huck 413f58f084eSCornelia Huck``assign_domain`` 414f58f084eSCornelia Huck To assign a usage domain, the domain number is written into the 415f58f084eSCornelia Huck ``assign_domain`` file. This may be done multiple times to assign more than one 416f58f084eSCornelia Huck usage domain. The domain number is specified using conventional semantics as 417f58f084eSCornelia Huck a decimal, hexadecimal, or octal number. For example, to assign usage domains 418f58f084eSCornelia Huck 4, 8, and 71 to a mediated matrix device in decimal, hexadecimal and octal 419f58f084eSCornelia Huck respectively:: 420f58f084eSCornelia Huck 421f58f084eSCornelia Huck echo 4 > assign_domain 422f58f084eSCornelia Huck echo 0x8 > assign_domain 423f58f084eSCornelia Huck echo 0107 > assign_domain 424f58f084eSCornelia Huck 425f58f084eSCornelia Huck In order to successfully assign a domain: 426f58f084eSCornelia Huck 427f58f084eSCornelia Huck * The domain number specified must represent a value from 0 up to the 428f58f084eSCornelia Huck maximum domain number allowed by the machine model. If a domain number 429f58f084eSCornelia Huck higher than the maximum is specified, the operation will terminate with 430f58f084eSCornelia Huck an error (ENODEV). 431f58f084eSCornelia Huck 432f58f084eSCornelia Huck * All APQNs that can be derived from the domain ID being assigned and the IDs 433f58f084eSCornelia Huck of the previously assigned adapters must be bound to the vfio_ap device 434f58f084eSCornelia Huck driver. If no domains have yet been assigned, then there must be at least 435f58f084eSCornelia Huck one APQN with the specified APQI bound to the vfio_ap driver. If no such 436f58f084eSCornelia Huck APQNs are bound to the driver, the operation will terminate with an 437f58f084eSCornelia Huck error (EADDRNOTAVAIL). 438f58f084eSCornelia Huck 439f58f084eSCornelia Huck * No APQN that can be derived from the domain ID being assigned and the IDs 440f58f084eSCornelia Huck of the previously assigned adapters can be assigned to another mediated 441f58f084eSCornelia Huck matrix device. If an APQN is assigned to another mediated matrix device, 442f58f084eSCornelia Huck the operation will terminate with an error (EADDRINUSE). 443f58f084eSCornelia Huck 444f58f084eSCornelia Huck``unassign_domain`` 445f58f084eSCornelia Huck To unassign a usage domain, the domain number is written into the 446f58f084eSCornelia Huck ``unassign_domain`` file. This may be done multiple times to unassign more than 447f58f084eSCornelia Huck one usage domain. 448f58f084eSCornelia Huck 449f58f084eSCornelia Huck``assign_control_domain`` 450f58f084eSCornelia Huck To assign a control domain, the domain number is written into the 451f58f084eSCornelia Huck ``assign_control_domain`` file. This may be done multiple times to 452f58f084eSCornelia Huck assign more than one control domain. The domain number may be specified using 453f58f084eSCornelia Huck conventional semantics as a decimal, hexadecimal, or octal number. For 454f58f084eSCornelia Huck example, to assign control domains 4, 8, and 71 to a mediated matrix device 455f58f084eSCornelia Huck in decimal, hexadecimal and octal respectively:: 456f58f084eSCornelia Huck 457f58f084eSCornelia Huck echo 4 > assign_domain 458f58f084eSCornelia Huck echo 0x8 > assign_domain 459f58f084eSCornelia Huck echo 0107 > assign_domain 460f58f084eSCornelia Huck 461f58f084eSCornelia Huck In order to successfully assign a control domain, the domain number 462f58f084eSCornelia Huck specified must represent a value from 0 up to the maximum domain number 463f58f084eSCornelia Huck allowed by the machine model. If a control domain number higher than the 464f58f084eSCornelia Huck maximum is specified, the operation will terminate with an error (ENODEV). 465f58f084eSCornelia Huck 466f58f084eSCornelia Huck``unassign_control_domain`` 467f58f084eSCornelia Huck To unassign a control domain, the domain number is written into the 468f58f084eSCornelia Huck ``unassign_domain`` file. This may be done multiple times to unassign more than 469f58f084eSCornelia Huck one control domain. 470f58f084eSCornelia Huck 471f58f084eSCornelia HuckNotes: No changes to the AP matrix will be allowed while a guest using 472f58f084eSCornelia Huckthe mediated matrix device is running. Attempts to assign an adapter, 473f58f084eSCornelia Huckdomain or control domain will be rejected and an error (EBUSY) returned. 474f58f084eSCornelia Huck 475f58f084eSCornelia HuckStarting a Linux Guest Configured with an AP Matrix 476f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 477f58f084eSCornelia Huck 478f58f084eSCornelia HuckTo provide a mediated matrix device for use by a guest, the following option 479f58f084eSCornelia Huckmust be specified on the QEMU command line:: 480f58f084eSCornelia Huck 481f58f084eSCornelia Huck -device vfio_ap,sysfsdev=$path-to-mdev 482f58f084eSCornelia Huck 483f58f084eSCornelia HuckThe sysfsdev parameter specifies the path to the mediated matrix device. 484f58f084eSCornelia HuckThere are a number of ways to specify this path:: 485f58f084eSCornelia Huck 486f58f084eSCornelia Huck /sys/devices/vfio_ap/matrix/$uuid 487f58f084eSCornelia Huck /sys/bus/mdev/devices/$uuid 488f58f084eSCornelia Huck /sys/bus/mdev/drivers/vfio_mdev/$uuid 489f58f084eSCornelia Huck /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid 490f58f084eSCornelia Huck 491f58f084eSCornelia HuckWhen the linux guest is started, the guest will open the mediated 492f58f084eSCornelia Huckmatrix device's file descriptor to get information about the mediated matrix 493f58f084eSCornelia Huckdevice. The ``vfio_ap`` device driver will update the APM, AQM, and ADM fields in 494f58f084eSCornelia Huckthe guest's CRYCB with the adapter, usage domain and control domains assigned 495f58f084eSCornelia Huckvia the mediated matrix device's sysfs attribute files. Programs running on the 496f58f084eSCornelia Hucklinux guest will then: 497f58f084eSCornelia Huck 498f58f084eSCornelia Huck1. Have direct access to the APQNs derived from the cross product of the AP 499f58f084eSCornelia Huck adapter numbers (APID) and queue indexes (APQI) specified in the APM and AQM 500f58f084eSCornelia Huck fields of the guests's CRYCB respectively. These APQNs identify the AP queues 501f58f084eSCornelia Huck that are valid for use by the guest; meaning, AP commands can be sent by the 502f58f084eSCornelia Huck guest to any of these queues for processing. 503f58f084eSCornelia Huck 504f58f084eSCornelia Huck2. Have authorization to process AP commands to change a control domain 505f58f084eSCornelia Huck identified in the ADM field of the guest's CRYCB. The AP command must be sent 506f58f084eSCornelia Huck to a valid APQN (see 1 above). 507f58f084eSCornelia Huck 508f58f084eSCornelia HuckCPU model features: 509f58f084eSCornelia Huck 510f58f084eSCornelia HuckThree CPU model features are available for controlling guest access to AP 511f58f084eSCornelia Huckfacilities: 512f58f084eSCornelia Huck 513f58f084eSCornelia Huck1. AP facilities feature 514f58f084eSCornelia Huck 515f58f084eSCornelia Huck The AP facilities feature indicates that AP facilities are installed on the 516f58f084eSCornelia Huck guest. This feature will be exposed for use only if the AP facilities 517f58f084eSCornelia Huck are installed on the host system. The feature is s390-specific and is 518f58f084eSCornelia Huck represented as a parameter of the -cpu option on the QEMU command line:: 519f58f084eSCornelia Huck 520f58f084eSCornelia Huck qemu-system-s390x -cpu $model,ap=on|off 521f58f084eSCornelia Huck 522f58f084eSCornelia Huck Where: 523f58f084eSCornelia Huck 524f58f084eSCornelia Huck ``$model`` 525f58f084eSCornelia Huck is the CPU model defined for the guest (defaults to the model of 526f58f084eSCornelia Huck the host system if not specified). 527f58f084eSCornelia Huck 528f58f084eSCornelia Huck ``ap=on|off`` 529f58f084eSCornelia Huck indicates whether AP facilities are installed (on) or not 530f58f084eSCornelia Huck (off). The default for CPU models zEC12 or newer 531f58f084eSCornelia Huck is ``ap=on``. AP facilities must be installed on the guest if a 532f58f084eSCornelia Huck vfio-ap device (``-device vfio-ap,sysfsdev=$path``) is configured 533f58f084eSCornelia Huck for the guest, or the guest will fail to start. 534f58f084eSCornelia Huck 535f58f084eSCornelia Huck2. Query Configuration Information (QCI) facility 536f58f084eSCornelia Huck 537f58f084eSCornelia Huck The QCI facility is used by the AP bus running on the guest to query the 538f58f084eSCornelia Huck configuration of the AP facilities. This facility will be available 539f58f084eSCornelia Huck only if the QCI facility is installed on the host system. The feature is 540f58f084eSCornelia Huck s390-specific and is represented as a parameter of the -cpu option on the 541f58f084eSCornelia Huck QEMU command line:: 542f58f084eSCornelia Huck 543f58f084eSCornelia Huck qemu-system-s390x -cpu $model,apqci=on|off 544f58f084eSCornelia Huck 545f58f084eSCornelia Huck Where: 546f58f084eSCornelia Huck 547f58f084eSCornelia Huck ``$model`` 548f58f084eSCornelia Huck is the CPU model defined for the guest 549f58f084eSCornelia Huck 550f58f084eSCornelia Huck ``apqci=on|off`` 551f58f084eSCornelia Huck indicates whether the QCI facility is installed (on) or 552f58f084eSCornelia Huck not (off). The default for CPU models zEC12 or newer 553f58f084eSCornelia Huck is ``apqci=on``; for older models, QCI will not be installed. 554f58f084eSCornelia Huck 555f58f084eSCornelia Huck If QCI is installed (``apqci=on``) but AP facilities are not 556f58f084eSCornelia Huck (``ap=off``), an error message will be logged, but the guest 557f58f084eSCornelia Huck will be allowed to start. It makes no sense to have QCI 558f58f084eSCornelia Huck installed if the AP facilities are not; this is considered 559f58f084eSCornelia Huck an invalid configuration. 560f58f084eSCornelia Huck 561f58f084eSCornelia Huck If the QCI facility is not installed, APQNs with an APQI 562f58f084eSCornelia Huck greater than 15 will not be detected by the AP bus 563f58f084eSCornelia Huck running on the guest. 564f58f084eSCornelia Huck 565f58f084eSCornelia Huck3. Adjunct Process Facility Test (APFT) facility 566f58f084eSCornelia Huck 567f58f084eSCornelia Huck The APFT facility is used by the AP bus running on the guest to test the 568f58f084eSCornelia Huck AP facilities available for a given AP queue. This facility will be available 569f58f084eSCornelia Huck only if the APFT facility is installed on the host system. The feature is 570f58f084eSCornelia Huck s390-specific and is represented as a parameter of the -cpu option on the 571f58f084eSCornelia Huck QEMU command line:: 572f58f084eSCornelia Huck 573f58f084eSCornelia Huck qemu-system-s390x -cpu $model,apft=on|off 574f58f084eSCornelia Huck 575f58f084eSCornelia Huck Where: 576f58f084eSCornelia Huck 577f58f084eSCornelia Huck ``$model`` 578f58f084eSCornelia Huck is the CPU model defined for the guest (defaults to the model of 579f58f084eSCornelia Huck the host system if not specified). 580f58f084eSCornelia Huck 581f58f084eSCornelia Huck ``apft=on|off`` 582f58f084eSCornelia Huck indicates whether the APFT facility is installed (on) or 583f58f084eSCornelia Huck not (off). The default for CPU models zEC12 and 584f58f084eSCornelia Huck newer is ``apft=on`` for older models, APFT will not be 585f58f084eSCornelia Huck installed. 586f58f084eSCornelia Huck 587f58f084eSCornelia Huck If APFT is installed (``apft=on``) but AP facilities are not 588f58f084eSCornelia Huck (``ap=off``), an error message will be logged, but the guest 589f58f084eSCornelia Huck will be allowed to start. It makes no sense to have APFT 590f58f084eSCornelia Huck installed if the AP facilities are not; this is considered 591f58f084eSCornelia Huck an invalid configuration. 592f58f084eSCornelia Huck 593f58f084eSCornelia Huck It also makes no sense to turn APFT off because the AP bus 594f58f084eSCornelia Huck running on the guest will not detect CEX4 and newer devices 595f58f084eSCornelia Huck without it. Since only CEX4 and newer devices are supported 596f58f084eSCornelia Huck for guest usage, no AP devices can be made accessible to a 597f58f084eSCornelia Huck guest started without APFT installed. 598f58f084eSCornelia Huck 599f58f084eSCornelia HuckHot plug a vfio-ap device into a running guest 600f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 601f58f084eSCornelia Huck 602f58f084eSCornelia HuckOnly one vfio-ap device can be attached to the virtual machine's ap-bus, so a 603f58f084eSCornelia Huckvfio-ap device can be hot plugged if and only if no vfio-ap device is attached 604f58f084eSCornelia Huckto the bus already, whether via the QEMU command line or a prior hot plug 605f58f084eSCornelia Huckaction. 606f58f084eSCornelia Huck 607f58f084eSCornelia HuckTo hot plug a vfio-ap device, use the QEMU ``device_add`` command:: 608f58f084eSCornelia Huck 609*458e0562SChristian Borntraeger (qemu) device_add vfio-ap,sysfsdev="$path-to-mdev",id="$id" 610f58f084eSCornelia Huck 611f58f084eSCornelia HuckWhere the ``$path-to-mdev`` value specifies the absolute path to a mediated 612f58f084eSCornelia Huckdevice to which AP resources to be used by the guest have been assigned. 613*458e0562SChristian Borntraeger``$id`` is the name value for the optional id parameter. 614f58f084eSCornelia Huck 615f58f084eSCornelia HuckNote that on Linux guests, the AP devices will be created in the 616f58f084eSCornelia Huck``/sys/bus/ap/devices`` directory when the AP bus subsequently performs its periodic 617f58f084eSCornelia Huckscan, so there may be a short delay before the AP devices are accessible on the 618f58f084eSCornelia Huckguest. 619f58f084eSCornelia Huck 620f58f084eSCornelia HuckThe command will fail if: 621f58f084eSCornelia Huck 622f58f084eSCornelia Huck* A vfio-ap device has already been attached to the virtual machine's ap-bus. 623f58f084eSCornelia Huck 624f58f084eSCornelia Huck* The CPU model features for controlling guest access to AP facilities are not 625f58f084eSCornelia Huck enabled (see 'CPU model features' subsection in the previous section). 626f58f084eSCornelia Huck 627f58f084eSCornelia HuckHot unplug a vfio-ap device from a running guest 628f58f084eSCornelia Huck~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 629f58f084eSCornelia Huck 630f58f084eSCornelia HuckA vfio-ap device can be unplugged from a running KVM guest if a vfio-ap device 631f58f084eSCornelia Huckhas been attached to the virtual machine's ap-bus via the QEMU command line 632f58f084eSCornelia Huckor a prior hot plug action. 633f58f084eSCornelia Huck 634f58f084eSCornelia HuckTo hot unplug a vfio-ap device, use the QEMU ``device_del`` command:: 635f58f084eSCornelia Huck 636*458e0562SChristian Borntraeger (qemu) device_del "$id" 637f58f084eSCornelia Huck 638*458e0562SChristian BorntraegerWhere ``$id`` is the same id that was specified at device creation. 639f58f084eSCornelia Huck 640f58f084eSCornelia HuckOn a Linux guest, the AP devices will be removed from the ``/sys/bus/ap/devices`` 641f58f084eSCornelia Huckdirectory on the guest when the AP bus subsequently performs its periodic scan, 642f58f084eSCornelia Huckso there may be a short delay before the AP devices are no longer accessible by 643f58f084eSCornelia Huckthe guest. 644f58f084eSCornelia Huck 645f58f084eSCornelia HuckThe command will fail if the ``$path-to-mdev`` specified on the ``device_del`` command 646f58f084eSCornelia Huckdoes not match the value specified when the vfio-ap device was attached to 647f58f084eSCornelia Huckthe virtual machine's ap-bus. 648f58f084eSCornelia Huck 649f58f084eSCornelia HuckExample: Configure AP Matrices for Three Linux Guests 650f58f084eSCornelia Huck----------------------------------------------------- 651f58f084eSCornelia Huck 652f58f084eSCornelia HuckLet's now provide an example to illustrate how KVM guests may be given 653f58f084eSCornelia Huckaccess to AP facilities. For this example, we will show how to configure 654f58f084eSCornelia Huckthree guests such that executing the lszcrypt command on the guests would 655f58f084eSCornelia Hucklook like this: 656f58f084eSCornelia Huck 657f58f084eSCornelia HuckGuest1:: 658f58f084eSCornelia Huck 659f58f084eSCornelia Huck CARD.DOMAIN TYPE MODE 660f58f084eSCornelia Huck ------------------------------ 661f58f084eSCornelia Huck 05 CEX5C CCA-Coproc 662f58f084eSCornelia Huck 05.0004 CEX5C CCA-Coproc 663f58f084eSCornelia Huck 05.00ab CEX5C CCA-Coproc 664f58f084eSCornelia Huck 06 CEX5A Accelerator 665f58f084eSCornelia Huck 06.0004 CEX5A Accelerator 666f58f084eSCornelia Huck 06.00ab CEX5C CCA-Coproc 667f58f084eSCornelia Huck 668f58f084eSCornelia HuckGuest2:: 669f58f084eSCornelia Huck 670f58f084eSCornelia Huck CARD.DOMAIN TYPE MODE 671f58f084eSCornelia Huck ------------------------------ 672f58f084eSCornelia Huck 05 CEX5A Accelerator 673f58f084eSCornelia Huck 05.0047 CEX5A Accelerator 674f58f084eSCornelia Huck 05.00ff CEX5A Accelerator 675f58f084eSCornelia Huck 676f58f084eSCornelia HuckGuest3:: 677f58f084eSCornelia Huck 678f58f084eSCornelia Huck CARD.DOMAIN TYPE MODE 679f58f084eSCornelia Huck ------------------------------ 680f58f084eSCornelia Huck 06 CEX5A Accelerator 681f58f084eSCornelia Huck 06.0047 CEX5A Accelerator 682f58f084eSCornelia Huck 06.00ff CEX5A Accelerator 683f58f084eSCornelia Huck 684f58f084eSCornelia HuckThese are the steps: 685f58f084eSCornelia Huck 686f58f084eSCornelia Huck1. Install the vfio_ap module on the linux host. The dependency chain for the 687f58f084eSCornelia Huck vfio_ap module is: 688f58f084eSCornelia Huck 689f58f084eSCornelia Huck * iommu 690f58f084eSCornelia Huck * s390 691f58f084eSCornelia Huck * zcrypt 692f58f084eSCornelia Huck * vfio 693f58f084eSCornelia Huck * vfio_mdev 694f58f084eSCornelia Huck * vfio_mdev_device 695f58f084eSCornelia Huck * KVM 696f58f084eSCornelia Huck 697f58f084eSCornelia Huck To build the vfio_ap module, the kernel build must be configured with the 698f58f084eSCornelia Huck following Kconfig elements selected: 699f58f084eSCornelia Huck 700f58f084eSCornelia Huck * IOMMU_SUPPORT 701f58f084eSCornelia Huck * S390 702f58f084eSCornelia Huck * ZCRYPT 703f58f084eSCornelia Huck * S390_AP_IOMMU 704f58f084eSCornelia Huck * VFIO 705f58f084eSCornelia Huck * VFIO_MDEV 706f58f084eSCornelia Huck * VFIO_MDEV_DEVICE 707f58f084eSCornelia Huck * KVM 708f58f084eSCornelia Huck 709f58f084eSCornelia Huck If using make menuconfig select the following to build the vfio_ap module:: 710f58f084eSCornelia Huck -> Device Drivers 711f58f084eSCornelia Huck -> IOMMU Hardware Support 712f58f084eSCornelia Huck select S390 AP IOMMU Support 713f58f084eSCornelia Huck -> VFIO Non-Privileged userspace driver framework 714f58f084eSCornelia Huck -> Mediated device driver framework 715f58f084eSCornelia Huck -> VFIO driver for Mediated devices 716f58f084eSCornelia Huck -> I/O subsystem 717f58f084eSCornelia Huck -> VFIO support for AP devices 718f58f084eSCornelia Huck 719f58f084eSCornelia Huck2. Secure the AP queues to be used by the three guests so that the host can not 720f58f084eSCornelia Huck access them. To secure the AP queues 05.0004, 05.0047, 05.00ab, 05.00ff, 721f58f084eSCornelia Huck 06.0004, 06.0047, 06.00ab, and 06.00ff for use by the vfio_ap device driver, 722f58f084eSCornelia Huck the corresponding APQNs must be removed from the default queue drivers pool 723f58f084eSCornelia Huck as follows:: 724f58f084eSCornelia Huck 725f58f084eSCornelia Huck echo -5,-6 > /sys/bus/ap/apmask 726f58f084eSCornelia Huck 727f58f084eSCornelia Huck echo -4,-0x47,-0xab,-0xff > /sys/bus/ap/aqmask 728f58f084eSCornelia Huck 729f58f084eSCornelia Huck This will result in AP queues 05.0004, 05.0047, 05.00ab, 05.00ff, 06.0004, 730f58f084eSCornelia Huck 06.0047, 06.00ab, and 06.00ff getting bound to the vfio_ap device driver. The 731f58f084eSCornelia Huck sysfs directory for the vfio_ap device driver will now contain symbolic links 732f58f084eSCornelia Huck to the AP queue devices bound to it:: 733f58f084eSCornelia Huck 734f58f084eSCornelia Huck /sys/bus/ap 735f58f084eSCornelia Huck ... [drivers] 736f58f084eSCornelia Huck ...... [vfio_ap] 737f58f084eSCornelia Huck ......... [05.0004] 738f58f084eSCornelia Huck ......... [05.0047] 739f58f084eSCornelia Huck ......... [05.00ab] 740f58f084eSCornelia Huck ......... [05.00ff] 741f58f084eSCornelia Huck ......... [06.0004] 742f58f084eSCornelia Huck ......... [06.0047] 743f58f084eSCornelia Huck ......... [06.00ab] 744f58f084eSCornelia Huck ......... [06.00ff] 745f58f084eSCornelia Huck 746f58f084eSCornelia Huck Keep in mind that only type 10 and newer adapters (i.e., CEX4 and later) 747f58f084eSCornelia Huck can be bound to the vfio_ap device driver. The reason for this is to 748f58f084eSCornelia Huck simplify the implementation by not needlessly complicating the design by 749f58f084eSCornelia Huck supporting older devices that will go out of service in the relatively near 750f58f084eSCornelia Huck future, and for which there are few older systems on which to test. 751f58f084eSCornelia Huck 752f58f084eSCornelia Huck The administrator, therefore, must take care to secure only AP queues that 753f58f084eSCornelia Huck can be bound to the vfio_ap device driver. The device type for a given AP 754f58f084eSCornelia Huck queue device can be read from the parent card's sysfs directory. For example, 755f58f084eSCornelia Huck to see the hardware type of the queue 05.0004:: 756f58f084eSCornelia Huck 757f58f084eSCornelia Huck cat /sys/bus/ap/devices/card05/hwtype 758f58f084eSCornelia Huck 759f58f084eSCornelia Huck The hwtype must be 10 or higher (CEX4 or newer) in order to be bound to the 760f58f084eSCornelia Huck vfio_ap device driver. 761f58f084eSCornelia Huck 762f58f084eSCornelia Huck3. Create the mediated devices needed to configure the AP matrixes for the 763f58f084eSCornelia Huck three guests and to provide an interface to the vfio_ap driver for 764f58f084eSCornelia Huck use by the guests:: 765f58f084eSCornelia Huck 766f58f084eSCornelia Huck /sys/devices/vfio_ap/matrix/ 767f58f084eSCornelia Huck ... [mdev_supported_types] 768f58f084eSCornelia Huck ...... [vfio_ap-passthrough] (passthrough mediated matrix device type) 769f58f084eSCornelia Huck ......... create 770f58f084eSCornelia Huck ......... [devices] 771f58f084eSCornelia Huck 772f58f084eSCornelia Huck To create the mediated devices for the three guests:: 773f58f084eSCornelia Huck 774f58f084eSCornelia Huck uuidgen > create 775f58f084eSCornelia Huck uuidgen > create 776f58f084eSCornelia Huck uuidgen > create 777f58f084eSCornelia Huck 778f58f084eSCornelia Huck or 779f58f084eSCornelia Huck 780f58f084eSCornelia Huck :: 781f58f084eSCornelia Huck 782f58f084eSCornelia Huck echo $uuid1 > create 783f58f084eSCornelia Huck echo $uuid2 > create 784f58f084eSCornelia Huck echo $uuid3 > create 785f58f084eSCornelia Huck 786f58f084eSCornelia Huck This will create three mediated devices in the [devices] subdirectory named 787f58f084eSCornelia Huck after the UUID used to create the mediated device. We'll call them $uuid1, 788f58f084eSCornelia Huck $uuid2 and $uuid3 and this is the sysfs directory structure after creation:: 789f58f084eSCornelia Huck 790f58f084eSCornelia Huck /sys/devices/vfio_ap/matrix/ 791f58f084eSCornelia Huck ... [mdev_supported_types] 792f58f084eSCornelia Huck ...... [vfio_ap-passthrough] 793f58f084eSCornelia Huck ......... [devices] 794f58f084eSCornelia Huck ............ [$uuid1] 795f58f084eSCornelia Huck ............... assign_adapter 796f58f084eSCornelia Huck ............... assign_control_domain 797f58f084eSCornelia Huck ............... assign_domain 798f58f084eSCornelia Huck ............... matrix 799f58f084eSCornelia Huck ............... unassign_adapter 800f58f084eSCornelia Huck ............... unassign_control_domain 801f58f084eSCornelia Huck ............... unassign_domain 802f58f084eSCornelia Huck 803f58f084eSCornelia Huck ............ [$uuid2] 804f58f084eSCornelia Huck ............... assign_adapter 805f58f084eSCornelia Huck ............... assign_control_domain 806f58f084eSCornelia Huck ............... assign_domain 807f58f084eSCornelia Huck ............... matrix 808f58f084eSCornelia Huck ............... unassign_adapter 809f58f084eSCornelia Huck ............... unassign_control_domain 810f58f084eSCornelia Huck ............... unassign_domain 811f58f084eSCornelia Huck 812f58f084eSCornelia Huck ............ [$uuid3] 813f58f084eSCornelia Huck ............... assign_adapter 814f58f084eSCornelia Huck ............... assign_control_domain 815f58f084eSCornelia Huck ............... assign_domain 816f58f084eSCornelia Huck ............... matrix 817f58f084eSCornelia Huck ............... unassign_adapter 818f58f084eSCornelia Huck ............... unassign_control_domain 819f58f084eSCornelia Huck ............... unassign_domain 820f58f084eSCornelia Huck 821f58f084eSCornelia Huck4. The administrator now needs to configure the matrixes for the mediated 822f58f084eSCornelia Huck devices $uuid1 (for Guest1), $uuid2 (for Guest2) and $uuid3 (for Guest3). 823f58f084eSCornelia Huck 824f58f084eSCornelia Huck This is how the matrix is configured for Guest1:: 825f58f084eSCornelia Huck 826f58f084eSCornelia Huck echo 5 > assign_adapter 827f58f084eSCornelia Huck echo 6 > assign_adapter 828f58f084eSCornelia Huck echo 4 > assign_domain 829f58f084eSCornelia Huck echo 0xab > assign_domain 830f58f084eSCornelia Huck 831f58f084eSCornelia Huck Control domains can similarly be assigned using the assign_control_domain 832f58f084eSCornelia Huck sysfs file. 833f58f084eSCornelia Huck 834f58f084eSCornelia Huck If a mistake is made configuring an adapter, domain or control domain, 835f58f084eSCornelia Huck you can use the ``unassign_xxx`` interfaces to unassign the adapter, domain or 836f58f084eSCornelia Huck control domain. 837f58f084eSCornelia Huck 838f58f084eSCornelia Huck To display the matrix configuration for Guest1:: 839f58f084eSCornelia Huck 840f58f084eSCornelia Huck cat matrix 841f58f084eSCornelia Huck 842f58f084eSCornelia Huck The output will display the APQNs in the format ``xx.yyyy``, where xx is 843f58f084eSCornelia Huck the adapter number and yyyy is the domain number. The output for Guest1 844f58f084eSCornelia Huck will look like this:: 845f58f084eSCornelia Huck 846f58f084eSCornelia Huck 05.0004 847f58f084eSCornelia Huck 05.00ab 848f58f084eSCornelia Huck 06.0004 849f58f084eSCornelia Huck 06.00ab 850f58f084eSCornelia Huck 851f58f084eSCornelia Huck This is how the matrix is configured for Guest2:: 852f58f084eSCornelia Huck 853f58f084eSCornelia Huck echo 5 > assign_adapter 854f58f084eSCornelia Huck echo 0x47 > assign_domain 855f58f084eSCornelia Huck echo 0xff > assign_domain 856f58f084eSCornelia Huck 857f58f084eSCornelia Huck This is how the matrix is configured for Guest3:: 858f58f084eSCornelia Huck 859f58f084eSCornelia Huck echo 6 > assign_adapter 860f58f084eSCornelia Huck echo 0x47 > assign_domain 861f58f084eSCornelia Huck echo 0xff > assign_domain 862f58f084eSCornelia Huck 863f58f084eSCornelia Huck5. Start Guest1:: 864f58f084eSCornelia Huck 865f58f084eSCornelia Huck /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid1 ... 866f58f084eSCornelia Huck 867f58f084eSCornelia Huck7. Start Guest2:: 868f58f084eSCornelia Huck 869f58f084eSCornelia Huck /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid2 ... 870f58f084eSCornelia Huck 871f58f084eSCornelia Huck7. Start Guest3:: 872f58f084eSCornelia Huck 873f58f084eSCornelia Huck /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid3 ... 874f58f084eSCornelia Huck 875f58f084eSCornelia HuckWhen the guest is shut down, the mediated matrix devices may be removed. 876f58f084eSCornelia Huck 877f58f084eSCornelia HuckUsing our example again, to remove the mediated matrix device $uuid1:: 878f58f084eSCornelia Huck 879f58f084eSCornelia Huck /sys/devices/vfio_ap/matrix/ 880f58f084eSCornelia Huck ... [mdev_supported_types] 881f58f084eSCornelia Huck ...... [vfio_ap-passthrough] 882f58f084eSCornelia Huck ......... [devices] 883f58f084eSCornelia Huck ............ [$uuid1] 884f58f084eSCornelia Huck ............... remove 885f58f084eSCornelia Huck 886f58f084eSCornelia Huck 887f58f084eSCornelia Huck echo 1 > remove 888f58f084eSCornelia Huck 889f58f084eSCornelia HuckThis will remove all of the mdev matrix device's sysfs structures including 890f58f084eSCornelia Huckthe mdev device itself. To recreate and reconfigure the mdev matrix device, 891f58f084eSCornelia Huckall of the steps starting with step 3 will have to be performed again. Note 892f58f084eSCornelia Huckthat the remove will fail if a guest using the mdev is still running. 893f58f084eSCornelia Huck 894f58f084eSCornelia HuckIt is not necessary to remove an mdev matrix device, but one may want to 895f58f084eSCornelia Huckremove it if no guest will use it during the remaining lifetime of the linux 896f58f084eSCornelia Huckhost. If the mdev matrix device is removed, one may want to also reconfigure 897f58f084eSCornelia Huckthe pool of adapters and queues reserved for use by the default drivers. 898f58f084eSCornelia Huck 899f58f084eSCornelia HuckLimitations 900f58f084eSCornelia Huck----------- 901f58f084eSCornelia Huck 902f58f084eSCornelia Huck* The KVM/kernel interfaces do not provide a way to prevent restoring an APQN 903f58f084eSCornelia Huck to the default drivers pool of a queue that is still assigned to a mediated 904f58f084eSCornelia Huck device in use by a guest. It is incumbent upon the administrator to 905f58f084eSCornelia Huck ensure there is no mediated device in use by a guest to which the APQN is 906f58f084eSCornelia Huck assigned lest the host be given access to the private data of the AP queue 907f58f084eSCornelia Huck device, such as a private key configured specifically for the guest. 908f58f084eSCornelia Huck 909f58f084eSCornelia Huck* Dynamically assigning AP resources to or unassigning AP resources from a 910f58f084eSCornelia Huck mediated matrix device - see `Configuring an AP matrix for a linux guest`_ 911f58f084eSCornelia Huck section above - while a running guest is using it is currently not supported. 912f58f084eSCornelia Huck 913f58f084eSCornelia Huck* Live guest migration is not supported for guests using AP devices. If a guest 914f58f084eSCornelia Huck is using AP devices, the vfio-ap device configured for the guest must be 915f58f084eSCornelia Huck unplugged before migrating the guest (see `Hot unplug a vfio-ap device from a 916f58f084eSCornelia Huck running guest`_ section above.) 917