From patchwork Tue May 30 14:11:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 100890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2220747vqr; Tue, 30 May 2023 07:25:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6unVT+TW63ZzHdX9D8KwZ+1f0/DRDreIROWkYyusa8fzX6yqYPE2IJLI7/vCPB9R/YgbaC X-Received: by 2002:a17:90b:1d91:b0:256:ae6c:fd1f with SMTP id pf17-20020a17090b1d9100b00256ae6cfd1fmr2600346pjb.20.1685456747111; Tue, 30 May 2023 07:25:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685456747; cv=pass; d=google.com; s=arc-20160816; b=X2q9bvGzAQWLMS08LR/q8hNoO/xlJqp4c2/169n1jjL7MYbm+ft4KzT9kgcf46WVJ4 My5xHX5YYqjMRi7dPQZnVprSxh8OyrNcJBEyBnsEi6Sq4dc4YRnplbsGL9n3oQJq+GDk CaD9LRveBxKs/vMcJg8UMrvyISNQRXSEgFhBl9rna9GvUoxDonkSr2xJ555r730HQnZn MQRXTTzbb2RlaTkeTUOQV52y0c7U25CKgkMi68gz4AB5OGKC0iYFoz3HFXkzIbVXCJJ6 G6fhW2Eg989HUQ9HAZ6/5xy0V3f9+GTT+RJm7TzvhjbuvdXqP/un2A3TeUj5JRF3ChiR Z7HQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ee2qB947fjXKSbJ19wva3P15EHS0kat4zofWoK3PcBo=; b=mClWi+mOuUlMD1BA8DlananR965QV55r5QC9kA66hWccDVHXNzH+DFp9mLS+XcF7R7 KcCjDPk/5OTf+1ux/iThPVE3ReDFB9H55HRtZREl6Y5vli34etn/B8ryjYpLi0zsPKzj nGIH8LciZ4a7BCO7QLiY2xGCrYpUDIJ8BEIBFAPnPedZ/gHg5UBbDnv8uGmlw36BWW6H y027VAnYoY13fOtqr8q11ZMLvEsI99cs/OgyT9zzWVmNOrhrXG9DIqjEsdTwE9xwiBJX +cK7QBHhMoxftO78ya8ZJBwD1w72gF3sL+BA8aNYqZkOQHbPCIzbU+Lty6mItTEJGD05 DOnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="G4Z2/Wb1"; 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 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a17090a854c00b0025649fb6758si6718102pjw.170.2023.05.30.07.25.31; Tue, 30 May 2023 07:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="G4Z2/Wb1"; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232979AbjE3OMG (ORCPT + 99 others); Tue, 30 May 2023 10:12:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbjE3OME (ORCPT ); Tue, 30 May 2023 10:12:04 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2063.outbound.protection.outlook.com [40.107.220.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A71DBA0 for ; Tue, 30 May 2023 07:12:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CzeLnHnXDF93LFYyVgB052/qL2KcN3OXFPTFSftiaXiTJ+SuSE4/GJCJh8wRQvC7k4K7oW1350Q6Ueiq4I5GJT6mgmWFF8s9pKrPdntnUlML9AxLwBnAI9u+yHBS8G62URxNisI2H9HkOpL0IuPXwWGoKNcmELG6yCYKITdUcBW3yV4lfw4vL1aLNkfR4Qp/+Ca/rPsqznL8qx6Fkaj30lcBXktsVwII0uhYdFKLWMRxxMNcB5i97ZZI9w9P7GwJMX6t0F6AlLy4enxSJY6keROktv0ORwNoEBqtLn27eeH9/mWopDvAkPQOlHEbwwCmYEV5f35fGyEsYfYipgz5gw== 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=ee2qB947fjXKSbJ19wva3P15EHS0kat4zofWoK3PcBo=; b=DdCis3VkYBQ9R/TgqePhfQJyBGioC86A7ujni5I249GRjYJuHmT3qAu+Y4vJu5movQPhN+RETqxFi8FeAD7fISbfTUTlFDHc2ANYRRSnG1JROVF3hKoRYGRCRkBUuUm9Kh6/DaPIqcqgUhWE7UXjdhp3Xm2qEdsnybPStt1bcvMIqS0hgbcYYFItjaGamIVul57tGLC/q7tLDCXgcVcJAkNcWd1ltsWr05vA/r5SEQX5bmlqW8z+CeDOhp0UMF7DcRup9xPdga0NhyYCC3lw7x6/luuN6to9PJP8HkeBSMN2tj/gx6SeGsBjvkkixK4JQmZSNm0JT+K9VilVA/3GOA== 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=ee2qB947fjXKSbJ19wva3P15EHS0kat4zofWoK3PcBo=; b=G4Z2/Wb1yeJrUckMYfRr324NkDx2Y9kFY3Kg4zh2jhzGJKioKcAl5Kudo9oTanIyOc2RlTz/AVDupVOuxI4eSRMmtdZIXj/s/5FOSlSFsOteTLVmorF2/sUeqchByEYL8XfPpyTUvsfZuaAqdelBQ9mtX7oau35Mp3MILJFsS1I= Received: from SJ0PR03CA0262.namprd03.prod.outlook.com (2603:10b6:a03:3a0::27) by PH7PR12MB9102.namprd12.prod.outlook.com (2603:10b6:510:2f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:12:01 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:3a0:cafe::3) by SJ0PR03CA0262.outlook.office365.com (2603:10b6:a03:3a0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:01 +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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:01 +0000 Received: from titanite-d432host.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.2375.34; Tue, 30 May 2023 09:11:57 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 1/5] iommu/amd: Switch amd_iommu_update_ga() to use modify_irte_ga() Date: Tue, 30 May 2023 10:11:33 -0400 Message-ID: <20230530141137.14376-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> References: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT044:EE_|PH7PR12MB9102:EE_ X-MS-Office365-Filtering-Correlation-Id: cbf03df7-8743-4c5e-f05d-08db6117d661 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V/slZlIKp4jFNHiTr24gKO/rih7Uq6GNGK/1w7J1+S6xxrsxGfVKdr2FkgLGpgltRD1atwkHj91rxlAEpAJMKdZXzVX7K0j9beMsbtK4rtXRt22ACWxpPnM3bcdDqWWekh9jgB2u/TNe9fL0YiiGe0HwEGurtMsmgg+ws/Uq1Yg/K4l6qhjg6hlo4PDVZGJcI/sMZqCFGDhcMzeOmlacRp6cHLHQCTdiloranF+QxbleIL/q628gph3/LQRBhskScpV/O9S13FGqiavzIIyTCrTii/sXwEIMTGCA79g09EIdj6PBKpKMumKRQW5LWhRmP3c9nmHVyndxgUlQjjKmGSKZF3PChMPEgHlS8Myj0bgDFN0JmSsGRl4aGC7L4tVRzCq6F0iRW2qY6DTIRRNaMjdnvAox9n8eBT/uYSHpHl658WDVPlq0GEaH9AsDxbhojKQK8FKUfQrrDH4Lq94SrxCWJzknvueTCd6VgTb0R/y30atwWgT4Te97j0qJU0PR035OkRVV7DgzCbXCbBDwMO+m4SCeHS/ICTnk93/aUesdNzGZUQ8a3dT4wrmbG1q/yNk1t7InQds7IECcwtLdW8n7XY/AjGKgmNm7Ai+VZg3dZRR573JqqzgppnATDSYql2P2aIdypgo7B8maFoCJXIU5MIBHBagHELKjjYHoixhGzoRCP8am4GNEI2P2/QrCVaRt8AeKCAY4iHe1a+5rv5o6se/zefapTl6ShKvm97Q5N5r0RdTWImK27u8M0aaGHaT5rS9jqqQGq960R+ugVw== 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:(13230028)(4636009)(136003)(396003)(39860400002)(376002)(346002)(451199021)(36840700001)(46966006)(40470700004)(26005)(1076003)(36860700001)(41300700001)(7696005)(6666004)(16526019)(186003)(47076005)(83380400001)(426003)(336012)(2616005)(478600001)(40460700003)(110136005)(54906003)(82740400003)(82310400005)(70206006)(70586007)(4326008)(356005)(81166007)(40480700001)(316002)(5660300002)(8676002)(8936002)(44832011)(2906002)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:12:01.0535 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbf03df7-8743-4c5e-f05d-08db6117d661 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9102 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767329494346814963?= X-GMAIL-MSGID: =?utf-8?q?1767329494346814963?= From: Joao Martins The modify_irte_ga() uses cmpxchg_double() to update the IRTE in one shot, which is necessary when adding IRTE cache disabling support since the driver no longer need to flush the IRT for hardware to take effect. Please note that there is a functional change where the IsRun and Destination bits of IRTE are now cached in the struct amd_ir_data.entry. Reviewed-by: Jerry Snitselaar Signed-off-by: Joao Martins Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index ebb155bfef15..4a3a7346ab21 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3700,44 +3700,26 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu) int amd_iommu_update_ga(int cpu, bool is_run, void *data) { - unsigned long flags; - struct amd_iommu *iommu; - struct irq_remap_table *table; struct amd_ir_data *ir_data = (struct amd_ir_data *)data; - int devid = ir_data->irq_2_irte.devid; struct irte_ga *entry = (struct irte_ga *) ir_data->entry; - struct irte_ga *ref = (struct irte_ga *) ir_data->ref; if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) || - !ref || !entry || !entry->lo.fields_vapic.guest_mode) + !entry || !entry->lo.fields_vapic.guest_mode) return 0; - iommu = ir_data->iommu; - if (!iommu) - return -ENODEV; - - table = get_irq_table(iommu, devid); - if (!table) + if (!ir_data->iommu) return -ENODEV; - raw_spin_lock_irqsave(&table->lock, flags); - - if (ref->lo.fields_vapic.guest_mode) { - if (cpu >= 0) { - ref->lo.fields_vapic.destination = - APICID_TO_IRTE_DEST_LO(cpu); - ref->hi.fields.destination = - APICID_TO_IRTE_DEST_HI(cpu); - } - ref->lo.fields_vapic.is_run = is_run; - barrier(); + if (cpu >= 0) { + entry->lo.fields_vapic.destination = + APICID_TO_IRTE_DEST_LO(cpu); + entry->hi.fields.destination = + APICID_TO_IRTE_DEST_HI(cpu); } + entry->lo.fields_vapic.is_run = is_run; - raw_spin_unlock_irqrestore(&table->lock, flags); - - iommu_flush_irt(iommu, devid); - iommu_completion_wait(iommu); - return 0; + return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, + ir_data->irq_2_irte.index, entry, ir_data); } EXPORT_SYMBOL(amd_iommu_update_ga); #endif From patchwork Tue May 30 14:11:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 100879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2217054vqr; Tue, 30 May 2023 07:20:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LWj1p8aPA2NwpnhKXXxmw04ZBQ2bmHEuHkegOYTr3jKWp3+Vm6Xk4602R4YupxbX8nyW0 X-Received: by 2002:a17:90b:692:b0:24e:29ed:af07 with SMTP id m18-20020a17090b069200b0024e29edaf07mr2690014pjz.31.1685456429354; Tue, 30 May 2023 07:20:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685456429; cv=pass; d=google.com; s=arc-20160816; b=G4q1uijYUvRt+XRmwwP61hXdAbiWKA3bOluL4wr96/kMFYkOfwPlURVkTJz7A+iH3G wgBWkwoySsQZFXpKB5vnTVhToxGleUXtSdIfHyQQbbKJfgL2Li2/q4O2q9lp4ApwoAVJ 6v+VIoVDaY0UV0JEnBY4rgsyTgT6wf/DzZyZPPPBurATeoxtoK6KA1KhuOthqT6r/AeS LfWBCNF13PfI1XhPkymuu7yc69lxTgZdvkQtkky2mD58NdOMklUJ7uMqorVWCFk60yb0 wAOHs8+JObP38GrOZXosSuJ0flJFEHCXWSNmdnmyuNLvcnBxt8e7LyhsAc6cb6vaLlrC 02Qw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jwp6QcqdIjJgyKwXurCoaU7OraxSAQG+ziatjruJRhA=; b=sarkqeWCIRTB2C4teiD79B3aGrL26g9v3BhfigTykjidXskq5g5ySh67DcL4RKmDkd h/l6UsLEiW04DwjQLFTDH4tOxvp3c90jh8EzOCVQ0xfsJo8fV6hBvD0Din2771elT+PZ V7oovm1jJ77G5ERF+oK25YSyX20mpTYk/yVurqQkVtGc3n4G7BoB92uIsaY3Xt2P/h9g oufMTtYJbUZvztS0YzGW7QW1Gs3H1k8G/3X8NGSoCfF2l7gL0p5ec5hd6J5S1dcTH8lh ILW/5dqkpebyxP8/wU9DMLKdr/ogA8fqd8iUYdrDG/V096X2eeh2a24wmNiVw+sEKi73 vqAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=bUpYV6Pn; 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 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mg19-20020a17090b371300b002569e5bd4a2si2172497pjb.87.2023.05.30.07.20.16; Tue, 30 May 2023 07:20:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=bUpYV6Pn; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232984AbjE3OMN (ORCPT + 99 others); Tue, 30 May 2023 10:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbjE3OMI (ORCPT ); Tue, 30 May 2023 10:12:08 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20618.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::618]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78990C5 for ; Tue, 30 May 2023 07:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UnifeT/X7nb4zWVLn89nfytgmX8SbM6wlND5afWzkrPjdTqvfaiwd00acmfkE68G6aXhMT0Qtt7fblTv+jfefYwEgFF7iYSLmGf5epKrhUOVC7e7jNG4bEX4XNiSXK6lDZtBG99QY/FkL/vHkCMFpI9HTt1ZYCOJSHmjBFnG9+pkfwSfXMy1/3XUcaCcbXneQUDLA519J7v7HIxl2Oj7rkmTD5Qtuu/yq9CeeiMu3wtNU0//62thjUdj+yV+OwZJSyG1VDKcROmKI4aIUssmzQi2lM7K8sQ0Rogk2WjQGDFJ8MPCEG0Zo+50SGWn2qDnMcKQ/shyJfGk6wS27EM8Uw== 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=jwp6QcqdIjJgyKwXurCoaU7OraxSAQG+ziatjruJRhA=; b=bMRosdIpeTD8tp6wCSeXpLSrpJLrQ4cRrE0yj3NVOqtEDhGZ9If4uj5Kiu7FmcrWer998I/KZ0/CejzcCu4XT8R5YjlRENyZdlqkHATnDCuec1w75Pz8Q/cz+HfBObcOJO6CpDe4y1PPexCoceKPXtch62MvnglY21RfcTv0LJpSD5AWVDJYzyn/QdFhB1Z9hpvhG1nscKrETcRjciAtDfDlRKq1ik/EkzW7Nd8o0SOQQoYkajqMJhQ1VAwpvPm6npVhUFa6n9QXQrmbKRPKuovJ8V3+jKaBvem9UpWThr+B1szFQ7xDLl/GuvKW1VemxERA/4vNAvz7dmdWBtQGVA== 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=jwp6QcqdIjJgyKwXurCoaU7OraxSAQG+ziatjruJRhA=; b=bUpYV6PnShqXxKNp19nZO9c1aF8Z3iTRYQgnLxbgnT42yEUKTlg7YSR37bA241jT7Sldn7U+jN2Tw2JDPyrLM1xXPNxzx9ZzH7VXq3DMlBDJTTzW37A8eU7iSK6T4bLD7TEPzg12WnS6SLlr3yGAmoav+yoIRsGDamc1R5DD3ns= Received: from SJ0PR03CA0268.namprd03.prod.outlook.com (2603:10b6:a03:3a0::33) by LV8PR12MB9111.namprd12.prod.outlook.com (2603:10b6:408:189::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:12:04 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:3a0:cafe::fc) by SJ0PR03CA0268.outlook.office365.com (2603:10b6:a03:3a0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:03 +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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:02 +0000 Received: from titanite-d432host.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.2375.34; Tue, 30 May 2023 09:11:59 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 2/5] iommu/amd: Remove the unused struct amd_ir_data.ref Date: Tue, 30 May 2023 10:11:34 -0400 Message-ID: <20230530141137.14376-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> References: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT044:EE_|LV8PR12MB9111:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f6087b7-72af-49f3-2e03-08db6117d787 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nl7OorybJfJD3S4uIGujxASw9+FJTVYPlilE+DGTI1cyG3JHIV2bMVwkN6Z/gNvgow1X5cjvZpGrHRsJcDwXnvpYz+ghZFpUrJ4PpwnRKEbI2bUN9+WUHVM19fkBUQCqi7/jCYj2ZD3U5w49nhDbE15f7N7UuiapooVDCHHkfzmkpH8OKUepY0t8dYWcrWJGRsgg+/EEmkBbdvibRptwQ5IKoXUyn9r7d+LEDbSmM5MmLvLf82DRGbuUAeHJR04sulFg1p65HEfCYaIMA0q3rNFW9wqmM3/g+WlsaL7Jxk+Xxop8/563+qNHvVfOiUuyBZjT4NGbIO3HFGt4f2Esm1Vt4aeVlvMoT0ZDW1/NjXnAFI7hSH4+PeMuvSws5p43U30ZMVCcqx1z/ihgMo3QNbkfSyMuNNVdUVTuyfPhx/OKfUwwfVfkGevtvmbr6yT1eaupTnWN8Y9wG6sdTI6Rgdv41ojOeihI89MetnTGFAnuXXVyzJjzR7VRvdnbBaC0Aj7EVoia8wocmnHEeHoxnrvxlhClAcfHC0rO7JLecaGfmCnymH3MpEOQbcdi7klTJIXHDFYD1tbbj7+KnFvvIlplqbNuXY5XeQKvVBlGtpkX3KWec4JNU3XtqZF5Ob503nDsZtoMl80lCbzwEMZVsS4xy5H12Iyd6i1ZzPPqMaf8pHeGAAUHtAQFkObsadOfbT+Um6CohEWw+Q8vuL8Bp64++mRCPgPtMueQjnKrVymEkuDn2u+Yyk+uOp/XaCFWGP5qk1EFu/a+B6g00kNFKg== 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:(13230028)(4636009)(396003)(376002)(136003)(346002)(39860400002)(451199021)(40470700004)(46966006)(36840700001)(40460700003)(47076005)(83380400001)(2616005)(426003)(336012)(2906002)(16526019)(186003)(40480700001)(36756003)(82740400003)(356005)(81166007)(36860700001)(8936002)(8676002)(86362001)(478600001)(4326008)(70206006)(70586007)(5660300002)(41300700001)(7696005)(6666004)(316002)(26005)(1076003)(110136005)(82310400005)(44832011)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:12:02.9597 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f6087b7-72af-49f3-2e03-08db6117d787 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9111 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767329160771089072?= X-GMAIL-MSGID: =?utf-8?q?1767329160771089072?= Since the amd_iommu_update_ga() has been switched to use the modify_irte_ga() helper function to update the IRTE, the parameter is no longer needed. Reviewed-by: Jerry Snitselaar Suggested-by: Vasant Hegde Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 1 - drivers/iommu/amd/iommu.c | 17 +++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 3d684190b4d5..a0ff1e852efc 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -993,7 +993,6 @@ struct amd_ir_data { struct irq_2_irte irq_2_irte; struct msi_msg msi_entry; void *entry; /* Pointer to union irte or struct irte_ga */ - void *ref; /* Pointer to the actual irte */ /** * Store information for activate/de-activate diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4a3a7346ab21..0c4a2796bb0a 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2999,7 +2999,7 @@ static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, } static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, - struct irte_ga *irte, struct amd_ir_data *data) + struct irte_ga *irte) { bool ret; struct irq_remap_table *table; @@ -3026,9 +3026,6 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, */ WARN_ON(!ret); - if (data) - data->ref = entry; - raw_spin_unlock_irqrestore(&table->lock, flags); iommu_flush_irt(iommu, devid); @@ -3117,7 +3114,7 @@ static void irte_ga_activate(struct amd_iommu *iommu, void *entry, u16 devid, u1 struct irte_ga *irte = (struct irte_ga *) entry; irte->lo.fields_remap.valid = 1; - modify_irte_ga(iommu, devid, index, irte, NULL); + modify_irte_ga(iommu, devid, index, irte); } static void irte_deactivate(struct amd_iommu *iommu, void *entry, u16 devid, u16 index) @@ -3133,7 +3130,7 @@ static void irte_ga_deactivate(struct amd_iommu *iommu, void *entry, u16 devid, struct irte_ga *irte = (struct irte_ga *) entry; irte->lo.fields_remap.valid = 0; - modify_irte_ga(iommu, devid, index, irte, NULL); + modify_irte_ga(iommu, devid, index, irte); } static void irte_set_affinity(struct amd_iommu *iommu, void *entry, u16 devid, u16 index, @@ -3157,7 +3154,7 @@ static void irte_ga_set_affinity(struct amd_iommu *iommu, void *entry, u16 devid APICID_TO_IRTE_DEST_LO(dest_apicid); irte->hi.fields.destination = APICID_TO_IRTE_DEST_HI(dest_apicid); - modify_irte_ga(iommu, devid, index, irte, NULL); + modify_irte_ga(iommu, devid, index, irte); } } @@ -3508,7 +3505,7 @@ int amd_iommu_activate_guest_mode(void *data) entry->lo.fields_vapic.ga_tag = ir_data->ga_tag; return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, - ir_data->irq_2_irte.index, entry, ir_data); + ir_data->irq_2_irte.index, entry); } EXPORT_SYMBOL(amd_iommu_activate_guest_mode); @@ -3538,7 +3535,7 @@ int amd_iommu_deactivate_guest_mode(void *data) APICID_TO_IRTE_DEST_HI(cfg->dest_apicid); return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, - ir_data->irq_2_irte.index, entry, ir_data); + ir_data->irq_2_irte.index, entry); } EXPORT_SYMBOL(amd_iommu_deactivate_guest_mode); @@ -3719,7 +3716,7 @@ 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, ir_data); + ir_data->irq_2_irte.index, entry); } EXPORT_SYMBOL(amd_iommu_update_ga); #endif From patchwork Tue May 30 14:11:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 100886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2219293vqr; Tue, 30 May 2023 07:23:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7M09keUd7b1YEVkeluqosBHa21VllxyXiunvjBwQRIQhk99t3Pvap3CXUdUJxSCzI0/3F6 X-Received: by 2002:a05:6a20:8421:b0:10b:97c8:2e16 with SMTP id c33-20020a056a20842100b0010b97c82e16mr2989906pzd.29.1685456622910; Tue, 30 May 2023 07:23:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685456622; cv=pass; d=google.com; s=arc-20160816; b=AOkVYKU3l+g9iVjc7CFtrp7YsrRrM6YTwic5mUflS8oQIqbi9kGLk3jAULmkpFQO/J XKdm7wbZDxpwG5VbtejwIsokgPC7foYIZMXg6e5twIm15tocdF7VScVJK2GdBmAXBw69 BbcgO+oRyteZm0ualF2GjwDMZEbNA3ta2rf1lbBrh2a8fUZcty3JlOLZlR58I3YaYboM TJ+62JeKZ9ZZCkxs7qSGRknQ8+9blGzOSBPrws4ZrnDQlI7AQlTG5MPPD1uDehu9M4GH dOk86HHrdAA3C7V185DBbQi0olopB4XQ4VWtbrCRlQCAdHgR/3aU1MU0j+kZC8vlrhI/ KeTg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oZYs+r8uNjVf/8lOAlN48BpcDCsnxQBl31dbkVBXYTA=; b=gijb2kO+5q6RnnijxLOWWPg1fwkIH6TFrE1empVkDBMx0UrDtwkVMmltm+XVHhgA80 FEdE3m/VdI0ihzmtf3t+7rzYX0raCnIr+Mo96YZEyH+EOzMNAvK5AjNX0YHEhCWnfsFu FcF3nhy+f7hrBJ37i0cvTbwu5+IGrSmjyt/2/s0+8qHniLTUciejaFpHdybCgi8AWoWV NPz3vrQiI9cL48NDyP2v99f4sMOxKV9ntNUhqM/+yvjK4Y0fIZlXegLLT8Cy+8lkDnXK /OhnIASi7lYed2tzlzDrPRF2hvP+u5XC7SZVzlnPM3B8jb5bef+llxFAla3Cg7z2wR9v aAPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=KehOOcJo; 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 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a17090aba9000b0025653dc2881si5712196pjr.23.2023.05.30.07.23.31; Tue, 30 May 2023 07:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=KehOOcJo; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233013AbjE3OMP (ORCPT + 99 others); Tue, 30 May 2023 10:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232989AbjE3OMK (ORCPT ); Tue, 30 May 2023 10:12:10 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20623.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::623]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C428FA0 for ; Tue, 30 May 2023 07:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+rMbqzsyFs7sAMww2Mz6mJtnRNQmgJOdlr/kunaDgLrXK7hVw5NiFEfMUe53k+dlB9kRATMvHwgjJwodNAOtblXwhxrBV5toZ/TJK6qIKlt8Te1Qh/FArt6hDGSHMElXrWBlU0xBmNsfLt9zZ1gEi/iPPAZH4144JSASQ9MbKmiAgqaTmojQDauP0UFjoGMV5/Ia4LHGYfRkdz69/IhQS9zaPsVdQbsEawFVpqpUTjhmy7Jo0dB8mlK/pfNBPZSTatQ4AXbcFwELKh5PUfe3xUOzm6kFKUkLn+cDhHB0OSiuzkv5xPRpVVyXgYYHfHokfOOWh6+ZJ2dJPymaD0TaA== 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=oZYs+r8uNjVf/8lOAlN48BpcDCsnxQBl31dbkVBXYTA=; b=IgQwfOdlPknHfXYZvIG8OaU96reqam774Lzejy+O83ZIITuo0/lLbOzn1RxfzsM5p/qBNVQHC66JFHywkstW+PnCgROkKrde9pRLdo1T9eRG0qg6Ws0F4oIJCbY4rO4STP77Vvo5V/6FHyGHFfhE0NkvgYudnQXBXp3kEFH2x07p+0JDk617P+IIYlJTUKhYIsAIhtG/ktTc7FfxsZzwgkS7LE54QfUHezh/APWpcM+trKeeSTnfc0nM8oi1lMtmGzLtJALgjJXCYgQvW+wnjKf9s60y6S2tZUtl0j9317t5my1tEAmME7bwOyLsKkYBig4Bnb9p50T2mF9FznI+EA== 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=oZYs+r8uNjVf/8lOAlN48BpcDCsnxQBl31dbkVBXYTA=; b=KehOOcJoLT/H1QWp2XzTYPeOXukSPuSH3Gw8kdmpx2+y4geg1AIVb+/MTz3MZ2sAo1G0S+WX1nt+6f9BOaTKZhZGpfm0TMxQqBKhh2spms5H9WCam2ht90+R0FAdAjleyHDgIWWfan3g4qEV7gV29+BHJQdZF3+0LlirnL8rxVs= Received: from SJ0PR03CA0267.namprd03.prod.outlook.com (2603:10b6:a03:3a0::32) by PH0PR12MB8007.namprd12.prod.outlook.com (2603:10b6:510:28e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:12:05 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:3a0:cafe::6e) by SJ0PR03CA0267.outlook.office365.com (2603:10b6:a03:3a0::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23 via Frontend Transport; Tue, 30 May 2023 14:12: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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:04 +0000 Received: from titanite-d432host.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.2375.34; Tue, 30 May 2023 09:12:00 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 3/5] iommu/amd: Introduce Disable IRTE Caching Support Date: Tue, 30 May 2023 10:11:35 -0400 Message-ID: <20230530141137.14376-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> References: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT044:EE_|PH0PR12MB8007:EE_ X-MS-Office365-Filtering-Correlation-Id: 4eb980ea-2f3e-4d8b-e24d-08db6117d8a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7axUAzPtV9sPuoqUQjmnq5fpc1A++9wVUR/iONPcsimFDiBIKGAAzpMLfKTqf3ReSQhpQnd+JyjbKPxGxFULBBhb53al4Gb+Xyp/hlgl68bAO/M/xxbIYNaIcnS5FoxN2pKCVZUgBjMTJKNy4XnCfUY3vlNJgDRtRJa6SffZ4I17NHiHpZ4plfKV4PqyU7qXYNWHM+yhnBLhwGFdLe55Jvf2Ookop0ZFI5OnphyTm6YINXK7ndewZsOPH2OgmqbohwY7lipj7alYXoD6zc2AbH/deK7FoZ+jJV8BcClOAR58WADpPmMFVTaPQ5/Af/gj0/cj1AhizL5BX9h0pyolMZE/ND7bBxnrA/p3wp3YXbgirePfQ7XFXWurchl6FCNMlL6okjNaAEG4oJv84z7FJTaPCHH3DD6wzW6LCGHmPj6b8urfQPcL51oljb/vdnABnvUfsp+QzMnQXT1i0z9BsI/ugWiOwc9SeQ1C5/wT752d1N4aznrJlglJEu0YgitjNCMevBU6KWCYie0kPN7eiH5wC6Yb0O3j+xU2tPk5MmpiFMgIr2my8t8C5UbtJZoPNa+/TajxKwyj2sFGmdlQCruDjG5fLLTtcQkX4MxmeWVKQCw6dOcY7Bo0GskQjgZ/17jZh+C936axCpUZKGBHDykFz/Mh/s7tLwLquX7TzEj0iRGL6IY6lNEhq73tUmvfMVoPPVcP6eNsoqo3z8SKmV8pcysD0mW0rP1rG3H8gI1yQwxJw7C4MhL/M6c+tj916TnIi9WUnEFy3vWjkuLNEw== 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:(13230028)(4636009)(396003)(376002)(39860400002)(136003)(346002)(451199021)(36840700001)(46966006)(40470700004)(478600001)(40460700003)(54906003)(110136005)(8936002)(8676002)(5660300002)(44832011)(86362001)(82310400005)(36756003)(2906002)(356005)(81166007)(4326008)(82740400003)(70206006)(70586007)(316002)(40480700001)(41300700001)(2616005)(16526019)(186003)(1076003)(26005)(47076005)(36860700001)(7696005)(6666004)(426003)(336012)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:12:04.8346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4eb980ea-2f3e-4d8b-e24d-08db6117d8a2 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8007 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767329363571822633?= X-GMAIL-MSGID: =?utf-8?q?1767329363571822633?= An Interrupt Remapping Table (IRT) stores interrupt remapping configuration for each device. In a normal operation, the AMD IOMMU caches the table to optimize subsequent data accesses. This requires the IOMMU driver to invalidate IRT whenever it updates the table. The invalidation process includes issuing an INVALIDATE_INTERRUPT_TABLE command following by a COMPLETION_WAIT command. However, there are cases in which the IRT is updated at a high rate. For example, for IOMMU AVIC, the IRTE[IsRun] bit is updated on every vcpu scheduling (i.e. amd_iommu_update_ga()). On system with large amount of vcpus and VFIO PCI pass-through devices, the invalidation process could potentially become a performance bottleneck. Introducing a new kernel boot option: amd_iommu=irtcachedis which disables IRTE caching by setting the IRTCachedis bit in each IOMMU Control register, and bypass the IRT invalidation process. Reviewed-by: Jerry Snitselaar Co-developed-by: Alejandro Jimenez Signed-off-by: Alejandro Jimenez Signed-off-by: Suravee Suthikulpanit --- .../admin-guide/kernel-parameters.txt | 1 + drivers/iommu/amd/amd_iommu_types.h | 4 +++ drivers/iommu/amd/init.c | 36 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 6221a1d057dd..f29dee600faf 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -323,6 +323,7 @@ option with care. pgtbl_v1 - Use v1 page table for DMA-API (Default). pgtbl_v2 - Use v2 page table for DMA-API. + irtcachedis - Disable Interrupt Remapping Table (IRT) caching. amd_iommu_dump= [HW,X86-64] Enable AMD IOMMU driver option to dump the ACPI table diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index a0ff1e852efc..486a052e37ca 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -172,6 +172,7 @@ #define CONTROL_GAINT_EN 29 #define CONTROL_XT_EN 50 #define CONTROL_INTCAPXT_EN 51 +#define CONTROL_IRTCACHEDIS 59 #define CONTROL_SNPAVIC_EN 61 #define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) @@ -708,6 +709,9 @@ struct amd_iommu { /* if one, we need to send a completion wait command */ bool need_sync; + /* true if disable irte caching */ + bool irtcachedis_enabled; + /* Handle for IOMMU core code */ struct iommu_device iommu; diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index fd487c33b28a..fc0392d706db 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -160,6 +160,7 @@ static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE; static bool amd_iommu_detected; static bool amd_iommu_disabled __initdata; static bool amd_iommu_force_enable __initdata; +static bool amd_iommu_irtcachedis; static int amd_iommu_target_ivhd_type; /* Global EFR and EFR2 registers */ @@ -477,6 +478,9 @@ static void iommu_disable(struct amd_iommu *iommu) /* Disable IOMMU hardware itself */ iommu_feature_disable(iommu, CONTROL_IOMMU_EN); + + /* Clear IRTE cache disabling bit */ + iommu_feature_disable(iommu, CONTROL_IRTCACHEDIS); } /* @@ -2700,6 +2704,33 @@ static void iommu_enable_ga(struct amd_iommu *iommu) #endif } +static void iommu_disable_irtcachedis(struct amd_iommu *iommu) +{ + iommu_feature_disable(iommu, CONTROL_IRTCACHEDIS); +} + +static void iommu_enable_irtcachedis(struct amd_iommu *iommu) +{ + u64 ctrl; + + if (!amd_iommu_irtcachedis) + return; + + /* + * Note: + * The support for IRTCacheDis feature is dertermined by + * checking if the bit is writable. + */ + iommu_feature_enable(iommu, CONTROL_IRTCACHEDIS); + ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET); + ctrl &= (1ULL << CONTROL_IRTCACHEDIS); + if (ctrl) + iommu->irtcachedis_enabled = true; + pr_info("iommu%d (%#06x) : IRT cache is %s\n", + iommu->index, iommu->devid, + iommu->irtcachedis_enabled ? "disabled" : "enabled"); +} + static void early_enable_iommu(struct amd_iommu *iommu) { iommu_disable(iommu); @@ -2710,6 +2741,7 @@ static void early_enable_iommu(struct amd_iommu *iommu) iommu_set_exclusion_range(iommu); iommu_enable_ga(iommu); iommu_enable_xt(iommu); + iommu_enable_irtcachedis(iommu); iommu_enable(iommu); iommu_flush_all_caches(iommu); } @@ -2760,10 +2792,12 @@ static void early_enable_iommus(void) for_each_iommu(iommu) { iommu_disable_command_buffer(iommu); iommu_disable_event_buffer(iommu); + iommu_disable_irtcachedis(iommu); iommu_enable_command_buffer(iommu); iommu_enable_event_buffer(iommu); iommu_enable_ga(iommu); iommu_enable_xt(iommu); + iommu_enable_irtcachedis(iommu); iommu_set_device_table(iommu); iommu_flush_all_caches(iommu); } @@ -3411,6 +3445,8 @@ static int __init parse_amd_iommu_options(char *str) amd_iommu_pgtable = AMD_IOMMU_V1; } else if (strncmp(str, "pgtbl_v2", 8) == 0) { amd_iommu_pgtable = AMD_IOMMU_V2; + } else if (strncmp(str, "irtcachedis", 11) == 0) { + amd_iommu_irtcachedis = true; } else { pr_notice("Unknown option - '%s'\n", str); } From patchwork Tue May 30 14:11:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 100875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2215891vqr; Tue, 30 May 2023 07:18:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5haMVebJtcepQ2csrqc0Q1Z4Y5qC8CFj1C/CSy7bb30ueuLWJ5iP+FxBAUAupPVQ1o6aX8 X-Received: by 2002:a05:6a00:114e:b0:64d:123d:cc74 with SMTP id b14-20020a056a00114e00b0064d123dcc74mr2939581pfm.4.1685456329542; Tue, 30 May 2023 07:18:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685456329; cv=pass; d=google.com; s=arc-20160816; b=fyvunZSJYUm8L9eGjF7qn3W7YDX3dBFbG/YRWy/xjaqxve9+2Csjnm9nue87MYOB19 /H+LxN0ZLyPUcEBIBF+7gJcrPu2L2dCzwEq3/GfRbN/n/WtiOTE7SMjqVaMJLV/KBvsm qYuQurjjsPVjBAEmAwhRfaJ1XTOYbbKrTdCpECqsvLXVcWPjwXf+scTLNEYrNwCQdSrx GH344fo2JmSqB8qEUbHphteo/mnlxkSZwr18P/oUVTrSJ08DrFLkytbzFmZqzGCVkpG4 E8zZpzMEk7Kybm6MWA3FNJ01WOXCWcGLTWEp3O90B3nK13AGf+T/8/AmWUjYZjauW2An geEQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dplin9jP/RrG09YT921BmrFYs1i2xvloS5wsq9ZNzQo=; b=z3DrgVpJedUBYobngShzcsuO5gYMmViF53XrLh7FmgOyLXkvEf51m39mOQ2m8PfI2U kUrtiYq9oq11hyBVRHMEC9uvwxo6UkMcjUMFoKBNtmxlfn5U4b3ulYIDLnbGZqULkcA2 bklunBTnQT79r0f7z4CurIu1I68+6GY39JOdI2TGycx+/Srh7ircO28hixr2ZkvEManA JBbvuXG7WqMzpWd4/AFpz2q8hZ8Lx1qIaE59sKcrxlesDCPWDRi0l1OnMT/JwmuFRb0x yCGWWrcPNfLfbVtUv9IUCPvJNl07o3Uin8gtUYDuUk21lsxyFU/Ri96OZGqLHw2iA0t7 RHRw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Gm4ryB1J; 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 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x22-20020aa79416000000b0064d74234b07si1780649pfo.188.2023.05.30.07.18.32; Tue, 30 May 2023 07:18:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Gm4ryB1J; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232996AbjE3OML (ORCPT + 99 others); Tue, 30 May 2023 10:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbjE3OMI (ORCPT ); Tue, 30 May 2023 10:12:08 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2042.outbound.protection.outlook.com [40.107.93.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4145D9 for ; Tue, 30 May 2023 07:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g9Tpm/6DqcNXLQWXdT099SEPaT301wC4AQ0FjWDVZp9yD8rJUvStzXS1N5sM1pGcHCOA94hDSqtc+WZ2L/u4Lu+2JZ2S6yVHJWqCIBx6NwQ60/167YLjMBbaKKUaiAUoXA5eI9P105yoM2JGN9irwImdqIahj1NUaztVQC+iZRuqEP5Gr8nlbqwjIekdyE5HMNG09Mbj40cICEK7d8BpZftyw2sjtF7owXxJOQyyvhr8bpQs2N9m9n8OkQMnJ1wo6VL3+uO4U6mYp6uraxp1n6OKKCg64PMAAo3rImLZ9NapJjyE9NxFAb/xyQGcQs6SAJHMJymXvcBN0MrepcWsbw== 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=dplin9jP/RrG09YT921BmrFYs1i2xvloS5wsq9ZNzQo=; b=U8E3RKW70tG7TwZYGf6Gmo57KI+zTz6OayNXMxByE6w6Jj7rv+jcAu3g/brlXNfAV7PErF87i+Rq4e//mAyvRFNVbJP3UVxmD+KaKs1zFxBhEkr9VoRRZ8tRWJY3Tpj3n2/aqDgyc/4Z/UgXLCKoZrTkCMbA5VysHIx0HmFFgJb4nWd7zxF46talXBSMLynyUHlqOLUkmoahTB8I6FfFLPOnhV0TtQUiCefWyWm/0e6GVKO8XxzWuuoE4hAxCvHBPmLhUxzzKbz4E53C3U/3oAJqJsOcpaypTg91oEoG78Z0T1esjixcVsV4CtK32bBObgEgyY10oeC/2eWTbEWOUg== 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=dplin9jP/RrG09YT921BmrFYs1i2xvloS5wsq9ZNzQo=; b=Gm4ryB1JyePlQ4e+fgoSWDeuodsCdxtA6b0zJ6Sn2/W1Fqlol7bb8y9aBIKPM/M+qKdJ6Pb+0dkxT0s6TyT6wHxw58c+95xrmOyWP6FjXd/VVJU91xg8erqz1k5nOit1yEClEF0NaBKdKLAma9wMXce5OA+FQ3CLlZ2ylgYLjZ0= Received: from SJ0PR03CA0260.namprd03.prod.outlook.com (2603:10b6:a03:3a0::25) by CY8PR12MB8214.namprd12.prod.outlook.com (2603:10b6:930:76::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:12:05 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:3a0:cafe::60) by SJ0PR03CA0260.outlook.office365.com (2603:10b6:a03:3a0::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23 via Frontend Transport; Tue, 30 May 2023 14:12: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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:05 +0000 Received: from titanite-d432host.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.2375.34; Tue, 30 May 2023 09:12:02 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 4/5] iommu/amd: Do not Invalidate IRT when IRTE caching is disabled Date: Tue, 30 May 2023 10:11:36 -0400 Message-ID: <20230530141137.14376-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> References: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT044:EE_|CY8PR12MB8214:EE_ X-MS-Office365-Filtering-Correlation-Id: 48e52a11-1585-450f-6627-08db6117d909 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oQyTcyWUg7+clYu6S7DQEesyA/PyrE6yL/PCtIOp6T0m9Bkh5asVuQwPTODWCpv9jrf0Azcg16fPbAFje3wqFnXct9sd+1i3PH2m79WHXuaSOzcxPZnLNykZOKwxsKFCeLKgXAzejqSB0NbKChyAtdyqy9srWi2BGF43eQ2r0i1Pf2ukqx2RkemNNx7u9K+DgtVND32CJ4ruvMBwR/csnTKbR0D0eTCeII09AE2y1DPIMfCZVvU8vK1xFDl12iQQOjTEUdy1WIMlmuHvLdUNi0Hlwq0JEqfPCeiV5UPtizH1CW9ek0RkrPgwCMmJpjuPs4yzRIglxuV/Lz0fN7NUNKkJswgbcx2OIpjjkYl00bUDsnsKes4g1mtmPEBL0e3kOnK8wAK5S6cwSGY3+OFQuYodle+wCCFxwgOD1D2sczmrl4sUxOwkj8SWweJomDlqcuQu9j+DDPjtPDgaiO9Fo1D+3Y15OugLarYZXxit9ugr/XMfPfm7IcwwiNIGXWZ9jhpd8c6Ev5wCiE93BvmzxMc518Jw6vyXSgHxSVjQ4q4jAzVQd8GjYNdd82xEP6qxkCH812QJ6BxxRwWFC7eKhCFTmd2CoXdgSDWbFXm+y/kzNdmNtFcJ8LttOgJuMrWE5V7zPRFSk2o9xyML9ngKkao/J24L3Rs0Syq1Zlt7aphmX4KGtc8NNMCVGY0VPDXx0CxLgYdEAdWa6k0iMU0U959OcRSXSter1hBmyhNVOJBfIFunM/pZKNgao60/LwgPpMMlfhaWNB+q1ZjIYhSddw== 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:(13230028)(4636009)(136003)(376002)(396003)(346002)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(186003)(16526019)(2616005)(41300700001)(426003)(336012)(83380400001)(1076003)(36860700001)(26005)(7696005)(6666004)(47076005)(478600001)(110136005)(40460700003)(54906003)(356005)(81166007)(82740400003)(70206006)(4326008)(70586007)(40480700001)(316002)(5660300002)(8676002)(8936002)(44832011)(2906002)(86362001)(82310400005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:12:05.5064 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48e52a11-1585-450f-6627-08db6117d909 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8214 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767329056190331392?= X-GMAIL-MSGID: =?utf-8?q?1767329056190331392?= With the Interrupt Remapping Table cache disabled, there is no need to issue invalidate IRT and wait for its completion. Therefore, add logic to bypass the operation. Reviewed-by: Jerry Snitselaar Suggested-by: Joao Martins Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 0c4a2796bb0a..51c2b018433d 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1273,12 +1273,24 @@ static void amd_iommu_flush_irt_all(struct amd_iommu *iommu) u32 devid; u16 last_bdf = iommu->pci_seg->last_bdf; + if (iommu->irtcachedis_enabled) + return; + for (devid = 0; devid <= last_bdf; devid++) iommu_flush_irt(iommu, devid); iommu_completion_wait(iommu); } +static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid) +{ + if (iommu->irtcachedis_enabled) + return; + + iommu_flush_irt(iommu, devid); + iommu_completion_wait(iommu); +} + void iommu_flush_all_caches(struct amd_iommu *iommu) { if (iommu_feature(iommu, FEATURE_IA)) { @@ -3028,8 +3040,7 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, raw_spin_unlock_irqrestore(&table->lock, flags); - iommu_flush_irt(iommu, devid); - iommu_completion_wait(iommu); + iommu_flush_irt_and_complete(iommu, devid); return 0; } @@ -3048,8 +3059,7 @@ static int modify_irte(struct amd_iommu *iommu, table->table[index] = irte->val; raw_spin_unlock_irqrestore(&table->lock, flags); - iommu_flush_irt(iommu, devid); - iommu_completion_wait(iommu); + iommu_flush_irt_and_complete(iommu, devid); return 0; } @@ -3067,8 +3077,7 @@ static void free_irte(struct amd_iommu *iommu, u16 devid, int index) iommu->irte_ops->clear_allocated(table, index); raw_spin_unlock_irqrestore(&table->lock, flags); - iommu_flush_irt(iommu, devid); - iommu_completion_wait(iommu); + iommu_flush_irt_and_complete(iommu, devid); } static void irte_prepare(void *entry, From patchwork Tue May 30 14:11:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 100873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2215419vqr; Tue, 30 May 2023 07:18:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wy7928l4Il0NYWbmWg0lBrYQgnGvzUgsJJituLD3lo5OJDzYBXnfKqwOKNCsPcJMJMrDy X-Received: by 2002:a17:90b:398:b0:24d:ebfe:be93 with SMTP id ga24-20020a17090b039800b0024debfebe93mr2733955pjb.37.1685456292544; Tue, 30 May 2023 07:18:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685456292; cv=pass; d=google.com; s=arc-20160816; b=kbEhalHWeDmiQYWWaaG5wmoVgkmw8CQGbEWyplm91UG8n8wyccvCTq/Cai8REZ9X2o gDQ91MzRAubVUkoZcnXNF5h2thae7eMlM9lk8fGrSR2gWtqOgx+nduPjtPFl36NEvGhA PLf3kyB8JVgO9A5H10b6aG1EajjBZk8nbPnDw86hcxQ+sWV6eU2QAUk+Kup2G1R7ScWC 800eO/u3hFnTdqrkvcrKH3+aO9bpb2q0InaBJp7FrdZJuYmCO+FL85PTbV5lTc7p+Gxp 7NogHJV7TVSApjvsRqpEBBG8OzvnrMH3aSvpOk3aqkjjmBOREvD0xK2GOrI1jEbUtbj9 LMHw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yVqVpbSQ/trAhvaBLYKV0USAlWtHJf5UXN7XTgy/4Kw=; b=iMrit9WpCu/la9hqMD87/rd1Ww9rJMh1gS6SRUyDMyCLhOxYK4eUZ+PUA78eB4m9nG l/PBA6p7YYEk2fX0SSBxF/XspqhXCqwm3D8z8LZqwgEL5HKlAvTI5sz2rarWCjvioo6G xdB3a7B6NkH+2fWce4rdPte/KwG8E8n8tt8C//qKIFSTXld/Ld/M3eOHa/C4Q+6laKa8 BstowcjRM7qZA/NBQkO285b09bEN8QXelIBSvS3ixW5gsWcZr/vw4GDsvuIGiRCtL2Uz uAZiVVlpN2BAuytOx2k6ddgEX5xthFRvPhsm36PbS4F7rOARpwEj7JJ9Wagv2AC1p0Ba QDRw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="uP//OT8U"; 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 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a637e4f000000b0053fb69a6397si1257061pgn.587.2023.05.30.07.17.59; Tue, 30 May 2023 07:18:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="uP//OT8U"; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233016AbjE3OMS (ORCPT + 99 others); Tue, 30 May 2023 10:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbjE3OMN (ORCPT ); Tue, 30 May 2023 10:12:13 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2078.outbound.protection.outlook.com [40.107.92.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABFACFE for ; Tue, 30 May 2023 07:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BOdpDNO4kQZUBwd0sYzpQff1saappuN6OZEnTym7qM7YHBIJxDr26aIBo9tijstIbtycgoncZaQ+gFu+x/g5GcNJAn0DMTTmGZrOTuNQOdWedC5Kpi6ZnHf0pHc11Jc6Z9n1lGf+WPX7Zf2TNRWRsKCJawclHwYBWi+4bkW/5VJHIarJC6c/jLcXfc08AKIz0qa8kTIsero+UEf41btRwfqdOIBatqR3Z/0/VHeR3w2/gLyQL3SJ7i+4Q+a9jHVV3UYwiQFnyOmBejluYpT19lOznF96UAysVCi/JH/VdSEco6P6QhbMFoDZEYpDhRNgMemg9Il11E1jlhR1XkNLpA== 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=yVqVpbSQ/trAhvaBLYKV0USAlWtHJf5UXN7XTgy/4Kw=; b=V1cTBnb4Yny3mjnhGXsYI1bOVCKoVPqCB/ovTke4gmKw7QgB1lueZUmWaO+6neVOIDDoFe2GkRqJfKcg/77ME4yUJuJsd/3luwcMo+AQ2baN8G6gxYM+MuAcCsn6Kln7n53BlqLVR4rLQ3qpNVcTipysp3f1V2zHPWzfjuXkgbkRKv9dNUk6d1UN0qzujINaKYXGotjGxYs2f0ZEaqnLtjbYSPuMaR0XdziWfV4UOhq6lflJz00Srb3RRKElFSVLPpbyy8mQuyRyl1WNkZWVNnsP4w3JEfOxDdlWR8j2znDErUIu12DR1SxvZs0YgSiyMpiu4L/cofvnnGGuIpVU2w== 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=yVqVpbSQ/trAhvaBLYKV0USAlWtHJf5UXN7XTgy/4Kw=; b=uP//OT8UsVgligOL3/2BQCwDESpy/ROXBbeTeveZEhhEpYiSUXNcwPUKu5pZPQ4/5V2tOYUeSoRVSQmnDOcwiZsw4LT4YjgXusN5rGBnOkaKnh+sPnqOBaUDckm3dJdJGd0aBCufnqf8jJoJvxYcYpkfjy5EnPMuie13BRqXFTU= Received: from SJ0PR03CA0256.namprd03.prod.outlook.com (2603:10b6:a03:3a0::21) by PH7PR12MB9222.namprd12.prod.outlook.com (2603:10b6:510:2ef::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:12:07 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:3a0:cafe::9c) by SJ0PR03CA0256.outlook.office365.com (2603:10b6:a03:3a0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23 via Frontend Transport; Tue, 30 May 2023 14:12:07 +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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.22 via Frontend Transport; Tue, 30 May 2023 14:12:06 +0000 Received: from titanite-d432host.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.2375.34; Tue, 30 May 2023 09:12:03 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 5/5] iommu/amd: Improving Interrupt Remapping Table Invalidation Date: Tue, 30 May 2023 10:11:37 -0400 Message-ID: <20230530141137.14376-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> References: <20230530141137.14376-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT044:EE_|PH7PR12MB9222:EE_ X-MS-Office365-Filtering-Correlation-Id: c425a9ca-570c-4c04-e2c4-08db6117d9eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jEuSmauE/qiNR/KT4EpObdkSQyGBz+chsLxt4ee/3DrisOdtMZWULgqtrY3hNCsubrqJ68ntJFDmtv4jA+Ne8sp2JHOcfWsrOHx7W/0lN3873NxG31FaCvPI78N5GlrSk0SZp8vn+/fs08V9BnA6TGjXg2tsqafU98fhrLGMOg22PeIp2H4kndWhdQCzziv6N96f55t0qQlYHMhuSti0uDxLhOhtPPVL4Zpn8STswm+Pv8rQyIWEVaAhUE3M/whMxWJ+FtWufyEdQcgqUdLQfHW57wEK8zAO+pC5NvNOUv9VZCNw9xywb0irqzxt1y4LD2aD6pNTsGFZWI38IqmamsFT2SAzAo0kUjfmtFJpkRp8WWCxyEusO5y2GcYCb79l8tMVHPgd8dqi5O6vx7jtJDlYKTffc3TdZPgUINzOyVTVvRkRJT+6dASXEZ86pjftYA00Ha5scgblOXR1ggnrN8y44uRUmDs5E15JSYVBpe8Jd6BISKCdHuZLTQFYmpLGephuyVlsNenUlDJxXw270mlrnG5/tDm11fiYwAf+FHOj6Luizes+KFPNltjUH2LcZg/BwfGkhq8hjwMkJ9d9U7COl1YEzMSTkTSQ0/Bx1TkvA5aav12kH5fAQS0JZOzRk1OYlP4ARNdhb2yqVIlNEX6zSJyjcKAEhM2f1rKFo0FRy1TUO8QMJynbYKfCAh2EivZEgiMHT0NxsVlhVNB7czRaN/W3ny+YzBkErGBPjAxr6v2zc7zix1HjwTAbG2KpFbrAjr7IgN/OXcZk4E33lQ== 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:(13230028)(4636009)(376002)(39860400002)(346002)(396003)(136003)(451199021)(40470700004)(36840700001)(46966006)(186003)(1076003)(2906002)(16526019)(36860700001)(2616005)(36756003)(40460700003)(83380400001)(47076005)(40480700001)(336012)(426003)(4326008)(6666004)(316002)(70586007)(70206006)(41300700001)(7696005)(110136005)(478600001)(54906003)(356005)(81166007)(82740400003)(26005)(82310400005)(44832011)(8676002)(5660300002)(86362001)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:12:06.9907 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c425a9ca-570c-4c04-e2c4-08db6117d9eb 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9222 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767329017561400778?= X-GMAIL-MSGID: =?utf-8?q?1767329017561400778?= Invalidating Interrupt Remapping Table (IRT) requires, the AMD IOMMU driver to issue INVALIDATE_INTERRUPT_TABLE and COMPLETION_WAIT commands. Currently, the driver issues the two commands separately, which requires calling raw_spin_lock_irqsave() twice. In addition, the COMPLETION_WAIT could potentially be interleaved with other commands causing delay of the COMPLETION_WAIT command. Therefore, combine issuing of the two commands in one spin-lock, and changing struct amd_iommu.cmd_sem_val to use atomic64 to minimize locking. Reviewed-by: Jerry Snitselaar Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/init.c | 2 +- drivers/iommu/amd/iommu.c | 27 ++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 486a052e37ca..2fa65da2a9a5 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -744,7 +744,7 @@ struct amd_iommu { u32 flags; volatile u64 *cmd_sem; - u64 cmd_sem_val; + atomic64_t cmd_sem_val; #ifdef CONFIG_AMD_IOMMU_DEBUGFS /* DebugFS Info */ diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index fc0392d706db..16737819f79a 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1750,7 +1750,7 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h, iommu->pci_seg = pci_seg; raw_spin_lock_init(&iommu->lock); - iommu->cmd_sem_val = 0; + atomic64_set(&iommu->cmd_sem_val, 0); /* Add IOMMU to internal data structures */ list_add_tail(&iommu->list, &amd_iommu_list); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 51c2b018433d..57ae4a8072d3 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1182,11 +1182,11 @@ static int iommu_completion_wait(struct amd_iommu *iommu) if (!iommu->need_sync) return 0; - raw_spin_lock_irqsave(&iommu->lock, flags); - - data = ++iommu->cmd_sem_val; + data = atomic64_add_return(1, &iommu->cmd_sem_val); build_completion_wait(&cmd, iommu, data); + raw_spin_lock_irqsave(&iommu->lock, flags); + ret = __iommu_queue_command_sync(iommu, &cmd, false); if (ret) goto out_unlock; @@ -1284,11 +1284,28 @@ static void amd_iommu_flush_irt_all(struct amd_iommu *iommu) static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid) { + int ret; + u64 data; + unsigned long flags; + struct iommu_cmd cmd, cmd2; + if (iommu->irtcachedis_enabled) return; - iommu_flush_irt(iommu, devid); - iommu_completion_wait(iommu); + build_inv_irt(&cmd, devid); + data = atomic64_add_return(1, &iommu->cmd_sem_val); + build_completion_wait(&cmd2, iommu, data); + + raw_spin_lock_irqsave(&iommu->lock, flags); + ret = __iommu_queue_command_sync(iommu, &cmd, true); + if (ret) + goto out; + ret = __iommu_queue_command_sync(iommu, &cmd2, false); + if (ret) + goto out; + wait_on_sem(iommu, data); +out: + raw_spin_unlock_irqrestore(&iommu->lock, flags); } void iommu_flush_all_caches(struct amd_iommu *iommu)