Message ID | 20230524152633.203927-3-deller@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2909483rwl; Wed, 24 May 2023 08:33:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4slwuQ9xY7K/2rJ0763bCcR3elaoK0nZuVc7pM8NQCYPnoYfzlpwK+493GD8uXiwznJAMC X-Received: by 2002:a05:6a20:840b:b0:10b:b401:8435 with SMTP id c11-20020a056a20840b00b0010bb4018435mr11422594pzd.16.1684942435700; Wed, 24 May 2023 08:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684942435; cv=none; d=google.com; s=arc-20160816; b=tH06n21l51U6VrPfMYQUD0J6PZrguNIrVXm6FrqBKHx5WFX3Wi1dgHdcw7KEsh1DUM JGARcr0n6zHGfENiJ8gSDMRXIB1vB0mtTRp1yb4qJW+d6MNSdEB/Ko0sZitab7WfTnhL Wl6h59rSlvb1+uxANSkma9OVklIP8rqJ9gO4en7lG0Sdv45BCmOf/3bRcH+xBI4/cCQi 1BdcdrPCUOalXpsR2IrCPQGFVoGQS0lj/H2XgD+YYxCpd9NESL1yv69nPT5Gj7z8BGhd SqJ2+PbyyAkktwQN+qAgx4uppTY1uCdBdy57RBzH7Jyk2FnTxcncckZ1q9jI3jhlBgYt IJUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VE2sDTJ058+1pijeQGQ2OhjinAhFkQ5yLRT9Xvradzs=; b=Hmac24MyWDhBOQ8I7QeMEb0sPP+9+mG3wWYtM9qdgXkaLZ4J6INaJnm3MV58IdMKAC I90XnKTpyle2ObqpwhloSVtyEUdkjPGtDB3o0Jf+XdWmCHjyig5qWVDpUdM998tkprEC GfP98o0xW8u00Y88Rb4vLjPVhsOzRtr5ce/Oza4HIzIpeLQiEjfjKI9HslnFAPFcIYeO OGjxnnVWENs6q/N7OmqQVDp48ebUuvVcThfnha29JmzhngpxDui5bKpfim8TneaTsz0y 9NrgkEM8GOARD7+H4CDgnIxoJYkmSX1avCYgPEaFfiwcCew3rDqgFFf6+hMq7lH0Q0/r amiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=hZZAhGz1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a633c0b000000b005340840c0c0si3262009pga.11.2023.05.24.08.33.41; Wed, 24 May 2023 08:33:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=hZZAhGz1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235402AbjEXP0t (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Wed, 24 May 2023 11:26:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234306AbjEXP0q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 11:26:46 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7DD119; Wed, 24 May 2023 08:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1684941998; i=deller@gmx.de; bh=lapEzOcX0STqTt0KmKBhtPzemZ35g1ecV7VM6duHiTw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hZZAhGz1sczisgM/+s2NHhe0zQZMv9rY+98uxQlySChUAYyXqSpBTJY1mHhr2e4JG WtV4Dr1dYxuG12zH0uzGXnFVt4tygu8cfk0eae70buOBrPO9cX+Yp5m7oLM6m5JgIs YzFDOewJUhZnnpRVYgYKv/+FvNPDLV6krnPDRuiIlRSZRyDbgO5q4sjfHM/MMbE4li 4XHmoQhP7yWFfhmRKo8qxTaxAfEpNtEMzmGaNryxpOsjCEGysTRYhgh3eFjYeJpJD1 BxMYMaiirHtVPfvP8GWzWVW7YMozKTnErCUnInHYOlhqTpuIkXvGn3nOBMfpovSQ/L szijpurACVAXA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.145.4]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Md6R1-1qauHl2mzD-00aEQy; Wed, 24 May 2023 17:26:38 +0200 From: Helge Deller <deller@gmx.de> To: linux@armlinux.org.uk, dinguyen@kernel.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org Cc: Helge Deller <deller@gmx.de> Subject: [PATCH 2/3] nios2: Fix flush_dcache_page() for usage from irq context Date: Wed, 24 May 2023 17:26:32 +0200 Message-Id: <20230524152633.203927-3-deller@gmx.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230524152633.203927-1-deller@gmx.de> References: <20230524152633.203927-1-deller@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:QLHFTCIICHSorhJDOatdKxoLujOmIrGuhR+nU+2c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6PkMU9VgiuqWntDUdVBIOzIcwjvHrRjXK8IBL4meZMw z1vWPKL/+1rLG84oDsJa4jIDYwmb9e9mvl4UJxEIOM8fu2QxtAGaCKzKvKb8Uqw/aUMWdvGEE OYdnIg== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766790199373861394?= X-GMAIL-MSGID: =?utf-8?q?1766790199373861394?= |
Series |
Fix flush_dcache_page() for usage from irq context on ARM, NIOS2 and PARISC
|
|
Commit Message
Helge Deller
May 24, 2023, 3:26 p.m. UTC
Since at least kernel 6.1, flush_dcache_page() is called with IRQs
disabled, e.g. from aio_complete().
But the current implementation for flush_dcache_page() on NIOS2
unintentionally re-enables IRQs, which may lead to deadlocks.
Fix it by using xa_lock_irqsave() and xa_unlock_irqrestore()
for the flush_dcache_mmap_*lock() macros instead.
Cc: Dinh Nguyen <dinguyen@kernel.org>
Signed-off-by: Helge Deller <deller@gmx.de>
---
arch/nios2/include/asm/cacheflush.h | 4 ++++
arch/nios2/mm/cacheflush.c | 5 +++--
2 files changed, 7 insertions(+), 2 deletions(-)
--
2.38.1
Comments
Hi Helge, Thanks for the patch. Does it need a Fixes tag? Dinh On 5/24/23 10:26, Helge Deller wrote: > Since at least kernel 6.1, flush_dcache_page() is called with IRQs > disabled, e.g. from aio_complete(). > > But the current implementation for flush_dcache_page() on NIOS2 > unintentionally re-enables IRQs, which may lead to deadlocks. > > Fix it by using xa_lock_irqsave() and xa_unlock_irqrestore() > for the flush_dcache_mmap_*lock() macros instead. > > Cc: Dinh Nguyen <dinguyen@kernel.org> > Signed-off-by: Helge Deller <deller@gmx.de> > --- > arch/nios2/include/asm/cacheflush.h | 4 ++++ > arch/nios2/mm/cacheflush.c | 5 +++-- > 2 files changed, 7 insertions(+), 2 deletions(-) > > diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h > index d0b71dd71287..a37242662809 100644 > --- a/arch/nios2/include/asm/cacheflush.h > +++ b/arch/nios2/include/asm/cacheflush.h > @@ -48,5 +48,9 @@ extern void invalidate_dcache_range(unsigned long start, unsigned long end); > > #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) > #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) > +#define flush_dcache_mmap_lock_irqsave(mapping, flags) \ > + xa_lock_irqsave(&mapping->i_pages, flags) > +#define flush_dcache_mmap_unlock_irqrestore(mapping, flags) \ > + xa_unlock_irqrestore(&mapping->i_pages, flags) > > #endif /* _ASM_NIOS2_CACHEFLUSH_H */ > diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c > index 6aa9257c3ede..35f3b599187f 100644 > --- a/arch/nios2/mm/cacheflush.c > +++ b/arch/nios2/mm/cacheflush.c > @@ -75,11 +75,12 @@ static void flush_aliases(struct address_space *mapping, struct page *page) > { > struct mm_struct *mm = current->active_mm; > struct vm_area_struct *mpnt; > + unsigned long flags; > pgoff_t pgoff; > > pgoff = page->index; > > - flush_dcache_mmap_lock(mapping); > + flush_dcache_mmap_lock_irqsave(mapping, flags); > vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { > unsigned long offset; > > @@ -92,7 +93,7 @@ static void flush_aliases(struct address_space *mapping, struct page *page) > flush_cache_page(mpnt, mpnt->vm_start + offset, > page_to_pfn(page)); > } > - flush_dcache_mmap_unlock(mapping); > + flush_dcache_mmap_unlock_irqrestore(mapping, flags); > } > > void flush_cache_all(void) > -- > 2.38.1 >
Hi Dinh, On 6/14/23 00:39, Dinh Nguyen wrote: > Thanks for the patch. Does it need a Fixes tag? I did not add a fixes tag for the parisc or arm version. The code was originally correct, but later patches then suddenly started using cache flushes from irq context (e.g. 21b40200cfe96 ("aio: use flush_dcache_page()")) which then triggers the bug. So, it's hard to say that it fixes one specific commit. I suggest you backport it as far as possible. Helge > Dinh > > On 5/24/23 10:26, Helge Deller wrote: >> Since at least kernel 6.1, flush_dcache_page() is called with IRQs >> disabled, e.g. from aio_complete(). >> >> But the current implementation for flush_dcache_page() on NIOS2 >> unintentionally re-enables IRQs, which may lead to deadlocks. >> >> Fix it by using xa_lock_irqsave() and xa_unlock_irqrestore() >> for the flush_dcache_mmap_*lock() macros instead. >> >> Cc: Dinh Nguyen <dinguyen@kernel.org> >> Signed-off-by: Helge Deller <deller@gmx.de> >> --- >> arch/nios2/include/asm/cacheflush.h | 4 ++++ >> arch/nios2/mm/cacheflush.c | 5 +++-- >> 2 files changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h >> index d0b71dd71287..a37242662809 100644 >> --- a/arch/nios2/include/asm/cacheflush.h >> +++ b/arch/nios2/include/asm/cacheflush.h >> @@ -48,5 +48,9 @@ extern void invalidate_dcache_range(unsigned long start, unsigned long end); >> >> #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) >> #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) >> +#define flush_dcache_mmap_lock_irqsave(mapping, flags) \ >> + xa_lock_irqsave(&mapping->i_pages, flags) >> +#define flush_dcache_mmap_unlock_irqrestore(mapping, flags) \ >> + xa_unlock_irqrestore(&mapping->i_pages, flags) >> >> #endif /* _ASM_NIOS2_CACHEFLUSH_H */ >> diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c >> index 6aa9257c3ede..35f3b599187f 100644 >> --- a/arch/nios2/mm/cacheflush.c >> +++ b/arch/nios2/mm/cacheflush.c >> @@ -75,11 +75,12 @@ static void flush_aliases(struct address_space *mapping, struct page *page) >> { >> struct mm_struct *mm = current->active_mm; >> struct vm_area_struct *mpnt; >> + unsigned long flags; >> pgoff_t pgoff; >> >> pgoff = page->index; >> >> - flush_dcache_mmap_lock(mapping); >> + flush_dcache_mmap_lock_irqsave(mapping, flags); >> vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { >> unsigned long offset; >> >> @@ -92,7 +93,7 @@ static void flush_aliases(struct address_space *mapping, struct page *page) >> flush_cache_page(mpnt, mpnt->vm_start + offset, >> page_to_pfn(page)); >> } >> - flush_dcache_mmap_unlock(mapping); >> + flush_dcache_mmap_unlock_irqrestore(mapping, flags); >> } >> >> void flush_cache_all(void) >> -- >> 2.38.1 >>
diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h index d0b71dd71287..a37242662809 100644 --- a/arch/nios2/include/asm/cacheflush.h +++ b/arch/nios2/include/asm/cacheflush.h @@ -48,5 +48,9 @@ extern void invalidate_dcache_range(unsigned long start, unsigned long end); #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) +#define flush_dcache_mmap_lock_irqsave(mapping, flags) \ + xa_lock_irqsave(&mapping->i_pages, flags) +#define flush_dcache_mmap_unlock_irqrestore(mapping, flags) \ + xa_unlock_irqrestore(&mapping->i_pages, flags) #endif /* _ASM_NIOS2_CACHEFLUSH_H */ diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c index 6aa9257c3ede..35f3b599187f 100644 --- a/arch/nios2/mm/cacheflush.c +++ b/arch/nios2/mm/cacheflush.c @@ -75,11 +75,12 @@ static void flush_aliases(struct address_space *mapping, struct page *page) { struct mm_struct *mm = current->active_mm; struct vm_area_struct *mpnt; + unsigned long flags; pgoff_t pgoff; pgoff = page->index; - flush_dcache_mmap_lock(mapping); + flush_dcache_mmap_lock_irqsave(mapping, flags); vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { unsigned long offset; @@ -92,7 +93,7 @@ static void flush_aliases(struct address_space *mapping, struct page *page) flush_cache_page(mpnt, mpnt->vm_start + offset, page_to_pfn(page)); } - flush_dcache_mmap_unlock(mapping); + flush_dcache_mmap_unlock_irqrestore(mapping, flags); } void flush_cache_all(void)