Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2821412lqp; Mon, 25 Mar 2024 10:06:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKklrNugAJWUvP813+UmcQ+fFT/KzhMJwyy25e28tAxBVhOrgCkhNLPM7W86iWHMMqiaHa54eyP0PZ+xYgwOL68givFiokYfZS33whlw== X-Google-Smtp-Source: AGHT+IHjCTIgzRjD6YTjxQ+Bqurx2d62kj9K5tK63LF8VE9ouLYpVaO/bcWtkEBD0ynTPfkbZIOH X-Received: by 2002:a05:6870:7252:b0:220:a0b0:6d4a with SMTP id y18-20020a056870725200b00220a0b06d4amr8927076oaf.57.1711386397201; Mon, 25 Mar 2024 10:06:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711386397; cv=pass; d=google.com; s=arc-20160816; b=IUf9ejQBf3WTGBBEBR2Cu9spwIwhg7PM/GMkiIjPD1nr0SMVR5DXs33o34EUfTTYML Mcy+7Jxfm7s/jbC1Sj9I8L5gb/JsNxBE1Rwy+BGSoXBPFfC/bsobTFDQQxCkiF7YUPsp eO0Okun8+kOXjpAHHklliY8dDX4G0lcePMvus6b4wkzJiHN0AlJtVbuekzbW/M3msWnU koHVMNP7F05C6DGkhHY2fngd7tLtqv2/nqpffN3sWsjnOo7uAx8ejNkIw1t7KIXWq0VS gqrYTCLjb6LpJYfRgVAy1SL6LDDrN4THfRO/lclrU9QTgxufEtWQAmMJ7peaLqy/4b3f wueg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=yrwq/MwRkPr6XM5PqLQGjO/LfIdYiz0l6AT8j8PAEYs=; fh=WMU+t/lZydSWvh8ilBwNK1bagSF8n8uwFAMy6K6jlJ8=; b=A1VhqeaIQchE1p51pfqoKjXzATkEvZ3/Qv8PClyogskcd14psUKp6Ep1+zLHir77Dt QsBEF9kjtz0cUT102aL16fHiIqcbj8mS9YFtb9sj+2Ov5GcRqp8ZQrE//VtxL34ZCyWl P4vOO3dZCLP5mUVOEsncOcl9KB7NTYe5e+a1C1jXI1DTH7IWVrUz2NpgisXONVCOVkak 1wj//obx6ViC0eRiAWOzyIw/+ET1l3/4p7Y4PDJkPTSz4cgpNag3deSHlSInPP4Ko9PW P6ujRZcNVosLvO0rzviBSlhuSMQHIIdU8qLOW0b8h+grbayaGSCHmis09YhFbsxoHeqG z6+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fv4hX1dM; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-117354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c13-20020a630d0d000000b005d8c118be4dsi7777579pgl.136.2024.03.25.10.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:06:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fv4hX1dM; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-117354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AE009297F3B for ; Mon, 25 Mar 2024 16:56:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2C4313A41A; Mon, 25 Mar 2024 15:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="fv4hX1dM" Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A08E818C08; Mon, 25 Mar 2024 15:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711380119; cv=none; b=Di2D9pSZRzVFrwEyvsEh5nVXESKzcmm24JYouchH6MuhMbF4sJopnvuOx2dFvCOeIMb5hMDwyNOHwZ879Ez5QyrnOnfEFEoJrQk5NWRp0BXWEmfkUwnsBxvtSkxqYrrMNauqUjChXpVr4vg95NA2UPc1+9p5PKB1GKJwEgvKp7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711380119; c=relaxed/simple; bh=Z7ZRXeLKdWuIY/i4KBUBO0qa0OtkvNi41/wthDRv3uw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U23Ei0L54TLzRgSjB9HUC8pLt3X7RpkI+QaewFcG6A+2o+gF1q0g3qgYylT0yPMsz6VPljwvF3BBCt1WLXWTg6cIKwGgPWRtq0TRXho2rhQyRJgzT7askhpTldCflLTiRgG1if8q5nf5grUfCvJ4THjNK0TdJfRIxO1TrtOe9AQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=fv4hX1dM; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 8A71EFF809; Mon, 25 Mar 2024 15:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711380114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yrwq/MwRkPr6XM5PqLQGjO/LfIdYiz0l6AT8j8PAEYs=; b=fv4hX1dMW+whUxlXO6PgrPO5FtqLEOtD+3oSMlR0Lpw0faFS4WnQfo0Q9MHRSo0H2cXV8A roGJGgheYN+BFl2m+adPgf35EfnWlrD7eDSeYq+CccTGbYUTcKWkFmegq/gfPQl/O/Sckj 8b6u2YAhUFu+nvSVhVwBKWPqlMHktQe5wjMsl61/03ZPvlKIdzDKL/7pWvAMVjvR0bcIzN WrG70/iCB7tIHCjz9MWqozwi1f3xHAt88zaIVyYam29pONMIEfV377vfJOULAycBDjdK6k P7Lae/bOF4LRlA6YkTQ/R6aOf0/b25cVf8Jc/PQrfbi/ybybtohR0GIppFzBNA== From: Herve Codina To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Saravana Kannan Cc: 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 , Herve Codina Subject: [PATCH v6 0/2] Synchronize DT overlay removal with devlink removals Date: Mon, 25 Mar 2024 16:21:24 +0100 Message-ID: <20240325152140.198219-1-herve.codina@bootlin.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com Hi, In the following sequence: of_platform_depopulate(); /* Remove devices from a DT overlay node */ of_overlay_remove(); /* Remove the DT overlay node itself */ Some warnings are raised by __of_changeset_entry_destroy() which was called from of_overlay_remove(): ERROR: memory leak, expected refcount 1 instead of 2 ... The issue is that, during the device devlink removals triggered from the of_platform_depopulate(), jobs are put in a workqueue. These jobs drop the reference to the devices. When a device is no more referenced (refcount == 0), it is released and the reference to its of_node is dropped by a call to of_node_put(). These operations are fully correct except that, because of the workqueue, they are done asynchronously with respect to function calls. In the sequence provided, the jobs are run too late, after the call to __of_changeset_entry_destroy() and so a missing of_node_put() call is detected by __of_changeset_entry_destroy(). This series fixes this issue introducing device_link_wait_removal() in order to wait for the end of jobs execution (patch 1) and using this function to synchronize the overlay removal with the end of jobs execution (patch 2). Compared to the previous iteration: https://lore.kernel.org/linux-kernel/20240307111036.225007-1-herve.codina@bootlin.com/ this v6 series: - Add Saravana's 'Reviewed-by' tag This series handles cases reported by Luca [1] and Nuno [2]. [1]: https://lore.kernel.org/all/20231220181627.341e8789@booty/ [2]: https://lore.kernel.org/all/20240205-fix-device-links-overlays-v2-2-5344f8c79d57@analog.com/ Best regards, Hervé Changes v5 -> v6 - Patch 1 Add 'Reviewed-by: Saravana Kannan ' - Patch 2 No changes Changes v4 -> v5 - Patch 1 Remove the 'Fixes' tag Add 'Tested-by: Luca Ceresoli ' Add 'Reviewed-by: Nuno Sa ' - Patch 2 Update comment as suggested Add 'Reviewed-by: Saravana Kannan ' Add 'Tested-by: Luca Ceresoli ' Add 'Reviewed-by: Nuno Sa ' Changes v3 -> v4 - Patch 1 Uses flush_workqueue() instead of drain_workqueue(). - Patch 2 Remove unlock/re-lock when calling device_link_wait_removal() Move device_link_wait_removal() call to of_changeset_destroy() Update commit log Changes v2 -> v3 - Patch 1 No changes - Patch 2 Add missing device.h Changes v1 -> v2 - Patch 1 Rename the workqueue to 'device_link_wq' Add 'Fixes' tag and Cc stable - Patch 2 Add device.h inclusion. Call device_link_wait_removal() later in the overlay removal sequence (i.e. in free_overlay_changeset() function). Drop of_mutex lock while calling device_link_wait_removal(). Add 'Fixes' tag and Cc stable Herve Codina (2): driver core: Introduce device_link_wait_removal() of: dynamic: Synchronize of_changeset_destroy() with the devlink removals drivers/base/core.c | 26 +++++++++++++++++++++++--- drivers/of/dynamic.c | 12 ++++++++++++ include/linux/device.h | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) -- 2.44.0