Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5479534pxj; Wed, 23 Jun 2021 02:04:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1BhXnRIRGISETdLUOP+GkCO1fKLAFHwoJI1XIPFr7qffQGKuBonfbo1p9zocIojVxfkjg X-Received: by 2002:a05:6602:2001:: with SMTP id y1mr6316533iod.181.1624439053919; Wed, 23 Jun 2021 02:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624439053; cv=none; d=google.com; s=arc-20160816; b=YT28efcIL8t8FU5PbT/nb0SmDEZvgPl01dr6CCFkMqeWk2PEZcbb+3+TqZYeo7sP8j wtZxnHmr30BHhUj5c3rwada2lWFt7swmVHh9L6wtv13/rQSYZVavI2xM2Oe4dxkOoOzI nE246gpJLmm/2Bmv1uj5D55rC610v4Kl7gz4E46yq7kJ/+5oZM4L2tXygJhHwEANz9Rs wRRvKfb9f057i8j+Y6E3WcrhSe5X5/SGM7EebMOXR0ZmqkGHeMeENKmlpGQ4/ivNNCmt obLR9zT+1T5U87R1jxYjQBV+HHmoa9kQjaZsfs7BFnWSUyCpQXA9MxBnc6BQn29Ew7tr WdaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=AbZo0y92aFn1cZtrKVqHcde9LjFqERJM6DS1hjFZl/g=; b=AnBSXscbqxUpDjAc3a3M8ygUvbQhm2tvDdJrigGoTQpb/TEQ1k3Zl2epNgMn+tVkun wThV/HdoU3igYNZL/U4guACssdcuSCww9ougXcu90vkuq15cxGE6v6DKBr+d3KrjbCms aZfzQ7AInkEz5TrW/uBFZo4xikUQotl469IMXFW5X52gREomFSyuvcMbtCK117mooXz7 oc6zMhnMJ02yHiLdQYGAZQF/9TF3DqUrYpwCnh+CK299+mCnb3h+jBM4liLUvfFEzuRY vFEOt+/Xtf8KhhURouKSGYcVvHprhWhTzE5SIOVBxvefFQyNXm1CiL1PSvDlFgsqNlMM C3NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si19464640ilq.92.2021.06.23.02.04.01; Wed, 23 Jun 2021 02:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbhFWJFr (ORCPT + 99 others); Wed, 23 Jun 2021 05:05:47 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:8313 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbhFWJFq (ORCPT ); Wed, 23 Jun 2021 05:05:46 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4G8xyw54PYz71gv; Wed, 23 Jun 2021 16:59:20 +0800 (CST) Received: from dggema764-chm.china.huawei.com (10.1.198.206) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Wed, 23 Jun 2021 17:03:27 +0800 Received: from [10.174.185.179] (10.174.185.179) by dggema764-chm.china.huawei.com (10.1.198.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 23 Jun 2021 17:03:26 +0800 Subject: Re: [PATCH] KVM: selftests: Speed up set_memory_region_test To: Vitaly Kuznetsov CC: , Paolo Bonzini , "Sean Christopherson" , Wanpeng Li , "Jim Mattson" , kernel test robot , , References: <20210426130121.758229-1-vkuznets@redhat.com> From: Zenghui Yu Message-ID: <91a2d145-fd3c-6e8d-6478-60f62dff07fe@huawei.com> Date: Wed, 23 Jun 2021 17:03:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20210426130121.758229-1-vkuznets@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.185.179] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggema764-chm.china.huawei.com (10.1.198.206) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Vitaly Kuznetsov 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. Thanks, Zenghui