Received: by 10.213.65.68 with SMTP id h4csp2300545imn; Thu, 5 Apr 2018 12:29:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/mlzIrxOoE4eTOol7hMQEQ3rO1eAilNtDtwthPvZL6h8aNzhtKwsiRHfaZ2m2apKh5M8N+ X-Received: by 2002:a17:902:228:: with SMTP id 37-v6mr24234539plc.141.1522956546085; Thu, 05 Apr 2018 12:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522956546; cv=none; d=google.com; s=arc-20160816; b=FkBPh2IgifTBflI4hnXDXIC/UwBnai/No6VMS+yAwO26Qr6RUNDtIa3dCuxu7l2Kh/ gwaq3OJY7Sz3Z958qTBXOOgNXI2FNM9Jwew3QKPadVfC1diMhcSIPAvh7BN6JWqF2lTP s15RVCn8ECwndjQ/x6FOdLX4Lczi0B9dzTYmyXsN2m905y7RL+8Nehn8LAUK3keSUuKZ TcDGG7m7PZT0gCkbt2r8qMEiQbueJruOEXWMJlqboJNix0YLVyQLjYYQAxDwfKljLlb5 o7pX5aCiUwq5Y5Z3/mp6wxuvgYjBj99xG0xFEFJjQMfEhuddXpf2uPdXLvK+vbeaErTu 4lCQ== 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=0XHCGsbXd1JOZn+ArgpiezEFdTO0W6WD7Dzn4Ci9acU=; b=bOi/p0SFMZKaUc2KFJn4Pp2jf2ggFNZbAvxfhhC2duiGYNyxNMqGCoAC+UVUiHEW7d FYNC1DOxX1RgoOSWrbQZ2Rb3+TCSmXDO1Vivufl4lrMNKbY33cH+yfsp+XuS/i2bYqe1 nZv8iVU0YcUuuEtY764MKlHzvdI0BPRVm4xA9jVnX2uPAhydxbmVksQoHzWJP9Cm/Kki FfNzNye+cUkAJhMwKWN1HgHTdsOxAJImlWdxtYkOQ/7YQ4NucoW2Fmd8mxTt0yfLGYOp mEz1rXqqXKg3v6XkhOuab6jrwDJ+DlxT/JsAJTcSOvj1p72lIxyh2WPkupnUlhCA5ve0 +qJg== 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 b34-v6si6456331pld.249.2018.04.05.12.28.48; Thu, 05 Apr 2018 12:29:06 -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 S1752301AbeDET1C (ORCPT + 99 others); Thu, 5 Apr 2018 15:27:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:33196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751932AbeDET1A (ORCPT ); Thu, 5 Apr 2018 15:27:00 -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 2DB3421837; Thu, 5 Apr 2018 19:27:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DB3421837 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 d206so27591515qkb.0; Thu, 05 Apr 2018 12:27:00 -0700 (PDT) X-Gm-Message-State: ALQs6tAD5+l+nmtd6+sqo2mtC9uzH0Vo9I5exPYXBBSokyH157UpC+ob CqR7ZM81WrG5bPZa2l/dRuO7T2Dn25D73rA1hg== X-Received: by 10.55.221.219 with SMTP id u88mr32116986qku.147.1522956419264; Thu, 05 Apr 2018 12:26:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.213.166 with HTTP; Thu, 5 Apr 2018 12:26:38 -0700 (PDT) In-Reply-To: <69c06530-94df-b67b-4e56-6519275afb45@gmail.com> 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> <935d6135-c5db-e5f8-b850-8ef26ce0c0a0@web.de> <69c06530-94df-b67b-4e56-6519275afb45@gmail.com> From: Rob Herring Date: Thu, 5 Apr 2018 14:26:38 -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:16 PM, Frank Rowand wrote: > On 04/05/18 00:22, Jan Kiszka wrote: >> On 2018-04-05 02:55, Rob Herring wrote: >>> On Wed, Apr 4, 2018 at 5:35 PM, 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? >>> >>> No. I don't think that will work. >>> >>> The of_overlay_apply() function is still there, but static. We can >>> export it again if the need arises. >> >> That would be the simplest solution from our perspective, but I'm not >> sure if that is in the original spirit of this change. > > For short term out of tree usage, exporting of_overlay_apply() is ok. Meaning the out of tree users can go export it themselves. > Yes, for in-tree, exporting it again defeats the attempted process to > solve the overlay issues to make them acceptable in main line. The purpose of providing a function to apply an overlay in one step is to handle the common case and avoid open coding the sequence everywhere. That doesn't mean everyone will fall into the common case. Of course, it also doesn't mean we have to revert back to the previous way to handle users that need to tweak the unflattened tree before applying. Rob