[v6,18/33] dimm: get mapped memory region from DIMMDeviceClass->get_memory_region
diff mbox

Message ID 1446184587-142784-19-git-send-email-guangrong.xiao@linux.intel.com
State New
Headers show

Commit Message

Xiao Guangrong Oct. 30, 2015, 5:56 a.m. UTC
Curretly, the memory region of backed memory is directly mapped to
guest's address space, however, it is not true for nvdimm device

This patch let dimm device realize this fact and use
DIMMDeviceClass->get_memory_region method to get the mapped memory
region

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

Comments

Vladimir Sementsov-Ogievskiy Oct. 31, 2015, 10:52 a.m. UTC | #1
On 30.10.2015 08:56, Xiao Guangrong wrote:
> Curretly, the memory region of backed memory is directly mapped to
> guest's address space, however, it is not true for nvdimm device
>
> This patch let dimm device realize this fact and use
> DIMMDeviceClass->get_memory_region method to get the mapped memory
> region
>
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> ---
>   hw/mem/dimm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
> index 4a63409..498d380 100644
> --- a/hw/mem/dimm.c
> +++ b/hw/mem/dimm.c
> @@ -377,8 +377,9 @@ static void dimm_get_size(Object *obj, Visitor *v, void *opaque,
>       int64_t value;
>       MemoryRegion *mr;
>       DIMMDevice *dimm = DIMM(obj);
> +    DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj);
>   
> -    mr = host_memory_backend_get_memory(dimm->hostmem, errp);
> +    mr = ddc->get_memory_region(dimm);
>       value = memory_region_size(mr);
>   
>       visit_type_int(v, &value, name, errp);

Isn't it better to add Error** parameter to get_memory_region and not 
mix returning error in errp parameter and aborting through &error_abort?
Xiao Guangrong Oct. 31, 2015, 2:15 p.m. UTC | #2
On 10/31/2015 06:52 PM, Vladimir Sementsov-Ogievskiy wrote:
> On 30.10.2015 08:56, Xiao Guangrong wrote:
>> Curretly, the memory region of backed memory is directly mapped to
>> guest's address space, however, it is not true for nvdimm device
>>
>> This patch let dimm device realize this fact and use
>> DIMMDeviceClass->get_memory_region method to get the mapped memory
>> region
>>
>> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>> ---
>>   hw/mem/dimm.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
>> index 4a63409..498d380 100644
>> --- a/hw/mem/dimm.c
>> +++ b/hw/mem/dimm.c
>> @@ -377,8 +377,9 @@ static void dimm_get_size(Object *obj, Visitor *v, void *opaque,
>>       int64_t value;
>>       MemoryRegion *mr;
>>       DIMMDevice *dimm = DIMM(obj);
>> +    DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj);
>> -    mr = host_memory_backend_get_memory(dimm->hostmem, errp);
>> +    mr = ddc->get_memory_region(dimm);
>>       value = memory_region_size(mr);
>>       visit_type_int(v, &value, name, errp);
>
> Isn't it better to add Error** parameter to get_memory_region and not mix returning error in errp
> parameter and aborting through &error_abort?
>

Yes, it's better, will do. Thanks for your suggestion.


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Xiao Guangrong Nov. 2, 2015, 9:18 a.m. UTC | #3
On 10/31/2015 10:15 PM, Xiao Guangrong wrote:
>
>
> On 10/31/2015 06:52 PM, Vladimir Sementsov-Ogievskiy wrote:
>> On 30.10.2015 08:56, Xiao Guangrong wrote:
>>> Curretly, the memory region of backed memory is directly mapped to
>>> guest's address space, however, it is not true for nvdimm device
>>>
>>> This patch let dimm device realize this fact and use
>>> DIMMDeviceClass->get_memory_region method to get the mapped memory
>>> region
>>>
>>> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>> ---
>>>   hw/mem/dimm.c | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
>>> index 4a63409..498d380 100644
>>> --- a/hw/mem/dimm.c
>>> +++ b/hw/mem/dimm.c
>>> @@ -377,8 +377,9 @@ static void dimm_get_size(Object *obj, Visitor *v, void *opaque,
>>>       int64_t value;
>>>       MemoryRegion *mr;
>>>       DIMMDevice *dimm = DIMM(obj);
>>> +    DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj);
>>> -    mr = host_memory_backend_get_memory(dimm->hostmem, errp);
>>> +    mr = ddc->get_memory_region(dimm);
>>>       value = memory_region_size(mr);
>>>       visit_type_int(v, &value, name, errp);
>>
>> Isn't it better to add Error** parameter to get_memory_region and not mix returning error in errp
>> parameter and aborting through &error_abort?
>>
>
> Yes, it's better, will do. Thanks for your suggestion.

Vladimir,

After checking the current code, the @errp in pc-dimm's get_memory_region() is useless
and all its caller did not check the return value as they assumed the backend memory of
pc-dimm is always properly initialized.

So we catch the error condition internally instead of propagating it to the caller:

  static MemoryRegion *pc_dimm_get_memory_region(DIMMDevice *dimm)
  {
-    return host_memory_backend_get_memory(dimm->hostmem, &error_abort);
+    Error *local_err = NULL;
+    MemoryRegion *mr;
+
+    mr = host_memory_backend_get_memory(dimm->hostmem, &local_err);
+
+    /*
+     * plug a pc-dimm device whose backend memory was not properly
+     * initialized?
+     */
+    assert(!local_err && mr);
+    return mr;
  }

please review it in the new version i have CCed you.

Thanks for your review.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 4a63409..498d380 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -377,8 +377,9 @@  static void dimm_get_size(Object *obj, Visitor *v, void *opaque,
     int64_t value;
     MemoryRegion *mr;
     DIMMDevice *dimm = DIMM(obj);
+    DIMMDeviceClass *ddc = DIMM_GET_CLASS(obj);
 
-    mr = host_memory_backend_get_memory(dimm->hostmem, errp);
+    mr = ddc->get_memory_region(dimm);
     value = memory_region_size(mr);
 
     visit_type_int(v, &value, name, errp);