Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp19083rdb; Fri, 5 Jan 2024 00:57:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcFIrgdlbsvvSpFHtSsvDgEUD2elXf+ESQvpzCHbZCdyoD54cVASUS1slx1c8nAK+rPgML X-Received: by 2002:ae9:c306:0:b0:781:e37c:d77e with SMTP id n6-20020ae9c306000000b00781e37cd77emr1766931qkg.39.1704445058446; Fri, 05 Jan 2024 00:57:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704445058; cv=none; d=google.com; s=arc-20160816; b=f+l3/lvZ9TWEBdy3GpleFWQuqrTzh9iXPw1eJuXpg6+24G0QkCaFGzdMjSmXWHU2ye bvRj3WNdcm/JNTg/u++EAvJn7vXkYmNkCxg17pCT1wmh8Z3rwtflrHRAGyeHmnIjzeJo Sm3xHNQee0FmWC+ZwnBRU5g6TOi/KW4BPaCdgsR5YQVR5DIX4OXmF/q1r0XqG0beEwue 5ZN3p907cCWZ54IbuB8VDaKlCQEF/H46izNdK9T2eU5KSPqIjfWCw1LzsyTCrQ05zTj7 iOb5nArBeV0hZIpFYiPQW2NoBrf3Fk5pYVdqoPtu3GzfObg3e/e8xIK8iT8p8eH2jWPH UuMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=xdS9zmsmBpcGPs+kLiFZ+pYoB8vBAvOUp4pwwBWRKww=; fh=GRZGIeVv/kvF/AJoR8odVA4YNYd+QkyzwoQVuMXAzbc=; b=Nl5zUDr6PDjwxwSviXSkj9bwr8SF7jo/Pmowv+OCSqqgueLCrU7cduzoFrvkwyJd5W dSJBzwP943cGLzAMSKEfem/WVuWOe+QdlNpxRQtgV5elApofvOOe4jWFxQcqZPZbnxRz 409B2kxo9H0JJ+rfpzTAO88CTYqu49lly2Jk78/0XH0+Mc41Tyy6VrwBH0hhFjjOkEP3 KNiRDyPXmwLWizNO6Swq0N1oRAHGsRssyQsFd3/QY9hCvmMWxqRQZaUyylJxc8D1/Wf/ ncJgxcpMS0XSRWIhCnHWZHhcLa3ZEyL+qMNvTRizj78G2c9iHVGfmIFwh2AaV8uA0ywg aJXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=POpWpGTo; spf=pass (google.com: domain of linux-kernel+bounces-17627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d27-20020a05620a137b00b0078152733ae4si1294649qkl.43.2024.01.05.00.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 00:57:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=POpWpGTo; spf=pass (google.com: domain of linux-kernel+bounces-17627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 254581C22D86 for ; Fri, 5 Jan 2024 08:57:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED8D8225A1; Fri, 5 Jan 2024 08:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="POpWpGTo" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B275224C3 for ; Fri, 5 Jan 2024 08:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704444999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=xdS9zmsmBpcGPs+kLiFZ+pYoB8vBAvOUp4pwwBWRKww=; b=POpWpGTowl+vTymWedWfBv0u9qTM2iX1dLAsQBqOHoz2+J2Rv5o20A+9vBaThAlCWO8Xpy FN+2rpThsBsU7jAieUtnoToulO711qH24FWjZ1kgOqKpKChzk1tzqKqT61s1UlnLOuSqAo 5d/fujH7c/xG9+q2kidC2SXX5/yBYSk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-tcQMbQr7P3yWs5gjwYUrjw-1; Fri, 05 Jan 2024 03:56:32 -0500 X-MC-Unique: tcQMbQr7P3yWs5gjwYUrjw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3367657a290so839384f8f.3 for ; Fri, 05 Jan 2024 00:56:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704444991; x=1705049791; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xdS9zmsmBpcGPs+kLiFZ+pYoB8vBAvOUp4pwwBWRKww=; b=hM6FunGLUdhfWtuVxUebU9N+9rlfoblQWJnnaJgYf0zG0xCCx1DfdoaaOgyhJd6mt3 HpmgKlJeO8rUV7jZLfI6R9T3dC960uEYwD4xTVrBvfweXahnFvRKGYmstYhTQ55wTDAr /LjO+ntR6tHvz7vEFvBE1XTcE9Lfb00vL0aeVrF2E6Jv7EosabyX3DTuu7kPz1EFXJcX TdWoVGyXqW7a4VfYWYpE0pZXW/9LW4FHibrn/KU28po4sSuw93cbXHRwtJ9iwjgeta5Y AddBeH73r4HlA7hRV0OWdtgPXbEA45o3TdwZI1OhCD9GnJgg8WRiVGdoA7KzJ8XQcoIG rAYQ== X-Gm-Message-State: AOJu0Yw81eU3d6CEjdxKsFMfgt6+9GnpzUKTs8lzdeqHPdTSvlsvoFse a3LzCMMZrSD95214GN3CdzRFSetvhuGO1V8sXc2KNVG8L5JpHYAouLmFHKQFP9i+EEWC3ZyRb7X nDc2QNXlgxvq3cVs3uY6Tano0zcUu11nr X-Received: by 2002:adf:ce04:0:b0:333:4bd9:8e with SMTP id p4-20020adfce04000000b003334bd9008emr973629wrn.25.1704444991618; Fri, 05 Jan 2024 00:56:31 -0800 (PST) X-Received: by 2002:adf:ce04:0:b0:333:4bd9:8e with SMTP id p4-20020adfce04000000b003334bd9008emr973618wrn.25.1704444991123; Fri, 05 Jan 2024 00:56:31 -0800 (PST) Received: from ?IPV6:2003:cb:c705:fb00:4bb9:5362:8a63:a97d? (p200300cbc705fb004bb953628a63a97d.dip0.t-ipconnect.de. [2003:cb:c705:fb00:4bb9:5362:8a63:a97d]) by smtp.gmail.com with ESMTPSA id l3-20020adff483000000b0033719111458sm992009wro.36.2024.01.05.00.56.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jan 2024 00:56:30 -0800 (PST) Message-ID: <556f8a4f-c739-41e0-85ec-643a0b32a2ce@redhat.com> Date: Fri, 5 Jan 2024 09:56:29 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [syzbot] [mm?] WARNING in __folio_rmap_sanity_checks To: Ryan Roberts , Yin Fengwei , syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Matthew Wilcox References: <000000000000014174060e09316e@google.com> <3feecbd6-b3bd-440c-a4f9-2a7dba3ff8f1@intel.com> <36ace74a-1de7-4224-8bc1-7f487764f6e2@redhat.com> <8bc02927-a0f0-490a-a014-0e100d30ffe4@intel.com> <1eb61435-c89c-4ca1-b1b6-aa00b3478cd2@arm.com> Content-Language: en-US From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNg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341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <1eb61435-c89c-4ca1-b1b6-aa00b3478cd2@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit >>>>> If I am not wrong, that triggers: >>>>> >>>>> VM_WARN_ON_FOLIO(folio_test_large(folio) && >>>>>            !folio_test_large_rmappable(folio), folio); >>>>> >>>>> So we are trying to rmap a large folio that did not go through >>>>> folio_prep_large_rmappable(). > > Would someone mind explaining the rules to me for this? As far as I can see, > folio_prep_large_rmappable() just inits the _deferred_list and sets a flag so we > remember to deinit the list on destruction. Why can't we just init that list for > all folios order-2 or greater? Then everything is rmappable? I think we much rather want to look into moving all mapcount-related stuff into folio_prep_large_rmappable(). It doesn't make any sense to initialize that for any compound pages, especially the ones that will never get mapped to user space. > >>>>> >>>>> net/packet/af_packet.c calls vm_insert_page() on some pages/folios stoed >>>>> in the "struct packet_ring_buffer". No idea where that comes from, but I >>>>> suspect it's simply some compound allocation. >>>> Looks like: >>>>    alloc_pg_vec >>>>      alloc_one_pg_vec_page >>>>           gfp_t gfp_flags = GFP_KERNEL | __GFP_COMP | >>>>                             __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY; >>>> >>>>           buffer = (char *) __get_free_pages(gfp_flags, order); >>>> So you are right here... :). >>> >>> Hm, but I wonder if this something that's supposed to work or is this one of >>> the cases where we should actually use a VM_PFN mapping? >>> >>> It's not a pagecache(file/shmem) page after all. >>> >>> We could relax that check and document why we expect something that is not >>> marked rmappable. But it fells wrong. I suspect this should be a VM_PFNMAP >>> instead (like recent udmabuf changes). >> >> VM_PFNMAP looks correct. > > And why is making the folio rmappable and mapping it the normal way not the > right solution here? Because the folio could be order-1? Or something more profound? > Think about it: we are adding/removing a page from rmap handling that can *never* be looked up using the rmap because there is no rmap for these pages, and folio->index is just completely unexpressive. VM_MIXEDMAP doesn't have any linearity constraints. Logically, it doesn't make any sense to involve rmap code although it currently might work. validate_page_before_insert() blocks off most pages where the order-0 mapcount would be used for other purposes and everything would blow up. Looking at vm_insert_page(), this interface is only for pages the caller allocated. Maybe we should just not do any rmap accounting when mapping/unmapping these pages: not involve any rmap code, including mapcounts? vm_normal_page() works on these mappings, so we'd also have to skip rmap code when unmapping these pages etc. Maybe that's the whole reason we have the rmap handling here: to not special-case the unmap path. Alternatively, we can: (1) Require the caller to make sure large folios are rmappable. We already require allocations to be compound. Should be easy to add. (2) Allow non-rmappable folios in rmap code just for mapcount tracking. Confusing but possible. >> >> I do have another question: why do we just check the large folio >> rmappable? Does that mean order0 folio is always rmappable? >> We didn't really have a check for that I believe. We simply reject all pages in vm_insert_page() that are problematic because the pagecount is overloaded. >> I ask this because vm_insert_pages() is called in net/ipv4/tcp.c >> and drivers call vm_insert_page. I suppose they all need be VM_PFNMAP. Right, similar problem. -- Cheers, David / dhildenb