Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp204407lqe; Fri, 5 Apr 2024 19:27:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVp7xIpaybugn78CUtJBSn1SzlujzMXe8znVIphbwbgHso8Js/c7ELydZCqCMo6XjgDL+SbS2+ohZsIcqEt3l98RZ06XKFu1nlM7bYigA== X-Google-Smtp-Source: AGHT+IH4lGXPrDMaE/FKEEVyH5fTooemIYMf/eaU59hXApjp5eR+5jcdYExWWLJA6EB4XwCUj3TB X-Received: by 2002:a05:6402:5296:b0:568:9b14:d6c7 with SMTP id en22-20020a056402529600b005689b14d6c7mr3614348edb.16.1712370442074; Fri, 05 Apr 2024 19:27:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712370442; cv=pass; d=google.com; s=arc-20160816; b=Nfdxma86mU9AwfzG+YjjbnH6Gm9Di1FeuoK67J1mRuLalneVC2a4MOmRxzr6AzYnr8 iNZjAveQUEOxV5MwXqAxh20mbKyV7ErmKrxspwJ70lRcmqJt4El8j6gG3NS9oDDNBbVj zhRpdrTb9WNJUFJ+kL9hko19DQb8bpplbWgdGQHApjvblWvfgD+lDE0NPX5oFIzKWah7 37s9PAtDt/2GhTsCuMnW0w3yQFmMK1huFTCZrM2RF0VJ6cVsHA7ZyJ6kvxYHUvKGdAKJ L1Gg6UbcGkHfY3lu73DQF0NnxKhdWZ6/Kq/TVX91GkUqK6xdTmmcyT1QENhUUcSL54Df ARlQ== 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=LLCMAuT8XlxDFMChZ/O/Mte5wQ5d9/EwiR53zESodZU=; fh=bhqlPbXjHBxQzd6TvgdNdBs+Har8pRoecv6ZHfN2TWo=; b=wbC/ESqVQQZk+NYK+eXDPP78I31IDto6+1qEqzBZIsFAwKguM4DK9SEfO+tYJH/u6q 2YKnTENExIe92uWlpLt4m+Bnde0ugDMq37xin+sn1+WGB2eylI9xm2qNBK/qF8xtNj50 VlWI5X0b4wVA0kvJlBj5j8sbzHeThK2j7AcMNm3WfoYK47wO1I8VvD8M7M5UcL0Whbp+ S0gyBsfP8mt16xrxCEujIL0NcFR8uKdwtte3t34o/o8TmkyAr7pfAPK0DZVFH7dqE9sj pDn4LgRWwWYGLfk75RER/Iiqn0O+fcbmy/SbJJhy4UXXevqs4x85f+kY0ZgB6wieeFPX Os/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j36vr0q8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-133676-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133676-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g25-20020a50d5d9000000b0056c0d76d6c1si1278837edj.238.2024.04.05.19.27.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 19:27:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133676-linux.lists.archive=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=@intel.com header.s=Intel header.b=j36vr0q8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-133676-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133676-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7E2DB1F23B39 for ; Fri, 5 Apr 2024 22:29:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75E7517994E; Fri, 5 Apr 2024 22:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j36vr0q8" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 C994C17798A; Fri, 5 Apr 2024 22:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712356012; cv=none; b=rgqPFEaOdXVt12GrWrumzf/edA05bF7xwPMZO7S0REfOjl9ZN/vwCEgjzTk0oMsbtCfZCevONsFVZ/La0mTE1BHqGeLw6F+j/fL3EBXoV5wlFTQzVFmEs0GKHlSO8wShFhgBcpducesyrbkIt5U9TYUu+SS9HUYHoCURsT9iQ54= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712356012; c=relaxed/simple; bh=SZUjCrw1LUAiGX4RfPDzIUAm4sRy4Tpnthwda+0PrNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g5zAaGcrd66wBILX+LUa4Kni0MJrKP79ZDtuO2U351mJqYu2dJyki3vz0gyEaZKxNoSprb8HraIg/VoxHl1T/nOJW6bHvHADwUKgP3hq9ooeyHMJSSts+PuR0mzc/4JWd+pQC9ZkVWDUgbjVK1OWl1pvydbpoY2NfzheFLrh4AA= 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=j36vr0q8; arc=none smtp.client-ip=192.198.163.10 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=1712356011; x=1743892011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SZUjCrw1LUAiGX4RfPDzIUAm4sRy4Tpnthwda+0PrNE=; b=j36vr0q8zFUCTvwNm6J8ebuvCz4P0fungbfdjziywe9hesKnHFBzH0wV +zysY0hkaCCxsXIJbI0r0TRxkIkvRJPTt6RWqmg+K25ggBFssFOWt6P28 tyDHPuSRjxvplrKT+Hulxdq37unA+2DN0Lrtym8/feuKJH0cG5p1+ogrC nXbqRgd19P3CzTHl5IAkpIk7BhIXK5gpbgtdj5rel+U5/LfSRmlNWkNKv pNa6V3cubOXwzHfiafUhk3l/2LQ/wGUG73bf5jyDH4U9DK3V4N8dH29JD KwiTz2O2FOqyIi7bb1t6IiR5gCg7w1rtBFucG+3PBJRKaC7zt6neUnj6/ Q==; X-CSE-ConnectionGUID: Uf7U6SoAQh2pdlSs1KeB4g== X-CSE-MsgGUID: +k9FiiP/SNm0mjrHenEQZg== X-IronPort-AV: E=McAfee;i="6600,9927,11035"; a="19062748" X-IronPort-AV: E=Sophos;i="6.07,182,1708416000"; d="scan'208";a="19062748" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2024 15:26:49 -0700 X-CSE-ConnectionGUID: c7lY9DQnQJahb0u+aMx9BA== X-CSE-MsgGUID: kqbc0R3dTH+A67aTYnJJeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,182,1708416000"; d="scan'208";a="23928323" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by fmviesa004.fm.intel.com with ESMTP; 05 Apr 2024 15:26:48 -0700 From: Jacob Pan To: LKML , X86 Kernel , Peter Zijlstra , iommu@lists.linux.dev, Thomas Gleixner , "Lu Baolu" , kvm@vger.kernel.org, Dave Hansen , Joerg Roedel , "H. Peter Anvin" , "Borislav Petkov" , "Ingo Molnar" Cc: Paul Luse , Dan Williams , Jens Axboe , Raj Ashok , "Tian, Kevin" , maz@kernel.org, seanjc@google.com, "Robin Murphy" , jim.harris@samsung.com, a.manzanares@samsung.com, "Bjorn Helgaas" , guang.zeng@intel.com, robert.hoo.linux@gmail.com, Jacob Pan Subject: [PATCH v2 06/13] x86/irq: Set up per host CPU posted interrupt descriptors Date: Fri, 5 Apr 2024 15:31:03 -0700 Message-Id: <20240405223110.1609888-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240405223110.1609888-1-jacob.jun.pan@linux.intel.com> References: <20240405223110.1609888-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 To support posted MSIs, create a posted interrupt descriptor (PID) for each host CPU. Later on, when setting up IRQ CPU affinity, IOMMU's interrupt remapping table entry (IRTE) will point to the physical address of the matching CPU's PID. Each PID is initialized with the owner CPU's physical APICID as the destination. Originally-by: Thomas Gleixner Signed-off-by: Jacob Pan --- v2: Fix xAPIC destination ID assignment, Oliver Sang reported failture on system with x2apic optout BIOS option. --- arch/x86/include/asm/hardirq.h | 3 +++ arch/x86/include/asm/posted_intr.h | 7 +++++++ arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/irq.c | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h index fbc7722b87d1..01ea52859462 100644 --- a/arch/x86/include/asm/hardirq.h +++ b/arch/x86/include/asm/hardirq.h @@ -48,6 +48,9 @@ typedef struct { DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat); +#ifdef CONFIG_X86_POSTED_MSI +DECLARE_PER_CPU_ALIGNED(struct pi_desc, posted_interrupt_desc); +#endif #define __ARCH_IRQ_STAT #define inc_irq_stat(member) this_cpu_inc(irq_stat.member) diff --git a/arch/x86/include/asm/posted_intr.h b/arch/x86/include/asm/posted_intr.h index c682c41d4e44..4e5eea2d20e0 100644 --- a/arch/x86/include/asm/posted_intr.h +++ b/arch/x86/include/asm/posted_intr.h @@ -80,4 +80,11 @@ static inline bool pi_test_sn(struct pi_desc *pi_desc) return test_bit(POSTED_INTR_SN, (unsigned long *)&pi_desc->control); } +#ifdef CONFIG_X86_POSTED_MSI +extern void intel_posted_msi_init(void); + +#else +static inline void intel_posted_msi_init(void) {}; + +#endif /* X86_POSTED_MSI */ #endif /* _X86_POSTED_INTR_H */ diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 5c1e6d6be267..1a5fb657e1b6 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -68,6 +68,7 @@ #include #include #include +#include #include "cpu.h" @@ -2219,6 +2220,8 @@ void cpu_init(void) barrier(); x2apic_setup(); + + intel_posted_msi_init(); } mmgrab(&init_mm); diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index 35fde0107901..f39f6147104c 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define CREATE_TRACE_POINTS #include @@ -334,6 +336,27 @@ DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_nested_ipi) } #endif +#ifdef CONFIG_X86_POSTED_MSI + +/* Posted Interrupt Descriptors for coalesced MSIs to be posted */ +DEFINE_PER_CPU_ALIGNED(struct pi_desc, posted_interrupt_desc); + +void intel_posted_msi_init(void) +{ + u32 destination; + u32 apic_id; + + this_cpu_write(posted_interrupt_desc.nv, POSTED_MSI_NOTIFICATION_VECTOR); + + /* + * APIC destination ID is stored in bit 8:15 while in XAPIC mode. + * VT-d spec. CH 9.11 + */ + apic_id = this_cpu_read(x86_cpu_to_apicid); + destination = x2apic_enabled() ? apic_id : apic_id << 8; + this_cpu_write(posted_interrupt_desc.ndst, destination); +} +#endif /* X86_POSTED_MSI */ #ifdef CONFIG_HOTPLUG_CPU /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ -- 2.25.1