Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp320961rdb; Fri, 5 Jan 2024 10:53:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKqbXTO61eeueov7C9g9E3rPLW6yG76EmFre++5YuSpv9vBGgmxuNG5FDzMGJafxbQ6r6c X-Received: by 2002:a50:a456:0:b0:557:34b4:22ed with SMTP id v22-20020a50a456000000b0055734b422edmr615536edb.15.1704480831242; Fri, 05 Jan 2024 10:53:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480831; cv=none; d=google.com; s=arc-20160816; b=d+bG1+93cXqOp8ee0OtMSbvbG3/8te4dnBvIG4i1t7rU5tmfyd/iy3UGxQCAvQIKm0 tvCSDbNGKEWnsbUa4ehyJz2pE+BCVobAkK1fFq+QRzSNNnrn+xcnuK0VTFTPg5+6vERJ TrH5DZJxB+ZJhPB5lQMDcVAR4H6GElfOqnUwtpwEfijGRktemB4jbIHs1FSl1JHZEYgI 4Twx2vdNgJ/Op7uRog53P4++SdY0y4432CaJg8DBC5kQZoACIZ5eZBkpX3K0h7NAEPs9 ARxN7snx5w97s+OtNlroVZnJM68tyIx52cqJbtWQD6PYksv+CLWzMypHb5WFQRPT4CyQ Q6aA== 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=+IrXuO7gzRuPTab542AHBaSpYWgjBTMenk/DnQ7YooI=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=kzMrjPAysqvTB4lUuo05hKAtxgL+ZrMmMX3VS3LhJOzv1r9dw+DsPLKnm5WQkDInY9 FbjJ5cxUCjRVPIVLeKpq3sgvsP37okbEYqKenOktX08of/6zhgE0BaBljq2nnflG2rY7 Sak96IllNS2gr/WmVT5Iwd2mk+mYRSrCuCpJ+ltQ0/aNFVCrlhbRyKtQ1ZP7+i+/41kP DxDqQjtdAhVjfZwoDCFNbCZMyPu6oMvTVWCIJLVMR+qy/sGSEtEKPeK+OF2Ce1EOL0p3 W8N/yWjrq8OgtYOOFTVBAs/rJ4aofLkrRBaWINf1/Oq8aeIDn24BURpfNjgFm17DR/8f zjVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=cNGAEogZ; spf=pass (google.com: domain of linux-kernel+bounces-18265-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18265-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u16-20020a509510000000b00557447b5d27si292513eda.596.2024.01.05.10.53.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:53:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18265-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=cNGAEogZ; spf=pass (google.com: domain of linux-kernel+bounces-18265-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18265-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F0FDB1F24719 for ; Fri, 5 Jan 2024 18:53:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF9EB3C08D; Fri, 5 Jan 2024 18:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="cNGAEogZ" 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 A5BF63BB2F for ; Fri, 5 Jan 2024 18:47:29 +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=1704480448; bh=hLZrw2uyBORbZqEow6e5Z9wt3wafG02YrAXZMmshnO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cNGAEogZcRVb+dzqTWonn6PmYnXTX/FYV6PGxzbt6f7gVux5+fwoN2dMxpElgOFUS +33gPf13ydlPZmcFiQTEO0+P5pqkPzdqGlyjAxqtd7FpXlOaQ65gl2/ndIE4C0mMt+ 8xHKpqYWRDi4C35UEpLbVnJYos06xo0pZuVKz0NNx3y2Xs7AbpqylorRj/8+X+u83u w0/28yBpFqXZ2J8n7urums5aDltS79D3CrOamytc5tdJcglGEl9gCPuFZjbk2a1G/u JI2WrP99ehgJFQLyAQrYZhBGs+HZl3Ow4xHiUZb2nPJV/yaI9fr42/OlV7F9uE/zH3 nYGaYi3xmoiXw== 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 6FB813782058; Fri, 5 Jan 2024 18:47:26 +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 27/30] drm/virtio: Pin display framebuffer BO Date: Fri, 5 Jan 2024 21:46:21 +0300 Message-ID: <20240105184624.508603-28-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 Prepare to addition of memory shrinker support by pinning display framebuffer BO pages in memory while they are in use by display on host. Shrinker is free to relocate framebuffer BO pages if it doesn't know that pages are in use, thus pin the pages to disallow shrinker to move them. Acked-by: Gerd Hoffmann Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_gem.c | 19 +++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_plane.c | 17 +++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index bb7d86a0c6a1..83d1e4622292 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -318,6 +318,8 @@ void virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs); void virtio_gpu_array_put_free_delayed(struct virtio_gpu_device *vgdev, struct virtio_gpu_object_array *objs); void virtio_gpu_array_put_free_work(struct work_struct *work); +int virtio_gpu_gem_pin(struct virtio_gpu_object *bo); +void virtio_gpu_gem_unpin(struct virtio_gpu_object *bo); /* virtgpu_vq.c */ int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev); diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c index 7db48d17ee3a..625c05d625bf 100644 --- a/drivers/gpu/drm/virtio/virtgpu_gem.c +++ b/drivers/gpu/drm/virtio/virtgpu_gem.c @@ -294,3 +294,22 @@ void virtio_gpu_array_put_free_work(struct work_struct *work) } spin_unlock(&vgdev->obj_free_lock); } + +int virtio_gpu_gem_pin(struct virtio_gpu_object *bo) +{ + int err; + + if (virtio_gpu_is_shmem(bo)) { + err = drm_gem_shmem_pin(&bo->base); + if (err) + return err; + } + + return 0; +} + +void virtio_gpu_gem_unpin(struct virtio_gpu_object *bo) +{ + if (virtio_gpu_is_shmem(bo)) + drm_gem_shmem_unpin(&bo->base); +} diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c index a72a2dbda031..162fb8a44d71 100644 --- a/drivers/gpu/drm/virtio/virtgpu_plane.c +++ b/drivers/gpu/drm/virtio/virtgpu_plane.c @@ -248,20 +248,28 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane, struct virtio_gpu_device *vgdev = dev->dev_private; struct virtio_gpu_framebuffer *vgfb; struct virtio_gpu_object *bo; + int err; if (!new_state->fb) return 0; vgfb = to_virtio_gpu_framebuffer(new_state->fb); bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]); - if (!bo || (plane->type == DRM_PLANE_TYPE_PRIMARY && !bo->guest_blob)) + + err = virtio_gpu_gem_pin(bo); + if (err) + return err; + + if (plane->type == DRM_PLANE_TYPE_PRIMARY && !bo->guest_blob) return 0; if (bo->dumb && (plane->state->fb != new_state->fb)) { vgfb->fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context, 0); - if (!vgfb->fence) + if (!vgfb->fence) { + virtio_gpu_gem_unpin(bo); return -ENOMEM; + } } return 0; @@ -271,15 +279,20 @@ static void virtio_gpu_plane_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *state) { struct virtio_gpu_framebuffer *vgfb; + struct virtio_gpu_object *bo; if (!state->fb) return; vgfb = to_virtio_gpu_framebuffer(state->fb); + bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]); + if (vgfb->fence) { dma_fence_put(&vgfb->fence->f); vgfb->fence = NULL; } + + virtio_gpu_gem_unpin(bo); } static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, -- 2.43.0