Received: by 2002:ac2:48a3:0:0:0:0:0 with SMTP id u3csp568603lfg; Fri, 11 Mar 2022 13:34:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0YS9AR0vVeJolji9Puhhv92XL3wkWqEe3zxfMz5djKM991giqQ51RQS+Cp1ZNSoRdq0QE X-Received: by 2002:a17:903:1248:b0:151:9708:d586 with SMTP id u8-20020a170903124800b001519708d586mr12177096plh.15.1647034455673; Fri, 11 Mar 2022 13:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647034455; cv=none; d=google.com; s=arc-20160816; b=oPau+IdPCfP5y0/ZrwBoDRr4ORfpHoxQ7PlBL6NCKm3/ZZ7Ug57+eWajxsc+DbVce4 /2KutbIGrTqrxpvy3hPa90k3WYknT23rYe/7E9/0/ZFW9/EiF0RITTcUiAVlAhuBOmsG ZlmqFDtF4YqmvjNE5D0+zzm/JfI3gkPVujE7kaqezEMawHmAGzM1imCnE5fXcd/P4unS g1XDVgobYYgvuGPYaHOz04FDeVQPFGdFspBCGnyr6xkgFitJ12Lhk/Qd501yyPqrocEa Lry/ZqBfvq93sdwboj64Yo6/GKyEFkHSPDAo2isdYRBJNn+pbmyFqv8MqcMCMSLlnT9a ZUng== 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=d31r8wTn8h3Sl16eJtem9/DzCXEnrJZYgsbgAyz5g0M=; b=wa60pOehwv0xe34kMTNdf25aWLj/Q7tIEmF7JuX6Xdx1RUM1tgRhrsHZjxzQtBgIoZ HoQmPbnYffKQqFLuvCoybiqrpsY1qKjs2+To5iV11CgmZV71O3lfEU11Lk+X+VzUNKiA T27JvCQmoYW5m1fgZmsOmdU8gE7pM3Ctl97P8pIKTDqeuxOwpDWTzM+M/NDuyOFAnzdE JlD9bufXaZ/AUv2YteOeyerbc/ziESy5c3u28YfANP93wlIdsk1vAbV4XbGkhsDV+Grz atodAmnbtwg1fmHYEft8nOiVmez9B/Ha3Bi8PkSVzIyxLu5Tr35wdTX+MDNvI2p9xgVF dZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JqSJtnkg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t2-20020a17090a3e4200b001bd59aded80si8675377pjm.100.2022.03.11.13.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 13:34:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JqSJtnkg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76C3D10613F; Fri, 11 Mar 2022 13:03:17 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349806AbiCKOms (ORCPT + 99 others); Fri, 11 Mar 2022 09:42:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346607AbiCKOm3 (ORCPT ); Fri, 11 Mar 2022 09:42:29 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61E18CDBF; Fri, 11 Mar 2022 06:40:58 -0800 (PST) Date: Fri, 11 Mar 2022 14:40:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647009657; 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=d31r8wTn8h3Sl16eJtem9/DzCXEnrJZYgsbgAyz5g0M=; b=JqSJtnkgkbjOIO9yScpX07mC6JY6mRkfFHoCyFKdra20jradN1y2X14ysHd0gOcpP04lP+ QFdD4f8HCuSBB58LnJyJ5kBC+8+VYmD6B/fz1HB1aL0BNY9yUm+1kVZPSOKLHTnbnaT8nH D5zXB02ATGmUYPGg0mIOF4U412vS5shMVADzX09ce2cyPjKOUyQLoAQwCJdeOX2AvwLFNm aeSfLW/9EYdqrwyraBj6aGWP/ZbcHy0i7pRwqKUMZz7VX5H6ypW0VjRvK5KK17KWHvdwiv ggyXxwyRYxpBcH4aQf0RAS0Ley1Y6Faw/UAVdgX7zWcGdJooJ8L5k81LMoASzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647009657; 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=d31r8wTn8h3Sl16eJtem9/DzCXEnrJZYgsbgAyz5g0M=; b=/1ewpK7i9vAF7LrR8bPHYqSvxcNmHm6GxTBwS5NImT7QHpC3NK0G3nrHZ0Dm+nGCLU9gYE GN0ChRpjqUbia/Dw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86: Fix {int3,ibt}_selftest() vs LTO Cc: Nick Desaulniers , David Laight , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <164700965635.16921.2130693129403753558.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 The following commit has been merged into the x86/core branch of tip: Commit-ID: c7d90e15b8950009d0d4e8f3503b09b2ea6d527c Gitweb: https://git.kernel.org/tip/c7d90e15b8950009d0d4e8f3503b09b2ea6d527c Author: Peter Zijlstra AuthorDate: Thu, 10 Mar 2022 11:16:03 +01:00 Committer: Peter Zijlstra CommitterDate: Fri, 11 Mar 2022 13:05:08 +01:00 x86: Fix {int3,ibt}_selftest() vs LTO Both these selftests define a symbol in inline asm which goes side-ways if the asm gets duplicated due to inlining. Nick actually saw this happen with a Clang LTO build. Mark the two selftests noinline to ensure this cannot happen, as suggestd by David. While there, update the comment for int3_selftest() and increase coding style consistency between the two. Fixes: 103c0093ceb6 ("x86/ibt: Add IBT feature, MSR and #CP handling") Reported-by: Nick Desaulniers Suggested-by: David Laight , Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers # llvm build, non-IBT boot Link: https://lkml.kernel.org/r/YinP49gEl2zUVekz@hirez.programming.kicks-ass.net --- arch/x86/kernel/alternative.c | 8 ++++---- arch/x86/kernel/traps.c | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d6c41f8..820c43a 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -781,7 +781,8 @@ int3_exception_notify(struct notifier_block *self, unsigned long val, void *data return NOTIFY_STOP; } -static void __init int3_selftest(void) +/* Must be noinline to ensure uniqueness of int3_selftest_ip. */ +static noinline void __init int3_selftest(void) { static __initdata struct notifier_block int3_exception_nb = { .notifier_call = int3_exception_notify, @@ -794,9 +795,8 @@ static void __init int3_selftest(void) /* * Basically: int3_magic(&val); but really complicated :-) * - * Stick the address of the INT3 instruction into int3_selftest_ip, - * then trigger the INT3, padded with NOPs to match a CALL instruction - * length. + * INT3 padded with NOP to CALL_INSN_SIZE. The int3_exception_nb + * notifier above will emulate CALL for us. */ asm volatile ("int3_selftest_ip:\n\t" ANNOTATE_NOENDBR diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 89fb299..755c23b 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -213,7 +213,7 @@ DEFINE_IDTENTRY(exc_overflow) static __ro_after_init bool ibt_fatal = true; -void ibt_selftest_ip(void); /* code label defined in asm below */ +extern void ibt_selftest_ip(void); /* code label defined in asm below */ enum cp_error_code { CP_EC = (1 << 15) - 1, @@ -237,7 +237,7 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) if (WARN_ON_ONCE(user_mode(regs) || (error_code & CP_EC) != CP_ENDBR)) return; - if (unlikely(regs->ip == (unsigned long)ibt_selftest_ip)) { + if (unlikely(regs->ip == (unsigned long)&ibt_selftest_ip)) { regs->ax = 0; return; } @@ -251,7 +251,8 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) BUG(); } -bool ibt_selftest(void) +/* Must be noinline to ensure uniqueness of ibt_selftest_ip. */ +noinline bool ibt_selftest(void) { unsigned long ret;