From patchwork Fri Apr 21 16:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1217389vqo; Fri, 21 Apr 2023 10:07:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YUxmjz+Pwh8u0+7fKKq+RyhU0TmFzxgL0dkx4nZkd8seoLTGZtSg+0tVTNEs1dhIBfPgFs X-Received: by 2002:a5e:9806:0:b0:762:7e58:8d38 with SMTP id s6-20020a5e9806000000b007627e588d38mr3753867ioj.10.1682096839889; Fri, 21 Apr 2023 10:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096839; cv=none; d=google.com; s=arc-20160816; b=iE3Tc3s+Nma4hMjnkfkGJet4r9DVEdfE4hnbr8o/M1tomnabdlW8F+8s7OIJcOnUo0 l86Nh9cJUdlTAeKqxaHKT9fQuWvgchj1wzjgvJJEGpiXG5LS1dL0yG3f2rByuQb/i6EJ e46kSVkODm/Ci6ae/ooHHyakYi66H78QcYlaooxyBPm2clAAI7g+XTqdEpHy8+7qoKEA IHgvR3x+gjzciB5UlL0naahGxqmsY9e02wIGvsLhS/tRWCAVoMTHQLJPjE2kKEzl4daP 2nUgmThV/jQn9U8Khegp/ADbBHNMGpQjEouK+J2JEV3DRYvniJHqh7WHSaODG0oi9dD4 L8yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=XgxikP+X3kYGOAuFnf+zh/dPS0rwAngpLKDcQUsUAcM=; b=SicGtWvV56+r2BZT3kDNS5CWO9avCH8M+mE7x3geBkyab8H85i0AYDQjkIdP5nfiHd fYp7L+b/XzRio18wxYhaNlyHH0OwkDpFERNQQipQBflY2O4AaE3p8hdvyELODMgx07MG pV9hBwbRikM7joYDqfRbAQcxcaQUO8b7kSOgcJtKh78IjiBtlXFrtYG9uTCNLmLPWAyQ uT1LqqfeJFqnTyzRoyyLqnGkSZ3ucI0Kob97R7VWVsEe6UVu7hpDddQgIVXAXjJ254Ay KJ98r1jBv9MoOqkwntqvGf0CXNxdv7wxWZx6PTVMYadl8enxP3dtGjjIXyp93gFAgR8r dIQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=frqfkYHi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a26-20020a027a1a000000b00408bc066274si3732005jac.43.2023.04.21.10.07.05; Fri, 21 Apr 2023 10:07:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=frqfkYHi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbjDURB2 (ORCPT + 99 others); Fri, 21 Apr 2023 13:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233186AbjDURBZ (ORCPT ); Fri, 21 Apr 2023 13:01:25 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D7E19A1 for ; Fri, 21 Apr 2023 10:00:53 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id af79cd13be357-74e0b7fe88eso288457485a.2 for ; Fri, 21 Apr 2023 10:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096444; x=1684688444; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XgxikP+X3kYGOAuFnf+zh/dPS0rwAngpLKDcQUsUAcM=; b=frqfkYHiWLwSQFqHz31EJ135syidE4qVtbOc6iEOZ/iEYUWysic2idqtZdbke1Ui0y aWPZMtbw+3T+6wTEHQWesDvOOl5IePj/Bwr/U+x5YeiO5LLmBXNto12w6yAsiE8d0wHY LRkkZEdrooFcrDdv5Tgby3JXvm7M0ZnXA2Nw0v54LJ/2dxOisTC46fxx06Hg4eEMsUK9 epWe7sSsK87KebYDRcaYbnG7cnacFq1tKGINEO6b9q7TXjjVdRZEhO9Q4pt5IK3He5TQ A6HaEMEdCi+da+qq+Oo1JJn8m25ZL3cHxPEZVN5G2kCBODtz3uYr/oiuZRcwfMGWIDnh dGnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096444; x=1684688444; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XgxikP+X3kYGOAuFnf+zh/dPS0rwAngpLKDcQUsUAcM=; b=j2BKoHEua67wXp8GRRhGseIRPcsKBiZOkZObrtBXd2BGC9Q/gjaQTITajJSuIbn62Z t4UjPb8hGzCbVj7R9INpiWNgf4Hz1r4JqCc3ux91frAWDIjOuXDd0Nemsm8wos1b4N4Q gBiCgNP+WgQHSIEMY1udefwRAhabyKAku5Bwa9YfY9e4qE2vSeNQ1+tlrPPLmcMDZbEu FAVXOWsadpf2Ft0ue0HjEPFqKb7z2LAei3NqOfyNLGHYQwJNL74ljfymoJN/68tFWp8B aZ3FnfpkT/YPDSJn+adEBD3+3VftfA7Xf+sCJQT3j0KPFxe7LK1PuF86Y14I4s7HeZ9T GmVg== X-Gm-Message-State: AAQBX9emlCXdwo9Hm6iof05HslnNGdOsZN6HCTelxovVSEYzAw9M8lQb j2MU1c8em1rKyRFXJFcrMUls3efxyFlx X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a63:f54b:0:b0:520:e728:8894 with SMTP id e11-20020a63f54b000000b00520e7288894mr1352406pgk.5.1682095990900; Fri, 21 Apr 2023 09:53:10 -0700 (PDT) Date: Fri, 21 Apr 2023 09:52:57 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-2-vipinsh@google.com> Subject: [PATCH 1/9] KVM: selftests: Allow dirty_log_perf_test to clear dirty memory in chunks From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763806375837562839?= X-GMAIL-MSGID: =?utf-8?q?1763806375837562839?= In dirty_log_perf_test, provide option 'k' to specify the size of the chunks and clear dirty memory in chunks in each iteration. If this option is not provided then fallback to old way of clearing whole memslot in one call per iteration. In production environment whole memslot is rarely cleared in a single call, instead clearing operation is split across multiple calls to reduce time between clearing and sending memory to a remote host. This change mimics the production usecases and allow to get metrics based on that. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 19 ++++++++++++--- .../testing/selftests/kvm/include/memstress.h | 12 ++++++++-- tools/testing/selftests/kvm/lib/memstress.c | 24 ++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 416719e20518..0852a7ba42e1 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -134,6 +134,7 @@ struct test_params { uint32_t write_percent; uint32_t random_seed; bool random_access; + uint64_t clear_chunk_size; }; static void run_test(enum vm_guest_mode mode, void *arg) @@ -144,6 +145,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) uint64_t guest_num_pages; uint64_t host_num_pages; uint64_t pages_per_slot; + uint64_t pages_per_clear; struct timespec start; struct timespec ts_diff; struct timespec get_dirty_log_total = (struct timespec){0}; @@ -164,6 +166,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages); host_num_pages = vm_num_host_pages(mode, guest_num_pages); pages_per_slot = host_num_pages / p->slots; + pages_per_clear = p->clear_chunk_size / getpagesize(); bitmaps = memstress_alloc_bitmaps(p->slots, pages_per_slot); @@ -244,8 +247,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) if (dirty_log_manual_caps) { clock_gettime(CLOCK_MONOTONIC, &start); - memstress_clear_dirty_log(vm, bitmaps, p->slots, - pages_per_slot); + memstress_clear_dirty_log_in_chunks(vm, bitmaps, p->slots, + pages_per_slot, + pages_per_clear); ts_diff = timespec_elapsed(start); clear_dirty_log_total = timespec_add(clear_dirty_log_total, ts_diff); @@ -343,6 +347,11 @@ static void help(char *name) " To leave the application task unpinned, drop the final entry:\n\n" " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" " (default: no pinning)\n"); + printf(" -k: Specify the chunk size in which dirty memory gets cleared\n" + " in memslots in each iteration. If the size is bigger than\n" + " the memslot size then whole memslot is cleared in one call.\n" + " Size must be aligned to the host page size. e.g. 10M or 3G\n" + " (default: UINT64_MAX, clears whole memslot in one call)\n"); puts(""); exit(0); } @@ -358,6 +367,7 @@ int main(int argc, char *argv[]) .slots = 1, .random_seed = 1, .write_percent = 100, + .clear_chunk_size = UINT64_MAX, }; int opt; @@ -368,7 +378,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:k:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -392,6 +402,9 @@ int main(int argc, char *argv[]) case 'i': p.iterations = atoi_positive("Number of iterations", optarg); break; + case 'k': + p.clear_chunk_size = parse_size(optarg); + break; case 'm': guest_modes_cmdline(optarg); break; diff --git a/tools/testing/selftests/kvm/include/memstress.h b/tools/testing/selftests/kvm/include/memstress.h index ce4e603050ea..2acc93f76fc3 100644 --- a/tools/testing/selftests/kvm/include/memstress.h +++ b/tools/testing/selftests/kvm/include/memstress.h @@ -75,8 +75,16 @@ void memstress_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vc void memstress_enable_dirty_logging(struct kvm_vm *vm, int slots); void memstress_disable_dirty_logging(struct kvm_vm *vm, int slots); void memstress_get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int slots); -void memstress_clear_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], - int slots, uint64_t pages_per_slot); +void memstress_clear_dirty_log_in_chunks(struct kvm_vm *vm, + unsigned long *bitmaps[], int slots, + uint64_t pages_per_slot, + uint64_t pages_per_clear); +static inline void memstress_clear_dirty_log(struct kvm_vm *vm, + unsigned long *bitmaps[], int slots, + uint64_t pages_per_slot) { + memstress_clear_dirty_log_in_chunks(vm, bitmaps, slots, pages_per_slot, + pages_per_slot); +} unsigned long **memstress_alloc_bitmaps(int slots, uint64_t pages_per_slot); void memstress_free_bitmaps(unsigned long *bitmaps[], int slots); diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c index 3632956c6bcf..e0c701ab4e9a 100644 --- a/tools/testing/selftests/kvm/lib/memstress.c +++ b/tools/testing/selftests/kvm/lib/memstress.c @@ -355,16 +355,28 @@ void memstress_get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int sl } } -void memstress_clear_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], - int slots, uint64_t pages_per_slot) +void memstress_clear_dirty_log_in_chunks(struct kvm_vm *vm, + unsigned long *bitmaps[], int slots, + uint64_t pages_per_slot, + uint64_t pages_per_clear) { - int i; + int i, slot; + uint64_t from, clear_pages_count; for (i = 0; i < slots; i++) { - int slot = MEMSTRESS_MEM_SLOT_INDEX + i; - - kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], 0, pages_per_slot); + slot = MEMSTRESS_MEM_SLOT_INDEX + i; + from = 0; + clear_pages_count = pages_per_clear; + + while (from < pages_per_slot) { + if (from + clear_pages_count > pages_per_slot) + clear_pages_count = pages_per_slot - from; + kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], from, + clear_pages_count); + from += clear_pages_count; + } } + } unsigned long **memstress_alloc_bitmaps(int slots, uint64_t pages_per_slot) From patchwork Fri Apr 21 16:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1208384vqo; Fri, 21 Apr 2023 09:55:34 -0700 (PDT) X-Google-Smtp-Source: AKy350bWWYWrdNaAIjeEJ7FjWxeVGZMyWsCcKhyetpKTEmi470iFFLwEX1EccQGodb974Mt64Z7t X-Received: by 2002:a05:6a21:9982:b0:ec:8f81:e9f7 with SMTP id ve2-20020a056a21998200b000ec8f81e9f7mr8116149pzb.16.1682096134712; Fri, 21 Apr 2023 09:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096134; cv=none; d=google.com; s=arc-20160816; b=naquYs3gDD55IuaAEpiYF79869dxFyq8L/2s6oJBpRm+S34iihiFOq5YPTT6yte/fH xRjpIdZznsYJWfIv5Ae+tRLzfssD9sifA40GP9DAbixugnxgRZ7ualw6Kw2eU2HGLFIt ahN0P5vZaGeGeziMmJIaVYu3QaR6e+1zrCpVfb+sdBolMoREe8xO3I5efgfcTvhPBmNa Pcmvq8soDNFaHQd2YP4Ysr2WQsh//1BrK7qEZPccgojF7LlLCZDed6cKpLmNMmZyqXbR JLeYS9dwsPIIKC0EUjfOmBRpNxwXoDWlXkRkSMp0FWf/LjObEIDfm8NmjpE3FP5FjaRZ /g0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=dM0sknYnz5Tr9YshwaHjySCVB3V9EWCXlRX5uFgEya8=; b=Y5Hty+g+ET0m8ebGeTBs7zEx2OFbdHkeU1awSokNF2s2DAgFa0OYxaBW7QALChzqck JZhUu6U6YZrBkRVSP5MmQkcgwHMiH2zTMtM2L/Odz02xKoaXB9qqizkkPpTYCAqcib2U prKhM5dPOd9ZekWBEvsLGEwU8PvovmC6PhXWBYWEOOvmLIsL84IbMued2dIfmCW8QTxS aeSQR6NsRXu1l7v29UWgf+KApeOUcblnXPOHG5ATWQMGkR0QxJ6hVFeOKhMtplP3m9i6 z2fRbFSe61QXN0nKaSY6mV3GXVVmOY6F4xDAfd3ROLuZl+gDknT3qbIln8AHbzHCBxMt 683w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=cKoOxJh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a635404000000b004e018302ac3si4605764pgb.612.2023.04.21.09.55.20; Fri, 21 Apr 2023 09:55:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=cKoOxJh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbjDUQyv (ORCPT + 99 others); Fri, 21 Apr 2023 12:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbjDUQyb (ORCPT ); Fri, 21 Apr 2023 12:54:31 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C68C315A3D for ; Fri, 21 Apr 2023 09:54:15 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2472a2e72d1so2199554a91.3 for ; Fri, 21 Apr 2023 09:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682095992; x=1684687992; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dM0sknYnz5Tr9YshwaHjySCVB3V9EWCXlRX5uFgEya8=; b=cKoOxJh4k5Df809KvDrC16SHpyyANbnD88ODpXNOuka0EEfmMXb9/GGZHQjZmiaSGC PHXwzp6oJJCuBjtwH55J3xqdIM10HnXCfOmj/GRFwtdNPqo3g+mBSidFvw86YFvbU0sY QFH5aE4DJ8NgYwN0BX1m2H/84CVYfPBQlivAZjfI0w0gbJssCQFPLo6dhrf9i30gQDYK RVT9NmA3RwkhJ9wGFaj9EOO7LpEIdOpFNM2q37g3x6fVQdiBTnwi7UMa2h5IS92inTkJ 5XzKSeq94NI91RbwFfXmAf2d+oezqCbzgzE8MFn7zbTcJm/Y08tOtjCRc2EpRU8GmuIw Joug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682095992; x=1684687992; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dM0sknYnz5Tr9YshwaHjySCVB3V9EWCXlRX5uFgEya8=; b=HZgNh/Ii5oBhelek4NE+W4/6x+byRvRpyRy8w894ZALvckvxe5b+rEoiAJKXZ/IzmT uPH0kU2sg8Ptq1SXqHvz4vCHL5k3nlxW6MuINOVXbsU9iWMaZdp7fqf6Ez0ephffRrWF Tt3hWi+OdFNhOXMxoQ91At+rXmeXYMcqpBYKOfUj8VDSsvoApPVaMFxrIQUyss1T0E2m poR3mob/AQVvAIuTaXuuX2weuBeA1e1yR2HqDQRbnyXSq26u0ch8fSbgtCmg7uDS9Lad FonBcqJF4nATyxGiMCBTNRRjcRIaNixK8jXQCMaI0CAcBUZ+/PSsLWnnzXuMPeq52TNN tMUQ== X-Gm-Message-State: AAQBX9fIq+s3SH/DFARSwOix6FHgtkz/jwIyk2PAcUXQNX3HKSfRYxyK Plu9ZKFeAs2fx3op2ir8QCZgcVsxmVbT X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:740d:b0:244:8f24:783d with SMTP id a13-20020a17090a740d00b002448f24783dmr1553862pjg.4.1682095992639; Fri, 21 Apr 2023 09:53:12 -0700 (PDT) Date: Fri, 21 Apr 2023 09:52:58 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-3-vipinsh@google.com> Subject: [PATCH 2/9] KVM: selftests: Add optional delay between consecutive Clear-Dirty-Log calls From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763805636520835930?= X-GMAIL-MSGID: =?utf-8?q?1763805636520835930?= In dirty_log_perf_test, add option "-l" to wait between consecutive Clear-Dirty-Log calls. Accept delay in milliseconds. This allows dirty_log_perf_test to mimic real world use where after clearing dirty memory, some time is spent in transferring memory before making a subsequeunt Clear-Dirty-Log call. Signed-off-by: Vipin Sharma --- .../testing/selftests/kvm/dirty_log_perf_test.c | 17 +++++++++++++++-- tools/testing/selftests/kvm/include/memstress.h | 5 +++-- tools/testing/selftests/kvm/lib/memstress.c | 10 +++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 0852a7ba42e1..338f03a4a550 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -135,6 +135,7 @@ struct test_params { uint32_t random_seed; bool random_access; uint64_t clear_chunk_size; + int clear_chunk_wait_time_ms }; static void run_test(enum vm_guest_mode mode, void *arg) @@ -249,7 +250,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) clock_gettime(CLOCK_MONOTONIC, &start); memstress_clear_dirty_log_in_chunks(vm, bitmaps, p->slots, pages_per_slot, - pages_per_clear); + pages_per_clear, + p->clear_chunk_wait_time_ms); ts_diff = timespec_elapsed(start); clear_dirty_log_total = timespec_add(clear_dirty_log_total, ts_diff); @@ -352,6 +354,11 @@ static void help(char *name) " the memslot size then whole memslot is cleared in one call.\n" " Size must be aligned to the host page size. e.g. 10M or 3G\n" " (default: UINT64_MAX, clears whole memslot in one call)\n"); + printf(" -l: Specify time in milliseconds to wait after Clear-Dirty-Log\n" + " call. This allows to mimic use cases where flow is to get\n" + " dirty log followed by multiple clear dirty log calls and\n" + " sending corresponding memory to destination (in this test\n" + " sending will be just idle waiting)\n"); puts(""); exit(0); } @@ -368,6 +375,7 @@ int main(int argc, char *argv[]) .random_seed = 1, .write_percent = 100, .clear_chunk_size = UINT64_MAX, + .clear_chunk_wait_time_ms = 0, }; int opt; @@ -378,7 +386,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:k:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:k:l:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -405,6 +413,11 @@ int main(int argc, char *argv[]) case 'k': p.clear_chunk_size = parse_size(optarg); break; + case 'l': + p.clear_chunk_wait_time_ms = + atoi_non_negative("Clear dirty log chunks wait time", + optarg); + break; case 'm': guest_modes_cmdline(optarg); break; diff --git a/tools/testing/selftests/kvm/include/memstress.h b/tools/testing/selftests/kvm/include/memstress.h index 2acc93f76fc3..01fdcea80360 100644 --- a/tools/testing/selftests/kvm/include/memstress.h +++ b/tools/testing/selftests/kvm/include/memstress.h @@ -78,12 +78,13 @@ void memstress_get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int sl void memstress_clear_dirty_log_in_chunks(struct kvm_vm *vm, unsigned long *bitmaps[], int slots, uint64_t pages_per_slot, - uint64_t pages_per_clear); + uint64_t pages_per_clear, + int wait_ms); static inline void memstress_clear_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int slots, uint64_t pages_per_slot) { memstress_clear_dirty_log_in_chunks(vm, bitmaps, slots, pages_per_slot, - pages_per_slot); + pages_per_slot, 0); } unsigned long **memstress_alloc_bitmaps(int slots, uint64_t pages_per_slot); void memstress_free_bitmaps(unsigned long *bitmaps[], int slots); diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c index e0c701ab4e9a..483ecbc53a5b 100644 --- a/tools/testing/selftests/kvm/lib/memstress.c +++ b/tools/testing/selftests/kvm/lib/memstress.c @@ -358,10 +358,15 @@ void memstress_get_dirty_log(struct kvm_vm *vm, unsigned long *bitmaps[], int sl void memstress_clear_dirty_log_in_chunks(struct kvm_vm *vm, unsigned long *bitmaps[], int slots, uint64_t pages_per_slot, - uint64_t pages_per_clear) + uint64_t pages_per_clear, + int wait_ms) { int i, slot; uint64_t from, clear_pages_count; + struct timespec wait = { + .tv_sec = wait_ms / 1000, + .tv_nsec = (wait_ms % 1000) * 1000000ull, + }; for (i = 0; i < slots; i++) { slot = MEMSTRESS_MEM_SLOT_INDEX + i; @@ -374,6 +379,9 @@ void memstress_clear_dirty_log_in_chunks(struct kvm_vm *vm, kvm_vm_clear_dirty_log(vm, slot, bitmaps[i], from, clear_pages_count); from += clear_pages_count; + if (wait_ms) + nanosleep(&wait, NULL); + } } From patchwork Fri Apr 21 16:52:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1211263vqo; Fri, 21 Apr 2023 10:00:43 -0700 (PDT) X-Google-Smtp-Source: AKy350aaGOKOi4WXjX9S80hO+iIuutI6haWh6iInXBGgGff1WGiS/XXTyG9uYn55Vi+HjHEf2gwp X-Received: by 2002:a05:6a00:2346:b0:63b:7fc0:a4af with SMTP id j6-20020a056a00234600b0063b7fc0a4afmr7200098pfj.26.1682096442645; Fri, 21 Apr 2023 10:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096442; cv=none; d=google.com; s=arc-20160816; b=s3P4VdivHwB5z19vWwiET1rU+tJ6jKc+WSAcU50hJhiMZ/36dETnaDqEmSuuI4xFPa cbJ9iu5a74cpxEGFB/CzWxVc8l/3PDr3poZEgFNZdlT0NSH6yFxjGCAljf0TiskNzor+ Wj6mEqbILTswqLm3MuVgCAx+zURjn31g4Hfdhtzb+Qz9qP9b09uWcbD/qznVslIH27nL w0HKm+d1rymQdVTd812C8gg3zdrR7IsJO1VOnrpayJXD1zI2VabpMyrFr6LfSdxq08eI HBc26KEHaT8DlRlxbC7O6i7a+r2Dn3ALuOEcWU2V8Dym7kJDrtedOT3xbZGJfmaOq/6u GBtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2PAF8eecHjdHkncCHVDxnuwZD238/O/D5uX087DV6gk=; b=ggR67udQAg8pDAr6ZHT0G0JJdsPphrQW8TfIjxn9fSHh7+hjTox6+mc4iOLmcZBasC rmj9g5GalxB3vdUREd/27ySHlZaNRYbT6QU+dBCAu5YkhmXUWPOItEwddfb8GYxrOObq NvRz2eJSmTRsyxm0f1J36zI5LJaifkNMa1orZMXNTxtATOMjU9hOlFcCs24qkmgn+gEH PxYqFXhhX+0B6Zy2uFQrm83n1n9aL1+xlNu5wD0jSw3ZqpOqFdYXcyabeFASUWGwpLvk POe3kOB5riuyitxupWERqLyaXoN+FSSYA8o0lY5tNNzEfEo4cxrRtxVx54H5Luz4QH+5 Ik3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=PTkyUTn2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020aa795a6000000b0063b7a92ff37si4780682pfk.231.2023.04.21.10.00.27; Fri, 21 Apr 2023 10:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=PTkyUTn2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233508AbjDUQzQ (ORCPT + 99 others); Fri, 21 Apr 2023 12:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233467AbjDUQyp (ORCPT ); Fri, 21 Apr 2023 12:54:45 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC25167C7 for ; Fri, 21 Apr 2023 09:54:29 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1a697b64beaso15782235ad.1 for ; Fri, 21 Apr 2023 09:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682095994; x=1684687994; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2PAF8eecHjdHkncCHVDxnuwZD238/O/D5uX087DV6gk=; b=PTkyUTn2160dQG/w0LBEubHoXT6/kolM07eAXpOkI5VQKBjVge2/G3D9DJWv4EmluF jwrYT87c/pr1Xst3R4sPDfwUW1QW6N7gw0yt507TfR8+t+X9AZokv5qPyHgjsmekGrNG N5lb8NDbmayYdr4sbEsTRxgCzT7JDO2aRCdXd3ULGGsFS/IzMoTjppouMIJbEHzjtzJn 0UQdx9F3D1PLMFaK3GeO580/u61tzYb2QXdQjUSDj2cShYPf8ASAPVv3u7/P4wOk+ciC 66tN/SEGEQMjy6UGRqCfjY+yHppjjUO6tyxdYKf7p4Z/hg9iu3GtO1l0LIPj0nE4z4c0 zDPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682095994; x=1684687994; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2PAF8eecHjdHkncCHVDxnuwZD238/O/D5uX087DV6gk=; b=IKxHNV2uXG4cHynM691h7uysZTpI5y2I1Ochi8kzp4ZBWoZN6kkeOPKe672YeHGTIl FuaQqnoBxv0p1uvLNT+CVhnVyF4MroO4u+3vkYz30QGDQoc/Z+2R9KbY9czR8erWg4fJ 5/c0kZTuChykEJUhpCnwtQY8SupfhLt+OWlkFA1LbOIVPdIfpmFttEpczD2EyoFkXdIz k39k3hwWYd6+JRBxv8z3qMSgMUD6gUu2c7DvRqYoqqWiMw3UCTjTZDDdM+1iGNCgxeyw 1ThVxpjoghsCQ5DspWzbosRhifrrqa1bLradzyih5WnEqba2l66ECWiowfaArjv5+5oX 1JwQ== X-Gm-Message-State: AAQBX9e+pXlhjvth7syldiDNeyY0Ul0Y7gcHH8BIg30E4D/OkonsR3SY RNbHeBDZCYW84GhviLACefwUBzPIPlw9 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:7b85:b0:1a0:4321:920e with SMTP id w5-20020a1709027b8500b001a04321920emr1816879pll.12.1682095994335; Fri, 21 Apr 2023 09:53:14 -0700 (PDT) Date: Fri, 21 Apr 2023 09:52:59 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-4-vipinsh@google.com> Subject: [PATCH 3/9] KVM: selftests: Pass count of read and write accesses from guest to host From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763805959282834628?= X-GMAIL-MSGID: =?utf-8?q?1763805959282834628?= Pass number of read and write accesses done in the memstress' guest code to userspace. These counts will be one way to measure vCPU performances during memstress and dirty logging related tests. For example, in dirty_log_perf_test this can be used to measure impact of dirty and clear log APIs on vCPUs performances. In current dirty_log_perf_test, each vCPU executes in lockstep to the current iteration in userspace, therefore, these access counts will not provide much useful information except for observing individual vCPUs read vs write accesses. However, in future commits, dirty_log_perf_test behavior will be changed to allow vCPUs to execute independent of userspace iterations. This will mimic real world workload where guest keeps on executing while VMM is collecting and clearing dirty logs separately. With read and write accesses known for each vCPU, impact of get and clear dirty log APIs can be quantified. Note that these access counts will not be 100% reliable in knowing vCPUs performances since vCPUs scheduling can impact the progress. Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/lib/memstress.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c index 483ecbc53a5b..9c2e360e610f 100644 --- a/tools/testing/selftests/kvm/lib/memstress.c +++ b/tools/testing/selftests/kvm/lib/memstress.c @@ -50,6 +50,8 @@ void memstress_guest_code(uint32_t vcpu_idx) struct memstress_args *args = &memstress_args; struct memstress_vcpu_args *vcpu_args = &args->vcpu_args[vcpu_idx]; struct guest_random_state rand_state; + uint64_t write_access; + uint64_t read_access; uint64_t gva; uint64_t pages; uint64_t addr; @@ -65,6 +67,8 @@ void memstress_guest_code(uint32_t vcpu_idx) GUEST_ASSERT(vcpu_args->vcpu_idx == vcpu_idx); while (true) { + write_access = 0; + read_access = 0; for (i = 0; i < pages; i++) { if (args->random_access) page = guest_random_u32(&rand_state) % pages; @@ -73,13 +77,16 @@ void memstress_guest_code(uint32_t vcpu_idx) addr = gva + (page * args->guest_page_size); - if (guest_random_u32(&rand_state) % 100 < args->write_percent) + if (guest_random_u32(&rand_state) % 100 < args->write_percent) { *(uint64_t *)addr = 0x0123456789ABCDEF; - else + write_access++; + } else { READ_ONCE(*(uint64_t *)addr); + read_access++; + } } - GUEST_SYNC(1); + GUEST_SYNC_ARGS(1, read_access, write_access, 0, 0); } } From patchwork Fri Apr 21 16:53:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1216162vqo; Fri, 21 Apr 2023 10:05:48 -0700 (PDT) X-Google-Smtp-Source: AKy350ZhPMdrWVmpHhnoZNTH1D20togekow3OEXEg9MchcaiIRs0g1OdXgZqngRRMJSpH752Ccdc X-Received: by 2002:a92:1e08:0:b0:32c:a8c7:766c with SMTP id e8-20020a921e08000000b0032ca8c7766cmr4335593ile.14.1682096747862; Fri, 21 Apr 2023 10:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096747; cv=none; d=google.com; s=arc-20160816; b=NaBvWBb9GRp/Rh1nppFPN+JLCOqj3ok3lIPWSY5lzE2nNnPpLf9wMIBqUpj9yRSQE5 zi5C83IXpGH/yif9s9uk6YwovnfO5NHPuCD7LM4uff2zDTDxUViujjTdsixHrwFsTUg3 MEX8KXU5XT3mH808sqiLLQKbFQjEcEni1VZYVxH1BOZbdZHU8gVkB0nduk/WjU95V5yL 6gC6pNFKVDVTWPbncfVNnQ23Z8bvRu9QRpxCLZsPVVmGTIEkMOQ1o9+atSb9QBZTHGjx 4AuJBOYlQNfMTdhm94+XQ5/QxlCVHG0SCJixz5//JWQse9pa8nNeVxbELoGm7Ma1N0jZ MPfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=QAMadok09XxgFvaDO3J6Lgqv+ZDwnOLb2IYSq9G7u+A=; b=Zo5NPnHw3qZdIc0hYEUKTvlUSQ3FMtk/i31SKdUp7RKngKjgIZqOBeIjmN0Ttg0Otv GVbhjsP15qmrJ05sWGV0Mmt3JbrevDh+0mjS96gujffPntXRaIqNEmHLIcfecpilAiUI 57ScQxXZ2qYR750eCSYbqSGuCN5I4D4Utg474y+wlpSfQLVSuTu8Y2qQfDTyVcPuZtJN Wrk8YeTS3K80fH6K4U5W7MX5Ty4rzsaDpZKcp0M8FEoeLNejbcs+LAJZP3gN20j2dU9J UIqvuSHJETyDUWRJozhw5RXApMaIqwCnLyJDXW9klIM5k9xyepdpaLq1yu4B/mpMz08U FEjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=5l1CzLum; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17-20020a924b11000000b0032b70e749e3si4462749ilg.182.2023.04.21.10.05.34; Fri, 21 Apr 2023 10:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=5l1CzLum; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbjDURAa (ORCPT + 99 others); Fri, 21 Apr 2023 13:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233306AbjDURAW (ORCPT ); Fri, 21 Apr 2023 13:00:22 -0400 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DD8167C1 for ; Fri, 21 Apr 2023 09:59:55 -0700 (PDT) Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-52057b3d776so1488812a12.2 for ; Fri, 21 Apr 2023 09:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682095996; x=1684687996; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QAMadok09XxgFvaDO3J6Lgqv+ZDwnOLb2IYSq9G7u+A=; b=5l1CzLumfw4VvnGKs1LekidIOHm6RR2ZhVTA1I+whH2HeXgm2o8PhxoPUQLTHfydb9 MbBxamdeRZWqIzwIX6cPpq9NGQ3282H+LGUyBZpLlO6iAgfWncKkZnXQevgjEqCzsFvI /ie9WS7cdYCl1aCB7+4MGfZNo6IMNnRdfZplWSdxceYc0BIUM6d0gO/blOvoZokSUVGw Y1vWnwlcSKtpR4AbEKzTUp+leY3IooaW0MIg6qShyiSd1O990V5j6KZFgnSxmwclrSfF iRRS2VvoFH4pfGHIeK5C/wh3ElWiAy4UgpcFTrfc4JtiPWNVC38kZkoYq7eJ04Cn12As uI2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682095996; x=1684687996; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QAMadok09XxgFvaDO3J6Lgqv+ZDwnOLb2IYSq9G7u+A=; b=YFCdqUu1CYrz6tMJVGBIWiCTmQjD6goPc61bifbkDtQHBFcfBWnTp+D1nSynwAY0Lv DrXm63QAtHOGBBrHJhWvAEwheYOtWnUSwR34YQeWeBDuTqtKPyvr4r3Sv2/RH4ei09KF Mlj4D/bnHF016YnyyOZhVoeX+k9w7Oj6VI+VMqwNy6Nz9JBNmz5KgylBm0bnem7yjk79 SP42zs4hKrf5Q1S+VE6k56XN40YrJWzqq//6cBbmqDnbd+oFtuiAaCjVzV06DOzWyG21 6fYXaDFeU5qZC3cSYfVX/xlFCOkWe67+4MPv/V10uwAiKVgzPLpAyceeSkrhV/t2XP+J y3Mw== X-Gm-Message-State: AAQBX9dY75xpbjHv9iLdYL2ZBTQD9MlJ1Fjr8LS/jLD2utJnFydG6q6V DQT4LPGRRsLCXeN/VpWewI/Pbn6D6Xf4 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a63:105e:0:b0:520:53fa:9878 with SMTP id 30-20020a63105e000000b0052053fa9878mr1424111pgq.6.1682095996166; Fri, 21 Apr 2023 09:53:16 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:00 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-5-vipinsh@google.com> Subject: [PATCH 4/9] KVM: selftests: Print read and write accesses of pages by vCPUs in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763806279365759705?= X-GMAIL-MSGID: =?utf-8?q?1763806279365759705?= Fetch read and write accesses of pages from guest code and print count across all vCPUs in dirty_log_perf_test. This data provides progress made by vCPUs during dirty logging operations. Since, vCPUs execute in lockstep with userspace dirty log iterations, this metric is not very interesting. However, in future commits when dirty_log_perf_test can execute vCPUs independently from dirty log iterations then this metric can give good measure of vCPUs performance during dirty logging. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 338f03a4a550..0a08a3d21123 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "kvm_util.h" @@ -66,17 +67,22 @@ static u64 dirty_log_manual_caps; static bool host_quit; static int iteration; static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; +static atomic_ullong total_reads; +static atomic_ullong total_writes; static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) { struct kvm_vcpu *vcpu = vcpu_args->vcpu; int vcpu_idx = vcpu_args->vcpu_idx; uint64_t pages_count = 0; + uint64_t reads = 0; + uint64_t writes = 0; struct kvm_run *run; struct timespec start; struct timespec ts_diff; struct timespec total = (struct timespec){0}; struct timespec avg; + struct ucall uc = {}; int ret; run = vcpu->run; @@ -89,7 +95,7 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) ts_diff = timespec_elapsed(start); TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret); - TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC, + TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_SYNC, "Invalid guest sync status: exit_reason=%s\n", exit_reason_str(run->exit_reason)); @@ -101,6 +107,8 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) if (current_iteration) { pages_count += vcpu_args->pages; total = timespec_add(total, ts_diff); + reads += uc.args[2]; + writes += uc.args[3]; pr_debug("vCPU %d iteration %d dirty memory time: %ld.%.9lds\n", vcpu_idx, current_iteration, ts_diff.tv_sec, ts_diff.tv_nsec); @@ -123,6 +131,8 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) pr_debug("\nvCPU %d dirtied 0x%lx pages over %d iterations in %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n", vcpu_idx, pages_count, vcpu_last_completed_iteration[vcpu_idx], total.tv_sec, total.tv_nsec, avg.tv_sec, avg.tv_nsec); + atomic_fetch_add(&total_reads, reads); + atomic_fetch_add(&total_writes, writes); } struct test_params { @@ -176,6 +186,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) dirty_log_manual_caps); arch_setup_vm(vm, nr_vcpus); + atomic_store(&total_reads, 0); + atomic_store(&total_writes, 0); /* Start the iterations */ iteration = 0; @@ -295,6 +307,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec); } + pr_info("Total pages touched: %llu (Reads: %llu, Writes: %llu)\n", + atomic_load(&total_reads) + atomic_load(&total_writes), + atomic_load(&total_reads), atomic_load(&total_writes)); + memstress_free_bitmaps(bitmaps, p->slots); arch_cleanup_vm(vm); memstress_destroy_vm(vm); From patchwork Fri Apr 21 16:53:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1224083vqo; Fri, 21 Apr 2023 10:17:23 -0700 (PDT) X-Google-Smtp-Source: AKy350YVkeqo23B7acDfLXfoNgF5SdjmHbVbVieoK1ZxZ0OEk00jZI7eFACX6QfYitsJz3op7xDY X-Received: by 2002:a05:6a20:748f:b0:d9:27f7:8c4a with SMTP id p15-20020a056a20748f00b000d927f78c4amr7478478pzd.0.1682097442949; Fri, 21 Apr 2023 10:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682097442; cv=none; d=google.com; s=arc-20160816; b=R54orYpaE+i63MtH1UnrEeIdaS7ahVMNaG+By0s6ofctyPJsENGI7BdxRlB2jdaG2C xdyrz3BX4/E57ZCYSR79gkDNvKVhPk0jeGeDebhG6xwj97iNdx4tiSRjshTj8Q3o6jqR 4sjeodDi3WBgk9PB9KxKyLX70V+EfKui4JR3xKiKrU/RG1ipNTcptTO4RIm76X63ifXV CNbmUZSZvTGISJ7nsMeIp4x6rCBCTpJbDmuYBZj/8mMGtZ5mHEOfuaL0xhIpLI6evwOC xPmoB1VeblkDaU1sCveJ2pv6mYW2YkdqFYfTZ5ZZiYHnnqwA43QqS3Rssq1e6XaWsDU5 ZDQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=K4flH6XuI9dv6dwtzR0KQ1PZpqeGOsBZ2CGHMQcZby5bdsCEWZWiEHFfSFi6w0tWzP BUaB0eIxLLzpn08DUhSK4Nf7vHgIob5fQiyLtMyTcL34QuW/eHD7af7p5pBrg0V/AZRB u9JXKYF8y5A8R5F0usZxAl7TeQKW87g5ygbHkEPLHg045CpWq9zdTuqibPoIzcBujZ+b fi8jINKgYfFaLbv063t1gfFNvKYdg0Gvl3Lu/1td0E4F/WVhKL+bVrfgDf8WnBYRnd3Y MWdyQpfEp/xiFJOdT4AFsd5/uAmWtjhXeCjAFwxmorjLPP+HssWb0uSzVUP1E8JmyS84 q20w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=cwKBgaS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b201-20020a621bd2000000b0062565210347si4752453pfb.275.2023.04.21.10.17.07; Fri, 21 Apr 2023 10:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=cwKBgaS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232592AbjDURCf (ORCPT + 99 others); Fri, 21 Apr 2023 13:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbjDURCb (ORCPT ); Fri, 21 Apr 2023 13:02:31 -0400 Received: from mail-vk1-xa4a.google.com (mail-vk1-xa4a.google.com [IPv6:2607:f8b0:4864:20::a4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B948015628 for ; Fri, 21 Apr 2023 10:02:02 -0700 (PDT) Received: by mail-vk1-xa4a.google.com with SMTP id 71dfb90a1353d-4404c17ddc6so549976e0c.2 for ; Fri, 21 Apr 2023 10:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096508; x=1684688508; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=cwKBgaS0WopiwHwuYQpJgWkE9nSxf7p9hQYZ1AUBEY7JH7Up9fxYUEXwnJEII0BBbd SmJV4hpApQTi1NVYumlyuPoXfgmM/B3Cf2dtKbCMXPAe+5MXmna29ZCklFtCoKATSXS5 JiEttU8ikp/7etnI/in+PUnNhWJs0c92v/J+1f6QBLOBcZTijEwdstNfnyz/+OoHilZ9 NtQjDxLpB6ICZTuvFSNjqzHB4h+YIJFrm5adhAsDEQh75uYzWWuJVT/IqK3NxtuWnsbZ EXlf0Yp0zCUyCIGd0MJYepfcd0G1jbpvMTaGnzGsDDjvKjGjTFDTHgCnA2TRkVM1RdY0 uxrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096508; x=1684688508; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=Jdx5+dCP6qCiKszqDiyqKiImLT9FAHW96czEFIIzyztib32rhD+c5kUIN1nFyDnPeC haDqyQ2R22yUPw0ewQw19GZib12WHmV5JnieIaMsHDhwXxiu8bHGdYzQ5i5mW7CNHPPt AIi1r7Wc0Pk4bpR3Y9dvkI7VcRHiOt0RIwBsMsW8UiaEDzEYXecoYmVc/uyGeBbWdDtB BoBnAnnIVZgRLeOtXOG+a7DHnLHo7MkXlDVhwkTzz4Zl04csl275WeTNdxPqRneVnLU4 3xPTi04HNWrdXuydKoke/rMfXUgBZ9HmkLsEz5mlQd/C0e/dxpYwVHlGq3MaZfJRBhwG RnNA== X-Gm-Message-State: AAQBX9dFpOFnVfA3SXbUSi0MzZ+Tag2/88w/TxygrYFtLTc5j0v1X21V KIisamlew501Z0KeEFeKmXIwMG/5MMAd X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:d147:0:b0:b8c:ad5:6b4e with SMTP id i68-20020a25d147000000b00b8c0ad56b4emr1983907ybg.12.1682095998019; Fri, 21 Apr 2023 09:53:18 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:01 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-6-vipinsh@google.com> Subject: [PATCH 5/9] KVM: selftests: Allow independent execution of vCPUs in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763807008699906261?= X-GMAIL-MSGID: =?utf-8?q?1763807008699906261?= Allow vCPUs to execute independent of dirty log iterations after initialization is complete. Hide this feature behind the new option "-j". This change makes dirty_log_perf_test execute like real world workflows where guest vCPUs keep on executing while VMM collects dirty logs. Total pages touched during execution of test will give good estimate of how vCPUs are performing while dirty logging is enabled. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 0a08a3d21123..ffdad535fdaa 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -69,6 +69,7 @@ static int iteration; static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; static atomic_ullong total_reads; static atomic_ullong total_writes; +static bool lockstep_iterations; static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) { @@ -83,12 +84,16 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) struct timespec total = (struct timespec){0}; struct timespec avg; struct ucall uc = {}; + int current_iteration = -1; int ret; run = vcpu->run; while (!READ_ONCE(host_quit)) { - int current_iteration = READ_ONCE(iteration); + if (lockstep_iterations) + current_iteration = READ_ONCE(iteration); + else + current_iteration++; clock_gettime(CLOCK_MONOTONIC, &start); ret = _vcpu_run(vcpu); @@ -118,13 +123,19 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) ts_diff.tv_nsec); } - /* - * Keep running the guest while dirty logging is being disabled - * (iteration is negative) so that vCPUs are accessing memory - * for the entire duration of zapping collapsible SPTEs. - */ - while (current_iteration == READ_ONCE(iteration) && - READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) {} + if (lockstep_iterations) { + /* + * Keep running the guest while dirty logging is being disabled + * (iteration is negative) so that vCPUs are accessing memory + * for the entire duration of zapping collapsible SPTEs. + */ + while (current_iteration == READ_ONCE(iteration) && + READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) + ; + } else { + while (!READ_ONCE(iteration)) + ; + } } avg = timespec_div(total, vcpu_last_completed_iteration[vcpu_idx]); @@ -238,17 +249,19 @@ static void run_test(enum vm_guest_mode mode, void *arg) clock_gettime(CLOCK_MONOTONIC, &start); iteration++; - pr_debug("Starting iteration %d\n", iteration); - for (i = 0; i < nr_vcpus; i++) { - while (READ_ONCE(vcpu_last_completed_iteration[i]) - != iteration) - ; - } + if (lockstep_iterations) { + pr_debug("Starting iteration %d\n", iteration); + for (i = 0; i < nr_vcpus; i++) { + while (READ_ONCE(vcpu_last_completed_iteration[i]) + != iteration) + ; + } - ts_diff = timespec_elapsed(start); - vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); - pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", - iteration, ts_diff.tv_sec, ts_diff.tv_nsec); + ts_diff = timespec_elapsed(start); + vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); + pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", + iteration, ts_diff.tv_sec, ts_diff.tv_nsec); + } clock_gettime(CLOCK_MONOTONIC, &start); memstress_get_dirty_log(vm, bitmaps, p->slots); @@ -365,6 +378,10 @@ static void help(char *name) " To leave the application task unpinned, drop the final entry:\n\n" " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" " (default: no pinning)\n"); + printf(" -j: Execute vCPUs independent of dirty log iterations\n" + " Independent vCPUs execution will allow them to continuously\n" + " dirty memory while main thread is collecting and clearing\n" + " dirty logs in the main thread's iterations.\n"); printf(" -k: Specify the chunk size in which dirty memory gets cleared\n" " in memslots in each iteration. If the size is bigger than\n" " the memslot size then whole memslot is cleared in one call.\n" @@ -399,10 +416,10 @@ int main(int argc, char *argv[]) kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | KVM_DIRTY_LOG_INITIALLY_SET); - + lockstep_iterations = true; guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:k:l:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:jk:l:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -426,6 +443,9 @@ int main(int argc, char *argv[]) case 'i': p.iterations = atoi_positive("Number of iterations", optarg); break; + case 'j': + lockstep_iterations = false; + break; case 'k': p.clear_chunk_size = parse_size(optarg); break; From patchwork Fri Apr 21 16:53:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1208485vqo; Fri, 21 Apr 2023 09:55:48 -0700 (PDT) X-Google-Smtp-Source: AKy350aKEZJfM2LHOhALwVDePLhWUQrOqYk/6q7emvdwMF60TJH2RmRl21PbVPfAq3efbIQAlqSx X-Received: by 2002:a05:6a00:2406:b0:63b:8571:8102 with SMTP id z6-20020a056a00240600b0063b85718102mr5889712pfh.3.1682096148461; Fri, 21 Apr 2023 09:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096148; cv=none; d=google.com; s=arc-20160816; b=SwvvbmiiiWnL/Vhca37YT9M+smqYCa+bsFFOCnyTJYF4sCFmOWwAN5GG/T9nYQG6Kh FnyhLJu31Hc10omr9FC556pyE5Q9YWRimRC70MpXAXH5dHZ9jz/iWe5sknlprQSg1m7M dsW3cgVEVnbiNUm6ZXn0Pc57G7ISl/4NQDeAFZrMHRu7jSqbSlx9crmgedAb5iMxKk8Y 8drSF/oh9BvVwupFTJj18/tV0e+pNQwJ1ixA4dUkgm6XaLEjFm4i5wSTdG11BtoNKdK9 1aenp09V97NXV3hZkjMTS0JaXNQ2ANxFSMBOLfZP/+NZsIJAI3d+xViEGPFnLII1rG6p cJlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=aDUI7xCr7dWf/FkK1CK1yXAqGXh9n1NZNFj54qb+KHU=; b=fZzHXfloyloz/jxLLx0PB5zGcfxTJtwYR+QiWu/RC94kG9wcIYSE8z3OHpYBvBqNEH ybGtDZ/f320QHq7cpgudzWHQCb5NwBecfLwIywRVbtk3uA7nKo3cveI9Q6beTLUbEmon g0eeTk5BDAF2CwV1B0sXG8Sjyr8b+QZQqQDtCT+WkiQBteaddVSUVWtiHA9Rib0plgOe y9WDYopl750qaxk/QjtIjIbaKuc7CWkAC75j0cbDTz00UPMTy2QUzKol2r1iHwkDfsFg MQQilHCPjkJgLOy6B6ar3ogEN1RRJaOY4A32uvenX/6xCxC/anmCQyVvitEjuTDu2YAB PL7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xTDct9zx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a63610a000000b00513edc81581si4842688pgb.287.2023.04.21.09.55.33; Fri, 21 Apr 2023 09:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xTDct9zx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233321AbjDUQzD (ORCPT + 99 others); Fri, 21 Apr 2023 12:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233381AbjDUQyi (ORCPT ); Fri, 21 Apr 2023 12:54:38 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3CE715625 for ; Fri, 21 Apr 2023 09:54:21 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-63b3bf0b814so2752490b3a.2 for ; Fri, 21 Apr 2023 09:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682095999; x=1684687999; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aDUI7xCr7dWf/FkK1CK1yXAqGXh9n1NZNFj54qb+KHU=; b=xTDct9zxZ9N8ALbPUp/viW7lM9BRRuwGhBUMNIpBcky3DENAIpUsYaKC4hxy6ElANa XJM0ALn9fzQGXWa5TwxvUayRtY+2kF+0hSFrS4Z13rLNDvpjdJ1bTkvnlg/aszqM3kw6 JwtYRMMCwqvts/H9WPbPOWtINNCHPcx52iHlR+Mni7gOLO5npE1/M3beOvxeJdJAoVtK oYpcB0E2UWuNNPfDE3N6K7L1PsDilnRRB45iG1BH2Hs9bkLyvvb6zqJnC7OL6glGnKD+ tqNazVeTkEV+I2VUzEqOogcJ5o+xCg88TmCeF1jcEtkdTpDT5v8zElAEZqy2mA1rdmJ4 ZLUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682095999; x=1684687999; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aDUI7xCr7dWf/FkK1CK1yXAqGXh9n1NZNFj54qb+KHU=; b=mD5KWUrTM7I4keTM/rpRLPkf982eNckc0RGQwa0EaGvw7QHh6JGOCf3r6ysbTZNj/i tZo8NZi2zZIb7O9Cbr+rTyg5LItow4hPn6n8ymbjPS9jgxkb2rALtlxqQSQZ/Dm+ovqS CveIVYUO6zG0cXPDTN4QiT+wl2snlHA6B2Otx8VeK05n+EIUkq1SEQix4o0XN7Ur2/TX zMe3HTZ6vzWv01yWdjUJTyb95+wwb9rAIwm/CiNDi6+rJAaM23lHnyNjZjk1AsTlg9Vm +k5GMq8RAo0qLFzL/mjtxxNi8AYOi6+5wvElr634o+c2j+HCz/Y6d9cCuu8EoOj24+Hz gjzQ== X-Gm-Message-State: AAQBX9eGFKe8LzM7MFutYgTd72b6FBOpvApFmKgE1Pe+SVf4mFiexFf9 6aftZKnAktQsLM7Cl063NUB82DU0a/7a X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:134b:b0:63d:5dcd:bc06 with SMTP id k11-20020a056a00134b00b0063d5dcdbc06mr2146455pfu.5.1682095999596; Fri, 21 Apr 2023 09:53:19 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:02 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-7-vipinsh@google.com> Subject: [PATCH 6/9] KVM: arm64: Correct the kvm_pgtable_stage2_flush() documentation From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763805650460457786?= X-GMAIL-MSGID: =?utf-8?q?1763805650460457786?= Remove _range suffix from kvm_pgtable_stage2_flush_range which is used in documentation of kvm_pgtable_stage2_flush(). There is no function named kvm_pgtable_stage2_flush_range(). Fixes: 93c66b40d728 ("KVM: arm64: Add support for stage-2 cache flushing in generic page-table") Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 4cd6762bda80..4cd62506c198 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -605,9 +605,8 @@ int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr, bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr); /** - * kvm_pgtable_stage2_flush_range() - Clean and invalidate data cache to Point - * of Coherency for guest stage-2 address - * range. + * kvm_pgtable_stage2_flush() - Clean and invalidate data cache to Point of + * Coherency for guest stage-2 address range. * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to flush. * @size: Size of the range. From patchwork Fri Apr 21 16:53:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1216004vqo; Fri, 21 Apr 2023 10:05:38 -0700 (PDT) X-Google-Smtp-Source: AKy350b1N6JIMS/4GA2+2IBg/kUVCQNcrfKhAMUMmEFQs7Fqxer/WRWOMcktgFBvzouE6qwR1i1x X-Received: by 2002:a05:6e02:1b8d:b0:326:5b1b:3cc5 with SMTP id h13-20020a056e021b8d00b003265b1b3cc5mr5785506ili.15.1682096738371; Fri, 21 Apr 2023 10:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096738; cv=none; d=google.com; s=arc-20160816; b=hX3UroDi71wfaIQGwxnnkt3uX8hmLsbfcWPz73sKh5mtevQdz7DCboZiq+jc3BCc36 w9JPSvK21Mlv4qlxsCdiuJBeKolnMrsdSOKmcuAN5uqn4jfD1ke2zCqs6pXlaiPAhiBE WE/YubgcHzhNlUcCApIjOQRwZI83JLykQFK2I2+u3WfYyG1ImEu4YE3pIepr86CfKnla 2CvYcJfo3vckIqmUiLgMmWTNqK6Oj+pWYavr7oZud3YVgOvMO4SBKiNPqCDDy611BfPg +uLpX1XdFsj/eSMVq91DlIJ1UxJDC524OfkAUXIzcsVc/ddb6+WUERYaQ3IHE/xty5Hn tC1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=gE2N+oWt7hK60UExWH8Apuvl/6Zc9TUNxMrpzS6/3Tk=; b=cNcCIfnaDEJLKdUcbfz33A8yUVda1YHutaBAZ9rTCHMFzBiXKtHlG5hzBaQFCLx8V2 wEDzx4qRYTADXwZO37bfQnULjoH3c2buSD//mqvU00V2EFaOsZiwPOrz441Siyh1eusR Y/z3DhVsB6qqNxhW6yrfnr96KQlNcLuw2TqFtIGC1ABM4b8PsU6wqfOEHg9k5awR+Cu8 Rfp2ZkwojOxIBUZWhCeSFURFUySxSfKRsoNFc0FbPnMTtGjSFmvevRoifjdrx3qB+Nh3 KQsaYxKvyWXJyJrlT2YpAP5qSbebBnf70xc90LxTvwR4CdjhgOLm2EBWpTP7BzIDyVKF whwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=gSJswkUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a92d44d000000b00326309db713si4239214ilm.84.2023.04.21.10.05.24; Fri, 21 Apr 2023 10:05:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=gSJswkUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233265AbjDURA0 (ORCPT + 99 others); Fri, 21 Apr 2023 13:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233462AbjDUQ7r (ORCPT ); Fri, 21 Apr 2023 12:59:47 -0400 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8929B1546F for ; Fri, 21 Apr 2023 09:59:24 -0700 (PDT) Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1a52677bd54so15773355ad.3 for ; Fri, 21 Apr 2023 09:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096001; x=1684688001; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gE2N+oWt7hK60UExWH8Apuvl/6Zc9TUNxMrpzS6/3Tk=; b=gSJswkUtsqGy+NAfu8py5auMpkfLQNTOEqX3uJ9U9Og/ThQanQOKyGUkdPpPpGces1 JpO7/8XndhNyW9IWOI0DDDaGS4u0h+nk5XDS2GaU/CIIPt+gKrJUunjiSwrs3SD6+lmK wh8ezPSLRVsI9k+kb5tXPIHwUoJgXCm0nOXfCCMzRUm+aSooj6bPriuueEgRC25O2ve2 DnSPWIvPfpaLGGXJeHYj1BpIYqB/JxSdn66Mw4UCn5rgAEpuf+2j/iCwE5JFs61Ikr7f Ym5a7YO8FpydTjeb6RKG5TTrhNhKd8qH9v5YJRVyuzemRjvxOLMfGgUvt+dkgVK1UreB wi4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096001; x=1684688001; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gE2N+oWt7hK60UExWH8Apuvl/6Zc9TUNxMrpzS6/3Tk=; b=EnRT0D7V6lgctOLOFSauzMoI4uSK4kKtJNDm/UFCQXMwzlx9ZpSc0RPoziLGcklHkp Sf88VF0gBFc5Lmk5rF2B8gVB2O2ZKIYZOuGHH4exZn9/g8UoxPXbNHr/s1hlF1GZQBhG Y1lR3z17/2WWevQaVfJYk5yKMB1zTzIjClFZbY/gBSRZDXdaWIFchYEP6UTutgCd6+7y UmbiIPjX/JFqkXOCCpNXFFFRgKnF94MlJK0xkjuZ0KovIFgeHr1dw/J90+roUzSwr/n6 M1qX/568/oNfj8FEk0kYJix66RUXeZToKnzJfamNYZTE6kwaOPudFpEiHuB766PKEWnW lVbA== X-Gm-Message-State: AAQBX9fLRzKHeQsrRtYi634Ka9MxeP91rHIHY9WwT+c5HTBoG1doUXVX H8qFiEKd33ZyaSTxNEnnlt92/3qEYUCk X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:ca14:b0:1a6:b4bf:8956 with SMTP id w20-20020a170902ca1400b001a6b4bf8956mr1835188pld.12.1682096001326; Fri, 21 Apr 2023 09:53:21 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:03 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-8-vipinsh@google.com> Subject: [PATCH 7/9] KVM: mmu: Move mmu lock/unlock to arch code for clear dirty log From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763806269529369467?= X-GMAIL-MSGID: =?utf-8?q?1763806269529369467?= Move mmu_lock lock and unlock calls from common code in kvm_clear_dirty_log_protect() to arch specific code in kvm_arch_mmu_enable_log_dirty_pt_masked(). None of the other code inside the for loop of kvm_arch_mmu_enable_log_dirty_pt_masked() needs mmu_lock exclusivity apart from the arch specific API call. Future commits will change clear dirty log operations under mmu read lock instead of write lock for ARM and, potentially, x86 architectures. No functional changes intended. Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 2 ++ arch/mips/kvm/mmu.c | 2 ++ arch/riscv/kvm/mmu.c | 2 ++ arch/x86/kvm/mmu/mmu.c | 3 +++ virt/kvm/dirty_ring.c | 2 -- virt/kvm/kvm_main.c | 4 ---- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 7113587222ff..dc1c9059604e 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1002,7 +1002,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { + write_lock(&kvm->mmu_lock); kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); + write_unlock(&kvm->mmu_lock); } static void kvm_send_hwpoison_signal(unsigned long address, short lsb) diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index e8c08988ed37..b8d4723d197e 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -415,11 +415,13 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { + spin_lock(&kvm->mmu_lock); gfn_t base_gfn = slot->base_gfn + gfn_offset; gfn_t start = base_gfn + __ffs(mask); gfn_t end = base_gfn + __fls(mask); kvm_mips_mkclean_gpa_pt(kvm, start, end); + spin_unlock(&kvm->mmu_lock); } /* diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 78211aed36fa..425fa11dcf9c 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -395,11 +395,13 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, gfn_t gfn_offset, unsigned long mask) { + spin_lock(&kvm->mmu_lock); phys_addr_t base_gfn = slot->base_gfn + gfn_offset; phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; gstage_wp_range(kvm, start, end); + spin_unlock(&kvm->mmu_lock); } void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 144c5a01cd77..f1dc549b01cb 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1367,6 +1367,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { + write_lock(&kvm->mmu_lock); /* * Huge pages are NOT write protected when we start dirty logging in * initially-all-set mode; must write protect them here so that they @@ -1397,6 +1398,8 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, kvm_mmu_clear_dirty_pt_masked(kvm, slot, gfn_offset, mask); else kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); + + write_unlock(&kvm->mmu_lock); } int kvm_cpu_dirty_log_size(void) diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c index c1cd7dfe4a90..d894c58d2152 100644 --- a/virt/kvm/dirty_ring.c +++ b/virt/kvm/dirty_ring.c @@ -66,9 +66,7 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask) if (!memslot || (offset + __fls(mask)) >= memslot->npages) return; - KVM_MMU_LOCK(kvm); kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset, mask); - KVM_MMU_UNLOCK(kvm); } int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, int index, u32 size) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f40b72eb0e7b..378c40e958b6 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2157,7 +2157,6 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, struct kvm_dirty_log *log) dirty_bitmap_buffer = kvm_second_dirty_bitmap(memslot); memset(dirty_bitmap_buffer, 0, n); - KVM_MMU_LOCK(kvm); for (i = 0; i < n / sizeof(long); i++) { unsigned long mask; gfn_t offset; @@ -2173,7 +2172,6 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, struct kvm_dirty_log *log) kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset, mask); } - KVM_MMU_UNLOCK(kvm); } if (flush) @@ -2268,7 +2266,6 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm, if (copy_from_user(dirty_bitmap_buffer, log->dirty_bitmap, n)) return -EFAULT; - KVM_MMU_LOCK(kvm); for (offset = log->first_page, i = offset / BITS_PER_LONG, n = DIV_ROUND_UP(log->num_pages, BITS_PER_LONG); n--; i++, offset += BITS_PER_LONG) { @@ -2291,7 +2288,6 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm, offset, mask); } } - KVM_MMU_UNLOCK(kvm); if (flush) kvm_arch_flush_remote_tlbs_memslot(kvm, memslot); From patchwork Fri Apr 21 16:53:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1214743vqo; Fri, 21 Apr 2023 10:04:14 -0700 (PDT) X-Google-Smtp-Source: AKy350bqvph/aOO7y/zd5+ewO2My/c6DVhOORPOzUVu6QGF7tLT8j/Oukk+e1usj4KSTtm3ZxJf0 X-Received: by 2002:a17:902:d50f:b0:1a1:f70c:c81a with SMTP id b15-20020a170902d50f00b001a1f70cc81amr7858436plg.9.1682096654423; Fri, 21 Apr 2023 10:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096654; cv=none; d=google.com; s=arc-20160816; b=QY4/2yWtQhEiIWfHe6SlhQFzcfPb07/YwbE02LTxwiEIxutJsvarkTvrs45iw+6kKa qL63zGxmMz8JTnhIBNSCK/2nDlvGBH6wiB95BQwqgru1tCmBrolIpzKa9Zkxua35Vdkt 6xshqYwXmWmUYnhcKVLICOJcC4bZCLUQELogHcc6UPx2hJwWjioZtD9RFqvZcXc3yc2A zrf24vd7gy3WUnfuV1jHhL4Nz4sl1fQIsGTo2Ik64E0opmYjblSPBCEu/dOQr/Eeu4wa LfTl9CQoEDKwygH+jRNuXFWVfBwmXx7QQn9aZ1/vrDPIM3wbn4EaVigsoofXDN/05jCs myMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=qC7e8besLo1ag72RTnGUdqUNToUJA9of6W+yz9oDvfY=; b=0vToRinsyQzSMMt7S20YI14gA5ROtxk4L5hkHwcgXMbRZ/5tZ78hFd8Dqf3RrqGgOh RKeD19/e53bo2FOUN1UmcKsuzT1c85KEaB7fNwTQNmzdUKZ2KW45b64zjrdLsrZw67HL mqx6hFurfGS7c813kQPRpchVM8KsAOveUwFcKdBFoOf5zAEmrzz1wv2MMyKvZ5SJ8Ehh ruVlcPQKITrkZ/xlHNUsCmdDKaOMxOLPdcUR6y+t8euF2Xe13mFQUmK4yY0Y7TgfC/iQ PqlSgtxv+LYAesMlyVm5WgVJI2wRXkmiEqw7iD9Udr+ni7sY3vrHF44GE+JnDIHnj6cl TcZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=GOG4w3Pi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170903228900b0019f28eff6f9si3983310plh.502.2023.04.21.10.03.58; Fri, 21 Apr 2023 10:04:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=GOG4w3Pi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbjDUQ4f (ORCPT + 99 others); Fri, 21 Apr 2023 12:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbjDUQ4V (ORCPT ); Fri, 21 Apr 2023 12:56:21 -0400 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A96416FA7 for ; Fri, 21 Apr 2023 09:55:44 -0700 (PDT) Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-63d30b08700so12914943b3a.1 for ; Fri, 21 Apr 2023 09:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096003; x=1684688003; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qC7e8besLo1ag72RTnGUdqUNToUJA9of6W+yz9oDvfY=; b=GOG4w3Pi6Eguql63DqPQoIqooDk2CqgiNgSILELR6uyDzdTl7Vzyy+xaIluVcSjhyC RvCjMUQV09KGtSZBzaSFu2ULcU3Y3JJpf5vC4vVKPaROFTvqMFHnKW7ByaMxXfk+EzAG 99Opx1mgfDUi8BUkLeU+cbao2T7UFu79PD2joe0F54/b7N6UHkeWd9KQWvVxtVFSqqBN 4IaiBkj2jyw7kaprKEY+F3kKrY4x7q4duJcpFclPPBqAR7WayXdFPSvh7rZW6yMWTzoe DS8bOW/ilapcUDSa/xMSHG8hRonLGXyfdOJIEtji0VIqlLUQKZGmAZZyv+1a4rxUZ26s iMZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096003; x=1684688003; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qC7e8besLo1ag72RTnGUdqUNToUJA9of6W+yz9oDvfY=; b=eu6CstwCvFdvtaAKbk8jghUE2qZmbP1Gn+rXL2yMaJuPFJhQ3lm3NsaiLevSPOwqqX KdcgGL7RoLUwNbWQsHTgcTNB1ySOWRxY1Oou9nk3bw23wj2xY5xYtjGh+fKNSE53fJ8N kiHvldoaRZRbSfOZKVxrI/BLnYzP9GnCsLslHM6Mm+zjCIp7AiBO5KbYBiIyvJt7Y1bs V5j8imSpYS79wckvsyPZIZZ63kjvkMnkYsWKYB51lr5pxHhJHJ9Qo/oyXpLdGuAw58ZN b/t2GvzDAjXZ6H88VEMHwFiCWIDXgdo2pV8aibLrHWQKFk2dP3aFGMbmedeUiU1EzNxo Ha9w== X-Gm-Message-State: AAQBX9cmztsCbpCwDTFCpnD4w2yF1XF+oVNaD2ohpsWEDNuAgURsD+cB oHkb+QSA9XuIYpfawuhogi9OHj36/AQw X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:a6a:b0:244:9909:6e60 with SMTP id o97-20020a17090a0a6a00b0024499096e60mr1346561pjo.3.1682096003103; Fri, 21 Apr 2023 09:53:23 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:04 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-9-vipinsh@google.com> Subject: [PATCH 8/9] KMV: arm64: Allow stage2_apply_range_sched() to pass page table walker flags From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763806181706020813?= X-GMAIL-MSGID: =?utf-8?q?1763806181706020813?= Allow stage2_apply_range_sched() to pass enum kvm_pgtable_walk_flags{} to stage 2 walkers. Pass 0 as the flag to make this change no-op This capability will be used in future commits to enable clear-dirty-log operation under MMU read lock. Current users of stage2_apply_range_*() API run under assumption of holding MMU write lock. Stage2 page table walkers then run under the same assumption. In future commits when clear-dirty-log operation under MMU read lock is added then there needs to be a way to pass this shared intent to page table walkers. No functional changes intended. Signed-off-by: Vipin Sharma --- arch/arm64/include/asm/kvm_pgtable.h | 12 +++++++++--- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 ++-- arch/arm64/kvm/hyp/pgtable.c | 16 ++++++++++------ arch/arm64/kvm/mmu.c | 26 ++++++++++++++++---------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 4cd62506c198..79a452d78e08 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -508,6 +508,7 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to remove the mapping. * @size: Size of the mapping. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. @@ -520,7 +521,8 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_stage2_wrprotect() - Write-protect guest stage-2 address range @@ -528,6 +530,7 @@ int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to write-protect, * @size: Size of the range. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. @@ -538,7 +541,8 @@ int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_stage2_mkyoung() - Set the access flag in a page-table entry. @@ -610,13 +614,15 @@ bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr); * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). * @addr: Intermediate physical address from which to flush. * @size: Size of the range. + * @flags: Page-table walker flags. * * The offset of @addr within a page is ignored and @size is rounded-up to * the next page boundary. * * Return: 0 on success, negative error code on failure. */ -int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size); +int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags); /** * kvm_pgtable_walk() - Walk a page-table. diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 552653fa18be..bac3c2c31cbe 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -326,11 +326,11 @@ static int host_stage2_unmap_dev_all(void) /* Unmap all non-memory regions to recycle the pages */ for (i = 0; i < hyp_memblock_nr; i++, addr = reg->base + reg->size) { reg = &hyp_memory[i]; - ret = kvm_pgtable_stage2_unmap(pgt, addr, reg->base - addr); + ret = kvm_pgtable_stage2_unmap(pgt, addr, reg->base - addr, 0); if (ret) return ret; } - return kvm_pgtable_stage2_unmap(pgt, addr, BIT(pgt->ia_bits) - addr); + return kvm_pgtable_stage2_unmap(pgt, addr, BIT(pgt->ia_bits) - addr, 0); } struct kvm_mem_range { diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 3d61bd3e591d..3a585e1fba11 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1024,12 +1024,14 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, return 0; } -int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { struct kvm_pgtable_walker walker = { .cb = stage2_unmap_walker, .arg = pgt, - .flags = KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_TABLE_POST, + .flags = flags | KVM_PGTABLE_WALK_LEAF | + KVM_PGTABLE_WALK_TABLE_POST, }; return kvm_pgtable_walk(pgt, addr, size, &walker); @@ -1108,11 +1110,12 @@ static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, return 0; } -int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { return stage2_update_leaf_attrs(pgt, addr, size, 0, KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, - NULL, NULL, 0); + NULL, NULL, flags); } kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) @@ -1193,11 +1196,12 @@ static int stage2_flush_walker(const struct kvm_pgtable_visit_ctx *ctx, return 0; } -int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size) +int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size, + enum kvm_pgtable_walk_flags flags) { struct kvm_pgtable_walker walker = { .cb = stage2_flush_walker, - .flags = KVM_PGTABLE_WALK_LEAF, + .flags = flags | KVM_PGTABLE_WALK_LEAF, .arg = pgt, }; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index dc1c9059604e..e0189cdda43d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -48,7 +48,9 @@ static phys_addr_t stage2_range_addr_end(phys_addr_t addr, phys_addr_t end) */ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end, - int (*fn)(struct kvm_pgtable *, u64, u64), + enum kvm_pgtable_walk_flags flags, + int (*fn)(struct kvm_pgtable *, u64, u64, + enum kvm_pgtable_walk_flags), bool resched) { struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu); @@ -61,7 +63,7 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, return -EINVAL; next = stage2_range_addr_end(addr, end); - ret = fn(pgt, addr, next - addr); + ret = fn(pgt, addr, next - addr, flags); if (ret) break; @@ -72,8 +74,8 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, return ret; } -#define stage2_apply_range_resched(mmu, addr, end, fn) \ - stage2_apply_range(mmu, addr, end, fn, true) +#define stage2_apply_range_resched(mmu, addr, end, flags, fn) \ + stage2_apply_range(mmu, addr, end, flags, fn, true) static bool memslot_is_logging(struct kvm_memory_slot *memslot) { @@ -236,7 +238,7 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 lockdep_assert_held_write(&kvm->mmu_lock); WARN_ON(size & ~PAGE_MASK); - WARN_ON(stage2_apply_range(mmu, start, end, kvm_pgtable_stage2_unmap, + WARN_ON(stage2_apply_range(mmu, start, end, 0, kvm_pgtable_stage2_unmap, may_block)); } @@ -251,7 +253,8 @@ static void stage2_flush_memslot(struct kvm *kvm, phys_addr_t addr = memslot->base_gfn << PAGE_SHIFT; phys_addr_t end = addr + PAGE_SIZE * memslot->npages; - stage2_apply_range_resched(&kvm->arch.mmu, addr, end, kvm_pgtable_stage2_flush); + stage2_apply_range_resched(&kvm->arch.mmu, addr, end, 0, + kvm_pgtable_stage2_flush); } /** @@ -932,10 +935,13 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, * @mmu: The KVM stage-2 MMU pointer * @addr: Start address of range * @end: End address of range + * @flags: Page-table walker flags. */ -static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end) +static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end, + enum kvm_pgtable_walk_flags flags) { - stage2_apply_range_resched(mmu, addr, end, kvm_pgtable_stage2_wrprotect); + stage2_apply_range_resched(mmu, addr, end, flags, + kvm_pgtable_stage2_wrprotect); } /** @@ -964,7 +970,7 @@ static void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot) end = (memslot->base_gfn + memslot->npages) << PAGE_SHIFT; write_lock(&kvm->mmu_lock); - stage2_wp_range(&kvm->arch.mmu, start, end); + stage2_wp_range(&kvm->arch.mmu, start, end, 0); write_unlock(&kvm->mmu_lock); kvm_flush_remote_tlbs(kvm); } @@ -988,7 +994,7 @@ static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; - stage2_wp_range(&kvm->arch.mmu, start, end); + stage2_wp_range(&kvm->arch.mmu, start, end, 0); } /* From patchwork Fri Apr 21 16:53:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1213393vqo; Fri, 21 Apr 2023 10:02:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bUwOChhe+g8Br1NcMRutESa3CMp5TLysnjFqhWjZCgSoueUmPbYk2R/bhYglNcQim4vvXR X-Received: by 2002:a05:7500:c8e:b0:fc:bcd8:a7df with SMTP id fu14-20020a0575000c8e00b000fcbcd8a7dfmr382345gab.14.1682096572266; Fri, 21 Apr 2023 10:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096572; cv=none; d=google.com; s=arc-20160816; b=S6PKfdeyNMPbYbpon2juAGFXoZfWH3vwCtwfZwM0w0nSWwUY0L4tA398BKdr1roi4h eTFWk1HfhAMs3xANW1D0U/ULjwP4vxBspIx18ozxOKeNdJ2TvjKsnadgWpSSduW/3xK+ knXVKUmpd1EpK25AM41yv4IYim6Dh02r+hAyzYAf+zjt5/m5J/Q8oBEJAkkPfpM9OO4z +e7/UuMDR1diIwg8iXHmHF9O32N430j8zTkyQIJqQiaXUlugLPF/BBIyyn3mwILWmgv+ d6Rwri12slOrZkJwDJXBZCEQslo5so6By7WOTT4Ngn2thdKDYcUYQMLcEu5fyGsPdaah Jh8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=EZkpp0Q8jjYvxCvjV0ny/+Rc/wVVpL1bL7ck4xeVhlc=; b=zR+yL80rkFfsQWIj+neYTmpVsSCBFmiIrodJFeSxna1e7Q3njZ7lknMDVDCUcKoJFc 6J1/pDJ2U5NZBeaVn4O8Lzn//4N6gojeQoAV0ke/ZA+YqVg+AprDV7UiAMYXTnXEDBhc tnfKQqA+NwGX8bURVtqKZSNx1LF2mp/f5Htxsdy89i99gMxfgsCcY/D3uYiQ07nTFGRN FzOCCQSimJFZQ9rlY2CfRItp4Ry0fW+8y8pEA2bpiDP/o57dIvL5Vr6e4JGPKlCZqgkL rZ7iPhiYFI6UF1sG4f5z3ObyeFzgjYYFx3F4tnq64vOhgoiUs1QHvGsuIoyf74Ybffs4 Uj/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=0h1fkH+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020ab073d3000000b00773e09e0565si1074318uaq.156.2023.04.21.10.02.37; Fri, 21 Apr 2023 10:02:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=0h1fkH+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233461AbjDUQzN (ORCPT + 99 others); Fri, 21 Apr 2023 12:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233417AbjDUQyn (ORCPT ); Fri, 21 Apr 2023 12:54:43 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF491545C for ; Fri, 21 Apr 2023 09:54:25 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-24749db972cso1352524a91.2 for ; Fri, 21 Apr 2023 09:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096005; x=1684688005; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EZkpp0Q8jjYvxCvjV0ny/+Rc/wVVpL1bL7ck4xeVhlc=; b=0h1fkH+Qg9TAAOhRy5ByqB0jrA5qVCSK4v4VOevyiT2ApjSQTkdNJB5NveNHYdDJyn UJHQdihO3xA3kzsZEepsUYjUUldoQQHE3IwikHmH626x/P3dqcuE74kUFvi/fYfmL8id EDHpOrTTDrdls8Ay6MgcRCV+nPsBif06WnlTwtqTPlBkRDbsQd0Ihsksz1E+BPVTlwL+ Wr1jDKNxfs+qyRuwYH973UQwgCLkK4mXV3n/qkGEbaFtetzvIDazfRsZNp9s0jwVrFs5 k56stUv4Ja+Quv0wmKFN8uJmrJL9UvFWW6XEpyc/9yhzn8gHY1vEcRlztKntO6uIDVGX jZXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096005; x=1684688005; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EZkpp0Q8jjYvxCvjV0ny/+Rc/wVVpL1bL7ck4xeVhlc=; b=h5EZqzOjlG3qafMG1J+G2BBjCXtSGGLtkrQhihXH3vpQrpZ2cJtrUIwuciREum8k+x xiPknoxvkxHmZmcGuDegRR2H/VPBNn0uLY25NTf8TXOeQDHm0aZM3WWqIIUO6AP/eucA RJyiB6L8ebG2ntQJkyP7CW5U2fE4LVryl51KIRbmiOVV6TEwKjyscDhtjteuarOssxMQ gPqN4NT28bMUWb/oDp8HG6QEt4G1PVP7wOzgHb+55JkXwZ2a3GFr8DpSjxzK5Dq/05jY SnNnteZovG/Jr1mH90eO7dm66lpb7bm9mEwhHnJlSNZV908sW39KQUfh71hMeoYwxJaw c9Og== X-Gm-Message-State: AAQBX9dC2eOn4dD2t9Ra7GYF/hxnSsOHj2XYAfAJROxx1RUyCWiyaFWk vfyaAMtR7aYhD4+xWlClXXnsDB2hY8Cj X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:690d:b0:23f:a851:4f04 with SMTP id r13-20020a17090a690d00b0023fa8514f04mr1467442pjj.3.1682096004881; Fri, 21 Apr 2023 09:53:24 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:05 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-10-vipinsh@google.com> Subject: [PATCH 9/9] KVM: arm64: Run clear-dirty-log under MMU read lock From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763806095183382883?= X-GMAIL-MSGID: =?utf-8?q?1763806095183382883?= Take MMU read lock for write protecting PTEs and use shared page table walker for clearing dirty logs. Clearing dirty logs are currently performed under MMU write locks. This means vCPUs write protection fault, which also take MMU read lock, will be blocked during this operation. This causes guest degradation and especially noticeable on VMs with lot of vCPUs. Taking MMU read lock will allow vCPUs to execute parallelly and reduces the impact on vCPUs performance. Tested improvement on a ARM Ampere Altra host (64 CPUs, 256 GB memory and single NUMA node) via dirty_log_perf_test for 48 vCPU, 96 GB memory, 8GB clear chunk size, 1 second wait between Clear-Dirty-Log calls and configuration: Test command: ./dirty_log_perf_test -s anonymous_hugetlb_2mb -b 2G -v 48 -l 1 -k 8G -j -m 2 Before: Total pages touched: 50331648 (Reads: 0, Writes: 50331648) After: Total pages touched: 125304832 (Reads: 0, Writes: 125304832) Signed-off-by: Vipin Sharma --- arch/arm64/kvm/mmu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index e0189cdda43d..3f2117d93998 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -67,8 +67,12 @@ static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, if (ret) break; - if (resched && next != end) - cond_resched_rwlock_write(&kvm->mmu_lock); + if (resched && next != end) { + if (flags & KVM_PGTABLE_WALK_SHARED) + cond_resched_rwlock_read(&kvm->mmu_lock); + else + cond_resched_rwlock_write(&kvm->mmu_lock); + } } while (addr = next, addr != end); return ret; @@ -994,7 +998,7 @@ static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; - stage2_wp_range(&kvm->arch.mmu, start, end, 0); + stage2_wp_range(&kvm->arch.mmu, start, end, KVM_PGTABLE_WALK_SHARED); } /* @@ -1008,9 +1012,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { - write_lock(&kvm->mmu_lock); + read_lock(&kvm->mmu_lock); kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); - write_unlock(&kvm->mmu_lock); + read_unlock(&kvm->mmu_lock); } static void kvm_send_hwpoison_signal(unsigned long address, short lsb)