From patchwork Fri Dec 1 21:19:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 120387 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1655518qgn; Fri, 1 Dec 2017 13:26:12 -0800 (PST) X-Google-Smtp-Source: AGs4zMbvzG2YKAG+i8T2v9c813EisEV3mS9AUr6iOpNwPnUo79OrHKildlxoH8UzWV7kA6M8j6ri X-Received: by 10.99.153.2 with SMTP id d2mr7046397pge.379.1512163572399; Fri, 01 Dec 2017 13:26:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512163572; cv=none; d=google.com; s=arc-20160816; b=QzpCCdrcDVMSEbz7h6FDhJt+3cWiWhQKJ2RDR8zwsN99iaRZtBigeY7NxcP3Cka2OZ aMuj6C9modZ8MVZ59UVTp8YThHuYabcu7cOgxXzsA2W1+X6qmDk5lyL95aazjYcmlUWl QJB4jqRgKK6k0a4Yth7tGaCwovicsbpXbIZX2ZASrquL2Ht83LrTQVkeiXZa1uXCqMwo mZpWPrGfjn1CFcv/UHdFQlPUQgkOZMTQs9lzoTzaH8s3hFEOALwBU0AGGGnRakeICT1W f0TmlsjFEdDcCpryeh0weg1pO0LegkHbgb9Qx00kctwyj9fmpvSNWVHQwNoiw9bpHSWy /9TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1rNy77/PAImno98ljWJe2khTgitKwOlSs6IM90SBxa4=; b=sXsNSYg+ygYLuoT32Okt3/E4m/PQt492TEw122xs5ZCgNnAl96rMwIIxdg10iAN4PW yRMB2Qdfsi3ZtEO48WfjxOnhgbrRwkeeMD02w44f7jKBXzCxaMV1LUhlaGAIkQRr8nSY ZXieDdbu2zCP+AA1JTiFz9AvOnpNaiVFT3usvZRspX6TZizInKHexpEf8RQp7L+iok1O WfGBCcqjtVQAjxvcRyt81K0BY6fLcLREbEOV6kLedtn0UPCk1Z6ebUZudzUboYjbO2Wk njSO7UD6R6jXqa7E7Kwz5W2pbltJDeBaIRSDdJEKHOw9ScFRmqnOCNeQGaTER16cOJ5T HlyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PHkA5CT5; spf=pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-rt-users-owner@vger.kernel.org; dmarc=fail (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 u66si5760540pfa.237.2017.12.01.13.26.12; Fri, 01 Dec 2017 13:26:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PHkA5CT5; spf=pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-rt-users-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbdLAV0L (ORCPT + 4 others); Fri, 1 Dec 2017 16:26:11 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39527 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbdLAV0K (ORCPT ); Fri, 1 Dec 2017 16:26:10 -0500 Received: by mail-wr0-f194.google.com with SMTP id a41so9577896wra.6 for ; Fri, 01 Dec 2017 13:26:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4IWFfyA8qbht0pbAaWWcgZ+mreBLvmqM3d70R4Q8pxQ=; b=PHkA5CT5J4SlaoFfIRk8BTLr98g5VgavB/WQ725JS5coJ2YMunZmkw5cP5wo67AeUq zxLhyrGCYSDu1PHmbwvvNghJQ4uN4hzywxC0Ez2smK87vmQlHqN6QNfCRQp+gLqeXRV3 5ZqEMGlwyIw7kShZHVI7BNIBrxn7rAa9sP6oQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4IWFfyA8qbht0pbAaWWcgZ+mreBLvmqM3d70R4Q8pxQ=; b=kUumydZcBmpn28HI8C6Az4b/Fk2XUyOYsEQQ4/KUmNJbXRnT8ZqqjdnOTJcBDQ/3eE Eruz89/GmU6NyZAHtpLvLzRQdtllcDL3qKvdYMscVIyvlBrcy+qe0k3Km5PYeHranIMp KXFWK0O9kSFqrEW7rOQ2GpJVNSf258bz3Xe6y1LQmm6gPtBVYCWt1OZSKspqsV6V7YyB rrY3meM+3DgiZkcsqDMmycsqC5Fam1XEQQMVf2i16TpD8FYPT2vUnedNPfIyF37GHuDm RP7/3dmbuMRjRPOtITmo1TKM7gqFOyiwlzW5oLWEeE5TMHRtvxl5TERouubnhyNdgY2o l+6w== X-Gm-Message-State: AJaThX7ZZapyskcsVfflqyv5lPhLdUDglgG/E1JLK82OuCdYVceoC79Z HakVGk37AqVtq/HUMpYgAlw3qg== X-Received: by 10.223.142.49 with SMTP id n46mr6279292wrb.279.1512163569448; Fri, 01 Dec 2017 13:26:09 -0800 (PST) Received: from localhost.localdomain ([105.150.171.234]) by smtp.gmail.com with ESMTPSA id p17sm2161682wma.23.2017.12.01.13.26.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2017 13:26:08 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Dave Martin , Russell King - ARM Linux , Sebastian Andrzej Siewior , Mark Rutland , linux-rt-users@vger.kernel.org, Peter Zijlstra , Catalin Marinas , Will Deacon , Steven Rostedt , Thomas Gleixner Subject: [PATCH 4/5] crypto: arm64/chacha20 - move kernel mode neon en/disable into loop Date: Fri, 1 Dec 2017 21:19:26 +0000 Message-Id: <20171201211927.24653-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171201211927.24653-1-ard.biesheuvel@linaro.org> References: <20171201211927.24653-1-ard.biesheuvel@linaro.org> Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org When kernel mode NEON was first introduced on arm64, the preserve and restore of the userland NEON state was completely unoptimized, and involved saving all registers on each call to kernel_neon_begin(), and restoring them on each call to kernel_neon_end(). For this reason, the NEON crypto code that was introduced at the time keeps the NEON enabled throughout the execution of the crypto API methods, which may include calls back into the crypto API that could result in memory allocation or other actions that we should avoid when running with preemption disabled. Since then, we have optimized the kernel mode NEON handling, which now restores lazily (upon return to userland), and so the preserve action is only costly the first time it is called after entering the kernel. So let's put the kernel_neon_begin() and kernel_neon_end() calls around the actual invocations of the NEON crypto code, and run the remainder of the code with kernel mode NEON disabled (and preemption enabled) Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/chacha20-neon-glue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm64/crypto/chacha20-neon-glue.c b/arch/arm64/crypto/chacha20-neon-glue.c index cbdb75d15cd0..b9ca7bef428a 100644 --- a/arch/arm64/crypto/chacha20-neon-glue.c +++ b/arch/arm64/crypto/chacha20-neon-glue.c @@ -36,6 +36,7 @@ static void chacha20_doneon(u32 *state, u8 *dst, const u8 *src, { u8 buf[CHACHA20_BLOCK_SIZE]; + kernel_neon_begin(); while (bytes >= CHACHA20_BLOCK_SIZE * 4) { chacha20_4block_xor_neon(state, dst, src); bytes -= CHACHA20_BLOCK_SIZE * 4; @@ -55,6 +56,7 @@ static void chacha20_doneon(u32 *state, u8 *dst, const u8 *src, chacha20_block_xor_neon(state, buf, buf); memcpy(dst, buf, bytes); } + kernel_neon_end(); } static int chacha20_neon(struct skcipher_request *req) @@ -72,7 +74,6 @@ static int chacha20_neon(struct skcipher_request *req) crypto_chacha20_init(state, ctx, walk.iv); - kernel_neon_begin(); while (walk.nbytes > 0) { unsigned int nbytes = walk.nbytes; @@ -83,7 +84,6 @@ static int chacha20_neon(struct skcipher_request *req) nbytes); err = skcipher_walk_done(&walk, walk.nbytes - nbytes); } - kernel_neon_end(); return err; }