From patchwork Mon Jun 4 15:48:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10446875 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DABEC60375 for ; Mon, 4 Jun 2018 15:48:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDD3428B41 for ; Mon, 4 Jun 2018 15:48:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE71528B49; Mon, 4 Jun 2018 15:48:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69B5828B41 for ; Mon, 4 Jun 2018 15:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750934AbeFDPsM (ORCPT ); Mon, 4 Jun 2018 11:48:12 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:36902 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbeFDPsL (ORCPT ); Mon, 4 Jun 2018 11:48:11 -0400 Received: by mail-ot0-f195.google.com with SMTP id 101-v6so15757375oth.4; Mon, 04 Jun 2018 08:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=CXBosUokYaNnzSkufrEzxL6wgvi2ySlEAZ4FjJdGx5A=; b=MQohb+yVyQB1/xVaXE7ImVzd8UlmwKRt9oqwSneN9B07Y84Erj2+PtYFOC7W0s6eY/ Z2b6u42yKMbho6qnmuw2UAiYKj2QeXLNezvzh1kVuZ9bsV90bXr5k3FSyqa+PLTfm99V YpgfAsGpWmryZ9varo/0rDSeO54iQvJZW5/Ad+Z1dwlM+inU7jSTyvQPI2pMdKSJIyPI XcXSBCYDFqFAVcZmqt+s6H1F+NsXxRfCV5jlvIJzXqr3LX7MMGMYiinDcEk06XOWyKEl 7Aq9B1+N0ty516wQzor5CTTiJkBLkvad0/RrE9wdh4/f2jW3+4mdWJWz+/gbsSPmnR0c H2tg== 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; bh=CXBosUokYaNnzSkufrEzxL6wgvi2ySlEAZ4FjJdGx5A=; b=K9cJYdVaO4v/l11kLt3g6Wqj8ziBdWT0r66JRp2O6e5E6Xg9/ii5QXHnNNJ8iWMYkv rkqxh9ELPHlkWHCL35CGr8NEWV4gjNbcGhS1v/NbB08b8aupaDP5yYKe/EC29jvojU/r ARyiwwvac+NtFracsq/D4Q7WfnoVWZBd7t0yx3NWP4Qi5xO74fkeOjJP5KlWHL43aE59 dubXXRhN7IO1q4WYH8z+r7mN1E8m6e2sF8bYxLilGLFIeRduX+xmj8HejfX2iV4rBy5W HavtH1HDzv1NmwtiB8mkK+GUggcp2G1DrXD0UQZxLnWy1PMfznC/5/da56RJUOieInlm +qSg== X-Gm-Message-State: ALKqPwcs7XMbmfl4QWqDy4cLmFn9P5+eyTR80H67s/wsS1SD5pniAc59 sAnODosp36f/aGdePXHTobs= X-Google-Smtp-Source: ADUXVKIZIzV2Jg8SBGEluJZSxFqu/6Lqqc9nH9Swe1a2lFMDcEqq9k4e12ytBQub+NA4bfD4UIRBZw== X-Received: by 2002:a9d:5a8a:: with SMTP id w10-v6mr15827021oth.16.1528127290515; Mon, 04 Jun 2018 08:48:10 -0700 (PDT) Received: from austins740xd.raid.adc.delllabs.net ([143.166.81.254]) by smtp.gmail.com with ESMTPSA id t4-v6sm3560175otd.40.2018.06.04.08.48.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 08:48:09 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: alex_gagniuc@dellteam.com, austin_bolen@dell.com, shyam_iyer@dell.com, keith.busch@intel.com, Alexandru Gagniuc , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*() Date: Mon, 4 Jun 2018 10:48:02 -0500 Message-Id: <20180604154803.14185-1-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.14.4 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_read/write_config*() functions have several safeguards to prevent stallling accesses when a device is removed. However, their "_user_" counterparts use a different code path. To make sure that safeguards are used for userspace PCI config accesses, piggyback the "_user_" functions on the in-kernel pci_read/write_config*(). Signed-off-by: Alexandru Gagniuc --- drivers/pci/access.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/pci/access.c b/drivers/pci/access.c index a3ad2fe185b9..6db2a8713c85 100644 --- a/drivers/pci/access.c +++ b/drivers/pci/access.c @@ -223,16 +223,9 @@ int pci_user_read_config_##size \ (struct pci_dev *dev, int pos, type *val) \ { \ int ret = PCIBIOS_SUCCESSFUL; \ - u32 data = -1; \ if (PCI_##size##_BAD) \ return -EINVAL; \ - raw_spin_lock_irq(&pci_lock); \ - if (unlikely(dev->block_cfg_access)) \ - pci_wait_cfg(dev); \ - ret = dev->bus->ops->read(dev->bus, dev->devfn, \ - pos, sizeof(type), &data); \ - raw_spin_unlock_irq(&pci_lock); \ - *val = (type)data; \ + ret = pci_read_config_##size(dev, pos, val); \ return pcibios_err_to_errno(ret); \ } \ EXPORT_SYMBOL_GPL(pci_user_read_config_##size); @@ -245,12 +238,7 @@ int pci_user_write_config_##size \ int ret = PCIBIOS_SUCCESSFUL; \ if (PCI_##size##_BAD) \ return -EINVAL; \ - raw_spin_lock_irq(&pci_lock); \ - if (unlikely(dev->block_cfg_access)) \ - pci_wait_cfg(dev); \ - ret = dev->bus->ops->write(dev->bus, dev->devfn, \ - pos, sizeof(type), val); \ - raw_spin_unlock_irq(&pci_lock); \ + ret = pci_write_config_##size(dev, pos, val); \ return pcibios_err_to_errno(ret); \ } \ EXPORT_SYMBOL_GPL(pci_user_write_config_##size);