Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1283673pxb; Fri, 1 Apr 2022 09:10:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznmAWLQfSnI7t1OM2Y+XLAh5grNkQJyoAmCFBLSMv5U1gQEDsKSR8xQqCrIaToijVg14gN X-Received: by 2002:a17:90a:db08:b0:1c9:7cf3:6363 with SMTP id g8-20020a17090adb0800b001c97cf36363mr12722207pjv.35.1648829449168; Fri, 01 Apr 2022 09:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648829449; cv=none; d=google.com; s=arc-20160816; b=zAPrDOe07cDHGKFifAjIQFIYznjtr3rQBQLyHe26Qz9SCJuDVHcueHUx0DZl6Tb8YM MJmU0Lug6eRmSSf/w/m+ld8dRRqdXLgXj6xaBr4opFxM/8AQS+ErOq5BAW4Dv8az9R5I /C1D3ienSo5Mn0RbPBD9PoiyscxyS0R42eyqvaVIyvsYbVqQoLGcCJn9Su8mlsGZ+5SY yu4Yfr4xV5xjuLeDMpq/mGX7ohVAhSH1b+zqB+D+EnxoBLKmlTwTVzRBNgvrhOlavcok q6G9kzcNONku1MRHdEqb9i6ZkMK7lJGYT2+ADO6mMuYpZKNU2bbhY0uTOVo7WUgwaAKt 245Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=yarhBo2tFnfNVxqwwqB638EI650JgOv95CKAJieVYZc=; b=Ss1YksSVves3l9xr67/2BoVv4yHvDzhb1ziEr/dQ75/KQyYr4kVLDLhlSH/xOFvOMj e4gPyqI8GFmveG/kbENFys46bOxGXhJJUCF7YJZriRrpy6EAF5pl9eQ5gvkUMywAcx+L c4Aw5lWUahkUYQ27rTk8EZ4NIgp2UUFO55vEDAd50SGK46VFpWwCUsLDVhx4rZIBhu0V ApBcf3M23AzdPxToxjWJwnqQWwhhzzxZYZ2SJ6YA3PoYTH8nXZwwrjMBkIoZZDjoEA+x BY9AVWfveOOxo3QE7K7SEdCQBbwFM4rJ0N9PMkymi+U+ypLeO2w1gL3cDkt75UjsU6v8 Lj6Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a170902c95100b00153b2d1640dsi2772606pla.21.2022.04.01.09.10.34; Fri, 01 Apr 2022 09:10:49 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245707AbiDAGox (ORCPT + 99 others); Fri, 1 Apr 2022 02:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344079AbiDAGnj (ORCPT ); Fri, 1 Apr 2022 02:43:39 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C05E9264F58 for ; Thu, 31 Mar 2022 23:40:19 -0700 (PDT) Received: from mail-wm1-f41.google.com ([209.85.128.41]) by mrelayeu.kundenserver.de (mreue107 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MPXQi-1nMTYJ2eJe-00MddZ for ; Fri, 01 Apr 2022 08:40:17 +0200 Received: by mail-wm1-f41.google.com with SMTP id p12-20020a05600c430c00b0038cbdf52227so877785wme.2 for ; Thu, 31 Mar 2022 23:40:17 -0700 (PDT) X-Gm-Message-State: AOAM530l5h6/pQQT2y69dB5WcUjM7hNsiSjX0VVey5NfKjV9YgHd5CRu yzbW9TIgn+8LDxo5A0m8yEBF57iqtOzHrMrJvsc= X-Received: by 2002:a05:600c:4ecc:b0:38e:354d:909 with SMTP id g12-20020a05600c4ecc00b0038e354d0909mr7594064wmq.33.1648795217089; Thu, 31 Mar 2022 23:40:17 -0700 (PDT) MIME-Version: 1.0 References: <20220401041615.3296387-1-jcmvbkbc@gmail.com> In-Reply-To: <20220401041615.3296387-1-jcmvbkbc@gmail.com> From: Arnd Bergmann Date: Fri, 1 Apr 2022 08:40:00 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] habanalabs: fix build warning To: Max Filippov Cc: Ohad Sharabi , Oded Gabbay , Arnd Bergmann , Greg Kroah-Hartman , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:7/apYVceyzMHHgjhbHbSAYnE7h2T/G9qv4kwD8wrvsXM5e+LFSL S+EALX0C6wX+pnBlIUgazT457a+WA/Fix/gLOaODFCAOmRs20bK7ADIcuz7N9+fIwReGT8T bEiq2viY6ow/wjNfiTCMESnKlz1oWojzGZ8Zoq0Itm+Yqkoq03s0VpOFwjN+v2DPAjuCCY5 oPtTyUPYv9wq//NP+AppA== X-UI-Out-Filterresults: notjunk:1;V03:K0:yzVWTzNIuSM=:HpOTpmiDGwk6lkLB+VVzz9 CF9Pc0gNQLlmr0cJSjeqKvctG4hZIxmvuv5locXyPvZ2FfWIUePBWRZHmG3BFdmc+Kj02QJzi L9tovfBMfuvAZ1zF8Ev6aZk/YXRyGFwN+i97gtpgi4xzJQg7ksGx2lmf+JfiGLPB79HWjrkrN QTXDdXzr9roetm/PT0yv46BJiRq/BkDZJZykAgONn0NJNAHmOsyrPTxLA/tgtB2xp2oQMVZRA CxlRoBC/RB9gS9SW9HNjdFSXbZdSA133O2NCbY47zEz2PCdLAdQ5jJZ7EnybqZYrB2CjaobO+ ND8FWBYc8w+XwzvEwji4FWDQVjWc6ZSyZJLrWeHqWVrLApPS+p0MInmnk9vVEqAtkiy9koHUI pdeKXNlukKUmEcJqF1EjDR4O5c0Z4DxoL3e2g4zRdKsHco41pdENmF+mzyX3Q1jzdkAYgPrPH CXqODSNdzB1FGwmwlTcBJwRlzgOQ3CKrZZEBjKip+jlmbQkroQ8ucJmV0GBtm0iJ0V6oqlpqB CtgcU0EgIokGbUiRmrg/ElxYNYk7QlviBQCW0hDjy9oSzrTWxeWCHHmq3+0/5LdqeHPPxZTN6 AgOorSvqxp9+lAAFFa5dgVjSr8R0KaRCinz0MLOfa2euzam+fVbLIzMuMQ3/0smSKqdxI7MA1 TjELv3ZJM59t2RuDgQwwefvM6bqWzLReNqbHdAlswsoy4AUByqChrEm+dg6q1OI5a4ZMtbXQw 7NPkw9Efyu7+YjneCW/jnddlTGYK/aWwAbDwT4zRllceY1wVdefnusfWg8n5ZD9loXugvZJyI h9joV5u0P1gwlXxHh4dSnxBnBrs+jUQS2kcQb8Vkp5pdaqMXQc= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, 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 Fri, Apr 1, 2022 at 6:16 AM Max Filippov wrote: > > allmodconfig build fails on ARCH=xtensa with the following message: > > drivers/misc/habanalabs/common/memory.c:153:49: error: cast from pointer > to integer of different size [-Werror=pointer-to-int-cast] > (u64) gen_pool_dma_alloc_align(vm->dram_pg_pool, > > Fix it by adding intermediate conversion to uintptr_t as in other places > in that driver. > > Fixes: e8458e20e0a3 ("habanalabs: make sure device mem alloc is page aligned") > Signed-off-by: Max Filippov > --- > drivers/misc/habanalabs/common/memory.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c > index e008d82e4ba3..f0d373171d2a 100644 > --- a/drivers/misc/habanalabs/common/memory.c > +++ b/drivers/misc/habanalabs/common/memory.c > @@ -150,9 +150,9 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args, > for (i = 0 ; i < num_pgs ; i++) { > if (is_power_of_2(page_size)) > phys_pg_pack->pages[i] = > - (u64) gen_pool_dma_alloc_align(vm->dram_pg_pool, > - page_size, NULL, > - page_size); > + (u64)(uintptr_t)gen_pool_dma_alloc_align(vm->dram_pg_pool, > + page_size, NULL, > + page_size); > else > phys_pg_pack->pages[i] = (u64) gen_pool_alloc(vm->dram_pg_pool, > page_size); This addresses the warning, but I suspect there is still a problem in the code: The description of that member lists it as '@pages: the physical page array', but it is actually a kernel virtual address that gets passed to it. Since this is a 'u64' member, it is hard to tell what type it actually is. gen_pool_dma_alloc_align() returns both a virtual address and a dma (bus) address. The dma address is ignored here, which makes me wonder why this interface is used in the first place. I can see four possible things that may be going on here: - if the pages[] array is meant to be a kernel virtual address, it should be changed from a 'u64' to a normal pointer, with the cast removed. - if the pages[] array is meant to be a physical address, as documented, it should be assigned using virt_to_phys() on the pointer, with a warning that this must not be used a as a dma address (which can easily get confused with a phys address as the binary representation is often the same in the absence of an iommu). In this case, it should also be changed to a phys_addr_t. - if the pages[] array is meant to be a dma address, it should be changed to a dma_addr_t, and passed as the third argument to gen_pool_dma_alloc_align() in order to return the correct address. - if there is a 'u64' member that is used for two (or all three) of the above depending on context, it should be replaced with either multiple struct members or a union. Looking at other uses of the pages[] array, I see a dma_addr_t assigned to it in init_phys_pg_pack_from_userptr(), but map_phys_pg_pack() and alloc_sgt_from_device_pages appear to treat it as a cpu-physical phys_addr_t rather than a device address again. Arnd