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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EDF1ECAAD3 for ; Thu, 1 Sep 2022 15:50:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 03DAF4A104; Thu, 1 Sep 2022 11:50:08 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qWaJDqL2kK0t; Thu, 1 Sep 2022 11:50:05 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id B73424A1B0; Thu, 1 Sep 2022 11:50:05 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 50CCB4A104 for ; Thu, 1 Sep 2022 11:50:04 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rPakmbuuuUIj for ; Thu, 1 Sep 2022 11:50:03 -0400 (EDT) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 0C3E94A0FE for ; Thu, 1 Sep 2022 11:50:02 -0400 (EDT) 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 D70C561F1A; Thu, 1 Sep 2022 15:50:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC8EDC433D6; Thu, 1 Sep 2022 15:49:59 +0000 (UTC) Date: Thu, 1 Sep 2022 16:49:56 +0100 From: Catalin Marinas To: Peter Collingbourne Subject: Re: [PATCH v3 1/7] arm64: mte: Fix/clarify the PG_mte_tagged semantics Message-ID: References: <20220810193033.1090251-1-pcc@google.com> <20220810193033.1090251-2-pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220810193033.1090251-2-pcc@google.com> Cc: kvm@vger.kernel.org, Marc Zyngier , Cornelia Huck , Steven Price , linux-arm-kernel@lists.infradead.org, Vincenzo Frascino , Will Deacon , kvmarm@lists.cs.columbia.edu, Evgenii Stepanov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Wed, Aug 10, 2022 at 12:30:27PM -0700, Peter Collingbourne wrote: > From: Catalin Marinas > > Currently the PG_mte_tagged page flag mostly means the page contains > valid tags and it should be set after the tags have been cleared or > restored. However, in mte_sync_tags() it is set before setting the tags > to avoid, in theory, a race with concurrent mprotect(PROT_MTE) for > shared pages. However, a concurrent mprotect(PROT_MTE) with a copy on > write in another thread can cause the new page to have stale tags. > Similarly, tag reading via ptrace() can read stale tags of the > PG_mte_tagged flag is set before actually clearing/restoring the tags. > > Fix the PG_mte_tagged semantics so that it is only set after the tags > have been cleared or restored. This is safe for swap restoring into a > MAP_SHARED or CoW page since the core code takes the page lock. Add two > functions to test and set the PG_mte_tagged flag with acquire and > release semantics. The downside is that concurrent mprotect(PROT_MTE) on > a MAP_SHARED page may cause tag loss. This is already the case for KVM > guests if a VMM changes the page protection while the guest triggers a > user_mem_abort(). > > Signed-off-by: Catalin Marinas > Cc: Will Deacon > Cc: Marc Zyngier > Cc: Steven Price > Cc: Peter Collingbourne > --- > v3: > - fix build with CONFIG_ARM64_MTE disabled When you post someone else's patches (thanks for updating them BTW), please add your Signed-off-by line. You should also add a note in the SoB block about the changes you made, so something like: [pcc@google.com: fix build with CONFIG_ARM64_MTE disabled] Singed-off-by: your name/address -- Catalin _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40852ECAAD3 for ; Thu, 1 Sep 2022 15:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mFlo5QW+cpgMOmrpfDeXjI2XMn9m8pEYAgJnrrI5dNo=; b=RHiEEWva7WBHdD dad+tM44feqVAInRsTtAVrVAAZvxhQq0ecz21GQbXEUPAl7nA0jqDgnfqYJA9xfeJB3mVgBBXnhhp HlohyIUwq4D+sLQ6353C9/QB9hWOHMcxJkUslxlt/lMq6cKzm6v95kixa3nZ8I5yXeJpAbvuL5eED bEXZ6FBPTe5Zc8mVJoA6CoK31rZ+tMnL8JiPElbAAAVh5rx7/WSHOhGjEQZWOYOEHc5+2RMsUMqd4 weCMs2oh4p5LuZCAbMHphqfvCEJs2FBOwoe2oiMuWj3zrBV7nbEfHoNUhg/12tKKiv/YFoBVhNAxb Z5PT5z1ycvEO/C0hZoLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTmSG-00D184-Gd; Thu, 01 Sep 2022 15:50:08 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTmSA-00D0yJ-OG for linux-arm-kernel@lists.infradead.org; Thu, 01 Sep 2022 15:50:04 +0000 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 D70C561F1A; Thu, 1 Sep 2022 15:50:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC8EDC433D6; Thu, 1 Sep 2022 15:49:59 +0000 (UTC) Date: Thu, 1 Sep 2022 16:49:56 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Cornelia Huck , Will Deacon , Marc Zyngier , Evgenii Stepanov , kvm@vger.kernel.org, Steven Price , Vincenzo Frascino Subject: Re: [PATCH v3 1/7] arm64: mte: Fix/clarify the PG_mte_tagged semantics Message-ID: References: <20220810193033.1090251-1-pcc@google.com> <20220810193033.1090251-2-pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220810193033.1090251-2-pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_085002_888353_D60D4EEF X-CRM114-Status: GOOD ( 23.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 10, 2022 at 12:30:27PM -0700, Peter Collingbourne wrote: > From: Catalin Marinas > > Currently the PG_mte_tagged page flag mostly means the page contains > valid tags and it should be set after the tags have been cleared or > restored. However, in mte_sync_tags() it is set before setting the tags > to avoid, in theory, a race with concurrent mprotect(PROT_MTE) for > shared pages. However, a concurrent mprotect(PROT_MTE) with a copy on > write in another thread can cause the new page to have stale tags. > Similarly, tag reading via ptrace() can read stale tags of the > PG_mte_tagged flag is set before actually clearing/restoring the tags. > > Fix the PG_mte_tagged semantics so that it is only set after the tags > have been cleared or restored. This is safe for swap restoring into a > MAP_SHARED or CoW page since the core code takes the page lock. Add two > functions to test and set the PG_mte_tagged flag with acquire and > release semantics. The downside is that concurrent mprotect(PROT_MTE) on > a MAP_SHARED page may cause tag loss. This is already the case for KVM > guests if a VMM changes the page protection while the guest triggers a > user_mem_abort(). > > Signed-off-by: Catalin Marinas > Cc: Will Deacon > Cc: Marc Zyngier > Cc: Steven Price > Cc: Peter Collingbourne > --- > v3: > - fix build with CONFIG_ARM64_MTE disabled When you post someone else's patches (thanks for updating them BTW), please add your Signed-off-by line. You should also add a note in the SoB block about the changes you made, so something like: [pcc@google.com: fix build with CONFIG_ARM64_MTE disabled] Singed-off-by: your name/address -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66EFDECAAD1 for ; Thu, 1 Sep 2022 15:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234523AbiIAPuW (ORCPT ); Thu, 1 Sep 2022 11:50:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234387AbiIAPuU (ORCPT ); Thu, 1 Sep 2022 11:50:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D734DF34 for ; Thu, 1 Sep 2022 08:50:04 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id EDE8AB82837 for ; Thu, 1 Sep 2022 15:50:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC8EDC433D6; Thu, 1 Sep 2022 15:49:59 +0000 (UTC) Date: Thu, 1 Sep 2022 16:49:56 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Cornelia Huck , Will Deacon , Marc Zyngier , Evgenii Stepanov , kvm@vger.kernel.org, Steven Price , Vincenzo Frascino Subject: Re: [PATCH v3 1/7] arm64: mte: Fix/clarify the PG_mte_tagged semantics Message-ID: References: <20220810193033.1090251-1-pcc@google.com> <20220810193033.1090251-2-pcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220810193033.1090251-2-pcc@google.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Aug 10, 2022 at 12:30:27PM -0700, Peter Collingbourne wrote: > From: Catalin Marinas > > Currently the PG_mte_tagged page flag mostly means the page contains > valid tags and it should be set after the tags have been cleared or > restored. However, in mte_sync_tags() it is set before setting the tags > to avoid, in theory, a race with concurrent mprotect(PROT_MTE) for > shared pages. However, a concurrent mprotect(PROT_MTE) with a copy on > write in another thread can cause the new page to have stale tags. > Similarly, tag reading via ptrace() can read stale tags of the > PG_mte_tagged flag is set before actually clearing/restoring the tags. > > Fix the PG_mte_tagged semantics so that it is only set after the tags > have been cleared or restored. This is safe for swap restoring into a > MAP_SHARED or CoW page since the core code takes the page lock. Add two > functions to test and set the PG_mte_tagged flag with acquire and > release semantics. The downside is that concurrent mprotect(PROT_MTE) on > a MAP_SHARED page may cause tag loss. This is already the case for KVM > guests if a VMM changes the page protection while the guest triggers a > user_mem_abort(). > > Signed-off-by: Catalin Marinas > Cc: Will Deacon > Cc: Marc Zyngier > Cc: Steven Price > Cc: Peter Collingbourne > --- > v3: > - fix build with CONFIG_ARM64_MTE disabled When you post someone else's patches (thanks for updating them BTW), please add your Signed-off-by line. You should also add a note in the SoB block about the changes you made, so something like: [pcc@google.com: fix build with CONFIG_ARM64_MTE disabled] Singed-off-by: your name/address -- Catalin