Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp138288lqp; Sun, 9 Jun 2024 21:24:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZF/thWV9gH19NIIP/pWOv8SS7yFqi5Z5gSH/EBY/ISDdlsabzIb5n1WuGp+0GRJHuNUq0Df8IiZEDmGQm0rfvMAYoDaKEDMBTCG1A+w== X-Google-Smtp-Source: AGHT+IHGftbk0AXJfcvepG6fJE1GjYZMQtGwyK1FvJK2/IeYeEtyCsTlZ6wtSmJ8Xq8l/t6/01K/ X-Received: by 2002:a50:cdde:0:b0:57c:7151:2669 with SMTP id 4fb4d7f45d1cf-57c71512b1fmr2250800a12.7.1717993456204; Sun, 09 Jun 2024 21:24:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717993456; cv=pass; d=google.com; s=arc-20160816; b=odX8vU6Kg/l+bbYQyjiUcUrCPHhPehurLg1agNBV97L6ReASiiEQQzPtcspkBQv3Vi LIPKGyw12pUJB8woaSRegwvbHU9nbFeRnYZod9SJ0NbswVjKoBb0iSlH5uKBdoeZmgra E8U8bxfqAL+70u33SdR3dzi4MTToxpzE43IPr3FWAkpEOWQBdwnUAgg8Rp8uStbR1VTM 5CLsihJ76bzK2/YCFcovfFxqweEHt/Jt6t19y6xkeFgY8vL0NtfKArdQz4ISgd2ZdUqX ahcwYLFyhQ1H0lrJ51gN3SLlk9B+yk++M/1gwkv4JYUCiWri0BFBRcGb0UFF+CjK+r3n Ws9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=STes9dvsOiZHvfV9vRJe27/8pEpJsEu/gt/yrG0Qqek=; fh=opXV1WEp03kbeubOZloyb10FoNtntQdRllRWblbVMRI=; b=n18DQyIS2s4DQAmZfKB4brab/1qk+HuM/0zL9jPQ6AHshPFZyiUK4aH17bNz9+zJFm GZ54V+Fu/ypBZ+aot72vz8xObyWNii+7wIkdP51TNbREQrFe8/6FadrMiwzRXynyHLaa qF8bSS1gz6pmP02xXk+/pTBbtAWcEjDJQxz2IS/9MA9M214IPkR127QonLKEqL9dyrAt KXAJ2eOtdzYEtPrFY2oAe/PwwEA/A2a1Rf9SgprPewO0DYMMkJGZF7ZBmwgCRXciNCco aAkavyTjk1hpBTlt9cIu1D1uQ5v7oreKRHmIDb2zHXjaC1rSNlOeZS0C1JHM1SNTZ9nK BNsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=o8tqZ6pt; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=o8tqZ6pt; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-207614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c5c71c1a3si2929739a12.102.2024.06.09.21.24.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 21:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=o8tqZ6pt; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=o8tqZ6pt; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-207614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B86701F21A95 for ; Mon, 10 Jun 2024 04:24:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84B1BB665; Mon, 10 Jun 2024 04:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o8tqZ6pt"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="fQWD18aj"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o8tqZ6pt"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="fQWD18aj" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 78BC1A93A; Mon, 10 Jun 2024 04:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717993449; cv=none; b=G409HSeChJ0HqzSyc2yPFvJSr3sGqymee8m/DJN2pkUrIhzSedI+Mo0xw3PNfSNllA8/zQJ21HoerDxHLOUYCIuf3n0IYyyWqw8m8Byx7KlETRdzfO5tReu2+myUQuhIvXpUNe2Cmj+TC1l4l04xD5sSE/E6VPEgBKnxMBhzKso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717993449; c=relaxed/simple; bh=+9BQud+5GBo9h9IzICMyOHTlWYfumUw1E7HBpbUGWBg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DVj7TJ6JL92/rd9y6OHe5VGub+JYWGM7UTCitGGP7O4WgEby9mnCQTNoT1Lbqo5BbkPEw70XrQktS4Z0zMXgRDFt29aQP6x1firMDfHXkLoM5flYtTnQ+y4Hy+iehXXNmM5dJYylAZtOIdVIeqU1TuDSBZciwoeJs9ACTlCifa8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o8tqZ6pt; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=fQWD18aj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o8tqZ6pt; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=fQWD18aj; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (unknown [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 88FA1219DC; Mon, 10 Jun 2024 04:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717993444; 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=STes9dvsOiZHvfV9vRJe27/8pEpJsEu/gt/yrG0Qqek=; b=o8tqZ6ptgNBJgDzFFFlXJ4BuRYktYynoSB9CmRx3kAKTTWOQVXmg2tdchdht62Uh4KiAoT Xjh9Ea6U1Dp2/lG8fVpOXMgyDKEwE6igfCaySZdZRfxaGYQYm6usncgdP35NZiqT5JNfOa RSbw87vp6yMYDpWUD7crMXYt1zHzDeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717993444; 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=STes9dvsOiZHvfV9vRJe27/8pEpJsEu/gt/yrG0Qqek=; b=fQWD18ajS3CyXfmlEKPJp0P/CvQjtxtJJeWW8NIZLqMy2mo4mWHdImltCgMGR17riJ+K30 kQDBwHnbIU0PuZBw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717993444; 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=STes9dvsOiZHvfV9vRJe27/8pEpJsEu/gt/yrG0Qqek=; b=o8tqZ6ptgNBJgDzFFFlXJ4BuRYktYynoSB9CmRx3kAKTTWOQVXmg2tdchdht62Uh4KiAoT Xjh9Ea6U1Dp2/lG8fVpOXMgyDKEwE6igfCaySZdZRfxaGYQYm6usncgdP35NZiqT5JNfOa RSbw87vp6yMYDpWUD7crMXYt1zHzDeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717993444; 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=STes9dvsOiZHvfV9vRJe27/8pEpJsEu/gt/yrG0Qqek=; b=fQWD18ajS3CyXfmlEKPJp0P/CvQjtxtJJeWW8NIZLqMy2mo4mWHdImltCgMGR17riJ+K30 kQDBwHnbIU0PuZBw== 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 5D2BD13A7F; Mon, 10 Jun 2024 04:24:03 +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 jBLQE+N/ZmYYFwAAD6G6ig (envelope-from ); Mon, 10 Jun 2024 04:24:03 +0000 Date: Mon, 10 Jun 2024 06:23:57 +0200 From: Oscar Salvador To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, kasan-dev@googlegroups.com, Andrew Morton , Mike Rapoport , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Alexander Potapenko , Marco Elver , Dmitry Vyukov Subject: Re: [PATCH v1 2/3] mm/memory_hotplug: initialize memmap of !ZONE_DEVICE with PageOffline() instead of PageReserved() Message-ID: References: <20240607090939.89524-1-david@redhat.com> <20240607090939.89524-3-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240607090939.89524-3-david@redhat.com> X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SUBJECT_HAS_EXCLAIM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_TWELVE(0.00)[23]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.30 X-Spam-Flag: NO On Fri, Jun 07, 2024 at 11:09:37AM +0200, David Hildenbrand wrote: > We currently initialize the memmap such that PG_reserved is set and the > refcount of the page is 1. In virtio-mem code, we have to manually clear > that PG_reserved flag to make memory offlining with partially hotplugged > memory blocks possible: has_unmovable_pages() would otherwise bail out on > such pages. > > We want to avoid PG_reserved where possible and move to typed pages > instead. Further, we want to further enlighten memory offlining code about > PG_offline: offline pages in an online memory section. One example is > handling managed page count adjustments in a cleaner way during memory > offlining. > > So let's initialize the pages with PG_offline instead of PG_reserved. > generic_online_page()->__free_pages_core() will now clear that flag before > handing that memory to the buddy. > > Note that the page refcount is still 1 and would forbid offlining of such > memory except when special care is take during GOING_OFFLINE as > currently only implemented by virtio-mem. > > With this change, we can now get non-PageReserved() pages in the XEN > balloon list. From what I can tell, that can already happen via > decrease_reservation(), so that should be fine. > > HV-balloon should not really observe a change: partial online memory > blocks still cannot get surprise-offlined, because the refcount of these > PageOffline() pages is 1. > > Update virtio-mem, HV-balloon and XEN-balloon code to be aware that > hotplugged pages are now PageOffline() instead of PageReserved() before > they are handed over to the buddy. > > We'll leave the ZONE_DEVICE case alone for now. > > Signed-off-by: David Hildenbrand > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 27e3be75edcf7..0254059efcbe1 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -734,7 +734,7 @@ static inline void section_taint_zone_device(unsigned long pfn) > /* > * Associate the pfn range with the given zone, initializing the memmaps > * and resizing the pgdat/zone data to span the added pages. After this > - * call, all affected pages are PG_reserved. > + * call, all affected pages are PageOffline(). > * > * All aligned pageblocks are initialized to the specified migratetype > * (usually MIGRATE_MOVABLE). Besides setting the migratetype, no related > @@ -1100,8 +1100,12 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, > > move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE); > > - for (i = 0; i < nr_pages; i++) > - SetPageVmemmapSelfHosted(pfn_to_page(pfn + i)); > + for (i = 0; i < nr_pages; i++) { > + struct page *page = pfn_to_page(pfn + i); > + > + __ClearPageOffline(page); > + SetPageVmemmapSelfHosted(page); So, refresh my memory here please. AFAIR, those VmemmapSelfHosted pages were marked Reserved before, but now, memmap_init_range() will not mark them reserved anymore. I do not think that is ok? I am worried about walkers getting this wrong. We usually skip PageReserved pages in walkers because are pages we cannot deal with for those purposes, but with this change, we will leak PageVmemmapSelfHosted, and I am not sure whether are ready for that. Moreover, boot memmap pages are marked as PageReserved, which would be now inconsistent with those added during hotplug operations. All in all, I feel uneasy about this change. -- Oscar Salvador SUSE Labs