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 D3B91D1CDAC for ; Tue, 22 Oct 2024 07:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2116F6B0083; Tue, 22 Oct 2024 03:49:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2756B0085; Tue, 22 Oct 2024 03:49:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0898D6B0088; Tue, 22 Oct 2024 03:49:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E0C526B0083 for ; Tue, 22 Oct 2024 03:49:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E1E001C69FD for ; Tue, 22 Oct 2024 07:48:58 +0000 (UTC) X-FDA: 82700462292.12.A718690 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf20.hostedemail.com (Postfix) with ESMTP id B442E1C0019 for ; Tue, 22 Oct 2024 07:48:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1n7MXVHm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lzwsiTr9; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1n7MXVHm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lzwsiTr9; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729583232; a=rsa-sha256; cv=none; b=TCtgadPu/+jP06+2Erpl8GKcuV0atcPU72cN5fFuA0Y320hdi/aFJXlUC8OVK3ZUE881PB Jxyunl04medQ17ONYzCwnKLSFNQ0w9r/F+Ck1D5qKXptgSqvqIdBREPFANKEZkuJpmp3JR Kh8V9khduDG+aTr4t63ebaYmp98bVe0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1n7MXVHm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lzwsiTr9; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1n7MXVHm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=lzwsiTr9; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729583232; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m7sZdKMGSdM6kuvLwufr4oBJIa0eABSyj1x+dLkMRJ8=; b=POLj4D1zQEnAl+zVYODMRxee8rzuEBTPWDbMlixU5lszF1eLWRg8TXtXGQUU2Ln8fq5wc9 JLNehEKuPGTgBHJQci6NEdB5an5yARvvoYC0MszleezD+HHsIstVlzVoTNVQoxX1CxlzwH w9mSedDSNR6Bs4TlBJz72Mt6mPF+F8s= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1ED3621C79; Tue, 22 Oct 2024 07:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1729583353; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m7sZdKMGSdM6kuvLwufr4oBJIa0eABSyj1x+dLkMRJ8=; b=1n7MXVHm6P6xSUKAFFCHHBL1jHjA3GLQvxX8tJ+Lmm84sbnSceCMM4psZa7nAK96qpZ9KU 9kDX/CdxyzZawiHEiVv70dsH7swJXu3isuZvM2jbB266+jkDpaDeJoM99e52UCyGEwCeOt CW+QUaKH+H4yIFuG2Y9FMnIhKN4eFgw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1729583353; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m7sZdKMGSdM6kuvLwufr4oBJIa0eABSyj1x+dLkMRJ8=; b=lzwsiTr9kgCRA8TwWBeyL+sx6DSNIMKiJQtLRAddW1+k4MjRxzvr62vUXJdwLxPk8Z1ZPJ hfzZssdpyjBGUEDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1729583353; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m7sZdKMGSdM6kuvLwufr4oBJIa0eABSyj1x+dLkMRJ8=; b=1n7MXVHm6P6xSUKAFFCHHBL1jHjA3GLQvxX8tJ+Lmm84sbnSceCMM4psZa7nAK96qpZ9KU 9kDX/CdxyzZawiHEiVv70dsH7swJXu3isuZvM2jbB266+jkDpaDeJoM99e52UCyGEwCeOt CW+QUaKH+H4yIFuG2Y9FMnIhKN4eFgw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1729583353; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m7sZdKMGSdM6kuvLwufr4oBJIa0eABSyj1x+dLkMRJ8=; b=lzwsiTr9kgCRA8TwWBeyL+sx6DSNIMKiJQtLRAddW1+k4MjRxzvr62vUXJdwLxPk8Z1ZPJ hfzZssdpyjBGUEDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2B7EB13AC9; Tue, 22 Oct 2024 07:49:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qQdCB/hYF2dCbgAAD6G6ig (envelope-from ); Tue, 22 Oct 2024 07:49:12 +0000 Date: Tue, 22 Oct 2024 09:49:06 +0200 From: Oscar Salvador To: Huang Ying Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "Kirill A . Shutemov" , x86@kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dan Williams , Kai Huang , David Hildenbrand , "H. Peter Anvin" , Andy Lutomirski Subject: Re: [PATCH -V3] x86/tdx, memory hotplug: Check whole hot-adding memory range for TDX Message-ID: References: <20241022031617.159969-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241022031617.159969-1-ying.huang@intel.com> X-Rspamd-Action: no action X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B442E1C0019 X-Stat-Signature: opwuqfr9cxq7nzwfhfzmio6jeozqc96w X-Rspam-User: X-HE-Tag: 1729583335-54021 X-HE-Meta: U2FsdGVkX1+Udm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Tgc3tkUJ4vNpvXrzfgogjaCOYhVDOOLRa6nr93v+sV/w/ZCFjHZ7u9urGFCQvKEVP6EZe1F1/cq2dTuP8mfG/LGWpXoTjajzpV2P9s0hJd7mH7C89FeuVTX87fk1SaZULQW9YxjZrY/i8hpBc8JN2Y9M9L2f0IFh/qEfoHy8OeG96dpDFkFixWBpvOBvCeMrq85 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 Tue, Oct 22, 2024 at 11:16:17AM +0800, Huang Ying wrote: > On systems with TDX (Trust Domain eXtensions) enabled, current kernel > checks the TDX compatibility of the hot-added memory ranges through a > memory hotplug notifier for each memory_block. 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, current kernel will show the error message > like below in the kernel log, > > online_pages [mem 0xXXXXXXXXXX-0xXXXXXXXXXX] failed > > Both are too general to root cause the problem. This may confuse > users. One solution is to print some error messages in the TDX memory > hotplug notifier. However, kernel calls memory hotplug notifiers for > each memory block, so this may lead to a large volume of messages in > the kernel log if a large number of memory blocks are onlined with a > script or automatically. For example, the typical size of memory > block is 128MB on x86_64, when online 64GB CXL memory, 512 messages > will be logged. > > Therefore, this patch checks the TDX compatibility of the whole > hot-adding memory range through a newly added architecture specific > function (arch_check_hotplug_memory_range()). If this patch rejects > the memory hot-adding for TDX compatibility, it will output a kernel > log message like below, > > virt/tdx: Reject hot-adding memory range: 0xXXXXXXXX-0xXXXXXXXX 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 kernel will reject > the whole CXL memory range. While the CXL memory can still be used > via devdax interface. > > This also makes the original TDX memory hotplug notifier useless, so > this patch deletes it. > > Signed-off-by: "Huang, Ying" Acked-by: Oscar Salvador One question below: ... > +int tdx_check_hotplug_memory_range(u64 start, u64 size) > { > - struct memory_notify *mn = v; > - > - if (action != MEM_GOING_ONLINE) > - return NOTIFY_OK; > + u64 start_pfn = PHYS_PFN(start); > + u64 end_pfn = PHYS_PFN(start + size); > > /* > * Empty list means TDX isn't enabled. Allow any memory > - * to go online. > + * to be hot-added. > */ > if (list_empty(&tdx_memlist)) > - return NOTIFY_OK; > + return 0; > > /* > * The TDX memory configuration is static and can not be > - * changed. Reject onlining any memory which is outside of > + * changed. Reject hot-adding any memory which is outside of > * the static configuration whether it supports TDX or not. > */ > - if (is_tdx_memory(mn->start_pfn, mn->start_pfn + mn->nr_pages)) > - return NOTIFY_OK; > + if (is_tdx_memory(start_pfn, end_pfn)) > + return 0; > > - return NOTIFY_BAD; > + pr_info("Reject hot-adding memory range: %#llx-%#llx for TDX compatibility.\n", > + start, start + size); Why not using pr_err() here? I was checking which kind of information level we use when failing at hot-adding memory, and we seem to be using pr_err(), and pr_debug() when onlining/offlining. Not a big deal, and not saying it is wrong, but was just wondering the reasoning behind. -- Oscar Salvador SUSE Labs