lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <yq1tvnj780o.fsf@oracle.com>
Date:   Fri, 24 Aug 2018 17:46:15 -0400
From:   "Martin K. Petersen" <martin.petersen@...cle.com>
To:     Ard Biesheuvel <ard.biesheuvel@...aro.org>
Cc:     "Martin K. Petersen" <martin.petersen@...cle.com>,
        Jeffrey Lien <Jeff.Lien@....com>,
        Christoph Hellwig <hch@...radead.org>,
        "linux-kernel\@vger.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-crypto\@vger.kernel.org" <linux-crypto@...r.kernel.org>,
        "linux-block\@vger.kernel.org" <linux-block@...r.kernel.org>,
        "linux-scsi\@vger.kernel.org" <linux-scsi@...r.kernel.org>,
        "herbert\@gondor.apana.org.au" <herbert@...dor.apana.org.au>,
        "tim.c.chen\@linux.intel.com" <tim.c.chen@...ux.intel.com>,
        David Darrington <david.darrington@....com>,
        Jeff Furlong <jeff.furlong@....com>
Subject: Re: [PATCH] Performance Improvement in CRC16 Calculations.


Ard,

> I'd prefer to handle this without help from userland.
>
> It shouldn't be too difficult to register a module notifier that only
> sets a flag (or the static key, even?), and to free and re-allocate
> the crc_t10dif transform if the flag is set.

Something like this proof of concept?

diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index 1ad33e555805..87d0e8f0794a 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -15,10 +15,50 @@
 #include <linux/init.h>
 #include <crypto/hash.h>
 #include <linux/static_key.h>
+#include <linux/notifier.h>
 
 static struct crypto_shash *crct10dif_tfm;
 static struct static_key crct10dif_fallback __read_mostly;
 
+static void crc_t10dif_print(void)
+{
+	if (static_key_false(&crct10dif_fallback))
+		pr_info("CRC T10 DIF calculated using library function\n");
+	else
+		pr_info("CRC T10 DIF calculated using crypto hash %s\n",
+			crypto_tfm_alg_driver_name(crypto_shash_tfm(crct10dif_tfm)));
+}
+
+static int crc_t10dif_rehash(struct notifier_block *self, unsigned long val, void *data)
+{
+#ifdef CONFIG_MODULES
+	struct module *mod = data;
+
+	if (val != MODULE_STATE_LIVE ||
+	    strncmp(mod->name, "crct10dif", strlen("crct10dif")))
+		return 0;
+
+	/* Fall back to library function while we replace the tfm */
+	static_key_slow_inc(&crct10dif_fallback);
+
+	crypto_free_shash(crct10dif_tfm);
+	crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
+	if (IS_ERR(crct10dif_tfm)) {
+		crct10dif_tfm = NULL;
+		goto out;
+	}
+
+	static_key_slow_dec(&crct10dif_fallback);
+out:
+	crc_t10dif_print();
+	return 0;
+#endif /* CONFIG_MODULES */
+}
+
+static struct notifier_block crc_t10dif_nb = {
+	.notifier_call = crc_t10dif_rehash,
+};
+
 __u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len)
 {
 	struct {
@@ -49,16 +90,21 @@ EXPORT_SYMBOL(crc_t10dif);
 
 static int __init crc_t10dif_mod_init(void)
 {
+	register_module_notifier(&crc_t10dif_nb);
+
 	crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
 	if (IS_ERR(crct10dif_tfm)) {
 		static_key_slow_inc(&crct10dif_fallback);
 		crct10dif_tfm = NULL;
 	}
+
+	crc_t10dif_print();
 	return 0;
 }
 
 static void __exit crc_t10dif_mod_fini(void)
 {
+	unregister_module_notifier(&crc_t10dif_nb);
 	crypto_free_shash(crct10dif_tfm);
 }
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ