From: "Jan Beulich" Subject: [PATCH 5/5] VT-d: adjust IOMMU interrupt affinities when all CPUs are online Date: Wed, 21 Nov 2012 10:19:41 +0000 Message-ID: <50ACB8CE02000078000AA4B0@nat28.tlf.novell.com> References: <50ACB5C602000078000AA487@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part93A262AD.3__=" Return-path: In-Reply-To: <50ACB5C602000078000AA487@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Wei Huang , Wei Wang , xiantao.zhang@intel.com, Gang Wei List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part93A262AD.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Since these interrupts get setup before APs get brought online, their affinities naturally could only ever point to CPU 0 alone so far. Adjust this to include potentially multiple CPUs in the target mask (when running in one of the cluster modes), and take into account NUMA information (to handle the interrupts on a CPU on the node where the respective IOMMU is). Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -839,6 +839,7 @@ void acpi_dmar_reinstate(void) =20 void acpi_dmar_zap(void) { + adjust_vtd_irq_affinities(); if ( dmar_table =3D=3D NULL ) return; dmar_table->signature[0] =3D 'X'; --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -52,6 +52,7 @@ int invalidate_sync(struct iommu *iommu) int iommu_flush_iec_global(struct iommu *iommu); int iommu_flush_iec_index(struct iommu *iommu, u8 im, u16 iidx); void clear_fault_bits(struct iommu *iommu); +int adjust_vtd_irq_affinities(void); =20 struct iommu * ioapic_to_iommu(unsigned int apic_id); struct iommu * hpet_to_iommu(unsigned int hpet_id); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1971,6 +1971,33 @@ void clear_fault_bits(struct iommu *iomm spin_unlock_irqrestore(&iommu->register_lock, flags); } =20 +static void adjust_irq_affinity(struct acpi_drhd_unit *drhd) +{ + const struct acpi_rhsa_unit *rhsa =3D drhd_to_rhsa(drhd); + unsigned int node =3D rhsa ? pxm_to_node(rhsa->proximity_domain) + : NUMA_NO_NODE; + const cpumask_t *cpumask =3D &cpu_online_map; + + if ( node < MAX_NUMNODES && node_online(node) && + cpumask_intersects(&node_to_cpumask(node), cpumask) ) + cpumask =3D &node_to_cpumask(node); + dma_msi_set_affinity(irq_to_desc(drhd->iommu->msi.irq), cpumask); +} + +int adjust_vtd_irq_affinities(void) +{ + struct acpi_drhd_unit *drhd; + + if ( !iommu_enabled ) + return 0; + + for_each_drhd_unit ( drhd ) + adjust_irq_affinity(drhd); + + return 0; +} +__initcall(adjust_vtd_irq_affinities); + static int init_vtd_hw(void) { struct acpi_drhd_unit *drhd; @@ -1984,13 +2011,10 @@ static int init_vtd_hw(void) */ for_each_drhd_unit ( drhd ) { - struct irq_desc *desc; + adjust_irq_affinity(drhd); =20 iommu =3D drhd->iommu; =20 - desc =3D irq_to_desc(iommu->msi.irq); - dma_msi_set_affinity(desc, desc->arch.cpu_mask); - clear_fault_bits(iommu); =20 spin_lock_irqsave(&iommu->register_lock, flags); --=__Part93A262AD.3__= Content-Type: text/plain; name="VT-d-interrupt-affinity.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="VT-d-interrupt-affinity.patch" VT-d: adjust IOMMU interrupt affinities when all CPUs are online=0A=0ASince= these interrupts get setup before APs get brought online, their=0Aaffiniti= es naturally could only ever point to CPU 0 alone so far.=0AAdjust this to = include potentially multiple CPUs in the target mask=0A(when running in = one of the cluster modes), and take into account NUMA=0Ainformation (to = handle the interrupts on a CPU on the node where the=0Arespective IOMMU = is).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/drivers/passthrough/vtd/dmar.c=0A+++ b/xen/drivers/passthrough/vtd/dm= ar.c=0A@@ -839,6 +839,7 @@ void acpi_dmar_reinstate(void)=0A =0A void = acpi_dmar_zap(void)=0A {=0A+ adjust_vtd_irq_affinities();=0A if ( = dmar_table =3D=3D NULL )=0A return;=0A dmar_table->signature[0]= =3D 'X';=0A--- a/xen/drivers/passthrough/vtd/extern.h=0A+++ b/xen/drivers/= passthrough/vtd/extern.h=0A@@ -52,6 +52,7 @@ int invalidate_sync(struct = iommu *iommu)=0A int iommu_flush_iec_global(struct iommu *iommu);=0A int = iommu_flush_iec_index(struct iommu *iommu, u8 im, u16 iidx);=0A void = clear_fault_bits(struct iommu *iommu);=0A+int adjust_vtd_irq_affinities(voi= d);=0A =0A struct iommu * ioapic_to_iommu(unsigned int apic_id);=0A struct = iommu * hpet_to_iommu(unsigned int hpet_id);=0A--- a/xen/drivers/passthroug= h/vtd/iommu.c=0A+++ b/xen/drivers/passthrough/vtd/iommu.c=0A@@ -1971,6 = +1971,33 @@ void clear_fault_bits(struct iommu *iomm=0A spin_unlock_irq= restore(&iommu->register_lock, flags);=0A }=0A =0A+static void adjust_irq_a= ffinity(struct acpi_drhd_unit *drhd)=0A+{=0A+ const struct acpi_rhsa_uni= t *rhsa =3D drhd_to_rhsa(drhd);=0A+ unsigned int node =3D rhsa ? = pxm_to_node(rhsa->proximity_domain)=0A+ : = NUMA_NO_NODE;=0A+ const cpumask_t *cpumask =3D &cpu_online_map;=0A+=0A+ = if ( node < MAX_NUMNODES && node_online(node) &&=0A+ cpumask_int= ersects(&node_to_cpumask(node), cpumask) )=0A+ cpumask =3D = &node_to_cpumask(node);=0A+ dma_msi_set_affinity(irq_to_desc(drhd->iommu= ->msi.irq), cpumask);=0A+}=0A+=0A+int adjust_vtd_irq_affinities(void)=0A+{= =0A+ struct acpi_drhd_unit *drhd;=0A+=0A+ if ( !iommu_enabled )=0A+ = return 0;=0A+=0A+ for_each_drhd_unit ( drhd )=0A+ = adjust_irq_affinity(drhd);=0A+=0A+ return 0;=0A+}=0A+__initcall(adjust_v= td_irq_affinities);=0A+=0A static int init_vtd_hw(void)=0A {=0A struct = acpi_drhd_unit *drhd;=0A@@ -1984,13 +2011,10 @@ static int init_vtd_hw(void= )=0A */=0A for_each_drhd_unit ( drhd )=0A {=0A- struct = irq_desc *desc;=0A+ adjust_irq_affinity(drhd);=0A =0A iommu = =3D drhd->iommu;=0A =0A- desc =3D irq_to_desc(iommu->msi.irq);=0A- = dma_msi_set_affinity(desc, desc->arch.cpu_mask);=0A-=0A = clear_fault_bits(iommu);=0A =0A spin_lock_irqsave(&iommu->register_= lock, flags);=0A --=__Part93A262AD.3__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part93A262AD.3__=--