From patchwork Tue Feb 2 18:57:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 12062735 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 42B7FC433E0 for ; Tue, 2 Feb 2021 19:18:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07A4564E45 for ; Tue, 2 Feb 2021 19:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239585AbhBBTSe (ORCPT ); Tue, 2 Feb 2021 14:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239285AbhBBS7v (ORCPT ); Tue, 2 Feb 2021 13:59:51 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F0BC061356 for ; Tue, 2 Feb 2021 10:57:57 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id v7so7104895ybl.15 for ; Tue, 02 Feb 2021 10:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=KYVd6fUQw3zIOqAGEpGtYtjC1FQT+zrejnhSTvgL1Tc=; b=AbpanSfQAKLYwwX/pQuSNKeFHr4axrcCDvd62suB3GmDBdzIgiYdCdzSU4mns/bb7s a9Ee+nd9i7nsCQoujjH+slrX1c943W0QHX6Jv7Cgx9L/gZrGM9jyW+8MzaHhJktg36/3 XoGH5dQdlgilaYiE30BZN2sSC+tNUsK9ZlqUe2pLgAucdYkMKrOtbHFvy9idE1YeCVQJ cmBW1MhPJigCh2nv0G8CngVoj0RdP3aDG45cHxi5Wjk5bsmFhJ76Hhy+ENvn2JpnjKv+ 2mP4Yw5dtmybP1Uqo9W0d3PbOXMw0lIT8vSv+nzas46LrzHEON0j8m9GGNyBJZE2Q63Q BfIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KYVd6fUQw3zIOqAGEpGtYtjC1FQT+zrejnhSTvgL1Tc=; b=NF9AjgLjIMsWPG/7ShEUeFJ+KsPWgfB6ugWTgg1BdD5Bt+ebzc0ZDTedjCoJ2M93GZ FYHVfbvF09Id9pWyua13etUvXdv5gD3IQNlFQbcR9WTX03UvxSO9138OEuPckDW1jWt8 ZEvRkqHNWq6OIbxPpC2ycXnNvs5D7bABeTDJ2dDzSJ/CTm+BlH24PbmhSld9mNBC/gKJ PhOVZZtegQfbXdepCRpenh3tGfEyebcAIi8B/fc5Rony8WRd8hCCpw+0dKX44USlx8K7 /+lsXklBJAzvkQ+0D4E7HUpGToHHyBSlUXZlNKn3XYzhHruRKJFwzqtA3GN7jX6i8Xek ZKvQ== X-Gm-Message-State: AOAM53320iwcDoGevviW01ZDiBlY+TFh0dYouGqQjP9Dyk2Q9v0tGLD4 JAoM3GS8t0GNI6IjprO0KYBxibW8U5/j X-Google-Smtp-Source: ABdhPJwbOZw3GpJNQQ/n0bg2L6ItJcBXZkWD0jzrdbnmEfZlWs/Wz2K6OMts+qvcqYo7IMhvQJ5WsYdQd26f Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:9090:561:5a98:6d47]) (user=bgardon job=sendgmr) by 2002:a25:b745:: with SMTP id e5mr34704252ybm.518.1612292276425; Tue, 02 Feb 2021 10:57:56 -0800 (PST) Date: Tue, 2 Feb 2021 10:57:16 -0800 In-Reply-To: <20210202185734.1680553-1-bgardon@google.com> Message-Id: <20210202185734.1680553-11-bgardon@google.com> Mime-Version: 1.0 References: <20210202185734.1680553-1-bgardon@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v2 10/28] KVM: x86/mmu: Fix TDP MMU zap collapsible SPTEs From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Peter Feiner , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong , Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There is a bug in the TDP MMU function to zap SPTEs which could be replaced with a larger mapping which prevents the function from doing anything. Fix this by correctly zapping the last level SPTEs. Fixes: 14881998566d ("kvm: x86/mmu: Support disabling dirty logging for the tdp MMU") Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/tdp_mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index c3075fb568eb..e3066d08c1dc 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1098,8 +1098,8 @@ bool kvm_tdp_mmu_slot_set_dirty(struct kvm *kvm, struct kvm_memory_slot *slot) } /* - * Clear non-leaf entries (and free associated page tables) which could - * be replaced by large mappings, for GFNs within the slot. + * Clear leaf entries which could be replaced by large mappings, for + * GFNs within the slot. */ static void zap_collapsible_spte_range(struct kvm *kvm, struct kvm_mmu_page *root, @@ -1111,7 +1111,7 @@ static void zap_collapsible_spte_range(struct kvm *kvm, tdp_root_for_each_pte(iter, root, start, end) { if (!is_shadow_present_pte(iter.old_spte) || - is_last_spte(iter.old_spte, iter.level)) + !is_last_spte(iter.old_spte, iter.level)) continue; pfn = spte_to_pfn(iter.old_spte);