Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4732085imm; Wed, 30 May 2018 10:51:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI3UjUX6CO5/CCRw5oXF0HmGTasvc35P/rlgse8lzjG1QrI9KJUphBLrOyn32z6qZttEfgW X-Received: by 2002:a63:7043:: with SMTP id a3-v6mr2955857pgn.206.1527702686179; Wed, 30 May 2018 10:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527702686; cv=none; d=google.com; s=arc-20160816; b=squL5pLgavFszz8IWv+YStmQAR65Ou2EVpUL/iGBlLy3Qk2/OPPb5F98GWi8POCPxV txLFeTWMnkbRCAQ1Y3cOPX6x95+b7gYadzG0j6WaVYQnI30rXRJ2qv1UBNty4tMxLz/1 OUy0e6lBypuvlqr8oV2/UDyRFM/3uFHIJgCuQKg5mvUybCfvnUkdEv+DSBE3uSksME+r abwUqi7TdkSSpJn6C+6nM7z2AiRK3BhnWavPbAZMya+aIUXhedqHAVGmTNSGesdii1qd eXQ9sZEKGWOCB6BsvYth86ZYaMAUnqw/nLiXXIV8XZqxXI2+XG0FYckm6aRyfMVT8A/B VVgw== 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=eSxIq97LasrisOf5RMelI068T+dB5rS70rpyjaca8nc=; b=hbQK2YkH+ZE98xZu+51T/EVdJmnAXEYL8wbbMNNAiuiTiiFxYq99HxFdNyQ/ip9D+d jJDpCOMdJTXiNgUXcgPVqy5NxCM8EQBlPV9f5p77oSXhk9T9gINRiVdyhpnLTxk2kSNw qVOo5JFWLqQTNKiQ0pC2+KOoXrGUTy62nEtefkmhCOD4OazZxJEFaqhuQE1VPfYA9MFI ceUsWbIKeccbB0ymqKlynL+CjbiNaglFNDDGcDbIhTnbUd9hNk9+GgVzBqlz0fmw4dSh W8rW054RTWVS6pORLAUuKppacnzBdw97sG5LBylY86qnTwk+nNSAx48YvJVuzmLhdgxs rvtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TwVZB0pi; 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 o89-v6si10079022pfi.165.2018.05.30.10.51.12; Wed, 30 May 2018 10:51:26 -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=TwVZB0pi; 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 S1753759AbeE3RtR (ORCPT + 99 others); Wed, 30 May 2018 13:49:17 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:38270 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753651AbeE3RtP (ORCPT ); Wed, 30 May 2018 13:49:15 -0400 Received: by mail-lf0-f68.google.com with SMTP id z142-v6so5614779lff.5; Wed, 30 May 2018 10:49:14 -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=eSxIq97LasrisOf5RMelI068T+dB5rS70rpyjaca8nc=; b=TwVZB0pii7rA0/oWqgPnzDEcRdy4NugLwyc5j+72jxV++Izm7vRhna6GLKvIp64uEy sD3LQyGc3O8qFk7ePAfXFPRQKInyA5R+EgnOQuhX5ZauZLBnMab3xGxSNYxrY+zM3XkV iDm/e0e4tu+bZU0oLcBCP+XfsE74PkkXBcawjWMhnjj1HdAyTmxPllNYkQAwEPRP6dbf 3M9uX4v4baRZk/oOraJysdo/snah87ptJ/nxmm0fnICYgsYr4NjkQc4ighHWAe9USL49 QPi02F4CwlYlrjIlNptAjkbsaB0cBMTR4ZK1w3oKOnJlpzhUlrJk2xIg8enPZ+88UktZ AxNA== 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=eSxIq97LasrisOf5RMelI068T+dB5rS70rpyjaca8nc=; b=Lt+VwQ5RAoQqigSHaCR39eTw0d80254G/OTC4qVGtJhGaVcLNU1cX5NpZ4yh5Y3POT 0J4PEpF+SI9Bq9964QoqmSy2OXvqmSgtwo7qIhJrAO9b6TKPD81OCIHVcBY7Etx3aZ3y slaaH0QNo+YYky7Hu/tHvUKg3NM5al2zp9P9V7XdjgruwN8wbw9EydbDEw8M4pJ9nx/P skIhjQ6ahd1HUIP4LT0HGaoP8EAcDBHDnCDrIao6CfJfjnEzOI3cR5ku3tLMAGiPZeQQ DwrV9Z1IbZjfjBgUeha2/azzhqqDhw1UYPIF4VkjZCxi0erfEfXc7ju7P2B4J3nixvIE ANGg== X-Gm-Message-State: ALKqPwfxAd8e0rjBrki/Q7JqhDQiaBAWNY1CCB5nEaMxqSkLNwnPtdpX 3dj7N/pg8bZZTa3ttlUrdRA= X-Received: by 2002:a2e:2b51:: with SMTP id q78-v6mr2793839lje.119.1527702553403; Wed, 30 May 2018 10:49:13 -0700 (PDT) Received: from [192.168.0.20] (39-55-94-178.pool.ukrtel.net. [178.94.55.39]) by smtp.googlemail.com with ESMTPSA id u11-v6sm7194720lju.76.2018.05.30.10.49.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 10:49:12 -0700 (PDT) Subject: Re: [PATCH 3/8] xen/grant-table: Allow allocating buffers suitable for DMA To: Boris Ostrovsky , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, jgross@suse.com, konrad.wilk@oracle.com Cc: daniel.vetter@intel.com, dongwon.kim@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko References: <20180525153331.31188-1-andr2000@gmail.com> <20180525153331.31188-4-andr2000@gmail.com> <94de6bd7-405c-c43f-0468-be71efff7552@oracle.com> From: Oleksandr Andrushchenko Message-ID: <5e6e0f5d-a417-676a-1aad-c51eb09e6dee@gmail.com> Date: Wed, 30 May 2018 20:49:11 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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/30/2018 06:20 PM, Boris Ostrovsky wrote: > On 05/30/2018 02:34 AM, Oleksandr Andrushchenko wrote: >> On 05/29/2018 10:10 PM, Boris Ostrovsky wrote: >>> On 05/25/2018 11:33 AM, Oleksandr Andrushchenko wrote: >>> +/** >>> + * gnttab_dma_free_pages - free DMAable pages >>> + * @args: arguments to the function >>> + */ >>> +int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) >>> +{ >>> +    xen_pfn_t *frames; >>> +    size_t size; >>> +    int i, ret; >>> + >>> +    gnttab_pages_clear_private(args->nr_pages, args->pages); >>> + >>> +    frames = kcalloc(args->nr_pages, sizeof(*frames), GFP_KERNEL); >>> >>> Any way you can do it without allocating memory? One possibility is to >>> keep allocated frames from gnttab_dma_alloc_pages(). (Not sure I like >>> that either but it's the only thing I can think of). >> Yes, I was also thinking about storing the allocated frames array from >> gnttab_dma_alloc_pages(), but that seemed not to be clear enough as >> the caller of the gnttab_dma_alloc_pages will need to store those frames >> in some context, so we can pass them on free. But the caller doesn't >> really >> need the frames which might confuse, so I decided to make those >> allocations >> on the fly. >> But I can still rework that to store the frames if you insist: please >> let me know. > > I would prefer not to allocate anything in the release path. Yes, I > realize that dragging frames array around is not necessary but IMO it's > better than potentially failing an allocation during a teardown. A > comment in the struct definition could explain the reason for having > this field. Then I would suggest we have it this way: current API requires that struct page **pages are allocated from outside. So, let's allocate the frames from outside as well. This way the caller is responsible for both pages and frames arrays and API looks consistent. > >>> >>>> +    if (!frames) >>>> +        return -ENOMEM; >>>> + >>>> +    for (i = 0; i < args->nr_pages; i++) >>>> +        frames[i] = page_to_xen_pfn(args->pages[i]); >>> Not xen_page_to_gfn()? >> Well, according to [1] it should be : >>     /* XENMEM_populate_physmap requires a PFN based on Xen >>      * granularity. >>      */ >>     frame_list[i] = page_to_xen_pfn(page); > > Ah, yes. I was looking at decrease_reservation and automatically assumed > the same parameter type. Good, then this one is resolved > > -boris > > Thank you, Oleksandr