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 797D6C76196 for ; Fri, 7 Apr 2023 10:14:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED7F7900003; Fri, 7 Apr 2023 06:14:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6125900002; Fri, 7 Apr 2023 06:14:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDCE0900003; Fri, 7 Apr 2023 06:14:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BD5F9900002 for ; Fri, 7 Apr 2023 06:14:17 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8609741408 for ; Fri, 7 Apr 2023 10:14:17 +0000 (UTC) X-FDA: 80654184954.23.EC76278 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf03.hostedemail.com (Postfix) with ESMTP id ABDD520002 for ; Fri, 7 Apr 2023 10:14:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JcECVJwt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of emmir@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=emmir@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680862455; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=quNG0/wNI8R4PE48ZPLbRS2Bu1I51NvVN8NOjnDtCG0=; b=S/VeA0rSUAK4xyjeygKtTwTkj/zQWm8CpljOcJkrHdG6TRIuzbmfrxbxEfbTvodFrOT1M+ iFgmTAZt9GxQ7yPBaH15axnKwxCprXvArY1ariZ0A+P4XDtL9VOE+9kPH9Y3/1wpP2BPSD U3fFShaeWTW71bsCGjAjobKx7advbA0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JcECVJwt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of emmir@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=emmir@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680862455; a=rsa-sha256; cv=none; b=fZ1fZujvNHrNcP8Vj39k87yUMtl7MsyjtcRGt2UPtkeXSovuphOZk6RTNmEMkojxtsi9Gx QW1gDHHZLgHcRgVsHSHtuQknSBAokpXLEa6Fi+jLdBBLpfzHAwalgf0KOOsKcJkih0XxIQ WuGms9wkvUtcv9QAFZH2uibTVvDjbC8= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-93071f06a9dso164205766b.2 for ; Fri, 07 Apr 2023 03:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680862454; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=quNG0/wNI8R4PE48ZPLbRS2Bu1I51NvVN8NOjnDtCG0=; b=JcECVJwtE1OnPOTAeOUPTVfA5DreOqkA9WYtxG4fnxJ2f84SN0+8ur0Ij38TZ8F0Ey +E13rWXKyFkyiraUO9dvaxcoIGBpad6Smc5H/L0RqNZIZAWzdTcVOdfJOfMIm8jSVfCa dVUOxoHjI8FYYh81x6bvI4Iyqv1qpTo/1PFxUIzz4uNQycwswnWKDnG67CpXYPbcRKgr qy60/lnshum8MWT71alOWw3DaYY+8VovHIAVLaq4nbKhDRIvehY2B7kz/VcMFOHLtrVZ pvzCSfY9mGlE9CYYde3Oac6L/GEcJ8D3gTkfFQ9fofuHnwENI/JreGFoq4iROZS9ApaL QyKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680862454; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=quNG0/wNI8R4PE48ZPLbRS2Bu1I51NvVN8NOjnDtCG0=; b=av2pfu/spwE5bJIiJxB25KlwWdG4PRA/1l7MpMwCMIeRDfkpYfhTLbUpBFl+i09XId tbnz0PjcIUFXXGM/pLXzoK+N3iz0Z5Sc92Yg5xVs8/75OIq6bBoUJ9X4whJUEENpVUFp tenXwilYAMrtfPcdyyG0eDGrqsjfJnsbn5vZshflm5U7QeujUa96QyX2jC4wLXphBunl Y0EDPF9KQSqdwX309oZyEoZ1V8DpIescQrXJaXwfgQ8OWd+/PX0qNUaHAfEOfZ/LLa+G pd1CvNXG7PuT33vrJwdKZZTlSqpfRLLkTwzI0wO7vnZ2jthQFXpapFetTy91UHGCKTG6 TWkg== X-Gm-Message-State: AAQBX9es8MICcy1oyJBPq0t5jti9HvFgQOL4u5cpDbF0iFKXQ5n7MfSX L3c23spYnHPSXufnK/A67rW1Kw6O1Kxevv3Ofas+GQ== X-Google-Smtp-Source: AKy350aXhjdkSqobczCxGxZfYh9g2IVUgJJqiGQ7eeBTICfWYwKlrYT86twOyByKnkSZt/pnAlZQTgEbn3ZN2++tDSk= X-Received: by 2002:a50:cd84:0:b0:4ad:6052:ee90 with SMTP id p4-20020a50cd84000000b004ad6052ee90mr1254691edi.7.1680862454074; Fri, 07 Apr 2023 03:14:14 -0700 (PDT) MIME-Version: 1.0 References: <20230406074005.1784728-1-usama.anjum@collabora.com> <20230406074005.1784728-3-usama.anjum@collabora.com> <0351b563-5193-6431-aa9c-c5bf5741b791@collabora.com> <8a837998-604f-a871-729e-aa274a621481@collabora.com> In-Reply-To: From: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Date: Fri, 7 Apr 2023 12:14:02 +0200 Message-ID: Subject: Re: [PATCH v12 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs To: Muhammad Usama Anjum Cc: Mike Rapoport , Peter Xu , David Hildenbrand , Andrew Morton , Andrei Vagin , Danylo Mocherniuk , Paul Gofman , Cyrill Gorcunov , Nadav Amit , Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Matthew Wilcox , Pasha Tatashin , Axel Rasmussen , "Gustavo A . R . Silva" , Dan Williams , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Greg KH , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ABDD520002 X-Stat-Signature: 8mmyztixz94p8nz4u395oyof13w5yxje X-HE-Tag: 1680862455-491711 X-HE-Meta: U2FsdGVkX1+z8Lsw8K94jo329XjgMtk8U1Hg5as4s1FViOrkcH5PjAahVmNwRMtGky2hWIUHZ6C2fznXyKU124LhlTB2Uy2HpbR+f/xm+t/RiT0pWkUxMWkGHPT4rw4JO2TjYJmK1GHfs3I118rxAeNItQLh57L74Xehf2p6RYazUtS1OeV9wNYLmRcgdZQM8pwgMoC6KMN9MhN7QHATEF1WwvLHLc4a5Wss8hhuS/ZoiViz08LtBqukOkYhNOKCQejX3DdeHS1pHf1KxokfFWx/6rbLTKjFGHL13V299mrG6wuO7fx8kqliDzMxVjT18ZdKGUB68qn6wsqfxXjTXoYf4Gq1KGdSDihJjw1fwi7WkhCJ+pqiUxl/oRoVyOGJhqU8osazlfE63LoDSlFRewAx4Ftgeb+BRt2tZuEIvSnHKyS6YnH2UsF4qLgEBgbeiFaLkMB5Puq1ZRejhUepOkjdqqd4RVP7M8k8o3SaXddZXq++EcCijsDieDYYWxsFueKJ03NcL+t/HKOlXIZZVrPSwi3r19Rr/3FGRxNr/317TTd5oMz8/Ro5ZmLiZgSqWjFtCB1h1b8kRc5wNrhyeR1CWUT4Sr/5C/TBQjAprVzns2cDuwDqnCFlLqPG/Oa1GBrrDPSAyERi4FbrzqzjrcnytJ0i+Twflla0/pp+brMqk9GLH2QzZb98Af/b5zvaHBPg0UFbAYPCclQUjNEg6KWt/ZhjxQf9WgNvwS2H0ry3AcQRjelZnVdWU314iukvGHUnaUxPnYLAcFH+BjviWlO7aUXuWqG4LRV9bKNiHb2za4gDWXQvf9QluAGofJiIbTwLyWHf7Z9rm6GxQ17B9r5JsGh2tBYCakbU2kJSn94HK25yA3wy+YPu44nkkHjV2XqGJvavpDU+ISBR4v/8ThDizFRIL/tdfenh0kp64b0FDj5gmuD58nfJldGhWkXXUl+5//+nB/2KW5eiHG7 foRbktyt vzlayMOMvRDemdwihYHRH0tKbGCRMwPbP9fUq2F7Bjd2mT4rxjRqK2i8b2RceKKd8hjUROJXcpvrZA9EyJeZq0q3xqaFIlfxwdbdOXBuEw6zoAcqc0bI8f56837p0tYe5LmwRasAWthNsbXX1gAqFYr1ZuCH7Q08a0pbJ9p2wPZTvTke7XI6hM8exeH77ySLeGGU31pTmFBQHhwHuMTfoM1i25b2RF+EMe1Ipp+sK1R+dyzHvP4W4mmQzi7muv19ajqLm1suO4jpez0WL9dQe8ygku5sbUAG75NAejaJZxearqT3Zec0Z9bYpPje82qtgRE49/TrpvGwahpXbY4CsDPAMQOeDIhwaK57orlXqOia7TFIZotjxiN4sV8p8YPYOyt2GHAQrluabl+0Q9QgqtqPq8gWfIjkbKIpZ 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, 7 Apr 2023 at 12:04, Muhammad Usama Anjum wrote: > On 4/7/23 12:34=E2=80=AFPM, Micha=C5=82 Miros=C5=82aw wrote: > > On Thu, 6 Apr 2023 at 23:04, Muhammad Usama Anjum > > wrote: > >> On 4/7/23 1:00=E2=80=AFAM, Micha=C5=82 Miros=C5=82aw wrote: > >>> On Thu, 6 Apr 2023 at 19:58, Muhammad Usama Anjum > >>> wrote: [...] > >>>>>> + /* > >>>>>> + * Allocate smaller buffer to get output from inside the p= age walk > >>>>>> + * functions and walk page range in PAGEMAP_WALK_SIZE size= chunks. As > >>>>>> + * we want to return output to user in compact form where = no two > >>>>>> + * consecutive regions should be continuous and have the s= ame flags. > >>>>>> + * So store the latest element in p.cur between different = walks and > >>>>>> + * store the p.cur at the end of the walk to the user buff= er. > >>>>>> + */ > >>>>>> + p.vec =3D kmalloc_array(p.vec_len, sizeof(struct page_regi= on), > >>>>>> + GFP_KERNEL); > >>>>>> + if (!p.vec) > >>>>>> + return -ENOMEM; > >>>>>> + > >>>>>> + walk_start =3D walk_end =3D start; > >>>>>> + while (walk_end < end && !ret) { > >>>>> > >>>>> The loop will stop if a previous iteration returned ENOSPC (and the > >>>>> error will be lost) - is it intended? > >>>> It is intentional. -ENOSPC means that the user buffer is full even t= hough > >>>> there was more memory to walk over. We don't treat this error. So wh= en > >>>> buffer gets full, we stop walking over further as user buffer has go= tten > >>>> full and return as success. > >>> > >>> Thanks. What's the difference between -ENOSPC and > >>> PM_SCAN_FOUND_MAX_PAGES? They seem to result in the same effect (code > >>> flow). > >> -ENOSPC --> user buffer has been filled completely > >> PM_SCAN_FOUND_MAX_PAGES --> max_pages have been found, user buffer may > >> still have more space > > > > What is the difference in code behaviour when those two cases are > > compared? (I'd expect none.) > There is difference: > We add data to user buffer. If it succeeds with return code 0, we engage > the WP. If it succeeds with PM_SCAN_FOUND_MAX_PAGES, we still engage the > WP. But if we get -ENOSPC, we don't perform engage as the data wasn't add= ed > to the user buffer. Thanks! I see it now. I see a few more corner cases here: 1. If we did engage WP but fail to copy the vector we return -EFAULT but the WP is already engaged. I'm not sure this is something worth guarding against, but documenting that would be helpful I think. 2. If uffd_wp_range() fails, but we have already processed pages earlier, we should treat the error like ENOSPC and back out the failed range (the earier changes would be lost otherwise). Best Regards Micha=C5=82 Miros=C5=82aw