Message ID | 20221102160106.1096948-1-scott@os.amperecomputing.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E154C43219 for <linux-arm-kernel@archiver.kernel.org>; Wed, 2 Nov 2022 16:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=LJI/VVyhLeX4KMJYgdRYdkjNLsXK7AGjQ1h72BRSd5U=; b=ChirRDrxSr86kK lX897DZqj+nPebZY2z1Rm3/F5Od4F1nRYYs89dJ6fZSnFjdybEclKWmOf0ig8WCL9heJhJoQKqUP+ gu/DJkMZ40Jvj3dq6iWt0iX/HLHBi+6yOBKBIShVxnXrVcc8kiolSL14Bk0IqC286USQXj7ydYLmA XqHVsSGecGqPBmiVYpg8PL28tdTlaVuXR1OUjA4S1LkceRANZ9x0ze/a2xHAtiZPorTLVZycapX4R FPoigQyMCnKUn5exvz4X3YHtm/QoxchQ5X5R4KyDKlykALlGEx7qD35aBsrD/uO4Nz/M2VqzOPRy/ nqDsnnbsSfNMtf8hptWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqGBH-00BxTl-0v; Wed, 02 Nov 2022 16:01:31 +0000 Received: from mail-dm6nam12on2110.outbound.protection.outlook.com ([40.107.243.110] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqGBB-00BxPY-S2 for linux-arm-kernel@lists.infradead.org; Wed, 02 Nov 2022 16:01:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZVj0uFOroSDhcOy8AisEAR9YKR9RhNxgezWK6IcwrgYUL0KelqwiZsSIkFNgo5+W4Wymyf7vbUunwIDzdeYrwzcWORPeQgyK8xxuIXMlbhcSgqclRyafqR74qjGD98ZrekTwT8B9MFQDyPmQEThIcHT/tjBOKUTiq2sjszsZKeIrjt0WoivS3ZdV7C/ujma/iHYwBHkJJPeDCGkIBUzdboKArT1wH5ve8vCZYL/eE6GAHi18ixuQ2h5InhQ+gnSpjS1u09g23SECAHdPEqNRcVgSgSXVTj8c8oczZzp5/1ncFLa/YtaRys0YbKMu/LsgYEY+Wvs8To/AnmvxN28yaw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=B7ZFRgkpWZRTUSvJRm4I5ZuDwcPutD9S3gV67cvsn3E=; b=gTQDGQSRyHbssbresXoXr4kIk4KX5AEWGrpFwaUUFge8A4SQUPwD1IVXW2IoAhZzyfACVP3wv75DUHls3lth1fpMFXtIpnGR/QZ0O/AQ9oRu6b8BaEycQLwlqZDC6LK2MftQmpOE59XukBne2Y19wmlKqNw0zOzEirOSEF9rQHpw8rg2rO1sWrkuaHdTs4cuasT3/mdAaI14sCS8cv3llXNhaplUviVe60AyW+mC4p78VWR+TBA8SujVc6VO7VH6BQBX0GmVbT0M3mo1Bu34hoS1IaegHfl7DnM0JxYr+Tx7urD0zO73v8iXxMZZRUqkoIfPph9Wo+1iNvWzInmn0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B7ZFRgkpWZRTUSvJRm4I5ZuDwcPutD9S3gV67cvsn3E=; b=BP9Ugz9P1tHs5CkAZCr2V8oU8Y/2VxIkjdmeARnR8AqueiE4PMzez5FTBjzykLFWvdhcqExvYdk4IuOT16xgSPsyNaeZ4CPKri2ar2ntDAiU5Ii1yerlZM2u78dnomqdVCYrVSmd818BD9Ghv1LCMfD9PsdwPpuPVy+sYE4DdM8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by BN8PR01MB5315.prod.exchangelabs.com (2603:10b6:408:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.18; Wed, 2 Nov 2022 16:01:16 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::17fc:6ee3:d2c9:7731]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::17fc:6ee3:d2c9:7731%7]) with mapi id 15.20.5769.021; Wed, 2 Nov 2022 16:01:16 +0000 From: D Scott Phillips <scott@os.amperecomputing.com> To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, James Morse <james.morse@arm.com>, Geert Uytterhoeven <geert@linux-m68k.org>, Darren Hart <darren@os.amperecomputing.com>, patches@amperecomputing.com Subject: [PATCH v2] arm64: Fix bit-shifting UB in the MIDR_CPU_MODEL() macro Date: Wed, 2 Nov 2022 09:01:06 -0700 Message-Id: <20221102160106.1096948-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.37.3 X-ClientProxiedBy: RO2P152CA0020.LAMP152.PROD.OUTLOOK.COM (2603:10d6:10:2c::25) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|BN8PR01MB5315:EE_ X-MS-Office365-Filtering-Correlation-Id: 1569e1dd-a874-4475-9742-08dabceb78e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3qpZMdQOq1Rxny8Y8eEr5uTRiZEW+Yw2dLVGPqnpynMJUeoRXN7Cpik3gjEvJY/+n06bxu/tMvQ7/uu0VjhBot+6MU3X1MvScBws6cYXbe4GwTocIzTmL9HnPPGgkW/H4NqP+AHPSkQuilN3EfvvdTRII/aZ83izbPdFFsBE/V4RUHFi08vM/SFd4ZFn5zJhzBY0xaoHTDbccAvFQn1NKqQlYn6+wD5Mtu1hlV9TZCHBQyAUfK/M+bdPPcJx4pD+SuHTGkOeQejPa+q1M+EabH9mGjPXU0dY09OkhRozx1ezZgmUqw5lBF+MnRUkXhgW8srjt6tqYwTECZQl+dPul4lfXiEmKOBli21KVhkD7NZoIqRKCmkMvnJXVVlhJ9vjOyZ79K7qPS8lIqK3wuY4xIcxGCuM9hoLnhKhQtK6tVUf5b98KtVDEYD6GewHzc5cmGjq/qRPZSL5d/qC/3XeB9sFM9GqEwsGE0eMtdpeI/+DBwYAWfcn9cVUNhHScjn7oMSNssQ/vA4j1aqU2Nuu6bZ7b8jl9kcJPePLQ9hilFr5/L3hPzA4bJlgNUJKDx4YmgiRO/pGFG1Oh6qdbs43RRlxXi60rcp33O7j5/oud9wNaAUd2KtQOF/V4XtPUoQGuXEyxUVQmZS3O36/D5I5NWhOlWx6E2Zk2kMIwfogkhbgOB8jPvrF1gmMCxTO/Ad4Gmnc7eln51dbl1JVrZXa/XWXgq9Udw+9mhQRpl5EOd503LnKvU8FEX5wVoBYbETsEcd7R+2eEdrN6mrIgopVwvQIEZVeZ8fw9v/Fs+XGP78= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(396003)(39850400004)(366004)(346002)(376002)(451199015)(2906002)(5660300002)(86362001)(38100700002)(38350700002)(83380400001)(1076003)(186003)(2616005)(6512007)(26005)(6666004)(107886003)(478600001)(6486002)(6916009)(54906003)(316002)(41300700001)(8936002)(66476007)(4326008)(66556008)(66946007)(8676002)(6506007)(52116002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nVvs2xJpWUYtzGReK3MNphkBI3U/mfgNV3BC2d9mvU5Y9wG7zLoFUKEGSqdOyLZPhoIOq41/4wCuVrdRiDek/oC+JYoT9+23ULvFH5nmSW53nz+I801e1ukBwZ7eCROXmCycDSt+15y2JR2ADIb+7EBprpoToJd7cRj3qrodpucmgL2NxcifezUJJY5RbxNdQdBDJNgkWTGM2CeKtCQedFkTIlNeYBAEVlYxUszkgkKqttJYkUhuGB6f3xOR2WREwkXA0xLpX8ZorUIY9ePnj6QF4z/LKkcA6pijgS3A6MZEPeXPFv07SLNhQ1PEa1V2eT6ZowGicPbVVo3+de0/6n68/iyt0Y9ex0zGzAtNbNwSJa/OGpRNy/BFPhQa5YrjEI8PatL3zt/qzKAvrvEKTYua72OlwG5sDh8Cq8GpVBm2EC8Shoi53DtvzQsXQeHqg9l82I1fBnTbsxgox9OyvP/8akd077NGe0JroGBtJ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dWThFGXDIOzx1snHee3IXQeH3D37DMuVrGog== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1569e1dd-a874-4475-9742-08dabceb78e7 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2022 16:01:16.2969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KfENCc8VRuZkVHopQSn8vx9yvhaggJybm9DoWhvQA8LWE0ns62q8kmaMkdhdaaGoLtRLasdD3VxkWSKeiMKZeIJQD5ObPSAC/19Gil7AV47Fa2Tw2Qy3rSJXxLmE2Kr0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR01MB5315 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221102_090126_157435_AC19C2FB X-CRM114-Status: GOOD ( 12.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: <linux-arm-kernel.lists.infradead.org> List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe> List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/> List-Post: <mailto:linux-arm-kernel@lists.infradead.org> List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help> List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org> Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org |
Series |
[v2] arm64: Fix bit-shifting UB in the MIDR_CPU_MODEL() macro
|
expand
|
On Wed, 2 Nov 2022 09:01:06 -0700, D Scott Phillips wrote: > CONFIG_UBSAN_SHIFT with gcc-5 complains that the shifting of > ARM_CPU_IMP_AMPERE (0xC0) into bits [31:24] by MIDR_CPU_MODEL() is > undefined behavior. Well, sort of, it actually spells the error as: > > arch/arm64/kernel/proton-pack.c: In function 'spectre_bhb_loop_affected': > arch/arm64/include/asm/cputype.h:44:2: error: initializer element is not constant > (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \ > ^ > > [...] Applied to arm64 (for-next/fixes), thanks! [1/1] arm64: Fix bit-shifting UB in the MIDR_CPU_MODEL() macro https://git.kernel.org/arm64/c/8ec8490a1950
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index abc418650fec..65e53ef5a396 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -41,7 +41,7 @@ (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT) #define MIDR_CPU_MODEL(imp, partnum) \ - (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \ + ((_AT(u32, imp) << MIDR_IMPLEMENTOR_SHIFT) | \ (0xf << MIDR_ARCHITECTURE_SHIFT) | \ ((partnum) << MIDR_PARTNUM_SHIFT))
CONFIG_UBSAN_SHIFT with gcc-5 complains that the shifting of ARM_CPU_IMP_AMPERE (0xC0) into bits [31:24] by MIDR_CPU_MODEL() is undefined behavior. Well, sort of, it actually spells the error as: arch/arm64/kernel/proton-pack.c: In function 'spectre_bhb_loop_affected': arch/arm64/include/asm/cputype.h:44:2: error: initializer element is not constant (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \ ^ This isn't an issue for other Implementor codes, as all the other codes have zero in the top bit and so are representable as a signed int. Cast the implementor code to unsigned in MIDR_CPU_MODEL to remove the undefined behavior. Fixes: 0e5d5ae837c8 ("arm64: Add AMPERE1 to the Spectre-BHB affected list") Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: D Scott Phillips <scott@os.amperecomputing.com> --- Changes since v1 (https://lore.kernel.org/all/20221017210119.3581-1-scott@os.amperecomputing.com/): - cast in MIDR_CPU_MODEL() instead of changing ARM_CPU_IMP_AMPERE arch/arm64/include/asm/cputype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)