From patchwork Wed Jun 5 21:21:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13687530 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 7C662C25B76 for ; Wed, 5 Jun 2024 21:21:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA4B16B009F; Wed, 5 Jun 2024 17:21:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2CB46B00A0; Wed, 5 Jun 2024 17:21:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA66D6B00A1; Wed, 5 Jun 2024 17:21:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 99F286B009F for ; Wed, 5 Jun 2024 17:21:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3662F160871 for ; Wed, 5 Jun 2024 21:21:56 +0000 (UTC) X-FDA: 82198107432.10.481C9F1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 3951E40007 for ; Wed, 5 Jun 2024 21:21:53 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fB1ZLmvw; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717622513; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=q6guOYJrLrFlpYszneZcHobnkFGNTsHvKaDHPs9XpUQ=; b=f4ujl5gsoUAa/W8MMDtAxXiA70fVS2qS3/zyar+xChnjvBV6fGk06vSmfnlBPkPHyVYhmB N9lh9IGiz7U3K4IZTw84UoJ054OiEMJlGS1BlQQwqfSVdYID4foLPwy6DcPqMUYglOskDW MXFwgkBGNVrtTsVM67nX0iDe89kU2FQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fB1ZLmvw; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717622513; a=rsa-sha256; cv=none; b=wpZ2ipOEc/uYumOb6AowDjgCIeeh8e24CkYE8Zg01j9B7N3waAaxDeBpmHI5yA3XG3Y240 ij3beEpTFjFLofBdmtivuNfLKNUZnTKk4niTam4IuFtUUgtcRt0XLStvFyGNphu1d8vxMn KPsr2WVQggcx4HOcdoVaCI5CKweIRCM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717622512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=q6guOYJrLrFlpYszneZcHobnkFGNTsHvKaDHPs9XpUQ=; b=fB1ZLmvwWhs/Op/cjuMKiKrA5nPct35MGUQuaOY/5rKNLw5pumpeYOzG33JvRx4kBXPpJ4 JXzNcId9xxN9GGLxtdTtAd1KENHFPGwq+KHaK402jf4FTMXmdBBcdZwRUlIkCh0d1A1FIF IImYIKmGlcHv57OMwf78VTMTkI0ryx4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-uOt4TykHPCiKXMwFK5g0hg-1; Wed, 05 Jun 2024 17:21:51 -0400 X-MC-Unique: uOt4TykHPCiKXMwFK5g0hg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ad5ebfaa68so463296d6.0 for ; Wed, 05 Jun 2024 14:21:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622511; x=1718227311; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q6guOYJrLrFlpYszneZcHobnkFGNTsHvKaDHPs9XpUQ=; b=Q0klPSyzT8kybf8K+Dka+GhVQib1NGXIJQ4LlMhrhrquPKj2g+yhRFDWJ/QMnCF6nZ bwIJcmYwJdPN+JDYg/T29d0XDd97WF8F91lquMjTUj9E0DDeh4f5yH2bIu/ielsJJmMx Ay8vl9y/P80TcQ7XZeEkUDl8+ee+Wo7UU/UAKFNTC7wUlaaRKR2ZNY1y8aAU5ZV2O+8I R8BWFY96yuDzfhUGZItr3xw5wufmSf9CyJSAYmpdWOvjpyDsY+zkZOB3ASNxGu1cgrnR O/yePS6IZrNXp1HVNhdJHe2DM7pEeNPdhQ1mhiGIbXY0H3WB+ZROwMJSEjp53lAFSTrC fNoQ== X-Forwarded-Encrypted: i=1; AJvYcCXVDHDy0FkRFaIUqtKviHFGG/cLlo4/ne34mL6/y8BHrIXbjXVFnn6HQahElvQeRkHdbxxUcbKaDFfAAb1FWvpPgbA= X-Gm-Message-State: AOJu0YwgrMjDlBKHDhA4z0KQUYARj7BlqttWBJOd1eJGBI7o1T4Un/uB kzy4LQHZVjzGUhXxR/PsNlCin8RpNQvrHqlxuUcer1tr0X56+phXvAeBdBcoy5moOh31E73P5mu kgxUNHjYw3VFPm6m7RHF21LqRdYmfbqp2/qSvMoK+93TR0uc4 X-Received: by 2002:a05:620a:2886:b0:794:edc7:1566 with SMTP id af79cd13be357-795240df187mr386798985a.4.1717622509876; Wed, 05 Jun 2024 14:21:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/geT55RHJOuBFW7WU7jX5S3mLJfm9lo9rhjmiuT/dUaQZocvdbrgkL6NqCoC3YnHeG8ne9Q== X-Received: by 2002:a05:620a:2886:b0:794:edc7:1566 with SMTP id af79cd13be357-795240df187mr386796285a.4.1717622509326; Wed, 05 Jun 2024 14:21:49 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794f3290417sm471861785a.135.2024.06.05.14.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:21:48 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , peterx@redhat.com, Dan Williams , Pasha Tatashin Subject: [PATCH] mm/page_table_check: Fix crash on ZONE_DEVICE Date: Wed, 5 Jun 2024 17:21:46 -0400 Message-ID: <20240605212146.994486-1-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3951E40007 X-Stat-Signature: decdopg3c5crq7qd6udiuzf6qexmy413 X-HE-Tag: 1717622513-491012 X-HE-Meta: U2FsdGVkX19hQFzkoW9NY+paQeUG96IBJifjO2gUDsKtojlkNI6KFgkcygZf0na4/PYyRTbazxkQW8kLOItCSOARyB0u81VkBLLt3Gk+Qc5idSTghyazn30w1kQTagwx7VzLasfHlKHTRvqsNPVMILi5ES6bcV2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oYRinaTNycxbGFcY+MmZra2x01XNifVQ7eINrrhRr0r45EXzE8amOYAQv2xXH0mH4CZ+MeZk7ImPpvNKpSpaIUmVFtLyDLzhaY3pze+1vonsjojZ5SDygLB5lb0VbmwowO+Wbm7p6KgNE9R6DPKbdyCx2TixYqy2eEwrwarWpgiLn8199XnzcOuLyw56EMDS5fWO+SAr6D6X3DeJoKMgvmPEZeuadz2qZBZ6TVx5EUhnCnKaXmgW53+IUI8Sxwx6nsxWM9kQZkaWrxxdkKVgbjHO94590aBZB26/boYEPp4TkNw3feSKKPrJ4FTMd9RSM6gTg== 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: Not all pages may apply to pgtable check. One example is ZONE_DEVICE pages: they map PFNs directly, and they don't allocate page_ext at all even if there's struct page around. One may reference devm_memremap_pages(). When both ZONE_DEVICE and page-table-check enabled, then try to map some dax memories, one can trigger kernel bug constantly now when the kernel was trying to inject some pfn maps on the dax device: kernel BUG at mm/page_table_check.c:55! While it's pretty legal to use set_pxx_at() for ZONE_DEVICE pages for page fault resolutions, skip all the checks if page_ext doesn't even exist in pgtable checker, which applies to ZONE_DEVICE but maybe more. Cc: Dan Williams Cc: Pasha Tatashin Signed-off-by: Peter Xu Reviewed-by: Dan Williams Reviewed-by: Alistair Popple Reviewed-by: Pasha Tatashin --- mm/page_table_check.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 4169576bed72..509c6ef8de40 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -73,6 +73,9 @@ static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt) page = pfn_to_page(pfn); page_ext = page_ext_get(page); + if (!page_ext) + return; + BUG_ON(PageSlab(page)); anon = PageAnon(page); @@ -110,6 +113,9 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, page = pfn_to_page(pfn); page_ext = page_ext_get(page); + if (!page_ext) + return; + BUG_ON(PageSlab(page)); anon = PageAnon(page); @@ -140,7 +146,10 @@ void __page_table_check_zero(struct page *page, unsigned int order) BUG_ON(PageSlab(page)); page_ext = page_ext_get(page); - BUG_ON(!page_ext); + + if (!page_ext) + return; + for (i = 0; i < (1ul << order); i++) { struct page_table_check *ptc = get_page_table_check(page_ext);