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 D04DDCD1288 for ; Wed, 3 Apr 2024 12:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6882C6B009A; Wed, 3 Apr 2024 08:59:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 638536B009B; Wed, 3 Apr 2024 08:59:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5277A6B009C; Wed, 3 Apr 2024 08:59:16 -0400 (EDT) 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 330FE6B009A for ; Wed, 3 Apr 2024 08:59:16 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E497E80A6F for ; Wed, 3 Apr 2024 12:59:15 +0000 (UTC) X-FDA: 81968226270.19.8BE2A6E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id C5BE014001D for ; Wed, 3 Apr 2024 12:59:13 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.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=1712149154; 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=qOO5VokNliBqRQWeRVMD93NppeXdyLR4MX7ojEhs3k8=; b=qcNX0E75jED2TIKoZZzdMDEgryjX5MsA8cbhCKR0C85mjQnYTjL0fp96Lier5QTKB1TTRZ aVFGEVZ69tD3KAK68lF0FQCm0TYINFPzxIx69ZwOo9g/s1xKy28w/rwsmMoD7wauvKMxul ef6e3Ji8o/zJEhE1mlyIha0rkh99jzs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.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=1712149154; a=rsa-sha256; cv=none; b=PUxp6/pAbApNRfncfM6Viatp1zrkwqzM6kTLr96SrjQ3rOsM2r7uxfYvrSu0pRAIsTXwUM 3ElA6/o5Ge5LlC0hkx8czyHdCK8Yx+qNqiyvsuBUfZqOs7HObJiD5G5SiI8g0EBdy8l4LS 2fGjo0/fzjkpckJjjybwxbcVnGtgJyk= 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 C265B1007; Wed, 3 Apr 2024 05:59:43 -0700 (PDT) Received: from [10.57.72.245] (unknown [10.57.72.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E1AA53F7B4; Wed, 3 Apr 2024 05:59:10 -0700 (PDT) Message-ID: Date: Wed, 3 Apr 2024 13:59:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 0/4] Reduce cost of ptep_get_lockless on arm64 Content-Language: en-GB To: David Hildenbrand , Mark Rutland , Catalin Marinas , Will Deacon , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrew Morton , Muchun Song Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240215121756.2734131-1-ryan.roberts@arm.com> <0ae22147-e1a1-4bcb-8a4c-f900f3f8c39e@redhat.com> <374d8500-4625-4bff-a934-77b5f34cf2ec@arm.com> <8bd9e136-8575-4c40-bae2-9b015d823916@redhat.com> <86680856-2532-495b-951a-ea7b2b93872f@arm.com> <35236bbf-3d9a-40e9-84b5-e10e10295c0c@redhat.com> From: Ryan Roberts In-Reply-To: <35236bbf-3d9a-40e9-84b5-e10e10295c0c@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: zmpkxagxmj8nb3daeicfkrupz1698zgh X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C5BE014001D X-HE-Tag: 1712149153-281675 X-HE-Meta: U2FsdGVkX1/5cPImVez8QvQrsqo5HTm7pg4qgaKOY9+LGRMSeHfw1R7M2bUliglAOn3rXxKERZ2b/1a+C4fTohK7EVQrsSFgXXrb2Fjxx/FFnt7omc3Zs1woqTPaF0tiYpglquWICQlQCEYp69YnfJws3Z6doEm3UJE5iiMSyKldydyb9mKlOh3B8WlfgqUeDp5sps+iEQbmEsC/xrTInNYQpG7muRRG1Cm3Wu3GVjnM7ss/awff7O3rL6PRAInU/3Qbyro3bgvl/GMxA/W/T19yUcj4eJpQN1KPrV42M5W02SqMze20yTMbpGX6Cm5od20oN5xC9i3gHcCQIgwh6zRX7pfibHzpVRwVjiVqiijHEotd+vCLzd50ZV8DmsUbTij2+4JSI4C2T5AS2K75vxFC91WS1Uk1mMSQ6fllWX96qEJR4J477JRcq1bcYCP5GaCwFa2hYqWSQNXS4heJg3ltTqRD0/EP4zIsQMtFjGd2+B1lVn2QcRj/8+ZJEBOMU8fqo00mcu9sZsyJHSfM5mi0RJsxbvMELNzL+u+GiaagPFdW5wruS++hBeR1PgapYceD6yl4rgTJEvUGXyynK8ildstFYIogxNk99aDjzEob+Lw0kBvA5phIPvmPcqGm00Gh9KNg7R0OQYxg7kWpFWClENSDcD6e5HBaIKOXH+L+aO8CLn2V8xMaUdxMCQCDpov1rl+7nFUDpU920H9JG8kmrXuLbvaseksREwI9aVXOtlrQQvnqB9sujGUYoTX2wzPDmpnDPp0/SgIEKGfRjjATC76EttkNthR9EOz8vyjIaX0mVHhAgsMdqjKsoEt2ORD5Gx3QE1it4BIyNTmMDM1iFog0zdteW9F7GdSLNcbEHWSKMMpMLF7tRqsA6NYD4wKbY7tGPFU= 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: On 27/03/2024 09:34, David Hildenbrand wrote: > On 26.03.24 18:51, Ryan Roberts wrote: >> On 26/03/2024 17:39, David Hildenbrand wrote: >>> On 26.03.24 18:32, Ryan Roberts wrote: >>>> On 26/03/2024 17:04, David Hildenbrand wrote: >>>>>>>>> >>>>>>>>> Likely, we just want to read "the real deal" on both sides of the >>>>>>>>> pte_same() >>>>>>>>> handling. >>>>>>>> >>>>>>>> Sorry I'm not sure I understand? You mean read the full pte including >>>>>>>> access/dirty? That's the same as dropping the patch, right? Of course if >>>>>>>> we do >>>>>>>> that, we still have to keep pte_get_lockless() around for this case. In an >>>>>>>> ideal >>>>>>>> world we would convert everything over to ptep_get_lockless_norecency() and >>>>>>>> delete ptep_get_lockless() to remove the ugliness from arm64. >>>>>>> >>>>>>> Yes, agreed. Patch #3 does not look too crazy and it wouldn't really affect >>>>>>> any >>>>>>> architecture. >>>>>>> >>>>>>> I do wonder if pte_same_norecency() should be defined per architecture >>>>>>> and the >>>>>>> default would be pte_same(). So we could avoid the mkold etc on all other >>>>>>> architectures. >>>>>> >>>>>> Wouldn't that break it's semantics? The "norecency" of >>>>>> ptep_get_lockless_norecency() means "recency information in the returned pte >>>>>> may >>>>>> be incorrect". But the "norecency" of pte_same_norecency() means "ignore the >>>>>> access and dirty bits when you do the comparison". >>>>> >>>>> My idea was that ptep_get_lockless_norecency() would return the actual >>>>> result on >>>>> these architectures. So e.g., on x86, there would be no actual change in >>>>> generated code. >>>> >>>> I think this is a bad plan... You'll end up with subtle differences between >>>> architectures. >>>> >>>>> >>>>> But yes, the documentation of these functions would have to be improved. >>>>> >>>>> Now I wonder if ptep_get_lockless_norecency() should actively clear >>>>> dirty/accessed bits to more easily find any actual issues where the bits still >>>>> matter ... >>>> >>>> I did a version that took that approach. Decided it was not as good as this way >>>> though. Now for the life of me, I can't remember my reasoning. >>> >>> Maybe because there are some code paths that check accessed/dirty without >>> "correctness" implications? For example, if the PTE is already dirty, no need to >>> set it dirty etc? >> >> I think I decided I was penalizing the architectures that don't care because all >> their ptep_get_norecency() and ptep_get_lockless_norecency() need to explicitly >> clear access/dirty. And I would have needed ptep_get_norecency() from day 1 so >> that I could feed its result into pte_same(). > > True. With ptep_get_norecency() you're also penalizing other architectures. > Therefore my original thought about making the behavior arch-specific, but the > arch has to make sure to get the combination of > ptep_get_lockless_norecency()+ptep_same_norecency() is right. > > So if an arch decide to ignore bits in ptep_get_lockless_norecency(), it must > make sure to also ignore them in ptep_same_norecency(), and must be able to > handle access/dirty bit changes differently. > > Maybe one could have one variant for "hw-managed access/dirty" vs. "sw managed > accessed or dirty". Only the former would end up ignoring stuff here, the latter > would not. > > But again, just some random thoughts how this affects other architectures and > how we could avoid it. The issue I describe in patch #3 would be gone if > ptep_same_norecency() would just do a ptep_same() check on other architectures > -- and would make it easier to sell :) > I've been thinking some more about this. I think your proposal is the following: // ARM64 ptep_get_lockless_norecency() { - returned access/dirty may be incorrect - returned access/dirty may be differently incorrect between 2 calls } pte_same_norecency() { - ignore access/dirty when doing comparison } ptep_set_access_flags(ptep, pte) { - must not assume access/dirty in pte are "more permissive" than access/dirty in *ptep - must only set access/dirty in *ptep, never clear } // Other arches: no change to generated code ptep_get_lockless_norecency() { return ptep_get_lockless(); } pte_same_norecency() { return pte_same(); } ptep_set_access_flags(ptep, pte) { - may assume access/dirty in pte are "more permissive" than access/dirty in *ptep - if no HW access/dirty updates, "*ptep = pte" always results in "more permissive" change } An arch either specializes all 3 or none of them. This would allow us to get rid of ptep_get_lockless(). And it addresses the bug you found with ptep_set_access_flags(). BUT, I still have a nagging feeling that there are likely to be other similar problems caused by ignoring access/dirty during pte_same_norecency(). I can't convince myself that its definitely all safe and robust. So I'm leaning towards dropping patch 3 and therefore keeping ptep_get_lockless() around. Let me know if you have any insight that might help me change my mind :) Thanks, Ryan