From patchwork Thu Aug 12 04:36:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12433709 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=-14.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 B75D6C432BE for ; Thu, 12 Aug 2021 14:21:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 941696108C for ; Thu, 12 Aug 2021 14:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237958AbhHLOWA (ORCPT ); Thu, 12 Aug 2021 10:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237952AbhHLOWA (ORCPT ); Thu, 12 Aug 2021 10:22:00 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E464CC0613D9; Thu, 12 Aug 2021 07:21:34 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id n12so6814772plf.4; Thu, 12 Aug 2021 07:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=csFOusVLJbr+QwATacvMZAXfEPfUH2cDcHQVoTGE5vE=; b=JkEWtiTyDNnJ+BzIN7Gz4qDf9wicTiI7ILdP/I+xMvTXTscedD/r/rSItHK+lfLr0z 0OtLaO69EGsib16m8EQWcCZpgB8SPH0upDGSu4NxUrfhBlgrnfyTkf1+yiTgPxSatpH9 17L45Is8Dp2uwQstt+csUVSpQBzigZP1KR8nmBMnFFqqDLSA51/KSBzuQpqN78eARQ6n hwDDchcyVUhJmebAjxPf4opcS6nCJYJUmorP/vgUJmu+TeYiobJcWIRTCPfz/bl6HKeg d8U7Etb1zaRQsS0uVQktLHvt6yy9puI3MLSRFIDkdc/ROeq234enJPc2yKkDh2zChW4B AJ7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=csFOusVLJbr+QwATacvMZAXfEPfUH2cDcHQVoTGE5vE=; b=rLybaxMonuxstrOXBp3hPIvNgaRmzFJamNivL6LE3h6+XTlV+ypWbNvADW2wsjVe7a vwyalu7n7uhu0ona99SyxfXar8C00y99XCOWR9oXyz9C8GRAXPuLZV/AwkdOfKaRE8JC juyPieZ4NSCpi9gctRfw+Vb9axuWgxx6uc0nEPPtikbbZg0iizjCtuHRwInIUQ2guT+V IANMC7lHkLV6SkaTIuE/vdMXNhU0QzrvXLngDhZ43/mO7Zwr1Xr1g83pLv3DKInp0T9S cWLjfTBBphdrJoUXaeUThY+SD+Ttdh3dCFLN/BVA+WIJs1GzIgI5+bJn1VAKH+H10oCS S1uQ== X-Gm-Message-State: AOAM532ocHQeZ0VR8DGtOf8Uq1n3Z/UpdyMHyQx8WpJ0azzehhg5NRWF kN/JcvrYAQbzX3ymF1i0NFqHUFrBQIE= X-Google-Smtp-Source: ABdhPJxDz2GetmVfJp2EYNCcDHh9bJawwgY+Rv+RN1HTpSpXhkjBHc6aQr/V0Lw0d/St2Uq1V1Mk2A== X-Received: by 2002:a17:90b:23d6:: with SMTP id md22mr16100202pjb.149.1628778094275; Thu, 12 Aug 2021 07:21:34 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id x19sm4129996pgk.37.2021.08.12.07.21.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Aug 2021 07:21:34 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Subject: [PATCH 1/2] KVM: X86: Check pte present first in __shadow_walk_next() Date: Thu, 12 Aug 2021 12:36:29 +0800 Message-Id: <20210812043630.2686-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan So far, the loop bodies already ensure the pte is present before calling __shadow_walk_next(). But checking pte present in __shadow_walk_next() is a more prudent way of programing and loop bodies will not need to always check it. It allows us removing is_shadow_present_pte() in the loop bodies. Signed-off-by: Lai Jiangshan Signed-off-by: Sean Christopherson Acked-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index a272ccbddfa1..c48ecb25d5f8 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2231,7 +2231,7 @@ static bool shadow_walk_okay(struct kvm_shadow_walk_iterator *iterator) static void __shadow_walk_next(struct kvm_shadow_walk_iterator *iterator, u64 spte) { - if (is_last_spte(spte, iterator->level)) { + if (!is_shadow_present_pte(spte) || is_last_spte(spte, iterator->level)) { iterator->level = 0; return; } From patchwork Thu Aug 12 04:36:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12433711 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=-14.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 1B705C4338F for ; Thu, 12 Aug 2021 14:21:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF6BB60FD7 for ; Thu, 12 Aug 2021 14:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237971AbhHLOWJ (ORCPT ); Thu, 12 Aug 2021 10:22:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237968AbhHLOWI (ORCPT ); Thu, 12 Aug 2021 10:22:08 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CEDAC061756; Thu, 12 Aug 2021 07:21:43 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d1so7502241pll.1; Thu, 12 Aug 2021 07:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sfjh2TOrUQjWKK1WuaUcVyTMXiq8ArXgrYRkmZfmijU=; b=FhCvezG0085J3wxcSiEtYzUXKlFc5dQ0hhlsg9IzzwYxm6PyVzWBfvD0MyZ+KWh7HB Kyqoyddjar3UeuL+cpRXbIApFYRqd0gaFZaDgAudKc3UY625P7GXW2iTi/pmFaTXH7o5 iTMwNhRZLZgkqylizFg740UQxaP5flSrJW007zDgERXEREMxeG8J2lH/fTEsVxwnmzu0 jm38Ke/bNRBb8JoAoSH/TGR/VLXVN+CqMzuGJj9U9Fn+u1Ht52961SVp0bYp4byNwdlv 0yD1vQwlvnA/vr1ZS95F3RSMgXIE0D7yDAtw763uTbsacHpl0P7QR7bXcdoTN4vmqIra E5Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sfjh2TOrUQjWKK1WuaUcVyTMXiq8ArXgrYRkmZfmijU=; b=tX17akt4arQJ5PdLPiMoSECUXGhgqmI75UBSP8DqZDBYym50ERRCUvoygm8DqL1W7L WqK2BLxR6FYm7D93oeB7UGgWXxw1DjyjOZAMsEUVLIhKo3OoRb+3D17ekFbympi0P+QI ZFmar37sWSVLHBXSFJpyV+eJ5hqpLd5iBNFUStr6JdTa0hw555DLeepoCW2gsurZbJrg 1GN1AWzWXPX6lVyI4y/19comw2XzQJ9/07VDyFhB30e9LAt5EKouAOXHYoECEd4cOsRK usAZuu1OXqXSPY6Ff/RkO1gUI4jiCYYxWThsOhNvRHWk5LRJEuOr7jqB6+3iqhvQu8Wv IMwg== X-Gm-Message-State: AOAM531kCBDFEn/q1X/gNGah2AhvsNkmvJMN4A++YTlziY3JxpHYWMDN lFfLwK9M8XbGviJho5MgfuNwa/FWhY8= X-Google-Smtp-Source: ABdhPJySJPZUuNQ6WNcFx1/Dn2zORy43XMmZhsxk3EmGeYBs8yTi58i/+NjWG7JrUlAauljrBHgJcA== X-Received: by 2002:a17:90a:d711:: with SMTP id y17mr4560278pju.74.1628778102743; Thu, 12 Aug 2021 07:21:42 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id g3sm3582841pfi.197.2021.08.12.07.21.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Aug 2021 07:21:42 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Subject: [PATCH 2/2] KVM: X86: Remove the present check from for_each_shadow_entry* loop body Date: Thu, 12 Aug 2021 12:36:30 +0800 Message-Id: <20210812043630.2686-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20210812043630.2686-1-jiangshanlai@gmail.com> References: <20210812043630.2686-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The function __shadow_walk_next() for the for_each_shadow_entry* looping has the check and propagates the result to shadow_walk_okay(). Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c48ecb25d5f8..42eebba6782e 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3152,9 +3152,6 @@ static u64 *fast_pf_get_last_sptep(struct kvm_vcpu *vcpu, gpa_t gpa, u64 *spte) for_each_shadow_entry_lockless(vcpu, gpa, iterator, old_spte) { sptep = iterator.sptep; *spte = old_spte; - - if (!is_shadow_present_pte(old_spte)) - break; } return sptep; @@ -3694,9 +3691,6 @@ static int get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes, int *root_level spte = mmu_spte_get_lockless(iterator.sptep); sptes[leaf] = spte; - - if (!is_shadow_present_pte(spte)) - break; } return leaf; @@ -3811,11 +3805,8 @@ static void shadow_page_table_clear_flood(struct kvm_vcpu *vcpu, gva_t addr) u64 spte; walk_shadow_page_lockless_begin(vcpu); - for_each_shadow_entry_lockless(vcpu, addr, iterator, spte) { + for_each_shadow_entry_lockless(vcpu, addr, iterator, spte) clear_sp_write_flooding_count(iterator.sptep); - if (!is_shadow_present_pte(spte)) - break; - } walk_shadow_page_lockless_end(vcpu); }