Skip to contentSkip to conversation

staging: gasket: add DMA direction flags a.o.

PATCH In review Todd Poynor 2 participants 5 messages Oct 16, 2018 – Oct 19, 2018 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: gasket: add DMA direction flags a.o.

From: Todd Poynor <[email protected]>

Add flags to page mapping ioctls that specify DMA directions other than bi-directional, avoiding unnecessary cache maintenance for read-only or write-only buffers.

Remove some spammy / unhelpful / inaccurately formatted debug logs.

Nick Ewalt (1):
staging: gasket: page_table: add mapping flags

Todd Poynor (2):
staging: gasket: remove debug logs for callback invocation
staging: gasket: remove debug logs in page table mapping calls

 drivers/staging/gasket/gasket.h            |  33 ++++++
 drivers/staging/gasket/gasket_core.c       |   7 +-
 drivers/staging/gasket/gasket_ioctl.c      |  62 +++++++++---
 drivers/staging/gasket/gasket_page_table.c | 111 +++++++++++----------
 drivers/staging/gasket/gasket_page_table.h |   4 +-
 5 files changed, 142 insertions(+), 75 deletions(-)
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog
#1 lore raw

PATCH 1/3 staging: gasket: remove debug logs for callback invocation

From: Todd Poynor <[email protected]>

Debug logs for device-specific callback invocation aren't very useful, remove.

---
 drivers/staging/gasket/gasket_core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/staging/gasket/gasket_core.c +1 -6
index f230bec76ae4e..a445d58fb3999 100644
@@ -109,8 +109,6 @@ check_and_invoke_callback(struct gasket_dev *gasket_dev,
 {
 	int ret = 0;
 
-	dev_dbg(gasket_dev->dev, "check_and_invoke_callback %p\n",
-		cb_function);
 	if (cb_function) {
 		mutex_lock(&gasket_dev->mutex);
 		ret = cb_function(gasket_dev);
@@ -126,11 +124,8 @@ gasket_check_and_invoke_callback_nolock(struct gasket_dev *gasket_dev,
 {
 	int ret = 0;
 
-	if (cb_function) {
-		dev_dbg(gasket_dev->dev,
-			"Invoking device-specific callback.\n");
+	if (cb_function)
 		ret = cb_function(gasket_dev);
-	}
 	return ret;
 }
 
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog
#2 lore raw

PATCH 2/3 staging: gasket: remove debug logs in page table mapping calls

In reply to Todd Poynor

From: Todd Poynor <[email protected]>

Remove very noisy debug logs that also contain typos and incorrect output formats.

---
 drivers/staging/gasket/gasket_page_table.c | 24 ----------------------
 1 file changed, 24 deletions(-)
drivers/staging/gasket/gasket_page_table.c +0 -24
index 5b398b7ba81d3..b7d460cf15fbc 100644
@@ -477,7 +477,6 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
 	for (i = 0; i < num_pages; i++) {
 		page_addr = host_addr + i * PAGE_SIZE;
 		offset = page_addr & (PAGE_SIZE - 1);
-		dev_dbg(pg_tbl->device, "%s i %d\n", __func__, i);
 		if (is_coherent(pg_tbl, host_addr)) {
 			u64 off =
 				(u64)host_addr -
@@ -506,22 +505,9 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
 			ptes[i].dma_addr =
 				dma_map_page(pg_tbl->device, page, 0, PAGE_SIZE,
 					     DMA_BIDIRECTIONAL);
-			dev_dbg(pg_tbl->device,
-				"%s i %d pte %p pfn %p -> mapped %llx\n",
-				__func__, i, &ptes[i],
-				(void *)page_to_pfn(page),
-				(unsigned long long)ptes[i].dma_addr);
 
 			if (dma_mapping_error(pg_tbl->device,
 					      ptes[i].dma_addr)) {
-				dev_dbg(pg_tbl->device,
-					"%s i %d -> fail to map page %llx "
-					"[pfn %p ohys %p]\n",
-					__func__, i,
-					(unsigned long long)ptes[i].dma_addr,
-					(void *)page_to_pfn(page),
-					(void *)page_to_phys(page));
-
 				if (gasket_release_page(ptes[i].page))
 					--pg_tbl->num_active_pages;
 
@@ -892,11 +878,6 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl,
 	pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, PAGE_SIZE,
 				     DMA_TO_DEVICE);
 	if (dma_mapping_error(pg_tbl->device, pte->dma_addr)) {
-		dev_dbg(pg_tbl->device,
-			"%s: fail to map page [pfn %lx phys %llx]\n",
-			__func__, page_to_pfn(pte->page),
-			page_to_phys(pte->page));
-
 		free_page(page_addr);
 		vfree(pte->sublevel);
 		memset(pte, 0, sizeof(struct gasket_page_table_entry));
@@ -1050,11 +1031,6 @@ int gasket_page_table_map(struct gasket_page_table *pg_tbl, ulong host_addr,
 	}
 
 	mutex_unlock(&pg_tbl->mutex);
-
-	dev_dbg(pg_tbl->device,
-		"%s done: ha %llx daddr %llx num %d, ret %d\n",
-		__func__, (unsigned long long)host_addr,
-		(unsigned long long)dev_addr, num_pages, ret);
 	return ret;
 }
 EXPORT_SYMBOL(gasket_page_table_map);
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog
#3 lore raw

PATCH 3/3 staging: gasket: page_table: add mapping flags

In reply to Todd Poynor

From: Nick Ewalt <[email protected]>

This allows for more precise dma_direction in the dma_map_page requests. Also leaves room for adding more flags later.

---
 drivers/staging/gasket/gasket.h            | 33 ++++++++
 drivers/staging/gasket/gasket_ioctl.c      | 62 +++++++++++----
 drivers/staging/gasket/gasket_page_table.c | 87 ++++++++++++++--------
 drivers/staging/gasket/gasket_page_table.h |  4 +-
 4 files changed, 141 insertions(+), 45 deletions(-)
drivers/staging/gasket/gasket.h +33 -0
index a0f065c517a52..93e7af1551975 100644
@@ -37,6 +37,31 @@ struct gasket_page_table_ioctl {
 	u64 device_address;
 };
 
+/*
+ * Structure for ioctl mapping buffers with flags when using the Gasket
+ * page_table module.
+ */
+struct gasket_page_table_ioctl_flags {
+	struct gasket_page_table_ioctl base;
+	/*
+	 * Flags indicating status and attribute requests from the host.
+	 * NOTE: STATUS bit does not need to be set in this request.
+	 *       Set RESERVED bits to 0 to ensure backwards compatibility.
+	 *
+	 * Bitfields:
+	 *   [0]     - STATUS: indicates if this entry/slot is free
+	 *                0 = PTE_FREE
+	 *                1 = PTE_INUSE
+	 *   [2:1]   - DMA_DIRECTION: dma_data_direction requested by host
+	 *               00 = DMA_BIDIRECTIONAL
+	 *               01 = DMA_TO_DEVICE
+	 *               10 = DMA_FROM_DEVICE
+	 *               11 = DMA_NONE
+	 *   [31:3]  - RESERVED
+	 */
+	u32 flags;
+};
+
 /*
  * Common structure for ioctls mapping and unmapping buffers when using the
  * Gasket page_table module.
@@ -119,4 +144,12 @@ struct gasket_coherent_alloc_config_ioctl {
 #define GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR                                 \
 	_IOWR(GASKET_IOCTL_BASE, 11, struct gasket_coherent_alloc_config_ioctl)
 
+/*
+ * Tells the kernel to map size bytes at host_address to device_address in
+ * page_table_index page table. Passes flags to indicate additional attribute
+ * requests for the mapped memory.
+ */
+#define GASKET_IOCTL_MAP_BUFFER_FLAGS                                          \
+	_IOW(GASKET_IOCTL_BASE, 12, struct gasket_page_table_ioctl_flags)
+
 #endif /* __GASKET_H__ */
drivers/staging/gasket/gasket_ioctl.c +49 -13

102 lines not on this page · raw message

drivers/staging/gasket/gasket_page_table.c +56 -31

235 lines not on this page · raw message

drivers/staging/gasket/gasket_page_table.h +3 -1
index 7b01b73ea3e70..d4df6a198e9e0 100644
@@ -85,6 +85,8 @@ int gasket_page_table_partition(struct gasket_page_table *page_table,
  * @host_addr: Starting host virtual memory address of the pages.
  * @dev_addr: Starting device address of the pages.
  * @num_pages: Number of [4kB] pages to map.
+ * @flags: Specifies attributes to apply to the pages.
+ *         Internal structure matches gasket_page_table_ioctl_flags.flags.
  *
  * Description: Maps the "num_pages" pages of host memory pointed to by
  *              host_addr to the address "dev_addr" in device memory.
@@ -95,7 +97,7 @@ int gasket_page_table_partition(struct gasket_page_table *page_table,
  *              If there is an error, no pages are mapped.
  */
 int gasket_page_table_map(struct gasket_page_table *page_table, ulong host_addr,
-			  ulong dev_addr, uint num_pages);
+			  ulong dev_addr, uint num_pages, u32 flags);
 
 /*
  * Un-map host pages from device memory.
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog
#4 lore raw

Re: [PATCH 3/3] staging: gasket: page_table: add mapping flags

Quoted 4 lines · Todd Poynor

From: Nick Ewalt <[email protected]>

This allows for more precise dma_direction in the dma_map_page requests. Also leaves room for adding more flags later.

Why are you adding new features to this code? It needs to have stuff cleaned up and removed before you can add new stuff to it.

And why is this new ioctl even needed?

Some patch review comments below:

Quoted 11 lines
drivers/staging/gasket/gasket.h +11 -0
+/*
+ * Structure for ioctl mapping buffers with flags when using the Gasket
+ * page_table module.
+ */
+struct gasket_page_table_ioctl_flags {
+	struct gasket_page_table_ioctl base;
+	/*
+	 * Flags indicating status and attribute requests from the host.
+	 * NOTE: STATUS bit does not need to be set in this request.
+	 *       Set RESERVED bits to 0 to ensure backwards compatibility.
+	 *

drivers/staging/gasket/gasket.h struct gasket_page_table_ioctl { · line 60

Quoted 10 lines
drivers/staging/gasket/gasket.h +10 -0
+	 * Bitfields:
+	 *   [0]     - STATUS: indicates if this entry/slot is free
+	 *                0 = PTE_FREE
+	 *                1 = PTE_INUSE
+	 *   [2:1]   - DMA_DIRECTION: dma_data_direction requested by host
+	 *               00 = DMA_BIDIRECTIONAL
+	 *               01 = DMA_TO_DEVICE
+	 *               10 = DMA_FROM_DEVICE
+	 *               11 = DMA_NONE
+	 *   [31:3]  - RESERVED

What endian are these bitfields in?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 */
+	u32 flags;

"u32" is not a valid variable type for something that goes across the user/kernel boundry. It should be __u32. You all know this stuff...

Quoted 5 lines
drivers/staging/gasket/gasket_page_table.c +0 -0
index b7d460cf15fbc..06e188f5b905c 100644

drivers/staging/gasket/gasket_page_table.c line 95

Quoted 9 lines
drivers/staging/gasket/gasket_page_table.c +6 -0
@@ -87,6 +87,19 @@
  */
 #define GASKET_EXTENDED_LVL1_SHIFT 12
 
+/*
+ * Utilities for accessing flags bitfields.
+ */
+#define MASK(field)            (((1u << field##_WIDTH) - 1) << field##_SHIFT)
+#define GET(field, flags)      (((flags) & MASK(field)) >> field##_SHIFT)
+#define SET(field, flags, val) (((flags) & ~MASK(field)) | ((val) << field##_SHIFT))

Ick, why invent stuff the kernel already has? Please never do that, use the functions/macros we already have for this very thing please.

That way I don't have to audit it that you all got it correct, and neither do you have to guess that you got it correct :)

thanks,

greg k-h