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 X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 6A6C2C433FE for ; Fri, 4 Dec 2020 17:25:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9883422B43 for ; Fri, 4 Dec 2020 17:25:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9883422B43 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D8AA76B005C; Fri, 4 Dec 2020 12:25:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3BCE6B005D; Fri, 4 Dec 2020 12:25:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C51C56B006E; Fri, 4 Dec 2020 12:25:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id AED046B005C for ; Fri, 4 Dec 2020 12:25:34 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 55516180AD806 for ; Fri, 4 Dec 2020 17:25:34 +0000 (UTC) X-FDA: 77556276588.20.horse42_29049ce273c6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 2F187180C07AB for ; Fri, 4 Dec 2020 17:25:34 +0000 (UTC) X-HE-Tag: horse42_29049ce273c6 X-Filterd-Recvd-Size: 3422 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Fri, 4 Dec 2020 17:25:33 +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 316DFAD20; Fri, 4 Dec 2020 17:25:32 +0000 (UTC) Subject: Re: [PATCH 3/7] mm,madvise: call soft_offline_page() without MF_COUNT_INCREASED To: Oscar Salvador Cc: akpm@linux-foundation.org, n-horiguchi@ah.jp.nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naoya Horiguchi , Dan Williams References: <20201119105716.5962-1-osalvador@suse.de> <20201119105716.5962-4-osalvador@suse.de> <2aa4bf71-443b-9b9b-b761-12761263dfec@suse.cz> <20201201113511.GA22242@linux> From: Vlastimil Babka Message-ID: <840d4669-ae3f-b7c4-6132-e20d1bf9e952@suse.cz> Date: Fri, 4 Dec 2020 18:25:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201201113511.GA22242@linux> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 12/1/20 12:35 PM, Oscar Salvador wrote: > On Wed, Nov 25, 2020 at 07:20:33PM +0100, Vlastimil Babka wrote: >> On 11/19/20 11:57 AM, Oscar Salvador wrote: >> > 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. >> >> Well, but can't it go away due to reclaim, migration or whatever? > > Yes, it can. > >> > @@ -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. >> >> Sure they have to. We might just be unexpectedly messing with other process' >> memory. Or does anything else prevent that? > > No, nothing does, and I have to confess that I managed to confuse myself here. > If we release such page and that page ends up in buddy, nothing prevents someone > else to get that page, and then we would be messing with other process memory. > > I guess the right thing to do is just to make sure we got that page and that > that page remains pinned as long as the memory failure handling goes. OK, so that means we don't introduce this race for MADV_SOFT_OFFLINE, but it's already (and still) there for MADV_HWPOISON since Dan's 23e7b5c2e271 ("mm, madvise_inject_error: Let memory_failure() optionally take a page reference") no? > I will remove those patches from the patchset and re-submit with only the > refactoring and pcp-disabling. > > Thanks Vlastimil >