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 2027AC433EF for ; Mon, 21 Mar 2022 15:34:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BE446B0072; Mon, 21 Mar 2022 11:34:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86CD46B0073; Mon, 21 Mar 2022 11:34:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7348F6B0074; Mon, 21 Mar 2022 11:34:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 60F086B0072 for ; Mon, 21 Mar 2022 11:34:12 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1AF38A45C5 for ; Mon, 21 Mar 2022 15:34:12 +0000 (UTC) X-FDA: 79268789544.20.3F6755D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id 7325D40038 for ; Mon, 21 Mar 2022 15:34:11 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2F847210EE; Mon, 21 Mar 2022 15:34:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1647876850; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VNyX+fb8O+Otr4c7FYr7v/jIn4CB8StYw4c40MavmeE=; b=Ru+P1yK2Jw1QXzAyhjr0RARsHnQE7zJV28GEnbEs4xJuTY3Xf5qtvm/QzeTKVVyypizHIj uwJd/qnMAsrfNC1aXFENGw4LABp31GnpyUUfUQDpMqoJdGXPRstyzHVslVCOrBll2SAkmo 0BfBq2jRMc1eqVe0T+AsJsJOXmz90QY= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 76B2CA3B87; Mon, 21 Mar 2022 15:34:09 +0000 (UTC) Date: Mon, 21 Mar 2022 16:34:08 +0100 From: Michal Hocko To: Charan Teja Kalla Cc: akpm@linux-foundation.org, surenb@google.com, vbabka@suse.cz, rientjes@google.com, sfr@canb.auug.org.au, edgararriaga@google.com, minchan@kernel.org, nadav.amit@gmail.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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4f091776142f2ebf7b94018146de72318474e686.1647008754.git.quic_charante@quicinc.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7325D40038 X-Stat-Signature: bczkk669w9nguomiwhfpcwoaqinan9qr Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Ru+P1yK2; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf04.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-HE-Tag: 1647876851-136123 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 Fri 11-03-22 20:59:06, Charan Teja Kalla wrote: > The process_madvise() system call is expected to skip holes in vma > passed through 'struct iovec' vector list. Where is this assumption coming from? From the man page I can see: : The advice might be applied to only a part of iovec if one of its : elements points to an invalid memory region in the remote : process. No further elements will be processed beyond that : point. > 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. I am not sure I follow. With your previous patch and -ENOMEM from do_madvise you get the the answer you are looking for, no? With this applied you are loosing the information that some of the iters are not mapped or has a hole. Which might be a useful information especially when processing on remote tasks which are free to manipulate their address spaces. > Fixes: ecb8ac8b1f14("mm/madvise: introduce process_madvise() syscall: an external memory hinting API") > Cc: # 5.10+ > Signed-off-by: Charan Teja Kalla > --- > Changes in V2: > -- Fixed handling of ENOMEM by process_madvise(). > -- Patch doesn't exist in V1. > > mm/madvise.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index e97e6a9..14fb76d 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1426,9 +1426,16 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > > while (iov_iter_count(&iter)) { > iovec = iov_iter_iovec(&iter); > + /* > + * do_madvise returns ENOMEM if unmapped holes are present > + * in the passed VMA. process_madvise() is expected to skip > + * unmapped holes passed to it in the 'struct iovec' list > + * and not fail because of them. Thus treat -ENOMEM return > + * from do_madvise as valid and continue processing. > + */ > ret = do_madvise(mm, (unsigned long)iovec.iov_base, > iovec.iov_len, behavior); > - if (ret < 0) > + if (ret < 0 && ret != -ENOMEM) > break; > iov_iter_advance(&iter, iovec.iov_len); > } > -- > 2.7.4 -- Michal Hocko SUSE Labs