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 EFF98C433EF for ; Tue, 12 Apr 2022 08:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66A276B0078; Tue, 12 Apr 2022 04:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61AE26B007B; Tue, 12 Apr 2022 04:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 509186B007D; Tue, 12 Apr 2022 04:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 41EBA6B0078 for ; Tue, 12 Apr 2022 04:31:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 020F281E60 for ; Tue, 12 Apr 2022 08:31:21 +0000 (UTC) X-FDA: 79347557604.16.09DBAAC Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf29.hostedemail.com (Postfix) with ESMTP id 65256120008 for ; Tue, 12 Apr 2022 08:31:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 35DFD21605; Tue, 12 Apr 2022 08:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649752280; h=from:from:reply-to: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=J4oZ5Id2h6it4fiDyrJmuUcSlwYpQ6Eq5cB+JfWrgi8=; b=0DMVcKFWhv7nf6NCfI+3WvajoyThHlsLQKyG1fEXnZFBWsfclaH9b7GM7j4HrY+dl5krhE Em75RXISBSgf95kQWvq2ks6s8SE6xQjeg5nwqdzemHh95Rs6E1Hf4/KgmJQGD7E295mM3/ sXgjarjf8NxVCd0HlE7lALHTvsLUcM0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649752280; h=from:from:reply-to: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=J4oZ5Id2h6it4fiDyrJmuUcSlwYpQ6Eq5cB+JfWrgi8=; b=14E8a9dM2gvIlMFQ6SiT0gWuvalTrf0waJ3kOsTa4H0ISNe1PmCPOrouanZwvsvvp6TKOP Trdl0ED0QG0T6UDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DF89A13780; Tue, 12 Apr 2022 08:31:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Gok9M9c4VWKgFQAAMHmgww (envelope-from ); Tue, 12 Apr 2022 08:31:19 +0000 Date: Tue, 12 Apr 2022 10:31:18 +0200 From: Oscar Salvador To: Xu Yu Cc: linux-mm@kvack.org, akpm@linux-foundation.org Subject: Re: [PATCH] mm/memory-failure.c: bail out early if huge zero page Message-ID: References: <49273e6688d7571756603dac996692a15f245d58.1649603963.git.xuyu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49273e6688d7571756603dac996692a15f245d58.1649603963.git.xuyu@linux.alibaba.com> X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 9nkhym1194qftazft8ocgg4gsfjm44mr Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0DMVcKFW; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=14E8a9dM; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.28 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Rspamd-Queue-Id: 65256120008 X-HE-Tag: 1649752281-947133 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 Sun, Apr 10, 2022 at 11:22:34PM +0800, Xu Yu wrote: > Kernel panic when injecting memory_failure for the global huge_zero_page, > when CONFIG_DEBUG_VM is enabled, as follows. ... > In fact, huge_zero_page is unhandlable currently in either soft offline > or memory failure injection. With CONFIG_DEBUG_VM disabled, > huge_zero_page is bailed out when checking HWPoisonHandlable() in > get_any_page(), or checking page mapping in split_huge_page_to_list(). > > This makes huge_zero_page bail out early in madvise_inject_error(), and > panic above won't happen again. I would not special case this in madvise_inject_error() but rather handle it in memory-failure code. We do already have HWPoisonHandlable(), which tells us whether the page is of a type we can really do something about, so why not add another check in HWPoisonHandlable() for huge_zero_page(), and have that checked in memory_failure(). Something like (untested): diff --git a/mm/memory-failure.c b/mm/memory-failure.c index dcb6bb9cf731..dccd0503f803 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1181,6 +1181,10 @@ static inline bool HWPoisonHandlable(struct page *page, unsigned long flags) { bool movable = false; + /* Can't handle huge_zero_page() */ + if(is_huge_zero_page(compound_head(page))) + return false; + /* Soft offline could mirgate non-LRU movable pages */ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page)) movable = true; @@ -1796,6 +1800,10 @@ int memory_failure(unsigned long pfn, int flags) res = -EBUSY; goto unlock_mutex; } + } else if(!HWPoisonHandable(p)) { + action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); + res = -EBUSY; + goto unlock_mutex; } if (PageTransHuge(hpage)) { It can certainly be prettier, but you can get the idea. > > Reported-by: Abaci > Signed-off-by: Xu Yu > --- > mm/madvise.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 1873616a37d2..03ad50d222e0 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1079,7 +1079,7 @@ static int madvise_inject_error(int behavior, > > for (; start < end; start += size) { > unsigned long pfn; > - struct page *page; > + struct page *page, *head; > int ret; > > ret = get_user_pages_fast(start, 1, 0, &page); > @@ -1087,12 +1087,21 @@ static int madvise_inject_error(int behavior, > return ret; > pfn = page_to_pfn(page); > > + head = compound_head(page); > + if (unlikely(is_huge_zero_page(head))) { > + pr_warn("Unhandlable attempt to %s pfn %#lx at process virtual address %#lx\n", > + behavior == MADV_SOFT_OFFLINE ? "soft offline" : > + "inject memory failure for", > + pfn, start); > + return -EINVAL; > + } > + > /* > * When soft offlining hugepages, after migrating the page > * we dissolve it, therefore in the second loop "page" will > * no longer be a compound page. > */ > - size = page_size(compound_head(page)); > + size = page_size(head); > > if (behavior == MADV_SOFT_OFFLINE) { > pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", > -- > 2.20.1.2432.ga663e714 > > -- Oscar Salvador SUSE Labs