Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3490638ybl; Sun, 12 Jan 2020 19:35:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxBuDusZq8TGlGgy2kR/ff+JXvGeLIBnXm1GMVe0trAo1UXKy4ECpk0RWO9ZMtnCEDQkDj6 X-Received: by 2002:aca:aa15:: with SMTP id t21mr11550351oie.177.1578886543571; Sun, 12 Jan 2020 19:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578886543; cv=none; d=google.com; s=arc-20160816; b=s/mSpuywEGprvrBugNkqbfFTUnBMpQ1VTBE9XqNaerwt64cRYhwJnkJ8/D5PxMxLLf 0dv1945koGjAgc+br+MoNQuNiBFgnfo+O3uv1uDwe9wuzlcmJqeUMs4L5J8MBAOkW3RX 1jt7pUsKfZo4wf4aEKluuGvh2/Ng4Ld0BxkmN5DngQUkYVph3/5JhX4e2RGWIwj1QrFP cdGGC0G2mrdPlPX1/hrqxBjMOLnHB2le29WCawQVQaTE5RTRo1x4HkIU3eccugr2HrIh 0faicag0oRoT4G7bckQAmyZHw/ue+c7p7qCMd9xGm5tZjJm7k8eZ3VY4QYF50HZ/9UzJ wo/Q== 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=xFqcxE7gzA9H12FKOdbMb//B/oYmfZK/RzAcHl+CnTs=; b=chNlnZ1PP1FcxBlpCEy5czQjFLpTS1JHg93idGrbeS4bxJKVFjrcJZN6sqGaD0ocEp Wk+bteBBKIDMzZAwOr3zRp/dbUmYtm5qFWIo/RBupR/eWej0bTjoiAJVe4HoH7bEMa7q XxI/HCH7M0LB0ducMaBvdzZp0sMc/82hLyu2FQzCoyiIeegRPJcAZsNEzYNYOEW21eHS 6zPN4GZ844vEygmKxK7whGTpGvN8nugocvgNaju8l1cjWeD3Reqo7OXgcQFq2KsO9NUB XHem1x4NvK35/PMEw07YeRobUa+eFz3jXVZo2MyUuWpK9RVNr0jKA67IEs4M2BWEOd2y mELw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k+FPJXn+; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 8si5855933ota.266.2020.01.12.19.35.22; Sun, 12 Jan 2020 19:35:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=k+FPJXn+; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1733148AbgAMDfV (ORCPT + 99 others); Sun, 12 Jan 2020 22:35:21 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43898 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733020AbgAMDfV (ORCPT ); Sun, 12 Jan 2020 22:35:21 -0500 Received: by mail-pg1-f196.google.com with SMTP id k197so4014479pga.10 for ; Sun, 12 Jan 2020 19:35:21 -0800 (PST) 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=xFqcxE7gzA9H12FKOdbMb//B/oYmfZK/RzAcHl+CnTs=; b=k+FPJXn+qDrc8Rv9GkbgTYmLV+c06ODhfg3UhsWFDxASC2rDKBsa5hPArKfSnHOiHf SiqlCOxOzq9cRabPerK7MdccjmcZQQqUHr2ENSp13QJ2VYuqA+dCtQri/vOUCtYve+4N AdsmmYGs2PctIv6buQ3S2tTWv/krI5/wFhyhKQd/xrBZSxjlsdI+/ZM9XoGe9y/wdc45 WdtqH8HGpuq7/0MpnZxHh1QWEUyQ9CK5sCVbvZvGRdDEy1YF8XxySFRhTKPlbKh4FMzg qTb2Q7X//1CY+5EHEEXdNPyHCSpbf6OEWnK25vSgDkemlto12Le5Ftx4cxIgFJpTfKJo +qrg== 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=xFqcxE7gzA9H12FKOdbMb//B/oYmfZK/RzAcHl+CnTs=; b=XSPvh/GQx7JeyqAswBTZZJA28jwbAF3cytsTLy0gUzqsQDj2m4SPi89xHciXP8QvGI n4/xw2V/BAdLO7S/LewBn4NbheIAq12AYjRdBW3OmSWoMBrjI99t5/0N5aYD0zUNsAGJ V7kq/xtXP2S7YEnGBRFxg2guxIQaFqK9iWM/JWK8Mvfz2NrUMIJA2cVpEsys0r1roNKJ mz0zmUNh4rh8sZ5nZomcQ28hi9SbRPhTkAjFkqFs2NyNfE+gQhTzHiyDGCvYVZzRrm0R e2RBUcupiL2tWvA6wEP9CDKIq+T/OWHwpM723cq8YuZzXeiwRPWBvziYCPqkpO/qKYjU n6OQ== X-Gm-Message-State: APjAAAWZO3LOR4PtaAD3tAN5S5Q7SjJxff+qYTVdb33+L5N1IjCPh/i6 NDsgB9osTNu9gKLZV/yMAxpJtA== X-Received: by 2002:aa7:982d:: with SMTP id q13mr17816648pfl.152.1578886521046; Sun, 12 Jan 2020 19:35:21 -0800 (PST) Received: from ?IPv6:240e:362:498:8200:f030:f64d:8b7a:5e5a? ([240e:362:498:8200:f030:f64d:8b7a:5e5a]) by smtp.gmail.com with ESMTPSA id i23sm11662197pfo.11.2020.01.12.19.35.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jan 2020 19:35:20 -0800 (PST) Subject: Re: [PATCH v11 2/4] uacce: add uacce driver To: Greg Kroah-Hartman Cc: Arnd Bergmann , Herbert Xu , jonathan.cameron@huawei.com, dave.jiang@intel.com, grant.likely@arm.com, jean-philippe , Jerome Glisse , ilias.apalodimas@linaro.org, francois.ozog@linaro.org, kenneth-lee-2012@foxmail.com, Wangzhou , "haojian . zhuang" , guodong.xu@linaro.org, linux-accelerators@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux-foundation.org, Kenneth Lee , Zaibo Xu References: <1578710919-12141-1-git-send-email-zhangfei.gao@linaro.org> <1578710919-12141-3-git-send-email-zhangfei.gao@linaro.org> <20200111194006.GD435222@kroah.com> From: zhangfei Message-ID: <053ccd05-4f11-5be6-47c2-eee5c2f1fdc4@linaro.org> Date: Mon, 13 Jan 2020 11:34:55 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200111194006.GD435222@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi, Greg Thanks for the review. On 2020/1/12 上午3:40, Greg Kroah-Hartman wrote: > On Sat, Jan 11, 2020 at 10:48:37AM +0800, Zhangfei Gao wrote: >> +static int uacce_fops_open(struct inode *inode, struct file *filep) >> +{ >> + struct uacce_mm *uacce_mm = NULL; >> + struct uacce_device *uacce; >> + struct uacce_queue *q; >> + int ret = 0; >> + >> + uacce = xa_load(&uacce_xa, iminor(inode)); >> + if (!uacce) >> + return -ENODEV; >> + >> + if (!try_module_get(uacce->parent->driver->owner)) >> + return -ENODEV; > Why are you trying to grab the module reference of the parent device? > Why is that needed and what is that going to help with here? > > This shouldn't be needed as the module reference of the owner of the > fileops for this module is incremented, and the "parent" module depends > on this module, so how could it be unloaded without this code being > unloaded? > > Yes, if you build this code into the kernel and the "parent" driver is a > module, then you will not have a reference, but when you remove that > parent driver the device will be removed as it has to be unregistered > before that parent driver can be removed from the system, right? > > Or what am I missing here? The refcount here is preventing rmmod "parent" module after fd is opened, since user driver has mmap kernel memory to user space, like mmio, which may still in-use. With the refcount protection, rmmod "parent" module will fail until application free the fd. log like: rmmod: ERROR: Module hisi_zip is in use > >> +static void uacce_release(struct device *dev) >> +{ >> + struct uacce_device *uacce = to_uacce_device(dev); >> + >> + kfree(uacce); >> + uacce = NULL; > That line didn't do anything :) Yes, this is a mistake. It is up to caller to set to NULL to prevent release multi times. Thanks