Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp216854lqs; Mon, 4 Mar 2024 22:48:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWiFSAv69N8toGRZfIefmXCHBeKKgC0+91Blkupbd6fv9fHPOk/Akiy5/tbDSaBiw1nmfz8Tioc5CYGa5mOTAAccNUGaEDg/PWMtyfmGQ== X-Google-Smtp-Source: AGHT+IFuKreez2RX0rUmmJVv2M+HYiUlfRxJqV6I9ZglsxOQJUvgcJnbWc7IjAt6fi9mFF1tDha6 X-Received: by 2002:a17:90b:815:b0:297:4f1:8a19 with SMTP id bk21-20020a17090b081500b0029704f18a19mr8868477pjb.23.1709621282145; Mon, 04 Mar 2024 22:48:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709621282; cv=pass; d=google.com; s=arc-20160816; b=kJY71UTG4Uoafgk5gkx7YczyasUlsQSRoAaqtnxWPRfa+i2dYXlHB01peCbn01cl8s f9xaCMZ2BMqGX6T8YC4zvz5l/BxJcBz/eBdgeq2GuAR+ietqUg9s47CoH1qdfUnLMDY0 fuwt6ts8nrvDkrvcN7ghVQMsaVDRtL6boT0rwNe7Nhie/inI/ueoB8W6uhZBu7qStHXU ZIW47T3LGJmj0aVoD9UaL6wEextAlDlYa50J8hZ1G4qLbH0GUVIHIIfgpPF/tkmsVxRN mCz0q9q2Xym5ETJ1tnRJYO8+KEGEEsj60HznmbB/bRJl+k2EUqzy5Zi0CfgGwwFBvGa0 s84g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=2isqh14d05L6zoJqPkxhn5o+6H4cX5aRd/OEiiiX0AM=; fh=nAv+Mj9y/vXOF1pXytK+ZM7BpuZetbVD6wZ9NfaygZU=; b=ILTjhyhCIyKq+sInh8n9Q78G7X5x1PNzcQomcnB0pPtXBgpKuSFo22Pa0nJ/rCNghX 17J35kvijZQ/0KYcS1ZnB41BPMQQnJRysXaksx2l0oq9i/3bL8pvwn6TiBWHPm5I286S 5RFqJvpK0+PaYu7mV0fiQpg6LqAzzixsL7ZTW9lx6+HG6SJ2uvhdE+wqMrWZiUEejRSU mGfinNYszUtF5uRRr1vJcsUdmE/hg+eA/gRhX5YyBfIDYu9Arl5REVsCExmj7OEv53X0 wc2pN4ydH+l0EDLoQhOn8aTCmXwt8wAnNKz0icQfQs9kEXQ2eoExp3hlCJzOKMRiW13J hwig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ONVtEDtZ; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91747-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id nc8-20020a17090b37c800b0029a90ca16d6si9700454pjb.22.2024.03.04.22.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 22:48:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91747-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ONVtEDtZ; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91747-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4952BB23B52 for ; Tue, 5 Mar 2024 06:47:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36F9645C14; Tue, 5 Mar 2024 06:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ONVtEDtZ" Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 A4F4B405FD for ; Tue, 5 Mar 2024 06:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709621270; cv=none; b=ap6A4YvpauiTNRDueHRiIvzs1QlEQjskFc/boiV+9PPrKpMxHif6YCd15I7JTrhz08MUPHjwhvO80iCrGpPAnB3LE4Ql14/KmC6AGX2DZUUgfQ4c/jVloU/LpSUlQykAEezX7T+wQi7YUChsu5HFaVwfMnDsEHtw7x6kmdMaya0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709621270; c=relaxed/simple; bh=O4yVRud/9+8a7tAKirWeQ09Db+zegMJkuUhSNXLZlLs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=p1tqYNUKaIgE6MZL4TvlRw24lM4lZBhYFJym3FJt1wzqdJma9JVru3YNfKBE//kMX0E0nn4QLvBjXcxuAC7MjkU0Dn8YYZl8/D4ufH32mG5suG0FfN+k3Gr/6j1F0Cudyjbw279YO+8J3ynB+G3DB+G4+oDnAQ8ldqWmYZ1S5g8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ONVtEDtZ; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-42ef8193ae6so128601cf.1 for ; Mon, 04 Mar 2024 22:47:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709621267; x=1710226067; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2isqh14d05L6zoJqPkxhn5o+6H4cX5aRd/OEiiiX0AM=; b=ONVtEDtZdzGnMJI+zo6Oxb19tlK2LZZG1OtKEJjSDJAbbkfK8OghKuvZmaFYcvu/aw 00nQIKJ0STugS5NGNpDi52ueOHzrs0jBU6LCJZnjeg0F7K0+0hojasrLKyBPdrzICwgb a7CQp8m9NJelj/uwWRMVpwDOVjY/erQQLQTrJH84wDptjLL3dF7q19YffDMjCh+T19bI EvCnvg71oWAhY/fcuW69km/FZ0iiWilN4rGQACnmQHkDKyYdodgWzEgOjV+132sCYSlc HmvoSu6vEIhJCXZeWKPcRT680jedt7PLqjL8biSxsTx3nLognxntH+qptoTxnKN8WKzF bMrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709621267; x=1710226067; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2isqh14d05L6zoJqPkxhn5o+6H4cX5aRd/OEiiiX0AM=; b=dP5K1wED4Fz2SM3zOd1+ZUvdSY+L7QhxHfk4mL1EzAIIPLZtu2hAXy5dNUPl2mMYQZ /7TTqb7Q5y3cUCofyQh7ZJJ6hU9BBzElyxWO+Isb8SPgUVMEalADwijCTF/Yhnmvgxg+ HquY68dv9qKEoGNHYIJbTvkZo21FH/G8lIctndKjC3+o1EAXMVVZdExDPF2Wl1FJdbE5 t7yw1nXdpm/8fmLRetRSV2Pzy2gupdtejmKizKfmfBwM3L3kZGzIS8EFH61Ef+PeWV8O m8uGxGq3JrVnfu+EwQfU3GLspnWZ3Vnimd5mYTQhdkTKmMCY+28jmIEAKlZR0likabws RXVw== X-Forwarded-Encrypted: i=1; AJvYcCV0QfG2ogRxCMCzWQsU6OYk2uuKnMynLE48l3nIykB13LWVbCiZsHiNwVlZVhV/AgAxMktMHh0Knq7+Hm628Qk60YGBLqoqtOrdk3we X-Gm-Message-State: AOJu0Ywqw2vQ65VUMsfYNz+LCfGC+VZ+nmLiTrEWmyPYhEl3KBIoIfKN mIKNXA42nw48+/1SMe+3wsaPhXv8aHImOjA5xSJ7rCrGgT0EkQ2GptlIfgVmpyt+TL+x7E/6sX6 3YYUHipAhem40ZTtyL65+q82GW/zeN2a6SikF X-Received: by 2002:a05:622a:1985:b0:42e:e0da:343d with SMTP id u5-20020a05622a198500b0042ee0da343dmr123630qtc.10.1709621267471; Mon, 04 Mar 2024 22:47:47 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240229105204.720717-1-herve.codina@bootlin.com> <20240229105204.720717-3-herve.codina@bootlin.com> <20240304152202.GA222088-robh@kernel.org> <20240304174933.7ad023f9@bootlin.com> In-Reply-To: <20240304174933.7ad023f9@bootlin.com> From: Saravana Kannan Date: Mon, 4 Mar 2024 22:47:09 -0800 Message-ID: Subject: Re: [PATCH v3 2/2] of: overlay: Synchronize of_overlay_remove() with the devlink removals To: Herve Codina Cc: Rob Herring , =?UTF-8?B?TnVubyBTw6E=?= , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 4, 2024 at 8:49=E2=80=AFAM Herve Codina wrote: > > Hi Rob, > > On Mon, 4 Mar 2024 09:22:02 -0600 > Rob Herring wrote: > > ... > > > > > @@ -853,6 +854,14 @@ static void free_overlay_changeset(struct > > > > overlay_changeset *ovcs) > > > > { > > > > int i; > > > > > > > > + /* > > > > + * 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); > > > > > > I'm still not convinced we need to drop the lock. What happens if som= eone else > > > grabs the lock while we are in device_link_wait_removal()? Can we gua= rantee that > > > we can't screw things badly? > > > > It is also just ugly because it's the callers of > > free_overlay_changeset() that hold the lock and now we're releasing it > > behind their back. > > > > As device_link_wait_removal() is called before we touch anything, can't > > it be called before we take the lock? And do we need to call it if > > applying the overlay fails? Rob, This[1] scenario Luca reported seems like a reason for the device_link_wait_removal() to be where Herve put it. That example seems reasonable. [1] - https://lore.kernel.org/all/20231220181627.341e8789@booty/ > > > > Indeed, having device_link_wait_removal() is not needed when applying the > overlay fails. > > I can call device_link_wait_removal() from the caller of_overlay_remove() > but not before the lock is taken. > We need to call it between __of_changeset_revert_notify() and > free_overlay_changeset() and so, the lock is taken. > > This lead to the following sequence: > --- 8< --- > int of_overlay_remove(int *ovcs_id) > { > ... > mutex_lock(&of_mutex); > ... > > ret =3D __of_changeset_revert_notify(&ovcs->cset); > ... > > ret_tmp =3D overlay_notify(ovcs, OF_OVERLAY_POST_REMOVE); > ... > > mutex_unlock(&of_mutex); > device_link_wait_removal(); > mutex_lock(&of_mutex); > > free_overlay_changeset(ovcs); > ... > mutex_unlock(&of_mutex); > ... > } > --- 8< --- > > In this sequence, the question is: > Do we need to release the mutex lock while device_link_wait_removal() is > called ? In general I hate these kinds of sequences that release a lock and then grab it again quickly. It's not always a bug, but my personal take on that is 90% of these introduce a bug. Drop the unlock/lock and we'll deal a deadlock if we actually hit one. I'm also fairly certain that device_link_wait_removal() can't trigger something else that can cause an OF overlay change while we are in the middle of one. And like Rob said, I'm not sure this unlock/lock is a good solution for that anyway. Please CC me on the next series. And I'm glad folks convinced you to use flush_workqueue(). As I said in the older series, I think drain_workqueue() will actually break device links. -Saravana -Saravana