Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1695423lqg; Mon, 4 Mar 2024 00:15:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8B1cWqmK0oMuT8HqwBbD8HvyXztoySvPDUyMTPR+k7nD6WWFS7GkIDx7rUfjEzHdBb0L8PqqsBBGjv2lv4bqaF6ctOQ7qslOguZ8K5Q== X-Google-Smtp-Source: AGHT+IGh/LbZqpEX4rFPvg47qjHfIhwzEGbawpPGZWVDaGXitHa8UNMAFxRZ5ZYM/nw6LEckR4XP X-Received: by 2002:a05:6a00:4fce:b0:6e5:7480:e5b9 with SMTP id le14-20020a056a004fce00b006e57480e5b9mr8960667pfb.9.1709540146101; Mon, 04 Mar 2024 00:15:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709540145; cv=pass; d=google.com; s=arc-20160816; b=YCcpLsqzyuRWPgAJRCAYPo0CeKoXh9gWjm3HRPfVIj7LN2nfcsZ1qxEKYvZT4wBlB1 MFDrKtm3gQYZsgsa3UHY4apRYlKNhXI11MFiNR0xWNq541r6n5CYaMp4oCxz0icQ35ik TaPDF8yWHLHLQ2ygfTZxTSfYkHy1LvE9AeLNJVEDFJK+HtDmBcBU5Zqz5DZI+y8umyaa Is3b8Zlgs+Ynt8NKOAWXcprIDt+zf6pLNuqakLTLEbJcifYIfzbZgxodnlSIPTmdj2Gm IgVuuO/MFLC1MO7/z/Pw1nAc+Eud/TyaMxwIiwWmeJ7U15bKZbNxxhBw/p0vRUnH37ZB NuRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Bse7RxBmsw9s8EAGtlOoFR46L9n2YUC9/b0yiLi9LxA=; fh=1Pcwr+7jgHStDNK258JJJg8DjZmnMfMCfTu9Ox2Yvt0=; b=SuiNsOFUPNdX/btsnsRP79LxtVS87eXOXoJ6mbrRqxmhjSBl7QsLLbxanfKGFyRwlk DX1LFBTGTqGej44c9KBUKY9gFUVR+epLXYECJbpg0psxxPyeiurzP6ZuAmbCqvpUdimt /nl5ruZqOwaR2sfAB7RiQMCehJHrd8vMHoG5sEUmWLwcOcf5tfEIx+OGsmU8t002u50E sieBxdsJBIcLhOrBSGkB114pIJUoPFhbDK+c7nGlwdeinzhWsvhWMrIHwZx9aE8ljmF2 9D8XKoU6+YywXMVZ8K2KRjRPBsBKZL3+GP8Vw9OK1q+l7piDPhxaRk7dsFsz7MHF7xxO zRmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-90182-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90182-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b19-20020a056a000cd300b006e625bbfb6csi1021107pfv.345.2024.03.04.00.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 00:15:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90182-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-90182-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90182-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8ED1B282319 for ; Mon, 4 Mar 2024 08:15:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AEDD17564; Mon, 4 Mar 2024 08:15:25 +0000 (UTC) Received: from mx1.zhaoxin.com (MX1.ZHAOXIN.COM [210.0.225.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6A3116436 for ; Mon, 4 Mar 2024 08:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.0.225.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709540124; cv=none; b=vAI+IP/XDWHaMytzWMhe757uRQiUo65Kuv3hh2s4qiTXoYEqx4tFRkYuyNjj8GmIE8MXEPuj5DcR8vJai2zRGoMcxJEnTqnbGX9hAHa3bw6RJJQdKH/K52IqXKcy4v5o0d+KzJYA4QjKDmCtFEjC6qpcN8ZSW3uiAH2OCPMz21M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709540124; c=relaxed/simple; bh=VJWSqHQPMivBeqfzMOvO9PGJPKuYFI58V0eb5OjVzjo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=jdABDJgPhK1zm/arESnPx18iGthnh0KpLLZDsTXTsYKmSUgdO42mIZto24+jslaUgKnhOwIcMR0KmpIsh8u1ZEiIiE7LqHcJ3TN6H21tK8HVVA81CEJNE1ZtihN36CHbiWRWHhFiZZkx9oR1doqNahegfl1Jl8AfF6tC+RnzJuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=210.0.225.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1709540111-086e2316ee06760001-xx1T2L Received: from ZXSHMBX2.zhaoxin.com (ZXSHMBX2.zhaoxin.com [10.28.252.164]) by mx1.zhaoxin.com with ESMTP id JjMqnPvHCH8Gl0M9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 04 Mar 2024 16:15:11 +0800 (CST) X-Barracuda-Envelope-From: LeoLiu-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Received: from ZXBJMBX03.zhaoxin.com (10.29.252.7) by ZXSHMBX2.zhaoxin.com (10.28.252.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 4 Mar 2024 16:15:10 +0800 Received: from xin.lan (10.32.64.1) by ZXBJMBX03.zhaoxin.com (10.29.252.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 4 Mar 2024 16:15:08 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 From: LeoLiu-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.7 To: , , , , CC: , , , , , leoliu-oc Subject: [PATCH] iommu/dma: Fix not fully traversing iova reservations issue Date: Mon, 4 Mar 2024 16:15:07 +0800 X-ASG-Orig-Subj: [PATCH] iommu/dma: Fix not fully traversing iova reservations issue Message-ID: <20240304081507.63221-1-LeoLiu-oc@zhaoxin.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To ZXBJMBX03.zhaoxin.com (10.29.252.7) X-Barracuda-Connect: ZXSHMBX2.zhaoxin.com[10.28.252.164] X-Barracuda-Start-Time: 1709540111 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.35:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 1537 X-Barracuda-BRTS-Status: 0 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.121644 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- From: leoliu-oc For multiple devices in the same iommu group, sorted later device (based on Bus:Dev.Func) have the RMRR. Sorted earlier device (without RMRR) initialized the iova domain causing the sorted later device goto done_unlock. Then, the sorted later device (with RMRR) cannot execute the iova_reserve_iommu_regions to reserve the RMRR in the group's iova domain, and other devices (in the same group) alloc iova in RMRR are permitted. DMA iova addresses conflict with RMRR in this case. Goto iova_reserve_iommu_regions could avoid the problem (make sure all devices of the same group execute reserve iova) Signed-off-by: leoliu-oc --- drivers/iommu/dma-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 50ccc4f1ef81..2b6c6bf4bccf 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -709,7 +709,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, } ret = 0; - goto done_unlock; + goto iova_reserve; } init_iova_domain(iovad, 1UL << order, base_pfn); @@ -724,6 +724,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, (!device_iommu_capable(dev, IOMMU_CAP_DEFERRED_FLUSH) || iommu_dma_init_fq(domain))) domain->type = IOMMU_DOMAIN_DMA; +iova_reserve: ret = iova_reserve_iommu_regions(dev, domain); done_unlock: -- 2.34.1