From patchwork Wed Dec 20 22:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13500620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AC16C3DA6E for ; Wed, 20 Dec 2023 22:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C38048D0009; Wed, 20 Dec 2023 17:45:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE8618D0002; Wed, 20 Dec 2023 17:45:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A89F08D0009; Wed, 20 Dec 2023 17:45:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 92F468D0002 for ; Wed, 20 Dec 2023 17:45:33 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6B5B6405F1 for ; Wed, 20 Dec 2023 22:45:33 +0000 (UTC) X-FDA: 81588679746.03.67B5BEA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id BC04FC000B for ; Wed, 20 Dec 2023 22:45:31 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dxdtD0aa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703112331; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w6z2XPcaQaFkvw9bopV7cZh6Qr6jUgqju9ezjmrboLY=; b=4LIuW3azXFeSucUUkQYYCimdFuLlfBhzYvaNcyKYu0Y8V0+WvpgAFiOkl22vhpL7GO1nk3 q0rl9YcOs8f2XHlNAM5UTSLCfTt1UBM7u+FlgOmC0H9J3eGDIefP6lRFg/GGKQXHpexhPJ gSsdwa4MSwFHAEfX5lM0MnaXpEvfsV8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dxdtD0aa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703112331; a=rsa-sha256; cv=none; b=EfCfXTus2qvKZHC1fFVsqd9IbDbIC8kMp5kJdoeamNwD8G49DiHgiBgbW/q/AEBiTT5GEQ oSS6QPX/7K6ygAm1ZVHY3rGgBfUVvIuG7QOCU5FedwqIvrDSnimuEIeXTNZ0ZRs3pZuTsz 5N54VMeZK3iDUByRi5M7BVQJeqRQdj8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703112331; 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=dxdtD0aaP0Gyfa5debhNBaH4AfI33zUXBYlDRxJJU9zYhN9chLUQ8iRZaEOrFJYtJtnvm4 oicsogUf/B6v3WQCK9UGTB3R2/kp+rHd2VhYajuZNwQV++q8eZzHcgBJlGRMT6l1c3aYBE XbGWAOnUPUahE4lvjjHfvme3GtoP1r0= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Stat-Signature: k7yc4hrainh5gsbxy13jcmgncdogwde3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BC04FC000B X-HE-Tag: 1703112331-454551 X-HE-Meta: U2FsdGVkX1+OOAT3WKYz14psZ3aXybHJy8REdEEK8KYF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3Mz3Q3Q5ANa6z3CEgADMxMwAr6yW3kNMeP8oSTkl/e3ZqBf/D00WSER/IO6Y56sJ0j8wbg7uUaMTqsI0GS+lljKE/ZtkRqI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);