From patchwork Wed Jun 23 02:28:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12338851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F7FC48BE5 for ; Wed, 23 Jun 2021 02:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF52660C3E for ; Wed, 23 Jun 2021 02:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbhFWCav (ORCPT ); Tue, 22 Jun 2021 22:30:51 -0400 Received: from mail-pg1-f182.google.com ([209.85.215.182]:41864 "EHLO mail-pg1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbhFWCat (ORCPT ); Tue, 22 Jun 2021 22:30:49 -0400 Received: by mail-pg1-f182.google.com with SMTP id u190so471236pgd.8; Tue, 22 Jun 2021 19:28:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LBQrvoFPocMJkFcQu4BsnarGUiW1t6Ipw95ekgoHgGs=; b=SkJWv3S+iXzq2Yhpn15SZlFSftfoxGcUGtTzF1WtVgYJOlJtwZt2CeXwwuP+tv14lg RwSwkyLmEG3/0WA6+NvveScef0+lP0bxIKGpSfqEENTGlSg48FCYoCr3iL9T2VFXsU6V +LZrc0rWP3bCOOCK2kBy6iqtMv5cd7iGzB0U/W6sjsxQ1aNw2bRHpiaEyK3AahEybzuF 2jlFZkg2fYMibWP1JaDw9YAEHwgbMsiNR7p0hfWJXRSrN1JpYBkyM1AC5TbVEDpTz2Bc +GOnyp+ry3tG4+yzCh3M9C06UNvbeE46KIR9b5fsrOwsZEbBaX/KwoP98UIPw58cU8I+ nMww== X-Gm-Message-State: AOAM5310uMPXdAD7Jk+ag+J2NzqJUysNRi5cg/5vWr6Dw+fZJrDFHdRt MstdAniyrruLBSivFAc4gAE= X-Google-Smtp-Source: ABdhPJyTm1u9FtJlYn57k29Q04An5rIzOg0bXZ0j2tbvleo5R+VQGN1/s++L2RcaYzo/rM5PQOhl0Q== X-Received: by 2002:a65:4608:: with SMTP id v8mr1546154pgq.269.1624415311647; Tue, 22 Jun 2021 19:28:31 -0700 (PDT) Received: from localhost ([173.239.198.97]) by smtp.gmail.com with ESMTPSA id c18sm20578436pgf.66.2021.06.22.19.28.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 19:28:30 -0700 (PDT) From: Luis Chamberlain To: bhelgaas@google.com, alex.williamson@redhat.com, cohuck@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, eric.auger@redhat.com, giovanni.cabiddu@intel.com, mjrosato@linux.ibm.com, jannh@google.com, kvm@vger.kernel.org, linux-pci@vger.kernel.org, schnelle@linux.ibm.com Cc: minchan@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, jeyu@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, mcgrof@kernel.org, axboe@kernel.dk, mbenes@suse.com, jpoimboe@redhat.com, tglx@linutronix.de, keescook@chromium.org, jikos@kernel.org, rostedt@goodmis.org, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] PCI: Export pci_dev_trylock() and pci_dev_unlock() Date: Tue, 22 Jun 2021 19:28:23 -0700 Message-Id: <20210623022824.308041-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210623022824.308041-1-mcgrof@kernel.org> References: <20210623022824.308041-1-mcgrof@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Other places in the kernel use this form, and so just provide a common path for it. Acked-by: Bjorn Helgaas Signed-off-by: Luis Chamberlain Reviewed-by: Cornelia Huck --- drivers/pci/pci.c | 6 ++++-- include/linux/pci.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index f09821af1d2e..b1d9bb3f5ae2 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5027,7 +5027,7 @@ static void pci_dev_lock(struct pci_dev *dev) } /* Return 1 on successful lock, 0 on contention */ -static int pci_dev_trylock(struct pci_dev *dev) +int pci_dev_trylock(struct pci_dev *dev) { if (pci_cfg_access_trylock(dev)) { if (device_trylock(&dev->dev)) @@ -5037,12 +5037,14 @@ static int pci_dev_trylock(struct pci_dev *dev) return 0; } +EXPORT_SYMBOL_GPL(pci_dev_trylock); -static void pci_dev_unlock(struct pci_dev *dev) +void pci_dev_unlock(struct pci_dev *dev) { device_unlock(&dev->dev); pci_cfg_access_unlock(dev); } +EXPORT_SYMBOL_GPL(pci_dev_unlock); static void pci_dev_save_and_disable(struct pci_dev *dev) { diff --git a/include/linux/pci.h b/include/linux/pci.h index 6248e044dd29..d8f056f3a2e3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1622,6 +1622,9 @@ void pci_cfg_access_lock(struct pci_dev *dev); bool pci_cfg_access_trylock(struct pci_dev *dev); void pci_cfg_access_unlock(struct pci_dev *dev); +int pci_dev_trylock(struct pci_dev *dev); +void pci_dev_unlock(struct pci_dev *dev); + /* * PCI domain support. Sometimes called PCI segment (eg by ACPI), * a PCI domain is defined to be a set of PCI buses which share From patchwork Wed Jun 23 02:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12338853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 336F8C48BE5 for ; Wed, 23 Jun 2021 02:30:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B7906137D for ; Wed, 23 Jun 2021 02:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbhFWCaz (ORCPT ); Tue, 22 Jun 2021 22:30:55 -0400 Received: from mail-pl1-f176.google.com ([209.85.214.176]:39736 "EHLO mail-pl1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbhFWCaw (ORCPT ); Tue, 22 Jun 2021 22:30:52 -0400 Received: by mail-pl1-f176.google.com with SMTP id o21so349256pll.6; Tue, 22 Jun 2021 19:28:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gwx1ZCzIHLcluKpzR6wn6tTFWmEGPnbN9lvDpuT4Ci8=; b=E22iIsaEpX5QmOz5vAlaSEHvPJYKFjxvYGGxnofwgK3IA/F/y6hlGJUXYUGig/C7P4 87etjL/j+o+N5PSwa539Ifu4j/56Gs6bj+ErzYhOlKH1iSVtuYuJi7EP9JYAvkxyPr22 rEL0uC6bh6PFdDfL/6RG0cosfCgBze/UCLZwDmvmJVH8dzjQMjVG0DOHs/wy+X6OlpgF PUvqvE+/OZw8DaJsRDvWgpBfBDtA1P/owCRFPQC2bH4T0D7+qajgyxCilgn4UqurKuCo 956MTTN6DdIOAxWTpqO2jK6h+etKCXJ2W3N+eF9pjVJWauybvlSc9jGWik5u/544ccEq H9Qg== X-Gm-Message-State: AOAM533P4FmbaxucTYkxFoIRXMYbCJeGSVHSthpzEGp5ZcAm2v2uQBq0 1p6zr/HPmJkne0TIf2dIw4Q= X-Google-Smtp-Source: ABdhPJzHcG9fcZjWj1Zasi09PP3Nkv6szaELFTskqly+XG8me/DlhyZU2zgg8OCk4/5vNC1sFucw3g== X-Received: by 2002:a17:90a:d704:: with SMTP id y4mr7049988pju.22.1624415314997; Tue, 22 Jun 2021 19:28:34 -0700 (PDT) Received: from localhost ([173.239.198.97]) by smtp.gmail.com with ESMTPSA id y7sm3474466pja.8.2021.06.22.19.28.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 19:28:33 -0700 (PDT) From: Luis Chamberlain To: bhelgaas@google.com, alex.williamson@redhat.com, cohuck@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, eric.auger@redhat.com, giovanni.cabiddu@intel.com, mjrosato@linux.ibm.com, jannh@google.com, kvm@vger.kernel.org, linux-pci@vger.kernel.org, schnelle@linux.ibm.com Cc: minchan@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, jeyu@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, mcgrof@kernel.org, axboe@kernel.dk, mbenes@suse.com, jpoimboe@redhat.com, tglx@linutronix.de, keescook@chromium.org, jikos@kernel.org, rostedt@goodmis.org, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] vfio: use the new pci_dev_trylock() helper to simplify try lock Date: Tue, 22 Jun 2021 19:28:24 -0700 Message-Id: <20210623022824.308041-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210623022824.308041-1-mcgrof@kernel.org> References: <20210623022824.308041-1-mcgrof@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the new pci_dev_trylock() helper to simplify our locking. Signed-off-by: Luis Chamberlain Reviewed-by: Cornelia Huck Reviewed-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index bd7c482c948a..02b05f7b9a91 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -477,13 +477,10 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) * We can not use the "try" reset interface here, which will * overwrite the previously restored configuration information. */ - if (vdev->reset_works && pci_cfg_access_trylock(pdev)) { - if (device_trylock(&pdev->dev)) { - if (!__pci_reset_function_locked(pdev)) - vdev->needs_reset = false; - device_unlock(&pdev->dev); - } - pci_cfg_access_unlock(pdev); + if (vdev->reset_works && pci_dev_trylock(pdev)) { + if (!__pci_reset_function_locked(pdev)) + vdev->needs_reset = false; + pci_dev_unlock(pdev); } pci_restore_state(pdev);