diff mbox

[1/4] acpi,memory-hotplug : add memory offline code to acpi_memory_device_remove()

Message ID 506C0C53.60205@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yasuaki Ishimatsu Oct. 3, 2012, 9:58 a.m. UTC
From: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>

The memory device can be removed by 2 ways:
1. send eject request by SCI
2. echo 1 >/sys/bus/pci/devices/PNP0C80:XX/eject

In the 1st case, acpi_memory_disable_device() will be called.
In the 2nd case, acpi_memory_device_remove() will be called.
acpi_memory_device_remove() will also be called when we unbind the
memory device from the driver acpi_memhotplug.

acpi_memory_disable_device() has already implemented a code which
offlines memory and releases acpi_memory_info struct . But
acpi_memory_device_remove() has not implemented it yet.

So the patch implements acpi_memory_remove_memory() for offlining
memory and releasing acpi_memory_info struct. And it is used by both
acpi_memory_device_remove() and acpi_memory_disable_device().

Additionally, if the type is ACPI_BUS_REMOVAL_EJECT in
acpi_memory_device_remove() , it means that the user wants to eject
the memory device. In this case, acpi_memory_device_remove() calls
acpi_memory_remove_memory().

CC: David Rientjes <rientjes@google.com>
CC: Jiang Liu <liuj97@gmail.com>
CC: Len Brown <len.brown@intel.com>
CC: Christoph Lameter <cl@linux.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> 
Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
 drivers/acpi/acpi_memhotplug.c |   44 +++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)


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

Comments

Motohiro KOSAKI Oct. 4, 2012, 8:53 p.m. UTC | #1
On Wed, Oct 3, 2012 at 5:58 AM, Yasuaki Ishimatsu
<isimatu.yasuaki@jp.fujitsu.com> wrote:
> From: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
>
> The memory device can be removed by 2 ways:
> 1. send eject request by SCI
> 2. echo 1 >/sys/bus/pci/devices/PNP0C80:XX/eject
>
> In the 1st case, acpi_memory_disable_device() will be called.
> In the 2nd case, acpi_memory_device_remove() will be called.
> acpi_memory_device_remove() will also be called when we unbind the
> memory device from the driver acpi_memhotplug.
>
> acpi_memory_disable_device() has already implemented a code which
> offlines memory and releases acpi_memory_info struct . But
> acpi_memory_device_remove() has not implemented it yet.
>
> So the patch implements acpi_memory_remove_memory() for offlining
> memory and releasing acpi_memory_info struct. And it is used by both
> acpi_memory_device_remove() and acpi_memory_disable_device().
>
> Additionally, if the type is ACPI_BUS_REMOVAL_EJECT in
> acpi_memory_device_remove() , it means that the user wants to eject
> the memory device. In this case, acpi_memory_device_remove() calls
> acpi_memory_remove_memory().
>
> CC: David Rientjes <rientjes@google.com>
> CC: Jiang Liu <liuj97@gmail.com>
> CC: Len Brown <len.brown@intel.com>
> CC: Christoph Lameter <cl@linux.com>
> Cc: Minchan Kim <minchan.kim@gmail.com>
> CC: Andrew Morton <akpm@linux-foundation.org>
> CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> ---
>  drivers/acpi/acpi_memhotplug.c |   44 +++++++++++++++++++++++++++++++----------
>  1 file changed, 34 insertions(+), 10 deletions(-)
>
> Index: linux-3.6/drivers/acpi/acpi_memhotplug.c
> ===================================================================
> --- linux-3.6.orig/drivers/acpi/acpi_memhotplug.c       2012-10-03 18:55:33.386378909 +0900
> +++ linux-3.6/drivers/acpi/acpi_memhotplug.c    2012-10-03 18:55:58.624380688 +0900
> @@ -306,24 +306,37 @@ static int acpi_memory_powerdown_device(
>         return 0;
>  }
>
> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>  {
>         int result;
>         struct acpi_memory_info *info, *n;
>
> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {

Which lock protect this loop?


> +               if (!info->enabled)
> +                       return -EBUSY;
> +
> +               result = remove_memory(info->start_addr, info->length);
> +               if (result)
> +                       return result;

I suspect you need to implement rollback code instead of just return.


> +
> +               list_del(&info->list);
> +               kfree(info);
> +       }
> +
> +       return 0;
> +}
> +
> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
> +{
> +       int result;
>
>         /*
>          * Ask the VM to offline this memory range.
>          * Note: Assume that this function returns zero on success
>          */

Write function comment instead of this silly comment.

> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
> -               if (info->enabled) {
> -                       result = remove_memory(info->start_addr, info->length);
> -                       if (result)
> -                               return result;
> -               }
> -               kfree(info);
> -       }
> +       result = acpi_memory_remove_memory(mem_device);
> +       if (result)
> +               return result;
>
>         /* Power-off and eject the device */
>         result = acpi_memory_powerdown_device(mem_device);

This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
to release callback, but don't explain why.





> @@ -473,12 +486,23 @@ static int acpi_memory_device_add(struct
>  static int acpi_memory_device_remove(struct acpi_device *device, int type)
>  {
>         struct acpi_memory_device *mem_device = NULL;
> -
> +       int result;
>
>         if (!device || !acpi_driver_data(device))
>                 return -EINVAL;
>
>         mem_device = acpi_driver_data(device);
> +
> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
> +               /*
> +                * offline and remove memory only when the memory device is
> +                * ejected.
> +                */

This comment explain nothing. A comment should describe _why_ should we do.
e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.


> +               result = acpi_memory_remove_memory(mem_device);
> +               if (result)
> +                       return result;
> +       }
> +
>         kfree(mem_device);
>
>         return 0;
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 8, 2012, 6:58 a.m. UTC | #2
At 10/05/2012 04:53 AM, KOSAKI Motohiro Wrote:
> On Wed, Oct 3, 2012 at 5:58 AM, Yasuaki Ishimatsu
> <isimatu.yasuaki@jp.fujitsu.com> wrote:
>> From: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
>>
>> The memory device can be removed by 2 ways:
>> 1. send eject request by SCI
>> 2. echo 1 >/sys/bus/pci/devices/PNP0C80:XX/eject
>>
>> In the 1st case, acpi_memory_disable_device() will be called.
>> In the 2nd case, acpi_memory_device_remove() will be called.
>> acpi_memory_device_remove() will also be called when we unbind the
>> memory device from the driver acpi_memhotplug.
>>
>> acpi_memory_disable_device() has already implemented a code which
>> offlines memory and releases acpi_memory_info struct . But
>> acpi_memory_device_remove() has not implemented it yet.
>>
>> So the patch implements acpi_memory_remove_memory() for offlining
>> memory and releasing acpi_memory_info struct. And it is used by both
>> acpi_memory_device_remove() and acpi_memory_disable_device().
>>
>> Additionally, if the type is ACPI_BUS_REMOVAL_EJECT in
>> acpi_memory_device_remove() , it means that the user wants to eject
>> the memory device. In this case, acpi_memory_device_remove() calls
>> acpi_memory_remove_memory().
>>
>> CC: David Rientjes <rientjes@google.com>
>> CC: Jiang Liu <liuj97@gmail.com>
>> CC: Len Brown <len.brown@intel.com>
>> CC: Christoph Lameter <cl@linux.com>
>> Cc: Minchan Kim <minchan.kim@gmail.com>
>> CC: Andrew Morton <akpm@linux-foundation.org>
>> CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>> Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>> ---
>>  drivers/acpi/acpi_memhotplug.c |   44 +++++++++++++++++++++++++++++++----------
>>  1 file changed, 34 insertions(+), 10 deletions(-)
>>
>> Index: linux-3.6/drivers/acpi/acpi_memhotplug.c
>> ===================================================================
>> --- linux-3.6.orig/drivers/acpi/acpi_memhotplug.c       2012-10-03 18:55:33.386378909 +0900
>> +++ linux-3.6/drivers/acpi/acpi_memhotplug.c    2012-10-03 18:55:58.624380688 +0900
>> @@ -306,24 +306,37 @@ static int acpi_memory_powerdown_device(
>>         return 0;
>>  }
>>
>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>  {
>>         int result;
>>         struct acpi_memory_info *info, *n;
>>
>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
> 
> Which lock protect this loop?

There is no any lock to protect it now...

> 
> 
>> +               if (!info->enabled)
>> +                       return -EBUSY;
>> +
>> +               result = remove_memory(info->start_addr, info->length);
>> +               if (result)
>> +                       return result;
> 
> I suspect you need to implement rollback code instead of just return.
> 
> 
>> +
>> +               list_del(&info->list);
>> +               kfree(info);
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>> +{
>> +       int result;
>>
>>         /*
>>          * Ask the VM to offline this memory range.
>>          * Note: Assume that this function returns zero on success
>>          */
> 
> Write function comment instead of this silly comment.
> 
>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>> -               if (info->enabled) {
>> -                       result = remove_memory(info->start_addr, info->length);
>> -                       if (result)
>> -                               return result;
>> -               }
>> -               kfree(info);
>> -       }
>> +       result = acpi_memory_remove_memory(mem_device);
>> +       if (result)
>> +               return result;
>>
>>         /* Power-off and eject the device */
>>         result = acpi_memory_powerdown_device(mem_device);
> 
> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
> to release callback, but don't explain why.

Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().

> 
> 
> 
> 
> 
>> @@ -473,12 +486,23 @@ static int acpi_memory_device_add(struct
>>  static int acpi_memory_device_remove(struct acpi_device *device, int type)
>>  {
>>         struct acpi_memory_device *mem_device = NULL;
>> -
>> +       int result;
>>
>>         if (!device || !acpi_driver_data(device))
>>                 return -EINVAL;
>>
>>         mem_device = acpi_driver_data(device);
>> +
>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>> +               /*
>> +                * offline and remove memory only when the memory device is
>> +                * ejected.
>> +                */
> 
> This comment explain nothing. A comment should describe _why_ should we do.
> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.

Hmm, we have 2 ways to remove a memory:
1. SCI
2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject

In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
the memory and remove it from kernel in the release callback. We will poweroff
the memory device in acpi_bus_hot_remove_device(), so we must offline
and remove it if the type is ACPI_BUS_REMOVAL_EJECT.

I guess we should not poweroff the memory device when we fail to offline it.
But device_release_driver() doesn't returns any error...

Thanks
Wen Congyang

> 
> 
>> +               result = acpi_memory_remove_memory(mem_device);
>> +               if (result)
>> +                       return result;
>> +       }
>> +
>>         kfree(mem_device);
>>
>>         return 0;
>>
>> --
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>> the body to majordomo@kvack.org.  For more info on Linux MM,
>> see: http://www.linux-mm.org/ .
>> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 12, 2012, 7:10 p.m. UTC | #3
>>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>>  {
>>>         int result;
>>>         struct acpi_memory_info *info, *n;
>>>
>>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>
>> Which lock protect this loop?
>
> There is no any lock to protect it now...

When iterate an item removal list, you should use lock for protecting from
memory corruption.




>>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>> +{
>>> +       int result;
>>>
>>>         /*
>>>          * Ask the VM to offline this memory range.
>>>          * Note: Assume that this function returns zero on success
>>>          */
>>
>> Write function comment instead of this silly comment.
>>
>>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>> -               if (info->enabled) {
>>> -                       result = remove_memory(info->start_addr, info->length);
>>> -                       if (result)
>>> -                               return result;
>>> -               }
>>> -               kfree(info);
>>> -       }
>>> +       result = acpi_memory_remove_memory(mem_device);
>>> +       if (result)
>>> +               return result;
>>>
>>>         /* Power-off and eject the device */
>>>         result = acpi_memory_powerdown_device(mem_device);
>>
>> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
>> to release callback, but don't explain why.
>
> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().

Even if reuse or not reuse, you changed the behavior. If any changes
has no good rational, you cannot get an ack.




>>> @@ -473,12 +486,23 @@ static int acpi_memory_device_add(struct
>>>  static int acpi_memory_device_remove(struct acpi_device *device, int type)
>>>  {
>>>         struct acpi_memory_device *mem_device = NULL;
>>> -
>>> +       int result;
>>>
>>>         if (!device || !acpi_driver_data(device))
>>>                 return -EINVAL;
>>>
>>>         mem_device = acpi_driver_data(device);
>>> +
>>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>>> +               /*
>>> +                * offline and remove memory only when the memory device is
>>> +                * ejected.
>>> +                */
>>
>> This comment explain nothing. A comment should describe _why_ should we do.
>> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
>> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.
>
> Hmm, we have 2 ways to remove a memory:
> 1. SCI
> 2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
>
> In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
> the memory and remove it from kernel in the release callback. We will poweroff
> the memory device in acpi_bus_hot_remove_device(), so we must offline
> and remove it if the type is ACPI_BUS_REMOVAL_EJECT.
>
> I guess we should not poweroff the memory device when we fail to offline it.
> But device_release_driver() doesn't returns any error...

1) I think /sys/bus/acpi/devices/PNP0C80:XX/eject should emulate acpi
eject. Can't
you make a pseudo acpi eject event and detach device by acpi regular path?

2) Your explanation didn't explain why we should ignore REMOVAL_NORMAL
and REMOVEL_EJECT. As far as reviewers can't track your intention, we
can't maintain
the code and can't ack them.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 17, 2012, 6:48 a.m. UTC | #4
At 10/13/2012 03:10 AM, KOSAKI Motohiro Wrote:
>>>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>>>  {
>>>>         int result;
>>>>         struct acpi_memory_info *info, *n;
>>>>
>>>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>
>>> Which lock protect this loop?
>>
>> There is no any lock to protect it now...
> 
> When iterate an item removal list, you should use lock for protecting from
> memory corruption.
> 
> 
> 
> 
>>>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>> +{
>>>> +       int result;
>>>>
>>>>         /*
>>>>          * Ask the VM to offline this memory range.
>>>>          * Note: Assume that this function returns zero on success
>>>>          */
>>>
>>> Write function comment instead of this silly comment.
>>>
>>>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>> -               if (info->enabled) {
>>>> -                       result = remove_memory(info->start_addr, info->length);
>>>> -                       if (result)
>>>> -                               return result;
>>>> -               }
>>>> -               kfree(info);
>>>> -       }
>>>> +       result = acpi_memory_remove_memory(mem_device);
>>>> +       if (result)
>>>> +               return result;
>>>>
>>>>         /* Power-off and eject the device */
>>>>         result = acpi_memory_powerdown_device(mem_device);
>>>
>>> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
>>> to release callback, but don't explain why.
>>
>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
> 
> Even if reuse or not reuse, you changed the behavior. If any changes
> has no good rational, you cannot get an ack.

I don't understand this? IIRC, the behavior isn't changed.

Thanks
Wen Congyang

> 
> 
> 
> 
>>>> @@ -473,12 +486,23 @@ static int acpi_memory_device_add(struct
>>>>  static int acpi_memory_device_remove(struct acpi_device *device, int type)
>>>>  {
>>>>         struct acpi_memory_device *mem_device = NULL;
>>>> -
>>>> +       int result;
>>>>
>>>>         if (!device || !acpi_driver_data(device))
>>>>                 return -EINVAL;
>>>>
>>>>         mem_device = acpi_driver_data(device);
>>>> +
>>>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>>>> +               /*
>>>> +                * offline and remove memory only when the memory device is
>>>> +                * ejected.
>>>> +                */
>>>
>>> This comment explain nothing. A comment should describe _why_ should we do.
>>> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
>>> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.
>>
>> Hmm, we have 2 ways to remove a memory:
>> 1. SCI
>> 2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
>>
>> In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
>> the memory and remove it from kernel in the release callback. We will poweroff
>> the memory device in acpi_bus_hot_remove_device(), so we must offline
>> and remove it if the type is ACPI_BUS_REMOVAL_EJECT.
>>
>> I guess we should not poweroff the memory device when we fail to offline it.
>> But device_release_driver() doesn't returns any error...
> 
> 1) I think /sys/bus/acpi/devices/PNP0C80:XX/eject should emulate acpi
> eject. Can't
> you make a pseudo acpi eject event and detach device by acpi regular path?
> 
> 2) Your explanation didn't explain why we should ignore REMOVAL_NORMAL
> and REMOVEL_EJECT. As far as reviewers can't track your intention, we
> can't maintain
> the code and can't ack them.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 17, 2012, 8:59 a.m. UTC | #5
On Wed, Oct 17, 2012 at 2:48 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
> At 10/13/2012 03:10 AM, KOSAKI Motohiro Wrote:
>>>>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>>>>  {
>>>>>         int result;
>>>>>         struct acpi_memory_info *info, *n;
>>>>>
>>>>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>>
>>>> Which lock protect this loop?
>>>
>>> There is no any lock to protect it now...
>>
>> When iterate an item removal list, you should use lock for protecting from
>> memory corruption.
>>
>>
>>
>>
>>>>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>>> +{
>>>>> +       int result;
>>>>>
>>>>>         /*
>>>>>          * Ask the VM to offline this memory range.
>>>>>          * Note: Assume that this function returns zero on success
>>>>>          */
>>>>
>>>> Write function comment instead of this silly comment.
>>>>
>>>>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>>> -               if (info->enabled) {
>>>>> -                       result = remove_memory(info->start_addr, info->length);
>>>>> -                       if (result)
>>>>> -                               return result;
>>>>> -               }
>>>>> -               kfree(info);
>>>>> -       }
>>>>> +       result = acpi_memory_remove_memory(mem_device);
>>>>> +       if (result)
>>>>> +               return result;
>>>>>
>>>>>         /* Power-off and eject the device */
>>>>>         result = acpi_memory_powerdown_device(mem_device);
>>>>
>>>> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
>>>> to release callback, but don't explain why.
>>>
>>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
>>
>> Even if reuse or not reuse, you changed the behavior. If any changes
>> has no good rational, you cannot get an ack.
>
> I don't understand this? IIRC, the behavior isn't changed.

Heh, please explain why do you think so.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 17, 2012, 9:08 a.m. UTC | #6
At 10/17/2012 04:59 PM, KOSAKI Motohiro Wrote:
> On Wed, Oct 17, 2012 at 2:48 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
>> At 10/13/2012 03:10 AM, KOSAKI Motohiro Wrote:
>>>>>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>>>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>>>>>  {
>>>>>>         int result;
>>>>>>         struct acpi_memory_info *info, *n;
>>>>>>
>>>>>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>>>
>>>>> Which lock protect this loop?
>>>>
>>>> There is no any lock to protect it now...
>>>
>>> When iterate an item removal list, you should use lock for protecting from
>>> memory corruption.
>>>
>>>
>>>
>>>
>>>>>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>>>> +{
>>>>>> +       int result;
>>>>>>
>>>>>>         /*
>>>>>>          * Ask the VM to offline this memory range.
>>>>>>          * Note: Assume that this function returns zero on success
>>>>>>          */
>>>>>
>>>>> Write function comment instead of this silly comment.
>>>>>
>>>>>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>>>> -               if (info->enabled) {
>>>>>> -                       result = remove_memory(info->start_addr, info->length);
>>>>>> -                       if (result)
>>>>>> -                               return result;
>>>>>> -               }
>>>>>> -               kfree(info);
>>>>>> -       }
>>>>>> +       result = acpi_memory_remove_memory(mem_device);
>>>>>> +       if (result)
>>>>>> +               return result;
>>>>>>
>>>>>>         /* Power-off and eject the device */
>>>>>>         result = acpi_memory_powerdown_device(mem_device);
>>>>>
>>>>> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
>>>>> to release callback, but don't explain why.
>>>>
>>>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
>>>
>>> Even if reuse or not reuse, you changed the behavior. If any changes
>>> has no good rational, you cannot get an ack.
>>
>> I don't understand this? IIRC, the behavior isn't changed.
> 
> Heh, please explain why do you think so.
> 


We just introduce a function, and move codes from acpi_memory_disable_device() to the new
function. We call the new function in acpi_memory_disable_device(), so the function
acpi_memory_disable_device()'s behavior isn't changed.

Maybe I don't understand what do you want to say.

Thanks
Wen Congyang
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 17, 2012, 9:18 a.m. UTC | #7
At 10/13/2012 03:10 AM, KOSAKI Motohiro Wrote:
>>>> -static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>> +static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
>>>>  {
>>>>         int result;
>>>>         struct acpi_memory_info *info, *n;
>>>>
>>>> +       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>
>>> Which lock protect this loop?
>>
>> There is no any lock to protect it now...
> 
> When iterate an item removal list, you should use lock for protecting from
> memory corruption.
> 
> 
> 
> 
>>>> +static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
>>>> +{
>>>> +       int result;
>>>>
>>>>         /*
>>>>          * Ask the VM to offline this memory range.
>>>>          * Note: Assume that this function returns zero on success
>>>>          */
>>>
>>> Write function comment instead of this silly comment.
>>>
>>>> -       list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
>>>> -               if (info->enabled) {
>>>> -                       result = remove_memory(info->start_addr, info->length);
>>>> -                       if (result)
>>>> -                               return result;
>>>> -               }
>>>> -               kfree(info);
>>>> -       }
>>>> +       result = acpi_memory_remove_memory(mem_device);
>>>> +       if (result)
>>>> +               return result;
>>>>
>>>>         /* Power-off and eject the device */
>>>>         result = acpi_memory_powerdown_device(mem_device);
>>>
>>> This patch move acpi_memory_powerdown_device() from ACPI_NOTIFY_EJECT_REQUEST
>>> to release callback, but don't explain why.
>>
>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
> 
> Even if reuse or not reuse, you changed the behavior. If any changes
> has no good rational, you cannot get an ack.
> 
> 
> 
> 
>>>> @@ -473,12 +486,23 @@ static int acpi_memory_device_add(struct
>>>>  static int acpi_memory_device_remove(struct acpi_device *device, int type)
>>>>  {
>>>>         struct acpi_memory_device *mem_device = NULL;
>>>> -
>>>> +       int result;
>>>>
>>>>         if (!device || !acpi_driver_data(device))
>>>>                 return -EINVAL;
>>>>
>>>>         mem_device = acpi_driver_data(device);
>>>> +
>>>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>>>> +               /*
>>>> +                * offline and remove memory only when the memory device is
>>>> +                * ejected.
>>>> +                */
>>>
>>> This comment explain nothing. A comment should describe _why_ should we do.
>>> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
>>> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.
>>
>> Hmm, we have 2 ways to remove a memory:
>> 1. SCI
>> 2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
>>
>> In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
>> the memory and remove it from kernel in the release callback. We will poweroff
>> the memory device in acpi_bus_hot_remove_device(), so we must offline
>> and remove it if the type is ACPI_BUS_REMOVAL_EJECT.
>>
>> I guess we should not poweroff the memory device when we fail to offline it.
>> But device_release_driver() doesn't returns any error...
> 
> 1) I think /sys/bus/acpi/devices/PNP0C80:XX/eject should emulate acpi
> eject. Can't
> you make a pseudo acpi eject event and detach device by acpi regular path?

It is another issue. And we only can implement it here with current acpi
implemention. Some other acpi devices(for example: cpu) do it like this.

> 
> 2) Your explanation didn't explain why we should ignore REMOVAL_NORMAL
> and REMOVEL_EJECT. As far as reviewers can't track your intention, we
> can't maintain
> the code and can't ack them.
> 

REMOVAL_NORMAL means the user want to unbind the memory device from this driver.
It is no need to eject the device, and we can still use this device after unbinding.
So it can be ignored.

REMOVAL_EJECT means the user want to eject and remove the device, and we should
not use the device. So we should offline and remove the memory here.

Thanks
Wen Congyang
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 17, 2012, 9:18 a.m. UTC | #8
>>>>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
>>>>
>>>> Even if reuse or not reuse, you changed the behavior. If any changes
>>>> has no good rational, you cannot get an ack.
>>>
>>> I don't understand this? IIRC, the behavior isn't changed.
>>
>> Heh, please explain why do you think so.
>
> We just introduce a function, and move codes from acpi_memory_disable_device() to the new
> function. We call the new function in acpi_memory_disable_device(), so the function
> acpi_memory_disable_device()'s behavior isn't changed.
>
> Maybe I don't understand what do you want to say.

Ok, now you agreed you moved the code, yes? So then, you should explain why
your code moving makes zero impact other acpi_memory_disable_device() caller.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 17, 2012, 9:52 a.m. UTC | #9
At 10/17/2012 05:18 PM, KOSAKI Motohiro Wrote:
>>>>>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
>>>>>
>>>>> Even if reuse or not reuse, you changed the behavior. If any changes
>>>>> has no good rational, you cannot get an ack.
>>>>
>>>> I don't understand this? IIRC, the behavior isn't changed.
>>>
>>> Heh, please explain why do you think so.
>>
>> We just introduce a function, and move codes from acpi_memory_disable_device() to the new
>> function. We call the new function in acpi_memory_disable_device(), so the function
>> acpi_memory_disable_device()'s behavior isn't changed.
>>
>> Maybe I don't understand what do you want to say.
> 
> Ok, now you agreed you moved the code, yes? So then, you should explain why
> your code moving makes zero impact other acpi_memory_disable_device() caller.

We just move the code, and don't change the acpi_memory_disable_device()'s behavior.

I look it the change again, and found some diffs:
1. we treat !info->enabled as error, while it isn't a error without this patch
2. we remove memory info from the list, it is a bug fix because we free the memory
   that stores memory info.(I have sent a patch to fix this bug, and it is in akpm's tree now)

I guess you mean 1 will change the behavior. In the last version, I don't do it.
Ishimatsu changes this and I don't notify this.

To Ishimatsu:

Why do you change this?

Thanks
Wen Congyang

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yasuaki Ishimatsu Oct. 18, 2012, 1:25 a.m. UTC | #10
Hi Wen,

2012/10/17 18:52, Wen Congyang wrote:
> At 10/17/2012 05:18 PM, KOSAKI Motohiro Wrote:
>>>>>>> Hmm, it doesn't move the code. It just reuse the code in acpi_memory_powerdown_device().
>>>>>>
>>>>>> Even if reuse or not reuse, you changed the behavior. If any changes
>>>>>> has no good rational, you cannot get an ack.
>>>>>
>>>>> I don't understand this? IIRC, the behavior isn't changed.
>>>>
>>>> Heh, please explain why do you think so.
>>>
>>> We just introduce a function, and move codes from acpi_memory_disable_device() to the new
>>> function. We call the new function in acpi_memory_disable_device(), so the function
>>> acpi_memory_disable_device()'s behavior isn't changed.
>>>
>>> Maybe I don't understand what do you want to say.
>>
>> Ok, now you agreed you moved the code, yes? So then, you should explain why
>> your code moving makes zero impact other acpi_memory_disable_device() caller.
>
> We just move the code, and don't change the acpi_memory_disable_device()'s behavior.
>
> I look it the change again, and found some diffs:
> 1. we treat !info->enabled as error, while it isn't a error without this patch
> 2. we remove memory info from the list, it is a bug fix because we free the memory
>     that stores memory info.(I have sent a patch to fix this bug, and it is in akpm's tree now)
>
> I guess you mean 1 will change the behavior. In the last version, I don't do it.
> Ishimatsu changes this and I don't notify this.
>
> To Ishimatsu:
>
> Why do you change this?

Oops. If so, it's my mistake.
Could you update it in next version?

Thanks,
Yasuaki Ishimatsu

>
> Thanks
> Wen Congyang
>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 18, 2012, 7:44 p.m. UTC | #11
>>>>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>>>>> +               /*
>>>>> +                * offline and remove memory only when the memory device is
>>>>> +                * ejected.
>>>>> +                */
>>>>
>>>> This comment explain nothing. A comment should describe _why_ should we do.
>>>> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
>>>> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.
>>>
>>> Hmm, we have 2 ways to remove a memory:
>>> 1. SCI
>>> 2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
>>>
>>> In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
>>> the memory and remove it from kernel in the release callback. We will poweroff
>>> the memory device in acpi_bus_hot_remove_device(), so we must offline
>>> and remove it if the type is ACPI_BUS_REMOVAL_EJECT.
>>>
>>> I guess we should not poweroff the memory device when we fail to offline it.
>>> But device_release_driver() doesn't returns any error...
>>
>> 1) I think /sys/bus/acpi/devices/PNP0C80:XX/eject should emulate acpi
>> eject. Can't
>> you make a pseudo acpi eject event and detach device by acpi regular path?
>
> It is another issue. And we only can implement it here with current acpi
> implemention. Some other acpi devices(for example: cpu) do it like this.

Hint: only cpu take like this.


>> 2) Your explanation didn't explain why we should ignore REMOVAL_NORMAL
>> and REMOVEL_EJECT. As far as reviewers can't track your intention, we
>> can't maintain
>> the code and can't ack them.
>>
>
> REMOVAL_NORMAL means the user want to unbind the memory device from this driver.
> It is no need to eject the device, and we can still use this device after unbinding.
> So it can be ignored.
>
> REMOVAL_EJECT means the user want to eject and remove the device, and we should
> not use the device. So we should offline and remove the memory here.

This is not exactly correct, IMHO. Usually, we must not touch unbinded
device because
they are out of OS control. If I understand is correct, the main
reason is to distinguish a
rollback of driver initialization failure and true ejection.

REMOVAL_NORMAL is usually used for rollback and REMOVAL_EJECT is used for
removal device eject. Typical device don't need to distinguish them
because we should
deallocate every resource even when driver initialization failure.

However, cpu and memory are exceptions. They are recognized from kernel before
driver initialization. Then even if machine have crappy acpi table and
make failure acpi
initialization, disabling memory make no sense.

And, when you make _exceptional_ rule, you should comment verbosely in the code
the detail.  likes 1) why we need.  2) which
device/machine/environment suffer such exception. 2)  what affect
other subsys.

Even though cpu hotplug has crappy poor comment and document, please
don't follow
them.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 19, 2012, 7:35 a.m. UTC | #12
At 10/18/2012 09:25 AM, Yasuaki Ishimatsu Wrote:
> Hi Wen,
> 
> 2012/10/17 18:52, Wen Congyang wrote:
>> At 10/17/2012 05:18 PM, KOSAKI Motohiro Wrote:
>>>>>>>> Hmm, it doesn't move the code. It just reuse the code in
>>>>>>>> acpi_memory_powerdown_device().
>>>>>>>
>>>>>>> Even if reuse or not reuse, you changed the behavior. If any changes
>>>>>>> has no good rational, you cannot get an ack.
>>>>>>
>>>>>> I don't understand this? IIRC, the behavior isn't changed.
>>>>>
>>>>> Heh, please explain why do you think so.
>>>>
>>>> We just introduce a function, and move codes from
>>>> acpi_memory_disable_device() to the new
>>>> function. We call the new function in acpi_memory_disable_device(),
>>>> so the function
>>>> acpi_memory_disable_device()'s behavior isn't changed.
>>>>
>>>> Maybe I don't understand what do you want to say.
>>>
>>> Ok, now you agreed you moved the code, yes? So then, you should
>>> explain why
>>> your code moving makes zero impact other acpi_memory_disable_device()
>>> caller.
>>
>> We just move the code, and don't change the
>> acpi_memory_disable_device()'s behavior.
>>
>> I look it the change again, and found some diffs:
>> 1. we treat !info->enabled as error, while it isn't a error without
>> this patch
>> 2. we remove memory info from the list, it is a bug fix because we
>> free the memory
>>     that stores memory info.(I have sent a patch to fix this bug, and
>> it is in akpm's tree now)
>>
>> I guess you mean 1 will change the behavior. In the last version, I
>> don't do it.
>> Ishimatsu changes this and I don't notify this.
>>
>> To Ishimatsu:
>>
>> Why do you change this?
> 
> Oops. If so, it's my mistake.
> Could you update it in next version?

OK

Thanks
Wen Congyang

> 
> Thanks,
> Yasuaki Ishimatsu
> 
>>
>> Thanks
>> Wen Congyang
>>
>>> -- 
>>> To unsubscribe from this list: send the line "unsubscribe
>>> linux-kernel" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at  http://www.tux.org/lkml/
>>>
>>
>> -- 
>> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> 
> 
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 19, 2012, 9:08 a.m. UTC | #13
At 10/19/2012 03:44 AM, KOSAKI Motohiro Wrote:
>>>>>> +       if (type == ACPI_BUS_REMOVAL_EJECT) {
>>>>>> +               /*
>>>>>> +                * offline and remove memory only when the memory device is
>>>>>> +                * ejected.
>>>>>> +                */
>>>>>
>>>>> This comment explain nothing. A comment should describe _why_ should we do.
>>>>> e.g. Why REMOVAL_NORMAL and REMOVEL_EJECT should be ignored. Why
>>>>> we need remove memory here instead of ACPI_NOTIFY_EJECT_REQUEST.
>>>>
>>>> Hmm, we have 2 ways to remove a memory:
>>>> 1. SCI
>>>> 2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
>>>>
>>>> In the 2nd case, there is no ACPI_NOTIFY_EJECT_REQUEST. We should offline
>>>> the memory and remove it from kernel in the release callback. We will poweroff
>>>> the memory device in acpi_bus_hot_remove_device(), so we must offline
>>>> and remove it if the type is ACPI_BUS_REMOVAL_EJECT.
>>>>
>>>> I guess we should not poweroff the memory device when we fail to offline it.
>>>> But device_release_driver() doesn't returns any error...
>>>
>>> 1) I think /sys/bus/acpi/devices/PNP0C80:XX/eject should emulate acpi
>>> eject. Can't
>>> you make a pseudo acpi eject event and detach device by acpi regular path?
>>
>> It is another issue. And we only can implement it here with current acpi
>> implemention. Some other acpi devices(for example: cpu) do it like this.
> 
> Hint: only cpu take like this.
> 
> 
>>> 2) Your explanation didn't explain why we should ignore REMOVAL_NORMAL
>>> and REMOVEL_EJECT. As far as reviewers can't track your intention, we
>>> can't maintain
>>> the code and can't ack them.
>>>
>>
>> REMOVAL_NORMAL means the user want to unbind the memory device from this driver.
>> It is no need to eject the device, and we can still use this device after unbinding.
>> So it can be ignored.
>>
>> REMOVAL_EJECT means the user want to eject and remove the device, and we should
>> not use the device. So we should offline and remove the memory here.
> 
> This is not exactly correct, IMHO. Usually, we must not touch unbinded
> device because
> they are out of OS control. If I understand is correct, the main
> reason is to distinguish a
> rollback of driver initialization failure and true ejection.
> 
> REMOVAL_NORMAL is usually used for rollback and REMOVAL_EJECT is used for
> removal device eject. Typical device don't need to distinguish them
> because we should
> deallocate every resource even when driver initialization failure.
> 
> However, cpu and memory are exceptions. They are recognized from kernel before
> driver initialization. Then even if machine have crappy acpi table and
> make failure acpi
> initialization, disabling memory make no sense.

Hmm, IIRC, if the memory is recognized from kerenl before driver initialization,
the memory device is not managed by the driver acpi_memhotplug.

I think we should also deal with REMOVAL_NORMAL here now. Otherwise it will cause
some critical problem: we unbind the device from the driver but we still use
it. If we eject it, we have no chance to offline and remove it. It is very dangerous.

Thanks
Wen Congyang

> 
> And, when you make _exceptional_ rule, you should comment verbosely in the code
> the detail.  likes 1) why we need.  2) which
> device/machine/environment suffer such exception. 2)  what affect
> other subsys.
> 
> Even though cpu hotplug has crappy poor comment and document, please
> don't follow
> them.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 19, 2012, 6:19 p.m. UTC | #14
> Hmm, IIRC, if the memory is recognized from kerenl before driver initialization,
> the memory device is not managed by the driver acpi_memhotplug.

Yup.


> I think we should also deal with REMOVAL_NORMAL here now. Otherwise it will cause
> some critical problem: we unbind the device from the driver but we still use
> it. If we eject it, we have no chance to offline and remove it. It is very dangerous.

??
If resource was not allocated a driver, a driver doesn't need to
deallocate it when
error path. I haven't caught your point.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wen Congyang Oct. 20, 2012, 5:02 a.m. UTC | #15
At 10/20/2012 02:19 AM, KOSAKI Motohiro Wrote:
>> Hmm, IIRC, if the memory is recognized from kerenl before driver initialization,
>> the memory device is not managed by the driver acpi_memhotplug.
> 
> Yup.
> 
> 
>> I think we should also deal with REMOVAL_NORMAL here now. Otherwise it will cause
>> some critical problem: we unbind the device from the driver but we still use
>> it. If we eject it, we have no chance to offline and remove it. It is very dangerous.
> 
> ??
> If resource was not allocated a driver, a driver doesn't need to
> deallocate it when
> error path. I haven't caught your point.
> 

REMOVAL_NORMAL can be in 2 cases:
1. error path. If init call fails, we don't call it. We call this function
   only when something fails after init.

2. unbind the device from the driver.
   If we don't offline and remove memory when unbinding the device from the driver,
   the device may be out of control. When we eject this driver, we don't offline and
   remove it, but we will eject and poweroff the device. It is very dangerous because
   the kernel uses the memory but we poweroff it.

   acpi_bus_hot_remove_device()
       acpi_bus_trim() // this function successes because the device has no driver
       _PS3 // poweroff
       _EJ0 // eject

Thanks
Wen Congyang
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 22, 2012, 3:11 p.m. UTC | #16
>> ??
>> If resource was not allocated a driver, a driver doesn't need to
>> deallocate it when
>> error path. I haven't caught your point.
>>
>
> REMOVAL_NORMAL can be in 2 cases:
> 1. error path. If init call fails, we don't call it. We call this function
>    only when something fails after init.
> 2. unbind the device from the driver.
>    If we don't offline and remove memory when unbinding the device from the driver,
>    the device may be out of control. When we eject this driver, we don't offline and

Memory never be out of control by driver unloading. It is controled
from kernel core. It is an exception from regular linux driver model.


>    remove it, but we will eject and poweroff the device. It is very dangerous because
>    the kernel uses the memory but we poweroff it.
>
>    acpi_bus_hot_remove_device()
>        acpi_bus_trim() // this function successes because the device has no driver
>        _PS3 // poweroff
>        _EJ0 // eject
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Motohiro KOSAKI Oct. 22, 2012, 3:34 p.m. UTC | #17
On Mon, Oct 22, 2012 at 11:11 AM, KOSAKI Motohiro
<kosaki.motohiro@jp.fujitsu.com> wrote:
>>> ??
>>> If resource was not allocated a driver, a driver doesn't need to
>>> deallocate it when
>>> error path. I haven't caught your point.
>>>
>>
>> REMOVAL_NORMAL can be in 2 cases:
>> 1. error path. If init call fails, we don't call it. We call this function
>>    only when something fails after init.
>> 2. unbind the device from the driver.
>>    If we don't offline and remove memory when unbinding the device from the driver,
>>    the device may be out of control. When we eject this driver, we don't offline and
>
> Memory never be out of control by driver unloading. It is controled
> from kernel core. It is an exception from regular linux driver model.

Ah, got it.
acpi_bus_hot_remove_device() evaluate PS3 before EJ0. Then
your first patch may cause memory lost.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: linux-3.6/drivers/acpi/acpi_memhotplug.c
===================================================================
--- linux-3.6.orig/drivers/acpi/acpi_memhotplug.c	2012-10-03 18:55:33.386378909 +0900
+++ linux-3.6/drivers/acpi/acpi_memhotplug.c	2012-10-03 18:55:58.624380688 +0900
@@ -306,24 +306,37 @@  static int acpi_memory_powerdown_device(
 	return 0;
 }
 
-static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
+static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
 {
 	int result;
 	struct acpi_memory_info *info, *n;
 
+	list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
+		if (!info->enabled)
+			return -EBUSY;
+
+		result = remove_memory(info->start_addr, info->length);
+		if (result)
+			return result;
+
+		list_del(&info->list);
+		kfree(info);
+	}
+
+	return 0;
+}
+
+static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
+{
+	int result;
 
 	/*
 	 * Ask the VM to offline this memory range.
 	 * Note: Assume that this function returns zero on success
 	 */
-	list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
-		if (info->enabled) {
-			result = remove_memory(info->start_addr, info->length);
-			if (result)
-				return result;
-		}
-		kfree(info);
-	}
+	result = acpi_memory_remove_memory(mem_device);
+	if (result)
+		return result;
 
 	/* Power-off and eject the device */
 	result = acpi_memory_powerdown_device(mem_device);
@@ -473,12 +486,23 @@  static int acpi_memory_device_add(struct
 static int acpi_memory_device_remove(struct acpi_device *device, int type)
 {
 	struct acpi_memory_device *mem_device = NULL;
-
+	int result;
 
 	if (!device || !acpi_driver_data(device))
 		return -EINVAL;
 
 	mem_device = acpi_driver_data(device);
+
+	if (type == ACPI_BUS_REMOVAL_EJECT) {
+		/*
+		 * offline and remove memory only when the memory device is
+		 * ejected.
+		 */
+		result = acpi_memory_remove_memory(mem_device);
+		if (result)
+			return result;
+	}
+
 	kfree(mem_device);
 
 	return 0;