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 09D9DC48BF6 for ; Thu, 7 Mar 2024 14:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 911316B00BE; Thu, 7 Mar 2024 09:42:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C1996B00C4; Thu, 7 Mar 2024 09:42:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78A516B00C0; Thu, 7 Mar 2024 09:42:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6380B6B0196 for ; Thu, 7 Mar 2024 09:42:55 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 33BC61207CB for ; Thu, 7 Mar 2024 14:42:55 +0000 (UTC) X-FDA: 81870509910.01.D3E44E2 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by imf21.hostedemail.com (Postfix) with ESMTP id B06871C0003 for ; Thu, 7 Mar 2024 14:42:52 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of richard@nod.at designates 195.201.40.130 as permitted sender) smtp.mailfrom=richard@nod.at; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709822573; 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; bh=Hriwqv1VafwSnAEQgWhG3BftPtOdGMoUT9XyeEe3nbQ=; b=BAWrdeX2Jod6MI9rzgwCC+CRdKmKY0vluBbutu5a4ZBQHBnRvlYEazKUdDEcYc8Sr4tJRO uEiGX/EQGhlcJZ6TWNzgJ75ZffkPzkqEP9ssTC27jVwe2h4i8FIhMg87aHUnNNxhKsYryx 1hHCo9BBCephwm4+ch8OeOsxyMhbIs8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709822573; a=rsa-sha256; cv=none; b=Lr1+vvYXNQXIF0Yc/KDQN2A9WKBdaLxPa6jzC4YFlcvmBL7lYFDZDz9tGT6NaeEnOX3Hxo bRWt242aJiqEmEk+4GJmj2vqvcYKdvWaxWSFLj692HT3foq7TpNRHVyBb13qd+blUqP8+6 vs6eGee/AGMZ/g5LPRLVEqMu0ywQr0k= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of richard@nod.at designates 195.201.40.130 as permitted sender) smtp.mailfrom=richard@nod.at; dmarc=none Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id DAC1B644CE97; Thu, 7 Mar 2024 15:42:50 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id CIhG1qGm-RNL; Thu, 7 Mar 2024 15:42:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 58EF0644CE96; Thu, 7 Mar 2024 15:42:50 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7EDauf2v-cth; Thu, 7 Mar 2024 15:42:50 +0100 (CET) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 1DE0A644CE90; Thu, 7 Mar 2024 15:42:50 +0100 (CET) Date: Thu, 7 Mar 2024 15:42:49 +0100 (CET) From: Richard Weinberger To: David Hildenbrand Cc: linux-mm , linux-fsdevel , linux-kernel , Linux Doc Mailing List , upstream+pagemap , adobriyan , wangkefeng wang , ryan roberts , hughd , peterx , avagin , lstoakes , vbabka , Andrew Morton , usama anjum , Jonathan Corbet Message-ID: <2055158015.23529.1709822569814.JavaMail.zimbra@nod.at> In-Reply-To: References: <20240306232339.29659-1-richard@nod.at> <1058679077.23275.1709809843605.JavaMail.zimbra@nod.at> <7d9321db-a3c1-4593-91fa-c7f97bd9eecd@redhat.com> <1525238492.23321.1709812267495.JavaMail.zimbra@nod.at> <0644814b-869b-4694-bdb1-bab4e6186136@redhat.com> Subject: Re: [PATCH 1/2] [RFC] proc: pagemap: Expose whether a PTE is writable MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: proc: pagemap: Expose whether a PTE is writable Thread-Index: ALtl01Wd8Zr0Arr/iwJcm8Sl/cTDKQ== X-Rspamd-Queue-Id: B06871C0003 X-Rspam-User: X-Stat-Signature: k879mx469quigr9uxbshzcumppoekyks X-Rspamd-Server: rspam03 X-HE-Tag: 1709822572-332290 X-HE-Meta: U2FsdGVkX1+frtFm3M/qJFmDq6Vw2PJfV0tzVzCWd8aG35wtKYFXAFAe+NJ8pqC/Oc4Se0eOatN2aiGs+4+X7b8ySfh03/KJxuQrkSkdag7xziBsX1zsMXm/kzSSPa9ko514l/LK/SBEsRJXOabTDSpw9BqN8vg+np7qn5jWOZvyBmyo95EMy2bfjr1sHXoTvy8C6AqkfUM6NOdFhxT0fEbaW+iURypiYw2D/b+W99HNKvJKkUO5U8FxUkiXW87wobYrySjf6Jm2CEma1rOoonUSyrvpS8ngSGkbhXha2T0EB1Xp31oflBt5G1w7M2cwRIg/C//LZ8isDhLx7B9J0DGLm7bysDsPizmdNw+eKIdciTnzHR4NqNCdZ8XqtMYryeTJQ91oKJNF9mcxFdSq2+q0ATPxyddr4Rm7NgUupdX44X5DB4HPySFdxGyXsPFtr6rFBIEaLTCoeNmESbdVYksuOniD+9mazczafMov9KCyiTTVV0RePiAmJINxsQuY2lJmeu0B10Hac2jFj+RyED1jjPgrs/URLoK5ggRx3vVDt32lMZPFHNcKF7rgRB1I93ZICUJlSUW5ZtMSgJbypvStwDfmR+1r3+s6f0BTqCj+O6EAa9gdJkuakEmDuMfSL6jVR6IoVkDBSTUq7ftLNP0Oi7DyZXReYcH4sNbtSlGn0TcAkp780EihRXLbOpltz+cTdKWz93/ai0kyDfPSpq2NzCtCDlQ5O5E2DDEAgDFd7EAZFMvDXLlbcukQ5mHZrJYxowFC8TO/OZXfRAP8d3VRAczIErqMhuXnPty+hAF/uZQdT3FkXyD0nkSRtoh1gl4uw86veWv9kiuyEBREOzbf1rxTiUpYA8GlPsf4ysrVH5KFkDxAXK20MEVpMPA2nlypcxv1xhlHIxMYpgAM1nQkeXkhaSmJXOk4I1mWqM1CZGQPI3zfos3P3h1+MmfcS5L7BrpvNxrjbHyhcds KnyCPLux haUXNOXvKxDSMpOD8XbLgpeX/gkomONAyVKR21YP/7UR/39Hdaxrebhx29/UTCl/oMMHXACVVOWcPMJf74zW9yw26tBiFGb6detROk28kE5i6l0Somv+Op7Isaahv3bB8W5sgi37d79/QLqO3XlmQsl96vPjZcxNjK+Vf6bIkTpCcv7Ly9dAh79I0+GJiZ5jM+aPUafB4yIhw9S4= 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: ----- Urspr=C3=BCngliche Mail ----- > Von: "David Hildenbrand" >> One destructive way to find out in a writable mapping if the page would >> actually get remapped: >>=20 >> a) Read the PFN of a virtual address using pagemap >> b) Write to the virtual address using /proc/pid/mem >> c) Read the PFN of a virtual address using pagemap to see if it changed >>=20 >> If the application can be paused, you could read+write a single byte, >> turning it non-destructive. I'm not so sure whether this works well if a mapping is device memory or su= ch. =20 >> But that would still "hide" the remap-writable-type faults. Xenomai will tell me anyway when there was a page fault while a real time t= hread had the CPU. My idea was having a tool to check before the applications enters the criti= cal phase. >>> I fully understand that my use case is a corner case and anything but m= ainline. >>> While developing my debug tool I thought that improving the pagemap int= erface >>> might help others too. >>=20 >> I'm fine with this (can be a helpful debugging tool for some other cases >> as well, and IIRC we don't have another interface to introspect this), >> as long as we properly document the corner case that there could still >> be writefaults on some architectures when the page would not be >> accessed/dirty yet. Cool. :) =20 >=20 > [and I just recall, there are some other corner cases. For example, > pages in a shadow stack can be pte_write(), but they can only be written > by HW indirectly when modifying the stack, and ordinary write access > would still fault] Yeah, I noticed this while browsing through various pte_write() implementat= ions. That's a tradeoff I can live with. Thanks, //richard