From patchwork Wed Oct 2 14:17:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175007 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp818421ill; Wed, 2 Oct 2019 07:18:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcy0+aBZI6guqrQJ6dGLj9dzvW3mQRty4rm0pRt+SrRSAhYyDs3a0rkwY12gCbJ7MDmss7 X-Received: by 2002:a50:99da:: with SMTP id n26mr4016775edb.293.1570025883019; Wed, 02 Oct 2019 07:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570025883; cv=none; d=google.com; s=arc-20160816; b=hNBS3M2h2i+KDC5I3q+7UbFtOGlEKbRFId1qO+FRMnSo4tbbBeYVal9yIz+bRgLQkd 64ZzomVGf9uJ319Calz2uhzskFxQ0AMkFcOdpF1KUfYvsRmVcHvrz0xbE3L4f6KfOlxe m+SVKNfd7zE0XhlX4adikK21ZBNDYBaLIOCuP4ejVOden5DrBMHOlxVNvf6Xs2O8/ZTs yRQQujedpzHhqpNPSVjNsj9shRL4teVjG5P3VRyPnD7MyyBObN9AUXeRRt5PNkL/zj0W h66jBpxSz1xmtuxHgYO7ZXWB9vIXsccY0HHFUdYWuSxa1ohySXp+fuallBAGTZd3zAYy Mzmw== 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=aG4eoMjkkcuaDa5uAXgPjSu7DoIJsA0jc8CLt+o/aME=; b=PT12eDXw6IQgm5oVPURvp4EBHyMHdZSuQsHlynvuzKL1LghypR0Bok7PxlMEz2X9F9 tjsh+ommFFZ2NlVtjmKPYfmlVAjDbif9CvopY1t3Al57Hetkb9LBr8yXx8HU+pb9OmHm GfI892mT2VR/BVPPtn2/W1pJUFmh82iu34fR2icZpgmHxmszbjThwdl0ddGpBZDfal5E Ko5FEW2/8d6w1fcbNop7s6fogiBGdcKHVGoBrsQyM8fb3BerW/gxSTfBZpUK6BytgjBV Pbxoz8jidsGrJqQ1Ptcso5sBdHZ4VOfqz85r/+OrxF2hIt0B2SDPX97WNUC6wHvNOFlS OBsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KmwOUiyn; 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.02; Wed, 02 Oct 2019 07:18:03 -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=KmwOUiyn; 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 S1727708AbfJBOR7 (ORCPT + 3 others); Wed, 2 Oct 2019 10:17:59 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46329 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727771AbfJBOR7 (ORCPT ); Wed, 2 Oct 2019 10:17:59 -0400 Received: by mail-wr1-f65.google.com with SMTP id o18so19837721wrv.13 for ; Wed, 02 Oct 2019 07:17:57 -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=aG4eoMjkkcuaDa5uAXgPjSu7DoIJsA0jc8CLt+o/aME=; b=KmwOUiynwj4F/XpS8h1dJDnUfpoPARmlFUS/869QtrxibLP+gpmvx9ocA6EWTjD+Qy wSdL8KlnCHt8i51EBXK67IU9ZUmS8//ZNQkE7YgfP/EDNpJgFAYKjkxcHYm0yfgz7026 RAuOhyxb1mV8xlRw0DVYMKYxi8Vxk9ue4mXD+kL4QlE4MOfeY8j9YRm5OPia64MfuDyi fMt1KBH4Ou/ehhPEJBnW0wvz9GdBS7B/bPzrvQO6QosamlAWoatFAZljg2rfkd/XOl6t eDtoBhdCNguAzDTys1RYpi8PRC+qOi7N1effHgROv4fvB9+cMA1qv3Bm8E0xbdXtemeS ITHQ== 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=aG4eoMjkkcuaDa5uAXgPjSu7DoIJsA0jc8CLt+o/aME=; b=TdOg39uGaJh4NOideaT/+JUodzba8Bpo5TCl7pf1/SqcyWQejWi/7fqIosd4DTm6qw C7XGw8TlIWAVuLVidLZTM6lYu8GKvC0nJMUyzAAoq3FQdaByYDnz2hhdu0aSYZpbSvUV v3S8qLDmZ5R68IxliHg1JDFRynQYhvBlkiAY8IKzttZ9gKDtAULl4gY2Mrg8e3BghVcv JJwlFB0BKFXQJ0xa1jzlEAtINxvTPHjQMKU3ulByyIu+SGEX3WiIOXhLd7NoCrDMPf9q WjozE7zHxouK36kA3BxKP+7dOmETt6uyaFJwi82bfF9nlUtZUCUVWso33foPgkRwatq1 md+A== X-Gm-Message-State: APjAAAWVURpHC6oB7ETsQaZ0QSZwn0DGF83p+o8nzQ3uql1IgmxNXZKg vvmrlV623A86tZawIE9RKEY6T7w0P+G+f1ym X-Received: by 2002:adf:e60d:: with SMTP id p13mr2751308wrm.298.1570025877046; Wed, 02 Oct 2019 07:17:57 -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.17.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 07:17:56 -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 , Masahiro Yamada Subject: [PATCH v2 11/20] int128: move __uint128_t compiler test to Kconfig Date: Wed, 2 Oct 2019 16:17:04 +0200 Message-Id: <20191002141713.31189-12-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 In order to use 128-bit integer arithmetic in C code, the architecture needs to have declared support for it by setting ARCH_SUPPORTS_INT128, and it requires a version of the toolchain that supports this at build time. This is why all existing tests for ARCH_SUPPORTS_INT128 also test whether __SIZEOF_INT128__ is defined, since this is only the case for compilers that can support 128-bit integers. Let's fold this additional test into the Kconfig declaration of ARCH_SUPPORTS_INT128 so that we can also use the symbol in Makefiles, e.g., to decide whether a certain object needs to be included in the first place. Cc: Masahiro Yamada Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 2 +- arch/riscv/Kconfig | 2 +- arch/x86/Kconfig | 2 +- crypto/ecc.c | 2 +- init/Kconfig | 4 ++++ lib/ubsan.c | 2 +- lib/ubsan.h | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 41a9b4257b72..a591a0673694 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -67,7 +67,7 @@ config ARM64 select ARCH_USE_QUEUED_SPINLOCKS select ARCH_SUPPORTS_MEMORY_FAILURE select ARCH_SUPPORTS_ATOMIC_RMW - select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG + select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 && (GCC_VERSION >= 50000 || CC_IS_CLANG) select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 8eebbc8860bb..75a6c9117622 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -164,7 +164,7 @@ config ARCH_RV32I config ARCH_RV64I bool "RV64I" select 64BIT - select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 + select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 && GCC_VERSION >= 50000 select HAVE_FUNCTION_TRACER select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FTRACE_MCOUNT_RECORD diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d6e1faa28c58..f4d9d1e55e5c 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -24,7 +24,7 @@ config X86_64 depends on 64BIT # Options that are inherently 64-bit kernel only: select ARCH_HAS_GIGANTIC_PAGE - select ARCH_SUPPORTS_INT128 + select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_USE_CMPXCHG_LOCKREF select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA diff --git a/crypto/ecc.c b/crypto/ecc.c index dfe114bc0c4a..6e6aab6c987c 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -336,7 +336,7 @@ static u64 vli_usub(u64 *result, const u64 *left, u64 right, static uint128_t mul_64_64(u64 left, u64 right) { uint128_t result; -#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) +#if defined(CONFIG_ARCH_SUPPORTS_INT128) unsigned __int128 m = (unsigned __int128)left * right; result.m_low = m; diff --git a/init/Kconfig b/init/Kconfig index b4daad2bac23..020526f681c0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -785,6 +785,10 @@ config ARCH_SUPPORTS_NUMA_BALANCING config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH bool +config CC_HAS_INT128 + def_bool y + depends on !$(cc-option,-D__SIZEOF_INT128__=0) + # # For architectures that know their GCC __int128 support is sound # diff --git a/lib/ubsan.c b/lib/ubsan.c index e7d31735950d..b652cc14dd60 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -119,7 +119,7 @@ static void val_to_string(char *str, size_t size, struct type_descriptor *type, { if (type_is_int(type)) { if (type_bit_width(type) == 128) { -#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) +#if defined(CONFIG_ARCH_SUPPORTS_INT128) u_max val = get_unsigned_val(type, value); scnprintf(str, size, "0x%08x%08x%08x%08x", diff --git a/lib/ubsan.h b/lib/ubsan.h index b8fa83864467..7b56c09473a9 100644 --- a/lib/ubsan.h +++ b/lib/ubsan.h @@ -78,7 +78,7 @@ struct invalid_value_data { struct type_descriptor *type; }; -#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) +#if defined(CONFIG_ARCH_SUPPORTS_INT128) typedef __int128 s_max; typedef unsigned __int128 u_max; #else