From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 3E09D22173A for ; Fri, 19 Dec 2025 07:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766130711; cv=none; b=bIpwF3bfq1XTG3Wd+njb96wJpHuYFQO1tA2TfHIl5YtEa3gP4x3QOmArW1za0DjybTsz5jHt0FIYXQEn4RbaU0KQbJJk0SYt/OyfQ6HJi+py4k+/p6OpbUe/iatr6v59hJfFpNsrTpfj5Np+UW0epsoWsgAzhxw8ZnKuOp1ZViM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766130711; c=relaxed/simple; bh=6i7Lhre/JCY8yLJrOjxAnnD3DEoR4wlXovF0Nmi6pMU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=eznbHuHWZHd7BD8vkzj2MDYv12VvCNNHJIhg99h8KSlSVc+KEMZdvT0xtnhS5HnHUUCX87ODHlN1cQtmrLD+GWrIgICbloSR5Lfa7atDgN4zRKtAWL5Ps6tk4wuEnygjd6iEyQwfCsqkgu2awSmdq94ii90vRfj32EHM3la0Od4= 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=MBzBCzVy; arc=none smtp.client-ip=209.85.161.46 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="MBzBCzVy" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-65962c714eeso747226eaf.0 for ; Thu, 18 Dec 2025 23:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766130708; x=1766735508; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=41Gw+CNEv8JCYmTFPHgaksUdYbCOdfOME9GmEPP9m4k=; b=MBzBCzVy/tblKCVaZUOeFow3/JzPrzv8MK45tlS0plix5i4Xe3dGVyu68KhL3BoVo4 S6pRSbdOkdc7meP1IPu06URSynI9kPzbKFzdraMxoRtMuLSU7LCt59onT6C5Jng2XTV+ HGGUZZGJgj4rnCdb8y6U6jJCqimSa8qqXHvO6aGQtrSiIF+VoiAQwBbQzk0zaEvkB1a5 jcum2vBpv66xjsGIjws7DvNxjGAp3B80FPCUVegWzolMAIjg1Bo7UpMxXH7m65FcNdnp sNpyuJzyXQ0ASPJO+kxNWdrVjIlHBamoptdI/W1NJoH6OCxadXcFWraznTBtztr5hzHo do9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766130708; x=1766735508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=41Gw+CNEv8JCYmTFPHgaksUdYbCOdfOME9GmEPP9m4k=; b=EP6ZdwTdjVZEyZagRG8Oh/rQJOQ84jZ1yRXuQPaKQw3YDzvRrDsyKicQqZTLgEHXeK T9WByQcnpqyDUyBsGv48PCO4J8WOAVLy2tobnJKd0X50RL87hrmC5Epcj+N5CeK8OmNq uj07r1y2Z3a8Bt1s8RMPa1zi+CQpg4z69uqQTlrhVVpj1pq9kiveBmnPK+1VLJiZnC5P gMSnkByuXs7L11x+y3zPsZpES6lmX7Pz0gmTXUhJRXPu0aU865jBkxPPOIkSsZhLMY9F a2tpo/KVx0ruvz0ilh5nqqLrSbWRu5WfhDvjo3gSdBTElWEFwdsKwCXjiD22pIwgtROx NfhQ== X-Forwarded-Encrypted: i=1; AJvYcCUOl9Ix2reXQk4iBLGLWEgzvhq6LexDwCcgb55Ie9d9N6dUXFEaXySZN9MLQcoPexYy4JxgU9BCj8AYX44=@vger.kernel.org X-Gm-Message-State: AOJu0YwyghOd4N1a1Vk/cZhYbuqRZTc+06hlP0OUnZpUEZ66DFjOd2OZ ALbw8raeTTio4Vye2E0MoAUFFubLG7eADUT7KZV1jjOGryggwDDb7Zc9do9c1g== X-Gm-Gg: AY/fxX4latOylv+XjyJscRW6etVnj5WktoIIbmiE6LLGqyB1Mc/CKgIeX4XpT+sqhrC 3YCPNVOZGcFiYB8RoDU9rCugknbEtsEbA5ChNR9vczS7YtVPwyryXxc/z9qu/Zv9+uEoba8RPWk hbupAYFYOqPEGakLG5LWMwp8V5roDivSWbTGeOg6eI4pY6xfcHi5H4ZckJnBMYR0y5qPaYLfdSO HEWN54rsYd5bXkAT3+ZuUKaMQRZBRJPISWwicyJnNZ86SXx3/I0F2lFe7Bm/8VWxv1Q2dsqwDuQ XO2cCZexo3pwWkN0gHfUUL+APLqzLedtLnficl+1SBWnZS5NPyicEY3dpcdulG0WpXwD5PWlk3F 6TVykvcYxidnPgZZ8TF34nxsz+o4KnP/Vf8R3FGIZ3k+oJ4SNi0l1URgHJXhIT+fUZttt6iOa2M b87F+qDy6AHIFV9+qNPjYQ X-Google-Smtp-Source: AGHT+IG3BJRPOOEZ0WvlC5Z+hTnZkugL77JSmHKLal4jtBj7IefF9CMWnN7OGgSRa9VvlcJ7gNULnA== X-Received: by 2002:a17:902:e78c:b0:2a0:d0ae:454d with SMTP id d9443c01a7336-2a2cab4335fmr41005055ad.22.1766124302656; Thu, 18 Dec 2025 22:05:02 -0800 (PST) Received: from Barrys-MBP.hub ([47.72.129.29]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3c65d66sm10810765ad.20.2025.12.18.22.04.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 18 Dec 2025 22:05:01 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: catalin.marinas@arm.com, m.szyprowski@samsung.com, robin.murphy@arm.com, will@kernel.org Cc: ada.coupriediaz@arm.com, anshuman.khandual@arm.com, ardb@kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maz@kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, zhengtangquan@oppo.com Subject: [PATCH 0/6] dma-mapping: arm64: support batched cache sync Date: Fri, 19 Dec 2025 14:04:52 +0800 Message-Id: <20251219060452.85288-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20251219053658.84978-1-21cnbao@gmail.com> References: <20251219053658.84978-1-21cnbao@gmail.com> 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 For reasons unclear, the cover letter was omitted from the initial posting, despite Gmail indicating it was sent. This is a resend. Apologies for the noise. 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. diff with RFC: * Dropped lots of #ifdef/#else/#endif according to Catalin and Marek, thanks! * Also add iova link/unlink batches, which is marked as RFC as i lack hardware. This is suggested by Marek, thanks! RFC link: https://lore.kernel.org/lkml/20251029023115.22809-1-21cnbao@gmail.com/ Barry Song (6): arm64: Provide dcache_by_myline_op_nosync helper arm64: Provide dcache_clean_poc_nosync helper arm64: Provide dcache_inval_poc_nosync helper arm64: Provide arch_sync_dma_ batched helpers dma-mapping: Allow batched DMA sync operations if supported by the arch dma-iommu: Allow DMA sync batching for IOVA link/unlink arch/arm64/Kconfig | 1 + arch/arm64/include/asm/assembler.h | 79 +++++++++++++++++++------- arch/arm64/include/asm/cacheflush.h | 2 + arch/arm64/mm/cache.S | 58 +++++++++++++++---- arch/arm64/mm/dma-mapping.c | 24 ++++++++ drivers/iommu/dma-iommu.c | 12 +++- include/linux/dma-map-ops.h | 22 ++++++++ kernel/dma/Kconfig | 3 + kernel/dma/direct.c | 28 +++++++--- kernel/dma/direct.h | 86 +++++++++++++++++++++++++---- 10 files changed, 262 insertions(+), 53 deletions(-) -- 2.39.3 (Apple Git-146)