Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885187pxv; Fri, 2 Jul 2021 15:08:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqBMPgc5pNU1jFRtEjtjvZfWLvqMsnh8NksamFAp2i0XEBLNPvA1lUDvAn9zs/0lbhd5ZH X-Received: by 2002:a17:906:a18b:: with SMTP id s11mr1988100ejy.8.1625263717906; Fri, 02 Jul 2021 15:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263717; cv=none; d=google.com; s=arc-20160816; b=vZAcKV2ul0Sr0/x5u4K8J9SA+jclB9ZWdXlfu3rFxr7KupvYjcv8ZpeyzdSHvTx4Bw ZwqbN/vB9ygYZGgECMbKXsaFIogK9fPeOMEjwKHdNeT3RO3s0C9BgmNrvUm5gsP3m9UT o4B6Lgvn3aNJmZbo4Aeze2AThZSrfBj3rRMbY5P1FN2ZzcxK+Rw89D94dLExxlHgkaUZ ks+rvL0ShRAIPqjFqqsyfBO0Qk3nban/al6zTg0zR7XYueGZJSLPuYmqCw+VsiNBWDp1 y1+J4xfwiBTbmg7QbNYezpUrI8bzvfXuUqiJGY9KKCbCpe7hmuTpqxeCIt+v/a13MUzM 0HVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vHKhQzf0/cRamALo+FWNFVrqPBGZ0i2kMhob67zAoPo=; b=BtNm7qlr9UP6mAMJTiKqHtrjVaXdXTA2vgEqbVhsEkoulfyYHyAbFUNL7X8u/OjHml dirHtkHpJ1mCYEeSZ/OYzsGUBcEtjxtN9QScl4djKHWGB3F0zHRDVG4FjBdvAXMrJ4HY ri2gEHYCAyzlGZtz8aVglpWer6b+TnjD8+AoNeuxukER0b8/izhI5sJ5IYQTsHTdody2 oaAdbqziLOsm6z1v0qOLHyzWjiGkKAUmI7cwwtEUXmydmAouTvKA4NxjD4Fp+oU0fOIZ izkD+NCEqGb1BWbwOgwtp3TIaGtZbnRD7PCYQdC9YmWqezMAYxD1s5S/uJtVioadhPDw WgNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ne2si4280952ejc.639.2021.07.02.15.08.14; Fri, 02 Jul 2021 15:08:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233711AbhGBWI5 (ORCPT + 99 others); Fri, 2 Jul 2021 18:08:57 -0400 Received: from mga12.intel.com ([192.55.52.136]:50201 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233220AbhGBWIA (ORCPT ); Fri, 2 Jul 2021 18:08:00 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472759" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472759" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:27 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814825" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:27 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 45/69] KVM: x86/mmu: Return old SPTE from mmu_spte_clear_track_bits() Date: Fri, 2 Jul 2021 15:04:51 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Return the old SPTE when clearing a SPTE and push the "old SPTE present" check to the caller. Private shadow page support will use the old SPTE in rmap_remove() to determine whether or not there is a linked private shadow page. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/mmu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 0259781cee6a..6b0c8c84aabe 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -542,9 +542,9 @@ static bool mmu_spte_update(u64 *sptep, u64 new_spte) * Rules for using mmu_spte_clear_track_bits: * It sets the sptep from present to nonpresent, and track the * state bits, it is used to clear the last level sptep. - * Returns non-zero if the PTE was previously valid. + * Returns the old PTE. */ -static int mmu_spte_clear_track_bits(u64 *sptep) +static u64 mmu_spte_clear_track_bits(u64 *sptep) { kvm_pfn_t pfn; u64 old_spte = *sptep; @@ -555,7 +555,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep) old_spte = __update_clear_spte_slow(sptep, shadow_init_value); if (!is_shadow_present_pte(old_spte)) - return 0; + return old_spte; pfn = spte_to_pfn(old_spte); @@ -572,7 +572,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep) if (is_dirty_spte(old_spte)) kvm_set_pfn_dirty(pfn); - return 1; + return old_spte; } /* @@ -1104,7 +1104,9 @@ static u64 *rmap_get_next(struct rmap_iterator *iter) static void drop_spte(struct kvm *kvm, u64 *sptep) { - if (mmu_spte_clear_track_bits(sptep)) + u64 old_spte = mmu_spte_clear_track_bits(sptep); + + if (is_shadow_present_pte(old_spte)) rmap_remove(kvm, sptep); } -- 2.25.1