Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1177192rbb; Mon, 26 Feb 2024 00:46:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMdkklRC33ahietw2uvsrUUGs6+5fhPPQj+YTDly/mPbPkNXNzOb6CJLpiCt0Ad184fO4PBmQjSHOxNTLsN2FFGAaGtx3s0aOCOPQicg== X-Google-Smtp-Source: AGHT+IGX6zkblFt6C84z4X2lLE6k3gwn5KZP8ttgtu5QcruO9NX/7jzjw+YDqvbfde9xnLJqqVlT X-Received: by 2002:a1f:cac7:0:b0:4d1:3f59:5c79 with SMTP id a190-20020a1fcac7000000b004d13f595c79mr2634410vkg.15.1708937165332; Mon, 26 Feb 2024 00:46:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708937165; cv=pass; d=google.com; s=arc-20160816; b=VotLxkswW4oMu9Actx0IN20aLRlBjxfbP+HGqBNCP9yXV4EPdYyDUe5+vG5oUScEwa Q9G9ogRzLmReJ1c4tWelNSfgyKoDgLHdSSuKB3yebxpTlm0BNBkE1DfD7oiguWIuhAhG oWM0QYnIzYZClXc4Eww9O9rZJPbHuVSMum+a56G+34btiecsbcxJW/KZElrlYVm4VvlZ lCrZZFx8MVWohdbSo7bZXMOrHkMtQZaota6lIdV+/Zhs0u9A5t9ck5L2i9vTfQ6mVBBH my0Eo2cJ4gnUd9AQfVQ9By55g9sA7c+TBtxRuJgsycyYE9L1RE4ZFHxaPGmQzs71URWw vinA== 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=5g8fu/83/p6SQUz8R+MkA11bncdtcIX5WVNIIDXTRK4=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=L8ISBtFFBvRudjAc2vtTri7X7EJbRFNQZaDCkJI8dWCXHme8Y6QJz/2c4O4xXckOPH UZSHmBvJBAAqnGWzt6GFa2lMVGwHc8s/lq2v6tjI9w7wWrlkbj5q24JheKm3x4nNbCOW 3tZJ7htgtl9/jnRLiF1SJnER+FZmQZ0TzwwVwesbweHuRiC7vY+49EUd3fukCwHhAfLd fmgHC7zoGCZ366xqblmCJHbjoIe7sG2apll7dCT0W6QRCsLQOOhHyY32ZQuiMQ/aTlZV jn/9ITDtoaqI+a0aSqRdt5BcXvvFk7gVKYp/TEc74micKrPGeG9yotIEZvn3eTduGVDx +LZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hyGN813+; 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-80819-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80819-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jp13-20020ad45f8d000000b0068f34f52833si4568003qvb.107.2024.02.26.00.46.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:46:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80819-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hyGN813+; 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-80819-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80819-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1965C1C2093F for ; Mon, 26 Feb 2024 08:46:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F016060BAE; Mon, 26 Feb 2024 08:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hyGN813+" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 BA7136027B; Mon, 26 Feb 2024 08:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936102; cv=none; b=ie6Y+tMHPXwj+b+lzl/G3BdCkqhemCh73vlSuaAVAIc/rtndwITu9HoCFnws/TG0yCYQs0lbo6Afpn9J8dUt9Gd+UH4XW+Bvl3Kb8gARHXWtifsttfeJw+CE4bm8N2Zg8tmz3xCL2nCmao4Q3aKfkqQQihYmTk3F4WDCcijHmOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936102; c=relaxed/simple; bh=rcbdqsS4hYOqhGj7tlgdIuvBw0XJL9OLMgxeHGcJc1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tyYbbYcOXSwFrSjomAaUIsWeudUNbGJAAO341ecLmxgC5FhUtHeQLCgsS6JgaIkLWtYNLuVDtoe5h2vajnJhsUvcRZherY4p3le3k3tPgxEdmpU8fe9dam0U3B2nKmh0SSbbCEGSOemVUB+Ay8HKlASeiGN1Cfcbxht7jot4b0Q= 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=hyGN813+; arc=none smtp.client-ip=192.198.163.13 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=1708936101; x=1740472101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rcbdqsS4hYOqhGj7tlgdIuvBw0XJL9OLMgxeHGcJc1Y=; b=hyGN813+aARFCVEVzlmtpmYG0zvxeYcxG4N6tEadnCO9qoi9okMDXeEI 6OeqgoAjmjqnY/9amSZWF+v5GrzwIpfixQ+xgb94kyusF4IAidGjfcXCB AFOZeaB6LbQw9sDj1GIqEUxwmKyVRF7JjjhcM12bE72u8yQOkskWiTyuO OM1Eef+6f4QWA7hxPSOsApB4f/Dn7ivKGxoY+55+tfmLPnbL8o4cO9bIE fj081J5NtRKUFHHZV7ai9rXi9fIq5+V2zQ675oNTOB49RUWH+Erbsa3Tq 06RwUYvZbA/EqX7DH4yGhzXHKKmGY6haZB99BiD9NyJfE2i0n7xo9xqI8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="6155421" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6155421" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6615878" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:16 -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 v19 057/130] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Mon, 26 Feb 2024 00:25:59 -0800 Message-Id: <3692118f525c21cbe3670e1c20b1bbbf3be2b4ba.1708933498.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 --- v19: - Fix is_private_sptep() when NULL case. - drop CONFIG_KVM_MMU_PRIVATE --- arch/x86/include/asm/kvm_host.h | 13 ++++++++++++- arch/x86/kvm/mmu/mmu_internal.h | 5 +++++ arch/x86/kvm/mmu/spte.h | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 6c10d8d1017f..dcc6f7c38a83 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -349,7 +349,8 @@ union kvm_mmu_page_role { unsigned ad_disabled:1; unsigned guest_mode:1; unsigned passthrough:1; - unsigned :5; + unsigned is_private:1; + unsigned :4; /* * This is left at the top of the word so that @@ -361,6 +362,16 @@ union kvm_mmu_page_role { }; }; +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; +} + /* * 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 0443bfcf5d9c..e3f54701f98d 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..3ef8ea18321b 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -264,6 +264,13 @@ 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) +{ + if (WARN_ON_ONCE(!sptep)) + return false; + 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