From patchwork Tue Aug 24 23:34:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12456097 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 182EFC4338F for ; Tue, 24 Aug 2021 23:34:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4A9C61101 for ; Tue, 24 Aug 2021 23:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233464AbhHXXez (ORCPT ); Tue, 24 Aug 2021 19:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbhHXXez (ORCPT ); Tue, 24 Aug 2021 19:34:55 -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 9BB86C061757 for ; Tue, 24 Aug 2021 16:34:10 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id dw5-20020a17090b094500b00192fa4319b4so1313277pjb.8 for ; Tue, 24 Aug 2021 16:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=yWR8R2JmIMpMqoJkv4npjP+FInFv3IuBJ/q2uih/I90=; b=RjsbJSabKpGfRebTMn4lsqy7+IlDnl4YG9MA4mlbL2vD0mTYU0nLLHqPKhZsYbB8Az 8otqscLmQ3FVGOzDvsIZVV7UCpRf3PXNG49QZqKk22TquAC7YcBEj0p+9GZy34xWocA3 J4r5uG8AnzS9ZfymTIGYsaHKTi+JCE1lji3KmX54L4PVUe3zXuy84URcMQQFaMPgVz02 hwb5Y7AKxm+P5t+TsJPlUK26ax7rmbqJhWGod/wAo7NQrHGG09QVbX2m9A0dotzBDufS AtdlD01CWB5UgEAYsCV58mVldm8jzZmAoV0jsg9evH2+q4u6I74Vn9xJfOlbG7+0HTfG p9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=yWR8R2JmIMpMqoJkv4npjP+FInFv3IuBJ/q2uih/I90=; b=XU+NHkLHNTzhptvHqopxvivBBWUVRNmguzNR0uSReTVTHMgOXN1WuJDmIiowxl37wy jC9aUa6QcVlZFxF5w/LLSLo9iBdYdJqpUXhOFtROtsY7OetT6gfDUAbMKrMSSEWEiqwY O4t5jABW43WBO0AZ3Lwi0CXjJkKc5W6cTb01HxDDTsLxAGinr5LuTda9v9MQa+RcgJM1 wqkUFCvim43SX98QViKeAv7hZJFS1oBh9NKlp9foXo6SXVhfRcMSurzk11MfQhTtLIAK P8O6DUXP8GDSvTOgei8MO88XIzcyNHNMZcloU/FnHKEQS1e4BFH2gItM448x4vIbHh0Q /img== X-Gm-Message-State: AOAM533jBzYMH0DnfaEU7pVbytW0J9mgtbiO/+X/HLZotzt4rxUt7H54 JI4mY/DVwwe8fOyFDFwEyWYVoezbr2SXZw== X-Google-Smtp-Source: ABdhPJxaPnXtZu5GIJV7X1tofhDIaKhU+1XsoWVKAtsg20c2J44LS/ZbUqmu5wfEPjgnrKYHR3TYXvmLYmqhUQ== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:902:650b:b0:137:3940:ec24 with SMTP id b11-20020a170902650b00b001373940ec24mr1936384plk.36.1629848049970; Tue, 24 Aug 2021 16:34:09 -0700 (PDT) Date: Tue, 24 Aug 2021 23:34:07 +0000 Message-Id: <20210824233407.1845924-1-dmatlack@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH] KVM: x86/mmu: Refactor slot null check in kvm_mmu_hugepage_adjust From: David Matlack To: Paolo Bonzini Cc: kvm@vger.kernel.org, Ben Gardon , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The current code is correct but relies on is_error_noslot_pfn() to ensure slot is not null. The only reason is_error_noslot_pfn() was checked instead is because we did not have the slot before commit 6574422f913e ("KVM: x86/mmu: Pass the memslot around via struct kvm_page_fault") and looking up the memslot is expensive. Now that the slot is available, explicitly check if it's null and get rid of the redundant is_error_noslot_pfn() check. Suggested-by: Sean Christopherson Signed-off-by: David Matlack Reviewed-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4853c033e6ce..9b5424bcb173 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2925,10 +2925,10 @@ void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault if (unlikely(fault->max_level == PG_LEVEL_4K)) return; - if (is_error_noslot_pfn(fault->pfn) || kvm_is_reserved_pfn(fault->pfn)) + if (!slot || kvm_slot_dirty_track_enabled(slot)) return; - if (kvm_slot_dirty_track_enabled(slot)) + if (kvm_is_reserved_pfn(fault->pfn)) return; /*