From patchwork Thu Jun 17 23:19:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12329703 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 885A5C2B9F4 for ; Thu, 17 Jun 2021 23:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F311610CD for ; Thu, 17 Jun 2021 23:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232949AbhFQXWH (ORCPT ); Thu, 17 Jun 2021 19:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbhFQXWH (ORCPT ); Thu, 17 Jun 2021 19:22:07 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14358C061574 for ; Thu, 17 Jun 2021 16:19:58 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id v1-20020a372f010000b02903aa9be319adso3521512qkh.11 for ; Thu, 17 Jun 2021 16:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=x6kZay8QFcZCwXeqKzx9gBeO5XUJEU0U/bkJm47MKuE=; b=H6EUqqmHh9XZchhM9KBTYb6IjPova9sdoOF9S4YMX9GoX3gF3kMRVSu68u3jpkYezj DVgiTUa9RvYh5uqZk1UXOOUQgIFFTPqydPTaL8qc4lciufVCTigD8am16oXXk2ZkYRf6 dyMHvAL2AP/ac4Z+qZFXtyNYCb8LeVoPeU0iE56lGS7jFgbYc3MsEL40Mmn3lRcfo3jj DjCJLJUkwgquJQyoSD3tzO57myXP2OeFwXhUs2UJPqohlDtLlEaPqsZbzwCr/MSSe0fL 6W5vecyaksRpLw8WAoH7ksJ0rg7jDw1lriN2ovMZiDE2A8PvNnOfqDtDqt/grNpm0dBp XV0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=x6kZay8QFcZCwXeqKzx9gBeO5XUJEU0U/bkJm47MKuE=; b=NR2I5kzq7umqyWvF338dDhpBapEsQPp1lrdFlBQXBqHBZZw66B8nXH9BPyZmj7nRmv +gyRob5R98KG+raUrwUJySQtks8RODdJIWwHjnIrj8jCzgImcnV0AP17VUeRkEoecOEj sgTRCJJNK7oQa3Tt8sMha1FQILjeTFZw5nP5OPmfSl/Bz8PriONPr5Z9+tGNnLbzE6Zw WdYQ8F/czNVRYgc/Y76BvBzUIeaFpHnuGXtQlTho5avRgSnWxh7B0MGAclJxNZOIjHSz XACHXyEKy6aOhS5bVangiiQz8razJbj97zA/VHE6aQpp6zofOId4TUrDCIT4YLNdyXCX 6Wrg== X-Gm-Message-State: AOAM530vluCAMSxjnllw6SZncrNHtICQP82TMknRhsX1+OI+HpCcVPXY 6xR7UTOKioHTcz+PtE7XpF3sdbi4YmpsVSGbO/lWq4K/oHXM3aNPSZfaQ+6F7fiMSh0CWmNcxrm G3KNQdYzOq0xfXB3J2BH0TuxNS9Fye3fZHcC9iFp+iqAYELgJpOtN8bOEmhZ6dr8= X-Google-Smtp-Source: ABdhPJyU07nfV9swuZBO8xidyk7pO/mLeBScBOyR08mfHT9v03SAGvxkodm6EnM35TsbjWAPf43HWyTNNdm+hg== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a05:6214:268e:: with SMTP id gm14mr2452398qvb.25.1623971997147; Thu, 17 Jun 2021 16:19:57 -0700 (PDT) Date: Thu, 17 Jun 2021 23:19:45 +0000 In-Reply-To: <20210617231948.2591431-1-dmatlack@google.com> Message-Id: <20210617231948.2591431-2-dmatlack@google.com> Mime-Version: 1.0 References: <20210617231948.2591431-1-dmatlack@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 1/4] KVM: x86/mmu: Remove redundant is_tdp_mmu_root check From: David Matlack To: kvm@vger.kernel.org Cc: Ben Gardon , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Junaid Shahid , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The check for is_tdp_mmu_root in kvm_tdp_mmu_map is redundant because kvm_tdp_mmu_map's only caller (direct_page_fault) already checks is_tdp_mmu_root. Suggested-by: Sean Christopherson Signed-off-by: David Matlack --- arch/x86/kvm/mmu/tdp_mmu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 95eeb5ac6a8a..5888f2ba417c 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -979,8 +979,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, if (WARN_ON(!VALID_PAGE(vcpu->arch.mmu->root_hpa))) return RET_PF_RETRY; - if (WARN_ON(!is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa))) - return RET_PF_RETRY; level = kvm_mmu_hugepage_adjust(vcpu, gfn, max_level, &pfn, huge_page_disallowed, &req_level); From patchwork Thu Jun 17 23:19:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12329705 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 3B77DC48BE5 for ; Thu, 17 Jun 2021 23:20:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14701610A1 for ; Thu, 17 Jun 2021 23:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232968AbhFQXWI (ORCPT ); Thu, 17 Jun 2021 19:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232904AbhFQXWH (ORCPT ); Thu, 17 Jun 2021 19:22:07 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 059C6C06175F for ; Thu, 17 Jun 2021 16:19:59 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id f6-20020a6310060000b0290221a634c769so404124pgl.19 for ; Thu, 17 Jun 2021 16:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7ozmI8swoBDof9JfAPjd74vw6ODk/Ie9rh7HVUnD/+o=; b=qrr+xv7lLPCroy1+APdAOC/BgNDXZyumuBm9pfvzgbfrBbazORnRyVH+/JUIO89TML izXnfgCjVylnOa0MtgCx4OKQeMLOUSlsKR3IUXzG1xhDSM4BYjRvwaQgQtby3sDgWzQ0 zY7XXDE8yTFYBhxppDpkhv5InTgOOF6RUWaemuNQtYGrA2MWdK7KrPNb/HnI0E1EkZWq 5hCZW/MlRUri5BajxTQGto0la7GX9gozK/c7ms0tOAIn9xKlN9lltkSP5UfKbbapCh9b JmS7O0ajWx5d3LSdWgsdihbQ0NucCeIRpwpfPSJB8S8KgSzsxi+TxiIs5z7j4wJ2CTTF wBQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7ozmI8swoBDof9JfAPjd74vw6ODk/Ie9rh7HVUnD/+o=; b=L8jhkTr2MWZahlt+u1ly7/ajaI1ZRm0i/1k4YpS8CQUGmbo61Qla92rNFymwpY6etd gq3EeNqUfXj6qsXfahOk/DH5pSal5YK/CqItOmxtMzrBCJzYl6NT2BjG9AWcWlnwYzxl 3BthIHiNPb+yKnDeN9e8htDospqUxiTgr5BohUq0ZqdBnlL5BAJV9GJ9mejMROtXsLvM t1vx83ZVDPSj9E3lGuKRN4/tDrU1s/ayp4+XEqubn2BTDyjhREzo7UNa2Qq0ykjiE/I2 wUCrlcKdnVo59FT7yXcloqdjwV95ig/0BllzygrOs/+hX0RcFpUZrOtf76tu+yk8fCsd 3jrQ== X-Gm-Message-State: AOAM5305Unafhe/Rf1HBAoUp9DoIoKLsarzCBtNTkLe+D6ZBgq+08Qi1 hLFhIvtiviBSIBZlwdGYxaa2jAwL/Ip9ielpzJpfoYf/AIfu/0ZRP2VxVnXwhVGSAFMf9W5AZJ+ NrqUBp3fQSbJ3hQGooDPwhwlDmjN8/MU6C2g50MjdIHp5Zel5JcqNpKUx/pm2yeE= X-Google-Smtp-Source: ABdhPJxloI/3xnhjS/PxQYPEAhuKJVqjQZWvdCLH9ZmuB7xCxheay4bzoQMu1y9nJRyVSayiSDrGIuqPp5bniw== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:902:c9d5:b029:11e:7a87:205 with SMTP id q21-20020a170902c9d5b029011e7a870205mr1966933pld.37.1623971998432; Thu, 17 Jun 2021 16:19:58 -0700 (PDT) Date: Thu, 17 Jun 2021 23:19:46 +0000 In-Reply-To: <20210617231948.2591431-1-dmatlack@google.com> Message-Id: <20210617231948.2591431-3-dmatlack@google.com> Mime-Version: 1.0 References: <20210617231948.2591431-1-dmatlack@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 2/4] KVM: x86/mmu: Remove redundant is_tdp_mmu_enabled check From: David Matlack To: kvm@vger.kernel.org Cc: Ben Gardon , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Junaid Shahid , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This check is redundant because the root shadow page will only be a TDP MMU page if is_tdp_mmu_enabled() returns true, and is_tdp_mmu_enabled() never changes for the lifetime of a VM. It's possible that this check was added for performance reasons but it is unlikely that it is useful in practice since to_shadow_page() is cheap. That being said, this patch also caches the return value of is_tdp_mmu_root() in direct_page_fault() since there's no reason to duplicate the call so many times, so performance is not a concern. Suggested-by: Sean Christopherson Signed-off-by: David Matlack Reported-by: kernel test robot Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu.c | 11 ++++++----- arch/x86/kvm/mmu/tdp_mmu.h | 4 +--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 0144c40d09c7..1e6bf2e207f6 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3545,7 +3545,7 @@ static bool get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr, u64 *sptep) return reserved; } - if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa)) + if (is_tdp_mmu_root(vcpu->arch.mmu->root_hpa)) leaf = kvm_tdp_mmu_get_walk(vcpu, addr, sptes, &root); else leaf = get_walk(vcpu, addr, sptes, &root); @@ -3717,6 +3717,7 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn, static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, bool prefault, int max_level, bool is_tdp) { + bool is_tdp_mmu_fault = is_tdp_mmu_root(vcpu->arch.mmu->root_hpa); bool write = error_code & PFERR_WRITE_MASK; bool map_writable; @@ -3729,7 +3730,7 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, if (page_fault_handle_page_track(vcpu, error_code, gfn)) return RET_PF_EMULATE; - if (!is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa)) { + if (!is_tdp_mmu_fault) { r = fast_page_fault(vcpu, gpa, error_code); if (r != RET_PF_INVALID) return r; @@ -3751,7 +3752,7 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, r = RET_PF_RETRY; - if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa)) + if (is_tdp_mmu_fault) read_lock(&vcpu->kvm->mmu_lock); else write_lock(&vcpu->kvm->mmu_lock); @@ -3762,7 +3763,7 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, if (r) goto out_unlock; - if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa)) + if (is_tdp_mmu_fault) r = kvm_tdp_mmu_map(vcpu, gpa, error_code, map_writable, max_level, pfn, prefault); else @@ -3770,7 +3771,7 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, prefault, is_tdp); out_unlock: - if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa)) + if (is_tdp_mmu_fault) read_unlock(&vcpu->kvm->mmu_lock); else write_unlock(&vcpu->kvm->mmu_lock); diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h index 5fdf63090451..843ca2127faf 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.h +++ b/arch/x86/kvm/mmu/tdp_mmu.h @@ -91,12 +91,10 @@ static inline bool is_tdp_mmu_enabled(struct kvm *kvm) { return false; } static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; } #endif -static inline bool is_tdp_mmu_root(struct kvm *kvm, hpa_t hpa) +static inline bool is_tdp_mmu_root(hpa_t hpa) { struct kvm_mmu_page *sp; - if (!is_tdp_mmu_enabled(kvm)) - return false; if (WARN_ON(!VALID_PAGE(hpa))) return false; From patchwork Thu Jun 17 23:19:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12329707 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 27768C2B9F4 for ; Thu, 17 Jun 2021 23:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09C01610A5 for ; Thu, 17 Jun 2021 23:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232978AbhFQXWK (ORCPT ); Thu, 17 Jun 2021 19:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232904AbhFQXWJ (ORCPT ); Thu, 17 Jun 2021 19:22:09 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CE8C061574 for ; Thu, 17 Jun 2021 16:20:00 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id b23-20020a17090ae397b0290163949acb4dso5505288pjz.9 for ; Thu, 17 Jun 2021 16:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=q3OMF5TZcGvzvXMBtYYHIDqrzCzLQc2VyhrpFeWf3GY=; b=dAN9TmPWyzZdxsuMCsUhrRO7Myowk4jVSEWLE4GJ/aNX01VyPiRwGcBrk+/ixjkzKL b3XwGrScxCmV37BAfM7/NtW1qdoMB8P0HCgT6YB7g398HbksxKhUajIOmFhrWhVNbXL2 bR1nhOvFH3QlaV/Vfmky3hLimqxpaNsz1xLYDfmTG+WohDSk/InIGM8EAWb27pYfH5uI kgosm4jxOhGSOslRoHDmrFnhZMQXQdiHfxtu4yF3KwMur2y9QFc6MPiGKoJUolovktjG 3rpzUCoCxS+fIZ1LugZbk6TLcltF4MhPTJEOq5m3iGgW4hqg2F+Dz7p842ajTghM1p5T 9/Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=q3OMF5TZcGvzvXMBtYYHIDqrzCzLQc2VyhrpFeWf3GY=; b=bUjYl1skCnC1oBidfCj+sbrdXWjNXpZ7C8aI47xUl4jK6SBJ7QvluIsHgag9cdj2oJ QekbSFdHFLjjf6zIEx5slwQ/QEmqxCLcQgOgDi5El5DbPH1eqlNjR/kuwPPSM2s77B/Y 4yZgNqPi1GHBS8NdSaQ2+FHBh5Zp/EUIbfGNGA7K6RSPQeD3FdRnWw98Y/3YCfmgwKdr HaXzvJqgdhajoO0dx7TU+92famco/exZjTUlcKcHNLVk7UlHL6SrQWJv13mUGWfUkQkv UpwKjSvUmw2zV3a+LhO69g3MYtYRXsxfhPfBLNLJG3IeABrhcpFzhAmrIHwYGiewtPvE 98WQ== X-Gm-Message-State: AOAM533em24gyQxA6sE4g4MGvm+Gsa7PaEr4sPTVapJQt9uS7e47VISL gaCdwoZ2lRv6nIlS7DwCdApOklOV5ceDnEh+VNISWyvBwf4Se9IPu/dzTl48J44RyyObDtw8jvh ++2cJVgrlXVaT8EKM8g/0+mAmP9kwNeENaBrzMsg33cnrAtzAn4iqsiFeoy4rnY4= X-Google-Smtp-Source: ABdhPJwOlYyJKwE4uxmdp04wSHMxVwudq58zMUJNop78b23hlFHC/gxM8COzZgWLJWYDx5r2RrmtGz/WsTqJJw== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:90a:8589:: with SMTP id m9mr18544267pjn.168.1623972000085; Thu, 17 Jun 2021 16:20:00 -0700 (PDT) Date: Thu, 17 Jun 2021 23:19:47 +0000 In-Reply-To: <20210617231948.2591431-1-dmatlack@google.com> Message-Id: <20210617231948.2591431-4-dmatlack@google.com> Mime-Version: 1.0 References: <20210617231948.2591431-1-dmatlack@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 3/4] KVM: x86/mmu: Refactor is_tdp_mmu_root into is_tdp_mmu From: David Matlack To: kvm@vger.kernel.org Cc: Ben Gardon , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Junaid Shahid , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This change simplifies the call sites slightly and also abstracts away the implementation detail of looking at root_hpa as the mechanism for determining if the mmu is the TDP MMU. Suggested-by: Sean Christopherson Signed-off-by: David Matlack --- arch/x86/kvm/mmu/mmu.c | 4 ++-- arch/x86/kvm/mmu/tdp_mmu.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 1e6bf2e207f6..4a4580243210 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3545,7 +3545,7 @@ static bool get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr, u64 *sptep) return reserved; } - if (is_tdp_mmu_root(vcpu->arch.mmu->root_hpa)) + if (is_tdp_mmu(vcpu->arch.mmu)) leaf = kvm_tdp_mmu_get_walk(vcpu, addr, sptes, &root); else leaf = get_walk(vcpu, addr, sptes, &root); @@ -3717,7 +3717,7 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn, static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, bool prefault, int max_level, bool is_tdp) { - bool is_tdp_mmu_fault = is_tdp_mmu_root(vcpu->arch.mmu->root_hpa); + bool is_tdp_mmu_fault = is_tdp_mmu(vcpu->arch.mmu); bool write = error_code & PFERR_WRITE_MASK; bool map_writable; diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h index 843ca2127faf..a63e35378e43 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.h +++ b/arch/x86/kvm/mmu/tdp_mmu.h @@ -91,9 +91,10 @@ static inline bool is_tdp_mmu_enabled(struct kvm *kvm) { return false; } static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; } #endif -static inline bool is_tdp_mmu_root(hpa_t hpa) +static inline bool is_tdp_mmu(struct kvm_mmu *mmu) { struct kvm_mmu_page *sp; + hpa_t hpa = mmu->root_hpa; if (WARN_ON(!VALID_PAGE(hpa))) return false; From patchwork Thu Jun 17 23:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12329709 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 0827EC48BE5 for ; Thu, 17 Jun 2021 23:20:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E012A610A5 for ; Thu, 17 Jun 2021 23:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232975AbhFQXWM (ORCPT ); Thu, 17 Jun 2021 19:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbhFQXWL (ORCPT ); Thu, 17 Jun 2021 19:22:11 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C480C061574 for ; Thu, 17 Jun 2021 16:20:02 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id y17-20020a17090aa411b02901649daab2b1so4236357pjp.5 for ; Thu, 17 Jun 2021 16:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XWHGPcravhGhTAyO8386YDif3tw3JT3HgF/phaVp8zY=; b=fI/MTvGa8Ew0kXrtJpvptwgy7qIxwSRLRboX3MJFkirQDuA3gqfIPSvZvwewTUxXDR n2EJJ+sD5MyfUwLA0I1wGgVfiXUm8nxLElase8HFD8c41pjn6StclWBjzsSu/XNglXFo h+SIs5n0PSNwIZA5O3IGuBkD5aEyt8XSHDIXB1yPPMHu8t69LGGmDRhVOBt8l2CQ6AXX O6flhhry8YSE2OQeNG0uOJ0zxkooUvlZsLc/mdnVKdKL9+EiJvpFIZmda8GLffXPVQ7S D/itKomuYfW5J4UzAWlWGPSkB8di79+rvojmXNgRIDsHUmpGZ83ncYW44mK2B1JyB/lY jyIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XWHGPcravhGhTAyO8386YDif3tw3JT3HgF/phaVp8zY=; b=pz9KnkK3OT80r0v/FeWt56/5h9Q93jJdu/opSnl/we3Xi8/nvpAHpMt40qGiFite5Z sM2k+g9aN4NJi5xb/WpJB3H66bguQem0/dc8+VAc/ITG9e6SFfO9yf7i5CUXJ2XEUbCf ZSLVUEgUqsjv/6iDjk0ATswP9dhkvEav+yGmbwu7/5V4IMgzELkMV0BS5PCQS3Vn4aBc NE06JzzPrkT2iWDung0xtg4fRwoSTCvzTNFPnV5re3PphOUhkiTbdUGUNtlqvt3D1zq7 4wQofwbqqYMAWYxIR2qdccAEW/aTXadr9o/b3vxtjd5pX3dKqvTsQsE3JGong/oLYqVi 3OAQ== X-Gm-Message-State: AOAM531RubSCyjHQwkk896PhqFE4GlJLTyuYCy/PQLDt6gF4A2ucpgCc TA8Yp9jLa/gPUQE6L5nl10blMeT4UpnfzFkfDP0ooPhPNTqBtjbcSTlJWYdS+R90BWPCDiGHbwQ OEfj8jKIXIEyjm7eQUmxJly/IKxEnRHdJXaT3oSidhMYmBIKUFb9Cm1gpg5nVjMI= X-Google-Smtp-Source: ABdhPJwhUoEbdeMp24kbOo1twepcQ+Me0xy1ZH3YuuF2bsPWKxMr2UiLEacWb01hmMcDvCjmqix5ssO4WVu05w== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:90a:17e7:: with SMTP id q94mr7732437pja.117.1623972001484; Thu, 17 Jun 2021 16:20:01 -0700 (PDT) Date: Thu, 17 Jun 2021 23:19:48 +0000 In-Reply-To: <20210617231948.2591431-1-dmatlack@google.com> Message-Id: <20210617231948.2591431-5-dmatlack@google.com> Mime-Version: 1.0 References: <20210617231948.2591431-1-dmatlack@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 4/4] KVM: x86/mmu: Remove redundant root_hpa checks From: David Matlack To: kvm@vger.kernel.org Cc: Ben Gardon , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , Junaid Shahid , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The root_hpa checks below the top-level check in kvm_mmu_page_fault are theoretically redundant since there is no longer a way for the root_hpa to be reset during a page fault. The details of why are described in commit ddce6208217c ("KVM: x86/mmu: Move root_hpa validity checks to top of page fault handler") __direct_map, kvm_tdp_mmu_map, and get_mmio_spte are all only reachable through kvm_mmu_page_fault, therefore their root_hpa checks are redundant. Suggested-by: Sean Christopherson Signed-off-by: David Matlack --- arch/x86/kvm/mmu/mmu.c | 8 -------- arch/x86/kvm/mmu/tdp_mmu.c | 3 --- 2 files changed, 11 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4a4580243210..2e36430e54e6 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2827,9 +2827,6 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, gfn_t gfn = gpa >> PAGE_SHIFT; gfn_t base_gfn = gfn; - if (WARN_ON(!VALID_PAGE(vcpu->arch.mmu->root_hpa))) - return RET_PF_RETRY; - level = kvm_mmu_hugepage_adjust(vcpu, gfn, max_level, &pfn, huge_page_disallowed, &req_level); @@ -3540,11 +3537,6 @@ static bool get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr, u64 *sptep) int root, leaf, level; bool reserved = false; - if (!VALID_PAGE(vcpu->arch.mmu->root_hpa)) { - *sptep = 0ull; - return reserved; - } - if (is_tdp_mmu(vcpu->arch.mmu)) leaf = kvm_tdp_mmu_get_walk(vcpu, addr, sptes, &root); else diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 5888f2ba417c..fa436a4ae01d 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -977,9 +977,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, int level; int req_level; - if (WARN_ON(!VALID_PAGE(vcpu->arch.mmu->root_hpa))) - return RET_PF_RETRY; - level = kvm_mmu_hugepage_adjust(vcpu, gfn, max_level, &pfn, huge_page_disallowed, &req_level);