Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp837916ybl; Fri, 30 Aug 2019 07:56:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWjta8XaonFmoqc36g6pTrfsBgft4WQdv4xF6SI66GGVotGNd2J2RKLHmwA9lptNckefkK X-Received: by 2002:a62:b415:: with SMTP id h21mr18664012pfn.198.1567176969455; Fri, 30 Aug 2019 07:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567176969; cv=none; d=google.com; s=arc-20160816; b=WYUVTRfIY/oPStnd5UX+O6vIILKMF6RbUcsqtWRP/zTuO5xovEFE3ReplujblINREX /XXDTADd7EmvHqnOIV8yDMgqmzpU/UF9Eyy9WwiuMQSOBhGhPzt+qZMgxuvc1ahU05Mm T/YZvA0L5aO0oMGMO2bWYeALvjIa94ItHdwS+JJnkyougXZbEw9icG57T8w9HVg/jXnQ Y9s6T0Vv8ZoJvi0rXhTrSvK+gCjbWqrz52JrLG+qjlFAGq0aIJSfs0D97oLgf0axpA84 nkabCGy5CuUj0lSHyCQA/Bqnil2Xr2D8f/7PMH69sQkXFomBVT3n8QBEg6xAR/gtjVo6 grxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=vbBcV2E28U4iN2QaWYHhbULA5tjozc5BMYZPQOhbMUg=; b=OZOatq40oN0io3+zQ1LIcfemhgFsR11zLmfP4NgFuY0oR8ZJmUu8h97Evl4z9t29BO kGMnjcKLA7Do0jxoHxQYxGnlgJMReUeMEJbX7oRf4MfVdI7R13aZn1ZbFj5tTJFySJDZ pkN9r0tKv2bRRReT4qnFScmUXrQSN3oeKl+7PCN8hKJWg7S0VuT4HotSZzdt7CaZ28lk /rJBwpxH11C3zkF3HlqpZXxCc+rwwVHr8tve9hU3Zgy2S4v+HOs1jsrbeJUKoFnUtBtX xs4DA7NkagRNM+fbHgLIOpAwC3pgbXCZgeDz10piUoEEHusVTXshD7fkmlv+jUjRt+ks dhxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fenmtq5R; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25si5756756pfi.265.2019.08.30.07.55.54; Fri, 30 Aug 2019 07:56:09 -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=@linaro.org header.s=google header.b=fenmtq5R; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbfH3OzF (ORCPT + 99 others); Fri, 30 Aug 2019 10:55:05 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43472 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727603AbfH3OzE (ORCPT ); Fri, 30 Aug 2019 10:55:04 -0400 Received: by mail-pg1-f196.google.com with SMTP id k3so3659203pgb.10 for ; Fri, 30 Aug 2019 07:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=vbBcV2E28U4iN2QaWYHhbULA5tjozc5BMYZPQOhbMUg=; b=fenmtq5R4+LIiYLJboWbllEaXaJUS4j6xSVjJBqw7Mevo1J+J2ck8qdf1glBSTEPHu VuyVBafv35kubmcKNw6n3XmaBGrp1mVbGMXcQ9rDq0DwM8qUXMTFRbIDUqf4H8ebIm5U U9aozCQrjsreSNWqLN/OfyjLD5nJjU7C2kuvSnMgxzCq9S5AFlFl2e2fkpAvstEyBLjf 5/1FdQ3Hj8ZU7Yw7X8a8grIKxnbtO9daC9TwH7Y+eU/p0b7FHLeZwzWV/Og2rCTW9O9G HOD4hWNgNP4KTrx5I0BOr2z9V3dIjwUx/OZx2vESCWgEA+fYSU54BSWgBtOGQQynofbS VfTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=vbBcV2E28U4iN2QaWYHhbULA5tjozc5BMYZPQOhbMUg=; b=PnsuoN2j+TYZIsI1zOz2AgtmZRnxHcNfDytdyFAUTAR870ZT+WUg4Fa7DEVcpv7CbN hSeLtDvsy7hbGe5DTrHl9VZbv2P/RMUmalWuLFTcCzcsLZwM/V/kIoLixSOkRj7Ag30f C5x85exZ5/N68NJXmFeJte7f7vzWCg+UYVT7kSjjB1NBpbwDFqbwnHjMDJZj6lt+fwQO ZqkHe2m3sWJNcVLp8n9yIsW8Zp7GmGf4WbEN7/QylFuurJ5j2jpchJ/xWq8G2AGrvaAh Elr/1nsDszTNuzxEv0KipItwUsVKpKLVN14+5dEjL+QPesA3l4BOvrAe1pITIPXBRjls aQhw== X-Gm-Message-State: APjAAAU2rNeMLX1ASuPpQpqMAzFkdA1lTXOozq8ibV2oZ7j+UcHUZnau 6SI7a+ex4mNKfFPMTrPosN/fhA== X-Received: by 2002:a17:90a:f48d:: with SMTP id bx13mr16152517pjb.97.1567176904229; Fri, 30 Aug 2019 07:55:04 -0700 (PDT) Received: from [192.168.11.133] (li1566-229.members.linode.com. [139.162.86.229]) by smtp.gmail.com with ESMTPSA id a142sm9295073pfd.147.2019.08.30.07.54.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Aug 2019 07:55:03 -0700 (PDT) Subject: Re: [PATCH v2 2/2] uacce: add uacce driver To: Greg Kroah-Hartman Cc: Arnd Bergmann , jonathan.cameron@huawei.com, kenneth-lee-2012@foxmail.com, Wangzhou , linux-accelerators@lists.ozlabs.org, linux-kernel@vger.kernel.org, Kenneth Lee , Zaibo Xu References: <1566998876-31770-1-git-send-email-zhangfei.gao@linaro.org> <1566998876-31770-3-git-send-email-zhangfei.gao@linaro.org> <20190828152201.GA10163@kroah.com> <5c2b0889-ea05-1ecd-fe5b-40611bd31945@linaro.org> <20190829095439.GA13915@kroah.com> From: zhangfei Message-ID: <39f792df-e3e3-eaa6-f78b-bf325b79f1b7@linaro.org> Date: Fri, 30 Aug 2019 22:54:46 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190829095439.GA13915@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Greg On 2019/8/29 下午5:54, Greg Kroah-Hartman wrote: > On Thu, Aug 29, 2019 at 05:05:13PM +0800, zhangfei wrote: >> Hi, Greg >> >> On 2019/8/28 下午11:22, Greg Kroah-Hartman wrote: >>> On Wed, Aug 28, 2019 at 09:27:56PM +0800, Zhangfei Gao wrote: >>>> +struct uacce { >>>> + const char *drv_name; >>>> + const char *algs; >>>> + const char *api_ver; >>>> + unsigned int flags; >>>> + unsigned long qf_pg_start[UACCE_QFRT_MAX]; >>>> + struct uacce_ops *ops; >>>> + struct device *pdev; >>>> + bool is_vf; >>>> + u32 dev_id; >>>> + struct cdev cdev; >>>> + struct device dev; >>>> + void *priv; >>>> + atomic_t state; >>>> + int prot; >>>> + struct mutex q_lock; >>>> + struct list_head qs; >>>> +}; >>> At a quick glance, this problem really stood out to me. You CAN NOT >>> have two different objects within a structure that have different >>> lifetime rules and reference counts. You do that here with both a >>> 'struct cdev' and a 'struct device'. Pick one or the other, but never >>> both. >>> >>> I would recommend using a 'struct device' and then a 'struct cdev *'. >>> That way you get the advantage of using the driver model properly, and >>> then just adding your char device node pointer to "the side" which >>> interacts with this device. >>> >>> Then you might want to call this "struct uacce_device" :) >> Here the 'struct cdev' and 'struct device' have the same lifetime and >> refcount. > No they do not, that's impossible as refcounts are incremented from > different places (i.e. userspace). > >> They are allocated with uacce when uacce_register and freed when >> uacce_unregister. > And that will not work. I am sorry, could I ask more about this part.   * This function should be used whenever the struct cdev and the  * struct device are members of the same structure whose lifetime is  * managed by the struct device. From cdev_device_add comments, looks struct cdev and stuct device can be in the same structure like uacce, and uacce is released when put_device(device) Also cdev_device_del do the device_del(dev) and cdev_del(cdev). Copy: fs/char_dev.c /**  * cdev_device_add() - add a char device and it's corresponding  *      struct device, linkink  * @dev: the device structure  * @cdev: the cdev structure  *  * cdev_device_add() adds the char device represented by @cdev to the system,  * just as cdev_add does. It then adds @dev to the system using device_add  * The dev_t for the char device will be taken from the struct device which  * needs to be initialized first. This helper function correctly takes a  * reference to the parent device so the parent will not get released until  * all references to the cdev are released.  *  * This helper uses dev->devt for the device number. If it is not set  * it will not add the cdev and it will be equivalent to device_add.  *  * This function should be used whenever the struct cdev and the  * struct device are members of the same structure whose lifetime is  * managed by the struct device.  *  * NOTE: Callers must assume that userspace was able to open the cdev and  * can call cdev fops callbacks at any time, even if this function fails.  */ int cdev_device_add(struct cdev *cdev, struct device *dev) {         int rc = 0;         if (dev->devt) {                 cdev_set_parent(cdev, &dev->kobj);                 rc = cdev_add(cdev, dev->devt, 1);                 if (rc)                         return rc;         }         rc = device_add(dev);         if (rc)                 cdev_del(cdev);         return rc; } Thanks