diff mbox

[v2,1/8] acpi nvdimm: fix wrong buffer size returned by DSM method

Message ID 1470984850-66891-2-git-send-email-guangrong.xiao@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Guangrong Aug. 12, 2016, 6:54 a.m. UTC
Currently, 'RLEN' is the totally buffer size written by QEMU and it is
ACPI internally used only. The buffer size returned to guest should
not include 'RLEN' itself

Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
 hw/acpi/nvdimm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Igor Mammedov Sept. 20, 2016, 2:07 p.m. UTC | #1
On Fri, 12 Aug 2016 14:54:03 +0800
Xiao Guangrong <guangrong.xiao@linux.intel.com> wrote:

> Currently, 'RLEN' is the totally buffer size written by QEMU and it is
> ACPI internally used only. The buffer size returned to guest should
> not include 'RLEN' itself
Do you see any errors in guest with this bug present?
It would be nice to put error messages here so that fix could be found
later just by searching git log and qemu-devel for errors user sees
in guest.


> 
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> ---
>  hw/acpi/nvdimm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
> index e486128..5454c0f 100644
> --- a/hw/acpi/nvdimm.c
> +++ b/hw/acpi/nvdimm.c
> @@ -863,6 +863,8 @@ static void nvdimm_build_common_dsm(Aml *dev)
>  
>      result_size = aml_local(1);
>      aml_append(method, aml_store(aml_name("RLEN"), result_size));
> +    /* RLEN is not included in the payload returned to guest. */
> +    aml_append(method, aml_subtract(result_size, aml_int(4), result_size));
you can merge above store with subtract like this:
  aml_subtract(aml_name("RLEN"), foo, result_size)

Style nit: try not to use magic numbers,
look at how RLEN is defined earlier, extract it into macro and reuse in both places


>      aml_append(method, aml_store(aml_shiftleft(result_size, aml_int(3)),
instead of shiftleft, I'd suggest use here multiply operator and BITS_PER_BYTE
so it would obvious what's going on and rewrite following without intermediate store.

>                                   result_size));
>      aml_append(method, aml_create_field(aml_name("ODAT"), aml_int(0),
aml_create_field(aml_name("ODAT"),
                 aml_int(0),
                 aml_multiply(result_size, aml_int(BITS_PER_BYTE), NULL),
                 "OBUF"))

BTW:
dsm_out_buf_size is more descriptive than result_size

also NCAL later uses Arg6 when method has only 5 arguments which doesn't seem right
instead of arg6 you should make/use local variable 'dsm_out_buf'

As sanity check I'd suggest to extract nvdimm ssdt in guest, decompile and compile it back.
Currently I can't compile it back which mean it's really broken.
Michael S. Tsirkin Sept. 20, 2016, 3:14 p.m. UTC | #2
On Tue, Sep 20, 2016 at 04:07:57PM +0200, Igor Mammedov wrote:
> As sanity check I'd suggest to extract nvdimm ssdt in guest, decompile and compile it back.
> Currently I can't compile it back which mean it's really broken.

Not always true, disassembler is sometimes producing weird code.
But it's a strong hint.
Igor Mammedov Sept. 20, 2016, 4:23 p.m. UTC | #3
On Tue, 20 Sep 2016 18:14:48 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, Sep 20, 2016 at 04:07:57PM +0200, Igor Mammedov wrote:
> > As sanity check I'd suggest to extract nvdimm ssdt in guest, decompile and compile it back.
> > Currently I can't compile it back which mean it's really broken.  
> 
> Not always true, disassembler is sometimes producing weird code.
> But it's a strong hint.
Unfortunately in current master it's broken as keyword ARG_FOO is used as field name
Xiao Guangrong Sept. 21, 2016, 5:30 a.m. UTC | #4
On 09/20/2016 10:07 PM, Igor Mammedov wrote:
> On Fri, 12 Aug 2016 14:54:03 +0800
> Xiao Guangrong <guangrong.xiao@linux.intel.com> wrote:
>
>> Currently, 'RLEN' is the totally buffer size written by QEMU and it is
>> ACPI internally used only. The buffer size returned to guest should
>> not include 'RLEN' itself
> Do you see any errors in guest with this bug present?
> It would be nice to put error messages here so that fix could be found
> later just by searching git log and qemu-devel for errors user sees
> in guest.
>

No, i did not see any error log in vm. I guess kernel nvdimm driver uses
the buffer based on the 'length' field. I will improve the code to check
whether the buffer size is matched with this field in vm.

>
>>
>> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>> ---
>>  hw/acpi/nvdimm.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
>> index e486128..5454c0f 100644
>> --- a/hw/acpi/nvdimm.c
>> +++ b/hw/acpi/nvdimm.c
>> @@ -863,6 +863,8 @@ static void nvdimm_build_common_dsm(Aml *dev)
>>
>>      result_size = aml_local(1);
>>      aml_append(method, aml_store(aml_name("RLEN"), result_size));
>> +    /* RLEN is not included in the payload returned to guest. */
>> +    aml_append(method, aml_subtract(result_size, aml_int(4), result_size));
> you can merge above store with subtract like this:
>   aml_subtract(aml_name("RLEN"), foo, result_size)

Yes, it is better indeed.

>
> Style nit: try not to use magic numbers,
> look at how RLEN is defined earlier, extract it into macro and reuse in both places

Okay.

>
>
>>      aml_append(method, aml_store(aml_shiftleft(result_size, aml_int(3)),
> instead of shiftleft, I'd suggest use here multiply operator and BITS_PER_BYTE
> so it would obvious what's going on and rewrite following without intermediate store.
>

I agree. However, qemu does not implement multiply primitive, i'd make a
separate patchset for these cleanups you suggested.

>>                                   result_size));
>>      aml_append(method, aml_create_field(aml_name("ODAT"), aml_int(0),
> aml_create_field(aml_name("ODAT"),
>                  aml_int(0),
>                  aml_multiply(result_size, aml_int(BITS_PER_BYTE), NULL),
>                  "OBUF"))
>
> BTW:
> dsm_out_buf_size is more descriptive than result_size

Yes, indeed.

>
> also NCAL later uses Arg6 when method has only 5 arguments which doesn't seem right
> instead of arg6 you should make/use local variable 'dsm_out_buf'

Sorry, my typo. Will fix.

>
> As sanity check I'd suggest to extract nvdimm ssdt in guest, decompile and compile it back.
> Currently I can't compile it back which mean it's really broken.
>

Good suggestion, i will try it.
diff mbox

Patch

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index e486128..5454c0f 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -863,6 +863,8 @@  static void nvdimm_build_common_dsm(Aml *dev)
 
     result_size = aml_local(1);
     aml_append(method, aml_store(aml_name("RLEN"), result_size));
+    /* RLEN is not included in the payload returned to guest. */
+    aml_append(method, aml_subtract(result_size, aml_int(4), result_size));
     aml_append(method, aml_store(aml_shiftleft(result_size, aml_int(3)),
                                  result_size));
     aml_append(method, aml_create_field(aml_name("ODAT"), aml_int(0),