Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1807244ioo; Fri, 27 May 2022 18:30:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynEAM61gTg/ypaICZHAL4IxCmKfsnxM2aaXSIJOzF3OrPH/XqkwWv6eSADWnU+aSNhsS1Y X-Received: by 2002:a17:90a:2e83:b0:1da:3273:53ab with SMTP id r3-20020a17090a2e8300b001da327353abmr11198790pjd.14.1653701451392; Fri, 27 May 2022 18:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653701451; cv=none; d=google.com; s=arc-20160816; b=hqqqy8pw7WBjDMPWoMbng+NvO3eXjbhCn0XR3Fgd+INq+6v5LsYTJrptROO8erz10F LvCG66lqNkKCVxzyf34itcw758JE+AfWhvkw6kxvvnnjrlReNZq0LZ8zyLOdl69W4lBS zMg8Bu2RO8aYFVMQyM2vFO7/ItOrAXNOnW1Y5pnxk/hxfBUbumpvVsSi1jXdObsYNaaj CjL9LEzRGs/F8mr4trozJfgJy3833Raie8MXXbKgM3R5dOIIWOk3KFXddkjRgQAXJ+Rs FHXyHPrOZl88FFDoioI2ef+Nl/YBB76huqjvBEtKe/bjOyw4I7y9hhVTrqWHewGeVCcP 6x1w== 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=4WA8fC0HvFj8a3Q/jeBbk6YzQ11GAN56Y+9yGWUJGB0=; b=0TgiBzih2avn7kI4t6mOKe2H8avJeGbmSPCk/NMxLAMSeeDMHEASEpaViAEqrq903e dgn2io3dfu1ZaSmrPaIxdX66gv7/qZal5d1/0BG4cjr9u1X8FDvDc3TilpJ3npmtjIwu NoV1UNeeLxan2aNYzIRwTrCB9UIheTLAPEMHzuBJvqSUT0LhykKrK2J8+4Z4f+X/nzFf Z6X2lNb8VSrqvJXlFxzit4Qe1wyLqOtzufIMJ5If7DEmQjN0JoclGN9Lp6EuKHGIROPB IKT9XWjQR5sAsWM/Ocoa/TSWLPsG2YPB2hR9kawbBY1PcBln6NiDe6lS5KxEFBwqMSlp w0QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=PhWK+Iyk; 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 p11-20020a1709028a8b00b00156bddf0f3csi6812656plo.53.2022.05.27.18.30.38; Fri, 27 May 2022 18:30:51 -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=PhWK+Iyk; 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 S1349590AbiEZXya (ORCPT + 99 others); Thu, 26 May 2022 19:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349577AbiEZXyX (ORCPT ); Thu, 26 May 2022 19:54:23 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7859CE8BBA; Thu, 26 May 2022 16:54:22 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id 7FE781F40878 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1653609261; bh=mb8OzuWYSbm/AwBqD3mtEmj7ojjTOwTQHEjozWJ6AEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhWK+IykYUYDFR1HcPNf0jNTY7TZY0Ln8bRitBt0kB04+hQst9WEWAPvJrsPNbW/Z zIQsLj3s8FkbFS4J6AAh9FGS2SwW1x8ICQ0O/cvyoPbSY9PlksO1KkHleCnmYzw7Z6 Ps8r6ksbvWvvZMDMZbofS5W+UPPdelQLtTYTEoz/XHigCcMJC4tMpERsMpTB6zdAic 8fb8WgUWkUOccDal1GJu2bE6uZh0Ptg5/jLFxQaJtKw60Ga4PMr48eHgPMc+RrV70m KD8BH07+7/LJbMYplSdVI7Vrv32FhCvxsaGBiQiOPaDk68WNK5CFK34N2/2GNSCthp uuNX5S9HTuVQQ== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Rob Clark , Emil Velikov , Robin Murphy , Qiang Yu , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Dmitry Osipenko , Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com Subject: [PATCH v6 04/22] drm/panfrost: Fix shrinker list corruption by madvise IOCTL Date: Fri, 27 May 2022 02:50:22 +0300 Message-Id: <20220526235040.678984-5-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220526235040.678984-1-dmitry.osipenko@collabora.com> References: <20220526235040.678984-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_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 from the list before it's re-added. Fix it. Cc: stable@vger.kernel.org Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support") 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 087e69b98d06..b1e6d238674f 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.35.3