Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp215821lqc; Thu, 29 Feb 2024 15:27:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWBaOB+InL6ScpWfmU0LHzprx1ZGNTQ3d6Ls6V6v9dNUylaZYzaQeplzzNrLEx6jNxMDT8vHnomaQFoXyzKNNmrN+yIYYrImqBQluQgIQ== X-Google-Smtp-Source: AGHT+IGunADtrmMG1J8YafqWvSnvwUzSKf2UstsUFNDtKti9BtZxTPNr3oqJ/O8gxD+KhiNLcjCM X-Received: by 2002:a05:6a20:9f45:b0:1a0:f616:32be with SMTP id ml5-20020a056a209f4500b001a0f61632bemr5114605pzb.10.1709249248926; Thu, 29 Feb 2024 15:27:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709249248; cv=pass; d=google.com; s=arc-20160816; b=rlwy38xHsjISnsqLmqNt8Luf9HlONU1+VhzbwfRLvzIZJ+7QLg9P78YsbAURjGWUsu 6cYKI3nsOQIgWQLe1pahuBepkcTe2o3fuO6jo80HopWKrjkXja/WXM9kCFP42CrbyLIO C9RCKgb9KVoZuQhOUkyWL0yWiVHyM5zM4jARE5R/hjUzUj3M+FhwfERYhVOJW2wR3Qjs oaRh6CfIoKgJJoWNpWho0/kVwRerR9Z+M+H4PKJdiW+egidEg+q1VkF1mpLsMyLPDkIw L5//Fn0OWM8YQ+nXfZPPssIs2m5kS8TjsOyuuS3Nyr7fZYU0krDWTX0i1ZG3Np27y+A3 SXrg== 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=2qC3fdiR3wpO9HRmx8vGtLqu6epk2+GZTHN12FsFnSk=; fh=wd0rlJnubXoUIZttjPHo9wUDsrNiR8ulSWgOdywD7uI=; b=O1fzrbKRoXHf2EtpjRYNpt4hu3qYUwTc8DQYA5oSw4U9/FdtsmKLAEpeLPKlWhIbgV 7oSUfIqSGpi+aa/1epq0r06/xeWP8wEcuyXL9qtWZlKJGHDuhApRePO5asBVfHp7njzq k9Hucq0eqJ0XtFMTKIhE3xYHIMkc0pQHjjyJGHgYEgzPIF83EtfzgEku+RLLPu077N1p DzTKU90ykhK4LsCsRTSiakH5uSmrc7EN68QkWzw+lvEIsh3+QW67kmGmMNkQkfrd11t0 OgJ3nfwaLWaS8TCQkoMlhT6Ozoe4euCmGH8V1eP25W3XjDWEoCahksii7rdYMG2ARS7w yJUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=A24Mc9Wi; 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-87688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87688-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 l14-20020a65680e000000b005e438e94b1esi2272770pgt.382.2024.02.29.15.27.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:27:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87688-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=A24Mc9Wi; 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-87688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87688-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 6D667B2279E for ; Thu, 29 Feb 2024 23:27:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B124200CD; Thu, 29 Feb 2024 23:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A24Mc9Wi" Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (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 050D97827E for ; Thu, 29 Feb 2024 23:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709249214; cv=none; b=NDy51LKKZ6hdwLWpl5SUqyG9P0sq0VfH75I0xMcfXms9E3fUey69FS/jaPNBLskW+RSBbvtE9CILZczV3zdb7fJbp+KmxZtJgheqj852wTxi/KlmaCaQ3/OOfm3OJYDxC1ze/Uau4axmOT+R80YRFmTjT75WQxpf5ljzpCzOf6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709249214; c=relaxed/simple; bh=XY+tF/oyv5RZqs+TYf1m3Rn6En+Ql1F7UgQnTwazuWQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ftOxHstopHTPbV4+k/rC7YbY1zGLoFhc0HhlAtGCYrKHuhm55fQoSgkEPPJ00znZja7TwLmNCxwXmaHQwO95puJagcyGF6VxSx2S0cMus1JJoYsms1BR8CxfHIw3Umkwr/JAFSxTCP3M761uWVs3I5A03T6D/k7VfvlzIShMB44= 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=A24Mc9Wi; arc=none smtp.client-ip=209.85.160.181 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-f181.google.com with SMTP id d75a77b69052e-42ec412cafdso17161cf.1 for ; Thu, 29 Feb 2024 15:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709249211; x=1709854011; 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=2qC3fdiR3wpO9HRmx8vGtLqu6epk2+GZTHN12FsFnSk=; b=A24Mc9WiSVEs5PorukWsU2KUenqSFBj+odxFx72XrNl8qJ7NHq/egTBXeDCf5tgmoE ZcREkBetYcmOehfzJr0CAxychPYapTfDhm6KO96lETs1L3GTnkCLEAZvqo9CBcLUVy6n qC3OUbov/Ldn15Td33tR3Ti1nQydbh+ntddvI0ubZxVfQume/3pK6uacneS3OCTohta4 k2yKLeTEdD9WKJxxJu55fQN2PRBZ9sDXsC7YJ6HdffiUmftnyyQAR4Bnx50xQ0vGv/fb BGPrKcZfBp2gXheNQTg7t4yPJwW42IIcjtMfew/0tZtHAj5hmgRSCG5thzYxHdZBLYd+ K9Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709249211; x=1709854011; 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=2qC3fdiR3wpO9HRmx8vGtLqu6epk2+GZTHN12FsFnSk=; b=Kz03XnYoTtX/2wjvJ6KThsp2NuqDvCBj91j3h0P4VcnQURrlMY33fj76egvLfEyw6f RLDY5d+rx8ZsO4cDWr8Jse/wcZvcbNQlZrIqXvW8GP0xkV4JX/n9pUNkNOTEGnn7wTJ4 KKOR6nZdkR6MT0fB2h9z+y8BYUffQ3CfEQL9QWmSvA7xPOwLafNb5B1ky/a+CbdYYd9e ESQRpqpzLyjU2wyq0G+2q6+mmqZewvuS4wXZrrt/ajcduXjS/nujBD+noUmMSKVp7xR8 WH/wYvf4x6WGnc5w8WfFvcQYfOtJaNO8ppdSYHkKJLo8qsd5gI4pScH5FFQvs4GDIJA1 fVFg== X-Forwarded-Encrypted: i=1; AJvYcCVdydym5yxOyVm4rSGPfNWQi/ErudRpakRmVhFmzoBtePcnd0+ziKvPyVdjHwrt7EnLfnHUOi2ETEilG32ZpxL++B6FbaXNTaHH+B0F X-Gm-Message-State: AOJu0YwsQwjcICSVHHsKUEFJkCmY31rRtBN26DhjPRwkrYg7+YlD66iM ILW3c6d0+HyAc4bCfh5aD2W7EyZceXXRFFhx2Q/5DpVEGTdP3F/13P9+3Schfjf1bZwBKwgjOYM 31JA6kKcN7QlbVSYgQ+U15VUrzFKABqiRNGig X-Received: by 2002:a05:622a:6:b0:42e:8e9e:3a1f with SMTP id x6-20020a05622a000600b0042e8e9e3a1fmr91697qtw.10.1709249210646; Thu, 29 Feb 2024 15:26:50 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231130174126.688486-1-herve.codina@bootlin.com> <20231130174126.688486-2-herve.codina@bootlin.com> <20240223101115.6bf7d570@bootlin.com> In-Reply-To: From: Saravana Kannan Date: Thu, 29 Feb 2024 15:26:14 -0800 Message-ID: Subject: Re: [PATCH 1/2] driver core: Introduce device_link_wait_removal() To: =?UTF-8?B?TnVubyBTw6E=?= Cc: Herve Codina , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , 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 , Thomas Petazzoni , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 23, 2024 at 2:41=E2=80=AFAM Nuno S=C3=A1 wrote: > > On Fri, 2024-02-23 at 10:11 +0100, Herve Codina wrote: > > Hi Saravana, > > > > On Tue, 20 Feb 2024 16:31:13 -0800 > > Saravana Kannan wrote: > > > > ... > > > > > > +void device_link_wait_removal(void) > > > > +{ > > > > + /* > > > > + * devlink removal jobs are queued in the dedicated work qu= eue. > > > > + * To be sure that all removal jobs are terminated, ensure = that > > > > any > > > > + * scheduled work has run to completion. > > > > + */ > > > > + drain_workqueue(fw_devlink_wq); > > > > > > Is there a reason this needs to be drain_workqueu() instead of > > > flush_workqueue(). Drain is a stronger guarantee than we need in this > > > case. All we are trying to make sure is that all the device link > > > remove work queued so far have completed. > > > > I used drain_workqueue() because drain_workqueue() allows for jobs alre= ady > > present in a workqueue to re-queue a job and drain_workqueue() will wai= t > > also for this new job completion. > > > > I think flush_workqueue() doesn't wait for this chain queueing. > > > > In our case, my understanding was that device_link_release_fn() calls > > put_device() for the consumer and the supplier. > > If refcounts reaches zero, devlink_dev_release() can be called again > > and re-queue a job. > > > > Looks sensible. The only doubt (that Saravana mays know better) is that I= 'm not > sure put_device() on a supplier or consumer can actually lead to > devlink_dev_release(). AFAIU, a consumer or a supplier should not be a de= vice > from the devlink class. Hence, looking at device_release(), I'm not sure = it can > happen unless for some odd reason someone is messing with devlinks in .re= move() > or .type->remove(). The case we are trying to fix here involves a supplier or a consumer device (say Device-A) being device_del(). When that happens, all the device links to/from the device are deleted by a call to device_links_purge() since a device link can't exist without both the supplier and consumer existing. The problem you were hitting is that the device link deletion code does the put_device(Device-A) in a workqueue. You change is to make sure to wait until that has completed. To do that, you only need to wait for the device link deletion work (already queued before returning from device_del()) to finish. You don't need to wait for anything more. I read up on drain_workqueue() before I made my comments. The point I was trying to make is that there could be some unrelated device link deletions that you don't need to wait on. But taking a closer look[1], it looks like drain_workqueue() might actually cause bugs because while a workqueue is being drained, if another unrelated device link deletion is trying to queue work, that will get ignored. Reply to rest of the emails in this thread here: Nuno, Sorry if I messed up who sent the first patch, but I did dig back to your v1. But I could be wrong. If devlink_dev_release() could have done the work synchronously, we'd have done it in the first place. It's actually a bug because devlink_dev_release() gets called in atomic context but the put_device() on the supplier/consumer can do some sleeping work. -Saravana [1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tr= ee/kernel/workqueue.c#n1727