Received: by 10.223.164.200 with SMTP id h8csp926072wrb; Mon, 6 Nov 2017 01:05:53 -0800 (PST) X-Google-Smtp-Source: ABhQp+Rk/8EkPd1ompg9HHq/yzWrpeAdPPXYEeSdJGgLLtkXgnz8sW1w8ypw7QSrwD0QqhmKURix X-Received: by 10.99.107.6 with SMTP id g6mr14871562pgc.215.1509959153193; Mon, 06 Nov 2017 01:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509959153; cv=none; d=google.com; s=arc-20160816; b=KKm8NfWqzf9eIM4hgkzQepZ1HbJImh3zWmc3yuFrGtr138IT2ToTqPRKsXsEzUjtA3 2uir3jD/2WeAeF6uTrTTs6uJbB5wkH6tYI17EQLPk5AbJ3YOXweU67/E0G7Nd4JWd/By lzaxSykCOL0KDaMtzwdNzWFRtBUxoAYE3Z0Rb8fC0MESR0eiXun+BwCmYcuLcPLD5DnN 75FXnPtE+HLh4FmJleAcM4XDQj+mISS4CEf3HEctEEDNWpQdRa0Sr8v2pdtZ7IqrMzu0 Ly6jZqXtyr4YuNpUoYipEo2GIVTPrQS5ys4nfT0kR/UR2urt1iCmHjgIPBIDSifNAV8V f7pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=zprEdZ+a1+YrcgpT+V0n1RD9uXei3a3m50osSkmMNdc=; b=azpImok5233oafMIaZKDhpKwcJommaozfC9zNN/otkdqx0gA9LjjOineyXihSwF8kj uuhfWa1NWxmOeCoSU66YOo7s4llHZ8XWz9R2ByYJAAj4wEnLF9i0y1zSORq+tRN1rtHl 85PuuXDnz2RDA3xMOOLbH+R9cJTvS9+txKdvVHeKTd7TBXglfGXfUH51x5gl99lrtVPu VQ0SwbolUpATrBioM/QOYEj6tWAN+gGtOQ/Qx4/MNWaJujb/Tgpeju8vJsD4urS1eGcN VGCY3sQ3VHmcJrb0HKJ4h9P3z6gP7ogKNfJOeXgulERRN//8vkX/o/slTKHfJapXtPF7 Thaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MJI5/KUL; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si9776938ply.181.2017.11.06.01.05.39; Mon, 06 Nov 2017 01:05:53 -0800 (PST) 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=MJI5/KUL; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752603AbdKFJFA (ORCPT + 98 others); Mon, 6 Nov 2017 04:05:00 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45631 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752093AbdKFJEz (ORCPT ); Mon, 6 Nov 2017 04:04:55 -0500 Received: by mail-lf0-f67.google.com with SMTP id n69so9682635lfn.2 for ; Mon, 06 Nov 2017 01:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=zprEdZ+a1+YrcgpT+V0n1RD9uXei3a3m50osSkmMNdc=; b=MJI5/KULfrqUu62wqze8KgySsEsQVsis363l0Y4Ol1IOor34g/95t2zThHHKXfZru+ fmaAjSwaTEgrUGsYQg0z3nkR187ViQiMJkFy2nK8UX3hJ2ZF6oh1PMw/lIBZbajgX+8P eNlFCo8sLlp9S5h1ioG5KkA2bwTScxyjJ+BMOdyVg3kt+JZWeTYTJU+6ZhwwlWlysHQn SG1HAqUV92+qI1QM8TlOLwIGWt6jE7ZPERzmU8xmvshDmNCAMFbDHcz74x+nmUT8rWXe jpHUMF70tLj5umCKmEaCZVl7Y9OpRwEbfDSj4EAp/P8qPEIL3guqHp8DFLhnC6ATOoS2 CqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=zprEdZ+a1+YrcgpT+V0n1RD9uXei3a3m50osSkmMNdc=; b=CVLsyajWt4bEB3fT98f8bn+08/tZRKzXjK+xhVklmfsr7g17nkgFmdygGa5VZl3oyq 1tGx7Ifppgx0/0v9jQGvLgFwX6XWDWQFHBXiwa/x9FhR954UrMNu8r4kz3hd7jFiwZcY 8Q43AbAvRyfdLJWY62Mv0Ys1ZYYbvp8w6VCylePxIoLmGsKF6QH892kxobt5Vmj4OfEr FYThqqeAnlAK3LNAF2ICyUw9dxlxi/JUu/+CYjOMH1iWvxal2WX+i4rZ6753uygXI2tR TBlhpqsx5VmX5gtQ7x3kL/w9+0i4Np03gs7dCBgF9nFbqXRFxnKTDlxFzBZtuCGxbLd9 t+hQ== X-Gm-Message-State: AJaThX609DBjPgMVs0RR9aZ7n+48wzsEkFRImv4JDLmNDClOdHEH/U6u +xZ92YOAvPzMk1LOQTt+kN4nd5wzrx/uT7gdgVI= X-Received: by 10.25.100.18 with SMTP id y18mr6120846lfb.260.1509959093910; Mon, 06 Nov 2017 01:04:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.196.198 with HTTP; Mon, 6 Nov 2017 01:04:52 -0800 (PST) In-Reply-To: References: <20170921085922.11659-1-ganapatrao.kulkarni@cavium.com> <20170921085922.11659-4-ganapatrao.kulkarni@cavium.com> From: Ganapatrao Kulkarni Date: Mon, 6 Nov 2017 14:34:52 +0530 Message-ID: Subject: Re: [PATCH 3/4] iommu/arm-smmu-v3: Use NUMA memory allocations for stream tables and comamnd queues To: Robin Murphy , Will Deacon Cc: Ganapatrao Kulkarni , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-mm@kvack.org, Christoph Hellwig , Marek Szyprowski , Lorenzo Pieralisi , Hanjun Guo , Joerg Roedel , vbabka@suse.cz, akpm@linux-foundation.org, mhocko@suse.com, Tomasz.Nowicki@cavium.com, Robert Richter , jnair@caviumnetworks.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 18, 2017 at 7:06 PM, Robin Murphy wrote: > On 04/10/17 14:53, Ganapatrao Kulkarni wrote: >> Hi Robin, >> >> >> On Thu, Sep 21, 2017 at 5:28 PM, Robin Murphy wrote: >>> [+Christoph and Marek] >>> >>> On 21/09/17 09:59, Ganapatrao Kulkarni wrote: >>>> Introduce smmu_alloc_coherent and smmu_free_coherent functions to >>>> allocate/free dma coherent memory from NUMA node associated with SMMU. >>>> Replace all calls of dmam_alloc_coherent with smmu_alloc_coherent >>>> for SMMU stream tables and command queues. >>> >>> This doesn't work - not only do you lose the 'managed' aspect and risk >>> leaking various tables on probe failure or device removal, but more >>> importantly, unless you add DMA syncs around all the CPU accesses to the >>> tables, you lose the critical 'coherent' aspect, and that's a horribly >>> invasive change that I really don't want to make. >> >> this implementation is similar to function used to allocate memory for >> translation tables. > > The concept is similar, yes, and would work if implemented *correctly* > with the aforementioned comprehensive and hugely invasive changes. The > implementation as presented in this patch, however, is incomplete and > badly broken. > > By way of comparison, the io-pgtable implementations contain all the > necessary dma_sync_* calls, never relied on devres, and only have one > DMA direction to worry about (hint: the queues don't all work > identically). There are also a couple of practical reasons for using > streaming mappings with the DMA == phys restriction there - tracking > both the CPU and DMA addresses for each table would significantly > increase the memory overhead, and using the cacheable linear map address > in all cases sidesteps any potential problems with the atomic PTE > updates. Neither of those concerns apply to the SMMUv3 data structures, > which are textbook coherent DMA allocations (being tied to the lifetime > of the device, rather than transient). > >> why do you see it affects to stream tables and not to page tables. >> at runtime, both tables are accessed by SMMU only. >> >> As said in cover letter, having stream table from respective NUMA node >> is yielding >> around 30% performance! >> please suggest, if there is any better way to address this issue? > > I fully agree that NUMA-aware allocations are a worthwhile thing that we > want. I just don't like the idea of going around individual drivers > replacing coherent API usage with bodged-up streaming mappings - I > really think it's worth making the effort to to tackle it once, in the > proper place, in a way that benefits all users together. > > Robin. > >>> >>> Christoph, Marek; how reasonable do you think it is to expect >>> dma_alloc_coherent() to be inherently NUMA-aware on NUMA-capable >>> systems? SWIOTLB looks fairly straightforward to fix up (for the simple >>> allocation case; I'm not sure it's even worth it for bounce-buffering), >>> but the likes of CMA might be a little trickier... IIUC, having DMA allocation per node may become issue for 32 bit PCI devices connected on NODE 1 on IOMMU less platforms. most of the platforms may have NODE 1 RAM located beyond 4GB and having DMA allocation beyond 32bit for NODE1(and above) devices may make 32 bit pci devices not usable. DMA/IOMMU experts, please advise? >>> >>> Robin. >>> >>>> Signed-off-by: Ganapatrao Kulkarni >>>> --- >>>> drivers/iommu/arm-smmu-v3.c | 57 ++++++++++++++++++++++++++++++++++++++++----- >>>> 1 file changed, 51 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c >>>> index e67ba6c..bc4ba1f 100644 >>>> --- a/drivers/iommu/arm-smmu-v3.c >>>> +++ b/drivers/iommu/arm-smmu-v3.c >>>> @@ -1158,6 +1158,50 @@ static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent) >>>> } >>>> } >>>> >>>> +static void *smmu_alloc_coherent(struct arm_smmu_device *smmu, size_t size, >>>> + dma_addr_t *dma_handle, gfp_t gfp) >>>> +{ >>>> + struct device *dev = smmu->dev; >>>> + void *pages; >>>> + dma_addr_t dma; >>>> + int numa_node = dev_to_node(dev); >>>> + >>>> + pages = alloc_pages_exact_nid(numa_node, size, gfp | __GFP_ZERO); >>>> + if (!pages) >>>> + return NULL; >>>> + >>>> + if (!(smmu->features & ARM_SMMU_FEAT_COHERENCY)) { >>>> + dma = dma_map_single(dev, pages, size, DMA_TO_DEVICE); >>>> + if (dma_mapping_error(dev, dma)) >>>> + goto out_free; >>>> + /* >>>> + * We depend on the SMMU being able to work with any physical >>>> + * address directly, so if the DMA layer suggests otherwise by >>>> + * translating or truncating them, that bodes very badly... >>>> + */ >>>> + if (dma != virt_to_phys(pages)) >>>> + goto out_unmap; >>>> + } >>>> + >>>> + *dma_handle = (dma_addr_t)virt_to_phys(pages); >>>> + return pages; >>>> + >>>> +out_unmap: >>>> + dev_err(dev, "Cannot accommodate DMA translation for IOMMU page tables\n"); >>>> + dma_unmap_single(dev, dma, size, DMA_TO_DEVICE); >>>> +out_free: >>>> + free_pages_exact(pages, size); >>>> + return NULL; >>>> +} >>>> + >>>> +static void smmu_free_coherent(struct arm_smmu_device *smmu, size_t size, >>>> + void *pages, dma_addr_t dma_handle) >>>> +{ >>>> + if (!(smmu->features & ARM_SMMU_FEAT_COHERENCY)) >>>> + dma_unmap_single(smmu->dev, dma_handle, size, DMA_TO_DEVICE); >>>> + free_pages_exact(pages, size); >>>> +} >>>> + >>>> static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) >>>> { >>>> size_t size; >>>> @@ -1172,7 +1216,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) >>>> strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; >>>> >>>> desc->span = STRTAB_SPLIT + 1; >>>> - desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma, >>>> + desc->l2ptr = smmu_alloc_coherent(smmu, size, &desc->l2ptr_dma, >>>> GFP_KERNEL | __GFP_ZERO); >>>> if (!desc->l2ptr) { >>>> dev_err(smmu->dev, >>>> @@ -1487,7 +1531,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) >>>> struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; >>>> >>>> if (cfg->cdptr) { >>>> - dmam_free_coherent(smmu_domain->smmu->dev, >>>> + smmu_free_coherent(smmu, >>>> CTXDESC_CD_DWORDS << 3, >>>> cfg->cdptr, >>>> cfg->cdptr_dma); >>>> @@ -1515,7 +1559,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, >>>> if (asid < 0) >>>> return asid; >>>> >>>> - cfg->cdptr = dmam_alloc_coherent(smmu->dev, CTXDESC_CD_DWORDS << 3, >>>> + cfg->cdptr = smmu_alloc_coherent(smmu, CTXDESC_CD_DWORDS << 3, >>>> &cfg->cdptr_dma, >>>> GFP_KERNEL | __GFP_ZERO); >>>> if (!cfg->cdptr) { >>>> @@ -1984,7 +2028,7 @@ static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, >>>> { >>>> size_t qsz = ((1 << q->max_n_shift) * dwords) << 3; >>>> >>>> - q->base = dmam_alloc_coherent(smmu->dev, qsz, &q->base_dma, GFP_KERNEL); >>>> + q->base = smmu_alloc_coherent(smmu, qsz, &q->base_dma, GFP_KERNEL); >>>> if (!q->base) { >>>> dev_err(smmu->dev, "failed to allocate queue (0x%zx bytes)\n", >>>> qsz); >>>> @@ -2069,7 +2113,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) >>>> size, smmu->sid_bits); >>>> >>>> l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); >>>> - strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, >>>> + strtab = smmu_alloc_coherent(smmu, l1size, &cfg->strtab_dma, >>>> GFP_KERNEL | __GFP_ZERO); >>>> if (!strtab) { >>>> dev_err(smmu->dev, >>>> @@ -2097,8 +2141,9 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) >>>> u32 size; >>>> struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; >>>> >>>> + >>>> size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3); >>>> - strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma, >>>> + strtab = smmu_alloc_coherent(smmu, size, &cfg->strtab_dma, >>>> GFP_KERNEL | __GFP_ZERO); >>>> if (!strtab) { >>>> dev_err(smmu->dev, >>>> >>> >> >> thanks >> Ganapat >> > thanks Ganapat From 1581604455059959292@xxx Wed Oct 18 14:05:47 +0000 2017 X-GM-THRID: 1579139169210447923 X-Gmail-Labels: Inbox,Category Forums