Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2284633ybl; Thu, 19 Dec 2019 11:00:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyF1BuEpoBJSQcSUORhmoRkXlCtXO8smq2ps8vJ1m8p+DEmZQNS6ufk2Zuay4Vx+u7e2pvS X-Received: by 2002:a05:6830:13d3:: with SMTP id e19mr809349otq.135.1576782052212; Thu, 19 Dec 2019 11:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782052; cv=none; d=google.com; s=arc-20160816; b=rAilDV6Yfdk41O+8n6GXVFV/V3gK2Af2aXVT7fv9sfRKm3Wwx0uWZLP8f7pFFgzr+x 8Z/NiIIn7IfO4EhzKJqhmRYy1uIcBEeRZPkNF9fv9Iw1oxjueQk2sbvFgkakkkHDcvmQ AqJiZmghYYrzpkxqnxxYrseMPW0D3HcMw9VZhRL71ozAGN6d7u4UgJGh/E0fSqzoVBpc g0OsJhS/4KQx+oiomBCMkBGgmM9SCBNDX/EZmvrBqJk+BrdTQes5uW6ae13FiQI7tTmK tlpevhIekhp6PnKHFmdTM7zfp6n+nWuW6Vk31c55i3OK1HPO8WfH9Zn+K/SJVW23BGze KqXQ== 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=gaqrrWpomdfHS9xNmaOeqIpJUSNX3TvMZ3edl+pRFcw=; b=WP5DGGyMHob0SpQ0+QXwsaMRT2eaTO8iVl70Ynn53gOGSwr1v92hncHjAz6kSh0uhA Jq//6LQ6ysEotBZvCD6y4Wrb60s9bwr0kKEkCBmmabWiWqL/J9gNJgc1m+8Ht/EFfKvw hCZtr9grcUNsDb9G72TKF+RBYYVKnQlDA9uRZeJXtYMZcE7txTiD4ym73HfJBsdCC9W2 kHnwONORmpcBLRJNTuw0wSO7/bxWZQF0MR7JHg/2kmTiiqWJIabziKFE7dQiOKGi4b4T ikatJwR650koFGnCBp7LofmZWQbgSwtXLTWvy01Av8suR/HAmbDLlb3caiSWjo56f6jC cgzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Nwpdwecq; 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 x20si3742516otq.222.2019.12.19.11.00.39; Thu, 19 Dec 2019 11:00:52 -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=Nwpdwecq; 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 S1729995AbfLSS6X (ORCPT + 99 others); Thu, 19 Dec 2019 13:58:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:50536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730273AbfLSSyz (ORCPT ); Thu, 19 Dec 2019 13:54:55 -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 9334D206EC; Thu, 19 Dec 2019 18:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781695; bh=jM4AaFsdUm+PCgilD4TxVD2a/AGAmFNdPl4DlFC+EvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nwpdwecqpy74LXwL7VivJDnDmds/T6W3ciX2Cd5CHPGlxtUEaMVE2QAn+23C5M1A4 6cMV3h4eDytV5X07Eqxy9lMTX65fcum3wX74yw1XIBYk6gqzBRMlTPPtt/qrYlkgGz UfC4+PVqHLt5eaDOjy/qBD/ctQXqFX889KGQ6zM8= 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 43/80] drm/panfrost: Fix a race in panfrost_ioctl_madvise() Date: Thu, 19 Dec 2019 19:34:35 +0100 Message-Id: <20191219183111.174687637@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 70cc77952efebf6722d483cb83cfb563ac9768db upstream. If 2 threads change the MADVISE property of the same BO in parallel we might end up with an shmem->madv value that's inconsistent with the presence of the BO in the shrinker list. The easiest solution to fix that is to protect the drm_gem_shmem_madvise() call with the shrinker lock. 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-3-boris.brezillon@collabora.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/panfrost/panfrost_drv.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -347,20 +347,19 @@ static int panfrost_ioctl_madvise(struct return -ENOENT; } + mutex_lock(&pfdev->shrinker_lock); args->retained = drm_gem_shmem_madvise(gem_obj, args->madv); if (args->retained) { struct panfrost_gem_object *bo = to_panfrost_bo(gem_obj); - mutex_lock(&pfdev->shrinker_lock); - if (args->madv == PANFROST_MADV_DONTNEED) - list_add_tail(&bo->base.madv_list, &pfdev->shrinker_list); + list_add_tail(&bo->base.madv_list, + &pfdev->shrinker_list); else if (args->madv == PANFROST_MADV_WILLNEED) list_del_init(&bo->base.madv_list); - - mutex_unlock(&pfdev->shrinker_lock); } + mutex_unlock(&pfdev->shrinker_lock); drm_gem_object_put_unlocked(gem_obj); return 0;