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=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=unavailable 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 DB984C2D0F3 for ; Thu, 2 Apr 2020 00:28:00 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B1D192082F for ; Thu, 2 Apr 2020 00:28:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (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 B1D192082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1B34910FC48CE; Wed, 1 Apr 2020 17:28:50 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a00:1450:4864:20::542; helo=mail-ed1-x542.google.com; envelope-from=dan.j.williams@intel.com; receiver= Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8D6C610FC48C9 for ; Wed, 1 Apr 2020 17:28:47 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id o1so2116367edv.1 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=EGGMXs/zURIXtKd2li4eTIwfDjS8HLWO7yD/UcRVp2ITqtgzK8FUvzlymf5LHO4Yi+ beAxABuFXFmGiWHDb7zbg1tRl3qZMC3EUiFYSDF7H9q4cSBdikBMJgkXeuFq1Ctk58aN g8xVaCz1c3Rss553oniEdSx9JVfu272MfVhqeL47Y8KlMVhtMsFoiCy/obmdBq6rORi+ GlG6atGLJuutsBMdTbaA8/AcjZI7BvgONozC6lQtLNjOMgOY0KeJdmEb99UfpvPKoxur CNleRCT3LUIId2ybZDwaqfc3BphhgujuBY0a9CHuEvl1AaRNXCxWuGAwBTa5ouzTtjFn szQQ== X-Gm-Message-State: AGi0PuZvpIHnx3Vphhyzat7UnusWUxgNBN3seQp3ZGugzXZG6CmGOSNE kDXnEXWmdwdDk0Bq04G148w7G/c1g17Aj7vshNpm0A== 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" Message-ID-Hash: USGGE3C5HEW5SF374W35BYBI4UNYDAM3 X-Message-ID-Hash: USGGE3C5HEW5SF374W35BYBI4UNYDAM3 X-MailFrom: dan.j.williams@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: "Aneesh Kumar K . V" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , 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 X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 > _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org 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=unavailable 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 049A1C2BA12 for ; Thu, 2 Apr 2020 00:28:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C271C207FF for ; Thu, 2 Apr 2020 00:28:00 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733089AbgDBA17 (ORCPT ); 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-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" 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 > 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=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=unavailable 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 71952C43331 for ; Thu, 2 Apr 2020 00:29:59 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0F1D42063A for ; Thu, 2 Apr 2020 00:29:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (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 0F1D42063A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48t3qS1BnpzDrF4 for ; Thu, 2 Apr 2020 11:29:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=intel.com (client-ip=2a00:1450:4864:20::542; helo=mail-ed1-x542.google.com; envelope-from=dan.j.williams@intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=b6uKoVWD; dkim-atps=neutral Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48t3nC3sg8zDrCs for ; Thu, 2 Apr 2020 11:27:58 +1100 (AEDT) Received: by mail-ed1-x542.google.com with SMTP id i16so2033147edy.11 for ; Wed, 01 Apr 2020 17:27:58 -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=DgE+JGJ6gHmWfwsGHBqosdPMXa0RnKDwR/ntUFiWekv3SsyC4PKG7qY0KYtWKbrXlC 6163FR6qU8vWLiKeV1vnDjJFmp7YyIe73KuPP9IbLCej8IYQrJJLTEmcOZcy7CXWdTCa TCeN1A2Cbgqaj2YlmtbtJRi4F6K4qDMnmh2MBGCUL8FbMkBzkWKuiV/owoJvbssSgxvO udWDasyd9x4wW8MPk+yTLaRk+Cf6olTYtntnE8ydkijAv3JhIhYonkqMmsuiRWPwn6q8 oInWXaYW0oxAFQVEBSHujtwmH+yvFOq8xRHEYSkCB2yqlvbxOX5TJvFGdKRWC9pNRT5c VYOA== X-Gm-Message-State: AGi0PuaIBtrAntWMpFAveP8jO1cWdwSodISn7MjhB0RyzVF1/Ppwbjzi BREv6MYrkhY6VWkbTzh9eHtfp1PBuYjAItsF14Mc9Q== 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" Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Madhavan Srinivasan , Alexey Kardashevskiy , Masahiro Yamada , Oliver O'Halloran , Mauro Carvalho Chehab , Ira Weiny , Rob Herring , Dave Jiang , linux-nvdimm , "Aneesh Kumar K . V" , Krzysztof Kozlowski , Anju T Sudhakar , Mahesh Salgaonkar , Andrew Donnellan , Arnd Bergmann , Greg Kurz , Nicholas Piggin , =?UTF-8?Q?C=C3=A9dric_Le_Goater?= , Thomas Gleixner , Hari Bathini , Linux MM , Greg Kroah-Hartman , Linux Kernel Mailing List , Vishal Verma , Frederic Barrat , Paul Mackerras , Andrew Morton , linuxppc-dev , "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 >