From patchwork Mon Apr 10 11:58:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 9672477 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 8B40360244 for ; Mon, 10 Apr 2017 12:01:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 834501FF61 for ; Mon, 10 Apr 2017 12:01:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77EDF28449; Mon, 10 Apr 2017 12:01:41 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 C33821FF61 for ; Mon, 10 Apr 2017 12:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752955AbdDJMBe (ORCPT ); Mon, 10 Apr 2017 08:01:34 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36227 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753291AbdDJMBc (ORCPT ); Mon, 10 Apr 2017 08:01:32 -0400 Received: by mail-pg0-f66.google.com with SMTP id 81so25490604pgh.3 for ; Mon, 10 Apr 2017 05:01:32 -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:in-reply-to:references; bh=pu3ECqgAylE7ud1soLBgT+hqo6tjnzDRrEmDwV02muU=; b=EEihzPLAxkKBrCnHHpBRo51VTXERxCKheW4wDHvPp7m5GeSVMcN2/VgV9Ti83XhgeO O1LQrh2TzteiDXWtt1hxjEgh2LhZsu+IvNPIncEv5l6Wi2SwOuCgpsfz4ephMjCKFMl+ pRpnnGKGEcSa9pEZ8vcdMJEhDqrWMRl7jOr4nytbkr4dLVnDt1apIMhr/vTSKIXh/8Mw M7dxhgme8hPQwbb2gwat2yzYq+85CySstRfkKAUpp2c8Gn/DWSmGYRTrWv+d+DjUhPzk szIOxnyNmjULf+lJAdtMjSYK6PUWbVG3aJM92jwxPNzCW8oUXIIsAy9sGC+RpYiauCpn VXjw== 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; bh=pu3ECqgAylE7ud1soLBgT+hqo6tjnzDRrEmDwV02muU=; b=NK4K+2oHiaHXgxlOLN7108I3ryQnFMnUp2mjrnkB/Y2xoMxKbqE5koyheC6ZIoT2JG wC1ZOI1HsNLvQlH9v/uv7snFGHIYos+WzkpGX0YOQMC2sklFaMbusZ+mvvV0oB9tYBhd W24LYcB79HR6TygG3Ye9WG27eKzG9OTDN1KogMoJa7SPImcpz1OleRh9pcJYg5dlHNf3 LMOyOGHZ3GKcoOrXAshbdNGZ5SEI4x+AtZfOsuDCEWt4pY66msoMJWzJDqXBxSlAIJKW Tdn0+lZVdW1Y75zFvXgtRmfHIt28lH+0S2H2jp69jNSCjk33AIPZ4BqZw0/5dH9lyUkf c9zA== X-Gm-Message-State: AFeK/H2upipuzWBp+RkwMxZB3ZC3/JWQ2plkKJNrX3GYGT1izfKmQRG1BhjHnbBlq8dQ8g== X-Received: by 10.99.9.66 with SMTP id 63mr56320946pgj.22.1491825691884; Mon, 10 Apr 2017 05:01:31 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id h71sm24481917pfj.65.2017.04.10.05.01.31 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:01:31 -0700 (PDT) From: Yongji Xie To: bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, alex.williamson@redhat.com, gwshan@linux.vnet.ibm.com, aik@ozlabs.ru, benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, zhong@linux.vnet.ibm.com Subject: [PATCH v10 2/4] PCI: Add pcibios_default_alignment() for arch-specific alignment control Date: Mon, 10 Apr 2017 19:58:12 +0800 Message-Id: <1491825494-19331-3-git-send-email-elohimes@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1491825494-19331-1-git-send-email-elohimes@gmail.com> References: <1491825494-19331-1-git-send-email-elohimes@gmail.com> 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 When VFIO passes through a PCI device to a guest, it does not allow the guest to mmap BARs that are smaller than PAGE_SIZE unless it can reserve the rest of the page (see vfio_pci_probe_mmaps()). This is because a page might contain several small BARs for unrelated devices and a guest should not be able to access all of them. VFIO emulates guest accesses to non-mappable BARs, which is functional but slow. On systems with large page sizes, e.g., PowerNV with 64K pages, BARs are more likely to share a page and performance is more likely to be a problem. Add a weak function to set default alignment for all PCI devices. An arch can override it to force the PCI core to place memory BARs on their own pages. Signed-off-by: Yongji Xie --- drivers/pci/pci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7904d02..02f1255 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4947,6 +4947,11 @@ void pci_ignore_hotplug(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_ignore_hotplug); +resource_size_t __weak pcibios_default_alignment(struct pci_dev *dev) +{ + return 0; +} + #define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0}; static DEFINE_SPINLOCK(resource_alignment_lock); @@ -4962,14 +4967,15 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev) { int seg, bus, slot, func, align_order, count; unsigned short vendor, device, subsystem_vendor, subsystem_device; - resource_size_t align = 0; + resource_size_t align = pcibios_default_alignment(dev); char *p; spin_lock(&resource_alignment_lock); p = resource_alignment_param; - if (!*p) + if (!*p && !align) goto out; if (pci_has_flag(PCI_PROBE_ONLY)) { + align = 0; pr_info_once("PCI: Ignoring requested alignments (PCI_PROBE_ONLY)\n"); goto out; }