From patchwork Wed Sep 30 21:54:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11810319 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 72EDF112C for ; Wed, 30 Sep 2020 21:55:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 578802076B for ; Wed, 30 Sep 2020 21:55:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e98yVpzX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731337AbgI3VzZ (ORCPT ); Wed, 30 Sep 2020 17:55:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54670 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731149AbgI3Vyv (ORCPT ); Wed, 30 Sep 2020 17:54:51 -0400 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601502889; 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=e98yVpzXyQuneIiQ2CEML1gXuqnNmc6ZmsmksNOWg72rzdExon873lwjVaGDcbXTiDwNDE LSkE2BqsMJEXFfS5hFAcLQST53hD8zz/F/nWPKOlauM+RJ9Hla/C9vIJDj70dQ8F7pc+o6 1Q46dmVQBoBt1CmonOWV7n/Pt0Ke9wk= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-Kppw0q41PjSPr0kk5oMl0A-1; Wed, 30 Sep 2020 17:54:47 -0400 X-MC-Unique: Kppw0q41PjSPr0kk5oMl0A-1 Received: by mail-qk1-f200.google.com with SMTP id 196so1813085qkn.6 for ; Wed, 30 Sep 2020 14:54:47 -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=rTw0NvBHz6QNVxxa3gSk6r4y+3UeXl27n/mjYxUFeBjIfgjve/ancJbIsIV8MjFr2i X+WWMJTweTYQ9S9ejaaOclbcxUPQkBNFtQXHrojgw+KBw5++WQv6YYkx7F9UikB4ureQ vDg6TWwpGVdpcvy5lIBmjQl2BklNqJcjTsOb48y/NbsxqSqcfymhC3zlUOZWpJ46gcGo rKEeiQtOOB9jPGtcqcYKW8Cql0jykPaLQhcXUl2ecT4lh0hZLtetgBXZxswVPZIPMGky 1cMzlDuzXHoQi8ZAcb5S7B6av14c0QY4hEA4fN8vQkqbN+UpiFcYznkl+XcJLi2H4CnG abFA== X-Gm-Message-State: AOAM533zCM2yvSDoF5euSzFb6dIXyyN91eagjDWMvzmoKzt8VZxWYYi2 SYiMWieU3tiV1va3MtqY2SQ7N87ri/2BU9v3FVjMXkq67IDYgzujoAfwUkykF1jCxoPAdsPBM2h bgRQxh9kND2TC X-Received: by 2002:ad4:458f:: with SMTP id x15mr4778514qvu.33.1601502886786; Wed, 30 Sep 2020 14:54:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgo6UUSfCswBxGTrc/RqPjHglVK7rdsdmnMfHg/7YWGzhVDh1XzGwDbb9emTsQorHWifx9gA== X-Received: by 2002:ad4:458f:: with SMTP id x15mr4778501qvu.33.1601502886576; Wed, 30 Sep 2020 14:54:46 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp130-09-184-147-14-204.dsl.bell.ca. [184.147.14.204]) by smtp.gmail.com with ESMTPSA id 8sm3729293qkc.100.2020.09.30.14.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 14:54:45 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Jones , Sean Christopherson , Paolo Bonzini , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH v12 10/13] KVM: selftests: Introduce after_vcpu_run hook for dirty log test Date: Wed, 30 Sep 2020 17:54:44 -0400 Message-Id: <20200930215444.48247-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930214948.47225-1-peterx@redhat.com> References: <20200930214948.47225-1-peterx@redhat.com> MIME-Version: 1.0 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);