From patchwork Sun May 29 17:49:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sander Vanheule X-Patchwork-Id: 1636710 X-Patchwork-Delegate: sander@svanheule.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=SollzShq; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=svanheule.net header.i=@svanheule.net header.a=rsa-sha256 header.s=mail1707 header.b=AKkuE0ch; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LB5nY6TCTz9sBF for ; Mon, 30 May 2022 03:56:14 +1000 (AEST) 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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tDo8DvQ88SthzPEdy476EuzEOPyQuDEFRL452yGozLM=; b=SollzShqc7eEp9 gPGzD8uK8m6vMrEU/W+gB+KNinvkM+AvwIBJsIWrPbpxuOoN3apFRx3Nnj6pftbr4uNZ4gE5tfiH5 jgCodGuH5/Q2uXbPsQip0XwkDzBHjDZ8am4YqGQgMy9630o35dNQgPB6ojfq0lKM6tyblnLi12PRN SIospn1vo8uLuXHFFXvXhcjpPH83YaUQOAowwFlRudhOzK+NgFiYp7fxL2YguSKHc2c2lJAh73Kcy By0PaMQsSonSQv9xqVJ/060Xcwyp5iikaNV10kbIsps8YqcFfVSiAf+NmYeQWgV0Io/ZiuguVYBOe FQsahSO9Z7miy4gtvKCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvN2z-004OCn-Tu; Sun, 29 May 2022 17:49:50 +0000 Received: from polaris.svanheule.net ([84.16.241.116]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvN2w-004OAl-BN for openwrt-devel@lists.openwrt.org; Sun, 29 May 2022 17:49:48 +0000 Received: from terra.. (unknown [IPv6:2a02:a03f:eaf9:8401:aa9f:5d01:1b2a:e3cd]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id DD5BA2DF571; Sun, 29 May 2022 19:49:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1653846579; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=eX7Fbzk8RAVAEkMMhmvyg9Cx0teIHyMpkytgCeKBtak=; b=AKkuE0chujeszV3UhKqR2mmqS4Hbyg7kGLgY1b0XO4RtBWwYW+77uWA1+kqQIJzmEwX7zL cf6AkXCi3Q/+x22RfU8vqf1gv18t8lKOevorDNHg2JV82IrYrH1xyZleReYJUEb2SItfWN Yn2qdMd98swYr3du0obt4heHxGwJKGTXZU5eS8HZDXthPC02ZYtYdsV4xvEPh7emP4yeJ+ lPFXb3eSbY6NY33Lrv/maUyVZX7jpKm2D23ac31exaCzgdzzu9Q0eb4u8JehZS8ARKmZPY 7IELPF7MJyVX7yuV4S4Uf3/FDWcfeiZOQt1SfXuICf0VhHoGflq5aTuedEBu/g== From: Sander Vanheule To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Robert Marko , INAGAKI Hiroshi Subject: [PATCH] realtek: don't unmask non-maskable GPIO IRQs Date: Sun, 29 May 2022 19:49:33 +0200 Message-Id: <20220529174933.293405-1-sander@svanheule.net> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220529_104946_883442_5F3C7B5F X-CRM114-Status: GOOD ( 10.75 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: On uniprocessor builds, for_each_cpu(cpu, mask) will assume 'mask' always contains exactly one CPU, and ignore the actual mask contents. This causes the loop to run, even when it shouldn't on an empty [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [84.16.241.116 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org On uniprocessor builds, for_each_cpu(cpu, mask) will assume 'mask' always contains exactly one CPU, and ignore the actual mask contents. This causes the loop to run, even when it shouldn't on an empty mask, and tries to access an unintialised pointer. Fix this by wrapping the loop in a cpumask_empty() check, to ensure it will not run on uniprocessor builds if the CPU mask is empty. Fixes: af6cd37f42f3 ("realtek: replace RTL93xx GPIO patches") Reported-by: Robert Marko Reported-by: INAGAKI Hiroshi Signed-off-by: Sander Vanheule Tested-by: Robert Marko --- .../316-otto-gpio-uniprocessor-irq-mask.patch | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 target/linux/realtek/patches-5.10/316-otto-gpio-uniprocessor-irq-mask.patch diff --git a/target/linux/realtek/patches-5.10/316-otto-gpio-uniprocessor-irq-mask.patch b/target/linux/realtek/patches-5.10/316-otto-gpio-uniprocessor-irq-mask.patch new file mode 100644 index 000000000000..f83f5a781f74 --- /dev/null +++ b/target/linux/realtek/patches-5.10/316-otto-gpio-uniprocessor-irq-mask.patch @@ -0,0 +1,29 @@ +--- a/drivers/gpio/gpio-realtek-otto.c ++++ b/drivers/gpio/gpio-realtek-otto.c +@@ -304,6 +304,7 @@ static int realtek_gpio_irq_set_affinity + static int realtek_gpio_irq_init(struct gpio_chip *gc) + { + struct realtek_gpio_ctrl *ctrl = gpiochip_get_data(gc); ++ void __iomem *irq_cpu_mask; + unsigned int port; + int cpu; + +@@ -311,8 +312,16 @@ static int realtek_gpio_irq_init(struct + realtek_gpio_write_imr(ctrl, port, 0, 0); + realtek_gpio_clear_isr(ctrl, port, GENMASK(7, 0)); + +- for_each_cpu(cpu, &ctrl->cpu_irq_maskable) +- iowrite8(GENMASK(7, 0), realtek_gpio_irq_cpu_mask(ctrl, port, cpu)); ++ /* ++ * Uniprocessor builds assume a mask always contains one CPU, ++ * so only start the loop if we have at least one maskable CPU. ++ */ ++ if(!cpumask_empty(&ctrl->cpu_irq_maskable)) { ++ for_each_cpu(cpu, &ctrl->cpu_irq_maskable) { ++ irq_cpu_mask = realtek_gpio_irq_cpu_mask(ctrl, port, cpu); ++ iowrite8(GENMASK(7, 0), irq_cpu_mask); ++ } ++ } + } + + return 0;