From patchwork Wed Dec 21 22:24:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 35531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:8188:b0:89:790f:f786 with SMTP id m8csp4944872dye; Wed, 21 Dec 2022 14:25:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfJ6jRItYoToar1zeHY+rDnL5iqocSAMb294kIOH6syFCBKeGB93dq/Y1V64M8Wpt/DDPu X-Received: by 2002:a05:6402:3983:b0:475:c640:ddd2 with SMTP id fk3-20020a056402398300b00475c640ddd2mr3304387edb.26.1671661515330; Wed, 21 Dec 2022 14:25:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671661515; cv=none; d=google.com; s=arc-20160816; b=lasC0Z6rtSaO7wl6VrHYwcEDLzXKpOm1X4DyoZgnQXSyJQFrW+TykCplhJ/6pdtpDy 2OggpzyLuW002OZqwNONl4fNV7ks8jSJLPsrrv/RWyz6Z0+o7ZtUEGVIegcVg8SkZFW0 h2aW5lDNQFZJl2F6GyLSLLS+OD8QSM5hlQvzO1ELS6fRqo9xpUiOQZY+EZgjsrzYDlGb b5+0ZybcvnugcTsC/7H/awE0IQm6S5Lkm55MkwlKV+dqKpARiKEflWtkT/L/Zw1Ljtsg 3/FSLQHYb5V/1Y5DPesDPzc7eV9Kv0fHK7rQgWSpq7JG+S/dpljNYVNwMRmfOdb+b54G Bu5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=aKlgYMYIrlGLbMYP963Rt32Noqo2pCtoxK8D34uyWJ4=; b=E2DKCIDo6ob2ngXw66NLo3kdvGRBgbFYZenNIhMaFIUydpJ9IL969JFNiMn15UtXlz FD6FyHEOxk2gMeByPf2QcIB8VBRdmHFMowI3kapT5csh6Mu+kaifA7+YgURU3Gu146NV Y1TQYSZ271Jyi81+S72Tl7N/i3t8qPm2v7yWw0EFapraKni+BaU/6o3D3jYdQ55h8hr1 fPaHTn7tzCgN3VYmbbaSdjIhgMwpcMffDqe4T8rjyKd23QGry1NeTYOpyDpm7KMCtqSu JuWzKvR4+3Ysf+kL3LIn5mgX5Ol+aOIyNA7DTKllOB6nZ6A72M9rFciSeTiuzTmxwfdQ 2cVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PWqhNCgk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ta9-20020a1709078c0900b007ac60b83407si13794046ejc.725.2022.12.21.14.24.49; Wed, 21 Dec 2022 14:25:15 -0800 (PST) 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=@google.com header.s=20210112 header.b=PWqhNCgk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234945AbiLUWYa (ORCPT + 99 others); Wed, 21 Dec 2022 17:24:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234897AbiLUWYY (ORCPT ); Wed, 21 Dec 2022 17:24:24 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1961A27164 for ; Wed, 21 Dec 2022 14:24:24 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id k22-20020aa79736000000b0057f3577fdbaso475pfg.8 for ; Wed, 21 Dec 2022 14:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aKlgYMYIrlGLbMYP963Rt32Noqo2pCtoxK8D34uyWJ4=; b=PWqhNCgkLNsL4LTq6n3P2N/wL2IC5fNtKlHcljZPjv1KMJIXNnu+jM/wiOaUfvSQzQ sqxmogZSTOlLja/osRpS7Ow8EfzSUYnreoaLWkkFdbixfiBmjccx0+KswydFi9OPd7G+ ufafOm2aNUYdbkAWCv2FGT5m/chD2Utam3lq9+XJO5/Q1b+hNSmrMeQga388z7ynT7v8 NX7DKNfpSeQMnVeRYugzoXNHWHSvxsw+I6ma6X+E6cBtDFf2MAyzy1YNcTGk8tmCzLNd ney/iJw+QhWYPcoct/qe9KDj8ngJbHLXsqU23YGjejcPJ/Eqxv/IM84tu17ag52e0e8x 5slQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aKlgYMYIrlGLbMYP963Rt32Noqo2pCtoxK8D34uyWJ4=; b=jeRoZiXDXqNratWFstsbBBv3NvCxI8PDSbm6Xyy9Vl/rIiLhWN2Hea9a1+bjXaHLBv xygDM2wUjMhdPc1zaOxaGOl9UZIUoEZsS6sHMlByDPc7esREnc6o7dRRrYldTfT3vBcy ydq58iYtAMt+7qsR9UQHhJhBhOyA8FKmuWFI967Qiai49ze3L4ktbOO2OfL6Jq7i1F60 pQpHml0qOOBjRsrsyEq/TP+dwbRRMW/RnKPSc5228l0A5DFbVQH2F5Q4mI4FcAqtlBoc nHPq7uGL/Zo/A7M3czS8zrIyR2YtkPfDEWIHiBkNKO2WJ51/Jtbf4jFZLgzqPelkdO4+ FdqQ== X-Gm-Message-State: AFqh2kpLpnKK8+mRXk7LERwvjers7Fk+O+kT06HujJhyWtZDiKxXDTbO xVXRCbRef36i3eWZ4Xg2SmZcWp/x00R8hpRe8ZteC7D8JIzGgfXBNPZKdIkTx/gp+dior+qgKFn 8jsiZaRCBcZCGtyfrAbaU60dYjbPDGQtumNxZot+lg6iUnIUKvJ0yeW4D3/422x64iis3gr3L X-Received: from sweer.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:e45]) (user=bgardon job=sendgmr) by 2002:a17:90a:6845:b0:219:2bc2:f71e with SMTP id e5-20020a17090a684500b002192bc2f71emr274766pjm.142.1671661463529; Wed, 21 Dec 2022 14:24:23 -0800 (PST) Date: Wed, 21 Dec 2022 22:24:05 +0000 In-Reply-To: <20221221222418.3307832-1-bgardon@google.com> Mime-Version: 1.0 References: <20221221222418.3307832-1-bgardon@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221221222418.3307832-2-bgardon@google.com> Subject: [RFC 01/14] KVM: x86/MMU: Add shadow_mmu.(c|h) From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , David Matlack , Vipin Sharma , Nagareddy Reddy , Ben Gardon X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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?1752864145471442438?= X-GMAIL-MSGID: =?utf-8?q?1752864145471442438?= As a first step to splitting the Shadow MMU out of KVM MMU common code, add separate files for it with some of the boilerplate and includes the Shadow MMU will need. No functional change intended. Signed-off-by: Ben Gardon --- arch/x86/kvm/Makefile | 2 +- arch/x86/kvm/mmu/mmu.c | 1 + arch/x86/kvm/mmu/shadow_mmu.c | 21 +++++++++++++++++++++ arch/x86/kvm/mmu/shadow_mmu.h | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kvm/mmu/shadow_mmu.c create mode 100644 arch/x86/kvm/mmu/shadow_mmu.h diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile index 80e3fe184d17..d6e94660b006 100644 --- a/arch/x86/kvm/Makefile +++ b/arch/x86/kvm/Makefile @@ -12,7 +12,7 @@ include $(srctree)/virt/kvm/Makefile.kvm kvm-y += x86.o emulate.o i8259.o irq.o lapic.o \ i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \ hyperv.o debugfs.o mmu/mmu.o mmu/page_track.o \ - mmu/spte.o + mmu/spte.o mmu/shadow_mmu.o ifdef CONFIG_HYPERV kvm-y += kvm_onhyperv.o diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4736d7849c60..07b99a7ce830 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -20,6 +20,7 @@ #include "mmu.h" #include "mmu_internal.h" #include "tdp_mmu.h" +#include "shadow_mmu.h" #include "x86.h" #include "kvm_cache_regs.h" #include "smm.h" diff --git a/arch/x86/kvm/mmu/shadow_mmu.c b/arch/x86/kvm/mmu/shadow_mmu.c new file mode 100644 index 000000000000..7bce5ec52b2e --- /dev/null +++ b/arch/x86/kvm/mmu/shadow_mmu.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KVM Shadow MMU + * + * This file implements the Shadow MMU: the KVM MMU implementation which has + * developed organically from hardware which did not have second level paging, + * and so used "shadow paging" to virtualize guest memory. The Shadow MMU is + * an alternative to the TDP MMU which only supports hardware with Two + * Dimentional Paging. (e.g. EPT on Intel or NPT on AMD CPUs.) Note that the + * Shadow MMU also supports TDP, it's just less scalable. The Shadow and TDP + * MMUs can cooperate to support nested virtualization on hardware with TDP. + */ +#include "mmu.h" +#include "mmu_internal.h" +#include "mmutrace.h" +#include "shadow_mmu.h" +#include "spte.h" + +#include +#include +#include diff --git a/arch/x86/kvm/mmu/shadow_mmu.h b/arch/x86/kvm/mmu/shadow_mmu.h new file mode 100644 index 000000000000..719b10f6c403 --- /dev/null +++ b/arch/x86/kvm/mmu/shadow_mmu.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __KVM_X86_MMU_SHADOW_MMU_H +#define __KVM_X86_MMU_SHADOW_MMU_H + +#include + +#endif /* __KVM_X86_MMU_SHADOW_MMU_H */