Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4058096pxu; Tue, 20 Oct 2020 07:22:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv6wRmhAeBvuFvTtq/XeeA9sbDajkDQ6ivebd1578Rhc73TQowtU9RodV/IpCs1x5XpSfL X-Received: by 2002:a17:906:3bc7:: with SMTP id v7mr3240276ejf.245.1603203738435; Tue, 20 Oct 2020 07:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603203738; cv=none; d=google.com; s=arc-20160816; b=bEytyImA5egdMMA1UwKhLpRZWF1iF8MPIX+jDuQROIuyJs9M9715qgIzwOSjgJSrbl Ly/okRQ0zfIh2mtD4z5QCMcCc26ejWpnhB+Aef806WH9STz8IPIqxvYiB4G7miEbKCJg ELQtAMdVInU0SG8B/yGVeAqgsDKG1QPm3sVoc2hEqMZTLItOaoTcMWER7gzVdrisnbOl 4esaLfMVBGvgVs89Ly4CrWZ6PbPMY4B4VSkeE7GnzkQmoJOYhUFUJB5r9jPWBDR+ITu7 TKiMM1W0qg8LchIO6ocU06HR2L0umlqlRYxEnl4PZwalTltvONJTQbG2N8/Tmq3Rmza9 JbeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MlBaKhZP4GI0VebiAfqCnBLgaq4+S2Nzio5iVEsG/JE=; b=0+HO8C/R9IAL4ogqO4OfP+eW0pldiJWqihN1FMZbRvwZPzdptFZqvn1GxalFxNm563 1gxWsaUsdFDAxP/ZjAP79uXH3Gtex63RaYyahlaHVJPRO//hqszvzX3M6+aWcOVAIKXI 6ZbR7sU905iRVuyZJj2FstUoGcDFOShn5tyA4cNLrv2zn3uGok/aXi6OZr6pQvOhDBnz tCGvaetDcR5KPwcheK5lo8HTu8JFONv56Oe3Trd/NuHBGUmTT9YAVWlNKWfXMDri+yGT w4C1to6etl94/hkyGIqJVUe2ayqzuDzVDDZtjBPYdqUjaTSdBmdvX8oShCsgfswUJenJ etrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=loKa6NqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si1342021edk.97.2020.10.20.07.21.55; Tue, 20 Oct 2020 07:22:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=loKa6NqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407948AbgJTORl (ORCPT + 99 others); Tue, 20 Oct 2020 10:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:42436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407909AbgJTORk (ORCPT ); Tue, 20 Oct 2020 10:17:40 -0400 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B9C92098B; Tue, 20 Oct 2020 14:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603203460; bh=7rH2oCmShidqtPeA4u5rqM8J73bTkhhLU52QiXSBT40=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=loKa6NqWkAorw1V+jQUaedGQesUGpg8Ez9fJnm1t9IEMJ9eNUcaWAyTk1ZDfJTUFH /796j9czwnLAg57zLBoO0ALBSNgxfnM1XnNNQwquHJtCuymT8YvUH9assDv4ixZcz9 DM9tMUmlifgD9y5kEG1Z7PT6qmEB21+Ejdb16j5c= Received: by mail-oi1-f174.google.com with SMTP id l4so2265877oii.13; Tue, 20 Oct 2020 07:17:40 -0700 (PDT) X-Gm-Message-State: AOAM530i+ZNcXtqD7JuSvPV0Tb7C8Sbif9KV/tEGsJXTHz4Bflq51xLs i6p99AEvomzkdKMWOWj2SIHt2LkpwoTlCpwpQQ== X-Received: by 2002:aca:4c52:: with SMTP id z79mr2072666oia.147.1603203459435; Tue, 20 Oct 2020 07:17:39 -0700 (PDT) MIME-Version: 1.0 References: <20201020073558.3582-1-vincent.whitchurch@axis.com> <20201020134633.3vv7hyvodg4tbro2@axis.com> In-Reply-To: <20201020134633.3vv7hyvodg4tbro2@axis.com> From: Rob Herring Date: Tue, 20 Oct 2020 09:17:27 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: Fix reserved-memory overlap detection To: Vincent Whitchurch Cc: Frank Rowand , kernel , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2020 at 8:46 AM Vincent Whitchurch wrote: > > On Tue, Oct 20, 2020 at 03:00:14PM +0200, Rob Herring wrote: > > On Tue, Oct 20, 2020 at 2:36 AM Vincent Whitchurch > > wrote: > > > > > > The reserved-memory overlap detection code fails to detect overlaps if > > > either of the regions starts at address 0x0. For some reason the code > > > explicitly checks for and ignores such regions, but this check looks > > > invalid. Remove the check and fix this detection. > > > > Wouldn't 'base' be 0 for nodes that have a 'size' and no address? The > > base in those cases isn't set until later when > > __reserved_mem_alloc_size() is called. > > Ah, yes, I guess that's why the check was there. I see that those > entries have both a zero address and a zero size, so this seems to work: Yes, I think it should work. > > diff --git a/arch/arm/boot/dts/vexpress-v2p-ca9.dts b/arch/arm/boot/dts/vexpress-v2p-ca9.dts > index 623246f37448..6627e71c7283 100644 > --- a/arch/arm/boot/dts/vexpress-v2p-ca9.dts > +++ b/arch/arm/boot/dts/vexpress-v2p-ca9.dts > @@ -81,6 +81,18 @@ vram: vram@4c000000 { > reg = <0x4c000000 0x00800000>; > no-map; > }; > + > + foo@0 { > + reg = <0x0 0x2000>; > + }; > + > + bar@1000 { > + reg = <0x0 0x1000>; 0x1000 base? > + }; > + > + baz { > + size = <0x1000>; > + }; > }; > > clcd@10020000 { > diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c > index 46b9371c8a33..fea9433d942a 100644 > --- a/drivers/of/of_reserved_mem.c > +++ b/drivers/of/of_reserved_mem.c > @@ -200,6 +200,16 @@ static int __init __rmem_cmp(const void *a, const void *b) > if (ra->base > rb->base) > return 1; > > + /* > + * Put the dynamic allocations (address == 0, size == 0) before static > + * allocations at address 0x0 so that overlap detection works > + * correctly. > + */ > + if (ra->size < rb->size) > + return -1; > + if (ra->size > rb->size) > + return 1; > + > return 0; > } > > @@ -212,13 +222,19 @@ static void __init __rmem_check_for_overlap(void) > > sort(reserved_mem, reserved_mem_count, sizeof(reserved_mem[0]), > __rmem_cmp, NULL); > + > + for (i = 0; i < reserved_mem_count - 1; i++) { > + struct reserved_mem *this = &reserved_mem[i]; > + > + pr_info("i %d base %x size %x\n", i, this->base, this->size); > + } > + > for (i = 0; i < reserved_mem_count - 1; i++) { > struct reserved_mem *this, *next; > > this = &reserved_mem[i]; > next = &reserved_mem[i + 1]; > - if (!(this->base && next->base)) > - continue; > + > if (this->base + this->size > next->base) { > phys_addr_t this_end, next_end; >