Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1916326lqg; Mon, 4 Mar 2024 07:34:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtoS6I2bmfTWsenxXZpz433c5yqSRIY1KeauyImqL//t4inZgotVxij2HNkM5jcOc0Q9Wms1DI3f2O+jujQFyXJt7V4gl3CNxR9wch+w== X-Google-Smtp-Source: AGHT+IF66G/dwvJm4aEkHhXFwca7ac49AMBpzT5xw+E22hSo+fKn/ODymrGZ9GAuZj5wqilFAO6D X-Received: by 2002:a05:6808:6397:b0:3c1:86e0:49f2 with SMTP id ec23-20020a056808639700b003c186e049f2mr8238515oib.55.1709566488658; Mon, 04 Mar 2024 07:34:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709566488; cv=pass; d=google.com; s=arc-20160816; b=qM1VBflbhfLao/flC/pNmaXDUVkg4GmnVnD8QmW93P7hZoIbeKxxDv6neVQf67EApL rV3AsvKU6YDoOf0A4/7oRZADXeRqNifByHTEi3LbNYdnF8QDo3zL7vaS+LqdOIly4ygD b6Qm3LoeiMGgYUfx2uej5c+Pl2eKUTLTCEAnQLHijkTCobLdIuTQpLO5gacAbtfVpOL0 BDwaLoIKTVj7ozvuEcN9pyrOZN3xJvrlskK9nW4U8eGsKxtCwEuiX2UCXBT6IfnIO9Vn ZJrPe/68vh5ilCrRwF1N2uBZI+1Knp8hskgG6QT9JPQXVPV2QYGIJhmuo6cwG78j9l9O Otzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=bWvYOuCuRfEcVskjhEHNCFWud68WSGUgd2zUqGEpjT0=; fh=nCgSGujAWUaImie74pZauWLQmlfEgQLEbWe7O8lpBWo=; b=LQcFSOlIILzzH6Y1VScz6fFDVtf3ge1gNO9Ek5vnSJG9x9mBqVgMbi/gbIgJx0ywXp zzzlArtYOCCetvaRGkK0gnIFWeP3QCrzRxd3+F98CF6aZnhIR8ZniYq1URgV/CuipI8d 0gBdz1kznErXdpYYX8ZLmnll8vqr+hfhvC0eRBb7OfziOAP1cw6Z1KgATMzaDmuGoe5L TUw9mouyvm8PvaHnBQT/dT/CAd7+ob0R7CNzVU8nqDaEB6Oj9HqOUpkjlXWi7js+YaxZ oFqQDAoU5vvCEsCa91dkgRwe4ysHi7Ey778EVTrfQLQTg2nomUtTe1Q8KJgX/K6gqfDh eQCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IwV6aY0S; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-90838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w15-20020ac857cf000000b0042e224098e6si4833803qta.467.2024.03.04.07.34.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:34:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IwV6aY0S; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-90838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 553421C22EF3 for ; Mon, 4 Mar 2024 15:34:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8013C46B9A; Mon, 4 Mar 2024 15:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IwV6aY0S" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0CE44D134; Mon, 4 Mar 2024 15:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709566375; cv=none; b=QxtWonXixoUtumE8D4fGUmiIEQYa+V8lZkTj8xOPotrUSCc4NB65upGYQdb3UMq+Fqznea/+mt8PhxNr+gwlvu6ugYusnsagj/XJfN9JdDrBlhIyRlKcCar6HpUFq+vsFV5HkepkEhERoL0nBoJLIjzmBIjM29imt9xoy4SjTFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709566375; c=relaxed/simple; bh=3EAj3xv1au4Q4TJ50vvjHAcAy5htc0pMEaTTLlfhjOQ=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=c98cGUrQvBOvqo7XGLOaGpPfH5Won6BS+xUeMfapek2/QjEAMNXeBY5Vq7e2x/HlVuBAgQy/I0KInGee8cimDa2ni52CWdxPZOuIH9yVHBG07mvIJsqqHn0FGCUPrdm0JkzMLhAq61UN0HDRPWGHLZdSBUHJysBrklaxldk8xwY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IwV6aY0S; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a441d7c6125so562907966b.2; Mon, 04 Mar 2024 07:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709566372; x=1710171172; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=bWvYOuCuRfEcVskjhEHNCFWud68WSGUgd2zUqGEpjT0=; b=IwV6aY0Szpjtuexl28y/Bg5Dzx2rQ3Mf07TlyJbpZIvjp+rsxbH/TBcFmb4ZIDH/fz Gj87MHiS5CIqUjlHg8SEBaMMrXu4nHnEHsj6kZGPGnp6CIMWlmPR97PGY6BovE2mzbGG HyJ11E2ZFMD1YATGRNl6lrQi7QAZQoP7L9HIlOgeB5NWRYYbNq/TG7AgPACg86Gf/ciG Ic+hQcmpI5eeI1Fce64wUA6uYMneuP93ybU/sTzgH5CF4kdvmTyOOC/4G5WKbdRKHEl6 vRke1BbVd8aj8lC6PPu+nNnElTg4CNe88THHmoWnchVq9k1d3B6oXIajB0uziDlLcOd1 EhSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709566372; x=1710171172; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bWvYOuCuRfEcVskjhEHNCFWud68WSGUgd2zUqGEpjT0=; b=lOZ7VcF6w+F2OkX6kTWcdf+ENp9qJtfuNFPtOgkRKvIZPYfsLljPfXVwNFyp5jnRwE RAFmh7+BB+FxgsPkU60dlkVKPVx4h6CHMGEYyRnhTsYRE5dFV3W6mmxIZDnYDhy3+nxX xHJNXhVLoJnjGKh+alVsxac6NYT9zHHf2sUY0lQ+bPyveHNCGLAXAqza3b2O7ERTc54S VxzUhuGrU14BA+Zsjk5SusMRQzNtzrEfBUdIKv1jIIb/yq12/Szblq1c9KR21nPVYyYb +0andbAxj5BI70dx9npG5GYmGnza2UwZvcICdJCAvMhucF5yMNt+Wyzm3IfPdAlOMPlQ PHtg== X-Forwarded-Encrypted: i=1; AJvYcCWicphpRxCFdQB7ED0O3QBs3me51CHiGYNrpcFetXiooWpUSMcwLWlIYavv2zAIQxTjAN77ni2HeDqLiyvh8/LFdjpF0OnHl4ZFIYDidotF0/WmVdrSrKOkKUACzemj+f2QPk9rFHv0/EOtjYGwmco9vMkMpodfc6cW4n3dK/mhrg== X-Gm-Message-State: AOJu0YwvpwXMwv+fcjpluJv9wL4nohcO6ez0MeMeBM//WvO71hHkihHD OY6EjwgoLD6FmRp4lAYZbndUgNcHShtxXz8wTemmPtxsf5V7ic/v X-Received: by 2002:a17:906:f35b:b0:a43:fd9e:2d69 with SMTP id hg27-20020a170906f35b00b00a43fd9e2d69mr7096029ejb.6.1709566371768; Mon, 04 Mar 2024 07:32:51 -0800 (PST) Received: from ?IPv6:2003:f6:ef1b:2000:944c:cbc7:1e1c:2c47? (p200300f6ef1b2000944ccbc71e1c2c47.dip0.t-ipconnect.de. [2003:f6:ef1b:2000:944c:cbc7:1e1c:2c47]) by smtp.gmail.com with ESMTPSA id wp1-20020a170907060100b00a44ce0671b1sm2937118ejb.108.2024.03.04.07.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:32:51 -0800 (PST) Message-ID: <93d0adf0ee6f3737af4d482dc206fe152f762482.camel@gmail.com> Subject: Re: [PATCH v3 2/2] of: overlay: Synchronize of_overlay_remove() with the devlink removals From: Nuno =?ISO-8859-1?Q?S=E1?= To: Rob Herring Cc: Herve Codina , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Lizhi Hou , Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Luca Ceresoli , Nuno Sa , Thomas Petazzoni , stable@vger.kernel.org Date: Mon, 04 Mar 2024 16:36:15 +0100 In-Reply-To: <20240304152202.GA222088-robh@kernel.org> References: <20240229105204.720717-1-herve.codina@bootlin.com> <20240229105204.720717-3-herve.codina@bootlin.com> <20240304152202.GA222088-robh@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-03-04 at 09:22 -0600, Rob Herring wrote: > On Thu, Feb 29, 2024 at 12:18:49PM +0100, Nuno S=C3=A1 wrote: > > On Thu, 2024-02-29 at 11:52 +0100, Herve Codina wrote: > > > In the following sequence: > > > =C2=A0 1) of_platform_depopulate() > > > =C2=A0 2) of_overlay_remove() > > >=20 > > > During the step 1, devices are destroyed and devlinks are removed. > > > During the step 2, OF nodes are destroyed but > > > __of_changeset_entry_destroy() can raise warnings related to missing > > > of_node_put(): > > > =C2=A0 ERROR: memory leak, expected refcount 1 instead of 2 ... > > >=20 > > > Indeed, during the devlink removals performed at step 1, the removal > > > itself releasing the device (and the attached of_node) is done by a j= ob > > > queued in a workqueue and so, it is done asynchronously with respect = to > > > function calls. > > > When the warning is present, of_node_put() will be called but wrongly > > > too late from the workqueue job. > > >=20 > > > In order to be sure that any ongoing devlink removals are done before > > > the of_node destruction, synchronize the of_overlay_remove() with the > > > devlink removals. > > >=20 > > > Fixes: 80dd33cf72d1 ("drivers: base: Fix device link removal") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Herve Codina > > > --- > > > =C2=A0drivers/of/overlay.c | 10 +++++++++- > > > =C2=A01 file changed, 9 insertions(+), 1 deletion(-) > > >=20 > > > diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c > > > index 2ae7e9d24a64..7a010a62b9d8 100644 > > > --- a/drivers/of/overlay.c > > > +++ b/drivers/of/overlay.c > > > @@ -8,6 +8,7 @@ > > > =C2=A0 > > > =C2=A0#define pr_fmt(fmt) "OF: overlay: " fmt > > > =C2=A0 > > > +#include > >=20 > > This is clearly up to the DT maintainers to decide but, IMHO, I would v= ery > > much > > prefer to see fwnode.h included in here rather than directly device.h (= so > > yeah, > > renaming the function to fwnode_*). >=20 > IMO, the DT code should know almost nothing about fwnode because that's= =20 > the layer above it. But then overlay stuff is kind of a layer above the= =20 > core DT code too. Yeah, my reasoning is just that it may be better than knowing about device.= h code... But maybe I'm wrong :) >=20 > > But yeah, I might be biased by own series :) > >=20 > > > =C2=A0#include > > > =C2=A0#include > > > =C2=A0#include > > > @@ -853,6 +854,14 @@ static void free_overlay_changeset(struct > > > overlay_changeset *ovcs) > > > =C2=A0{ > > > =C2=A0 int i; > > > =C2=A0 > > > + /* > > > + * Wait for any ongoing device link removals before removing some > > > of > > > + * nodes. Drop the global lock while waiting > > > + */ > > > + mutex_unlock(&of_mutex); > > > + device_link_wait_removal(); > > > + mutex_lock(&of_mutex); > >=20 > > I'm still not convinced we need to drop the lock. What happens if someo= ne > > else > > grabs the lock while we are in device_link_wait_removal()? Can we guara= ntee > > that > > we can't screw things badly? >=20 > It is also just ugly because it's the callers of=20 > free_overlay_changeset() that hold the lock and now we're releasing it= =20 > behind their back. >=20 > As device_link_wait_removal() is called before we touch anything, can't= =20 > it be called before we take the lock? And do we need to call it if=20 > applying the overlay fails? >=20 My natural feeling was to put it right before checking the node refcount...= and I would like to still see proof that there's any potential deadlock. I did = not checked the code but the issue with calling it before we take the lock is t= hat likely the device links wont be removed because the overlay removal path (w= hich unbinds devices from drivers) needs to run under the lock? - Nuno S=C3=A1