From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 0A98E1586C2 for ; Sat, 27 Dec 2025 00:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766795430; cv=none; b=U0GDwuWskO7/ZVhnMyRJvAe1PqwLTU85CHZ89jF9TMl1F13QAJrq8Zft/6hQooIw3GA5winX18EH1BQI04pTtLadhBOLV48SzIu95F3Mm1lNifpGn6PPxlLJUBnTzj7/flYh1azbiTvpdF4/RChfWaV/9738s0tiH1rZFC2wv5E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766795430; c=relaxed/simple; bh=FYq5m/cre8Va9uIZfDVuD0yX85YIHbjbORD+rvMdAOQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XR9kuCl2QLY/U9gUd14sZGgITIV3OhyoGMkaXq1SLZff5tUTeLLW5egRD7h4GlYuwwqtbmhGOuFslQ6vr+RQN3uWDKlhF/QhZXzCM4itCk0UeptSahamdlqCcAypKkJXLPsGtJPFCL/QT8czUh4/L4u4luynkhysRF4pMDBLat8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XXyAwz7a; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XXyAwz7a" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4ee1fca7a16so63965741cf.3 for ; Fri, 26 Dec 2025 16:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766795427; x=1767400227; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/r7srQmiwZEhg1qAC5GzWj8afC3w1hmN+Jy3ezOc8f0=; b=XXyAwz7aGpjfUO5Xc07WJJzZdQ8OTHbBCLWax7fZQwi7KCZvw+MhPFNFbDt6/Ze85l 0MGaA53Qq8Iiwxyx3nLR00PxlCBqaVLlaZ3o6AKha1XdAOdqbqGdZC+gjPHzaj21pBSN ezk3X3AK9uJdoPYnODrEAQ0eKBTKNUHHTAcMD8sDMwoKNBExgxNtVPDLJuNa4PlDXuu6 1AuiI+auVsPL1UPogGfL7VCdJ0ocedlhH4uA4O7wFyI7HfU8xmWN3g/sZrxQlF1cEici X5I/byIQd9k0rX9H9zv/S6EIspf0bKFeAFL9So1qybwsiP77Z6SIhX4Vdm3nRhmLeXAd ftXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766795427; x=1767400227; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/r7srQmiwZEhg1qAC5GzWj8afC3w1hmN+Jy3ezOc8f0=; b=nIe9hIpezu+KoQ6BgjD8B0JSVKD1NKaYHY99l7c0GtNh7IREw4VlEYPW8Gx/EQvR1B S9lYnCkESCelherLIrmVBEQyWZ5WqOk25rRyyUShovWR/2JFUCFy7d/pIjQVCXbc+SNc y/HbCojNK5wHYzxXve+gGg9eu6FlcSr+CpxYJ4rF4OUk1tayMlsXkxkHW+n7btfeBsG5 Zo5oNckrvE+kIuLaZ1wZZvZOG93opSIOsf7K4PBgiJCi+nHk6dCjMieFb6JFrnCdDvCf yhdx8iWqEpzl9KO6H8YO0d8SfqXDRcOkeyK8OZb6rIx133VKyNwsMLJnUHXEW7bmQmUo 4hvA== X-Gm-Message-State: AOJu0Yz+vOMUTBI/HFHmSgLAIRVg4LK+Z7DD5C89Mk8pRZA6DpMHtvHz 8LP7RVVyRoBDaYXeqEbKASfKbhPezJIBYF8PSkwccvRV75Zd/fLFwqBlPM+xCjeu X-Gm-Gg: AY/fxX6taUvzLY0V7YKzth5wymWBHhE3fZk7+gI17Oyp6F/I6QRyVI3jh6Ixipb9l3G PXwgOrpBp8t0t/qpHKejmcn87ikrmtVrOP9hCk1O0HxuQJwWVgb/OjyeOFPL9HA8v9dz2JAK/pS Yur5ZOt6wrsbCPV2bg+lQpAdIF5OeH/mih/ub2KnptDpyKxnvXe/JKPKStF5J8DcOUHpjwdEjnC EyBLij1Mezgda6NQQyjbbjmoLSd2RpxuDktqaOYtcs+MFP+CJY/jRm0eN2kswvynqXn581MA96S Ari1FKoVZkKZziosJ8OJvjgTP7Y8MADozVwY4wSNVnq/P+4veogNiiE9G6OpnR9Rcf9A5i3GOoi Xf9eKX/69Tq0qf26SJNKHnzZM/BXW8Rb72pmZRKhwK74GHLDq4v4W+kA4CdlOQ58uroFkQzdcBf kY+GKgYswn5LQzPvPrRSBk/Oc= X-Google-Smtp-Source: AGHT+IGRk72ichKRcHInGwm03WbYMZHXhydzrv/dBjOlD3Ki0dbJk2IiVKSqfCl2HL9XczgL6zklJg== X-Received: by 2002:a17:90a:e7c9:b0:32e:7340:a7f7 with SMTP id 98e67ed59e1d1-34e921131admr17034959a91.2.1766789597799; Fri, 26 Dec 2025 14:53:17 -0800 (PST) Received: from barry-desktop.hub ([47.72.129.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34e772ac1acsm9981428a91.9.2025.12.26.14.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Dec 2025 14:53:16 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: catalin.marinas@arm.com, m.szyprowski@samsung.com, robin.murphy@arm.com, will@kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Barry Song , Leon Romanovsky , Ada Couprie Diaz , Ard Biesheuvel , Marc Zyngier , Anshuman Khandual , Ryan Roberts , Suren Baghdasaryan , Joerg Roedel , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Tangquan Zheng , Huacai Zhou Subject: [PATCH v2 0/8] dma-mapping: arm64: support batched cache sync Date: Sat, 27 Dec 2025 11:52:40 +1300 Message-ID: <20251226225254.46197-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Barry Song Many embedded ARM64 SoCs still lack hardware cache coherency support, which causes DMA mapping operations to appear as hotspots in on-CPU flame graphs. For an SG list with *nents* entries, the current dma_map/unmap_sg() and DMA sync APIs perform cache maintenance one entry at a time. After each entry, the implementation synchronously waits for the corresponding region’s D-cache operations to complete. On architectures like arm64, efficiency can be improved by issuing all entries’ operations first and then performing a single batched wait for completion. Tangquan's results show that batched synchronization can reduce dma_map_sg() time by 64.61% and dma_unmap_sg() time by 66.60% on an MTK phone platform (MediaTek Dimensity 9500). The tests were performed by pinning the task to CPU7 and fixing the CPU frequency at 2.6 GHz, running dma_map_sg() and dma_unmap_sg() on 10 MB buffers (10 MB / 4 KB sg entries per buffer) for 200 iterations and then averaging the results. I also ran this patch set on an RK3588 Rock5B+ board and observed that millions of DMA sync operations were batched. v2: * Refine a large amount of arm64 asm code based on feedback from Robin, thanks! * Drop batch_add APIs and always use arch_sync_dma_for_* + flush, even for a single buffer, based on Leon’s suggestion, thanks! * Refine a large amount of code based on feedback from Leon, thanks! * Also add batch support for iommu_dma_sync_sg_for_{cpu,device} v1 link: https://lore.kernel.org/lkml/20251219053658.84978-1-21cnbao@gmail.com/ v1, diff with RFC: * Drop a large number of #ifdef/#else/#endif blocks based on feedback from Catalin and Marek, thanks! * Also add batched iova link/unlink support, marked as RFC since I lack the required hardware. This was suggested by Marek, thanks! RFC link: https://lore.kernel.org/lkml/20251029023115.22809-1-21cnbao@gmail.com/ Barry Song (8): arm64: Provide dcache_by_myline_op_nosync helper arm64: Provide dcache_clean_poc_nosync helper arm64: Provide dcache_inval_poc_nosync helper dma-mapping: Separate DMA sync issuing and completion waiting dma-mapping: Support batch mode for dma_direct_sync_sg_for_* dma-mapping: Support batch mode for dma_direct_{map,unmap}_sg dma-iommu: Support DMA sync batch mode for IOVA link and unlink dma-iommu: Support DMA sync batch mode for iommu_dma_sync_sg_for_{cpu, device} arch/arm64/include/asm/assembler.h | 24 +++++++++--- arch/arm64/include/asm/cache.h | 6 +++ arch/arm64/include/asm/cacheflush.h | 2 + arch/arm64/kernel/relocate_kernel.S | 3 +- arch/arm64/mm/cache.S | 57 +++++++++++++++++++++++------ arch/arm64/mm/dma-mapping.c | 4 +- drivers/iommu/dma-iommu.c | 35 ++++++++++++++---- drivers/xen/swiotlb-xen.c | 24 ++++++++---- include/linux/dma-map-ops.h | 6 +++ kernel/dma/direct.c | 23 +++++++++--- kernel/dma/direct.h | 21 ++++++++--- kernel/dma/mapping.c | 6 +-- kernel/dma/swiotlb.c | 4 +- 13 files changed, 165 insertions(+), 50 deletions(-) Cc: Leon Romanovsky Cc: Marek Szyprowski Cc: Catalin Marinas Cc: Will Deacon Cc: Ada Couprie Diaz Cc: Ard Biesheuvel Cc: Marc Zyngier Cc: Anshuman Khandual Cc: Ryan Roberts Cc: Suren Baghdasaryan Cc: Robin Murphy Cc: Joerg Roedel Cc: Juergen Gross Cc: Stefano Stabellini Cc: Oleksandr Tyshchenko Cc: Tangquan Zheng Cc: Huacai Zhou -- 2.43.0