Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2955171ybl; Thu, 29 Aug 2019 15:45:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVSppV1FJudg/bEahQjZYLlYV5fGHaoDtqm/Gp5HUE1PlcZETilxKag44ZpKWxj+P7ixPd X-Received: by 2002:a17:902:8348:: with SMTP id z8mr12803141pln.38.1567118707451; Thu, 29 Aug 2019 15:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567118707; cv=none; d=google.com; s=arc-20160816; b=v8q4Ax+K07OfUlaf7/Ef5rPDH5/zV3rmhpamaACVphIjwMxwSWW3ZACdAiiJl7G6ML q32PFrOjAr1iMvZ/VFWQTd7WFlIJOb0TEm1vkp88KQ41vt+yYUdqfdf4uxtq0jEtSHLk V7WL1HOEDe2oIW5AZXMuLFbwutaEAgVERvXecsaPbYN9OnlCf9fRKICC1h5XlXrqABzI 3n4O/DXJ4EmrcQHCsad/FhFP/ghhzJjdsBzXhdpEUemXZIlgLSrtbBpwd6vC9CpisbYr 8knLg77bQzKiS1yh6B1sz9CcwTvkOV2NBRJpI7cya185jTI377DAvA/1u+VGrsO80Gkx kIAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=4BWzlViPm8gCH7EbQY4FlmVAcRcHBvLofm0bzxYKq8w=; b=jCAsf8BLDhzfMEWRxZb08kZzR/NLXkjjbi9DtVwGeC9+LVu7FeNorVxrgOjj+n6P1s A3Ll1NDAFyGtZQjRXyZvg2J+T3xUfEEkIbBZUIXjUSoxZA063zYv5q5PYh7yyqrB+phO YSsyD9fw/vQsVqzEp5J9tevuG394sm3QIUHNVEb0seqMhaABLxYemhjmWUOnwtbGhlcr O8gxFGfHNNMy4x0+a/isYq5gwkbQgYkja4zh/ybm/7cCGAzCwYbt1tYxcitesAN1twen tYcNafTOVH6o4f9qZyxtcDLREQ0cIA1OY4mEA44tkTu5MP+VIOGRdNIXaM2lSUmOJFV5 r1sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1YN/3xio"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si3023673plp.4.2019.08.29.15.44.51; Thu, 29 Aug 2019 15:45:07 -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=@kernel.org header.s=default header.b="1YN/3xio"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728629AbfH2WmA (ORCPT + 99 others); Thu, 29 Aug 2019 18:42:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:57692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbfH2Wl7 (ORCPT ); Thu, 29 Aug 2019 18:41:59 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A31312189D; Thu, 29 Aug 2019 22:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567118519; bh=K4rt8zt90Kmj60EUr8Ldv/KP5AZNgIOkytellVQSzmc=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=1YN/3xioK/sOkd2EHLYyrqoX59ZRTxCvQ8FvQpisRpYOU/0fSb7JKuj23nCZQH6hu /RlPCh5ef2sQ3bgqTFLrsqntATI/sGsYVmmUrwpiJsHK6U8JdkHPxtUByH2AGJpzQ0 jVl7lnqoqH4YW8dX0danw5b7kBAaiscoagXBaJPM= Date: Thu, 29 Aug 2019 15:41:58 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Christoph Hellwig cc: Stefano Stabellini , Konrad Rzeszutek Wilk , x86@kernel.org, linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/11] xen/arm: simplify dma_cache_maint In-Reply-To: <20190826121944.515-4-hch@lst.de> Message-ID: References: <20190826121944.515-1-hch@lst.de> <20190826121944.515-4-hch@lst.de> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 26 Aug 2019, Christoph Hellwig wrote: > Calculate the required operation in the caller, and pass it directly > instead of recalculating it for each page, and use simple arithmetics > to get from the physical address to Xen page size aligned chunks. > > Signed-off-by: Christoph Hellwig > --- > arch/arm/xen/mm.c | 62 +++++++++++++++++------------------------------ > 1 file changed, 22 insertions(+), 40 deletions(-) > > diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c > index 90574d89d0d4..14210ebdea1a 100644 > --- a/arch/arm/xen/mm.c > +++ b/arch/arm/xen/mm.c > @@ -35,64 +35,46 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order) > return __get_free_pages(flags, order); > } > > -enum dma_cache_op { > - DMA_UNMAP, > - DMA_MAP, > -}; > static bool hypercall_cflush = false; > > -/* functions called by SWIOTLB */ > - > -static void dma_cache_maint(dma_addr_t handle, unsigned long offset, > - size_t size, enum dma_data_direction dir, enum dma_cache_op op) > +/* buffers in highmem or foreign pages cannot cross page boundaries */ > +static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op) > { > struct gnttab_cache_flush cflush; > - unsigned long xen_pfn; > - size_t left = size; > > - xen_pfn = (handle >> XEN_PAGE_SHIFT) + offset / XEN_PAGE_SIZE; > - offset %= XEN_PAGE_SIZE; > + cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK; > + cflush.offset = xen_offset_in_page(handle); > + cflush.op = op; > > do { > - size_t len = left; > - > - /* buffers in highmem or foreign pages cannot cross page > - * boundaries */ > - if (len + offset > XEN_PAGE_SIZE) > - len = XEN_PAGE_SIZE - offset; > - > - cflush.op = 0; > - cflush.a.dev_bus_addr = xen_pfn << XEN_PAGE_SHIFT; > - cflush.offset = offset; > - cflush.length = len; > - > - if (op == DMA_UNMAP && dir != DMA_TO_DEVICE) > - cflush.op = GNTTAB_CACHE_INVAL; > - if (op == DMA_MAP) { > - if (dir == DMA_FROM_DEVICE) > - cflush.op = GNTTAB_CACHE_INVAL; > - else > - cflush.op = GNTTAB_CACHE_CLEAN; > - } > - if (cflush.op) > - HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1); > + if (size + cflush.offset > XEN_PAGE_SIZE) > + cflush.length = XEN_PAGE_SIZE - cflush.offset; > + else > + cflush.length = size; isn't it missing a: cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK; here? > + HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1); > + > + handle += cflush.length; > + size -= cflush.length; > > - offset = 0; > - xen_pfn++; > - left -= len; > - } while (left); > + cflush.offset = 0; > + } while (size); > } > > static void __xen_dma_page_dev_to_cpu(struct device *hwdev, dma_addr_t handle, > size_t size, enum dma_data_direction dir) > { > - dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_UNMAP); > + if (dir != DMA_TO_DEVICE) > + dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); > } > > static void __xen_dma_page_cpu_to_dev(struct device *hwdev, dma_addr_t handle, > size_t size, enum dma_data_direction dir) > { > - dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_MAP); > + if (dir == DMA_FROM_DEVICE) > + dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); > + else > + dma_cache_maint(handle, size, GNTTAB_CACHE_CLEAN); > } > > void __xen_dma_map_page(struct device *hwdev, struct page *page, > -- > 2.20.1 >