Received: by 2002:a05:7412:a9a8:b0:f9:92ae:e617 with SMTP id o40csp23674rdh; Wed, 20 Dec 2023 14:46:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkgc3/ktzy1l0Bpvy9JQhELXN0Axic7I321ufA/n4EuNs6jPzl+e2h1ym04mNzQUb1RrVi X-Received: by 2002:ac8:5845:0:b0:427:91f0:7f9a with SMTP id h5-20020ac85845000000b0042791f07f9amr1094503qth.133.1703112412232; Wed, 20 Dec 2023 14:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703112412; cv=none; d=google.com; s=arc-20160816; b=RNfkR1NodgKaboiCnPF801zkCeOIcJGZ+0TCz+JmzuC40sJrOdDKYk15IpTmo14ixL Xpl9bBUbjg1+fO51ybGxAnfFwDxQUEEkYflIflRab1gzQ8YiEWO9U7qApv4elhCYffHC gjMTIF/41eQM3pUnWXbVzyrHU9qoR8uguMW0Y17yCBo07WX3/GOFYc5x6/833GvMCx17 CuvRs6s9leW/xZ8uiobGAtWpVsm9VUa/ztkjSox/CbfuGoxEQ8j1sk56CcN8Ls1mAgUM PBPYTFfXQoZUN3srBEsWvC7+Q7ZNRmOwsLzkdtzPgPvo3tpxwke3/slQv7wqalYpxURP EKCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=w6z2XPcaQaFkvw9bopV7cZh6Qr6jUgqju9ezjmrboLY=; fh=UlFXU+hKOMcm6idRzNfe3Pu+B5L1f7aeir3C6i/NWQA=; b=lXz0jJJvR1ZVx82JSoPP09rTr5OOBWYBS9TzZHsN4F6VsiFETLNUZGvmGaJ0ZqRNBj Ts6w2yEIoo17FRnZVDP+iBxloVe2Yh/6LqmqjOwTbRTMqeYsbq0VD+Bpkxd/krXgrarw Afgtj8kIZFB+tkmoCJyFwT1c0l+oHWM1lGPRl05c53aBUTop66+MtbYfeEijT4smkMln 837lzzdHPueht9wSpfjzgGFuTgaPq3BPNiz5GwQC0gD9PipyrwgxtXZzgFMxpAmlXlMt Bjt1jsUO81xlZ5I42WV5p3QaKPyQqltBfWPCqWsrZxBK8xZjBzZUq+3sfBpFbHkCNG+4 lzMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eoTXJITF; spf=pass (google.com: domain of linux-kernel+bounces-7532-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7532-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 z8-20020ac87f88000000b0042581e4d6f6si743726qtj.547.2023.12.20.14.46.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 14:46:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7532-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=eoTXJITF; spf=pass (google.com: domain of linux-kernel+bounces-7532-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7532-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 054771C22EA5 for ; Wed, 20 Dec 2023 22:46:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 138A51E527; Wed, 20 Dec 2023 22:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eoTXJITF" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 E3B1E4C618 for ; Wed, 20 Dec 2023 22:45:30 +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=1703112330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w6z2XPcaQaFkvw9bopV7cZh6Qr6jUgqju9ezjmrboLY=; b=eoTXJITFpHJkUItZjnxNWkHAhQ3ZjJBJkSoJMfXMAAlsQ1sfGF+vhMDNDQosXjx1gj4wr1 MOsS4xSluQZfig/x5t7TKI6vnQDHm5oPZQxAhBU/ic6DwyDrEH+rUpAZ6dWVWNYgp1dqKA LQlzIBuS0jFhEPnmbYDTtGPFZ3zA7kQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-ykSjz5bzOj2Bw6ZSVoP9RQ-1; Wed, 20 Dec 2023 17:45:23 -0500 X-MC-Unique: ykSjz5bzOj2Bw6ZSVoP9RQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 122D5848C03; Wed, 20 Dec 2023 22:45:23 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA27740C6EB9; Wed, 20 Dec 2023 22:45:20 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Ryan Roberts , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu Subject: [PATCH v2 06/40] mm/rmap: add hugetlb sanity checks for anon rmap handling Date: Wed, 20 Dec 2023 23:44:30 +0100 Message-ID: <20231220224504.646757-7-david@redhat.com> In-Reply-To: <20231220224504.646757-1-david@redhat.com> References: <20231220224504.646757-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Let's make sure we end up with the right folios in the right functions when adding an anon rmap, just like we already do in the other rmap functions. Reviewed-by: Ryan Roberts Signed-off-by: David Hildenbrand --- mm/rmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/rmap.c b/mm/rmap.c index c229e48cf5a9e..6a1829324053e 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1262,6 +1262,8 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, bool compound = flags & RMAP_COMPOUND; bool first; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); + /* Is page being mapped by PTE? Is this its first map to be added? */ if (likely(!compound)) { first = atomic_inc_and_test(&page->_mapcount); @@ -1343,6 +1345,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, { int nr = folio_nr_pages(folio); + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_VMA(address < vma->vm_start || address + (nr << PAGE_SHIFT) > vma->vm_end, vma); __folio_set_swapbacked(folio); @@ -2634,6 +2637,7 @@ void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc) void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address, rmap_t flags) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); @@ -2646,6 +2650,8 @@ void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, void hugetlb_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); + BUG_ON(address < vma->vm_start || address >= vma->vm_end); /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0); -- 2.43.0