Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp183135rdb; Mon, 22 Jan 2024 16:46:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqXtpfbKpQl+aSAze7CgIw7UT3nd+exTC9HalOnyeAr6l0fp7MJ1XubHWleZ4HLX8y2cDc X-Received: by 2002:a05:600c:a081:b0:40e:b107:9e16 with SMTP id jh1-20020a05600ca08100b0040eb1079e16mr40112wmb.230.1705970815534; Mon, 22 Jan 2024 16:46:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705970815; cv=pass; d=google.com; s=arc-20160816; b=woN7kiiJ7UGPcVzt7yygkhSjDzQS40CmsQeYJzlhoIvra2Tbmw/Zd68KTbPG0TmzqR t6bZ6l+9FmwNlETlnCjRy7Okyv5m12JgcEcxMs/FEc37YOvDUDtpMl/0BmYAB+d/qIRd xau0cjxTf4HMIgx+XVRLiOD8dTGH4IG8Wff8TJ+Hm8UPApkOfiJ6EoX2C8YF4GmpWz4Z DJqzOU9ByB9cmTPzHcQu4BYfHeEvt+m3hj+dkUw5NvigO82b+DdwQkOm6z6tExv3oI1T AkC2yB4qRAw6J04bZWG86mzd9IiZriDlkLBo80+19XqOoBI4Wjhs4a+bJXwBPYsPNo2O T5Mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=g45WkpTHRjNfVBdOf5I7MG+ceS2djOI7VT1IIABR+vM=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=duhjU4NnBTDbpZQ7F1Nu+aZ5cZlFX3iP771oSLSVqJrjRbS4BO9PNE2xDlg972Shrd T56j5lkPdj5DpFjusnrhwQIF3IiHYk1NeeFj2kEjjBK9NbwNwUj77CZ+m6BvDvEJfwZy MuRsspXchP8c3pjdHfq5EF7tb2lFcHfOQu/pIYN3j96YZ2Au4o2/JiZZskf0WlaPG1z/ cTnpZZ3vSKNCTbFntF9fKbBFltPtcI/vaXOmpO7rID9k+depeFGP2BLg4OipRLLtU4fm IK8jw0hiTbwkBkK+JDvVVrIcRz9GQV1r4p+98ll/PaemRBx0evKYX7fj+VIfJNxcn9D0 nO5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZWTFz0Pq; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u11-20020a170906b10b00b00a28bb1b00c1si11463169ejy.1018.2024.01.22.16.46.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:46:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZWTFz0Pq; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 49D281F282CD for ; Tue, 23 Jan 2024 00:46:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8A91605CA; Mon, 22 Jan 2024 23:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZWTFz0Pq" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4540E60248; Mon, 22 Jan 2024 23:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967739; cv=none; b=MaunsbNoYvr6736IRIET7GZlCN7I8wVqr6dhWxt51quv3CFZdsrHlLEVo7gmvSIaOR5rwWUvcf/DPOF2x0Cu8GYPoNxJTPkwFd1Wi0Ms+zH7SQyzdHZWnTaKZDBH79kptCUnkNa48zTzb4CYDoIK2gR5d2qwDuLGYe8aP2H3TFQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967739; c=relaxed/simple; bh=2tOEn0svI5eYjclbb69emalwJiMYsXQtzlVRRlauB0w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rvxY4HKYYkwDaTk4//3W9g6370GDPuIhNR9pYYp8dPAIP7YpKZTehWJ+O3fH8IZJCT6XCqs9m+2hm59xj0BJ/QVRBJJND+kBs2JgqWcle42n8x9oIKp9FYWbyU0u3tn4B3tnU4PU44uH7E3sN9qgoMl1cT4tli+JQu1CwdecCqo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZWTFz0Pq; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967738; x=1737503738; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2tOEn0svI5eYjclbb69emalwJiMYsXQtzlVRRlauB0w=; b=ZWTFz0PqGf8ivsNHLKPa/4Q4gQH0bV5Evfkd9OC4n4PwOOZofv5UbSsQ DvoJQSbitVG/o4TOrVMWxRiox4lA+Ob3RG5gzMuppPz2v9oDnixOWtcit 3N89redpAEJ0V0tCZQ3YyA6MhlHMuP+16jQUxa7o7PEYZgucc6F8+gEvI YKDPJGxp50YRwCYBE3rv47oR+taizp7Q6u87kNDvZsHrFLRIlEhbLg8NM mSr9/d8BHwKhYUcSOvuqsDjnvdugBP8ePi4sr8orH8J4lJ3yfJmXMDHz+ nBiSM3Hvu5nTpghb0Ao0r0RF8Mahp3gb6wjRNxEG19iRdIMoohXxZKRa3 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="8016378" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="8016378" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="1468105" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:30 -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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 046/121] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Mon, 22 Jan 2024 15:53:22 -0800 Message-Id: <33812f5282bc42e0e8e6eaaa2a6a63ce4d258bfc.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 313519edd79e..0cdbbc21136b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -349,7 +349,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 @@ -361,6 +366,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 2b9377442927..97af4e39ce6f 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