From patchwork Tue Nov 22 12:28:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 24337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2172257wrr; Tue, 22 Nov 2022 04:33:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6zt9NrbRWShlGsdnJTDTvSoVa4ZIc+f2HiecRwuSkzQrGe5xQLeeJwEDzAuvhwSM19wJ3Y X-Received: by 2002:a17:906:f8a:b0:7ad:9f03:aa1f with SMTP id q10-20020a1709060f8a00b007ad9f03aa1fmr19790477ejj.632.1669120382612; Tue, 22 Nov 2022 04:33:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669120382; cv=none; d=google.com; s=arc-20160816; b=MF5VvakBSFCug0WlvCrOt5oqh5W+UJ2TFDZEePvbXa6+05R1s6ApYNzIQHjJu6yMxi tI0EdyY5xfE8rcOsT3cN/a/aMgrtuZj0ZBOOlYl0cK2oMPnQ6z1XSLbZEDbuy3o8oZSJ Om+6sGIbu/kkGnGFi9nNdP6mt7c/iQGwlyf8bYY+DYssf2M5E7sJDC8OkE2TDljXY60K k5dFL7jGvABclpeohJtT/ofzxf1uJ7hQGSgSSebbhYCbEewXHTRYLvRjNmlRc7X+XOS2 rxgydtnnougUJdDPcJditYUDO8d7f4et7teojOfleA6ErPlt3ecSM25Uo4wftZn6RlyB y4nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=gMhYDeW6cO8i9Z//LZXm6hhlJ2+VSC3EwZFBBVTwq24=; b=bvEAGhyzaddLhmVeub6PHTdTVljcjtpd6EgTGmHqFimGRdiFs/uOMtBn1PERo0PNLG gjuw0dKHUl8AOKva0F4pTtNNTtsvVNgS4tuJkSw1ehyoPGzAb7xTX8K9EwfwpT75bR+M IFR77WFb84qzhEHlX2mfg1qEaBHWZWBZHevs4uXVpFa7HFS3GpfVkQRGvbpdEv2CeSss X05rzNDNp6+etqeKid2gubNo6CExShaIRZGmePdHpsgranu0Zf8YuHbNbBKMXgeEkwAo hjNjS/zs5bsSgYlQHTF+LtPn+g6NFDs/Vm9/cWry2dqtQgD12tzWbg1dUdRkqOnmvlKN 1HdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PxopwqDC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cih7vO3L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a056402511300b00458b42ff418si12539790edd.221.2022.11.22.04.32.29; Tue, 22 Nov 2022 04:33:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PxopwqDC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cih7vO3L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiKVM2b (ORCPT + 99 others); Tue, 22 Nov 2022 07:28:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233765AbiKVM20 (ORCPT ); Tue, 22 Nov 2022 07:28:26 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A3DC4C262; Tue, 22 Nov 2022 04:28:25 -0800 (PST) Date: Tue, 22 Nov 2022 12:28:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669120102; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gMhYDeW6cO8i9Z//LZXm6hhlJ2+VSC3EwZFBBVTwq24=; b=PxopwqDCvXYSeYW1C1FSrvHPY/c2Nipl1U4jazlsGG8GNcd4l2gFxNGvrhDg1Sk8IL/34s lfE+3gbkKanrahRQlkNsZzog4ELsXY86AP0W2awSujHclTXxyuh8KntugaduR0Wsq1oC2b btwofzNf7XMbqSWvVca0BLcBi2mfG1II/FDzinzvaFfmyofbbmYfaZQtxD1teHZnv8h2ip LDN+o3N1jHHok6vtpf/Az9KMx9HVdA+eIt2+dZbtCjbp81Ezvfo1PLSypJzhOQvrN+Pdqb yvCG7hsBojq2Sr5d3FaWH6tSu5QqTMMWBU+r5zxWHDB+Fsvdjf0Z68oyyHqo4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669120102; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gMhYDeW6cO8i9Z//LZXm6hhlJ2+VSC3EwZFBBVTwq24=; b=cih7vO3LYLTHmxiOw9QYg6hLazcc7dJXtpNOt/SH+f4IFcSwX6kCjSgjtkCDCqYRnCnqEN 8o/7FI52Kn1MRzAg== From: "tip-bot2 for Julian Pidancet" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/alternatives] x86/alternative: Consistently patch SMP locks in vmlinux and modules Cc: Julian Pidancet , Borislav Petkov , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221027204906.511277-1-julian.pidancet@oracle.com> References: <20221027204906.511277-1-julian.pidancet@oracle.com> MIME-Version: 1.0 Message-ID: <166912010097.4906.7346211098182590940.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747775490405095062?= X-GMAIL-MSGID: =?utf-8?q?1750199574554186038?= The following commit has been merged into the x86/alternatives branch of tip: Commit-ID: 0b1a2171551e05c45ad999e403272ddafa7286c8 Gitweb: https://git.kernel.org/tip/0b1a2171551e05c45ad999e403272ddafa7286c8 Author: Julian Pidancet AuthorDate: Thu, 27 Oct 2022 22:49:06 +02:00 Committer: Borislav Petkov CommitterDate: Tue, 22 Nov 2022 13:13:55 +01:00 x86/alternative: Consistently patch SMP locks in vmlinux and modules alternatives_smp_module_add() restricts patching of SMP lock prefixes to the text address range passed as an argument. For vmlinux, patching all the instructions located between the _text and _etext symbols is allowed. That includes the .text section but also other sections such as .text.hot and .text.unlikely. As per the comment inside the 'struct smp_alt_module' definition, the original purpose of this restriction is to avoid patching the init code because in the case when one boots with a single CPU, the LOCK prefixes to the locking primitives are removed. Later on, when other CPUs are onlined, those LOCK prefixes get added back in but by that time the .init code is very likely removed so patching that would be a bad idea. For modules, the current code only allows patching instructions located inside the .text segment, excluding other sections such as .text.hot or .text.unlikely, which may need patching. Make patching of the kernel core and modules more consistent by allowing all text sections of modules except .init.text to be patched in module_finalize(). For that, use mod->core_layout.base/mod->core_layout.text_size as the address range allowed to be patched, which include all the code sections except the init code. [ bp: Massage and expand commit message. ] Signed-off-by: Julian Pidancet Signed-off-by: Borislav Petkov Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20221027204906.511277-1-julian.pidancet@oracle.com --- arch/x86/kernel/module.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index c032edc..b1e6e45 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -251,14 +251,12 @@ int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *me) { - const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL, - *para = NULL, *orc = NULL, *orc_ip = NULL, - *retpolines = NULL, *returns = NULL, *ibt_endbr = NULL; + const Elf_Shdr *s, *alt = NULL, *locks = NULL, *para = NULL, + *orc = NULL, *orc_ip = NULL, *retpolines = NULL, + *returns = NULL, *ibt_endbr = NULL; char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) { - if (!strcmp(".text", secstrings + s->sh_name)) - text = s; if (!strcmp(".altinstructions", secstrings + s->sh_name)) alt = s; if (!strcmp(".smp_locks", secstrings + s->sh_name)) @@ -302,12 +300,13 @@ int module_finalize(const Elf_Ehdr *hdr, void *iseg = (void *)ibt_endbr->sh_addr; apply_ibt_endbr(iseg, iseg + ibt_endbr->sh_size); } - if (locks && text) { + if (locks) { void *lseg = (void *)locks->sh_addr; - void *tseg = (void *)text->sh_addr; + void *text = me->core_layout.base; + void *text_end = text + me->core_layout.text_size; alternatives_smp_module_add(me, me->name, lseg, lseg + locks->sh_size, - tseg, tseg + text->sh_size); + text, text_end); } if (orc && orc_ip)