Received: by 10.192.165.148 with SMTP id m20csp2572393imm; Thu, 26 Apr 2018 13:22:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+0oB+AOWPSWWESn09Svj0DHI8W5lyUnz8ZVkp0IverHt9yRjama7ITyn1qfcDq1Q9MYgN5 X-Received: by 2002:a17:902:205:: with SMTP id 5-v6mr34450422plc.301.1524774140537; Thu, 26 Apr 2018 13:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524774140; cv=none; d=google.com; s=arc-20160816; b=yoLKBsYd0o0xOYSb7EXgPjcSFxEjGrHmVOEgm63+DgtqPUB4Vn1La+FrP+BihZAVKd CzBTYXNJ37PSIpEF1/qkQ+KH6sbVUAQ27tB7mpduiyu4wyc5f9at+omH7dXI7b2zsQ8o ii9FmQyZ9JWrFDr8ESq8/QYM0wmwDeSP2ziGzXyPUBdrRs+Fhd+UhtAQpWJjEr1gL6HB pvPLvt2MJreKPkiKQCauLFuaG0MlBJ/CsR0UemGV5xNGDb97UN6zZQJuJq7WfcBPifpO Hb/JBDu9l/EnHf0bt+8rkTZu9r8GyBO3TG/ZV8EEit9OBbS2xL0utya5w4BJ70pM4ZcL RT5Q== 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=FOJE41xs/Fos/4XCUBEWPPD947iATVy0XFFlZkddgZQ=; b=YkjuD4/v/oab7DywsZhQSJgWmwg2vZlbgZha1Awz1gCOEk5IPQxlw5I7D/AHly1C5z 9LJ2NL8q4xEuaHZb+OoUdD4FzLq+LhwbTsLmK4UfJJmtGv3DATKaTuOS1ahCALDJ2MDy p/pLFo9OdhZA7elDP60ljuIQtKWgXKhPc0ddK36gEYMU9Q2GyutiTDGQFoh4CF4OOdig 1H5Deftd2GvNkLmK2vTfGBK/gMkOziKqbMMeUMlU8buqJtAqkh+3Y+NJevO1urvviH7M B43roTMqx3GCLg1uYkjr8sDa16w2J01YjnJM43g5XkwYrqHNwZ8lTWFevSF0Iyf/ps6N i5Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hIZTiwOd; 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 17si16585749pgh.114.2018.04.26.13.22.04; Thu, 26 Apr 2018 13:22:20 -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=hIZTiwOd; 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 S1754170AbeDZUUr (ORCPT + 99 others); Thu, 26 Apr 2018 16:20:47 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39972 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752358AbeDZUUp (ORCPT ); Thu, 26 Apr 2018 16:20:45 -0400 Received: by mail-pf0-f193.google.com with SMTP id f189so10135001pfa.7; Thu, 26 Apr 2018 13:20:45 -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=FOJE41xs/Fos/4XCUBEWPPD947iATVy0XFFlZkddgZQ=; b=hIZTiwOdqghc8oeIBcicF7tQer3R/aMxmesEOFDQAiE1hCJWw1l04lc4tcn7TH+EPN qSSLKIF7XSne5EkvoPGhYkosW81Q5Sd9xGwrWLZb76nD0ZZ7O+pJ/15zIE0gnoUfYNPX xXvR3zMng9dSKKXGdaOMN4L3FHB//KvbLqxzh/5V0QL0v0gjez0fDPuKKSiEcy0mA8wa 0vQJdUFIR+WQHldapPeFeb7SNslFF6NrzocP9Hr0ZDTzipPAMbc8MimiM62tU/x14hQe OR97KwYIXC48fXH7Rzu7qzCksd56uw/wVCI3O8qGyUkbUP+mZKfUVxtVlA1DiqJ/EV4G QTOA== 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=FOJE41xs/Fos/4XCUBEWPPD947iATVy0XFFlZkddgZQ=; b=qbDYavPtW04hOT2gbgpphcuBFWIBlDZI5ZXKzsSQmo4mBo2ptq1SAEApGqxGxIGpjN FnYTRBgCVWHybXnHS+Y5/xYWFgM7RDa35HjJkRZ/u9ySSPgRKvbGInqljB4V0jSDjA+v hXzgioHBnaZOT8HEXBv4jZPSdml1TfSwki8kYUHd7gu4BotYJ0tjwcKybyseOrBbGZSI Jeam2msl9hxvQFoMhMWz1M4iPK+Sys0vx5N2f72fUp5t9bBifngEN/0bQB5QvpLEaCpP PQabmfw1T5sIDxCTuVI9aa9tsnklRXUAtR0g7div/PRDYzCKk3Pq2iSeyLapZ2HpFRIC 1+Kw== X-Gm-Message-State: ALQs6tD5JD+JM/4F55CDmemx9MvYa/1Z8NLvmUP88CG23w0KzDPny9Jl aQuPZswyQZYSSIQlOczie74= X-Received: by 2002:a17:902:a50f:: with SMTP id s15-v6mr36218599plq.175.1524774045165; Thu, 26 Apr 2018 13:20:45 -0700 (PDT) Received: from [192.168.1.70] (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id a23sm9193506pfi.176.2018.04.26.13.20.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 13:20:44 -0700 (PDT) Subject: Re: [PATCH v2] of: overlay: Stop leaking resources on overlay removal To: Jan Kiszka , Pantelis Antoniou , Rob Herring , devicetree Cc: Linux Kernel Mailing List , Alan Tull , Geert Uytterhoeven References: From: Frank Rowand Message-ID: Date: Thu, 26 Apr 2018 13:20:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.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/26/18 04:00, Jan Kiszka wrote: > Only the overlay notifier callbacks have a chance to potentially get > hold of references to those two resources, but they are not supposed to > store them beyond OF_OVERLAY_POST_REMOVE. > > Document the overlay notifier API, its constraint regarding pointer > lifetime, and then remove intentional leaks of ovcs->overlay_tree and > ovcs->fdt from free_overlay_changeset. > > See also https://lkml.org/lkml/2018/4/23/1063 and following. > > Signed-off-by: Jan Kiszka > --- > Documentation/devicetree/overlay-notes.txt | 8 ++++++++ > drivers/of/overlay.c | 30 +++++++++++++++++++++--------- > 2 files changed, 29 insertions(+), 9 deletions(-) > > diff --git a/Documentation/devicetree/overlay-notes.txt b/Documentation/devicetree/overlay-notes.txt > index a4feb6dde8cd..725fb8d255c1 100644 > --- a/Documentation/devicetree/overlay-notes.txt > +++ b/Documentation/devicetree/overlay-notes.txt > @@ -98,6 +98,14 @@ Finally, if you need to remove all overlays in one-go, just call > of_overlay_remove_all() which will remove every single one in the correct > order. > > +In addition, there is the option to register notifiers that get called on > +overlay operations. See of_overlay_notifier_register/unregister and > +enum of_overlay_notify_action for details. > + > +Note that a notifier callback is not supposed to store pointers to a device > +tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the > +respective node it received. > + > Overlay DTS Format > ------------------ > > diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c > index b35fe88f1851..7baa53e5b1d7 100644 > --- a/drivers/of/overlay.c > +++ b/drivers/of/overlay.c > @@ -102,12 +102,28 @@ static DEFINE_IDR(ovcs_idr); > > static BLOCKING_NOTIFIER_HEAD(overlay_notify_chain); > > +/** > + * of_overlay_notifier_register() - Register notifier for overlay operations > + * @nb: Notifier block to register > + * > + * Register for notification on overlay operations on device tree nodes. The > + * reported actions definied by @of_reconfig_change. The notifier callback > + * furthermore receives a pointer to the affected device tree node. > + * > + * Note that a notifier callback is not supposed to store pointers to a device > + * tree node or its content beyond @OF_OVERLAY_POST_REMOVE corresponding to the > + * respective node it received. > + */ > int of_overlay_notifier_register(struct notifier_block *nb) > { > return blocking_notifier_chain_register(&overlay_notify_chain, nb); > } > EXPORT_SYMBOL_GPL(of_overlay_notifier_register); > > +/** > + * of_overlay_notifier_register() - Unregister notifier for overlay operations > + * @nb: Notifier block to unregister > + */ > int of_overlay_notifier_unregister(struct notifier_block *nb) > { > return blocking_notifier_chain_unregister(&overlay_notify_chain, nb); > @@ -671,17 +687,13 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) > of_node_put(ovcs->fragments[i].overlay); > } > kfree(ovcs->fragments); > - > /* > - * TODO > - * > - * would like to: kfree(ovcs->overlay_tree); > - * but can not since drivers may have pointers into this data > - * > - * would like to: kfree(ovcs->fdt); > - * but can not since drivers may have pointers into this data > + * There should be no live pointers into ovcs->overlay_tree and > + * ovcs->fdt due to the policy that overlay notifiers are not allowed > + * to retain pointers into the overlay devicetree. > */ > - > + kfree(ovcs->overlay_tree); > + kfree(ovcs->fdt); > kfree(ovcs); > } > > These added kfree()s are depending on good review of overlay notifier patches to prevent retaining pointers into this freed memory. When this patch is accepted I will submit a patch to add a "K:" pattern line to the Overlay MAINTAINERS entry to catch when overlay notifiers are added. Reviewed-by: Frank Rowand