From nobody Mon May 11 07:46:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 962A5C4332F for ; Tue, 12 Apr 2022 12:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237296AbiDLMaK (ORCPT ); Tue, 12 Apr 2022 08:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353460AbiDLM2I (ORCPT ); Tue, 12 Apr 2022 08:28:08 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC3052C1 for ; Tue, 12 Apr 2022 04:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649763504; x=1681299504; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=N4WSKTydTrMHsksFWCFFkVf1bcccCKP0eWt9cxX6l5w=; b=aApql1SANmAk9GBqzMFPTK6a3aJzc7prOrXAvMXTElvFSOTdHy4JWSpF /prsx1DQCcwDVSOTYBlnJp1roc1lBKagxn3rM/MzxOetSjp3ppDxHttWv TsmWcS8O/adAYT42FU+T9PKL2yCAUZmyjWfd8LU49oi6+xRWrt0rtV5G8 m1k1t8WMxRSOBY4PbA1hM6VSIu4y/vEl8EqRN7miQ412yiGjFOiLoVe01 xI2Jr1Npbbdf+IHJzccDdce9EPYhX/wDUYdWr6XLGvGuKY94bMmgKleVv adsOK5KNiYHg8OCyd9ORsWAeCEFExKxqVUZd+ltaLajE23BQdAENwr4hu Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10314"; a="259951075" X-IronPort-AV: E=Sophos;i="5.90,253,1643702400"; d="scan'208";a="259951075" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 04:38:24 -0700 X-IronPort-AV: E=Sophos;i="5.90,253,1643702400"; d="scan'208";a="572723776" Received: from spr.sh.intel.com ([10.239.53.23]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 04:38:21 -0700 From: Chao Gao To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: robin.murphy@arm.com, m.szyprowski@samsung.com, hch@lst.de, Chao Gao , Wang Zhaoyang1 , Gao Liang , Kevin Tian Subject: [PATCH] dma-direct: avoid redundant memory sync for swiotlb Date: Tue, 12 Apr 2022 19:38:05 +0800 Message-Id: <20220412113805.3210-1-chao.gao@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When we looked into FIO performance with swiotlb enabled in VM, we found swiotlb_bounce() is always called one more time than expected for each DMA read request. It turns out that the bounce buffer is copied to original DMA buffer twice after the completion of a DMA request (one is done by in dma_direct_sync_single_for_cpu(), the other by swiotlb_tbl_unmap_single()). But the content in bounce buffer actually doesn't change between the two rounds of copy. So, one round of copy is redundant. Pass DMA_ATTR_SKIP_CPU_SYNC flag to swiotlb_tbl_unmap_single() to skip the memory copy in it. This fix increases FIO 64KB sequential read throughput in a guest with swiotlb=3Dforce by 5.6%. Reported-by: Wang Zhaoyang1 Reported-by: Gao Liang Signed-off-by: Chao Gao Reviewed-by: Kevin Tian --- kernel/dma/direct.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h index 4632b0f4f72e..8a6cd53dbe8c 100644 --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -114,6 +114,7 @@ static inline void dma_direct_unmap_page(struct device = *dev, dma_addr_t addr, dma_direct_sync_single_for_cpu(dev, addr, size, dir); =20 if (unlikely(is_swiotlb_buffer(dev, phys))) - swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); + swiotlb_tbl_unmap_single(dev, phys, size, dir, + attrs | DMA_ATTR_SKIP_CPU_SYNC); } #endif /* _KERNEL_DMA_DIRECT_H */ --=20 2.25.1