From mboxrd@z Thu Jan 1 00:00:00 1970 From: Igor Mammedov Subject: Re: [PATCH v2 1/8] acpi nvdimm: fix wrong buffer size returned by DSM method Date: Tue, 20 Sep 2016 16:07:57 +0200 Message-ID: <20160920160757.3fdc2ce8@nial.brq.redhat.com> References: <1470984850-66891-1-git-send-email-guangrong.xiao@linux.intel.com> <1470984850-66891-2-git-send-email-guangrong.xiao@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: pbonzini@redhat.com, gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org To: Xiao Guangrong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:36056 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751387AbcITOIC (ORCPT ); Tue, 20 Sep 2016 10:08:02 -0400 In-Reply-To: <1470984850-66891-2-git-send-email-guangrong.xiao@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, 12 Aug 2016 14:54:03 +0800 Xiao Guangrong 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 > --- > 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmLiS-0001Uu-Cn for qemu-devel@nongnu.org; Tue, 20 Sep 2016 10:08:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmLiN-0001bD-6Y for qemu-devel@nongnu.org; Tue, 20 Sep 2016 10:08:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmLiM-0001aE-Vc for qemu-devel@nongnu.org; Tue, 20 Sep 2016 10:08:03 -0400 Date: Tue, 20 Sep 2016 16:07:57 +0200 From: Igor Mammedov Message-ID: <20160920160757.3fdc2ce8@nial.brq.redhat.com> In-Reply-To: <1470984850-66891-2-git-send-email-guangrong.xiao@linux.intel.com> References: <1470984850-66891-1-git-send-email-guangrong.xiao@linux.intel.com> <1470984850-66891-2-git-send-email-guangrong.xiao@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/8] acpi nvdimm: fix wrong buffer size returned by DSM method List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xiao Guangrong Cc: pbonzini@redhat.com, gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org On Fri, 12 Aug 2016 14:54:03 +0800 Xiao Guangrong 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 > --- > 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.