Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp266405rwb; Tue, 25 Jul 2023 15:42:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4MydclZ2TUP3iMquT/aVlXZvH6OVrJImKYptHoVlrIDmVd4wL7vTRRqhgq85dN0SUcwJw X-Received: by 2002:a17:902:a603:b0:1bb:9b48:ea94 with SMTP id u3-20020a170902a60300b001bb9b48ea94mr516121plq.32.1690324957350; Tue, 25 Jul 2023 15:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690324957; cv=none; d=google.com; s=arc-20160816; b=rQEn3ifdZ7KQ/120/tzj2WR4XXQGfFX/5j2M0g6rQsKQEQiz/WesDIgFuQn+nlsAGb bI7UOCew24OTxnWJyS0I9tPv3Q5UQaYXEPMNWYbNKRYZGvNAUXCTxQULcHcUpWdpPrTX Gpwr+Kfy69eD++0UIhHe+9DDrM/enNtVvYdrrhPn9LE8xGDKns/T0YBS9Ua78LTtzEU0 VJb8kDspDxXdSIn/1jCiA9CzK+0lPfzmZU+/Wwa+6G00xAYPgswNmWhxKIHslxE62VEs qdyeI1UN9caaobpJAlIivbDLTQ4lq2RBDrd6edW8+50LDMYbf8pUTIPHoaHnVO8kGLXh ELjQ== 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=6T9C2CVSNgWae2xGkoVjQNcagREDcZQv4AXqV0bIDis=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=PNmRGEEKuGp4T42pDHV3gs1Ip1vPi/rEAXGjdZ7jhe9zQSxOSBJprCH+RS92kkKGQv LVachFjPknJxjjfEVlTNeQ2WVRVwUQbiqjMzumVDhGuecyOxJs5V+xXMMohVO720kiab G72LDXU81B4THlWtKGOd3FQ8q+6kToAliwyl2DUCV5IS3n7T83fLKzmUSdqsoyJ+ePiB A+2nqJKpJwyuBjgUjRA2gx8IpQrJurPJZxb2+akXlzpJJrU0837PNKrDx6XAkLIbUMQh bMmVhGiyG2WPHYkKt/SNMjVaVfuVQDMemtNAZ3LAd2HqUW5PqKNmM1Ir3xIaWP4Csmtn rlNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k4yM29fX; 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 l13-20020a170903244d00b001b89b35deeesi12705319pls.390.2023.07.25.15.42.25; Tue, 25 Jul 2023 15:42:37 -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=k4yM29fX; 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 S232433AbjGYWU2 (ORCPT + 99 others); Tue, 25 Jul 2023 18:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjGYWTV (ORCPT ); Tue, 25 Jul 2023 18:19:21 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 024C24482; Tue, 25 Jul 2023 15:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323392; x=1721859392; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oSpwVS/FUjL4d73DdU92utlrGySSdjlxHtDcqhGvYZw=; b=k4yM29fXIQYiIa+0yHggSdfvSE18XSyYon/D0F8QTPwMGvAtntEsFmgh 7ea81ELsvF73lm6Y7m18wb8627SjRFDfhMES2t1/SZsmsgakOS3gkZ/Sg 25WpA0cBKRjlWG2vmwJ+V8kbJV9yT2HSu5q5NdcOlapx+89Updipzg5nJ t6SOrqp31S0Ag/1OJ/KJ4dS3URoiyAk0vqZGpy9gsR0SkNqk5QaaIrN4F UcvLkxUl2JavL0sE3eK1xDfdXD6vxUSLpyA1cUm3t3tBMFJ7SKYrabFZQ HPmOiFylwuubMX7hm6pMUyVf7iKtB6drpSij4W1vMLaUf6Yj6SoKGvM8t g==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="357863260" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="357863260" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="1056938923" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="1056938923" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:36 -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 v15 042/115] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Tue, 25 Jul 2023 15:13:53 -0700 Message-Id: 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 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 0bc53c942c6c..56f9297b1bb8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -340,7 +340,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 @@ -352,6 +357,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 76fa38da74f1..2409c4dca208 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 a8418fd8ae9e..41973fe6bc22 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