powerpc/nvdimm: Add support for multibyte read/write for metadata
PATCH 1/1 powerpc/nvdimm: Add support for multibyte read/write for metadata
SCM_READ/WRITE_MEATADATA hcall supports multibyte read/write. This patch updates the metadata read/write to use 1, 2, 4 or 8 byte read/write as mentioned in PAPR document.
READ/WRITE_METADATA hcall supports the 1, 2, 4, or 8 bytes read/write. For other values hcall results H_P3.
Hypervisor stores the metadata contents in big-endian format and in-order to enable read/write in different granularity, we need to switch the contents to big-endian before calling HCALL.
Based on an patch from Oliver O'Halloran <[email protected]>
--- arch/powerpc/platforms/pseries/papr_scm.c | 104 +++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-)
arch/powerpc/platforms/pseries/papr_scm.c +82 -22
@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 ) + read =2 ; +else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ; + +case 2 : + *(uint16_t *)(hdr->out_buf + data_offset) =be16_to_cpu (data[0 ] &0xffff ); +break ; + +case 1 : + *(uint32_t *)(hdr->out_buf + data_offset) = (data[0 ] &0xff ); +break ; + } + }return 0 ; }static int papr_scm_meta_set (struct papr_scm_priv *p, -struct nd_cmd_set_config_hdr *hdr) +struct nd_cmd_set_config_hdr *hdr) { +unsigned long offset, data_offset; +int len, wrote; +unsigned long data; +__be64 data_be;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , - p->drc_index, hdr->in_offset, hdr->in_buf[0 ],1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ +for (len = hdr->in_length; len; len -= wrote) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) { + data = *(uint64_t *)(hdr->in_buf + data_offset); + data_be =cpu_to_be64 (data); + wrote =8 ; + }else if (len >=4 ) { + data = *(uint32_t *)(hdr->in_buf + data_offset); + data &=0xffffffff ; + data_be =cpu_to_be32 (data); + wrote =4 ; + }else if (len >=2 ) { + data = *(uint16_t *)(hdr->in_buf + data_offset); + data &=0xffff ; + data_be =cpu_to_be16 (data); + wrote =2 ; + }else { + data_be = *(uint8_t *)(hdr->in_buf + data_offset); + data_be &=0xff ; + wrote =1 ; + } + + ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , p->drc_index, + offset, data_be, wrote); +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + }return 0 ; }
@@ -154,7 +214,7 @@ int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, get_size_hdr = buf; get_size_hdr->status =0 ; - get_size_hdr->max_xfer =1 ; + get_size_hdr->max_xfer =8 ; get_size_hdr->config_size = p->metadata_size; *cmd_rc =0 ;break ;
Signature · 1 line
2.21.0
Quoted 7 lines · Aneesh Kumar K.V
SCM_READ/WRITE_MEATADATA hcall supports multibyte read/write. This patch updates the metadata read/write to use 1, 2, 4 or 8 byte read/write as mentioned in PAPR document.
READ/WRITE_METADATA hcall supports the 1, 2, 4, or 8 bytes read/write. For other values hcall results
H_P3.
You should probably fold the second paragraph here into the first.
Quoted 148 lines
Hypervisor stores the metadata contents in big-endian format and in-order to enable read/write in different granularity, we need to switch the contents to big-endian before calling HCALL.
Based on an patch from Oliver O'Halloran <[email protected]>
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/platforms/pseries/papr_scm.c | 104 +++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-)arch/powerpc/platforms/pseries/papr_scm.c +82
-23@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 ) + read =2 ; +else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ; + +case 2 : + *(uint16_t *)(hdr->out_buf + data_offset) =be16_to_cpu (data[0 ] &0xffff ); +break ; + +case 1 : + *(uint32_t *)(hdr->out_buf + data_offset) = (data[0 ] &0xff ); +break ; + } + }return 0 ; }static int papr_scm_meta_set (struct papr_scm_priv *p, -struct nd_cmd_set_config_hdr *hdr) +struct nd_cmd_set_config_hdr *hdr) { +unsigned long offset, data_offset; +int len, wrote; +unsigned long data; +__be64 data_be;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , - p->drc_index, hdr->in_offset, hdr->in_buf[0 ],1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ +for (len = hdr->in_length; len; len -= wrote) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) { + data = *(uint64_t *)(hdr->in_buf + data_offset); + data_be =cpu_to_be64 (data); + wrote =8 ; + }else if (len >=4 ) { + data = *(uint32_t *)(hdr->in_buf + data_offset); + data &=0xffffffff ; + data_be =cpu_to_be32 (data); + wrote =4 ; + }else if (len >=2 ) { + data = *(uint16_t *)(hdr->in_buf + data_offset); + data &=0xffff ; + data_be =cpu_to_be16 (data); + wrote =2 ; + }else { + data_be = *(uint8_t *)(hdr->in_buf + data_offset); + data_be &=0xff ; + wrote =1 ; + } + + ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , p->drc_index, + offset, data_be, wrote); +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + }return 0 ; }@@ -154,7 +214,7 @@ int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, get_size_hdr = buf; get_size_hdr->status =0 ; - get_size_hdr->max_xfer =1 ; + get_size_hdr->max_xfer =8 ; get_size_hdr->config_size = p->metadata_size; *cmd_rc =0 ;break ; --
Quoted 1 line
2.21.0
I assume you got the qemu bits sorted out with Shiva? Looks good otherwise.
Quoted 153 lines · Oliver
Quoted 7 lines · Aneesh Kumar K.V
SCM_READ/WRITE_MEATADATA hcall supports multibyte read/write. This patch updates the metadata read/write to use 1, 2, 4 or 8 byte read/write as mentioned in PAPR document.
READ/WRITE_METADATA hcall supports the 1, 2, 4, or 8 bytes read/write. For other values hcall results
H_P3.You should probably fold the second paragraph here into the first.
Quoted 141 lines
Hypervisor stores the metadata contents in big-endian format and in-order to enable read/write in different granularity, we need to switch the contents to big-endian before calling HCALL.
Based on an patch from Oliver O'Halloran <[email protected]>
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/platforms/pseries/papr_scm.c | 104 +++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-)arch/powerpc/platforms/pseries/papr_scm.c +81
-21@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 ) + read =2 ; +else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ; + +case 2 : + *(uint16_t *)(hdr->out_buf + data_offset) =be16_to_cpu (data[0 ] &0xffff ); +break ; + +case 1 : + *(uint32_t *)(hdr->out_buf + data_offset) = (data[0 ] &0xff ); +break ; + } + }return 0 ; }static int papr_scm_meta_set (struct papr_scm_priv *p, -struct nd_cmd_set_config_hdr *hdr) +struct nd_cmd_set_config_hdr *hdr) { +unsigned long offset, data_offset; +int len, wrote; +unsigned long data; +__be64 data_be;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , - p->drc_index, hdr->in_offset, hdr->in_buf[0 ],1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ +for (len = hdr->in_length; len; len -= wrote) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) { + data = *(uint64_t *)(hdr->in_buf + data_offset); + data_be =cpu_to_be64 (data); + wrote =8 ; + }else if (len >=4 ) { + data = *(uint32_t *)(hdr->in_buf + data_offset); + data &=0xffffffff ; + data_be =cpu_to_be32 (data); + wrote =4 ; + }else if (len >=2 ) { + data = *(uint16_t *)(hdr->in_buf + data_offset); + data &=0xffff ; + data_be =cpu_to_be16 (data); + wrote =2 ; + }else { + data_be = *(uint8_t *)(hdr->in_buf + data_offset); + data_be &=0xff ; + wrote =1 ; + } + + ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , p->drc_index, + offset, data_be, wrote); +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + }return 0 ; }@@ -154,7 +214,7 @@ int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, get_size_hdr = buf;
Quoted 10 lines
Quoted 8 lines
arch/powerpc/platforms/pseries/papr_scm.c +1
-2get_size_hdr->status =0 ; - get_size_hdr->max_xfer =1 ; + get_size_hdr->max_xfer =8 ; get_size_hdr->config_size = p->metadata_size; *cmd_rc =0 ;break ; --2.21.0
I assume you got the qemu bits sorted out with Shiva? Looks good otherwise.
That is correct. I also tested with different xfer values (1, 2, 4, 8) on both Qemu and PowerVM.
Quoted 2 lines
Reviewed-by Oliver O'Halloran <[email protected]>
Thanks
-aneesh
Quoted 47 lines · Aneesh Kumar K.V
SCM_READ/WRITE_MEATADATA hcall supports multibyte read/write. This patch updates the metadata read/write to use 1, 2, 4 or 8 byte read/write as mentioned in PAPR document.
READ/WRITE_METADATA hcall supports the 1, 2, 4, or 8 bytes read/write. For other values hcall results
H_P3.Hypervisor stores the metadata contents in big-endian format and in-order to enable read/write in different granularity, we need to switch the contents to big-endian before calling HCALL.
Based on an patch from Oliver O'Halloran <[email protected]>
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/platforms/pseries/papr_scm.c | 104 +++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-)arch/powerpc/platforms/pseries/papr_scm.c +4
-12@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; -
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 119
Quoted 10 lines
arch/powerpc/platforms/pseries/papr_scm.c +10
-0+for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 )
Do not need a space before "len".
Quoted 16 lines
arch/powerpc/platforms/pseries/papr_scm.c +16
-0+ read =2 ; + else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ;
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 145
Quoted 10 lines
arch/powerpc/platforms/pseries/papr_scm.c +10
-0+case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ; + +case 2 : + *(uint16_t *)(hdr->out_buf + data_offset) =be16_to_cpu (data[0 ] &0xffff ); +break ; + +case 1 : + *(uint32_t *)(hdr->out_buf + data_offset) = (data[0 ] &0xff );
Memory corruption, should be uint8_t*.
Quoted 29 lines
arch/powerpc/platforms/pseries/papr_scm.c +11
-9+break ; + } + }return 0 ; }static int papr_scm_meta_set (struct papr_scm_priv *p, -struct nd_cmd_set_config_hdr *hdr) +struct nd_cmd_set_config_hdr *hdr) { +unsigned long offset, data_offset; +int len, wrote; +unsigned long data; +__be64 data_be;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , - p->drc_index, hdr->in_offset, hdr->in_buf[0 ],1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ +for (len = hdr->in_length; len; len -= wrote) { +
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 175
Quoted 10 lines
arch/powerpc/platforms/pseries/papr_scm.c +10
-0+ data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) { + data = *(uint64_t *)(hdr->in_buf + data_offset); + data_be =cpu_to_be64 (data); + wrote =8 ; + }else if (len >=4 ) { + data = *(uint32_t *)(hdr->in_buf + data_offset); + data &=0xffffffff ;
Why do you need &0xffffffff here and below (&0xffff, &0xff)? uint32_t is unsigned type so the sign bit won't be extended.
Quoted 33 lines
arch/powerpc/platforms/pseries/papr_scm.c +21
-1+ data_be =cpu_to_be32 (data); + wrote =4 ; + }else if (len >=2 ) { + data = *(uint16_t *)(hdr->in_buf + data_offset); + data &=0xffff ; + data_be =cpu_to_be16 (data); + wrote =2 ; + }else { + data_be = *(uint8_t *)(hdr->in_buf + data_offset); + data_be &=0xff ; + wrote =1 ; + } + + ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , p->drc_index, + offset, data_be, wrote); +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + }return 0 ; }@@ -154,7 +214,7 @@ int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, get_size_hdr = buf; get_size_hdr->status =0 ; - get_size_hdr->max_xfer =1 ; + get_size_hdr->max_xfer =8 ; get_size_hdr->config_size = p->metadata_size; *cmd_rc =0 ;break ;
Signature · 1 line
Alexey
Michael Ellerman
reviewerQuoted 3 lines · Aneesh Kumar K.V
Quoted 2 lines · Oliver
On Sun, Jun 2, 2019 at 2:44 PM Aneesh Kumar K.V
<[email protected]> wrote:
...
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
arch/powerpc/platforms/pseries/papr_scm.c +33
-12@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 ) + read =2 ; +else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ;
...
Quoted 5 lines
Quoted 2 lines
I assume you got the qemu bits sorted out with Shiva? Looks good otherwise.
That is correct. I also tested with different xfer values (1, 2, 4, 8) on both Qemu and PowerVM.
With a big endian kernel?
cheers
Quoted 52 lines · Alexey Kardashevskiy
Quoted 51 lines · Aneesh Kumar K.V
SCM_READ/WRITE_MEATADATA hcall supports multibyte read/write. This patch updates the metadata read/write to use 1, 2, 4 or 8 byte read/write as mentioned in PAPR document.
READ/WRITE_METADATA hcall supports the 1, 2, 4, or 8 bytes read/write. For other values hcall results
H_P3.Hypervisor stores the metadata contents in big-endian format and in-order to enable read/write in different granularity, we need to switch the contents to big-endian before calling HCALL.
Based on an patch from Oliver O'Halloran <[email protected]>
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/platforms/pseries/papr_scm.c | 104 +++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-)arch/powerpc/platforms/pseries/papr_scm.c +8
-12@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset;
Quoted 8 lines
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 119
Quoted 6 lines
arch/powerpc/platforms/pseries/papr_scm.c +6
-0+ +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 )Do not need a space before "len".
Will fix in next update
Quoted 23 lines
Quoted 23 lines
arch/powerpc/platforms/pseries/papr_scm.c +21
-0+ read =2 ; + else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ; + +case 2 :
Quoted 8 lines
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 145
Quoted 5 lines
arch/powerpc/platforms/pseries/papr_scm.c +5
-0+ *(uint16_t *)(hdr->out_buf + data_offset) =be16_to_cpu (data[0 ] &0xffff ); +break ; + +case 1 : + *(uint32_t *)(hdr->out_buf + data_offset) = (data[0 ] &0xff );Memory corruption, should be uint8_t*.
Good catch. That also resulted in an error on big endian kernel. Will fix that in next update
Quoted 37 lines
Quoted 37 lines
arch/powerpc/platforms/pseries/papr_scm.c +17
-9+break ; + } + }return 0 ; }static int papr_scm_meta_set (struct papr_scm_priv *p, -struct nd_cmd_set_config_hdr *hdr) +struct nd_cmd_set_config_hdr *hdr) { +unsigned long offset, data_offset; +int len, wrote; +unsigned long data; +__be64 data_be;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , - p->drc_index, hdr->in_offset, hdr->in_buf[0 ],1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ +for (len = hdr->in_length; len; len -= wrote) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) { + data = *(uint64_t *)(hdr->in_buf + data_offset); + data_be =cpu_to_be64 (data);
Quoted 8 lines
arch/powerpc/platforms/pseries/papr_scm.c static int drc_pmem_unbind(struct papr_scm_priv *p) · line 175
Quoted 4 lines
arch/powerpc/platforms/pseries/papr_scm.c +4
-0+ wrote =8 ; + }else if (len >=4 ) { + data = *(uint32_t *)(hdr->in_buf + data_offset); + data &=0xffffffff ;Why do you need &0xffffffff here and below (&0xffff, &0xff)?
uint32_tis unsigned type so the sign bit won't be extended.
Sure. I just want to make sure we don't take extra data. For now I will keep it as it is and let Michael Ellerman decide to drop that?
Quoted 28 lines
Quoted 28 lines
arch/powerpc/platforms/pseries/papr_scm.c +20
-0+ data_be =cpu_to_be32 (data); + wrote =4 ; + }else if (len >=2 ) { + data = *(uint16_t *)(hdr->in_buf + data_offset); + data &=0xffff ; + data_be =cpu_to_be16 (data); + wrote =2 ; + }else { + data_be = *(uint8_t *)(hdr->in_buf + data_offset); + data_be &=0xff ; + wrote =1 ; + } + + ret =plpar_hcall_norets (H_SCM_WRITE_METADATA , p->drc_index, + offset, data_be, wrote); +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + }return 0 ; }@@ -154,7 +214,7 @@ int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, get_size_hdr = buf;
Quoted 10 lines
Quoted 7 lines
arch/powerpc/platforms/pseries/papr_scm.c +1
-1get_size_hdr->status =0 ; - get_size_hdr->max_xfer =1 ; + get_size_hdr->max_xfer =8 ; get_size_hdr->config_size = p->metadata_size; *cmd_rc =0 ;break ;Signature · 1 line
Alexey
Thanks for the review
-aneesh
Quoted 66 lines · Michael Ellerman
Quoted 3 lines · Aneesh Kumar K.V
Quoted 2 lines · Oliver
On Sun, Jun 2, 2019 at 2:44 PM Aneesh Kumar K.V
<[email protected]> wrote:...
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
arch/powerpc/platforms/pseries/papr_scm.c +33
-12@@ -97,42 +97,102 @@ static int drc_pmem_unbind(struct papr_scm_priv *p) }static int papr_scm_meta_get (struct papr_scm_priv *p, -struct nd_cmd_get_config_data_hdr *hdr) +struct nd_cmd_get_config_data_hdr *hdr) {unsigned long data[PLPAR_HCALL_BUFSIZE ]; +unsigned long offset, data_offset; +int len, read;int64_t ret; -if (hdr->in_offset >= p->metadata_size || hdr->in_length !=1 ) +if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)return -EINVAL ; - ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, - hdr->in_offset,1 ); - -if (ret ==H_PARAMETER )/* bad DRC index */ -return -ENODEV ; -if (ret) -return -EINVAL ;/* other invalid parameter */ - - hdr->out_buf[0 ] = data[0 ] &0xff ; - +for (len = hdr->in_length; len; len -= read) { + + data_offset = hdr->in_length - len; + offset = hdr->in_offset + data_offset; + +if (len >=8 ) + read =8 ; +else if (len >=4 ) + read =4 ; +else if ( len >=2 ) + read =2 ; +else + read =1 ; + + ret =plpar_hcall (H_SCM_READ_METADATA , data, p->drc_index, + offset, read); + +if (ret ==H_PARAMETER )/* bad DRC index */ +return -ENODEV ; +if (ret) +return -EINVAL ;/* other invalid parameter */ + +switch (read) { +case 8 : + *(uint64_t *)(hdr->out_buf + data_offset) =be64_to_cpu (data[0 ]); +break ; +case 4 : + *(uint32_t *)(hdr->out_buf + data_offset) =be32_to_cpu (data[0 ] &0xffffffff ); +break ;...
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
I assume you got the qemu bits sorted out with Shiva? Looks good otherwise.
That is correct. I also tested with different xfer values (1, 2, 4, 8) on both Qemu and PowerVM.
With a big endian kernel?
I completed this testing and found new bugs in other parts of the code.
Thanks for the sugestion.
-aneesh