Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3319803imm; Fri, 24 Aug 2018 14:55:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY1zorAKGAe2HZvMJDNsGfmwrLX5gCDeNxopDA5VtIMvyU+hYVOfE5+EdgxWCsDqKkwC4Wd X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr3241860pgp.334.1535147747954; Fri, 24 Aug 2018 14:55:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535147747; cv=none; d=google.com; s=arc-20160816; b=NFKGC3fgzNBjbzqa9p90eqPdMAWfT6zLskZfXuo89/d8020bWSPIfZR5dVy0Gkjnhq q7cHuBVL3tXoXXRsSG8ZVYwqGeKeLMuTJp3gEc+AT1nSR+jgARdTveahBrYPRXRKyyto L/692l0W0XE5I/dnfE/2W1zD43ZwGrM00tv6GD8AQIPElN1Vh8iVOO+ZxAxfVLoTJe/p x9C808GALh0pCVxvSdrIg7lfnKB0psEIqdgBLoPh5VVBTmFqUrMyyzoYb23G0MulAXHu z2fyyQ0ORTWBgGEpdnNs9RA2i+vYDPFd888b/eexXC4GrRoEghxBNdgyo499Ojqa47cV IUqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=v424ShiyTLXftwcsDxGFlIW3vyt+xOhu1ZOiBoXjA98=; b=uvA06UZYoFAbQ0y1XbRmHANx8HvtH12Epxz/K0+LK6c6y6bf5jrLAg9AdudPZ107ju LkylMnpa3cUL2Lh/feqY0Qrbe7eEuOLaL7oR47v/AO8NtUSYgplo9uCfL1DPAZ0koQ78 Ma2XRWXaXK9TWAUlGBoxat5pz3y7mYxz2rxrrQ2w8tDjJwUHU7FtETgnBphUZiiGk/uT Wo9kF0buoqpOihjqooKGwWcFYOllBoEc4I9uaFRaTX6ozTJtD7c4ax1gogB8DFD4esdP o+krnKrdzpWqSS+g/GUdccGowEV3u/g6SxvBBDqwcDwoZuqJbCaTHhwRVwp5FO7twqFJ Z5kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjJOkW7N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o21-v6si7698443pgc.658.2018.08.24.14.55.32; Fri, 24 Aug 2018 14:55:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjJOkW7N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbeHYBa4 (ORCPT + 99 others); Fri, 24 Aug 2018 21:30:56 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:38817 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbeHYBaz (ORCPT ); Fri, 24 Aug 2018 21:30:55 -0400 Received: by mail-it0-f66.google.com with SMTP id p129-v6so3747143ite.3 for ; Fri, 24 Aug 2018 14:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=v424ShiyTLXftwcsDxGFlIW3vyt+xOhu1ZOiBoXjA98=; b=YjJOkW7NfqETCaYJzbEpwQZK/SOMjumTj5i44m1okSqwNYDkNkvsycD0aq5+D8VFLC d+mLApLk9uJXvHRDErbx9vPepvkH06MD1uDCMox9M1NYroMulgWNP0Q/miktZh5wtOFl RbuTiLuuEahIoHaC6I+kToS52PgQLv2tyErIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=v424ShiyTLXftwcsDxGFlIW3vyt+xOhu1ZOiBoXjA98=; b=qj8CnHmCGKVEH/oYVtVHMQcRbVs4rymeCOCD2OMQLuc2nkNyaAvLaurfEaJzFXUVHg x9z4MC8sthAQKZFbyDwZYa04d3OB4ZTK+J9bMPW9KSksSdAXzldjpyQ0zCQQzyUYoxgX rxwqTPJOt0Evh+O5M98aLEP9GC8R+XkbOf9bYJwKWASdcDDxr8aSWJ2tmq6y0+rDOqfB RN0RyRTJJ8FDgi2sLFN3HtPx760LyTntS3WrtixCkcuTPmnH/Wh1yr8LAp+krgJWqa4x 9xq3b9/W/1y/vm+03/6i7b4OijOu4Fht5Td/0wUDiObK93uSnFpIfh00Sq0aIGO0IKeb Ju0g== X-Gm-Message-State: APzg51BiK8HAjB1gGtROhKkpj9By9NBhJrFpR2pHM5xoDQhFq3FEqjWX 6g7ftUbaGjgMVFw2FBFOpPiFqjumOMEznybK1ZT4XQ== X-Received: by 2002:a24:8309:: with SMTP id d9-v6mr2833556ite.123.1535147667684; Fri, 24 Aug 2018 14:54:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:ac05:0:0:0:0:0 with HTTP; Fri, 24 Aug 2018 14:54:26 -0700 (PDT) In-Reply-To: References: <1533928331-21303-1-git-send-email-jeff.lien@wdc.com> <20180822062016.GA10356@infradead.org> From: Ard Biesheuvel Date: Fri, 24 Aug 2018 22:54:26 +0100 Message-ID: Subject: Re: [PATCH] Performance Improvement in CRC16 Calculations. To: "Martin K. Petersen" Cc: Jeffrey Lien , Christoph Hellwig , "linux-kernel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-scsi@vger.kernel.org" , "herbert@gondor.apana.org.au" , "tim.c.chen@linux.intel.com" , David Darrington , Jeff Furlong Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24 August 2018 at 22:46, Martin K. Petersen wrote: > > 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 > #include > #include > +#include > > 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); > } > This looks like it should work, yes. It does rely on the module name to start with 'crct10dif' but I guess that is reasonable, and matches the current state on all architectures. Anyone care to boot test this? Jeffrey?