diff options
author | JaeMan Park <jaeman@google.com> | 2021-07-19 17:33:16 +0900 |
---|---|---|
committer | JaeMan Park <jaeman@google.com> | 2021-07-22 05:33:28 +0000 |
commit | 7dca8ac4aeaca1507864c8b330b0a604c87633cf (patch) | |
tree | 93e1b22cb8e5d0301eca698b16f6e2b3956d7b3f /wmediumd | |
parent | 476eb906a5f7258cbc6381428d24ad1f4abe70bc (diff) | |
download | wmediumd-7dca8ac4aeaca1507864c8b330b0a604c87633cf.tar.gz |
Fix translation of vring address to guest-physical
At vhost protocol, vring address at virtq descriptor is physical
address of guest OS. But, current vhost implementation at
wmediumd (maybe referenced from usfstl) translates vring address
as host user address. It raises exception when attaching CF instance
to wmediumd using vhost.
Bug: 194023816
Test: lunch aosp_cf_x86_64_phone-userdebug &&
m PRODUCT_ENFORCE_MAC80211_HWSIM=true droid wmediumd &&
wmediumd -u /tmp/vhost_server_mac80211 -c $ANDROID_BUILD_TOP/external/wmediumd/tests/cuttlefish.cfg
and then, execute
launch_cvd --vhost-user-mac80211-hwsim=/tmp/vhost_server_mac80211
Change-Id: I00b881b82a98e2cb4e5ef51d40cffcb81dac3eab
Diffstat (limited to 'wmediumd')
-rw-r--r-- | wmediumd/inc/usfstl/vhost.h | 7 | ||||
-rw-r--r-- | wmediumd/lib/vhost.c | 25 |
2 files changed, 30 insertions, 2 deletions
diff --git a/wmediumd/inc/usfstl/vhost.h b/wmediumd/inc/usfstl/vhost.h index f07a33d..017d0b5 100644 --- a/wmediumd/inc/usfstl/vhost.h +++ b/wmediumd/inc/usfstl/vhost.h @@ -140,6 +140,13 @@ void usfstl_vhost_user_config_changed(struct usfstl_vhost_user_dev *dev); */ void *usfstl_vhost_user_to_va(struct usfstl_vhost_user_dev *dev, uint64_t addr); +/** + * usfstl_vhost_phys_to_va - translate address + * @dev: device to translate address for + * @addr: guest-side physical addr + */ +void *usfstl_vhost_phys_to_va(struct usfstl_vhost_user_dev *dev, uint64_t addr); + /* also some IOV helpers */ size_t iov_len(struct iovec *sg, unsigned int nsg); size_t iov_fill(struct iovec *sg, unsigned int nsg, diff --git a/wmediumd/lib/vhost.c b/wmediumd/lib/vhost.c index 1a85140..b437efd 100644 --- a/wmediumd/lib/vhost.c +++ b/wmediumd/lib/vhost.c @@ -138,7 +138,7 @@ usfstl_vhost_user_get_virtq_buf(struct usfstl_vhost_user_dev_int *dev, } addr = virtio_to_cpu64(dev, desc->addr); - vec->iov_base = usfstl_vhost_user_to_va(&dev->ext, addr); + vec->iov_base = usfstl_vhost_phys_to_va(&dev->ext, addr); vec->iov_len = virtio_to_cpu32(dev, desc->len); desc = &virtq->desc[virtio_to_cpu16(dev, desc->next)]; @@ -836,7 +836,28 @@ void *usfstl_vhost_user_to_va(struct usfstl_vhost_user_dev *extdev, uint64_t add dev->regions[region].mmap_offset); } - USFSTL_ASSERT(0, "cannot translate address %"PRIx64"\n", addr); + USFSTL_ASSERT(0, "cannot translate user address %"PRIx64"\n", addr); + return NULL; +} + +void *usfstl_vhost_phys_to_va(struct usfstl_vhost_user_dev *extdev, uint64_t addr) +{ + struct usfstl_vhost_user_dev_int *dev; + unsigned int region; + + dev = container_of(extdev, struct usfstl_vhost_user_dev_int, ext); + + for (region = 0; region < dev->n_regions; region++) { + if (addr >= dev->regions[region].guest_phys_addr && + addr < dev->regions[region].guest_phys_addr + + dev->regions[region].size) + return (uint8_t *)dev->region_vaddr[region] + + (addr - + dev->regions[region].guest_phys_addr + + dev->regions[region].mmap_offset); + } + + USFSTL_ASSERT(0, "cannot translate physical address %"PRIx64"\n", addr); return NULL; } |