Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp70671imu; Fri, 14 Dec 2018 14:39:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/WjiXORgBxirCymQj0vKSygu9BUV4k0CInho7CXGtf8GxEiO73cAEni+iwijeQMHLoSSNQD X-Received: by 2002:a63:554b:: with SMTP id f11mr4404684pgm.37.1544827167474; Fri, 14 Dec 2018 14:39:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544827167; cv=none; d=google.com; s=arc-20160816; b=oebwQcj8gEjPV4t0geTYwR04P2ATPtcsWbEchOMDZMAb9k8bkqDpBr2Zh3/08cOt/s NX9opW6oCMxPD6g2/qrZI9Y+NyKzEcMkavs12/hv1Has7WgPgm+ou2kx7JlgRLjb7rNS u4PiCUuMhOKOQuD1IeT5sKVKmyctKELf9tJz91/126Jv1noYjuG6vUg8headOPDyJS72 UEbk+gissHNELoyWfr+zl8nPmJQQaICFOQr2ZZ7RiYnFzKfj68TvDnCR012NZRsl8iU9 IJd7EegN6dT77JIuyH023KbT+bZ+g9WkX2Kaq6SeCmkOYbrUanNToc2IGyc6lnUwK23G ggug== 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; bh=g3KVSBRx0QabCy9wJuZNKFW3vNbztiC+9T0uYuxrFE4=; b=m9RkcggMFv9LjVKsKx0vr1zrMRM5rV17Pq8q4xUbtdyuG2oyxOJbT0fLn9tqtU8uB+ QTe4OZBLiBql68ZfFlRM68yQWqVeIX7FN/GO4PSYpKb/WDhf5QmDD5uj97eA9TIk5h/T mqgvMKEIdrSfLzoyzAWlKFJwuFSVume6lGKkAnqDMQJ9Nv0fEmaRw9sRcU8eukRMrgTn hZPaVnVEymL+mnWax9K7bu+JAfQ5ax7oqXuhgFP8fjvYj+fTUAOa23ToZuyJOuDnXyGk KpRW4v6e3O7hVHRne5nLcA7jlrOlw51lXJSEkEpFllU2udtKdRT+LcBm6mXVhx3zvSaN X8Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JHZJNYGw; 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 u4si4822120pls.34.2018.12.14.14.39.11; Fri, 14 Dec 2018 14:39:27 -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=@gmail.com header.s=20161025 header.b=JHZJNYGw; 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 S1730153AbeLNWiX (ORCPT + 99 others); Fri, 14 Dec 2018 17:38:23 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46377 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729789AbeLNWiX (ORCPT ); Fri, 14 Dec 2018 17:38:23 -0500 Received: by mail-pl1-f193.google.com with SMTP id t13so3327115ply.13; Fri, 14 Dec 2018 14:38:22 -0800 (PST) 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=g3KVSBRx0QabCy9wJuZNKFW3vNbztiC+9T0uYuxrFE4=; b=JHZJNYGwV3YIGfhCzB7vObzQHxrAOclM4CSjYIa5u4gDZ99tt3d5/JZzBEgqhyM9tn mS1/Q1JJtSCfXgHdUxVtGaW7nbnBEJsUzQnG6KhqPOQpmLMSXH17sRdbuySNBjDnPOxh rwB8Lqjfkq0eeCHYfJ99r3S23LFMJ2OpVlWDXq04zDrw7EP3ezl1vz4p9hdcIQMHU1XB X04G2s/N8hBXguzll24uRaakrbdkNbozhGLTv4l4Zi8krGSEYmRsc0EoXpMtW2ecxrQ9 Pgn0/fV5Vgkhh/QSM+tIVYYCJKnA2H9PFzN7yoh1BSdpF+nH4uzDKiG1f8YwK8EQHIvp lcfg== 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=g3KVSBRx0QabCy9wJuZNKFW3vNbztiC+9T0uYuxrFE4=; b=tRNschggMo+DSx2wiTqfNB4C3C+xxKLY3b3PnYmtKpaeBpfzEWaW+EqfFVGRh6kBl0 tJ2cgSb4BEMjWtXeNlCd37FNfK606+Mui5nXAmnjaW7IiwT8wOiPbZG0GrkE2VIHuRzC CAMde1O2o/wCqKGTmgqY/I2XawpcjvB3inyzNuQJkL/IVcONILvD3NV45z6UVQIEwxYS wbn/coTSWYTumQ7L3YnXp3r8ZueGrqzrjyMuZn6NdQsLtkTLBQdxcweX8oqqRCJ41WNX ZQNgI1zhWtutvk4kMXoLxuPhM7ZyO0WHNanKjFtQZmGYxV71ZsRwH2WIaDlCCHIbOuRQ dV1g== X-Gm-Message-State: AA+aEWZOyw6nxoSzOEX4fdj0CJTjhhpSIfxwC68qDEybIGFvQRIz+udE BYC4xAh2pYX2NJR1aw1lMMs9iUYI X-Received: by 2002:a17:902:9a98:: with SMTP id w24mr4557439plp.213.1544827102290; Fri, 14 Dec 2018 14:38:22 -0800 (PST) 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 89sm9403568pfl.120.2018.12.14.14.38.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 14:38:21 -0800 (PST) Subject: Re: [PATCH 2/2] of: __of_detach_node() - remove node from phandle cache To: Michael Bringmann , Rob Herring Cc: linuxppc-dev , Michael Ellerman , Tyrel Datwyler , tlfalcon@linux.vnet.ibm.com, minkim@us.ibm.com, devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , Frank Rowand References: <1544769771-5468-1-git-send-email-frowand.list@gmail.com> <1544769771-5468-3-git-send-email-frowand.list@gmail.com> <68a9e834-b11d-8b9f-1669-466709257f37@linux.vnet.ibm.com> From: Frank Rowand Message-ID: <878c5024-c184-12f3-2868-df6c79d568ce@gmail.com> Date: Fri, 14 Dec 2018 14:38:20 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <68a9e834-b11d-8b9f-1669-466709257f37@linux.vnet.ibm.com> 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 12/14/18 1:56 PM, Michael Bringmann wrote: > On 12/14/2018 11:20 AM, Rob Herring wrote: >> 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. Correct, this should never happen. I will add the WARN. > We don't actually remove the pointer from the phandle cache when we set > OF_DETACHED in drivers/of/dynamic.c:__of_detach_node. The phandle cache > is currently static within drivers/of/base.c. There are a couple of > calls to of_populate_phandle_cache / of_free_phandle_cache within > drivers/of/overlay.c, but these are not involved in the device tree > updates that occur during LPAR migration. A WARN here would only make > sense, if we also arrange to clear the handle. Rob's reply did not include the full patch 2/2. The full patch 2/2 also adds a call to __of_free_phandle_cache_entry() in __of_detach_node(). -Frank > >> >> Rob > > Michael > >> >> >