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 37B1AC433F5 for ; Wed, 13 Oct 2021 03:01:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B105A60EDF for ; Wed, 13 Oct 2021 03:01:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B105A60EDF 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 4BDC86B006C; Tue, 12 Oct 2021 23:01:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46E33900002; Tue, 12 Oct 2021 23:01:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 334EB6B0072; Tue, 12 Oct 2021 23:01:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 223A26B006C for ; Tue, 12 Oct 2021 23:01:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DA5992D015 for ; Wed, 13 Oct 2021 03:01:44 +0000 (UTC) X-FDA: 78689914128.12.90CE8DC Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf20.hostedemail.com (Postfix) with ESMTP id 7E24BD0000B2 for ; Wed, 13 Oct 2021 03:00:44 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id p13so4161395edw.0 for ; Tue, 12 Oct 2021 20:00:44 -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=uD7/xxEwM4AnRl/5PHzcJRyzYKic3SfztDUF3alZMoU=; b=BvxjOrwpeLJ7J1jBri14NRiKPnl7NctLM88EIysS4L64io8NBvn2ZFq4MqAWCogBCx 3XoEqg2aGSsN9o2TzuLNC0BjAUDeCJVGBeauiW0cDX+kGOQq+nrgE4/j80T3uwAiDsy3 vUbXXaVGqQWYo2Cej94MbVoFzs2xYnAuqa1EfhehJ34BhLK3XXKso7sV/VopHTIZnGYp 30FpTlG4Y+AdOJeBN/5wOj/jgrya/oWKIqGHq2itR1h6bYn3HJu30L5J5WtAQDdhsRzI o/kSy2+P731DMSQCZTaT9HTGWwHoUFbDIlm3R44CCY2CaJ+vQENn/JeACcDSTuv8Mety sDqA== 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=uD7/xxEwM4AnRl/5PHzcJRyzYKic3SfztDUF3alZMoU=; b=Nxnf4KMvXhK/k9CkfmzKkf0NPChJQcuOpB5mIrVWaxDwoqaRQuDogYcg9kNLg2oea7 FSi3/YBZXFlW5EGIkZe+3/5V2u4kjaVOfs6atcXdu4uBleU/yBCSTx6rZgGvyfXRe1n9 Qxde1SRoo8wYIxCg9fd/R96DKs+6+AU5eRCUl6/RJ9lFLmSQZjC/9NIW9TaF3l+xWGzK YH0FofOcTMYk0d9EeMNDdv9KQ0Bu5hO6Dw4zkzBynDghc1DmVbsLl/S84TpOUsk6pbJ1 XuXFMQ0v4yrjNU2g9mvzruxUBHijn1xhEF32bRXXJGU/2kDJmLV/k4HsDqhG08BVWy36 8z4w== X-Gm-Message-State: AOAM533CK/gSXI0gw3SIfKN/UG3+L8Yr/0o25Rqe/MqiqgoCKmVotc19 nf+8BD2JQASsg9C/lPc8phj5HJxAtKs+Fv0xUbg= X-Google-Smtp-Source: ABdhPJxW5me4u4P1TFyqA7pV0a03ZgWXyGnH/2+8NRlHyfV1AP9NuSMcbvbbxYjdLGsyJJAKYDTjL57UyfHMCGz2N9s= X-Received: by 2002:a17:907:170a:: with SMTP id le10mr35446437ejc.537.1634094043176; Tue, 12 Oct 2021 20:00:43 -0700 (PDT) MIME-Version: 1.0 References: <20210930215311.240774-1-shy828301@gmail.com> <20210930215311.240774-5-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Tue, 12 Oct 2021 20:00:31 -0700 Message-ID: Subject: Re: [v3 PATCH 4/5] mm: shmem: don't truncate page if memory failure happens To: Peter Xu Cc: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Hugh Dickins , "Kirill A. Shutemov" , Matthew Wilcox , Oscar Salvador , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7E24BD0000B2 X-Stat-Signature: sx9m4dhb515n8itzmwxreicr3yjft416 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BvxjOrwp; spf=pass (imf20.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1634094044-371254 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 Tue, Oct 12, 2021 at 3:27 PM Peter Xu wrote: > > On Tue, Oct 12, 2021 at 12:17:33PM -0700, Yang Shi wrote: > > On Mon, Oct 11, 2021 at 6:57 PM Peter Xu wrote: > > > > > > On Thu, Sep 30, 2021 at 02:53:10PM -0700, Yang Shi wrote: > > > > diff --git a/mm/shmem.c b/mm/shmem.c > > > > index 88742953532c..75c36b6a405a 100644 > > > > --- a/mm/shmem.c > > > > +++ b/mm/shmem.c > > > > @@ -2456,6 +2456,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, > > > > struct inode *inode = mapping->host; > > > > struct shmem_inode_info *info = SHMEM_I(inode); > > > > pgoff_t index = pos >> PAGE_SHIFT; > > > > + int ret = 0; > > > > > > > > /* i_rwsem is held by caller */ > > > > if (unlikely(info->seals & (F_SEAL_GROW | > > > > @@ -2466,7 +2467,17 @@ shmem_write_begin(struct file *file, struct address_space *mapping, > > > > return -EPERM; > > > > } > > > > > > > > - return shmem_getpage(inode, index, pagep, SGP_WRITE); > > > > + ret = shmem_getpage(inode, index, pagep, SGP_WRITE); > > > > + > > > > + if (*pagep) { > > > > + if (PageHWPoison(*pagep)) { > > > > + unlock_page(*pagep); > > > > + put_page(*pagep); > > > > + ret = -EIO; > > > > + } > > > > + } > > > > + > > > > + return ret; > > > > } > > > > > > > > static int > > > > @@ -2555,6 +2566,11 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) > > > > unlock_page(page); > > > > } > > > > > > > > + if (page && PageHWPoison(page)) { > > > > + error = -EIO; > > > > + break; > > > > + } > > > > + > > > > /* > > > > * We must evaluate after, since reads (unlike writes) > > > > * are called without i_rwsem protection against truncate > > > > > > [...] > > > > > > > @@ -4193,6 +4216,10 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, > > > > page = ERR_PTR(error); > > > > else > > > > unlock_page(page); > > > > + > > > > + if (PageHWPoison(page)) > > > > + page = ERR_PTR(-EIO); > > > > + > > > > return page; > > > > #else > > > > /* > > > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > > > > index 7a9008415534..b688d5327177 100644 > > > > --- a/mm/userfaultfd.c > > > > +++ b/mm/userfaultfd.c > > > > @@ -233,6 +233,11 @@ static int mcontinue_atomic_pte(struct mm_struct *dst_mm, > > > > goto out; > > > > } > > > > > > > > + if (PageHWPoison(page)) { > > > > + ret = -EIO; > > > > + goto out_release; > > > > + } > > > > + > > > > ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, > > > > page, false, wp_copy); > > > > if (ret) > > > > -- > > > > 2.26.2 > > > > > > > > > > These are shmem_getpage_gfp() call sites: > > > > > > shmem_getpage[151] return shmem_getpage_gfp(inode, index, pagep, sgp, > > > shmem_fault[2112] err = shmem_getpage_gfp(inode, vmf->pgoff, &vmf->page, SGP_CACHE, > > > shmem_read_mapping_page_gfp[4188] error = shmem_getpage_gfp(inode, index, &page, SGP_CACHE, > > > > > > These are further shmem_getpage() call sites: > > > > > > collapse_file[1735] if (shmem_getpage(mapping->host, index, &page, > > > shmem_undo_range[965] shmem_getpage(inode, start - 1, &page, SGP_READ); > > > shmem_undo_range[980] shmem_getpage(inode, end, &page, SGP_READ); > > > shmem_write_begin[2467] return shmem_getpage(inode, index, pagep, SGP_WRITE); > > > shmem_file_read_iter[2544] error = shmem_getpage(inode, index, &page, sgp); > > > shmem_fallocate[2733] error = shmem_getpage(inode, index, &page, SGP_FALLOC); > > > shmem_symlink[3079] error = shmem_getpage(inode, 0, &page, SGP_WRITE); > > > shmem_get_link[3120] error = shmem_getpage(inode, 0, &page, SGP_READ); > > > mcontinue_atomic_pte[235] ret = shmem_getpage(inode, pgoff, &page, SGP_READ); > > > > > > Wondering whether this patch covered all of them. > > > > No, it doesn't need. Not all places care about hwpoison page, for > > example, truncate, hole punch, etc. Only the APIs which return the > > data back to userspace or write back to disk need care about if the > > data is corrupted or not since. This has been elaborated in the cover > > letter. > > I see, sorry I missed that. However I still have two entries unsure in above > list that this patch didn't cover (besides fault path, truncate, ...): > > collapse_file[1735] if (shmem_getpage(mapping->host, index, &page, > shmem_get_link[3120] error = shmem_getpage(inode, 0, &page, SGP_READ); > > IIUC the 1st one is when we want to collapse a file thp, should we stop the > attempt if we see a hwpoison small page? The page refcount could stop collapsing hwpoison page. One could argue khugepaged could bail out earlier by checking hwpoison flag, but it is definitely not a must do. So it relies on refcount now. > > The 2nd one should be where we had a symlink shmem file and the 1st page which > stores the link got corrupted. Should we fail the get_link() then? Thanks for catching this. Yeah, it seems this one is overlooked. I didn't know that reading symlink needed to copy the first page. Will fix it in the next version. > > -- > Peter Xu >