Message ID | 20230406151429.524591-3-tanure@linux.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1126130vqo; Thu, 6 Apr 2023 08:50:24 -0700 (PDT) X-Google-Smtp-Source: AKy350aUHBOpBpDyJ3hXIqiY1RokwS8lCQOHO9TLxd3EmqL6S7pdvs0k5+SomuOQVvLymzgkeNPB X-Received: by 2002:a17:90b:1bcc:b0:23c:fef0:d441 with SMTP id oa12-20020a17090b1bcc00b0023cfef0d441mr11475184pjb.33.1680796223749; Thu, 06 Apr 2023 08:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680796223; cv=none; d=google.com; s=arc-20160816; b=qT1LRaTJM6ojMNpG1qbyb1BfZewKzoovxCFLSxl4trAWd3qVKjEeIikq975r0O/Mh9 zsSr97wO+UPpab9Y7+Do3TFItgG9yOUbB+A6IhGtPB68MXKt3Gpr39TtEvGmXI1jS5r9 xH8w49yzsxiA5jHH5NdS4eTG1oAyFWLS1tHUbhzo+yfqepdOA6l5koDdbTPWIIS0xXAU Kx7abtR9g3JXWsVSB43tzaX5t7XnbHvKukkPY/0qRXS9isZV5hWGROrE5VU6vdiqj23t loP9Kiu+oLfqg2hA4pUXOm3aDYW9AsG4M7t9nzFpesNZF0RSc2Sge2plupF4bXACIcP6 kwEw== 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; bh=VKATmeJF+Xd6RfEgdIKd/kdycc50pAq48rMDI6zu3z4=; b=vDYwjigznEccRJKqE+EbX+vbwkWIgLvN4nDwyVsTWlt0wCCThPkzlNv+FEtkhDOtqb X1o0aeEH2dJKJNjXyWm7YPkesrDtNhRfUNoddjVDFHQ33PWPKBsoKq6shuZk1vKjpucD 6n4gXHyGiJUr7dF5NE7vevZfInalUWw66N/xSl810t0nQFCsYvYChfUwoXscIuoIWKG7 pH8tFLQkhCp49cOaEtegjzIdezpnwEh1kFHjgMS3T9onKF1yBfTb8hFWWi/enJxNpBKF oqeTyY65hHZ/UHGn7VFLt5LMrVzfQAfT0LMT2KD3SJ5PpRfuH7nzcIKe2whtc86EjRcs DBSA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp9-20020a17090b4a8900b0023f1eccd286si1704346pjb.107.2023.04.06.08.50.11; Thu, 06 Apr 2023 08:50:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239733AbjDFPPD (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Thu, 6 Apr 2023 11:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239727AbjDFPOt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 6 Apr 2023 11:14:49 -0400 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E4E81980; Thu, 6 Apr 2023 08:14:48 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id d11-20020a05600c3acb00b003ef6e6754c5so20277344wms.5; Thu, 06 Apr 2023 08:14:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680794086; x=1683386086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VKATmeJF+Xd6RfEgdIKd/kdycc50pAq48rMDI6zu3z4=; b=dt+SmTvy2gx2thRpX0PbgTQkGnR50qRgsPB8Eh9n0afq9RSCNEQn4GbNyOvTfjqUJm W7zZ2I2n230HU6Q/ozN+wVs4VClgTivAw1HfR1Df9ELv0UBLnN9+NVrQueFfOAcgxAl3 uYh2WZR9loalROn20tVp655TpDJAHKnc4EKUoFBvWJnv0Q1EiC9lR7KjDJGggFYiwIvn C9eo0+KrPfLgBu5A40eOmGznzSkgmwHZstIdZ96MSQYh014T2GZNXab/fhTWtPKjnRTF Cq70AtNfaMM24LLI6x2Iy488+X3O0lqsoAgA/wjmsBnP7FIqEl6FZ3Fhb65I8fxV/Xqv WhWw== X-Gm-Message-State: AAQBX9cc2txjeWIOQcER1H7lZT8S6AYWZhAieFKIJ0a5IDWpZpOoWc8U w68K6QUz2zyaGeYM9PRSP+k= X-Received: by 2002:a7b:c850:0:b0:3ef:6ea4:a675 with SMTP id c16-20020a7bc850000000b003ef6ea4a675mr7787556wml.36.1680794086552; Thu, 06 Apr 2023 08:14:46 -0700 (PDT) Received: from ryzen.lan (cpc87451-finc19-2-0-cust61.4-2.cable.virginm.net. [82.11.51.62]) by smtp.gmail.com with ESMTPSA id fj12-20020a05600c0c8c00b003ef67848a21sm5560213wmb.13.2023.04.06.08.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 08:14:46 -0700 (PDT) From: Lucas Tanure <tanure@linux.com> To: Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>, Mike Rapoport <rppt@kernel.org>, Andrew Morton <akpm@linux-foundation.org> Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jbrunet@baylibre.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, martin.blumenstingl@googlemail.com, narmstrong@baylibre.com, stefan@agner.ch, Lucas Tanure <tanure@linux.com> Subject: [PATCH 2/2] of: fdt: Allow the kernel to mark nomap regions received from fdt Date: Thu, 6 Apr 2023 16:14:29 +0100 Message-Id: <20230406151429.524591-3-tanure@linux.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230406151429.524591-1-tanure@linux.com> References: <20230406151429.524591-1-tanure@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762442580840683927?= X-GMAIL-MSGID: =?utf-8?q?1762442580840683927?= |
Series |
Fix Random Kernel panic from when fail to reserve memory
|
|
Commit Message
Lucas Tanure
April 6, 2023, 3:14 p.m. UTC
Reserved regions can be described in FDT and device trees, but FDT doesn't
provide the related flags, like nomap.
So allow the kernel to mark regions where the base and size received from
the device tree are the same as the base and region on FDT.
Here we trust that the device tree has a more updated description of the
region than the one received from FDT.
Signed-off-by: Lucas Tanure <tanure@linux.com>
---
drivers/of/fdt.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
Comments
On Thu, Apr 6, 2023 at 10:14 AM Lucas Tanure <tanure@linux.com> wrote: > > Reserved regions can be described in FDT and device trees, but FDT doesn't > provide the related flags, like nomap. It took me a minute to understand what you meant by FDT vs. device trees. Use the exact things you are talking about: /memreserve/ and /reserved-memory node. > So allow the kernel to mark regions where the base and size received from > the device tree are the same as the base and region on FDT. > Here we trust that the device tree has a more updated description of the > region than the one received from FDT. > > Signed-off-by: Lucas Tanure <tanure@linux.com> > --- > drivers/of/fdt.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index d1a68b6d03b3..754a7ea4f45c 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -482,11 +482,13 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base, > if (nomap) { > /* > * If the memory is already reserved (by another region), we > - * should not allow it to be marked nomap, but don't worry > - * if the region isn't memory as it won't be mapped. > + * should not allow it to be marked nomap, unless is the exact same region > + * (same base and size), which the kernel knows better and should be allowed to mark > + * it as nomap. > + * But don't worry if the region isn't memory as it won't be mapped. > */ > - if (memblock_overlaps_region(&memblock.memory, base, size) && > - memblock_is_region_reserved(base, size)) > + if (memblock_overlaps_region(&memblock.memory, base, size) == MEMBLOCK_OVERLAPS && > + memblock_is_region_reserved(base, size) == MEMBLOCK_OVERLAPS) Won't this fail to work as IIRC memblock will merge regions when they are adjacent and have the same atrributes. Perhaps instead, the DT code should ignore any /memreserve/ entries that are also in /reserved-memory. I would suggest just reverse the order they are processed, but I suspect that might cause some regression. This code is all fragile especially with platforms putting in 100 regions. Finally, perhaps fix u-boot. The reason the reserved location goes in both places was to support an OS not supporting /reserved-memory. I think that support has been in place for a lot longer than anyone would care about. Rob
On 06/04/2023 17:48, Rob Herring wrote: > On Thu, Apr 6, 2023 at 10:14 AM Lucas Tanure <tanure@linux.com> wrote: >> >> Reserved regions can be described in FDT and device trees, but FDT doesn't >> provide the related flags, like nomap. > > It took me a minute to understand what you meant by FDT vs. device > trees. Use the exact things you are talking about: /memreserve/ and > /reserved-memory node. > >> So allow the kernel to mark regions where the base and size received from >> the device tree are the same as the base and region on FDT. >> Here we trust that the device tree has a more updated description of the >> region than the one received from FDT. >> >> Signed-off-by: Lucas Tanure <tanure@linux.com> >> --- >> drivers/of/fdt.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c >> index d1a68b6d03b3..754a7ea4f45c 100644 >> --- a/drivers/of/fdt.c >> +++ b/drivers/of/fdt.c >> @@ -482,11 +482,13 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base, >> if (nomap) { >> /* >> * If the memory is already reserved (by another region), we >> - * should not allow it to be marked nomap, but don't worry >> - * if the region isn't memory as it won't be mapped. >> + * should not allow it to be marked nomap, unless is the exact same region >> + * (same base and size), which the kernel knows better and should be allowed to mark >> + * it as nomap. >> + * But don't worry if the region isn't memory as it won't be mapped. >> */ >> - if (memblock_overlaps_region(&memblock.memory, base, size) && >> - memblock_is_region_reserved(base, size)) >> + if (memblock_overlaps_region(&memblock.memory, base, size) == MEMBLOCK_OVERLAPS && >> + memblock_is_region_reserved(base, size) == MEMBLOCK_OVERLAPS) > > Won't this fail to work as IIRC memblock will merge regions when they > are adjacent and have the same atrributes. > > Perhaps instead, the DT code should ignore any /memreserve/ entries > that are also in /reserved-memory. > > I would suggest just reverse the order they are processed, but I > suspect that might cause some regression. This code is all fragile > especially with platforms putting in 100 regions. > > Finally, perhaps fix u-boot. The reason the reserved location goes in > both places was to support an OS not supporting /reserved-memory. I > think that support has been in place for a lot longer than anyone > would care about. Fixing U-Boot won't fix already tagged and in-the-field mainline u-boot releases that adds /memreserve/ entries, so yes u-boot should be definitely fixed but Linux should ignore the /memreserve/ entries when they matches an /reserved-memory node like when the U-Boot /memreserve/ code was added. Neil > > Rob > > _______________________________________________ > linux-amlogic mailing list > linux-amlogic@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-amlogic
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d1a68b6d03b3..754a7ea4f45c 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -482,11 +482,13 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base, if (nomap) { /* * If the memory is already reserved (by another region), we - * should not allow it to be marked nomap, but don't worry - * if the region isn't memory as it won't be mapped. + * should not allow it to be marked nomap, unless is the exact same region + * (same base and size), which the kernel knows better and should be allowed to mark + * it as nomap. + * But don't worry if the region isn't memory as it won't be mapped. */ - if (memblock_overlaps_region(&memblock.memory, base, size) && - memblock_is_region_reserved(base, size)) + if (memblock_overlaps_region(&memblock.memory, base, size) == MEMBLOCK_OVERLAPS && + memblock_is_region_reserved(base, size) == MEMBLOCK_OVERLAPS) return -EBUSY; return memblock_mark_nomap(base, size);