Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3314563imm; Fri, 24 Aug 2018 14:48:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbwJyt6W25FZ3CgUDj4//eM7DSKT+HjvS0DH5KnoIarMm0+mqvHUu/MSk7iWXaxahWzBpRw X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr3671982pfa.238.1535147290262; Fri, 24 Aug 2018 14:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535147290; cv=none; d=google.com; s=arc-20160816; b=P52EFHcqyOTKQhKdQyZfssAy7OJIDhUP5wiK8pUhcbuAfvufTIarCoDH7SPry9s6Ux 1P8fi+QdFx7KwS6KP8S/uvXZQmrooaoiDhh2SIHuzlKrtPvLle8muvwwPl+Nt/yD3x2p YopHFNu9R6sgCg4SfKxn8zaUKy20BkJAd4HM8PDNrxRczuV9gQLoJms9lS5EIuyAUrnd GMl+E2O7mP3LV11HfVn59s0hWAh5gIzXhPXra8etsjRViK61T0vakrm+zSrMpuv0AoDF T5fZaRGySBq5DnQaWOix+1+sNHrqqxMz/JBBDEiv21ajwzs7v0Ie7cFHeNpUWRTEf8sA NDow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:organization:from:subject:cc:to :dkim-signature:arc-authentication-results; bh=ORU+yIvUntIEDM52lIK3kWseF3WoFNqF9okZ3+clss0=; b=xU5H6mLlI10bYFX/jKg09rz4WSFoCxHHrNpN9YC4bfOIDbNzWd2HUrMUAIJ2zgBwFV 6gHjv0vkA/vBnM2LvaK4fccFNkd6wUl+hjuMiGM8D27YUrbLbl2ovSPhwezJI3ZbkFvM zJk/TP8EcFebMzmo6HzH5XPbR9ZEsJpNON1OFvyb4rrPoQvE6IAgYm5tqeZWLEu73oD1 9HON5ivJgQvhBzygbkS5ueoaSxiFpm5xmvfIERBkOn42AXkYdkvAQiA3RSosavggUCxh kcocIDTzGb0dEaYdLkFN+DfVnFlpaTVZP8uWhk5jl9ZhzTduR5vjTvPR/b4+MKdZUfhx OLeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=YvNSsY3m; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si7834529pgm.570.2018.08.24.14.47.55; Fri, 24 Aug 2018 14:48:10 -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=@oracle.com header.s=corp-2018-07-02 header.b=YvNSsY3m; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbeHYBXL (ORCPT + 99 others); Fri, 24 Aug 2018 21:23:11 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:55898 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbeHYBXK (ORCPT ); Fri, 24 Aug 2018 21:23:10 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7OLd97l152884; Fri, 24 Aug 2018 21:46:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : subject : from : references : date : in-reply-to : message-id : mime-version : content-type; s=corp-2018-07-02; bh=ORU+yIvUntIEDM52lIK3kWseF3WoFNqF9okZ3+clss0=; b=YvNSsY3mlDYk267wSZ2O6QM8y0w9E/E+ldnT5AHFAeYeFBKPjDq+kxbj8mXfaqvgNQrR 9HzoVQcdC8DU5RIbv8WHcsVmzyH/ffWzLFhOI9CG8XO/U3UinKWiT5vb1VO51udZgvBk S/gui+iNjY2AwFdKAkcEbGnHk3mzRGmSQGd7qGwuQINOMzNSsnXeatmrqPvIrh59VhC2 rDbzwcXqyNpCpZPc/gjg2sZAfsqZBVecvkK+X9Ezd4zzWY6zdL3NgtoAwSid+yuXB6AD Unfeey7vKzGKebw9bndIvejnzsMJ5pjAOBIZuEMmlDkjrLqH345OYC6PVY9H86+QArXk +w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2kxc3ra8wm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Aug 2018 21:46:21 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7OLkK99029691 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Aug 2018 21:46:20 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7OLkJXf012859; Fri, 24 Aug 2018 21:46:19 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 24 Aug 2018 14:46:18 -0700 To: Ard Biesheuvel Cc: "Martin K. Petersen" , 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 Subject: Re: [PATCH] Performance Improvement in CRC16 Calculations. From: "Martin K. Petersen" Organization: Oracle Corporation References: <1533928331-21303-1-git-send-email-jeff.lien@wdc.com> <20180822062016.GA10356@infradead.org> Date: Fri, 24 Aug 2018 17:46:15 -0400 In-Reply-To: (Ard Biesheuvel's message of "Fri, 24 Aug 2018 18:38:36 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8995 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808240219 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); }