Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp819760rdb; Tue, 19 Sep 2023 11:01:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaPpktMXlXZ+AQM2XIRq/iUM7WywX7ts/42+ZOyPEVyQz3GaDqRePJFTGUs6z9mYI44D9I X-Received: by 2002:a05:6a20:f3a3:b0:15a:592c:131a with SMTP id qr35-20020a056a20f3a300b0015a592c131amr209309pzb.30.1695146514050; Tue, 19 Sep 2023 11:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695146514; cv=none; d=google.com; s=arc-20160816; b=VGZWd3zMdigesnYsy/9gsIpZ2Des+ONq5T5uMe6Z6BJNxlxFZXBU8oHLXi8kgGkhg6 3D52wLwLtr9kx6+/x2Cirf+UqnDpZgCsGthxWYRlPG4mO7GbBwcUs0XX8HGN0Fu48dYY zdN8RO3TOOF3aImUGrxvV4v1O3VVYb6gDRXozYkybuu8gb5UV5Ht5aIZ+N26dGrL2Urh 6iOTF//dfj/Mg6bZPOFiHgIcQ4/UZBka4efi6lsJ43NAXczvvgUyhrUJaYB20L7ZtQGd 4GOrOzRmxBa6hzy9S4qtPZvg9O9vKod8gIew+T+i1CrylNOz/p+IbkGdyvMWjaEMQJRO MzyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=K4XOxDjoQc0tDKul2sAFg8dPE5RBNC5v+ER7EvKWlro=; fh=RE9vxGWu9qVR16+rr8QIAN+fcabTBFggemqrniMJrEI=; b=necarJW/JvfZ/l/rA0WEzewI8ygCNjxhsLRCWllxLVoQ2AcJcZIwbx9jFa+VM8LnOO zU0SQrpMCBR6Qf+fw2b6B1lh6q1nRopbBCGh88NSY9i05Nkzhf5UGYoS+S4dxLqULksK jLUkcdZYLVFmCNtNbqoJp9LbVHxfOr7aMUPDB28spR/RLu/G0JqvKY/c+pkQMZOqXJM5 Y2hEElxBXvYhRrrlV+XsEFsasKlBkWYIM4rHM7N73qiJsswSsN0dbZM1mdL3nwizy9wP zbjN//yCMjLMYiVMam08KQm9xEqusSXAOeidbNqL4MNN8Sd6s5Wl9+aCaIMdvpcErDwG VwaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=NUUqRKI9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e23-20020a656897000000b00578d78d0c94si154032pgt.710.2023.09.19.11.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 11:01:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=NUUqRKI9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 9A6E88280128; Tue, 19 Sep 2023 08:44:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233188AbjISPn6 (ORCPT + 99 others); Tue, 19 Sep 2023 11:43:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233186AbjISPn4 (ORCPT ); Tue, 19 Sep 2023 11:43:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71740C6 for ; Tue, 19 Sep 2023 08:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=K4XOxDjoQc0tDKul2sAFg8dPE5RBNC5v+ER7EvKWlro=; b=NUUqRKI9eBera0KC3gXkeqZtkM /GFKMZSxhT/N4WSHKiJ/LnKARML8J4fVRmJAK6vS+sngTB3qVVyL5CZ7+aYjPzEBzodj/t51kyRLt +lC5J68P8dYuCckGOdMcFiLmJTQjK6XnyMKf+KwyMI7oVjFXRLoLzSfMEgkQla6fltpCc33xk0tTD jkWzrEOofVLacRE1OsH9DD0Y3UrJuKKDfV9dv6ARDpn1HVgbpIj1e8+kk7CJygrv6/VjTWV4BPRkl RwV6MSNc1q6jXJklBhtoCEN0yr3A6DbNe1h+LuJ/9Kx0mqQ2fnY4HswW1WJ8xjBYMRuhM1tY0rMmS FoqlIc6w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qict2-000Qnd-Tt; Tue, 19 Sep 2023 15:43:40 +0000 Date: Tue, 19 Sep 2023 16:43:40 +0100 From: Matthew Wilcox To: Oleksandr Natalenko Cc: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Andi Shyti , Andrzej Hajda , Matthew Auld , Matt Roper , Aravind Iddamsetty , Fei Yang , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Nathan Chancellor , Chris Wilson , Daniele Ceraolo Spurio , Andrew Morton , linux-mm@kvack.org Subject: Re: [REGRESSION] [BISECTED] Panic in gen8_ggtt_insert_entries() with v6.5 Message-ID: References: <4857570.31r3eYUQgx@natalenko.name> <6287208.lOV4Wx5bFT@natalenko.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6287208.lOV4Wx5bFT@natalenko.name> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 08:44:00 -0700 (PDT) On Tue, Sep 19, 2023 at 10:26:42AM +0200, Oleksandr Natalenko wrote: > Andrzej asked me to try to revert commits 0b62af28f249, e0b72c14d8dc and 1e0877d58b1e, and reverting those fixed the i915 crash for me. The e0b72c14d8dc and 1e0877d58b1e commits look like just prerequisites, so I assume 0b62af28f249 ("i915: convert shmem_sg_free_table() to use a folio_batch") is the culprit here. > > Could you please check this? > > Our conversation with Andrzej is available at drm-intel GitLab [1]. > > Thanks. > > [1] https://gitlab.freedesktop.org/drm/intel/-/issues/9256 Wow, that is some great debugging. Thanks for all the time & effort you and others have invested. Sorry for breaking your system. You're almost right about the "prerequisites", but it's in the other direction; 0b62af28f249 is a prerequisite for the later two cleanups, so reverting all three is necessary to test 0b62af28f249. It seems to me that you've isolated the problem to constructing overly long sg lists. I didn't realise that was going to be a problem, so that's my fault. Could I ask you to try this patch? I'll follow up with another patch later because I think I made another assumption that may not be valid. diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 8f1633c3fb93..73a4a4eb29e0 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -100,6 +100,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, st->nents = 0; for (i = 0; i < page_count; i++) { struct folio *folio; + unsigned long nr_pages; const unsigned int shrink[] = { I915_SHRINK_BOUND | I915_SHRINK_UNBOUND, 0, @@ -150,6 +151,8 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, } } while (1); + nr_pages = min_t(unsigned long, + folio_nr_pages(folio), page_count - i); if (!i || sg->length >= max_segment || folio_pfn(folio) != next_pfn) { @@ -157,13 +160,13 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, sg = sg_next(sg); st->nents++; - sg_set_folio(sg, folio, folio_size(folio), 0); + sg_set_folio(sg, folio, nr_pages * PAGE_SIZE, 0); } else { /* XXX: could overflow? */ - sg->length += folio_size(folio); + sg->length += nr_pages * PAGE_SIZE; } - next_pfn = folio_pfn(folio) + folio_nr_pages(folio); - i += folio_nr_pages(folio) - 1; + next_pfn = folio_pfn(folio) + nr_pages; + i += nr_pages - 1; /* Check that the i965g/gm workaround works. */ GEM_BUG_ON(gfp & __GFP_DMA32 && next_pfn >= 0x00100000UL);