Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1475520img; Tue, 19 Mar 2019 08:25:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0p05QM+0a9uzrQknem/RVeryJQBk9ReCDJAE8fbQbWFMPkkJuKLgpeYo3uK+4XGy0Jc5j X-Received: by 2002:a63:6142:: with SMTP id v63mr1579387pgb.342.1553009108354; Tue, 19 Mar 2019 08:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553009108; cv=none; d=google.com; s=arc-20160816; b=xQhjr7VyO/oUzuGo1icUAjRsCFYs909cHzysp9EBxozA/A7zVPo3x1LXCvkjvWCeuP ZEqbX2FtrzGTpEPLtVDRSVPXis5qQu70zXWgYpxj5pXeay5N2jOKBrR4gfVYrTjnayPb kbxCinLf6C2QMn6EaEEL8CdJgq8luqDTHRPGd2YM+vzBt6HgT2CstJa+kGw/6TBS/UId gcZjojXbnwEDDuTsPz0Pbi/SPOzWUcrJ/9t/T5mfEeT4QtXVlTL9pWXG5mtMSj0VjjtS bIGpir9ahEsuR+lfjzdClVVSo4N2t2IIGQLUckJH8wmtYaOhWh1aB9uK0k40QdUkncUl 1VoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=CpzEqGyOCfpNpw9oixEL1eTI8BmbOV0KTjwVSvnTDAM=; b=cbKgraAXXjTIZ8Pk5yuzo9scheNK/wwGLEvzqm3GoGGv7iplTcfyHzUCPN19YFvwpy N20gJMgY1Z7Tl2sXAum27c16t4OW9qCYztyqOUQ2KbE/bVs0XlhEJu0w4UlQILOsVUUj TStQL/M8ZQXoh/ix/OMv+3xlXYRfe/Mzkj0iK1wwu/e/UcCMlwK08QaM19TExfU5Fwyi oVqpoKZ0NCZlLCIslD5bfiG73Lj1JcBQQK+hC1vjpweU24IOAbxWJDJ7jtLlI4s+m0y8 9dPYsRHEv0y+Pa8XX3psPsBepXhJTvKQfolRR95Bj8F78fqaWXb6oES8b8gmfTUtp4CB yxCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lnpP+bLR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g186si11485749pgc.586.2019.03.19.08.24.52; Tue, 19 Mar 2019 08:25:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lnpP+bLR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727371AbfCSPYR (ORCPT + 99 others); Tue, 19 Mar 2019 11:24:17 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:55516 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbfCSPYR (ORCPT ); Tue, 19 Mar 2019 11:24:17 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x2JFO5Kb117118; Tue, 19 Mar 2019 10:24:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1553009045; bh=CpzEqGyOCfpNpw9oixEL1eTI8BmbOV0KTjwVSvnTDAM=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=lnpP+bLRLhii5KP+yVHYpanAac0o0TU0I9/xcMi1rsS6Xzv8glkLSX3R9IbVEyofw mdPhVR6YBGsWFz4/wicQ+BA7hXzbsB4neHK61gMs494NiRw+h6i/ZL1q2etyJDBYV5 chIPEHg/ezSXCKAsAspJGJZzSpxCYQWR0LQ86Beg= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x2JFO5wL085998 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 19 Mar 2019 10:24:05 -0500 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 19 Mar 2019 10:24:05 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5 via Frontend Transport; Tue, 19 Mar 2019 10:24:05 -0500 Received: from [10.250.67.168] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x2JFO4xN000625; Tue, 19 Mar 2019 10:24:04 -0500 Subject: Re: [RFC][PATCH 1/5 v2] dma-buf: Add dma-buf heaps framework To: Brian Starkey , John Stultz CC: lkml , Laura Abbott , Benjamin Gaignard , Greg KH , Sumit Semwal , Liam Mark , Chenbo Feng , Alistair Strachan , "dri-devel@lists.freedesktop.org" , nd References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-2-git-send-email-john.stultz@linaro.org> <20190319120825.3mvdxp5saluboy7o@DESKTOP-E1NTVVP.localdomain> From: "Andrew F. Davis" Message-ID: <0deeabd5-9f61-b250-a531-a86c6c58b679@ti.com> Date: Tue, 19 Mar 2019 10:24:04 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190319120825.3mvdxp5saluboy7o@DESKTOP-E1NTVVP.localdomain> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/19/19 7:08 AM, Brian Starkey wrote: > Hi John, > > On Tue, Mar 05, 2019 at 12:54:29PM -0800, John Stultz wrote: >> From: "Andrew F. Davis" > > [snip] > >> + >> +#define NUM_HEAP_MINORS 128 >> +static DEFINE_IDR(dma_heap_idr); >> +static DEFINE_MUTEX(minor_lock); /* Protect idr accesses */ > > I saw that Matthew Wilcox is trying to nuke idr: > https://patchwork.freedesktop.org/series/57073/ > > Perhaps a different data structure could be considered? (I don't have > an informed opinion on which). > Looks like XArray is the suggested replacement. Should be easy enough, the minor number would just index to our heap struct directly, I'll give it a shot and see. >> + >> +dev_t dma_heap_devt; >> +struct class *dma_heap_class; >> +struct list_head dma_heap_list; >> +struct dentry *dma_heap_debug_root; >> + >> +static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, >> + unsigned int flags) >> +{ >> + len = PAGE_ALIGN(len); >> + if (!len) >> + return -EINVAL; > > I think aligning len to pages only makes sense if heaps are going to > allocate aligned to pages too. Perhaps that's an implicit assumption? > If so, lets document it. > > Why not let the heaps take care of aligning len however they want > though? > This is how I originally had it, but I think we couldn't find any case where you would want an the start or end of a buffer to not fall on a page boundary here. It would only lead to problems. As you say though, nothing keeping us from moving that into the heaps themselves. > ... > >> + >> +int dma_heap_add(struct dma_heap *heap) >> +{ >> + struct device *dev_ret; >> + int ret; >> + >> + if (!heap->name || !strcmp(heap->name, "")) { >> + pr_err("dma_heap: Cannot add heap without a name\n"); >> + return -EINVAL; >> + } >> + >> + if (!heap->ops || !heap->ops->allocate) { >> + pr_err("dma_heap: Cannot add heap with invalid ops struct\n"); >> + return -EINVAL; >> + } >> + >> + /* Find unused minor number */ >> + mutex_lock(&minor_lock); >> + ret = idr_alloc(&dma_heap_idr, heap, 0, NUM_HEAP_MINORS, GFP_KERNEL); >> + mutex_unlock(&minor_lock); >> + if (ret < 0) { >> + pr_err("dma_heap: Unable to get minor number for heap\n"); >> + return ret; >> + } >> + heap->minor = ret; >> + >> + /* Create device */ >> + heap->heap_devt = MKDEV(MAJOR(dma_heap_devt), heap->minor); >> + dev_ret = device_create(dma_heap_class, >> + NULL, >> + heap->heap_devt, >> + NULL, >> + heap->name); >> + if (IS_ERR(dev_ret)) { >> + pr_err("dma_heap: Unable to create char device\n"); >> + return PTR_ERR(dev_ret); >> + } >> + >> + /* Add device */ >> + cdev_init(&heap->heap_cdev, &dma_heap_fops); >> + ret = cdev_add(&heap->heap_cdev, dma_heap_devt, NUM_HEAP_MINORS); > > Shouldn't this be s/dma_heap_devt/heap->heap_devt/ and a count of 1? > Hmm, strange this ever worked before.. > Also would it be better to have cdev_add/device_create the other way > around? First create the char device, then once it's all set up > register it with sysfs. > Yes that does seem to be more common, lets flip it. >> + if (ret < 0) { >> + device_destroy(dma_heap_class, heap->heap_devt); >> + pr_err("dma_heap: Unable to add char device\n"); >> + return ret; >> + } >> + >> + return 0; >> +} >> +EXPORT_SYMBOL(dma_heap_add); > > Until we've figured out how modules are going to work, I still think > it would be a good idea to not export this. > Agree. Andrew > Cheers, > -Brian >