Message ID | 20231017144236.8287-1-suravee.suthikulpanit@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4183721vqb; Tue, 17 Oct 2023 07:43:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFcuGjMIksrQLC4NWw3rmilEEQpE0GCh+L/0kESsO7eKBYetzzT75npjaYUKk22pAl1fsI X-Received: by 2002:a17:902:e746:b0:1bb:9e6e:a9f3 with SMTP id p6-20020a170902e74600b001bb9e6ea9f3mr2563943plf.4.1697553806749; Tue, 17 Oct 2023 07:43:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697553806; cv=pass; d=google.com; s=arc-20160816; b=uxEIZxfzM0jm8EL+8uK2vkOSlDrQi25VW+2EOqh0PkMF03NzAWWlZss978svwqJzyU EqDARdP5Ecobl/dcgoy6IFOdqShwv8Y4oV3lh3Kd7RNMWuRC6CcFqFwx8/NhlPlAXxl0 ObbEbQtS+oivZrVuVbtUPmrgOMMahDaDLPdT/gShrOMhSMpRaHOneDRIysGmciNLbod6 y5bUq5AeEoInes1LjFhOPxoPNJJmAlcTLEieaRjoSRaNdoJOBtNOaFe27MUE0ZsBrZgA VHGRXke9t46DT8E5S+0jYV9z5706p6tKqoeE3Fo4wgF1oZu9bdxYcjgblqDPteyLKOU6 G0kA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=VvqNF/Z00hPImL77gykfZBxIqcjrMKj4qye6DdddhBs=; fh=XekHbzsaafPrK9yzVO5BvGznsIPaPDAS7uM9FOvfFBA=; b=UomUti13RgoyAmXFE+FWeeTfqAZbo6OWVkghXtRFMgIl6XTLomp2ueUeO3m6cf3gaQ wyfPd3/itxPjoNpkrFokCA4XQETG4n2lrEmDubiOz47Iy3Tc+J2x0rr+mYdRuMJvF/Mf m2wulwNSA/AoQQkOD9ZXoiS5mV+cAX1onPQOKrCjnfaEZRBg5dCmdE2NKutoCxLTu37W lMkTlCqx8t41sYFImCkC4wgmTqpCCjVou09m6ZLePiG0jfS7Q9iTs7dmvP1PWKUDrt5r civPT+zJCLumIjXZScRA+cN0E5sW/ghIuqlaZq7WaLUPuwH1M+t/Mj92Zx10oOeJvJmf usqw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=o3bdd0y8; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ij21-20020a170902ab5500b001b025aba9f2si1831071plb.22.2023.10.17.07.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=o3bdd0y8; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1584280C60E3; Tue, 17 Oct 2023 07:43:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344061AbjJQOnM (ORCPT <rfc822;hjfbswb@gmail.com> + 20 others); Tue, 17 Oct 2023 10:43:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233885AbjJQOnL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 17 Oct 2023 10:43:11 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2059.outbound.protection.outlook.com [40.107.220.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21A12BA for <linux-kernel@vger.kernel.org>; Tue, 17 Oct 2023 07:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkP54UIrXU1/Kn+3YNiWSBi2ZYT0qpKzbtQvUITGqJvI8VrkLN2HpZCiAp9zfdmltRELWcyuGcA2SRZWqr8HQtgtx/7Dmx0ATYNUrTeLuUP3UH7YH09Bti1McFFLwHRfBB8rM7cOw5rBrhrAcaqgu4PGceseGgN8y0yJq8JY9yP8tc3JGPjwfH2lxdF2ToaxFyc0NDqxVIAfzsMN+0Y9Q0bugHnbmU81VcWzi0zhuW441gCuLNCSU2LsAwfXFPCP9j22TI5eFev269LR4SHtmDFb2acKulQI2++BAmdn4BllkHNEXiSLdoWul9Xgejc6eFJqUj2eAKCf9pZf/Ttjiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VvqNF/Z00hPImL77gykfZBxIqcjrMKj4qye6DdddhBs=; b=oTlB9qv8SkbNewdlopv4wIC4Wa9hQAE9jaqbNj6EHjcLR10VnZDnxV5CXiv057ImGN8mHJS8LxKUfJkgyhYjb/EQ51aitzQYlJg/+yPxCCAkEoh7yxcuUwkKehx4JlpYzAGQuoit3T4boeWa5U4fQp4GpfKPCc9xnverXis+HDESgm5oPL0eFpP1omYW5WJIXSWtD/SUsNJmFDOmvkHCo6aQmKgitPWOVkq8wo+MjPPfu4VKh4ridVnycL/YsxL3mSShe8LApUW8XSIW31tItHh2NM4mAWnTdkMDaxDWcIjQYufz6w3ipWxdkUfkau/VJAcX3/gU5kSKsElcQRCU1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VvqNF/Z00hPImL77gykfZBxIqcjrMKj4qye6DdddhBs=; b=o3bdd0y8mXzv8P++8VasMV+tU99grOougeF5+mXHt4SeVT6+aj2hjdO/mzX/oRIxj8nTdjE9SvGb+4U+oP+/WFqKkakZmcc/H8d2RjB6Y/etuD7WMnz3/8u9wVmop6tNGLIflqpFLRqoZ1883HwzZ0FVBLgo766FGySoq2K7H4I= Received: from SN7PR04CA0165.namprd04.prod.outlook.com (2603:10b6:806:125::20) by MN2PR12MB4504.namprd12.prod.outlook.com (2603:10b6:208:24f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Tue, 17 Oct 2023 14:43:05 +0000 Received: from SA2PEPF000015CD.namprd03.prod.outlook.com (2603:10b6:806:125:cafe::97) by SN7PR04CA0165.outlook.office365.com (2603:10b6:806:125::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Tue, 17 Oct 2023 14:43:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CD.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Tue, 17 Oct 2023 14:43:05 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 17 Oct 2023 09:43:04 -0500 From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> To: <linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev> CC: <joro@8bytes.org>, <mlevitsk@redhat.com>, <seanjc@google.com>, <vasant.hegde@amd.com>, <jon.grimm@amd.com>, <santosh.shukla@amd.com>, <joao.m.martins@oracle.com>, <alejandro.j.jimenez@oracle.com>, <boris.ostrovsky@oracle.com>, Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Subject: [PATCH] iommu/amd: Do not flush IRTE when only updating isRun and destination fields Date: Tue, 17 Oct 2023 09:42:36 -0500 Message-ID: <20231017144236.8287-1-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CD:EE_|MN2PR12MB4504:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e3963d8-eff9-420e-7711-08dbcf1f5f69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0PsTMrDY3YCztXSQyCKk821fAt7/QieMbcHhMrFRf936zQOP4tDgWus8OJsZIVhXxulQznqr1VVmBAld3zqletgp/1MXYD3/h7lBN/XMiwLNB+MICC2c76hJtRmE4YKYeNVKNMOIPzS4E4OQzThDB0/VVb0ASYqHnoqdee4dG7MIZV+mNpgCneU9ZCl3Zr4VJGSS9EyAr/rZDdx6NazkyQ9hUbWhDIoW+FGWy+zMnq9+LvictuOyfRaZt7cCIBkF4rV+kU1bWThS1o2pWrA32UMVDnAzswPpNlWDlqpFA2E5Ty6OiMDWYbOK/4ZMvQnonLqVq5PNnCz7ZnxZk07BdWoFTU/wkiIjHMV2lXPnOCwPnCN+5xGogYs2toAPAiwb+LezaV/LXdExAH5DkDod6BB+v/exZGkOlPj2/8yGzRllXHMaoPSE/ZvHU9KSMM8W2k/C9RT2Vq1VhgI9HH8vB0E/sgJI8YwF/WUxcoEv6GXRcSWH5i0IQs7+HEkLR9+dqVik1pspQLssOdeqPZPD4AV8ftq9pQWpETn5/yJPX/YI3iJvt8DsW9xv697dpzC95Xn0qkSJSQ0ZSsU39c5vj83TXOtuoZgwqvsASFFR98a1P7Sy7WKJEJeZ+neB2iiF4fbPs58Fpk9brwWIKOTu0J7B2WmUWrbKht1mGmLhzjnK8E2+MCP82NQ9+RcOmxV2LDUMdzAO70GsXhP2p2lmtTWoUlgSjtWYSy8xgPlhpoAePqxAKS3aKqwZenMEglc3 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(39860400002)(396003)(346002)(376002)(230922051799003)(1800799009)(451199024)(186009)(64100799003)(82310400011)(46966006)(36840700001)(40470700004)(86362001)(41300700001)(44832011)(36860700001)(47076005)(7696005)(5660300002)(83380400001)(8936002)(4326008)(8676002)(2906002)(70586007)(70206006)(36756003)(356005)(316002)(336012)(110136005)(54906003)(426003)(1076003)(2616005)(81166007)(40480700001)(16526019)(82740400003)(26005)(40460700003)(966005)(6666004)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 14:43:05.4115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e3963d8-eff9-420e-7711-08dbcf1f5f69 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4504 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 07:43:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780014180286894681 X-GMAIL-MSGID: 1780014180286894681 |
Series |
iommu/amd: Do not flush IRTE when only updating isRun and destination fields
|
|
Commit Message
Suravee Suthikulpanit
Oct. 17, 2023, 2:42 p.m. UTC
According to the recent update in the AMD IOMMU spec [1], the IsRun and
Destination fields of the Interrupt Remapping Table Entry (IRTE) are not
cached by the IOMMU hardware.
Therefore, do not issue the INVALIDATE_INTERRUPT_TABLE command when
updating IRTE[IsRun] and IRTE[Destination] when IRTE[GuestMode]=1, which
should help improve IOMMU AVIC/x2AVIC performance.
References:
[1] AMD IOMMU Spec Revision (Rev 3.08-PUB)
(Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf)
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
drivers/iommu/amd/iommu.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
Comments
У вт, 2023-10-17 у 09:42 -0500, Suravee Suthikulpanit пише: > According to the recent update in the AMD IOMMU spec [1], the IsRun and > Destination fields of the Interrupt Remapping Table Entry (IRTE) are not > cached by the IOMMU hardware. Is that true for all AMD hardware that supports AVIC? E.g Zen1/Zen2 hardware? Is there a chance that this will cause a similar errata to the is_running errata that Zen2 cpus have? > > Therefore, do not issue the INVALIDATE_INTERRUPT_TABLE command when > updating IRTE[IsRun] and IRTE[Destination] when IRTE[GuestMode]=1, which > should help improve IOMMU AVIC/x2AVIC performance. > > References: > [1] AMD IOMMU Spec Revision (Rev 3.08-PUB) > (Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf) Looks like the link is broken. Best regards, Maxim Levitsky > > Cc: Joao Martins <joao.m.martins@oracle.com> > Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> > Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> > --- > drivers/iommu/amd/iommu.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index 089886485895..d63590563d3e 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -2970,8 +2970,8 @@ static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, > return index; > } > > -static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > - struct irte_ga *irte) > +static int __modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > { > struct irq_remap_table *table; > struct irte_ga *entry; > @@ -2998,6 +2998,18 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > > raw_spin_unlock_irqrestore(&table->lock, flags); > > + return 0; > +} > + > +static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > +{ > + bool ret; > + > + ret = __modify_irte_ga(iommu, devid, index, irte); > + if (ret) > + return ret; > + > iommu_flush_irt_and_complete(iommu, devid); > > return 0; > @@ -3681,8 +3693,8 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) > } > entry->lo.fields_vapic.is_run = is_run; > > - return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > - ir_data->irq_2_irte.index, entry); > + return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > + ir_data->irq_2_irte.index, entry); > } > EXPORT_SYMBOL(amd_iommu_update_ga); > #endif
On 10/17/2023 9:51 PM, Maxim Levitsky wrote: > У вт, 2023-10-17 у 09:42 -0500, Suravee Suthikulpanit пише: >> According to the recent update in the AMD IOMMU spec [1], the IsRun and >> Destination fields of the Interrupt Remapping Table Entry (IRTE) are not >> cached by the IOMMU hardware. > Is that true for all AMD hardware that supports AVIC? E.g Zen1/Zen2 hardware? This is true for all AVIC/x2AVIC-capable IOMMU hardware in the past. > Is there a chance that this will cause a similar errata to the is_running > errata that Zen2 cpus have? Please let me check on this and get back. >> Therefore, do not issue the INVALIDATE_INTERRUPT_TABLE command when >> updating IRTE[IsRun] and IRTE[Destination] when IRTE[GuestMode]=1, which >> should help improve IOMMU AVIC/x2AVIC performance. >> >> References: >> [1] AMD IOMMU Spec Revision (Rev 3.08-PUB) >> (Link:https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf) > Looks like the link is broken. The link above is the default location for AMD IOMMU spec, (which is currently being fixed). In the mean time, here is the temporary link to the latest document. (https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_3_07_PUB.pdf) Thanks, Suravee
On 10/17/2023 8:12 PM, Suravee Suthikulpanit wrote: > According to the recent update in the AMD IOMMU spec [1], the IsRun and > Destination fields of the Interrupt Remapping Table Entry (IRTE) are not > cached by the IOMMU hardware. > > Therefore, do not issue the INVALIDATE_INTERRUPT_TABLE command when > updating IRTE[IsRun] and IRTE[Destination] when IRTE[GuestMode]=1, which > should help improve IOMMU AVIC/x2AVIC performance. > > References: > [1] AMD IOMMU Spec Revision (Rev 3.08-PUB) > (Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf) > > Cc: Joao Martins <joao.m.martins@oracle.com> > Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> > Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Looks good to me. Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> -Vasant > --- > drivers/iommu/amd/iommu.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index 089886485895..d63590563d3e 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -2970,8 +2970,8 @@ static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, > return index; > } > > -static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > - struct irte_ga *irte) > +static int __modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > { > struct irq_remap_table *table; > struct irte_ga *entry; > @@ -2998,6 +2998,18 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > > raw_spin_unlock_irqrestore(&table->lock, flags); > > + return 0; > +} > + > +static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > +{ > + bool ret; > + > + ret = __modify_irte_ga(iommu, devid, index, irte); > + if (ret) > + return ret; > + > iommu_flush_irt_and_complete(iommu, devid); > > return 0; > @@ -3681,8 +3693,8 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) > } > entry->lo.fields_vapic.is_run = is_run; > > - return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > - ir_data->irq_2_irte.index, entry); > + return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > + ir_data->irq_2_irte.index, entry); > } > EXPORT_SYMBOL(amd_iommu_update_ga); > #endif
On 10/17/23 10:42, Suravee Suthikulpanit wrote: > According to the recent update in the AMD IOMMU spec [1], the IsRun and > Destination fields of the Interrupt Remapping Table Entry (IRTE) are not > cached by the IOMMU hardware. > > Therefore, do not issue the INVALIDATE_INTERRUPT_TABLE command when > updating IRTE[IsRun] and IRTE[Destination] when IRTE[GuestMode]=1, which > should help improve IOMMU AVIC/x2AVIC performance. > > References: > [1] AMD IOMMU Spec Revision (Rev 3.08-PUB) > (Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf) > > Cc: Joao Martins <joao.m.martins@oracle.com> > Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> > Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Built on top of v6.6-rc6 tag, and booted on EPYC Genoa host. Launched 380 vCPU guest with AVIC enabled and 16 VFs, and ran rds-ping workload that uses all of the VFs to send traffic. THis workload has been used in the past to stress IOMMU AVIC code paths. No issues found. Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> > --- > drivers/iommu/amd/iommu.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index 089886485895..d63590563d3e 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -2970,8 +2970,8 @@ static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, > return index; > } > > -static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > - struct irte_ga *irte) > +static int __modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > { > struct irq_remap_table *table; > struct irte_ga *entry; > @@ -2998,6 +2998,18 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > > raw_spin_unlock_irqrestore(&table->lock, flags); > > + return 0; > +} > + > +static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, > + struct irte_ga *irte) > +{ > + bool ret; > + > + ret = __modify_irte_ga(iommu, devid, index, irte); > + if (ret) > + return ret; > + > iommu_flush_irt_and_complete(iommu, devid); > > return 0; > @@ -3681,8 +3693,8 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) > } > entry->lo.fields_vapic.is_run = is_run; > > - return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > - ir_data->irq_2_irte.index, entry); > + return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, > + ir_data->irq_2_irte.index, entry); > } > EXPORT_SYMBOL(amd_iommu_update_ga); > #endif
Maxim, On 10/17/2023 10:36 PM, Suthikulpanit, Suravee wrote: > > On 10/17/2023 9:51 PM, Maxim Levitsky wrote: >> У вт, 2023-10-17 у 09:42 -0500, Suravee Suthikulpanit пише: >>> According to the recent update in the AMD IOMMU spec [1], the IsRun and >>> Destination fields of the Interrupt Remapping Table Entry (IRTE) are not >>> cached by the IOMMU hardware. >> Is that true for all AMD hardware that supports AVIC? E.g Zen1/Zen2 >> hardware? > > This is true for all AVIC/x2AVIC-capable IOMMU hardware in the past. > >> Is there a chance that this will cause a similar errata to the is_running >> errata that Zen2 cpus have? > > Please let me check on this and get back. Just to be sure, could you please tell me which errata number are you referring to here? Thanks, Suravee
On Thu, 2023-10-19 at 16:11 +0700, Suthikulpanit, Suravee wrote: > Maxim, > > On 10/17/2023 10:36 PM, Suthikulpanit, Suravee wrote: > > On 10/17/2023 9:51 PM, Maxim Levitsky wrote: > > > У вт, 2023-10-17 у 09:42 -0500, Suravee Suthikulpanit пише: > > > > According to the recent update in the AMD IOMMU spec [1], the IsRun and > > > > Destination fields of the Interrupt Remapping Table Entry (IRTE) are not > > > > cached by the IOMMU hardware. > > > Is that true for all AMD hardware that supports AVIC? E.g Zen1/Zen2 > > > hardware? > > > > This is true for all AVIC/x2AVIC-capable IOMMU hardware in the past. > > > > > Is there a chance that this will cause a similar errata to the is_running > > > errata that Zen2 cpus have? > > > > Please let me check on this and get back. > > Just to be sure, could you please tell me which errata number are you > referring to here? Hi! The errata is this one: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/revision-guides/56323-PUB_1_01.pdf (ERRATA #1235) The errata meaning is that once the CPU sets is_running=0 in AVIC's physical ID table, the hardware might still not cause #incomplete_ipi vmexit, for a few times. This means that KVM is not notified of the pending interrupt and it lets the target vCPU block instead of being woken up. In regard to the IOMMU, the parallel errata like situation would be that CPU sets is_running=0 in the IOMMU tables, exactly afterwards an interrupt arrives and the IOMMU doesn't log the interrupt in the GA log. Note that regardless if the IOMMU works correctly or not, the KVM has to check IRR after it sets is_running=0 to avoid memory reordering races, but it does so and uses a memory barrier to ensure correctness. PS: Recently I realized that a very simple workaround exists for errata #1235: At expense of the performance, the KVM can permanently set is_running=0 in the AVIC's physical id table. This will ensure that all ICR writes except self IPIs will cause a VM exit, thus in the expense of performance will ensure that AVIC works correctly. And this configuration while slower than full AVIC, it's still much better than having no AVIC, because AVIC still accelerates the receiver side of IPIs, and also IOMMU can still post interrupts. In fact with the workaround applied, AVIC is exactly equivalent to Intel's APICv without IPI virtualization. This is the latest version of my patch series: [PATCH v3 0/4] Allow AVIC's IPI virtualization to be optional https://www.spinics.net/lists/kvm/msg328416.html A help with a review will be highly appreciated. In addition to that I would highly appreciate if AMD could respond to these questions: 1. Is the errata #1235 really not present on Zen1 CPUs? It doesn't appear in the revision guide, but I still suspect that the guide might just not be up to date. I haven't tested a Zen1 machine to see if I can reproduce it yet. 2. As I see AMD disabled AVIC on Zen3 machines, but it does appear to work just fine in my testing. Is it possible that the reason for the disabling is also related to ICR/IPI emulation and that if I apply the same workaround as for errata #1235, then AVIC could be safely enabled on Zen3, despite support for it not being present in CPUID? If I know the answer to these questions, it might be possible to enable AVIC on all current AMD hardware by default. AFAIK (my personal opinion, based on various downstream bugs opened and their urgency) that our customers do care about APICv, but somehow assume as a fact that AMD doesn't have such feature while in fact AMD does. So I think that if AVIC were to be enabled by default on AMD, that would be something that AMD's (and ours) customers would appreciate very much. Best regards, Maxim Levitsky > > Thanks, > Suravee >
On Tue, Oct 17, 2023 at 09:42:36AM -0500, Suravee Suthikulpanit wrote: > drivers/iommu/amd/iommu.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) Applied, thanks.
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 089886485895..d63590563d3e 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2970,8 +2970,8 @@ static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, return index; } -static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, - struct irte_ga *irte) +static int __modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, + struct irte_ga *irte) { struct irq_remap_table *table; struct irte_ga *entry; @@ -2998,6 +2998,18 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, raw_spin_unlock_irqrestore(&table->lock, flags); + return 0; +} + +static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, + struct irte_ga *irte) +{ + bool ret; + + ret = __modify_irte_ga(iommu, devid, index, irte); + if (ret) + return ret; + iommu_flush_irt_and_complete(iommu, devid); return 0; @@ -3681,8 +3693,8 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) } entry->lo.fields_vapic.is_run = is_run; - return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, - ir_data->irq_2_irte.index, entry); + return __modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, + ir_data->irq_2_irte.index, entry); } EXPORT_SYMBOL(amd_iommu_update_ga); #endif