From: Konrad Rzeszutek Wilk <konrad@kernel.org>
To: xen-devel@lists.xenproject.org, konrad@kernel.org,
boris.ostrovsky@oracle.com, jgross@suse.com
Cc: sstabellini@kernel.org, wei.liu2@citrix.com,
martin.petersen@oracle.com, George.Dunlap@eu.citrix.com,
andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com,
tim@xen.org, jbeulich@suse.com
Subject: [PATCH RFC 1/2] xen/page_alloc: Add size_align parameter to provide MFNs which are size aligned.
Date: Tue, 29 Nov 2016 23:39:38 -0500 [thread overview]
Message-ID: <1480480779-12078-2-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1480480779-12078-1-git-send-email-konrad.wilk@oracle.com>
This is to support the requirement that exists in PV dom0
when doing DMA requests:
"dma_alloc_coherent()
[...]
The CPU virtual address and the DMA address are both guaranteed to be
aligned to the smallest PAGE_SIZE order which is greater than or equal
to the requested size. This invariant exists (for example) to guarantee
that if you allocate a chunk which is smaller than or equal to 64
kilobytes, the extent of the buffer you receive will not cross a 64K
boundary."
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
xen/common/memory.c | 3 +++
xen/common/page_alloc.c | 22 +++++++++++++++++++++-
xen/include/public/memory.h | 2 ++
xen/include/xen/mm.h | 2 ++
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 21797ca..a4c0c54 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -475,6 +475,9 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
(BITS_PER_LONG+PAGE_SHIFT)));
memflags |= MEMF_node(XENMEMF_get_node(exch.out.mem_flags));
+ if ( XENMEMF_align_size & exch.out.mem_flags && is_hardware_domain(d) )
+ memflags |= MEMF_size_align;
+
for ( i = (exch.nr_exchanged >> in_chunk_order);
i < (exch.in.nr_extents >> in_chunk_order);
i++ )
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index ae2476d..e43f52f 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -738,7 +738,7 @@ static struct page_info *alloc_heap_pages(
* Others try tmem pools then fail. This is a workaround until all
* post-dom0-creation-multi-page allocations can be eliminated.
*/
- if ( ((order == 0) || (order >= 9)) &&
+ if ( ((order == 0) || (order >= 9)) && !(memflags & MEMF_size_align) &&
(total_avail_pages <= midsize_alloc_zone_pages) &&
tmem_freeable_pages() )
goto try_tmem;
@@ -752,14 +752,34 @@ static struct page_info *alloc_heap_pages(
{
zone = zone_hi;
do {
+ struct page_info *old = NULL;
+
/* Check if target node can support the allocation. */
if ( !avail[node] || (avail[node][zone] < request) )
continue;
/* Find smallest order which can satisfy the request. */
for ( j = order; j <= MAX_ORDER; j++ )
+ {
+ next_page:
if ( (pg = page_list_remove_head(&heap(node, zone, j))) )
+ {
+ if ( memflags & MEMF_size_align )
+ {
+ if (pg == old)
+ continue;
+
+ if ( (page_to_mfn(pg) % request ) == 0 )
+ goto found;
+
+ page_list_add_tail(pg, &heap(node, zone, j));
+ old = pg;
+ pg = NULL;
+ goto next_page;
+ }
goto found;
+ }
+ }
} while ( zone-- > zone_lo ); /* careful: unsigned zone may wrap */
if ( (memflags & MEMF_exact_node) && req_node != NUMA_NO_NODE )
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index 5bf840f..311e7d8 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -58,6 +58,8 @@
#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
/* Flag to indicate the node specified is virtual node */
#define XENMEMF_vnode (1<<18)
+/* Flag to indicate the allocation to be size aligned. */
+#define XENMEMF_align_size (1U<<19)
#endif
struct xen_memory_reservation {
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 76fbb82..c505170 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -224,6 +224,8 @@ struct npfec {
#define MEMF_no_owner (1U<<_MEMF_no_owner)
#define _MEMF_no_tlbflush 6
#define MEMF_no_tlbflush (1U<<_MEMF_no_tlbflush)
+#define _MEMF_size_align 7
+#define MEMF_size_align (1U<<_MEMF_size_align)
#define _MEMF_node 8
#define MEMF_node_mask ((1U << (8 * sizeof(nodeid_t))) - 1)
#define MEMF_node(n) ((((n) + 1) & MEMF_node_mask) << _MEMF_node)
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-11-30 4:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-30 4:39 [PATCH RFC] Add size alignment to page allocator Konrad Rzeszutek Wilk
2016-11-30 4:39 ` Konrad Rzeszutek Wilk [this message]
2016-11-30 9:30 ` [PATCH RFC 1/2] xen/page_alloc: Add size_align parameter to provide MFNs which are size aligned Jan Beulich
2016-11-30 16:42 ` Konrad Rzeszutek Wilk
2016-11-30 16:45 ` Jan Beulich
2016-11-30 4:39 ` [PATCH RFC 2/2] xen-swiotlb: Provide size aligned DMA addresses Konrad Rzeszutek Wilk
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=1480480779-12078-2-git-send-email-konrad.wilk@oracle.com \
--to=konrad@kernel.org \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=martin.petersen@oracle.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).