From patchwork Thu Jan 17 13:55:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhuang Yanying X-Patchwork-Id: 10768289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 446CE13B4 for ; Thu, 17 Jan 2019 14:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 348482FF7C for ; Thu, 17 Jan 2019 14:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 285062FF83; Thu, 17 Jan 2019 14:00:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB01D2FF7C for ; Thu, 17 Jan 2019 14:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbfAQOAg (ORCPT ); Thu, 17 Jan 2019 09:00:36 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:35842 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726917AbfAQOAe (ORCPT ); Thu, 17 Jan 2019 09:00:34 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 4A32C98030C6F6F75A08; Thu, 17 Jan 2019 22:00:31 +0800 (CST) Received: from localhost (10.177.21.2) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.408.0; Thu, 17 Jan 2019 22:00:24 +0800 From: Zhuangyanying To: , , CC: , , , Subject: [PATCH 1/4] KVM: MMU: correct the behavior of mmu_spte_update_no_track Date: Thu, 17 Jan 2019 13:55:28 +0000 Message-ID: <1547733331-16140-2-git-send-email-ann.zhuangyanying@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1547733331-16140-1-git-send-email-ann.zhuangyanying@huawei.com> References: <1547733331-16140-1-git-send-email-ann.zhuangyanying@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.21.2] X-CFilter-Loop: Reflected Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong Current behavior of mmu_spte_update_no_track() does not match the name of _no_track() as actually the A/D bits are tracked and returned to the caller This patch introduces the real _no_track() function to update the spte regardless of A/D bits and rename the original function to _track() The _no_track() function will be used by later patches to update upper spte which need not care of A/D bits indeed Signed-off-by: Xiao Guangrong --- arch/x86/kvm/mmu.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ce770b4..eeb3bac 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -731,10 +731,29 @@ static void mmu_spte_set(u64 *sptep, u64 new_spte) } /* - * Update the SPTE (excluding the PFN), but do not track changes in its + * Update the SPTE (excluding the PFN) regardless of accessed/dirty + * status which is used to update the upper level spte. + */ +static void mmu_spte_update_no_track(u64 *sptep, u64 new_spte) +{ + u64 old_spte = *sptep; + + WARN_ON(!is_shadow_present_pte(new_spte)); + + if (!is_shadow_present_pte(old_spte)) { + mmu_spte_set(sptep, new_spte); + return; + } + + __update_clear_spte_fast(sptep, new_spte); +} + +/* + * Update the SPTE (excluding the PFN), the original value is + * returned, based on it, the caller can track changes of its * accessed/dirty status. */ -static u64 mmu_spte_update_no_track(u64 *sptep, u64 new_spte) +static u64 mmu_spte_update_track(u64 *sptep, u64 new_spte) { u64 old_spte = *sptep; @@ -769,7 +788,7 @@ static u64 mmu_spte_update_no_track(u64 *sptep, u64 new_spte) static bool mmu_spte_update(u64 *sptep, u64 new_spte) { bool flush = false; - u64 old_spte = mmu_spte_update_no_track(sptep, new_spte); + u64 old_spte = mmu_spte_update_track(sptep, new_spte); if (!is_shadow_present_pte(old_spte)) return false;