From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org
Cc: alex.williamson@redhat.com, allen.m.kay@intel.com,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 10/11] vfio/pci: Hide stolen memory from the user
Date: Fri, 12 Feb 2016 17:02:56 -0700 [thread overview]
Message-ID: <20160213000255.17047.2712.stgit@gimli.home> (raw)
In-Reply-To: <20160212235331.17047.56669.stgit@gimli.home>
We do not provide a way for the user to access the host stolen memory
therefore hide both the base address and the size. This is mostly
useful for VM users where the driver may try to make use of the memory
referenced by these registers, whether the VM considers it reserved
for the GPU or not.
Unfortunately the format of the GMCH_CTRL register is not constant
between chip revisions, so we're stuck with ongoing maintenance to try
to track the latest device IDs. Perhaps if the register is stable now
we should blacklist pre-SandyBridge devices, identify the old format
for Gen 6 and 7 devices, and assume anything else uses Gen 8 format.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/vfio/pci/vfio_pci_igd.c | 80 +++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_igd.c
index 6394b16..03d916e 100644
--- a/drivers/vfio/pci/vfio_pci_igd.c
+++ b/drivers/vfio/pci/vfio_pci_igd.c
@@ -18,11 +18,15 @@
#include <linux/uaccess.h>
#include <linux/vfio.h>
+#include <drm/i915_drm.h>
+#include <drm/i915_pciids.h>
+
#include "vfio_pci_private.h"
#define OPREGION_SIGNATURE "IntelGraphicsMem"
#define OPREGION_SIZE (8 * 1024)
#define OPREGION_PCI_ADDR 0xfc
+#define BDSM_PCI_ADDR 0x5c /* Base Data Stolen Memory */
static size_t vfio_pci_igd_rw(struct vfio_pci_device *vdev, char __user *buf,
size_t count, loff_t *ppos, bool iswrite)
@@ -264,8 +268,64 @@ static int vfio_pci_igd_cfg_init(struct vfio_pci_device *vdev)
return 0;
}
+struct vfio_pci_igd_info {
+ u16 gmch_gsm_mask;
+};
+
+static const struct vfio_pci_igd_info igd_gen6 = {
+ .gmch_gsm_mask = SNB_GMCH_GMS_MASK << SNB_GMCH_GMS_SHIFT,
+};
+
+static const struct vfio_pci_igd_info igd_gen8 = {
+ .gmch_gsm_mask = BDW_GMCH_GMS_MASK << BDW_GMCH_GMS_SHIFT,
+};
+
+static const struct pci_device_id vfio_pci_igd_ids[] = {
+ /* Gen6 - SandyBridge */
+ INTEL_SNB_D_IDS(&igd_gen6),
+ INTEL_SNB_M_IDS(&igd_gen6),
+ /* Gen7 - IvyBridge, ValleyView, Haswell */
+ INTEL_IVB_D_IDS(&igd_gen6),
+ INTEL_IVB_M_IDS(&igd_gen6),
+ INTEL_IVB_Q_IDS(&igd_gen6),
+ INTEL_VLV_M_IDS(&igd_gen6),
+ INTEL_VLV_D_IDS(&igd_gen6),
+ INTEL_HSW_D_IDS(&igd_gen6),
+ INTEL_HSW_M_IDS(&igd_gen6),
+ /* Gen8 - BroadWell, CherryView */
+ INTEL_BDW_GT12D_IDS(&igd_gen8),
+ INTEL_BDW_GT12M_IDS(&igd_gen8),
+ INTEL_BDW_GT3D_IDS(&igd_gen8),
+ INTEL_BDW_GT3M_IDS(&igd_gen8),
+ INTEL_CHV_IDS(&igd_gen8),
+ /* Gen9 - SkyLake, Broxton, KabyLake */
+ INTEL_SKL_GT1_IDS(&igd_gen8),
+ INTEL_SKL_GT2_IDS(&igd_gen8),
+ INTEL_SKL_GT3_IDS(&igd_gen8),
+ INTEL_SKL_GT4_IDS(&igd_gen8),
+ INTEL_BXT_IDS(&igd_gen8),
+ INTEL_KBL_GT1_IDS(&igd_gen8),
+ INTEL_KBL_GT2_IDS(&igd_gen8),
+ INTEL_KBL_GT3_IDS(&igd_gen8),
+ INTEL_KBL_GT4_IDS(&igd_gen8),
+ { 0 }
+};
+
+static struct vfio_pci_igd_info *vfio_pci_igd_info(struct pci_dev *pdev)
+{
+ const struct pci_device_id *id;
+
+ id = pci_match_id(vfio_pci_igd_ids, pdev);
+ if (!id)
+ return NULL;
+
+ return (struct vfio_pci_igd_info *)id->driver_data;
+}
+
int vfio_pci_igd_init(struct vfio_pci_device *vdev)
{
+ struct vfio_pci_igd_info *info;
+ u16 gmch;
int ret;
ret = vfio_pci_igd_opregion_init(vdev);
@@ -276,5 +336,25 @@ int vfio_pci_igd_init(struct vfio_pci_device *vdev)
if (ret)
return ret;
+ memset(vdev->vconfig + BDSM_PCI_ADDR, 0, 4);
+ memset(vdev->pci_config_map + BDSM_PCI_ADDR,
+ PCI_CAP_ID_INVALID_VIRT, 4);
+
+ info = vfio_pci_igd_info(vdev->pdev);
+ if (!info) {
+ dev_warn(&vdev->pdev->dev,
+ "Unknown/Unsupported Intel IGD device\n");
+ return 0;
+ }
+
+ ret = pci_read_config_word(vdev->pdev, SNB_GMCH_CTRL, &gmch);
+ if (ret)
+ return ret;
+
+ gmch &= ~info->gmch_gsm_mask;
+ *(__le16 *)(vdev->vconfig + SNB_GMCH_CTRL) = cpu_to_le16(gmch);
+ memset(vdev->pci_config_map + SNB_GMCH_CTRL,
+ PCI_CAP_ID_INVALID_VIRT, 2);
+
return 0;
}
next prev parent reply other threads:[~2016-02-13 0:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-13 0:01 [PATCH v2 00/11] vfio: capability chains, sparse mmaps, device specific regions, IGD support Alex Williamson
2016-02-13 0:02 ` [PATCH v2 01/11] vfio: Define capability chains Alex Williamson
2016-02-13 0:02 ` [PATCH v2 02/11] vfio: Add capability chain helpers Alex Williamson
2016-02-13 0:02 ` [PATCH v2 03/11] vfio: Define sparse mmap capability for regions Alex Williamson
2016-02-13 0:02 ` [PATCH v2 04/11] vfio/pci: Include sparse mmap capability for MSI-X table regions Alex Williamson
2016-02-13 0:02 ` [PATCH v2 05/11] vfio: Define device specific region type capability Alex Williamson
2016-02-13 0:02 ` [PATCH v2 06/11] vfio/pci: Add infrastructure for additional device specific regions Alex Williamson
2016-02-13 0:02 ` [PATCH v2 07/11] vfio/pci: Enable virtual register in PCI config space Alex Williamson
2016-02-13 0:02 ` [PATCH v2 08/11] vfio/pci: Intel IGD OpRegion support Alex Williamson
2016-02-13 0:02 ` [PATCH v2 09/11] vfio/pci: Intel IGD host and LCP bridge config space access Alex Williamson
2016-02-13 0:02 ` Alex Williamson [this message]
2016-02-13 0:03 ` [PATCH v2 11/11] vfio/pci: Expose shadow ROM as PCI option ROM Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160213000255.17047.2712.stgit@gimli.home \
--to=alex.williamson@redhat.com \
--cc=allen.m.kay@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).