From 9a276592fbe099827c49d22f3112c34ad5c43803 Mon Sep 17 00:00:00 2001 From: Zhi Jin Date: Thu, 23 Aug 2018 09:25:44 +0800 Subject: [PATCH] DM NPK: use a slice (8 masters) as the minimal unit for NPK virt To align with the configuration of the HOST tool, the SW masters are organized in slices of 8 masters each. The slice is also the minimal unit to allocate the SW masters for each UOS. The patch is to update the parameter checking function. Tracked-On: #1138 Signed-off-by: Zhi Jin Reviewed-by: Chen Gang --- devicemodel/hw/pci/npk.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/devicemodel/hw/pci/npk.c b/devicemodel/hw/pci/npk.c index 1d2f2d384..ab19c542b 100644 --- a/devicemodel/hw/pci/npk.c +++ b/devicemodel/hw/pci/npk.c @@ -159,11 +159,11 @@ static inline uint32_t *offset2reg(uint64_t offset) return reg; } -static inline int valid_param(int m_off, int m_num) +static inline int valid_param(uint32_t m_off, uint32_t m_num) { - /* 256-aligned, no less than 256, no overflow */ - if (!(m_off & 0xFF) && !(m_num & 0xFF) && (m_off >> 8) > 0 - && (m_num >> 8) > 0 && m_off + m_num <= NPK_SW_MSTR_NUM) + /* 8-aligned, no less than 8, no overflow */ + if (((m_off & 0x7U) == 0) && ((m_num & 0x7U) == 0) && (m_off > 0x7U) + && (m_num > 0x7U) && (m_off + m_num <= NPK_SW_MSTR_NUM)) return 1; return 0; @@ -177,11 +177,12 @@ static inline int valid_param(int m_off, int m_num) */ static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) { - int i, b, s, f, fd, ret, m_off, m_num, error = -1; + int i, b, s, f, fd, ret, error = -1; DIR *dir; struct dirent *dent; char name[PATH_MAX]; uint8_t h_cfg[PCI_REGMAX + 1]; + uint32_t m_off, m_num; uint64_t sw_bar_base; struct npk_reg_default_val *d; @@ -210,7 +211,7 @@ static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) */ /* get the master offset and the number for this guest */ - if (opts == NULL || sscanf(opts, "%d/%d", &m_off, &m_num) != 2 + if ((opts == NULL) || (sscanf(opts, "%u/%u", &m_off, &m_num) != 2) || !valid_param(m_off, m_num)) { m_off = 256; m_num = 256;