crypto: Add Intel Analytics Accelerator (IAA) crypto compression driver
Subsystems (6)
v10 cover crypto: Add Intel Analytics Accelerator (IAA) crypto compression driver
Hi, this is v10 of the IAA crypto driver, incorporating feedback from v9.
v10 changes:
- Fixed the warnings pointed out in v9 when using 'make W=1 C=1'.
- Added a new patch, 'dmaengine: idxd: Add support for device/wq defaults' which auto-configures a default set of devices and wqs so users don't have to do any IAA configuration/setup if they don't want to. Also updated the Documentation accordingly.
- Removed the 'dmaengine: idxd: add wq driver name support for accel-config user tool' patch since it's now upstream.
- Added a section (in the Appendix) to Documentation/driver-api/crypto/iaa/iaa-crypto.rst describing the sysfs interface.
- While converting my testing scripts to accel-config, realized accel-config won't allow disabling the wqs if client_count is > 0, so to address it moved the idxd_wq_get() into iaa_wq_get().
- Fixed a bug in the pr_debug() in wq_table_next_wq(), noticed while testing.
v9 changes:
- Renamed drv_enable/disable_wq() to idxd_drv_enable/disable_wq() and exported it, changing all existing callers as well as the iaa_crypto driver.
- While testing, ran into a use-after-free bug in the irq support flagged by KASAN so fixed that up in iaa_compress() (added missing disable_async check).
- Also, while fixing the use-after-free bug, rearranged the out:
part of iaa_desc_complete() to make it cleaner.
- Also for the verify cases, reversed the dma mapping by adding and calling a new iaa_remap_for_verify() function, since verify basically does a decompress after reversing the src and dst buffers.
- Added new Acked-by and Reviewed-by tags.
v8 changes:
- Rebased to current cryptodev tree.
- Added generic-deflate software fallback for decompression in cases where there's a hardware failure that would otherwise prevent the data being recovered.
- Changed the driver_name code to use strim().
- Changed the null-destination cases to use sgl_alloc_order() rather than sgl_alloc().
- Added more Reviewed-by tags.
v7 changes:
- Rebased to current cryptodev tree.
- Removed 'canned' compression mode (deflate-iaa-canned) and fixed up dependencies in other patches and Documentation.
- Removed op_block checks.
- Removed a stray debugging #ifdef.
- Changed sysfs-driver-dma-idxd driver_name version to 6.6.0.
v6 changes:
- Rebased to current cryptodev tree.
- Changed code to create/register separate algorithms for each compression mode - one for 'fixed' (deflate-iaa) and one for 'canned' (deflate-iaa-canned).
- Got rid of 'compression_mode' attribute and all the compression mode code that deals with 'active' compression modes, since there's no longer a single active compression mode.
- Use crypto_ctx to allow common compress/decompress code to distinguish between the different compression modes. Also use it to capture settings such as verify_compress, use_irq, etc. In addition to being cleaner, this will allow for easier performance comparisons using different modes/settings.
- Update Documentation and comments to reflect the changes.
- Fixed a bug found by Rex Zhang in decompress_header() which unmapped src2 rather than src as it should have. Thanks, Rex!
v5 changes:
- Rebased to current cryptodev tree.
- Changed sysfs-driver-dma-idxd driver_name version to 6.5.0.
- Renamed wq private accessor functions to idxd_wq_set/get_private().
v4 changes:
- Added and used DRIVER_NAME_SIZE for wq driver_name.
- Changed all spaces to tabs in CRYPTO_DEV_IAA_CRYPTO_STATS config menu.
- Removed the private_data void * from wq and replaced with wq_confdev() instead, as suggested by Dave Jiang.
- Added more Reviewed-by tags.
v3 changes:
- Reworked the code to only allow the registered crypto alg to be unregistered by removing the module. Also added an iaa_wq_get() and iaa_wq_put() to take/give up a reference to the work queue while there are compresses/decompresses in flight. This is synchronized with the wq remove function, so that the iaa_wq/iaa_devices can't go away beneath active operations. This was tested by removing/disabling the iaa wqs/devices while operations were in flight.
- Simplified the rebalance code and removed cpu_to_iaa() function since it was overly complicated and wasn't actually working as advertised.
- As a result of reworking the above code, fixed several bugs such as possibly unregistering an unregistered crypto alg, a memory leak where iaa_wqs weren't being freed, and making sure the compression schemes were registered before registering the driver.
- Added set_/idxd_wq_private() accessors for wq private data.
- Added missing XPORT_SYMBOL_NS_GPL() to [PATCH 04/15] dmaengine:
idxd: Export descriptor management functions
- Added Dave's Reviewed-by: tags from v2.
- Updated Documentation and commit messages to reflect the changes above.
- Rebased to to cryptodev tree, since that has the earlier changes that moved the intel drivers to crypto/intel.
v2 changes:
- Removed legacy interface and all related code; merged async interface into main deflate patch.
- Added support for the null destination case. Thanks to Giovanni Cabiddu for making me aware of this as well as the selftests for it.
- Had to do some rearrangement of the code in order to pass all the selftests. Also added a testcase for 'canned'.
- Moved the iaa crypto driver to drivers/crypto/intel, and moved all the other intel drivers there as well (which will be posted as a separate series immediately following this one).
- Added an iaa crypto section to MAINTAINERS.
- Updated the documenation and commit messages to reflect the removal of the legacy interface.
- Changed kernel version from 6.3.0 to 6.4.0 in patch 01/15 (wq driver name support)
v1:
This series adds Linux crypto algorithm support for Intel® In-memory Analytics Accelerator (Intel IAA) [1] hardware compression and decompression, which is available on Sapphire Rapids systems.
The IAA crypto support is implemented as an IDXD sub-driver. The IDXD driver already present in the kernel provides discovery and management of the IAA devices on a system, as well as all the functionality needed to manage, submit, and wait for completion of work executed on them. The first 7 patches (patches starting with dmaengine:) add small bits of underlying IDXD plumbing needed to allow external sub-drivers to take advantage of this support and claim ownership of specific IAA devices and workqueues.
The remaining patches add the main support for this feature via the crypto API, making it transparently accessible to kernel features that can make use of it such as zswap and zram (patches starting with crypto – iaa:).
These include both sync/async support for the deflate algorithm implemented by the IAA hardware, as well as an additional option for driver statistics and Documentation.
Patch 8 ('[PATCH 08/15] crypto: iaa - Add IAA Compression Accelerator Documentation') describes the IAA crypto driver in detail; the following is just a high-level synopsis meant to aid the following discussion.
The IAA hardware is fairly complex and generally requires a knowledgeable administrator with sufficiently detailed understanding of the hardware to set it up before it can be used. As mentioned in the Documentation, this typically requires using a special tool called accel-config to enumerate and configure IAA workqueues, engines, etc, although this can also be done using only sysfs files.
The operation of the driver mirrors this requirement and only allows the hardware to be accessed via the crypto layer once the hardware has been configured and bound to the the IAA crypto driver. As an IDXD sub-driver, the IAA crypto driver essentially takes ownership of the hardware until it is given up explicitly by the administrator. This occurs automatically when the administrator enables the first IAA workqueue or disables the last one; the iaa_crypto (sync and async) algorithms are registered when the first workqueue is enabled, and deregistered when the last one is disabled.
The normal sequence of operations would normally be:
< configure the hardware using accel-config or sysfs >
< configure the iaa crypto driver (see below) >
< configure the subsystem e.g. zswap/zram to use the iaa_crypto algo >
< run the workload >
There are a small number of iaa_crypto driver attributes that the administrator can configure, and which also need to be configured before the algorithm is enabled:
compression_mode:
The IAA crypto driver supports an extensible interface supporting any number of different compression modes that can be tailored to specific types of workloads. These are implemented as tables and given arbitrary names describing their intent.
There are currently only 2 compression modes, “canned” and “fixed”. In order to set a compression mode, echo the mode’s name to the compression_mode driver attribute:
echo "canned" > /sys/bus/dsa/drivers/crypto/compression_mode
There are a few other available iaa_crypto driver attributes (see Documentation for details) but the main one we want to consider in detail for now is the ‘sync_mode’ attribute.
The ‘sync_mode’ attribute has 3 possible settings: ‘sync’, ‘async’, and ‘async_irq’.
The context for these different modes is that although the iaa_crypto driver implements the asynchronous crypto interface, the async interface is currently only used in a synchronous way by facilities like zswap that make use of it.
This is fine for software compress/decompress algorithms, since there’s no real benefit in being able to use a truly asynchronous interface with them. This isn’t the case, though, for hardware compress/decompress engines such as IAA, where truly asynchronous behavior is beneficial if not completely necessary to make optimal use of the hardware.
The IAA crypto driver ‘sync_mode’ support should allow facilities such as zswap to ‘support async (de)compression in some way [2]’ once they are modified to actually make use of it.
When the ‘async_irq’ sync_mode is specified, the driver sets the bits in the IAA work descriptor to generate an irq when the work completes. So for every compression or decompression, the IAA acomp_alg implementations called by crypto_acomp_compress/decompress() simply set up the descriptor, turn on the 'request irq' bit and return immediately with -EINPROGRESS. When the work completes, the irq fires and the IDXD driver’s irq thread for that irq invokes the callback the iaa_crypto module registered with IDXD. When the irq thread gets scheduled, it wakes up the caller, which could be for instance zswap, waiting synchronously via crypto_wait_req().
Using the simple madvise test program in '[PATCH 08/15] crypto: iaa - Add IAA Compression Accelerator Documentation' along with a set of pages from the spec17 benchmark and tracepoint instrumentation measuring the time taken between the start and end of each compress and decompress, this case, async_irq, takes on average 6,847 ns for compression and 5,840 ns for decompression. (See Table 1 below for a summary of all the tests.)
When sync_mode is set to ‘sync’, the interrupt bit is not set and the work descriptor is submitted in the same way it was for the previous case. In this case the call doesn’t return but rather loops around waiting in the iaa_crypto driver’s check_completion() function which continually checks the descriptor’s completion bit until it finds it set to ‘completed’. It then returns to the caller, again for example zswap waiting in crypto_wait_req(). From the standpoint of zswap, this case is exactly the same as the previous case, the difference seen only in the crypto layer and the iaa_crypto driver internally; from its standpoint they’re both synchronous calls. There is however a large performance difference: an average of 3,177 ns for compress and 2,235 ns for decompress.
The final sync_mode is ‘async’. In this case also the interrupt bit is not set and the work descriptor is submitted, returning immediately to the caller with -EINPROGRESS. Because there’s no interrupt set to notify anyone when the work completes, the caller needs to somehow check for work completion. Because core code like zswap can’t do this directly by for example calling iaa_crypto’s check_completion(), there would need to be some changes made to code like zswap and the crypto layer in order to take advantage of this mode. As such, there are no numbers to share for this mode.
Finally, just a quick discussion of the remaining numbers in Table 1, those comparing the iaa_crypto sync and async irq cases to software deflate. Software deflate took average of 108,978 ns for compress and 14,485 ns for decompress.
As can be seen from Table 1, the numbers using the iaa_crypto driver for deflate as compared to software are so much better that merging it would seem to make sense on its own merits. The 'async' sync_mode described above, however, offers the possibility of even greater gains to be had against higher-performing algorithms such as lzo, via parallelization, once the calling facilities are modified to take advantage of it. Follow-up patchsets to this one will demonstrate concretely how that might be accomplished.
Thanks,
Tom
Table 1. Zswap latency and compression numbers (in ns):
Algorithm compress decompress
----------------------------------------------------------
iaa sync 3,177 2,235
iaa async irq 6,847 5,840
software deflate 108,978 14,485
[1] https://cdrdv2.intel.com/v1/dl/getContent/721858
[2] https://lore.kernel.org/lkml/[email protected]/
Dave Jiang (1):
dmaengine: idxd: add external module driver support for dsa_bus_type
Tom Zanussi (13):
dmaengine: idxd: Rename drv_enable/disable_wq to
idxd_drv_enable/disable_wq, and export
dmaengine: idxd: Export descriptor management functions
dmaengine: idxd: Export wq resource management functions
dmaengine: idxd: Add wq private data accessors
dmaengine: idxd: add callback support for iaa crypto
crypto: iaa - Add IAA Compression Accelerator Documentation
crypto: iaa - Add Intel IAA Compression Accelerator crypto driver core
crypto: iaa - Add per-cpu workqueue table with rebalancing
crypto: iaa - Add compression mode management along with fixed mode
crypto: iaa - Add support for deflate-iaa compression algorithm
crypto: iaa - Add irq support for the crypto async interface
crypto: iaa - Add IAA Compression Accelerator stats
dmaengine: idxd: Add support for device/wq defaults
.../driver-api/crypto/iaa/iaa-crypto.rst | 824 +++++++ Documentation/driver-api/crypto/iaa/index.rst | 20 + Documentation/driver-api/crypto/index.rst | 20 + Documentation/driver-api/index.rst | 1 + MAINTAINERS | 7 + crypto/testmgr.c | 10 + drivers/crypto/intel/Kconfig | 1 + drivers/crypto/intel/Makefile | 1 + drivers/crypto/intel/iaa/Kconfig | 19 + drivers/crypto/intel/iaa/Makefile | 12 + drivers/crypto/intel/iaa/iaa_crypto.h | 173 ++ .../crypto/intel/iaa/iaa_crypto_comp_fixed.c | 92 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 2181 +++++++++++++++++ drivers/crypto/intel/iaa/iaa_crypto_stats.c | 313 +++ drivers/crypto/intel/iaa/iaa_crypto_stats.h | 53 + drivers/dma/idxd/Makefile | 2 +- drivers/dma/idxd/bus.c | 6 + drivers/dma/idxd/cdev.c | 6 +- drivers/dma/idxd/defaults.c | 53 + drivers/dma/idxd/device.c | 13 +- drivers/dma/idxd/dma.c | 9 +- drivers/dma/idxd/idxd.h | 83 +- drivers/dma/idxd/init.c | 7 + drivers/dma/idxd/irq.c | 12 +- drivers/dma/idxd/submit.c | 9 +- 25 files changed, 3896 insertions(+), 31 deletions(-) create mode 100644 Documentation/driver-api/crypto/iaa/iaa-crypto.rst create mode 100644 Documentation/driver-api/crypto/iaa/index.rst create mode 100644 Documentation/driver-api/crypto/index.rst create mode 100644 drivers/crypto/intel/iaa/Kconfig create mode 100644 drivers/crypto/intel/iaa/Makefile create mode 100644 drivers/crypto/intel/iaa/iaa_crypto.h create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_main.c create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_stats.c create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_stats.h create mode 100644 drivers/dma/idxd/defaults.c
Signature · 1 line
2.34.1
PATCH v10 1/14 dmaengine: idxd: add external module driver support for dsa_bus_type
From: Dave Jiang <[email protected]>
Add support to allow an external driver to be registered to the dsa_bus_type and also auto-loaded.
--- drivers/dma/idxd/bus.c | 6 ++++++ drivers/dma/idxd/idxd.h | 3 +++ 2 files changed, 9 insertions(+)
drivers/dma/idxd/bus.c +6 -0
@@ -67,11 +67,17 @@ static void idxd_config_bus_remove(struct device *dev) idxd_drv->remove (idxd_dev); } +static int idxd_bus_uevent (const struct device *dev,struct kobj_uevent_env *env) +{ +return add_uevent_var (env,"MODALIAS=" IDXD_DEVICES_MODALIAS_FMT ,0 ); +} +struct bus_type dsa_bus_type = { .name ="dsa" , .match = idxd_config_bus_match, .probe = idxd_config_bus_probe, .remove = idxd_config_bus_remove, + .uevent = idxd_bus_uevent, };EXPORT_SYMBOL_GPL (dsa_bus_type);
drivers/dma/idxd/idxd.h +3 -0
@@ -655,6 +655,9 @@ static inline int idxd_wq_driver_name_match(struct idxd_wq *wq, struct device *dreturn (strncmp (wq->driver_name, dev->driver->name,strlen (dev->driver->name)) ==0 ); } +#define MODULE_ALIAS_IDXD_DEVICE (type) MODULE_ALIAS("idxd:t" __stringify(type) "*") +#define IDXD_DEVICES_MODALIAS_FMT "idxd:t%d" +int __must_check __idxd_driver_register (struct idxd_device_driver *idxd_drv,struct module *module,const char *mod_name);#define idxd_driver_register (driver) \
Signature · 1 line
2.34.1
PATCH v10 2/14 dmaengine: idxd: Rename drv_enable/disable_wq to idxd_drv_enable/disable_wq, and export
In reply to Tom ZanussiRename drv_enable_wq and drv_disable_wq to idxd_drv_enable_wq and idxd_drv_disable_wq respectively, so that they're no longer too generic to be exported. This also matches existing naming within the idxd driver.
And to allow idxd sub-drivers to enable and disable wqs, export them.
--- drivers/dma/idxd/cdev.c | 6 +++--- drivers/dma/idxd/device.c | 6 ++++-- drivers/dma/idxd/dma.c | 6 +++--- drivers/dma/idxd/idxd.h | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-)
drivers/dma/idxd/cdev.c +3 -3
@@ -550,7 +550,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) } wq->type =IDXD_WQT_USER ; - rc =drv_enable_wq (wq); + rc =idxd_drv_enable_wq (wq);if (rc <0 ) goto err;
@@ -565,7 +565,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)return 0 ; err_cdev: -drv_disable_wq (wq); +idxd_drv_disable_wq (wq); err:destroy_workqueue (wq->wq); wq->type =IDXD_WQT_NONE ;
@@ -580,7 +580,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev)mutex_lock (&wq->wq_lock);idxd_wq_del_cdev (wq); -drv_disable_wq (wq); +idxd_drv_disable_wq (wq); wq->type =IDXD_WQT_NONE ;destroy_workqueue (wq->wq); wq->wq =NULL ;
drivers/dma/idxd/device.c +4 -2
@@ -1350,7 +1350,7 @@ int idxd_wq_request_irq(struct idxd_wq *wq)return rc; } -int drv_enable_wq (struct idxd_wq *wq) +int idxd_drv_enable_wq (struct idxd_wq *wq) {struct idxd_device *idxd = wq->idxd;struct device *dev = &idxd->pdev->dev;
@@ -1482,8 +1482,9 @@ int drv_enable_wq(struct idxd_wq *wq) err:return rc; } +EXPORT_SYMBOL_NS_GPL (idxd_drv_enable_wq,IDXD ); -void drv_disable_wq (struct idxd_wq *wq) +void idxd_drv_disable_wq (struct idxd_wq *wq) {struct idxd_device *idxd = wq->idxd;struct device *dev = &idxd->pdev->dev;
@@ -1503,6 +1504,7 @@ void drv_disable_wq(struct idxd_wq *wq) wq->type =IDXD_WQT_NONE ; wq->client_count =0 ; } +EXPORT_SYMBOL_NS_GPL (idxd_drv_disable_wq,IDXD );int idxd_device_drv_probe (struct idxd_dev *idxd_dev) {
drivers/dma/idxd/dma.c +3 -3
@@ -314,7 +314,7 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev) wq->type =IDXD_WQT_KERNEL ; - rc =drv_enable_wq (wq); + rc =idxd_drv_enable_wq (wq);if (rc <0 ) {dev_dbg (dev,"Enable wq %d failed: %d\n" , wq->id, rc); rc = -ENXIO ;
@@ -333,7 +333,7 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev)return 0 ; err_dma: -drv_disable_wq (wq); +idxd_drv_disable_wq (wq); err: wq->type =IDXD_WQT_NONE ;mutex_unlock (&wq->wq_lock);
@@ -347,7 +347,7 @@ static void idxd_dmaengine_drv_remove(struct idxd_dev *idxd_dev)mutex_lock (&wq->wq_lock);__idxd_wq_quiesce (wq);idxd_unregister_dma_channel (wq); -drv_disable_wq (wq); +idxd_drv_disable_wq (wq);mutex_unlock (&wq->wq_lock); }
drivers/dma/idxd/idxd.h +2 -2
@@ -685,8 +685,8 @@ void idxd_unmask_error_interrupts(struct idxd_device *idxd);/* device control */ int idxd_device_drv_probe (struct idxd_dev *idxd_dev);void idxd_device_drv_remove (struct idxd_dev *idxd_dev); -int drv_enable_wq (struct idxd_wq *wq); -void drv_disable_wq (struct idxd_wq *wq); +int idxd_drv_enable_wq (struct idxd_wq *wq); +void idxd_drv_disable_wq (struct idxd_wq *wq);int idxd_device_init_reset (struct idxd_device *idxd);int idxd_device_enable (struct idxd_device *idxd);int idxd_device_disable (struct idxd_device *idxd);
Signature · 1 line
2.34.1
PATCH v10 3/14 dmaengine: idxd: Export descriptor management functions
In reply to Tom ZanussiTo allow idxd sub-drivers to access the descriptor management functions, export them.
--- drivers/dma/idxd/submit.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dma/idxd/submit.c +3 -0
@@ -61,6 +61,7 @@ struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)return __get_desc (wq, idx, cpu); } +EXPORT_SYMBOL_NS_GPL (idxd_alloc_desc,IDXD );void idxd_free_desc (struct idxd_wq *wq,struct idxd_desc *desc) {
@@ -69,6 +70,7 @@ void idxd_free_desc(struct idxd_wq *wq, struct idxd_desc *desc) desc->cpu =-1 ;sbitmap_queue_clear (&wq->sbq, desc->id, cpu); } +EXPORT_SYMBOL_NS_GPL (idxd_free_desc,IDXD );static struct idxd_desc *list_abort_desc (struct idxd_wq *wq,struct idxd_irq_entry *ie,struct idxd_desc *desc)
@@ -215,3 +217,4 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)percpu_ref_put (&wq->wq_active);return 0 ; } +EXPORT_SYMBOL_NS_GPL (idxd_submit_desc,IDXD );
Signature · 1 line
2.34.1
PATCH v10 4/14 dmaengine: idxd: Export wq resource management functions
In reply to Tom ZanussiTo allow idxd sub-drivers to access the wq resource management functions, export them.
--- drivers/dma/idxd/device.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/dma/idxd/device.c +5 -0
@@ -161,6 +161,7 @@ int idxd_wq_alloc_resources(struct idxd_wq *wq)free_hw_descs (wq);return rc; } +EXPORT_SYMBOL_NS_GPL (idxd_wq_alloc_resources,IDXD );void idxd_wq_free_resources (struct idxd_wq *wq) {
@@ -174,6 +175,7 @@ void idxd_wq_free_resources(struct idxd_wq *wq)dma_free_coherent (dev, wq->compls_size, wq->compls, wq->compls_addr);sbitmap_queue_free (&wq->sbq); } +EXPORT_SYMBOL_NS_GPL (idxd_wq_free_resources,IDXD );int idxd_wq_enable (struct idxd_wq *wq) {
@@ -405,6 +407,7 @@ int idxd_wq_init_percpu_ref(struct idxd_wq *wq)reinit_completion (&wq->wq_resurrect);return 0 ; } +EXPORT_SYMBOL_NS_GPL (idxd_wq_init_percpu_ref,IDXD );void __idxd_wq_quiesce (struct idxd_wq *wq) {
@@ -414,6 +417,7 @@ void __idxd_wq_quiesce(struct idxd_wq *wq)complete_all (&wq->wq_resurrect);wait_for_completion (&wq->wq_dead); } +EXPORT_SYMBOL_NS_GPL (__idxd_wq_quiesce,IDXD );void idxd_wq_quiesce (struct idxd_wq *wq) {
@@ -421,6 +425,7 @@ void idxd_wq_quiesce(struct idxd_wq *wq)__idxd_wq_quiesce (wq);mutex_unlock (&wq->wq_lock); } +EXPORT_SYMBOL_NS_GPL (idxd_wq_quiesce,IDXD );/* Device control bits */ static inline bool idxd_is_enabled (struct idxd_device *idxd)
Signature · 1 line
2.34.1
PATCH v10 5/14 dmaengine: idxd: Add wq private data accessors
In reply to Tom ZanussiAdd the accessors idxd_wq_set_private() and idxd_wq_get_private() allowing users to set and retrieve a private void * associated with an idxd_wq.
The private data is stored in the idxd_dev.conf_dev associated with each idxd_wq.
--- drivers/dma/idxd/idxd.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/dma/idxd/idxd.h +10 -0
@@ -618,6 +618,16 @@ static inline int idxd_wq_refcount(struct idxd_wq *wq)return wq->client_count; }; +static inline void idxd_wq_set_private (struct idxd_wq *wq,void *private) +{ +dev_set_drvdata (wq_confdev (wq), private); +} + +static inline void *idxd_wq_get_private (struct idxd_wq *wq) +{ +return dev_get_drvdata (wq_confdev (wq)); +} +/* * Intel IAA does not support batch processing. * The max batch size of device, max batch size of wq and
Signature · 1 line
2.34.1
PATCH v10 6/14 dmaengine: idxd: add callback support for iaa crypto
In reply to Tom ZanussiCreate a lightweight callback interface to allow idxd sub-drivers to be notified when work sent to idxd wqs has completed.
For a sub-driver to be notified of work completion, it needs to:
- Set the descriptor's 'Request Completion Interrupt'
(IDXD_OP_FLAG_RCI)
- Set the sub-driver desc_complete() callback when registering the sub-driver e.g.:
struct idxd_device_driver my_drv = {
.probe = my_probe,
.desc_complete = my_complete,
}
- Set the sub-driver-specific context in the sub-driver's descriptor
e.g:
idxd_desc->crypto.req = req;
idxd_desc->crypto.tfm = tfm;
idxd_desc->crypto.src_addr = src_addr;
idxd_desc->crypto.dst_addr = dst_addr;When the work completes and the completion irq fires, idxd will invoke the desc_complete() callback with pointers to the descriptor, context, and completion_type.
--- drivers/dma/idxd/device.c | 2 +- drivers/dma/idxd/dma.c | 3 +- drivers/dma/idxd/idxd.h | 62 ++++++++++++++++++++++++++++++++------- drivers/dma/idxd/irq.c | 12 ++++---- drivers/dma/idxd/submit.c | 6 ++-- 5 files changed, 65 insertions(+), 20 deletions(-)
drivers/dma/idxd/device.c +1 -1
@@ -1271,7 +1271,7 @@ static void idxd_flush_pending_descs(struct idxd_irq_entry *ie) tx = &desc->txd; tx->callback =NULL ; tx->callback_result =NULL ; -idxd_dma_complete_txd (desc, ctype, true); +idxd_dma_complete_txd (desc, ctype, true,NULL ,NULL ); } }
drivers/dma/idxd/dma.c +2 -1
@@ -22,7 +22,7 @@ static inline struct idxd_wq *to_idxd_wq(struct dma_chan *c)void idxd_dma_complete_txd (struct idxd_desc *desc,enum idxd_complete_type comp_type, -bool free_desc) +bool free_desc,void *ctx,u32 *status) {struct idxd_device *idxd = desc->wq->idxd;struct dma_async_tx_descriptor *tx;
@@ -359,6 +359,7 @@ static enum idxd_dev_type dev_types[] = {struct idxd_device_driver idxd_dmaengine_drv = { .probe = idxd_dmaengine_drv_probe, .remove = idxd_dmaengine_drv_remove, + .desc_complete = idxd_dma_complete_txd, .name ="dmaengine" , .type = dev_types, };
drivers/dma/idxd/idxd.h +52 -10
120 lines not on this page · raw message
drivers/dma/idxd/irq.c +6 -6
@@ -123,7 +123,7 @@ static void idxd_abort_invalid_int_handle_descs(struct idxd_irq_entry *ie)list_for_each_entry_safe (d, t, &flist, list) {list_del (&d->list); -idxd_dma_complete_txd (d,IDXD_COMPLETE_ABORT , true); +idxd_desc_complete (d,IDXD_COMPLETE_ABORT , true); } }
@@ -534,7 +534,7 @@ static void idxd_int_handle_resubmit_work(struct work_struct *work)*/ if (rc != -EAGAIN ) { desc->completion->status =IDXD_COMP_DESC_ABORT ; -idxd_dma_complete_txd (desc,IDXD_COMPLETE_ABORT , false); +idxd_desc_complete (desc,IDXD_COMPLETE_ABORT , false); }idxd_free_desc (wq, desc); }
@@ -575,11 +575,11 @@ static void irq_process_pending_llist(struct idxd_irq_entry *irq_entry)* and 0xff, which DSA_COMP_STATUS_MASK can mask out. */ if (unlikely (desc->completion->status ==IDXD_COMP_DESC_ABORT )) { -idxd_dma_complete_txd (desc,IDXD_COMPLETE_ABORT , true); +idxd_desc_complete (desc,IDXD_COMPLETE_ABORT , true);continue ; } -idxd_dma_complete_txd (desc,IDXD_COMPLETE_NORMAL , true); +idxd_desc_complete (desc,IDXD_COMPLETE_NORMAL , true); }else {spin_lock (&irq_entry->list_lock); list_add_tail(&desc->list,
@@ -618,11 +618,11 @@ static void irq_process_work_list(struct idxd_irq_entry *irq_entry)* and 0xff, which DSA_COMP_STATUS_MASK can mask out. */ if (unlikely (desc->completion->status ==IDXD_COMP_DESC_ABORT )) { -idxd_dma_complete_txd (desc,IDXD_COMPLETE_ABORT , true); +idxd_desc_complete (desc,IDXD_COMPLETE_ABORT , true);continue ; } -idxd_dma_complete_txd (desc,IDXD_COMPLETE_NORMAL , true); +idxd_desc_complete (desc,IDXD_COMPLETE_NORMAL , true); } }
drivers/dma/idxd/submit.c +4 -2
@@ -127,7 +127,8 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,spin_unlock (&ie->list_lock);if (found) -idxd_dma_complete_txd (found,IDXD_COMPLETE_ABORT , false); +idxd_dma_complete_txd (found,IDXD_COMPLETE_ABORT , false, +NULL ,NULL );/* * completing the descriptor will return desc to allocator and
@@ -137,7 +138,8 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,*/ list_for_each_entry_safe (d, t, &flist, list) {list_del_init (&d->list); -idxd_dma_complete_txd (found,IDXD_COMPLETE_ABORT , true); +idxd_dma_complete_txd (found,IDXD_COMPLETE_ABORT , true, +NULL ,NULL ); } }
Signature · 1 line
2.34.1
PATCH v10 7/14 crypto: iaa - Add IAA Compression Accelerator Documentation
In reply to Tom ZanussiBecause the IAA Compression Accelerator requires significant user setup in order to be used properly, this adds documentation on the iaa_crypto driver including setup, usage, and examples.
--- .../driver-api/crypto/iaa/iaa-crypto.rst | 824 ++++++++++++++++++ Documentation/driver-api/crypto/iaa/index.rst | 20 + Documentation/driver-api/crypto/index.rst | 20 + Documentation/driver-api/index.rst | 1 + 4 files changed, 865 insertions(+) create mode 100644 Documentation/driver-api/crypto/iaa/iaa-crypto.rst create mode 100644 Documentation/driver-api/crypto/iaa/index.rst create mode 100644 Documentation/driver-api/crypto/index.rst
Documentation/driver-api/crypto/iaa/iaa-crypto.rst new file +824 -0
@@ -0,0 +1,824 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================================= +IAA Compression Accelerator Crypto Driver +========================================= + +Tom Zanussi <[email protected]> + +The IAA crypto driver supports compression/decompression compatible +with the DEFLATE compression standard described in RFC 1951, which is +the compression/decompression algorithm exported by this module. + +The IAA hardware spec can be found here: + + https://cdrdv2.intel.com/v1/dl/getContent/721858 + +The iaa_crypto driver is designed to work as a layer underneath +higher-level compression devices such as zswap. + +Users can select IAA compress/decompress acceleration by specifying +one of the supported IAA compression algorithms in whatever facility +allows compression algorithms to be selected. + +For example, a zswap device can select the IAA 'fixed' mode +represented by selecting the 'deflate-iaa' crypto compression +algorithm:: + + # echo deflate-iaa > /sys/module/zswap/parameters/compressor + +This will tell zswap to use the IAA 'fixed' compression mode for all +compresses and decompresses. + +Currently, there is only one compression modes available, 'fixed' +mode. + +The 'fixed' compression mode implements the compression scheme +specified by RFC 1951 and is given the crypto algorithm name +'deflate-iaa'. (Because the IAA hardware has a 4k history-window +limitation, only buffers <= 4k, or that have been compressed using a +<= 4k history window, are technically compliant with the deflate spec, +which allows for a window of up to 32k. Because of this limitation, +the IAA fixed mode deflate algorithm is given its own algorithm name +rather than simply 'deflate'). + + +Config options and other setup +============================== + +The IAA crypto driver is available via menuconfig using the following +path:: + + Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression Accelerator + +In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO. + +The IAA crypto driver also supports statistics, which are available +via menuconfig using the following path:: + + Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression -> Enable Intel(R) IAA Compression Accelerator Statistics + +In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS. + +The following config options should also be enabled:: + + CONFIG_IRQ_REMAP=y + CONFIG_INTEL_IOMMU=y + CONFIG_INTEL_IOMMU_SVM=y + CONFIG_PCI_ATS=y + CONFIG_PCI_PRI=y + CONFIG_PCI_PASID=y + CONFIG_INTEL_IDXD=m + CONFIG_INTEL_IDXD_SVM=y + +IAA is one of the first Intel accelerator IPs that can work in +conjunction with the Intel IOMMU. There are multiple modes that exist +for testing. Based on IOMMU configuration, there are 3 modes:: + + - Scalable + - Legacy + - No IOMMU + + +Scalable mode +------------- + +Scalable mode supports Shared Virtual Memory (SVM or SVA). It is +entered when using the kernel boot commandline:: + + intel_iommu=on,sm_on + +with VT-d turned on in BIOS. + +With scalable mode, both shared and dedicated workqueues are available +for use. + +For scalable mode, the following BIOS settings should be enabled:: + + Socket Configuration > IIO Configuration > Intel VT for Directed I/O (VT-d) > Intel VT for Directed I/O + + Socket Configuration > IIO Configuration > PCIe ENQCMD > ENQCMDS + + +Legacy mode +----------- + +Legacy mode is entered when using the kernel boot commandline:: + + intel_iommu=off + +or VT-d is not turned on in BIOS. + +If you have booted into Linux and not sure if VT-d is on, do a "dmesg +| grep -i dmar". If you don't see a number of DMAR devices enumerated, +most likely VT-d is not on. + +With legacy mode, only dedicated workqueues are available for use. + + +No IOMMU mode +------------- + +No IOMMU mode is entered when using the kernel boot commandline:: + + iommu=off. + +With no IOMMU mode, only dedicated workqueues are available for use. + + +Usage +===== + +accel-config +------------ + +When loaded, the iaa_crypto driver automatically creates a default +configuration and enables it, and assigns default driver attributes. +If a different configuration or set of driver attributes is required, +the user must first disable the IAA devices and workqueues, reset the +configuration, and then re-register the deflate-iaa algorithm with the +crypto subsystem by removing and reinserting the iaa_crypto module. + +The :ref:`iaa_disable_script` in the 'Use Cases' +section below can be used to disable the default configuration. + +See :ref:`iaa_default_config` below for details of the default +configuration. + +More likely than not, however, and because of the complexity and +configurability of the accelerator devices, the user will want to +configure the device and manually enable the desired devices and +workqueues. + +The userspace tool to help doing that is called accel-config. Using +accel-config to configure device or loading a previously saved config +is highly recommended. The device can be controlled via sysfs +directly but comes with the warning that you should do this ONLY if +you know exactly what you are doing. The following sections will not +cover the sysfs interface but assumes you will be using accel-config. + +The :ref:`iaa_sysfs_config` section in the appendix below can be +consulted for the sysfs interface details if interested. + +The accel-config tool along with instructions for building it can be +found here: + + https://github.com/intel/idxd-config/#readme + +Typical usage +------------- + +In order for the iaa_crypto module to actually do any +compression/decompression work on behalf of a facility, one or more +IAA workqueues need to be bound to the iaa_crypto driver. + +For instance, here's an example of configuring an IAA workqueue and +binding it to the iaa_crypto driver (note that device names are +specified as 'iax' rather than 'iaa' - this is because upstream still +has the old 'iax' device naming in place) :: + + # configure wq1.0 + + accel-config config-wq --group-id=0 --mode=dedicated --type=kernel --name="iaa_crypto" --device_name="crypto" iax1/wq1.0 + + # enable IAA device iax1 + + accel-config enable-device iax1 + + # enable wq1.0 on IAX device iax1 + + accel-config enable-wq iax1/wq1.0 + +Whenever a new workqueue is bound to or unbound from the iaa_crypto +driver, the available workqueues are 'rebalanced' such that work +submitted from a particular CPU is given to the most appropriate +workqueue available. Current best practice is to configure and bind +at least one workqueue for each IAA device, but as long as there is at +least one workqueue configured and bound to any IAA device in the +system, the iaa_crypto driver will work, albeit most likely not as +efficiently. + +The IAA crypto algorigthms is operational and compression and +decompression operations are fully enabled following the successful +binding of the first IAA workqueue to the iaa_crypto driver. + +Similarly, the IAA crypto algorithm is not operational and compression +and decompression operations are disabled following the unbinding of +the last IAA worqueue to the iaa_crypto driver. + +As a result, the IAA crypto algorithms and thus the IAA hardware are +only available when one or more workques are bound to the iaa_crypto +driver. + +When there are no IAA workqueues bound to the driver, the IAA crypto +algorithms can be unregistered by removing the module. + + +Driver attributes +----------------- + +There are a couple user-configurable driver attributes that can be +used to configure various modes of operation. They're listed below, +along with their default values. To set any of these attributes, echo +the appropriate values to the attribute file located under +/sys/bus/dsa/drivers/crypto/ + +The attribute settings at the time the IAA algorithms are registered +are captured in each algorithm's crypto_ctx and used for all compresses +and decompresses when using that algorithm. + +The available attributes are: + + - verify_compress + + Toggle compression verification. If set, each compress will be + internally decompressed and the contents verified, returning error + codes if unsuccessful. This can be toggled with 0/1:: + + echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress + + The default setting is '1' - verify all compresses. + + - sync_mode + + Select mode to be used to wait for completion of each compresses + and decompress operation. + + The crypto async interface support implemented by iaa_crypto + provides an implementation that satisfies the interface but does + so in a synchronous manner - it fills and submits the IDXD + descriptor and then loops around waiting for it to complete before + returning. This isn't a problem at the moment, since all existing + callers (e.g. zswap) wrap any asynchronous callees in a + synchronous wrapper anyway. + + The iaa_crypto driver does however provide true asynchronous + support for callers that can make use of it. In this mode, it + fills and submits the IDXD descriptor, then returns immediately + with -EINPROGRESS. The caller can then either poll for completion + itself, which requires specific code in the caller which currently + nothing in the upstream kernel implements, or go to sleep and wait + for an interrupt signaling completion. This latter mode is + supported by current users in the kernel such as zswap via + synchronous wrappers. Although it is supported this mode is + significantly slower than the synchronous mode that does the + polling in the iaa_crypto driver previously mentioned. + + This mode can be enabled by writing 'async_irq' to the sync_mode + iaa_crypto driver attribute:: + + echo async_irq > /sys/bus/dsa/drivers/crypto/sync_mode + + Async mode without interrupts (caller must poll) can be enabled by + writing 'async' to it:: + + echo async > /sys/bus/dsa/drivers/crypto/sync_mode + + The mode that does the polling in the iaa_crypto driver can be + enabled by writing 'sync' to it:: + + echo sync > /sys/bus/dsa/drivers/crypto/sync_mode + + The default mode is 'sync'. + +.. _iaa_default_config: + +IAA Default Configuration +------------------------- + +When the iaa_crypto driver is loaded, each IAA device has a single +work queue configured for it, with the following attributes:: + + mode "dedicated" + threshold 0 + size 16 + priority 10 + type IDXD_WQT_KERNEL + group 0 + name "iaa_crypto" + driver_name "crypto" + +The devices and workqueues are also enabled and therefore the driver +is ready to be used without any additional configuration. + +The default driver attributes in effect when the driver is loaded are:: + + sync_mode "sync" + verify_compress 1 + +In order to change either the device/work queue or driver attributes, +the enabled devices and workqueues must first be disabled. In order +to have the new configuration applied to the deflate-iaa crypto +algorithm, it needs to be re-registered by removing and reinserting +the iaa_crypto module. The :ref:`iaa_disable_script` in the 'Use +Cases' section below can be used to disable the default configuration. + +Statistics +========== + +If the optional debugfs statistics support is enabled, the IAA crypto +driver will generate statistics which can be accessed in debugfs at:: + + # ls -al /sys/kernel/debug/iaa-crypto/ + total 0 + drwxr-xr-x 2 root root 0 Mar 3 09:35 . + drwx------ 47 root root 0 Mar 3 09:35 .. + -rw-r--r-- 1 root root 0 Mar 3 09:35 max_acomp_delay_ns + -rw-r--r-- 1 root root 0 Mar 3 09:35 max_adecomp_delay_ns + -rw-r--r-- 1 root root 0 Mar 3 09:35 max_comp_delay_ns + -rw-r--r-- 1 root root 0 Mar 3 09:35 max_decomp_delay_ns + -rw-r--r-- 1 root root 0 Mar 3 09:35 stats_reset + -rw-r--r-- 1 root root 0 Mar 3 09:35 total_comp_bytes_out + -rw-r--r-- 1 root root 0 Mar 3 09:35 total_comp_calls + -rw-r--r-- 1 root root 0 Mar 3 09:35 total_decomp_bytes_in + -rw-r--r-- 1 root root 0 Mar 3 09:35 total_decomp_calls + -rw-r--r-- 1 root root 0 Mar 3 09:35 wq_stats + +Most of the above statisticss are self-explanatory. The wq_stats file +shows per-wq stats, a set for each iaa device and wq in addition to +some global stats:: + + # cat wq_stats + global stats: + total_comp_calls: 100 + total_decomp_calls: 100 + total_comp_bytes_out: 22800 + total_decomp_bytes_in: 22800 + total_completion_einval_errors: 0 + total_completion_timeout_errors: 0 + total_completion_comp_buf_overflow_errors: 0 + + iaa device: + id: 1 + n_wqs: 1 + comp_calls: 0 + comp_bytes: 0 + decomp_calls: 0 + decomp_bytes: 0 + wqs: + name: iaa_crypto + comp_calls: 0 + comp_bytes: 0 + decomp_calls: 0 + decomp_bytes: 0 + + iaa device: + id: 3 + n_wqs: 1 + comp_calls: 0 + comp_bytes: 0 + decomp_calls: 0 + decomp_bytes: 0 + wqs: + name: iaa_crypto + comp_calls: 0 + comp_bytes: 0 + decomp_calls: 0 + decomp_bytes: 0 + + iaa device: + id: 5 + n_wqs: 1 + comp_calls: 100 + comp_bytes: 22800 + decomp_calls: 100 + decomp_bytes: 22800 + wqs: + name: iaa_crypto + comp_calls: 100 + comp_bytes: 22800 + decomp_calls: 100 + decomp_bytes: 22800 + +Writing 0 to 'stats_reset' resets all the stats, including the +per-device and per-wq stats:: + + # echo 0 > stats_reset + # cat wq_stats + global stats: + total_comp_calls: 0 + total_decomp_calls: 0 + total_comp_bytes_out: 0 + total_decomp_bytes_in: 0 + total_completion_einval_errors: 0 + total_completion_timeout_errors: 0 + total_completion_comp_buf_overflow_errors: 0 + ... + + +Use cases +========= + +Simple zswap test +----------------- + +For this example, the kernel should be configured according to the +dedicated mode options described above, and zswap should be enabled as +well:: + + CONFIG_ZSWAP=y + +This is a simple test that uses iaa_compress as the compressor for a +swap (zswap) device. It sets up the zswap device and then uses the +memory_memadvise program listed below to forcibly swap out and in a +specified number of pages, demonstrating both compress and decompress. + +The zswap test expects the work queues for each IAA device on the +system to be configured properly as a kernel workqueue with a +workqueue driver_name of "crypto". + +The first step is to make sure the iaa_crypto module is loaded:: + + modprobe iaa_crypto + +If the IAA devices and workqueues haven't previously been disabled and +reconfigured, then the default configuration should be in place and no +further IAA configuration is necessary. See :ref:`iaa_default_config` +below for details of the default configuration. + +If the default configuration is in place, you should see the iaa +devices and wq0s enabled:: + + # cat /sys/bus/dsa/devices/iax1/state + enabled + # cat /sys/bus/dsa/devices/iax1/wq1.0/state + enabled + +To demonstrate that the following steps work as expected, these +commands can be used to enable debug output:: + + # echo -n 'module iaa_crypto +p' > /sys/kernel/debug/dynamic_debug/control + # echo -n 'module idxd +p' > /sys/kernel/debug/dynamic_debug/control + +Use the following commands to enable zswap:: + + # echo 0 > /sys/module/zswap/parameters/enabled + # echo 50 > /sys/module/zswap/parameters/max_pool_percent + # echo deflate-iaa > /sys/module/zswap/parameters/compressor + # echo zsmalloc > /sys/module/zswap/parameters/zpool + # echo 1 > /sys/module/zswap/parameters/enabled + # echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled + # echo 100 > /proc/sys/vm/swappiness + # echo never > /sys/kernel/mm/transparent_hugepage/enabled + # echo 1 > /proc/sys/vm/overcommit_memory + +Now you can now run the zswap workload you want to measure. For +example, using the memory_memadvise code below, the following command +will swap in and out 100 pages:: + + ./memory_madvise 100 + + Allocating 100 pages to swap in/out + Swapping out 100 pages + Swapping in 100 pages + Swapped out and in 100 pages + +You should see something like the following in the dmesg output:: + + [ 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) 4096 + [ 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) 8192 + [ 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 1568 + [ 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 0 + ... + +Now that basic functionality has been demonstrated, the defaults can +be erased and replaced with a different configuration. To do that, +first disable zswap:: + + # echo lzo > /sys/module/zswap/parameters/compressor + # swapoff -a + # echo 0 > /sys/module/zswap/parameters/accept_threshold_percent + # echo 0 > /sys/module/zswap/parameters/max_pool_percent + # echo 0 > /sys/module/zswap/parameters/enabled + # echo 0 > /sys/module/zswap/parameters/enabled + +Then run the :ref:`iaa_disable_script` in the 'Use Cases' section +below to disable the default configuration. + +Finally turn swap back on:: + + # swapon -a + +Following all that the IAA device(s) can now be re-configured and +enabled as desired for further testing. Below is one example. + +The zswap test expects the work queues for each IAA device on the +system to be configured properly as a kernel workqueue with a +workqueue driver_name of "crypto". + +The below script automatically does that:: + + #!/bin/bash + + echo "IAA devices:" + lspci -d:0cfe + echo "# IAA devices:" + lspci -d:0cfe | wc -l + + # + # count iaa instances + # + iaa_dev_id="0cfe" + num_iaa=$(lspci -d:${iaa_dev_id} | wc -l) + echo "Found ${num_iaa} IAA instances" + + # + # disable iaa wqs and devices + # + echo "Disable IAA" + + for ((i = 1; i < ${num_iaa} * 2; i += 2)); do + echo disable wq iax${i}/wq${i}.0 + accel-config disable-wq iax${i}/wq${i}.0 + echo disable iaa iax${i} + accel-config disable-device iax${i} + done + + echo "End Disable IAA" + + # + # configure iaa wqs and devices + # + echo "Configure IAA" + for ((i = 1; i < ${num_iaa} * 2; i += 2)); do + accel-config config-wq --group-id=0 --mode=dedicated --size=128 --priority=10 --type=kernel --name="iaa_crypto" --driver_name="crypto" iax${i}/wq${i} + done + + echo "End Configure IAA" + + # + # enable iaa wqs and devices + # + echo "Enable IAA" + + for ((i = 1; i < ${num_iaa} * 2; i += 2)); do + echo enable iaa iaa${i} + accel-config enable-device iaa${i} + echo enable wq iaa${i}/wq${i}.0 + accel-config enable-wq iaa${i}/wq${i}.0 + done + + echo "End Enable IAA" + +When the workqueues are bound to the iaa_crypto driver, you should +see something similar to the following in dmesg output if you've +enabled debug output (echo -n 'module iaa_crypto +p' > +/sys/kernel/debug/dynamic_debug/control):: + + [ 60.752344] idxd 0000:f6:02.0: add_iaa_wq: added wq 000000004068d14d to iaa 00000000c9585ba2, n_wq 1 + [ 60.752346] iaa_crypto: rebalance_wq_table: nr_nodes=2, nr_cpus 160, nr_iaa 8, cpus_per_iaa 20 + [ 60.752347] iaa_crypto: rebalance_wq_table: iaa=0 + [ 60.752349] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0) + [ 60.752350] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0) + [ 60.752352] iaa_crypto: rebalance_wq_table: assigned wq for cpu=0, node=0 = wq 00000000c8bb4452 + [ 60.752354] iaa_crypto: rebalance_wq_table: iaa=0 + [ 60.752355] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0) + [ 60.752356] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0) + [ 60.752358] iaa_crypto: rebalance_wq_table: assigned wq for cpu=1, node=0 = wq 00000000c8bb4452 + [ 60.752359] iaa_crypto: rebalance_wq_table: iaa=0 + [ 60.752360] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0) + [ 60.752361] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0) + [ 60.752362] iaa_crypto: rebalance_wq_table: assigned wq for cpu=2, node=0 = wq 00000000c8bb4452 + [ 60.752364] iaa_crypto: rebalance_wq_table: iaa=0 + . + . + . + +Once the workqueues and devices have been enabled, the IAA crypto +algorithms are enabled and available. When the IAA crypto algorithms +have been successfully enabled, you should see the following dmesg +output:: + + [ 64.893759] iaa_crypto: iaa_crypto_enable: iaa_crypto now ENABLED + +Now run the following zswap-specific setup commands to have zswap use +the 'fixed' compression mode:: + + echo 0 > /sys/module/zswap/parameters/enabled + echo 50 > /sys/module/zswap/parameters/max_pool_percent + echo deflate-iaa > /sys/module/zswap/parameters/compressor + echo zsmalloc > /sys/module/zswap/parameters/zpool + echo 1 > /sys/module/zswap/parameters/enabled + echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled + + echo 100 > /proc/sys/vm/swappiness + echo never > /sys/kernel/mm/transparent_hugepage/enabled + echo 1 > /proc/sys/vm/overcommit_memory + +Finally, you can now run the zswap workload you want to measure. For +example, using the code below, the following command will swap in and +out 100 pages:: + + ./memory_madvise 100 + + Allocating 100 pages to swap in/out + Swapping out 100 pages + Swapping in 100 pages + Swapped out and in 100 pages + +You should see something like the following in the dmesg output if +you've enabled debug output (echo -n 'module iaa_crypto +p' > +/sys/kernel/debug/dynamic_debug/control):: + + [ 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) 4096 + [ 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) 8192 + [ 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 1568 + [ 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 0 + [ 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) 228 + [ 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) 4096 + [ 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 0 + [ 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) 228 + [ 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) 4096 + [ 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 0 + +In order to unregister the IAA crypto algorithms, and register new +ones using different parameters, any users of the current algorithm +should be stopped and the IAA workqueues and devices disabled. + +In the case of zswap, remove the IAA crypto algorithm as the +compressor and turn off swap (to remove all references to +iaa_crypto):: + + echo lzo > /sys/module/zswap/parameters/compressor + swapoff -a + + echo 0 > /sys/module/zswap/parameters/accept_threshold_percent + echo 0 > /sys/module/zswap/parameters/max_pool_percent + echo 0 > /sys/module/zswap/parameters/enabled + +Once zswap is disabled and no longer using iaa_crypto, the IAA wqs and +devices can be disabled. + +.. _iaa_disable_script: + +IAA disable script +------------------ + +The below script automatically does that:: + + #!/bin/bash + + echo "IAA devices:" + lspci -d:0cfe + echo "# IAA devices:" + lspci -d:0cfe | wc -l + + # + # count iaa instances + # + iaa_dev_id="0cfe" + num_iaa=$(lspci -d:${iaa_dev_id} | wc -l) + echo "Found ${num_iaa} IAA instances" + + # + # disable iaa wqs and devices + # + echo "Disable IAA" + + for ((i = 1; i < ${num_iaa} * 2; i += 2)); do + echo disable wq iax${i}/wq${i}.0 + accel-config disable-wq iax${i}/wq${i}.0 + echo disable iaa iax${i} + accel-config disable-device iax${i} + done + + echo "End Disable IAA" + +Finally, at this point the iaa_crypto module can be removed, which +will unregister the current IAA crypto algorithms:: + + rmmod iaa_crypto + + +memory_madvise.c (gcc -o memory_memadvise memory_madvise.c):: + + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + #include <sys/mman.h> + #include <linux/mman.h> + + #ifndef MADV_PAGEOUT + #define MADV_PAGEOUT 21 /* force pages out immediately */ + #endif + + #define PG_SZ 4096 + + int main(int argc, char **argv) + { + int i, nr_pages = 1; + int64_t *dump_ptr; + char *addr, *a; + int loop = 1; + + if (argc > 1) + nr_pages = atoi(argv[1]); + + printf("Allocating %d pages to swap in/out\n", nr_pages); + + /* allocate pages */ + addr = mmap(NULL, nr_pages * PG_SZ, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + *addr = 1; + + /* initialize data in page to all '*' chars */ + memset(addr, '*', nr_pages * PG_SZ); + + printf("Swapping out %d pages\n", nr_pages); + + /* Tell kernel to swap it out */ + madvise(addr, nr_pages * PG_SZ, MADV_PAGEOUT); + + while (loop > 0) { + /* Wait for swap out to finish */ + sleep(5); + + a = addr; + + printf("Swapping in %d pages\n", nr_pages); + + /* Access the page ... this will swap it back in again */ + for (i = 0; i < nr_pages; i++) { + if (a[0] != '*') { + printf("Bad data from decompress!!!!!\n"); + + dump_ptr = (int64_t *)a; + for (int j = 0; j < 100; j++) { + printf(" page %d data: %#llx\n", i, *dump_ptr); + dump_ptr++; + } + } + + a += PG_SZ; + } + + loop --; + } + + printf("Swapped out and in %d pages\n", nr_pages); + +Appendix +======== + +.. _iaa_sysfs_config: + +IAA sysfs config interface +-------------------------- + +Below is a description of the IAA sysfs interface, which as mentioned +in the main document, should only be used if you know exactly what you +are doing. Even then, there's no compelling reason to use it directly +since accel-config can do everything the sysfs interface can and in +fact accel-config is based on it under the covers. + +The 'IAA config path' is /sys/bus/dsa/devices and contains +subdirectories representing each IAA device, workqueue, engine, and +group. Note that in the sysfs interface, the IAA devices are actually +named using iax e.g. iax1, iax3, etc. (Note that IAA devices are the +odd-numbered devices; the even-numbered devices are DSA devices and +can be ignored for IAA). + +The 'IAA device bind path' is /sys/bus/dsa/drivers/idxd/bind and is +the file that is written to enable an IAA device. + +The 'IAA workqueue bind path' is /sys/bus/dsa/drivers/crypto/bind and +is the file that is written to enable an IAA workqueue. + +Similarly /sys/bus/dsa/drivers/idxd/unbind and +/sys/bus/dsa/drivers/crypto/unbind are used to disable IAA devices and +workqueues. + +The basic sequence of commands needed to set up the IAA devices and +workqueues is: + +For each device:: + 1) Disable any workqueues enabled on the device. For example to + disable workques 0 and 1 on IAA device 3:: + + # echo wq3.0 > /sys/bus/dsa/drivers/crypto/unbind + # echo wq3.1 > /sys/bus/dsa/drivers/crypto/unbind + + 2) Disable the device. For example to disable IAA device 3:: + + # echo iax3 > /sys/bus/dsa/drivers/idxd/unbind + + 3) configure the desired workqueues. For example, to configure + workqueue 3 on IAA device 3:: + + # echo dedicated > /sys/bus/dsa/devices/iax3/wq3.3/mode + # echo 128 > /sys/bus/dsa/devices/iax3/wq3.3/size + # echo 0 > /sys/bus/dsa/devices/iax3/wq3.3/group_id + # echo 10 > /sys/bus/dsa/devices/iax3/wq3.3/priority + # echo "kernel" > /sys/bus/dsa/devices/iax3/wq3.3/type + # echo "iaa_crypto" > /sys/bus/dsa/devices/iax3/wq3.3/name + # echo "crypto" > /sys/bus/dsa/devices/iax3/wq3.3/driver_name + + 4) Enable the device. For example to enable IAA device 3:: + + # echo iax3 > /sys/bus/dsa/drivers/idxd/bind + + 5) Enable the desired workqueues on the device. For example to + enable workques 0 and 1 on IAA device 3:: + + # echo wq3.0 > /sys/bus/dsa/drivers/crypto/bind + # echo wq3.1 > /sys/bus/dsa/drivers/crypto/bind
Documentation/driver-api/crypto/iaa/index.rst new file +20 -0
@@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================= +IAA (Intel Analytics Accelerator) +================================= + +IAA provides hardware compression and decompression via the crypto +API. + +.. toctree:: + :maxdepth: 1 + + iaa-crypto + +.. only:: subproject and html + + Indices + ======= + + * :ref:`genindex`
Documentation/driver-api/crypto/index.rst new file +20 -0
@@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============== +Crypto Drivers +============== + +Documentation for crypto drivers that may need more involved setup and +configuration. + +.. toctree:: + :maxdepth: 1 + + iaa/index + +.. only:: subproject and html + + Indices + ======= + + * :ref:`genindex`
Documentation/driver-api/index.rst +1 -0
@@ -115,6 +115,7 @@ available subsections can be seen below. hte/index wmi dpll + crypto/index .. only:: subproject and html
Signature · 1 line
2.34.1
PATCH v10 8/14 crypto: iaa - Add Intel IAA Compression Accelerator crypto driver core
In reply to Tom ZanussiThe Intel Analytics Accelerator (IAA) is a hardware accelerator that provides very high thoughput compression/decompression compatible with the DEFLATE compression standard described in RFC 1951, which is the compression/decompression algorithm exported by this module.
Users can select IAA compress/decompress acceleration by specifying one of the deflate-iaa* algorithms as the compression algorithm to use by whatever facility allows asynchronous compression algorithms to be selected.
For example, zswap can select the IAA fixed deflate algorithm 'deflate-iaa' via:
# echo deflate-iaa > /sys/module/zswap/parameters/compressor
This patch adds iaa_crypto as an idxd sub-driver and tracks iaa devices and workqueues as they are probed or removed.
[ Based on work originally by George Powley, Jing Lin and Kyung Min Park ]
--- MAINTAINERS | 7 + drivers/crypto/intel/Kconfig | 1 + drivers/crypto/intel/Makefile | 1 + drivers/crypto/intel/iaa/Kconfig | 10 + drivers/crypto/intel/iaa/Makefile | 10 + drivers/crypto/intel/iaa/iaa_crypto.h | 30 ++ drivers/crypto/intel/iaa/iaa_crypto_main.c | 323 +++++++++++++++++++++ 7 files changed, 382 insertions(+) create mode 100644 drivers/crypto/intel/iaa/Kconfig create mode 100644 drivers/crypto/intel/iaa/Makefile create mode 100644 drivers/crypto/intel/iaa/iaa_crypto.h create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_main.c
MAINTAINERS +7 -0
@@ -10719,6 +10719,13 @@ S: Supported Q: https://patchwork.kernel.org/project/linux-dmaengine/list/ F: drivers/dma/ioat* +INTEL IAA CRYPTO DRIVER +M: Tom Zanussi <[email protected]> +L: [email protected] +S: Supported +F: Documentation/driver-api/crypto/iaa/iaa-crypto.rst +F: drivers/crypto/intel/iaa/* + INTEL IDLE DRIVER M: Jacob Pan <[email protected]> M: Len Brown <[email protected]>
drivers/crypto/intel/Kconfig +1 -0
@@ -3,3 +3,4 @@ source "drivers/crypto/intel/keembay/Kconfig" source "drivers/crypto/intel/ixp4xx/Kconfig" source "drivers/crypto/intel/qat/Kconfig" +source "drivers/crypto/intel/iaa/Kconfig"
drivers/crypto/intel/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-y += keembay/ obj-y += ixp4xx/ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/ +obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) += iaa/
drivers/crypto/intel/iaa/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config CRYPTO_DEV_IAA_CRYPTO + tristate "Support for Intel(R) IAA Compression Accelerator" + depends on CRYPTO_DEFLATE + depends on INTEL_IDXD + default n + help + This driver supports acceleration for compression and + decompression with the Intel Analytics Accelerator (IAA) + hardware using the cryptographic API. If you choose 'M' + here, the module will be called iaa_crypto.
drivers/crypto/intel/iaa/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for IAA crypto device drivers +# + +ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD + +obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o + +iaa_crypto-y := iaa_crypto_main.o
drivers/crypto/intel/iaa/iaa_crypto.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */ + +#ifndef __IAA_CRYPTO_H__ +#define __IAA_CRYPTO_H__ + +#include <linux/crypto.h> +#include <linux/idxd.h> +#include <uapi/linux/idxd.h> + +#define IDXD_SUBDRIVER_NAME "crypto" + +/* Representation of IAA workqueue */ +struct iaa_wq { +struct list_head list; +struct idxd_wq *wq; + +struct iaa_device *iaa_device; +}; + +/* Representation of IAA device with wqs, populated by probe */ +struct iaa_device { +struct list_head list; +struct idxd_device *idxd; + +int n_wq; +struct list_head wqs; +}; + +#endif
drivers/crypto/intel/iaa/iaa_crypto_main.c new file +323 -0
323 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 9/14 crypto: iaa - Add per-cpu workqueue table with rebalancing
In reply to Tom ZanussiThe iaa compression/decompression algorithms in later patches need a way to retrieve an appropriate IAA workqueue depending on how close the associated IAA device is to the current cpu.
For this purpose, add a per-cpu array of workqueues such that an appropriate workqueue can be retrieved by simply accessing the per-cpu array.
Whenever a new workqueue is bound to or unbound from the iaa_crypto driver, the available workqueues are 'rebalanced' such that work submitted from a particular CPU is given to the most appropriate workqueue available. There currently isn't any way for the user to tweak the way this is done internally - if necessary, knobs can be added later for that purpose. Current best practice is to configure and bind at least one workqueue for each IAA device, but as long as there is at least one workqueue configured and bound to any IAA device in the system, the iaa_crypto driver will work, albeit most likely not as efficiently.
[ Based on work originally by George Powley, Jing Lin and Kyung Min Park ]
--- drivers/crypto/intel/iaa/iaa_crypto.h | 7 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 222 +++++++++++++++++++++ 2 files changed, 229 insertions(+)
drivers/crypto/intel/iaa/iaa_crypto.h +7 -0
@@ -27,4 +27,11 @@ struct iaa_device { struct list_head wqs; }; +struct wq_table_entry { +struct idxd_wq **wqs; +int max_wqs; +int n_wqs; +int cur_wq; +}; +#endif
drivers/crypto/intel/iaa/iaa_crypto_main.c +222 -0
281 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 10/14 crypto: iaa - Add compression mode management along with fixed mode
In reply to Tom ZanussiDefine an in-kernel API for adding and removing compression modes, which can be used by kernel modules or other kernel code that implements IAA compression modes.
Also add a separate file, iaa_crypto_comp_fixed.c, containing huffman tables generated for the IAA 'fixed' compression mode. Future compression modes can be added in a similar fashion.
One or more crypto compression algorithms will be created for each compression mode, each of which can be selected as the compression algorithm to be used by a particular facility.
--- drivers/crypto/intel/iaa/Makefile | 2 +- drivers/crypto/intel/iaa/iaa_crypto.h | 85 +++++ .../crypto/intel/iaa/iaa_crypto_comp_fixed.c | 92 +++++ drivers/crypto/intel/iaa/iaa_crypto_main.c | 327 +++++++++++++++++- 4 files changed, 504 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c
drivers/crypto/intel/iaa/Makefile +1 -1
@@ -7,4 +7,4 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o -iaa_crypto-y := iaa_crypto_main.o +iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o
drivers/crypto/intel/iaa/iaa_crypto.h +85 -0
106 lines not on this page · raw message
drivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c new file +92 -0
92 lines not on this page · raw message
drivers/crypto/intel/iaa/iaa_crypto_main.c +326 -1
366 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 11/14 crypto: iaa - Add support for deflate-iaa compression algorithm
In reply to Tom ZanussiThis patch registers the deflate-iaa deflate compression algorithm and hooks it up to the IAA hardware using the 'fixed' compression mode introduced in the previous patch.
Because the IAA hardware has a 4k history-window limitation, only buffers <= 4k, or that have been compressed using a <= 4k history window, are technically compliant with the deflate spec, which allows for a window of up to 32k. Because of this limitation, the IAA fixed mode deflate algorithm is given its own algorithm name, 'deflate-iaa'.
With this change, the deflate-iaa crypto algorithm is registered and operational, and compression and decompression operations are fully enabled following the successful binding of the first IAA workqueue to the iaa_crypto sub-driver.
when there are no IAA workqueues bound to the driver, the IAA crypto algorithm can be unregistered by removing the module.
A new iaa_crypto 'verify_compress' driver attribute is also added, allowing the user to toggle compression verification. If set, each compress will be internally decompressed and the contents verified, returning error codes if unsuccessful. This can be toggled with 0/1:
echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress
The default setting is '1' - verify all compresses.
The verify_compress value setting at the time the algorithm is registered is captured in the algorithm's crypto_ctx and used for all compresses when using the algorithm.
[ Based on work originally by George Powley, Jing Lin and Kyung Min Park ]
--- crypto/testmgr.c | 10 + drivers/crypto/intel/iaa/iaa_crypto.h | 36 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 1050 +++++++++++++++++++- 3 files changed, 1078 insertions(+), 18 deletions(-)
crypto/testmgr.c +10 -0
@@ -4815,6 +4815,16 @@ static const struct alg_test_desc alg_test_descs[] = { .decomp = __VECS(deflate_decomp_tv_template) } } + }, { + .alg = "deflate-iaa", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(deflate_comp_tv_template), + .decomp = __VECS(deflate_decomp_tv_template) + } + } }, { .alg = "dh", .test = alg_test_kpp,
drivers/crypto/intel/iaa/iaa_crypto.h +36 -0
@@ -10,15 +10,42 @@#define IDXD_SUBDRIVER_NAME "crypto" +#define IAA_DECOMP_ENABLE BIT(0) +#define IAA_DECOMP_FLUSH_OUTPUT BIT(1) +#define IAA_DECOMP_CHECK_FOR_EOB BIT(2) +#define IAA_DECOMP_STOP_ON_EOB BIT(3) +#define IAA_DECOMP_SUPPRESS_OUTPUT BIT(9) + +#define IAA_COMP_FLUSH_OUTPUT BIT(1) +#define IAA_COMP_APPEND_EOB BIT(2) + +#define IAA_COMPLETION_TIMEOUT 1000000 + +#define IAA_ANALYTICS_ERROR 0x0a +#define IAA_ERROR_DECOMP_BUF_OVERFLOW 0x0b +#define IAA_ERROR_COMP_BUF_OVERFLOW 0x19 +#define IAA_ERROR_WATCHDOG_EXPIRED 0x24 +#define IAA_COMP_MODES_MAX 2#define FIXED_HDR 0x2#define FIXED_HDR_SIZE 3 +#define IAA_COMP_FLAGS (IAA_COMP_FLUSH_OUTPUT | \ + IAA_COMP_APPEND_EOB) + +#define IAA_DECOMP_FLAGS (IAA_DECOMP_ENABLE | \ + IAA_DECOMP_FLUSH_OUTPUT | \ + IAA_DECOMP_CHECK_FOR_EOB | \ + IAA_DECOMP_STOP_ON_EOB) +/* Representation of IAA workqueue */ struct iaa_wq {struct list_head list; +struct idxd_wq *wq; +int ref; +bool remove;struct iaa_device *iaa_device; };
@@ -119,4 +146,13 @@ int add_iaa_compression_mode(const char *name,void remove_iaa_compression_mode (const char *name); +enum iaa_mode { +IAA_MODE_FIXED , +}; + +struct iaa_compression_ctx { +enum iaa_mode mode; +bool verify_compress; +}; +#endif
drivers/crypto/intel/iaa/iaa_crypto_main.c +1032 -18
1,197 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 12/14 crypto: iaa - Add irq support for the crypto async interface
In reply to Tom ZanussiThe existing iaa crypto async support provides an implementation that satisfies the interface but does so in a synchronous manner - it fills and submits the IDXD descriptor and then waits for it to complete before returning. This isn't a problem at the moment, since all existing callers (e.g. zswap) wrap any asynchronous callees in a synchronous wrapper anyway.
This change makes the iaa crypto async implementation truly
asynchronous: it fills and submits the IDXD descriptor, then returns immediately with -EINPROGRESS. It also sets the descriptor's 'request completion irq' bit and sets up a callback with the IDXD driver which is called when the operation completes and the irq fires. The existing callers such as zswap use synchronous wrappers to deal with -EINPROGRESS and so work as expected without any changes.
This mode can be enabled by writing 'async_irq' to the sync_mode iaa_crypto driver attribute:
echo async_irq > /sys/bus/dsa/drivers/crypto/sync_mode
Async mode without interrupts (caller must poll) can be enabled by writing 'async' to it:
echo async > /sys/bus/dsa/drivers/crypto/sync_mode
The default sync mode can be enabled by writing 'sync' to it:
echo sync > /sys/bus/dsa/drivers/crypto/sync_mode
The sync_mode value setting at the time the IAA algorithms are registered is captured in each algorithm's crypto_ctx and used for all compresses and decompresses when using a given algorithm.
--- drivers/crypto/intel/iaa/iaa_crypto.h | 2 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 266 ++++++++++++++++++++- 2 files changed, 266 insertions(+), 2 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto.h +2 -0
@@ -153,6 +153,8 @@ enum iaa_mode {struct iaa_compression_ctx {enum iaa_mode mode;bool verify_compress; +bool async_mode; +bool use_irq; };#endif
drivers/crypto/intel/iaa/iaa_crypto_main.c +264 -2
342 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 13/14 crypto: iaa - Add IAA Compression Accelerator stats
In reply to Tom ZanussiAdd support for optional debugfs statistics support for the IAA Compression Accelerator. This is enabled by the kernel config item:
CRYPTO_DEV_IAA_CRYPTO_STATS
When enabled, the IAA crypto driver will generate statistics which can be accessed at /sys/kernel/debug/iaa-crypto/.
See Documentation/driver-api/crypto/iax/iax-crypto.rst for details.
--- drivers/crypto/intel/iaa/Kconfig | 9 + drivers/crypto/intel/iaa/Makefile | 2 + drivers/crypto/intel/iaa/iaa_crypto.h | 13 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 39 ++- drivers/crypto/intel/iaa/iaa_crypto_stats.c | 313 ++++++++++++++++++++ drivers/crypto/intel/iaa/iaa_crypto_stats.h | 53 ++++ 6 files changed, 427 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_stats.c create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_stats.h
drivers/crypto/intel/iaa/Kconfig +9 -0
@@ -8,3 +8,12 @@ config CRYPTO_DEV_IAA_CRYPTO decompression with the Intel Analytics Accelerator (IAA) hardware using the cryptographic API. If you choose 'M' here, the module will be called iaa_crypto. + +config CRYPTO_DEV_IAA_CRYPTO_STATS + bool "Enable Intel(R) IAA Compression Accelerator Statistics" + depends on CRYPTO_DEV_IAA_CRYPTO + default n + help + Enable statistics for the IAA compression accelerator. + These include per-device and per-workqueue statistics in + addition to global driver statistics.
drivers/crypto/intel/iaa/Makefile +2 -0
@@ -8,3 +8,5 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o + +iaa_crypto-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS) += iaa_crypto_stats.o
drivers/crypto/intel/iaa/iaa_crypto.h +13 -0
@@ -48,6 +48,11 @@ struct iaa_wq {bool remove;struct iaa_device *iaa_device; + +u64 comp_calls; +u64 comp_bytes; +u64 decomp_calls; +u64 decomp_bytes; };struct iaa_device_compression_mode {
@@ -69,6 +74,11 @@ struct iaa_device {int n_wq;struct list_head wqs; + +u64 comp_calls; +u64 comp_bytes; +u64 decomp_calls; +u64 decomp_bytes; };struct wq_table_entry {
@@ -157,4 +167,7 @@ struct iaa_compression_ctx { bool use_irq; }; +extern struct list_head iaa_devices; +extern struct mutex iaa_devices_lock; +#endif
drivers/crypto/intel/iaa/iaa_crypto_main.c +37 -2
@@ -14,6 +14,7 @@#include "idxd.h" #include "iaa_crypto.h" +#include "iaa_crypto_stats.h" #ifdef pr_fmt#undef pr_fmt
@@ -85,8 +86,8 @@ static void wq_table_clear_entry(int cpu)memset (entry->wqs,0 , entry->max_wqs *sizeof (struct idxd_wq *)); } -static LIST_HEAD (iaa_devices); -static DEFINE_MUTEX (iaa_devices_lock); +LIST_HEAD (iaa_devices); +DEFINE_MUTEX (iaa_devices_lock);/* If enabled, IAA hw crypto algos are registered, unavailable otherwise */ static bool iaa_crypto_enabled;
@@ -1051,6 +1052,7 @@ static inline int check_completion(struct device *dev, ret = -ETIMEDOUT ;dev_dbg (dev,"%s timed out, size=0x%x\n" , op_str, comp->output_size); +update_completion_timeout_errs (); goto out; }
@@ -1060,6 +1062,7 @@ static inline int check_completion(struct device *dev,dev_dbg (dev,"compressed > uncompressed size," " not compressing, size=0x%x\n" , comp->output_size); +update_completion_comp_buf_overflow_errs (); goto out; }
@@ -1072,6 +1075,7 @@ static inline int check_completion(struct device *dev,dev_dbg (dev,"iaa %s status=0x%x, error=0x%x, size=0x%x\n" , op_str, comp->status, comp->error_code, comp->output_size);print_hex_dump (KERN_INFO ,"cmp-rec: " ,DUMP_PREFIX_OFFSET ,8 ,1 , comp,64 ,0 ); +update_completion_einval_errs (); goto out; }
@@ -1093,6 +1097,8 @@ static int deflate_generic_decompress(struct acomp_req *req)kunmap_local (src);kunmap_local (dst); +update_total_sw_decomp_calls (); +return ret; }
@@ -1160,6 +1166,15 @@ static void iaa_desc_complete(struct idxd_desc *idxd_desc, ctx->req->dlen = idxd_desc->iax_completion->output_size; } +/* Update stats */ +if (ctx->compress) { +update_total_comp_bytes_out (ctx->req->dlen); +update_wq_comp_bytes (iaa_wq->wq, ctx->req->dlen); + }else { +update_total_decomp_bytes_in (ctx->req->dlen); +update_wq_decomp_bytes (iaa_wq->wq, ctx->req->dlen); + } +if (ctx->compress && compression_ctx->verify_compress) {dma_addr_t src_addr, dst_addr;u32 compression_crc;
@@ -1279,6 +1294,10 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, goto err; } +/* Update stats */ +update_total_comp_calls (); +update_wq_comp_calls (wq); +if (ctx->async_mode && !disable_async) { ret = -EINPROGRESS ;dev_dbg (dev,"%s: returning -EINPROGRESS\n" , __func__);
@@ -1293,6 +1312,10 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, *dlen = idxd_desc->iax_completion->output_size; +/* Update stats */ +update_total_comp_bytes_out (*dlen); +update_wq_comp_bytes (wq, *dlen); + *compression_crc = idxd_desc->iax_completion->crc;if (!ctx->async_mode)
@@ -1509,6 +1532,10 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, goto err; } +/* Update stats */ +update_total_decomp_calls (); +update_wq_decomp_calls (wq); +if (ctx->async_mode && !disable_async) { ret = -EINPROGRESS ;dev_dbg (dev,"%s: returning -EINPROGRESS\n" , __func__);
@@ -1539,6 +1566,10 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req,if (!ctx->async_mode)idxd_free_desc (wq, idxd_desc); + +/* Update stats */ +update_total_decomp_bytes_in (slen); +update_wq_decomp_bytes (wq, slen); out:return ret; err:
@@ -2103,6 +2134,9 @@ static int __init iaa_crypto_init_module(void) goto err_sync_attr_create; } +if (iaa_crypto_debugfs_init ()) +pr_warn ("debugfs init failed, stats not available\n" ); +pr_debug ("initialized\n" ); out:return ret;
@@ -2125,6 +2159,7 @@ static void __exit iaa_crypto_cleanup_module(void)if (iaa_unregister_compression_device ())pr_debug ("IAA compression device unregister failed\n" ); +iaa_crypto_debugfs_cleanup ();driver_remove_file (&iaa_crypto_driver.drv, &driver_attr_sync_mode); driver_remove_file(&iaa_crypto_driver.drv,
drivers/crypto/intel/iaa/iaa_crypto_stats.c new file +313 -0
313 lines not on this page · raw message
drivers/crypto/intel/iaa/iaa_crypto_stats.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 14/14 dmaengine: idxd: Add support for device/wq defaults
In reply to Tom ZanussiAdd a load_device_defaults() function pointer to struct idxd_driver_data, which if defined, will be called when an idxd device is probed and will allow the idxd device to be configured with default values.
The load_device_defaults() function is passed an idxd device to work with to set specific device attributes.
Also add a load_device_defaults() implementation IAA devices; future patches would add default functions for other device types such as DSA.
The way idxd device probing works, if the device configuration is valid at that point e.g. at least one workqueue and engine is properly configured then the device will be enabled and ready to go.
The IAA implementation, idxd_load_iaa_device_defaults(), configures a single workqueue (wq0) for each device with the following default values:
mode "dedicated"
threshold 0
size 16
priority 10
type IDXD_WQT_KERNEL
group 0
name "iaa_crypto"
driver_name "crypto"Note that this now adds another configuration step for any users that want to configure their own devices/workqueus with something different in that they'll first need to disable (in the case of IAA) wq0 and the device itself before they can set their own attributes and re-enable, since they've been already been auto-enabled. Note also that in order for the new configuration to be applied to the deflate-iaa crypto algorithm the iaa_crypto module needs to unregister the old version, which is accomplished by removing the iaa_crypto module, and re-registering it with the new configuration by reinserting the iaa_crypto module.
--- drivers/dma/idxd/Makefile | 2 +- drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++ drivers/dma/idxd/idxd.h | 4 +++ drivers/dma/idxd/init.c | 7 +++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 drivers/dma/idxd/defaults.c
drivers/dma/idxd/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o idxd_bus-y := bus.o obj-$(CONFIG_INTEL_IDXD) += idxd.o -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o
drivers/dma/idxd/defaults.c new file +53 -0
53 lines not on this page · raw message
drivers/dma/idxd/idxd.h +4 -0
@@ -277,6 +277,8 @@ struct idxd_dma_dev {struct dma_device dma; }; +typedef int (*load_device_defaults_fn_t ) (struct idxd_device *idxd); +struct idxd_driver_data {const char *name_prefix;enum idxd_type type;
@@ -286,6 +288,7 @@ struct idxd_driver_data {int evl_cr_off;int cr_status_off;int cr_result_off; +load_device_defaults_fn_t load_device_defaults; };struct idxd_evl {
@@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd);void idxd_wqs_quiesce (struct idxd_device *idxd);bool idxd_queue_int_handle_resubmit (struct idxd_desc *desc);void multi_u64_to_bmap (unsigned long *bmap,u64 *val,int count); +int idxd_load_iaa_device_defaults (struct idxd_device *idxd);/* device interrupt control */ irqreturn_t idxd_misc_thread (int vec,void *data);
drivers/dma/idxd/init.c +7 -0
@@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr), .cr_status_off = offsetof(struct iax_completion_record, status), .cr_result_off = offsetof(struct iax_completion_record, error_code), + .load_device_defaults = idxd_load_iaa_device_defaults, }, };
@@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; } +if (data->load_device_defaults) { + rc = data->load_device_defaults (idxd); +if (rc) +dev_warn (dev,"IDXD loading device defaults failed\n" ); + } + rc =idxd_register_devices (idxd);if (rc) {dev_err (dev,"IDXD sysfs setup failed\n" );
Signature · 1 line
2.34.1
Re: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
Quoted 40 lines · Tom Zanussi
Add a
load_device_defaults()function pointer to structidxd_driver_data, which if defined, will be called when an idxd device is probed and will allow the idxd device to be configured with default values.The
load_device_defaults()function is passed an idxd device to work with to set specific device attributes.Also add a
load_device_defaults()implementation IAA devices; future patches would add default functions for other device types such as DSA.The way idxd device probing works, if the device configuration is valid at that point e.g. at least one workqueue and engine is properly configured then the device will be enabled and ready to go.
The IAA implementation,
idxd_load_iaa_device_defaults(), configures a single workqueue (wq0) for each device with the following default values:mode "dedicated" threshold 0 size 16 priority 10 type IDXD_WQT_KERNEL group 0 name "iaa_crypto" driver_name "crypto"Note that this now adds another configuration step for any users that want to configure their own devices/workqueus with something different in that they'll first need to disable (in the case of IAA) wq0 and the device itself before they can set their own attributes and re-enable, since they've been already been auto-enabled. Note also that in order for the new configuration to be applied to the deflate-iaa crypto algorithm the
iaa_cryptomodule needs to unregister the old version, which is accomplished by removing theiaa_cryptomodule, and re-registering it with the new configuration by reinserting theiaa_cryptomodule.
Quoted 1 line
Signed-off-by Tom Zanussi <[email protected]>
Quoted 134 lines
--- drivers/dma/idxd/Makefile | 2 +- drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++ drivers/dma/idxd/idxd.h | 4 +++ drivers/dma/idxd/init.c | 7 +++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 drivers/dma/idxd/defaults.cdrivers/dma/idxd/Makefile +1
-1@@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o idxd_bus-y := bus.o obj-$(CONFIG_INTEL_IDXD) += idxd.o -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.odrivers/dma/idxd/defaults.c new file +53
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ +#include <linux/kernel.h> +#include "idxd.h" + +int idxd_load_iaa_device_defaults (struct idxd_device *idxd) +{ +struct idxd_engine *engine; +struct idxd_group *group; +struct idxd_wq *wq; + +if (!test_bit (IDXD_FLAG_CONFIGURABLE , &idxd->flags)) +return 0 ; + + wq = idxd->wqs[0 ]; + +if (wq->state !=IDXD_WQ_DISABLED ) +return -EPERM ; + +/* set mode to "dedicated" */ +set_bit (WQ_FLAG_DEDICATED , &wq->flags); + wq->threshold =0 ; + +/* set size to 16 */ + wq->size =16 ; + +/* set priority to 10 */ + wq->priority =10 ; + +/* set type to "kernel" */ + wq->type =IDXD_WQT_KERNEL ; + +/* set wq group to 0 */ + group = idxd->groups[0 ]; + wq->group = group; + group->num_wqs++; + +/* set name to "iaa_crypto" */ +memset (wq->name,0 ,WQ_NAME_SIZE +1 ); +strscpy (wq->name,"iaa_crypto" ,WQ_NAME_SIZE +1 ); + +/* set driver_name to "crypto" */ +memset (wq->driver_name,0 ,DRIVER_NAME_SIZE +1 ); +strscpy (wq->driver_name,"crypto" ,DRIVER_NAME_SIZE +1 ); + + engine = idxd->engines[0 ]; + +/* set engine group to 0 */ + engine->group = idxd->groups[0 ]; + engine->group->num_engines++; + +return 0 ; +}drivers/dma/idxd/idxd.h +4
-0@@ -277,6 +277,8 @@ struct idxd_dma_dev {struct dma_device dma; }; +typedef int (*load_device_defaults_fn_t ) (struct idxd_device *idxd); +struct idxd_driver_data {const char *name_prefix;enum idxd_type type;@@ -286,6 +288,7 @@ struct idxd_driver_data {int evl_cr_off;int cr_status_off;int cr_result_off; +load_device_defaults_fn_t load_device_defaults; };struct idxd_evl {@@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd);void idxd_wqs_quiesce (struct idxd_device *idxd);bool idxd_queue_int_handle_resubmit (struct idxd_desc *desc);void multi_u64_to_bmap (unsigned long *bmap,u64 *val,int count); +int idxd_load_iaa_device_defaults (struct idxd_device *idxd);/* device interrupt control */ irqreturn_t idxd_misc_thread (int vec,void *data);drivers/dma/idxd/init.c +7
-0@@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr), .cr_status_off = offsetof(struct iax_completion_record, status), .cr_result_off = offsetof(struct iax_completion_record, error_code), + .load_device_defaults = idxd_load_iaa_device_defaults, }, };@@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; } +if (data->load_device_defaults) { + rc = data->load_device_defaults (idxd); +if (rc) +dev_warn (dev,"IDXD loading device defaults failed\n" ); + } + rc =idxd_register_devices (idxd);if (rc) {dev_err (dev,"IDXD sysfs setup failed\n" );
Re: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
Quoted 55 lines · Dave Jiang
Quoted 52 lines · Tom Zanussi
Add a
load_device_defaults()function pointer to structidxd_driver_data, which if defined, will be called when an idxd device
is probed and will allow the idxd device to be configured with default
values.The
load_device_defaults()function is passed an idxd device to work
with to set specific device attributes.Also add a
load_device_defaults()implementation IAA devices; future
patches would add default functions for other device types such as DSA.The way idxd device probing works, if the device configuration is valid at that point e.g. at least one workqueue and engine is properly
configured then the device will be enabled and ready to go.The IAA implementation,
idxd_load_iaa_device_defaults(), configures a
single workqueue (wq0) for each device with the following default values:mode "dedicated"
threshold 0
size 16
priority 10
type IDXD_WQT_KERNEL
group 0
name "iaa_crypto"
driver_name "crypto"Note that this now adds another configuration step for any users that
want to configure their own devices/workqueus with something different
in that they'll first need to disable (in the case of IAA) wq0 and the
device itself before they can set their own attributes and re- enable,
since they've been already been auto-enabled. Note also that in order
for the new configuration to be applied to the deflate-iaa crypto algorithm theiaa_cryptomodule needs to unregister the old version,
which is accomplished by removing theiaa_cryptomodule, and re-registering it with the new configuration by reinserting theiaa_cryptomodule.
Quoted 3 lines
Quoted 1 line
Signed-off-by Tom Zanussi <[email protected]>Reviewed-by Dave Jiang <[email protected]>
Thanks, Dave!
Tom
Quoted 147 lines
Quoted 147 lines
---
drivers/dma/idxd/Makefile | 2 +-
drivers/dma/idxd/defaults.c | 53
+++++++++++++++++++++++++++++++++++++
drivers/dma/idxd/idxd.h | 4 +++
drivers/dma/idxd/init.c | 7 +++++4 files changed, 65 insertions(+), 1 deletion(-)create mode 100644
drivers/dma/idxd/defaults.cdrivers/dma/idxd/Makefile +0
-0@@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.oidxd_bus-y := bus.o
obj-$(CONFIG_INTEL_IDXD) += idxd.o
-idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o
+idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o
idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.odrivers/dma/idxd/defaults.c new file +53
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ +#include <linux/kernel.h> +#include "idxd.h" + +int idxd_load_iaa_device_defaults (struct idxd_device *idxd) +{ + struct idxd_engine *engine; + struct idxd_group *group; + struct idxd_wq *wq; + + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) + return 0; + + wq = idxd->wqs[0]; + + if (wq->state != IDXD_WQ_DISABLED) + return -EPERM; + + /* set mode to "dedicated" */ + set_bit(WQ_FLAG_DEDICATED, &wq->flags); + wq->threshold = 0; + + /* set size to 16 */ + wq->size = 16; + + /* set priority to 10 */ + wq->priority = 10; + + /* set type to "kernel" */ + wq->type = IDXD_WQT_KERNEL; + + /* set wq group to 0 */ + group = idxd->groups[0]; + wq->group = group; + group->num_wqs++; + + /* set name to "iaa_crypto" */ + memset(wq->name, 0, WQ_NAME_SIZE + 1); + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); + + /* set driver_name to "crypto" */ + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); + + engine = idxd->engines[0]; + + /* set engine group to 0 */ + engine->group = idxd->groups[0]; + engine->group->num_engines++; + + return 0; +}drivers/dma/idxd/idxd.h +0
-0@@ -277,6 +277,8 @@ struct idxd_dma_dev { struct dma_device dma; };
+typedef int (*load_device_defaults_fn_t) (structidxd_device*idxd);
+
structidxd_driver_data{
const char*name_prefix;
enumidxd_typetype;drivers/dma/idxd/idxd.h +1
-0@@ -286,6 +288,7 @@ struct idxd_driver_data { int evl_cr_off; int cr_status_off; int cr_result_off; + load_device_defaults_fn_t load_device_defaults; };
structidxd_evl{drivers/dma/idxd/idxd.h +1
-0@@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd); void idxd_wqs_quiesce(struct idxd_device *idxd); bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); +int idxd_load_iaa_device_defaults (struct idxd_device *idxd);
/* device interrupt control */
irqreturn_tidxd_misc_thread(int vec, void *data);drivers/dma/idxd/init.c +0
-0@@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr),.cr_status_off = offsetof(struct
iax_completion_record, status),
.cr_result_off = offsetof(structiax_completion_record,error_code),
+ .load_device_defaults =idxd_load_iaa_device_defaults,
},
};drivers/dma/idxd/init.c +0
-0@@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; }
+ if (data->load_device_defaults) {
+ rc =data->load_device_defaults(idxd);
+ if (rc)
+ dev_warn(dev, "IDXD loading device defaults failed\n");
+ }
+
rc =idxd_register_devices(idxd);
if (rc) {
dev_err(dev, "IDXD sysfs setup failed\n");
Re: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
In reply to Tom ZanussiHi, Tom,
Quoted 16 lines · Tom Zanussi
Add a
load_device_defaults()function pointer to structidxd_driver_data, which if defined, will be called when an idxd device is probed and will allow the idxd device to be configured with default values.The
load_device_defaults()function is passed an idxd device to work with to set specific device attributes.Also add a
load_device_defaults()implementation IAA devices; future patches would add default functions for other device types such as DSA.The way idxd device probing works, if the device configuration is valid at that point e.g. at least one workqueue and engine is properly configured then the device will be enabled and ready to go.
Quoted 7 lines
The IAA implementation,
idxd_load_iaa_device_defaults(), configures a single workqueue (wq0) for each device with the following default values:mode "dedicated" threshold 0 size 16
Why is it 16?
If wqcap supports less than 16, configuring wq size 16 will fail.
If wqcap supports more than 16, wq size 16 uses less wq size than capable and less performance.
Is it better to set wq size as total wq size reported in wqcap?
Quoted 75 lines
priority 10 type IDXD_WQT_KERNEL group 0 name "iaa_crypto" driver_name "crypto"Note that this now adds another configuration step for any users that want to configure their own devices/workqueus with something different in that they'll first need to disable (in the case of IAA) wq0 and the device itself before they can set their own attributes and re-enable, since they've been already been auto-enabled. Note also that in order for the new configuration to be applied to the deflate-iaa crypto algorithm the
iaa_cryptomodule needs to unregister the old version, which is accomplished by removing theiaa_cryptomodule, and re-registering it with the new configuration by reinserting theiaa_cryptomodule.Signed-off-by Tom Zanussi <[email protected]>--- drivers/dma/idxd/Makefile | 2 +- drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++ drivers/dma/idxd/idxd.h | 4 +++ drivers/dma/idxd/init.c | 7 +++++ 4 files changed, 65 insertions(+), 1 deletion(-)create mode 100644
drivers/dma/idxd/defaults.cdrivers/dma/idxd/Makefile +1
-1@@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o idxd_bus-y := bus.o obj-$(CONFIG_INTEL_IDXD) += idxd.o -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.odrivers/dma/idxd/defaults.c new file +30
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ +#include <linux/kernel.h> +#include "idxd.h" + +int idxd_load_iaa_device_defaults (struct idxd_device *idxd) +{ +struct idxd_engine *engine; +struct idxd_group *group; +struct idxd_wq *wq; + +if (!test_bit (IDXD_FLAG_CONFIGURABLE , &idxd->flags)) +return 0 ; + + wq = idxd->wqs[0 ]; + +if (wq->state !=IDXD_WQ_DISABLED ) +return -EPERM ; + +/* set mode to "dedicated" */ +set_bit (WQ_FLAG_DEDICATED , &wq->flags); + wq->threshold =0 ; + +/* set size to 16 */ + wq->size =16 ; + +/* set priority to 10 */ + wq->priority =10 ; + +/* set type to "kernel" */
drivers/dma/idxd/defaults.c line 40
Quoted 10 lines
drivers/dma/idxd/defaults.c new file +10
-0+ wq->type =IDXD_WQT_KERNEL ; + +/* set wq group to 0 */ + group = idxd->groups[0 ]; + wq->group = group; + group->num_wqs++; + +/* set name to "iaa_crypto" */ +memset (wq->name,0 ,WQ_NAME_SIZE +1 ); +strscpy (wq->name,"iaa_crypto" ,WQ_NAME_SIZE +1 );
Is strcpy(wq->name, "iaa_crypto") simpler than memset() and strscpy()?
drivers/dma/idxd/defaults.c line 44
Quoted 4 lines
drivers/dma/idxd/defaults.c new file +4
-0+ +/* set driver_name to "crypto" */ +memset (wq->driver_name,0 ,DRIVER_NAME_SIZE +1 ); +strscpy (wq->driver_name,"crypto" ,DRIVER_NAME_SIZE +1 );
Is strcpy(wq->driver_name, "crypto") simpler?
Quoted 53 lines
drivers/dma/idxd/defaults.c new file +9
-0+ + engine = idxd->engines[0 ]; + +/* set engine group to 0 */ + engine->group = idxd->groups[0 ]; + engine->group->num_engines++; + +return 0 ; +}drivers/dma/idxd/idxd.h +4
-0@@ -277,6 +277,8 @@ struct idxd_dma_dev {struct dma_device dma; }; +typedef int (*load_device_defaults_fn_t ) (struct idxd_device *idxd); +struct idxd_driver_data {const char *name_prefix;enum idxd_type type;@@ -286,6 +288,7 @@ struct idxd_driver_data {int evl_cr_off;int cr_status_off;int cr_result_off; +load_device_defaults_fn_t load_device_defaults; };struct idxd_evl {@@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd);void idxd_wqs_quiesce (struct idxd_device *idxd);bool idxd_queue_int_handle_resubmit (struct idxd_desc *desc);void multi_u64_to_bmap (unsigned long *bmap,u64 *val,int count); +int idxd_load_iaa_device_defaults (struct idxd_device *idxd);/* device interrupt control */ irqreturn_t idxd_misc_thread (int vec,void *data);drivers/dma/idxd/init.c +1
-0@@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr), .cr_status_off = offsetof(struct iax_completion_record, status), .cr_result_off = offsetof(struct iax_completion_record, error_code), + .load_device_defaults = idxd_load_iaa_device_defaults, }, };@@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; }
drivers/dma/idxd/init.c static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 757
Quoted 10 lines
drivers/dma/idxd/init.c +6
-0+if (data->load_device_defaults) { + rc = data->load_device_defaults (idxd); +if (rc) +dev_warn (dev,"IDXD loading device defaults failed\n" ); + } + rc =idxd_register_devices (idxd);if (rc) {dev_err (dev,"IDXD sysfs setup failed\n" );
Thanks.
-Fenghua
Re: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
Hi Fenghua,
Quoted 33 lines · Fenghua Yu
Hi, Tom,
Quoted 21 lines · Tom Zanussi
Add a
load_device_defaults()function pointer to structidxd_driver_data, which if defined, will be called when an idxd device
is probed and will allow the idxd device to be configured with default
values.The
load_device_defaults()function is passed an idxd device to work
with to set specific device attributes.Also add a
load_device_defaults()implementation IAA devices; future
patches would add default functions for other device types such as DSA.The way idxd device probing works, if the device configuration is valid at that point e.g. at least one workqueue and engine is properly
configured then the device will be enabled and ready to go.Quoted 8 lines
The IAA implementation,
idxd_load_iaa_device_defaults(), configures a
single workqueue (wq0) for each device with the following default values:mode "dedicated"
threshold 0
size 16
Quoted 7 lines
Why is it 16?
If wqcap supports less than 16, configuring wq size 16 will fail. If wqcap supports more than 16, wq size 16 uses less wq size than capable and less performance.
Is it better to set wq size as total wq size reported in wqcap?
Yes, good point. I'll calculate this based on wqcap.
Quoted 90 lines
Quoted 90 lines
priority 10
type IDXD_WQT_KERNEL
group 0
name "iaa_crypto"
driver_name "crypto"Note that this now adds another configuration step for any users that
want to configure their own devices/workqueus with something different
in that they'll first need to disable (in the case of IAA) wq0 and the
device itself before they can set their own attributes and re- enable,
since they've been already been auto-enabled. Note also that in order
for the new configuration to be applied to the deflate-iaa crypto algorithm theiaa_cryptomodule needs to unregister the old version,
which is accomplished by removing theiaa_cryptomodule, and re-registering it with the new configuration by reinserting theiaa_cryptomodule.Signed-off-by Tom Zanussi <[email protected]>---
drivers/dma/idxd/Makefile | 2 +-
drivers/dma/idxd/defaults.c| 53
+++++++++++++++++++++++++++++++++++++
drivers/dma/idxd/idxd.h | 4 +++
drivers/dma/idxd/init.c | 7 +++++4 files changed, 65 insertions(+), 1 deletion(-)create mode 100644
drivers/dma/idxd/defaults.cdrivers/dma/idxd/Makefile +0
-0@@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.oidxd_bus-y := bus.o
obj-$(CONFIG_INTEL_IDXD) += idxd.o
-idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o
+idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o
idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.odrivers/dma/idxd/defaults.c new file +35
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ +#include <linux/kernel.h> +#include "idxd.h" + +int idxd_load_iaa_device_defaults (struct idxd_device *idxd) +{ + struct idxd_engine *engine; + struct idxd_group *group; + struct idxd_wq *wq; + + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) + return 0; + + wq = idxd->wqs[0]; + + if (wq->state != IDXD_WQ_DISABLED) + return -EPERM; + + /* set mode to "dedicated" */ + set_bit(WQ_FLAG_DEDICATED, &wq->flags); + wq->threshold = 0; + + /* set size to 16 */ + wq->size = 16; + + /* set priority to 10 */ + wq->priority = 10; + + /* set type to "kernel" */ + wq->type = IDXD_WQT_KERNEL; + + /* set wq group to 0 */ + group = idxd->groups[0]; + wq->group = group;
Quoted 8 lines
drivers/dma/idxd/defaults.c line 40
Quoted 5 lines
drivers/dma/idxd/defaults.c new file +5
-0+ group->num_wqs++; + + /* set name to "iaa_crypto" */ + memset(wq->name, 0, WQ_NAME_SIZE + 1); + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1);Is
strcpy(wq->name, "iaa_crypto")simpler thanmemset()andstrscpy()?
That's what I originally had, but checkpatch complained about it, suggesting strscpy, so I changed it to make checkpatch happy.
Quoted 7 lines
drivers/dma/idxd/defaults.c line 44
Quoted 5 lines
drivers/dma/idxd/defaults.c new file +4
-0+ + /* set driver_name to "crypto" */ + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1);Is
strcpy(wq->driver_name, "crypto")simpler?
Same here.
Thanks,
Tom
Quoted 76 lines
Quoted 64 lines
drivers/dma/idxd/defaults.c new file +9
-0+ + engine = idxd->engines[0]; + + /* set engine group to 0 */ + engine->group = idxd->groups[0]; + engine->group->num_engines++; + + return 0; +}drivers/dma/idxd/idxd.h +0
-0@@ -277,6 +277,8 @@ struct idxd_dma_dev { struct dma_device dma; };
+typedef int (*load_device_defaults_fn_t) (structidxd_device*idxd);
+
structidxd_driver_data{
const char*name_prefix;
enumidxd_typetype;drivers/dma/idxd/idxd.h +1
-0@@ -286,6 +288,7 @@ struct idxd_driver_data { int evl_cr_off; int cr_status_off; int cr_result_off; + load_device_defaults_fn_t load_device_defaults; };
structidxd_evl{drivers/dma/idxd/idxd.h +1
-0@@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd); void idxd_wqs_quiesce(struct idxd_device *idxd); bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); +int idxd_load_iaa_device_defaults (struct idxd_device *idxd);
/* device interrupt control */
irqreturn_tidxd_misc_thread(int vec, void *data);drivers/dma/idxd/init.c +0
-0@@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr),.cr_status_off = offsetof(struct
iax_completion_record, status),
.cr_result_off = offsetof(structiax_completion_record,error_code),
+ .load_device_defaults =idxd_load_iaa_device_defaults,
},
};drivers/dma/idxd/init.c +0
-0@@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; }
+ if (data->load_device_defaults) {
+ rc =data->load_device_defaults(idxd);Quoted 8 lines
+ if (rc)
+ dev_warn(dev, "IDXD loading device defaults failed\n");
+ }
+
rc =idxd_register_devices(idxd);
if (rc) {
dev_err(dev, "IDXD sysfs setup failed\n");Thanks.
-Fenghua
Re: [PATCH v10 02/14] dmaengine: idxd: Rename drv_enable/disable_wq to idxd_drv_enable/disable_wq, and export
In reply to Tom ZanussiQuoted 6 lines · Tom Zanussi
Rename
drv_enable_wqanddrv_disable_wqtoidxd_drv_enable_wqandidxd_drv_disable_wqrespectively, so that they're no longer too generic to be exported. This also matches existing naming within the idxd driver.And to allow idxd sub-drivers to enable and disable wqs, export them.
Signature · 1 line
~Vinod
RE: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
In reply to Tom ZanussiHi, Tom,
Quoted 9 lines
From: Tom Zanussi <[email protected]>
Quoted 5 lines
Quoted 3 lines
+ /* set name to "
iaa_crypto" */
+ memset(wq->name, 0,WQ_NAME_SIZE+ 1);
+ strscpy(wq->name, "iaa_crypto",WQ_NAME_SIZE+ 1);Is
strcpy(wq->name, "iaa_crypto")simpler thanmemset()andstrscpy()?That's what I originally had, but checkpatch complained about it, suggesting strscpy, so I changed it to make checkpatch happy.
Why is size WQ_NAME_SIZE+1 instead of WQ_NAME_SIZE? Will WQ_NAME_SIZE+1 cause mem corruption because wq->name is defined as a string with WQ_NAME_SIZE?
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
+
+ /* setdriver_nameto "crypto" */
+ memset(wq->driver_name, 0,DRIVER_NAME_SIZE+ 1); + strscpy(wq->driver_name, "crypto",DRIVER_NAME_SIZE+ 1);Is
strcpy(wq->driver_name, "crypto")simpler?Same here.
Ditto.
Thanks.
-Fenghua
Re: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults
Hi Fenghua,
Quoted 10 lines · Fenghua
Hi, Tom,
Quoted 8 lines
From: Tom Zanussi <[email protected]>
Quoted 6 lines
Quoted 3 lines
+ /* set name to "
iaa_crypto" */
+ memset(wq->name, 0,WQ_NAME_SIZE+ 1);
+ strscpy(wq->name, "iaa_crypto",WQ_NAME_SIZE+ 1);Is
strcpy(wq->name, "iaa_crypto")simpler thanmemset()andstrscpy()?
Quoted 7 lines
Quoted 3 lines
That's what I originally had, but checkpatch complained about it, suggesting
strscpy, so I changed it to make checkpatch happy.Why is size WQ_NAME_SIZE+1 instead of
WQ_NAME_SIZE? Will WQ_NAME_SIZE+1 cause mem corruption becausewq->nameis defined as a string withWQ_NAME_SIZE?
No, wq->name actually is:
char name[WQ_NAME_SIZE + 1];
This code is doing the same thing as elsewhere in the idxd driver except instead of sprintf() it uses strscpy().
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
+
+ /* setdriver_nameto "crypto" */
+ memset(wq->driver_name, 0,DRIVER_NAME_SIZE+ 1); + strscpy(wq->driver_name, "crypto",DRIVER_NAME_SIZE+ 1);
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Is
strcpy(wq->driver_name, "crypto")simpler?Same here.
Ditto.
Same.
Tom
Quoted 3 lines
Thanks.
-Fenghua