From patchwork Wed Jul 11 07:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141669 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799700ljj; Wed, 11 Jul 2018 00:41:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRDHp2Ln6GAVUQ6tuPhXfEAIgciGtbd9eDQkm3flgx4nLtqDwEXtGf+PsPxq5vqhTKsnzT X-Received: by 2002:a62:d693:: with SMTP id a19-v6mr28707835pfl.248.1531294906254; Wed, 11 Jul 2018 00:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294906; cv=none; d=google.com; s=arc-20160816; b=uhTuJhm2cf4xMvURG9gFy9CMR5WUZgsO+9A3lAE3MCNVRhlbF4mVyo7j2zKjZHlh3F BBSBfYtM/LhctGewO1ioOmQfaRBWe639u4vAtW9f3G0qC2eIzYhyzef/dTkC9XePXK0F nF9FTJLsLdQzlAdPkNn7wDDvya0yKXKvS8OD8s9TGzhV2nrNehi47QVkQdXp9LBC8RnZ BwTDMQjlZN2px+R3//nNjKDDjYCnEd92XX7c9+U/F9yZOq0in27i4s/U2N2D730khi6S miIJEVCCQ5Uw287Lr62/UayU4y2q3qc11zOHEwCxmj62abH8hnVKc0VYXpoAAwq+mLNJ Z7PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=R0WvoE+NXVGbmbYDW1Kdxv55yJDm4gPa//+F7IdsMyTe3uHG4NcWc09axAgnHIdY1c mWADeWUx32KmGAPikBwFb6HXOg4sOqnZqt1n4UfGaLl9q5sE3lDnWZxVn3ORASzz+/4r fIMNKGRdkw7oro5djxtBsZ+BdYhDxeErFMmbKR2wM7g24AYDkBMc9YdlRKu7Qgw+sG/P UKPhPipMfsNPD5sDXepHn6FnyEZibYteQZ9uZ4ykMQzlfyibtlcVOe9jlDmaJesP/xhv OA6yQ64RwLuI//mNt0843Rx95+lYkctBMm2txDJY2S/JmhJuFtrE7ivFn56rgHmAAAmv IrCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D0IWLzid; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 77-v6si20121449pfh.332.2018.07.11.00.41.46; Wed, 11 Jul 2018 00:41:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D0IWLzid; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726588AbeGKHoj (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:39 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44411 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHoj (ORCPT ); Wed, 11 Jul 2018 03:44:39 -0400 Received: by mail-pg1-f196.google.com with SMTP id r1-v6so2686765pgp.11 for ; Wed, 11 Jul 2018 00:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=D0IWLzidIP460MwlrQAG6aeF2+wQJfsdDVp4sxz2rV6CBYykEPx9kJafLWl8/24Izp aBJMYleQySH+AEvDxpml4JhRLirMDCdI0nyFbiR1OSvWAEfj7RRTITx5GkIFI1GZomOC mjB1OxQ7nC/1WvViv/ENHY915vprkVR7BhIno= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=XtFD+pQp5QM8onw8iGgqcuMhcPGJKxr0YOfs7i1YDMJ5ZboAm4XgcGHZhpVzxemKev XikVEpoct5CTZTGyciGrIeIoqnqV8Ij1kbHqm8zf4apSGRnjZIfrL/GY+Ydu3GHeDZ+8 g+EmTtAjDLMwDa3Rd+531oOUmDHRTfUFg4bO5R7uh6L2WsGHXcAnSo3gxw7wdt39zQR+ vJR9dXw1p8UhwPXstKouzmAGZrs6x7dLY29FI+UIc97qOrVdThTaBocnwO69TrKxwnOI ChdSoFOsID+g5hlQ9C9CmirEWNeHVCas/+ZCzVn/WWd6ppPOCRxjyBh53IGg0f60wUAz iUaw== X-Gm-Message-State: APt69E02uTmdb89OXDUEa9ujOsMq2mi6QnGEqGV6P+cYjXLvBwwkpg0S FW1Ih6dN6jhZft/ZXjhXwW5jew== X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr26126916pgp.334.1531294902996; Wed, 11 Jul 2018 00:41:42 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s144-v6sm4342192pfs.123.2018.07.11.00.41.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:41:42 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , "Eric W. Biederman" Subject: [PATCH v11 03/15] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Wed, 11 Jul 2018 16:41:51 +0900 Message-Id: <20180711074203.3019-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memblock list is another source for usable system memory layout. So powerpc's arch_kexec_walk_mem() is moved to kexec_file.c so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and merged into the existing arch_kexec_walk_mem() for general use, either resource list or memblock list. A consequent function will not work for kdump with memblock list, but this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 --------------------- kernel/kexec_file.c | 54 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) -- 2.17.0 diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 0bd23dc789a4..5357b09902c5 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..b088324fb3ad 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -513,6 +563,10 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(struct resource *, void *)) { + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + return kexec_walk_memblock(kbuf, func); + if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY,