Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1218841ybl; Thu, 12 Dec 2019 11:29:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyyZxM9FSstUdRQdnR3rG97y/dt4+SmPd4gbaN7KESoGT9Dmzw3gp2l7wRXXzfAygQViy/G X-Received: by 2002:aca:f1d4:: with SMTP id p203mr6032485oih.116.1576178960839; Thu, 12 Dec 2019 11:29:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576178960; cv=none; d=google.com; s=arc-20160816; b=JYoIw3xnykfpkk26H4ywb4cpXLeB3Y9gvV/BeHqSZ6dOtGRM2//TFNCClvRFeDi+uK qlxMfc0fsChNEqBMaedLW5OHB6e2ZcRWLwjA479JgoOs4gX4zJ6WO1/FNnJSyaNLOQgt F470QXSIJ6jt7CXhex/hndvSc0I5WAi5cniZgZFSeRwXhl5oPpFsEWAMgn0uvGUuQtXU pMO30hx/tQk8jhNL+QZDtqivXzSeHJN4pbUjXdsGbMuzM8NV0rgo8VH0kGp4pdX2mtun uh3/dayLk5+lvyVZOHu3VD0asKynu7X7fXUxCzDIF1JtYPY0WGD9vWB5fr/7K9s3jniO rDWA== 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=FyQERma/wUOX53gd6IVKBMBR7m9qcljaxUwh7R1rYiA=; b=iIA0haWHdEKSJ2wiW90ME3cp/i3HlVlVBwqrSSMFPnZy3Tw3IdGAVIQTbBNFqm3uvq oJ+xmkIQv10p3B48FxaMWZ2O6kXL4luIHdDSkJs5WZoLhGW713Tk3ZRsvahgyjKhyBB7 365DO4C1cauiLu3jNgAz2SJURpAaW9Fb0SwwN/oCXZm898WKJ4h6ay9k/Ph4vRkB/sI+ coDS92Egtc8L3v85+0mBl19iUlRIc/x4mAo2NMCWzJ7MrY0aIV0TBALVWEqO5Dr25RcV dvLeq2ynghEAstTAkBNSAw+4SDczEq4hTYkusr2TX6QnumIx5E78FuCcvVJa8dvanCeq U9kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LJ4yl5RD; 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 m8si3489981oim.180.2019.12.12.11.29.07; Thu, 12 Dec 2019 11:29:20 -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=LJ4yl5RD; 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 S1730525AbfLLT2j (ORCPT + 99 others); Thu, 12 Dec 2019 14:28:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:40322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730168AbfLLT2j (ORCPT ); Thu, 12 Dec 2019 14:28:39 -0500 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 71F5A22527; Thu, 12 Dec 2019 19:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576178918; bh=mw6yUbytXpLJnaF1QjwaHchkWwnhvbA8I3y52Tw2Tkk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LJ4yl5RDalD1iX2sPYWVNYhW1QG8yMGa4rOVnu/yoyZxHiQMmRhBr4LxVCdtCLmla A3GDqIHIq+4MZ9HBRYnVDc87v/oZwJ//PGE/JhPR1cK30cQvEB0ncvz8Fp5BEGGuCn WrPdijRMUurAw65q8RPOEbNPV8srq7NkNTCyvGMo= Received: by mail-qk1-f179.google.com with SMTP id w127so2552608qkb.11; Thu, 12 Dec 2019 11:28:38 -0800 (PST) X-Gm-Message-State: APjAAAWJ5giif7u8JXkPn5kPUdJF2Kch80gTM4HWUhGPvp1efspLsfN8 yjt7hBmf0S+y+FLslQ40T8LLyvXOy6NyJ/avoQ== X-Received: by 2002:a37:85c4:: with SMTP id h187mr10000154qkd.223.1576178917566; Thu, 12 Dec 2019 11:28:37 -0800 (PST) MIME-Version: 1.0 References: <20191211232345.24810-1-robh@kernel.org> <20191212130539.loxpr2hbfcodh4gz@linutronix.de> In-Reply-To: <20191212130539.loxpr2hbfcodh4gz@linutronix.de> From: Rob Herring Date: Thu, 12 Dec 2019 13:28:26 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: Rework and simplify phandle cache to use a fixed size To: Sebastian Andrzej Siewior Cc: devicetree@vger.kernel.org, Frank Rowand , "linux-kernel@vger.kernel.org" , Michael Ellerman , Segher Boessenkool 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 Thu, Dec 12, 2019 at 7:05 AM Sebastian Andrzej Siewior wrote: > > On 2019-12-11 17:48:54 [-0600], Rob Herring wrote: > > > - if (phandle_cache) { > > > - 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)) { > > > - WARN_ON(1); /* did not uncache np on node removal */ > > > - of_node_put(np); > > > - phandle_cache[masked_handle] = NULL; > > > - np = NULL; > > > - } > > > + if (phandle_cache[handle_hash] && > > > + handle == phandle_cache[handle_hash]->phandle) > > > + np = phandle_cache[handle_hash]; > > > + if (np && of_node_check_flag(np, OF_DETACHED)) { > > > + WARN_ON(1); /* did not uncache np on node removal */ > > > > BTW, I don't think this check is even valid. If we failed to detach > > and remove the node from the cache, then we could be accessing np > > after freeing it. > > this is kmalloc()ed memory which is always valid. If the memory is > already re-used then > handle == phandle_cache[handle_hash]->phandle > > will fail (the check, not the memory access itself). There's a 1 in 2^32 chance it won't. > If the check > remains valid then you can hope for the OF_DETACHED flag to trigger the > warning. Keyword is hope. To look at it another way. Do we need this check? It is in the "fast path". There's a single location where we set OF_DETACHED and the cache entry is removed at the same time. Also, if we do free the node's memory, it also checks for OF_DETACHED. Previously, a free wouldn't happen because we incremented the ref count on nodes in the cache. Rob