Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp653418iog; Fri, 17 Jun 2022 10:30:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQ2Z+fxWUUHpwZ0YX4RFyxGwo8jhB+xGyf19H0o0m9RaDFMyDTiBhSfwOxBmHe0wrSvIkD X-Received: by 2002:a17:906:99c5:b0:6fe:b069:4ab6 with SMTP id s5-20020a17090699c500b006feb0694ab6mr10180408ejn.436.1655487042971; Fri, 17 Jun 2022 10:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655487042; cv=none; d=google.com; s=arc-20160816; b=rPXHZsxun4vTfDVStKX2qQQHG1EGsuCXLlssQumUlwCddVz4M5X4cashW3S3JwDuQh 26zItMIVD2gBJj4PdM+nx13jxkuwzu/NXTC4mWYsNo73SK/vwX9WyJ4L5O7QaIbHS7KY t5/KM0Ifg8QpNZhDHhBoYSx7h6mqj1rk75UbJQbTLyTjTRU03qKrlPnQ2Raj+ZahUoPe 8+WfVdo1jGO/+mxWBZ51BTO4LMqQA5W1lnkoumtD4yn2smbBrxnQevKmaIH72wb9H0WZ Z+Tiz9OtaQ/X950lL3c9yiRE1paHUhvXdJ8ZXIU+IZTE2Sw2DY8dwGls7Ltah/xrWOmk tFbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=bw256R5V4CPHPzhuM4+GsRBXhQw56r13l3Z80+n3+HQ=; b=xFTUDZqAegFT/IR89aAgUHV/OJqNYNEyFDLzpNwbhXmfxEDHqYlH81m6+Nj5aUE3sg 2o73e5j3MJKwuGBrtJTG+/R3r5zrdbRuSd2Wg3HlOdTtITv9EBMhPYY2hQdzMdvNpkX0 Y4nZQUN5TTEKIgXghWKgqOONh6Z+7uCwE2YWbQpWeApNdbvIpsIXBMPhgalKx3cE2MJf ux2fP2vnIHfyx9e7RDiF/JOoGcusY9XV5wz21CJpDL2GaRzg4+7Vd92onAIO5ZPD0U1b ZF+XsaRPdO+LnoyuET98s4Sk62n+59egY2pLCfMR+KJ32Ws8gdKuR8NIG75WWogV2CDq 4aHQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 27-20020a170906001b00b0071017c31a82si4677442eja.567.2022.06.17.10.30.17; Fri, 17 Jun 2022 10:30:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383250AbiFQRWp (ORCPT + 99 others); Fri, 17 Jun 2022 13:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382911AbiFQRWo (ORCPT ); Fri, 17 Jun 2022 13:22:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2FED2612 for ; Fri, 17 Jun 2022 10:22:41 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F03EE1474; Fri, 17 Jun 2022 10:22:40 -0700 (PDT) Received: from [10.57.84.65] (unknown [10.57.84.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0344E3F792; Fri, 17 Jun 2022 10:22:39 -0700 (PDT) Message-ID: <88080559-0c96-ec91-6f72-df05a2d0c5af@arm.com> Date: Fri, 17 Jun 2022 18:22:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: helping with remapping vmem for dma Content-Language: en-GB To: Frank Wunderlich , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Marek Szyprowski References: From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,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 On 2022-06-17 17:17, Frank Wunderlich wrote: > Am 15. Juni 2022 15:17:00 MESZ schrieb Christoph Hellwig : >> On Wed, Jun 15, 2022 at 02:15:33PM +0100, Robin Murphy wrote: >>> Put simply, if you want to call dma_map_single() on a buffer, then that >>> buffer needs to be allocated with kmalloc() (or technically alloc_pages(), >>> but then dma_map_page() would make more sense when dealing with entire >>> pages. >> >> Yes. It sounds like the memory here comes from the dma coherent >> allocator, in which case the code need to use the address returned >> by that and not create another mapping. > > Hi > > traced it to buffer allocated as simple uint8-array [1]: > > UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT)]; Ah, so it's trying to do DMA with a stack variable? CONFIG_DMA_API_DEBUG is your friend; it should have screamed about that specifically. Allocate this buffer properly to begin with, and free it again on the way out of the function (it's surely not worth having to make a temporary copy further down the callchain). The kmalloc flags can probably be regular GFP_KERNEL, unless this can be called from more restrictive contexts like an IRQ handler - the fact that it might be mapped for DMA later is essentially irrelevant in that respect. Thanks, Robin. > > and then called as > > nicRxWaitResponse(prAdapter,0,aucBuffer,sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT),/* 4B + 4B */ > &u4RxPktLength) > > this calls [2]: > > WLAN_STATUS > nicRxWaitResponse(IN P_ADAPTER_T prAdapter, > IN UINT_8 ucPortIdx, OUT PUINT_8 pucRspBuffer, IN UINT_32 u4MaxRespBufferLen, OUT PUINT_32 pu4Length) > { > ... > HAL_PORT_RD(prAdapter,ucPortIdx == 0 ? MCR_WRDR0 : MCR_WRDR1, u4PktLen, pucRspBuffer, u4MaxRespBufferLen); > } > > > nicRxWaitResponse contains a do-while(true)-loop, but it looks like this is failing on first call (i see my debug before call of HAL_PORT_RD only once)... > > do i need kmalloc before call of nicRxWaitResponse and if yes which flags are right here? > https://www.kernel.org/doc/htmldocs/kernel-api/API-kmalloc.html > > callstack is like this: > > [ 126.919569] __dma_page_dev_to_cpu from kalDevPortRead+0x3a0/0x6b4 [wlan_gen2] > [ 126.928643] kalDevPortRead [wlan_gen2] from nicRxWaitResponse+0x4c0/0x61c [wlan_gen2] > [ 126.939752] nicRxWaitResponse [wlan_gen2] from wlanImageSectionDownloadStatus.part.0+0xd0/0x26c [wlan_gen2] > [ 126.952783] wlanImageSectionDownloadStatus.part.0 [wlan_gen2] from wlanImageSectionDownload+0x168/0x36c [wlan_gen2] > [ 126.966511] wlanImageSectionDownload [wlan_gen2] from wlanAdapterStart+0x674/0xf94 [wlan_gen2] > [ 126.978367] wlanAdapterStart [wlan_gen2] from wlanProbe+0x318/0xbe8 [wlan_gen2] > [ 126.988951] wlanProbe [wlan_gen2] from HifAhbProbe+0x54/0x88 [wlan_gen2] > [ 126.998905] HifAhbProbe [wlan_gen2] from wmt_func_wifi_on+0x4c/0x150 > > regards Frank > > [1] https://github.com/frank-w/BPI-R2-4.14/blob/5.18-main/drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_lib.c#L3046 > [2] https://github.com/frank-w/BPI-R2-4.14/blob/5.18-main/drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c#L3604