From patchwork Tue Nov 28 14:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471279 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 0A5FDC07E97 for ; Tue, 28 Nov 2023 14:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DE0E6B0306; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94ED36B030E; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6816B6B0308; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 550516B0306 for ; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2D7D51A0233 for ; Tue, 28 Nov 2023 14:52:21 +0000 (UTC) X-FDA: 81507653682.28.02DD2D9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 61A7CA0006 for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHgU9yEq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1701183139; 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=2oP52ROWQFWEf94d+ZcdDH9xIN9/viIr5hzxAC40F1s=; b=4qoxftS6JiSbC4SQi7ndfPfBTFT37f5a+qTOOXQEAxaHJq2tx442XLOtpHoinkSU2fyq7V y0bY/MCiXxPTE6ztbRCXgY6SKjjFEt70/txuGFMtmVjd16f5/DnBmXNhgtzB7PQ+bSqVeH xj9Jj1bSpfz/+ETDkN3tIIVobz90toY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHgU9yEq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183139; a=rsa-sha256; cv=none; b=uWJdz5xIoHMHogF5qpDPFSYlI7V4pr/YlKpXQqhXux7dWhVJ/2yXYJ7m6VtcvaZjOcKZqC DbrS+Ev2BL1X9eel3kCzVwuLch7dQ840XZe14/+5CArlzVAsrgJ0S1Rs8MidW0r+4umL9y M4Vlbwa2EEMF9qZ1kbXshKBbCEs07Zo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183138; 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=2oP52ROWQFWEf94d+ZcdDH9xIN9/viIr5hzxAC40F1s=; b=bHgU9yEq+dDV+rdqinsao6CZWoerjtoMyOJiIh4EL4itHUImqxF5MCOk2flgvFp+9S+sgJ H/ExO4QavNNQUh9cnvw7m8qyoiHmH3FqHy99tR0frTUdPGjBDaLGYASZSbGiSWWPZKasNz zvyKSQeIGby6lKI7wUE+F7lDTQPDrPI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-n6VIUHicO2m-dt6V1ZNSMQ-1; Tue, 28 Nov 2023 09:52:13 -0500 X-MC-Unique: n6VIUHicO2m-dt6V1ZNSMQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 237E03C100B4; Tue, 28 Nov 2023 14:52:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24AC310E45; Tue, 28 Nov 2023 14:52:12 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 5/5] mm/rmap: add hugetlb sanity checks Date: Tue, 28 Nov 2023 15:52:05 +0100 Message-ID: <20231128145205.215026-6-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspam-User: X-Stat-Signature: 8u583xfas94atrxxcqd318rihif4zd9o X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 61A7CA0006 X-HE-Tag: 1701183139-203047 X-HE-Meta: U2FsdGVkX19jwVr0NiBhvpGaionmLzjHt3EWXT9BqGc3NGa4Zou6x66AfJ5xCDmt8eQWxzF8Ad9zulaSVZMTrCmwuSiQutmhfJGks0L8YeL6rXn3P8rqJ2z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Odbq4n9zAdBTiY4Q== 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. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 6 ++++++ mm/rmap.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 8068c332e2ce..9625b6551d01 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -212,6 +212,7 @@ void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, struct vm_area_struct *vma) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); if (PageAnonExclusive(&folio->page)) { @@ -225,6 +226,7 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, static inline void hugetlb_add_file_rmap(struct folio *folio) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); @@ -232,11 +234,15 @@ static inline void hugetlb_add_file_rmap(struct folio *folio) static inline void hugetlb_remove_rmap(struct folio *folio) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); + atomic_dec(&folio->_entire_mapcount); } static inline void __page_dup_rmap(struct page *page, bool compound) { + VM_WARN_ON(folio_test_hugetlb(page_folio(page))); + if (compound) { struct folio *folio = (struct folio *)page; diff --git a/mm/rmap.c b/mm/rmap.c index 5037581b79ec..466f1ea5d0a6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1313,6 +1313,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, { int nr; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma); __folio_set_swapbacked(folio); @@ -1353,6 +1354,7 @@ void folio_add_file_rmap_range(struct folio *folio, struct page *page, unsigned int nr_pmdmapped = 0, first; int nr = 0; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(compound && !folio_test_pmd_mappable(folio), folio); /* Is page being mapped by PTE? Is this its first map to be added? */ @@ -1438,6 +1440,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, bool last; enum node_stat_item idx; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_PAGE(compound && !PageHead(page), page); /* Is page being unmapped by PTE? Is this its last map to be removed? */ @@ -2585,6 +2588,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); @@ -2597,6 +2601,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);