Received: by 2002:a05:6a10:d593:0:0:0:0 with SMTP id gn19csp1200467pxb; Wed, 2 Dec 2020 13:08:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYK8eeuNZhEzlORxPWjDRyTF3EQNhOnGlRO3fmr886Q1CVcdpqskkSyo8xZZs7lTSkFmxl X-Received: by 2002:a05:6402:22ab:: with SMTP id cx11mr1858666edb.98.1606943332920; Wed, 02 Dec 2020 13:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606943332; cv=none; d=google.com; s=arc-20160816; b=JrBVfKJOgV8VWibrDRDSdJlg8VYCSFd1e8g1JU3HJo9GnII+zZpuqZ8RNDJwGtS7pJ glYhxJC98g/k50Nbk20fyhPY07sjVSXMpt/ZqSIE8CRjpLUbi17z49chrxJ3CioJNFw9 19ojvy9o6c79StCF1Y5fX/w6gZB+HpSof+RSfw+T2m7ryH/yZYSl1orh9vjq+3DKY7FG ItGk3BncJ7Y5cIFKCMCFjGDkThbmmctHJhpzjMhvFy2+1kSZ8G6Z91hm+nkcNk5bqGcR X+kpATb93YJlKHLGWSUMqhdqqvn2qFF79fP2D+iJBvWkN9upThpBSHX/PazHYfhaStPi Bkag== 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 :message-id:date:subject:cc:to:from; bh=xpf37xVCx1UcL6tHWvvFWKdRC3vOXVOu9cAIMYjwB0g=; b=szGfsNP1mIfLggdtpDGTXORJ2+vr138c3oBpLZmMMucbBvOlzIskTAM2pRppOiMByt uZdUtGsDd+BwWYk+/GCzsp/5jFMdgZ64cZHe/2btWOnYlkbaGOgnJW16I0OHFQyA74rQ eYldtWq7oa8UaKQQD/bqxnSqeTzpWy6uTlrmkMY3/5gz2pOBlSwHrdCQVgQacMvZ+9MT 8h8tGW8idKwBarnEEZk3/ghgg1/NQmfxusfK0lMfNS7BWOzq9VdCAcWyO705HdrA4x5H 15fjO1n+5sJt4D+eegQ7UoPLHXlIKhKfJYLr0VVIuj/gl1hLVJ/TyQg11/iFBOT78w2D /opg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si631475ejj.398.2020.12.02.13.08.27; Wed, 02 Dec 2020 13:08:52 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387665AbgLBVEW (ORCPT + 99 others); Wed, 2 Dec 2020 16:04:22 -0500 Received: from vps-vb.mhejs.net ([37.28.154.113]:44310 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbgLBVEW (ORCPT ); Wed, 2 Dec 2020 16:04:22 -0500 X-Greylist: delayed 1671 seconds by postgrey-1.27 at vger.kernel.org; Wed, 02 Dec 2020 16:04:20 EST Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.93.0.4) (envelope-from ) id 1kkYqj-0004aI-SE; Wed, 02 Dec 2020 21:35:41 +0100 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Shuah Khan Cc: Sean Christopherson , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests: kvm/set_memory_region_test: Fix race in move region test Date: Wed, 2 Dec 2020 21:35:36 +0100 Message-Id: <0fdddb94bb0e31b7da129a809a308d91c10c0b5e.1606941224.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Maciej S. Szmigiero" The current memory region move test correctly handles the situation that the second (realigning) memslot move operation would temporarily trigger MMIO until it completes, however it does not handle the case in which the first (misaligning) move operation does this, too. This results in false test assertions in case it does so. Fix this by handling temporary MMIO from the first memslot move operation in the test guest code, too. Fixes: 8a0639fe9201 ("KVM: sefltests: Add explicit synchronization to move mem region test") Signed-off-by: Maciej S. Szmigiero --- The race is pretty hard to trigger on the current KVM memslot code, to trigger it reliably an extra delay in memslot move op is needed: --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1173,7 +1173,7 @@ static struct kvm_memslots *kvm_dup_memslots(struct kvm_memslots *old, return slots; } - +#include static int kvm_set_memslot(struct kvm *kvm, const struct kvm_userspace_memory_region *mem, struct kvm_memory_slot *old, @@ -1212,6 +1212,8 @@ static int kvm_set_memslot(struct kvm *kvm, * - kvm_is_visible_gfn (mmu_check_root) */ kvm_arch_flush_shadow_memslot(kvm, slot); + + if (change == KVM_MR_MOVE) mdelay(100); } r = kvm_arch_prepare_memory_region(kvm, new, mem, change); .../selftests/kvm/set_memory_region_test.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index b3ece55a2da6..6f441dd9f33c 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -156,14 +156,23 @@ static void guest_code_move_memory_region(void) GUEST_SYNC(0); /* - * Spin until the memory region is moved to a misaligned address. This - * may or may not trigger MMIO, as the window where the memslot is - * invalid is quite small. + * Spin until the memory region starts getting moved to a + * misaligned address. + * Every region move may or may not trigger MMIO, as the + * window where the memslot is invalid is usually quite small. */ val = guest_spin_on_val(0); GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val); - /* Spin until the memory region is realigned. */ + /* Spin until the misaligning memory region move completes. */ + val = guest_spin_on_val(MMIO_VAL); + GUEST_ASSERT_1(val == 1 || val == 0, val); + + /* Spin until the memory region starts to get re-aligned. */ + val = guest_spin_on_val(0); + GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val); + + /* Spin until the re-aligning memory region move completes. */ val = guest_spin_on_val(MMIO_VAL); GUEST_ASSERT_1(val == 1, val);