From nobody Tue Oct 10 14:34:21 2023 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 4S4dhF4VVhz4wr4B; Tue, 10 Oct 2023 14:34:21 +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 4S4dhF38Nxz4RHm; Tue, 10 Oct 2023 14:34:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696948461; 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=20Oz3+IIJh960BozgdRPXSz02kQMu58IeMNNTRjWGtQ=; b=ZbbpiGr5XmiiaNOfm3Jv/BKjeS3ZXLyVYr4IglsbZwlgxumOc4kuaX5LaWmKRGQ4GrB35m c+iNdPvFIb/FSwyF/QVJVCHj1y3SGoFAXoV4YPjoTE8Osi6pb00CoqfaFQCJ5rnjfF4HEL yovoYd5epE1L/WngkeA7Q1JBCKj4iBHBBxWzua8wIrCLsnoLkanweJwkixkfZhi4MVETka 44fykWAjt2q6GM9ckSQA3lZKljDaCzgMVPLpOeyDfC7BNmRQHKuOZj08mIRNEL89Cuxm/C PhdXtB56vu1332KBQhLcO5uLYFJwgT8J0+ACJm4CvR7skYuK6zpepkVOpPtOww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696948461; a=rsa-sha256; cv=none; b=yDmRCmXc5gMCTYtvKByHA2HwmZDrUJo4f0cyDluX/rAVdmT8vYf77ADVVR0siI9GnpAhYX 5XK2GySUc9erP0AhaLI8YCwywPwfuZRWTOdN5VuQR5BcJBftH2TNtL1cCeY6yxZwEiq5Ay xvRxo5Cbjm772VQZhSYDByzQiO9FthPmjmRInqX+6KldTGntiFca7prYwu24AGWhhD/Ks9 9/7W3IAXFho2zZCwM9RkYge0b/zuAdoTLg2ctx/3eSVLTpw+idE2hY1Ypf+1HHYWNIV7H9 ash+OXpqWMfGa1rB1Ky1JNoLZtivf+Z6kJB24swh5gTIxdoOpW5m7INfP1CZjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696948461; 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=20Oz3+IIJh960BozgdRPXSz02kQMu58IeMNNTRjWGtQ=; b=oUe2rZS1202E0tPg79zX+5kdkXZJOT4D7B8Op6OVhzZ1aeNnYH20dn6cGDinNtw4qFcek+ x3EHPseKUkhzEr40jXpv6OpLxlEhLgsvsyLvjrhT+16DLK7IkVPc7tbTnXMXvsQeJxQJWQ rcLzCO8uvSq56DJjqGZgYp3DW7MPOxHjXQTq/f++jd6f47mTclPMgGaubev9yVuTZiiPbI OR3afmGA+E6e4yTnQlULrhBpEAxJ/utSaD5wCvhPXwlmDtgHnMzanJk8PtqyR0jIC9Y43j bqnZSTRTnMhdUfKCFpzKC0UEddqo/0tk7ZzDnWcN7PNoI+VuRXu0nM4ky/sXlQ== 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 4S4dhF2GJgzhXR; Tue, 10 Oct 2023 14:34:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39AEYLhI005114; Tue, 10 Oct 2023 14:34:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39AEYLdn005110; Tue, 10 Oct 2023 14:34:21 GMT (envelope-from git) Date: Tue, 10 Oct 2023 14:34:21 GMT Message-Id: <202310101434.39AEYLdn005110@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 7e4ebe43721f - releng/14.0 - linuxkpi: fix iteration in __sg_alloc_table_from_pages 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 7e4ebe43721f24b78d9bd736988798bb46c54f71 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=7e4ebe43721f24b78d9bd736988798bb46c54f71 commit 7e4ebe43721f24b78d9bd736988798bb46c54f71 Author: Austin Shafer AuthorDate: 2023-09-06 14:08:05 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-10-10 14:33:54 +0000 linuxkpi: fix iteration in __sg_alloc_table_from_pages Commit 3f686532c9b4 tried to fix an issue with not properly starting at the first page in the sg list to prevent a panic. This worked but with the side effect of incrementing "s" during the final iteration causing it to be NULL since the list had ended. In cases non-DEBUG kernels this causes a panic with drm-5.15, since "s" is NULL when we later pass it to sg_mark_end(). This change decouples the iteration sg from the return value so that it is never incremented past the final page in the chain. Approved by: re (gjb) Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D41574 (cherry picked from commit 09b0401e91a92bcb58ea1873857b42f8211f660f) (cherry picked from commit 2709483a725e1da2d443d9e391bfaa0f223099be) --- sys/compat/linuxkpi/common/include/linux/scatterlist.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/scatterlist.h b/sys/compat/linuxkpi/common/include/linux/scatterlist.h index 0e4cc90e57a5..e462d5c649f1 100644 --- a/sys/compat/linuxkpi/common/include/linux/scatterlist.h +++ b/sys/compat/linuxkpi/common/include/linux/scatterlist.h @@ -343,7 +343,7 @@ __sg_alloc_table_from_pages(struct sg_table *sgt, { unsigned int i, segs, cur, len; int rc; - struct scatterlist *s; + struct scatterlist *s, *sg_iter; #if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300 if (prv != NULL) { @@ -377,10 +377,18 @@ __sg_alloc_table_from_pages(struct sg_table *sgt, #endif cur = 0; - for (i = 0, s = sgt->sgl; i < sgt->orig_nents; i++) { + for_each_sg(sgt->sgl, sg_iter, sgt->orig_nents, i) { unsigned long seg_size; unsigned int j; + /* + * We need to make sure that when we exit this loop "s" has the + * last sg in the chain so we can call sg_mark_end() on it. + * Only set this inside the loop since sg_iter will be iterated + * until it is NULL. + */ + s = sg_iter; + len = 0; for (j = cur + 1; j < count; ++j) { len += PAGE_SIZE; @@ -394,8 +402,6 @@ __sg_alloc_table_from_pages(struct sg_table *sgt, size -= seg_size; off = 0; cur = j; - - s = sg_next(s); } KASSERT(s != NULL, ("s is NULL after loop in __sg_alloc_table_from_pages()"));