Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp320481rdb; Fri, 5 Jan 2024 10:52:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0CN9RC1vJuFm2B5yjk45fwUGHGQVRqWGdcaleb6XGbaFc5YWkMJ0maea+3tqgpjsv3WnQ X-Received: by 2002:a05:6358:70c1:b0:175:3524:f2ce with SMTP id h1-20020a05635870c100b001753524f2cemr3055596rwh.1.1704480763897; Fri, 05 Jan 2024 10:52:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480763; cv=none; d=google.com; s=arc-20160816; b=dfyBJUGi7zASkTr3b4lXyMZgPSInbFh0esIURyDecYl3996Fh840+qQBXWRO1gsF55 cbb2egl6ptp98t9j0FhVcSWAIUKYGHQ+Hn2gDYav8b4cbecmlxmUdqPjoKUYGiM6oePs MTmUHYjsLIc3xfEFJdnkOrswybaOH2z7QcqkZKI5N8Y/pFo4xGafQxDg+wwma+VM8xnA HMBpX242QZpHSXyK5VyskWRNdOS0pwY55q+go23muVMfGRlPMmY0M3oqTH/bTGon4lKM 9iLn4ePMEKHZ+LuUGv4X5YXYw5KFcwdaON8SjEqEJ/Adi06EuqVT85JZZ1+tqTYIdHhJ nlLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bl4Stn0U07rFiIwM4bIt2wOUs0fat/6ybFFRE7pRjE8=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=b/h/v1PG1ktYTexwCGBMbiZlJVd3y1mcRC9vCPYOZlblaEStOCcpHWqEaM0e8qfSRm Vdr1iVRI2NH5DshZHd7zam6pbvKQZYNRxlkFXq83vbjh40TsodETS67LOUpbnniEYuZ2 hmEV0PquGZe7Ex4wOskmjrN1116uXO+LEpvSP3qc1TxcW3V+P2ixwIzAOW4hADbtaHbL Xr/rOoeF8hfiyQIst/Q4sLbojm5Nf8v3yYIn9nm47AJWazzynfrRxMH77vT+SP4bvwX6 DQCsfn9yb9wsPYNyg6HdW+YpjNr4+BjHM38v8rKyFtRZyyf2am7XUIV9Q9hTGxPxAzRt BjMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kEoyrUuq; spf=pass (google.com: domain of linux-kernel+bounces-18261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m20-20020a6562d4000000b005cdf8b1fcdasi1650147pgv.194.2024.01.05.10.52.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:52:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kEoyrUuq; spf=pass (google.com: domain of linux-kernel+bounces-18261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87A15285D69 for ; Fri, 5 Jan 2024 18:52:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22F373AC0F; Fri, 5 Jan 2024 18:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="kEoyrUuq" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 037F23A8DA for ; Fri, 5 Jan 2024 18:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1704480441; bh=92DtaMjqXiYcBus3ShTQudZc7/346pWIqwyiwc+pNg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kEoyrUuqdlwGs9/4O1PrKLsmZzI4Qej2W6V9qzlpK5WXJD5FO5/7xgqBoX8Ye5FOg UOulsj9FNHuqHJO6tCgTyhe6URp00htm15iutOBQhSX09/qLL6Ad2PHzYg2XpltfXE lAOx/3vdvleFz0Yz3tcgltqtVEl3+1HHKBDcWKSGulLCaYZfRYClEs5tuG4o5yJ/H3 T3ZAjeT4JQ2L+Mqpb5QigjMzoytAMbLi+PiGtjX6QZdn2kP3zaHiB+h5BiM5wq3tZ/ dJZtoQmTCTFFxOqUAVQaEUg+ZvvOBLsfg/5P5nlPyFRDxwC5+69nCOlo+aKsQgewhr gKNZgZcK76bSg== Received: from workpc.. (cola.collaboradmins.com [195.201.22.229]) (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) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 273D3378204A; Fri, 5 Jan 2024 18:47:20 +0000 (UTC) From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Boris Brezillon , Emma Anholt , Melissa Wen Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v19 23/30] drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() Date: Fri, 5 Jan 2024 21:46:17 +0300 Message-ID: <20240105184624.508603-24-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105184624.508603-1-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Export drm_gem_shmem_get_pages_sgt_locked() that will be used by virtio-gpu shrinker during GEM swap-in operation done under the held reservation lock. Reviewed-by: Boris Brezillon Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 22 +++++++++++++++++++++- include/drm/drm_gem_shmem_helper.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 59cebd1e35af..8fd7851c088b 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -875,12 +875,31 @@ struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem) } EXPORT_SYMBOL_GPL(drm_gem_shmem_get_sg_table); -static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem) +/** + * drm_gem_shmem_get_pages_sgt_locked - Provide a scatter/gather table of pinned + * pages for a shmem GEM object + * @shmem: shmem GEM object + * + * This is a locked version of @drm_gem_shmem_get_sg_table that exports a + * scatter/gather table suitable for PRIME usage by calling the standard + * DMA mapping API. + * + * Drivers must hold GEM's reservation lock when using this function. + * + * Drivers who need to acquire an scatter/gather table for objects need to call + * drm_gem_shmem_get_pages_sgt() instead. + * + * Returns: + * A pointer to the scatter/gather table of pinned pages or error pointer on failure. + */ +struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem) { struct drm_gem_object *obj = &shmem->base; int ret; struct sg_table *sgt; + dma_resv_assert_held(shmem->base.resv); + if (shmem->sgt) return shmem->sgt; @@ -904,6 +923,7 @@ static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_ kfree(sgt); return ERR_PTR(ret); } +EXPORT_SYMBOL_GPL(drm_gem_shmem_get_pages_sgt_locked); /** * drm_gem_shmem_get_pages_sgt - Pin pages, dma map them, and return a diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h index df97c11fc99a..167f00f089de 100644 --- a/include/drm/drm_gem_shmem_helper.h +++ b/include/drm/drm_gem_shmem_helper.h @@ -149,6 +149,7 @@ void drm_gem_shmem_purge_locked(struct drm_gem_shmem_object *shmem); struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem); struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem); +struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem); void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem, struct drm_printer *p, unsigned int indent); -- 2.43.0