Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3115463pxj; Mon, 17 May 2021 18:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7ZFpcDUGhWwAzR/C6VfM/lIjglSvSzsfqzr1vMHMVklnFm2wChVXDNjlVXTG1xsfhAaOv X-Received: by 2002:aa7:d2d4:: with SMTP id k20mr3655212edr.384.1621300209108; Mon, 17 May 2021 18:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300209; cv=none; d=google.com; s=arc-20160816; b=aEqdx26y34kkjAj6WFHZP7oYHDaBV3lUXclSxT+BndDCmvvSOTK6oHZVuMMqkacLN6 MYeb5e3SKynjMNYygvjJh/fecaJMo8ZjWNJ8Zu65RIJhwdBEdoaZct1Dx6zeWAjTo+5a er+PDKAsuoMcsjGFqjUtLCAX68sQUNa+J4v+b/Zi2RueAhOw5J0gkFNnBCuVVK8XTcYo KVQur3JtrVReAZjfK5Ow45aZbnUg0uq7kzgFeW6s49bfShtSYIFCUXvIvw0bP8sMkK9l QHdOfPqgQS/SEJaNAsBSLGY8yrkfD/fxUtgX1VqThpdl2W4B8d3Jj5obuxoLZxjoh/mr J+Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J5kBX5UC0s/Q3sequSiBoUAkgPr9nvqi+y6/cFdJTPA=; b=hjkizGGaa1uH409mBSUpUYvlbIIyXoUwxzPg+WYKIj1CpkcyMNfZU6t3kwKUKOT1sJ 6cZ1XEwSOtirN5plxukoaK9wmN6tLribplvXIrbLP7QNpd7blZxrnko/S3+CikemXwJW faBQcwzfX50afSfikzjVu8qBy1cRHVA+NZyov6VccctT9DSz6k3bjHUHstvqCP3GmSei lJvKuv3IfcFc1vdnhA6/k7/an18JsVNicMi5QvScuUwvV+ga6tKgbmDg5HUUho8gUd9S MUnviVIuuI/6OtZ4CZlka6EONv6lJLbIfwPECcEcnHsHL7luuz5DS8nj+LoPATMB6WzJ 4mZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lZjQ3ghp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx2si8069781ejb.176.2021.05.17.18.09.46; Mon, 17 May 2021 18:10:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lZjQ3ghp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238436AbhEQObM (ORCPT + 99 others); Mon, 17 May 2021 10:31:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:53200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239218AbhEQO0K (ORCPT ); Mon, 17 May 2021 10:26:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9496861477; Mon, 17 May 2021 14:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260802; bh=KMxVWAlBQGza4iF6X4Bq4LDaMZ+yUZMGxldgOtD4oUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZjQ3ghpPTrYwEVmsEaK88uykO0yCA3wdkE1dsXVnQ0J5IS09tligLgWUkbddpQHF 7A8g+FfxivXYTyPVdHPSZEDXzhYXHBMulKh2o1s0JlFJzGk3ujUJhxGTeURs5R6MK+ dpDWjKTDxo/lTxmunLu/UEIWU3McVESzpVJFtLTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Dan Williams , Baoquan He , Daniel Vetter , Andy Shevchenko , Mauro Carvalho Chehab , Dave Young , Vivek Goyal , Dave Hansen , Keith Busch , Michal Hocko , Qian Cai , Oscar Salvador , Eric Biederman , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Tom Lendacky , Brijesh Singh , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.12 239/363] kernel/resource: make walk_system_ram_res() find all busy IORESOURCE_SYSTEM_RAM resources Date: Mon, 17 May 2021 16:01:45 +0200 Message-Id: <20210517140310.667669664@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Hildenbrand [ Upstream commit 97f61c8f44ec9020708b97a51188170add4f3084 ] Patch series "kernel/resource: make walk_system_ram_res() and walk_mem_res() search the whole tree", v2. Playing with kdump+virtio-mem I noticed that kexec_file_load() does not consider System RAM added via dax/kmem and virtio-mem when preparing the elf header for kdump. Looking into the details, the logic used in walk_system_ram_res() and walk_mem_res() seems to be outdated. walk_system_ram_range() already does the right thing, let's change walk_system_ram_res() and walk_mem_res(), and clean up. Loading a kdump kernel via "kexec -p -s" ... will result in the kdump kernel to also dump dax/kmem and virtio-mem added System RAM now. Note: kexec-tools on x86-64 also have to be updated to consider this memory in the kexec_load() case when processing /proc/iomem. This patch (of 3): It used to be true that we can have system RAM (IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY) only on the first level in the resource tree. However, this is no longer holds for driver-managed system RAM (i.e., added via dax/kmem and virtio-mem), which gets added on lower levels, for example, inside device containers. We have two users of walk_system_ram_res(), which currently only consideres the first level: a) kernel/kexec_file.c:kexec_walk_resources() -- We properly skip IORESOURCE_SYSRAM_DRIVER_MANAGED resources via locate_mem_hole_callback(), so even after this change, we won't be placing kexec images onto dax/kmem and virtio-mem added memory. No change. b) arch/x86/kernel/crash.c:fill_up_crash_elf_data() -- we're currently not adding relevant ranges to the crash elf header, resulting in them not getting dumped via kdump. This change fixes loading a crashkernel via kexec_file_load() and including dax/kmem and virtio-mem added System RAM in the crashdump on x86-64. Note that e.g,, arm64 relies on memblock data and, therefore, always considers all added System RAM already. Let's find all IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY resources, making the function behave like walk_system_ram_range(). Link: https://lkml.kernel.org/r/20210325115326.7826-1-david@redhat.com Link: https://lkml.kernel.org/r/20210325115326.7826-2-david@redhat.com Fixes: ebf71552bb0e ("virtio-mem: Add parent resource for all added "System RAM"") Fixes: c221c0b0308f ("device-dax: "Hotplug" persistent memory for use like normal RAM") Signed-off-by: David Hildenbrand Reviewed-by: Dan Williams Acked-by: Baoquan He Cc: Greg Kroah-Hartman Cc: Dan Williams Cc: Daniel Vetter Cc: Andy Shevchenko Cc: Mauro Carvalho Chehab Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: Dave Hansen Cc: Keith Busch Cc: Michal Hocko Cc: Qian Cai Cc: Oscar Salvador Cc: Eric Biederman Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Tom Lendacky Cc: Brijesh Singh Cc: "Eric W. Biederman" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index 627e61b0c124..4efd6e912279 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -457,7 +457,7 @@ int walk_system_ram_res(u64 start, u64 end, void *arg, { unsigned long flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; - return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, true, + return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, false, arg, func); } -- 2.30.2