From patchwork Wed Oct 2 14:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175010 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp818550ill; Wed, 2 Oct 2019 07:18:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxM+qXgpBI5IWgMFT3jZ+ecS1h1ssvn0lxiXmw//HjQSzaVQUXE26u5h2Tlhihf6/GmpdVW X-Received: by 2002:a17:906:b74e:: with SMTP id fx14mr3303319ejb.226.1570025888223; Wed, 02 Oct 2019 07:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570025888; cv=none; d=google.com; s=arc-20160816; b=x3L0X8aPGMRcftVlqVBJF8OdBcbRFZDJew4a0Wz4SxVH8uC1HyFWU9AoLCSLHlFGTD u/H9kYiXk2H6lZLap/olZ6v8HNFPPVRMxF1r4bjh0bB0p9zVRwPSyxFj7SIUlGw+oVY6 ubYByzXZh8bqOmxCnmEy/YHlGXf51Tm/BkT4TPZaY2ZVn7zlAxjrQhshPi+65PpTjiPO fl/3DtK+P8Rji3QKx/wc2AONEjvRGKvyM2/bgWnSWS0lW+NcFs08GAa641Ajc68uua4s n/NCcUu5hhphH9JTLeIlwyXEaMB9guA8Osd6oOWdyyur8npPCtLzYoyFtZo0r8MyezmK 3MKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l8cC6Plr9Pjy6A3czOGNz4y4TekSjUV9NitiUk1ehQ0=; b=B9tz50i3gFWQT5ZTEu5SsWgtt2/eZQ32PLBoYkyRHDBsBh5u47GCaKkh/5b1nsY9/j 8yebl5f+b3Fndajp0d7idtgZKaeBs47ILPHUf4vZFU3rOLyy6uwtEajGriu8P3Q/A9Ln mMZ4sfY9KRuptyt7b0RY6J4Wxz7oq8yKxMineEG/7ItSGw7k/p5Maw73Ba5AXK3F9Uek YvGHfyn0EeygkauQAtnppgyFmpDlhjWwnr4W543/8Cs1puZ2pyh7FgCv86X/78TsylOa 4YkhDIZEralOSH2NPloi0ZsnYspwcZUvfIOD40Hj1z3/4J6nGR1zdoUhxWD7XhNtpxVf B7Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qsq0LJou; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 z10si11200503edx.168.2019.10.02.07.18.08; Wed, 02 Oct 2019 07:18:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=Qsq0LJou; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1728150AbfJBOSH (ORCPT + 3 others); Wed, 2 Oct 2019 10:18:07 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41548 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727771AbfJBOSG (ORCPT ); Wed, 2 Oct 2019 10:18:06 -0400 Received: by mail-wr1-f67.google.com with SMTP id q9so1092546wrm.8 for ; Wed, 02 Oct 2019 07:18:05 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=l8cC6Plr9Pjy6A3czOGNz4y4TekSjUV9NitiUk1ehQ0=; b=Qsq0LJoujxz7MIHt0LpKbFOEBfni0+2aEhAzk8LlJqOkSFQgW/avAyZ9ny5PBPeWdp 0ZK2UpVh1JTnWIwHBY38xyRAGfX7z7h4bZdB3G/CeJ0/KniC+//hf0IgfHBj94rPkMTf iwPT7Cx7d+c4EHrcCJm+uQP7vMbeAy9CFbFtb9h2GlLCvgZnJxa/kOIlDzCXyNZuzf7Y dnAX3gjoQ2t6Z83vQJVVKg7dAfK2otSQW+kkXktw2M19JJE71+ZlUdyYe6oX3gZKgHqZ L+6nMN9Ad8sUrdQqinOjwnG2A6jXWn/v7sU46K+2H7I54cd2w2kCSMukfrQW81GeaIuS IRQg== 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:mime-version:content-transfer-encoding; bh=l8cC6Plr9Pjy6A3czOGNz4y4TekSjUV9NitiUk1ehQ0=; b=MuGegs8n1LVp3jsIrPafDOiGJP/nMsLyJLMqXVkyTfZcD21FpEEkmfnoF9/NBVwrlC LE+pGgGdQbWQ/rnjekcHzAxDRxqklKKvUNJAPGw59HzFv9yjTvwlJd95Nw6z2WRRApvd sNeeJj9Pxgql7Y/4zbOmMBUiLEwGPlnSzueFud7uFqKRdahJ8OT1v7R7MIcI3q62SY74 F0FD4A7QCw045yuoXN905vQAuo/5Goh5le+xbWzwV5XQHxTRwdstiKpJ7fW2zkuCgTPX vd1SvwDnkjjpt9xgtRf9ypD2b3tWQMq5+4Jfvi3201QAjzvTGjVPRqgAv01ESA3PkQAB vCfQ== X-Gm-Message-State: APjAAAWKvXFTkZhAd0oF8mB4sJFZ0lbvQ9BEtp0mdzuVtVRhKWaG5OzS X3qBLTwk3Lf73GZ7p+I7u8iW41UxckBYz9i/ X-Received: by 2002:a5d:5052:: with SMTP id h18mr2824697wrt.397.1570025884285; Wed, 02 Oct 2019 07:18:04 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:f145:3252:fc29:76c9]) by smtp.gmail.com with ESMTPSA id t13sm41078149wra.70.2019.10.02.07.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 07:18:03 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , David Miller , Greg KH , Linus Torvalds , "Jason A . Donenfeld" , Samuel Neves , Dan Carpenter , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Will Deacon , Marc Zyngier , Catalin Marinas , Martin Willi , Peter Zijlstra , Josh Poimboeuf Subject: [PATCH v2 15/20] crypto: lib/curve25519 - work around Clang stack spilling issue Date: Wed, 2 Oct 2019 16:17:08 +0200 Message-Id: <20191002141713.31189-16-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191002141713.31189-1-ard.biesheuvel@linaro.org> References: <20191002141713.31189-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Arnd reports that the 32-bit generic library code for Curve25119 ends up using an excessive amount of stack space when built with Clang: lib/crypto/curve25519-fiat32.c:756:6: error: stack frame size of 1384 bytes in function 'curve25519_generic' [-Werror,-Wframe-larger-than=] Let's give some hints to the compiler regarding which routines should not be inlined, to prevent it from running out of registers and spilling to the stack. The resulting code performs identically under both GCC and Clang, and makes the warning go away. Suggested-by: Arnd Bergmann Signed-off-by: Ard Biesheuvel --- lib/crypto/curve25519-fiat32.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/lib/crypto/curve25519-fiat32.c b/lib/crypto/curve25519-fiat32.c index 1c455207341d..2fde0ec33dbd 100644 --- a/lib/crypto/curve25519-fiat32.c +++ b/lib/crypto/curve25519-fiat32.c @@ -223,7 +223,7 @@ static __always_inline void fe_1(fe *h) h->v[0] = 1; } -static void fe_add_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) +static noinline void fe_add_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) { { const u32 x20 = in1[9]; { const u32 x21 = in1[8]; @@ -266,7 +266,7 @@ static __always_inline void fe_add(fe_loose *h, const fe *f, const fe *g) fe_add_impl(h->v, f->v, g->v); } -static void fe_sub_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) +static noinline void fe_sub_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) { { const u32 x20 = in1[9]; { const u32 x21 = in1[8]; @@ -309,7 +309,7 @@ static __always_inline void fe_sub(fe_loose *h, const fe *f, const fe *g) fe_sub_impl(h->v, f->v, g->v); } -static void fe_mul_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) +static noinline void fe_mul_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) { { const u32 x20 = in1[9]; { const u32 x21 = in1[8]; @@ -441,7 +441,7 @@ fe_mul_tll(fe *h, const fe_loose *f, const fe_loose *g) fe_mul_impl(h->v, f->v, g->v); } -static void fe_sqr_impl(u32 out[10], const u32 in1[10]) +static noinline void fe_sqr_impl(u32 out[10], const u32 in1[10]) { { const u32 x17 = in1[9]; { const u32 x18 = in1[8]; @@ -619,7 +619,7 @@ static __always_inline void fe_invert(fe *out, const fe *z) * * Preconditions: b in {0,1} */ -static __always_inline void fe_cswap(fe *f, fe *g, unsigned int b) +static noinline void fe_cswap(fe *f, fe *g, unsigned int b) { unsigned i; b = 0 - b;