All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spapr_nvdimm.c: make 'label-size' mandatory
@ 2020-04-13 20:36 Daniel Henrique Barboza
  2020-04-14  2:01 ` David Gibson
  2020-04-24  1:36 ` David Gibson
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Henrique Barboza @ 2020-04-13 20:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, david

The pseries machine does not support NVDIMM modules without label.
Attempting to do so, even if the overall block size is aligned with
256MB, will seg fault the guest kernel during NVDIMM probe. This
can be avoided by forcing 'label-size' to always be present for
sPAPR NVDIMMs.

The verification was put before the alignment check because the
presence of label-size affects the alignment calculation, so
it's not optimal to warn the user about an alignment error,
then about the lack of label-size, then about a new alignment
error when the user sets a label-size.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/ppc/spapr_nvdimm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
index 25be8082d7..9abcdcc26b 100644
--- a/hw/ppc/spapr_nvdimm.c
+++ b/hw/ppc/spapr_nvdimm.c
@@ -37,6 +37,12 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
     QemuUUID uuid;
     int ret;
 
+    if (object_property_get_int(OBJECT(nvdimm), NVDIMM_LABEL_SIZE_PROP,
+                                &error_abort) == 0) {
+        error_setg(errp, "NVDIMM device requires label-size to be set");
+        return;
+    }
+
     if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
         error_setg(errp, "NVDIMM memory size excluding the label area"
                    " must be a multiple of %" PRIu64 "MB",
-- 
2.25.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] spapr_nvdimm.c: make 'label-size' mandatory
  2020-04-13 20:36 [PATCH] spapr_nvdimm.c: make 'label-size' mandatory Daniel Henrique Barboza
@ 2020-04-14  2:01 ` David Gibson
  2020-04-14 11:04   ` Daniel Henrique Barboza
  2020-04-24  1:36 ` David Gibson
  1 sibling, 1 reply; 5+ messages in thread
From: David Gibson @ 2020-04-14  2:01 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: Igor Mammedov, Michael S. Tsirkin, qemu-ppc, qemu-devel, Xiao Guangrong

[-- Attachment #1: Type: text/plain, Size: 2408 bytes --]

CCing Xiao, Michael and Igor for generic NVDIMM perspective.

On Mon, Apr 13, 2020 at 05:36:28PM -0300, Daniel Henrique Barboza wrote:
> The pseries machine does not support NVDIMM modules without label.
> Attempting to do so, even if the overall block size is aligned with
> 256MB, will seg fault the guest kernel during NVDIMM probe. This
> can be avoided by forcing 'label-size' to always be present for
> sPAPR NVDIMMs.
> 
> The verification was put before the alignment check because the
> presence of label-size affects the alignment calculation, so
> it's not optimal to warn the user about an alignment error,
> then about the lack of label-size, then about a new alignment
> error when the user sets a label-size.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

So, this would get the job done, but it seems a bit inelegant compared
to having the device default to working settings.  I'm looking at how
this interacts with the generic constraints on label-size.

The generic nvdimm code has a MIN_NAMESPACE_LABEL_SIZE of 128 kiB, and
values of label-size less than that are rejected.  Except that if
label-size is not set at all, it is left as 0.

Is that intended behaviour?  Do x86 (or whatever) NVDIMMs have a label
of at least 128kiB, unless they have no label at all?  Or could we
make the default label-size 128kiB generically?

> ---
>  hw/ppc/spapr_nvdimm.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
> index 25be8082d7..9abcdcc26b 100644
> --- a/hw/ppc/spapr_nvdimm.c
> +++ b/hw/ppc/spapr_nvdimm.c
> @@ -37,6 +37,12 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>      QemuUUID uuid;
>      int ret;
>  
> +    if (object_property_get_int(OBJECT(nvdimm), NVDIMM_LABEL_SIZE_PROP,
> +                                &error_abort) == 0) {
> +        error_setg(errp, "NVDIMM device requires label-size to be set");
> +        return;
> +    }
> +
>      if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
>          error_setg(errp, "NVDIMM memory size excluding the label area"
>                     " must be a multiple of %" PRIu64 "MB",

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spapr_nvdimm.c: make 'label-size' mandatory
  2020-04-14  2:01 ` David Gibson
@ 2020-04-14 11:04   ` Daniel Henrique Barboza
  2020-04-24  1:45     ` David Gibson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Henrique Barboza @ 2020-04-14 11:04 UTC (permalink / raw)
  To: David Gibson
  Cc: Igor Mammedov, Michael S. Tsirkin, qemu-ppc, qemu-devel, Xiao Guangrong



On 4/13/20 11:01 PM, David Gibson wrote:
> CCing Xiao, Michael and Igor for generic NVDIMM perspective.
> 
> On Mon, Apr 13, 2020 at 05:36:28PM -0300, Daniel Henrique Barboza wrote:
>> The pseries machine does not support NVDIMM modules without label.
>> Attempting to do so, even if the overall block size is aligned with
>> 256MB, will seg fault the guest kernel during NVDIMM probe. This
>> can be avoided by forcing 'label-size' to always be present for
>> sPAPR NVDIMMs.
>>
>> The verification was put before the alignment check because the
>> presence of label-size affects the alignment calculation, so
>> it's not optimal to warn the user about an alignment error,
>> then about the lack of label-size, then about a new alignment
>> error when the user sets a label-size.
>>
>> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> 
> So, this would get the job done, but it seems a bit inelegant compared
> to having the device default to working settings.  I'm looking at how
> this interacts with the generic constraints on label-size.
> 
> The generic nvdimm code has a MIN_NAMESPACE_LABEL_SIZE of 128 kiB, and
> values of label-size less than that are rejected.  Except that if
> label-size is not set at all, it is left as 0.
> 
> Is that intended behaviour?  Do x86 (or whatever) NVDIMMs have a label
> of at least 128kiB, unless they have no label at all?  Or could we
> make the default label-size 128kiB generically?

My limited understanding on how NVDIMM works in x86 is that x86 NVDIMMs can
work with and without label, but the label has a minimum size of 128kiB.

The current NVDIMM init code always adds NVDIMM_LABEL_SIZE_PROP regardless
of user settings, as you can see in hw/mem/nvdimm.c, nvdimm_init(). I found
this out in my first attempt in this patch when doing


object_property_find(OBJECT(nvdimm), NVDIMM_LABEL_SIZE_PROP,
                      &error_abort) == 0) == NULL


inside spapr_nvdimm.c and finding out that this property is always present. This
means that the way to distinguish between label and label-less NVDIMMs is to
check label_size != 0, as we can see being done in hw/acpi/nvdimm.c. What I did
then was to use this same approach in spapr_nvdimm.c.




Thanks,


DHB



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spapr_nvdimm.c: make 'label-size' mandatory
  2020-04-13 20:36 [PATCH] spapr_nvdimm.c: make 'label-size' mandatory Daniel Henrique Barboza
  2020-04-14  2:01 ` David Gibson
@ 2020-04-24  1:36 ` David Gibson
  1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2020-04-24  1:36 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-ppc, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2210 bytes --]

On Mon, Apr 13, 2020 at 05:36:28PM -0300, Daniel Henrique Barboza wrote:
> The pseries machine does not support NVDIMM modules without label.
> Attempting to do so, even if the overall block size is aligned with
> 256MB, will seg fault the guest kernel during NVDIMM probe. This
> can be avoided by forcing 'label-size' to always be present for
> sPAPR NVDIMMs.
> 
> The verification was put before the alignment check because the
> presence of label-size affects the alignment calculation, so
> it's not optimal to warn the user about an alignment error,
> then about the lack of label-size, then about a new alignment
> error when the user sets a label-size.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

So, I still think it's kind of bogus that the guest side driver falls
over so messily (more on that elswhere in the thread).

However, regardless of that, it does make sense to enforce the PAPR
restriction that all NVDIMMs have labels.  And it fixes the visible
problem with a minimal change.

So, I've applied to ppc-for-5.1.  I am going to update the error
messages a little to make it clearer that these are PAPR specific
restrictions.

> ---
>  hw/ppc/spapr_nvdimm.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
> index 25be8082d7..9abcdcc26b 100644
> --- a/hw/ppc/spapr_nvdimm.c
> +++ b/hw/ppc/spapr_nvdimm.c
> @@ -37,6 +37,12 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>      QemuUUID uuid;
>      int ret;
>  
> +    if (object_property_get_int(OBJECT(nvdimm), NVDIMM_LABEL_SIZE_PROP,
> +                                &error_abort) == 0) {
> +        error_setg(errp, "NVDIMM device requires label-size to be set");
> +        return;
> +    }
> +
>      if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
>          error_setg(errp, "NVDIMM memory size excluding the label area"
>                     " must be a multiple of %" PRIu64 "MB",

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spapr_nvdimm.c: make 'label-size' mandatory
  2020-04-14 11:04   ` Daniel Henrique Barboza
@ 2020-04-24  1:45     ` David Gibson
  0 siblings, 0 replies; 5+ messages in thread
From: David Gibson @ 2020-04-24  1:45 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: Igor Mammedov, Michael S. Tsirkin, qemu-ppc, qemu-devel, Xiao Guangrong

[-- Attachment #1: Type: text/plain, Size: 2759 bytes --]

On Tue, Apr 14, 2020 at 08:04:29AM -0300, Daniel Henrique Barboza wrote:
> 
> 
> On 4/13/20 11:01 PM, David Gibson wrote:
> > CCing Xiao, Michael and Igor for generic NVDIMM perspective.
> > 
> > On Mon, Apr 13, 2020 at 05:36:28PM -0300, Daniel Henrique Barboza wrote:
> > > The pseries machine does not support NVDIMM modules without label.
> > > Attempting to do so, even if the overall block size is aligned with
> > > 256MB, will seg fault the guest kernel during NVDIMM probe. This
> > > can be avoided by forcing 'label-size' to always be present for
> > > sPAPR NVDIMMs.
> > > 
> > > The verification was put before the alignment check because the
> > > presence of label-size affects the alignment calculation, so
> > > it's not optimal to warn the user about an alignment error,
> > > then about the lack of label-size, then about a new alignment
> > > error when the user sets a label-size.
> > > 
> > > Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> > 
> > So, this would get the job done, but it seems a bit inelegant compared
> > to having the device default to working settings.  I'm looking at how
> > this interacts with the generic constraints on label-size.
> > 
> > The generic nvdimm code has a MIN_NAMESPACE_LABEL_SIZE of 128 kiB, and
> > values of label-size less than that are rejected.  Except that if
> > label-size is not set at all, it is left as 0.
> > 
> > Is that intended behaviour?  Do x86 (or whatever) NVDIMMs have a label
> > of at least 128kiB, unless they have no label at all?  Or could we
> > make the default label-size 128kiB generically?
> 
> My limited understanding on how NVDIMM works in x86 is that x86 NVDIMMs can
> work with and without label, but the label has a minimum size of 128kiB.

Ok.  Kinda weird, but ok.

But.. the thing that bothers me about this is that the guest is
crashing in generic code.  If the generic code can handle a label-less
nvdimm on x86, why is it dying on power.

After a bit of poking, I think the answer is that x86 is explicitly
treating label_size==0 as "label not supported" and returning explicit
errors for the get_label_size/read_label/write_label low level
operations, which the generic code is handling.  ppc, I think, is
instead just returning bogus/meaningless values which the generic code
is choking on.

So, I really think we should have the spapr_scm driver on the guest
side check for the zero sized label case and return similar errors,
for robustness.

But, I don't care enough to do it myself.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-24  1:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13 20:36 [PATCH] spapr_nvdimm.c: make 'label-size' mandatory Daniel Henrique Barboza
2020-04-14  2:01 ` David Gibson
2020-04-14 11:04   ` Daniel Henrique Barboza
2020-04-24  1:45     ` David Gibson
2020-04-24  1:36 ` David Gibson

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.