Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2609251rdg; Mon, 16 Oct 2023 09:17:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtn+Y+BIrK1bDNPsMRQS6dqsFF04LRGlhrJI7s2O4Hb7oIusX68ixrf5odGky2Kisg5Dwe X-Received: by 2002:a05:6a21:4988:b0:172:f4e:5104 with SMTP id ax8-20020a056a21498800b001720f4e5104mr14206504pzc.20.1697473040039; Mon, 16 Oct 2023 09:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697473040; cv=none; d=google.com; s=arc-20160816; b=Iq8kpOIjDpnDMpmHyAteUwybF7evGg1EXHOxnZZCNS8N4FGvJLxcdqii+lr0FTF7qX tGpOWh8VuR58rBUoktuSzriCc/nfGr/uthh9TEUJnQzwn0uYAV4Ls/VWqSBVWiJdnMwE jWBsvJYS2PSrmSvbikG5V3mD/k7cgn1xd0bKjgPWpRC5m3jhV+lenDML02dALZG9IBMj WI0QR+BVc0yJdcVi43DdbcEgyzQ/duUlahc/RgmefP4K/qAbBG9y73ESfuyvONJKRf/Y cRmJjXngWYAa6WLAW7UvtH/ms9WYiPPokQaHlX5g2C3jTeoofWCrY1h82PU6cqvgYe9l cPsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y982War7Y42iESRVVNvIx0ngE8yYxOM6LeqYQ+pjNOU=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=XytXNkhJWpZJ2aC+Nw5jVR3NluH7A++Yu1KkDJG7pZSAwjvOMQZjHmnUw/hjFdP9/9 eV+H4DlBLbKZbpYuIpKUHsUdgHK99CDtlPO88f+Lndcr9u5NcQGRCq7o9CFgtPskgQ7x +YJCdx2G5dBL4sAyocuBKK4qTBmfr9BHNT6diqugyJqQu6Gbb/nuAaW9Abz14CUyTH5n UiwmnUzDEaoi92wXDtWCldrodNDobD8bXixIWnKI61jm3LkIVBkppzduAXAfFYLAajkQ t1WvpmpR4/3vP1qpRMQQnAnB+TBQM3MYEAP4qaxytlPP/NdAI1xaT9YfQKBTrDJTL6JB XEeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XibQhhp2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a15-20020a170902eccf00b001b9ffda162csi8094885plh.441.2023.10.16.09.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XibQhhp2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8652B804A484; Mon, 16 Oct 2023 09:17:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233732AbjJPQQm (ORCPT + 99 others); Mon, 16 Oct 2023 12:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjJPQQg (ORCPT ); Mon, 16 Oct 2023 12:16:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC1CF0; Mon, 16 Oct 2023 09:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697472994; x=1729008994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tBh4x5NVn85tVT3gq0UMO4KHl1axLMCXo4q1WaHLaQI=; b=XibQhhp2lCTDb+SczXJcq6zjZQ9zSXOJrsF6t4l7UKz2hIJpexDjmRxb GS5bXpMegAKC71m1qe2oTVJCFM6yYxhkEhNtCrW4Q2Dw4Ixz35udAcXSP yIN0Qi1i7z5JGSdXKfHlpTLxlfg437NiDYUTa4I/9B3Ynhx2ibIrADDpY bG3vnoUPCZToNvBBTewsbSsBZvCWKa2B+C2dNPEVkrBwvkyZ9hSMdKvnl i/r649Gb+e7K6JencrlHYOi9n7/HHQjbspQ0uBTH/18WtoG6ZPz+0IqNo HAvC8+aLvVRWoPbjm28qo3ZlEQiVBc7ihd775AYTplYFP4Pg5y8FpsQDa w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364921738" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364921738" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="846448098" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="846448098" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:41 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v16 042/116] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Mon, 16 Oct 2023 09:13:54 -0700 Message-Id: <515ae014205e4f034df4d5dae53292a14a67cf39.1697471314.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:17:06 -0700 (PDT) From: Isaku Yamahata Because TDX support introduces private mapping, add a new member in union kvm_mmu_page_role with access functions to check the member. Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 27 +++++++++++++++++++++++++++ arch/x86/kvm/mmu/mmu_internal.h | 5 +++++ arch/x86/kvm/mmu/spte.h | 6 ++++++ 3 files changed, 38 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3970473d1807..f8664becb1e4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -341,7 +341,12 @@ union kvm_mmu_page_role { unsigned ad_disabled:1; unsigned guest_mode:1; unsigned passthrough:1; +#ifdef CONFIG_KVM_MMU_PRIVATE + unsigned is_private:1; + unsigned :4; +#else unsigned :5; +#endif /* * This is left at the top of the word so that @@ -353,6 +358,28 @@ union kvm_mmu_page_role { }; }; +#ifdef CONFIG_KVM_MMU_PRIVATE +static inline bool kvm_mmu_page_role_is_private(union kvm_mmu_page_role role) +{ + return !!role.is_private; +} + +static inline void kvm_mmu_page_role_set_private(union kvm_mmu_page_role *role) +{ + role->is_private = 1; +} +#else +static inline bool kvm_mmu_page_role_is_private(union kvm_mmu_page_role role) +{ + return false; +} + +static inline void kvm_mmu_page_role_set_private(union kvm_mmu_page_role *role) +{ + WARN_ON_ONCE(1); +} +#endif + /* * kvm_mmu_extended_role complements kvm_mmu_page_role, tracking properties * relevant to the current MMU configuration. When loading CR0, CR4, or EFER, diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 8de1192b1cca..a510f0a16853 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -145,6 +145,11 @@ static inline int kvm_mmu_page_as_id(struct kvm_mmu_page *sp) return kvm_mmu_role_as_id(sp->role); } +static inline bool is_private_sp(const struct kvm_mmu_page *sp) +{ + return kvm_mmu_page_role_is_private(sp->role); +} + static inline bool kvm_mmu_page_ad_need_write_protect(struct kvm_mmu_page *sp) { /* diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 1a163aee9ec6..88db32cba0fd 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -264,6 +264,12 @@ static inline struct kvm_mmu_page *root_to_sp(hpa_t root) return spte_to_child_sp(root); } +static inline bool is_private_sptep(u64 *sptep) +{ + WARN_ON_ONCE(!sptep); + return is_private_sp(sptep_to_sp(sptep)); +} + static inline bool is_mmio_spte(struct kvm *kvm, u64 spte) { return (spte & shadow_mmio_mask) == kvm->arch.shadow_mmio_value && -- 2.25.1