Message ID | 20230725070549.89810-1-luxu.kernel@bytedance.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2295504vqg; Tue, 25 Jul 2023 00:27:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8JAau1c2kc+48BTBLsiTWy5AEnmvnnBVBWQ3sizM8l6jge/hJpCIIjVSBfdzsAY93CeOh X-Received: by 2002:a05:6402:8d2:b0:522:3855:7ec5 with SMTP id d18-20020a05640208d200b0052238557ec5mr3408325edz.10.1690270052921; Tue, 25 Jul 2023 00:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690270052; cv=none; d=google.com; s=arc-20160816; b=PmxDS/6IrxyII2GDWjFdeI8HewLj2bR1cPGn9okmCZUrM/dNrNnQpDMHc76XHbojmO KpuhYH/EwYWjFgjteyQU48G6gAcGoE9451a4LtvSq8Mdh8OOLxuhh6YVDycIQDqOUy96 pGY/WAwzRcjIWCocvLTbZrxDVdpIuQ3llPHEdi+tn44vhW1VmWLv66BisSS49+MbUYuF uAAL6v9k7OxlhGwKqRFfcMbIWEc3ceFdePVjnO9YnFmqWtQB+W9efo4EtsaGqZE8pFOu bF+uXzFZywnaRXiReggPxIpTddCmP1aIkEGDu7cYxai3GG6m+ASUutKf8SuZ080w5vZO UAIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3YiFtbazXCGKkSvCu29PAaqFDD+rQJcJJfLFd8Lc7dE=; fh=FC+csOhHkz5VfVF/Fy8v72dwFDGgYGlzPgegwLFYb3I=; b=Qp8bGvY60EmDwNhhR5855Ilu5/9oji1UwaYiWMM98bDix+/mvSJ5bm2DDkxydEs3J9 8leabgPO/azVSDbSUGk9Wmr1SgNuzhSu+kvXehBm4QFODbiFQeF6/XUBUBQf5PKR9Ja8 ZQBDTDX9V/C4IDzn9OFREPbD2vNHjYhDhi56HZKqjIFS1D2NKJk8bSGo1xTvIkXCBaaz nwsqeasKN6K1Zf/I/8FX9scncx3b+uRqex6RS/YFWVhQSUB2GcqMhvEK8RC4Gy67SYfT kvS345hcwFyRCRADLy7q9MsdO0rXFODyH+c/jd1OHwZn24E5F/5jlKWi5gNef3gMUH6k lQTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Lo8PhI9m; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v19-20020a056402185300b0052229e936c9si3327839edy.648.2023.07.25.00.27.09; Tue, 25 Jul 2023 00:27:32 -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=@bytedance.com header.s=google header.b=Lo8PhI9m; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbjGYHGd (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Tue, 25 Jul 2023 03:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjGYHGY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Jul 2023 03:06:24 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5679512C for <linux-kernel@vger.kernel.org>; Tue, 25 Jul 2023 00:05:57 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-66869feb7d1so3056103b3a.3 for <linux-kernel@vger.kernel.org>; Tue, 25 Jul 2023 00:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690268757; x=1690873557; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3YiFtbazXCGKkSvCu29PAaqFDD+rQJcJJfLFd8Lc7dE=; b=Lo8PhI9mKE9la2FEdDvKX1tKoJGeVXRVcEQOW8jg2w5CkcWv8ZCbVQoo+JCfVSl54g Q5oJhDZ3TzZ7C7f224IcRM8uioFnSKcrB1Pdr3oK9+sDnWK6kd/KXRBMXqCeeYoeTpUJ MuP9Gl3ESPfQLD1iIuQDEpJkLT6PhSJHM+mSwSGBK9n/umasczanNmv3dkxRML+cA/6o hz/XazC11REsa+u1YQHtT5OxoXhozjrPCdMJjG/tH+b3nSxQs9R569DldPwxdVpzhK9F jUFVWptCwB8EEhQSjyNw0S1XavIOqT4w97EAteNO4iJZ6461qx8mn6jPQtdMdgKKY8jf aKpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690268757; x=1690873557; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3YiFtbazXCGKkSvCu29PAaqFDD+rQJcJJfLFd8Lc7dE=; b=j0eK2ZH3iPVvyF9Ea8lz8uvxazzkrtH42aNvjZ0RXCCtprpUB3xUIBpDKrURCTluLJ ahfrTae+/GzGpKOEpZeWs9t8d86ZSDcKoN40+CBz1Wp8zu4ZFdi9QC56GvTHTpT+50JM UjAlHVS0iD/s4eQx8CWOdnlJ26DV+CLeA8O+ujbnrjgTJHKWYnVky/H3k6BAtwaTfxoP QrnSJ063eRakg0vW7kG6uWY737H9cZSY9OijDRyDijyN4+8P7VdaQV6PL4lkO3dyWA/2 /85FZMT254+v4vezcGsVoxft7tMsGwcjflusKuA+gq6RuuMhfoaIEdyGrbLF4/4gGUQE ajAQ== X-Gm-Message-State: ABy/qLbDzLo1OiUxf6ClpfoDF7KzyRlccegnxvqJbq6hZQTZ3G8V77iT nOM4L428IjZuKbRoB7mcgsKglg== X-Received: by 2002:a05:6a20:9717:b0:12d:4c17:bb2d with SMTP id hr23-20020a056a20971700b0012d4c17bb2dmr9066791pzc.26.1690268756829; Tue, 25 Jul 2023 00:05:56 -0700 (PDT) Received: from J9GPGXL7NT.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id p6-20020aa78606000000b00640dbbd7830sm9165478pfn.18.2023.07.25.00.05.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jul 2023 00:05:56 -0700 (PDT) From: Xu Lu <luxu.kernel@bytedance.com> To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Xu Lu <luxu.kernel@bytedance.com> Subject: [PATCH] riscv: Fix local irq restore when flags indicates irq disabled Date: Tue, 25 Jul 2023 15:05:49 +0800 Message-Id: <20230725070549.89810-1-luxu.kernel@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: INBOX X-GMAIL-THRID: 1772376611238247611 X-GMAIL-MSGID: 1772376611238247611 |
Series |
riscv: Fix local irq restore when flags indicates irq disabled
|
|
Commit Message
Xu Lu
July 25, 2023, 7:05 a.m. UTC
When arch_local_irq_restore() is called with flags indicating irqs
disabled, we need to clear SR_IE bit in CSR_STATUS, whereas current
implementation based on csr_set() function only sets SR_IE bit of
CSR_STATUS when SR_IE bit of flags is high and does nothing when
SR_IE bit of flags is low.
This commit supplies csr clear operation when calling irq restore
function with flags indicating irq disabled.
Fixes: 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI")
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
arch/riscv/include/asm/irqflags.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Tue, 25 Jul 2023 00:05:49 PDT (-0700), luxu.kernel@bytedance.com wrote: > When arch_local_irq_restore() is called with flags indicating irqs > disabled, we need to clear SR_IE bit in CSR_STATUS, whereas current > implementation based on csr_set() function only sets SR_IE bit of > CSR_STATUS when SR_IE bit of flags is high and does nothing when > SR_IE bit of flags is low. > > This commit supplies csr clear operation when calling irq restore > function with flags indicating irq disabled. > > Fixes: 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI") > Signed-off-by: Xu Lu <luxu.kernel@bytedance.com> > --- > arch/riscv/include/asm/irqflags.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h > index 08d4d6a5b7e9..7c31fc3c3559 100644 > --- a/arch/riscv/include/asm/irqflags.h > +++ b/arch/riscv/include/asm/irqflags.h > @@ -49,7 +49,10 @@ static inline int arch_irqs_disabled(void) > /* set interrupt enabled status */ > static inline void arch_local_irq_restore(unsigned long flags) > { > - csr_set(CSR_STATUS, flags & SR_IE); > + if (flags & SR_IE) > + csr_set(CSR_STATUS, SR_IE); > + else > + csr_clear(CSR_STATUS, SR_IE); Unless I'm missing something, the original version is correct: local_irq_restore() must be paired with a local_irq_save(), so we can only get here with interrupts disabled. > } > > #endif /* _ASM_RISCV_IRQFLAGS_H */
On Wed, Aug 9, 2023 at 2:05 PM Palmer Dabbelt <palmer@dabbelt.com> wrote: > > On Tue, 25 Jul 2023 00:05:49 PDT (-0700), luxu.kernel@bytedance.com wrote: > > When arch_local_irq_restore() is called with flags indicating irqs > > disabled, we need to clear SR_IE bit in CSR_STATUS, whereas current > > implementation based on csr_set() function only sets SR_IE bit of > > CSR_STATUS when SR_IE bit of flags is high and does nothing when > > SR_IE bit of flags is low. > > > > This commit supplies csr clear operation when calling irq restore > > function with flags indicating irq disabled. > > > > Fixes: 6d60b6ee0c97 ("RISC-V: Device, timer, IRQs, and the SBI") > > Signed-off-by: Xu Lu <luxu.kernel@bytedance.com> > > --- > > arch/riscv/include/asm/irqflags.h | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h > > index 08d4d6a5b7e9..7c31fc3c3559 100644 > > --- a/arch/riscv/include/asm/irqflags.h > > +++ b/arch/riscv/include/asm/irqflags.h > > @@ -49,7 +49,10 @@ static inline int arch_irqs_disabled(void) > > /* set interrupt enabled status */ > > static inline void arch_local_irq_restore(unsigned long flags) > > { > > - csr_set(CSR_STATUS, flags & SR_IE); > > + if (flags & SR_IE) > > + csr_set(CSR_STATUS, SR_IE); > > + else > > + csr_clear(CSR_STATUS, SR_IE); > > Unless I'm missing something, the original version is correct: > local_irq_restore() must be paired with a local_irq_save(), so we can > only get here with interrupts disabled. Yes, it is correct if local_irq_save() is called when irq is enabled before. The flags returned will be SR_IE. And it is safe to call local_irq_restore() with flag SR_IE in any case. However, if local_irq_save() is called when irq is disabled. The SR_IE bit of flag returned is clear. If some code between local_irq_save() and local_irq_restore() reenables irq, causing the SR_IE bit of CSR_STATUS back to 1, then local_irq_restore() can not restore irq status back to disabled. Here is an example in existing driver (may not belong to riscv arch) in drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c. The pseudo code behaves like: int rtl8723e_hw_init(struct ieee80211_hw *hw) { int err; unsigned long flags; ... local_irq_save_flags(flags); local_irq_enable(); ... local_irq_restore(flags); ... return err; } > > > } > > > > #endif /* _ASM_RISCV_IRQFLAGS_H */
diff --git a/arch/riscv/include/asm/irqflags.h b/arch/riscv/include/asm/irqflags.h index 08d4d6a5b7e9..7c31fc3c3559 100644 --- a/arch/riscv/include/asm/irqflags.h +++ b/arch/riscv/include/asm/irqflags.h @@ -49,7 +49,10 @@ static inline int arch_irqs_disabled(void) /* set interrupt enabled status */ static inline void arch_local_irq_restore(unsigned long flags) { - csr_set(CSR_STATUS, flags & SR_IE); + if (flags & SR_IE) + csr_set(CSR_STATUS, SR_IE); + else + csr_clear(CSR_STATUS, SR_IE); } #endif /* _ASM_RISCV_IRQFLAGS_H */