Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3614319imm; Fri, 25 May 2018 08:37:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpojxEvs6LiKvQhgebfhW76PSYP9apkC6gIm446sM3qJ6pDlxO0ERKROHRIPBireRhFVGVg X-Received: by 2002:a17:902:3103:: with SMTP id w3-v6mr3053182plb.37.1527262631732; Fri, 25 May 2018 08:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527262631; cv=none; d=google.com; s=arc-20160816; b=qZohWgXk8n6xpt4Meqej9NnRIAiFCQCxh+5m/iz1tVb/yyoGWwKNREgWBztTU+BqrI MR6QzVlJ8a6lQQlq2UtAApE8qQY5ZqKnRnqpHfLbsBR3f4iPT+4fHzq0fnnj/xr1H8DW idZgaDwps/x7KZnje+KQ+gpFjg4EGowYvio1YGkWLIhCUL0rk9CMimB/zLd/rSlTO5o/ jAEBt26C5KTnT9X5OGPUiqc7XrQo7HqO/gunEIQ0KnegK9cOMnyIRZtLNyPgdVUGyW7D A9tPlQY/leu6++quShdW1yBMs1uIO8t4B/sCjq7otEl+I3ETmRI9a9FBLSv8Pf3Bn0fU eeuQ== 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=H7iRMq5lbO1ysDwxwM70K4srHvmE2bBWe8vDvEVa/f8=; b=dnBJXQaOPTZoW2VUVpocbyqVXt7mC53XuPO5Iflgl3WXu2ANMZROTIkaBESu79C8O8 iccD1QQ55pFQd32GDipndvPq0OyaJgCD0Sm3Cs+ivUzS2G3wogjlLub6ucXj17S8gaou Qzm0E8vyYBBXiSgTqgGUbnCBriaVcVzxH1K4bCLm8Lldz6BYqzELBFDIc8P6df0RHTvx jMdlmOBGYLddrRt+rhduZg888VZSA01H++tQc9P/CKwYZmdwzvuddvlcD7c5wwHRhyBe fWJYEcL2XtOBEZlvWjDDRRd00LRzJolxAx4t9T8djgCqFLp9S9pP/NJ/adtav81/Bp5x iNtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ELHkUiV8; 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 32-v6si24256700ple.319.2018.05.25.08.36.56; Fri, 25 May 2018 08:37:11 -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=ELHkUiV8; 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 S967014AbeEYPfa (ORCPT + 99 others); Fri, 25 May 2018 11:35:30 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:44658 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965440AbeEYPdp (ORCPT ); Fri, 25 May 2018 11:33:45 -0400 Received: by mail-wr0-f196.google.com with SMTP id y15-v6so9946146wrg.11; Fri, 25 May 2018 08:33:44 -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=H7iRMq5lbO1ysDwxwM70K4srHvmE2bBWe8vDvEVa/f8=; b=ELHkUiV8syd+93InxCf8o4CkmSTREw9pkt6IqvP0iyQT1LwOeV3bl7Oy7M13HylbOG UUL9bpSPw2AJWTzwms4SuUgO0ECG3txii9BX8kzDusXZZAxgxDQ9NOio+2KS6MFBs8n5 2g1kdFCzrpA7Y72mWGWtJ1ZMyLDwz7kdRDFf/MwoXNS9nOJrHeJUrteNgE/G50JGv7r/ 6GHLy/Gh89WQm/3uo6/LeCwsZNR10hl3QC6lSEzdC6lHnvT6TGVb2jnlLjGT8a8PyCSk e2IpxOgGd3wYuemo5WPSnZfxdf1bPie6Gt1NPaJs2ciV4PCiMy+LJDRyLHY1Y0Amwrm1 pDpw== 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=H7iRMq5lbO1ysDwxwM70K4srHvmE2bBWe8vDvEVa/f8=; b=PPmGMhirXEM7vf6LyjdZW1FYdBiSLVZKxhLNGGmOM1rqdciBNbI9jYeOaJi1iMFmwc wmIYrXyqhDtGWT/GdDmQhJTfeVfrE13ceZIpwnGHpRoxa1ETb0QOHZGIPSOK5O0160Tp aTt2Mjhz0ujVr4V4KPvi9zzPs0A6S9u1K02nYIrsEbRwQAW6bZTzz+AhjskGUzktpo0u 6amE8j8VdNSJ5E8b442/YQx5uaSapv6L3lAelBdvG8VPmlPzBIwyBGQDeS8EQGF2vKWj /I5IOtvy3Ia0gENys7ifyu67vArFIefD1D/Wk6G1L/P47NGfzxGryy4RFpEsiM0pJWl4 CJ6A== X-Gm-Message-State: ALKqPwdhgBql8AR7Vj6ogiLqVj6NVGoqB6sQTWZSK9moMxI7OL2ljMWa 6G6pBEFS7h0FqITS6LpsQUs= X-Received: by 2002:a19:eb4d:: with SMTP id j74-v6mr1816552lfh.1.1527262423940; Fri, 25 May 2018 08:33:43 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-54.209.223.85.sovam.net.ua. [85.223.209.54]) by smtp.gmail.com with ESMTPSA id l7-v6sm314231ljh.53.2018.05.25.08.33.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 May 2018 08:33:42 -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 1/8] xen/grant-table: Make set/clear page private code shared Date: Fri, 25 May 2018 18:33:24 +0300 Message-Id: <20180525153331.31188-2-andr2000@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180525153331.31188-1-andr2000@gmail.com> References: <20180525153331.31188-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 27be107d6480..d7488226e1f2 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(gnttab_alloc_pages); +EXPORT_SYMBOL(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(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(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(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