From patchwork Tue Jan 26 13:41:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanan Wang X-Patchwork-Id: 12046617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 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,URIBL_BLOCKED,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 772E3C433E0 for ; Tue, 26 Jan 2021 13:44:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 3DEF12255F for ; Tue, 26 Jan 2021 13:44:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DEF12255F Authentication-Results: mail.kernel.org; dmarc=none (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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject: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=da7gCt8q/S7zRScMFhwLffuPFQSbTFBTpZ/qvXgUm8o=; b=yEdVxjIIawI0cNk5yrWZQwqwq8 EAqjNQIfGU8Bm2fIdEobIMBcfUnzZGCg/mDEO1mcqCmV3R5WKoHMJysW9FI1EKq/mTa2c/ZgqB8qj bsI60fQe3S1a+4gDdAi1bcK1OJPMGFEdopc+biXgFsVyN/4pSwbL3scG+mk33vs347BhZrJ0jtZVM UIDSjlqkbmv8ujItBU7DwfWP7EjWCAvXVHJkzW2LEeWYAOCL7UZpnSk+vwvu3Qeqz8UMUb4oNZA1b 6mnF/jLPakDZsFCmoTBe29HVWWPmadZrYhTA4NITZdjQ6jcB0iufyj1mfBkfbGz6YCgGCkRa5LmaP D/uvvgzA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l4Oc8-0001pC-S9; Tue, 26 Jan 2021 13:42:36 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l4Obn-0001g1-BJ for linux-arm-kernel@lists.infradead.org; Tue, 26 Jan 2021 13:42:20 +0000 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DQ7DT5ZtPzjCXP; Tue, 26 Jan 2021 21:41:13 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 26 Jan 2021 21:42:04 +0800 From: Yanan Wang To: , , , , Marc Zyngier , Will Deacon , Catalin Marinas Subject: [RFC PATCH v1 0/5] Enable CPU TTRem feature for stage-2 Date: Tue, 26 Jan 2021 21:41:57 +0800 Message-ID: <20210126134202.381996-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-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210126_084217_480279_9F6F672F X-CRM114-Status: GOOD ( 13.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Suzuki K Poulose , Yanan Wang , yezengruan@huawei.com, James Morse , yuzenghui@huawei.com, wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi all, This series enable CPU TTRem feature for stage-2 page table and a RFC is sent for some comments, thanks. The ARMv8.4 TTRem feature offers 3 levels of support when changing block size without changing any other parameters that are listed as requiring use of break-before-make. And I found that maybe we can use this feature to make some improvement for stage-2 page table and the following explains what TTRem exactly does for the improvement. If migration of a VM with hugepages is canceled midway, KVM will adjust the stage-2 table mappings back to block mappings. We currently use BBM to replace the table entry with a block entry. Take adjustment of 1G block mapping as an example, with BBM procedures, we have to invalidate the old table entry first, flush TLB and unmap the old table mappings, right before installing the new block entry. So there will be a bit long period when the old table entry is invalid before installation of the new block entry, if other vCPUs access any guest page within the 1G range during this period and find the table entry invalid, they will all exit from guest with a translation fault. Actually, these translation faults are not necessary, because the block mapping will be built later. Besides, KVM will still try to build 1G block mappings for these spurious translation faults, and will perform cache maintenance operations, page table walk, etc. In summary, the spurious faults are caused by invalidation in BBM procedures. Approaches of TTRem level 1,2 ensure that there will not be a moment when the old table entry is invalid before installation of the new block entry. However, level-2 method will possibly lead to a TLB conflict which is bothering, so we use nT both at level-1 and level-2 case to avoid handling TLB conflict aborts. For an implementation which meets level 1 or level 2, the CPU has two responses to choose when accessing a block table entry with nT bit set: Firstly, CPU will generate a translation fault, the effect of this response is simier to BBM. Secondly, CPU can use the block entry for translation. So with the second kind of implementation, the above described spurious translations can be prevented. Yanan Wang (5): KVM: arm64: Detect the ARMv8.4 TTRem feature KVM: arm64: Add an API to get level of TTRem supported by hardware KVM: arm64: Support usage of TTRem in guest stage-2 translation KVM: arm64: Add handling of coalescing tables into a block mapping KVM: arm64: Adapt page-table code to new handling of coalescing tables arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/cpufeature.h | 13 ++++++ arch/arm64/kernel/cpufeature.c | 10 +++++ arch/arm64/kvm/hyp/pgtable.c | 62 +++++++++++++++++++++++------ 4 files changed, 74 insertions(+), 14 deletions(-)