Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2569722rwo; Sun, 23 Jul 2023 19:16:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlHi2WNlXTr1ItjALDXMBRbtXBppjQjxtfneTBG5tGRRlVT6mdZqs/2PRggQxgujHG2re2H4 X-Received: by 2002:a05:6871:60d:b0:1bb:6cca:3468 with SMTP id w13-20020a056871060d00b001bb6cca3468mr1618288oan.47.1690164961503; Sun, 23 Jul 2023 19:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690164961; cv=none; d=google.com; s=arc-20160816; b=yRCIq/UvjRaDv7/eLPvPMqag+Disey9oNhIJ+WSd6enmXSngOhg+62y6VXPEjYq1RN wJyqOgH4ONnsfTPEQEAnhmuz65XskrgOVQ1ex9wrduAkUD9KNOlA7VwZD0+d9vO1BmkH o3eRtd8ntOkpTNlHAkXx0dvr4Az8YGgKGGKpdvKcJ4Tj2xoVZXHJ2IUL9ccX7YyA3DQW tdyF73SoEKVZQmfxtfTmQF+ogiEIHY8VwVoFO7f29+i1m+xrx3lzVdNApfn1pbcKoomN ne24e3ftxfLUePYq+uWOsbNBbpI0Lr1ZeIpfDm4E71yF/L4NNiUQW1v/jKt6kwsrgcYg 2Vbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MRFPrGna+RpQntYGJojNTgUDadA3cag5oEgK837OC0Y=; fh=VD9h/6bO4Qf15fzY4wlNRU1tlyoKPeIlaSTSpT4hR8I=; b=iy9Dw28EjEtxFtLymcrBBZLggrTVhlSv4U15/pXEW1UFndHfUJ7nJLqNLqAiaaLyOf VViMSq1GbPEGy8MaabokY1X2rpvfbPAEz3gZZxMmcQZlh1o3Whvs5bcVAK5n5Brm0bLD Qpw5oE0+crjlvxHYDHzO0XjeU3H6gY1YAwsXevGmUMr7X8EJYS8688HUmJQG443nTQDT 8KEAZU+GuJMVhetNQO5AmXJtzA0ty0TUNo5MP58lPgv+o+ckHYOyrHYr/MbKanaePTPA IETqvgy5MrHSz6H/DkoOnGUEZdtf9a0ltTTfU2aFTd9DkrTRP/bzduzpHf2YrrlRZ7G2 Mfig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tc1bwUAt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f2-20020a056a0022c200b00682ad3475d1si8292809pfj.92.2023.07.23.19.15.45; Sun, 23 Jul 2023 19:16:01 -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=@kernel.org header.s=k20201202 header.b=Tc1bwUAt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231916AbjGXByV (ORCPT + 99 others); Sun, 23 Jul 2023 21:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbjGXBxh (ORCPT ); Sun, 23 Jul 2023 21:53:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2DEE30DE; Sun, 23 Jul 2023 18:44:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 81BFB60E17; Mon, 24 Jul 2023 01:18:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BACA4C433C8; Mon, 24 Jul 2023 01:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690161536; bh=VAUVrDKsxKmQTd4qU5eND6DPF6UiQpEvEcMDq2Pzp+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tc1bwUAtCfyxZPF1t0PNJ0u8tBvJ4u4AxxCrlUbjb6NikEFtVXCqOT+h4FywiG3Mb cgPWDEF0sZg1TeBoJW/unwaEjjrKptqa9mKBpTx0FGHGtVppaC7fAVtGDl1acNVZeT 8pYX/QwYu7ohr/VMfS+7gKbjdjoa0b92m4tnYlAjlu59X5hnQiNTaOEb5vRNFE99at MUdV9RIqTwxCgGI7pXz/DdAsISm1ebl0dPyCSqEXxseu5oJv59wmd3lkp7d6r3leOR hGX6KuTFXWWk3/NQQ6rndD1Iw8hyWAfFt+PQrq6VYeCTZzWwgyV1DxcfzRb97fQSDA p0Xq7y9qaGV6g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Suravee Suthikulpanit , Jerry Snitselaar , Alejandro Jimenez , Joerg Roedel , Sasha Levin , corbet@lwn.net, joro@8bytes.org, will@kernel.org, paulmck@kernel.org, catalin.marinas@arm.com, rdunlap@infradead.org, peterz@infradead.org, rostedt@goodmis.org, kim.phillips@amd.com, linux-doc@vger.kernel.org, iommu@lists.linux.dev Subject: [PATCH AUTOSEL 6.4 37/58] iommu/amd: Introduce Disable IRTE Caching Support Date: Sun, 23 Jul 2023 21:13:05 -0400 Message-Id: <20230724011338.2298062-37-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724011338.2298062-1-sashal@kernel.org> References: <20230724011338.2298062-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.5 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Suravee Suthikulpanit [ Upstream commit 66419036f68a838c00cbccacd6cb2e99da6e5710 ] 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 Link: https://lore.kernel.org/r/20230530141137.14376-4-suravee.suthikulpanit@amd.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- .../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 9e5bab29685ff..986ac2b73ea22 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 2ddbda3a43746..5a224e244be8a 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -174,6 +174,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) @@ -716,6 +717,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 c2d80a4e5fb06..02846299af0ef 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -162,6 +162,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 */ @@ -484,6 +485,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); } /* @@ -2710,6 +2714,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); @@ -2720,6 +2751,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); } @@ -2770,10 +2802,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); } @@ -3426,6 +3460,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); } -- 2.39.2