Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1906336lqb; Mon, 27 May 2024 01:05:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOmy2wR4C6R1Z26hR0JD4tPtEeiYYJEbknsVrc/abOvQj2NGHHFA3defYLLe3et8Fc+GpQMRXnU6JXeX24rytxOLEkUuf3jXAAIh+Njg== X-Google-Smtp-Source: AGHT+IGgJ1lU3zAALLIipK6O7lqwX9fA1HDzDuPi5MqrOMtayKzLPKOqRg66H3Aeyidy7cAwftnV X-Received: by 2002:a17:906:a0a:b0:a5a:4683:e961 with SMTP id a640c23a62f3a-a6264f0eeaemr554357266b.52.1716797151067; Mon, 27 May 2024 01:05:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716797151; cv=pass; d=google.com; s=arc-20160816; b=JDOm0jgQ27ydmWDtA7oKnr+U320gfJ97SiCI5usTYP2IcbnoHXbEGKFA1f2mz9DGka 3DijxgwzEP3oWTfA1cMXoYb4pIPPanV/cyeQYvb3cAyDycBRMk/ciUlbXODqjsEQGMXj x3fVtEnkLxR/uKBs8k4M7cOJ3KWhHD33UVrJZpabl9L44vJEGfnr80DwfVbs/AMGSPXo 1c+dKWZG8grqR3RQ7f2mJoIof9ss4UZwALuHXeeFdwlAeNfH7djclEke8vmivr09BFIp cy6Hsp+mTgTFV3JPh/8Nr31P5CPvCUQ+USV7VNBeN/JBUCTr3jbhUnPjxEuoTJb0NYyK cBmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=s6Ej7PH1U7c3MCFmCIJBzY8FeKEBUyLMB9/q6iKOYWQ=; fh=uKl1CTlin8qnxt56ErGp3UOINPCBskOXHDuKvJLDQbo=; b=MOsfy2IW7XHb+7PuBkVsDr9QHUNo3yk+hBLQGnF9S3JfHGdYBrvcQJyDsaQWZRdi7i Hy6/BnlHnSlu3mH2qfPYuuvsXRtypqEXvGZuL6JgK9Ecv5BGWAbbUTOoqFvUFJF/zPvk 0Bx3ywlXUxFgPz2uBjTHLyer69cf4yzOij/4EzH3uR6k/pKs6kT8X6Cc6iIUctjlC3R1 u910ao39pz4wUsUXTmSuKPqkd2kJYfrfSXEjk1KQmDy0fWwwcJyp+Z+IyVE4170hJELb uo1lxKhcnNu4kImHk2cS0ElSRbvoLEaLyNsREkdQ33Og8PuzWv30wB0MrUvHydmzhR1b Mm0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vMwUCNrZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a62d36e20besi165273066b.522.2024.05.27.01.05.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 01:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vMwUCNrZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B2D0E1F21B84 for ; Mon, 27 May 2024 08:05:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C3083A1B6; Mon, 27 May 2024 08:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vMwUCNrZ" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D288D381A4 for ; Mon, 27 May 2024 08:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716797145; cv=none; b=PpLRDA3gG4XtRgyZmlB7P9tButW1ObQiQhhIjFfQcflVedBByo6zDezjSs7VL666ar/h5x+UqgXpcBvLOCmGseL02Wx7vJ50yfR2IS6tLb8HSWbdEwj2q/1nFueB0DSXrbM69PIe3RCpDzkKh/fQQ9Ig/ly3jYy8W2QShnf4XA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716797145; c=relaxed/simple; bh=3DDBsxPmMiaT2ZVtbL2hPOPFaxiQLUWIfAZuVjSxrdM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=o1VD+YTsFaWzJin4SR/nVM8Mh4HIOX/cAW4ag228zt6qrO5n18BjZ1wUVE03zr/QQaiCeDgfx6JdI1ayrP/ZSvl98VTN4Ba4b8hcV2EVKZv0ZQVYBlGI1/1ZuknHmgmT0mSNH8XXmb8KtJZusrM7rzqfYqOO17BZp4GfPMQoc7A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vMwUCNrZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52973C2BBFC for ; Mon, 27 May 2024 08:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716797145; bh=3DDBsxPmMiaT2ZVtbL2hPOPFaxiQLUWIfAZuVjSxrdM=; h=From:To:Subject:Date:From; b=vMwUCNrZXSB0lbhSj3wleoZYvVsrbWe7wPcZ2Whvu+HX8I/sutwnTE0xwolqC/fDk 8ytj75ArzjSYnMhq1Bsg8GIJaMSysyT0jocZlnuqRKChxtZpFv/yBfgvjZqDSOjgX2 O3x8/Jv/9DYyva7NJTaHNJd+qbO0aAplvItItz2+pW8eTpdSQec8hbSxkRypSrJzun HAYdXu1Ps1s4M5YXvDtCbFa+7AIubiPW9JlXP5dytY8fpMQaNoCoqx3sOjlMaw6COd Cu56GSwJZmT47iaEWbnJLj3+IZ6FCPU2nEIyN7cdtePf/zWPGR38w4lVWXeIFQ/nMa hfUxPhRe1RAyw== From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH] crypto: testmgr - test setkey in no-SIMD context Date: Mon, 27 May 2024 01:05:39 -0700 Message-ID: <20240527080539.163052-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Biggers Since crypto_shash_setkey(), crypto_ahash_setkey(), crypto_skcipher_setkey(), and crypto_aead_setkey() apparently need to work in no-SIMD context on some architectures, make the self-tests cover this scenario. Specifically, sometimes do the setkey while under crypto_disable_simd_for_test(), and do this independently from disabling SIMD for the other parts of the crypto operation since there is no guarantee that all parts happen in the same context. (I.e., drivers mustn't store the key in different formats for SIMD vs. no-SIMD.) Signed-off-by: Eric Biggers --- crypto/testmgr.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 00f5a6cf341a5..1b30e3565e805 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -291,10 +291,14 @@ struct test_sg_division { * @key_offset: misalignment of the key, where 0 is default alignment * @key_offset_relative_to_alignmask: if true, add the algorithm's alignmask to * the @key_offset * @finalization_type: what finalization function to use for hashes * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP. + * This applies to the parts of the operation that aren't controlled + * individually by @nosimd_setkey or @src_divs[].nosimd. + * @nosimd_setkey: set the key (if applicable) with SIMD disabled? Requires + * !CRYPTO_TFM_REQ_MAY_SLEEP. */ struct testvec_config { const char *name; enum inplace_mode inplace_mode; u32 req_flags; @@ -304,10 +308,11 @@ struct testvec_config { unsigned int key_offset; bool iv_offset_relative_to_alignmask; bool key_offset_relative_to_alignmask; enum finalization_type finalization_type; bool nosimd; + bool nosimd_setkey; }; #define TESTVEC_CONFIG_NAMELEN 192 /* @@ -531,11 +536,12 @@ static bool valid_testvec_config(const struct testvec_config *cfg) if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) && cfg->finalization_type == FINALIZATION_TYPE_DIGEST) return false; - if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) && + if ((cfg->nosimd || cfg->nosimd_setkey || + (flags & SGDIVS_HAVE_NOSIMD)) && (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP)) return false; return true; } @@ -839,20 +845,27 @@ static int prepare_keybuf(const u8 *key, unsigned int ksize, *keybuf_ret = keybuf; *keyptr_ret = keyptr; return 0; } -/* Like setkey_f(tfm, key, ksize), but sometimes misalign the key */ +/* + * Like setkey_f(tfm, key, ksize), but sometimes misalign the key. + * In addition, run the setkey function in no-SIMD context if requested. + */ #define do_setkey(setkey_f, tfm, key, ksize, cfg, alignmask) \ ({ \ const u8 *keybuf, *keyptr; \ int err; \ \ err = prepare_keybuf((key), (ksize), (cfg), (alignmask), \ &keybuf, &keyptr); \ if (err == 0) { \ + if ((cfg)->nosimd_setkey) \ + crypto_disable_simd_for_test(); \ err = setkey_f((tfm), keyptr, (ksize)); \ + if ((cfg)->nosimd_setkey) \ + crypto_reenable_simd_for_test(); \ kfree(keybuf); \ } \ err; \ }) @@ -1116,13 +1129,19 @@ static void generate_random_testvec_config(struct rnd_state *rng, cfg->finalization_type = FINALIZATION_TYPE_DIGEST; p += scnprintf(p, end - p, " use_digest"); break; } - if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) && prandom_bool(rng)) { - cfg->nosimd = true; - p += scnprintf(p, end - p, " nosimd"); + if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP)) { + if (prandom_bool(rng)) { + cfg->nosimd = true; + p += scnprintf(p, end - p, " nosimd"); + } + if (prandom_bool(rng)) { + cfg->nosimd_setkey = true; + p += scnprintf(p, end - p, " nosimd_setkey"); + } } p += scnprintf(p, end - p, " src_divs=["); p = generate_random_sgl_divisions(rng, cfg->src_divs, ARRAY_SIZE(cfg->src_divs), p, end, base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0 -- 2.45.1