From patchwork Wed Nov 30 04:39:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9453573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5234860756 for ; Wed, 30 Nov 2016 04:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4800F28329 for ; Wed, 30 Nov 2016 04:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C7D028426; Wed, 30 Nov 2016 04:42:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C70052837F for ; Wed, 30 Nov 2016 04:42:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBwgZ-00028m-CV; Wed, 30 Nov 2016 04:39:59 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBwgX-00028H-Jk for xen-devel@lists.xenproject.org; Wed, 30 Nov 2016 04:39:57 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 51/B5-08512-C185E385; Wed, 30 Nov 2016 04:39:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRWlGSWpSXmKPExsVyMfTOQV2ZCLs Ig1v9fBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8arNwfZCpYpVix6Y9rAuE2ii5GLQ0hgFqNE 1+r17F2MnBwsAh9YJNa9BktICExjlbixpZMVJCEhECPx98VURgi7UuJF9yU2EFtIQEliy+THj BCTdjFJXH24HqxIWEBPYvK322A2m4C+xNO115i7GDmAmt0kPl3jAgmLCKRKTHj1gA2kl1ngG6 PEy41fmSF6MyXuHn7IBHGRqsSsTzcYQXp5gXr7J3FB3CAncfNcJ9hITgF3ibvX1SHOcZNYs+w 2+wRGoQWMDKsYNYpTi8pSi3SNTPWSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQKD sJ6BgXEH4652v0OMkhxMSqK8UpZ2EUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeD+HAeUEi1LTU yvSMnOA8QCTluDgURLhNQwFSvMWFyTmFmemQ6ROMVpyvPrw4gETx785r4Bkx4cPD5iEWPLy81 KlxHm/gcwTAGnIKM2DGweL2UuMslLCvIwMDAxCPAWpRbmZJajyrxjFORiVhHnfgUzhycwrgdv 6CuggJqCD3r62BjmoJBEhJdXAGPOBrfn0ijs3Jr7llk/az8F3UXWbfVjUat2ERJae4ou1Xfca uMNtarlLT156uovxUrbjjJ1T+/x+3yv1K3x8a/WyKJF5oUKlKquSZdk+LI6x2OYj8CzN4H7V2 jnqS06+6NnLMPdGiPjuJfP2O5in/yi8EFr9t1S6+f478ychr7eu0n/YOTnKT4mlOCPRUIu5qD gRAP1J0xHUAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1480480794!73036885!1 X-Originating-IP: [209.85.220.193] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8114 invoked from network); 30 Nov 2016 04:39:55 -0000 Received: from mail-qk0-f193.google.com (HELO mail-qk0-f193.google.com) (209.85.220.193) by server-9.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 30 Nov 2016 04:39:55 -0000 Received: by mail-qk0-f193.google.com with SMTP id y205so20422551qkb.1 for ; Tue, 29 Nov 2016 20:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vTBrAkIv3MMuXdDDWvb2VKrtMoqje70bCJYdR9i3Fg8=; b=tZRESLAchQ+KyEav56Y6K6Fs5nVar3AZMjUbiD5S5uo49pW0k8gmljc3b9/556rYAW tYbE7R7DpOT9i+BAh2V2ovRbJz3OB7EvSi1NDNXuAra6CQlgnlJB7QZbIIbvrp63EG4r y1R4M00cC8IG3O2nsRxOI0KX5UgNgkvTNDH8DYcd2biGOEc8H+gNZS+8jz0o5JHNjkZR fk1JMBnN7LWDnl3kYNPndqJ12dz+pP2Tsg7MzYsbVZTAQix7verq68S8fD5XcCm7kw8a VGrAwT4xhBLa8k0zfU/GFcxRPKGiJsXkP/N9Bv7NBcvdHempwz4+EvDQ1x6SD8Kr/RaM gz4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=vTBrAkIv3MMuXdDDWvb2VKrtMoqje70bCJYdR9i3Fg8=; b=AucJ8kBNJgE2wkUOMGkkVzLQYWA4WL8NbFuvrRNeUOBshGEP9d/rQv0QeRKYuT3GOy f//etNMiuqj0EoMrL2WcLZ5Xr5nGo9/SQ/O8cHaBo1hQHavN6kEdpuUtHN4xEtBooTgs Ehpv9CKzVY0/grGitEsLubngTMbl9U6MzmCpqhgsv4b0pmmONGLqbh4o7TZvb+l+MZ9G MT7ccyxts7eAEceEIZlUYu61hPEb0eHJ9h346hv0gbFVI2w7AeC2c3xwIuZOI8Zg5ofm 52lLeBKgiBUxh3BPIhPQQZzd0QQsKQRSfI3kzR1Ei5OrY7K5ir96NmZS7l9xbCKMMJ3r AzZg== X-Gm-Message-State: AKaTC01ghK3No/fcp6X2wMMfm4gHMSjrNGKHx2lTRSNAVsQ+M8b8ShNVaymsnKD1XJdiKg== X-Received: by 10.55.51.77 with SMTP id z74mr30361535qkz.201.1480480794852; Tue, 29 Nov 2016 20:39:54 -0800 (PST) Received: from build-external.dumpdata.com (209-6-196-81.c3-0.smr-ubr2.sbo-smr.ma.cable.rcn.com. [209.6.196.81]) by smtp.gmail.com with ESMTPSA id q65sm32558920qki.20.2016.11.29.20.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 20:39:54 -0800 (PST) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, boris.ostrovsky@oracle.com, jgross@suse.com Date: Tue, 29 Nov 2016 23:39:38 -0500 Message-Id: <1480480779-12078-2-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480480779-12078-1-git-send-email-konrad.wilk@oracle.com> References: <1480480779-12078-1-git-send-email-konrad.wilk@oracle.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: [Xen-devel] [PATCH RFC 1/2] xen/page_alloc: Add size_align parameter to provide MFNs which are size aligned. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)