From patchwork Sun Mar 13 21:14:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1604857 X-Patchwork-Delegate: daniel@makrotopia.org 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=anRjJ21w; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=k6ClUfLb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::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:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KGsvS2YSJz9sGJ for ; Mon, 14 Mar 2022 08:17:40 +1100 (AEDT) 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:References:In-Reply-To: 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: List-Owner; bh=CiDB/OjmxyBes7kdtYivXwITsl6ZRV3x3I+DuNseK3s=; b=anRjJ21wRg0h0x hfRlJiSkbltJ9tbiesfR0/KkpHmgXfH2sZ9nyFyBBHgNrUJEXvVn75LYMsZNxbG9wQyip8aRf/kyB gQBhUkX/+nxDCJDKLGt3U2ll/DHvp9TQJ869u6U96Sqtwh+if3cOGU+jRjyE5QQvqW5YCSXSaoSKX ZpIfS7gZBfNYg7SFjuaeMB8adju21sibjb219C+x2YI3hUi0cSVPYeSv3NtF372H9pgfeke0vxnZ3 n61ot9o26GYCQO5KGbyetu+8WV2qSKOcsNW5AQUG5xnlLxDnmEgSzqJRznkFN10O3Hz6vpw9mtLdg PXOCg30O5EBTTnuAIGuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTVYc-003NWM-Dw; Sun, 13 Mar 2022 21:15:18 +0000 Received: from srv4.3e8.eu ([2001:67c:12a0:200::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTVYL-003NTm-5y for openwrt-devel@lists.openwrt.org; Sun, 13 Mar 2022 21:15:03 +0000 Received: from localhost.localdomain (p200300c6cf1a2ca042ec7477250c65aa.dip0.t-ipconnect.de [IPv6:2003:c6:cf1a:2ca0:42ec:7477:250c:65aa]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 4F852601EA; Sun, 13 Mar 2022 22:14:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1647206089; 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: in-reply-to:in-reply-to:references:references; bh=efQgbY4uYYeOnkIGS3XIEgk7LgkJPjdr5jeNoP8yha0=; b=k6ClUfLbJoQHlJVEp0+HSiD9ZTQVC4SDeBoanDhoMmx3QOY2NU83s/lPC4znu9gLEFoy2W nZ2YycU+cjIiHA7Igaxp4apDCvyp5P+ia+epjm9Xr10PXDeLbzLRJCuhpdLd6CltVQmwHn ZjDtqQ15B5uxClgehGFuiCLnGpU2g/SCNHvcz9Ujgav7eZ2LQTcl4NZM1BI+8pA/uv19Yj moo/X+fQ++8U2yok33NWsTnkH2PbV21jJc/+IbFK+k5UShz3p0H0Sx+fHa0YA1/6Z0uHdz a9izmDcYKI+O1ZCe463gGMnelbAkppTSK1qIt4nNcpzWLDNJCLRsUtaCaSun1A== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Jan Hoffmann Subject: [PATCH 4/4] ltq-vdsl-mei: add locking to interrupt handler Date: Sun, 13 Mar 2022 22:14:38 +0100 Message-Id: <20220313211438.1302111-5-jan@3e8.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220313211438.1302111-1-jan@3e8.eu> References: <20220313211438.1302111-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220313_141501_536690_A2026BDA X-CRM114-Status: GOOD ( 20.01 ) X-Spam-Score: -0.2 (/) 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: Some users noticed repeated resyncs at random intervals, which go away when the MEI driver is configured to use polling instead of interrupts. Debugging shows that this seems to be caused by concurren [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an 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 Some users noticed repeated resyncs at random intervals, which go away when the MEI driver is configured to use polling instead of interrupts. Debugging shows that this seems to be caused by concurrent calls to MEI_ReadMailbox (in the interrupt handler) and MEI_WriteMailbox. This appears to be mostly triggered when there is an interrupt for vectoring error reports. In polling mode, calls to MEI_ReadMailbox are protected by the same semaphore as is used in MEI_WriteMailbox. When interrupts are used, MEI_WriteMailbox appears to rely on MEI_DisableDeviceInt and MEI_EnableDeviceInt to provide mutual exclusion with the interrupt handler. These functions mask/unmask interrupts, and there is an additional check of the mask in the interrupt handler itself. However, this is not sufficient on systems with SMP, as the interrupt handler may be running in parallel, and could already be past the interrupt mask check at this point. This adds a lock to the interrupt handler, and also acquires this lock in MEI_DisableDeviceInt. This should make sure that after a call to MEI_DisableDeviceInt the interrupt is masked, and the interrupt handler is either not running, has alread finished its work, or is still before the interrupt mask check, and is thus going to detect the change. Signed-off-by: Jan Hoffmann --- package/kernel/lantiq/ltq-vdsl-mei/Makefile | 2 +- .../patches/200-interrupt-lock.patch | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 package/kernel/lantiq/ltq-vdsl-mei/patches/200-interrupt-lock.patch diff --git a/package/kernel/lantiq/ltq-vdsl-mei/Makefile b/package/kernel/lantiq/ltq-vdsl-mei/Makefile index d4a5ea720b67..b7060eb2b48b 100644 --- a/package/kernel/lantiq/ltq-vdsl-mei/Makefile +++ b/package/kernel/lantiq/ltq-vdsl-mei/Makefile @@ -9,7 +9,7 @@ include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=ltq-vdsl-vr9-mei PKG_VERSION:=1.5.17.6 -PKG_RELEASE:=5 +PKG_RELEASE:=6 PKG_BASE_NAME:=drv_mei_cpe PKG_SOURCE:=$(PKG_BASE_NAME)-$(PKG_VERSION).tar.gz diff --git a/package/kernel/lantiq/ltq-vdsl-mei/patches/200-interrupt-lock.patch b/package/kernel/lantiq/ltq-vdsl-mei/patches/200-interrupt-lock.patch new file mode 100644 index 000000000000..a677ccec554e --- /dev/null +++ b/package/kernel/lantiq/ltq-vdsl-mei/patches/200-interrupt-lock.patch @@ -0,0 +1,45 @@ +--- a/src/drv_mei_cpe_common.c ++++ b/src/drv_mei_cpe_common.c +@@ -104,6 +104,8 @@ IFX_uint32_t MEI_FsmStateSetMsgPreAction + MEI_DEVCFG_DATA_T MEI_DevCfgData; + #endif + ++static DEFINE_SPINLOCK(MEI_InterruptLock); ++ + /* ============================================================================ + Proc-FS and debug variable definitions + ========================================================================= */ +@@ -2134,6 +2136,9 @@ IFX_int32_t MEI_ProcessIntPerIrq(MEIX_CN + #if (MEI_SUPPORT_DEBUG_STREAMS == 1) + IFX_int_t extraDbgStreamLoop = 0; + #endif ++ unsigned long flags; ++ ++ spin_lock_irqsave(&MEI_InterruptLock, flags); + + /* get the actual chip device from the list and step through the VRX devices */ + while(pNextXCntrl) +@@ -2167,6 +2172,8 @@ IFX_int32_t MEI_ProcessIntPerIrq(MEIX_CN + } + #endif + ++ spin_unlock_irqrestore(&MEI_InterruptLock, flags); ++ + return meiIntCnt; + } + +@@ -2639,9 +2646,14 @@ IFX_int32_t MEI_MsgSendPreAction( + */ + IFX_void_t MEI_DisableDeviceInt(MEI_DEV_T *pMeiDev) + { ++ unsigned long flags; ++ spin_lock_irqsave(&MEI_InterruptLock, flags); ++ + MEI_MaskInterrupts( &pMeiDev->meiDrvCntrl, + ME_ARC2ME_INTERRUPT_MASK_ALL); + ++ spin_unlock_irqrestore(&MEI_InterruptLock, flags); ++ + return; + } +