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 ABBB6C433FE for ; Thu, 27 Jan 2022 12:35:51 +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=eGXwp9WGostu7VinGIedrFZSxzdAwnElkx4RWX14XMI=; b=caS1TVrjbpdGuW ES1Y9x2u6tjvXVxvZNrp41F2JutPB7WoDAPUFXYoms5QBITSU0A6KHztrxQcoTm6waKoZDAX3iCg0 nyDO76/3xg87M4BvWbr+cMXxoYxvlWbCRid+KJCDBIJ+fuk70zrsepM169NJvdwwzMxmlHejr7VIM XWJnGYOqQplLHbXKd/X4tCP7U8sHgF+3rEeoJunXEpWS7QNcK1AVm4RRGpdRAPLwwEr4lBISmTI8A gdml/XlmmnO0dJuxA6WqnZI3LqKkfs5lvkIf3x9Uv9dfSKutTnVrBiq8KdjUYvfoZ3Gi6v+04nvcB bjUfi/qy+ZpnJZ4RsDOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nD3z5-00FjKw-W9; Thu, 27 Jan 2022 12:34:40 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nD3z2-00FjJp-UZ for linux-arm-kernel@lists.infradead.org; Thu, 27 Jan 2022 12:34:38 +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 ams.source.kernel.org (Postfix) with ESMTPS id A1F7FB821EE; Thu, 27 Jan 2022 12:34:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EB75C340E4; Thu, 27 Jan 2022 12:34:32 +0000 (UTC) Date: Thu, 27 Jan 2022 12:34:28 +0000 From: Catalin Marinas To: David Hildenbrand Cc: Jianyong Wu , Ard Biesheuvel , Justin He , "will@kernel.org" , Anshuman Khandual , "akpm@linux-foundation.org" , "quic_qiancai@quicinc.com" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "gshan@redhat.com" , nd Subject: Re: [PATCH v3] arm64/mm: avoid fixmap race condition when create pud mapping Message-ID: References: <3e6513f9-77ca-79e5-d185-7e9a11ec7689@redhat.com> <65fdd873-1f93-56e3-c7a5-98d621c5dbd8@redhat.com> <7eb4bc77-c1db-99c4-4c77-ae9ddd159abb@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220127_043437_145977_9A240F17 X-CRM114-Status: GOOD ( 20.50 ) 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 Thu, Jan 27, 2022 at 01:22:47PM +0100, David Hildenbrand wrote: > > Yes, system_state can roughly separate these callers of __create_pgd_mapping. When system_state > SYSTEM_BOOTING we can add the lock. > > Thus, I have the following change: > > > > static DEFINE_SPINLOCK(swapper_pgdir_lock); > > +static DEFINE_MUTEX(fixmap_lock); > > > > void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) > > { > > @@ -329,6 +330,8 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > > } > > BUG_ON(p4d_bad(p4d)); > > > > + if (system_state > SYSTEM_BOOTING) > > As there is nothing smaller than SYSTEM_BOOTING, you can use > if (system_state != SYSTEM_BOOTING) > > ... > > > > > It seems work and somehow simper. But I don't know if it is reasonable to do this. So, any idea? @Ard Biesheuvel @Catalin Marinas > > It's worth looking at kernel/notifier.c, e.g., > blocking_notifier_chain_register() > > if (unlikely(system_state == SYSTEM_BOOTING)) > return notifier_chain_register(&nh->head, n); > > down_write(&nh->rwsem); > ret = notifier_chain_register(&nh->head, n); > up_write(&nh->rwsem); > > If we decide to go down that path, we should make sure to add a comment like > > /* > * No need for locking during early boot. And it doesn't work as > * expected with KASLR enabled where we might clear BSS twice. > */ A similar approach sounds fine to me. -- 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 704C1C433EF for ; Thu, 27 Jan 2022 12:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241173AbiA0Meg (ORCPT ); Thu, 27 Jan 2022 07:34:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231901AbiA0Meg (ORCPT ); Thu, 27 Jan 2022 07:34:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79E3C061714 for ; Thu, 27 Jan 2022 04:34:35 -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 1EC5261A70 for ; Thu, 27 Jan 2022 12:34:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EB75C340E4; Thu, 27 Jan 2022 12:34:32 +0000 (UTC) Date: Thu, 27 Jan 2022 12:34:28 +0000 From: Catalin Marinas To: David Hildenbrand Cc: Jianyong Wu , Ard Biesheuvel , Justin He , "will@kernel.org" , Anshuman Khandual , "akpm@linux-foundation.org" , "quic_qiancai@quicinc.com" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "gshan@redhat.com" , nd Subject: Re: [PATCH v3] arm64/mm: avoid fixmap race condition when create pud mapping Message-ID: References: <3e6513f9-77ca-79e5-d185-7e9a11ec7689@redhat.com> <65fdd873-1f93-56e3-c7a5-98d621c5dbd8@redhat.com> <7eb4bc77-c1db-99c4-4c77-ae9ddd159abb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 27, 2022 at 01:22:47PM +0100, David Hildenbrand wrote: > > Yes, system_state can roughly separate these callers of __create_pgd_mapping. When system_state > SYSTEM_BOOTING we can add the lock. > > Thus, I have the following change: > > > > static DEFINE_SPINLOCK(swapper_pgdir_lock); > > +static DEFINE_MUTEX(fixmap_lock); > > > > void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) > > { > > @@ -329,6 +330,8 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > > } > > BUG_ON(p4d_bad(p4d)); > > > > + if (system_state > SYSTEM_BOOTING) > > As there is nothing smaller than SYSTEM_BOOTING, you can use > if (system_state != SYSTEM_BOOTING) > > ... > > > > > It seems work and somehow simper. But I don't know if it is reasonable to do this. So, any idea? @Ard Biesheuvel @Catalin Marinas > > It's worth looking at kernel/notifier.c, e.g., > blocking_notifier_chain_register() > > if (unlikely(system_state == SYSTEM_BOOTING)) > return notifier_chain_register(&nh->head, n); > > down_write(&nh->rwsem); > ret = notifier_chain_register(&nh->head, n); > up_write(&nh->rwsem); > > If we decide to go down that path, we should make sure to add a comment like > > /* > * No need for locking during early boot. And it doesn't work as > * expected with KASLR enabled where we might clear BSS twice. > */ A similar approach sounds fine to me. -- Catalin