Skip to contentSkip to conversation

hyper_dmabuf: initial working version of hyper_dmabuf drv

RFC PATCH In review Dongwon Kim 6 participants 105 messages Dec 19, 2017 – Feb 15, 2018 Page 1 of 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/60 hyper_dmabuf: initial working version of hyper_dmabuf drv

Upload of intial version of hyper_DMABUF driver enabling DMA_BUF exchange between two different VMs in virtualized platform based on hypervisor such as KVM or XEN.

Hyper_DMABUF drv's primary role is to import a DMA_BUF from originator then re-export it to another Linux VM so that it can be mapped and accessed by it.

The functionality of this driver highly depends on Hypervisor's native page sharing mechanism and inter-VM communication support.

This driver has two layers, one is main hyper_DMABUF framework for scatter-gather list management that handles actual import and export of DMA_BUF. Lower layer is about actual memory sharing and communication between two VMs, which is hypervisor-specific interface.

This driver is initially designed to enable DMA_BUF sharing across VMs in Xen environment, so currently working with Xen only.

This also adds Kernel configuration for hyper_DMABUF drv under Device Drivers->Xen driver support->hyper_dmabuf options.

To give some brief information about each source file,

hyper_dmabuf/hyper_dmabuf_conf.h
: configuration info

hyper_dmabuf/hyper_dmabuf_drv.c
: driver interface and initialization

hyper_dmabuf/hyper_dmabuf_imp.c
: scatter-gather list generation and management. DMA_BUF ops for DMA_BUF reconstructed from hyper_DMABUF

hyper_dmabuf/hyper_dmabuf_ioctl.c
: IOCTLs calls for export/import and comm channel creation unexport.

hyper_dmabuf/hyper_dmabuf_list.c
: Database (linked-list) for exported and imported hyper_DMABUF

hyper_dmabuf/hyper_dmabuf_msg.c
: creation and management of messages between exporter and importer

hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c
: comm ch management and ISRs for incoming messages.

hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c : Database (linked-list) for keeping information about existing comm channels among VMs

---
 drivers/xen/Kconfig                                |   2 +
 drivers/xen/Makefile                               |   1 +
 drivers/xen/hyper_dmabuf/Kconfig                   |  14 +
 drivers/xen/hyper_dmabuf/Makefile                  |  34 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h       |   2 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  54 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        | 101 +++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 852 +++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        |  31 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 462 +++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       | 119 +++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h       |  40 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 212 +++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  45 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h      |  16 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  70 ++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 328 ++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |  62 ++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  | 106 +++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h  |  35 +
 20 files changed, 2586 insertions(+)
 create mode 100644 drivers/xen/hyper_dmabuf/Kconfig
 create mode 100644 drivers/xen/hyper_dmabuf/Makefile
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h
drivers/xen/Kconfig +2 -0
index d8dd546..b59b0e3 100644
@@ -321,4 +321,6 @@ config XEN_SYMS
 config XEN_HAVE_VPMU
        bool
 
+source "drivers/xen/hyper_dmabuf/Kconfig"
+
 endmenu
drivers/xen/Makefile +1 -0
index 451e833..a6e253a 100644
@@ -4,6 +4,7 @@ obj-$(CONFIG_X86)			+= fallback.o
 obj-y	+= grant-table.o features.o balloon.o manage.o preempt.o time.o
 obj-y	+= events/
 obj-y	+= xenbus/
+obj-y	+= hyper_dmabuf/
 
 nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_features.o			:= $(nostackp)
drivers/xen/hyper_dmabuf/Kconfig new file +14 -0
new file mode 100644
index 0000000..75e1f96
@@ -0,0 +1,14 @@
+menu "hyper_dmabuf options"
+
+config HYPER_DMABUF
+	tristate "Enables hyper dmabuf driver"
+	default y
+
+config HYPER_DMABUF_XEN
+	bool "Configure hyper_dmabuf for XEN hypervisor"
+	default y
+	depends on HYPER_DMABUF
+	help
+	  Configuring hyper_dmabuf driver for XEN hypervisor
+
+endmenu
drivers/xen/hyper_dmabuf/Makefile new file +34 -0
new file mode 100644
index 0000000..0be7445
@@ -0,0 +1,34 @@
+TARGET_MODULE:=hyper_dmabuf
+
+# If we running by kernel building system
+ifneq ($(KERNELRELEASE),)
+	$(TARGET_MODULE)-objs := hyper_dmabuf_drv.o \
+                                 hyper_dmabuf_ioctl.o \
+                                 hyper_dmabuf_list.o \
+				 hyper_dmabuf_imp.o \
+				 hyper_dmabuf_msg.o \
+				 xen/hyper_dmabuf_xen_comm.o \
+				 xen/hyper_dmabuf_xen_comm_list.o
+
+obj-$(CONFIG_HYPER_DMABUF) := $(TARGET_MODULE).o
+
+# If we are running without kernel build system
+else
+BUILDSYSTEM_DIR?=../../../
+PWD:=$(shell pwd)
+
+all :
+# run kernel build system to make module
+$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) modules
+
+clean:
+# run kernel build system to cleanup in current directory
+$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) clean
+
+load:
+	insmod ./$(TARGET_MODULE).ko
+
+unload:
+	rmmod ./$(TARGET_MODULE).ko
+
+endif
drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h new file +2 -0
new file mode 100644
index 0000000..3d9b2d6
@@ -0,0 +1,2 @@
+#define CURRENT_TARGET XEN
+#define INTER_DOMAIN_DMABUF_SYNCHRONIZATION
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c new file +54 -0

54 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h new file +101 -0

101 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c new file +852 -0

852 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h new file +31 -0
new file mode 100644
index 0000000..003c158
@@ -0,0 +1,31 @@
+#ifndef __HYPER_DMABUF_IMP_H__
+#define __HYPER_DMABUF_IMP_H__
+
+#include "hyper_dmabuf_struct.h"
+
+/* extract pages directly from struct sg_table */
+struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt);
+
+/* create sg_table with given pages and other parameters */
+struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
+                                int frst_ofst, int last_len, int nents);
+
+grant_ref_t hyper_dmabuf_create_gref_table(struct page **pages, int rdomain, int nents,
+					   struct hyper_dmabuf_shared_pages_info *shared_pages_info);
+
+int hyper_dmabuf_cleanup_gref_table(struct hyper_dmabuf_sgt_info *sgt_info);
+
+int hyper_dmabuf_cleanup_imported_pages(struct hyper_dmabuf_imported_sgt_info *sgt_info);
+
+/* map first level tables that contains reference numbers for actual shared pages */
+grant_ref_t *hyper_dmabuf_map_gref_table(grant_ref_t *gref_table, int n_pages_table);
+
+/* map and construct sg_lists from reference numbers */
+struct sg_table* hyper_dmabuf_map_pages(grant_ref_t gref, int frst_ofst, int last_len, int nents, int sdomain,
+					struct hyper_dmabuf_shared_pages_info *shared_pages_info);
+
+int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
+
+struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+
+#endif /* __HYPER_DMABUF_IMP_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c new file +462 -0

462 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c new file +119 -0

119 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h new file +40 -0
new file mode 100644
index 0000000..869cd9a
@@ -0,0 +1,40 @@
+#ifndef __HYPER_DMABUF_LIST_H__
+#define __HYPER_DMABUF_LIST_H__
+
+#include "hyper_dmabuf_struct.h"
+
+/* number of bits to be used for exported dmabufs hash table */
+#define MAX_ENTRY_EXPORTED 7
+/* number of bits to be used for imported dmabufs hash table */
+#define MAX_ENTRY_IMPORTED 7
+
+struct hyper_dmabuf_info_entry_exported {
+        struct hyper_dmabuf_sgt_info *info;
+        struct hlist_node node;
+};
+
+struct hyper_dmabuf_info_entry_imported {
+        struct hyper_dmabuf_imported_sgt_info *info;
+        struct hlist_node node;
+};
+
+int hyper_dmabuf_table_init(void);
+
+int hyper_dmabuf_table_destroy(void);
+
+int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
+
+/* search for pre-exported sgt and return id of it if it exist */
+int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid);
+
+int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
+
+struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id);
+
+struct hyper_dmabuf_imported_sgt_info *hyper_dmabuf_find_imported(int id);
+
+int hyper_dmabuf_remove_exported(int id);
+
+int hyper_dmabuf_remove_imported(int id);
+
+#endif // __HYPER_DMABUF_LIST_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c new file +212 -0

212 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h new file +45 -0

45 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h new file +16 -0
new file mode 100644
index 0000000..a577167
@@ -0,0 +1,16 @@
+#ifndef __HYPER_DMABUF_QUERY_H__
+#define __HYPER_DMABUF_QUERY_H__
+
+enum hyper_dmabuf_query {
+	DMABUF_QUERY_TYPE_LIST = 0x10,
+	DMABUF_QUERY_EXPORTER,
+	DMABUF_QUERY_IMPORTER,
+	DMABUF_QUERY_SIZE
+};
+
+enum hyper_dmabuf_status {
+	EXPORTED = 0x01,
+	IMPORTED
+};
+
+#endif /* __HYPER_DMABUF_QUERY_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h new file +70 -0

70 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c new file +328 -0

328 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h new file +62 -0

62 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c new file +106 -0

106 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h new file +35 -0
new file mode 100644
index 0000000..5929f99
@@ -0,0 +1,35 @@
+#ifndef __HYPER_DMABUF_XEN_COMM_LIST_H__
+#define __HYPER_DMABUF_XEN_COMM_LIST_H__
+
+/* number of bits to be used for exported dmabufs hash table */
+#define MAX_ENTRY_EXPORT_RING 7
+/* number of bits to be used for imported dmabufs hash table */
+#define MAX_ENTRY_IMPORT_RING 7
+
+struct hyper_dmabuf_exporter_ring_info {
+        struct hyper_dmabuf_ring_info_export *info;
+        struct hlist_node node;
+};
+
+struct hyper_dmabuf_importer_ring_info {
+        struct hyper_dmabuf_ring_info_import *info;
+        struct hlist_node node;
+};
+
+int hyper_dmabuf_ring_table_init(void);
+
+int hyper_dmabuf_ring_table_destroy(void);
+
+int hyper_dmabuf_register_exporter_ring(struct hyper_dmabuf_ring_info_export *ring_info);
+
+int hyper_dmabuf_register_importer_ring(struct hyper_dmabuf_ring_info_import *ring_info);
+
+struct hyper_dmabuf_ring_info_export *hyper_dmabuf_find_exporter_ring(int domid);
+
+struct hyper_dmabuf_ring_info_import *hyper_dmabuf_find_importer_ring(int domid);
+
+int hyper_dmabuf_remove_exporter_ring(int domid);
+
+int hyper_dmabuf_remove_importer_ring(int domid);
+
+#endif // __HYPER_DMABUF_XEN_COMM_LIST_H__
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

RFC PATCH 2/60 hyper_dmabuf: added a doc for hyper_dmabuf sharing

High-level description of hyper_dmabuf driver has been added to "Documentation" directory.

---
 Documentation/hyper-dmabuf-sharing.txt | 734 +++++++++++++++++++++++++++++++++
 1 file changed, 734 insertions(+)
 create mode 100644 Documentation/hyper-dmabuf-sharing.txt
Documentation/hyper-dmabuf-sharing.txt new file +734 -0
new file mode 100644
index 0000000..a6744f8
@@ -0,0 +1,734 @@
+Linux Hyper DMABUF Driver
+
+------------------------------------------------------------------------------
+Section 1. Overview
+------------------------------------------------------------------------------
+
+Hyper_DMABUF driver is a Linux device driver running on multiple Virtual
+achines (VMs), which expands DMA-BUF sharing capability to the VM environment
+where multiple different OS instances need to share same physical data without
+data-copy across VMs.
+
+To share a DMA_BUF across VMs, an instance of the Hyper_DMABUF drv on the
+exporting VM (so called, “exporter”) imports a local DMA_BUF from the original
+producer of the buffer, then re-exports it with an unique ID, hyper_dmabuf_id
+for the buffer to the importing VM (so called, “importer”).
+
+Another instance of the Hyper_DMABUF driver on importer registers
+a hyper_dmabuf_id together with reference information for the shared physical
+pages associated with the DMA_BUF to its database when the export happens.
+
+The actual mapping of the DMA_BUF on the importer’s side is done by
+the Hyper_DMABUF driver when user space issues the IOCTL command to access
+the shared DMA_BUF. The Hyper_DMABUF driver works as both an importing and
+exporting driver as is, that is, no special configuration is required.
+Consequently, only a single module per VM is needed to enable cross-VM DMA_BUF
+exchange.
+
+------------------------------------------------------------------------------
+Section 2. Architecture
+------------------------------------------------------------------------------
+
+1. Hyper_DMABUF ID
+
+hyper_dmabuf_id is a global handle for shared DMA BUFs, which is compatible
+across VMs. It is a key used by the importer to retrieve information about
+shared Kernel pages behind the DMA_BUF structure from the IMPORT list. When
+a DMA_BUF is exported to another domain, its hyper_dmabuf_id and META data
+are also kept in the EXPORT list by the exporter for further synchronization
+of control over the DMA_BUF.
+
+hyper_dmabuf_id is “targeted”, meaning it is valid only in exporting (owner of
+the buffer) and importing VMs, where the corresponding hyper_dmabuf_id is
+stored in their database (EXPORT and IMPORT lists).
+
+A user-space application specifies the targeted VM id in the user parameter
+when it calls the IOCTL command to export shared DMA_BUF to another VM.
+
+hyper_dmabuf_id_t is a data type for hyper_dmabuf_id. It is defined as 16-byte
+data structure, and it contains id and rng_key[3] as elements for
+the structure.
+
+typedef struct {
+        int id;
+        int rng_key[3]; /* 12bytes long random number */
+} hyper_dmabuf_id_t;
+
+The first element in the hyper_dmabuf_id structure, int id is combined data of
+a count number generated by the driver running on the exporter and
+the exporter’s ID. The VM’s ID is a one byte value and located at the field’s
+SB in int id. The remaining three bytes in int id are reserved for a count
+number.
+
+However, there is a limit related to this count number, which is 1000.
+Therefore, only little more than a byte starting from the LSB is actually used
+for storing this count number.
+
+#define HYPER_DMABUF_ID_CREATE(domid, id) \
+        ((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+
+This limit on the count number directly means the maximum number of DMA BUFs
+that  can be shared simultaneously by one VM. The second element of
+hyper_dmabuf_id, that is int rng_key[3], is an array of three integers. These
+numbers are generated by Linux’s native random number generation mechanism.
+This field is added to enhance the security of the Hyper DMABUF driver by
+maximizing the entropy of hyper_dmabuf_id (that is, preventing it from being
+guessed by a security attacker).
+
+Once DMA_BUF is no longer shared, the hyper_dmabuf_id associated with
+the DMA_BUF is released, but the count number in hyper_dmabuf_id is saved in
+the ID list for reuse. However, random keys stored in int rng_key[3] are not
+reused. Instead, those keys are always filled with freshly generated random
+keys for security.
+
+2. IOCTLs
+
+a. IOCTL_HYPER_DMABUF_TX_CH_SETUP
+
+This type of IOCTL is used for initialization of a one-directional transmit
+communication channel with a remote domain.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_tx_ch_setup {
+    /* IN parameters */
+    /* Remote domain id */
+    int remote_domain;
+};
+
+b. IOCTL_HYPER_DMABUF_RX_CH_SETUP
+
+This type of IOCTL is used for initialization of a one-directional receive
+communication channel with a remote domain.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_rx_ch_setup {
+    /* IN parameters */
+    /* Source domain id */
+    int source_domain;
+};
+
+c. IOCTL_HYPER_DMABUF_EXPORT_REMOTE
+
+This type of IOCTL is used to export a DMA BUF to another VM. When a user
+space application makes this call to the driver, it extracts Kernel pages
+associated with the DMA_BUF, then makes those shared with the importing VM.
+
+All reference information for this shared pages and hyper_dmabuf_id is
+created, then passed to the importing domain through a communications
+channel for synchronous registration. In the meantime, the hyper_dmabuf_id
+for the shared DMA_BUF is also returned to user-space application.
+
+This IOCTL can accept a reference to “user-defined” data as well as a FD
+for the DMA BUF. This private data is then attached to the DMA BUF and
+exported together with it.
+
+ore details regarding this private data can be found in chapter for
+“Hyper_DMABUF Private Data”.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_export_remote {
+    /* IN parameters */
+    /* DMA buf fd to be exported */
+    int dmabuf_fd;
+    /* Domain id to which buffer should be exported */
+    int remote_domain;
+    /* exported dma buf id */
+    hyper_dmabuf_id_t hid;
+    /* size of private data */
+    int sz_priv;
+    /* ptr to the private data for Hyper_DMABUF */
+    char *priv;
+};
+
+d. IOCTL_HYPER_DMABUF_EXPORT_FD
+
+The importing VM uses this IOCTL to import and re-export a shared DMA_BUF
+locally to the end-consumer using the standard Linux DMA_BUF framework.
+Upon IOCTL call, the Hyper_DMABUF driver finds the reference information
+of the shared DMA_BUF with the given hyper_dmabuf_id, then maps all shared
+pages in its own Kernel space. The driver then constructs a scatter-gather
+list with those mapped pages and creates a brand-new DMA_BUF with the list,
+which is eventually exported with a file descriptor to the local consumer.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_export_fd {
+    /* IN parameters */
+    /* hyper dmabuf id to be imported */
+    int hyper_dmabuf_id;
+    /* flags */
+    int flags;
+    /* OUT parameters */
+    /* exported dma buf fd */
+    int fd;
+};
+
+e. IOCTL_HYPER_DMABUF_UNEXPORT
+
+This type of IOCTL is used when it is necessary to terminate the current
+sharing of a DMA_BUF. When called, the driver first checks if there are any
+consumers actively using the DMA_BUF. Then, it unexports it if it is not
+mapped or used by any consumers. Otherwise, it postpones unexporting, but
+makes the buffer invalid to prevent any further import of the same DMA_BUF.
+DMA_BUF is completely unexported after the last consumer releases it.
+
+”Unexport” means remove all reference information about the DMA_BUF from the
+LISTs and make all pages private again.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_unexport {
+    /* IN parameters */
+    /* hyper dmabuf id to be unexported */
+    int hyper_dmabuf_id;
+    /* delay in ms by which unexport processing will be postponed */
+    int delay_ms;
+    /* OUT parameters */
+    /* Status of request */
+    int status;
+};
+
+f. IOCTL_HYPER_DMABUF_QUERY
+
+This IOCTL is used to retrieve specific information about a DMA_BUF that
+is being shared.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_query {
+    /* in parameters */
+    /* hyper dmabuf id to be queried */
+    int hyper_dmabuf_id;
+    /* item to be queried */
+    int item;
+    /* OUT parameters */
+    /* output of query */
+    /* info can be either value or reference */
+    unsigned long info;
+};
+
+<Available Queries>
+
+HYPER_DMABUF_QUERY_TYPE
+ - Return the type of DMA_BUF from the current domain, Exported or Imported.
+
+HYPER_DMABUF_QUERY_EXPORTER
+ - Return the exporting domain’s ID of a shared DMA_BUF.
+
+HYPER_DMABUF_QUERY_IMPORTER
+ - Return the importing domain’s ID of a shared DMA_BUF.
+
+HYPER_DMABUF_QUERY_SIZE
+ - Return the size of a shared DMA_BUF in bytes.
+
+HYPER_DMABUF_QUERY_BUSY
+ - Return ‘true’ if a shared DMA_BUF is currently used
+   (mapped by the end-consumer).
+
+HYPER_DMABUF_QUERY_UNEXPORTED
+ - Return ‘true’ if a shared DMA_BUF is not valid anymore
+   (so it does not allow a new consumer to map it).
+
+HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED
+ - Return ‘true’ if a shared DMA_BUF is scheduled to be unexported
+   (but is still valid) within a fixed time.
+
+HYPER_DMABUF_QUERY_PRIV_INFO
+ - Return ‘private’ data attached to shared DMA_BUF to the user space.
+   ‘unsigned long info’ is the user space pointer for the buffer, where
+   private data will be copied to.
+
+HYPER_DMABUF_QUERY_PRIV_INFO_SIZE
+ - Return the size of the private data attached to the shared DMA_BUF.
+
+3. Event Polling
+
+Event-polling can be enabled optionally by selecting the Kernel config option,
+Enable event-generation and polling operation under xen/hypervisor in Kernel’s
+menuconfig. The event-polling mechanism includes the generation of
+an import-event, adding it to the event-queue and providing a notification to
+the application so that it can retrieve the event data from the queue.
+
+For this mechanism, “Poll” and “Read” operations are added to the Hyper_DMABUF
+driver. A user application that polls the driver goes into a sleep state until
+there is a new event added to the queue. An application uses “Read” to retrieve
+event data from the event queue. Event data contains the hyper_dmabuf_id and
+the private data of the buffer that has been received by the importer.
+
+For more information on private data, refer to Section 3.5).
+Using this method, it is possible to lower the risk of the hyper_dmabuf_id and
+other sensitive information about the shared buffer (for example, meta-data
+for shared images) being leaked while being transferred to the importer because
+all of this data is shared as “private info” at the driver level. However,
+please note there should be a way for the importer to find the correct DMA_BUF
+in this case when there are multiple Hyper_DMABUFs being shared simultaneously.
+For example, the surface name or the surface ID of a specific rendering surface
+needs to be sent to the importer in advance before it is exported in a surface-
+sharing use-case.
+
+Each event data given to the user-space consists of a header and the private
+information of the buffer. The data type is defined as follows:
+
+struct hyper_dmabuf_event_hdr {
+        int event_type; /* one type only for now - new import */
+        hyper_dmabuf_id_t hid; /* hyper_dmabuf_id of specific hyper_dmabuf */
+        int size; /* size of data */
+};
+
+struct hyper_dmabuf_event_data {
+        struct hyper_dmabuf_event_hdr hdr;
+        void *data; /* private data */
+};
+
+4. Hyper_DMABUF Private Data
+
+Each Hyper_DMABUF can come with private data, the size of which can be up to
+AX_SIZE_PRIV_DATA (currently 192 byte). This private data is just a chunk of
+plain data attached to every Hyper_DMABUF. It is guaranteed to be synchronized
+across VMs, exporter and importer. This private data does not have any specific
+structure defined at the driver level, so any “user-defined” format or
+structure can be used. In addition, there is no dedicated use-case for this
+data. It can be used virtually for any purpose. For example, it can be used to
+share meta-data such as dimension and color formats for shared images in
+a surface sharing model. Another example is when we share protected media
+contents.
+
+This private data can be used to transfer flags related to content protection
+information on streamed media to the importer.
+
+Private data is initially generated when a buffer is exported for the first
+time. Then, it is updated whenever the same buffer is re-exported. During the
+re-exporting process, the Hyper_DMABUF driver only updates private data on
+both sides with new data from user-space since the same buffer already exists
+on both the IMPORT LIST and EXPORT LIST.
+
+There are two different ways to retrieve this private data from user-space.
+The first way is to use “Read” on the Hyper_DMABUF driver. “Read” returns the
+data of events containing private data of the buffer. The second way is to
+make a query to Hyper_DMABUF. There are two query items,
+HYPER_DMABUF_QUERY_PRIV_INFO and HYPER_DMABUF_QUERY_PRIV_INFO_SIZE available
+for retrieving private data and its size.
+
+5. Scatter-Gather List Table (SGT) Management
+
+SGT management is the core part of the Hyper_DMABUF driver that manages an
+SGT, a representation of the group of kernel pages associated with a DMA_BUF.
+This block includes four different sub-blocks:
+
+a. Hyper_DMABUF_id Manager
+
+This ID manager is responsible for generating a hyper_dmabuf_id for an
+exported DMA_BUF. When an ID is requested, the ID Manager first checks if
+there are any reusable IDs left in the list and returns one of those,
+if available. Otherwise, it creates the next count number and returns it
+to the caller.
+
+b. SGT Creator
+
+The SGT (struct sg_table) contains information about the DMA_BUF such as
+references to all kernel pages for the buffer and their connections. The
+SGT Creator creates a new SGT on the importer side with pages shared by
+the hypervisor.
+
+c. Kernel Page Extractor
+
+The Page Extractor extracts pages from a given SGT before those pages
+are shared.
+
+d. List Manager Interface
+
+The SGT manger also interacts with export and import list managers. It
+sends out information (for example, hyper_dmabuf_id, reference, and
+DMA_BUF information) about the exported or imported DMA_BUFs to the
+list manager. Also, on IOCTL request, it asks the list manager to find
+and return the information for a corresponding DMA_BUF in the list.
+
+6. DMA-BUF Interface
+
+The DMA-BUF interface provides standard methods to manage DMA_BUFs
+reconstructed by the Hyper_DMABUF driver from shared pages. All of the
+relevant operations are listed in struct dma_buf_ops. These operations
+are standard DMA_BUF operations, therefore they follow standard DMA BUF
+protocols.
+
+Each DMA_BUF operation communicates with the exporter at the end of the
+routine for “indirect DMA_BUF synchronization”.
+
+7. Export/Import List Management
+
+Whenever a DMA_BUF is shared and exported, its information is added to the
+database (EXPORT-list) on the exporting VM. Similarly, information about an
+imported DMA_BUF is added to the importing database (IMPORT list) on the
+importing VM, when the export happens.
+
+All of the entries in the lists are needed to manage the exported/imported
+DMA_BUF more efficiently. Both lists are implemented as Linux hash tables.
+The key to the list is hyper_dmabuf_id and the output is the information of
+the DMA_BUF. The List Manager manages all requests from other blocks and
+transactions within lists to ensure that all entries are up-to-date and
+that the list structure is consistent.
+
+The List Manager provides basic functionality, such as:
+
+- Adding to the List
+- Removal from the List
+- Finding information about a DMA_BUF, given the hyper_dmabuf_id
+
+8. Page Sharing by Hypercalls
+
+The Hyper_DMABUF driver assumes that there is a native page-by-page memory
+sharing mechanism available on the hypervisor. Referencing a group of pages
+that are being shared is what the driver expects from “backend” APIs or the
+hypervisor itself.
+
+For the example, xen backend integrated in current code base utilizes Xen’s
+grant-table interface for sharing the underlying kernel pages (struct *page).
+
+ore details about grant-table interface can be found at the following locations:
+
+https://wiki.xen.org/wiki/Grant_Table
+https://xenbits.xen.org/docs/4.6-testing/misc/grant-tables.txt
+
+9. Message Management
+
+The exporter and importer can each create a message that consists of an opcode
+(command) and operands (parameters) and send it to each other.
+
+The message format is defined as:
+
+struct hyper_dmabuf_req {
+        unsigned int req_id; /* Sequence number. Used for RING BUF
+                                synchronization */
+        unsigned int stat; /* Status.Response from receiver. */
+        unsigned int cmd;  /* Opcode */
+        unsigned int op[MAX_NUMBER_OF_OPERANDS]; /* Operands */
+};
+
+The following table gives the list of opcodes:
+
+<Opcodes in Message to Exporter/Importer>
+
+HYPER_DMABUF_EXPORT (exporter --> importer)
+ - Export a DMA_BUF to the importer. The importer registers the corresponding
+   DMA_BUF in its IMPORT LIST when the message is received.
+
+HYPER_DMABUF_EXPORT_FD (importer --> exporter)
+ - Locally exported as FD. The importer sends out this command to the exporter
+   to notify that the buffer is now locally exported (mapped and used).
+
+HYPER_DMABUF_EXPORT_FD_FAILED (importer --> exporter)
+ - Failed while exporting locally. The importer sends out this command to the
+   exporter to notify the exporter that the EXPORT_FD failed.
+
+HYPER_DMABUF_NOTIFY_UNEXPORT (exporter --> importer)
+ - Termination of sharing. The exporter notifies the importer that the DMA_BUF
+   has been unexported.
+
+HYPER_DMABUF_OPS_TO_REMOTE (importer --> exporter)
+ - Not implemented yet.
+
+HYPER_DMABUF_OPS_TO_SOURCE (exporter --> importer)
+ - DMA_BUF ops to the exporter, for DMA_BUF upstream synchronization.
+   Note: Implemented but it is done asynchronously due to performance issues.
+
+The following table shows the list of operands for each opcode.
+
+<Operands in Message to Exporter/Importer>
+
+- HYPER_DMABUF_EXPORT
+
+op0 to op3 – hyper_dmabuf_id
+op4 – number of pages to be shared
+op5 – offset of data in the first page
+op6 – length of data in the last page
+op7 – reference number for the group of shared pages
+op8 – size of private data
+op9 to (op9+op8)  – private data
+
+- HYPER_DMABUF_EXPORT_FD
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_EXPORT_FD_FAILED
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_NOTIFY_UNEXPORT
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_OPS_TO_REMOTE(Not implemented)
+
+- HYPER_DMABUF_OPS_TO_SOURCE
+
+op0 to op3 – hyper_dmabuf_id
+op4 – type of DMA_BUF operation
+
+9. Inter VM (Domain) Communication
+
+Two different types of inter-domain communication channels are required,
+one in kernel space and the other in user space. The communication channel
+in user space is for transmitting or receiving the hyper_dmabuf_id. Since
+there is no specific security (for example, encryption) involved in the
+generation of a global id at the driver level, it is highly recommended that
+the customer’s user application set up a very secure channel for exchanging
+hyper_dmabuf_id between VMs.
+
+The communication channel in kernel space is required for exchanging messages
+from “message management” block between two VMs. In the current reference
+backend for Xen hypervisor, Xen ring-buffer and event-channel mechanisms are
+used for message exchange between impoter and exporter.
+
+10. What are required in hypervisor
+
+emory sharing and message communication between VMs
+
+------------------------------------------------------------------------------
+Section 3. Hyper DMABUF Sharing Flow
+------------------------------------------------------------------------------
+
+1. Exporting
+
+To export a DMA_BUF to another VM, user space has to call an IOCTL
+(IOCTL_HYPER_DMABUF_EXPORT_REMOTE) with a file descriptor for the buffer given
+by the original exporter. The Hyper_DMABUF driver maps a DMA_BUF locally, then
+issues a hyper_dmabuf_id and SGT for the DMA_BUF, which is registered to the
+EXPORT list. Then, all pages for the SGT are extracted and each individual
+page is shared via a hypervisor-specific memory sharing mechanism
+(for example, in Xen this is grant-table).
+
+One important requirement on this memory sharing method is that it needs to
+create a single integer value that represents the list of pages, which can
+then be used by the importer for retrieving the group of shared pages.  For
+this, the “Backend” in the reference driver utilizes the multiple level
+addressing mechanism.
+
+Once the integer reference to the list of pages is created, the exporter
+builds the “export” command and sends it to the importer, then notifies the
+importer.
+
+2. Importing
+
+The Import process is divided into two sections. One is the registration
+of DMA_BUF from the exporter. The other is the actual mapping of the buffer
+before accessing the data in the buffer. The former (termed “Registration”)
+happens on an export event (that is, the export command with an interrupt)
+in the exporter.
+
+The latter (termed “Mapping”) is done asynchronously when the driver gets the
+IOCTL call from user space. When the importer gets an interrupt from the
+exporter, it checks the command in the receiving queue and if it is an
+“export” command, the registration process is started. It first finds
+hyper_dmabuf_id and the integer reference for the shared pages, then stores
+all of that information together with the “domain id” of the exporting domain
+in the IMPORT LIST.
+
+In the case where “event-polling” is enabled (Kernel Config - Enable event-
+generation and polling operation), a “new sharing available” event is
+generated right after the reference info for the new shared DMA_BUF is
+registered to the IMPORT LIST. This event is added to the event-queue.
+
+The user process that polls Hyper_DMABUF driver wakes up when this event-queue
+is not empty and is able to read back event data from the queue using the
+driver’s “Read” function. Once the user-application calls EXPORT_FD IOCTL with
+the proper parameters including hyper_dmabuf_id, the Hyper_DMABUF driver
+retrieves information about the matched DMA_BUF from the IMPORT LIST. Then, it
+maps all pages shared (referenced by the integer reference) in its kernel
+space and creates its own DMA_BUF referencing the same shared pages. After
+this, it exports this new DMA_BUF to the other drivers with a file descriptor.
+DMA_BUF can then be used just in the same way a local DMA_BUF is.
+
+3. Indirect Synchronization of DMA_BUF
+
+Synchronization of a DMA_BUF within a single OS is automatically achieved
+because all of importer’s DMA_BUF operations are done using functions defined
+on the exporter’s side, which means there is one central place that has full
+control over the DMA_BUF. In other words, any primary activities such as
+attaching/detaching and mapping/un-mapping are all captured by the exporter,
+meaning that the exporter knows basic information such as who is using the
+DMA_BUF and how it is being used. This, however, is not applicable if this
+sharing is done beyond a single OS because kernel space (where the exporter’s
+DMA_BUF operations reside) is simply not visible to the importing VM.
+
+Therefore, “indirect synchronization” was introduced as an alternative solution,
+which is now implemented in the Hyper_DMABUF driver. This technique makes
+the exporter create a shadow DMA_BUF when the end-consumer of the buffer maps
+the DMA_BUF, then duplicates any DMA_BUF operations performed on
+the importer’s side. Through this “indirect synchronization”, the exporter is
+able to virtually track all activities done by the consumer (mostly reference
+counter) as if those are done in exporter’s local system.
+
+------------------------------------------------------------------------------
+Section 4. Hypervisor Backend Interface
+------------------------------------------------------------------------------
+
+The Hyper_DMABUF driver has a standard “Backend” structure that contains
+mappings to various functions designed for a specific Hypervisor. Most of
+these API functions should provide a low-level implementation of communication
+and memory sharing capability that utilize a Hypervisor’s native mechanisms.
+
+struct hyper_dmabuf_backend_ops {
+        /* retreiving id of current virtual machine */
+        int (*get_vm_id)(void);
+        /* get pages shared via hypervisor-specific method */
+        int (*share_pages)(struct page **, int, int, void **);
+        /* make shared pages unshared via hypervisor specific method */
+        int (*unshare_pages)(void **, int);
+        /* map remotely shared pages on importer's side via
+         *  hypervisor-specific method
+         */
+        struct page ** (*map_shared_pages)(int, int, int, void **);
+        /* unmap and free shared pages on importer's side via
+         *  hypervisor-specific method
+         */
+        int (*unmap_shared_pages)(void **, int);
+        /* initialize communication environment */
+        int (*init_comm_env)(void);
+        /* destroy communication channel */
+        void (*destroy_comm)(void);
+        /* upstream ch setup (receiving and responding) */
+        int (*init_rx_ch)(int);
+        /* downstream ch setup (transmitting and parsing responses) */
+        int (*init_tx_ch)(int);
+        /* send msg via communication ch */
+        int (*send_req)(int, struct hyper_dmabuf_req *, int);
+};
+
+<Hypervisor-specific Backend Structure>
+
+1. get_vm_id
+
+	Returns the VM (domain) ID
+
+	Input:
+
+		-ID of the current domain
+
+	Output:
+
+		None
+
+2. share_pages
+
+	Get pages shared via hypervisor-specific method and return one reference
+	ID that represents the complete list of shared pages
+
+	Input:
+
+		-Array of pages
+		-ID of importing VM
+		-Number of pages
+		-Hypervisor specific Representation of reference info of shared
+		 pages
+
+	Output:
+
+		-Hypervisor specific integer value that represents all of
+		 the shared pages
+
+3. unshare_pages
+
+	Stop sharing pages
+
+	Input:
+
+		-Hypervisor specific Representation of reference info of shared
+		 pages
+		-Number of shared pages
+
+	Output:
+
+		0
+
+4. map_shared_pages
+
+	Map shared pages locally using a hypervisor-specific method
+
+	Input:
+
+		-Reference number that represents all of shared pages
+		-ID of exporting VM, Number of pages
+		-Reference information for any purpose
+
+	Output:
+
+		-An array of shared pages (struct page**)
+
+5. unmap_shared_pages
+
+	Unmap shared pages
+
+	Input:
+
+		-Hypervisor specific Representation of reference info of shared pages
+
+	Output:
+
+		-0 (successful) or one of Standard Kernel errors
+
+6. init_comm_env
+
+	Setup infrastructure needed for communication channel
+
+	Input:
+
+		None
+
+	Output:
+
+		None
+
+7. destroy_comm
+
+	Cleanup everything done via init_comm_env
+
+	Input:
+
+		None
+
+	Output:
+
+		None
+
+8. init_rx_ch
+
+	Configure receive channel
+
+	Input:
+
+		-ID of VM on the other side of the channel
+
+	Output:
+
+		-0 (successful) or one of Standard Kernel errors
+
+9. init_tx_ch
+
+	Configure transmit channel
+
+	Input:
+
+		-ID of VM on the other side of the channel
+
+	Output:
+
+		-0 (success) or one of Standard Kernel errors
+
+10. send_req
+
+	Send message to other VM
+
+	Input:
+
+		-ID of VM that receives the message
+		-Message
+
+	Output:
+
+		-0 (success) or one of Standard Kernel errors
+
+-------------------------------------------------------------------------------
+-------------------------------------------------------------------------------
Signature · 1 line
2.7.4
#2 lore raw

RFC PATCH 2/60 hyper_dmabuf: added a doc for hyper_dmabuf sharing

In reply to Dongwon Kim

High-level description of hyper_dmabuf driver has been added to "Documentation" directory.

---
 Documentation/hyper-dmabuf-sharing.txt | 734 +++++++++++++++++++++++++++++++++
 1 file changed, 734 insertions(+)
 create mode 100644 Documentation/hyper-dmabuf-sharing.txt
Documentation/hyper-dmabuf-sharing.txt new file +734 -0
new file mode 100644
index 0000000..a6744f8
@@ -0,0 +1,734 @@
+Linux Hyper DMABUF Driver
+
+------------------------------------------------------------------------------
+Section 1. Overview
+------------------------------------------------------------------------------
+
+Hyper_DMABUF driver is a Linux device driver running on multiple Virtual
+achines (VMs), which expands DMA-BUF sharing capability to the VM environment
+where multiple different OS instances need to share same physical data without
+data-copy across VMs.
+
+To share a DMA_BUF across VMs, an instance of the Hyper_DMABUF drv on the
+exporting VM (so called, “exporter”) imports a local DMA_BUF from the original
+producer of the buffer, then re-exports it with an unique ID, hyper_dmabuf_id
+for the buffer to the importing VM (so called, “importer”).
+
+Another instance of the Hyper_DMABUF driver on importer registers
+a hyper_dmabuf_id together with reference information for the shared physical
+pages associated with the DMA_BUF to its database when the export happens.
+
+The actual mapping of the DMA_BUF on the importer’s side is done by
+the Hyper_DMABUF driver when user space issues the IOCTL command to access
+the shared DMA_BUF. The Hyper_DMABUF driver works as both an importing and
+exporting driver as is, that is, no special configuration is required.
+Consequently, only a single module per VM is needed to enable cross-VM DMA_BUF
+exchange.
+
+------------------------------------------------------------------------------
+Section 2. Architecture
+------------------------------------------------------------------------------
+
+1. Hyper_DMABUF ID
+
+hyper_dmabuf_id is a global handle for shared DMA BUFs, which is compatible
+across VMs. It is a key used by the importer to retrieve information about
+shared Kernel pages behind the DMA_BUF structure from the IMPORT list. When
+a DMA_BUF is exported to another domain, its hyper_dmabuf_id and META data
+are also kept in the EXPORT list by the exporter for further synchronization
+of control over the DMA_BUF.
+
+hyper_dmabuf_id is “targeted”, meaning it is valid only in exporting (owner of
+the buffer) and importing VMs, where the corresponding hyper_dmabuf_id is
+stored in their database (EXPORT and IMPORT lists).
+
+A user-space application specifies the targeted VM id in the user parameter
+when it calls the IOCTL command to export shared DMA_BUF to another VM.
+
+hyper_dmabuf_id_t is a data type for hyper_dmabuf_id. It is defined as 16-byte
+data structure, and it contains id and rng_key[3] as elements for
+the structure.
+
+typedef struct {
+        int id;
+        int rng_key[3]; /* 12bytes long random number */
+} hyper_dmabuf_id_t;
+
+The first element in the hyper_dmabuf_id structure, int id is combined data of
+a count number generated by the driver running on the exporter and
+the exporter’s ID. The VM’s ID is a one byte value and located at the field’s
+SB in int id. The remaining three bytes in int id are reserved for a count
+number.
+
+However, there is a limit related to this count number, which is 1000.
+Therefore, only little more than a byte starting from the LSB is actually used
+for storing this count number.
+
+#define HYPER_DMABUF_ID_CREATE(domid, id) \
+        ((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+
+This limit on the count number directly means the maximum number of DMA BUFs
+that  can be shared simultaneously by one VM. The second element of
+hyper_dmabuf_id, that is int rng_key[3], is an array of three integers. These
+numbers are generated by Linux’s native random number generation mechanism.
+This field is added to enhance the security of the Hyper DMABUF driver by
+maximizing the entropy of hyper_dmabuf_id (that is, preventing it from being
+guessed by a security attacker).
+
+Once DMA_BUF is no longer shared, the hyper_dmabuf_id associated with
+the DMA_BUF is released, but the count number in hyper_dmabuf_id is saved in
+the ID list for reuse. However, random keys stored in int rng_key[3] are not
+reused. Instead, those keys are always filled with freshly generated random
+keys for security.
+
+2. IOCTLs
+
+a. IOCTL_HYPER_DMABUF_TX_CH_SETUP
+
+This type of IOCTL is used for initialization of a one-directional transmit
+communication channel with a remote domain.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_tx_ch_setup {
+    /* IN parameters */
+    /* Remote domain id */
+    int remote_domain;
+};
+
+b. IOCTL_HYPER_DMABUF_RX_CH_SETUP
+
+This type of IOCTL is used for initialization of a one-directional receive
+communication channel with a remote domain.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_rx_ch_setup {
+    /* IN parameters */
+    /* Source domain id */
+    int source_domain;
+};
+
+c. IOCTL_HYPER_DMABUF_EXPORT_REMOTE
+
+This type of IOCTL is used to export a DMA BUF to another VM. When a user
+space application makes this call to the driver, it extracts Kernel pages
+associated with the DMA_BUF, then makes those shared with the importing VM.
+
+All reference information for this shared pages and hyper_dmabuf_id is
+created, then passed to the importing domain through a communications
+channel for synchronous registration. In the meantime, the hyper_dmabuf_id
+for the shared DMA_BUF is also returned to user-space application.
+
+This IOCTL can accept a reference to “user-defined” data as well as a FD
+for the DMA BUF. This private data is then attached to the DMA BUF and
+exported together with it.
+
+ore details regarding this private data can be found in chapter for
+“Hyper_DMABUF Private Data”.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_export_remote {
+    /* IN parameters */
+    /* DMA buf fd to be exported */
+    int dmabuf_fd;
+    /* Domain id to which buffer should be exported */
+    int remote_domain;
+    /* exported dma buf id */
+    hyper_dmabuf_id_t hid;
+    /* size of private data */
+    int sz_priv;
+    /* ptr to the private data for Hyper_DMABUF */
+    char *priv;
+};
+
+d. IOCTL_HYPER_DMABUF_EXPORT_FD
+
+The importing VM uses this IOCTL to import and re-export a shared DMA_BUF
+locally to the end-consumer using the standard Linux DMA_BUF framework.
+Upon IOCTL call, the Hyper_DMABUF driver finds the reference information
+of the shared DMA_BUF with the given hyper_dmabuf_id, then maps all shared
+pages in its own Kernel space. The driver then constructs a scatter-gather
+list with those mapped pages and creates a brand-new DMA_BUF with the list,
+which is eventually exported with a file descriptor to the local consumer.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_export_fd {
+    /* IN parameters */
+    /* hyper dmabuf id to be imported */
+    int hyper_dmabuf_id;
+    /* flags */
+    int flags;
+    /* OUT parameters */
+    /* exported dma buf fd */
+    int fd;
+};
+
+e. IOCTL_HYPER_DMABUF_UNEXPORT
+
+This type of IOCTL is used when it is necessary to terminate the current
+sharing of a DMA_BUF. When called, the driver first checks if there are any
+consumers actively using the DMA_BUF. Then, it unexports it if it is not
+mapped or used by any consumers. Otherwise, it postpones unexporting, but
+makes the buffer invalid to prevent any further import of the same DMA_BUF.
+DMA_BUF is completely unexported after the last consumer releases it.
+
+”Unexport” means remove all reference information about the DMA_BUF from the
+LISTs and make all pages private again.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_unexport {
+    /* IN parameters */
+    /* hyper dmabuf id to be unexported */
+    int hyper_dmabuf_id;
+    /* delay in ms by which unexport processing will be postponed */
+    int delay_ms;
+    /* OUT parameters */
+    /* Status of request */
+    int status;
+};
+
+f. IOCTL_HYPER_DMABUF_QUERY
+
+This IOCTL is used to retrieve specific information about a DMA_BUF that
+is being shared.
+
+The user space argument for this type of IOCTL is defined as:
+
+struct ioctl_hyper_dmabuf_query {
+    /* in parameters */
+    /* hyper dmabuf id to be queried */
+    int hyper_dmabuf_id;
+    /* item to be queried */
+    int item;
+    /* OUT parameters */
+    /* output of query */
+    /* info can be either value or reference */
+    unsigned long info;
+};
+
+<Available Queries>
+
+HYPER_DMABUF_QUERY_TYPE
+ - Return the type of DMA_BUF from the current domain, Exported or Imported.
+
+HYPER_DMABUF_QUERY_EXPORTER
+ - Return the exporting domain’s ID of a shared DMA_BUF.
+
+HYPER_DMABUF_QUERY_IMPORTER
+ - Return the importing domain’s ID of a shared DMA_BUF.
+
+HYPER_DMABUF_QUERY_SIZE
+ - Return the size of a shared DMA_BUF in bytes.
+
+HYPER_DMABUF_QUERY_BUSY
+ - Return ‘true’ if a shared DMA_BUF is currently used
+   (mapped by the end-consumer).
+
+HYPER_DMABUF_QUERY_UNEXPORTED
+ - Return ‘true’ if a shared DMA_BUF is not valid anymore
+   (so it does not allow a new consumer to map it).
+
+HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED
+ - Return ‘true’ if a shared DMA_BUF is scheduled to be unexported
+   (but is still valid) within a fixed time.
+
+HYPER_DMABUF_QUERY_PRIV_INFO
+ - Return ‘private’ data attached to shared DMA_BUF to the user space.
+   ‘unsigned long info’ is the user space pointer for the buffer, where
+   private data will be copied to.
+
+HYPER_DMABUF_QUERY_PRIV_INFO_SIZE
+ - Return the size of the private data attached to the shared DMA_BUF.
+
+3. Event Polling
+
+Event-polling can be enabled optionally by selecting the Kernel config option,
+Enable event-generation and polling operation under xen/hypervisor in Kernel’s
+menuconfig. The event-polling mechanism includes the generation of
+an import-event, adding it to the event-queue and providing a notification to
+the application so that it can retrieve the event data from the queue.
+
+For this mechanism, “Poll” and “Read” operations are added to the Hyper_DMABUF
+driver. A user application that polls the driver goes into a sleep state until
+there is a new event added to the queue. An application uses “Read” to retrieve
+event data from the event queue. Event data contains the hyper_dmabuf_id and
+the private data of the buffer that has been received by the importer.
+
+For more information on private data, refer to Section 3.5).
+Using this method, it is possible to lower the risk of the hyper_dmabuf_id and
+other sensitive information about the shared buffer (for example, meta-data
+for shared images) being leaked while being transferred to the importer because
+all of this data is shared as “private info” at the driver level. However,
+please note there should be a way for the importer to find the correct DMA_BUF
+in this case when there are multiple Hyper_DMABUFs being shared simultaneously.
+For example, the surface name or the surface ID of a specific rendering surface
+needs to be sent to the importer in advance before it is exported in a surface-
+sharing use-case.
+
+Each event data given to the user-space consists of a header and the private
+information of the buffer. The data type is defined as follows:
+
+struct hyper_dmabuf_event_hdr {
+        int event_type; /* one type only for now - new import */
+        hyper_dmabuf_id_t hid; /* hyper_dmabuf_id of specific hyper_dmabuf */
+        int size; /* size of data */
+};
+
+struct hyper_dmabuf_event_data {
+        struct hyper_dmabuf_event_hdr hdr;
+        void *data; /* private data */
+};
+
+4. Hyper_DMABUF Private Data
+
+Each Hyper_DMABUF can come with private data, the size of which can be up to
+AX_SIZE_PRIV_DATA (currently 192 byte). This private data is just a chunk of
+plain data attached to every Hyper_DMABUF. It is guaranteed to be synchronized
+across VMs, exporter and importer. This private data does not have any specific
+structure defined at the driver level, so any “user-defined” format or
+structure can be used. In addition, there is no dedicated use-case for this
+data. It can be used virtually for any purpose. For example, it can be used to
+share meta-data such as dimension and color formats for shared images in
+a surface sharing model. Another example is when we share protected media
+contents.
+
+This private data can be used to transfer flags related to content protection
+information on streamed media to the importer.
+
+Private data is initially generated when a buffer is exported for the first
+time. Then, it is updated whenever the same buffer is re-exported. During the
+re-exporting process, the Hyper_DMABUF driver only updates private data on
+both sides with new data from user-space since the same buffer already exists
+on both the IMPORT LIST and EXPORT LIST.
+
+There are two different ways to retrieve this private data from user-space.
+The first way is to use “Read” on the Hyper_DMABUF driver. “Read” returns the
+data of events containing private data of the buffer. The second way is to
+make a query to Hyper_DMABUF. There are two query items,
+HYPER_DMABUF_QUERY_PRIV_INFO and HYPER_DMABUF_QUERY_PRIV_INFO_SIZE available
+for retrieving private data and its size.
+
+5. Scatter-Gather List Table (SGT) Management
+
+SGT management is the core part of the Hyper_DMABUF driver that manages an
+SGT, a representation of the group of kernel pages associated with a DMA_BUF.
+This block includes four different sub-blocks:
+
+a. Hyper_DMABUF_id Manager
+
+This ID manager is responsible for generating a hyper_dmabuf_id for an
+exported DMA_BUF. When an ID is requested, the ID Manager first checks if
+there are any reusable IDs left in the list and returns one of those,
+if available. Otherwise, it creates the next count number and returns it
+to the caller.
+
+b. SGT Creator
+
+The SGT (struct sg_table) contains information about the DMA_BUF such as
+references to all kernel pages for the buffer and their connections. The
+SGT Creator creates a new SGT on the importer side with pages shared by
+the hypervisor.
+
+c. Kernel Page Extractor
+
+The Page Extractor extracts pages from a given SGT before those pages
+are shared.
+
+d. List Manager Interface
+
+The SGT manger also interacts with export and import list managers. It
+sends out information (for example, hyper_dmabuf_id, reference, and
+DMA_BUF information) about the exported or imported DMA_BUFs to the
+list manager. Also, on IOCTL request, it asks the list manager to find
+and return the information for a corresponding DMA_BUF in the list.
+
+6. DMA-BUF Interface
+
+The DMA-BUF interface provides standard methods to manage DMA_BUFs
+reconstructed by the Hyper_DMABUF driver from shared pages. All of the
+relevant operations are listed in struct dma_buf_ops. These operations
+are standard DMA_BUF operations, therefore they follow standard DMA BUF
+protocols.
+
+Each DMA_BUF operation communicates with the exporter at the end of the
+routine for “indirect DMA_BUF synchronization”.
+
+7. Export/Import List Management
+
+Whenever a DMA_BUF is shared and exported, its information is added to the
+database (EXPORT-list) on the exporting VM. Similarly, information about an
+imported DMA_BUF is added to the importing database (IMPORT list) on the
+importing VM, when the export happens.
+
+All of the entries in the lists are needed to manage the exported/imported
+DMA_BUF more efficiently. Both lists are implemented as Linux hash tables.
+The key to the list is hyper_dmabuf_id and the output is the information of
+the DMA_BUF. The List Manager manages all requests from other blocks and
+transactions within lists to ensure that all entries are up-to-date and
+that the list structure is consistent.
+
+The List Manager provides basic functionality, such as:
+
+- Adding to the List
+- Removal from the List
+- Finding information about a DMA_BUF, given the hyper_dmabuf_id
+
+8. Page Sharing by Hypercalls
+
+The Hyper_DMABUF driver assumes that there is a native page-by-page memory
+sharing mechanism available on the hypervisor. Referencing a group of pages
+that are being shared is what the driver expects from “backend” APIs or the
+hypervisor itself.
+
+For the example, xen backend integrated in current code base utilizes Xen’s
+grant-table interface for sharing the underlying kernel pages (struct *page).
+
+ore details about grant-table interface can be found at the following locations:
+
+https://wiki.xen.org/wiki/Grant_Table
+https://xenbits.xen.org/docs/4.6-testing/misc/grant-tables.txt
+
+9. Message Management
+
+The exporter and importer can each create a message that consists of an opcode
+(command) and operands (parameters) and send it to each other.
+
+The message format is defined as:
+
+struct hyper_dmabuf_req {
+        unsigned int req_id; /* Sequence number. Used for RING BUF
+                                synchronization */
+        unsigned int stat; /* Status.Response from receiver. */
+        unsigned int cmd;  /* Opcode */
+        unsigned int op[MAX_NUMBER_OF_OPERANDS]; /* Operands */
+};
+
+The following table gives the list of opcodes:
+
+<Opcodes in Message to Exporter/Importer>
+
+HYPER_DMABUF_EXPORT (exporter --> importer)
+ - Export a DMA_BUF to the importer. The importer registers the corresponding
+   DMA_BUF in its IMPORT LIST when the message is received.
+
+HYPER_DMABUF_EXPORT_FD (importer --> exporter)
+ - Locally exported as FD. The importer sends out this command to the exporter
+   to notify that the buffer is now locally exported (mapped and used).
+
+HYPER_DMABUF_EXPORT_FD_FAILED (importer --> exporter)
+ - Failed while exporting locally. The importer sends out this command to the
+   exporter to notify the exporter that the EXPORT_FD failed.
+
+HYPER_DMABUF_NOTIFY_UNEXPORT (exporter --> importer)
+ - Termination of sharing. The exporter notifies the importer that the DMA_BUF
+   has been unexported.
+
+HYPER_DMABUF_OPS_TO_REMOTE (importer --> exporter)
+ - Not implemented yet.
+
+HYPER_DMABUF_OPS_TO_SOURCE (exporter --> importer)
+ - DMA_BUF ops to the exporter, for DMA_BUF upstream synchronization.
+   Note: Implemented but it is done asynchronously due to performance issues.
+
+The following table shows the list of operands for each opcode.
+
+<Operands in Message to Exporter/Importer>
+
+- HYPER_DMABUF_EXPORT
+
+op0 to op3 – hyper_dmabuf_id
+op4 – number of pages to be shared
+op5 – offset of data in the first page
+op6 – length of data in the last page
+op7 – reference number for the group of shared pages
+op8 – size of private data
+op9 to (op9+op8)  – private data
+
+- HYPER_DMABUF_EXPORT_FD
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_EXPORT_FD_FAILED
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_NOTIFY_UNEXPORT
+
+op0 to op3 – hyper_dmabuf_id
+
+- HYPER_DMABUF_OPS_TO_REMOTE(Not implemented)
+
+- HYPER_DMABUF_OPS_TO_SOURCE
+
+op0 to op3 – hyper_dmabuf_id
+op4 – type of DMA_BUF operation
+
+9. Inter VM (Domain) Communication
+
+Two different types of inter-domain communication channels are required,
+one in kernel space and the other in user space. The communication channel
+in user space is for transmitting or receiving the hyper_dmabuf_id. Since
+there is no specific security (for example, encryption) involved in the
+generation of a global id at the driver level, it is highly recommended that
+the customer’s user application set up a very secure channel for exchanging
+hyper_dmabuf_id between VMs.
+
+The communication channel in kernel space is required for exchanging messages
+from “message management” block between two VMs. In the current reference
+backend for Xen hypervisor, Xen ring-buffer and event-channel mechanisms are
+used for message exchange between impoter and exporter.
+
+10. What are required in hypervisor
+
+emory sharing and message communication between VMs
+
+------------------------------------------------------------------------------
+Section 3. Hyper DMABUF Sharing Flow
+------------------------------------------------------------------------------
+
+1. Exporting
+
+To export a DMA_BUF to another VM, user space has to call an IOCTL
+(IOCTL_HYPER_DMABUF_EXPORT_REMOTE) with a file descriptor for the buffer given
+by the original exporter. The Hyper_DMABUF driver maps a DMA_BUF locally, then
+issues a hyper_dmabuf_id and SGT for the DMA_BUF, which is registered to the
+EXPORT list. Then, all pages for the SGT are extracted and each individual
+page is shared via a hypervisor-specific memory sharing mechanism
+(for example, in Xen this is grant-table).
+
+One important requirement on this memory sharing method is that it needs to
+create a single integer value that represents the list of pages, which can
+then be used by the importer for retrieving the group of shared pages.  For
+this, the “Backend” in the reference driver utilizes the multiple level
+addressing mechanism.
+
+Once the integer reference to the list of pages is created, the exporter
+builds the “export” command and sends it to the importer, then notifies the
+importer.
+
+2. Importing
+
+The Import process is divided into two sections. One is the registration
+of DMA_BUF from the exporter. The other is the actual mapping of the buffer
+before accessing the data in the buffer. The former (termed “Registration”)
+happens on an export event (that is, the export command with an interrupt)
+in the exporter.
+
+The latter (termed “Mapping”) is done asynchronously when the driver gets the
+IOCTL call from user space. When the importer gets an interrupt from the
+exporter, it checks the command in the receiving queue and if it is an
+“export” command, the registration process is started. It first finds
+hyper_dmabuf_id and the integer reference for the shared pages, then stores
+all of that information together with the “domain id” of the exporting domain
+in the IMPORT LIST.
+
+In the case where “event-polling” is enabled (Kernel Config - Enable event-
+generation and polling operation), a “new sharing available” event is
+generated right after the reference info for the new shared DMA_BUF is
+registered to the IMPORT LIST. This event is added to the event-queue.
+
+The user process that polls Hyper_DMABUF driver wakes up when this event-queue
+is not empty and is able to read back event data from the queue using the
+driver’s “Read” function. Once the user-application calls EXPORT_FD IOCTL with
+the proper parameters including hyper_dmabuf_id, the Hyper_DMABUF driver
+retrieves information about the matched DMA_BUF from the IMPORT LIST. Then, it
+maps all pages shared (referenced by the integer reference) in its kernel
+space and creates its own DMA_BUF referencing the same shared pages. After
+this, it exports this new DMA_BUF to the other drivers with a file descriptor.
+DMA_BUF can then be used just in the same way a local DMA_BUF is.
+
+3. Indirect Synchronization of DMA_BUF
+
+Synchronization of a DMA_BUF within a single OS is automatically achieved
+because all of importer’s DMA_BUF operations are done using functions defined
+on the exporter’s side, which means there is one central place that has full
+control over the DMA_BUF. In other words, any primary activities such as
+attaching/detaching and mapping/un-mapping are all captured by the exporter,
+meaning that the exporter knows basic information such as who is using the
+DMA_BUF and how it is being used. This, however, is not applicable if this
+sharing is done beyond a single OS because kernel space (where the exporter’s
+DMA_BUF operations reside) is simply not visible to the importing VM.
+
+Therefore, “indirect synchronization” was introduced as an alternative solution,
+which is now implemented in the Hyper_DMABUF driver. This technique makes
+the exporter create a shadow DMA_BUF when the end-consumer of the buffer maps
+the DMA_BUF, then duplicates any DMA_BUF operations performed on
+the importer’s side. Through this “indirect synchronization”, the exporter is
+able to virtually track all activities done by the consumer (mostly reference
+counter) as if those are done in exporter’s local system.
+
+------------------------------------------------------------------------------
+Section 4. Hypervisor Backend Interface
+------------------------------------------------------------------------------
+
+The Hyper_DMABUF driver has a standard “Backend” structure that contains
+mappings to various functions designed for a specific Hypervisor. Most of
+these API functions should provide a low-level implementation of communication
+and memory sharing capability that utilize a Hypervisor’s native mechanisms.
+
+struct hyper_dmabuf_backend_ops {
+        /* retreiving id of current virtual machine */
+        int (*get_vm_id)(void);
+        /* get pages shared via hypervisor-specific method */
+        int (*share_pages)(struct page **, int, int, void **);
+        /* make shared pages unshared via hypervisor specific method */
+        int (*unshare_pages)(void **, int);
+        /* map remotely shared pages on importer's side via
+         *  hypervisor-specific method
+         */
+        struct page ** (*map_shared_pages)(int, int, int, void **);
+        /* unmap and free shared pages on importer's side via
+         *  hypervisor-specific method
+         */
+        int (*unmap_shared_pages)(void **, int);
+        /* initialize communication environment */
+        int (*init_comm_env)(void);
+        /* destroy communication channel */
+        void (*destroy_comm)(void);
+        /* upstream ch setup (receiving and responding) */
+        int (*init_rx_ch)(int);
+        /* downstream ch setup (transmitting and parsing responses) */
+        int (*init_tx_ch)(int);
+        /* send msg via communication ch */
+        int (*send_req)(int, struct hyper_dmabuf_req *, int);
+};
+
+<Hypervisor-specific Backend Structure>
+
+1. get_vm_id
+
+	Returns the VM (domain) ID
+
+	Input:
+
+		-ID of the current domain
+
+	Output:
+
+		None
+
+2. share_pages
+
+	Get pages shared via hypervisor-specific method and return one reference
+	ID that represents the complete list of shared pages
+
+	Input:
+
+		-Array of pages
+		-ID of importing VM
+		-Number of pages
+		-Hypervisor specific Representation of reference info of shared
+		 pages
+
+	Output:
+
+		-Hypervisor specific integer value that represents all of
+		 the shared pages
+
+3. unshare_pages
+
+	Stop sharing pages
+
+	Input:
+
+		-Hypervisor specific Representation of reference info of shared
+		 pages
+		-Number of shared pages
+
+	Output:
+
+		0
+
+4. map_shared_pages
+
+	Map shared pages locally using a hypervisor-specific method
+
+	Input:
+
+		-Reference number that represents all of shared pages
+		-ID of exporting VM, Number of pages
+		-Reference information for any purpose
+
+	Output:
+
+		-An array of shared pages (struct page**)
+
+5. unmap_shared_pages
+
+	Unmap shared pages
+
+	Input:
+
+		-Hypervisor specific Representation of reference info of shared pages
+
+	Output:
+
+		-0 (successful) or one of Standard Kernel errors
+
+6. init_comm_env
+
+	Setup infrastructure needed for communication channel
+
+	Input:
+
+		None
+
+	Output:
+
+		None
+
+7. destroy_comm
+
+	Cleanup everything done via init_comm_env
+
+	Input:
+
+		None
+
+	Output:
+
+		None
+
+8. init_rx_ch
+
+	Configure receive channel
+
+	Input:
+
+		-ID of VM on the other side of the channel
+
+	Output:
+
+		-0 (successful) or one of Standard Kernel errors
+
+9. init_tx_ch
+
+	Configure transmit channel
+
+	Input:
+
+		-ID of VM on the other side of the channel
+
+	Output:
+
+		-0 (success) or one of Standard Kernel errors
+
+10. send_req
+
+	Send message to other VM
+
+	Input:
+
+		-ID of VM that receives the message
+		-Message
+
+	Output:
+
+		-0 (success) or one of Standard Kernel errors
+
+-------------------------------------------------------------------------------
+-------------------------------------------------------------------------------
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

RFC PATCH 3/60 hyper_dmabuf: re-use dma_buf previously exported if exist

In reply to Dongwon Kim

Now we re-use dma_buf instead of exporting it via normal process (including new mappings). For this, hyper_dmabuf list entries can be searched with "struct dma_buf*". Also, ioctl (export_remote) is modified to just return hyper_dmabuf_id if the specific dmabuf has already been exported to the target domain.

This patch also Includes changes in printk calles for debugging.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 28 +++++++++++++--------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 17 ++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c  |  4 ++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h  |  2 +-
 4 files changed, 26 insertions(+), 25 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +14 -14
index faa5c1b..7cb5c35 100644
@@ -532,7 +532,7 @@ static int hyper_dmabuf_ops_attach(struct dma_buf* dmabuf, struct device* dev,
 						HYPER_DMABUF_OPS_ATTACH);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -552,7 +552,7 @@ static void hyper_dmabuf_ops_detach(struct dma_buf* dmabuf, struct dma_buf_attac
 						HYPER_DMABUF_OPS_DETACH);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -586,7 +586,7 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 						HYPER_DMABUF_OPS_MAP);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return st;
@@ -618,7 +618,7 @@ static void hyper_dmabuf_ops_unmap(struct dma_buf_attachment *attachment,
 						HYPER_DMABUF_OPS_UNMAP);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -636,7 +636,7 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dmabuf)
 						HYPER_DMABUF_OPS_RELEASE);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -653,7 +653,7 @@ static int hyper_dmabuf_ops_begin_cpu_access(struct dma_buf *dmabuf, enum dma_da
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -672,7 +672,7 @@ static int hyper_dmabuf_ops_end_cpu_access(struct dma_buf *dmabuf, enum dma_data
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_END_CPU_ACCESS);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return 0;
@@ -691,7 +691,7 @@ static void *hyper_dmabuf_ops_kmap_atomic(struct dma_buf *dmabuf, unsigned long
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KMAP_ATOMIC);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL; /* for now NULL.. need to return the address of mapped region */
@@ -710,7 +710,7 @@ static void hyper_dmabuf_ops_kunmap_atomic(struct dma_buf *dmabuf, unsigned long
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KUNMAP_ATOMIC);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -727,7 +727,7 @@ static void *hyper_dmabuf_ops_kmap(struct dma_buf *dmabuf, unsigned long pgnum)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL; /* for now NULL.. need to return the address of mapped region */
@@ -746,7 +746,7 @@ static void hyper_dmabuf_ops_kunmap(struct dma_buf *dmabuf, unsigned long pgnum,
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KUNMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -763,7 +763,7 @@ static int hyper_dmabuf_ops_mmap(struct dma_buf *dmabuf, struct vm_area_struct *
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_MMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -782,7 +782,7 @@ static void *hyper_dmabuf_ops_vmap(struct dma_buf *dmabuf)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_VMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL;
@@ -801,7 +801,7 @@ static void hyper_dmabuf_ops_vunmap(struct dma_buf *dmabuf, void *vaddr)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_VUNMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +9 -8
index 5e50908..665cada 100644
@@ -86,27 +86,28 @@ static int hyper_dmabuf_export_remote(void *data)
 	export_remote_attr = (struct ioctl_hyper_dmabuf_export_remote *)data;
 
 	dma_buf = dma_buf_get(export_remote_attr->dmabuf_fd);
+
 	if (!dma_buf) {
 		printk("Cannot get dma buf\n");
 		return -1;
 	}
 
-	attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device);
-	if (!attachment) {
-		printk("Cannot get attachment\n");
-		return -1;
-	}
-
 	/* we check if this specific attachment was already exported
 	 * to the same domain and if yes, it returns hyper_dmabuf_id
 	 * of pre-exported sgt */
-	ret = hyper_dmabuf_find_id(attachment, export_remote_attr->remote_domain);
+	ret = hyper_dmabuf_find_id(dma_buf, export_remote_attr->remote_domain);
 	if (ret != -1) {
-		dma_buf_detach(dma_buf, attachment);
 		dma_buf_put(dma_buf);
 		export_remote_attr->hyper_dmabuf_id = ret;
 		return 0;
 	}
+
+	attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device);
+	if (!attachment) {
+		printk("Cannot get attachment\n");
+		return -1;
+	}
+
 	/* Clear ret, as that will cause whole ioctl to return failure to userspace, which is not true */
 	ret = 0;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +2 -2
index 77a7e65..ad2109c 100644
@@ -65,13 +65,13 @@ struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id)
 }
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid)
+int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
 {
 	struct hyper_dmabuf_info_entry_exported *info_entry;
 	int bkt;
 
 	hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node)
-		if(info_entry->info->attachment == attach &&
+		if(info_entry->info->attachment->dmabuf == dmabuf &&
 			info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +1 -1
index 869cd9a..463a6da 100644
@@ -25,7 +25,7 @@ int hyper_dmabuf_table_destroy(void);
 int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid);
+int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid);
 
 int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

RFC PATCH 3/60 hyper_dmabuf: re-use dma_buf previously exported if exist

In reply to Dongwon Kim

Now we re-use dma_buf instead of exporting it via normal process (including new mappings). For this, hyper_dmabuf list entries can be searched with "struct dma_buf*". Also, ioctl (export_remote) is modified to just return hyper_dmabuf_id if the specific dmabuf has already been exported to the target domain.

This patch also Includes changes in printk calles for debugging.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 28 +++++++++++++--------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 17 ++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c  |  4 ++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h  |  2 +-
 4 files changed, 26 insertions(+), 25 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +14 -14
index faa5c1b..7cb5c35 100644
@@ -532,7 +532,7 @@ static int hyper_dmabuf_ops_attach(struct dma_buf* dmabuf, struct device* dev,
 						HYPER_DMABUF_OPS_ATTACH);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -552,7 +552,7 @@ static void hyper_dmabuf_ops_detach(struct dma_buf* dmabuf, struct dma_buf_attac
 						HYPER_DMABUF_OPS_DETACH);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -586,7 +586,7 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 						HYPER_DMABUF_OPS_MAP);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return st;
@@ -618,7 +618,7 @@ static void hyper_dmabuf_ops_unmap(struct dma_buf_attachment *attachment,
 						HYPER_DMABUF_OPS_UNMAP);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -636,7 +636,7 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dmabuf)
 						HYPER_DMABUF_OPS_RELEASE);
 
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -653,7 +653,7 @@ static int hyper_dmabuf_ops_begin_cpu_access(struct dma_buf *dmabuf, enum dma_da
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -672,7 +672,7 @@ static int hyper_dmabuf_ops_end_cpu_access(struct dma_buf *dmabuf, enum dma_data
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_END_CPU_ACCESS);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return 0;
@@ -691,7 +691,7 @@ static void *hyper_dmabuf_ops_kmap_atomic(struct dma_buf *dmabuf, unsigned long
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KMAP_ATOMIC);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL; /* for now NULL.. need to return the address of mapped region */
@@ -710,7 +710,7 @@ static void hyper_dmabuf_ops_kunmap_atomic(struct dma_buf *dmabuf, unsigned long
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KUNMAP_ATOMIC);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -727,7 +727,7 @@ static void *hyper_dmabuf_ops_kmap(struct dma_buf *dmabuf, unsigned long pgnum)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL; /* for now NULL.. need to return the address of mapped region */
@@ -746,7 +746,7 @@ static void hyper_dmabuf_ops_kunmap(struct dma_buf *dmabuf, unsigned long pgnum,
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_KUNMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
@@ -763,7 +763,7 @@ static int hyper_dmabuf_ops_mmap(struct dma_buf *dmabuf, struct vm_area_struct *
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_MMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return ret;
@@ -782,7 +782,7 @@ static void *hyper_dmabuf_ops_vmap(struct dma_buf *dmabuf)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_VMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	return NULL;
@@ -801,7 +801,7 @@ static void hyper_dmabuf_ops_vunmap(struct dma_buf *dmabuf, void *vaddr)
 	ret = hyper_dmabuf_sync_request_and_wait(HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(sgt_info->hyper_dmabuf_id),
 						HYPER_DMABUF_OPS_VUNMAP);
 	if (ret < 0) {
-		printk("send dmabuf sync request failed\n");
+		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +9 -8
index 5e50908..665cada 100644
@@ -86,27 +86,28 @@ static int hyper_dmabuf_export_remote(void *data)
 	export_remote_attr = (struct ioctl_hyper_dmabuf_export_remote *)data;
 
 	dma_buf = dma_buf_get(export_remote_attr->dmabuf_fd);
+
 	if (!dma_buf) {
 		printk("Cannot get dma buf\n");
 		return -1;
 	}
 
-	attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device);
-	if (!attachment) {
-		printk("Cannot get attachment\n");
-		return -1;
-	}
-
 	/* we check if this specific attachment was already exported
 	 * to the same domain and if yes, it returns hyper_dmabuf_id
 	 * of pre-exported sgt */
-	ret = hyper_dmabuf_find_id(attachment, export_remote_attr->remote_domain);
+	ret = hyper_dmabuf_find_id(dma_buf, export_remote_attr->remote_domain);
 	if (ret != -1) {
-		dma_buf_detach(dma_buf, attachment);
 		dma_buf_put(dma_buf);
 		export_remote_attr->hyper_dmabuf_id = ret;
 		return 0;
 	}
+
+	attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device);
+	if (!attachment) {
+		printk("Cannot get attachment\n");
+		return -1;
+	}
+
 	/* Clear ret, as that will cause whole ioctl to return failure to userspace, which is not true */
 	ret = 0;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +2 -2
index 77a7e65..ad2109c 100644
@@ -65,13 +65,13 @@ struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id)
 }
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid)
+int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
 {
 	struct hyper_dmabuf_info_entry_exported *info_entry;
 	int bkt;
 
 	hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node)
-		if(info_entry->info->attachment == attach &&
+		if(info_entry->info->attachment->dmabuf == dmabuf &&
 			info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +1 -1
index 869cd9a..463a6da 100644
@@ -25,7 +25,7 @@ int hyper_dmabuf_table_destroy(void);
 int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf_attachment *attach, int domid);
+int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid);
 
 int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

RFC PATCH 4/60 hyper_dmabuf: new index, k for pointing a right n-th page

In reply to Dongwon Kim

Need a new index, k in hyper_dmabuf_extract_pgs function for picking up a correct n-th page in contigous memory space.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +6 -5
index 7cb5c35..3b40ec0 100644
@@ -39,7 +39,7 @@ static int hyper_dmabuf_get_num_pgs(struct sg_table *sgt)
 struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 {
 	struct hyper_dmabuf_pages_info *pinfo;
-	int i, j;
+	int i, j, k;
 	int length;
 	struct scatterlist *sgl;
 
@@ -57,7 +57,7 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 	pinfo->frst_ofst = sgl->offset;
 	pinfo->pages[0] = sg_page(sgl);
 	length = sgl->length - PAGE_SIZE + sgl->offset;
-	i=1;
+	i = 1;
 
 	while (length > 0) {
 		pinfo->pages[i] = nth_page(sg_page(sgl), i);
@@ -71,12 +71,12 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 		pinfo->pages[i++] = sg_page(sgl);
 		length = sgl->length - PAGE_SIZE;
 		pinfo->nents++;
+		k = 1;
 
 		while (length > 0) {
-			pinfo->pages[i] = nth_page(sg_page(sgl), i);
+			pinfo->pages[i++] = nth_page(sg_page(sgl), k++);
 			length -= PAGE_SIZE;
 			pinfo->nents++;
-			i++;
 		}
 	}
 
@@ -535,7 +535,8 @@ static int hyper_dmabuf_ops_attach(struct dma_buf* dmabuf, struct device* dev,
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
-	return ret;
+	/* Ignoring ret for now */
+	return 0;
 }
 
 static void hyper_dmabuf_ops_detach(struct dma_buf* dmabuf, struct dma_buf_attachment *attach)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

RFC PATCH 4/60 hyper_dmabuf: new index, k for pointing a right n-th page

In reply to Dongwon Kim

Need a new index, k in hyper_dmabuf_extract_pgs function for picking up a correct n-th page in contigous memory space.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +6 -5
index 7cb5c35..3b40ec0 100644
@@ -39,7 +39,7 @@ static int hyper_dmabuf_get_num_pgs(struct sg_table *sgt)
 struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 {
 	struct hyper_dmabuf_pages_info *pinfo;
-	int i, j;
+	int i, j, k;
 	int length;
 	struct scatterlist *sgl;
 
@@ -57,7 +57,7 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 	pinfo->frst_ofst = sgl->offset;
 	pinfo->pages[0] = sg_page(sgl);
 	length = sgl->length - PAGE_SIZE + sgl->offset;
-	i=1;
+	i = 1;
 
 	while (length > 0) {
 		pinfo->pages[i] = nth_page(sg_page(sgl), i);
@@ -71,12 +71,12 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 		pinfo->pages[i++] = sg_page(sgl);
 		length = sgl->length - PAGE_SIZE;
 		pinfo->nents++;
+		k = 1;
 
 		while (length > 0) {
-			pinfo->pages[i] = nth_page(sg_page(sgl), i);
+			pinfo->pages[i++] = nth_page(sg_page(sgl), k++);
 			length -= PAGE_SIZE;
 			pinfo->nents++;
-			i++;
 		}
 	}
 
@@ -535,7 +535,8 @@ static int hyper_dmabuf_ops_attach(struct dma_buf* dmabuf, struct device* dev,
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
-	return ret;
+	/* Ignoring ret for now */
+	return 0;
 }
 
 static void hyper_dmabuf_ops_detach(struct dma_buf* dmabuf, struct dma_buf_attachment *attach)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

RFC PATCH 5/60 hyper_dmabuf: skip creating a comm ch if exist for the VM

In reply to Dongwon Kim

hyper_dmabuf_importer_ring_setup creates new channel only if there is no existing downstream communication channel previously created for the exporter VM.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 13 +++++++------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +7 -6
index 3b40ec0..6b16e37 100644
@@ -827,12 +827,11 @@ static const struct dma_buf_ops hyper_dmabuf_ops = {
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags)
 {
 	int fd;
-
 	struct dma_buf* dmabuf;
 
-/* call hyper_dmabuf_export_dmabuf and create and bind a handle for it
- * then release */
-
+	/* call hyper_dmabuf_export_dmabuf and create
+	 * and bind a handle for it then release
+	 */
 	dmabuf = hyper_dmabuf_export_dma_buf(dinfo);
 
 	fd = dma_buf_fd(dmabuf, flags);
@@ -845,9 +844,11 @@ struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_inf
 	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
 
 	exp_info.ops = &hyper_dmabuf_ops;
-	exp_info.size = dinfo->sgt->nents * PAGE_SIZE; /* multiple of PAGE_SIZE, not considering offset */
+
+	/* multiple of PAGE_SIZE, not considering offset */
+	exp_info.size = dinfo->sgt->nents * PAGE_SIZE;
 	exp_info.flags = /* not sure about flag */0;
 	exp_info.priv = dinfo;
 
 	return dma_buf_export(&exp_info);
-};
+}
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +20 -0
index 665cada..90e0c65 100644
@@ -12,6 +12,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_query.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
+#include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "hyper_dmabuf_msg.h"
 
 struct hyper_dmabuf_private {
@@ -31,6 +32,7 @@ static uint32_t hyper_dmabuf_id_gen(void) {
 static int hyper_dmabuf_exporter_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_exporter_ring_setup *ring_attr;
+	struct hyper_dmabuf_ring_info_export *ring_info;
 	int ret = 0;
 
 	if (!data) {
@@ -39,6 +41,15 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 	}
 	ring_attr = (struct ioctl_hyper_dmabuf_exporter_ring_setup *)data;
 
+	/* check if the ring ch already exists */
+	ring_info = hyper_dmabuf_find_exporter_ring(ring_attr->remote_domain);
+
+	if (ring_info) {
+		printk("(exporter's) ring ch to domid = %d already exist\ngref = %d, port = %d\n",
+			ring_info->rdomain, ring_info->gref_ring, ring_info->port);
+		return 0;
+	}
+
 	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain,
 						&ring_attr->ring_refid,
 						&ring_attr->port);
@@ -49,6 +60,7 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 static int hyper_dmabuf_importer_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_importer_ring_setup *setup_imp_ring_attr;
+	struct hyper_dmabuf_ring_info_import *ring_info;
 	int ret = 0;
 
 	if (!data) {
@@ -58,6 +70,14 @@ static int hyper_dmabuf_importer_ring_setup(void *data)
 
 	setup_imp_ring_attr = (struct ioctl_hyper_dmabuf_importer_ring_setup *)data;
 
+	/* check if the ring ch already exist */
+	ring_info = hyper_dmabuf_find_importer_ring(setup_imp_ring_attr->source_domain);
+
+	if (ring_info) {
+		printk("(importer's) ring ch to domid = %d already exist\n", ring_info->sdomain);
+		return 0;
+	}
+
 	/* user need to provide a port number and ref # for the page used as ring buffer */
 	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain,
 						 setup_imp_ring_attr->ring_refid,
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

RFC PATCH 5/60 hyper_dmabuf: skip creating a comm ch if exist for the VM

In reply to Dongwon Kim

hyper_dmabuf_importer_ring_setup creates new channel only if there is no existing downstream communication channel previously created for the exporter VM.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 13 +++++++------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +7 -6
index 3b40ec0..6b16e37 100644
@@ -827,12 +827,11 @@ static const struct dma_buf_ops hyper_dmabuf_ops = {
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags)
 {
 	int fd;
-
 	struct dma_buf* dmabuf;
 
-/* call hyper_dmabuf_export_dmabuf and create and bind a handle for it
- * then release */
-
+	/* call hyper_dmabuf_export_dmabuf and create
+	 * and bind a handle for it then release
+	 */
 	dmabuf = hyper_dmabuf_export_dma_buf(dinfo);
 
 	fd = dma_buf_fd(dmabuf, flags);
@@ -845,9 +844,11 @@ struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_inf
 	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
 
 	exp_info.ops = &hyper_dmabuf_ops;
-	exp_info.size = dinfo->sgt->nents * PAGE_SIZE; /* multiple of PAGE_SIZE, not considering offset */
+
+	/* multiple of PAGE_SIZE, not considering offset */
+	exp_info.size = dinfo->sgt->nents * PAGE_SIZE;
 	exp_info.flags = /* not sure about flag */0;
 	exp_info.priv = dinfo;
 
 	return dma_buf_export(&exp_info);
-};
+}
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +20 -0
index 665cada..90e0c65 100644
@@ -12,6 +12,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_query.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
+#include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "hyper_dmabuf_msg.h"
 
 struct hyper_dmabuf_private {
@@ -31,6 +32,7 @@ static uint32_t hyper_dmabuf_id_gen(void) {
 static int hyper_dmabuf_exporter_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_exporter_ring_setup *ring_attr;
+	struct hyper_dmabuf_ring_info_export *ring_info;
 	int ret = 0;
 
 	if (!data) {
@@ -39,6 +41,15 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 	}
 	ring_attr = (struct ioctl_hyper_dmabuf_exporter_ring_setup *)data;
 
+	/* check if the ring ch already exists */
+	ring_info = hyper_dmabuf_find_exporter_ring(ring_attr->remote_domain);
+
+	if (ring_info) {
+		printk("(exporter's) ring ch to domid = %d already exist\ngref = %d, port = %d\n",
+			ring_info->rdomain, ring_info->gref_ring, ring_info->port);
+		return 0;
+	}
+
 	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain,
 						&ring_attr->ring_refid,
 						&ring_attr->port);
@@ -49,6 +60,7 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 static int hyper_dmabuf_importer_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_importer_ring_setup *setup_imp_ring_attr;
+	struct hyper_dmabuf_ring_info_import *ring_info;
 	int ret = 0;
 
 	if (!data) {
@@ -58,6 +70,14 @@ static int hyper_dmabuf_importer_ring_setup(void *data)
 
 	setup_imp_ring_attr = (struct ioctl_hyper_dmabuf_importer_ring_setup *)data;
 
+	/* check if the ring ch already exist */
+	ring_info = hyper_dmabuf_find_importer_ring(setup_imp_ring_attr->source_domain);
+
+	if (ring_info) {
+		printk("(importer's) ring ch to domid = %d already exist\n", ring_info->sdomain);
+		return 0;
+	}
+
 	/* user need to provide a port number and ref # for the page used as ring buffer */
 	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain,
 						 setup_imp_ring_attr->ring_refid,
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

RFC PATCH 6/60 hyper_dmabuf: map shared pages only once when importing.

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

If shared pages of buffer were already mapped on importer side, do not map them again on next request to export fd.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +11 -9
index 90e0c65..af94359 100644
@@ -203,7 +203,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 
 	if (!data) {
 		printk("user data is NULL\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	export_fd_attr = (struct ioctl_hyper_dmabuf_export_fd *)data;
@@ -218,15 +218,17 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 		imported_sgt_info->last_len, imported_sgt_info->nents,
 		HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id));
 
-	imported_sgt_info->sgt = hyper_dmabuf_map_pages(imported_sgt_info->gref,
-						imported_sgt_info->frst_ofst,
-						imported_sgt_info->last_len,
-						imported_sgt_info->nents,
-						HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id),
-						&imported_sgt_info->shared_pages_info);
-
 	if (!imported_sgt_info->sgt) {
-		return -1;
+		imported_sgt_info->sgt = hyper_dmabuf_map_pages(imported_sgt_info->gref,
+							imported_sgt_info->frst_ofst,
+							imported_sgt_info->last_len,
+							imported_sgt_info->nents,
+							HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id),
+							&imported_sgt_info->shared_pages_info);
+		if (!imported_sgt_info->sgt) {
+			printk("Failed to create sgt\n");
+			return -EINVAL;
+		}
 	}
 
 	export_fd_attr->fd = hyper_dmabuf_export_fd(imported_sgt_info, export_fd_attr->flags);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

RFC PATCH 6/60 hyper_dmabuf: map shared pages only once when importing.

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

If shared pages of buffer were already mapped on importer side, do not map them again on next request to export fd.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +11 -9
index 90e0c65..af94359 100644
@@ -203,7 +203,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 
 	if (!data) {
 		printk("user data is NULL\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	export_fd_attr = (struct ioctl_hyper_dmabuf_export_fd *)data;
@@ -218,15 +218,17 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 		imported_sgt_info->last_len, imported_sgt_info->nents,
 		HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id));
 
-	imported_sgt_info->sgt = hyper_dmabuf_map_pages(imported_sgt_info->gref,
-						imported_sgt_info->frst_ofst,
-						imported_sgt_info->last_len,
-						imported_sgt_info->nents,
-						HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id),
-						&imported_sgt_info->shared_pages_info);
-
 	if (!imported_sgt_info->sgt) {
-		return -1;
+		imported_sgt_info->sgt = hyper_dmabuf_map_pages(imported_sgt_info->gref,
+							imported_sgt_info->frst_ofst,
+							imported_sgt_info->last_len,
+							imported_sgt_info->nents,
+							HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(imported_sgt_info->hyper_dmabuf_id),
+							&imported_sgt_info->shared_pages_info);
+		if (!imported_sgt_info->sgt) {
+			printk("Failed to create sgt\n");
+			return -EINVAL;
+		}
 	}
 
 	export_fd_attr->fd = hyper_dmabuf_export_fd(imported_sgt_info, export_fd_attr->flags);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

RFC PATCH 7/60 hyper_dmabuf: message parsing done via workqueue

In reply to Dongwon Kim

Use workqueue mechanism to delay message parsing done after exiting from ISR to reduce ISR execution time.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  13 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |   5 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |   4 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 155 ++++++++++++++-------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  75 ++++------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |   7 -
 6 files changed, 152 insertions(+), 107 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +13 -0
index 0698327..70b4878 100644
@@ -1,5 +1,8 @@
 #include <linux/init.h>       /* module_init, module_exit */
 #include <linux/module.h> /* version info, MODULE_LICENSE, MODULE_AUTHOR, printk() */
+#include <linux/workqueue.h>
+#include <xen/grant_table.h>
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
@@ -10,6 +13,8 @@ MODULE_AUTHOR("IOTG-PED, INTEL");
 int register_device(void);
 int unregister_device(void);
 
+struct hyper_dmabuf_private hyper_dmabuf_private;
+
 /*===============================================================================================*/
 static int hyper_dmabuf_drv_init(void)
 {
@@ -24,6 +29,10 @@ static int hyper_dmabuf_drv_init(void)
 
 	printk( KERN_NOTICE "initializing database for imported/exported dmabufs\n");
 
+	/* device structure initialization */
+	/* currently only does work-queue initialization */
+	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
+
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
 		return -EINVAL;
@@ -45,6 +54,10 @@ static void hyper_dmabuf_drv_exit(void)
 	hyper_dmabuf_table_destroy();
 	hyper_dmabuf_ring_table_init();
 
+	/* destroy workqueue */
+	if (hyper_dmabuf_private.work_queue)
+		destroy_workqueue(hyper_dmabuf_private.work_queue);
+
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +5 -0
index 2dad9a6..6145d29 100644
@@ -1,6 +1,11 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
+struct hyper_dmabuf_private {
+        struct device *device;
+	struct workqueue_struct *work_queue;
+};
+
 typedef int (*hyper_dmabuf_ioctl_t)(void *data);
 
 struct hyper_dmabuf_ioctl_desc {
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +1 -3
index af94359..e4d8316 100644
@@ -15,9 +15,7 @@
 #include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "hyper_dmabuf_msg.h"
 
-struct hyper_dmabuf_private {
-	struct device *device;
-} hyper_dmabuf_private;
+extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
 static uint32_t hyper_dmabuf_id_gen(void) {
 	/* TODO: add proper implementation */
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +103 -52

199 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +30 -45

161 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +0 -7
index 2754917..4ad0529 100644
@@ -36,17 +36,10 @@ struct hyper_dmabuf_ring_info_import {
         struct hyper_dmabuf_back_ring ring_back;
 };
 
-//struct hyper_dmabuf_work {
-//	hyper_dmabuf_ring_rq requrest;
-//	struct work_struct msg_parse;
-//};
-
 int32_t hyper_dmabuf_get_domid(void);
 
 int hyper_dmabuf_next_req_id_export(void);
 
-int hyper_dmabuf_next_req_id_import(void);
-
 /* exporter needs to generated info for page sharing */
 int hyper_dmabuf_exporter_ringbuf_init(int rdomain, grant_ref_t *gref, int *port);
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

RFC PATCH 7/60 hyper_dmabuf: message parsing done via workqueue

In reply to Dongwon Kim

Use workqueue mechanism to delay message parsing done after exiting from ISR to reduce ISR execution time.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  13 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |   5 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |   4 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 155 ++++++++++++++-------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  75 ++++------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |   7 -
 6 files changed, 152 insertions(+), 107 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +13 -0
index 0698327..70b4878 100644
@@ -1,5 +1,8 @@
 #include <linux/init.h>       /* module_init, module_exit */
 #include <linux/module.h> /* version info, MODULE_LICENSE, MODULE_AUTHOR, printk() */
+#include <linux/workqueue.h>
+#include <xen/grant_table.h>
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
@@ -10,6 +13,8 @@ MODULE_AUTHOR("IOTG-PED, INTEL");
 int register_device(void);
 int unregister_device(void);
 
+struct hyper_dmabuf_private hyper_dmabuf_private;
+
 /*===============================================================================================*/
 static int hyper_dmabuf_drv_init(void)
 {
@@ -24,6 +29,10 @@ static int hyper_dmabuf_drv_init(void)
 
 	printk( KERN_NOTICE "initializing database for imported/exported dmabufs\n");
 
+	/* device structure initialization */
+	/* currently only does work-queue initialization */
+	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
+
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
 		return -EINVAL;
@@ -45,6 +54,10 @@ static void hyper_dmabuf_drv_exit(void)
 	hyper_dmabuf_table_destroy();
 	hyper_dmabuf_ring_table_init();
 
+	/* destroy workqueue */
+	if (hyper_dmabuf_private.work_queue)
+		destroy_workqueue(hyper_dmabuf_private.work_queue);
+
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +5 -0
index 2dad9a6..6145d29 100644
@@ -1,6 +1,11 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
+struct hyper_dmabuf_private {
+        struct device *device;
+	struct workqueue_struct *work_queue;
+};
+
 typedef int (*hyper_dmabuf_ioctl_t)(void *data);
 
 struct hyper_dmabuf_ioctl_desc {
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +1 -3
index af94359..e4d8316 100644
@@ -15,9 +15,7 @@
 #include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "hyper_dmabuf_msg.h"
 
-struct hyper_dmabuf_private {
-	struct device *device;
-} hyper_dmabuf_private;
+extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
 static uint32_t hyper_dmabuf_id_gen(void) {
 	/* TODO: add proper implementation */
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +103 -52

199 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +30 -45

161 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +0 -7
index 2754917..4ad0529 100644
@@ -36,17 +36,10 @@ struct hyper_dmabuf_ring_info_import {
         struct hyper_dmabuf_back_ring ring_back;
 };
 
-//struct hyper_dmabuf_work {
-//	hyper_dmabuf_ring_rq requrest;
-//	struct work_struct msg_parse;
-//};
-
 int32_t hyper_dmabuf_get_domid(void);
 
 int hyper_dmabuf_next_req_id_export(void);
 
-int hyper_dmabuf_next_req_id_import(void);
-
 /* exporter needs to generated info for page sharing */
 int hyper_dmabuf_exporter_ringbuf_init(int rdomain, grant_ref_t *gref, int *port);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

RFC PATCH 8/60 hyper_dmabuf: automatic comm channel initialization using xenstore

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

This introduces use of xenstore for creating and managing communication channels between two VMs in the system.

When hyper_dmabuf driver is loaded in the service VM (host OS), a new xenstore directory, "/local/domain/<domid>/data/hyper_dmabuf" is created in xenstore filesystem. Whenever a new guest OS creates and initailizes its own upstream channel the service VM, new directory is created under the main directory created above as shown here:

/local/domain/<domid>/data/hyper_dmabuf/<remote domid>/port /local/domain/<domid>/data/hyper_dmabuf/<remote domid>/gref

This patch also adds a "xenstore watch" callback is called when a new upstream connection is made from another VM (VM-b). Upon detection, this VM (VM-a) intializes a downstream channel ,paired with detected upstream connection as shown below.

VM-a (downstream) <----- (upstream) VM-a

And as soon as this downstream channel is created, a new upstream channel from VM-a to VM-b is automatically created and initialized via "xenstore watch" call back on VM-b.

VM-a (upstream) <----- (downstream) VM-b

As a result, there will be bi-directional communication channel available between two VMs.

When upstream channel is removed (e.g. unloading driver), VM on the other side is notified and "xenstore watch" callback is invoked. Via this callback, VM can remove corresponding downstream channel.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  11 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  14 --
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  30 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  31 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |   2 -
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 226 +++++++++++++++++++--
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |  18 +-
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  22 ++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h  |   6 +
 9 files changed, 270 insertions(+), 90 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +10 -1
index 70b4878..5b5dae44 100644
@@ -6,6 +6,7 @@
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
+#include "xen/hyper_dmabuf_xen_comm.h"
 
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("IOTG-PED, INTEL");
@@ -43,6 +44,11 @@ static int hyper_dmabuf_drv_init(void)
 		return -EINVAL;
 	}
 
+	ret = hyper_dmabuf_setup_data_dir();
+	if (ret < 0) {
+		return -EINVAL;
+	}
+
 	/* interrupt for comm should be registered here: */
 	return ret;
 }
@@ -52,12 +58,15 @@ static void hyper_dmabuf_drv_exit(void)
 {
 	/* hash tables for export/import entries and ring_infos */
 	hyper_dmabuf_table_destroy();
-	hyper_dmabuf_ring_table_init();
+
+	hyper_dmabuf_cleanup_ringbufs();
+	hyper_dmabuf_ring_table_destroy();
 
 	/* destroy workqueue */
 	if (hyper_dmabuf_private.work_queue)
 		destroy_workqueue(hyper_dmabuf_private.work_queue);
 
+	hyper_dmabuf_destroy_data_dir();
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +0 -14
index 6145d29..7511afb 100644
@@ -29,8 +29,6 @@ struct ioctl_hyper_dmabuf_exporter_ring_setup {
 	/* IN parameters */
 	/* Remote domain id */
 	uint32_t remote_domain;
-	grant_ref_t ring_refid; /* assigned by driver, copied to userspace after initialization */
-	uint32_t port; /* assigned by driver, copied to userspace after initialization */
 };
 
 #define IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP \
@@ -39,10 +37,6 @@ struct ioctl_hyper_dmabuf_importer_ring_setup {
 	/* IN parameters */
 	/* Source domain id */
 	uint32_t source_domain;
-	/* Ring shared page refid */
-	grant_ref_t ring_refid;
-	/* Port number */
-	uint32_t port;
 };
 
 #define IOCTL_HYPER_DMABUF_EXPORT_REMOTE \
@@ -95,12 +89,4 @@ struct ioctl_hyper_dmabuf_query {
 	uint32_t info;
 };
 
-#define IOCTL_HYPER_DMABUF_REMOTE_EXPORTER_RING_SETUP \
-_IOC(_IOC_NONE, 'G', 6, sizeof(struct ioctl_hyper_dmabuf_remote_exporter_ring_setup))
-struct ioctl_hyper_dmabuf_remote_exporter_ring_setup {
-	/* in parameters */
-	uint32_t rdomain; /* id of remote domain where exporter's ring need to be setup */
-	uint32_t info;
-};
-
 #endif //__LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +2 -28
index e4d8316..44a153b 100644
@@ -48,9 +48,7 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 		return 0;
 	}
 
-	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain,
-						&ring_attr->ring_refid,
-						&ring_attr->port);
+	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain);
 
 	return ret;
 }
@@ -76,10 +74,7 @@ static int hyper_dmabuf_importer_ring_setup(void *data)
 		return 0;
 	}
 
-	/* user need to provide a port number and ref # for the page used as ring buffer */
-	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain,
-						 setup_imp_ring_attr->ring_refid,
-						 setup_imp_ring_attr->port);
+	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain);
 
 	return ret;
 }
@@ -355,26 +350,6 @@ static int hyper_dmabuf_query(void *data)
 	return ret;
 }
 
-static int hyper_dmabuf_remote_exporter_ring_setup(void *data)
-{
-	struct ioctl_hyper_dmabuf_remote_exporter_ring_setup *remote_exporter_ring_setup;
-	struct hyper_dmabuf_ring_rq *req;
-
-	remote_exporter_ring_setup = (struct ioctl_hyper_dmabuf_remote_exporter_ring_setup *)data;
-
-	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORTER_RING_SETUP, NULL);
-
-	/* requesting remote domain to set-up exporter's ring */
-	if(hyper_dmabuf_send_request(remote_exporter_ring_setup->rdomain, req) < 0) {
-		kfree(req);
-		return -EINVAL;
-	}
-
-	kfree(req);
-	return 0;
-}
-
 static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORTER_RING_SETUP, hyper_dmabuf_exporter_ring_setup, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP, hyper_dmabuf_importer_ring_setup, 0),
@@ -382,7 +357,6 @@ static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_FD, hyper_dmabuf_export_fd_ioctl, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_DESTROY, hyper_dmabuf_destroy, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query, 0),
-	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_REMOTE_EXPORTER_RING_SETUP, hyper_dmabuf_remote_exporter_ring_setup, 0),
 };
 
 static long hyper_dmabuf_ioctl(struct file *filp,
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +1 -30
index 0166e61..8a059c8 100644
@@ -70,12 +70,6 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 			request->operands[i] = operands[i];
 		break;
 
-	/* requesting the other side to setup another ring channel for reverse direction */
-	case HYPER_DMABUF_EXPORTER_RING_SETUP:
-		/* command : HYPER_DMABUF_EXPORTER_RING_SETUP */
-		/* no operands needed */
-		break;
-
 	default:
 		/* no command found */
 		return;
@@ -163,13 +157,6 @@ void cmd_process_work(struct work_struct *work)
 		 */
 		break;
 
-	case HYPER_DMABUF_IMPORTER_RING_SETUP:
-		/* command: HYPER_DMABUF_IMPORTER_RING_SETUP */
-		/* no operands needed */
-		hyper_dmabuf_importer_ringbuf_init(domid, req->operands[0], req->operands[1]);
-
-		break;
-
 	default:
 		/* shouldn't get here */
 		/* no matched command, nothing to do.. just return error */
@@ -185,7 +172,6 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 	struct cmd_process *proc;
 	struct hyper_dmabuf_ring_rq *temp_req;
 	struct hyper_dmabuf_imported_sgt_info *imported_sgt_info;
-	int ret;
 
 	if (!req) {
 		printk("request is NULL\n");
@@ -193,28 +179,13 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 	}
 
 	if ((req->command < HYPER_DMABUF_EXPORT) ||
-		(req->command > HYPER_DMABUF_IMPORTER_RING_SETUP)) {
+		(req->command > HYPER_DMABUF_OPS_TO_SOURCE)) {
 		printk("invalid command\n");
 		return -EINVAL;
 	}
 
 	req->status = HYPER_DMABUF_REQ_PROCESSED;
 
-	/* HYPER_DMABUF_EXPORTER_RING_SETUP requires immediate
-	 * follow up so can't be processed in workqueue
-	 */
-	if (req->command == HYPER_DMABUF_EXPORTER_RING_SETUP) {
-		ret = hyper_dmabuf_exporter_ringbuf_init(domid, &req->operands[0], &req->operands[1]);
-		if (ret < 0) {
-			req->status = HYPER_DMABUF_REQ_ERROR;
-		}
-
-		req->status = HYPER_DMABUF_REQ_NEEDS_FOLLOW_UP;
-		req->command = HYPER_DMABUF_IMPORTER_RING_SETUP;
-
-		return req->command;
-	}
-
 	/* HYPER_DMABUF_DESTROY requires immediate
 	 * follow up so can't be processed in workqueue
 	 */
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +0 -2
index 44bfb70..9b25bdb 100644
@@ -7,8 +7,6 @@ enum hyper_dmabuf_command {
 	HYPER_DMABUF_DESTROY_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
-	HYPER_DMABUF_EXPORTER_RING_SETUP, /* requesting remote domain to set up exporter's ring */
-	HYPER_DMABUF_IMPORTER_RING_SETUP, /* requesting remote domain to set up importer's ring */
 };
 
 enum hyper_dmabuf_ops {
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +213 -13

302 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +16 -2
index 4ad0529..a4819ca 100644
@@ -2,6 +2,7 @@
 #define __HYPER_DMABUF_XEN_COMM_H__
 
 #include "xen/interface/io/ring.h"
+#include "xen/xenbus.h"
 
 #define MAX_NUMBER_OF_OPERANDS 9
 
@@ -27,6 +28,7 @@ struct hyper_dmabuf_ring_info_export {
         int gref_ring;
         int irq;
         int port;
+	struct xenbus_watch watch;
 };
 
 struct hyper_dmabuf_ring_info_import {
@@ -34,17 +36,29 @@ struct hyper_dmabuf_ring_info_import {
         int irq;
         int evtchn;
         struct hyper_dmabuf_back_ring ring_back;
+	struct gnttab_unmap_grant_ref unmap_op;
 };
 
 int32_t hyper_dmabuf_get_domid(void);
+int32_t hyper_dmabuf_setup_data_dir(void);
+int32_t hyper_dmabuf_destroy_data_dir(void);
 
 int hyper_dmabuf_next_req_id_export(void);
 
 /* exporter needs to generated info for page sharing */
-int hyper_dmabuf_exporter_ringbuf_init(int rdomain, grant_ref_t *gref, int *port);
+int hyper_dmabuf_exporter_ringbuf_init(int rdomain);
 
 /* importer needs to know about shared page and port numbers for ring buffer and event channel */
-int hyper_dmabuf_importer_ringbuf_init(int sdomain, grant_ref_t gref, int port);
+int hyper_dmabuf_importer_ringbuf_init(int sdomain);
+
+/* cleans up exporter ring created for given domain */
+void hyper_dmabuf_exporter_ringbuf_cleanup(int rdomain);
+
+/* cleans up importer ring created for given domain */
+void hyper_dmabuf_importer_ringbuf_cleanup(int sdomain);
+
+/* cleans up all exporter/importer rings */
+void hyper_dmabuf_cleanup_ringbufs(void);
 
 /* send request to the remote domain */
 int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req);
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +22 -0
index 15c9d29..5778468 100644
@@ -104,3 +104,25 @@ int hyper_dmabuf_remove_importer_ring(int domid)
 
 	return -1;
 }
+
+void hyper_dmabuf_foreach_exporter_ring(void (*func)(int rdom))
+{
+	struct hyper_dmabuf_exporter_ring_info *info_entry;
+	struct hlist_node *tmp;
+	int bkt;
+
+	hash_for_each_safe(hyper_dmabuf_hash_exporter_ring, bkt, tmp, info_entry, node) {
+		func(info_entry->info->rdomain);
+	}
+}
+
+void hyper_dmabuf_foreach_importer_ring(void (*func)(int sdom))
+{
+	struct hyper_dmabuf_importer_ring_info *info_entry;
+	struct hlist_node *tmp;
+	int bkt;
+
+	hash_for_each_safe(hyper_dmabuf_hash_importer_ring, bkt, tmp, info_entry, node) {
+		func(info_entry->info->sdomain);
+	}
+}
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h +6 -0
index 5929f99..fd1958c 100644
@@ -32,4 +32,10 @@ int hyper_dmabuf_remove_exporter_ring(int domid);
 
 int hyper_dmabuf_remove_importer_ring(int domid);
 
+/* iterates over all exporter rings and calls provided function for each of them */
+void hyper_dmabuf_foreach_exporter_ring(void (*func)(int rdom));
+
+/* iterates over all importer rings and calls provided function for each of them */
+void hyper_dmabuf_foreach_importer_ring(void (*func)(int sdom));
+
 #endif // __HYPER_DMABUF_XEN_COMM_LIST_H__
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#14 lore raw

RFC PATCH 8/60 hyper_dmabuf: automatic comm channel initialization using xenstore

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

This introduces use of xenstore for creating and managing communication channels between two VMs in the system.

When hyper_dmabuf driver is loaded in the service VM (host OS), a new xenstore directory, "/local/domain/<domid>/data/hyper_dmabuf" is created in xenstore filesystem. Whenever a new guest OS creates and initailizes its own upstream channel the service VM, new directory is created under the main directory created above as shown here:

/local/domain/<domid>/data/hyper_dmabuf/<remote domid>/port /local/domain/<domid>/data/hyper_dmabuf/<remote domid>/gref

This patch also adds a "xenstore watch" callback is called when a new upstream connection is made from another VM (VM-b). Upon detection, this VM (VM-a) intializes a downstream channel ,paired with detected upstream connection as shown below.

VM-a (downstream) <----- (upstream) VM-a

And as soon as this downstream channel is created, a new upstream channel from VM-a to VM-b is automatically created and initialized via "xenstore watch" call back on VM-b.

VM-a (upstream) <----- (downstream) VM-b

As a result, there will be bi-directional communication channel available between two VMs.

When upstream channel is removed (e.g. unloading driver), VM on the other side is notified and "xenstore watch" callback is invoked. Via this callback, VM can remove corresponding downstream channel.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  11 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  14 --
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  30 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  31 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |   2 -
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 226 +++++++++++++++++++--
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |  18 +-
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  22 ++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h  |   6 +
 9 files changed, 270 insertions(+), 90 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +10 -1
index 70b4878..5b5dae44 100644
@@ -6,6 +6,7 @@
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
+#include "xen/hyper_dmabuf_xen_comm.h"
 
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("IOTG-PED, INTEL");
@@ -43,6 +44,11 @@ static int hyper_dmabuf_drv_init(void)
 		return -EINVAL;
 	}
 
+	ret = hyper_dmabuf_setup_data_dir();
+	if (ret < 0) {
+		return -EINVAL;
+	}
+
 	/* interrupt for comm should be registered here: */
 	return ret;
 }
@@ -52,12 +58,15 @@ static void hyper_dmabuf_drv_exit(void)
 {
 	/* hash tables for export/import entries and ring_infos */
 	hyper_dmabuf_table_destroy();
-	hyper_dmabuf_ring_table_init();
+
+	hyper_dmabuf_cleanup_ringbufs();
+	hyper_dmabuf_ring_table_destroy();
 
 	/* destroy workqueue */
 	if (hyper_dmabuf_private.work_queue)
 		destroy_workqueue(hyper_dmabuf_private.work_queue);
 
+	hyper_dmabuf_destroy_data_dir();
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +0 -14
index 6145d29..7511afb 100644
@@ -29,8 +29,6 @@ struct ioctl_hyper_dmabuf_exporter_ring_setup {
 	/* IN parameters */
 	/* Remote domain id */
 	uint32_t remote_domain;
-	grant_ref_t ring_refid; /* assigned by driver, copied to userspace after initialization */
-	uint32_t port; /* assigned by driver, copied to userspace after initialization */
 };
 
 #define IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP \
@@ -39,10 +37,6 @@ struct ioctl_hyper_dmabuf_importer_ring_setup {
 	/* IN parameters */
 	/* Source domain id */
 	uint32_t source_domain;
-	/* Ring shared page refid */
-	grant_ref_t ring_refid;
-	/* Port number */
-	uint32_t port;
 };
 
 #define IOCTL_HYPER_DMABUF_EXPORT_REMOTE \
@@ -95,12 +89,4 @@ struct ioctl_hyper_dmabuf_query {
 	uint32_t info;
 };
 
-#define IOCTL_HYPER_DMABUF_REMOTE_EXPORTER_RING_SETUP \
-_IOC(_IOC_NONE, 'G', 6, sizeof(struct ioctl_hyper_dmabuf_remote_exporter_ring_setup))
-struct ioctl_hyper_dmabuf_remote_exporter_ring_setup {
-	/* in parameters */
-	uint32_t rdomain; /* id of remote domain where exporter's ring need to be setup */
-	uint32_t info;
-};
-
 #endif //__LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +2 -28
index e4d8316..44a153b 100644
@@ -48,9 +48,7 @@ static int hyper_dmabuf_exporter_ring_setup(void *data)
 		return 0;
 	}
 
-	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain,
-						&ring_attr->ring_refid,
-						&ring_attr->port);
+	ret = hyper_dmabuf_exporter_ringbuf_init(ring_attr->remote_domain);
 
 	return ret;
 }
@@ -76,10 +74,7 @@ static int hyper_dmabuf_importer_ring_setup(void *data)
 		return 0;
 	}
 
-	/* user need to provide a port number and ref # for the page used as ring buffer */
-	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain,
-						 setup_imp_ring_attr->ring_refid,
-						 setup_imp_ring_attr->port);
+	ret = hyper_dmabuf_importer_ringbuf_init(setup_imp_ring_attr->source_domain);
 
 	return ret;
 }
@@ -355,26 +350,6 @@ static int hyper_dmabuf_query(void *data)
 	return ret;
 }
 
-static int hyper_dmabuf_remote_exporter_ring_setup(void *data)
-{
-	struct ioctl_hyper_dmabuf_remote_exporter_ring_setup *remote_exporter_ring_setup;
-	struct hyper_dmabuf_ring_rq *req;
-
-	remote_exporter_ring_setup = (struct ioctl_hyper_dmabuf_remote_exporter_ring_setup *)data;
-
-	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORTER_RING_SETUP, NULL);
-
-	/* requesting remote domain to set-up exporter's ring */
-	if(hyper_dmabuf_send_request(remote_exporter_ring_setup->rdomain, req) < 0) {
-		kfree(req);
-		return -EINVAL;
-	}
-
-	kfree(req);
-	return 0;
-}
-
 static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORTER_RING_SETUP, hyper_dmabuf_exporter_ring_setup, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP, hyper_dmabuf_importer_ring_setup, 0),
@@ -382,7 +357,6 @@ static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_FD, hyper_dmabuf_export_fd_ioctl, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_DESTROY, hyper_dmabuf_destroy, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query, 0),
-	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_REMOTE_EXPORTER_RING_SETUP, hyper_dmabuf_remote_exporter_ring_setup, 0),
 };
 
 static long hyper_dmabuf_ioctl(struct file *filp,
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +1 -30
index 0166e61..8a059c8 100644
@@ -70,12 +70,6 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 			request->operands[i] = operands[i];
 		break;
 
-	/* requesting the other side to setup another ring channel for reverse direction */
-	case HYPER_DMABUF_EXPORTER_RING_SETUP:
-		/* command : HYPER_DMABUF_EXPORTER_RING_SETUP */
-		/* no operands needed */
-		break;
-
 	default:
 		/* no command found */
 		return;
@@ -163,13 +157,6 @@ void cmd_process_work(struct work_struct *work)
 		 */
 		break;
 
-	case HYPER_DMABUF_IMPORTER_RING_SETUP:
-		/* command: HYPER_DMABUF_IMPORTER_RING_SETUP */
-		/* no operands needed */
-		hyper_dmabuf_importer_ringbuf_init(domid, req->operands[0], req->operands[1]);
-
-		break;
-
 	default:
 		/* shouldn't get here */
 		/* no matched command, nothing to do.. just return error */
@@ -185,7 +172,6 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 	struct cmd_process *proc;
 	struct hyper_dmabuf_ring_rq *temp_req;
 	struct hyper_dmabuf_imported_sgt_info *imported_sgt_info;
-	int ret;
 
 	if (!req) {
 		printk("request is NULL\n");
@@ -193,28 +179,13 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 	}
 
 	if ((req->command < HYPER_DMABUF_EXPORT) ||
-		(req->command > HYPER_DMABUF_IMPORTER_RING_SETUP)) {
+		(req->command > HYPER_DMABUF_OPS_TO_SOURCE)) {
 		printk("invalid command\n");
 		return -EINVAL;
 	}
 
 	req->status = HYPER_DMABUF_REQ_PROCESSED;
 
-	/* HYPER_DMABUF_EXPORTER_RING_SETUP requires immediate
-	 * follow up so can't be processed in workqueue
-	 */
-	if (req->command == HYPER_DMABUF_EXPORTER_RING_SETUP) {
-		ret = hyper_dmabuf_exporter_ringbuf_init(domid, &req->operands[0], &req->operands[1]);
-		if (ret < 0) {
-			req->status = HYPER_DMABUF_REQ_ERROR;
-		}
-
-		req->status = HYPER_DMABUF_REQ_NEEDS_FOLLOW_UP;
-		req->command = HYPER_DMABUF_IMPORTER_RING_SETUP;
-
-		return req->command;
-	}
-
 	/* HYPER_DMABUF_DESTROY requires immediate
 	 * follow up so can't be processed in workqueue
 	 */
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +0 -2
index 44bfb70..9b25bdb 100644
@@ -7,8 +7,6 @@ enum hyper_dmabuf_command {
 	HYPER_DMABUF_DESTROY_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
-	HYPER_DMABUF_EXPORTER_RING_SETUP, /* requesting remote domain to set up exporter's ring */
-	HYPER_DMABUF_IMPORTER_RING_SETUP, /* requesting remote domain to set up importer's ring */
 };
 
 enum hyper_dmabuf_ops {
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +213 -13

302 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +16 -2
index 4ad0529..a4819ca 100644
@@ -2,6 +2,7 @@
 #define __HYPER_DMABUF_XEN_COMM_H__
 
 #include "xen/interface/io/ring.h"
+#include "xen/xenbus.h"
 
 #define MAX_NUMBER_OF_OPERANDS 9
 
@@ -27,6 +28,7 @@ struct hyper_dmabuf_ring_info_export {
         int gref_ring;
         int irq;
         int port;
+	struct xenbus_watch watch;
 };
 
 struct hyper_dmabuf_ring_info_import {
@@ -34,17 +36,29 @@ struct hyper_dmabuf_ring_info_import {
         int irq;
         int evtchn;
         struct hyper_dmabuf_back_ring ring_back;
+	struct gnttab_unmap_grant_ref unmap_op;
 };
 
 int32_t hyper_dmabuf_get_domid(void);
+int32_t hyper_dmabuf_setup_data_dir(void);
+int32_t hyper_dmabuf_destroy_data_dir(void);
 
 int hyper_dmabuf_next_req_id_export(void);
 
 /* exporter needs to generated info for page sharing */
-int hyper_dmabuf_exporter_ringbuf_init(int rdomain, grant_ref_t *gref, int *port);
+int hyper_dmabuf_exporter_ringbuf_init(int rdomain);
 
 /* importer needs to know about shared page and port numbers for ring buffer and event channel */
-int hyper_dmabuf_importer_ringbuf_init(int sdomain, grant_ref_t gref, int port);
+int hyper_dmabuf_importer_ringbuf_init(int sdomain);
+
+/* cleans up exporter ring created for given domain */
+void hyper_dmabuf_exporter_ringbuf_cleanup(int rdomain);
+
+/* cleans up importer ring created for given domain */
+void hyper_dmabuf_importer_ringbuf_cleanup(int sdomain);
+
+/* cleans up all exporter/importer rings */
+void hyper_dmabuf_cleanup_ringbufs(void);
 
 /* send request to the remote domain */
 int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req);
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +22 -0
index 15c9d29..5778468 100644
@@ -104,3 +104,25 @@ int hyper_dmabuf_remove_importer_ring(int domid)
 
 	return -1;
 }
+
+void hyper_dmabuf_foreach_exporter_ring(void (*func)(int rdom))
+{
+	struct hyper_dmabuf_exporter_ring_info *info_entry;
+	struct hlist_node *tmp;
+	int bkt;
+
+	hash_for_each_safe(hyper_dmabuf_hash_exporter_ring, bkt, tmp, info_entry, node) {
+		func(info_entry->info->rdomain);
+	}
+}
+
+void hyper_dmabuf_foreach_importer_ring(void (*func)(int sdom))
+{
+	struct hyper_dmabuf_importer_ring_info *info_entry;
+	struct hlist_node *tmp;
+	int bkt;
+
+	hash_for_each_safe(hyper_dmabuf_hash_importer_ring, bkt, tmp, info_entry, node) {
+		func(info_entry->info->sdomain);
+	}
+}
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h +6 -0
index 5929f99..fd1958c 100644
@@ -32,4 +32,10 @@ int hyper_dmabuf_remove_exporter_ring(int domid);
 
 int hyper_dmabuf_remove_importer_ring(int domid);
 
+/* iterates over all exporter rings and calls provided function for each of them */
+void hyper_dmabuf_foreach_exporter_ring(void (*func)(int rdom));
+
+/* iterates over all importer rings and calls provided function for each of them */
+void hyper_dmabuf_foreach_importer_ring(void (*func)(int sdom));
+
 #endif // __HYPER_DMABUF_XEN_COMM_LIST_H__
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

RFC PATCH 9/60 hyper_dmabuf: indirect DMA_BUF synchronization via shadowing

In reply to Dongwon Kim

Importer now sends a synchronization request to the exporter when any of DMA_BUF operations on imported Hyper_DMABUF is executed (e.g dma_buf_map and dma_buf_unmap). This results in a creation of shadow DMA_BUF and exactly same DMA_BUF operation to be executed on it.

The main purpose of this is to get DMA_BUF synchronized eventually between the original creator of DMA_BUF and the end consumer of it running on the importer VM.

---
 drivers/xen/hyper_dmabuf/Makefile                  |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  90 ++++++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  52 ++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |   8 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  43 +++--
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 189 +++++++++++++++++++++
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h    |   6 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  32 +++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  52 +++++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |   2 +-
 10 files changed, 397 insertions(+), 78 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h
drivers/xen/hyper_dmabuf/Makefile +1 -0
index 0be7445..3459382 100644
@@ -7,6 +7,7 @@ ifneq ($(KERNELRELEASE),)
                                  hyper_dmabuf_list.o \
 				 hyper_dmabuf_imp.o \
 				 hyper_dmabuf_msg.o \
+				 hyper_dmabuf_remote_sync.o \
 				 xen/hyper_dmabuf_xen_comm.o \
 				 xen/hyper_dmabuf_xen_comm_list.o
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +53 -37

271 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +41 -11

110 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +4 -4
index ad2109c..2b3ef6b 100644
@@ -33,7 +33,7 @@ int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info)
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_exported, &info_entry->node,
-		info_entry->info->hyper_dmabuf_id);
+		 info_entry->info->hyper_dmabuf_id);
 
 	return 0;
 }
@@ -47,7 +47,7 @@ int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info)
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_imported, &info_entry->node,
-		info_entry->info->hyper_dmabuf_id);
+		 info_entry->info->hyper_dmabuf_id);
 
 	return 0;
 }
@@ -71,8 +71,8 @@ int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
 	int bkt;
 
 	hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node)
-		if(info_entry->info->attachment->dmabuf == dmabuf &&
-			info_entry->info->hyper_dmabuf_rdomain == domid)
+		if(info_entry->info->dma_buf == dmabuf &&
+		   info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
 	return -1;
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +28 -15

79 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c new file +189 -0

189 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h new file +6 -0
new file mode 100644
index 0000000..fc85fa8
@@ -0,0 +1,6 @@
+#ifndef __HYPER_DMABUF_REMOTE_SYNC_H__
+#define __HYPER_DMABUF_REMOTE_SYNC_H__
+
+int hyper_dmabuf_remote_sync(int id, int ops);
+
+#endif // __HYPER_DMABUF_REMOTE_SYNC_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +30 -2
index c8a2f4d..bfe80ee 100644
@@ -18,6 +18,30 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
+/* stack of mapped sgts */
+struct sgt_list {
+	struct sg_table *sgt;
+	struct list_head list;
+};
+
+/* stack of attachments */
+struct attachment_list {
+	struct dma_buf_attachment *attach;
+	struct list_head list;
+};
+
+/* stack of vaddr mapped via kmap */
+struct kmap_vaddr_list {
+	void *vaddr;
+	struct list_head list;
+};
+
+/* stack of vaddr mapped via vmap */
+struct vmap_vaddr_list {
+	void *vaddr;
+	struct list_head list;
+};
+
 struct hyper_dmabuf_shared_pages_info {
 	grant_ref_t *data_refs;	/* table with shared buffer pages refid */
 	grant_ref_t *addr_pages; /* pages of 2nd level addressing */
@@ -46,9 +70,13 @@ struct hyper_dmabuf_pages_info {
 struct hyper_dmabuf_sgt_info {
         int hyper_dmabuf_id; /* unique id to reference dmabuf in remote domain */
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
-        struct sg_table *sgt; /* pointer to sgt */
+
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
-	struct dma_buf_attachment *attachment; /* needed to store this for freeing this later */
+	struct sgt_list *active_sgts;
+	struct attachment_list *active_attached;
+	struct kmap_vaddr_list *va_kmapped;
+	struct vmap_vaddr_list *va_vmapped;
+
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +44 -8

121 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +1 -1
index a4819ca..4ab031a 100644
@@ -61,7 +61,7 @@ void hyper_dmabuf_importer_ringbuf_cleanup(int sdomain);
 void hyper_dmabuf_cleanup_ringbufs(void);
 
 /* send request to the remote domain */
-int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req);
+int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req, int wait);
 
 /* called by interrupt (WORKQUEUE) */
 int hyper_dmabuf_send_response(struct hyper_dmabuf_ring_rp* response, int domain);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#16 lore raw

RFC PATCH 9/60 hyper_dmabuf: indirect DMA_BUF synchronization via shadowing

In reply to Dongwon Kim

Importer now sends a synchronization request to the exporter when any of DMA_BUF operations on imported Hyper_DMABUF is executed (e.g dma_buf_map and dma_buf_unmap). This results in a creation of shadow DMA_BUF and exactly same DMA_BUF operation to be executed on it.

The main purpose of this is to get DMA_BUF synchronized eventually between the original creator of DMA_BUF and the end consumer of it running on the importer VM.

---
 drivers/xen/hyper_dmabuf/Makefile                  |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  90 ++++++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  52 ++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |   8 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  43 +++--
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 189 +++++++++++++++++++++
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h    |   6 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  32 +++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  52 +++++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |   2 +-
 10 files changed, 397 insertions(+), 78 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h
drivers/xen/hyper_dmabuf/Makefile +1 -0
index 0be7445..3459382 100644
@@ -7,6 +7,7 @@ ifneq ($(KERNELRELEASE),)
                                  hyper_dmabuf_list.o \
 				 hyper_dmabuf_imp.o \
 				 hyper_dmabuf_msg.o \
+				 hyper_dmabuf_remote_sync.o \
 				 xen/hyper_dmabuf_xen_comm.o \
 				 xen/hyper_dmabuf_xen_comm_list.o
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +53 -37

271 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +41 -11

110 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +4 -4
index ad2109c..2b3ef6b 100644
@@ -33,7 +33,7 @@ int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info)
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_exported, &info_entry->node,
-		info_entry->info->hyper_dmabuf_id);
+		 info_entry->info->hyper_dmabuf_id);
 
 	return 0;
 }
@@ -47,7 +47,7 @@ int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info)
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_imported, &info_entry->node,
-		info_entry->info->hyper_dmabuf_id);
+		 info_entry->info->hyper_dmabuf_id);
 
 	return 0;
 }
@@ -71,8 +71,8 @@ int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
 	int bkt;
 
 	hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node)
-		if(info_entry->info->attachment->dmabuf == dmabuf &&
-			info_entry->info->hyper_dmabuf_rdomain == domid)
+		if(info_entry->info->dma_buf == dmabuf &&
+		   info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
 	return -1;
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +28 -15

79 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c new file +189 -0

189 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h new file +6 -0
new file mode 100644
index 0000000..fc85fa8
@@ -0,0 +1,6 @@
+#ifndef __HYPER_DMABUF_REMOTE_SYNC_H__
+#define __HYPER_DMABUF_REMOTE_SYNC_H__
+
+int hyper_dmabuf_remote_sync(int id, int ops);
+
+#endif // __HYPER_DMABUF_REMOTE_SYNC_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +30 -2
index c8a2f4d..bfe80ee 100644
@@ -18,6 +18,30 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
+/* stack of mapped sgts */
+struct sgt_list {
+	struct sg_table *sgt;
+	struct list_head list;
+};
+
+/* stack of attachments */
+struct attachment_list {
+	struct dma_buf_attachment *attach;
+	struct list_head list;
+};
+
+/* stack of vaddr mapped via kmap */
+struct kmap_vaddr_list {
+	void *vaddr;
+	struct list_head list;
+};
+
+/* stack of vaddr mapped via vmap */
+struct vmap_vaddr_list {
+	void *vaddr;
+	struct list_head list;
+};
+
 struct hyper_dmabuf_shared_pages_info {
 	grant_ref_t *data_refs;	/* table with shared buffer pages refid */
 	grant_ref_t *addr_pages; /* pages of 2nd level addressing */
@@ -46,9 +70,13 @@ struct hyper_dmabuf_pages_info {
 struct hyper_dmabuf_sgt_info {
         int hyper_dmabuf_id; /* unique id to reference dmabuf in remote domain */
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
-        struct sg_table *sgt; /* pointer to sgt */
+
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
-	struct dma_buf_attachment *attachment; /* needed to store this for freeing this later */
+	struct sgt_list *active_sgts;
+	struct attachment_list *active_attached;
+	struct kmap_vaddr_list *va_kmapped;
+	struct vmap_vaddr_list *va_vmapped;
+
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +44 -8

121 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +1 -1
index a4819ca..4ab031a 100644
@@ -61,7 +61,7 @@ void hyper_dmabuf_importer_ringbuf_cleanup(int sdomain);
 void hyper_dmabuf_cleanup_ringbufs(void);
 
 /* send request to the remote domain */
-int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req);
+int hyper_dmabuf_send_request(int domain, struct hyper_dmabuf_ring_rq *req, int wait);
 
 /* called by interrupt (WORKQUEUE) */
 int hyper_dmabuf_send_response(struct hyper_dmabuf_ring_rp* response, int domain);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#17 lore raw

RFC PATCH 10/60 hyper_dmabuf: make sure to free memory to prevent leak

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

In hyper_dmabuf_export_remote, page_info->pages needs to be freed before freeing page_info.

Also, info_entry in hyper_dmabuf_remove_exported/imported and hyper_dmabuf_remove_exporter/importer_ring needs to be freed after removal of an entry.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c             | 1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c              | 2 ++
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c      | 2 ++
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c | 2 ++
 4 files changed, 7 insertions(+)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +1 -0
index bace8b2..6f100ef 100644
@@ -191,6 +191,7 @@ static int hyper_dmabuf_export_remote(void *data)
 	/* free msg */
 	kfree(req);
 	/* free page_info */
+	kfree(page_info->pages);
 	kfree(page_info);
 
 	return ret;
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +2 -0
index 2b3ef6b..1420df9 100644
@@ -98,6 +98,7 @@ int hyper_dmabuf_remove_exported(int id)
 	hash_for_each(hyper_dmabuf_hash_exported, bkt, info_entry, node)
 		if(info_entry->info->hyper_dmabuf_id == id) {
 			hash_del(&info_entry->node);
+			kfree(info_entry);
 			return 0;
 		}
 
@@ -112,6 +113,7 @@ int hyper_dmabuf_remove_imported(int id)
 	hash_for_each(hyper_dmabuf_hash_imported, bkt, info_entry, node)
 		if(info_entry->info->hyper_dmabuf_id == id) {
 			hash_del(&info_entry->node);
+			kfree(info_entry);
 			return 0;
 		}
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +2 -0
index 576085f..116850e 100644
@@ -320,6 +320,8 @@ int hyper_dmabuf_importer_ringbuf_init(int sdomain)
 		ring_info->unmap_op.handle = ops[0].handle;
 	}
 
+	kfree(ops);
+
 	sring = (struct hyper_dmabuf_sring*) pfn_to_kaddr(page_to_pfn(shared_ring));
 
 	BACK_RING_INIT(&ring_info->ring_back, sring, PAGE_SIZE);
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +2 -0
index 5778468..a068276 100644
@@ -85,6 +85,7 @@ int hyper_dmabuf_remove_exporter_ring(int domid)
 	hash_for_each(hyper_dmabuf_hash_exporter_ring, bkt, info_entry, node)
 		if(info_entry->info->rdomain == domid) {
 			hash_del(&info_entry->node);
+			kfree(info_entry);
 			return 0;
 		}
 
@@ -99,6 +100,7 @@ int hyper_dmabuf_remove_importer_ring(int domid)
 	hash_for_each(hyper_dmabuf_hash_importer_ring, bkt, info_entry, node)
 		if(info_entry->info->sdomain == domid) {
 			hash_del(&info_entry->node);
+			kfree(info_entry);
 			return 0;
 		}
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#18 lore raw

RFC PATCH 11/60 hyper_dmabuf: check stack before unmapping/detaching shadow DMA_BUF

In reply to Dongwon Kim

Make sure list of mapping/attaching activities on impoter VM is not empty before doing unmapping/detaching shadow DMA BUF for indirect synchronization.

---
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 68 +++++++++++++++++-----
 1 file changed, 53 insertions(+), 15 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +53 -15
index 6ba932f..fa2fa11 100644
@@ -11,6 +11,21 @@
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
+/* Whenever importer does dma operations from remote domain,
+ * a notification is sent to the exporter so that exporter
+ * issues equivalent dma operation on the original dma buf
+ * for indirect synchronization via shadow operations.
+ *
+ * All ptrs and references (e.g struct sg_table*,
+ * struct dma_buf_attachment) created via these operations on
+ * exporter's side are kept in stack (implemented as circular
+ * linked-lists) separately so that those can be re-referenced
+ * later when unmapping operations are invoked to free those.
+ *
+ * The very first element on the bottom of each stack holds
+ * are what is created when initial exporting is issued so it
+ * should not be modified or released by this fuction.
+ */
 int hyper_dmabuf_remote_sync(int id, int ops)
 {
 	struct hyper_dmabuf_sgt_info *sgt_info;
@@ -33,7 +48,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		attachl = kcalloc(1, sizeof(*attachl), GFP_KERNEL);
 
 		attachl->attach = dma_buf_attach(sgt_info->dma_buf,
-						hyper_dmabuf_private.device);
+						 hyper_dmabuf_private.device);
 
 		if (!attachl->attach) {
 			kfree(attachl);
@@ -45,22 +60,31 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_DETACH:
-		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
-
-		if (!attachl) {
+		if (list_empty(&sgt_info->active_attached->list)) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_DETACH\n");
+			printk("no more dmabuf attachment left to be detached\n");
 			return -EINVAL;
 		}
+
+		attachl = list_first_entry(&sgt_info->active_attached->list,
+					   struct attachment_list, list);
+
 		dma_buf_detach(sgt_info->dma_buf, attachl->attach);
 		list_del(&attachl->list);
 		kfree(attachl);
 		break;
 
 	case HYPER_DMABUF_OPS_MAP:
-		sgtl = kcalloc(1, sizeof(*sgtl), GFP_KERNEL);
+		if (list_empty(&sgt_info->active_attached->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
+			printk("no more dmabuf attachment left to be detached\n");
+			return -EINVAL;
+		}
+
 		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
+					   struct attachment_list, list);
+
+		sgtl = kcalloc(1, sizeof(*sgtl), GFP_KERNEL);
 		sgtl->sgt = dma_buf_map_attachment(attachl->attach, DMA_BIDIRECTIONAL);
 		if (!sgtl->sgt) {
 			kfree(sgtl);
@@ -71,17 +95,20 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_UNMAP:
-		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
-		sgtl = list_first_entry(&sgt_info->active_sgts->list,
-					struct sgt_list, list);
-		if (!attachl || !sgtl) {
+		if (list_empty(&sgt_info->active_sgts->list) ||
+		    list_empty(&sgt_info->active_attached->list)) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_UNMAP\n");
+			printk("no more SGT or attachment left to be freed\n");
 			return -EINVAL;
 		}
 
+		attachl = list_first_entry(&sgt_info->active_attached->list,
+					   struct attachment_list, list);
+		sgtl = list_first_entry(&sgt_info->active_sgts->list,
+					struct sgt_list, list);
+
 		dma_buf_unmap_attachment(attachl->attach, sgtl->sgt,
-					DMA_BIDIRECTIONAL);
+					 DMA_BIDIRECTIONAL);
 		list_del(&sgtl->list);
 		kfree(sgtl);
 		break;
@@ -129,9 +156,15 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_KUNMAP_ATOMIC:
 	case HYPER_DMABUF_OPS_KUNMAP:
+		if (list_empty(&sgt_info->va_kmapped->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
+			printk("no more dmabuf VA to be freed\n");
+			return -EINVAL;
+		}
+
 		va_kmapl = list_first_entry(&sgt_info->va_kmapped->list,
-					struct kmap_vaddr_list, list);
-		if (!va_kmapl || va_kmapl->vaddr == NULL) {
+					    struct kmap_vaddr_list, list);
+		if (va_kmapl->vaddr == NULL) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
 			return -EINVAL;
 		}
@@ -167,6 +200,11 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_VUNMAP:
+		if (list_empty(&sgt_info->va_vmapped->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
+			printk("no more dmabuf VA to be freed\n");
+			return -EINVAL;
+		}
 		va_vmapl = list_first_entry(&sgt_info->va_vmapped->list,
 					struct vmap_vaddr_list, list);
 		if (!va_vmapl || va_vmapl->vaddr == NULL) {
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#19 lore raw

RFC PATCH 11/60 hyper_dmabuf: check stack before unmapping/detaching shadow DMA_BUF

In reply to Dongwon Kim

Make sure list of mapping/attaching activities on impoter VM is not empty before doing unmapping/detaching shadow DMA BUF for indirect synchronization.

---
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 68 +++++++++++++++++-----
 1 file changed, 53 insertions(+), 15 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +53 -15
index 6ba932f..fa2fa11 100644
@@ -11,6 +11,21 @@
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
+/* Whenever importer does dma operations from remote domain,
+ * a notification is sent to the exporter so that exporter
+ * issues equivalent dma operation on the original dma buf
+ * for indirect synchronization via shadow operations.
+ *
+ * All ptrs and references (e.g struct sg_table*,
+ * struct dma_buf_attachment) created via these operations on
+ * exporter's side are kept in stack (implemented as circular
+ * linked-lists) separately so that those can be re-referenced
+ * later when unmapping operations are invoked to free those.
+ *
+ * The very first element on the bottom of each stack holds
+ * are what is created when initial exporting is issued so it
+ * should not be modified or released by this fuction.
+ */
 int hyper_dmabuf_remote_sync(int id, int ops)
 {
 	struct hyper_dmabuf_sgt_info *sgt_info;
@@ -33,7 +48,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		attachl = kcalloc(1, sizeof(*attachl), GFP_KERNEL);
 
 		attachl->attach = dma_buf_attach(sgt_info->dma_buf,
-						hyper_dmabuf_private.device);
+						 hyper_dmabuf_private.device);
 
 		if (!attachl->attach) {
 			kfree(attachl);
@@ -45,22 +60,31 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_DETACH:
-		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
-
-		if (!attachl) {
+		if (list_empty(&sgt_info->active_attached->list)) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_DETACH\n");
+			printk("no more dmabuf attachment left to be detached\n");
 			return -EINVAL;
 		}
+
+		attachl = list_first_entry(&sgt_info->active_attached->list,
+					   struct attachment_list, list);
+
 		dma_buf_detach(sgt_info->dma_buf, attachl->attach);
 		list_del(&attachl->list);
 		kfree(attachl);
 		break;
 
 	case HYPER_DMABUF_OPS_MAP:
-		sgtl = kcalloc(1, sizeof(*sgtl), GFP_KERNEL);
+		if (list_empty(&sgt_info->active_attached->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
+			printk("no more dmabuf attachment left to be detached\n");
+			return -EINVAL;
+		}
+
 		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
+					   struct attachment_list, list);
+
+		sgtl = kcalloc(1, sizeof(*sgtl), GFP_KERNEL);
 		sgtl->sgt = dma_buf_map_attachment(attachl->attach, DMA_BIDIRECTIONAL);
 		if (!sgtl->sgt) {
 			kfree(sgtl);
@@ -71,17 +95,20 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_UNMAP:
-		attachl = list_first_entry(&sgt_info->active_attached->list,
-					struct attachment_list, list);
-		sgtl = list_first_entry(&sgt_info->active_sgts->list,
-					struct sgt_list, list);
-		if (!attachl || !sgtl) {
+		if (list_empty(&sgt_info->active_sgts->list) ||
+		    list_empty(&sgt_info->active_attached->list)) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_UNMAP\n");
+			printk("no more SGT or attachment left to be freed\n");
 			return -EINVAL;
 		}
 
+		attachl = list_first_entry(&sgt_info->active_attached->list,
+					   struct attachment_list, list);
+		sgtl = list_first_entry(&sgt_info->active_sgts->list,
+					struct sgt_list, list);
+
 		dma_buf_unmap_attachment(attachl->attach, sgtl->sgt,
-					DMA_BIDIRECTIONAL);
+					 DMA_BIDIRECTIONAL);
 		list_del(&sgtl->list);
 		kfree(sgtl);
 		break;
@@ -129,9 +156,15 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_KUNMAP_ATOMIC:
 	case HYPER_DMABUF_OPS_KUNMAP:
+		if (list_empty(&sgt_info->va_kmapped->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
+			printk("no more dmabuf VA to be freed\n");
+			return -EINVAL;
+		}
+
 		va_kmapl = list_first_entry(&sgt_info->va_kmapped->list,
-					struct kmap_vaddr_list, list);
-		if (!va_kmapl || va_kmapl->vaddr == NULL) {
+					    struct kmap_vaddr_list, list);
+		if (va_kmapl->vaddr == NULL) {
 			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
 			return -EINVAL;
 		}
@@ -167,6 +200,11 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_VUNMAP:
+		if (list_empty(&sgt_info->va_vmapped->list)) {
+			printk("dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
+			printk("no more dmabuf VA to be freed\n");
+			return -EINVAL;
+		}
 		va_vmapl = list_first_entry(&sgt_info->va_vmapped->list,
 					struct vmap_vaddr_list, list);
 		if (!va_vmapl || va_vmapl->vaddr == NULL) {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#20 lore raw

RFC PATCH 12/60 hyper_dmabuf: two different unexporting mechanisms

In reply to Dongwon Kim

unexporting on exporter's side now have two options, one is , that just remove and free everything to literally "disconnect" from importer, the other is just to return fail if any apps running on importer is still attached or DMAing. Currently whether forcing or unforcing it is determined by how "FORCED_UNEXPORING" is defined.

Also, the word "destroy" in IOCTL commands and several functions have been modified to "unexport", which sounds more reasonable.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h   |  8 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 94 ++++++++++++++++++++++++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h   |  4 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 +++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c   | 62 +++++++++---------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h   |  4 +-
 6 files changed, 142 insertions(+), 50 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +4 -4
index 7511afb..8778a19 100644
@@ -65,11 +65,11 @@ struct ioctl_hyper_dmabuf_export_fd {
 	uint32_t fd;
 };
 
-#define IOCTL_HYPER_DMABUF_DESTROY \
-_IOC(_IOC_NONE, 'G', 4, sizeof(struct ioctl_hyper_dmabuf_destroy))
-struct ioctl_hyper_dmabuf_destroy {
+#define IOCTL_HYPER_DMABUF_UNEXPORT \
+_IOC(_IOC_NONE, 'G', 4, sizeof(struct ioctl_hyper_dmabuf_unexport))
+struct ioctl_hyper_dmabuf_unexport {
 	/* IN parameters */
-	/* hyper dmabuf id to be destroyed */
+	/* hyper dmabuf id to be unexported */
 	uint32_t hyper_dmabuf_id;
 	/* OUT parameters */
 	/* Status of request */
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +93 -1

112 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +4 -0
index 003c158..71c1bb0 100644
@@ -24,6 +24,10 @@ grant_ref_t *hyper_dmabuf_map_gref_table(grant_ref_t *gref_table, int n_pages_ta
 struct sg_table* hyper_dmabuf_map_pages(grant_ref_t gref, int frst_ofst, int last_len, int nents, int sdomain,
 					struct hyper_dmabuf_shared_pages_info *shared_pages_info);
 
+int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int force);
+
+void hyper_dmabuf_free_sgt(struct sg_table *sgt);
+
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
 
 struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +10 -10
index 6f100ef..a222c1b 100644
@@ -20,7 +20,7 @@ extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
 static uint32_t hyper_dmabuf_id_gen(void) {
 	/* TODO: add proper implementation */
-	static uint32_t id = 0;
+	static uint32_t id = 1000;
 	static int32_t domid = -1;
 	if (domid == -1) {
 		domid = hyper_dmabuf_get_domid();
@@ -259,12 +259,12 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	return ret;
 }
 
-/* removing dmabuf from the database and send int req to the source domain
+/* unexport dmabuf from the database and send int req to the source domain
  * to unmap it.
  */
-static int hyper_dmabuf_destroy(void *data)
+static int hyper_dmabuf_unexport(void *data)
 {
-	struct ioctl_hyper_dmabuf_destroy *destroy_attr;
+	struct ioctl_hyper_dmabuf_unexport *unexport_attr;
 	struct hyper_dmabuf_sgt_info *sgt_info;
 	struct hyper_dmabuf_ring_rq *req;
 	int ret;
@@ -274,20 +274,20 @@ static int hyper_dmabuf_destroy(void *data)
 		return -EINVAL;
 	}
 
-	destroy_attr = (struct ioctl_hyper_dmabuf_destroy *)data;
+	unexport_attr = (struct ioctl_hyper_dmabuf_unexport *)data;
 
 	/* find dmabuf in export list */
-	sgt_info = hyper_dmabuf_find_exported(destroy_attr->hyper_dmabuf_id);
+	sgt_info = hyper_dmabuf_find_exported(unexport_attr->hyper_dmabuf_id);
 
 	/* failed to find corresponding entry in export list */
 	if (sgt_info == NULL) {
-		destroy_attr->status = -EINVAL;
+		unexport_attr->status = -EINVAL;
 		return -EFAULT;
 	}
 
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
 
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_DESTROY, &destroy_attr->hyper_dmabuf_id);
+	hyper_dmabuf_create_request(req, HYPER_DMABUF_NOTIFY_UNEXPORT, &unexport_attr->hyper_dmabuf_id);
 
 	/* now send destroy request to remote domain
 	 * currently assuming there's only one importer exist
@@ -300,7 +300,7 @@ static int hyper_dmabuf_destroy(void *data)
 
 	/* free msg */
 	kfree(req);
-	destroy_attr->status = ret;
+	unexport_attr->status = ret;
 
 	/* Rest of cleanup will follow when importer will free it's buffer,
 	 * current implementation assumes that there is only one importer
@@ -386,7 +386,7 @@ static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP, hyper_dmabuf_importer_ring_setup, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_REMOTE, hyper_dmabuf_export_remote, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_FD, hyper_dmabuf_export_fd_ioctl, 0),
-	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_DESTROY, hyper_dmabuf_destroy, 0),
+	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_UNEXPORT, hyper_dmabuf_unexport, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query, 0),
 };
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +29 -33

122 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +2 -2
index 9b25bdb..39a114a 100644
@@ -3,8 +3,8 @@
 
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
-	HYPER_DMABUF_DESTROY,
-	HYPER_DMABUF_DESTROY_FINISH,
+	HYPER_DMABUF_NOTIFY_UNEXPORT,
+	HYPER_DMABUF_UNEXPORT_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
 };
Signature · 1 line
2.7.4
#21 lore raw

RFC PATCH 12/60 hyper_dmabuf: two different unexporting mechanisms

In reply to Dongwon Kim

unexporting on exporter's side now have two options, one is , that just remove and free everything to literally "disconnect" from importer, the other is just to return fail if any apps running on importer is still attached or DMAing. Currently whether forcing or unforcing it is determined by how "FORCED_UNEXPORING" is defined.

Also, the word "destroy" in IOCTL commands and several functions have been modified to "unexport", which sounds more reasonable.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h   |  8 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c   | 94 ++++++++++++++++++++++++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h   |  4 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 20 +++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c   | 62 +++++++++---------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h   |  4 +-
 6 files changed, 142 insertions(+), 50 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +4 -4
index 7511afb..8778a19 100644
@@ -65,11 +65,11 @@ struct ioctl_hyper_dmabuf_export_fd {
 	uint32_t fd;
 };
 
-#define IOCTL_HYPER_DMABUF_DESTROY \
-_IOC(_IOC_NONE, 'G', 4, sizeof(struct ioctl_hyper_dmabuf_destroy))
-struct ioctl_hyper_dmabuf_destroy {
+#define IOCTL_HYPER_DMABUF_UNEXPORT \
+_IOC(_IOC_NONE, 'G', 4, sizeof(struct ioctl_hyper_dmabuf_unexport))
+struct ioctl_hyper_dmabuf_unexport {
 	/* IN parameters */
-	/* hyper dmabuf id to be destroyed */
+	/* hyper dmabuf id to be unexported */
 	uint32_t hyper_dmabuf_id;
 	/* OUT parameters */
 	/* Status of request */
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +93 -1

112 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +4 -0
index 003c158..71c1bb0 100644
@@ -24,6 +24,10 @@ grant_ref_t *hyper_dmabuf_map_gref_table(grant_ref_t *gref_table, int n_pages_ta
 struct sg_table* hyper_dmabuf_map_pages(grant_ref_t gref, int frst_ofst, int last_len, int nents, int sdomain,
 					struct hyper_dmabuf_shared_pages_info *shared_pages_info);
 
+int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int force);
+
+void hyper_dmabuf_free_sgt(struct sg_table *sgt);
+
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
 
 struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +10 -10
index 6f100ef..a222c1b 100644
@@ -20,7 +20,7 @@ extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
 static uint32_t hyper_dmabuf_id_gen(void) {
 	/* TODO: add proper implementation */
-	static uint32_t id = 0;
+	static uint32_t id = 1000;
 	static int32_t domid = -1;
 	if (domid == -1) {
 		domid = hyper_dmabuf_get_domid();
@@ -259,12 +259,12 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	return ret;
 }
 
-/* removing dmabuf from the database and send int req to the source domain
+/* unexport dmabuf from the database and send int req to the source domain
  * to unmap it.
  */
-static int hyper_dmabuf_destroy(void *data)
+static int hyper_dmabuf_unexport(void *data)
 {
-	struct ioctl_hyper_dmabuf_destroy *destroy_attr;
+	struct ioctl_hyper_dmabuf_unexport *unexport_attr;
 	struct hyper_dmabuf_sgt_info *sgt_info;
 	struct hyper_dmabuf_ring_rq *req;
 	int ret;
@@ -274,20 +274,20 @@ static int hyper_dmabuf_destroy(void *data)
 		return -EINVAL;
 	}
 
-	destroy_attr = (struct ioctl_hyper_dmabuf_destroy *)data;
+	unexport_attr = (struct ioctl_hyper_dmabuf_unexport *)data;
 
 	/* find dmabuf in export list */
-	sgt_info = hyper_dmabuf_find_exported(destroy_attr->hyper_dmabuf_id);
+	sgt_info = hyper_dmabuf_find_exported(unexport_attr->hyper_dmabuf_id);
 
 	/* failed to find corresponding entry in export list */
 	if (sgt_info == NULL) {
-		destroy_attr->status = -EINVAL;
+		unexport_attr->status = -EINVAL;
 		return -EFAULT;
 	}
 
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
 
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_DESTROY, &destroy_attr->hyper_dmabuf_id);
+	hyper_dmabuf_create_request(req, HYPER_DMABUF_NOTIFY_UNEXPORT, &unexport_attr->hyper_dmabuf_id);
 
 	/* now send destroy request to remote domain
 	 * currently assuming there's only one importer exist
@@ -300,7 +300,7 @@ static int hyper_dmabuf_destroy(void *data)
 
 	/* free msg */
 	kfree(req);
-	destroy_attr->status = ret;
+	unexport_attr->status = ret;
 
 	/* Rest of cleanup will follow when importer will free it's buffer,
 	 * current implementation assumes that there is only one importer
@@ -386,7 +386,7 @@ static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_IMPORTER_RING_SETUP, hyper_dmabuf_importer_ring_setup, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_REMOTE, hyper_dmabuf_export_remote, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_FD, hyper_dmabuf_export_fd_ioctl, 0),
-	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_DESTROY, hyper_dmabuf_destroy, 0),
+	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_UNEXPORT, hyper_dmabuf_unexport, 0),
 	HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query, 0),
 };
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +29 -33

122 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +2 -2
index 9b25bdb..39a114a 100644
@@ -3,8 +3,8 @@
 
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
-	HYPER_DMABUF_DESTROY,
-	HYPER_DMABUF_DESTROY_FINISH,
+	HYPER_DMABUF_NOTIFY_UNEXPORT,
+	HYPER_DMABUF_UNEXPORT_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
 };
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#22 lore raw

RFC PATCH 13/60 hyper_dmabuf: postponing cleanup of hyper_DMABUF

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Immediate clean up of buffer is not possible if the buffer is actively used by importer. In this case, we need to postpone freeing hyper_DMABUF until the last consumer unmaps and releases the buffer on impoter VM. New reference count is added for tracking usage by importers.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 37 ++++++++++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 34 +++++++++++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 49 +++++++---------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  1 -
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 14 +++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  9 +++-
 6 files changed, 95 insertions(+), 49 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +34 -3
index 06bd8e5..f258981 100644
@@ -9,6 +9,7 @@
 #include "hyper_dmabuf_imp.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
+#include "hyper_dmabuf_list.h"
 
 #define REFS_PER_PAGE (PAGE_SIZE/sizeof(grant_ref_t))
 
@@ -104,7 +105,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 
 	ret = sg_alloc_table(sgt, nents, GFP_KERNEL);
 	if (ret) {
-		sg_free_table(sgt);
+		hyper_dmabuf_free_sgt(sgt);
 		return NULL;
 	}
 
@@ -129,6 +130,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 void hyper_dmabuf_free_sgt(struct sg_table* sgt)
 {
 	sg_free_table(sgt);
+	kfree(sgt);
 }
 
 /*
@@ -583,6 +585,9 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 		kfree(attachl);
 	}
 
+	/* Start cleanup of buffer in reverse order to exporting */
+	hyper_dmabuf_cleanup_gref_table(sgt_info);
+
 	/* unmap dma-buf */
 	dma_buf_unmap_attachment(sgt_info->active_attached->attach,
 				 sgt_info->active_sgts->sgt,
@@ -594,8 +599,6 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 	/* close connection to dma-buf completely */
 	dma_buf_put(sgt_info->dma_buf);
 
-	hyper_dmabuf_cleanup_gref_table(sgt_info);
-
 	kfree(sgt_info->active_sgts);
 	kfree(sgt_info->active_attached);
 	kfree(sgt_info->va_kmapped);
@@ -694,6 +697,9 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	ret = hyper_dmabuf_sync_request_and_wait(sgt_info->hyper_dmabuf_id,
 						HYPER_DMABUF_OPS_MAP);
 
+	kfree(page_info->pages);
+	kfree(page_info);
+
 	if (ret < 0) {
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
@@ -741,12 +747,34 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dmabuf)
 
 	sgt_info = (struct hyper_dmabuf_imported_sgt_info *)dmabuf->priv;
 
+	if (sgt_info) {
+		/* dmabuf fd is being released - decrease refcount */
+		sgt_info->ref_count--;
+
+		/* if no one else in that domain is using that buffer, unmap it for now */
+		if (sgt_info->ref_count == 0) {
+			hyper_dmabuf_cleanup_imported_pages(sgt_info);
+			hyper_dmabuf_free_sgt(sgt_info->sgt);
+			sgt_info->sgt = NULL;
+		}
+	}
+
 	ret = hyper_dmabuf_sync_request_and_wait(sgt_info->hyper_dmabuf_id,
 						HYPER_DMABUF_OPS_RELEASE);
 
 	if (ret < 0) {
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
+
+	/*
+	 * Check if buffer is still valid and if not remove it from imported list.
+	 * That has to be done after sending sync request
+	 */
+	if (sgt_info && sgt_info->ref_count == 0 &&
+	    sgt_info->flags == HYPER_DMABUF_SGT_INVALID) {
+		hyper_dmabuf_remove_imported(sgt_info->hyper_dmabuf_id);
+		kfree(sgt_info);
+	}
 }
 
 static int hyper_dmabuf_ops_begin_cpu_access(struct dma_buf *dmabuf, enum dma_data_direction dir)
@@ -944,6 +972,9 @@ int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int fla
 
 	fd = dma_buf_fd(dmabuf, flags);
 
+	/* dmabuf fd is exported for given bufer - increase its ref count */
+	dinfo->ref_count++;
+
 	return fd;
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +27 -7
index a222c1b..c57acafe 100644
@@ -135,6 +135,7 @@ static int hyper_dmabuf_export_remote(void *data)
 	/* TODO: We might need to consider using port number on event channel? */
 	sgt_info->hyper_dmabuf_rdomain = export_remote_attr->remote_domain;
 	sgt_info->dma_buf = dma_buf;
+	sgt_info->flags = 0;
 
 	sgt_info->active_sgts = kcalloc(1, sizeof(struct sgt_list), GFP_KERNEL);
 	sgt_info->active_attached = kcalloc(1, sizeof(struct attachment_list), GFP_KERNEL);
@@ -233,6 +234,15 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	if (imported_sgt_info == NULL) /* can't find sgt from the table */
 		return -1;
 
+	/*
+	 * Check if buffer was not unexported by exporter.
+	 * In such exporter is waiting for importer to finish using that buffer,
+	 * so do not allow export fd of such buffer anymore.
+	 */
+	if (imported_sgt_info->flags == HYPER_DMABUF_SGT_INVALID) {
+		return -EINVAL;
+	}
+
 	printk("%s Found buffer gref %d  off %d last len %d nents %d domain %d\n", __func__,
 		imported_sgt_info->gref, imported_sgt_info->frst_ofst,
 		imported_sgt_info->last_len, imported_sgt_info->nents,
@@ -289,9 +299,7 @@ static int hyper_dmabuf_unexport(void *data)
 
 	hyper_dmabuf_create_request(req, HYPER_DMABUF_NOTIFY_UNEXPORT, &unexport_attr->hyper_dmabuf_id);
 
-	/* now send destroy request to remote domain
-	 * currently assuming there's only one importer exist
-	 */
+	/* Now send unexport request to remote domain, marking that buffer should not be used anymore */
 	ret = hyper_dmabuf_send_request(sgt_info->hyper_dmabuf_rdomain, req, true);
 	if (ret < 0) {
 		kfree(req);
@@ -300,11 +308,23 @@ static int hyper_dmabuf_unexport(void *data)
 
 	/* free msg */
 	kfree(req);
-	unexport_attr->status = ret;
 
-	/* Rest of cleanup will follow when importer will free it's buffer,
-	 * current implementation assumes that there is only one importer
-         */
+	/*
+	 * Check if any importer is still using buffer, if not clean it up completly,
+	 * otherwise mark buffer as unexported and postpone its cleanup to time when
+	 * importer will finish using it.
+	 */
+	if (list_empty(&sgt_info->active_sgts->list) &&
+	    list_empty(&sgt_info->active_attached->list)) {
+		hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
+		hyper_dmabuf_remove_exported(unexport_attr->hyper_dmabuf_id);
+		kfree(sgt_info);
+	} else {
+		sgt_info->flags = HYPER_DMABUF_SGT_UNEXPORTED;
+	}
+
+	/* TODO: should we mark here that buffer was destroyed immiedetaly or that was postponed ? */
+	unexport_attr->status = ret;
 
 	return ret;
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +15 -34

73 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +0 -1
index 39a114a..fc1365b 100644
@@ -4,7 +4,6 @@
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
 	HYPER_DMABUF_NOTIFY_UNEXPORT,
-	HYPER_DMABUF_UNEXPORT_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
 };
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +11 -3
index fa2fa11..61ba4ed 100644
@@ -8,6 +8,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
+#include "hyper_dmabuf_imp.h"
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
@@ -114,10 +115,17 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_RELEASE:
-		/* remote importer shouldn't release dma_buf because
-		 * exporter will hold handle to the dma_buf as
-		 * far as dma_buf is shared with other domains.
+		/*
+		 * Importer just released buffer fd, check if there is any other importer still using it.
+		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
+		 if (list_empty(&sgt_info->active_sgts->list) &&                                                                  	    list_empty(&sgt_info->active_attached->list) &&
+		     sgt_info->flags == HYPER_DMABUF_SGT_UNEXPORTED) {
+			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
+			hyper_dmabuf_remove_exported(id);
+			kfree(sgt_info);
+		}
+
 		break;
 
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +8 -1
index bfe80ee..1194cf2 100644
@@ -18,6 +18,11 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
+enum hyper_dmabuf_sgt_flags {
+        HYPER_DMABUF_SGT_INVALID = 0x10,
+        HYPER_DMABUF_SGT_UNEXPORTED,
+};
+
 /* stack of mapped sgts */
 struct sgt_list {
 	struct sg_table *sgt;
@@ -76,7 +81,7 @@ struct hyper_dmabuf_sgt_info {
 	struct attachment_list *active_attached;
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
-
+	int flags;
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
@@ -92,6 +97,8 @@ struct hyper_dmabuf_imported_sgt_info {
 	grant_ref_t gref; /* reference number of top level addressing page of shared pages */
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
+	int flags;
+	int ref_count;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#23 lore raw

RFC PATCH 13/60 hyper_dmabuf: postponing cleanup of hyper_DMABUF

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Immediate clean up of buffer is not possible if the buffer is actively used by importer. In this case, we need to postpone freeing hyper_DMABUF until the last consumer unmaps and releases the buffer on impoter VM. New reference count is added for tracking usage by importers.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 37 ++++++++++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 34 +++++++++++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 49 +++++++---------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  1 -
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 14 +++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  9 +++-
 6 files changed, 95 insertions(+), 49 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +34 -3
index 06bd8e5..f258981 100644
@@ -9,6 +9,7 @@
 #include "hyper_dmabuf_imp.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
+#include "hyper_dmabuf_list.h"
 
 #define REFS_PER_PAGE (PAGE_SIZE/sizeof(grant_ref_t))
 
@@ -104,7 +105,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 
 	ret = sg_alloc_table(sgt, nents, GFP_KERNEL);
 	if (ret) {
-		sg_free_table(sgt);
+		hyper_dmabuf_free_sgt(sgt);
 		return NULL;
 	}
 
@@ -129,6 +130,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 void hyper_dmabuf_free_sgt(struct sg_table* sgt)
 {
 	sg_free_table(sgt);
+	kfree(sgt);
 }
 
 /*
@@ -583,6 +585,9 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 		kfree(attachl);
 	}
 
+	/* Start cleanup of buffer in reverse order to exporting */
+	hyper_dmabuf_cleanup_gref_table(sgt_info);
+
 	/* unmap dma-buf */
 	dma_buf_unmap_attachment(sgt_info->active_attached->attach,
 				 sgt_info->active_sgts->sgt,
@@ -594,8 +599,6 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 	/* close connection to dma-buf completely */
 	dma_buf_put(sgt_info->dma_buf);
 
-	hyper_dmabuf_cleanup_gref_table(sgt_info);
-
 	kfree(sgt_info->active_sgts);
 	kfree(sgt_info->active_attached);
 	kfree(sgt_info->va_kmapped);
@@ -694,6 +697,9 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	ret = hyper_dmabuf_sync_request_and_wait(sgt_info->hyper_dmabuf_id,
 						HYPER_DMABUF_OPS_MAP);
 
+	kfree(page_info->pages);
+	kfree(page_info);
+
 	if (ret < 0) {
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
@@ -741,12 +747,34 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dmabuf)
 
 	sgt_info = (struct hyper_dmabuf_imported_sgt_info *)dmabuf->priv;
 
+	if (sgt_info) {
+		/* dmabuf fd is being released - decrease refcount */
+		sgt_info->ref_count--;
+
+		/* if no one else in that domain is using that buffer, unmap it for now */
+		if (sgt_info->ref_count == 0) {
+			hyper_dmabuf_cleanup_imported_pages(sgt_info);
+			hyper_dmabuf_free_sgt(sgt_info->sgt);
+			sgt_info->sgt = NULL;
+		}
+	}
+
 	ret = hyper_dmabuf_sync_request_and_wait(sgt_info->hyper_dmabuf_id,
 						HYPER_DMABUF_OPS_RELEASE);
 
 	if (ret < 0) {
 		printk("hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
+
+	/*
+	 * Check if buffer is still valid and if not remove it from imported list.
+	 * That has to be done after sending sync request
+	 */
+	if (sgt_info && sgt_info->ref_count == 0 &&
+	    sgt_info->flags == HYPER_DMABUF_SGT_INVALID) {
+		hyper_dmabuf_remove_imported(sgt_info->hyper_dmabuf_id);
+		kfree(sgt_info);
+	}
 }
 
 static int hyper_dmabuf_ops_begin_cpu_access(struct dma_buf *dmabuf, enum dma_data_direction dir)
@@ -944,6 +972,9 @@ int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int fla
 
 	fd = dma_buf_fd(dmabuf, flags);
 
+	/* dmabuf fd is exported for given bufer - increase its ref count */
+	dinfo->ref_count++;
+
 	return fd;
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +27 -7
index a222c1b..c57acafe 100644
@@ -135,6 +135,7 @@ static int hyper_dmabuf_export_remote(void *data)
 	/* TODO: We might need to consider using port number on event channel? */
 	sgt_info->hyper_dmabuf_rdomain = export_remote_attr->remote_domain;
 	sgt_info->dma_buf = dma_buf;
+	sgt_info->flags = 0;
 
 	sgt_info->active_sgts = kcalloc(1, sizeof(struct sgt_list), GFP_KERNEL);
 	sgt_info->active_attached = kcalloc(1, sizeof(struct attachment_list), GFP_KERNEL);
@@ -233,6 +234,15 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	if (imported_sgt_info == NULL) /* can't find sgt from the table */
 		return -1;
 
+	/*
+	 * Check if buffer was not unexported by exporter.
+	 * In such exporter is waiting for importer to finish using that buffer,
+	 * so do not allow export fd of such buffer anymore.
+	 */
+	if (imported_sgt_info->flags == HYPER_DMABUF_SGT_INVALID) {
+		return -EINVAL;
+	}
+
 	printk("%s Found buffer gref %d  off %d last len %d nents %d domain %d\n", __func__,
 		imported_sgt_info->gref, imported_sgt_info->frst_ofst,
 		imported_sgt_info->last_len, imported_sgt_info->nents,
@@ -289,9 +299,7 @@ static int hyper_dmabuf_unexport(void *data)
 
 	hyper_dmabuf_create_request(req, HYPER_DMABUF_NOTIFY_UNEXPORT, &unexport_attr->hyper_dmabuf_id);
 
-	/* now send destroy request to remote domain
-	 * currently assuming there's only one importer exist
-	 */
+	/* Now send unexport request to remote domain, marking that buffer should not be used anymore */
 	ret = hyper_dmabuf_send_request(sgt_info->hyper_dmabuf_rdomain, req, true);
 	if (ret < 0) {
 		kfree(req);
@@ -300,11 +308,23 @@ static int hyper_dmabuf_unexport(void *data)
 
 	/* free msg */
 	kfree(req);
-	unexport_attr->status = ret;
 
-	/* Rest of cleanup will follow when importer will free it's buffer,
-	 * current implementation assumes that there is only one importer
-         */
+	/*
+	 * Check if any importer is still using buffer, if not clean it up completly,
+	 * otherwise mark buffer as unexported and postpone its cleanup to time when
+	 * importer will finish using it.
+	 */
+	if (list_empty(&sgt_info->active_sgts->list) &&
+	    list_empty(&sgt_info->active_attached->list)) {
+		hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
+		hyper_dmabuf_remove_exported(unexport_attr->hyper_dmabuf_id);
+		kfree(sgt_info);
+	} else {
+		sgt_info->flags = HYPER_DMABUF_SGT_UNEXPORTED;
+	}
+
+	/* TODO: should we mark here that buffer was destroyed immiedetaly or that was postponed ? */
+	unexport_attr->status = ret;
 
 	return ret;
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +15 -34

73 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +0 -1
index 39a114a..fc1365b 100644
@@ -4,7 +4,6 @@
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
 	HYPER_DMABUF_NOTIFY_UNEXPORT,
-	HYPER_DMABUF_UNEXPORT_FINISH,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
 };
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +11 -3
index fa2fa11..61ba4ed 100644
@@ -8,6 +8,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
+#include "hyper_dmabuf_imp.h"
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
@@ -114,10 +115,17 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		break;
 
 	case HYPER_DMABUF_OPS_RELEASE:
-		/* remote importer shouldn't release dma_buf because
-		 * exporter will hold handle to the dma_buf as
-		 * far as dma_buf is shared with other domains.
+		/*
+		 * Importer just released buffer fd, check if there is any other importer still using it.
+		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
+		 if (list_empty(&sgt_info->active_sgts->list) &&                                                                  	    list_empty(&sgt_info->active_attached->list) &&
+		     sgt_info->flags == HYPER_DMABUF_SGT_UNEXPORTED) {
+			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
+			hyper_dmabuf_remove_exported(id);
+			kfree(sgt_info);
+		}
+
 		break;
 
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +8 -1
index bfe80ee..1194cf2 100644
@@ -18,6 +18,11 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
+enum hyper_dmabuf_sgt_flags {
+        HYPER_DMABUF_SGT_INVALID = 0x10,
+        HYPER_DMABUF_SGT_UNEXPORTED,
+};
+
 /* stack of mapped sgts */
 struct sgt_list {
 	struct sg_table *sgt;
@@ -76,7 +81,7 @@ struct hyper_dmabuf_sgt_info {
 	struct attachment_list *active_attached;
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
-
+	int flags;
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
@@ -92,6 +97,8 @@ struct hyper_dmabuf_imported_sgt_info {
 	grant_ref_t gref; /* reference number of top level addressing page of shared pages */
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
+	int flags;
+	int ref_count;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#24 lore raw

RFC PATCH 14/60 hyper_dmabuf: clean-up process based on file->f_count

In reply to Dongwon Kim

Now relaese funcs checks f_count for the file instead of our own refcount because it can't track dma_buf_get.

Also, importer now sends out HYPER_DMABUF_FIRST_EXPORT to let the exporter know corresponding dma-buf has ever exported on importer's side. This is to cover the case where exporter exports a buffer and unexport it right away before importer does first export_fd (there won't be any dma_buf_release nofication to exporter since SGT was never created by importer.)

After importer creates its own SGT, only condition it is completely released is that dma_buf is unexported (so valid == 0) and user app closes all locally assigned FDs (when dma_buf_release is called.) Otherwise, it needs to stay there since previously exported FD can be reused.

Also includes minor changes;

1. flag had been changed to "bool valid" for conciseness.
2. added bool importer_exported in sgt_info as an indicator for usage of buffer on the importer.
3. num of pages is added (nents) to hyper_dmabuf_sgt_info to keep the size info in EXPORT list.
3. more minor changes and clean-ups.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 76 ++++++++++++---------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        |  5 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 78 ++++++++++++----------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h       |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 34 ++++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  2 +
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 10 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     | 19 +++---
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  6 +-
 12 files changed, 143 insertions(+), 93 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +1 -0
index 5b5dae44..5a7cfa5 100644
@@ -33,6 +33,7 @@ static int hyper_dmabuf_drv_init(void)
 	/* device structure initialization */
 	/* currently only does work-queue initialization */
 	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
+	hyper_dmabuf_private.domid = hyper_dmabuf_get_domid();
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +1 -0
index 8778a19..ff883e1 100644
@@ -3,6 +3,7 @@
 
 struct hyper_dmabuf_private {
         struct device *device;
+	int domid;
 	struct workqueue_struct *work_queue;
 };
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +44 -32

169 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +4 -1
index 71c1bb0..1b0801f 100644
@@ -1,6 +1,7 @@
 #ifndef __HYPER_DMABUF_IMP_H__
 #define __HYPER_DMABUF_IMP_H__
 
+#include <linux/fs.h>
 #include "hyper_dmabuf_struct.h"
 
 /* extract pages directly from struct sg_table */
@@ -30,6 +31,8 @@ void hyper_dmabuf_free_sgt(struct sg_table *sgt);
 
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
 
-struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+void hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+
+int dmabuf_refcount(struct dma_buf *dma_buf);
 
 #endif /* __HYPER_DMABUF_IMP_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +44 -34

143 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +1 -1
index 1420df9..18731de 100644
@@ -65,7 +65,7 @@ struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id)
 }
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
+int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid)
 {
 	struct hyper_dmabuf_info_entry_exported *info_entry;
 	int bkt;
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +1 -1
index 463a6da..f55d06e 100644
@@ -25,7 +25,7 @@ int hyper_dmabuf_table_destroy(void);
 int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid);
+int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid);
 
 int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +29 -5
index 97b42a4..a2d687f 100644
@@ -55,6 +55,14 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 		request->operands[0] = operands[0];
 		break;
 
+	case HYPER_DMABUF_FIRST_EXPORT:
+		/* dmabuf fd is being created on imported side for first time */
+		/* command : HYPER_DMABUF_FIRST_EXPORT,
+		 * operands0 : hyper_dmabuf_id
+		 */
+		request->operands[0] = operands[0];
+		break;
+
 	case HYPER_DMABUF_OPS_TO_REMOTE:
 		/* notifying dmabuf map/unmap to importer (probably not needed) */
 		/* for dmabuf synchronization */
@@ -81,6 +89,7 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 void cmd_process_work(struct work_struct *work)
 {
 	struct hyper_dmabuf_imported_sgt_info *imported_sgt_info;
+	struct hyper_dmabuf_sgt_info *sgt_info;
 	struct cmd_process *proc = container_of(work, struct cmd_process, work);
 	struct hyper_dmabuf_ring_rq *req;
 	int domid;
@@ -117,11 +126,25 @@ void cmd_process_work(struct work_struct *work)
 		for (i=0; i<4; i++)
 			imported_sgt_info->private[i] = req->operands[5+i];
 
-		imported_sgt_info->flags = 0;
-		imported_sgt_info->ref_count = 0;
+		imported_sgt_info->valid = 1;
 		hyper_dmabuf_register_imported(imported_sgt_info);
 		break;
 
+	case HYPER_DMABUF_FIRST_EXPORT:
+		/* find a corresponding SGT for the id */
+		sgt_info = hyper_dmabuf_find_exported(req->operands[0]);
+
+		if (!sgt_info) {
+			printk("critical err: requested sgt_info can't be found %d\n", req->operands[0]);
+			break;
+		}
+
+		if (sgt_info->importer_exported)
+			printk("warning: exported flag is not supposed to be 1 already\n");
+
+		sgt_info->importer_exported = 1;
+		break;
+
 	case HYPER_DMABUF_OPS_TO_REMOTE:
 		/* notifying dmabuf map/unmap to importer (probably not needed) */
 		/* for dmabuf synchronization */
@@ -170,13 +193,14 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 			hyper_dmabuf_find_imported(req->operands[0]);
 
 		if (imported_sgt_info) {
-			/* check if buffer is still mapped and in use */
-			if (imported_sgt_info->sgt) {
+			/* if anything is still using dma_buf */
+			if (imported_sgt_info->dma_buf &&
+			    dmabuf_refcount(imported_sgt_info->dma_buf) > 0) {
 				/*
 				 * Buffer is still in  use, just mark that it should
 				 * not be allowed to export its fd anymore.
 				 */
-				imported_sgt_info->flags = HYPER_DMABUF_SGT_INVALID;
+				imported_sgt_info->valid = 0;
 			} else {
 				/* No one is using buffer, remove it from imported list */
 				hyper_dmabuf_remove_imported(req->operands[0]);
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +2 -0
index fc1365b..1e9d827 100644
@@ -3,6 +3,7 @@
 
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
+	HYPER_DMABUF_FIRST_EXPORT,
 	HYPER_DMABUF_NOTIFY_UNEXPORT,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
@@ -14,6 +15,7 @@ enum hyper_dmabuf_ops {
 	HYPER_DMABUF_OPS_MAP,
 	HYPER_DMABUF_OPS_UNMAP,
 	HYPER_DMABUF_OPS_RELEASE,
+	HYPER_DMABUF_OPS_RELEASE_FINAL,
 	HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS,
 	HYPER_DMABUF_OPS_END_CPU_ACCESS,
 	HYPER_DMABUF_OPS_KMAP_ATOMIC,
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +7 -3
index 61ba4ed..5017b17 100644
@@ -114,13 +114,13 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		kfree(sgtl);
 		break;
 
-	case HYPER_DMABUF_OPS_RELEASE:
+	case HYPER_DMABUF_OPS_RELEASE_FINAL:
 		/*
 		 * Importer just released buffer fd, check if there is any other importer still using it.
 		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
-		 if (list_empty(&sgt_info->active_sgts->list) &&                                                                  	    list_empty(&sgt_info->active_attached->list) &&
-		     sgt_info->flags == HYPER_DMABUF_SGT_UNEXPORTED) {
+		 if (list_empty(&sgt_info->active_attached->list) &&
+		     !sgt_info->valid) {
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 			hyper_dmabuf_remove_exported(id);
 			kfree(sgt_info);
@@ -128,6 +128,10 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 		break;
 
+	case HYPER_DMABUF_OPS_RELEASE:
+		/* place holder */
+		break;
+
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
 		ret = dma_buf_begin_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
 		if (!ret) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +8 -11
index 1194cf2..92e06ff 100644
@@ -6,10 +6,10 @@
 /* Importer combine source domain id with given hyper_dmabuf_id
  * to make it unique in case there are multiple exporters */
 
-#define HYPER_DMABUF_ID_IMPORTER(sdomain, id) \
-	((((sdomain) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+#define HYPER_DMABUF_ID_IMPORTER(domid, id) \
+	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
 
-#define HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(id) \
+#define HYPER_DMABUF_DOM_ID(id) \
 	(((id) >> 24) & 0xFF)
 
 /* each grant_ref_t is 4 bytes, so total 4096 grant_ref_t can be
@@ -18,11 +18,6 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
-enum hyper_dmabuf_sgt_flags {
-        HYPER_DMABUF_SGT_INVALID = 0x10,
-        HYPER_DMABUF_SGT_UNEXPORTED,
-};
-
 /* stack of mapped sgts */
 struct sgt_list {
 	struct sg_table *sgt;
@@ -77,11 +72,13 @@ struct hyper_dmabuf_sgt_info {
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
 
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
+	int nents; /* number of pages, which may be different than sgt->nents */
 	struct sgt_list *active_sgts;
 	struct attachment_list *active_attached;
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
-	int flags;
+	bool valid;
+	bool importer_exported; /* exported locally on importer's side */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
@@ -95,10 +92,10 @@ struct hyper_dmabuf_imported_sgt_info {
 	int last_len;	/* length of data in the last shared page */
 	int nents;	/* number of pages to be shared */
 	grant_ref_t gref; /* reference number of top level addressing page of shared pages */
+	struct dma_buf *dma_buf;
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
-	int flags;
-	int ref_count;
+	bool valid;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +1 -5
index 116850e..f9e0df3 100644
@@ -456,13 +456,12 @@ static irqreturn_t hyper_dmabuf_back_ring_isr(int irq, void *info)
 	do {
 		rc = ring->req_cons;
 		rp = ring->sring->req_prod;
-
+		more_to_do = 0;
 		while (rc != rp) {
 			if (RING_REQUEST_CONS_OVERFLOW(ring, rc))
 				break;
 
 			memcpy(&req, RING_GET_REQUEST(ring, rc), sizeof(req));
-			printk("Got request\n");
 			ring->req_cons = ++rc;
 
 			ret = hyper_dmabuf_msg_parse(ring_info->sdomain, &req);
@@ -479,13 +478,11 @@ static irqreturn_t hyper_dmabuf_back_ring_isr(int irq, void *info)
 				RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(ring, notify);
 
 				if (notify) {
-					printk("Notyfing\n");
 					notify_remote_via_irq(ring_info->irq);
 				}
 			}
 
 			RING_FINAL_CHECK_FOR_REQUESTS(ring, more_to_do);
-			printk("Final check for requests %d\n", more_to_do);
 		}
 	} while (more_to_do);
 
@@ -541,7 +538,6 @@ static irqreturn_t hyper_dmabuf_front_ring_isr(int irq, void *info)
 
 		if (i != ring->req_prod_pvt) {
 			RING_FINAL_CHECK_FOR_RESPONSES(ring, more_to_do);
-			printk("more to do %d\n", more_to_do);
 		} else {
 			ring->sring->rsp_event = i+1;
 		}
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#25 lore raw

RFC PATCH 14/60 hyper_dmabuf: clean-up process based on file->f_count

In reply to Dongwon Kim

Now relaese funcs checks f_count for the file instead of our own refcount because it can't track dma_buf_get.

Also, importer now sends out HYPER_DMABUF_FIRST_EXPORT to let the exporter know corresponding dma-buf has ever exported on importer's side. This is to cover the case where exporter exports a buffer and unexport it right away before importer does first export_fd (there won't be any dma_buf_release nofication to exporter since SGT was never created by importer.)

After importer creates its own SGT, only condition it is completely released is that dma_buf is unexported (so valid == 0) and user app closes all locally assigned FDs (when dma_buf_release is called.) Otherwise, it needs to stay there since previously exported FD can be reused.

Also includes minor changes;

1. flag had been changed to "bool valid" for conciseness.
2. added bool importer_exported in sgt_info as an indicator for usage of buffer on the importer.
3. num of pages is added (nents) to hyper_dmabuf_sgt_info to keep the size info in EXPORT list.
3. more minor changes and clean-ups.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 76 ++++++++++++---------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        |  5 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 78 ++++++++++++----------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h       |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 34 ++++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  2 +
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 10 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     | 19 +++---
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  6 +-
 12 files changed, 143 insertions(+), 93 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +1 -0
index 5b5dae44..5a7cfa5 100644
@@ -33,6 +33,7 @@ static int hyper_dmabuf_drv_init(void)
 	/* device structure initialization */
 	/* currently only does work-queue initialization */
 	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
+	hyper_dmabuf_private.domid = hyper_dmabuf_get_domid();
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +1 -0
index 8778a19..ff883e1 100644
@@ -3,6 +3,7 @@
 
 struct hyper_dmabuf_private {
         struct device *device;
+	int domid;
 	struct workqueue_struct *work_queue;
 };
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +44 -32

169 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +4 -1
index 71c1bb0..1b0801f 100644
@@ -1,6 +1,7 @@
 #ifndef __HYPER_DMABUF_IMP_H__
 #define __HYPER_DMABUF_IMP_H__
 
+#include <linux/fs.h>
 #include "hyper_dmabuf_struct.h"
 
 /* extract pages directly from struct sg_table */
@@ -30,6 +31,8 @@ void hyper_dmabuf_free_sgt(struct sg_table *sgt);
 
 int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
 
-struct dma_buf* hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+void hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+
+int dmabuf_refcount(struct dma_buf *dma_buf);
 
 #endif /* __HYPER_DMABUF_IMP_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +44 -34

143 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +1 -1
index 1420df9..18731de 100644
@@ -65,7 +65,7 @@ struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id)
 }
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid)
+int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid)
 {
 	struct hyper_dmabuf_info_entry_exported *info_entry;
 	int bkt;
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +1 -1
index 463a6da..f55d06e 100644
@@ -25,7 +25,7 @@ int hyper_dmabuf_table_destroy(void);
 int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id(struct dma_buf *dmabuf, int domid);
+int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid);
 
 int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +29 -5
index 97b42a4..a2d687f 100644
@@ -55,6 +55,14 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 		request->operands[0] = operands[0];
 		break;
 
+	case HYPER_DMABUF_FIRST_EXPORT:
+		/* dmabuf fd is being created on imported side for first time */
+		/* command : HYPER_DMABUF_FIRST_EXPORT,
+		 * operands0 : hyper_dmabuf_id
+		 */
+		request->operands[0] = operands[0];
+		break;
+
 	case HYPER_DMABUF_OPS_TO_REMOTE:
 		/* notifying dmabuf map/unmap to importer (probably not needed) */
 		/* for dmabuf synchronization */
@@ -81,6 +89,7 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
 void cmd_process_work(struct work_struct *work)
 {
 	struct hyper_dmabuf_imported_sgt_info *imported_sgt_info;
+	struct hyper_dmabuf_sgt_info *sgt_info;
 	struct cmd_process *proc = container_of(work, struct cmd_process, work);
 	struct hyper_dmabuf_ring_rq *req;
 	int domid;
@@ -117,11 +126,25 @@ void cmd_process_work(struct work_struct *work)
 		for (i=0; i<4; i++)
 			imported_sgt_info->private[i] = req->operands[5+i];
 
-		imported_sgt_info->flags = 0;
-		imported_sgt_info->ref_count = 0;
+		imported_sgt_info->valid = 1;
 		hyper_dmabuf_register_imported(imported_sgt_info);
 		break;
 
+	case HYPER_DMABUF_FIRST_EXPORT:
+		/* find a corresponding SGT for the id */
+		sgt_info = hyper_dmabuf_find_exported(req->operands[0]);
+
+		if (!sgt_info) {
+			printk("critical err: requested sgt_info can't be found %d\n", req->operands[0]);
+			break;
+		}
+
+		if (sgt_info->importer_exported)
+			printk("warning: exported flag is not supposed to be 1 already\n");
+
+		sgt_info->importer_exported = 1;
+		break;
+
 	case HYPER_DMABUF_OPS_TO_REMOTE:
 		/* notifying dmabuf map/unmap to importer (probably not needed) */
 		/* for dmabuf synchronization */
@@ -170,13 +193,14 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req)
 			hyper_dmabuf_find_imported(req->operands[0]);
 
 		if (imported_sgt_info) {
-			/* check if buffer is still mapped and in use */
-			if (imported_sgt_info->sgt) {
+			/* if anything is still using dma_buf */
+			if (imported_sgt_info->dma_buf &&
+			    dmabuf_refcount(imported_sgt_info->dma_buf) > 0) {
 				/*
 				 * Buffer is still in  use, just mark that it should
 				 * not be allowed to export its fd anymore.
 				 */
-				imported_sgt_info->flags = HYPER_DMABUF_SGT_INVALID;
+				imported_sgt_info->valid = 0;
 			} else {
 				/* No one is using buffer, remove it from imported list */
 				hyper_dmabuf_remove_imported(req->operands[0]);
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +2 -0
index fc1365b..1e9d827 100644
@@ -3,6 +3,7 @@
 
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
+	HYPER_DMABUF_FIRST_EXPORT,
 	HYPER_DMABUF_NOTIFY_UNEXPORT,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
@@ -14,6 +15,7 @@ enum hyper_dmabuf_ops {
 	HYPER_DMABUF_OPS_MAP,
 	HYPER_DMABUF_OPS_UNMAP,
 	HYPER_DMABUF_OPS_RELEASE,
+	HYPER_DMABUF_OPS_RELEASE_FINAL,
 	HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS,
 	HYPER_DMABUF_OPS_END_CPU_ACCESS,
 	HYPER_DMABUF_OPS_KMAP_ATOMIC,
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +7 -3
index 61ba4ed..5017b17 100644
@@ -114,13 +114,13 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		kfree(sgtl);
 		break;
 
-	case HYPER_DMABUF_OPS_RELEASE:
+	case HYPER_DMABUF_OPS_RELEASE_FINAL:
 		/*
 		 * Importer just released buffer fd, check if there is any other importer still using it.
 		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
-		 if (list_empty(&sgt_info->active_sgts->list) &&                                                                  	    list_empty(&sgt_info->active_attached->list) &&
-		     sgt_info->flags == HYPER_DMABUF_SGT_UNEXPORTED) {
+		 if (list_empty(&sgt_info->active_attached->list) &&
+		     !sgt_info->valid) {
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 			hyper_dmabuf_remove_exported(id);
 			kfree(sgt_info);
@@ -128,6 +128,10 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 		break;
 
+	case HYPER_DMABUF_OPS_RELEASE:
+		/* place holder */
+		break;
+
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
 		ret = dma_buf_begin_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
 		if (!ret) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +8 -11
index 1194cf2..92e06ff 100644
@@ -6,10 +6,10 @@
 /* Importer combine source domain id with given hyper_dmabuf_id
  * to make it unique in case there are multiple exporters */
 
-#define HYPER_DMABUF_ID_IMPORTER(sdomain, id) \
-	((((sdomain) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+#define HYPER_DMABUF_ID_IMPORTER(domid, id) \
+	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
 
-#define HYPER_DMABUF_ID_IMPORTER_GET_SDOMAIN_ID(id) \
+#define HYPER_DMABUF_DOM_ID(id) \
 	(((id) >> 24) & 0xFF)
 
 /* each grant_ref_t is 4 bytes, so total 4096 grant_ref_t can be
@@ -18,11 +18,6 @@
  * frame buffer) */
 #define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
 
-enum hyper_dmabuf_sgt_flags {
-        HYPER_DMABUF_SGT_INVALID = 0x10,
-        HYPER_DMABUF_SGT_UNEXPORTED,
-};
-
 /* stack of mapped sgts */
 struct sgt_list {
 	struct sg_table *sgt;
@@ -77,11 +72,13 @@ struct hyper_dmabuf_sgt_info {
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
 
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
+	int nents; /* number of pages, which may be different than sgt->nents */
 	struct sgt_list *active_sgts;
 	struct attachment_list *active_attached;
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
-	int flags;
+	bool valid;
+	bool importer_exported; /* exported locally on importer's side */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
@@ -95,10 +92,10 @@ struct hyper_dmabuf_imported_sgt_info {
 	int last_len;	/* length of data in the last shared page */
 	int nents;	/* number of pages to be shared */
 	grant_ref_t gref; /* reference number of top level addressing page of shared pages */
+	struct dma_buf *dma_buf;
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
 	struct hyper_dmabuf_shared_pages_info shared_pages_info;
-	int flags;
-	int ref_count;
+	bool valid;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +1 -5
index 116850e..f9e0df3 100644
@@ -456,13 +456,12 @@ static irqreturn_t hyper_dmabuf_back_ring_isr(int irq, void *info)
 	do {
 		rc = ring->req_cons;
 		rp = ring->sring->req_prod;
-
+		more_to_do = 0;
 		while (rc != rp) {
 			if (RING_REQUEST_CONS_OVERFLOW(ring, rc))
 				break;
 
 			memcpy(&req, RING_GET_REQUEST(ring, rc), sizeof(req));
-			printk("Got request\n");
 			ring->req_cons = ++rc;
 
 			ret = hyper_dmabuf_msg_parse(ring_info->sdomain, &req);
@@ -479,13 +478,11 @@ static irqreturn_t hyper_dmabuf_back_ring_isr(int irq, void *info)
 				RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(ring, notify);
 
 				if (notify) {
-					printk("Notyfing\n");
 					notify_remote_via_irq(ring_info->irq);
 				}
 			}
 
 			RING_FINAL_CHECK_FOR_REQUESTS(ring, more_to_do);
-			printk("Final check for requests %d\n", more_to_do);
 		}
 	} while (more_to_do);
 
@@ -541,7 +538,6 @@ static irqreturn_t hyper_dmabuf_front_ring_isr(int irq, void *info)
 
 		if (i != ring->req_prod_pvt) {
 			RING_FINAL_CHECK_FOR_RESPONSES(ring, more_to_do);
-			printk("more to do %d\n", more_to_do);
 		} else {
 			ring->sring->rsp_event = i+1;
 		}
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#26 lore raw

RFC PATCH 15/60 hyper_dmabuf: reusing previously released hyper_dmabuf_id

In reply to Dongwon Kim

Now, released hyper_dmabuf_ids are stored in a stack - (hyper_dmabuf_private.id_queue) for reuse. This is to prevent overflow of ids for buffers. We also limit maximum number for the id to 1000 for the stability and optimal performance.

---
 drivers/xen/hyper_dmabuf/Makefile                  |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  5 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  6 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         | 76 ++++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h         | 24 +++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 15 ++---
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |  3 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  9 ---
 9 files changed, 120 insertions(+), 20 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h
drivers/xen/hyper_dmabuf/Makefile +1 -0
index 3459382..c9b8b7f 100644
@@ -7,6 +7,7 @@ ifneq ($(KERNELRELEASE),)
                                  hyper_dmabuf_list.o \
 				 hyper_dmabuf_imp.o \
 				 hyper_dmabuf_msg.o \
+				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
 				 xen/hyper_dmabuf_xen_comm.o \
 				 xen/hyper_dmabuf_xen_comm_list.o
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +5 -0
index 5a7cfa5..66d6cb9 100644
@@ -5,6 +5,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 
@@ -67,6 +68,10 @@ static void hyper_dmabuf_drv_exit(void)
 	if (hyper_dmabuf_private.work_queue)
 		destroy_workqueue(hyper_dmabuf_private.work_queue);
 
+	/* destroy id_queue */
+	if (hyper_dmabuf_private.id_queue)
+		destroy_reusable_list();
+
 	hyper_dmabuf_destroy_data_dir();
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +6 -0
index ff883e1..37b0cc1 100644
@@ -1,10 +1,16 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
+struct list_reusable_id {
+	int id;
+	struct list_head list;
+};
+
 struct hyper_dmabuf_private {
         struct device *device;
 	int domid;
 	struct workqueue_struct *work_queue;
+	struct list_reusable_id *id_queue;
 };
 
 typedef int (*hyper_dmabuf_ioctl_t)(void *data);
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c new file +76 -0

76 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h new file +24 -0
new file mode 100644
index 0000000..2c8daf3
@@ -0,0 +1,24 @@
+#ifndef __HYPER_DMABUF_ID_H__
+#define __HYPER_DMABUF_ID_H__
+
+/* Importer combine source domain id with given hyper_dmabuf_id
+ * to make it unique in case there are multiple exporters */
+
+#define HYPER_DMABUF_ID_CREATE(domid, id) \
+	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+
+#define HYPER_DMABUF_DOM_ID(id) \
+	(((id) >> 24) & 0xFF)
+
+/* currently maximum number of buffers shared
+ * at any given moment is limited to 1000
+ */
+#define HYPER_DMABUF_ID_MAX 1000
+
+void store_reusable_id(int id);
+
+void destroy_reusable_list(void);
+
+int hyper_dmabuf_get_id(void);
+
+#endif /*__HYPER_DMABUF_ID_H*/
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +1 -0
index fa445e5..b109138 100644
@@ -7,6 +7,7 @@
 #include <asm/xen/page.h>
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_imp.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_list.h"
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +4 -11
index e334b77..5c6d9c8 100644
@@ -11,6 +11,7 @@
 #include "hyper_dmabuf_imp.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_id.h"
 #include "hyper_dmabuf_query.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
@@ -18,16 +19,6 @@
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
-static uint32_t hyper_dmabuf_id_gen(void) {
-	/* TODO: add proper implementation */
-	static uint32_t id = 1000;
-	static int32_t domid = -1;
-	if (domid == -1) {
-		domid = hyper_dmabuf_get_domid();
-	}
-	return HYPER_DMABUF_ID_IMPORTER(domid, id++);
-}
-
 static int hyper_dmabuf_exporter_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_exporter_ring_setup *ring_attr;
@@ -133,7 +124,7 @@ static int hyper_dmabuf_export_remote(void *data)
 
 	sgt_info = kmalloc(sizeof(*sgt_info), GFP_KERNEL);
 
-	sgt_info->hyper_dmabuf_id = hyper_dmabuf_id_gen();
+	sgt_info->hyper_dmabuf_id = hyper_dmabuf_get_id();
 	/* TODO: We might need to consider using port number on event channel? */
 	sgt_info->hyper_dmabuf_rdomain = export_remote_attr->remote_domain;
 	sgt_info->dma_buf = dma_buf;
@@ -334,6 +325,8 @@ static int hyper_dmabuf_unexport(void *data)
 		hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 		hyper_dmabuf_remove_exported(unexport_attr->hyper_dmabuf_id);
 		kfree(sgt_info);
+		/* register hyper_dmabuf_id to the list for reuse */
+		store_reusable_id(unexport_attr->hyper_dmabuf_id);
 	}
 
 	return ret;
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +3 -0
index 5017b17..c5950e0 100644
@@ -6,6 +6,7 @@
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_imp.h"
@@ -124,6 +125,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 			hyper_dmabuf_remove_exported(id);
 			kfree(sgt_info);
+			/* store hyper_dmabuf_id in the list for reuse */
+			store_reusable_id(id);
 		}
 
 		break;
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +0 -9
index 92e06ff..b52f958 100644
@@ -3,15 +3,6 @@
 
 #include <xen/interface/grant_table.h>
 
-/* Importer combine source domain id with given hyper_dmabuf_id
- * to make it unique in case there are multiple exporters */
-
-#define HYPER_DMABUF_ID_IMPORTER(domid, id) \
-	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
-
-#define HYPER_DMABUF_DOM_ID(id) \
-	(((id) >> 24) & 0xFF)
-
 /* each grant_ref_t is 4 bytes, so total 4096 grant_ref_t can be
  * in this block meaning we can share 4KB*4096 = 16MB of buffer
  * (needs to be increased for large buffer use-cases such as 4K
Signature · 1 line
2.7.4
#27 lore raw

RFC PATCH 15/60 hyper_dmabuf: reusing previously released hyper_dmabuf_id

In reply to Dongwon Kim

Now, released hyper_dmabuf_ids are stored in a stack - (hyper_dmabuf_private.id_queue) for reuse. This is to prevent overflow of ids for buffers. We also limit maximum number for the id to 1000 for the stability and optimal performance.

---
 drivers/xen/hyper_dmabuf/Makefile                  |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  5 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  6 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         | 76 ++++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h         | 24 +++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 15 ++---
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |  3 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  9 ---
 9 files changed, 120 insertions(+), 20 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h
drivers/xen/hyper_dmabuf/Makefile +1 -0
index 3459382..c9b8b7f 100644
@@ -7,6 +7,7 @@ ifneq ($(KERNELRELEASE),)
                                  hyper_dmabuf_list.o \
 				 hyper_dmabuf_imp.o \
 				 hyper_dmabuf_msg.o \
+				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
 				 xen/hyper_dmabuf_xen_comm.o \
 				 xen/hyper_dmabuf_xen_comm_list.o
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +5 -0
index 5a7cfa5..66d6cb9 100644
@@ -5,6 +5,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_list.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 
@@ -67,6 +68,10 @@ static void hyper_dmabuf_drv_exit(void)
 	if (hyper_dmabuf_private.work_queue)
 		destroy_workqueue(hyper_dmabuf_private.work_queue);
 
+	/* destroy id_queue */
+	if (hyper_dmabuf_private.id_queue)
+		destroy_reusable_list();
+
 	hyper_dmabuf_destroy_data_dir();
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +6 -0
index ff883e1..37b0cc1 100644
@@ -1,10 +1,16 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
+struct list_reusable_id {
+	int id;
+	struct list_head list;
+};
+
 struct hyper_dmabuf_private {
         struct device *device;
 	int domid;
 	struct workqueue_struct *work_queue;
+	struct list_reusable_id *id_queue;
 };
 
 typedef int (*hyper_dmabuf_ioctl_t)(void *data);
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c new file +76 -0

76 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h new file +24 -0
new file mode 100644
index 0000000..2c8daf3
@@ -0,0 +1,24 @@
+#ifndef __HYPER_DMABUF_ID_H__
+#define __HYPER_DMABUF_ID_H__
+
+/* Importer combine source domain id with given hyper_dmabuf_id
+ * to make it unique in case there are multiple exporters */
+
+#define HYPER_DMABUF_ID_CREATE(domid, id) \
+	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
+
+#define HYPER_DMABUF_DOM_ID(id) \
+	(((id) >> 24) & 0xFF)
+
+/* currently maximum number of buffers shared
+ * at any given moment is limited to 1000
+ */
+#define HYPER_DMABUF_ID_MAX 1000
+
+void store_reusable_id(int id);
+
+void destroy_reusable_list(void);
+
+int hyper_dmabuf_get_id(void);
+
+#endif /*__HYPER_DMABUF_ID_H*/
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +1 -0
index fa445e5..b109138 100644
@@ -7,6 +7,7 @@
 #include <asm/xen/page.h>
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_imp.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_list.h"
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +4 -11
index e334b77..5c6d9c8 100644
@@ -11,6 +11,7 @@
 #include "hyper_dmabuf_imp.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_id.h"
 #include "hyper_dmabuf_query.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "xen/hyper_dmabuf_xen_comm_list.h"
@@ -18,16 +19,6 @@
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
-static uint32_t hyper_dmabuf_id_gen(void) {
-	/* TODO: add proper implementation */
-	static uint32_t id = 1000;
-	static int32_t domid = -1;
-	if (domid == -1) {
-		domid = hyper_dmabuf_get_domid();
-	}
-	return HYPER_DMABUF_ID_IMPORTER(domid, id++);
-}
-
 static int hyper_dmabuf_exporter_ring_setup(void *data)
 {
 	struct ioctl_hyper_dmabuf_exporter_ring_setup *ring_attr;
@@ -133,7 +124,7 @@ static int hyper_dmabuf_export_remote(void *data)
 
 	sgt_info = kmalloc(sizeof(*sgt_info), GFP_KERNEL);
 
-	sgt_info->hyper_dmabuf_id = hyper_dmabuf_id_gen();
+	sgt_info->hyper_dmabuf_id = hyper_dmabuf_get_id();
 	/* TODO: We might need to consider using port number on event channel? */
 	sgt_info->hyper_dmabuf_rdomain = export_remote_attr->remote_domain;
 	sgt_info->dma_buf = dma_buf;
@@ -334,6 +325,8 @@ static int hyper_dmabuf_unexport(void *data)
 		hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 		hyper_dmabuf_remove_exported(unexport_attr->hyper_dmabuf_id);
 		kfree(sgt_info);
+		/* register hyper_dmabuf_id to the list for reuse */
+		store_reusable_id(unexport_attr->hyper_dmabuf_id);
 	}
 
 	return ret;
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +3 -0
index 5017b17..c5950e0 100644
@@ -6,6 +6,7 @@
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_id.h"
 #include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_imp.h"
@@ -124,6 +125,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 			hyper_dmabuf_remove_exported(id);
 			kfree(sgt_info);
+			/* store hyper_dmabuf_id in the list for reuse */
+			store_reusable_id(id);
 		}
 
 		break;
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +0 -9
index 92e06ff..b52f958 100644
@@ -3,15 +3,6 @@
 
 #include <xen/interface/grant_table.h>
 
-/* Importer combine source domain id with given hyper_dmabuf_id
- * to make it unique in case there are multiple exporters */
-
-#define HYPER_DMABUF_ID_IMPORTER(domid, id) \
-	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
-
-#define HYPER_DMABUF_DOM_ID(id) \
-	(((id) >> 24) & 0xFF)
-
 /* each grant_ref_t is 4 bytes, so total 4096 grant_ref_t can be
  * in this block meaning we can share 4KB*4096 = 16MB of buffer
  * (needs to be increased for large buffer use-cases such as 4K
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#28 lore raw

RFC PATCH 16/60 hyper_dmabuf: define hypervisor specific backend API

In reply to Dongwon Kim

For adoption of hyper_dmabuf driver to various hypervisors other than Xen, a "backend" layer is defined and separated out from existing one-body structure.

"Backend" is basically a list of entry points of function calls that provides method to do Kernel's page-level sharing and inter VMs communication using hypervisor's native mechanism (hypercall).

All backend APIs are listed up in "struct hyper_dmabuf_backend_ops" as shown below.

struct hyper_dmabuf_backend_ops {
        /* retreiving id of current virtual machine */
        int (*get_vm_id)(void);

        /* get pages shared via hypervisor-specific method */
        int (*share_pages)(struct page **, int, int, void **);

        /* make shared pages unshared via hypervisor specific method */
        int (*unshare_pages)(void **, int);

        /* map remotely shared pages on importer's side via
         * hypervisor-specific method
         */
        struct page ** (*map_shared_pages)(int, int, int, void **);

        /* unmap and free shared pages on importer's side via
         * hypervisor-specific method
         */
        int (*unmap_shared_pages)(void **, int);

        /* initialize communication environment */
        int (*init_comm_env)(void);

        void (*destroy_comm)(void);

        /* upstream ch setup (receiving and responding) */
        int (*init_rx_ch)(int);

        /* downstream ch setup (transmitting and parsing responses) */
        int (*init_tx_ch)(int);

        int (*send_req)(int, struct hyper_dmabuf_req *, int);
};

Within this new structure, only backend APIs need to be re-designed or replaced with new ones when porting this sharing model to a different hypervisor environment, which is a lot simpler than completely redesiging whole driver for a new hypervisor.

---
 drivers/xen/hyper_dmabuf/Makefile                  |  11 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h       |   1 -
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  33 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        | 112 ++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         |   6 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 426 ++-------------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        |  14 -
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 134 +++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h      |  87 +++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  52 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  23 +-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |   4 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  26 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 303 +++++++++------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |  51 +--
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  67 ++--
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h  |  32 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c    |  22 ++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.h    |  20 +
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 356 +++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.h    |  19 +
 21 files changed, 949 insertions(+), 850 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.h
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c
 create mode 100644 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.h
drivers/xen/hyper_dmabuf/Makefile +9 -2
index c9b8b7f..d90cfc3 100644
@@ -1,5 +1,7 @@
 TARGET_MODULE:=hyper_dmabuf
 
+PLATFORM:=XEN
+
 # If we running by kernel building system
 ifneq ($(KERNELRELEASE),)
 	$(TARGET_MODULE)-objs := hyper_dmabuf_drv.o \
@@ -9,8 +11,13 @@ ifneq ($(KERNELRELEASE),)
 				 hyper_dmabuf_msg.o \
 				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
-				 xen/hyper_dmabuf_xen_comm.o \
-				 xen/hyper_dmabuf_xen_comm_list.o
+
+ifeq ($(CONFIG_XEN), y)
+	$(TARGET_MODULE)-objs += xen/hyper_dmabuf_xen_comm.o \
+				 xen/hyper_dmabuf_xen_comm_list.o \
+				 xen/hyper_dmabuf_xen_shm.o \
+				 xen/hyper_dmabuf_xen_drv.o
+endif
 
 obj-$(CONFIG_HYPER_DMABUF) := $(TARGET_MODULE).o
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h +0 -1
index 3d9b2d6..d012b05 100644
@@ -1,2 +1 @@
 #define CURRENT_TARGET XEN
-#define INTER_DOMAIN_DMABUF_SYNCHRONIZATION
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +17 -16
index 66d6cb9..ddcc955 100644
@@ -1,15 +1,18 @@
-#include <linux/init.h>       /* module_init, module_exit */
-#include <linux/module.h> /* version info, MODULE_LICENSE, MODULE_AUTHOR, printk() */
+#include <linux/init.h>
+#include <linux/module.h>
 #include <linux/workqueue.h>
-#include <xen/grant_table.h>
-#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
+#include "hyper_dmabuf_msg.h"
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_id.h"
-#include "xen/hyper_dmabuf_xen_comm_list.h"
-#include "xen/hyper_dmabuf_xen_comm.h"
 
-MODULE_LICENSE("Dual BSD/GPL");
+#ifdef CONFIG_XEN
+#include "xen/hyper_dmabuf_xen_drv.h"
+extern struct hyper_dmabuf_backend_ops xen_backend_ops;
+#endif
+
+MODULE_LICENSE("GPL");
 MODULE_AUTHOR("IOTG-PED, INTEL");
 
 int register_device(void);
@@ -29,24 +32,24 @@ static int hyper_dmabuf_drv_init(void)
 		return -EINVAL;
 	}
 
+#ifdef CONFIG_XEN
+	hyper_dmabuf_private.backend_ops = &xen_backend_ops;
+#endif
+
 	printk( KERN_NOTICE "initializing database for imported/exported dmabufs\n");
 
 	/* device structure initialization */
 	/* currently only does work-queue initialization */
 	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
-	hyper_dmabuf_private.domid = hyper_dmabuf_get_domid();
+	hyper_dmabuf_private.domid = hyper_dmabuf_private.backend_ops->get_vm_id();
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
 		return -EINVAL;
 	}
 
-	ret = hyper_dmabuf_ring_table_init();
-	if (ret < 0) {
-		return -EINVAL;
-	}
+	ret = hyper_dmabuf_private.backend_ops->init_comm_env();
 
-	ret = hyper_dmabuf_setup_data_dir();
 	if (ret < 0) {
 		return -EINVAL;
 	}
@@ -61,8 +64,7 @@ static void hyper_dmabuf_drv_exit(void)
 	/* hash tables for export/import entries and ring_infos */
 	hyper_dmabuf_table_destroy();
 
-	hyper_dmabuf_cleanup_ringbufs();
-	hyper_dmabuf_ring_table_destroy();
+	hyper_dmabuf_private.backend_ops->destroy_comm();
 
 	/* destroy workqueue */
 	if (hyper_dmabuf_private.work_queue)
@@ -72,7 +74,6 @@ static void hyper_dmabuf_drv_exit(void)
 	if (hyper_dmabuf_private.id_queue)
 		destroy_reusable_list();
 
-	hyper_dmabuf_destroy_data_dir();
 	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
 	unregister_device();
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +33 -79

127 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +5 -1
index 7bbb179..b58a111 100644
@@ -1,5 +1,6 @@
 #include <linux/list.h>
 #include <linux/slab.h>
+#include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_id.h"
 
@@ -19,6 +20,7 @@ void store_reusable_id(int id)
 static int retrieve_reusable_id(void)
 {
 	struct list_reusable_id *reusable_head = hyper_dmabuf_private.id_queue;
+	int id;
 
 	/* check there is reusable id */
 	if (!list_empty(&reusable_head->list)) {
@@ -27,7 +29,9 @@ static int retrieve_reusable_id(void)
 						 list);
 
 		list_del(&reusable_head->list);
-		return reusable_head->id;
+		id = reusable_head->id;
+		kfree(reusable_head);
+		return id;
 	}
 
 	return -1;
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +25 -401

488 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +0 -14
index 1b0801f..a4a6d63 100644
@@ -11,20 +11,6 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt);
 struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
                                 int frst_ofst, int last_len, int nents);
 
-grant_ref_t hyper_dmabuf_create_gref_table(struct page **pages, int rdomain, int nents,
-					   struct hyper_dmabuf_shared_pages_info *shared_pages_info);
-
-int hyper_dmabuf_cleanup_gref_table(struct hyper_dmabuf_sgt_info *sgt_info);
-
-int hyper_dmabuf_cleanup_imported_pages(struct hyper_dmabuf_imported_sgt_info *sgt_info);
-
-/* map first level tables that contains reference numbers for actual shared pages */
-grant_ref_t *hyper_dmabuf_map_gref_table(grant_ref_t *gref_table, int n_pages_table);
-
-/* map and construct sg_lists from reference numbers */
-struct sg_table* hyper_dmabuf_map_pages(grant_ref_t gref, int frst_ofst, int last_len, int nents, int sdomain,
-					struct hyper_dmabuf_shared_pages_info *shared_pages_info);
-
 int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int force);
 
 void hyper_dmabuf_free_sgt(struct sg_table *sgt);
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +63 -71

242 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h new file +87 -0

87 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +23 -29

140 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +20 -3
index 1e9d827..ac4caeb 100644
@@ -1,6 +1,22 @@
 #ifndef __HYPER_DMABUF_MSG_H__
 #define __HYPER_DMABUF_MSG_H__
 
+#define MAX_NUMBER_OF_OPERANDS 9
+
+struct hyper_dmabuf_req {
+	unsigned int request_id;
+	unsigned int status;
+	unsigned int command;
+	unsigned int operands[MAX_NUMBER_OF_OPERANDS];
+};
+
+struct hyper_dmabuf_resp {
+	unsigned int response_id;
+	unsigned int status;
+	unsigned int command;
+	unsigned int operands[MAX_NUMBER_OF_OPERANDS];
+};
+
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
 	HYPER_DMABUF_FIRST_EXPORT,
@@ -35,10 +51,11 @@ enum hyper_dmabuf_req_feedback {
 };
 
 /* create a request packet with given command and operands */
-void hyper_dmabuf_create_request(struct hyper_dmabuf_ring_rq *request,
-                                        enum hyper_dmabuf_command command, int *operands);
+void hyper_dmabuf_create_request(struct hyper_dmabuf_req *req,
+				 enum hyper_dmabuf_command command,
+				 int *operands);
 
 /* parse incoming request packet (or response) and take appropriate actions for those */
-int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_ring_rq *req);
+int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req);
 
 #endif // __HYPER_DMABUF_MSG_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +3 -1
index c5950e0..0f4735c 100644
@@ -5,9 +5,9 @@
 #include <linux/dma-buf.h>
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_list.h"
+#include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_id.h"
-#include "xen/hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_imp.h"
 
@@ -133,6 +133,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_RELEASE:
 		/* place holder */
+                sgt_info->importer_exported--;
+
 		break;
 
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +5 -21
index b52f958..f053dd10 100644
@@ -1,14 +1,6 @@
 #ifndef __HYPER_DMABUF_STRUCT_H__
 #define __HYPER_DMABUF_STRUCT_H__
 
-#include <xen/interface/grant_table.h>
-
-/* each grant_ref_t is 4 bytes, so total 4096 grant_ref_t can be
- * in this block meaning we can share 4KB*4096 = 16MB of buffer
- * (needs to be increased for large buffer use-cases such as 4K
- * frame buffer) */
-#define MAX_ALLOWED_NUM_PAGES_FOR_GREF_NUM_ARRAYS 4
-
 /* stack of mapped sgts */
 struct sgt_list {
 	struct sg_table *sgt;
@@ -33,15 +25,6 @@ struct vmap_vaddr_list {
 	struct list_head list;
 };
 
-struct hyper_dmabuf_shared_pages_info {
-	grant_ref_t *data_refs;	/* table with shared buffer pages refid */
-	grant_ref_t *addr_pages; /* pages of 2nd level addressing */
-	grant_ref_t *top_level_page; /* page of top level addressing, it contains refids of 2nd level pages */
-	grant_ref_t top_level_ref; /* top level refid */
-	struct gnttab_unmap_grant_ref* unmap_ops; /* unmap ops for mapped pages */
-	struct page **data_pages; /* data pages to be unmapped */
-};
-
 /* Exporter builds pages_info before sharing pages */
 struct hyper_dmabuf_pages_info {
         int hyper_dmabuf_id; /* unique id to reference dmabuf in source domain */
@@ -69,8 +52,8 @@ struct hyper_dmabuf_sgt_info {
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
 	bool valid;
-	bool importer_exported; /* exported locally on importer's side */
-	struct hyper_dmabuf_shared_pages_info shared_pages_info;
+	int importer_exported; /* exported locally on importer's side */
+	void *refs_info; /* hypervisor-specific info for the references */
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
@@ -79,14 +62,15 @@ struct hyper_dmabuf_sgt_info {
  * its own memory map once userspace asks for reference for the buffer */
 struct hyper_dmabuf_imported_sgt_info {
 	int hyper_dmabuf_id; /* unique id to reference dmabuf (HYPER_DMABUF_ID_IMPORTER(source domain id, exporter's hyper_dmabuf_id */
+	int ref_handle; /* reference number of top level addressing page of shared pages */
 	int frst_ofst;	/* start offset in shared page #1 */
 	int last_len;	/* length of data in the last shared page */
 	int nents;	/* number of pages to be shared */
-	grant_ref_t gref; /* reference number of top level addressing page of shared pages */
 	struct dma_buf *dma_buf;
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
-	struct hyper_dmabuf_shared_pages_info shared_pages_info;
+	void *refs_info;
 	bool valid;
+	int num_importers;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +179 -124

561 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +17 -34

83 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +31 -36

147 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h +15 -17
index fd1958c..18b3afd 100644
@@ -2,40 +2,38 @@
 #define __HYPER_DMABUF_XEN_COMM_LIST_H__
 
 /* number of bits to be used for exported dmabufs hash table */
-#define MAX_ENTRY_EXPORT_RING 7
+#define MAX_ENTRY_TX_RING 7
 /* number of bits to be used for imported dmabufs hash table */
-#define MAX_ENTRY_IMPORT_RING 7
+#define MAX_ENTRY_RX_RING 7
 
-struct hyper_dmabuf_exporter_ring_info {
-        struct hyper_dmabuf_ring_info_export *info;
+struct xen_comm_tx_ring_info_entry {
+        struct xen_comm_tx_ring_info *info;
         struct hlist_node node;
 };
 
-struct hyper_dmabuf_importer_ring_info {
-        struct hyper_dmabuf_ring_info_import *info;
+struct xen_comm_rx_ring_info_entry {
+        struct xen_comm_rx_ring_info *info;
         struct hlist_node node;
 };
 
-int hyper_dmabuf_ring_table_init(void);
+void xen_comm_ring_table_init(void);
 
-int hyper_dmabuf_ring_table_destroy(void);
+int xen_comm_add_tx_ring(struct xen_comm_tx_ring_info *ring_info);
 
-int hyper_dmabuf_register_exporter_ring(struct hyper_dmabuf_ring_info_export *ring_info);
+int xen_comm_add_rx_ring(struct xen_comm_rx_ring_info *ring_info);
 
-int hyper_dmabuf_register_importer_ring(struct hyper_dmabuf_ring_info_import *ring_info);
+int xen_comm_remove_tx_ring(int domid);
 
-struct hyper_dmabuf_ring_info_export *hyper_dmabuf_find_exporter_ring(int domid);
+int xen_comm_remove_rx_ring(int domid);
 
-struct hyper_dmabuf_ring_info_import *hyper_dmabuf_find_importer_ring(int domid);
+struct xen_comm_tx_ring_info *xen_comm_find_tx_ring(int domid);
 
-int hyper_dmabuf_remove_exporter_ring(int domid);
-
-int hyper_dmabuf_remove_importer_ring(int domid);
+struct xen_comm_rx_ring_info *xen_comm_find_rx_ring(int domid);
 
 /* iterates over all exporter rings and calls provided function for each of them */
-void hyper_dmabuf_foreach_exporter_ring(void (*func)(int rdom));
+void xen_comm_foreach_tx_ring(void (*func)(int domid));
 
 /* iterates over all importer rings and calls provided function for each of them */
-void hyper_dmabuf_foreach_importer_ring(void (*func)(int sdom));
+void xen_comm_foreach_rx_ring(void (*func)(int domid));
 
 #endif // __HYPER_DMABUF_XEN_COMM_LIST_H__
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c new file +22 -0
new file mode 100644
index 0000000..e7b871a
@@ -0,0 +1,22 @@
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <xen/grant_table.h>
+#include "../hyper_dmabuf_msg.h"
+#include "../hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_xen_drv.h"
+#include "hyper_dmabuf_xen_comm.h"
+#include "hyper_dmabuf_xen_shm.h"
+
+struct hyper_dmabuf_backend_ops xen_backend_ops = {
+	.get_vm_id = hyper_dmabuf_get_domid,
+	.share_pages = hyper_dmabuf_xen_share_pages,
+	.unshare_pages = hyper_dmabuf_xen_unshare_pages,
+	.map_shared_pages = (void *)hyper_dmabuf_xen_map_shared_pages,
+	.unmap_shared_pages = hyper_dmabuf_xen_unmap_shared_pages,
+	.init_comm_env = hyper_dmabuf_xen_init_comm_env,
+	.destroy_comm = hyper_dmabuf_xen_destroy_comm,
+	.init_rx_ch = hyper_dmabuf_xen_init_rx_rbuf,
+	.init_tx_ch = hyper_dmabuf_xen_init_tx_rbuf,
+	.send_req = hyper_dmabuf_xen_send_req,
+};
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.h new file +20 -0
new file mode 100644
index 0000000..e351c08
@@ -0,0 +1,20 @@
+#ifndef __HYPER_DMABUF_XEN_DRV_H__
+#define __HYPER_DMABUF_XEN_DRV_H__
+#include <xen/interface/grant_table.h>
+
+extern struct hyper_dmabuf_backend_ops xen_backend_ops;
+
+/* Main purpose of this structure is to keep
+ * all references created or acquired for sharing
+ * pages with another domain for freeing those later
+ * when unsharing.
+ */
+struct xen_shared_pages_info {
+        grant_ref_t lvl3_gref; /* top level refid */
+        grant_ref_t *lvl3_table; /* page of top level addressing, it contains refids of 2nd level pages */
+        grant_ref_t *lvl2_table; /* table of 2nd level pages, that contains refids to data pages */
+        struct gnttab_unmap_grant_ref* unmap_ops; /* unmap ops for mapped pages */
+        struct page **data_pages; /* data pages to be unmapped */
+};
+
+#endif // __HYPER_DMABUF_XEN_COMM_H__
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c new file +356 -0

356 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.h new file +19 -0
new file mode 100644
index 0000000..2287804
@@ -0,0 +1,19 @@
+#ifndef __HYPER_DMABUF_XEN_SHM_H__
+#define __HYPER_DMABUF_XEN_SHM_H__
+
+/* This collects all reference numbers for 2nd level shared pages and create a table
+ * with those in 1st level shared pages then return reference numbers for this top level
+ * table. */
+int hyper_dmabuf_xen_share_pages(struct page **pages, int domid, int nents,
+				 void **refs_info);
+
+int hyper_dmabuf_xen_unshare_pages(void **refs_info, int nents);
+
+/* Maps provided top level ref id and then return array of pages containing data refs.
+ */
+struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int nents,
+						void **refs_info);
+
+int hyper_dmabuf_xen_unmap_shared_pages(void **refs_info, int nents);
+
+#endif /* __HYPER_DMABUF_XEN_SHM_H__ */
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#29 lore raw

RFC PATCH 17/60 hyper_dmabuf: use dynamic debug macros for logging

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Replaces printk to debug macros

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  4 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  4 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 46 +++++++++-----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 50 +++++++++------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 26 +++++---
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 60 ++++++++++++------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 73 +++++++++++++++-------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 50 +++++++++------
 8 files changed, 206 insertions(+), 107 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +3 -1
index ddcc955..9d99769 100644
@@ -1,6 +1,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/workqueue.h>
+#include <linux/device.h>
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_drv.h"
@@ -36,7 +37,8 @@ static int hyper_dmabuf_drv_init(void)
 	hyper_dmabuf_private.backend_ops = &xen_backend_ops;
 #endif
 
-	printk( KERN_NOTICE "initializing database for imported/exported dmabufs\n");
+	dev_info(hyper_dmabuf_private.device,
+		 "initializing database for imported/exported dmabufs\n");
 
 	/* device structure initialization */
 	/* currently only does work-queue initialization */
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +4 -0
index 03d77d7..c16e8d4 100644
@@ -1,6 +1,10 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
+#include <linux/device.h>
+
+struct hyper_dmabuf_req;
+
 struct list_reusable_id {
 	int id;
 	struct list_head list;
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +30 -16

142 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +31 -19

166 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +16 -10
index 4647115..9c38900 100644
@@ -114,12 +114,12 @@ void cmd_process_work(struct work_struct *work)
 		imported_sgt_info->nents = req->operands[1];
 		imported_sgt_info->ref_handle = req->operands[4];
 
-		printk("DMABUF was exported\n");
-		printk("\thyper_dmabuf_id %d\n", req->operands[0]);
-		printk("\tnents %d\n", req->operands[1]);
-		printk("\tfirst offset %d\n", req->operands[2]);
-		printk("\tlast len %d\n", req->operands[3]);
-		printk("\tgrefid %d\n", req->operands[4]);
+		dev_dbg(hyper_dmabuf_private.device, "DMABUF was exported\n");
+		dev_dbg(hyper_dmabuf_private.device, "\thyper_dmabuf_id %d\n", req->operands[0]);
+		dev_dbg(hyper_dmabuf_private.device, "\tnents %d\n", req->operands[1]);
+		dev_dbg(hyper_dmabuf_private.device, "\tfirst offset %d\n", req->operands[2]);
+		dev_dbg(hyper_dmabuf_private.device, "\tlast len %d\n", req->operands[3]);
+		dev_dbg(hyper_dmabuf_private.device, "\tgrefid %d\n", req->operands[4]);
 
 		for (i=0; i<4; i++)
 			imported_sgt_info->private[i] = req->operands[5+i];
@@ -133,7 +133,8 @@ void cmd_process_work(struct work_struct *work)
 		sgt_info = hyper_dmabuf_find_exported(req->operands[0]);
 
 		if (!sgt_info) {
-			printk("critical err: requested sgt_info can't be found %d\n", req->operands[0]);
+			dev_err(hyper_dmabuf_private.device,
+				"critical err: requested sgt_info can't be found %d\n", req->operands[0]);
 			break;
 		}
 
@@ -163,13 +164,13 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	int ret;
 
 	if (!req) {
-		printk("request is NULL\n");
+		dev_err(hyper_dmabuf_private.device, "request is NULL\n");
 		return -EINVAL;
 	}
 
 	if ((req->command < HYPER_DMABUF_EXPORT) ||
 		(req->command > HYPER_DMABUF_OPS_TO_SOURCE)) {
-		printk("invalid command\n");
+		dev_err(hyper_dmabuf_private.device, "invalid command\n");
 		return -EINVAL;
 	}
 
@@ -183,7 +184,8 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		/* command : HYPER_DMABUF_NOTIFY_UNEXPORT,
 		 * operands0 : hyper_dmabuf_id
 		 */
-
+		dev_dbg(hyper_dmabuf_private.device,
+			"%s: processing HYPER_DMABUF_NOTIFY_UNEXPORT\n", __func__);
 		sgt_info = hyper_dmabuf_find_imported(req->operands[0]);
 
 		if (sgt_info) {
@@ -216,6 +218,8 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		 * operands0 : hyper_dmabuf_id
 		 * operands1 : enum hyper_dmabuf_ops {....}
 		 */
+		dev_dbg(hyper_dmabuf_private.device,
+			"%s: HYPER_DMABUF_OPS_TO_SOURCE\n", __func__);
 		ret = hyper_dmabuf_remote_sync(req->operands[0], req->operands[1]);
 		if (ret)
 			req->status = HYPER_DMABUF_REQ_ERROR;
@@ -225,6 +229,8 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		return req->command;
 	}
 
+	dev_dbg(hyper_dmabuf_private.device,
+		"%s: putting request to workqueue\n", __func__);
 	temp_req = kmalloc(sizeof(*temp_req), GFP_KERNEL);
 
 	memcpy(temp_req, req, sizeof(*temp_req));
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +40 -20

149 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +50 -23

209 lines not on this page · raw message

drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +32 -18

198 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#30 lore raw

RFC PATCH 18/60 hyper_dmabuf: reset comm channel when one end has disconnected.

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

When exporter or importer is disconnected, ring buffer should be reinitialzed, otherwise on next reconnection exporter/importer will receive old requests/responses remaining in the ring buffer, which are not valid anymore.

This patch also blocks back ring irq until communication channel is initialized and fully active to prevent a race condition.

---
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +21 -3
index 5e7a250..b629032 100644
@@ -282,6 +282,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 void hyper_dmabuf_xen_cleanup_tx_rbuf(int domid)
 {
 	struct xen_comm_tx_ring_info *ring_info;
+	struct xen_comm_rx_ring_info *rx_ring_info;
 
 	/* check if we at all have exporter ring for given rdomain */
 	ring_info = xen_comm_find_tx_ring(domid);
@@ -307,6 +308,12 @@ void hyper_dmabuf_xen_cleanup_tx_rbuf(int domid)
 				  (unsigned long) ring_info->ring_front.sring);
 
 	kfree(ring_info);
+
+	rx_ring_info = xen_comm_find_rx_ring(domid);
+	if (!rx_ring_info)
+		return;
+
+	BACK_RING_INIT(&(rx_ring_info->ring_back), rx_ring_info->ring_back.sring, PAGE_SIZE);
 }
 
 /* importer needs to know about shared page and port numbers for
@@ -378,9 +385,8 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 
 	BACK_RING_INIT(&ring_info->ring_back, sring, PAGE_SIZE);
 
-	ret = bind_interdomain_evtchn_to_irqhandler(domid, rx_port,
-						    back_ring_isr, 0,
-						    NULL, (void*)ring_info);
+	ret = bind_interdomain_evtchn_to_irq(domid, rx_port);
+
 	if (ret < 0) {
 		return -EINVAL;
 	}
@@ -399,6 +405,10 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 		ret = hyper_dmabuf_xen_init_tx_rbuf(domid);
 	}
 
+	ret = request_irq(ring_info->irq,
+			  back_ring_isr, 0,
+			  NULL, (void*)ring_info);
+
 	return ret;
 }
 
@@ -406,6 +416,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 void hyper_dmabuf_xen_cleanup_rx_rbuf(int domid)
 {
 	struct xen_comm_rx_ring_info *ring_info;
+	struct xen_comm_tx_ring_info *tx_ring_info;
 	struct page *shared_ring;
 
 	/* check if we have importer ring created for given sdomain */
@@ -425,6 +436,13 @@ void hyper_dmabuf_xen_cleanup_rx_rbuf(int domid)
 	gnttab_free_pages(1, &shared_ring);
 
 	kfree(ring_info);
+
+	tx_ring_info = xen_comm_find_tx_ring(domid);
+	if (!tx_ring_info)
+		return;
+
+	SHARED_RING_INIT(tx_ring_info->ring_front.sring);
+	FRONT_RING_INIT(&(tx_ring_info->ring_front), tx_ring_info->ring_front.sring, PAGE_SIZE);
 }
 
 int hyper_dmabuf_xen_init_comm_env(void)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#31 lore raw

RFC PATCH 19/60 hyper_dmabuf: fix the case with sharing a buffer with 2 pages

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Checking whether buffer has more than two pages should be done by evaluating nents > 1 instead of i > 1 to properly cover the case when nents == 2.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +1 -1
index b61d29a..9b05063 100644
@@ -129,7 +129,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 		sg_set_page(sgl, pages[i], PAGE_SIZE, 0);
 	}
 
-	if (i > 1) /* more than one page */ {
+	if (nents > 1) /* more than one page */ {
 		sgl = sg_next(sgl);
 		sg_set_page(sgl, pages[i], last_len, 0);
 	}
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#32 lore raw

RFC PATCH 20/60 hyper_dmabuf: optimized loop with less condition check

In reply to Dongwon Kim

Redefined nents_last, which means # of gref in the last page of lvl2 table in any situation even if it is same as REFS_PER_PAGE. With this, loop can be simplified with less condition check.

---
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +5 -3
index cc9860b..cb5b86f 100644
@@ -184,8 +184,10 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	struct gnttab_map_grant_ref *data_map_ops;
 	struct gnttab_unmap_grant_ref *data_unmap_ops;
 
-	int nents_last = nents % REFS_PER_PAGE;
-	int n_lvl2_grefs = (nents / REFS_PER_PAGE) + ((nents_last > 0) ? 1 : 0);
+	/* # of grefs in the last page of lvl2 table */
+	int nents_last = (nents - 1) % REFS_PER_PAGE + 1;
+	int n_lvl2_grefs = (nents / REFS_PER_PAGE) + ((nents_last > 0) ? 1 : 0) -
+			   (nents_last == REFS_PER_PAGE);
 	int i, j, k;
 
 	dev_dbg(hyper_dmabuf_private.device, "%s entry\n", __func__);
@@ -270,7 +272,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 
 	k = 0;
 
-	for (i = 0; i < (nents_last ? n_lvl2_grefs - 1 : n_lvl2_grefs); i++) {
+	for (i = 0; i < n_lvl2_grefs - 1; i++) {
 		lvl2_table = pfn_to_kaddr(page_to_pfn(lvl2_table_pages[i]));
 		for (j = 0; j < REFS_PER_PAGE; j++) {
 			gnttab_set_map_op(&data_map_ops[k],
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#33 lore raw

RFC PATCH 21/60 hyper_dmabuf: exposing drv information using sysfs

In reply to Dongwon Kim

From: Michał Janiszewski <[email protected]>

This adds two entries in SYSFS with information about imported and exported entries. The information exposed contains details about number of pages, whether a buffer is valid or not, and importer/exporter count.

Sysfs for hyper_dmabuf can be enabled by setting a new config option, "CONFIG_HYPER_DMABUF_SYSFS" to 'yes'.

---
 drivers/xen/hyper_dmabuf/Kconfig             |  7 +++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c  | 12 ++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c  |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c | 74 ++++++++++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h |  3 ++
 5 files changed, 96 insertions(+), 2 deletions(-)
drivers/xen/hyper_dmabuf/Kconfig +7 -0
index 75e1f96..56633a2 100644
@@ -11,4 +11,11 @@ config HYPER_DMABUF_XEN
 	help
 	  Configuring hyper_dmabuf driver for XEN hypervisor
 
+config HYPER_DMABUF_SYSFS
+	bool "Enable sysfs information about hyper DMA buffers"
+	default y
+	help
+	  Expose information about imported and exported buffers using
+	  hyper_dmabuf driver
+
 endmenu
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +11 -1
index 9d99769..3fc30e6 100644
@@ -22,7 +22,7 @@ int unregister_device(void);
 struct hyper_dmabuf_private hyper_dmabuf_private;
 
 /*===============================================================================================*/
-static int hyper_dmabuf_drv_init(void)
+static int __init hyper_dmabuf_drv_init(void)
 {
 	int ret = 0;
 
@@ -51,10 +51,16 @@ static int hyper_dmabuf_drv_init(void)
 	}
 
 	ret = hyper_dmabuf_private.backend_ops->init_comm_env();
+	if (ret < 0) {
+		return -EINVAL;
+	}
 
+#ifdef CONFIG_HYPER_DMABUF_SYSFS
+	ret = hyper_dmabuf_register_sysfs(hyper_dmabuf_private.device);
 	if (ret < 0) {
 		return -EINVAL;
 	}
+#endif
 
 	/* interrupt for comm should be registered here: */
 	return ret;
@@ -63,6 +69,10 @@ static int hyper_dmabuf_drv_init(void)
 /*-----------------------------------------------------------------------------------------------*/
 static void hyper_dmabuf_drv_exit(void)
 {
+#ifdef CONFIG_HYPER_DMABUF_SYSFS
+	hyper_dmabuf_unregister_sysfs(hyper_dmabuf_private.device);
+#endif
+
 	/* hash tables for export/import entries and ring_infos */
 	hyper_dmabuf_table_destroy();
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +1 -1
index 9b05063..924710f 100644
@@ -24,7 +24,7 @@ int dmabuf_refcount(struct dma_buf *dma_buf)
 	return -1;
 }
 
-/* return total number of pages referecned by a sgt
+/* return total number of pages referenced by a sgt
  * for pre-calculation of # of pages behind a given sgt
  */
 static int hyper_dmabuf_get_num_pgs(struct sg_table *sgt)
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +74 -0

80 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +3 -0
index f55d06e..a46f884 100644
@@ -37,4 +37,7 @@ int hyper_dmabuf_remove_exported(int id);
 
 int hyper_dmabuf_remove_imported(int id);
 
+int hyper_dmabuf_register_sysfs(struct device *dev);
+int hyper_dmabuf_unregister_sysfs(struct device *dev);
+
 #endif // __HYPER_DMABUF_LIST_H__
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#34 lore raw

RFC PATCH 22/60 hyper_dmabuf: configure license

In reply to Dongwon Kim

Set the license of the driver to "GPL and MIT-X dual" and owner to "Intel". Also attached license term to all source and header files

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h       | 26 ++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        | 32 ++++++++++++++++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         | 28 +++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h         | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 28 +++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 28 +++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h      | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       | 28 +++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h       | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 28 +++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h      | 24 ++++++++++++++++
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 28 +++++++++++++++++++
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h    | 24 ++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     | 24 ++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 28 +++++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   | 24 ++++++++++++++++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  | 28 +++++++++++++++++++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h  | 24 ++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c    | 28 +++++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.h    | 24 ++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 28 +++++++++++++++++++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.h    | 24 ++++++++++++++++
 25 files changed, 648 insertions(+), 2 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h +26 -0
index d012b05..ee1886c 100644
@@ -1 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+/* configuration */
+
 #define CURRENT_TARGET XEN
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +30 -2
index 3fc30e6..4e0ccdd 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/workqueue.h>
@@ -13,8 +41,8 @@
 extern struct hyper_dmabuf_backend_ops xen_backend_ops;
 #endif
 
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("IOTG-PED, INTEL");
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Intel Corporation");
 
 int register_device(void);
 int unregister_device(void);
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +24 -0
index c16e8d4..0b1441e 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +28 -0
index b58a111..9b4ff45 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/list.h>
 #include <linux/slab.h>
 #include "hyper_dmabuf_msg.h"
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h +24 -0
index 2c8daf3..4394903 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_ID_H__
 #define __HYPER_DMABUF_ID_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +28 -0
index 924710f..a017070 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h +24 -0
index a4a6d63..eda075b3 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_IMP_H__
 #define __HYPER_DMABUF_IMP_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +28 -0
index b1e0bdb..b0f5b5b 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h +24 -0
index de216d3..e43a25f 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_IOCTL_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_IOCTL_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +28 -0
index 1d224c4..e46ae19 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +24 -0
index a46f884..35dc722 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_LIST_H__
 #define __HYPER_DMABUF_LIST_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +28 -0
index 9c38900..b9bd6d8 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +24 -0
index ac4caeb..8b3c857 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_MSG_H__
 #define __HYPER_DMABUF_MSG_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h +24 -0
index a577167..6cf5b2d 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_QUERY_H__
 #define __HYPER_DMABUF_QUERY_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +28 -0
index 2758915..4c28f11 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h +24 -0
index fc85fa8..71ee358 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_REMOTE_SYNC_H__
 #define __HYPER_DMABUF_REMOTE_SYNC_H__
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +24 -0
index f053dd10..2a58218 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_STRUCT_H__
 #define __HYPER_DMABUF_STRUCT_H__
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +28 -0
index b629032..14336c9 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +24 -0
index ba41e9d..298af08 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_XEN_COMM_H__
 #define __HYPER_DMABUF_XEN_COMM_H__
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +28 -0
index 2a1f45b..0fa2d55 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.h +24 -0
index 18b3afd..cde8ade 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_XEN_COMM_LIST_H__
 #define __HYPER_DMABUF_XEN_COMM_LIST_H__
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c +28 -0
index e7b871a..6afb520 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.h +24 -0
index e351c08..c5fec24 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_XEN_DRV_H__
 #define __HYPER_DMABUF_XEN_DRV_H__
 #include <xen/interface/grant_table.h>
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +28 -0
index cb5b86f..122aac1 100644
@@ -1,3 +1,31 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Dongwon Kim <[email protected]>
+ *    Mateusz Polrola <[email protected]>
+ *
+ */
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.h +24 -0
index 2287804..629ec0f 100644
@@ -1,3 +1,27 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
 #ifndef __HYPER_DMABUF_XEN_SHM_H__
 #define __HYPER_DMABUF_XEN_SHM_H__
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#35 lore raw

RFC PATCH 23/60 hyper_dmabuf: use CONFIG_HYPER_DMABUF_XEN instead of CONFIG_XEN

In reply to Dongwon Kim

Now, use CONFIG_HYPER_DMABUF_XEN as a configuration option for building hyper_dmabuf for Xen hypervisor.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +2 -2
index 4e0ccdd..569b95e 100644
@@ -36,7 +36,7 @@
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_id.h"
 
-#ifdef CONFIG_XEN
+#ifdef CONFIG_HYPER_DMABUF_XEN
 #include "xen/hyper_dmabuf_xen_drv.h"
 extern struct hyper_dmabuf_backend_ops xen_backend_ops;
 #endif
@@ -61,7 +61,7 @@ static int __init hyper_dmabuf_drv_init(void)
 		return -EINVAL;
 	}
 
-#ifdef CONFIG_XEN
+#ifdef CONFIG_HYPER_DMABUF_XEN
 	hyper_dmabuf_private.backend_ops = &xen_backend_ops;
 #endif
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#36 lore raw

RFC PATCH 23/60 hyper_dmabuf: use CONFIG_HYPER_DMABUF_XEN instead of CONFIG_XEN

In reply to Dongwon Kim

Now, use CONFIG_HYPER_DMABUF_XEN as a configuration option for building hyper_dmabuf for Xen hypervisor.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +2 -2
index 4e0ccdd..569b95e 100644
@@ -36,7 +36,7 @@
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_id.h"
 
-#ifdef CONFIG_XEN
+#ifdef CONFIG_HYPER_DMABUF_XEN
 #include "xen/hyper_dmabuf_xen_drv.h"
 extern struct hyper_dmabuf_backend_ops xen_backend_ops;
 #endif
@@ -61,7 +61,7 @@ static int __init hyper_dmabuf_drv_init(void)
 		return -EINVAL;
 	}
 
-#ifdef CONFIG_XEN
+#ifdef CONFIG_HYPER_DMABUF_XEN
 	hyper_dmabuf_private.backend_ops = &xen_backend_ops;
 #endif
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#37 lore raw

RFC PATCH 24/60 hyper_dmabuf: waits for resp only if WAIT_AFTER_SYNC_REQ == 1

In reply to Dongwon Kim

hyper_dmabuf's sync_request (previously hyper_dmabuf_sync_request_ and_wait) now does not wait for the response from exporter if WAIT_AFTER_SYNC_REQ==0. This is to prevent peformance degradation due to the communication latency while doing indirect hyper DMABUF synchronization.

This patch also includes some minor changes as followed:

1. hyper_dmabuf_free_sgt is removed. Now we call sg_free_table and kfree directly from all the places where this function was executed. This was done for conciseness.

2. changed hyper_dmabuf_get_domid to hyper_dmabuf_xen_get_domid for consistence in func names in the backend.

3. some minor clean-ups

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h       |  2 -
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 91 +++++++++++-----------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  2 -
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |  2 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 14 ++--
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |  2 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c    |  2 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 21 +++--
 8 files changed, 69 insertions(+), 67 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_conf.h +0 -2
index ee1886c..d5125f2 100644
@@ -23,5 +23,3 @@
  */
 
 /* configuration */
-
-#define CURRENT_TARGET XEN
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +46 -45

212 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +0 -2
index b9bd6d8..c99176ac 100644
@@ -39,8 +39,6 @@
 #include "hyper_dmabuf_remote_sync.h"
 #include "hyper_dmabuf_list.h"
 
-#define FORCED_UNEXPORTING 0
-
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
 struct cmd_process {
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +1 -1
index 4c28f11..f93c936 100644
@@ -53,7 +53,7 @@ extern struct hyper_dmabuf_private hyper_dmabuf_private;
  * later when unmapping operations are invoked to free those.
  *
  * The very first element on the bottom of each stack holds
- * are what is created when initial exporting is issued so it
+ * is what is created when initial exporting is issued so it
  * should not be modified or released by this fuction.
  */
 int hyper_dmabuf_remote_sync(int id, int ops)
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +7 -7
index 14336c9..ba6b126 100644
@@ -53,7 +53,7 @@ static int xen_comm_setup_data_dir(void)
 {
 	char buf[255];
 
-	sprintf(buf, "/local/domain/%d/data/hyper_dmabuf", hyper_dmabuf_get_domid());
+	sprintf(buf, "/local/domain/%d/data/hyper_dmabuf", hyper_dmabuf_xen_get_domid());
 	return xenbus_mkdir(XBT_NIL, buf, "");
 }
 
@@ -67,7 +67,7 @@ static int xen_comm_destroy_data_dir(void)
 {
 	char buf[255];
 
-	sprintf(buf, "/local/domain/%d/data/hyper_dmabuf", hyper_dmabuf_get_domid());
+	sprintf(buf, "/local/domain/%d/data/hyper_dmabuf", hyper_dmabuf_xen_get_domid());
 	return xenbus_rm(XBT_NIL, buf, "");
 }
 
@@ -130,7 +130,7 @@ static int xen_comm_get_ring_details(int domid, int rdomid, int *grefid, int *po
 	return (ret <= 0 ? 1 : 0);
 }
 
-int hyper_dmabuf_get_domid(void)
+int hyper_dmabuf_xen_get_domid(void)
 {
 	struct xenbus_transaction xbt;
 	int domid;
@@ -192,7 +192,7 @@ static void remote_dom_exporter_watch_cb(struct xenbus_watch *watch,
 	 * it means that remote domain has setup it for us and we should connect
 	 * to it.
 	 */
-	ret = xen_comm_get_ring_details(hyper_dmabuf_get_domid(), rdom,
+	ret = xen_comm_get_ring_details(hyper_dmabuf_xen_get_domid(), rdom,
 					&grefid, &port);
 
 	if (ring_info && ret != 0) {
@@ -287,7 +287,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 
 	ret = xen_comm_add_tx_ring(ring_info);
 
-	ret = xen_comm_expose_ring_details(hyper_dmabuf_get_domid(), domid,
+	ret = xen_comm_expose_ring_details(hyper_dmabuf_xen_get_domid(), domid,
 					   ring_info->gref_ring, ring_info->port);
 
 	/*
@@ -299,7 +299,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 	ring_info->watch.node = (const char*) kmalloc(sizeof(char) * 255, GFP_KERNEL);
 	sprintf((char*)ring_info->watch.node,
 		"/local/domain/%d/data/hyper_dmabuf/%d/port",
-		domid, hyper_dmabuf_get_domid());
+		domid, hyper_dmabuf_xen_get_domid());
 
 	register_xenbus_watch(&ring_info->watch);
 
@@ -368,7 +368,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 		return 0;
 	}
 
-	ret = xen_comm_get_ring_details(hyper_dmabuf_get_domid(), domid,
+	ret = xen_comm_get_ring_details(hyper_dmabuf_xen_get_domid(), domid,
 					&rx_gref, &rx_port);
 
 	if (ret) {
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +1 -1
index 298af08..9c93165 100644
@@ -50,7 +50,7 @@ struct xen_comm_rx_ring_info {
 	struct gnttab_unmap_grant_ref unmap_op;
 };
 
-int hyper_dmabuf_get_domid(void);
+int hyper_dmabuf_xen_get_domid(void);
 
 int hyper_dmabuf_xen_init_comm_env(void);
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_drv.c +1 -1
index 6afb520..aa4c2f5 100644
@@ -37,7 +37,7 @@
 #include "hyper_dmabuf_xen_shm.h"
 
 struct hyper_dmabuf_backend_ops xen_backend_ops = {
-	.get_vm_id = hyper_dmabuf_get_domid,
+	.get_vm_id = hyper_dmabuf_xen_get_domid,
 	.share_pages = hyper_dmabuf_xen_share_pages,
 	.unshare_pages = hyper_dmabuf_xen_unshare_pages,
 	.map_shared_pages = (void *)hyper_dmabuf_xen_map_shared_pages,
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +13 -8
index 122aac1..b158c11 100644
@@ -108,8 +108,8 @@ int hyper_dmabuf_xen_share_pages(struct page **pages, int domid, int nents,
 	/* Share 2nd level addressing pages in readonly mode*/
 	for (i=0; i< n_lvl2_grefs; i++) {
 		lvl3_table[i] = gnttab_grant_foreign_access(domid,
-							   virt_to_mfn((unsigned long)lvl2_table+i*PAGE_SIZE ),
-							   1);
+							    virt_to_mfn((unsigned long)lvl2_table+i*PAGE_SIZE ),
+							    1);
 	}
 
 	/* Share lvl3_table in readonly mode*/
@@ -240,10 +240,12 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 
 	lvl3_table = (grant_ref_t *)pfn_to_kaddr(page_to_pfn(lvl3_table_page));
 
-	gnttab_set_map_op(&lvl3_map_ops, (unsigned long)lvl3_table, GNTMAP_host_map | GNTMAP_readonly,
+	gnttab_set_map_op(&lvl3_map_ops, (unsigned long)lvl3_table,
+			  GNTMAP_host_map | GNTMAP_readonly,
 			  (grant_ref_t)lvl3_gref, domid);
 
-	gnttab_set_unmap_op(&lvl3_unmap_ops, (unsigned long)lvl3_table, GNTMAP_host_map | GNTMAP_readonly, -1);
+	gnttab_set_unmap_op(&lvl3_unmap_ops, (unsigned long)lvl3_table,
+			    GNTMAP_host_map | GNTMAP_readonly, -1);
 
 	if (gnttab_map_refs(&lvl3_map_ops, NULL, &lvl3_table_page, 1)) {
 		dev_err(hyper_dmabuf_private.device, "HYPERVISOR map grant ref failed");
@@ -285,8 +287,9 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	/* Checks if pages were mapped correctly */
 	for (i = 0; i < n_lvl2_grefs; i++) {
 		if (lvl2_map_ops[i].status) {
-			dev_err(hyper_dmabuf_private.device, "HYPERVISOR map grant ref failed status = %d",
-			       lvl2_map_ops[i].status);
+			dev_err(hyper_dmabuf_private.device,
+				"HYPERVISOR map grant ref failed status = %d",
+				lvl2_map_ops[i].status);
 			return NULL;
 		} else {
 			lvl2_unmap_ops[i].handle = lvl2_map_ops[i].handle;
@@ -344,7 +347,8 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 
 	for (i = 0; i < nents; i++) {
 		if (data_map_ops[i].status) {
-			dev_err(hyper_dmabuf_private.device, "HYPERVISOR map grant ref failed status = %d\n",
+			dev_err(hyper_dmabuf_private.device,
+				"HYPERVISOR map grant ref failed status = %d\n",
 				data_map_ops[i].status);
 			return NULL;
 		} else {
@@ -376,7 +380,8 @@ int hyper_dmabuf_xen_unmap_shared_pages(void **refs_info, int nents) {
 
 	if (sh_pages_info->unmap_ops == NULL ||
 	    sh_pages_info->data_pages == NULL) {
-		dev_warn(hyper_dmabuf_private.device, "Imported pages already cleaned up or buffer was not imported yet\n");
+		dev_warn(hyper_dmabuf_private.device,
+			 "Imported pages already cleaned up or buffer was not imported yet\n");
 		return 0;
 	}
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#38 lore raw

RFC PATCH 25/60 hyper_dmabuf: introduced delayed unexport

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

To prevent overhead when a DMA BUF needs to be exported right after it is unexported, a marginal delay is introduced in unexporting process. This adds a probation period to the unexporting process. If the same DMA_BUF is requested to be exported agagin, unexporting process is canceled right away and the buffer can be reused without any extensive re-exporting process.

Additionally, "FIRST EXPORT" message is synchronously transmitted to the exporter VM (importer VM waits for the response.) to make sure the buffer is still valid (not unexported) on expoter VM's side before importer VM starts to use it.

"delayed_ms" attribute is added to unexport ioctl, used for hardcoding delay from userspace.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |   4 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 157 ++++++++++++++-------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h      |   2 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  41 +++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |   2 +
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |   2 +
 6 files changed, 139 insertions(+), 69 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +4 -0
index d7a35fc..a9bc354 100644
@@ -341,6 +341,10 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	/* extract pages from sgt */
 	page_info = hyper_dmabuf_ext_pgs(sgt_info->sgt);
 
+	if (!page_info) {
+		return NULL;
+	}
+
 	/* create a new sg_table with extracted pages */
 	st = hyper_dmabuf_create_sgt(page_info->pages, page_info->frst_ofst,
 				page_info->last_len, page_info->nents);
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +104 -53

239 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h +2 -0
index e43a25f..558964c 100644
@@ -90,6 +90,8 @@ struct ioctl_hyper_dmabuf_unexport {
 	/* IN parameters */
 	/* hyper dmabuf id to be unexported */
 	int hyper_dmabuf_id;
+	/* delay in ms by which unexport processing will be postponed */
+	int delay_ms;
 	/* OUT parameters */
 	/* Status of request */
 	int status;
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +25 -16

71 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +2 -0
index 2a58218..a41fd0a 100644
@@ -78,6 +78,8 @@ struct hyper_dmabuf_sgt_info {
 	bool valid;
 	int importer_exported; /* exported locally on importer's side */
 	void *refs_info; /* hypervisor-specific info for the references */
+	struct delayed_work unexport_work;
+	bool unexport_scheduled;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +2 -0
index ba6b126..a8cce26 100644
@@ -551,6 +551,8 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 			dev_err(hyper_dmabuf_private.device, "request timed-out\n");
 			return -EBUSY;
 		}
+
+		return req_pending.status;
 	}
 
 	return 0;
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#39 lore raw

RFC PATCH 26/60 hyper_dmabuf: add mutexes to prevent several race conditions

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Added mutex to export_fd ioctl to prevent double pages mapping of the same buffer to prevent race condition when two consumers are trying to map the same buffer on importer VM.

Also locked mutex before sending request via xen communication channel to prevent req_pending override by another caller.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c          |  2 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h          |  1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c        |  6 ++++++
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c | 10 ++++++++++
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h |  1 +
 5 files changed, 20 insertions(+)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +2 -0
index 569b95e..584d55d 100644
@@ -56,6 +56,8 @@ static int __init hyper_dmabuf_drv_init(void)
 
 	printk( KERN_NOTICE "hyper_dmabuf_starting: Initialization started" );
 
+	mutex_init(&hyper_dmabuf_private.lock);
+
 	ret = register_device();
 	if (ret < 0) {
 		return -EINVAL;
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +1 -0
index 0b1441e..8445416 100644
@@ -76,6 +76,7 @@ struct hyper_dmabuf_private {
 
 	/* backend ops - hypervisor specific */
 	struct hyper_dmabuf_backend_ops *backend_ops;
+	struct mutex lock;
 };
 
 #endif /* __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +6 -0
index 018de8c..8851a9c 100644
@@ -260,6 +260,8 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	if (sgt_info == NULL || !sgt_info->valid) /* can't find sgt from the table */
 		return -1;
 
+	mutex_lock(&hyper_dmabuf_private.lock);
+
 	sgt_info->num_importers++;
 
 	/* send notification for export_fd to exporter */
@@ -274,6 +276,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 		kfree(req);
 		dev_err(hyper_dmabuf_private.device, "Failed to create sgt or notify exporter\n");
 		sgt_info->num_importers--;
+		mutex_unlock(&hyper_dmabuf_private.lock);
 		return -EINVAL;
 	}
 	kfree(req);
@@ -282,6 +285,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 		dev_err(hyper_dmabuf_private.device,
 			"Buffer invalid\n");
 		sgt_info->num_importers--;
+		mutex_unlock(&hyper_dmabuf_private.lock);
 		return -1;
 	} else {
 		dev_dbg(hyper_dmabuf_private.device, "Can import buffer\n");
@@ -303,6 +307,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 
 		if (!data_pages) {
 			sgt_info->num_importers--;
+			mutex_unlock(&hyper_dmabuf_private.lock);
 			return -EINVAL;
 		}
 
@@ -318,6 +323,7 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 		ret = export_fd_attr->fd;
 	}
 
+	mutex_unlock(&hyper_dmabuf_private.lock);
 	dev_dbg(hyper_dmabuf_private.device, "%s exit\n", __func__);
 	return 0;
 }
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +10 -0
index a8cce26..9d67b47 100644
@@ -278,6 +278,8 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 	ring_info->irq = ret;
 	ring_info->port = alloc_unbound.port;
 
+	mutex_init(&ring_info->lock);
+
 	dev_dbg(hyper_dmabuf_private.device,
 		"%s: allocated eventchannel gref %d  port: %d  irq: %d\n",
 		__func__,
@@ -512,6 +514,9 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 		return -EINVAL;
 	}
 
+
+	mutex_lock(&ring_info->lock);
+
 	ring = &ring_info->ring_front;
 
 	if (RING_FULL(ring))
@@ -519,6 +524,7 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 
 	new_req = RING_GET_REQUEST(ring, ring->req_prod_pvt);
 	if (!new_req) {
+		mutex_unlock(&ring_info->lock);
 		dev_err(hyper_dmabuf_private.device,
 			"NULL REQUEST\n");
 		return -EIO;
@@ -548,13 +554,17 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 		}
 
 		if (timeout < 0) {
+			mutex_unlock(&ring_info->lock);
 			dev_err(hyper_dmabuf_private.device, "request timed-out\n");
 			return -EBUSY;
 		}
 
+		mutex_unlock(&ring_info->lock);
 		return req_pending.status;
 	}
 
+	mutex_unlock(&ring_info->lock);
+
 	return 0;
 }
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +1 -0
index 9c93165..0533e4d 100644
@@ -39,6 +39,7 @@ struct xen_comm_tx_ring_info {
         int gref_ring;
         int irq;
         int port;
+	struct mutex lock;
 	struct xenbus_watch watch;
 };
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#40 lore raw

RFC PATCH 27/60 hyper_dmabuf: use proper error codes

In reply to Dongwon Kim

Cleaned up and corrected error codes and condition in various error check routines. Also added proper err messages when func returns error.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        | 14 +++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  8 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 66 ++++++++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  6 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  5 +-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 38 ++++++-------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 20 +++----
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  4 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    |  2 +-
 10 files changed, 94 insertions(+), 71 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +10 -4
index 584d55d..44a9139 100644
@@ -60,7 +60,7 @@ static int __init hyper_dmabuf_drv_init(void)
 
 	ret = register_device();
 	if (ret < 0) {
-		return -EINVAL;
+		return ret;
 	}
 
 #ifdef CONFIG_HYPER_DMABUF_XEN
@@ -77,18 +77,24 @@ static int __init hyper_dmabuf_drv_init(void)
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initialize table for exported/imported entries\n");
+		return ret;
 	}
 
 	ret = hyper_dmabuf_private.backend_ops->init_comm_env();
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initiailize hypervisor-specific comm env\n");
+		return ret;
 	}
 
 #ifdef CONFIG_HYPER_DMABUF_SYSFS
 	ret = hyper_dmabuf_register_sysfs(hyper_dmabuf_private.device);
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initialize sysfs\n");
+		return ret;
 	}
 #endif
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +1 -1
index 9b4ff45..35bfdfb 100644
@@ -62,7 +62,7 @@ static int retrieve_reusable_id(void)
 		return id;
 	}
 
-	return -1;
+	return -ENOENT;
 }
 
 void destroy_reusable_list(void)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +4 -4
index a9bc354..a0b3946 100644
@@ -84,11 +84,11 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 	struct scatterlist *sgl;
 
 	pinfo = kmalloc(sizeof(*pinfo), GFP_KERNEL);
-	if (pinfo == NULL)
+	if (!pinfo)
 		return NULL;
 
 	pinfo->pages = kmalloc(sizeof(struct page *)*hyper_dmabuf_get_num_pgs(sgt), GFP_KERNEL);
-	if (pinfo->pages == NULL)
+	if (!pinfo->pages)
 		return NULL;
 
 	sgl = sgt->sgl;
@@ -138,7 +138,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 	int i, ret;
 
 	sgt = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
-	if (sgt == NULL) {
+	if (!sgt) {
 		return NULL;
 	}
 
@@ -348,7 +348,7 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	/* create a new sg_table with extracted pages */
 	st = hyper_dmabuf_create_sgt(page_info->pages, page_info->frst_ofst,
 				page_info->last_len, page_info->nents);
-	if (st == NULL)
+	if (!st)
 		goto err_free_sg;
 
         if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +41 -25

189 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +3 -3
index e46ae19..2cb4bb4 100644
@@ -177,7 +177,7 @@ int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid)
 		   info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
-	return -1;
+	return -ENOENT;
 }
 
 struct hyper_dmabuf_imported_sgt_info *hyper_dmabuf_find_imported(int id)
@@ -204,7 +204,7 @@ int hyper_dmabuf_remove_exported(int id)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 int hyper_dmabuf_remove_imported(int id)
@@ -219,5 +219,5 @@ int hyper_dmabuf_remove_imported(int id)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +3 -2
index dd4bb01..6e24442 100644
@@ -100,7 +100,7 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_req *req,
 		 * operands0 : hyper_dmabuf_id
 		 * operands1 : map(=1)/unmap(=2)/attach(=3)/detach(=4)
 		 */
-		for (i=0; i<2; i++)
+		for (i = 0; i < 2; i++)
 			req->operands[i] = operands[i];
 		break;
 
@@ -199,6 +199,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		 */
 		dev_dbg(hyper_dmabuf_private.device,
 			"%s: processing HYPER_DMABUF_NOTIFY_UNEXPORT\n", __func__);
+
 		sgt_info = hyper_dmabuf_find_imported(req->operands[0]);
 
 		if (sgt_info) {
@@ -232,6 +233,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		 */
 		dev_dbg(hyper_dmabuf_private.device,
 			"%s: HYPER_DMABUF_OPS_TO_SOURCE\n", __func__);
+
 		ret = hyper_dmabuf_remote_sync(req->operands[0], req->operands[1]);
 		if (ret)
 			req->status = HYPER_DMABUF_REQ_ERROR;
@@ -271,7 +273,6 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	memcpy(temp_req, req, sizeof(*temp_req));
 
 	proc = kcalloc(1, sizeof(struct cmd_process), GFP_KERNEL);
-
 	proc->rq = temp_req;
 	proc->domid = domid;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +19 -19
index f93c936..a74e800 100644
@@ -71,7 +71,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	if (!sgt_info) {
 		dev_err(hyper_dmabuf_private.device,
 			"dmabuf remote sync::can't find exported list\n");
-		return -EINVAL;
+		return -ENOENT;
 	}
 
 	switch (ops) {
@@ -85,7 +85,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(attachl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_ATTACH\n");
-			return -EINVAL;
+			return PTR_ERR(attachl->attach);
 		}
 
 		list_add(&attachl->list, &sgt_info->active_attached->list);
@@ -97,7 +97,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_DETACH\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf attachment left to be detached\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -113,8 +113,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
 			dev_err(hyper_dmabuf_private.device,
-				"no more dmabuf attachment left to be detached\n");
-			return -EINVAL;
+				"no more dmabuf attachment left to be mapped\n");
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -126,7 +126,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(sgtl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
-			return -EINVAL;
+			return PTR_ERR(sgtl->sgt);
 		}
 		list_add(&sgtl->list, &sgt_info->active_sgts->list);
 		break;
@@ -137,8 +137,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_UNMAP\n");
 			dev_err(hyper_dmabuf_private.device,
-				"no more SGT or attachment left to be freed\n");
-			return -EINVAL;
+				"no more SGT or attachment left to be unmapped\n");
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -176,19 +176,19 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
 		ret = dma_buf_begin_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
-		if (!ret) {
+		if (ret) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS\n");
-			ret = -EINVAL;
+			return ret;
 		}
 		break;
 
 	case HYPER_DMABUF_OPS_END_CPU_ACCESS:
 		ret = dma_buf_end_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
-		if (!ret) {
+		if (ret) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_END_CPU_ACCESS\n");
-			ret = -EINVAL;
+			return ret;
 		}
 		break;
 
@@ -206,7 +206,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_kmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KMAP(_ATOMIC)\n");
-			return -EINVAL;
+			return PTR_ERR(va_kmapl->vaddr);
 		}
 		list_add(&va_kmapl->list, &sgt_info->va_kmapped->list);
 		break;
@@ -218,15 +218,15 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf VA to be freed\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		va_kmapl = list_first_entry(&sgt_info->va_kmapped->list,
 					    struct kmap_vaddr_list, list);
-		if (va_kmapl->vaddr == NULL) {
+		if (!va_kmapl->vaddr) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
-			return -EINVAL;
+			return PTR_ERR(va_kmapl->vaddr);
 		}
 
 		/* unmapping 1 page */
@@ -256,7 +256,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_vmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VMAP\n");
-			return -EINVAL;
+			return PTR_ERR(va_vmapl->vaddr);
 		}
 		list_add(&va_vmapl->list, &sgt_info->va_vmapped->list);
 		break;
@@ -267,14 +267,14 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf VA to be freed\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 		va_vmapl = list_first_entry(&sgt_info->va_vmapped->list,
 					struct vmap_vaddr_list, list);
 		if (!va_vmapl || va_vmapl->vaddr == NULL) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		dma_buf_vunmap(sgt_info->dma_buf, va_vmapl->vaddr);
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +10 -10
index 9d67b47..2cc35e3 100644
@@ -232,7 +232,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 	/* from exporter to importer */
 	shared_ring = (void *)__get_free_pages(GFP_KERNEL, 1);
 	if (shared_ring == 0) {
-		return -EINVAL;
+		return -ENOMEM;
 	}
 
 	sring = (struct xen_comm_sring *) shared_ring;
@@ -246,17 +246,17 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 							   0);
 	if (ring_info->gref_ring < 0) {
 		/* fail to get gref */
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	alloc_unbound.dom = DOMID_SELF;
 	alloc_unbound.remote_dom = domid;
 	ret = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
 					&alloc_unbound);
-	if (ret != 0) {
+	if (ret) {
 		dev_err(hyper_dmabuf_private.device,
 			"Cannot allocate event channel\n");
-		return -EINVAL;
+		return -EIO;
 	}
 
 	/* setting up interrupt */
@@ -271,7 +271,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 		HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
 		gnttab_end_foreign_access(ring_info->gref_ring, 0,
 					virt_to_mfn(shared_ring));
-		return -EINVAL;
+		return -EIO;
 	}
 
 	ring_info->rdomain = domid;
@@ -387,7 +387,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	map_ops = kmalloc(sizeof(*map_ops), GFP_KERNEL);
 
 	if (gnttab_alloc_pages(1, &shared_ring)) {
-		return -EINVAL;
+		return -ENOMEM;
 	}
 
 	gnttab_set_map_op(&map_ops[0], (unsigned long)pfn_to_kaddr(page_to_pfn(shared_ring)),
@@ -399,12 +399,12 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	ret = gnttab_map_refs(map_ops, NULL, &shared_ring, 1);
 	if (ret < 0) {
 		dev_err(hyper_dmabuf_private.device, "Cannot map ring\n");
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	if (map_ops[0].status) {
 		dev_err(hyper_dmabuf_private.device, "Ring mapping failed\n");
-		return -EINVAL;
+		return -EFAULT;
 	} else {
 		ring_info->unmap_op.handle = map_ops[0].handle;
 	}
@@ -418,7 +418,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	ret = bind_interdomain_evtchn_to_irq(domid, rx_port);
 
 	if (ret < 0) {
-		return -EINVAL;
+		return -EIO;
 	}
 
 	ring_info->irq = ret;
@@ -511,7 +511,7 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 	if (!ring_info) {
 		dev_err(hyper_dmabuf_private.device,
 			"Can't find ring info for the channel\n");
-		return -EINVAL;
+		return -ENOENT;
 	}
 
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +2 -2
index 0fa2d55..2f469da 100644
@@ -110,7 +110,7 @@ int xen_comm_remove_tx_ring(int domid)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 int xen_comm_remove_rx_ring(int domid)
@@ -125,7 +125,7 @@ int xen_comm_remove_rx_ring(int domid)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 void xen_comm_foreach_tx_ring(void (*func)(int domid))
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +1 -1
index b158c11..c03e5a0 100644
@@ -388,7 +388,7 @@ int hyper_dmabuf_xen_unmap_shared_pages(void **refs_info, int nents) {
 	if (gnttab_unmap_refs(sh_pages_info->unmap_ops, NULL,
 			      sh_pages_info->data_pages, nents) ) {
 		dev_err(hyper_dmabuf_private.device, "Cannot unmap data pages\n");
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	gnttab_free_pages(nents, sh_pages_info->data_pages);
Signature · 1 line
2.7.4
#41 lore raw

RFC PATCH 27/60 hyper_dmabuf: use proper error codes

In reply to Dongwon Kim

Cleaned up and corrected error codes and condition in various error check routines. Also added proper err messages when func returns error.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        | 14 +++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  8 +--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 66 ++++++++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  6 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  5 +-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 38 ++++++-------
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 20 +++----
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  4 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    |  2 +-
 10 files changed, 94 insertions(+), 71 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +10 -4
index 584d55d..44a9139 100644
@@ -60,7 +60,7 @@ static int __init hyper_dmabuf_drv_init(void)
 
 	ret = register_device();
 	if (ret < 0) {
-		return -EINVAL;
+		return ret;
 	}
 
 #ifdef CONFIG_HYPER_DMABUF_XEN
@@ -77,18 +77,24 @@ static int __init hyper_dmabuf_drv_init(void)
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initialize table for exported/imported entries\n");
+		return ret;
 	}
 
 	ret = hyper_dmabuf_private.backend_ops->init_comm_env();
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initiailize hypervisor-specific comm env\n");
+		return ret;
 	}
 
 #ifdef CONFIG_HYPER_DMABUF_SYSFS
 	ret = hyper_dmabuf_register_sysfs(hyper_dmabuf_private.device);
 	if (ret < 0) {
-		return -EINVAL;
+		dev_err(hyper_dmabuf_private.device,
+			"failed to initialize sysfs\n");
+		return ret;
 	}
 #endif
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +1 -1
index 9b4ff45..35bfdfb 100644
@@ -62,7 +62,7 @@ static int retrieve_reusable_id(void)
 		return id;
 	}
 
-	return -1;
+	return -ENOENT;
 }
 
 void destroy_reusable_list(void)
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +4 -4
index a9bc354..a0b3946 100644
@@ -84,11 +84,11 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 	struct scatterlist *sgl;
 
 	pinfo = kmalloc(sizeof(*pinfo), GFP_KERNEL);
-	if (pinfo == NULL)
+	if (!pinfo)
 		return NULL;
 
 	pinfo->pages = kmalloc(sizeof(struct page *)*hyper_dmabuf_get_num_pgs(sgt), GFP_KERNEL);
-	if (pinfo->pages == NULL)
+	if (!pinfo->pages)
 		return NULL;
 
 	sgl = sgt->sgl;
@@ -138,7 +138,7 @@ struct sg_table* hyper_dmabuf_create_sgt(struct page **pages,
 	int i, ret;
 
 	sgt = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
-	if (sgt == NULL) {
+	if (!sgt) {
 		return NULL;
 	}
 
@@ -348,7 +348,7 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	/* create a new sg_table with extracted pages */
 	st = hyper_dmabuf_create_sgt(page_info->pages, page_info->frst_ofst,
 				page_info->last_len, page_info->nents);
-	if (st == NULL)
+	if (!st)
 		goto err_free_sg;
 
         if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +41 -25

189 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +3 -3
index e46ae19..2cb4bb4 100644
@@ -177,7 +177,7 @@ int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid)
 		   info_entry->info->hyper_dmabuf_rdomain == domid)
 			return info_entry->info->hyper_dmabuf_id;
 
-	return -1;
+	return -ENOENT;
 }
 
 struct hyper_dmabuf_imported_sgt_info *hyper_dmabuf_find_imported(int id)
@@ -204,7 +204,7 @@ int hyper_dmabuf_remove_exported(int id)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 int hyper_dmabuf_remove_imported(int id)
@@ -219,5 +219,5 @@ int hyper_dmabuf_remove_imported(int id)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +3 -2
index dd4bb01..6e24442 100644
@@ -100,7 +100,7 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_req *req,
 		 * operands0 : hyper_dmabuf_id
 		 * operands1 : map(=1)/unmap(=2)/attach(=3)/detach(=4)
 		 */
-		for (i=0; i<2; i++)
+		for (i = 0; i < 2; i++)
 			req->operands[i] = operands[i];
 		break;
 
@@ -199,6 +199,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		 */
 		dev_dbg(hyper_dmabuf_private.device,
 			"%s: processing HYPER_DMABUF_NOTIFY_UNEXPORT\n", __func__);
+
 		sgt_info = hyper_dmabuf_find_imported(req->operands[0]);
 
 		if (sgt_info) {
@@ -232,6 +233,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		 */
 		dev_dbg(hyper_dmabuf_private.device,
 			"%s: HYPER_DMABUF_OPS_TO_SOURCE\n", __func__);
+
 		ret = hyper_dmabuf_remote_sync(req->operands[0], req->operands[1]);
 		if (ret)
 			req->status = HYPER_DMABUF_REQ_ERROR;
@@ -271,7 +273,6 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	memcpy(temp_req, req, sizeof(*temp_req));
 
 	proc = kcalloc(1, sizeof(struct cmd_process), GFP_KERNEL);
-
 	proc->rq = temp_req;
 	proc->domid = domid;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +19 -19
index f93c936..a74e800 100644
@@ -71,7 +71,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	if (!sgt_info) {
 		dev_err(hyper_dmabuf_private.device,
 			"dmabuf remote sync::can't find exported list\n");
-		return -EINVAL;
+		return -ENOENT;
 	}
 
 	switch (ops) {
@@ -85,7 +85,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(attachl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_ATTACH\n");
-			return -EINVAL;
+			return PTR_ERR(attachl->attach);
 		}
 
 		list_add(&attachl->list, &sgt_info->active_attached->list);
@@ -97,7 +97,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_DETACH\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf attachment left to be detached\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -113,8 +113,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
 			dev_err(hyper_dmabuf_private.device,
-				"no more dmabuf attachment left to be detached\n");
-			return -EINVAL;
+				"no more dmabuf attachment left to be mapped\n");
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -126,7 +126,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(sgtl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
-			return -EINVAL;
+			return PTR_ERR(sgtl->sgt);
 		}
 		list_add(&sgtl->list, &sgt_info->active_sgts->list);
 		break;
@@ -137,8 +137,8 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_UNMAP\n");
 			dev_err(hyper_dmabuf_private.device,
-				"no more SGT or attachment left to be freed\n");
-			return -EINVAL;
+				"no more SGT or attachment left to be unmapped\n");
+			return -EFAULT;
 		}
 
 		attachl = list_first_entry(&sgt_info->active_attached->list,
@@ -176,19 +176,19 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
 		ret = dma_buf_begin_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
-		if (!ret) {
+		if (ret) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS\n");
-			ret = -EINVAL;
+			return ret;
 		}
 		break;
 
 	case HYPER_DMABUF_OPS_END_CPU_ACCESS:
 		ret = dma_buf_end_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
-		if (!ret) {
+		if (ret) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_END_CPU_ACCESS\n");
-			ret = -EINVAL;
+			return ret;
 		}
 		break;
 
@@ -206,7 +206,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_kmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KMAP(_ATOMIC)\n");
-			return -EINVAL;
+			return PTR_ERR(va_kmapl->vaddr);
 		}
 		list_add(&va_kmapl->list, &sgt_info->va_kmapped->list);
 		break;
@@ -218,15 +218,15 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf VA to be freed\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		va_kmapl = list_first_entry(&sgt_info->va_kmapped->list,
 					    struct kmap_vaddr_list, list);
-		if (va_kmapl->vaddr == NULL) {
+		if (!va_kmapl->vaddr) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KUNMAP(_ATOMIC)\n");
-			return -EINVAL;
+			return PTR_ERR(va_kmapl->vaddr);
 		}
 
 		/* unmapping 1 page */
@@ -256,7 +256,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_vmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VMAP\n");
-			return -EINVAL;
+			return PTR_ERR(va_vmapl->vaddr);
 		}
 		list_add(&va_vmapl->list, &sgt_info->va_vmapped->list);
 		break;
@@ -267,14 +267,14 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
 			dev_err(hyper_dmabuf_private.device,
 				"no more dmabuf VA to be freed\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 		va_vmapl = list_first_entry(&sgt_info->va_vmapped->list,
 					struct vmap_vaddr_list, list);
 		if (!va_vmapl || va_vmapl->vaddr == NULL) {
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VUNMAP\n");
-			return -EINVAL;
+			return -EFAULT;
 		}
 
 		dma_buf_vunmap(sgt_info->dma_buf, va_vmapl->vaddr);
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +10 -10
index 9d67b47..2cc35e3 100644
@@ -232,7 +232,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 	/* from exporter to importer */
 	shared_ring = (void *)__get_free_pages(GFP_KERNEL, 1);
 	if (shared_ring == 0) {
-		return -EINVAL;
+		return -ENOMEM;
 	}
 
 	sring = (struct xen_comm_sring *) shared_ring;
@@ -246,17 +246,17 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 							   0);
 	if (ring_info->gref_ring < 0) {
 		/* fail to get gref */
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	alloc_unbound.dom = DOMID_SELF;
 	alloc_unbound.remote_dom = domid;
 	ret = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
 					&alloc_unbound);
-	if (ret != 0) {
+	if (ret) {
 		dev_err(hyper_dmabuf_private.device,
 			"Cannot allocate event channel\n");
-		return -EINVAL;
+		return -EIO;
 	}
 
 	/* setting up interrupt */
@@ -271,7 +271,7 @@ int hyper_dmabuf_xen_init_tx_rbuf(int domid)
 		HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
 		gnttab_end_foreign_access(ring_info->gref_ring, 0,
 					virt_to_mfn(shared_ring));
-		return -EINVAL;
+		return -EIO;
 	}
 
 	ring_info->rdomain = domid;
@@ -387,7 +387,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	map_ops = kmalloc(sizeof(*map_ops), GFP_KERNEL);
 
 	if (gnttab_alloc_pages(1, &shared_ring)) {
-		return -EINVAL;
+		return -ENOMEM;
 	}
 
 	gnttab_set_map_op(&map_ops[0], (unsigned long)pfn_to_kaddr(page_to_pfn(shared_ring)),
@@ -399,12 +399,12 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	ret = gnttab_map_refs(map_ops, NULL, &shared_ring, 1);
 	if (ret < 0) {
 		dev_err(hyper_dmabuf_private.device, "Cannot map ring\n");
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	if (map_ops[0].status) {
 		dev_err(hyper_dmabuf_private.device, "Ring mapping failed\n");
-		return -EINVAL;
+		return -EFAULT;
 	} else {
 		ring_info->unmap_op.handle = map_ops[0].handle;
 	}
@@ -418,7 +418,7 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 	ret = bind_interdomain_evtchn_to_irq(domid, rx_port);
 
 	if (ret < 0) {
-		return -EINVAL;
+		return -EIO;
 	}
 
 	ring_info->irq = ret;
@@ -511,7 +511,7 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 	if (!ring_info) {
 		dev_err(hyper_dmabuf_private.device,
 			"Can't find ring info for the channel\n");
-		return -EINVAL;
+		return -ENOENT;
 	}
 
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +2 -2
index 0fa2d55..2f469da 100644
@@ -110,7 +110,7 @@ int xen_comm_remove_tx_ring(int domid)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 int xen_comm_remove_rx_ring(int domid)
@@ -125,7 +125,7 @@ int xen_comm_remove_rx_ring(int domid)
 			return 0;
 		}
 
-	return -1;
+	return -ENOENT;
 }
 
 void xen_comm_foreach_tx_ring(void (*func)(int domid))
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +1 -1
index b158c11..c03e5a0 100644
@@ -388,7 +388,7 @@ int hyper_dmabuf_xen_unmap_shared_pages(void **refs_info, int nents) {
 	if (gnttab_unmap_refs(sh_pages_info->unmap_ops, NULL,
 			      sh_pages_info->data_pages, nents) ) {
 		dev_err(hyper_dmabuf_private.device, "Cannot unmap data pages\n");
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	gnttab_free_pages(nents, sh_pages_info->data_pages);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#42 lore raw

RFC PATCH 28/60 hyper_dmabuf: address several synchronization issues

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

This patch addresses several synchronization issues while sharing DMA_BUF with another VM.

1. Set WAIT_AFTER_SYNC_REQ to false by default to prevent possible performance degradation when waing for the response for every syncrhonization request to exporter VM.

2. Removed HYPER_DMABUF_OPS_RELEASE_FINAL message - now exporter can automatically detect when there are no more consumers of DMA_BUF so importer VM doesn't have to send out this message.

3. Renamed HYPER_DMABUF_FIRST_EXPORT into HYPER_DMABUF_EXPORT_FD

4. Introduced HYPER_DMABUF_EXPORT_FD_FAILED message to undo HYPER_DMABUF_FIRST_EXPORT in case of any failure while executing hyper_dmabuf_export_fd_ioctl

5. Waiting until other VM processes all pending requests when ring buffers are all full.

6. Create hyper_dmabuf.h with definitions of driver interface under include/uapi/xen/

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 21 ++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 17 +++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h      | 74 +----------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 30 +++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |  4 +-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    | 24 ++++--
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  5 +-
 include/uapi/xen/hyper_dmabuf.h                    | 96 ++++++++++++++++++++++
 8 files changed, 163 insertions(+), 108 deletions(-)
 create mode 100644 include/uapi/xen/hyper_dmabuf.h
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +6 -15
index a0b3946..5a034ffb 100644
@@ -187,10 +187,7 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 	 * side.
 	 */
 	if (!force &&
-	    (!list_empty(&sgt_info->va_kmapped->list) ||
-	    !list_empty(&sgt_info->va_vmapped->list) ||
-	    !list_empty(&sgt_info->active_sgts->list) ||
-	    !list_empty(&sgt_info->active_attached->list))) {
+	    sgt_info->importer_exported) {
 		dev_warn(hyper_dmabuf_private.device, "dma-buf is used by importer\n");
 		return -EPERM;
 	}
@@ -259,7 +256,7 @@ int hyper_dmabuf_cleanup_sgt_info(struct hyper_dmabuf_sgt_info *sgt_info, int fo
 	return 0;
 }
 
-#define WAIT_AFTER_SYNC_REQ 1
+#define WAIT_AFTER_SYNC_REQ 0
 
 inline int hyper_dmabuf_sync_request(int id, int dmabuf_ops)
 {
@@ -431,17 +428,11 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dma_buf)
 	final_release = sgt_info && !sgt_info->valid &&
 		        !sgt_info->num_importers;
 
-	if (final_release) {
-		ret = hyper_dmabuf_sync_request(sgt_info->hyper_dmabuf_id,
-						HYPER_DMABUF_OPS_RELEASE_FINAL);
-	} else {
-		ret = hyper_dmabuf_sync_request(sgt_info->hyper_dmabuf_id,
-						HYPER_DMABUF_OPS_RELEASE);
-	}
-
+	ret = hyper_dmabuf_sync_request(sgt_info->hyper_dmabuf_id,
+					HYPER_DMABUF_OPS_RELEASE);
 	if (ret < 0) {
-		dev_err(hyper_dmabuf_private.device,
-			"hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
+		dev_warn(hyper_dmabuf_private.device,
+			 "hyper_dmabuf::%s Error:send dmabuf sync request failed\n", __func__);
 	}
 
 	/*
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +14 -3
index 19ca725..58b115a 100644
@@ -35,6 +35,7 @@
 #include <linux/dma-buf.h>
 #include <linux/delay.h>
 #include <linux/list.h>
+#include <xen/hyper_dmabuf.h>
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_ioctl.h"
 #include "hyper_dmabuf_list.h"
@@ -282,12 +283,17 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 	/* send notification for export_fd to exporter */
 	operand = sgt_info->hyper_dmabuf_id;
 
+	dev_dbg(hyper_dmabuf_private.device, "Exporting fd of buffer %d\n", operand);
+
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_FIRST_EXPORT, &operand);
+	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT_FD, &operand);
 
 	ret = ops->send_req(HYPER_DMABUF_DOM_ID(operand), req, true);
 
 	if (ret < 0) {
+		/* in case of timeout other end eventually will receive request, so we need to undo it */
+		hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT_FD_FAILED, &operand);
+		ops->send_req(HYPER_DMABUF_DOM_ID(operand), req, false);
 		kfree(req);
 		dev_err(hyper_dmabuf_private.device, "Failed to create sgt or notify exporter\n");
 		sgt_info->num_importers--;
@@ -298,12 +304,12 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 
 	if (ret == HYPER_DMABUF_REQ_ERROR) {
 		dev_err(hyper_dmabuf_private.device,
-			"Buffer invalid\n");
+			"Buffer invalid %d, cannot import\n", operand);
 		sgt_info->num_importers--;
 		mutex_unlock(&hyper_dmabuf_private.lock);
 		return -EINVAL;
 	} else {
-		dev_dbg(hyper_dmabuf_private.device, "Can import buffer\n");
+		dev_dbg(hyper_dmabuf_private.device, "Can import buffer %d\n", operand);
 		ret = 0;
 	}
 
@@ -322,7 +328,12 @@ static int hyper_dmabuf_export_fd_ioctl(void *data)
 						   &sgt_info->refs_info);
 
 		if (!data_pages) {
+			dev_err(hyper_dmabuf_private.device, "Cannot map pages of buffer %d\n", operand);
 			sgt_info->num_importers--;
+			req = kcalloc(1, sizeof(*req), GFP_KERNEL);
+			hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT_FD_FAILED, &operand);
+			ops->send_req(HYPER_DMABUF_DOM_ID(operand), req, false);
+			kfree(req);
 			mutex_unlock(&hyper_dmabuf_private.lock);
 			return -EINVAL;
 		}
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h +3 -71

83 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +24 -6
index 6e24442..3111cdc 100644
@@ -79,9 +79,10 @@ void hyper_dmabuf_create_request(struct hyper_dmabuf_req *req,
 		req->operands[0] = operands[0];
 		break;
 
-	case HYPER_DMABUF_FIRST_EXPORT:
-		/* dmabuf fd is being created on imported side for first time */
-		/* command : HYPER_DMABUF_FIRST_EXPORT,
+	case HYPER_DMABUF_EXPORT_FD:
+	case HYPER_DMABUF_EXPORT_FD_FAILED:
+		/* dmabuf fd is being created on imported side or importing failed */
+		/* command : HYPER_DMABUF_EXPORT_FD or HYPER_DMABUF_EXPORT_FD_FAILED,
 		 * operands0 : hyper_dmabuf_id
 		 */
 		req->operands[0] = operands[0];
@@ -244,8 +245,10 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	}
 
 	/* synchronous dma_buf_fd export */
-	if (req->command == HYPER_DMABUF_FIRST_EXPORT) {
+	if (req->command == HYPER_DMABUF_EXPORT_FD) {
 		/* find a corresponding SGT for the id */
+		dev_dbg(hyper_dmabuf_private.device,
+			"Processing HYPER_DMABUF_EXPORT_FD %d\n", req->operands[0]);
 		exp_sgt_info = hyper_dmabuf_find_exported(req->operands[0]);
 
 		if (!exp_sgt_info) {
@@ -254,17 +257,32 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 			req->status = HYPER_DMABUF_REQ_ERROR;
 		} else if (!exp_sgt_info->valid) {
 			dev_dbg(hyper_dmabuf_private.device,
-				"Buffer no longer valid - cannot export\n");
+				"Buffer no longer valid - cannot export fd %d\n", req->operands[0]);
 			req->status = HYPER_DMABUF_REQ_ERROR;
 		} else {
 			dev_dbg(hyper_dmabuf_private.device,
-				"Buffer still valid - can export\n");
+				"Buffer still valid - can export fd%d\n", req->operands[0]);
 			exp_sgt_info->importer_exported++;
 			req->status = HYPER_DMABUF_REQ_PROCESSED;
 		}
 		return req->command;
 	}
 
+	if (req->command == HYPER_DMABUF_EXPORT_FD_FAILED) {
+		dev_dbg(hyper_dmabuf_private.device,
+			"Processing HYPER_DMABUF_EXPORT_FD_FAILED %d\n", req->operands[0]);
+		exp_sgt_info = hyper_dmabuf_find_exported(req->operands[0]);
+
+		if (!exp_sgt_info) {
+			dev_err(hyper_dmabuf_private.device,
+				"critical err: requested sgt_info can't be found %d\n", req->operands[0]);
+			req->status = HYPER_DMABUF_REQ_ERROR;
+		} else {
+			exp_sgt_info->importer_exported--;
+			req->status = HYPER_DMABUF_REQ_PROCESSED;
+		}
+		return req->command;
+	}
 
 	dev_dbg(hyper_dmabuf_private.device,
 		"%s: putting request to workqueue\n", __func__);
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +2 -2
index 8b3c857..50ce617 100644
@@ -43,7 +43,8 @@ struct hyper_dmabuf_resp {
 
 enum hyper_dmabuf_command {
 	HYPER_DMABUF_EXPORT = 0x10,
-	HYPER_DMABUF_FIRST_EXPORT,
+	HYPER_DMABUF_EXPORT_FD,
+	HYPER_DMABUF_EXPORT_FD_FAILED,
 	HYPER_DMABUF_NOTIFY_UNEXPORT,
 	HYPER_DMABUF_OPS_TO_REMOTE,
 	HYPER_DMABUF_OPS_TO_SOURCE,
@@ -55,7 +56,6 @@ enum hyper_dmabuf_ops {
 	HYPER_DMABUF_OPS_MAP,
 	HYPER_DMABUF_OPS_UNMAP,
 	HYPER_DMABUF_OPS_RELEASE,
-	HYPER_DMABUF_OPS_RELEASE_FINAL,
 	HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS,
 	HYPER_DMABUF_OPS_END_CPU_ACCESS,
 	HYPER_DMABUF_OPS_KMAP_ATOMIC,
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +15 -9
index a74e800..0eded61 100644
@@ -152,13 +152,25 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		kfree(sgtl);
 		break;
 
-	case HYPER_DMABUF_OPS_RELEASE_FINAL:
+	case HYPER_DMABUF_OPS_RELEASE:
+		dev_dbg(hyper_dmabuf_private.device,
+			"Buffer %d released, references left: %d\n",
+			 sgt_info->hyper_dmabuf_id,
+			 sgt_info->importer_exported -1);
+                sgt_info->importer_exported--;
+		/* If there are still importers just break, if no then continue with final cleanup */
+		if (sgt_info->importer_exported)
+			break;
+
 		/*
 		 * Importer just released buffer fd, check if there is any other importer still using it.
 		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
-		 if (list_empty(&sgt_info->active_attached->list) &&
-		     !sgt_info->valid) {
+		dev_dbg(hyper_dmabuf_private.device,
+			"Buffer %d final released\n", sgt_info->hyper_dmabuf_id);
+
+		if (!sgt_info->valid && !sgt_info->importer_exported &&
+		    !sgt_info->unexport_scheduled) {
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
 			hyper_dmabuf_remove_exported(id);
 			kfree(sgt_info);
@@ -168,12 +180,6 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 		break;
 
-	case HYPER_DMABUF_OPS_RELEASE:
-		/* place holder */
-                sgt_info->importer_exported--;
-
-		break;
-
 	case HYPER_DMABUF_OPS_BEGIN_CPU_ACCESS:
 		ret = dma_buf_begin_cpu_access(sgt_info->dma_buf, DMA_BIDIRECTIONAL);
 		if (ret) {
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +3 -2
index 2cc35e3..ce9862a 100644
@@ -519,8 +519,9 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 
 	ring = &ring_info->ring_front;
 
-	if (RING_FULL(ring))
-		return -EBUSY;
+	while (RING_FULL(ring)) {
+		usleep_range(100, 120);
+	}
 
 	new_req = RING_GET_REQUEST(ring, ring->req_prod_pvt);
 	if (!new_req) {
include/uapi/xen/hyper_dmabuf.h new file +96 -0

96 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#43 lore raw

RFC PATCH 29/60 hyper_dmabuf: make sure to release allocated buffers when exiting

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

It is required to release all allocated buffers when the application crashes. With the change, hyper_dmabuf_sgt_info includes file pointers for the driver. If it's released unexpectedly, the driver is now unexporting all already-exported buffers to prevent memory leak.

In case there are multiple applications exporting same buffer to another VM, unexporting is not started when one of those crashes. Actual unexporting is invoked only if the last application that exported the buffer is crashed or finished via "emergency-unexport" routine, that is executed automatically when all of file pointers opened for accessing hyper_dmabuf driver are closed.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c    |  6 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c  | 73 ++++++++++++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h  |  2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c   | 14 +++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h   |  4 ++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h |  7 +++
 6 files changed, 81 insertions(+), 25 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +4 -2
index 44a9139..a12d4dc 100644
@@ -54,7 +54,7 @@ static int __init hyper_dmabuf_drv_init(void)
 {
 	int ret = 0;
 
-	printk( KERN_NOTICE "hyper_dmabuf_starting: Initialization started" );
+	printk( KERN_NOTICE "hyper_dmabuf_starting: Initialization started\n");
 
 	mutex_init(&hyper_dmabuf_private.lock);
 
@@ -122,7 +122,9 @@ static void hyper_dmabuf_drv_exit(void)
 	if (hyper_dmabuf_private.id_queue)
 		destroy_reusable_list();
 
-	printk( KERN_NOTICE "dma_buf-src_sink model: Exiting" );
+	dev_info(hyper_dmabuf_private.device,
+		 "hyper_dmabuf driver: Exiting\n");
+
 	unregister_device();
 }
 /*===============================================================================================*/
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +51 -22

149 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.h +1 -1
index 8355e30..ebfbb84 100644
@@ -25,7 +25,7 @@
 #ifndef __HYPER_DMABUF_IOCTL_H__
 #define __HYPER_DMABUF_IOCTL_H__
 
-typedef int (*hyper_dmabuf_ioctl_t)(void *data);
+typedef int (*hyper_dmabuf_ioctl_t)(struct file *filp, void *data);
 
 struct hyper_dmabuf_ioctl_desc {
 	unsigned int cmd;
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +14 -0
index 2cb4bb4..c1285eb 100644
@@ -221,3 +221,17 @@ int hyper_dmabuf_remove_imported(int id)
 
 	return -ENOENT;
 }
+
+void hyper_dmabuf_foreach_exported(
+	void (*func)(struct hyper_dmabuf_sgt_info *, void *attr),
+	void *attr)
+{
+	struct hyper_dmabuf_info_entry_exported *info_entry;
+	struct hlist_node *tmp;
+	int bkt;
+
+	hash_for_each_safe(hyper_dmabuf_hash_exported, bkt, tmp,
+			info_entry, node) {
+		func(info_entry->info, attr);
+	}
+}
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +4 -0
index 35dc722..925b0d1 100644
@@ -61,6 +61,10 @@ int hyper_dmabuf_remove_exported(int id);
 
 int hyper_dmabuf_remove_imported(int id);
 
+void hyper_dmabuf_foreach_exported(
+	void (*func)(struct hyper_dmabuf_sgt_info *, void *attr),
+	void *attr);
+
 int hyper_dmabuf_register_sysfs(struct device *dev);
 int hyper_dmabuf_unregister_sysfs(struct device *dev);
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +7 -0
index a41fd0a..9952b3f 100644
@@ -80,6 +80,13 @@ struct hyper_dmabuf_sgt_info {
 	void *refs_info; /* hypervisor-specific info for the references */
 	struct delayed_work unexport_work;
 	bool unexport_scheduled;
+	/* owner of buffer
+	 * TODO: that is naiive as buffer may be reused by
+	 * another userspace app, so here list of struct file should be kept
+	 * and emergency unexport should be executed only after last of buffer
+	 * uses releases hyper_dmabuf device
+	 */
+	struct file *filp;
 	int private[4]; /* device specific info (e.g. image's meta info?) */
 };
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#44 lore raw

RFC PATCH 30/60 hyper_dmabuf: free already mapped pages when error happens

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

It is needed to freeing already-mapped pages if it gets error before finishing mapping all pages.

---
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 43 +++++++++++++++++++---
 1 file changed, 38 insertions(+), 5 deletions(-)
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +38 -5
index c03e5a0..524f75c 100644
@@ -255,7 +255,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	if (lvl3_map_ops.status) {
 		dev_err(hyper_dmabuf_private.device, "HYPERVISOR map grant ref failed status = %d",
 			lvl3_map_ops.status);
-		return NULL;
+		goto error_cleanup_lvl3;
 	} else {
 		lvl3_unmap_ops.handle = lvl3_map_ops.handle;
 	}
@@ -263,7 +263,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	/* Map all second level pages */
 	if (gnttab_alloc_pages(n_lvl2_grefs, lvl2_table_pages)) {
 		dev_err(hyper_dmabuf_private.device, "Cannot allocate pages\n");
-		return NULL;
+		goto error_cleanup_lvl3;
 	}
 
 	for (i = 0; i < n_lvl2_grefs; i++) {
@@ -277,6 +277,9 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	if (gnttab_unmap_refs(&lvl3_unmap_ops, NULL, &lvl3_table_page, 1)) {
 		dev_err(hyper_dmabuf_private.device, "xen: cannot unmap top level page\n");
 		return NULL;
+	} else {
+		/* Mark that page was unmapped */
+		lvl3_unmap_ops.handle = -1;
 	}
 
 	if (gnttab_map_refs(lvl2_map_ops, NULL, lvl2_table_pages, n_lvl2_grefs)) {
@@ -290,7 +293,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 			dev_err(hyper_dmabuf_private.device,
 				"HYPERVISOR map grant ref failed status = %d",
 				lvl2_map_ops[i].status);
-			return NULL;
+			goto error_cleanup_lvl2;
 		} else {
 			lvl2_unmap_ops[i].handle = lvl2_map_ops[i].handle;
 		}
@@ -298,7 +301,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 
 	if (gnttab_alloc_pages(nents, data_pages)) {
 		dev_err(hyper_dmabuf_private.device, "Cannot allocate pages\n");
-		return NULL;
+		goto error_cleanup_lvl2;
 	}
 
 	k = 0;
@@ -343,6 +346,11 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 			      n_lvl2_grefs)) {
 		dev_err(hyper_dmabuf_private.device, "Cannot unmap 2nd level refs\n");
 		return NULL;
+	} else {
+		/* Mark that pages were unmapped */
+		for (i = 0; i < n_lvl2_grefs; i++) {
+			lvl2_unmap_ops[i].handle = -1;
+		}
 	}
 
 	for (i = 0; i < nents; i++) {
@@ -350,7 +358,7 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 			dev_err(hyper_dmabuf_private.device,
 				"HYPERVISOR map grant ref failed status = %d\n",
 				data_map_ops[i].status);
-			return NULL;
+			goto error_cleanup_data;
 		} else {
 			data_unmap_ops[i].handle = data_map_ops[i].handle;
 		}
@@ -369,6 +377,31 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 
 	dev_dbg(hyper_dmabuf_private.device, "%s exit\n", __func__);
 	return data_pages;
+
+error_cleanup_data:
+	gnttab_unmap_refs(data_unmap_ops, NULL, data_pages,
+			  nents);
+
+	gnttab_free_pages(nents, data_pages);
+
+error_cleanup_lvl2:
+	if (lvl2_unmap_ops[0].handle != -1)
+		gnttab_unmap_refs(lvl2_unmap_ops, NULL, lvl2_table_pages,
+				  n_lvl2_grefs);
+	gnttab_free_pages(n_lvl2_grefs, lvl2_table_pages);
+
+error_cleanup_lvl3:
+	if (lvl3_unmap_ops.handle != -1)
+		gnttab_unmap_refs(&lvl3_unmap_ops, NULL, &lvl3_table_page, 1);
+	gnttab_free_pages(1, &lvl3_table_page);
+
+	kfree(lvl2_table_pages);
+	kfree(lvl2_map_ops);
+	kfree(lvl2_unmap_ops);
+	kfree(data_map_ops);
+
+
+	return NULL;
 }
 
 int hyper_dmabuf_xen_unmap_shared_pages(void **refs_info, int nents) {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#45 lore raw

RFC PATCH 31/60 hyper_dmabuf: built-in compilation option

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Enabled built-in compilation option of hyper_dmabuf driver. Also, moved backend initialization into open() to remove its dependencies on Kernel booting sequence.

hyper_dmabuf.h is now installed as one of standard header files of Kernel.

This patch also addresses possible memory leaks in various places.

---
 drivers/xen/hyper_dmabuf/Kconfig                   |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  17 ++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         |  14 +++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  13 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 113 +++++++++++++++++----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  15 +++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  20 ++++
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |  32 +++++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |   6 ++
 .../hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c  |  15 +++
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    |   6 ++
 include/uapi/xen/Kbuild                            |   6 ++
 13 files changed, 227 insertions(+), 32 deletions(-)
 create mode 100644 include/uapi/xen/Kbuild
drivers/xen/hyper_dmabuf/Kconfig +1 -0
index 56633a2..185fdf8 100644
@@ -14,6 +14,7 @@ config HYPER_DMABUF_XEN
 config HYPER_DMABUF_SYSFS
 	bool "Enable sysfs information about hyper DMA buffers"
 	default y
+	depends on HYPER_DMABUF
 	help
 	  Expose information about imported and exported buffers using
 	  hyper_dmabuf driver
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +9 -8
index a12d4dc..92d710e 100644
@@ -66,6 +66,15 @@ static int __init hyper_dmabuf_drv_init(void)
 #ifdef CONFIG_HYPER_DMABUF_XEN
 	hyper_dmabuf_private.backend_ops = &xen_backend_ops;
 #endif
+	/*
+	 * Defer backend setup to first open call.
+	 * Due to fact that some hypervisors eg. Xen, may have dependencies
+	 * to userspace daemons like xenstored, in that case all xenstore
+	 * calls done from kernel will block until that deamon will be
+	 * started, in case where module is built in that will block entire
+	 * kernel initialization.
+	 */
+	hyper_dmabuf_private.backend_initialized = false;
 
 	dev_info(hyper_dmabuf_private.device,
 		 "initializing database for imported/exported dmabufs\n");
@@ -73,7 +82,6 @@ static int __init hyper_dmabuf_drv_init(void)
 	/* device structure initialization */
 	/* currently only does work-queue initialization */
 	hyper_dmabuf_private.work_queue = create_workqueue("hyper_dmabuf_wqueue");
-	hyper_dmabuf_private.domid = hyper_dmabuf_private.backend_ops->get_vm_id();
 
 	ret = hyper_dmabuf_table_init();
 	if (ret < 0) {
@@ -82,13 +90,6 @@ static int __init hyper_dmabuf_drv_init(void)
 		return ret;
 	}
 
-	ret = hyper_dmabuf_private.backend_ops->init_comm_env();
-	if (ret < 0) {
-		dev_err(hyper_dmabuf_private.device,
-			"failed to initiailize hypervisor-specific comm env\n");
-		return ret;
-	}
-
 #ifdef CONFIG_HYPER_DMABUF_SYSFS
 	ret = hyper_dmabuf_register_sysfs(hyper_dmabuf_private.device);
 	if (ret < 0) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +1 -0
index 8445416..91fda04 100644
@@ -77,6 +77,7 @@ struct hyper_dmabuf_private {
 	/* backend ops - hypervisor specific */
 	struct hyper_dmabuf_backend_ops *backend_ops;
 	struct mutex lock;
+	bool backend_initialized;
 };
 
 #endif /* __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +14 -0
index 35bfdfb..fe95091 100644
@@ -40,6 +40,13 @@ void store_reusable_id(int id)
 	struct list_reusable_id *new_reusable;
 
 	new_reusable = kmalloc(sizeof(*new_reusable), GFP_KERNEL);
+
+	if (!new_reusable) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return;
+	}
+
 	new_reusable->id = id;
 
 	list_add(&new_reusable->list, &reusable_head->list);
@@ -94,6 +101,13 @@ int hyper_dmabuf_get_id(void)
 	/* first cla to hyper_dmabuf_get_id */
 	if (id == 0) {
 		reusable_head = kmalloc(sizeof(*reusable_head), GFP_KERNEL);
+
+		if (!reusable_head) {
+			dev_err(hyper_dmabuf_private.device,
+				"No memory left to be allocated\n");
+			return -ENOMEM;
+		}
+
 		reusable_head->id = -1; /* list head have invalid id */
 		INIT_LIST_HEAD(&reusable_head->list);
 		hyper_dmabuf_private.id_queue = reusable_head;
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +11 -2
index 5a034ffb..34dfa18 100644
@@ -270,6 +270,12 @@ inline int hyper_dmabuf_sync_request(int id, int dmabuf_ops)
 
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
 
+	if (!req) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	hyper_dmabuf_create_request(req, HYPER_DMABUF_OPS_TO_SOURCE, &operands[0]);
 
 	/* send request and wait for a response */
@@ -366,8 +372,11 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	return st;
 
 err_free_sg:
-	sg_free_table(st);
-	kfree(st);
+	if (st) {
+		sg_free_table(st);
+		kfree(st);
+	}
+
 	return NULL;
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +95 -18

177 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +15 -0
index c1285eb..90c8c56 100644
@@ -34,8 +34,11 @@
 #include <asm/uaccess.h>
 #include <linux/hashtable.h>
 #include <linux/dma-buf.h>
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_list.h"
 
+extern struct hyper_dmabuf_private hyper_dmabuf_private;
+
 DECLARE_HASHTABLE(hyper_dmabuf_hash_imported, MAX_ENTRY_IMPORTED);
 DECLARE_HASHTABLE(hyper_dmabuf_hash_exported, MAX_ENTRY_EXPORTED);
 
@@ -132,6 +135,12 @@ int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info)
 
 	info_entry = kmalloc(sizeof(*info_entry), GFP_KERNEL);
 
+	if (!info_entry) {
+		dev_err(hyper_dmabuf_private.device,
+                        "No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_exported, &info_entry->node,
@@ -146,6 +155,12 @@ int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info)
 
 	info_entry = kmalloc(sizeof(*info_entry), GFP_KERNEL);
 
+	if (!info_entry) {
+		dev_err(hyper_dmabuf_private.device,
+                        "No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	info_entry->info = info;
 
 	hash_add(hyper_dmabuf_hash_imported, &info_entry->node,
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +20 -0
index 3111cdc..5f64261 100644
@@ -134,6 +134,13 @@ void cmd_process_work(struct work_struct *work)
 		 * operands5~8 : Driver-specific private data (e.g. graphic buffer's meta info)
 		 */
 		imported_sgt_info = kcalloc(1, sizeof(*imported_sgt_info), GFP_KERNEL);
+
+		if (!imported_sgt_info) {
+			dev_err(hyper_dmabuf_private.device,
+				"No memory left to be allocated\n");
+			break;
+		}
+
 		imported_sgt_info->hyper_dmabuf_id = req->operands[0];
 		imported_sgt_info->frst_ofst = req->operands[2];
 		imported_sgt_info->last_len = req->operands[3];
@@ -288,9 +295,22 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		"%s: putting request to workqueue\n", __func__);
 	temp_req = kmalloc(sizeof(*temp_req), GFP_KERNEL);
 
+	if (!temp_req) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	memcpy(temp_req, req, sizeof(*temp_req));
 
 	proc = kcalloc(1, sizeof(struct cmd_process), GFP_KERNEL);
+
+	if (!proc) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	proc->rq = temp_req;
 	proc->domid = domid;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +28 -4
index 0eded61..2dab833 100644
@@ -78,6 +78,12 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	case HYPER_DMABUF_OPS_ATTACH:
 		attachl = kcalloc(1, sizeof(*attachl), GFP_KERNEL);
 
+		if (!attachl) {
+			dev_err(hyper_dmabuf_private.device,
+				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_ATTACH\n");
+			return -ENOMEM;
+		}
+
 		attachl->attach = dma_buf_attach(sgt_info->dma_buf,
 						 hyper_dmabuf_private.device);
 
@@ -85,7 +91,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(attachl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_ATTACH\n");
-			return PTR_ERR(attachl->attach);
+			return -ENOMEM;
 		}
 
 		list_add(&attachl->list, &sgt_info->active_attached->list);
@@ -121,12 +127,19 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 					   struct attachment_list, list);
 
 		sgtl = kcalloc(1, sizeof(*sgtl), GFP_KERNEL);
+
+		if (!sgtl) {
+			dev_err(hyper_dmabuf_private.device,
+				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
+			return -ENOMEM;
+		}
+
 		sgtl->sgt = dma_buf_map_attachment(attachl->attach, DMA_BIDIRECTIONAL);
 		if (!sgtl->sgt) {
 			kfree(sgtl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_MAP\n");
-			return PTR_ERR(sgtl->sgt);
+			return -ENOMEM;
 		}
 		list_add(&sgtl->list, &sgt_info->active_sgts->list);
 		break;
@@ -201,6 +214,11 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	case HYPER_DMABUF_OPS_KMAP_ATOMIC:
 	case HYPER_DMABUF_OPS_KMAP:
 		va_kmapl = kcalloc(1, sizeof(*va_kmapl), GFP_KERNEL);
+		if (!va_kmapl) {
+			dev_err(hyper_dmabuf_private.device,
+				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KMAP(_ATOMIC)\n");
+			return -ENOMEM;
+		}
 
 		/* dummy kmapping of 1 page */
 		if (ops == HYPER_DMABUF_OPS_KMAP_ATOMIC)
@@ -212,7 +230,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_kmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_KMAP(_ATOMIC)\n");
-			return PTR_ERR(va_kmapl->vaddr);
+			return -ENOMEM;
 		}
 		list_add(&va_kmapl->list, &sgt_info->va_kmapped->list);
 		break;
@@ -255,6 +273,12 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	case HYPER_DMABUF_OPS_VMAP:
 		va_vmapl = kcalloc(1, sizeof(*va_vmapl), GFP_KERNEL);
 
+		if (!va_vmapl) {
+			dev_err(hyper_dmabuf_private.device,
+				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VMAP\n");
+			return -ENOMEM;
+		}
+
 		/* dummy vmapping */
 		va_vmapl->vaddr = dma_buf_vmap(sgt_info->dma_buf);
 
@@ -262,7 +286,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 			kfree(va_vmapl);
 			dev_err(hyper_dmabuf_private.device,
 				"dmabuf remote sync::error while processing HYPER_DMABUF_OPS_VMAP\n");
-			return PTR_ERR(va_vmapl->vaddr);
+			return -ENOMEM;
 		}
 		list_add(&va_vmapl->list, &sgt_info->va_vmapped->list);
 		break;
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +6 -0
index ce9862a..43dd3b6 100644
@@ -381,6 +381,12 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 
 	ring_info = kmalloc(sizeof(*ring_info), GFP_KERNEL);
 
+	if (!ring_info) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	ring_info->sdomain = domid;
 	ring_info->evtchn = rx_port;
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm_list.c +15 -0
index 2f469da..4708b49 100644
@@ -34,9 +34,12 @@
 #include <asm/uaccess.h>
 #include <linux/hashtable.h>
 #include <xen/grant_table.h>
+#include "../hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_xen_comm.h"
 #include "hyper_dmabuf_xen_comm_list.h"
 
+extern struct hyper_dmabuf_private hyper_dmabuf_private;
+
 DECLARE_HASHTABLE(xen_comm_tx_ring_hash, MAX_ENTRY_TX_RING);
 DECLARE_HASHTABLE(xen_comm_rx_ring_hash, MAX_ENTRY_RX_RING);
 
@@ -52,6 +55,12 @@ int xen_comm_add_tx_ring(struct xen_comm_tx_ring_info *ring_info)
 
 	info_entry = kmalloc(sizeof(*info_entry), GFP_KERNEL);
 
+	if (!info_entry) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	info_entry->info = ring_info;
 
 	hash_add(xen_comm_tx_ring_hash, &info_entry->node,
@@ -66,6 +75,12 @@ int xen_comm_add_rx_ring(struct xen_comm_rx_ring_info *ring_info)
 
 	info_entry = kmalloc(sizeof(*info_entry), GFP_KERNEL);
 
+	if (!info_entry) {
+		dev_err(hyper_dmabuf_private.device,
+			"No memory left to be allocated\n");
+		return -ENOMEM;
+	}
+
 	info_entry->info = ring_info;
 
 	hash_add(xen_comm_rx_ring_hash, &info_entry->node,
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +6 -0
index 524f75c..c6a2993 100644
@@ -96,6 +96,12 @@ int hyper_dmabuf_xen_share_pages(struct page **pages, int domid, int nents,
 	lvl2_table = (grant_ref_t *)__get_free_pages(GFP_KERNEL, n_lvl2_grefs);
 
 	sh_pages_info = kmalloc(sizeof(*sh_pages_info), GFP_KERNEL);
+
+	if (!sh_pages_info) {
+		dev_err(hyper_dmabuf_private.device, "No more space left\n");
+		return -ENOMEM;
+	}
+
 	*refs_info = (void *)sh_pages_info;
 
 	/* share data pages in rw mode*/
include/uapi/xen/Kbuild new file +6 -0
new file mode 100644
index 0000000..bf81f42
@@ -0,0 +1,6 @@
+# UAPI Header export list
+header-y += evtchn.h
+header-y += gntalloc.h
+header-y += gntdev.h
+header-y += privcmd.h
+header-y += hyper_dmabuf.h
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#46 lore raw

RFC PATCH 32/60 hyper_dmabuf: make all shared pages read-only

In reply to Dongwon Kim

All shared pages need to be read-only from importer's point of view to prevent the buffer from being corrupted.

This patch may need to be reverted if we find a better way to protect the original content in this sharing model.

---
 drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +8 -8
index c6a2993..1416a69 100644
@@ -104,24 +104,24 @@ int hyper_dmabuf_xen_share_pages(struct page **pages, int domid, int nents,
 
 	*refs_info = (void *)sh_pages_info;
 
-	/* share data pages in rw mode*/
+	/* share data pages in readonly mode for security */
 	for (i=0; i<nents; i++) {
 		lvl2_table[i] = gnttab_grant_foreign_access(domid,
 							    pfn_to_mfn(page_to_pfn(pages[i])),
-							    0);
+							    true /* read-only from remote domain */);
 	}
 
 	/* Share 2nd level addressing pages in readonly mode*/
 	for (i=0; i< n_lvl2_grefs; i++) {
 		lvl3_table[i] = gnttab_grant_foreign_access(domid,
 							    virt_to_mfn((unsigned long)lvl2_table+i*PAGE_SIZE ),
-							    1);
+							    true);
 	}
 
 	/* Share lvl3_table in readonly mode*/
 	lvl3_gref = gnttab_grant_foreign_access(domid,
 						virt_to_mfn((unsigned long)lvl3_table),
-						1);
+						true);
 
 
 	/* Store lvl3_table page to be freed later */
@@ -317,12 +317,12 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 		for (j = 0; j < REFS_PER_PAGE; j++) {
 			gnttab_set_map_op(&data_map_ops[k],
 					  (unsigned long)pfn_to_kaddr(page_to_pfn(data_pages[k])),
-					  GNTMAP_host_map,
+					  GNTMAP_host_map | GNTMAP_readonly,
 					  lvl2_table[j], domid);
 
 			gnttab_set_unmap_op(&data_unmap_ops[k],
 					    (unsigned long)pfn_to_kaddr(page_to_pfn(data_pages[k])),
-					    GNTMAP_host_map, -1);
+					    GNTMAP_host_map | GNTMAP_readonly, -1);
 			k++;
 		}
 	}
@@ -333,12 +333,12 @@ struct page ** hyper_dmabuf_xen_map_shared_pages(int lvl3_gref, int domid, int n
 	for (j = 0; j < nents_last; j++) {
 		gnttab_set_map_op(&data_map_ops[k],
 				  (unsigned long)pfn_to_kaddr(page_to_pfn(data_pages[k])),
-				  GNTMAP_host_map,
+				  GNTMAP_host_map | GNTMAP_readonly,
 				  lvl2_table[j], domid);
 
 		gnttab_set_unmap_op(&data_unmap_ops[k],
 				    (unsigned long)pfn_to_kaddr(page_to_pfn(data_pages[k])),
-				    GNTMAP_host_map, -1);
+				    GNTMAP_host_map | GNTMAP_readonly, -1);
 		k++;
 	}
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#47 lore raw

RFC PATCH 33/60 hyper_dmabuf: error checking on the result of dma_buf_map_attachment

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Added error checking on the result of function call, dma_buf_map_attachment

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +5 -0
index c0048d9..476c0d7 100644
@@ -149,6 +149,11 @@ static int hyper_dmabuf_export_remote(struct file *filp, void *data)
 
 	sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL);
 
+	if (IS_ERR(sgt)) {
+		dev_err(hyper_dmabuf_private.device, "Cannot map attachment\n");
+		return PTR_ERR(sgt);
+	}
+
 	sgt_info = kcalloc(1, sizeof(*sgt_info), GFP_KERNEL);
 
 	if(!sgt_info) {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#48 lore raw

RFC PATCH 34/60 hyper_dmabuf: extend DMA bitmask to 64-bits.

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Extending DMA bitmask of hyper_dmabuf device to cover whole address space driver may access.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +1 -1
index 476c0d7..f7d98c1 100644
@@ -723,7 +723,7 @@ int register_device(void)
 	hyper_dmabuf_private.device = hyper_dmabuf_miscdev.this_device;
 
 	/* TODO: Check if there is a different way to initialize dma mask nicely */
-	dma_coerce_mask_and_coherent(hyper_dmabuf_private.device, 0xFFFFFFFF);
+	dma_coerce_mask_and_coherent(hyper_dmabuf_private.device, DMA_BIT_MASK(64));
 
 	return ret;
 }
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#49 lore raw

RFC PATCH 35/60 hyper_dmabuf: 128bit hyper_dmabuf_id with random keys

In reply to Dongwon Kim

The length of hyper_dmabuf_id is increased to 128bit by adding random key (96bit) to the id. This is to prevent possible leak of the id by guessing on importer VM (by unauthorized application).

hyper_dmabuf_id_t is now defined as,

	typedef struct {
	    int id;
	    int rng_key[3];
	} hyper_dmabuf_id_t;
---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |   2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |   3 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c         |  57 ++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h         |  17 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        |  51 +++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 199 +++++++++++++--------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |  87 ++++++---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h       |  10 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        | 115 +++++++-----
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |   2 +-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |  21 ++-
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h    |   2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |  20 ++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h   |   2 -
 include/uapi/xen/hyper_dmabuf.h                    |  13 +-
 15 files changed, 372 insertions(+), 229 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +1 -1
index 92d710e..c802c3e 100644
@@ -30,9 +30,9 @@
 #include <linux/module.h>
 #include <linux/workqueue.h>
 #include <linux/device.h>
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_conf.h"
 #include "hyper_dmabuf_msg.h"
-#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_id.h"
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +2 -1
index 91fda04..ffe4d53 100644
@@ -26,11 +26,12 @@
 #define __LINUX_PUBLIC_HYPER_DMABUF_DRV_H__
 
 #include <linux/device.h>
+#include <xen/hyper_dmabuf.h>
 
 struct hyper_dmabuf_req;
 
 struct list_reusable_id {
-	int id;
+	hyper_dmabuf_id_t hid;
 	struct list_head list;
 };
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +38 -19

109 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_id.h +8 -9
index 4394903..a3336d9 100644
@@ -25,24 +25,23 @@
 #ifndef __HYPER_DMABUF_ID_H__
 #define __HYPER_DMABUF_ID_H__
 
-/* Importer combine source domain id with given hyper_dmabuf_id
- * to make it unique in case there are multiple exporters */
+#define HYPER_DMABUF_ID_CREATE(domid, cnt) \
+        ((((domid) & 0xFF) << 24) | ((cnt) & 0xFFFFFF))
 
-#define HYPER_DMABUF_ID_CREATE(domid, id) \
-	((((domid) & 0xFF) << 24) | ((id) & 0xFFFFFF))
-
-#define HYPER_DMABUF_DOM_ID(id) \
-	(((id) >> 24) & 0xFF)
+#define HYPER_DMABUF_DOM_ID(hid) \
+        (((hid.id) >> 24) & 0xFF)
 
 /* currently maximum number of buffers shared
  * at any given moment is limited to 1000
  */
 #define HYPER_DMABUF_ID_MAX 1000
 
-void store_reusable_id(int id);
+void store_reusable_hid(hyper_dmabuf_id_t hid);
 
 void destroy_reusable_list(void);
 
-int hyper_dmabuf_get_id(void);
+hyper_dmabuf_id_t hyper_dmabuf_get_hid(void);
+
+bool hyper_dmabuf_hid_keycomp(hyper_dmabuf_id_t hid1, hyper_dmabuf_id_t hid2);
 
 #endif /*__HYPER_DMABUF_ID_H*/
drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c +28 -23

174 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +123 -76

380 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +60 -27

173 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_list.h +5 -5
index 925b0d1..8f64db8 100644
@@ -49,17 +49,17 @@ int hyper_dmabuf_table_destroy(void);
 int hyper_dmabuf_register_exported(struct hyper_dmabuf_sgt_info *info);
 
 /* search for pre-exported sgt and return id of it if it exist */
-int hyper_dmabuf_find_id_exported(struct dma_buf *dmabuf, int domid);
+hyper_dmabuf_id_t hyper_dmabuf_find_hid_exported(struct dma_buf *dmabuf, int domid);
 
 int hyper_dmabuf_register_imported(struct hyper_dmabuf_imported_sgt_info* info);
 
-struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(int id);
+struct hyper_dmabuf_sgt_info *hyper_dmabuf_find_exported(hyper_dmabuf_id_t hid);
 
-struct hyper_dmabuf_imported_sgt_info *hyper_dmabuf_find_imported(int id);
+struct hyper_dmabuf_imported_sgt_info *hyper_dmabuf_find_imported(hyper_dmabuf_id_t hid);
 
-int hyper_dmabuf_remove_exported(int id);
+int hyper_dmabuf_remove_exported(hyper_dmabuf_id_t hid);
 
-int hyper_dmabuf_remove_imported(int id);
+int hyper_dmabuf_remove_imported(hyper_dmabuf_id_t hid);
 
 void hyper_dmabuf_foreach_exported(
 	void (*func)(struct hyper_dmabuf_sgt_info *, void *attr),
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +70 -45

219 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +1 -1
index 50ce617..636d6f1 100644
@@ -25,7 +25,7 @@
 #ifndef __HYPER_DMABUF_MSG_H__
 #define __HYPER_DMABUF_MSG_H__
 
-#define MAX_NUMBER_OF_OPERANDS 9
+#define MAX_NUMBER_OF_OPERANDS 13
 
 struct hyper_dmabuf_req {
 	unsigned int request_id;
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +12 -9
index 2dab833..be1d395 100644
@@ -31,10 +31,10 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/dma-buf.h>
+#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_struct.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_msg.h"
-#include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_id.h"
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_imp.h"
@@ -56,7 +56,7 @@ extern struct hyper_dmabuf_private hyper_dmabuf_private;
  * is what is created when initial exporting is issued so it
  * should not be modified or released by this fuction.
  */
-int hyper_dmabuf_remote_sync(int id, int ops)
+int hyper_dmabuf_remote_sync(hyper_dmabuf_id_t hid, int ops)
 {
 	struct hyper_dmabuf_sgt_info *sgt_info;
 	struct sgt_list *sgtl;
@@ -66,7 +66,7 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 	int ret;
 
 	/* find a coresponding SGT for the id */
-	sgt_info = hyper_dmabuf_find_exported(id);
+	sgt_info = hyper_dmabuf_find_exported(hid);
 
 	if (!sgt_info) {
 		dev_err(hyper_dmabuf_private.device,
@@ -167,9 +167,10 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 
 	case HYPER_DMABUF_OPS_RELEASE:
 		dev_dbg(hyper_dmabuf_private.device,
-			"Buffer %d released, references left: %d\n",
-			 sgt_info->hyper_dmabuf_id,
-			 sgt_info->importer_exported -1);
+			"Buffer {id:%d key:%d %d %d} released, references left: %d\n",
+			 sgt_info->hid.id, sgt_info->hid.rng_key[0], sgt_info->hid.rng_key[1],
+			 sgt_info->hid.rng_key[2], sgt_info->importer_exported -1);
+
                 sgt_info->importer_exported--;
 		/* If there are still importers just break, if no then continue with final cleanup */
 		if (sgt_info->importer_exported)
@@ -180,15 +181,17 @@ int hyper_dmabuf_remote_sync(int id, int ops)
 		 * If not and buffer was unexported, clean up shared data and remove that buffer.
 		 */
 		dev_dbg(hyper_dmabuf_private.device,
-			"Buffer %d final released\n", sgt_info->hyper_dmabuf_id);
+			"Buffer {id:%d key:%d %d %d} final released\n",
+			sgt_info->hid.id, sgt_info->hid.rng_key[0], sgt_info->hid.rng_key[1],
+			sgt_info->hid.rng_key[2]);
 
 		if (!sgt_info->valid && !sgt_info->importer_exported &&
 		    !sgt_info->unexport_scheduled) {
 			hyper_dmabuf_cleanup_sgt_info(sgt_info, false);
-			hyper_dmabuf_remove_exported(id);
+			hyper_dmabuf_remove_exported(hid);
 			kfree(sgt_info);
 			/* store hyper_dmabuf_id in the list for reuse */
-			store_reusable_id(id);
+			store_reusable_hid(hid);
 		}
 
 		break;
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.h +1 -1
index 71ee358..36638928 100644
@@ -25,6 +25,6 @@
 #ifndef __HYPER_DMABUF_REMOTE_SYNC_H__
 #define __HYPER_DMABUF_REMOTE_SYNC_H__
 
-int hyper_dmabuf_remote_sync(int id, int ops);
+int hyper_dmabuf_remote_sync(hyper_dmabuf_id_t hid, int ops);
 
 #endif // __HYPER_DMABUF_REMOTE_SYNC_H__
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +14 -6
index 9952b3f..991a8d4 100644
@@ -51,7 +51,7 @@ struct vmap_vaddr_list {
 
 /* Exporter builds pages_info before sharing pages */
 struct hyper_dmabuf_pages_info {
-        int hyper_dmabuf_id; /* unique id to reference dmabuf in source domain */
+        hyper_dmabuf_id_t hid; /* unique id to reference dmabuf in source domain */
         int hyper_dmabuf_rdomain; /* currenting considering just one remote domain access it */
         int frst_ofst; /* offset of data in the first page */
         int last_len; /* length of data in the last page */
@@ -64,22 +64,27 @@ struct hyper_dmabuf_pages_info {
  * Exporter stores references to sgt in a hash table
  * Exporter keeps these references for synchronization and tracking purposes
  *
- * Importer use this structure exporting to other drivers in the same domain */
+ * Importer use this structure exporting to other drivers in the same domain
+ */
 struct hyper_dmabuf_sgt_info {
-        int hyper_dmabuf_id; /* unique id to reference dmabuf in remote domain */
+        hyper_dmabuf_id_t hid; /* unique id to reference dmabuf in remote domain */
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
 
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
 	int nents; /* number of pages, which may be different than sgt->nents */
+
+	/* list of remote activities on dma_buf */
 	struct sgt_list *active_sgts;
 	struct attachment_list *active_attached;
 	struct kmap_vaddr_list *va_kmapped;
 	struct vmap_vaddr_list *va_vmapped;
-	bool valid;
+
+	bool valid; /* set to 0 once unexported. Needed to prevent further mapping by importer */
 	int importer_exported; /* exported locally on importer's side */
 	void *refs_info; /* hypervisor-specific info for the references */
 	struct delayed_work unexport_work;
 	bool unexport_scheduled;
+
 	/* owner of buffer
 	 * TODO: that is naiive as buffer may be reused by
 	 * another userspace app, so here list of struct file should be kept
@@ -94,13 +99,16 @@ struct hyper_dmabuf_sgt_info {
  * Importer store these references in the table and map it in
  * its own memory map once userspace asks for reference for the buffer */
 struct hyper_dmabuf_imported_sgt_info {
-	int hyper_dmabuf_id; /* unique id to reference dmabuf (HYPER_DMABUF_ID_IMPORTER(source domain id, exporter's hyper_dmabuf_id */
+	hyper_dmabuf_id_t hid; /* unique id for shared dmabuf imported */
+
 	int ref_handle; /* reference number of top level addressing page of shared pages */
-	int frst_ofst;	/* start offset in shared page #1 */
+	int frst_ofst;	/* start offset in first shared page */
 	int last_len;	/* length of data in the last shared page */
 	int nents;	/* number of pages to be shared */
+
 	struct dma_buf *dma_buf;
 	struct sg_table *sgt; /* sgt pointer after importing buffer */
+
 	void *refs_info;
 	bool valid;
 	int num_importers;
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.h +0 -2
index 0533e4d..80741c1 100644
@@ -29,8 +29,6 @@
 #include "xen/xenbus.h"
 #include "../hyper_dmabuf_msg.h"
 
-#define MAX_NUMBER_OF_OPERANDS 9
-
 DEFINE_RING_TYPES(xen_comm, struct hyper_dmabuf_req, struct hyper_dmabuf_resp);
 
 struct xen_comm_tx_ring_info {
include/uapi/xen/hyper_dmabuf.h +9 -4
index 2eff3a8e..992a542 100644
@@ -25,6 +25,11 @@
 #ifndef __LINUX_PUBLIC_HYPER_DMABUF_H__
 #define __LINUX_PUBLIC_HYPER_DMABUF_H__
 
+typedef struct {
+        int id;
+        int rng_key[3]; /* 12bytes long random number */
+} hyper_dmabuf_id_t;
+
 #define IOCTL_HYPER_DMABUF_TX_CH_SETUP \
 _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_hyper_dmabuf_tx_ch_setup))
 struct ioctl_hyper_dmabuf_tx_ch_setup {
@@ -50,7 +55,7 @@ struct ioctl_hyper_dmabuf_export_remote {
 	/* Domain id to which buffer should be exported */
 	int remote_domain;
 	/* exported dma buf id */
-	int hyper_dmabuf_id;
+	hyper_dmabuf_id_t hid;
 	int private[4];
 };
 
@@ -59,7 +64,7 @@ _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_hyper_dmabuf_export_fd))
 struct ioctl_hyper_dmabuf_export_fd {
 	/* IN parameters */
 	/* hyper dmabuf id to be imported */
-	int hyper_dmabuf_id;
+	hyper_dmabuf_id_t hid;
 	/* flags */
 	int flags;
 	/* OUT parameters */
@@ -72,7 +77,7 @@ _IOC(_IOC_NONE, 'G', 4, sizeof(struct ioctl_hyper_dmabuf_unexport))
 struct ioctl_hyper_dmabuf_unexport {
 	/* IN parameters */
 	/* hyper dmabuf id to be unexported */
-	int hyper_dmabuf_id;
+	hyper_dmabuf_id_t hid;
 	/* delay in ms by which unexport processing will be postponed */
 	int delay_ms;
 	/* OUT parameters */
@@ -85,7 +90,7 @@ _IOC(_IOC_NONE, 'G', 5, sizeof(struct ioctl_hyper_dmabuf_query))
 struct ioctl_hyper_dmabuf_query {
 	/* in parameters */
 	/* hyper dmabuf id to be queried */
-	int hyper_dmabuf_id;
+	hyper_dmabuf_id_t hid;
 	/* item to be queried */
 	int item;
 	/* OUT parameters */
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#50 lore raw

RFC PATCH 36/60 hyper_dmabuf: error handling when share_pages fails

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

When error occurs while sharing pages, all pages already shared needs to be un-shared and proper error code has to be returned.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  6 ++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 50 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +5 -1
index f1581d5..375b664 100644
@@ -31,7 +31,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/miscdevice.h>
-#include <linux/uaccess.h>
+#include <asm/uaccess.h>
 #include <linux/dma-buf.h>
 #include <linux/delay.h>
 #include <linux/list.h>
@@ -242,6 +242,10 @@ static int hyper_dmabuf_export_remote(struct file *filp, void *data)
 	operands[6] = page_info->last_len;
 	operands[7] = ops->share_pages (page_info->pages, export_remote_attr->remote_domain,
 					page_info->nents, &sgt_info->refs_info);
+	if (operands[7] < 0) {
+		dev_err(hyper_dmabuf_private.device, "pages sharing failed\n");
+		goto fail_map_req;
+	}
 
 	/* driver/application specific private info, max 4x4 bytes */
 	operands[8] = export_remote_attr->private[0];
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +50 -0

74 lines not on this page · raw message

Signature · 1 line
2.7.4
#51 lore raw

RFC PATCH 36/60 hyper_dmabuf: error handling when share_pages fails

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

When error occurs while sharing pages, all pages already shared needs to be un-shared and proper error code has to be returned.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  6 ++-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c    | 50 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +5 -1
index f1581d5..375b664 100644
@@ -31,7 +31,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/miscdevice.h>
-#include <linux/uaccess.h>
+#include <asm/uaccess.h>
 #include <linux/dma-buf.h>
 #include <linux/delay.h>
 #include <linux/list.h>
@@ -242,6 +242,10 @@ static int hyper_dmabuf_export_remote(struct file *filp, void *data)
 	operands[6] = page_info->last_len;
 	operands[7] = ops->share_pages (page_info->pages, export_remote_attr->remote_domain,
 					page_info->nents, &sgt_info->refs_info);
+	if (operands[7] < 0) {
+		dev_err(hyper_dmabuf_private.device, "pages sharing failed\n");
+		goto fail_map_req;
+	}
 
 	/* driver/application specific private info, max 4x4 bytes */
 	operands[8] = export_remote_attr->private[0];
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_shm.c +50 -0

74 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#52 lore raw

RFC PATCH 37/60 hyper_dmabuf: implementation of query ioctl

In reply to Dongwon Kim

List of queries is re-defined. Now it supports following items:

	enum hyper_dmabuf_query {
		DMABUF_QUERY_TYPE = 0x10,
		DMABUF_QUERY_EXPORTER,
		DMABUF_QUERY_IMPORTER,
		DMABUF_QUERY_SIZE,
		DMABUF_QUERY_BUSY,
		DMABUF_QUERY_UNEXPORTED,
		DMABUF_QUERY_DELAYED_UNEXPORTED,
	};

Also, actual querying part of the function is moved to hyper_dmabuf_query.c

---
 drivers/xen/hyper_dmabuf/Makefile             |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 111 ++++++++++---------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c | 115 ++++++++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h |  38 +--------
 include/uapi/xen/hyper_dmabuf.h               |  17 ++++
 5 files changed, 179 insertions(+), 103 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c
drivers/xen/hyper_dmabuf/Makefile +1 -0
index d90cfc3..8865f50 100644
@@ -11,6 +11,7 @@ ifneq ($(KERNELRELEASE),)
 				 hyper_dmabuf_msg.o \
 				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
+				 hyper_dmabuf_query.o \
 
 ifeq ($(CONFIG_XEN), y)
 	$(TARGET_MODULE)-objs += xen/hyper_dmabuf_xen_comm.o \
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +43 -68

167 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c new file +115 -0

115 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h +3 -35
index 6cf5b2d..295e923 100644
@@ -1,40 +1,8 @@
-/*
- * Copyright © 2017 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- */
-
 #ifndef __HYPER_DMABUF_QUERY_H__
 #define __HYPER_DMABUF_QUERY_H__
 
-enum hyper_dmabuf_query {
-	DMABUF_QUERY_TYPE_LIST = 0x10,
-	DMABUF_QUERY_EXPORTER,
-	DMABUF_QUERY_IMPORTER,
-	DMABUF_QUERY_SIZE
-};
+int hyper_dmabuf_query_imported(struct hyper_dmabuf_imported_sgt_info *imported_sgt_info, int query);
 
-enum hyper_dmabuf_status {
-	EXPORTED = 0x01,
-	IMPORTED
-};
+int hyper_dmabuf_query_exported(struct hyper_dmabuf_sgt_info *sgt_info, int query);
 
-#endif /* __HYPER_DMABUF_QUERY_H__ */
+#endif // __HYPER_DMABUF_QUERY_H__
include/uapi/xen/hyper_dmabuf.h +17 -0
index 992a542..bee0f86 100644
@@ -98,4 +98,21 @@ struct ioctl_hyper_dmabuf_query {
 	int info;
 };
 
+/* DMABUF query */
+
+enum hyper_dmabuf_query {
+        HYPER_DMABUF_QUERY_TYPE = 0x10,
+        HYPER_DMABUF_QUERY_EXPORTER,
+        HYPER_DMABUF_QUERY_IMPORTER,
+        HYPER_DMABUF_QUERY_SIZE,
+        HYPER_DMABUF_QUERY_BUSY,
+        HYPER_DMABUF_QUERY_UNEXPORTED,
+        HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED,
+};
+
+enum hyper_dmabuf_status {
+        EXPORTED= 0x01,
+        IMPORTED,
+};
+
 #endif //__LINUX_PUBLIC_HYPER_DMABUF_H__
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#53 lore raw

RFC PATCH 37/60 hyper_dmabuf: implementation of query ioctl

In reply to Dongwon Kim

List of queries is re-defined. Now it supports following items:

	enum hyper_dmabuf_query {
		DMABUF_QUERY_TYPE = 0x10,
		DMABUF_QUERY_EXPORTER,
		DMABUF_QUERY_IMPORTER,
		DMABUF_QUERY_SIZE,
		DMABUF_QUERY_BUSY,
		DMABUF_QUERY_UNEXPORTED,
		DMABUF_QUERY_DELAYED_UNEXPORTED,
	};

Also, actual querying part of the function is moved to hyper_dmabuf_query.c

---
 drivers/xen/hyper_dmabuf/Makefile             |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 111 ++++++++++---------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c | 115 ++++++++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h |  38 +--------
 include/uapi/xen/hyper_dmabuf.h               |  17 ++++
 5 files changed, 179 insertions(+), 103 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c
drivers/xen/hyper_dmabuf/Makefile +1 -0
index d90cfc3..8865f50 100644
@@ -11,6 +11,7 @@ ifneq ($(KERNELRELEASE),)
 				 hyper_dmabuf_msg.o \
 				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
+				 hyper_dmabuf_query.o \
 
 ifeq ($(CONFIG_XEN), y)
 	$(TARGET_MODULE)-objs += xen/hyper_dmabuf_xen_comm.o \
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +43 -68

167 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c new file +115 -0

115 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h +3 -35
index 6cf5b2d..295e923 100644
@@ -1,40 +1,8 @@
-/*
- * Copyright © 2017 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- */
-
 #ifndef __HYPER_DMABUF_QUERY_H__
 #define __HYPER_DMABUF_QUERY_H__
 
-enum hyper_dmabuf_query {
-	DMABUF_QUERY_TYPE_LIST = 0x10,
-	DMABUF_QUERY_EXPORTER,
-	DMABUF_QUERY_IMPORTER,
-	DMABUF_QUERY_SIZE
-};
+int hyper_dmabuf_query_imported(struct hyper_dmabuf_imported_sgt_info *imported_sgt_info, int query);
 
-enum hyper_dmabuf_status {
-	EXPORTED = 0x01,
-	IMPORTED
-};
+int hyper_dmabuf_query_exported(struct hyper_dmabuf_sgt_info *sgt_info, int query);
 
-#endif /* __HYPER_DMABUF_QUERY_H__ */
+#endif // __HYPER_DMABUF_QUERY_H__
include/uapi/xen/hyper_dmabuf.h +17 -0
index 992a542..bee0f86 100644
@@ -98,4 +98,21 @@ struct ioctl_hyper_dmabuf_query {
 	int info;
 };
 
+/* DMABUF query */
+
+enum hyper_dmabuf_query {
+        HYPER_DMABUF_QUERY_TYPE = 0x10,
+        HYPER_DMABUF_QUERY_EXPORTER,
+        HYPER_DMABUF_QUERY_IMPORTER,
+        HYPER_DMABUF_QUERY_SIZE,
+        HYPER_DMABUF_QUERY_BUSY,
+        HYPER_DMABUF_QUERY_UNEXPORTED,
+        HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED,
+};
+
+enum hyper_dmabuf_status {
+        EXPORTED= 0x01,
+        IMPORTED,
+};
+
 #endif //__LINUX_PUBLIC_HYPER_DMABUF_H__
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#54 lore raw

RFC PATCH 38/60 hyper_dmabuf: preventing self exporting of dma_buf

In reply to Dongwon Kim

Adding ID check to make sure a dma-buf is exported externally since hyper_dmabuf only allows to export a dmabuf to a different VM.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +6 -0
index 12f7ce4..b77b156 100644
@@ -103,6 +103,12 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 
 	export_remote_attr = (struct ioctl_hyper_dmabuf_export_remote *)data;
 
+	if (hyper_dmabuf_private.domid == export_remote_attr->remote_domain) {
+		dev_err(hyper_dmabuf_private.device,
+			"exporting to the same VM is not permitted\n");
+		return -EINVAL;
+	}
+
 	dma_buf = dma_buf_get(export_remote_attr->dmabuf_fd);
 
 	if (IS_ERR(dma_buf)) {
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#55 lore raw

RFC PATCH 38/60 hyper_dmabuf: preventing self exporting of dma_buf

In reply to Dongwon Kim

Adding ID check to make sure a dma-buf is exported externally since hyper_dmabuf only allows to export a dmabuf to a different VM.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +6 -0
index 12f7ce4..b77b156 100644
@@ -103,6 +103,12 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 
 	export_remote_attr = (struct ioctl_hyper_dmabuf_export_remote *)data;
 
+	if (hyper_dmabuf_private.domid == export_remote_attr->remote_domain) {
+		dev_err(hyper_dmabuf_private.device,
+			"exporting to the same VM is not permitted\n");
+		return -EINVAL;
+	}
+
 	dma_buf = dma_buf_get(export_remote_attr->dmabuf_fd);
 
 	if (IS_ERR(dma_buf)) {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#56 lore raw

RFC PATCH 39/60 hyper_dmabuf: correcting DMA-BUF clean-up order

In reply to Dongwon Kim

Reordering clean-up procedure

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 37 +++++++++++++++++----------
 1 file changed, 24 insertions(+), 13 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +24 -13
index b77b156..2ff2c145 100644
@@ -148,21 +148,24 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	attachment = dma_buf_attach(dma_buf, hyper_dmabuf_private.device);
 	if (IS_ERR(attachment)) {
 		dev_err(hyper_dmabuf_private.device, "Cannot get attachment\n");
-		return PTR_ERR(attachment);
+		ret = PTR_ERR(attachment);
+		goto fail_attach;
 	}
 
 	sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL);
 
 	if (IS_ERR(sgt)) {
 		dev_err(hyper_dmabuf_private.device, "Cannot map attachment\n");
-		return PTR_ERR(sgt);
+		ret = PTR_ERR(sgt);
+		goto fail_map_attachment;
 	}
 
 	sgt_info = kcalloc(1, sizeof(*sgt_info), GFP_KERNEL);
 
 	if(!sgt_info) {
 		dev_err(hyper_dmabuf_private.device, "no more space left\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto fail_sgt_info_creation;
 	}
 
 	sgt_info->hid = hyper_dmabuf_get_hid();
@@ -171,8 +174,8 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	if(sgt_info->hid.id == -1) {
 		dev_err(hyper_dmabuf_private.device,
 			"exceeds allowed number of dmabuf to be exported\n");
-		/* TODO: Cleanup sgt */
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto fail_sgt_info_creation;
 	}
 
 	/* TODO: We might need to consider using port number on event channel? */
@@ -286,6 +289,8 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 
 	return ret;
 
+/* Clean-up if error occurs */
+
 fail_send_request:
 	kfree(req);
 
@@ -293,20 +298,26 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	hyper_dmabuf_remove_exported(sgt_info->hid);
 
 fail_export:
-	dma_buf_unmap_attachment(sgt_info->active_attached->attach,
-				 sgt_info->active_sgts->sgt,
-				 DMA_BIDIRECTIONAL);
-	dma_buf_detach(sgt_info->dma_buf, sgt_info->active_attached->attach);
-	dma_buf_put(sgt_info->dma_buf);
-
 	kfree(sgt_info->va_vmapped);
+
 fail_map_va_vmapped:
 	kfree(sgt_info->va_kmapped);
+
 fail_map_va_kmapped:
-	kfree(sgt_info->active_sgts);
-fail_map_active_sgts:
 	kfree(sgt_info->active_attached);
+
 fail_map_active_attached:
+	kfree(sgt_info->active_sgts);
+
+fail_map_active_sgts:
+fail_sgt_info_creation:
+	dma_buf_unmap_attachment(attachment, sgt, DMA_BIDIRECTIONAL);
+
+fail_map_attachment:
+	dma_buf_detach(dma_buf, attachment);
+
+fail_attach:
+	dma_buf_put(dma_buf);
 
 	return ret;
 }
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#57 lore raw

RFC PATCH 40/60 hyper_dmabuf: do not use 'private' as field name

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Using a word, 'private' is not recommended because of conflict with language keyword when compiling with C++.
So changing those to 'priv'.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 8 ++++----
 include/uapi/xen/hyper_dmabuf.h               | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +4 -4
index 2ff2c145..9d05d66 100644
@@ -257,10 +257,10 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	}
 
 	/* driver/application specific private info, max 4x4 bytes */
-	operands[8] = export_remote_attr->private[0];
-	operands[9] = export_remote_attr->private[1];
-	operands[10] = export_remote_attr->private[2];
-	operands[11] = export_remote_attr->private[3];
+	operands[8] = export_remote_attr->priv[0];
+	operands[9] = export_remote_attr->priv[1];
+	operands[10] = export_remote_attr->priv[2];
+	operands[11] = export_remote_attr->priv[3];
 
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
 
include/uapi/xen/hyper_dmabuf.h +1 -1
index bee0f86..a2d22d0 100644
@@ -56,7 +56,7 @@ struct ioctl_hyper_dmabuf_export_remote {
 	int remote_domain;
 	/* exported dma buf id */
 	hyper_dmabuf_id_t hid;
-	int private[4];
+	int priv[4];
 };
 
 #define IOCTL_HYPER_DMABUF_EXPORT_FD \
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#58 lore raw

RFC PATCH 41/60 hyper_dmabuf: re-organize driver source

In reply to Dongwon Kim

Re-orginized source code for more intuitive structure

For this,

1. driver's file operations other than ioctls have been moved to hyper_dmabuf_drv.c.

2. Separated out dma-buf operations from hyper_dmabuf_ops.c and put those in a new file, 'hyper_dmabuf_ops.c'. Remaining part (SGT core management) is also put in the a new file, 'hyper_dmabuf_sgt_proc.c'. hyper_dmabuf_imp.c and hyper_dmabuf_imp.h are removed as a result.

3. Header files and Makefile are also updated accordingly.

---
 drivers/xen/hyper_dmabuf/Makefile                  |   3 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        |  95 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c        | 682 ---------------------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h        |  48 --
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 136 +---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |   1 -
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.c        | 471 ++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.h        |  32 +
 .../xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c    |   2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.c   | 258 ++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.h   |  41 ++
 11 files changed, 920 insertions(+), 849 deletions(-)
 delete mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c
 delete mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.h
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.h
drivers/xen/hyper_dmabuf/Makefile +2 -1
index 8865f50..5040b9f 100644
@@ -7,7 +7,8 @@ ifneq ($(KERNELRELEASE),)
 	$(TARGET_MODULE)-objs := hyper_dmabuf_drv.o \
                                  hyper_dmabuf_ioctl.o \
                                  hyper_dmabuf_list.o \
-				 hyper_dmabuf_imp.o \
+				 hyper_dmabuf_sgl_proc.o \
+				 hyper_dmabuf_ops.o \
 				 hyper_dmabuf_msg.o \
 				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +89 -6

125 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.c deleted +0 -682

682 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_imp.h deleted +0 -48

48 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +26 -110

157 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +0 -1
index 12ebad3..c516df8 100644
@@ -35,7 +35,6 @@
 #include <linux/workqueue.h>
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_drv.h"
-#include "hyper_dmabuf_imp.h"
 #include "hyper_dmabuf_remote_sync.h"
 #include "hyper_dmabuf_list.h"
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.c new file +471 -0

471 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.h new file +32 -0
new file mode 100644
index 0000000..8c06fc6
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __HYPER_DMABUF_OPS_H__
+#define __HYPER_DMABUF_OPS_H__
+
+int hyper_dmabuf_export_fd(struct hyper_dmabuf_imported_sgt_info *dinfo, int flags);
+
+void hyper_dmabuf_export_dma_buf(struct hyper_dmabuf_imported_sgt_info *dinfo);
+
+#endif /* __HYPER_DMABUF_IMP_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_remote_sync.c +1 -1
index be1d395..9004406 100644
@@ -37,7 +37,7 @@
 #include "hyper_dmabuf_msg.h"
 #include "hyper_dmabuf_id.h"
 #include "hyper_dmabuf_msg.h"
-#include "hyper_dmabuf_imp.h"
+#include "hyper_dmabuf_sgl_proc.h"
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.c new file +258 -0

258 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.h new file +41 -0

41 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#59 lore raw

RFC PATCH 42/60 hyper_dmabuf: always generate a new random keys

In reply to Dongwon Kim

From: Mateusz Polrola <[email protected]>

Need to update random keys when reusing hyper_dmabuf_id in the list to increase security

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_id.c +3 -2
index f59dee3..cccdc19 100644
@@ -120,10 +120,11 @@ hyper_dmabuf_id_t hyper_dmabuf_get_hid(void)
 	 */
 	if (hid.id == -1 && count < HYPER_DMABUF_ID_MAX) {
 		hid.id = HYPER_DMABUF_ID_CREATE(hyper_dmabuf_private.domid, count++);
-		/* random data embedded in the id for security */
-		get_random_bytes(&hid.rng_key[0], 12);
 	}
 
+	/* random data embedded in the id for security */
+	get_random_bytes(&hid.rng_key[0], 12);
+
 	return hid;
 }
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#60 lore raw

RFC PATCH 43/60 hyper_dmabuf: fixes on memory leaks in various places

In reply to Dongwon Kim

Make sure to free buffers before returning to prevent memory leaks

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      | 19 +++++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  9 +++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.c        |  6 ++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.c   |  4 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   | 52 +++++++++++++++++++---
 5 files changed, 78 insertions(+), 12 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +17 -2
index 283fe5a..3215003 100644
@@ -282,6 +282,7 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 
 	/* free msg */
 	kfree(req);
+
 	/* free page_info */
 	kfree(page_info->pages);
 	kfree(page_info);
@@ -298,6 +299,10 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 fail_map_req:
 	hyper_dmabuf_remove_exported(sgt_info->hid);
 
+	/* free page_info */
+	kfree(page_info->pages);
+	kfree(page_info);
+
 fail_export:
 	kfree(sgt_info->va_vmapped);
 
@@ -433,6 +438,13 @@ static int hyper_dmabuf_export_fd_ioctl(struct file *filp, void *data)
 
 			sgt_info->num_importers--;
 			req = kcalloc(1, sizeof(*req), GFP_KERNEL);
+
+			if (!req) {
+				dev_err(hyper_dmabuf_private.device,
+					"No more space left\n");
+				return -ENOMEM;
+			}
+
 			hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT_FD_FAILED, &operands[0]);
 			ops->send_req(HYPER_DMABUF_DOM_ID(sgt_info->hid), req, false);
 			kfree(req);
@@ -681,16 +693,19 @@ long hyper_dmabuf_ioctl(struct file *filp,
 
 	if (copy_from_user(kdata, (void __user *)param, _IOC_SIZE(cmd)) != 0) {
 		dev_err(hyper_dmabuf_private.device, "failed to copy from user arguments\n");
-		return -EFAULT;
+		ret = -EFAULT;
+		goto ioctl_error;
 	}
 
 	ret = func(filp, kdata);
 
 	if (copy_to_user((void __user *)param, kdata, _IOC_SIZE(cmd)) != 0) {
 		dev_err(hyper_dmabuf_private.device, "failed to copy to user arguments\n");
-		return -EFAULT;
+		ret = -EFAULT;
+		goto ioctl_error;
 	}
 
+ioctl_error:
 	kfree(kdata);
 
 	return ret;
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +7 -2
index c516df8..46cf9a4 100644
@@ -191,8 +191,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	struct hyper_dmabuf_req *temp_req;
 	struct hyper_dmabuf_imported_sgt_info *sgt_info;
 	struct hyper_dmabuf_sgt_info *exp_sgt_info;
-	hyper_dmabuf_id_t hid = {req->operands[0], /* hid.id */
-			       {req->operands[1], req->operands[2], req->operands[3]}}; /* hid.rng_key */
+	hyper_dmabuf_id_t hid;
 	int ret;
 
 	if (!req) {
@@ -200,6 +199,11 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 		return -EINVAL;
 	}
 
+	hid.id = req->operands[0];
+	hid.rng_key[0] = req->operands[1];
+	hid.rng_key[1] = req->operands[2];
+	hid.rng_key[2] = req->operands[3];
+
 	if ((req->command < HYPER_DMABUF_EXPORT) ||
 		(req->command > HYPER_DMABUF_OPS_TO_SOURCE)) {
 		dev_err(hyper_dmabuf_private.device, "invalid command\n");
@@ -332,6 +336,7 @@ int hyper_dmabuf_msg_parse(int domid, struct hyper_dmabuf_req *req)
 	if (!proc) {
 		dev_err(hyper_dmabuf_private.device,
 			"No memory left to be allocated\n");
+		kfree(temp_req);
 		return -ENOMEM;
 	}
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_ops.c +4 -2
index 81cb09f..9313c42 100644
@@ -148,9 +148,8 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 	if (!st)
 		goto err_free_sg;
 
-        if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
+        if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir))
                 goto err_free_sg;
-        }
 
 	ret = hyper_dmabuf_sync_request(sgt_info->hid,
 					HYPER_DMABUF_OPS_MAP);
@@ -171,6 +170,9 @@ static struct sg_table* hyper_dmabuf_ops_map(struct dma_buf_attachment *attachme
 		kfree(st);
 	}
 
+	kfree(page_info->pages);
+	kfree(page_info);
+
 	return NULL;
 }
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_sgl_proc.c +3 -1
index c2d013a..dd17d26 100644
@@ -89,8 +89,10 @@ struct hyper_dmabuf_pages_info *hyper_dmabuf_ext_pgs(struct sg_table *sgt)
 		return NULL;
 
 	pinfo->pages = kmalloc(sizeof(struct page *)*hyper_dmabuf_get_num_pgs(sgt), GFP_KERNEL);
-	if (!pinfo->pages)
+	if (!pinfo->pages) {
+		kfree(pinfo);
 		return NULL;
+	}
 
 	sgl = sgt->sgl;
 
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +47 -5

128 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#61 lore raw

RFC PATCH 44/60 hyper_dmabuf: proper handling of sgt_info->priv

In reply to Dongwon Kim

sgt_info->priv will be used to store user private info passed in ioctl. Data in sgt_info->priv is transfered via comm channel to the importer VM whenever DMA_BUF is exported to keep the private data synchroized across VMs.

This patch also adds hyper_dmabuf_send_export_msg that replaces some of export_remote_ioctl to make it more readable and compact.

---
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c  | 110 ++++++++++++++-----------
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h |   6 +-
 2 files changed, 65 insertions(+), 51 deletions(-)
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +63 -47
index 3215003..dfdb889 100644
@@ -82,17 +82,64 @@ static int hyper_dmabuf_rx_ch_setup_ioctl(struct file *filp, void *data)
 	return ret;
 }
 
+static int hyper_dmabuf_send_export_msg(struct hyper_dmabuf_sgt_info *sgt_info,
+					struct hyper_dmabuf_pages_info *page_info)
+{
+	struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
+	struct hyper_dmabuf_req *req;
+	int operands[12] = {0};
+	int ret, i;
+
+	/* now create request for importer via ring */
+	operands[0] = sgt_info->hid.id;
+
+	for (i=0; i<3; i++)
+		operands[i+1] = sgt_info->hid.rng_key[i];
+
+	if (page_info) {
+		operands[4] = page_info->nents;
+		operands[5] = page_info->frst_ofst;
+		operands[6] = page_info->last_len;
+		operands[7] = ops->share_pages (page_info->pages, sgt_info->hyper_dmabuf_rdomain,
+						page_info->nents, &sgt_info->refs_info);
+		if (operands[7] < 0) {
+			dev_err(hyper_dmabuf_private.device, "pages sharing failed\n");
+			return -1;
+		}
+	}
+
+	/* driver/application specific private info, max 4x4 bytes */
+	memcpy(&operands[8], &sgt_info->priv[0], sizeof(unsigned int) * 4);
+
+	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
+
+	if(!req) {
+		dev_err(hyper_dmabuf_private.device, "no more space left\n");
+		return -1;
+	}
+
+	/* composing a message to the importer */
+	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT, &operands[0]);
+
+	ret = ops->send_req(sgt_info->hyper_dmabuf_rdomain, req, false);
+
+	if(ret) {
+		dev_err(hyper_dmabuf_private.device, "error while communicating\n");
+	}
+
+	kfree(req);
+
+	return ret;
+}
+
 static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 {
 	struct ioctl_hyper_dmabuf_export_remote *export_remote_attr;
-	struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
 	struct dma_buf *dma_buf;
 	struct dma_buf_attachment *attachment;
 	struct sg_table *sgt;
 	struct hyper_dmabuf_pages_info *page_info;
 	struct hyper_dmabuf_sgt_info *sgt_info;
-	struct hyper_dmabuf_req *req;
-	int operands[MAX_NUMBER_OF_OPERANDS];
 	hyper_dmabuf_id_t hid;
 	int i;
 	int ret = 0;
@@ -138,6 +185,13 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 					}
 					sgt_info->unexport_scheduled = 0;
 				}
+
+				/* update private data in sgt_info with new ones */
+				memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 4);
+
+				/* TODO: need to send this private info to the importer so that those
+				 * on importer's side are also updated */
+
 				dma_buf_put(dma_buf);
 				export_remote_attr->hid = hid;
 				return 0;
@@ -225,6 +279,9 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	INIT_LIST_HEAD(&sgt_info->va_kmapped->list);
 	INIT_LIST_HEAD(&sgt_info->va_vmapped->list);
 
+	/* copy private data to sgt_info */
+	memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 4);
+
 	page_info = hyper_dmabuf_ext_pgs(sgt);
 	if (!page_info) {
 		dev_err(hyper_dmabuf_private.device, "failed to construct page_info\n");
@@ -236,53 +293,15 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	/* now register it to export list */
 	hyper_dmabuf_register_exported(sgt_info);
 
-	page_info->hyper_dmabuf_rdomain = sgt_info->hyper_dmabuf_rdomain;
-	page_info->hid = sgt_info->hid; /* may not be needed */
-
 	export_remote_attr->hid = sgt_info->hid;
 
-	/* now create request for importer via ring */
-	operands[0] = page_info->hid.id;
-
-	for (i=0; i<3; i++)
-		operands[i+1] = page_info->hid.rng_key[i];
-
-	operands[4] = page_info->nents;
-	operands[5] = page_info->frst_ofst;
-	operands[6] = page_info->last_len;
-	operands[7] = ops->share_pages (page_info->pages, export_remote_attr->remote_domain,
-					page_info->nents, &sgt_info->refs_info);
-	if (operands[7] < 0) {
-		dev_err(hyper_dmabuf_private.device, "pages sharing failed\n");
-		goto fail_map_req;
-	}
-
-	/* driver/application specific private info, max 4x4 bytes */
-	operands[8] = export_remote_attr->priv[0];
-	operands[9] = export_remote_attr->priv[1];
-	operands[10] = export_remote_attr->priv[2];
-	operands[11] = export_remote_attr->priv[3];
-
-	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
+	ret = hyper_dmabuf_send_export_msg(sgt_info, page_info);
 
-	if(!req) {
-		dev_err(hyper_dmabuf_private.device, "no more space left\n");
-		goto fail_map_req;
-	}
-
-	/* composing a message to the importer */
-	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT, &operands[0]);
-
-	ret = ops->send_req(export_remote_attr->remote_domain, req, false);
-
-	if(ret) {
-		dev_err(hyper_dmabuf_private.device, "error while communicating\n");
+	if (ret < 0) {
+		dev_err(hyper_dmabuf_private.device, "failed to send out the export request\n");
 		goto fail_send_request;
 	}
 
-	/* free msg */
-	kfree(req);
-
 	/* free page_info */
 	kfree(page_info->pages);
 	kfree(page_info);
@@ -294,9 +313,6 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 /* Clean-up if error occurs */
 
 fail_send_request:
-	kfree(req);
-
-fail_map_req:
 	hyper_dmabuf_remove_exported(sgt_info->hid);
 
 	/* free page_info */
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +2 -4
index 991a8d4..a1d3ec6 100644
@@ -51,8 +51,6 @@ struct vmap_vaddr_list {
 
 /* Exporter builds pages_info before sharing pages */
 struct hyper_dmabuf_pages_info {
-        hyper_dmabuf_id_t hid; /* unique id to reference dmabuf in source domain */
-        int hyper_dmabuf_rdomain; /* currenting considering just one remote domain access it */
         int frst_ofst; /* offset of data in the first page */
         int last_len; /* length of data in the last page */
         int nents; /* # of pages */
@@ -71,7 +69,7 @@ struct hyper_dmabuf_sgt_info {
 	int hyper_dmabuf_rdomain; /* domain importing this sgt */
 
 	struct dma_buf *dma_buf; /* needed to store this for freeing it later */
-	int nents; /* number of pages, which may be different than sgt->nents */
+	int nents;
 
 	/* list of remote activities on dma_buf */
 	struct sgt_list *active_sgts;
@@ -92,7 +90,7 @@ struct hyper_dmabuf_sgt_info {
 	 * uses releases hyper_dmabuf device
 	 */
 	struct file *filp;
-	int private[4]; /* device specific info (e.g. image's meta info?) */
+	int priv[4]; /* device specific info (e.g. image's meta info?) */
 };
 
 /* Importer store references (before mapping) on shared pages
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#62 lore raw

RFC PATCH 45/60 hyper_dmabuf: adding poll/read for event generation

In reply to Dongwon Kim

hyper_dmabuf driver on importing domain now generates event every time new hyper_dmabuf is available (visible) to the importer.

Each event comes with 128 byte private data, which can contain any meta data or user data specific to the originator of DMA BUF.

---
 drivers/xen/hyper_dmabuf/Kconfig                   |  10 ++
 drivers/xen/hyper_dmabuf/Makefile                  |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c        | 120 +++++++++++++++++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h        |  48 ++++++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_event.c      | 125 +++++++++++++++++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_event.h      |  38 +++++++
 drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c      |  23 ++--
 drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c       |   1 +
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c        |  44 +++++++-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h        |   2 +-
 drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h     |   4 +-
 .../xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c   |  37 +++++-
 include/uapi/xen/hyper_dmabuf.h                    |  13 ++-
 13 files changed, 430 insertions(+), 36 deletions(-)
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_event.c
 create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_event.h
drivers/xen/hyper_dmabuf/Kconfig +10 -0
index 185fdf8..eb1b637 100644
@@ -19,4 +19,14 @@ config HYPER_DMABUF_SYSFS
 	  Expose information about imported and exported buffers using
 	  hyper_dmabuf driver
 
+config HYPER_DMABUF_EVENT_GEN
+	bool "Enable event-generation and polling operation"
+	default n
+	depends on HYPER_DMABUF
+	help
+	  With this config enabled, hyper_dmabuf driver on the importer side
+	  generates events and queue those up in the event list whenever a new
+	  shared DMA-BUF is available. Events in the list can be retrieved by
+	  read operation.
+
 endmenu
drivers/xen/hyper_dmabuf/Makefile +1 -0
index 5040b9f..1cd7a81 100644
@@ -13,6 +13,7 @@ ifneq ($(KERNELRELEASE),)
 				 hyper_dmabuf_id.o \
 				 hyper_dmabuf_remote_sync.o \
 				 hyper_dmabuf_query.o \
+				 hyper_dmabuf_event.o \
 
 ifeq ($(CONFIG_XEN), y)
 	$(TARGET_MODULE)-objs += xen/hyper_dmabuf_xen_comm.o \
drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +119 -1

157 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.h +36 -12

58 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_event.c new file +125 -0

125 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_event.h new file +38 -0
new file mode 100644
index 0000000..44c4856
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __HYPER_DMABUF_EVENT_H__
+#define __HYPER_DMABUF_EVENT_H__
+
+#define MAX_NUMBER_OF_EVENT 1024
+
+enum hyper_dmabuf_event_type {
+	HYPER_DMABUF_NEW_IMPORT = 0x10000,
+};
+
+void hyper_dmabuf_events_release(void);
+
+int hyper_dmabuf_import_event(hyper_dmabuf_id_t hid);
+
+#endif /* __HYPER_DMABUF_EVENT_H__ */
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c +11 -12
index dfdb889..85b70db 100644
@@ -87,7 +87,7 @@ static int hyper_dmabuf_send_export_msg(struct hyper_dmabuf_sgt_info *sgt_info,
 {
 	struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
 	struct hyper_dmabuf_req *req;
-	int operands[12] = {0};
+	int operands[40] = {0};
 	int ret, i;
 
 	/* now create request for importer via ring */
@@ -109,7 +109,7 @@ static int hyper_dmabuf_send_export_msg(struct hyper_dmabuf_sgt_info *sgt_info,
 	}
 
 	/* driver/application specific private info, max 4x4 bytes */
-	memcpy(&operands[8], &sgt_info->priv[0], sizeof(unsigned int) * 4);
+	memcpy(&operands[8], &sgt_info->priv[0], sizeof(unsigned int) * 32);
 
 	req = kcalloc(1, sizeof(*req), GFP_KERNEL);
 
@@ -121,11 +121,7 @@ static int hyper_dmabuf_send_export_msg(struct hyper_dmabuf_sgt_info *sgt_info,
 	/* composing a message to the importer */
 	hyper_dmabuf_create_request(req, HYPER_DMABUF_EXPORT, &operands[0]);
 
-	ret = ops->send_req(sgt_info->hyper_dmabuf_rdomain, req, false);
-
-	if(ret) {
-		dev_err(hyper_dmabuf_private.device, "error while communicating\n");
-	}
+	ret = ops->send_req(sgt_info->hyper_dmabuf_rdomain, req, true);
 
 	kfree(req);
 
@@ -141,7 +137,6 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	struct hyper_dmabuf_pages_info *page_info;
 	struct hyper_dmabuf_sgt_info *sgt_info;
 	hyper_dmabuf_id_t hid;
-	int i;
 	int ret = 0;
 
 	if (!data) {
@@ -187,10 +182,14 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 				}
 
 				/* update private data in sgt_info with new ones */
-				memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 4);
+				memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 32);
+
+				/* send an export msg for updating priv in importer */
+				ret = hyper_dmabuf_send_export_msg(sgt_info, NULL);
 
-				/* TODO: need to send this private info to the importer so that those
-				 * on importer's side are also updated */
+				if (ret < 0) {
+					dev_err(hyper_dmabuf_private.device, "Failed to send a new private data\n");
+				}
 
 				dma_buf_put(dma_buf);
 				export_remote_attr->hid = hid;
@@ -280,7 +279,7 @@ static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
 	INIT_LIST_HEAD(&sgt_info->va_vmapped->list);
 
 	/* copy private data to sgt_info */
-	memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 4);
+	memcpy(&sgt_info->priv[0], &export_remote_attr->priv[0], sizeof(unsigned int) * 32);
 
 	page_info = hyper_dmabuf_ext_pgs(sgt);
 	if (!page_info) {
drivers/xen/hyper_dmabuf/hyper_dmabuf_list.c +1 -0
index 21fc7d0..eaef2c1 100644
@@ -37,6 +37,7 @@
 #include "hyper_dmabuf_drv.h"
 #include "hyper_dmabuf_list.h"
 #include "hyper_dmabuf_id.h"
+#include "hyper_dmabuf_event.h"
 
 extern struct hyper_dmabuf_private hyper_dmabuf_private;
 
drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.c +38 -6

72 lines not on this page · raw message

drivers/xen/hyper_dmabuf/hyper_dmabuf_msg.h +1 -1
index 636d6f1..7464273 100644
@@ -25,7 +25,7 @@
 #ifndef __HYPER_DMABUF_MSG_H__
 #define __HYPER_DMABUF_MSG_H__
 
-#define MAX_NUMBER_OF_OPERANDS 13
+#define MAX_NUMBER_OF_OPERANDS 40
 
 struct hyper_dmabuf_req {
 	unsigned int request_id;
drivers/xen/hyper_dmabuf/hyper_dmabuf_struct.h +2 -2
index a1d3ec6..f01f535 100644
@@ -90,7 +90,7 @@ struct hyper_dmabuf_sgt_info {
 	 * uses releases hyper_dmabuf device
 	 */
 	struct file *filp;
-	int priv[4]; /* device specific info (e.g. image's meta info?) */
+	int priv[32]; /* device specific info (e.g. image's meta info?) */
 };
 
 /* Importer store references (before mapping) on shared pages
@@ -110,7 +110,7 @@ struct hyper_dmabuf_imported_sgt_info {
 	void *refs_info;
 	bool valid;
 	int num_importers;
-	int private[4]; /* device specific info (e.g. image's meta info?) */
+	int priv[32]; /* device specific info (e.g. image's meta info?) */
 };
 
 #endif /* __HYPER_DMABUF_STRUCT_H__ */
drivers/xen/hyper_dmabuf/xen/hyper_dmabuf_xen_comm.c +36 -1
index 9689346..370a07d 100644
@@ -32,6 +32,7 @@
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 #include <linux/delay.h>
+#include <linux/time.h>
 #include <xen/grant_table.h>
 #include <xen/events.h>
 #include <xen/xenbus.h>
@@ -474,6 +475,8 @@ int hyper_dmabuf_xen_init_rx_rbuf(int domid)
 			  back_ring_isr, 0,
 			  NULL, (void*)ring_info);
 
+	return ret;
+
 fail_others:
 	kfree(map_ops);
 
@@ -545,6 +548,10 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 	struct hyper_dmabuf_req *new_req;
 	struct xen_comm_tx_ring_info *ring_info;
 	int notify;
+
+	struct timeval tv_start, tv_end;
+	struct timeval tv_diff;
+
 	int timeout = 1000;
 
 	/* find a ring info for the channel */
@@ -559,7 +566,11 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 
 	ring = &ring_info->ring_front;
 
+	do_gettimeofday(&tv_start);
+
 	while (RING_FULL(ring)) {
+		dev_dbg(hyper_dmabuf_private.device, "RING_FULL\n");
+
 		if (timeout == 0) {
 			dev_err(hyper_dmabuf_private.device,
 				"Timeout while waiting for an entry in the ring\n");
@@ -609,6 +620,21 @@ int hyper_dmabuf_xen_send_req(int domid, struct hyper_dmabuf_req *req, int wait)
 		}
 
 		mutex_unlock(&ring_info->lock);
+		do_gettimeofday(&tv_end);
+
+		/* checking time duration for round-trip of a request for debugging */
+		if (tv_end.tv_usec >= tv_start.tv_usec) {
+			tv_diff.tv_sec = tv_end.tv_sec-tv_start.tv_sec;
+			tv_diff.tv_usec = tv_end.tv_usec-tv_start.tv_usec;
+		} else {
+			tv_diff.tv_sec = tv_end.tv_sec-tv_start.tv_sec-1;
+			tv_diff.tv_usec = tv_end.tv_usec+1000000-tv_start.tv_usec;
+		}
+
+		if (tv_diff.tv_sec != 0 && tv_diff.tv_usec > 16000)
+			dev_dbg(hyper_dmabuf_private.device, "send_req:time diff: %ld sec, %ld usec\n",
+				tv_diff.tv_sec, tv_diff.tv_usec);
+
 		return req_pending.status;
 	}
 
@@ -657,6 +683,10 @@ static irqreturn_t back_ring_isr(int irq, void *info)
 							sizeof(resp));
 				ring->rsp_prod_pvt++;
 
+				dev_dbg(hyper_dmabuf_private.device,
+					"sending response to exporter for request id:%d\n",
+					resp.response_id);
+
 				RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(ring, notify);
 
 				if (notify) {
@@ -696,8 +726,13 @@ static irqreturn_t front_ring_isr(int irq, void *info)
 			/* update pending request's status with what is
 			 * in the response
 			 */
-			if (req_pending.request_id == resp->response_id)
+
+			dev_dbg(hyper_dmabuf_private.device,
+				"getting response from importer\n");
+
+			if (req_pending.request_id == resp->response_id) {
 				req_pending.status = resp->status;
+			}
 
 			if (resp->status == HYPER_DMABUF_REQ_NEEDS_FOLLOW_UP) {
 				/* parsing response */
include/uapi/xen/hyper_dmabuf.h +12 -1
index a2d22d0..3a6172e 100644
@@ -30,6 +30,17 @@ typedef struct {
         int rng_key[3]; /* 12bytes long random number */
 } hyper_dmabuf_id_t;
 
+struct hyper_dmabuf_event_hdr {
+	int event_type; /* one type only for now - new import */
+	hyper_dmabuf_id_t hid; /* hyper_dmabuf_id of specific hyper_dmabuf */
+	size_t size; /* size of data */
+};
+
+struct hyper_dmabuf_event_data {
+	struct hyper_dmabuf_event_hdr hdr;
+	void *data; /* private data */
+};
+
 #define IOCTL_HYPER_DMABUF_TX_CH_SETUP \
 _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_hyper_dmabuf_tx_ch_setup))
 struct ioctl_hyper_dmabuf_tx_ch_setup {
@@ -56,7 +67,7 @@ struct ioctl_hyper_dmabuf_export_remote {
 	int remote_domain;
 	/* exported dma buf id */
 	hyper_dmabuf_id_t hid;
-	int priv[4];
+	int priv[32];
 };
 
 #define IOCTL_HYPER_DMABUF_EXPORT_FD \
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel