From patchwork Wed Nov 22 09:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 13464321 Return-Path: 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 C3552C61D9B for ; Wed, 22 Nov 2023 09:30:25 +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:References:In-Reply-To: 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: List-Owner; bh=mfy1DlBov25oZCqpPXseBkSHgLM4BlSYhzSjNErmNQc=; b=lo+DQxo51gm1xg Mgci+KK7IKbaGbsKNY3iP0ZytHwWRcZLqs7WS17DOcbRfkdzMz6pvTc+XBtwVk0zzFDZoPFwipJyc aTZoDrbcQLugkC0pVEBIQe9ahnDfKMm6arxsvRptYdOJbKrDjPY31HKkaCvbejfttaz5+H9iqs8E+ jr4ObHlz/1KapEapP9zOva9+bBzxPA4gNWTNykrhPzBHjFX+kaLQ3yjlc8hpWfP7t1wZ0nqLLVVf2 Hf5Rzpgb7Ya3n6wR5op12vfiHgYdjMCW49xtJmiezs2pJ44eh894kosrKn8HEtG0JDE9uofevzJFL A/Zg5zV53Dn0AJSHYQXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5jYT-001Cw1-0Y; Wed, 22 Nov 2023 09:29:57 +0000 Received: from mail-bn1nam02on20730.outbound.protection.outlook.com ([2a01:111:f400:7eb2::730] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5jYQ-001CsA-2w for linux-arm-kernel@lists.infradead.org; Wed, 22 Nov 2023 09:29:56 +0000 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> 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: EWKGUL0VhRMabPmxy3qFWoWmeDPfiAeD1DTmts7nn1+6LTWpMf/Vw4L4aiqPR7N/10lTliK7F+JtwbqPvD2Z7i0p99KA7e/SirEbeZRqIMzf8i5sdNc0gtWJAKnHb16Hr1rpzwyQVN7qBaA/M/ceqbz6n0PNBRFca21zXqU7dy+VMe0hmlhkTf4DmofOlvucPBUznZ5qtm69/jYAaW1ydR3/7MVsDssoGAQqXB3Vsmn6bFSguGk8g9cSr3pIoRvA+EMSU3pgkEXnRfLpGiXXEyUyeqC3w0NxnweC9H0YT2MjKbB2dA5DCINLajpyxwFenFCP/7GWIkML0ffXytJARCsIA+zXxs907p/9m0cBHWgCn+RiBGsqlHreK1sNc4GSFkxRlDNV+XzqDyM2OlJuMGyGy4zuLwTTKM+U38iRpP9uPXd5Rq1BmhThj8tfqotJ6us4g8hqti6RVxS1pOUNqi42ar6BNWvfq/LUyEafkQDtRWbmFp4B3TVPXngHvGTKA1o3ODUTxLkqmuYZWN3C1as/gedi8Qzsk6hyWhOqY7T/Plyy1J2CJZQPXzSOcm7dOz/4yTgrFowLVrgpGouLcVdajbOZbbH0mVowxd/N230Jx4hCCL83Jo9i0rxoTDzIn2/ClaKvtheTwW9pu9+UlHk0ij30fHMoBGZwnd1/1ZeayGKkXgKTbwroIIIXDnp8Wa2IGEoSJymdX/4CSWwosSLZUhptVMGeE/vAQr69CCdyyXy1OxY5DqhLqfzLSNCfl5h3VUqZps3B4RKYrODdINPtzrG4mqH3Bky0fm/FdUv/Wltp+bxEKl+hWAMaoQGpZhpTvCWXzAtjt1T5bsSkqe8u35oC2WryA8627hU1V7YFcquIvF4ArgY+mI1Dzyn1Ag8WpiZDYiH60616ZBmKAtpZlWnNd7oEEwCfdKLWUos0zW5x90UmYghGgubhi3zvnYQW7F6BwWh827xC2eiE5P3VhqXVg7MQptWB1mqozsKAxu5X88foovrKGnGJl8pOhOb8Pip7fdE1V21oQlcOEi1AB0EPWiD+PqrJWokKp5LTNTOQffLDailPr+QVUwJ7xsVeYuDSf4qnViXJx1CZPaKwOrAn6nFx9iSTF7AwjNRfxdXWUfxmteTostKRX8zeo10mFhSQIZu2hQeebDARq2QABpHR9v/4dvAqlgrJ2xdLBlhf64wTAWolVTv8gpDAVYWdaZm687Ok0cy0V47Wxbco6dKs0ESnorgFReeabb8bK66FTdd7RimxPKktTmGGRfWiu+MfmwgqxlTcHMsAhKC8IKw9JZ5Wknie1A+NH8P0pewpbmPthUKhIGPIPTTTphWstLeHtw/83qzLNuIYmWWBdL2/RXPTS5LU7lL8f2hEOEe1Uzsu7ssunGG7ZAl3ZO+dvf4kwusOzFtFAXsz9bw9uzQBJd4Z5yR6nPJ5bC890CmT7gnE+Wgjz3fynr3RxYuYe1ADuGCV89W56ZbAbCvuI6lVII25/dxA9sfsak+JvMgvZhAFMpTD2fyVaeT0CX6NnnPbPjBErWP7eP53H0pYQCrepsWdoX1GUBXiE5ePPsQnT4gxvqzjN5WWVq6uI98NaVOJZJnwK4Tr1NuJ4kaCADZtuCLOq1yzVX5MHMc= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231122_012954_952537_98CEF458 X-CRM114-Status: GOOD ( 12.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); } }