From 857e6c0415cfae0e3563e60c7c44107b26151ef3 Mon Sep 17 00:00:00 2001 From: Tw Date: Fri, 31 May 2019 15:35:36 +0800 Subject: [PATCH] dm: passthrough: allow not page-aligned sized bar to be mapped Some physical bar sizes are not page aligned, in order to support them, we map a bigger region which is page aligned. Tracked-On: #3181 Signed-off-by: Tw Reviewed-by: Binbin Wu --- devicemodel/hw/pci/passthrough.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index 00e19ef54..4cb359de8 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -574,13 +574,22 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev) if (bartype != PCIBAR_IO) { /* note here PAGE_MASK is 0xFFFFF000 */ - if (((base | size) & ~PAGE_MASK) != 0) { + if ((base & ~PAGE_MASK) != 0) { warnx("passthru device %x/%x/%x BAR %d: " - "base %#lx or size %#lx not page aligned\n", + "base %#lx not page aligned\n", ptdev->sel.bus, ptdev->sel.dev, - ptdev->sel.func, i, base, size); + ptdev->sel.func, i, base); return -1; } + /* roundup to PAGE_SIZE for bar size */ + if ((size & ~PAGE_MASK) != 0) { + warnx("passthru device %x/%x/%x BAR %d: " + "size[%lx] is expanded to page aligned [%lx]\n", + ptdev->sel.bus, ptdev->sel.dev, + ptdev->sel.func, i, size, roundup2(size, PAGE_SIZE)); + size = roundup2(size, PAGE_SIZE); + } + } /* Cache information about the "real" BAR */