Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1586083rdh; Mon, 25 Sep 2023 18:37:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdcauPxoyQNxuWZXTn7qafCUj7F74HDOsQxCP54Qpi7YD/OSePsspF+YpfUCB34i13ZOmE X-Received: by 2002:a05:6a20:1445:b0:15e:7323:5bf3 with SMTP id a5-20020a056a20144500b0015e73235bf3mr1946358pzi.26.1695692275387; Mon, 25 Sep 2023 18:37:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695692275; cv=none; d=google.com; s=arc-20160816; b=OGWAk7vlfY1ExdeIs0z6n36xxQU5WbDXyEz1LKs+GcS9Oc7X2o7g/zQ+D8cuVibdqs m2vLK+JiP2V9y0L2XOpQLAJH/JyRZalUx4CRde6vMMyqtSrzq97TVnBoI6BLAL4ZNpqn eP/8X4VdHCDbyInUw3ei+AiKiaDpNUrg9GpOfk1srbE0NA+pqoZtHLuZmtjM+W+mw8JT dsDl1HtEZ+WooMB2KItVRGIMArlf/45cT1coO/18lRFU95friN5dyTZuiX7o2gSIwYYW 0VemwEdJJ22qzyZAVw2YO5bt8nh+b6ohZpoh5HvjYRNmsOo65M/qPdDfPmf/CWN8wxiN lSCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=1NK4d8pkTzJhXkH2rah8kLxm8Da/pT2SsnBQBA7294A=; fh=TLdaYVTYpkOucWp2gi2TZIRkEiwPxZ330gpwGOOjymo=; b=MuncyGsNrAYBGD4lEJU+OhtDOl2fY1aAF24PrKwTgm8JXxDL0gZzt0PDKokRWWQESe 7U7LecM9eQMWHWMFh7bc21kwuMratAB7rg4mnDppyenSM/j0tXkbqZe4jzRPe4xu/to1 ydjuXS/jyWdLW+/cbJ2sDBXw5O/nPdnKvqfLsYUYjXFOCkj0nu+aA1kW8ilRm8tsf23+ cjVTAa2F2NwUk4AUkSFVuBzceri9a6dKXY284P8CKjXhwPrcCefZsNYk37CzaxJintNe LNdWDM6/E397ZRH7Btvkvd7c9ODPPzxIvpcxxOjU4fWCObnNOdhHzgjDHIHgBLYQvMzP qE1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oPThoU46; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k20-20020a637b54000000b0056959099f46si765396pgn.856.2023.09.25.18.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 18:37:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oPThoU46; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 665648334893; Mon, 25 Sep 2023 17:30:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbjIZAas (ORCPT + 99 others); Mon, 25 Sep 2023 20:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjIZAar (ORCPT ); Mon, 25 Sep 2023 20:30:47 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46E1B10A for ; Mon, 25 Sep 2023 17:30:41 -0700 (PDT) Received: from [192.168.2.47] (109-252-153-31.dynamic.spd-mgts.ru [109.252.153.31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 78C9C6607243; Tue, 26 Sep 2023 01:30:38 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695688239; bh=mcSnwfi+AXEs19IZ43nY6DvON7iYOy/W6ZlsG/AihDw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=oPThoU46lcTW8Wl1lrN3e9b8DxC5nN4z1FyzkgPvTTZmV7tDMXwHbDFk8Hyw8sZQo yz9R2X+kV4hym8IRTHfIlEzSFtPm2y5j4e0wGI5AEtdxgTrEwKUJU2VmSIeCxcDzHC qwbAo7s3HrDrmUtqPQ2L+yfoSPeo9NK9mHD/FFbmf/m6d1WSfKP4KyDs4+6EeclVkz oLgoYz3Xa2Mb3L8HjLnK6kRAF6OIjjblgP6XpPxzvhJeJLawdJvm1feuFPecHEGUG6 O7fwIm3WuSy8qqz2DLn8fhV6YF2fDa66oSrnqK92jBBGX+bVl4tefytmaiCX+oRjVK EFa/PfMxREknw== Message-ID: <454c464e-4534-7ec3-6d38-49b7df83c7be@collabora.com> Date: Tue, 26 Sep 2023 03:30:35 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v17 13/18] drm/shmem-helper: Add memory shrinker Content-Language: en-US To: Boris Brezillon Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?Q?Christian_K=c3=b6nig?= , Qiang Yu , Steven Price , Emma Anholt , Melissa Wen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org References: <20230914232721.408581-1-dmitry.osipenko@collabora.com> <20230914232721.408581-14-dmitry.osipenko@collabora.com> <20230915104633.0d5c3932@collabora.com> From: Dmitry Osipenko In-Reply-To: <20230915104633.0d5c3932@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 17:30:46 -0700 (PDT) On 9/15/23 11:46, Boris Brezillon wrote: > The naming becomes quite confusing, with drm_gem_shmem_unpin_locked() > and drm_gem_shmem_unpin_pages_locked(). By the look of it, it seems to > do exactly the opposite of drm_gem_shmem_swapin_locked(), except for > the missing ->evicted = true, which we can move here anyway, given > drm_gem_shmem_purge_locked() explicitly set it to false anyway. The > other thing that's missing is the > drm_gem_shmem_update_pages_state_locked(), but it can also be moved > there I think, if the the ->madv update happens before the > drm_gem_shmem_unpin_pages_locked() call in > drm_gem_shmem_purge_locked(). > > So, how about renaming this function drm_gem_shmem_swapout_locked()? The swapout name would be misleading to me because pages aren't moved to swap, but allowed to be moved. I'll rename it to drm_gem_shmem_shrinker_unpin_locked(). >> { >> struct drm_gem_object *obj = &shmem->base; >> struct drm_device *dev = obj->dev; >> >> dma_resv_assert_held(shmem->base.resv); >> >> - drm_WARN_ON(obj->dev, !drm_gem_shmem_is_purgeable(shmem)); >> + if (shmem->evicted) >> + return; >> >> dma_unmap_sgtable(dev->dev, shmem->sgt, DMA_BIDIRECTIONAL, 0); > Are we sure we'll always have sgt != NULL? IIRC, if the GEM is only > mmap-ed in userspace, get_sgt() is not necessarily called by the driver > (needed to map in GPU space), and we have a potential NULL deref here. > Maybe that changed at some point in the series, and sgt is > unconditionally populated when get_pages() is called now. The sgt is always set in this function because it's part of shrinker and shrinker doesn't touch GEMs without sgt. >> + __drm_gem_shmem_release_pages(shmem); > Make sure you drop the implicit pages_use_count ref the sgt had, this > way you can still tie the necessity to drop the pages to sgt != NULL in > drm_gem_shmem_free(). This will require further refcnt re-initialization when pages are restored if it's dropped to zero. I don't see how this will improve anything. -- Best regards, Dmitry