From patchwork Wed Nov 30 04:39:39 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: 9453571 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 054666071E 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 EF37C28329 for ; Wed, 30 Nov 2016 04:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E399528429; Wed, 30 Nov 2016 04:42:17 +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 788DF28329 for ; Wed, 30 Nov 2016 04:42:17 +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-000290-JT; Wed, 30 Nov 2016 04:39:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBwgY-00028S-Dy for xen-devel@lists.xenproject.org; Wed, 30 Nov 2016 04:39:58 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 27/DC-28490-D185E385; Wed, 30 Nov 2016 04:39:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRWlGSWpSXmKPExsVyMfTOQV3ZCLs Ig8Z/nBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0b7nwb2gmeqFdee7mVvYGyX72Lk5BASmMUo cWpWcBcjFweLwAcWiWtrPjCBOBIC01gl1k7fzgpSJSEQI7Hn1jY2CLtK4sKdCSwQ3UoSWyY/Z gRpEBLYxSRxfcYtsCJhAT2Jyd9uM4LYbAL6Ek/XXmPuYuQAanaT+HSNCyQsIpAqMeHVAzaQXm aBb4wSLzd+BasRFvCUeHDUEKSGRUBV4uOrTrCRvECtMxbvZIG4QU7i5rlOsHJOAXeJu9fVIc5 xk1iz7Db7BEahBYwMqxjVi1OLylKLdA31kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r1kvNz NzECg5ABCHYw7nzudIhRkoNJSZRXytIuQogvKT+lMiOxOCO+qDQntfgQowwHh5IEb2Y4UE6wK DU9tSItMwcYDzBpCQ4eJRHeLpA0b3FBYm5xZjpE6hSjJcerDy8eMHG82fUSSHZ8+PCASYglLz 8vVUqc91sYUIMASENGaR7cOFjMXmKUlRLmZQQ6UIinILUoN7MEVf4VozgHo5IwbxrIWp7MvBK 4ra+ADmICOujta2uQg0oSEVJSDYzCFccWesXtOW3RY7Ocd39G2uvPaxkjOe/HckWIzp60+Keo 1eQtenNfnROuZf3IHrTTsf+rNL82t7f7f5HjvzPSvjTz+jG/m3RwvrgB16n/3P2sAQvTO64Y/ C53CgsNfl6e6Wxz1GS9g5ta8CVvpYWaH9U+ijbvd3X2D6+qKxWd6mIkzR7ySImlOCPRUIu5qD gRAN8G7orUAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1480480796!74863795!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 7236 invoked from network); 30 Nov 2016 04:39:56 -0000 Received: from mail-qk0-f193.google.com (HELO mail-qk0-f193.google.com) (209.85.220.193) by server-9.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 30 Nov 2016 04:39:56 -0000 Received: by mail-qk0-f193.google.com with SMTP id h201so20394850qke.3 for ; Tue, 29 Nov 2016 20:39:56 -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=1G9QOmvwxhsJYQfX/YlFZsYPryhAoiGA709mxqrQifA=; b=UZngOdcplGgY6+3ImVpOQCNjgslTLzTXKyf2ST4GZG9twRfMhhizW3PeXmaFqP2OMT Ds2KyJOV4FcDb7vwmsHMdf/uq5MgpsLaRk5iQKE0Q0Q/9jk8QJROl95mpMVXXkHBlSty jU9bpoS2CJo/FsmupWP+imYk3YiRJZ4DEexztKfxkx2kxcuKHoPH5ks0lH7oAh99rLrN DROqEVahR1Uicq3K3YnoHcVgRcd7BTV9XKUaBRKLMAb46SiKj2UAWPC0b1zH44ba68b2 xRJ4CoCAzVGeT4JaehOv6Aipz/AXYQRoUnhzLv3+N8jYnEGDYVSn0lzFfg8+CY2DzbA8 TISQ== 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=1G9QOmvwxhsJYQfX/YlFZsYPryhAoiGA709mxqrQifA=; b=Tn10LWq6NDN3FWmAvOA2hM68LHAVoeZ1/Zy7ABIm9BhO+hKXfEhur1jMV9zpKtGV8Q 3TtsuJ2KNxiOOcp+XQvM9CNpC3XFVjfPQe/93jiIYm6oA9hzZ/u/d92LapUF9Met551o 9ettDnPl1YcV2lYeZjGYQBaVP5ld3hkeBqtSnFcIfxOwVYgfv5uPJ5lcjZ7buOLZrYIL Lci3FJW2W0XKCphG4rv6Qc3I7gosQZphPn26SZag/UQ6iIj9qCRBkg5JIwhKmtptNmhS VTO0mNHAJDjn5VmQKuyUFU5caAixjjU7/XCbSmLbc/eSGzn9NCEvffYkRzimcXbpmTq9 Zf3Q== X-Gm-Message-State: AKaTC00AwmA+f7IzslyPndvenbDTwHhq7a/aL2qgZ3s5XjWjeWal1SkCOxF2AgltSiTvTA== X-Received: by 10.55.121.69 with SMTP id u66mr26921906qkc.207.1480480795862; Tue, 29 Nov 2016 20:39:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 20:39:55 -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:39 -0500 Message-Id: <1480480779-12078-3-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 2/2] xen-swiotlb: Provide size aligned DMA addresses. 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 The dma_alloc_coherent() API specifies that: [...] 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." This change, along with the XENMEMF_align_size in the hypervisor allows us to provide DMA buffers that are size aligned. Signed-off-by: Konrad Rzeszutek Wilk --- arch/x86/xen/mmu.c | 12 +++++++----- drivers/xen/swiotlb-xen.c | 4 ++-- include/xen/interface/memory.h | 10 ++++++++++ include/xen/xen-ops.h | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index 7d5afdb..07e5a97 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -2577,7 +2577,8 @@ static int xen_exchange_memory(unsigned long extents_in, unsigned int order_in, unsigned long extents_out, unsigned int order_out, unsigned long *mfns_out, - unsigned int address_bits) + unsigned int address_bits, + bool size_align) { long rc; int success; @@ -2599,7 +2600,8 @@ static int xen_exchange_memory(unsigned long extents_in, unsigned int order_in, }; BUG_ON(extents_in << order_in != extents_out << order_out); - + if (size_align) + exchange.out.address_bits |= XENMEMF_align_size; rc = HYPERVISOR_memory_op(XENMEM_exchange, &exchange); success = (exchange.nr_exchanged == extents_in); @@ -2611,7 +2613,7 @@ static int xen_exchange_memory(unsigned long extents_in, unsigned int order_in, int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits, - dma_addr_t *dma_handle) + dma_addr_t *dma_handle, bool size_align) { unsigned long *in_frames = discontig_frames, out_frame; unsigned long flags; @@ -2641,7 +2643,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, out_frame = virt_to_pfn(vstart); success = xen_exchange_memory(1UL << order, 0, in_frames, 1, order, &out_frame, - address_bits); + address_bits, size_align); /* 3. Map the new extent in place of old pages. */ if (success) @@ -2682,7 +2684,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order) /* 3. Do the exchange for non-contiguous MFNs. */ success = xen_exchange_memory(1, order, &in_frame, 1UL << order, - 0, out_frames, 0); + 0, out_frames, 0, false); /* 4. Map new pages in place of old pages. */ if (success) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 87e6035..4996685 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -173,7 +173,7 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) rc = xen_create_contiguous_region( p + (i << IO_TLB_SHIFT), get_order(slabs << IO_TLB_SHIFT), - dma_bits, &dma_handle); + dma_bits, &dma_handle, false); } while (rc && dma_bits++ < max_dma_bits); if (rc) return rc; @@ -334,7 +334,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, *dma_handle = dev_addr; else { if (xen_create_contiguous_region(phys, order, - fls64(dma_mask), dma_handle) != 0) { + fls64(dma_mask), dma_handle, true) != 0) { xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h index 9aa8988..b98271f 100644 --- a/include/xen/interface/memory.h +++ b/include/xen/interface/memory.h @@ -19,6 +19,16 @@ #define XENMEM_increase_reservation 0 #define XENMEM_decrease_reservation 1 #define XENMEM_populate_physmap 6 +/* + * Maximum # bits addressable by the user of the allocated region (e.g., I/O + * devices often have a 32-bit limitation even in 64-bit systems). If zero + * then the user has no addressing restriction. This field is not used by + * XENMEM_decrease_reservation. + */ + +/* Flag to indicate the allocation to be size aligned. */ +#define XENMEMF_align_size (1U<<19) + struct xen_memory_reservation { /* diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index b5486e6..9aa3ab8 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -36,7 +36,7 @@ int xen_setup_shutdown_event(void); extern unsigned long *xen_contiguous_bitmap; int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits, - dma_addr_t *dma_handle); + dma_addr_t *dma_handle, bool size_align); void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);