Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp616892pxv; Thu, 8 Jul 2021 09:59:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqpJYy8F/XahMXJxffMDgXxvjdaA4gIX0zxbgj6IVjM2UsdEhnkpc8AymdoNB1SQs70CEV X-Received: by 2002:a05:6602:2093:: with SMTP id a19mr17699056ioa.200.1625763582018; Thu, 08 Jul 2021 09:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625763582; cv=none; d=google.com; s=arc-20160816; b=ycVbJfjz7loIRs4Ux+gS/ingbqAhPH+6d386UXlOXIwLDM3CMYPkxZIYnSZd7F0bWN HWjFhZnumCqDDrJgkmyejfV7ikK3wvCHbhb0O8E9lAYDctbGZUCmGAOzHJyXP5UVkdy8 9Upuxds00DIXoUBTOe0iPPwd4PEnf2S/2SJPukVJOmxNtoxLQJmlAyq5sIr4te+vDWTo bUwRs/IEYVWPwRdFa5/VVbeZU05U5bCFcQINlqlcNPZoTf2shFxJ4ZQa1v+b68rGvb3S ad33MrAJYg3AsOZC7o+vuRUc6nK4mJCCOv/IY7hdQS6lsAgUo6c2Rr5qDjtsnVF9O3M5 p4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2CS38GY8uch1zA08SQ4xz6CBM44J4uI/8FoF/YQIRvg=; b=YpVy7OfxL8K1t0Kq634hKCdI3fnABJyQYKh6fG7hOrLHL3R5mM/PyPX3aIteNDSiRo /MsqXB6Yu82W++2bS7v1QurYsk2TW+cYgexTlsVR6TCuqiA27kGfMjohSwLsAPxEU8ta 9wfDHE2Txe/ESL+DwXiGIC5k1SzCgP4qEuM96e6VAhezEDwde0BSL9vvI6q6aHG3IVWO 07HDyRt5vCw98dwmcwm7YRFvj+eixBja1PDSJDl+0kyjRmpTSEShAYa/hvpgkCSiBtEw gZwPZQpIGgL+l09Q2G/kceAby0mZjuIXolYe0oliCH1Vp0ffr8kMDQSErtR9MuZVwqvI OSeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m8XywZ2+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x22si2478047iow.99.2021.07.08.09.59.29; Thu, 08 Jul 2021 09:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m8XywZ2+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229516AbhGHRAX (ORCPT + 99 others); Thu, 8 Jul 2021 13:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbhGHRAU (ORCPT ); Thu, 8 Jul 2021 13:00:20 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B6DC06175F for ; Thu, 8 Jul 2021 09:57:37 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id g19so9999204ybe.11 for ; Thu, 08 Jul 2021 09:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2CS38GY8uch1zA08SQ4xz6CBM44J4uI/8FoF/YQIRvg=; b=m8XywZ2+S9UOWKZmzx/D8unKfUc0zQgMFZMupUXrfvQ1W7WhFP6Q2bXBW2DvqTJNDF sWvhuUlLRlanBWYnkusi47QZxNLB3oHqqzFG2OEBkbSj74/lknP4zAdzSwClyWiTuvZ4 PWDnFFv8AsiqZbSJkpEH+H07F66xB2yqu8T1GwqJhxTItaJCauQXY1Y+nIxioLFmQQL1 OYvrW1QQxi9VBCf8ocG+lkouQDEPYkKtrxZcQ+OA/S6reyIV8LY9sGNH7zo1uNl3usMB UI9k1YuR8ov+3FJdH5uJyLdVL5mLZ2WX3+Cb4NqXQBZlnxQmds5KMR8avZBsK4FwUUVC NpBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2CS38GY8uch1zA08SQ4xz6CBM44J4uI/8FoF/YQIRvg=; b=bfgxXoLn9dUgMy3qCMZQ4WS4QDXzZKhx6ZD/of3dhS3FHel/cKg4yOCD7neMsXsjCp KN3tG1EH1kRnf4stR1hf+Zd8jFmNY1Zk0HlgBeFrwIUe68tc0bPfCbe7xLTvU7sw9pRb 5rSu9bnVwfIqadUZinwJgXzdQQkMwingFnKCddwriqnVvBz4OdOm/TkSQ9VhEeR1hhqm KIIyS8ewaXZjSRYb+HaeERBZut9jBJaVSD0P1quKHLx344Ts4vqz7Wft8ZZJY1Lzx334 zXmCxpHRbt52cQvoh2PlJ+5/pXjvqerjl3xS6qk7UuvCPr3ahcqf4VnlWQ84j9bKRnPP kKAg== X-Gm-Message-State: AOAM530KMKnWnhQkYcm/jMTVQATmJAa5vLTN5Q3x86ZuMYiP3FwEox+1 zqwhyVLezK6xRh4o1undyGNrum8/rDlcN2ZALxLQBg== X-Received: by 2002:a25:8b91:: with SMTP id j17mr38884530ybl.228.1625763456939; Thu, 08 Jul 2021 09:57:36 -0700 (PDT) MIME-Version: 1.0 References: <20210707172948.1025-1-adrian.hunter@intel.com> <20210707172948.1025-3-adrian.hunter@intel.com> <66130101-b0c5-a9a3-318a-468c6f3b380f@intel.com> In-Reply-To: From: Saravana Kannan Date: Thu, 8 Jul 2021 09:57:01 -0700 Message-ID: Subject: Re: [PATCH RFC 2/2] scsi: ufshcd: Fix device links when BOOT WLUN fails to probe To: "Rafael J. Wysocki" Cc: Adrian Hunter , Greg Kroah-Hartman , "Martin K . Petersen" , "James E . J . Bottomley" , "open list:TARGET SUBSYSTEM" , Avri Altman , Bean Huo , Can Guo , Asutosh Das , Bart Van Assche , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 8, 2021 at 9:49 AM Rafael J. Wysocki wrote: > > On Thu, Jul 8, 2021 at 6:46 PM Saravana Kannan wrote: > > > > On Thu, Jul 8, 2021 at 7:17 AM Adrian Hunter wrote: > > > > > > On 8/07/21 3:31 pm, Rafael J. Wysocki wrote: > > > > On Wed, Jul 7, 2021 at 7:49 PM Adrian Hunter wrote: > > > >> > > > >> On 7/07/21 8:39 pm, Greg Kroah-Hartman wrote: > > > >>> On Wed, Jul 07, 2021 at 08:29:48PM +0300, Adrian Hunter wrote: > > > >>>> If a LUN fails to probe (e.g. absent BOOT WLUN), the device will not have > > > >>>> been registered but can still have a device link holding a reference to the > > > >>>> device. The unwanted device link will prevent runtime suspend indefinitely, > > > >>>> and cause some warnings if the supplier is ever deleted (e.g. by unbinding > > > >>>> the UFS host controller). Fix by explicitly deleting the device link when > > > >>>> SCSI destroys the SCSI device. > > > >>>> > > > >>>> Signed-off-by: Adrian Hunter > > > >>>> --- > > > >>>> drivers/scsi/ufs/ufshcd.c | 7 +++++++ > > > >>>> 1 file changed, 7 insertions(+) > > > >>>> > > > >>>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > > > >>>> index 708b3b62fc4d..483aa74fe2c8 100644 > > > >>>> --- a/drivers/scsi/ufs/ufshcd.c > > > >>>> +++ b/drivers/scsi/ufs/ufshcd.c > > > >>>> @@ -5029,6 +5029,13 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev) > > > >>>> spin_lock_irqsave(hba->host->host_lock, flags); > > > >>>> hba->sdev_ufs_device = NULL; > > > >>>> spin_unlock_irqrestore(hba->host->host_lock, flags); > > > >>>> + } else { > > > >>>> + /* > > > >>>> + * If a LUN fails to probe (e.g. absent BOOT WLUN), the device > > > >>>> + * will not have been registered but can still have a device > > > >>>> + * link holding a reference to the device. > > > >>>> + */ > > > >>>> + device_links_scrap(&sdev->sdev_gendev); > > > >>> > > > >>> What created that link? And why did it do that before probe happened > > > >>> successfully? > > > >> > > > >> The same driver created the link. > > > >> > > > >> The documentation seems to say it is allowed to, if it is the consumer. > > > >> From Documentation/driver-api/device_link.rst > > > >> > > > >> Usage > > > >> ===== > > > >> > > > >> The earliest point in time when device links can be added is after > > > >> :c:func:`device_add()` has been called for the supplier and > > > >> :c:func:`device_initialize()` has been called for the consumer. > > > > > > > > Yes, this is allowed, but if you've added device links to a device > > > > object that is not going to be registered after all, you are > > > > responsible for doing the cleanup. > > > > > > > > Why can't you call device_link_del() directly on those links? > > > > > > > > Or device_link_remove() if you don't want to deal with link pointers? > > > > > > > > > > Those only work for DL_FLAG_STATELESS device links, but we use only > > > DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE flags. > > > > Is there a reason you can't use DL_FLAG_STATELESS? It doesn't preclude > > you from using RPM_ACTIVE as far as I can tell. > > Perhaps he wants the links to be managed if they are used after all. > > Anyway, this is a valid use case that is not covered right now. Maybe. But the suggested patch is certainly risky. There is no requirement the consumer is registered before the links are added though. So, randomly deleting a managed link when device_link_put_kref() is called on a stateless refcount (they are still the same link still) isn't right. The entity that created the managed device link might still want it there. Also, if two entities create a managed link and one of them calls device_link_put_kref() before the device is registered, we have a UAF problem because managed links aren't refcounted (more than once). -Saravana