From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20DE7CF884C for ; Fri, 4 Oct 2024 15:46:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FB7A6B0102; Fri, 4 Oct 2024 11:46:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 985446B0106; Fri, 4 Oct 2024 11:46:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D6B16B0104; Fri, 4 Oct 2024 11:46:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 55AB46B0101 for ; Fri, 4 Oct 2024 11:46:19 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 13545A195D for ; Fri, 4 Oct 2024 15:46:19 +0000 (UTC) X-FDA: 82636346478.26.3E4A521 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 2B6F2100007 for ; Fri, 4 Oct 2024 15:46:16 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=h0+62sg6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728056754; a=rsa-sha256; cv=none; b=YhPnKiTgPF58tOFODnBYEfTpErYStSORMdwKgfCPgJ7Xs1Ey77bbvF5w4sagDBZdlvCNAT XpCa0saaq1kbxCx/9tWIdk/ssR+vriiC+DW7bDDCampBr3iwX6EULKqENMCStsSMuyLo01 NCnCaZkfcuIJ+EORyuJKxmX5OedLK1E= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=h0+62sg6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728056754; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cNNH+yI6KP3MLhT3Lv0mWixF93SS3ILelEwRHgMmM3w=; b=T6TUgQDz6pIow/oKmqV0LsAPUlWjuKW8G94/estvaCOxD2T163SxHrAElJsIcq45+4/M0U d5bdoabUKosCeFNtnueGhpA4mIsNtDg8JKappMemf9pRCrU6lISj3qUKAeU/wK5mq1HtQn 4ApjUWiVQDG3CZY1apYTZfNB+wcS1S0= Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5c88e45f467so3768695a12.1 for ; Fri, 04 Oct 2024 08:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728056776; x=1728661576; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cNNH+yI6KP3MLhT3Lv0mWixF93SS3ILelEwRHgMmM3w=; b=h0+62sg61G0b55kA4Bd54HyAkO962/Mo4VXx4bmvAL7T89EO4s33KU8GBaCeyH4AfD vnbx3Kh1VXSmgzgP9PqZMA2mlgUNgt4Pypl4iuLb0PsFukh9jHKe/QBLN63huTwsXJ3x xdLlnptdHczG8JsgD8qk2Z2P6kkRjYRPmzvS4nhsxaQccApMdvWX00cpxea3L7YfbPNa 6Y2qjpFSeoTh7U093yPdoHeQbGbkDUyoLKY7mVCmrHuXkSA2nWQhXWuXY5P+p+cEVl7e 0YiB0NRoHZDoLqV5TboyAXals33ihEtOIfdLLdC/Uh5qVMs0BOKaIZ2UykFHfqYgDpZM E1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728056776; x=1728661576; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cNNH+yI6KP3MLhT3Lv0mWixF93SS3ILelEwRHgMmM3w=; b=teWqgO1oX3gOmliTulFNbqMMvXrxxSSiauhLbAGs+ZKP9ZO0YaIC8e8gV428TCVWpk i1GdwgcybJaFcpLOC9JcJ2gVe9DkT304PWYbaaeU7VStoYS68C/KMRk/KsrqAB1iK/iH /mYAQZfQLQ8rNWuK+smcVnaJIUsNSSFCEPAKm7VjnH2bFfftL5bjk+TbVIrzQn1s9KwV Tl9dbWvkMoTlHx2ZVmWglSNkD+poGA8QO64LFCtrwpt/JBqiaiuHBKJCfDqLnKvowUrO dlBE2YHvre09BWiAxeCAbE9OcWbiEZPSl44tdsMMeXOE2jl/PWsh6d/cXwR3IWha3zmc rN8A== X-Forwarded-Encrypted: i=1; AJvYcCWFKE8Y3GivCei2f2JgDMhSDzTnHPVs7H9b/9NM4X3Asyn5cWdfy9RApAT+VhyFnHFJnpj3H7ke/g==@kvack.org X-Gm-Message-State: AOJu0YzJJzjydWvn5olZDJVTOvNwRTW2x+jhwQ/jjuWhJsQkbHmhY9k4 j3RiJ4FtE3TzX0HCaug1Um2lKu9YZaKzpCaSogpcz++nyOshhx+pjQBz6Arr5uH/+KBZOwMigaA HpyxLhhcFfAo7R2mjXDSWM8p9yeM= X-Google-Smtp-Source: AGHT+IElPuynvwCObKiBOuwsWFdMz9YTT/Oc+/+5k2c7nutYZ1ME/tf4FG80rW5FbnRUy2Gf1Tc2aFySux4xMBJtsm0= X-Received: by 2002:a05:6402:510d:b0:5c8:81a6:f14c with SMTP id 4fb4d7f45d1cf-5c8d2f3b9f3mr3741500a12.9.1728056775346; Fri, 04 Oct 2024 08:46:15 -0700 (PDT) MIME-Version: 1.0 References: <20240930055112.344206-1-ying.huang@intel.com> <8734lgpuoi.fsf@yhuang6-desk2.ccr.corp.intel.com> <66ff297119b92_964f2294c6@dwillia2-xfh.jf.intel.com.notmuch> <66ff5dd3b9128_964fe294ca@dwillia2-xfh.jf.intel.com.notmuch> In-Reply-To: <66ff5dd3b9128_964fe294ca@dwillia2-xfh.jf.intel.com.notmuch> From: Yang Shi Date: Fri, 4 Oct 2024 08:46:03 -0700 Message-ID: Subject: Re: [PATCH] tdx, memory hotplug: Check whole hot-adding memory range for TDX To: Dan Williams Cc: "Huang, Ying" , David Hildenbrand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "Kirill A . Shutemov" , x86@kernel.org, Andrew Morton , Oscar Salvador , linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kai Huang , "H. Peter Anvin" , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: 38zd96t9f7u56tbnxxsmqur5zq7t47mg X-Rspamd-Queue-Id: 2B6F2100007 X-Rspamd-Server: rspam02 X-HE-Tag: 1728056776-718357 X-HE-Meta: U2FsdGVkX1+cHmk8ORHXud40cFDS8zHJcYCL8GhVn8zZBp2DAvvMhWHtb6aTi3PihSOcZinBK2JZXXLAOf/2UM3joiFlmDNm5LkAxhE5O70aERQe6bCIq7+OUP+kI1b/V9IqiBF2hBNk/tjJ/kSiPpudCEIzRQB05sgh9n3+lqmtSbxLyIhA4CK2lfs+GV9jv5byeqjTN4hXFDO5hmLYIp7IpeiCFb+qncIMaOOZF4phh+QmMYV1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qDArKp8+6yKt8JDT18TwQTug7JaXNt/QcruAtYeBAzRmznXZlRg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Oct 3, 2024 at 8:15=E2=80=AFPM Dan Williams wrote: > > Yang Shi wrote: > > On Thu, Oct 3, 2024 at 4:32=E2=80=AFPM Dan Williams wrote: > > > > > > Yang Shi wrote: > > > > On Mon, Sep 30, 2024 at 4:54=E2=80=AFPM Huang, Ying wrote: > > > > > > > > > > Hi, David, > > > > > > > > > > Thanks a lot for comments! > > > > > > > > > > David Hildenbrand writes: > > > > > > > > > > > On 30.09.24 07:51, Huang Ying wrote: > > > > > >> On systems with TDX (Trust Domain eXtensions) enabled, memory = ranges > > > > > >> hot-added must be checked for compatibility by TDX. This is c= urrently > > > > > >> implemented through memory hotplug notifiers for each memory_b= lock. > > > > > >> If a memory range which isn't TDX compatible is hot-added, for > > > > > >> example, some CXL memory, the command line as follows, > > > > > >> $ echo 1 > /sys/devices/system/node/nodeX/memoryY/online > > > > > >> will report something like, > > > > > >> bash: echo: write error: Operation not permitted > > > > > >> If pr_debug() is enabled, the error message like below will be= shown > > > > > >> in the kernel log, > > > > > >> online_pages [mem 0xXXXXXXXXXX-0xXXXXXXXXXX] failed > > > > > >> Both are too general to root cause the problem. This will con= fuse > > > > > >> users. One solution is to print some error messages in the TD= X memory > > > > > >> hotplug notifier. However, memory hotplug notifiers are calle= d for > > > > > >> each memory block, so this may lead to a large volume of messa= ges in > > > > > >> the kernel log if a large number of memory blocks are onlined = with a > > > > > >> script or automatically. For example, the typical size of mem= ory > > > > > >> block is 128MB on x86_64, when online 64GB CXL memory, 512 mes= sages > > > > > >> will be logged. > > > > > > > > > > > > ratelimiting would likely help here a lot, but I agree that it = is > > > > > > suboptimal. > > > > > > > > > > > >> Therefore, in this patch, the whole hot-adding memory range is > > > > > >> checked > > > > > >> for TDX compatibility through a newly added architecture speci= fic > > > > > >> function (arch_check_hotplug_memory_range()). If rejected, th= e memory > > > > > >> hot-adding will be aborted with a proper kernel log message. = Which > > > > > >> looks like something as below, > > > > > >> virt/tdx: Reject hot-adding memory range: 0xXXXXXXXX-0xXXXX= XXXX > > > > > >> for TDX compatibility. > > > > > >> > The target use case is to support CXL memory on TDX enabled = systems. > > > > > >> If the CXL memory isn't compatible with TDX, the whole CXL mem= ory > > > > > >> range hot-adding will be rejected. While the CXL memory can s= till be > > > > > >> used via devdax interface. > > > > > > > > > > > > I'm curious, why can that memory be used through devdax but not > > > > > > through the buddy? I'm probably missing something important :) > > > > > > > > > > Because only TDX compatible memory can be used for TDX guest. Th= e buddy > > > > > is used to allocate memory for TDX guest. While devdax will not = be used > > > > > for that. > > > > > > > > Sorry for chiming in late. I think CXL also faces the similar probl= em > > > > on the platform with MTE (memory tagging extension on ARM64). AFAIK= , > > > > we can't have MTE on CXL, so CXL has to stay as dax device if MTE i= s > > > > enabled. > > > > > > > > We should need a similar mechanism to prevent users from hot-adding > > > > CXL memory if MTE is on. But not like TDX I don't think we have a > > > > simple way to tell whether the pfn belongs to CXL or not. Please > > > > correct me if I'm wrong. I'm wondering whether we can find a more > > > > common way to tell memory hotplug to not hot-add some region. For > > > > example, a special flag in struct resource. off the top of my head. > > > > > > > > No solid idea yet, I'm definitely seeking some advice. > > > > > > Could the ARM version of arch_check_hotplug_memory_range() check if M= TE > > > is enabled in the CPU and then ask the CXL subsystem if the address r= ange is > > > backed by a topology that supports MTE? > > > > Kernel can tell whether MTE is really enabled. For the CXL part, IIUC > > that relies on the CXL subsystem is able to tell whether that range > > can support MTE or not, right? Or CXL subsystem tells us whether the > > range is CXL memory range or not, then we can just refuse MTE for all > > CXL regions for now. Does CXL support this now? > > So the CXL specification has section: > > 8.2.4.31 CXL Extended Metadata Capability Register > > ...that indicates if the device supports "Extended Metadata" (EMD). > However, the CXL specification does not talk about how a given hosts > uses the extended metadata capabilities of a device. That detail would > need to come from an ARM platform specification. > > Currently CXL subsystem does nothing with this since there has been no > need to date, but I would expect someone from the ARM side to plumb this > detection into the CXL subsystem. Yeah, it should be a good way to let the kernel know whether CXL supports memory tagging or not. > > > > However, why would it be ok to access CXL memory without MTE via devd= ax, > > > but not as online page allocator memory? > > > > CXL memory can be onlined as system ram as long as MTE is not enabled. > > It just can be used as devdax device if MTE is enabled. > > Do you mean the kernel only manages MTE for kernel pages, but with user > mapped memory the application will need to implicitly know that > memory-tagging is not available? I think the current assumption is that all buddy memory (can be used by userspace) should be taggable. And memory tagging is only supported for anonymous mapping and tmpfs. I'm adding hugetlbfs support. But any memory backed by the real backing store doesn't have memory tagging support. > > I worry about applications that might not know that their heap is coming > from a userspace memory allocator backed by device-dax rather than the > kernel. IIUC, memory mapping from device-dax is a file mapping, right? If so, it is safe. If it is not, I think it is easy to handle. We can just reject any VM_MTE mapping from DAX. > > > > If the goal is to simply deny any and all non-MTE supported CXL regio= n > > > from attaching then that could probably be handled as a modification = to > > > the "cxl_acpi" driver to deny region creation unless it supports > > > everything the CPU expects from "memory". > > > > I'm not quite familiar with the details in CXL driver. What did you > > mean "deny region creation"? As long as the CXL memory still can be > > used as devdax device, it should be fine. > > Meaning that the CXL subsytem knows how to, for a given address range, fi= gure > out the members and geometry of the CXL devices that contribute to that > range (CXL region). It would be straightforward to add EMD to that > enumeration and flag the CXL region as not online-capable if the CPU has > MTE enabled but no EMD capability. It sounds like a good way to me.