Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1686245pxp; Thu, 10 Mar 2022 10:04:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMEeRLHXpgRYacx2vkofST8CZ1aXHTjxofGYzEeMcMw2Q3nG2pQBPVbfvpYvKVzq09UMTa X-Received: by 2002:a17:907:9495:b0:6da:9602:3ec6 with SMTP id dm21-20020a170907949500b006da96023ec6mr5338947ejc.589.1646935447405; Thu, 10 Mar 2022 10:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646935447; cv=none; d=google.com; s=arc-20160816; b=Zqc4w3rAAhtenlKKTkdo3J1+0h510vwqBHsBkY+DOSeFDKjSefMkUZ21Id8LphDe/y 8TKq9xN7T0Q8B1Rl385XdfuDQB8ZG8DtPQfnZgiCLXtZfTcvy+qLUM9RszwjF7zurKvq K4Hm8H4CSWSqQvJ51RC2aDgJqPp+2cxnAYJWE+wMRwYfYpn5NJRKP17EaOGbebNsAQC+ HzL4xSm2G2ZrKDoUaDa4wcNLv68Gtdi2ASViYLDoNEwZBBbr9Inz9njMoUBn8sxtItQk onxvVDSosH7Llt8lBKzLLbQhz47SAPGjQIU9pdL6QtITsbvMfpzE9KLC78I4mm83cM2/ zF7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/IalRAFcuzbyyT+wYoMtKv0yxgtlvFF8P0B3U3hiXSQ=; b=jdNXzQ8GtT7h1C68lNVE1N4heLvGOVKFYjxXtMW49kN12Iu3VyDOcVFDBmkcmDnrYr twVM4R6JPZFxvstGXvdeCMmYDrQOsSN2ojbQUSlVxiAW23b9yxYBbgF3CA/q6qfwrYO+ idjUGANgrIAd6absvFDL83qWlHHZdXNcd+q7m6O8DLljU8xHzu7AXVsiEsSwz095DAJi Hpuceuvl7Ipmu3EKLY6t2qPPlAPf84fGbkTyk1PyA3O7VKZx62Onv99PoaxgOKYrVZKQ LbBCpj/eRJR5y7xjdcLFjogVQOMyo4+9hUdW6PYCWNMMLbqd5c78bPUI0m3HNi0b6WFo wdSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="i/+u5Rqf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb11-20020a1709071c8b00b006d90af95a8bsi3636004ejc.369.2022.03.10.10.03.40; Thu, 10 Mar 2022 10:04:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="i/+u5Rqf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240853AbiCJJf6 (ORCPT + 99 others); Thu, 10 Mar 2022 04:35:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiCJJf5 (ORCPT ); Thu, 10 Mar 2022 04:35:57 -0500 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85764139CEF for ; Thu, 10 Mar 2022 01:34:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1646904897; x=1678440897; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=/IalRAFcuzbyyT+wYoMtKv0yxgtlvFF8P0B3U3hiXSQ=; b=i/+u5RqfjHoslcV1YQ7rwy2T+vl9VyZ5fhlWMmgeGIkWjuerLtvOr1kH OpcKKh7QfpfZH39HDwE/eo7etj5GZZXOmNlciui3kRGRcJ4KM0PKhwk1r 3ribAEkbKjyk1wEeFSOIVawv33CLXOIjUqbZReVREJPF3bp8mdm/PjR1N 0=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-01.qualcomm.com with ESMTP; 10 Mar 2022 01:34:57 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 01:34:56 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 10 Mar 2022 01:34:34 -0800 Received: from [10.216.27.16] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 10 Mar 2022 01:34:30 -0800 Message-ID: <3846d4ff-c8ab-3c44-1974-fee451894c0d@quicinc.com> Date: Thu, 10 Mar 2022 15:04:26 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] mm: madvise: return correct bytes advised with process_madvise Content-Language: en-US To: Nadav Amit , Minchan Kim CC: Andrew Morton , , Stephen Rothwell , David Rientjes , , Michal Hocko , Linux-MM , Linux Kernel Mailing List References: <1646803679-11433-1-git-send-email-quic_charante@quicinc.com> From: Charan Teja Kalla In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Thanks Amit for the inputs!! On 3/10/2022 12:20 AM, Nadav Amit wrote: > --- > mm/madvise.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 38d0f51..d3b49b3 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1426,15 +1426,21 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > > while (iov_iter_count(&iter)) { > iovec = iov_iter_iovec(&iter); > + /* > + * Even when [start, end) passed to do_madvise covers > + * some unmapped addresses, it continues processing with > + * returning ENOMEM at the end. Thus consider the range > + * as processed when do_madvise() returns ENOMEM. > + * This makes process_madvise() never returns ENOMEM. > + */ > > I fully understand and relate to the basic motivation of this > patch. > > The ENOMEM that this patch checks for, IIUC, is the ENOMEM that is > returned on unmapped holes. Such ENOMEM does not appear, according to > the man page, to be a valid reason to return ENOMEM to userspace. > Presumably process_madvise() is expected to skip unmapped holes > and not to fail because of them> True, that ENOMEM represents the VMA passed contains the unmapped holes. Pasting the Documentation of do_madvise(): * -ENOMEM - addresses in the specified range are not currently * mapped, or are outside the AS of the process. Internally process_madvise() calls do_madvise() in a loop by passing the vma it received in 'struct iovec'. And I too agree here that process_madvise() is expected to process the unmapped holes. > Having said that, I do not think that the check that the patch does > is clean or clearly documented. If it is about the Documentation, how about adding: "Since process_madvise() is expected to process unmapped holes, never return ENOMEM received from do_madvise() to user". If the code changes can be made further cleaner, please suggest. > > In addition, this patch (and some work on process_madvise()) raise > in my mind a couple of questions: > > 1. There are other errors that process_madvise might encounter > and can be propagated back to userspace, but are not > documented. For instance if can_madv_lru_vma() fails on > MADV_COLD, userspace will get EINVAL. EINVAL is not documented > as a valid error-code for such case in either madvise() and > process_madvise() man pages. I agree here with the man page documentations too and felt the same while going through them. For the mentioned case too, in the madvise[1] man page, EINVAL return type is only talked for MADV_DONTNEED and MADV_REMOVE. It should also contains for MADV_PAGEOUT, MADV_COLD and as well for MADV_FREE. The other missing return types, which I came across, in process_madvise are: EINVAL - return from process_madvise_behavior_valid(). EINTR - from mm_access() EACCES - from mm_access() Thanks, Charan