From patchwork Fri Jan 15 11:45:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 1426932 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=sIFw66fH; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHKCr1c7rz9sVr for ; Fri, 15 Jan 2021 22:47:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728593AbhAOLqc (ORCPT ); Fri, 15 Jan 2021 06:46:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbhAOLqb (ORCPT ); Fri, 15 Jan 2021 06:46:31 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50BCFC0613D3 for ; Fri, 15 Jan 2021 03:45:51 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id b24so7008464qtt.22 for ; Fri, 15 Jan 2021 03:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Rz2b+XEvx25E0d7OPlpAzQcwuev8Qgbux4h+dak74dg=; b=sIFw66fH47WMRfKdYPomiYUnm03OJCKfEvISckqLpB2W5No42YW8N3BsxiahD/JLuh dSkzcXtK3CsvZjnjv/d+QicPOyE9bNeT42/EcF+6xasp1ylCtruksdkwZSRp4Q0jNSv1 ekbpNY1HRjggYzxqxVHmYCMMAEExxPDfpLgD0X3BW4mk0TO6/tVNYL3ZYCdyRZwbqOZl spiou8LekqUnBVsLRsTZg3CuAR/TAo5ORjd0+LCakWbvVgc5Dy5/98DhqZztuNQo8riw w90cQulHlK1qBU5V7cGFOTvOf9uiiIgPSMAEBee4C+ibJ2JLQrp6LhMeAxxLUI/zGzMD +AVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Rz2b+XEvx25E0d7OPlpAzQcwuev8Qgbux4h+dak74dg=; b=NiSG5ZZtvLwuouGxsz/1GnPIqnZ94sh+lFD5VGb/dQ5Mq8GNmc5PSvFvihstEJWrsS 9e6ttUHS96BkLzys9X3WJozVrIC9cHRkHUW2xerWfMq0KfqF43ch95FVrlB5337TXStS HYRRZ4fT+UI3GDpimGvINvh3lHwaGTDWnLT47WUG4b4HegbZuyG3HIXiTYqsY2lJp+EB QFlLuY/Lm4zynoJVXWjTdovAX8q8AR6dVuJKS/zFnHgjj4TEQrIoFLJds/KdwVojggET Nrqf8OSrBukzh1IvOIxKihUkeaQq+QVXa1llGL9JM41dCwsIqzddI/3zD56oM8I+4qBu 3hAg== X-Gm-Message-State: AOAM533Pg0Rt7b0ld0jO/cSXgWNyBtJgIudkVn8zOEe2RiMHhzmOfhrs 6Rbq6TgGm1qX5nz8rxEUKdkLmIJK0onb X-Google-Smtp-Source: ABdhPJwphIAmMLFWWoitWR5YhAGbWyj24kH7lzmC4hmsSiOHBm/Jebxz9uyGGb+mXmbPoZWjIKvVBHJaKcu7 Sender: "qperret via sendgmr" X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:ad4:5491:: with SMTP id q17mr11657655qvy.62.1610711150448; Fri, 15 Jan 2021 03:45:50 -0800 (PST) Date: Fri, 15 Jan 2021 11:45:43 +0000 In-Reply-To: <20210115114544.1830068-1-qperret@google.com> Message-Id: <20210115114544.1830068-2-qperret@google.com> Mime-Version: 1.0 References: <20210115114544.1830068-1-qperret@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 1/2] fdt: Properly handle "no-map" field in the memory region From: Quentin Perret To: robh+dt@kernel.org, frowand.list@gmail.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, drinkcat@chromium.org, swboyd@chromium.org, f.fainelli@gmail.com, karahmed@amazon.de, kernel-team@android.com Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: KarimAllah Ahmed Mark the memory region with NOMAP flag instead of completely removing it from the memory blocks. That makes the FDT handling consistent with the EFI memory map handling. Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: KarimAllah Ahmed Signed-off-by: Quentin Perret --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index feb0f2d67fc5..427b534d60d2 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1147,7 +1147,7 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size, bool nomap) { if (nomap) - return memblock_remove(base, size); + return memblock_mark_nomap(base, size); return memblock_reserve(base, size); } From patchwork Fri Jan 15 11:45:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 1426933 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=NGPjIfYx; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHKCz5MyKz9sSC for ; Fri, 15 Jan 2021 22:47:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbhAOLrL (ORCPT ); Fri, 15 Jan 2021 06:47:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbhAOLrK (ORCPT ); Fri, 15 Jan 2021 06:47:10 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4C6C061795 for ; Fri, 15 Jan 2021 03:45:53 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id k126so7666668qkf.8 for ; Fri, 15 Jan 2021 03:45:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=jR//nrlijl/JEPmJhF1uzhnuEqPPRoekagqUwRo/Wps=; b=NGPjIfYxeqdggFn0u42r+MwCt7fcCb+wOyNjTm0ctsFkxreS2Ffu8SRGHqhs0XWLbL +HC2gFKPh7WaOkbsWr3THWOSM5ljVoBQVV8EsAvbVp4Eoi3at0yKmhVlZvlp0WghefDt 3U+TYnTCRMNuCmPtJQ49lVNiN9ysRsCwIIx90PEiE8pTamnzhRy+3YNidyS4JikS95t4 wD6QHUqG28ZLTp260KgzM572Cj5IFyFQuF5y8Ek0oIoE9SzALmpLFN+Zp7aZaNg1Z3xN D1WY81Es/YODjFsLFoiV6C4sPToyQAyzwbIj5yFUW+LElCnpfsO+dLCGPH6pL6DXf9Rf stUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jR//nrlijl/JEPmJhF1uzhnuEqPPRoekagqUwRo/Wps=; b=a9vatMvCFRGa8XDtrZdLP+moWa8ajsgKMq7CMEsi94ySxOXhFVg2GeUsjbCalFOGH6 c0gF+mrElZ5BCI2PJQV6spln9qHky3ABt6DSZbcXboxijxVp/ccrj8mMmO7igUC4Pe5X rI47dULokwz0pfyVqi3W5DdbEKUWrGoxH6q46zOCzI0umfRg/xhbhvaFlrFIEP6HjFqe C3881Zz9BKsA8HCMXc8hNslaRwO8K5TAb/EbMxQPSX9xkhKg8cSTy+JsISxQWsniuTZL 4naDg4wQdAzqLlnzaR9OFuMLhnIvI8l+t0+aO1MwL4Pi3x8PWA52Flt7nn9ttjAWnd3A lfLw== X-Gm-Message-State: AOAM532vY1Z/yEjcwDjTM7wLkJIweW1OepbPz66ToMI/8DlPTwWZRq24 Kj5L+ae3etl6L0Fjr8QYE6LNlIjF02Uc X-Google-Smtp-Source: ABdhPJzig+EXRL+D7XvYHYAIQivncwYh6hTL6zFdhd5ydmxvjATXyRAcl027gxFVsO0+c9Ta3VivoGMe9AQK Sender: "qperret via sendgmr" X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:6214:b12:: with SMTP id u18mr5640495qvj.21.1610711152432; Fri, 15 Jan 2021 03:45:52 -0800 (PST) Date: Fri, 15 Jan 2021 11:45:44 +0000 In-Reply-To: <20210115114544.1830068-1-qperret@google.com> Message-Id: <20210115114544.1830068-3-qperret@google.com> Mime-Version: 1.0 References: <20210115114544.1830068-1-qperret@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 2/2] of/fdt: Make sure no-map does not remove already reserved regions From: Quentin Perret To: robh+dt@kernel.org, frowand.list@gmail.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, drinkcat@chromium.org, swboyd@chromium.org, f.fainelli@gmail.com, karahmed@amazon.de, kernel-team@android.com Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Nicolas Boichat If the device tree is incorrectly configured, and attempts to define a "no-map" reserved memory that overlaps with the kernel data/code, the kernel would crash quickly after boot, with no obvious clue about the nature of the issue. For example, this would happen if we have the kernel mapped at these addresses (from /proc/iomem): 40000000-41ffffff : System RAM 40080000-40dfffff : Kernel code 40e00000-411fffff : reserved 41200000-413e0fff : Kernel data And we declare a no-map shared-dma-pool region at a fixed address within that range: mem_reserved: mem_region { compatible = "shared-dma-pool"; reg = <0 0x40000000 0 0x01A00000>; no-map; }; To fix this, when removing memory regions at early boot (which is what "no-map" regions do), we need to make sure that the memory is not already reserved. If we do, __reserved_mem_reserve_reg will throw an error: [ 0.000000] OF: fdt: Reserved memory: failed to reserve memory for node 'mem_region': base 0x0000000040000000, size 26 MiB and the code that will try to use the region should also fail, later on. We do not do anything for non-"no-map" regions, as memblock explicitly allows reserved regions to overlap, and the commit that this fixes removed the check for that precise reason. [ qperret: fixed conflicts caused by the usage of memblock_mark_nomap ] Fixes: 094cb98179f19b7 ("of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap") Signed-off-by: Nicolas Boichat Reviewed-by: Stephen Boyd Signed-off-by: Quentin Perret --- drivers/of/fdt.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 427b534d60d2..dcc1dd96911a 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1146,8 +1146,16 @@ int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size) int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size, bool nomap) { - if (nomap) + if (nomap) { + /* + * If the memory is already reserved (by another region), we + * should not allow it to be marked nomap. + */ + if (memblock_is_region_reserved(base, size)) + return -EBUSY; + return memblock_mark_nomap(base, size); + } return memblock_reserve(base, size); }