From nobody Mon Nov 25 18:43:00 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D49C1741C9 for ; Fri, 25 Oct 2024 15:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729869154; cv=none; b=CjgLQczmVGPsVAdf/jqpMmWjyv4UWj/je7X3q6DzhOl7C2NspmfdWDfUZC3loiGJu+DNOa92R8rLaB6x1L1skG5PYZOgUEjL8h8ZRuOibjXaBJHJ6cJcBYJHHr6Da1Uj5QhjmOltJvcyPPHKYXcJl4LU5dju0zLb2QS7yXmy8hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729869154; c=relaxed/simple; bh=wzqFyeRzIbZYPQzh5xeryisiS+GCyWq3rwgwt2g7Hdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=npzlyfaj6Ho2cirHdRgr2/KY13/d6w5P1aWgmgWuhy1V0x6N9vRUqDEKgHz8icieyZMqpQYsrHwC6QRDYoh/4EqPTG8+SdeOdl8eTRKfha09am/9Zr00yyMLnWRf+PRAaTT8LwegdsCyX7jLvt0ys7RD1Ysp2ziUK5FWAsp/VGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ob7zSL9b; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ob7zSL9b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869151; 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=Ob7zSL9bXQdGEXB+AmISqW/7tdPloKHAylYjXWdMDrbyjq+3FJLSocyuYFs90M/tC/OEFX d0fDUJ2YQY2UNLd1J8VNTOal1gAIZ4MY2KvyhWFParrGcXfEwuYY6rO4uf3YYc9Nkb1XJ6 W03ReNRe0Zoq6fahtlMwOoxdtKr2WmA= 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=20P=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" 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 =3D { .proc_mmap =3D mmap_vmcore, }; =20 -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_elf6= 4(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_elf= 64(char *elfptr, end =3D roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size =3D end - start; =20 - /* Add this contiguous chunk of memory to vmcore list.*/ - new =3D get_new_element(); - if (!new) + if (vmcore_alloc_add_mem_node(vc_list, start, size)) return -ENOMEM; - new->paddr =3D start; - new->size =3D size; - list_add_tail(&new->list, vc_list); =20 /* Update the program header offset. */ phdr_ptr->p_offset =3D vmcore_off + (paddr - start); @@ -1133,7 +1122,6 @@ static int __init process_ptload_program_headers_elf3= 2(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_elf= 32(char *elfptr, end =3D roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size =3D end - start; =20 - /* Add this contiguous chunk of memory to vmcore list.*/ - new =3D get_new_element(); - if (!new) + if (vmcore_alloc_add_mem_node(vc_list, start, size)) return -ENOMEM; - new->paddr =3D start; - new->size =3D size; - list_add_tail(&new->list, vc_list); =20 /* Update the program header offset */ phdr_ptr->p_offset =3D 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; }; =20 +/* 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 =3D kzalloc(sizeof(*m), GFP_KERNEL); + + if (!m) + return -ENOMEM; + m->paddr =3D paddr; + m->size =3D 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 */ --=20 2.46.1