From patchwork Mon Oct 7 16:46:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175384 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4529664ill; Mon, 7 Oct 2019 09:46:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDJUs1rHOT1aoJ5S807t+/yfZQnSYy+DbC1et4BoHokS56FO3Y3kkYhyT6QLsh1kTzJAz6 X-Received: by 2002:a17:906:1801:: with SMTP id v1mr24601953eje.146.1570466815427; Mon, 07 Oct 2019 09:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570466815; cv=none; d=google.com; s=arc-20160816; b=dVJVNkfFJHKp7MzYi7esM17OB9o9X7CGUORfcdtCd0Wq7zL3Jc/4GEB6PRdFIUuoon XGKEX1a93n31T5MisreLMa0Ckt9zeNSr7TznQwxfaBSLTD9JkIBU+qQ/t9V54MgK8i1S 8HQ6hhcTQqGq6iwsaYNROP3yX31NcyERboS4065iDE3AjMIASF/VUVe/DycCbvpeZH+g mBNpMeDdGhiVf5YQwlrZBIOggTHC1RPceaXI5dlqFJ6W/G4jSIMoBIzaCxTdutIQbdGY FySr1lnSeD1/olAnhOFIJIuQoYKsXzf27s4AbuqqKiyv/DqMvCbhpwX2cIip/kDSL94R QxTw== 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=knZ7L5Ap+d4mGw5ThL8ChEcKWr/98SCZUyTSQBa5GGP7VvCdJCNeXeFudwpkYTqFUN euRMjD1cld46Cnf8gjfpuExG9NoXM7HqT5gUgqStd8CcM7PDo14gn1vXYz+ajjFv8PFM aeQxQKTZjgiMeM7EyJra0v+BjGlRTGgZch+XV1M/jKd/h1l9iqR59h6UgrZyr04pld8J vazHLu0kDXDa2R0cjTSOhdzE8vuX2AHagTd1XOw5Lxq+9nH9AhzQPnc3Oe2Y+jy5fJkx iq3qq1V3auVyVNY8nDdw2Hq0TnmlE7FEYZ8r2XZX8PWJv3G+6fTiz3DVPGZGkG30ywvj 3tYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tBHqbCz6; 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 f17si11357081edf.328.2019.10.07.09.46.55; Mon, 07 Oct 2019 09:46:55 -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=tBHqbCz6; 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 S1729131AbfJGQqy (ORCPT + 3 others); Mon, 7 Oct 2019 12:46:54 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34975 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbfJGQqy (ORCPT ); Mon, 7 Oct 2019 12:46:54 -0400 Received: by mail-wm1-f67.google.com with SMTP id y21so218440wmi.0 for ; Mon, 07 Oct 2019 09:46:53 -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=tBHqbCz6T6xWpbqBVtCbqQbMhWL7rQZ6MMBP459qOKUAqgoq3SCwd1eOUpDkp1fAUn BsdotWKYC546hRZa3+Ml5EhKP/8+pQETAT9ju3eDsPH/elr7+Vm3qilFCAJhRNMqG19x UkODQFyJY/4tf7kaWAQJ9Q2wGu6eQggE3bPkuY93Nqs1JoKbYx6+bidtteZ3NyKIHJdH 5wn1gWYNgNxHWw2sPgKJDe/GK5id0xzt9hcUzFgBLgW98p8/K3QWm+Rp8zfPk7Z7Bnze Cp0Caa5F8TC4eNRcnUsynEzMF6dsB1fW9rjGftgbPUniNQnbXuoSvOmZOTEzsA/7YhFu kirA== 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=m8YIzD82yaQMKN82BLQF1b/tL5VvpCfMuEsk1RTbvQJ0tPfLlPVteN+T8+o9F/sFB+ VW+Gzho5Awrnp+vqCD8R1BH8J9UmdoGllbcF23zQEB86qEgkxcpOEbXIWyhFDdgZv9L2 Upm2ZVgdpkrxEN5C1h60iLMlNBNrLIdiB/3zTVontDyr+43XQDL/LUaSanknHBQ9c8RH B5mbTvC5O4di9+XETOUVwEvYX/t9pXhcfJfjqM459qpwlLoOhBKlr0N/wwEYTNCj0q8Q Hkrkr0uyns+oBUsntybj+TMCsYErCX+HL1/x+nsQ2nt52PlHfHXJRfMYofWdbDiOlcLx AZuw== X-Gm-Message-State: APjAAAU8DQ+p4R5bnQsawUZ7V51amFfxTOUmycQKrGLoFGZ2gqZ0Dd/O TljJ3u8qu3yhQsNJe7Ux0MhtlHuhiEBA5Q== X-Received: by 2002:a1c:2d54:: with SMTP id t81mr131696wmt.167.1570466812451; Mon, 07 Oct 2019 09:46:52 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id b22sm68507wmj.36.2019.10.07.09.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 09:46:51 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , David Miller , "Jason A . Donenfeld" , Samuel Neves , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Martin Willi , Rene van Dorst Subject: [PATCH v3 24/29] crypto: lib/curve25519 - work around Clang stack spilling issue Date: Mon, 7 Oct 2019 18:46:05 +0200 Message-Id: <20191007164610.6881-25-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007164610.6881-1-ard.biesheuvel@linaro.org> References: <20191007164610.6881-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;