845 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3=========================================4IAA Compression Accelerator Crypto Driver5=========================================6 7Tom Zanussi <tom.zanussi@linux.intel.com>8 9The IAA crypto driver supports compression/decompression compatible10with the DEFLATE compression standard described in RFC 1951, which is11the compression/decompression algorithm exported by this module.12 13The IAA hardware spec can be found here:14 15 https://cdrdv2.intel.com/v1/dl/getContent/72185816 17The iaa_crypto driver is designed to work as a layer underneath18higher-level compression devices such as zswap.19 20Users can select IAA compress/decompress acceleration by specifying21one of the supported IAA compression algorithms in whatever facility22allows compression algorithms to be selected.23 24For example, a zswap device can select the IAA 'fixed' mode25represented by selecting the 'deflate-iaa' crypto compression26algorithm::27 28 # echo deflate-iaa > /sys/module/zswap/parameters/compressor29 30This will tell zswap to use the IAA 'fixed' compression mode for all31compresses and decompresses.32 33Currently, there is only one compression modes available, 'fixed'34mode.35 36The 'fixed' compression mode implements the compression scheme37specified by RFC 1951 and is given the crypto algorithm name38'deflate-iaa'. (Because the IAA hardware has a 4k history-window39limitation, only buffers <= 4k, or that have been compressed using a40<= 4k history window, are technically compliant with the deflate spec,41which allows for a window of up to 32k. Because of this limitation,42the IAA fixed mode deflate algorithm is given its own algorithm name43rather than simply 'deflate').44 45 46Config options and other setup47==============================48 49The IAA crypto driver is available via menuconfig using the following50path::51 52 Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression Accelerator53 54In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO.55 56The IAA crypto driver also supports statistics, which are available57via menuconfig using the following path::58 59 Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression -> Enable Intel(R) IAA Compression Accelerator Statistics60 61In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS.62 63The following config options should also be enabled::64 65 CONFIG_IRQ_REMAP=y66 CONFIG_INTEL_IOMMU=y67 CONFIG_INTEL_IOMMU_SVM=y68 CONFIG_PCI_ATS=y69 CONFIG_PCI_PRI=y70 CONFIG_PCI_PASID=y71 CONFIG_INTEL_IDXD=m72 CONFIG_INTEL_IDXD_SVM=y73 74IAA is one of the first Intel accelerator IPs that can work in75conjunction with the Intel IOMMU. There are multiple modes that exist76for testing. Based on IOMMU configuration, there are 3 modes::77 78 - Scalable79 - Legacy80 - No IOMMU81 82 83Scalable mode84-------------85 86Scalable mode supports Shared Virtual Memory (SVM or SVA). It is87entered when using the kernel boot commandline::88 89 intel_iommu=on,sm_on90 91with VT-d turned on in BIOS.92 93With scalable mode, both shared and dedicated workqueues are available94for use.95 96For scalable mode, the following BIOS settings should be enabled::97 98 Socket Configuration > IIO Configuration > Intel VT for Directed I/O (VT-d) > Intel VT for Directed I/O99 100 Socket Configuration > IIO Configuration > PCIe ENQCMD > ENQCMDS101 102 103Legacy mode104-----------105 106Legacy mode is entered when using the kernel boot commandline::107 108 intel_iommu=off109 110or VT-d is not turned on in BIOS.111 112If you have booted into Linux and not sure if VT-d is on, do a "dmesg113| grep -i dmar". If you don't see a number of DMAR devices enumerated,114most likely VT-d is not on.115 116With legacy mode, only dedicated workqueues are available for use.117 118 119No IOMMU mode120-------------121 122No IOMMU mode is entered when using the kernel boot commandline::123 124 iommu=off.125 126With no IOMMU mode, only dedicated workqueues are available for use.127 128 129Usage130=====131 132accel-config133------------134 135When loaded, the iaa_crypto driver automatically creates a default136configuration and enables it, and assigns default driver attributes.137If a different configuration or set of driver attributes is required,138the user must first disable the IAA devices and workqueues, reset the139configuration, and then re-register the deflate-iaa algorithm with the140crypto subsystem by removing and reinserting the iaa_crypto module.141 142The :ref:`iaa_disable_script` in the 'Use Cases'143section below can be used to disable the default configuration.144 145See :ref:`iaa_default_config` below for details of the default146configuration.147 148More likely than not, however, and because of the complexity and149configurability of the accelerator devices, the user will want to150configure the device and manually enable the desired devices and151workqueues.152 153The userspace tool to help doing that is called accel-config. Using154accel-config to configure device or loading a previously saved config155is highly recommended. The device can be controlled via sysfs156directly but comes with the warning that you should do this ONLY if157you know exactly what you are doing. The following sections will not158cover the sysfs interface but assumes you will be using accel-config.159 160The :ref:`iaa_sysfs_config` section in the appendix below can be161consulted for the sysfs interface details if interested.162 163The accel-config tool along with instructions for building it can be164found here:165 166 https://github.com/intel/idxd-config/#readme167 168Typical usage169-------------170 171In order for the iaa_crypto module to actually do any172compression/decompression work on behalf of a facility, one or more173IAA workqueues need to be bound to the iaa_crypto driver.174 175For instance, here's an example of configuring an IAA workqueue and176binding it to the iaa_crypto driver (note that device names are177specified as 'iax' rather than 'iaa' - this is because upstream still178has the old 'iax' device naming in place) ::179 180 # configure wq1.0181 182 accel-config config-wq --group-id=0 --mode=dedicated --type=kernel --priority=10 --name="iaa_crypto" --driver-name="crypto" iax1/wq1.0183 184 accel-config config-engine iax1/engine1.0 --group-id=0185 186 # enable IAA device iax1187 188 accel-config enable-device iax1189 190 # enable wq1.0 on IAX device iax1191 192 accel-config enable-wq iax1/wq1.0193 194Whenever a new workqueue is bound to or unbound from the iaa_crypto195driver, the available workqueues are 'rebalanced' such that work196submitted from a particular CPU is given to the most appropriate197workqueue available. Current best practice is to configure and bind198at least one workqueue for each IAA device, but as long as there is at199least one workqueue configured and bound to any IAA device in the200system, the iaa_crypto driver will work, albeit most likely not as201efficiently.202 203The IAA crypto algorigthms is operational and compression and204decompression operations are fully enabled following the successful205binding of the first IAA workqueue to the iaa_crypto driver.206 207Similarly, the IAA crypto algorithm is not operational and compression208and decompression operations are disabled following the unbinding of209the last IAA worqueue to the iaa_crypto driver.210 211As a result, the IAA crypto algorithms and thus the IAA hardware are212only available when one or more workques are bound to the iaa_crypto213driver.214 215When there are no IAA workqueues bound to the driver, the IAA crypto216algorithms can be unregistered by removing the module.217 218 219Driver attributes220-----------------221 222There are a couple user-configurable driver attributes that can be223used to configure various modes of operation. They're listed below,224along with their default values. To set any of these attributes, echo225the appropriate values to the attribute file located under226/sys/bus/dsa/drivers/crypto/227 228The attribute settings at the time the IAA algorithms are registered229are captured in each algorithm's crypto_ctx and used for all compresses230and decompresses when using that algorithm.231 232The available attributes are:233 234 - verify_compress235 236 Toggle compression verification. If set, each compress will be237 internally decompressed and the contents verified, returning error238 codes if unsuccessful. This can be toggled with 0/1::239 240 echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress241 242 The default setting is '1' - verify all compresses.243 244 - sync_mode245 246 Select mode to be used to wait for completion of each compresses247 and decompress operation.248 249 The crypto async interface support implemented by iaa_crypto250 provides an implementation that satisfies the interface but does251 so in a synchronous manner - it fills and submits the IDXD252 descriptor and then loops around waiting for it to complete before253 returning. This isn't a problem at the moment, since all existing254 callers (e.g. zswap) wrap any asynchronous callees in a255 synchronous wrapper anyway.256 257 The iaa_crypto driver does however provide true asynchronous258 support for callers that can make use of it. In this mode, it259 fills and submits the IDXD descriptor, then returns immediately260 with -EINPROGRESS. The caller can then either poll for completion261 itself, which requires specific code in the caller which currently262 nothing in the upstream kernel implements, or go to sleep and wait263 for an interrupt signaling completion. This latter mode is264 supported by current users in the kernel such as zswap via265 synchronous wrappers. Although it is supported this mode is266 significantly slower than the synchronous mode that does the267 polling in the iaa_crypto driver previously mentioned.268 269 This mode can be enabled by writing 'async_irq' to the sync_mode270 iaa_crypto driver attribute::271 272 echo async_irq > /sys/bus/dsa/drivers/crypto/sync_mode273 274 Async mode without interrupts (caller must poll) can be enabled by275 writing 'async' to it::276 277 echo async > /sys/bus/dsa/drivers/crypto/sync_mode278 279 The mode that does the polling in the iaa_crypto driver can be280 enabled by writing 'sync' to it::281 282 echo sync > /sys/bus/dsa/drivers/crypto/sync_mode283 284 The default mode is 'sync'.285 286.. _iaa_default_config:287 288IAA Default Configuration289-------------------------290 291When the iaa_crypto driver is loaded, each IAA device has a single292work queue configured for it, with the following attributes::293 294 mode "dedicated"295 threshold 0296 size Total WQ Size from WQCAP297 priority 10298 type IDXD_WQT_KERNEL299 group 0300 name "iaa_crypto"301 driver_name "crypto"302 303The devices and workqueues are also enabled and therefore the driver304is ready to be used without any additional configuration.305 306The default driver attributes in effect when the driver is loaded are::307 308 sync_mode "sync"309 verify_compress 1310 311In order to change either the device/work queue or driver attributes,312the enabled devices and workqueues must first be disabled. In order313to have the new configuration applied to the deflate-iaa crypto314algorithm, it needs to be re-registered by removing and reinserting315the iaa_crypto module. The :ref:`iaa_disable_script` in the 'Use316Cases' section below can be used to disable the default configuration.317 318Statistics319==========320 321If the optional debugfs statistics support is enabled, the IAA crypto322driver will generate statistics which can be accessed in debugfs at::323 324 # ls -al /sys/kernel/debug/iaa-crypto/325 total 0326 drwxr-xr-x 2 root root 0 Mar 3 07:55 .327 drwx------ 53 root root 0 Mar 3 07:55 ..328 -rw-r--r-- 1 root root 0 Mar 3 07:55 global_stats329 -rw-r--r-- 1 root root 0 Mar 3 07:55 stats_reset330 -rw-r--r-- 1 root root 0 Mar 3 07:55 wq_stats331 332The global_stats file shows a set of global statistics collected since333the driver has been loaded or reset::334 335 # cat global_stats336 global stats:337 total_comp_calls: 4300338 total_decomp_calls: 4164339 total_sw_decomp_calls: 0340 total_comp_bytes_out: 5993989341 total_decomp_bytes_in: 5993989342 total_completion_einval_errors: 0343 total_completion_timeout_errors: 0344 total_completion_comp_buf_overflow_errors: 136345 346The wq_stats file shows per-wq stats, a set for each iaa device and wq347in addition to some global stats::348 349 # cat wq_stats350 iaa device:351 id: 1352 n_wqs: 1353 comp_calls: 0354 comp_bytes: 0355 decomp_calls: 0356 decomp_bytes: 0357 wqs:358 name: iaa_crypto359 comp_calls: 0360 comp_bytes: 0361 decomp_calls: 0362 decomp_bytes: 0363 364 iaa device:365 id: 3366 n_wqs: 1367 comp_calls: 0368 comp_bytes: 0369 decomp_calls: 0370 decomp_bytes: 0371 wqs:372 name: iaa_crypto373 comp_calls: 0374 comp_bytes: 0375 decomp_calls: 0376 decomp_bytes: 0377 378 iaa device:379 id: 5380 n_wqs: 1381 comp_calls: 1360382 comp_bytes: 1999776383 decomp_calls: 0384 decomp_bytes: 0385 wqs:386 name: iaa_crypto387 comp_calls: 1360388 comp_bytes: 1999776389 decomp_calls: 0390 decomp_bytes: 0391 392 iaa device:393 id: 7394 n_wqs: 1395 comp_calls: 2940396 comp_bytes: 3994213397 decomp_calls: 4164398 decomp_bytes: 5993989399 wqs:400 name: iaa_crypto401 comp_calls: 2940402 comp_bytes: 3994213403 decomp_calls: 4164404 decomp_bytes: 5993989405 ...406 407Writing to 'stats_reset' resets all the stats, including the408per-device and per-wq stats::409 410 # echo 1 > stats_reset411 # cat wq_stats412 global stats:413 total_comp_calls: 0414 total_decomp_calls: 0415 total_comp_bytes_out: 0416 total_decomp_bytes_in: 0417 total_completion_einval_errors: 0418 total_completion_timeout_errors: 0419 total_completion_comp_buf_overflow_errors: 0420 ...421 422 423Use cases424=========425 426Simple zswap test427-----------------428 429For this example, the kernel should be configured according to the430dedicated mode options described above, and zswap should be enabled as431well::432 433 CONFIG_ZSWAP=y434 435This is a simple test that uses iaa_compress as the compressor for a436swap (zswap) device. It sets up the zswap device and then uses the437memory_memadvise program listed below to forcibly swap out and in a438specified number of pages, demonstrating both compress and decompress.439 440The zswap test expects the work queues for each IAA device on the441system to be configured properly as a kernel workqueue with a442workqueue driver_name of "crypto".443 444The first step is to make sure the iaa_crypto module is loaded::445 446 modprobe iaa_crypto447 448If the IAA devices and workqueues haven't previously been disabled and449reconfigured, then the default configuration should be in place and no450further IAA configuration is necessary. See :ref:`iaa_default_config`451below for details of the default configuration.452 453If the default configuration is in place, you should see the iaa454devices and wq0s enabled::455 456 # cat /sys/bus/dsa/devices/iax1/state457 enabled458 # cat /sys/bus/dsa/devices/iax1/wq1.0/state459 enabled460 461To demonstrate that the following steps work as expected, these462commands can be used to enable debug output::463 464 # echo -n 'module iaa_crypto +p' > /sys/kernel/debug/dynamic_debug/control465 # echo -n 'module idxd +p' > /sys/kernel/debug/dynamic_debug/control466 467Use the following commands to enable zswap::468 469 # echo 0 > /sys/module/zswap/parameters/enabled470 # echo 50 > /sys/module/zswap/parameters/max_pool_percent471 # echo deflate-iaa > /sys/module/zswap/parameters/compressor472 # echo zsmalloc > /sys/module/zswap/parameters/zpool473 # echo 1 > /sys/module/zswap/parameters/enabled474 # echo 100 > /proc/sys/vm/swappiness475 # echo never > /sys/kernel/mm/transparent_hugepage/enabled476 # echo 1 > /proc/sys/vm/overcommit_memory477 478Now you can now run the zswap workload you want to measure. For479example, using the memory_memadvise code below, the following command480will swap in and out 100 pages::481 482 ./memory_madvise 100483 484 Allocating 100 pages to swap in/out485 Swapping out 100 pages486 Swapping in 100 pages487 Swapped out and in 100 pages488 489You should see something like the following in the dmesg output::490 491 [ 404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096492 [ 404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192493 [ 404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568494 [ 404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0495 ...496 497Now that basic functionality has been demonstrated, the defaults can498be erased and replaced with a different configuration. To do that,499first disable zswap::500 501 # echo lzo > /sys/module/zswap/parameters/compressor502 # swapoff -a503 # echo 0 > /sys/module/zswap/parameters/accept_threshold_percent504 # echo 0 > /sys/module/zswap/parameters/max_pool_percent505 # echo 0 > /sys/module/zswap/parameters/enabled506 # echo 0 > /sys/module/zswap/parameters/enabled507 508Then run the :ref:`iaa_disable_script` in the 'Use Cases' section509below to disable the default configuration.510 511Finally turn swap back on::512 513 # swapon -a514 515Following all that the IAA device(s) can now be re-configured and516enabled as desired for further testing. Below is one example.517 518The zswap test expects the work queues for each IAA device on the519system to be configured properly as a kernel workqueue with a520workqueue driver_name of "crypto".521 522The below script automatically does that::523 524 #!/bin/bash525 526 echo "IAA devices:"527 lspci -d:0cfe528 echo "# IAA devices:"529 lspci -d:0cfe | wc -l530 531 #532 # count iaa instances533 #534 iaa_dev_id="0cfe"535 num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)536 echo "Found ${num_iaa} IAA instances"537 538 #539 # disable iaa wqs and devices540 #541 echo "Disable IAA"542 543 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do544 echo disable wq iax${i}/wq${i}.0545 accel-config disable-wq iax${i}/wq${i}.0546 echo disable iaa iax${i}547 accel-config disable-device iax${i}548 done549 550 echo "End Disable IAA"551 552 echo "Reload iaa_crypto module"553 554 rmmod iaa_crypto555 modprobe iaa_crypto556 557 echo "End Reload iaa_crypto module"558 559 #560 # configure iaa wqs and devices561 #562 echo "Configure IAA"563 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do564 accel-config config-wq --group-id=0 --mode=dedicated --wq-size=128 --priority=10 --type=kernel --name="iaa_crypto" --driver-name="crypto" iax${i}/wq${i}.0565 accel-config config-engine iax${i}/engine${i}.0 --group-id=0566 done567 568 echo "End Configure IAA"569 570 #571 # enable iaa wqs and devices572 #573 echo "Enable IAA"574 575 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do576 echo enable iaa iax${i}577 accel-config enable-device iax${i}578 echo enable wq iax${i}/wq${i}.0579 accel-config enable-wq iax${i}/wq${i}.0580 done581 582 echo "End Enable IAA"583 584When the workqueues are bound to the iaa_crypto driver, you should585see something similar to the following in dmesg output if you've586enabled debug output (echo -n 'module iaa_crypto +p' >587/sys/kernel/debug/dynamic_debug/control)::588 589 [ 60.752344] idxd 0000:f6:02.0: add_iaa_wq: added wq 000000004068d14d to iaa 00000000c9585ba2, n_wq 1590 [ 60.752346] iaa_crypto: rebalance_wq_table: nr_nodes=2, nr_cpus 160, nr_iaa 8, cpus_per_iaa 20591 [ 60.752347] iaa_crypto: rebalance_wq_table: iaa=0592 [ 60.752349] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)593 [ 60.752350] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)594 [ 60.752352] iaa_crypto: rebalance_wq_table: assigned wq for cpu=0, node=0 = wq 00000000c8bb4452595 [ 60.752354] iaa_crypto: rebalance_wq_table: iaa=0596 [ 60.752355] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)597 [ 60.752356] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)598 [ 60.752358] iaa_crypto: rebalance_wq_table: assigned wq for cpu=1, node=0 = wq 00000000c8bb4452599 [ 60.752359] iaa_crypto: rebalance_wq_table: iaa=0600 [ 60.752360] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)601 [ 60.752361] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)602 [ 60.752362] iaa_crypto: rebalance_wq_table: assigned wq for cpu=2, node=0 = wq 00000000c8bb4452603 [ 60.752364] iaa_crypto: rebalance_wq_table: iaa=0604 .605 .606 .607 608Once the workqueues and devices have been enabled, the IAA crypto609algorithms are enabled and available. When the IAA crypto algorithms610have been successfully enabled, you should see the following dmesg611output::612 613 [ 64.893759] iaa_crypto: iaa_crypto_enable: iaa_crypto now ENABLED614 615Now run the following zswap-specific setup commands to have zswap use616the 'fixed' compression mode::617 618 echo 0 > /sys/module/zswap/parameters/enabled619 echo 50 > /sys/module/zswap/parameters/max_pool_percent620 echo deflate-iaa > /sys/module/zswap/parameters/compressor621 echo zsmalloc > /sys/module/zswap/parameters/zpool622 echo 1 > /sys/module/zswap/parameters/enabled623 624 echo 100 > /proc/sys/vm/swappiness625 echo never > /sys/kernel/mm/transparent_hugepage/enabled626 echo 1 > /proc/sys/vm/overcommit_memory627 628Finally, you can now run the zswap workload you want to measure. For629example, using the code below, the following command will swap in and630out 100 pages::631 632 ./memory_madvise 100633 634 Allocating 100 pages to swap in/out635 Swapping out 100 pages636 Swapping in 100 pages637 Swapped out and in 100 pages638 639You should see something like the following in the dmesg output if640you've enabled debug output (echo -n 'module iaa_crypto +p' >641/sys/kernel/debug/dynamic_debug/control)::642 643 [ 404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096644 [ 404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192645 [ 404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568646 [ 404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0647 [ 409.203227] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228648 [ 409.203235] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21ee3dc000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096649 [ 409.203239] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21ee3dc000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0650 [ 409.203254] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228651 [ 409.203256] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21f1551000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096652 [ 409.203257] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21f1551000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0653 654In order to unregister the IAA crypto algorithms, and register new655ones using different parameters, any users of the current algorithm656should be stopped and the IAA workqueues and devices disabled.657 658In the case of zswap, remove the IAA crypto algorithm as the659compressor and turn off swap (to remove all references to660iaa_crypto)::661 662 echo lzo > /sys/module/zswap/parameters/compressor663 swapoff -a664 665 echo 0 > /sys/module/zswap/parameters/accept_threshold_percent666 echo 0 > /sys/module/zswap/parameters/max_pool_percent667 echo 0 > /sys/module/zswap/parameters/enabled668 669Once zswap is disabled and no longer using iaa_crypto, the IAA wqs and670devices can be disabled.671 672.. _iaa_disable_script:673 674IAA disable script675------------------676 677The below script automatically does that::678 679 #!/bin/bash680 681 echo "IAA devices:"682 lspci -d:0cfe683 echo "# IAA devices:"684 lspci -d:0cfe | wc -l685 686 #687 # count iaa instances688 #689 iaa_dev_id="0cfe"690 num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)691 echo "Found ${num_iaa} IAA instances"692 693 #694 # disable iaa wqs and devices695 #696 echo "Disable IAA"697 698 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do699 echo disable wq iax${i}/wq${i}.0700 accel-config disable-wq iax${i}/wq${i}.0701 echo disable iaa iax${i}702 accel-config disable-device iax${i}703 done704 705 echo "End Disable IAA"706 707Finally, at this point the iaa_crypto module can be removed, which708will unregister the current IAA crypto algorithms::709 710 rmmod iaa_crypto711 712 713memory_madvise.c (gcc -o memory_memadvise memory_madvise.c)::714 715 #include <stdio.h>716 #include <stdlib.h>717 #include <string.h>718 #include <unistd.h>719 #include <sys/mman.h>720 #include <linux/mman.h>721 722 #ifndef MADV_PAGEOUT723 #define MADV_PAGEOUT 21 /* force pages out immediately */724 #endif725 726 #define PG_SZ 4096727 728 int main(int argc, char **argv)729 {730 int i, nr_pages = 1;731 int64_t *dump_ptr;732 char *addr, *a;733 int loop = 1;734 735 if (argc > 1)736 nr_pages = atoi(argv[1]);737 738 printf("Allocating %d pages to swap in/out\n", nr_pages);739 740 /* allocate pages */741 addr = mmap(NULL, nr_pages * PG_SZ, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);742 *addr = 1;743 744 /* initialize data in page to all '*' chars */745 memset(addr, '*', nr_pages * PG_SZ);746 747 printf("Swapping out %d pages\n", nr_pages);748 749 /* Tell kernel to swap it out */750 madvise(addr, nr_pages * PG_SZ, MADV_PAGEOUT);751 752 while (loop > 0) {753 /* Wait for swap out to finish */754 sleep(5);755 756 a = addr;757 758 printf("Swapping in %d pages\n", nr_pages);759 760 /* Access the page ... this will swap it back in again */761 for (i = 0; i < nr_pages; i++) {762 if (a[0] != '*') {763 printf("Bad data from decompress!!!!!\n");764 765 dump_ptr = (int64_t *)a;766 for (int j = 0; j < 100; j++) {767 printf(" page %d data: %#llx\n", i, *dump_ptr);768 dump_ptr++;769 }770 }771 772 a += PG_SZ;773 }774 775 loop --;776 }777 778 printf("Swapped out and in %d pages\n", nr_pages);779 780Appendix781========782 783.. _iaa_sysfs_config:784 785IAA sysfs config interface786--------------------------787 788Below is a description of the IAA sysfs interface, which as mentioned789in the main document, should only be used if you know exactly what you790are doing. Even then, there's no compelling reason to use it directly791since accel-config can do everything the sysfs interface can and in792fact accel-config is based on it under the covers.793 794The 'IAA config path' is /sys/bus/dsa/devices and contains795subdirectories representing each IAA device, workqueue, engine, and796group. Note that in the sysfs interface, the IAA devices are actually797named using iax e.g. iax1, iax3, etc. (Note that IAA devices are the798odd-numbered devices; the even-numbered devices are DSA devices and799can be ignored for IAA).800 801The 'IAA device bind path' is /sys/bus/dsa/drivers/idxd/bind and is802the file that is written to enable an IAA device.803 804The 'IAA workqueue bind path' is /sys/bus/dsa/drivers/crypto/bind and805is the file that is written to enable an IAA workqueue.806 807Similarly /sys/bus/dsa/drivers/idxd/unbind and808/sys/bus/dsa/drivers/crypto/unbind are used to disable IAA devices and809workqueues.810 811The basic sequence of commands needed to set up the IAA devices and812workqueues is:813 814For each device::815 1) Disable any workqueues enabled on the device. For example to816 disable workques 0 and 1 on IAA device 3::817 818 # echo wq3.0 > /sys/bus/dsa/drivers/crypto/unbind819 # echo wq3.1 > /sys/bus/dsa/drivers/crypto/unbind820 821 2) Disable the device. For example to disable IAA device 3::822 823 # echo iax3 > /sys/bus/dsa/drivers/idxd/unbind824 825 3) configure the desired workqueues. For example, to configure826 workqueue 3 on IAA device 3::827 828 # echo dedicated > /sys/bus/dsa/devices/iax3/wq3.3/mode829 # echo 128 > /sys/bus/dsa/devices/iax3/wq3.3/size830 # echo 0 > /sys/bus/dsa/devices/iax3/wq3.3/group_id831 # echo 10 > /sys/bus/dsa/devices/iax3/wq3.3/priority832 # echo "kernel" > /sys/bus/dsa/devices/iax3/wq3.3/type833 # echo "iaa_crypto" > /sys/bus/dsa/devices/iax3/wq3.3/name834 # echo "crypto" > /sys/bus/dsa/devices/iax3/wq3.3/driver_name835 836 4) Enable the device. For example to enable IAA device 3::837 838 # echo iax3 > /sys/bus/dsa/drivers/idxd/bind839 840 5) Enable the desired workqueues on the device. For example to841 enable workques 0 and 1 on IAA device 3::842 843 # echo wq3.0 > /sys/bus/dsa/drivers/crypto/bind844 # echo wq3.1 > /sys/bus/dsa/drivers/crypto/bind845