Received: by 10.213.65.68 with SMTP id h4csp2309907imn; Thu, 5 Apr 2018 12:39:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/T1gpWQUDBqCGEKLY88FHhqDx4tCm8pOLO/CD888tK5abgM80Wglyq1kGMgRfsFK5L0zcH X-Received: by 10.101.78.142 with SMTP id b14mr11060489pgs.406.1522957191747; Thu, 05 Apr 2018 12:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522957191; cv=none; d=google.com; s=arc-20160816; b=dCY0C1l63pRJMBdiv4SQm2sflNWQnDn1NOHenTtmyUUxkoMMtG63ETQnByiouZG4Iw 17C4HfGCweCMinvAMY8nV8UzyVGCHL3LWG4+Fu5cecMU9JDQ1+zCqHmPn4ioHd8Q4Gsr bUFZ6iXIpqqttcb6HJf1uIIMGj27sZXWeQeWksg9MXsO4YK0HuoiIQNzcgxEXfU00Gk1 RU7kdZXXJLij2NMIxUc8HzrEk4pALatDkvPdoFT4kykU0m0M06MYmys4ST9vXO85Y6F9 OVmmmCKnrh0HwR01MQs/LaZeh0uBE79wmOyWp9JqjSX6IsLgyv1bgGFLUBypIiLYLRKk Bdpg== 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=5W/5/HeO5IzRnD5Mg7gdhwrnmvhMh9Ak4l6o7rUoyQc=; b=GMaRoNWViYcjzmheM3tJ+3v3JOrqC+bQ2omQT6msvwSbtlGpnVHLgK6tNM2zAGZird UxwozE1JhjHLM+k4n74PoH+44pOlJFbvRzuJYOat66DJO3V1XXse6wuvMl2hvfakalf3 y8bn7pPKBMskqSHyj6pdq+jn1Kq0JzHfF8nHLyZfZJf/74sMxG6BQ77zEAq61CvZfNVJ Emf2QsCBupmrQLCQ+mz0H9W73LU1TGCLJaCvDQVbOYRPa3m1v72seCxXV552U6dmazdV fpDisKzy/lhpBEiu0PICCv7Vi4sdZZoI4fF4DgS5sH2jmKGD/YpA34BKcbJSk+DGnxNn HcpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kzOURjOn; 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 m198si5879723pga.107.2018.04.05.12.39.36; Thu, 05 Apr 2018 12:39:51 -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=kzOURjOn; 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 S1752626AbeDEThJ (ORCPT + 99 others); Thu, 5 Apr 2018 15:37:09 -0400 Received: from mail-pl0-f49.google.com ([209.85.160.49]:46115 "EHLO mail-pl0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751952AbeDEThG (ORCPT ); Thu, 5 Apr 2018 15:37:06 -0400 Received: by mail-pl0-f49.google.com with SMTP id 59-v6so17926854plc.13; Thu, 05 Apr 2018 12:37:06 -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=5W/5/HeO5IzRnD5Mg7gdhwrnmvhMh9Ak4l6o7rUoyQc=; b=kzOURjOnSGoRu8ChRwVFfkCkioo9W0f/imH3aZZlThHuJkA43SS+w0O8aREWP28S0t MSYbw2CfHj+YTAF9BCMfJr5hRZE+l/lSu3vUzCixtUEQ8/ad4iul7TeRjmCf9vUhgfvt 1wJm8WPxFe35EpWTUF1AaFm2WADq5yNvwnP8Kno+3qkzzaNTEpy0uZ3IPVkuEPJPOYpK whsQuislI3bChqOhJdeknvnTYTkLVxNkmFUpV79Pjqet21pP5ZdfP15HXQu0zfRW2iy3 HjgufyozbIVCKyQuYsqLqbqLzvgJGV6l55r+W5CF9nN+EBJFKVdPpnBn6qNp/opDeYvv Ltyw== 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=5W/5/HeO5IzRnD5Mg7gdhwrnmvhMh9Ak4l6o7rUoyQc=; b=hJEDWPzwTGm1P4+ePwW79SXtNpeAHpb+VT1KIJ2OzKzfPS9mKGZh8yTeMnqUMMEScO VBrRVDGFZ8YP0cnk+DUZTsKpl+J/xvTVyfl1eHv4qGsgRzTaqijCQy3Y6Jaq6fOS3fQj d417lLIHdKBpjJdcB919SPYFc7LL0ygZAcjEHBuQuEppx7j3+22LiVhZ82sjMm4RVnB0 iMMpHDCbUP0TN4zYCIMDds6JaZx603cgMHNKfEhZ55YdGvybM5kHF52ibFpVOUlKCG2I lsSGNQSlkhaT0oT1Pgks8RmsD9To4dDNwEw7vJGEEVFFvwMZ9qEqQeLJO3XVTSgL+4Es lMoA== X-Gm-Message-State: AElRT7G5GAh/Xi5txa8aA72BVPXpJ3UjgmGXd9G/m4j6oNOF6+7bHLjH M/VWTKBAQnE83J7HJQQ7E/8= X-Received: by 2002:a17:902:9692:: with SMTP id n18-v6mr23822224plp.175.1522957026435; Thu, 05 Apr 2018 12:37:06 -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 j11sm15377350pgs.13.2018.04.05.12.37.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 12:37:05 -0700 (PDT) Subject: Re: [PATCH v7 2/5] of: change overlay apply input data from unflattened to FDT To: Rob Herring Cc: Jan Kiszka , Pantelis Antoniou , Pantelis Antoniou , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , Geert Uytterhoeven , Laurent Pinchart , 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> <935d6135-c5db-e5f8-b850-8ef26ce0c0a0@web.de> <69c06530-94df-b67b-4e56-6519275afb45@gmail.com> From: Frank Rowand Message-ID: <07f25928-6ecf-ac34-e724-cad2e94f6ba7@gmail.com> Date: Thu, 5 Apr 2018 12:37:04 -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:26, Rob Herring wrote: > 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. That was one of the intents behind the change. The other intent is that with lifetime of the overlay FDT and overlay expanded tree visible outside the devicetree core, we can not free the overlay FDT or the overlay expanded tree because we need to protect against use after free errors. The open coded examples of applying overlays commonly have issues with freeing the overlay FDT and/or the overlay expanded tree, which leads to the potential for use after free errors. > 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 >