From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87392C433F5 for ; Mon, 1 Nov 2021 19:26:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2A5CB60FC4 for ; Mon, 1 Nov 2021 19:26:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2A5CB60FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 763CB940021; Mon, 1 Nov 2021 15:26:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7137894000F; Mon, 1 Nov 2021 15:26:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 602E3940021; Mon, 1 Nov 2021 15:26:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 526F494000F for ; Mon, 1 Nov 2021 15:26:31 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 07E12183BCDB0 for ; Mon, 1 Nov 2021 19:26:31 +0000 (UTC) X-FDA: 78761342982.08.A738DC5 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf20.hostedemail.com (Postfix) with ESMTP id EB045D0000A9 for ; Mon, 1 Nov 2021 19:26:22 +0000 (UTC) Received: by mail-ed1-f50.google.com with SMTP id m14so14883158edd.0 for ; Mon, 01 Nov 2021 12:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=awRFGVO/gEQLPCvLdPa1TvcfMQKVkjzH/TfPshmvxyI=; b=obLOf3ccUIEXaH3sAXUGYjRIT2RizjEh57JWWlYoEQ2MDiQg/dK0ScmBgCXmvIR2zj OvLBsYIQ7Cb7n39G/MFxKf/nmMpeSswmlwUi0FeufAtgLT8o7WO6cwl7v4yZ0xV3bqEj 6v+jgXo0JTVGlU8GCfVi9nedqqLpJv7GW7BQyQrTASf1/PPo1lV36mFyyhHRhLFY4PWO kMtnA6X8D/vqHDRLyy4zAWCAEV0JYScWYAoEYP5mCcWWE8sXPGf7uLtd6yLTlnyV9qRm dj6ZnxuqQH4yKs9vDnG4ZB8N9wTtcy1KxUa7eWv7pVFrEsUa7snwXYjFjrhv1lt6Pexv gc4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=awRFGVO/gEQLPCvLdPa1TvcfMQKVkjzH/TfPshmvxyI=; b=5KZZ4echoHjrkkKzP4L5cHl8M6aiCseQMa1svqOAj77Ts1bzSsbGsXAlgYHdZ2c5ua xvisDs/L+noKqQWdSCKur6MR9D4fwqfCrbTAF3f0dkttydwaFAE+6/tb59JADEq4DMUI Xp8SDmWcBVlQXmRwTV20mC5mCuXQ/gqMBq1HqTFqHLjKw7qIzIykg/4ypUmWAWyKs4ou 2ldmnsMiCoL9LVbdhEoDMQMCepLjj4eFCBWnUdIXR/eivGsvl+41O9h46ZQWCME0jsiC 5OQRgQK3/7bqDIDlIn9gdSGuEVjTEINr2HKnOE0c5mZxsylXWv1ffad/sKgLbb9yk/ZJ ubCA== X-Gm-Message-State: AOAM533raLt/sz4O2tV3nSS0ormQOsp38s9/blTbbV2aaBD6FRwGHBq1 i4o5Aq2/qnLXVGQ9Qs/ZyIHCaUAtfn4krs7/AS4= X-Google-Smtp-Source: ABdhPJycTYNHD7i+MZ1fe0HvWpmtzl4F1t05J0MIBxL8wQ86zQGqWVCKOVdJh8IsyRVnbaJIRmfrCZYEY10uDEIwVoI= X-Received: by 2002:a17:907:3f83:: with SMTP id hr3mr38815891ejc.555.1635794789559; Mon, 01 Nov 2021 12:26:29 -0700 (PDT) MIME-Version: 1.0 References: <20210930215311.240774-1-shy828301@gmail.com> <20210930215311.240774-3-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Mon, 1 Nov 2021 12:26:17 -0700 Message-ID: Subject: Re: [v3 PATCH 2/5] mm: filemap: check if THP has hwpoisoned subpage for PMD page fault To: Naresh Kamboju Cc: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Hugh Dickins , "Kirill A. Shutemov" , Matthew Wilcox , Peter Xu , Oscar Salvador , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List , Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Anders Roxell , lkft-triage@lists.linaro.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EB045D0000A9 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=obLOf3cc; spf=pass (imf20.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: j3mwn45kmtnm6yx6freim3t5ye4it3f3 X-HE-Tag: 1635794782-135909 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: On Mon, Nov 1, 2021 at 12:05 PM Naresh Kamboju wrote: > > Hi Yang, > > On Fri, 1 Oct 2021 at 03:23, Yang Shi wrote: > > > > When handling shmem page fault the THP with corrupted subpage could be PMD > > mapped if certain conditions are satisfied. But kernel is supposed to > > send SIGBUS when trying to map hwpoisoned page. > > > > There are two paths which may do PMD map: fault around and regular fault. > > > > Before commit f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") > > the thing was even worse in fault around path. The THP could be PMD mapped as > > long as the VMA fits regardless what subpage is accessed and corrupted. After > > this commit as long as head page is not corrupted the THP could be PMD mapped. > > > > In the regular fault path the THP could be PMD mapped as long as the corrupted > > page is not accessed and the VMA fits. > > > > This loophole could be fixed by iterating every subpage to check if any > > of them is hwpoisoned or not, but it is somewhat costly in page fault path. > > > > So introduce a new page flag called HasHWPoisoned on the first tail page. It > > indicates the THP has hwpoisoned subpage(s). It is set if any subpage of THP > > is found hwpoisoned by memory failure and cleared when the THP is freed or > > split. > > > > Fixes: 800d8c63b2e9 ("shmem: add huge pages support") > > Cc: > > Suggested-by: Kirill A. Shutemov > > Signed-off-by: Yang Shi > > --- > > include/linux/page-flags.h | 19 +++++++++++++++++++ > > mm/filemap.c | 12 ++++++------ > > mm/huge_memory.c | 2 ++ > > mm/memory-failure.c | 6 +++++- > > mm/memory.c | 9 +++++++++ > > mm/page_alloc.c | 4 +++- > > 6 files changed, 44 insertions(+), 8 deletions(-) > > When CONFIG_MEMORY_FAILURE not set > we get these build failures. Thanks for catching this. It is because Willy's page folio series changed the definition of PAGEFLAG_FALSE macro. But patch was new in 5.15-rc7, so his series doesn't cover this. The below patch should be able to fix it: diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index d8623d6e1141..981341a3c3c4 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -803,8 +803,8 @@ PAGEFLAG_FALSE(DoubleMap, double_map) PAGEFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) TESTSCFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) #else -PAGEFLAG_FALSE(HasHWPoisoned) - TESTSCFLAG_FALSE(HasHWPoisoned) +PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) + TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) #endif /* I will prepare a formal patch for 5.16. > > Regression found on x86_64 and i386 gcc-11 builds > Following build warnings / errors reported on Linux mainline master. > > metadata: > git_describe: v5.15-559-g19901165d90f > git_repo: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git > git_short_log: 19901165d90f (\"Merge tag > 'for-5.16/inode-sync-2021-10-29' of git://git.kernel.dk/linux-block\") > target_arch: x86_64 > toolchain: gcc-11 > > > In file included from include/linux/mmzone.h:22, > from include/linux/gfp.h:6, > from include/linux/slab.h:15, > from include/linux/crypto.h:20, > from arch/x86/kernel/asm-offsets.c:9: > include/linux/page-flags.h:806:29: error: macro "PAGEFLAG_FALSE" > requires 2 arguments, but only 1 given > 806 | PAGEFLAG_FALSE(HasHWPoisoned) > | ^ > include/linux/page-flags.h:411: note: macro "PAGEFLAG_FALSE" defined here > 411 | #define PAGEFLAG_FALSE(uname, lname) TESTPAGEFLAG_FALSE(uname, > lname) \ > | > include/linux/page-flags.h:807:39: error: macro "TESTSCFLAG_FALSE" > requires 2 arguments, but only 1 given > 807 | TESTSCFLAG_FALSE(HasHWPoisoned) > | ^ > include/linux/page-flags.h:414: note: macro "TESTSCFLAG_FALSE" defined here > 414 | #define TESTSCFLAG_FALSE(uname, lname) > \ > | > include/linux/page-flags.h:806:1: error: unknown type name 'PAGEFLAG_FALSE' > 806 | PAGEFLAG_FALSE(HasHWPoisoned) > | ^~~~~~~~~~~~~~ > include/linux/page-flags.h:807:25: error: expected ';' before 'static' > 807 | TESTSCFLAG_FALSE(HasHWPoisoned) > | ^ > | ; > ...... > 815 | static inline bool is_page_hwpoison(struct page *page) > | ~~~~~~ > make[2]: *** [scripts/Makefile.build:121: arch/x86/kernel/asm-offsets.s] Error 1 > > Reported-by: Linux Kernel Functional Testing > > build link: > ----------- > https://builds.tuxbuild.com/20KPBpXK6K0bKSIKAIKfwlBq7O4/build.log > > build config: > ------------- > https://builds.tuxbuild.com/20KPBpXK6K0bKSIKAIKfwlBq7O4/config > > # To install tuxmake on your system globally > # sudo pip3 install -U tuxmake > > tuxmake --runtime podman --target-arch x86_64 --toolchain gcc-11 > --kconfig defconfig --kconfig-add > https://builds.tuxbuild.com/20KPBpXK6K0bKSIKAIKfwlBq7O4/config > > link: > https://builds.tuxbuild.com/20KPBpXK6K0bKSIKAIKfwlBq7O4/tuxmake_reproducer.sh > > -- > Linaro LKFT > https://lkft.linaro.org