From nobody Mon May 09 12:32:20 2022 X-Original-To: dev-commits-src-all@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 970841AD9264; Mon, 9 May 2022 12:32:20 +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 4KxgY03kBZz3j5y; Mon, 9 May 2022 12:32:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652099540; 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=pPnFKRyy9oc8hWovAtPUttCUDN5ejGfMVt+dxF11thc=; b=ufGg87usEdcE48euVU4my+SIZ/GnmCQBgBK9SIH+Gj8FEbMBPn9rt5v10crxCSgaQfH45p +MoNw4QVFRukR0XDD4GYJgzwcilJSLZ0iKshhkktgWZn0GRmH39ZD+y5yiZdge9MFnv7WS tn521iymSoWmzWSARnXRpVrsxI4JlsQBURPLlBv0EzKlW05jhn6z1+6u3+AX8gMvXcsYgB zZu5ycnvq3gg2Lz7I0IBRvfq6yueb9jkyMFr8Nz5kHKp2DuOljveUfCkJx4Vj1WdiRfh9E D1wQKJp8VrGc7HEtGqpJGVYUkeEQtmUcE4HR20aRrmP5UJ99Q4gjO10K5yLXLQ== 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 5719411585; Mon, 9 May 2022 12:32:20 +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 249CWKmT031629; Mon, 9 May 2022 12:32:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 249CWKhv031628; Mon, 9 May 2022 12:32:20 GMT (envelope-from git) Date: Mon, 9 May 2022 12:32:20 GMT Message-Id: <202205091232.249CWKhv031628@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 097991f8ffd6 - stable/13 - linuxkpi: Mitigate a seqlock livelock List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 097991f8ffd639b38fce65d4acf7b4986bca8dcf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652099540; 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=pPnFKRyy9oc8hWovAtPUttCUDN5ejGfMVt+dxF11thc=; b=PQRAutIX0O7nul1fJUv90+Ds6Ty+O3LeTePKSaSsz73BuCa7EqBsqZnrtwQrf8awCB8qx0 AhOIpa/2W3guk7RWrOh1jjT8mT68PGLsUd6yW9O/0o252ey9BhmU3S0IQ12Wvnf89lW1LJ CvQCjmTcdqPla/ox5C1fzJTLjte0UlNmFeEYJvYPb5gPU1nxyjmPKVxuqmALFzw7tZam5g 0/L3WGDTUzwScwcEyHOxgXvyGxwn9c6UGEMsBX+zAxubwOU150Mm9ROKYuO92NkO6JhKrC NkCdX40hELTUGucBf4U+G3jjeUYPtvSA6J37yTp3Iz/F/yUxAfHi8HPWCHlgRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652099540; a=rsa-sha256; cv=none; b=HgiapEfDuNZ5PE3UezMbWE8JranzsyaYYa8LFrxYZekCu+PUrvyC8ujlx233RqQMW2/dxK NcIB+Lw459nPmfXU37yHay/GpSXzq4ZuhF3reTeFVnEmJBFBUfzjgXT51gSzoJjAbFjE4/ 98UmY0fr3LkNb9jK0fKyTZoXYm2hkl35vyb0VEfVg97f6zr+kPFo7IINn6aW60CQfmSZrU g4qJ32BDF0tYr8Vr171XfEXpujPciQeRptkgpZNOxnMzIGWMqL92MeeDp8Ku/qvkb1iKZi IPAZbxPAb2IFmASnkp63tp46cpQBI27BADKBiXyLr4CWHY0g7UDQRjojxI2wjw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=097991f8ffd639b38fce65d4acf7b4986bca8dcf commit 097991f8ffd639b38fce65d4acf7b4986bca8dcf Author: Mark Johnston AuthorDate: 2022-04-25 13:13:03 +0000 Commit: Mark Johnston CommitDate: 2022-05-09 12:32:09 +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 Sponsored by: The FreeBSD Foundation (cherry picked from commit efb8f0b8db8747243f7999b874403d5c86e93b74) --- 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 03d36d89de89..2f4892525e8a 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