Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5608284rdb; Wed, 13 Dec 2023 13:55:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IH146v2+PjL0PwhlQDq7JOxIpEoMFWjn4uXqu7NTuhdUEm7NF3arGTtfFbHz+OLgtbfmHQg X-Received: by 2002:a05:6a20:918b:b0:18c:8afc:cdd2 with SMTP id v11-20020a056a20918b00b0018c8afccdd2mr5166025pzd.17.1702504551844; Wed, 13 Dec 2023 13:55:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702504551; cv=none; d=google.com; s=arc-20160816; b=kU2kFWhm113IZ8P/PkKMU4EqAWKVH6BGA21P8vSgBhnvBmo3s3DzC8bBolKi79nsiU qlkPfzfIGvB/bjlmt0bBrf7E7H5voMJxq5SmXVMrO63q5yhUT8C704wakmxUy7UD7ZOb Nsu6gDTkr/WeoVWTnjGZnIq8RLVQq8elwFtn8kUDS4YCRxA5opRyIbID90UtGjUKo19p cQuyTJGoCgC0uJWKJE12WjFAn72wfe0Qjf8O0qS1YRF9ZfAmBE34abj/fW7q0Avqjujd Wof51XBP57DOseezmoc8uCtbwoF1mNpaczpe/2e5FnUr+599Sc6RjqGy1+1xuX0MjOFj qyEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=tpqPH/l/hsN4Mae1ayxvBQkCqLLjfHKV4070PTEncTU=; fh=ZvpbeHpP0Y0v3u+CaZzOwTVebjaGJIGbrjWY8xhkDeQ=; b=uK+Kc+z2I5A1rVc6kWNMtvPInswQArQP8ObwxyZzrm9Uv3Jp5FdoEPIuBGnJ32XpzD 3mcE1R3rD54vJwgdGnDF/dr8BzxAuFS5KuSUR4Nf3/ikfft4bx3seUtoHU35t9dYUk96 X+C9A/M5HtK5m/O1hUqgaOKfs7Y2ah5fFQ0GOoLUbVf38grCDLflXHOoG/s1hIqQDU9X m2dYHyA7UDzyEnnx5t+bqw6TFanY3JN2sEnT/Y+svVjB4E/3jLAHtTVcejbjWqz/HMh3 f0lVY+G1jLNYRSAYoNSMfqqcfdd2DxxEb8YFGh0NGX1kOQifrn+qJf32DRbLwLysVExd jbqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QG1ufpIW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id u13-20020a170902e5cd00b001cfb4bd0e36si10472229plf.341.2023.12.13.13.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 13:55:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QG1ufpIW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A61D2819D9E1; Wed, 13 Dec 2023 13:55:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442567AbjLMVza (ORCPT + 99 others); Wed, 13 Dec 2023 16:55:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233861AbjLMVzW (ORCPT ); Wed, 13 Dec 2023 16:55:22 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1D3810C; Wed, 13 Dec 2023 13:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702504527; x=1734040527; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o2lEbwHxUNP/lL0Zv5x84LTlhNESluWyXeo3F7KR8cs=; b=QG1ufpIWnyLB6Up/SG/2/l0SBsGxKtIXVr9pqrSIXikgVjTw7BH93F5V 3K3N2STz19gAQGHcapG1HsRgcSz4nwHKgKBG5bOBWJhZAroMqy54coHb1 H8sAIUJED7wa84abxrJH1xKF+zAoRhlrGcO+G2Z3WOs1KiNNkqoIhQ/Sp B2J/eLnKdkLYuD80ER/h/2oDnz9oQqBROtanRtMjHw3dQ/+t4R13TbW5o PsWfTEKYve1sPwIIZwR7QNC/ca3auSOAszXHKLt+6puaNGU562MpIc3fs RHybNZTKqE3wUeERDn4xaxcbejNnU6A9ySpXe/+IzMP2TopElH8LjLBfd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="2176917" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="2176917" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 13:55:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="808320353" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="808320353" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.24.100.114]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 13:55:26 -0800 Date: Wed, 13 Dec 2023 14:00:21 -0800 From: Jacob Pan To: Thomas Gleixner Cc: LKML , X86 Kernel , iommu@lists.linux.dev, Lu Baolu , kvm@vger.kernel.org, Dave Hansen , Joerg Roedel , "H. Peter Anvin" , Borislav Petkov , Ingo Molnar , Raj Ashok , "Tian, Kevin" , maz@kernel.org, peterz@infradead.org, seanjc@google.com, Robin Murphy , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH RFC 13/13] iommu/vt-d: Enable posted mode for device MSIs Message-ID: <20231213140021.4cc84bb2@jacob-builder> In-Reply-To: <87zfynt6uo.ffs@tglx> References: <20231112041643.2868316-1-jacob.jun.pan@linux.intel.com> <20231112041643.2868316-14-jacob.jun.pan@linux.intel.com> <87zfynt6uo.ffs@tglx> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 13:55:48 -0800 (PST) Hi Thomas, On Wed, 06 Dec 2023 21:26:55 +0100, Thomas Gleixner wrote: > On Sat, Nov 11 2023 at 20:16, Jacob Pan wrote: > > #ifdef CONFIG_X86_POSTED_MSI > > > > static u64 get_pi_desc_addr(struct irq_data *irqd) > > @@ -1133,6 +1144,29 @@ static u64 get_pi_desc_addr(struct irq_data > > *irqd) > > return __pa(per_cpu_ptr(&posted_interrupt_desc, cpu)); > > } > > + > > +static void intel_ir_reconfigure_irte_posted(struct irq_data *irqd) > > +{ > > + struct intel_ir_data *ir_data = irqd->chip_data; > > + struct irte *irte = &ir_data->irte_entry; > > + struct irte irte_pi; > > + u64 pid_addr; > > + > > + pid_addr = get_pi_desc_addr(irqd); > > + > > + memset(&irte_pi, 0, sizeof(irte_pi)); > > + > > + /* The shared IRTE already be set up as posted during > > alloc_irte */ > > -ENOPARSE Will delete this. What I meant was that the shared IRTE has already been setup as posted mode instead of remappable mode. So when we make a copy, there is no need to change the mode. > > + dmar_copy_shared_irte(&irte_pi, irte); > > + > > + irte_pi.pda_l = (pid_addr >> (32 - PDA_LOW_BIT)) & ~(-1UL << > > PDA_LOW_BIT); > > + irte_pi.pda_h = (pid_addr >> 32) & ~(-1UL << PDA_HIGH_BIT); > > + > > + modify_irte(&ir_data->irq_2_iommu, &irte_pi); > > +} > > + > > +#else > > +static inline void intel_ir_reconfigure_irte_posted(struct irq_data > > *irqd) {} #endif > > > > static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool > > force) @@ -1148,8 +1182,9 @@ static void > > intel_ir_reconfigure_irte(struct irq_data *irqd, bool force) > > irte->vector = cfg->vector; irte->dest_id = IRTE_DEST(cfg->dest_apicid); > > > > - /* Update the hardware only if the interrupt is in remapped > > mode. */ > > - if (force || ir_data->irq_2_iommu.mode == IRQ_REMAPPING) > > + if (ir_data->irq_2_iommu.posted_msi) > > + intel_ir_reconfigure_irte_posted(irqd); > > + else if (force || ir_data->irq_2_iommu.mode == IRQ_REMAPPING) > > modify_irte(&ir_data->irq_2_iommu, irte); > > } > > > > @@ -1203,7 +1238,7 @@ static int intel_ir_set_vcpu_affinity(struct > > irq_data *data, void *info) struct intel_ir_data *ir_data = > > data->chip_data; struct vcpu_data *vcpu_pi_info = info; > > > > - /* stop posting interrupts, back to remapping mode */ > > + /* stop posting interrupts, back to the default mode */ > > if (!vcpu_pi_info) { > > modify_irte(&ir_data->irq_2_iommu, > > &ir_data->irte_entry); } else { > > @@ -1300,10 +1335,14 @@ static void > > intel_irq_remapping_prepare_irte(struct intel_ir_data *data, { > > struct irte *irte = &data->irte_entry; > > > > - prepare_irte(irte, irq_cfg->vector, irq_cfg->dest_apicid); > > + if (data->irq_2_iommu.mode == IRQ_POSTING) > > + prepare_irte_posted(irte); > > + else > > + prepare_irte(irte, irq_cfg->vector, > > irq_cfg->dest_apicid); > > switch (info->type) { > > case X86_IRQ_ALLOC_TYPE_IOAPIC: > > + prepare_irte(irte, irq_cfg->vector, > > irq_cfg->dest_apicid); > > What? This is just wrong. Above you have: > > > + if (data->irq_2_iommu.mode == IRQ_POSTING) > > + prepare_irte_posted(irte); > > + else > > + prepare_irte(irte, irq_cfg->vector, > > irq_cfg->dest_apicid); > > Can you spot the fail? My bad, I forgot to delete this. It is probably easier just override the IRTE for the posted MSI case. @@ -1274,6 +1354,11 @@ static void intel_irq_remapping_prepare_irte(struct intel_ir_data *data, break; case X86_IRQ_ALLOC_TYPE_PCI_MSI: case X86_IRQ_ALLOC_TYPE_PCI_MSIX: + if (posted_msi_supported()) { + prepare_irte_posted(irte); + data->irq_2_iommu.posted_msi = 1; + } + > > > /* Set source-id of interrupt request */ > > set_ioapic_sid(irte, info->devid); > > apic_printk(APIC_VERBOSE, KERN_DEBUG "IOAPIC[%d]: Set > > IRTE entry (P:%d FPD:%d Dst_Mode:%d Redir_hint:%d Trig_Mode:%d > > Dlvry_Mode:%X Avail:%X Vector:%02X Dest:%08X SID:%04X SQ:%X SVT:%X)\n", > > @@ -1315,10 +1354,18 @@ static void > > intel_irq_remapping_prepare_irte(struct intel_ir_data *data, sub_handle > > = info->ioapic.pin; break; case X86_IRQ_ALLOC_TYPE_HPET: > > + prepare_irte(irte, irq_cfg->vector, > > irq_cfg->dest_apicid); set_hpet_sid(irte, info->devid); > > break; > > case X86_IRQ_ALLOC_TYPE_PCI_MSI: > > case X86_IRQ_ALLOC_TYPE_PCI_MSIX: > > + if (posted_msi_supported()) { > > + prepare_irte_posted(irte); > > + data->irq_2_iommu.posted_msi = 1; > > + } else { > > + prepare_irte(irte, irq_cfg->vector, > > irq_cfg->dest_apicid); > > + } > > Here it gets even more hilarious. Thanks, Jacob