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 AD5FEC433EF for ; Thu, 16 Dec 2021 15:21:02 +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:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2FmuePz+LvUHapyAfz5VF3anCW+1AiR/ERlHSQBCg40=; b=1vpM72E1X38u4f 2q2aC4ReTpnKnTZ/a6mhlNkshpKd/C3fnx1jXtUfZ2gPeY0iYoaY3xb1PA9V5rXMe+dpkM+T9T2Cy EF70hT+egaZJcTkeZ+3kil124IGZyOhnVY6f5C/3B02xBBZ7ww4/msxlQkPvZSOsMJeF5W6TPuzaF nPp5jmv/wjzbn8PB92/7udZIMrmYbJ9q82uexrHjo7vRLTnn+vFJwE+R13lRjqz8I+PymCe34ohbK o8PP+N4Qgad9qoLSTLWgEe0s+M535YTtrHOQYc+YT1LrXfTMvordutK8QAQqil9CZkyKAQs3RuTUQ ZbKUq7fBhZ/3YL2H3SjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxsXj-006LvT-0T; Thu, 16 Dec 2021 15:19:39 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxsXf-006LuB-Eu for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 15:19:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639667974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b+sQyopi0uIME//r8qldSsjFvpGoZ+LazJwGfIuhnnM=; b=Szq9nVh1AUGpQ+IgmTXL77NRWClXrOUJVSPPszYhEMLVivyhqJeKYDlSywbG3XS2SVUnU7 F7YCRrw8eloyp+x1vbOyB07GGWnw2aCCylKXbLkqOUUXObZz/psFIw4Pmk7h74uDFzRVNI 54hfy0tNcPKLSWLkTBnL26vIbXCe8Ww= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-VBjlaNEvMo60tjYfs3n4Sg-1; Thu, 16 Dec 2021 10:19:33 -0500 X-MC-Unique: VBjlaNEvMo60tjYfs3n4Sg-1 Received: by mail-wm1-f69.google.com with SMTP id v23-20020a05600c215700b0034566adb612so2199170wml.0 for ; Thu, 16 Dec 2021 07:19:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=b+sQyopi0uIME//r8qldSsjFvpGoZ+LazJwGfIuhnnM=; b=2vx2CAzVdFBecAdHRDjYODFtIJmDg9msY8l5Q/54uvcznOHrKQQr+rFWznhJxvF63Y E3Viiw8jO8ua9ke0GHUrJe4KnQiA5Wedb7nHzcgf2KBY9zA56gM76zPOZQRkT/BnpBIv iPCeZENzYvyxfGACdaVjc2devpQbdstEwfEwxwaKtCd1C8Trl+j1HNz+VLd57hDxETZE 9wZcQ95fDeZPwRQS3wMibf9JW17iyD5Qs4RYgGYhHzGk187yx1Pq9q5ZAoWmbMn2nRwF uLAQRzO+z/LgIXGUQaql98xOsvgrz5PAkiM+RjHjmSxWutI9fX1l21tUDq0zbTSnL6Bs gh1Q== X-Gm-Message-State: AOAM530j4AiPurpx3rjrFWzUWX08/bkB4doD4pq/AWlYyH2dQUF+Rn3d 05Vk2xfVBddt+TnNIj6DC9tH8cH3MDAofvxrQ9axMUycmw5uHHl0WWnUyGu2J8Fw9jQ343YMKkH YgEiQmQon5iqMlBwpEflRUoAnlXc5kktgfaI= X-Received: by 2002:a05:600c:4f86:: with SMTP id n6mr5283254wmq.129.1639667972135; Thu, 16 Dec 2021 07:19:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyi2biwblkcE3Sdx6LdWlmPVQL9ind80eFCHvbthDOUMB7XZKIOVpbSm2flDQPaoEIPReIZhA== X-Received: by 2002:a05:600c:4f86:: with SMTP id n6mr5283219wmq.129.1639667971930; Thu, 16 Dec 2021 07:19:31 -0800 (PST) Received: from [192.168.3.132] (p4ff23dcd.dip0.t-ipconnect.de. [79.242.61.205]) by smtp.gmail.com with ESMTPSA id z6sm6479489wmp.9.2021.12.16.07.19.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 07:19:31 -0800 (PST) Message-ID: <995f4a1c-35e2-03ef-d09d-14e822e186fe@redhat.com> Date: Thu, 16 Dec 2021 16:19:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v3] arm64/mm: avoid fixmap race condition when create pud mapping To: Jianyong Wu , catalin.marinas@arm.com, will@kernel.org, anshuman.khandual@arm.com, akpm@linux-foundation.org Cc: 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 References: <20211216082812.165387-1-jianyong.wu@arm.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20211216082812.165387-1-jianyong.wu@arm.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_071935_623307_65E48339 X-CRM114-Status: GOOD ( 20.08 ) 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 16.12.21 09:28, 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 > --- > > Change log: > > from v2 to v3: > change spin lock to mutex lock as kernel may sleep when create pud > map. > > arch/arm64/mm/mmu.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index acfae9b41cc8..e680a6a8ca40 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_MUTEX(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)); > > + /* > + * We only have one fixmap entry per page-table level, so take > + * the fixmap lock until we're done. > + */ > + mutex_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(); > + mutex_unlock(&fixmap_lock); > } > > static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, > Hopefully now we get it right and there are not any "special" callpaths :) Acked-by: David Hildenbrand -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel