Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7245918ybl; Wed, 15 Jan 2020 18:38:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyIo5BWyH36/pHjp5HoGRGxIqUTgNc40l6h7FAaD10xhR2OEnZVXQUo4XGS/A7v0LGBVwO/ X-Received: by 2002:aca:3f54:: with SMTP id m81mr2360658oia.73.1579142301684; Wed, 15 Jan 2020 18:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579142301; cv=none; d=google.com; s=arc-20160816; b=N7qH18GyX6XC8U5xiiFEzmV+g94TRWurS4gIE3+mw/fEjtd/dI2bFsZoKB7X1AjB9F cf/rQm8H83CvOtNYMrv/hXFD9dc3AB37gbYr9W68sac9918+fqspKk2Yei4qwbo4vqdr YCY3Xumq128HY/4UaMngMSQMlsHNyInP2rkRvS0xn99rQVvR4sekn/y1gWAaoUrs43m3 45kcvtkvEv11wkbIgoWJXwQRHK9/LmfzIg2TsY/ciwR56+KOdwIr1UFSk8j75K6Hlf8O RiXWy0fbY6rNjiK+/kHNUr0dkw3apFAs/y2ShTIOCrGEo+2TfZWeT8Q7Ql5smbcx62jN Tbmg== 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=ISxVLQvK8s5nY6LD7WJ8K+q3IuJWjWSPNsTVjYjwR80=; b=y8/3a10jcyD7TgrQGycb7vWG6vBD/ZpHZQa/Z6+e9Fc96WNDpYbEYHuNzQR9n1sHWn TyJ8t4mep6ushB1i1Xm5HmoVvhhZeDnmr7Nc/jitfGztQ8C9cWCndmdbb3H2xKwO/b7Y sRUzfS69AN6cvY0YGshHUkh628zaBGISJ/2o4MBoLcNfXAbjEujMBP4rKS+/0E4AKP6V E11Jbta6cpqjkF9hpsFGGBJHedmaL410OleJbkSCnJJMKUYSrD+jSHg4KZbuZm8xe/LU n1ajGzLQjOi2+q4N9aUidrfewNW/iT7qPm7/xiGtgWcybXV/s29ocelXAEz9rRL5LjrW Aj0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i2BXAPLH; 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 l17si11555243otk.218.2020.01.15.18.38.01; Wed, 15 Jan 2020 18:38:21 -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=i2BXAPLH; 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 S1730643AbgAPCMC (ORCPT + 99 others); Wed, 15 Jan 2020 21:12:02 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:54769 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730599AbgAPCMB (ORCPT ); Wed, 15 Jan 2020 21:12:01 -0500 Received: by mail-pj1-f66.google.com with SMTP id kx11so787340pjb.4 for ; Wed, 15 Jan 2020 18:12:01 -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=ISxVLQvK8s5nY6LD7WJ8K+q3IuJWjWSPNsTVjYjwR80=; b=i2BXAPLH47Eap5rnuaSk8R3uM2RBSpnlp2GmGBNYBu9aWN7QmFKWYXXjSZ0zO2NJ5l TtgRXB620x7o7cZqjHRAu5vtlw8XUy026f4IXofijWYbgiqL6OZkmTv0LALmnqLA3GI0 apyz/E6RIb6mnB31hZ5IWR9SRCdBnv3ROCv4zfnvf7ABKpOha1w44MuNGwgY5aDHoGfy dZNbKRKgKfaNxkoOSGBRVZPlGyIOAkWZEpoZY0gUle3V95e44IgMYbrwbTbw+qWnwwFc tMqnci8VTrjsBHDFf1sunwD9DjGW33qVtO23fpOgUW05G3QsHLKwN/RpRkVszP7ZITFN QhbQ== 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=ISxVLQvK8s5nY6LD7WJ8K+q3IuJWjWSPNsTVjYjwR80=; b=JS8T5j8fOk/k/y+70/t0T/v+6Zob3iPDglBu1wXDi3wInrFMbiS5gh4W9B9HnP7DXG P6dKvWxP6LK13r0aOP5MrqCi1gS8VwUYW8563BqVNLFNpjerVN7Vvo0dHb8SdRIWzREO xLOzGZY9fHnqDFW8e4GXIGqUMU2khgdSwcxLnJD7lMzyl2c+2lvblqB+0qLE02AJ7fsV o3BFwBhlrv7/X0U6NKvwBz8LYiRPFt8A4AhBh3ODfAiowuvLsB7jLgs4ryyP1JViEvuT LaGP7T3LuTasovUGMif8amc/YZpjGr3yVHfadgfoZemOHOj4BzK77AGcZR79T+ggkMgj Y6zQ== X-Gm-Message-State: APjAAAUayidB4fabZJ92wmFuaFpvBKcQKjvvtsjqDyxDdUxKd1nRRtt9 wZQtS6y7zRTYWGqUa7A8pGmJ7g== X-Received: by 2002:a17:902:462:: with SMTP id 89mr29644947ple.270.1579140720839; Wed, 15 Jan 2020 18:12:00 -0800 (PST) Received: from ?IPv6:240e:362:43d:200:56f:3d32:378b:3366? ([240e:362:43d:200:56f:3d32:378b:3366]) by smtp.gmail.com with ESMTPSA id g11sm22149064pgd.26.2020.01.15.18.11.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jan 2020 18:12:00 -0800 (PST) Subject: Re: [PATCH v11 2/4] uacce: add uacce driver To: Dave Jiang , Greg Kroah-Hartman Cc: Arnd Bergmann , Herbert Xu , jonathan.cameron@huawei.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> <053ccd05-4f11-5be6-47c2-eee5c2f1fdc4@linaro.org> <20200114145934.GA1960403@kroah.com> <9454d674-85db-32ba-4f28-eb732777d59d@intel.com> From: zhangfei Message-ID: <6c08d1ad-53a5-0238-3767-c40d7b10df3c@linaro.org> Date: Thu, 16 Jan 2020 10:11:20 +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: <9454d674-85db-32ba-4f28-eb732777d59d@intel.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, Dave On 2020/1/16 上午12:43, Dave Jiang wrote: > > > On 1/15/20 4:18 AM, zhangfei wrote: >> Hi, Greg >> >> On 2020/1/14 下午10:59, Greg Kroah-Hartman wrote: >>> On Mon, Jan 13, 2020 at 11:34:55AM +0800, zhangfei wrote: >>>> 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 >>> But if the "parent" module is to be unloaded, it has to unregister the >>> "child" device and that will call the destructor in here and then you >>> will tear everything down and all should be good. >>> >>> There's no need to "forbid" a module from being unloaded, even if it is >>> being used.  Look at all networking drivers, they work that way, right? >> Thanks Greg for the kind suggestion. >> >> I still have one uncertainty. >> Does uacce has to block process continue accessing the mmapped area >> when remove "parent" module? >> Uacce can block device access the physical memory when parent module >> call uacce_remove. >> But application is still running, and suppose it is not the kernel >> driver's responsibility to call unmap. >> >> I am looking for some examples in kernel, >> looks vfio does not block process continue accessing when >> vfio_unregister_iommu_driver either. >> >> In my test, application will keep waiting after rmmod parent, until >> ctrl+c, when unmap is called. >> During the process, kernel does not report any error. >> >> Do you have any advice? > > Would it work to call unmap_mapping_range() on the char dev > inode->i_mappings? I think you need to set the vma->fault function ptr > for the vm_operations_struct in the original mmap(). After the > mappings are unmapped, you can set a state variable to trigger the > return of VM_FAULT_SIGBUS in the ->fault function when the user app > accesses the mmap region again and triggers a page fault. The user app > needs to be programmed to catch exceptions to deal with that. Thanks Dave for the advice. Will look into it, may need some time to investigate. I would like to make an additional patch for this issue, since it does not impact the main function. Thanks