Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp488286imm; Fri, 1 Jun 2018 04:42:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL5G4S7vVEOVBe4hnJtyzyCEqYPvjdPJJxqDc/QAnAaqVCvdqXGUFCatPfy43N6lyMm+kUG X-Received: by 2002:a17:902:8a82:: with SMTP id p2-v6mr10805545plo.244.1527853362453; Fri, 01 Jun 2018 04:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527853362; cv=none; d=google.com; s=arc-20160816; b=cHx0atQ/NXO4y0q3LtYzvRB7ijdEhxp4IhgMUbIzpQnGd6mElIPa2uZPbfNIBecUFV s1cC5F9JfuyXT8goKSi0W/21D/g+gw64NAgSrdKhdzn7W6E62NK54sRxVcGl364P6L8h YminWX19jVLlPrGaryVw+bfgyfvDwMbqCUuWXXh29MkQowBYjp2xWTrhwoQNz7uAsHzV 3tFUJBw1A8i6NXT/B3PA6GgB8fHLPsrbekK/oKkQtl9a8NNtkpDqaCM0a1DeuD/LVIXe DpBx63FtGQqp1NHlFQML5EjrK6XU3qH5bjbX3/ELva+FDQAg+VlNoTMEyj/yXkA1CSDa KyoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vtHFiDNGGtjlWrxz5EWCbD9iQlUQUB7tfabW3cGbFFQ=; b=Ht68IcUvxoBtcC6pav2lpEHCE6ob/sOTdsMIDuGvdbzjneSHbDTsUpsH3E/jqce5xO D+hIFH7FoeIXTtKqmaE4DwrV1HMzdUbCJYfrtQQl5E4kPMZpAxHuMmKnY3Ki4Tu8rM4t GFg/Yy4QWBzRdutPEADVjtcsscgsA+EHrujL27nlrLjWhZm5nKU3KADbty7KukNMrN4o xenKEAffd9vGNinbL1f6lonZfkTrI8on+T5Ms8zHSu48/QtADMNIRxTj+QB3h6BSpTPC Er7P9L3iZaSLfpbi/s5+dDFd9Wpc2wdyrIceV1Dttu7p4xfgOQpQhzGntqnclQlgrX7g Rwqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ip/6cOzt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189-v6si2649387pga.107.2018.06.01.04.42.28; Fri, 01 Jun 2018 04:42:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ip/6cOzt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751929AbeFALlu (ORCPT + 99 others); Fri, 1 Jun 2018 07:41:50 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:43549 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092AbeFALlo (ORCPT ); Fri, 1 Jun 2018 07:41:44 -0400 Received: by mail-lf0-f68.google.com with SMTP id n18-v6so14356708lfh.10; Fri, 01 Jun 2018 04:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vtHFiDNGGtjlWrxz5EWCbD9iQlUQUB7tfabW3cGbFFQ=; b=ip/6cOzt66yrkmf1t9otki8Hx3wS2emUVUek1OI/kGlMNWij5egysQvK/mEvOG79X5 pPoUIs5cnUw8dUKJ5GNqH7NG8JJiNEXMroyOaFlzOwMY+a9n+3PWGl+15SQ6HUZ2+FC0 dva3atqybkFFdL+mcaWgS21gc3jRTzcLKWlOtdWEbA7P+PhTemsjCz5s+teIsm5hxXI/ 3ZE/IofdNc/8vjqz/1+cj7YnkWdzggfHZY+M2kdsxClGbtqO91MYLImlFrch2qv/ZH4q ThVumjNMwoVFxTO9Y02S1j1hPpE/RonVJoP4llzndJNfb8qJsAJOcmtIMq6ds1Piwu5p t1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vtHFiDNGGtjlWrxz5EWCbD9iQlUQUB7tfabW3cGbFFQ=; b=io3+kuYQf4OcEzoTtvhm/iUFTB38KsFmymaaJdqVST4+RJj+liOHncHQ77Kw3Al48v lP9NR7x+bjm/FtJbRBMsaMPZ1ARcoI0BCZ9flkbwBJt0ckUOlen+0sjS8v9md9OrZakU CeeknkkcE7jEDX+9CmPkGkIleJT2povxm9WS7bgxALv4wTjzRXvFmQBgby5LIGRPZA9g 2Yh+z5SzQC5DyJy1TdjVOk39N8HDb/VYn9gLRzq2fqLypvDtaiOXpyDyC3F8IX2Xxnh/ Uu8K+67KgJgY07qXPI8COgllmr30Gi6mZDQ84VyToOzoGBwDCGB/2luVhRmhRBI+5YRf sLAQ== X-Gm-Message-State: APt69E24wtVTzJ7gViR6vCq1Fb2ThignzUmDax+LSPf9HmZOwdgLnMiT kGoG5UjzbLXOXfJdZkH/gXw= X-Received: by 2002:a2e:8151:: with SMTP id t17-v6mr528204ljg.32.1527853302668; Fri, 01 Jun 2018 04:41:42 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-51.209.223.85.sovam.net.ua. [85.223.209.51]) by smtp.gmail.com with ESMTPSA id c6-v6sm8066280lja.22.2018.06.01.04.41.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Jun 2018 04:41:41 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: daniel.vetter@intel.com, andr2000@gmail.com, dongwon.kim@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko Subject: [PATCH v2 2/9] xen/grant-table: Make set/clear page private code shared Date: Fri, 1 Jun 2018 14:41:25 +0300 Message-Id: <20180601114132.22596-3-andr2000@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601114132.22596-1-andr2000@gmail.com> References: <20180601114132.22596-1-andr2000@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Andrushchenko Make set/clear page private code shared and accessible to other kernel modules which can re-use these instead of open-coding. Signed-off-by: Oleksandr Andrushchenko --- drivers/xen/grant-table.c | 54 +++++++++++++++++++++++++-------------- include/xen/grant_table.h | 3 +++ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index ba36ff3e4903..dbb48a89e987 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -769,29 +769,18 @@ void gnttab_free_auto_xlat_frames(void) } EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames); -/** - * gnttab_alloc_pages - alloc pages suitable for grant mapping into - * @nr_pages: number of pages to alloc - * @pages: returns the pages - */ -int gnttab_alloc_pages(int nr_pages, struct page **pages) +int gnttab_pages_set_private(int nr_pages, struct page **pages) { int i; - int ret; - - ret = alloc_xenballooned_pages(nr_pages, pages); - if (ret < 0) - return ret; for (i = 0; i < nr_pages; i++) { #if BITS_PER_LONG < 64 struct xen_page_foreign *foreign; foreign = kzalloc(sizeof(*foreign), GFP_KERNEL); - if (!foreign) { - gnttab_free_pages(nr_pages, pages); + if (!foreign) return -ENOMEM; - } + set_page_private(pages[i], (unsigned long)foreign); #endif SetPagePrivate(pages[i]); @@ -799,14 +788,30 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) return 0; } -EXPORT_SYMBOL_GPL(gnttab_alloc_pages); +EXPORT_SYMBOL_GPL(gnttab_pages_set_private); /** - * gnttab_free_pages - free pages allocated by gnttab_alloc_pages() - * @nr_pages; number of pages to free - * @pages: the pages + * gnttab_alloc_pages - alloc pages suitable for grant mapping into + * @nr_pages: number of pages to alloc + * @pages: returns the pages */ -void gnttab_free_pages(int nr_pages, struct page **pages) +int gnttab_alloc_pages(int nr_pages, struct page **pages) +{ + int ret; + + ret = alloc_xenballooned_pages(nr_pages, pages); + if (ret < 0) + return ret; + + ret = gnttab_pages_set_private(nr_pages, pages); + if (ret < 0) + gnttab_free_pages(nr_pages, pages); + + return ret; +} +EXPORT_SYMBOL_GPL(gnttab_alloc_pages); + +void gnttab_pages_clear_private(int nr_pages, struct page **pages) { int i; @@ -818,6 +823,17 @@ void gnttab_free_pages(int nr_pages, struct page **pages) ClearPagePrivate(pages[i]); } } +} +EXPORT_SYMBOL_GPL(gnttab_pages_clear_private); + +/** + * gnttab_free_pages - free pages allocated by gnttab_alloc_pages() + * @nr_pages; number of pages to free + * @pages: the pages + */ +void gnttab_free_pages(int nr_pages, struct page **pages) +{ + gnttab_pages_clear_private(nr_pages, pages); free_xenballooned_pages(nr_pages, pages); } EXPORT_SYMBOL_GPL(gnttab_free_pages); diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h index 2e37741f6b8d..de03f2542bb7 100644 --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h @@ -198,6 +198,9 @@ void gnttab_free_auto_xlat_frames(void); int gnttab_alloc_pages(int nr_pages, struct page **pages); void gnttab_free_pages(int nr_pages, struct page **pages); +int gnttab_pages_set_private(int nr_pages, struct page **pages); +void gnttab_pages_clear_private(int nr_pages, struct page **pages); + int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, struct gnttab_map_grant_ref *kmap_ops, struct page **pages, unsigned int count); -- 2.17.0