From patchwork Wed Dec 4 12:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893716 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 1E776E7716B for ; Wed, 4 Dec 2024 12:55:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93ABC6B00A8; Wed, 4 Dec 2024 07:55:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 913A56B00A9; Wed, 4 Dec 2024 07:55:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F1166B00AA; Wed, 4 Dec 2024 07:55:26 -0500 (EST) 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 450276B00A8 for ; Wed, 4 Dec 2024 07:55:26 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0BAB21A0B12 for ; Wed, 4 Dec 2024 12:55:26 +0000 (UTC) X-FDA: 82857272484.28.0A744BF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id CAA2B40011 for ; Wed, 4 Dec 2024 12:55:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yf690vQH; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@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=1733316912; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=lnFJc5YFI0CKx1fp77IbF1XeJjSZSwlye9mv0hnwC3UP+RzMryXZgE9FLGm/JAKntyBC5Y 4HvoR4WtY78tYC0v2DXoBFsi1IJ9Zke6esMz9t4RmIf0aIZ++eJyC1cGQ8se5xxw5FubFa Yxpdjf15/Y0MsFWzH1TZEUGUr8+9DZY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yf690vQH; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316912; a=rsa-sha256; cv=none; b=GJA1XsskSGejGciO6XiQe7bVGsFahZI1z78V9xDvMNIu6vN80OPAlCyo1JotTJ7O+iRliZ deR6eRwrhSvvmcqaG6wai+Gk7nIhuIH0kSKFZMScV4xme/1GTCvTJgXA7o1rASJYIXwKh5 qzdIQG9Dsel4y2ZyCK+omgjx1bm8Qsk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=Yf690vQHXm6pwynMZHORO2K/EvbovV3uToav/ThH+3SOeuOcMFtJxVGQFza/g+dkrasawe XAwRGAPyzxcRHWhBnEWuutrNpg6e5ChPxZn06t88s8icf1GPlHvcUm+FgdPxt+WYceJv4j 0fOBcwB6IY4qisnXPuu8IDQwTz7AP3Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-169-rq0khAElNROA-sGmkowk5A-1; Wed, 04 Dec 2024 07:55:21 -0500 X-MC-Unique: rq0khAElNROA-sGmkowk5A-1 X-Mimecast-MFC-AGG-ID: rq0khAElNROA-sGmkowk5A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434a90fecfeso49797305e9.1 for ; Wed, 04 Dec 2024 04:55:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316921; x=1733921721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=fily8Fn4cYMypSatmXqQGxvNeHGMNxkbDe0BZcW+TvxSdAdF55uDC6t5my1mIXXYBE luwUxE1xR3smoERCTvZXplcb3oTV5WSDd/6sXSUdRhia2DVaY+867LckMKFJXHUtU43m 4rPuVcAK7DcLeotJCSWNONkSn+r0FgvMmZujFbaiz6Zz2Q79Eo4YzSQ1XY8KGJe9jthQ X6/6nvv2qQuT2sP64zvu1QvZWcZXOZYmHUyO/6kxpcYoVb5XfVe6JLRCu0yud9UPj5Nm 3uZQRiz0UHFNpfXwvg7fErPwHg62DXv9frPgVawqo8vhF9ZVjihc84OnKgH3Y8hbMEr6 oVyA== X-Gm-Message-State: AOJu0YyQdrH1dLqU/fY9w7d/EQFlUmPiH+JPfrQvcm7NBGtYjd/j+Lb8 H3IR4Pb4DTyFAwdvtylaLmtPnuO2R9HcQWfnEeFUj9CrvDzFj69Z0GCiV807AnrchCF7dipz2sk p0TliDK1l06RhEuTxEtItgSyKtdw93rOmIMcurabjWGI6w7N7puc+sKLMFEA= X-Gm-Gg: ASbGncvHB0ug2fCOmBRbc3B8ps7dQxksT1c6Q1aMFi7G8IpsVHszAsSAcD7iRcHLyQ3 G8twmlO9ZFgqdHQnlf/iNCdl4j158utlrwxHBfAsm2X7uYf71U9olC4malbfePrwE3Rp7aqAbPt m5HDjYwDtQsE2pSIHZj9ZS/Ms0ECk2lSley0UNOFSuKLtcvBHtA6q5o0i23MZ3CqCwg44u4lnnt Ka1iXgKt8q5JNzFHdUIRycVC2AsUNRcc0GDO1NK4VVSkdXBzTcqz9xbRlV1O/0OdDoNj3CIQ4Q2 w5KrY3mJPVSUZ8b4GiVfmHwUwUqYB+FgzpI= X-Received: by 2002:a5d:5986:0:b0:382:4115:1ccb with SMTP id ffacd0b85a97d-385fd3cd078mr5363634f8f.7.1733316920737; Wed, 04 Dec 2024 04:55:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVrn7snw7RGTPCk/ImHOMtvIc2Zo//ldD8UcsohYWGwkye1iFqtEVkXPmZASBRCfdSRO6pnw== X-Received: by 2002:a5d:5986:0:b0:382:4115:1ccb with SMTP id ffacd0b85a97d-385fd3cd078mr5363620f8f.7.1733316920347; Wed, 04 Dec 2024 04:55:20 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52c0bc7sm23529155e9.35.2024.12.04.04.55.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:19 -0800 (PST) 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 v2 11/12] virtio-mem: support CONFIG_PROC_VMCORE_DEVICE_RAM Date: Wed, 4 Dec 2024 13:54:42 +0100 Message-ID: <20241204125444.1734652-12-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PMiAqGQ_UYRPaTGdmNDZktKpqr0pFKsFnV1_If_SmpU_1733316921 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: CAA2B40011 X-Rspamd-Server: rspam12 X-Stat-Signature: d1zj3jfotamcq3b7zt7ib4dewq5g34re X-Rspam-User: X-HE-Tag: 1733316912-241117 X-HE-Meta: U2FsdGVkX1/xwl9g9eEisgLSjG+96dkDjhPxtZvrGu4eSU9UTHIrwq6CGyZHd0w9x2lGB2m5jlXw2j2PdSyUq67lPpMaVTnbtmSTwaBlkK9KGxESdhJVDKIHMfWO4xu42uStmEYDAkEKeQAYagmdTkMU/9gqsMat4EhbZ+ob9Y0oCFK7AQrjWjFa6cSt70gNWFaf410yzLqxgeaCg5mUg6ru8psuXwNWcB5ivS1McXicsXzcLgLg7cXxLw0oXK4DT0en7fE6rnzGV4nSHBh46Q7mTZZdYeZJmEG/LBQRRkgQ4Tu422Wzm6Q4vWPeDoBX+7564mOYwZmpnZHz2RQNRy74EMllvrx/gfgu+6fI1sL1xgvaPVIUSm8MhR2IIIcbCClpgaRtiMwoFN+3flY+TtFW9R5EvP0D4jQrjBy7TPzt5OUMNCP6ay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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/virtio_mem.c | 88 +++++++++++++++++++++++++++++++++++++ fs/proc/Kconfig | 1 + 2 files changed, 89 insertions(+) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 73477d5b79cf..8a294b9cbcf6 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_range(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_ranges(&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 */ diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index 5668620ab34d..6ae966c561e7 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -67,6 +67,7 @@ config NEED_PROC_VMCORE_DEVICE_RAM config PROC_VMCORE_DEVICE_RAM def_bool y depends on PROC_VMCORE && NEED_PROC_VMCORE_DEVICE_RAM + depends on VIRTIO_MEM help If the elfcore hdr is allocated and prepared by the dump kernel ("2nd kernel") instead of the crashed kernel, RAM provided by memory