From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Zhangfei Gao <zhangfei.gao@linaro.org>,
Kenneth Lee <liguozhu@hisilicon.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Herbert Xu <herbert@gondor.apana.org.au>, <grant.likely@arm.com>,
jean-philippe <jean-philippe@linaro.org>,
"Jerome Glisse" <jglisse@redhat.com>,
<ilias.apalodimas@linaro.org>, <francois.ozog@linaro.org>,
<kenneth-lee-2012@foxmail.com>,
Wangzhou <wangzhou1@hisilicon.com>,
"haojian . zhuang" <haojian.zhuang@linaro.org>,
<guodong.xu@linaro.org>, <linux-accelerators@lists.ozlabs.org>,
<linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
<iommu@lists.linux-foundation.org>, Zaibo Xu <xuzaibo@huawei.com>
Subject: Re: [PATCH v10 2/4] uacce: add uacce driver
Date: Thu, 9 Jan 2020 17:38:19 +0000 [thread overview]
Message-ID: <20200109173819.00003cbf@Huawei.com> (raw)
In-Reply-To: <1576465697-27946-3-git-send-email-zhangfei.gao@linaro.org>
On Mon, 16 Dec 2019 11:08:15 +0800
Zhangfei Gao <zhangfei.gao@linaro.org> wrote:
> From: Kenneth Lee <liguozhu@hisilicon.com>
>
> Uacce (Unified/User-space-access-intended Accelerator Framework) targets to
> provide Shared Virtual Addressing (SVA) between accelerators and processes.
> So accelerator can access any data structure of the main cpu.
> This differs from the data sharing between cpu and io device, which share
> only data content rather than address.
> Since unified address, hardware and user space of process can share the
> same virtual address in the communication.
>
> Uacce create a chrdev for every registration, the queue is allocated to
> the process when the chrdev is opened. Then the process can access the
> hardware resource by interact with the queue file. By mmap the queue
> file space to user space, the process can directly put requests to the
> hardware without syscall to the kernel space.
>
> The IOMMU core only tracks mm<->device bonds at the moment, because it
> only needs to handle IOTLB invalidation and PASID table entries. However
> uacce needs a finer granularity since multiple queues from the same
> device can be bound to an mm. When the mm exits, all bound queues must
> be stopped so that the IOMMU can safely clear the PASID table entry and
> reallocate the PASID.
>
> An intermediate struct uacce_mm links uacce devices and queues.
> Note that an mm may be bound to multiple devices but an uacce_mm
> structure only ever belongs to a single device, because we don't need
> anything more complex (if multiple devices are bound to one mm, then
> we'll create one uacce_mm for each bond).
>
> uacce_device --+-- uacce_mm --+-- uacce_queue
> | '-- uacce_queue
> |
> '-- uacce_mm --+-- uacce_queue
> +-- uacce_queue
> '-- uacce_queue
>
> Signed-off-by: Kenneth Lee <liguozhu@hisilicon.com>
> Signed-off-by: Zaibo Xu <xuzaibo@huawei.com>
> Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Hi,
Two small things I'd missed previously. Fix those and for
what it's worth
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> Documentation/ABI/testing/sysfs-driver-uacce | 37 ++
> drivers/misc/Kconfig | 1 +
> drivers/misc/Makefile | 1 +
> drivers/misc/uacce/Kconfig | 13 +
> drivers/misc/uacce/Makefile | 2 +
> drivers/misc/uacce/uacce.c | 628 +++++++++++++++++++++++++++
> include/linux/uacce.h | 161 +++++++
> include/uapi/misc/uacce/uacce.h | 38 ++
> 8 files changed, 881 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-driver-uacce
> create mode 100644 drivers/misc/uacce/Kconfig
> create mode 100644 drivers/misc/uacce/Makefile
> create mode 100644 drivers/misc/uacce/uacce.c
> create mode 100644 include/linux/uacce.h
> create mode 100644 include/uapi/misc/uacce/uacce.h
>
...
> +
> +What: /sys/class/uacce/<dev_name>/available_instances
> +Date: Dec 2019
> +KernelVersion: 5.6
> +Contact: linux-accelerators@lists.ozlabs.org
> +Description: Available instances left of the device
> + Return -ENODEV if uacce_ops get_available_instances is not provided
> +
See below. It doesn't "return" it prints it currently.
...
> +static int uacce_fops_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> + struct uacce_queue *q = filep->private_data;
> + struct uacce_device *uacce = q->uacce;
> + struct uacce_qfile_region *qfr;
> + enum uacce_qfrt type = UACCE_MAX_REGION;
> + int ret = 0;
> +
> + if (vma->vm_pgoff < UACCE_MAX_REGION)
> + type = vma->vm_pgoff;
> + else
> + return -EINVAL;
> +
> + qfr = kzalloc(sizeof(*qfr), GFP_KERNEL);
> + if (!qfr)
> + return -ENOMEM;
> +
> + vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND | VM_WIPEONFORK;
> + vma->vm_ops = &uacce_vm_ops;
> + vma->vm_private_data = q;
> + qfr->type = type;
> +
> + mutex_lock(&uacce_mutex);
> +
> + if (q->state != UACCE_Q_INIT && q->state != UACCE_Q_STARTED) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + if (q->qfrs[type]) {
> + ret = -EEXIST;
> + goto out_with_lock;
> + }
> +
> + switch (type) {
> + case UACCE_QFRT_MMIO:
> + if (!uacce->ops->mmap) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + ret = uacce->ops->mmap(q, vma, qfr);
> + if (ret)
> + goto out_with_lock;
> +
> + break;
> +
> + case UACCE_QFRT_DUS:
> + if (uacce->flags & UACCE_DEV_SVA) {
> + if (!uacce->ops->mmap) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + ret = uacce->ops->mmap(q, vma, qfr);
> + if (ret)
> + goto out_with_lock;
> + }
Slightly odd corner case, but what stops us getting here with
the UACCE_DEV_SVA flag not set? If that happened I'd expect to
return an error but looks like we return 0.
> + break;
> +
> + default:
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + q->qfrs[type] = qfr;
> + mutex_unlock(&uacce_mutex);
> +
> + return ret;
> +
> +out_with_lock:
> + mutex_unlock(&uacce_mutex);
> + kfree(qfr);
> + return ret;
> +}
...
> +static ssize_t available_instances_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct uacce_device *uacce = to_uacce_device(dev);
> + int val = -ENODEV;
> +
> + if (uacce->ops->get_available_instances)
> + val = uacce->ops->get_available_instances(uacce);
> +
> + return sprintf(buf, "%d\n", val);
It's unusual to pass an error value back as a string.
I'd expect some logic like..
if (val < 0)
return val;
return sprintf(buf, "%d\n", val);
Note this is the documented behavior "returns -ENODEV".
> +}
> +
> +static ssize_t algorithms_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct uacce_device *uacce = to_uacce_device(dev);
> +
> + return sprintf(buf, "%s\n", uacce->algs);
> +}
> +
...
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Zhangfei Gao <zhangfei.gao@linaro.org>,
Kenneth Lee <liguozhu@hisilicon.com>
Cc: jean-philippe <jean-philippe@linaro.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Arnd Bergmann <arnd@arndb.de>,
francois.ozog@linaro.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
ilias.apalodimas@linaro.org, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Jerome Glisse <jglisse@redhat.com>,
grant.likely@arm.com,
"haojian . zhuang" <haojian.zhuang@linaro.org>,
linux-accelerators@lists.ozlabs.org,
linux-crypto@vger.kernel.org, guodong.xu@linaro.org,
kenneth-lee-2012@foxmail.com
Subject: Re: [PATCH v10 2/4] uacce: add uacce driver
Date: Thu, 9 Jan 2020 17:38:19 +0000 [thread overview]
Message-ID: <20200109173819.00003cbf@Huawei.com> (raw)
In-Reply-To: <1576465697-27946-3-git-send-email-zhangfei.gao@linaro.org>
On Mon, 16 Dec 2019 11:08:15 +0800
Zhangfei Gao <zhangfei.gao@linaro.org> wrote:
> From: Kenneth Lee <liguozhu@hisilicon.com>
>
> Uacce (Unified/User-space-access-intended Accelerator Framework) targets to
> provide Shared Virtual Addressing (SVA) between accelerators and processes.
> So accelerator can access any data structure of the main cpu.
> This differs from the data sharing between cpu and io device, which share
> only data content rather than address.
> Since unified address, hardware and user space of process can share the
> same virtual address in the communication.
>
> Uacce create a chrdev for every registration, the queue is allocated to
> the process when the chrdev is opened. Then the process can access the
> hardware resource by interact with the queue file. By mmap the queue
> file space to user space, the process can directly put requests to the
> hardware without syscall to the kernel space.
>
> The IOMMU core only tracks mm<->device bonds at the moment, because it
> only needs to handle IOTLB invalidation and PASID table entries. However
> uacce needs a finer granularity since multiple queues from the same
> device can be bound to an mm. When the mm exits, all bound queues must
> be stopped so that the IOMMU can safely clear the PASID table entry and
> reallocate the PASID.
>
> An intermediate struct uacce_mm links uacce devices and queues.
> Note that an mm may be bound to multiple devices but an uacce_mm
> structure only ever belongs to a single device, because we don't need
> anything more complex (if multiple devices are bound to one mm, then
> we'll create one uacce_mm for each bond).
>
> uacce_device --+-- uacce_mm --+-- uacce_queue
> | '-- uacce_queue
> |
> '-- uacce_mm --+-- uacce_queue
> +-- uacce_queue
> '-- uacce_queue
>
> Signed-off-by: Kenneth Lee <liguozhu@hisilicon.com>
> Signed-off-by: Zaibo Xu <xuzaibo@huawei.com>
> Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Hi,
Two small things I'd missed previously. Fix those and for
what it's worth
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> Documentation/ABI/testing/sysfs-driver-uacce | 37 ++
> drivers/misc/Kconfig | 1 +
> drivers/misc/Makefile | 1 +
> drivers/misc/uacce/Kconfig | 13 +
> drivers/misc/uacce/Makefile | 2 +
> drivers/misc/uacce/uacce.c | 628 +++++++++++++++++++++++++++
> include/linux/uacce.h | 161 +++++++
> include/uapi/misc/uacce/uacce.h | 38 ++
> 8 files changed, 881 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-driver-uacce
> create mode 100644 drivers/misc/uacce/Kconfig
> create mode 100644 drivers/misc/uacce/Makefile
> create mode 100644 drivers/misc/uacce/uacce.c
> create mode 100644 include/linux/uacce.h
> create mode 100644 include/uapi/misc/uacce/uacce.h
>
...
> +
> +What: /sys/class/uacce/<dev_name>/available_instances
> +Date: Dec 2019
> +KernelVersion: 5.6
> +Contact: linux-accelerators@lists.ozlabs.org
> +Description: Available instances left of the device
> + Return -ENODEV if uacce_ops get_available_instances is not provided
> +
See below. It doesn't "return" it prints it currently.
...
> +static int uacce_fops_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> + struct uacce_queue *q = filep->private_data;
> + struct uacce_device *uacce = q->uacce;
> + struct uacce_qfile_region *qfr;
> + enum uacce_qfrt type = UACCE_MAX_REGION;
> + int ret = 0;
> +
> + if (vma->vm_pgoff < UACCE_MAX_REGION)
> + type = vma->vm_pgoff;
> + else
> + return -EINVAL;
> +
> + qfr = kzalloc(sizeof(*qfr), GFP_KERNEL);
> + if (!qfr)
> + return -ENOMEM;
> +
> + vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND | VM_WIPEONFORK;
> + vma->vm_ops = &uacce_vm_ops;
> + vma->vm_private_data = q;
> + qfr->type = type;
> +
> + mutex_lock(&uacce_mutex);
> +
> + if (q->state != UACCE_Q_INIT && q->state != UACCE_Q_STARTED) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + if (q->qfrs[type]) {
> + ret = -EEXIST;
> + goto out_with_lock;
> + }
> +
> + switch (type) {
> + case UACCE_QFRT_MMIO:
> + if (!uacce->ops->mmap) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + ret = uacce->ops->mmap(q, vma, qfr);
> + if (ret)
> + goto out_with_lock;
> +
> + break;
> +
> + case UACCE_QFRT_DUS:
> + if (uacce->flags & UACCE_DEV_SVA) {
> + if (!uacce->ops->mmap) {
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + ret = uacce->ops->mmap(q, vma, qfr);
> + if (ret)
> + goto out_with_lock;
> + }
Slightly odd corner case, but what stops us getting here with
the UACCE_DEV_SVA flag not set? If that happened I'd expect to
return an error but looks like we return 0.
> + break;
> +
> + default:
> + ret = -EINVAL;
> + goto out_with_lock;
> + }
> +
> + q->qfrs[type] = qfr;
> + mutex_unlock(&uacce_mutex);
> +
> + return ret;
> +
> +out_with_lock:
> + mutex_unlock(&uacce_mutex);
> + kfree(qfr);
> + return ret;
> +}
...
> +static ssize_t available_instances_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct uacce_device *uacce = to_uacce_device(dev);
> + int val = -ENODEV;
> +
> + if (uacce->ops->get_available_instances)
> + val = uacce->ops->get_available_instances(uacce);
> +
> + return sprintf(buf, "%d\n", val);
It's unusual to pass an error value back as a string.
I'd expect some logic like..
if (val < 0)
return val;
return sprintf(buf, "%d\n", val);
Note this is the documented behavior "returns -ENODEV".
> +}
> +
> +static ssize_t algorithms_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct uacce_device *uacce = to_uacce_device(dev);
> +
> + return sprintf(buf, "%s\n", uacce->algs);
> +}
> +
...
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-01-09 17:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 3:08 [PATCH v10 0/4] Add uacce module for Accelerator Zhangfei Gao
2019-12-16 3:08 ` Zhangfei Gao
2019-12-16 3:08 ` [PATCH v10 1/4] uacce: Add documents for uacce Zhangfei Gao
2019-12-16 3:08 ` Zhangfei Gao
2019-12-16 3:08 ` [PATCH v10 2/4] uacce: add uacce driver Zhangfei Gao
2019-12-16 3:08 ` Zhangfei Gao
2020-01-09 17:38 ` Jonathan Cameron [this message]
2020-01-09 17:38 ` Jonathan Cameron
2020-01-10 6:55 ` zhangfei.gao
2020-01-10 10:10 ` Jonathan Cameron
2020-01-10 10:10 ` Jonathan Cameron
2020-01-10 14:50 ` zhangfei.gao
2019-12-16 3:08 ` [PATCH v10 3/4] crypto: hisilicon - Remove module_param uacce_mode Zhangfei Gao
2019-12-16 3:08 ` Zhangfei Gao
2020-01-09 17:40 ` Jonathan Cameron
2020-01-09 17:40 ` Jonathan Cameron
2019-12-16 3:08 ` [PATCH v10 4/4] crypto: hisilicon - register zip engine to uacce Zhangfei Gao
2019-12-16 3:08 ` Zhangfei Gao
2020-01-09 17:48 ` Jonathan Cameron
2020-01-09 17:48 ` Jonathan Cameron
2020-01-10 7:07 ` zhangfei
2020-01-10 7:07 ` zhangfei
2019-12-23 13:41 ` [PATCH v10 0/4] Add uacce module for Accelerator zhangfei
2019-12-23 13:41 ` zhangfei
2020-01-08 16:47 ` Dave Jiang
2020-01-08 16:47 ` Dave Jiang
2020-01-09 17:49 ` Jonathan Cameron
2020-01-09 17:49 ` Jonathan Cameron
2020-01-10 7:03 ` zhangfei
2020-01-10 7:03 ` zhangfei
2020-01-10 10:08 ` Jonathan Cameron
2020-01-10 10:08 ` Jonathan Cameron
2020-01-10 11:29 ` zhangfei.gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200109173819.00003cbf@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=arnd@arndb.de \
--cc=francois.ozog@linaro.org \
--cc=grant.likely@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=guodong.xu@linaro.org \
--cc=haojian.zhuang@linaro.org \
--cc=herbert@gondor.apana.org.au \
--cc=ilias.apalodimas@linaro.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jean-philippe@linaro.org \
--cc=jglisse@redhat.com \
--cc=kenneth-lee-2012@foxmail.com \
--cc=liguozhu@hisilicon.com \
--cc=linux-accelerators@lists.ozlabs.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wangzhou1@hisilicon.com \
--cc=xuzaibo@huawei.com \
--cc=zhangfei.gao@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.