From: Paolo Bonzini <pbonzini@redhat.com>
To: Zenghui Yu <yuzenghui@huawei.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
kernel test robot <oliver.sang@intel.com>,
linux-kernel@vger.kernel.org, wanghaibin.wang@huawei.com
Subject: Re: [PATCH] KVM: selftests: Speed up set_memory_region_test
Date: Wed, 23 Jun 2021 23:45:30 +0200 [thread overview]
Message-ID: <3dc9bd69-f38a-daed-4ac3-84b280ef5901@redhat.com> (raw)
In-Reply-To: <91a2d145-fd3c-6e8d-6478-60f62dff07fe@huawei.com>
On 23/06/21 11:03, Zenghui Yu wrote:
> On 2021/4/26 21:01, Vitaly Kuznetsov wrote:
>> After commit 4fc096a99e01 ("KVM: Raise the maximum number of user
>> memslots")
>> set_memory_region_test may take too long, reports are that the default
>> timeout value we have (120s) may not be enough even on a physical host.
>>
>> Speed things up a bit by throwing away vm_userspace_mem_region_add()
>> usage
>> from test_add_max_memory_regions(), we don't really need to do the
>> majority
>> of the stuff it does for the sake of this test.
>>
>> On my AMD EPYC 7401P, # time ./set_memory_region_test
>> pre-patch:
>> Testing KVM_RUN with zero added memory regions
>> Allowed number of memory slots: 32764
>> Adding slots 0..32763, each memory region with 2048K size
>> Testing MOVE of in-use region, 10 loops
>> Testing DELETE of in-use region, 10 loops
>>
>> real 0m44.917s
>> user 0m7.416s
>> sys 0m34.601s
>>
>> post-patch:
>> Testing KVM_RUN with zero added memory regions
>> Allowed number of memory slots: 32764
>> Adding slots 0..32763, each memory region with 2048K size
>> Testing MOVE of in-use region, 10 loops
>> Testing DELETE of in-use region, 10 loops
>>
>> real 0m20.714s
>> user 0m0.109s
>> sys 0m18.359s
>>
>> Reported-by: kernel test robot <oliver.sang@intel.com>
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>
> I've seen the failure on my arm64 server, # ./set_memory_region_test
>
> Allowed number of memory slots: 32767
> Adding slots 0..32766, each memory region with 2048K size
> ==== Test Assertion Failure ====
> set_memory_region_test.c:391: ret == 0
> pid=42696 tid=42696 errno=22 - Invalid argument
> 1 0x00000000004015a7: test_add_max_memory_regions at
> set_memory_region_test.c:389
> 2 (inlined by) main at set_memory_region_test.c:426
> 3 0x0000ffffb7c63bdf: ?? ??:0
> 4 0x00000000004016db: _start at :?
> KVM_SET_USER_MEMORY_REGION IOCTL failed,
> rc: -1 errno: 22 slot: 2624
>
>> + mem = mmap(NULL, MEM_REGION_SIZE * max_mem_slots + alignment,
>
> The problem is that max_mem_slots is declared as uint32_t, the result
> of (MEM_REGION_SIZE * max_mem_slots) is unexpectedly truncated to be
> 0xffe00000.
>
>> + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>> + TEST_ASSERT(mem != MAP_FAILED, "Failed to mmap() host");
>> + mem_aligned = (void *)(((size_t) mem + alignment - 1) &
>> ~(alignment - 1));
>> +
>> for (slot = 0; slot < max_mem_slots; slot++) {
>> - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
>> - guest_addr, slot, mem_reg_npages,
>> - 0);
>> - guest_addr += MEM_REGION_SIZE;
>> + ret = test_memory_region_add(vm, mem_aligned +
>> + ((uint64_t)slot * MEM_REGION_SIZE),
>
> These unmapped VAs got caught by access_ok() checker in
> __kvm_set_memory_region() as they happen to go beyond the task's
> address space on arm64. Casting max_mem_slots to size_t in both
> mmap() and munmap() fixes the issue for me.
Can you provide a patch for both?
Paolo
next prev parent reply other threads:[~2021-06-23 21:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-26 13:01 Vitaly Kuznetsov
2021-06-23 9:03 ` Zenghui Yu
2021-06-23 21:45 ` Paolo Bonzini [this message]
2021-06-24 7:18 ` Zenghui Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3dc9bd69-f38a-daed-4ac3-84b280ef5901@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.sang@intel.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanghaibin.wang@huawei.com \
--cc=wanpengli@tencent.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®