From patchwork Thu Jan 14 17:26:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 8034491 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 64FD49F744 for ; Thu, 14 Jan 2016 17:27:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86AB120497 for ; Thu, 14 Jan 2016 17:27:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 754D320430 for ; Thu, 14 Jan 2016 17:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756132AbcANR1A (ORCPT ); Thu, 14 Jan 2016 12:27:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51408 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753641AbcANR05 (ORCPT ); Thu, 14 Jan 2016 12:26:57 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 9DF5CC0ABF24; Thu, 14 Jan 2016 17:26:57 +0000 (UTC) Received: from gimli.home (ovpn-113-148.phx2.redhat.com [10.3.113.148]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0EHQvpY002890; Thu, 14 Jan 2016 12:26:57 -0500 Subject: [RFC PATCH] pci: Identify Enhanced Allocation (EA) BAR Equivalent resources From: Alex Williamson To: bhelgaas@google.com, linux-pci@vger.kernel.org Cc: sean.stalley@intel.com, david.daney@cavium.com Date: Thu, 14 Jan 2016 10:26:56 -0700 Message-ID: <20160114172645.23429.9938.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We've done a pretty good job of abstracting EA from drivers, but there are some properties of BAR Equivalent resources that don't really jive with traditional PCI BARs. In particular, natural alignment is only encouraged, not required. Why does this matter? There are drivers like vfio-pci that will happily gobble up the EA abstraction that's been implemented and expose a device using EA to userspace as if those resources are traditional BARs. Pretty cool. The vfio API is bus agnostic, so it doesn't care about alignment. The problem comes with PCI config space emulation where we don't let userspace manipulate the BAR value, but we do emulate BAR sizing. The abstraction kind of falls apart if userspace gets garbage when they try to size what appears to be a traditional BAR, but is actually a BAR equivalent. We could simply round up the size in vfio to make it naturally aligned, but then we're imposing artificial sizes to the user and we have the discontinuity that BAR size emulation and vfio region size reporting don't agree on the size. I think what we want to do is expose EA to the user, reporting traditional BARs with BEIs as zero-sized and providing additional regions for the user to access each EA region, whether it has a BEI or not. To facilitate that, a flag indicating whether a PCI resource is a traditional BAR or BAR equivalent seems much nicer than attempting to size the BAR ourselves or deducing it through the EA capability. Thoughts? Signed-off-by: Alex Williamson Acked-by: Sean O. Stalley --- drivers/pci/pci.c | 2 +- include/linux/ioport.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 314db8c..174c734 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2229,7 +2229,7 @@ void pci_pm_init(struct pci_dev *dev) static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop) { - unsigned long flags = IORESOURCE_PCI_FIXED; + unsigned long flags = IORESOURCE_PCI_FIXED | IORESOURCE_PCI_EA_BEI; switch (prop) { case PCI_EA_P_MEM: diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 24bea08..5acc194 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -105,6 +105,8 @@ struct resource { /* PCI control bits. Shares IORESOURCE_BITS with above PCI ROM. */ #define IORESOURCE_PCI_FIXED (1<<4) /* Do not move resource */ +/* PCI Enhanced Allocation defined BAR equivalent resource */ +#define IORESOURCE_PCI_EA_BEI (1<<5) /* helpers to define resources */ #define DEFINE_RES_NAMED(_start, _size, _name, _flags) \