From patchwork Wed Jan 31 07:21:12 2024 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: 194547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1722505dyb; Tue, 30 Jan 2024 23:23:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMYeBhDYcpYRG6kmr3xsvbILjc3ihu9mYKzgubG+3KsdvQtKyVBjnt2OmtbLTl9EKa4GDw X-Received: by 2002:aa7:cfc3:0:b0:55e:deca:c46f with SMTP id r3-20020aa7cfc3000000b0055edecac46fmr470884edy.16.1706685824502; Tue, 30 Jan 2024 23:23:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706685824; cv=pass; d=google.com; s=arc-20160816; b=sE8scqmxf55mE7BVFQIwqBvpGkrS6R8F5B9n+ipG73ddHc75FCAoDYKKrxdt3JykxE hl5OnCu8FDReNotrzN+qm9V6UW1JRmas+QPHFLhpETihaGKW1vzMmdBE0QlYCZjXpqQ7 b2UaPsvcHI6ZVmmHxteb0fstgciJFzy98pGj2inHZob9QwNyvKdNoa+5QjEwrkNYhz2f eejA4xz4idZD7n8gvWV5kVzCZuiAtfTlymSA0okC0ivDdmlyy1IU5scSfxjJ7Ip95mQK uvlHzDdoFFRc7Bska8RFbHyoq5pKbZJIJkMvnE/lHpzaGroFErkAE5Y76HQu6Kor2Kmj UEzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=gO6FmRQ/6qkXrVZgXxQqaUicH/UR4aEHfbZ1mLsB7W8=; fh=sWVV2dOVLUYfA8K2bFnW+/c3Sk7WXMOkQc4MhhOM//I=; b=00BBQVpMXXCGWvYIRRAFlDxqvN6jINTvkzpZWU6jxvAdcnQ7UxneBoqr3PVL77q2b4 Bej3rbFYHtDIYMZFLz/0XqGzauT8A6WVnrU+9gxRJqrZNIU4mQ1nSaQBiymdmEeozF+s LiWeJONcOnn89jSBaTtrd9PNCxU2GxLjQfT4TfcCfNyf9y9Y23/zGoTIN4mxkSOwcWIz Wo2BQ608v/i77HGcn1sAiVydGD1hO42xVXnWjlOfE7CSLKoe+1MK4PwZokeW+dZO9N1F B0C5dNyDIgbGP2LEB8pGEJO5DwsdnXtTHJm0LxcDfGvU8axM7Ilmt2jSTZ4E3GQZsG6j +9qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uw9zDhLZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=gGKXNg09; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-45899-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45899-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCV4ksNadxUt7OXeCXAh7kNStK/mmSOnmy97gyKbgc/Rsu7ghvlmOPduHZE2u0h4m/ER+ToFJewu4vKjr4a3tMWmXJhU3A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g17-20020a0564021ed100b0055f2be34e20si1942530edg.138.2024.01.30.23.23.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 23:23:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45899-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uw9zDhLZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=gGKXNg09; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-45899-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45899-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 am.mirrors.kernel.org (Postfix) with ESMTPS id F1B1C1F2661F for ; Wed, 31 Jan 2024 07:23:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 314BF54BD3; Wed, 31 Jan 2024 07:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uw9zDhLZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gGKXNg09" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9F2B45EE6D; Wed, 31 Jan 2024 07:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706685677; cv=none; b=gqY2YHECAsorbIo0c4i/GjZVcSM9VnHf+Ljc3/HIs6vXw0cRjwXyNT2u9FhkU9P0zfRdz9nWSU7vrmpC0H5Ncllj1aLChy49JMrZSKSThrznOmzNUa3haUgbPdtTP2DErbXpdiKsSCUGNdbpIOheqb9nnhO+7iX+8w9TlVcH1fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706685677; c=relaxed/simple; bh=6+F1hPsoJtpa7g87qGqwoWZc8GuOf2GdIoO7utlDpeU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Z8wupAzIjPFxs74RpQQn9uiXodWsFIlk9tmJk4qCuvuebcoAzE5H+aC3YKOCsmPmYguOddcNebgq80rU1GfSXfLExz6YfKqR6bvUgv7QcQ80j7RV/vRexvEEZjET3IfBhY5UoY13eOKsvbiuuMrWzSwzB/s0dXK3gchivYPjws0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uw9zDhLZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gGKXNg09; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 31 Jan 2024 07:21:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706685674; 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=gO6FmRQ/6qkXrVZgXxQqaUicH/UR4aEHfbZ1mLsB7W8=; b=uw9zDhLZcKGjfVZ0pl/6f0hPQkgl1KnsUUzIKJC4T2j2TAVzBP6Tv+oUzgajkWCWiSzox0 U6W4iJrQDyohCy15jrbfroWez64O7x85Uo98zQMD01lAr1wdAZESdwO+XkaaA+SGkMhbaW 4zbxOwe3o46dpqy9IRs5aDbqZzh5RSCUegA3heP5g3t+r6qHt5/rA3aJQgYXl0RXSTHiFO zWePXIl4r3ykr0UBGCNJf/wTasMvj/6IehacEyxC+E9NQ3u6NTjXi6EYSfVop6p4Rgg8qr MeBEAsvU2MX8Ax2BVPc0tX+7sJDValWPkUz7kZqX9z8U0wgWds9sBf9sFVw0Mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706685674; 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=gO6FmRQ/6qkXrVZgXxQqaUicH/UR4aEHfbZ1mLsB7W8=; b=gGKXNg09sTs7ho8xBIXjON7PrTAg7uDQ/gvftoYfFj5AcB24tYx+zOPCIVmoBxueN9T28W 1SQiB33gt+M8YxBA== From: "tip-bot2 for Xin Li" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/traps: Add sysvec_install() to install a system interrupt handler Cc: Xin Li , Thomas Gleixner , Shan Kang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231205105030.8698-28-xin3.li@intel.com> References: <20231205105030.8698-28-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170668567256.398.1219856927168401142.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440842795804067 X-GMAIL-MSGID: 1789589794968571374 The following commit has been merged into the x86/fred branch of tip: Commit-ID: db7c787d8ba268a8d8beabb0027715246375c6e0 Gitweb: https://git.kernel.org/tip/db7c787d8ba268a8d8beabb0027715246375c6e0 Author: Xin Li AuthorDate: Tue, 05 Dec 2023 02:50:16 -08:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 30 Jan 2024 18:20:35 +01:00 x86/traps: Add sysvec_install() to install a system interrupt handler Add sysvec_install() to install a system interrupt handler into the IDT or the FRED system interrupt handler table. Signed-off-by: Xin Li Signed-off-by: Thomas Gleixner Tested-by: Shan Kang Link: https://lore.kernel.org/r/20231205105030.8698-28-xin3.li@intel.com --- arch/x86/entry/entry_fred.c | 14 ++++++++++++++ arch/x86/include/asm/desc.h | 2 -- arch/x86/include/asm/idtentry.h | 15 +++++++++++++++ arch/x86/kernel/cpu/acrn.c | 4 ++-- arch/x86/kernel/cpu/mshyperv.c | 15 +++++++-------- arch/x86/kernel/idt.c | 4 ++-- arch/x86/kernel/kvm.c | 2 +- drivers/xen/events/events_base.c | 2 +- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c index 125b623..3be0269 100644 --- a/arch/x86/entry/entry_fred.c +++ b/arch/x86/entry/entry_fred.c @@ -119,6 +119,20 @@ static idtentry_t sysvec_table[NR_SYSTEM_VECTORS] __ro_after_init = { SYSVEC(POSTED_INTR_NESTED_VECTOR, kvm_posted_intr_nested_ipi), }; +static bool fred_setup_done __initdata; + +void __init fred_install_sysvec(unsigned int sysvec, idtentry_t handler) +{ + if (WARN_ON_ONCE(sysvec < FIRST_SYSTEM_VECTOR)) + return; + + if (WARN_ON_ONCE(fred_setup_done)) + return; + + if (!WARN_ON_ONCE(sysvec_table[sysvec - FIRST_SYSTEM_VECTOR])) + sysvec_table[sysvec - FIRST_SYSTEM_VECTOR] = handler; +} + static noinstr void fred_extint(struct pt_regs *regs) { unsigned int vector = regs->fred_ss.vector; diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index ab97b22..ec95fe4 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -402,8 +402,6 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit) desc->limit1 = (limit >> 16) & 0xf; } -void alloc_intr_gate(unsigned int n, const void *addr); - static inline void init_idt_data(struct idt_data *data, unsigned int n, const void *addr) { diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 570f286..47d4c04 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -459,6 +459,21 @@ __visible noinstr void func(struct pt_regs *regs, \ #define DEFINE_FREDENTRY_DEBUG DEFINE_FREDENTRY_RAW #endif +void idt_install_sysvec(unsigned int n, const void *function); + +#ifdef CONFIG_X86_FRED +void fred_install_sysvec(unsigned int vector, const idtentry_t function); +#else +static inline void fred_install_sysvec(unsigned int vector, const idtentry_t function) { } +#endif + +#define sysvec_install(vector, function) { \ + if (cpu_feature_enabled(X86_FEATURE_FRED)) \ + fred_install_sysvec(vector, function); \ + else \ + idt_install_sysvec(vector, asm_##function); \ +} + #else /* !__ASSEMBLY__ */ /* diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c index bfeb18f..2c5b51a 100644 --- a/arch/x86/kernel/cpu/acrn.c +++ b/arch/x86/kernel/cpu/acrn.c @@ -26,8 +26,8 @@ static u32 __init acrn_detect(void) static void __init acrn_init_platform(void) { - /* Setup the IDT for ACRN hypervisor callback */ - alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback); + /* Install system interrupt handler for ACRN hypervisor callback */ + sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callback); x86_platform.calibrate_tsc = acrn_get_tsc_khz; x86_platform.calibrate_cpu = acrn_get_tsc_khz; diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 01fa06d..45e0e70 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -539,19 +539,18 @@ static void __init ms_hyperv_init_platform(void) */ x86_platform.apic_post_init = hyperv_init; hyperv_setup_mmu_ops(); - /* Setup the IDT for hypervisor callback */ - alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_hyperv_callback); - /* Setup the IDT for reenlightenment notifications */ + /* Install system interrupt handler for hypervisor callback */ + sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback); + + /* Install system interrupt handler for reenlightenment notifications */ if (ms_hyperv.features & HV_ACCESS_REENLIGHTENMENT) { - alloc_intr_gate(HYPERV_REENLIGHTENMENT_VECTOR, - asm_sysvec_hyperv_reenlightenment); + sysvec_install(HYPERV_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment); } - /* Setup the IDT for stimer0 */ + /* Install system interrupt handler for stimer0 */ if (ms_hyperv.misc_features & HV_STIMER_DIRECT_MODE_AVAILABLE) { - alloc_intr_gate(HYPERV_STIMER0_VECTOR, - asm_sysvec_hyperv_stimer0); + sysvec_install(HYPERV_STIMER0_VECTOR, sysvec_hyperv_stimer0); } # ifdef CONFIG_SMP diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index 660b601..0cd53fa 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -337,7 +337,7 @@ void idt_invalidate(void) load_idt(&idt); } -void __init alloc_intr_gate(unsigned int n, const void *addr) +void __init idt_install_sysvec(unsigned int n, const void *function) { if (WARN_ON(n < FIRST_SYSTEM_VECTOR)) return; @@ -346,5 +346,5 @@ void __init alloc_intr_gate(unsigned int n, const void *addr) return; if (!WARN_ON(test_and_set_bit(n, system_vectors))) - set_intr_gate(n, addr); + set_intr_gate(n, function); } diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index dfe9945..b055579 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -829,7 +829,7 @@ static void __init kvm_guest_init(void) if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF_INT) && kvmapf) { static_branch_enable(&kvm_async_pf_enabled); - alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_kvm_asyncpf_interrupt); + sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_kvm_asyncpf_interrupt); } #ifdef CONFIG_SMP diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c index b8cfea7..e2813ba 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -2216,7 +2216,7 @@ static __init void xen_alloc_callback_vector(void) return; pr_info("Xen HVM callback vector for event delivery is enabled\n"); - alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_xen_hvm_callback); + sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_xen_hvm_callback); } #else void xen_setup_callback_vector(void) {}