From patchwork Tue May 3 14:16:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835838 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 321FBC433EF for ; Tue, 3 May 2022 14:18:29 +0000 (UTC) Received: from localhost ([::1]:45734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltMC-0001cE-Aj for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL7-0007gI-3o for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:21 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:53096) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL3-0001LF-Vm for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:19 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243BpJOG013484; Tue, 3 May 2022 14:17:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=JpBsjHAvZ1qab1yYy12cHgZOwT/JgUZDs8vVbtCv7Mk=; b=Be0X4G93V/4N5EnuW1+UJjoE88UDr2QyddhHdLDf7AEhWDDLLXUiWOjCvMDY0G7571+B dPOQYCwvG9ewduffu7dvoBK6zfgmHxoUe1MwzkidDhVPyl/TdA1wLCq9saRECFS+KB74 I86Itse8GKdKinaB5yYE5Cendna9Nr7Hk6YSGb6gr7TB9k31sSTCsqmIiqZtQ7D9MGwi pk66wwF9AeQJCGV/8zGd9IZXaL/kC/Js5YrXCO6HO/ofsf7ryXx68dqCpg3c6FXAuHA3 9ju+Qbppi6EGslE0yO6WMFjtyNZ6lqm928gD9ixRppzuGX8Jbd7i9P0KSuHXDDpZeo3T 3g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frvqsdtg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:09 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EGR29001721; Tue, 3 May 2022 14:17:09 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fruj91jt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T9GAH6cGU+vncknotDptoanposlCDrV4xA1qV5OFSXrXzrUGeLtJ3kEE/xmiTtAHkT6qmTyXmtwGtK1ABcBPDza86yFXYU0lqfRiQVWWJbdSna7ZJnYc01vu6ijBp2kSFeHN5EwPg9s7xMioJsnOcOVZ182hXPddHIU0q8XU8qaPS+gcRBmu2EoO9pQcKuhDlgEY+neqqHfanuXBUVdi7zAN1kW4l+caJcziGkGcKNFqE9ZlxJ+nByHZISniXFt7dWDTvCA5Y2WOi3Wgi49WRxCJjh30mmySBfsAa1HHG3F+B4VnE7N7EzlJr1V52bvDrjupeWaNvUssBJDNt8CeEA== 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=JpBsjHAvZ1qab1yYy12cHgZOwT/JgUZDs8vVbtCv7Mk=; b=RMYHj4yo4/YwM9zW6IKzgkiSA00zQ6ZvftdPlBVOUWBwzwOks1tww7UGpM2ONaRmtR29cMOb3iavR3Lmps6JcvMES9aex0UZgn0d8JBQ5tzlgxoFW8Q0zqXiMg7njZl9C7Qmp4qR6YXQgXl08shfRfbRHs1/7aNCiAJzpdJo/kSWBsHM3QNEYia//Y0++eC46qMk8ScWpvE9HMHKPvD+aUfDUm4YmTsuXkbrZrtafiV4ivS39ASy1l7o78RIAjigK4ZI1GMZ+3elBviP5RnswY12rCmOYh/hLkOaGho+SGc6R64k3OlZUPJvcvS/XeRTbPzPiGf5AKfT7FEe2BKMvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JpBsjHAvZ1qab1yYy12cHgZOwT/JgUZDs8vVbtCv7Mk=; b=BvjSBoLU6TFwXcGAqwDpEjEDbcTYvV5AgkF9csyKRvDU736azaEsVqjxaX3RQjGj6BbLk4mYwCDNBzTWZTMfPUaj1HF58bylTajXcoi+9VFZvDhM/Ma3ogq/6Q0xNx9UT2kkCKvgA5AmIeNzICLDoGHjU9YKbK97zjw/WwbOGn0= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:06 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:06 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 01/17] tests/avocado: Specify target VM argument to helper routines Date: Tue, 3 May 2022 10:16:42 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84db46a5-7766-4809-7a2f-08da2d0f9a40 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3XaSm9P+j/NJQFUu1HEjxrpmtverWG2ZW65ZJgHEbk1BdcS8nINAy0fZuF6V+bLmlmw4uQvsVq8+Qa/QzvNyTz4pH/jBjx1GHI6pnYWfQZ/KJiaqkuCShWCCBfu191rDZ146k3f7ute2EAfLgkmpEermtOs7HXBSSMNpw8/CZS8w06atWx37oReSLf09SvvBjsQ0rZFIFCy8kXppPvlvaxr9+R+zHmTXjEqlJKvNJ9Ixfm4fZ+w4MdwcAihGW0fbZuXuZAl+sgYeiPerA6GtZp3C70U46bpOLPCwuAmVZ9CyNIhvggO9pUZ/wsdUb7dIComrEQ5vFg1+yoENTMyKotFGvKmhkJpfqQmhhOlpFazhFuEU5ePJU2Y/litID9DkDY1yBVkfyf9akntk2FH7ZZJSiMeFsgtVOggIt32Hz5BTPUs9ltSO3tWOdxQKBcy4c45ajlpsWPrFMlM3NRd8kUp7D9sdL87H8Z+H+PprXY3+WR+J6elZ2WP0WnQyh3VhBzKifp/aEyI/JsBWLz1e/3frji0YBpTyuxxA9+xx/R0pTNMynweKRUKqtDf5SuisPHxryyecE2lKmX9NYUfwdF4AiO7y+9xXbGL7T61cfXQkUWe6WV3bX1Do4xI4901bqINFMZY3h7s8ZTtcicPhWI6+5oQEHNeA1FKCf0qAq09WnuJVLHVRdr9trRuATwpHKuNVuMi0FaQp7tM4/cqDUQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rvIi0v7gMJ09zWxTrIzJuU1l/kP9?= =?utf-8?q?7kbmJQ0MgEnaK3fkUTELPydiaEm5h919czbgzxVFhzzgwJajqdetmtPG8k7km9Rav?= =?utf-8?q?7/aP6Fi+U3NYbwzhJmNhfjBr2xVeNuaNfsTmVDLB+Sshtl9MAAb3y1bLA2xdevAT+?= =?utf-8?q?72dkerUDre9xjgPxVDSZdn4S7x80bdnvmZYLwWG0xxemsnpXtkNZoBurh3mKCccBV?= =?utf-8?q?lrVk8zubX3U99oiiYvQdqagFoE0/g4UzzsXfgZpjgLOlga2V35PPiUFWp40MJ8ovk?= =?utf-8?q?C0Y+27YFpIjobqMg08DHmUHji2hpQgIqPq23+tbGL3nnZmK9QTAszzyqIzXqi6spC?= =?utf-8?q?w5+VVdLUkFsDuzMiDlq66R5CQOVkIsuekNG/tnctXs5IlAJtmz6JyA69/SK4PG0z7?= =?utf-8?q?mQaPhrvZuWnDCukhBEjauzLHVKj1z/Be9Z+6KHpZgrKSBnPV0D9AwVoK6t7JU0+Ai?= =?utf-8?q?rG4Dxls+P+78Hq+rpcHCvG5szW8hprmI0cnq77kh67KLyRq5QYmEyAHiFZwbGKOFq?= =?utf-8?q?E/DPxXQezcm1f/JED7M/zvfkO5RdfzKk0Wo551HjnnYQ+votBirmx3NPGYd1447O2?= =?utf-8?q?UMbH+hOg2wXer8eW9wMjamwhNA+IsZcW1Y7fSZNtrdbcXiez1zZ9T0KqzXBajHPTT?= =?utf-8?q?JF6qp/Qe6acl4GIvqK+T618gAF9bb96HrRVqCSD9/V5OYnAI1xhMKVgYJYhGVCbi3?= =?utf-8?q?Ywp47IM/CBvLava2UR+3ffk2wi8dYT85qGtqX58RHrG0uHHMCysNti0Qcxbsn810o?= =?utf-8?q?iItDu0jwHvRueKvmftxBJi9New0v428Zc3BEJIt/u+wTEJmGSZwatSTxC0B+PlFae?= =?utf-8?q?Z4N4yA9lvWkudP8oUl2H2l6p1CAgfbAAd5X/SiMuBip/hdreuSx/DFXx5Mw8fBi+Y?= =?utf-8?q?N8Frf2Ml4PiAE7RxPdensVtTrT0wGlBSHiP8/oSvnXn8J96KEULiDebd3BvBRPTVY?= =?utf-8?q?pWzP11qXkAiRguSZaPKwhFJsyqCZC1PYvFHHREeEgaom/W1b8mhGUOZdWUFKZnWoy?= =?utf-8?q?JtUaCryvID0Ma2NW2r0JogSvEodM+34Q8mkSf8DdF/grYRwibUqiIV4h66rq1Zmcb?= =?utf-8?q?QibaWn5bWBrCzrpDyDr6zKOso5IsWVp0PWDQAA3nL+CX89f6nB51Yh4UbPhsaEkGt?= =?utf-8?q?9aAmdeW1dTn2UjVnfzGqL2/OZfei9Wq+QikfEGvxjtzm52+veUqiKbVdV1CyeRy+r?= =?utf-8?q?J8x52AUPwumDYqmkPZ7npVhSby9O5i0t89gUQbg9BCZW7pdoWsXbhUWtaebkQA/NZ?= =?utf-8?q?RYxVI1P6nPSBSZH0Q5/ktH3HV2oEzMjeHfbIHi8Atiu7XSbf9A9koD2i1DW83LhNV?= =?utf-8?q?x4zIjWIy+52gjcnPDwbogBaufvSOT8PLxw4U4gzSNV2X6y8VbEh+23dYXdxmE+0Ey?= =?utf-8?q?8/EtirgUL/9nW6gq1rB4Krx9OVDQc2nYSHq//yOXcl4oYkeU9XchV9+j++TvPuOR7?= =?utf-8?q?9FuEFfbKj2ntz8D6O3OVlQ1BJ+4MDIZeeK9FUNbl9LnS80jakfOQD+vWsDP0cGfaN?= =?utf-8?q?C1cti5ZoS9nBVmrw2SVBzd0JBUmRnT2jDLk+hUGQaCR7D45+BeQRRr7o/yVU85/k3?= =?utf-8?q?8LT3pbqStaMigDODcJlsW72USwWHZBR8o7njD4LcF/w5nXQRSqPV17fx6Ur2sQhAk?= =?utf-8?q?KnmaqYYN7DBdtJqyTtlH0cOZ0XYue8Og=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84db46a5-7766-4809-7a2f-08da2d0f9a40 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:06.3741 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XmolGDuMm1NG/DkOBJ3vdzV7yQ1Y8nwQ2oSVu+W0oItQLZFiu5aRhEHo2VACCn14Wj8Lmcb0K2au0ZfNX5/bEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: UdFFEEFJa8Sy1eGEkCSCnO47gw1AH0tQ X-Proofpoint-ORIG-GUID: UdFFEEFJa8Sy1eGEkCSCnO47gw1AH0tQ Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Specify target VM for exec_command and exec_command_and_wait_for_pattern routines Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Beraldo Leal Reviewed-by: Stefan Hajnoczi --- tests/avocado/avocado_qemu/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py index 39f15c1d51..340a345799 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -198,7 +198,7 @@ def wait_for_console_pattern(test, success_message, failure_message=None, """ _console_interaction(test, success_message, failure_message, None, vm=vm) -def exec_command(test, command): +def exec_command(test, command, vm=None): """ Send a command to a console (appending CRLF characters), while logging the content. @@ -207,11 +207,14 @@ def exec_command(test, command): :type test: :class:`avocado_qemu.QemuSystemTest` :param command: the command to send :type command: str + :param vm: target vm + :type vm: :class:`qemu.machine.QEMUMachine` """ - _console_interaction(test, None, None, command + '\r') + _console_interaction(test, None, None, command + '\r', vm=vm) def exec_command_and_wait_for_pattern(test, command, - success_message, failure_message=None): + success_message, failure_message=None, + vm=None): """ Send a command to a console (appending CRLF characters), then wait for success_message to appear on the console, while logging the. @@ -223,8 +226,11 @@ def exec_command_and_wait_for_pattern(test, command, :param command: the command to send :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails + :param vm: target vm + :type vm: :class:`qemu.machine.QEMUMachine` """ - _console_interaction(test, success_message, failure_message, command + '\r') + _console_interaction(test, success_message, failure_message, command + '\r', + vm=vm) class QemuBaseTest(avocado.Test): def _get_unique_tag_val(self, tag_name): From patchwork Tue May 3 14:16:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835843 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 2ECFAC433FE for ; Tue, 3 May 2022 14:21:53 +0000 (UTC) Received: from localhost ([::1]:53754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltPU-0007aS-7u for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:21:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL8-0007gZ-3y for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:22 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:13500) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL6-0001Mv-0a for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:21 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243B8Mvs029440; Tue, 3 May 2022 14:17:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=HyLmZZmUtNjHoWk/fXc0kbzQpeB0AWYnnkpgJEjjtxM=; b=1B7rnOZOXNcAYFDgOWn9YxO7lrWhF/Jnz49tTDZ/2CIVZEkeNJMuMTgG4F4BY8ERrYJd yF2ekaOUb6Nh21iQRMQErcd/b0IPpySjR4onEItQfb3W+PlSb+mgIRNPYODYvFaFljLz 39TacHMg1DWdvcR5ZUBNXI2inGW2h9M+LOSdbB+Kw3IS9nmWci1U/z2dXuP554+f9sBg Z2YU0DDlSGklX1jDbvOMQWh0XB4N5ZTL9orSCTaiBaKpMLL48EJhq7zALrJn3iuxySuD yBQOcuotfcmUZMJtuxiBFRkZRNmeLFE7YTCZ8IuDkud/g6bx2yr75yO68c1B+uVxS1Tt kw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:14 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG1s8032338; Tue, 3 May 2022 14:17:12 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd2q3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nr/0dSCIkRMWZiqqaq/FT5xBxJhpYpQzzWUHAQJCjMdnxv19ECtGj5IXq8+RHm3qwgdW7p30FtfyeFnSowjlkyPryrgbE1Lk/YQ2E8ubeJSFQXLBtxmZHSrG8+gzDGbC4WIjEYqP7oLjtLDbJVCyi3FM8bZDGz7QPq5zrcVtPdFcQBBLfm2O3B3L7YIfUW2aQGIKIziXX0S9Wm63eBBTy+nxc9GCg23WRWI+W7VJeXEqvjuC8RepP0h3b993Sfv2e1uwtel0f7+yUJ375eujwREFajtS4u3AKfsSiGL8B4f0M/tzIuEbsayZYY3iE6pYlIe0L2/2YBT3rD8yqRs2tQ== 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=HyLmZZmUtNjHoWk/fXc0kbzQpeB0AWYnnkpgJEjjtxM=; b=djr1CSAL9nn8vJDRCYCLH8jR4qWHOcgh85j4Aj1RrDf/3ntAmSBENclJGMhcOuonIgJi4FBs1uxxrQlVY94blgbVnLkK1gieNrL7KuDZfD3loXWloMwS0XfjOu9O3qpukOzdEk2DAvwd2/uLhUNFI9gL/hoNpjapwFp8jDxX7mwXhtPfkItqlKmC8yMzBB5SzN4fkK0b3y4n/fPLc/KXRczHxMvdWV50HAiKH71BpWA1KGb5qFjSh8p4SlM0TL4kGvuADiq6HdYw5RmTjyPl3c6BZPIgTclL7TSrqdanUkJ3y1tJoShliIqzw47sFNVJafNv+ZapbhKlzFJQp/M1Lg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HyLmZZmUtNjHoWk/fXc0kbzQpeB0AWYnnkpgJEjjtxM=; b=HQa/GcRtPiSUjT/Y76euvKJixBdq1VglA1JWhFdbRtFSSXcTyJ5x7PFOswTGLxE00hMQNH70ORSxY1Qbvwt7O85YuzQMcubTlM/D0O3/Y9Xx/6SdHS+uZi6dyYibwRyiKWvg/VMtn1tUp39lULEgxWmOchhG2UDQZtE1vs8INM0= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:09 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:09 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 02/17] qdev: unplug blocker for devices Date: Tue, 3 May 2022 10:16:43 -0400 Message-Id: <01e8950f954c291acd74c9caf1d2016e898cd80c.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7b4de9e-dd8e-4ed4-fddd-08da2d0f9bd0 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l9z3QmXuuGqss2xf5HETSfR+LdSI5O3YgCNFZqRnQBygyEKZ6dBPeeythAH5j9KfFaurZdlQJvGVp7b2rCf3HlhsoAmh/0JjASxHkasgn7OzSgCTjyb9r2aKR5vqqqox1jj6i5dV5CfF8xEyYvsrM8Kf6PaxrdEK+A196Fe6RBnHzhfPsSc9BpiSXYOm7HHDZ8kAYKwbi2PnQuqKK8oAyiapPRSG2GSpYttaTo6nfjTtjX0lcfovvYuzbQ8kRN5aiS6dJgX7VA465WaHqZIomvqr/jerfv1jvQr3tp0+M5sbjqJ5TeQt6zZ8y9Rr6QM7HgKvUO/qtE7Jl9dQ/2mN2yQm4QbuwMzhJzl80iTUzDLBgI5/znjeTFFHcSKkqPSFlL+DfBecOXAuNT0ItaOaPAaOEV06JAW1ip7lSSycdNJSNHpHsBWuUcValTM0znJ72v35fG2VatIUyHvGm3n0cY0AdkftTcY+ZZtd+7fvKXXOO4sq17KzGrC79paZm0Z2SrbQQeiSYVuaTOYrssJBSPw14zd4U8t0y12jlD1b+jtP+Q3dLsvyD1n6GM8eQn8KJD0GtbsPZ7og2JFPX9UPt+jaIjsKXyPjlu9zYZ0DFOSlUwxBUr//Ri0KPzpZEzvW9ktDXzWfDQWOCtlL8fZF/7MBQWvmc8V8UCd6v8guxmKJlcimbXSkcNkSIr+fDH6kNdHTN0Cqwt9+3SXBGuCiuw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EpOnjBZF25p3lFhC+08HAmQhDOPltp9XNLK7fHlSFKeoRMc6OqTVRS7FUfnYzvH3jELkprUdodQBPiT6GXiGH45Uj9KBTjHH/C1gY+HR1GT+vJkzEsWbvmzXNiP/xElFimR3F20M73uxGKmCVaPD7QxM/EOQZ8T7sEOXsYBbywjLtUgLOv9GmRpGBXIXggKx3Y+NLllzAYKwn2i3BT9PCPrMAQHXnDc4H0UgA1G8Xq/GwINheJOCZaECbtUYqy/5nnWiSFlcgCj5snsLNE2ekkCor3SL03oPFbqyd8h348z9oq2st77R7ZNGE/K69W6SwkN2EZFLu6voM0QN1M8zunGYU97Vwfcwux+MyO+NSGWO2S70pE0OpCp06wGq4KScBKEk6eymcopJrxtcLybnpsVMLmY5x6NIwn/nxNPTd3VmTA07FurZNcam/hf6caN/9qvqyqOgbLrI++1lC/kN8Q8YOAHheLCGuGTeP4mjkYw365kB8Wv2hxA2TGEdUa0+4sDShZTZ4aoAmjbxnyzC/GwBOKod0FIU50p/A0st4FVWiQgc8n6GMytF81i2/kuhUMHpwxAdt5X5ksEnCrtF7vOndbI46ZsOTuW2CpQ1+fV8/VUEkNVjpL/asOWeXPAKQ9O/hrDE5He2nm9u9AKqgh5P9moPs6233Fyoa4gZNyN8bjyeALXi3FRaaVhPIkEn66anzoXqlX4dDaLkOF7KAuBBIFQNdZh2VH6cZv7Rer4Inat2AkO5xonDtIJRLyUegNHEHcjYCFw9ke2ZCtJxL0dyUl7eF27MdEX5gHd2QEx9u5nPCpmozKZxHCdfSgTbEEf8Zpk1xTIbM/U5V+XrlmcUReiaHgwKCHBKZNT3RWy8Pm/HX6qp3aQFiqxwbZKFHZA7hVN+xcL5325ZdaglZosS7CboQKCdm7sNYxJv96YeBuGWgdgIx/hSaEdX+M6YmCSzKzc7k/eGmcQK/4+RqNouonJHT4NRdaooXcqY41Rt+ug3JpP5UnDUMq9Ux1XjgnM8arAUUQ1/q0PmdJGeJWUP4xmrCsYRTgU0v8HrBGLjjlsFg/Ajd4IlrrpVu3DKMtc+NrKSviaNgdkOZrS/0RAdBroF++/3M0cA5DGML6Vyu3iweIEivKmN5wHnVAr32eTSDTG5weqsjPeO6+Y1J58T1NXKQ99kOUnCHK3+qXTygHV9qiaQc5fXPDwyfC9G+0UPgbZypcsYMN6pFyJq7K3VCB85ww99Z7+d81mOnvhWBAUEGpdl8dxg6ilqcHZgBljeYWw4Uq4EZbycVBpQX72lE6ld9b33rSThzLlHcM9jyV6TUk5JJ9wf4ouY7sHaPuNVnTwBgejmNvS5oKYtYuFhwVfV9JOMM3bjxDVCUlf45cKlvjLwrbhNdCRffHH9CBpFZcZHNN95qVyy3oGWhgoqBXqzITfOMIW8dtb5eVZJ/pdqrIiMwI+yu4Kh6leFOLB6Dlb4NWCzlVKMQoq20VjmzSV1Dz6mrE26WUX9PAjGbw30rOvQgw7Qkr0AkP6zwFPtaDqJjYsTskOdqZXgJi+syfz5m7AxKurle8u9NP2BlYPpY2/oGqWCPyF1c81xT7q1aOVTFwxRLdL9wur9KFCWIhyS7dCSYFVNonOPx0a4Q7zoNxV1f8JjhZ598sPgEUmUIz0OXRlK56JEfi8n7c0YErKzGjlxN++ZBIV0kfJfzIXnUCTNm3HPK3tU8E004MZVpjk5yUwkzyIsXQkW9Q== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7b4de9e-dd8e-4ed4-fddd-08da2d0f9bd0 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:09.0145 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wzQ9dOEyDPXDRKm3qJ7RBKbF7k+jqXSmMywFo3O/aeT4f/pcqjx7yuZNe7ABfKFLWxdZEWJ/+jHzjm3r1l61kQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: fO_ImpAA67On8H5SnBuRtS8J67KDfJa3 X-Proofpoint-GUID: fO_ImpAA67On8H5SnBuRtS8J67KDfJa3 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add blocker to prevent hot-unplug of devices TYPE_VFIO_USER_SERVER, which is introduced shortly, attaches itself to a PCIDevice on which it depends. If the attached PCIDevice gets removed while the server in use, it could cause it crash. To prevent this, TYPE_VFIO_USER_SERVER adds an unplug blocker for the PCIDevice. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++ hw/core/qdev.c | 24 ++++++++++++++++++++++++ softmmu/qdev-monitor.c | 4 ++++ 3 files changed, 57 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..1b9fa25e5c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -193,6 +193,7 @@ struct DeviceState { int instance_id_alias; int alias_required_for_version; ResettableState reset; + GSList *unplug_blockers; }; struct DeviceListener { @@ -419,6 +420,34 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/* + * qdev_add_unplug_blocker: Adds an unplug blocker to a device + * + * @dev: Device to be blocked from unplug + * @reason: Reason for blocking + */ +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason); + +/* + * qdev_del_unplug_blocker: Removes an unplug blocker from a device + * + * @dev: Device to be unblocked + * @reason: Pointer to the Error used with qdev_add_unplug_blocker. + * Used as a handle to lookup the blocker for deletion. + */ +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason); + +/* + * qdev_unplug_blocked: Confirms if a device is blocked from unplug + * + * @dev: Device to be tested + * @reason: Returns one of the reasons why the device is blocked, + * if any + * + * Returns: true if device is blocked from unplug, false otherwise + */ +bool qdev_unplug_blocked(DeviceState *dev, Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..0806d8fcaa 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -468,6 +468,28 @@ char *qdev_get_dev_path(DeviceState *dev) return NULL; } +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason); +} + +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason); +} + +bool qdev_unplug_blocked(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + + if (dev->unplug_blockers) { + error_propagate(errp, error_copy(dev->unplug_blockers->data)); + return true; + } + + return false; +} + static bool device_get_realized(Object *obj, Error **errp) { DeviceState *dev = DEVICE(obj); @@ -704,6 +726,8 @@ static void device_finalize(Object *obj) DeviceState *dev = DEVICE(obj); + g_assert(!dev->unplug_blockers); + QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); qemu_free_irqs(ngl->in, ngl->num_in); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 12fe60c467..9cfd59d17c 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -898,6 +898,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) HotplugHandlerClass *hdc; Error *local_err = NULL; + if (qdev_unplug_blocked(dev, errp)) { + return; + } + if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return; From patchwork Tue May 3 14:16:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835842 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 E1B87C433EF for ; Tue, 3 May 2022 14:21:51 +0000 (UTC) Received: from localhost ([::1]:53740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltPT-0007Zw-1V for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:21:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL8-0007gp-Mr for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:22 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:16710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL6-0001NF-TU for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:22 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243BFGeF032436; Tue, 3 May 2022 14:17:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=I3u9gOkAUpl1AHnH79myWR6YBjHgkemLhZvc15Sk7z94CXfx/WZ2lt5Ss7I7KnerHqmO 8W7kmEx5c3FCaMNZ1WAKGUm5+WTGwzuL+923o2d9xvXfGEyVBGRZOIi/OHp83nHdwIao 0aBR8bcSKrl5X5DJmTkABE+I6K8TBtsecZs6EI/iR/pdXaszqM07HVX423RvrTDr6JeD Lxs3vpmjalAOWjbEKhTo3dFDHG82nyZyuhwFQkdVE0maAF2OwbAYAtwuALYb3ez4Q0UZ TvzqKEKZnANTrEAbhW61F6Nfn07R/FPgSiMeckCN8dek0KMhcqaaTxRDln3Qb05u0wLi /w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0anng5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:16 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG1s9032338; Tue, 3 May 2022 14:17:12 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd2q3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WSMjfPSQDSD4GfyNqiepc2XISB2wdIIHDecIgTzHft6RoBvlvYsY3dSn39Qb0PSznzH7ZUTWgsrHyKojSMeK2TFZDjl4q1u8Y57NP2SqQfcnfVM9nfEll6egZ8A+msIay6XtCvY9hrl29NS+xpzRhbM2O2YyPDsZsdhSQQtcCn/LW9kyQx3ccdtjS1VJaDR5beaGJBMQnAs3/icjWxscSvHgueRgEZsWkAzYOuTshSb/wriPxnCdohd/17hJSQNSSeJ0LE7iE9OzZ2YgTqW1/5d6qTgPcTT/Gg5k6cEDJN9XWCrP0iN0/WD0hGZM0nfJI0INKoceDupkQyIjrf4KlA== 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=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=ZfSSbB0qQvRCzFUoRZUazsJ0TiokYYQ1FlKtyF2wYIGvxS8nxlvVQZHjfo6cEAv94JBIdUqlaMkLxgv2WkVPr71OiNTMvmOJut5eNqfjgrRtJ4+QwtHN4v2ij6UgPKiwIWg046GkE+86dpqaUl/isImaZvbGtdOhFGKfrUHtfC2CaVH/cCPCP3vplRhFGlkLuUo2WmHFS683p/cuY8MaOqhD/vN/nl/m/H0DATQ3Ol/rBFG+iW/Mp6v5LD6c5i4GRJtgpsdNsDeEF8RN/VUcaZbUDKBoA0x1igx0XhusYgFz2Ydf/nYR87bplSWRvnVul4FCdwgcE4nGvxQRLedH/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=UlTUaNyHH6jJaB/tWF0aYZ1iRsR2a9O/ZlmFUDYgtz78Q1+2d3QuclP0172N0WxyaOeuk80OZ4gWdDTIxkYLsytcS+r/YXlbiJnvgq5DTKX2csF1LEXLyqghBryfDI6BsZhOeC9A6y9RsKcYRtvvWOHlBhyD7O9sVl/cAF4J2Zg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:11 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:11 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 03/17] remote/machine: add HotplugHandler for remote machine Date: Tue, 3 May 2022 10:16:44 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30cd5452-90d1-49db-6f1d-08da2d0f9d4e X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6uV4CltSxwgWLFWbX4Jx7KBN9s8kxGTgB6mG4UGrEHATuk+EkKyFc2c4b0bF8giQM+uh+FMT6x9malAe5v/TM3hdbvzwaytp83zu44y5lY9/5qpBh6pxBU5Vz6kz5R/khi5RoijacNo/Hy55SJ4mOakt/NyB6iQYfoJdLPzPDsk/D9kN36XaAAD8vtfSk1xevwYGa47T4d9s6RpUD9Url0lUkW6k+2k+bnugoIr40frvMv6NOdqeFCqtuhwR4fT0ueK3DQgwFTkAWjV4VVp5PTgRxkTIcvGxKzeYvVtoFI7TZXDw/m9RnAsFqDgtIYwIvid7TnlZ/jSxP3ngSlH25Q3ajYHoWiqSlOi3dc4ReVyAWFOoicK05MYBOskgXmqnKdJ7zjHXdk5MajmZph/BQGObBAYsSx7Of4Fr5Yo59ot464AftccVTgEWyFDfFNIF3G1DnQqJTVo110QBFjDwzvebKFhofWM2dlH4BkRjtHmhfl2BecF/xoVDqpK+6Ua6lCMxGB+2dMcHfmflKXEONo5HNybSj2wWTiH6Pf6BWT7lP5Haf36MVcYtM1QnPY9tMFUVCAyuyc+sRuoTW3J5LTK44En6sPXEt1rlpc27vo4712G0Oa7oMEnyKR5mh6BOGJJIhaEpw2dhI8MX37+H5XkNTzEvySmfVOJm8jHPYTni+eFUyn/rVza6YRme0ret+0uGgMNn1L48WoBfGokbxQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VRz4HrTo0M77HUR7dgb3GT+FUlxurOnFOwjEmFhjWb4QrApmkTQotFsGhBhTbXh8mRRquZf+sh0aXzfmnTmJBMi0jdEtS7G7k9unr+WAkP21rkW9gHMEdAFFoO131wnDixDFfqqKoHUsUP5qRFUSK/K4gNTirNGaqaBOXUQAX+bX1O/jzj1Nlm3c9saVSZM0EmrkXzA0DT1Hyq7vHJG60L13QP+cZiUHLLUGM2guk7kSSxwk9ZS58w4Z7CuBj8oJSAnTASfUbFZrqMYL92hv/Y7cEMvlY/TBc89Z998WmBuR1BXyKSrQ3SdJz5ngJdAoIIjBxCkPLDpCTHAZcAgQPzPO9LX0obKvJSoa1THEolA6AcVJ1SVx7ws9fdPJAhAUkpoQ4rtNrpOlnizdcRufbZJp+U+U5q7Y076D2AaHbqfdrEqq6VOoDvgSSNiRWAcqWkdxlQ9FQhb7wAkrPeL4M6fbjcRwmOStXHfwucPkrexTCD7v2a/hK2+EJtrebrX+SFO9z8H2TqVQCaWWF1L77VhGjHoyDS6zqdYMzccnQCkS7ZpbVkXRVwoU864wjfzHMzplL1VdPRYugQfnSMlJu6SDqSFxnQHnatbDQ5xTCKJ/gYqH7fT7v/IMPcpDTFAjJeb+uf7U+hdEAa7vMhw9ZgEtsScb0fv6Wslz1aIUHIBgDKFtZTgX+Os/spyGsq3h39sTrR888JEmOrRnRJrj6tIS+LbDaGo4y05ojmB22a75NnHI2AUy7FnN71XiDyUKxJYNVj+aSyAui3ibN3TSqOx2UqO6dVGS/hOMOr3PNp78gWgK6svEnatwYVp0gyp+ud+pJNLOmC7jvXIWT16OUjOIaknyshVQ1/uJebzujtm3kJCbw8QbLqEFaxFwebo4aTQ3RkMUAx5A8GRo9g8DB8U70u5dF6D8p37RIVOlZ4/6b3q2xRgKhqpLPlXQW4/LP09sRqowBg13UfKMFaskHYBX0ir9Al6dm8u3FKUl6pYwuAmXlZ6Qlkh+xQ1xQJv71aVZx8APaHXFYTAnwjSN3wUggjcCH/dowkkncTto+5GhQFRb9/nElXcdjURl6sU7uTvWuY5bOwm9z58zlHg1AihviYOIaCXKV2S9+ntUad0C2m//F0On/5CURbX2zPAZCJY5EgcOGYjBDRJ8/0Te4Bd6BQKapJPg026FB5UcJpPncieeDZa9GdZT2d1soJfuZA2khPo+4ow2AZPNy6+EuDjYECZ0Q/3IHsTOuVEs3PKf6V2TVaMMLNauGGKN6TCPwoHuSXcc10RR002CGDGRAz1eLY/eveWOScaHHFYNNgV7qwnFlDzGbGROjE+gkEs1WyLpy5dAMm3rLq9rLASHrgYJQiPcd/AYu3R57JjEOeQhCI8B2N+Q523sATYOhw5n5CJLSyKfFnkP0Lx8737ieTG/t02t+rW8pQY82upnMMMPpAK1ZBmMiHG9fezjonTIm2Jj+Qk+YRGDGKJDVWuinOtw5A6wq2zkqVB5Be6iwyR4BI3N7ebECt9uZKHIPQfpS11Ho/RMPacNxiylWEnydeE7KjSCeQjAiE8tH19Um2VF6y8bX0JtXnC6zygOcIG9U2w14j/kd8KSP/jrS6BtzcPpLzlCRjV4+fIDmwVdo2YgJL+j4jvBoC4ccQe5UTIMD7r3iNnDG3NjqPpS+C0DiBPZxOLipQv6dM5f+WOWkfcplfCViMno+GADekmGal7bC3mLtMcBGuzIux24UVjrww== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30cd5452-90d1-49db-6f1d-08da2d0f9d4e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:11.5456 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XrYzFLLLRhlh3eR/t0/1fzcNiXycOT8kBWKI6Z9xCUiHOgA5f7oaDtS4ZGQuCoUstRvTj1EdNK2oQE6uM4TqwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: 4PNbYRcK00AaHdlgd42Mb5G1kueaPc3v X-Proofpoint-ORIG-GUID: 4PNbYRcK00AaHdlgd42Mb5G1kueaPc3v Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow hotplugging of PCI(e) devices to remote machine Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 92d71d47bb..a97e53e250 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -20,6 +20,7 @@ #include "qapi/error.h" #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +#include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) { @@ -53,14 +54,19 @@ static void remote_machine_init(MachineState *machine) pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, &s->iohub, REMOTE_IOHUB_NB_PIRQS); + + qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + + hc->unplug = qdev_simple_device_unplug_cb; } static const TypeInfo remote_machine = { @@ -68,6 +74,10 @@ static const TypeInfo remote_machine = { .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), .class_init = remote_machine_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } }; static void remote_machine_register_types(void) From patchwork Tue May 3 14:16:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835846 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 B33C8C433EF for ; Tue, 3 May 2022 14:26:24 +0000 (UTC) Received: from localhost ([::1]:33936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltTr-0004zN-Ra for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:26:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL9-0007is-Ua for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:23 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:19974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltL8-0001NW-4O for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:23 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243B5TcT030007; Tue, 3 May 2022 14:17:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=APxzVfYTCw36/FZNBDN9epQxaxw17a9aTs3XSZ5mRHtM68S0gC4wb4TOnS3oRS+xfosz R6CR1vP0fykpCfUNy7GnQUCRbVZtkAvKF/eKOjxdymerpc7ED2yfcPiNJPqj579JfxPh PkhzqhfLIGV7d7pe+X0c3p0i1/ZdyU0JVk8rI2BeaV3cZ5m2RzkOe0lvCri6NBDr5DBU F113PsxVoWDzMrpFrKo0LzN9C7hU87wX0VcaOTigRd09RNv1NVrZl6x28SbU4ZAvuhLA 65Oy00TsL1/0aYuJqepnx1vJud+XQayqxySTXSubGIiChKbO+Kir8vU/KO+g6e2RLq7s oQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtnw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:17 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EFIao031973; Tue, 3 May 2022 14:17:16 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2048.outbound.protection.outlook.com [104.47.57.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fs1a4r3ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U5Ycxv6SbRqTZjhog+fTVG+M36L5ql83pirLtCx/6hSfveSsqzopLQ+6NzQY2lJRe5abtYiOznB2UO3fu7kSt0c0Sdwm/OYQ+r2xEo4Qt5V39VabVxiD3pYJHQGhgUNK9HnrHnKImlGYfkGFFdxjQHlr2WRPBW/cZLlSb+LXWM5EjQNi1hPLtrEidVuVyQhksbH6F5o31UI81PADhhwILJmxkpwlN9uDNRyddOHoMnADmclHqz5NyC3wsQkGPvXDSuBfTZa7xT6qdkWNdX6nit+oV8Z1PF39AYh1Bw3UQ/rP8fEe0o/w0S6Cm0mfUjPfqsPoluxZGwUrU9iUDGrJfQ== 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=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=FxlV8laQEg/Dqzh1OpYCZgP1RUpiUnSBb/9bc8XnpuazYx9UuQEO7G2rsvYIJEWoV237CY56xm5pEPCAE/KB9PzxAEl9SFPePHndyNjE3HNYw+xOzU+Kp4Bl4f0BxnrPoiZJ09vpRG9QkiBTRjibaTrzeYUJzCDzrI+ZuXakB7PPAPwcqAHeIQCNaEWZX1Giut9RXNxMDRWGRqo0IOoxRrhqNRsi+UsrAkTUQXMQEASR18kkFVwAdlMnotKiPN7qfbPFvwI8tz3z3bbFiDyUPIBtzhEqR89snFr+YbBW0qCv9oq8f7isSrqKEgEC0Rx+ixgKzFI2uU3oPJimLsj+hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=x7lXYNk/Crfbz4ycoMv9FgRDkAl0E72xmttkxmpuYFHAyvZzJ+vKKPTNVuju83XkBt2faM+W8QXaiPhvfw3xGi/VW3eFPsPzaA8b/yrEq4bp4AREyf9B+7jBSZMh4LHcHR1t5eVW218evgksTcZE9JGTl2oZvuUXUC740bv3fj8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:14 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:14 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 04/17] remote/machine: add vfio-user property Date: Tue, 3 May 2022 10:16:45 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06168dca-4e90-4530-2e25-08da2d0f9eda X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XjZQRYK2FealI8GOSDVN0UEwgQe8S3gdLRGVnS+JcbFL1Ev0HUC2FSIpgXCoIaESvhzbuJHhicBS8ZVI5ea+EZsdxYXD7ftXwCrq3ITKdBQe8LRAOn9aiDl24/dxPmOjS7N9Mu6U6aOwPFeM4fgeLHUBiswH2D2Gadxn5GL6tknzYVowcVSmnpZNfX5OJZA7s4xpwE7tTXkGqpB/dy0EZ45KsVHI9OpxloX0KvUOh1Oa68AQBWVAC2wU9zPuylAbWUwOV/ktFsfTIH6dwmKCEV7DT/g4PZwd1v7+6qomrbH+CaUr9On82CUaws4XH+kvxCWxfSLjIJUmACe7SstN83k5lxa8O7MqD7ZkgFxGBbOFqW3o6MijD+6TQtErHVksVYD9J+Pwac2NqcdlghS8MuvKW24S2+kiP/qllLFwCPhGuYXLl4VPRNFvbQnqpx4/y6O9mShJ23FE7WipglJN/wJzBNVubJpow4KTOhm/zN1oT8gQamtS0g5xWq5fzsPuFwYZ405PRtQSJ+Uk71NFqAxRGNBNAlin5diEvaKVPITrOK2QGR8c4RKVs98yzMy6abeKSHhAvvIUPlJqLsQvmkXpP1+11ObkwqnGeXGR65f9qVTd3mK7QZSA0goYfqrayK9+bLkpVtK3AEoKsCCujWNXrqnFykp6s67KbuUAlfoGKxYn5cgrg5bLFiMo3lYnkIsK+TCQHq2yW5rqznrSPw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lM3HvzLSRVpw2LXRYCZ8c1xfnodLJwk9cL3U+seegmgzuOqgAGgRhdSkDE+++bApjvT1Spw0MWeqPyZ3Sp+iw5Y/WoK3yd6cMH299qp9NieB/tV3Zs3nMzQv1neMiy74TBM1ePVBJb6pseIFQ30JfDIEo2d3u8WqqomAXJBbAn9KPuwV873IFQuP7DlRhe0dP18RwIx6T+CBvWbbdml4EusWh74S5FgRj2ZhMCWC/ohr564NcgJ7aSY2S4GX+GBYEwxusQJXBtzU6/hYonSMVeCzNrnBDrb8cwoecTUTfOGTacnNrz1u83+LsSOdyLH64TJH4X16G2o6LIE0aGfoyFfUNn/+apilkXqPHeBEbD7sjeWHH3u48daYKmzyWfWGTNetO26bQ79vNvE9K3zw6ef4onCFTu4yLd3nA/5uM53T8ocX9hmSvvr4U8bxDn9f9N5y5aii2ER5Cg8aV/y8gMCFetOT2k7/FFlvqjUVL+5DYH4h0fsiDm05YExWaLaZgUTNImG6wTLrEwLdMvTPvfPCOJ9hNaO3LoqC+UpCpwehBKv3TuszoBF/6lAUaqX/haMg/w7Xe/uZOgnujADeXMJJ2ke5mVZggsQtRuEtJo1oTnaHTorqr81lii/jftMqBbwcxczgCpdmjoZgWcB1b1/XfraxwgPsM4fQzQXPPyQg42jKJRtQdGLJQYGN9LsrVRGVAWobgBV2zsfn+IAhohfPVTmCcAPA+tL7H702jFGaiabVwyNCvnKMTwsodRACekaGhuBFgRZkjNpvW8k8zW74rXAoJuBTBtQ4uLCtSYXNDapUrYVpYj5f979BXY+53Tbn43o5YQ3CTwJpct5ZFDQD10jIavHeohvisFfa71YuBqgRYtzIxb20pgT0V8abC0vWXH/aGGubLuDuK7dShbICvgAWx2x3GzG2OwdwblEJPPK56hMCJf/d6bVPZ8zr3zjjLY+4Vi+4Wayy3WnXb2EdbIZvCy0/MX3ATj/5aCfzcZHaUyk+hmpLFqALEt8/PoC5RBATTC2QRGs0wnzT5aBHsgqT7QzQWUG9bjKzB3PS0cjAG5ntQoM0UNwYamhTqq5WxLt5A7pV/0QVcbEJ1LQmwV1UjN9C6uOk9Je6QkS4bDBaLzHn1YqLkWy9Y23ki0iA+prR1ToDvnG5F4FtgKlJywmmX8BybxSDJkaYoIvDdhlslvwqwYp1EO7jbU4+a9H5E8d449fqHWcED4aS4F5yFQGG9Nq+5gVF9tDcHZ4h1HGsmEw+vy05c6RjBCFfhOPrYhqvZ5V0f4a96Lshiz5+vMI5zyTUbzaegnkE94H/P2KylTkVEeNuGiHJQit7UaTb2vaf/HecZPBkuQ5skCVLDSPaGD8bw9x3Z5HQp2uWniDdy69Il0dCVFQ89kJ8fVIYd4BkAOekZ4r7fPmgopdAuqaCpNYDazQyLrI6tWuadOeswRKQpodvm+HdONTnulO4gpriDyRTqHev4M8yvPK+P4XFnUKPZOAjsGri76ygxPLCE9PuoAAocrOMskUhD5Bns2Q2Cfz2l5euMogyAflfW22sUS1exYnaJGkU8HqX6kvd5qZ95z+zmQQHIREitMwI1gQ8UACHv+1zRPIgTM5oskHxZh/LytqSOPK05Onr6AuWzhuCNoqJzox20mKhasLlRKXMKlKmiEb4Vsq/a2we/EH2e8AhOoJZRzg5bwxJmP+CinC4DtArYzh3xVWl66BWcKao1NQxR7mpjuURJQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06168dca-4e90-4530-2e25-08da2d0f9eda X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:14.1079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: whht5obX78ZoJtuWIWxP/ceqI7gNTNjGKLQqllSovYWxhgjpzLEaUTnrRzcVFUtgay9Cbl6OyWtMxYmaojTMRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: DhSDRVyzl3VB56RqDA_Ac2WtXYx_vwbA X-Proofpoint-GUID: DhSDRVyzl3VB56RqDA_Ac2WtXYx_vwbA Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add vfio-user to x-remote machine. It is a boolean, which indicates if the machine supports vfio-user protocol. The machine configures the bus differently vfio-user and multiprocess protocols, so this property informs it on how to configure the bus. This property should be short lived. Once vfio-user fully replaces multiprocess, this property could be removed. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/machine.h | 2 ++ hw/remote/machine.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index 2a2a33c4b2..8d0fa98d33 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -22,6 +22,8 @@ struct RemoteMachineState { RemotePCIHost *host; RemoteIOHubState iohub; + + bool vfio_user; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a97e53e250..9f3cdc55c3 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -58,6 +58,25 @@ static void remote_machine_init(MachineState *machine) qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } +static bool remote_machine_get_vfio_user(Object *obj, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->vfio_user; +} + +static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + if (phase_check(PHASE_MACHINE_CREATED)) { + error_setg(errp, "Error enabling vfio-user - machine already created"); + return; + } + + s->vfio_user = value; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -67,6 +86,10 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->desc = "Experimental remote machine"; hc->unplug = qdev_simple_device_unplug_cb; + + object_class_property_add_bool(oc, "vfio-user", + remote_machine_get_vfio_user, + remote_machine_set_vfio_user); } static const TypeInfo remote_machine = { From patchwork Tue May 3 14:16:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835850 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 CF694C433FE for ; Tue, 3 May 2022 14:30:15 +0000 (UTC) Received: from localhost ([::1]:41246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltXa-0002ND-UA for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:30:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLD-0007qE-0B for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:27 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:27802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLB-0001OJ-5A for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:26 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243CDxw9018740; Tue, 3 May 2022 14:17:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=onV3Igl2TI+BzyyyLln/oXxujPwDe5TMz1+dKgoQ9H8=; b=boB84zhyrkCDIHDRVobZrvnWF3SRLsXLRpsRYEdlOBPyABP2DpXtPlOsWEw82pVHA7Wk yitzpEmHwOgYGruIVJ/NIRbCzd44KNl3nQgOg6MYrPuGgCw+9VBlsH5Si/tGmn/urFsx HNTGzRuPGxwvPG85Ft1L4cKXZBewaLjIY8a26i6VMOAw1zpnroHoL2hXuVELPMMhWpZn mlrGvxX8pCs4pb+4GUGZzu+AkBv6ij0JpmWclnPV4/bMZ8Ors1m+0aQbzILeBBa3CQdj EquIGir7KtKl8+czyl47jDk252uUvsxa5t3qHJ2aLs7AOTqLr28Sd/+Bk/rth2DcfMsG Jw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frwnt5rw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:20 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG2GS032480; Tue, 3 May 2022 14:17:19 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd2tv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LPIxUZOUKaZSjvVgUXaY99XHWsSVYv/fZicuI/5n0rPwN4yAiM50oXEuZeMfcU/Vf+IbYgHymIcxCfb73CHPwH9OQGCujhkkeccHFpcBaVv18QR767p9+7hT4arVCuAMtq4qYPW2RBnKTctm2bDLKFDqFl4nAD25lQvVincDNNke9NpRkiwxalG+JwEEBosrc/BhWhhDwWiSYkrAT1TOYkVnDOs98cxqeS8sEJiVCNcZYhcYyOL6FV61ezfga858DprMavtouawMtjWOhpKG+VHyIqH6DgEzLtkqlP5pCjdbu4WAbS4KW+aIwRAbaw96cbUgGrsB9AQVs03VRCrxUA== 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=onV3Igl2TI+BzyyyLln/oXxujPwDe5TMz1+dKgoQ9H8=; b=V1ZNiqK8iV7LDjGFP0vvsWODAx1Q7BtCpD3Iaju1weXY3sP6qvGdHcSEdRuo2PV5EMoLhYmp2SUJXmtqmQ6s9NdvK3mXNqssW60X7E69V4si46SvxcE2h+IXe/4c32fsn3gtgBkk/n7rMbDB0CwXxF5eJE3yhJnVsneMlILGK0HjkW5UKB8br8QF49stVaWeOas5QqKAP0ElxtIyICybkVXIVeMingychmBQSJQA34kJIaPEtOcm/iehsMSn1ihDN51SX7zgVu+/9Px8zb/o8kYpxzt6heHpi4jL64ot1TFC5oKrAgUBpthDwXtR2supuIvJAR9VNH2ea1EY5MCvxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=onV3Igl2TI+BzyyyLln/oXxujPwDe5TMz1+dKgoQ9H8=; b=s+ecmMCqHibXe4fgQpUFmP7p2Np5C+WzhGnwuidtGKZ7079mZEs+22ePtwUAwlctyKZiUoW2mvoN2qcW7oaHVBjw5PF45pQsc5cEOOxabz2jbJ8kj9PnwEsF1/LPoQ50Y7S/0xLOH4kmR1V1RKYD6TbbJGbwekJyX1hW0khpA4Q= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:16 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:16 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 05/17] configure: require cmake 3.19 or newer Date: Tue, 3 May 2022 10:16:46 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1228a370-6f4d-4f17-c648-08da2d0fa05e X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uiUws35EiAC2J2tbjELMzGRXDH5hzEDaxI6lHR2dzsRZAmOM/DUkKwfpAm/x2fi2sPM/VE2zL6hOvOJ8pffsSAa4N+NX1NWM12mOFLoNKdZxSHi3qLmr7BZM+mqCLLmmN3jQj1b//3Izg/buSczeqaWfgraeSALq1mED+bpzNzbr6l4UBwuSRxGcl7+uhFRHMs1+qsp1nvncHO1YbWKTrBmR0w88Xkggs2Bsj/esMei6qLScWSGStXtECLzXPxiFxedzXpKe+iVnEHNSww5YO9lmrEj3n/e5bzGsb/tW7WIC8Y/t/slAyuWWwQDM2w/QfPvgYuhaqwOf5EiuR98zOiBdJ04Z1q6o303rOO+iZLJWqdZm91Rs1HalVo/bosKafba+dZGkPBYwDGi8VMvDhvxcrlWzzraYQf8meHEfWqId7VzahDR91wircsswZkDJINa6IltTWjJZNugBmMFPYYSv3R8fbSVJt2nLdFC/q0lxAFnItzfjhzQfpEByMx3/02ScBblA6KdmviPNuL0VddWVLkvLZJqLEdaJ4AoocJEBFuFF/bEcPR4/hQVBgGojIAnW6zce3Mv6wOVXTxR8J27Jc+FsUFcYFQ5OR92z0Bgeq4D0ep5LgQVMPXmCRlSDMcx4RYnM5nnoRXDyrMN+TI6o/HpYYb0RJdvflAvNaukiQQMYh6vHBO4ZUQkDHjajas63W/aWo/qWy2uPQ9f8Pw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zVpQpHGjoTueqyoMvGBcDqimxaCGv/6j12WalfeFIuTULtfyEnux1kRzdonnCui3cGVCItCOIFfzMcUyrEqZRZU295UGIa7qMZGskw5Nabv1p8MfOrfXL6/3cibyGd5UVScSZkf0bbkVwjVTERhJuava+ktCpl0WT67+rQVJnspu/93ulNu32LlaiyFhQz4lFaxuqO9sEL7+4/07+E3KuPGewQTzG+o2gu29Pkh+CRvu9a/sY8zZr+dwXlaGifpHfJezj/HZCsrVdWGCTERUONuNto/KPQ/l9s9GeJig+6uOe901dcbsAWEANPGQnJ70KGvIL85ANAou7MiVl+60y6doPWjhKjkvGyn/jlDRYZ0lQPyF2+HQ+WF8CtztNIqwFzRCqFYuwtn4Pu20Ac8y5K2FmwPZ399J4HRSAnwd/78SvTWd0gQep8s2bxiLKTrBRPUYceWN6ciqG22pC7S+0vUCi1KoHk5U4lyZW4tnIUR40GHhqLpUD3XrB9JM1Yty7pzefUgp5+UUcnEsL1TIemtqmHoU+UuPZeGkwej8guMIGvXvmhqQCQ70qkrhc9SrFAC5T1duvq++SZlfNF6RIQkAnVWIVW1wBoMy+Q9MjctLB5PncZ2kmjpsax4QE+iSu1FgjlXbSo4LFTu1G71Mph+LXl4bOpMlblmRCOZHuTGLLP8MwQcF9eeRvnPbqcmu0S1vWXsq9coHKb9q13+co9YLvYB5zjgzhAjafWisnpdq+o1rUN11tjISosZcCQVA88EKqko6srWCQkKKegwnFKfxfU/XJ5knJ1IBqnYPqeo68gASkOgtFnd7RmA3JfKWFouhd+3WZno2KHKkUtr/eeNTFi/34CH5VJum1iPuEmV6Fb8EhbVhLHL93LsQPryNRkzMnRSO5cZCYblAYqO3bMhsGx8IhhNeYjIbpUjH4ype+KZ4Wn0L0qICzHcyEZz8R3NRZU7MF4vG4q7F0IIMtWkkTsiJ51TMgtboRDd/uEXW+bGlyKNJg3KNR+ApJiFuQmYFVs5ATzDrzrhN/q2v5wBEx1okH5fl/jwG37sM9DP9pd6coa8wd9DHqBiXMuuHCanP3PTpUin3soqNRJiYNJvkj1pumaDxAlCQS+ARBoDW9xhUYmXTCfZCQNsDeYaR6FwUB18sB8qKCB/wtsjGw7HeZXaDn9x4CFgYdp2lI1PjxNt08JbwjxhgDpq1gQ2aZZxIpJXhZFkreKikZwrT5eBW36u8qzFM2XdehgwGgD9+LEMwd/zKzdgw7r8CVL2q4XsNyj1L7hsMD5OcFAD143hEgMkt4jEupDW3G0cPyUQrJECJXY9tW9crBgpEcHzleNRb8WHj7deNnjGoJDCGktgesF56Wo8fajWPR5KLu5M/4YhmgaWv+m8uK76aF6UksxAqC2akhXnELR35HRdySvug1eogpGCps8fbmGVizGOIdM/Y7fay4yjZzlYvBgTsk1+CpjzcZOPxlu/R9cPLCrx2inxHtOm7bEx/5ivYkdo1m1pOEVm9tjr2OvKpUGstgVuxfU34PAv4AZlR8bW2MIMPLQ9HdqQBCherFVHp5UoLauGXk7nRKWIZ0mGmFKuUH7mFDGATJZSeooJl/hvQbBbjXV2qhV6G1XXSMLyikHVGS/vclC56uSFbydBjGQm+1AkoYp3RbEOwqUsrBt7iGgV49yxAZ+R9XP4edB8FRhkZjaH7zqnhZ4MhvTBbdiN2vWvqW0aHswxmKR/I8/o9fg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1228a370-6f4d-4f17-c648-08da2d0fa05e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:16.6702 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ENjeAAPasvzNCOXFYPXbeyAYtA7QbuduX4/BokWfwr6ztT3gbSuz0Bdokm8TLq9bYtxU0UBpr4NWgqU5B8UwQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: 5yRIilnZvv0l2irsf232ItpOisny4Kg4 X-Proofpoint-GUID: 5yRIilnZvv0l2irsf232ItpOisny4Kg4 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" cmake needs to accept the compiler flags specified with CMAKE__COMPILER variable. It does so starting with version 3.19 Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- configure | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/configure b/configure index 59c43bea05..7cefab289d 100755 --- a/configure +++ b/configure @@ -249,6 +249,7 @@ stack_protector="" safe_stack="" use_containers="yes" gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb") +cmake_required="no" if test -e "$source_path/.git" then @@ -2503,6 +2504,21 @@ if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" exit 1 fi +# Per cmake spec, CMAKE__COMPILER variable may include "mandatory" compiler +# flags. QEMU needs to specify these flags to correctly configure the build +# environment. cmake 3.19 allows specifying these mandatory compiler flags, +# and as such 3.19 or newer is required to build QEMU. +if test "$cmake_required" = "yes" ; then + cmake_bin=$(command -v "cmake") + if [ -z "$cmake_bin" ]; then + error_exit "cmake not found" + fi + cmake_version=$($cmake_bin --version | head -n 1) + if ! version_ge ${cmake_version##* } 3.19; then + error_exit "QEMU needs cmake 3.19 or newer" + fi +fi + config_host_mak="config-host.mak" echo "# Automatically generated by configure - do not modify" > $config_host_mak From patchwork Tue May 3 14:16:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835847 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 5C05CC433FE for ; Tue, 3 May 2022 14:26:25 +0000 (UTC) Received: from localhost ([::1]:33974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltTs-00050p-Bb for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:26:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLF-0007xK-SR for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:29 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:33266) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLD-0001Of-AN for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:29 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243B8Mvw029440; Tue, 3 May 2022 14:17:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=91StVAABZPdaB0Npp+prlgomuvSyaDsx6H3hSLZg2ss=; b=Y3Vbxcib4BoM6gaPX3dZ23vknV6zKQMCv2ToNANt+SCCLyMZYo5j6i4noIod4v74KSJ6 XTTMObJeEhWg+ygpVvckFycG3rsAhrl9r1XC5fJYPli/nQfOfZrU2c8v1D1Ni+TnpM08 dghVw8y9s0oGomaE7g2JUgSaLQNhHT+eW2adiiS0jkO2Cut7SQBr6Lsqs4awmichTRlS P5Jz/WlfxpaZlZuYnrK5rEdBC0JfHpwmxg0YdBfmYs4pGIE2RYRVljDD/eg/delW7aOD mQDdl/qUcUKS1O3x4AjzT6HA33iD0xwvsEz0pZOgWQ9zMOgE4/DbXkF8Nb1uYbrPB/az jg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtp8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:22 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG2Sb032476; Tue, 3 May 2022 14:17:21 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2048.outbound.protection.outlook.com [104.47.57.48]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd2v8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Iz0BZyXpPf0GuCqS1zfn2jJkqucO8Fc8r+t7+mLAKmVxpDQrlqUvgyEP35e/ExkMGKVqXm9tW+bWFZe/NZJxWA9pb3t69cE0izxOEpdZB0w3YaVuaqbcHMv53Ea1NfuZMhenq8LIGB4MvRXUbmOZ85tAGJgy/fmGAov/M7lB+mQiyUdzoluJfG63ipG/OiTZ69Iv8aiF/2z3/yXfy6A8OaN681izXampsGV/oEuk/WAkscwCgM84sYU/SI7aXOq2VmdarxQ/GQC4TqFHPomUZdKbHyD1lbu/GS58XQCQUdmAiSVCKAnPZcufFlFzF/iEmyOpRW+nzwriFUXi9ChTtA== 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=91StVAABZPdaB0Npp+prlgomuvSyaDsx6H3hSLZg2ss=; b=aq3+OMSnJU4RZbJnrRSTDo7sK3VzarTMReF5gS2CQ3LIH3/LHHxC7uLpqK8lqXNYqEhk3o/2yc3R+yak8NhcQYoeewZHwMPH50f916kKHYNF9Bu0u0K30pUr95ja89HA36EeEph0LsNTgbIwj0IX8p40OegFZRa2PMC/tgykhK4eWSo79636dWQfPeUe+qt0aJYUoMNLpi3FhHv5lIu2ZZWQ7oHbH8MzAO7RSOZBKpH9bu5tYvFhjQ/PsV9YZIqHI41oLzzrnXzRxxj5eD05eZ0A1pACRhYIH3zb6DmiCYZAtVg6W6YT318tRJRGKrHHPZ3rXR+mmJcZyIYdMPEa/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=91StVAABZPdaB0Npp+prlgomuvSyaDsx6H3hSLZg2ss=; b=UavtAYXahdVhS6dawAnfxYEZ+1x0PmH1kVLZweCzqBTK7Jj45/9jI6ZcyfYPOE6MpXN0vYlnd5EfPXppB5CSxZ4UuXu2LuehbPGvMIP2tX8Ro3PmccFCMuQAVkQAVejil0MRUaGMk6qbHoEjURsk6ljztzxGkD6OrMkMcGiQitI= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:19 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:19 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 06/17] vfio-user: build library Date: Tue, 3 May 2022 10:16:47 -0400 Message-Id: <7560757f7e08842bbfc78bafdee6959f2ab43f80.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 224cea7a-cb72-4732-3784-08da2d0fa1dc X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xnrZ422vnW1NHpzafeH3id+ruoD5a39NdEFw/tdVG7qUpgKAfr+wfhwz2xmJE2tNchhTK6R2/hbxs6mxeGgguPGcXI9U6i0TdOFM+LIG+Q5xdeXwDKbaSZF5DolojjnBZuICCSCMKiRpo4f2rIz2Q+U1z96I+gBnjPx64x8iKiF/LRZCcNMQyWJ2ogY8m8Nad2JoNBAZxj9zygatEyABG2no40Fwb1mCmxUprzexzFgv/fr2NpqN1f9SCI0+lEKowDdQ6yI0xxPO/F1es4HOp66O7Y3aImZmSHmWAZogjifsS5JutgnpyDPx2Nk5pLGRZRozR7ZvvKqUJ5SHU1OWaqeQlxdw8YUVUB9Lu6DTXP/mGQZ3W1OE7RJe9E9piHv2qSIVaAD+A/XgPSOBuFPgEAQ36BhOqL5W3YtGFFxj4dqZM+7Gi2YPBjplyUqpCxlYeMJNVnF7g83/0gt15rIRSsCu5UyxAkzd7ick090tgU4mXLadB1egcsJp64z5l7rIhGDfTVZCelgukVWCFVncrOCoy538iRuKbw3mGR2uTQsALzkIdQH2fmhvein2n5LHNJblN7YLz1pJNpSKmka9kuoAzi943OFhO+Eo6mBbcCR00Cx2vVhi14v28bS/DE+2oddlDdJ5mvfxubGzmW3x6lGfNyuEKfWcIWLth/VFBxsDIZuhmSNLxIOWGAAFyh/5mkfWdNL35lRLMWDzpbI61N+2YZbJDyycUwGsofwdPiNkAxzO1wcWYzmEu9KDINVLx+HYpOUqTFBTYGmP6Y4ndyrEkm9uEox09MHq4j1Pp4SWfUFKN/i6bzxBDmo27Yyvn4c4GooZLTzsvoST2ixyhjkehlcVX/RqPY2jFa8PJyY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(30864003)(2906002)(966005)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rQapH3X3t7op6rP2HbtsqNO1luRTE6fndhH82yY7qeQE0WGd+cD6Mm3ryAlKs9Uia2bU3Epr1CWNnjdDY7P5swnNUSByqsSs00MAv6vFjth0/HZtc98NqTWXF8lORStkWsmqnLEYNyFNFisrYe/8GdwwSAV7wiuwKnHqGOGzlNVWVDDfp9ERGkBrfn28NUbn42QmSTi6hPJnE5pL40cVXeVpa9yb5x5FkJO+FkiNX1FHHQUOPGuHx+LGeeVKeGTLh1LfZGUpST+XMfAbUOb3YaluG/tFO/cA4MIYd5eR7q1Tjo9ZAp7iycRNQ0ITSL/XpqYIidHgh0ARvBTx+BMEkKOGrUKY/GnJvdNBniQRxA3WV8EQUBmSLWcitrAEcK8OYbl6Lo2nyBbPjuS9TKS+aMOXQcOqpqGwZWkMk2QvvmUJD74cO+XtL54ode6lGVYX/pU/NJFjEhiacC+2lhBD596Igo1jIa4Cf30E1kBjvNjDmK+3w9FHvywICPd/tEN2yN1oI25BNoEZpnvZfYjc3gpRNMJjdDFvs1vlcf5MifxeB4MYXyff2t2m5imgz8RGsDHhRusfxUy+PQmmo/AQYTfBpJZmCDOGAGR+o9FlRT44qimRnIO/z3Jq4T2qCHcO2PV/ILQtonrEsMoY6shFjgo6F2NLcFYI8+xzi7Pwwc2P9UuQ8hBgIcK2zEHGF243E8thS3Qgj0+1/HjLDxfq5A0yvkbXS7oVKj+KSwIig/m8Zzj4J9E7q9UA3jzYVgVSm/4w6WLkKAPuOlzmfrG1GEn4lq+w+dDyxmgzbMoPrnnO5zqho5oGDJnJtJaBrADAh8eCYwCmOU9vzJqb74VrNQwqI5SJwImgz3dr4OZ+yt3T9Yzjt8HK1FGjmUFUcF7xITeZ6u6MKOtTXodED/xyNFk4qhohAFU5wHS/dm08hwL52skVAafvjq8Oi/L+4Wwh54FpAekTmimx9DLM1gvbfdBX3hy7gYunnbiJ2xh4brw3oQmLBmD92EXq6pmfHmsT0HBaI3YH4sIYatoj9DU1y5nUhRqgvuoB1/wn4DATjLX8wz4a/64nD3U4brY8rgtaISYM/Xiy7wl+x1/GWGZ+1ospPn0KrYMCktXDDab/AQTbh7NHiQ3hI43UMRJtjV4oByEkg15GFIGcJSTNFim7FOR5mrL1CTHDJAM7Tm+ceTX1av8x6qkXv+riYMA4C4W1xyElSRDYmxOl6kCIXMGQKqmOzbvewV0LY1qi+nhBxk7F9K59L/b/JLLx4wot1fIy0IYBvnDJ+c5zumv5N1y4yyHdk88fJzUj5K/7GLzNj2b4IVHctOuXxkxHvtfAolFIf5ydtljG6eH7HyTF5mkvJ0Qux87KUg37xBEo1DswN2Da6kn3HzqhH+W+lkJCtoSuFPQuSgtq2h4ajgj7YU8Si+mTkylkpfEioL2duBQ2bl7d5nfqqLc4K6j2SgKgLPv/ZRaRcqImEERhDoDa7dPCUkJrjisVDfVQRkl4lRE+ICgeYDu8ecLc7bgNZ2QIRrGl89cNjf7qSJ0QczoF79hmpeINpEYUGrXR/7RKZBR1kode5y1jozOxPJZQJsEvze8FCHBdNzrPDapMeOy3PI+bo9wACpN1i/xp4VFntNMqp6WhbTFKLt4LCSiyT5n2hKSqbFWOcoC4U/FnurorafmH/qtf7qjHSiOh/ClNqrKT7o+5pLLnghqn3zPIpv2kC1KX18HcfOZu/WKU/COIOwQOcg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 224cea7a-cb72-4732-3784-08da2d0fa1dc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:19.1388 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 47pPyX06opSPoKIQrKy1ukcXXy7d+Z/B48NJ0x2A6hAAMmM91rQ/YepLiDLxizdgq+9qE7uMdd6G3+Eco2umQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: qJjWnRLxC5FBtPkyFwAwuyXCNZPLN_aA X-Proofpoint-GUID: qJjWnRLxC5FBtPkyFwAwuyXCNZPLN_aA Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" add the libvfio-user library as a submodule. build it as a cmake subproject. libvfio-user is distributed with BSD 3-Clause license and json-c with MIT (Expat) license Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- configure | 20 +++++++++- meson.build | 44 +++++++++++++++++++++- .gitlab-ci.d/buildtest.yml | 2 + .gitmodules | 3 ++ Kconfig.host | 4 ++ MAINTAINERS | 1 + hw/remote/Kconfig | 4 ++ hw/remote/meson.build | 2 + meson_options.txt | 3 ++ subprojects/libvfio-user | 1 + tests/docker/dockerfiles/centos8.docker | 2 + tests/docker/dockerfiles/ubuntu2004.docker | 2 + 12 files changed, 86 insertions(+), 2 deletions(-) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index 7cefab289d..3b096f1b94 100755 --- a/configure +++ b/configure @@ -326,6 +326,7 @@ meson="" meson_args="" ninja="" skip_meson=no +vfio_user_server="disabled" # The following Meson options are handled manually (still they # are included in the automatically generated help message) @@ -1008,6 +1009,11 @@ for opt do ;; --disable-blobs) meson_option_parse --disable-install-blobs "" ;; + --enable-vfio-user-server) vfio_user_server="enabled" + cmake_required="yes" + ;; + --disable-vfio-user-server) vfio_user_server="disabled" + ;; --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc ;; --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc @@ -1226,6 +1232,7 @@ cat << EOF vhost-kernel vhost kernel backend support vhost-user vhost-user backend support vhost-vdpa vhost-vdpa kernel backend support + vfio-user-server vfio-user server support NOTE: The object files are built at the place where configure is launched EOF @@ -2350,6 +2357,17 @@ case "$slirp" in ;; esac +########################################## +# check for vfio_user_server + +case "$vfio_user_server" in + auto | enabled ) + if test "$git_submodules_action" != "ignore"; then + git_submodules="${git_submodules} subprojects/libvfio-user" + fi + ;; +esac + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -2854,7 +2872,7 @@ if test "$skip_meson" = no; then -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \ -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \ -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \ - -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \ + -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp -Dvfio_user_server=$vfio_user_server \ $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \ $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \ "$@" $cross_arg "$PWD" "$source_path" diff --git a/meson.build b/meson.build index 1fe7d257ff..55b872b51e 100644 --- a/meson.build +++ b/meson.build @@ -298,6 +298,11 @@ have_tpm = get_option('tpm') \ .require(targetos != 'windows', error_message: 'TPM emulation only available on POSIX systems') \ .allowed() +if targetos != 'linux' and get_option('vfio_user_server').enabled() + error('vfio-user server is supported only on Linux') +endif +vfio_user_server_allowed = targetos == 'linux' and not get_option('vfio_user_server').disabled() + # Target-specific libraries and flags libm = cc.find_library('m', required: false) threads = dependency('threads') @@ -2204,7 +2209,8 @@ host_kconfig = \ (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ (have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \ - (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \ + (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ] @@ -2596,6 +2602,41 @@ if get_option('cfi') and slirp_opt == 'system' + ' Please configure with --enable-slirp=git') endif +vfiouser = not_found +if have_system and vfio_user_server_allowed + have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libvfio-user/Makefile') + + if not have_internal + error('libvfio-user source not found - please pull git submodule') + endif + + json_c = dependency('json-c', required: false) + if not json_c.found() + json_c = dependency('libjson-c', required: false) + endif + if not json_c.found() + json_c = dependency('libjson-c-dev', required: false) + endif + + if not json_c.found() + error('Unable to find json-c package') + endif + + cmake = import('cmake') + + vfiouser_subproj = cmake.subproject('libvfio-user') + + vfiouser_sl = vfiouser_subproj.dependency('vfio-user-static') + + # Although cmake links the json-c library with vfio-user-static + # target, that info is not available to meson via cmake.subproject. + # As such, we have to separately declare the json-c dependency here. + # This appears to be a current limitation of using cmake inside meson. + # libvfio-user is planning a switch to meson in the future, which + # would address this item automatically. + vfiouser = declare_dependency(dependencies: [vfiouser_sl, json_c]) +endif + fdt = not_found if have_system fdt_opt = get_option('fdt') @@ -3708,6 +3749,7 @@ summary_info += {'target list': ' '.join(target_dirs)} if have_system summary_info += {'default devices': get_option('default_devices')} summary_info += {'out of process emulation': multiprocess_allowed} + summary_info += {'vfio-user server': vfio_user_server_allowed} endif summary(summary_info, bool_yn: true, section: 'Targets and accelerators') diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 0aea7ab84c..671a5d8fa4 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -42,6 +42,7 @@ build-system-ubuntu: variables: IMAGE: ubuntu2004 CONFIGURE_ARGS: --enable-docs --enable-fdt=system --enable-slirp=system + --enable-vfio-user-server TARGETS: aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build @@ -165,6 +166,7 @@ build-system-centos: IMAGE: centos8 CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system --enable-modules --enable-trace-backends=dtrace --enable-docs + --enable-vfio-user-server TARGETS: ppc64-softmmu or1k-softmmu s390x-softmmu x86_64-softmmu rx-softmmu sh4-softmmu nios2-softmmu MAKE_CHECK_ARGS: check-build diff --git a/.gitmodules b/.gitmodules index f4b6a9b401..d66af96dc9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -67,3 +67,6 @@ [submodule "tests/lcitool/libvirt-ci"] path = tests/lcitool/libvirt-ci url = https://gitlab.com/libvirt/libvirt-ci.git +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/Kconfig.host b/Kconfig.host index 60b9c07b5e..f2da8bcf8a 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -45,3 +45,7 @@ config MULTIPROCESS_ALLOWED config FUZZ bool select SPARSE_MEM + +config VFIO_USER_SERVER_ALLOWED + bool + imply VFIO_USER_SERVER diff --git a/MAINTAINERS b/MAINTAINERS index 294c88ace9..84b0e019e8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3598,6 +3598,7 @@ F: hw/remote/proxy-memory-listener.c F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h +F: subprojects/libvfio-user EBPF: M: Jason Wang diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig index 08c16e235f..2d6b4f4cf4 100644 --- a/hw/remote/Kconfig +++ b/hw/remote/Kconfig @@ -2,3 +2,7 @@ config MULTIPROCESS bool depends on PCI && PCI_EXPRESS && KVM select REMOTE_PCIHOST + +config VFIO_USER_SERVER + bool + depends on MULTIPROCESS diff --git a/hw/remote/meson.build b/hw/remote/meson.build index e6a5574242..dfea6b533b 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -7,6 +7,8 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) + specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) diff --git a/meson_options.txt b/meson_options.txt index af432a4ee6..e1315f9a07 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -95,6 +95,9 @@ option('avx512f', type: 'feature', value: 'disabled', option('keyring', type: 'feature', value: 'auto', description: 'Linux keyring support') +option('vfio_user_server', type: 'feature', value: 'auto', + description: 'vfio-user server support') + option('attr', type : 'feature', value : 'auto', description: 'attr/xattr support') option('auth_pam', type : 'feature', value : 'auto', diff --git a/subprojects/libvfio-user b/subprojects/libvfio-user new file mode 160000 index 0000000000..030d2f6e79 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 030d2f6e7978b8ca7577b81d4f48e2771bcd8f47 diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index 4b20925bbf..300833d8e0 100644 --- a/tests/docker/dockerfiles/centos8.docker +++ b/tests/docker/dockerfiles/centos8.docker @@ -23,6 +23,7 @@ RUN dnf update -y && \ capstone-devel \ ccache \ clang \ + cmake \ ctags \ cyrus-sasl-devel \ daxctl-devel \ @@ -45,6 +46,7 @@ RUN dnf update -y && \ gtk3-devel \ hostname \ jemalloc-devel \ + json-c-devel \ libaio-devel \ libasan \ libattr-devel \ diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dockerfiles/ubuntu2004.docker index a3b38884e3..7c6131686a 100644 --- a/tests/docker/dockerfiles/ubuntu2004.docker +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -18,6 +18,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ ca-certificates \ ccache \ clang \ + cmake \ dbus \ debianutils \ diffutils \ @@ -58,6 +59,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libiscsi-dev \ libjemalloc-dev \ libjpeg-turbo8-dev \ + libjson-c-dev \ liblttng-ust-dev \ liblzo2-dev \ libncursesw5-dev \ From patchwork Tue May 3 14:16:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835839 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 EE6F1C433EF for ; Tue, 3 May 2022 14:19:02 +0000 (UTC) Received: from localhost ([::1]:46502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltMj-000299-U7 for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:19:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLF-0007w4-BG for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:29 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLC-0001Ob-T7 for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:29 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243B7SdB013665; Tue, 3 May 2022 14:17:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=kjvFJIOvwys/UVuFncNELqzdH3RbWKhIth7UDqDKcFU=; b=aX/wVVTDHoN2yyGyRu+f1GK2ZVmjo8ru7baZ6FvfxF/GJBLKxDA2Qfymy+oaEZGss7X1 IzrwCl53s0gQqcQA5yzNUsE2K34WzujR3QQf44JvoqztQCNG3RG6txsiUbMtlsFz8pkB 9sNwNSkHNTp3LcF/ZQL4s8andIkCWRQdskXvWKzwLYcMbkKitJSUWZyvtwCIEEFhcxjH UehGoC3fqkQJb7PdP57AMRbZkNjUfv/4z5s1bYHC2nlbBDgZWQKQcNGGxLjSp0Q5RvgM i5pVw3vCR+69JoCbIItcfReKBeeCYGAMcre67CwXriSuJKtvO2Biy0TP4PGLCIgm9dqI 2w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frvqsdtg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:24 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EGRg2001680; Tue, 3 May 2022 14:17:24 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fruj91k3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JOFRgVS8GZYTbH7j391kfpNCuhupkSpCdYqU6YnqD5j+vn7+z3CQL1z/y/356K4P+W3PotPoQQlrbS5RVRpmtBf1SatjW91Vul4I4m0uoC55OQvbxQI6gT4qJv89DN5Sibn1s++RsbBDXR4dVGJsyM/5oAQYq67rnLUzSkfDvLs7itV/Ljyc9ihnHhIU5XELA+zIgbml6YoYMS7ElSJ3V5CGjduDGIFZ1uMHjWHXDmFmjxff9pnAnpHoKtUaBt+Q1g/cItpgDY+fewOvstB+zTrovkk25QxIjrE34M6rd9bmzcKGy6rIGKlpb1q67HVqsHM++w/dO6M4ZUnMR+099w== 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=kjvFJIOvwys/UVuFncNELqzdH3RbWKhIth7UDqDKcFU=; b=OU6GthxG5j3xPdj9TZWW6Bpb/Vxgywb7/dGjKFhIHs6rB6XsBkvyIXrodMNIOWtJL81pBV5stLe9vIxOX7rjxk71v2VK0DUaMLeKutvUmZDjQRto0uOJUiqD9f0K2tCNqwH+drySr85SkKQ3PQI+y5ueMEV6HVSsV74sYcKUwbLexk+3Fxkj5eh05aEnT5DrqBNGOXBmM9uEQobyksBqK0q2HPvKs8hWnPG/0l6RNxZdKWMtWEnC9IEmI8UgoNxKmHeqcewo49KYFQUGTuKhBVtEc3pBRF3nzTk+dADeJMQwf8QFTqQqvk3jysxUAcuSDt5NcSOkatq+OL7eQP7p0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kjvFJIOvwys/UVuFncNELqzdH3RbWKhIth7UDqDKcFU=; b=VAev19X/L1us6t7SPa8Q3s4/OEQ5ztUc2QmiJxWPM7otK9kl6h9VQ9BBIaZ+0ziFHllentiGrHNkR8XW5nue+dD0johSbe3b4SyJPUR5LG1hEJ0ct8eQNAh8gTiukjEdwdEq3ZSJlDipWxKh2RfCFNw++tTXqnnRCQ2MQNNha3M= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:21 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:21 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 07/17] vfio-user: define vfio-user-server object Date: Tue, 3 May 2022 10:16:48 -0400 Message-Id: <48d0f7214036d48b1f70b90a8c4a6c2a46363ee9.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cd426cfa-393a-4aa3-0b12-08da2d0fa35c X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TYQuJldPmVxsXoaXyiZkVNgwKxySas8rTgyL3dqTRhtDfLux34kIUj/AelbDLWV0uozF1CZYJ9lVmUNP1JQzFNxqrtMJXk3qsllLdvzjOg7qF0Rk6lBd8cok2MEtTxpYCPJuqv9mBkZkSx+iGGwpzYYlzEvVAc8chVAVUyLsNDPtf7HJLXlsqXSTRMuizpO65IysU8KCRK85oTkZb5PzR8B+ey6SjsIHlKqYpAsmTSOBbHtvtI60Dv4uXZ2DkP6BVg/8p/ocf8bY/GvnP0GitKejA4aLePM0FGjmZraKzr4TQKomYxgCmwK8OJ9KiZ4n+UHaxevkvHDB2hveCulNbkmdf1bg4ZhrUCVdrsvLKq19uZiXaugRv4qfGwAs4AVm+g2uIxpsgTVoEYsxjtZ5VQnqjGRegxVv+mJsmuxGzs2y+2u9l1ELEICVYiRgJUlmBa1QDqmQ5LgaSyjdG/atEqYgn4np/cNC5vx2ynCrSWO4IQS1mgC1U3SiJ5CCEhpLryywz8FZW+cHaSX692OzLEfnSb16TwVWzmk61box0c7dT16E+HccSN3kEEjf6wL4Hq1z2QjmYElnNpjI1OEc3dxLFEhXIp5jW6dcxYgs5u2jxMMT7onat3tZ4ifIhmPzbf0aCSnqBkWwuqFg+DdCsRa5Rl2skxhOvL6chiJMFuhmq291dSAkiHEn5fPmCBk0G9EOKUUDThwwXH+dFpM97Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(30864003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fczYOU0ArnHjD5Evrn20mBahrfoK?= =?utf-8?q?/L/fCMIuAHxvXgOF1t7IJePm4fOKWbyO1BqEk7NKpYF6V+KdIe/+XcnyRA+lfKlZs?= =?utf-8?q?PuZ7faHJEzZiMHCTNFOhKhrZ1dXTxe16KKVJ/jya2VGgnV0omGncuXm1wewMOXnz+?= =?utf-8?q?UgjZ8++wATAAaudd4noZh8ou9UYUuUVQsuIJm/CPupIp3M2lfN+pZ+g517qT7y4hL?= =?utf-8?q?18bQdxM3J1vfsHsL7I3FDo6WC+V6Sl20yewx1ZJskXjFUzMmyOPtA90bWFDqxGpmm?= =?utf-8?q?WXVJmW9CEgPkAhvVwiISet62AdiL1G0nfwBzTlOjiZTRnvC2x1am3Zy8GF3UnL01X?= =?utf-8?q?zCLfV895W1rWVw3djlPYMthS1hm7vf5ocniP/C7PY5EkSOzIG3BIc6pdGZy3N0Seg?= =?utf-8?q?yDswL2WvoQwk20h+E6pYzlgdlbWdSawYjwHt20AnWZyumn33Nk8ctMNbrp+XT2pHF?= =?utf-8?q?sNMQJdcILzV6sT418kr1Op0GLx0V3p09wbIEX/RDB+SFwA8Pj0XXXhBiiT+Cunzie?= =?utf-8?q?geJvAv4wfOlyX9jBnpJXpZHDhh/8XrdP9iA7Dq1rQN04JCfXWuakqNzkY4K1G90xj?= =?utf-8?q?sbJvzt7aR/Kti0OKbf+zhs7pVn3612+yjzFrNx5fZTZs8B/Z2fxPNkO60SiKn6aA7?= =?utf-8?q?i9Tz5nN5m/0wFj0/R76pnYE+P2H+F2DOy+sSrwZzS95fQPdwG5y8qVYdi7Apk8/GV?= =?utf-8?q?UP7nfT/zIubflYbvl9eurgWmSMrtU/OMdQ0xce+5yJOew7IePDwQC1940YKmCiL+P?= =?utf-8?q?YQGZjiTPYRc6gClwKR+kbDnBX0McxJjh0X/ujIvCtZU+z5/rbRFlfOz3WcyAnD8HT?= =?utf-8?q?Pg2qs1tkkfSBZfkibzZLE3epk+nbfh8pCfcJz5ZD167MlQ08wrN4qOPr/1GE/DVNS?= =?utf-8?q?8FkwW1bXLJUgaBExEhyQDv8VnfTpnBn8G7tAkLxjnjdU1sIIGYIHmb4TkWsQivCov?= =?utf-8?q?XZNJF/iIMlLwk1Cg2HveVmKVoXncTA9rOYi4wTABHlf8PS5W6d3g5m/EIqF0LbFeN?= =?utf-8?q?t4nmt4GeAkHcd86GEfMSPNJHMjK8r45GGG2q3OddpMr9jF6RxAORUyHt+S7LpC7ZT?= =?utf-8?q?n0g99x5bdm4IOssouR5Ug0TOt6jRLy/hdZrqLdjHwzf8CZeSajLFB7WqCEZaLcPCB?= =?utf-8?q?jWueFxR5KV8OrUfZD/M2703G5SGpq/w2lZKWitXLqyqBjUVjwdgP0WPQlo4NhBhvu?= =?utf-8?q?+69kEG1aqcbYGIOUVG8w00FSiWDzFaApcCtQ1/WlmpyuuioCP1n0nGOaoTEKqXA61?= =?utf-8?q?qV3b2GbOkq6kxn3NcTVSsQDZfh63YBkji6d4TWcZbDTUVhpo2KMzUN5N1MV0cOZEb?= =?utf-8?q?cQH82TdaZ93c3eJDytPn2uObGOxqAgPJspEj2cLGAwzjH7L4icR1CAb+FieCpVyLE?= =?utf-8?q?PiIUtkbxMgBWFoN5Cu3eyuRb74qu0pv7zSP3tyhHTvRqykY5a+wwYlcwexuzbf7s/?= =?utf-8?q?lKVWUA9p4HWxg5x3qk7xWwocCAx8+EpeZ0zHZvRgrbXh2hEmQ+6iEccTNcN0FGeBZ?= =?utf-8?q?OgpUB3rLAYLWR6ReliDelZ2Jq4WyQTmpYKDpW7Mn45zvZqKnMRsZtNGi91cw26NAL?= =?utf-8?q?ul1Vn7dl6a9B7jPrX16bIDSpuWskrmrCHsNzKNsEoodHJeXlk0L3SL9zSZc5wECsd?= =?utf-8?q?jOLR+bJvhYhovOKDkMdggsaxq94GjweA=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd426cfa-393a-4aa3-0b12-08da2d0fa35c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:21.7480 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qZwqZGzJ/8hZcD//+PaEKMrPyN5vxG8dSpxmN27vqau4ucWAND0jRGwNo1+PLPni0bMBdYJREUI4evFifiMlcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: JjP9VKYrJRD4L3CULnrlLPI3zwXT4mxO X-Proofpoint-ORIG-GUID: JjP9VKYrJRD4L3CULnrlLPI3zwXT4mxO Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define vfio-user object which is remote process server for QEMU. Setup object initialization functions and properties necessary to instantiate the object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- qapi/qom.json | 20 +++- include/hw/remote/machine.h | 2 + hw/remote/machine.c | 27 +++++ hw/remote/vfio-user-obj.c | 210 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 7 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index eeb5395ff3..582def0522 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -703,6 +703,20 @@ { 'struct': 'RemoteObjectProperties', 'data': { 'fd': 'str', 'devid': 'str' } } +## +# @VfioUserServerProperties: +# +# Properties for x-vfio-user-server objects. +# +# @socket: socket to be used by the libvfio-user library +# +# @device: the id of the device to be emulated at the server +# +# Since: 7.1 +## +{ 'struct': 'VfioUserServerProperties', + 'data': { 'socket': 'SocketAddress', 'device': 'str' } } + ## # @RngProperties: # @@ -842,7 +856,8 @@ 'tls-creds-psk', 'tls-creds-x509', 'tls-cipher-suites', - { 'name': 'x-remote-object', 'features': [ 'unstable' ] } + { 'name': 'x-remote-object', 'features': [ 'unstable' ] }, + { 'name': 'x-vfio-user-server', 'features': [ 'unstable' ] } ] } ## @@ -905,7 +920,8 @@ 'tls-creds-psk': 'TlsCredsPskProperties', 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', - 'x-remote-object': 'RemoteObjectProperties' + 'x-remote-object': 'RemoteObjectProperties', + 'x-vfio-user-server': 'VfioUserServerProperties' } } ## diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index 8d0fa98d33..ac32fda387 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -24,6 +24,8 @@ struct RemoteMachineState { RemoteIOHubState iohub; bool vfio_user; + + bool auto_shutdown; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 9f3cdc55c3..4d008ed721 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -77,6 +77,28 @@ static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) s->vfio_user = value; } +static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->auto_shutdown; +} + +static void remote_machine_set_auto_shutdown(Object *obj, bool value, + Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = value; +} + +static void remote_machine_instance_init(Object *obj) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = true; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -90,12 +112,17 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, remote_machine_set_vfio_user); + + object_class_property_add_bool(oc, "auto-shutdown", + remote_machine_get_auto_shutdown, + remote_machine_set_auto_shutdown); } static const TypeInfo remote_machine = { .name = TYPE_REMOTE_MACHINE, .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), + .instance_init = remote_machine_instance_init, .class_init = remote_machine_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c new file mode 100644 index 0000000000..bc49adcc27 --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,210 @@ +/** + * QEMU vfio-user-server server object + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +/** + * Usage: add options: + * -machine x-remote,vfio-user=on,auto-shutdown=on + * -device ,id= + * -object x-vfio-user-server,id=,type=unix,path=, + * device= + * + * Note that x-vfio-user-server object must be used with x-remote machine only. + * This server could only support PCI devices for now. + * + * type - SocketAddress type - presently "unix" alone is supported. Required + * option + * + * path - named unix socket, it will be created by the server. It is + * a required option + * + * device - id of a device on the server, a required option. PCI devices + * alone are supported presently. + */ + +#include "qemu/osdep.h" + +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "sysemu/runstate.h" +#include "hw/boards.h" +#include "hw/remote/machine.h" +#include "qapi/error.h" +#include "qapi/qapi-visit-sockets.h" + +#define TYPE_VFU_OBJECT "x-vfio-user-server" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +/** + * VFU_OBJECT_ERROR - reports an error message. If auto_shutdown + * is set, it aborts the machine on error. Otherwise, it logs an + * error message without aborting. + */ +#define VFU_OBJECT_ERROR(o, fmt, ...) \ + { \ + if (vfu_object_auto_shutdown()) { \ + error_setg(&error_abort, (fmt), ## __VA_ARGS__); \ + } else { \ + error_report((fmt), ## __VA_ARGS__); \ + } \ + } \ + +struct VfuObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; +}; + +struct VfuObject { + /* private */ + Object parent; + + SocketAddress *socket; + + char *device; + + Error *err; +}; + +static bool vfu_object_auto_shutdown(void) +{ + bool auto_shutdown = true; + Error *local_err = NULL; + + if (!current_machine) { + return auto_shutdown; + } + + auto_shutdown = object_property_get_bool(OBJECT(current_machine), + "auto-shutdown", + &local_err); + + /* + * local_err would be set if no such property exists - safe to ignore. + * Unlikely scenario as auto-shutdown is always defined for + * TYPE_REMOTE_MACHINE, and TYPE_VFU_OBJECT only works with + * TYPE_REMOTE_MACHINE + */ + if (local_err) { + auto_shutdown = true; + error_free(local_err); + } + + return auto_shutdown; +} + +static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + visit_type_SocketAddress(v, name, &o->socket, errp); + + if (o->socket->type != SOCKET_ADDRESS_TYPE_UNIX) { + error_setg(errp, "vfu: Unsupported socket type - %s", + SocketAddressType_str(o->socket->type)); + qapi_free_SocketAddress(o->socket); + o->socket = NULL; + return; + } + + trace_vfu_prop("socket", o->socket->u.q_unix.path); +} + +static void vfu_object_set_device(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->device); + + o->device = g_strdup(str); + + trace_vfu_prop("device", str); +} + +static void vfu_object_init(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs++; + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_setg(&o->err, "vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + g_free(o->device); + + o->device = NULL; + + if (!k->nr_devs && vfu_object_auto_shutdown()) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static void vfu_object_class_init(ObjectClass *klass, void *data) +{ + VfuObjectClass *k = VFU_OBJECT_CLASS(klass); + + k->nr_devs = 0; + + object_class_property_add(klass, "socket", "SocketAddress", NULL, + vfu_object_set_socket, NULL, NULL); + object_class_property_set_description(klass, "socket", + "SocketAddress " + "(ex: type=unix,path=/tmp/sock). " + "Only UNIX is presently supported"); + object_class_property_add_str(klass, "device", NULL, + vfu_object_set_device); + object_class_property_set_description(klass, "device", + "device ID - only PCI devices " + "are presently supported"); +} + +static const TypeInfo vfu_object_info = { + .name = TYPE_VFU_OBJECT, + .parent = TYPE_OBJECT, + .instance_size = sizeof(VfuObject), + .instance_init = vfu_object_init, + .instance_finalize = vfu_object_finalize, + .class_size = sizeof(VfuObjectClass), + .class_init = vfu_object_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void vfu_register_types(void) +{ + type_register_static(&vfu_object_info); +} + +type_init(vfu_register_types); diff --git a/MAINTAINERS b/MAINTAINERS index 84b0e019e8..1b5719cd89 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3599,6 +3599,7 @@ F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user +F: hw/remote/vfio-user-obj.c EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index dfea6b533b..534ac5df79 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -6,6 +6,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 0b23974f90..7da12f0d96 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -2,3 +2,6 @@ mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" + +# vfio-user-obj.c +vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" From patchwork Tue May 3 14:16:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835859 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 7DB5FC433F5 for ; Tue, 3 May 2022 14:33:43 +0000 (UTC) Received: from localhost ([::1]:47104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltaw-0006sF-Gi for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:33:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLP-0008Nk-6A for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:39 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:57284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLN-0001Pp-1r for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:38 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243DAHbx019339; Tue, 3 May 2022 14:17:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=xnB+AvqBNhF8TzrG5Kv5da0R1liwDMiDrkymTAawt+7CugE0otsotyZ4zXQ4nrJm/03u a1yymKiHn6UnIPodAwcxeglxdRqtN39Kyx9fSklStF7M8SNGkWuZwoa/nz88YXUhofDI LJCHe76Wj+D4nvnHwR1jpH51KZj+KisOCgktd5Bg4nvvENCHMYMIdR1PKakrIlRmtYEm u8n1wuAUgsJMhElA2iFMSb5YgnHKAngVOGnhit8xVDQjM1hlD1Fol9lSMztV7VZXJQWu xhi546rVbnBSW3pBQWntF0QHku4rAvtAWVVg/obJtfDKnwhPVI0hTWWvcve6xmwrBz6Y 2g== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frwnt5rwn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:30 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG2ek032474; Tue, 3 May 2022 14:17:26 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd2xa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NLggwZ9ptDC6llM18Ile+R4sgj4qAZBBMaonHu4H4zblMGEniot6Bwl02mvKCyn3PPtzKOd6IXBJ+0wtIfFhLO3jiVbjXvuSo9lqwsJJuJxgkBQGjKzvxLHf4QT9Bc4r25fkpNPz83W7qm6Y8801m64e5Be/GqhEoNsUGn9emtKdCkszmRLYsVCLQlR6mTogWAHpHsc4EXnWLN1Dg6LgBaB1LfXvgoPBq/bKfHeHMNgAvlAkl5KBH+I5vWh1FaUPz5q2ciOViRFhzGR4vIjzYN58S6T+T8l99athMo/7+afJDTK9fRSQjFc2D+zseFU1o4xWZUL4FpJv4HnZWFM6Xw== 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=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=TAypylcH3DIUw7Tt+mxJ2yQtIhByLQt+OT4WMnWFPl06ZcKNpEKP37EyWX54IxYby6I8l7Bzopn5Tvf6gbynMxQkOFPnAGMydkjdCv9pdG/rKPoBCNxs7Tbr4YaRwYTHsSqrakUSBLsuehnz5jQQ1HzsFMLEMwDAYKBBr8s5hc6R3sKAI+Ti7ssDXpClpxWR3QNSqm0fo50IJzvSbZ87Y7dOo+rzn14LmqF3pF8wXCE7uQWsQ1l8JkWBrzcCqsJQ+BR6Z6TN8ktIZv8Yc8ORNhpz9+2hHsD3e0uHs+c6JocGH25q8gsdy7ohCDA39nSaOfo7EnSCY/Eigp4TyGt7Iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=kCUxZzwH/e0i5WRc6YVYWfolchFhFSEWPOmjovLR2h8og4JdOm9NBjef8Kix1Ht2z/wgm2DI0Dxt/dqo6i9m2gf7vdl2eSUYeeaEX7apt7l7L/65F7Cn5WZtVVAm4+oDqqv2LRNTyvQdK0aErpI/5gEwHIU7OVQL941tmvkPevI= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:24 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:24 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 08/17] vfio-user: instantiate vfio-user context Date: Tue, 3 May 2022 10:16:49 -0400 Message-Id: <8efa05487b7a2f9c2cb512245f21a5a0db837d3b.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c034eda1-434a-4abb-058f-08da2d0fa4e3 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mXXwXRt+/r/qfuxDYqlEkGYJLCAQ+zRQdoV8AF4NfBa+kRSUMNCzLJa5RLsk+Bylzo76i6MFDEpF0HDlZZ5W2h3hTrCF+UqoK/aRF4rEK0aSkKwoacdrhatGV9xVTslb+Pw5E61zlcwkuyoFzzV5NuLK2ZFk+CYNdPEQGjJAz/zYhW8feOlHtfVydC+xTn1O4K4IZ6F9MpPjE6Oz0Ncaw2gizTew6Cf76t38so6we3bHvA51xS20/efG7Bjf9p+YuTTXdj9i5UTbaAnqrzAB1FUdeVOb3cfxlSJsEJO4aGLS5hjdZdixQdg/HOvjUuBcw0K5LYHasIxbpoCQx36ilWaD5OE/rmXB5RBEkGZ589J2HXrQH4Q9w4Ld6owwm51yxU0HqEPYV+1pe+MYL3pQ2h/+p2utXPz6S+tqv0ZUka6uCHIkvyLpnKhdcoZTysH+Np8rd3sUZAhChEE/sVhOKM7Yc5qu8S3MO0vuYwqa2E28FQCR26XHRteznaEkd7ohq6F9sdZE0p4Jo1yN6oo1kTC8sjM0rM2P/0R9UwY4FL7IzgNEhtqRDrfP7RGR1ssVJF3S7Yz/DIevD+fiDNWQh2/sAKOszoGUeLw3tkkFUmmFMB2yYTV1uHPdlFvzz4O+c6ECkAqQlu9sQMvmRkg//N3CMg7EILPkP4U08YIo1WMpf8X1g0i50WmQirSGFx1kqLprxNSLvu4CnWjmaAoG8g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JBs7wV1GDP4BwDbVzAu20hM7dvIVr/hajsorbYXcNsQj01JCS23bxJ1zxP+4PlDECFc4yfCr16c3Gm6fpI+D6yy+CJqbXF0JKpQfspp1M0Y23UAMFfSMK3McYAnqcNWYVtVCVW3iKxvg0Wc++TIblQRZ8aLWoKrsWjqF4Hzbn4AfpMJQ8hK2Eupa/T6WQQAlxnXOC+9qxgnhUH2Is1AsS1zngh1cIiW6kodDWREDn3DA1yqbD56EJWvZ6GtbvMn+cO634mVmiqf+AIxnTBhz927rnZJX4jsHlw4zMriFUYBsbRFXC9XCmTaYVOjA/Fj0SJXjwOR9ULPkQVYMS7Nt9BGDfpH9TDZzChxIPGKlJG0aBg8942gCApH+SjcYaOaiOF7e1sI3cnuF+eQCANQg8Q1f5GlBp2sBawNJdA2TpCLqXtbDGbTcN9GO6CqMbbjWOs2myxcrcG+T/+DwflcNfhVqSFo4waAZSpILUJN0ZaQuUZ4Ec4ZNTNU7k0U1q3aP+Nzqid+0eVlpB39HfYSjnUlUwpigCakzihkUxRdNupu7Q9AZ7xG0Gfpcf3QFRt8nlobbgcUQPCbuItwJo3DeVGbUYWTxjkV3MHEiUPw2fektG4qizTXfDu08IukNJbuSx2U9D1ZJHsV3ofYXwJa7zKSpXKUrNebBvAMhQCNkxdcYCwZA3W4o3MSD82ajv/tnRYmkfoA/HTsG2BrfavTl45R96jGD9Ax8Nsggo/sOWF9iev3xPSCoezo65/dBfYwliYswywAtWb2MBtig9sYuvL//EtneM0O0AjiAvpQ6E+74N81zsizYfQ2AIIXrStxSJPx6dyXDMDwqsDXnjObN2QKamuCnWDPlwvaz6LadAU7pgfcj66vaikoZPXEQBnboTGJH04AvCyZKchYpf9wzm0xHAfs+t/nQDOiQChN/uMoF/R8KazoM3w6jMEc1wjMLH/v4HMFD0wT23499z4zMGkg3zK9DW0SA1jBRz/3ZflgQMKxldmoXC2dojALTEe8hFNOKAqWOHj4wmxrkHkyMoj3h3+O1RIIFS1FQq9I9yQ5e/VV4L3lWxSiALadWAk8O5ZZSJ/lmAySktHhDwrsZyW7yNqdDPr59gzWvUHJ4T6ibv99qQJY7npT1lAFRQPylDppI6TKm9VN1bq8NoDbfsKUTAw0+K2gzgvkQygUV5F0KLUvP8npCfdVZlhXSiUiy/btpTV+O/O2eNGBI0M8rfFpPAqFverMaXptB/0pGxYiR3nq5quEHLYsim1ewGvlw5TJzyZW1Ya1N0kBigcsa3UDwor8zR/GDGCcR0h3ohmwWpvOzdHuILFj7wSZ/w9+XCP6rGY3dVk9PClC282ux19X83Vx+CBBdmirccdaeIIv2LrKroaN6N2xOW/ULCH4+VHWjW7MQvXrhxsoQkNPOT/d/PV6QCYkTdhYliJpUU/0X0e+PZsu9EwxH/2+auLR1a99Cr43JAEf7Lasv6J28CAFgf5gOaMtcXScaq6vC3Y1CwJO5Uv5tKMia8S7im8+OlSkMjw6Z/ZIt/HE2hNxSSVEokLxMGwsWLH1p9P1weluHns38qJr630c1nhBsGRbYS++9rUOEbeL9FUMUxNKse5FfKDB5zq9QxmhtaXQiKt1Joh1T4rUSS8x5Nnt8238adM6oJr2eiJf467DCZok92wOvj8Hl7ISQMa9ln0w/A9ven2QgzacDNC1ApPVrjZivALP1YXpF7ajboZLOSBn9+g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c034eda1-434a-4abb-058f-08da2d0fa4e3 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:24.2790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MH4WFaBYaOuPLgxn//LcT6bkXhP/4hF4wyKQaK1ipDHTp1BHfTkr+wpSSNe0D078HW0YS0AR8tBViuo201AEkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: 8L8A6RvuBJb-FkKtLE7OC8CZBfFYjqv0 X-Proofpoint-GUID: 8L8A6RvuBJb-FkKtLE7OC8CZBfFYjqv0 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" create a context with the vfio-user library to run a PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index bc49adcc27..68f8a9dfa9 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -40,6 +40,9 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qemu/notify.h" +#include "sysemu/sysemu.h" +#include "libvfio-user.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -73,8 +76,14 @@ struct VfuObject { char *device; Error *err; + + Notifier machine_done; + + vfu_ctx_t *vfu_ctx; }; +static void vfu_object_init_ctx(VfuObject *o, Error **errp); + static bool vfu_object_auto_shutdown(void) { bool auto_shutdown = true; @@ -107,6 +116,11 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + error_setg(errp, "vfu: Unable to set socket property - server busy"); + return; + } + qapi_free_SocketAddress(o->socket); o->socket = NULL; @@ -122,17 +136,69 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, } trace_vfu_prop("socket", o->socket->u.q_unix.path); + + vfu_object_init_ctx(o, errp); } static void vfu_object_set_device(Object *obj, const char *str, Error **errp) { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + error_setg(errp, "vfu: Unable to set device property - server busy"); + return; + } + g_free(o->device); o->device = g_strdup(str); trace_vfu_prop("device", str); + + vfu_object_init_ctx(o, errp); +} + +/* + * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' + * properties. It also depends on devices instantiated in QEMU. These + * dependencies are not available during the instance_init phase of this + * object's life-cycle. As such, the server is initialized after the + * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT + * when the machine is setup, and the dependencies are available. + */ +static void vfu_object_machine_done(Notifier *notifier, void *data) +{ + VfuObject *o = container_of(notifier, VfuObject, machine_done); + Error *err = NULL; + + vfu_object_init_ctx(o, &err); + + if (err) { + error_propagate(&error_abort, err); + } +} + +static void vfu_object_init_ctx(VfuObject *o, Error **errp) +{ + ERRP_GUARD(); + + if (o->vfu_ctx || !o->socket || !o->device || + !phase_check(PHASE_MACHINE_READY)) { + return; + } + + if (o->err) { + error_propagate(errp, o->err); + o->err = NULL; + return; + } + + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o, VFU_DEV_TYPE_PCI); + if (o->vfu_ctx == NULL) { + error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) @@ -147,6 +213,12 @@ static void vfu_object_init(Object *obj) TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); return; } + + if (!phase_check(PHASE_MACHINE_READY)) { + o->machine_done.notify = vfu_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); + } + } static void vfu_object_finalize(Object *obj) @@ -160,6 +232,11 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_ctx) { + vfu_destroy_ctx(o->vfu_ctx); + o->vfu_ctx = NULL; + } + g_free(o->device); o->device = NULL; @@ -167,6 +244,11 @@ static void vfu_object_finalize(Object *obj) if (!k->nr_devs && vfu_object_auto_shutdown()) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } + + if (o->machine_done.notify) { + qemu_remove_machine_init_done_notifier(&o->machine_done); + o->machine_done.notify = NULL; + } } static void vfu_object_class_init(ObjectClass *klass, void *data) From patchwork Tue May 3 14:16:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835840 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 CA1F7C433EF for ; Tue, 3 May 2022 14:19:09 +0000 (UTC) Received: from localhost ([::1]:47096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltMq-0002ZX-PU for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:19:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLM-0008Dj-57 for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:36 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:50346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLK-0001PZ-5i for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:35 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243BLJgo030616; Tue, 3 May 2022 14:17:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=a+4wE2YG9xs0eUF58o/LSFGH+P2cHi6/Mit4L3tnN+03zTl2O4J5MhhFysls6W2XwRW9 e735Vd7p0ma1BugEY1vgzT299LCbBvStGg9/53MvNkqrwQdzXgHwdnlmnLGYsLKoUW/Z ZT73aPJeEGUgeXvPSoEPLA5wTArRXvfXXAX2O0ZB6KR/M3Zk2teOf/KdP7f6FS5hEKTu mMtM2ayNaL5cWKN17IMK4Jgdp8OungUtyR/2hqG1Wp2/M2bXsCX3wKdMwbbcY/mLNZBL m0xrxBfo5KOFQsznZNRRxSlo6KP2Rt5Fr1EyPfOXVYjGQwaxGg1PO+UNFbAox8wZK4Yt zw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtpw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:29 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EFMY6018974; Tue, 3 May 2022 14:17:28 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fruj2eam2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FERKYJofFHpHAV5OlsT3x6O02fJs5NqkRYuIq7fPnQObWbt2abNyj4OIMNJ1nS6m1YytldKxZhS1oj+tYSM9sFrheINvGCjT7rMEs0tq2ikytAoOT1F9QgGibUIRELQJ3yWzJwfuZFDfszvYw1Eax9xP9J7G3gb3ZpRqnwruTCj1zjEvBI+AZUfML6E/i1bCQmfoiNFKbvujbG3PcQet6xx4tpbrGITpky6xjBtawZsgNP+0omNajRujY3YQ8PzZ/gvLfu1UYAq5n9Va8vWiRnm7ZKVNR1lbm+e8uRA+Zdz7G6p2KWKaDK2XXNDFz1q2YI8u4ySACpfAZP5t9kndEQ== 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=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=bdBGxTeNE4zYmvLmlMVQVKm69pYiVUtq04uEGIjD3ROP9twmDeOXgeLAG2Nc/CWeWDrIpoFVLw1mDT+Jf4mJLmOzcoMtHgfxuTnmgTzSg2ZRl0+xDwFEEktgm6MBufEvz264hPO5OXNJJx4NlgtKfjIf6chHPJ5exi3/2JRCDQDYR/0XecXozRBtCNwqr/bjAtLioge1s4Ulr5/LEZ+OhaF6kdW0D0Y5A2q910Q+FZGDoy2EM1DvgKPhjsSRGLKuFRgl72BEU8l5Kcn26c+0HTEckbcJ2HbGy1aSzaap69gnX5ZynT5oYK5N5GZMYTsUC5UOCtuWa5orAUlYQtmNVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=e756TvgoH9F24HN+hZnXMRfXEo5+3Ha1cU+QRY9k0ZKYvIimSPqeXA6w8+qKYG8vvFcTWQw2RNna8WA7TCIQa8SIJBKlu3ER1MYQ+Qpxoh3fHso+fiEXfBMJeWIviM/xOZsm2zlSKDZlb6bSyp8kdHG+iYSgT20jZ4y6i4G5VvU= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:27 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 09/17] vfio-user: find and init PCI device Date: Tue, 3 May 2022 10:16:50 -0400 Message-Id: <2226baf68de509ed6b144bdc50810a0a073c89f9.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9fe01cfe-4644-476a-c293-08da2d0fa68d X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xQl5TkDxF++/afAjdvxBzp0hbr3Ls+xa6ic+shd5BAQ9rVoacIEWLlUq3M+B0rZmS9UwjGEmCHSKAglDdQ6KbAUKXLQKoTYTFmpZkmsDi0pV9pXKz+VqXqsKM69c9nh4GvvOpWMvO1wVxjNhZnBd9y1/MSZfZkzx9efwUphu8oBa37NRgdtB7plQuWJeVsdaxeeZRMyMIIzT2ZQQfUlTHfI5yD71CiVo3pbsOHaayGr4uaUUPYBDiASfGbWqwI2HaEyn7ZXrrXdjZbA3zRP3yeFY8nGVGvV+xKG06xMrt88FXO/DMFps9XttnlfqC3dRcKUCSaxccwOJ59PILlX7WUk5kzpefEZM1HBiFLaJz0Wf3rDNMMxJKF1R44pIbvorX8GKm7cD4m5tjN83MIk7YV8r9vp/ngdHEKB2T5uDy0lVEET27T5Mq3N+8noZyVRqaI+5th7/lzxkrwFEh1h13oWfYZw9dsJYTYZLuDlTZhq0eYXEZofg/MlGJKleahSlCsggn+rF1C249OjhoKE7zVUYdzhZSF5RE2s8X+atMEESFXVBmqr6uHdM3Eot2Z9bvCTWvBRXo/Vb9yjKxKg4kj4eqvLhrcQ35OC6VUacS7fQKhxguP0am20/g+EYbUdPHfmVj1Y5kvZ6epjaglfgWsSzDTuJSGpZM9iQDiPX3E7cxAFa9pjMdNmH3l8xAMpzjQu3UhmXELTOKLNTn4DFww== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZbDYhIWK5yXHlh/fIuzN9J4H9KnWBb8GkvdmVUb6rVz9SCvfguDWEc/sEzUicubkxNdy2HhF/IJUYc4DhbefmhMHu+u8IYiXZXHts5QDZWbdHXF6FmKO+ObPLMxf2/EAtXVrOldhWDUMXUEC/fRsTF8BCYtvLZwca5KZ0RhQKJJ+FVTZKS+kr4G6NCw51JmxQwHpyLcgr04/hD0lgwqV5WfJYEc60j7fi0ys0HZU8nEX7atgJPPKxQmx66wNEcpll8c2YO1YOG6s3Hj+9v9TbcqJW2AdTJVGaQZNBuFlR2WMMmYRw7+BqS9IzDkEnYblnfoPHWP4i7BGfmrvjsxzjHPljydq29QbRAZEpn7n22tOHSeBQxKkH4TdvVXQ7W+GOfKR7mDjd/1uqWJH205v+DrqmQA4e6sX9Lm/HSKQn3YgwHog92EscjtzmPt24X3VdUX+vCtqEuJtfzBu0YlTFqJP5kFdX7vLzJZakVg/6VxREbFkHYWp6CVxT43xI0r4IfaFToIk4/sXENbJA7PZLEoTuXa4ea4R3QdglubQkq/QPzfow6P2J9bMkRl+bw6lNitSC65umfUcDuCfMIX2KxkT9yKefvSorr+YGJG/xwUEw8+5M8GMRvGfQKnLbphr2tFryBn6nIePBX/YTXgs0Hy2BYu9LtIMc2bttSk8gDD3FnqHb0fAKPdFvqaYS4fQK+jpgaGjBu0D/DJ1VKz0sAa2RTElaJ2YVwQpxgYTLYgUSAwvKlfpANB52zI8zOC6/TmkyKSP1Ziu79FQ5vnilllLFZbPxJkk2tmFuWNRHvfoXACsfQyEh9tqwaNelCifQz7uRAFZmE1zatT3j5aKPsnTt/RhHnmcWdhr+TTWvnWyhYWcLWiz4ko7Fj/E8TvLgAQdkIUzBVSI7l03K8TGmjXF6whaxenBrG/YiFizxJCA1uVlGt8SovoUr56cN3cPuXF62RAHhyjBOfWQ8BNTRt7qbpyZ81tE5YhrF+pO4sGZxI0HZGW3BZVsEx6nMP+U9Fb6UDoRGHMwv8X+2NDOi5T42zhRMTfmL7fm1BzfHuANm4Ip+fN+U3ayLXUDUOlWURYlM++uc3R2odAiLPUdMkePh+WCfKYTcwyRTgmXyWttbFurf0LEBW5rQqL5DfcHOxCaINPuwk1zCkxbPyyiVJ94RyKpit3safK+rZfLdZl3OXjAQlxuwHnWLncg1tGQKpMoSAOlfy2fMNMsZnSf6KYv/0QaRWOG57JwMFvOUS+VjqTSq4RpX4OE+ZDzl8Gq0QOPr7dJStJ3duY7YnuOYaLgkEUVmzBlPHad69KMLDhALBq1lhUhv/VMvqekIAVB5DNR0zeHSG++LlXEtaLLeAp70oRUal+0/Mx7ZP9ALiIqfyHc2JirjsrOQAKylM86ELSlVJwYOfAeftJlhzDp5a2WvRuXt69o/7y4I6RSoV3lFqtwSOjmvGoEYe+LBD/BbiK/qQ1KMgrPaJBPKAsp+CMa/5sss1Qmyi8MIsN9ACPxmtdd4grIuVxOHXjNowlxx2sPOpOY+l7QLAQqfbAoE8iw5qxdBGADWAmF/bGrID8E6CZgfhQ+OF83eYArdxX0JHVpsn1QNEHHdAekNdTK9byWPyqeu3WFiXvSogWQ6egiq/JxbvHW0VgmMnk0T+8DDVuItKjZSiYb/A/vHECGkObsZe56/WZpqyVctA3wiHsa35GRLQDtHor7GPL8PtOnZvx2RegQvJ5QhNy3xZ6keg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fe01cfe-4644-476a-c293-08da2d0fa68d X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:27.0757 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gscaE7Hhw78jAfrzWtRfxb1AJ4616UNIntzWMMVV5l/P96tS8rk6twq6HOsD4yY/NKB9IJoBDT76+v+mdbk0BQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: P6TypLxHwTc7WFZe5qjEB37lk7PEEPZz X-Proofpoint-GUID: P6TypLxHwTc7WFZe5qjEB37lk7PEEPZz Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Find the PCI device with specified id. Initialize the device context with the QEMU PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 68f8a9dfa9..3ca6aa2b45 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -43,6 +43,8 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" +#include "hw/qdev-core.h" +#include "hw/pci/pci.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -80,6 +82,10 @@ struct VfuObject { Notifier machine_done; vfu_ctx_t *vfu_ctx; + + PCIDevice *pci_dev; + + Error *unplug_blocker; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -181,6 +187,9 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) static void vfu_object_init_ctx(VfuObject *o, Error **errp) { ERRP_GUARD(); + DeviceState *dev = NULL; + vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + int ret; if (o->vfu_ctx || !o->socket || !o->device || !phase_check(PHASE_MACHINE_READY)) { @@ -199,6 +208,53 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); return; } + + dev = qdev_find_recursive(sysbus_get_default(), o->device); + if (dev == NULL) { + error_setg(errp, "vfu: Device %s not found", o->device); + goto fail; + } + + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(errp, "vfu: %s not a PCI device", o->device); + goto fail; + } + + o->pci_dev = PCI_DEVICE(dev); + + object_ref(OBJECT(o->pci_dev)); + + if (pci_is_express(o->pci_dev)) { + pci_type = VFU_PCI_TYPE_EXPRESS; + } + + ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to attach PCI device %s to context - %s", + o->device, strerror(errno)); + goto fail; + } + + error_setg(&o->unplug_blocker, + "vfu: %s for %s must be deleted before unplugging", + TYPE_VFU_OBJECT, o->device); + qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + + return; + +fail: + vfu_destroy_ctx(o->vfu_ctx); + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + if (o->pci_dev) { + object_unref(OBJECT(o->pci_dev)); + o->pci_dev = NULL; + } + o->vfu_ctx = NULL; } static void vfu_object_init(Object *obj) @@ -241,6 +297,17 @@ static void vfu_object_finalize(Object *obj) o->device = NULL; + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + + if (o->pci_dev) { + object_unref(OBJECT(o->pci_dev)); + o->pci_dev = NULL; + } + if (!k->nr_devs && vfu_object_auto_shutdown()) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } From patchwork Tue May 3 14:16:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835845 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 AFFF0C433F5 for ; Tue, 3 May 2022 14:22:54 +0000 (UTC) Received: from localhost ([::1]:57200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltQT-0001Uq-SH for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:22:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLO-0008M3-Lf for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:38 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:55840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLM-0001Pi-EI for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:38 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243DEwCs004092; Tue, 3 May 2022 14:17:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Vo9a/ni58/tCG70YpzQGSNu+WUYCHxjC1SxAWpNAStM=; b=szndI3Btl2El9A7KNAUxL1Kv/GmrUjrQbnSh/xVOUwVtxFRHGwHBlMnXavhtohtZ8kmA Zg87Hklsmdi941GL8hDE02w/ZmBW4KC6zTi9C9JYFeqdhCt72IhjOHC/JBYwmbfJuh99 1KQcBTThst9EYdhAdnOeQ6TsbCdoOlaUG3hGBPJt4hb1ZMtKvi66Wutz9ZIgHmiTnid9 sI8mDzACuTkugtzOLqSFZOCkwq8h8jbtsh/7DVtM8E7qiGpBgJgmUnsteaz/ehFI0cqc eF9fKn0+mu2BrmlkRUyv9dL1OREGKXbutElxkfS9GutUGCTEvf9Nvu7iPhv99LU7gljN 2A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0annhh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:32 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EGQOn002363; Tue, 3 May 2022 14:17:31 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2047.outbound.protection.outlook.com [104.47.57.47]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fruj2e5pf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AlMmXeMDwqLPIVOdE99LKBscda48EUy4SsowB4MCRVnml8oUKSeBftG7s8RpHtZ3HNolzvT4g8+0dz8FleMYRXBqgcmLz10ZwRs8m0qnvb03LWjZa7K+TUt2u6HXTfbqc+RwTAoO/BZtPlxosUWhucRgUM7bR4JnMGECqjn7CxCSs0UfuwS/36NP7csMA2DL9XRRLdjRBHUdFZpqHVIINwr8I9BbcAX++8KRarvBx8b/C+iBhue2H5/YuTLqt85MLuGRou2RYt6loetWanAI224JWz2VuXi4irMimOM9a5a97qNQiXXcx83W0J03Ca0pY66KpAhmf/HRNbTSSLhXAw== 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=Vo9a/ni58/tCG70YpzQGSNu+WUYCHxjC1SxAWpNAStM=; b=F4BBlsMKuw4Lz3YNPXQPLXA0d6sbibxAfzd0SUTJXoUpN/qylKt+uYrjKQG3k6b+pnXKiejQ6jjrsSdWpJ8Vr4pE3kCMkamhLrjSD4OsMFEoVJmvfV3tzxvhqlDppzc3zyzjMf/uj/bUWrp6O3lHA1yVS8VTymH1BmHLdsqkIM+fArS+jBC7b4d9gWjmBbRLTyBav24P7VV2eHEf7tilbqpwPABOu/GyV/bCApCqI40+ztNg9tg+o+7TUWby6bRmrTKFFG/BteBrq0XxSgp8pd6jEH0IL2zaZ21xrJ3P2cpkTcAgnFxk706an5pjkwZI4W810T7Ys1qXO3GZRxlhaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vo9a/ni58/tCG70YpzQGSNu+WUYCHxjC1SxAWpNAStM=; b=oQrEdn68xy8MG4UYuobL0g7Tw8N4+fNqFKGDr6eAIZk+CW50Dg2n/yeF1ZLplrSpe9e3NIP/DS+5luP0E56fcxsL1bh84OPzYy8VIvGc/ItAYRzQbnEdKK2u00vYeOjwe6EmxIvuHpAshDUSQ1EmEapRQhvEzYcwMcs3PsTo+FA= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:30 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:29 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 10/17] vfio-user: run vfio-user context Date: Tue, 3 May 2022 10:16:51 -0400 Message-Id: <7350f4813b73af783965b758ecf39d0a6a76db53.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38906efb-1026-4639-e1fd-08da2d0fa83a X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +tts2CHIQkXy/P4iTSg2V8TJs0yN5DgPvj5cWQuMtAIhzXski9+YA+1fflYqaEk/rPpLqhM8cTQt9dn/5Lw6fb0TT6Jxuo+GCxLO1Qnv4o76NorVUlVQax5Z2RFiKDfjrWRPhDiVzIe1NghuzO2jcDnFMWCy7Nr+HAZ7yOOcu/OVNk/oygwuTK3oVySEEXBScSAnqIBdMI2rAhGeEfp9bPGPlkDl/Sz9eQNKoZLcpc+BKEMPOmMe68jvu2b1ssGSIFlthu4ULQYpbLrbMNprl5Jc4hMcnen/9+hjfHGizH2Yvxj6afY975TQbkAzupuOaDvDBKuS09YWw3jrBvRCeF1093/N3/BJ0IEZov66340obqVXwNivAKJUBTITnKOFaAySi4U/w/SbC/B19b3ftUxRz8ovsrQLy25E5GA8f2u/JDp9A+rRFuYnZvBZrKDwm8qfkQ7fWcaG5n7LdJPj3iJCmQNQjuowIeoa4NHNcaJ8F/mmfciKpeX5L6+EACCA3LF9uwjl5yUziVX7ubbO7TxeJad/Lb7p7036JyPd0tz/tPHLr/M7MnsNmWNRzq6hKoKBz810a8631djKKXn5Ut7LBzyJ0YLn61B851l9Wz9m6oj4CF6gRWK/Qc4Ct3FfHBfEdI5K8IPH337X5cfOV5oULKthpdPSm/7SmvOHM3ha8Bdt7onKXf/2aog9/t31uSkX8eLPTnACuQPRiOGu1w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cvWvWPrWTSNgjKr3h7UEBIKh2Y/vxMdViHxUteXon3t+RRft1piiTSZXnuNG4WJOh1vHPU2bnzYFSt/JMRfP7Pa7Rgo/vjbiCxMKBWlqfUaeeGyu/N48mC8WTOJGoo24StnwBuYsEviEwfmNQfao/gANl0UAlxt0+Pn97CyLaKslOu1AmSR5euYUp6S5HUYl7SgTGEJIc2gNoHlZ8MZhqSfEAekPm5TCM6XP6JBqSbkqHS9p522ZFa6YnKWOVzf07SB3B6wUudHXoCsLgq1W/B10D/9p6FJdUwNrXmraZrtUZkSiiUQL0WQ8L4jEbz18EeyjG8pn03ojcS/frBksAyimveSa0sjqSysLQOp0fw82a+xbPCESxF9JSeyl/rFKLHjHzxSIPLGXTt1MSy19egvNr928mx9quAf4wjnpsftR1wGzDyYdGXXl3Wi4HdjCGK3krZbC7SmxXt+6YzRN7lVJMcMycbaVkW6KiXtezQ8idNvElv6yLEs0bg8wivZUuOAP4XdyBYt7GOI6ksesvva81vmRznRbE/Ka2ciw4vX+fxpVwJB3wQpyMbFBdYI/jsD3D92Dl+wFeKjgHal1Bsmes3FnpJtTgd8wI7ku4Duf6iAiab+94Q81bjDcCjxZCBHvoyuwpBkcYZRmJ8zytLBBWMMvEk632COf64NuyLsthd8q26hONbjyW7Veva00sVJwL6DV6VmSgKPJsS7abOGn/uePhEIVqTBTt/9cWu2dZ6g4Rlmj9KX/XrihEFPBXbtrFxxij2sPvmEuW6CGQTf/zAF0Hc4xyOCGFLW/UwlqxNKU0Z4U0BD0qpMq87NOOD53Pj7kN0TP2Mf5WdHYJisGAaZz8q44XtYXoX4pf3HYX6ZYfipWyFa/92IfxYKNMnBmOtR2L7KyJpzsUQ3t9aJNhvs3YPTx90KOvjlAZYdsPRQjd18HGilHQzZrvElzfPjdDstAlha++9cfvRJYstHwFQyiOPUbNHMDOBW3Gu7tMvCNnlhA1/+o5D3svZzq/vzz+JJqp1hhV7/XQMoppQJAvORyQnC32uQXp7jP6nYsEk11T+SKNiFrkzhwHxVZE7WVIn/22ddC0svI6428TggaGfMcjng+7QJaGitxZnLI6wx5HuEcRguQtdY4TB/VuXkuwDtvmL/iAlHfYzGKzz3UZ+tec48JlnRjMqn5aC6AATWEorIoOngdACp8i7mSyXUSB4LhxCjJpyqQOOzbduGYnbl5iqqga++/kvtRymUd2ItkI3oiSSnIWTJ2YJi76Nr0eF8H+d2V+liMZFabEzoXJ3tlgQmCD25VfNXf6gSsjRlu4sdXjy59qTBd6oWkAfB9UkDPIsIGP3jtPPA0CQ24oqYfUHx0F484UFSFUn7OVbuk0XMpoUmrTI+uR44uPOCZ/L0hixUfFULFgjHbTDt1LpoiBHN9yPK/RQjO5g6luvrGW0UHCQiGtERzR+XurPDsHlz9pYddutpn2Hu6zzFXZauAHQ8/0+A8+mKNM1ZBRYDxwvSyFCBd8Rq1xQBqGChl69cLNsn1YZiZEo8tHSPU8Fp5fE+cV6ODB26d2g2fd/02Uj6vL0e4hdcULLHZVvmsOYxhj2VHQjFuJ3wuaIIwszYo1VKKuUUfrqMrVGJu+H7D96SsrFrsxrSzWkqrAU1e54OGYTSGScMkrxFZoRfCWMfIsEAp808gWLpGyZD1jdZFRScTJJ1hPLHLKk1gxXFXnh1QGfoawvi0KZoKGQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38906efb-1026-4639-e1fd-08da2d0fa83a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:29.8880 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iwI5Apabj7X5nf4b1bq+mbGWiNqfglsHXSJv7jbVj/tWxMlaRu5h61sDrrD52Koytu9FxNw6OLaKmoI7NKY+WQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: TfMYthjcFw7Ank5BEITrOH8mLwRZEs1q X-Proofpoint-ORIG-GUID: TfMYthjcFw7Ank5BEITrOH8mLwRZEs1q Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Setup a handler to run vfio-user context. The context is driven by messages to the file descriptor associated with it - get the fd for the context and hook up the handler with it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- qapi/misc.json | 30 +++++++++++ hw/remote/vfio-user-obj.c | 102 +++++++++++++++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/qapi/misc.json b/qapi/misc.json index b83cc39029..fa49f2876a 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -553,3 +553,33 @@ ## { 'event': 'RTC_CHANGE', 'data': { 'offset': 'int', 'qom-path': 'str' } } + +## +# @VFU_CLIENT_HANGUP: +# +# Emitted when the client of a TYPE_VFIO_USER_SERVER closes the +# communication channel +# +# @vfu-id: ID of the TYPE_VFIO_USER_SERVER object +# +# @vfu-qom-path: path to the TYPE_VFIO_USER_SERVER object in the QOM tree +# +# @dev-id: ID of attached PCI device +# +# @dev-qom-path: path to attached PCI device in the QOM tree +# +# Since: 7.1 +# +# Example: +# +# <- { "event": "VFU_CLIENT_HANGUP", +# "data": { "vfu-id": "vfu1", +# "vfu-qom-path": "/objects/vfu1", +# "dev-id": "sas1", +# "dev-qom-path": "/machine/peripheral/sas1" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'VFU_CLIENT_HANGUP', + 'data': { 'vfu-id': 'str', 'vfu-qom-path': 'str', + 'dev-id': 'str', 'dev-qom-path': 'str' } } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 3ca6aa2b45..3a4c6a9fa0 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -27,6 +27,9 @@ * * device - id of a device on the server, a required option. PCI devices * alone are supported presently. + * + * notes - x-vfio-user-server could block IO and monitor during the + * initialization phase. */ #include "qemu/osdep.h" @@ -40,11 +43,14 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qapi/qapi-events-misc.h" #include "qemu/notify.h" +#include "qemu/thread.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "qemu/timer.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -86,6 +92,8 @@ struct VfuObject { PCIDevice *pci_dev; Error *unplug_blocker; + + int vfu_poll_fd; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -164,6 +172,76 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) vfu_object_init_ctx(o, errp); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + const char *vfu_id; + char *vfu_path, *pci_dev_path; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + vfu_id = object_get_canonical_path_component(OBJECT(o)); + vfu_path = object_get_canonical_path(OBJECT(o)); + g_assert(o->pci_dev); + pci_dev_path = object_get_canonical_path(OBJECT(o->pci_dev)); + qapi_event_send_vfu_client_hangup(vfu_id, vfu_path, + o->device, pci_dev_path); + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + g_free(vfu_path); + g_free(pci_dev_path); + break; + } else { + VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s", + o->device, strerror(errno)); + break; + } + } + } +} + +static void vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + GPollFD pfds[1]; + int ret; + + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + + pfds[0].fd = o->vfu_poll_fd; + pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + /** + * vfu_object_attach_ctx can block QEMU's main loop + * during attach - the monitor and other IO + * could be unresponsive during this time. + */ + (void)qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS); + goto retry_attach; + } else if (ret < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to attach device %s to context - %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -202,7 +280,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) return; } - o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, + LIBVFIO_USER_FLAG_ATTACH_NB, o, VFU_DEV_TYPE_PCI); if (o->vfu_ctx == NULL) { error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); @@ -241,6 +320,21 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(errp, "vfu: Failed to realize device %s- %s", + o->device, strerror(errno)); + goto fail; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(errp, "vfu: Failed to get poll fd %s", o->device); + goto fail; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); + return; fail: @@ -275,6 +369,7 @@ static void vfu_object_init(Object *obj) qemu_add_machine_init_done_notifier(&o->machine_done); } + o->vfu_poll_fd = -1; } static void vfu_object_finalize(Object *obj) @@ -288,6 +383,11 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_poll_fd != -1) { + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + } + if (o->vfu_ctx) { vfu_destroy_ctx(o->vfu_ctx); o->vfu_ctx = NULL; From patchwork Tue May 3 14:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835849 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 738C0C433EF for ; Tue, 3 May 2022 14:28:23 +0000 (UTC) Received: from localhost ([::1]:37166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltVm-0007gy-Fi for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:28:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLY-0000SB-8R for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:48 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:12308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLV-0001QE-ES for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:47 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243BFGeW032436; Tue, 3 May 2022 14:17:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=aOqM4qtrihuCrrAaKoU4iKuZKZzm0HZCO5WY/cMYBhc=; b=uVSWZoSDTYfu1C4+1JBi7n9BWJzXcrZut2x3ugW0yprsjnKSs2YcmQufuSZeMvIk830l 496JqqS/ngFFbSsywXUDdxLUU2pChW875pqLx415RLB7fqguygp+MdYv/QaR+QsXBelz uR1Qz2u9IDpCtv2LLwuQLAm9Sc1aRWcwK99ax14aOwJt2B3G/mmFlAFDmQfLx9JgY129 3c1RZfzFqMC/s1aD16fJ/f1+oBn0BZvUNQTkUvc7eiFZggoFcK6gA+rGXdAyUKseXCCD Qu/g0ft+6P6gmsax2LqmaiDqbhrY3KhG8Vm7xyqpUm6w2dlVKVN+e1rye+Reyk/W0ebV vg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0annj5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:40 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EFJLv032022; Tue, 3 May 2022 14:17:39 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2044.outbound.protection.outlook.com [104.47.57.44]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fs1a4r3ww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wy2TdyKb5gVK6IJ4UjCwB1krUs0lVwZCNifojaIIKBrpQ6xVnvM8wiysVhcCfXSn1mYmIuxLor7t0jJHwql17NSN5klfrZ3VQxxfqEsw2YaSmKh6nG3F05jLLjJDWimJLW75jgi/QnvnDiKAmUzeo4tWtd1pmiz/EPAJiiAw1tQAWIMxVX0GQb6zU7RtMtHqVJDuo2jhJ/i+TR0xOHW9tBNb0BSdL/i/7BecniEdfJID/2UkQJydzzq7ONSpU043HqF/VMBIMVT1Df+8MK0y9uFxMG22ImKioKDQ7lESjQBGcSKDDdu7E70LQfAlcNvThqQoSqlPMkN2Y/o9c/Kqyw== 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=aOqM4qtrihuCrrAaKoU4iKuZKZzm0HZCO5WY/cMYBhc=; b=JdnNMWIbXlr5G5XmmJsG0d2zYBa7SZjEFbHJO5pXGGRo7gKfMsKsaMBQvGP8uTZyyTFNiAtTZy9rC2NvoaIbRW3yoVg0RS5Sq7Y5hpyGb2CyjKxt90LQe66lppMC9Ns0vvB15Dnk0iEVvK+nH94Wui8DqzjC9okRavr/Lk4PbkzreLFhwKQJzd/HzAtdoNPCX/a1J6debLlEQjH1g0ybFDiCp7uvpjn+cPglHf5KYkYauQpBZQ4kxtb9QiLoU3k4L7kj9Sl+SMxyl+OciHVoCU1p/2uWS2K1yxaHcHj6eN8BBei0yZxYNSwC3tBB94IChVEOoxTh/wWV6QxfY01iLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aOqM4qtrihuCrrAaKoU4iKuZKZzm0HZCO5WY/cMYBhc=; b=WWc1vhh2mZ1SRAtdSSn/O3gW1n7czqv00A03I9KKBbbnCXirr/05A/9iWnTdV1SrDCikbjiV3wTqxdQ11qzJXB1Ux0zzXaQo7rz3NaCuA4ibHb9hh2eL7IA/cRenijkdD/YewWgB9yRkrlzW9Bs1K+bzjuAhQmGhDDnQQVmIUZc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:32 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:32 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 11/17] vfio-user: handle PCI config space accesses Date: Tue, 3 May 2022 10:16:52 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b4da81b-7946-4dde-9ef9-08da2d0fa9e5 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tBuaXd92A7aNd/hDyhXmUtLq2qVH/4Gn565e87sNJ/fNjuk1hou5xN9K1AUT+pwwlsYG8x4aytRGPid31vIuBoBLoOfxuh0qaBv/QOZoUt5U+wuq81g2dGeCxWQLAUVyusAvpZywI7cBMQOxnBje/l+lNkh6TzQKR7iZ0/1nnj0NJUrIAevFqwQfjZHsoe+XXfllg2ogQ2Nu/VYclf1TrYIy+mnOBdmM+x+BfTz2IXOg2jkp1eg59JWpJF76/NXc1ygTGhpr4SgE0Axu2vixcK8lJJN9LhScLM3znFzQXyUrk65dW1HerIH8YZPOV6t3390QlkKV0r6xHzUZIKcVmCjJ0DFvVqEyEfbwO1g1RMgTun8kuQGG5ZBTZDZvTvqNe1NOzHOOVm7i7ZLCxKcctbgT+RHQf4IEC1eDt8AuxwP7OagbnT/B3v8sHvdjjfwbRIaRGk7AK2EJ5whX4ayL0SbShuhTW0Q8XfN6SvXkzoTa0WbRVC1MEXuMPRtDfJvejIBNOFwVrQSCnE4d+sBsayvrtdFmMybVbZ6optupV0UJcS51ESFTJlQbgQPYfjEfqtlDwJynLegAZdWM//M/6VGQNSU8F6aEN0dI4nI2kRxtZdXvenEKCsHxXi+O2kPdZosFCe9hnoCet+vRNpUNWWpbIIrZalMabj8n3PfqYgmQyLhaCyksiYqt/O4oLyjsldJamX8uJzzMaSGnlrs3fw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1pTzc/G2GVNhorqWGAW4bGDHkP7TvoEAIVRdw+3gfQOwTEHOSZAZqP43I/n0nKbI8QGBrC7v/jDN2ojEdV/tsVD1dgGGdAmUnh2Bs2RLjYRPsp6Xy6gOckZ2pw5sHnXD3M7Bo95Xg+NedrnKV42Q3WrMUikbYj+OMH6lfKtxUFEEhGzS1oZbuUVUhvC5grfnnGZwAnz1V3Zy149fcPdmlIKVApqimX1LxqpD3KFGzl9vJMkNM1aZ53uDx/nTqu6gSVyDY5RjJ8/Ay3YVoqBgiyNZ6dPDmTSkAfUMGSQM/UREyyy8g+eIlCyVwBLIbVidsevzRiwZj3FkfJnRhxeut1uyKby6sn++zczbNCUaCs56152itHXp3ErHUyr2QGRDGFYiSJK4r4eU3jx5CfA50Px7nOCBgOa46Ab8yYnyktGX/AEUXLuf6PSiArB+0cOWX/7YNJvZ9NxojznADFYMzK8rHy4g9JCHFGseXu3XfvVjdBYmHEDwoK0rQMwjgK+GmsNyoMKO8zSzY+dlwwNSAIBbdBU+FQ9yaf7GEIOvA+obaq4+mHGgZszn3mX5RP5RM7o4iKX1Bv0+/ejk6YRil33vHkgUGMd/7YzJw+tKR9QDL755PA4hMMW9lxZKWitttQ85CulshbpGhW+o8EulwoEvJrWY++r/cm7Hj/wExwom82FYLP4UiJDRVtiZIiddIZ2UIUqquFQ0cPXLKmUUTQKEussx3+2CBQgEJmHamCHxtc4svZmh00aRpqXthGev7eDTaByjg7wO27iIiOF7VWFTD5byiN8JYN/YNvCZwsWRFX1o8RJX0QSlaIxRcBIc0yxmKvxH+J6D2cAIagrEhf+MEFXxNVBbP7d/ksF6aNz0LMd9D0H+x6cqmvPtinrum7lpUMqjRyR8soCJ+4J4WWpV6xEF4pQ1mNp1DzfoV9NYNPSLk48/VRp4ovSZAaxF5T1UuhdFQHOh2fWvV7gdfWP2tkOkIDlFu3CTYcb9CUMGINHRIuR3uQOX/MSFk17z7p2/lgAI7DtlS6fWR40tqYRlAKvlK+zIcYF+9eVghFlr0GNdM08youMPTUqKmNQob2m+PpLXPEL7cKL5K6T9dx3tZh3Shb7a6qlQLO9nIDYITNnjz5E1G5im5028dkgaTG6UTXGYK9r9iyompTvueHhmJIADTZzo+fxLbtB29IkK/QOyhUphHn4y/CmlxWz0FMHBsQbZyJwApcwXR8LlEeaskbLlBBxc7JeEY5zy4mHVcXKCXLxIKDbgz3FphryCoYuiYey8LDP7QGxoiHY/Hp8pPpOTRqh7JtZ8HP3jsXmsGVzQyklxEsqNpRMmOCxK2M1etNbB0wOj2yumAbMS6nDrLJPY6jhHFpS4tzdUZM2bEHngybLlrabPIj7h3OMirLgfJiyQYoq2c3uJp3QO1QzqJVTkq3JkNsuUbNaWx+dqBbLKL+PewkvIVvIQq8/ytpD3nstyXNXHbUlyZMIfvQrt9f8O4aLgLzY/hAHGY8M51/K2QHlE5bgVI25Hj/n3OqIVsulqbjY9sMejfRzTlDYGCncWqiF0cHeenZWLYagXMdEQyThaKIQIs/Ng3fV+b/5mxrQgtsNwAv8zwZEm2F6dfifc32J6rX7skIVxqDV/dwrPlqnXZSugwk9Wcbw49+sKPnex8XdJKXUesEh6LnHsYQBXcEuQJkB2Bkm+8WZjiBBOfoSapbM2GTAPuDs7smqlqh883gcU8G7+fuL+Sg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b4da81b-7946-4dde-9ef9-08da2d0fa9e5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:32.6847 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Qnwpa3+voHzDF62nY7vXpbCYLWCjl+frme74li7VPCYimYMtZBnyqSfw+9V2IIBx2ZWuCEdH62PAsWwjmLVe3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: OSxORMj65V0oCwqll43MYigxWNQ7E2pB X-Proofpoint-ORIG-GUID: OSxORMj65V0oCwqll43MYigxWNQ7E2pB Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register handlers for PCI config space accesses Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 51 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 53 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 3a4c6a9fa0..c81a76094c 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -46,6 +46,7 @@ #include "qapi/qapi-events-misc.h" #include "qemu/notify.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" @@ -242,6 +243,45 @@ retry_attach: qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); } +static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, + size_t count, loff_t offset, + const bool is_write) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + uint32_t pci_access_width = sizeof(uint32_t); + size_t bytes = count; + uint32_t val = 0; + char *ptr = buf; + int len; + + /* + * Writes to the BAR registers would trigger an update to the + * global Memory and IO AddressSpaces. But the remote device + * never uses the global AddressSpaces, therefore overlapping + * memory regions are not a problem + */ + while (bytes > 0) { + len = (bytes > pci_access_width) ? pci_access_width : bytes; + if (is_write) { + memcpy(&val, ptr, len); + pci_host_config_write_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), + val, len); + trace_vfu_cfg_write(offset, val); + } else { + val = pci_host_config_read_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), len); + memcpy(ptr, &val, len); + trace_vfu_cfg_read(offset, val); + } + offset += len; + ptr += len; + bytes -= len; + } + + return count; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -320,6 +360,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_access, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0d96..2ef7884346 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" From patchwork Tue May 3 14:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835862 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 C191EC433EF for ; Tue, 3 May 2022 14:38:16 +0000 (UTC) Received: from localhost ([::1]:55294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltfL-0004SK-RI for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:38:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLY-0000TI-Kj for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:48 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:12830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLV-0001QG-Kr for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:48 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243DEwCx004092; Tue, 3 May 2022 14:17:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=3pNimpuQZqiwrCvFuPMHL0mRMAp6gHodfV5qtEbdfa0=; b=QXqT32uSINYtcjFpCi75h7UyX/x924/OKneoQhZyiyau8xeTCq4HXfUtxykjm0orr2B4 pJy4mpfttt7HcdP0/AxYZJUZj2MYmOl5kWWRr++rBfMAqlw3kLetSY4kh6q4LPW/UBnk kh6lut4Ej5kjyrrS1sl314FsK/CGE070Mmn76JKVMMOtE1Ev3FZWkEzPJNQd/9GA4Ry6 tpTBMKqEHK/ka4sKmvDSqQj74H0ox667dCjL1HhXVfQpF+pdWx0nCshdCVFjd0WhWFSS +O4ZQdXfpZ25wuPuYZIxzcmzkHgw5riGackAuXov8DpjmlrtnrSZwg+5P2whJGUijjE/ CA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0annj7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:41 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EFJLw032022; Tue, 3 May 2022 14:17:40 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2044.outbound.protection.outlook.com [104.47.57.44]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fs1a4r3ww-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffjC+wmDzaQZ1QnHM0H3xjYX+mWaazCG3KeFrgcV4xE5PJq0XN+ASC64XsKJMHxCbS3gqLsTFgwZSCQnVS4rEq9CwLf/BP+vbEBqHB2JZ7uhGptr3zwouODj3TWGF4kLnXUJ69hAEU7ohtkVdPRYoMsQX2ES5d5btCm/UjM+BGZnf/oAbb2cgog7l5A1oITRurASnuNtrHTXD65BN1eXCwGNnQEo86ukjkC9phiLFo+Mab4leQ6xZJRJMPuNj85+mVTlsv1EZAYmt6Uv7zFQ5d4Ju9PYWewo9atMCxa0zVUqAzfUctvg9Oy8dIB1kDmom6N4dkZQw+4cPZtYW31QRw== 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=3pNimpuQZqiwrCvFuPMHL0mRMAp6gHodfV5qtEbdfa0=; b=L6iyMvTIPuQozVfAc7EZC4biIATdfVBtkNVAjOh3etXWNzGcch8qh4bGvcYDtTbOp0rVr1qzDYKuuiWwaRIZLy1niXsM+SZJoAPg6Q4gTJhI1hovsjryTkY+66Fo1sD4GSNHi0N80xaMS9iFyL9zosWCOGCv332MPBIBiSRug2Aa5i5WzmkNq4boP1pNiJecLPIkC1p7lx3CgMgmVHxMdsM4dXy83RvPp3ydrkaHeXFZRME7TNhtYgfJYx/+tKz9PB7FHI7ABbUCzMuGZq0ElpizavYjXPxmTxwE7KZD1Rfz2n98ChuC4DgbmnnxH3nF2XeJvmdgjLeeMxdKGhyCBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3pNimpuQZqiwrCvFuPMHL0mRMAp6gHodfV5qtEbdfa0=; b=vP+fIVpJymuvUdzt1J4Oqc1iiwcFsA09RY3kBNVVLK8XMjFv/BQNsIiYjYViTfU6UbmJZ9d6U+c7awl1PQZavViQSOFreMpQe7T1mVWs8EEifx1FEc+PBzBh1OFrmJNuLEWr2Dxg7P6XZu1FgTHMoDSzuTWrfjJZcTdPQ/yjk/Q= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:35 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:35 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 12/17] vfio-user: IOMMU support for remote device Date: Tue, 3 May 2022 10:16:53 -0400 Message-Id: <29948a10c3f2db09686fb6d257e31e4f873cb7d5.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af69b0b7-78fe-4020-1eaf-08da2d0fabb4 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: voQ0cPQczoTjhRLhzWhqyQwwOVS4vYMQkiGtY4QbClD1V3FWYVaSTBFpcRiec5b6K4lOosqnkQAEu0Ya0cjQWGXwmB7WMPKZFEaqKYGkJGyfPW0P+pD9/t72JoIDPrnGh/1K2O16GqKjnCUUQLJZ3wGnJtJ0ZhVjCPgjcE2ehHhu2VgZ1gRTvpzzoXnm9EncIjtfjSJ1I6LfSiYVvoGQsxnJtMkbnGCqJAzLxKHoFGUAk5SL5JYxZWIJjpQL0GAqdsUCxmsyCvcjU1lwkvIdmWoVIaORjeOiUaNk0OiSrhYRo/E/ho30UDkQDb3IKnHRtMshCAoEPVhL1l9DxomE9ItuSgRSqf+5UHP4t7cuxX7OMDR+fgiuXNUo7zCjW35u5Ml2BPa3qUFPWCEB66u9+POOsMIr70bH3k/YWoXGRB+esRA6wvgkQRwF8GLjYr1DmQ7nBrtEp11mYCGKY7D8/u71X6xpUk5d0wLwACdfp4hGfc9nKPgmB8wZHMlY4pjJC4RqZqfisd7VdbOhA3Q3WPsr3XastPpj18Y31qo9GuMrsnUpqesAh+pJTyYEieVyMFAacPgT0IdK0JQN39Fd/JrBk1H+eW8axKOKgbqjDyH/2rD6wwlZ3nXncviaVnlr1rYtV4kfLJAzGOraYB5LdtqyEfIdKGcFA5ES0BzF4jGnUuq8/aCcQS1DhYYEuBUo X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hTx/mI7W41k3jSQYd3M5rkc8W4eQ?= =?utf-8?q?RK9GnzQXUQ1MM0eSehDzaYSZ82mi5z8y+3dZoki9In8B1spEZzzsJecXhfKeXchjj?= =?utf-8?q?sWUjh/wJRDNjz8AI/b8QLkqrVSf7csmsJcvgj10x+3bFvbrJkQkKpGzZ2wSJGxa1D?= =?utf-8?q?L74mtoDchJ0iBrUS62yREIQvJGpCZks0hvlEd5+tn3xVS4Ydh6Drb5/l+HS8qy7Jd?= =?utf-8?q?HcED4mM5vDLeVfdelZ70PIrGH7cRqu7QJNs1QJBuV3r+52PtXW+/v+HY9i23Q18fP?= =?utf-8?q?yWa5ySQLq7YJWU7lysS0IP8T+hGzrU08zzmTX+3TwicPlVn4+30Dk4Ev5pRTOPsQK?= =?utf-8?q?0bwCaUR6K1uDtC+P6+MrHGn2TZbatcqj2Tn1y3ClzPtqJurk0kslPXgVn7+0UWV57?= =?utf-8?q?7T8j1Q59soQu8b2q//ozshPcuTtMFYX1cxAGU9UpUpISOelN3qWTNp18NxJXc741r?= =?utf-8?q?FQeaSzrqeqtVbn5kR5+PVeDrqtNq1NnemvUZiGYwmvpQ4wgBPJKTbfvNcC8g5cKki?= =?utf-8?q?vT6hYFeitTtlUsyhknPa1+XB6Ar3l6WySPXDOdlge+DvwMk+uw/hxhqrCF7LB1RoA?= =?utf-8?q?k6fM2OTKrrjwZg7RDRIWFRFrf8ZumQAs3UkVZRy1j40KUWO/1ONvC+3QwLURyTUJ3?= =?utf-8?q?bK3QLC07ImwK7stgWV2WbOdRI/EJSBBzLoD4epfjJeW/gU0j8IsonA+xz+N4WJ+7F?= =?utf-8?q?hxIgJNbP+Vn3G0UcVP1x7gP9imwfPInq0v+zoHJqdpBusNNX9Z6ISIY5INvVKRc2M?= =?utf-8?q?oa+HiZusaJSpPayWG3j0BT8DUPy3iyo2HM/suVsyjUr5rQ2xmU9T6+gEcLmnsa9If?= =?utf-8?q?NxIGocQY2u/sOp6DaGoQKzRlHApjksUiBnsqYQ6N5hWbSShq478FD4um0QYUFaL27?= =?utf-8?q?hEBCwXwGZG1Ke6z2TmrMSuF7Mv4oyvzqtatWRgavcjn1BgHjpTgmA63LId2qvUvhJ?= =?utf-8?q?0TmTwhdUnrKoFokFcEVeXPifO5KyfE2Nf6kerd0G8tAkT4PlZQu9QjAuoGqaNqzvV?= =?utf-8?q?Sjq9LJtmOu6UFj6dxmY3HEt66pxQxI2axojv9CliFv7IvA01AWzsjuGY2ZEt/Dto8?= =?utf-8?q?asdx96MTM2t1sQ19I3zpMdM1oSbkPnMuY2KWZkzA+VyxUZH7zHOTsnK3HYncYEBcl?= =?utf-8?q?mk9KuvDpqfUuvlW5JnpbM3zuEfZaNlkhniPYhoTLxAGRHKq3SumKOGqzxlGbuJVLq?= =?utf-8?q?lheoPQc24y/fAmU37NIk0L6YRrwVfKjZ/U97lXXpZ3f33T7RRjE4UUWNCOZ3yuC8L?= =?utf-8?q?Vu6AqkGlNKQMxbMINO+N7g9HBhn+H7rORHaDY0lC7vJBFGC6EjAvLZOSz3VVFFXV5?= =?utf-8?q?HlAaXXNWvF9gL33D/fupSFMQjVtWOUNtiHf96Y8ApYk7jyHCDTKA2BXOrWqOU80iw?= =?utf-8?q?fyPJhH8f5ElETbSWCrKMIfBG+y7ftO2MvKW9XbD1VGWnH6Il98Z49N4lztWsUp5wp?= =?utf-8?q?+WU+HhaoR8RFiXy84Ugr2wYFLhADc4XWwb9deeyLPg8owej1zkcAKgAO0Jn7QJJYU?= =?utf-8?q?cSRPZQjs4PiyOGzh3fcDW3IsalRWRmudcxZstJOFqofEUv8GOAv5Es9Nz6xgQzg5F?= =?utf-8?q?k1oJrRLpQLhXkpYTvEVjCy9VB3eIwQGDjj3nKe5SbahLneCvOm3Qd2W4woPiLqie7?= =?utf-8?q?nUwvPlGEpkFzIfV+SwurYR2FcpS7SHDw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: af69b0b7-78fe-4020-1eaf-08da2d0fabb4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:35.7626 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xkxNBtUYfPjxu2gdIuvXAXahGnWwUdyFZs3dOvAxbej2i6bogxprvnDxvr4ehSQPgHBCqEA9uAWPjHwgLwvwxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: T2rHEvokVdlIloDLQRrr5mvCIjRj9LPT X-Proofpoint-ORIG-GUID: T2rHEvokVdlIloDLQRrr5mvCIjRj9LPT Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Assign separate address space for each device in the remote processes. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/iommu.h | 40 ++++++++++++ hw/remote/iommu.c | 131 ++++++++++++++++++++++++++++++++++++++ hw/remote/machine.c | 13 +++- MAINTAINERS | 2 + hw/remote/meson.build | 1 + 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 include/hw/remote/iommu.h create mode 100644 hw/remote/iommu.c diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h new file mode 100644 index 0000000000..33b68a8f4b --- /dev/null +++ b/include/hw/remote/iommu.h @@ -0,0 +1,40 @@ +/** + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOMMU_H +#define REMOTE_IOMMU_H + +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" + +#ifndef INT2VOIDP +#define INT2VOIDP(i) (void *)(uintptr_t)(i) +#endif + +typedef struct RemoteIommuElem { + MemoryRegion *mr; + + AddressSpace as; +} RemoteIommuElem; + +#define TYPE_REMOTE_IOMMU "x-remote-iommu" +OBJECT_DECLARE_SIMPLE_TYPE(RemoteIommu, REMOTE_IOMMU) + +struct RemoteIommu { + Object parent; + + GHashTable *elem_by_devfn; + + QemuMutex lock; +}; + +void remote_iommu_setup(PCIBus *pci_bus); + +void remote_iommu_unplug_dev(PCIDevice *pci_dev); + +#endif diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c new file mode 100644 index 0000000000..fd723d91f3 --- /dev/null +++ b/hw/remote/iommu.c @@ -0,0 +1,131 @@ +/** + * IOMMU for remote device + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "hw/remote/iommu.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" +#include "trace.h" + +/** + * IOMMU for TYPE_REMOTE_MACHINE - manages DMA address space isolation + * for remote machine. It is used by TYPE_VFIO_USER_SERVER. + * + * - Each TYPE_VFIO_USER_SERVER instance handles one PCIDevice on a PCIBus. + * There is one RemoteIommu per PCIBus, so the RemoteIommu tracks multiple + * PCIDevices by maintaining a ->elem_by_devfn mapping. + * + * - memory_region_init_iommu() is not used because vfio-user MemoryRegions + * will be added to the elem->mr container instead. This is more natural + * than implementing the IOMMUMemoryRegionClass APIs since vfio-user + * provides something that is close to a full-fledged MemoryRegion and + * not like an IOMMU mapping. + * + * - When a device is hot unplugged, the elem->mr reference is dropped so + * all vfio-user MemoryRegions associated with this vfio-user server are + * destroyed. + */ + +static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, + void *opaque, int devfn) +{ + RemoteIommu *iommu = opaque; + RemoteIommuElem *elem = NULL; + + qemu_mutex_lock(&iommu->lock); + + elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn)); + + if (!elem) { + elem = g_malloc0(sizeof(RemoteIommuElem)); + g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem); + } + + if (!elem->mr) { + elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION)); + memory_region_set_size(elem->mr, UINT64_MAX); + address_space_init(&elem->as, elem->mr, NULL); + } + + qemu_mutex_unlock(&iommu->lock); + + return &elem->as; +} + +void remote_iommu_unplug_dev(PCIDevice *pci_dev) +{ + AddressSpace *as = pci_device_iommu_address_space(pci_dev); + RemoteIommuElem *elem = NULL; + + if (as == &address_space_memory) { + return; + } + + elem = container_of(as, RemoteIommuElem, as); + + address_space_destroy(&elem->as); + + object_unref(elem->mr); + + elem->mr = NULL; +} + +static void remote_iommu_init(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + iommu->elem_by_devfn = g_hash_table_new_full(NULL, NULL, NULL, g_free); + + qemu_mutex_init(&iommu->lock); +} + +static void remote_iommu_finalize(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + qemu_mutex_destroy(&iommu->lock); + + g_hash_table_destroy(iommu->elem_by_devfn); + + iommu->elem_by_devfn = NULL; +} + +void remote_iommu_setup(PCIBus *pci_bus) +{ + RemoteIommu *iommu = NULL; + + g_assert(pci_bus); + + iommu = REMOTE_IOMMU(object_new(TYPE_REMOTE_IOMMU)); + + pci_setup_iommu(pci_bus, remote_iommu_find_add_as, iommu); + + object_property_add_child(OBJECT(pci_bus), "remote-iommu", OBJECT(iommu)); + + object_unref(OBJECT(iommu)); +} + +static const TypeInfo remote_iommu_info = { + .name = TYPE_REMOTE_IOMMU, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteIommu), + .instance_init = remote_iommu_init, + .instance_finalize = remote_iommu_finalize, +}; + +static void remote_iommu_register_types(void) +{ + type_register_static(&remote_iommu_info); +} + +type_init(remote_iommu_register_types) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 4d008ed721..cbb2add291 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -20,6 +20,7 @@ #include "qapi/error.h" #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +#include "hw/remote/iommu.h" #include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) @@ -99,6 +100,16 @@ static void remote_machine_instance_init(Object *obj) s->auto_shutdown = true; } +static void remote_machine_dev_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + qdev_unrealize(dev); + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_iommu_unplug_dev(PCI_DEVICE(dev)); + } +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -107,7 +118,7 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; - hc->unplug = qdev_simple_device_unplug_cb; + hc->unplug = remote_machine_dev_unplug_cb; object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, diff --git a/MAINTAINERS b/MAINTAINERS index 1b5719cd89..f257afcf8a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3600,6 +3600,8 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: hw/remote/iommu.c +F: include/hw/remote/iommu.h EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 534ac5df79..bcef83c8cc 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -6,6 +6,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iommu.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) From patchwork Tue May 3 14:16:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835861 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 36190C433EF for ; Tue, 3 May 2022 14:36:40 +0000 (UTC) Received: from localhost ([::1]:53130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltdn-0002tH-6z for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:36:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLY-0000T7-IX for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:48 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:14524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLW-0001QM-GE for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:48 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243DAHc5019339; Tue, 3 May 2022 14:17:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=SKq+lWqOLLS/Mx00DMxGlW7ota6diAEcJ93gdJsbq9I=; b=iFKbE/UXTuyHBjIBHSoPsAD+ZsWP69J4HGOK2Cf+OS6TWpltaF7UHHjZCsTPR/QWk4X3 nTQf/jH4MgqEagB+gS1nE49sD9t2IfplEM9y4qNv7l+FWkX3STtQyHZYru7poIOjJlK6 /kVBbU/LljgcB8NDuMXLNy2MZWiMn37BZYxp9d4ZmgReD/Y2yTlSuMk+uAuEC2oPYyKG ky8EAisCNKOCIqiEtZTlzniRqItPUGby8HpULRvreXLqbivIAtNms6iZc9qF4T6PziN5 RQL9HsPNB7kwxh6PdBPvw8olEhEAe+KjxYwnXoL2PQDt3l7356u3cn8X7KQGUOOJDY7B PQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frwnt5rxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:42 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EG1Ve032363; Tue, 3 May 2022 14:17:40 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fsvbmd34p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UDPBPvjzQQhscsYBWyIQJNcyU3c0K8tf8IS6X7gwJ4o6b2xsTKuVwq9kxcthneuzJLkNf/f94al6SRs+p0NNtvPyjuQyQ7PcKl3G5Zz0IGBpoaqruU/+2k0DznZ8jOvsX3cVjBHJAQ9GRsyb8qMppfecfjoG2pN1nCT01Yk8wTrCgk/wFySoaad9AJW1BlCuyfCwHPfnbRL9I89Eg8+2VW3q3DdzZLlxqeTHOuxYq5donjqIt5c+GPyBJIJIPMExYjfkFCUHlp+ZAKqi/TIKRk2zWJZFa+DCoHYkLPXy8vLx9p+aNQjCKRq5W3p9DSq35YKvRwoQe0K6yI0+GORkwA== 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=SKq+lWqOLLS/Mx00DMxGlW7ota6diAEcJ93gdJsbq9I=; b=UvyWolOds/p/E4Mup6fg0rCY0z6w11HK19A9kgpj8ajPIsrEMCrAlUAiClhwiAimE44JeUskLiTBVgVhgA+0m4k37LAICzV7Nhd/ORSmoFsre3V9YvYMrxfrd1liaYNqtuBzYcGMMZIHe5IL4Y2+54h/GpzX4I6c1U1aJFKXoLiBBtZo8QaBVX98de3aTMMND80IDsuftpaOTpWlXZVmZQ8xe5HIhxbUaJFQUqzPczNrAp6jQyHJHYLmqmjPET9ITwB8dVMfefI+Xb9KWug0dkvT2+I8PB4+OQkz0rLx/W2l0/PEIY2mXlcGUc26jet4xU4eK4xUdg4Zy1YZY9TqBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SKq+lWqOLLS/Mx00DMxGlW7ota6diAEcJ93gdJsbq9I=; b=wdCn8qwR1eijc54kCfxcYbo7TWZBCbVAJ760VQ2aCPduzf3zQuCIl/WO4VM6o84TKLrqntn2L/UTjB6BPw848ux+T9I7PObAa9eaucMNxMWfA9i0mGmECd7CF8qumB03Z/81lAndyZDdzU2EC2003w+dk3oBfDevsULBBT4vcC8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BYAPR10MB2600.namprd10.prod.outlook.com (2603:10b6:a02:aa::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:38 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:38 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 13/17] vfio-user: handle DMA mappings Date: Tue, 3 May 2022 10:16:54 -0400 Message-Id: <12e7a02ffeafd9f50cf61cba092c7207e328c23e.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2d4db23-1c33-4051-a259-08da2d0fad44 X-MS-TrafficTypeDiagnostic: BYAPR10MB2600:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TFm/uSb1oaTI9CLOWMlNmlSg0U6QWmpvVEdMrIW7MEoVvweN9ih/ytP2XybNZkKXxy/yozcJ+nHu/nUITZXWfeQ8+AvnnLkhSmSvsEBFQw8fI0mcF53ihWMSBkdDgUawtne/JVrCfrp+dFKP2XxVShokz7ZD7JS6t2uJ3WsDsSdI7jGrbeGxma+yOniZpo0W9sEOiTWNC5GUPAQzHA5GFce+TyV+KnrIWGviiH0oTeDeNMvJtj4YGsDHVaWpbTDJ+IFmdD7Z6OQClqdn0nImPUm+64BucF7f01xK0Y/doS8AsC9XvlqfmRuaV1sfD/nViU/M8KogUGOm6aIf095HuoPRr3n0VQNSR/BjYdxKPa2HYpOAQ7V0cIiy71LfJOeAoW35Xn4D9kQio8RjRgDAexGLFEfovbWPNrfwEh5yNV/rEWn8W2ZQ320mu0NT6XIqEqwu0/rOtWasYGOvELErsRoMfmLd3V12TQT40NORvjBbhIP0FYdujQqBHlo9ki1EfAqf0NjYbbzVigeGXSDEQ+7c0+MYzNt9KgcpjZooRsrgue+sd7xlDkKFCF8ZYbzzpQIxsWs1oOtXixD3VEKglNzDRZWiyz4IckXY6kx5+z9DkHI7UgElS6lXebeWgAAEIvjYX39h9rkSdGKxyfbj77D8p/9roy6zE596YsbqAutFO3P/bnyTmVCiOjSBzvGJpIIJSGsmQgezUd34mfOn/w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6916009)(38100700002)(316002)(36756003)(38350700002)(83380400001)(52116002)(66476007)(6666004)(8676002)(5660300002)(66946007)(508600001)(186003)(66556008)(4326008)(7416002)(2906002)(6486002)(86362001)(6512007)(26005)(8936002)(107886003)(2616005)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3tf9r56Me34qYa37VjAc4OvJIGzFboBoK9fU3LOx2XtW6GyzhiMgd8Y38SEYHSfUz9CqtiHldq2M/08ejMO9M+AOmzVesJQQC2uviHVrfrmb0fIEEB577YwjP8fIlYnsK5TU4Qpx3VlVH3jJ2syhkFVd7NIDN0nos0QxmE0YJlP52TsqHI3ROvz7IgPZvb6VulNWUDcHi2fvkUGkUmggSZAfC9IsqgCcCyY0o4ay4iEsSUARBIKMp2cyX/ncRyj5JSoL4JNqh067orpMImmFIx8zW3SUpj7s74Yyb+PbyqPg2tlFSkbwPiUJBiVfQjFugW8jw2851MZubgf1bEvldzRuFnxKBa2I9RhjRmwACKNdLmKe/AVbWW1dgJzrgIxQOoI/l4n78dhFeYq2w47JaLOFC1jA6DNkl4Y6TMLX8B/rwWvhK0Z/n6cy/9bnUsJxrCBp3E8oei4YG2Mjr3QdlgdNZru38BlhNecBNE2oeZ9BeQA6MOmcFajKz+Uvv6z0GyO8xvNvUOV96NlLoZ11UAVsyJKZyamT/WfThhi/76JQGsSNkes04iqRs4w7PSDDGmhFEGvmrJRSY3yN/uRdqKK46JsYl938ZXf34Y4VNniKo4jftWBZChmQqTNK1hn1kKxxx3UOPpSDW/ztzzX64zE2QJEbCikYt1VJn7X5lCn7iBYrL6ADr2dAaab8ARzRoEzr8cyl2HzZLw9b7tPguksvkpAs/0sh0r5h1sO0Zmj3TvUZgG6HuQ5FPeVismf6tUCRGrnFGjSj9kQlCe0TtPZLxL3uDLk0tMD++k3/+sgDTvReovCb7VKsdpCdryNoE3apNK044p59heiJMNAyQXImhiz29k1ryv6wxy4qS3YFVriRuFTy3/IBqC+dGlc72Z2ZfB1fXbuOHxS3nJIN0dfxj/SPuW1fH7c+5p7VpugSaKptnqUxNNrpmSlhttkQuefusFxK6u5PLHrtOlS8i5mCvGgM4h6OcPz0y+ZjsxoTuZu4uV28Uh40tXLRFq9wFy2k5jcZbpgBHr4lQnl7Q+HXPOHegm5uL9IOtfeJ6RN4/aCe8GNvbhPPA6c32b7JMs1dnoijoKuJJvBr5q8x3bjbeHaqqBu2gkYYJeQ6L3KM6W7Cw1eAoA2cMB6Ba7DyKfPBgnyobsC5U8uJfaC1fZ1MIjzDYFduOQ1UNP82mFk5I2cat/Qf0JPYA3YjRfzjVhD2fWEBNKG2sW3etFtaCEgHFiPFY4Sz22yUeLFeRKg1mWZ79kiqFU9czusA4pF4dbfmRdxtYVN0qoGgMcCkU3KlZswRomqXcxldPjngA37KTUJ4Vno0f9gZPGBEkswimIHFHFMhrHDJ3LvZvSiVtNlZcTZXvdHFrzAjYZUFiO3Y7xfpWt1u/rLDFAZVfWNbkWtP7dw89K6ihr79ZSfEqE/Pc6lH9ib5986528eGwAtmdEfc3Xaz/qThNcw2lR90cJCRUqc5UADV/qI9htJYSozS1smYh+rKYcFM5r6EUXl72OKkEPbvfe705JZSvBwYgWB91kGI7R5TeqGbE7SM0AmIiBYdyDieODZt4aNHVlRW1Ts5QdeW6LlVeBESTeKJo3ltlZ4u2lDfknGyMwXjLPGcZ3Y4oCQXC7l89KmJfbQeJXQRgyLPgqDwcPatosW6Dc06lmh9B3KzfJP/z0MLl6NtDFw8ZMxUquGlWuW7RTRpML7L2MfS4kjSD5/r9JOPwwOwPastiw+17rP6ivAUVg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2d4db23-1c33-4051-a259-08da2d0fad44 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:38.3093 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: glSo5KTgboc2icBCnrGE4P+z1zaFmyfRKmsyICrfTCN5oiflRq6VNDGmTKDPqOL/KQeaozE8olhePJfw3kf8NQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB2600 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: dSLxK9YN0EmbWCOwGaslQxrXIYY4hqj3 X-Proofpoint-GUID: dSLxK9YN0EmbWCOwGaslQxrXIYY4hqj3 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register callbacks to manage the RAM regions used for device DMA Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 5 ++++ hw/remote/vfio-user-obj.c | 55 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 3 files changed, 62 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index cbb2add291..645b54343d 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -22,6 +22,7 @@ #include "hw/remote/iohub.h" #include "hw/remote/iommu.h" #include "hw/qdev-core.h" +#include "hw/remote/iommu.h" static void remote_machine_init(MachineState *machine) { @@ -51,6 +52,10 @@ static void remote_machine_init(MachineState *machine) pci_host = PCI_HOST_BRIDGE(rem_host); + if (s->vfio_user) { + remote_iommu_setup(pci_host->bus); + } + remote_iohub_init(&s->iohub); pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index c81a76094c..736339c74a 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -282,6 +282,54 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, return count; } +static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("mem-%s-%"PRIx64"", o->device, + (uint64_t)info->vaddr); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_add_subregion(dma_as->root, (hwaddr)iov->iov_base, subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return; + } + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_del_subregion(dma_as->root, mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -371,6 +419,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup DMA handlers for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 2ef7884346..f945c7e33b 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -7,3 +7,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" +vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" +vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" From patchwork Tue May 3 14:16:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835844 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 6AA90C433F5 for ; Tue, 3 May 2022 14:22:28 +0000 (UTC) Received: from localhost ([::1]:55252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltQ3-0000Ah-G7 for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLp-0001MJ-1K for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:05 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:28696) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLm-0001R0-Jo for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:04 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243E1bJK019152; Tue, 3 May 2022 14:17:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=bwpQbyF89pYHKySXBqp31gT7ja4B8YdjbKTW5AdBJlg=; b=axMzp8+x/GSHEbxX8RGkHlB3a1nz5Tez1uLrkVqd8YG4f67oMc3OLnpInYY8acJCBLIP /nXgaQKEYKL+mSEMV9hneGmBcTr4Bd3tLbdajAWnMCvzBr/aQa9G+0BSiqYhhlh2xRq3 1XYsgCNEb+FiNbAROjy3EIU5V601B179+tWT6X3xwr7Aq57tOywBHDIkf6k4PVnQ6PR6 /YtmlgKU2zCwYrlmSiZw7RLT3W5wL2eYbLMr0nZgIe4FJVB1R9KKZjCpRH9wHeBx4b0y E7DM8xQ+wFrUUqBI/LbgzCma9MxhkfXAD4suZ5hi4gpIU8KEijSYrvpFJa3/yDWXU0AW ow== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frw0annjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:45 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EEqli016184; Tue, 3 May 2022 14:17:43 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2176.outbound.protection.outlook.com [104.47.58.176]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fruj8keq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ABZ9bD7g23FnFKyjtfar7U8ijlyVr4UBsV2fKZHHuMFwzY+8tiSRDYG+6H2E4+AdAKcwl/XJ7rY15d/LfggpXF8CVKC1M1gb3ar2eDbP45JJHEjwQCIs3KgaK5C8WxHwDuyTATiAlvoHCwSfsYysgKL5Nq/lsXeRq0B9R4dJcgn3ZRNpZOZtrlbW5Fu9+BX8Fsr7Vwx4+fmPxnCLv0Rv5/l+0C3xmLjSGBBly/gfaObppJJFWIMJoku+ezxeq2/t75dQ2grPDARUrGbbl5/JnBXFE8pz6L52RCDja+bYI7OphzdP1O15PQmp78pdlC+IGT/WWSaoxS1Guu5kNP/gCw== 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=bwpQbyF89pYHKySXBqp31gT7ja4B8YdjbKTW5AdBJlg=; b=YGiqXGiMIQxyuDeZSf2a+c9YIM1cMY8f1YCBmuYPrc7oXKW2uqSju0lxVzvBKjCY8AZeu/+EENlk3Tro+9NieQOyc7KRtM5w8QT78LRUGWKMeCHnZArO0ZSvlHocHDF2yxhRoAteLf6lr+cALstjyo2xJ1gr14qYaMAi3WXzhpDXkRsosRIyYNM8D+hNKA65RKaYhKD9Yu4mofKlWA1Kn0C6WYJBpj3iYMmNyxYATrLGGqW+hNl9Z5JImV6ebo+imI5TnrskCLSXqIXjSJ9LYTMyInmKlPwIv10aNRirFmYQ/bnan5tsR6DREgXBP12ZU3wOgaWo33ndN+Pg34Ws1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bwpQbyF89pYHKySXBqp31gT7ja4B8YdjbKTW5AdBJlg=; b=vznvNLwj97ZI1eJHjJQG+klSyKm5yzqQsMY4PjuamlmhrZ4sdY9Oa7sgrMlIGG1JVGKeGXsnhT0IgtJcpehO6juWV7W9Sd5dvEwfoSG+jZ4jltsCX5eURGwtMR/Xhikpag1CrT9tMVrhfc7jz9m6fJ6l66SNkzyZHXiS9s2PyVw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BYAPR10MB2600.namprd10.prod.outlook.com (2603:10b6:a02:aa::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:41 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:40 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 14/17] vfio-user: handle PCI BAR accesses Date: Tue, 3 May 2022 10:16:55 -0400 Message-Id: <677a333e1c2843aafa8c6c2487e149208a5a5032.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e143c4f-c4eb-4a9b-d82d-08da2d0faec6 X-MS-TrafficTypeDiagnostic: BYAPR10MB2600:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xeynjphcred6hC4T+gTnZl+I3UoC5EOrm/ijuXYXqtEGcmgP7gXrOAF9VWE4IP7CMDpGcQ7DjVz1yQgxDBwCZIk7WVs7juYyHKZae0KWonwnurFcQ8GO8//OKiHbWoUetKYGAZCgVB0Q7+nnxvPb6fAjwy2tIhG6m6yuoNun3DJ0TDhJM8XhmHhF46SchYiA8o4fV+ZHm2JWk5Fv1JdkmtRGBtBsZpkB5YUSkghnNLPLpNc8nWyuT0MfgftIOslpX4zczc0OYtpphp+s83zHpRdEhzmflOUPoS02rQDqfZF+WcfBW4+nboW2V0LC2KfEoKagfVTctJrTMykKKwGeGY+Bn2HZyBJb7c4PHQcydXt0sJumP+5vQ1t/YZQq0sTFXuEfFErXTpj4B2kqFQGEo+HonHjm7FIIfP4bu6f2BEsw8PUqS5QLee1vf8f9dCok9p6f0Dzu/bUtWZafqJSAlfEkZGjSL1jjtt95SvwyiPXZPQl0iU5WujO9OuYM0uXLMdp/M+ieFmnYVHjT9NKFQ+GZ9ygO7bgt8jnIJH1UWAsIvGuX83vi2vcexatKQGSzGJgV9TAuVB3fMToxWrz/zv+5LT7iqqxDKAsOlfCbqJDfCdRMEns8h1AtZVfU7DzlcYDXue55KL1+B3B5nV2CXvkBdoHLj0mfl5Z/tjCbRhKWhUcnJMwj+RQdL6Fn3esWvdz00uRPkhVagDFD4R/G1Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6916009)(38100700002)(316002)(36756003)(38350700002)(83380400001)(52116002)(66476007)(6666004)(8676002)(5660300002)(66946007)(508600001)(186003)(66556008)(4326008)(7416002)(2906002)(6486002)(86362001)(6512007)(26005)(8936002)(107886003)(2616005)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /3oquNaY1WbwZDaRwlvBBrsPickeWq5T2Fo695g4K6JfsjYIFszKFuYDND0vvPghiWfr5nW3WhAh6DETI3jv03MDn8eGCs8SxNB4bcMMr7bGF+01rsJrUeo0vPOc4IpwaMADDwnSl4B4ikOmMqw/MaWrQj3OMsh+jw6k9VWJRa7ebVgWFCqmppnTuJrUfxbAuMU3OLtZwrRt2lV0xacvyw0uBWWAttCg4iukwf4O4jeDwroUzEtUZPn77cpPkF+gZJkvP9oTueFlguBQnRVLUM1fE9SPNnuKQnYSYc9mVJ1WzHn3kpu7xeZKZNiGIlkjVUXfCTYfwEWNVL0dt1agDh6e4Fg/KTTq7SnazTou4rKh3/peF2K/nKjLlGp2r4o9LUKQ7mU3RHz9dFD5f+hb2D2KAa5UPsYxjtHs7hf4em0sTr01mEzMS9QbCjSkWAfhOHxRnrl9zu3c3rklYAnjNXZ09rSLOHWiYbbv9zQi6imXJ0H4sNo7FsWqTxeVPMbaPU/Ciinnz/UwgMRuYN/4gWUACAHU4PhD5BIAAcoNNnjW2pRi9g7bbAA24WV6sXtf5hvCzkHzBbL5r7BVRRYjG6jFYqviId9qS9Oh2tgnC73a5Rtha2fqzauOPRV2RiYA8BbttQ6+RTA1IyPkaDXKyVrnWDfZZmK7wooEl+bE6S7am+nt/8MVFNLV2giS74SpQMWIehjKNTHdcyvtESbz5RHqhxJpIdAD32S+2S12gdo8Wgk9mM4MSXKQ925QA6UsWyyQhh/eBUFRTEqnUnYHcXmnKO8E9r/3/mNYgJf5Ye47+i8ALuDdZCVAWCV0FBfb+yTmH+MGCwmd2DDbUcZvU5w08uc6r53wOR2spFqkoqkxsIRSxoUSrGQA0puoaCZjb1XEcO5rHhWLWqfS/L0v8bSbqF5whbo7HeYka9J6PrVRsLaTC7ZpEwAbdJ8654YU7EscmDDqO/iAC0mcmJBrN+nYjpNKKzPswIQxTRh9b3tRNXddvrWrpFujLCXc1AUHS4V6zmulYJML2j4OBQ2oSUrui/n7MO5kXACmaFeE+Cbk3pguSWUq8z05lumm/LmnZquk/uIVW+jd3cr3fLTjbpQCC71PeLVKEczMDVB9GNUzzcmzYlwtuapwobHjr9iTmyZOx8fc5rQNpaKylZgOS96KiIqQlXT5ePZ1PqmEvLp8z7FC3sZ5Yn6d3MQSv/+Evm6xuy2MsHCSUd8DHtcTSoeHNJgMujjD8sch9kZkGWPpgeq45PdTTj+833CC459Y6jQiB4UA+PXPAtn2pwb7/qoKa3XqgwDcMIV+pxmNAHZEDblUE7N+d4kIHUVWC6hPsSYI0bbW5eUF0fgXHPMtJ38ZXNUsyaqUp7OPY7vGH0mhzlc+wdhT6Q0QkwwiO9hl1QBjDlc3Jl2ZVEZhoB5SZ+BqkuDLMBUSxeUNKd7TmFNl+inWotViKYwg4i0b6TnghhrvlNUeFM9F3HMmOAxIT8EFOyMXC66/JDgCfvrzPcrnlLlit8A8f9cNRS0YimTbbIyEEJdl63+GOMLopL7UmW49LCWETfRyE4hZi/LrnrJTPx70eBPXyjTOcxbGKwEPnRl20FR9QYLYOMOFwztMo1AzCwwjnro4msaVcgN5RwGu1etUSxORKPRYGj2boOf4mta8NQIm0Pz2gcrsKqFyqvXGvdjTKbCYEyTbB4rsous5OMaMJMfEBHbphCSOEnDPmVSywIPjrZCLE2IMWiHE5g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e143c4f-c4eb-4a9b-d82d-08da2d0faec6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:40.9185 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qji8nKWniK/ck92n59sdhTSjjn+U6Nuw5Gz62/0lPlBSDXLjelQ/BHs/A5Ot7NJwkbvaZ1QpboRqWQMGtvJ2xA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB2600 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-GUID: 4Zn9MS4LvUB7GFqj24frHNn0UGP0d1q7 X-Proofpoint-ORIG-GUID: 4Zn9MS4LvUB7GFqj24frHNn0UGP0d1q7 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Determine the BARs used by the PCI device and register handlers to manage the access to the same. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/exec/memory.h | 3 + hw/remote/vfio-user-obj.c | 190 ++++++++++++++++++++++++++++++++ softmmu/physmem.c | 4 +- tests/qtest/fuzz/generic_fuzz.c | 9 +- hw/remote/trace-events | 3 + 5 files changed, 203 insertions(+), 6 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index f1c19451bc..a6a0f4d8ad 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2810,6 +2810,9 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, const void *buf, hwaddr len); +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr); +bool prepare_mmio_access(MemoryRegion *mr); + static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { if (is_write) { diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 736339c74a..f5ca909e68 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -52,6 +52,7 @@ #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "qemu/timer.h" +#include "exec/memory.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -330,6 +331,193 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); } +static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, + hwaddr size, const bool is_write) +{ + uint8_t *ptr = buf; + bool release_lock = false; + uint8_t *ram_ptr = NULL; + MemTxResult result; + int access_size; + uint64_t val; + + if (memory_access_is_direct(mr, is_write)) { + /** + * Some devices expose a PCI expansion ROM, which could be buffer + * based as compared to other regions which are primarily based on + * MemoryRegionOps. memory_region_find() would already check + * for buffer overflow, we don't need to repeat it here. + */ + ram_ptr = memory_region_get_ram_ptr(mr); + + if (is_write) { + memcpy((ram_ptr + offset), buf, size); + } else { + memcpy(buf, (ram_ptr + offset), size); + } + + return 0; + } + + while (size) { + /** + * The read/write logic used below is similar to the ones in + * flatview_read/write_continue() + */ + release_lock = prepare_mmio_access(mr); + + access_size = memory_access_size(mr, size, offset); + + if (is_write) { + val = ldn_he_p(ptr, access_size); + + result = memory_region_dispatch_write(mr, offset, val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + } else { + result = memory_region_dispatch_read(mr, offset, &val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + + stn_he_p(ptr, access_size, val); + } + + if (release_lock) { + qemu_mutex_unlock_iothread(); + release_lock = false; + } + + if (result != MEMTX_OK) { + return -1; + } + + size -= access_size; + ptr += access_size; + offset += access_size; + } + + return 0; +} + +static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar, + hwaddr bar_offset, char * const buf, + hwaddr len, const bool is_write) +{ + MemoryRegionSection section = { 0 }; + uint8_t *ptr = (uint8_t *)buf; + MemoryRegion *section_mr = NULL; + uint64_t section_size; + hwaddr section_offset; + hwaddr size = 0; + + while (len) { + section = memory_region_find(pci_dev->io_regions[pci_bar].memory, + bar_offset, len); + + if (!section.mr) { + warn_report("vfu: invalid address 0x%"PRIx64"", bar_offset); + return size; + } + + section_mr = section.mr; + section_offset = section.offset_within_region; + section_size = int128_get64(section.size); + + if (is_write && section_mr->readonly) { + warn_report("vfu: attempting to write to readonly region in " + "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]", + pci_bar, bar_offset, + (bar_offset + section_size)); + memory_region_unref(section_mr); + return size; + } + + if (vfu_object_mr_rw(section_mr, ptr, section_offset, + section_size, is_write)) { + warn_report("vfu: failed to %s " + "[0x%"PRIx64" - 0x%"PRIx64"] in bar %d", + is_write ? "write to" : "read from", bar_offset, + (bar_offset + section_size), pci_bar); + memory_region_unref(section_mr); + return size; + } + + size += section_size; + bar_offset += section_size; + ptr += section_size; + len -= section_size; + + memory_region_unref(section_mr); + } + + return size; +} + +/** + * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs. + * + * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would + * define vfu_object_bar2_handler + */ +#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \ + static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \ + char * const buf, size_t count, \ + loff_t offset, const bool is_write) \ + { \ + VfuObject *o = vfu_get_private(vfu_ctx); \ + PCIDevice *pci_dev = o->pci_dev; \ + \ + return vfu_object_bar_rw(pci_dev, BAR_NO, offset, \ + buf, count, is_write); \ + } \ + +VFU_OBJECT_BAR_HANDLER(0) +VFU_OBJECT_BAR_HANDLER(1) +VFU_OBJECT_BAR_HANDLER(2) +VFU_OBJECT_BAR_HANDLER(3) +VFU_OBJECT_BAR_HANDLER(4) +VFU_OBJECT_BAR_HANDLER(5) +VFU_OBJECT_BAR_HANDLER(6) + +static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = { + &vfu_object_bar0_handler, + &vfu_object_bar1_handler, + &vfu_object_bar2_handler, + &vfu_object_bar3_handler, + &vfu_object_bar4_handler, + &vfu_object_bar5_handler, + &vfu_object_bar6_handler, +}; + +/** + * vfu_object_register_bars - Identify active BAR regions of pdev and setup + * callbacks to handle read/write accesses + */ +static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) +{ + int flags = VFU_REGION_FLAG_RW; + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + if ((i == VFU_PCI_DEV_ROM_REGION_IDX) || + pdev->io_regions[i].memory->readonly) { + flags &= ~VFU_REGION_FLAG_WRITE; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + flags, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -426,6 +614,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 657841eed0..fb16be57a6 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2719,7 +2719,7 @@ void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size) invalidate_and_set_dirty(mr, addr, size); } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -2746,7 +2746,7 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) return l; } -static bool prepare_mmio_access(MemoryRegion *mr) +bool prepare_mmio_access(MemoryRegion *mr) { bool release_lock = false; diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c index bce8360482..8cd33f6c7e 100644 --- a/tests/qtest/fuzz/generic_fuzz.c +++ b/tests/qtest/fuzz/generic_fuzz.c @@ -144,7 +144,7 @@ static void *pattern_alloc(pattern p, size_t len) return buf; } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +static int fuzz_memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -242,11 +242,12 @@ void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr) /* * If mr1 isn't RAM, address_space_translate doesn't update l. Use - * memory_access_size to identify the number of bytes that it is safe - * to write without accidentally writing to another MemoryRegion. + * fuzz_memory_access_size to identify the number of bytes that it + * is safe to write without accidentally writing to another + * MemoryRegion. */ if (!memory_region_is_ram(mr1)) { - l = memory_access_size(mr1, l, addr1); + l = fuzz_memory_access_size(mr1, l, addr1); } if (memory_region_is_ram(mr1) || memory_region_is_romd(mr1) || diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f945c7e33b..847d50d88f 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -9,3 +9,6 @@ vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" +vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" +vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" +vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" From patchwork Tue May 3 14:16:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835851 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 17BD9C4332F for ; Tue, 3 May 2022 14:30:18 +0000 (UTC) Received: from localhost ([::1]:41358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltXd-0002S1-3O for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:30:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLe-0000ng-Mf for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:54 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:27602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLc-0001Qx-4R for qemu-devel@nongnu.org; Tue, 03 May 2022 10:17:54 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243ECdiJ004338; Tue, 3 May 2022 14:17:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=mlCkAwpcRuzDafSgT+t7m0vM+vkwgP/E+WlP+5gnIcg=; b=tGEvApXdqOY8INtOV5t7gid5Cmwq+0UJPUpquE5HPOAGzDQ8kRkW8+jQEhRX7sGJs5UX FTHJFKvjSgKsKfZYodRNkH3iviRarZL9Me/yC8gcczE3YRzBbhq26lIHPuwuchq3j++H twTIb+USlWb9N+pZkWLxtuxk07UOab7GsbF+QTnog2PcOZoyN7PQrj3QuN2/UdpWbkxP 0ep+94/pWTeSew0K3+ANssVyJIADG1y/6KMe/KC+2PTnlexM3yOytZB2foRG5/R62HqB BbqCcKuS0GeaGkTymXFfiPQmc2nBVwSp/NjDIr/c2Ew4Fn0YNwbpJV+o0Th4o1wnFRbK sA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:47 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EGPwW002277; Tue, 3 May 2022 14:17:46 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fruj2e5uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuYV4saL/Nt3hRPCGXuqxmlrM+YFPzT64wMbLIs5FuB9puLk8wVmwXmawlEcKSXJVV/uACEByh8RbceuZzBB//+LzSgMmAHUr7TjF16QXD6Qh4OmoT18ssbosFB0IRhgcGle5sXt3tdga5UJwONEfFcLY9ntrAlmO/s/wBHOmZQ6HxxNKGYXJepSI7aiJOO65aLPCpsVO8om5hSdxVAd1hgE4lT6Y7tEzcUvm61boIyBK7nNrWsFS6MY8Wt9La9GgRGhiE3b9f8WdAoyQoiRau/nlBbD30WMwCfUnZ4Jg3SY46P89PSMfsHh0wOsWB73Cb81Lci9eFoVsume0fpDug== 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=mlCkAwpcRuzDafSgT+t7m0vM+vkwgP/E+WlP+5gnIcg=; b=hWf5ifH2fIo2tSuavzdHfRFEsaCLHvSq/z+mWQTruGO3+7jl1Qq2CeJkPH9IYjJB0L/76t6zgDRzJebBzFKdDrQMONUvusBGbLACK/UT81ZiXATgexvgsHmgvAXeSVXB45w0hf2jmPS8LqmkZorGk0sub0sI1ZBP7nCF1zFwFqQC1q1VkYj4QAFqnotDy9MfSiegu5GfPBfG3WxPza7AGe0qiQI/9DzXs2CBc+N3ViMzxooPYCY8kYSWWcNcx+o9wnZzp+2gN82HTyFg3EWlvvkNNJIb6aSJUCdE9XnknOpfCjjQPQ9lpPydA4BVybXmB/zj49I1p3A7c4ck2d0/vw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mlCkAwpcRuzDafSgT+t7m0vM+vkwgP/E+WlP+5gnIcg=; b=rudI5Z3UocLm9nPfktOmSVtzrwRvhoNgCl/WD4gvHs/Cm3vy5FWHnJuITm2Z9mYtsbQNMWF6lkEnrZep7RqG5sJksJcW6tfCrsVTUDQx/7ruYtlOMbrTnYl2R0sVcfGtrUuKIIA9j4+ms1HfT0Uqecb5QOIWB/MI12kE/ouRJEw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:43 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:43 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 15/17] vfio-user: handle device interrupts Date: Tue, 3 May 2022 10:16:56 -0400 Message-Id: <25ab3efc76a9f2b4fedf82f53a4a0cbf8bcd5eb6.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 02836736-ff19-4f4a-5bd5-08da2d0fb057 X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UJDAa5Jn1UXeJvTYI7lE7WGlK3Nqu9dz2hsfUX91QnZv7eDecloXhKfTrqliplJfXPjywJLkHQQ49Xu0yVbcgEQA+z6930vTXwExA9RPpm510v+gje/knctCHkVast12jzfNZFO7WeJ04HLJXOqtUnujpzVQHVfDxmvkxcj3po+O8LYQB8p82ypZitnK91UeElRRcwDk+HA+cHRHYV8WXcofJVqRkvWzOSichIS9dgU0kUv5cpvIiWk8EyEcmlChnt8MhpMy1a/Qkk03jdYVJ9AUtBquBtDOx5FLnrWQjRNP3IciO4V30+kmbBRqt2TuTjxHSy61MjsAyk5ugr0uB9rbwcPamhszXLihPpVX4Ub+Mw+jTsjN/psEA+4SkdzMDrWJQJQfbGvMk8Jv/iE4DE8d9t1lMkOnBIVbfngHMBRP57/xDEELsCFfsFX7D7awFu6kpRo4RtqzS1YxesjNHUAKagZRfr9aTcKBY+0FEyar20DP3/LfDGbdMq0t1bL0PiYvAraE3ZAaXnKS1Theo+O2MzXkv9y7Rz/hwa942G2Q8oznuoabtS+2M+xIxkjSq2/IVz6kMDMqHvjSueWgc5/c67owNRPgR77FTKD+TqWWTsUax3pqS16NCiuPbAXMyeN+3iUoD0cBbrJsnIM3Z+AMsNa5D3k2nQz5W/WUs3AgjRu53pxbwpastDakTHmRhKuC3+kKeLbGiOkKodjsWg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(83380400001)(66946007)(2616005)(6506007)(186003)(107886003)(30864003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: egDBvlbQaN5W7E+ErZ9j4pu7a8lHN5xYDpNXJb3vBdTmq5bjudZgd26ikK5lS8DdidN6hio8+1h2Rviyk132fbNfdAJouZT5Q1P5KzB3Qj0spq8PRsYGWmvu+9MrvQ4kpKoFlmykQuATS0ifhLcYwQfX6OVHDovTw3GE76uGTnhOxRaFf04KLQTBDZ+FQUXn97BI8YMNQIKdLjmZuONG2z8/dcLMSn8IoyBlOyr+xo+IHw/1V4WwELmeev9yS9Ztph6eIrEx8aTdffmyApN8frVibnBaEBbsBpIAvhhM7HP2m7okhOg0693Y94h9vhdMx0LqzciUGoudNk54KhVQXo82EwcuV90ig2p/FoJlG+LxrcLE3B6tQ9U6AH3MVdlm3SdaBtdeuyeGqPb/YcZVVdcX6ww6XP2U/R6JRKl41xBIP6+z8Gy/7JjGqSHc+emMFmwqY+YjSv4kB47qT4ZDadpGaBd4wx+35zeN9ElHYki/Q2S1UoCmuX7kovfifTiASftZ4/HMg//tgXGLgBBcum5+/io0CAQgqIlR/kwxZRmSLY13EAbgegZ4ReFI0GKOwoHUzk+1Fplita2F51BNG7+E4z6hu2VoddLYpk4/w48UcTdZQxRjLiIHSE+FvgnEfuXtBvA2JZxLdcMfdzJ9IAoOcwtobPe1mswMZ5I2pLEdXegN3QW4FW0sRmy3HDX7cELc6hwNlp9J8KOCj/MB3P7l8wGl8cYTaMEZRfHWSu2WHZoyMX7a3XA9NElOKgtZbCxDQo5mMOpC9Blsuv0CRb6+/NHTXR3ggMsJrjsi+ntHgGrpku+Od7dXpgQUdbcDQn6zYXqE4m0zrjk5RtihgNmbqKuwkoKDBnoXmHPRJg/u+hLWIxxqrb+2m1LZ5opqD0xScM1Q67tCgn6DAX8r1kznub819gtF7ZB08iE+PfYeSjb68Hbu+Y1D5C3DcnDyAbEGOPVktP/18EWP46iwCZ/4fvkdcUsUkSAFx6FB9RfvXLkEyAlekHqwdc7LM/nrO9wigx+dMW937Fl8/oGBTEwRNL+fQZQc43buNpL5zN0qoXqtNPtRvS5zkARuh6TA/gIu55ibjldW5s8hsVb2oRAHy+pAMgWS/TKKEDg6zBYqojyydpCrgppD5pZ9CAx/U4psvewpQd9YPGnttFQzCq/wItubiBACO8OdDPVDeyo3Y25pg4MSD13yRnzsNrnlBfciLwBscVchkoYXaqiCOGrHq5uEAtcXorKBE5Q9aR0UWzL4T7bXWN1gxFyGcRisIBLo13bHVZeYYdAY0720XFggNi/+RM4djftPDIYVVt7XG7OdZ+gxHLBQ+A1ej8fuIR3l87W5hAf6CyibAp8ZsLhTcxMpihibzRr8ZooLrDgf9CsZf5ZyxjY16u6O+s6NNDIjjtmx1gFin/J+s80gZL0rJ95mCdJLfLT8flEbB/E5GmO5+ZY1chSCnNIhMVMci97u9eEeBOjS3xFwi/HYs/VEk/Steirv88aaJSoZOcupuIKm3VhdeLf/HT6NSLnZCnaFGA8tOkv1gSW/0irTetQh4Ght9skKM6Sz2pcU5k1pT7H3BtMQP/537HBkt4sGHASLWUOmFpfgFJrl/+yWwIJTU1yh1yHUYe+aP3l5KRZj/J7oPCDu/fBKu0wM+Pf0NRJmin3HHGX7wxlXWOOaCHoeGT6rNsA1qE9smRzptilmXqry4HLR6V8AtqUXw9ICxlHwns8TUKRMX0XKhc+mvw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02836736-ff19-4f4a-5bd5-08da2d0fb057 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:43.5433 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kX0b86fOyLFFGKUoM1vDcpSB3GYvaA+OKrAUV2dzKhA4Jy6XljnQlwB5VgVMnJWkthXVRqMTyTcvgB9hwEVnWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: Fe5NbwZeFPVQv3unklAe9RXEpm4b_31M X-Proofpoint-GUID: Fe5NbwZeFPVQv3unklAe9RXEpm4b_31M Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Forward remote device's interrupts to the guest Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/pci/pci.h | 13 ++++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 16 ++-- hw/pci/msix.c | 10 ++- hw/pci/pci.c | 13 ++++ hw/remote/machine.c | 14 +++- hw/remote/vfio-user-obj.c | 123 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 11 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 include/hw/remote/vfio-user-obj.h create mode 100644 stubs/vfio-user-obj.c diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 3a32b8dd40..7595c05c98 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -16,6 +16,7 @@ extern bool pci_available; #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) #define PCI_BUILD_BDF(bus, devfn) ((bus << 8) | (devfn)) +#define PCI_BDF_TO_DEVFN(x) ((x) & 0xff) #define PCI_BUS_MAX 256 #define PCI_DEVFN_MAX 256 #define PCI_SLOT_MAX 32 @@ -127,6 +128,10 @@ typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type); typedef void PCIUnregisterFunc(PCIDevice *pci_dev); +typedef void MSITriggerFunc(PCIDevice *dev, MSIMessage msg); +typedef MSIMessage MSIPrepareMessageFunc(PCIDevice *dev, unsigned vector); +typedef MSIMessage MSIxPrepareMessageFunc(PCIDevice *dev, unsigned vector); + typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ #define PCI_BAR_UNMAPPED (~(pcibus_t)0) @@ -321,6 +326,14 @@ struct PCIDevice { /* Space to store MSIX table & pending bit array */ uint8_t *msix_table; uint8_t *msix_pba; + + /* May be used by INTx or MSI during interrupt notification */ + void *irq_opaque; + + MSITriggerFunc *msi_trigger; + MSIPrepareMessageFunc *msi_prepare_message; + MSIxPrepareMessageFunc *msix_prepare_message; + /* MemoryRegion container for msix exclusive BAR setup */ MemoryRegion msix_exclusive_bar; /* Memory Regions for MSIX table and pending bit entries. */ diff --git a/include/hw/remote/vfio-user-obj.h b/include/hw/remote/vfio-user-obj.h new file mode 100644 index 0000000000..87ab78b875 --- /dev/null +++ b/include/hw/remote/vfio-user-obj.h @@ -0,0 +1,6 @@ +#ifndef VFIO_USER_OBJ_H +#define VFIO_USER_OBJ_H + +void vfu_object_set_bus_irq(PCIBus *pci_bus); + +#endif diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f33c..d556e17a09 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -134,7 +134,7 @@ void msi_set_message(PCIDevice *dev, MSIMessage msg) pci_set_word(dev->config + msi_data_off(dev, msi64bit), msg.data); } -MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +static MSIMessage msi_prepare_message(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; @@ -159,6 +159,11 @@ MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) return msg; } +MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +{ + return dev->msi_prepare_message(dev, vector); +} + bool msi_enabled(const PCIDevice *dev) { return msi_present(dev) && @@ -241,6 +246,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, 0xffffffff >> (PCI_MSI_VECTORS_MAX - nr_vectors)); } + dev->msi_prepare_message = msi_prepare_message; + return 0; } @@ -256,6 +263,7 @@ void msi_uninit(struct PCIDevice *dev) cap_size = msi_cap_sizeof(flags); pci_del_capability(dev, PCI_CAP_ID_MSI, cap_size); dev->cap_present &= ~QEMU_PCI_CAP_MSI; + dev->msi_prepare_message = NULL; MSI_DEV_PRINTF(dev, "uninit\n"); } @@ -334,11 +342,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector) void msi_send_message(PCIDevice *dev, MSIMessage msg) { - MemTxAttrs attrs = {}; - - attrs.requester_id = pci_requester_id(dev); - address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, - attrs, NULL); + dev->msi_trigger(dev, msg); } /* Normally called by pci_default_write_config(). */ diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331cd0b..6f85192d6f 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -31,7 +31,7 @@ #define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8) #define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8) -MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +static MSIMessage msix_prepare_message(PCIDevice *dev, unsigned vector) { uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE; MSIMessage msg; @@ -41,6 +41,11 @@ MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) return msg; } +MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +{ + return dev->msix_prepare_message(dev, vector); +} + /* * Special API for POWER to configure the vectors through * a side channel. Should never be used by devices. @@ -344,6 +349,8 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, "msix-pba", pba_size); memory_region_add_subregion(pba_bar, pba_offset, &dev->msix_pba_mmio); + dev->msix_prepare_message = msix_prepare_message; + return 0; } @@ -429,6 +436,7 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar) g_free(dev->msix_entry_used); dev->msix_entry_used = NULL; dev->cap_present &= ~QEMU_PCI_CAP_MSIX; + dev->msix_prepare_message = NULL; } void msix_uninit_exclusive_bar(PCIDevice *dev) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e99417e501..f451300ce7 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -306,6 +306,15 @@ void pci_device_deassert_intx(PCIDevice *dev) } } +static void pci_msi_trigger(PCIDevice *dev, MSIMessage msg) +{ + MemTxAttrs attrs = {}; + + attrs.requester_id = pci_requester_id(dev); + address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, + attrs, NULL); +} + static void pci_reset_regions(PCIDevice *dev) { int r; @@ -1201,6 +1210,8 @@ static void pci_qdev_unrealize(DeviceState *dev) pci_device_deassert_intx(pci_dev); do_pci_unregister_device(pci_dev); + + pci_dev->msi_trigger = NULL; } void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -2235,6 +2246,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) } pci_set_power(pci_dev, true); + + pci_dev->msi_trigger = pci_msi_trigger; } PCIDevice *pci_new_multifunction(int devfn, bool multifunction, diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 645b54343d..75d550daae 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,8 @@ #include "hw/remote/iommu.h" #include "hw/qdev-core.h" #include "hw/remote/iommu.h" +#include "hw/remote/vfio-user-obj.h" +#include "hw/pci/msi.h" static void remote_machine_init(MachineState *machine) { @@ -54,12 +56,16 @@ static void remote_machine_init(MachineState *machine) if (s->vfio_user) { remote_iommu_setup(pci_host->bus); - } - remote_iohub_init(&s->iohub); + msi_nonbroken = true; + + vfu_object_set_bus_irq(pci_host->bus); + } else { + remote_iohub_init(&s->iohub); - pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, - &s->iohub, REMOTE_IOHUB_NB_PIRQS); + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + } qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index f5ca909e68..d351b1daa3 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -53,6 +53,9 @@ #include "hw/pci/pci.h" #include "qemu/timer.h" #include "exec/memory.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" +#include "hw/remote/vfio-user-obj.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -96,6 +99,10 @@ struct VfuObject { Error *unplug_blocker; int vfu_poll_fd; + + MSITriggerFunc *default_msi_trigger; + MSIPrepareMessageFunc *default_msi_prepare_message; + MSIxPrepareMessageFunc *default_msix_prepare_message; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -518,6 +525,111 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_map_irq(PCIDevice *pci_dev, int intx) +{ + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), + pci_dev->devfn); + + return pci_bdf; +} + +static void vfu_object_set_irq(void *opaque, int pirq, int level) +{ + PCIBus *pci_bus = opaque; + PCIDevice *pci_dev = NULL; + vfu_ctx_t *vfu_ctx = NULL; + int pci_bus_num, devfn; + + if (level) { + pci_bus_num = PCI_BUS_NUM(pirq); + devfn = PCI_BDF_TO_DEVFN(pirq); + + /* + * pci_find_device() performs at O(1) if the device is attached + * to the root PCI bus. Whereas, if the device is attached to a + * secondary PCI bus (such as when a root port is involved), + * finding the parent PCI bus could take O(n) + */ + pci_dev = pci_find_device(pci_bus, pci_bus_num, devfn); + + vfu_ctx = pci_dev->irq_opaque; + + g_assert(vfu_ctx); + + vfu_irq_trigger(vfu_ctx, 0); + } +} + +static MSIMessage vfu_object_msi_prepare_msg(PCIDevice *pci_dev, + unsigned int vector) +{ + MSIMessage msg; + + msg.address = 0; + msg.data = vector; + + return msg; +} + +static void vfu_object_msi_trigger(PCIDevice *pci_dev, MSIMessage msg) +{ + vfu_ctx_t *vfu_ctx = pci_dev->irq_opaque; + + vfu_irq_trigger(vfu_ctx, msg.data); +} + +static void vfu_object_setup_msi_cbs(VfuObject *o) +{ + o->default_msi_trigger = o->pci_dev->msi_trigger; + o->default_msi_prepare_message = o->pci_dev->msi_prepare_message; + o->default_msix_prepare_message = o->pci_dev->msix_prepare_message; + + o->pci_dev->msi_trigger = vfu_object_msi_trigger; + o->pci_dev->msi_prepare_message = vfu_object_msi_prepare_msg; + o->pci_dev->msix_prepare_message = vfu_object_msi_prepare_msg; +} + +static void vfu_object_restore_msi_cbs(VfuObject *o) +{ + o->pci_dev->msi_trigger = o->default_msi_trigger; + o->pci_dev->msi_prepare_message = o->default_msi_prepare_message; + o->pci_dev->msix_prepare_message = o->default_msix_prepare_message; +} + +static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev) +{ + vfu_ctx_t *vfu_ctx = o->vfu_ctx; + int ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + if (msix_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ, + msix_nr_vectors_allocated(pci_dev)); + } else if (msi_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ, + msi_nr_vectors_allocated(pci_dev)); + } + + if (ret < 0) { + return ret; + } + + vfu_object_setup_msi_cbs(o); + + pci_dev->irq_opaque = vfu_ctx; + + return 0; +} + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ + pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, 1); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -616,6 +728,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o, o->pci_dev); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup interrupts for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -641,6 +760,8 @@ fail: o->unplug_blocker = NULL; } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } @@ -700,6 +821,8 @@ static void vfu_object_finalize(Object *obj) } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } diff --git a/stubs/vfio-user-obj.c b/stubs/vfio-user-obj.c new file mode 100644 index 0000000000..79100d768e --- /dev/null +++ b/stubs/vfio-user-obj.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/remote/vfio-user-obj.h" + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ +} diff --git a/MAINTAINERS b/MAINTAINERS index f257afcf8a..d2e977affb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3600,6 +3600,7 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 847d50d88f..c167b3c7a5 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -12,3 +12,4 @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" +vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d" diff --git a/stubs/meson.build b/stubs/meson.build index 6f80fec761..d8f3fd5c44 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -60,3 +60,4 @@ if have_system else stub_ss.add(files('qdev.c')) endif +stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) From patchwork Tue May 3 14:16:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835848 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 555D6C433EF for ; Tue, 3 May 2022 14:27:35 +0000 (UTC) Received: from localhost ([::1]:35390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltV0-0006NR-BH for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:27:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLp-0001PR-W4 for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:06 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLo-0001RA-3l for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:05 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243BLJh5030616; Tue, 3 May 2022 14:17:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=w724ZuHrHAXeMxoWPy21id6gRSHTFTyl0Dhlxo3unHI=; b=WgTCsjhM1Kqd2b6hBgGnIr+CZAZ0VGm+18E3A26lMevI/wu5Oq/KShGfIr4MkhQ7taFo kmjra0Rk1NyGaV3vCcB55XB1xauh1/Vn5XCmcX0Fy0TVTlAM2ZEAHsBzeq7yfudaBfuX mStmj0hrp9v1nT16RariY9Ir1dYH/f3TPrhWIctDq90y1JvLiz7ilgoClOvkUthbOPI4 pSaJ63/f8uAatO3gixDTWyql26bEEEUC51oHWBgaZ0XsMw5GoMB206DkAKEobE1Sx55p i9rNi/EfaFqvDVQI76au0lAbU9YZlWnF4zRhB5DlfBHPheRLGPGt0FmxaqSC+yq+4/8X Tw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruq0dtrt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:49 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EGR9Q001768; Tue, 3 May 2022 14:17:48 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2047.outbound.protection.outlook.com [104.47.57.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fruj91keq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ex/86i70sAcbsWFJTY2opzKkzv6G/8IlWIBPBcCpFOcNvbzWVX/vwLwhvmBy7D0wjnS+yvzSwx4DZC4iXzBggYWDWpkAs4KDf1killHz27qms1cxgwtcQacOAkSQaTqPyzERuQ3Atdvx2vmW/Hfk8XHQ49aYLK91VKPeOZDj4pmNEXC2Mzf8eFSgSsSQLtu00OWAPpkU0eYlM3GrSfIa4le4GQl7vJgEmyF9BPmgPrRzXYZOWU/QHXxJArnt+QET2xxY/dz+isqp2thrS9VlOjnbnwOcgkiQxaR6TY2NMQBCcTSdVXhGtnENcazCFMMfhKxVyAKnw+V+64/wcHqAog== 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=w724ZuHrHAXeMxoWPy21id6gRSHTFTyl0Dhlxo3unHI=; b=EnTPwDUYdADySxmHKsSbgAPqQKPqvaZg1kPPzqNS4+7p9/ZXA3qPgDuDL+//ew56y2/9ontulzZomCOen1VX57oi3e78gSn/K8n0G6oZ0HBi2XUmduXPMBkflx+ByfdZN9l4UiDoB0RAE9CGYkXO0kOQxG2gaSryccIJB2XsSztHD2wptsbtKKnWLWRrZ0VInl055tZhjQytKZNpTEKb933zI61Xvlaab0oGejaSEun6ztdmVBzdoSv9RfM7pVECzXz9D+K0RGpu5f1TBShguUyMoRYPDjhJG5HVbWAQzQpN7OBgLtVSpY3Hk9WAxkZkGq8/cOXnQtYPgWY5zwzbbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w724ZuHrHAXeMxoWPy21id6gRSHTFTyl0Dhlxo3unHI=; b=N/UI7fKNM7z6GmrGeWIemKwMrzIbTdhBKtc0tcSeugmD7VAq/0eHbl/6V9SfwTpwpZr2d8jnBmBHEBl/65V4XtuP0vD06XaTy2RvlSwYtf0F60y96slIjbDKpqh1yqQbBjrflbR1a1QoIGbTKQSbmHhq71jZe8j/7WmFbUcdtJw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3358.namprd10.prod.outlook.com (2603:10b6:208:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 14:17:46 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:46 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 16/17] vfio-user: handle reset of remote device Date: Tue, 3 May 2022 10:16:57 -0400 Message-Id: <72e150191b85971dddae712f0f6969482cb4d6fb.1651586203.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1932284-7ae7-40b3-f3fd-08da2d0fb1db X-MS-TrafficTypeDiagnostic: MN2PR10MB3358:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LqJUyBSLcYROqTQcw6F8OQVX4uqpsAvqMIP4sTtx8QtHhOgNnr7zbLgNPq2KrxTyj/AmNmy+gvfQcJodk8rXc4hz/7gNA2eB63FkC3EK39qRRZRKOkwulKR/q5NjoYa0zzCCJGOKz1vB3AmbrN+96BI+QIwEF66xHicvkhd8B9Botui9TG+0qBwInR/TToZgYRm3cULbNWNJX2/rIYHpacibtOBMyGC8bVMs0znAhpPsnJRMuYD9PGsDkJbA7c+2UyUKZ4pC531AZDrDEN5chs7dsqnEheOcI9Yz+mFY2C9UAF5bS4NP+1DxLJyE1ardfbAkkaqHZV9Qm9Au5PfvK4NvYI0ebIBvQOtIdrUwgxq2WiDHSq8otV6rfBsWLvUGsD9qnELNgNWtg0Q4FFmL0lnS5yV+RYbpItPAe7jPtF7E/7z8ELnUSDcVcGYM6DFGQFT+NN/wNNenUlkV3mQ+IsFNPaoMEEJ1WJA6bVLj5mSFCGwBuiLUzGgQSWnszK+0BIzcrzBfkLH1KB8YksnDNTYZJIKdrlmtg9M2XmNnhC883JhsYGQwNIkUmtcURsDCyNC5jZ+nKPYhffcZW2GOM4RpRdsxzWCjZQHnNBrIPrwVP/j4o+u5Uq5uDRT44av4iBlIOQwrRirFuVGFXBJfq9U6utSO+pFF8DcXsgZLQqrNeQnm0jOWXP5XxjH4cE+0B2iVN/fdn2pnBzY5Y+DLdA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(66946007)(2616005)(6506007)(186003)(107886003)(2906002)(6486002)(6916009)(316002)(38350700002)(38100700002)(7416002)(5660300002)(8936002)(6512007)(86362001)(4326008)(6666004)(52116002)(66476007)(508600001)(8676002)(26005)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zo5hnyw49TSGAzNCEs5LKoESpdNlbwX+Zs6Tb8Jr+3CIZmgubns8MozUnw/JGJ+vkt3CmdbDfdIYKQrQTkyY7RelviPUbiviNqHKIfBTbK+U+8GZYfhac+LWlhiTefe5ubqbqMAiDjoCDlHNdmIdStCnObXoOt/J83N+TtfrIeNoPSnHrzkX2O+J0nqVnTNWOypFKZc4SRyLCkowN9uaOwz/39IN5CNXHFWiZqwkzd3a0EtwbLUqe+PMf+WqbpeqN6/fCdkYjOB0zupH4MKrXkzz6twd6yJQmZczy+PGBsUei9mOXf4O7QLYH8wihjAZqnPaHLaFSZZ7iRt0MHOUPWvy6uEUrarvxpfFhZu5/M+Q2pyleHS3z29e+EX3i3cYN/A/1ukFHhHreb9mj+vUukZrWBdr8Nx2i23IQYbyOrmCi7DYuiH3tZU9R2WhebmRkpgGYgjfm4JgJW417gMzGYloNIt0oi/o63VBoLcFPT5WG8rZ4FwyuaXYtFK/Q1vc8sS8On/4FLXKJypuXXOziWqJX9Ft/NjkPV+pRGzlWykLilPmB6xjkv+TzbbHzuYQeUouKKhNj4aLf4acnKMsHXovzJk8KNqmuWQR/Oadx7nxH9eM2In4BPCt/1axlz8+O81h1WC6oz3CJcfPqKgbN8jakEIMQjFhHzxlc1MaPa6lapvpWNDJnziX+tMbVXJBBltVfkmrepZgSagdsBAJhBk2HFOcYfIgSIaEt3aLg8rDAgpOy9daZw2FYn7fLS9W4R5yh8RjUvBjX4A3/qRjFdoCL++ZVtnMHb+aNJEK5VuJQI980hJUqHYFly2O2sz9EQubi7PoqqWUo5hkqSviXCX8GYc/c9NzhnN6on5OtYH2iMVVxdTb1m7Fouc6Y7ThwQZfM9lm4818v9AjnC3XTTho4MdY6ph6tsffyMy3tj9ztw4/4mi/BTA7FT5S2k7v6jM5hjes/H/33+CYytOw/wEQUfD4cz147RDqN/zpFSVxq1s+bTo2MepULeHMPVTz5a+10M+y3hoHgEaGrqQji60FYot47BVH/rHs0dD7jsWL0LgmJqASaD9C6AXHnu3iY2nohpMXIkLHHAPugSZdUqsvuGYr15QQtK5OnItRI01iUTIDjGikgaRbAoOyIyMiTLVPu8PtqtU+/A8zcgybOQm64Teb4DeSJitCsmBVuh2s7+ahLmP4LYMtQXCVX3cAaLiWjrGBOM7l3SAejPZdQI5wdljopVYO7NWDfMRMwFnJgBcAt41WAkztgLjEPmzPykg0arAr5h4/dawatBJnrfi4TEl/00um14xP9/WrmllPFXa1w8X6DbFEnnl653EG9bmx111s2YLwpRZ9df5NHg0XCPN/FLFFo4oQh+o3MqaEU/dad5xpKZ1VPUXza//z39sVix4EG/+fwnD1snaA3cvpsiuGVT6lTha0dlPF6nwV9sZaFKCGQWHc8Il61PQGcHiWicOX4a7jsFpNj4k4i0ORQoFppWeXp3gylDJPc+FuRorP4wL5m3pQjGw0PTsGVIkYn24qch5V5UPh9qjd0T6dk1ma2cFAwtbM84EiPLCCbiFLCE6NUYRqw8jjBG0lBNt6fvbVbrLtiDKL8UK0XIpXT9IY2ks4K6nzxFmh2GU7qQwI9BBdK5gbnPIyUyNelNnTQnS78kciVnFJGy4N2I8+lGg91S3xjcKYTIfqWt3tGytCY+mE2kUStdifhAI/iyQGuVeq44UsTL1RSYAUrA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1932284-7ae7-40b3-f3fd-08da2d0fb1db X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:46.0275 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: juHTelQDHBq2DXt7Ah1z37FG8jlPhzKrEkQKCnqL7lh44KaE4AFeF67QlUWkcga9PSt+bHFU6w5QLGhf/goj3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3358 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: XvNVxvY1ISS0TjhntCxqlTfzeoLiF9IR X-Proofpoint-GUID: XvNVxvY1ISS0TjhntCxqlTfzeoLiF9IR Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds handler to reset a remote device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index d351b1daa3..15b06744f9 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -630,6 +630,20 @@ void vfu_object_set_bus_irq(PCIBus *pci_bus) pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, 1); } +static int vfu_object_device_reset(vfu_ctx_t *vfu_ctx, vfu_reset_type_t type) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + /* vfu_object_ctx_run() handles lost connection */ + if (type == VFU_RESET_LOST_CONN) { + return 0; + } + + qdev_reset_all(DEVICE(o->pci_dev)); + + return 0; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -735,6 +749,12 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_reset_cb(o->vfu_ctx, &vfu_object_device_reset); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup reset callback"); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", From patchwork Tue May 3 14:16:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12835858 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 45A63C433EF for ; Tue, 3 May 2022 14:31:20 +0000 (UTC) Received: from localhost ([::1]:43660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nltYc-0004GN-CL for qemu-devel@archiver.kernel.org; Tue, 03 May 2022 10:31:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLt-0001bl-Ch for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:09 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:38822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nltLq-0001RU-UL for qemu-devel@nongnu.org; Tue, 03 May 2022 10:18:09 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243DAHcD019339; Tue, 3 May 2022 14:17:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=///lrZXZWqHcbD1GL0YEEYdYTKaDn4rh06gGgGd9UVE=; b=sUWkrIORa85FPvSI+NvV5vQS1VGRBriHFqtIxFHQ+du//vjW43g3nrwwYu0SJ0X2DLCl wQ+5I2APslgm25B1Q3q7IAUAQofTmatAVFfblhCMuXhCPn3LiBJGLB6ZQ7kfn6Hy8zSs T5KVQK7IBhCFhXdNjh4+7g6Iw4AXtHs+FN3rpuCj4wmHWA2RqDSDx4cVy9I+d5/OYBE+ FJuHDI11AEcxyQv4Bcw7EuOhSNdCtkI2cNOzQr+1donoGZyV2ki9btN1C9q4Tkrg+dDA G4xMdZUhFeHU5zUAc4IDS9aCIDfboZAhuVGQB1WS76Hgo4LYWYkhGquwvV8hPYp4ohVD 3g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3frwnt5ryw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:52 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 243EFNum019043; Tue, 3 May 2022 14:17:52 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2042.outbound.protection.outlook.com [104.47.56.42]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fruj2eaux-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 May 2022 14:17:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1fN8HPoiloF8ScfriQr+yLU6r0gH/Bu+zl25IOsoF83o7rJIg+E6WNaE/IYTpiB0Bz54Kz3AeqtQ61ZdAUjIVL1crPCPYgqi3FofGD6ei+LjK3X2Ce8fr6FvxPMwJarZlh51XPwAS/DkLbHkaVMIRG5Otv38nEikdyFUnolj1MVNUrGJjuEkk68XRjvo1XGOX3tUqTq215oh3E1RZYdqV2Hetgeokq1NKKCOPj9gAl8k84zWa+YKSK3O4rkHtL5wW/Yr5i1P+m+OImN9tAALkmwhDHbyzq0MIQ9xhfDrDm0Ja9SOUxMitDpvMuvCiFmxpqc5czsa1k466m6ugf3GQ== 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=///lrZXZWqHcbD1GL0YEEYdYTKaDn4rh06gGgGd9UVE=; b=YtidafnD3whVLCkAjZFq4hsJ3qSsQJwohr1IuC07Ai81tpPtpgRIMzsYs2tja8YbDd6TM9uni9ybKvx/zqjwptwgO0nS2NoJT5VJYj43QHEU1GG3JgZwZAOcbrWmL1K0thvRFU9bYoN+yNpxPrSIQjPaz5RPFo2o+2wdgldU93wSf2UlKzO7GM4PnvuDz16XOpN6/7m/wUO4qv2QIiWBuAvfZDbYrwGJ/I8bhO0KjXICtSH4/oF1wmUvRxEIE4PV2JNeF0QNHkESECT1Lq1G2jH1q3UaRadWB9GvkrAMD/mvsOMdi7YlZyggZbgAjmYpyfitwvlf7gLuPHP32W1vXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=///lrZXZWqHcbD1GL0YEEYdYTKaDn4rh06gGgGd9UVE=; b=EbySnOkHgq1VEEAO7+oCLX3bDh4A7f0EQvtAoM5875cMe03GACzTNGcl8H05w6vZZ9P7T5JeoHS5GRDzbkEmwoOiH4JDCExteVnsKL7x5XzdRoL1Dc30tvYQK16NJrErrb6IFut0/1c1+JdXB7TCzlTEX/XSbgSsNKTsbdHo6A0= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BYAPR10MB2983.namprd10.prod.outlook.com (2603:10b6:a03:83::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Tue, 3 May 2022 14:17:49 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5206.013; Tue, 3 May 2022 14:17:48 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v9 17/17] vfio-user: avocado tests for vfio-user Date: Tue, 3 May 2022 10:16:58 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50f57c8d-953a-4e48-29d0-08da2d0fb35e X-MS-TrafficTypeDiagnostic: BYAPR10MB2983:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c8cJOzirv8KU6dYa3UCgnRre9Y5m5RsUs+22mbP1TATp7Wnj42wF2kls8maq8ILwFhtC++vaS7+UZ8t2GbgfvEU+nfUrgvIRekrqhBhItL2Swxu1ueGlDDbxXaN/JR/V2fPQHTktn7sS+lNLsJ29MlWWz2ck874MGhRKIxRf2cLES7rBPli16W4+afZN3gS6byLYy1xSotyBEZF518qy1LJaXYNvxbIm8Q3KBacicyduON9cEgpUGXf3xPLJqFVf1hHf3kTR4VZ1NmvCa/Uu6Y8FAiZFYUZETQ4aSeza+BR1eu/YUdNQT784oMaxManZ5bHg9y+/WL/WxLdula2TcB9cQESjThpa9rL7WnlZxZ308sBZ0ElTyNKeNrZ/0s0F44SJ6RS2dnHm260DwM5pUan8x4MUwV4vqoeN+WedRzX3ASANQO5d67q09wjVNrHHAtOR1FzvLXsBkYxozztc1hhsf6pqZQrxeTY4LBgiUwN9sc5EV3BBwDlV3Tvs/PqLBEOlqVYeQAefkzQqgmYfdfWziwz2t86rHQbyGfebrk2Q0gMEne8LSAUjL5EMC3NsZjrMEbCpp+fbyzl03DUs7TJ+ti10CCNjL6gQVl5Nq6dx5kNAiO/izY0YnyzSlyEVXUyk3P0wakslKPsitCoDI0KI3XklrD4P3Lv4LyY2HTuuWiUkSRRd+5uYXqDxXSA5NOhx1Ds1/qWocQ3QfWc2IVakxXjO6WvruFdySeJb8yAMXYMEiZi5cCf5rfIdH/fX2HLZM4B72u5/HSJiFq4T2PZu0HUwbs07iLHGTTCo2is= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6512007)(6666004)(6506007)(52116002)(316002)(6916009)(2616005)(186003)(26005)(36756003)(2906002)(8676002)(38350700002)(38100700002)(4326008)(66946007)(86362001)(66556008)(8936002)(66476007)(5660300002)(7416002)(508600001)(6486002)(83380400001)(107886003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B2sYrw2LeSkZaP8tDKIiCrthkWihXLQ1cPDv1f9KlLoS3uQ7vQLhm05r6N0Gy0gqv+cxfGhLKChdloiwj2pAGOcdjAWflcU01+e5dp+BLOTjCLI+sLQBMFChsV2PaXhq9cHqHBgBsywEbrcjvUH97D38Dlw0ODavZg5XX34SDQ1PrkosYSr2y8761hBTwHdYaSK3ejOS3OhCeC7z7Wnc7IqT4fiNfEJAedqkeKveEQ4jenzFzf58L4iDv11XSipSvW3pH2yKcUox2N/zuOmKXHHKZrZDgY0fbrVYzlNe6hFtX/ejJmS5tLATYBdABP2j8SuCzLgxC0P+brwEysvAofzdj85iwjFqaRZEHrrn6czawE3QLqOUuoGlWJQRTxTmmGdfYdB3R9D4/H7L5mAr2C3HOf1JZoIb8kRnPOE8i6zFs/3L4jn/m0O6yLONlrkme8tO4JH07vNbmURuw9Hp/q7refHWuCWjwQAmSFlqSmPHGuxGayOV1M1VmdHNObKfRl26EiMuXzxQ9gyvqcO3fzXmZeeX2VareJarQSqkadTSQhskjvjH1DZUp1MgUZS+9sjlTGLzlSxARFMUWjKjN8l9FA6iZtAzuzn636ow5Dt3UdKujhrRJnn7oDWSgc10ajunU0/xGCRwInkckPvznBd4yZ/lcQjYFJt+EEbHTbDD4TQpQtg4uhYPvx8N1gpK8mBiQQxrmh9NdttTDoiHTCaahB27f15xXZ/z6mTAjadB0iWoKmf0qqN000ffyo4jwbp81JfZghShG6NBHL9ysr/va4OsyHhBIb2ZwHXaTvYVrC2QODaXtFHBc6Sh95DkzEwgV3VC97ev27mx5lDy7GoceckvAUHF8qA2ZRXtZ1N3xZz51DDxyi0wzIyCP73cKMfoE/iotjyTB0gBeBzBmuZuAWCy3PhNixNvyaG7OG3e3+XJY930tgLUvTM/4WMqVqT7118TuaN7kTZbXNGeyzS0oW3iSsRhxlM9nmRxs8iXoFhjAqZqb1NRgLgRWA2FPv0YLDAb2jQZg53Qfm5Ej1k+XoaX/FzfeJOkB/Sgrp6NL5OSk1XkfKXtjIKEX6AXmVBYiZNO7REcK/V2By3QvTlNDTzWxR9eOcwzr8nzxm1GTQXl0j4Bb4nWB0Eew1g5IhWf+4elveHvk/71B7DX2Y0GZVHApIVT1+0tpfYpI0EooKmgXC2mKDSK/CzF8YYWNvEm3RpkRSpnZBCo42fifnb0PIN/rUFPa4zw1oGU3R3NIDT5oU1XabFicK0wElAvfqq4h7BPFKhRGDemvexXf5bKFvlvZDOo6B1H2xr8rhwcn2QrO40FCLyQ8AbTWuWE6a3iv481r+MjYNdHN/Q1gKhgzMFQchtssxWKcnnSmfAeOPcg1uUYe5qAOOvxrKmHN/iBa/5vVdiCuVH1BpmgpC5rOTA6i0R2juAyvK9KJfttkQERJV45OHxXEhWf+29DO8UezIGwytRJiVc9LBNelEKZrvoatfyKHpHfpOv0N+JKJoYxD6luBbzZA2sjBYiHESjnCYsbynJ8vFEV3ihYfLKw1SJzhGm/iuMRU5yOWrZI98IR/CHkksmQvNeRIU1gVIzosUeZq88AqUQupBmbGgfUEKZEsjtdVIH9tJWM1r2u5bIcHvbp06eg7nus1hMvLW/XdvStv/N12agGBnxVvts2FHleUddNIsq0JN8alftwPPM5Puxy6WHBdC2Tkb33Ag7HnE4g5EFjH79HQm5gGw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50f57c8d-953a-4e48-29d0-08da2d0fb35e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 14:17:48.5429 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MiuO+4BYp5c7JCygG+ZO+uM3cBRkLlm3Eybvh1rrCnhNr5KuTyWDJzxZSLPQ3q2s3ybZlGeYaY1ZXkqIiJ6U2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB2983 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-03_05:2022-05-02, 2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205030103 X-Proofpoint-ORIG-GUID: hZyt-2ROMCn8sFrSlvFFbiVFznBmrnDe X-Proofpoint-GUID: hZyt-2ROMCn8sFrSlvFFbiVFznBmrnDe Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Avocado tests for libvfio-user in QEMU - tests startup, hotplug and migration of the server object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- MAINTAINERS | 1 + tests/avocado/vfio-user.py | 164 +++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 tests/avocado/vfio-user.py diff --git a/MAINTAINERS b/MAINTAINERS index d2e977affb..103fcb472f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3603,6 +3603,7 @@ F: hw/remote/vfio-user-obj.c F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h +F: tests/avocado/vfio-user.py EBPF: M: Jason Wang diff --git a/tests/avocado/vfio-user.py b/tests/avocado/vfio-user.py new file mode 100644 index 0000000000..ced304d770 --- /dev/null +++ b/tests/avocado/vfio-user.py @@ -0,0 +1,164 @@ +# vfio-user protocol sanity test +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + + +import os +import socket +import uuid + +from avocado_qemu import QemuSystemTest +from avocado_qemu import wait_for_console_pattern +from avocado_qemu import exec_command +from avocado_qemu import exec_command_and_wait_for_pattern + +from avocado.utils import network +from avocado.utils import wait + +class VfioUser(QemuSystemTest): + """ + :avocado: tags=vfiouser + """ + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + timeout = 20 + + def _get_free_port(self): + port = network.find_free_port() + if port is None: + self.cancel('Failed to find a free port') + return port + + def validate_vm_launch(self, vm): + wait_for_console_pattern(self, 'as init process', + 'Kernel panic - not syncing', vm=vm) + exec_command(self, 'mount -t sysfs sysfs /sys', vm=vm) + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/*/uevent', + 'PCI_ID=1000:0060', vm=vm) + + def launch_server_startup(self, socket, *opts): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote,vfio-user=on') + server_vm.add_args('-nodefaults') + server_vm.add_args('-device', 'megasas,id=sas1') + server_vm.add_args('-object', 'x-vfio-user-server,id=vfioobj1,' + 'type=unix,path='+socket+',device=sas1') + for opt in opts: + server_vm.add_args(opt) + server_vm.launch() + return server_vm + + def launch_server_hotplug(self, socket): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote,vfio-user=on') + server_vm.add_args('-nodefaults') + server_vm.launch() + server_vm.qmp('device_add', args_dict=None, conv_keys=None, + driver='megasas', id='sas1') + obj_add_opts = {'qom-type': 'x-vfio-user-server', + 'id': 'vfioobj', 'device': 'sas1', + 'socket': {'type': 'unix', 'path': socket}} + server_vm.qmp('object-add', args_dict=obj_add_opts) + return server_vm + + def launch_client(self, kernel_path, initrd_path, kernel_command_line, + machine_type, socket, *opts): + client_vm = self.get_vm() + client_vm.set_console() + client_vm.add_args('-machine', machine_type) + client_vm.add_args('-accel', 'kvm') + client_vm.add_args('-cpu', 'host') + client_vm.add_args('-object', + 'memory-backend-memfd,id=sysmem-file,size=2G') + client_vm.add_args('--numa', 'node,memdev=sysmem-file') + client_vm.add_args('-m', '2048') + client_vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line) + client_vm.add_args('-device', + 'vfio-user-pci,socket='+socket) + for opt in opts: + client_vm.add_args(opt) + client_vm.launch() + return client_vm + + def do_test_startup(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(socket): + os.remove(socket) + self.launch_server_startup(socket) + client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, socket) + self.validate_vm_launch(client) + + def do_test_hotplug(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(socket): + os.remove(socket) + self.launch_server_hotplug(socket) + client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, socket) + self.validate_vm_launch(client) + + def test_vfio_user_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=distro:centos + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 rdinit=/bin/bash') + machine_type = 'pc' + self.do_test_startup(kernel_url, initrd_url, kernel_command_line, + machine_type) + + def test_vfio_user_aarch64(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=distro:ubuntu + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/aarch64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/aarch64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'rdinit=/bin/bash console=ttyAMA0') + machine_type = 'virt,gic-version=3' + self.do_test_startup(kernel_url, initrd_url, kernel_command_line, + machine_type) + + def test_vfio_user_hotplug_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=distro:centos + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 rdinit=/bin/bash') + machine_type = 'pc' + self.do_test_hotplug(kernel_url, initrd_url, kernel_command_line, + machine_type) +