Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1197309pxb; Fri, 21 Jan 2022 12:02:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyseC47jzlDJb6UQIHphwJJMHtD0Tlx5DrgsNXWndNOKVzZfsI6oGnyWjjR5o35SoJzi1hL X-Received: by 2002:a17:903:11d1:b0:149:57d1:acc6 with SMTP id q17-20020a17090311d100b0014957d1acc6mr5087328plh.134.1642795371357; Fri, 21 Jan 2022 12:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642795371; cv=none; d=google.com; s=arc-20160816; b=FpmcIleytKhoS8VKg6CBFF9qwm9n4vXdIqKOXO5fd/459ohu60MvZPj2cDnFiZRKoX F9lG/ejYo0aIKoK5NM4PlkVBm+ivq6nbFk0PkzQE6K8KtwmZojPYbxBoFKMQGsVFQLVL lZlYaZS4IGhIW90o265v78as/a53On+iCqeNp2i+dWMYU8GNjhzlWqsvFfWQIvtnc31a udcRYeyDoPX2XAFngfZL1UoOT1YD8+YlqM8NBHHAFe9P6RYPDQ0pTp1gRvgGwZxDgqWd KJ9LivhkTZ4yWej/pqPK+RMzR772/3oM/AAwln66aPGC7D9NBXLODI3NpmjlYXtjCtR1 ZQgQ== 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:dkim-signature; bh=SVNoxQMp637bgUGyLKUQMTT6jCUfGMhBKrAhjOzC1jA=; b=Y4g5ei8xqF6fmRXtX1yy6xpJgM9ybw40ldOq3WtRefghk14Wo31wS43dwVbUBBZE/E 0unqoFQKUrx4K/9sR3ZmOcplGZNf+5I/r7MMePbvZZUCmM6YJFM0uNBotI41oXj8Ql/q LfeY1qv1aPR+dsyrTrLkLL6Gn+w8lghgPYQ7kfnllsUeI/iVYiDlgNq0irp5MFA9JkTo +kry7VP/KDkqkifvvzfQUavm/NL8cwcVpZL6on0npkixnaB4pxUXLPZnOgtnPEeQQYmb GXdSC/5nhyTibWD/uSD7hwceeCamEi0RyDE4itf9lHF23JK4+osJUf5+drV3slKbM9oh 5PJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vw/hy5bg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u2si7674970ple.78.2022.01.21.12.02.38; Fri, 21 Jan 2022 12:02:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vw/hy5bg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244864AbiASUhm (ORCPT + 99 others); Wed, 19 Jan 2022 15:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233766AbiASUhl (ORCPT ); Wed, 19 Jan 2022 15:37:41 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 219E4C061574 for ; Wed, 19 Jan 2022 12:37:41 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id m3so13259828lfu.0 for ; Wed, 19 Jan 2022 12:37:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SVNoxQMp637bgUGyLKUQMTT6jCUfGMhBKrAhjOzC1jA=; b=Vw/hy5bg5C+CCYO+oJtgWYZCGRowuXfpuM1y/pli43kr+OiB3OWzkR6ZyW+nfXxt/s VAn2AjX3mL+nlHsEF9z/pBhrlFgPcsEA0h1sAo1ZC4YcWsIWZ0jeb+wpDXa+U2omlUCF pf/73OVbaBLU61/xMVSHktQI827IhnQn2hI4w8Tkbj/fmE8A6Xntpo4ktyfN/ATLaSyR OmbGO1wuYpDN6JCPJ6apqXqpoeOCB/ZbqWFXSeJZIDyaqZ4S0vxFtOgFaUm3xw+cnlGx I1oFnxocUDYadU9R73MgSd6PbQAJyeaWf6JpFnbLe1rT3w0y4YtI4EsZ5WHxq0hL/Blm wwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SVNoxQMp637bgUGyLKUQMTT6jCUfGMhBKrAhjOzC1jA=; b=MpuveFq9I6XMiNEH9wg3gHKo8aRhwiPj37bIV/cjWUWccsAD5KCbMTeu21dqPFTeUU /Vn1QASvXZ7OQFzRTXey6iMXaRyOzopQ+7Az1s6nIhKnvNLq4iye35I+34cPf+Og3SKE L/xMgAUFGOJ9qCfXQ7I+cQf+/lQy5iRp2miGSvU5tPgcFspXLYwj5I13wDwmEZSItkb8 om1dERAAZLRlLi7Pcy4/jOOpzVUDqDa8wgQ9EzCm5UIgx5q7tgzaHUEquzUcb0nttLVp dNdauS3EU+nE7nDV4GRf+Ytkh71WaV0Y2JUSdhoxVitrytWh7g+vq6glEGD3I2LycbPF gnEQ== X-Gm-Message-State: AOAM533hy/KMR1Q4C+kxdin8L8uLm4pyyKVKwoayJ0eqRMtkR5QC6fw0 +IadOMnFgMuaFj4Q1dyT9d9g2E1D12KA+QKc2XMiYg== X-Received: by 2002:a05:6512:329b:: with SMTP id p27mr30040874lfe.36.1642624659492; Wed, 19 Jan 2022 12:37:39 -0800 (PST) MIME-Version: 1.0 References: <20220113123406.11520-1-guangming.cao@mediatek.com> <4f88205c1b344aea8608960e2f85b8f4@intel.com> <24157767-dc29-bbdd-5428-d89ecc6b9606@amd.com> <6b8182a1-7cdc-7369-5c34-e6d0c24efcca@amd.com> <82faa62f1bc946cf2f9ee2f7d15c567162238eab.camel@mediatek.com> In-Reply-To: From: John Stultz Date: Wed, 19 Jan 2022 12:37:27 -0800 Message-ID: Subject: Re: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation To: "Guangming.Cao" Cc: =?UTF-8?Q?Christian_K=C3=B6nig?= , "Ruhl, Michael J" , "sumit.semwal@linaro.org" , "linux-arm-kernel@lists.infradead.org" , "wsd_upstream@mediatek.com" , "libo.kang@mediatek.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "yf.wang@mediatek.com" , "linaro-mm-sig@lists.linaro.org" , "linux-mediatek@lists.infradead.org" , "lmark@codeaurora.org" , "benjamin.gaignard@linaro.org" , "bo.song@mediatek.com" , "matthias.bgg@gmail.com" , "labbott@redhat.com" , "mingyuan.ma@mediatek.com" , "jianjiao.zeng@mediatek.com" , "linux-media@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 19, 2022 at 1:58 AM Guangming.Cao wrote: > On Fri, 2022-01-14 at 17:17 -0800, John Stultz wrote: > > If the max value is per-heap, why not enforce that value in the > > per-heap allocation function? > > > > Moving the check to the heap alloc to me seems simpler to me than > > adding complexity to the infrastructure to add a heap max_size > > callback. Is there some other use for the callback that you envision? > > > > If you think max the value is per-heap, why not add an optional > callback for dma-heap to solve this issue(prevent consuming too much > time for a doomed to fail allocation), if the dma-heap doesn't have a > special size check, just use the default value(totalram) in dma-heap > framework to do the size check. As the totalram default isn't correct for all heaps (or necessarily even most heaps), so those heaps would need to implement the callback. I'm just not sure adding complexity to the framework to address this is useful. Instead of an additional check in the allocation function, heap implementers will need to assess if the default logic in a framework is correct, and then possibly implement the callback. > Yes, for linux dma-heaps, only system-heap needs it, so adding it in > system heap is the simplest. However, there are many vendor dma-heaps > like system-heap which won't be uploaded to linux codebase, and maybe > have same limitation, all these heaps need to add the same limitation. My worry is that without seeing these vendor heaps, this is a bit of a theoretical concern. We don't have the data on how common this is. I very much hope that vendors can start submitting their heaps upstream (along with drivers that benefit from the heaps). Then we can really assess what makes the most sense for the community maintained code. > I just think it's boring. However, If you think discussing these absent > cases based on current linux code is meaningless, I also agree to it. So, as a rule, the upstream kernel doesn't create/maintain logic to accommodate out of tree code. Now, I agree there is the potential for some duplication in the checks in the allocation logic, but until it affects the upstream kernel, community maintainers can't really make an appropriate evaluation. As a contra-example, if the allocation is some extreme hotpath, adding an extra un-inlinable function pointer traversal for the size callback may actually have a negative impact. This isn't likely but again, if we cannot demonstrate it one way or the other against the upstream tree, we can't figure out what the best solution might be. > So, to summarize, if you still think adding it in system_heap.c is > better, I also agree and I will update the patch to add it in > system_heap.c I think this is the best solution for now. As this is not part of an userland ABI, we can always change it in the future once we see the need. thanks -john