Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1800105pxa; Sun, 23 Aug 2020 17:16:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVLRCwKk5bSmYt4jmkMlyZxmmFYLxEC2/w/g/14KYtPUFOFtWvE2WW1cWXr9RUpRygbre8 X-Received: by 2002:a17:906:819:: with SMTP id e25mr3373226ejd.95.1598228194767; Sun, 23 Aug 2020 17:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598228194; cv=none; d=google.com; s=arc-20160816; b=ZEHDhX6naAuCHOgz1DjR80XCrRvjZMvLT2h7GUSUK63qONomTSo7H+p2JcR0AN8EKY 55FngouoZ4Cc76dbTSgltgmWhQKYY+1baQrRxIXyygOjN2+7bIfZ68K/AjKa13eyRay1 rKPQcTXODF/XXle73dsQAyP9/GqiBqGHCxCaTdPU+o6kLGL8dQZuKB8DpteD7XPs9o4k IqmqQYkVgMSPvRiFP7XQwOewDGKZQLTKAvVOUMr9zSJfluhWWNWzQ8E0XzcXyBJ5L7tx Vj6pri1dphNypjrc9Mi+30jMeZ2iU7hmYPT2/H3ZEyfkmnUz8PMQX78Egn0PDRWRFykU ToMA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=2qvzvkep7ZlQHNyjrGsuXQAp+x7s+RjdNiOv81NxtoQ=; b=QJvsDkC9n+wjWWGyNFrnzU7zFwegbarrEYdbbZq5fV9XlOxr3S2q87Nvd36M1eTeSH Yk1w8WKXn/KK1gkdxDKKU4FqR7X5gpcFeYe9rMkrHydm+T/ARnHFT2D3xSEE0lQJ4T59 dDdA2FwAY8j4yKcxHP2A/EJtyxphmQj5ikS8vakX/eypxgVLlOn/ZgOXSmQRNmZ79TJe i9AaFRLXpRTfPbIoUKVIMdR7DqJmpLtnnq8qd9W1M/xPKRnyYzDqP8DcPIadHOYnxkkC 75QyoXdmWQhgDEphBCJRaQ2BnpQPbkRfDQIUPDDFQDRIvB3zuzUa8baLZo/7HPYrspWA ioYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=ph3cmZei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si5759561edr.422.2020.08.23.17.16.11; Sun, 23 Aug 2020 17:16:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=ph3cmZei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727823AbgHXAEw (ORCPT + 99 others); Sun, 23 Aug 2020 20:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbgHXAEs (ORCPT ); Sun, 23 Aug 2020 20:04:48 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E67C061573 for ; Sun, 23 Aug 2020 17:04:47 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id p18so5790664ilm.7 for ; Sun, 23 Aug 2020 17:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2qvzvkep7ZlQHNyjrGsuXQAp+x7s+RjdNiOv81NxtoQ=; b=ph3cmZeijsQTsHnHnrr9eCGgxMPexaLwCGnu3F9Od9T7oE9SJ1xriseSecoaLR+A31 cxdttU99z8vHmtpSvs9wLGOOgPOY6GzwuKuovZh4UMjplaxKJu/wyAtKKGV99cTnuUCc b9jW667DJd78gpOSqL093TQrnCvZ9zpW4sDgc9e3s4gqdpHbIh0cqwIbSVLaQrTLqDAX thER0vKrZAtqkOJvYQeGZuITMeh4kPZ6AWC1kOvIEmnWvuxZr35lD2OOnlXMpkqB5GBo XlqFU7D/ggoXmysuTUVEiDWk1jvnBEMzHRuwpliqu/K2HYrSEPvB6WXxqYArt4mYifKa QdMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2qvzvkep7ZlQHNyjrGsuXQAp+x7s+RjdNiOv81NxtoQ=; b=AW4ZEi19oPMRZVMQWiFKmSL4lhMeuExNjCgCJpMz0z8K2ZjbJg1jqgA0xrKSbU3tAk Un657znHOeqQqFfEZxVJC3HN/WbsnuJs8b/KAmkQLFvyJ+ZK+CtxFMZLJEz8kz0EID/Z 0vN+/RaF68tzLiGI0qxQcoVoD4V2iTii56tRbSPzRw4tnuODEfVEB5R7y1vN1jxAtmAi iNqgXfiskJ/P3cMJJLKacDtm3xKJ73egIrexuO1Pllo0kTP05Y1ud2TtROQhQQ7jcsVC vbtTguE4Lqug5Nod/n2TEtMdirQGx5Ji6pYlQolV8PuHwScH9OlezW/uHD5iCTeuTB5p 9xSw== X-Gm-Message-State: AOAM531qjKIifIhmqmUJDjWHyLutMN4ow5nhuNUiNGe1TB/+IRW7rJSc GZ+VUIWPAGs4zHHAZxudC9bKm1cynTlcghg0I5G22g== X-Received: by 2002:a92:4f:: with SMTP id 76mr2640989ila.11.1598227486317; Sun, 23 Aug 2020 17:04:46 -0700 (PDT) MIME-Version: 1.0 References: <20191221150402.13868-1-murphyt7@tcd.ie> <465815ae-9292-f37a-59b9-03949cb68460@deltatee.com> <20200529124523.GA11817@infradead.org> <33137cfb-603c-86e8-1091-f36117ecfaf3@deltatee.com> In-Reply-To: From: Tom Murphy Date: Mon, 24 Aug 2020 01:04:35 +0100 Message-ID: Subject: Re: [PATCH 0/8] Convert the intel iommu driver to the dma-iommu api To: Logan Gunthorpe Cc: Marek Szyprowski , Christoph Hellwig , iommu@lists.linux-foundation.org, kvm@vger.kernel.org, David Airlie , dri-devel@lists.freedesktop.org, Bjorn Andersson , Matthias Brugger , Julien Grall , Thierry Reding , Will Deacon , Jean-Philippe Brucker , linux-samsung-soc@vger.kernel.org, Marc Zyngier , Krzysztof Kozlowski , Jonathan Hunter , linux-rockchip@lists.infradead.org, Andy Gross , Gerald Schaefer , linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org, Alex Williamson , linux-mediatek@lists.infradead.org, Rodrigo Vivi , linux-tegra@vger.kernel.org, Thomas Gleixner , virtualization@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Robin Murphy , Cornelia Huck , Linux Kernel Mailing List , Kukjin Kim , David Woodhouse , Jani Nikula , Joonas Lahtinen 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 Hi Logan/All, I have added a check for the sg_dma_len == 0 : """ } __sgt_iter(struct scatterlist *sgl, bool dma) { struct sgt_iter s = { .sgp = sgl }; + if (sgl && sg_dma_len(sgl) == 0) + s.sgp = NULL; if (s.sgp) { ..... """ at location [1]. but it doens't fix the problem. You're right though, this change does need to be made, this code doesn't handle pages of sg_dma_len(sg) == 0 correctly So my guess is that we have more bugs in other parts of the i915 driver (or there is a problem with my "sg_dma_len == 0" fix above). I have been trying to spot where else the code might be buggy but I haven't had any luck so far. I'm doing a microconfernce (at LPC 2020) this wednesdays [1] on this if you're interested in attending. I'm hoping I can chat about it with a few people and find how can reproduce and fix this issues. I don't have any more time I can give to this unfortunately and it would be a shame for the work to go to waste. [0] https://github.com/torvalds/linux/blob/d012a7190fc1fd72ed48911e77ca97ba4521bccd/drivers/gpu/drm/i915/i915_scatterlist.h#L28 [1] https://linuxplumbersconf.org/event/7/contributions/846/ On Fri, 29 May 2020 at 22:21, Logan Gunthorpe wrote: > > > > On 2020-05-29 3:11 p.m., Marek Szyprowski wrote: > > Patches are pending: > > https://lore.kernel.org/linux-iommu/20200513132114.6046-1-m.szyprowski@samsung.com/T/ > > Cool, nice! Though, I still don't think that fixes the issue in > i915_scatterlist.h given it still ignores sg_dma_len() and strictly > relies on sg_next()/sg_is_last() to stop iterating -- and I suspect this > is the bug that got in Tom's way. > > >> However, as Robin pointed out, there are other ugly tricks like stopping > >> iterating through the SGL when sg_dma_len() is zero. For example, the > >> AMD driver appears to use drm_prime_sg_to_page_addr_arrays() which does > >> this trick and thus likely isn't buggy (otherwise, I'd expect someone to > >> have complained by now seeing AMD has already switched to IOMMU-DMA. > > > > I'm not sure that this is a trick. Stopping at zero sg_dma_len() was > > somewhere documented. > > Well whatever you want to call it, it is ugly to have some drivers doing > one thing with the returned value and others assuming there's an extra > zero at the end. It just causes confusion for people reading/copying the > code. It would be better if they are all consistent. However, I concede > stopping at zero should not be broken, presently. > > Logan