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 DDF50C433F5 for ; Tue, 12 Oct 2021 22:27:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7044460E54 for ; Tue, 12 Oct 2021 22:27:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7044460E54 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E9EC96B006C; Tue, 12 Oct 2021 18:27:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4D926B0071; Tue, 12 Oct 2021 18:27:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3CDC6B0072; Tue, 12 Oct 2021 18:27:06 -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 C0E8B6B006C for ; Tue, 12 Oct 2021 18:27:06 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7443C1833948E for ; Tue, 12 Oct 2021 22:27:06 +0000 (UTC) X-FDA: 78689222052.40.74878DF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 31B5FF0000AE for ; Tue, 12 Oct 2021 22:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634077625; 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: in-reply-to:in-reply-to:references:references; bh=11TQf4w46vxOJoeO7+popc8HKFJ+HG521dDzvTk1Lk8=; b=QIXdDBl8eSMBdxeyr6zLbciZJ2CoJjFFKJbhDvmz1nF0zecHVN5rPyQK+udwfMsoze/REM DT0pe5SppS4X0mGb+nMqPsYD5RwDcuphqARWq+WPbHgnnnPw22gAXMeCRDLO4Eftz7APq3 TK+qFSbnL7xKorN2rMRFEM04H/FaqKM= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-3ydUJAYGPsS1qEI-tSIqgA-1; Tue, 12 Oct 2021 18:27:04 -0400 X-MC-Unique: 3ydUJAYGPsS1qEI-tSIqgA-1 Received: by mail-pj1-f69.google.com with SMTP id m9-20020a17090ade09b029017903cc8d6cso2362259pjv.4 for ; Tue, 12 Oct 2021 15:27:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=11TQf4w46vxOJoeO7+popc8HKFJ+HG521dDzvTk1Lk8=; b=Iaoeb2F5h5S3tEtEeXp/0xc5OC8Wo37uudCtAZAO/cZ8+A7byT+MDaIaAWJFCRXIJ9 jx2BLpnc/dRgHsGK/JnKygp9l+fDOt2iPNL4tTAQDb+uukL8/DUWGKuwuZO31VNYrWAb uvMCtpSCcOhmUNZcHK5ytBzwo646lt/N1ECQb9fizSFZcMwKqjoIfMduLBM0xQP8srJt 3/9PX46b/pRQ0Khfv8mk/QK3jBAVlUAsDe/qYapYH5FyVcC3piJcj37bs3Qu83jgLWkl rdzOnjZRL5Pz1w5LK2vkbbqt+/556i0EwnptwMobPgYAv7G7C0OiN41LMsnHT5nHOIFv BDPg== X-Gm-Message-State: AOAM531d4ufAUM+Hq2lQJ+fHAtepVAsRPMT54tm8dAdt7Q9PPIr9nAfK NJZdW3kQnrQtgacA00ebWIeaoaQxc4EKhpei0A4xQa4T0yB6oGPbS2TseQG9FmOASMvxjsZha1o tu20KQjeDsds= X-Received: by 2002:a17:902:784c:b0:138:f4e5:9df8 with SMTP id e12-20020a170902784c00b00138f4e59df8mr32406561pln.14.1634077622746; Tue, 12 Oct 2021 15:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBA8O2OyyLjqqHonyZMbXGzyNSBUEqrTLwK9Uzpcpvikl0VbwmqaUyOmIPtZKgrZY8iK/tcA== X-Received: by 2002:a17:902:784c:b0:138:f4e5:9df8 with SMTP id e12-20020a170902784c00b00138f4e59df8mr32406524pln.14.1634077622340; Tue, 12 Oct 2021 15:27:02 -0700 (PDT) Received: from t490s ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id j6sm12131143pgq.0.2021.10.12.15.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 15:27:01 -0700 (PDT) Date: Wed, 13 Oct 2021 06:26:55 +0800 From: Peter Xu To: Yang Shi Cc: HORIGUCHI =?utf-8?B?TkFPWUEo5aCA5Y+jIOebtOS5nyk=?= , Hugh Dickins , "Kirill A. Shutemov" , Matthew Wilcox , Oscar Salvador , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Subject: Re: [v3 PATCH 4/5] mm: shmem: don't truncate page if memory failure happens Message-ID: References: <20210930215311.240774-1-shy828301@gmail.com> <20210930215311.240774-5-shy828301@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QIXdDBl8; spf=none (imf11.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 31B5FF0000AE X-Stat-Signature: iwmc9kxpymfq5atxpozrc16mp4eb4fyq X-HE-Tag: 1634077626-454821 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 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 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? -- Peter Xu