Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5357924imm; Tue, 12 Jun 2018 06:45:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKZ2KvfxE2cuB2r2a82fHoMRCQBUw977Qd/irzP8R8clF5Ap8qwZmh4f03uDHDc2IC5TwZH X-Received: by 2002:a62:d146:: with SMTP id t6-v6mr466784pfl.127.1528811122490; Tue, 12 Jun 2018 06:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528811122; cv=none; d=google.com; s=arc-20160816; b=MdWjxr0XcTKTeXUWSgbhkFpjkVzO+875nWiFDocmsJvfDP1q4049c5XO/QHu0fZHCG 5X583T9FZraXhob0ePkM+rvaNQkA3FqVwzaUcgdvCsKXhwgOy1HOUZ0LXrlFfVOS7MLX /j/pUoplw5i76zUPYEkc1U5vc1fhbqIgx5/ph4nnd+JWNuSQdqFqKEb9mfddP0eTF21s pCGDD3A4+gAyyQqtHigVcdXdb4XLOKmZ1mfvdOW7561xUBAl+2a2q1XMT9aBmBsjGw0T R9s2k8BYKg9oOsdq7hdbvdo2XPX9LIaTDJ5VuZSxWy2UnbU3RRlV2i4IvYZGfvJCYfW+ JTTw== 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=qn9DhGEWTMaawUxaGfYqOvXnzJRBZPC7KzIu0SJDlM8=; b=XbqzkOsz5hzPwo4JbuOFzaNzm+5UVy4BQYiJj9TAVsifh68jqUTvq8D2CcHoP1fS/M ZKRwRqTr7EZS/6qCb5JfYpR93FGAibPVByddV/ByofsNMAk9mJfZulXL4GbckKSvPv1v JdjGgrVtB4tAL8vQVDwcrhfBswJ0NiAQAHnGDDGdTh55jAd9jrm5wUCiqDxFxuvZPTrA YfuFmCRqU9SeBhSxg2LbFerypp00gSLlQxHGAFSfbMzfgPylqhverGQKOciqTkeTRuaF 97ZR+YeatJs5uQSLyTXaba2c0jZoHrWgUlH6OJZNrcIRJETolLRyBXzigcPy9iO5p77u 1ydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sjHDAbz9; 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 k7-v6si160866pgs.210.2018.06.12.06.45.07; Tue, 12 Jun 2018 06:45:22 -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=sjHDAbz9; 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 S934094AbeFLNoE (ORCPT + 99 others); Tue, 12 Jun 2018 09:44:04 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:43849 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933088AbeFLNmO (ORCPT ); Tue, 12 Jun 2018 09:42:14 -0400 Received: by mail-lf0-f68.google.com with SMTP id n15-v6so36077229lfn.10; Tue, 12 Jun 2018 06:42:13 -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=qn9DhGEWTMaawUxaGfYqOvXnzJRBZPC7KzIu0SJDlM8=; b=sjHDAbz9JtEc+rn5NO7EMFdyMajglohYTaXKZ9yMtAV6OGhYBu9AErOjQOLfZabetd n8BlFXlS3IV6IA5NjnhZ0wyqiLleSKln+gFMqqq/P6SW0LUzfFovfmwC8A2ZL618EARh AccRdJRsMyHcEkiCmxM2uI1w/ZyRYbgAuL0odMn4T0SRF4DyV3HEg1DECFj6hhwuQ3Dz cG+qJAN2kHraySbGJUIPmTuAxsTD6AM4Km8aP1kh31dP+cCNgx1mjbIfj43Ia7x0Tbf1 DHku11p4wLopOurOeoUYLLhg+pg8KA6FzyauQHoFMa7NZNn/dOjkRgdIFR+7gUso+ls5 uo8w== 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=qn9DhGEWTMaawUxaGfYqOvXnzJRBZPC7KzIu0SJDlM8=; b=EaT1ZtODoMTiWofKUn91eNhT+rb84YcEFz3tB0tUHeNCfztSlUOLKvVFoeBBo+h0V3 r23Alb6RxPK6x2QS5djcUCspxjGXSAxRAkkWhemZK9gRy6wR0YoPQs9EwEdfj6Q+z2Wg ZoRXs/bmvgdU4YLTqke7CdzbMiQbk1IhWaelbnAtV9LnZH7ahBdR/1EcTFjdSt06AT2m eNCbeTmWJLMbmLG7tCLUxP/hJ1zLUJMomBastkS6otUvoDpfmDVsXWLstMy6A2ogDzU1 E1zg8o4at7/Ge43Heeuip0JY2tTAEd6zPrv5or0jgmX5gHdWJcJWdFtDnTaLqtC+N73J zeGQ== X-Gm-Message-State: APt69E28hk0KsqkgBQnDl24P1PWd2FbXjkUttyiQjjaLbtzPwtpIPepo k6TXAi0iFNfzvez0vGCC3uE= X-Received: by 2002:a2e:458a:: with SMTP id s132-v6mr308287lja.92.1528810932047; Tue, 12 Jun 2018 06:42:12 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id x18-v6sm46692ljh.63.2018.06.12.06.42.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Jun 2018 06:42:11 -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 v3 2/9] xen/grant-table: Make set/clear page private code shared Date: Tue, 12 Jun 2018 16:41:53 +0300 Message-Id: <20180612134200.17456-3-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612134200.17456-1-andr2000@gmail.com> References: <20180612134200.17456-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 Reviewed-by: Boris Ostrovsky --- 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.1