From: Long Li <lon...@microsoft.com>

The ring buffer data region always starts at the system page boundary
after ring buffer head. The current code assumes the system page size is
4k. This is not always correct.

Fix this by using system page size for addressing ring buffer data.

Fixes: 831dba47bd ("bus/vmbus: add Hyper-V virtual bus support")
Cc: sta...@dpdk.org
Signed-off-by: Long Li <lon...@microsoft.com>
---
 drivers/bus/vmbus/rte_vmbus_reg.h | 9 +++------
 drivers/bus/vmbus/vmbus_bufring.c | 9 ++++++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/bus/vmbus/rte_vmbus_reg.h 
b/drivers/bus/vmbus/rte_vmbus_reg.h
index 54a26d12bd..fb7e3043ec 100644
--- a/drivers/bus/vmbus/rte_vmbus_reg.h
+++ b/drivers/bus/vmbus/rte_vmbus_reg.h
@@ -100,14 +100,11 @@ struct __rte_packed_begin vmbus_bufring {
                uint32_t value;
        } feature_bits;
 
-       /* Pad it to rte_mem_page_size() so that data starts on page boundary */
-       uint8_t reserved2[4028];
-
        /*
-        * Ring data starts here + RingDataStartOffset
-        * !!! DO NOT place any fields below this !!!
+        * This is the end of ring buffer head. The ring buffer data is system
+        * page aligned and starts at rte_mem_page_size() from the beginning
+        * of this structure
         */
-       uint8_t data[];
 } __rte_packed_end;
 
 /*
diff --git a/drivers/bus/vmbus/vmbus_bufring.c 
b/drivers/bus/vmbus/vmbus_bufring.c
index c78619dc44..fcb97287dc 100644
--- a/drivers/bus/vmbus/vmbus_bufring.c
+++ b/drivers/bus/vmbus/vmbus_bufring.c
@@ -36,7 +36,10 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned 
int blen)
 {
        br->vbr = buf;
        br->windex = br->vbr->windex;
-       br->dsize = blen - sizeof(struct vmbus_bufring);
+
+       /* The ring buffer data starts at the 2nd page of the ring buffer */
+       RTE_VERIFY(blen > rte_mem_page_size());
+       br->dsize = blen - rte_mem_page_size();
 }
 
 /*
@@ -72,7 +75,7 @@ static inline uint32_t
 vmbus_txbr_copyto(const struct vmbus_br *tbr, uint32_t windex,
                  const void *src0, uint32_t cplen)
 {
-       uint8_t *br_data = tbr->vbr->data;
+       uint8_t *br_data = (uint8_t *)tbr->vbr + rte_mem_page_size();
        uint32_t br_dsize = tbr->dsize;
        const uint8_t *src = src0;
 
@@ -170,7 +173,7 @@ static inline uint32_t
 vmbus_rxbr_copyfrom(const struct vmbus_br *rbr, uint32_t rindex,
                    void *dst0, size_t cplen)
 {
-       const uint8_t *br_data = rbr->vbr->data;
+       const uint8_t *br_data = (uint8_t *)rbr->vbr + rte_mem_page_size();
        uint32_t br_dsize = rbr->dsize;
        uint8_t *dst = dst0;
 
-- 
2.34.1

Reply via email to