Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp237599imm; Wed, 30 May 2018 22:38:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKc1CWA+WSCnah4LeSE21UfNfdXfDiVtQBmasKZQSV+UqAyzhujrra+eUk7us/gdF8Vwy2+ X-Received: by 2002:a63:ab45:: with SMTP id k5-v6mr4355085pgp.192.1527745117559; Wed, 30 May 2018 22:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527745117; cv=none; d=google.com; s=arc-20160816; b=mMb0hsugy6qL2J/yHdFuoW+j5h1wef30PSOnieeYE3ftz38DL5IU+uoa68Ivnb/xVt +8jPp/DMHCsE7kBMK5gAkLK1FDk2bn/QSNVPzkEtCMaKJnVBsWCQ2BNXCg0pCFinSbEt 5QVF9YVg0UG+eBzdQasGC5gAKoBIlDk7d45STXwgW0cH0t/AqTPJvQh9vxrnnwdPOrte vgtw/lY2acgvnIPYW89tIanPv4YC6O3+hbMoOFaYCHKbfh9ogx+VKFIS/IGhAWlDuitE e3YViBIkZXywjYGVW37jXhB2vW5uSL2TWZhT80Qxk72CEM7kk6dC+95sUlsEl/UUGEeE ibug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=DimH+M0ApywEGP0uZcwoNB0jgavwVUuMiHh++/jbRls=; b=Q+IGTJzCshrgW0sg/jQ945EMMi4d51zaX4kMrZ7Uwrx+iNl3LmCcVS3YfJJqyOYL4f 4Vys2/80Cuc3NK/QeQME31G+Ovosd4NxaZxREJ6Vj8sOGNSMsCH2U5wlF9H+FPFL9nhg SiGe77ub0cVKxzLsoUfY9FV3j+iqmjMOuOAobNeIvvcjNfjxBecgCZ00q3vXxjbSXDa9 r313bVjJwmXn7fR1Stl1iMMyWcLaj4X/1j7DZgezDtMC7Ee3bqrM6oFYwHbcNJc4sKvC KUhOHDA/ZD8Mq+suckP3Olj40A+dJXjUtxJtqTn85lzgZOVDsngJcDkPb7WRgub9gFWc XNdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MNF7B/t4; 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 o61-v6si14210542pld.109.2018.05.30.22.38.23; Wed, 30 May 2018 22:38:37 -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=MNF7B/t4; 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 S1753926AbeEaFhi (ORCPT + 99 others); Thu, 31 May 2018 01:37:38 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36225 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753895AbeEaFhg (ORCPT ); Thu, 31 May 2018 01:37:36 -0400 Received: by mail-lf0-f67.google.com with SMTP id u4-v6so7822576lff.3; Wed, 30 May 2018 22:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=DimH+M0ApywEGP0uZcwoNB0jgavwVUuMiHh++/jbRls=; b=MNF7B/t4PJn6uDcpPb8rxAyxxILZkZxUbTHE4/z3u1l1s4+x1Xh0mGOY6JK9QnGZBE dM45a0C/cto4CPw40LwEtiXKqh3pH/z2wNvWzJu6DEY/LGv2vUz5gXVeUVyMkzklEHEl 0me57KqN3CRA6J4GUUPvgqZASIN1WQEt4CGUBPNvrjiT52Gmjxg49BrgfgFPuyqm6g/B D5hbddrcefxYERiyMKuMOegDsiVbFxQBJYl17RTEyDsy0exSNQad65w1+m7lkijKDphd txtaSB2tcvLqDpzM4QJiDfKOr4PsUUVYezhtKK6iX7RLkMOWcsIs5UZrAvQHT0G3mRzb /K/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=DimH+M0ApywEGP0uZcwoNB0jgavwVUuMiHh++/jbRls=; b=sFfRr20crTy6pcTqejUhm3QTl+NBZuYRvWQC4IQVPZdOys1Z5B2i8JOM05kKI2BLrK HZlLOuwErd6ML8843rwjAup0sv7MrkRfGX2dq7xa5sh96H3FUKCkvpEDlA67kM5dI+SZ LS6l/9MV/hDWOgWQ6PUx/mCZnP5oygvzsZ8cubu/NjljqjGgUKGLrXn5kbhwze/c2P/R HHoEdUJ2SCBRGACZ9/kYQyoUYXbQIKlv94sXuw/voB9EGzoP5IPx6vCw0vb3Cg8hUgh2 P06oZY5gCVu3oqiZLxTljkxXRVMuHFtWx+d1s5+oGgBhUux9882ON+gyD8SYQLjiqrfk DS9w== X-Gm-Message-State: ALKqPwfnHu4tekT4Lsjn/uJPJDbeDnuOU0+iGO1Up+XXNQPZkwj2N+tq AtEoRRWIBHaDxFk78Mi8cks= X-Received: by 2002:a19:5701:: with SMTP id l1-v6mr3488505lfb.32.1527745054915; Wed, 30 May 2018 22:37:34 -0700 (PDT) Received: from [10.17.182.9] (ll-51.209.223.85.sovam.net.ua. [85.223.209.51]) by smtp.gmail.com with ESMTPSA id k5-v6sm7439937lji.39.2018.05.30.22.37.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 22:37:34 -0700 (PDT) Subject: Re: [PATCH 1/8] xen/grant-table: Make set/clear page private code shared To: Dongwon Kim 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 References: <20180525153331.31188-1-andr2000@gmail.com> <20180525153331.31188-2-andr2000@gmail.com> <20180530213416.GA3159@downor-Z87X-UD5H> From: Oleksandr Andrushchenko Message-ID: <3830bb6c-62e8-199a-aef3-59ccc0e59017@gmail.com> Date: Thu, 31 May 2018 08:37:32 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180530213416.GA3159@downor-Z87X-UD5H> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/31/2018 12:34 AM, Dongwon Kim wrote: > 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? gnttab_free_pages(nr_pages, pages); will take care of it when called from outside, see below. It can also handle partial allocations, so no problem here >> 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 >>