From patchwork Fri Oct 25 15:11:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850922 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 EC59DD0BB56 for ; Fri, 25 Oct 2024 15:12:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C19D6B0096; Fri, 25 Oct 2024 11:12:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6991B6B0098; Fri, 25 Oct 2024 11:12:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5880B6B0099; Fri, 25 Oct 2024 11:12:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3A7F56B0096 for ; Fri, 25 Oct 2024 11:12:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 48C5A1C6044 for ; Fri, 25 Oct 2024 15:12:13 +0000 (UTC) X-FDA: 82712465304.01.11FC481 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 75DD680009 for ; Fri, 25 Oct 2024 15:11:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hs0sm+pj; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869076; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UerumhmGRgSm1AsU/ieQ+gWT/mqI7oI1n5V7Kl7Bfao=; b=pPSabtYRdki/RaSI9eert4PmcKsc+EqBffqgM/kTMKOVHSuhIwDqXUeB/83qyFEsxiz9Nb 4qn/fVsf9hq83YESZQd4h2htRsAQvx3UkU0gKGGTZnQgXkspgRi1HfuuE6rff3iY1xbY5q m0VQQDiSHoX0Y/nPLaJbxwIw0/4pyUs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hs0sm+pj; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869076; a=rsa-sha256; cv=none; b=1oP1NINnOWkWU5bpS16pmv9hYI85LGduIMTxsoENtswjPM+mzichQh2QCAHX2H0Hc7ghHT 3NGsx4QJozoOiyswBUHCEN18BAvbB64PPh7fM8e3YI6LRNnZtVmcLNAT5JPUPla1hqLEen gJN4nEcrhiX0ZRzznK9jtV9bPPf53as= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UerumhmGRgSm1AsU/ieQ+gWT/mqI7oI1n5V7Kl7Bfao=; b=Hs0sm+pjoDif+jLDFQB0WXqEMspTwAjosfHFHTLGOeAnr7Xm+VHfrlWPtjS45kUSVbjXFT 86pb0Uwte+1k34f7izulhFbnVAUNF3rZgAwqZCi2OkoJmyykt4UkwlAMnntlBXhkA+69Wk StMg1/jvpHzE3XCfwzfRsGOSXmUUwTY= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-8XrGVJi3OyGjKDZHuJgcSw-1; Fri, 25 Oct 2024 11:12:30 -0400 X-MC-Unique: 8XrGVJi3OyGjKDZHuJgcSw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 98ACF1955E70; Fri, 25 Oct 2024 15:12:27 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.22.65.27]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 006CD30001A9; Fri, 25 Oct 2024 15:12:19 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Baoquan He , Vivek Goyal , Dave Young , Thomas Huth , Cornelia Huck , Janosch Frank , Claudio Imbrenda , Eric Farman , Andrew Morton Subject: [PATCH v1 05/11] fs/proc/vmcore: factor out allocating a vmcore memory node Date: Fri, 25 Oct 2024 17:11:27 +0200 Message-ID: <20241025151134.1275575-6-david@redhat.com> In-Reply-To: <20241025151134.1275575-1-david@redhat.com> References: <20241025151134.1275575-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 75DD680009 X-Stat-Signature: 1ckxg5xrkpxd7cd6xtehqtryy567pbk3 X-HE-Tag: 1729869116-821844 X-HE-Meta: U2FsdGVkX1/gkfWDpmoXfWb/scuU/XxAr2SSv7q1RLt3e+3Fub2LksbfzZF/QrdkmiQycasKTRpvJqgcjciFeE4cIeiq/1M78DPQ5FBzeP+BCPLi4phQ9fT1DK8bhia+rGWbhZodHPBi1bSCwLi4iLr9tli0/NFQ/goxWTcXYAAE8/agArgpK85Nu1lZK0CV6CBdEs8AHV94pYCjic+3wM8kT1zd+A3iMkB8L6aI8X/RrHQ1rDnUrfiAIYdj2wRZntjqg54NGJtLbHUEW2utvPnI0WmqUGuRpS/6Tludo1OTcLDzP1Yu2TO9Q+sR4ZyMFFxfOpm7GDNtqxBr3yaYFxVz47UyAwG22/KnFI4ZT/CYqQp0k/XuZlWtwY0aTLaNyxB+FW3TFzYv8snXJCMEoEjq4ic1+BG6S3CMTvhCL+omidWfNVuor+u0jsLX2XxZnBOVcbk/LwtblK9yDtRCEKzMuK2wf3DI3degLjAQkDV1aGKBxJUzUi5GLVOnDb+KRgCoYrOcV/T3pT7iReCGpM0fTuXRuQt7f6rY5Mtylm6+URWcim4mr5mOE4zyDgSfGIMB30xqyCVBfJLMUbHavoAFMlRgLt7o0GdOC3HtNgIPzisD7ja2jnzS5isVH4MBLxm+sjFYuXhMsrh132bqaqRsfZjbXcffgJW2cvzPy0IUFB9GQSwanWlgQMiHdAE5FbJxiWWjGWUp1t0eMiS4468LX2tRkUHP3rssOEl8yxbSUVJNgaEtDaM3y/QURyTIFYjLJa36PhLDDcLHs2vo+V5QCj1tQNJKYM87BqBz+P/SVjDf46cuDfHPdM13EIc2Uacnv4cvOIj8mfyaZ6U0C5p6erHmK1qoPTADFFtJnPtOxIRUppPNMYFuJw1nf0Y+ck3MRGKB0fADHBa6DaAUKznnErVHjz6lUR8p6jvpv2HRNvUjQiTki6Ft/JD6vp9IZux89bpeJbZlfhOt4ti OCVusy9N glpwL/KwtoK8Lc9ah7JT99eyVLhUbpp+/Oi6v0K1pjlJRUCbwgsnxNFQ7iX3079PY554xzDAmhbXqhN6+39BUm2d5bf7SeH/HeTMIwnmZsxPwi4l/OKPRjMJ1/X+J059mY78d56M7Cw1QlsBCA/Nq//EnH5J+fWmePxMVjVXt++/l5mBMbIdTOcy4DHIPQ/VzlQP8sbna5w3Xvb8R62ytlGcGfexnZIjz5NbJkvY1QSARM8VkM71ra/JrNXfKyzWRpo9upPOiG4Kq5Xk95MyX1LOM4/iHYCDlgqUm28wkpXoel1Oh9wCMUMHNVtgod4X3b8s8yQAwQu3nfW8= 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: Let's factor it out into include/linux/crash_dump.h, from where we can use it also outside of vmcore.c later. Signed-off-by: David Hildenbrand Acked-by: Baoquan He --- fs/proc/vmcore.c | 21 ++------------------- include/linux/crash_dump.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 47652df95202..76fdc3fb8c0e 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -683,11 +683,6 @@ static const struct proc_ops vmcore_proc_ops = { .proc_mmap = mmap_vmcore, }; -static struct vmcore_mem_node * __init get_new_element(void) -{ - return kzalloc(sizeof(struct vmcore_mem_node), GFP_KERNEL); -} - static u64 get_vmcore_size(size_t elfsz, size_t elfnotesegsz, struct list_head *vc_list) { @@ -1090,7 +1085,6 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { - struct vmcore_mem_node *new; int i; Elf64_Ehdr *ehdr_ptr; Elf64_Phdr *phdr_ptr; @@ -1113,13 +1107,8 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size = end - start; - /* Add this contiguous chunk of memory to vmcore list.*/ - new = get_new_element(); - if (!new) + if (vmcore_alloc_add_mem_node(vc_list, start, size)) return -ENOMEM; - new->paddr = start; - new->size = size; - list_add_tail(&new->list, vc_list); /* Update the program header offset. */ phdr_ptr->p_offset = vmcore_off + (paddr - start); @@ -1133,7 +1122,6 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { - struct vmcore_mem_node *new; int i; Elf32_Ehdr *ehdr_ptr; Elf32_Phdr *phdr_ptr; @@ -1156,13 +1144,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size = end - start; - /* Add this contiguous chunk of memory to vmcore list.*/ - new = get_new_element(); - if (!new) + if (vmcore_alloc_add_mem_node(vc_list, start, size)) return -ENOMEM; - new->paddr = start; - new->size = size; - list_add_tail(&new->list, vc_list); /* Update the program header offset */ phdr_ptr->p_offset = vmcore_off + (paddr - start); diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 5e48ab12c12b..ae77049fc023 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -121,6 +121,20 @@ struct vmcore_mem_node { loff_t offset; }; +/* Allocate a vmcore memory node and add it to the list. */ +static inline int vmcore_alloc_add_mem_node(struct list_head *list, + unsigned long long paddr, unsigned long long size) +{ + struct vmcore_mem_node *m = kzalloc(sizeof(*m), GFP_KERNEL); + + if (!m) + return -ENOMEM; + m->paddr = paddr; + m->size = size; + list_add_tail(&m->list, list); + return 0; +} + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */