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 CEBD8C433EF for ; Thu, 17 Mar 2022 16:24:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3262D8D0002; Thu, 17 Mar 2022 12:24:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8F78D0001; Thu, 17 Mar 2022 12:24:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 104A98D0002; Thu, 17 Mar 2022 12:24:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F04048D0001 for ; Thu, 17 Mar 2022 12:24:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A3D0A182888AA for ; Thu, 17 Mar 2022 16:24:06 +0000 (UTC) X-FDA: 79254400092.22.A62BDCF Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf02.hostedemail.com (Postfix) with ESMTP id 3ACFC80010 for ; Thu, 17 Mar 2022 16:24:06 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id a5so7255606pfv.2 for ; Thu, 17 Mar 2022 09:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CxHgpSNZZuEtV5slXCliwgtbxDqjHZAN89PA6Kha9DQ=; b=iPAspoN1cg41/RL92HB4FhRGyagjBvagM5CpfCMVgHIe/NOZVcb+ykblGBqEVqTLtz xF8Skv9VuPLU37EdRRSifh8gynYM+K5ULxGEmG3ByTmueZrXPQIj6+ouCaCTlWRFLlNF otsnBI08np3EV3drQhJ0xTW/L483Q5q85CxzujVmQ0LH7ytdX/neCpf/MYBCnR3RrKDu 10Wxy4Kr6ABKpryrufH/P8PxG6GplEO/7NTNESKE5F2SHT3bVkrKcobomZ84iUTfIYim KRl3H4JGmn10rTxV4JZI/N1J7jWwvpt7DWmPPgNB/x3LSmoZPmAmkDyFeNBrPKXGpLju VkpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=CxHgpSNZZuEtV5slXCliwgtbxDqjHZAN89PA6Kha9DQ=; b=GAnVVf1ZwRhE0Yi7890wxm47BdRk582McLzSmOVZMlTb6d5QllsFy5ptpJ/jSldIXo jkWm5FKhX9xJf52qXS3tFNCU4D5JMPz/0UYKIvTaKWXS0z97INF4hMa85jd4ioIXhJgz BEx9ifBnJsqSC75Z8EcCTMmrrzbMCrxuqmEPIuaMz8LxtwFrQbge+9ifwxHntv/MgkAG FqnrQjSf50nIsdRLTHMs4/fQNX0KHRNU2n1ssfWmivu2chU2VODaQ19ARu89w2QT5M9B ElTIrv1dXn07xhpjm8NtMa+hUcLRnx/bgUNPV70u8l81mEbVtNuaiqIWapwQ/7qq5XyI j/Eg== X-Gm-Message-State: AOAM531uu7+zki81l0NUjVK+S/ggdXtDxNeIgm8EOxkDTBpSg4+gjQZm Jr/2uU5vNqunnyFzTxW9XCY= X-Google-Smtp-Source: ABdhPJxzBcB7aeTPqJrx6jD8KKAt6PoUG1RqtUoPQyS+6jB+C9zd1Ix29rCWyHkQ1xVZp+b2p2Sjew== X-Received: by 2002:a63:cd:0:b0:382:1204:84f6 with SMTP id 196-20020a6300cd000000b00382120484f6mr2059100pga.109.1647534244814; Thu, 17 Mar 2022 09:24:04 -0700 (PDT) Received: from google.com ([2620:15c:211:201:b625:fd41:4746:7bf5]) by smtp.gmail.com with ESMTPSA id b5-20020a056a0002c500b004f6dbd217c9sm6726611pft.108.2022.03.17.09.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 09:24:04 -0700 (PDT) Date: Thu, 17 Mar 2022 09:24:01 -0700 From: Minchan Kim To: Charan Teja Kalla Cc: Andrew Morton , surenb@google.com, vbabka@suse.cz, rientjes@google.com, sfr@canb.auug.org.au, edgararriaga@google.com, nadav.amit@gmail.com, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "# 5 . 10+" Subject: Re: [PATCH V2,2/2] mm: madvise: skip unmapped vma holes passed to process_madvise Message-ID: References: <4f091776142f2ebf7b94018146de72318474e686.1647008754.git.quic_charante@quicinc.com> <20220315164807.7a9cf1694ee2db8709a8597c@linux-foundation.org> <5428f192-1537-fa03-8e9c-4a8322772546@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5428f192-1537-fa03-8e9c-4a8322772546@quicinc.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3ACFC80010 X-Stat-Signature: oqqtk3y4owgwcf9mc3zb4bu8w41i1xjy X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iPAspoN1; spf=pass (imf02.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-HE-Tag: 1647534246-340485 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, Mar 16, 2022 at 07:49:38PM +0530, Charan Teja Kalla wrote: > Thanks Andrew and Minchan. > > On 3/16/2022 7:13 AM, Minchan Kim wrote: > > On Tue, Mar 15, 2022 at 04:48:07PM -0700, Andrew Morton wrote: > >> On Tue, 15 Mar 2022 15:58:28 -0700 Minchan Kim wrote: > >> > >>> On Fri, Mar 11, 2022 at 08:59:06PM +0530, Charan Teja Kalla wrote: > >>>> The process_madvise() system call is expected to skip holes in vma > >>>> passed through 'struct iovec' vector list. But do_madvise, which > >>>> process_madvise() calls for each vma, returns ENOMEM in case of unmapped > >>>> holes, despite the VMA is processed. > >>>> Thus process_madvise() should treat ENOMEM as expected and consider the > >>>> VMA passed to as processed and continue processing other vma's in the > >>>> vector list. Returning -ENOMEM to user, despite the VMA is processed, > >>>> will be unable to figure out where to start the next madvise. > >>>> Fixes: ecb8ac8b1f14("mm/madvise: introduce process_madvise() syscall: an external memory hinting API") > >>>> Cc: # 5.10+ > >>> > >>> Hmm, not sure whether it's stable material since it changes semantic of > >>> API. It would be better to change the semantic from 5.19 with man page > >>> update to specify the change. > >> > >> It's a very desirable change and it makes the code match the manpage > >> and it's cc:stable. I think we should just absorb any transitory > >> damage which this causes people. I doubt if there will be much - if > >> anyone was affected by this they would have already told us that it's > >> broken? > > > > > > process_madvise fails to return exact processed bytes at several cases > > if it encounters the error, such as, -EINVAL, -EINTR, -ENOMEM in the > > middle of processing vmas. And now we are trying to make exception for > > change for only hole? > I think EINTR will never return in the middle of processing VMA's for > the behaviours supported by process_madvise(). > > It can return EINTR when: > ------------------------- > 1) PTRACE_MODE_READ is being checked in mm_access() where it is waiting > on task->signal->exec_update_lock. EINTR returned from here guarantees > that process_madvise() didn't event start processing. > https://elixir.bootlin.com/linux/v5.16.14/source/mm/madvise.c#L1264 --> > https://elixir.bootlin.com/linux/v5.16.14/source/kernel/fork.c#L1318 > > 2) The process_madvise() started processing VMA's but the required > behavior on a VMA needs mmap_write_lock_killable(), from where EINTR is > returned. The current behaviours supported by process_madvise(), > MADV_COLD, PAGEOUT, WILLNEED, just need read lock here. > https://elixir.bootlin.com/linux/v5.16.14/source/mm/madvise.c#L1164 > **Thus I think no way for EINTR can be returned by process_madvise() in > the middle of processing.** . No? > > for EINVAL: > ----------- > The only case, I can think of, where EINVAL can be returned in the > middle of processing is in examples like, given range contains VMA's > with a hole in between and one of the VMA contains the pages that fails > can_madv_lru_vma() condition. > So, it's a limitation that this returns -EINVAL though some bytes are > processed. > OR > Since there exists still some invalid bytes processed it is valid to > return -EINVAL here and user has to check the address range sent? > > for ENOMEM: > ---------- > Though complete range is processed still returns ENOMEM. IMO, This > shouldn't be treated as error which the patch is targeted for. Then > there is limitation case that you mentioned below where it returns > positive processes bytes even though it didn't process anything if it > couldn't find any vma for the first iteration in madvise_walk_vmas > > I think the above limitations with EINVAL and ENOMEM are arising because > we are relying on do_madvise() functionality which madvise() call uses > to process a single VMA. When 'struct iovec' vector processing interface > is given in a system call, it is the expectation by the caller that this > system call should return the correct bytes processed to help the user > to take the correct decisions. Please correct me If i am wrong here. > > So, should we add the new function say do_process_madvise(), which take > cares of above limitations? or any alternative suggestions here please? What I am thinking now is that the process_madvise needs own iterator(i.e., do_process_madvise) and it should represent exact bytes it addressed with exacts ranges like process_vm_readv/writev. Poviding valid ranges is responsiblity from the user. > > > IMO, it's worth to note in man page. > > > > Or the current patch for just ENOMEM is sufficient here and we just have > to update the man page? > > > In addition, this change returns positive processes bytes even though > > it didn't process anything if it couldn't find any vma for the first > > iteration in madvise_walk_vmas. > > Thanks, > Charan >