From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792602392; b=RCIvoLE+cPnyzPJBd3TDdwcbnyfLekRzzbWsRO261kJ7IG2vv1SNBAbpX7wQokcRjl4d TRSyw24zah0jW+RBr//v74SGwJwVg9MNq0oykYLeEh5y+hqlBBWFFkaVDFyyU1s4OhHqq k/AJNxBA2DHUyB+es6m65zUIF1vW1c7QeaboNKqAX3VzyyGVOgKeHBfRokBmCWLh4iO1R PWVVTFORPZuiAN1y1zCIUKV5EbIy4bwpBsS/QLd1nOGDURsApG+mLK3ydvBMGJtRM7Z9B Tmx29/aZT7S+C4CxdmRQ1dE47mCuePjIqhlSzVPFh7F3xfGZfhZpt2dwd7gdjliXbyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792602392; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Date:From: To:Cc:Subject:Message-ID:In-Reply-To:References:Organization:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding: X-Proofpoint-Spam-Info:X-Proofpoint-GUID:X-Proofpoint-ORIG-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=ColfoWoZWjzQM3y8Ujd1hnMszqJ8Z+vfszS9gttO2x8YS0zpYHBB9sq5rDPXGtMH6U5K jV7RHD40iIJ0ci0gJjcOhhLdjgDLCD8U8UglAzDJyZEf5uR4itZ7yzdSvgu+opE/HP6Ig HgY0Dfx9jEVDK1bp2bL2yskfo277LLSNJ9s3XCIxCtAm6xRCw51EZMb7t9hcwZ6Yg7ik2 Nv8hOiBGsWiATNIU4n+ye80NykHsxHaQeDLz1ufHlZ4qqSmtXwoTBzTXOStviYyee0JhD fqKwyqWc2LQ2TWWifuMI9DkVQPlW2CPnm2MWecd+kQ6MsjjNfhsSi6LyF3h//S4BS7A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OSlcL8cO; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=S0lM1fWI; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B54E9606A32A for ; Wed, 21 Oct 2026 17:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B54E9606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OSlcL8cO; dkim=pass (2048-bit key, unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=S0lM1fWI Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69LFU6JM141642 for ; Wed, 21 Oct 2026 17:06:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=OSlcL8cOU5zXbryB 8fphfV9zo1XreQA4OpWxV/h7tO89Sx+6X2Zl5p6+0ULsUn90taN9eGxYH16jm+qk L0XZJ7Dn3v8XGxu9eL4AUwpW89Q08hqaGYjoQLd+s7IfocWo3yT9caDh8KNWlz5H s2wvu8IN32qEW3e4b+swbEmyIx4Sb7Bfs53jhsZpFAhMxFVFGH/lhgrGUhOIl9na ZHCzsoC6k5dyzggh321+7NzEQC0sx6z0Q589PxqQBdkJCqG9N/vTM/t84N6WLpwZ XNzQ4yeKMJxtggMzRJOTsDyC0PwIrehi/AU/krpfAg39mwEvzewP39PNMVc/Bg+a pxwNPQ== Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hex58924r-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 21 Oct 2026 17:06:30 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-36696c9f55bso54386eec.1 for ; Wed, 21 Oct 2026 10:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792602390; x=1793207190; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=S0lM1fWIw6Y5hJNpLN3G50Ucns5COX1CrBE5hbyjPvJoSWfaUU74zEBfK5Y9LOfw2o 3qJuezojUa7Gwuxzpuy/sRiQzyLvOc9/wbbwX7fNFq1fLWNTYoqZf2H0HrpG76BxzJkd j4NEOGLlwqNWTzlkJzpYzISQUweCoK4ctrM0+yYr/nhRkxxHwelCf8Yr47GhsPdS/Gh/ VebX6ND7e/SueIFT8iifQkT50U24TtcvbyCvGuKBnDq3FtCLV80e+kGT9AWueohj3ns1 ZLNryXgd9nc5t4EbUsKv7TiPfGLjKNrhfFHKWolwtgbwMqQR6ThArwPN1LlmwKKUPgZc Ru6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792602390; x=1793207190; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=jCpXd+dMeD56z8MW4hvowHgtkFM7/3y8scU+h0noGTrzn6WjLGRtwIp+8HaEND8XKH 2JsQoET2TjNGT/DzewZC9e1hc0gJU8TPO5Dha1BSvfhtScSOv4LIkbvlHDd9XHfH2FM1 Nq6f1m4wdI8UVuE+K+bJb//gSoHzLk36qlKCFMC/x43OkTPd43jixGLor6ho3pXFRWoa 7kecmWqDWxVM7iDSalllz1pmsmo03RMGrYb8HF2i8cyRMDGCk/lMCtNBF+ReTf4Ro36T 4TQ5U4T197FTQu7m8HcOemnMs2q4CFuhvVpSmY7nVVXIl+6TsFMDYDaOnKkjhY9jTHom UiiA== X-Forwarded-Encrypted: i=1; AKwUvBw2cYkftl28VGJeMyHTk9ZLEeUIKu4M2V/xxpUeoUp9FmvzUK+p0Bm5KsV3pE9zsnrU8qY9A3cdCo8=@vger.kernel.org X-Gm-Message-State: AFq9FYIL/XPmClt/GfMEHlknSzh9V6xryz59oUjJs5CTAGOYa3rSn4aa zzAr1kAerrudpyI912Octi9wMLKc0h8AylFVC3N0F6Q030gwPr9+9N3jORh1W/ZZEk2CNIr+OPq 1Bbooo1Vtq7Rl+Adn8SbQNXUkXA0tSIA6+WrNVxHdMZJf7zpFvpXtVAGaTjuUnnU= X-Gm-Gg: AYBFou3SctnbIs+cOSo7ABzrJyaTT7CFODqjQGuO2r+fjiJhyaVnkuJ8+SuS/Dwp668 oOTzDw3WeVw/+w0n678xG9/w/6M7UMKBMMQKxXpted89+wCAEAXAbSCwmwe3bOCaCnBdExj+/p3 TSnaVN7p7kfcHW7hrXE0eFFXP0u8w3Ku/t8eetHlyDep5rsGL587cOAH+HNF05moGgs00hqrhP+ LqdtlJk/xqMKiWJGHdT92Fwc6jAhd+q8ufgPSpr+h45ro6lW6J+XHHL7zmYTzWwG2qnjC/f7Kw2 9q8v8+mwGtdxJzh4FgxL3lZhB1pzILE8y6TNlhaX6ekaZ4SRZ479Ndc7C04xK9wc/kE6fUM1cF+ LH4AkVvPARHOjf1qjfbDwl+zHAxoZ7eA3R7Uk7QMEAQ== X-Received: by 2002:a05:693c:20cf:20b0:363:a45d:10b1 with SMTP id 5a478bee46e88-365fa49061dmr6847134eec.5.1792602390066; Wed, 21 Oct 2026 10:06:30 -0700 (PDT) X-Received: by 2002:a05:693c:20cf:20b0:363:a45d:10b1 with SMTP id 5a478bee46e88-365fa49061dmr6847104eec.5.1792602389510; Wed, 21 Oct 2026 10:06:29 -0700 (PDT) Received: from localhost (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-367f52ce166sm5334511eec.29.2026.10.21.10.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2026 10:06:29 -0700 (PDT) Date: Wed, 21 Oct 2026 10:06:22 -0700 From: Jonathan Cameron To: Jason Gunthorpe Cc: Alexandre Ghiti , Albert Ou , Ard Biesheuvel , Arnd Bergmann , Catalin Marinas , Jonathan Corbet , David Sterba , Ilias Apalodimas , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Randy Dunlap , Simon Glass , Shuah Khan , Nick Terrell , Will Deacon , Alexandre Ghiti , Conor Dooley , linux-integrity@vger.kernel.org, Palmer Dabbelt , patches@lists.linux.dev, Piotr =?ISO-8859-1?Q?Kr=F3l?= , Ross Philipson , Sami Tolvanen , Song Shuai Subject: Re: [PATCH v2 08/15] efi/libstub: Have efi_kaslr_relocate_kernel() handle extra_size Message-ID: <20261021100622.00007ae5@oss.qualcomm.com> In-Reply-To: <8-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> References: <0-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> <8-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> Organization: Qualcomm X-Mailer: Claws Mail 4.4.0 (GTK 3.24.51; x86_64-w64-mingw32) X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIxMDA2OCBTYWx0ZWRfX5iuyfnI6OiRg XllgEU+Yu+ZPimJ148B3ovIlUxzYyZXA75kILv79uOoZdI61Y+issQSGXo8DmE7JKZuT0O02jE5 ynBkx2gv0gW1WvpE3Q1JxFdGK9FTTQM= X-Proofpoint-GUID: L8uXR5tBvkezWb8Ap4DvVrvPg2tsz0Ve X-Proofpoint-ORIG-GUID: L8uXR5tBvkezWb8Ap4DvVrvPg2tsz0Ve X-Authority-Analysis: v=2.4 cv=Ku7YSmWN c=1 sm=1 tr=0 ts=6ad8f116 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=kj9zAlcOel0A:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=Ikd4Dj_1AAAA:8 a=EUspDBNiAAAA:8 a=z1Vexnt6jiiBlSUV7TIA:9 a=CjuIK1q_8ugA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDIxMDA2OCBTYWx0ZWRfX8n6gPhPcOnh3 gG524lrF+ipxQo52SzBpVybs9cj5O8rwxd04sFpFIKq2Jr2JUiBdfeSWE8d/zOmfJLOq0rCACRi e9zX7fGJxwpwkdW60i4AwTlBJDVX63aeneuMn+E6cXoGPySFg+t//Erd4L2zhomVYTc5MzuHzbb nkSVkRkUWIbP8KY3RT/TWq9OfpXyGRJtQapxPLwy+yzjhMBKC6qOuDWZ+U519A5sllXf8IRPJNm PdYxC7fTPqz0V4ocuMHEaNGuO+5NM8aYUnTCGgI4uSQuIetPftj+3VkBXKaTm1ViXTfFCFDUFqO Z+H4AxRmZyJwa1nBO32i5vgHV/idanNigkroowr5DKv3k3TwdqdMOD3YBZ3yUk0az4zYLHsOJAJ eaI3AE9nqiM+PW2E6McIr4SlA3yeBiou+dr6YSzu8OXzYFNoKJeK444ON3Yxk5wMmTdf9rtGnXf vgRd9k5f/Q0pqfoZY9Q== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-21_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610210068 On Fri, 2 Oct 2026 20:31:45 -0300 Jason Gunthorpe wrote: > There are three possibilities here, each a little different: > - relocating for kaslr, just request extra_size like the zboot flow does > when allocating from EFI > - in place, attempt to allocate from EFI precisely after Image to > confirm nothing weird is there, failing that > - like any other error with the in place EFI location allocate > non-randomly with extra_size included > > Remove the callers' assignments of reserve_size since > efi_kaslr_relocate_kernel() now does it. > > Signed-off-by: Jason Gunthorpe A couple of trivial comments. Otherwise looks good to me. Reviewed-by: Jonathan Cameron > diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c > index 4bc963e999eb97..e419f3800af517 100644 > --- a/drivers/firmware/efi/libstub/kaslr.c > +++ b/drivers/firmware/efi/libstub/kaslr.c > @@ -125,16 +164,29 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr, > } > > if (status != EFI_SUCCESS) { > - if (!check_image_region(*image_addr, kernel_memsize)) { > + bool image_region_ok = > + check_image_region(*image_addr, kernel_memsize); > + > + if (!image_region_ok) { Why this change? I don't particularly mind but seems to be churn that isn't necessarily needed. > efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI memory region\n"); > } else if (IS_ALIGNED(*image_addr, min_kimg_align) && > - (unsigned long)_end < EFI_ALLOC_LIMIT) { > - /* > - * Just execute from wherever we were loaded by the > - * UEFI PE/COFF loader if the placement is suitable. > - */ > - *reserve_size = 0; > - return EFI_SUCCESS; > + (unsigned long)_end + extra_size < EFI_ALLOC_LIMIT) { > + if (!extra_size) { > + /* > + * Just execute from wherever we were loaded by > + * the UEFI PE/COFF loader if the placement is > + * suitable. > + */ > + *reserve_size = 0; > + return EFI_SUCCESS; > + } > + > + status = allocate_image_tail(*image_addr, > + kernel_memsize, extra_size, > + reserve_addr, > + reserve_size); I'd move reserve_size up a line to group it with reserve_addr. > + if (status == EFI_SUCCESS) > + return EFI_SUCCESS; > } > > status = efi_allocate_pages_aligned(*reserve_size, reserve_addr, > diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c > index 725b634c517919..a88b2d275e5bb0 100644 > --- a/drivers/firmware/efi/libstub/riscv-stub.c > +++ b/drivers/firmware/efi/libstub/riscv-stub.c > @@ -37,7 +37,6 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > kernel_codesize = __init_text_end - _start; > kernel_memsize = kernel_size + (_end - _edata); > *image_addr = (unsigned long)_start; > - *reserve_size = kernel_memsize; > > status = efi_kaslr_relocate_kernel(image_addr, > reserve_addr, reserve_size, From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E991606A319 for ; Wed, 21 Oct 2026 17:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=FgkBn9uZ; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OSlcL8cO; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=bg5NaBOp DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W8bKj7Qva5fVZw2qsm9F5e7gO45CUBSs+TU8N4mtEtw=; b=FgkBn9uZSBYk4E Uqv9O1wMUXS0WE9u6zP7+dqg1GQGTNp2hvHOyZBoGzM47SWhGKMRSRPtTMNXWGokDp9NiCJEzV7OO beHaQeTdO+snQLEaxLWrQSf+A3aSMvtKALH3kSfmIKQuTGxH/7nJ/ARpRZGpXDLJqxMyKh298xpSp blORdTQz1zKpj3ve0IqinTNWBCOro2QNHXfiugYMK8nYWzQSo6FYfX3LI2A5i09IU1eWkkf3Tdn9D Vm6aKc5fpajjQGvyFddc35CxUXc9RCMx25aL5mx+GlEqjx0iLxou6XcDo2R1+aYp5TEfcTs1ygQK7 V28KCtuziTQTlV3vBhHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xJZlq-0000000CVoI-1dyV; Wed, 21 Oct 2026 17:06:34 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xJZlo-0000000CVnR-1sCb for linux-riscv@lists.infradead.org; Wed, 21 Oct 2026 17:06:33 +0000 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69LFU5wv992237 for ; Wed, 21 Oct 2026 17:06:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=OSlcL8cOU5zXbryB 8fphfV9zo1XreQA4OpWxV/h7tO89Sx+6X2Zl5p6+0ULsUn90taN9eGxYH16jm+qk L0XZJ7Dn3v8XGxu9eL4AUwpW89Q08hqaGYjoQLd+s7IfocWo3yT9caDh8KNWlz5H s2wvu8IN32qEW3e4b+swbEmyIx4Sb7Bfs53jhsZpFAhMxFVFGH/lhgrGUhOIl9na ZHCzsoC6k5dyzggh321+7NzEQC0sx6z0Q589PxqQBdkJCqG9N/vTM/t84N6WLpwZ XNzQ4yeKMJxtggMzRJOTsDyC0PwIrehi/AU/krpfAg39mwEvzewP39PNMVc/Bg+a pxwNPQ== Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4heh5r479e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 21 Oct 2026 17:06:31 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-36696c9f55bso54378eec.1 for ; Wed, 21 Oct 2026 10:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792602390; x=1793207190; darn=lists.infradead.org; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=bg5NaBOpTc7/dDj6CRO6EJvpIwaYM9GeEMZoUHtZ8dfkPhd3qZysXP7sinBNDmhxqL puSMbxZ3SDjoQkEl4wCMp+W7Y+B8xIrFxQNWeuCYqdB+9YEHjDax0ZfFOVH3h5klFmSy WL3iiwMo3TMdumk8wcu9x9i6tJTedpsTgSgEoeDuAX5zGRwoK0gRGdkPC2YptDU9qbaQ yZWN8FdRciXzXziHEYp8ahRgBQY8GGMh5P1RntVMA0fdQ1U6/YmK5Q4c5MbBJlaJ8g1+ BWYRXYdAkEJroIpLa+tKieAP4jiTeFyerpK2BjkT2MLVm3UBiZZkSC67zwrlXghIA5jR lPwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792602390; x=1793207190; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4KgtddslSOEOaN73E6Xh0kX0j9JGBALLWlHj4vZIcu8=; b=fRNGV0VPfg9OrVZ7kggsjaNZLeNjIODC1PnNGKhF9wNeXwxGV35DwmC7mSyGko4NPy +CN6WU/GX5bLhN30Je7k+XVx4KPalyScXzQN+SpKD4XOH2kfBgvVHvhMBp6/vAxoEZ+2 VVZc6hX23T4E/ghLwVBAW/HtEy2g9qK5yiYUrKAb5Jlr1KnQ7iNdQhF1uBLDMborIH4F J95MY3IKUPH8ORUn0QlLPWNdpa7jpXCHxsK033CzzhVFNy4+d+c1c9BOGt5Q9gjxEF7x Pi1PmOoyLs/Dwq6jgix/5plndeGkL+nQ+BfOQhBRnmhtMAFxWNHSM3fbcuaAVWo9weTn YOXQ== X-Forwarded-Encrypted: i=1; AKwUvByMKak9AMCwl73n30dC8o2UhrnFTga0oMnQEN323Vay0PfGwvx0n/KWaWOSw07xWQmynlgITeWiww/zvA==@lists.infradead.org X-Gm-Message-State: AFq9FYJvdf8jeFeDLWAUq9C3Q4SirQLkd1SGHo7J+Ua0LUlkuP8cmBCn O/TNTBDJageodn9a2TS/TcXZx7JItWdBg1qIvNkv0bpwfP+vzUCfR74rvTSypGr22Zr38tmzHDV mtnQVrhEEy4OpbcS6wkvKTKGOsuveYZt7upwRmJ0YPoLGyJ0fc32z/yf6pAc46JUykNO6skEU7X AseKk= X-Gm-Gg: AYBFou094d5567lNF9HaSreSzPVXca8wJge0x/M2GE5xU999jgk+13UwoSZw4Pfig1X nCInBXnB1gZM0biMh0it3vZXmQLGX0I/bjPsJH0lwEFoB8WadQEM4HC3j6o08caH+v3Y070Di04 v3wS6lyp4G1dSeG60a7j5sWM3d/yDUU+5++GBAyTJXU3sVErkRRneStCvNlUGzDnKQn9ABayTwf 7G3kkIKOyToyOsx/5X+BKjt8CfmX6DjMaIMPJzRPX9fp48BAwkDKavId2cXYh4btCtWgOy6eIHQ /QkU4w+/A3e1xozcJADpYgfSygrxNxqXLNjeuXazmrUbBzsuZDk601jFRxy9XDnICyQCuHsS2Ej 0YxqG/7CpP5ujH/nZdcHlDfl6pxZMt/TPWb9iuyJEGQ== X-Received: by 2002:a05:693c:20cf:20b0:363:a45d:10b1 with SMTP id 5a478bee46e88-365fa49061dmr6847147eec.5.1792602390111; Wed, 21 Oct 2026 10:06:30 -0700 (PDT) X-Received: by 2002:a05:693c:20cf:20b0:363:a45d:10b1 with SMTP id 5a478bee46e88-365fa49061dmr6847104eec.5.1792602389510; Wed, 21 Oct 2026 10:06:29 -0700 (PDT) Received: from localhost (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-367f52ce166sm5334511eec.29.2026.10.21.10.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2026 10:06:29 -0700 (PDT) Date: Wed, 21 Oct 2026 10:06:22 -0700 From: Jonathan Cameron To: Jason Gunthorpe Cc: Alexandre Ghiti , Albert Ou , Ard Biesheuvel , Arnd Bergmann , Catalin Marinas , Jonathan Corbet , David Sterba , Ilias Apalodimas , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Randy Dunlap , Simon Glass , Shuah Khan , Nick Terrell , Will Deacon , Alexandre Ghiti , Conor Dooley , linux-integrity@vger.kernel.org, Palmer Dabbelt , patches@lists.linux.dev, Piotr =?ISO-8859-1?Q?Kr=F3l?= , Ross Philipson , Sami Tolvanen , Song Shuai Subject: Re: [PATCH v2 08/15] efi/libstub: Have efi_kaslr_relocate_kernel() handle extra_size Message-ID: <20261021100622.00007ae5@oss.qualcomm.com> In-Reply-To: <8-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> References: <0-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> <8-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com> Organization: Qualcomm X-Mailer: Claws Mail 4.4.0 (GTK 3.24.51; x86_64-w64-mingw32) X-Archived-By: MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=aI5lOr9m c=1 sm=1 tr=0 ts=6ad8f117 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=kj9zAlcOel0A:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=Ikd4Dj_1AAAA:8 a=EUspDBNiAAAA:8 a=z1Vexnt6jiiBlSUV7TIA:9 a=CjuIK1q_8ugA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-ORIG-GUID: 6KPX30FEyRyYsXIT1tbPFDakN5ltDJKJ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDIxMDA2OCBTYWx0ZWRfX2d0Ql4F1R1DG N6pk8Q4/iKPC9RgzAKTrnI8QoKrFXuHwn6J+iquK55WUgMsc4007RCx/XukacmRxOnraE+4nxpX J6vZtIWo3M3UBB/Zr7ZzDFUdF4RAaoo1D6rGLpQ+KtPtkAoZF8M2c7Onk5CeD6B1DzZI5gOF3v4 tL/uB97HkxUdEj8H+98D8IloIA4CXyvI9nmiVJvsXv1FOo4oFdv0oNhrRPjijgJUKIsQmfB4l+Y u0tmpyaWsJQXontC7tLhMEz1ZQdiJ3Qe4Qrf9sk6iihN8h/zKSh7wQlxYr50jar+MAWGcmsNhYk TxP9bipgiI9Elw8EysYWD5KTuCStupVeHbdhThN6NY5kIT8R20vKVwhVbCj2nsyMB6U5a+D8Dp4 d+59VDMZDgDUGCnSEG1RTR8Rl+D4i8HDlqlY/nOU0qkwGuo99eBgEnwyykpXvRhjHbF3bj1JRng fWdvTy397/QAs0+laqA== X-Proofpoint-GUID: 6KPX30FEyRyYsXIT1tbPFDakN5ltDJKJ X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIxMDA2OCBTYWx0ZWRfX/+1BFKlcutL2 trDtQUTfjWwDhI1CLtULoSIxfkDQ0/fU9wC1FHSW8lqHX33Skf8336Dxa63IWEgviK7UxxauYEi EHWeBWmJ++2dkWcyl4NGESb7ZEuJBVc= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-21_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 impostorscore=0 spamscore=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610210068 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261021_100632_594907_4710A561 X-CRM114-Status: GOOD ( 24.16 ) X-Spam-Score: -2.8 (--) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, 2 Oct 2026 20:31:45 -0300 Jason Gunthorpe wrote: > There are three possibilities here, each a little different: > - relocating for kaslr, just request extra_size like the zboot flow does > when allocating from EFI > - in place, attempt to allocate from EFI precisely after Image to > confirm nothing weird is there, failing that > - like any other error with the in place EFI location allocate > non-randomly with extra_size included > > Remove the callers' assignments of reserve_size since > efi_kaslr_relocate_kernel() now does it. > > Signed-off-by: Jason Gunthorpe A couple of trivial comments. Otherwise looks good to me. Reviewed-by: Jonathan Cameron > diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c > index 4bc963e999eb97..e419f3800af517 100644 > --- a/drivers/firmware/efi/libstub/kaslr.c > +++ b/drivers/firmware/efi/libstub/kaslr.c > @@ -125,16 +164,29 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr, > } > > if (status != EFI_SUCCESS) { > - if (!check_image_region(*image_addr, kernel_memsize)) { > + bool image_region_ok = > + check_image_region(*image_addr, kernel_memsize); > + > + if (!image_region_ok) { Why this change? I don't particularly mind but seems to be churn that isn't necessarily needed. > efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI memory region\n"); > } else if (IS_ALIGNED(*image_addr, min_kimg_align) && > - (unsigned long)_end < EFI_ALLOC_LIMIT) { > - /* > - * Just execute from wherever we were loaded by the > - * UEFI PE/COFF loader if the placement is suitable. > - */ > - *reserve_size = 0; > - return EFI_SUCCESS; > + (unsigned long)_end + extra_size < EFI_ALLOC_LIMIT) { > + if (!extra_size) { > + /* > + * Just execute from wherever we were loaded by > + * the UEFI PE/COFF loader if the placement is > + * suitable. > + */ > + *reserve_size = 0; > + return EFI_SUCCESS; > + } > + > + status = allocate_image_tail(*image_addr, > + kernel_memsize, extra_size, > + reserve_addr, > + reserve_size); I'd move reserve_size up a line to group it with reserve_addr. > + if (status == EFI_SUCCESS) > + return EFI_SUCCESS; > } > > status = efi_allocate_pages_aligned(*reserve_size, reserve_addr, > diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c > index 725b634c517919..a88b2d275e5bb0 100644 > --- a/drivers/firmware/efi/libstub/riscv-stub.c > +++ b/drivers/firmware/efi/libstub/riscv-stub.c > @@ -37,7 +37,6 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > kernel_codesize = __init_text_end - _start; > kernel_memsize = kernel_size + (_end - _edata); > *image_addr = (unsigned long)_start; > - *reserve_size = kernel_memsize; > > status = efi_kaslr_relocate_kernel(image_addr, > reserve_addr, reserve_size, _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv