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 544BAC433F5 for ; Wed, 5 Jan 2022 18:05:15 +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=9FGvOTbRCuPWqegUJb8UnEH1/kOSThMKqMsFGUrdzKs=; b=X2aVicABkGD0dz 2rfD5fVL8lvrs9dEvwLT5vr/0YMtC+P0BdH2bIhPCnlYJs4hcHHPaDHIFHUK6AObcNBnk5ZL2DALc 8g+lvlfvD9s1G45vq4Up21Kb+YeQQ6YA2G5Fl8o0wp5HUT0oRaUIkb/Q2MktDAiSzlkSppgsWfFjS 7/ByRh/kj/zkkWYO8nQnmK1ZVsaUqjSU1qCggbSmj3L1vBmC2u0ugHNGDJX9OlEGZ53o+ynbJqGdg QG657ANchDJB9dUVisr+7Vvaq2W5h97IRxQWh5Su7VkmtRCBKtJx9FJ+t86RIzbsa/IpBBD8lJNk5 V9SO/dVeyaEzPVfdKFWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5Adt-00FYAO-DQ; Wed, 05 Jan 2022 18:04:09 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5Adp-00FY9W-JF for linux-arm-kernel@lists.infradead.org; Wed, 05 Jan 2022 18:04:06 +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 B047B61864; Wed, 5 Jan 2022 18:04:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13CFCC36AE0; Wed, 5 Jan 2022 18:04:00 +0000 (UTC) Date: Wed, 5 Jan 2022 18:03:57 +0000 From: Catalin Marinas To: Jianyong Wu Cc: will@kernel.org, anshuman.khandual@arm.com, akpm@linux-foundation.org, david@redhat.com, quic_qiancai@quicinc.com, ardb@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, gshan@redhat.com, justin.he@arm.com, nd@arm.com Subject: Re: [PATCH v3] arm64/mm: avoid fixmap race condition when create pud mapping Message-ID: References: <20211216082812.165387-1-jianyong.wu@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211216082812.165387-1-jianyong.wu@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220105_100405_698318_B8995161 X-CRM114-Status: GOOD ( 12.81 ) 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, Dec 16, 2021 at 04:28:12PM +0800, Jianyong Wu wrote: > The 'fixmap' is a global resource and is used recursively by > create pud mapping(), leading to a potential race condition in the > presence of a concurrent call to alloc_init_pud(): > > kernel_init thread virtio-mem workqueue thread > ================== =========================== > > alloc_init_pud(...) alloc_init_pud(...) > pudp = pud_set_fixmap_offset(...) pudp = pud_set_fixmap_offset(...) > READ_ONCE(*pudp) > pud_clear_fixmap(...) > READ_ONCE(*pudp) // CRASH! > > As kernel may sleep during creating pud mapping, introduce a mutex lock to > serialise use of the fixmap entries by alloc_init_pud(). > > Signed-off-by: Jianyong Wu I tried to queue this patch but with certain configurations it doesn't boot under Qemu. Starting from defconfig, update .config with (I had this in one of my build scripts): $ ./scripts/config \ -e DEBUG_KERNEL \ -e DEBUG_PAGEALLOC \ -e DEBUG_PAGEALLOC_ENABLE_DEFAULT \ -e DEBUG_WX \ -e DEBUG_SET_MODULE_RONX \ -e DEBUG_ALIGN_RODATA \ -e ARM64_PTDUMP_DEBUGFS \ -e DEBUG_OBJECTS \ -e DEBUG_OBJECTS_FREE \ -e DEBUG_OBJECTS_TIMERS \ -e DEBUG_KOBJECT_RELEASE \ -e DEBUG_LOCKING_API_SELFTESTS \ -e DEBUG_PREEMPT \ -e DEBUG_TIMEKEEPING \ -e DEBUG_VM \ -e DEBUG_VM_VMACACHE \ -e DEBUG_VM_RB \ -e DEBUG_VM_PGFLAGS \ -e DEBUG_VIRTUAL \ -e DEBUG_LIST \ -e DEBUG_PI_LIST \ -e DEBUG_SG \ -e PROVE_LOCKING \ -e DEBUG_RT_MUTEXES \ -e DEBUG_ATOMIC_SLEEP \ -e ATOMIC64_SELFTEST It stop after exiting the EFI boot services. I did not have time to debug. -- 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 B5324C433F5 for ; Wed, 5 Jan 2022 18:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242708AbiAESEH (ORCPT ); Wed, 5 Jan 2022 13:04:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242686AbiAESEF (ORCPT ); Wed, 5 Jan 2022 13:04:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABE45C061245 for ; Wed, 5 Jan 2022 10:04:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id 724A1B81CE7 for ; Wed, 5 Jan 2022 18:04:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13CFCC36AE0; Wed, 5 Jan 2022 18:04:00 +0000 (UTC) Date: Wed, 5 Jan 2022 18:03:57 +0000 From: Catalin Marinas To: Jianyong Wu Cc: will@kernel.org, anshuman.khandual@arm.com, akpm@linux-foundation.org, david@redhat.com, quic_qiancai@quicinc.com, ardb@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, gshan@redhat.com, justin.he@arm.com, nd@arm.com Subject: Re: [PATCH v3] arm64/mm: avoid fixmap race condition when create pud mapping Message-ID: References: <20211216082812.165387-1-jianyong.wu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211216082812.165387-1-jianyong.wu@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 16, 2021 at 04:28:12PM +0800, Jianyong Wu wrote: > The 'fixmap' is a global resource and is used recursively by > create pud mapping(), leading to a potential race condition in the > presence of a concurrent call to alloc_init_pud(): > > kernel_init thread virtio-mem workqueue thread > ================== =========================== > > alloc_init_pud(...) alloc_init_pud(...) > pudp = pud_set_fixmap_offset(...) pudp = pud_set_fixmap_offset(...) > READ_ONCE(*pudp) > pud_clear_fixmap(...) > READ_ONCE(*pudp) // CRASH! > > As kernel may sleep during creating pud mapping, introduce a mutex lock to > serialise use of the fixmap entries by alloc_init_pud(). > > Signed-off-by: Jianyong Wu I tried to queue this patch but with certain configurations it doesn't boot under Qemu. Starting from defconfig, update .config with (I had this in one of my build scripts): $ ./scripts/config \ -e DEBUG_KERNEL \ -e DEBUG_PAGEALLOC \ -e DEBUG_PAGEALLOC_ENABLE_DEFAULT \ -e DEBUG_WX \ -e DEBUG_SET_MODULE_RONX \ -e DEBUG_ALIGN_RODATA \ -e ARM64_PTDUMP_DEBUGFS \ -e DEBUG_OBJECTS \ -e DEBUG_OBJECTS_FREE \ -e DEBUG_OBJECTS_TIMERS \ -e DEBUG_KOBJECT_RELEASE \ -e DEBUG_LOCKING_API_SELFTESTS \ -e DEBUG_PREEMPT \ -e DEBUG_TIMEKEEPING \ -e DEBUG_VM \ -e DEBUG_VM_VMACACHE \ -e DEBUG_VM_RB \ -e DEBUG_VM_PGFLAGS \ -e DEBUG_VIRTUAL \ -e DEBUG_LIST \ -e DEBUG_PI_LIST \ -e DEBUG_SG \ -e PROVE_LOCKING \ -e DEBUG_RT_MUTEXES \ -e DEBUG_ATOMIC_SLEEP \ -e ATOMIC64_SELFTEST It stop after exiting the EFI boot services. I did not have time to debug. -- Catalin