The default attributes for guest_memfd pages without in-place conversion
is private. However, the ucall pages need to be shared between the host
and the guest. Thus, set them as shared.

Signed-off-by: Lisa Wang <[email protected]>
---
 tools/testing/selftests/kvm/lib/ucall_common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c 
b/tools/testing/selftests/kvm/lib/ucall_common.c
index 029ce21f9f2f..c03dfc763172 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -27,6 +27,7 @@ static struct ucall_header *ucall_pool;
 
 void ucall_init(struct kvm_vm *vm, gpa_t mmio_gpa)
 {
+       struct userspace_mem_region *region;
        struct ucall_header *hdr;
        struct ucall *uc;
        gva_t gva;
@@ -37,6 +38,13 @@ void ucall_init(struct kvm_vm *vm, gpa_t mmio_gpa)
        hdr = (struct ucall_header *)addr_gva2hva(vm, gva);
        memset(hdr, 0, sizeof(*hdr));
 
+       region = vm_get_mem_region(vm, MEM_REGION_DATA);
+       if (region->region.flags & KVM_MEM_GUEST_MEMFD) {
+               size_t aligned_sz = align_up(sizeof(*hdr), vm->page_size);
+
+               vm_mem_set_shared(vm, addr_gva2gpa(vm, gva), aligned_sz);
+       }
+
        for (i = 0; i < KVM_MAX_VCPUS; ++i) {
                uc = &hdr->ucalls[i];
                uc->hva = uc;

-- 
2.56.0.rc1.315.gc6ed9934b7-goog


Reply via email to