From patchwork Thu Jun 30 20:06:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12902144 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 7A422CCA473 for ; Thu, 30 Jun 2022 20:06:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2D0B12B149; Thu, 30 Jun 2022 20:06:36 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id C99BF12B131 for ; Thu, 30 Jun 2022 20:06:31 +0000 (UTC) Received: from dimapc.. (109-252-118-164.nat.spd-mgts.ru [109.252.118.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id C4F7A6601982; Thu, 30 Jun 2022 21:06:29 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1656619590; bh=ZPZ5Uw8WfuLpWfqCGj0P84Xq3+MvCoBG3Xz7cqkjkIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtuP5uxMVGGoJr+g1XAK8gzrG+Ce0uKhMWiz8589NkV3hXraWoS9dXwCl2p4iDfzi yRGe/FI+8iOcun6gyHS5hv3V6jD/M8o3MRjPfZfappvu6pOhorvCMvKvCdP7WHFdgW GPciW+ul7eGORtSTNkIaU7pixxx3lJ/LMxmEYYuBqafO5Q6KD5BNJh1cd7AekE8uIR WShj/XvrAzMRocXBpSJ4xg8K7KVUMuDiSIXmyso5SQmvi/q/lt0jBiJa9IiOd9jeGq 134r/fzE5N/WxVSFc4IMm2D+yVe7V5FVv7hfkSY3PvgPY9hGAIft7FAU1vchCGAJBs 88JGZOeLAISbg== From: Dmitry Osipenko To: David Airlie , Daniel Vetter , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Tomeu Vizoso , Rob Clark , Robin Murphy Subject: [PATCH v7 2/2] drm/panfrost: Fix shrinker list corruption by madvise IOCTL Date: Thu, 30 Jun 2022 23:06:01 +0300 Message-Id: <20220630200601.1884120-3-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630200601.1884120-1-dmitry.osipenko@collabora.com> References: <20220630200601.1884120-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Osipenko , kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Calling madvise IOCTL twice on BO causes memory shrinker list corruption and crashes kernel because BO is already on the list and it's added to the list again, while BO should be removed from the list before it's re-added. Fix it. Cc: stable@vger.kernel.org Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support") Acked-by: Alyssa Rosenzweig Reviewed-by: Steven Price Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/panfrost/panfrost_drv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index c58075bc096e..2d870cf73b07 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -433,8 +433,8 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data, if (args->retained) { if (args->madv == PANFROST_MADV_DONTNEED) - list_add_tail(&bo->base.madv_list, - &pfdev->shrinker_list); + list_move_tail(&bo->base.madv_list, + &pfdev->shrinker_list); else if (args->madv == PANFROST_MADV_WILLNEED) list_del_init(&bo->base.madv_list); }