From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2AF3DC4332F for ; Fri, 4 Nov 2022 20:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IVeHUJgON62GGHxdxZdRD0cbE6CGt+4G2s60/Yv5PdA=; b=cCOQFbH4U6FwRA q1dG4sJHz6snL/0m8qd4sU4juJxuH5cTaQqC4vFIoI2FMMfB59v8m3BZx0p9slBMKDRz+OZV+03FU 4TThx4SJwijrGhbbRwtolVNAM8RMlHOkXo9owYAdenSJGIVLkTbBz29ttazGQP2LGAX+XixvsG4cA 95LUWlng1gleXrkdTcFNdvmow/HbGPheDoKblQcL0uYsOfLUPrWZDa2nB8NnXaqe8wxKyDBT30t1R XPtNRFuk34k8mf8MgbVksokPwARs1Da29v/imlbjgE8bCK5eybtmkt1wYOsD1Z5wy3mjjxx5BKjP9 Xww7l8RURaOkS7sGC/CA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1or3S5-0053Pc-IJ; Fri, 04 Nov 2022 20:38:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1or3S1-0053I0-Nx for linux-arm-kernel@lists.infradead.org; Fri, 04 Nov 2022 20:38:07 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 321D71FB; Fri, 4 Nov 2022 13:38:06 -0700 (PDT) Received: from [10.57.36.87] (unknown [10.57.36.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F07353F5A1; Fri, 4 Nov 2022 13:37:58 -0700 (PDT) Message-ID: <37f1afec-628b-927f-006e-7dc11c0afd35@arm.com> Date: Fri, 4 Nov 2022 20:37:52 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] drm/panfrost: Update io-pgtable API Content-Language: en-GB To: Dmitry Osipenko , robh@kernel.org, tomeu.vizoso@collabora.com Cc: linux-arm-kernel@lists.infradead.org, alyssa.rosenzweig@collabora.com, dri-devel@lists.freedesktop.org, steven.price@arm.com References: From: Robin Murphy In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221104_133805_926820_EA31A215 X-CRM114-Status: GOOD ( 19.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022-11-04 20:11, Dmitry Osipenko wrote: > On 8/23/22 01:01, Robin Murphy wrote: >> Convert to io-pgtable's bulk {map,unmap}_pages() APIs, to help the old >> single-page interfaces eventually go away. Unmapping heap BOs still >> wants to be done a page at a time, but everything else can get the full >> benefit of the more efficient interface. >> >> Signed-off-by: Robin Murphy >> --- >> drivers/gpu/drm/panfrost/panfrost_mmu.c | 40 +++++++++++++++---------- >> 1 file changed, 25 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c >> index b285a8001b1d..e246d914e7f6 100644 >> --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c >> +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c >> @@ -248,11 +248,15 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev) >> mmu_write(pfdev, MMU_INT_MASK, ~0); >> } >> >> -static size_t get_pgsize(u64 addr, size_t size) >> +static size_t get_pgsize(u64 addr, size_t size, size_t *count) >> { >> - if (addr & (SZ_2M - 1) || size < SZ_2M) >> - return SZ_4K; >> + size_t blk_offset = -addr % SZ_2M; >> >> + if (blk_offset || size < SZ_2M) { >> + *count = min_not_zero(blk_offset, size) / SZ_4K; >> + return SZ_4K; >> + } >> + *count = size / SZ_2M; >> return SZ_2M; >> } >> >> @@ -287,12 +291,16 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu, >> dev_dbg(pfdev->dev, "map: as=%d, iova=%llx, paddr=%lx, len=%zx", mmu->as, iova, paddr, len); >> >> while (len) { >> - size_t pgsize = get_pgsize(iova | paddr, len); >> + size_t pgcount, mapped = 0; >> + size_t pgsize = get_pgsize(iova | paddr, len, &pgcount); >> >> - ops->map(ops, iova, paddr, pgsize, prot, GFP_KERNEL); >> - iova += pgsize; >> - paddr += pgsize; >> - len -= pgsize; >> + ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, >> + GFP_KERNEL, &mapped); >> + /* Don't get stuck if things have gone wrong */ >> + mapped = max(mapped, pgsize); >> + iova += mapped; >> + paddr += mapped; >> + len -= mapped; >> } >> } >> >> @@ -344,15 +352,17 @@ void panfrost_mmu_unmap(struct panfrost_gem_mapping *mapping) >> mapping->mmu->as, iova, len); >> >> while (unmapped_len < len) { >> - size_t unmapped_page; >> - size_t pgsize = get_pgsize(iova, len - unmapped_len); >> + size_t unmapped_page, pgcount; >> + size_t pgsize = get_pgsize(iova, len - unmapped_len, &pgcount); >> >> - if (ops->iova_to_phys(ops, iova)) { >> - unmapped_page = ops->unmap(ops, iova, pgsize, NULL); >> - WARN_ON(unmapped_page != pgsize); >> + if (bo->is_heap) >> + pgcount = 1; >> + if (!bo->is_heap || ops->iova_to_phys(ops, iova)) { >> + unmapped_page = ops->unmap_pages(ops, iova, pgsize, pgcount, NULL); >> + WARN_ON(unmapped_page != pgsize * pgcount); > > This patch causes this WARN_ON to trigger. It doesn't happen all the > time, I see that the whole unmapped area is mapped. Initially, I thought > that this happens because it tries to unmap a partially mapped range, > but I checked that ops->iova_to_phys() returns address for all 4k chunks. > > For example the pgsize * pgcount = 0x8000000, while returned > unmapped_page = 0x6000000. > > I don't see this problem with this patch reverted. This is using today's > linux-next. Any ideas? What's the base IOVA in such a case? I'm wondering if the truncated size lines up to any interesting boundary. Presumably you're not seeing any additional warnings from io-pgtable itself? Thanks, Robin. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel