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 93D48C4332F for ; Thu, 1 Dec 2022 23:09:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0D936B0071; Thu, 1 Dec 2022 18:09:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E96B16B0073; Thu, 1 Dec 2022 18:09:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0F976B0074; Thu, 1 Dec 2022 18:09:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BECAB6B0071 for ; Thu, 1 Dec 2022 18:09:27 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 83CD08073A for ; Thu, 1 Dec 2022 23:09:27 +0000 (UTC) X-FDA: 80195280774.13.754A6BE Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf03.hostedemail.com (Postfix) with ESMTP id 2AA252000D for ; Thu, 1 Dec 2022 23:09:25 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kN0ky+0M; dmarc=none; spf=pass (imf03.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669936166; h=from:from:sender: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:dkim-signature; bh=o5GKwF+YckAjgslhLafbmEcGKFCOPh0t+VQtu7Nnu3M=; b=usQ1HDHKhnUArFwDKIfkqqPgQQldwypZa6UoWC+KUND8kgk4QzkY00/mnMlbzZyRozbnwF Pl99Vn54AJL64sqlxAenr+FRp+N4KJFrXwTj9BcqLeFYApQ6knNoTtNdtHBXJutMz+EFE3 2cO0q3trdClld9ZemdFnu1bNNMvV/hs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kN0ky+0M; dmarc=none; spf=pass (imf03.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669936166; a=rsa-sha256; cv=none; b=c4ld+AILe+QSPzOurAAmLA37KM6lnrXizIQ1ejLsdzkDN40Bpy1GQq6gwo+2iltMlyYPL7 U0IJWvRpSoWs71+bcPRLmfpx9iLGdXLDTlxY/NI7kwPwslZgef1F7ot+pL7mwxpako1AuN zj8wI5AEAYoKGBqBkX0JcXG0Ioi3X2c= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 2DF44CE1DC9; Thu, 1 Dec 2022 23:09:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D13C433C1; Thu, 1 Dec 2022 23:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1669936160; bh=H6kYmK1YyifKIU+ZFk85mRczfZDsez8Oh5l6zUZPeSo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kN0ky+0MJjTxQrOcoIFxjgW5sQmC+6iCa5rt4yt4/fUg/IqNXQJcOscPrpszuPb0R VADiRU/u7w0vfU21vUMQM2Id6Kq2qKWPL+GTw4rgthz0/Ppue7v1YPbf0nlmt9bbzc 9/DOBj4asw2SyhvlxDai+zvZMVLnEbDCNTcLGW00= Date: Thu, 1 Dec 2022 15:09:19 -0800 From: Andrew Morton To: Jiaqi Yan Cc: kirill.shutemov@linux.intel.com, kirill@shutemov.name, shy828301@gmail.com, tongtiangen@huawei.com, tony.luck@intel.com, naoya.horiguchi@nec.com, linmiaohe@huawei.com, linux-mm@kvack.org, osalvador@suse.de Subject: Re: [PATCH v8 1/2] mm/khugepaged: recover from poisoned anonymous memory Message-Id: <20221201150919.bc41d6f9269e63fc86b1d17d@linux-foundation.org> In-Reply-To: <20221201005931.3877608-2-jiaqiyan@google.com> References: <20221201005931.3877608-1-jiaqiyan@google.com> <20221201005931.3877608-2-jiaqiyan@google.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: tzcqj1jamc8umqsuojwzwchzftou4ujb X-Spamd-Result: default: False [-0.06 / 9.00]; BAYES_HAM(-2.66)[98.48%]; IRL_BL_25(2.00)[52.25.139.140:received]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; BAD_REP_POLICIES(0.10)[]; R_SPF_ALLOW(0.00)[+a:sin.source.kernel.org]; R_DKIM_ALLOW(0.00)[linux-foundation.org:s=korg]; RCPT_COUNT_SEVEN(0.00)[10]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[linux-foundation.org:+]; RCVD_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DMARC_NA(0.00)[linux-foundation.org]; MID_RHS_MATCH_FROM(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 2AA252000D X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1669936165-443887 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 Wed, 30 Nov 2022 16:59:30 -0800 Jiaqi Yan wrote: > Make __collapse_huge_page_copy return whether copying anonymous pages > succeeded, and make collapse_huge_page handle the return status. > > Break existing PTE scan loop into two for-loops. The first loop copies > source pages into target huge page, and can fail gracefully when running > into memory errors in source pages. If copying all pages succeeds, the > second loop releases and clears up these normal pages. Otherwise, the > second loop rolls back the page table and page states by: > - re-establishing the original PTEs-to-PMD connection. > - releasing source pages back to their LRU list. > > Tested manually: > 0. Enable khugepaged on system under test. > 1. Start a two-thread application. Each thread allocates a chunk of > non-huge anonymous memory buffer. > 2. Pick 4 random buffer locations (2 in each thread) and inject > uncorrectable memory errors at corresponding physical addresses. > 3. Signal both threads to make their memory buffer collapsible, i.e. > calling madvise(MADV_HUGEPAGE). > 4. Wait and check kernel log: khugepaged is able to recover from poisoned > pages and skips collapsing them. > 5. Signal both threads to inspect their buffer contents and make sure no > data corruption. Looks like a nice patchset. I'd like to give it a run in linux-next but we're at -rc7 and we have no review/ack tags. So it should be a post-6.2-rc1 thing. I have a quibble. > --- a/include/linux/highmem.h > +++ b/include/linux/highmem.h > @@ -361,6 +361,27 @@ static inline void copy_highpage(struct page *to, struct page *from) > > #endif > > +/* > + * Machine check exception handled version of copy_highpage. Return number > + * of bytes not copied if there was an exception; otherwise 0 for success. > + * Note handling #MC requires arch opt-in. > + */ > +static inline int copy_mc_highpage(struct page *to, struct page *from) > +{ > + char *vfrom, *vto; > + unsigned long ret; > + > + vfrom = kmap_local_page(from); > + vto = kmap_local_page(to); > + ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE); > + if (ret == 0) > + kmsan_copy_page_meta(to, from); > + kunmap_local(vto); > + kunmap_local(vfrom); > + > + return ret; > +} Why inlined? It's large, it's slow, it's called only from khugepaged.c. A regular out-of-line function which is static to khugepaged.c seems more appropriate?