qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt()
@ 2020-10-29 15:33 Greg Kurz
  2020-10-29 15:33 ` [PATCH 2/2] spapr: Convert hpt_prepare_thread() to use qemu_try_memalign() Greg Kurz
  2020-10-29 20:11 ` [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() David Gibson
  0 siblings, 2 replies; 3+ messages in thread
From: Greg Kurz @ 2020-10-29 15:33 UTC (permalink / raw)
  To: David Gibson; +Cc: qemu-ppc, Philippe Mathieu-Daudé, qemu-devel

Sometimes QEMU needs to allocate the HPT in userspace, namely with TCG
or PR KVM. This is performed with qemu_memalign() because of alignment
requirements. Like glib's allocators, its behaviour is to abort on OOM
instead of returning NULL.

This could be changed to qemu_try_memalign(), but in the specific case
of spapr_reallocate_hpt(), the outcome would be to terminate QEMU anyway
since no HPT means no MMU for the guest. Drop the dead code instead.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr.c |    6 ------
 1 file changed, 6 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 227075103e9a..12a012d9dd09 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1522,12 +1522,6 @@ int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp)
         int i;
 
         spapr->htab = qemu_memalign(size, size);
-        if (!spapr->htab) {
-            error_setg_errno(errp, errno,
-                             "Could not allocate HPT of order %d", shift);
-            return -ENOMEM;
-        }
-
         memset(spapr->htab, 0, size);
         spapr->htab_shift = shift;
 




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

* [PATCH 2/2] spapr: Convert hpt_prepare_thread() to use qemu_try_memalign()
  2020-10-29 15:33 [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() Greg Kurz
@ 2020-10-29 15:33 ` Greg Kurz
  2020-10-29 20:11 ` [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kurz @ 2020-10-29 15:33 UTC (permalink / raw)
  To: David Gibson; +Cc: qemu-ppc, Philippe Mathieu-Daudé, qemu-devel

HPT resizing is asynchronous: the guest first kicks off the creation of a
new HPT, then it waits for that new HPT to be actually created and finally
it asks the current HPT to be replaced by the new one.

In the case of a userland allocated HPT, this currently relies on calling
qemu_memalign() which aborts on OOM and never returns NULL. Since we seem
to have path to report the failure to the guest with an H_NO_MEM return
value, use qemu_try_memalign() instead of qemu_memalign().

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_hcall.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 607740150fa2..1d8e8e6a888f 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -360,7 +360,7 @@ static void *hpt_prepare_thread(void *opaque)
     SpaprPendingHpt *pending = opaque;
     size_t size = 1ULL << pending->shift;
 
-    pending->hpt = qemu_memalign(size, size);
+    pending->hpt = qemu_try_memalign(size, size);
     if (pending->hpt) {
         memset(pending->hpt, 0, size);
         pending->ret = H_SUCCESS;




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

* Re: [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt()
  2020-10-29 15:33 [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() Greg Kurz
  2020-10-29 15:33 ` [PATCH 2/2] spapr: Convert hpt_prepare_thread() to use qemu_try_memalign() Greg Kurz
@ 2020-10-29 20:11 ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2020-10-29 20:11 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-ppc, Philippe Mathieu-Daudé, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1518 bytes --]

On Thu, Oct 29, 2020 at 04:33:48PM +0100, Greg Kurz wrote:
> Sometimes QEMU needs to allocate the HPT in userspace, namely with TCG
> or PR KVM. This is performed with qemu_memalign() because of alignment
> requirements. Like glib's allocators, its behaviour is to abort on OOM
> instead of returning NULL.
> 
> This could be changed to qemu_try_memalign(), but in the specific case
> of spapr_reallocate_hpt(), the outcome would be to terminate QEMU anyway
> since no HPT means no MMU for the guest. Drop the dead code instead.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Series applied to ppc-for-5.2.

> ---
>  hw/ppc/spapr.c |    6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 227075103e9a..12a012d9dd09 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1522,12 +1522,6 @@ int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp)
>          int i;
>  
>          spapr->htab = qemu_memalign(size, size);
> -        if (!spapr->htab) {
> -            error_setg_errno(errp, errno,
> -                             "Could not allocate HPT of order %d", shift);
> -            return -ENOMEM;
> -        }
> -
>          memset(spapr->htab, 0, size);
>          spapr->htab_shift = shift;
>  
> 
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2020-10-29 20:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 15:33 [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() Greg Kurz
2020-10-29 15:33 ` [PATCH 2/2] spapr: Convert hpt_prepare_thread() to use qemu_try_memalign() Greg Kurz
2020-10-29 20:11 ` [PATCH 1/2] spapr: Drop dead code in spapr_reallocate_hpt() David Gibson

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).