From nobody Tue Dec 06 15:27:40 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 4NRPRx1nWtz4jw6J; Tue, 6 Dec 2022 15:27:41 +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 4NRPRx1GmQz3vSs; Tue, 6 Dec 2022 15:27:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670340461; 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=el0swPMxtF4hA1YfIpAZCB6+ZjsiCy919XWCRjaS8ho=; b=BsOsNHe/Y6eGnbgIruj2U62etMf3ncQWzmICvUno7EgOGyhvVDyIUCe7497IwRVpzuhOaN 4etJVxmjT0bx2qk4b3VjH1Dwj63w4FcBqnDS2fPhKc3JNkyHO7OFPDhuy26aZxT+CwSNnV pfjVI+Gl4ThXyhAO2GgJ/AJWDj8c0s6pCGLzC5ac/9pLx3s9wm9c3Xu//2rDRaLv/lisGu AcKWt+y+2qjD3tdjwdLcHdbv4jJ0y0MztRIWcKziTG9utwxRN5TcWcKhCi9B1JBTOm7fX9 c8AsoJnnve1DoBniUCoO06haRw7ifDXdMEIchh3rMpFXrLhIZnKpoPIykObwAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670340461; 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=el0swPMxtF4hA1YfIpAZCB6+ZjsiCy919XWCRjaS8ho=; b=TJT66GU7r9paD0BZxc4qzDx8lvqHHWb45T1hYuO+ujGTvC3RlBhts9i+CHy1BKMuAwhwLK kinVdCMb3xNrjDQf58UJVX6ygQuAAXIz2qFQn4KUJjMdOa2QFuv2zV1gydsOQV94B2Vq2p No9fmz+U/Qlm2zLinvN+OBZrp2PO/ksxgAfWpZaLGnvAALsChV9djTxpBX2nTn6zLjh35x BK6jTLHnoD5e7WvTKeuS/iqltkBzg+Lk/6ddRAa3tY/467m07/I+Ez9iJu1wezQfMTWlZ5 LDnt2Tw12O3Z/Psgkt4WsSEZpCjHKmEmt2HF5lkB5pnZ+yUTNRYkPREIO8wj1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670340461; a=rsa-sha256; cv=none; b=KA/pyvSCEeb+jyW9Z9m78rggsfFPvcxRtWA46+9RohFczGBotsXUUZSCKbUcqpaF4tCqFC D0m2EDiggkEDbJIfO6EXRdKpq1HC1TtMqgVUVtaMuywBnona8nzeDuUywt0OSUggN2OxCm 1EIE4Fxd2wNWKmFkgYPZjLy7YLo/v9iXYYkZ6raUrXxOCyOoQvNQwfCF0iNISQvzWD3Gzg 3sUOMmq/NnL70bfPRGJpqo+9VK9cnzKoh0/VMIkazdGs8oO90Arpvxb2RFLQ72NmMZkUmF tLUCFTgKPctrysbTUc316+jyNEH4BApKns10hFKhx6a5ZmhqylKarnh6HMFuSg== 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 4NRPRx04plzhgq; Tue, 6 Dec 2022 15:27:41 +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 2B6FRexH091444; Tue, 6 Dec 2022 15:27:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B6FReUE091443; Tue, 6 Dec 2022 15:27:40 GMT (envelope-from git) Date: Tue, 6 Dec 2022 15:27:40 GMT Message-Id: <202212061527.2B6FReUE091443@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 4085bde9fa2e - main - linuxkpi: Fix return value of dma_map_sgtable 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: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4085bde9fa2ea7ebe861a2e4a07312aac00a26fc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=4085bde9fa2ea7ebe861a2e4a07312aac00a26fc commit 4085bde9fa2ea7ebe861a2e4a07312aac00a26fc Author: Austin Shafer AuthorDate: 2022-12-06 15:25:53 +0000 Commit: Emmanuel Vadot CommitDate: 2022-12-06 15:25:53 +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") --- 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 d3d25fcce857..7f2579787b4b 100644 --- a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h +++ b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h @@ -362,7 +362,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