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 02/11] vfio: Add capability chain helpers
Date: Fri, 12 Feb 2016 17:02:09 -0700 [thread overview]
Message-ID: <20160213000209.17047.96633.stgit@gimli.home> (raw)
In-Reply-To: <20160212235331.17047.56669.stgit@gimli.home>
Allow sub-modules to easily reallocate a buffer for managing
capability chains for info ioctls.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/vfio/vfio.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/vfio.h | 11 ++++++++++
2 files changed, 65 insertions(+)
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 4cc961b..6fd6fa5 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1729,6 +1729,60 @@ long vfio_external_check_extension(struct vfio_group *group, unsigned long arg)
EXPORT_SYMBOL_GPL(vfio_external_check_extension);
/**
+ * Sub-module support
+ */
+/*
+ * Helper for managing a buffer of info chain capabilities, allocate or
+ * reallocate a buffer with additional @size, filling in @id and @version
+ * of the capability. A pointer to the new capability is returned.
+ *
+ * NB. The chain is based at the head of the buffer, so new entries are
+ * added to the tail, vfio_info_cap_shift() should be called to fixup the
+ * next offsets prior to copying to the user buffer.
+ */
+struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
+ size_t size, u16 id, u16 version)
+{
+ void *buf;
+ struct vfio_info_cap_header *header, *tmp;
+
+ buf = krealloc(caps->buf, caps->size + size, GFP_KERNEL);
+ if (!buf) {
+ kfree(caps->buf);
+ caps->size = 0;
+ return ERR_PTR(-ENOMEM);
+ }
+
+ caps->buf = buf;
+ header = buf + caps->size;
+
+ /* Eventually copied to user buffer, zero */
+ memset(header, 0, size);
+
+ header->id = id;
+ header->version = version;
+
+ /* Add to the end of the capability chain */
+ for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next)
+ ; /* nothing */
+
+ tmp->next = caps->size;
+ caps->size += size;
+
+ return header;
+}
+EXPORT_SYMBOL_GPL(vfio_info_cap_add);
+
+void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)
+{
+ struct vfio_info_cap_header *tmp;
+
+ for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset)
+ tmp->next += offset;
+}
+EXPORT_SYMBOL_GPL(vfio_info_cap_shift);
+
+/**
* Module/class support
*/
static char *vfio_devnode(struct device *dev, umode_t *mode)
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 610a86a..0ecae0b 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -92,6 +92,17 @@ extern int vfio_external_user_iommu_id(struct vfio_group *group);
extern long vfio_external_check_extension(struct vfio_group *group,
unsigned long arg);
+/*
+ * Sub-module helpers
+ */
+struct vfio_info_cap {
+ struct vfio_info_cap_header *buf;
+ size_t size;
+};
+extern struct vfio_info_cap_header *vfio_info_cap_add(
+ struct vfio_info_cap *caps, size_t size, u16 id, u16 version);
+extern void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset);
+
struct pci_dev;
#ifdef CONFIG_EEH
extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev);
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 ` Alex Williamson [this message]
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 ` [PATCH v2 10/11] vfio/pci: Hide stolen memory from the user Alex Williamson
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=20160213000209.17047.96633.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).