From patchwork Thu Nov 19 10:57:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 11917129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9D62C2D0E4 for ; Thu, 19 Nov 2020 10:57:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 43F05246EE for ; Thu, 19 Nov 2020 10:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43F05246EE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6F0C06B005C; Thu, 19 Nov 2020 05:57:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3152B6B006C; Thu, 19 Nov 2020 05:57:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF5EE6B005D; Thu, 19 Nov 2020 05:57:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 93EB56B0068 for ; Thu, 19 Nov 2020 05:57:31 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2256F181AEF1A for ; Thu, 19 Nov 2020 10:57:31 +0000 (UTC) X-FDA: 77500866702.26.fire77_110a5ed27342 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 0415E1806F122 for ; Thu, 19 Nov 2020 10:57:30 +0000 (UTC) X-HE-Tag: fire77_110a5ed27342 X-Filterd-Recvd-Size: 2927 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Nov 2020 10:57:30 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 61A7EAD18; Thu, 19 Nov 2020 10:57:29 +0000 (UTC) From: Oscar Salvador To: akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naoya Horiguchi , Oscar Salvador Subject: [PATCH 3/7] mm,madvise: call soft_offline_page() without MF_COUNT_INCREASED Date: Thu, 19 Nov 2020 11:57:12 +0100 Message-Id: <20201119105716.5962-4-osalvador@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201119105716.5962-1-osalvador@suse.de> References: <20201119105716.5962-1-osalvador@suse.de> MIME-Version: 1.0 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: From: Naoya Horiguchi The call to get_user_pages_fast is only to get the pointer to a struct page of a given address, pinning it is memory-poisoning handler's job, so drop the refcount grabbed by get_user_pages_fast(). Note that the target page is still pinned after this put_page() because the current process should have refcount from mapping. Signed-off-by: Naoya Horiguchi Signed-off-by: Oscar Salvador Signed-off-by: Oscar Salvador --- mm/madvise.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index c6b5524add58..7a0f64b93635 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -900,20 +900,23 @@ static int madvise_inject_error(int behavior, */ size = page_size(compound_head(page)); + /* + * The get_user_pages_fast() is just to get the pfn of the + * given address, and the refcount has nothing to do with + * what we try to test, so it should be released immediately. + * This is racy but it's intended because the real hardware + * errors could happen at any moment and memory error handlers + * must properly handle the race. + */ + put_page(page); + if (behavior == MADV_SOFT_OFFLINE) { pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", pfn, start); - ret = soft_offline_page(pfn, MF_COUNT_INCREASED); + ret = soft_offline_page(pfn, 0); } else { pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", pfn, start); - /* - * Drop the page reference taken by get_user_pages_fast(). In - * the absence of MF_COUNT_INCREASED the memory_failure() - * routine is responsible for pinning the page to prevent it - * from being released back to the page allocator. - */ - put_page(page); ret = memory_failure(pfn, 0); }