From patchwork Tue Aug 22 14:27:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 136566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp3741565vqi; Tue, 22 Aug 2023 09:27:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGi0ttkDSOARrnzddKdNnhceKvZdrIppSQ0k/lO1uSsqyrBHPet30VnuczIfXULIJ3V4oI2 X-Received: by 2002:a05:6808:17a5:b0:3a7:36f9:51aa with SMTP id bg37-20020a05680817a500b003a736f951aamr14745394oib.17.1692721678119; Tue, 22 Aug 2023 09:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692721678; cv=none; d=google.com; s=arc-20160816; b=SzKAuvYTEJ+5LnzPjPL4AFORCmPxrbowcij4vzsdCkkGOzcJ2TSUDash57ROjF1oCH ea1i4zRQYJhhxMFXdgFUvIBJGyUkTWS50kpBDX8qQ120HovGqcgpQ/hYLpgV8fe95WES 11Fru6OLte+tRWvD/Qi7JSHKDiJbUgOs86u16kNZamHAhkokZT4CZ5J0VM8M1xpjWghk W6u/h9HihLsIAfbyTuHZvpRP2o2GRLuLhPQey/KXrN380fMUd6wSrzCiU4xXQwTqmvF+ PttatPds0epVvPdszZZQXG9pFHyHXvTHTXyqfccy+z8Czgs4X12jelkDWZyOzwNBuptz enJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=5DNKKUpPUD/V3fwC+HtWO+fiV9Bi8h1Ya5UHKPAuWD0=; fh=7Uh4kL0So3TgGgI9x96xeE3gRxyfbfBhRAvN3fkQNFs=; b=Hp5gzZtxVUwxTtnbyMJDggF3jk3peCX2PbxWUMTtENzzKk7tWSbYkYaR3kBALASl7b Fr51CUd56OyyoUneVapOI6WqG55+b2NUe62Iryylt6k6Ryu0nHRRHrfiUP2K4Ge85+Yn H7V0IRYPY3tyqUcI2jMqa2woRh9+rt0lnOjPWplliJ/+uk9JVzLfp7fvEJcNcnFULfku Z/GjV0GOBNXjYd3Md5msaMlYwu4BE+JHieq2pqBgOEgJqLwRoCAEOosNiLqW0QmeT4gc CvK8FlVdVWRyMwgPw7EFX2ZOJEX4XtsAKRw3Eu987+0uhaqpMqhBPIuN6a6eqwaJk/fQ PYng== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 e8-20020a656488000000b00565e386ff40si8819984pgv.744.2023.08.22.09.27.43; Tue, 22 Aug 2023 09:27:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236668AbjHVO2C (ORCPT + 99 others); Tue, 22 Aug 2023 10:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236674AbjHVO2B (ORCPT ); Tue, 22 Aug 2023 10:28:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D349CF7 for ; Tue, 22 Aug 2023 07:27:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DED5B6590E for ; Tue, 22 Aug 2023 14:27:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 452AAC433C7; Tue, 22 Aug 2023 14:27:52 +0000 (UTC) Date: Tue, 22 Aug 2023 16:27:49 +0200 From: Helge Deller To: Dinh Nguyen , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH v2] nios2: Fix flush_dcache_page() for usage from irq context Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774947326329203022 X-GMAIL-MSGID: 1774947326329203022 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 Signed-off-by: Helge Deller --- v2: - rebased patch on top of for-next series, to be applied after the folio patches --- diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h index 7c48c5213fb7..348cea097792 100644 --- a/arch/nios2/include/asm/cacheflush.h +++ b/arch/nios2/include/asm/cacheflush.h @@ -52,5 +52,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 28b805f465a8..0ee9c5f02e08 100644 --- a/arch/nios2/mm/cacheflush.c +++ b/arch/nios2/mm/cacheflush.c @@ -75,12 +75,13 @@ static void flush_aliases(struct address_space *mapping, struct folio *folio) { struct mm_struct *mm = current->active_mm; struct vm_area_struct *vma; + unsigned long flags; pgoff_t pgoff; unsigned long nr = folio_nr_pages(folio); pgoff = folio->index; - flush_dcache_mmap_lock(mapping); + flush_dcache_mmap_lock_irqsave(mapping, flags); vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff + nr - 1) { unsigned long start; @@ -92,7 +93,7 @@ static void flush_aliases(struct address_space *mapping, struct folio *folio) start = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); flush_cache_range(vma, start, start + nr * PAGE_SIZE); } - flush_dcache_mmap_unlock(mapping); + flush_dcache_mmap_unlock_irqrestore(mapping, flags); } void flush_cache_all(void)