Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp219545imm; Thu, 26 Jul 2018 02:14:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe7LD5DzebKYS59lUUV/uNLfUbU1of1/6LUdaroQGOEyL1E7HOsq5uR4Ms33baDhHS23BO9 X-Received: by 2002:a62:5047:: with SMTP id e68-v6mr1270093pfb.157.1532596496826; Thu, 26 Jul 2018 02:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532596496; cv=none; d=google.com; s=arc-20160816; b=xuSDbicb0QTQNFrM8i9u5+4y8zoyMryhL8POT45rrWe0QFUqS5WtgvKpz+AyNSyng1 l7kxr5KnNzIjLR6qnL96bLFJ3LNLZKT1ROiamUcJYtP+3D3KL+LZkKESbdJIVJ8yFqOS c0UmIoAZ7CxJq10jnR/F/P8JWY/bQKj9OiOFpDTGr824agIMkuCdIodF/YjP2dTZSVBo q3bnPjhn+6M9My1U886fodpysrdWbtIG/IvOGoVKGnQVd7bx3mXYTdvo/iqngv53s+gn L2h+51ZmBHfJC/tJ6u+bYl5fCrCKgApyUvyxq6SfSOozV6NxGOzG9nsXAY4DTQRPJEhQ wY4A== 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=ZxVj8ldNzhGcahVourk1+Rk4Swm9tUghLyvrUPcxxQk=; b=JpRMWbODoGu4wFfZ2bEjb6PuSJ3KN/VnByQn1C9AlfI+CdKOpUQjYtDPZ0OYhmJQ3j ZcVEjwhFD1xGF1azph5miNuGdRtpWcqm+0iKXDZNA8e3ECZYSAJRomLayGFw7wRK2jhu DqF1zRWO2rMr8d7b0aVRiMOsORbEqdOsvhprE3bHZCtp80/l53zZlH380OVvPeYZJKc1 LtI/OnyM2lq3zeXMKL+H79sobm50mYYHUkhyG13op6LsCOE2K23tCViN5LZLhdqTDJK3 nkzAf5f90Bv3lOZLa6UqH78wsM/74K/1Z8aacHdh5RZNljYdwmqOGklcy/nNyUiumQ0q pZVA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d191-v6si934278pga.157.2018.07.26.02.14.42; Thu, 26 Jul 2018 02:14:56 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729103AbeGZK3n (ORCPT + 99 others); Thu, 26 Jul 2018 06:29:43 -0400 Received: from verein.lst.de ([213.95.11.211]:35518 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728600AbeGZK3n (ORCPT ); Thu, 26 Jul 2018 06:29:43 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 1B68D68D64; Thu, 26 Jul 2018 11:17:32 +0200 (CEST) Date: Thu, 26 Jul 2018 11:17:32 +0200 From: Christoph Hellwig To: Eugeniy Paltsev Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Vineet Gupta , Alexey Brodkin , hch@lst.de Subject: Re: [PATCH 3/4] ARC: refactor arch/arc/mm/dma.c Message-ID: <20180726091731.GC24209@lst.de> References: <20180724101001.31965-1-Eugeniy.Paltsev@synopsys.com> <20180724101001.31965-4-Eugeniy.Paltsev@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180724101001.31965-4-Eugeniy.Paltsev@synopsys.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 24, 2018 at 01:10:00PM +0300, Eugeniy Paltsev wrote: > Refactoring, no functional change intended. Might be worth explaining a bit why you are refactoring it (i.e. what is the benefit). > > Signed-off-by: Eugeniy Paltsev > --- > arch/arc/mm/dma.c | 28 ++++++++++------------------ > 1 file changed, 10 insertions(+), 18 deletions(-) > > diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c > index b693818cd8e5..46584c7c2858 100644 > --- a/arch/arc/mm/dma.c > +++ b/arch/arc/mm/dma.c > @@ -27,30 +27,24 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > struct page *page; > phys_addr_t paddr; > void *kvaddr; > - int need_coh = 1, need_kvaddr = 0; > + bool need_coh = !(attrs & DMA_ATTR_NON_CONSISTENT); > > page = alloc_pages(gfp, order); > if (!page) > return NULL; > > /* This is linear addr (0x8000_0000 based) */ > paddr = page_to_phys(page); > > *dma_handle = paddr; > > + /* > + * - A coherent buffer needs MMU mapping to enforce non-cachability > + * - A highmem page needs a virtual handle (hence MMU mapping) > + * independent of cachability. > + * kvaddr is kernel Virtual address (0x7000_0000 based) > + */ > + if (PageHighMem(page) || need_coh) { dma_alloc_attrs clears __GFP_HIGHMEM from the passed in gfp mask, so you'll never get a highmem page here. That also means you can merge this conditional with the one for the cache writeback and invalidation and kill the need_coh flag entirely. > kvaddr = ioremap_nocache(paddr, size); > if (kvaddr == NULL) { > __free_pages(page, order); > @@ -81,11 +75,9 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr, > { > phys_addr_t paddr = dma_handle; > struct page *page = virt_to_page(paddr); > - int is_non_coh = 1; > - > - is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT); > + bool is_coh = !(attrs & DMA_ATTR_NON_CONSISTENT); > > - if (PageHighMem(page) || !is_non_coh) > + if (PageHighMem(page) || is_coh) > iounmap((void __force __iomem *)vaddr); > Same here. Also if you clean this up it would be great to take the per-device pfn offset into account, even if that isn't used anywhere on arc yet, that is call phys_to_dma and dma_to_phys to convert to an from the dma address.