All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86: fix small LDT allocation for Xen
@ 2015-09-02 12:46 Jan Beulich
  2015-09-02 14:08 ` Andy Lutomirski
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2015-09-02 12:46 UTC (permalink / raw)
  To: mingo, tglx, hpa
  Cc: David Vrabel, luto, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	linux-kernel

While commit 37868fe113 ("x86/ldt: Make modify_ldt synchronous") added
a nice comment explaining that Xen needs page-aligned whole page chunks
for guest descriptor tables, it then nevertheless used kzalloc() on the
small size path. As I'm unaware of guarantees for kmalloc(PAGE_SIZE, )
to return page-aligned memory blocks, I believe this needs to be
switched back to __get_free_page().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
v2: Also adjust the freeing side.
---
 arch/x86/kernel/ldt.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- 4.2/arch/x86/kernel/ldt.c
+++ 4.2-x86-LDT-alloc/arch/x86/kernel/ldt.c
@@ -58,7 +58,7 @@ static struct ldt_struct *alloc_ldt_stru
 	if (alloc_size > PAGE_SIZE)
 		new_ldt->entries = vzalloc(alloc_size);
 	else
-		new_ldt->entries = kzalloc(PAGE_SIZE, GFP_KERNEL);
+		new_ldt->entries = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
 
 	if (!new_ldt->entries) {
 		kfree(new_ldt);
@@ -95,7 +95,7 @@ static void free_ldt_struct(struct ldt_s
 	if (ldt->size * LDT_ENTRY_SIZE > PAGE_SIZE)
 		vfree(ldt->entries);
 	else
-		kfree(ldt->entries);
+		put_page(virt_to_page(ldt->entries));
 	kfree(ldt);
 }
 




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

* Re: [PATCH v2] x86: fix small LDT allocation for Xen
  2015-09-02 12:46 [PATCH v2] x86: fix small LDT allocation for Xen Jan Beulich
@ 2015-09-02 14:08 ` Andy Lutomirski
  2015-09-02 15:40   ` Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Lutomirski @ 2015-09-02 14:08 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Boris Ostrovsky, H. Peter Anvin, Konrad Rzeszutek Wilk,
	David Vrabel, linux-kernel@vger.kernel.org, Ingo Molnar,
	Thomas Gleixner

On Sep 2, 2015 5:46 AM, "Jan Beulich" <JBeulich@suse.com> wrote:
>
> While commit 37868fe113 ("x86/ldt: Make modify_ldt synchronous") added
> a nice comment explaining that Xen needs page-aligned whole page chunks
> for guest descriptor tables, it then nevertheless used kzalloc() on the
> small size path. As I'm unaware of guarantees for kmalloc(PAGE_SIZE, )
> to return page-aligned memory blocks, I believe this needs to be
> switched back to __get_free_page().
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
> v2: Also adjust the freeing side.
> ---
>  arch/x86/kernel/ldt.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> --- 4.2/arch/x86/kernel/ldt.c
> +++ 4.2-x86-LDT-alloc/arch/x86/kernel/ldt.c
> @@ -58,7 +58,7 @@ static struct ldt_struct *alloc_ldt_stru
>         if (alloc_size > PAGE_SIZE)
>                 new_ldt->entries = vzalloc(alloc_size);
>         else
> -               new_ldt->entries = kzalloc(PAGE_SIZE, GFP_KERNEL);
> +               new_ldt->entries = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
>
>         if (!new_ldt->entries) {
>                 kfree(new_ldt);
> @@ -95,7 +95,7 @@ static void free_ldt_struct(struct ldt_s
>         if (ldt->size * LDT_ENTRY_SIZE > PAGE_SIZE)
>                 vfree(ldt->entries);
>         else
> -               kfree(ldt->entries);
> +               put_page(virt_to_page(ldt->entries));

FWIW, I'm not convinced this is or was correct.  Using free_page looks
a bit safer, and free_page does more than just put_page.

Does anyone here know the right way to do this?

--Andy

>         kfree(ldt);
>  }
>
>
>
>

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

* Re: [PATCH v2] x86: fix small LDT allocation for Xen
  2015-09-02 14:08 ` Andy Lutomirski
@ 2015-09-02 15:40   ` Jan Beulich
  2015-09-02 16:59     ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2015-09-02 15:40 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: David Vrabel, Ingo Molnar, Thomas Gleixner, Boris Ostrovsky,
	Konrad Rzeszutek Wilk, linux-kernel@vger.kernel.org,
	H. Peter Anvin

>>> On 02.09.15 at 16:08, <luto@amacapital.net> wrote:
> On Sep 2, 2015 5:46 AM, "Jan Beulich" <JBeulich@suse.com> wrote:
>>
>> While commit 37868fe113 ("x86/ldt: Make modify_ldt synchronous") added
>> a nice comment explaining that Xen needs page-aligned whole page chunks
>> for guest descriptor tables, it then nevertheless used kzalloc() on the
>> small size path. As I'm unaware of guarantees for kmalloc(PAGE_SIZE, )
>> to return page-aligned memory blocks, I believe this needs to be
>> switched back to __get_free_page().
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> Cc: Andy Lutomirski <luto@kernel.org>
>> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>> Cc: David Vrabel <david.vrabel@citrix.com>
>> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>> ---
>> v2: Also adjust the freeing side.
>> ---
>>  arch/x86/kernel/ldt.c |    4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> --- 4.2/arch/x86/kernel/ldt.c
>> +++ 4.2-x86-LDT-alloc/arch/x86/kernel/ldt.c
>> @@ -58,7 +58,7 @@ static struct ldt_struct *alloc_ldt_stru
>>         if (alloc_size > PAGE_SIZE)
>>                 new_ldt->entries = vzalloc(alloc_size);
>>         else
>> -               new_ldt->entries = kzalloc(PAGE_SIZE, GFP_KERNEL);
>> +               new_ldt->entries = (void 
> *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
>>
>>         if (!new_ldt->entries) {
>>                 kfree(new_ldt);
>> @@ -95,7 +95,7 @@ static void free_ldt_struct(struct ldt_s
>>         if (ldt->size * LDT_ENTRY_SIZE > PAGE_SIZE)
>>                 vfree(ldt->entries);
>>         else
>> -               kfree(ldt->entries);
>> +               put_page(virt_to_page(ldt->entries));
> 
> FWIW, I'm not convinced this is or was correct.  Using free_page looks
> a bit safer, and free_page does more than just put_page.

Actually I agree. put_page() is meant to be paired with get_page();
__get_free_pages() is just misleading (i.e. doesn't imply a get_page())
and instead is to be paired with free_pages(). Will do a v3 then.

Jan


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

* Re: [PATCH v2] x86: fix small LDT allocation for Xen
  2015-09-02 15:40   ` Jan Beulich
@ 2015-09-02 16:59     ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2015-09-02 16:59 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andy Lutomirski, David Vrabel, Ingo Molnar, Thomas Gleixner,
	Boris Ostrovsky, Konrad Rzeszutek Wilk,
	linux-kernel@vger.kernel.org, H. Peter Anvin


* Jan Beulich <JBeulich@suse.com> wrote:

> >> @@ -95,7 +95,7 @@ static void free_ldt_struct(struct ldt_s
> >>         if (ldt->size * LDT_ENTRY_SIZE > PAGE_SIZE)
> >>                 vfree(ldt->entries);
> >>         else
> >> -               kfree(ldt->entries);
> >> +               put_page(virt_to_page(ldt->entries));
> > 
> > FWIW, I'm not convinced this is or was correct.  Using free_page looks
> > a bit safer, and free_page does more than just put_page.
> 
> Actually I agree. put_page() is meant to be paired with get_page();
> __get_free_pages() is just misleading (i.e. doesn't imply a get_page())
> and instead is to be paired with free_pages(). Will do a v3 then.

So put_page() is a page cache primitive and should not be used outside of it.

As it happens, it is safe to put_page() a regularly allocated page as well, but 
it's a little bit slower than doing a free_page().

Thanks,

	Ingo

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

end of thread, other threads:[~2015-09-02 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-02 12:46 [PATCH v2] x86: fix small LDT allocation for Xen Jan Beulich
2015-09-02 14:08 ` Andy Lutomirski
2015-09-02 15:40   ` Jan Beulich
2015-09-02 16:59     ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.