Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4319905pxb; Wed, 20 Apr 2022 00:02:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgHN/nAZP3zqc3MK6rd3jy6jVTvNogJOfSCL3IhDOscyxMrh0W1k19nv8+C9dYdsmSh8UY X-Received: by 2002:a50:c099:0:b0:415:f5c7:700e with SMTP id k25-20020a50c099000000b00415f5c7700emr21438362edf.205.1650438151405; Wed, 20 Apr 2022 00:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650438151; cv=none; d=google.com; s=arc-20160816; b=V/J5/TJSrVCSet6FtfgUj0RcwFmb/x+rcA87vze6MbyO696BdRj7sX8vD9ExZV/AKf NE78m8DNV3hjyyrDIodZ4pXq2+4jDwMG4rgEeypPLpaY/os4wBIzP+++Huykyn4+jmoX phQPlrNhgkdsFXvQ8AbMrQL9KBZXHEjpAnCDhnhP1m+VlC0WoVcXkGvIcHMaExKPfkRa c7JXIohnI+bOb/uoomsdQJYBnYdON5UtpFv8ZDsU8JngDh7n2Nu7VyfkR2cIV8ibQQlZ X1qhm7EJAzdK/KeCiKb4tJyJzGLIWYFHa1rhN37O58LW1BWfyKUVseItj6AJJjLZzllE rASw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5kqJQdZUixXUzMyKStZvjE203V+JGDE0Rg4GnUaTgqY=; b=rkhht4nP9yUHABAhka+Siyf8LqbFVdHtIGNZR/IP/FFDkbDfNko//BCgI6pz186ybz t17kvU6H+Rod709j61lTImvKb4matfXreuxn65kf6ftcMPs31Zwxa6xg+wN7oxpvRrVW v2atF/IR3AeDGberOm5ugYW8+SMAZwzYVIK2obcEGhbDQcagNPVqQm+l+vbgAg5p8hI5 HSTFsObVGoNvBO6k1vG0Vfz0usJGUh04byyjhv8YGXXHBqPcURx6xh/6KRuECuXZVhmb jSRTVwgFwFbjqw8XBQF/DI5nkLsfMcRH+3OIYzlzFL0U8KAymyyIY9knAVlNNRvi6glI xv7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp2FhIxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170906784100b006e89480fb4dsi1099579ejm.344.2022.04.20.00.02.02; Wed, 20 Apr 2022 00:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp2FhIxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240729AbiDRMjf (ORCPT + 99 others); Mon, 18 Apr 2022 08:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239805AbiDRMd2 (ORCPT ); Mon, 18 Apr 2022 08:33:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A081B7B6; Mon, 18 Apr 2022 05:26:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B6405B80EC4; Mon, 18 Apr 2022 12:26:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D8CFC385A7; Mon, 18 Apr 2022 12:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284785; bh=h6KgK4UlLuqt00S7/NelzItnrRfUYPhvikAZc4K9Z2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rp2FhIxRUpBi4yq9SCzADl9s+ZGd/BMhoK1oUS57yv5Ys6IlijTrGtqYmw9arUavJ AyYRWVKkSpWP3HE560D6EeK+DcWadfe7i6jnOiJJnhjAa5lAPlPrARGERO0MuxifVe 4B0s/J5kllzbBrz8IzFc41hQml/M180WNUxnkFng= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Zhaoyang1 , Gao Liang , Chao Gao , Kevin Tian , Christoph Hellwig Subject: [PATCH 5.17 215/219] dma-direct: avoid redundant memory sync for swiotlb Date: Mon, 18 Apr 2022 14:13:04 +0200 Message-Id: <20220418121212.884196794@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Chao Gao commit 9e02977bfad006af328add9434c8bffa40e053bb upstream. 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%. Fixes: 55897af63091 ("dma-direct: merge swiotlb_dma_ops into the dma_direct code") Reported-by: Wang Zhaoyang1 Reported-by: Gao Liang Signed-off-by: Chao Gao Reviewed-by: Kevin Tian Signed-off-by: Christoph Hellwig Signed-off-by: Greg Kroah-Hartman --- kernel/dma/direct.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -114,6 +114,7 @@ static inline void dma_direct_unmap_page 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 */