Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp568103lqr; Wed, 5 Jun 2024 14:23:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXI5lH7aZaeJxsR+Cg/8TR45/zRBhxqr4vgLtXQFIML16eK5kuBPTg0Ku/kt0SNl6NZub/1Z1wP5QDLj1irV9z7XlzULLUgU5U/Ig0juQ== X-Google-Smtp-Source: AGHT+IFt5IT766xDNtMP+L55aKbaziDT4Q1tEXUWGJakpQsHCTudD30Ml2t33jXfA2rP0bk+syzw X-Received: by 2002:a17:902:e892:b0:1f3:b9d:87e6 with SMTP id d9443c01a7336-1f6a5a052a4mr46753165ad.8.1717622593086; Wed, 05 Jun 2024 14:23:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717622593; cv=pass; d=google.com; s=arc-20160816; b=YhC6qGtcT7msdOIuo5fugMexhx5k/svpwC+k62bqn4wYpwA4og3N9QcDy0FWF7qbNy jiHPsIZP89pIQJJ3bMBVdX9HYtNt90fxkYzXqqiRt9x6XJnQ/nH+XNu8IBmm7GIpKQ8K 46ELMfyvWdHLOKFlT8FaQ68b6RujYbJdxPj8Nt22OwsZpQ6FXifZGbJuPlYJWv58dE2/ p9+JhXbw8yXRDoZTy8VU44HJfO7i/7ZvI2Ji7bhF5NASyesfUirKk7gWT+m9XO1k+5C6 HSsRqFzbpCPy3kBNKwGZ+4D1/zCaowSNHFKH9iRLpg+scGhmJpoZtiQwdo+l/QBHV2m+ cw7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=q6guOYJrLrFlpYszneZcHobnkFGNTsHvKaDHPs9XpUQ=; fh=kmUAz7hd9mkuhV3pzSu0TaGaWvkAu92cZw54IiYvbQs=; b=Kp+0Wn7+fTpeQGYC+W0If2uYCddZ3UXkjD0uN+Y4XWRWXupk8wXQibvjMnfztya7OB +HRhK+wY6X4nN2kk5m4G6sXMpTIcvzzetJT2VDFSOoDqD1m8quHfjUoP4/Bi/a7QLBq6 +VpLhPRCT9vgvUVkATeVLBplKgtS/H1IeBMj99UZYwFUdEiIUxwPWC0nTQgzCEOL2ra6 DgjhgxFkNcdgvItJk3VQDSbCMhP2ItJsVD4t/iEpXoNJfaLdgq655h+lwWh8fbfe30/z VWoeDl6CHLpTkyyzNveQ5OHNt4/pjEGTrPzN9Sb5EArj7bOhtuXnt7xwwLdXpPoIAtV8 ShTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A50sO0eC; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-203248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f667512be6si74096175ad.572.2024.06.05.14.23.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A50sO0eC; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-203248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 95645289023 for ; Wed, 5 Jun 2024 21:22:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 341EE15FA96; Wed, 5 Jun 2024 21:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A50sO0eC" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB86E139D00 for ; Wed, 5 Jun 2024 21:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717622520; cv=none; b=he8ANfWd51yaDkkriCeNHtfahppD/o4idf3w7Wb7KHc/2FNePTadRf7FkAi/EOpIrzYi46aVdhOoFqZ7El5kibumt7w+khvJ6e7uPn3PZZqmWfJpGu2kc++7JTXgZoGjfzJiraY+1dxEvXgy+zl5MwULT4Ta0ivc4IUS13rKXKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717622520; c=relaxed/simple; bh=Qc3m+In7q6R+uy35WlCxQJ9rhymGQbbIYBejG40+EAs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=F9BVW8yFkAZ0kPMjkV67edPuKfCjMikuIAIgHzNq3F4wQAezc//udDTz8OSOLhU5lL/sMZ3xKowrb2zoO394jLtSjXyh/+uxq5rE0z/v599SHvAWn3zBhQPG8FCYjK5y1Ku8cIZMuKr66ntQgsYKiwnmunlXUZfHAdlKonfLE/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=A50sO0eC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717622517; 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; bh=q6guOYJrLrFlpYszneZcHobnkFGNTsHvKaDHPs9XpUQ=; b=A50sO0eCZdcakUuXJxvn3T3e80DJ296BiKSzpk7STipAwTdnIkW8KzI4+qSfdVDE7zN4TN 4c4I8orpO7D7NEgp/Y9BOy0wf8+zFAcTczeCTZOA7+7n54SBvBb1knXm3sR4f68ZY4oBD3 kN9dLCGY+rjJBETQlsKLJpyJA+vF7bo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-xnxhcw4JOP-8bxeUNGvRhA-1; Wed, 05 Jun 2024 17:21:51 -0400 X-MC-Unique: xnxhcw4JOP-8bxeUNGvRhA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6ae4a58fa7cso503026d6.2 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=1717622510; x=1718227310; 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=SjlXM3UfuLa2sAT7rLs4NgZWtR4ueqSXcXHa9jJ8nIZaib/FQ4moga4aGQoqlOVOD6 WUR8YGAPtBw4mwj32aSi3nZwguMVhMPAnLGIDwGgxelGOxAr9CneN8hNy1omCxJrfE8d gVP1Gpqr8xWy58V7GjFJasjs85/ZnLGZlU9Ji96VPFdYgEtF90s0ip03omJdkOThUpd1 Fy0XlelNALpPE4gkE5E46TlC9fxEuuewQsSFHOAQvKtPp6bX9jZGJtpKAxQYJrKx0ZlB uS980s3YW4b55AANeF4n9PeZaeeBSU81RjAY+U0hcltRUo4/MHrAR+CCEGeyNPrtHur1 GQ0w== X-Gm-Message-State: AOJu0Yw+wIGjMwy2ByoXoYV/nsBBu/jojT3Gzumd+u7iCNJlBaoFeShL vLlSw8gjtyuBNI5evMFjEcNQIsJWzMbGHSJOv4EUUg51qVFGm7O2b7NVceiNNACJFNCqlaUE0Gl DE1Bgy81BGjnLJPHku09RABLSf5URetJDFysxYwP7juXL162mWkO66mnSqGAGxmNmTR7z2wKUzm hY1WjLMPEu/L9+j2Nwt/tod8yICgirJL578dhbQ/oeSvI= X-Received: by 2002:a05:620a:2886:b0:794:edc7:1566 with SMTP id af79cd13be357-795240df187mr386800485a.4.1717622510094; Wed, 05 Jun 2024 14:21:50 -0700 (PDT) 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.45.0