Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp966004iog; Thu, 30 Jun 2022 14:01:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1svE3bz2gdXXOIzkVxQ83Xg6//YKuiGLSe3sc5ewYkcwswHekvTHg1S8G228LTpejKzHnMO X-Received: by 2002:a17:90b:1986:b0:1ec:71f6:5fd9 with SMTP id mv6-20020a17090b198600b001ec71f65fd9mr13788703pjb.188.1656622860251; Thu, 30 Jun 2022 14:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656622860; cv=none; d=google.com; s=arc-20160816; b=SALVPHIWfonVyCZduo+Ek/pehWONG8xCaABO11jnXkBGXZ3taq2GzYFcYaOmcoiS8v 0rdJyw1enlDp6NNul3anvQxYFXtG20WCJQVaMR+vAvmQHRtyOkfCnsy85ok03tHBvtcf zG1/oaqFYKe7VPuAkQW/6H2U0crSHKv72QVU4io0lncKt7CegEGoygQv+QFn2szLdTcy IYTmC5/fhO3K1EZ9c0tLH4RwD68ClIJ3aLoORd+sgpOjJVbEOSSc9UAKsh5iaJzTBCpR T9LyDNDC7JAtROJ0g41vD3shm7zPLE1KYpMPUcF5AXXbJ3NW3sU1i4JZLV6oqLkix8Ji 5LSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ftaPbkTfDZDjcdBC0gC0fRWaxRBIOB9l1bn9W7tIjms=; b=P52wfBSVqgQA6wXEMlTUXM+kp+gfbJKxZ5dC41By1V69GBq9Fci9+/MpSmdcI6Xttg jauZHzXbyTmWeI7MquBHIK7EhTyrM2+73GC8YEcOpsXj90GWFLuBpoZP2H5qxDkUOjQi 0thjo7jb1ZGNtrLGuh0KHkUId5oe2fislBtj/RVpFoJFrOZR+fV3gqijAyrkPfDHtlHc Ng7wkpLEAi+j9PVKPcHzTqOsOXyZIXY5+FIGckFCClZnzSXAALIBKl5ZZGSaJwl+e2Rh 9iPtpH3VGQ8bBfSN40XtNU6wabibkkPq+i24QRvnwmBezoOfa1XYcRjovL92TR4VB/T9 0J7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GtuP5uxM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b0040d4a4adb72si27103741pge.560.2022.06.30.14.00.47; Thu, 30 Jun 2022 14:01:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GtuP5uxM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237018AbiF3UGj (ORCPT + 99 others); Thu, 30 Jun 2022 16:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236841AbiF3UGd (ORCPT ); Thu, 30 Jun 2022 16:06:33 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0373B568 for ; Thu, 30 Jun 2022 13:06:31 -0700 (PDT) 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , kernel@collabora.com 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } -- 2.36.1