From patchwork Mon Nov 28 04:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1709524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=npDM7XRV; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLByx0L1mz23nB for ; Mon, 28 Nov 2022 15:18:00 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NLByw59qqz3f37 for ; Mon, 28 Nov 2022 15:18:00 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=npDM7XRV; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=npDM7XRV; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NLBwb2Xhbz3cL1 for ; Mon, 28 Nov 2022 15:15:59 +1100 (AEDT) Received: by mail-pj1-x1033.google.com with SMTP id 3-20020a17090a098300b00219041dcbe9so7892818pjo.3 for ; Sun, 27 Nov 2022 20:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a7R9heIoAg42vgnWEBRYpJlNY18RAwQzKTaUAUkLcfg=; b=npDM7XRVYF8htHZG1hHMVYU6dbZokUzEHgDICho41UI7ruvizp8f5hWtlEupd95SMt XuXumM5OHkF/8ShVGEfDbhjS0s1r/BmJVwILKP13k0WCcez+pD8nmKZvm+3o+jZ6TVSV GIjsVf6tTEcw/P1yVt4f0j7PYRulu0a/6JJYPv0JiNH5hlFCZ9bjeNVHo7H1WY5AmjlC DfsA8MoCuk6kWG1ONRlC1ibTsRyQ9v97I3izrQhwytvGsMBG5f709C5FaaRa84HMRKMH ku2pe6sQ+Shf+3FYS9ktwK5hOioqrtvoyeCxf4F/R8cszxtqbti+0swV17RIXEPtbmfm wdMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a7R9heIoAg42vgnWEBRYpJlNY18RAwQzKTaUAUkLcfg=; b=piy9cBVYer+7qsYoOjv/CiqLtCOil4l26pdzuJza7J2exOfTFDFbv33MH2SgSKUpyV CqDyrlDNx5d2UORlt7QdAPFH97O7lh97ZKcu43fY24xZ7UguPXmlKBIoFIwR/y47bK2G diABX/Ij2mvrRnYLzsieNrXDNnQIFeHiZYRrl/7tcPTgdO4ECtJUMsu7Hql7MNT1LouP 4lbcW8idJiDlnRo9rv7P+OUBDhH/kLkZTH81B3NeN/7njCrlEHY3J2OBEfKB0Sg/Gspr B8RnZWohaLgkldOCXz6A1FmdaVDXBdLwU7ly+1P62EP0G+UOI2v4m81K8K2YDDexrBU/ 5B6Q== X-Gm-Message-State: ANoB5pkyGn0f2NGtetiK81JK/IYEch3kwNMBjFelMRH+eRUuJuTdIc6k 6zogGMUr0XiLQmGcuDb5ZB4eG2tvJS4= X-Google-Smtp-Source: AA0mqf5ld6vlEQt9yisUzJ+hVwunoUL0MM0ltj7rnkorwWz9iBCJwQtFUyRTib6MgmwFZT3d6NTDoQ== X-Received: by 2002:a17:902:e80f:b0:186:f4ba:a817 with SMTP id u15-20020a170902e80f00b00186f4baa817mr35546670plg.97.1669608951177; Sun, 27 Nov 2022 20:15:51 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.231.60]) by smtp.gmail.com with ESMTPSA id y28-20020aa79afc000000b0057489a78979sm6905670pfp.21.2022.11.27.20.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 20:15:50 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v6 1/4] module: add module_elf_check_arch for module-specific checks Date: Mon, 28 Nov 2022 14:15:36 +1000 Message-Id: <20221128041539.1742489-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221128041539.1742489-1-npiggin@gmail.com> References: <20221128041539.1742489-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luis Chamberlain , Nicholas Piggin , Jessica Yu , =?utf-8?q?Michal_Such=C3=A1nek?= Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The elf_check_arch() function is also used to test compatibility of usermode binaries. Kernel modules may have more specific requirements, for example powerpc would like to test for ABI version compatibility. Add a weak module_elf_check_arch() that defaults to true, and call it from elf_validity_check(). Cc: Michael Ellerman Signed-off-by: Jessica Yu [np: added changelog, adjust name, rebase] Acked-by: Luis Chamberlain Signed-off-by: Nicholas Piggin --- include/linux/moduleloader.h | 3 +++ kernel/module/main.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 9e09d11ffe5b..7b4587a19189 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -13,6 +13,9 @@ * must be implemented by each architecture. */ +/* arch may override to do additional checking of ELF header architecture */ +bool module_elf_check_arch(Elf_Ehdr *hdr); + /* Adjust arch-specific sections. Return 0 on success. */ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, diff --git a/kernel/module/main.c b/kernel/module/main.c index d02d39c7174e..7b3f6fb0d428 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1674,6 +1674,11 @@ static int elf_validity_check(struct load_info *info) info->hdr->e_machine); goto no_exec; } + if (!module_elf_check_arch(info->hdr)) { + pr_err("Invalid module architecture in ELF header: %u\n", + info->hdr->e_machine); + goto no_exec; + } if (info->hdr->e_shentsize != sizeof(Elf_Shdr)) { pr_err("Invalid ELF section header size\n"); goto no_exec; @@ -2247,6 +2252,11 @@ static void flush_module_icache(const struct module *mod) (unsigned long)mod->core_layout.base + mod->core_layout.size); } +bool __weak module_elf_check_arch(Elf_Ehdr *hdr) +{ + return true; +} + int __weak module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, char *secstrings, From patchwork Mon Nov 28 04:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1709523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=l/iLDT8f; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLBxn26wLz23nB for ; Mon, 28 Nov 2022 15:17:01 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NLBxn1Rpsz3cKG for ; Mon, 28 Nov 2022 15:17:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=l/iLDT8f; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1034; helo=mail-pj1-x1034.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=l/iLDT8f; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NLBwY4Vmzz3cC5 for ; Mon, 28 Nov 2022 15:15:57 +1100 (AEDT) Received: by mail-pj1-x1034.google.com with SMTP id t11-20020a17090a024b00b0021932afece4so1835950pje.5 for ; Sun, 27 Nov 2022 20:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vWgWrGLeB+xoOH8mvK1ujoMXEg/wPFZ3hsl6zxq8pJw=; b=l/iLDT8fdITMMgPTM1OEBl2VpkbMGHTdHD68WEayeoPTUc9kMCCdaPwDayAsHoWy8P KLAmiOe2+7hxSqpRgiqO0qBXrzBIdRXOKV3lMATbgCjJWMj00R7QgfgeAcMjUcn4Ng0+ FHyD/G2JHnEz76WGN3AWg6pdTwBXepFUAGDE25DoZ5Qf5g5tNOUGqDeDW5LOUhHcn2aM EKrd1YyUgI6AlFpklti+e7p3o7HYoK7YKOzq+5aIPmSo3IrqJYwcubYOteI4Yi68J8D4 rMLppqGqewLXNHTDklSYb3Q+HB9goDMCmYR7qll5YiOYXsmDpd4RofId9QKCcqdEQqvM B00g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vWgWrGLeB+xoOH8mvK1ujoMXEg/wPFZ3hsl6zxq8pJw=; b=nw8tPLtm+UMuOD6o4+OZsU2SbfF7OLDF5kNURZc+poQpOVMgFOhLzhHOjj3JOFZpTP iewQCFE/s/h+kMW0hJtk+07mJp1Uz4zUWX+xgc7CYUKApPNE94H6rQt7/+mp0upAi7+r AfFponR6KhqeJjnw540b3EsRfKY0tFWRDqvKdH5iB9Doo94+8e0qVPlVeL+HJD354nI7 iQqwy2Wm7gL2Nna3+N/967wYdjWvqAvzKSwE5SYRUq8IYIOENMNdUjoPfE1POtfYoc4+ OJg4khwaSZA7QY/q7gANn7gtXChbnWRkhEmGtdsrR6o4G7+KCcPpC8L4FGWnWGx5NVck ktfA== X-Gm-Message-State: ANoB5plQAi3eD4LGGki0AbIubgZNQBUrCDCa8c4+P1FRNwOACYkINYkC K0rTwAJEZQptohwQeJFSWRxG0iOOORY= X-Google-Smtp-Source: AA0mqf5j+1Lr/RaqQvmrrufa8o64AA1/RlnUbPLuebbHNCs23UhLdo97GkvIz6MX/F5zcroxHdio5g== X-Received: by 2002:a17:902:ccce:b0:185:4880:91cd with SMTP id z14-20020a170902ccce00b00185488091cdmr30167065ple.130.1669608955319; Sun, 27 Nov 2022 20:15:55 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.231.60]) by smtp.gmail.com with ESMTPSA id y28-20020aa79afc000000b0057489a78979sm6905670pfp.21.2022.11.27.20.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 20:15:54 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v6 2/4] powerpc/64: Add module check for ELF ABI version Date: Mon, 28 Nov 2022 14:15:37 +1000 Message-Id: <20221128041539.1742489-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221128041539.1742489-1-npiggin@gmail.com> References: <20221128041539.1742489-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luis Chamberlain , Nicholas Piggin , Jessica Yu , =?utf-8?q?Michal_Such=C3=A1nek?= Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Override the generic module ELF check to provide a check for the ELF ABI version. This becomes important if we allow big-endian ELF ABI V2 builds but it doesn't hurt to check now. Cc: Jessica Yu Signed-off-by: Michael Ellerman [np: split patch, added changelog, adjust to Jessica's proposal] Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/module_64.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 7e45dc98df8a..ff045644f13f 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -31,6 +31,16 @@ this, and makes other things simpler. Anton? --RR. */ +bool module_elf_check_arch(Elf_Ehdr *hdr) +{ + unsigned long abi_level = hdr->e_flags & 0x3; + + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) + return abi_level == 2; + else + return abi_level < 2; +} + #ifdef CONFIG_PPC64_ELF_ABI_V2 static func_desc_t func_desc(unsigned long addr) From patchwork Mon Nov 28 04:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1709525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=YuK7cDIw; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLBzx0B5mz23nB for ; Mon, 28 Nov 2022 15:18:53 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NLBzw5k2cz3f4v for ; Mon, 28 Nov 2022 15:18:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=YuK7cDIw; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::535; helo=mail-pg1-x535.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=YuK7cDIw; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NLBwf27Dqz3cMf for ; Mon, 28 Nov 2022 15:16:01 +1100 (AEDT) Received: by mail-pg1-x535.google.com with SMTP id 136so8895309pga.1 for ; Sun, 27 Nov 2022 20:16:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1UNoFZjpqfGudip0kcMOvEq1qB17vDLLLPW/9fqGP8Y=; b=YuK7cDIwgwKHS54DS4Csqsf2PgHKcd+EzUrKIzTIOyFfwZQrvdE0uDkn+9KhMAoj3S a0ERrSjVjDlTlZ31bJYHoPevbIuM1TDx4wiuRnjz4cIPPnzGoShwCycQi47hbEFJm/XC 1AH472k1D1nLuVeKdk0GVy4CCFLYjxViV8NabpFQYRhwVQjwvWtUEMSrlpBVA8aZnKpl tEy079TDOK29ao83qCBagqZeyK/WsbqF7qksG6ziI5IHnTnglfimdQcqykS6GjVaqhVs X4rSgEcvq51PhI3uwSzqrnTRS2km8j3PnskPWovDZecg1aHz25RpSw/BsYCJXXmOchQZ 2sZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1UNoFZjpqfGudip0kcMOvEq1qB17vDLLLPW/9fqGP8Y=; b=w/6lDDpbu83mvxvZ1KCM4YQWQKB/6YPxMYQs9GUVUGYFn0NIKTFBhJhAmLGWo50CpT gwJA1bnSeF6CUM3eMLh4LDs46q/zWhJrztNifhG3Bhot7MYZUi4CQ0zm5M8G2DKHVuVC Ast866d72BoUFSzGPE+eqKNcKIj5IWwxkivBuVfjUdMf6j8SHEQ5fI14klFeQtENFQbw Ml0EUN6BMpsW/5xHlrFx1wuW/90KwuQX02I3/EZdTBe+KTV460SUNhnNpW6oiU2G2Jt+ tc3kz7zG/HmVC2sQAK/kJLNDHCc/NhNdnI5joyVQNeCAz79pxRoyg3vhLb6sI8Zpz7GN wORg== X-Gm-Message-State: ANoB5plc25Ue8Z2+tg0+RSchSv5mTr6yN6v5pn9HQm8qmyn3U2Eb33Wb Pd4Yrdt55EGYla68rMbLP0aNxiBIZSc= X-Google-Smtp-Source: AA0mqf4LO1D2cXSejQO9SQP9ABk2k9Efb00/Uwli0Zfe3d2tGwmou2ft5Rky9inB6JOJtKR9talZDA== X-Received: by 2002:a63:b01:0:b0:477:d8c5:3ac2 with SMTP id 1-20020a630b01000000b00477d8c53ac2mr14694421pgl.339.1669608959518; Sun, 27 Nov 2022 20:15:59 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.231.60]) by smtp.gmail.com with ESMTPSA id y28-20020aa79afc000000b0057489a78979sm6905670pfp.21.2022.11.27.20.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 20:15:59 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v6 3/4] powerpc/64: Add big-endian ELFv2 flavour to crypto VMX asm generation Date: Mon, 28 Nov 2022 14:15:38 +1000 Message-Id: <20221128041539.1742489-4-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221128041539.1742489-1-npiggin@gmail.com> References: <20221128041539.1742489-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luis Chamberlain , =?utf-8?q?Michal_Such=C3=A1nek?= , Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This allows asm generation for big-endian ELFv2 builds. Signed-off-by: Nicholas Piggin --- drivers/crypto/vmx/Makefile | 12 +++++++++++- drivers/crypto/vmx/ppc-xlate.pl | 10 ++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/vmx/Makefile b/drivers/crypto/vmx/Makefile index 2560cfea1dec..e33c7238e7f8 100644 --- a/drivers/crypto/vmx/Makefile +++ b/drivers/crypto/vmx/Makefile @@ -2,8 +2,18 @@ obj-$(CONFIG_CRYPTO_DEV_VMX_ENCRYPT) += vmx-crypto.o vmx-crypto-objs := vmx.o aesp8-ppc.o ghashp8-ppc.o aes.o aes_cbc.o aes_ctr.o aes_xts.o ghash.o +ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) +override flavour := linux-ppc64le +else +ifdef CONFIG_PPC64_ELF_ABI_V2 +override flavour := linux-ppc64-elfv2 +else +override flavour := linux-ppc64 +endif +endif + quiet_cmd_perl = PERL $@ - cmd_perl = $(PERL) $< $(if $(CONFIG_CPU_LITTLE_ENDIAN), linux-ppc64le, linux-ppc64) > $@ + cmd_perl = $(PERL) $< $(flavour) > $@ targets += aesp8-ppc.S ghashp8-ppc.S diff --git a/drivers/crypto/vmx/ppc-xlate.pl b/drivers/crypto/vmx/ppc-xlate.pl index 36db2ef09e5b..b583898c11ae 100644 --- a/drivers/crypto/vmx/ppc-xlate.pl +++ b/drivers/crypto/vmx/ppc-xlate.pl @@ -9,6 +9,8 @@ open STDOUT,">$output" || die "can't open $output: $!"; my %GLOBALS; my $dotinlocallabels=($flavour=~/linux/)?1:0; +my $elfv2abi=(($flavour =~ /linux-ppc64le/) or ($flavour =~ /linux-ppc64-elfv2/))?1:0; +my $dotfunctions=($elfv2abi=~1)?0:1; ################################################################ # directives which need special treatment on different platforms @@ -40,7 +42,7 @@ my $globl = sub { }; my $text = sub { my $ret = ($flavour =~ /aix/) ? ".csect\t.text[PR],7" : ".text"; - $ret = ".abiversion 2\n".$ret if ($flavour =~ /linux.*64le/); + $ret = ".abiversion 2\n".$ret if ($elfv2abi); $ret; }; my $machine = sub { @@ -56,8 +58,8 @@ my $size = sub { if ($flavour =~ /linux/) { shift; my $name = shift; $name =~ s|^[\.\_]||; - my $ret = ".size $name,.-".($flavour=~/64$/?".":"").$name; - $ret .= "\n.size .$name,.-.$name" if ($flavour=~/64$/); + my $ret = ".size $name,.-".($dotfunctions?".":"").$name; + $ret .= "\n.size .$name,.-.$name" if ($dotfunctions); $ret; } else @@ -142,7 +144,7 @@ my $vmr = sub { # Some ABIs specify vrsave, special-purpose register #256, as reserved # for system use. -my $no_vrsave = ($flavour =~ /linux-ppc64le/); +my $no_vrsave = ($elfv2abi); my $mtspr = sub { my ($f,$idx,$ra) = @_; if ($idx == 256 && $no_vrsave) { From patchwork Mon Nov 28 04:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1709526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=CT61j/eO; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLC0x5ddCz23nB for ; Mon, 28 Nov 2022 15:19:45 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NLC0x0hvhz3f8l for ; Mon, 28 Nov 2022 15:19:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=CT61j/eO; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=CT61j/eO; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NLBwj15Cxz3cQl for ; Mon, 28 Nov 2022 15:16:04 +1100 (AEDT) Received: by mail-pj1-x1033.google.com with SMTP id t17so8320303pjo.3 for ; Sun, 27 Nov 2022 20:16:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vysrk3dGTGyq4JoEtNOlnGeU0Y9RTh57n/bH2voLswM=; b=CT61j/eO21oJFoArWdo5BXt9PjYN56dxU7TxhKm8eGie18UtMCh6x7M8nf6RhHrohE KCetcywpvOt+OuN5lHvMqvqnUpcU/U7NL90xfg2l6oxRgws9Pb9eLi/0D230cNpNsga1 BFTr2l71QoZy8xXcHMP78h8OK885PwSzMjP4RBv1I+YTgCwBoidYcxga/h5Vi9K0mw7H 1hndDv/iVkqi1YjDEcSC2nrRRyE+z7MeEelm7Gks57kBdgZEM1DG4b7noSkquVOH8DKG k5tyrIA4X8QrNHW4X6cnY4/Lwjex1kCKy0i6RnHo/A0VhRAid/Q9dbv2fIncq5K0R6eG vmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vysrk3dGTGyq4JoEtNOlnGeU0Y9RTh57n/bH2voLswM=; b=nxO/2L/Z4q4pg3DFcNjp09GsJlhwiBGrz6FHJPkDGf66YEsEjlMM+0CcTPlh3U5VTx zO7m2v7yfHLUpSEp4PgL7q8K6STqklugsC6sCWKiVQbpniWUcK3OCiiZG2LPDPQxErCv NCFIkAq1NOpCkmaOCufZYyXjxMndB6xif9dSI3811suaNBbBmCVz0WDMfqHsGpnm/I19 zXunVs16JSjUb7xbjw8wCFu7HvJ8MxwqRyfoBtXGXbxqE2K7ARgfWHeI63SsFMlYpaYa opvlhLZX9ru1BQsiawjEhBFb8noAhaWr4oF6KQCRfg9v6u5D5PHyYTpKm9aIb1xsPl8Q XoUQ== X-Gm-Message-State: ANoB5pkXGV/zyxu+mlqMsIloB7mz8Su+koMhrCUhA+FsjwC4HwCVchEq WYEe0AuEGQJKslyXt2Cuh2MP7Gm0R4Y= X-Google-Smtp-Source: AA0mqf61Q9PHfLeMkWB4Z3x5rPv5/rLH2A0u1Sxu5ThZlDdD9zvRWmcj4fNMDlgzGkTjjDyzoulPvw== X-Received: by 2002:a17:90a:440f:b0:218:9894:62c1 with SMTP id s15-20020a17090a440f00b00218989462c1mr43569056pjg.205.1669608962923; Sun, 27 Nov 2022 20:16:02 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.231.60]) by smtp.gmail.com with ESMTPSA id y28-20020aa79afc000000b0057489a78979sm6905670pfp.21.2022.11.27.20.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 20:16:02 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v6 4/4] powerpc/64: Option to build big-endian with ELFv2 ABI Date: Mon, 28 Nov 2022 14:15:39 +1000 Message-Id: <20221128041539.1742489-5-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221128041539.1742489-1-npiggin@gmail.com> References: <20221128041539.1742489-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luis Chamberlain , =?utf-8?q?Michal_Such=C3=A1nek?= , Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Provide an option to build big-endian kernels using the ELFv2 ABI. This works on GCC only for now. Clang is rumored to support this, but core build files need updating first, at least. This gives big-endian kernels useful advantages of the ELFv2 ABI, e.g., less stack usage, -mprofile-kernel support, better compatibility with eBPF tools. BE+ELFv2 is not officially supported by the GNU toolchain, but it works fine in testing and has been used by some userspace for some time (e.g., Void Linux). Tested-by: Michal Suchánek Reviewed-by: Segher Boessenkool Signed-off-by: Nicholas Piggin --- arch/powerpc/Kconfig | 21 +++++++++++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 2ca5418457ed..2d0d80bcc24a 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 source "arch/powerpc/platforms/Kconfig.cputype" +config CC_HAS_ELFV2 + def_bool PPC64 && $(cc-option, -mabi=elfv2) + config 32BIT bool default y if PPC32 @@ -583,6 +586,24 @@ config KEXEC_FILE config ARCH_HAS_KEXEC_PURGATORY def_bool KEXEC_FILE +config PPC64_BIG_ENDIAN_ELF_ABI_V2 + bool "Build big-endian kernel using ELF ABI V2 (EXPERIMENTAL)" + depends on PPC64 && CPU_BIG_ENDIAN + depends on CC_HAS_ELFV2 + depends on LD_IS_BFD && LD_VERSION >= 22400 + default n + help + This builds the kernel image using the "Power Architecture 64-Bit ELF + V2 ABI Specification", which has a reduced stack overhead and faster + function calls. This internal kernel ABI option does not affect + userspace compatibility. + + The V2 ABI is standard for 64-bit little-endian, but for big-endian + it is less well tested by kernel and toolchain. However some distros + build userspace this way, and it can produce a functioning kernel. + + This requires GCC and binutils 2.24 or newer. + config RELOCATABLE bool "Build a relocatable kernel" depends on PPC64 || (FLATMEM && (44x || PPC_85xx)) diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 0c4eed9aea80..6e94d45f3baa 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -575,10 +575,10 @@ config CPU_LITTLE_ENDIAN endchoice config PPC64_ELF_ABI_V1 - def_bool PPC64 && CPU_BIG_ENDIAN + def_bool PPC64 && (CPU_BIG_ENDIAN && !PPC64_BIG_ENDIAN_ELF_ABI_V2) config PPC64_ELF_ABI_V2 - def_bool PPC64 && CPU_LITTLE_ENDIAN + def_bool PPC64 && !PPC64_ELF_ABI_V1 config PPC64_BOOT_WRAPPER def_bool n