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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7542DC433EF for ; Mon, 30 May 2022 06:50:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A23B38D0002; Mon, 30 May 2022 02:50:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F66C8D0001; Mon, 30 May 2022 02:50:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BF948D0002; Mon, 30 May 2022 02:50:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7BA018D0001 for ; Mon, 30 May 2022 02:50:07 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 44DB134FE5 for ; Mon, 30 May 2022 06:50:07 +0000 (UTC) X-FDA: 79521484854.15.6EE7277 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 7FCA740054 for ; Mon, 30 May 2022 06:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653893406; 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: in-reply-to:in-reply-to:references:references; bh=OA2EU1n3m5GYJZ5id1x49ev2OO8TYlhuVqKxXwmud78=; b=Ot0qgosl9gD0fKl+a67b2/ijKuGJhFXR+Nu7Eu1VXranrB/7vZdchQ8u/bQcrdXThwz3+b Gp//++jGvChMtBztSqvXoV0uxp+7jsQfV30tJKGcNxDL94EMzq5wfOXvtbEyTY8EEWyqqj dJCSWijVIq4oy2cp1WjsHEPK6jRP0JY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-103-S-QneznwMMCdp30VFsWpKQ-1; Mon, 30 May 2022 02:50:04 -0400 X-MC-Unique: S-QneznwMMCdp30VFsWpKQ-1 Received: by mail-wr1-f71.google.com with SMTP id bt14-20020a056000080e00b002100d89c219so1349909wrb.2 for ; Sun, 29 May 2022 23:50: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:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=OA2EU1n3m5GYJZ5id1x49ev2OO8TYlhuVqKxXwmud78=; b=3wu05SdnarOYwx+O+XiUsN3jfv1xGHqjeZXmy8AAHbFGGmEUQU4mTOiDKv++V6TJ0e 36GTaoddW3fvDL8UYw5ZAVr+I4nSzUCZ3kdco2ZgbXLv3dydLlL61MGm3773Q2cm5Lz2 zIqLPp+vvf558nzQB1ArcUKizvniy1Z782CmSRccbEDAyeUIA/U0vXuYi4h8ABhY5KTA n2vvANK3Xg4BkwLGC75UAuATbaBFzscAyF3PcTOIPv4YGpvUG+th6MdxF/A0JYPc6LSU 4sAGOeSbN81ekw6AnCfIk5WvONyA59ieYSh2rgpepdmAZsypJeOYxYOSBg6LXuA7l3aw zkbQ== X-Gm-Message-State: AOAM53016eNa8MsIaAN6PGax5ziotweh372sICKgTuFF2lUlCj0R9oq9 fbwn/HBDCQsU4c1X7cDejmL1k2grGRlITHA8MNeW9LEklV6koESPf4LTVqHNjXVb61rDogH0RWm 2OwZUi+oJ0U4= X-Received: by 2002:adf:9cca:0:b0:210:2f76:93fe with SMTP id h10-20020adf9cca000000b002102f7693femr4575102wre.12.1653893403106; Sun, 29 May 2022 23:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ4OTL2ca2wmWyNO4crgHpqC/B3lDmwhG91OltBGji82xyGj9aMMNAtDCPwYTN03OTbIPtxw== X-Received: by 2002:adf:9cca:0:b0:210:2f76:93fe with SMTP id h10-20020adf9cca000000b002102f7693femr4575084wre.12.1653893402877; Sun, 29 May 2022 23:50:02 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:7c00:aaa9:2ce5:5aa0:f736? (p200300cbc7047c00aaa92ce55aa0f736.dip0.t-ipconnect.de. [2003:cb:c704:7c00:aaa9:2ce5:5aa0:f736]) by smtp.gmail.com with ESMTPSA id m5-20020a5d64a5000000b0020c5253d8casm9032773wrp.22.2022.05.29.23.50.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 May 2022 23:50:02 -0700 (PDT) Message-ID: <2d742b58-efd2-9a74-0af6-68948a06bfe8@redhat.com> Date: Mon, 30 May 2022 08:50:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: zhenwei pi , akpm@linux-foundation.org, naoya.horiguchi@nec.com, mst@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jasowang@redhat.com, virtualization@lists.linux-foundation.org, pbonzini@redhat.com, peterx@redhat.com, qemu-devel@nongnu.org References: <20220520070648.1794132-1-pizhenwei@bytedance.com> <20220520070648.1794132-3-pizhenwei@bytedance.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 2/3] mm/memory-failure.c: support reset PTE during unpoison In-Reply-To: <20220520070648.1794132-3-pizhenwei@bytedance.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: ds3ttfr84pf8q5ak1fscwhq87dkjgenc Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ot0qgosl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf01.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7FCA740054 X-HE-Tag: 1653893400-970872 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 20.05.22 09:06, zhenwei pi wrote: > Origianlly, unpoison_memory() is only used by hwpoison-inject, and > unpoisons a page which is poisoned by hwpoison-inject too. The kernel PTE > entry has no change during software poison/unpoison. > > On a virtualization platform, it's possible to fix hardware corrupted page > by hypervisor, typically the hypervisor remaps the error HVA(host virtual > address). So add a new parameter 'const char *reason' to show the reason > called by. > > Once the corrupted page gets fixed, the guest kernel needs put page to > buddy. Reuse the page and hit the following issue(Intel Platinum 8260): > BUG: unable to handle page fault for address: ffff888061646000 > #PF: supervisor write access in kernel mode > #PF: error_code(0x0002) - not-present page > PGD 2c01067 P4D 2c01067 PUD 61aaa063 PMD 10089b063 PTE 800fffff9e9b9062 > Oops: 0002 [#1] PREEMPT SMP NOPTI > CPU: 2 PID: 31106 Comm: stress Kdump: loaded Tainted: G M OE 5.18.0-rc6.bm.1-amd64 #6 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 > RIP: 0010:clear_page_erms+0x7/0x10 > > The kernel PTE entry of the fixed page is still uncorrected, kernel hits > page fault during prep_new_page. So add 'bool reset_kpte' to get a change > to fix the PTE entry if the page is fixed by hypervisor. Why don't we want to do that for the hwpoison case? > > Signed-off-by: zhenwei pi > --- > include/linux/mm.h | 2 +- > mm/hwpoison-inject.c | 2 +- > mm/memory-failure.c | 26 +++++++++++++++++++------- > 3 files changed, 21 insertions(+), 9 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 665873c2788c..7ba210e86401 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3191,7 +3191,7 @@ enum mf_flags { > extern int memory_failure(unsigned long pfn, int flags); > extern void memory_failure_queue(unsigned long pfn, int flags); > extern void memory_failure_queue_kick(int cpu); > -extern int unpoison_memory(unsigned long pfn); > +extern int unpoison_memory(unsigned long pfn, bool reset_kpte, const char *reason); > extern int sysctl_memory_failure_early_kill; > extern int sysctl_memory_failure_recovery; > extern void shake_page(struct page *p); > diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c > index 5c0cddd81505..0dd17ba98ade 100644 > --- a/mm/hwpoison-inject.c > +++ b/mm/hwpoison-inject.c > @@ -57,7 +57,7 @@ static int hwpoison_unpoison(void *data, u64 val) > if (!capable(CAP_SYS_ADMIN)) > return -EPERM; > > - return unpoison_memory(val); > + return unpoison_memory(val, false, "hwpoison-inject"); s/hwpoison-inject/hwpoison/ or maybe s/hwpoison-inject/debugfs/ > } > > DEFINE_DEBUGFS_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n"); > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 95c218bb0a37..a46de3be1dd7 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -2132,21 +2132,26 @@ core_initcall(memory_failure_init); > /** > * unpoison_memory - Unpoison a previously poisoned page > * @pfn: Page number of the to be unpoisoned page > + * @reset_kpte: Reset the PTE entry for kmap > + * @reason: The callers tells why unpoisoning the page > * > - * Software-unpoison a page that has been poisoned by > - * memory_failure() earlier. > + * Unpoison a page that has been poisoned by memory_failure() earlier. > * > - * This is only done on the software-level, so it only works > - * for linux injected failures, not real hardware failures > + * For linux injected failures, there is no need to reset PTE entry. > + * It's possible to fix hardware memory failure on a virtualization platform, > + * once hypervisor fixes the failure, guest needs put page back to buddy and > + * reset the PTE entry in kernel. Why can't we do this unconditionally? Just check if the PTE is poisoned, and if so, reset it. -- Thanks, David / dhildenb