Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp732699pxb; Thu, 26 Aug 2021 13:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0D/rzRG84AcId1DqIW+U+df0ilj2B4kpBncOrZ01g8gBI5GTAwjXEaajKuAZSNW+N4M60 X-Received: by 2002:a17:906:681a:: with SMTP id k26mr3253169ejr.506.1630009020796; Thu, 26 Aug 2021 13:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630009020; cv=none; d=google.com; s=arc-20160816; b=lWqohp6+pvgYkiU0gWtXEycE6qbRZbP/lEM2NwC0ftlsgyN/tO8HM+7tmiaPP08tfr q/d/aY3o/JOj3JxigbpbQI5M7n/0IehKrhX+5ifx4Kxn1Fzj+dbC+PZU170Y+jDQ5BJ6 GC89f79G2RfFxqSqOkC5P3u4k9kWB2BqEa7x4mFC4kFur1MBCobjl+6jeDxgPgwgFSL/ 4bmWFts5AzUhOjn2FkGA745eRUmvSX2YCDmR3wTGFAa2s2mwc/PlH1DUw8AJ2/9giyH9 V3zD+owZz2Em6vSM5/pvUHYoIuvG9UOPJ6STrd1sxXThgv5O3V9AA8TNu+sI5rG6vzFD H4Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Hr1dE90H5YdZDUlgzkS8UsQx9P+U2IwJloakxSeTCKw=; b=UhXedjZvkUyOKM53SK1apsX3yBWfLLEEM8VFVvEJCEszwPA9G65jnYEjjU9YqCMGOt Jrn2rTb4lvRyBK8ITtGYNGh6IHVt599zZ0ATSR8YPbO2FgXeGoVsni3mS2TnCS24fXxK UNPQalDg3W5cI9j5ct5a2cBEddyFH+y0/FeAUFpfueO4hExWj2C3JG7O+zK4TcKEj5dS nESFPPiT3ExR33Ddllh9xvH7BCRSFgw5SrFUp8kxD76yvSdDFZxDEE2MTK2Owzfi4M2l XlFoU4wWguson0ccm+59SoyZIzSWRN1zKr9uRhEcb7k6VQRqG61yVW9/5xUufsltJDr9 zjaw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si3712181ejk.645.2021.08.26.13.16.35; Thu, 26 Aug 2021 13:17:00 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232398AbhHZUPz (ORCPT + 99 others); Thu, 26 Aug 2021 16:15:55 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:46851 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbhHZUPy (ORCPT ); Thu, 26 Aug 2021 16:15:54 -0400 Received: by mail-wr1-f46.google.com with SMTP id f5so6834912wrm.13; Thu, 26 Aug 2021 13:15:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Hr1dE90H5YdZDUlgzkS8UsQx9P+U2IwJloakxSeTCKw=; b=LSNWrXGI6b24ZVpRGryz+J9EguYQ8KycqBSXRbjJa6DYyf27BGwitYnyPoMltihnuw /wKB0PptQ0MWmjLc16ChGEEwB5+EV/Vv51dyuQSk3D46OHWrZt9ihd6ZaKqGp2e8UvIW yGoiblAAmGKioMeVTrXgIrjo7e/rv1bh94P3zBB9ZzmyzQuX45XsJH5esBLfjikaNaAI vsF6NCZO+c8gAaPrmE9d83ydvGbl9CV2uTIBaZKP0hkywge4Gtuz55xXRqHHQ/xwl1J8 +Bf5Ircv45DfCP4aq0cd7/dzSurfuuWuUB73ThSRYNNVD4QBkJJgvGI0WUyL3SZDk1Z1 v9+Q== X-Gm-Message-State: AOAM532KzcH38p1f1YtHFoIwc0CkQIINzHDpv08z/jh2kzX3gaAxLbWQ mDkyIEWxWaadOT+5RfBTdW0= X-Received: by 2002:a5d:51ca:: with SMTP id n10mr6031139wrv.119.1630008905618; Thu, 26 Aug 2021 13:15:05 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id k16sm4207187wrx.87.2021.08.26.13.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 13:15:05 -0700 (PDT) Date: Thu, 26 Aug 2021 20:15:03 +0000 From: Wei Liu To: Long Li Cc: Wei Liu , Michael Kelley , "longli@linuxonhyperv.com" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Lorenzo Pieralisi , Rob Herring , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Bjorn Helgaas , Dan Carpenter Subject: Re: [PATCH] PCI: hv: Fix a bug on removing child devices on the bus Message-ID: <20210826201503.ycckbcpu3f6flbb6@liuwe-devbox-debian-v2> References: <1629789620-11049-1-git-send-email-longli@linuxonhyperv.com> <20210824110208.xd57oqm5rii4rr4n@liuwe-devbox-debian-v2> <20210826194113.yihk7ete4n4ej4gz@liuwe-devbox-debian-v2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021 at 08:09:19PM +0000, Long Li wrote: > > Subject: Re: [PATCH] PCI: hv: Fix a bug on removing child devices on the bus > > > > On Thu, Aug 26, 2021 at 04:50:28PM +0000, Michael Kelley wrote: > > > From: Long Li Sent: Wednesday, August 25, 2021 > > > 1:25 PM > > > > > > > > > > > > > I thought list_for_each_entry_safe() is for use when list > > > > > manipulation is *not* protected by a lock and you want to safely > > > > > walk the list even if an entry gets removed. If the list is > > > > > protected by a lock or not subject to contention (as is the case > > > > > here), then > > > > > list_for_each_entry() is the simpler implementation. The original > > > > > implementation didn't need to use the _safe version because of the spin > > lock. > > > > > > > > > > Or do I have it backwards? > > > > > > > > > > Michael > > > > > > > > I think we need list_for_each_entry_safe() because we delete the list > > elements while going through them: > > > > > > > > Here is the comment on list_for_each_entry_safe(): > > > > /** > > > > * Loop through the list, keeping a backup pointer to the element. > > > > This > > > > * macro allows for the deletion of a list element while looping > > > > through the > > > > * list. > > > > * > > > > * See list_for_each_entry for more details. > > > > */ > > > > > > > > > > Got it. Thanks (and to Rob Herring). I read that comment but > > > with the wrong assumptions and didn't understand it correctly. > > > > > > Interestingly, pci-hyperv.c has another case of looping through this > > > list and removing items where the _safe version is not used. > > > See pci_devices_present_work() where the missing children are moved to > > > a list on the stack. > > > > That can be converted too, I think. > > > > The original code is not wrong per-se. It is just not as concise as using > > list_for_each_entry_safe. > > > > Wei. > > I assume we are talking about the following code in pci_devices_present_work(): > > list_for_each_entry(hpdev, &hbus->children, list_entry) { > if (hpdev->reported_missing) { > found = true; > put_pcichild(hpdev); > list_move_tail(&hpdev->list_entry, &removed); > break; > } > } > > This code is correct as there is a "break" after a list entry is > removed from the list. So there is no need to use the _safe version. > This code can be converted to use the _safe version. After this block there is another block like while (!list_empty(removed)) { ... list_del(...) } I assumed Michael was referring to that block. :-) Wei.