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 E6F0CC3600C for ; Thu, 3 Apr 2025 13:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3C25280003; Thu, 3 Apr 2025 09:57:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEA68280001; Thu, 3 Apr 2025 09:57:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD834280003; Thu, 3 Apr 2025 09:57:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8EB8F280001 for ; Thu, 3 Apr 2025 09:57:43 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A2F531408E1 for ; Thu, 3 Apr 2025 13:57:44 +0000 (UTC) X-FDA: 83292885648.25.D829F50 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf07.hostedemail.com (Postfix) with ESMTP id D9CD240007 for ; Thu, 3 Apr 2025 13:57:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iW7Kcl6M; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743688663; a=rsa-sha256; cv=none; b=5yfbSLvXtu2oTg7aHS61cSfuHde1w3XFLvgiOvSN8oCI9M0VZGt7by+Kb6kP1u79zpsoDi dexpyDm8Fsq3xtmZ20HzwldGC98HbYsvPVp70ZIXYyRVTPg1dsBJj+vWDR07Twy5ddeb0Y 6DaZgnzEg4B3wOk2icmgZIjuJrk+phI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iW7Kcl6M; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743688663; 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=zez+6p8Y3I5aFWhI6/jit+0uu3QYEFLgq6rmajm/pbc=; b=QBDu/aUBmsE0jbV1LUCimKvEe/LMlzEpQWwk6QL5tIh5sSrQOOK04UXc4Hue4gJCTsnO9v RRUev6sO3kNpaXCxKG2Pc4OJk3I+lhgFAV5fLMYDtyRwwry2VVkL7TXMw4wKeiFZ/MS/mV aZ4BTUbvt3rGiRdBWttqnLpyd0AcwSA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 003CA4395F; Thu, 3 Apr 2025 13:57:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A24EC4CEE3; Thu, 3 Apr 2025 13:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743688661; bh=5SR2KTBI1kKtfOBINvsox0Z0ryfiIm93Ekm8MRv/a4I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iW7Kcl6McmBEbJ1JPZ4u0Huxc2f6LpTnxB8SXB6QM6RbBFXxP9bN9E8qyknVSdeu+ l/b+SAQ0QWM3fR8hQqvYA7ZOXApBXeYHLHS2dOtEI4U4eNVuZ996rcgf9L1vOMk1VK fsR+piAc8w0Tw7dC/yfcWpuGp/3Zm0/Hg6A4cnGFfj20+RRAL0D7bzGlvX7pR+TyEM MNWnWibgibRxnmAdvGDG7Qxe1hwAugVpYoRsDOYU8Dz9TOIZ3hKlDJrJ32IqaHfWrO 0gY5wz+zFvE4o6h1f3Wor+aFDgX4QJbAEqle0OkXvoDBz/9rl4ykSomefNEMfNRYWa D3h05S20MooXA== Date: Thu, 3 Apr 2025 16:57:25 +0300 From: Mike Rapoport To: Pratyush Yadav Cc: Changyuan Lyu , linux-kernel@vger.kernel.org, graf@amazon.com, akpm@linux-foundation.org, luto@kernel.org, anthony.yznaga@oracle.com, arnd@arndb.de, ashish.kalra@amd.com, benh@kernel.crashing.org, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, dwmw2@infradead.org, ebiederm@xmission.com, mingo@redhat.com, jgowans@amazon.com, corbet@lwn.net, krzk@kernel.org, mark.rutland@arm.com, pbonzini@redhat.com, pasha.tatashin@soleen.com, hpa@zytor.com, peterz@infradead.org, robh+dt@kernel.org, robh@kernel.org, saravanak@google.com, skinsburskii@linux.microsoft.com, rostedt@goodmis.org, tglx@linutronix.de, thomas.lendacky@amd.com, usama.arif@bytedance.com, will@kernel.org, devicetree@vger.kernel.org, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, Jason Gunthorpe Subject: Re: [PATCH v5 09/16] kexec: enable KHO support for memory preservation Message-ID: References: <20250320015551.2157511-1-changyuanl@google.com> <20250320015551.2157511-10-changyuanl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: D9CD240007 X-Stat-Signature: jek1ccux77ur498mnj6ec766b7xtbe4y X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743688662-682787 X-HE-Meta: U2FsdGVkX1/lv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2YcHDPAVuhmLWD4dkrPZAqQZmkH2MY8BuqXAeAX8JDUsEsSqakoEmVHrDYjkoqcwyoepzmKQZ2C1eSVoC6TwQ6I8Isp8Aj0Sx+90ZgK6X2Vn5RZ+AvvfK+WLUH/CymhHxUYAuUUomM6mW61fPHJpFVvOFiI/1w/RbTo+Z7aEBzvSd1fm0BwOLUlPfxgjLFefcILDau29UKJeqReY5H4pu/JS9VvuhDe+iWV2fXLuActai5hAzs3WVMf3s94AeM5VFkCsRIqhTPkkGxZE6JEs2M8uezNRysyLvOt3Geq0EHldJmN9b0tdY2SKCzYbvg== 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 Wed, Apr 02, 2025 at 07:16:27PM +0000, Pratyush Yadav wrote: > Hi Changyuan, > > On Wed, Mar 19 2025, Changyuan Lyu wrote: > > > From: "Mike Rapoport (Microsoft)" > > > > Introduce APIs allowing KHO users to preserve memory across kexec and > > get access to that memory after boot of the kexeced kernel > > > > kho_preserve_folio() - record a folio to be preserved over kexec > > kho_restore_folio() - recreates the folio from the preserved memory > > kho_preserve_phys() - record physically contiguous range to be > > preserved over kexec. > > kho_restore_phys() - recreates order-0 pages corresponding to the > > preserved physical range > > > > The memory preservations are tracked by two levels of xarrays to manage > > chunks of per-order 512 byte bitmaps. For instance the entire 1G order > > of a 1TB x86 system would fit inside a single 512 byte bitmap. For > > order 0 allocations each bitmap will cover 16M of address space. Thus, > > for 16G of memory at most 512K of bitmap memory will be needed for order 0. > > > > At serialization time all bitmaps are recorded in a linked list of pages > > for the next kernel to process and the physical address of the list is > > recorded in KHO FDT. > > > > The next kernel then processes that list, reserves the memory ranges and > > later, when a user requests a folio or a physical range, KHO restores > > corresponding memory map entries. > > > > Suggested-by: Jason Gunthorpe > > Signed-off-by: Mike Rapoport (Microsoft) > > Co-developed-by: Changyuan Lyu > > Signed-off-by: Changyuan Lyu > > --- > > include/linux/kexec_handover.h | 38 +++ > > kernel/kexec_handover.c | 486 ++++++++++++++++++++++++++++++++- > > 2 files changed, 522 insertions(+), 2 deletions(-) > [...] > > +int kho_preserve_phys(phys_addr_t phys, size_t size) > > +{ > > + unsigned long pfn = PHYS_PFN(phys), end_pfn = PHYS_PFN(phys + size); > > + unsigned int order = ilog2(end_pfn - pfn); > > This caught my eye when playing around with the code. It does not put > any limit on the order, so it can exceed NR_PAGE_ORDERS. Also, when I don't see a problem with this > initializing the page after KHO, we pass the order directly to > prep_compound_page() without sanity checking it. The next kernel might > not support all the orders the current one supports. Perhaps something > to fix? And this needs to be fixed and we should refuse to create folios larger than MAX_ORDER. > > + unsigned long failed_pfn; > > + int err = 0; > > + > > + if (!kho_enable) > > + return -EOPNOTSUPP; > > + > > + down_read(&kho_out.tree_lock); > > + if (kho_out.fdt) { > > + err = -EBUSY; > > + goto unlock; > > + } > > + > > + for (; pfn < end_pfn; > > + pfn += (1 << order), order = ilog2(end_pfn - pfn)) { > > + err = __kho_preserve(&kho_mem_track, pfn, order); > > + if (err) { > > + failed_pfn = pfn; > > + break; > > + } > > + } > [... > > +struct folio *kho_restore_folio(phys_addr_t phys) > > +{ > > + struct page *page = pfn_to_online_page(PHYS_PFN(phys)); > > + unsigned long order = page->private; > > + > > + if (!page) > > + return NULL; > > + > > + order = page->private; > > + if (order) > > + prep_compound_page(page, order); > > + else > > + kho_restore_page(page); > > + > > + return page_folio(page); > > +} > [...] > > -- > Regards, > Pratyush Yadav -- Sincerely yours, Mike.