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 26813C433EF for ; Mon, 13 Dec 2021 13:46:42 +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=aatbnvlVXg8buGtbGQ5AI7gT4uhfa4mHl42+hD2vNYY=; b=tzCoNgivhjPwKb D5he7S11+s8v8I3qjPfIMvFhKwV3wgYdAPT/xjm/0KMROJJCsr6WReGKWUgHvb2DEvOuxYxMqtO9t 8lfBGKAdZgKA4T9YqdoX0YqI9svcy3D+AJJI2a90ElfUf1n2MOnfNv5iHnEckuL7fa2z2EfIm43vT ikV+3KWrajF4MYQR/ERh/7PRp7bjF9i8CxZyT0HeevUQ62prY0lcfPDhOi6glzjBqDofgX8ALAKux 9Xl5pa7txfYucD6o++1eLT0DjU9i80O0BYPtgqP9x4ueXPJ1tv+7UBz0Zi3vSn4kJwoYp6eOfCv8h EPkaW4UmostVI4qooQJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwldj-009mKY-Hl; Mon, 13 Dec 2021 13:45:15 +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 1mwldg-009mJD-1x for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 13:45:13 +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 206A3B80EDF; Mon, 13 Dec 2021 13:45:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFC9EC34601; Mon, 13 Dec 2021 13:45:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639403108; bh=91yVe1naGosE6KNTG6Oc+VHEYyMxHFTrdQmSPgcWi3k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WbxC2oCIfQeKo3kYgo2wl3ithsZJAwPeZZsS7N8sWga9fuPT9ocYgeiZSKOYqxtJD y0g7kGh67vnB4A90zLuUXZgnqSIR4yVa8fOVGM2QRgjFl26dkZHWwH+1z4uGToAkmp 6Snw6uGZaxyQJPcfjqBZDaLL5ZVcNLQfYGL3cv1CsvEnPvkknWpIYngpyguHxckCxc o6UY/8J8ZvlBny/0Qenasg1tHfFpgvPHMB+tvYoJBTqZ3kr9woSdM/9rniweB92PMq uEYJjSqQ/ouAsABEB88jF3rYVcf86ztNk8pzVKbYM1YV19/ha7FmaxM5ZEEDITF+M9 sDurvEPexN2OA== Date: Mon, 13 Dec 2021 13:45:03 +0000 From: Will Deacon To: Ard Biesheuvel Cc: Anshuman Khandual , Jianyong Wu , Catalin Marinas , Andrew Morton , Linux Kernel Mailing List , Linux ARM , David Hildenbrand , Gavin Shan , Jia He , nd Subject: Re: [PATCH v2] arm64/mm: avoid fixmap race condition when create pud mapping Message-ID: <20211213134503.GD11570@willie-the-truck> References: <20211210095432.51798-1-jianyong.wu@arm.com> <1e63e2f7-0563-2866-4665-84fe220b615f@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_054512_408271_B316350A X-CRM114-Status: GOOD ( 25.98 ) 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 Mon, Dec 13, 2021 at 11:35:16AM +0100, Ard Biesheuvel wrote: > On Mon, 13 Dec 2021 at 11:16, Anshuman Khandual > wrote: > > On 12/10/21 3:24 PM, Jianyong Wu wrote: > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > > index acfae9b41cc8..98ac09ae9588 100644 > > > --- a/arch/arm64/mm/mmu.c > > > +++ b/arch/arm64/mm/mmu.c > > > @@ -63,6 +63,7 @@ static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; > > > static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; > > > > > > static DEFINE_SPINLOCK(swapper_pgdir_lock); > > > +static DEFINE_SPINLOCK(fixmap_lock); > > > > > > void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) > > > { > > > @@ -329,6 +330,11 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > > > } > > > BUG_ON(p4d_bad(p4d)); > > > > > > + /* > > > + * fixmap is global resource, thus it needs to be protected by a lock > > > + * in case of race condition. > > > + */ > > > > Small nit, format and align this comment block. I guess > > could also be done while merging this patch as well. > > > > > + spin_lock(&fixmap_lock); > > > pudp = pud_set_fixmap_offset(p4dp, addr); > > > do { > > > pud_t old_pud = READ_ONCE(*pudp); > > > @@ -359,6 +365,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > > > } while (pudp++, addr = next, addr != end); > > > > > > pud_clear_fixmap(); > > > + spin_unlock(&fixmap_lock); > > > } > > > > > > static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, > > > > > > > Reviewed-by: Anshuman Khandual > > We have different fixmap slots for different page table levels, so > 'fixmap_lock' is not the right name. > > But we already have swapper_pgdir_lock as well, which serializes the > use of the pgdir level fixmap slot. And we have no spinlocks > protecting the other levels. > > So should we perhaps clean this up more comprehensively? Wouldn't it > be better to add a mutex to __create_pgd_mapping(), for instance? That does sound like a better way to do things, but the simplicity of this patch is quite attractive for backporting. Would you object to me queuing it as-is, on the premise that I'm more than happy to take consolidation changes on top? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel