From patchwork Thu Jun 17 10:58:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanan Wang X-Patchwork-Id: 12327453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0117C2B9F4 for ; Thu, 17 Jun 2021 11:00:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 77AC7613E2 for ; Thu, 17 Jun 2021 11:00:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 77AC7613E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=c4Zf6cB2SAIGFM9vesmtdHCleyMquUzQrYisFXC6hYw=; b=a6gwaRxLafJrkR 6u3sEGeDiQBCr4gVdGh9ijnqhJD0zrEVLnlv7dLl374maJ1HxtS4tv/65vt0aXb1Pa7QtwxUuPBu2 qrc35dn+AmKbXCOHWERZEnNo5F1NU1dJqK7qeIo8QqQ0Nc7qH943JhXaQWms7KPOFUgaRk7Q2MneH 8Na0SFIpVut5/Cxbqbc/wS9btkOJQR7Oe3GuUeLtRdLNOUjlUqJpxbn0iFYUTBiu37axg2+anV3Lc c81q2q6r5pTmuBg197K2iJqTzzbhtRQHKedXmMlJV70uoikFmv6EyilQNjmcEaYogYE6/4hkS+vJ+ 5fXFmFpTDvkghRTsazrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltpjW-009xVQ-Ih; Thu, 17 Jun 2021 10:58:50 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltpjG-009xP6-4a for linux-arm-kernel@lists.infradead.org; Thu, 17 Jun 2021 10:58:37 +0000 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G5JnK2bvcz1BNRZ; Thu, 17 Jun 2021 18:53:25 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 17 Jun 2021 18:58:27 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 17 Jun 2021 18:58:26 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Quentin Perret" , Alexandru Elisei , , , , CC: Catalin Marinas , James Morse , Julien Thierry , "Suzuki K Poulose" , Gavin Shan , , , , Yanan Wang Subject: [PATCH v7 0/4] KVM: arm64: Improve efficiency of stage2 page table Date: Thu, 17 Jun 2021 18:58:20 +0800 Message-ID: <20210617105824.31752-1-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210617_035834_574831_E6716257 X-CRM114-Status: GOOD ( 11.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello, This series makes some efficiency improvement of guest stage-2 page table code, and there are some test results to quantify the benefit. Description for this series: We currently uniformly permorm CMOs of D-cache and I-cache in function user_mem_abort before calling the fault handlers. If we get concurrent guest faults(e.g. translation faults, permission faults) or some really unnecessary guest faults caused by BBM, CMOs for the first vcpu are necessary while the others later are not. By moving CMOs to the fault handlers, we can easily identify conditions where they are really needed and avoid the unnecessary ones. As it's a time consuming process to perform CMOs especially when flushing a block range, so this solution reduces much load of kvm and improve efficiency of the stage-2 page table code. We can imagine two specific scenarios which will gain much benefit: 1) In a normal VM startup, this solution will improve the efficiency of handling guest page faults incurred by vCPUs, when initially populating stage-2 page tables. 2) After live migration, the heavy workload will be resumed on the destination VM, however all the stage-2 page tables need to be rebuilt at the moment. So this solution will ease the performance drop during resuming stage. The following are test results originally from v3 [1] to represent how much benefit was introduced by movement of CMOs. We can use KVM selftest to simulate a scenario of concurrent guest memory access and test the execution time that KVM uses to create new stage-2 mappings, update the existing mappings, split/rebuild huge mappings during/after dirty logging. hardware platform: HiSilicon Kunpeng920 Server host kernel: Linux mainline v5.12-rc2 test tools: KVM selftest [2] [1] https://lore.kernel.org/lkml/20210326031654.3716-1-wangyanan55@huawei.com/ [2] https://lore.kernel.org/lkml/20210302125751.19080-1-wangyanan55@huawei.com/ cmdline: ./kvm_page_table_test -m 4 -s anonymous -b 1G -v 80 (80 vcpus, 1G memory, page mappings(normal 4K)) KVM_CREATE_MAPPINGS: before 104.35s -> after 90.42s +13.35% KVM_UPDATE_MAPPINGS: before 78.64s -> after 75.45s + 4.06% cmdline: ./kvm_page_table_test -m 4 -s anonymous_thp -b 20G -v 40 (40 vcpus, 20G memory, block mappings(THP 2M)) KVM_CREATE_MAPPINGS: before 15.66s -> after 6.92s +55.80% KVM_UPDATE_MAPPINGS: before 178.80s -> after 123.35s +31.00% KVM_REBUILD_BLOCKS: before 187.34s -> after 131.76s +30.65% cmdline: ./kvm_page_table_test -m 4 -s anonymous_hugetlb_1gb -b 20G -v 40 (40 vcpus, 20G memory, block mappings(HUGETLB 1G)) KVM_CREATE_MAPPINGS: before 104.54s -> after 3.70s +96.46% KVM_UPDATE_MAPPINGS: before 174.20s -> after 115.94s +33.44% KVM_REBUILD_BLOCKS: before 103.95s -> after 2.96s +97.15% --- Changelogs: v6->v7: - refine the new callback names and the related comments (Marc) - refine the patch subject and commit messages - v6: https://lore.kernel.org/lkml/20210616095200.38008-1-wangyanan55@huawei.com/ v5->v6: - convert the guest CMO functions into callbacks in kvm_pgtable_mm_ops (Marc) - drop patch #6 in v5 since we are stuffing topup into mmu_lock section (Quentin) - rebased on latest kvmarm/tree - v5: https://lore.kernel.org/lkml/20210415115032.35760-1-wangyanan55@huawei.com/ v4->v5: - rebased on the latest kvmarm/tree to adapt to the new stage-2 page-table code - v4: https://lore.kernel.org/lkml/20210409033652.28316-1-wangyanan55@huawei.com --- Yanan Wang (4): KVM: arm64: Introduce two cache maintenance callbacks KVM: arm64: Introduce mm_ops member for structure stage2_attr_data KVM: arm64: Tweak parameters of guest cache maintenance functions KVM: arm64: Move guest CMOs to the fault handlers arch/arm64/include/asm/kvm_mmu.h | 9 +---- arch/arm64/include/asm/kvm_pgtable.h | 42 ++++++++++++--------- arch/arm64/kvm/hyp/pgtable.c | 48 ++++++++++++++++++------ arch/arm64/kvm/mmu.c | 55 +++++++++++++--------------- 4 files changed, 89 insertions(+), 65 deletions(-)