Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753379AbdHKRHZ (ORCPT ); Fri, 11 Aug 2017 13:07:25 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:41273 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752781AbdHKRHY (ORCPT ); Fri, 11 Aug 2017 13:07:24 -0400 Subject: Re: [PATCH 2/2] mm,fork: introduce MADV_WIPEONFORK To: Rik van Riel , Michal Hocko Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, fweimer@redhat.com, colm@allcosts.net, akpm@linux-foundation.org, keescook@chromium.org, luto@amacapital.net, wad@chromium.org, mingo@kernel.org, kirill@shutemov.name, dave.hansen@intel.com References: <20170806140425.20937-1-riel@redhat.com> <20170806140425.20937-3-riel@redhat.com> <20170810152352.GZ23863@dhcp22.suse.cz> <1502464992.6577.48.camel@redhat.com> <6a3e2dbe-6274-4402-0716-88f4fbda73dd@oracle.com> <1502470781.6577.49.camel@redhat.com> From: Mike Kravetz Message-ID: Date: Fri, 11 Aug 2017 10:07:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1502470781.6577.49.camel@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2203 Lines: 66 On 08/11/2017 09:59 AM, Rik van Riel wrote: > On Fri, 2017-08-11 at 09:36 -0700, Mike Kravetz wrote: >> On 08/11/2017 08:23 AM, Rik van Riel wrote: >>> On Thu, 2017-08-10 at 17:23 +0200, Michal Hocko wrote: >>>> On Sun 06-08-17 10:04:25, Rik van Riel wrote: >>>> [...] >>>>> diff --git a/kernel/fork.c b/kernel/fork.c >>>>> index 17921b0390b4..db1fb2802ecc 100644 >>>>> --- a/kernel/fork.c >>>>> +++ b/kernel/fork.c >>>>> @@ -659,6 +659,13 @@ static __latent_entropy int >>>>> dup_mmap(struct >>>>> mm_struct *mm, >>>>> tmp->vm_flags &= ~(VM_LOCKED | >>>>> VM_LOCKONFAULT); >>>>> tmp->vm_next = tmp->vm_prev = NULL; >>>>> file = tmp->vm_file; >>>>> + >>>>> + /* With VM_WIPEONFORK, the child gets an empty >>>>> VMA. */ >>>>> + if (tmp->vm_flags & VM_WIPEONFORK) { >>>>> + tmp->vm_file = file = NULL; >>>>> + tmp->vm_ops = NULL; >>>>> + } >>>> >>>> What about VM_SHARED/|VM)MAYSHARE flags. Is it OK to keep the >>>> around? >>>> At >>>> least do_anonymous_page SIGBUS on !vm_ops && VM_SHARED. Or do I >>>> miss >>>> where those flags are cleared? >>> >>> Huh, good spotting. That makes me wonder why the test case that >>> Mike and I ran worked just fine on a MAP_SHARED|MAP_ANONYMOUS VMA, >>> and returned zero-filled memory when read by the child process. >> >> Well, I think I still got a BUG with a MAP_SHARED|MAP_ANONYMOUS vma >> on >> your v2 patch. Did not really want to start a discussion on the >> implementation until the issue of exactly what VM_WIPEONFORK was >> supposed >> to do was settled. > > It worked here, but now I don't understand why :) > >>> >>> OK, I'll do a minimal implementation for now, which will return >>> -EINVAL if MADV_WIPEONFORK is called on a VMA with MAP_SHARED >>> and/or an mmapped file. >>> >>> It will work the way it is supposed to with anonymous MAP_PRIVATE >>> memory, which is likely the only memory it will be used on, anyway. >>> >> >> Seems reasonable. >> >> You should also add VM_HUGETLB to those returning -EINVAL. IIRC, a >> VM_HUGETLB vma even without VM_SHARED expects vm_file != NULL. > > In other words (flags & MAP_SHARED || vma->vm_file) would catch > hugetlbfs, too? Yes, that should catch hugetlbfs. -- Mike Kravetz