Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5675061rwb; Tue, 22 Nov 2022 03:29:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf7qwOnYmI4ZdqYuB/XDVtQtNZYChiPukRL4BlR+hRANt5Kz7sYV2wOOK6ieDkja/2p5KZM3 X-Received: by 2002:a17:90a:5883:b0:218:f84:3f98 with SMTP id j3-20020a17090a588300b002180f843f98mr31777161pji.238.1669116552861; Tue, 22 Nov 2022 03:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669116552; cv=none; d=google.com; s=arc-20160816; b=1Hel21FXBeInzZ4KTyhsOd4gVGQSDf4OUGzQIkXtrND+hYlASnmA+M1H4XgYbZ/05G 9XMX4Yag76JVJeTl+qkq6OKrATzlmqyks1Pdwi/0kSj58vtyo+IPsg39Hzn/5yo2onIR Tph4zC7UxJtpiukuN5OmiOdFB30P99wJsdQLsA1acUU8fsGi7Bw9hwz7Kq0GQKn6H5fO DSU9bqc7FUh6HYsdxN6bk1CPCJ1JxfCyfq1P5NU15xkcWop19nHTD6lR0IrFg+Ex1ZUj lY12ZvhMl7mwuiL3UXuC0MHisyjEtyU0uLBzp1gGH5WAaNK79mbjArEUT9Ov0IwKdGMF tM2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2kKmKw9F0OesdpU+ebf4yS1QypyTG0EYpnjF6j8iDNs=; b=m7+VvWWfarPC/rGFvd7j3m4uVVMpZvUfNkBrvppKiyjg8AuK0J/kV9FtxLkHJmQiNh 3wMRMocbyx9Rii25EUyGrzdkZXwBJtbNhFQI9tqAyW0HIEdOwp/5Ld5ogVQ6sphDtcig 2UBvVpUq+WgxOeeYHGeqye9w8jZnStKNHCdUaEc5ltC8zjGlT76Q6SP6sPCe+iNXXVzH J3/38SNtus3mX6as7HAVr1YOY8yBVavsAOlr1bV6ABNy5xSAJhC3JSXE0tFn7aiXVxro VX1F4CnFm8pL9cuCuBme1Hyzd2S2tACrADurT10Ng6cU93sJRsZwUnCwml1XG0SaNQXb jUPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a056a00240100b005676e2c36b4si5990703pfh.47.2022.11.22.03.28.56; Tue, 22 Nov 2022 03:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232904AbiKVLLZ (ORCPT + 90 others); Tue, 22 Nov 2022 06:11:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbiKVLLX (ORCPT ); Tue, 22 Nov 2022 06:11:23 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 90F2E2CCAC for ; Tue, 22 Nov 2022 03:11:21 -0800 (PST) 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 5EBD91FB; Tue, 22 Nov 2022 03:11:27 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.3.127]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C7E2E3F587; Tue, 22 Nov 2022 03:11:19 -0800 (PST) Date: Tue, 22 Nov 2022 11:11:14 +0000 From: Mark Rutland To: Will Deacon Cc: Anshuman Khandual , linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64/mm: Intercept pfn changes in set_pte_at() Message-ID: References: <20221116031001.292236-1-anshuman.khandual@arm.com> <20221118141317.GF4046@willie-the-truck> <879e561c-e834-196c-b9c5-6e44ac2c0296@arm.com> <20221122095748.GA19471@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221122095748.GA19471@willie-the-truck> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 22, 2022 at 09:57:49AM +0000, Will Deacon wrote: > On Tue, Nov 22, 2022 at 01:43:17PM +0530, Anshuman Khandual wrote: > > > > > > On 11/18/22 19:43, Will Deacon wrote: > > > On Wed, Nov 16, 2022 at 08:40:01AM +0530, Anshuman Khandual wrote: > > >> Changing pfn on a user page table mapped entry, without first going through > > >> break-before-make (BBM) procedure is unsafe. This just updates set_pte_at() > > >> to intercept such changes, via an updated pgattr_change_is_safe(). This new > > >> check happens via __check_racy_pte_update(), which has now been renamed as > > >> __check_safe_pte_update(). > > >> > > >> Cc: Catalin Marinas > > >> Cc: Will Deacon > > >> Cc: Mark Rutland > > >> Cc: Andrew Morton > > >> Cc: linux-arm-kernel@lists.infradead.org > > >> Cc: linux-kernel@vger.kernel.org > > >> Signed-off-by: Anshuman Khandual > > >> --- > > >> This applies on v6.1-rc4 > > >> > > >> arch/arm64/include/asm/pgtable.h | 8 ++++++-- > > >> arch/arm64/mm/mmu.c | 8 +++++++- > > >> 2 files changed, 13 insertions(+), 3 deletions(-) > > > > > > I remember Mark saying that BBM is sometimes violated by the core code in > > > cases where the pte isn't actually part of a live pgtable (e.g. if it's on > > > the stack or part of a newly allocated table). Won't that cause false > > > positives here? > > > > Could you please elaborate ? If the pte is not on a live page table, then > > pte_valid() will return negative on such entries. So any update there will > > be safe. I am wondering, how this change will cause false positives which > > would not have been possible earlier. > > I don't think pte_valid() will always return false for these entries. > Consider, for example, ptes which are valid but which live in a table that > is not reachable by the MMU. I think this is what Mark had in mind, but it > would be helpful if he could chime in with the specific example he ran into. Yup -- that was the case I had in mind. IIRC I hit that in the past when trying to do something similar, but I can't recall exactly where that was. I suspect that was probably to do with page migration or huge page splitting/merging. Looking around, at least __split_huge_zero_page_pmd() and __split_huge_pmd_locked() do something like that, creating a temporary pmd entry on the stack, populating a table of non-live but valid ptes, then plumbing it into the real pmd. We'd need to check that there aren't other cases like that. Thanks, Mark.