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: 170831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3978029vqx; Tue, 28 Nov 2023 06:53:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLoDYemSAP6Cfp8Jdyd9dneaHpIpn5NwTVxPvO5NlSqNV+33Hrs3E1m1L5QJ/INXM4Q5Gd X-Received: by 2002:a17:90b:164b:b0:280:99ca:1611 with SMTP id il11-20020a17090b164b00b0028099ca1611mr14100464pjb.20.1701183189801; Tue, 28 Nov 2023 06:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701183189; cv=none; d=google.com; s=arc-20160816; b=MGdt2tMVjERsVeDGxwz63qB26Yn7b0XZsWtURPXf2hqL+CUolifgjsM/JvXwxz/SjW PCa7K/N7fSTPLKpLzkn/PCMLD6CZK2pcRR/Ma7un4qQFGwM9TTSBxBkRp491z6i+PFm/ Tpgw18FZJQl1vka+vMtqaNY5FvhG4G90fg4TrtUPV87b9Bf+pV+mJy91gxm4JXI6D+6E QqiviCrgzKEd4GhNuLFSfv5eHa7iVx5h38vRlaN1/jno9/EEU7yZYZMKE5L1Mf9VA/ou uW+eD2yeO3dXk4x4fyuFW1zArMDd7eHYY5F//nljhnDjTWOr0R9YeP6OYTGmH1IR/yDe h4Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2oP52ROWQFWEf94d+ZcdDH9xIN9/viIr5hzxAC40F1s=; fh=iXyIHEqHOYLHaHkg4AmQBb0b8vPARyWexIbS110BxH8=; b=tz7GDXQWQ5OxHx8TIwbkGYMx8vpFECYBYOYo/2l6SjTySCj30uIM14BNu+YATxbvy+ 9VD2ir/BX+3kwoj6nS3wYFTHD7xfVx0lLMxVd8UyIAewqyGpZKwyEwq6Wjy0Oe+106Bj l75drht138cl2GZ3Rn7/+CtlDYl8y8+5HC2ULRZbPhxhJgLHwdnRr8XkN37wY0EVNu01 u0OVWooEToAfbgBU5tovrJ/f4X+3XJSWMkAjSrNV9pDWffWZ5CF/8ns0x1i+G2x0jHZl 1qOVjy+LcBdlZYBbMkhaEq8vYFSIVO17q39UKOeloymfpHG8Z5YiSXBVgaWG9WSddsH8 menw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A1RS3WSs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id lj3-20020a17090b344300b002839aba9d89si12142926pjb.25.2023.11.28.06.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 06:53:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A1RS3WSs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B354C8047051; Tue, 28 Nov 2023 06:52:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346405AbjK1OwT (ORCPT + 99 others); Tue, 28 Nov 2023 09:52:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346384AbjK1OwL (ORCPT ); Tue, 28 Nov 2023 09:52:11 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83001701 for ; Tue, 28 Nov 2023 06:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183137; 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=A1RS3WSs73Ghrw8nLtKzKhrT9wn7+PWalZ5oMzMSXyufOj5BE4gpTjHSFmQbzuBUALBbGU z0Eo1JzQo3dB20Yred1YjI/WtgESh8bDiJW1c3rvYVYUiymO/qmgQz9z4dhQlOGue6OhS3 8NpXtobQVhVHV7Ky9rF4nSeQk5cSEcs= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 06:52:33 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783819864435863366 X-GMAIL-MSGID: 1783819864435863366 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);