Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp359480rwl; Wed, 5 Apr 2023 01:31:05 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgMBZ6IRvlU0JNnRc02fjkm8xb3A/YUzgV3thAu/xuitCK1ctby7Dl6JyqoFGh6nmL/twM X-Received: by 2002:a17:906:8503:b0:947:71cf:7c97 with SMTP id i3-20020a170906850300b0094771cf7c97mr1409779ejx.36.1680683465062; Wed, 05 Apr 2023 01:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680683465; cv=none; d=google.com; s=arc-20160816; b=dBwZ42DzqY88Wc/kYqWqxei9eg/nGNGhlOUzaQzd0Ah9EGpIU76Q3fUbTMily7QrcV Nhs5QebvT2NGabxuhP6gmBnGHsRJc7rVfZm+AgdGSk71HDwSqbvVNVWlxUH/Dnv3HPBg BHqzQEaMlFlUSx0nwAv2Zjj9hWOEyezwspgekgDIPf2YclfmCH1URHhF0BBQQG1iJcRj gfuLE0Mr5kIoJriKYJuvcD5Fyl/UWQuhQTCFQfHt/CMnj6njHtLVwXPUu+InZni+ORak Jgzi9LlYe64q8XbR6aI+sD1Xxf908GnB76Yo14+/xig6OASYn9gRfDg9JsLmnryBKgag 947A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VDbKStUWUqjjI+jVIxHLVrixEOyIXAliEp87dKa75WU=; b=xtpISfdY07ux913Bd6Jxc9ZW12nAj6pL+E3cHwlOsJB4eNN3K7pyCoW2LphHziHjX+ r+Xec4o8p4NpGUuPcSuXQtGuWBGFZcVFDK5i6kX1UhFm2eassWy0eSnSdHS7InLtohpS jNtu4KS28PJuP1yNCzA09oHXoFhq/aNnUHLEsQtwtIM8cwHDIYie/Zvqyp7EXtOEmM04 W2PV2oaVwU/hrBhahtgpIhDUJYCTYn3AImMQ2OjxnZ2v+xT9smhyjRF/Lp553j3o0T2H z/b9WJN4a5AIDsaTdmGg8GkOdfcBWMa25FGic0dYBm7SjFGSkWkQ4EIxdqEmXXwuhfcw EVYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L2Yi2n4z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fy36-20020a1709069f2400b0094823286610si2210053ejc.620.2023.04.05.01.30.38; Wed, 05 Apr 2023 01:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L2Yi2n4z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237393AbjDEIOP (ORCPT + 99 others); Wed, 5 Apr 2023 04:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237329AbjDEION (ORCPT ); Wed, 5 Apr 2023 04:14:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80E0F5; Wed, 5 Apr 2023 01:14:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 42B2D6245E; Wed, 5 Apr 2023 08:14:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CFBFC4339E; Wed, 5 Apr 2023 08:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680682451; bh=1nSglfItAuDI4ol4In4nVcuiP9G4IB0lSOQfSgEOfCY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=L2Yi2n4zcZcm4bQPPU9sZ242yVQyuXbhGtQaan735qEWwqiZ3wEPVMZQsqABQgPEE h4Kuprkm89+5gPA24oQ2/9I6eV+LxhDUM2DUcXKpKVy5YXk7ArZN8NAuzjgl5VARRM wcer0NjYmQr4y7zJeSmHLlI0s9iLgrNG/AiSJm3oCm76Psb/7/jWEHFAIoE64Br1Ir lkpXFbN/G+Wp+8QoAUqC4V96V88RgLk80ykpJndM/K6uzZYw3/LwclwTFJxRWBOlFP 4KsAIdE+vLwRKmB/mycLYLgwJ26PzfrOT1aGIFg+RaabKatVZcAOnvHIPkiwmY5GQd GpKW41dSctb4g== Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5002e950e23so208382a12.1; Wed, 05 Apr 2023 01:14:11 -0700 (PDT) X-Gm-Message-State: AAQBX9fg1rVS6/naNV0sH8O/Ni+I5Xv9506cLvgUbwJQxll5ytn6PMv6 VfjrAv2SbrwVtgzET/Bm+jLWhzU2iE6FuAJSDDQ= X-Received: by 2002:a50:9509:0:b0:4ab:49b9:686d with SMTP id u9-20020a509509000000b004ab49b9686dmr691501eda.1.1680682449803; Wed, 05 Apr 2023 01:14:09 -0700 (PDT) MIME-Version: 1.0 References: <20230301085545.2373646-1-chenhuacai@loongson.cn> In-Reply-To: From: Huacai Chen Date: Wed, 5 Apr 2023 16:13:57 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] efi/loongarch: Reintroduce efi_relocate_kernel() to relocate kernel To: Youling Tang Cc: Huacai Chen , Ard Biesheuvel , linux-efi@vger.kernel.org, loongarch@lists.linux.dev, Xuefeng Li , Xuerui Wang , linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Ard, What is the status of this patch now? Huacai On Wed, Mar 1, 2023 at 8:06=E2=80=AFPM Huacai Chen = wrote: > > Hi, Youling, > > On Wed, Mar 1, 2023 at 6:08=E2=80=AFPM Youling Tang wrote: > > > > Hi, Huacai > > > > On 03/01/2023 05:30 PM, Huacai Chen wrote: > > > Hi, Youling, > > > > > > On Wed, Mar 1, 2023 at 5:21=E2=80=AFPM Youling Tang wrote: > > >> > > >> Hi, Huacai > > >> > > >> On 03/01/2023 04:55 PM, Huacai Chen wrote: > > >>> Since Linux-6.3, LoongArch supports PIE kernel now, so let's reintr= oduce > > >>> efi_relocate_kernel() to relocate the core kernel. > > >> > > >> If we strongly rely on the PIE feature after the modification, we ne= ed > > >> to modify it as follows, > > > There is no strong rely, efi_relocate_kernel() can also handle the > > > non-PIE kernel. > > > > IMHO, if EFI_KIMG_PREFERRED_ADDRESS is no longer defined as > > `PHYSADDR(VMLINUX_LOAD_ADDRESS)` (physical link address), we need to > > relocate through the RELOCATABLE function, so it is recommended to > > select RELOCATABLE if EFI_STUB is enabled > We can select RELOCATABLE when we modify EFI_KIMG_PREFERRED_ADDRESS. > Before that I prefer to give a chance to build a non-PIE kernel. > > Huacai > > > > Youling. > > > > > > Huacai > > >> > > >> --- a/arch/loongarch/Kconfig > > >> +++ b/arch/loongarch/Kconfig > > >> @@ -137,6 +137,7 @@ config LOONGARCH > > >> select PCI_MSI_ARCH_FALLBACKS > > >> select PCI_QUIRKS > > >> select PERF_USE_VMALLOC > > >> + select RELOCATABLE > > >> select RTC_LIB > > >> select SMP > > >> select SPARSE_IRQ > > >> > > >> or: > > >> > > >> --- a/arch/loongarch/Kconfig > > >> +++ b/arch/loongarch/Kconfig > > >> @@ -360,6 +360,7 @@ config EFI_STUB > > >> default y > > >> depends on EFI > > >> select EFI_GENERIC_STUB > > >> + select RELOCATABLE > > >> help > > >> > > >> Youling. > > >> > > >>> > > >>> Signed-off-by: Huacai Chen > > >>> --- > > >>> drivers/firmware/efi/libstub/loongarch-stub.c | 24 ++++++---------= ---- > > >>> 1 file changed, 7 insertions(+), 17 deletions(-) > > >>> > > >>> diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/driver= s/firmware/efi/libstub/loongarch-stub.c > > >>> index eee7ed43cdfb..72c71ae201f0 100644 > > >>> --- a/drivers/firmware/efi/libstub/loongarch-stub.c > > >>> +++ b/drivers/firmware/efi/libstub/loongarch-stub.c > > >>> @@ -21,26 +21,16 @@ efi_status_t handle_kernel_image(unsigned long = *image_addr, > > >>> efi_loaded_image_t *image, > > >>> efi_handle_t image_handle) > > >>> { > > >>> - int nr_pages =3D round_up(kernel_asize, EFI_ALLOC_ALIGN) / EF= I_PAGE_SIZE; > > >>> - efi_physical_addr_t kernel_addr =3D EFI_KIMG_PREFERRED_ADDRES= S; > > >>> efi_status_t status; > > >>> + unsigned long kernel_addr =3D 0; > > >>> > > >>> - /* > > >>> - * Allocate space for the kernel image at the preferred offse= t. This is > > >>> - * the only location in memory from where we can execute the = image, so > > >>> - * no point in falling back to another allocation. > > >>> - */ > > >>> - status =3D efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, > > >>> - EFI_LOADER_DATA, nr_pages, &kernel_addr)= ; > > >>> - if (status !=3D EFI_SUCCESS) > > >>> - return status; > > >>> - > > >>> - *image_addr =3D EFI_KIMG_PREFERRED_ADDRESS; > > >>> - *image_size =3D kernel_asize; > > >>> + kernel_addr =3D (unsigned long)&kernel_offset - kernel_offset= ; > > >>> + > > >>> + status =3D efi_relocate_kernel(&kernel_addr, kernel_fsize, ke= rnel_asize, > > >>> + EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_ali= gn(), 0x0); > > >>> > > >>> - memcpy((void *)EFI_KIMG_PREFERRED_ADDRESS, > > >>> - (void *)&kernel_offset - kernel_offset, > > >>> - kernel_fsize); > > >>> + *image_addr =3D kernel_addr; > > >>> + *image_size =3D kernel_asize; > > >>> > > >>> return status; > > >>> } > > >>> > > >> > > > >