From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF24419995E for ; Tue, 1 Jul 2025 22:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407278; cv=none; b=lJARmZRc1g8tHHzyrOFPW1Loeux0ijWm/Jby5DsX3jpJwad7VAuPrg0Jy0TPZBk8xFkpJZrpz8Mdqyw/hTB4kmKjZZIGDnLaDp9u4CfehTs+70eD5sSnPcXDF+4IVJvMaXl4HXhdmWmDYi++XHC5O0HK9/m9OBVIMdIaUdj3uu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751407278; c=relaxed/simple; bh=ym4G6ufKkIWzagLIfI+OhFmb/6iNAI1xtHVDilZhmaw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z0q1OCJf5KLWbowutC1mZEHjySxcOrgl/4x8JOuj4J5Rt/xznvp4Mpd7+9RgtNuoCMNUHRf+uh8klYbZKU/6U8sk8HpKcqVbDIPtaet2pXik2pCeQu+WXDnkG6FGW5yO6sxbj3zNAtlA3xf+Gu+aJGzFZh+gJPOPTIFj/uvQfLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZHz+0HE4; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZHz+0HE4" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74943a7cd9aso5803575b3a.3 for ; Tue, 01 Jul 2025 15:01:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751407276; x=1752012076; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sZpSfMGCY39joD2VC5bXg87sm6OUeYjHe/LMyzT4YGA=; b=ZHz+0HE42hZqtmU9rg2tJEY2N2iuOH72Kq0J9aUOgxRXbBufm+KN9q65AMUkjhpkNF s4lRyv4/diVr61Waahi8gmZ5eYItKwm85Xdm+M3CvrS8dQZqlwepjKxy6i1fMphJlkJ8 bOxuDFc9jP6WSNNgVdqDM5nImMcebBKXs8MsIP1LZQrSfbHGWZH2CVLLPeiucXrSTmRF Dr8RZEnbZz2B3RdaF7mtJxGN7L0J8hYkfgTG3R5RP3C3yZQ2Tn1UspkVVw7WTq6Zjhm4 m3fiASrRpGGAIGCqf28TZ1BaxD5eHUO9v0uismIfsbr8frJr+8iPn2cbErThb2p49n5E 7UwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751407276; x=1752012076; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sZpSfMGCY39joD2VC5bXg87sm6OUeYjHe/LMyzT4YGA=; b=qkjLQsXlOFH+FWp6FoWIJMPtX3rBz5fb3eCT5B2Qb7BPNPDWvCvAVjcfbWHCM1y791 ff+YlwUDLv/Bat8g0/VG72AGKIbmqYxHdYczwTnP+uPnoiN12ibtoWspn0eUWNGvWBx0 4Z28wwi0YYgS6qcVLIZnSIy6/ahEGZTa7ua5InouGqCbxW/oGXeiwR6ad0odvgQGX6xR JpGpR6sUWzyIhD8mKCyKTKwx14Ndi87ifCyagPgnWKJdBfsbA9O8UuWjfeiYFfdDaAn6 bn/SmmOqsbMQRruhgu5rigPuH8mMKtdVBdxym9zO08Xvy/+WE74Ej4ZT+JKfpVrF593y 00nw== X-Forwarded-Encrypted: i=1; AJvYcCWT2DZmGvCM8vDJckNnjAosD4p4UW1MvZuV1LPFL+jADF46xfbOvCeFDNFyazhuHD0pxTDSiAxMoNVn02c=@vger.kernel.org X-Gm-Message-State: AOJu0YzRvdDNJZASwjQW+MIpIh7u68mv46mhe+aONHVfDnj0vw1F4PKQ PRqDGOhMu2WVno7EbJ+GoobwQODNUWiQubSGiJIbjSWdyp2G/uay5E7b/+Kope8lJS3FhwgrRbk ZTMEmqV0h9fhJwi5ikS+gHeHdHg== X-Google-Smtp-Source: AGHT+IEd9keGJPvtO1uRbJlDNElYmO2f0J3qSttebwAES17DT1AOdOkvIO1LIuYSPiK3tQDScGLMbN+3Qhbuix38Cw== X-Received: from pfbbk11.prod.google.com ([2002:aa7:830b:0:b0:748:f98a:d97b]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:618f:b0:216:1ea0:a51a with SMTP id adf61e73a8af0-222d7f25634mr1088275637.38.1751407276143; Tue, 01 Jul 2025 15:01:16 -0700 (PDT) Date: Tue, 01 Jul 2025 15:01:14 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <447bae3b7f5f2439b0cb4eb77976d9be843f689b.camel@intel.com> <4cbdfd3128a6dcc67df41b47336a4479a07bf1bd.camel@intel.com> Message-ID: Subject: Re: [RFC PATCH 08/21] KVM: TDX: Increase/decrease folio ref for huge pages From: Ackerley Tng To: Yan Zhao Cc: "Edgecombe, Rick P" , "Shutemov, Kirill" , "Li, Xiaoyao" , "kvm@vger.kernel.org" , "Hansen, Dave" , "david@redhat.com" , "thomas.lendacky@amd.com" , "tabba@google.com" , "vbabka@suse.cz" , "quic_eberman@quicinc.com" , "michael.roth@amd.com" , "linux-kernel@vger.kernel.org" , "seanjc@google.com" , "Peng, Chao P" , "Du, Fan" , "Yamahata, Isaku" , "pbonzini@redhat.com" , "binbin.wu@linux.intel.com" , "Weiny, Ira" , "Li, Zhiquan1" , "Annapurve, Vishal" , "jroedel@suse.de" , "Miao, Jun" , "pgonda@google.com" , "x86@kernel.org" Content-Type: text/plain; charset="UTF-8" Yan Zhao writes: > On Mon, Jun 30, 2025 at 12:25:49PM -0700, Ackerley Tng wrote: >> "Edgecombe, Rick P" writes: >> >> > On Mon, 2025-06-30 at 19:13 +0800, Yan Zhao wrote: >> >> > > ok! Lets go f/g. Unless Yan objects. >> >> I'm ok with f/g. But I have two implementation specific questions: >> >> >> >> 1. How to set the HWPoison bit in TDX? >> >> I was thinking to set the HWpoison flag based on page type. If regular >> 4K page, set the flag. If THP page (not (yet) supported by guest_memfd), >> set the has_hwpoison flag, and if HugeTLB page, call >> folio_set_hugetlb_hwpoison(). > Could you elaborate on how to call folio_set_hugetlb_hwpoison()? > Sorry I meant "in TDX" as in the part of the kernel that performs the unmap. I'm assuming something like int ret = tdx_do_unmap(page) if (ret) set_hwpoison_based_on_folio_type(page_folio(page)) And set_hwpoison_based_on_folio_type() would have to be written to know how to set the HWpoison flag based on type of the folio. I think I might have used the wrong terminology elsewhere. Sorry about that. I don't mean to call folio_set_hugetlb_hwpoison() from within the TDX module. I meant to set HWpoison in the kernel, based on return value to the kernel from the TDX module. >> But if we go with Rick's suggestion below, then we don't have to figure >> this out. >> >> >> 2. Should we set this bit for non-guest-memfd pages (e.g. for S-EPT pages) ? >> > >> > Argh, I guess we can keep the existing ref count based approach for the other >> > types of TDX owned pages? >> > >> >> Wait TDX can only use guest_memfd pages, right? Even if TDX can use >> non-guest_memfd pages, why not also set HWpoison for non-guest_memfd >> pages? > As in https://lore.kernel.org/all/aGJxU95VvQvQ3bj6@yzhao56-desk.sh.intel.com/, > I don't find a proper interface for TDX to set HWpoison bit on non-guset_memfd > pages. > > Neither memory_failure() nor memory_failure_queue() seem fit.