From nobody Wed Dec 17 10:44:29 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 0DF262066D4 for ; Wed, 19 Mar 2025 02:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742350842; cv=none; b=LhnzieAU11RkuHgC6k6txnKtSfia/ctQjl++LDaNXa56HzXkZH4f9/vDFmeHomi6YJVnL340J7inRwEq06JEj7vVmb/oXSnjxcCH6d5GT7O/iJD3WRCNxmHP1i7NJ0TO0sjGy0hkGPnmiLEMZ2GB1gFo8hktqspkiY1HetK3v8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742350842; c=relaxed/simple; bh=TcFOaMBC3GdcjOyQV2RecoDfdc6RUJknTRvdya4AKys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wvh04ql0eOBTB7Hfdpxf3rHDgWmlBe4dpHeyICrWdlQYQU/tVXPdgYi/ffK3uYnBizkwERUL0fkr7QK/xRC1Pb6zlDIXEeua5ADveOuKA0ATmkNGYYoeOd1dzPN6tG2W5xuQhaBRPfV/j2xezr7TNUN3yXFgLmLeAGYrQt/VHsI= 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=VFe5GliK; arc=none smtp.client-ip=192.198.163.19 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VFe5GliK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742350841; x=1773886841; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TcFOaMBC3GdcjOyQV2RecoDfdc6RUJknTRvdya4AKys=; b=VFe5GliKf6c4+U8vslI48O2WsyK0svSiDExCR8sQOwM8IF2cBHw6QC5n YmUL3YRtpjbzFPM7/twpfLcAG6Lk/EqqiBnZnpOwXnpSdOxO6u2vSPzoI QHGDPtegjpQC+Xlmy0QL1yDQGJlTFtdF0gHPlzNGfkWLRQ2R8KUshNPFx LHEcCN1RKlYHxW+EP08qZ2Ifwi4oYWpLRsQo+XNDwLme0Ay8o1NNicmib ZU0ADtJkFBZ0trS5XXG68aBBng6H1OoMfC1bEnVhzbIYbSIFzmke7PZsp XGJkx4Z6KQ4tOAA7r16wHKErliwEL0tp2Z37CDjpQCbFlWyC7plldHzVr Q==; X-CSE-ConnectionGUID: nhduTO9vSVaUjD9oCPiIAw== X-CSE-MsgGUID: BM7K1/ILQu+vlbiZFBCBCQ== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="42693229" X-IronPort-AV: E=Sophos;i="6.14,258,1736841600"; d="scan'208";a="42693229" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 19:20:40 -0700 X-CSE-ConnectionGUID: zME7LeUqQ3updjLGzdwjTQ== X-CSE-MsgGUID: loUmRC3sQxqg7KwWaHBMDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,258,1736841600"; d="scan'208";a="123372401" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 18 Mar 2025 19:20:39 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled Date: Wed, 19 Mar 2025 10:20:59 +0800 Message-ID: <20250319022101.1053133-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319022101.1053133-1-baolu.lu@linux.intel.com> References: <20250319022101.1053133-1-baolu.lu@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add a helper to take care of reconfiguring an IRTE to deliver IRQs to the host, i.e. not to a vCPU, and use the helper when an IRTE's vCPU affinity is nullified, i.e. when KVM puts an IRTE back into "host" mode. Because posted MSIs use an ephemeral IRTE, using modify_irte() puts the IRTE into full remapped mode, i.e. unintentionally disables posted MSIs on the IRQ. Fixes: ed1e48ea4370 ("iommu/vt-d: Enable posted mode for device MSIs") Cc: stable@vger.kernel.org Cc: Thomas Gleixner Cc: Jacob Pan Signed-off-by: Sean Christopherson Link: https://lore.kernel.org/r/20250315025135.2365846-2-seanjc@google.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/irq_remapping.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_= remapping.c index ad795c772f21..c495b533103f 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -1169,7 +1169,17 @@ static void intel_ir_reconfigure_irte_posted(struct = irq_data *irqd) static inline void intel_ir_reconfigure_irte_posted(struct irq_data *irqd)= {} #endif =20 -static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool force) +static void __intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_= host) +{ + struct intel_ir_data *ir_data =3D irqd->chip_data; + + if (ir_data->irq_2_iommu.posted_msi) + intel_ir_reconfigure_irte_posted(irqd); + else if (force_host || ir_data->irq_2_iommu.mode =3D=3D IRQ_REMAPPING) + modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry); +} + +static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_ho= st) { struct intel_ir_data *ir_data =3D irqd->chip_data; struct irte *irte =3D &ir_data->irte_entry; @@ -1182,10 +1192,7 @@ static void intel_ir_reconfigure_irte(struct irq_dat= a *irqd, bool force) irte->vector =3D cfg->vector; irte->dest_id =3D IRTE_DEST(cfg->dest_apicid); =20 - if (ir_data->irq_2_iommu.posted_msi) - intel_ir_reconfigure_irte_posted(irqd); - else if (force || ir_data->irq_2_iommu.mode =3D=3D IRQ_REMAPPING) - modify_irte(&ir_data->irq_2_iommu, irte); + __intel_ir_reconfigure_irte(irqd, force_host); } =20 /* @@ -1240,7 +1247,7 @@ static int intel_ir_set_vcpu_affinity(struct irq_data= *data, void *info) =20 /* stop posting interrupts, back to the default mode */ if (!vcpu_pi_info) { - modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry); + __intel_ir_reconfigure_irte(data, true); } else { struct irte irte_pi; =20 --=20 2.43.0