From nobody Mon Apr 25 13:26:38 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id ADE8C1A98E5D; Mon, 25 Apr 2022 13:26:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kn5Q63nHSz4nx3; Mon, 25 Apr 2022 13:26:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650893198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BrHA1nC39SQ1oDfzBtTsbuXbK0vXDSFZ/3gkd65Xrqg=; b=m0pWmndOMfs6Ik9gyP56tkWIhi8qcvPLUQnY7KP+1daSPDk/n3V1hUt/8+CipE+WFmlMU7 gRGVzJyxI8udSHrYKylvMMY/+yLsIwIOUY9KLROq0xZT0yshlHf3XzBS5LYb05bAqGOFzm Z2tgIlqrUiF3kN603f0IjlwSV9fnu1k7+E/q6zgBct6uD6Vu5LbAiErkIu6kxDtESOgRzr Swy6fVg4Ug+evzPd/JpxFDHtLr/QC62oIhWvCSGA6iydcr6qPh4a9TJ4V4FDfKsEi/uhh1 I6P7vHAdBpwM9faJ5VsWj0wAqCsekN1FL375ICmbfE4+xx9Istc9kWIdI6o4Tw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5355B1B6DD; Mon, 25 Apr 2022 13:26:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23PDQcGE051297; Mon, 25 Apr 2022 13:26:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23PDQcoZ051296; Mon, 25 Apr 2022 13:26:38 GMT (envelope-from git) Date: Mon, 25 Apr 2022 13:26:38 GMT Message-Id: <202204251326.23PDQcoZ051296@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: efb8f0b8db87 - main - linuxkpi: Mitigate a seqlock livelock List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: efb8f0b8db8747243f7999b874403d5c86e93b74 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650893198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BrHA1nC39SQ1oDfzBtTsbuXbK0vXDSFZ/3gkd65Xrqg=; b=UZHl0+Am+abxy51bd9nBd5TI6RPrnaQ/TRWwhXZPQi5QctlBX6HsD4SNZOPfLUcdtwIBu5 y3Mm5Q3TqKx0+qk6qU+C1woSbCK0LHTTvlS5euKjLZhz9J5HoiHZoQyZXgTfjKqPezMyO4 PDKhfn4IZOj2cZ7Gtpbry7q4VJb3+JZg4OLdF7JfThyYB69A39ZIb6pF8yuKFLtXPl7gcW Cqtyy6JDZiluDtjWLhD8Y75b69opadMegANgVW67lb290VKmEHjjllUTglR9OjpWdpYtCD Yksp0/QLVZnpTEs6Be2V4b83wb6ETwrCNkhYxStDx7Lo78JiDeAiKnnf86ejWA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650893198; a=rsa-sha256; cv=none; b=lHOfsJPcNP/M5BDLedUPf0q3ZbY7m2aseOM7uhT1Cf8s6y3sj4WUDxssoHJABPBdamFE8R KoNTzVRqtwHAY755C0kKPny8NA/zqwNnBHNeqf4fmIboYi8FCXtx9bD2QBCMVU8XwuS4QY jbLHiqi+PIA2l/UdZxpJIcaAOt7KDNtnX1/+q2tXRMeCedykxoNmVGAiuOs5LQxADrZkoO dMej8vPIhEWUx/BJAHwwdXcgs2/cCZBbxBP1PCChdIkZv6K5sK+s/ULnOmcP4YQBBTNg2U H3R/A6fbGxJuuWlMK1IaxYa1HEEDixYnaKhKKshvPy05LWnuNbItPz1FMywwIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=efb8f0b8db8747243f7999b874403d5c86e93b74 commit efb8f0b8db8747243f7999b874403d5c86e93b74 Author: Mark Johnston AuthorDate: 2022-04-25 13:13:03 +0000 Commit: Mark Johnston CommitDate: 2022-04-25 13:13:03 +0000 linuxkpi: Mitigate a seqlock livelock Disable preemption in seqlock write sections when using the _irqsave variant. This ensures that a writer can't be preempted and subsequently starved by a reader running in a callout handler on the same CPU. This fixes occasional display hangs seen when using the i915 driver. Tested by: emaste, wulf Reviewed by: wulf, hselasky MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35021 --- sys/compat/linuxkpi/common/include/linux/seqlock.h | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/seqlock.h b/sys/compat/linuxkpi/common/include/linux/seqlock.h index 6f0618d7ac9d..6e81e7a0fa45 100644 --- a/sys/compat/linuxkpi/common/include/linux/seqlock.h +++ b/sys/compat/linuxkpi/common/include/linux/seqlock.h @@ -30,6 +30,7 @@ #define _LINUXKPI_LINUX_SEQLOCK_H__ #include +#include #include #include #include @@ -100,29 +101,52 @@ seqlock_init(struct seqlock *seqlock) } static inline void -write_seqlock(struct seqlock *seqlock) +lkpi_write_seqlock(struct seqlock *seqlock, const bool irqsave) { mtx_lock(&seqlock->seql_lock); + if (irqsave) + critical_enter(); write_seqcount_begin(&seqlock->seql_count); } static inline void -write_sequnlock(struct seqlock *seqlock) +write_seqlock(struct seqlock *seqlock) +{ + lkpi_write_seqlock(seqlock, false); +} + +static inline void +lkpi_write_sequnlock(struct seqlock *seqlock, const bool irqsave) { write_seqcount_end(&seqlock->seql_count); + if (irqsave) + critical_exit(); mtx_unlock(&seqlock->seql_lock); } +static inline void +write_sequnlock(struct seqlock *seqlock) +{ + lkpi_write_sequnlock(seqlock, false); +} + +/* + * Disable preemption when the consumer wants to disable interrupts. This + * ensures that the caller won't be starved if it is preempted by a + * higher-priority reader, but assumes that the caller won't perform any + * blocking operations while holding the write lock; probably a safe + * assumption. + */ #define write_seqlock_irqsave(seqlock, flags) do { \ (flags) = 0; \ - write_seqlock(seqlock); \ + lkpi_write_seqlock(seqlock, true); \ } while (0) static inline void write_sequnlock_irqrestore(struct seqlock *seqlock, unsigned long flags __unused) { - write_sequnlock(seqlock); + lkpi_write_sequnlock(seqlock, true); } static inline unsigned