Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2338405imu; Fri, 14 Dec 2018 09:23:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/UiSUbkXb1CFOV6WTlSrOpnixZj5pfEbmpYY0kEaJ/+NSnSdsIJHxEwz2gol4MWJt3kE+4g X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr3511500plp.247.1544808188718; Fri, 14 Dec 2018 09:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544808188; cv=none; d=google.com; s=arc-20160816; b=fZ9Y/VomNCPTF1FISLJKKrskMmvy1w04zH/BPiOnxmrL2dV8+DS4xKgt6fsHKKeh72 VZ3eCNr0Zm/oGOdqPSZiEj29CtKFgHX2o1Off2Oi0xYZATHbtbDhg3UWVbt2NnQelR+V jVi+civT3R1s5adPR/mu0D0h2BrNtuJKLYXkDNbGpbdz6E6f+L1Aenad2/jzBO6jSw9F VCl39SXW7p5Nk30seBku49LXHrs6VabodWfJHYFrNNlYdkfehyRm4iJgMi1eaEGoLPHi 0HumdVcAhZPAEVMwHTgrhXyjICV+TXEJn0N93jLEJCj9pHE5g9fukfVKO61foso9wlol zIvA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=4Llz9llbVXGZjY4C3Kjp2vIHeApTMJ3iI90gip46vV4=; b=y/geTJ8SaB929ISA1xL+GcLQ2adi9uVgRO3lmQu5mahxtyE2K4v0jdK4Vr1E4rJf1b aK/QA5wKcmbXcYIfYD87qqN/epZ0L4MsXnvawnPkBVBDwhWmz1v5wWx+Biz8IwHD4G0B PjZyTzDnOsCb3NcAZqcZP6EbkEvbtXSnhal3MM2ptrog98aWPEfDWks37gRKPqjKxX4m KPOQXNSFDkvOov1yqxpxsQoqINVq71lMPIk/KGolwIdXviwY+izj8tzZv81JAcdip7iP AQ3CeYF5/lVTn4rjMPGbH/qrMjy3stFSMGpuj9vQkREoqaQFS3mzJfWdQ9wcpNWmosy6 etxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jk6cGvAJ; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n32si4414158pgm.439.2018.12.14.09.22.52; Fri, 14 Dec 2018 09:23:08 -0800 (PST) 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=@kernel.org header.s=default header.b=Jk6cGvAJ; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730266AbeLNRUP (ORCPT + 99 others); Fri, 14 Dec 2018 12:20:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:41576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729508AbeLNRUP (ORCPT ); Fri, 14 Dec 2018 12:20:15 -0500 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.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 62DF12070B; Fri, 14 Dec 2018 17:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544808015; bh=17sy1cCSStd8lhmEga2NxAz/c3m4ocZS/i17ebqa7EI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Jk6cGvAJQfQI+e/4LlEK4od6zBgkjqbm5UFGv0N5bvovzk+KTl4Dj4GBs52uekfWe soGUWcGiXcYUDyDQ/LNnBkBzLhWjVs5HiiULZYln89R1KkmMBRJYTc3wMhqlLsx04Y psPtTrPdXUTwrFuKL8ouAPkCE1gvMRWUlb0gWk7I= Received: by mail-qt1-f178.google.com with SMTP id e5so6955240qtr.12; Fri, 14 Dec 2018 09:20:14 -0800 (PST) X-Gm-Message-State: AA+aEWaYfpkQetHgHO+W/VrNTOmADpe/+YQUnXQRjN139RcTZ76Dy47R IQVfSyBhfXZvBG8uRe3GalhoqE4/oOZsUXPjjg== X-Received: by 2002:a0c:9e05:: with SMTP id p5mr3646677qve.246.1544808013572; Fri, 14 Dec 2018 09:20:13 -0800 (PST) MIME-Version: 1.0 References: <1544769771-5468-1-git-send-email-frowand.list@gmail.com> <1544769771-5468-3-git-send-email-frowand.list@gmail.com> In-Reply-To: <1544769771-5468-3-git-send-email-frowand.list@gmail.com> From: Rob Herring Date: Fri, 14 Dec 2018 11:20:01 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] of: __of_detach_node() - remove node from phandle cache To: Frank Rowand Cc: mwb@linux.vnet.ibm.com, linuxppc-dev , Michael Ellerman , Tyrel Datwyler , tlfalcon@linux.vnet.ibm.com, minkim@us.ibm.com, devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" 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 Fri, Dec 14, 2018 at 12:43 AM wrote: > > From: Frank Rowand > > Non-overlay dynamic devicetree node removal may leave the node in > the phandle cache. Subsequent calls to of_find_node_by_phandle() > will incorrectly find the stale entry. Remove the node from the > cache. > > Add paranoia checks in of_find_node_by_phandle() as a second level > of defense (do not return cached node if detached, do not add node > to cache if detached). > > Reported-by: Michael Bringmann > Signed-off-by: Frank Rowand > --- > drivers/of/base.c | 29 ++++++++++++++++++++++++++++- > drivers/of/dynamic.c | 3 +++ > drivers/of/of_private.h | 4 ++++ > 3 files changed, 35 insertions(+), 1 deletion(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index d599367cb92a..34a5125713c8 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -162,6 +162,27 @@ int of_free_phandle_cache(void) > late_initcall_sync(of_free_phandle_cache); > #endif > > +/* > + * Caller must hold devtree_lock. > + */ > +void __of_free_phandle_cache_entry(phandle handle) > +{ > + phandle masked_handle; > + > + if (!handle) > + return; > + > + masked_handle = handle & phandle_cache_mask; > + > + if (phandle_cache) { > + if (phandle_cache[masked_handle] && > + handle == phandle_cache[masked_handle]->phandle) { > + of_node_put(phandle_cache[masked_handle]); > + phandle_cache[masked_handle] = NULL; > + } > + } > +} > + > void of_populate_phandle_cache(void) > { > unsigned long flags; > @@ -1209,11 +1230,17 @@ struct device_node *of_find_node_by_phandle(phandle handle) > if (phandle_cache[masked_handle] && > handle == phandle_cache[masked_handle]->phandle) > np = phandle_cache[masked_handle]; > + if (np && of_node_check_flag(np, OF_DETACHED)) { > + of_node_put(np); > + phandle_cache[masked_handle] = NULL; This should never happen, right? Any time we set OF_DETACHED, the entry should get removed from the cache. I think we want a WARN here in case we're in an unexpected state. Rob