From patchwork Fri Oct 25 15:11:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850918 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 6936DD0C61F for ; Fri, 25 Oct 2024 15:12:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F256E6B0083; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED6776B0085; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9E036B0088; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BBD856B0083 for ; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8CCE9AC6D3 for ; Fri, 25 Oct 2024 15:11:25 +0000 (UTC) X-FDA: 82712464380.22.12DBB17 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 833BA4001B for ; Fri, 25 Oct 2024 15:11:53 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fgJhnSnE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869082; a=rsa-sha256; cv=none; b=E4GkRV2Z2jmSpUoNZamkgrFXVxiiHOHYPdj5J9q3U8oQboMJpomc+Ax/k64flnOU238XK3 VuD6u3CB9RwVrrnZeUTXISVS3+ift/xULNc3UbY3/xzTrCRDwd+P1gDS9r6LyT9GffiZc7 Gu11V/zWvJFD6LH7zAbOGfEbnBAaf4o= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fgJhnSnE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869082; 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=VrMChLaTWQQV1P3cCXF0g4Mb1STd5YPEt4ibYFFJxW4=; b=1QQz4Bo1SG6iVGOFjyGol2LuBSG/70CAtz5YBcY2y1U/atBMTF1iLMyDh2KizWT8FmKGzZ hRRE+VblGzmtnrBvYjMnod3McmpY69Fo43Pdy4auFYpbqZwQ+nJQLWZl0fTEP+B8sf8V9O iMBAMpam017jcF8sHsD0r/9jWm8lVrg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869121; 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=VrMChLaTWQQV1P3cCXF0g4Mb1STd5YPEt4ibYFFJxW4=; b=fgJhnSnEQSTql4I4+FerEDjUXmI19VK+NxbhKXl3Hq6GJ/HQv1ipTufu8pTDSZv2RyjO2B WctAAgGWqxj+/xDsNihW+2AwG5llF5XDzMQS+8l8jTskh8afRSaXlhu0eUowl7xRdruy6a o2epJmpChMRnBbUAjXp/xWUjtESmFg0= Received: from mx-prod-mc-04.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-35-oROdk647PWOwfbs1qWmB5g-1; Fri, 25 Oct 2024 11:11:58 -0400 X-MC-Unique: oROdk647PWOwfbs1qWmB5g-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1D5A8193585B; Fri, 25 Oct 2024 15:11:53 +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 1F17D3000198; Fri, 25 Oct 2024 15:11:44 +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 01/11] fs/proc/vmcore: convert vmcore_cb_lock into vmcore_mutex Date: Fri, 25 Oct 2024 17:11:23 +0200 Message-ID: <20241025151134.1275575-2-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-Rspam-User: X-Stat-Signature: c6xs7uggk6d437hhj853tgfgg6fbypyt X-Rspamd-Queue-Id: 833BA4001B X-Rspamd-Server: rspam02 X-HE-Tag: 1729869113-484944 X-HE-Meta: U2FsdGVkX19d0jhD0laZlf+ab8R7c80mRZ/x8DOu8tp8vNrLX/ZWSyJU7KNEKzuFmL1Wm2XQ8mNdXt48Y6MMXVxnGP0SdJ6L1tS9L+lbG3UdUJ4os4HM2pM73KQTf3n0k+z1r4106w7ZBNUyIDf/N2bgmBKZrJynB98aYftbBDBcJYzhguL9DmWVe6UHpsmKH7j0EXlAOzptOcGwJ+x+uzkcm1K/khfGcW4DjeqCXDkG6ftUaXEf2Ek/TIZy5mf0jB2+P/hialcmnB4jiLzByV4ItJnaezAKpIBpwnGt3LNRGmL0GJOMVc9r7ExvT3B1nQRR/KNt3PjPWGqiuiGT/gCa3iURrvZR2bsiVTGVipBTWpMeNrmkFR6AbhMRhvPc5PlE6rth1auW90pIaGDo7mQJAh0blvITyyuh5zBE7sJbYsf1pVLzVeM6n4pHESLGcCluinFTZ7Chlg/13zonz39GhNICtG9fMod38kzoIUYMLWVLoGSyb7rDxQnnUCP5I1G2hgbl4zHA/akpXJfg5F833ypCjDo7/Ho5cfGIxveBp/F8QnvIXMXTltSfm0Gpi3fRkf4PPZ/1TPl8UDApQx7+gGjpI7MlQ2hKqBT4Wz1btKG1gokE2TrgBU2XfDgD1vP3Fwt0PrUS5xN7MulE3jrWxuDUK0BDcHzzoRGcrigvTF8Fflo/V8vhsAWNd8qGzo7zNhUTb8QjHfMypcSltrzcTA4KDHMi02FwJjtugOSoUj72mbJEivf/Xuqk4IEiZEjldNCId2FPHoGHofOvvk0y0AqjWpRoHO3k8nIvQf/8B0qPXZ508KWRiFDC3OCUPvAOLlH+1Kz/F3PtADInCVrUt2nqb5AqpmxyGVXvrnxPusRJ1F2PXHlQBO+9Ai09qb7c6FqNeX0lm082mcp+5U1hx6yhItuGv+aKN+qiRgcX1kxkceyoVGOgyNkDGPGeZLXQzGhnwaPurw7RclZ hZiutQpD aC6Rgi2cOK3ZLb2yGJs1jNCBH2K4sMbzotEsYIR5eM4RJcBWPJ7dsIgjlfHIoi7vZ2GIs1GUhBFCcnwI+B/HCkwfojR9dsyrzjpCDK+13GqnEXTFjxSEX+IC2nG9+0+6mTcw8B32hUzUoQZtFvZWyjTgxBeqetMFveLU4El86J0VTmgZMP730F0FAM76tUIK5oCwqVp1959oTmdvubUkoLcSO01//XYg0+xhu/Fagg6JOyArxD+DGvSqQzYGPTgXFAV3wny0monLD87BeSgZA+1gb5YG+AFsNBBg87dC2Uxhiebci30dUqMLi0wRQ9E1aHAfj11Ec8BvLxYjjnUtIJ3FP+j8w84NmezjqpsBZuMVbhcpMefBfx2yBHw== 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: We want to protect vmcore modifications from concurrent opening of the vmcore, and also serialize vmcore modiciations. Let's convert the spinlock into a mutex, because some of the operations we'll be protecting might sleep (e.g., memory allocations) and might take a bit longer. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index b52d85f8ad59..110ce193d20f 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -62,7 +62,8 @@ core_param(novmcoredd, vmcoredd_disabled, bool, 0); /* Device Dump Size */ static size_t vmcoredd_orig_sz; -static DEFINE_SPINLOCK(vmcore_cb_lock); +static DEFINE_MUTEX(vmcore_mutex); + DEFINE_STATIC_SRCU(vmcore_cb_srcu); /* List of registered vmcore callbacks. */ static LIST_HEAD(vmcore_cb_list); @@ -72,7 +73,7 @@ static bool vmcore_opened; void register_vmcore_cb(struct vmcore_cb *cb) { INIT_LIST_HEAD(&cb->next); - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); list_add_tail(&cb->next, &vmcore_cb_list); /* * Registering a vmcore callback after the vmcore was opened is @@ -80,13 +81,13 @@ void register_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback registration\n"); - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); } EXPORT_SYMBOL_GPL(register_vmcore_cb); void unregister_vmcore_cb(struct vmcore_cb *cb) { - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); list_del_rcu(&cb->next); /* * Unregistering a vmcore callback after the vmcore was opened is @@ -95,7 +96,7 @@ void unregister_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback unregistration\n"); - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); synchronize_srcu(&vmcore_cb_srcu); } @@ -120,9 +121,9 @@ static bool pfn_is_ram(unsigned long pfn) static int open_vmcore(struct inode *inode, struct file *file) { - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); vmcore_opened = true; - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); return 0; } From patchwork Fri Oct 25 15:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850919 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 43159D0C61F for ; Fri, 25 Oct 2024 15:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D03C26B0088; Fri, 25 Oct 2024 11:12:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB37E6B0089; Fri, 25 Oct 2024 11:12:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7BB06B008A; Fri, 25 Oct 2024 11:12:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 99C2E6B0088 for ; Fri, 25 Oct 2024 11:12:10 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A7157A0B0F for ; Fri, 25 Oct 2024 15:11:34 +0000 (UTC) X-FDA: 82712464590.21.D11114D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id EFEDF1C000C for ; Fri, 25 Oct 2024 15:11:59 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G3qmtLVM; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1729868975; 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=5pKboAP4By7PRQHzx/JKVUBvBNHAppZRg9bKS5h/5DI=; b=4MeY0WcYWdyXec8ijfu6hRjm4rvG7xJHPXJudaNCJHOqmneUfl2tCQL9iXvlGDo1HCu0mp PoqraHx/t63+BgdKhJu+iF9BK7OIT8wLaaHQGUpSxyabN8XIxjqFEENvjQra4G6uQ9UeQr Ck8igN4B6UgCCMDsWziObG39nt1ZGwo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729868975; a=rsa-sha256; cv=none; b=R7yfU6lnMfRsESsq5gdmRUozQpNKAkjxIqUEwbYVTVMwjD1M3/5X0MliV5SP+XS1SKeSMg JZbEShRVQjE+KDVsfg86Kt7pZGYzTyQCA7VHU2bKMwKqtQjxqD1pQwjzYZZdFM/EXZRPte eRd0v92MGy9UOEe8StNoq+AVcx5Fpfo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G3qmtLVM; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869127; 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=5pKboAP4By7PRQHzx/JKVUBvBNHAppZRg9bKS5h/5DI=; b=G3qmtLVMI5ATiX7PDk5iWiljrHLCQ0zd0iagYyTSS6MqmcbOcyzzPbZi5VQcy/fcZ6uYhI t4V1p0ZV1RZ1GKgdaX1d0v/zQT7zBVACINVUz5FYIuItqvVdF5ROBsQiJJ4RQGftOL3lHM RQQcKVtsgD8GHPwtOqyEnXmMWUYKWcg= Received: from mx-prod-mc-03.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-505-2i6VTHzzNouTjIokigDSJA-1; Fri, 25 Oct 2024 11:12:04 -0400 X-MC-Unique: 2i6VTHzzNouTjIokigDSJA-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4B3F51955F3F; Fri, 25 Oct 2024 15:12:02 +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 7CD01300018D; Fri, 25 Oct 2024 15:11:53 +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 02/11] fs/proc/vmcore: replace vmcoredd_mutex by vmcore_mutex Date: Fri, 25 Oct 2024 17:11:24 +0200 Message-ID: <20241025151134.1275575-3-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-Queue-Id: EFEDF1C000C X-Stat-Signature: 9g7w4k5od8dy6kbkrz5wxoi3n4mhptiy X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729869119-8994 X-HE-Meta: U2FsdGVkX1+UJ5Zm5Mdb0F5yTilb5YFTxDXbynd3bRzA15WagN+7C2Pv8HO1/AsyPlGQqY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8J+dSSNb5Xrr/CyoWlKctggP8scn2k2jAwOh2K94tO8WhVZLQrZAYn+0uoVUH2r1QoLolKqs/FyeRglfpBzXk2IyJhjn9DRs3H5jC55NvWdvCwbdAUNpWKz+D34bi0VzjJCI9iW5hBRIP3IepsrMxpj5XHbGSlV5+SJX9SPy6/msH2QNsd3ZdM76rwOtRwDR2hku05MIE397wzDyTAL+QlXXWg== 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 use our new mutex instead. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 110ce193d20f..b91c304463c9 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -53,7 +53,6 @@ static struct proc_dir_entry *proc_vmcore; #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP /* Device Dump list and mutex to synchronize access to list */ static LIST_HEAD(vmcoredd_list); -static DEFINE_MUTEX(vmcoredd_mutex); static bool vmcoredd_disabled; core_param(novmcoredd, vmcoredd_disabled, bool, 0); @@ -248,7 +247,7 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) size_t tsz; char *buf; - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); @@ -269,7 +268,7 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) } out_unlock: - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); return ret; } @@ -283,7 +282,7 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, size_t tsz; char *buf; - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); @@ -306,7 +305,7 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, } out_unlock: - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); return ret; } #endif /* CONFIG_MMU */ @@ -1517,9 +1516,9 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) dump->size = data_size; /* Add the dump to driver sysfs list */ - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_add_tail(&dump->list, &vmcoredd_list); - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); vmcoredd_update_size(data_size); return 0; @@ -1537,7 +1536,7 @@ EXPORT_SYMBOL(vmcore_add_device_dump); static void vmcore_free_device_dumps(void) { #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); while (!list_empty(&vmcoredd_list)) { struct vmcoredd_node *dump; @@ -1547,7 +1546,7 @@ static void vmcore_free_device_dumps(void) vfree(dump->buf); vfree(dump); } - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ } From patchwork Fri Oct 25 15:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850920 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 5BA20D0BB56 for ; Fri, 25 Oct 2024 15:12:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED8436B008A; Fri, 25 Oct 2024 11:12:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E87EA6B008C; Fri, 25 Oct 2024 11:12:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4F666B0092; Fri, 25 Oct 2024 11:12:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B495F6B008A for ; Fri, 25 Oct 2024 11:12:20 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6C073120CAC for ; Fri, 25 Oct 2024 15:12:02 +0000 (UTC) X-FDA: 82712464884.06.DAF9F98 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 174894001E for ; Fri, 25 Oct 2024 15:11:50 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Rqj5EET6; spf=pass (imf07.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=1729868983; 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=RBGqG14Ir1TauPvJbSz3jQOA9+mQRgCc4BCTlJgnkuA=; b=M/cC88xADEA+SBW4hGkMsoRSJSiK7Vi0FsO6D/pOUuMbDuEEvC8Y+R/yVKdcqNHogpw1AB WOQtD3OrGxr3vlshZhZTBSgFdOlqY4r0tev9WAPz8Rplwdf93ayI6W9dz9fQdjw8JagFF5 rCWxtaykFF2NViXA/f8WfsZmP69nRWw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729868983; a=rsa-sha256; cv=none; b=8mChhsXGyAE6ACC6h+HzYzD27z2hzLNztBcY614hY1wLKydi3YyNv9Lan/6KoRIk8qdU/Q JhONgXtUproDeDml4PX4dY6M14ouSrYSRFwi+5uj2GbdbXYz9gukPVCRg0DlvwsYQUp/vA Jf+Ylx3pML5dNXC+O0JGY3MLDrRu8eA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Rqj5EET6; spf=pass (imf07.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869137; 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=RBGqG14Ir1TauPvJbSz3jQOA9+mQRgCc4BCTlJgnkuA=; b=Rqj5EET6GQwa0uXiipITubJYJzWfk20EteUrsW8ZAGEyP17keweeL/LyCahCAmY/ZfpakE Xj1vnyiAiGLhpWNrIJPw2Cra3uB5W0xLTltnwF26YHuEt5KfmcfneAbEA6EmCzffcAp/St AYqw8rJUf6ZS4U1sX4gszfJcHXMR3T0= Received: from mx-prod-mc-01.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-602-pkIUU_7mPiOuJegdS3U3rg-1; Fri, 25 Oct 2024 11:12:13 -0400 X-MC-Unique: pkIUU_7mPiOuJegdS3U3rg-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C5211955F43; Fri, 25 Oct 2024 15:12:10 +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 AF463300018D; Fri, 25 Oct 2024 15:12:02 +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 03/11] fs/proc/vmcore: disallow vmcore modifications after the vmcore was opened Date: Fri, 25 Oct 2024 17:11:25 +0200 Message-ID: <20241025151134.1275575-4-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 174894001E X-Stat-Signature: n5gfz4sexbtgxwi5t5wk3x3n7hw1w9kf X-HE-Tag: 1729869110-253758 X-HE-Meta: U2FsdGVkX1/lTiUj64rXjFXqkkdiKOBAxphNkLsjTM0RKmbuBhMHoKI9vPkKTPOMufEzRRFZAK9fFDSm0pudjcj11da9W4jVCEXzlRjwdC85NJOqLNw1vdduM2G6d/xYSJCQ71uOByKxft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FoH7liuAWLtvQTGI7aNT7ukKCgaAg0yhAd5ZAu7hluoCZuD7s98zBthHcflaq0YnCn1Pwtm552Hn1clgMoLS0Wv/nNITTIWmFU5js2IuZYinU= 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 protect all vmcore modifications by the vmcore_mutex and disallow vmcore modifications after the vmcore was opened: modifications would no longer be safe. Properly synchronize against concurrent opening of the vmcore. As a nice side-effect, we now properly protect concurrent vmcore modifications. No need to grab the mutex during mmap()/read(): after we opened the vmcore, modifications are impossible. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index b91c304463c9..6371dbaa21be 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -243,33 +243,27 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) { struct vmcoredd_node *dump; u64 offset = 0; - int ret = 0; size_t tsz; char *buf; - mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); buf = dump->buf + start - offset; - if (copy_to_iter(buf, tsz, iter) < tsz) { - ret = -EFAULT; - goto out_unlock; - } + if (copy_to_iter(buf, tsz, iter) < tsz) + return -EFAULT; size -= tsz; start += tsz; /* Leave now if buffer filled already */ if (!size) - goto out_unlock; + return 0; } offset += dump->size; } -out_unlock: - mutex_unlock(&vmcore_mutex); - return ret; + return 0; } #ifdef CONFIG_MMU @@ -278,20 +272,16 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, { struct vmcoredd_node *dump; u64 offset = 0; - int ret = 0; size_t tsz; char *buf; - mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); buf = dump->buf + start - offset; if (remap_vmalloc_range_partial(vma, dst, buf, 0, - tsz)) { - ret = -EFAULT; - goto out_unlock; - } + tsz)) + return -EFAULT; size -= tsz; start += tsz; @@ -299,14 +289,12 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, /* Leave now if buffer filled already */ if (!size) - goto out_unlock; + return 0; } offset += dump->size; } -out_unlock: - mutex_unlock(&vmcore_mutex); - return ret; + return 0; } #endif /* CONFIG_MMU */ #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ @@ -1482,6 +1470,10 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) return -EINVAL; } + /* We'll recheck under lock later. */ + if (data_race(vmcore_opened)) + return -EBUSY; + if (!data || !strlen(data->dump_name) || !data->vmcoredd_callback || !data->size) return -EINVAL; @@ -1515,12 +1507,16 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) dump->buf = buf; dump->size = data_size; - /* Add the dump to driver sysfs list */ + /* Add the dump to driver sysfs list and update the elfcore hdr */ mutex_lock(&vmcore_mutex); - list_add_tail(&dump->list, &vmcoredd_list); - mutex_unlock(&vmcore_mutex); + if (vmcore_opened) { + ret = -EBUSY; + goto out_err; + } + list_add_tail(&dump->list, &vmcoredd_list); vmcoredd_update_size(data_size); + mutex_unlock(&vmcore_mutex); return 0; out_err: From patchwork Fri Oct 25 15:11:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850921 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 79066D0BB56 for ; Fri, 25 Oct 2024 15:12:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CE476B0092; Fri, 25 Oct 2024 11:12:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07E926B0095; Fri, 25 Oct 2024 11:12:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E88936B0096; Fri, 25 Oct 2024 11:12:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CBB786B0092 for ; Fri, 25 Oct 2024 11:12:27 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CDA7FA09ED for ; Fri, 25 Oct 2024 15:11:51 +0000 (UTC) X-FDA: 82712465472.05.281F4CD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 53D5980010 for ; Fri, 25 Oct 2024 15:11:48 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gQva7K9X; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869020; a=rsa-sha256; cv=none; b=Tax/SOFdN3SNvjDwlmqn5LRPnEx7PwVtsAQF/D4C0JOzMyYokkKs7MHadC5IGJO/lzCdop Z/6NCx0PP/4oHqbDa6mcc5mVcpcsoyxK3nMqez/8TnGbcL5rWPkVD4MO3MptwwetGGkQzu g7VPQEwMakeN7lwPcNvkXKAeKyp5IV8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gQva7K9X; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869020; 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=D6QGok1SHO7tWBONbTK+qNFzpgcjUP8FVLCibVkMqhw=; b=8X9FInNGurUxVe7o365rPnt+W57SR6zdXpPaqwOWyW26MwvOx8kVSnX41EFcXtTKKJI+G0 bwWHPOTNvL5+ZiuikoFoP0oQS9mKTticp12RcW7UPYsHsbdN17YABfOrTwzidsfnGVX/Om ukCoBtHzWaJpJPDqs06dqIh1QRqe4JI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869145; 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=D6QGok1SHO7tWBONbTK+qNFzpgcjUP8FVLCibVkMqhw=; b=gQva7K9XGz+oR8s9WP+3kkPAwKcD4XlfTEeduDYEGgS7WxwtbiZtpo+9ZWHmr5f9LZRZ2O Qa8ldBJwRvo2ztWpvAJjq2pw2zvFyMmWasQhuWI+AckRUJkGMxBBKRwQZEbC6cRB2rpBmy WERYLwkTb5GR5d7dBHZA9t8UOfOGj+o= Received: from mx-prod-mc-01.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-64-m7d72Gv7PTyqbx3Zkb-x3g-1; Fri, 25 Oct 2024 11:12:21 -0400 X-MC-Unique: m7d72Gv7PTyqbx3Zkb-x3g-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65E1F1956077; Fri, 25 Oct 2024 15:12:19 +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 E93DA300018D; Fri, 25 Oct 2024 15:12:10 +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 04/11] fs/proc/vmcore: move vmcore definitions from kcore.h to crash_dump.h Date: Fri, 25 Oct 2024 17:11:26 +0200 Message-ID: <20241025151134.1275575-5-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: rspam12 X-Rspamd-Queue-Id: 53D5980010 X-Stat-Signature: qdknnuqzs3mwuz3kzk7akeq3qqqf1oyr X-Rspam-User: X-HE-Tag: 1729869108-921565 X-HE-Meta: U2FsdGVkX1+l2DfSKiwKJWvaSfULMSfeC+rLNBF2V2ZS5nIjARvnZQkIa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CaxV2k/Ik+ZVoic8I8+SL9XLu4PDPs5c7eG9JLYcqNCXIZZf8+pK7dxYOozOVlPueAOwagxA1AA65s+H5cd+ucb0oaqoxClPs/MWPSJkDnEmntUTnV9WfwgoBgEcvKfJC9mwhRdUiRdrv1iR/UrOmhC7jzUka0ey0g0GVYzHPxGnoaA30mEkJmnOgBhElesqCmZ6sn129YLklF/NHmvZxNd818Y1Cmz4KAntPe9Bfe1w== 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: These defines are not related to /proc/kcore, move them to crash_dump.h instead. While at it, rename "struct vmcore" to "struct vmcore_mem_node", which is a more fitting name. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 20 ++++++++++---------- include/linux/crash_dump.h | 13 +++++++++++++ include/linux/kcore.h | 13 ------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 6371dbaa21be..47652df95202 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -304,10 +304,10 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, */ static ssize_t __read_vmcore(struct iov_iter *iter, loff_t *fpos) { + struct vmcore_mem_node *m = NULL; ssize_t acc = 0, tmp; size_t tsz; u64 start; - struct vmcore *m = NULL; if (!iov_iter_count(iter) || *fpos >= vmcore_size) return 0; @@ -560,8 +560,8 @@ static int vmcore_remap_oldmem_pfn(struct vm_area_struct *vma, static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) { size_t size = vma->vm_end - vma->vm_start; + struct vmcore_mem_node *m; u64 start, end, len, tsz; - struct vmcore *m; start = (u64)vma->vm_pgoff << PAGE_SHIFT; end = start + size; @@ -683,16 +683,16 @@ static const struct proc_ops vmcore_proc_ops = { .proc_mmap = mmap_vmcore, }; -static struct vmcore* __init get_new_element(void) +static struct vmcore_mem_node * __init get_new_element(void) { - return kzalloc(sizeof(struct vmcore), GFP_KERNEL); + 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) { + struct vmcore_mem_node *m; u64 size; - struct vmcore *m; size = elfsz + elfnotesegsz; list_for_each_entry(m, vc_list, list) { @@ -1090,11 +1090,11 @@ 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; loff_t vmcore_off; - struct vmcore *new; ehdr_ptr = (Elf64_Ehdr *)elfptr; phdr_ptr = (Elf64_Phdr*)(elfptr + sizeof(Elf64_Ehdr)); /* PT_NOTE hdr */ @@ -1133,11 +1133,11 @@ 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; loff_t vmcore_off; - struct vmcore *new; ehdr_ptr = (Elf32_Ehdr *)elfptr; phdr_ptr = (Elf32_Phdr*)(elfptr + sizeof(Elf32_Ehdr)); /* PT_NOTE hdr */ @@ -1175,8 +1175,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, static void set_vmcore_list_offsets(size_t elfsz, size_t elfnotes_sz, struct list_head *vc_list) { + struct vmcore_mem_node *m; loff_t vmcore_off; - struct vmcore *m; /* Skip ELF header, program headers and ELF note segment. */ vmcore_off = elfsz + elfnotes_sz; @@ -1587,9 +1587,9 @@ void vmcore_cleanup(void) /* clear the vmcore list. */ while (!list_empty(&vmcore_list)) { - struct vmcore *m; + struct vmcore_mem_node *m; - m = list_first_entry(&vmcore_list, struct vmcore, list); + m = list_first_entry(&vmcore_list, struct vmcore_mem_node, list); list_del(&m->list); kfree(m); } diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index acc55626afdc..5e48ab12c12b 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -114,10 +114,23 @@ struct vmcore_cb { extern void register_vmcore_cb(struct vmcore_cb *cb); extern void unregister_vmcore_cb(struct vmcore_cb *cb); +struct vmcore_mem_node { + struct list_head list; + unsigned long long paddr; + unsigned long long size; + loff_t offset; +}; + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */ +struct vmcoredd_node { + struct list_head list; /* List of dumps */ + void *buf; /* Buffer containing device's dump */ + unsigned int size; /* Size of the buffer */ +}; + /* Device Dump information to be filled by drivers */ struct vmcoredd_data { char dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Unique name of the dump */ diff --git a/include/linux/kcore.h b/include/linux/kcore.h index 86c0f1d18998..9a2fa013c91d 100644 --- a/include/linux/kcore.h +++ b/include/linux/kcore.h @@ -20,19 +20,6 @@ struct kcore_list { int type; }; -struct vmcore { - struct list_head list; - unsigned long long paddr; - unsigned long long size; - loff_t offset; -}; - -struct vmcoredd_node { - struct list_head list; /* List of dumps */ - void *buf; /* Buffer containing device's dump */ - unsigned int size; /* Size of the buffer */ -}; - #ifdef CONFIG_PROC_KCORE void __init kclist_add(struct kcore_list *, void *, size_t, int type); 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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ytlGcGfexnZIjz5NbJkvY1QSARM8VkM71ra/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 */ From patchwork Fri Oct 25 15:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850939 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 ECC73D0BB56 for ; Fri, 25 Oct 2024 15:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 871066B0099; Fri, 25 Oct 2024 11:12:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8201E6B009B; Fri, 25 Oct 2024 11:12:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E946B009C; Fri, 25 Oct 2024 11:12:45 -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 53DB56B0099 for ; Fri, 25 Oct 2024 11:12:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 32642140D6B for ; Fri, 25 Oct 2024 15:12:24 +0000 (UTC) X-FDA: 82712465304.17.837D59C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 27531C000C for ; Fri, 25 Oct 2024 15:12:34 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PgzS1vUx; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1729869085; 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=gIFNVFgavkgVE76rylQBcYDoA1k/9BPXcVZSMfOlsww=; b=dKRJEaOUfIQ/y4jxvTKigK5ys4+Ac83q436ZkWFGnDpp5LMydt+PX6IcE2BKmm1lfacrfg c5RIUkcXgo7jhidU7efqRq4dMI7SDz8aKodQ0o7uzDZtqTjlmVH1L9NtVUv2iT9UC0uofI S7tkmYUilrjzX27gbS8yBlV8KAE2jE0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PgzS1vUx; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1729869085; a=rsa-sha256; cv=none; b=6ePrOpLCTQTw/a2m7SGGQTh85SY+U/tTNXqHBa3JyKYvL6XU4dTJ0Pc5Lec2NUY3BdSl8v raQGhH0ezRnW7fdQFf/vuHt0Q7Mf71HfBL+BLxD2C/GcqaQsJdOBWm+YU6fVOPOtPTlVR9 wTgl4J/SSUZcS8n14TEjPOFAXEPMSpI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869162; 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=gIFNVFgavkgVE76rylQBcYDoA1k/9BPXcVZSMfOlsww=; b=PgzS1vUxZ0uddPT3LqJA+CNRyxkp9Tbpx+Xt+jQ8yrdWsKmhvJxY1KyijuTnBLaqt08YFW 1VR+vh3k0mfD0CUPXsiiFgcR9BWt8L6uNAY/j5BnL2awlch0596Tly6qm3cqV+g5yxagzo OarSny9Ss4VLiQZVw+I7Fd3DP4kS0so= Received: from mx-prod-mc-05.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-271-KbkSjjO5MweDNtywRObLgg-1; Fri, 25 Oct 2024 11:12:38 -0400 X-MC-Unique: KbkSjjO5MweDNtywRObLgg-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1FBE1955F25; Fri, 25 Oct 2024 15:12:36 +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 2F05A300018D; Fri, 25 Oct 2024 15:12:27 +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 06/11] fs/proc/vmcore: factor out freeing a list of vmcore ranges Date: Fri, 25 Oct 2024 17:11:28 +0200 Message-ID: <20241025151134.1275575-7-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: 27531C000C X-Stat-Signature: kbdempww4rp9bqgqzohx5udxawrjxmsk X-HE-Tag: 1729869154-364377 X-HE-Meta: U2FsdGVkX18olD1NER8aUYs14OtCTvuLt5qmthcyjmBkWX1l1hTRFwqb5OXPgeAn6E4kUepHZABffAwSolYfvw7clfGMXGg+gOZ7tuMTfMVyjNkvadw+QPTrPdumj+tOrwqD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IvhOHKa6hy/5WlnhXyi3jAwmFaWvbuZh3rBHFngV9JzNzGjQHrC6jfyvkSpsdN1wxwXh3VqhIkF0NfR9rI3wm5x9PEwZX5GC8T+4aOOPgqOKy2d8= 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 | 9 +-------- include/linux/crash_dump.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 76fdc3fb8c0e..3e90416ee54e 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1568,14 +1568,7 @@ void vmcore_cleanup(void) proc_vmcore = NULL; } - /* clear the vmcore list. */ - while (!list_empty(&vmcore_list)) { - struct vmcore_mem_node *m; - - m = list_first_entry(&vmcore_list, struct vmcore_mem_node, list); - list_del(&m->list); - kfree(m); - } + vmcore_free_mem_nodes(&vmcore_list); free_elfcorebuf(); /* clear vmcore device dump list */ diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index ae77049fc023..722dbcff7371 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -135,6 +135,17 @@ static inline int vmcore_alloc_add_mem_node(struct list_head *list, return 0; } +/* Free a list of vmcore memory nodes. */ +static inline void vmcore_free_mem_nodes(struct list_head *list) +{ + struct vmcore_mem_node *m, *tmp; + + list_for_each_entry_safe(m, tmp, list, list) { + list_del(&m->list); + kfree(m); + } +} + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */ From patchwork Fri Oct 25 15:11:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850940 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 495A6D0BB56 for ; Fri, 25 Oct 2024 15:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D52D66B009D; Fri, 25 Oct 2024 11:12:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D28EC6B009E; Fri, 25 Oct 2024 11:12:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF0E46B009F; Fri, 25 Oct 2024 11:12:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A2ACD6B009D for ; Fri, 25 Oct 2024 11:12:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 49656C0C43 for ; Fri, 25 Oct 2024 15:12:33 +0000 (UTC) X-FDA: 82712466816.02.C643B89 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id EBCA540018 for ; Fri, 25 Oct 2024 15:12:36 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ljj98W6U; spf=pass (imf01.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=1729868967; 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=6hl9c5Yb2sx5GRvpqgpVj1LJUfxGGqj6HUI+5nw39Sc=; b=0m7pw7LKVY3Ui2NsutysokmySKHLaHVa/2qFo1IJfxQ0mVAAURLGZwBXAXYAv40nSjR+tK Y9JUdN1ChfE4Y+QHSRIUXUBplXlTGnr/SlZNQbCHaUA+ZrFk7gDm+HajCd2bEyQB3jvgdS GV0BBAbKaLco9sS7A65m516q0iMRG3E= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ljj98W6U; spf=pass (imf01.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=1729868967; a=rsa-sha256; cv=none; b=6/ZBhJn4TNkoWEU6Fipjt1SATGE5sWRwvFdLy6vQA/WzzDsbKbdId3zI/G32BtzpXF7ZhD YtjkHWSsazvMrJAgrbJjOfgK6syplEysIYaeMItnisbFsCIjgQi+qBCSHeUr9TgWuGHz7t CR3EAC0BbaowDwBvdZryKOaCvd4XcqQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869172; 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=6hl9c5Yb2sx5GRvpqgpVj1LJUfxGGqj6HUI+5nw39Sc=; b=Ljj98W6UFSUT5qNKBTbQMi3hCjaMgdS0UMFUwd/lJWqwYVRKvbmUPbSuGxP8+jshugyR/w yELfbaVwPRtjV5zz4VCMJfWia4x8pjsXfwiIEjTCFcPaVEh2gOfKU8zFey1A9dt5zmgVVC wLj5m3H7uzSzTbyBHMbD46sRoIdV0N8= Received: from mx-prod-mc-03.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-692-4fSCEJXAOeah5Ecoqje4TQ-1; Fri, 25 Oct 2024 11:12:47 -0400 X-MC-Unique: 4fSCEJXAOeah5Ecoqje4TQ-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3839D1955F54; Fri, 25 Oct 2024 15:12:45 +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 4B62C30001A9; Fri, 25 Oct 2024 15:12:37 +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 07/11] fs/proc/vmcore: introduce PROC_VMCORE_DEVICE_RAM to detect device RAM ranges in 2nd kernel Date: Fri, 25 Oct 2024 17:11:29 +0200 Message-ID: <20241025151134.1275575-8-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: rspam06 X-Rspamd-Queue-Id: EBCA540018 X-Stat-Signature: qs7hrgs1birdxsq1beed3jr3w6ggu1oz X-Rspam-User: X-HE-Tag: 1729869156-464342 X-HE-Meta: U2FsdGVkX1/I/yTsnoylfhwe2cr2fWjVK/fz/Vk9l3teC1nLkaILxPAgqrAj9qjZae5sabsKeAEWmjpG67LssrXLmAEC94SqbQCPOAIc2k7dxNwQwL8HaWrxUbMKcEGQoJM09+hkG91MGsjTe16G2tByxH5x6s3WvGR+1h8VGvbi1pSFFA7rsohuLdaGqZQITKoek6C5uz0klAb17wci6pyr57noT/kCkrsz/lbE3KLKnM7puRoWAwG/XPaQJtnbIW1E2rpEHvxog9MVNKUWeFGswUgUhWCiDqxQ7kU4PLw/VT4/zB6wHHWXBmFGTHd+M+S9U8LRLHC8osayd6bbgyXwZ2Z3myo3ocGeqCkKJ1f3ScTQ8qP+Dp+/CFo/qVkchYT0OsvuGOYVpjqd1bVsVXuZY8kUwlO0ttaqZ5ZV1a33PtnyyAlw5DeNfyUM6Ko8RsdGqMd0h8KvrF7vw+3xk5bT6t/FniDbhQYxBidkEQ0YmebTHj18KiDAldhKROVYsR3LRRjTD6OWUI7Oh5drKJBLvU+h9ayddWfpyv+JqbkWP6pE2AmT9H2/raGFX6+S/OSIs+XDYwDvr97cKYCXpFOSzkF08ja7eF4E+hgPrRYKeF2WEGyAK29kZLiteVPT+p8Hcgxf2z8mpNwauTGhZHlSSGcKz5Iep0hI8OjWzrodqLNrlPYn7kdEENKj6YXUT9PsTUdVLo6eG/5Wh3eW/J/9Uj6o3WSclXjblpLdo6ySsn+mrC+nqeAsWUPz/Yuu+wzCD4iEMB9goyP7Y5Ci90ct8isVLgQ0v5KbJMnzGhiRLyOlOYIjAc4grMwDJJzLsB22pGc0lgNfnfEYd8XqtYaACDpypgEp0fSmd0pHgj9xgSJpu9hnfTvBZfsShZdwIAmm3kS/f1xfh7ERjJCUchxRXrYHDbCXFavM5DqhPaqkspycIjV3LvIFQA+8CzR0Eq0ch8As1VUojAcOzkb kYhiGNI1 NV5zCGLYUrp/NpGhs15i2VkdnfKO+tU5dHCYzFjmejZ5nSwxgGK3OMSQd4dUC9/l5pQBop/ml7Ca2BWeudDc1hZLezZyWHpULqu97OcwngpxLU0/TdlX56NjI3XtWktG+tKR4IeBa8RGOkjC0TuXrVp1UX8AvCUi7zfs4XaHCRnuRNbG7QjpuSQARZtNiaPsmoywU+w9C6IgGagD9A1dtiYoJxL7B45uLgEy0dXjIj+iQxkixVNqfL0fRLTpGbbN9Inj5lUEV8hmwirnTvc4jFORx7ru9wwfchp6FwLAcZYfucf87Cu+Vp2tbwxANkUX7qQwGlwk39+vMAnWzl1+oKJDNeOkuiTTrIN3ViXH99BHanilEGhwr4ys2sQ== 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: s390 allocates+prepares the elfcore hdr in the dump (2nd) kernel, not in the crashed kernel. RAM provided by memory devices such as virtio-mem can only be detected using the device driver; when vmcore_init() is called, these device drivers are usually not loaded yet, or the devices did not get probed yet. Consequently, on s390 these RAM ranges will not be included in the crash dump, which makes the dump partially corrupt and is unfortunate. Instead of deferring the vmcore_init() call, to an (unclear?) later point, let's reuse the vmcore_cb infrastructure to obtain device RAM ranges as the device drivers probe the device and get access to this information. Then, we'll add these ranges to the vmcore, adding more PT_LOAD entries and updating the offsets+vmcore size. Use Kconfig tricks to include this code automatically only if (a) there is a device driver compiled that implements the callback (PROVIDE_PROC_VMCORE_DEVICE_RAM) and; (b) the architecture actually needs this information (NEED_PROC_VMCORE_DEVICE_RAM). The current target use case is s390, which only creates an elf64 elfcore, so focusing on elf64 is sufficient. Signed-off-by: David Hildenbrand --- fs/proc/Kconfig | 25 ++++++ fs/proc/vmcore.c | 156 +++++++++++++++++++++++++++++++++++++ include/linux/crash_dump.h | 9 +++ 3 files changed, 190 insertions(+) diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index d80a1431ef7b..1e11de5f9380 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -61,6 +61,31 @@ config PROC_VMCORE_DEVICE_DUMP as ELF notes to /proc/vmcore. You can still disable device dump using the kernel command line option 'novmcoredd'. +config PROVIDE_PROC_VMCORE_DEVICE_RAM + def_bool n + +config NEED_PROC_VMCORE_DEVICE_RAM + def_bool n + +config PROC_VMCORE_DEVICE_RAM + def_bool y + depends on PROC_VMCORE + depends on NEED_PROC_VMCORE_DEVICE_RAM + depends on PROVIDE_PROC_VMCORE_DEVICE_RAM + help + If the elfcore hdr is allocated and prepared by the dump kernel + ("2nd kernel") instead of the crashed kernel, RAM provided by memory + devices such as virtio-mem will not be included in the dump + image, because only the device driver can properly detect them. + + With this config enabled, these RAM ranges will be queried from the + device drivers once the device gets probed, so they can be included + in the crash dump. + + Relevant architectures should select NEED_PROC_VMCORE_DEVICE_RAM + and relevant device drivers should select + PROVIDE_PROC_VMCORE_DEVICE_RAM. + config PROC_SYSCTL bool "Sysctl support (/proc/sys)" if EXPERT depends on PROC_FS diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 3e90416ee54e..c332a9a4920b 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -69,6 +69,8 @@ static LIST_HEAD(vmcore_cb_list); /* Whether the vmcore has been opened once. */ static bool vmcore_opened; +static void vmcore_process_device_ram(struct vmcore_cb *cb); + void register_vmcore_cb(struct vmcore_cb *cb) { INIT_LIST_HEAD(&cb->next); @@ -80,6 +82,8 @@ void register_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback registration\n"); + else if (cb->get_device_ram) + vmcore_process_device_ram(cb); mutex_unlock(&vmcore_mutex); } EXPORT_SYMBOL_GPL(register_vmcore_cb); @@ -1511,6 +1515,158 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) EXPORT_SYMBOL(vmcore_add_device_dump); #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +static int vmcore_realloc_elfcore_buffer_elf64(size_t new_size) +{ + char *elfcorebuf_new; + + if (WARN_ON_ONCE(new_size < elfcorebuf_sz)) + return -EINVAL; + if (get_order(elfcorebuf_sz_orig) == get_order(new_size)) { + elfcorebuf_sz_orig = new_size; + return 0; + } + + elfcorebuf_new = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(new_size)); + if (!elfcorebuf_new) + return -ENOMEM; + memcpy(elfcorebuf_new, elfcorebuf, elfcorebuf_sz); + free_pages((unsigned long)elfcorebuf, get_order(elfcorebuf_sz_orig)); + elfcorebuf = elfcorebuf_new; + elfcorebuf_sz_orig = new_size; + return 0; +} + +static void vmcore_reset_offsets_elf64(void) +{ + Elf64_Phdr *phdr_start = (Elf64_Phdr *)(elfcorebuf + sizeof(Elf64_Ehdr)); + loff_t vmcore_off = elfcorebuf_sz + elfnotes_sz; + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)elfcorebuf; + Elf64_Phdr *phdr; + int i; + + for (i = 0, phdr = phdr_start; i < ehdr->e_phnum; i++, phdr++) { + u64 start, end; + + /* + * After merge_note_headers_elf64() we should only have a single + * PT_NOTE entry that starts immediately after elfcorebuf_sz. + */ + if (phdr->p_type == PT_NOTE) { + phdr->p_offset = elfcorebuf_sz; + continue; + } + + start = rounddown(phdr->p_offset, PAGE_SIZE); + end = roundup(phdr->p_offset + phdr->p_memsz, PAGE_SIZE); + phdr->p_offset = vmcore_off + (phdr->p_offset - start); + vmcore_off = vmcore_off + end - start; + } + set_vmcore_list_offsets(elfcorebuf_sz, elfnotes_sz, &vmcore_list); +} + +static int vmcore_add_device_ram_elf64(struct list_head *list, size_t count) +{ + Elf64_Phdr *phdr_start = (Elf64_Phdr *)(elfcorebuf + sizeof(Elf64_Ehdr)); + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)elfcorebuf; + struct vmcore_mem_node *cur; + Elf64_Phdr *phdr; + size_t new_size; + int rc; + + if ((Elf32_Half)(ehdr->e_phnum + count) != ehdr->e_phnum + count) { + pr_err("Kdump: too many device ram ranges\n"); + return -ENOSPC; + } + + /* elfcorebuf_sz must always cover full pages. */ + new_size = sizeof(Elf64_Ehdr) + + (ehdr->e_phnum + count) * sizeof(Elf64_Phdr); + new_size = roundup(new_size, PAGE_SIZE); + + /* + * Make sure we have sufficient space to include the new PT_LOAD + * entries. + */ + rc = vmcore_realloc_elfcore_buffer_elf64(new_size); + if (rc) { + pr_err("Kdump: resizing elfcore failed\n"); + return rc; + } + + /* Modify our used elfcore buffer size to cover the new entries. */ + elfcorebuf_sz = new_size; + + /* Fill the added PT_LOAD entries. */ + phdr = phdr_start + ehdr->e_phnum; + list_for_each_entry(cur, list, list) { + WARN_ON_ONCE(!IS_ALIGNED(cur->paddr | cur->size, PAGE_SIZE)); + elfcorehdr_fill_device_ram_ptload_elf64(phdr, cur->paddr, cur->size); + + /* p_offset will be adjusted later. */ + phdr++; + ehdr->e_phnum++; + } + list_splice_tail(list, &vmcore_list); + + /* We changed elfcorebuf_sz and added new entries; reset all offsets. */ + vmcore_reset_offsets_elf64(); + + /* Finally, recalculated the total vmcore size. */ + vmcore_size = get_vmcore_size(elfcorebuf_sz, elfnotes_sz, + &vmcore_list); + proc_vmcore->size = vmcore_size; + return 0; +} + +static void vmcore_process_device_ram(struct vmcore_cb *cb) +{ + unsigned char *e_ident = (unsigned char *)elfcorebuf; + struct vmcore_mem_node *first, *m; + LIST_HEAD(list); + int count; + + if (cb->get_device_ram(cb, &list)) { + pr_err("Kdump: obtaining device ram ranges failed\n"); + return; + } + count = list_count_nodes(&list); + if (!count) + return; + + /* We only support Elf64 dumps for now. */ + if (WARN_ON_ONCE(e_ident[EI_CLASS] != ELFCLASS64)) { + pr_err("Kdump: device ram ranges only support Elf64\n"); + goto out_free; + } + + /* + * For some reason these ranges are already know? Might happen + * with unusual register->unregister->register sequences; we'll simply + * sanity check using the first range. + */ + first = list_first_entry(&list, struct vmcore_mem_node, list); + list_for_each_entry(m, &vmcore_list, list) { + unsigned long long m_end = m->paddr + m->size; + unsigned long long first_end = first->paddr + first->size; + + if (first->paddr < m_end && m->paddr < first_end) + goto out_free; + } + + /* If adding the mem nodes succeeds, they must not be freed. */ + if (!vmcore_add_device_ram_elf64(&list, count)) + return; +out_free: + vmcore_free_mem_nodes(&list); +} +#else /* !CONFIG_PROC_VMCORE_DEVICE_RAM */ +static void vmcore_process_device_ram(struct vmcore_cb *cb) +{ +} +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ + /* Free all dumps in vmcore device dump list */ static void vmcore_free_device_dumps(void) { diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 722dbcff7371..8e581a053d7f 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -20,6 +20,8 @@ extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size); extern void elfcorehdr_free(unsigned long long addr); extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos); extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos); +void elfcorehdr_fill_device_ram_ptload_elf64(Elf64_Phdr *phdr, + unsigned long long paddr, unsigned long long size); extern int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot); @@ -99,6 +101,12 @@ static inline void vmcore_unusable(void) * indicated in the vmcore instead. For example, a ballooned page * contains no data and reading from such a page will cause high * load in the hypervisor. + * @get_device_ram: query RAM ranges that can only be detected by device + * drivers, such as the virtio-mem driver, so they can be included in + * the crash dump on architectures that allocate the elfcore hdr in the dump + * ("2nd") kernel. Indicated RAM ranges may contain holes to reduce the + * total number of ranges; such holes can be detected using the pfn_is_ram + * callback just like for other RAM. * @next: List head to manage registered callbacks internally; initialized by * register_vmcore_cb(). * @@ -109,6 +117,7 @@ static inline void vmcore_unusable(void) */ struct vmcore_cb { bool (*pfn_is_ram)(struct vmcore_cb *cb, unsigned long pfn); + int (*get_device_ram)(struct vmcore_cb *cb, struct list_head *list); struct list_head next; }; extern void register_vmcore_cb(struct vmcore_cb *cb); From patchwork Fri Oct 25 15:11:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850941 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 8A6C6D0BB56 for ; Fri, 25 Oct 2024 15:13:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 207D56B009F; Fri, 25 Oct 2024 11:13:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B79D6B00A0; Fri, 25 Oct 2024 11:13:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07F7D6B00A1; Fri, 25 Oct 2024 11:13:04 -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 DCD746B009F for ; Fri, 25 Oct 2024 11:13:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EDE1340AD1 for ; Fri, 25 Oct 2024 15:12:52 +0000 (UTC) X-FDA: 82712466144.20.6D28C91 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id DC8F24001A for ; Fri, 25 Oct 2024 15:12:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OnNY6ntw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869129; a=rsa-sha256; cv=none; b=I0HCGgTk14D3Y9TjrrgH8a1GdGibbFFhcJ7L1YGlIFW3GU/8LcTi+agBGgA1IxMqxtmjKR itebxWiDS6r3po4Am4KALpY5j5THXDQ9UURNpOSgdJ7CNryKSJJBTw3ANkja84ag+n+6wl R1uQuZxYcVeD5uJVz++umsMEh0igJKs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OnNY6ntw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869129; 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=ACGdF21cKkvnMHoeXpjOJK7M5S4ojlG1Lcv7sY6UCa8=; b=efiLj5udKaNYxd8Q5vA5PAtvA6YRM7OlDIZd9Zrto/HcxcPNjBgrMQaYLwTYFTCJ4RhE9w 02RMsUuusEs5PNH34ujccDSJ6CEo6ajZjS9eJe34HYgXgwo2QYZyWTp4E43oWsJlZsbAyH oYpM+SuRoPPXoHMkFhs1mMUiPgSkowc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869181; 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=ACGdF21cKkvnMHoeXpjOJK7M5S4ojlG1Lcv7sY6UCa8=; b=OnNY6ntwDB+Olu4i4hvV0IllRDENwj64Nj+JLUC1/Gi8m5ycVYXpU20vsKxvk1Wpl07KBx okcDvQyK18COUcZk9dL+eDffNqrEBtJqRzcL9VCA1ex+6PwzVVtFdv36LN8uU2xWqyHCCd TNmI1gv75HuaOa3Kychz4e4DPGsTSSU= Received: from mx-prod-mc-04.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-640-JyKffLwLP4WOg7IrO6F-yg-1; Fri, 25 Oct 2024 11:12:58 -0400 X-MC-Unique: JyKffLwLP4WOg7IrO6F-yg-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC5061955F35; Fri, 25 Oct 2024 15:12:53 +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 93CD030001A7; Fri, 25 Oct 2024 15:12:45 +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 08/11] virtio-mem: mark device ready before registering callbacks in kdump mode Date: Fri, 25 Oct 2024 17:11:30 +0200 Message-ID: <20241025151134.1275575-9-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-Rspam-User: X-Rspamd-Queue-Id: DC8F24001A X-Rspamd-Server: rspam01 X-Stat-Signature: 6mtzezxtpy68txxo1qma1163squ5skgi X-HE-Tag: 1729869157-892948 X-HE-Meta: U2FsdGVkX1+vJAtR9i5dNLe457lDEn0L9um6WGGfh7PwGFcG5pd5WT2aooIoRwsrXnu2kLwdnSnM5rNGI14pIeVNyAhsetpL8/Z5KutGp0aWNQoDj0GKQCajruXi/iGfqW/8zmqWkfJS0egZ2+oD3bwcTabyIKEhajxBSNZteMXontRuilecCMVCVjxqB9SpNQRHtwNpzQIuPXTG66NIGfVrB6L1om/uhKP/ywVdx9CmJGMHDu1HVPF1VqCLR0Asky/oJm41GKRDjQAItEyHImzLJzDcV1BPJPuqg+RQhrl6Fto+ShPXWJ5N2xKTNC0vUEH8sarXGA+6u2/izQIwSuZOGiuULQrL5H/AkN0Fdtb5+eQD8lGRVC79PjnujXMzu1iawJx0NtNKDCezmO1AE2BbMDZUE92PtJDGboD8n7txGxWV04YT3xIKgd1jPQZfJdn5/p4kH9YWc+FIpxK7RKlPpi1p1zqGFY6DeoI3HdKyQNUUd7hNhHGk/zI7es1/XIe8Zl00MK2vy6ltlYiGITn1gh58wmws0syFW+L9ynAOmbjGVruTmM9+8FRLBQpol1NzC7iK8vP94K4C0QR6BJhOb/V5KuLCC7MdH6l9WPj/TC9fDksvqNFNuCyvE4tiMdb5qFoGKSW3J8Wx44xMbuTJhO+zmsVmXcwx4awMppEdiXgWZqBN1BImOqxX3KJZym/oDtygMfAdigAn97J2fSbkXgq1nxHS9v7AbRW5L/vZ1dsGMXdE5qYmL9B/c0wWkzJo1IwQmKlXVtvTrI2107Em9go/J9ANrdo8URj6n4i07z+kyZaXVAwkB2H00drQQ4AAzQovLbURx886C8cjfY70giaU97Vb4yv1TaPm5Hr+mt/XRIpE3vV3l3sI7nwYsnxVSk+xV9TiNFxJlK01xpjA7gyHTbAp/qz6qb5Si51V2wc8SLSNE9WlX6gZB/Nemtl1rz0c7IY0tR15fgR PSSNQr8W qslwXtfBmGteSK1U5EdalN6Q0/TeIvYQ8EZ60ZS2Ek9tW6dmt+fynYWofT9CfP7wM3GTvdgIcuzLYSQljEDFxqKy3qHxmmLy67Gz8XyvWaz8tu8GddT380wMRL8oXx78ClNdMVzfTaK/KPlZJXwvnGP8yZzJBc6BJiwuhB06inFSX3DCU8v2deb4bS4LnmeVLnjyMFualmGHjZJE8r6hDapySjLXKwpO2yIamxkvss95AJvDFds1YVa0hfjk0UITAFhXLkRKwvfqB0WLgAtji8vl096gk0TV/KR1vmlYmsVf7wMDq0KBSSbLUuSlUuzSpaX9BYEVkjoUhvKs= 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: After the callbacks are registered we may immediately get a callback. So mark the device ready before registering the callbacks. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index b0b871441578..126f1d669bb0 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2648,6 +2648,7 @@ static int virtio_mem_init_hotplug(struct virtio_mem *vm) if (rc) goto out_unreg_pm; + virtio_device_ready(vm->vdev); return 0; out_unreg_pm: unregister_pm_notifier(&vm->pm_notifier); @@ -2729,6 +2730,8 @@ static bool virtio_mem_vmcore_pfn_is_ram(struct vmcore_cb *cb, static int virtio_mem_init_kdump(struct virtio_mem *vm) { + /* We must be prepared to receive a callback immediately. */ + virtio_device_ready(vm->vdev); #ifdef CONFIG_PROC_VMCORE dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n"); vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram; @@ -2870,8 +2873,6 @@ static int virtio_mem_probe(struct virtio_device *vdev) if (rc) goto out_del_vq; - virtio_device_ready(vdev); - /* trigger a config update to start processing the requested_size */ if (!vm->in_kdump) { atomic_set(&vm->config_changed, 1); From patchwork Fri Oct 25 15:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850942 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 30CFBD0C61F for ; Fri, 25 Oct 2024 15:13:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF24C6B00A1; Fri, 25 Oct 2024 11:13:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA29F6B00A2; Fri, 25 Oct 2024 11:13:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6A436B00A3; Fri, 25 Oct 2024 11:13:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8C5A26B00A1 for ; Fri, 25 Oct 2024 11:13:10 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 91A4A120BB1 for ; Fri, 25 Oct 2024 15:12:52 +0000 (UTC) X-FDA: 82712467110.21.DA8E83C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id AEE32C0010 for ; Fri, 25 Oct 2024 15:12:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TTYxUR93; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869148; a=rsa-sha256; cv=none; b=49oTaJl3aTm4qjCMk9/XuEqNRxR6e44nd3xuu8/2vrUivmpSEmuwNHetR9S/rMKE8K0A/j WWVQUSU7NB8kNV0kSep8eKJwBMAn1vp6IU82h6Pwz5HxbeECu9ExdT77CHcfxe6gmPBQZg WWU1GiBElcyxOAHGGltujQ5gPsgKANc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TTYxUR93; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869148; 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=PdMqUIxpls1gNH4eQdrzo/q29zzRB98r4tpBih1lnzQ=; b=Io5l6yQeODTn3KyvlnAGdvK8z7y02oCYsMpvfmmndZbNR5fi+Jwj4WDrmQnWpNbnKO5YdK 1zB9lQfO6ze5lUMqoSR50crQT7ORKDkL+Gxz0Hs/ZMAtksGljGlK4TTFnRHP28RxJyGTpG T+hP6QgNvtBF7lPJXDlBPkATvEQhiV4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869188; 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=PdMqUIxpls1gNH4eQdrzo/q29zzRB98r4tpBih1lnzQ=; b=TTYxUR93kp1msM0gW1NrCDUBJybHOfMr0I051x9XaUukvrwmxa8YEmqVh+uiU9MNY5ff+o W0dPYNhDGDZl1J7R08ZLIogdMwBNfHVrYtfzjs8i/BuGNY+DQMpI5b2d2trR2jXl4XA+Th buwEnQbJOv+blDuOerRwYVmT0CMwxB8= Received: from mx-prod-mc-05.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-642-o3a0P1v0Nd-PreOhqdKZvg-1; Fri, 25 Oct 2024 11:13:03 -0400 X-MC-Unique: o3a0P1v0Nd-PreOhqdKZvg-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2135819560A2; Fri, 25 Oct 2024 15:13:01 +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 5282C300018D; Fri, 25 Oct 2024 15:12:54 +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 09/11] virtio-mem: remember usable region size Date: Fri, 25 Oct 2024 17:11:31 +0200 Message-ID: <20241025151134.1275575-10-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-Rspam-User: X-Stat-Signature: ofe4px6tp13sk7g3k5ayd6997t9if6cc X-Rspamd-Queue-Id: AEE32C0010 X-Rspamd-Server: rspam02 X-HE-Tag: 1729869168-993219 X-HE-Meta: U2FsdGVkX188+5m/gYiZU8b53du3efL5TMQz+rMkf+lA0HYePhcnfolq4zDRKbzawPWjIYfteQlTQnB+CxknI7mzResxEuq7BjF85TtsSHAClPuuXvCVhollLkXF1KnTuEJy9RO9SjVqJKRlyXogQE3nno2l1614iev61gPkrI1DcVxQsujqvklhsnEeLxDbdI+K2OWV+9FHznUovEoPTicEX7unIjGqeqkB6RGvQjh5SbsEp+Atc3fjh4nTi7bnwrVFqWuK5EsEJfogz47ZRXOpAE1TGw1J2vkS0pU/akUpooybE3eUY+QLkKSKPILil1ut4jPb0acqKteZD86cAbUX1SLOsMJhHUItUHw7RWXmQXCC4nKqrVjvvvRq6zsP1mPe2P8RbcsXhL3itwyFKWSb94qQqkpLcdAzCTN6OtJbdZunzVrH55FudG/zTDOchexzBs2AXC+VIy5HWa9lDf+RNtah6yJoyktVjOCH9mIhpH6pF51Azg3U03TrLdqrIH8ScnSw0fHfg9NUH3gaXQgcQuuRYbL0x9T/L1J5aYJx6l2TR9x9iz4JgA+yUS5Orh0zi3lPMzY/PBglSgfgbhkJbkcyD/s4c9bqCcXCIERIhwwfu2aJ94S/QTMcKQW9p4UhchMCdw6SdP04Vjv6BoTrB6HW00MNzBKcmvi3IbAnPYqrWM8A5LuvJj4E6eznQdr6Fos4c5Ynn/8LWmy5x/F7Firj41o5ylvp1A1QEw+0XGlXYBoTUrwRLVSIXRTA+E3YoFeNuAjxnp9G8dRCItAf7fEWQ9eG/DIb+6Ln7s4hgIU3Gzqh8RuS1ypnfMmPNuJipIOr4GQ0wjdMBuoEcSMNthtf3bQt2IKBrjiT94Kcwuik8PQ+3adwM0DgXn3fdKi4a51+HZ0LR/FWGU1vD5evXIDXd3fcWMs9iRuaZKjYwW/zS4wfq7+KMe3THZ8sJnVfhFGzOVZzdfngoTm ksCtJYFP SIHoj4S8EYLtqXcPyUf2yFlfnNFjQ6MtDcfQfiiHNelXf1Pu3Xz4KCNx4eXvnx+gLTHZK1z9BgOL8OiQFm8hrmvH7vSSqhN+k40qiUe8VUJV7hVndUHYA10MQjZrCJrfRZl3myBIZjk7+0hpwMxd7ESacsacvHt20J/zepggnD6qQWvvCp9iBH5SOF68PxE4MbL8rRFkO5zqCeqBJES7HHVLi1ZQn39ZYE4RGSaF2A8fbrrlNvgeChse8egmITBc0r+FEqlfj74Z9sNNDMMpv5RVrzyJFPuum7mhlZPSpsrHzTtYceq3axqc1bI4k3Pm3j6CRuyo5QLWApG8= 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 remember the usable region size, which will be helpful in kdump mode next. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 126f1d669bb0..73477d5b79cf 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -133,6 +133,8 @@ struct virtio_mem { uint64_t addr; /* Maximum region size in bytes. */ uint64_t region_size; + /* Usable region size in bytes. */ + uint64_t usable_region_size; /* The parent resource for all memory added via this device. */ struct resource *parent_resource; @@ -2368,7 +2370,7 @@ static int virtio_mem_cleanup_pending_mb(struct virtio_mem *vm) static void virtio_mem_refresh_config(struct virtio_mem *vm) { const struct range pluggable_range = mhp_get_pluggable_range(true); - uint64_t new_plugged_size, usable_region_size, end_addr; + uint64_t new_plugged_size, end_addr; /* the plugged_size is just a reflection of what _we_ did previously */ virtio_cread_le(vm->vdev, struct virtio_mem_config, plugged_size, @@ -2378,8 +2380,8 @@ static void virtio_mem_refresh_config(struct virtio_mem *vm) /* calculate the last usable memory block id */ virtio_cread_le(vm->vdev, struct virtio_mem_config, - usable_region_size, &usable_region_size); - end_addr = min(vm->addr + usable_region_size - 1, + usable_region_size, &vm->usable_region_size); + end_addr = min(vm->addr + vm->usable_region_size - 1, pluggable_range.end); if (vm->in_sbm) { @@ -2763,6 +2765,8 @@ static int virtio_mem_init(struct virtio_mem *vm) virtio_cread_le(vm->vdev, struct virtio_mem_config, addr, &vm->addr); virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, &vm->region_size); + virtio_cread_le(vm->vdev, struct virtio_mem_config, usable_region_size, + &vm->usable_region_size); /* Determine the nid for the device based on the lowest address. */ if (vm->nid == NUMA_NO_NODE) From patchwork Fri Oct 25 15:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850943 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 AF893D0BB56 for ; Fri, 25 Oct 2024 15:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3673E6B00A3; Fri, 25 Oct 2024 11:13:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F0A46B00A4; Fri, 25 Oct 2024 11:13:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F4D86B00A5; Fri, 25 Oct 2024 11:13:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D85EF6B00A3 for ; Fri, 25 Oct 2024 11:13:16 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0D3B11C68C9 for ; Fri, 25 Oct 2024 15:12:54 +0000 (UTC) X-FDA: 82712467404.30.3870155 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 2551B1A0019 for ; Fri, 25 Oct 2024 15:12:49 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jShXYWPt; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1729869039; 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=mE6UZtvB4UrwqxDxBvXj02Eqawd4qPQUjTyB3c978sA=; b=4O6bJHAz6P94s3ecwo5b4PtR7o6xjsxyXX6mhih7bSJgy/g8vmvMcWmYUvi2OKOrvI2Bta Ah6HLj+c/m8Ii7zY/3u1h/CV6jXl+EWPNrUTiMkwccJwLyV/pVDYIRzTxo/5lfbNVPwGXl 6HZ0ghylEIfPsa8qU5zQGoG7KP5zoZo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869039; a=rsa-sha256; cv=none; b=0Ff5/bE5rBQ/TsBKNY8y+pXkXsG63WUdYTOCQq0MuDbMO36TGn69owHE+pStfgXNDOEUyc EHNA3v1wtqMAUaOrUNpJfGMHvUQoVqcI6uN65dC+GBZnJTTDNbvfBG3qI217X58S67/Frp IwaZJKi6bKEq6lcfe3jjl2DcF+tAEp4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jShXYWPt; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869194; 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=mE6UZtvB4UrwqxDxBvXj02Eqawd4qPQUjTyB3c978sA=; b=jShXYWPtNueJxnQRao9sOto0TZM9uybO9ME4q04+FsmPBh0o70ILCrDJZLOWdeFoGlDM7A 1ROz+woSCMRNprdLg8xEgBopWOA3/W+3PKlU868FPQaZ6SHr1BcMemCOt21vPkJJ9OgZAY wt9YkQreZQ2jqAlBZl4mc3bV+/56ohg= 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-373-3cSc-QklMMuKHb2DIsw0Pg-1; Fri, 25 Oct 2024 11:13:10 -0400 X-MC-Unique: 3cSc-QklMMuKHb2DIsw0Pg-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 A10BC1955D4A; Fri, 25 Oct 2024 15:13:08 +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 86CEF300018D; Fri, 25 Oct 2024 15:13:01 +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 10/11] virtio-mem: support CONFIG_PROC_VMCORE_DEVICE_RAM Date: Fri, 25 Oct 2024 17:11:32 +0200 Message-ID: <20241025151134.1275575-11-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-Stat-Signature: 6mykjtr1sb6pxkw96r14ppww3k5mnczm X-Rspamd-Queue-Id: 2551B1A0019 X-Rspam-User: X-Rspamd-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oN/lOohEyMKEHYbwbumjZK+d62CV+c1MSF7gBAZCmVmjDon3cMw6Cq65zLhxiRbc/avmUgs4TlNCmDzy2J0NxJbp/8pzyp/6wZG/2FSbVDd8JSZ9k34YetEz8Jo0b5SUG4genfTyDAl7dSp9IzSGbkacRKh/v88aI1Po4ZPiQj6V83ME9ap5IhqyDkCXdh3ce34xJFBnyCHEn55rn0rcVb/+U7hQ68O5/iqD1lQYIkdqiM25xY//vMvJZD9torSiPl0hz8z8YsBHRz/FlBdbZ+GOGqxR63h3rAJbj8t5YWTw== 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 implement the get_device_ram() vmcore callback, so architectures that select NEED_PROC_VMCORE_NEED_DEVICE_RAM, like s390 soon, can include that memory in a crash dump. Merge ranges, and process ranges that might contain a mixture of plugged and unplugged, to reduce the total number of ranges. Signed-off-by: David Hildenbrand --- drivers/virtio/Kconfig | 1 + drivers/virtio/virtio_mem.c | 88 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index 2eb747311bfd..60fdaf2c2c49 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -128,6 +128,7 @@ config VIRTIO_MEM depends on MEMORY_HOTREMOVE depends on CONTIG_ALLOC depends on EXCLUSIVE_SYSTEM_RAM + select PROVIDE_PROC_VMCORE_DEVICE_RAM if PROC_VMCORE help This driver provides access to virtio-mem paravirtualized memory devices, allowing to hotplug and hotunplug memory. diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 73477d5b79cf..1ae1199a7617 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2728,6 +2728,91 @@ static bool virtio_mem_vmcore_pfn_is_ram(struct vmcore_cb *cb, mutex_unlock(&vm->hotplug_mutex); return is_ram; } + +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +static int virtio_mem_vmcore_add_device_ram(struct virtio_mem *vm, + struct list_head *list, uint64_t start, uint64_t end) +{ + int rc; + + rc = vmcore_alloc_add_mem_node(list, start, end - start); + if (rc) + dev_err(&vm->vdev->dev, + "Error adding device RAM range: %d\n", rc); + return rc; +} + +static int virtio_mem_vmcore_get_device_ram(struct vmcore_cb *cb, + struct list_head *list) +{ + struct virtio_mem *vm = container_of(cb, struct virtio_mem, + vmcore_cb); + const uint64_t device_start = vm->addr; + const uint64_t device_end = vm->addr + vm->usable_region_size; + uint64_t chunk_size, cur_start, cur_end, plugged_range_start = 0; + LIST_HEAD(tmp_list); + int rc; + + if (!vm->plugged_size) + return 0; + + /* Process memory sections, unless the device block size is bigger. */ + chunk_size = max_t(uint64_t, PFN_PHYS(PAGES_PER_SECTION), + vm->device_block_size); + + mutex_lock(&vm->hotplug_mutex); + + /* + * We process larger chunks and indicate the complete chunk if any + * block in there is plugged. This reduces the number of pfn_is_ram() + * callbacks and mimic what is effectively being done when the old + * kernel would add complete memory sections/blocks to the elfcore hdr. + */ + cur_start = device_start; + for (cur_start = device_start; cur_start < device_end; cur_start = cur_end) { + cur_end = ALIGN_DOWN(cur_start + chunk_size, chunk_size); + cur_end = min_t(uint64_t, cur_end, device_end); + + rc = virtio_mem_send_state_request(vm, cur_start, + cur_end - cur_start); + + if (rc < 0) { + dev_err(&vm->vdev->dev, + "Error querying block states: %d\n", rc); + goto out; + } else if (rc != VIRTIO_MEM_STATE_UNPLUGGED) { + /* Merge ranges with plugged memory. */ + if (!plugged_range_start) + plugged_range_start = cur_start; + continue; + } + + /* Flush any plugged range. */ + if (plugged_range_start) { + rc = virtio_mem_vmcore_add_device_ram(vm, &tmp_list, + plugged_range_start, + cur_start); + if (rc) + goto out; + plugged_range_start = 0; + } + } + + /* Flush any plugged range. */ + if (plugged_range_start) + rc = virtio_mem_vmcore_add_device_ram(vm, &tmp_list, + plugged_range_start, + cur_start); +out: + mutex_unlock(&vm->hotplug_mutex); + if (rc < 0) { + vmcore_free_mem_nodes(&tmp_list); + return rc; + } + list_splice_tail(&tmp_list, list); + return 0; +} +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ #endif /* CONFIG_PROC_VMCORE */ static int virtio_mem_init_kdump(struct virtio_mem *vm) @@ -2737,6 +2822,9 @@ static int virtio_mem_init_kdump(struct virtio_mem *vm) #ifdef CONFIG_PROC_VMCORE dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n"); vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram; +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM + vm->vmcore_cb.get_device_ram = virtio_mem_vmcore_get_device_ram; +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ register_vmcore_cb(&vm->vmcore_cb); return 0; #else /* CONFIG_PROC_VMCORE */ From patchwork Fri Oct 25 15:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850944 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 46043D0BB56 for ; Fri, 25 Oct 2024 15:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC7466B00A5; Fri, 25 Oct 2024 11:13:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D508A6B00A6; Fri, 25 Oct 2024 11:13:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCAA96B00A7; Fri, 25 Oct 2024 11:13:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 96FE06B00A5 for ; Fri, 25 Oct 2024 11:13:23 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D9D641C6912 for ; Fri, 25 Oct 2024 15:13:00 +0000 (UTC) X-FDA: 82712467488.27.6BE614F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 73368160026 for ; Fri, 25 Oct 2024 15:13:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SZ8ZTNH3; spf=pass (imf08.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=1729869124; 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=duV64aDOzPCg70Erai+k0MR4CZFFfLJs/Tny3PQhGqo=; b=I5R8+8qM9Jkv9msQomxizBgCcG4LFdh/b/QRNUcR2zzpH0KKCfup2J+61URD2S/gGxZPbl l4nfblgqPSliy1yvJfzg1t+BC8PE/joSFJ2ztgjGR2WSg7Sf3dyYNkS30VsYg2mCEmVW7X D5cBrV+WPpR1QMENU05ns2WuBHjG304= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SZ8ZTNH3; spf=pass (imf08.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=1729869124; a=rsa-sha256; cv=none; b=MloU7+bwtzS8uXTg54rkhhofPQ/m7oeuKoEllQlqUii+w/7+2J/XWeEuvNdoBtIkj9qKPq LKUYGAlNy/f/lfAJmiwSbyQIaEq7yMHFCHguWwXkQQt84B6M0OVS26GVbIwGF87UW3JUyo ZPwzJAUlaVQzfxqzQhvnGUd6gL4wjz4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869201; 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=duV64aDOzPCg70Erai+k0MR4CZFFfLJs/Tny3PQhGqo=; b=SZ8ZTNH32jWnPI1YGwlhe4guDJlFRSM9ZOOU5udU2HtrvbrKCUYYNDkKwNnsnInQgIeavu 0ajlt5XqGfEPZSh76m5fngw+Hs3yeLPJqyrfqbG4AA1lzeeTEnlS6qT9oRMJe2OS0fJgYj dQ2lSEK31Y8xL/hdD7AmJygxbQayAf0= 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-44-_q3EKHFQNEmGt7K_9EZzAQ-1; Fri, 25 Oct 2024 11:13:19 -0400 X-MC-Unique: _q3EKHFQNEmGt7K_9EZzAQ-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 750F61956096; Fri, 25 Oct 2024 15:13:17 +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 27021300018D; Fri, 25 Oct 2024 15:13:08 +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 11/11] s390/kdump: virtio-mem kdump support (CONFIG_PROC_VMCORE_DEVICE_RAM) Date: Fri, 25 Oct 2024 17:11:33 +0200 Message-ID: <20241025151134.1275575-12-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: 73368160026 X-Stat-Signature: 6ixq47gxk81a8g6t5reprqqmidrx4cu7 X-HE-Tag: 1729869188-553503 X-HE-Meta: U2FsdGVkX19YLkJbSbCicsZupW6Msc20CGPf0Qg17H+5XOAcwu8n4FqfNwS69/PQ9U48Y6habujRbybwDfUFf8qbWkN2+nmYtz3cNjVq9XonvLIsIzLlvj+2F/tkkbZpK7GWYrnDADmi9KfWH5d6q/hwQ59jdPzxJ1pabWmk+zxjDuS5tuBVvJvtguXYWURcB1GslO1v/61Z+wejnMbko8XIcbh12/bvZmCZWL6JhJ/8g+wfk0+VxHFkjmfZ2HVAOVlOMrmF1YcGcbQVBrWsR4Rmt+zWIDa4wj9WtPkglU5Mlzx5P15ZrDc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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 add support for including virtio-mem device RAM in the crash dump, setting NEED_PROC_VMCORE_DEVICE_RAM, and implementing elfcorehdr_fill_device_ram_ptload_elf64(). To avoid code duplication, factor out the code to fill a PT_LOAD entry. Signed-off-by: David Hildenbrand --- arch/s390/Kconfig | 1 + arch/s390/kernel/crash_dump.c | 39 ++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index d339fe4fdedf..d80450d957a9 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -230,6 +230,7 @@ config S390 select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE if PCI select NEED_PER_CPU_EMBED_FIRST_CHUNK + select NEED_PROC_VMCORE_DEVICE_RAM if PROC_VMCORE select NEED_SG_DMA_LENGTH if PCI select OLD_SIGACTION select OLD_SIGSUSPEND3 diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index edae13416196..97b9e71b734d 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -497,6 +497,19 @@ static int get_mem_chunk_cnt(void) return cnt; } +static void fill_ptload(Elf64_Phdr *phdr, unsigned long paddr, + unsigned long vaddr, unsigned long size) +{ + phdr->p_type = PT_LOAD; + phdr->p_vaddr = vaddr; + phdr->p_offset = paddr; + phdr->p_paddr = paddr; + phdr->p_filesz = size; + phdr->p_memsz = size; + phdr->p_flags = PF_R | PF_W | PF_X; + phdr->p_align = PAGE_SIZE; +} + /* * Initialize ELF loads (new kernel) */ @@ -509,14 +522,8 @@ static void loads_init(Elf64_Phdr *phdr, bool os_info_has_vm) if (os_info_has_vm) old_identity_base = os_info_old_value(OS_INFO_IDENTITY_BASE); for_each_physmem_range(idx, &oldmem_type, &start, &end) { - phdr->p_type = PT_LOAD; - phdr->p_vaddr = old_identity_base + start; - phdr->p_offset = start; - phdr->p_paddr = start; - phdr->p_filesz = end - start; - phdr->p_memsz = end - start; - phdr->p_flags = PF_R | PF_W | PF_X; - phdr->p_align = PAGE_SIZE; + fill_ptload(phdr, start, old_identity_base + start, + end - start); phdr++; } } @@ -526,6 +533,22 @@ static bool os_info_has_vm(void) return os_info_old_value(OS_INFO_KASLR_OFFSET); } +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +/* + * Fill PT_LOAD for a physical memory range owned by a device and detected by + * its device driver. + */ +void elfcorehdr_fill_device_ram_ptload_elf64(Elf64_Phdr *phdr, + unsigned long long paddr, unsigned long long size) +{ + unsigned long old_identity_base = 0; + + if (os_info_has_vm()) + old_identity_base = os_info_old_value(OS_INFO_IDENTITY_BASE); + fill_ptload(phdr, paddr, old_identity_base + paddr, size); +} +#endif + /* * Prepare PT_LOAD type program header for kernel image region */