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 092B8C001E0 for ; Wed, 9 Aug 2023 19:34:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DC8C6B0071; Wed, 9 Aug 2023 15:34:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38B8C6B0075; Wed, 9 Aug 2023 15:34:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 253208E0001; Wed, 9 Aug 2023 15:34:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 119116B0071 for ; Wed, 9 Aug 2023 15:34:29 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7A5CC08EA for ; Wed, 9 Aug 2023 19:34:28 +0000 (UTC) X-FDA: 81105567816.30.866841A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 1C8A1C001B for ; Wed, 9 Aug 2023 19:34:25 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691609666; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PYEjI5OLbYunF5YNM08AECgJJ+YlcBD7vAwr3jNbeVQ=; b=5WGEljIfC6sFypmXjDKSw2wm4PLe1RfAnj1T+lZeu3/U7Q0mBzt1Q+vdWFSAMg9PUn3Y9Y 3Wp90C+hcCn4Muv7OlJvYd3UJUgrXSqFTOaYvZ9O/OroBdAHJXYNEQopvEavk20bXdMSYt 0s3XYdTNjt+sp9BiNApdWeaJClS0Ukk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691609666; a=rsa-sha256; cv=none; b=LU2u/TBPb2Grne1ojjIAPNLSebc6kZ7C9QLks3KQyeAOTpNDw5SzjZi54JXe30KCLP1V2C jZFfLe8CfiDmPfgHuRCnq95eJVNmDawFU26QXpy6UQieqGK0Iomxf3+KSCxR+vShF27o4Q QggQDUqxJ+dZfCbvApT3nNXHbvQ+360= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C405D75; Wed, 9 Aug 2023 12:35:07 -0700 (PDT) Received: from [10.57.79.142] (unknown [10.57.79.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CA3A3F6C4; Wed, 9 Aug 2023 12:34:22 -0700 (PDT) Message-ID: <241cb5d6-0941-4dbb-9d16-9226d34ebaf8@arm.com> Date: Wed, 9 Aug 2023 20:34:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/3] mm: add functions folio_in_range() and folio_within_vma() Content-Language: en-GB To: Yin Fengwei , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, yuzhao@google.com, willy@infradead.org, hughd@google.com, yosryahmed@google.com, david@redhat.com, shy828301@gmail.com References: <20230809061105.3369958-1-fengwei.yin@intel.com> <20230809061105.3369958-2-fengwei.yin@intel.com> From: Ryan Roberts In-Reply-To: <20230809061105.3369958-2-fengwei.yin@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 1C8A1C001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xr1ehy9zhbz4a9h9hhhg65k5p7thszx5 X-HE-Tag: 1691609665-196327 X-HE-Meta: U2FsdGVkX1/f7m4C7LOefQSHbXMcOq0Ld/8WcBu/JF5Vqzg/zAXsTZuihxHpnbn+SIZtHQPRYaBwxTzU7gLAuUcDhCn6s/25hLRuR0cjFv5lS38M48x0ihB4TYwoamppm5WLpYtqq403ryaD3VYEYYjAnEiCm+VYukFrZnPQ2z052fuUQHpBSm1c8xzSzsvA28iILAy1YWACwO3GZNgx7/oFE4++2hxh5blzXbggvQ3SHO7v9RkWMLwwXMVNH7JHNYk43LXNU9KABT3EJTR0MbT3uhXytYuvw+EyRtqaUHeqRcZNS0K/NJ1h/PG9Ene/mWQ3p6foMVx8Ya5odGtGYe8PsSSUUpHH1yy4/UptUrxNnGOORLu5+z8WhviHYgQLiHtJCH/U1955FaBXHndamdgOTFXCRESZ+6uEGgKg3Mz8/vddbc8a8X7ys1dxZxup4zA22heL53lM7m8JsfbajQdFouwipnV9PW3SRqJcvv/XB5zJvMTpy1j4n+WeoNyBbDa2Ba2EfR7KzeTL7qxczSDyOMaMHzvzGT5FGJS3XiehXycGhyredYngBXXisKe0GhRP8gUoOZ8fVjHRot8z/LhNs0qbJ6TLsZkj5rrZ+c5TiJNcTi5I+wvnkEk+xvj9pBR6bc/XO0Pza7cf4uO5g5CkzJXDo/bKnl6u3nHWxMt3BqkMn3BCNABZDHKWzkXFiWgGlUbgI8K+DEFb5IymAUWuWHH/XyjDEEyjdlWhmumAD+YG2Kuf5lqTv7FEKckpY44LxtKD84o2N+MU+yfPCD3k6UqBmavcv0KNmPSq2CYfvTY/ipXb2hjv3cU4P/OIat2LXnN+WV94qRFD/eek+bwFYg6QtU8MMiPumpk0U02alvZukDZ9lXGUZI1666FeXAfoRFpVsacUvouuryk2IgWz4uuD1shPyLNrov1J9VCBej+Gf0P7K+EhNcCsdVYxwOMfTxeCMGuZeLdkb9c 4my4NOVm MNOdT/xXLN6JePl+etjGo9uFN5pQLh4RVlxc/X5fp1emAHy/LVYffDG1W7QlWxG+yOMqFpexXJsekWGPvMsdrgR17au8pnErqGhDOpyKmfEAjFUGQsHd+atomEhVc+o8aT+sqNigN5df4B3cDW1tANp44ne6r96eBXQT6sf5ALZzzpO5GvfWrnSkeV3a3rmI/AjlKSPuIsmoU6Z2+1jQ0NYIAHw== 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 09/08/2023 07:11, Yin Fengwei wrote: > It will be used to check whether the folio is mapped to specific > VMA and whether the mapping address of folio is in the range. > > Also a helper function folio_within_vma() to check whether folio > is in the range of vma based on folio_in_range(). > > Signed-off-by: Yin Fengwei > --- > mm/internal.h | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/mm/internal.h b/mm/internal.h > index 154da4f0d557..5d1b71010fd2 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -585,6 +585,41 @@ extern long faultin_vma_page_range(struct vm_area_struct *vma, > bool write, int *locked); > extern bool mlock_future_ok(struct mm_struct *mm, unsigned long flags, > unsigned long bytes); > + > +static inline bool > +folio_in_range(struct folio *folio, struct vm_area_struct *vma, > + unsigned long start, unsigned long end) I still think it would be beneficial to have a comment block describing the requirements and behaviour of the function: - folio must have at least 1 page that is mapped in vma - the result tells you if the folio lies within the range, but it does not tell you that all of its pages are actually _mapped_ (e.g. they may not have been faulted in yet). - I think [start, end) is intended intersect with the vma too? (although I'm pretty sure sure the logic works if it doesn't?) > +{ > + pgoff_t pgoff, addr; > + unsigned long vma_pglen = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; > + > + VM_WARN_ON_FOLIO(folio_test_ksm(folio), folio); > + if (start > end) > + return false; > + > + if (start < vma->vm_start) > + start = vma->vm_start; > + > + if (end > vma->vm_end) > + end = vma->vm_end; > + > + pgoff = folio_pgoff(folio); > + > + /* if folio start address is not in vma range */ > + if (!in_range(pgoff, vma->vm_pgoff, vma_pglen)) > + return false; > + > + addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > + > + return !(addr < start || end - addr < folio_size(folio)); > +} > + > +static inline bool > +folio_within_vma(struct folio *folio, struct vm_area_struct *vma) why call this *within* but call the folio_in_range() *in*? Feels cleaner to use the same word for both. > +{ > + return folio_in_range(folio, vma, vma->vm_start, vma->vm_end); > +} > + > /* > * mlock_vma_folio() and munlock_vma_folio(): > * should be called with vma's mmap_lock held for read or write,