From: Todd Poynor <toddpoynor@gmail.com>
To: Rob Springer <rspringer@google.com>,
Ben Chan <benchan@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
Nick Ewalt <nicholasewalt@google.com>,
Todd Poynor <toddpoynor@google.com>
Subject: [PATCH 08/10] staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping
Date: Mon, 17 Sep 2018 05:39:03 -0700 [thread overview]
Message-ID: <20180917123905.213639-9-toddpoynor@gmail.com> (raw)
In-Reply-To: <20180917123905.213639-1-toddpoynor@gmail.com>
From: Nick Ewalt <nicholasewalt@google.com>
Previously pages would have never been unmapped in this case.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 33 +++++++++++++---------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index c1ce8f984f8e0..779ad2f23ef9b 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -433,6 +433,19 @@ static int is_coherent(struct gasket_page_table *pg_tbl, ulong host_addr)
return min <= host_addr && host_addr < max;
}
+/* Safely return a page to the OS. */
+static bool gasket_release_page(struct page *page)
+{
+ if (!page)
+ return false;
+
+ if (!PageReserved(page))
+ SetPageDirty(page);
+ put_page(page);
+
+ return true;
+}
+
/*
* Get and map last level page table buffers.
*
@@ -500,6 +513,13 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
(unsigned long long)ptes[i].dma_addr,
(void *)page_to_pfn(page),
(void *)page_to_phys(page));
+
+ /* clean up */
+ if (gasket_release_page(ptes[i].page))
+ --pg_tbl->num_active_pages;
+
+ memset(&ptes[i], 0,
+ sizeof(struct gasket_page_table_entry));
return -1;
}
}
@@ -571,19 +591,6 @@ static int gasket_alloc_simple_entries(struct gasket_page_table *pg_tbl,
return 0;
}
-/* Safely return a page to the OS. */
-static bool gasket_release_page(struct page *page)
-{
- if (!page)
- return false;
-
- if (!PageReserved(page))
- SetPageDirty(page);
- put_page(page);
-
- return true;
-}
-
/*
* Unmap and release mapped pages.
* The page table mutex must be held by the caller.
--
2.19.0.397.gdd90340f6a-goog
next prev parent reply other threads:[~2018-09-17 12:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
2018-09-17 12:38 ` [PATCH 01/10] staging: gasket: Kconfig: describe Apex as an Edge TPU device Todd Poynor
2018-09-17 12:38 ` [PATCH 02/10] staging: gasket: interrupt: remove PCI-MSIX-specific status check Todd Poynor
2018-09-17 12:38 ` [PATCH 03/10] staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent Todd Poynor
2018-09-17 12:38 ` [PATCH 04/10] staging: gasket: fix DMA direction for extended page tables Todd Poynor
2018-09-17 12:39 ` [PATCH 05/10] staging: gasket: fix data page unmap DMA direction Todd Poynor
2018-09-17 12:39 ` [PATCH 06/10] staging: gasket: page_table: don't unmap coherent pages Todd Poynor
2018-09-17 12:39 ` [PATCH 07/10] staging: gasket: fix gasket_free_coherent_memory metadata frees Todd Poynor
2018-09-17 12:39 ` Todd Poynor [this message]
2018-09-17 12:39 ` [PATCH 09/10] staging: gasket: page_table: use total_entries for max ext lvl0 page idx Todd Poynor
2018-09-17 12:39 ` [PATCH 10/10] staging: gasket: page_table: handle failed dma_map_page Todd Poynor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180917123905.213639-9-toddpoynor@gmail.com \
--to=toddpoynor@gmail.com \
--cc=benchan@chromium.org \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicholasewalt@google.com \
--cc=rspringer@google.com \
--cc=toddpoynor@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).