From patchwork Thu Oct 17 19:09:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 176719 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1360366ill; Thu, 17 Oct 2019 12:10:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2b8gvo6CZoa6e7Iui/m1U1++cesCeghM739iLAhMHqQoquVpHJh3K5tRTTqGmGuDXAL/2 X-Received: by 2002:a50:f384:: with SMTP id g4mr5420893edm.282.1571339447526; Thu, 17 Oct 2019 12:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571339447; cv=none; d=google.com; s=arc-20160816; b=lCK7//WsY6rbApnEB4WhDhgyGT5X+10B3cEj46jMweCJEKvThZ+amjNwvBRhJ6H7HV HwkGvq4I8fVr/UkKJ3AbJCg/MGIHj0QDnUQ5GmMuOCq510VwQ+h+0KPrzNiQVR7CrtXX GiWrefTftTc5H52IbKZJuDyGaHQWTbSRjlfqugs98YoXbMmhEvQWHq9mYiP0i7lLZwwN fLK6rLlJWtUYatEsAM7CG1FKv4UF3xql5PTBBi+zw4Y906xdUhe/zxzbDPBAdM/qf64T QjK6eh1yfLSxvEJzT0TkRKh3zrXuzcXtKdfF0NBWblDnf/oJWQyuaKETqL8JUxsNlI+6 paKw== 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=zT8/d8NDokMVyIuATf4Ld3OXZsDfhjGd4zuClnFXqH9yVlg1nU8Fl/SYa3OxcDdepk x8g9T1hCMNShWtA7se27IAxYsjJ8qbqMXxecLZwzEt7T7wPC2Nhf6y0g/wE0LC0lpZIT wH0hvshO8jf1t0Izjh63Mg4HDK++rd0EEtnlgYa6DzwnEWG+szunZIIKNspUakkso6EW 187g9IDo08WJaGAfvvfWNSX+dFlXSvq2PAEVISWGQzBfGsaGIXARGsJ867VvOsp96mh+ gDpGEACAiwG4eLWVwkona/jiryobGDgbdA/zbHTIz1afYVxvBRXA445GH9jDkNi2JdeP X/Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JTrpH5vM; 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 e31si2292605ede.199.2019.10.17.12.10.46; Thu, 17 Oct 2019 12:10:47 -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=JTrpH5vM; 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 S2503396AbfJQTKq (ORCPT + 3 others); Thu, 17 Oct 2019 15:10:46 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45928 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503404AbfJQTKp (ORCPT ); Thu, 17 Oct 2019 15:10:45 -0400 Received: by mail-wr1-f68.google.com with SMTP id r5so3568093wrm.12 for ; Thu, 17 Oct 2019 12:10:44 -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=JTrpH5vMG4pRHdwhPUcRaOLrAQJrXB21I1UgYWDWYCbLl1o+OLRQ27LBhLTTSN5pDL TuIOaPHu15kOTFszlcEZnGwqg7bGNJjgR44yLhOOzy6OkrPZb5WywEJMs2CHwKGifD+R LMzIzUjn1F5sPeAgKB0qTm+5GdQzX1+kbD59QKr20FVi3W/C9ri/SqLf6vN9AlDbo/eT bCP6oTTFGRgB6BtI47HrrksplqnHZPxVbqKLJXg0mKj2/KZCecWP80b1mebSlmRMhc0H 1bhuRCfDQ+4+e3aIfI5YYsTyascoMDkWJhK5uStZ1Lf14lMp+ltPMdfyykMbH/GzdDMk v1Gg== 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=EN1xGVLNGOFLFzTvtXPOwfOfXqsN/9NMQ3XQSHzpfuJZ7v0pYmrw4+9dtBdsFHzsIU mxKiZwTLmJ6JGaBLTm4Ti118VZqWGIL3/Eny4mTjj/nlIcuPPiTgpmJoO2MSARq0nz1o batDRYo0v3ZJSoTVMlyj9MtlLaUbG+FXaJP9iC60agwTIlWFGRr6Tc4oEtVZakFN3OTe QrYldI6mekI++9Ql5nNUMMYgDGevrjsW34rEJQcHgWDI35xL3qb38umLgeQPiIbwX78Y PQWniPoUSBLSWxsfhWrqGcYEPEe4n2nOIVxXJ/9Sc6rvMHg9kqcNCPYmUZi7jQhnd0K+ 2Y/Q== X-Gm-Message-State: APjAAAXYcwnbmDSjmqP2fjFE3tANEzvFbzOFEfweY3ElrVIy303Nt7Xw LGU9hCv6OAGJgyyPNLhxOZ/hb3H3pXFegXow X-Received: by 2002:adf:fcd2:: with SMTP id f18mr1569432wrs.388.1571339443532; Thu, 17 Oct 2019 12:10:43 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:ccb6:e9d4:c1bc:d107]) by smtp.gmail.com with ESMTPSA id y3sm5124528wro.36.2019.10.17.12.10.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Oct 2019 12:10:42 -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 , David Sterba Subject: [PATCH v4 30/35] crypto: lib/curve25519 - work around Clang stack spilling issue Date: Thu, 17 Oct 2019 21:09:27 +0200 Message-Id: <20191017190932.1947-31-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017190932.1947-1-ard.biesheuvel@linaro.org> References: <20191017190932.1947-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;