From patchwork Wed Oct 26 06:11:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp88158wru; Tue, 25 Oct 2022 23:32:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6BYmnjp+TWQEpO8vKL3kKuvZxDFj9xedMeyXnOU0H4sW13mYAaidhtDHSc5haKQqPHkwYx X-Received: by 2002:a63:f755:0:b0:44b:e438:ef2f with SMTP id f21-20020a63f755000000b0044be438ef2fmr37176252pgk.314.1666765944625; Tue, 25 Oct 2022 23:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666765944; cv=none; d=google.com; s=arc-20160816; b=IbQLDXqif7mtdXcxDC9SnW2vQlFzhmQyWMPaxxAzLIzk39LeqeOu5Xm5Hs155pfd3y MD3bMAW2J2cRYS56ceWCbART39HFxXh6oI+q0J90htC2EI14jAIE5u6jHDq1SG6epRIF R0sA6ce5gmJIU3eV32t56KfZZernMV1cK2ArvWSLaPmsgsJpYpTFUw8E8wLbo1Vbv4DY AqJnpxLgllI2AJpQXA1h3zZispmeXke1Eh2D80QjBc0ziqNJ4m3Oc4vEopWKFrZObkVA rRNBVmxtu4ZcKA9LSnmqbbb1XBWA/lQRtLESLp8uGF+zlKh/y2CHn/rwiPYicBV41kEl SjVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=tgxjTxvjPTIXV3SFnxEgSVVrpV7F4tmAX7ZyULG30rc=; b=Qly6tpKc+lV2HNdM7gEKkUbUOpayQU+1r3hvAX2GXvkJHBrAdAYVNx9aATBWhPZLFb VMqT7TEhjrPE7ukp4eU/fD6Nq6UIdzDZfUAmBxvJjrR88lvQ5EMb3Odgu/AG5Ya9Pko3 twk4vjavesNkoPXKYfydAO1KS3fUBdm3pDvAE1U5r5yPaTOn7zn6VuDWdvsAQfacfqvZ HAbslETKLWWLlwKPbepGW43r/IgD5zbovJfc9d+LMS1nKTQ0wYlb9aMgCI8hloF8b0WQ Wvi+xPvNzZEzvs90cnvcf2etyIG4M83cO3Cw58/VEp9yMi+o+NHB6ctqfpmn9r7qMpfU 9FMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VGJCYgsr; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a631604000000b0046f0ae1bb7dsi5615291pgl.170.2022.10.25.23.32.09; Tue, 25 Oct 2022 23:32:24 -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=@redhat.com header.s=mimecast20190719 header.b=VGJCYgsr; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231937AbiJZGLj (ORCPT + 99 others); Wed, 26 Oct 2022 02:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233022AbiJZGLe (ORCPT ); Wed, 26 Oct 2022 02:11:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FDE6923F7 for ; Tue, 25 Oct 2022 23:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666764691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=tgxjTxvjPTIXV3SFnxEgSVVrpV7F4tmAX7ZyULG30rc=; b=VGJCYgsrBkesDEYLsUc2TUc9I6sQQ9uEfdOWwvo5FEtKx0tmGgYfP4ReUBI7DzExh/+23l C5F1QZB9MExiaxESy5cfcF/wHkxXm8RoqIV3fACa/eIOIYUhQy6sG/SSffsTGkl2RNgJE4 xYveTBJH3FydOYv7V0IwoR0WDX1aYL8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-279-K37i301cPmugDpp7MWN5pA-1; Wed, 26 Oct 2022 02:11:26 -0400 X-MC-Unique: K37i301cPmugDpp7MWN5pA-1 Received: by mail-wm1-f69.google.com with SMTP id o18-20020a05600c4fd200b003c6ceb1339bso1015203wmq.1 for ; Tue, 25 Oct 2022 23:11:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tgxjTxvjPTIXV3SFnxEgSVVrpV7F4tmAX7ZyULG30rc=; b=0oC5M8EK2gxBFsTwf43oxyJunO1O+3KyNWi3ntOjhwQ0TYdwTZYSghyo9e5oDGf5YK TLPA0StFMIHcQBbxjmPbCmH4L257kvjAcGjAFfFk5vADbPeDKU5eZePNIxfJMthhDnLg IziVhCkOvQHxeVDyJz//Z0/RMqUM7/3Zyaw8zXynVNaK4iwUgUXvNu014XzwWZMhmRQj ptttEbNE2aCv7u3ZY2rPMCBJFswfvyBDK5byNsYKUk6axHVT+nEtxdjIL+mFd8qKOzVP el7byyPBH7PNXT1OJp3rvQPy+ltkBslydXVbXb8eQxVyotMXyLfiBn9NRjBMpTJY72IX khPg== X-Gm-Message-State: ACrzQf0HVY0eTtsn+/auwZWck2CMRqyylaaG9XOmve3ot2zb18URWCOE 1NYpKjdGkLLi4eg/w47+J2ZbY8sB0lJUDG3G/CkH3eW/Y53Yb2BFJFOQ0sQgQRvKVBBNZR559s4 RoDE49z3htwp8QwZNylYRT4O7Q45Sf7wuJzsPp84+6RMP4u8bAb7fbk1sLUJ7R90Xb2NH6w== X-Received: by 2002:a7b:c4c2:0:b0:3b4:fdc4:6df9 with SMTP id g2-20020a7bc4c2000000b003b4fdc46df9mr1144876wmk.123.1666764685222; Tue, 25 Oct 2022 23:11:25 -0700 (PDT) X-Received: by 2002:a7b:c4c2:0:b0:3b4:fdc4:6df9 with SMTP id g2-20020a7bc4c2000000b003b4fdc46df9mr1144857wmk.123.1666764684970; Tue, 25 Oct 2022 23:11:24 -0700 (PDT) Received: from redhat.com ([2.55.3.42]) by smtp.gmail.com with ESMTPSA id p8-20020a05600c2e8800b003c64c186206sm915339wmn.16.2022.10.25.23.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 23:11:24 -0700 (PDT) Date: Wed, 26 Oct 2022 02:11:21 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Wei Gong , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: [PATCH v2] pci: fix device presence detection for VFs Message-ID: <20221026060912.173250-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747730767204325220?= X-GMAIL-MSGID: =?utf-8?q?1747730767204325220?= virtio uses the same driver for VFs and PFs. Accordingly, pci_device_is_present is used to detect device presence. This function isn't currently working properly for VFs since it attempts reading device and vendor ID. As VFs are present if and only if PF is present, just return the value for that device. Reported-by: Wei Gong Signed-off-by: Michael S. Tsirkin Tested-by: Wei Gong Tested-by: Wei Gong --- Wei Gong, thanks for your testing of the RFC! As I made a small change, would appreciate re-testing. Thanks! changes from RFC: use pci_physfn() wrapper to make the code build without PCI_IOV drivers/pci/pci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 2127aba3550b..899b3f52e84e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6445,8 +6445,13 @@ bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2) bool pci_device_is_present(struct pci_dev *pdev) { + struct pci_dev *physfn = pci_physfn(pdev); u32 v; + /* Not a PF? Switch to the PF. */ + if (physfn != pdev) + return pci_device_is_present(physfn); + if (pci_dev_is_disconnected(pdev)) return false; return pci_bus_read_dev_vendor_id(pdev->bus, pdev->devfn, &v, 0);