Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2283193ybl; Thu, 19 Dec 2019 10:59:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzZsUKYTSYkuya976URzdcVu7TMXKTmg8NI4X0OUHgqi+VVwtmapmusSqIxxSTaDW0PKvXT X-Received: by 2002:a9d:ea6:: with SMTP id 35mr9990759otj.106.1576781977826; Thu, 19 Dec 2019 10:59:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781977; cv=none; d=google.com; s=arc-20160816; b=yhmjgvrF9oLvqbU+Kdhcz3sbKPXvDywGw8LSSiyUYLfH0okVg07vuYZPFTYtZIfJzK CNjijIK0dLh0p3Y3O2eAMXFKJXLba5EuAn/KJxOlctq6zOxku8emibb7WygVQhrLYCC7 eEdDPM3UdCZKXxcW0WtJjlkrUjSasskr2ZzdZqx52ZrX0GBL2hqNpqUMbBni8VRRbmu3 rAEutMFdziWHrDNVYuFjatEkF5dY6vewp9QuuYhqGwVt5r25dwwHO15/DQfXjZC+2E8C YrwcqqhCEF+ag2YwPZx8gQYe0di6oww9ceu4aoNFj2LWiH4X7RXg66ViOe5zluwPGh4D OZ+w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nZ46visys2qqHgAeqhwk3jH/BccRm0f2gV6pwvvW8Ug=; b=LIq/tmLFS5SUPmqW1PsU++Lv/uwMJis54eB6IcxeKw11H5L9kOuEU9BvNtIja5sDjR sA7K2KwDqdaqxpxmrVTY2lxcLpe6ULsAhUZ3xZ91mBpTzIAmyzICxZQTptfl5UFiHWiQ 8GTtg5DyJk/kTfRZZoCY20rQCE8Vs2wIRRv/jNyYqMn3adp3B1Cdsm9whmOP7U5s/oxp 6QA768eN5rvvOhacv+JvnkZzPdz9OFFL3yOe6EQGAY8rmwUW/3gdqEG/+xHexIsGHWHd T5IxQYNZd1gMBngB6A8idQQWyjH0GSbrwprnDAxTkY/K2zmpuIaSXKm/08EDgW3D86Hd DlJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vVbXIRG8; 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 f4si3674283oto.169.2019.12.19.10.59.26; Thu, 19 Dec 2019 10:59:37 -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=@kernel.org header.s=default header.b=vVbXIRG8; 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 S1730603AbfLSSzB (ORCPT + 99 others); Thu, 19 Dec 2019 13:55:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:50656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730596AbfLSSzA (ORCPT ); Thu, 19 Dec 2019 13:55:00 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 75CC7206EC; Thu, 19 Dec 2019 18:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781699; bh=Be1O2j7Z4b1WMstvecL4tEM81NqtYVosdwqztphEMZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vVbXIRG8GiS//HAnTBrW5aPAgYCLejA/4kB0AYlDrtiij+zknKS1gA1IbgpW4i3Fc fV/YEx9WGsarhX+ays+d6CEQ8+bKFyF1peJ1tm0GJ0rUKH4ljnmJdhmJrbne+YrLMN /pmRqUeTfbdCcQVD7DGoNBYSTZsYvnGSoCFqMNx4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Brezillon , Steven Price , Alyssa Rosenzweig , Rob Herring Subject: [PATCH 5.4 45/80] drm/panfrost: Fix a race in panfrost_gem_free_object() Date: Thu, 19 Dec 2019 19:34:37 +0100 Message-Id: <20191219183113.201635558@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Brezillon commit aed44cbeae2b7674cd155ba5cc6506aafe46a94e upstream. panfrost_gem_shrinker_scan() might purge a BO (release the sgt and kill the GPU mapping) that's being freed by panfrost_gem_free_object() if we don't remove the BO from the shrinker list at the beginning of panfrost_gem_free_object(). Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support") Cc: Signed-off-by: Boris Brezillon Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring Link: https://patchwork.freedesktop.org/patch/msgid/20191129135908.2439529-5-boris.brezillon@collabora.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/panfrost/panfrost_gem.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -19,6 +19,16 @@ static void panfrost_gem_free_object(str struct panfrost_gem_object *bo = to_panfrost_bo(obj); struct panfrost_device *pfdev = obj->dev->dev_private; + /* + * Make sure the BO is no longer inserted in the shrinker list before + * taking care of the destruction itself. If we don't do that we have a + * race condition between this function and what's done in + * panfrost_gem_shrinker_scan(). + */ + mutex_lock(&pfdev->shrinker_lock); + list_del_init(&bo->base.madv_list); + mutex_unlock(&pfdev->shrinker_lock); + if (bo->sgts) { int i; int n_sgt = bo->base.base.size / SZ_2M; @@ -33,11 +43,6 @@ static void panfrost_gem_free_object(str kfree(bo->sgts); } - mutex_lock(&pfdev->shrinker_lock); - if (!list_empty(&bo->base.madv_list)) - list_del(&bo->base.madv_list); - mutex_unlock(&pfdev->shrinker_lock); - drm_gem_shmem_free_object(obj); }