lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOSf1CHVWV-ku9ajCpdw4cONdpSO-8vm=oMLvCo+F1xF-xCL6w@mail.gmail.com>
Date:   Mon, 24 Feb 2020 12:30:19 +1100
From:   "Oliver O'Halloran" <oohall@...il.com>
To:     Alistair Delva <adelva@...gle.com>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Kenny Root <kroot@...gle.com>,
        Rob Herring <robh+dt@...nel.org>,
        Dan Williams <dan.j.williams@...el.com>,
        Vishal Verma <vishal.l.verma@...el.com>,
        Dave Jiang <dave.jiang@...el.com>,
        Ira Weiny <ira.weiny@...el.com>,
        Device Tree <devicetree@...r.kernel.org>,
        "linux-nvdimm@...ts.01.org" <linux-nvdimm@...ts.01.org>,
        kernel-team@...roid.com
Subject: Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT

On Sun, Feb 23, 2020 at 5:30 AM Alistair Delva <adelva@...gle.com> wrote:
>
> From: Kenny Root <kroot@...gle.com>
>
> Add support for parsing the 'memory-region' DT property in addition to
> the 'reg' DT property. This enables use cases where the pmem region is
> not in I/O address space or dedicated memory (e.g. a bootloader
> carveout).
>
> Signed-off-by: Kenny Root <kroot@...gle.com>
> Signed-off-by: Alistair Delva <adelva@...gle.com>
> Cc: "Oliver O'Halloran" <oohall@...il.com>
> Cc: Rob Herring <robh+dt@...nel.org>
> Cc: Dan Williams <dan.j.williams@...el.com>
> Cc: Vishal Verma <vishal.l.verma@...el.com>
> Cc: Dave Jiang <dave.jiang@...el.com>
> Cc: Ira Weiny <ira.weiny@...el.com>
> Cc: devicetree@...r.kernel.org
> Cc: linux-nvdimm@...ts.01.org
> Cc: kernel-team@...roid.com
> ---
>  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
>  1 file changed, 50 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 8224d1431ea9..a68e44fb0041 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -14,13 +14,47 @@ struct of_pmem_private {
>         struct nvdimm_bus *bus;
>  };
>
> +static void of_pmem_register_region(struct platform_device *pdev,
> +                                   struct nvdimm_bus *bus,
> +                                   struct device_node *np,
> +                                   struct resource *res, bool is_volatile)
> +{
> +       struct nd_region_desc ndr_desc;
> +       struct nd_region *region;
> +
> +       /*
> +        * NB: libnvdimm copies the data from ndr_desc into it's own
> +        * structures so passing a stack pointer is fine.
> +        */
> +       memset(&ndr_desc, 0, sizeof(ndr_desc));
> +       ndr_desc.numa_node = dev_to_node(&pdev->dev);
> +       ndr_desc.target_node = ndr_desc.numa_node;
> +       ndr_desc.res = res;
> +       ndr_desc.of_node = np;
> +       set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> +
> +       if (is_volatile)
> +               region = nvdimm_volatile_region_create(bus, &ndr_desc);
> +       else
> +               region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +
> +       if (!region)
> +               dev_warn(&pdev->dev,
> +                        "Unable to register region %pR from %pOF\n",
> +                        ndr_desc.res, np);
> +       else
> +               dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> +                       ndr_desc.res, np);
> +}
> +
>  static int of_pmem_region_probe(struct platform_device *pdev)
>  {
>         struct of_pmem_private *priv;
> -       struct device_node *np;
> +       struct device_node *mrp, *np;
>         struct nvdimm_bus *bus;
> +       struct resource res;
>         bool is_volatile;
> -       int i;
> +       int i, ret;
>
>         np = dev_of_node(&pdev->dev);
>         if (!np)
> @@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>                         is_volatile ? "volatile" : "non-volatile",  np);
>
>         for (i = 0; i < pdev->num_resources; i++) {
> -               struct nd_region_desc ndr_desc;
> -               struct nd_region *region;
> -
> -               /*
> -                * NB: libnvdimm copies the data from ndr_desc into it's own
> -                * structures so passing a stack pointer is fine.
> -                */
> -               memset(&ndr_desc, 0, sizeof(ndr_desc));
> -               ndr_desc.numa_node = dev_to_node(&pdev->dev);
> -               ndr_desc.target_node = ndr_desc.numa_node;
> -               ndr_desc.res = &pdev->resource[i];
> -               ndr_desc.of_node = np;
> -               set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> -
> -               if (is_volatile)
> -                       region = nvdimm_volatile_region_create(bus, &ndr_desc);
> -               else
> -                       region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +               of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
> +                                       is_volatile);
> +       }
>
> -               if (!region)
> -                       dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +       i = 0;
> +       while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {

Doesn't compile since the the iteration variable is declared above as
"mrp" rather than "mr_np". The patch looks fine otherwise and seems to
work ok, so:

Reviewed-by: Oliver O'Halloran <oohall@...il.com>

> +               ret = of_address_to_resource(mr_np, 0, &res);
> +               if (ret)
> +                       dev_warn(
> +                               &pdev->dev,
> +                               "Unable to acquire memory-region from %pOF: %d\n",
> +                               mr_np, ret);
>                 else
> -                       dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +                       of_pmem_register_region(pdev, bus, np, &res,
> +                                               is_volatile)

Now days I think it's cleaner to use braces around multi-line blocks
even if it's a single statement, up to you though.

> +               of_node_put(mr_np);
>         }
>
>         return 0;
> --
> 2.25.0.265.gbab2e86ba0-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ