Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4088925rdb; Mon, 11 Dec 2023 08:30:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK4Bp+1jh6z8wviLEvq8YvtEJdEx37bPDtT9YlhIzP/eLgXepGzUUXVU19gC8sVk3db2AK X-Received: by 2002:a17:902:c1c6:b0:1d0:acf9:f45b with SMTP id c6-20020a170902c1c600b001d0acf9f45bmr2037824plc.135.1702312249757; Mon, 11 Dec 2023 08:30:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702312249; cv=none; d=google.com; s=arc-20160816; b=G9r47soPg6s13KEsBHEq5y/0ofSRwxmod42aR9B4A8knEuAsfW1fUrZ99/9swXSFUd F5QM4MLko4VOC/BK5kLj+cO0okOcvlFpn9PAmXcYRWWPBe6Hj/W/UuurlgCcyTs2/7qi W0HfC+RrPgCOP5VjtziSOSU2/SbfI7wgHWX2M6IiaFp+3z1k4LKgD9Ap7R/HeJ2HKSMr K6EemOmVfO38RHbWPJVr12CMhzn/OCEAMYzjjzVBAbtbMshJC8vgLfcHXVdwrkbZrYx9 eOFfu/OQaAARRwYoLzhHUfLi1aP9g1uoYYWi+/6i4DG1nVf5+ngYOPESloqL9CJjCQBN lKig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=HVjZ2rMqq1lNyVLFT7YzuKYr/UaSB0hu1L4ajD0rYHE=; fh=GlLzLBhqF07GE0FJUf82nnkBDPyXS9iIZ0BDzvPX32s=; b=T1dkXWZMRomsc6Oo25GCRn7VmkCedYwlhgoEEMA9H8ThzekLFMzavT9Q5gjSI9nPXB +4nd2qyoO4u4aYQfzIYd7E4hDUrJJZUn4jzLx8TLqlt57MrR9g4ZqRp9+c24oxMwp09T 6y4EPd/3vgfjoWxO3Vh3+AB/nE8iSM64SnU/aT2eoPXrDuLk6bcCz8T/NdnEHedNduP3 ShkCqSdVdkt4MEaLvHEkPN82uYFF1OfmJka07WUzZnCeqjEmeMmaNVWneLhOZQ9GIqAT 5Q6bk2m6ohN0Pw549le9V4qJ4Y6rLEf8DVAMgQAvg1ze80iBrd7uU6Ly+m2qmrhqE9kn oO+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id d14-20020a170902cece00b001d1db5e39adsi6436784plg.95.2023.12.11.08.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:30:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 29EC2807861F; Mon, 11 Dec 2023 08:30:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344596AbjLKQ34 (ORCPT + 99 others); Mon, 11 Dec 2023 11:29:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234967AbjLKQ3z (ORCPT ); Mon, 11 Dec 2023 11:29:55 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDB5D99 for ; Mon, 11 Dec 2023 08:30:01 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3DDFE1007; Mon, 11 Dec 2023 08:30:48 -0800 (PST) Received: from [10.57.73.30] (unknown [10.57.73.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2028F3F738; Mon, 11 Dec 2023 08:30:00 -0800 (PST) Message-ID: Date: Mon, 11 Dec 2023 16:29:59 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 06/39] mm/rmap: add hugetlb sanity checks Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu References: <20231211155652.131054-1-david@redhat.com> <20231211155652.131054-7-david@redhat.com> From: Ryan Roberts In-Reply-To: <20231211155652.131054-7-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:30:11 -0800 (PST) On 11/12/2023 15:56, David Hildenbrand wrote: > Let's make sure we end up with the right folios in the right functions. > > Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts > --- > include/linux/rmap.h | 7 +++++++ > mm/rmap.c | 6 ++++++ > 2 files changed, 13 insertions(+) > > diff --git a/include/linux/rmap.h b/include/linux/rmap.h > index 4c0650e9f6db..e3857d26b944 100644 > --- a/include/linux/rmap.h > +++ b/include/linux/rmap.h > @@ -217,6 +217,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)) { > @@ -231,6 +232,7 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, > /* See page_try_share_anon_rmap() */ > static inline int hugetlb_try_share_anon_rmap(struct folio *folio) > { > + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); > VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); > VM_WARN_ON_FOLIO(!PageAnonExclusive(&folio->page), folio); > > @@ -253,6 +255,7 @@ static inline int hugetlb_try_share_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); > @@ -260,11 +263,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 e210ac1b73de..41597da14f26 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1343,6 +1343,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); > @@ -1395,6 +1396,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? */ > @@ -1480,6 +1482,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? */ > @@ -2632,6 +2635,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); > @@ -2644,6 +2648,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);