From patchwork Mon May 15 10:12:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 1781302 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gerhold.net header.i=@gerhold.net header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=CY+o6P9V; dkim=pass header.d=gerhold.net header.i=@gerhold.net header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=NpzOsiBC; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QKZyt5nh3z20dX for ; Mon, 15 May 2023 20:16:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241093AbjEOKQU (ORCPT ); Mon, 15 May 2023 06:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240832AbjEOKQM (ORCPT ); Mon, 15 May 2023 06:16:12 -0400 X-Greylist: delayed 179 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 15 May 2023 03:15:35 PDT Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02BC2106; Mon, 15 May 2023 03:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684145544; cv=none; d=strato.com; s=strato-dkim-0002; b=qDTIIAzqDyNFmO0GjIMWdlTAsPfxoi9c54XrSPnPIBCD+/Ac0NqjPIo6RX6ZXYFA/v XfSRhLCFFqaZY+hM+ieOq8rjSYgktwQ/tfFSeaZAmb+l7MHOBSN4ag8OibJxs/nNzGuJ yqHI9U60zAdGQoDotldrbSoLHJ3sxR3Qfu9o4COGYCqhsQq6l6N9z7Kw7UQS2+hRBwIR ftSNtfx19eFQlt3El2cFRuG67B9/TXphBjO+Sjj2KW4jf6hH/KJ9cnxjcR4SGfqgcLPZ RArsEHlfPp6fstmF4Zj5Agy2rxlSMF7RV1jvuhngOzoXFykStQDrUs8J8MweXQjExpqD ybsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=strato.com; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=olVuiJZGfA/LHV3YVLMLjpbt55lnzWTZbOuO9FJhuMI=; b=V6mauyZYvxwo5w3sMUAKskAbdeyyXVMqzWDRWwTuyaCbU9/14gd3OZUCy4fSob6NBl +pP2fjAi05cVDIRS9WVjjmdDh4HOuGTqMstUiaOGL+XIs9QGySlmIgEiCO4M1q/1iGSu MWPKD5uWoPvJ8KS524PAe+iZXzdMYRXYiM20K4LDW40/PHJ2AMGETzRzF5TxMXQxXVGa u3uIVWYGvYN4z1wyYRYEN69RSAS6OQjxcWqlhYXj9so/o/hJH0q/I11WFB7yU5AJ5Ta0 q9xTCt4ceGjb82ozounPElMKglNLribywWcnBbr5wYmG7TgOygKjw0qkUhK+O4y4CM4Z xfyg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=olVuiJZGfA/LHV3YVLMLjpbt55lnzWTZbOuO9FJhuMI=; b=CY+o6P9VjlLTzgmoC0ukNBftxBPWTp+7p5Sf63HXc0kUdrbe51QDEhkdp9Wtei8gCx 36mkGqS1MxlBxUd2aUZm8VSzzNvMDQ+iEyrYqhhDomIXlgCGy0lYIQlTuJVh/7vTZXjH LZk02fO22jf3tEZDtUtM/hEzd/CoSxwcSfng63j1v3SMB17uUs5bzuub7PAMNgvhSk5h fVs9gKoT23x5tolvWfYrBeCcMwEdRGVXI+f17rwhgYErxVvZpiA+WYm8KF5vlZFlNfSK JKBYgV4xLhWiG84cXENjPysczqq8CwbFkGjrxDqLv8EBWXhxPuxZ28E+Od8VshjfWQ3m NQpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0003; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=olVuiJZGfA/LHV3YVLMLjpbt55lnzWTZbOuO9FJhuMI=; b=NpzOsiBC7Df5KrzmYokWRVug7C5LvTnshPFSpfjZg+SXou+lgjK2J8KTa7xrsVuGtr lptCIGHXxBH9BsowsSBg== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVOQjVd4CteZ/7jYgS+mLFY+H0JAn8u4ly9TY=" Received: from [192.168.244.3] by smtp.strato.de (RZmta 49.4.0 DYNA|AUTH) with ESMTPSA id j6420az4FACO1JG (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 15 May 2023 12:12:24 +0200 (CEST) From: Stephan Gerhold Date: Mon, 15 May 2023 12:12:16 +0200 Subject: [PATCH 1/5] dt-bindings: reserved-memory: Add alloc-{bottom-up,top-down} MIME-Version: 1.0 Message-Id: <20230510-dt-resv-bottom-up-v1-1-3bf68873dbed@gerhold.net> References: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> In-Reply-To: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Frank Rowand Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: devicetree@vger.kernel.org Right now the allocation behavior for dynamic reserved memory is implementation-defined. On Linux it is dependent on the architecture. This is usually fine if the address is completely arbitrary. However, when using "alloc-ranges" it is helpful to allow controlling this. That way you can make sure that the reservations are placed next to other (static) allocations to keep the free memory contiguous if possible. Signed-off-by: Stephan Gerhold --- .../bindings/reserved-memory/reserved-memory.yaml | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml index c680e397cfd2..56f4bc6137e7 100644 --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml @@ -52,6 +52,18 @@ properties: Address and Length pairs. Specifies regions of memory that are acceptable to allocate from. + alloc-bottom-up: + type: boolean + description: > + Specifies that the memory region should be preferably allocated + at the lowest available address within the "alloc-ranges" region. + + alloc-top-down: + type: boolean + description: > + Specifies that the memory region should be preferably allocated + at the highest available address within the "alloc-ranges" region. + iommu-addresses: $ref: /schemas/types.yaml#/definitions/phandle-array description: > @@ -93,6 +105,10 @@ properties: system can use that region to store volatile or cached data that can be otherwise regenerated or migrated elsewhere. +dependencies: + alloc-bottom-up: [alloc-ranges] + alloc-top-down: [alloc-ranges] + allOf: - if: required: @@ -178,4 +194,27 @@ examples: }; }; }; + + - | + / { + compatible = "foo"; + model = "foo"; + + #address-cells = <2>; + #size-cells = <2>; + + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + adsp_mem: adsp { + size = <0x0 0x600000>; + alignment = <0x0 0x100000>; + alloc-ranges = <0x0 0x86800000 0x0 0x10000000>; + alloc-bottom-up; + no-map; + }; + }; + }; ... From patchwork Mon May 15 10:12:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 1781301 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gerhold.net header.i=@gerhold.net header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=WROWHfEy; dkim=pass header.d=gerhold.net header.i=@gerhold.net header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=0IzAm2OS; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QKZys6GWhz20dX for ; Mon, 15 May 2023 20:16:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241084AbjEOKQT (ORCPT ); Mon, 15 May 2023 06:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240414AbjEOKQL (ORCPT ); Mon, 15 May 2023 06:16:11 -0400 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1A632102; Mon, 15 May 2023 03:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684145544; cv=none; d=strato.com; s=strato-dkim-0002; b=T8Uit922Ztk76khdVJSDdctVn6H1THgKHsSXYuvr+EKjImFJ5E7zJF9AMM91JczFgG t51IDdXavoFrTxcE/+JkConLRr1Pkv1O+T3VtExVAejK7bNZxrXK0h39sqExka9ZsIHm DvXiaURmi8hEVPj3+xKcKomyd0nAtI4Lk3mIKfYUhlUxMvepW+YIEFLwtEIf/LCdIsVH vlIahSVpxljh0uVZe2qaPECyxSP64xUD3TmVtBWCMuoVbLHDw4Soe2AYnEg4iJrArT02 RUyU4/PPRxPKsdG7Zk4RzMjOUe4PxO++QVMKdhAHxz3PBBY/7BIstevhZRL1nuZEfx6y zyNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=strato.com; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=jfB/CpVNa1JJ+lCLjNohI5jzcdCGpDmi64bliceUj4E=; b=bC09aaEomTGV5NEiEiq0AOH/urBGNKEM/WfGT+qgQdfFrtI1BqsuKHJ9rXf7fdGCia sbCiafS8l1vCkM7XzRFX+q+mSSqBmEOM6xurlqtD2/t1Df14fsHxQdYAWdfKyM0lYY7t gh27yhgwLDWHIlFERSFxMlrI7kRb7D9cc5NrvKAp8ReVEARTMNHBK+2TqetvpsCpgNZv OIdtIHGiTYrFBkw2SwOdTyIYl0i3gXYtdY6eBSFHYE6Kv+odNenRcW6AA6SNV9pgcKFv hwQwOEGklFA/Lf5YkLRwtZID+ZC+fXpJA0x/HW6XAq/jUTFWqtC1rn+lyP0ou/hER5Ou ka1A== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=jfB/CpVNa1JJ+lCLjNohI5jzcdCGpDmi64bliceUj4E=; b=WROWHfEyjMq/Q/G1dolZPFwt4ZlT+ICnNtbgViYYzlfQwkEAcmL27Ezq8Lgr7439eC BHXmRl2eUjMEHnQyIVMgB+VoM6XCZNrMzH3/QOiOnP+MqFYha4Lj64im5n3vXH7Ea4Ch pxDms+Cf58akmv1XgezvGTPHzGCcJlMiBWvmWrVme3esZ30esR1G9NVpTGprb/U0r2Du 5oWM7c7l9c2VO1PjNuvrjwOuIElJo/1fcV+mZ+ypA4i1UcxaKvWpVo+6fKbu9IKW3qEg 4J95wqHk6h4KpGZ/1NZh8PVKGBKmyTVPT+d0CHWhahqMNmES7W5IBQ4RiIV64udkyLCF /FGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0003; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=jfB/CpVNa1JJ+lCLjNohI5jzcdCGpDmi64bliceUj4E=; b=0IzAm2OSKSa3+6O4Nfm1SUdH5UqnTb2zgC4j3SBLyKUO0zGxZdG3JlmLSrT7PZHhsE 1vgoLsnBEKs5RsAFeoBA== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVOQjVd4CteZ/7jYgS+mLFY+H0JAn8u4ly9TY=" Received: from [192.168.244.3] by smtp.strato.de (RZmta 49.4.0 DYNA|AUTH) with ESMTPSA id j6420az4FACO1JH (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 15 May 2023 12:12:24 +0200 (CEST) From: Stephan Gerhold Date: Mon, 15 May 2023 12:12:17 +0200 Subject: [PATCH 2/5] of: reserved_mem: Implement alloc-{bottom-up,top-down} MIME-Version: 1.0 Message-Id: <20230510-dt-resv-bottom-up-v1-2-3bf68873dbed@gerhold.net> References: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> In-Reply-To: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Frank Rowand Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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: devicetree@vger.kernel.org Use memblock_set_bottom_up() to specify an explicit allocation order for dynamic reservations with "alloc-ranges". Since the default value varies between architectures the previous value is saved and restored after trying the allocations. If neither alloc-bottom-up or alloc-top-down are specified the previous implementation-defined allocation order is preserved. Signed-off-by: Stephan Gerhold Acked-by: Konrad Dybcio --- drivers/of/of_reserved_mem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 948efa9f99e3..6443140deacf 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -89,7 +89,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, phys_addr_t base = 0, align = 0, size; int len; const __be32 *prop; - bool nomap; + bool nomap, prev_bottom_up; int ret; prop = of_get_flat_dt_prop(node, "size", &len); @@ -130,6 +130,12 @@ static int __init __reserved_mem_alloc_size(unsigned long node, return -EINVAL; } + prev_bottom_up = memblock_bottom_up(); + if (of_get_flat_dt_prop(node, "alloc-bottom-up", NULL)) + memblock_set_bottom_up(true); + if (of_get_flat_dt_prop(node, "alloc-top-down", NULL)) + memblock_set_bottom_up(false); + base = 0; while (len > 0) { @@ -148,6 +154,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, len -= t_len; } + memblock_set_bottom_up(prev_bottom_up); } else { ret = early_init_dt_alloc_reserved_memory_arch(size, align, 0, 0, nomap, &base); From patchwork Mon May 15 10:12:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 1781304 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gerhold.net header.i=@gerhold.net header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=op7/C51o; dkim=pass header.d=gerhold.net header.i=@gerhold.net header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=gMMt+EFd; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QKZyz2s57z20dX for ; Mon, 15 May 2023 20:16:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240886AbjEOKQZ (ORCPT ); Mon, 15 May 2023 06:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241077AbjEOKQN (ORCPT ); Mon, 15 May 2023 06:16:13 -0400 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE82173C; Mon, 15 May 2023 03:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684145544; cv=none; d=strato.com; s=strato-dkim-0002; b=gid8Z8GPX+8U8veQDzigS8Kg6g36Fygn5Di1dTukcxwv9ENyB9BT7VxZHsIFy2fLS5 A/LqUC1JPW00lcgXen7jK16CCDBjCluAkZEWAS2BHyfmAvVrGBymfKuXv509DjqpLywO b8ltprG0Wd+RKsm3/tk7f4haWCVOfSEcGaQbNIQFYyoZnwOOcd2x3ycFFYRtjcEqfgnE 1ZVL909FOqrOY5d1Qvb9LVmVQD1diy38FVZKscTk5by5QilsXcKgm8h2N/C5xU0ZzxNS ZssZslo9rhxI7cW5Op0dusCJ3M7q5WzNfNOD5k1/DV6zpolgMzP/+tJAVRAIPf0iJ3Tt z3Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=strato.com; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=DNTC0U3plBj7cthESRLpCld4G4lr+3CgqNixMQWGBow=; b=B640sq6QxE1g7r5NSs5nSKwdO0W6d5EZsOuxZ1B0bGH8H4VYZc2kuF6nfUSNze66oo uDYKmzbSB/feJ2pHf9fpDckepVVjyt47dwpfspm/S1syU8PnC/4ObI8Bg9Et/jkzTFIO eF0G+tb3SccVQRLWHdTwAFS/53TAXHEZMAmm6COT3TdPl3quPBeEC5pwZg7DFNlmyoJz Mtf0vtHHotD+zjRuDdXcy6tA2p/pkOv/txHRkUwrib0TcCGm6yc9jjTauOS1IqsP0kfu TVslfMhPw6UYTJ9bUI1QbL7szA/B0Imh9LOZd4jHwRyjvDV7I6iiWGji1PM2fdM5q49r Lgeg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0002; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=DNTC0U3plBj7cthESRLpCld4G4lr+3CgqNixMQWGBow=; b=op7/C51ozPARSOEyrMPwMTrmQQgjf+W/Gx3IIhxw7EY8aDIImpixNrB6PSIS2YAZXY 40c5+jU2bqPIKPwlhcf/8ua+4uttvlmm/Z0/UTxvg8f2ViJEY7u0OTzNUk2ZYM57ckr2 UxRbDawLu/LFc5R4r0PjCd1MlaX2+ncl70AdCmc6cgIHzC1n4bR1zQUBYlOtAjUHo18d lLO/Zc/p0ewSGPnRhZ1WbvI23htdtVmVzKiodXnNdfdJeK8ro8ttLYam85ebX+6eRD5b jRERkKUE+s13J+91vGLuX9gB7Fh4OL3RJUvznHHi0j5w6JZ0xq2LAkW+UbhSGwojrSUf tW8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1684145544; s=strato-dkim-0003; d=gerhold.net; h=Cc:To:In-Reply-To:References:Message-Id:Subject:Date:From:Cc:Date: From:Subject:Sender; bh=DNTC0U3plBj7cthESRLpCld4G4lr+3CgqNixMQWGBow=; b=gMMt+EFdTB5ds3J1kxDXQo7JfoVyAQx2QRs1dmiW5lPRexdNCZs/JQvvOFUBF4781W MEy3TBDkmpRCfTcEnkBQ== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVOQjVd4CteZ/7jYgS+mLFY+H0JAn8u4ly9TY=" Received: from [192.168.244.3] by smtp.strato.de (RZmta 49.4.0 DYNA|AUTH) with ESMTPSA id j6420az4FACO1JI (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 15 May 2023 12:12:24 +0200 (CEST) From: Stephan Gerhold Date: Mon, 15 May 2023 12:12:18 +0200 Subject: [PATCH 3/5] of: reserved_mem: Use stable allocation order MIME-Version: 1.0 Message-Id: <20230510-dt-resv-bottom-up-v1-3-3bf68873dbed@gerhold.net> References: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> In-Reply-To: <20230510-dt-resv-bottom-up-v1-0-3bf68873dbed@gerhold.net> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Frank Rowand Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: devicetree@vger.kernel.org sort() in Linux is based on heapsort which is not a stable sort algorithm - equal elements are being reordered. For reserved memory in the device tree this happens mainly for dynamic allocations: They do not have an address to sort with, so they are reordered somewhat randomly when adding/removing other unrelated reserved memory nodes. Functionally this is not a big problem, but it's confusing during development when all the addresses change after adding unrelated reserved memory nodes. Make the order stable by sorting dynamic allocations according to the node order in the device tree. Static allocations are not affected by this because they are still sorted by their (fixed) address. Signed-off-by: Stephan Gerhold --- drivers/of/of_reserved_mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 6443140deacf..f6d14354a534 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -224,6 +224,11 @@ static int __init __rmem_cmp(const void *a, const void *b) if (ra->size > rb->size) return 1; + if (ra->fdt_node < rb->fdt_node) + return -1; + if (ra->fdt_node > rb->fdt_node) + return 1; + return 0; }