提交 5ff2a4b9 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/sstabellini-http/tags/xen-20180522-tag' into staging

Xen 2018/05/22

# gpg: Signature made Tue 22 May 2018 19:44:06 BST
# gpg:                using RSA key 894F8F4870E1AE90
# gpg: Good signature from "Stefano Stabellini <stefano.stabellini@eu.citrix.com>"
# gpg:                 aka "Stefano Stabellini <sstabellini@kernel.org>"
# Primary key fingerprint: D04E 33AB A51F 67BA 07D3  0AEA 894F 8F48 70E1 AE90

* remotes/sstabellini-http/tags/xen-20180522-tag:
  xen_disk: be consistent with use of xendev and blkdev->xendev
  xen_disk: use a single entry iovec
  xen_backend: make the xen_feature_grant_copy flag private
  xen_disk: remove use of grant map/unmap
  xen_backend: add an emulation of grant copy
  xen: remove other open-coded use of libxengnttab
  xen_disk: remove open-coded use of libxengnttab
  xen_backend: add grant table helpers
  xen: add a meaningful declaration of grant_copy_segment into xen_common.h
  checkpatch: generalize xen handle matching in the list of types
  xen-hvm: create separate function for ioreq server initialization
  xen_pt: Present the size of 64 bit BARs correctly
  configure: Add explanation for --enable-xen-pci-passthrough
  xen/pt: use address_space_memory object for memory region hooks
  xen-pvdevice: Introduce a simplistic xen-pvdevice save state
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
......@@ -1588,7 +1588,7 @@ disabled with --disable-FEATURE, default is enabled if available:
virtfs VirtFS
mpath Multipath persistent reservation passthrough
xen xen backend driver support
xen-pci-passthrough
xen-pci-passthrough PCI passthrough support for Xen
brlapi BrlAPI (Braile)
curl curl connectivity
membarrier membarrier system call (for Linux 4.14+ or Windows)
......
......@@ -331,14 +331,14 @@ static int xen_9pfs_free(struct XenDevice *xendev)
for (i = 0; i < xen_9pdev->num_rings; i++) {
if (xen_9pdev->rings[i].data != NULL) {
xengnttab_unmap(xen_9pdev->xendev.gnttabdev,
xen_9pdev->rings[i].data,
(1 << xen_9pdev->rings[i].ring_order));
xen_be_unmap_grant_refs(&xen_9pdev->xendev,
xen_9pdev->rings[i].data,
(1 << xen_9pdev->rings[i].ring_order));
}
if (xen_9pdev->rings[i].intf != NULL) {
xengnttab_unmap(xen_9pdev->xendev.gnttabdev,
xen_9pdev->rings[i].intf,
1);
xen_be_unmap_grant_refs(&xen_9pdev->xendev,
xen_9pdev->rings[i].intf,
1);
}
if (xen_9pdev->rings[i].bh != NULL) {
qemu_bh_delete(xen_9pdev->rings[i].bh);
......@@ -390,11 +390,10 @@ static int xen_9pfs_connect(struct XenDevice *xendev)
}
g_free(str);
xen_9pdev->rings[i].intf = xengnttab_map_grant_ref(
xen_9pdev->xendev.gnttabdev,
xen_9pdev->xendev.dom,
xen_9pdev->rings[i].ref,
PROT_READ | PROT_WRITE);
xen_9pdev->rings[i].intf =
xen_be_map_grant_ref(&xen_9pdev->xendev,
xen_9pdev->rings[i].ref,
PROT_READ | PROT_WRITE);
if (!xen_9pdev->rings[i].intf) {
goto out;
}
......@@ -403,12 +402,11 @@ static int xen_9pfs_connect(struct XenDevice *xendev)
goto out;
}
xen_9pdev->rings[i].ring_order = ring_order;
xen_9pdev->rings[i].data = xengnttab_map_domain_grant_refs(
xen_9pdev->xendev.gnttabdev,
(1 << ring_order),
xen_9pdev->xendev.dom,
xen_9pdev->rings[i].intf->ref,
PROT_READ | PROT_WRITE);
xen_9pdev->rings[i].data =
xen_be_map_grant_refs(&xen_9pdev->xendev,
xen_9pdev->rings[i].intf->ref,
(1 << ring_order),
PROT_READ | PROT_WRITE);
if (!xen_9pdev->rings[i].data) {
goto out;
}
......
此差异已折叠。
......@@ -233,12 +233,11 @@ static int con_initialise(struct XenDevice *xendev)
if (!xendev->dev) {
xen_pfn_t mfn = con->ring_ref;
con->sring = xenforeignmemory_map(xen_fmem, con->xendev.dom,
PROT_READ|PROT_WRITE,
PROT_READ | PROT_WRITE,
1, &mfn, NULL);
} else {
con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
con->ring_ref,
PROT_READ|PROT_WRITE);
con->sring = xen_be_map_grant_ref(xendev, con->ring_ref,
PROT_READ | PROT_WRITE);
}
if (!con->sring)
return -1;
......@@ -267,7 +266,7 @@ static void con_disconnect(struct XenDevice *xendev)
if (!xendev->dev) {
xenforeignmemory_unmap(xen_fmem, con->sring, 1);
} else {
xengnttab_unmap(xendev->gnttabdev, con->sring, 1);
xen_be_unmap_grant_ref(xendev, con->sring);
}
con->sring = NULL;
}
......
......@@ -95,7 +95,8 @@ typedef struct XenIOState {
CPUState **cpu_by_vcpu_id;
/* the evtchn port for polling the notification, */
evtchn_port_t *ioreq_local_port;
/* evtchn local port for buffered io */
/* evtchn remote and local ports for buffered io */
evtchn_port_t bufioreq_remote_port;
evtchn_port_t bufioreq_local_port;
/* the evtchn fd for polling */
xenevtchn_handle *xce_handle;
......@@ -1236,12 +1237,52 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
}
void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
static int xen_map_ioreq_server(XenIOState *state)
{
int i, rc;
xen_pfn_t ioreq_pfn;
xen_pfn_t bufioreq_pfn;
evtchn_port_t bufioreq_evtchn;
int rc;
rc = xen_get_ioreq_server_info(xen_domid, state->ioservid,
&ioreq_pfn, &bufioreq_pfn,
&bufioreq_evtchn);
if (rc < 0) {
error_report("failed to get ioreq server info: error %d handle=%p",
errno, xen_xc);
return rc;
}
DPRINTF("shared page at pfn %lx\n", ioreq_pfn);
DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
state->shared_page = xenforeignmemory_map(xen_fmem, xen_domid,
PROT_READ | PROT_WRITE,
1, &ioreq_pfn, NULL);
if (state->shared_page == NULL) {
error_report("map shared IO page returned error %d handle=%p",
errno, xen_xc);
return -1;
}
state->buffered_io_page = xenforeignmemory_map(xen_fmem, xen_domid,
PROT_READ | PROT_WRITE,
1, &bufioreq_pfn, NULL);
if (state->buffered_io_page == NULL) {
error_report("map buffered IO page returned error %d", errno);
return -1;
}
state->bufioreq_remote_port = bufioreq_evtchn;
return 0;
}
void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
{
int i, rc;
xen_pfn_t ioreq_pfn;
XenIOState *state;
state = g_malloc0(sizeof (XenIOState));
......@@ -1269,25 +1310,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
state->wakeup.notify = xen_wakeup_notifier;
qemu_register_wakeup_notifier(&state->wakeup);
rc = xen_get_ioreq_server_info(xen_domid, state->ioservid,
&ioreq_pfn, &bufioreq_pfn,
&bufioreq_evtchn);
rc = xen_map_ioreq_server(state);
if (rc < 0) {
error_report("failed to get ioreq server info: error %d handle=%p",
errno, xen_xc);
goto err;
}
DPRINTF("shared page at pfn %lx\n", ioreq_pfn);
DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
state->shared_page = xenforeignmemory_map(xen_fmem, xen_domid,
PROT_READ|PROT_WRITE,
1, &ioreq_pfn, NULL);
if (state->shared_page == NULL) {
error_report("map shared IO page returned error %d handle=%p",
errno, xen_xc);
goto err;
}
......@@ -1308,14 +1332,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
goto err;
}
state->buffered_io_page = xenforeignmemory_map(xen_fmem, xen_domid,
PROT_READ|PROT_WRITE,
1, &bufioreq_pfn, NULL);
if (state->buffered_io_page == NULL) {
error_report("map buffered IO page returned error %d", errno);
goto err;
}
/* Note: cpus is empty at this point in init */
state->cpu_by_vcpu_id = g_malloc0(max_cpus * sizeof(CPUState *));
......@@ -1340,7 +1356,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
}
rc = xenevtchn_bind_interdomain(state->xce_handle, xen_domid,
bufioreq_evtchn);
state->bufioreq_remote_port);
if (rc == -1) {
error_report("buffered evtchn bind error %d", errno);
goto err;
......
......@@ -71,6 +71,16 @@ static const MemoryRegionOps xen_pv_mmio_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
static const VMStateDescription vmstate_xen_pvdevice = {
.name = "xen-pvdevice",
.version_id = 1,
.minimum_version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_PCI_DEVICE(parent_obj, XenPVDevice),
VMSTATE_END_OF_LIST()
}
};
static void xen_pv_realize(PCIDevice *pci_dev, Error **errp)
{
XenPVDevice *d = XEN_PV_DEVICE(pci_dev);
......@@ -120,6 +130,7 @@ static void xen_pv_class_init(ObjectClass *klass, void *data)
k->class_id = PCI_CLASS_SYSTEM_OTHER;
dc->desc = "Xen PV Device";
dc->props = xen_pv_props;
dc->vmsd = &vmstate_xen_pvdevice;
}
static const TypeInfo xen_pv_type_info = {
......
......@@ -160,9 +160,8 @@ static void net_tx_packets(struct XenNetDev *netdev)
(txreq.flags & NETTXF_more_data) ? " more_data" : "",
(txreq.flags & NETTXF_extra_info) ? " extra_info" : "");
page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
netdev->xendev.dom,
txreq.gref, PROT_READ);
page = xen_be_map_grant_ref(&netdev->xendev, txreq.gref,
PROT_READ);
if (page == NULL) {
xen_pv_printf(&netdev->xendev, 0,
"error: tx gref dereference failed (%d)\n",
......@@ -183,7 +182,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
qemu_send_packet(qemu_get_queue(netdev->nic),
page + txreq.offset, txreq.size);
}
xengnttab_unmap(netdev->xendev.gnttabdev, page, 1);
xen_be_unmap_grant_ref(&netdev->xendev, page);
net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
}
if (!netdev->tx_work) {
......@@ -254,9 +253,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));
netdev->rx_ring.req_cons = ++rc;
page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
netdev->xendev.dom,
rxreq.gref, PROT_WRITE);
page = xen_be_map_grant_ref(&netdev->xendev, rxreq.gref, PROT_WRITE);
if (page == NULL) {
xen_pv_printf(&netdev->xendev, 0,
"error: rx gref dereference failed (%d)\n",
......@@ -265,7 +262,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
return -1;
}
memcpy(page + NET_IP_ALIGN, buf, size);
xengnttab_unmap(netdev->xendev.gnttabdev, page, 1);
xen_be_unmap_grant_ref(&netdev->xendev, page);
net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
return size;
......@@ -338,19 +335,17 @@ static int net_connect(struct XenDevice *xendev)
return -1;
}
netdev->txs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
netdev->xendev.dom,
netdev->tx_ring_ref,
PROT_READ | PROT_WRITE);
netdev->txs = xen_be_map_grant_ref(&netdev->xendev,
netdev->tx_ring_ref,
PROT_READ | PROT_WRITE);
if (!netdev->txs) {
return -1;
}
netdev->rxs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
netdev->xendev.dom,
netdev->rx_ring_ref,
PROT_READ | PROT_WRITE);
netdev->rxs = xen_be_map_grant_ref(&netdev->xendev,
netdev->rx_ring_ref,
PROT_READ | PROT_WRITE);
if (!netdev->rxs) {
xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs);
netdev->txs = NULL;
return -1;
}
......@@ -375,11 +370,11 @@ static void net_disconnect(struct XenDevice *xendev)
xen_pv_unbind_evtchn(&netdev->xendev);
if (netdev->txs) {
xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs);
netdev->txs = NULL;
}
if (netdev->rxs) {
xengnttab_unmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
xen_be_unmap_grant_ref(&netdev->xendev, netdev->rxs);
netdev->rxs = NULL;
}
}
......
......@@ -173,8 +173,9 @@ static int usbback_gnttab_map(struct usbback_req *usbback_req)
for (i = 0; i < usbback_req->nr_buffer_segs; i++) {
ref[i] = usbback_req->req.seg[i].gref;
}
usbback_req->buffer = xengnttab_map_domain_grant_refs(xendev->gnttabdev,
usbback_req->nr_buffer_segs, xendev->dom, ref, prot);
usbback_req->buffer =
xen_be_map_grant_refs(xendev, ref, usbback_req->nr_buffer_segs,
prot);
if (!usbback_req->buffer) {
return -ENOMEM;
......@@ -206,8 +207,9 @@ static int usbback_gnttab_map(struct usbback_req *usbback_req)
for (i = 0; i < usbback_req->nr_extra_segs; i++) {
ref[i] = usbback_req->req.seg[i + usbback_req->req.nr_buffer_segs].gref;
}
usbback_req->isoc_buffer = xengnttab_map_domain_grant_refs(
xendev->gnttabdev, usbback_req->nr_extra_segs, xendev->dom, ref, prot);
usbback_req->isoc_buffer =
xen_be_map_grant_refs(xendev, ref, usbback_req->nr_extra_segs,
prot);
if (!usbback_req->isoc_buffer) {
return -ENOMEM;
......@@ -291,14 +293,14 @@ static void usbback_do_response(struct usbback_req *usbback_req, int32_t status,
}
if (usbback_req->buffer) {
xengnttab_unmap(xendev->gnttabdev, usbback_req->buffer,
usbback_req->nr_buffer_segs);
xen_be_unmap_grant_refs(xendev, usbback_req->buffer,
usbback_req->nr_buffer_segs);
usbback_req->buffer = NULL;
}
if (usbback_req->isoc_buffer) {
xengnttab_unmap(xendev->gnttabdev, usbback_req->isoc_buffer,
usbback_req->nr_extra_segs);
xen_be_unmap_grant_refs(xendev, usbback_req->isoc_buffer,
usbback_req->nr_extra_segs);
usbback_req->isoc_buffer = NULL;
}
......@@ -834,11 +836,11 @@ static void usbback_disconnect(struct XenDevice *xendev)
xen_pv_unbind_evtchn(xendev);
if (usbif->urb_sring) {
xengnttab_unmap(xendev->gnttabdev, usbif->urb_sring, 1);
xen_be_unmap_grant_ref(xendev, usbif->urb_sring);
usbif->urb_sring = NULL;
}
if (usbif->conn_sring) {
xengnttab_unmap(xendev->gnttabdev, usbif->conn_sring, 1);
xen_be_unmap_grant_ref(xendev, usbif->conn_sring);
usbif->conn_sring = NULL;
}
......@@ -877,12 +879,10 @@ static int usbback_connect(struct XenDevice *xendev)
return -1;
}
usbif->urb_sring = xengnttab_map_grant_ref(xendev->gnttabdev, xendev->dom,
urb_ring_ref,
PROT_READ | PROT_WRITE);
usbif->conn_sring = xengnttab_map_grant_ref(xendev->gnttabdev, xendev->dom,
conn_ring_ref,
PROT_READ | PROT_WRITE);
usbif->urb_sring = xen_be_map_grant_ref(xendev, urb_ring_ref,
PROT_READ | PROT_WRITE);
usbif->conn_sring = xen_be_map_grant_ref(xendev, conn_ring_ref,
PROT_READ | PROT_WRITE);
if (!usbif->urb_sring || !usbif->conn_sring) {
xen_pv_printf(xendev, 0, "error mapping rings\n");
usbback_disconnect(xendev);
......@@ -1024,10 +1024,7 @@ static void usbback_alloc(struct XenDevice *xendev)
/* max_grants: for each request and for the rings (request and connect). */
max_grants = USBIF_MAX_SEGMENTS_PER_REQUEST * USB_URB_RING_SIZE + 2;
if (xengnttab_set_max_grants(xendev->gnttabdev, max_grants) < 0) {
xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
strerror(errno));
}
xen_be_set_max_grant_refs(xendev, max_grants);
}
static int usbback_free(struct XenDevice *xendev)
......
......@@ -44,9 +44,9 @@ BusState *xen_sysbus;
/* public */
struct xs_handle *xenstore = NULL;
const char *xen_protocol;
bool xen_feature_grant_copy;
/* private */
static bool xen_feature_grant_copy;
static int debug;
int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val)
......@@ -106,6 +106,156 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
return 0;
}
void xen_be_set_max_grant_refs(struct XenDevice *xendev,
unsigned int nr_refs)
{
assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
if (xengnttab_set_max_grants(xendev->gnttabdev, nr_refs)) {
xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
strerror(errno));
}
}
void *xen_be_map_grant_refs(struct XenDevice *xendev, uint32_t *refs,
unsigned int nr_refs, int prot)
{
void *ptr;
assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
ptr = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_refs,
xen_domid, refs, prot);
if (!ptr) {
xen_pv_printf(xendev, 0,
"xengnttab_map_domain_grant_refs failed: %s\n",
strerror(errno));
}
return ptr;
}
void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr,
unsigned int nr_refs)
{
assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
if (xengnttab_unmap(xendev->gnttabdev, ptr, nr_refs)) {
xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
strerror(errno));
}
}
static int compat_copy_grant_refs(struct XenDevice *xendev,
bool to_domain,
XenGrantCopySegment segs[],
unsigned int nr_segs)
{
uint32_t *refs = g_new(uint32_t, nr_segs);
int prot = to_domain ? PROT_WRITE : PROT_READ;
void *pages;
unsigned int i;
for (i = 0; i < nr_segs; i++) {
XenGrantCopySegment *seg = &segs[i];
refs[i] = to_domain ?
seg->dest.foreign.ref : seg->source.foreign.ref;
}
pages = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_segs,
xen_domid, refs, prot);
if (!pages) {
xen_pv_printf(xendev, 0,
"xengnttab_map_domain_grant_refs failed: %s\n",
strerror(errno));
g_free(refs);
return -1;
}
for (i = 0; i < nr_segs; i++) {
XenGrantCopySegment *seg = &segs[i];
void *page = pages + (i * XC_PAGE_SIZE);
if (to_domain) {
memcpy(page + seg->dest.foreign.offset, seg->source.virt,
seg->len);
} else {
memcpy(seg->dest.virt, page + seg->source.foreign.offset,
seg->len);
}
}
if (xengnttab_unmap(xendev->gnttabdev, pages, nr_segs)) {
xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
strerror(errno));
}
g_free(refs);
return 0;
}
int xen_be_copy_grant_refs(struct XenDevice *xendev,
bool to_domain,
XenGrantCopySegment segs[],
unsigned int nr_segs)
{
xengnttab_grant_copy_segment_t *xengnttab_segs;
unsigned int i;
int rc;
assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
if (!xen_feature_grant_copy) {
return compat_copy_grant_refs(xendev, to_domain, segs, nr_segs);
}
xengnttab_segs = g_new0(xengnttab_grant_copy_segment_t, nr_segs);
for (i = 0; i < nr_segs; i++) {
XenGrantCopySegment *seg = &segs[i];
xengnttab_grant_copy_segment_t *xengnttab_seg = &xengnttab_segs[i];
if (to_domain) {
xengnttab_seg->flags = GNTCOPY_dest_gref;
xengnttab_seg->dest.foreign.domid = xen_domid;
xengnttab_seg->dest.foreign.ref = seg->dest.foreign.ref;
xengnttab_seg->dest.foreign.offset = seg->dest.foreign.offset;
xengnttab_seg->source.virt = seg->source.virt;
} else {
xengnttab_seg->flags = GNTCOPY_source_gref;
xengnttab_seg->source.foreign.domid = xen_domid;
xengnttab_seg->source.foreign.ref = seg->source.foreign.ref;
xengnttab_seg->source.foreign.offset =
seg->source.foreign.offset;
xengnttab_seg->dest.virt = seg->dest.virt;
}
xengnttab_seg->len = seg->len;
}
rc = xengnttab_grant_copy(xendev->gnttabdev, nr_segs, xengnttab_segs);
if (rc) {
xen_pv_printf(xendev, 0, "xengnttab_copy failed: %s\n",
strerror(errno));
}
for (i = 0; i < nr_segs; i++) {
xengnttab_grant_copy_segment_t *xengnttab_seg =
&xengnttab_segs[i];
if (xengnttab_seg->status != GNTST_okay) {
xen_pv_printf(xendev, 0, "segment[%u] status: %d\n", i,
xengnttab_seg->status);
rc = -1;
}
}
g_free(xengnttab_segs);
return rc;
}
/*
* get xen backend device, allocate a new one if it doesn't exist.
*/
......@@ -149,18 +299,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
}
qemu_set_cloexec(xenevtchn_fd(xendev->evtchndev));
if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
xendev->gnttabdev = xengnttab_open(NULL, 0);
if (xendev->gnttabdev == NULL) {
xen_pv_printf(NULL, 0, "can't open gnttab device\n");
xenevtchn_close(xendev->evtchndev);
qdev_unplug(DEVICE(xendev), NULL);
return NULL;
}
} else {
xendev->gnttabdev = NULL;
}
xen_pv_insert_xendev(xendev);
if (xendev->ops->alloc) {
......@@ -322,6 +460,16 @@ static int xen_be_try_initialise(struct XenDevice *xendev)
}
}
if (xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
xendev->gnttabdev = xengnttab_open(NULL, 0);
if (xendev->gnttabdev == NULL) {
xen_pv_printf(NULL, 0, "can't open gnttab device\n");
return -1;
}
} else {
xendev->gnttabdev = NULL;
}
if (xendev->ops->initialise) {
rc = xendev->ops->initialise(xendev);
}
......@@ -369,6 +517,10 @@ static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
xendev->ops->disconnect) {
xendev->ops->disconnect(xendev);
}
if (xendev->gnttabdev) {
xengnttab_close(xendev->gnttabdev);
xendev->gnttabdev = NULL;
}
if (xendev->be_state != state) {
xen_be_set_state(xendev, state);
}
......
......@@ -907,7 +907,7 @@ out:
}
}
memory_listener_register(&s->memory_listener, &s->dev.bus_master_as);
memory_listener_register(&s->memory_listener, &address_space_memory);
memory_listener_register(&s->io_listener, &address_space_io);
s->listener_set = true;
XEN_PT_LOG(d,
......
......@@ -504,6 +504,8 @@ static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
break;
case XEN_PT_BAR_FLAG_UPPER:
assert(index > 0);
r_size = d->io_regions[index - 1].size >> 32;
bar_emu_mask = XEN_PT_BAR_ALLF;
bar_ro_mask = r_size ? r_size - 1 : 0;
break;
......
......@@ -16,7 +16,6 @@
/* variables */
extern struct xs_handle *xenstore;
extern const char *xen_protocol;
extern bool xen_feature_grant_copy;
extern DeviceState *xen_sysdev;
extern BusState *xen_sysbus;
......@@ -42,6 +41,39 @@ void xen_be_register_common(void);
int xen_be_register(const char *type, struct XenDevOps *ops);
int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state);
int xen_be_bind_evtchn(struct XenDevice *xendev);
void xen_be_set_max_grant_refs(struct XenDevice *xendev,
unsigned int nr_refs);
void *xen_be_map_grant_refs(struct XenDevice *xendev, uint32_t *refs,
unsigned int nr_refs, int prot);
void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr,
unsigned int nr_refs);
typedef struct XenGrantCopySegment {
union {
void *virt;
struct {
uint32_t ref;
off_t offset;
} foreign;
} source, dest;
size_t len;
} XenGrantCopySegment;
int xen_be_copy_grant_refs(struct XenDevice *xendev,
bool to_domain, XenGrantCopySegment segs[],
unsigned int nr_segs);
static inline void *xen_be_map_grant_ref(struct XenDevice *xendev,
uint32_t ref, int prot)
{
return xen_be_map_grant_refs(xendev, &ref, 1, prot);
}
static inline void xen_be_unmap_grant_ref(struct XenDevice *xendev,
void *ptr)
{
return xen_be_unmap_grant_refs(xendev, ptr, 1);
}
/* actual backend drivers */
extern struct XenDevOps xen_console_ops; /* xen_console.c */
......
......@@ -667,8 +667,21 @@ static inline int xen_domain_create(xc_interface *xc, uint32_t ssidref,
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40800
typedef void *xengnttab_grant_copy_segment_t;
struct xengnttab_grant_copy_segment {
union xengnttab_copy_ptr {
void *virt;
struct {
uint32_t ref;
uint16_t offset;
uint16_t domid;
} foreign;
} source, dest;
uint16_t len;
uint16_t flags;
int16_t status;
};
typedef struct xengnttab_grant_copy_segment xengnttab_grant_copy_segment_t;
static inline int xengnttab_grant_copy(xengnttab_handle *xgt, uint32_t count,
xengnttab_grant_copy_segment_t *segs)
......
......@@ -271,7 +271,7 @@ our @typeList = (
qr{hwaddr},
# external libraries
qr{xml${Ident}},
qr{xendevicemodel_handle},
qr{xen\w+_handle},
# Glib definitions
qr{gchar},
qr{gshort},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册