Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2683660rwd; Sun, 28 May 2023 22:08:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lU2987VM3PDKtquhbXHTiKhsjyi3eujyo8vu1PSZUVxf48rbH8GbVoLxZByO7Hxrv2SjG X-Received: by 2002:a05:6a20:3952:b0:100:6f8f:7793 with SMTP id r18-20020a056a20395200b001006f8f7793mr8509086pzg.3.1685336918261; Sun, 28 May 2023 22:08:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685336918; cv=none; d=google.com; s=arc-20160816; b=BrwLp8EalI7EgB1s2GW3oHo/KXi5MRqII0aSMPOD7cXpOZEbyBJxQBKyXgJKAgoj5f 9KZY+V6LxBLHBc3CmKVAiQrKBd5RHqHNFlLMuPGSWZBwFZyRZRqOA2JnU0tTjCaxuemy KSYzwXrGwMc8zJS4S3cS04km2JCja+acVn+IlTeigOv5viFrOBm70geHgSW1Z4kl+air jDqqbjQ2azcVGuW475wcOZPym8djs3H+tDlNeXN7IbVwNL3PUPD0gC0bs8v0dWW2Po2+ o36d4OykCWiaLr9H/vagiPfkmdqM8jW9O10czCudwWJU+18pY3GDwF8IyYDjekL88nrU yvXg== 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=ymBtFWTbHrSl8aDExoghbCwUPr5ErmCOxrI8qwJgNaE=; b=f1fjBHOWvnctCB4sNg2Wi9wxNrOf/EAGmpg3K36esRtMfRjTS6uS9nITDV1cIYlb37 Gh0r55leBDYbeFAgkTBMoUMkri6MKI9Q+XvJg4sdgM1noX3czGm1YdvHyv85+POKilcJ 6ku4KXQpFWp9VrLY+640nfmj6y2NOIAfeLX+Rx9OLVXo629vfHPQh1fNP1F7vaZ5MYRt b5YYSnuok4Scn0Y/UhRvuNSaapwoby5X3znjCthHa0gO44H/v1yiH34kAyB8HHCDxUDz VJh1X4lfyhvRT77XM50uwmG1GHUTTxh0fSxUZ4qqdlJFTD3XFbcFm19BLE7bJGV1OsOl xYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g4U44pa7; 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 d27-20020a63735b000000b0053f2601e5a4si4234919pgn.737.2023.05.28.22.08.26; Sun, 28 May 2023 22:08:38 -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=g4U44pa7; 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 S231778AbjE2EZf (ORCPT + 99 others); Mon, 29 May 2023 00:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjE2EZB (ORCPT ); Mon, 29 May 2023 00:25:01 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6C319A7; Sun, 28 May 2023 21:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334165; x=1716870165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9G9wAoyvooIHjRdJA2jPZy8BecY0++h8s+r9jdvUDeU=; b=g4U44pa7LwZ/sXNdlpfrX+IlxGtOVJW9TIZWvGMEbFzUs4gho5vuV24w lZDDCTIubeJBa7k1nF2zsj+2j5Y1Cjts8WsW2ArCY2M7Y/o6h/xk1PhHz eo3qi79R0ZoU7N9zIrj0ooEmfYQ7dT2ttp+sdDuBXQPUde4jz7UooBTRB 4h4ArHm2xcLe8WTbEYh8zP+Y6OwTRP9qwx06pPy9pkmeEtHTht4Kn7QMy ZNYeDVGmO/C2SMlUn2sgf+iEV/2VG3W2q8eQrX419BWFCgxPQ1T9P1Liq uQPGxBPM5UD6m22LDobMxtUwrcD1jJbHCy9GrkXrmoboeOfd3x7Fjb6D+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334965959" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334965959" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784278" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784278" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:13 -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 Subject: [PATCH v14 041/113] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role Date: Sun, 28 May 2023 21:19:23 -0700 Message-Id: <1add64fe7c9c370272f9689367bbbc3334dda14c.1685333727.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.6 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,T_SCC_BODY_TEXT_LINE 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 5f3cace6a85f..e8484ec90c61 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -338,7 +338,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 @@ -350,6 +355,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 ab480e40055b..45912ab65075 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