qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mem/cxl_type3: fix hpa to dpa logic
@ 2024-03-27  1:46 Yao Xingtao via
  2024-03-27 13:28 ` Jonathan Cameron via
  0 siblings, 1 reply; 6+ messages in thread
From: Yao Xingtao via @ 2024-03-27  1:46 UTC (permalink / raw)
  To: jonathan.cameron, fan.ni; +Cc: qemu-devel, caoqq, Yao Xingtao

In 3, 6, 12 interleave ways, we could not access cxl memory properly,
and when the process is running on it, a 'segmentation fault' error will
occur.

According to the CXL specification '8.2.4.20.13 Decoder Protection',
there are two branches to convert HPA to DPA:
b1: Decoder[m].IW < 8 (for 1, 2, 4, 8, 16 interleave ways)
b2: Decoder[m].IW >= 8 (for 3, 6, 12 interleave ways)

but only b1 has been implemented.

To solve this issue, we should implement b2:
  DPAOffset[51:IG+8]=HPAOffset[51:IG+IW] / 3
  DPAOffset[IG+7:0]=HPAOffset[IG+7:0]
  DPA=DPAOffset + Decoder[n].DPABase

Links: https://lore.kernel.org/linux-cxl/3e84b919-7631-d1db-3e1d-33000f3f3868@fujitsu.com/
Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
---
 hw/mem/cxl_type3.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index b0a7e9f11b..2c1218fb12 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -805,10 +805,17 @@ static bool cxl_type3_dpa(CXLType3Dev *ct3d, hwaddr host_addr, uint64_t *dpa)
             continue;
         }
 
-        *dpa = dpa_base +
-            ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) |
-             ((MAKE_64BIT_MASK(8 + ig + iw, 64 - 8 - ig - iw) & hpa_offset)
-              >> iw));
+        if (iw < 8) {
+            *dpa = dpa_base +
+                ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) |
+                 ((MAKE_64BIT_MASK(8 + ig + iw, 64 - 8 - ig - iw) & hpa_offset)
+                  >> iw));
+        } else {
+            *dpa = dpa_base +
+                ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) |
+                 ((((MAKE_64BIT_MASK(ig + iw, 64 - ig - iw) & hpa_offset)
+                   >> (ig + iw)) / 3) << (ig + 8)));
+        }
 
         return true;
     }
-- 
2.37.3



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

end of thread, other threads:[~2024-04-07  1:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-27  1:46 [PATCH] mem/cxl_type3: fix hpa to dpa logic Yao Xingtao via
2024-03-27 13:28 ` Jonathan Cameron via
2024-03-28  6:24   ` Xingtao Yao (Fujitsu) via
2024-04-01 16:00     ` Jonathan Cameron via
2024-04-05 16:45       ` Jonathan Cameron via
2024-04-07  1:46         ` Xingtao Yao (Fujitsu) via

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