Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp776938pxb; Tue, 12 Apr 2022 13:10:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0Uwd75cRns8zLFxF5QF72Gx0CeQmJ9qrn7c1Yf5V3eDAX4bQhgZzkaDNqrVOYuSaJb2e1 X-Received: by 2002:a63:6c8a:0:b0:398:5208:220a with SMTP id h132-20020a636c8a000000b003985208220amr32104643pgc.176.1649794223446; Tue, 12 Apr 2022 13:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649794223; cv=none; d=google.com; s=arc-20160816; b=fqJdsEfDG8g1xHOuhv+9ZSARi2rqjKo3wkZ3P/EwfcMhxV9ZEGx/NzpJSM+IF/fCsx keinqLtUs01WOlsFHH/2T/JQ5tSUsEMU8JdmjRUuOoTLEc4bVcILwOZxfCJKpL8lzigl u7hry7VxRzMITfMp5VIlpE38BnD7vW5vi6LlFgMwEPgD8JNEkUPacYCoabhBsidyL0wT 2w7CIZaEzXeUJZcSQjODinGYnbHYNtwnK05huyUQzXn5MXIFOmgbwZ0JanWhzdwDTpb3 MdTilDMEG7t4LRcfatczYNOS1XYVaJA7hiPzV6bocB1fvM4A94pmMAjfrCZr0mvzj8GY wDTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k1zZiMfDe+UoXYHE4YEF1iyF4Ab8jYwjP9i3JLjXxc4=; b=QP4GH2yIFsufkaI2bHb7ABfQT/IOvv9pC+J3P2kojXv1m7oJGmsucF76VjOEudpeaP 1J4m+XWonfY4lR5vyankfy0wJbrlLFlUT7bAKtZuS6FNED3SGAdmtcZ1CddUtSTXTXpr BiwMIavVyayQro0G7+Z3JFHYW1Z+HtP+X0asCSgvE1zTrVLlw/lGoi5aO7KZByQPLpab gPAi87nBBulR4+MbOgKsqhtt5UwYIgqOEKV+lONqzIDKc3HpTuo10owrF7FLNCm+zgKU rPPZk+l40CALIbhK4Ye+iNEHo/5y2nWrYQQQks8lkGh0MwBBl2OvMrIcDum96G5Yi4VG LBdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aApql1SA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p12-20020a631e4c000000b003816043ee51si3816447pgm.70.2022.04.12.13.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:10:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aApql1SA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13C9B69729; Tue, 12 Apr 2022 12:58:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234971AbiDLMaI (ORCPT + 99 others); Tue, 12 Apr 2022 08:30:08 -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: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=force 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); 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 */ -- 2.25.1