Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1734475ioo; Mon, 23 May 2022 01:54:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLpXN55BYISFRNwcx319Zay0zJXhC424V2dEoVg8HpfiQHwcWllSHbFxpV4ugh5mUPBoes X-Received: by 2002:a63:181:0:b0:3f6:656a:e616 with SMTP id 123-20020a630181000000b003f6656ae616mr15288001pgb.448.1653296054886; Mon, 23 May 2022 01:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653296054; cv=none; d=google.com; s=arc-20160816; b=yxjqnJyM+ei5F445PteCNYNrPbiKVVk2gN6SH/cToL+zfVyPyxBDD5WaP6VauJc3Qk V1NRwCp+yHtrnapfcZRQJWLm4H1XEkLSLzCTbWzfO45DoqbZv18UvDboLYGywtW8XMpm e3Rh4IWyb6cNbTUKeCdhwHrFkBSv6JVA2om49mBsHDo1WBtb5KzChcNmHf8fTQhWB2gu 6aeIg7J/xncEIR7c8voTrDTUvs7Z2VHKWukO4q2o3fjn4UGxqGYUDpdWvptBtaiLTBom HIesg88/fdLi8ibRPyCwWKqbl8VzFje+h3X5CxL4XSm+nT8GhyPnD2z8FnNgVd93u2Ai uPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=pxBN4qd2Ox8ZyLMxExL1i3qx0MaG8nHVRbGAtGIlZ5Q=; b=CP6FYWhskw1sCg69Ft0DUpawphcwHIJ4rQ5wql/NKCOtJ3MYz4MGc2+SpaGRjjO8YK 7zcEFlnFgc+MXMMMtwtUIqdK3qGXnvVlw9pZSSpKB9wk1AsVf4B89/Lx9ejBQ7+ks32Q EjMgOaL2WnJ5J9iDXiJN+xHuvlZEYsin5I1RvUP/CTmkMrfQs1dGRa3u+T/yn/pjUkQx Tx8APz69ldQISLz6FXrPGoxbfVV4Wo1PblpBc3Drcvx3HVXwnW+/IfiRthYB7erfTZSC dZI/2OpeIh4SppekW1rdgeXQadroewos/Cbwx9tPyOFyZrQjoIaX93YF+lWad0WbK9ah Edtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=r9jcFozH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mi18-20020a17090b4b5200b001bed39e61cesi14296175pjb.23.2022.05.23.01.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=r9jcFozH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E5C7186F5; Mon, 23 May 2022 01:41:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231983AbiEWIl2 (ORCPT + 99 others); Mon, 23 May 2022 04:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232076AbiEWIlI (ORCPT ); Mon, 23 May 2022 04:41:08 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71A786413; Mon, 23 May 2022 01:41:05 -0700 (PDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24N8LPC5001298; Mon, 23 May 2022 08:40:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=pxBN4qd2Ox8ZyLMxExL1i3qx0MaG8nHVRbGAtGIlZ5Q=; b=r9jcFozH9ZYNP6y1NQuLpp1Ol778rYWh9S2ZFyYUC68UqVitrfS+bGGDmfck/lCZOQdb m14/UXjLwN5h9X61xQLmrGRkEKmWLW7+rdwflF/i5OMlHkbC/9J/gDiWDBCk0bEJyvPg MeTdPg8/UNa2TIuAAYn7c440WC3ACoP1TDP/aYjceBdT5KgLzhWGQ/ebEIhLNoMsJbaz CrWaluMXEUyA2YJ0ihX7Vgkh/I3xt88JW1JCGwyr9It98/HpA7onqSyrJOqZsF7u9TkI EtDRNtD/kb1PmBMdMG1YEAEIlf3jLAqyXBI6sY1Oq/4URYhAYKINU+xwAtrK9s8xOn5S +g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g7a3ryftf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 08:40:59 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24N7vawt028878; Mon, 23 May 2022 08:40:58 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g7a3ryft1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 08:40:58 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24N7fNpZ001898; Mon, 23 May 2022 08:40:57 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3g6qq92fbw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 08:40:56 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24N8er8B51773894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 May 2022 08:40:53 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B51C85204E; Mon, 23 May 2022 08:40:53 +0000 (GMT) Received: from oc-nschnelle.boeblingen.de.ibm.com (unknown [9.155.199.46]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6B4F55204F; Mon, 23 May 2022 08:40:53 +0000 (GMT) Message-ID: <26e53653b06e6045ef94f2c5f9c10e333821f186.camel@linux.ibm.com> Subject: Re: [PATCH RESEND v5 1/4] PCI: Clean up pci_scan_slot() From: Niklas Schnelle To: Bjorn Helgaas Cc: Bjorn Helgaas , Jan Kiszka , Matthew Rosato , Pierre Morel , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-s390@vger.kernel.org, linux-pci@vger.kernel.org Date: Mon, 23 May 2022 10:40:53 +0200 In-Reply-To: <20220513140723.GA947754@bhelgaas> References: <20220513140723.GA947754@bhelgaas> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: oiYVEcXeUU0nn-6MTTh1kgwana7kjaKx X-Proofpoint-ORIG-GUID: fQ9j2cjFyKKG-q4izm0OY682iSR6rOu5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-23_03,2022-05-20_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 spamscore=0 impostorscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=946 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205230045 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-05-13 at 09:07 -0500, Bjorn Helgaas wrote: > On Thu, May 12, 2022 at 04:56:42PM +0200, Niklas Schnelle wrote: > > On Thu, 2022-05-05 at 10:38 +0200, Niklas Schnelle wrote: > > > While determining the next PCI function is factored out of > > > pci_scan_slot() into next_fn() the former still handles the first > > > function as a special case. This duplicates the code from the scan loop. > > > > > > Furthermore the non ARI branch of next_fn() is generally hard to > > > understand and especially the check for multifunction devices is hidden > > > in the handling of NULL devices for non-contiguous multifunction. It > > > also signals that no further functions need to be scanned by returning > > > 0 via wraparound and this is a valid function number. > > > > > > Improve upon this by transforming the conditions in next_fn() to be > > > easier to understand. > > > > > > By changing next_fn() to return -ENODEV instead of 0 when there is no > > > next function we can then handle the initial function inside the loop > > > and deduplicate the shared handling. This also makes it more explicit > > > that only function 0 must exist. > > > > > > No functional change is intended. > > > > > > Cc: Jan Kiszka > > > Signed-off-by: Niklas Schnelle > > > --- > > > > Friendly ping :-) > > Thanks and sorry for the delay. I'm off today for my daughter's > wedding reception but will get back to it next week. Just to expose > some of my thought process (and not to request more work from you!) > I've been wondering whether b1bd58e448f2 ("PCI: Consolidate > "next-function" functions") is really causing us more trouble than > it's worth. In some ways that makes the single next-function harder > to read. But I guess the hypervisor special case is not exactly a > "next-function" thing -- it's a "keep scanning even if there's no fn > 0" thing. > > Bjorn I've thought again about your comment. Personally what I like about b1bd58e448f2 ("PCI: Consolidate "next-function" functions") is that it got rid of the next_fn function pointer complication. I agree though that on the other hand it removed a nice separation between the ARI and traditional cases. So I'm thinking maybe we should bring that part back. I think my patch as is makes it easier to see the equivalence to the existing code but then we could add a patch on top and turn it into the below, it's a bit more verbose but very easy to follow. static int next_ari_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) { … } static int next_trad_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) { if (fn >= 7) return -ENODEV; /* only multifunction devices may have more functions */ if (dev && !dev->multifunction) return -ENODEV; return fn + 1; } static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) { if (pci_ari_enabled(bus)) { return next_ari_fn(bus, dev, fn); } return next_trad_fn(bus, dev, fn); }