Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp411318rdb; Thu, 5 Oct 2023 09:19:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7AEzIbv93ArWo3Oh+MAISEEaPqYIjaS3gj3kHFqx0bNhb34bwTni1Y6SZMyUSSvRiLWJy X-Received: by 2002:a05:6a20:3cab:b0:15a:bf8:7dfc with SMTP id b43-20020a056a203cab00b0015a0bf87dfcmr6310781pzj.15.1696522760462; Thu, 05 Oct 2023 09:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696522760; cv=none; d=google.com; s=arc-20160816; b=OFjd+Ulh+YxgBuCvxzgO19F9eaqAjcXUv2kp4THlifpnovuMLdEpQRFhYMf+Tj9dlK +F3trsktstZdPqBjSPFFQG2KGImpLgOWIpqaP0yupjereeFWiObBbCQeoT/AkBxtHl5V 7m6IsPBuS6mLLU3oPAqHzG0lIcIaCuaUkZhIXxCUsGA2UBO0MESAGgSb+qquja5NLV7I 16P1rBr1mEiGhqH9uu4uRlx0fiHRerb+Ei6q3DceazikQM/z0ANivz+2OTF/3AYZeTjQ Xr25L4bxkt76uOC7RRHrUSj4JJAvcQEywBUArSodetQP8BjhK2RZx3VIIobuhu+uEPzf 4VUQ== 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=Mkk02uRjKGFB4e8aG+3kpHFTSQxewntkAdfkHaxdesI=; fh=9GR74lKSEfFrjpoVU/BCxOv9hK4Hos97MvLgykXa2oU=; b=OnDdpVpaTev/t6se9ODLTnJdTnfHyHbqjfQeT6yMxjQWjeG5iULNcdEt2XYcHMluen gPDw0AAskq2yJSA9omznl+5b8xrKEBGV5TvKBXEMBywXtgLQXnu4/+Xu2WBdICkKfiKS GxzNsvd/FL4nFt7CdX2NRhO9kBQo2CZk5U9yX8DZ3xNdmQqJ+6T762+37VpWkGy7SrpO T8YTE5O+3ZdPBomuwhUJTQa+Wy0/uIFEnAYGqanoiaDn56gu4/SG45+nz8Ry7iyNnQJt IQDyv5+sem34taLDzLYVIEFwo7nmH6TFS2u6c61uUP6YZD40AEDEVxaj9dKfezFwPFJm 1zKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=e8lzia3e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ju22-20020a170903429600b001c59b6ed118si1690681plb.157.2023.10.05.09.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=e8lzia3e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 62D9E808BE67; Thu, 5 Oct 2023 09:19:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241812AbjJEQQg (ORCPT + 99 others); Thu, 5 Oct 2023 12:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241126AbjJEQNl (ORCPT ); Thu, 5 Oct 2023 12:13:41 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3534026FD8; Thu, 5 Oct 2023 06:05:33 -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=Mkk02uRjKGFB4e8aG+3kpHFTSQxewntkAdfkHaxdesI=; b=e8lzia3eWGjc2IATz+le3lrKVu gOGiebot8NBca6IuY1/7+0Md+gtJwtDVfAHSbA0UWbreBJzbz2kT+hFv+RpLa6r5qqRoffNUXfRGU VA7jnn8XW5RZTzKlM7OWo4x9vALqRV3miM8Zj4Wp1GxFCK1GDxu9CMi+opvVuCBcDMsxrXr1VD/GA ISl5cGU9QCIbPRtkw/08b6pYXUxKIhk56rJaYx/OV4skaPAarzqcWN2klpsiXE8vITVUS0/02QcWn rDUIB+fTSXu4BQliJpqS6UwH588iRi1GdKAdsFAPCdE/peTEyKFsQeCaJqVQf6gemqeoarlPqa0Hy z8Nh6/3A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qoO2h-009V8J-IJ; Thu, 05 Oct 2023 13:05:27 +0000 Date: Thu, 5 Oct 2023 14:05:27 +0100 From: Matthew Wilcox To: Oleksandr Natalenko Cc: Thomas Zimmermann , Linux Regressions , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Christian =?iso-8859-1?Q?K=F6nig?= , linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, Maxime Ripard , Bagas Sanjaya , Andrew Morton , Sumit Semwal , linux-media@vger.kernel.org Subject: Re: [REGRESSION] BUG: KFENCE: memory corruption in drm_gem_put_pages+0x186/0x250 Message-ID: References: <13360591.uLZWGnKmhe@natalenko.name> <3254850.aeNJFYEL58@natalenko.name> <22037450.EfDdHjke4D@natalenko.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <22037450.EfDdHjke4D@natalenko.name> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 05 Oct 2023 09:19:01 -0700 (PDT) On Thu, Oct 05, 2023 at 02:30:55PM +0200, Oleksandr Natalenko wrote: > No-no, sorry for possible confusion. Let me explain again: > > 1. we had an issue with i915, which was introduced by 0b62af28f249, and later was fixed by 863a8eb3f270 > 2. now I've discovered another issue, which looks very similar to 1., but in a VM with Cirrus VGA, and it happens even while having 863a8eb3f270 applied > 3. I've tried reverting 3291e09a4638, after which I cannot reproduce the issue with Cirrus VGA, but clearly there was no fix for it discussed > > IOW, 863a8eb3f270 is the fix for 0b62af28f249, but not for 3291e09a4638. It looks like 3291e09a4638 requires a separate fix. Thank you! Sorry about the misunderstanding. Try this: diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 6129b89bb366..44a948b80ee1 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -540,7 +540,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj) struct page **pages; struct folio *folio; struct folio_batch fbatch; - int i, j, npages; + long i, j, npages; if (WARN_ON(!obj->filp)) return ERR_PTR(-EINVAL); @@ -564,11 +564,13 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj) i = 0; while (i < npages) { + long nr; folio = shmem_read_folio_gfp(mapping, i, mapping_gfp_mask(mapping)); if (IS_ERR(folio)) goto fail; - for (j = 0; j < folio_nr_pages(folio); j++, i++) + nr = min(npages - i, folio_nr_pages(folio)); + for (j = 0; j < nr; j++, i++) pages[i] = folio_file_page(folio, i); /* Make sure shmem keeps __GFP_DMA32 allocated pages in the