Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8598849rwp; Wed, 19 Jul 2023 12:14:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlG69N+BOQNdhcuZKiIqdhnIZwpTLqYC4rq2hc6B+xJ/lhGC/QR0gWpxpOjr2RiuwhuOSdNf X-Received: by 2002:a17:90a:ca10:b0:262:fe4b:b45 with SMTP id x16-20020a17090aca1000b00262fe4b0b45mr4210727pjt.19.1689794040224; Wed, 19 Jul 2023 12:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689794040; cv=none; d=google.com; s=arc-20160816; b=u54DvnfcU8g6wepiKKI3W3RsRent+35XHAkDuQLRyhnl5iA/skENkMNgMkL3NNp1q7 aTg8JNoZ4o0dX1Xs0QX80bpX+RKo/DH+b2jQflzb3Xyr/4FVHG2hERqsCbxmIohswVj+ fTRAJ0zg870KvfIMXOe8Ffin0W488tr/Cg8REq6WVxhGvKJakPUofgydBBlMqD3yM/wg JNc3YTduouhG+hflnxO0LSU6vnsfRYFnR38u4I5yoJ6MpAqAgpAZLqd/TtwYb8DyET3V B75LMv2hif1S01vxAWoQC2Z3enA2YZimUG/heq8YdO0c8wXBFrYGsSL+pfWJYJaIdH7l k6gg== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=nFNm/B30lE7noc/cRMiphk9MIR4+pbgOvbkXrldOglc=; fh=KXPWoqM6GWVpzh1ZGFuKWKj00O+1xBx7e6tUiAZk6WI=; b=OF1HS9Q05Elcw/YJ4xVzVYOoktutrmpBd+b7Gvh0XA585iQH8qKIHkJmXY/15guiFg tw3fS6SdNWhYaNd68g1liRXx84RmsyABdiXXP4dpIb6qyvn2TLFt1l6EkTNPpqnY+Nzh UPcd9DLIurHYV3OQbu3z2J14tJINxXn9CaecVyZ9lhi3GtU4CYm9IhVYRLoIh5jmpv4Z +Vdt5wElyeHfbi2UzxnA988WXnkxv+TU6KzdRQBjFdlBBN4HQ1ZrvpfRGhPdhX1OesTX NEAhiD3UoWCLAZWRkntfmc3XFlcxzSSzZvgp6l6hGaPCB/9dTwKt2UjwBLYbUexEv2vb XVrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z+u7r3i/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a17090aa88e00b00262e650abadsi1826006pjq.117.2023.07.19.12.13.47; Wed, 19 Jul 2023 12:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z+u7r3i/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230226AbjGSS0X (ORCPT + 99 others); Wed, 19 Jul 2023 14:26:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjGSS0V (ORCPT ); Wed, 19 Jul 2023 14:26:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7AAF1FC8; Wed, 19 Jul 2023 11:26:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 54AD5617CB; Wed, 19 Jul 2023 18:26:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86513C433C8; Wed, 19 Jul 2023 18:26:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689791179; bh=6nmxXiiQH/ZgR/96VnW9bkCyBKJ7S68RVdSGVdB9E38=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Z+u7r3i/0+xnn6FAc7NUsW8Tlb84OCb6IRrTAwcTC6JC+fOwa17/ERlpVm7bocSTv /x2ZvRb8KTK7MXBjgS3M0xtQV1V8R0Uwq1BTghd9MZH/kLdx56uCyDJzOoTMm1rj0L 2+Co/0CcxzsUxq8TjzvfbgSIHMnMKEIaHgSvL2G3qi+A+qX+314ECd0CU3iROLETBF taaCSiqPZPVAlHbivih/xuF8ZB8DegYq2cw+Dy0e4GHQ4NkNwmGTrzfQ30SNH8xMD0 ihLzwndiC1oPP+LujNtk+LElPQoisUEZBdffDOh2kOnF6Jyi1iFcw4ous5GoEZYrCA IVTVt+FhJVdpg== Date: Wed, 19 Jul 2023 13:26:17 -0500 From: Bjorn Helgaas To: Sui Jingfeng Cc: Bjorn Helgaas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sui@freedesktop.org, Jingfeng@loongson.cn, Sui Jingfeng , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Mario Limonciello Subject: Re: [PATCH 2/6] PCI/VGA: Deal with PCI VGA compatible devices only Message-ID: <20230719182617.GA509912@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230711134354.755966-3-sui.jingfeng@linux.dev> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Tue, Jul 11, 2023 at 09:43:50PM +0800, Sui Jingfeng wrote: > From: Sui Jingfeng > > Currently, vgaarb only cares about PCI VGA-compatible class devices. > > While vga_arbiter_del_pci_device() gets called unbalanced when some PCI > device is about to be removed. This happens even during the boot process. The previous code calls vga_arbiter_add_pci_device() for every device (every device present at boot and also every hot-added device). It only allocates a vga_device if pdev->class is 0x0300XX. It calls vga_arbiter_del_pci_device() for every device removal. It does nothing unless it finds a vga_device. This seems symmetric and reasonable to me. Did you observe a problem with it? > Another reason is that the vga_arb_device_init() function is not efficient. > Since we only care about VGA-compatible devices (pdev->class == 0x030000), > We could filter the unqualified devices out in the vga_arb_device_init() > function. While the current implementation is to search all PCI devices > in a system, this is not necessary. Optimization is fine, but the most important thing here is to be clear about what functional change this patch makes. As I mentioned at [1], if this patch affects the class codes accepted, please make that clear here. > Reviewed-by: Mario Limonciello > Signed-off-by: Sui Jingfeng I do not see Mario's Reviewed-by on the list. I do see Mario's Reviewed-by [2] for a previous version, but that version added this in pci_notify(): + if (pdev->class != PCI_CLASS_DISPLAY_VGA << 8) + return 0; while this version adds: + if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) + return 0; It's OK to carry a review to future versions if there are insignificant changes, but this is a functional change that seems significant to me. The first matches only 0x030000, while the second discards the low eight bits so it matches 0x0300XX. [1] https://lore.kernel.org/r/20230718231400.GA496927@bhelgaas [2] https://lore.kernel.org/all/5b6fdf65-b354-94a9-f883-be820157efad@amd.com/ > --- > drivers/pci/vgaarb.c | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) > > diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c > index c1bc6c983932..021116ed61cb 100644 > --- a/drivers/pci/vgaarb.c > +++ b/drivers/pci/vgaarb.c > @@ -754,10 +754,6 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev) > struct pci_dev *bridge; > u16 cmd; > > - /* Only deal with VGA class devices */ > - if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) > - return false; > - > /* Allocate structure */ > vgadev = kzalloc(sizeof(struct vga_device), GFP_KERNEL); > if (vgadev == NULL) { > @@ -1502,6 +1498,10 @@ static int pci_notify(struct notifier_block *nb, unsigned long action, > > vgaarb_dbg(dev, "%s\n", __func__); > > + /* Deal with VGA compatible devices only */ > + if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) > + return 0; > + > /* For now we're only intereted in devices added and removed. I didn't > * test this thing here, so someone needs to double check for the > * cases of hotplugable vga cards. */ > @@ -1534,8 +1534,8 @@ static struct miscdevice vga_arb_device = { > > static int __init vga_arb_device_init(void) > { > + struct pci_dev *pdev = NULL; > int rc; > - struct pci_dev *pdev; > > rc = misc_register(&vga_arb_device); > if (rc < 0) > @@ -1543,13 +1543,14 @@ static int __init vga_arb_device_init(void) > > bus_register_notifier(&pci_bus_type, &pci_notifier); > > - /* We add all PCI devices satisfying VGA class in the arbiter by > - * default */ > - pdev = NULL; > - while ((pdev = > - pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, > - PCI_ANY_ID, pdev)) != NULL) > - vga_arbiter_add_pci_device(pdev); > + /* > + * We add all PCI VGA compatible devices in the arbiter by default > + */ > + do { > + pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev); > + if (pdev) > + vga_arbiter_add_pci_device(pdev); > + } while (pdev); > > pr_info("loaded\n"); > return rc; > -- > 2.25.1 >