Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp59093lqd; Tue, 23 Apr 2024 14:43:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6watHClRnmCm4/+u4R6y0i5oCvqE4t1TchxAioLMMe8zrNiBaX/ICh043qAfqjTKT3h1LouQL6jd9DXhPpfJ/BxM0TcQl8e5rYgG1aw== X-Google-Smtp-Source: AGHT+IEJ8K2NnseDmZyZ9jFLPu0CSTxmHXBAJGWHTnYKQ/pbeqprBN1ZTfCW3d0VaYPjdGuz0Sds X-Received: by 2002:a05:6e02:1b0e:b0:36a:1104:2d6e with SMTP id i14-20020a056e021b0e00b0036a11042d6emr997779ilv.1.1713908591574; Tue, 23 Apr 2024 14:43:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713908591; cv=pass; d=google.com; s=arc-20160816; b=mN0QJGxhnZrVes0lzG0vJVPGYkKKk7RvWMenW3e6K3xyen5X5zfRYEsBHkwlN5BVEs /312honUs8BHtiP4cqOEtXR1L+JTprT6OSOdmhE5fIENv7MzYbaxrYpOZKI+pomagHBb dWsWEYQNdUOAJU9LaPhkYgKgSp1qDl32GwxrIuCsbbMnpbcQjxO9c3cF5nx3Og/AUeqA JUwOvxF0bMw22PtVYckJW1Ps5h52Kt8o6u0Vce5ZEBuoqcIQ7isVVWUJynT70aZkT480 sBBDm4qoKGFj/XTbEg9Gl3Hxl3JZdlaODQYUE6qzWbgt1MOFcB8+oE6xOysntFE6Efml Yv2w== 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=o/Xt+nnMTHpfd1SZJptII+Z46rZEFk3uaKK07C7RzrA=; fh=4IBoZs+3h6h6AGI2zwHuwus2k8ZfhluO5SikKfX3GCM=; b=x6gcCOiDEZ2IYEDRZMviZ1n548WAqe4BIEIyQEExczqJFCXzsul+xlBWIDxFwyrH0n dT90xhQyEyl2694g/Mgb4wWBh34NoJZXgH/aVkKOLAhNRmGdcqkf67sssw6DHBYtdx14 xQXzJZj0O1h94rRAHItBV/lWtw7cJXsnUkdN3H5DRPO/mFoN0E9JhjP7wStRrKFTbHDR Ks6vCNOUIR4fNHFA9Cb4hjoqK8QCKYoctO8IKRGH1NnDP4EFdCnG40Ry++FmxnYGuc6d puNPQKoX4+Y/1VGWQy8x88cGInMDV740fQr53RtHho4aij36X4Nya+Gha6vGMLDwlCJW FgBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MDQRfFUP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-155688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bw12-20020a056a02048c00b005fd897b9493si5831232pgb.861.2024.04.23.14.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 14:43:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MDQRfFUP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-155688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155688-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F067128AB8B for ; Tue, 23 Apr 2024 17:38:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5445F142624; Tue, 23 Apr 2024 17:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MDQRfFUP" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 CA3DC1422C4; Tue, 23 Apr 2024 17:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713893812; cv=none; b=EGUAVvBfzqBAUMiAHeQcqtNAO/HGLZr3zJZoeKGKCu+ogYPMYMWl9Z4fZjz11vvKlZu0DEYdA53TN7rblMcq7CE04PymDZAdApdI/A4nJrDv51y+NTBmQsL5aOu0mkDZXTwUQ3Vy012ckV9vU32L3E9V3Npb97wXug8mHFcyBWU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713893812; c=relaxed/simple; bh=0/U+YELiuj5g/GjoG92UbXxnUKLMjYMQutBYyDFxAhY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bmhuXvhmxH/5N89q8cV0ueAttTl1Ew+K8PrfgHV5xmHuR02odAzTGM5DL3s7SQHPQA09Bo70XO4vL6UFPVmpzOOo+Ep81pdSfjS590lVYaF36ODIoJodeuOleRzruQuOsfoanj3KdBWKD/ix60ZYkI/th68ayWyd/WgS0nYi9K8= 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=MDQRfFUP; arc=none smtp.client-ip=192.198.163.14 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=1713893811; x=1745429811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0/U+YELiuj5g/GjoG92UbXxnUKLMjYMQutBYyDFxAhY=; b=MDQRfFUP4+Ssqv6v2GYh3iBS2QbJfn5MRTnHDewD38IZRfkrt+0nN0ge 45/Xgt8V1hS1MXVQFeVaXLl7i99/V9ZIZZR8U/qwaIzHRlgUkU51lLMNg E7s70y/HB0AY2tgd01Y7cHEhb+9gb/foU/fJjC9QMHGjiiJvgUlVuapnC x6ryPXdU+RSMK2q/fdLsrZO3tCHGIfDzD8/G7F15mCnm0QwLBNEMYmI/w pKUiflpDl2dwHVJAmgOk23Gtz+4w8JFwKd0IFNa3ColCQrVol0l0gUkio 4hUYkf5eqbFNZOUhtsTprcGFwX40LMPSar/EP60NqhEHhU8NXs799y8Hl g==; X-CSE-ConnectionGUID: iXhIyT5OQaaHP4zpFkYJ3Q== X-CSE-MsgGUID: iEOgEvhwT2a3LgfmH966xg== X-IronPort-AV: E=McAfee;i="6600,9927,11053"; a="9712404" X-IronPort-AV: E=Sophos;i="6.07,222,1708416000"; d="scan'208";a="9712404" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2024 10:36:44 -0700 X-CSE-ConnectionGUID: lXFAGWmhRbKmIpvscpz2CA== X-CSE-MsgGUID: PkCcphDSRou6pvokaPlNxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,222,1708416000"; d="scan'208";a="29097423" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by fmviesa004.fm.intel.com with ESMTP; 23 Apr 2024 10:36:42 -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, oliver.sang@intel.com, acme@kernel.org, Jacob Pan Subject: [PATCH v3 06/12] x86/irq: Set up per host CPU posted interrupt descriptors Date: Tue, 23 Apr 2024 10:41:08 -0700 Message-Id: <20240423174114.526704-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240423174114.526704-1-jacob.jun.pan@linux.intel.com> References: <20240423174114.526704-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 --- v3: Rename per CPU PID for posted MSI from pi_desc to posted_msi_pi_desc 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 | 6 ++++++ arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/irq.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h index fbc7722b87d1..e7ab594b3a7a 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_msi_pi_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 20e31891de15..6f84f6739d99 100644 --- a/arch/x86/include/asm/posted_intr.h +++ b/arch/x86/include/asm/posted_intr.h @@ -91,4 +91,10 @@ static inline void __pi_clear_sn(struct pi_desc *pi_desc) pi_desc->notifications &= ~BIT(POSTED_INTR_SN); } +#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 605c26c009c8..25ef145586c6 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" @@ -2227,6 +2228,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..dbb3a19b3004 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_msi_pi_desc); + +void intel_posted_msi_init(void) +{ + u32 destination; + u32 apic_id; + + this_cpu_write(posted_msi_pi_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_msi_pi_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