Received: by 10.192.165.156 with SMTP id m28csp637874imm; Wed, 11 Apr 2018 05:07:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx49V68rmxIFJF1iqYvi89wws3rR7N8s3GtKSmD8Dti7Xkb2bMX8bj2KzEMIB5UqtRVXt6/AJ X-Received: by 10.99.117.12 with SMTP id q12mr3180215pgc.395.1523448476027; Wed, 11 Apr 2018 05:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523448475; cv=none; d=google.com; s=arc-20160816; b=AZFJ6gZo+zEG0t+FqNxxqG5xviWd2SYq/OGXw990rW3d7joxMsfe1Sq9yUy97LnJ4t QVOJRFk0MEK5ntQsFQU9z5LvRrmsUTyOH+yf9CdslYvPXVvCgScErsMC5KuKZGkKuuPl fSYXC4/6qG0Qd/ikCQ1KW/yGelcd8PykS4OlG6DqIljwNK1A/VQaMLVi4FNZnUZk2tYh 6ArjDRSN4z4+CwnNmHacSVo/QQWWLeHG3RUVBxr9Bz3CnXpuypci0k1jvnJAW4mqLe9y k81fqjuK+XpZdtYfJhA+CL3CYDO+KlhHEPh1e38Qi6gKY39tjqBQC86BzS7oDsyKp8Zm 6RRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=1YBIEf7x3W1aFLEAaS50JwQuv1aMbndIywaImTrLP1E=; b=QxTEJKvAMeWTKJL33apOnTf3I6tytAV7JMZfQEw9e2V78Gn9kwJpBkjx6rOhsYEwEv oWeORGZjuc4fq/cQCQZVkcKJ2oh8OfxUcRp2r9/ujeYnJ38bIfFqz8xFyyW9DX5S3DEl G3LmrVssIxwiPSA7bFKqkz907QF1TNt4eoWkRxnk6e5oBOz/5GwnH2iA/tbP/dHNFyeg DL1zEpEbVxrfeviXj72L9qfOeVVcPRx1E21Vc9UKH3iOrZcrrtzqDsNJo5b1bDbmCW5/ QPeLaMhrxVPDLF2WpYru4m3FsOmLFJo4DJmFIMkID/MZ8gXSk9SMverY5k7q6hcf234Z ffXQ== 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 c28si655551pgn.792.2018.04.11.05.07.18; Wed, 11 Apr 2018 05:07:55 -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 S1752806AbeDKMEH (ORCPT + 99 others); Wed, 11 Apr 2018 08:04:07 -0400 Received: from foss.arm.com ([217.140.101.70]:48410 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751797AbeDKMEF (ORCPT ); Wed, 11 Apr 2018 08:04:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 439CE1529; Wed, 11 Apr 2018 05:04:05 -0700 (PDT) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 84F7E3F587; Wed, 11 Apr 2018 05:04:01 -0700 (PDT) Subject: Re: [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers To: Sinan Kaya , amd-gfx@lists.freedesktop.org, timur@codeaurora.org, sulrich@codeaurora.org Cc: Tom St Denis , "David (ChunMing) Zhou" , Emily Deng , David Airlie , linux-arm-msm@vger.kernel.org, Felix Kuehling , open list , "open list:DRM DRIVERS" , David Panariti , Jim Qu , Huang Rui , Roger He , Monk Liu , Feifei Xu , Alex Deucher , =?UTF-8?Q?Christian_K=c3=b6nig?= , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, hch@lst.de References: <1523394001-4615-1-git-send-email-okaya@codeaurora.org> From: Robin Murphy Message-ID: <32b82296-bba5-b5f1-266b-45c1ed66da94@arm.com> Date: Wed, 11 Apr 2018 13:03:59 +0100 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: <1523394001-4615-1-git-send-email-okaya@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/04/18 21:59, Sinan Kaya wrote: > Code is expecing to observe the same number of buffers returned from > dma_map_sg() function compared to sg_alloc_table_from_pages(). This > doesn't hold true universally especially for systems with IOMMU. So why not fix said code? It's clearly not a real hardware limitation, and the map_sg() APIs have potentially returned fewer than nents since forever, so there's really no excuse. > IOMMU driver tries to combine buffers into a single DMA address as much > as it can. The right thing is to tell the DMA layer how much combining > IOMMU can do. Disagree; this is a dodgy hack, since you'll now end up passing scatterlists into dma_map_sg() which already violate max_seg_size to begin with, and I think a conscientious DMA API implementation would be at rights to fail the mapping for that reason (I know arm64 happens not to, but that was a deliberate design decision to make my life easier at the time). As a short-term fix, at least do something like what i915 does and constrain the table allocation to the desired segment size as well, so things remain self-consistent. But still never claim that faking a hardware constraint as a workaround for a driver shortcoming is "the right thing to do" ;) Robin. > Signed-off-by: Sinan Kaya > --- > drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 2 +- > drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 1 + > drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 1 + > drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 1 + > 4 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c > index 8e28270..1b031eb 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c > @@ -851,7 +851,7 @@ static int gmc_v6_0_sw_init(void *handle) > pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32)); > dev_warn(adev->dev, "amdgpu: No coherent DMA available.\n"); > } > - > + dma_set_max_seg_size(adev->dev, PAGE_SIZE); > r = gmc_v6_0_init_microcode(adev); > if (r) { > dev_err(adev->dev, "Failed to load mc firmware!\n"); > diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c > index 86e9d682..0a4b2cc1 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c > @@ -999,6 +999,7 @@ static int gmc_v7_0_sw_init(void *handle) > pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32)); > pr_warn("amdgpu: No coherent DMA available\n"); > } > + dma_set_max_seg_size(adev->dev, PAGE_SIZE); > > r = gmc_v7_0_init_microcode(adev); > if (r) { > diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c > index 9a813d8..b171529 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c > @@ -1096,6 +1096,7 @@ static int gmc_v8_0_sw_init(void *handle) > pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32)); > pr_warn("amdgpu: No coherent DMA available\n"); > } > + dma_set_max_seg_size(adev->dev, PAGE_SIZE); > > r = gmc_v8_0_init_microcode(adev); > if (r) { > diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c > index 3b7e7af..36e658ab 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c > @@ -855,6 +855,7 @@ static int gmc_v9_0_sw_init(void *handle) > pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32)); > printk(KERN_WARNING "amdgpu: No coherent DMA available.\n"); > } > + dma_set_max_seg_size(adev->dev, PAGE_SIZE); > > r = gmc_v9_0_mc_init(adev); > if (r) >