Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp963475rdf; Wed, 22 Nov 2023 01:33:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbJuCfeUtnbc2vk7AyfekYNYsSU7LcYrNOBrlAtU2tdHBPBusg0T3q/6Y75E+wkd2tC6aw X-Received: by 2002:a05:6a21:3614:b0:187:c8ca:75ad with SMTP id yg20-20020a056a21361400b00187c8ca75admr1470572pzb.31.1700645601668; Wed, 22 Nov 2023 01:33:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700645601; cv=pass; d=google.com; s=arc-20160816; b=E5AooegNyWK9C4uYcQjveR2w6sBc3JEWaUlchKstax38yrFYcHTALpOyP5K0WqoI/Q tt+ai4IEvhu2qjCq9UcpWqLsuXGWuh1hQe0ockz5bqOwVBkNat8BcIJlL85Nl8aQ2PZA 03zSMKlgxvuFINxvmX8cmNMYou2kIwlS7/5cUZAxujafBnMS3KFC1Yb2Q094J/V/cWAV yKAbBj29/e2W++15N3Kqhh4jTaTvpsAJ33zEA6kZlpXyT4z2lUWvsbRxMRTXkQ1Vi2Gc skcXy/VjV6+ZoXy8EXahme1IQ8jpEFPeTnK6Mybx1z1JhYOcP3lz9YTdiNHqiZSPLv2y xRrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SUn//U9TfDz72Pv19tjJUG4gFENPgF7D5GIy7JZ2GPE=; fh=IFMWg6fVnSyRGoEnT4djvIpOdIiU2mjS7YkNhQGkXP4=; b=MO6cFE/tdYUWVfRW/ygKcrF5KA1z5De2cjhy+CxpNUTqEIufncd7znIKFklELWr4vT OYeJrOr2d+NwEYO78fprXJ1VpeGwsWECaPRXiPEozIfmrvn6bZPMh50brFgUlJ9gp2z7 1Q0rG37F3ZtVPlnNWtwIAR0nT/yD6iH4pdgr2NshwoF4vNP4Gk+k1WRRQKRKb3SJ26wu +yrGKur05Nk+J/F5pw2GtVAuzBZMwzJNjBGiJF04oyzuDBUGPUqRQjmJlU6VnHFgUPB2 24FZT29cMS6Fv8ztNOrMzxabPk0ljGgci0uPMYIN6a8N+aUOvXCTcxgxblaXD0bvmBfW w/Yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=mLRaBt4N; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q16-20020a656850000000b005c2201d6a57si9349501pgt.283.2023.11.22.01.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:33:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=mLRaBt4N; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 43793806B548; Wed, 22 Nov 2023 01:30:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235202AbjKVJaC (ORCPT + 99 others); Wed, 22 Nov 2023 04:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235235AbjKVJ34 (ORCPT ); Wed, 22 Nov 2023 04:29:56 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2121.outbound.protection.outlook.com [40.107.101.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2AA7193 for ; Wed, 22 Nov 2023 01:29:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LLlwMUdvihAQH93fCLa5GcBj+KWJSpJ8HxQuYss1ggzTkX+S6apvRVgY7V54JIk4m8j7UecDqyBxWomfQ1ioq5RTo3KzalKhoQMydgUncyKqiefvyYye46E5Egy7L7KFHrlJFGmzHryqH4GKFSOMNSSff3iUDT7Srt6ZUrMF7z010y+fFlWBR4MvOC8MveH7Ebd1v+gY+4KfBQ43y8KDBVT3H0yDg8mxzklBi0lJaXD2TR19wptvw0H5TG3vM+wg9UkavuGqvDP7kwMXSeqJLXuHu3SrSJGYmuwibkTHNkJsDwZew3DQ+5bqf39Sglq+HyE9Cy0mYUd4/qnd81vxqg== 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=SUn//U9TfDz72Pv19tjJUG4gFENPgF7D5GIy7JZ2GPE=; b=RY0g4WF3DlKXqSw0pAMlMdRHj8WND5BEzD6kBdvz5mxTz87ipOOF9+haHbXJp3s9vB4m4eQPhpaxeuRmbLJJEI98C0NfgvIbMpRFec5K3r6nQaYfbCtnrNU0moPNvP3HhkO/n7iZzp4oYYWIbc0nINrI8qBSmEXb4DphpMiPcSJHtzLOiZHmiHup1/sj0J3bMceDO+zDsj3kmN9rEBa+PejWTwcqr3ZhWcuhLLvrX1LZcof670GDmX/Nb1UBlUxMjrFwTGlYA5fCbL+7eyITODa3Orqr3aHkv8iP6N7ctAPXKu7jUgGfmTLjtuMB6DWmJ/N0GjyWwi7K1IQF9cnFJg== 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=SUn//U9TfDz72Pv19tjJUG4gFENPgF7D5GIy7JZ2GPE=; b=mLRaBt4NF4bEZbFvCblOULGm3iRwFLc19WHq8sB81H/lIC5XSKed91GWUIURUFbszwzVoGfFJUwuCnUolT9P/oWroa04TUfOXPTXF90gPo5KOeAYv1m5REFcqthvAzuPD7OZfmmGIN4Wj+iH37RvF0bBoGVZLC14kP7G51zsEaQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB7975.prod.exchangelabs.com (2603:10b6:510:26d::15) by CO1PR01MB6760.prod.exchangelabs.com (2603:10b6:303:f2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 09:29:44 +0000 Received: from PH0PR01MB7975.prod.exchangelabs.com ([fe80::3f45:6905:e017:3b77]) by PH0PR01MB7975.prod.exchangelabs.com ([fe80::3f45:6905:e017:3b77%7]) with mapi id 15.20.7002.027; Wed, 22 Nov 2023 09:29:44 +0000 From: Huang Shijie To: catalin.marinas@arm.com Cc: will@kernel.org, mark.rutland@arm.com, suzuki.poulose@arm.com, broonie@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, robh@kernel.org, oliver.upton@linux.dev, maz@kernel.org, patches@amperecomputing.com, Huang Shijie Subject: [PATCH 2/4] arm64: alternative: handle the kernel exception table Date: Wed, 22 Nov 2023 17:28:53 +0800 Message-Id: <20231122092855.4440-3-shijie@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231122092855.4440-1-shijie@os.amperecomputing.com> References: <20231122092855.4440-1-shijie@os.amperecomputing.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CH0PR03CA0247.namprd03.prod.outlook.com (2603:10b6:610:e5::12) To PH0PR01MB7975.prod.exchangelabs.com (2603:10b6:510:26d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7975:EE_|CO1PR01MB6760:EE_ X-MS-Office365-Filtering-Correlation-Id: aa21e5d5-c202-4ad2-8287-08dbeb3d8f90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QCp8t67fD1sIeBn/PpE8bjsJvqFUMAmsLAmiy/bjbC7mQ5s+40tdnsNEYiawqEmjOYUO2gu0dNFIEU0YAPE7I6CaOc7Wr04F2q88bPmKYxlnNSeO1X2QKeOYowKp9eY4oyCCx7E6JqTTd3jU+VZtjjTy4gjI4JaZuzDjogIfCL+J3vfnhBSpnlMNbx6LZJor+ADs0utlBzPOaSQP0Q1gJ6wbXL9pueV9pU+R1OqF8ITX7TAZNDg6cXRntVDV1fB47k8C4dxXa35mfpRmcLFkI/4H9EYBi7dVi5XsIsF7pXuZQ9iOkkE2DXkQ8xfXW3uzb6a9TyYdJNM60GaWAUZcGBDT2c73pOQ5+I2qjoZaqu3LLc9sqUAu9WOeNOn/p7DV4X3vm/DEeMMUQyPzlcPJN+1meOqPrygbW0FCs6J7NK0COSlNHNnkTgPosB7fLlX62YDrRtSsosQ2AOo8PYorBa2B3dAxbTVjW5l1l40gvPKZlUnFPhN8nRr1bgDuCJDy0aOWI3VFWErCfLwZQkSpbup3bMnaSWP6BfClPaEUsHVlgOleJiTNFIg3f/LnQoJwEj1s6UK0zq1YTl9wlwdF/DjCtRGFDVJuefbXzcp+US0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7975.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(39850400004)(396003)(136003)(366004)(376002)(346002)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(41300700001)(2906002)(86362001)(7416002)(5660300002)(38350700005)(6512007)(2616005)(1076003)(26005)(478600001)(6486002)(107886003)(6506007)(52116002)(6666004)(38100700002)(66946007)(316002)(4326008)(8676002)(66556008)(8936002)(6916009)(66476007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?EWKGUL0VhRMabPmxy3qFWoWmeDPfiAeD1DTmts7nn1+6LTWpMf/Vw4L4aiqP?= =?us-ascii?Q?R7N/10lTliK7F+JtwbqPvD2Z7i0p99KA7e/SirEbeZRqIMzf8i5sdNc0gtWJ?= =?us-ascii?Q?AKnHb16Hr1rpzwyQVN7qBaA/M/ceqbz6n0PNBRFca21zXqU7dy+VMe0hmlhk?= =?us-ascii?Q?Tf4DmofOlvucPBUznZ5qtm69/jYAaW1ydR3/7MVsDssoGAQqXB3Vsmn6bFSg?= =?us-ascii?Q?uGk8g9cSr3pIoRvA+EMSU3pgkEXnRfLpGiXXEyUyeqC3w0NxnweC9H0YT2Mj?= =?us-ascii?Q?KbB2dA5DCINLajpyxwFenFCP/7GWIkML0ffXytJARCsIA+zXxs907p/9m0c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dKs0ESnorgFReeabb8b?= =?us-ascii?Q?K66FTdd7RimxPKktTmGGRfWiu+MfmwgqxlTcHMsAhKC8IKw9JZ5Wknie1A+N?= =?us-ascii?Q?H8P0pewpbmPthUKhIGPIPTTTphWstLeHtw/83qzLNuIYmWWBdL2/RXPTS5LU?= =?us-ascii?Q?7lL8f2hEOEe1Uzsu7ssunGG7ZAl3ZO+dvf4kwusOzFtFAXsz9bw9uzQBJd4Z?= =?us-ascii?Q?5yR6nPJ5bC890CmT7gnE+Wgjz3fynr3RxYuYe1ADuGCV89W56ZbAbCvuI6lV?= =?us-ascii?Q?II25/dxA9sfsak+JvMgvZhAFMpTD2fyVaeT0CX6NnnPbPjBErWP7eP53H0pY?= =?us-ascii?Q?QCrepsWdoX1GUBXiE5ePPsQnT4gxvqzjN5WWVq6uI98NaVOJZJnwK4Tr1NuJ?= =?us-ascii?Q?4kaCADZtuCLOq1yzVX5MHMc=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa21e5d5-c202-4ad2-8287-08dbeb3d8f90 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7975.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 09:29:43.9654 (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: yo83bd2K29ZBU2doqssWgpeoT6cTPDq3FugHG7cfvsJ19fkgMg8riBQ5K+3w529K72K4I8cYkTz8UjBNpF7UB0Kyf/EQupacCvE1QrwNLlGqor0ScJHVbQ3XpeNKQOn/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB6760 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 01:30:19 -0800 (PST) In arch/arm64/lib/copy_templates.S, some macros involve kernel exception table, such as ldp1/stp1/strh1/str1,etc. Current alternative_if does not support to embed them. This patch adds the support to embed them into alternative_if: 1.) Modify the @insn to the right address, 2.) Sort the kernel exception table. Signed-off-by: Huang Shijie --- arch/arm64/kernel/alternative.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 8ff6610af496..4c73f9cc9a85 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -19,6 +19,7 @@ #include #include #include +#include #define __ALT_PTR(a, f) ((void *)&(a)->f + (a)->f) #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) @@ -101,6 +102,22 @@ static __always_inline u32 get_alt_insn(struct alt_instr *alt, __le32 *insnptr, return insn; } +/* Check the kernel exception table */ +static void check_extable(__le32 *origptr, __le32 *updptr, __le32 *replptr) +{ + struct exception_table_entry *e; + unsigned long addr = (unsigned long)replptr; + + e = (struct exception_table_entry *)search_kernel_exception_table(addr); + if (e) { + /* Modify the @insn to the right address */ + e->insn = cpu_to_le32((int)((long)(origptr) - (long)(&e->insn))); + + /* Sort the kernel exception table */ + __sort_main_extable(); + } +} + static noinstr void patch_alternative(struct alt_instr *alt, __le32 *origptr, __le32 *updptr, int nr_inst) { @@ -112,6 +129,7 @@ static noinstr void patch_alternative(struct alt_instr *alt, u32 insn; insn = get_alt_insn(alt, origptr + i, replptr + i); + check_extable(origptr + i, updptr + i, replptr + i); updptr[i] = cpu_to_le32(insn); } } -- 2.40.1