From nobody Sun Feb 8 02:22:00 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC307472DB1 for ; Thu, 8 Jan 2026 11:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767872337; cv=none; b=fWFpIc7ZkBF43aPhSYtT+yVSJ0G1w/iAhx5em2ZZxmeU7YT1nEYIWClPPqs59iFmNAFC20vpj9Kz2vfLxiuFCmuJ3wQbFbBnob2c1OESrHhM76r1Y+BKn7QP1KqM09v6Xth+j2KcWg6GEur6LGav/goaq1nm5NJPOc+MJ9zICmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767872337; c=relaxed/simple; bh=Fx6BCdFN7l0mjaIYuJOQklh2nn/iWgHSBjgfKrDUd3g=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Qx6T19aNeShncwZqrBRsWRF6ui1c/nns4rT/+nAoWt0jWTJ8VWjCJt9MMfRtndIt6ysCKM7eiDp+jz05yO/E2MCHQZ5DF7rbZvYuCQ5xWmkAKFoyweSKNEaaiMdTVKSdcMGkY3uFLgVQsz5kvybhrGdHj20LKbhQokb/eEgmJ1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0QmIQl1Y; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0QmIQl1Y" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-47a97b785bdso24873195e9.3 for ; Thu, 08 Jan 2026 03:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767872331; x=1768477131; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=h+PD5I1T9SWnu5gQJxf6wuZ/2pTtA653VoNBiXR/ZCw=; b=0QmIQl1Yo7DOOdVcS7hQusKLCbn59tRhycmXtrOs/3M21IrI1mCGnDIFUxNwEXRj+M O9tYKPRSjohQ4rGrxiplPqbfP9kwoBLwZHM9XlEXXHU5ABnrk4QBp/B6sGJK279sU/Xv LLP1xMqTQl7DaOAXwhLyxHWju/Zsy7n9Bl8e0L2tOjgqsQL0f6Wr/uq5hIZlw+DggdjE GNzyQ+lhAl7M8uSzeNxUC742GydTvsp14KVYDS6abaqMypITQBuMRMJDnPIr8uIHmxmN vA+crGrNS+gYCt2x/Bu+F2KtUW3a4m7K+32qax/8ML4WwUN5NGgyA06/xDc71ox0G+uP VPng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767872331; x=1768477131; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h+PD5I1T9SWnu5gQJxf6wuZ/2pTtA653VoNBiXR/ZCw=; b=ev0I53P8yhZNNU5Rakz0X9RlPb3z254wg58qPli4ymXMZ3U2PBUfgF65dTndgxlPi1 qJJmCyscn4N6F7P+CELQFCaFVx6CFz2kjP1Ec3uY7NkQwR4uRj7k91oCnEMSDKW0ltbw 3AVQDWPEGmJu3O+OlGKFXdJRc9Lh2++UqXdEQLc71zbmKx2w6b99HCCm8sGFin3e2H31 9aRLFxamDcV2Y5rp5NEj3FbHPZULBKXYQ7DpeZ2FmGCSevRgWD58MW6Dhv9Osb7Ka2NF C+6TlHa5e42IZngMSvVxpT4RdvEC+w1aKLoAhcVoAKCNLJ6HPQQ7QiWyh2uOYYHAB/OU +x0g== X-Forwarded-Encrypted: i=1; AJvYcCWYMVc6GkpPIN6HqcCdcr1OaP5cxoQMR36Pw3N2hOzg7F/w5JjnJC8PstRHqZa045BUcAORZkHeNsmLUuU=@vger.kernel.org X-Gm-Message-State: AOJu0YxPLRRzhkISrBS/MV3uo6waze67BVR1AWjysqY0dyAPP/YLg73V 4HslcXCXHtUdYbNKZ0Wn24FMF2nfiW5G/64HbGrvb4WFb1V2vqedrjUyEYjEAJynh45gcHs/jmo OsMVrWGcnY4u34Q== X-Google-Smtp-Source: AGHT+IGr16gVlj0tGy6ZbPOm8QxP8OJb1ECy1Lx+gySYdlsvpdFscKv8yCc/e9t5dZ5OMMD/GUP08duGuCyGKw== X-Received: from wrbfs2.prod.google.com ([2002:a05:6000:25c2:b0:430:f5a3:57c8]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e51:b0:477:7af8:c8ad with SMTP id 5b1f17b1804b1-47d84b39850mr75537675e9.31.1767872331602; Thu, 08 Jan 2026 03:38:51 -0800 (PST) Date: Thu, 8 Jan 2026 11:38:46 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.351.gbe84eed79e-goog Message-ID: <20260108113846.56179-1-smostafa@google.com> Subject: [PATCH] iommu/io-pgtable-arm: Drop DMA API usage for CMOs From: Mostafa Saleh To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: robin.murphy@arm.com, will@kernel.org, joro@8bytes.org, Mostafa Saleh , Jason Gunthorpe Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As part of the KVM SMMUv3 series[1], we are trying to factor out the kernel specific code from io-pgtable-arm so it can also compile for the hypervisor. Jason pointed out that the DMA-API calls are not really needed [2]. Looking more into this. Initially, the io-pgtable API let drivers do the CMOs using tlb::flush_pgtable() where drivers were using the DMA API (map/unmap_single) only to do CMOs as the low-level cache functions won=E2=80=99t be available for modules. This was later moved to the core code [3], with possibility to convert it to full blown DMA-API code if there was a use case. However, no such use case appeared, and we can simplify the code slightly by doing CMO directly instead of going through the DMA-API functions just for CMOs. Although HTTU is not used at the moment, leave the arch_sync_dma_for_cpu() in __arm_lpae_free_pages() as this is not a hot path. Removing the DMA-API will also remove some extra checks ensuring that the IOMMU can deal with physical addrs. we can add those check at page table creation time (Something as use_dma_iommu/is_swiotlb_active However, that seemed a little too much as Linux doesn't support such topologies anyways. [1] https://lore.kernel.org/linux-iommu/20251117184815.1027271-1-smostafa@g= oogle.com/ [2] https://lore.kernel.org/linux-iommu/20251216005834.GC31492@ziepe.ca/ [3] https://lore.kernel.org/linux-iommu/7c5584d3efa61ee6b0b87efb72f24f32852= aafb7.1438195011.git.robin.murphy@arm.com/ Suggested-by: Jason Gunthorpe Signed-off-by: Mostafa Saleh --- drivers/iommu/io-pgtable-arm.c | 39 +++++++--------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index e6626004b323..0da9195155ec 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include =20 #include =20 @@ -254,7 +254,6 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t = gfp, { struct device *dev =3D cfg->iommu_dev; size_t alloc_size; - dma_addr_t dma; void *pages; =20 /* @@ -271,32 +270,10 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_= t gfp, if (!pages) return NULL; =20 - if (!cfg->coherent_walk) { - dma =3D dma_map_single(dev, pages, size, DMA_TO_DEVICE); - if (dma_mapping_error(dev, dma)) - goto out_free; - /* - * We depend on the IOMMU being able to work with any physical - * address directly, so if the DMA layer suggests otherwise by - * translating or truncating them, that bodes very badly... - */ - if (dma !=3D virt_to_phys(pages)) - goto out_unmap; - } - + if (!cfg->coherent_walk) + arch_sync_dma_for_device(__arm_lpae_dma_addr(pages), size, + DMA_TO_DEVICE); return pages; - -out_unmap: - dev_err(dev, "Cannot accommodate DMA translation for IOMMU page tables\n"= ); - dma_unmap_single(dev, dma, size, DMA_TO_DEVICE); - -out_free: - if (cfg->free) - cfg->free(cookie, pages, size); - else - iommu_free_pages(pages); - - return NULL; } =20 static void __arm_lpae_free_pages(void *pages, size_t size, @@ -304,8 +281,8 @@ static void __arm_lpae_free_pages(void *pages, size_t s= ize, void *cookie) { if (!cfg->coherent_walk) - dma_unmap_single(cfg->iommu_dev, __arm_lpae_dma_addr(pages), - size, DMA_TO_DEVICE); + arch_sync_dma_for_cpu(__arm_lpae_dma_addr(pages), + size, DMA_TO_DEVICE); =20 if (cfg->free) cfg->free(cookie, pages, size); @@ -316,8 +293,8 @@ static void __arm_lpae_free_pages(void *pages, size_t s= ize, static void __arm_lpae_sync_pte(arm_lpae_iopte *ptep, int num_entries, struct io_pgtable_cfg *cfg) { - dma_sync_single_for_device(cfg->iommu_dev, __arm_lpae_dma_addr(ptep), - sizeof(*ptep) * num_entries, DMA_TO_DEVICE); + arch_sync_dma_for_device(__arm_lpae_dma_addr(ptep), + sizeof(*ptep) * num_entries, DMA_TO_DEVICE); } =20 static void __arm_lpae_clear_pte(arm_lpae_iopte *ptep, struct io_pgtable_c= fg *cfg, int num_entries) --=20 2.52.0.351.gbe84eed79e-goog