Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2531264rwr; Fri, 21 Apr 2023 10:04:57 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/WmtDQVoF4aGLeqHsbD7yV2VQK/j5N0yFKF3btR2aAeIm7ASuAasmXyKm+eMafAOhKnL2 X-Received: by 2002:a17:902:d2ce:b0:1a0:7663:731b with SMTP id n14-20020a170902d2ce00b001a07663731bmr6631015plc.5.1682096697000; Fri, 21 Apr 2023 10:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682096696; cv=none; d=google.com; s=arc-20160816; b=JNOhU9oqqthmhNfO7BP4n8rdGgv0StyKxu1S8+6RR26/eWtol6IX84zFvy79jtObCb iWbnV2bcuqmoV7VMyJOiKoCCAkHrZTPhDel+aW5vJfMDgXendjceFw349Sqta2yMKk+L 1L3CB8PIctNr4y4Mmt54xke2h4tMtWMOz6oTICg9UHRrcgOWJQnfiGxsgcOZURiFItn1 JrXaXwwubJRsY0Vdr15Xx+lKWYtt7tLsRHdkDhIn8rc50U3LufO2UPReXkfz2r5Obigy DSU3g8wU9LlxopOd0RO/t7aby1FwKAT4Cmp04wx0v2jGtyFh4p9gz9nhnRE2N1w0JbDg NoHQ== 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:mime-version:date :dkim-signature; bh=Bpz9GCI4OFqr9DlnIkg8fh50O4zOZAPmw/GqyWI1sUY=; b=sVFipfzQ8XoOwXmu0eYz1da4cnOSZYPoUu4NeBksWYWFLxJ26SM+U4IzanuXA3TVpx pJaSA3PVE8BRuG2FvPWPP+KbmdK7Mxe8s6rInyDDjWhRO5cFONQbxE2z0cshnPWdrjxo P23iawqNKz/ldrJOKuZgYrYRHdZQD1IxUeRctZvFWbI5IbSMZpKpVrGx1ynKVFN8WWSJ Rdy0D6xIwu2qSiUgSPRAWX2TqoJZo8U/zyVwYnzMzIctL8VD/SYdia6kox+1iOXcWb7Y 8v5Yqw1omX69O6ugAQjoLsr+ZId4U2XWKWo0tbrFgNp1DyYwVoc/RkokcBk2Y/d1yhww 8DqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=DGn7gCyk; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a170902e74900b001a1cbc5c04fsi4919776plf.341.2023.04.21.10.04.45; Fri, 21 Apr 2023 10:04:56 -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=DGn7gCyk; 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 S233257AbjDUQ7f (ORCPT + 99 others); Fri, 21 Apr 2023 12:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233241AbjDUQ73 (ORCPT ); Fri, 21 Apr 2023 12:59:29 -0400 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97EAE15A0C for ; Fri, 21 Apr 2023 09:59:08 -0700 (PDT) Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-63b5e149dc2so1757607b3a.0 for ; Fri, 21 Apr 2023 09:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682095989; x=1684687989; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Bpz9GCI4OFqr9DlnIkg8fh50O4zOZAPmw/GqyWI1sUY=; b=DGn7gCykqxE1wl2tXEHxtzFbscSQI+JYs1BOyBXnwpOUa0v37O5EWPBn/ZgODYtQlN ucm2bl+oRpYs66hkDH2OsTMMwYnJjHqmfL1Gfoz55eaPsC+KkP0XkEqAwZ6rs8pd6Rpz FUqoTwNDb4fdpZO/bATUsOleiUawwODIJsv2oBaDLHov514nHeOp01TeHl5biXsvmD+B drB6ioShN8gZ615eSTgzwj90uRL3MtckEF9+PdrDWulnCx0CuSxldhcUkAHan3z7jBnk tHJsR2+7JQcAF/jPDdgXfTyng+EIcBFq/MixhtIbZMOElAUZCqnEM9rZEPv1BqgcbQ1G Ek/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682095989; x=1684687989; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Bpz9GCI4OFqr9DlnIkg8fh50O4zOZAPmw/GqyWI1sUY=; b=k+whUXXKeUMVfKcH2P2fvRQASSGtnZlzUzcZGHx0ERBTXlemcj/4PqNJ5I5suQK7TJ AMkCOBs74bbx+IyGbFKvLzMTbAU97iQK4EAQl0MNvdzYX3aQX8dls0MrqlHCqdHwL87J XEt1jNVg0NZZeMEeLOD2A+d7u8yVxhkSJxVir7pOGY/KMSoWJccifgl3nOR7MO11Et4w SjOv/KmCPX6Q2G25LkLGTnFem0sNAJh6hEYWu1k1G66RNkI+7UtPTzDM4ejl5iRHNPVj V0Z/pqsFUkZkIWymBJclfeCxobBCy/1GffFkLIIvH2jaC+OpO1GXEBSnVGBPiUDq8fDk bh2Q== X-Gm-Message-State: AAQBX9eWkX6UGxQsl5V+yFBLV5if0362UFNNM1rsYxTn8jD4VrEyoI5E hG/TureP0fRIQWXqYdQbhFG7qutTmMsU X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:b94:b0:63d:397a:8fdd with SMTP id g20-20020a056a000b9400b0063d397a8fddmr2339440pfj.0.1682095989138; Fri, 21 Apr 2023 09:53:09 -0700 (PDT) Date: Fri, 21 Apr 2023 09:52:56 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-1-vipinsh@google.com> Subject: [PATCH 0/9] KVM: arm64: Use MMU read lock for clearing dirty logs 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 Content-Type: text/plain; charset="UTF-8" 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 This patch series improves guest vCPUs performances on Arm during clearing dirty log operations by taking MMU read lock instead of MMU write lock. vCPUs write protection faults are fixed in Arm using MMU read locks. However, when userspace is clearing dirty logs via KVM_CLEAR_DIRTY_LOG ioctl, then kernel code takes MMU write lock. This will block vCPUs write protection faults and degrade guest performance. This degradation gets worse as guest VM size increases in terms of memory and vCPU count. In this series, MMU read lock adoption is made possible by using KVM_PGTABLE_WALK_SHARED flag in page walker. Patches 1 to 5: These patches are modifying dirty_log_perf_test. Intent is to mimic production scenarios where guest keeps on executing while userspace threads collect and clear dirty logs independently. Three new command line options are added: 1. j: Allows to run guest vCPUs and main thread collecting dirty logs independently of each other after initialization is complete. 2. k: Allows to clear dirty logs in smaller chunks compared to existing whole memslot clear in one call. 3. l: Allows to add customizable wait time between consecutive clear dirty log calls to mimic sending dirty memory to destination. Patch 7-8: These patches refactor code to move MMU lock operations to arch specific code, refactor Arm's page table walker APIs, and change MMU write lock for clearing dirty logs to read lock. Patch 8 has results showing improvements based on dirty_log_perf_test. Vipin Sharma (9): KVM: selftests: Allow dirty_log_perf_test to clear dirty memory in chunks KVM: selftests: Add optional delay between consecutive Clear-Dirty-Log calls KVM: selftests: Pass count of read and write accesses from guest to host KVM: selftests: Print read and write accesses of pages by vCPUs in dirty_log_perf_test KVM: selftests: Allow independent execution of vCPUs in dirty_log_perf_test KVM: arm64: Correct the kvm_pgtable_stage2_flush() documentation KVM: mmu: Move mmu lock/unlock to arch code for clear dirty log KMV: arm64: Allow stage2_apply_range_sched() to pass page table walker flags KVM: arm64: Run clear-dirty-log under MMU read lock arch/arm64/include/asm/kvm_pgtable.h | 17 ++- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 +- arch/arm64/kvm/hyp/pgtable.c | 16 ++- arch/arm64/kvm/mmu.c | 36 ++++-- arch/mips/kvm/mmu.c | 2 + arch/riscv/kvm/mmu.c | 2 + arch/x86/kvm/mmu/mmu.c | 3 + .../selftests/kvm/dirty_log_perf_test.c | 108 ++++++++++++++---- .../testing/selftests/kvm/include/memstress.h | 13 ++- tools/testing/selftests/kvm/lib/memstress.c | 43 +++++-- virt/kvm/dirty_ring.c | 2 - virt/kvm/kvm_main.c | 4 - 12 files changed, 185 insertions(+), 65 deletions(-) base-commit: 95b9779c1758f03cf494e8550d6249a40089ed1c -- 2.40.0.634.g4ca3ef3211-goog