Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4907421imm; Wed, 30 May 2018 14:37:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLuBdQFjgriq4Q+Czb69K1SlWM563yETazQAZS/rbytxUTJiBdJQjVM30PT2T4p936iC6Eo X-Received: by 2002:a62:5281:: with SMTP id g123-v6mr4302138pfb.22.1527716253497; Wed, 30 May 2018 14:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527716253; cv=none; d=google.com; s=arc-20160816; b=SzxVi87xYQ+K5fcQeqFHVKgnE401DfESHIklqOzqMDL63QR4CZaph4HrhUdUyJKvYx kXHaMlcvidmGlrx+oixG620RJf0PE9jOl9FojfZcqzTAFm776MG8pCE/drndyqlTLy1y 2+c8Wwirmc1VW2Kx7HoVkQ+X5k+qXZsQ9uiXZkR6/FqIJ3JjXjnu+sG1a9Gu53GluGJi W0FGIQtktxF7k0GOogwTyVHz8cD41HQ5/0Tfdvn+l2DaW5dxwn1q1fwaf7iqk8lwXyjM b7Xl/COre5UrzeV4V436LkY8arLzhawVeftVrzMIRhcBz9tuoCpBJcG69TtOFsB5cibA fwPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=bmU8FIdflZOARWA0GURZHPRUhph0qFzaqI4Akp6EA/I=; b=0tJkYgkrR0CLre+d6pY5BcTR6ArcM4ksvP+CVgvm3p+4miZ4SjP8NbPohKob8RSeA9 XnPS4lFH1NVBBoqbF+b08A3Lj2tx5rdnHQnDkAVNnNOdOGwjy7zOAeaaKSRudD/Ck8hq gZVxhV5pFNetpVgBgjZKrXeh51T0OTr8pO1R5Z5Z3LO203emB045b5vhTA2IDLMEqVja BcqhiwNP2o6qtMwM18cQhUOZskGLgC+/rsfv67opRIR/HAMWy8SFnfp1EIkqS2Cfw40i vFbydXl4PkLzFKBClu2e4kclUmaGR0jUpnFufWkIn9EnK7UoZpk85HHQLkJ3MWakZF9z 3vVg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si7273019pgq.616.2018.05.30.14.37.19; Wed, 30 May 2018 14:37:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932414AbeE3Vgy (ORCPT + 99 others); Wed, 30 May 2018 17:36:54 -0400 Received: from mga18.intel.com ([134.134.136.126]:31647 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932222AbeE3Vgx (ORCPT ); Wed, 30 May 2018 17:36:53 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2018 14:36:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,461,1520924400"; d="scan'208";a="60455712" Received: from downor-z87x-ud5h.fm.intel.com (HELO downor-Z87X-UD5H) ([10.1.122.107]) by orsmga001.jf.intel.com with ESMTP; 30 May 2018 14:36:52 -0700 Date: Wed, 30 May 2018 14:34:16 -0700 From: Dongwon Kim To: Oleksandr Andrushchenko Cc: 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, daniel.vetter@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko Subject: Re: [PATCH 1/8] xen/grant-table: Make set/clear page private code shared Message-ID: <20180530213416.GA3159@downor-Z87X-UD5H> References: <20180525153331.31188-1-andr2000@gmail.com> <20180525153331.31188-2-andr2000@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180525153331.31188-2-andr2000@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 25, 2018 at 06:33:24PM +0300, Oleksandr Andrushchenko wrote: > 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) Don't we have to free previously allocated "foreign"(s) if it fails in the middle (e.g. 0 < i && i < nr_pages - 1) before returning? > 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 >