Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp560823rwb; Thu, 12 Jan 2023 09:19:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXuCFkdiPdb0Rg/dR604o6r+7nag7IwU47rD1ABvsOp/fkys4ywvkIpJ/aCLo6K4lzanWFdp X-Received: by 2002:a17:907:2c6c:b0:828:7581:f01f with SMTP id ib12-20020a1709072c6c00b008287581f01fmr58275761ejc.23.1673543980711; Thu, 12 Jan 2023 09:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673543980; cv=none; d=google.com; s=arc-20160816; b=J+Iy94dghUe8fR3exAiqMqNywx662CMKzqs84qXu/PTY5yekTgOwyb5C7XhzGV0XpP PqVbcglgplh6GvLwrM3LQB6XjWdJLTUQWNBCPDiNm/FwMuYxtPfqjHiQjobzPixccAmC WJdm+p7iFKl30HsmXPwZo+/W58VWcAAZgeHR9YFRB4q2xgr/2bzN356FgcvWPj/b4SZq iXQlEZ0R7Qx3lwzZ5jfp2ZZoz7JYlQH2BWxh9PJsfkN7ABAddcGJc2oVIp4UpxJtZVnn lEOqtSQYo5Xus2GEJPF7uVi40gv/u9s38yhbW4Ku0NnhqUWNxtUAzWuedttbDXXQdEmV et4A== 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=1JJ+3M3aBJBaqXQ3O5ZM6RPbxmhL7xMAGvvZo8z9IJ8=; b=0mzn0uCbUi7a/PpyxQZTXeiFKGO0TplKR6didYeCdJTb0P9diHsD7T4CJZ09/MrGsx 8DWNJ2S3zzvrslVrucQKHOpXTyyhZ7i57oZP7TOgG1rJb9xTAPXm4bNbqcF41Duw1ErS DltOm/l2k6h725/IcD6W5K0dSpGpIjNa3mXUwh4D1LUvzlM3gfQlyrtcyC8ms6+Za8rQ uIh052t4u3tNg+z3kHfwGbU6+n5xgcXV6tl7F0wa4r8WiOK5dhReah1i0praogsocDtH NOJKv4jIRXyOwYaVSaa3uNtTYTmROFBqoQaqvymfPaEf5/gpF/BQ9an6j31mCTDAc9E1 31Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WCVcPh5E; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf11-20020a1709077f0b00b007c083c69ec3si21365155ejc.155.2023.01.12.09.19.28; Thu, 12 Jan 2023 09:19:40 -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=@intel.com header.s=Intel header.b=WCVcPh5E; 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 S240907AbjALQqQ (ORCPT + 50 others); Thu, 12 Jan 2023 11:46:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240189AbjALQic (ORCPT ); Thu, 12 Jan 2023 11:38:32 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 002F6192B7; Thu, 12 Jan 2023 08:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541242; x=1705077242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S/jw3kznyhrFvcMs6VGxaBJFTYyJIkmtsa5BZ49TGDU=; b=WCVcPh5EJCBQN25z6mAqO36v2MG9GhWeVoi0PUdSnN+LUgrErfMDn15I op4pPW/utnMt1azNygGkqLaX4lFP/PpjBRiLbWwi+ktR3p4UQwUcStZJe TdmI89aRmR2nwh3VfCKbAZgqWwOPkPEFjgLuBg/1XVc7xy09EHBliWFMb lFkKRpqyyU58RH0j9kqucwPbSV/ub9U8U6aVBX75Ei05ltUPQPW+a6k1q Zo3bGuWODcTLgun860W/u2pZaeNMOxPMETgV65ypt8BMZyhuaRvVbWVtl /IFdKI6teaPULePOD1A7wiiXze7kzpnqsxR98SnkgoUFpAaBKJHvYrhf3 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811843" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811843" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:26 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151769" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151769" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:26 -0800 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 Subject: [PATCH v11 040/113] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Thu, 12 Jan 2023 08:31:48 -0800 Message-Id: <8e1c92dd0726e2f2e15cee33fdc4480a84f85b83.1673539699.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=-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 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 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 f5b51bdef0c6..1bcd118eef31 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -342,7 +342,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 @@ -354,6 +359,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 6767bc9b7c5c..a20b54060bc8 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -143,6 +143,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 256395eb593f..7046671b08cb 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -251,6 +251,12 @@ static inline struct kvm_mmu_page *sptep_to_sp(u64 *sptep) return to_shadow_page(__pa(sptep)); } +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