Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1171201ybb; Wed, 1 Apr 2020 17:29:42 -0700 (PDT) X-Google-Smtp-Source: APiQypJw757xf2FTZXlisA20Q7aQXK+PmhWDTJiPT6lF51ydPpKOd2HHjzJc3IxPdaco8icefSbg X-Received: by 2002:aca:5211:: with SMTP id g17mr461721oib.19.1585787382068; Wed, 01 Apr 2020 17:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585787382; cv=none; d=google.com; s=arc-20160816; b=S8p7j9WZK8XPYzNT12cfXHvK+zgbFGQUIn2IMFWTGBFjlT62mSL4+6Cn+XAfGLkPyZ e7zWRDrU7MmM+19dfCGknKCjgge2ApN2PYUNMSUJO3Wxu/UWHm1bFfdFk6TIQ1Kdc8BX bBeR53O86yMBXIjTstFYqaSL7aTIUQrmP5j4mY5W9CCSmT9ZluPJfPnUKskIJaeBwTXL wcppnHoFqAyM35NGLNkAQJfZ0dBMuNaSQqc6I0v/V4uv2UhJHmmVMzFq5Y8Lvbu+9dOQ 9cs6Jq+9rSjKDrT2jiISMQaC9IkAGHYUyuRUSMPCIkR+Zug9eNGIfCiLL7gUWQJlKl5t gxpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rMoG139BAS3vSwnWNPt9NkvE0YK9VqiQxacpdg4y9C8=; b=ZZdIIVODpcfSAaGG52C767mFVpNeE2SAjib3eQdPGHRO14Pr2/SM1rBQsDWlsLLbVV BE9qkR35Bx2wu2EGthqDEU6WjCHz0IxnSEGweOaOASwqTkh5KInPCQ6oV7qkyanYDZ+u WrYyNLiz8kV/HkvR8fRSUHll1f8jl2QUTjRv4wY3ZbX39OTfvafDMGM+k0zIgkyCoxKe v7Rhi+J6Ec/WffvbJX4vnm9j1Ar6ZYJs3v9mxCsSjsYqwsJ3v77rElYXBlLT+msulmEE VR+m+VI5P4a2+GW6ghqgZIn8fEuD0zlRggQ9HVca91Ms7Fbr07Zb+XhfmxDgMzUaX1/M GnIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=b6uKoVWD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si1511292ooh.53.2020.04.01.17.29.29; Wed, 01 Apr 2020 17:29:42 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=b6uKoVWD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733025AbgDBA17 (ORCPT + 99 others); Wed, 1 Apr 2020 20:27:59 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36479 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732637AbgDBA17 (ORCPT ); Wed, 1 Apr 2020 20:27:59 -0400 Received: by mail-ed1-f65.google.com with SMTP id i7so2103200edq.3 for ; Wed, 01 Apr 2020 17:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rMoG139BAS3vSwnWNPt9NkvE0YK9VqiQxacpdg4y9C8=; b=b6uKoVWD6Cr/lKr0YKKqMS9MF7tOH9aunCZBAsMTrUwvYWsPp1CQ7F2m6pUvgy7vnC 7RoP8LQla92LBHCgkc2g8QdtBVJnzc0090CjTAM1Qi72DURzMZxg+e3varCSqD1vdYPW M/J9cDqpOhDIQV8pOvn/Wi9N2bh1HIWmlCL9gpU0A+E2OcO1vE/3E9uIvB/gKd1dzfw9 cOKT2ahz2TY5AoDZtiyTHFtltYl4sHWpADTGK37DpLuiTdhIl4j/T+eRkmatFe2Dxpsa kI6IxAFqojnBZm1JIGXsGk8QJgQIoQVNjJWwM41Euv2WGnSLotJt/HR6pWfn0S80QoFK FCqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rMoG139BAS3vSwnWNPt9NkvE0YK9VqiQxacpdg4y9C8=; b=MjS862COnNX4neEVwF0d0nAsPFe6mOFlv6cbm6t+Sr7480jrx+Su9K4a/OpJ9pCjZW m9ZA1fBF6qogqrKUltdRHlW2C8n8p6G8l3u5yaHzXa+JpbHtB8OryKNas1lT2NgHlRUL ZA0A7biSWv7M+UYEuiH8Mns1jlYSWoR+97ps98/FTOl7WHfrucKievuHbwUDejnvP1uM CGgfo/FpklHLO+DQZFIUDHzJ/1/+JiQMdYrY1YL7zqeYeMD0fpwUtTymGpeInTD2fIDv PvyCEdxMUzv5f4Wagq4pN191SgU6R3FrwUDzoaz+rSsKQoNi9uHlChclydcajfP0hfLP 0B9g== X-Gm-Message-State: AGi0PuYXvnB+iA6aprnVnR4/0g76F05XRemycup+9EbbnaVsUa9Cg56O KA34pcqrlz4/b9iQIvsuN7+N6MUGcRzcv/jf7WdiRA== X-Received: by 2002:a17:906:dbd4:: with SMTP id yc20mr703878ejb.335.1585787276297; Wed, 01 Apr 2020 17:27:56 -0700 (PDT) MIME-Version: 1.0 References: <20200327071202.2159885-1-alastair@d-silva.org> <20200327071202.2159885-16-alastair@d-silva.org> In-Reply-To: <20200327071202.2159885-16-alastair@d-silva.org> From: Dan Williams Date: Wed, 1 Apr 2020 17:27:45 -0700 Message-ID: Subject: Re: [PATCH v4 15/25] nvdimm/ocxl: Register a character device for userspace to interact with To: "Alastair D'Silva" Cc: "Aneesh Kumar K . V" , "Oliver O'Halloran" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Vishal Verma , Dave Jiang , Ira Weiny , Andrew Morton , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Anton Blanchard , Krzysztof Kozlowski , Mahesh Salgaonkar , Madhavan Srinivasan , =?UTF-8?Q?C=C3=A9dric_Le_Goater?= , Anju T Sudhakar , Hari Bathini , Thomas Gleixner , Greg Kurz , Nicholas Piggin , Masahiro Yamada , Alexey Kardashevskiy , Linux Kernel Mailing List , linuxppc-dev , linux-nvdimm , Linux MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 29, 2020 at 10:53 PM Alastair D'Silva wrote: > > This patch introduces a character device (/dev/ocxlpmemX) which further > patches will use to interact with userspace, such as error logs, > controller stats and card debug functionality. This was asked earlier, but I'll reiterate, I do not see what justifies an ocxlpmemX private device ABI vs routing through the existing generic character ndbusX and nmemX character devices. > > Signed-off-by: Alastair D'Silva > --- > drivers/nvdimm/ocxl/main.c | 117 ++++++++++++++++++++++++++++++++- > drivers/nvdimm/ocxl/ocxlpmem.h | 2 + > 2 files changed, 117 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvdimm/ocxl/main.c b/drivers/nvdimm/ocxl/main.c > index 8db573036423..9b85fcd3f1c9 100644 > --- a/drivers/nvdimm/ocxl/main.c > +++ b/drivers/nvdimm/ocxl/main.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include "ocxlpmem.h" > @@ -356,6 +357,67 @@ static int ocxlpmem_register(struct ocxlpmem *ocxlpmem) > return device_register(&ocxlpmem->dev); > } > > +static void ocxlpmem_put(struct ocxlpmem *ocxlpmem) > +{ > + put_device(&ocxlpmem->dev); > +} > + > +static struct ocxlpmem *ocxlpmem_get(struct ocxlpmem *ocxlpmem) > +{ > + return (!get_device(&ocxlpmem->dev)) ? NULL : ocxlpmem; > +} > + > +static struct ocxlpmem *find_and_get_ocxlpmem(dev_t devno) > +{ > + struct ocxlpmem *ocxlpmem; > + int minor = MINOR(devno); > + > + mutex_lock(&minors_idr_lock); > + ocxlpmem = idr_find(&minors_idr, minor); > + if (ocxlpmem) > + ocxlpmem_get(ocxlpmem); > + mutex_unlock(&minors_idr_lock); > + > + return ocxlpmem; > +} > + > +static int file_open(struct inode *inode, struct file *file) > +{ > + struct ocxlpmem *ocxlpmem; > + > + ocxlpmem = find_and_get_ocxlpmem(inode->i_rdev); > + if (!ocxlpmem) > + return -ENODEV; > + > + file->private_data = ocxlpmem; > + return 0; > +} > + > +static int file_release(struct inode *inode, struct file *file) > +{ > + struct ocxlpmem *ocxlpmem = file->private_data; > + > + ocxlpmem_put(ocxlpmem); > + return 0; > +} > + > +static const struct file_operations fops = { > + .owner = THIS_MODULE, > + .open = file_open, > + .release = file_release, > +}; > + > +/** > + * create_cdev() - Create the chardev in /dev for the device > + * @ocxlpmem: the SCM metadata > + * Return: 0 on success, negative on failure > + */ > +static int create_cdev(struct ocxlpmem *ocxlpmem) > +{ > + cdev_init(&ocxlpmem->cdev, &fops); > + return cdev_add(&ocxlpmem->cdev, ocxlpmem->dev.devt, 1); > +} > + > /** > * ocxlpmem_remove() - Free an OpenCAPI persistent memory device > * @pdev: the PCI device information struct > @@ -376,6 +438,13 @@ static void remove(struct pci_dev *pdev) > if (ocxlpmem->nvdimm_bus) > nvdimm_bus_unregister(ocxlpmem->nvdimm_bus); > > + /* > + * Remove the cdev early to prevent a race against userspace > + * via the char dev > + */ > + if (ocxlpmem->cdev.owner) > + cdev_del(&ocxlpmem->cdev); > + > device_unregister(&ocxlpmem->dev); > } > } > @@ -527,11 +596,18 @@ static int probe(struct pci_dev *pdev, const struct pci_device_id *ent) > goto err; > } > > - if (setup_command_metadata(ocxlpmem)) { > + rc = setup_command_metadata(ocxlpmem); > + if (rc) { > dev_err(&pdev->dev, "Could not read command metadata\n"); > goto err; > } > > + rc = create_cdev(ocxlpmem); > + if (rc) { > + dev_err(&pdev->dev, "Could not create character device\n"); > + goto err; > + } > + > elapsed = 0; > timeout = ocxlpmem->readiness_timeout + > ocxlpmem->memory_available_timeout; > @@ -599,6 +675,36 @@ static struct pci_driver pci_driver = { > .shutdown = remove, > }; > > +static int file_init(void) > +{ > + int rc; > + > + rc = alloc_chrdev_region(&ocxlpmem_dev, 0, NUM_MINORS, "ocxlpmem"); > + if (rc) { > + idr_destroy(&minors_idr); > + pr_err("Unable to allocate OpenCAPI persistent memory major number: %d\n", > + rc); > + return rc; > + } > + > + ocxlpmem_class = class_create(THIS_MODULE, "ocxlpmem"); > + if (IS_ERR(ocxlpmem_class)) { > + idr_destroy(&minors_idr); > + pr_err("Unable to create ocxlpmem class\n"); > + unregister_chrdev_region(ocxlpmem_dev, NUM_MINORS); > + return PTR_ERR(ocxlpmem_class); > + } > + > + return 0; > +} > + > +static void file_exit(void) > +{ > + class_destroy(ocxlpmem_class); > + unregister_chrdev_region(ocxlpmem_dev, NUM_MINORS); > + idr_destroy(&minors_idr); > +} > + > static int __init ocxlpmem_init(void) > { > int rc; > @@ -606,16 +712,23 @@ static int __init ocxlpmem_init(void) > mutex_init(&minors_idr_lock); > idr_init(&minors_idr); > > - rc = pci_register_driver(&pci_driver); > + rc = file_init(); > if (rc) > return rc; > > + rc = pci_register_driver(&pci_driver); > + if (rc) { > + file_exit(); > + return rc; > + } > + > return 0; > } > > static void ocxlpmem_exit(void) > { > pci_unregister_driver(&pci_driver); > + file_exit(); > } > > module_init(ocxlpmem_init); > diff --git a/drivers/nvdimm/ocxl/ocxlpmem.h b/drivers/nvdimm/ocxl/ocxlpmem.h > index b72b3f909fc3..ee3bd651f254 100644 > --- a/drivers/nvdimm/ocxl/ocxlpmem.h > +++ b/drivers/nvdimm/ocxl/ocxlpmem.h > @@ -2,6 +2,7 @@ > // Copyright 2020 IBM Corp. > > #include > +#include > #include > #include > #include > @@ -103,6 +104,7 @@ struct command_metadata { > struct ocxlpmem { > struct device dev; > struct pci_dev *pdev; > + struct cdev cdev; > struct ocxl_fn *ocxl_fn; > struct nd_interleave_set nd_set; > struct nvdimm_bus_descriptor bus_desc; > -- > 2.24.1 >