nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Liu, Jingqi" <jingqi.liu@intel.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: nvdimm@lists.linux.dev
Subject: Re: [PATCH] ndctl/dimm: Fix to dump namespace indexs and labels
Date: Wed, 9 Jun 2021 09:27:16 +0800	[thread overview]
Message-ID: <5e4349ec-18d9-ce11-c5cd-f1918404ff91@intel.com> (raw)
In-Reply-To: <CAPcyv4hzS93k5PYXE_bVp6SQ8WwPw09B+SyJC0xPKE20simwuQ@mail.gmail.com>

Hi Dan,

On 6/8/2021 4:03 AM, Dan Williams wrote:
> On Wed, Jun 2, 2021 at 6:36 PM Jingqi Liu <jingqi.liu@intel.com> wrote:
>>
>> The following bug is caused by setting the size of Label Index Block
>> to a fixed 256 bytes.
>>
>> Use the following Qemu command to start a Guest with 2MB label-size:
>>          -object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M
>>          -device nvdimm,memdev=mem1,id=nv1,label-size=2M
>>
>> There is a namespace in the Guest as follows:
>>          $ ndctl list
>>          [
>>            {
>>              "dev":"namespace0.0",
>>              "mode":"devdax",
>>              "map":"dev",
>>              "size":14780727296,
>>              "uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8",
>>              "chardev":"dax0.0",
>>              "align":2097152,
>>              "name":"namespace0.0"
>>            }
>>          ]
>>
>> Fail to read labels. The result is as follows:
>>          $ ndctl read-labels -u nmem0
>>          [
>>          ]
>>          read 0 nmem
>>
>> If using the following Qemu command to start the Guest with 128K
>> label-size, this label can be read correctly.
>>          -object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M
>>          -device nvdimm,memdev=mem1,id=nv1,label-size=128K
>>
>> The size of a Label Index Block depends on how many label slots fit into
>> the label storage area. The minimum size of an index block is 256 bytes
>> and the size must be a multiple of 256 bytes. For a storage area of 128KB,
>> the corresponding Label Index Block size is 256 bytes. But if the label
>> storage area is not 128KB, the Label Index Block size should not be 256 bytes.
>>
>> Namespace Label Index Block appears twice at the top of the label storage area.
>> Following the two index blocks, an array for storing labels takes up the
>> remainder of the label storage area.
>>
>> When reading namespace index and labels, we should read the field of 'mysize'
>> in the Label Index Block. Then we can correctly calculate the starting offset
>> of another Label Index Block and the following namespace labels.
> 
> Good find! I agree this is broken, but I'm not sure this is the way to
> fix it. The ndctl enabling is meant to support dumping index blocks
> that might be corrupt, so I don't want to rely on index block data for
> this value. It should copy the kernel which has this definition for
> determining sizeof_namespace_index():
> 
> size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
> {
>          u32 nslot, space, size;
> 
>          /*
>           * Per UEFI 2.7, the minimum size of the Label Storage Area is large
>           * enough to hold 2 index blocks and 2 labels.  The minimum index
>           * block size is 256 bytes. The label size is 128 for namespaces
>           * prior to version 1.2 and at minimum 256 for version 1.2 and later.
>           */
>          nslot = nvdimm_num_label_slots(ndd);
>          space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd);
>          size = __sizeof_namespace_index(nslot) * 2;
>          if (size <= space && nslot >= 2)
>                  return size / 2;
> 
>          dev_err(ndd->dev, "label area (%d) too small to host (%d byte)
> labels\n",
>                          ndd->nsarea.config_size, sizeof_namespace_label(ndd));
>          return 0;
> }
> 
Good point. Thanks for your comment.
I'll send a patch based on your suggestion soon.

Thanks,
Jingqi

  reply	other threads:[~2021-06-09  1:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03  1:25 [PATCH] ndctl/dimm: Fix to dump namespace indexs and labels Jingqi Liu
2021-06-07 20:03 ` Dan Williams
2021-06-09  1:27   ` Liu, Jingqi [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-09  3:06 Jingqi Liu
2021-06-16  1:31 ` Liu, Jingqi
2021-07-02  4:41 ` Dan Williams
2021-07-08  0:21 ` Verma, Vishal L
2021-07-08  1:53   ` Liu, Jingqi
2021-07-08  5:59     ` Verma, Vishal L
2021-07-08  6:52       ` Liu, Jingqi
2021-06-02 12:18 Jingqi Liu

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=5e4349ec-18d9-ce11-c5cd-f1918404ff91@intel.com \
    --to=jingqi.liu@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=nvdimm@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).