Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1616534pxp; Thu, 17 Mar 2022 12:48:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzegz+CYOfmkJtw08Y4eG0sRxKIFdJKnZnUP5qj4Bjzfgy8V51eig5qfZgebCmzrvanpToT X-Received: by 2002:a17:902:bcc6:b0:153:53c2:7e2c with SMTP id o6-20020a170902bcc600b0015353c27e2cmr6550870pls.14.1647546526986; Thu, 17 Mar 2022 12:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546526; cv=none; d=google.com; s=arc-20160816; b=j7uPG7//ljTA8F929m/6zfmTtpBT8KGSKADUvzN1v5PxhKkryJ4Z4790Qxo0+80rFs Uwnbfv8raIjKlqD7voxrCRIaGwl4f2o/JLa1zsz0IkYk2ZLyhQvLD5jnxVYYViRtNEql y+ZDORxapvwm4/X3nfqKmbA7Pk9x4plVCqJx/1qhhOqWx5fyYChDw4Ltl8AvqWyVcMJs LItwk5K1kj3m3lkAGdVGeZmF3bp8NHQHVn13pPOE8F6F8QrmpvCyp9uR97LqwHQHYFTx yCVqUHSEJF82jYHZGHme7lP82SPUDbE1fo/JnwDLvtvASKG6PzFijTjSw0aawN3RjRVG baTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=CxHgpSNZZuEtV5slXCliwgtbxDqjHZAN89PA6Kha9DQ=; b=AQw6zJvRTzvbR6cAmZ5CX/9Q1++e4gEHkeS9qEHPW+G4UkWTKPpgftpls5BwmgHhT+ YhgnCDqHxKmqDSSftXEfajSdZLz1+qL1o1X8cE2UDPpuCmEU8sMcW5ntdA9OlsIufR9F WYMRcvyyOLB1kS6941HcN/C5lvayH2fGKiXB9vJRSSGOJlWxz4WoYttpb2yvUYYhhJug WbFzLNWr456eBLd9fXY/ytGDAWvkVGNjEZKrnFrLPhXyatMX5/0KdV+dywkMZhslGuAX jJYKhyLpe0SOvR2S55vEHFxddiLRBjNMM1eWvrX5XqAnnsZo0LJS2XHoY8rx+vk5mmT1 yPvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iPAspoN1; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d2-20020a656b82000000b003816043f0efsi3132796pgw.740.2022.03.17.12.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:48:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iPAspoN1; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6E2ED255A8F; Thu, 17 Mar 2022 12:47:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236497AbiCQQZY (ORCPT + 99 others); Thu, 17 Mar 2022 12:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbiCQQZW (ORCPT ); Thu, 17 Mar 2022 12:25:22 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8103ABB92A; Thu, 17 Mar 2022 09:24:05 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id t14so3028247pgr.3; 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=rnYnkAxudSxOCXZbojhRtiTVTIV2n2vFApaO8Ge6stD9ACvpkTn+9J26+nacjhL8ai V9PZ9SNjqS8Yi+R59OiIzH4eqGjRF2SXc+QB9h6rM36Ry86fRGNFNfSqzOaOmge4pyzn Pob5XVmFPFi19kVXUrj1MNpZklkPMlPhV4QcTBleshnH4KYwDn7mg3SCc5RjeFGYyNDX Hoj0g67+ruSD9sYR/c8XkGSayNQRyuqmOKGhtESAQZDgVwsNAgZ72U/y2Wo9uyPQy+Hy kYPHzWGll7NYH+RWuDUm2hJNfWdOa2+WyKCIcs6k61QhO92rE9+8MCU7HSxgQuyD5E5s RYhg== X-Gm-Message-State: AOAM5338gSGrqK2WH4CF+8Gg3JLGG1Nep1vLwppUE8vhD6Sel74XLE2g 07dVP0tlB9A2QVFdBK/h7yCvBmq9oP4= 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) Sender: Minchan Kim 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >