From patchwork Tue Feb 23 08:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 12100045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DEF7C433E0 for ; Tue, 23 Feb 2021 08:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 491C364E20 for ; Tue, 23 Feb 2021 08:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232133AbhBWImj (ORCPT ); Tue, 23 Feb 2021 03:42:39 -0500 Received: from mail-eopbgr1320105.outbound.protection.outlook.com ([40.107.132.105]:27718 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232054AbhBWImj (ORCPT ); Tue, 23 Feb 2021 03:42:39 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=neRYyw4ST5IjBzdy75KZufkcY6HHhLVgPMaEk4sQY46H29v8mG7lqYIQFSI2a9YXF3Gyj4TsM36ROZFLrD0sl+wX6B0eGty8tbgmveyHWLb3addspw3xA2zVJ7dyEbde/mUc+U8GOa6zEtkx2ljsNfDze1M50Jj7du/JXeDp6OQ7JqvboVtLLmKl6LHIsn+6YhsbBPwzXqK7wa1idWoU3fpfIozhRDc5GQ36p9vOK5OfoMJHv6LpSASoHF3KuHkypI0ecxEiAx/DnwmRnlj2DtCTPVC/scufn5rFlcsTWo2AGDAxKvY+A2t2R1jIbsQKeufKcsPKtFegoUInZBUKGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IRzTOLozD2+GmOLIG4rzAWnEQh+qTnWV3UcLHAF3Vw8=; b=g24iwtI6bIFmzXwqgoJfRcAAccbh3KCBQWwx/3qqdE43BXvB6hdji9IMCKNhFWq+sLH+dVgws79glD+S6E6SJxVEhNJd9/CSBQ/+23rSZGyTwuoL9AnMAKQXWkwvJ+gUSNV70UYFnA69EksI9dKBE/T4MlybVpqaiqcISLYhAEtmjd/iYj1nDWQ1YKKTMdLuhWFxHGxxP7ASLKkkFYrp4qkxeIXN7ttCas3MiO+xVWitEmZqtJdPl9gR8ySpqd6bzAUICzB2vjrgecgVPQMMCVB4Lf4ixCs61bE2zswdpUuIG3efHDaK/9YL3T5Xg+4V4H4VS0tRFoWHtE2KHzqn0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cipunited.com; dmarc=pass action=none header.from=cipunited.com; dkim=pass header.d=cipunited.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cipunited.onmicrosoft.com; s=selector1-cipunited-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IRzTOLozD2+GmOLIG4rzAWnEQh+qTnWV3UcLHAF3Vw8=; b=weMWllObg505MUxcLSCIvb8aPe28Kfod/31z5YwSPad783CeQ2v/G8ELPou8nErMrNnmG9C5v4iiyJpfZDz4tmqMM99Mg1r+o2GMi/L1Dseo7oFB2oc+zcwzqeWwVbqKQQDtLL3mR1uU7cUkozf3lYoXEZSNYrPSLUJyuyl05dI= Authentication-Results: alpha.franken.de; dkim=none (message not signed) header.d=none;alpha.franken.de; dmarc=none action=none header.from=cipunited.com; Received: from HKAPR04MB3956.apcprd04.prod.outlook.com (2603:1096:203:d5::13) by HK0PR04MB3444.apcprd04.prod.outlook.com (2603:1096:203:8d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.26; Tue, 23 Feb 2021 08:41:01 +0000 Received: from HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::b5d5:d70f:ed37:984c]) by HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::b5d5:d70f:ed37:984c%5]) with mapi id 15.20.3868.033; Tue, 23 Feb 2021 08:41:01 +0000 From: YunQiang Su To: tsbogend@alpha.franken.de, jiaxun.yang@flygoat.com, macro@orcam.me.uk, syq@debian.org Cc: linux-mips@vger.kernel.org, YunQiang Su , stable@vger.kernel.org Subject: [PATCH v5] MIPS: introduce config option to force use FR=0 for FPXX binary Date: Tue, 23 Feb 2021 08:40:49 +0000 Message-Id: <20210223084049.16475-1-yunqiang.su@cipunited.com> X-Mailer: git-send-email 2.20.1 X-Originating-IP: [60.247.76.83] X-ClientProxiedBy: HKAPR04CA0014.apcprd04.prod.outlook.com (2603:1096:203:d0::24) To HKAPR04MB3956.apcprd04.prod.outlook.com (2603:1096:203:d5::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (60.247.76.83) by HKAPR04CA0014.apcprd04.prod.outlook.com (2603:1096:203:d0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Tue, 23 Feb 2021 08:41:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05600c75-2e5a-4bfa-70a7-08d8d7d6bf51 X-MS-TrafficTypeDiagnostic: HK0PR04MB3444: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1002; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gP3fcG2i++eeZte0tTpes1CbU+oRTo9ZuJ6YC/fnwTSaaD9hSJp53TxT96zV4psI6pTDD/Fxecvsml+6GkACXbcxT89q9Kq2bkgQk+1QhitZeianzpErjVEogyUIJFrdZRROX5V9X1wTaqOgIPAfKpOTCI6p18o183gwdau4O/e+YVFyKV4eEiXKgfNpOJYi1EZTEcgKY/2WV+c/QfSp1+bGT0cZU+F/4SqxABENHmkyE7yzoTpFadNnUS2/NNVQrF3Sw7DUTR7IQ0DYERc7hWdVrrwyOTbvjPgAp+JlrXe2zGPl6VR0P1Zp+VJPOMpBjO5EPNzS5m9xDuDa97GfCRTQz1VA0dDgtOpyFgEChH7iIrUHxjr3IODvRRXqDF/+jNZ63D+A/K3ZDCVoXOC9ZLaYLYY/cc6d3CKA/ykBZeSFh+rFIZYUrFiAB+h7tx+AsF5cBWhLwe9qfhFg303n10Yw9DUtQpKSX+6ztSik/LwcQuVyP++4gop5k9oA0hpbpKbIm3q/l7fUNIpu5RFz04ljGIVTehamM0V6Lp8VUuk5rVjMdNuLJxjTgvQuFXf2Xiq3wPuZBlO9icfgjh/GcX0XEoMGk+KLf0gbWr1af33jXOWBFnbvXu/LCSUG/tEYvTaKreF1WtRBrv9hRp1Ptw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HKAPR04MB3956.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(376002)(396003)(39830400003)(346002)(6666004)(6506007)(8936002)(6512007)(966005)(86362001)(5660300002)(2616005)(26005)(16526019)(186003)(1076003)(956004)(36756003)(2906002)(66476007)(8676002)(69590400012)(52116002)(83380400001)(316002)(66556008)(66946007)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foxmSNO8SQk/MU4uMEby6ocTlVqWS3wbfUA7Q1yX6zkuQH/1BQFhRgpiDBUiUKfYiM/+QsbGKb2Mir0aLCU7oq2sVLSz6NF3J/VT01GdJL90xUR9kYPk40qhkZ1Kh65d6FqpQGBwMSRqoBKKWoFN/JjVJevbRJVdm+Eg/4cQ4f1ulf4wKONqu8nbTfLgctfHsUtXWHVvSCVe1A+myCKA2mRiSsPskntfmjJGabUL6V5NiY+Nw6it8vQGEmEj79sHQCxEsxNhyZO4bGGmpUXp2lzjZ8mW9HKDS4LftiIYOgPNj9N8DJdDF2XFLUJm5Z+L2H/ X-OriginatorOrg: cipunited.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05600c75-2e5a-4bfa-70a7-08d8d7d6bf51 X-MS-Exchange-CrossTenant-AuthSource: HKAPR04MB3956.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2021 08:41:00.9885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e31cf5b5-ee69-4d5f-9c69-edeeda2458c0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y30Ph/IxJG56qUs60lxLeL+lSjKUMqfvFzr8qOojwT07nQfaVpPeamJ7z5AGB66a23DFB5QgSm2Bc9b7lwWjNsX/GKlWNimX20m6q+dTW2w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR04MB3444 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org some binary, for example the output of golang, may be mark as FPXX, while in fact they are still FP32. Since FPXX binary can work with both FR=1 and FR=0, we introduce a config option CONFIG_MIPS_O32_FPXX_USE_FR0 to force it to use FR=0 here. https://go-review.googlesource.com/c/go/+/239217 https://go-review.googlesource.com/c/go/+/237058 v4->v5: Fix CONFIG_MIPS_O32_FPXX_USE_FR0 usage: if -> ifdef v3->v4: introduce a config option: CONFIG_MIPS_O32_FPXX_USE_FR0 v2->v3: commit message: add Signed-off-by and Cc to stable. v1->v2: Fix bad commit message: in fact, we are switching to FR=0 Signed-off-by: YunQiang Su Cc: stable@vger.kernel.org # 4.19+ --- arch/mips/Kconfig | 11 +++++++++++ arch/mips/kernel/elf.c | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 0a17bedf4f0d..442db620636f 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -3100,6 +3100,17 @@ config MIPS_O32_FP64_SUPPORT If unsure, say N. +config MIPS_O32_FPXX_USE_FR0 + bool "Use FR=0 mode for O32 FPXX binaries" if !CPU_MIPSR6 + depends on MIPS_O32_FP64_SUPPORT + help + O32 FPXX can works on both FR=0 and FR=1 mode, so by default, the + mode preferred by hardware is used. + + While some binaries may be marked as FPXX by mistake, for example + output of golang: they are in fact FP32 mode. To compatiable with + these binaries, we should use FR=0 mode for them. + config USE_OF bool select OF diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c index 7b045d2a0b51..54b40b2b40b7 100644 --- a/arch/mips/kernel/elf.c +++ b/arch/mips/kernel/elf.c @@ -234,9 +234,10 @@ int arch_check_elf(void *_ehdr, bool has_interpreter, void *_interp_ehdr, * fpxx case. This is because, in any-ABI (or no-ABI) we have no FPU * instructions so we don't care about the mode. We will simply use * the one preferred by the hardware. In fpxx case, that ABI can - * handle both FR=1 and FR=0, so, again, we simply choose the one - * preferred by the hardware. Next, if we only use single-precision - * FPU instructions, and the default ABI FPU mode is not good + * handle both FR=1 and FR=0. Here, we may need to use FR=0, because + * some binaries may be mark as FPXX by mistake (ie, output of golang). + * - If we only use single-precision FPU instructions, + * and the default ABI FPU mode is not good * (ie single + any ABI combination), we set again the FPU mode to the * one is preferred by the hardware. Next, if we know that the code * will only use single-precision instructions, shown by single being @@ -248,8 +249,14 @@ int arch_check_elf(void *_ehdr, bool has_interpreter, void *_interp_ehdr, */ if (prog_req.fre && !prog_req.frdefault && !prog_req.fr1) state->overall_fp_mode = FP_FRE; +#ifdef CONFIG_MIPS_O32_FPXX_USE_FR0 + else if (prog_req.fr1 && prog_req.frdefault) + state->overall_fp_mode = FP_FR0; + else if (prog_req.single && !prog_req.frdefault) +#else else if ((prog_req.fr1 && prog_req.frdefault) || (prog_req.single && !prog_req.frdefault)) +#endif /* Make sure 64-bit MIPS III/IV/64R1 will not pick FR1 */ state->overall_fp_mode = ((raw_current_cpu_data.fpu_id & MIPS_FPIR_F64) && cpu_has_mips_r2_r6) ?