Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2369200rdb; Tue, 10 Oct 2023 01:37:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEo06fbEqAWKJrvoGpO1WcmhHXJdOgTdGmzkMVFfPe5T7tKJA6dw6ztw8P41nvT6g51HBU X-Received: by 2002:a17:90a:6603:b0:27c:eedb:384d with SMTP id l3-20020a17090a660300b0027ceedb384dmr687814pjj.28.1696927033483; Tue, 10 Oct 2023 01:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696927033; cv=none; d=google.com; s=arc-20160816; b=bCSpm/rfQx/F8L1ISBLOSsJ/NpxHg6+UoBWiLeFXgY1VziEa7d/rufhDgyyOOlWAlE AP7NQnKjrmcmcbqDpKsIYyry6b9SBcA5we5h/TNgn1kRTt5JOdY97xlJaYxU/SDNgfxX dyBkay6S6odat0XrEAVVpL5Y48rItOQNiOLCVNk1lCjxPDtteiy5JKCDmbYakvUsy1Pw mrifOB4jBPbQcqHLBKU+Ksk5lZEZ6XTDTd8ZqjugU0j9/jN+owXQlyDtQK+xViPxW424 F2FZUWuoty/tEv0AE/T3Voj1eE05NrkqQpnq3bQr5ozhcrWJ2pKB8+3+8LvcotDyalC7 E9Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=33IVhesigJcuejGpVEe8pyt0awTQnWIBNLKO2ksZp8c=; fh=qpQuS5DB8/tFQfmdgX1i3QvppRzkrzhfKx2/rzpwOaE=; b=SYONmwpsKs8KMMo4ssl8BO9RjmZY7KGrLHhY80hlijBbIZ9w2XegpDgC3onRtDRana 5+WTsegvBU9ifRuQqbJ0E4NYLv5MOyHOILw7fBFEm9Q/Cnxk9lHa/HjrIG9X6m+3OADw Ag8uyOd6iKZ519Elbd5JyyDaugPh1HQFoDsnGceoDTAd5TnZEiO16piB4KdeDALXPr83 ET1U0C4yhhiRcl9Dv9OqYQ58N8W3ZEihLZe+5XsmQkwdOGUiw4fUxx9ncCYF93EJhI7s tqaH1ZAmHEQEc7oxVKR+8QawLoh6DoIx2MvpjResQwxHzEcI88MBFCmNPz56CaTCiEQx mGPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bXtY4xmI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ot8-20020a17090b3b4800b0026b71fdd505si12576659pjb.177.2023.10.10.01.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:37:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bXtY4xmI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E53BD80220E9; Tue, 10 Oct 2023 01:37:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442990AbjJJIgl (ORCPT + 99 others); Tue, 10 Oct 2023 04:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442929AbjJJIfl (ORCPT ); Tue, 10 Oct 2023 04:35:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB9EBB0; Tue, 10 Oct 2023 01:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696926939; x=1728462939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GQCMPF9yOreHoZSYiAwwtuGF3KN8BZQ7hfFsQ7RV6BI=; b=bXtY4xmIXZHQOZCQV0x2TwrkFm/HEB+plRFOae2y9eARWcxiVOO0SfaR y/cYrF9IniF9MAlZCC5JXVjdVLDTIXz5D1Eczc9RoO40AtJPmBKmSIA7w m0wyW6acZta3qV5+gCM0Ycg1K3AmqTezHn4effwEmr2JCEuuE+Rixqsel hLnyBUEXyo5OCGI0dHMHMVEpAw2D5uMHMRZWLKu9eNDEtzom++6R4oFDz zTAsUQxDp6mSnl5L+AFZRnREXpWKNGDJorcEmjh9JFEmSXxrnJSWbG+FD NRIQT4Nb+8hyhQh1CWpMlOHXoB+mZa94wR7JUUNajY1YA64EFv7N+KYNz w==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="363689842" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="363689842" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:35:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="1084687206" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="1084687206" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:35:35 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , Sean Christopherson , linux-coco@lists.linux.dev, Chao Peng Subject: [PATCH 10/12] KVM: selftests: Allow mapping guest memory without host alias Date: Tue, 10 Oct 2023 01:35:18 -0700 Message-Id: <9e970731a61711acd38b1819ab5d2eaf326e0f0f.1696926843.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 10 Oct 2023 01:37:09 -0700 (PDT) X-Spam-Level: ** From: Isaku Yamahata For test the KVM hwpoison of memory, the recovery path unmaps the virtual memory and send SIGBUS with its address. If the poisoned page is mapped at twice or more in the virtual memory, the address in SIGBUS siginfo isn't deterministic. To make the hwpoison test cases deterministic, allow to avoid guest memory alias. Signed-off-by: Isaku Yamahata --- .../selftests/kvm/include/kvm_util_base.h | 4 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 23 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index a18db6a7b3cf..e980776a2c94 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -435,6 +435,10 @@ void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, uint64_t gpa, uint64_t size, void *hva); int __vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, uint64_t gpa, uint64_t size, void *hva); +void __vm_userspace_mem_region_add(struct kvm_vm *vm, + enum vm_mem_backing_src_type src_type, + uint64_t guest_paddr, uint32_t slot, uint64_t npages, + uint32_t flags, bool alias); void vm_userspace_mem_region_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 7a8af1821f5d..310c3a760cb8 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -691,12 +691,14 @@ static void __vm_mem_region_delete(struct kvm_vm *vm, sparsebit_free(®ion->unused_phy_pages); ret = munmap(region->mmap_start, region->mmap_size); TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("munmap()", ret)); - if (region->fd >= 0) { - /* There's an extra map when using shared memory. */ + + /* There's an extra map when using shared memory. */ + if (region->mmap_alias) { ret = munmap(region->mmap_alias, region->mmap_size); TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("munmap()", ret)); - close(region->fd); } + if (region->fd >= 0) + close(region->fd); free(region); } @@ -920,10 +922,10 @@ void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, * given by slot, which must be unique and < KVM_MEM_SLOTS_NUM. The * region is created with the flags given by flags. */ -void vm_userspace_mem_region_add(struct kvm_vm *vm, +void __vm_userspace_mem_region_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages, - uint32_t flags) + uint32_t flags, bool create_alias) { int ret; struct userspace_mem_region *region; @@ -1057,7 +1059,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, hash_add(vm->regions.slot_hash, ®ion->slot_node, slot); /* If shared memory, create an alias. */ - if (region->fd >= 0) { + if (region->fd >= 0 && create_alias) { region->mmap_alias = mmap(NULL, region->mmap_size, PROT_READ | PROT_WRITE, vm_mem_backing_src_alias(src_type)->flag, @@ -1070,6 +1072,15 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, } } +void vm_userspace_mem_region_add(struct kvm_vm *vm, + enum vm_mem_backing_src_type src_type, + uint64_t guest_paddr, uint32_t slot, uint64_t npages, + uint32_t flags) +{ + __vm_userspace_mem_region_add(vm, src_type, guest_paddr, slot, npages, + flags, true); +} + /* * Memslot to region * -- 2.25.1