LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/2] kasan: fix memory notifier handling
@ 2018-05-22 10:07 David Hildenbrand
  2018-05-22 10:07 ` [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE David Hildenbrand
  2018-05-22 10:07 ` [PATCH v2 2/2] kasan: fix memory hotplug during boot David Hildenbrand
  0 siblings, 2 replies; 10+ messages in thread
From: David Hildenbrand @ 2018-05-22 10:07 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel, David Hildenbrand

If onlining of pages fails (is canceled), we don't properly free up memory.
Also, the memory hotplug notifier is not registered early enough, still
failing on certain setups where memory is detected, added and onlined
early.

v1 -> v2:
- s/MEM_CANCEL_OFFLINE/MEM_CANCEL_ONLINE

David Hildenbrand (2):
  kasan: free allocated shadow memory on MEM_CANCEL_ONLINE
  kasan: fix memory hotplug during boot

 mm/kasan/kasan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE
  2018-05-22 10:07 [PATCH v2 0/2] kasan: fix memory notifier handling David Hildenbrand
@ 2018-05-22 10:07 ` David Hildenbrand
  2018-05-22 16:26   ` Andrey Ryabinin
  2018-05-22 10:07 ` [PATCH v2 2/2] kasan: fix memory hotplug during boot David Hildenbrand
  1 sibling, 1 reply; 10+ messages in thread
From: David Hildenbrand @ 2018-05-22 10:07 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, David Hildenbrand, Andrey Ryabinin,
	Alexander Potapenko, Dmitry Vyukov, open list:KASAN

We have to free memory again when we cancel onlining, otherwise a later
onlining attempt will fail.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 mm/kasan/kasan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index 135ce2838c89..53564229674b 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 		kmemleak_ignore(ret);
 		return NOTIFY_OK;
 	}
+	case MEM_CANCEL_ONLINE:
 	case MEM_OFFLINE: {
 		struct vm_struct *vm;
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 10:07 [PATCH v2 0/2] kasan: fix memory notifier handling David Hildenbrand
  2018-05-22 10:07 ` [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE David Hildenbrand
@ 2018-05-22 10:07 ` David Hildenbrand
  2018-05-22 16:26   ` Andrey Ryabinin
  1 sibling, 1 reply; 10+ messages in thread
From: David Hildenbrand @ 2018-05-22 10:07 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, David Hildenbrand, Andrey Ryabinin,
	Alexander Potapenko, Dmitry Vyukov, open list:KASAN

Using module_init() is wrong. E.g. ACPI adds and onlines memory before
our memory notifier gets registered.

This makes sure that ACPI memory detected during boot up will not
result in a kernel crash.

Easily reproducable with QEMU, just specify a DIMM when starting up.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 mm/kasan/kasan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index 53564229674b..a8b85706e2d6 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -892,5 +892,5 @@ static int __init kasan_memhotplug_init(void)
 	return 0;
 }
 
-module_init(kasan_memhotplug_init);
+core_initcall(kasan_memhotplug_init);
 #endif
-- 
2.17.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE
  2018-05-22 10:07 ` [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE David Hildenbrand
@ 2018-05-22 16:26   ` Andrey Ryabinin
  0 siblings, 0 replies; 10+ messages in thread
From: Andrey Ryabinin @ 2018-05-22 16:26 UTC (permalink / raw)
  To: David Hildenbrand, linux-mm, Andrew Morton
  Cc: linux-kernel, Alexander Potapenko, Dmitry Vyukov, open list:KASAN



On 05/22/2018 01:07 PM, David Hildenbrand wrote:
> We have to free memory again when we cancel onlining, otherwise a later
> onlining attempt will fail.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---

Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: <stable@vger.kernel.org>

>  mm/kasan/kasan.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
> index 135ce2838c89..53564229674b 100644
> --- a/mm/kasan/kasan.c
> +++ b/mm/kasan/kasan.c
> @@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
>  		kmemleak_ignore(ret);
>  		return NOTIFY_OK;
>  	}
> +	case MEM_CANCEL_ONLINE:
>  	case MEM_OFFLINE: {
>  		struct vm_struct *vm;
>  
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 10:07 ` [PATCH v2 2/2] kasan: fix memory hotplug during boot David Hildenbrand
@ 2018-05-22 16:26   ` Andrey Ryabinin
  2018-05-22 16:36     ` David Hildenbrand
  0 siblings, 1 reply; 10+ messages in thread
From: Andrey Ryabinin @ 2018-05-22 16:26 UTC (permalink / raw)
  To: David Hildenbrand, linux-mm, Andrew Morton
  Cc: linux-kernel, Alexander Potapenko, Dmitry Vyukov, open list:KASAN



On 05/22/2018 01:07 PM, David Hildenbrand wrote:
> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
> our memory notifier gets registered.
> 
> This makes sure that ACPI memory detected during boot up will not
> result in a kernel crash.
> 
> Easily reproducable with QEMU, just specify a DIMM when starting up.

         reproducible
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---

Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: <stable@vger.kernel.org>

>  mm/kasan/kasan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
> index 53564229674b..a8b85706e2d6 100644
> --- a/mm/kasan/kasan.c
> +++ b/mm/kasan/kasan.c
> @@ -892,5 +892,5 @@ static int __init kasan_memhotplug_init(void)
>  	return 0;
>  }
>  
> -module_init(kasan_memhotplug_init);
> +core_initcall(kasan_memhotplug_init);
>  #endif
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 16:26   ` Andrey Ryabinin
@ 2018-05-22 16:36     ` David Hildenbrand
  2018-05-22 19:50       ` Andrey Ryabinin
  0 siblings, 1 reply; 10+ messages in thread
From: David Hildenbrand @ 2018-05-22 16:36 UTC (permalink / raw)
  To: Andrey Ryabinin, linux-mm, Andrew Morton
  Cc: linux-kernel, Alexander Potapenko, Dmitry Vyukov, open list:KASAN

On 22.05.2018 18:26, Andrey Ryabinin wrote:
> 
> 
> On 05/22/2018 01:07 PM, David Hildenbrand wrote:
>> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
>> our memory notifier gets registered.
>>
>> This makes sure that ACPI memory detected during boot up will not
>> result in a kernel crash.
>>
>> Easily reproducable with QEMU, just specify a DIMM when starting up.
> 
>          reproducible
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
> 
> Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: <stable@vger.kernel.org>

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")


> 
>>  mm/kasan/kasan.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
>> index 53564229674b..a8b85706e2d6 100644
>> --- a/mm/kasan/kasan.c
>> +++ b/mm/kasan/kasan.c
>> @@ -892,5 +892,5 @@ static int __init kasan_memhotplug_init(void)
>>  	return 0;
>>  }
>>  
>> -module_init(kasan_memhotplug_init);
>> +core_initcall(kasan_memhotplug_init);
>>  #endif
>>


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 16:36     ` David Hildenbrand
@ 2018-05-22 19:50       ` Andrey Ryabinin
  2018-05-22 21:07         ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Andrey Ryabinin @ 2018-05-22 19:50 UTC (permalink / raw)
  To: David Hildenbrand, linux-mm, Andrew Morton
  Cc: linux-kernel, Alexander Potapenko, Dmitry Vyukov, open list:KASAN



On 05/22/2018 07:36 PM, David Hildenbrand wrote:
> On 22.05.2018 18:26, Andrey Ryabinin wrote:
>>
>>
>> On 05/22/2018 01:07 PM, David Hildenbrand wrote:
>>> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
>>> our memory notifier gets registered.
>>>
>>> This makes sure that ACPI memory detected during boot up will not
>>> result in a kernel crash.
>>>
>>> Easily reproducable with QEMU, just specify a DIMM when starting up.
>>
>>          reproducible
>>>
>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>> ---
>>
>> Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
>> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> Cc: <stable@vger.kernel.org>
> 
> Think this even dates back to:
> 
> 786a8959912e ("kasan: disable memory hotplug")
> 

Indeed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 19:50       ` Andrey Ryabinin
@ 2018-05-22 21:07         ` Andrew Morton
  2018-05-23  9:59           ` Andrey Ryabinin
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2018-05-22 21:07 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: David Hildenbrand, linux-mm, linux-kernel, Alexander Potapenko,
	Dmitry Vyukov, open list:KASAN

On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:

> 
> 
> On 05/22/2018 07:36 PM, David Hildenbrand wrote:
> > On 22.05.2018 18:26, Andrey Ryabinin wrote:
> >>
> >>
> >> On 05/22/2018 01:07 PM, David Hildenbrand wrote:
> >>> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
> >>> our memory notifier gets registered.
> >>>
> >>> This makes sure that ACPI memory detected during boot up will not
> >>> result in a kernel crash.
> >>>
> >>> Easily reproducable with QEMU, just specify a DIMM when starting up.
> >>
> >>          reproducible
> >>>
> >>> Signed-off-by: David Hildenbrand <david@redhat.com>
> >>> ---
> >>
> >> Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
> >> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> >> Cc: <stable@vger.kernel.org>
> > 
> > Think this even dates back to:
> > 
> > 786a8959912e ("kasan: disable memory hotplug")
> > 
> 
> Indeed.

Is a backport to -stable justified for either of these patches?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-22 21:07         ` Andrew Morton
@ 2018-05-23  9:59           ` Andrey Ryabinin
  2018-05-23 11:52             ` David Hildenbrand
  0 siblings, 1 reply; 10+ messages in thread
From: Andrey Ryabinin @ 2018-05-23  9:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, linux-mm, linux-kernel, Alexander Potapenko,
	Dmitry Vyukov, open list:KASAN



On 05/23/2018 12:07 AM, Andrew Morton wrote:
> On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> 
>>
>>
>> On 05/22/2018 07:36 PM, David Hildenbrand wrote:
>>> On 22.05.2018 18:26, Andrey Ryabinin wrote:
>>>>
>>>>
>>>> On 05/22/2018 01:07 PM, David Hildenbrand wrote:
>>>>> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
>>>>> our memory notifier gets registered.
>>>>>
>>>>> This makes sure that ACPI memory detected during boot up will not
>>>>> result in a kernel crash.
>>>>>
>>>>> Easily reproducable with QEMU, just specify a DIMM when starting up.
>>>>
>>>>          reproducible
>>>>>
>>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>>> ---
>>>>
>>>> Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
>>>> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>>>> Cc: <stable@vger.kernel.org>
>>>
>>> Think this even dates back to:
>>>
>>> 786a8959912e ("kasan: disable memory hotplug")
>>>
>>
>> Indeed.
> 
> Is a backport to -stable justified for either of these patches?
> 

I don't see any reasons to not backport these.
The first one fixes failure to online memory, why it shouldn't be fixed in -stable?
The second one is fixes boot crash, it's definitely stable material IMO.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot
  2018-05-23  9:59           ` Andrey Ryabinin
@ 2018-05-23 11:52             ` David Hildenbrand
  0 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand @ 2018-05-23 11:52 UTC (permalink / raw)
  To: Andrey Ryabinin, Andrew Morton
  Cc: linux-mm, linux-kernel, Alexander Potapenko, Dmitry Vyukov,
	open list:KASAN

On 23.05.2018 11:59, Andrey Ryabinin wrote:
> 
> 
> On 05/23/2018 12:07 AM, Andrew Morton wrote:
>> On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
>>
>>>
>>>
>>> On 05/22/2018 07:36 PM, David Hildenbrand wrote:
>>>> On 22.05.2018 18:26, Andrey Ryabinin wrote:
>>>>>
>>>>>
>>>>> On 05/22/2018 01:07 PM, David Hildenbrand wrote:
>>>>>> Using module_init() is wrong. E.g. ACPI adds and onlines memory before
>>>>>> our memory notifier gets registered.
>>>>>>
>>>>>> This makes sure that ACPI memory detected during boot up will not
>>>>>> result in a kernel crash.
>>>>>>
>>>>>> Easily reproducable with QEMU, just specify a DIMM when starting up.
>>>>>
>>>>>          reproducible
>>>>>>
>>>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>>>> ---
>>>>>
>>>>> Fixes: fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
>>>>> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>>>>> Cc: <stable@vger.kernel.org>
>>>>
>>>> Think this even dates back to:
>>>>
>>>> 786a8959912e ("kasan: disable memory hotplug")
>>>>
>>>
>>> Indeed.
>>
>> Is a backport to -stable justified for either of these patches?
>>
> 
> I don't see any reasons to not backport these.
> The first one fixes failure to online memory, why it shouldn't be fixed in -stable?
> The second one is fixes boot crash, it's definitely stable material IMO.
> 

Agreed, at least the second one should be cc stable, as I can reproduce
it with a simple QEMU command.

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-05-23 11:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-22 10:07 [PATCH v2 0/2] kasan: fix memory notifier handling David Hildenbrand
2018-05-22 10:07 ` [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE David Hildenbrand
2018-05-22 16:26   ` Andrey Ryabinin
2018-05-22 10:07 ` [PATCH v2 2/2] kasan: fix memory hotplug during boot David Hildenbrand
2018-05-22 16:26   ` Andrey Ryabinin
2018-05-22 16:36     ` David Hildenbrand
2018-05-22 19:50       ` Andrey Ryabinin
2018-05-22 21:07         ` Andrew Morton
2018-05-23  9:59           ` Andrey Ryabinin
2018-05-23 11:52             ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).