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 105C6C6FD1D for ; Fri, 7 Apr 2023 11:11:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81E42900004; Fri, 7 Apr 2023 07:11:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CEA4900002; Fri, 7 Apr 2023 07:11:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66EB2900004; Fri, 7 Apr 2023 07:11:07 -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 54430900002 for ; Fri, 7 Apr 2023 07:11:07 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 118961C7380 for ; Fri, 7 Apr 2023 11:11:07 +0000 (UTC) X-FDA: 80654328174.09.8F6A70B Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 219C4160013 for ; Fri, 7 Apr 2023 11:11:04 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Xn0pM5Cw; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf08.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680865865; 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=Z+UXsTBLM8oyPH9AeiV9wymYAcXkGsDLtiL9gFvhDn4=; b=8UAciPCPhmJrSPl3rptbetIfjyaB6VjjFoK+E991siXmd1AAMzd29g4ktE3YFeWmY4sAW2 nUhc6qpw6VYNr+f0qmLLR1riW/K06swXdYxrRhGQDJftS9YK1A0kGtzPA0ejDcl5+st6ix v06ho5AJrC0Uz6XN3+/3cLTwVFXdo1M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Xn0pM5Cw; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf08.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680865865; a=rsa-sha256; cv=none; b=EaV+WODQUGFcWGiDx/s/52ZCJStCKaIgllky2i0F5e8As9KJL+yU3PQq0DS8kTcsLx1xeh T2ZZ8UuRwdpvKMzjynP8qE0uZNLyjWO2lL+VhXgLg2rmXnQmH7FwWA/HFUh8B+WtMkRSkS X6DA2l91jZtqDGRitBC2Ddb5dqNQO1o= Received: from [192.168.10.39] (unknown [119.155.57.40]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 5F33E66031A4; Fri, 7 Apr 2023 12:10:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680865863; bh=B0IW8AxLLQ/M9fKJHJt4ViUXFpwbhTGWKP+3cfqzxFg=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=Xn0pM5CwwZf3DBlCqByzYb2srNvK6Qsouf17RM6648RFVLhn+gQGdMjOePDCDjphn JcSpxS7uKiK7UvQds03zKV0j9nPHJ/q2OwifkwvL0drbd7AWYKRVODQi5j6WxHH9NT qKANjVs8LTaIHfjbdqqzBN0NAw0yznOUMW7id71VTMOrNTAzYfjjt3w9UNIbi24ECl D1AVay9dwuc9ZO2xLnW8+1AnHVwIaP2ZVB4tJY2L28ImkpMh1/IL0cq1c/jtgCgREi ixdBN9y45uRzNgCEoD8KCBkoqLnb8CX++e4Mhi5im273IpjyPXNNQ7D4+HkW+/0BR4 NUsIPoRTYp/bw== Message-ID: <05e14540-7092-5dd2-d503-473b673af716@collabora.com> Date: Fri, 7 Apr 2023 16:10:51 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cc: Muhammad Usama Anjum , 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 Subject: Re: [PATCH v12 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Content-Language: en-US To: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= 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> From: Muhammad Usama Anjum In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 219C4160013 X-Rspamd-Server: rspam09 X-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7C6Hm4JY5mbEOPwOB8vA+Xa+ua5u/bA4C6GeXBkDOAv6vW0UN8J87cL6R+KZf/X4bo8QBHk5JvXsDAAvIHV/pIyuULWWiH55JCfUVPt4aHfwsIK/HhQWEc9Io3vQaH2cK5yILU4xBF4wt+O/zV53ToXpsEjAJpZDIhUK0JQJfKc49xfAj7OsrW5Hs/V1jAsBaWFZz7MdKiMiB1INkNN0GAbYCfN1HqpngptpLLeZoVigUWKVLgUIE0M+fbj9CTqbgndS/pDmA5XUM3FEpG6rwMCgjD0z/d+97iTgth4MLHFUza3JZJNR8Rv+5C2wzXO+YjYImrZptbMFXBz8tYoZt9e4UKEyTI= 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 4/7/23 3:14 PM, Michał Mirosław wrote: > On Fri, 7 Apr 2023 at 12:04, Muhammad Usama Anjum > wrote: >> On 4/7/23 12:34 PM, Michał Mirosław wrote: >>> On Thu, 6 Apr 2023 at 23:04, Muhammad Usama Anjum >>> wrote: >>>> On 4/7/23 1:00 AM, Michał Mirosław wrote: >>>>> On Thu, 6 Apr 2023 at 19:58, Muhammad Usama Anjum >>>>> wrote: > [...] >>>>>>>> + /* >>>>>>>> + * Allocate smaller buffer to get output from inside the page 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 same 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 buffer. >>>>>>>> + */ >>>>>>>> + p.vec = kmalloc_array(p.vec_len, sizeof(struct page_region), >>>>>>>> + GFP_KERNEL); >>>>>>>> + if (!p.vec) >>>>>>>> + return -ENOMEM; >>>>>>>> + >>>>>>>> + walk_start = walk_end = 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 though >>>>>> there was more memory to walk over. We don't treat this error. So when >>>>>> buffer gets full, we stop walking over further as user buffer has gotten >>>>>> 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 added >> 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. Sure. > 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). Backing out is easier to do for hugepages. But for normal pages, we'll have to write some code to find where the current data was added (in cur or in vec) and back out from that. I'll have to write some more code to avoid the side-effects as well. But aren't we going over-engineering here? Error occurred and we are trying to keep the previously generated correct data and returning successfully still to the user? I don't think we should do this. An error is error. We should return the error simply even if the memory flags would get lost. We don't know what caused the error in uffd_wp_range(). Under normal situation, we there shouldn't have had error. > > Best Regards > Michał Mirosław -- BR, Muhammad Usama Anjum