Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1239902rdh; Fri, 24 Nov 2023 08:03:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVBr1X5XZ0NJY4YDQ6gwg3qbbKHXfV2jc4BFbaMh4YNK26wbc6q20aVAQI+DArmGFsBZS1 X-Received: by 2002:a81:d549:0:b0:5c9:9097:6427 with SMTP id l9-20020a81d549000000b005c990976427mr3166012ywj.44.1700841782884; Fri, 24 Nov 2023 08:03:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700841782; cv=none; d=google.com; s=arc-20160816; b=w/8fSYxnku1oJC97dku9fRl5UxLn7pSjzP1jikmRccSI+coCAp+RC+bgeTwWU187HO Kv+saHcBu9Y9tZmGQEvXpFyxFoCNrmljYEDj0LmwgUhPsbizl0ZxaLEi+BW81niRZh9C ucSCPw8U9Hv2OEIlM1s26oIXsVdOw1KNZSjoTjeg6JR+jFTp77t0822kRxTqUUSlQ/7V 2BS2hN0gF9dR+q4vrnpClt6LXsvRpdrIXz0JuFK4EqBv+kM79431tG9FOMAzbgDITuVg xbQLN+jL+dIQ9Qb9MEF5GZ9Id02WliHNJBo1fVgpA6sd7jBNnO1Q9nNBdipWlC8+ZHKP VHdA== 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=FIx1YrtcLveCC02iWnLW1Lr8XBOPNYeVOFiiPu2xIQ8=; fh=6PmgPY1AqDvQ3OESlvcPG4zC7xti9H1mZmb1NysvNno=; b=i0WKa1hXRTQqdu+df8mVyBe85OKWQLkSvQZepyuDLY4c7b0xM/CipxKvAXHtczJAtV xb7CkivJq/SVm2tCJDlXpl2sdYht7umE4lQGVQqugH9jVOJQLhJ+R00w6dyZOaFQyFmb 5ngCgT4JaRQ318URtccjto8XtZ7G1qqBtopCfzB1o3cwTDrFqCXnms53AUvweHDfHUdp jqjk2y52VQWSmnd7WXio/TRgjwOQRNLEuK+LOejjtLYUwDZrO7/iwRq3wMJ04n/pzm3j eL3IL0ATCtBzMTVPecEg5Tvyk5CAQ98RDwVsX7LV9KsR3f1iYxGN9h9lTScxzSQQn9Fy DCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="6aVF5B/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id fq3-20020a05690c350300b005cc4015900bsi2517653ywb.329.2023.11.24.08.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 08:03:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="6aVF5B/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 851FC80AC358; Fri, 24 Nov 2023 08:02:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345536AbjKXQCp (ORCPT + 99 others); Fri, 24 Nov 2023 11:02:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230491AbjKXQCn (ORCPT ); Fri, 24 Nov 2023 11:02:43 -0500 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45A671B5; Fri, 24 Nov 2023 08:02:49 -0800 (PST) Received: from pps.filterd (m0369458.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3AODACUB023392; Fri, 24 Nov 2023 17:02:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=selector1; bh=FIx1Yrt cLveCC02iWnLW1Lr8XBOPNYeVOFiiPu2xIQ8=; b=6aVF5B/rBs+91n+/V8KIzyk XDKQdZDb32l89xTctlCIVYJDixYEWC8v7grnnBlwcd6sOTEG/N91HqaTlU4i0ipR +FB71z+U/SwQVPjfILaCN1dRbIeQENZE3jy4vRdXSpQ9J72EdjJaOyLVO10qJmxd Og/zjepnYR6rw80ET33vhtEot7dqrXejT3H+WcToN3osOmsV3Y+uZu2YV7NDhYT6 kZOStn7gXYmBRpWe+xN0Nmw2JhVcnAhZdZctF0BLzOI2Or9AXnwFXhxGQ2iaTjfh LYNpz0scLeyPXm8/0w1j1o+dlmhdZLConsZiFoLSCzcUXRhkcS5WQILuc2H4nPA= = Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3uhr8ahh9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 17:02:37 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8141310002A; Fri, 24 Nov 2023 17:02:36 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 64A46252233; Fri, 24 Nov 2023 17:02:36 +0100 (CET) Received: from localhost (10.201.20.208) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 24 Nov 2023 17:02:36 +0100 From: Amelie Delaunay To: Vinod Koul CC: Amelie Delaunay , , Subject: [PATCH] dmaengine: dmatest: prevent using swiotlb buffer with nobounce parameter Date: Fri, 24 Nov 2023 17:02:35 +0100 Message-ID: <20231124160235.2459326-1-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.201.20.208] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_02,2023-11-22_01,2023-05-22_02 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 24 Nov 2023 08:02:59 -0800 (PST) Source and destination data buffers are allocated with GPF_KERNEL flag. It means that, if the DDR is more than 2GB, buffers can be allocated above the 32-bit addressable space. In this case, and if the dma controller is only 32-bit compatible, swiotlb bounce buffer, located in the 32-bit addressable space, is used and introduces a memcpy. To prevent this extra memcpy, due to swiotlb bounce buffer use because source or destination data buffer is allocated above the 32-bit addressable space, force source and destination data buffers allocation with GPF_DMA instead, when nobounce parameter is true. Signed-off-by: Amelie Delaunay --- drivers/dma/dmatest.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c index ffe621695e47..a4f608837849 100644 --- a/drivers/dma/dmatest.c +++ b/drivers/dma/dmatest.c @@ -21,6 +21,10 @@ #include #include +static bool nobounce; +module_param(nobounce, bool, 0644); +MODULE_PARM_DESC(nobounce, "Prevent using swiotlb buffer (default: use swiotlb buffer)"); + static unsigned int test_buf_size = 16384; module_param(test_buf_size, uint, 0644); MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer"); @@ -90,6 +94,7 @@ MODULE_PARM_DESC(polled, "Use polling for completion instead of interrupts"); /** * struct dmatest_params - test parameters. + * @nobounce: prevent using swiotlb buffer * @buf_size: size of the memcpy test buffer * @channel: bus ID of the channel to test * @device: bus ID of the DMA Engine to test @@ -106,6 +111,7 @@ MODULE_PARM_DESC(polled, "Use polling for completion instead of interrupts"); * @polled: use polling for completion instead of interrupts */ struct dmatest_params { + bool nobounce; unsigned int buf_size; char channel[20]; char device[32]; @@ -215,6 +221,7 @@ struct dmatest_done { struct dmatest_data { u8 **raw; u8 **aligned; + gfp_t gfp_flags; unsigned int cnt; unsigned int off; }; @@ -533,7 +540,7 @@ static int dmatest_alloc_test_data(struct dmatest_data *d, goto err; for (i = 0; i < d->cnt; i++) { - d->raw[i] = kmalloc(buf_size + align, GFP_KERNEL); + d->raw[i] = kmalloc(buf_size + align, d->gfp_flags); if (!d->raw[i]) goto err; @@ -655,6 +662,13 @@ static int dmatest_func(void *data) goto err_free_coefs; } + src->gfp_flags = GFP_KERNEL; + dst->gfp_flags = GFP_KERNEL; + if (params->nobounce) { + src->gfp_flags = GFP_DMA; + dst->gfp_flags = GFP_DMA; + } + if (dmatest_alloc_test_data(src, buf_size, align) < 0) goto err_free_coefs; @@ -1093,6 +1107,7 @@ static void add_threaded_test(struct dmatest_info *info) struct dmatest_params *params = &info->params; /* Copy test parameters */ + params->nobounce = nobounce; params->buf_size = test_buf_size; strscpy(params->channel, strim(test_channel), sizeof(params->channel)); strscpy(params->device, strim(test_device), sizeof(params->device)); -- 2.25.1