Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3355391pxf; Mon, 15 Mar 2021 07:51:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+eZuyZv2Lk7b/S2wnCLtnQRAjB7jBL6DOEx9a+9qoxLO157GbpVytCzun0oe3POdgkEvI X-Received: by 2002:a17:907:d15:: with SMTP id gn21mr23381513ejc.337.1615819817122; Mon, 15 Mar 2021 07:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615819817; cv=none; d=google.com; s=arc-20160816; b=NQ8EHbKbOyEuLRfZ0LqfTREswRGB0erq3Xuu3CWgsCtCG3tNi0y8jiD+K1agw02DaR Y0KUl7D4W1qx4Q4QmgTua38ND2zc3q87XCpGfaPWMjug4aFJV1UwQBn71HebwdNN4CzM ejtCIPSSE8IycNBrBex+lcpxpNPLSTg3zstrcLHUUBl1RPtEYymGQvjA4y4EmBuG4Vmk Ug+atwl4TvIoTvKnLoMGIR38LbK+JGeD6CkxFjtwCF9tVFcPuXnF0TfDk6RImpert+RM yZsWwwrAiGE0/lPzus5cz8kMkmti2t+mvm/+pU6IvYqjQ8h7M+0lkerxiUjcRKXv4LrA U9Zg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PMRvwwAMoAQOKOiWNxdl1+G5sbdeDpotCExB+3NcJNk=; b=oighI7UzRw3pALaTgck1nXdNa32u+rX/K2wIxkGIvq+LytISTmGhnof0MRB864CkJD NrIjUMsnl+tmesG1I+5AynlChSMEEG0DnDRAt5wvJcVIoQQNK5Sg837E6hW9h4C9zbIn NiMNtqFnqW7DD2aukl9hbtKTOczNCYqAnSgL9XGu8vgZXuNvoXPiP2zvjp7pOaVj/dhd cv2Ld483pofweR0a/pwvZ+E9Vj9nnW2WDGK6Esi1HpZDPFUEJybvDlb5xGzpVeQrmUH7 mj3/j06oI82j9aXpMIUsvu41aUSFLdbZWNpk00YyRWNja/lYg44xK/2lU+olpuz5kg3N kW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DDE/EdXi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si3175555eje.58.2021.03.15.07.49.53; Mon, 15 Mar 2021 07:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DDE/EdXi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240940AbhCOOsP (ORCPT + 99 others); Mon, 15 Mar 2021 10:48:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:49626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234347AbhCOODP (ORCPT ); Mon, 15 Mar 2021 10:03:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27C3964DAD; Mon, 15 Mar 2021 14:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816995; bh=GT23MI2WT8PQhaf0Bt8mf+eRN5Gc0SR/mz72E4QscaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDE/EdXi/kUkdxSCfyP9L/UWzdv7F4UUJDHZpxMs3bcHoKqkvTcHRG3nbr7DwM31l Z3OqtuaEb1MZtTUm5kw+dnNpTgl7UXFnVuQZu5wr0mg8/eDsa4ii2rDBz8HUYKdMO0 UWDytwbM43i0ZaT8uOf8FyucNCUb5fpBPyMyZKZI= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anthony DeRossi , =?UTF-8?q?Christian=20K=C3=B6nig?= , Maarten Lankhorst , Sasha Levin Subject: [PATCH 5.11 250/306] drm/ttm: Fix TTM page pool accounting Date: Mon, 15 Mar 2021 14:55:13 +0100 Message-Id: <20210315135516.095878997@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Anthony DeRossi [ Upstream commit ca63d76fd2319db984f2875992643f900caf2c72 ] Freed pages are not subtracted from the allocated_pages counter in ttm_pool_type_fini(), causing a leak in the count on device removal. The next shrinker invocation loops forever trying to free pages that are no longer in the pool: rcu: INFO: rcu_sched self-detected stall on CPU rcu: 3-....: (9998 ticks this GP) idle=54e/1/0x4000000000000000 softirq=434857/434857 fqs=2237 (t=10001 jiffies g=2194533 q=49211) NMI backtrace for cpu 3 CPU: 3 PID: 1034 Comm: kswapd0 Tainted: P O 5.11.0-com #1 Hardware name: System manufacturer System Product Name/PRIME X570-PRO, BIOS 1405 11/19/2019 Call Trace: ... sysvec_apic_timer_interrupt+0x77/0x80 asm_sysvec_apic_timer_interrupt+0x12/0x20 RIP: 0010:mutex_unlock+0x16/0x20 Code: e7 48 8b 70 10 e8 7a 53 77 ff eb aa e8 43 6c ff ff 0f 1f 00 65 48 8b 14 25 00 6d 01 00 31 c9 48 89 d0 f0 48 0f b1 0f 48 39 c2 <74> 05 e9 e3 fe ff ff c3 66 90 48 8b 47 20 48 85 c0 74 0f 8b 50 10 RSP: 0018:ffffbdb840797be8 EFLAGS: 00000246 RAX: ffff9ff445a41c00 RBX: ffffffffc02a9ef8 RCX: 0000000000000000 RDX: ffff9ff445a41c00 RSI: ffffbdb840797c78 RDI: ffffffffc02a9ac0 RBP: 0000000000000080 R08: 0000000000000000 R09: ffffbdb840797c80 R10: 0000000000000000 R11: fffffffffffffff5 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000084 R15: ffffffffc02a9a60 ttm_pool_shrink+0x7d/0x90 [ttm] ttm_pool_shrinker_scan+0x5/0x20 [ttm] do_shrink_slab+0x13a/0x1a0 ... debugfs shows the incorrect total: $ cat /sys/kernel/debug/dri/0/ttm_page_pool --- 0--- --- 1--- --- 2--- --- 3--- --- 4--- --- 5--- --- 6--- --- 7--- --- 8--- --- 9--- ---10--- wc : 0 0 0 0 0 0 0 0 0 0 0 uc : 0 0 0 0 0 0 0 0 0 0 0 wc 32 : 0 0 0 0 0 0 0 0 0 0 0 uc 32 : 0 0 0 0 0 0 0 0 0 0 0 DMA uc : 0 0 0 0 0 0 0 0 0 0 0 DMA wc : 0 0 0 0 0 0 0 0 0 0 0 DMA : 0 0 0 0 0 0 0 0 0 0 0 total : 3029 of 8244261 Using ttm_pool_type_take() to remove pages from the pool before freeing them correctly accounts for the freed pages. Fixes: d099fc8f540a ("drm/ttm: new TT backend allocation pool v3") Signed-off-by: Anthony DeRossi Link: https://patchwork.freedesktop.org/patch/msgid/20210303011723.22512-1-ajderossi@gmail.com Reviewed-by: Christian König Signed-off-by: Christian König Signed-off-by: Maarten Lankhorst Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 6e27cb1bf48b..4eb6efb8b8c0 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -268,13 +268,13 @@ static void ttm_pool_type_init(struct ttm_pool_type *pt, struct ttm_pool *pool, /* Remove a pool_type from the global shrinker list and free all pages */ static void ttm_pool_type_fini(struct ttm_pool_type *pt) { - struct page *p, *tmp; + struct page *p; mutex_lock(&shrinker_lock); list_del(&pt->shrinker_list); mutex_unlock(&shrinker_lock); - list_for_each_entry_safe(p, tmp, &pt->pages, lru) + while ((p = ttm_pool_type_take(pt))) ttm_pool_free_page(pt->pool, pt->caching, pt->order, p); } -- 2.30.1