From patchwork Mon Feb 26 08:25:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1940956dyb; Mon, 26 Feb 2024 00:38:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYmTKi/8tUgM6qcuJ5kB+FQA7nopl4CJ6ijikdfAZLND7CHOGtVSjdtkuoFn3mAgoWkGo37v+I/2SCp1WqMO7XjIIScQ== X-Google-Smtp-Source: AGHT+IFOeuDsfdzXCe15BBwG6JLsE7+tXWVOzhVTyma0AuLB4Q8ueKbYfCnUEXMqLAtlSX0cugWV X-Received: by 2002:a05:6830:310e:b0:6e4:89da:29b6 with SMTP id b14-20020a056830310e00b006e489da29b6mr8061090ots.21.1708936738131; Mon, 26 Feb 2024 00:38:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708936738; cv=pass; d=google.com; s=arc-20160816; b=OvLrDwdhbdV0Rv6JabcfC6gyI+UlX82904IdgU/n4tzB8WWHuW5/a++wuvyOH0yQxY bPTC31KROhM7rLWeGAqAVtPF2S734QyehBuNAlW63raXqT51QVWzuhbf0Z/wUgGKVRBD JwxzHY5QmYMcyAA9l3OLcPPYaAVE+UQw2ixv9Zn2xQcYtIMOqQECJk+9WjQrrtpj0R8Y n+c+753tPMm/oN6uYGA0+z0+/29DSWwH+heYJysyRNo5RAwjum7nyiQP3XPv0FbiYLBR ieMoW+t/7Q9pBGzTu1oH9H1kH0bw/BC97QQ/oq8mXidI4Hr8ZRqynEgMKkoo69D5w+9n a1mg== 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=R4wvlLPZa5XKdkGbXF4b9FWclkUFgwi20c7GME28QHk=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=Sz58ZikAoe4jwaYhSDYMC4ZG9XFWE5t6RXwN/0HVxK9ycx9iDVi02Q9o4bezPjyuuj Jq4Swh3TDh4RQ2DwJ4Q4k51LRCA9P7A/D9yIg1IHO2el/gWTeRMgwtxr4t/Qo7SWSxB9 yx+7dBJsjnh+lRtNqS2DuEPk3qdnrAD03cwtzHWRlHDRmyWIibKgWetXb5E4VYFbJu1s 03RKAjqpTfOogoVRRc7TsnzD1DXuEjkTOt9LNQ2A7FYYDjNjMmBU/p2l9umXtUure3Wc Emy4cMpbZhV4N+ldj7r3l67jneOoIThc15HzLc+Aj89ZWIIxI+qkGihM5RxweFEqPMXG ntHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V2gLD7oE; 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-80771-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80771-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id by13-20020a056a02058d00b005ce016cce2bsi3418299pgb.190.2024.02.26.00.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:38:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80771-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V2gLD7oE; 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-80771-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80771-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5A8E4B249F2 for ; Mon, 26 Feb 2024 08:32:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4DDA524C3; Mon, 26 Feb 2024 08:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V2gLD7oE" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 6971B38397; Mon, 26 Feb 2024 08:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936064; cv=none; b=pF5J3HEbuQPP9h7Z1CVwgogwrkdjufFplX5oDUtJPirTYnki3/iwu8F5X+Ug9mq2drsFoEL0HH3VlDwNUmLUWwF85/PsqD7Tv2KgyVmN3KJc9SEbu8qw/SPyHrrqKPztaU57QosBZpU+QVfHJno96ZpTfs69J85lTehxhJQp+Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936064; c=relaxed/simple; bh=Fyink57/ejQGrZ8tQRVicXDKz0HYEbCM9W9KphhTHVI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r+DAekreflbmQuWO8yoyLk1OGY6bXHq6LZU+FLepVVTXet2AuGjK7AzJFkiXUJw/dq2pbukz43+6HHRPHFynT24qUNoIYMOJsZmT+nXLuyxa26e9MqNYwEnBrV16UhHkjkMr07KNsVjS3oA0nycPVouZLLKEZ6ZtiuHfWmZu7lI= 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=V2gLD7oE; arc=none smtp.client-ip=192.198.163.7 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=1708936062; x=1740472062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fyink57/ejQGrZ8tQRVicXDKz0HYEbCM9W9KphhTHVI=; b=V2gLD7oE5oysIguiRSLUZOD6qMydjEB0hYWDSop+WMEMQdy66UUyj3Og Ddvy+dJpwOQfb1TPxHWE9G+HL+SJPqsvlvD5eFYnvJnNCFIPtALV663wF 6+pgklIv5Cbu6/TEo1e6OLGIT2rGzyr5yu6OZYwE/cU5V5Pwkjre8tpoC u1BmttzhJkmVGgP7524WF1N0LN4n2qtaZdDX39VLgZfd0OwKzZKnxI3zP crLkVGhKhHysOYXYjriP37u8j8KW6aAzy/GsVMXkVb0GTAL3YnZLZmwhu TSl7E/CYjvN8lrYWjVT8QGKOwrzZYH+J4U4IM8c+DTzxoxKBCDF9OOQay Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="28631466" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="28631466" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6474321" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:40 -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 010/130] KVM: x86: Pass is_private to gmem hook of gmem_max_level Date: Mon, 26 Feb 2024 00:25:12 -0800 Message-Id: <8108cc2b8ff01ec22de68f0d0758ef0671db43fc.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791950049294045136 X-GMAIL-MSGID: 1791950049294045136 From: Isaku Yamahata TDX wants to know the faulting address is shared or private so that the max level is limited by Secure-EPT or not. Because fault->gfn doesn't include shared bit, gfn doesn't tell if the faulting address is shared or not. Pass is_private for TDX case. TDX logic will be if (!is_private) return 0; else return PG_LEVEL_4K. Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/mmu/mmu.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d15f5b4b1656..57ce89fc2740 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1797,7 +1797,8 @@ struct kvm_x86_ops { gva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags); - int (*gmem_max_level)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, u8 *max_level); + int (*gmem_max_level)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, + bool is_private, u8 *max_level); }; struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 1e5e12d2707d..22db1a9f528a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4324,7 +4324,8 @@ static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, max_level = kvm_max_level_for_order(max_order); r = static_call(kvm_x86_gmem_max_level)(vcpu->kvm, fault->pfn, - fault->gfn, &max_level); + fault->gfn, fault->is_private, + &max_level); if (r) { kvm_release_pfn_clean(fault->pfn); return r;