Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2334523rwb; Mon, 15 Aug 2022 03:39:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR6sPdFjoguEn20pxcP+/6Rei+ijBzFIJ5/2ePZtDFb/IdGYt2OjOOd7lfN7/hNMsbzKqf8C X-Received: by 2002:a17:907:d88:b0:730:d0bc:977a with SMTP id go8-20020a1709070d8800b00730d0bc977amr10428699ejc.664.1660559955948; Mon, 15 Aug 2022 03:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660559955; cv=none; d=google.com; s=arc-20160816; b=ivu2qPV4IHuHrLJXKJQlMcqe6d2EOVexAVcWmAMg0l6WJYhPv7b3MEQXUGh0f8ltdC cfYl5EoIlaBlAxmpan0mzy627c+9F+cm+gMEEwIfNuIKSKeFdwvzhtzJJVhAMaqO+FIM oN7F/LfLQ7Zp8IgoicVdmWRzI56FnST+UmJa0kXKVl8qNWM2H5ilbi67RQoDDOMh/xVK C26aSQs4aIWZxhq/lC3ozRFy7w25/11YioswytVSV96wU3+rmhcCWXit7XXY4HC/YA10 o2syDySukocDAfTE+TMmOX+7QFuwuD4J3ylTQ5AvcqFBkb1Smw9trhr9Isf2vRscm9vU 88EA== 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=S3eRSGYfpLiReyjPvRY0z4jjhSMq/Vw7T4IGs5rj4bU=; b=KkCM6XZPr14kyd/fzsn/E8VKY2P+CFa5Z+kXlKCaNsYHM7eWWL/Xq2kRtZNpBg9nG9 ybWNHTbne85txqcXOw0TFVJSE3tVelwU2IQdUXkjQZg+G1u+Punruyu2jWCQWMzUtdqu EMsf7NwTjyFnu0mv6dBEsKhEn28d85i3cheaWmmcTsiAt0MdYBVjIQcTdcFdhDi3hiqM rTD/VxV6tYwAta6d37pWCMzi4qFdMNzEEWok50CcKDqcBoFUg5oKSjR/b32bxD/aLXfG 0YAgCjaQz9Xde7xXPw0zM08hOBWkUkPH4NiHugWIa/4XEsQY/Ga2D8s1G1o3qGHzmkhy vMYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hgAo6gey; 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=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020a05640251c800b00440d768eb42si8999977edd.89.2022.08.15.03.38.49; Mon, 15 Aug 2022 03:39:15 -0700 (PDT) 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=hgAo6gey; 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=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241986AbiHOKSW (ORCPT + 99 others); Mon, 15 Aug 2022 06:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbiHOKSP (ORCPT ); Mon, 15 Aug 2022 06:18:15 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB574299; Mon, 15 Aug 2022 03:18:14 -0700 (PDT) Received: from [IPV6:2a00:5f00:102:0:10b3:10ff:fe5d:4ec1] (unknown [IPv6:2a00:5f00:102:0:10b3:10ff:fe5d:4ec1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8DF3B66016A1; Mon, 15 Aug 2022 11:18:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1660558693; bh=bt6zHiqFOssYaXdPmgRbYknys43UYciOnxf9yqFEAiI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hgAo6geyIhflayb4fSNhoE0iCQz9PLhgoSSF3k70UyLRnrFgpztGxMJg5NTLlbrHn Boy7/1AsUR7rYYjFtOzLYzOV0aaHSviLrmzom9aJdFWAtTnLlEH2YpbL4cKtSXt5dl e5IgECy+yDiKVh5hx4Rct6WzBM78FtN1fTxgnm48704p8dhndVSPuzKi89qJ5/PyjR /33/QfZmcYn0KcI7HU9fVdZKdQChWY++Jn2YlT7UkydJatUawuEud1tdsAPQcEHwB8 KaR4zimR74GNPao0P+Y/5iMGrQO7UCmhRPCO89DBM92q7hvRscTboHWQHSKTH6wkxm r9kAFPouLjDVA== Message-ID: <14be3b22-1d60-732b-c695-ddacc6b21055@collabora.com> Date: Mon, 15 Aug 2022 13:18:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v1] drm/ttm: Refcount allocated tail pages Content-Language: en-US To: =?UTF-8?Q?Christian_K=c3=b6nig?= , David Airlie , Huang Rui , Daniel Vetter , Trigger Huang , Gert Wollny , Antonio Caggiano Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , kvm@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org References: <20220815095423.11131-1-dmitry.osipenko@collabora.com> <8230a356-be38-f228-4a8e-95124e8e8db6@amd.com> <134bce02-58d6-8553-bb73-42dfda18a595@collabora.com> <8caf3008-dcf3-985a-631e-e019b277c6f0@amd.com> <4fcc4739-2da9-1b89-209c-876129604d7d@amd.com> From: Dmitry Osipenko In-Reply-To: <4fcc4739-2da9-1b89-209c-876129604d7d@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 8/15/22 13:14, Christian König wrote: > Am 15.08.22 um 12:11 schrieb Christian König: >> Am 15.08.22 um 12:09 schrieb Dmitry Osipenko: >>> On 8/15/22 13:05, Christian König wrote: >>>> Am 15.08.22 um 11:54 schrieb Dmitry Osipenko: >>>>> Higher order pages allocated using alloc_pages() aren't refcounted and >>>>> they >>>>> need to be refcounted, otherwise it's impossible to map them by >>>>> KVM. This >>>>> patch sets the refcount of the tail pages and fixes the KVM memory >>>>> mapping >>>>> faults. >>>>> >>>>> Without this change guest virgl driver can't map host buffers into >>>>> guest >>>>> and can't provide OpenGL 4.5 profile support to the guest. The host >>>>> mappings are also needed for enabling the Venus driver using host GPU >>>>> drivers that are utilizing TTM. >>>>> >>>>> Based on a patch proposed by Trigger Huang. >>>> Well I can't count how often I have repeated this: This is an >>>> absolutely >>>> clear NAK! >>>> >>>> TTM pages are not reference counted in the first place and because of >>>> this giving them to virgl is illegal. >>> A? The first page is refcounted when allocated, the tail pages are not. >> >> No they aren't. The first page is just by coincident initialized with >> a refcount of 1. This refcount is completely ignored and not used at all. >> >> Incrementing the reference count and by this mapping the page into >> some other address space is illegal and corrupts the internal state >> tracking of TTM. > > See this comment in the source code as well: > >         /* Don't set the __GFP_COMP flag for higher order allocations. >          * Mapping pages directly into an userspace process and calling >          * put_page() on a TTM allocated page is illegal. >          */ > > I have absolutely no idea how somebody had the idea he could do this. I saw this comment, but it doesn't make sense because it doesn't explain why it's illegal. Hence it looks like a bogus comment since the refcouting certainly works, at least to a some degree because I haven't noticed any problems in practice, maybe by luck :) I'll try to dig out the older discussions, thank you for the quick reply! -- Best regards, Dmitry