diff mbox series

[RFC,1/3] xen/privcmd: replace kcalloc() by kvcalloc() when allocating empty pages

Message ID 6d698901-98a4-05be-c421-bcd0713f5335@suse.com (mailing list archive)
State Accepted
Commit 0432523f4807a83902857347bd73eb817ef0a742
Headers show
Series xen/privcmd: misc corrections | expand

Commit Message

Jan Beulich Sept. 22, 2021, 10:16 a.m. UTC
Osstest has been suffering test failures for a little while from order-4
allocation failures, resulting from alloc_empty_pages() calling
kcalloc(). As there's no need for physically contiguous space here,
switch to kvcalloc().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
RFC: I cannot really test this, as alloc_empty_pages() only gets used in
     the auto-translated case (i.e. on Arm or PVH Dom0, the latter of
     which I'm not trusting enough yet to actually start playing with
     guests).

There are quite a few more kcalloc() where it's not immediately clear
how large the element counts could possibly grow nor whether it would be
fine to replace them (i.e. physically contiguous space not required).

I wasn't sure whether to Cc stable@ here; the issue certainly has been
present for quite some time. But it didn't look to cause issues until
recently.

Comments

Jürgen Groß Sept. 23, 2021, 12:30 p.m. UTC | #1
On 22.09.21 12:16, Jan Beulich wrote:
> Osstest has been suffering test failures for a little while from order-4
> allocation failures, resulting from alloc_empty_pages() calling
> kcalloc(). As there's no need for physically contiguous space here,
> switch to kvcalloc().
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Juergen Gross <jgross@suse.com>

> ---
> RFC: I cannot really test this, as alloc_empty_pages() only gets used in
>       the auto-translated case (i.e. on Arm or PVH Dom0, the latter of
>       which I'm not trusting enough yet to actually start playing with
>       guests).
> 
> There are quite a few more kcalloc() where it's not immediately clear
> how large the element counts could possibly grow nor whether it would be
> fine to replace them (i.e. physically contiguous space not required).

I don't think those are an issue. Per default the sizes seem to be well
below a single page.

> I wasn't sure whether to Cc stable@ here; the issue certainly has been
> present for quite some time. But it didn't look to cause issues until
> recently.

I'd rather add it to stable. Its not as if the patch had a high
complexity.


Juergen
diff mbox series

Patch

--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -420,7 +420,7 @@  static int alloc_empty_pages(struct vm_a
 	int rc;
 	struct page **pages;
 
-	pages = kcalloc(numpgs, sizeof(pages[0]), GFP_KERNEL);
+	pages = kvcalloc(numpgs, sizeof(pages[0]), GFP_KERNEL);
 	if (pages == NULL)
 		return -ENOMEM;
 
@@ -428,7 +428,7 @@  static int alloc_empty_pages(struct vm_a
 	if (rc != 0) {
 		pr_warn("%s Could not alloc %d pfns rc:%d\n", __func__,
 			numpgs, rc);
-		kfree(pages);
+		kvfree(pages);
 		return -ENOMEM;
 	}
 	BUG_ON(vma->vm_private_data != NULL);
@@ -912,7 +912,7 @@  static void privcmd_close(struct vm_area
 	else
 		pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n",
 			numpgs, rc);
-	kfree(pages);
+	kvfree(pages);
 }
 
 static vm_fault_t privcmd_fault(struct vm_fault *vmf)