Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp881472lqb; Wed, 29 May 2024 13:28:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbx4AhU9kj0ejoIf5mnYISHMh/HQiki4QOb8RIxue+49Mct1vlirYdYcjeBdXLw+N44NZil65ojq67EXCXsMSumMJQpr5LsUwWlxr1iQ== X-Google-Smtp-Source: AGHT+IHM9fHHf/fBZDLaENS9L6emwba3T7qxrgEAbkYHWPQ098rPgpa2g96qKVibYZuGLMHZyALK X-Received: by 2002:a05:620a:4714:b0:792:95cf:99fc with SMTP id af79cd13be357-794e9e1ebecmr34396485a.62.1717014536032; Wed, 29 May 2024 13:28:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717014536; cv=pass; d=google.com; s=arc-20160816; b=GdoTS3tSx0RQC/j9dptiKPuvvtCiECh7HdB7KGAjIeGZWhuXUUJpqeFD97Q2ttJ32H 7tCBQD1+jlW3XzmW9D2gcZZ+KHYBqkwqrg/jbhuNcqJG2zvNCRisBCNALeeWO/e63occ 4jPo6ZyiF2IGmJtJSc2KkaZ2Mmiz8yn4PHBJ2malR5sVjXwdI9rSGBnH5U1N3v/JNlQ9 YWaFsiwGwz1Lv+Ky5gLJW5aoxUJZKUdFc+Mtnt3gjPfu6BSYWe1Qh6YGBB9pVO382asl U3xvIK1TlqOZh+pSScx5QtVzIvCMUjqtxrgvmM2nfLJ7IFDpwMChTjQUuKEM8lvhA7xF yFBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DpTZuHsN5rKGqRWk79TbzQyj3wDJPSN3rFajZci1qLI=; fh=fZepo/0slYBt9k/m8d9e8DJ82HBaU39Epa4sDwEDWNU=; b=Ebuz2I1/C1pO1kGPfRsk+abj+tUW/ktwit4WaM5weTsZCzwvemM3n2hMPMmojDwn3K sLw8v3vkJKBmSo5EumRDJm1aIVP1BYhKGQU/5d7WZeO0UVuBEZXVysaGsK2mDyYddqA6 CfoLeO59szOt8lFxmyiloVbxdknZQnHs1/NGAGe3Mog9VC/Hv3ODmu5A8176KelTtgxn Nh4gRNV8DT0oizaBm9zSsZ+NkRhiuRUkE1jU49amUPbMq2AYixCbgQibLMj2my8RvKO1 z4uBdt7eADoO309MsUfGuG8nlkoSNMcIv5r9QsPzkvqbcr5xM7oAxiYtbWCjaMTj/ayu 9Esw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WvmBMDnE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-194654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194654-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abcaba05si1334861285a.93.2024.05.29.13.28.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 13:28:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WvmBMDnE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-194654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194654-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 948D91C223E4 for ; Wed, 29 May 2024 20:28:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFC421C8FC9; Wed, 29 May 2024 20:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WvmBMDnE" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6A31C68B4; Wed, 29 May 2024 20:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717014516; cv=none; b=bZLX9mNgaV2gNzx0VjxuQpdZ0CG1aiOPfAgMwApAe8WT85Vhc6YOi2+E/b3urhcgqzZYMbGAql73iUD65Gy6kKaqwHlhpGXtWSvIml1bsaYfSs5b/pmWuJHrsZeR+ovndAQflzqfbXa4RWIQFr8tQqvaLJT9kxo6MKhWsNh3kJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717014516; c=relaxed/simple; bh=dSqou1KOvj6VEChE+4XJ6rK/xivwkSVK7t0PEao7PtQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N8+NvCpBXr2Yqx3P9VQ00EJLpgcbKS8iFi1PgUGtOe/xOV8TeAaSNKiOIoWWLBuBPKCj0i3jukE4xcrHrk9PuWeFLSYBaQN+H9szSipE3tjTB53TtXQ0FmIasC8k9G8GhgAcaNKgcihIplVvEoHoRwZIBLDDCh2z4Pp/C851wFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WvmBMDnE; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717014515; x=1748550515; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dSqou1KOvj6VEChE+4XJ6rK/xivwkSVK7t0PEao7PtQ=; b=WvmBMDnExqAbG9WrhC/lfNvA7d9xkqVCnkfd6r4qj8pHhyv8GiuIRKoA fqh003oC3x0tdCnOHMO3ep107qalpo38TS9xMij6I7q1/b3+cOoq86GcL 8mhu0y6EVtC0mNCF89cSFs39Okf/SR2PwEO3dFQrSwoQKGPG6+87yPPeF QCKhNMzpoVriLer8reyeNpFlp51oB2gp5HelAKyTje7atXk27faK8vc+e htgeZPUZySWvqqfweE3JJlSL/8o1VhYtXKY6eFuTEzkKPU+0Y6qxnvrzr B/jEn3cXYMzQw5OgpmkAgAZz3tUgu2QXxBvMHBynnSnhbcs3gwhHb70es w==; X-CSE-ConnectionGUID: fsgGmAEdQSiUq9r1flJNJQ== X-CSE-MsgGUID: bM9p2GDxT1+OEM6sZoyNaQ== X-IronPort-AV: E=McAfee;i="6600,9927,11087"; a="13574527" X-IronPort-AV: E=Sophos;i="6.08,199,1712646000"; d="scan'208";a="13574527" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2024 13:28:32 -0700 X-CSE-ConnectionGUID: CoBr3p4CRT2E4CYboQLtWA== X-CSE-MsgGUID: Ln1ZCyiKTjO2S3SDc3NfrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,199,1712646000"; d="scan'208";a="35491264" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by fmviesa007.fm.intel.com with ESMTP; 29 May 2024 13:28:32 -0700 From: Jacob Pan To: X86 Kernel , LKML , Thomas Gleixner , Dave Hansen , "H. Peter Anvin" , "Ingo Molnar" , "Borislav Petkov" , linux-perf-users@vger.kernel.org, Peter Zijlstra Cc: Andi Kleen , "Xin Li" , Jacob Pan Subject: [PATCH 1/6] x86/irq: Add enumeration of NMI source reporting CPU feature Date: Wed, 29 May 2024 13:33:20 -0700 Message-Id: <20240529203325.3039243-2-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240529203325.3039243-1-jacob.jun.pan@linux.intel.com> References: <20240529203325.3039243-1-jacob.jun.pan@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The lack of a mechanism to pinpoint the origins of Non-Maskable Interrupts (NMIs) necessitates that the NMI vector 2 handler consults each NMI source handler individually. This approach leads to inefficiencies, delays, and the occurrence of unnecessary NMIs, thereby also constraining the potential applications of NMIs. A new CPU feature, known as NMI source reporting, has been introduced as part of the Flexible Return and Event Delivery (FRED) spec. This feature enables the NMI vector 2 handler to directly obtain information about the NMI source from the FRED event data. The functionality of NMI source reporting is tied to the FRED. Although it is enumerated by a unique CPUID feature bit, it cannot be turned off independently once FRED is activated. Signed-off-by: Jacob Pan --- arch/x86/Kconfig | 9 +++++++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/kernel/cpu/cpuid-deps.c | 1 + arch/x86/kernel/traps.c | 4 +++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1d7122a1883e..b8b15f20b94e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -511,12 +511,21 @@ config X86_CPU_RESCTRL config X86_FRED bool "Flexible Return and Event Delivery" depends on X86_64 + select X86_NMI_SOURCE help When enabled, try to use Flexible Return and Event Delivery instead of the legacy SYSCALL/SYSENTER/IDT architecture for ring transitions and exception/interrupt handling if the system supports it. +config X86_NMI_SOURCE + def_bool n + help + Once enabled, information on NMI originator/source can be provided + via FRED event data. This makes NMI processing more efficient in that + NMI handler does not need to check for every possible source at + runtime when NMI is delivered. + config X86_BIGSMP bool "Support for big SMP systems with more than 8 CPUs" depends on SMP && X86_32 diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 3c7434329661..ec78d361e685 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -327,6 +327,7 @@ #define X86_FEATURE_FRED (12*32+17) /* Flexible Return and Event Delivery */ #define X86_FEATURE_LKGS (12*32+18) /* "" Load "kernel" (userspace) GS */ #define X86_FEATURE_WRMSRNS (12*32+19) /* "" Non-serializing WRMSR */ +#define X86_FEATURE_NMI_SOURCE (12*32+20) /* NMI source reporting */ #define X86_FEATURE_AMX_FP16 (12*32+21) /* "" AMX fp16 Support */ #define X86_FEATURE_AVX_IFMA (12*32+23) /* "" Support for VPMADD52[H,L]UQ */ #define X86_FEATURE_LAM (12*32+26) /* Linear Address Masking */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index c492bdc97b05..3856c4737d65 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -123,6 +123,12 @@ # define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31)) #endif +#ifdef CONFIG_X86_NMI_SOURCE +# define DISABLE_NMI_SOURCE 0 +#else +# define DISABLE_NMI_SOURCE (1 << (X86_FEATURE_NMI_SOURCE & 31)) +#endif + #ifdef CONFIG_KVM_AMD_SEV #define DISABLE_SEV_SNP 0 #else @@ -145,7 +151,7 @@ #define DISABLED_MASK10 0 #define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \ DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK) -#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM) +#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM|DISABLE_NMI_SOURCE) #define DISABLED_MASK13 0 #define DISABLED_MASK14 0 #define DISABLED_MASK15 0 diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index b7d9f530ae16..3f1a1a1961fa 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -84,6 +84,7 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_SHSTK, X86_FEATURE_XSAVES }, { X86_FEATURE_FRED, X86_FEATURE_LKGS }, { X86_FEATURE_FRED, X86_FEATURE_WRMSRNS }, + { X86_FEATURE_FRED, X86_FEATURE_NMI_SOURCE}, {} }; diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 4fa0b17e5043..465f04e4a79f 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -1427,8 +1427,10 @@ early_param("fred", fred_setup); void __init trap_init(void) { - if (cpu_feature_enabled(X86_FEATURE_FRED) && !enable_fred) + if (cpu_feature_enabled(X86_FEATURE_FRED) && !enable_fred) { setup_clear_cpu_cap(X86_FEATURE_FRED); + setup_clear_cpu_cap(X86_FEATURE_NMI_SOURCE); + } /* Init cpu_entry_area before IST entries are set up */ setup_cpu_entry_areas(); -- 2.25.1