From patchwork Mon Nov 13 20:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 164641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1470156vqg; Mon, 13 Nov 2023 12:55:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXPgHs0nkyVTrCwonjiKAtvQfnuyRnNrtKqNnWWy105Bt89W+vUpUaBGLPTe+X2gWpbtYX X-Received: by 2002:a17:902:f7d6:b0:1c3:3b5c:1fbf with SMTP id h22-20020a170902f7d600b001c33b5c1fbfmr394407plw.10.1699908954230; Mon, 13 Nov 2023 12:55:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699908954; cv=none; d=google.com; s=arc-20160816; b=hoyBelPos1ts8qw0InHF9i5sBOv2NDraB8fiNXldm8K0nUwuBkLU7Xf2tnbXZhQkiw 2BTEYj2k3TVfSU/8yV2DMPNjvcQ2r0lONLmQZLZHoXHNTCLhACfMfQ+TC3oYcey+5w1A kh3PlY29yCwpzHrI8zHrXCRvfxq/0ceXbXMol150/pXRnWiLqfSQaLAMNC7KXzh6rVRN /skAfcvpYdyJAhXc9LsaPzHx+YqVHs9hEn8rZ4Ii7IOeq3sC3ck2YE8vziFzEpPMQZUA I70dUG1AOYXvnBCTyfSCPmbegnXbIz3Ugv7/AQcIujPUlZAfe5fBCoQDSrcvsr4xq5ch QBgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=j+n4JjUuu7SDvwZ82+lpls2l3JBtzYdBv37CtP3ObUA=; fh=7Ir/mJFibKUK+ly6N2KyXv0EqG9Iwd+aiJ7/nd0b+II=; b=Hw2BB4imEFgVrcKbaBkpMAEL4hnSGF3EMrTcPVtaAthyDR4NVk1+gYPdTltm2tDIhK FPhZFrIdHIWfRvgQ8OZ4rGkpPUCudkQEMhAgWzKJNZfnMZQ+MhiR9GemQdFgmdYAU9KY 36mh8gRFH51VBZ+5q985onZgVEefw8bpVw8rd7Sn0VTjiFCkHdKvbmjfTZVzQSCKIiRn kEb57PkcGD5t0Xc7PKxOisEYpY007GM6H4yEepJM/WlJ23pJpplrRAVwbBsPZjvbfiJV tOV+lscqjkeFPaZ6X/00csqcpoE9rhD0XvfuJDg7uAvLBS/WoXWOc4xtai/OVQJNDhpx vTlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=mNXWqSzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y5-20020a17090322c500b001cc692bf120si6654519plg.61.2023.11.13.12.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 12:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=mNXWqSzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 97E018072A08; Mon, 13 Nov 2023 12:55:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjKMUzX (ORCPT + 30 others); Mon, 13 Nov 2023 15:55:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbjKMUzW (ORCPT ); Mon, 13 Nov 2023 15:55:22 -0500 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC17AD5F for ; Mon, 13 Nov 2023 12:55:16 -0800 (PST) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3ADKt4JJ014039; Mon, 13 Nov 2023 14:55:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1699908904; bh=j+n4JjUuu7SDvwZ82+lpls2l3JBtzYdBv37CtP3ObUA=; h=From:To:CC:Subject:Date; b=mNXWqSzREkkFWxja8MlUMK+Ynm2NNRzV5NnKslMYLJV3Gp7Pf8RcUFO06lt/gQW9i ADjtTMHPK8kafPTUsdza26TmUYTDfCDErspKKnacYh+T2BIKeVcoZm9r9b6qRhcdwT uzgPsQj4MXu5NGME4jrW3IpSosCzBtIofSnNZPdw= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3ADKt4Pd117171 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Nov 2023 14:55:04 -0600 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 13 Nov 2023 14:55:03 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 13 Nov 2023 14:55:04 -0600 Received: from lelv0327.itg.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3ADKt20b030247; Mon, 13 Nov 2023 14:55:02 -0600 From: Andrew Davis To: Tomi Valkeinen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter CC: , , Andrew Davis Subject: [PATCH v3] drm: omapdrm: Improve check for contiguous buffers Date: Mon, 13 Nov 2023 14:55:01 -0600 Message-ID: <20231113205501.616927-1-afd@ti.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 13 Nov 2023 12:55:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782483731964870736 X-GMAIL-MSGID: 1782483731964870736 While a scatter-gather table having only 1 entry does imply it is contiguous, it is a logic error to assume the inverse. Tables can have more than 1 entry and still be contiguous. Use a proper check here. Signed-off-by: Andrew Davis --- Changes from v2: - Double check that these multi-segment SGTs are handled correctly elsewhere in the driver - Rebase on v6.7-rc1 Changes from v1: - Sent correct version of patch :) drivers/gpu/drm/omapdrm/omap_gem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c index c48fa531ca321..3421e8389222a 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -48,7 +48,7 @@ struct omap_gem_object { * OMAP_BO_MEM_DMA_API flag set) * * - buffers imported from dmabuf (with the OMAP_BO_MEM_DMABUF flag set) - * if they are physically contiguous (when sgt->orig_nents == 1) + * if they are physically contiguous * * - buffers mapped through the TILER when pin_cnt is not zero, in which * case the DMA address points to the TILER aperture @@ -148,12 +148,18 @@ u64 omap_gem_mmap_offset(struct drm_gem_object *obj) return drm_vma_node_offset_addr(&obj->vma_node); } +static bool omap_gem_sgt_is_contiguous(struct sg_table *sgt, size_t size) +{ + return !(drm_prime_get_contiguous_size(sgt) < size); +} + static bool omap_gem_is_contiguous(struct omap_gem_object *omap_obj) { if (omap_obj->flags & OMAP_BO_MEM_DMA_API) return true; - if ((omap_obj->flags & OMAP_BO_MEM_DMABUF) && omap_obj->sgt->nents == 1) + if ((omap_obj->flags & OMAP_BO_MEM_DMABUF) && + omap_gem_sgt_is_contiguous(omap_obj->sgt, omap_obj->base.size)) return true; return false; @@ -1385,7 +1391,7 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size, union omap_gem_size gsize; /* Without a DMM only physically contiguous buffers can be supported. */ - if (sgt->orig_nents != 1 && !priv->has_dmm) + if (!omap_gem_sgt_is_contiguous(sgt, size) && !priv->has_dmm) return ERR_PTR(-EINVAL); gsize.bytes = PAGE_ALIGN(size); @@ -1399,7 +1405,7 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size, omap_obj->sgt = sgt; - if (sgt->orig_nents == 1) { + if (omap_gem_sgt_is_contiguous(sgt, size)) { omap_obj->dma_addr = sg_dma_address(sgt->sgl); } else { /* Create pages list from sgt */