Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5681954rwb; Tue, 22 Nov 2022 03:35:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf7jqaqOZfTOdzS8MWzDEbg3lGvgf+CGBPnM7sFhHCw7gCxatx2fSOEawFhRczsjwFqZCSFs X-Received: by 2002:a17:902:b40b:b0:188:ca57:ce0c with SMTP id x11-20020a170902b40b00b00188ca57ce0cmr7968057plr.57.1669116906992; Tue, 22 Nov 2022 03:35:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669116906; cv=none; d=google.com; s=arc-20160816; b=z/wlaYWu30GVSQvPB5LbpHPLadD4j23zFLpzA2wutiKeltoxf9/ohtMyA+SWau6BQZ GKzhuEHVW83irJvLk2DgyLlpjuIZO5jyN0UvxeOhy/gJqCBmDICwbrcShWp/UB/RZ4sH jBk7dFyc2hdJDw3ldJYdpfy4KoOuG302mpZG5ZmTNrjvqbuIj5RknIbnnNVc47qOM39q h0fWzWluDaa8NMXnI2jPDqNIZUXlArQHqvOdZr5iTvl21bNTaEZ6tI381um1wboY2mqc T1b1mTy3YW+M6iSfnI6PB/SRN2kd/P2bwETIY42hsu65wNYyLGvIkYsQOqYeYwyIklPs D+oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=tvj8O+nsFOzs4cVG+IkU24hIE3u0mfHIpjeGT+XyVnM=; b=RttDhs4ylTdQ8WFNAeopqTcFef3VWaNcjjryeGUCqgWYfNfQHwDOr6j4ex8Y2K3pv/ L0HHYXLgaHBeExG7b8soqb5/xrRC6q6nKKXqTbkGSjyxNdnNaUpT8GQoyEPudjHkBxkc x7jnx0Z1qq15DcTh5xYuFuWiNs5QqHa8YCxvFZVhbxWe93Rx+xOqHRvszu4k4cH3cG0y sM5Y3ZQba2hyuVs4vJ7Vpm5ELTC1yIhjWhgP4ab284j5sSQP15Gg85yfl1oZotoxPoG/ iP194x0TlkhS6uMQ5b3CqIovo80/oLwXRztY8eY3GXK2RPO4Xjaf0R8DhV8V3CHWTe6W +oSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TRip4teq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a1709028c9000b001870506835bsi12329439plo.601.2022.11.22.03.34.55; Tue, 22 Nov 2022 03:35:06 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TRip4teq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232929AbiKVJ6N (ORCPT + 91 others); Tue, 22 Nov 2022 04:58:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbiKVJ57 (ORCPT ); Tue, 22 Nov 2022 04:57:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255611580C for ; Tue, 22 Nov 2022 01:57:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B4CEA6160D for ; Tue, 22 Nov 2022 09:57:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8435C433C1; Tue, 22 Nov 2022 09:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669111074; bh=sHy129/fTPTMr30ytMQ+Mv9Fw9nOip00sz2ioeenqe0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TRip4teqKgeKP+0ivwczuYPgAJsQCkKxSnO6hdzTi3VzSD+KuBuNqdeHE7yqi6SXN +FsKYRE6BwO/U8R2Gyqb37Txcn0Y0EROO4vEh7a+ikRvBvq70vSdUzvWeF+p8rHKJG tZ9wC/KQyyAohjkcXErUASOIjFzmKrTYPnxEpwissxK8dx4skQva5OHdMupe+rZ4kq S2QbP3u7wfMockFVFWmkaJtv/EK9QCkbc8eWajKych2+7mI8mVfCJjbfz04KQHIJj3 Ytc2LVq3YRNQ7rn2RgvSKBZiaHdhxRSBWtva4IXrLRkUNQq0ae7h6PhpJ1X0TzVR7O 6pXLSY33E9yKw== Date: Tue, 22 Nov 2022 09:57:49 +0000 From: Will Deacon To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, Mark Rutland , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64/mm: Intercept pfn changes in set_pte_at() Message-ID: <20221122095748.GA19471@willie-the-truck> References: <20221116031001.292236-1-anshuman.khandual@arm.com> <20221118141317.GF4046@willie-the-truck> <879e561c-e834-196c-b9c5-6e44ac2c0296@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <879e561c-e834-196c-b9c5-6e44ac2c0296@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 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. Will