From patchwork Sat Nov 16 17:59:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13877671 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 28C49D68BF5 for ; Sat, 16 Nov 2024 17:59:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 555739C001C; Sat, 16 Nov 2024 12:59:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B5789C0018; Sat, 16 Nov 2024 12:59:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30AE89C001C; Sat, 16 Nov 2024 12:59:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0A6CD9C0018 for ; Sat, 16 Nov 2024 12:59:32 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76690C1D44 for ; Sat, 16 Nov 2024 17:59:31 +0000 (UTC) X-FDA: 82792718148.03.E9A1B57 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf07.hostedemail.com (Postfix) with ESMTP id A49FF40004 for ; Sat, 16 Nov 2024 17:58:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=Unqas3E1; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731779771; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8NgfUO+bQWj6bU8BgCVOh0fIa47vMCexDt60Dq7gXNk=; b=BnBuTsfag3+2zJkx2gpMPvII1yqxX0mndPE5k0hNj5YewTS3OpBl1tFRLofPWcKOLk0Q81 pUG7l+IJzzINjDCn1duatXkOhq38rGMd62x6j5xgB/4NGZtaRhqv4kzvohLFn/8+e279eo OKrD8OxjGaLsp0nSifku/fcphhH8Nq0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=Unqas3E1; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731779771; a=rsa-sha256; cv=none; b=3VM43mEHPNz6a+nB5V/cAmJL5Vj7wcYGehz/QjvK7PDlUjnJ2VDy7+1E2UO/PT7OFfycMZ qpJJNZ6QQa2s++BnBB9172sRwegKz4cVBj/6XZlUnOIOW7QhC+OxX9P3bDGZstXfq5h1dW NcmT0u0QoET+469pJJcLQ5+mVkWy2wI= Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4609d8874b1so14182181cf.3 for ; Sat, 16 Nov 2024 09:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1731779969; x=1732384769; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8NgfUO+bQWj6bU8BgCVOh0fIa47vMCexDt60Dq7gXNk=; b=Unqas3E1J/vRBIyjKXAh1zDzbgIkWgZ66j/lGs5W5rxo82qi3v4LJZfrlPi6gOf9wC VewLbehuKEj2b4dS4RQ3U9J8eF8USFEcINrpZq99GNeXqNjwYlWkqDh2ttGSSABDxey+ VLciG4y/6dZtjjq8VCFgB9Y/lvrZaCIQtCbBneCaO91AMG0G/i06uXRl2Z2qynyDnn8Z xMLL6WN7B3yr01PqIBREvmw3IWmk+CHxGIQHQsaXFwwGaJBok/weCsmYq1+TnbEp4TDa 3H0IPAEmxhP8+TuGRLeSnu1RVH+ohJ1fqhQFoDn4RwSBaend+K0fBdebKA5iu9aAjQxh SPMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731779969; x=1732384769; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8NgfUO+bQWj6bU8BgCVOh0fIa47vMCexDt60Dq7gXNk=; b=N08+GU77pvOOsMLdvw5w/NYhfeYAhULDV+fwSkiArCfHzR1CrCUujBIBXGbQMy0SkZ dI9nUBCYkL3+MeaXQDAg/Xp0bButHczDx8JmICzmLajOM1YAXC0j40nU9ZEftg5UPKwB SwDhrkKpJYyEq+hYMkW6RyUcodPGy7OeZWrde1AYIpGPD40OTbWYKXoCrcW3aUGLcLCz loIFHkwc73TO/lXE2Ee2ZINnZamzUGQm3KNhKx5n/AwaHREjyP87s4pY6h0tv13Zw94J eHAH+m+XSvfGlagqI6v0gCLAQ+D17OtWTMrVT4JRTZXBnIj3ASThTUjlSDBPQWcNczy0 gXoA== X-Forwarded-Encrypted: i=1; AJvYcCVuC6i9LtUgzF+tS4OdQsWMkVvuRT0XMcovjfjjFMonKvRL9Q3huU3dUNg8xsVsZXSajEavAdqjHQ==@kvack.org X-Gm-Message-State: AOJu0YwVcfLlEGBKKFFuUk+UR0ddAFIyhPXGbkMnaDEQ9Ukk7WMwvG+l juCKrQPrvNkrpxWWZllPiALxNSEDV70U8CiADLivt0kICEPnGXtbdjDgENDtAn0= X-Google-Smtp-Source: AGHT+IEMOLNEsp5sqgIkt52tiSL0kf4hziLkF3l6oWPXAHVLzfNvt2ajo6yR1l9MnxJe6dgs1UWO0g== X-Received: by 2002:a05:6214:5d0a:b0:6cb:e6b2:4a84 with SMTP id 6a1803df08f44-6d3fb7cc924mr77641716d6.14.1731779968837; Sat, 16 Nov 2024 09:59:28 -0800 (PST) Received: from soleen.c.googlers.com.com (51.57.86.34.bc.googleusercontent.com. [34.86.57.51]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca309d6sm280530085a.94.2024.11.16.09.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Nov 2024 09:59:28 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, akpm@linux-foundation.org, corbet@lwn.net, derek.kiernan@amd.com, dragan.cvetic@amd.com, arnd@arndb.de, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, tj@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, shuah@kernel.org, vegard.nossum@oracle.com, vattunuru@marvell.com, schalla@marvell.com, david@redhat.com, willy@infradead.org, osalvador@suse.de, usama.anjum@collabora.com, andrii@kernel.org, ryan.roberts@arm.com, peterx@redhat.com, oleg@redhat.com, tandersen@netflix.com, rientjes@google.com, gthelen@google.com Subject: [RFCv1 2/6] pagewalk: Add a page table walker for init_mm page table Date: Sat, 16 Nov 2024 17:59:18 +0000 Message-ID: <20241116175922.3265872-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241116175922.3265872-1-pasha.tatashin@soleen.com> References: <20241116175922.3265872-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A49FF40004 X-Stat-Signature: xtu5ptiti3qe6r567jx4jw3pffwkjwsb X-Rspam-User: X-HE-Tag: 1731779903-710199 X-HE-Meta: U2FsdGVkX1+f3qtrDllT7xnYxRNcxjPDZLGsvi/Pi2XVFAw1Y7sZoRxakwu6dK0kncOUZqP5WUtaWRDwiBAHQBaUMZ5TESTdXptK+ai9gv7NKOiLPO4rguwf6fLKOI2ySbg8tbo9vDZicqfR8A5DJtA84VpomjJMEdgM4qvwrxDflfhAqNOQ4IX14Aa5I/A6wVD4Y1ej+Mq9tBPzOdlgRWtyDPs1H+O3S4lvNOz3K1P1UrCIbw8MNVW6lvDSDXfsY9ztVLfuS6K1VJTA4LKQOzPAZ/GQewVERq5/z/j82BQGwf0gocWOOHJO2qGUdgSxh9R9mgKyvVAuvWm9liriZjxePnKhNo/Rs8bNlItJhcJ8mUDgp9NOdYbPwGafHYRsZ8aQiL5HWoWnHOSfcEBOhgP35ZAMVtF6T5CKS9cAyIUwa9GLz0M5Jj0VFclLUqY9pd8oOchcjhWBsGeDh8vCanfmNuK0ZX77MdA8hB6xhJU+jn5Hfl6QZDEgbGQZcu+Uf6V23gJNh4kgx1qjaXScZGqsoct0tJeyrCUoDMq09mjtZO9yTa/YsJBVM8ZIN0idJB8+c6dLItmXX6POsWT4ijDCxyBhTGkP+/RBL4TJzMgd1Zg0NK79tl+fRv5rpSDNGl/U8n4SdaxVQZxm+Wf2YyxSF1A3GSBGMhj0M0++VPJfSpk2Ud7w7ktA8rM7MGPzXtSGmNKPxs3vbQzu1S6nHTBHfNIzoURgtQXq9ntwSSpSoQ9N7Qu8hjmJI+o1QQy+2Gz9YDnKLDq8mwYL1l+T0orbtFE12aMRsE8cyuo2UMCS/8MaIwGUJPgiRApvkQi1V3KdPco9i2iDktKgkUSAACLseDcpl2uSLBaxSpIXt5ZDMTVs59Gm9/VSuNUjXMuSzmLz+kJtxYbYMBQK4rFtjWywtIdlpCbeIySGcxkxSCoduVHKVH9tbnjww4B14XQCtzdZRubPmbJsaN5OTJz wt7datOJ /G8X9gmO2PzqwOxgnUNFpqTe7Aa/Q91bvdnNhSF5tB20MaaCFMxaLi34rJdr29KoFT23JHWEIElwWLQ7HOvyCGtpUFXnHb/XAT+wFoLwvKvwEgubyThoM7LkY904/CqlrmbHW1RxExq55L/iG2QrBeVL8uI1JNffMo1Mz7ATMwBs/dTYthzVNCfXiwHA1mf3IqV/3WOcb8PX/23HH+fhiz0KzfchpouqXudXD6scCrFu3xTEcL8s9IITyPWeUsWqXUxyWmv4WPTJe/QQKgNtPJoArcQbb5tMP9TY1Ng42WkWNVbBmvNNps1mv94B2+iTmUTo49HFg4d66kqsodmlhCXSW3BA8Sf7Yttr9N2LDMySMp6ZD8P5SDNeTxE8HWDuszSukpsZQemARO2jbJBLUwHwStVBzIJYzQLvg8ADjhhUjU7yMXcQWIUm1PQ== 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: List-Subscribe: List-Unsubscribe: Page Detective will use it to walk the kernel page table. Make this function accessible from modules, and also while here make walk_page_range() accessible from modules, so Page Detective could use it to walk user page tables. Signed-off-by: Pasha Tatashin --- include/linux/pagewalk.h | 2 ++ mm/pagewalk.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h index f5eb5a32aeed..ff25374470f0 100644 --- a/include/linux/pagewalk.h +++ b/include/linux/pagewalk.h @@ -124,6 +124,8 @@ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, int walk_page_range_vma(struct vm_area_struct *vma, unsigned long start, unsigned long end, const struct mm_walk_ops *ops, void *private); +int walk_page_range_kernel(unsigned long start, unsigned long end, + const struct mm_walk_ops *ops, void *private); int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops, void *private); int walk_page_mapping(struct address_space *mapping, pgoff_t first_index, diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 5f9f01532e67..050790aeb15f 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -478,6 +478,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, } while (start = next, start < end); return err; } +EXPORT_SYMBOL_GPL(walk_page_range); /** * walk_page_range_novma - walk a range of pagetables not backed by a vma @@ -541,6 +542,37 @@ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, return walk_pgd_range(start, end, &walk); } +/** + * walk_page_range_kernel - walk a range of pagetables of kernel/init_mm + * @start: start address of the virtual address range + * @end: end address of the virtual address range + * @ops: operation to call during the walk + * @private: private data for callbacks' usage + * + * Similar to walk_page_range_novma() but specifically walks init_mm.pgd table. + * + * Note: This function takes two looks: get_online_mems(), and mmap_read, this + * is to prevent kernel page tables from being freed while walking. + */ +int walk_page_range_kernel(unsigned long start, unsigned long end, + const struct mm_walk_ops *ops, void *private) +{ + get_online_mems(); + if (mmap_read_lock_killable(&init_mm)) { + put_online_mems(); + return -EAGAIN; + } + + walk_page_range_novma(&init_mm, start, end, ops, + init_mm.pgd, private); + + mmap_read_unlock(&init_mm); + put_online_mems(); + + return 0; +} +EXPORT_SYMBOL_GPL(walk_page_range_kernel); + int walk_page_range_vma(struct vm_area_struct *vma, unsigned long start, unsigned long end, const struct mm_walk_ops *ops, void *private)