Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp528563pxj; Tue, 18 May 2021 08:38:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJmi2kgzA8LsFT7X5jyarwFXG/XnjMfuUxZwBPy53IpqruRhp94kZs3hwZoP7KFHO1dYbH X-Received: by 2002:a5d:8147:: with SMTP id f7mr4616661ioo.135.1621352310267; Tue, 18 May 2021 08:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621352310; cv=none; d=google.com; s=arc-20160816; b=cu1/VPOXFoTeOqUMHgYARZ80ewGGUiJ42VZlCpiGv+epYpx5JktII+5XF+AiYXrMxm nuc927TxbWBMwcKDbaS8WoxSKhWzA6LVkfKi0X6VLFe8ehkuog0dPd8AKVAYsDCNOCTK WoAIEPonk0VtxTPKmppcOWyv5c9oawJJk8UsxeoC3FtakQiC2CbDVR9t1iKhTcwivCNK aeao8eyE67UR/EXgz0uHsE5+Vt6+PW3Qkp5qR0xNMMru2VpZtc8xz96alhnR2uq2xR2f aQDz0eZ8NK9ycklzIXUfRXiAwlCe8KxiDzToJDKlPZs8Qy/cwOl3FmyTuGx5doMUZcS9 M/vA== 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=vsirFADNNPtdIWu8Oe1zchOHCdE4tVskO9fF3K/IY/o=; b=l3Glkv+U9qK8RFAGoJUcBOCYKMTA24+uzpBAk2vls64aNIzWGHLiPn1wxk9G4Yb/vd cDLAGVZBxj4xwcbMsLlt/FdIP8NmAsp0SSEoyJHGkuF5I6YXJp8C1sdSYI7exFWSVgxL LsS2fRGTokHaJyaIm9LqaUThJ5viiWEik5h1gigYP9IygitzYwyqI+ZqPlAKhSquKI41 470q3aC8HDBOs9BeCuqiNuKZ+LUgh6U/yJh8BYMKtgz97QF8UhaGB9N+kw2POr9apSfC IKEQwY47rIW4LkJ3UxgRsLa9UYIIxZdMSZ5Os8O+M4v0GuUr2YbSObv/xSngtuTgjXo8 SZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VX61vrqc; 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 o14si25809321iow.26.2021.05.18.08.38.15; Tue, 18 May 2021 08:38:30 -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=VX61vrqc; 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 S1345514AbhEQP4O (ORCPT + 99 others); Mon, 17 May 2021 11:56:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:37738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244584AbhEQPhD (ORCPT ); Mon, 17 May 2021 11:37:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 878F961941; Mon, 17 May 2021 14:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262427; bh=1qRHNux75ZxngztiyNmBzy8JNZLOeETwbgw2PDNUHaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VX61vrqcVBmueV8uVFJynRt15TYvALPIEQK3LA3f5gD8cJz2M/MC9iORex3EuXRVc byUzYx47vW7UW7EE+9fEuEW7TuhekuA7B7BS66bsp0XbZwYBSCpgMjw62jWwXmihM0 LWTJod05lACkXJKHdSSCQH0opqw4jgRmKXGRRhws= 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.10 185/289] kernel/resource: make walk_system_ram_res() find all busy IORESOURCE_SYSTEM_RAM resources Date: Mon, 17 May 2021 16:01:50 +0200 Message-Id: <20210517140311.334636478@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 3ae2f56cc79d..88a0ed866777 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -450,7 +450,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