From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82960C43331 for ; Thu, 2 Apr 2020 00:27:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2201A207FF for ; Thu, 2 Apr 2020 00:27:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="b6uKoVWD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2201A207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BE9378E0008; Wed, 1 Apr 2020 20:27:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9BC98E0007; Wed, 1 Apr 2020 20:27:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A621B8E0008; Wed, 1 Apr 2020 20:27:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 8DF068E0007 for ; Wed, 1 Apr 2020 20:27:58 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 46EF38248047 for ; Thu, 2 Apr 2020 00:27:58 +0000 (UTC) X-FDA: 76661027436.17.kite99_28716515a3a5e X-HE-Tag: kite99_28716515a3a5e X-Filterd-Recvd-Size: 10775 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 2 Apr 2020 00:27:57 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id a43so2070440edf.6 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=cH1ILBKnHp2CMCxF+JP1pSGt6HAVV9ZYIAZ6R+OzfV4OTxrYzwHPOnIiVtVKoasypZ FSUnPpFAx+Jgn2YknFtJ/Z2YK4+P1/IWe7QxL3jA2LpA1JN8T2Wo3ro7oy2+ZYOEtAXk wt7DIPF0r6gPB31knuTxy2qT1KUYO+PEHG+fbhwDjjV+H7Mbezz51W1LfjJjGbGhhwNn YO2xP6p4TLojLJlyfdhURX3yIomkxrpnlEUo0yJCUnpvE4EasUE7Awfe+oI/XrdvqQJo 1OtR6yMqMOs3oTNlh+njixJAq0I6ZOoVZPyOGW02/BRTOiFzKOuBtDO6IkkYmM/XykO4 7EjA== X-Gm-Message-State: AGi0PuYcGEFCkQ/jUKMjHUS7Ln8J9UaGkUW6zACb/PizX4igz+Ung6GV Erg1amWL49gQm009LDJ+6XngByGlNujlIxbX+LhjuA== X-Google-Smtp-Source: APiQypK1MdubaXDzXDW0OryS7Btp1yg8dmm5kamYFesYesYpOR0BQWhTUFKcfXpacPdBoNYqNEriI3UdkexV9JqGWrM= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 >