From patchwork Mon Mar 4 12:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 209512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1373526dyc; Mon, 4 Mar 2024 04:06:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxKeNxUjJZG9Ynigwi9okJFiQQM9xq3iQXfI/+2iOZVcwzOA7zu1MQlSLA0AdSHwqD9xinkm3Nir25ZUZQIaFccvT/zg== X-Google-Smtp-Source: AGHT+IGvZOPV3ntzTaq7qhCNgorWSoWl+Dpnm+xxeFS2PnDn9pCSp46Q4g7TaM8CRo2hKK1v+5pm X-Received: by 2002:a50:cbcc:0:b0:566:2817:fb06 with SMTP id l12-20020a50cbcc000000b005662817fb06mr4961695edi.7.1709553966073; Mon, 04 Mar 2024 04:06:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709553966; cv=pass; d=google.com; s=arc-20160816; b=L37gYzDbBJQZCCObPW6cfWvoew2ZkS5SJnwxplSeMZ8Yb+AYd1sPQXryv6HfZ5nt4C Dr0X4Ey1Tscf7thU/k23A2Ft5Uq1YzwNidKK7DYM4/mlGWlfiGHz5EKkDWeXBMzWvwIG 5EOQoE6lMIaNra9U6XssGHD8DO4TpBl4cN2dMIy03xxvc5hoArfTTpLVGf3uBsRmNrCI Uy+vCUt9BlTvy8veuU1sjC9Mqvhh6WE2TyqIzSSffLtQpILpauI8dBdQshr6FA8Rogc1 5a1dQhG2KzTIWgCusHQlJO4Va8PStnkG/VJhCN3bpFlxK7EbC0zRHSK4GcUOW0n2Go2O QXTA== 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=7LMPZLOvapJ2atoXejA3a44ahzhF8IUUyxhe8thfTZs=; fh=7Qd74vAHkmWgvX4FoLzNWkOFwvz+WhB63+y1pNrSTBk=; b=ctSxmNAHGQsD6p+kkMUvaT56kt7aIkBKJDkvflUef1qYygeW9hHNI16EYQxuRPu98S NPtq5DA9n2T4PZ7MxvuBUXBiG8g2zRVGdxRjXPJxef2F4ilEnMbFCIAV+UvdUHxJBrOv RE0BI+BNDuoARXilmKY5rK4DLvzb4fBB0wiXNOdtVydyY6IX9Io0ebWcXWcKB6URTL9N MckKOVoMDMy1dNvu2KWP86LRw+k5zYw+xLMfDOJhp2LLGlwAF0GSAQUXFpcbhioaf45b 6KncMcX4pZO+NihWWlAqKOZgJKIzWTzj9ijDF+Ueuyv4mpGikmTv6wYr6LVNHn/qrYnW ZE0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-90541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90541-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y21-20020a056402359500b00566d2e3212esi2945517edc.609.2024.03.04.04.06.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 04:06:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-90541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90541-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id AE7641F21D7A for ; Mon, 4 Mar 2024 12:06:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B20573BB5E; Mon, 4 Mar 2024 12:05:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF5D03A8E1 for ; Mon, 4 Mar 2024 12:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709553950; cv=none; b=tJdc2xGo4ozsAbag/ipzBXiGDJx2Ysn2ZA28BpoepXlC4YXfAJMa78qZS+MavcTwI8qGT4rLP5K6r6HnooUu6YRbSwZykbHCULkKZzaFhHEOvokZsBuJ1olWdgSwuz/TMFa+vRo6HULVfcf3LnnXYoML3XZy+c1KH1O1lTyzfv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709553950; c=relaxed/simple; bh=KAwUc2Kbgvw1J573Drd3ZQTYc3qRXADwMtlZMDBhq2Q=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=NGCQHOUXIMSxGoblIOBp5MnlD+pvUBn8AXTTE8milBuNcDDw2+Yl6Czc6WFScL/7mmcACPlC8We9sy1rnl86S8xxjodmsi66W+MSBXlCHr81fOqdqxo8B+/3mzIcnrlnQAYy1pbdj6jznCYFS/5Mv8Nl7n/pp5IoOh7Hbl9nEI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E22411FB; Mon, 4 Mar 2024 04:06:24 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0BC463F738; Mon, 4 Mar 2024 04:05:46 -0800 (PST) From: Robin Murphy To: joro@8bytes.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, will@kernel.org, mhklinux@outlook.com, petr@tesarici.cz, hch@lst.de Subject: [PATCH] iommu/dma: Document min_align_mask assumption Date: Mon, 4 Mar 2024 12:05:42 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792597259183953725 X-GMAIL-MSGID: 1792597259183953725 iommu-dma does not explicitly reference min_align_mask since we already assume that that will be less than or equal to any typical IOVA granule. We wouldn't realistically expect to see the case where it is larger, and that would be non-trivial to support, however for the sake of reasoning (particularly around the interaction with SWIOTLB), let's clearly enforce the assumption. Signed-off-by: Robin Murphy Reviewed-by: Petr Tesarik Reviewed-by: Michael Kelley --- drivers/iommu/dma-iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 50ccc4f1ef81..b58f5a3311c3 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -859,6 +859,11 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, iommu_deferred_attach(dev, domain)) return DMA_MAPPING_ERROR; + /* If anyone ever wants this we'd need support in the IOVA allocator */ + if (dev_WARN_ONCE(dev, dma_get_min_align_mask(dev) > iova_mask(iovad), + "Unsupported alignment constraint\n")) + return DMA_MAPPING_ERROR; + size = iova_align(iovad, size + iova_off); iova = iommu_dma_alloc_iova(domain, size, dma_mask, dev);