Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2348629rwb; Mon, 15 Aug 2022 04:00:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR7HHRbCeeokLIp5r9CMk947Ekc0HYkshoaLXwv9X7Dl7SUuAY69I/yXKvTMIdrSIGKhF//3 X-Received: by 2002:a05:6402:1bc9:b0:43d:3903:11ee with SMTP id ch9-20020a0564021bc900b0043d390311eemr14312103edb.113.1660561231975; Mon, 15 Aug 2022 04:00:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1660561231; cv=pass; d=google.com; s=arc-20160816; b=mit2O588SFoBJs9gtO5ON1SK+aGlW+l5q9J633kacsDjL/rkYkps9CXawNYlWKKWWX Y60zZEnEdeEt7EME0fZeMAaUH6dF+MJnnPRtRp7lJ37QCeIOqRMOyOXG1LRcBQx7pPLV o39bLOJlEApxSTIuI0RdEY0ni5FOU18IYzWRJitI/Zj9x66uhkRn/uALixNXp4gLGD/X Ec1E10/JuWb3gQMTaSnO11tJhqwwdSZVBpIklWHMJfRZKyTdvHLWZkZbDp0XHNaAPNV2 1nPw9T6gscU8gBeQOdChbYx+hF5+p0pN69GqGYV+pxikMknqY7sQP8IgYNCQkgjyRFKH HN2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=NdEM7mASNWY/WlXxM2w5jqRvCc2RGprOJ3UxiIjEE2Y=; b=ofQEAkhh+hAnGboGVTk66edpvj8ZG8f9x6Asm5EtwHSlLSbJI8n1vXLHs/rzBH42hB lhV8xPNrilMoHK1rvMj+JmCB7yEs95q7hZrr+eTgyJ3h4ZjQn/Es3Sdqph6QUVDPAGuz x/nuAYMTirOiCGYzX1XWwIXAQ4nV7L1nFdjNEr7TW9VszjxbTIC2JByCvKOKWvewKv+Z +PIM0FBuUVf0mHmvW4EcnOl9w4g5tbUn5Metfm2Cw6O7SBWsxcm9XcSivgCx1xzHV/t2 pusHg0A88XeyZjRLC5CA5JIAw4prAWIwPuDYsruwwfTXkx5Oo+qWMwtNARAu9h1pfFaa T3cw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=I9yKjhHs; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa15-20020a1709076d0f00b00730551afa8esi8494678ejc.885.2022.08.15.04.00.06; Mon, 15 Aug 2022 04:00:31 -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=@amd.com header.s=selector1 header.b=I9yKjhHs; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242449AbiHOKmf (ORCPT + 99 others); Mon, 15 Aug 2022 06:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242410AbiHOKmd (ORCPT ); Mon, 15 Aug 2022 06:42:33 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2071.outbound.protection.outlook.com [40.107.237.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E7F21834; Mon, 15 Aug 2022 03:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nMXMlYTVAf4fMjy60KboL5eYpaz4+JDaiFTNqKwwbFKqezjiqv3WlfcJcTIt62cf304tBm/o40sFq/c7By54p8xgumhiymfZGwP8VdNgdyMztuAxJS4Hp9mzyOUq4KYAtDlrWj8yP1vf4SwZoXo3ut4c/2qSnwWeBs/KAkOBlyUcQ8j7BdAiqAkBFVs46QR8GOVVCTBnugQHZ+5g+X7kZeyqe5VRg2zKd1GWz2X7OX9tlbDOrKJhnzxs4VuznaiHk56Ioq8N4jKmgiAyAhSvEdLsqa37ztVwAS6T2eNrJYvhgEiEw+sW9IL5m/xtfHLjeOFbXUCbfBWuZRyCjNYu3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NdEM7mASNWY/WlXxM2w5jqRvCc2RGprOJ3UxiIjEE2Y=; b=Xr2tuAPUT06EbcVNCGb5/vKmR8fo3Lmxi3m7dCPQ3srRIgOX6K/SujQqNc6PVZuG4up+Dqg34o5h5ubGhzmHOUW9mjWCfxixwI5wwhhoTHtp8VAjCjLsdpL+Cvl8EaOqvosijRBYbXL+YceYhAODAdAY7lsjl/KuWrDcGxE7JRxTcmLYtiRp3g6uLX4f4zqGQ0ocXa3+3QL1u7gKykjgyIvsXvuMdpCcnNsL9/DMYrMY6l0w4Stb+g1YH3pwDZEy7juZmZu9c8DiRAjcQ0exw/cW8rZudawErkE2N9OxuHCqrsUb/7BHi4wxjUp3lln+fXEJMmu2vBfAORhHNkOb/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NdEM7mASNWY/WlXxM2w5jqRvCc2RGprOJ3UxiIjEE2Y=; b=I9yKjhHsTz3Ew70RRsxTIVNH/oea4+fhaSx8FGJPOK6qq7TSjEtdmpmojLhaqMbZWQYFLVPVjVeUgfRsorkYaMczwjv4Bs6iTg+6m5k7XHW/o97V1GLOKLMYzJ/+8T1Yaes3AVFMxkpNJE30Cxip/HbTTn/xM3Y738uk4EF7IlE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by DM4PR12MB6158.namprd12.prod.outlook.com (2603:10b6:8:a9::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Mon, 15 Aug 2022 10:42:29 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::905:1701:3b51:7e39]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::905:1701:3b51:7e39%2]) with mapi id 15.20.5504.020; Mon, 15 Aug 2022 10:42:28 +0000 Message-ID: <2e64c037-ee5a-0c60-5dba-2e48bb437014@amd.com> Date: Mon, 15 Aug 2022 12:42:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1] drm/ttm: Refcount allocated tail pages Content-Language: en-US To: Dmitry Osipenko , 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> <14be3b22-1d60-732b-c695-ddacc6b21055@collabora.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <14be3b22-1d60-732b-c695-ddacc6b21055@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: AS8PR04CA0209.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::34) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7de8b93-6189-4f70-ccba-08da7eaad995 X-MS-TrafficTypeDiagnostic: DM4PR12MB6158:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BDD2f3kXN0j78ISkvJTKvaYziZsdFefQugRGnwHkdK4YKYfIZiPYhm5SRCjA0CfWjudreATdcO8sisaO5yCxIxiQPiF1Jjf1zNS2JQAmk/VUV3i+CafXckXp6cvblnZ/FNcgRGZlLtG1Si88G3uYdBI+Gy3bmPUbT5kp2JBygpAXor9TryOXlxB+PFxPM/lXsofDIxyx+YnKs5RZ13R4l909QBocnPRRd/6L6k5TjkasmWLuyEtJZ7BEbsUW05UWmY+dnElwuU1JXVl97uiYP+ApfF997bnIoAfhAT/sdicVcN7XrIuQY95GV/P+d4G2daHz8I8X9kGggc5JTsARRRfdfNRT/Sp2sTlVk3j7PZBql7oo+NnCt67tMbpU/Mffe/zodlma+K9m7ljPJYeusqiCTvvfj6p6xxE6iwJQYBJ/CAirYwcOrrSLyPX7fr5GdNCclr3dvCBtGjxCHlkFiFgp1N8yy1llIRvBqO3tME165jtGkkr7Ms13zM+a+y6EsfuLLCgGpGz5eoBJRazROmbd5dsw5S0Gfdq8B1mEIr0N0zaxray7ABPZSCPa3fpyjx79KMuSUqxYuMH20KmcqkGFF/htCN60zWxgj5vVULmH7BCBrKIH0iW7nZA274XBkiiVcPie7yj8U6Emhv2286083zoVYfyoI9g17efWA5DAaAk4HRPkSZKqhVt0zmRDGmwjjWw8e+hMwBz4yiZsefJzsoNLKF7g9JCpG+pb6dDBMzZ/ZIg8CEqfU4DcRdmDougg73uJ6nswpJPKUcZJXEoYLgo6a4ZMgPIZbpaDen8jBgGmHf8GDfIDIAex994fhbaLSdYcKZqwWLH+xiJ73A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(366004)(396003)(346002)(39860400002)(136003)(2616005)(66574015)(186003)(83380400001)(6486002)(478600001)(41300700001)(38100700002)(7416002)(6666004)(5660300002)(316002)(110136005)(2906002)(8676002)(66556008)(53546011)(66946007)(6512007)(4326008)(6506007)(31696002)(36756003)(8936002)(31686004)(66476007)(86362001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?R0J0Tm5BRDB2WXZnWjB4MnBndmUvL0gxNTVMVlFRUWNHOFZZdEtSU1dac0pZ?= =?utf-8?B?bzJXMWdVcHNDMkc2MnUwdldocUxYdTd3MHVuakxTNkYzOU5NUy8wL1NVbi9j?= =?utf-8?B?d3pyalBlSjVZS1pYVlR6Q3dPdmltUjEvMEhJUk5jblcxT3lzODRBckszWHZI?= =?utf-8?B?RFIzc1paOGZFNTNRV2hjQnVMbjFBTllBOGZXL2xx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ditsSXFDSTFNWEVaNS9UR2JRaW96cm4rb1RGejhTVTZqVUErVmJSZVlob013?= =?utf-8?B?WURXV1BnVEtHTCtzMERSUFgyWVlOdTlzL0lHTURVZjBRYXNGSzNGSHJuNFNY?= =?utf-8?B?V0JZbXp4QVROZWtIaFVOZUtTNGYzZEIyRGNyVm5KTGdUTmExQUhEM21RbjZo?= =?utf-8?Q?/7EJIuQoqDnytSBLbzxqttYe/3ZQX7sqz1dz388IBcaA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7de8b93-6189-4f70-ccba-08da7eaad995 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 10:42:28.8859 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Vpg0KmSUOQ5zTLiowY8cdDJhWJPf+5Hlz7L0ez4awi7PQ7FBGKGtpoCg19GGe/Ej X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6158 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 Am 15.08.22 um 12:18 schrieb Dmitry Osipenko: > 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 :) Well exactly that's the problem. It does not work, you are just lucky :) I will provide a patch to set the reference count to zero even for non-compound pages. Maybe that will yield more backtrace to abusers of this interface. Regards, Christian. > > I'll try to dig out the older discussions, thank you for the quick reply! >