From patchwork Tue May 9 13:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 9092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2944832vqo; Tue, 9 May 2023 07:52:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LWaTsUDI/O4iDY5eITJIyHtElxs+ayG+driLgqK6GJ0L1yATvJBBSxMyZaw48pjgXqA97 X-Received: by 2002:a17:90b:3685:b0:247:9456:6e13 with SMTP id mj5-20020a17090b368500b0024794566e13mr22223934pjb.11.1683643941035; Tue, 09 May 2023 07:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683643941; cv=none; d=google.com; s=arc-20160816; b=oPwWQp/67hqdTmoGOd6sqSmMLRptjHumYpU13OM82qlNtfATO3Jp693CbbzSyLKLyR 0tWyC0lpD9FiOVr2y3zLRbJOhEDrMhwYurtA+h0HDvuhbgKntMeOssrt8PwQkp3YMkcm R4byHpjZPqJX6sjw1FMCKTq3fIWS/zFOuIjbFoKxHpQOWq1zJ2MNUl2yNHZapMw7r/Ou ARbByV7coIiZzBBi77rMatRnUaSNm0+e28TAIVCaflMVTeKc7qLI8NSy5nNq7UBAxYcX RLM4p7RfL5bQ2vRT8ROXZ08Ck9ffrNcFEmtzBe3I5+uU+Cdz+hNPqfRsglL4+H2NZZYY kpoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=iMkJLU7QiljXNZ9lGu5vt4V6DPmSbCjqwY07QVstEts=; b=S5yK/QyJNYMwbyP+bGNSp+kgQh+HyT0HBYzxvVLNbkYTJkzSi3+vM+Q2j8bOMfH5Du n5Ti/wFpFOAEQoKT6ZBakZV2jzEcq/1VHcqqmD1wnSPaPwarScbrxMwFyf2NxHlYA4FV VJ+HFG5Nb5TAk0kff0MMS7caO6SwIKt9C99jL8rxPZJah08qGVYd97Ge6KIz2xDE7FNi +HLOkgYbtB3kaF0mKgmnMUcDgiigkEzOaTNakg68bgAq1Nc13DTh4TGpFwKYBDavWPJk MBNGflSDw/e9ra7Ai7hQLUtWoe1+KyDzB1zjVlbFnxH+f/S6Rhy6JDBplxVhdV+vC4P5 14uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SzwrZoKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020a17090a62cc00b0023d23393318si27185571pjs.55.2023.05.09.07.52.06; Tue, 09 May 2023 07:52:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SzwrZoKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235782AbjEIOO3 (ORCPT + 99 others); Tue, 9 May 2023 10:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235696AbjEIOO0 (ORCPT ); Tue, 9 May 2023 10:14:26 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E14E30E9; Tue, 9 May 2023 07:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683641665; x=1715177665; h=from:to:cc:subject:date:message-id; bh=iVlDQQpz9DCvQbjZv8eKsfsBkjZ19iJ/3jfnKsCHqwc=; b=SzwrZoKJ23uaJ4k422J8HQyuvE2VzGQD3czsryIwVLeQUEgz9CvqKbFU FYpxxNans3a/W4uGEqB5cYO+AKLDBqSITXVYmcYiiD0VjSFFTV+K3neiT v/g2/qyg/XGtL+17IQNU/lkzoa+BS4DRBKq4bbpXALpHqsw7smw0aZmL0 Fu3skGl92z3hKv1x5exGR+uUcR6Lh2OKvpWO8OdA148pifKuYjzR675uP 6ldLltBqFyISsEtZdag+CViegB8iYeHN4wTOBWA/8SlpMS+tAem6KkYW+ +RjoAG+1BXmAf6m3G/e26WYUSruiBx5fQEE5QfLyfZLDTAx3fj9Vhmb9X g==; X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="347399454" X-IronPort-AV: E=Sophos;i="5.99,262,1677571200"; d="scan'208";a="347399454" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2023 07:13:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="649345967" X-IronPort-AV: E=Sophos;i="5.99,262,1677571200"; d="scan'208";a="649345967" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2023 07:13:39 -0700 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, Yan Zhao Subject: [PATCH v2 0/6] KVM: x86/mmu: refine memtype related mmu zap Date: Tue, 9 May 2023 21:48:25 +0800 Message-Id: <20230509134825.1523-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765428629221546842?= X-GMAIL-MSGID: =?utf-8?q?1765428629221546842?= This series refines mmu zap caused by EPT memory type update. The first 3 patches will only do mmu zap when the target is to update memory type of EPT entries by introducing a help in patch 1 to skip non-EPT cases. The 4th patch will trigger zapping of EPT leaf entries if non-coherent DMA devices count goes from 0 to 1 or from 1 to 0. The 5th-6th patches reduces EPT zap count by introducing a per-VM based guest MTRR and only zap EPT entries when this per-VM based guest MTRR changes. Changelog: v1 --> v2: 1. Added a helper to skip non EPT case in patch 1 2. Added patch 2 to skip mmu zap when guest CR0_CD changes if EPT is not enabled. (Chao Gao) 3. Added patch 3 to skip mmu zap when guest MTRR changes if EPT is not enabled. 4. Do not mention TDX in patch 4 as the code is not merged yet (Chao Gao) 5. Added patches 5-6 to reduce EPT zap during guest bootup. v1: https://lore.kernel.org/all/20230508034700.7686-1-yan.y.zhao@intel.com/ Yan Zhao (6): KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes KVM: x86/mmu: only zap EPT when guest CR0_CD changes KVM: x86/mmu: only zap EPT when guest MTRR changes KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count KVM: x86: Keep a per-VM MTRR state KVM: x86/mmu: use per-VM based MTRR for EPT arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/mmu.h | 1 + arch/x86/kvm/mmu/mmu.c | 18 ++++- arch/x86/kvm/mtrr.c | 112 +++++++++++++++++++++++++------- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/x86.c | 10 ++- arch/x86/kvm/x86.h | 6 +- 7 files changed, 122 insertions(+), 30 deletions(-) base-commit: 5c291b93e5d665380dbecc6944973583f9565ee5