Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp7252449imm; Sun, 20 May 2018 22:46:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpuWxwomRKUZ3SL8wcPxVBP6tXmCLpxWAvNoOf8wA7yVWeDskl8VyysfesTXtb2VLXAy2X/ X-Received: by 2002:a62:4589:: with SMTP id n9-v6mr18672866pfi.158.1526881595826; Sun, 20 May 2018 22:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526881595; cv=none; d=google.com; s=arc-20160816; b=Xc+YWAJQqhPKhoauOPCfxEf92v/nHYjkQZhfX0Mvi4IKYb7urpVAA626UvQNIvAnHz +jpMaFeGMu4/kO9RrpGJf6XcsF0wNfJA+yk+V/9eKIpHMynF1wI3YzQN2gARKaq5ttsD hWJzFecGDvvB83ls6WElBonaOocNgK7wNf/DLZOqnW/WjThC8kTyNjyx1BHRYCbU9wTu 0D1GYYJWh+ndeTBg6ucPHqRsL3Tenw/7+4n261GDE9UixWekWtFnJF9FHl+z1rivxW8g batiQAY/QEMVgZiYK7aDFejYLpg7g9lzmiZJuvOAjZfqlBo6W9vG6qcoxBiGNCkDKBi6 VRtw== 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=RXFebNXaRJD4TVWNJs4cV4PPBlVubsJOqtKaQt8wcMs=; b=rPuAi/ngiK2yYwX0kzHw/pzNdRCXFB3iM5zXtNiXJ9vvk403I1V2V+FDq8WrE85y1b BRQpwkEgYw1ht3y0BOGh16pZIABvFdvmzk6tWA0R0hSgzakQ3oN9XIbZBCaIPtLxv33x mY9S6mnRazVm/wOAx3zOcUq0UjXe5tbWCqV1mn5YAuYussu5Kz6CZ7gU3fB4kskVwS5L vs4IcpNBLFrfl82MSrySc66zW/SnraanEp4wXuyFEMwx+SqN+ORmpjPzjxfQ/JG44v1i 651bvSvT25ublp+lVligAlqunCsQErUn0yUhctFVl+W3xxWTTiiON/66097orrJrEEoi IcGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QrhPblky; 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 f9-v6si10527837pgt.625.2018.05.20.22.46.21; Sun, 20 May 2018 22:46:35 -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=QrhPblky; 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 S1751574AbeEUFoy (ORCPT + 99 others); Mon, 21 May 2018 01:44:54 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36108 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbeEUFop (ORCPT ); Mon, 21 May 2018 01:44:45 -0400 Received: by mail-lf0-f68.google.com with SMTP id e9-v6so5173456lfb.3; Sun, 20 May 2018 22:44:43 -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=RXFebNXaRJD4TVWNJs4cV4PPBlVubsJOqtKaQt8wcMs=; b=QrhPblkyUqQ7xzPQ8a9uC0Mpr0yo1Md2S8oLRDtdAiDQzM+XKzF5ccKrjqQ2Es/pWb fg3WRZNwtzF1MFCBE5xg892+q6fuzY6jxuqW737KgHO59eeIlPqHeqiPcWbwmFqHGmP7 bA2CI9HEtRHZnnlATcr4GpQ0gTJnHl7kgEGzb65YcuV7enKTeZxh8ZmrYJaCn9OAs4zr 6pZXZzvdaIXRTmojxsvbxYKw91vl2hUqRa/TNmqeTd5LZNpIhOR993jTJ7v9vj09KsOL ttanZrTtrp1CkljGjHP5C4Cd1cykjZCUsKmPrzZPkTWIdBs6dfuRPqlqlB5+Ta62ZIYu 3UFA== 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=RXFebNXaRJD4TVWNJs4cV4PPBlVubsJOqtKaQt8wcMs=; b=Nko9hOfSsvRTBOsux1gbGWFvr41XKq1kOTP9qyHqiRyGt3joW+6e3NQL9fLvcOtTRg D37mq7ADtGkN+20YlBI1YC4ocg8QJaoEOdk2zgTkQXRBnwG5gOQv8kUT9oevzr5c8t4u +m5YuiIyF7STyWVO4m/v9qKaBMrBrDlbdF+AOVkja3AlgSfIBnJEBwdY2NGM1JIrScDG O/ILFaNN7SouvBiiyXuqZoIv5zlRW4I91mtVNigLWXd0EkaGscEi/5MWTVuQKdbicPKS io/rEhhhi1l/RgZsbMw+UaSz7HKU4FrEE29wd0uxJKfy80cIs9vj9Fc468ZtZ4mwuhqH TXxw== X-Gm-Message-State: ALKqPwc14K7xXTiD2/ErJG4aZ0TLRUrbz4hwAW0Q+EYCOhsjtGxEsy9I dDD7KlFSbu+BFYpDrP5cxAM= X-Received: by 2002:a19:a08a:: with SMTP id j132-v6mr6547534lfe.117.1526881482936; Sun, 20 May 2018 22:44:42 -0700 (PDT) Received: from [10.17.182.9] (ll-52.209.223.85.sovam.net.ua. [85.223.209.52]) by smtp.gmail.com with ESMTPSA id p18-v6sm3028904lfd.91.2018.05.20.22.44.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 22:44:42 -0700 (PDT) Subject: Re: [Xen-devel][RFC 2/3] xen/grant-table: Extend API to work with DMA buffers 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: <20180517082604.14828-1-andr2000@gmail.com> <20180517082604.14828-3-andr2000@gmail.com> <28532709-6c87-f048-be6a-3c4ba02ae56f@oracle.com> From: Oleksandr Andrushchenko Message-ID: <097da8bd-2cfc-0916-451d-dec3e4d2a52e@gmail.com> Date: Mon, 21 May 2018 08:44:40 +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: <28532709-6c87-f048-be6a-3c4ba02ae56f@oracle.com> 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/19/2018 01:19 AM, Boris Ostrovsky wrote: > On 05/17/2018 04:26 AM, Oleksandr Andrushchenko wrote: >> From: Oleksandr Andrushchenko >> >> Signed-off-by: Oleksandr Andrushchenko >> --- >> drivers/xen/grant-table.c | 49 +++++++++++++++++++++++++++++++++++++++ >> include/xen/grant_table.h | 7 ++++++ >> 2 files changed, 56 insertions(+) >> >> diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c >> index bb36b1e1dbcc..c27bcc420575 100644 >> --- a/drivers/xen/grant-table.c >> +++ b/drivers/xen/grant-table.c >> @@ -729,6 +729,55 @@ void gnttab_free_pages(int nr_pages, struct page **pages) >> } >> EXPORT_SYMBOL(gnttab_free_pages); >> >> +int gnttab_dma_alloc_pages(struct device *dev, bool coherent, >> + int nr_pages, struct page **pages, >> + void **vaddr, dma_addr_t *dev_bus_addr) >> +{ >> + int i; >> + int ret; >> + >> + ret = alloc_dma_xenballooned_pages(dev, coherent, nr_pages, pages, >> + vaddr, dev_bus_addr); >> + 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_dma_free_pages(dev, flags, nr_pages, pages, >> + *vaddr, *dev_bus_addr); >> + return -ENOMEM; >> + } >> + set_page_private(pages[i], (unsigned long)foreign); >> +#endif >> + SetPagePrivate(pages[i]); >> + } >> + return 0; >> +} >> +EXPORT_SYMBOL(gnttab_dma_alloc_pages); >> + >> +void gnttab_dma_free_pages(struct device *dev, bool coherent, >> + int nr_pages, struct page **pages, >> + void *vaddr, dma_addr_t dev_bus_addr) >> +{ >> + int i; >> + >> + for (i = 0; i < nr_pages; i++) { >> + if (PagePrivate(pages[i])) { >> +#if BITS_PER_LONG < 64 >> + kfree((void *)page_private(pages[i])); >> +#endif >> + ClearPagePrivate(pages[i]); >> + } >> + } >> + free_dma_xenballooned_pages(dev, coherent, nr_pages, pages, >> + vaddr, dev_bus_addr); >> +} >> +EXPORT_SYMBOL(gnttab_dma_free_pages); > > Given that these routines look almost exactly like their non-dma > counterparts I wonder whether common code could be factored out. Yes, this can be done > -boris > > > > >> + >> /* Handling of paged out grant targets (GNTST_eagain) */ >> #define MAX_DELAY 256 >> static inline void >> diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h >> index 34b1379f9777..20ee2b5ba965 100644 >> --- a/include/xen/grant_table.h >> +++ b/include/xen/grant_table.h >> @@ -195,6 +195,13 @@ 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_dma_alloc_pages(struct device *dev, bool coherent, >> + int nr_pages, struct page **pages, >> + void **vaddr, dma_addr_t *dev_bus_addr); >> +void gnttab_dma_free_pages(struct device *dev, bool coherent, >> + int nr_pages, struct page **pages, >> + void *vaddr, dma_addr_t dev_bus_addr); >> + >> int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, >> struct gnttab_map_grant_ref *kmap_ops, >> struct page **pages, unsigned int count);