From patchwork Fri Jul 7 16:52:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13305123 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 C7215EB64D9 for ; Fri, 7 Jul 2023 16:52:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 612618D0002; Fri, 7 Jul 2023 12:52:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C1EA6B0074; Fri, 7 Jul 2023 12:52:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D7D68D0002; Fri, 7 Jul 2023 12:52:40 -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 407F46B0072 for ; Fri, 7 Jul 2023 12:52:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0BB3140D40 for ; Fri, 7 Jul 2023 16:52:39 +0000 (UTC) X-FDA: 80985409638.15.6C36755 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf03.hostedemail.com (Postfix) with ESMTP id 8D4C220016 for ; Fri, 7 Jul 2023 16:52:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=achHiaMf; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688748757; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5IdTAm/mVq4hBk7ISMJ8Drz/LzCia5XtyQmyhwvy/ik=; b=tDJWsYuW3CaEjV/dbWWzPuJWLZfiQ3tT1YFH3A/l+De2HW4lyxNzpl5VkN31o4acX6hbQY YMhlpK4PY57gl6b4D1tp4dc+vgaMpm2+AcoULTZJdKUF6O0LNqvQB7AuzEETH7ZiTnPZQ/ pMa5Fi1CFsqS7vsVi9lSuNQT8LQWRZY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=achHiaMf; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688748757; a=rsa-sha256; cv=none; b=k/u0RxwyAXubIEFHBRN/1XtbFtE+e0zAiSfn4RBLLU8q4NqH8Ucc5JRJZFFPmW00IRO5d2 jPiCX+F504BOO37lumobNkegq5awpZVbrnCmYvKD4RMB+vsl/R+9upFaEEXWf0T75qUuJw s0I4EMurhdzPgVxjXlEjuTQ0M1iX6Og= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688748757; x=1720284757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9AZoEU1dBDfQPpclAW3AxhTYvcE6HGN/KVZD4GlGeoo=; b=achHiaMfUAiJypiVeDdj8zrGAhPX5u0U19gIPuwqd3o3SlIgghoyHlLX WkVhXCC/NQEH01X2NtlVVvr5ei5zMysjsi9dn2kz3tLH/EWwljdBY+4tr JRsHeO5sriOM2XU0+h+XX2xFcn4PfgSiHnzKlRFCaYZOdqp0IWyUVAr4P P9sIH+J1hkGw0QVAhWvuhCM+vcvpmNuIl6w8nQeFRchO7AizvmW5sPNb5 xp+34tV5XQ3V6j6VLvEJYdxp94+SZbDbG0NShmCEUjIVw8VcGFTwut5aD yrPtQz3I8agblg0XovqGw+JxS9H5EjnXDqI0E4l8M3l2xjoge7IKvFbXt w==; X-IronPort-AV: E=McAfee;i="6600,9927,10764"; a="353776317" X-IronPort-AV: E=Sophos;i="6.01,189,1684825200"; d="scan'208";a="353776317" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jul 2023 09:52:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10764"; a="697290444" X-IronPort-AV: E=Sophos;i="6.01,189,1684825200"; d="scan'208";a="697290444" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga006.jf.intel.com with ESMTP; 07 Jul 2023 09:52:33 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuzhao@google.com, ryan.roberts@arm.com, shy828301@gmail.com, akpm@linux-foundation.org, willy@infradead.org, david@redhat.com Cc: fengwei.yin@intel.com Subject: [RFC PATCH 1/3] mm: add function folio_in_range() Date: Sat, 8 Jul 2023 00:52:19 +0800 Message-Id: <20230707165221.4076590-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707165221.4076590-1-fengwei.yin@intel.com> References: <20230707165221.4076590-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: qi3gzyb9bdkbwjj37nh5g4tut7rze58c X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8D4C220016 X-HE-Tag: 1688748757-180509 X-HE-Meta: U2FsdGVkX18UyWOBYAYxjhaHtjqg0mcWbsJ4Q7SUZfkj4OfoB7haXCO6muruN2h2qycJ7LcE3rLQwVY6T3jgFySXGtW3Ur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5WAB4NMVYfYYxYFgU= 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: 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. Signed-off-by: Yin Fengwei --- mm/internal.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/internal.h b/mm/internal.h index f1276d90484ad..66117523d7d71 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -585,6 +585,32 @@ 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) +{ + 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 < 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 (pgoff < vma->vm_pgoff || pgoff > vma->vm_pgoff + vma_pglen) + return false; + + addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); + + return ((addr >= start) && (addr + folio_size(folio) <= end)); +} + /* * mlock_vma_folio() and munlock_vma_folio(): * should be called with vma's mmap_lock held for read or write,