From patchwork Fri Mar 10 16:29:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13169600 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25A38C6FD1F for ; Fri, 10 Mar 2023 16:29:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61FDE6B0071; Fri, 10 Mar 2023 11:29:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CFD96B0074; Fri, 10 Mar 2023 11:29:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 499706B0075; Fri, 10 Mar 2023 11:29:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3763C6B0071 for ; Fri, 10 Mar 2023 11:29:11 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0E1601A01D8 for ; Fri, 10 Mar 2023 16:29:11 +0000 (UTC) X-FDA: 80553523302.17.C9D3FE8 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 2C82010000E for ; Fri, 10 Mar 2023 16:29:08 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=NNSiKyB5; dkim=pass header.d=linutronix.de header.s=2020e header.b=1m605YEJ; spf=pass (imf05.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678465749; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=uBAEWUyZKwUmKqqazL7gQLTZOP1jiWdjfH5fZ0edGUU=; b=tWil2H0FymaxKtwFetWJmuaENFiZx/L+kf74g8Wi3VNLCNukT3eLQeC9Rue5VPKXAQAx6h t9XPV3EPWmRVic5weyveeZc6UgM05rE/mCYMqWGCLz5ujnuXV8UXa26zCsCokgvPFjQwF7 NCB98dH+Ewoi84UG6FVhkS8HmICNzcg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=NNSiKyB5; dkim=pass header.d=linutronix.de header.s=2020e header.b=1m605YEJ; spf=pass (imf05.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678465749; a=rsa-sha256; cv=none; b=TdQvnlmW2vrceoi0VgZgIigWacG4cqun3RYlYMov2jgQuelisg1gtJaljN7MflVMDYu48z gDniljk9ozzjT7l8uagrt63jK7JuiWMPD/+keSFUT967FO0ORBVaIgL50BN6jug0POBNJn dmpLWLfMMiiZPpaxbGaXSqqm+nW1//w= Date: Fri, 10 Mar 2023 17:29:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1678465747; 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; bh=uBAEWUyZKwUmKqqazL7gQLTZOP1jiWdjfH5fZ0edGUU=; b=NNSiKyB5IHTrbMB6dmMGiaJR/tftZeADFMcbX6qlAmPMVpm4BNi+71bCAY99Fu5GianfuH qqPCjRR402JCDU/QYbl7b4ccm0S7dljJ2zAPiSYSKNVmawQyXBLlWxynf2Hg1wedOgNVMC J6zIk+EP4Y9tHMztNCeFEgLRCurwqVDEPP2x/+q8larNso2hwgfYkZsmzMX37tysq1+PTL FtLEc5rjUXrTMYlgrLBJZUPj7rGiaKmrT9jhMRH83fkWQOsB460ziWx+Q952ScHQdTIs04 n2UxtsrZziUQBS5ULb94KRqsReshl0en9jRXMU3vYVEf5xQYn53seuSeFw6+gQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1678465747; 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; bh=uBAEWUyZKwUmKqqazL7gQLTZOP1jiWdjfH5fZ0edGUU=; b=1m605YEJfNMKkZvmYF5/huSgj0u4P+9jWQI0PxQVSk46rYUwrfXNs1X5gf1+WyTNPcUIgV qcP6tOSAO91Vs5Cg== From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Thomas Gleixner , Richard Weinberger Subject: [PATCH] io-mapping: Don't disable preempt on RT in io_mapping_map_atomic_wc(). Message-ID: <20230310162905.O57Pj7hh@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: 2C82010000E X-Stat-Signature: uocg17yfadfe4t598ib9bphqxb7nuf4g X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678465748-6139 X-HE-Meta: U2FsdGVkX18JpvqyumIJhvGsyPmb9jM9zQVGcX1GOgkhlWS5fY7d9x+kTEIF5Vs01OEFEjwg3MZgo5s7IZ1rw/ZbJWLkdWPYfY1KPmzEH5oYhJwFs6YiRbwuBSQjP8SdXiO9QDiujGBJnjnJbPtc4Xl93fFbCntny5LF7Q6x/0QzeQBEjcDsjvisQJ1jh/8nFlCHKNJKfr82UdiPTT1aAj5cKpG1//7lYCcmMKD42VMePYnHRmm3CZaga16iA3viC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spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: io_mapping_map_atomic_wc() disables preemption and pagefaults for historical reasons. The conversion to io_mapping_map_local_wc(), which only disables migration, cannot be done wholesale because quite some call sites need to be updated to accommodate with the changed semantics. On PREEMPT_RT enabled kernels the io_mapping_map_atomic_wc() semantics are problematic due to the implicit disabling of preemption which makes it impossible to acquire 'sleeping' spinlocks within the mapped atomic sections. PREEMPT_RT replaces the preempt_disable() with a migrate_disable() for more than a decade. It could be argued that this is a justification to do this unconditionally, but PREEMPT_RT covers only a limited number of architectures and it disables some functionality which limits the coverage further. Limit the replacement to PREEMPT_RT for now. This is also done kmap_atomic(). Reported-by: Richard Weinberger Link: https://lore.kernel.org/CAFLxGvw0WMxaMqYqJ5WgvVSbKHq2D2xcXTOgMCpgq9nDC-MWTQ@mail.gmail.com Signed-off-by: Sebastian Andrzej Siewior --- Richard reported it against the i915 driver. I got offlist another report and this reporter confirmed that it fixes the issue while no glitches or other problems were observed (in the kernel log and on screen). include/linux/io-mapping.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/linux/io-mapping.h b/include/linux/io-mapping.h index 09d4f17c8d3b6..7376c1df9c901 100644 --- a/include/linux/io-mapping.h +++ b/include/linux/io-mapping.h @@ -69,7 +69,10 @@ io_mapping_map_atomic_wc(struct io_mapping *mapping, BUG_ON(offset >= mapping->size); phys_addr = mapping->base + offset; - preempt_disable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_disable(); + else + migrate_disable(); pagefault_disable(); return __iomap_local_pfn_prot(PHYS_PFN(phys_addr), mapping->prot); } @@ -79,7 +82,10 @@ io_mapping_unmap_atomic(void __iomem *vaddr) { kunmap_local_indexed((void __force *)vaddr); pagefault_enable(); - preempt_enable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_enable(); + else + migrate_enable(); } static inline void __iomem * @@ -162,7 +168,10 @@ static inline void __iomem * io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset) { - preempt_disable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_disable(); + else + migrate_disable(); pagefault_disable(); return io_mapping_map_wc(mapping, offset, PAGE_SIZE); } @@ -172,7 +181,10 @@ io_mapping_unmap_atomic(void __iomem *vaddr) { io_mapping_unmap(vaddr); pagefault_enable(); - preempt_enable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_enable(); + else + migrate_enable(); } static inline void __iomem *