From patchwork Mon Mar 13 17:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 69000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1326059wrd; Mon, 13 Mar 2023 11:00:34 -0700 (PDT) X-Google-Smtp-Source: AK7set8UGw/DvalK0nHnPia7raXTzPJ5GyB8UVhdbHzAuFuaTrfDFAwDtM0L8jgZ19CHp06arsqV X-Received: by 2002:a17:903:8cb:b0:19e:8e73:e977 with SMTP id lk11-20020a17090308cb00b0019e8e73e977mr36183916plb.67.1678730433948; Mon, 13 Mar 2023 11:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678730433; cv=none; d=google.com; s=arc-20160816; b=XRGsDv5FY391+8d5RaBsXCl2uktEXlTr8BKxdVu/+gKQKmK8AdF09Eb9IWc0Gk44Z3 khw4Sd+6nzkYuG9wmGq4x6SyXrbD62Z3jhx5GXYsYNnqZLhyRQft6GGUETNIZv3f0GW9 xZ+TAisJ0K6FfkJph42a8tzvDnrClqTghVnVG0nTDZwGTosxp7wC+hOWo+Cgbc1kfSaQ KdwlOYIQYGQfO0GLQdSOGidZMfmRzElKAvv0ZEeQE6ZmsKeryzsXnQjAkXRsi/iWV30l 1i1PWrF1uB6s2d9mOKz3IMaNS4HcClh+jTZIBr9O3QKi2nv/LMjEfUaL6h+HTjgW7w0D Bqfg== 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 :message-id:date:subject:cc:to:from; bh=+5EZDs6kXnSVYcikXXlYapDyzbwlC80fqfQCO/00Qrc=; b=S3DBwHj5MXFh7qIcgpJucrTZbJEuGuPtKQMgcu2CxCbkKeUcarIfa3lb9aXjiSsk/k 6o+8X/PCRkVJz8St7GAxdOEoGPgskek6sLBwZhsJKCmQV27h5YB8zghsiHDSIjjEV2HU x3kAeKwy8ryzohgo8ciHH0tVS7w5dx3n7F8vwKsc5n9PLLT2/8+buz4qQzQq/yTpciuc MmkRUJdtS7MJySbT4YzzyMbHsgpqgxFOuxdY38zbf5h+OaRHkXdj1B+GOKyNiQR2mVDA avECln+0XnQQChjhQt5mcmEBAz69kj2PgKUnMt9HeRSBK381/XjXAb+qD1LVdvMMU2AV ARZA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a170902d48900b0019638b14613si229614plg.622.2023.03.13.11.00.18; Mon, 13 Mar 2023 11:00:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230080AbjCMRie (ORCPT + 99 others); Mon, 13 Mar 2023 13:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjCMRid (ORCPT ); Mon, 13 Mar 2023 13:38:33 -0400 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CACD12ED58; Mon, 13 Mar 2023 10:38:31 -0700 (PDT) Received: by mail-pl1-f180.google.com with SMTP id y11so13840018plg.1; Mon, 13 Mar 2023 10:38:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678729111; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+5EZDs6kXnSVYcikXXlYapDyzbwlC80fqfQCO/00Qrc=; b=fMXIagtLxBDhvjjuEu//L0RZiZKsyqq7JVOdZwWumUKwkxrBbF/QCzcj3Oh2lraz76 1HPNcYMDvzx54ZizUo1MdJotAq72Re2cHzbJjz+7h2qSyXvH8rU67ZDPeH/sOhRCMaxj 0RPj+lfVtfyG5d30VDhIc+rJnvGKh6Q87Lz8vwpyDc2nCjvtxtIMVq+obpiRkgUCK2mw 4e4xlbFzOTEsmPwcIvsEeMdDvkHIvbi4CkGxPlhmyTrIxNDQ4MoBsAE9djcwU4u5ZesS uNEhtWsTP9UIWU94EHIlWDpQ6QcFber8BOPSY9pAtF92nB5XJ9ODIEuyIiOTbuAAcoZ3 TRmQ== X-Gm-Message-State: AO0yUKXCGZTqqcC1Ua0ihPZ/zGkqzUOOb9MUSMXLRpzbTcbvnZ637cnZ cbNZHovyHepsXcP2Lh2Vdcg= X-Received: by 2002:a05:6a20:a88a:b0:d5:1f75:669a with SMTP id ca10-20020a056a20a88a00b000d51f75669amr798156pzb.13.1678729110953; Mon, 13 Mar 2023 10:38:30 -0700 (PDT) Received: from localhost.localdomain (61-227-97-148.dynamic-ip.hinet.net. [61.227.97.148]) by smtp.gmail.com with ESMTPSA id 12-20020a63184c000000b004fc2582aedbsm25873pgy.17.2023.03.13.10.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 10:38:30 -0700 (PDT) From: "You-Sheng Yang (vicamo)" To: Nirmal Patel , Jonathan Derrick , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Thomas Gleixner , Keith Busch Cc: "You-Sheng Yang (vicamo)" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: vmd: guard device addition and removal Date: Tue, 14 Mar 2023 01:37:33 +0800 Message-Id: <20230313173733.1815277-1-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760276443409180910?= X-GMAIL-MSGID: =?utf-8?q?1760276443409180910?= VMD may fail to create sysfs entries while `pci_rescan_bus()` called in some other drivers like t7xx wwan driver: sysfs: cannot create duplicate filename '/devices/.../resource0' Call Trace: sysfs_warn_dup.cold+0x17/0x34 sysfs_add_bin_file_mode_ns+0xc0/0xf0 sysfs_create_bin_file+0x6d/0xb0 pci_create_attr+0x117/0x260 pci_create_resource_files+0x6b/0x150 pci_create_sysfs_dev_files+0x18/0x30 pci_bus_add_device+0x30/0x80 pci_bus_add_devices+0x31/0x80 pci_bus_add_devices+0x5b/0x80 vmd_enable_domain.constprop.0+0x6b7/0x880 [vmd] vmd_probe+0x16d/0x193 [vmd] Fixes: 185a383ada2e ("x86/PCI: Add driver for Intel Volume Management Device (VMD)") Signed-off-by: You-Sheng Yang (vicamo) Reviewed-by: Nirmal Patel --- drivers/pci/controller/vmd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 769eedeb8802..f050991bd1e9 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -838,9 +838,13 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]); + pci_lock_rescan_remove(); + vmd->bus = pci_create_root_bus(&vmd->dev->dev, vmd->busn_start, &vmd_ops, sd, &resources); if (!vmd->bus) { + pci_unlock_rescan_remove(); + pci_free_resource_list(&resources); vmd_remove_irq_domain(vmd); return -ENODEV; @@ -893,6 +897,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) vmd_acpi_end(); + pci_unlock_rescan_remove(); + WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, "domain"), "Can't create symlink to domain\n"); return 0;