From nobody Wed Nov 27 21:27:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445902; cv=none; d=zohomail.com; s=zohoarc; b=jyrHcrWfPvqEE684PbKd+LvorjnQOpr6cufIa1tTrnmXoRwBKhnbPcD/ZrFS68dAt0X/YRHr5OaRE8tO+olUX/rGvacCv26ohl3XLwQ9kfy4rZTYvF074BKnVC8MIeYM7jqHrE2ctzZFZJ93CAKO9vvDaZdZZKGsmdvq8Oeo1JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445902; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=YgyveT/AkQorgP98FFpx1RYLQ7ksuh/Uc6LtWBijlWCq8VeUxfZsdvr96XLz9Z4kJM4JTjqc04SZNeE8MNfWso7DmiE06HnmlZj8FjYSD6CdIBspUqwd6hhTTImp82U2g/MkQgn9y86tAVmzeY3hfYECzkxsqeP+Fa25M6265pI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445902030973.4249630907808; Thu, 27 Jul 2023 01:18:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570917.893506 (Exim 4.92) (envelope-from ) id 1qOwC1-00064b-Bi; Thu, 27 Jul 2023 08:17:53 +0000 Received: by outflank-mailman (output) from mailman id 570917.893506; Thu, 27 Jul 2023 08:17:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOwC0-0005yF-20; Thu, 27 Jul 2023 08:17:52 +0000 Received: by outflank-mailman (input) for mailman id 570917; Thu, 27 Jul 2023 08:17:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw5T-0001DS-OP for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:11:07 +0000 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [2607:f8b0:4864:20::436]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 22d168aa-2c55-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 10:11:07 +0200 (CEST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6748a616e17so183287b3a.1 for ; Thu, 27 Jul 2023 01:11:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:05 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 22d168aa-2c55-11ee-b247-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445466; x=1691050266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=KWf7bMy1nbQ37OxDK+aLk4UU+d+DpidRt45gsv6WisntZ5r23wZ3pYKMCoLchBsQxQ dbRrJ4b0aFwJmGna2/IEy8T8QiKnn2NACgYbVRTrckTcQDGJyAPHMooOCl62MUAwOoyA JbZysBi4oQBt301gAOSv+2GS8dKtdtSP0nG8DKgUtI05eGkdQUUBXQMQvZN3o0luNYiw 8kcVk8roCfN8SKqwYrPgL6wyyB4sigzvUww4WP5NJ+eSnXEpjiht6HKW6ptfgHl7+XLv 6NnbrWDfXzNY62UnzW5yOMd63/qymxxfuyafQ4go8x2ZHPA9qwKwZ1PQJSZV3Wy/oPgn SKCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445466; x=1691050266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=DAr3LBZWDPaMckVC/wnvFReQO7mODTePKaCarOPlBko5XPAagDFCyxog0YXMJworqD UL9xzg19kYYc26jBryJZPUxIe8QIbRUd95Nybqxt1Ngw6kdzK1TEfNmbdOz3kUMtZa7p Nlz4eEqq93hGk3De7a2FwIpySoKlFv7AQpFV0med7lvhZJduVZEl1JpvM+MdYQXonx9D 488RfBC/RpeaJMo/jQFQnJaY3GK6TnOAKTaUR4AbAxPfBCMB+il1nZGvoG8w+pGOafez dct54VGIkSa/jX8Hu1uFugtNKHMXWKbHaLVXCgiL1wjqlZTMM5KVtda6FAhUnwz+UBHU 6Y6A== X-Gm-Message-State: ABy/qLY+WyeQMxoSJT0slFcFgmVBE8YFvQfqTyrDHbN5bjYGa3jW8mwo boFoblf268+WIrh5zcEgv2B9Cw== X-Google-Smtp-Source: APBJJlHsQWiMeK1ZGCoT9EMqzV36W3zQjtsLKzuNfdQAXhrStS5DTpZT9lorCJhzpRLn0tDb83CKIQ== X-Received: by 2002:aa7:8615:0:b0:681:9fe0:b543 with SMTP id p21-20020aa78615000000b006819fe0b543mr4626555pfn.2.1690445465777; Thu, 27 Jul 2023 01:11:05 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH v3 26/49] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Thu, 27 Jul 2023 16:04:39 +0800 Message-Id: <20230727080502.77895-27-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445903401100003 Content-Type: text/plain; charset="utf-8" In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the drm-panfrost shrinker, so that it can be freed asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU read-side critical section when releasing the struct panfrost_device. Signed-off-by: Qi Zheng Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++- drivers/gpu/drm/panfrost/panfrost_gem.h | 2 +- .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 30 +++++++++++-------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/p= anfrost/panfrost_device.h index b0126b9fbadc..e667e5689353 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -118,7 +118,7 @@ struct panfrost_device { =20 struct mutex shrinker_lock; struct list_head shrinker_list; - struct shrinker shrinker; + struct shrinker *shrinker; =20 struct panfrost_devfreq pfdevfreq; }; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panf= rost/panfrost_drv.c index a2ab99698ca8..e1d0e3a23757 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -601,10 +601,14 @@ static int panfrost_probe(struct platform_device *pde= v) if (err < 0) goto err_out1; =20 - panfrost_gem_shrinker_init(ddev); + err =3D panfrost_gem_shrinker_init(ddev); + if (err) + goto err_out2; =20 return 0; =20 +err_out2: + drm_dev_unregister(ddev); err_out1: pm_runtime_disable(pfdev->dev); panfrost_device_fini(pfdev); diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panf= rost/panfrost_gem.h index ad2877eeeccd..863d2ec8d4f0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -81,7 +81,7 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo, void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping); void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo); =20 -void panfrost_gem_shrinker_init(struct drm_device *dev); +int panfrost_gem_shrinker_init(struct drm_device *dev); void panfrost_gem_shrinker_cleanup(struct drm_device *dev); =20 #endif /* __PANFROST_GEM_H__ */ diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu= /drm/panfrost/panfrost_gem_shrinker.c index 6a71a2555f85..3dfe2b7ccdd9 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c @@ -18,8 +18,7 @@ static unsigned long panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_contr= ol *sc) { - struct panfrost_device *pfdev =3D - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev =3D shrinker->private_data; struct drm_gem_shmem_object *shmem; unsigned long count =3D 0; =20 @@ -65,8 +64,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj) static unsigned long panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_contro= l *sc) { - struct panfrost_device *pfdev =3D - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev =3D shrinker->private_data; struct drm_gem_shmem_object *shmem, *tmp; unsigned long freed =3D 0; =20 @@ -97,13 +95,22 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, s= truct shrink_control *sc) * * This function registers and sets up the panfrost shrinker. */ -void panfrost_gem_shrinker_init(struct drm_device *dev) +int panfrost_gem_shrinker_init(struct drm_device *dev) { struct panfrost_device *pfdev =3D dev->dev_private; - pfdev->shrinker.count_objects =3D panfrost_gem_shrinker_count; - pfdev->shrinker.scan_objects =3D panfrost_gem_shrinker_scan; - pfdev->shrinker.seeks =3D DEFAULT_SEEKS; - WARN_ON(register_shrinker(&pfdev->shrinker, "drm-panfrost")); + + pfdev->shrinker =3D shrinker_alloc(0, "drm-panfrost"); + if (!pfdev->shrinker) + return -ENOMEM; + + pfdev->shrinker->count_objects =3D panfrost_gem_shrinker_count; + pfdev->shrinker->scan_objects =3D panfrost_gem_shrinker_scan; + pfdev->shrinker->seeks =3D DEFAULT_SEEKS; + pfdev->shrinker->private_data =3D pfdev; + + shrinker_register(pfdev->shrinker); + + return 0; } =20 /** @@ -116,7 +123,6 @@ void panfrost_gem_shrinker_cleanup(struct drm_device *d= ev) { struct panfrost_device *pfdev =3D dev->dev_private; =20 - if (pfdev->shrinker.nr_deferred) { - unregister_shrinker(&pfdev->shrinker); - } + if (pfdev->shrinker) + shrinker_free(pfdev->shrinker); } --=20 2.30.2