From patchwork Tue Nov 14 09:16:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 164790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1739872vqg; Tue, 14 Nov 2023 01:17:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY89BFRGW957oAVawhXtjxx//ycZ9a/1wWmQfp5h2v92VUxI4zJL/isNgwonpwO9Lai1X2 X-Received: by 2002:a05:6870:7d08:b0:1f4:a992:a15f with SMTP id os8-20020a0568707d0800b001f4a992a15fmr14038512oab.43.1699953470732; Tue, 14 Nov 2023 01:17:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699953470; cv=none; d=google.com; s=arc-20160816; b=o5sbmf1Fsuu9ozy3sCOzNy21XlOF0QPz1zNHIWbfIFsGniiVK/uki9MqyEtT3y5vFZ NtKzIDmMZgvjK+pCBxKTXYvCXuJWsCgDOnhtwyGLa3+/68dEIeVPAcutHAVzOaUzQN1z Wyiu/6bSOn2uYwMoEi/JcFv74bpHIwjtviYIp0S9XHbGFROwSrWtmeRCFfoguF6CcxKd +XeCPamFNQCHE7HaB8nnqlo+TmjWY5vMDyBvrMBOmxeoXLPjEe2Qc2m92LvUryMF5USV kT0h7o7TuBOwMelJJ5b2w0J3Ts59elDw1sEUiYF8PA22V116c1bjBMpxMko0Fh8KFEIe 87Hg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FCQMK3tvMnlcAutGAmjADx8NXWTNg1Te+2YY/zMRKiU=; fh=gn/gKdjyvyhpMJrTzA0WEzUmVThf5rhHNFnn0FB9Zyw=; b=GiND6XO22/0E+p8yfLHOe3SVJcv95l1SnPF1UrZQHVE1DsOHjtIZT55mnrzaCsK/we nBF1ujcZ0BFlUEpfErDPx4fkWh3s2VN0xPFlPXM0Biyh2NpApWQkcgCOCDZqrtB6575T WVyk+Xibh9ZMQm4oC72pCWAst5CQm9ZXhm3Ugn7nRaVd+8Leo4IdSC6cmH+ASgCrcyp2 u9936cEcvMDWLqYdREyf30WSHgiG2rQHx+D84UBg4H5ITRACt+AqthX6P+GJEAFbc/bE 84YEEw7W7FJC0/WSR/gOviQsb8/z6siw0xprIFF658phEN4O7KxwryM6mghdhmW0vZFo nnjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UOXWY2Wb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l189-20020a633ec6000000b005b915369815si7477582pga.155.2023.11.14.01.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 01:17:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UOXWY2Wb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 48CD6805E44E; Tue, 14 Nov 2023 01:17:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbjKNJRm (ORCPT + 30 others); Tue, 14 Nov 2023 04:17:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbjKNJRi (ORCPT ); Tue, 14 Nov 2023 04:17:38 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B2FD43 for ; Tue, 14 Nov 2023 01:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699953439; 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=FCQMK3tvMnlcAutGAmjADx8NXWTNg1Te+2YY/zMRKiU=; b=UOXWY2Wb5epXuiGqQH9cxn/kj6gjrvbmGwh+n0F1HXq6gqlZg9fJ0i9tkL2u0Bah+USKB5 /ytg2GeEM4neBQFyJvFHoptZD9YkpHjhWvxr4UMK/fB7VaYj5Oi/7nBGF27FmjTkcoN2zJ 0NjYFIF6gRIEVY99tkj9g9ZMv5p0ZjA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-155-AtEvHmVsOLW5Ae-g10RPxA-1; Tue, 14 Nov 2023 04:17:15 -0500 X-MC-Unique: AtEvHmVsOLW5Ae-g10RPxA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB275101A53B; Tue, 14 Nov 2023 09:17:14 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3A2D2166B26; Tue, 14 Nov 2023 09:17:10 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: kexec@lists.infradead.org, x86@kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, takahiro.akashi@linaro.org, Baoquan He Subject: [PATCH 2/2] kexec_file: Load kernel at top of system RAM if required Date: Tue, 14 Nov 2023 17:16:58 +0800 Message-ID: <20231114091658.228030-3-bhe@redhat.com> In-Reply-To: <20231114091658.228030-1-bhe@redhat.com> References: <20231114091658.228030-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 14 Nov 2023 01:17:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782530378317276289 X-GMAIL-MSGID: 1782530410713280700 Kexec_load interface has been doing top down searching and loading kernel/initrd/purgtory etc to prepare for kexec reboot. In that way, the benefits are that it avoids to consume and fragment limited low memory which satisfy DMA buffer allocation and big chunk of continuous memory during system init; and avoids to stir with BIOS/FW reserved or occupied areas, or corner case handling/work around/quirk occupied areas when doing system init. By the way, the top-down searching and loading of kexec-ed kernel is done in user space utility code. For kexec_file loading, even if kexec_buf.top_down is 'true', it's simply ignored. It calls walk_system_ram_res() directly to go through all resources of System RAM bottom up, to find an available memory region, then call locate_mem_hole_callback() to allocate memory in that found memory region from top to down. This is not expected and inconsistent with kexec_load. Here check if kexec_buf.top_down is 'true' in kexec_walk_resources(), if yes, call the newly added walk_system_ram_res_rev() to find memory region of system RAM from top to down to load kernel/initrd etc. Signed-off-by: Baoquan He --- kernel/kexec_file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f9a419cd22d4..ba3ef30921b8 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -592,6 +592,8 @@ static int kexec_walk_resources(struct kexec_buf *kbuf, IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, crashk_res.start, crashk_res.end, kbuf, func); + else if (kbuf->top_down) + return walk_system_ram_res_rev(0, ULONG_MAX, kbuf, func); else return walk_system_ram_res(0, ULONG_MAX, kbuf, func); }