Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp174266rdb; Sun, 28 Jan 2024 20:17:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwrDcsySm+FDvbvo7+HcFMLUTEyLYr9Xj95gGzCCKWh2asMyXllsXUS7a4m2jQrc0mibVk X-Received: by 2002:a25:ae5c:0:b0:dc6:7efb:491d with SMTP id g28-20020a25ae5c000000b00dc67efb491dmr730187ybe.110.1706501837723; Sun, 28 Jan 2024 20:17:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706501837; cv=pass; d=google.com; s=arc-20160816; b=RKz9XSwnBUSPf/F9wFJ1roLqQzaWXemvPp08mUTIn5urKNkXmF6rHlVPW4jO9dqZ1E IFJDurdUReZuL+OTjZJ5PPEem9UaPJgv9AQ5c4ubrGxg4o02+XacWaUfZ23TJrKPXTKm htZ33biINQz874MamPt3whjqcExRoQdRxbELvgGkG3eh85bLh5cJKTsOgtohSs/hW9SI 5nkli+VKHksQqHxFtHVNl60maHXXFXzNNrlUpEvxLE2UOJId3uYvuWjw1SrDPKkeeHpu YJ7TX6hM4TlnRjM4vsPf8pdS+OLUScFk4UsEQ1MiCi90JTuL+0+h/wEQZ7SKY4TDBSBy dgGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=hwv8XN1V9LsxnLQimGFvvqdEl9MG8Olu9lSl9gmnWQg=; fh=8scsGQn+hJ1HvbMI23kGOdGh/wtWpH4wdCi8Q1zCFc4=; b=d7DfPB1M+zLJnnisxfjZfF92w1sqRSK0h4RBOAlmSwI6w4vGHXSieajIzw+ZsgPGts TfVu7xjBlrWeYr0a+Galw4oPR/+NrJDq22cPsFIv86+31D9n3wB+F/8wrFk9vGNu6+zl WY1uKzzQVqvrTGdK88B9lCngtpgQnK+y5iEM3vIYMkhbTqdnsWmmw+0bra6W2tJOG+9D Vue3xnJhoUSFyUWVh+MP9fwRmBCwGUDHlZwKDXPFr3PuBU5+qotSiK9SmiJmrIdt5RHJ JTNBupO/gKqFHz2Xd8bfr+GG27j9fFWQxbmYSSGsqikCyIaxaFneqiqwDblYGHxrdwfy Ws/Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S0qHdZIl; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-42073-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42073-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a9-20020a63e409000000b005d8bb0cd28fsi2942433pgi.69.2024.01.28.20.17.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 20:17:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42073-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S0qHdZIl; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-42073-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42073-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7F21A282B01 for ; Mon, 29 Jan 2024 01:50:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06341DF69; Mon, 29 Jan 2024 01:50:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="S0qHdZIl" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 069FADDC1; Mon, 29 Jan 2024 01:50:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706493031; cv=none; b=WQ1U8N5GngDQTgxdqcA8Fkv+DuqdlVVgbilCerq6WPqF5pATzHem5TSSYgjstnvaf7UbO/5eaJLzCib2lqSvqcCbKVjjtSKw6JzZ+RM4yrXeUN5R7pGnk518dJb6AV2BXxUvkSdF4ku+lnAcs2WY/bftxi9Ye9RLyllIYlAxS/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706493031; c=relaxed/simple; bh=SalaM6JGrf0LlUVTIAvgjUI/PUUumRog1VzeLyjKhQo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BMTOz3Vrb3WUD9J4HvJ32n/34bhXokqe8PlcpEMTQeO0FCMwkyna9YSpqc14qOAoVwtH7N2Jjo/ZqIEbo8seD2hphV2SouurPJqc963YL7keVzjOQ9hARxFMlHvU+H8Wv6ksEr1yQkVIstHZsnawW7iWg5uxRR/xQ8eBYbWghkQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=S0qHdZIl; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706493029; x=1738029029; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=SalaM6JGrf0LlUVTIAvgjUI/PUUumRog1VzeLyjKhQo=; b=S0qHdZIlBV74gow6C96e8x+TMlVUkVHkk+Y8too+PIGIsorVO5HhnYI/ hrhIbuBJKvCj+wu0LyPBsVLAFQwT1wuSpX96+aVcr+6gaHybuWvcp4qxR WCik+uk8CdIvzhxRoIlI2ZDQCFLNle4KuubgSnIy/S1hGGui5qDUGv9EM 2uGBykNfVHnr09OQxd0VRkdxZ0hhIsZDwwcI+DywD2U4DgdkmexdpgYti oI3LVxEyIowUyle8DD2IenTcC+rDm5uKApw2hTGd5cuqLmKRs36LxUmDi qKgPTHDT9Yn65E8EwmLsKpqcrUAvfX0YflVM/XmMiSKk/E5qCzQI9P/hT A==; X-IronPort-AV: E=McAfee;i="6600,9927,10967"; a="10214620" X-IronPort-AV: E=Sophos;i="6.05,226,1701158400"; d="scan'208";a="10214620" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 17:50:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,226,1701158400"; d="scan'208";a="3259814" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.93.8.92]) ([10.93.8.92]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 17:50:15 -0800 Message-ID: <3833f6df-337f-442a-b37c-070a92bbd30f@linux.intel.com> Date: Mon, 29 Jan 2024 09:50:13 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 046/121] KVM: x86/mmu: Add a new is_private member for union kvm_mmu_page_role To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, 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 References: <33812f5282bc42e0e8e6eaaa2a6a63ce4d258bfc.1705965635.git.isaku.yamahata@intel.com> From: Binbin Wu In-Reply-To: <33812f5282bc42e0e8e6eaaa2a6a63ce4d258bfc.1705965635.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/23/2024 7:53 AM, isaku.yamahata@intel.com wrote: > 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); If sptep is NULL, should return here, otherwise, the following code will de-reference a illegal pointer. > + 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 &&