All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-nvdimm@lists.01.org, axboe@kernel.dk, sfr@canb.auug.org.au,
	rafael@kernel.org, neilb@suse.de, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	linux-acpi@vger.kernel.org, jmoyer@redhat.com,
	linux-api@vger.kernel.org, akpm@linux-foundation.org, hch@lst.de
Subject: Re: [PATCH v5 02/21] libnvdimm, nfit: initial libnvdimm infrastructure and NFIT support
Date: Wed, 3 Jun 2015 16:57:04 +0200	[thread overview]
Message-ID: <20150603145704.GA22311@lst.de> (raw)
In-Reply-To: <20150602001419.4506.41953.stgit@dwillia2-desk3.amr.corp.intel.com>

On Mon, Jun 01, 2015 at 08:14:19PM -0400, Dan Williams wrote:
> A libnvdimm bus is the anchor device for registering nvdimm resources and
> interfaces, for example, a character control device, nvdimm devices,
> and I/O region devices.  The ACPI NFIT (NVDIMM Firmware Interface Table)
> is one possible platform description for such non-volatile memory
> resources in a system.  The nfit.ko driver attaches to the "ACPI0012"
> device that indicates the presence of the NFIT and parses the table to
> register a libnvdimm bus instance.

Havin lib in a name of a bus seems odd.  Why not simply the nvdimm bus?

Also this seems to both have the generic nvdimm infrastructure as well
as the acpi wiring.  Might make sense to split this into two patches?

> +config ACPI_NFIT
> +	tristate "ACPI NVDIMM Firmware Interface Table (NFIT)"
> +	depends on PHYS_ADDR_T_64BIT
> +	depends on BLK_DEV
> +	select NVDIMM_DEVICES
> +	select LIBNVDIMM

Is this the right way for the user to chose it?  It seems like enabling
the NVMDIMM subsystem would be the obvious choice, and ACPI would
simply enable the table parsing in that case.

> +static u8 nfit_uuid[NFIT_UUID_MAX][16];

Should this use the uuid_le type?

> +static const char *spa_type_name(u16 type)
> +{
> +	switch (type) {
> +	case NFIT_SPA_VOLATILE: return "volatile";
> +	case NFIT_SPA_PM: return "pmem";
> +	case NFIT_SPA_DCR: return "dimm-control-region";
> +	case NFIT_SPA_BDW: return "block-data-window";
> +	default: return "unknown";

Please never put code on the same line as a switch (or goto) label.

> +static void *add_table(struct acpi_nfit_desc *acpi_desc, void *table, const void *end)
> +{
> +	struct device *dev = acpi_desc->dev;
> +	struct acpi_nfit_header *hdr;
> +	void *err = ERR_PTR(-ENOMEM);
> +
> +	if (table >= end)
> +		return NULL;
> +
> +	hdr = (struct acpi_nfit_header *) table;

No need to case from void * to another pointer type.

> +	switch (hdr->type) {
> +	case ACPI_NFIT_TYPE_SYSTEM_ADDRESS: {
> +		struct nfit_spa *nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa),
> +				GFP_KERNEL);
> +		struct acpi_nfit_system_address *spa = table;
> +
> +		if (!nfit_spa)
> +			return err;
> +		INIT_LIST_HEAD(&nfit_spa->list);
> +		nfit_spa->spa = spa;
> +		list_add_tail(&nfit_spa->list, &acpi_desc->spas);
> +		dev_dbg(dev, "%s: spa index: %d type: %s\n", __func__,
> +				spa->range_index,
> +				spa_type_name(nfit_spa_type(spa)));

If you need local variables inside a switch statement you probably
want to split each case into a separate helper function.

> +static inline struct acpi_nfit_memory_map *__to_nfit_memdev(struct nfit_mem *nfit_mem)

This line is over 80 characters.

Also why the odd __-prefix?

> new file mode 100644
> index 000000000000..24b51dbc8215
> --- /dev/null
> +++ b/drivers/nvdimm/Kconfig
> @@ -0,0 +1,20 @@
> +menuconfig NVDIMM_DEVICES
> +	bool "NVDIMM (Non-Volatile Memory Device) Support"
> +	help
> +	  Generic support for non-volatile memory devices including
> +	  ACPI-6-NFIT defined resources.  On platforms that define an
> +	  NFIT, or otherwise can discover NVDIMM resources, a libnvdimm
> +	  bus is registered to advertise PMEM (persistent memory)
> +	  namespaces (/dev/pmemX) and BLK (sliding mmio window(s))
> +	  namespaces (/dev/ndX). A PMEM namespace refers to a memory
> +	  resource that may span multiple DIMMs and support DAX (see
> +	  CONFIG_DAX).  A BLK namespace refers to an NVDIMM control
> +	  region which exposes an mmio register set for windowed
> +	  access mode to non-volatile memory.
> +
> +if NVDIMM_DEVICES
> +
> +config LIBNVDIMM
> +	tristate
> +
> +endif

What different meanings will CONFIG_NVDIMM_DEVICES and CONFIG_LIBNVDIMM
have?

> diff --git a/drivers/nvdimm/nd-private.h b/drivers/nvdimm/nd-private.h
> new file mode 100644
> index 000000000000..e7c4e99a22a4
> --- /dev/null
> +++ b/drivers/nvdimm/nd-private.h

No need for -private if you're already under drivers/nvdimm..

> +#ifndef __ND_PRIVATE_H__
> +#define __ND_PRIVATE_H__
> +#include <linux/libnvdimm.h>
> +#include <linux/device.h>
> +
> +struct nvdimm_bus {
> +	struct nvdimm_bus_descriptor *nd_desc;
> +	struct device dev;
> +	int id;
> +};
> +#endif /* __ND_PRIVATE_H__ */

At least so far this header doesn't need libnvdimm.h

> +#ifndef __LIBNVDIMM_H__
> +#define __LIBNVDIMM_H__
> +struct nvdimm;
> +struct nvdimm_bus_descriptor;
> +typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
> +		struct nvdimm *nvdimm, unsigned int cmd, void *buf,
> +		unsigned int buf_len);
> +
> +struct nvdimm_bus_descriptor {
> +	unsigned long dsm_mask;
> +	char *provider_name;
> +	ndctl_fn ndctl;
> +};

Please provide proper methods that do one thing properly instead of
ioctl-like multiplexers.

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-nvdimm@ml01.01.org, axboe@kernel.dk, sfr@canb.auug.org.au,
	rafael@kernel.org, neilb@suse.de, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	linux-acpi@vger.kernel.org, jmoyer@redhat.com,
	linux-api@vger.kernel.org, akpm@linux-foundation.org, hch@lst.de
Subject: Re: [PATCH v5 02/21] libnvdimm, nfit: initial libnvdimm infrastructure and NFIT support
Date: Wed, 3 Jun 2015 16:57:04 +0200	[thread overview]
Message-ID: <20150603145704.GA22311@lst.de> (raw)
In-Reply-To: <20150602001419.4506.41953.stgit@dwillia2-desk3.amr.corp.intel.com>

On Mon, Jun 01, 2015 at 08:14:19PM -0400, Dan Williams wrote:
> A libnvdimm bus is the anchor device for registering nvdimm resources and
> interfaces, for example, a character control device, nvdimm devices,
> and I/O region devices.  The ACPI NFIT (NVDIMM Firmware Interface Table)
> is one possible platform description for such non-volatile memory
> resources in a system.  The nfit.ko driver attaches to the "ACPI0012"
> device that indicates the presence of the NFIT and parses the table to
> register a libnvdimm bus instance.

Havin lib in a name of a bus seems odd.  Why not simply the nvdimm bus?

Also this seems to both have the generic nvdimm infrastructure as well
as the acpi wiring.  Might make sense to split this into two patches?

> +config ACPI_NFIT
> +	tristate "ACPI NVDIMM Firmware Interface Table (NFIT)"
> +	depends on PHYS_ADDR_T_64BIT
> +	depends on BLK_DEV
> +	select NVDIMM_DEVICES
> +	select LIBNVDIMM

Is this the right way for the user to chose it?  It seems like enabling
the NVMDIMM subsystem would be the obvious choice, and ACPI would
simply enable the table parsing in that case.

> +static u8 nfit_uuid[NFIT_UUID_MAX][16];

Should this use the uuid_le type?

> +static const char *spa_type_name(u16 type)
> +{
> +	switch (type) {
> +	case NFIT_SPA_VOLATILE: return "volatile";
> +	case NFIT_SPA_PM: return "pmem";
> +	case NFIT_SPA_DCR: return "dimm-control-region";
> +	case NFIT_SPA_BDW: return "block-data-window";
> +	default: return "unknown";

Please never put code on the same line as a switch (or goto) label.

> +static void *add_table(struct acpi_nfit_desc *acpi_desc, void *table, const void *end)
> +{
> +	struct device *dev = acpi_desc->dev;
> +	struct acpi_nfit_header *hdr;
> +	void *err = ERR_PTR(-ENOMEM);
> +
> +	if (table >= end)
> +		return NULL;
> +
> +	hdr = (struct acpi_nfit_header *) table;

No need to case from void * to another pointer type.

> +	switch (hdr->type) {
> +	case ACPI_NFIT_TYPE_SYSTEM_ADDRESS: {
> +		struct nfit_spa *nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa),
> +				GFP_KERNEL);
> +		struct acpi_nfit_system_address *spa = table;
> +
> +		if (!nfit_spa)
> +			return err;
> +		INIT_LIST_HEAD(&nfit_spa->list);
> +		nfit_spa->spa = spa;
> +		list_add_tail(&nfit_spa->list, &acpi_desc->spas);
> +		dev_dbg(dev, "%s: spa index: %d type: %s\n", __func__,
> +				spa->range_index,
> +				spa_type_name(nfit_spa_type(spa)));

If you need local variables inside a switch statement you probably
want to split each case into a separate helper function.

> +static inline struct acpi_nfit_memory_map *__to_nfit_memdev(struct nfit_mem *nfit_mem)

This line is over 80 characters.

Also why the odd __-prefix?

> new file mode 100644
> index 000000000000..24b51dbc8215
> --- /dev/null
> +++ b/drivers/nvdimm/Kconfig
> @@ -0,0 +1,20 @@
> +menuconfig NVDIMM_DEVICES
> +	bool "NVDIMM (Non-Volatile Memory Device) Support"
> +	help
> +	  Generic support for non-volatile memory devices including
> +	  ACPI-6-NFIT defined resources.  On platforms that define an
> +	  NFIT, or otherwise can discover NVDIMM resources, a libnvdimm
> +	  bus is registered to advertise PMEM (persistent memory)
> +	  namespaces (/dev/pmemX) and BLK (sliding mmio window(s))
> +	  namespaces (/dev/ndX). A PMEM namespace refers to a memory
> +	  resource that may span multiple DIMMs and support DAX (see
> +	  CONFIG_DAX).  A BLK namespace refers to an NVDIMM control
> +	  region which exposes an mmio register set for windowed
> +	  access mode to non-volatile memory.
> +
> +if NVDIMM_DEVICES
> +
> +config LIBNVDIMM
> +	tristate
> +
> +endif

What different meanings will CONFIG_NVDIMM_DEVICES and CONFIG_LIBNVDIMM
have?

> diff --git a/drivers/nvdimm/nd-private.h b/drivers/nvdimm/nd-private.h
> new file mode 100644
> index 000000000000..e7c4e99a22a4
> --- /dev/null
> +++ b/drivers/nvdimm/nd-private.h

No need for -private if you're already under drivers/nvdimm..

> +#ifndef __ND_PRIVATE_H__
> +#define __ND_PRIVATE_H__
> +#include <linux/libnvdimm.h>
> +#include <linux/device.h>
> +
> +struct nvdimm_bus {
> +	struct nvdimm_bus_descriptor *nd_desc;
> +	struct device dev;
> +	int id;
> +};
> +#endif /* __ND_PRIVATE_H__ */

At least so far this header doesn't need libnvdimm.h

> +#ifndef __LIBNVDIMM_H__
> +#define __LIBNVDIMM_H__
> +struct nvdimm;
> +struct nvdimm_bus_descriptor;
> +typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
> +		struct nvdimm *nvdimm, unsigned int cmd, void *buf,
> +		unsigned int buf_len);
> +
> +struct nvdimm_bus_descriptor {
> +	unsigned long dsm_mask;
> +	char *provider_name;
> +	ndctl_fn ndctl;
> +};

Please provide proper methods that do one thing properly instead of
ioctl-like multiplexers.

  reply	other threads:[~2015-06-03 14:57 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02  0:14 [PATCH v5 00/21] libnvdimm: non-volatile memory devices Dan Williams
2015-06-02  0:14 ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 01/21] e820, efi: add ACPI 6.0 persistent memory types Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 02/21] libnvdimm, nfit: initial libnvdimm infrastructure and NFIT support Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-03 14:57   ` Christoph Hellwig [this message]
2015-06-03 14:57     ` Christoph Hellwig
2015-06-03 19:24     ` Williams, Dan J
2015-06-03 19:24       ` Williams, Dan J
2015-06-03 19:24       ` Williams, Dan J
2015-06-09  6:33       ` hch
2015-06-09  6:33         ` hch
2015-06-09  6:33         ` hch-jcswGhMUV9g
2015-06-09 22:27         ` Dan Williams
2015-06-09 22:27           ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 03/21] libnvdimm: control character device and libnvdimm bus sysfs attributes Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 04/21] libnvdimm, nfit: dimm/memory-devices Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 05/21] libnvdimm: control (ioctl) messages for libnvdimm bus and dimm devices Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-09  6:34   ` Christoph Hellwig
2015-06-09  6:34     ` Christoph Hellwig
2015-06-09  6:34     ` Christoph Hellwig
2015-06-09  6:57     ` Dan Williams
2015-06-09  6:57       ` Dan Williams
2015-06-09  6:57       ` Dan Williams
2015-06-10  7:33       ` Christoph Hellwig
2015-06-10  7:33         ` Christoph Hellwig
2015-06-10  7:33         ` Christoph Hellwig
2015-06-02  0:14 ` [PATCH v5 06/21] libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver infrastructure Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 07/21] libnvdimm, nfit: regions (block-data-window, persistent memory, volatile memory) Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 08/21] libnvdimm: support for legacy (non-aliasing) nvdimms Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-02  0:14 ` [PATCH v5 09/21] libnvdimm, nd_pmem: add libnvdimm support to the pmem driver Dan Williams
2015-06-02  0:14   ` Dan Williams
2015-06-03  7:44   ` Christoph Hellwig
     [not found]     ` <20150603074424.GA24949-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-06-03 19:31       ` Williams, Dan J
2015-06-03 19:31         ` Williams, Dan J
     [not found]         ` <1433359894.21035.33.camel-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-06-09  6:36           ` hch-jcswGhMUV9g
2015-06-09  6:36             ` hch
2015-06-02  0:15 ` [PATCH v5 10/21] pmem: Dynamically allocate partition numbers Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 11/21] libnvdimm, nfit: add interleave-set state-tracking infrastructure Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 12/21] libnvdimm: namespace indices: read and validate Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-09  6:39   ` Christoph Hellwig
2015-06-09  6:39     ` Christoph Hellwig
2015-06-09  6:39     ` Christoph Hellwig
2015-06-10 15:54     ` Dan Williams
2015-06-10 15:54       ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 13/21] libnvdimm: pmem label sets and namespace instantiation Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 14/21] libnvdimm: blk labels " Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 15/21] libnvdimm: write pmem label set Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 16/21] libnvdimm: write blk " Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 17/21] libnvdimm: infrastructure for btt devices Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-09  6:42   ` Christoph Hellwig
2015-06-09  6:42     ` Christoph Hellwig
2015-06-10 18:46     ` Matthew Wilcox
2015-06-10 18:46       ` Matthew Wilcox
2015-06-11  7:28       ` Christoph Hellwig
2015-06-11  7:28         ` Christoph Hellwig
     [not found]         ` <20150611072812.GB1905-jcswGhMUV9g@public.gmane.org>
2015-06-17 16:47           ` Jeff Moyer
2015-06-17 16:47             ` Jeff Moyer
     [not found]             ` <x49381qp9ic.fsf-RRHT56Q3PSP4kTEheFKJxxDDeQx5vsVwAInAS/Ez/D0@public.gmane.org>
2015-06-17 16:50               ` Dan Williams
2015-06-17 16:50                 ` Dan Williams
2015-06-17 16:57                 ` Jeff Moyer
2015-06-17 16:57                   ` Jeff Moyer
2015-06-17 17:09                   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 18/21] nd_btt: atomic sector updates Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-09  6:44   ` Christoph Hellwig
2015-06-09  6:44     ` Christoph Hellwig
2015-06-09  6:44     ` Christoph Hellwig
2015-06-09 18:27     ` Vishal Verma
2015-06-09 18:27       ` Vishal Verma
2015-06-10  7:34       ` Christoph Hellwig
2015-06-10  7:34         ` Christoph Hellwig
2015-06-10  7:34         ` Christoph Hellwig
2015-06-10 18:24         ` Vishal Verma
2015-06-10 18:24           ` Vishal Verma
2015-06-02  0:15 ` [PATCH v5 19/21] libnvdimm, nfit, nd_blk: driver for BLK-mode access persistent memory Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15 ` [PATCH v5 20/21] tools/testing/nvdimm: manufactured NFITs for interface development Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-02  0:15   ` Dan Williams
2015-06-09  6:48   ` Christoph Hellwig
2015-06-09  6:48     ` Christoph Hellwig
2015-06-09  6:48     ` Christoph Hellwig
2015-06-11 20:12     ` Dan Williams
2015-06-11 20:12       ` Dan Williams
2015-06-02  0:16 ` [PATCH v5 21/21] libnvdimm: Non-Volatile Devices Dan Williams
2015-06-02  0:16   ` Dan Williams

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=20150603145704.GA22311@lst.de \
    --to=hch@lst.de \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jmoyer@redhat.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=mingo@kernel.org \
    --cc=neilb@suse.de \
    --cc=rafael@kernel.org \
    --cc=sfr@canb.auug.org.au \
    /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.