Received: by 10.213.65.68 with SMTP id h4csp2301340imn; Thu, 5 Apr 2018 12:29:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/iAyz6dKfY1nl3QXI3ycPF3OiU/lFTa1TI5n6ipzGTtMjwsYKpeh29AVc0//kaEQpXxHmb X-Received: by 10.99.111.139 with SMTP id k133mr16044494pgc.236.1522956599302; Thu, 05 Apr 2018 12:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522956599; cv=none; d=google.com; s=arc-20160816; b=gDq2qKmxDS0RbbVKxQ6GIhseci8d/HEF2xpjYS0NvpiNwu1k3O2NhzV/lvdCIBOZ3d Nx7o+lHjy1zdd+lyTDqj3BY98hG6VI9xHD+DHAZTeNdzQXuvrSUJtJd6RGwV+ySGm4Kd V33lvgfee444JVepq32P0dDOloD/ZYBZAoNOMfkT/VfwlJX6mH+jrYIQB5HAFUEdADAf aZEL74qHmbS2/8b4/YxrwhGqE9FJPFxO5+VEeJw13Nl9xASVNSvrfuo9DkpwaJ5UW3dp crw0YFkZ/4GD6akdsurvtu2qqZkvZXooJmFRrBVtwvcLgSr73XkeDqtKGNAuDgn7dRSH 9vnA== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=8l2hdxVCmFB7YScMXyG6k/Me+TEWdhu6gO6VBevyH1s=; b=OjATq4saFrvDfj8e60JdginztWhr20xiikET6wfRbLBkJosekE725ovBAtO3psKuJF LBrIU7M2GgUWRkoNdS2nb80Uahaj7VLwc3qEFkzlS3hzpXnv2/ESjufsuWCduvgdPInj zdqZ7jXBbMx87ztPESg14sIUQ22BHyK0pIcDJ00vANZ+px0z9rU6BRAIHzbd6c4y9hh5 juy/uUpR2BT6s96xVPSZS+3zfAwvqwUynOucllH3xG9eA3nk363PtokYYhyN8b6Qk+2y 3uEHVGR3s4MvdPJoE+fwVg8uQu+lL9CPn1N0fgNJ9rCw4CwSs889iRvs7nEWeOTOGaaJ h8hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p2Ig62H6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g190si5008024pgc.741.2018.04.05.12.29.44; Thu, 05 Apr 2018 12:29:59 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p2Ig62H6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506AbeDET2h (ORCPT + 99 others); Thu, 5 Apr 2018 15:28:37 -0400 Received: from mail-pl0-f47.google.com ([209.85.160.47]:44459 "EHLO mail-pl0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbeDET2g (ORCPT ); Thu, 5 Apr 2018 15:28:36 -0400 Received: by mail-pl0-f47.google.com with SMTP id b6-v6so18604701pla.11; Thu, 05 Apr 2018 12:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8l2hdxVCmFB7YScMXyG6k/Me+TEWdhu6gO6VBevyH1s=; b=p2Ig62H64c7WyUz81eag7DER6cbx3MutTQRHfFtAvcCOVOIA77L7+V3NUXpiUlrfWq 7+zbJraz43a7hE2thzz5D7wLT2jQGH/Z5l0wCgl7UuJ53TK3bFbFFQ73dxvIiPUoK1sL EAe90j5f6h2Vw+eYNDMoBiIOgGqHHjfV7PSKlSQOD8tTtKcQO91F6swVgOB6X6S920zO GTfdzl+jawD7euR4fyz6jR1qTqaqVIfniFyPLT/22EKs8jnQfp/f+g1LJOA8oVkC8XF7 peprzYhGXjF4WX0JupYNKZaxe9Vxiby537dzjqRn1fQ+AikgzcwFEfSHFTiJ4xIfzYiU h8jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8l2hdxVCmFB7YScMXyG6k/Me+TEWdhu6gO6VBevyH1s=; b=XP1okgy78XfC+PnGJbN3MLFkIcExQ8xDuSDjv8sgFdSTZSQKuDVFrAmcqhO21Vlnaz /FevNGjwTTr1IPxSGU3pg0uGIyC8OhFWYfznqr59XJ1cb4M24bApp9C3MSndMrZeH+yE Hv3kgxs7SLoVhEkJcx5EKZDd1ZsfUPSfsiep07VT8lsGJzGFriUrUeLOYDb/9YNiAJv6 S+z5yCYRMeJvO1pZif1HKLyy+C6CEb0rSghENkx4jSnhDf0SAdYdQqoCWnmn3p/u76aG 84lYfSdKedbJvU0/kPmvXezhB4xyfHkrtMaqoOT2aeL4Li6CYcptStZd44C89zFMePfp i1UQ== X-Gm-Message-State: AElRT7EjfP4bHoZbzq0HV/lwCDsBhEyqpwxaB7ZkRLpY/ntZCdCtCick neXXF9Z9T/2l9JFqluWbcGA= X-Received: by 2002:a17:902:8501:: with SMTP id bj1-v6mr24655012plb.239.1522956515651; Thu, 05 Apr 2018 12:28:35 -0700 (PDT) Received: from [192.168.1.70] (c-73-93-215-6.hsd1.ca.comcast.net. [73.93.215.6]) by smtp.gmail.com with ESMTPSA id w24sm16999207pfl.84.2018.04.05.12.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 12:28:35 -0700 (PDT) Subject: Re: [PATCH v7 2/5] of: change overlay apply input data from unflattened to FDT To: Jan Kiszka , 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: Frank Rowand Message-ID: Date: Thu, 5 Apr 2018 12:28:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/. >> >> 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). If I understand create_vpci_of_overlay() correctly, it is assuming a fixed size of 4 cells. Line 314 is: for (n = 0, cell = 0; n < 4; n++) { Off the top of my head, it is theoretically possible to create a property that can contain the largest possible size for the property, then shrink the size by inserting NOPs at the end of the property to shrink it. >> >> I'll also reply to other comments in this thread. > > TIA! > > Jan >