Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1810068rdh; Tue, 26 Sep 2023 04:28:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQOZJxCXWXgxdNw5z6YGytNYEdpBaU1tYuy+IKC2BWIfSNisXuwmfdx0RiHtFLRO7dSZlD X-Received: by 2002:a05:6870:a491:b0:1d6:5670:fcce with SMTP id j17-20020a056870a49100b001d65670fccemr10174117oal.51.1695727680578; Tue, 26 Sep 2023 04:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695727680; cv=none; d=google.com; s=arc-20160816; b=qB+eUh8z/5mtjpODwTeE8HD7hxvIbvGL0XZtvBMRcmzkAAvP1TL8wH8M5A0ulQuGm1 RoF6TpRcNVpr2QaVWuvlFteRCubR64EFQrp2YbMXsWDKH0nuWlgSHuL3Aio1rIEIevOu k5a1l7huEMPKtWpy6zt/w1tgkuyVpayvKyEt3dJMDx/3bwcuyj9YbNnf6Hu5JP2vryuc q4UtZGfq5oC3aDr+x6O0kvgPAX2702EQetFE6IijQwv96BlMH0XdfA2daSTVeXNGjSyI q83UyWkCVsJpZg1jhtz/8JRHgJviOYGT76r35Kt23u2XOqHXEFN7JkRi43Ztca868AGD GVAQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=FvpgK748xhyxYnR1DNtKCJNTGA6/YW+vy7WK8hafX4s=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=q1MIJ7HPbs3o/PVR4TvfrUI6J5ucVV/n8pxTnZAD1SnjqZ7QPdTLxztoFd1mJ5IUL2 4HqllZsHhpS7oA8/7TlELAlS3mX5ChQIyQdzYzrQz9Ezk4djImAjvUdTHu+yFe7BZZVG Y9fbPQbS619DC2g0G45QDQWpY1FYhLc37yudiRCF1iUd0niYAJP/9NOp9ii6EjnhX6x1 HXF6nUxNT0nhWr3rgwFhGydHjG1t/nwAWdUByle46Ah9PjPmOLZKekDlqM4F4Yd9ncGz FIqn3qPzo2X4wXUioEQmbncja6zLR+OTzmhdJLzqsb+L44KHynFBvoUcspGDUQepsGbR cbhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=X++0iks2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b00584a9290bd3si1646442pgb.522.2023.09.26.04.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:28:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=X++0iks2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id BA9E280A07D3; Tue, 26 Sep 2023 00:43:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233345AbjIZHnU (ORCPT + 99 others); Tue, 26 Sep 2023 03:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjIZHnS (ORCPT ); Tue, 26 Sep 2023 03:43:18 -0400 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 3141D92 for ; Tue, 26 Sep 2023 00:43:12 -0700 (PDT) Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 356786607314; Tue, 26 Sep 2023 08:43:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695714190; bh=yxiZWpVqxhEON5vsUHcs14H1MKuPG2laNGhIxvUFUj4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=X++0iks2Sjt4BtU3DuUWiNtZAp7n9eU5yx8gJaKnwb4In5KbopYEZE0UKDSqPsF5+ YhDie/npt0KcwKy8kcnAd4Bf7x/NT9Z8znqAZkl3mZlRRagGY+1QzDgwU8f15BvPnH CfbCB2Lstrng2Yg99mmdwvgjyh75mVkABdUNTE4+mG0oxoJpbbfPOhCkhYN4qoa3Qu IxJZ2YfRaAlApG7JPkaxHzPRAObFUjQ2s7aJ3vnbuD2U4J2wbmpBpD1YH0e0GJJqFc yLiwrg7p+77hHL2+ojmv/D1gRdB1P9+iyj+/TfPgC2C9kKTk6GDUurw3Dh+eZehSlZ axodwmk8Yezcw== Date: Tue, 26 Sep 2023 09:43:07 +0200 From: Boris Brezillon To: Dmitry Osipenko Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?UTF-8?B?S8O2bmln?= , 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 Subject: Re: [PATCH v17 13/18] drm/shmem-helper: Add memory shrinker Message-ID: <20230926094307.506f4b93@collabora.com> In-Reply-To: <64e8708a-bb73-96ae-90af-f7b51317613b@collabora.com> References: <20230914232721.408581-1-dmitry.osipenko@collabora.com> <20230914232721.408581-14-dmitry.osipenko@collabora.com> <20230915104633.0d5c3932@collabora.com> <64e8708a-bb73-96ae-90af-f7b51317613b@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 00:43:19 -0700 (PDT) On Tue, 26 Sep 2023 03:37:22 +0300 Dmitry Osipenko wrote: > On 9/15/23 11:46, Boris Brezillon wrote: > >> -static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem) > >> +static int > >> +drm_gem_shmem_acquire_pages(struct drm_gem_shmem_object *shmem, bool init) > >> { > >> struct drm_gem_object *obj = &shmem->base; > >> struct page **pages; > >> > >> dma_resv_assert_held(shmem->base.resv); > >> > >> - if (refcount_inc_not_zero(&shmem->pages_use_count)) > >> + if (shmem->madv < 0) { > >> + drm_WARN_ON(obj->dev, shmem->pages); > >> + return -ENOMEM; > >> + } > >> + > >> + if (shmem->pages) { > >> + drm_WARN_ON(obj->dev, !shmem->evicted); > >> return 0; > >> + } > >> + > >> + if (drm_WARN_ON(obj->dev, !(init ^ refcount_read(&shmem->pages_use_count)))) > >> + return -EINVAL; > > OOC, why do we care? Is there any difference between initial and re-pin > > that make the page allocation impossible? Feels like, if there's a > > check to do, it should be done in the caller instead, and you can drop > > the init param here. > > This is a sanity check that addresses additional refcnt tracking > complexity imposed by shrinker. > > This function is used by both init and re-pin that is invoked from > several places in the code. It's not trivial to move that check to the > callers. drm_gem_shmem_acquire_pages() is called twice, once with init=false, once with init=true. If you really care about this check, it can be moved to the callers so 1/ it's clearer (the XOR operation between init and refcount to check if refcount is zero on init and non-zero otherwise is convoluted) 2/ it doesn't leak to the function whose purpose it to [re-]acquire pages