From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 1CC4B2C0F6D; Sat, 10 Oct 2026 06:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.8 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791612072; cv=fail; b=mFMBTFMAcptGKGT/tTYgGRLnP2litsdP64JWRDMATaxux9VgdEI+p5TnTrVjaI+2esOUeSpVb/31vWsNWeSJo0jq2DaYZymde4KkzNu43ntm+uHI4BMah1mAOTokuFskAhI1f411UsaRZgXD/bxKmuhsew0ZMknr3msfKNYosRY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791612072; c=relaxed/simple; bh=dUf9qr2fxKtAIWP75zYxoV/MBsCR4bVeuenygeyfRPo=; h=Date:From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=LvQyD9X52T3NP/Defwa0YzjVS0h9kTsA9cGAW0KMGXl1yj9R2ZblOLrNhawfuguWXZgBzp/r7Ih6VTZLrFp8w1IFLzon589HyHpCCupqNecc7CjmHWi84+b6dbi1EsTndscHIBUjy4qvizcrjk8wsaq6M8y45SHsSjEqFq3zB0Q= ARC-Authentication-Results:i=2; 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=U87UplwN; arc=fail smtp.client-ip=192.198.163.8 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="U87UplwN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791612070; x=1823148070; h=date:from:to:cc:subject:message-id:reply-to:references: in-reply-to:mime-version; bh=dUf9qr2fxKtAIWP75zYxoV/MBsCR4bVeuenygeyfRPo=; b=U87UplwNd/mHlSRn/mIFUsP0LUC0bxUgTZBL8F6HAFHGQHHsYz9vQhes 6+BJ5a/HMVTwWoPlXt66yg5GiFs4zPIKE8jHlqttx9oLqgImbKWKe6bum /X54dxj8BC5QFwKulmKp6f/pl/q3a9X3DOF2uX4hQ6Rf4f69okKDiRXgb tjKLFCSEPmXPs1Hi03XSMYGdse0Zd4/F0GLlCphsEFFlhkp9k9GL2ygw7 JX646dey9Z12Q/DWy3Z6aNgB3wvGrnFwhBvgc0HEtaQ3zV8IDTL3mu7Pc jlInWYl5mZ60LeKHZggyJPOnQB1cvzuXpCaNcsUYKbZuiIgbhL3oJ736t A==; X-CSE-ConnectionGUID: 9lEypRHDQFm/12xG1rLBqA== X-CSE-MsgGUID: +UvMDLVmTq6st+3330mjjQ== X-IronPort-AV: E=McAfee;i="6800,10657,11930"; a="300226" X-IronPort-AV: E=Sophos;i="6.27,149,1787036400"; d="scan'208";a="300226" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2026 23:01:09 -0700 X-CSE-ConnectionGUID: zhVmDA3qQlSsc9t9kj2KkQ== X-CSE-MsgGUID: wPjK0v6RRiOWpENhfWQbjw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,149,1787036400"; d="scan'208";a="481244" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by orviesa004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2026 23:01:09 -0700 Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Fri, 9 Oct 2026 23:01:08 -0700 Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49 via Frontend Transport; Fri, 9 Oct 2026 23:01:08 -0700 Received: from CY7PR03CU001.outbound.protection.outlook.com (40.93.198.16) by edgegateway.intel.com (134.134.137.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Fri, 9 Oct 2026 23:01:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YNwsjLfkRH4VYDcbjwy+cRbGfUi96yGB+IduFx/cxmgXeKpi9pN5xRLqV+i6abnZLngP3YT+Y0UwiWo4iTCMj2WX7ZebEr0WgvpGmMCKMRZKewNbyVZVWCfhjtSWcK2uOqLG9mwMHZLSKbgcOOMnsITRazbIvlhYxr3QiwrrpOwTEwAdxGFtbscgkq6NuwHMgOb1JAbnu1I3ldp39Mqh0t/UGF90lPL3UeRl4+WWBnKJjdPgNInOxV9xcsXaKjVUL6007A7d0Nehf87BORYME0qVWmlc0rFjDL0LmDKSMsGmfSIEiJFtbS6YZ1+EPr12SO5mOowbLZDaVIwSxioVOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wsjBJbTNwNPt5pcqoJJ0pndH0zp2WCkKiMVc3NqPfCQ=; b=FYB7TcwoAdUd5LX+OlhNv/OGYqPfEGY61i0ix4TUwAiUPVIOCbIF2A8ZoenCPa3OKao+Oevh99pDmRNfbhpas5ZCIj9nuDXrw0T9pQQu8Ho5d9+60H8Qs9KR24FdqjpdW8hyMfAgVZE6fDNdaxf5A50U+jsdnui2Bh2BFW1hobO40WcnFebLmjSEDlcb5FNxuNrWnyTR6AHe+x++fap+RyaKHCQQaJaaWBV1NzduFdLYgGZNEn81gFgNvXNnUgV4U2pVGUVGqW8rFU/7iCp/CS0JhoHCTf14Z6hwgwlFHDykUMGIz9+Cu4Dji2fY3hEC5ag7uBr94qpBH9jMUl6+mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM6PR11MB3243.namprd11.prod.outlook.com (2603:10b6:5:e::19) by DS6PR11MB203949.namprd11.prod.outlook.com (2603:10b6:8:49a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.18; Sat, 10 Oct 2026 06:01:01 +0000 Received: from DM6PR11MB3243.namprd11.prod.outlook.com ([fe80::6c83:d3c:7952:3ee1]) by DM6PR11MB3243.namprd11.prod.outlook.com ([fe80::6c83:d3c:7952:3ee1%4]) with mapi id 15.21.0496.015; Sat, 10 Oct 2026 06:01:01 +0000 Date: Sat, 10 Oct 2026 14:00:10 +0800 From: Yan Zhao To: "Edgecombe, Rick P" CC: "pbonzini@redhat.com" , "Hansen, Dave" , "seanjc@google.com" , "kvm@vger.kernel.org" , "Du, Fan" , "Li, Xiaoyao" , "Huang, Kai" , "thomas.lendacky@amd.com" , "tabba@google.com" , "vbabka@suse.cz" , "david@kernel.org" , "kas@kernel.org" , "michael.roth@amd.com" , "binbin.wu@linux.intel.com" , "linux-kernel@vger.kernel.org" , "Peng, Chao P" , "ackerleytng@google.com" , "nik.borisov@suse.com" , "francescolavra.fl@gmail.com" , "sagis@google.com" , "Annapurve, Vishal" , "Chen, Farrah" , "Gao, Chao" , "Miao, Jun" , "jgross@suse.com" , "pgonda@google.com" , "x86@kernel.org" Subject: Re: [PATCH v4 09/17] KVM: x86/mmu: Introduce hugepage_set_guest_inhibit() Message-ID: Reply-To: Yan Zhao References: <20260928090729.15468-1-yan.y.zhao@intel.com> <20260928091049.15615-1-yan.y.zhao@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: SI2PR01CA0032.apcprd01.prod.exchangelabs.com (2603:1096:4:192::18) To DM6PR11MB3243.namprd11.prod.outlook.com (2603:10b6:5:e::19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR11MB3243:EE_|DS6PR11MB203949:EE_ X-MS-Office365-Filtering-Correlation-Id: 07a52e24-ab61-4cbc-02c8-08df2693dc60 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|23010399003|6133799003|10067099003|22082099003|18002099003|261009223027099003|11063799006|5023799004|4143699003|56012099006; X-Microsoft-Antispam-Message-Info: +xdDGOffALrKSCpS2EIwiaLO1mRnI0ii1NPeSIbxcSISDOQbUmV+gyZDFqfCtgU+Jg9+IBTk9psqbooe7Ckzc/uB4HsPA/iZWLRZwK9ZdCYiBMeHvX2YT+fZw2xiURuegqD5d6t2+v84KAexigUB0lJ71Cn5sFiyYwlCqrZ3pqtY4KQrjtQV1rP7S6e6vswzGBmD466p7WzDlwzp37Hq+YX7fBa4dbZXeIfLf+fylnlA6ptAgL04oYuCdJCPRbZr3tZ21vnqaA1QkJQJ4rmiQNud2AgGQp4LN3xkxyTj0P/OzUr15ndVE9RopynEwM6gpsKrnKLakd6s222UFEm3Zy+iTvsp5r1YyorqsdybZRubzbrk2E0/+2oWFMHqMaEX1tiRYzbMW4W37zTjDGEprkFrO3WRMMEQDoxIncWFjRfLyPuwYdJ8d4JaKK9SLQZOQ2w2NRKkJEMTKHElrJ9xILkzuLp9S8L/4l9VovFnbSuGZfr2iWCkX2q10OPb6+Mc2PxGtP5f5SBGiulexBu1ZncaAByAfDM7Y+LUq/2ZJJkMNY5hdh218AEMAGGaYjl0idu85MMKmlzsYFpbVvzyEudzb7Q554xvl5PpxGVcuBDFBqxCqNgSJGLg8sCc44uOa3451b38mKkHUBMxpKiv4lgmQKHxkNiLvR/iGMLRNFc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB3243.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(23010399003)(6133799003)(10067099003)(22082099003)(18002099003)(261009223027099003)(11063799006)(5023799004)(4143699003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?3p8PljDHE3CnIBEOltxSEZVVVddk3HWodNfvtns2wD/WRLZTpFDJ1xeUyo2r?= =?us-ascii?Q?cIpKRPjmk+60YJ5ktFDY6U7myLpCRCz0j2gpaS3WsUqXcTRihfaK06xx3D1i?= =?us-ascii?Q?vSkTNikGEif8m15g+q96BoKL9TEZS4ZAFEYTA3enkzirY6OrFwcsqxf5aLMN?= =?us-ascii?Q?rc5Siqnr+0Avm4JP5Kn2Ta9/+K8NhX7GXGg7GyioYWPapSmAuGKftXZ3qdB0?= =?us-ascii?Q?7eLYVj3Zy759LtbjO37kFKKkw9l8Bwdp0SGKj08NXLRLxmvmukMCV26Qhyz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dlIyKHlX3XlYQu8Q== X-MS-Exchange-CrossTenant-Network-Message-Id: 07a52e24-ab61-4cbc-02c8-08df2693dc60 X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB3243.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2026 06:01:01.1497 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MmI/LqPsl5lkW8J4X4C+cgAXPORTkEHS/fJaFSe4z3YZ5fopDUfB4amsxHZD3/IlhsC5aCOECMLsGcCa8wzY6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS6PR11MB203949 X-OriginatorOrg: intel.com On Thu, Oct 08, 2026 at 07:57:37AM +0800, Edgecombe, Rick P wrote: > On Mon, 2026-09-28 at 17:10 +0800, Yan Zhao wrote: > > TDX requires guests to accept S-EPT mappings created by the host KVM. Due > > to the current implementation of the TDX module, if a guest accepts a GFN > > at a lower level after KVM maps it at a higher level, the TDX module will > > emulate an EPT violation VMExit to KVM instead of returning a size mismatch > > error to the guest. If KVM fails to perform page splitting in the VMExit > > handler, the guest's accept operation will be triggered again upon > > re-entering the guest, causing a repeated EPT violation VMExit. > > > > To facilitate passing the guest's accept level information to the KVM MMU > > core and to prevent the repeated mapping of a GFN at different levels due > > to different accept levels specified by different vCPUs, introduce the > > interface hugepage_set_guest_inhibit(). This interface specifies across > > vCPUs that mapping at a certain level is inhibited from the guest. > > > > Intentionally don't provide an API to clear KVM_LPAGE_GUEST_INHIBIT_FLAG > > for the time being, as detecting that it's ok to (re)install a huge page is > > tricky (and costly if KVM wants to be 100% accurate), and KVM doesn't > > currently support huge page promotion (only direct installation of > > huge pages) for S-EPT. > > > > As a result, the only scenario where clearing the flag would likely allow > > KVM to install a huge page is when an entire 2MB / 1GB range is converted > > to shared or private. But if the guest is accepting at 4KB granularity, > > odds are good the guest is using the memory for something "special" and > > will never convert the entire range to shared (and/or back to private). > > Punt that optimization to the future, if it's ever needed. > > > > Unlike hugepage_set/test_mixed(), which are placed under > > CONFIG_KVM_VM_MEMORY_ATTRIBUTES since they are unneeded when per-VM memory > > attributes is disabled, hugepage_set/test_guest_inhibit() are invoked when > > per-gmem memory attributes is enabled, since TDX huge page support is > > intentionally enabled only when per-gmem memory attributes is enabled. > > Not sure why we need the above paragraph. Especially the gmem part. It looks > like it was added since v5. Was it an AI review item? The internal Sashiko review suggested explaining why hugepage_set/test_guest_inhibit() are not placed next to hugepage_set/test_mixed(), given their similar naming, which seems reasonable to me. > With that addressed: So what about: " Place hugepage_set/test_guest_inhibit() near kvm_mmu_gfn_(dis)allow_lpage(), rather than next to hugepage_set/test_mixed(), so that they can be invoked outside of CONFIG_KVM_VM_MEMORY_ATTRIBUTES. " > Reviewed-by: Rick Edgecombe Thanks!