Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp130076lqo; Tue, 7 May 2024 14:44:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWy37nuTiYhebYVqEXFNixxez5ZuxsvR9P0sY50a6sBj8N6S+tNsWzt3AEP1F7DHpDXXC7KJ/qpGHDxz5NyS8tH/i6fcsfqSt0MXOYcA== X-Google-Smtp-Source: AGHT+IFXva3mxjXdb4SV3kQ6XOA2m4D54PzYufk1QJ0mX8PXhGiPV6L3xy+/5D8IZTceTRI5dg4s X-Received: by 2002:aa7:8286:0:b0:6f3:ee60:54c3 with SMTP id d2e1a72fcca58-6f49c226b26mr941116b3a.19.1715118267764; Tue, 07 May 2024 14:44:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715118267; cv=pass; d=google.com; s=arc-20160816; b=rg2At55GKLK4RBKVWE+scEzvh2U3Zk6gezddBYUE2TN8y+j3LTeKwEFOwNI/+MKBkb 8WeTrL4Yg20V65xPPNnJYHRhBx/6WMyPwNml10DAa09fuiD11BWohiSZkWHach9dv8ne myHBrshhwe9omhOi+pM1acY8UoQ2mqZi6NV0DEVPt6rax11YF5z7ptAMMOA/09JEN7/e Zuew6/V5pxetvk3oOxCurgnPu+zBHc4wfZqGrlbWlLhRh2po9IkZNEhpfHArcbXnIiQv 5cZEn77zmDQixEt7iV5dcFEsU2wIo7kgTmt4f0U1HdfljRUaPJhoro8sGE38YSsaB2SO iTHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=gDELcenDVUTdOR/ZE4H7s3yaDipCvxPwDJjdsHdy2uk=; fh=5SeQ5Uy2NLYCf1pFOVICZwgFfmmgUqYmPtOYWhMkig0=; b=CZ+FA+pTMsder3P/VUyIb51XFqPYkEelq4OO5JvNs53xw/mSATu5UNkjoUSRSjmmJR t5JGGq/8RKlJsmTbFXW7kgP9OZFqUgW17A+fz/GXizebgTygoW0GpyM0JVA61IcmuHF5 G4RYrbcxt0I3kkxHT02yZy8JjLAqueU4GXa1DNPCZ62y0eszgAR+bLYRLAzI35aeUgoj vpXhTm+X/s9sVhJ4aucnR2Fgr3FdwUlA1Gb1WTleAgKqzrTBR4paCXdAGQQtIxkItqCV 0zF8+VFCwE4nvS09UX/yv+yR+LqkyLjoBilMvpaYq0rlrCQUIneDtBafGTNV1rEIAc10 Z5ow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bPJ5vXwf; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-172222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b15-20020a630c0f000000b005dc4b84b38asi10620736pgl.72.2024.05.07.14.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 14:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bPJ5vXwf; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-172222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4EC9BB21D92 for ; Tue, 7 May 2024 21:43:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 972F477658; Tue, 7 May 2024 21:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="bPJ5vXwf" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CC93745E4; Tue, 7 May 2024 21:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715118173; cv=none; b=RqLLNzdSnCEJyUDpQZsb3xI1zwQiv/KBpR4rwnNlASu8dtL+JaP99NBdg6+BMXm5Mxu6mHfDXfssz+aBTJdyWwbPTaV8c+W6g6yPRro4GsFHnSw3w5dDsv1ISYL37C7PCHBPSserrVssp4CyEVy4sf0Qf0Mqy/lPgKTPuoGvizg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715118173; c=relaxed/simple; bh=U7DObR7C46rOp9WAJ9Kp1t+6jdidsG351JAUz0jNDZw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=deSI8DhSzMIMix4abJznsyZ0FnV0vMADCFpMCRbhWGjJGz6J/Hdx+3R6eMp+WFo9ROkh6TY2rhoiRU760wsQYDzo5S1lvGiPpb73Uo3CXGwR5S6Wa11uVZqj3lwAmrJrfcBMRxahWv2IZnyoMbjiIzPlr6rnSlD5bO6OT9gCyTo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=bPJ5vXwf; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 447KJshZ017981; Tue, 7 May 2024 21:42:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=gDELcenDVUTdOR/ZE4H7s3yaDipCvxPwDJjdsHdy2uk=; b=bP J5vXwfzUH5ib/0JhhS3oOojemgAFrRvcUUX1ZVH/iT+Z0iRMljIsxhlA24MLzlSc 7Kg2kRAyELip9ydW/nF+G8fcC/IMBqWZ00m3eJ0tXhHq+lxCWH01pW8p+tsbQvaP ESjuaYp5lyNeRD7v6oFkV6WqkaHdYVAJI2XWptJHxDQ88xkPa1Xcj4LLZ4pIjv6f cbNfN1LgpxPDvbU0Fd+BtjG/pqjHhC0+qzNxJpSkLIj7pJVLv3gAXfivDgel8xFs NY5HxlQ4OkjzlvEY0DXsuDSdT+BWBSmpsn7yB9pRUz0DZEwnCKf/E0AOxLt2wJwV KBrcNnN1/PZMxZSrH1sA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xyspr0ayb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 May 2024 21:42:19 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 447LgIj5010004 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 7 May 2024 21:42:18 GMT Received: from [10.110.119.86] (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 7 May 2024 14:42:14 -0700 Message-ID: Date: Tue, 7 May 2024 14:42:05 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] sh: Call paging_init() earlier in the init sequence To: John Paul Adrian Glaubitz , , CC: , , , , , Rob Herring , Rob Landley References: <20240423233150.74302-1-quic_obabatun@quicinc.com> <72ec7831604326e852eb228072b1d817bab829fb.camel@physik.fu-berlin.de> Content-Language: en-US From: Oreoluwa Babatunde In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: FeRwHS4RWyL3Ea5FIRgdOCFmwjviY9ox X-Proofpoint-GUID: FeRwHS4RWyL3Ea5FIRgdOCFmwjviY9ox X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-07_13,2024-05-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1011 malwarescore=0 suspectscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 mlxlogscore=772 bulkscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405010000 definitions=main-2405070150 On 5/2/2024 3:29 AM, John Paul Adrian Glaubitz wrote: > Hi Oreoluwa, > > On Wed, 2024-05-01 at 19:18 +0200, John Paul Adrian Glaubitz wrote: >> Hi Oreoluwa, >> >> On Tue, 2024-04-23 at 16:31 -0700, Oreoluwa Babatunde wrote: >>> The unflatten_device_tree() function contains a call to >>> memblock_alloc(). This is a problem because this allocation is done >>> before any of the reserved memory is set aside in paging_init(). >>> This means that there is a possibility for memblock to allocate from >>> any of the memory regions that are supposed to be set aside as reserved. >>> >>> Hence, move the call to paging_init() to be earlier in the init >>> sequence so that the reserved memory regions are set aside before any >>> allocations are done using memblock. >> I was just about to merge your patch when I ran a git blame on the code in >> arch/sh/kernel/setup.c and noticed the following commit by Rich Felker: >> >> commit eb6b6930a70faefe04479a71088cc10366782d9a >> Author: Rich Felker >> Date: Mon Jul 31 01:27:50 2017 -0400 >> >> sh: fix memory corruption of unflattened device tree >> >> unflatten_device_tree() makes use of memblock allocation, and >> therefore must be called before paging_init() migrates the memblock >> allocation data to the bootmem framework. Otherwise the record of the >> allocation for the expanded device tree will be lost, and will >> eventually be clobbered when allocated for another use. >> >> Signed-off-by: Rich Felker >> >> It looks like that the call to unflatten_device_tree() before paging_init() >> is intentional and needed for the device tree to be preserved in memory >> after running paging_init(). Hi John, Thank you for pointing this out. memblock_alloc() marks all its allocations as reserved by calling memblock_reserve(). https://elixir.bootlin.com/linux/latest/source/mm/memblock.c#L1463 This should normally stop other users from allocating from within that region of memory. But in this case, since all the free memory regions have already been transferred over to the bootmem framework by paging_init(), I am not sure if that logic will still hold for the unflatten_deivcetree allocated memory. The main goal of this patch is to make sure that the reserved memory regions defined in the DT are set aside before any memblock allocations are done (which includes the allocation done by unflatten_devicetree). Hence, I can restructure the patch to only remove the portion of code that is is responsible for setting aside the DT defined reserved memory regions from within paging_init(), and move it above the unflatten_devicetree() call. https://elixir.bootlin.com/linux/latest/source/arch/sh/mm/init.c#L292 I will explore further and possibly restructure this patch based on my findings. Thank you! Oreoluwa >> >> @Geert: Do you have any comments on this patch? >> @Rob: Could you test this patch on your J2 board and report back?