From patchwork Thu Jul 9 20:42:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 6759361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0417FC05AC for ; Thu, 9 Jul 2015 20:47:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2044D2053B for ; Thu, 9 Jul 2015 20:46:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D3812053C for ; Thu, 9 Jul 2015 20:46:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZDIgb-00010h-PS; Thu, 09 Jul 2015 20:44:49 +0000 Received: from smtp.citrix.com ([66.165.176.89]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZDIgF-0000e1-Og for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2015 20:44:28 +0000 X-IronPort-AV: E=Sophos;i="5.15,442,1432598400"; d="scan'208";a="279679541" From: Julien Grall To: Subject: [PATCH v2 03/20] xen/grant: Introduce helpers to split a page into grant Date: Thu, 9 Jul 2015 21:42:15 +0100 Message-ID: <1436474552-31789-4-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436474552-31789-1-git-send-email-julien.grall@citrix.com> References: <1436474552-31789-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150709_134427_960234_CE68FEB0 X-CRM114-Status: GOOD ( 16.10 ) X-Spam-Score: -7.3 (-------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ian.campbell@citrix.com, Konrad Rzeszutek Wilk , stefano.stabellini@eu.citrix.com, linux-kernel@vger.kernel.org, Julien Grall , David Vrabel , Boris Ostrovsky , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, a grant is always based on the Xen page granularity (i.e 4KB). When Linux is using a different page granularity, a single page will be split between multiple grants. The new helpers will be in charge to split the Linux page into grant and call a function given by the caller on each grant. In order to help some PV drivers, the callback is allowed to use less data and must update the resulting length. This is useful for netback. Also provide and helper to count the number of grants within a given contiguous region. Signed-off-by: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Boris Ostrovsky Cc: David Vrabel --- Changes in v2: - Patch added --- drivers/xen/grant-table.c | 26 ++++++++++++++++++++++++++ include/xen/grant_table.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 62f591f..3679293 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -296,6 +296,32 @@ int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly) } EXPORT_SYMBOL_GPL(gnttab_end_foreign_access_ref); +void gnttab_foreach_grant(struct page *page, unsigned int offset, + unsigned int len, xen_grant_fn_t fn, + void *data) +{ + unsigned int goffset; + unsigned int glen; + unsigned long pfn; + + len = min_t(unsigned int, PAGE_SIZE - offset, len); + goffset = offset & ~XEN_PAGE_MASK; + + pfn = xen_page_to_pfn(page) + (offset >> XEN_PAGE_SHIFT); + + while (len) { + glen = min_t(unsigned int, XEN_PAGE_SIZE - goffset, len); + fn(pfn_to_mfn(pfn), goffset, &glen, data); + + goffset += glen; + if (goffset == XEN_PAGE_SIZE) { + goffset = 0; + pfn++; + } + len -= glen; + } +} + struct deferred_entry { struct list_head list; grant_ref_t ref; diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h index 4478f4b..6f77378 100644 --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h @@ -45,8 +45,10 @@ #include #include +#include #include #include +#include #define GNTTAB_RESERVED_XENSTORE 1 @@ -224,4 +226,43 @@ static inline struct xen_page_foreign *xen_page_foreign(struct page *page) #endif } +/* Split Linux page in chunk of the size of the grant and call fn + * + * Parameters of fn: + * mfn: machine frame number based on grant granularity + * offset: offset in the grant + * len: length of the data in the grant. If fn decides to use less data, + * it must update len. + * data: internal information + */ +typedef void (*xen_grant_fn_t)(unsigned long mfn, unsigned int offset, + unsigned int *len, void *data); + +void gnttab_foreach_grant(struct page *page, unsigned int offset, + unsigned int len, xen_grant_fn_t fn, + void *data); + +/* Helper to get to call fn only on the first "grant chunk" */ +static inline void gnttab_one_grant(struct page *page, unsigned int offset, + unsigned len, xen_grant_fn_t fn, + void *data) +{ + /* The first request is limited to the size of one grant */ + len = min_t(unsigned int, XEN_PAGE_SIZE - (offset & ~XEN_PAGE_MASK), + len); + + gnttab_foreach_grant(page, offset, len, fn, data); +} + +/* Get the number of grant in a specified region + * + * offset: Offset in the first page + * len: total lenght of data (can cross multiple page) + */ +static inline unsigned int gnttab_count_grant(unsigned int offset, + unsigned int len) +{ + return (XEN_PFN_UP((offset & ~XEN_PAGE_MASK) + len)); +} + #endif /* __ASM_GNTTAB_H__ */