From patchwork Sat Dec 7 10:50:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Julia" X-Patchwork-Id: 13898240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85D2BE7717D for ; Sat, 7 Dec 2024 10:52:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.850611.1265002 (Exim 4.92) (envelope-from ) id 1tJsQI-0007i4-Mn; Sat, 07 Dec 2024 10:52:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 850611.1265002; Sat, 07 Dec 2024 10:52:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJsQI-0007hx-Jn; Sat, 07 Dec 2024 10:52:30 +0000 Received: by outflank-mailman (input) for mailman id 850611; Sat, 07 Dec 2024 10:52:29 +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 1tJsQH-0007hr-Q8 for xen-devel@lists.xenproject.org; Sat, 07 Dec 2024 10:52:29 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20615.outbound.protection.outlook.com [2a01:111:f403:2416::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 59305827-b489-11ef-a0d5-8be0dac302b0; Sat, 07 Dec 2024 11:52:28 +0100 (CET) Received: from CH2PR18CA0023.namprd18.prod.outlook.com (2603:10b6:610:4f::33) by SA1PR12MB8119.namprd12.prod.outlook.com (2603:10b6:806:337::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Sat, 7 Dec 2024 10:52:21 +0000 Received: from CH2PEPF00000140.namprd02.prod.outlook.com (2603:10b6:610:4f:cafe::e1) by CH2PR18CA0023.outlook.office365.com (2603:10b6:610:4f::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Sat, 7 Dec 2024 10:52:17 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000140.mail.protection.outlook.com (10.167.244.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Sat, 7 Dec 2024 10:52:17 +0000 Received: from jenkins-julia.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Sat, 7 Dec 2024 04:52:12 -0600 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: 59305827-b489-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SlvR02hKEYgqecz9uAmyFruuuJEldYY2K2oz+/k5/jqjqpwPKQfUekkQnKpKc0mv47KjjSDn5v3O8r9YTLPVkoPPb9/G+6XTMomnrEcTj5GQsS6e192FtrDO7GkFSAFyQSC/OQWj91In3QSsJtaVT1AKBEd36cz3Fu82oI+5bS7gwSdydokkMCNTYErfx2ux2MaOIjQXjaJ08NBcgaGRqSmpxZXg6/pkx+R4+L1mQrOieMfb/vdloLoiUZWXiaLMBfwxZZUGLMpCBni2fZq51v2vLI6XpbBKtjYMrNtZNVCBAejqdJ1NhscRbY+L8ORvxJ6TXTui1AbXnfnokMt5Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=3z7f/RAhcwAHkXYmUepiHSK25Jlz0SNuaumnbydHfcc=; b=XlfTi3mH4Fu7BLO+vkBCMu3xvYGm6vgCBpORbxO6uetUBPOnJUCPXsVoRN9hAzESvASBLDkj9keVMZ5hZEEF44d07GiauQALwQ2z46YuxTMREhaX/AA6dHuKHaXk89xXNOMKyfJYsAeqjePQat0rhGYI4mVtW+xsXbK9L+nvjoQOuf0jWcxkLda+dh4iKu53eSJS9ICPx/FaI+farccp6Ff+YQBkgJ9wr2QrWCpyNJlGklAuMeYpiFk5/x/wL75nHL5EEo+Ff7lTeczp03qGeU9rLQjUvmdGCnOQLkEZo62sFNtpLCJSLILIN4Q/OMX5SldaAXxl+fRAG6kpeDaRiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=3z7f/RAhcwAHkXYmUepiHSK25Jlz0SNuaumnbydHfcc=; b=Xhugr7oUoK1G6fhyrFgCD8kKP0JKFbNK8HWiq5awZ+LF78bVE7ecksUnCnTbU2V9FHJWLVvxFbcNHp1Aayufp8LyPu/WeA3ByXk2jKNMkgFpx4BujnF+mz9ZXjYYVXJyt0S4ygh+kXeIQnyghBYYRI3PxFIEvj/ogHTPjTpNVMk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Julia Zhang To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , , , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , CC: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Chen Jiqian , Huang Rui , Penny Zheng , Zhu Lingshan , Anthony PERARD , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Paul Durrant , Julia Zhang Subject: [PATCH 1/3] xen:get p2pdma_distance Date: Sat, 7 Dec 2024 18:50:22 +0800 Message-ID: <20241207105023.542399-2-julia.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241207105023.542399-1-julia.zhang@amd.com> References: <20241207105023.542399-1-julia.zhang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000140:EE_|SA1PR12MB8119:EE_ X-MS-Office365-Filtering-Correlation-Id: ecae0a17-be8f-4c2e-da1a-08dd16ad37e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: DU1i4lB89NXMg++EWvDHebP0wVGJ0sI3UJ+iKv+sVi2uSJTyV7UjIJZzESkhxsJ8sDlpy+OZD0o9cptA0TCn+aMbZV6P/W0WEbxeG+GyGGVKv2sTHBzY6/L4qlIkhb9h23QT03iB6e3cTwxsdMANV5LmdvrX/iU/1hdj7uqDyVU6dC8vbAVAZmIcPs7aoGEl04/3GUX1tJ6qrAqFTO2pY27wKQDq/fBX1lTBZorHVP/d9gYlExJ1flL3I//ikRm3tXRVRmgH6Kb3lWLYjdR4qRLPP94oEbva+3Tp0599kx97Xhsh2Qw6QACwe9m7zhRmmkWvkmVOVXciQMyhLdGZ7R20Nf9t6Tu5Vf8TJrtiPaV/HoSAF5vTSzlz/Jm9sLe8jUDkH08Z6AxDJLJs7tbfDWvb2K1y7ArN94kQC69eZuNwA90xnKKeFxyPDgfBCF9FnmFK5sRo/i05kPzqiMisbGw5Or528oGuc18U5xwrpt3JDT5283MDFGV9SmKUo77dFIX4Eao6BYOs45Fjw2Z+QrxSNzihcNSEb31XUiJvK5SDH0PuiLRP+rL6SRc4IVssKtqAlz9kgxUaNlk2FMEJNoswyrK8PO+TG+EGemGeM1Gv/F16g1CK8PI9N/ccTcTubHl8BZjqhpT8X6161bQFJejXn6NT5kD7yK3hWholwbsIltzvYrr0y4zxDMiyd+W5Uv4uGE+cmhFnXcVvyh1ldoTqhBPdKHnWboNonA4a64gKYFPbiPLhtbbGrqM/Lv89gLYf3xfTb8kUvVG37IKT+NsgVa7FVb0wdMX/IiYkWpQXgSWlBX/pkae8in/uUdJdCjDk/gINX66mcdX8hixyjuYdUmS3+BDvrCmYpi9HHvpiy5EqreGTESGXWHcJzfkUFWEyM9ffIUkbYpYunh8dAeMfvVaLJ8oo28jsL6uF6QAcm3tSQOlG1X/+GPgEp+WvLHCI9rD2IMYpzfLp3Gkf0hNCUqrvFf08D3nGxcNKbprMfHG/spMbf3+TKgMx2IhZnamIevGEMPzYrUxVb1x1nUWmNCWmsjGyg/I8lOGBYjvwo1bM0qt5hJnc0dUaOjbcbHVN13tJatnu5DGNTZeuWNUpwU0vF0nZQMnAO8NXvEKAqxeb/ImOeDeY+ySEiq8y6fDk0k1XfFoSj8jd4Rogc0Twgnc4VSwtbHQnjwz0DFhJrNVWcZgl1OwjDxnoJzaCuIO6Cs1vJN6rfNY4blVg4LULy5DReVMhvIt02rkQ1Ar12M9mz4JIGW5aihL/uqcJcunjw8teB/pye7C8lEU1q22Rg6dkk9myvjR25kfTNls6CNN9MQaTawR5eKwxk5Swh1wpK6qXlgbV6A22HwhFqqyX4uZHRh/KLlqVm/5UImk5FQbyJ0hBavBj9WWDCshUqoYmxdnBCSzF+6zwLxTgZIBpeCTa93TAWwrhuWzEMU2uI7/F5U8Gbg3Munkp3msIzRIVpP12qLxzo3KgODkpMA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2024 10:52:17.8242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecae0a17-be8f-4c2e-da1a-08dd16ad37e1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000140.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8119 To get the p2pdma_distance, this create a new privcmd ioctl to calculate p2pdma_distance for two pci devices on the host with pci notations sent from guest virtgpu driver. Signed-off-by: Julia Zhang --- drivers/xen/privcmd.c | 42 ++++++++++++++++++++++++++++++++++++++ include/uapi/xen/privcmd.h | 12 +++++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 72c161e94731..95f67815a2ef 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include #include @@ -977,6 +980,42 @@ static long privcmd_ioctl_map_hva_to_gpfns(struct file *file, void __user *udata return ret; } +static int privcmd_ioctl_p2pdma_distance(struct file *file, void __user *udata) +{ + struct privcmd_p2pdma_distance kdata; + struct pci_dev *provider = NULL; + struct pci_dev *client = NULL; + struct pci_dev *dev = NULL; + enum pci_p2pdma_map_type map; + + if (copy_from_user(&kdata, udata, sizeof(kdata))) + return -EFAULT; + + for_each_pci_dev(dev) { + if (dev->bus->number == kdata.provider_bus && + dev->devfn == PCI_DEVFN(kdata.provider_slot, kdata.provider_func)) { + provider = dev; + } else if (dev->bus->number == kdata.client_bus && + dev->devfn == PCI_DEVFN(kdata.client_slot, kdata.client_func)) { + client = dev; + } else { + continue; + } + } + + if (!provider || !client) { + pr_err("%s fail to get provider or client.\n", __func__); + return -EINVAL; + } + + kdata.distance = pci_p2pdma_distance(provider, &client->dev, false); + + if (copy_to_user(udata, &kdata, sizeof(kdata))) + return -EFAULT; + + return 0; +} + #ifdef CONFIG_XEN_PRIVCMD_EVENTFD /* Irqfd support */ static struct workqueue_struct *irqfd_cleanup_wq; @@ -1684,6 +1723,9 @@ static long privcmd_ioctl(struct file *file, ret = privcmd_ioctl_map_hva_to_gpfns(file, udata); break; + case IOCTL_PRIVCMD_P2PDMA_DISTANCE: + ret = privcmd_ioctl_p2pdma_distance(file, udata); + break; default: break; diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index d131002dd48f..a7ec3704519f 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -141,6 +141,16 @@ struct privcmd_map_hva_to_gpfns { int add_mapping; }; +struct privcmd_p2pdma_distance { + __u32 provider_bus; + __u32 provider_slot; + __u32 provider_func; + __u32 client_bus; + __u32 client_slot; + __u32 client_func; + __u32 distance; +}; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -174,6 +184,8 @@ struct privcmd_map_hva_to_gpfns { _IOW('P', 9, struct privcmd_ioeventfd) #define IOCTL_PRIVCMD_PCIDEV_GET_GSI \ _IOC(_IOC_NONE, 'P', 10, sizeof(struct privcmd_pcidev_get_gsi)) +#define IOCTL_PRIVCMD_P2PDMA_DISTANCE \ + _IOC(_IOC_NONE, 'P', 11, sizeof(struct privcmd_p2pdma_distance)) #define IOCTL_PRIVCMD_MAP_HVA_TO_GPFNS \ _IOC(_IOC_NONE, 'P', 13, sizeof(struct privcmd_map_hva_to_gpfns)) From patchwork Sat Dec 7 10:50:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Julia" X-Patchwork-Id: 13898241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06FF3E7717D for ; Sat, 7 Dec 2024 10:53:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.850620.1265011 (Exim 4.92) (envelope-from ) id 1tJsRE-0008HB-Vo; Sat, 07 Dec 2024 10:53:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 850620.1265011; Sat, 07 Dec 2024 10:53:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJsRE-0008H4-Sp; Sat, 07 Dec 2024 10:53:28 +0000 Received: by outflank-mailman (input) for mailman id 850620; Sat, 07 Dec 2024 10:53:28 +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 1tJsRD-0007hr-Vj for xen-devel@lists.xenproject.org; Sat, 07 Dec 2024 10:53:28 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20620.outbound.protection.outlook.com [2a01:111:f403:2009::620]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7c5ef923-b489-11ef-a0d5-8be0dac302b0; Sat, 07 Dec 2024 11:53:27 +0100 (CET) Received: from CH0PR03CA0393.namprd03.prod.outlook.com (2603:10b6:610:11b::21) by CY5PR12MB6060.namprd12.prod.outlook.com (2603:10b6:930:2f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.24; Sat, 7 Dec 2024 10:53:20 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::c8) by CH0PR03CA0393.outlook.office365.com (2603:10b6:610:11b::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Sat, 7 Dec 2024 10:53:20 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Sat, 7 Dec 2024 10:53:19 +0000 Received: from jenkins-julia.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Sat, 7 Dec 2024 04:53:14 -0600 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: 7c5ef923-b489-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S3SgNuJloh2w7NsWi+dU6TBIPFnYbNUmssk0veB2tuuBEkL3QffELJL3sOfFuiS0rSLjirXmOcaE49zHPPJ/dtQaDcyaSxEXCYben+ToimaSCVicZ8aUHnAuGo1k6CW3hv2Ggdsk0Fqn/z797tOtPAzlFNgYkp1XAJc0duTodzG1YBrwdMyB/hSNb6o4A6gPnPGsc8nfk9LgQwrHA2cZST1vnFHjs1ZytPCeDj1uVGgh/RzmMhCLXkIdUFQHDY7NmG5a4O3B+H3+NP42Fe+3A18bd5tTfZvbMCuhA2MNs/5+pGUAxUSdCUZycfZUnVKOnTvyiRfb4H62HCct3XHHvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=5cr/hCklb5oOa6uHklyD3rH+9Dy9jZjPa3XjRYdjDB4=; b=fUjCbtjZaPJRPX9eT7y2fM/rx5dj0rps+kBlBJ/QU3U43IgAb4KcI/5BeAETol4E5JvJeKZxTxKFmnsR379W+WSQ/V7yaqofpRWNL1eK7Xct94nmN2sFKYCgiyg7nGBA2F6aqaCFBSwDB2NMcCCmMKywJJE37J3jawfj5YrsfcKKwKXET7lAVUyaUdAbgSH5AnwtiggwR+gLZys6XtmcERdXEUCWImAqVwZ3bOPkpSL4bPAmCWAaO2fS021XsycAviUs4FVmFfflRcJOVAiCBrsuU+mkAvsqMWPvb693IwHRLMTGvxttof83WbxS8iGuadjyXplhsLPQsU/ukmZhbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=5cr/hCklb5oOa6uHklyD3rH+9Dy9jZjPa3XjRYdjDB4=; b=YeLBTl+N+bwMF6SyPsYGEBI2UVB8ERc5fw12gv/RbKlEtro4JhTra08+C09GSej+yv00egzNcYvnYJZmwTRoRtO+hCwfGIJEr7hy/v7nfwwvOmtIrAZGbqyXmHi3ZC0HP4KW5iObolh1+52RRxaYBpeE9K1f1RpFMHsXFaWPuPo= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Julia Zhang To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , , , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , CC: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Chen Jiqian , Huang Rui , Penny Zheng , Zhu Lingshan , Anthony PERARD , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Paul Durrant , Julia Zhang Subject: [PATCH 2/3] virtgpu: get p2pdma_distance Date: Sat, 7 Dec 2024 18:50:24 +0800 Message-ID: <20241207105023.542399-3-julia.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241207105023.542399-1-julia.zhang@amd.com> References: <20241207105023.542399-1-julia.zhang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000141:EE_|CY5PR12MB6060:EE_ X-MS-Office365-Filtering-Correlation-Id: 384bd968-5a51-4c15-8272-08dd16ad5cdb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: xl0uOfUoHWJiimtLuJyJGWveCUw234A8KbbNeuLTEzB07oxaVkIS40rRHKOS1lhOFoKgM6XR80EOvSzB6Cx0J2BV5qhVSXdE13cjNsHyJctIh1O/jV2kUQcRCpRxoGyTrqnrl2AjUhNX5hYwBdPtJrzbHZQyqAGjvUTN/2GQtFp5htF4pFBmzIdnNTDLgEcWye22apRsMK/gjWoma/WppMd8d7oNqoV0QyRRT1cvJZJPAHFfP1jYxDXQPxnTVTWEnRpcGOQluwvKKKID43byi7CBK0sCs04SuOczhJVCqUbrQiZninOOlZljjQ8gtpAE37jJJSy7hQtf81Ay+b+tWSzQH5YLIXavWnBnH5pWKWSOOTJ3mE1n1rhTFvJclxZggULyi7o0sFBrzduY9HqOtw1jYExmTSWPH/D2vxgvwQDAyMe3ebEcAuVFOfVJcjz5tKO3ASCHMLm9CupV/l3kURyaPpZL4W6Aey1pbYWhRum6xqBuUrhzugsoed6UEFtr5RtLZuqpkXCtmg326/e1hJypOqbB7Q2+Hx0X6jJ9cS9SVFglh/IxVbNrZQl37qr3ZkoAqBkhz68trGf84graU2xfVnif/NhovgNj8GMRaKkySqQ5+Dv6XKPfPK9VGlNdERaSuGDNte/gGkXdD0lIe7QhqfA43YHK3ptr5y+ngnRh+oL+MCYZ1li/fRwFSZ+BXheLjh4u02a+0WZhnjSPKzZkgNf8ZE8omplAW9Hyu2tNPqnW8olGeHKXFj60KtSZO3eX9NJd042mKuT8Pw02U+LSPFGMrlurYh/nzwFzv2FbHOYWnp2v2ExD27tuC0GVyWzItFrU+aQwwrlLabshqPMYzvCTneUZwYesovQPh0rj980PCU9oTbtzVB0i8Ni4RZWDWjZgdyRi+QspIRacXtZUjntdzs175B2McHdcijbMFW5tgQkIhkEZaxtolzl0RP20Q+10s2jOqRX5UrfweHnAzU/W+b4S6p0c1TvP2kcV5MqKN4C7TfTeLIJHye/kiAkAjNolFe3oa+CiENI7tOdN8rzn9wl1fYaa1MZVTfZBatvFvPTzXdKMcJEWwAOPnc35fkjNUIIEeJFU0DswXsqVlwTIJkFVZZhNPxYYDsIcsnFd6lMwH2UJyH6ubNs9w9l9p/sqEUDTkj4A6LmN+gHRMjBXEWflzbtw4dau6FJLLNoYmiN4fHsjjGHJ52kevmx7KJzhqIbN0ROI6fXvo6Mf/nWSOu4ZDRpvR75MfqWPYA6hZdoFZcjiDPeQ5O56tyctUENqQt7okMlJGaGWeatN29FGlsxyKyPRo525flc7ksflnKziJA6/Kw+nSwlj9pudlt/S51VBJnn7IBWhMX/HvD/CR928+lwWOasFCuerAYeYp1VUEpVO1FR25yTwYF/hGpAT0KCN/+2oBXemafti61EI2Fe+FcphdFQJK2LAzCsu+a+NlzO5OZ80D1/g34h5ReOzitZ96cdR20Pqig== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2024 10:53:19.8740 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 384bd968-5a51-4c15-8272-08dd16ad5cdb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6060 virtgpu driver need to get the p2pdma_distance to decide if virtio iGPU buffer can be imported by passthrough dGPU, which is the main step implement dGPU prime feature. To get the p2pdma_distance, this create a new virtgpu ioctl to send command of getting p2pdma_distance and pci notations of two pci devices from guest to host. Host will handle ioctl to calculate p2pdma_distance for this two pci devices on the host with pci notations sent from guest virtgpu driver. Signed-off-by: Julia Zhang --- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 +++++++++ drivers/gpu/drm/virtio/virtgpu_prime.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_vq.c | 53 ++++++++++++++++++++++++++ include/uapi/linux/virtio_gpu.h | 19 +++++++++ 4 files changed, 134 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 64c236169db8..1bbe510c8410 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -87,6 +87,18 @@ struct virtio_gpu_object_params { uint64_t blob_id; }; +struct virtio_gpu_pci_notation { + uint32_t bus; + uint32_t slot; + uint32_t func; +}; + +struct virtio_gpu_p2pdma_distance { + atomic_t p2pdma_state; + uint32_t distance; +}; + + struct virtio_gpu_object { struct drm_gem_shmem_object base; uint32_t hw_res_handle; @@ -488,4 +500,9 @@ void virtio_gpu_vram_unmap_dma_buf(struct device *dev, int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, struct drm_file *file); +int virtio_gpu_cmd_p2pdma_distance(struct virtio_gpu_device *vgdev, + struct virtio_gpu_pci_notation *provider_params, + struct virtio_gpu_pci_notation *client_params, + struct virtio_gpu_p2pdma_distance *p2pdma_dist); + #endif diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c index 44425f20d91a..4960620eba02 100644 --- a/drivers/gpu/drm/virtio/virtgpu_prime.c +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include "virtgpu_drv.h" @@ -71,6 +73,49 @@ static void virtgpu_gem_unmap_dma_buf(struct dma_buf_attachment *attach, drm_gem_unmap_dma_buf(attach, sgt, dir); } +static int virtgpu_get_p2pdma_distance(struct dma_buf *dma_buf, + struct dma_buf_attachment *attach) +{ + struct drm_gem_object *obj = attach->dmabuf->priv; + struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj); + struct drm_device *dev = obj->dev; + struct pci_dev *pdev = to_pci_dev(dev->dev); + struct pci_dev *pci_client; + struct virtio_gpu_pci_notation provider_params = {0}; + struct virtio_gpu_pci_notation client_params = {0}; + struct virtio_gpu_device *vgdev = dev->dev_private; + struct virtio_gpu_p2pdma_distance p2pdma_dist = {0}; + int ret = 0; + + attach->peer2peer = false; + if (pci_p2pdma_distance(pdev, attach->dev, false) < 0) + return 0; + + provider_params.bus = pdev->bus->number; + provider_params.slot = PCI_SLOT(pdev->devfn); + provider_params.func = PCI_FUNC(pdev->devfn); + pci_client = to_pci_dev(attach->dev); + client_params.bus = pci_client->bus->number; + client_params.slot = PCI_SLOT(pci_client->devfn); + client_params.func = PCI_FUNC(pci_client->devfn); + ret = virtio_gpu_cmd_p2pdma_distance(vgdev, &provider_params, &client_params, &p2pdma_dist); + if (ret) + return ret; + + ret = wait_event_timeout(vgdev->resp_wq, + atomic_read(&p2pdma_dist.p2pdma_state), + 5 * HZ); + if (!ret) + return -EBUSY; + + smp_rmb(); + + if (p2pdma_dist.distance >= 0) + attach->peer2peer = true; + + return 0; +} + static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .ops = { .cache_sgt_mapping = true, diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 0d3d0d09f39b..69c33df61b88 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -1197,6 +1197,28 @@ static void virtio_gpu_cmd_resource_map_cb(struct virtio_gpu_device *vgdev, wake_up_all(&vgdev->resp_wq); } +static void virtio_gpu_cmd_p2pdma_distance_cb(struct virtio_gpu_device *vgdev, + struct virtio_gpu_vbuffer *vbuf) +{ + struct virtio_gpu_resp_distance *resp = + (struct virtio_gpu_resp_distance *)vbuf->resp_buf; + struct virtio_gpu_p2pdma_distance *p2pdma_dist = vbuf->resp_cb_data; + + vbuf->resp_cb_data = NULL; + + if (resp->hdr.type != VIRTIO_GPU_RESP_OK_P2PDMA_DISTANCE) { + atomic_set(&p2pdma_dist->p2pdma_state, 0); + goto out; + } + + p2pdma_dist->distance = le32_to_cpu(resp->distance); + smp_wmb(); + atomic_set(&p2pdma_dist->p2pdma_state, 1); + +out: + wake_up_all(&vgdev->resp_wq); +} + int virtio_gpu_cmd_map(struct virtio_gpu_device *vgdev, struct virtio_gpu_object_array *objs, uint64_t offset) { @@ -1223,6 +1245,37 @@ int virtio_gpu_cmd_map(struct virtio_gpu_device *vgdev, return 0; } +int virtio_gpu_cmd_p2pdma_distance(struct virtio_gpu_device *vgdev, + struct virtio_gpu_pci_notation *provider_params, + struct virtio_gpu_pci_notation *client_params, + struct virtio_gpu_p2pdma_distance *p2pdma_dist) +{ + struct virtio_gpu_device_p2pdma_distance *cmd_p; + struct virtio_gpu_vbuffer *vbuf; + struct virtio_gpu_resp_distance *resp_buf; + + resp_buf = kzalloc(sizeof(*resp_buf), GFP_KERNEL); + if (!resp_buf) + return -ENOMEM; + + cmd_p = virtio_gpu_alloc_cmd_resp + (vgdev, virtio_gpu_cmd_p2pdma_distance_cb, &vbuf, sizeof(*cmd_p), + sizeof(struct virtio_gpu_resp_distance), resp_buf); + memset(cmd_p, 0, sizeof(*cmd_p)); + + cmd_p->hdr.type = cpu_to_le32(VIRTIO_GPU_CMD_P2PDMA_DISTANCE); + cmd_p->provider_bus = cpu_to_le32(provider_params->bus); + cmd_p->provider_slot = cpu_to_le32(provider_params->slot); + cmd_p->provider_func = cpu_to_le32(provider_params->func); + cmd_p->client_bus = cpu_to_le32(client_params->bus); + cmd_p->client_slot = cpu_to_le32(client_params->slot); + cmd_p->client_func = cpu_to_le32(client_params->func); + vbuf->resp_cb_data = p2pdma_dist; + + virtio_gpu_queue_ctrl_buffer(vgdev, vbuf); + return 0; +} + void virtio_gpu_cmd_unmap(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo) { diff --git a/include/uapi/linux/virtio_gpu.h b/include/uapi/linux/virtio_gpu.h index bf2c9cabd207..18313cffaa62 100644 --- a/include/uapi/linux/virtio_gpu.h +++ b/include/uapi/linux/virtio_gpu.h @@ -95,6 +95,7 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_CMD_SUBMIT_3D, VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB, VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB, + VIRTIO_GPU_CMD_P2PDMA_DISTANCE, /* cursor commands */ VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300, @@ -108,6 +109,7 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_RESP_OK_EDID, VIRTIO_GPU_RESP_OK_RESOURCE_UUID, VIRTIO_GPU_RESP_OK_MAP_INFO, + VIRTIO_GPU_RESP_OK_P2PDMA_DISTANCE, /* error responses */ VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200, @@ -429,6 +431,23 @@ struct virtio_gpu_set_scanout_blob { __le32 offsets[4]; }; +/* VIRTIO_GPU_CMD_P2PDMA_DISTANCE */ +struct virtio_gpu_device_p2pdma_distance { + struct virtio_gpu_ctrl_hdr hdr; + __le32 provider_bus; + __le32 provider_slot; + __le32 provider_func; + __le32 client_bus; + __le32 client_slot; + __le32 client_func; +}; + +/* VIRTIO_GPU_RESP_DISTANCE */ +struct virtio_gpu_resp_distance { + struct virtio_gpu_ctrl_hdr hdr; + __le32 distance; +}; + /* VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB */ struct virtio_gpu_resource_map_blob { struct virtio_gpu_ctrl_hdr hdr; From patchwork Sat Dec 7 10:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Zhang, Julia" X-Patchwork-Id: 13898246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42BCCE7717B for ; Sat, 7 Dec 2024 10:54:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.850625.1265022 (Exim 4.92) (envelope-from ) id 1tJsRf-0000HX-8R; Sat, 07 Dec 2024 10:53:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 850625.1265022; Sat, 07 Dec 2024 10:53:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJsRf-0000HQ-4Q; Sat, 07 Dec 2024 10:53:55 +0000 Received: by outflank-mailman (input) for mailman id 850625; Sat, 07 Dec 2024 10:53:53 +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 1tJsRd-0007hr-L9 for xen-devel@lists.xenproject.org; Sat, 07 Dec 2024 10:53:53 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20605.outbound.protection.outlook.com [2a01:111:f403:240a::605]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b6dc2c4-b489-11ef-a0d5-8be0dac302b0; Sat, 07 Dec 2024 11:53:53 +0100 (CET) Received: from CH0P223CA0030.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::6) by CH3PR12MB7572.namprd12.prod.outlook.com (2603:10b6:610:144::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Sat, 7 Dec 2024 10:53:45 +0000 Received: from CH2PEPF0000013C.namprd02.prod.outlook.com (2603:10b6:610:116:cafe::4) by CH0P223CA0030.outlook.office365.com (2603:10b6:610:116::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.12 via Frontend Transport; Sat, 7 Dec 2024 10:53:45 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF0000013C.mail.protection.outlook.com (10.167.244.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Sat, 7 Dec 2024 10:53:44 +0000 Received: from jenkins-julia.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Sat, 7 Dec 2024 04:53:39 -0600 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: 8b6dc2c4-b489-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p0ySH/xYkkF4lPN3bgTVsYZ/pjYLaN59aqVfBy34DJt1UJSAoe8lZpePXZAyZP3ZLtJIYACtJUgLf8Fd/SjiMjS4f4Cdw2+FQQ910r7hW2Mt1JAyYUyk3T+UI8HXxCfxMcddWP9wow/NpfGHPSXjIhG7IfEcTp16U4TpVL2vnnEsyP2AJH5ifTJSDloLYdzJ5mRWwC2ZE7xe2Xw4TLCLp6mWdW9fU19CcMXiUfgd23fykpya5J60X+y6lGkjcsKDXe0S+UGXIUDgdNajOWiEV3/KzA3JmpMkV9rNdd7+uInd0yLOckylnhr4Nc+nOytaKLTIm2I965pHpas5qoHoGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4ZkFtwcnYM2i/536XZMFv1NpvRLzNT6/8HZOgNw9APU=; b=IYYvzvc5qsR9GbQ0hGPfhNvHnebbOO5yTGBEPN1VZOqoGS8Nxw21XxNAmaVy+BqHlA6qnRCyMe9DD0z0cPEZaPrryUtEXUkdQKc9F6XFQDuVrWMSjcEuiZ0ykCxuN7oFd8au6/JPasHHzVXmzD8+NqNUzqyLBa7ZgBE9jshWQlwatA6jQIYYy/PYcq8t53Xijkx5vAOXR8w+EsSTAFDBARV+43DTHIvhGsXt5/WE8EvQUcERDuvuwhZCeJ7zJi2hgzpf2IKrb24sgdsNYiySnnbGoiATWBjgcssBQua9RHnhbgwQ556/ZX4RZGb7jgcA36C2v5sij/JiQWeJhPU+uQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=4ZkFtwcnYM2i/536XZMFv1NpvRLzNT6/8HZOgNw9APU=; b=YuZrRdDw32Gd5l4UpvOeTbHLgD56QTO10INg3o3T+Ac2L8srAH9J9EgJYQKOSpetZbPfpsvwu5jfTVlQ6KyyK+2knrpfzwW/ggvR0tKcfKrhGeIWpIg6foCzqs5e/Qv+tPzCRsfAdLUqXGZFCnMiYhUmv2kSdzfqdIBxPFJ1d9c= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Julia Zhang To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , , , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , CC: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Daniel Vetter , Chen Jiqian , Huang Rui , Penny Zheng , Zhu Lingshan , Anthony PERARD , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Paul Durrant , Julia Zhang Subject: [PATCH 3/3] drm/virtio: Implement device_attach Date: Sat, 7 Dec 2024 18:50:26 +0800 Message-ID: <20241207105023.542399-4-julia.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241207105023.542399-1-julia.zhang@amd.com> References: <20241207105023.542399-1-julia.zhang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000013C:EE_|CH3PR12MB7572:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d46a6a5-b8b5-453d-7fe6-08dd16ad6bca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: 2wKtCKDtVexDsiIbKn+FuNmPsOgS/VWMc7nExyLAuNnJpD3SY7ed/9JncehJ6IdZKDAdUrpX5RYeoDxcH44yYhMIdXsiZsfmxyhgZ11iAPX7+xhOsID0fRHWhJyqKRHEvmGrHuacbZSDD6kPJV8vSDstb5R/E+TpelwgR5KfiDJflDiln8aCvqFtEMxKjsQNX+bd6DaeMySzF8SMQQ/mcHJCeKcgDxx0aUH/5GNUWA+cOzw8hBD5uZ3sWgPI1+xfXp5/US5etcK8wmltdyCo3lO/VyhK87kDdjhQbsLXHSzWQ45utifk9uwOZijqvhPX7WIUqjERhzRif9sUKveJCdYi8SHHz+hFtjfVSyn8FZATHaOzMrOggUqP2cu0QIxQD3WHlDu97C3+G1cR6wKHrjaxNXebycCF+BM9WLv8WjqU5R6C6efWVntpdZ4xg9VwVMdXmR3XA8Rcm7bF8Hwij1Be2k8rrN7Wl58ZUjsZZLcBIuc+JO3TxEWvozHQFRn7BuEhLHjyViAqcqcdfIaq3VcVifS3udlMf3ddm/jedtiQE8GlqPzL9d5A1rpphCCe/0KqaJF6u8RUGuwbBwT7B7Q9bG6LjM6tPZCIyc4ySjyrRLvtFN1fgB5bln+0xo2eXjKheNlRPgvijXYO2QImEqALGPzaGXJ1HwkuDVobUDAOiVhP+HfeNX7C2TSPPNYasyke4PeSH4YPziRr8qud9WGAH3znX9fna8cgh7kv0oS88jTLVhDxMhGN2bRTZbqkM8LoRM2vgXNdXSaNPsg9fgMN7szZKLvCWS7+EMzAofbz6IRxgnAz+btmRldbEM9AnkCVbrWa96pb+BrqDkL4uArbTtyunSHZS8tg/XAaasIi/W0wzpfuHVlO1+7SvEr2e8c3ZmgNqslEmEYHVR6zxDJU1mgef2fk09dxj3iKKkLVWlq7ZGFYZ8tK9z6Xcexr1I8v9VPBEGBtKBbPDsdOp/z7L6Zd3G0mKbJqRXtB9Qxc/URS3l3p3w3MlPY2bdLWA8XfrEIqe3OZk2giSz4QReRDYCr+wPU8d8fZoDFrJ2xSg+0G/AqWxRpjkrPIlJSWhsnjCcd3mXcDOnvcD7B5jg4OmGFjemxk7gV9I5DYQ/yZivTlTb+MJP+yIGEWc1KM5R3dBN+Qz6o4cRJKfWoai9oFov5JkMzWlpuaxjkH6Bmkas6OuJdoVV9oAVDvsl/4Gg2X7Xk3f8gysiLhHO0+xzyIbMdfGPRow8Y/J+bfGzAN+/3f4+y8eKBqx8/YiAOhZQD9ncEf5gab0SVypE8wdn2fQYebptIu3li5xaXFlVNQI6ImNixFGnwoBYhc0P4QPCPBSYtKqiyms6kaamKIxZUcuAwYxe+ap1bP+5tF5C3lZsCcWnQKkHUIGhdW2V8qFh6zJ5Rg7gy9WrQLAFAW6hc17QrVXe1ZjQYEyBNF6aJiyaPrhy3TesM1ApUIpwKfaf6htWdFE4hAcItYfuKM5Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2024 10:53:44.9127 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d46a6a5-b8b5-453d-7fe6-08dd16ad6bca X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000013C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7572 As vram objects may be imported by other gpu drivers, peer2peer flag should be checked in dma_buf_ops->attach(). This reimplement virtio gpu dma_buf_ops->attach by adding a device_attach() function for virtio gpu. This function will get pci_p2pdma_distance and check attach->peer2peer before calling drm_gem_map_attach(). Signed-off-by: Julia Zhang Acked-by: Christian König --- drivers/gpu/drm/virtio/virtgpu_prime.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c index 4960620eba02..4f6bce79e10e 100644 --- a/drivers/gpu/drm/virtio/virtgpu_prime.c +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c @@ -116,6 +116,18 @@ static int virtgpu_get_p2pdma_distance(struct dma_buf *dma_buf, return 0; } +static int virtgpu_gem_device_attach(struct dma_buf *dma_buf, + struct dma_buf_attachment *attach) +{ + int ret = virtgpu_get_p2pdma_distance(dma_buf, attach); + if (ret) + return ret; + if (!attach->peer2peer) + return -EBUSY; + + return drm_gem_map_attach(dma_buf, attach); +} + static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .ops = { .cache_sgt_mapping = true, @@ -128,7 +140,7 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .vmap = drm_gem_dmabuf_vmap, .vunmap = drm_gem_dmabuf_vunmap, }, - .device_attach = drm_gem_map_attach, + .device_attach = virtgpu_gem_device_attach, .get_uuid = virtgpu_virtio_get_uuid, };