Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp95511rdb; Thu, 25 Jan 2024 09:10:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8KwIXwjPnT2zPF1gvTiLFcBAQCmFNebRGw/isjayOopR3awllZ2J5Rw9Y4iF3xudAyz7V X-Received: by 2002:aa7:9a0e:0:b0:6dd:8617:7733 with SMTP id w14-20020aa79a0e000000b006dd86177733mr924013pfj.58.1706202619417; Thu, 25 Jan 2024 09:10:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706202619; cv=pass; d=google.com; s=arc-20160816; b=eFGC8UlwJBuLQx3j62K9tTCoqC5cYF86M1OdfUheLf5URrtumSZdKY8xv9XtUbKQxw 2EiUjJ1BzCc3wm90nqV/rCEkyz5fHWyHuHYILq5vTzu9zWMBNKxVIXkPMbmOSheJW6QT dgc2CnLuexUlnMV6iZtrjJZw4AQtCD35mjaSu/PoGdS2gFhPIGxy19nWAgGKtQX/CXJG /KXobB4MWzBzOoPwXjpklASSb8xf9Wb7PmJlzCTZPUw6lStcKtO5vvSOQo4Y6walRJPT atRwfgUlIIXuv/H8LXfbYl1UEZ0XDwtRa8IE+uRsfZpsFucZ9Eya601hYRQK3WBQqGUA IbLA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=RVZvIOdDLkyCbfZ8j3GmjQYmDqYBMWxJLMIexyT6HDk=; fh=4ImKsb+DTnE9A1mibuCP28SmUggBgOC5rn3k2joY8bo=; b=zchL21cHbwBrH7P47SAf4atfyfTFS9wXaGPMSjR82pJI5MZR8YVTaB+E/S3XeBCLaP kV0GaEzrWwMUItg2Nt8H+rupNGvai/f+Iv34XTprTcM5kwQNkzykglSJuf27tGXyfU/I B6vwUgUSNnGVwWfq9gBsWjqAZIWWz6c0qWiCkK4Iq3nmjQEHfz4BE9BBauNSjSYsMmne 0ejXFD0Ysvxgflyf4R/YGTRQwfuBJKPGsSnuM4QovkyFESwdveR+zGQLNAApNfmV6beF VFDoUI2TeGHdekS+Z3QE5UgxwAR219uu4EbWSgoP/VpdZObW9W3XPp6Mj5m9my+HRQom q/3Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-38951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i16-20020aa78d90000000b006d9a617d2ecsi15538097pfr.80.2024.01.25.09.10.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:10:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-38951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 18F08B223EF for ; Thu, 25 Jan 2024 16:58:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C5DC13174E; Thu, 25 Jan 2024 16:47:23 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA51D12FF94 for ; Thu, 25 Jan 2024 16:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706201242; cv=none; b=lKJ4QRIvHqeF325CoE1Qaa35M7y31tjRalF3/dL7u7tST4Ptc8nNR3pS7k3ll++093dnTXz81pWxH2YgBxZ+lWzq58anShDGNZ/uVlpJY7EJGcUBfHsP/LQF1Wca37oBB4iPaafFb3DU4XoAx4v+Nn66ld72b2oAvh/sFDuF+34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706201242; c=relaxed/simple; bh=/FHwRI4r7JgDwNCxrf6OQAN4XCPE9f4qryDKOoKaftc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gDoCnEGTCQDQj4XNg5SUSuqpkQfXG2EBrlqA3shmsd8qGHiWo/yfUfVixbFb2CaduM64QoSajSJTsM3HJpUmmL16Fdd7nN1EsLqBo+S45hjH8W82UPlKR2dzYQzzx3xYmsWbD+gMAsK+AtlCEcYuchaYT3tJOUgcvpkvvVTlYvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 1E5B71763; Thu, 25 Jan 2024 08:48:05 -0800 (PST) Received: from [10.1.27.41] (e122027.cambridge.arm.com [10.1.27.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 454BA3F5A1; Thu, 25 Jan 2024 08:47:17 -0800 (PST) Message-ID: <08fd5c89-9fec-4fc8-b0a3-03e4ab9447d7@arm.com> Date: Thu, 25 Jan 2024 16:47:15 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 17/30] drm/panfrost: Fix the error path in panfrost_mmu_map_fault_addr() To: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?Q?Christian_K=C3=B6nig?= , Qiang Yu , Boris Brezillon , Emma Anholt , Melissa Wen Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-18-dmitry.osipenko@collabora.com> Content-Language: en-GB From: Steven Price In-Reply-To: <20240105184624.508603-18-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 05/01/2024 18:46, Dmitry Osipenko wrote: > From: Boris Brezillon > > If some the pages or sgt allocation failed, we shouldn't release the > pages ref we got earlier, otherwise we will end up with unbalanced > get/put_pages() calls. We should instead leave everything in place > and let the BO release function deal with extra cleanup when the object > is destroyed, or let the fault handler try again next time it's called. > > Fixes: 187d2929206e ("drm/panfrost: Add support for GPU heap allocations") > Cc: > Signed-off-by: Boris Brezillon > Co-developed-by: Dmitry Osipenko > Signed-off-by: Dmitry Osipenko Reviewed-by: Steven Price > --- > drivers/gpu/drm/panfrost/panfrost_mmu.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c > index bd5a0073009d..4a0b4bf03f1a 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c > +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c > @@ -502,11 +502,18 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, > mapping_set_unevictable(mapping); > > for (i = page_offset; i < page_offset + NUM_FAULT_PAGES; i++) { > + /* Can happen if the last fault only partially filled this > + * section of the pages array before failing. In that case > + * we skip already filled pages. > + */ > + if (pages[i]) > + continue; > + > pages[i] = shmem_read_mapping_page(mapping, i); > if (IS_ERR(pages[i])) { > ret = PTR_ERR(pages[i]); > pages[i] = NULL; > - goto err_pages; > + goto err_unlock; > } > } > > @@ -514,7 +521,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, > ret = sg_alloc_table_from_pages(sgt, pages + page_offset, > NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL); > if (ret) > - goto err_pages; > + goto err_unlock; > > ret = dma_map_sgtable(pfdev->dev, sgt, DMA_BIDIRECTIONAL, 0); > if (ret) > @@ -537,8 +544,6 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, > > err_map: > sg_free_table(sgt); > -err_pages: > - drm_gem_shmem_put_pages_locked(&bo->base); > err_unlock: > dma_resv_unlock(obj->resv); > err_bo: