From patchwork Fri Oct 23 18:33:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11854391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67C40C55178 for ; Fri, 23 Oct 2020 18:35:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 161112464E for ; Fri, 23 Oct 2020 18:35:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gSw866OF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755013AbgJWSfM (ORCPT ); Fri, 23 Oct 2020 14:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43884 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754911AbgJWSe1 (ORCPT ); Fri, 23 Oct 2020 14:34:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603478065; 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=gSw866OFRFAjdk1qPqJwGGuFw0LGP0gqXbXImiMhQ8dlDNYWxxxIODZD0hqBESJg6ualwD TOI7+SN6xu8kSCaGKNSkJwcrQ2qT1sc1+Ac7IhoiGReBhwVEKjhwrnBje/PPUGcXXN0dGe GF9PWuRpMap+kqkHy/f01kbDC9lAPEc= 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-173-6XCw4TKEM2yue6KB4yEjeQ-1; Fri, 23 Oct 2020 14:34:24 -0400 X-MC-Unique: 6XCw4TKEM2yue6KB4yEjeQ-1 Received: by mail-qk1-f200.google.com with SMTP id a81so1620789qkg.10 for ; Fri, 23 Oct 2020 11:34:24 -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=EHoCnFIWqgeM9HiODEZRs8kol+PgyPUKNW+gmozypaoJvWGemeS6ES0e85DYLU6v3i ar36KEEq6jtFszfoYXt3qfszmSrS//nV+6YsLzSHzcBAYzOfQCBURbqQE64gHVzXnndw XTJ421nJsiNOo2RFt55szlkJAW31c53AyrqZ+vtJSpaYZPSdkhu+fylSTSWkeTHkPFPF hzuM7Kjv7fRyQD/2pl4+jPRuRgJPaundaCiIHOKotWKEe6p3FzeSP92Hy7JS4hxKaXau bUVOwwRqRmW/wiJ4gCV+0Inwrq06tzbsfyOp+BFk0gAHD4h2PtWeEI3S2oPTJanUZtJn Vmbw== X-Gm-Message-State: AOAM532lGdhV7tC3YotF1UyJsqrQXvvgjPZ8jRGW7xR6EkJ9Q6k+TvSO ebN+qco47cvlsDF6pU+DdZL0rzn8PFnfJgSyaf5uda8H5mw/0od6lnyHKrwO69etMStaRXPdOOf aoUTs3EpqYVEK X-Received: by 2002:a0c:a046:: with SMTP id b64mr355645qva.55.1603478063249; Fri, 23 Oct 2020 11:34:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOYTeZ0ac3uGzRsmzmGfUqoKhn3pSnvG8Kmi4QqfMXryXBKDUJGYNAxSV7Vo6420pD0yg2aA== X-Received: by 2002:a0c:a046:: with SMTP id b64mr355628qva.55.1603478063023; Fri, 23 Oct 2020 11:34:23 -0700 (PDT) Received: from xz-x1.redhat.com (toroon474qw-lp140-04-174-95-215-133.dsl.bell.ca. [174.95.215.133]) by smtp.gmail.com with ESMTPSA id u11sm1490407qtk.61.2020.10.23.11.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 11:34:22 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , peterx@redhat.com, Andrew Jones , "Dr . David Alan Gilbert" , Paolo Bonzini Subject: [PATCH v15 11/14] KVM: selftests: Introduce after_vcpu_run hook for dirty log test Date: Fri, 23 Oct 2020 14:33:55 -0400 Message-Id: <20201023183358.50607-12-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201023183358.50607-1-peterx@redhat.com> References: <20201023183358.50607-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);