From nobody Thu Feb 02 11:14:33 2023 X-Original-To: dev-commits-src-branches@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 4P6x5531zKz3cwNd; Thu, 2 Feb 2023 11:14:33 +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 4P6x552QLCz46mq; Thu, 2 Feb 2023 11:14:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675336473; 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=MyLJDkX3n+kcCmoPNyhT/TJCR4//LEVd+DPCn1bA1Kg=; b=KmApRTbidB3uds2tmjGYWSoew/bNnzoOebwD/AgnEH0gYKyZstfYwU8w0OBvwVynbjLCxa bV3DOjUK7rGQv8SjigA3CVt/+DTMcJOWNvQGj/VBJH/3kWY+MlCcGVuwQ6m6iSWNU2Br8Z ByZjHFuLgo00R1RfxhcTV3OZFEREhBTr/CfIhYlMITP2rMre3z7sc6+m0EldI23KeM+s5l m6aWqapnkgZcYICuDNkyNrEUd7OXfRI3MwXEloLO1A2dYgKJWC6GXwqwPGBFqDm0gkCcY5 mgOPWpFHGz7TzjBV665yh6Xfam9iD8qZ1YmTnr9obq8O356pOjld0OczY1CC+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675336473; 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=MyLJDkX3n+kcCmoPNyhT/TJCR4//LEVd+DPCn1bA1Kg=; b=ydmM+zZdWxc2DmMKmlKnkxPEjGJEBgo5Bk9RzVTUKuthyY841NDoQ5nuEbGsYYsEezumAd /QJi38t9kolRL/Hx7vW8uuD6Rsf1wLjL6vu1G4EZyYlumBqli9Tm2hpLsru9d1OweT5uO5 2qN1EfIeQu/PrSSXy7TI7Pxynn8HTtyZ0zLp0MfImCi1nihXV9ySpIdkTm/fzopSLjTDQm I04Vdk8Cru4KIbeNMiNKfJvm5FlnJUxoZQvh9Ki9v/MDdDdHLLRp/QYGHBqd64WAzPvo5/ ku8UMaSdqbX5R8VZQVLg1T6A9JVBq/fc+7ElnONa8i14SUdximPBzO+GRU9SWw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675336473; a=rsa-sha256; cv=none; b=A+0ZC+2tqUtdUI5Zwb6ZUhkY6FkCjvadvSLd6U45QC+PqA5IMkW+bvvxDnscwTl8/RYupK AjbYYaMCxwbhP4fgpeJYjU7W6SdoTwe10s7Yilm+9yLg7584JVnpPqlIQNpaGE7zLq2Ktz o8mN9kTdZlDYzPd19WDpTsVBIVwoI2Z82xK1/Ku+jeBciCF2iQC/LhF/hFBsBeS8X2wgt7 kNKAyoLaA3xKiDEolXIhHAQxGlsu+jQfrvEoK9RCbhHrSY/UNo4PMLJik/ZJEJqYAcl1ZV VwXV6EbivQENnP+dpQ5EmiL/wLVTP3kcot72uSSc931f3tJ0mEUCip98xXmaBw== 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 4P6x551S8qzsfD; Thu, 2 Feb 2023 11:14:33 +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 312BEXv7076634; Thu, 2 Feb 2023 11:14:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 312BEXoN076633; Thu, 2 Feb 2023 11:14:33 GMT (envelope-from git) Date: Thu, 2 Feb 2023 11:14:33 GMT Message-Id: <202302021114.312BEXoN076633@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 59a9cd98631c - stable/13 - linuxkpi: Fix return value of dma_map_sgtable List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 59a9cd98631c026a4666e604752e99b04207d63c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=59a9cd98631c026a4666e604752e99b04207d63c commit 59a9cd98631c026a4666e604752e99b04207d63c Author: Austin Shafer AuthorDate: 2022-12-06 15:25:53 +0000 Commit: Emmanuel Vadot CommitDate: 2023-02-02 11:10:36 +0000 linuxkpi: Fix return value of dma_map_sgtable dma_map_sgtable internally uses the dma_map_sg_attrs helper. The problem is that dma_map_sg_attrs returns the number of entries mapped, whereas dma_map_sgtable returns nonzero on failure. This leads to dma_map_sgtable returning non-zero-but-positive values which tricks other areas of the stack into thinking nents is a valid pointer. This checks if nents is valid and returns zero if so, updating the nents field in sgt. This fixes PRIME render offload with nvidia-drm. Fixes: 9202c95f47c2 ("linuxkpi: Add dma_{un,}map_sgtable") (cherry picked from commit 4085bde9fa2ea7ebe861a2e4a07312aac00a26fc) --- sys/compat/linuxkpi/common/include/linux/dma-mapping.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h index ef3570ef7639..25e4acf9e45d 100644 --- a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h +++ b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h @@ -358,7 +358,14 @@ dma_map_sgtable(struct device *dev, struct sg_table *sgt, unsigned long attrs) { - return (dma_map_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs)); + int nents = dma_map_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs); + + if (nents < 0) { + return nents; + } else { + sgt->nents = nents; + return 0; + } } static inline void