linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: davem@davemloft.net, fenghua.yu@intel.com, vkoul@kernel.org,
	dave.jiang@intel.com, tony.luck@intel.com,
	wajdi.k.feghali@intel.com, james.guilford@intel.com,
	kanchana.p.sridhar@intel.com, giovanni.cabiddu@intel.com,
	linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
	dmaengine@vger.kernel.org
Subject: Re: [PATCH v2 12/15] crypto: iaa - Add support for iaa_crypto deflate compression algorithm
Date: Thu, 6 Apr 2023 16:00:38 +0800	[thread overview]
Message-ID: <ZC58JggIXgpJ1tpD@gondor.apana.org.au> (raw)
In-Reply-To: <20230328153535.126223-13-tom.zanussi@linux.intel.com>

On Tue, Mar 28, 2023 at 10:35:32AM -0500, Tom Zanussi wrote:
>
> @@ -881,12 +1574,26 @@ static int iaa_crypto_probe(struct idxd_dev *idxd_dev)
>  
>  	rebalance_wq_table();
>  
> +	if (first_wq) {
> +		iaa_crypto_enabled = true;
> +		ret = iaa_register_compression_device();
> +		if (ret != 0) {
> +			iaa_crypto_enabled = false;
> +			dev_dbg(dev, "IAA compression device registration failed\n");
> +			goto err_register;
> +		}
> +
> +		pr_info("iaa_crypto now ENABLED\n");
> +	}
> +

Sorry for picking on your driver but I've got to start somewhere :)

A long standing problem shared by almost all crypto drivers is that
the hardware removal handling is completely broken.

This is because hardware can be removed at any time, including during
a crypto operatin.  So drivers must work carefully around that fact.

Here is a recipe for dealing with this safely:

1) Never unregister your crypto algorithms, even after the last
piece of hardware has been unplugged.  The algorithms should only
be unregistered (if they have been registered through the first
successful probe call) in the module unload function.

2) Never free any software state for your hardware without some form
of synchronisation with oustanding operations.

Any mechanism would do, for example, you could use a spinlock if the
critical path isn't very long.  The operational path would take the
lock, check the hardware state, and if present proceed with the
operation (but still being prepared to cope if the hardware goes
AWAL because even if the driver state is still present the actual
hardware may be gone already).

Then the removal path would simply take the spinlock, set a flag
indicating the hardware is gone and then you could safely unlock
and free your driver states.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2023-04-06  8:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 15:35 [PATCH v2 00/15] crypto: Add Intel Analytics Accelerator (IAA) crypto compression driver Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 01/15] dmaengine: idxd: add wq driver name support for accel-config user tool Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 02/15] dmaengine: idxd: add external module driver support for dsa_bus_type Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 03/15] dmaengine: idxd: Export drv_enable/disable and related functions Tom Zanussi
2023-03-28 16:02   ` Dave Jiang
2023-03-28 15:35 ` [PATCH v2 04/15] dmaengine: idxd: Export descriptor management functions Tom Zanussi
2023-03-28 16:04   ` Dave Jiang
2023-03-28 16:12     ` Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 05/15] dmaengine: idxd: Export wq resource " Tom Zanussi
2023-03-28 16:04   ` Dave Jiang
2023-03-28 15:35 ` [PATCH v2 06/15] dmaengine: idxd: Add private_data to struct idxd_wq Tom Zanussi
2023-03-28 16:06   ` Dave Jiang
2023-03-28 16:13     ` Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 07/15] dmaengine: idxd: add callback support for iaa crypto Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 08/15] crypto: iaa - Add IAA Compression Accelerator Documentation Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 09/15] crypto: iaa - Add Intel IAA Compression Accelerator crypto driver core Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 10/15] crypto: iaa - Add per-cpu workqueue table with rebalancing Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 11/15] crypto: iaa - Add compression mode management along with fixed mode Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 12/15] crypto: iaa - Add support for iaa_crypto deflate compression algorithm Tom Zanussi
2023-04-06  8:00   ` Herbert Xu [this message]
2023-04-06 14:43     ` Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 13/15] crypto: iaa - Add support for default IAA 'canned' compression mode Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 14/15] crypto: iaa - Add irq support for the crypto async interface Tom Zanussi
2023-03-28 15:35 ` [PATCH v2 15/15] crypto: iaa - Add IAA Compression Accelerator stats Tom Zanussi
     [not found] ` <20230329075149.2736-1-hdanton@sina.com>
2023-03-29 14:58   ` [PATCH v2 10/15] crypto: iaa - Add per-cpu workqueue table with rebalancing Tom Zanussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZC58JggIXgpJ1tpD@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dave.jiang@intel.com \
    --cc=davem@davemloft.net \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=giovanni.cabiddu@intel.com \
    --cc=james.guilford@intel.com \
    --cc=kanchana.p.sridhar@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.zanussi@linux.intel.com \
    --cc=tony.luck@intel.com \
    --cc=vkoul@kernel.org \
    --cc=wajdi.k.feghali@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).