From patchwork Fri Nov 24 16:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 169485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1323068vqx; Fri, 24 Nov 2023 08:02:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAe9Kx9yUxeQMdvH9VW5JLZ3H4lWGchg90aCL9ROzeQcWvMa/6cKnau9/wKgWrWhROf+z5 X-Received: by 2002:a05:6808:1211:b0:3ab:8295:f2f1 with SMTP id a17-20020a056808121100b003ab8295f2f1mr4122640oil.45.1700841778620; Fri, 24 Nov 2023 08:02:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700841778; cv=none; d=google.com; s=arc-20160816; b=BPveYV/US/l5Crq2e6e4KgRcItm1ChjcQh+KFZk8M4XgBc7DdpjKt+Tfff+nhJwhEx ZufKGiMIQoobWIOKhVZoq3fXZbPnkoQOZ6Xum4dme8Mlf5YM+oqFbMh4XoNvt3TEHTes rN8aOWgoVgBz+Qw+EWX4j33O8N6CUs4SeUBLHWdgeIGpoSptBmm7FzmH1Bx2jz779TUK JmBwqnwMbZaC4A8mb0ZjKJPaFOIz5WFMowManw/heznozX4I/5I9BO5ST2OBWNOzHxZi phcSGQJSRkPo5Sk5G0o/c8iiQwVesq2GTXphLQbIsIDSOIxNmWAEKyuy/0U+jRzQ7Pum /2Nw== 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 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o21-20020a544795000000b003b6ddd7b198si1436941oic.294.2023.11.24.08.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 08:02:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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 2620:137:e000::3:1 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 C467D80AC364; Fri, 24 Nov 2023 08:02:53 -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 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:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783461868543095741 X-GMAIL-MSGID: 1783461868543095741 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));