From patchwork Sun Mar 5 22:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 6129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1559279wrd; Sun, 5 Mar 2023 14:45:25 -0800 (PST) X-Google-Smtp-Source: AK7set+TPFbuJ67Bqr40C60+MSMr2ShX+E/r39OTmPL9P7adqoY7y7u51J7uN8H872MNV6fcsBmW X-Received: by 2002:a17:90b:1e01:b0:237:39b1:7cb1 with SMTP id pg1-20020a17090b1e0100b0023739b17cb1mr9696531pjb.19.1678056324732; Sun, 05 Mar 2023 14:45:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678056324; cv=none; d=google.com; s=arc-20160816; b=pFMz7TT4SrJVdTAIdk/BuYLbLTUJDfpNBi93rDS2FQphh1N1o71xMpVoyQUx0D/xrv 25QPOiuAfd8dxhjKXY5QVnI9KtUJY6JIady77ZqRmIfW1dbO/HrVPOoqaL2eVR1gAvcz ZI4O+oP2Av3RhapnQ4P3vDAVErX1w+CY4+EBralCJSYSv6CZjGsrYZC7BEZ/Uo0jyiaG UBUshXucQNTPdDozvEnoumtsCIfm2DxrZQHTRq37VcjvYPZNYXxPI0Atmkpo3ieeQfpF YYEJxFcfu+QeNH2QiPCaCJcrBM1v9516iPWA65+cxk32IZBK8tfv9iC7jsuoZxFOdvim obxQ== 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=C4pi6ERLx1Lk4E6abQt9bgviHnKnRjhjj9Dww9JslMs=; b=ssNY/rvVeG43wM+Qznrmq2WvkFNLaatxNHAGjtFa1brO84yjE4I2Hl4k1kUnQ69cVV dRbMi0eHXD1BgE4G7gEqnsxn1IaSpgGHD5QaPHkMW0CBEskTuYLXdo7a+QP0cB0onWJT LJTkaZhpTYc2pXMSSoR/N+wfb4NZxWA7aPG6Ula5wPydjRbv3GEdT7SYmRT/7nJIEFiF ATWNgYgDbdXl4eP2fcb94Eel3+/sMgyzp97Zgh3lQaWgE9pFktwGEo1KN8uDHrXTqEMw xXdt7k6RZCqEAZKNKLHwSafQoZD152KiszItJwDhJANC6yxOuX8JP9jV7q/fNkdKymaj eEFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WRPw6sZ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a17090ac00500b002340e488cc5si10300007pjt.96.2023.03.05.14.45.10; Sun, 05 Mar 2023 14:45:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WRPw6sZ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjCEWLb (ORCPT + 99 others); Sun, 5 Mar 2023 17:11:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjCEWLa (ORCPT ); Sun, 5 Mar 2023 17:11:30 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1291913D4A for ; Sun, 5 Mar 2023 14:11:28 -0800 (PST) Received: from workpc.. (unknown [109.252.117.89]) (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 madras.collabora.co.uk (Postfix) with ESMTPSA id 9DEDE6602097; Sun, 5 Mar 2023 22:11:25 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678054287; bh=VtlMAkBh8fY9xCWhTSNCidwaxxi7vJ8HsX8hoUdvt7A=; h=From:To:Cc:Subject:Date:From; b=WRPw6sZ8reGpJm+GDgk7+XNUy9kCbuV/JN9gd3zHRY0eDYVrEr7JzQaSA3j3EIKDp 7WbOo1Pjlr6Cu+Wz8TU7pd2Ni0jdGcEGRxeuo/qAYxMtdgNYyVfJyAoRlc0wCnry/M 5BE0IQb3zvm6R3WUQROVT06/GSWR0Yh2O+sLj58R2zkxN7vDD5I/iz8bHXBZUCknqv NSGnqeK84a/9TuOPso+HBImBC55AkJ6nHuSMJB92O2M4m6ugkiW5RwdFqi/jzuV0VQ c79TRjmirRP30J2y3lqwlY+w3LNBcqJU7bcJ/HhY+XM6T/kbkrzSGa1kjzoFweSp1I mldqGDPJY50fw== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org, intel-gfx@lists.freedesktop.org Subject: [PATCH v12 00/11] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers Date: Mon, 6 Mar 2023 01:10:00 +0300 Message-Id: <20230305221011.1404672-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759569588814617707?= X-GMAIL-MSGID: =?utf-8?q?1759569588814617707?= This series: 1. Adds common drm-shmem memory shrinker 2. Enables shrinker for VirtIO-GPU driver 3. Switches Panfrost driver to the common shrinker Changelog: v12:- Fixed the "no previous prototype for function" warning reported by kernel build bot for v11. - Fixed the missing reservation lock reported by Intel CI for VGEM driver. Other drivers using drm-shmem were affected similarly to VGEM. The problem was in the dma-buf attachment code path that led to drm-shmem pinning function which assumed the held reservation lock by drm_gem_pin(). In the past that code path was causing trouble for i915 driver and we've changed the locking scheme for the attachment code path in the dma-buf core to let exporters to handle the locking themselves. After a closer investigation, I realized that my assumption about testing of dma-buf export code path using Panfrost driver was incorrect. Now I created additional local test to exrecise the Panfrost export path. I also reproduced the issue reported by the Intel CI for v10. It's all fixed now by making the drm_gem_shmem_pin() to take the resv lock by itself. - Patches are based on top of drm-tip, CC'd intel-gfx CI for testing. v11:- Rebased on a recent linux-next. Added new patch as a result: drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() It's needed by the virtio-gpu driver to swap-in/unevict shmem object, previously get_pages_sgt() didn't use locking. - Separated the "Add memory shrinker" patch into smaller parts to ease the reviewing, as was requested by Thomas Zimmermann: drm/shmem-helper: Factor out pages alloc/release from drm_gem_shmem_get/put_pages() drm/shmem-helper: Add pages_pin_count field drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin drm/shmem-helper: Factor out unpinning part from drm_gem_shmem_purge() - Addessed the v10 review comments from Thomas Zimmermann: return errno instead of bool, sort code alphabetically, rename function and etc minor changes. - Added new patch to remove the "map->is_iomem" from drm-shmem, as was suggested by Thomas Zimmermann. - Added acks and r-b's that were given to v10. v10:- Was partially applied to misc-fixes/next. https://lore.kernel.org/dri-devel/6c16f303-81df-7ebe-85e9-51bb40a8b301@collabora.com/T/ Dmitry Osipenko (11): drm/shmem-helper: Switch to reservation lock drm/shmem-helper: Factor out pages alloc/release from drm_gem_shmem_get/put_pages() drm/shmem-helper: Add pages_pin_count field drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin drm/shmem-helper: Factor out unpinning part from drm_gem_shmem_purge() drm/shmem-helper: Add memory shrinker drm/shmem-helper: Remove obsoleted is_iomem test drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() drm/gem: Export drm_gem_pin/unpin() drm/virtio: Support memory shrinking drm/panfrost: Switch to generic memory shrinker drivers/gpu/drm/drm_gem.c | 2 + drivers/gpu/drm/drm_gem_shmem_helper.c | 613 ++++++++++++++---- drivers/gpu/drm/drm_internal.h | 2 - drivers/gpu/drm/lima/lima_gem.c | 8 +- drivers/gpu/drm/panfrost/Makefile | 1 - drivers/gpu/drm/panfrost/panfrost_device.h | 4 - drivers/gpu/drm/panfrost/panfrost_drv.c | 34 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 30 +- drivers/gpu/drm/panfrost/panfrost_gem.h | 9 - .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 122 ---- drivers/gpu/drm/panfrost/panfrost_job.c | 18 +- drivers/gpu/drm/panfrost/panfrost_mmu.c | 19 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 18 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 52 ++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 37 ++ drivers/gpu/drm/virtio/virtgpu_kms.c | 8 + drivers/gpu/drm/virtio/virtgpu_object.c | 137 +++- drivers/gpu/drm/virtio/virtgpu_plane.c | 22 +- drivers/gpu/drm/virtio/virtgpu_vq.c | 40 ++ include/drm/drm_device.h | 10 +- include/drm/drm_gem.h | 3 + include/drm/drm_gem_shmem_helper.h | 83 ++- include/uapi/drm/virtgpu_drm.h | 14 + 23 files changed, 917 insertions(+), 369 deletions(-) delete mode 100644 drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c