Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp825001ybt; Wed, 8 Jul 2020 12:38:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyin+Hdh6a+eTa4Lxfs8C0ZGoZOXCPPirGAv42x13hlkHqJ1VIGO+I9x1mspYoOzAf4858z X-Received: by 2002:aa7:d285:: with SMTP id w5mr40584931edq.174.1594237084207; Wed, 08 Jul 2020 12:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594237084; cv=none; d=google.com; s=arc-20160816; b=VU716arwVcd82wdY0A/BpgHhZTTxb1h3Lj/zW3JJrfbl5mgQ/ibzaCEbg2YpvLfexI lEzfeLnPzH5bSaL89Tq0cdpfuqBH6yPJemAVjMa1+Si4DiRXS3vTUM/YLx6NbkB7FgFK VpGZMNGoePvFttQSiDoi4sZBI0pTtR874AHgHIZWignXZVFmS8SOdTHX1b2F/odWSzIX SV8mqVriLKDjE69iGJ+FJSam0mI/gY7yByv0mrreRSVg3l15yH+0C0iw//tjplM6akfk jNybo3bDBU+pozM3DDB2m46l8NSoJ0Ok6LgsqWSRYLaE2cyceMOY1zLvRgR4MJL61UEq 7hqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Frsr00VTIsYjdqDeTzSRco7BaTYBstaIvbV6rdyHlg=; b=CZE3DGAgbs18s746r9K9cVbKgJhygO41zbjRniPwD0bpwIGgIAwV3euiIxrhFYBLYv YINNCO3UjXVcucvh/7tQsh486BkHuDUu7/MrAlCrCOCrHez+8mCNryVxlbkxATHWlE3H uLayBfOujQVSV9jadJC08vVNkJT9C3Sh2RQUZNvgYQeXYU+eGlsPS4gUQHzyspqS0uUB 2ZcfvLfADI9g7tbDE0l6+l4v7REweEu7JKkkAESyeCXuHMQ89RxkI0UHbBfdzTxQwp5u hobQDDhkvHuQCwOWc2CuVG5fKx6KVP6d9uj50a668CQZPjPOd3LTQMR+9yjGs/8zAw2U zn4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JQP3kVbB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y25si612324edm.63.2020.07.08.12.37.41; Wed, 08 Jul 2020 12:38:04 -0700 (PDT) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JQP3kVbB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbgGHTfB (ORCPT + 99 others); Wed, 8 Jul 2020 15:35:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21266 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726845AbgGHTec (ORCPT ); Wed, 8 Jul 2020 15:34:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594236871; 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=JQP3kVbBCsMNHp5r6QtA13veXWfGfDique/5XXzTNxa1Yz90gnmDbQ6EvMz40WyM9PTkB/ dal/ufeW3x0R3Mw1yY3mfQHBDxUQe38pfikRDXknfsRhptU/Bv2Q6z5Wfwn7qoBMTzXaEn NClDR3qLGFLrd0oHWo9UKWtKldxpDSg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-508-pzovjpSsOBqq_O5aaSHhxQ-1; Wed, 08 Jul 2020 15:34:29 -0400 X-MC-Unique: pzovjpSsOBqq_O5aaSHhxQ-1 Received: by mail-qk1-f198.google.com with SMTP id 13so16893867qks.11 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=tib4gOIeEnkmuuTjoQBq3IfQYCximWA7uDWP66KW2+76WWVNQC+kuRj9LsKsQ0Je+N CbcigAeRhqBjv7V8qK2Q29gOaK3XCVFv+TqKmLPTYAyOdmLVasK6g5NQnlpqCJUMHa5+ 7KICEJHhQGZ+ldRj59E/9xYJPtZOJkBDE/YM7eW2yPdqjxujo4Y9C/XumXq7ZvRyeD4c 8Rsh9W56PnF1EtYPWw6T66CyRCcs9OQ5nQ3+rNn4hV6v/xYVepx49F07l4WK+I+fwoFc 1LkzVp/nJc2vDKHGXRaGyLxMOato04Ckzen7EPwWxUVlMsTbMq3+nSgfSK3lMAMrkV49 O/LQ== X-Gm-Message-State: AOAM531NTg5QEoRKYH5bhJlDUQoQQFMMJ9Gq1mTMS45ZqxyOJw+ZZJ0A kC+xG3VQ17F6bDsfQr3j4ni4hY7Y35nNQzxqWWuPKfJRLN6xZWePTNYR9Y8xfEJYRZfMKqAezbU myMVH7RsDHu/g455ziMKZbHzW X-Received: by 2002:a05:6214:12c:: with SMTP id w12mr12785332qvs.78.1594236869167; Wed, 08 Jul 2020 12:34:29 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.26.2