Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp182975rdf; Thu, 2 Nov 2023 18:28:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9ivcFEBPu84cu5jwDDjuXO3CQjtNhnmme8c+OxDs48+XbDrorHEa9g+XxKLaoQvTz8P43 X-Received: by 2002:a05:6a20:8421:b0:180:d17a:7677 with SMTP id c33-20020a056a20842100b00180d17a7677mr13633523pzd.36.1698974898467; Thu, 02 Nov 2023 18:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698974898; cv=none; d=google.com; s=arc-20160816; b=wXrDV8iShUAdHAoBzdvtLIKOlhflnhITpaAY4ojL79hVPJpUimG8ydLludg9J+6f5D BXk+hfvvFuEKN2ZE9CfuQETdF+nqb/WiWJ9Z1bfdwKhOirX0zQU5Lm/+MARLgNGILTsn sBLry7mme9BajEzy0XG5g7PSXvxoI+WLBg61uPiT+6Axbvez07vC3HVTMOly5+QgAJ76 Q5Ip3uER3HloIieDx75/3PqxyuEQ67r5cTFKXVXYuZG82UpdfJTttzDeRNhz8OWX2ftb uObOqx++2Q4y0w3FqZ+SPc8bz7HYB/mfmVBHvUDShqwizTg7ATeKFwKh3vp6l+ABik65 dq+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vANmfjhWuefo3Bjt/ORHTu0IFPxRZHx59I967LHWjE8=; fh=z4VhEaLcah0qV6vSWV8QxKHluZrbSpuwkHHj2031370=; b=g6KpP7/PTBeTaHQo9BLCvh14Rd1dhpS52GVjB3uEC6/VBra+xBVLxOWNOHPBziS0eA qpTqMdeif5PWKNRMGikfSe6e8CnxJ6H7wtzG45ZBesdYK9ucHJD4cg2uUEvm5e+tsbjU I6tApWqqu7r4zKJw86YADdFcYxjZ3guxqMBmjrpmBM3rGkIuL9gHwr/r0JIQuS1flFHs E6ZIvKyDMQOj26Ug2et9ZiZ+1yUrefEUv710Hj5gjMs2xFBL8SYgXz7iEqLz9BBHoZAY Y4i7GsfL+J66Gmr0aw/TmHSVHJpG/ksQsqpg4hST1YDo3OJTfeq7ngAiY3AIkRify5Dh 6kCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bF0W6U8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id co8-20020a17090afe8800b00274e16f797csi619075pjb.20.2023.11.02.18.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 18:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bF0W6U8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9981A8075EF9; Thu, 2 Nov 2023 18:28:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377761AbjKCB1i (ORCPT + 99 others); Thu, 2 Nov 2023 21:27:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377759AbjKCB1g (ORCPT ); Thu, 2 Nov 2023 21:27:36 -0400 Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F661A5; Thu, 2 Nov 2023 18:27:30 -0700 (PDT) Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-49618e09f16so661260e0c.2; Thu, 02 Nov 2023 18:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698974849; x=1699579649; 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=vANmfjhWuefo3Bjt/ORHTu0IFPxRZHx59I967LHWjE8=; b=bF0W6U8y+YNyyIbpr8h6Q4lcJcbyR4nQ9twhtPDse2tfVS2cY7YHhAcTJ5h8qu8Q7o NH7WwVsHMB7dzim9RCBFf1t/m/QbVykX+wwhcGtMHLGRhCl4oeWh/VKLg8t7WxblKV0p CQLLy06jytdHSmFcrMkVc4eQZ9ieKqQs5OCMAN6HoUhwlNH2lftY8HWGOEPlfLoMFe8O jL1Ru2EeYHyV21UCxEfsdh/h6OyOb7nMegKOfO2C1t/PnRDNLcpDrtooES1uqyzQAKWl QILKNj2tz+CanrLiWxD7ePDnFmne2LtBAybandf3tIqfwP+Kkj+JIoy7PgvoXZLqqVyF tJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698974849; x=1699579649; 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=vANmfjhWuefo3Bjt/ORHTu0IFPxRZHx59I967LHWjE8=; b=P3jb3qcRbpWms9aciDP+nVe2n/PjCtMvkeyfXBbRNu8piTxwhETrbBEkkyP/oWQbUG nC0SPYaLCRtBaIoaarvSB9oZpJSMetUqeNqOL3unrRLvCNH71Z4f+C1Mkzck0AO1bBKD fvcGLi2PTGm4KrSnw39wgAk0O1WVMa7ICm18XZp+1/QpZF5lSe9XWcyYkflG1+gl87ha xGDd9Hs+oA6LUO7AYOKsjl6zMR9RQZPpWbDh7UYxE+I+s8JS0Oy2VRxCcYoW1kxQ2WEU XTd2NbPViOUg4BmPlQZbG/NtHqCGiPByAX+vB+PEed1ZX/TRB8Ty+fiRpVmagib5YJZP u1xg== X-Gm-Message-State: AOJu0Yy11NE4Hvhq0RLyTjA4iykCoJfsBtd3UBY4OFxjjXKFPhpP+S7u j22+E/u7sqVrDbd93UwjuMs3qWE0rQ+tKJfC7t1c53urfmFGKg== X-Received: by 2002:a1f:ab0b:0:b0:4a4:680:bfad with SMTP id u11-20020a1fab0b000000b004a40680bfadmr18856423vke.7.1698974849633; Thu, 02 Nov 2023 18:27:29 -0700 (PDT) MIME-Version: 1.0 References: <20231013034158.2745127-1-alistair.francis@wdc.com> <20231013034158.2745127-2-alistair.francis@wdc.com> <20231017083421.GA23168@wunner.de> In-Reply-To: <20231017083421.GA23168@wunner.de> From: Alistair Francis Date: Fri, 3 Nov 2023 11:27:02 +1000 Message-ID: Subject: Re: [PATCH v9 2/3] PCI/DOE: Expose the DOE features via sysfs To: Lukas Wunner Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 18:28:13 -0700 (PDT) On Tue, Oct 17, 2023 at 6:34=E2=80=AFPM Lukas Wunner wrot= e: > > On Fri, Oct 13, 2023 at 01:41:57PM +1000, Alistair Francis wrote: > > +#ifdef CONFIG_SYSFS > > +static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj, > > + struct attribute *a, int n) > > +{ > > + struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); > > + struct pci_doe_mb *doe_mb; > > + unsigned long index, j; > > + void *entry; > > + > > + xa_for_each(&pdev->doe_mbs, index, doe_mb) { > > + xa_for_each(&doe_mb->feats, j, entry) > > + return a->mode; > > + } > > + > > + return 0; > > +} > > Out of curiosity: Does this method prevent creation of a > "doe_features" directory for devices which don't have any > DOE mailboxes? It does once this patch (or something similar) is applied: https://lkml.org/lkml/2022/8/24/607 GKH and I are working on getting a patch like that working and merged Alistair > > (If it does, a code comment explaining that might be helpful.) > > > > +const struct attribute_group pci_dev_doe_feature_group =3D { > > + .name =3D "doe_features", > > + .attrs =3D pci_dev_doe_feature_attrs, > > + .is_visible =3D pci_doe_sysfs_attr_is_visible, > > +}; > > Nit: Wondering why the "=3D" is aligned for .name and .attrs > but not for .is_visible? > > > > +static void pci_doe_sysfs_feature_remove(struct pci_dev *pdev, > > + struct pci_doe_mb *doe_mb) > > +{ > > + struct device *dev =3D &pdev->dev; > > + struct device_attribute *attrs =3D doe_mb->sysfs_attrs; > > + unsigned long i; > > + void *entry; > > Nit: Inverse Christmas tree? > > > > +static int pci_doe_sysfs_feature_populate(struct pci_dev *pdev, > > + struct pci_doe_mb *doe_mb) > > +{ > > + struct device *dev =3D &pdev->dev; > > + struct device_attribute *attrs; > > + unsigned long num_features =3D 0; > > + unsigned long vid, type; > > + unsigned long i; > > + void *entry; > > + int ret; > > + > > + xa_for_each(&doe_mb->feats, i, entry) > > + num_features++; > > + > > + attrs =3D kcalloc(num_features, sizeof(*attrs), GFP_KERNEL); > > + if (!attrs) > > + return -ENOMEM; > > + > > + doe_mb->sysfs_attrs =3D attrs; > > + xa_for_each(&doe_mb->feats, i, entry) { > > + sysfs_attr_init(&attrs[i].attr); > > + vid =3D xa_to_value(entry) >> 8; > > + type =3D xa_to_value(entry) & 0xFF; > > + attrs[i].attr.name =3D kasprintf(GFP_KERNEL, > > + "0x%04lX:%02lX", vid, type= ); > > Nit: Capital X conversion specifier will result in upper case hex > characters in filename and contents, whereas existing sysfs attributes > such as "vendor", "device" contain lower case hex characters. > > Might want to consider lower case x for consistency. > > > > +void pci_doe_sysfs_teardown(struct pci_dev *pdev) > > +{ > > + struct pci_doe_mb *doe_mb; > > + unsigned long index; > > + > > + xa_for_each(&pdev->doe_mbs, index, doe_mb) { > > + pci_doe_sysfs_feature_remove(pdev, doe_mb); > > + } > > Nit: Curly braces not necessary. > > > > @@ -1153,6 +1154,10 @@ static void pci_remove_resource_files(struct pci= _dev *pdev) > > { > > int i; > > > > + if (IS_ENABLED(CONFIG_PCI_DOE)) { > > + pci_doe_sysfs_teardown(pdev); > > + } > > Nit: Curly braces not necessary. > > > > @@ -1230,6 +1235,12 @@ static int pci_create_resource_files(struct pci_= dev *pdev) > > int i; > > int retval; > > > > + if (IS_ENABLED(CONFIG_PCI_DOE)) { > > + retval =3D pci_doe_sysfs_init(pdev); > > + if (retval) > > + return retval; > > + } > > + > > /* Expose the PCI resources from this device as files */ > > for (i =3D 0; i < PCI_STD_NUM_BARS; i++) { > > I think this needs to be added to pci_create_sysfs_dev_files() instead. > > pci_create_resource_files() only deals with creation of resource files, > as the name implies, which is unrelated to DOE features. > > Worse, pci_create_resource_files() is also called from > pci_dev_resource_resize_attr(), i.e. every time user space > writes to the "resource##n##_resize" attributes. > > Similarly, the call to pci_doe_sysfs_teardown() belongs in > pci_remove_sysfs_dev_files(). > > Thanks, > > Lukas