From patchwork Thu Jan 14 12:13:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanan Wang X-Patchwork-Id: 12019385 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 2C614C433E0 for ; Thu, 14 Jan 2021 12:15:58 +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 BD96323877 for ; Thu, 14 Jan 2021 12:15:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD96323877 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=USZ0bSfOYl3lBNIQch9aMDBrD9xJOqDxxefrLCFLJDY=; b=PUba2C4G5x4cwnJuKt5Mg2ah3r L6Ilzy+lLTa6hhBbyZ3tG14i6LQvucM+/E97sxsZGtEqphW/vm2W3uKb3dZWmQnKiF+wWTym/lN8c kWuu4i2Xu4Mppa91RFScmtE3ZMNwEnrK2RQG+cVSrILr8qgB1ACyv0PKeB/KCQ12RX4z+My4UNshh byiZ1kCkmDkmiROSc0ran1ljmpuk3MbNJqg/TvS5LqYTSCxT/wYhrUhufN/mR36FzqLmAiZq0Kb7v iZ6HOIvQtvlGUNEIsYDXMlwhaimLjEd1Dz3ZkPkev6gXZOFsKY1BKzRxKSSdENT/tcL8m0Cbaqhtp /Xxf//1Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l01W8-0007AK-HH; Thu, 14 Jan 2021 12:14:20 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l01Vz-000746-3B for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 12:14:12 +0000 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DGjrD4zP5z7VFy; Thu, 14 Jan 2021 20:13:00 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Thu, 14 Jan 2021 20:13:52 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Catalin Marinas" , , , , Subject: [PATCH v3 0/3] Some optimization for stage-2 translation Date: Thu, 14 Jan 2021 20:13:47 +0800 Message-ID: <20210114121350.123684-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-20210114_071411_445130_461D7668 X-CRM114-Status: GOOD ( 13.45 ) 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: Gavin Shan , Quentin Perret , 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, This patch series(v3) make some optimization for stage-2 translation. About patch-1: Procedures of hyp stage-1 map and guest stage-2 map are quite different, but they are now tied closely by function kvm_set_valid_leaf_pte(). So adjust the relative code for ease of code maintenance in the future. About patch-2: There have been the separate map handler and perms handler used independently for mapping and relaxing permissions in the new page-table infrastructure for stage-2, yet there is still a specific case where we end up changing the access permissions in the map path, and something unsatisfactory could happen because of current handling for this case. To solve above problem, we can filter out this case from the map path and abort the PTE update. Instead, let the vCPU enter back the guest and it will exit next time to go through the relax_perms path if still needed. About patch-3: We now set the pfn dirty and mark the page dirty before calling fault handlers in user_mem_abort(), so we might end up having spurious dirty pages if update of permissions or mapping has failed. Let's move these two operations after the fault handlers, and they will be done only if the fault has been handled successfully. When an -EAGAIN errno is returned from the map handler, we hope to the vcpu to enter guest directly instead of exiting back to userspace, so adjust the return value at the end of function. --- Changelogs v2->v3: - Rebased on top of v5.11-rc3 - Refine the commit messages - Make some adjustment about return value in patch-2 and patch-3 - v2: https://lore.kernel.org/lkml/20201216122844.25092-1-wangyanan55@huawei.com/ v1->v2: - Make part of the diff a seperate patch (patch-1) - Add Will's Signed-off-by for patch-1 - Return an errno when meeting changing permissions case in map path - Add a new patch (patch-3) - v1: https://lore.kernel.org/lkml/20201211080115.21460-1-wangyanan55@huawei.com/ --- Yanan Wang (3): KVM: arm64: Adjust partial code of hyp stage-1 map and guest stage-2 map KVM: arm64: Filter out the case of only changing permissions from stage-2 map path KVM: arm64: Mark the page dirty only if the fault is handled successfully arch/arm64/include/asm/kvm_pgtable.h | 5 ++ arch/arm64/kvm/hyp/pgtable.c | 83 ++++++++++++++++------------ arch/arm64/kvm/mmu.c | 13 +++-- 3 files changed, 60 insertions(+), 41 deletions(-)