Message ID | 20230328153535.126223-1-tom.zanussi@linux.intel.com |
---|---|
Headers | show |
Series | crypto: Add Intel Analytics Accelerator (IAA) crypto compression driver | expand |
Hi Hillf, On Wed, 2023-03-29 at 15:51 +0800, Hillf Danton wrote: > On 28 Mar 2023 10:35:30 -0500 Tom Zanussi > <tom.zanussi@linux.intel.com> > > +/* > > + * Given a cpu, find the closest IAA instance. The idea is to try > > to > > + * choose the most appropriate IAA instance for a caller and > > spread > > + * available workqueues around to clients. > > + */ > > +static inline int cpu_to_iaa(int cpu) > > +{ > > + int node, n_cpus = 0, test_cpu, iaa = 0; > > + int nr_iaa_per_node, nr_cores_per_iaa; > > + const struct cpumask *node_cpus; > > + > > + if (!nr_nodes) > > + return 0; > > + > > + nr_iaa_per_node = nr_iaa / nr_nodes; > > + if (!nr_iaa_per_node) > > + return 0; > > + > > + nr_cores_per_iaa = nr_cpus_per_node / nr_iaa_per_node; > > + > > + for_each_online_node(node) { > > + node_cpus = cpumask_of_node(node); > > + if (!cpumask_test_cpu(cpu, node_cpus)) > > + continue; > > cpu_to_node(cpu) works for you. Yes, thanks for pointing that out. > > + > > + for_each_cpu(test_cpu, node_cpus) { > > + if ((n_cpus % nr_cpus_per_node) == 0) > > + iaa = node * nr_iaa_per_node; > > + > > + if (test_cpu == cpu) > > + return iaa; > > Given nr_iaa_per_node, why round robin-ing every iaa in the node not > work? True, we should be able to simplify this, will do for the next version. Thanks, Tom > > + > > + n_cpus++; > > + > > + if ((n_cpus % cpus_per_iaa) == 0) > > + iaa++; > > + } > > + } > > + > > + return -1; > > +}
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,
Hi Herbert, On Thu, 2023-04-06 at 16:00 +0800, Herbert Xu wrote: > 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 :) No problem, thanks for reviewing the code. ;-) > > 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. > OK, yeah, thanks for pointing this out along with the detailed explanation and remedy. Will take care of this in the next version. Tom > Thanks,