Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp72395imm; Fri, 13 Jul 2018 17:35:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeoHJj6b9n/NSsRTe6jkrPumVUSK8aMu4kqr/4PX6lb2/pCyxPGAEzF+OZ+VkLMQJaGND5g X-Received: by 2002:a17:902:7c8b:: with SMTP id y11-v6mr8146160pll.222.1531528546144; Fri, 13 Jul 2018 17:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531528546; cv=none; d=google.com; s=arc-20160816; b=06FJ0RV2mp440UUvGpNGogwCbq+7r5UoDXc/TRlCXNz3Qd2u6sbh3CMtjn3x8+BLOc R4sdcF+NHq5/HYEtlD+QfaNeyTet5tgHyLMT0nCsuALG6I6fYrsoBnXoOL4kNWWiSUBk FqbxinkgzQWE1ka1yvkITsIm4A6VOsxKv/mwfnQ/KZLxj/f2BeJFLNjHIAHzNHhJRfQ1 Kjv51cy8wtqNDpvhW8bd9QHv7iF+lqSS44rIqBszifYDE+Asvt3qjvO9zzZ5eScuwsj6 kFQeMjhyWJJkdUfXzel3a3bCfsapLs5tBfTlKJ+ikGOpL1qThrznzQs1bhR7guJBx1xL cOJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=bcYAEPAfhwjwqoLmOxUJoo6JBA4MU9s1oePpKYOiXts=; b=VfZ6B8Eq8w0RdYcDCLdAROXIOOEF4inKexgU0NfacepGaxfC4A4kK1Ob/U+lk+gvqj QkOvrJqUWmqIJ3j9jEPqEbaIwWdvUQws0ITZYJ7pJraARTErWaGeMLIW0Lz8q9cm9g+U 7S6XMr0+DF0IoqyTklaGevbnD7ETWeiWeDZdDKFD+oCtRFLzOcMmWD28SGIUXKTpnA+3 DTdOYBs3ysEhXgHvbrECPFO+dBmBkCRzxgPs7bxHjDgWHBTMc5SR9d+faULTfYIAIgCP eO6bHssxC/3LqrsaqeuvCW1PT4BD5J1VVgpMQ9VnOtSgs1xbfUJmJ8H71WmJAxsbsVNn JFxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="fw/v9rpV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j129-v6si24603528pgc.186.2018.07.13.17.35.28; Fri, 13 Jul 2018 17:35:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="fw/v9rpV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731402AbeGNAvr (ORCPT + 99 others); Fri, 13 Jul 2018 20:51:47 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:34351 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbeGNAvr (ORCPT ); Fri, 13 Jul 2018 20:51:47 -0400 Received: by mail-oi0-f65.google.com with SMTP id 13-v6so65374487ois.1 for ; Fri, 13 Jul 2018 17:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bcYAEPAfhwjwqoLmOxUJoo6JBA4MU9s1oePpKYOiXts=; b=fw/v9rpV9ehGI1zbCyRXL8YB33GqKMBXhM99/in45IIXsfx9s4vePx/he10iSbiMIi nT0VeqfLfnek3r43bc3A0sAyf3zYF6Y8eCZsLrqHgaZRWnzPvwYSijOsxr1pVDD1bfHq oGuWYfS01YK1L14ZekAITUm8OGz4FlMHNesu41LNBKL9AhjeIVWZ4+ZEJZm/Mo29lGV1 zZklqtgx1dpqClslI0YGdY+KEaWzYhZKcEIEg+gcVJ4ADOMPrcMz3fIx48mOtR/kWw9s B3ZZDjJ8X7fZOJJy9Q7oXyV7GimBZiU6Uu5nDLP/DLhgupWMZJBxLK3+shPi81RfGfwk J/GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bcYAEPAfhwjwqoLmOxUJoo6JBA4MU9s1oePpKYOiXts=; b=lnHRYDpO8zfrzNEd4BXnBVnKpyEg4pw4r+z+jqpn0FiSWxjKHD3YyRFN34vN9NU/tO Ta/zW0d/guAwhoLMF7McniVDBpVuMDKzxrYy8dfswgl341RUANm2UImHgq2sySAEMAu+ oaJRk4d9cVexXf5/YHcYGX6z+4RFyqOKBxyq4zRpTUJRlcrkifBaA/CzNyko/1CjtJ9i NHP3Unk/MW9YIFtW8DFWwE0FE7TGwkO5+xGYd3oT7xcrkDaP3U6Tmj3iL7O6zcTtPkDw k7rVjCgdpMWqVAJ1tsapCEPOXkPClIPzTyH0wBcwh7EcIR7YU/vS08hLHyOFD90SRfaI 6PzQ== X-Gm-Message-State: AOUpUlH3MTNtTp3uMwKF7hiacHswAKeg9nVQPdJ4hQFhJwZUMKN0KRZr R6H6g6uOQwPyelXQMnRef3Gctv8hCz4uXKFczBBDHA== X-Received: by 2002:aca:3c45:: with SMTP id j66-v6mr8602664oia.118.1531528488457; Fri, 13 Jul 2018 17:34:48 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:3495:0:0:0:0:0 with HTTP; Fri, 13 Jul 2018 17:34:48 -0700 (PDT) In-Reply-To: <20180713063125.GA10034@hori1.linux.bs1.fc.nec.co.jp> References: <153074042316.27838.17319837331947007626.stgit@dwillia2-desk3.amr.corp.intel.com> <153074044986.27838.16910122305490506387.stgit@dwillia2-desk3.amr.corp.intel.com> <20180713063125.GA10034@hori1.linux.bs1.fc.nec.co.jp> From: Dan Williams Date: Fri, 13 Jul 2018 17:34:48 -0700 Message-ID: Subject: Re: [PATCH v5 05/11] mm, madvise_inject_error: Let memory_failure() optionally take a page reference To: Naoya Horiguchi Cc: "linux-nvdimm@lists.01.org" , Michal Hocko , "hch@lst.de" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "jack@suse.cz" , "ross.zwisler@linux.intel.com" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 12, 2018 at 11:31 PM, Naoya Horiguchi wrote: > Hello Dan, > > On Wed, Jul 04, 2018 at 02:40:49PM -0700, Dan Williams wrote: >> The madvise_inject_error() routine uses get_user_pages() to lookup the >> pfn and other information for injected error, but it does not release >> that pin. The assumption is that failed pages should be taken out of >> circulation. >> >> However, for dax mappings it is not possible to take pages out of >> circulation since they are 1:1 physically mapped as filesystem blocks, >> or device-dax capacity. They also typically represent persistent memory >> which has an error clearing capability. >> >> In preparation for adding a special handler for dax mappings, shift the >> responsibility of taking the page reference to memory_failure(). I.e. >> drop the page reference and do not specify MF_COUNT_INCREASED to >> memory_failure(). >> >> Cc: Michal Hocko >> Cc: Naoya Horiguchi >> Signed-off-by: Dan Williams >> --- >> mm/madvise.c | 18 +++++++++++++++--- >> 1 file changed, 15 insertions(+), 3 deletions(-) >> >> diff --git a/mm/madvise.c b/mm/madvise.c >> index 4d3c922ea1a1..b731933dddae 100644 >> --- a/mm/madvise.c >> +++ b/mm/madvise.c >> @@ -631,11 +631,13 @@ static int madvise_inject_error(int behavior, >> >> >> for (; start < end; start += PAGE_SIZE << order) { >> + unsigned long pfn; >> int ret; >> >> ret = get_user_pages_fast(start, 1, 0, &page); >> if (ret != 1) >> return ret; >> + pfn = page_to_pfn(page); >> >> /* >> * When soft offlining hugepages, after migrating the page >> @@ -651,17 +653,27 @@ static int madvise_inject_error(int behavior, >> >> if (behavior == MADV_SOFT_OFFLINE) { >> pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", >> - page_to_pfn(page), start); >> + pfn, start); >> >> ret = soft_offline_page(page, MF_COUNT_INCREASED); >> if (ret) >> return ret; >> continue; >> } >> + >> pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", >> - page_to_pfn(page), start); >> + pfn, start); >> + >> + ret = memory_failure(pfn, 0); >> + >> + /* >> + * 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(page_to_pfn(page), MF_COUNT_INCREASED); > > MF_COUNT_INCREASED means that the page refcount for memory error handling > is taken by the caller so you don't have to take one inside memory_failure(). > So this code don't keep with the definition, then another refcount can be > taken in memory_failure() in normal LRU page's case for example. > As a result the error message "Memory failure: %#lx: %s still referenced by > %d users\n" will be dumped in page_action(). > > So if you want to put put_page() in madvise_inject_error(), I think that > > put_page(page); > ret = memory_failure(pfn, 0); > > can be acceptable because the purpose of get_user_pages_fast() here is > just getting pfn, and the refcount itself is not so important. > IOW, memory_failure() is called only with pfn which never changes depending > on the page's status. Ok, I'll resend with the put_page() moved before memory_failure() to make it more clear that memory_failure() is responsible for taking its own reference and that there is no dependency to hold the reference in madvise_inject_error(). > In production system memory_failure() is called via machine check code > without taking any pagecount, so I don't think the this injection interface > is properly mocking the real thing. So I'm feeling that this flag will be > wiped out at some point. Ok, makes sense.