From patchwork Fri Jan 29 13:33:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Vasile X-Patchwork-Id: 8163291 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 45BA59F38B for ; Fri, 29 Jan 2016 13:49:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 440282038D for ; Fri, 29 Jan 2016 13:49:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32A5420386 for ; Fri, 29 Jan 2016 13:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756127AbcA2Ntr (ORCPT ); Fri, 29 Jan 2016 08:49:47 -0500 Received: from mail-bn1bon0066.outbound.protection.outlook.com ([157.56.111.66]:30812 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756078AbcA2Ntq (ORCPT ); Fri, 29 Jan 2016 08:49:46 -0500 Received: from BY2PR03CA054.namprd03.prod.outlook.com (10.141.249.27) by SN1PR0301MB2062.namprd03.prod.outlook.com (10.163.227.149) with Microsoft SMTP Server (TLS) id 15.1.396.15; Fri, 29 Jan 2016 13:33:47 +0000 Received: from BY2FFO11FD035.protection.gbl (2a01:111:f400:7c0c::115) by BY2PR03CA054.outlook.office365.com (2a01:111:e400:2c5d::27) with Microsoft SMTP Server (TLS) id 15.1.396.15 via Frontend Transport; Fri, 29 Jan 2016 13:33:47 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD035.mail.protection.outlook.com (10.1.14.220) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Fri, 29 Jan 2016 13:33:46 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u0TDXCYQ009579; Fri, 29 Jan 2016 06:33:44 -0700 From: Catalin Vasile To: CC: , , , , Catalin Vasile Subject: [RFC 2/2] crypto: tcrypt - Add ahash digest bandwidth tests support Date: Fri, 29 Jan 2016 15:33:07 +0200 Message-ID: <1454074387-8321-3-git-send-email-cata.vasile@nxp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1454074387-8321-1-git-send-email-cata.vasile@nxp.com> References: <1454074387-8321-1-git-send-email-cata.vasile@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 130985480264971590; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD035; 1:7sgDD294t1lXjBCmutFsDg+Za3gC4e15ct6wMtBg/19PDzLslnYaeXTV75FuUfHFq2NDQhFerci5DESDH+S//DmrizcXSTJjBsuhgeRwtgkcdG68IwDrBc6aocJrXwyH9b83jJgI5Y0dcY1NZJ4t71qmayvnxaVXpLqZSb5yYqC11+NZc9r9WZSwEgFBLxkqKRQhQgHZqCjgB1VfBgxUc/dNCusj3K7IxunDpuBfBjOL7aguIyR/fBY3Ngm9TKmZIkZ9eaXosmYuvJUkKUE5YaRpftoDiHH/+6HxKVMzsm9dTAdzMtXhZZeafMIuky89n4exKAb6wN9tKxhiU4mZWkXyUAXK3CPaUNLLn6BcWXUBkRDvH4JrGFY8A3NFJLkVUcvx1Rr9NgmxOPr2cpTGcXHIuG0FCa9+NmQBuf2DBn8hhPnveg/FBabsLohG2+ha5Jgc3pmIF+H01kbvs52rS5PlTYkptl01fwBvJCMaprX8FKBrvMdWC7e3PbkUmQuevlJ7EbNtqnpm1Ue9gBUkuSh+UBWUSwi2xQqf/K/P2V/ZPHoZ9CWpOomBIp7V2xCJ07jlftBX6MUdqUHCEPtYJA== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(18543002)(199003)(76176999)(47776003)(50986999)(4326007)(6806005)(3470700001)(33646002)(5008740100001)(106466001)(5003940100001)(229853001)(2351001)(11100500001)(105606002)(50466002)(19580405001)(110136002)(5001960100002)(2950100001)(92566002)(86362001)(50226001)(77096005)(1096002)(1220700001)(19580395003)(36756003)(2906002)(104016004)(586003)(48376002)(87936001)(85426001)(189998001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR0301MB2062; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 18f751b9-23e1-43b7-7546-08d328b0d064 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2062; 2:3G0H8okqPBTSYAchX1vwS7Grhd7di10AJaYZxQKrjJ7JVe3CuTvF42C2UzqICKhZWOqQWNuZs2XsRzS4UVStvKnctYKBh9qIePZqCZ0YOnHUrbJOWpQKHnggaLfsgNDcqh2FnJuyWRr1LLsSTp755xwEmDovGjMZQe3eyAxiiwRBgIi+QjK0GgyiaqejCHMk; 3:EN6bPHycecV6pLeqs2dYbcUsTEXn0hm4055wHgdTnCc8kBIayJhAdGTa9AoWMzZs5CaZQk1pbhQ9FD1dMhYAgVHUi0ZHwVYcFKpoDXP6SAJWBXFVJtAyaZZTl/nCh4ec3ocxkFfOEaPaHjVG8PiLkrKJcP9x8yFFU8FzMuAjJ7ZK7OmscaWZ40KngByBjhv7CSQPzXDkeSc1DnDWlD0q4Hx8LWD2njUR0fqMfQHrPM8=; 25:nZMxtz6gJq6yFpsWYD21W82qDdiBu8krh5qrrrFj7X0+az1uOqOtA4dnbQGTLJ9D4mvTOd2lainl+guRdFMpPRgwn00AtQkraL+9vqDt31EFCO2BbswMTy8oS1I5JgPaI1A5HsAHHFAyKCA/SXSid9muNiWeKyUUdppYqt8IIhvF6Xiu4lD1mL/5XZ26x5EUlED9RaIbs1nOREeBV0LTRiZFSInPIi6eFBwnw7sww3FuLnlQhgmOVtCHg0uoaegA X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB2062; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(13018025)(13017025)(13015025)(5005006)(13023025)(13024025)(10201501046)(3002001); SRVR:SN1PR0301MB2062; BCL:0; PCL:0; RULEID:(400006); SRVR:SN1PR0301MB2062; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2062; 4:Jle2zWr+z2EHWjmxeseH5Osx5DuXOUb3+KS6KKmOIWSS2sfsLP/wKJGIsAVvL7e1Vf2c1ra4ObrJnFDcrTBuKv8qe7OdnpCrf+H6QVl27xamDTTS/qCuohkigJrp8PD1Zx8YcwRHLQ8u98AxCvDq1t1FRU8T2Av8LIrwqsHFm9TYzzto+LomiMTdLgwlTBceGapFFKLPPVUzxEPHTTLuPWG4nBya7O8S+CvcmhtlvkZWqt2eaggHtj3KjnsSPZCCJrqSuJc5kxhnuZxFocR5Fe0o+l/DgucJWABB8VcQe2jQM7GOiw0vpK3LCDxUXKTiMQ++GmDs3YC7Isjgr8eU5EcnZmzie/kxqkxvvdZtqh6BCkSBlHqGR9ul1CNmZSPlo6jb+tvUptQIR5YJBMtombIu/ZWWfkFuxACbTb6XCxTmQSSSfM8+4XzzeT/8bXW0KZWi5nWPscytOckSubR20BVMKlp9GPWpXcZMcBWZWtY5rsHg+wVgD6+B7yaoUHtB X-Forefront-PRVS: 083691450C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0301MB2062; 23:eIhrF71z8IggMb8qcIjK0imRymXGZyX0qHW4qdm?= =?us-ascii?Q?HJ/l4LJ2msD2Gge5P95sB1iYyPlQR4fjTf0WlPsdhHiAODg5ARrkoFCFKVyc?= =?us-ascii?Q?MnxdUHzjp3WROmoN9y06Ebstv6QmtW7R9PoqV1SlsvUeMd2/BBibOsA9xbsL?= =?us-ascii?Q?fyj+NmXLdp7HCMu1O8vK6D9VnwnI6ROErEnLl44j3qoFTdn7li4IU6PTBbdL?= =?us-ascii?Q?yjWV/vpfvqKbR2UYvhYaS2TOZh56gexrPjvEOF/iI0fK5tGBCvQIdd5zy1z8?= =?us-ascii?Q?1kKB+uqWIghyk4/r7/n0IXIFPqCzo7GN3xNV33ZwxJsy7Wy41eebH3veSdXq?= =?us-ascii?Q?wc2vur5rlSbAq6hImAVsSSXdRRJR224lfYPAFRTc5HV4cU5rL3Y6TW9UeywL?= =?us-ascii?Q?KUnLkTR3HVMJZC/gdWARIyempvFBpiaWj0RyzVRVxPWe8NLrhCm5Ji25thyA?= =?us-ascii?Q?U9G3CtWwJroyoyxuHLpMRU3O5FP2Tt8zpBx44YhPXCDoQxXgQaLyT5vz7SDk?= =?us-ascii?Q?/qdjA+GIYm6JP7nPTNBOl5WRzIVxImAENyFyg8xXkK8qEWZdFfwgdfWR1Mr2?= =?us-ascii?Q?Ak81OSAhCymWyeNup7mcKdFXVkeNR+HA5yMVehhska7Bqt+1i6fCJ+nTLVej?= =?us-ascii?Q?lz2iZLVV5KrTQIWg65+USrlkxGc0QzEENuiX/2JQpll0a32qslwp9SAR/ZKv?= =?us-ascii?Q?0PK0VZP/YmaLyoDL8os5Z3/jmqInRekEyfocfguO2O6i7w9L0FMOIeEedBmY?= =?us-ascii?Q?g2zZ0bktjWjQUTkRkFEO2fILdtC7g23f4S8s6Byvqw14OBvZk7L6/wNO0SjH?= =?us-ascii?Q?jtOfkmAzytB3zUtdzFdXP4yStvBWhGIvQXWEfTcqMqn+MIF3WeuYuT+expY6?= =?us-ascii?Q?+1JA6GLF/tzqDlKJdJdWFCPAyE+F5XefGYCYfgc4FbiLhj3XhQ5+4UVJO64e?= =?us-ascii?Q?dL2k5yxqW0WJqNj21ZJTleWpTk6cR5IKUaYXl6gVRIW35fR9Hes2w6hK79rQ?= =?us-ascii?Q?4/hO6hcnDer66fTVJHD9OQ4Z0RjNaDiUGskqaQegsp80+knmOeGrR6/wkzTp?= =?us-ascii?Q?V1qCW+PlT+rdRM5VuTeNqMv8r433XFTPKAIVWMFc99Aos0J93HHTEA+4tbVc?= =?us-ascii?Q?Tx/phW/td4MQ=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2062; 5:5slaevBj09DkzxI66nmzBtouDA3F0ZtILzOmmVH14om/W1oh7B2h059iNNdfDq5u13NbDDUN4LQOep7bXxLR0o0X6DQhkBuq4BV88qSOM2R79STvLqeU3VOD8qXC3XKGpQ5/jq8AtViggVIA4Guo3mldfqRPnx8wAcF94skRd4c=; 24:/KnaItcifOQA2IQmVa2gS7gakSfgWtSSwTRFXRGTw7d16mlqfqZ889dL0D/yXbD2mXbWuIAB1IGvm0cvOIaDvtCzHaG0nSbMnYdsaEsacTs= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2016 13:33:46.3879 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB2062 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Catalin Vasile --- crypto/tcrypt.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index f56419d..02a3856 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -1316,6 +1316,176 @@ static void band_acipher(const char *algo, int enc, unsigned int secs, band_acipher_destroy_session_ctx(&ses_ctx); } +static inline struct ahash_request +*band_ahash_alloc_req_digest(struct band_session_ctx *ses_ctx) +{ + struct ahash_request *req; + struct band_req_ctx *br; + void *buf_sg; + u8 *icv; + size_t req_size = sizeof(struct ahash_request) + + crypto_ahash_reqsize(ses_ctx->tfm); + size_t src_size = ses_ctx->job_size - + crypto_ahash_digestsize(ses_ctx->tfm); + size_t no_sg_entries = DIV_ROUND_UP(src_size, PAGE_SIZE); + int rv; + int i; + + rv = band_alloc_req(ses_ctx, (void **)&req, (void **)&buf_sg); + if (unlikely(rv)) + return NULL; + + br = ((void *)req) + req_size; + icv = buf_sg + src_size; + sg_init_table(br->sg, no_sg_entries); + if (src_size < PAGE_SIZE) + sg_set_buf(br->sg, buf_sg, src_size); + else + for (i = 0; i < no_sg_entries; i++) { + sg_set_buf(br->sg + i, buf_sg, PAGE_SIZE); + buf_sg += PAGE_SIZE; + } + ahash_request_set_tfm(req, ses_ctx->tfm); + ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, + band_complete, br); + ahash_request_set_crypt(req, br->sg, icv, src_size); + + init_completion(&br->completion); + br->session = ses_ctx; + + return req; +} + +static int band_ahash_jiffies_digest(struct band_session_ctx *ses_ctx, int secs) +{ + struct ahash_request *req; + unsigned long start, end; + unsigned long stop; + int elapsed_secs; + int bcount; + int no_jobs_done; + int ret; + unsigned long long band; + + for (start = jiffies, end = start + secs * HZ, bcount = 0; + time_before(jiffies, end); bcount++) { + req = band_ahash_alloc_req_digest(ses_ctx); + if (unlikely(req == NULL)) + break; + ret = do_one_band_op(&req->base, crypto_ahash_digest(req)); + if (unlikely(ret != -EINPROGRESS && ret)) + break; + } + + stop = jiffies; + no_jobs_done = atomic_read(&band_async_done); + elapsed_secs = (stop - start) / HZ; + + while (atomic_read(&band_async_done) < bcount) + cpu_relax(); + + band = ses_ctx->job_size - crypto_ahash_digestsize(ses_ctx->tfm); + band = no_jobs_done * band; + pr_cont("%d operations in %d seconds (%llu bytes processed)\n", + bcount, secs, band); + + return 0; +} + +static inline int +band_ahash_init_session_ctx(const char *algo, + struct band_session_ctx *ses_ctx) +{ + struct crypto_ahash *tfm; + struct kmem_cache *req_cache; + mempool_t *req_mpool; + size_t req_size; + int err; + + tfm = crypto_alloc_ahash(algo, 0, 0); + if (IS_ERR(tfm)) { + pr_err("failed to load transform for %s: %ld\n", + algo, PTR_ERR(tfm)); + return PTR_ERR(tfm); + } + + req_size = sizeof(struct ahash_request) + + crypto_ahash_reqsize(tfm) + + sizeof(struct band_req_ctx); + req_cache = kmem_cache_create("tcrypt-band-ahash-req", + req_size, 0, 0, NULL); + if (unlikely(!req_cache)) { + pr_err("failed to allocate request cache memory\n"); + err = -ENOMEM; + goto out; + } + + req_mpool = mempool_create(1024, mempool_alloc_slab, mempool_free_slab, + req_cache); + if (unlikely(!req_mpool)) { + pr_err("failed to allocate request memory pool\n"); + err = -ENOMEM; + goto out_free_cache; + } + + ses_ctx->req_mpool = req_mpool; + ses_ctx->tfm = tfm; + + return 0; + +out_free_cache: + kmem_cache_destroy(req_cache); +out: + crypto_free_ahash(tfm); + return err; +} + +static inline void +band_ahash_destroy_session_ctx(struct band_session_ctx *ses_ctx) +{ + struct kmem_cache *req_cache = ses_ctx->req_mpool->pool_data; + + mempool_destroy(ses_ctx->req_mpool); + kmem_cache_destroy(req_cache); + crypto_free_ahash(ses_ctx->tfm); +} + +static void band_ahash_digest(const char *algo, unsigned int secs) +{ + struct band_session_ctx ses_ctx; + u32 *b_size; + int i, ret; + + if (!secs) + return; + + ret = band_ahash_init_session_ctx(algo, &ses_ctx); + if (unlikely(ret)) + return; + + pr_info("\ntesting band of async %s (%s)\n", algo, + get_driver_name(crypto_ahash, ses_ctx.tfm)); + + b_size = aead_sizes; + i = 0; + do { + pr_info("test %u (%d byte blocks): ", i, *b_size); + + ses_ctx.job_size = *b_size + + crypto_ahash_digestsize(ses_ctx.tfm); + atomic_set(&band_async_done, 0); + ret = band_ahash_jiffies_digest(&ses_ctx, secs); + if (ret) { + pr_err("hashing failed ret=%d\n", ret); + break; + } + b_size++; + i++; + } while (*b_size); + + band_ahash_destroy_session_ctx(&ses_ctx); +} + static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret) { if (ret == -EINPROGRESS || ret == -EBUSY) { @@ -2691,6 +2861,26 @@ static int do_test(const char *alg, u32 type, u32 mask, int m) band_acipher("ctr(blowfish)", DECRYPT, sec, NULL, 0, speed_template_8_32); break; + case 700: + if (alg) { + band_ahash_digest(alg, sec); + break; + } + case 701: + band_ahash_digest("md5", sec); + break; + case 702: + band_ahash_digest("sha1", sec); + break; + case 703: + band_ahash_digest("sha256", sec); + break; + case 704: + band_ahash_digest("sha384", sec); + break; + case 705: + band_ahash_digest("sha512", sec); + break; case 1000: test_available(); break;