From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 76D681DF985 for ; Sun, 16 Nov 2025 06:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763275783; cv=none; b=r/eMmwSojikuCBpMYRs1FT696pF/0ut6lxzo/PCtrkJfNdyd007eISJuiRo0WwW1IJrLAtlgqEB9OFsBBY4ZB3S/wF62G0rAYuF/xI71IQVDTlT4SSj3/XEoeZHsfkW76Wy5HlL5he5hxLPd9oz0z1UD+aDRQFIQNhb0MWV0dc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763275783; c=relaxed/simple; bh=cFx7Pj7cGjLF5vOA6b8gUZke2BYzOHpGbWxZRYfJv/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mxhsizpEXmrhOn0KD+swCCtopyz77IWw3ksW4a5aWeOqa7XIA+SOu4nXxQmcpWr40D8grp41FAKdZCcDigQJU+7A5LPhGazyeiXORRq8DQ4xyrOq+VCzm7s5cfWQ4CIOxI5giC3JK23kL9kHCYMM6VDFVsv3YvO2QLErQ49KclU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P0A3Ma3N; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P0A3Ma3N" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7ba55660769so1808656b3a.1 for ; Sat, 15 Nov 2025 22:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763275781; x=1763880581; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9b8IJSYXtBsPcOc3zz//VewvB+A/HFTZrZRLMW1CFbA=; b=P0A3Ma3NlxIbZeC0SnQFdz9X0/nYSDjK7qpPbb9U1weGv5sUANQA2EI+BWtg4uEL6Y VgrCBGGyd2nhS0LFwh7MVkvNTut76NMQWgSLcN4NcbOT7oKdqcBw4KHmvw2K1AiJBsRz UxSIoSg7ySuFi+dPQ77S9Nktqklm/Fh32QkJORJhFPNx3rgRfSH65B7cGsGwewfnmPa7 7OSts5IX32ZVHzRXZbYH+d/geWoTB7Z4S1gyrhZiu8JEdDwYNnevzgfqOtoBy4cIk05x 9SujktP503I93bA4IsBSzwB02KEg1jrUzQ/TppUMABs3MnKP0umBYEDnCol35cGXfUE0 cGSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763275781; x=1763880581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9b8IJSYXtBsPcOc3zz//VewvB+A/HFTZrZRLMW1CFbA=; b=m4midorX6YE3AKCTFo50/kiP7kNjORDuhbJLaNSpHgTdbrfIKaLvl79vTtuRcfviBs V9f+dKQ6GIkRiadDf1Ea+fJM+lzBSZtv34vn5cosXEM43DTHMeSOtPM4tO05GSwxBT7f Cja9PN/AhVEuVo4lwyAT+sIW6W2f93m313tt50qejKykVlamkMOaLon6l7Ig4KSbQcw8 Qoqw/T6RcQInDH6gW95LYFKuAbk4wJDjylERvWz2rmx4C//MDYNG4iAmLtFauCRc5ods R9J/mn21z3U3rJLIE1OKBw61/9gEXRMzmSre69j4yT+keh7OYvLWU9pujJlka1kTbwe7 TRnA== X-Forwarded-Encrypted: i=1; AJvYcCUdW8ywuk3Qj+jSJb3/7xxtPe3xkYitu5yn9nRvGklgrCx+VGYXZSq41nhQC95yuFLMa3tUY569HBjlpU8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyp5XijrxaM6tdPiS8XUwXnTqWQ6f02qfgJaMmuP5NkOsRJAIe8 eoxQrOAfrDxaJVyTNz/WL8Lqoq3LMR2fP9Ltp/Wzj6okFFpieit1HeeC X-Gm-Gg: ASbGncuEi5TghC93AzzLfTSM9kpWXN8zyCIFMfWdi/q64jHdb3Br2+oNG+Mtb93DPU5 M49rfaVB69VS9gSBgY5ECcVtd7ySE5AaQ/s8iN2rsvWU2ro6LKnkOnNU0eVdtKU9i5f+pYXsgN8 DQzpbkz9eQUQNwPMcVRv8v/WaWAIZAJLsYIYNy/ZGUcRR8Du4Zpvxwp8GKRHY2kgfCF15QITmeT 9hho4GLj9OVvMgy3+ez12xBuFT1PBKrJEG3MzUHB1+nQm9RfrewsF4Vd6uw2/QDMLNWTS8IKxlc +SL9iA4z0FSnDrJvKyNbbvzr2jgYsrjlgiCbKuwC+Oug5pOPJ3Dv0NtuxTnw9qqo5Z+pe5++8dz 4jiOgXzAKbo2Q99HzxRFoqjDCIyi3a+ox+ivm+RMWdtTYMGLZcq7AWwSU7O6YtMV1CFO5QdwB8w == X-Google-Smtp-Source: AGHT+IFouFg86tnbEJBbixUeQQEONClEEPNYmTk01w9DMsSZyQU+lHf3REEj3Dr3gbQQjBDIKCsHKw== X-Received: by 2002:a05:6a21:4ec5:10b0:35e:e604:f787 with SMTP id adf61e73a8af0-35ee61484ccmr465968637.39.1763275780537; Sat, 15 Nov 2025 22:49:40 -0800 (PST) Received: from localhost.localdomain ([2403:2c80:17::10:4006]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b9250d2d16sm9578369b3a.22.2025.11.15.22.49.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Nov 2025 22:49:40 -0800 (PST) From: Lance Yang To: pasha.tatashin@soleen.com Cc: akpm@linux-foundation.org, arnd@arndb.de, bhe@redhat.com, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, jasonmiu@google.com, kees@kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rppt@kernel.org, Lance Yang Subject: Re: [PATCH v2 03/13] kho: Introduce high-level memory allocation API Date: Sun, 16 Nov 2025 14:49:18 +0800 Message-ID: <20251116064918.35549-1-ioworker0@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251114190002.3311679-4-pasha.tatashin@soleen.com> References: <20251114190002.3311679-4-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lance Yang On Fri, 14 Nov 2025 13:59:52 -0500, Pasha Tatashin wrote: > Currently, clients of KHO must manually allocate memory (e.g., via > alloc_pages), calculate the page order, and explicitly call > kho_preserve_folio(). Similarly, cleanup requires separate calls to > unpreserve and free the memory. > > Introduce a high-level API to streamline this common pattern: > > - kho_alloc_preserve(size): Allocates physically contiguous, zeroed > memory and immediately marks it for preservation. > - kho_unpreserve_free(ptr): Unpreserves and frees the memory > in the current kernel. > - kho_restore_free(ptr): Restores the struct page state of > preserved memory in the new kernel and immediately frees it to the > page allocator. > > Signed-off-by: Pasha Tatashin > Reviewed-by: Mike Rapoport (Microsoft) > --- > include/linux/kexec_handover.h | 22 +++++--- > kernel/liveupdate/kexec_handover.c | 87 ++++++++++++++++++++++++++++++ > 2 files changed, 102 insertions(+), 7 deletions(-) > > diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h > index 80ece4232617..38a9487a1a00 100644 > --- a/include/linux/kexec_handover.h > +++ b/include/linux/kexec_handover.h > @@ -2,8 +2,9 @@ > #ifndef LINUX_KEXEC_HANDOVER_H > #define LINUX_KEXEC_HANDOVER_H > > -#include > +#include > #include > +#include > > struct kho_scratch { > phys_addr_t addr; > @@ -48,6 +49,9 @@ int kho_preserve_pages(struct page *page, unsigned int nr_pages); > int kho_unpreserve_pages(struct page *page, unsigned int nr_pages); > int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation); > int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); > +void *kho_alloc_preserve(size_t size); > +void kho_unpreserve_free(void *mem); > +void kho_restore_free(void *mem); > struct folio *kho_restore_folio(phys_addr_t phys); > struct page *kho_restore_pages(phys_addr_t phys, unsigned int nr_pages); > void *kho_restore_vmalloc(const struct kho_vmalloc *preservation); > @@ -101,6 +105,14 @@ static inline int kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) > return -EOPNOTSUPP; > } > > +void *kho_alloc_preserve(size_t size) > +{ > + return ERR_PTR(-EOPNOTSUPP); > +} > + > +void kho_unpreserve_free(void *mem) { } > +void kho_restore_free(void *mem) { } The compile is unhapply here when CONFIG_KEXEC_HANDOVER is not set ... ``` ld: arch/x86/realmode/rm/video-mode.o: in function `kho_alloc_preserve': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: multiple definition of `kho_alloc_preserve'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: first defined here ld: arch/x86/realmode/rm/video-mode.o: in function `kho_unpreserve_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: multiple definition of `kho_unpreserve_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: first defined here ld: arch/x86/realmode/rm/video-mode.o: in function `kho_restore_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: multiple definition of `kho_restore_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: first defined here ld: arch/x86/realmode/rm/regs.o: in function `kho_alloc_preserve': /home/runner/work/mm-test-robot/mm-test-robot/linux/arch/x86/realmode/rm/regs.c:102: multiple definition of `kho_alloc_preserve'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: first defined here ld: arch/x86/realmode/rm/regs.o: in function `kho_unpreserve_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/arch/x86/realmode/rm/regs.c:104: multiple definition of `kho_unpreserve_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: first defined here ld: arch/x86/realmode/rm/regs.o: in function `kho_restore_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/arch/x86/realmode/rm/regs.c:105: multiple definition of `kho_restore_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: first defined here ld: arch/x86/realmode/rm/video-vga.o: in function `kho_alloc_preserve': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: multiple definition of `kho_alloc_preserve'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: first defined here ld: arch/x86/realmode/rm/video-vga.o: in function `kho_unpreserve_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: multiple definition of `kho_unpreserve_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: first defined here ld: arch/x86/realmode/rm/video-vga.o: in function `kho_restore_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: multiple definition of `kho_restore_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: first defined here ld: arch/x86/realmode/rm/video-vesa.o: in function `kho_alloc_preserve': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: multiple definition of `kho_alloc_preserve'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: first defined here ld: arch/x86/realmode/rm/video-vesa.o: in function `kho_unpreserve_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: multiple definition of `kho_unpreserve_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: first defined here ld: arch/x86/realmode/rm/video-vesa.o: in function `kho_restore_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: multiple definition of `kho_restore_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: first defined here ld: arch/x86/realmode/rm/video-bios.o: in function `kho_alloc_preserve': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: multiple definition of `kho_alloc_preserve'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:102: first defined here ld: arch/x86/realmode/rm/video-bios.o: in function `kho_unpreserve_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: multiple definition of `kho_unpreserve_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:104: first defined here ld: arch/x86/realmode/rm/video-bios.o: in function `kho_restore_free': /home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: multiple definition of `kho_restore_free'; arch/x86/realmode/rm/wakemain.o:/home/runner/work/mm-test-robot/mm-test-robot/linux/./include/linux/kexec_handover.h:105: first defined here make[5]: *** [arch/x86/realmode/rm/Makefile:49: arch/x86/realmode/rm/realmode.elf] Error 1 make[4]: *** [arch/x86/realmode/Makefile:22: arch/x86/realmode/rm/realmode.bin] Error 2 make[3]: *** [scripts/Makefile.build:556: arch/x86/realmode] Error 2 ``` Perhaps these stubs should be declared as static inline? That should make the compiler happy and resolve the linking errors :) ----8<---- diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 6dd0dcdf0ec1..5f7b9de97e8d 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -96,13 +96,13 @@ static inline int kho_preserve_vmalloc(void *ptr, static inline void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) { } -void *kho_alloc_preserve(size_t size) +static inline void *kho_alloc_preserve(size_t size) { return ERR_PTR(-EOPNOTSUPP); } -void kho_unpreserve_free(void *mem) { } -void kho_restore_free(void *mem) { } +static inline void kho_unpreserve_free(void *mem) { } +static inline void kho_restore_free(void *mem) { } static inline struct folio *kho_restore_folio(phys_addr_t phys) { --- [...] Cheers, Lance