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+GyGGVK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nc4VSwtbHQnjwz0DFhJrNVWcZgl1OwjDxnoJzaCuIO6Cs1vJN6rfNY4blVg4LULy5DReVMhvIt02rkQ1Ar12M9mz4JIGW5aihL/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))