Received: by 10.213.65.68 with SMTP id h4csp2289340imn; Thu, 5 Apr 2018 12:15:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/jvJvbojaWb9hFxQcrFT/FbNumosLGzfg2Vkww5T8QeIvEopG/znpWIE3dq+k1aYx8juev X-Received: by 2002:a17:902:102:: with SMTP id 2-v6mr24152672plb.48.1522955747887; Thu, 05 Apr 2018 12:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522955747; cv=none; d=google.com; s=arc-20160816; b=fGkglMlSggXAQRNLGGItbcyXqC3aI6vOpLh06h9NuVG1oULcvuBX2USJdrMbcqWvEj nyF7n/smSAdBTLX+DqwXg8WMFP4N2Bsn+cXMd5O/ixtS5rVuKGTE0GUtx20vBFnynZgb +BqLR05zJiePqaC3ct/KRWPLdeK/mRSNDUSkULJVTAKjt2cpkUyZ7msbg92YQZcw2To2 RidnzIXz8t2NNymJvtAJVILce9k6r8oaloM3vYqEdRY6wAe/xHRBKvyXSXbOe672KCdk qoKuY9/71SzpHJQILxgBS6qGQb1cab69o8UviV24ZXEqAM2VB0JaHNKXNX0z4oZn5nZI jXWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=Xkrr3jJYBGpcTO3SFV8ZFEuFlhlzDYrS5LwAit0c7Fc=; b=xgVYcvk2B+qiw4wNA2iabzHN36LJ445hpzwjtNvf8tZ9660pV9akpWMSpbfUXZZzQQ 10MbAaWBVpz/W+ISaft4QD0AUdSJXRzn07XuvbkkAuzJvmRE4oem7qqSZ6MYfgNwOG4F tFJhodvO7gf3CeBCiE/XglTMSctz4tYsfMJ16d2Sm5ANrSSq1LfaSC0g5prRPyqAxkgr 3SLribN+z9v3bvay4O8mgC4eu16olEQHCz2X3dvvM13e3RnqHEsJ2qcx/kOX/OBKVhwZ BqD+U1hcrQdVQTrUBpiSDIfJwV7EEwITUW2RJm96XG66akO0AhYmO1oUqWQSdRmgAx9L gKwQ== 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 3-v6si8769164plv.323.2018.04.05.12.15.33; Thu, 05 Apr 2018 12:15:47 -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 S1752282AbeDETNZ (ORCPT + 99 others); Thu, 5 Apr 2018 15:13:25 -0400 Received: from mout.web.de ([212.227.17.11]:57787 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbeDETNX (ORCPT ); Thu, 5 Apr 2018 15:13:23 -0400 Received: from [192.168.2.11] ([92.77.50.102]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Ldn6l-1edb4s1WTb-00j3qe; Thu, 05 Apr 2018 21:13:13 +0200 Subject: Re: [PATCH v7 2/5] of: change overlay apply input data from unflattened to FDT To: Frank Rowand , Rob Herring , pantelis.antoniou@konsulko.com, Pantelis Antoniou Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, geert@linux-m68k.org, laurent.pinchart+renesas@ideasonboard.com, Jailhouse 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: Jan Kiszka Openpgp: preference=signencrypt Message-ID: Date: Thu, 5 Apr 2018 21:13:09 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: <7bbf615b-3cdd-6bb4-6918-33e48de4225d@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:5I7KUHipNsaiyYTieuHa0WP9GqMwAaf1ZePrtMnxrat84rAu3mI s9Ps6lCf13gQmmbHmXfccZw8fSG3mUvy0exSg1+ghojBGnJ+qf+F5U3iR1L2MqS3yey5qR7 0I869FlB/kp7cib/GXBv/dEb673mJo88Ljbvp6tsvf72UOnNn6qIGC1vqro6yyC+xLJp6sZ eePJHd+I8taCpn0dq9x0Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:kj6Zi4UTgB4=:Vtm/+FGD1sa6K/GSi8dRNK LQaxs32nwienDXtJsReQnAiycFs1OIGI14pk2yqxR2F25rikCA3elEKjyGAhThFObJbkCVnWF gAJG5/PN3qJ769S9D4vccsdgRE81NCE89kdfiVVd9zu+uuwK/Qzs9Qno0d9p0Tp5Pir0PI1rv ZOs+aLcwI0BMBCAMApT0VPH6m7QQ+jTREwWIzXDTrqOxmiPWPtpWeFVVm5IHKBQCIfHV9/8fV oaYUfQ+23x4LBkL6FGOTuFD/mPx4QwXZZSn9rKcGbPGlEh2/keBMDFHxss+1azoxIWYGLvseN 64EBFuxk+FJxkWpjPOneHpuyQlH3gnePRJQYGTxa4xLK++PHlyVcatY1cfBb31CN3IgxHuHa0 kkQIlpopnjS7Jw/n1CQd8go9hPeaEYrsAFo7qBTtCRKM7D5LlX+bcaxB0ZLzI2ROEhGlkBcHv 4v9HFGIJ+nNxAUDo29q1w77GB7qELHyTNcXmJZSiJLeJqcT/6KzR6xIVuTjpn+DDmxOenoog7 QEtvq9iIfgbhM0ie7S4BFZZj9rP4SaO6QOPlA8P3nhjc9wKFe6l0pTl9klGIPxa7yYXpFtLqw x1l3SM+Dr75hdVAivYHqenOUdTzCK9bscqumM+PdWFvbraJNCS6gTDS7yQtv59dyq/dqS2XMx Chx8NJ1D8z6YtyJYtAKd0BXoN1UrtbSVAE1NiJTrAgU0/OTtWM9Pc4BDLGNEuFoYTCHzUXSUr oZeK81pASG3jPomPURB77cO85RH6p1NJw1Mp4wwwPHsUeFRPtcbzsLWgNzoNdwUkFD6LitcNz Nu6XZFX8qhi6dH8Mn8ozqwwnHCam5M7O7U2Zf2LvBbP7LDWDttSsIq9neDWWmPZtKErHbF2QM gGyzbHWAqUtwN/KWkeeaUOfkL5QF/AgBGo51tm/zDaiQY51YIzm/ahkiCGVTcWQnIhLDhL4z1 X0zWfp776B27PA3r3tqRSKSa1ufpEgmJbXYMXl/0MielPFgileVIFQlIoJisV26Fe+IyCaoKj ww== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > Looking at the driver, I see one potential issue with that approach. > The property "interrupt-map" is added directly to the changeset > instead of being an existing property in the overlay. Is it possible > to have this property in the overlay when needed? Well, the size of that property has a runtime dependency on the gic's #address-cells. If that is easy to account for depends a bit on the available FDT manipulation services. Or it would take multiple templates to handle the different cases (0, 1, or 2 IIRC). > > I'll also reply to other comments in this thread. TIA! Jan