Skip to contentSkip to conversation

ppc queue

GIT PULL Applied Daniel Henrique Barboza 2 participants 7 messages Jul 28, 2022 – Jul 29, 2022

lore
Share & tools
lore
#0 lore raw

The following changes since commit 3e4abe2c92964aadd35344a635b0f32cb487fd5c:

Merge tag 'pull-block-2022-07-27' of https://gitlab.com/vsementsov/qemu into staging (2022-07-27 20:10:15 -0700)

are available in the Git repository at:

https://gitlab.com/danielhb/qemu.git pull-ppc-20220728

for you to fetch changes up to 0c9717ff35d2fe46fa9cb91566fe2afbed9f4f2a:

target/ppc: Implement new wait variants (2022-07-28 13:30:41 -0300)

----------------------------------------------------------------
ppc patch queue for 2022-07-28:

Short queue with 2 Coverity fixes and one fix of the 'wait' insns that is causing hangs if the guest kernel uses the most up to date wait opcode.

- target/ppc:
- implement new wait variants to fix guest hang when using the new opcode
- ppc440_uc: initialize length passed to cpu_physical_memory_map()
- spapr_nvdimm: check if spapr_drc_index() returns NULL

----------------------------------------------------------------
Daniel Henrique Barboza (1):
hw/ppc: check if spapr_drc_index() returns NULL in spapr_nvdimm.c

Nicholas Piggin (1):
target/ppc: Implement new wait variants

Peter Maydell (1):
hw/ppc/ppc440_uc: Initialize length passed to cpu_physical_memory_map()

 hw/ppc/ppc440_uc.c     |  5 ++-
 hw/ppc/spapr_nvdimm.c  | 18 +++++++---
 target/ppc/internal.h  |  3 ++
 target/ppc/translate.c | 96 +++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 109 insertions(+), 13 deletions(-)
#1 lore raw

[PULL 1/3] hw/ppc: check if spapr_drc_index() returns NULL in spapr_nvdimm.c

spapr_nvdimm_flush_completion_cb() and flush_worker_cb() are using the DRC object returned by spapr_drc_index() without checking it for NULL. In this case we would be dereferencing a NULL pointer when doing SPAPR_NVDIMM(drc->dev) and PC_DIMM(drc->dev).

This can happen if, during a scm_flush(), the DRC object is wrongly freed/released (e.g. a bug in another part of the code). spapr_drc_index() would then return NULL in the callbacks.

Fixes Coverity CID 1487108, 1487178

Message-Id: <[email protected]>

---
 hw/ppc/spapr_nvdimm.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
hw/ppc/spapr_nvdimm.c +14 -4
index c4c97da5de..04a64cada3 100644
@@ -447,9 +447,15 @@ static int flush_worker_cb(void *opaque)
 {
     SpaprNVDIMMDeviceFlushState *state = opaque;
     SpaprDrc *drc = spapr_drc_by_index(state->drcidx);
-    PCDIMMDevice *dimm = PC_DIMM(drc->dev);
-    HostMemoryBackend *backend = MEMORY_BACKEND(dimm->hostmem);
-    int backend_fd = memory_region_get_fd(&backend->mr);
+    PCDIMMDevice *dimm;
+    HostMemoryBackend *backend;
+    int backend_fd;
+
+    g_assert(drc != NULL);
+
+    dimm = PC_DIMM(drc->dev);
+    backend = MEMORY_BACKEND(dimm->hostmem);
+    backend_fd = memory_region_get_fd(&backend->mr);
 
     if (object_property_get_bool(OBJECT(backend), "pmem", NULL)) {
         MemoryRegion *mr = host_memory_backend_get_memory(dimm->hostmem);
@@ -475,7 +481,11 @@ static void spapr_nvdimm_flush_completion_cb(void *opaque, int hcall_ret)
 {
     SpaprNVDIMMDeviceFlushState *state = opaque;
     SpaprDrc *drc = spapr_drc_by_index(state->drcidx);
-    SpaprNVDIMMDevice *s_nvdimm = SPAPR_NVDIMM(drc->dev);
+    SpaprNVDIMMDevice *s_nvdimm;
+
+    g_assert(drc != NULL);
+
+    s_nvdimm = SPAPR_NVDIMM(drc->dev);
 
     state->hcall_ret = hcall_ret;
     QLIST_REMOVE(state, node);
Signature · 1 line
2.36.1
#2 lore raw

[PULL 3/3] target/ppc: Implement new wait variants

In reply to Daniel Henrique Barboza

From: Nicholas Piggin <[email protected]>

ISA v2.06 adds new variations of wait, specified by the WC field. These are not all compatible with the prior wait implementation, because they add additional conditions that cause the processor to resume, which can cause software to hang or run very slowly.

At this moment, with the current wait implementation and a pseries guest using mainline kernel with new wait upcodes [1], QEMU hangs during boot if more than one CPU is present:

qemu-system-ppc64 -M pseries,x-vof=on -cpu POWER10 -smp 2 -nographic
-kernel zImage.pseries -no-reboot

QEMU will exit (as there's no filesystem) if the test "passes", or hang during boot if it hits the bug.

ISA v3.0 changed the wait opcode and removed the new variants (retaining the WC field but making non-zero values reserved).

ISA v3.1 added new WC values to the new wait opcode, and added a PL field.

This patch implements the new wait encoding and supports WC variants with no-op implementations, which provides basic correctness as explained in comments.

[1] https://lore.kernel.org/all/[email protected]/

Message-Id: <[email protected]>

[danielhb: added information about the bug being fixed]
---
 target/ppc/internal.h  |  3 ++
 target/ppc/translate.c | 96 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 91 insertions(+), 8 deletions(-)
target/ppc/internal.h +3 -0
index 467f3046c8..337a362205 100644
@@ -165,6 +165,9 @@ EXTRACT_HELPER_SPLIT_3(DX, 10, 6, 6, 5, 16, 1, 1, 0, 0)
 /* darn */
 EXTRACT_HELPER(L, 16, 2);
 #endif
+/* wait */
+EXTRACT_HELPER(WC, 21, 2);
+EXTRACT_HELPER(PL, 16, 2);
 
 /***                            Jump target decoding                       ***/
 /* Immediate address */
target/ppc/translate.c +88 -8

108 lines not on this page · raw message

Signature · 1 line
2.36.1
#3 lore raw

[PULL 2/3] hw/ppc/ppc440_uc: Initialize length passed to cpu_physical_memory_map()

In reply to Daniel Henrique Barboza

From: Peter Maydell <[email protected]>

In dcr_write_dma(), there is code that uses cpu_physical_memory_map() to implement a DMA transfer. That function takes a 'plen' argument, which points to a hwaddr which is used for both input and output: the caller must set it to the size of the range it wants to map, and on return it is updated to the actual length mapped. The dcr_write_dma() code fails to initialize rlen and wlen, so will end up mapping an unpredictable amount of memory.

Initialize the length values correctly, and check that we managed to map the entire range before using the fast-path memmove().

This was spotted by Coverity, which points out that we never initialized the variables before using them.

Fixes Coverity CID 1487137, 1487150

Message-Id: <[email protected]>

---
 hw/ppc/ppc440_uc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/ppc/ppc440_uc.c +4 -1
index a1ecf6dd1c..11fdb88c22 100644
@@ -904,14 +904,17 @@ static void dcr_write_dma(void *opaque, int dcrn, uint32_t val)
                     int width, i, sidx, didx;
                     uint8_t *rptr, *wptr;
                     hwaddr rlen, wlen;
+                    hwaddr xferlen;
 
                     sidx = didx = 0;
                     width = 1 << ((val & DMA0_CR_PW) >> 25);
+                    xferlen = count * width;
+                    wlen = rlen = xferlen;
                     rptr = cpu_physical_memory_map(dma->ch[chnl].sa, &rlen,
                                                    false);
                     wptr = cpu_physical_memory_map(dma->ch[chnl].da, &wlen,
                                                    true);
-                    if (rptr && wptr) {
+                    if (rptr && rlen == xferlen && wptr && wlen == xferlen) {
                         if (!(val & DMA0_CR_DEC) &&
                             val & DMA0_CR_SAI && val & DMA0_CR_DAI) {
                             /* optimise common case */
Signature · 1 line
2.36.1
#5 lore raw
Quoted 7 lines · Richard Henderson
Quoted 1 line · Daniel Henrique Barboza

   https://gitlab.com/danielhb/qemu.git  pull-ppc-20220728

fatal: couldn't find remote ref pull-ppc-20220728

Did you forget to push the tag to gitlab?

I guess I mistyped the credentials when running make-pullreq.sh and the tag wasn't pushed. Can you try again? It is pushed now:

https://gitlab.com/danielhb/qemu/-/commits/pull-ppc-20220728

Thanks,

Daniel

Quoted 3 lines

r~

#6 lore raw
In reply to Daniel Henrique Barboza
Quoted 15 lines · Daniel Henrique Barboza

The following changes since commit 3e4abe2c92964aadd35344a635b0f32cb487fd5c:

   Merge tag 'pull-block-2022-07-27' of https://gitlab.com/vsementsov/qemu into staging (2022-07-27 20:10:15 -0700)

are available in the Git repository at:

   https://gitlab.com/danielhb/qemu.git pull-ppc-20220728

for you to fetch changes up to 0c9717ff35d2fe46fa9cb91566fe2afbed9f4f2a:

   target/ppc: Implement new wait variants (2022-07-28 13:30:41 -0300)

----------------------------------------------------------------
ppc patch queue for 2022-07-28:

Quoted 8 lines

Short queue with 2 Coverity fixes and one fix of the 'wait' insns that is causing hangs if the guest kernel uses the most up to date wait opcode.

- target/ppc:
- implement new wait variants to fix guest hang when using the new opcode
- ppc440_uc: initialize length passed to cpu_physical_memory_map()
- spapr_nvdimm: check if spapr_drc_index() returns NULL

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.

r~

Quoted 16 lines

----------------------------------------------------------------
Daniel Henrique Barboza (1):
hw/ppc: check if spapr_drc_index() returns NULL in spapr_nvdimm.c

Nicholas Piggin (1):
target/ppc: Implement new wait variants

Peter Maydell (1):
hw/ppc/ppc440_uc: Initialize length passed to cpu_physical_memory_map()

  hw/ppc/ppc440_uc.c     |  5 ++-
  hw/ppc/spapr_nvdimm.c  | 18 +++++++---
  target/ppc/internal.h  |  3 ++
  target/ppc/translate.c | 96 +++++++++++++++++++++++++++++++++++++++++++++-----
  4 files changed, 109 insertions(+), 13 deletions(-)