From patchwork Wed Jul 8 19:34:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11652355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FFE36C1 for ; Wed, 8 Jul 2020 19:34:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E83442078D for ; Wed, 8 Jul 2020 19:34:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dImlm/c7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726187AbgGHTel (ORCPT ); Wed, 8 Jul 2020 15:34:41 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:60526 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726865AbgGHTeg (ORCPT ); Wed, 8 Jul 2020 15:34:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594236874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Frsr00VTIsYjdqDeTzSRco7BaTYBstaIvbV6rdyHlg=; b=dImlm/c7X00gIALsHn4kcOFmZcin47USVGFdbP1WWV1gu6VagNyZgWhq4iKGsCF4W4WiKf 12nqy+WjppPjnzX+w8QuyLLFqqBj3UvYKH3cF8h8TATvxOQOA5jMrRaKjpIDwMMmrJpjxb QnqAReFPw1wK2QuQeremrvbCdrsW1bs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-2AOmoCbbO7e8eTLXdvK6Gg-1; Wed, 08 Jul 2020 15:34:30 -0400 X-MC-Unique: 2AOmoCbbO7e8eTLXdvK6Gg-1 Received: by mail-qk1-f199.google.com with SMTP id 204so31715557qki.20 for ; Wed, 08 Jul 2020 12:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1Frsr00VTIsYjdqDeTzSRco7BaTYBstaIvbV6rdyHlg=; b=nyltqgpGOjQSPaLaSN3APjJmU/s3EE2l1BV4t8GXlKaR5BJsqxaKMRvFML/KhSG4cU VModW3fTga/l6OFJJtA4bbbss577OC/OKXIOu6g8BTDMGndNvKCStgGSGUECncMSD88f +vsOGTqEF5whM3aDac2EW9SfxzNDO24gbWEJJz84vp450zO0o4dI5uR6VqKBEZSrUQmD bcXALhupL7mzz/YVVlZGnzY9cjmc7nLCfsrYcuQ3QFpjle60H7U+QucaWe6ZSxHzbRgR y2C/hjAzc1UWKRtDqg9R+Nth+KTDRFfbW/+fpvbr1yaMLN1Ds82+UiPlDYbQRGnkBf/M 62+w== X-Gm-Message-State: AOAM5310tYBOIho3QPMZ2gn9Y7gDG7W2gBRSSaMq6dOlt8xHp0K2ckRw iSm/Z2esxDXYROgX4nZfTb4of2rpcBB9N7PIdUZzluzUeQWqVasuXR0TKSbWGmVPP8alj34aRl5 j4tTUaTrSCPB8 X-Received: by 2002:a05:6214:12c:: with SMTP id w12mr12785336qvs.78.1594236869174; Wed, 08 Jul 2020 12:34:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhhogDlEob2FtS8KDhjvuCX9hbkX64dztP+mMW9Xu5ZFyStLlHU0ETMPRqGMDCdqiDAPAv0Q== X-Received: by 2002:a05:6214:12c:: with SMTP id w12mr12785311qvs.78.1594236868931; Wed, 08 Jul 2020 12:34:28 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c8:6f::1f4f]) by smtp.gmail.com with ESMTPSA id f18sm664884qtc.28.2020.07.08.12.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 12:34:28 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Sean Christopherson , "Dr . David Alan Gilbert" , Andrew Jones , Paolo Bonzini Subject: [PATCH v11 10/13] KVM: selftests: Introduce after_vcpu_run hook for dirty log test Date: Wed, 8 Jul 2020 15:34:05 -0400 Message-Id: <20200708193408.242909-11-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200708193408.242909-1-peterx@redhat.com> References: <20200708193408.242909-1-peterx@redhat.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Provide a hook for the checks after vcpu_run() completes. Preparation for the dirty ring test because we'll need to take care of another exit reason. Reviewed-by: Andrew Jones Signed-off-by: Peter Xu --- tools/testing/selftests/kvm/dirty_log_test.c | 36 +++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 139ccb550618..a2160946bcf5 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -178,6 +178,15 @@ static void clear_log_collect_dirty_pages(struct kvm_vm *vm, int slot, kvm_vm_clear_dirty_log(vm, slot, bitmap, 0, num_pages); } +static void default_after_vcpu_run(struct kvm_vm *vm) +{ + struct kvm_run *run = vcpu_state(vm, VCPU_ID); + + TEST_ASSERT(get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC, + "Invalid guest sync status: exit_reason=%s\n", + exit_reason_str(run->exit_reason)); +} + struct log_mode { const char *name; /* Return true if this mode is supported, otherwise false */ @@ -187,16 +196,20 @@ struct log_mode { /* Hook to collect the dirty pages into the bitmap provided */ void (*collect_dirty_pages) (struct kvm_vm *vm, int slot, void *bitmap, uint32_t num_pages); + /* Hook to call when after each vcpu run */ + void (*after_vcpu_run)(struct kvm_vm *vm); } log_modes[LOG_MODE_NUM] = { { .name = "dirty-log", .collect_dirty_pages = dirty_log_collect_dirty_pages, + .after_vcpu_run = default_after_vcpu_run, }, { .name = "clear-log", .supported = clear_log_supported, .create_vm_done = clear_log_create_vm_done, .collect_dirty_pages = clear_log_collect_dirty_pages, + .after_vcpu_run = default_after_vcpu_run, }, }; @@ -247,6 +260,14 @@ static void log_mode_collect_dirty_pages(struct kvm_vm *vm, int slot, mode->collect_dirty_pages(vm, slot, bitmap, num_pages); } +static void log_mode_after_vcpu_run(struct kvm_vm *vm) +{ + struct log_mode *mode = &log_modes[host_log_mode]; + + if (mode->after_vcpu_run) + mode->after_vcpu_run(vm); +} + static void generate_random_array(uint64_t *guest_array, uint64_t size) { uint64_t i; @@ -261,25 +282,16 @@ static void *vcpu_worker(void *data) struct kvm_vm *vm = data; uint64_t *guest_array; uint64_t pages_count = 0; - struct kvm_run *run; - - run = vcpu_state(vm, VCPU_ID); guest_array = addr_gva2hva(vm, (vm_vaddr_t)random_array); - generate_random_array(guest_array, TEST_PAGES_PER_LOOP); while (!READ_ONCE(host_quit)) { + generate_random_array(guest_array, TEST_PAGES_PER_LOOP); + pages_count += TEST_PAGES_PER_LOOP; /* Let the guest dirty the random pages */ ret = _vcpu_run(vm, VCPU_ID); TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret); - if (get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC) { - pages_count += TEST_PAGES_PER_LOOP; - generate_random_array(guest_array, TEST_PAGES_PER_LOOP); - } else { - TEST_FAIL("Invalid guest sync status: " - "exit_reason=%s\n", - exit_reason_str(run->exit_reason)); - } + log_mode_after_vcpu_run(vm); } pr_info("Dirtied %"PRIu64" pages\n", pages_count);