Received: by 10.213.65.68 with SMTP id h4csp2391493imn; Thu, 5 Apr 2018 14:14:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/QlfNu2hTP0/4jVrkcKfcqIytfjODEaCjv4HvLwHvWheFxvGcJ1hp6lyLRKcIAqIiWwuxC X-Received: by 2002:a17:902:2863:: with SMTP id e90-v6mr24913573plb.58.1522962850453; Thu, 05 Apr 2018 14:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522962850; cv=none; d=google.com; s=arc-20160816; b=e2q9eSvHtfb/QNAAy1epeY+zAIBNY1wgTZ6voeaadsCX57xL8VugloBEbDk569p10n P7aJxdFUV61XU/MXuoxblCdFrifm9Xx7mqTVPy7bM/+M+2z45mha3JWavQeQJoLuVkNM hE6/EI9FIs4HLe3K+IXZwtDQ9zMJ+kwV/xhLoxAe8Qc9wrB82FrXA2H6cPNfEmwkC8xl DillizKa2JJLELwk5bajhY4OvpYP0x8e+ASPen/zccPki4YGG7gB9mqEOerQYd37CL4m vc6YJYsM29oIRB6hyyZK1XPxibpbq9Uin9EJVuK2z2u8gAXycVtHY+DQnVOgvZZR3yZW sZ4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=X3WcKGOjI1B6ojNBi3C+jaLrxuRXdCQfIeqtD7GBQTM=; b=auIfrQJFjcWCavHitGsSLkY/jInjO0OZY4pMySnEEcrKLZ76v/Bq3k74lfpj7CPD0D fqrVAU9NolYANdT6TtzcuXct2/WMiqSgcKHsfoEaaYZicAHmR/NW7vZv7ecB2ibRY3am vmjnUxruhoT3Q02BSS1OxbWQ/urOCMcyMpgTY0cx+iXni0bLBXxbLLhuHUogK7iKDbr7 4hd4HTo8DLQQBmxH2hFiyiV2RxwRyT0E8/IgV/gR8ZE4TfmSY64a+G7s2SIsJDLJ6Fra Bsn6xuZ3VrqyE0iBjsoHjSSSbcykP5WFfQOVb/e8ll2xFyvZlzEuS6CNWCJ+Vq25lSHv De/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si5859858pgv.668.2018.04.05.14.13.51; Thu, 05 Apr 2018 14:14:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751417AbeDEVMm (ORCPT + 99 others); Thu, 5 Apr 2018 17:12:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbeDEVMk (ORCPT ); Thu, 5 Apr 2018 17:12:40 -0400 Received: from mail-qk0-f178.google.com (mail-qk0-f178.google.com [209.85.220.178]) (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 12AFA21836; Thu, 5 Apr 2018 21:12:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12AFA21836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=robh+dt@kernel.org Received: by mail-qk0-f178.google.com with SMTP id 132so27912681qkd.5; Thu, 05 Apr 2018 14:12:40 -0700 (PDT) X-Gm-Message-State: ALQs6tCW8oAH1XowALjZPq6tjCxqbTTSmd40BiphbDXljrecWDs4FTc2 NQIkjzApa/KqiSR/yhWMPzZ9FQ5kqMKTnxn+sQ== X-Received: by 10.55.31.165 with SMTP id n37mr30814240qkh.184.1522962759066; Thu, 05 Apr 2018 14:12:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.213.166 with HTTP; Thu, 5 Apr 2018 14:12:18 -0700 (PDT) In-Reply-To: References: <1520122673-11003-1-git-send-email-frowand.list@gmail.com> <1520122673-11003-3-git-send-email-frowand.list@gmail.com> <09e3db63-cbf9-52a2-ee77-520979f17fea@web.de> <7bbf615b-3cdd-6bb4-6918-33e48de4225d@gmail.com> From: Rob Herring Date: Thu, 5 Apr 2018 16:12:18 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 2/5] of: change overlay apply input data from unflattened to FDT To: Frank Rowand Cc: Jan Kiszka , Pantelis Antoniou , Pantelis Antoniou , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , Geert Uytterhoeven , Laurent Pinchart , Jailhouse Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 5, 2018 at 2:28 PM, Frank Rowand wrote: > On 04/05/18 12:13, Jan Kiszka wrote: >> On 2018-04-05 20:59, Frank Rowand wrote: >>> Hi Jan, >>> >>> On 04/04/18 15:35, Jan Kiszka wrote: >>>> Hi Frank, >>>> >>>> On 2018-03-04 01:17, frowand.list@gmail.com wrote: >>>>> From: Frank Rowand >>>>> >>>>> Move duplicating and unflattening of an overlay flattened devicetree >>>>> (FDT) into the overlay application code. To accomplish this, >>>>> of_overlay_apply() is replaced by of_overlay_fdt_apply(). >>>>> >>>>> The copy of the FDT (aka "duplicate FDT") now belongs to devicetree >>>>> code, which is thus responsible for freeing the duplicate FDT. The >>>>> caller of of_overlay_fdt_apply() remains responsible for freeing the >>>>> original FDT. >>>>> >>>>> The unflattened devicetree now belongs to devicetree code, which is >>>>> thus responsible for freeing the unflattened devicetree. >>>>> >>>>> These ownership changes prevent early freeing of the duplicated FDT >>>>> or the unflattened devicetree, which could result in use after free >>>>> errors. >>>>> >>>>> of_overlay_fdt_apply() is a private function for the anticipated >>>>> overlay loader. >>>> >>>> We are using of_fdt_unflatten_tree + of_overlay_apply in the >>>> (out-of-tree) Jailhouse loader driver in order to register a virtual >>>> device during hypervisor activation with Linux. The DT overlay is >>>> created from a a template but modified prior to application to account >>>> for runtime-specific parameters. See [1] for the current implementation. >>>> >>>> I'm now wondering how to model that scenario best with the new API. >>>> Given that the loader lost ownership of the unflattened tree but the >>>> modification API exist only for the that DT state, I'm not yet seeing a >>>> clear solution. Should we apply the template in disabled form (status = >>>> "disabled"), modify it, and then activate it while it is already applied? >>> >>> Thank you for the pointer to the driver - that makes it much easier to >>> understand the use case and consider solutions. >>> >>> If you can make the changes directly on the FDT instead of on the >>> expanded devicetree, then you could move to the new API. >> >> Are there some examples/references on how to edit FDTs in-place in the >> kernel? I'd like to avoid writing the n-th FDT parser/generator. > > I don't know of any existing in-kernel edits of the FDT (but they might > exist). The functions to access an FDT are in libfdt, which is in > scripts/dtc/libfdt/. Let's please not go down that route of doing FDT modifications. There is little reason to other than for early boot changes. And it is much easier to work on unflattened trees. Rob