From patchwork Fri Mar 25 19:19:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791911 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 A1CB3C433FE for ; Fri, 25 Mar 2022 19:22:21 +0000 (UTC) Received: from localhost ([::1]:51476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpVs-0001w6-Nn for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:22:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTp-0007O5-0f for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:13 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:59880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTm-00034F-1J for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:12 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHvbas000392; Fri, 25 Mar 2022 19:19:58 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=TTytcwBs3sC/ZBTlu4Wy3DNcmkSqW1CaZzbotzrSEgI=; b=c2Ygh/uFQqXU9DtDcOG4riAjf8OCwDknPhtukSgbC/WG8pbeooAcR25KjvdBimvxjO+Y rCBrZ0HqWYegeCplr5bryeoDb1bcfpG/guOSgwISzPfybgXmyN4uvIyebKL1Ixz5z4i0 IDTdgUQvumw168ZA0GzyYX+LqTcg3Rd9iskNCYcBB5gDk9jbpltrNQp7RNfMGqyKLhjL 7duHDbJCOurxWIKqfdmR+4M97DEod0QTm8kYMKDsxuBz0LFV5UJSE/ZcYvPLqmpH08dj Q1fV3efQmrtUMEcRT6Jr8XYry/9+WrPIG56O62DkznrHub7uI/SJPXU/fBKrKMQaPdT/ +w== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew72aqnq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:19:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGXYH013970; Fri, 25 Mar 2022 19:19:57 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2047.outbound.protection.outlook.com [104.47.56.47]) by aserp3030.oracle.com with ESMTP id 3ew5793v07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:19:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zyhbem4Vd3DAocrM3tMfSSWn3BL+4K29r87H4qR9lKP7aSTQnqAUyvrgeGkkfYVp+h0BlL0kRap3C5bUS5Y5+/LTA7rGYmML64l01JRfAzHNVK4ERa+sSRZ1aPsNuJPuCaqoaersAyMcJWQABVByTdNtfZmU4s8fdlchHgq+1qFdgDqOXkAEWDY390I2kumFRuchAmPU6K2RyO/prr7JCwpYZ8j9r4+rnobUZtRCaGvRg0jUL6zxY2nyrbd9pThcOd0htoqdYwZZg1kc1iptyiqwCGwg3mPz+cypdBnsgaElP9TN+4K0eq8A4eHC2IrLeL0SRCvQ6WgFL29zIxAbeg== 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=TTytcwBs3sC/ZBTlu4Wy3DNcmkSqW1CaZzbotzrSEgI=; b=S1YKyy3Xt/V8B+C9o4BLzZqjpzVcideulPVB0PA0QPv5WNlEwfEjgHU3Hg2B3Gz+Q/wye3hzhxFt+h3jp0T2DMLwo9tFQXvPCOkD+9qMR9ubQHtflGHz8Q1syivMeiHdZV2wYqT9iGkNuMz2TVliw+lGKti6w98Qjn94MeB3buRyz7DTEC8JpWe33Da/6eN3UksLSxsmBKw8jJLHTePE/RB60AHJGtNovnwXKPHKi4X84M4ZS5VekQh7QrYonHob5BDt+VXwKppQpcgHZVnoaiCBTvZNBuPdWkNipbpJWZPAmsoS9FD/UUjkvIe6XyFAW1Y5JQxROSd+9vXmpDuOyA== 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=TTytcwBs3sC/ZBTlu4Wy3DNcmkSqW1CaZzbotzrSEgI=; b=BMNN6YW2FMfJKF1wb7KXdvoO+9T0N5Jq9fzOqECVUS9qoZuZwgmAlIkPWnwKGBdSlCd9swqep8KDbcOgsMyaHnW7luWbvAfJLSYGDsyrLituCZmyfKme1qVdJ/4Qn7552h5xqLjHhZItIWT2QrvPDdSgbOOXLmaJ1bfLBqzTUjg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:19:54 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:19:54 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 01/17] tests/avocado: Specify target VM argument to helper routines Date: Fri, 25 Mar 2022 15:19:30 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 2002a54a-3859-4613-3789-08da0e94710b X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: RvABJIHhK37wWXrIMQJD4mscrABqdVEsSZvvISKIDYe1xAcYjljB2J2N/C3zZWHivuben4dhWHkFE17UDKAov8b3OjgmhvEpJOgbvMNRGl+dGsfXsWd9oc88ReYTKXC3mFs7GpZB5ieDywVBZqP11cdcJWvJMrD5b+qkaaCB7Q7s2H4siE+NmwAwfxZtHVvq/bABxjq+3skWQ4bA5264GSCvsemXmdj2r96KlTNBmQUYyVV28GhOtQk1BKI91qM6p/s4sNGzCTrQw7+d3dvqiiux9gluPg2QCQh3KdxY8H4rpECMjrnsrgjUJg8tAaYu1YXu0ryzHegIp/gjjKGykwmXduwZnTMd0OcZLC5hw8WQzqrLGApcGrj5MU1tEBQraHL3hcb6veZfu5idhJPcYRtOueNQO5n7u2bp8SaU7eC65sYF4ZvMKeapzsUdGmMnzvKRdH0c7RRzY1Var6AscVmh3zWWHza6yk4czyvN2jZa2VOXwE0aSiI9UaTVX2Wxc58vwll4suPUhUmL68ZdYerUM9HKetv4kXaq9fB8b5z336wEg5gh0kbpeZ0qCOhnt4cQPSB1RKojT/hjE9tE3ke9b1gdxXz9liPEDdE1W34yTyC8r6q31gWzQVVW2NWiKnlq+apP0h2oQfuNv7I+GoKXTf4EerPz6k9STQqiBrXnaNRCmZOu6NCnJ0PkwctYDS68EKeGi4bU1WtxeQvwSQ== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?FnOYWySL1AIMfSNLfM3+Inep85G9?= =?utf-8?q?t+jhhWU3IeNJj/m5ExcYfwAZ/dMtPHdQ4/4OgFoibfYII1j/Ym9DXDD6ovNU/6NtG?= =?utf-8?q?p3tQz0FHNISQzjSUQ9KePo8QGjPH8e4kE3kONQbQeQ6Z7JZ0wa2AxOFiKCx9RsxEK?= =?utf-8?q?46KHsssfDMyPECnPnbRbVyzZhnXxoN7VB+yAFOggNLwKiUaWazEygZ3aMU3GvYMKR?= =?utf-8?q?+q8a76kOBn4vD0fDQLoEwxv9Nbb4QR1MzFmd6lgfZ1ReqtHP2n8LXrdf+59nliyWd?= =?utf-8?q?Mwilbj9s9b75GsN3pdayNEPPjYCfozXsqSD/MQp3FLOXnT1TMRuRph77Eowm+yxi6?= =?utf-8?q?AfWMFncYo1p7BkKMUURvgyqtSFPa4wJ+7U1neGj8nEJ5eddxex4ONGObJbVaq4Gs0?= =?utf-8?q?dJUzVXEeCks9GXSYrXeXiavvbpB0aCyJGHENiY6gNNsqGRW2/JxTo60vvti3TJkO5?= =?utf-8?q?ZkMswNJHRpX4zkHPRlCaqcnQWF7JjF8GohMmz1n/I/KV+cSKOTh5nxYLT0RK+UpeR?= =?utf-8?q?Wk5WRyOfYrIWSmzUbHw3L09IbQaLBKFhsMpUfHh7oS1fxvTe76aHa0eKh6KFgUvm4?= =?utf-8?q?WvrL7Re98IMLVwJhS/0ltJ/LNWsZhWivobq4ubpnsFg8dOXYMWEuFHtE65VwlukAw?= =?utf-8?q?dPX/gJfWQcweKx73fn0cxEPwSZztHvSpyclSJ9w4FljfdxOtJHEpeGR8akTe+dF/f?= =?utf-8?q?YKP8J0Twk8qUNeLjAUTHFk0kNB+Y39JhsGvBiWGhFhPncSzpIEBJp+mYiRP5Z5lCH?= =?utf-8?q?HuJEacW/2gIIEQFLs2x3vx3hb9iKNY0hBMEDCXqKY5TQkcg5d6CRWg7GKmmGxVJH9?= =?utf-8?q?M2QWq1sHAsYJg+dIkp1COT0tCmJe8hLXq4Gmkrx8lp/IZfNtrUe7lXqzm/ADOfgdj?= =?utf-8?q?X148VtDXY9q06m14PMpF6esiReROcm1ShmbTOmAm5aocbf+BTbhTu/On2+l/56zGZ?= =?utf-8?q?+PHUQ9cvq0jwcdvf8QcypFeunhLJv1nQ3qmRWt4vzLzJyY1xYPEM4mH6wAW4dmKJC?= =?utf-8?q?H5s1orO1cQTRyQispHg99Zoos8yjTK47X9H1AFT+ErB+Wi4ogtUtsAJWlrRIOPX5K?= =?utf-8?q?GDz2XhPDAVJXMPeWkF3D5wRBU4RrC66XXGjZxWN1qr4VtO57wLZEuW/xahF6oLrOq?= =?utf-8?q?S5OO7UnJilFl91bUfl/HCcnY6KeQqrapDQFAx7Mx4JSi0yZ8TCOUfSgMfFBFCuVN+?= =?utf-8?q?L5PnqlmXQW+p041QPgaC6bc3Jl+o2qEwqYLp5FmDzZ80qdE/Hi3WfOgQkFDzqbvyb?= =?utf-8?q?qtp+ScPRpPXdFU5jtzFVkrEN8AxfZdVxgrLQkzcRqjkkOlKqdOjB7lYtdhUCVIZSP?= =?utf-8?q?1A/i7PHXgUfK9lbjzpYxSvwWBNdP1kCmVl5k+sABfSb+rNoyqnWndPo5mhhw3VTMR?= =?utf-8?q?mc5znH2lrxoDIngdjnTYjbYn72PdGk7+Oako4KuHZizpr88G9pI8wrdnMhLcc+9fe?= =?utf-8?q?bx4hDXfMHAEI5xCSFeRu05s+/n+mMNfxJcZOi/iQzSgZvTikWbyMr4nuwZ22fGSNd?= =?utf-8?q?w3k2+Yp4ROnYLRtybL/UpV6mT8RmYR3XnKqPPAq4WeDzPgKSn7qarCife4/D9H7WY?= =?utf-8?q?nzAcHmzp2FHvnPqtNbv9+FXkjWUtd80HUqHsuLlm1BuPO76StMCXMtXLzbmNjyfok?= =?utf-8?q?syL1mx7rPIr/5KkB68DttngvBxTg2cHQ=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2002a54a-3859-4613-3789-08da0e94710b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:19:54.2730 (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: Oo9F2Q63oiqUjH1t4kKmwgF/FUSTLul/XrpDWp04v7GNH0aT2dRk+m2XGFJOKL7DxDGyb6Z915DLbicExJ+CaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: _VOsBa3yrETLEEhkXjA50WcKvCKQPyu2 X-Proofpoint-ORIG-GUID: _VOsBa3yrETLEEhkXjA50WcKvCKQPyu2 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 ac85e36a4d..18a34a798c 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 Fri Mar 25 19:19:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791912 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 6813FC433F5 for ; Fri, 25 Mar 2022 19:22:56 +0000 (UTC) Received: from localhost ([::1]:54462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpWR-0003wn-In for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:22:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTp-0007O6-0m for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:13 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:60068) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTm-00034I-Dg for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:12 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJCrw031416; Fri, 25 Mar 2022 19:20:00 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=2TfzwsdKkoSLpAZcAHPlG4MbvqRV9ya/urKqgtpFuuw=; b=PzNlFLmerZ0+8uHJY8yNrwLztlnCH5fVPHEvEdAlgoxjghSyvhgTHGOpXaUi8bg0q2Nj BYb8L6gJ1Ks4Vgbz1TWqm01U4DOKc6ojLJx8b3kLGKDYJadmSLr20yiZhGpuP2k0gT/w bTOq52tdkeuzWmsPBdemPXVpoOjeLPjvE9FbwqawNeMeLXoLDo6NEKDrnH+qcCGNIy3q YCbe1xzOBO/IX3keeqeUT9A8OWXgjP+k1xkOCBaTskYt5+ioBIV9096RrI65w+6X1Oej tRh8FaL4WvCAn5WfCNIckK3ZRqci4v0AsoV4pnaWeq49xCLBkaWHz0sR6IfRhJuOdkwL /Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb1k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:19:59 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGqlG077284; Fri, 25 Mar 2022 19:19:58 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2041.outbound.protection.outlook.com [104.47.56.41]) by aserp3020.oracle.com with ESMTP id 3ew701w9u8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:19:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TYIQP1ANjnsxA1pW/Gn2A+GkbiS4HZr8vmJHXE7/XmLWPQMvwM1tXanV0Mo3ORHT4oKaaeZCejW7NYCqQmU6taBpKWph27PO6fwIfhEY6pFfaMn5yn6w6psiy9Qyhsej7o0mr7LvCtVfbke9YamBLwR+ttHcp+nF4zy1z+UrELwvGMANyX9bVTrhFKWFXoRvwxNB82WliSTz5abcO0nC45II1MXjW3/jpOeRmRKp78JtnBBM+lfaEjoGhxMe0XayKjLWcda6Nal5wG7Q8Qcr1oie2Bu+XQ1hx037bGSVISe6C0NiATfwwm8zYCvMY9NvrUEBujqvuTWR57orBDNShA== 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=2TfzwsdKkoSLpAZcAHPlG4MbvqRV9ya/urKqgtpFuuw=; b=LhwfDxcUS2o7tad8Wk4Bplpi0aDs83rQVP4lvyl5VEuS3J88LdlHpmq0sIuJQb52XYY1qqUpqDsojQSEs+Zus8YLQcBQKYR9eDZ4Y015wSMUGKLLgpRwNW4x/igUIpQMlD28q2CeIUIU6YiMM7+sss51KdQsCQSWKmEf/pOkNv7vz14e9mPtWbhKH/gqWjmbJ0zydvHDdagnAnJOW7elqwYr8kU3Yz8J9DAnO8g6FV5mYMhqWJGIthHIg9xvUn2cqhQAcxIpXUsQgdcjJOJcjf1IIbG8S7RvgsnZKrpmw4FwEQZFasAyN0gNL69QJIPbCmoWrDpuy1iMFs7B9olaIQ== 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=2TfzwsdKkoSLpAZcAHPlG4MbvqRV9ya/urKqgtpFuuw=; b=p16k+Mw/yXYsrM+itvf3aCQ/PaP0noJSzCUdWk6R4y89d/2YMle5xNEj5nZ1JHUzErICNDTE8ho3dNPHstZpoMtkSmsuHJ6ufHzfB67L5WA0iOTj/p3x/dbpQ0b/289Hgltv2UShHrcQXLjH97PBCBwVpCGXE8EdDosjtiI7pWc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:19:57 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:19:57 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 02/17] qdev: unplug blocker for devices Date: Fri, 25 Mar 2022 15:19:31 -0400 Message-Id: <5526cf86f18a08f8228e602cf12eaae6f39e74aa.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 05238a38-5a44-41fb-7ddb-08da0e9472bf X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: Wi89nzedDgJ5Htem3cTZYkVR8cGJlqgnLBZiY7yrjMfjRIIIbr/6BeOL2+LSi6wynKgLKr1gj86MAr3Bmd12phOmzy7CigOwKvqXJvAaBkn/mOP2adxaXM9zg892mtnnXSYEoFHgl37HHjwsGP2cyY7tgLoV75KfzJUJmqlr+0NWZcnLvtY8U0ZHiGhfvDTLaEMSlYmrzKSDS/dlakJsQiCcnW55ObNnlkOVkoDpTVzCf0lJNCCSYSpyewn7DsxXS6L2xbP3T/7VIgqzDfEShMqYKcCfT9fB9xmMvh41rVp5huYvDmYqHFrFdrcuRm1fQPmnfdrEurIBXOGVp1dJfx9KgCp6Ys2n4pScoHtOFJILlIVv9g528mM03+WZus7mfMkA5e/hllY+oVp0SEIZMafSzLZT9FHoYKay4ly+E9HsJjb0JWr3b3RDCstty2rqMY6qbh+ptMuvsJIetm55kiZqH9KcNbD4T2M5srU1boN8LKR/5ekfqT1sijoKjPiQQjYzwFnGZNSugfdoWEJ6JGs6/ZGwPfUxBnubT3ga6dQJGaq4tWx1nvWelh0bISQA7u8W/+Z3+r1mylomJmm1Dvc9/owuT3AE0+648sbPKJRx3pRMDsAJymLEuYTrGSerLj5ZLM6YzfOwAjFCzBmVy2j6JS/NNHBCL6CNb3cpywR6BKKrPXg0IrOLDgnXpO1FnIRGBhtWEJoUiaP+CeQvWA== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hgz7FC6O15azzG7xY8fu1qasIpUt7YysBj2UlvVNjTc0V2x+ee7WtAnzItGRV9b6oa02YlsQs9CdQQ+GaMi6DX2aZdtiJbRBBQx/bqKlN5AGtDzbMfqofMGDfXnSV4Gsg8qb2GFYa/KYHkPPFX3KqDi2sXlHQ6aRRJqJiCTMP0hoy0PcEaCVQt1UgpcA/9B/ZAPTJiqijUsi+92FaLkzMQz1R27GPfLTEGTMIjxZaAiLeTdnQtBdN0cVpO9DaJGZyG5U37podOJQ4nzU9+sPeWYnAGAjGb5BhM0vPsmAnp/vroGQUwmNc1VNB7Bz+HIefYPv83q5QcarLZOlr0BvG4GTCdjSONH0ltgwZ8PyeOTqaeRjvnPK1+YF16UySG70AFCOXCqKr3sbkkH2OZlSfAA0bRmf6E11rzJ8/5qj7zIeVXU0Fdi3g+ltiAQQa8b1thrGIcDE7PQLfr3kVe7STUZkqlXC+E4eHkgeS7XksNvbZfmuX4fGzffDjQavh+161tKl+brtNnaOX0XriGEKtRIyI0yjvTHKkEvIDLyZjJ/G4OJ6cRWyyDXEOq/yWeBMl/FPlegQ/gJ71tBG8aQVuTzpZ4pRDIx3GcG9csB3MDvPMHxjUlHN+/VIWxYFJlr4d1JNPpc3oaeHCG7t27p3EYTQXeEOSd5nGJUlRoXAJaTyC/XA6e3djosi38Iphhe52UmFVAdy8LerP9ZWvH5Fm/fm8ZkbXo/uF6QWErIRMlLpMfvUIGHk4ODsFkrEx7iUl0d8CPFbaAn5ETTpU5BuWJjJnw7guI2uUa/PSEZfvmUkTEsm6BX/Y4QmoiJPzgCJEXe5+Fd2qNTusx1T26wemASr8TVwCNj1Ja1LYglUbbZ9+RegnRyFXGNrN26g09lGlZEZnEBPHrjdZERfwoarly09k48lMoi18Y0EITcyw702WrxGeIn6uDRb3GIrJ9zHKnivD5dGnIpeZvw/smMppuHw9qeXKHaYrRaSU8Yn4uCMPhqCpy3qfcSnnntstm8+VkB52LjmMUejMjTvxF7spCgs8thY5pRoFuSxC1llap7iXpHckX4J+oURoa65/Oq83SI4AHA8+SU1Imx9UJS+pwXU0d/nScaQa7ZxAfxGfZs+phw2rosRKya09cqi66Dw9tZiNvdUShlbplPFiikclhFBXXoEJpFiAvNaeZOs2MSB+BTa2NITODnOq0O1ec6/jprbQIHvJKz8NStzWixj5TtvQLn/ra/dks6bK6l2+X4RzJgYal+EJ/fdH04Z7ym3KgtzdFR7xN5QkNDo6XNQtcIA/9qyoIuqBdZht8wFGN9Yh/5DBg1ymp8WSslB4hldc8IOraP1oTSjUdL3C5EhO1mHI/er1hg62smkAjjHxNexgGw0b1LN6usR3+qsCbBGwnqj6t2tz8gXK3j0+yuPzFYcksYTVx7bNhZBRXbeoeeDvgDhk6+KHzhGlwBehTY5MecsKQwFi4cME0GEihHNVDKR8Dw24TEg+1sGmA2v/Z4QALalVtAOe8dKeItcq6Acfs6TZXOcWqUs3Yj4b/v8kpYDidUQNtz8tOzej7yrRv8upyk43UKH6zzycCtH+F8IK515ANXITfFxJ5agYl1RIN/GnPjhqf+AtoFcZLZSoxQ5A9fnS/CGgFJ3SGVoF6ncHAwXchAHBHwC0bqYsrgIUCjSIL+H/Zie7CRnuCWc84UPU4+A0fdufEkqrbqz5Zx/h30VXkxbZC+VMU3JqZPwWw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05238a38-5a44-41fb-7ddb-08da0e9472bf X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:19:57.1634 (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: sC6H4yFgLyqao7lBAjByCESam7liriHzsb9A9XyC2TexpSSPUguVADHcy3t+FndOKVBe6iDTQmPLq+rZa9uZ7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: vOtJEg7ZfnWBcxdW_Y57zmOkEXHPGBTs X-Proofpoint-ORIG-GUID: vOtJEg7ZfnWBcxdW_Y57zmOkEXHPGBTs 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add blocker to prevent hot-unplug of devices 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 Fri Mar 25 19:19:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791917 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 950B6C4332F for ; Fri, 25 Mar 2022 19:25:56 +0000 (UTC) Received: from localhost ([::1]:38160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpZL-0003Ta-LK for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:25:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTo-0007Np-Qb for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:12 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:58818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTl-00034A-GQ for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:12 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHS8fM031405; Fri, 25 Mar 2022 19:20:05 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=/9fgYmY3VqzOkuFKOBD8Jyf5x96OyKAr6GSdY7sOTgc=; b=cnVR++esnD6SEhF8lGA69eH8Ecqo+VdMP0oqE5bhSKNUxTmVWGNdLm0C52cNoHw8aNzI yyHc7Wh1OH8tguPo+wtwVxs6IEe7qN3Ieuu2oXahGPMkrMYfSc3Agh6+3BgTa8ELSPcf ozLpn+aJBHKVdnpCIMqqCuef72DEoI7jG3alZkSb25gvR4Lb63Adf/AkZJS7QylIrhSv mUo1Fb/3+aLuLaqphPHKC6bZDbNmPqCkxD23yM2ArwjzaLPTFqXr6VWWec7btp/umfDv m2XAKPgrXylopZLYhywiAWDZYHKR6agxoRzfOkczlf6S//+wp6uGcpxg3u3SWQuodckF tg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb1w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJHAxm125507; Fri, 25 Mar 2022 19:20:01 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2040.outbound.protection.outlook.com [104.47.56.40]) by userp3020.oracle.com with ESMTP id 3exawjj7xw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VAyQu7qf2RBQFnQBOEdntttGSNTLlbZrouAD0hwV4VgsB+3GT3zp3++k3lepH7iOduwdRV3JfSCnFyPqf+xn8C3s6oRJNm5ney0iNZkaKGlzZ5roXwPrcwnlNviWmqQpmXRDMPVJZdYrY7Bcs3Iuz7v5DDfQVA2ca9RlgwPkTTWCBbYGlUEtzW8syz/cQaipwy74SOxBHs7Ai9tZfelU83hfPGN5j7BvqjEfbCxCv65uIG/9txWmduQnk6n9yvCXiDAbiA+hylpGAlqeS2fZ8vqq/jLS+26ShZT5qmHD2e7uN/3Hkp17/zvEkeDkfoI1aDfvGVzrWene194ytEjoZg== 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=/9fgYmY3VqzOkuFKOBD8Jyf5x96OyKAr6GSdY7sOTgc=; b=HQ7MbLbJY+dcjYleReIULgO2XFoEPOR5BBqA6o3TNk7wQOiv2Slj+BchkyGijGbiMxwwNAhzaivPCYkaQNIIe+krDBo/ywQjsNhiuIp6Xiz4/BFtuoOgoGq67JX/GsRXG6FUzv8Q2icdGO8iAdZeJ6tVa0OjR0sc+sRK4x36/9XF2nLN427Xxr+vjY87ovqvr+gHfALIkfDmqZOSeg3Q7Ir0eQNdhrS6zK4yyj7HVEaNYFvYBfkwH2R8g5e8VbahUXSVI6tKuIm2sUE7xKzo2moCs+3YhbB33PxGu89TwsVEc14Uxj9yFHSpmfExLSfH0QrjNVUoUdRhLbgugZy7og== 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=/9fgYmY3VqzOkuFKOBD8Jyf5x96OyKAr6GSdY7sOTgc=; b=TsR/xvvBmw1h7SGAuvmfL4J2vNguBojNZCSuanBR3hLFlq42bLikI6VHyq00GRpLSpv6DA/kl8JsqFUc18bG5I2wAaPmV1tqFoG/hlxugrBCXebexCTHm9ypjCT9ToC1JQQajRdsa7CSqlmb4wk4ZpYfgDjxPlBegG/r4TWhflo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:19:59 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:19:59 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 03/17] remote/machine: add HotplugHandler for remote machine Date: Fri, 25 Mar 2022 15:19:32 -0400 Message-Id: <27e78b738ed37c235cbfc8bd52eae134e171b94c.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: a157e2c1-5dd6-4cf9-a34b-08da0e94740f X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: BrsXVPR+9SmdjnSPZuMmh959M4JPt6lWVoR3X/pIa6gu+KFTqATTDa9xIrEV3TKAmg/KJlTPI0JSh03sccv+DwPymKyuMjkGDrnTUFlbHedfGYJhfRK/qi2kwz3l7QlOrfwCwa+fODF/4cYa76+7inFLfP0Onsp44bLykJZ0i5VcXm2GPzKMjwaHguoAMd4GgvpPQW/CIuospx0Qd6jqRRnYbZzabu+a1lLLp03JX9PDzmTorUumEcinzyWeqXFxoxyHFMMEaCbTPwx8yfEoMpBKYQonlyFk7p1p688sEv8WwBvFG1UzP+JIQtdxppJRkfMc/VSe+BbFjoTK3Ae2rdWIt6NI1VuSf5S6D43iR/LVzoYwV+IDB9erADSyDG1csUQbBlZodJOulTiLFJ4D/trtjdkV56fWYdLJqofIuKhm1dpa2b+ySRPPlB4H0dSUC3kvR6r1Pz4cvp9a///CyRceUmJydLbheUPRJUjTJfZarWRSKZJAKq+ATkKdAyz6UIJmK9UfaEF7qeTEUuyY8HrOR7LvmqsvEo7W6f5dJjgXUDeJTqibgr5hA3W1h5LkYM9LupX5aCIMgugQFwRBDCdQGKjH762k/L6zeGekM04nX33WHEAA+SN4omhcF8g3tRdIyPTK7Bf4WCww9dG+H46YK+EBaNIK8kLzotStfCrQ/B+MnRrdPc/i3adVX80tNIl5pMQ+WQ8rsdwQlmnAZQ== 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)(186003)(107886003)(316002)(2616005)(26005)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cs55d34QEWu65evm01cSqLqNHlJBrxIvweea5TpPZ+LRQK+VLMHNJPxiDgiR16GLLOxuIJCDqpcPEVPlMawP+K6ufVYn/ftfqabRLXG4wbKrleqcfngZLkfe0ugTLqjtBFgOSoGqQeGgngO4YBfH3VcjyYRKzmWtTskPkqQZMQEacOLLIchKxwHR/i1fOmgl974YWE/e05brmKXmt7GrKYLbxa8fB1elBxsils2T5BPmk7Hvggwih8hvCz0kCQ9qAZpPb3e68OEcnHxh8VLcn9XK9/ZhzUNMvoaBcCDqFbP5l69KJv92+Mfnls0Igp885V9F6UGGpiUFL9fL9gsfaLwunt/xXvNvCgJycziY/jF3PsxIK7wUZB9OWMX8AeGeU1duiftsGJazDrVF1dCRfT8riGrfOsV6YATZW5A8sl9Pib9nPD/jPrXZ2yjNvcvNBSEeSh+JLKmz7JkxIt8G9yft0l4UzWCgzDTKfpyzN05C1xySGrf5/rOgrnVN2but7/Y1bD3mScM5jxhXy8YOYaHUGu3acwI0hGvVW5/TB/ngypSFrbj1YLejqwQ8SGfl5bsLl3LnRtkJzB8kb5YNOl99Yky7gjd/Dsj7wTQFJjgIBhQgfPIqBd3gCig1DBBySMdYocqGJDg0qfpaJ6yWxl4PqwoxxXxb94wMulJZCDk2Pw2AP9oq+YXPxnOQU1vwM3uH9a6kOafWwYRiCTdum79dkhyednBEmPyh3GR5OOG81LtJCsmbOUH8660yGKPMR1pfEkOnR6rOUEmcPtZVU3xXIoYMm8FIsJBNvnOhREYE6V2DWQhpJfv1GDYFYDMB0aETE/DbsabEwzcKK1C526dve325xY0701b+UfTOybadAb/WQ2iZOQT5kpHWgH3WySvvJKJE8EWAniWBFr4Uk63jvRErUMKSAo19a0dezPib6XwRZ+5Sm+/WtKMT2mrOQZNE7uwnuL0ZpvGJouoe1vX1tWlsQdnC53bFu6xRg0WuqKUV9as3vQ/SfHwRMNt4WnmuWClPbgLrIGItVb1O4LBrJc3xU/5fQsZDLr9/F0KcaaCBYwXnkYQO0/tRN2il4STw7Ki215T9Q6GzAenhXcBKTPptYYGLTczHSqsf+8kzCpgRRXDzMUh0KTJnupsmIvavzDx7Zhg3NncKgb+2b/vT+y5gTd6Erb2RyM39rZ1UinwEChCdnlb0vwK4u8K6L+Aa/w/V4YJL+SGgmdqPKCPd5lnxAiDNeatkkYAFnh6Sx/kL6zSc9ui9LeXc3B5UhTubH4fKIitmUeX6SuZLXn3XntQz25Eb8i1WDZfJLeoAVKIkOBiV9LEy6ffrUoUihBOMEkqbR0by3eDtEPD3pKaZBBNo+/IsGSt20Mos87wt9NvCq0EkJJZxdWbwS3MP7PxJxVL7ilS7tWc4gcmheMungQ0XT9LARQiBnNy/rUbu4LzBS+glF65owjnN8ZVLNxrojfeaiPc6xlNigrfYYLIX/cKQAXCY2OqH8M9tin6pUny96CpLUNi36bspd9Uh5V3xGXdD8L71wajuPtDd3IDxJUmNAdNkPhZqckfXiK3vfn/7xAXVIokeVeAppAszwI6yM6hMhH5Y2BwlRLL1l0TnAA6hL3xnPDUUYa3d0svrwnXY+WFavWt9s0832JEq73ApTwY2O6YFJfZWG+fY0kwyPqE/+pA4P8x3hcHjds1Cy5o1L9s+ZjepP+VX++5Rsljg08DsD96NAXJ2/8UBCg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a157e2c1-5dd6-4cf9-a34b-08da0e94740f X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:19:59.3508 (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: cvJMkQFhoF5qw3bmvyE8b0VZQgy8IRnGFtGmH/j83JdBew7DRbU9ZaMBMlnIxPEyG7J6pJQ3Ha5VicQpnv2ChQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: 4pUNu_OSj0J3vLd1zYSvbAjXczJ4Y_4h X-Proofpoint-ORIG-GUID: 4pUNu_OSj0J3vLd1zYSvbAjXczJ4Y_4h 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 952105eab5..0c5bd4f923 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -21,6 +21,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) { @@ -54,14 +55,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 = { @@ -69,6 +75,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 Fri Mar 25 19:19:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791913 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 51137C433EF for ; Fri, 25 Mar 2022 19:23:53 +0000 (UTC) Received: from localhost ([::1]:57784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpXM-0006A8-DP for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:23:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTn-0007MQ-Gz for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:11 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:58812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTl-000349-GW for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:11 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJa1G031491; Fri, 25 Mar 2022 19:20:05 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=knAUhec0MZfs+BQEeOok0aa3RG+yTNRzFlP3XMvR1zE=; b=s1ETEdCV7yMlxrXQHMlqEEnEy1V0S3jYYTKDVB1CZLcgVUbRAi6oKISh6x8bwNmjTgKA N3synRlkqH72OHFjXTtBO0GvXyj7lRqtMrzzOwlfs18nNglH8juDCVnHFj1lr2CTzDMO CEUNGEchtyXXyzir90wwXI2NTwDlYGmsPeb/5BB2SqtcfcxbIXUWL22n9Sj/AIrRYDTg HVMjHTpJY2QMwc/t2ZWZ4F1RaR0BPBCiGCN4NrPH/jP6dpgFrh/jQpsCWz9ocDgN/8I/ uid3i0rljgKAXqD4XkruwKH/NKKWAImZBf7dNd83P6FAecE2zYvSlck9ZzCz70JgOEyn lw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJHNPG125579; Fri, 25 Mar 2022 19:20:03 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2046.outbound.protection.outlook.com [104.47.56.46]) by userp3020.oracle.com with ESMTP id 3exawjj7xy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MqrGcfzCEF4lj+EZkHi5HJl4YzZhF0zjxPJCeIAUrLQ8ftaWPv2Avn2IW1jh6TI/R9vxY6bKKPPLmWUcujDwwq/DQhyUn682IedWJhwtBW3abbSKWhZ514zv508y2mQinL/UF8PLRXJ5Wn96qA0w8c1QJF3P+3apNOi+9AE0sjB8H7pvR4nBTiZH4xmhV9WmrtPDRUMffxuagLnsyxAwFuWTbLCKPfDCpN0iS1uNEb+xKxvXOoyRiBJ8JGeM2jMzTlHeFJ/9ApHmMxfqv/yX1TMb+3tloaO5XXUvftlbxsEMzUGMSZjadSjK4rB7ZKoj+0RcgK9oI8rlWYmBU4Nwqw== 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=knAUhec0MZfs+BQEeOok0aa3RG+yTNRzFlP3XMvR1zE=; b=UvCEQbchQa9Bt3RNAcj6tw28a94inqrFPn9DguV9bJ64OEzhJ6PofrB16R6Vz2fpdgPQKOglHVtrEU2uO5seRgksfE9ZVM1aRjCVSHRWcdDSoSeiCtoTdv3a5+gwBBh2g7PcRsYm6T0MAXfNZ9wjd3ZfEhGQ9nBcv1VUxtwU3j9TM7mKVOd0DKVM3l19TUHIG29xqrQXfpiNjpXQZEM2UfpYvLcwUvZMHGmXyRG1a6xP5sCwV8vhgU1WWIBEG2wxmLnXimFhSObkcCY5ahV+ad5Epqvc0WQ1HRDvt2LySAOaW+1A54LWUwgOfKuztJdg8H1lzi7A18zKvPW3cGcQ9Q== 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=knAUhec0MZfs+BQEeOok0aa3RG+yTNRzFlP3XMvR1zE=; b=ATTTDPmx7fDbon2wkiv2422EaudIl+FVnlLQ2UQxSO1UBMsTvrX/oBfSWHzlHdPR2GdSAljS0PbeAoLdTFbPQlRh8bG4OCAsgVpq3CG1bf4G/DLr9n7TDankMvUtFxZK8rnco8DIKrp2Wy3V2GRe5Jzszmi0l7h8olvaG63LhuE= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:01 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:01 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 04/17] remote/machine: add vfio-user property Date: Fri, 25 Mar 2022 15:19:33 -0400 Message-Id: <086b693fe9c44cfbe06a1c4eedf08f17ae72762d.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 99ac563a-09ab-4342-0204-08da0e94757a X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: 3ecXD3WZHvlVyV1UowqGsy6GHdvMltBQV9izwD51bKANL1O9+xpczqHPtiFpjHsWWPjKjXENNz53rKgc69qg8MGA/zRfmHbEBtQqKPmA1GAlspVUfDwpAdgJw6Rw/nB3whsIBbo1i3hwMPrVoaRYTCxgsH7St56FzKc0+J4px4471z2B4fsawzy+sc989MjMx99rskTn0Q8C9UiONCHLhV1iA15Y8VDMvRdR6H7lw3zKmXVz5tE+GGgkihibs9XNJZxavDSjEVHY7KV9oORjZ0+KzK/sGCYTRrrMg0pPtdSKvHThdm7QbVj71lJXLHsHV4EzQh6Do9zvAdxapIZJ/1x+2MSHlIFVtRwf8iBG1XhxNwOMP2iKUOag7woAFl896EWWG67p3bQmmBa4ooA4uMlBP++Y7D78hlCPJDodRsM082Ct3O4qsRPvw362/sKkA8Y1GWYL6uQf/Cyei7uRpFOFN1FwUK/sUSLpaeV/fMhsj5gqcz1d7Wemc9SpcpKgqlNWVZGI2D99FfVznsEXwsfSS0hd0833Rp8RE7fHORa/y8qQwkm8yRU7gLKwIeW5bCoKT7rebWgsNdhILocMH+SG2/+MUyczktp80/UOsFT+fknZSF3Eo6ZZ0H+SeB+eAC9hI5icUwJkwjYMnJsLvzW4dUUy6QsbUr3BOpGp6FkPNK876fnhHOz8+e74ahkNcxr9ALSSCgx55X8h1pl5kw== 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)(186003)(107886003)(316002)(2616005)(26005)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Nh7saTJQbgDnZAVQ+pQzAWG137EJo4hfH8/2T0zdJLnKjMZSC9oxRmBA6KnP/o3ZN6MjYuq30GYhnXSRh+S/S9O5kqNBx5co1zVo+XcybdbE6NwGXIhEBO4kXPF6v2VZIkMtqg/HHyX8VrjKBjIB9HWcKpnOHXxI3mCOMMO2gu8eZPWkSR/DvPUDmhDeunF67f0AHzgXCT38lFCtPjSNQ8DIdfQ/HZ1pibX2fEDysalxl2m1oayVLZWfzmqVM9fzAol/W7AS6wDXTczVkimM8SO/y/i22Oi2EV2ulkxUX+umUUVeAbEvlSz/J4bzC2TXQIjJuJmUu01tQhG2jY+rDPSrmenKTn6BeokRVsptpp4MINqYkNOtjb1jxwweJ+9LYGXt8rWEmurrOsnhC1b1OpLj8luIgPItxTCknq3vC1e1BxYOAW0qzb96zJULzz9aZJXqhE2Z2u3M8cjPODYVrtWyUOplkDFF/kZicPRCz9ErYXIeC5xUNnhamB9xdW75KwuB6irwHT0WfOqyHI6NXBDhtDF1UlBoL0dBdJAbkXJF/NE/XC2V8J3D0nL0BrsmDLxiVnpM1BN4zoYCr8mg6viHy2HkMuSN1T0iH1JW9Injo8zYA39OnMVx4T7s8knbzcRB2qIstukiJPDh/M+RkW40BF2KECN6+CDUz43J6p0hF0tdq0GFXkNhwPtR+t6rauHxhqwZ8nmtafn7IexZ0hd2LHpdE/Xxx2GRiOcqDWM95F6+JfJlsZ3NSJwR3xXinzBBF0WIN1FG2miZaUcGzhMeQlqsfR/Ph/Pn/psBHtc53N2t+ejUAMMLod3SPXTb/q8EoL+xbeHaSXYYx4XV/22D03vtFMusFVnuoI/hFKwxCzTzR4MOQkWB3KK2z1uGeEBsl96K4f2HiRMqd+LMKLh59mffOqCxfCFai/rMotuAG/9Fl4Ih7pkHaOXVbqgikL2rHWXmgN6nKZ/DdHOa5fiicfahvqYUdhJlBVHbIwGisi4mmPVQfSicim3ZrJ/kTrWIcMYWJG2zcijv05bYjPz5z55ibvR2+sVmTdEyHG7moiNy+qky4npls431+jPbTgVJgEuzU82BBHvLfHbz/qM+9Kjpl3PnUPudUsI1vGpKgamuHSQS49a8mZMhPhVXsjISRa0kec0/5dEt5aMo3DrZCIiGFpJ2QUlmHLYnpQ92zMyrcF8vwBUSomP/W4UTGh7HJtBzuRBHynCGNNAbbb2MPfDd7vjfOSZFmqUOq8mFPSquGt33vb82ADY4wuVY27Z+CHiJgjz1MDBPfHyDF6V/2oIrnnjn7sdqt4fRRA5FS/JgfYk9bJLmNnS2Isya2iHhqwFp0FqAZzRHSyBfkIPgXgTMnXaaEA1+YEMzGZufyUiyA4XezCz0u7R1fbxsSJuyOtyqogNttORV1/nrbT4amqmGqfjc4PwrWVStux8Ga55kyIA0ZN6tQyK03qCskluY+2cb1x6GdOpZAAU2jqVunYn2OFk85Oqe+IBpV03Se9GlHAxht8UHL0BSkNjBnDEz2v0LNm/RMxCQwh6K4yk2E/82mQSat4qsR4x9EnFDOo2NXJh6AGmjNXu1eUvun3oRp4oiL/rLMJvxaZEblDcval5vYBfYiiamwzOicLvVejob9yXhIoPRvEWl+piGLJd6ap/iUs/uvFY552Sww/xu+vO+5zryywXV8+MFPJKWLumi3Gn7LqkPamCaDT4kQkrbopN+BEnt42mPlCTYNA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99ac563a-09ab-4342-0204-08da0e94757a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:01.7100 (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: 8uecNIx289L1UtcW72oHLvS6sBnmb99n0idekbtCwCInIISVZ9ok6Wt/lduR9156xUSk4YcIjp4YrUnbUC1yDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: 2bs8e6H0tO8JkNmfjBSKRfHgnvNmXlZp X-Proofpoint-ORIG-GUID: 2bs8e6H0tO8JkNmfjBSKRfHgnvNmXlZp 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 0c5bd4f923..a9a75e170f 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -59,6 +59,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); @@ -68,6 +87,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 Fri Mar 25 19:19:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791916 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 45E5EC433F5 for ; Fri, 25 Mar 2022 19:24:50 +0000 (UTC) Received: from localhost ([::1]:34778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpYH-0001DC-30 for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:24:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTp-0007P2-Ja for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:13 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:63548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTn-00034e-IY for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:13 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHWvXE031098; Fri, 25 Mar 2022 19:20:07 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=/EVNMPpr6k/hMW2jc8BXhPzp5xFjCzcnb8zDOMEGWlQ=; b=Z92lWFG8ZomQkrq/Q56jJzZytbWN2tvFjLcdoleJJLJ3s1ug1ggAXOmQBO8RUDl24oIc YGWTzfjvw15G3wDmtCoaB7NiMZLSuPuoK8Qglwf7BthiohR9si+lpmutX17bZd5zq57j FxQ3VxyhRbFV6nfu6TUE8kvVHbwoxVI+oxcdLILRR3j2sPu8cUdew5Wir/wW4QqchQ8r OnpzdDASHUbAruX6/cpLnU2Sst9LvAO1hzisKKBnYkuevBBZIxir2GaT86K6JUvQOvBX qIOjLmZmIu6yLXjhRzAvY5kB0wSDVCQMU8J5+eSP6YSDEaiDFk9HqNMG0MZl+5Ki8Xpk NQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew5s10503-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:07 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJHJ3p125557; Fri, 25 Mar 2022 19:20:05 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2048.outbound.protection.outlook.com [104.47.56.48]) by userp3020.oracle.com with ESMTP id 3exawjj7y3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kJ8RlyJzSVASU/K2BSAcBHTVClmk0GUjo1AZjzX95po8nqvczV4+mngW/t5B4dBYsR3O//fG9/sa21BB465Ktgnotnx9YmDY44TDBK3BwMxxnOGX8rFpq2CAetr0iB7X3Hm0IPrywU+ltVHo3rB+Hn6qc2mS3wfamwuZxWusB2w967UHWhngBJLy9b21/AcPnI7u+XBHLlwJY1BbY5nwMUz8ap92JQmGdzr82lmAG3YYYqHDwHDALDwygpAJrQbn8dM2LmeGrQJRgOVd3l6ynQAaY8jInoQZ1dhBKnWaGxMIHfep+yqW0IX4kx9R9jGRWZaTLtW36tUZ6BDEs10+Cg== 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=/EVNMPpr6k/hMW2jc8BXhPzp5xFjCzcnb8zDOMEGWlQ=; b=jYEQJ2annrLl2ULbsUAi9P/YkC9xue+ifsqaDYpebQkjCo4g9dJa07HNMaGFVAZsfuu+kQFWLAAg7UhZZOZ8ezSyIWhJMgRH6+AmcXD4jNhuJTCptgizrKxa62RRC5PEbcK3As5OtT3ORe5lgI4qUNqcwI3UH77fcQ9zjN2qG7t9E6/pjsMe37Bdljebv9VR4SwGMZGNqXXZhXUYcgJIq//ti6LmYQMUkRRWTKAUYLHjaPGazCmVUSvtOVbsPf6BKiybVwJsXK6s/TsCyVWAH6BH9FvhVK/oXdkezoCosAGmbU0LlblhLVuC+9wpqSKLxMyR2EhSs/9b1z817Z/Ogw== 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=/EVNMPpr6k/hMW2jc8BXhPzp5xFjCzcnb8zDOMEGWlQ=; b=OSn72t810IYaOznNOq879tEbGf0reb0im5ki1Ibrt+X6MWK/XHqS7DzLB6rQ96W7EFwNOdI7tvX5F2ON5udCdgHw7y/o6g1nMOlCWzZL383sWYuHj3dK7TVEdOOvE+Krt8grkMhBMjI8VdmKY7/uTZxf9agk5xhXF1kKa8za5Ls= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:04 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:04 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 05/17] configure: require cmake 3.19 or newer Date: Fri, 25 Mar 2022 15:19:34 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: f75d122f-73cb-4a69-755d-08da0e9476d8 X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: 87s3JMIIdB+mHMf/e0JuRNGAnJub+5Qy8yR7X2m9moOPBLA6VQHRf5uyi0yQjU3nHpP8UmNc2cPBopJXLC1iFlVvlePf1QeTeCd7Oiv8goADzK3xz6FXvUXsfkhLUmqiGJ/rK2I+fmkiBB6vwqJdk6HJKlpEE8ktBrFURf0MnUsc5jXQT6GipcVuKKKBIzJkHVmGjc189SJGG7QI5hDw/43XlrvOAjo9RNlu1pw2Esjdfz9eqaYVmhd7BTN0L0ReJ2v/uK+m06TWW7diU3LPNacYG86bPWkUDG8Nq6OtgrBtzmK255Nmwa+Bs5bslf8+CB5QqotbsljNsVvbjcgFBKD+N/DAUY51jPWeuM6aJ4WYTwO5qOzQJh8z47voH23R0WCdVy0mr2lz1RaDn+4bKoinPOHY50dWObnnOaKBmJuoN3n4ifyNU7LKBwjwHwlPJOD/nCEMDLihOwCJhIb6uvY8C4RZ9JK5cL6MZa/XV58ohCsX9Hw5PxLn5Pjmg9kut65D9LX36r9B6dvvYDAfyoky+NmrMwma0wTKTR4NpVHP+X0xMYKvYOqVDjqO2PIL4+GfKbNmPxC18zMQ4RkJC9e7yGg+OSbteT9ebZv1qD1up/Zx+yvdissywGWIfQxgLhm1ztkKohLEmQc6Rpy1kiC/3mQfK3RImIbVZY9PQTJGuQ9ibBBEKy5nZ9YXKg347r3+n2/7RVIZPmvc4r+9Fg== 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)(186003)(107886003)(316002)(2616005)(26005)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o9wUP6s63Ryk2p5iFFqvIqdHPpk6p7gS7oPxUiLIWnqyp0po+TEMElPAE0GmiI0Dl/zM+wasY5ephyo35+8Pxk6GVr+co58mAJbRVPbBFFt5PG1RijeZCd3Iyck82OyXmd4l96egvKF26slGufXLFsQd7Iks+3dwt44iBwIBJrdIFcHTzALY4TdcVUgDz/Z7fG8ssHYUCQgCVVBcsX5VweqWJYYI9OyPQlYi64SxwvdO4NqmN0pZLfnxhX5qyW7Vg4kI715Pn70UHCeFetKVR+Y7VVIkD8FhIuCd1E5aypk0fKEAgOH3q4OAqI0ym9s8lKS/g3ta0GqjWOOOARYEr3i+TCM7aDCpgnVk6pdRGKvYPLjHNlf7m9054ym5omQrwQAiuHSZ7qx1Deh1Slx0oBklEydzcplSSDYKcyhKxNWJPQWlN5QjkmxdNijqy8PDc17GFw66iIymd7GhYeGjXJs715KjjaG3IrL1x+xkml1W3gnjPn0tK14I1zYy7aCJ3gKy3BoVQEztCXVSbdn5IhPQGpri2xjO4TUvxyDmxAlATVjCLlqo/U8uYBIh75hxf/WKVS4DPN4MJk7AmJQgxkicpzdjbxuW1PqD+5yp9sE0G7u5Lc3j2g/grOjpAtX/nnumhbdjB6hJfdVrtxkp6eAsxWJOMj7eb3qRrKxW4iN0OVZUwOLiKccmIscrDmoNp0iknd/KFeXNVdgAcYns3M8eDJkPLHBzunRFF0rQXTLgTHIRjhEZ4AaL2CvL0e/zJpgOKal8vOH2UxD/Cj29G8zvWMrpguAVd365cp9W9aIvZZ8RnaF1plTi5vtAFedxmJ2d4jhPdgguWywEpVcJA0pyLQc/6G5d6PzX6dGUrMcqqe08xl8zz7Btr4wagxWwft2S7VSBFls4FuCSyQF3hl8lK+9fx1iIzy93Amn2AbohYagFiMfn0qciiUGbeUrJYPaBqrSwAmfz9pISSC9QrAdXFHCAhRn9cI0XEyQKewjl9+IRCQ+DqTReXgetieiVRSsw8DlhmelsZKMnPNJ+wZRKifVK2zASQ1TfRA3kPDbfxiS4sRqv1DTFNpLErPetZENxO7b3eYqrynKpQpacWVNHuCUc2H1I1RjOC+PwMnCyDMv/y6v1zSauV42VPdFjEPKcHRXGKp4edA3ZJkFJKc5f9f4TDdv6r63flNBz74Z7cI7YybCo1AtiuH8RQQkao1IM9qtF5X+f2EM2IDn0kvZW6DEjZCxzTU3OFy/Pf8lWX1nIqtTRG12eZdPCosVyZGcTbbT2m4aUawH+7xnmAPS/bg4lBxOtLvQjBOu/kjtwfG4Dbo3m5DBofaIM4fmJZpXt11Mr2sYrgWwC8b+jfXtPKJixXOMMF4B6SPWFPHlnqy+E1QwuOigpTWK/BelFB2qBWfUJAI04bGziq+ksN/FXT2rSRy5B9YGN+FyywDiMbBue2NGT0FYMYUFW+8cTuB3tAfUP1cVb4HkstY2kMhkhEsLL9xyzsx1FH0nVccSNnBhnYbRmLCoUt3HEArTZy8o/yk/NfqJzPwusp2bKjWJiVzFMfzlhy/rWm2k+wY8gWEM5FaaOrpwC3euIjxfWebuji1c20MIBF/peRTeu7q11Youh7hgYqpv+1V3CzXu2IPUkAk25D2g1YtkznD20fnvXr7S+1MptIfhtt8RgBinll5Q2eUzoc3CKfrue8N1swZyM5eIHQI/HihgAycKTezb0UjgVy6PHuqYoIKFFHw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f75d122f-73cb-4a69-755d-08da0e9476d8 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:04.0223 (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: BdVIUSI15yLjhxCtXbB6WOg7WuB91vE/YWf5Yt0QbhydujJJ1YHYoM18ABCrLDhBNjTZlcGd667q4kq8aHuFyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: ZLScpFBL0ON4sWCRmC65e0HZFaNB881O X-Proofpoint-ORIG-GUID: ZLScpFBL0ON4sWCRmC65e0HZFaNB881O 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 --- configure | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/configure b/configure index 7c08c18358..7a1a98bddf 100755 --- a/configure +++ b/configure @@ -250,6 +250,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 @@ -2777,6 +2778,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 Fri Mar 25 19:19:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791933 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 21E04C433FE for ; Fri, 25 Mar 2022 19:28:04 +0000 (UTC) Received: from localhost ([::1]:43508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpbO-0007Cl-N9 for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:28:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTs-0007TK-BN for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:16 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:3564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTp-00035N-SW for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:16 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHPWQC031192; Fri, 25 Mar 2022 19:20: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=nytIBXWM6DcG2I5/3fupTRGVmzImYALmd0Jniuu/czI=; b=OnOHAIJgU4H999I75X+vLpAgBdakAR2bChlxI3JTlMW9la3Npg72mhTlkpN6JLOa3U6m KutZ97aWPlq35Hc0wyqkqVKBsrYVM1hAC5sTSpARW/DTJH2g3n6uoXgYJGxlgj3eHOMr PgZIAVeKvbjfFTf38LlKI14KsYhHgZYfo4j3m6pV655irN0nm69g0laAmgLQ8vZPuxCu muEpk5FFUY2Vrudot5kcI5d6r+1pxNSvMZMo3UOENNOtCK/7VJ9BkoFoaSh3egnWTom9 aHRDJ6Rkx536pL99IOpeQo6LcRV6w4z3G9O5pQmMQtxrC9QnoOJhTv/qUZrSIF2HvYAn qQ== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew5s10507-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:09 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGUm7013953; Fri, 25 Mar 2022 19:20:08 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2044.outbound.protection.outlook.com [104.47.56.44]) by aserp3030.oracle.com with ESMTP id 3ew5793v0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZfOu2upvTmzAwBHMERGzRt+cuNz4cUbEerpQbJaInKKYL+u/URZ1bnQaZhlu+rSBLqeF1NyvNBgqC+VdgtpzAXFypcj0s4c+NJfWpw5FvP27aRHi38fZB0q3IRn3fwBjyXXzUVVMMDOeGvNyI3ng1zebsK3df+2FLzCXy52eCnCiT7fA86UhJdYLkWW+pJJaR4jKJ6iJ0ZO3QvRW4wFIz3EqCpoglzBFLKAg8a41T1YEvohw7/8Tsav0q9eMG8g+2aXrGnIXYwv8e9QzQf1gcJAxh8U9tlN83jjc2pgj3eQDR37mlGz+2lGzQuKS3p6KfRDizydx7BVbWOa2BDdvZA== 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=nytIBXWM6DcG2I5/3fupTRGVmzImYALmd0Jniuu/czI=; b=FAXxkxAsv0LU2XrTKpGiXmSTEVCnyX2oVPRzFirCByBzmSVjU61kIQMLPcOCe9OB52h9e8vB1pa7acTOoiKMLTWWPTIwbjzghIpH/7jRveScpYJ1Rz5V8B/vY+P7MxWnVeFOE6dkLihCkCKYoaCo6Y0k8TnlqYERDUkG+zXROwMzATnAV7lLq5m2/Xb6sauQ32HVophyD3qFTBUW1HIihCyAO2rHifGJf+OSI82+gtZgvqD4Yx+vbOt5Ca6bX+GoDuMEl1CfsF+9GbBmcAulqaTwmXAX5fOwGIm+p0N12eP87+MzS3aceb50U+n/OCVy+oyvecYD8DOinLizMQFzBA== 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=nytIBXWM6DcG2I5/3fupTRGVmzImYALmd0Jniuu/czI=; b=WiwBFeAJkYuEfS4VSCs+a1/QRZl1QNtOhwpGOMtCH8xd23XyKq5JKpjFcthqyUwGNMBxOY+Lbvf5d1E3YBO9GgxaqMRzg9p9poKd1Guax+vM1BOGjF0aDPeCydUSj9zp0sAGNlWdS+iGB8eXnoKoMHNAQia2JXcEryRpNwVzHTg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:06 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:06 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 06/17] vfio-user: build library Date: Fri, 25 Mar 2022 15:19:35 -0400 Message-Id: <55c83bb6e4550d58fcc53b7e83a7d0de6ce825b1.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 73430611-0abb-4632-4ad0-08da0e947839 X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: jLrXl8PBl7L48SCVKQSBjQIGWrG53dfEOhSnAPsts2NOXqfKA0WIfeICpUaZR8IdzMEMzS2+jZIxfSMCdGJ+df99znLNhyUWozx4+k5oz0iyLmcZ4X0yD4slvhTzY3BtPeTAdK7cHid/Gu/m1MaEDl/TCK9SqrIpClVa1gAYs4GrJW1uUHEETAj94MUMvjziP2mgNuu89Bj9c4C1NFle43EF0HxTvztKdBopMoZAKAD9SDPxoagvA0WAJ1bG7xWlRVQXwgBICpB85pMFMf2aOAE1To5WcbtQfM3+WjjIfW5BtMr6yn3yHe1AK6ynVK52krIbRsjm5YzWhUvlzOpe62i47FnXFQuBPagp8to2qkSE11eCj4xcU2IXh8wZ22xvTtFLIZh2nTCSlBOf7U0N2TefHz2sDWiyU8upw28phh5VVX/ucikSu34koneGs+Cuhnp/Hv6e41Cg41Zidbke1no5jftJNBxLjoiXfvGNkCRx/ZxcujOQlg7mg83cs1gTmRQyBk/mdj9Yn9O6SoaOkVdPADRRUEEirpznuSJpZ7/C+7/rdyBMG2mKCCIXP7+KEXT5O2ZxztK8dykWdx508a/Qn/n+AD5hGVthOrn9JcLrO7ymLh+ngT1bgnoxVNRnHM9hj81dEdq3AqbZdi5SCPrSpUoYEdHv3C3Q66kXC8j5AapaXEax1BM28IN68BwrjT88ZFkfC9fs7ucEhoi5/T+uNBNsIKcdWiehmc6CoOulOvrKae8MoEh+o0aQ876rZdtOZKa/1XyxLWV6KcqoYAtSMVPWkxGTTwylk/UV7eF6WrWf4xsddhtBb8sSS04Inji0CmRyRrOUqYcqe1YpcpE4ONVuXY8c2nn06TrP+98= 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(30864003)(66946007)(2906002)(86362001)(508600001)(966005)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1AkcuxWYTC+Y0yhBd6LrSEnWLm1FCscuyKtrwRHgElluafa04pN4+AJXbo02Wp96X/SGpIovp8v9QpkPfQyHfgXTEfKFSg1nUv/e7cAYmTrZ8Du+LCT1o1rX+7vCK58hZa35wHBKNnSdsRlH10bkP7FJ6L/BkgfqUpzap4VVigxKh2uxHX8gLx+hRgjwAOn2i+Vg7WJ1AEmvv97JNsEtDHIHqAO2o0+2tUYVaq5G/sQsSMHAPKzSeAwuYFZ+owSpB2vCdo7Sohz8hWr1Up+yjINl8jsAP5a4EFSV1Q0Teuwf4aLNRQQxfT34/zKNAA7xaDsDuQ79EvXygVBDtV4r73IR1/js3QT0BTHe+g9GzvXFotdk2gBuiT1kTxOlsAekT/EvWjG7PNEM37lH0CKtmgkfDVwX/05s4SufAzHY+RfJgx9L82K2IshBpAGngxd55TSr+qTMg8Kl0Isne+0Oql7u4Ann93l0mApI/oRkdsfIFWgL+JhI3qBA2bJrs3JcQ/Dm+wZKZJh81ZYCfrcv6sxhjs9mzJnY9E5jcE0TEPER9wsWYRhFcFK0er1LtUznYCkFPHZ44UaEgKJlmOF1KACMWLB+4PVF8flTdl1Lak2MPHMEyE6w2ZwueY2kvVlT3DSwsa9X78glFGImaHDXuZxn0sHaCr4G91/sPfYYA59SxBmViu+IbmCq2dK3OwoXRWGdAD9CuL8dMvtJHL413yzON9KkYb/s0qE4KbhveuVuYhwujmIfpwyCJFIbnlDuZP3Ok/OpVOfLEHDVPj3LO/SgBddfCa+fvpRwhfYz38DNO4okl1yx56IcJ4YcaoOWSR3F+XL2AZxITSh72a+2rneGOEL5Uxng4ifJoTM6nTytXOyUlNDYburlycPR0yEeBkn9F8iCrsNG+hpJ2QuK+jyb9SRBctrdb9pd7CDEPEg4fdg8TFAiN6I/RtnXyozWa3+C++FxRLDMdEbIx34T6Pn1P9do6isAzk6jsMlJSxcwUary51j8ECDPlHiRvZAWu8ytB24y7uhyg8pnbdO6vZ6+Li48hlB9hydNLxWqnM1iZBhjNPp4pRQEKR2ePKodDCs6cgDwZxPm7VV8roiWqkcqhiaoYJNl23PKe/sScuhIIGSrZ6bTjvxyLsW83YpIfso/EgZafPWYH0GNroWCMJbYd6VHWpOilg9SRKDboTWLMVK5aAYikr7rg08Pxu+3Ud3gvMxrqeh7x/hKBCOglQcaD/PT6ivecblJyWwgNWptbnSMLvCK0BDz6xTIYliF1NfyCQzLrazJiMM4FYbU6I3E9VCebDjc4h34tOevOSLyW1mf7xEIYXolRtn/KHaIrLQryP9bi5kSjwhwbjXqlyNZagMFHvaQKKwqFENYlIVPhu+3mxMtMd1Iff9D9jmhLeRz0sTVIW2VvAhfYeny5W9AUO5+N0LAOLXB7MNcHLxAsi3wtvs5zutP8wy/j1PDYdI+BgBHTa74O+FnXX2kMUe3fDG1azUnE3pWN5lU9u5uSmzr49nHYScN/6sXj0sApo5LD4SeeO2VzyXJcUpwTJqSsiShqKAjqVEC91M7fL2AQXq/WZSFoYCvnuG4cPWqXx2/OnyO5HMVe7x25qrheJjZik39uSuIxewDSvGD38xZHiYOd8ebrjclJkW3Rv1ZYNF20D/OzD9VobD8s6dRgMqN1NVUCtG5QMtEhm/GCX8/w+brQoEdXnHazv6akK0NGAMX+62TPFLBmNf65joK3g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73430611-0abb-4632-4ad0-08da0e947839 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:06.3815 (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: qFFeULSNZzlECUYqAA6JftJRuUfDh/ZYoSWzZRsjoQLH+dnZB6eMCC2OCy9IdhfkpjRgbfFQzvFvKTNtw5aZOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: CPHcUWi7FzjjqnRMI4X_b0YSygLv2PPZ X-Proofpoint-ORIG-GUID: CPHcUWi7FzjjqnRMI4X_b0YSygLv2PPZ 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- 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 7a1a98bddf..c4fd7a42d4 100755 --- a/configure +++ b/configure @@ -333,6 +333,7 @@ meson_args="" ninja="" gio="$default_feature" skip_meson=no +vfio_user_server="disabled" # The following Meson options are handled manually (still they # are included in the automatically generated help message) @@ -1044,6 +1045,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 @@ -1267,6 +1273,7 @@ cat << EOF vhost-vdpa vhost-vdpa kernel backend support opengl opengl support gio libgio support + vfio-user-server vfio-user server support NOTE: The object files are built at the place where configure is launched EOF @@ -2622,6 +2629,17 @@ but not implemented on your system" fi fi +########################################## +# 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 @@ -3185,7 +3203,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 aef724ad3c..5ae87b8f86 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') @@ -2111,7 +2116,8 @@ host_kconfig = \ (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ ('CONFIG_PVRDMA' in config_host ? ['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' ] @@ -2500,6 +2506,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') @@ -3612,6 +3653,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 cc364afef7..0488bae9d0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3597,6 +3597,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 52b11cead4..bd531fd545 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -91,6 +91,9 @@ option('avx2', type: 'feature', value: 'auto', option('avx512f', type: 'feature', value: 'disabled', description: 'AVX512F optimizations') +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..7056525da5 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 7056525da5399d00831e90bed4aedb4b8442c9b2 diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index 3ede55d09b..b6b4aa9626 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 b9d06cb040..2422cc5574 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 Fri Mar 25 19:19:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791915 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 30A77C433EF for ; Fri, 25 Mar 2022 19:24:20 +0000 (UTC) Received: from localhost ([::1]:60302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpXn-0007qj-BF for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:24:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTx-0007VZ-4C for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:25 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:11658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTu-00035r-FA for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:20 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJCs2031416; Fri, 25 Mar 2022 19:20:13 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=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=vdnOu3OIM6ieJnh7BOnVeE3esCcP1xy/yzF17rpOJ44jOJXBLSBkNY3ZJy3s7ZAkvIBP TI/LDCCGGIyBt+Hf7Jm6lxjtAvnuRXSFC48vh/JH2f2UmE3HMBBW6+gR2+ugObzC7YfV q78vsbKV+dk3WyRg1ses7iQ5ENgKZMxSKBtlr0tLwIchbI3CSWoLOqUrW3HXaAfBP4LZ t6vFJB90eOj6nkTCtRSiaTquH0pIwgA4b2fJ8Qb24DJK3F+9Jbp+dT9qnh0u5ZA5Zm0J 9AeaEZwS1Lv4MPZ2c69wu4JR3H5N9jt9Ifj1F9MzP8Kv6C8f8RHW+LDSqa13Bp0M7V9N 1w== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:12 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJIFXe015896; Fri, 25 Mar 2022 19:20:10 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2044.outbound.protection.outlook.com [104.47.56.44]) by aserp3030.oracle.com with ESMTP id 3ew5793v0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OyVOktu09QEHnWPfxOiMya3r6eSB7eVtCtdCYEl5L3og4ZDlMqM3xqNS/yA4UV9hVxUYkMLNTZPp7t5ddn1V47nHepTUtXozvFT6JQhZ0brbbbHwtw8C+0sMGqkXSrfQXkddJEAHltsA4OYv3yECT1Z9weuTJ8uu81xbExeqivrthTvmY0lehjcj6a3GLZm+Cw1cMtlkxsGGyqivULt5jQGR+MXJiEjH5ViLwgFbJWD58fgURDPhD0xvRL7MXgpzqRM7LnNaV34ISH/Mztf6/jAljFCoOhR2ni2kDFEgAGloWrTatoGCxOhwIptUgcSTtUzkWOabev1oUZG8XNKx6w== 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=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=WTgS22iAzEjGQCWWBKV1Y/KaqKixN+kgQalZ9UjERAptu/xilWKYxhoEQmQrjjtC55BLuDLE7s+GB3NMXZShOe8Wm7LhN7YQUMiWyunJhWY/cba8cNvLAEUCENkJMNKWFkfxE+JEb7i8IFgLV6tDEFijIjvOGxD1SMgWUfFHPYtKr2iLk3tBs1ez8PIqS8R1j6DRiecUEZis1maiTs/9bjWJudpglAaEBX+HryIqjS4j/bvg3717EtlX2h2uxt+pgqC7pRP/4nJZCxptocd53rJvkF/Bdt14lcETT/bmJeP97ebVd388nfW+kWyMSdrye3MekM3d9pB+yBjypgIKyw== 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=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=vTnAGSvICnqxWR4TwP16kh2eu3mpUT9fzmy10zSklJUP10z8HLvb5WVIcNqa1QX4XTNlvaXSbmyWgOvMf+F3pqCJ3Iaa9h2sKIGSkaj1HHWmXz7JqfUyrJ3B/xo0aHdnZ7uc86YU8QHaTyOObBcaRbJvF9t/1zACoIfFD51s9Vo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:08 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:08 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 07/17] vfio-user: define vfio-user-server object Date: Fri, 25 Mar 2022 15:19:36 -0400 Message-Id: <35c1c4121dab88dc66548b8d47b27db275ac08d8.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 2879cec7-73e1-4747-d28a-08da0e94798b X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: 7XTD6pW4vg43ppm9Go4mjGEqn+8n67uW4W+5N2mFCJ11kAuCy5A+bV4OpDJ70V1bFFN+qZU1efFHqRp0y1S+4aGadHnw4GvS4fya7m3lnZ2A4xmrUQ8K4Ywp1u2A21g0msp9596E992UZn1QHXt9A72LZIc/vIC+8gSYq7tJ45Mp2qkYnFhTY4hZPjClPUvVmPMCDOSEYB7LQAQ1qUNXaCdUBKy6Unq6ReioPhCpnkZPW3Toluq4milBrDvBVEen7J1sSxsy0a04RUXSZfQmzoxgNOKnfePkCUmY66Pwhy9tKWOz389yDdBFusP7FKkXVQYt3Pt7z1b0P0kKGiFe91llil0+NPYPCa+nmnUUIpaKLDLeGqkU4zPk6O+OKUKeekbLOtQAvYn9xIt5vXaRz4iphdf7j7/7c85mXfUgJWdsNmzImnOh3aP1FsHGT0r9h0M5ZnVD8Fyo3p2JfaO1yeyVA2hKlMB9z6aA0I4WSHtkYaC+Oe+61t0OEWyuKXl6A7x4KG48LGM9SYBKn5R/jAYzHlABEVe21yY5a9BDTfMwDlKbHzhf6XftUL5ok3q0eCBKbupyHP33FeT6mLkaTz6tGwU6A4QBZ51VA57Tg3saBI7bhuH5daiz8skCBrDVKUGjlb/rPv3EopweNlY6TtbE6cmy9nem25TzprAIRDfff5vILyByQawgGlTGZaazlhrrMWyaXIPm0u7KkUPW2Q== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(30864003)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9J0UnwPa0bwgdCZk+rxyF9c7LzKu?= =?utf-8?q?fupjWM/Cm1cXF99l4GUmQMe0HZkdYvounWATeVWaM8ej22z+oxPpUpFtQ0YY/TQX1?= =?utf-8?q?XMsLfc1OUoHCiSxllp5PmNgNIW2I7OY75sAi56MtAkG9gDbcFkV+GQetyo2sJbrM+?= =?utf-8?q?RQq8cIIrGhedMQP/JcUp4IIAvP826hZvSLD+iN8Nj3NdpW6ogDquI96o7xCjWjgID?= =?utf-8?q?EoN6IKJg+2Uph3YI0oin5BRcwunNfqSuYsCSZ0+gcKy6Uw9Tzseax40WHxa+/O6qD?= =?utf-8?q?rPeP3qCWIhVtp6Bb1ypV4MRUiGK069gWbVaPQAM0y7DNWR1uB49KNoOnAYJqXZMfz?= =?utf-8?q?8fJJiQECU8EbGHvlh707Rq8s66BBFX9xC9/M+f+05f3Ky/GSAd/XIQqzqhpSJpYyP?= =?utf-8?q?LlxDHOBcSLfGOXPKhxGDFUwoNYea/MvwSjvS9cN+UZIdqZMG/0HoGsXKsW3l/t09S?= =?utf-8?q?mmnPtETtS0zNIJSBWNddf9XskTEzLf7+wskSpl0qR8OVdEmrWMeZTk6uAghUP0jH1?= =?utf-8?q?TxMVJ73qIDlsO2WcpBZ8ehyH/JrpavjQKZUP8gQIq4WQ0QAUcDkX5pRJE9NgLHLRj?= =?utf-8?q?E7WtJVQ5kdecML0ECWun1bKRnDV+uFdKnwa8+IV6VLgGuWqLQCkdgJaEgNMVxY0Ve?= =?utf-8?q?TdePr+5AKi9j2YqFq7dmSx+PngW9TjvPaW6nv/XRP7rpeJ8n/VyYRCOaJMVWp6Fs2?= =?utf-8?q?aDGC7Sbfk2htPWwPmNYuh9oUB2kezDYmMmueZmNuPOerJSnARJ9ok/Oo2yDcey0mY?= =?utf-8?q?9KmKdNla5YoHJw4mdrSZyBIhxml7gLH4pl8fJ/n9eaOB7o5Amp4htrfh/bzAUr8tW?= =?utf-8?q?vcB1AI32Fg1ly49alJ72pNXzzjjhyvgQ7GvqLuBqLgldmpYzAku87qIgmYnTsLeaq?= =?utf-8?q?p6gQALrUtdZTlHNSPQkOVMJbH5rMUzY0etEEkv2W489KCxOAck0cc+nQ6ObiQBKmY?= =?utf-8?q?6pp0QDqSMDR/lMKQqyQ0NkTCnx6RxYEWnbp29RgwazCbPBP1dCDK2gowrUtsL8r+1?= =?utf-8?q?qcWcQ/Efr7shc5DgZxUYAdfH8J3ZEslnRCIwtx/mjbCO49FAsTlBwt2MMEiRvAAPJ?= =?utf-8?q?CwHhu/Ratwun4ophLQoSTfxSkfAN6ebKvfzAhkzf9iYr6smfg53sOhxE6pW5mFuki?= =?utf-8?q?9gfav0OalMUz0Eu66OcdN2zdKrPaiiyNXfpnTG9cb7e/iDh6oGfr1AUO1h+8WbAbh?= =?utf-8?q?jjNF5v33dc8DlMLKUOfaICSruh2BgyYlTGgyexZWo1gp0wU8GhNzE5S10+WTuV4i2?= =?utf-8?q?9tVWXvW0XihMQWtB+Dt4rD/DlTUK1yYaORfA3CcDPSREZUM+ACQH9MxIv8g9HbejL?= =?utf-8?q?XrLpgmuJz7+E/FFCx85G8PL8NLjJW2VwEJj+FVMCX0hMOZUA5iiu620sp2JJzdZoc?= =?utf-8?q?ejBtGDw97M+Vu+tUs8BFWmPYA587ZnTF/bEllm5zB0upZIqHhJs9onLxskzGFaZKT?= =?utf-8?q?sSEP63lSR7S5FoiiwVTXANUoXqp6LrXN8PZsiI6sBi6VA4wHwypArTdouB8oiEjcb?= =?utf-8?q?hONnIDtVLeAI0LmJDsdbYupOQyVuTrfJVX4aSMew9Q06WuaFWlmpLHnjeoZt+H/bj?= =?utf-8?q?KOpy837FfEC4gXdMYC4tuRY3IMYAsKeoNmTviXhWKra2Ej1AQ+ksYyE63TTz99+Sp?= =?utf-8?q?9/JHMVbxiG/Fli/tE+068CxEqaGoh95Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2879cec7-73e1-4747-d28a-08da0e94798b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:08.5845 (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: MwZZ/72irX9ADU+mvEx0uED7PM20R5uiYgoIeMMMzOGEDPs8wpDOza/TO2f2bH51SZrXsfmA/3xJseGyeY32uQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: tGQWrJz1nWiTFeLC5BU72Tifa8x4Ptd9 X-Proofpoint-ORIG-GUID: tGQWrJz1nWiTFeLC5BU72Tifa8x4Ptd9 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 --- qapi/qom.json | 20 +++- include/hw/remote/machine.h | 8 +- hw/remote/machine.c | 23 ++++ hw/remote/vfio-user-obj.c | 211 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 7 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index eeb5395ff3..e7b1758a11 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 libvfiouser 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..2fcb9dada5 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -26,6 +26,12 @@ struct RemoteMachineState { bool vfio_user; }; +struct RemoteMachineClass { + MachineClass parent_class; + + bool auto_shutdown; +}; + /* Used to pass to co-routine device and ioc. */ typedef struct RemoteCommDev { PCIDevice *dev; @@ -33,7 +39,7 @@ typedef struct RemoteCommDev { } RemoteCommDev; #define TYPE_REMOTE_MACHINE "x-remote-machine" -OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) +OBJECT_DECLARE_TYPE(RemoteMachineState, RemoteMachineClass, REMOTE_MACHINE) void coroutine_fn mpqemu_remote_msg_loop_co(void *data); diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a9a75e170f..70178b222c 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -78,25 +78,48 @@ 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) +{ + RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj); + + return rmc->auto_shutdown; +} + +static void remote_machine_set_auto_shutdown(Object *obj, bool value, + Error **errp) +{ + RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj); + + rmc->auto_shutdown = value; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + RemoteMachineClass *rmc = REMOTE_MACHINE_CLASS(oc); HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + rmc->auto_shutdown = true; + 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); + + 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), + .class_size = sizeof(RemoteMachineClass), .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..c4d59b4d9d --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,211 @@ +/** + * 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 "qemu-common.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 0488bae9d0..e7b0297a63 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3598,6 +3598,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 Fri Mar 25 19:19:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791934 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 978ECC433F5 for ; Fri, 25 Mar 2022 19:28:58 +0000 (UTC) Received: from localhost ([::1]:46794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpcH-0000w9-Mw for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:28:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTw-0007Uq-BY for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:20 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:13308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTu-000361-FD for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:20 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHWvXG031098; Fri, 25 Mar 2022 19:20:14 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=kRf7+WxtOwU3kfUY0jVueoHBR59qT4ytR5JsWs/AK2k=; b=dKTR2QPDoj/BQEs/u332JBz0cSwvYq82xYcC0N+89Y/n7LUYDvd8xicBeTxUkQ4I5Yd0 CeAYXBKqHLUDVtPnq6eaV5EQFtZixvVjMNySV4uL0jGU6CF2pMV8oRMADSPCg1xoamMx w5S2zRS6I3EjugX3f72P5WbQltXYKUmSUIuNIVJJT6vzODNtY+u0qVnd4nnwNDx2DvWL GHjSFphrG5vHS7nLAVi7UTttjLqjRpe0zKAQF8BGp5N4sysiHLJnpG7CY/fc5zglSPIJ FKkZOHPCoYiCL/1G7i8Kt3h30kl5DUTIMiX5hyt42pKff5wQHRk3Lx5OhDH7acL0Ag1f nw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew5s1050j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:13 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJHhjJ077976; Fri, 25 Mar 2022 19:20:12 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2042.outbound.protection.outlook.com [104.47.56.42]) by aserp3020.oracle.com with ESMTP id 3ew701w9v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1nQ4bRJgiJFgGpOw9skjbKS5qhgqNKxRtm7wT9cBb7cMQHXZQe+uiUcGOiTMmvgJngyeJy1Wn9SFeL7hfss8EcfRCD1V+bKvKgu0naxxMIiHhNOvcTPNqv8n8Em+f3JMjLpWZkAcxapM+zehO9vu7GIFFM/nSO7RyvpFVUqTIq++G8kcm/BQr7rvr3cV/O4BSyDRUnWy36p2WGHJY0kgfGuhqFWa0IevoRuR2cJ/pBbb76rOPJiOFnV7oncOEgY0PTgG8zbiow963/wTz2no/9Hb5nWTADjQ/oWokK75j/W+9DJcsPJElQrIQoqoyiuJBtkLYw90NbOLNKXVqZa0A== 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=kRf7+WxtOwU3kfUY0jVueoHBR59qT4ytR5JsWs/AK2k=; b=JKJsFML3HqyfH+zZAqzX4FMZdS5LvWINZEi8LkhVCKTkSY0zpcpcRFEIfMp7yYSF9ZNgS9XrFdnPwU+vSC+hXxpPJOxGlidbwSOrlom4cE3JeqP+rHbnw3mFJN9Erfs+28ad7qbchbHI1mcrMPZ0IfRDyILrmIS5IOlcWWDYsUiF31WLOZvPDYkbgJM9cHb6CICxuYk1Ohlx0r/vBrWzwR7HUyzdFoHR56f7uIpqO6Jtp5euG9Nw8OHOCVs5/0uQ0I1XqDgTJwY6q7HbsCVa3+QfKJbJeFjuSnuj2YV0ZQCNe9MK6aN4UltJ0jt5NF2Tr3GfxV8rKJWDCmQlnNv5MA== 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=kRf7+WxtOwU3kfUY0jVueoHBR59qT4ytR5JsWs/AK2k=; b=EQiF492um+zSewJ1OodZwIskYrwPdCUDQ1DEYYKkwzvT5pQk2FhrDAG+PWxjxMHw70oAzMa+ijaQGnE0B87RnA0cElMLK3nHI0nwsUgUZWeFlGehXJbGCtOPZh5VfeeTSh7cJ+yy+DwhGkqU+dPXuXDAssSyS2SGQygC/rD0vAk= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:11 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:11 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 08/17] vfio-user: instantiate vfio-user context Date: Fri, 25 Mar 2022 15:19:37 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 6d65ea30-a5dc-4cea-a61f-08da0e947b0b X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: M041Cp2bZJppk1bUvpIlZN9/OmWKtnvvB4Y6E9d0lqLUMtruZA1YargZr+Tp+qNY3EvHAfQF+Eu+31RIWOHVz6ZsuSXX9Ygtx3Z9+Kiatf2Ceymb9/L6tOCKmNRRudc9PkE/BbELL/5P/1BBPgsCST0pPue6QmxjJrwJVCr7H8DNy6Gca7eXO1m6Ev30NfzqLtmczK1y6xlCgHX/XyNVCGPvyqUMgO023YFMAiTWCAcdsidQu81OSgd12FhPJPrdTUdE3O+Qs4uQ/52/Xvy82e13ICWMqmCmyEiz+r1nmoGpRzrmlC7ZtmVGKzTiUe24aUrNHKkOL+POy9HXLiWl7cX+EmlYlWmVLyaggLKNGRfyjpLVLu9IyWZO4OYBw/EHq7x7U5Of0bwFIHKdOj9QO6eVXLG/ORu4j4tWTl/RHt1Mz4XV6vnUvAAHpo5gjxOKIaf0FNcWKA51D+/mXcAyNRpXZsgdS4G7UrcqLJ8Omh15rVjfGvScclZQN+2fElk2DqEsGKDkOySdy6jUcIoZIZpPJ7Xmrtk/Ta1vUqWBYje9mKJ3if5PJeT3hcjQdeB64qd3lXWy35jNAK2jE2mIpddtIki7KhOaLbSVwVBvEdWM4hzV+0FbA3EmtooriOmiqTbAqYkT2PEcsboQ2Q6QSKmfSGgqoH13g0JoZhIJFJK7heX/EEFn0hkaPMIKcZEUlwepBrik5+q4YnzXQbXY3A== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: f3janopkuIpkXVZZlvSi4yvNwUjo+7EqrkcuTBYK867Alco+RVa22Q//sl/UbrRgZAqzND/67dKI2JA7WU2beAn9Zk+kHkCX9jLZbKu6kfk/QYsqz3eBhHuhhr2nYTZVLmEON1d488ZTt0FhCevwS0CwU9G30LR15KaFh+/Z63jROTK4Zph60IOVRITBN/nmrQKPSGuc3mwH1BpFAfSM05ezxcyRE9lNFyrNn+O3vAuGy1MzRAfSQ2J9LukN8lDSBfbxaXy3gvcKsgTq3jsNspXBrykIhOIkdJoKPzr8G08itoJj+lydwM+kZ4k5i5y95j0uzYazb4XEqS5SLnTrOjKlsMTPyjtCjweGrV2fvqczuBG2IAlFasaWQ7M8Nr3dMSdE0srHn1AGOOv7PwcR/R7noKEVE3rlEnPdh/VDiqkulHtgBMA6Zc44lGCrunvXL5drfoujE9c7lprJ/RwJ1WtvZn3HbRONogfieGS5Zo/lO+mw1aPhGwvRtdveBZwe+Tc8CF2W/tdBPtk1un0xu8WewkQC2i61gVFI81MkxCtdBT98aU2oc0rBps9U1yD3DJJTIKNDT+YrDjQu2gzevE4l7QWhKaKWzZ0HDNo4OSO9lYbXdp2R2k5rZ74D8AxyqO/L2r7L0iAO8F7FxVonoAz5rpd4ewPAtbHh50gqFHCuWSwn1EYQtD8P2pI7L0Bze+KnZ0PuOwf5xUcCpgV98G2xZW2mf7PJU8y/1kZ2/peuKQfHxu71Jvh40KKXdPI5B1DgdKxcti454HE5vGOeVy9/XkbIaPXFQ+wM+vcyZFue/CDcsvvYSkouvdMw5wjrpiA5nlkWcH1pxFSsMiq79Q3l9JZNLfn3pbsAlR5GhDp5D48ZmuCVe/1rL2/DfzEwkOSNVdALofJ1c4Vvlk7Z27rqSZzWqL0OU+BRtUtt1Sofrk7JPBP4KnF3eBFL5goMV/YaYq0mm4WQ3s/c+dUGZXDDfOBgECSMuI9e9DUv7Lediyk5Xttj1rclHZNNykbVodXc+LEnIXDZWUrMufolMgUd7bBkGkfqKGsSX/wzovlJHFEPKcGvK/LsxVdlXreNYc4kT1w9EainTSMzw9kWo+7QNKDqyVR1F5hFF7FIYFpBiFLOWfOwop3M7hRqAGtOUcUJ/2vfid97E8C2f5ljWJVHrV9jQf0yDflNAc6rBjo9O+n60Kaqt+wUJEO+u5u+BPfJu3Uv1CncnRQ8ges+nmkGY9vUifiwSmttm8AGVq++9KCW6Q664+6JeEzhuawT3ZzX8kPQYicI0qcyZGRa6IG4jTdTookQwWIpy8cXsZxS6SQ8O/zXLYMdH3xIwgkTA7zr/d13nmf9DHxPvrUFW7s+RPx6lONxeUvWJ3J2w8ws6WVofKwURfQldVV1U7j2G48GgjpIKLmPnqybNqmS2TRPFJ8gdTMNgwkiRTNtbMhjrWCuijznwM3iyEY/DFULPAJ6f4XRPxMIzQFV9gQTZPejaS50PtWHAuMavBYHJmWZ1jPUEqRNPpDzdSWfSsWG7rh4NmL3D307HHBLs8Tf6nhZ3b2JC6jry/670ORH7qxPSHcgVuecbOVmBjjcX4gbhjBOuNVOQiuMHxG9U00q8lmmA7bnpPCvL+3WGmK5ZNVwfH/Xugpan9Q88+KLOYQ+JCgMOS7lKuy7uCmvrO13tyemitZ5zVL2au5Bw7M2WpCSQ2IPpmNLhgv4xMTuodi9jo28AWiWRu61whfzMoGsig== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d65ea30-a5dc-4cea-a61f-08da0e947b0b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:11.0687 (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: z35mg9NDrgRUeIYzpubRjy8pTeLzce5xwekRYhmGvQnQKx8tNIdRbuJVjX56UrqccpE0YRuq2ywSN0iBZZ+ocA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: ljKZBafiJjDWdF256C4-ZUbSVog7qt0U X-Proofpoint-ORIG-GUID: ljKZBafiJjDWdF256C4-ZUbSVog7qt0U 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 c4d59b4d9d..d46acd5b63 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -41,6 +41,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) @@ -74,8 +77,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; @@ -108,6 +117,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; @@ -123,17 +137,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) @@ -148,6 +214,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) @@ -161,6 +233,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; @@ -168,6 +245,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 Fri Mar 25 19:19:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791936 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 B8786C433EF for ; Fri, 25 Mar 2022 19:31:25 +0000 (UTC) Received: from localhost ([::1]:52240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpee-0004dE-RL for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:31:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTy-0007Vt-HG for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:27 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:18384) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTw-000366-FG for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:22 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PIEN9o000397; Fri, 25 Mar 2022 19:20:16 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=zwPhI+aSY9A8g/pGSugY9jLxWCS4xmeP2Ig6quKEBs4=; b=unY1Pncn2sM42n834QpjWlz1IGUIzFgqVnlpPr5iD8TS9ZHLknq81rfued03sXJkJj1c PxavlOJGwMiaMmEDt+doOi3Qf6oEmmnKvmg6AyRY56YVFctChOn3OY7lZ1wtzWnuAucD K3U5J15y7YCZ0/zuGYa7L2/OZHpVSYEQO53+KOy220YJQZKmhpWVRU2XuWq495Ly2LxN qBM6L98VfI9z5DrwXCqdVCfwCwG73jSbR2RiNOshCN2po5bZT3ypyhPmtt2HrNUxlFFW N0zCMYK79f6Z14HvbnptN9w40TMusmhLn6Izo9TgM72fxB0rHcBk3ZppAWpORi+7zpV5 Dg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew72aqnrp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:16 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGW6n077178; Fri, 25 Mar 2022 19:20:15 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2045.outbound.protection.outlook.com [104.47.56.45]) by aserp3020.oracle.com with ESMTP id 3ew701w9v6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oKgQ2e9quCke9B9hWLl9ZwuxsqbivJqEWD1wPAaXAJvhucHHFYWfyzy0kWSE4FbeazNwk00hvkdx+AWIp1+A41h207YMXEGtJmo6UBvMz/LlPSaBY3uZj+0SA1xtvde1TbrSSLu2zDihxi6BpzJNIVny1f8Z7qkck1gF9DcPl3cc0ud7W+B40190iesCy6lLIKPVI3F73BlZIhBgyHvU+dOcX/9Uc7Bjotl5AJg+AW/inY8BQXaOQmXzzONgnnCS0OKBp2cMugiJ4KnBHcKJjc7MIkAQTIBP7y7oHwUEpiqQqCWC2aSvXjQa5vYQeCBruqOX+SU9kqGyAeuOmEhqhg== 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=zwPhI+aSY9A8g/pGSugY9jLxWCS4xmeP2Ig6quKEBs4=; b=H7teHtG1EyD0NDxB5Ltc8y0BIP7k24SpBklm+gQZlpN861qP4yq10LzwPQHHTGdDZaelbKxMhqLsoTr1djkQyc2dVItVjfnIeJ8zd2zGNUHuzFW/unLEEx8RsiNKQAZbdLUls0DYMceRihIsjOiEgZE3Hg1ra1zsUUWNKyi2lcQI+atkhqVirvo1LIvN50NVJTzflGhCbw1DhAU398XRnya4G9LrkXfslDJ9US1cLu/Bxm7yyTTfessGIi1ul7ZSfGZ1NDilu20oCHj8dT8SIwhE0wLMsV8hPBX5sQ+ffjux9xKji4qgl0EOspOGdY21YRvG3JGy2DGFJkVnr4T09Q== 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=zwPhI+aSY9A8g/pGSugY9jLxWCS4xmeP2Ig6quKEBs4=; b=uSn0+DM6DJTcU4bD0WEnQWzIWkLV9VUbdEAJka+uhPX+hv4fOBsKargAp8KeIwqv88hGMUAL+iAw9y/bCjqsN3NmHqOOc0YVWJrckcfMHGMf1oYey2ZZX4T3uknlkE/9LMWk69jUYTVt8aWRiGciT8GpEX3lY8Wvsy7oA7KzfAY= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:13 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:13 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 09/17] vfio-user: find and init PCI device Date: Fri, 25 Mar 2022 15:19:38 -0400 Message-Id: <753d79e5cf6f3568e58db25349be65e6cc8a656d.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 79b985b7-b2fc-4b3b-ddfc-08da0e947c6e X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: m0zJIVyX8lteECy3q0LQNbDOf3JXC+fbEUrCrkB934KEsafzk+gKVHrMPt70CboEDf8GrWXoWoKknZzsNB7wg6MgLnpog4cHwg/l+mlXq/BHamTM5R2RQFd7Vm/2vockpedeCdN3oW0DSJwQC/DhIKCTTvNyscqAgIzYKLluYwd7WLmK+yjvchuzu1ABIUm72QJREJXjReHn38xICZf48oH9YhAy2SLCjDLD9vdiChRbL+gxBcBcsq5L4fN72XNI4ofknq9VSMrSmBNgpKuAPWA17IPKr8qYmQ9u2KdkmHEj+hES05ylW0o1CtQZ4s7IwXqfjNlztV3pyenKl0pJA45ysuIIdra38RTyyoWE96hgvQhn0KjkC3SRo33QlTst+Ae3IQ4Lz6+5S1sTo3GDl66G3IYWQibmhUM/mno2quBD8RGTvcF9BYfARiKSqQQsHN1DCD45M41ceG6SfsevPkYCNadki/z/ld4Yxdc1boaStFpiFdJj2HNakdWnv+eUvMZ6HAip5PMLiyahQw3NhEG3kTtcmAcEB/oSSY/dpM7j3/VfYZkOheG3XN7GFcng+DnK1jSTSrJbVDhk+Sz/kt1FipuyHy/HHjXtwPa3dLy4zpCDw2UPJ+SB2tS6JEK6vraIeu4cKlqvG96Nsms3lta4rca1Q+7sD6OInGNgxJcyyfT4cfI3dVWjQh3zhW4Ag7iExEx8jw+48UmYDgNOaQ== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ygIoYmpRv8lH/5VGQ12Jy3ZOgeXjXIy6GjRS2G3UKxEkKjV1TtGsqFbXhsUwpJMMErLj9ZlmXd+mF8aU72eJTdYdeET9CU8wLwL1obRFOusHkGu9yItZIgNjrhaVaV6hK6zWBPBDsRAzTN9DxExPxmoXL93bTYRCS1P6yG/9BiCyOnS+uSgqsOEXnQNrNe3W3UoWwZMRmz5thwky+kobMU86vawZeaGHqycPZlm7jiAM7l7l7uo752D5s67K2rPnLWTre8AgOY/JLmMb8tiwqw8hPCi/n74YpFXaBzSjGtOzF9yYMK25ZP2hH9IIjuI1wgY3saA2EUNTr1xGGHo8LMn/t+v5I+FKbXVR2qlyXS+Fx3aqZUehXf2cdL2PCywOQnLY9FE+xxij3kL7hwzD7GQSqaoiv06nHxPu1NdMm6bQ1RR8/ViVEjeQsZa5sm744A399mop6Hp5+htSHCJWoraRUlCgnsAqiDsqCzln4OcP6I2j+jMeYONXuyJC6om1z/FF/JeYTLqMO7rIHvU5a5UMkxlwvlU/TIqjDnfosZElnw9gXqbywT5WBzbMAGjFEfItdMn9e2zdf1tGIT2OWux6vWp354fMK9Lq4AeUsY2M6y9dBstsIx7UbtAlg7IGteNL200ejf2iXUqIKlfh9jxv/lebLpwph1MBaKeLo6HTymW8WszN/n3dap0Vo0Z3lSoSlqL+/iBsa1DGUm3NU6g+X7vJopfKp/lC8Dw+HaehShGA0cpwdsJ+kteiRWF7340WZAPti4qu+Z4VqUxerajTm0gaX0wImsUERUq4XJYOfeCSPcxk1N9V8301E3NOd/x5Jz62MGW4sTcMVACB1UpFGjNhxWxeCUWFunXQvpADAa4k0/wWhtInoI9aFte0kK0Q+GNMgppWsSfj2I0CZNGlV9J2mCEOk7qzFqLvdWOx4xoJEcWU9IjIxhkN9XFklwo05UmDWad10NvrAZ3md+MK1f1uHpu7yy67eGdli6mhlnO/NQ9p10dXzUZhaj7ONFLwZzsYfE+2hPv3Uc4WGNkhQNsRIrJ/w1tPhaIoCBCCEQagdd0vQBfNPgqJiNQAhbJGLtm+0XgrRGDGefPNNUPrsk6/wPPDzfjXOMcPkTusNlracNi2GSGkXrFCb7mdrY5VpM3VY1H6pLdFYIjmJ1YDHXxDQRmDZ4mAiV3juiu8Xz6uRuih0eDtOUDHTqcYz+BcHSaV5stMyJZrVQmwYz336JuoIsyhxE4VYAiwJyh/K1r7Z5wLu+88HpHotgIQWKEpZ5EIWIGaA9dTUjwW/rn8YASMKrxX6426y2VofuwLQ5TIJIPU8kjSle0mOqOhHtgqyezdAO6qu56i9Z/uZduOhv/CBX4e0kuN0jXbVuNaOf4YTfwf4eN9+7hYei8gdYwB6+LYgat3WSLxRVEeL3GBiBIWtay9sVo9E8bNWWtiRUDD7r2zwz7VDhAVVLTBoq2QpHnrmLdTnv9XcqFecxUgogDL1XFSvL0ybPuz9f5S3SC+NOaqVPVRTJApN6CKfN3sNX3rkjGxqC4HfnVmhEmPbEbzvJwsiZuPojyRyOzTYCYPIXaIcRHnnfgl3MhTAKjdpnDFcyWr3vqcnL0vOc1K0sGZeye7XtRLA57p6UEQK6rImGAhpTh8hhPxrEjbT8QZUyYoOp92vV9t4LfCKxIiTYTGLyBw/Wd8CU4WpQgbHRmWr+daVD6GZi1JVDaxZyK5Vtwkmr3pX+2MhyzxbQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79b985b7-b2fc-4b3b-ddfc-08da0e947c6e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:13.3810 (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: bRCJ8cH32Hibd4zlNJEcHxB4VEjQBNJ5usTKAAqDbvKkXfwsPled6afgHMTblISnqjKfkD/Tj2V/+n8fGK4CGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: pG_99Jg19VhvjPVmGbfI1fsVwjAgv8g- X-Proofpoint-ORIG-GUID: pG_99Jg19VhvjPVmGbfI1fsVwjAgv8g- 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 d46acd5b63..15f6fe3a1a 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -44,6 +44,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) @@ -81,6 +83,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); @@ -182,6 +188,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)) { @@ -200,6 +209,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) @@ -242,6 +298,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 Fri Mar 25 19:19:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791937 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 1486DC433EF for ; Fri, 25 Mar 2022 19:32:30 +0000 (UTC) Received: from localhost ([::1]:55106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpfh-0006fp-1c for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:32:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpU0-0007W5-P2 for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:30 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:22508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTy-00036P-Cb for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:24 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJa1N031491; Fri, 25 Mar 2022 19:20: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=AImNOR4aVOIcL7ia0TJ+Pgoe0tp/TU+I7NELSc/Bdxg=; b=e2H2n2b0RHgt4X7p1TNMGvlCTNQPzt+x3Tfr3lucbGUEVCalk5b6aP4iMW2KcGGWCAsr uGAZC+2v0O2zn7+QoHuD1r+agxUV6ByrLpryBDzfiJmkE4qh0o4NESfGPxw+jMmXjCPr EMTfNtJtb4AsFcFwbT603fGwrSx1GQSar20FvevLoCAFVOvD25yqcpVyP3/EdZFPN+gW LTrrBAV2pELxgSToJCNwWquZcdWUIF5Dd4V0N8X2GNOv2XK6GUBvw/lkrjAbEtjv+s0H BIlmZUPP/8HGOCdSFTZ48k+LSeEemzCyxAPEyf4pGL0zFU5fXC3gyY//fz85xXSUR+C6 ww== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:18 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGtNc077299; Fri, 25 Mar 2022 19:20:17 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2041.outbound.protection.outlook.com [104.47.56.41]) by aserp3020.oracle.com with ESMTP id 3ew701w9v9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FlFXs0WUUQGmRqjZiZ0c+kCM6uwp/bfIIyrUM5rNcUxe3XAKXtc5QVGA+p4VdcJBngjHUFLByCOwZIYae9Ik6D2NXluuAZZw1FAbD6WuYxHfAghK1fL8qZojWwImlGDS5pMlov2ntxJOjeqLxhQ6wiuBHrCazsU4gP7e3x43rASJrnQk8d47h7KjVSEUsWRy2q4EgLrLb9fME9gyt/1OTEZvdszg79j7QSHF0l1wkuftCXHGXpjZqDJunfioTIy9eEzx4ST73VXpJuVPq8jL6hB6P3RJmqnu8tWUkbScvBRm/GWoDlW3cQF2EeaUiWt0TnqptMVT609EhFuHPSFIRw== 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=AImNOR4aVOIcL7ia0TJ+Pgoe0tp/TU+I7NELSc/Bdxg=; b=TR+PYKcntuTxwYlmAHKcJ1TbGY8etzkt2QFkXbp3+rm71IuPSpPsK+ux2JVzFyTUkaf0Qm0KNTaCoNoXf+gRrnhnPDmn6T7Yz1SvVHOvgdeRnFkiq+IRr3QAJQ8HiHEEvX8CqsEvAP3qfK+5GS0Qfi4/QIDvl+TdfUbGzND50OQkYk5RoGvHyPsp+MFjcF5o5DN6A7BexB8qlYRh7FdMf+Ytph56DU7iGmO//dNcY1G9IMagTr/SvmsJWcRgOpP1blO9X9ggmukDGmE/6tYTpPv8QFsOQ8dqNhRRSi6AB7lGUnd7eCyq50WUxUJaOGMup+uELA8cPlUJ6i/6pfLPsg== 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=AImNOR4aVOIcL7ia0TJ+Pgoe0tp/TU+I7NELSc/Bdxg=; b=NIkCnq9z90qy5eUn6ZQWmiSt6/ArxoUk1+n5Va4cdVbLHIBtbsu2ApJryZsxK+jXbQg3fc8RCOpXn+mQC8gDSlb8P7muqqUokqzRRtEaAUiXu3BmDyj2+6cYW8O0Hf+RwPKf8sYPoRHZxOqiKRg9Ewvru76ZxXkhaahdKszFbX4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:15 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:15 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 10/17] vfio-user: run vfio-user context Date: Fri, 25 Mar 2022 15:19:39 -0400 Message-Id: <7cbf66e83a2db56cede563b276ad89528ef903ba.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 837c8664-ed7f-4aa3-3eba-08da0e947dba X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: m9uADY5nk2tQjlDmzd8b9Z+hR73giYtVWJ89gDdSPZoNvslvCP7PjBD1kHMUZjtI60zPVEkPb/MdylglxodVr+rTsSn2cbgFtiefoEL2l7boInZVl6lOufF9YIcl3ALKtFDAo3FJ07ha8U1nGrMBu6LhpEPiSK18rm4cReaFz0roIXRIuseSU08NG2U4Oly25LKlq1WLx2sWDupl02NwSEl/LoCdbdijfkxK16mf9eeLI8J6963G10p4r/fPFAichKSsNEey6KSxQ/6u85wsWEDasATkVyyyvinZxMYq0U6iyfTg0W8u4UiefqE7EBN/DEQSmOk6iYvtmB+BgMVyO/SU+MRn6gO9BJuUqDs669dhQWGmYMOLIXInzrN7h73bOH+iUdgV63wU7IE/zQ4Dna1PR471DSGtEn7sHn6WC7Wgwd07WeFh+zfJf+KFzmnF5EExgYeNLA/24kCi1Zzc0GO/j5+u7C2BBCjBRpjjNb5QRnVUkfdYsc6yAe5If8G+lZ39p7WMEK21lP9pjTHx6AMTuISeaC4cjRi97A4FTKPwj1TrOODH/s+ghDptCUE6r8ULXi+y9qcbjWVUv9PSCZ0wunlykac4ByNHWZ5biNF477rGsCcopUOKochyMECYAwFm0iZBFWUIrHwiNw/kJN06sLNiwBIlxQ8vitiPTqOgNCQTMBewKXt4XXFo57EWC6wToUy+R7NnVmNTXXQlig== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Of6Wsc5H34jCbk0/V8xobVGNAOpLPFYM/dcTVHdLWIrLYxuUXAX03ounqoLIBzG6aOf0dw/lyq2XViD6rKukMPvcQEOGI31sE0A5UEY1tmSSZLenEgtvMrOFpIgP1ClGcOXkdoN+AynfZwaAljsjjRoHo1UkygZEMkaFy4futXlbMcvTsH6oFw3g7s+ribmkz1I31Kjo5PCTbJ2/ddLfmKaeU1rk+p9QYcYS9GSytSSbvNPgsFpqDddkLceMpPxBp0gYO/vgCExEWuKhYGtdNshmoL7iFqmQElODwHDggJeX9Ch34V0FwB/i+9A8Hm+NbZitzphCDWKhp1oQ8bltdNnL8xubHX0t1nUWbgVgOtMrHxO/LmWUMBnqditwpWrxyvr2gV0TFvwb5QhXZdBlpdlaUt9cer2wzKzMCBe6E9KMNHtAIEmWjIgaLkuG6ebNawTcrhU++JSkAI4mxA3YCa9OI17RxfWD+lJwI4KjkMY5RBOxUgvolKAWRHE0XifWKRxFAvtRL/wdr1mxWjP7ecJRJazNo+QoCXd7PtwypxGCBskBw3eG6x8+oZ6fqWXLwmjwfbpbX7Q3ne3Ae+thZN621EUESzM8SeVbIM0pGCCBMq34EQkp537btWr5w2VzbLxNEMFFB3bzCJY5W/D+xNohdMiVJ50w4IlJe7LVAfQMfqERJn79vY6XAo77ccZDZgmfPvbk9xZWIELa5Ag9ST/8OG7N/FxsRHlyFHJ1eoECAJ0P6uwlN+urRwSQPmzGJkSJ36xMoG8SzKHfbCz80rSGmnO7eRKnbPQZ64jXu8t8sxIUqEU5NKAobe9kEQ5FhKp43opWnCzm+0obhxQwjlCY6xUgrF+gv162pOAaK7g1bTXTG7PNv2UZb1Lu03yxm2bc1RIDqaDh/jJv62+2tYzIrqJV8hpWc+TInY9BzZXAnfNyiAu++QkxfIh7CZdMwBuMWtEY8pPuDeNs2gR3UTKsSeQf3Skg8Xzn094tTQtAwjPCm4FQzDJPRUdAKQbO4wCc7kVvEXaBUG7jqq1BsCQRkXLu5iQ/OZ7qeAZkIkp4OPzpISgfh8vxCO2uQUbPIj9WB8QHfkNziJE7klekmPmy3GNknU8L7exxpgyH7mv87SwaW7fh+nsL1rGs6gJRq5IvYHHx1ZEHws0MX6UMbs66aS9cPVFn5Ak554/eqfnQFBVUH7PpwvpDmB38ZtQ6nInrWDVmS7lWYC3P4TtEAArZqceEUKlNLj00N0gG92t7uFWizWu5LBJsRfdiQc3sd5pFHY6RoeGIEyxlaBh2J/Djhygs91J+m4s3OqyMNDCXdjostNEKHQhO13HY2zx0cYTanQ4Rk37NHDLdliN6uQF/bLbymu3ehCF+FxIH3rEj4ZfmmRTt5T1OveJMM5fXaVVQGOZFlrT4TxAD859xO2UlzcXBm9Ey2tdhtbAFAiO9a1aX9rNsNuOrVyUMC+VTCpd1tBvPQ9hwuhLpZ/YXYY6yBw0HOZXYeatmNTHeQTQo5izUEO7k2j35TsJymP0BPRqj0PC+M40Vv3D44UOwtoIWnvhUKdtQivHXWLQgKKM1AnpR3vlgzaRoQqNwgxgPmSXOsq5ZJRYKjA+3tqKH8EeiOhF5/KK/Gl3UblRSzN1KyqB1JZoCKk6k3eUYTj+kxdzEKWZSyDjixI4APhFwRU776udQV2K/qS+00QFU05ULVzpxNmNx18ngY7BpniAt64tmt/ShHy1K9MG09svLsg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 837c8664-ed7f-4aa3-3eba-08da0e947dba X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:15.5527 (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: 7ufCMsfhOQzFXeNU9HMLCu4UZXxfJGuQNBb115cQD64CysK7RtKVRaA9GCYrCeVBUqHk2WbOrb7oERsA6w97Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: uohxVOiuhj9vdMpQDzLk-5TDIVgcO6z4 X-Proofpoint-ORIG-GUID: uohxVOiuhj9vdMpQDzLk-5TDIVgcO6z4 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 | 23 ++++++++++ hw/remote/vfio-user-obj.c | 95 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/qapi/misc.json b/qapi/misc.json index b83cc39029..f3cc4a4854 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -553,3 +553,26 @@ ## { '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 +# +# @id: ID of the TYPE_VFIO_USER_SERVER object +# +# @device: ID of attached PCI device +# +# Since: 7.1 +# +# Example: +# +# <- { "event": "VFU_CLIENT_HANGUP", +# "data": { "id": "vfu1", +# "device": "lsi1" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'VFU_CLIENT_HANGUP', + 'data': { 'id': 'str', 'device': 'str' } } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 15f6fe3a1a..06d99a8698 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" @@ -41,11 +44,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) @@ -87,6 +93,8 @@ struct VfuObject { PCIDevice *pci_dev; Error *unplug_blocker; + + int vfu_poll_fd; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -165,6 +173,69 @@ 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 *id = NULL; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + id = object_get_canonical_path_component(OBJECT(o)); + qapi_event_send_vfu_client_hangup(id, o->device); + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + 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 @@ -203,7 +274,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)); @@ -242,6 +314,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: @@ -276,6 +363,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) @@ -289,6 +377,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 Fri Mar 25 19:19:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791914 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 9D8E5C433F5 for ; Fri, 25 Mar 2022 19:24:17 +0000 (UTC) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpXk-0007el-OO for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:24:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpU6-0007YX-MS for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:32 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:29222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpU1-00036h-Mt for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:27 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHS8fU031405; Fri, 25 Mar 2022 19:20: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=O/LD8FzeijjBHt4w2xn2t5nZZdlRJd4UWg3qtwr/if8=; b=RzRiEU/aozr7MueLCwkLzvKonbm7OH4XNCyoh9pUnnbzmIBp/W5HnakGdr9OB3Y8W1Uj zuCu/0Q7vh8J7HCFz4uC8PUeN76wcUS6bGLfd83L68E84LHcLbJWiQxvR+PrljkL2lrd JUHZKuDl2bFGGhddPWDRU9H10GPz9Xi7O6SOIDNfHSWfvtmxXciaHPssiMr2BYOr8/xz v9pKU3yhnAbLHpwFKYsmw23GPykcZh/cn2uLUWdR4GI0WgJD5IEzwyLjHUEtSsxkza+m H+bkHIriFKQEJEszIejMLymJkVw3YizC2zDYaVaaJjXIwmdLLmD8fukMxUrgxKI+Dd3Y vA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80] (may be forged)) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:21 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGEpm043625; Fri, 25 Mar 2022 19:20:19 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2043.outbound.protection.outlook.com [104.47.56.43]) by userp3030.oracle.com with ESMTP id 3ew49rgq7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xbj2ka5ZwEHBDey/5pAZujpyzCtfTa3Zej7vANfKrJneu9r9/lTNrIvIQMkbRAG+bAVNsdWlN8vQ1rOL3N5Sys0NFOYejtjjBkTqhLasN2XMhjb+DzmcnmTtGxGVxBMDTrQWpkwaPIGWwT/5/5q5ro5XCbLkHHcxAigpb7JcAgRN9YaLSPoilP5BiS7Hzv+pWZh9JhFaaT33/xX+hlWrnn2HV4/WiYkBuR10kx1XPuZqWfhyFuRlBcJC1uh3k5842/g4V0B2dJcKjjh1n556FviDcg2GQfODRAAGG8nJNpFccpMsCnvLSnAF8f9YGIQV9C3E4S0yspk9ITo5o1PZNg== 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=O/LD8FzeijjBHt4w2xn2t5nZZdlRJd4UWg3qtwr/if8=; b=GIVGG1Wq5G+BuHcw68s3nFSV6Ms4swGg4nOln3+PewWyDxBa3yx2UP62m9vb6iTwyoESmKi7D0nf9+UoZtpEkoX3xP7nY53LcGTIwgIv58gq3X6Zz1t40/zoBrql6iFU2PyZDqsiNPat8l9n8gA/mMsnkxs4yGWv5Tr9aLOpfzkSJxcNOT3RvXLZsYuy+i95FXG0dE9TajVLPpdC0P7O4JTmZDSTth239NDpibhHMb9WGWQYH4TNrqGQpBlQbZfu1V0sFFzpnDdeH6SFJVNiObITeT3tpEcESiqHoSZ9wphGj9I5xyjE3p0T7sQYxI31HdhGnSOrFAiXwJbbWrUQMA== 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=O/LD8FzeijjBHt4w2xn2t5nZZdlRJd4UWg3qtwr/if8=; b=KZQ/j9zJZhtMQPu/lWq836rpDsKSU2BTmn5A44IRfR8si2S+qmiM39EM3d8aOREmXwxu/OB4xC+0HM2nCxCLbBWZin4ddI2sMcmsPRLJ8m9Ci2RkTL4nDQ/JdJ1iKXO87Jtwi1X2Uw+dtZU49JzYKD/hnsjP48a1/1WLGV4/KGg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:17 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:17 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 11/17] vfio-user: handle PCI config space accesses Date: Fri, 25 Mar 2022 15:19:40 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: d56ddc54-12bc-41fa-3d32-08da0e947f03 X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: ZzNzN5Tzrrnk3ahlg+2oRM3bNrtImlxYMMO8G4ghh3Bz4guSQuhwJwhMiASs98c6XXsWbaXl6PmO4RwfXIaPBQuVF2Uek6OzO8s4Sa2MiAqzVJvl7qwdCV/qrVqwNrNV4okaL1d6znrQkiWverxESTnnA7ufJSLfjl6mv7iLz1chF+6LXBd/FR7p58kwSHknmXLXrW+hfuFJjFASxPyvwYcO5aP8KOoekXOm6FDgmCbQhzsCC1Ut583dqbYdUH1YAqjWkAmibugcgT7K0XXXe+LO4Z9K7qyTIq5rnF5z/aiYu0aGlqkjbzb/1EwwYhU3IjbxzvuC/d3XuSLDQaW8ga8dcA4O5obq4kItrz9TBCsZwY7MMGBfYPY8qHHvVevTLmakx7vHIJE7YXI8MLQsNEaAb5mzzlFW10amLn9BnaGIqBdbjfAeZa+n9tDPBTmJFuaEyT+C1LeQvPeCyz6jgPo8rWEyWc2RU/7UBHod838YuAUD5e29Es4nL4zpBmAHxQ/HvfqJpzvQiiMwz5xHE9v1GoXGxVygc99e1ETDBj6diE7oQgWylLUuXBFFBGwj6q8jmpcRFPBjKVzk2/h7uB8IOc7E3EhaeQAGqWytUJBi79SbGcv0ZOlrc4wk9H7nOxjcPLRObPMET2TH6d0UBL2r6V5pl/JhnBEQdNHc2rR80A8k9MDNLpQw6VI0SmsJCgr3cbcfKDNCZIvZyguYOw== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3LinSWChY/RMhD11gJUjQHD9I3L7Q2J0qViI/hnuge8+KvK68LMsaKReenUog3FUGI9LxQZQV29DgtFFrogYP+8NG2OjZOFTHZHNgz9K20VbFdaiukRwzZojVmbuvuCx01iNVn1iT9955tFqty6P5adRKZ+wSZRaklbyd8NTLTPGC3gAsmnXYN7KE9II2yAJkzCJX0scbazt69tJ+xm9WWXBksYZsVde7f+Zx5pnVUZxu3w6DHbQV+QYgjDTkUpE93uAluz5DuHInt6IY/BF4qAoEwSs0xFIhpR9hPfQ7Pn4+H1VbxengNKXN3j9/I1x8NtMS4na5Np8GsGTvVdNhQQgnTKE+Igv1GdXkX7RP6cnO94JfKgkI9RAE+CGqS53gkHMHk6r2q3eEFgltD1Jjj4uy8uQN/njfFuJP+D8ck/gYQDMdMmaRqhpQjDwKq5IjYcfIIReUTwpLOdr9tTOJD+rPRX7bgRNcvwx0nw7EBXZ0bQKD7M/tDP3kpDRSWCXvK6wXlI8abKUXThHVikytXX9ob2InXZBLDM+wMs2IWL1CcIvXcKAWMb0q4NMw+2FEISc9Uugc40MZa5TpvZDIVeMWD9ZvahanWR4HW9z9k5h3RFApHSdaj1jrPIKwn7rEIuuGYDRTWbmiW7Eae5CvXCLeRtkg/0oS/DoSxgIhkdqt72R25miIMEd8ZVpKQorwnpc9XnDS8EbgYcC5KEphqTN5dsHmIPkT8d+SzHWGVpqvuxE9gfboiQ6aTPaXub4N1DKo/Xx4owyzErHIO9YCGkBl3FEYoslhJTdnbRi8eSyuCGFMsIOQp7I7XauIPKpvdQ99qJo+edXGzdxwS/PCWfZtSdm4mSIG1vRpHpuRlcBNlhYWOLJn0n6Xdp0fQhVbsOb7kNAQcHTFG7OkUfT1hc26TkujM+1BeEpmh+d2cx7tZdxCet1GXtbum9Wp26xswJgHY0y5HLWjtOIGaYvhHEpsKj4cH4pzPyTNqPBqjhxLjBYOsvSMnjvZNXGEC3oM73dNWp/jZUHfPGmuJG/rCR3842NyEiiFthGjvgaWQ5htYZbbXzXpRQCaPqqQVyBfi67EQOUm55STfrB+CNKX471Ae8X1Lu+e5FOMcL/9brsMC/ZnXRb2R0suEkh58Dt29NhjeXhw5Tl1UsOcgFMSQ+7PdO0gtGoS7Js5f+9n4PikxYro+uR5/o5kbnJ9LSn4oV+rwUEfmiZOF+kiIrcTDXI8f3BIU7bUpfv/8XooWQXhNp4Tg8Wn7G5ph6quvGfiApuurCKWiQRszEK5lEy+Xvsm7BNlGxXEwBuU9z+/2hQndRgeOcMf2Y8wJOc6C2VXhjZyZh9+0pfV2x3wgyG6AoMG3G4fwVMLaoTf4ht1E+oJHUXy5KjPYxdIirZpqJSTGfoFCNNn2+MKviUnsN/TOreXOqP7d6ZxpsgCbEktWslspMbB3z1JDGcCJ+w7MB6223wlKw5ZCon1J2lLF2fbFpai7F39iYMRzUcE+ydQhoU0beU+FlyepJYkVCdB8JVDbmYzQ4b6KbrwwURYWrb6Kjdc/nyIzfqQ4W2Udh3kru6oXFDZDZcO4PNFGpyXmu4LJuSspac2tC4KTLtPIPhb9+tI8Bykdit9WOjsvNx5ab+ucHnHdlsfMf06PMdIh3oAvAywu6JNgLVEad2EgRINDHGM874KTRiqDON04brthC7G7m/IYud/b+FNVly3bgWOfIdZ4Xxvvv9zH8RxOt4kRukT/GfI0SVQYQZCNQ7G2s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d56ddc54-12bc-41fa-3d32-08da0e947f03 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:17.7088 (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: o0LGSjazTqAjAhdc18/EFpMh72hc00LFs5pB25wSN44+iiemfFnb1XBWYXRf5tmf+6cm81RzjDyDcFs+H6HOLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: SxQcq9lze3_h4RXZdFGlN0csVwqSlNY5 X-Proofpoint-ORIG-GUID: SxQcq9lze3_h4RXZdFGlN0csVwqSlNY5 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 06d99a8698..7b863dec4f 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -47,6 +47,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" @@ -236,6 +237,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 @@ -314,6 +354,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 Fri Mar 25 19:19:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791965 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 7DC24C433EF for ; Fri, 25 Mar 2022 19:36:53 +0000 (UTC) Received: from localhost ([::1]:37962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpjw-0005k0-Ky for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:36:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUH-0007pw-Am for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:41 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:33994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUF-00036v-Ay for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:41 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PI9MrD000421; Fri, 25 Mar 2022 19:20:24 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=KAUCqMYKFGzPIrC+n+5GA83VbZw8TVXWiiajiZOyadE=; b=waq+PFkojraRhp45KPbHU7aEooOaRLhJ/kr+qn/nbXxF1FRcbWY+3k87TYqCGA5EdCNd ODmx6g8xmAp6ZMY9nQP524w440lAFVO6H6sUd0RcYH/CIrsXiiiytbgAOZvw2Um8xj44 ez400cy3HMR+hq6PP/I7e73THhvn8WKKP6cy2VGrbbdyFo0azmU5GSttY6VYKGznujVh Sey7zN5Ey8Ao3gzVjFFik5WMPp4IwoRF29QPSApIAnZSU4oqdlvQ+SRErPs1J4/46P3f eIqlTAffzpGn3xrTwKpjPoMZ1ito3HbNKa7wz4otB+oAsjtj6ioEC9Az7H1dVAmyGfuV ZQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew72aqns8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:23 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGr2f125442; Fri, 25 Mar 2022 19:20:21 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2045.outbound.protection.outlook.com [104.47.56.45]) by userp3020.oracle.com with ESMTP id 3exawjj801-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jszhqgD4jLZuGb7wmwRKDvvByvsZQDJMcM+zz/srBNw5vWjPG+oWWaAc/N/Macda/9CLSzm/ViXuDxkwusVyuWlQMrRNZIjgAsx1Yekaz/HtIHXHU9G5MIiXmy0n18cptn4xFlsEoGCm78elMPSr+VRUJlY6z6EeOjtMdbEXhvInXiHzus0r7WDG5a3TaGoEg9+52411wuYZXugsqCaLvelcYR42xbLeUNLn5qCz1YYohhdNBKdkRqk0NY6RYfjyz63meh75zR8kH4kcw+yf7J9cbU4D3FA3avnoK7wRvxCwJnlLRWpi1g/syDO3Mdg4JRKC8DJLtqVokrJgosCiOQ== 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=KAUCqMYKFGzPIrC+n+5GA83VbZw8TVXWiiajiZOyadE=; b=FVgni14myN+otXSwpmB6nnffkYIEtaV7wXxWtvqWE2Dvk91ZbandXviiXKpm1R+YpNupai9hra71kO9xkYmE5Xw0NNnCE7H7hT9Z5u+ha+h5pCQQhLBhTqbVXP50fes6rmsN5j2gKNXcsRwtBTAp8FN8c5WXZiIs1ZP9j/IDsc9hUSHEX9FxbPcVim1s1uDZZLe30Wp2C8rCq/KkzK4wy91y/DbQxf9GRpTXvO8ov68qGzHjzWHhplr+GHFzIifHTMIrhupImg3d4G1ZI9K77E4zUdYPXVDKRSjNFY1X7/S+jW0rHHoX8mZEfasJibDWNXpAXSaPNYomSshXBB+83A== 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=KAUCqMYKFGzPIrC+n+5GA83VbZw8TVXWiiajiZOyadE=; b=F3ldANRVDYfuoZo0wOndV6+namb1Q5BY5k/Gav47YwzDIBItD3Ve9ka2OfmWSEsQ2X8n97qRA2qphwiV/vT4fE1cQxg2jcFx7NwxT+epgH39+BzfLdD9gYk6CONVOMeh6Np7Wd8T7lNLq2jTo6QWm5RBKvnzgEMon0JeTXNjDjM= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:20 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:20 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 12/17] vfio-user: IOMMU support for remote device Date: Fri, 25 Mar 2022 15:19:41 -0400 Message-Id: <2fdb90acd40a1f79d571d4e68c56e6b08aded60d.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 6c703a68-5ebb-4b45-004f-08da0e948051 X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: xRhL2iSMel1+Y0AgH2FinAlhUQcf6bw0gxCNre/Nw8wMwNfqQ2hcXgzFHp3ORGeYbLK0SaEOWzX3qwtimt+lYuiW3Sn7ChRBJCxln0euAmkeuUyPLpD/xWsn6FxkoH8KqKTPZ5/U1onshEGkO4C2IY04VlDeTSQvMWrJWeexP2BwamuQzfE2kLACg06yRbYSFX4OwHmqZH3glQqKAMm04JWM+sIwUhTY7Qjbz6ltufdn0hqofJyo4+10JcrjDYr1xKYYN8Ut+MdkkankQZaonF94uhavvaS7Idzzg/wIwQLFm50ZFlWAohKD4v616hinT2Ta8Oe4p+Gjr1klHfQexpW9FnNxGclXVPKvE5orbLo0yXv3+qA8MuC8rlzbYqE0UTcJsb5aQ2wok2b2weG9FdnYk8yoDwStDG5cKsmU8GapcqwIEj3M6+xbEjw+R0T84t2m6UFPHxlcEV6dS5utaYxYk+OrV7Ip0u847rJht391RU0q6YFVQ4qpL0XfBGrsf62ma0v4nVokvaTSUSgk+utZ9gtHd5RjHX2XcIbYwTg4FrfbRSSw+FS4RFy6zL7l429SdmHGA6zWNZEcs6fky9CIunDKGFVon8G6IvPxhgXkkO+bP2GnPkYzfJoFm0r91H1cILv95Odfc1UxeGW+izdUM4inmpRY0R4fp7Py5XX/EWfJRW4EocQhPbJUabhykag7EVGxx07JxzmCaW8TJQ== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QG7/yWm/Xaa79wXyCDQkyyPQ8jCy?= =?utf-8?q?tRdVqIrwJ1bC50oyNQxtICmO8e6qFA1jVFAs86sjcjdzpHN00sFcfXaL/c0ZjPQa6?= =?utf-8?q?Ll2g0QAYk5cdBsFgkY3rrJJ38SI8jV91OZXiZxR1v6bxmfu6XvFIBgpQiBrkrrbn2?= =?utf-8?q?94F6te5pHXf5uI/YU5KE7XQqEqQtpxLbdENgfdYkxbJPpBRdZzJmx5mxBTmCoySVk?= =?utf-8?q?3N7UJe1TYE6IXgx5P791vPuKmlkOD3Lz0I8mX1wsNJSJYOitxxADiWAxZOWIKuGps?= =?utf-8?q?Lw+dt/3V3q5p3QU2YnWPBQeh+VhRL6/nuuJAW0FvG65FpghfLGkQTITdzVtPLuITm?= =?utf-8?q?2ErzySnSmIdZbzXyLXgOo9v9KYlN00N+CQtbdD/cwr3VTSUvAmmYsnJDbygY0N4QI?= =?utf-8?q?/kaTKaIauK4B8hlRrIXhlrsFctIPaEmxJ6nWMjTaYGGH7f7mZM0s6MLnyYJac2Ve1?= =?utf-8?q?XaEjaIaAmyLzzPLrOzkN2g9f99mIFpbJ/WiQa/XaSEyDKnrYGmr8lGfKSgGL36pCC?= =?utf-8?q?iTShSk18YQcWY4plDsc9LPumVJgAI6Xzf44VrkJ8+8WQGtmLaf2MbJHhkl+FyLKjX?= =?utf-8?q?N/vH9sZQ8738EpDdjsfYBz+LHtScZINbvVB1LiKxPRC/Sy9sLb6hdwXw09JzoDmqM?= =?utf-8?q?kVzLBbMPXw2dtufq8uWJU6DPEhVdvftRmNdzj8XnlNg2vYJxO7Jf37q8Img3iG5S6?= =?utf-8?q?wCJEgSo50NVVtqQqhQWaJ8t2GrV69u83fSky1o2cLFUF5W1eDXAX1j7xwGlU/qEKC?= =?utf-8?q?JwQ1c6oIS0lr8TLpXiNnk/0or3SHmDViKDHSpajz90MEvRyuzZ2vYuB41qrS0JzEM?= =?utf-8?q?nq//9Gm2Loc+5DKl7OxglPcRvluRBKOEIN+hk5UC/JjUi2+1cWqvhAmvl7qm0h3yH?= =?utf-8?q?xz9YTGSoV/Fsx84nTd1zwAMU5fJNKLEKuelDxh/n8wyWmA8qhVHXgQPywOUeVwAJg?= =?utf-8?q?WxzuD04V5agnBNn0b5j39TOc20CtPSnIvCs7COHm7C8H/4KAYpsll0tob6BlVgXa6?= =?utf-8?q?IU+YcQtOA2JNAqcdoB4s9XRJbdW8EdhGtkgURbUaIWLyN9bAlVyz/OIUfc3eFxXE/?= =?utf-8?q?1pQZF1pfPjwdhUxyzu8heDh3Cs9foqUviT1K1Fje9Po/tAgo5Qs9LSJuslx/DTYFk?= =?utf-8?q?IalnsMrLsi5WMyf1N3aZv1Fi+Xec6ob3wtERypPgBgsUaYF/XVEy5bbgl0UTeuxDP?= =?utf-8?q?jnAa4bT5xdpVuOKGWUAaOvqi1JnYWSNf1NfMca7QClVurWlcsVYcC14zCJ9dMknzt?= =?utf-8?q?qcWTWw1iY23cM+AahL1ckjfjYCStc2M1LpVttLKbBBppAxk9YM62OtDo6allRiV6k?= =?utf-8?q?tqRMd6hwPc/gxeZnLvMBF6TyX0rp3GJq6Uhfx7s1VsSFvwjFfAt+cs1dpQlbVQjVW?= =?utf-8?q?vS6QXNOcgbCYMV3gLVpUf7ysjTBA/pQvu6hwgnAUIpQPOTLYcFq3jrNg+doh4llue?= =?utf-8?q?Ce9C98VM6HgkEl6ct5yjpNOT+wUcRc1kNpcYxTo3N930oQgsBRLAq/w6oDdG3H8aa?= =?utf-8?q?kCczWENPxepV3vMMqEH35zsLZJrhSKGNOBpKYRDA7Iwi4LwrIQXOfe7Q3Y0sycY+x?= =?utf-8?q?DvE9lz60VGZL4ploDaMvgLmWXy7bAQVphEC0TatRngWaMhdTwn4Cy3ewrTgSYMUEv?= =?utf-8?q?4lTnkwlL/u/OlouH6ACWJlgFcT6Ry79rklGJhvXB+xs8ue9ncC0ho=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c703a68-5ebb-4b45-004f-08da0e948051 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:19.9118 (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: uAX3NoKEThjwQabJP05NDMBlLwva5QkqwH4EybclvZDyLz8TuP1bjZv2WytTj6GbOXk6Y+CCVf3vA5hqj0pOBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: ENRtw5d64bn9I6lwOx0lBt98g6XB2uwJ X-Proofpoint-ORIG-GUID: ENRtw5d64bn9I6lwOx0lBt98g6XB2uwJ 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 --- include/hw/remote/iommu.h | 18 ++++++++ hw/remote/iommu.c | 95 +++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/remote/meson.build | 1 + 4 files changed, 116 insertions(+) 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..8f850400f1 --- /dev/null +++ b/include/hw/remote/iommu.h @@ -0,0 +1,18 @@ +/** + * 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" + +void remote_configure_iommu(PCIBus *pci_bus); + +void remote_iommu_del_device(PCIDevice *pci_dev); + +#endif diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c new file mode 100644 index 0000000000..13f329b45d --- /dev/null +++ b/hw/remote/iommu.c @@ -0,0 +1,95 @@ +/** + * 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 "qemu-common.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" + +struct RemoteIommuElem { + AddressSpace as; + MemoryRegion mr; +}; + +struct RemoteIommuTable { + QemuMutex lock; + GHashTable *elem_by_bdf; +} remote_iommu_table; + +#define INT2VOIDP(i) (void *)(uintptr_t)(i) + +static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, + void *opaque, int devfn) +{ + struct RemoteIommuTable *iommu_table = opaque; + struct RemoteIommuElem *elem = NULL; + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_bus), devfn); + + elem = g_hash_table_lookup(iommu_table->elem_by_bdf, INT2VOIDP(pci_bdf)); + + if (!elem) { + g_autofree char *mr_name = g_strdup_printf("vfu-ram-%d", pci_bdf); + g_autofree char *as_name = g_strdup_printf("vfu-as-%d", pci_bdf); + + elem = g_malloc0(sizeof(struct RemoteIommuElem)); + + memory_region_init(&elem->mr, NULL, mr_name, UINT64_MAX); + address_space_init(&elem->as, &elem->mr, as_name); + + qemu_mutex_lock(&iommu_table->lock); + g_hash_table_insert(iommu_table->elem_by_bdf, INT2VOIDP(pci_bdf), elem); + qemu_mutex_unlock(&iommu_table->lock); + } + + return &elem->as; +} + +static void remote_iommu_del_elem(gpointer data) +{ + struct RemoteIommuElem *elem = data; + + g_assert(elem); + + memory_region_unref(&elem->mr); + address_space_destroy(&elem->as); + + g_free(elem); +} + +void remote_iommu_del_device(PCIDevice *pci_dev) +{ + int pci_bdf; + + if (!remote_iommu_table.elem_by_bdf || !pci_dev) { + return; + } + + pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), pci_dev->devfn); + + qemu_mutex_lock(&remote_iommu_table.lock); + g_hash_table_remove(remote_iommu_table.elem_by_bdf, INT2VOIDP(pci_bdf)); + qemu_mutex_unlock(&remote_iommu_table.lock); +} + +void remote_configure_iommu(PCIBus *pci_bus) +{ + if (!remote_iommu_table.elem_by_bdf) { + remote_iommu_table.elem_by_bdf = + g_hash_table_new_full(NULL, NULL, NULL, remote_iommu_del_elem); + qemu_mutex_init(&remote_iommu_table.lock); + } + + pci_setup_iommu(pci_bus, remote_iommu_find_add_as, &remote_iommu_table); +} diff --git a/MAINTAINERS b/MAINTAINERS index e7b0297a63..21694a9698 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3599,6 +3599,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 Fri Mar 25 19:19:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791919 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 271FDC433EF for ; Fri, 25 Mar 2022 19:27:05 +0000 (UTC) Received: from localhost ([::1]:40770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpaS-0005Ff-6J for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:27:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUJ-0007x8-E9 for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:43 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:37060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUH-000374-9r for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:43 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJa1Q031491; Fri, 25 Mar 2022 19:20: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=cUbEfvClLTx4z5tU28fT3ty879NC0vrjYwLEnf5bLDM=; b=EnMATo2SBBLhY3algQ2f+n4JOBqgPT53FwOblsQW0jFVq5JAoupY6VntRPax9/iaaGYX izTO5Ge/FmppzXlLHRjQSr0/dcLtih3oX98WPVkoPs0+GeEh8aCdcIbhLwm9BpJjHUlE M1iYcHkZIJSJlYNJWLmkibBiXggcUUkoucJqGBCUwYHWExNnlD/YllhR1JGaktkeSbgE cU+7zS+zyAllHLht2wLGZ26KjFBtkYNmpj+6ytg5A4wBYl5Tb53sPaK8AMKuxHAGyaZL npxoPRv/wDFL+Q+Cpw/g0NUfHPrxCFnOnUsXMUebfBMxujwosPqQ/ae1o09/YHuRjdva HQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80] (may be forged)) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:25 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJFU5I043047; Fri, 25 Mar 2022 19:20:24 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2044.outbound.protection.outlook.com [104.47.56.44]) by userp3030.oracle.com with ESMTP id 3ew49rgq7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EhQ460Avn+EmFL+nf7EhU/gEdtdhm/zXDh2l00lzmWYJGVK5i4q69wCGGywOk4a0zLJue8Ab87eQJTTv4pfkNy0Qrvq+bxIdzkUsTqAx06j/ER384Ii2Sajp1yLYIkunQqAstBcpXafKoZwh798IQVcBOm9ZKKxDRV0oVf9l/Tz8P96BFULBl11XY8yPnFIoZZKmJRMqCALceqOi1xEL9YEWnlGnwamHtVj8w/dAO2MaZKKusuFCwn318UwokGUrEXPKiQUOJ2I6CnJyED4jfPMluDM1cyfM64Bvs4VRgUQxQwfR/OhYLox2PhZbW2bsKHZgcBFN3/bfAeUnV/jdlw== 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=cUbEfvClLTx4z5tU28fT3ty879NC0vrjYwLEnf5bLDM=; b=Fx2j+Ot+Jp345fnnDIbGf0eA1ARClg+nX7BrxsUh8so+3YtQLeuE1o2FZeqPbqKuUvx2ZBxYvm4mtb4Z48QQCe7NL77/uY9eoyB38bgo5cc6pYZKx8r8OeeExMINtvhdWNoRPPNPJKMd4dF6oYwChI7pxe+bnFsx2rysd0fsLbAbCLHnX/DJl/JXXSYJNGJWSTJ1zaKNUuirEqIoAXKpsv7HLoqLcPt5s1mvfn4BQKNdCljLokZmXZcOK5Q9u5yus5cbKb94VeiCXFnRw14GzMIa3ATOas/dbLekOA+/Ef5CwKM0tpnSoh5J8uMjMv61o4MbYyc+oquxUWhKlwZsnw== 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=cUbEfvClLTx4z5tU28fT3ty879NC0vrjYwLEnf5bLDM=; b=MmOFQRtADjHgYm5xpyq3zSAdDoYOH10+5zmXdWtAzqJQ+7KBvlqdTCzzPQyXo2cfN0KfC+JfWqc030ej9juWU1p1r+/tjmUsktI4bfa92EBDxmozLoW3nYZi5E6jIIqaJOpxI86SFKmg9/dc6aYJANzMEG5mTm3EZNmHGz1yDy4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:22 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:22 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 13/17] vfio-user: handle DMA mappings Date: Fri, 25 Mar 2022 15:19:42 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 59a1eef6-8aac-47a1-6125-08da0e94819c X-MS-TrafficTypeDiagnostic: BN0PR10MB5206: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: DWDWU6TrRN3F5pOX71+0ppiuTt7uPkTaIiG7JmhvAltOkJH+qINvWQK5rBqXS0cWhGSO9ML7OChmPCYbiZe7ct70FL4hfxe9k8PwY6yMM0yLgNpMztTGFCSVhKHq4JFdh5NmAdFbN3VX7TkEhAZCEVa2yksq4oQOkeYO6V89SruL5Rw8RQEsgfXWt+7LHjFmBzKLz3wcYPiwTl165FWYrDVLKV+cajaOOeJnnbUnU8W5WnUybBOsglHBYUIlNlt5GKC9+d8UtwGxrBlEmSITKFmZ60LuRttlzh1SPOdgvN7+iwQRvmOStpHciMDImMwZR3aj0JLjsgf3MvKcXi9pcfcpyYPc2DZWyUAhfMj59pq2dwI+n+ZODZIYNdMXkzQBlqPh8OLyBTXtGRADYH9rYeTt3enZVAslqhqH5LcL2CS0J8ejN6c5/+nqskiSfjf12YO8inyytn6flof/IUQ9P2ODVTNPfEPyn5YOANfokDPgpp995bnzA8gDggM5ndH+9ZqcyrF4mThhOPtutNfmQuIos7QQTJVCXz87thvlO82QpebFlr8HPh1hj5HeQbvi5xqXhx8fGLJVgPRUDnIlF/Ts8W/iIVxRuR3ND8zGAouK3TEWhx51FFvxEJSVCCvjAKhiZr22k86SCKkEGKKQprL93aLAQs8BqvXKzXkQfg7zH5/btuo8KfxbeSIeEc9JH5pj5PS2TA8kgK0rNo9+Dw== 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)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hCU7Oa0d4vTZvz4/RvCF+lBGThuxMgaVEry/TL8saOvzIQi9ltQpi9vN2abpv2QiCw9V1Duysgf2unJh6xyft+9PSQJbk0TJ+TCMg9RLAfxPDOHjnZXw8vbBWXv6t2tv7FXuZUUCYcDMCUxWbeFwyGYwidOnhlrdquUBB0SB2G1A8WBCddAeLxZ43jvrynXLTNy9YWypgMZmfLpQePsk8Simpfts8qUZzCujKZohnmEXGonZJh/2gBJfuGKa8ZhOqaa+x5Nt+ONlLseEnr+AZtemKVvodDr3VdvNE3dx2YO39xgHxmAmJGiqOOCdvLCmE0hnhGR458LeTFTFQOwfiNyyXHrO+C6GejQIBZUKPlE3fCj7QpkYVhYMlD9zJesmH0K3gu7+9GrDubJXLXR2cCwq8i+bUHTU55SpVLmJba0xDQbu29lfMNUI+xLFWbJmsM8GBSCEemPoO0PQ5M+pVM0Q8vvrnFAbwVu3ZSfJ8FyR/eKt7p9vEuz1FqI2GkBBb7t3nVBaOW0h9EXgPCp8r7M78sL+G9yJPuXhr0ClMVb4iiLDPxSxxrUOKlp3Gk4TTZieABleQm0+FWQsG1NHstm9DgUtUtDkbRW4oQIn6rhITshSxhQ9Uv3XDkq3LGyn07ntKnRkKLAcZmCXJiuPrmYGYgfKb93cGzVt/uvLNlQrZPkBHtbqxb6qDy4hDr9b9X9FyiWT9skPRQcunJ02NZ63MEHllnzRqsJ1jjKAg4hqmon8pwBVPkb13VGZ8R3sdqbwOlfv3ObB61dPRm81l3jZjSng4WKgYlDhsFF4+O3Y6OYIJWh64mAEBk9VoS4GzuRaFjKETpcIDHFYYoUlcuj6A7X9NXDXH+vdN029ZY9WAVaTZs0dfFlc0QcJG/ksBDzzd8jhHAS+E+Jr5h5ibgBgf8bghima5kxQqnUhRvzDOwmXE6baV8qZvQbYsMhrDsjVHca/JLQnX6bHcXsSlUCh8HbaSurxo/xqSg5nuYMuez0WsWSai2VquzIcfvcBCh8/uz7QsNTxaI7rh19RaOvcQ2AulW78eBoSQlWwYw1GHt4fbZ9GOqYgBBhGU14dqPKytqyuXFvzdvhEL8v9vBFoMQlpOwIsU94omiSXoEOsK7L9o8hrjsvAe9FymAvJW5zd+T5D7twpsLwCC7KEaic1Qg1B+CLC0TMJgC/nB3Datcg4qO+qBdRBW81P4SmTBmKiwZmkquWOTVcrrNx2Y6pBHCZwNXEtWG3njvOSrbAUNBS+8a8M3I0H7Vb9u/5AUMPVDapD348Q4ThW+Yp44l3/3HhMujy+bP0n4MgSAai4f4O68vr1ocAoi7yVBtG8oJ1gwobVXqRES2rVMXHfEVfFh7QRcIV03ykv0tyuql+0v8mUJ+498IYigAzSOCcgoOZN1KtmWRrnRGI+G7O8aQgjnvWVkVjdXE7uxSf2ILR2sAlh0OURkHdcvdsgnXfHW5bmmNJQe6w2qfME/b79lzboiZyl45HvudvFc6DiR/kzed7d06sG2MOWzOfp4EvGabzRTZhk96pmfW3u9RpF4gNPRCMy+tgnGzLE4q+EQ40cAYmoEU+I3hzZ8xHMT5G+TjmZXrpLdEJHkMs6uRM4y6A53DYqxwYxVqgYvRH5NtFllQWNVmU9j3IeASOtipA5HwWXlkiJMvsx7B0ZIYErJ6GrkxtVQDgBwGVFDFzDaqj+oiNdetjlNABvlzfngoopgDmqZJS6xor3lt6kCcwoUronV11+ILtT+OWprrIjSCI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59a1eef6-8aac-47a1-6125-08da0e94819c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:22.1460 (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: 6Oo2RG+W98wNOODJB7k8HXjkHwVbQpXNd1CJaLt1KFwO8gX21vXM1RS5nAYzA0f4juLkz71/1vMTxiXKA0iHSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: 1KyL5JXZLC5bb6KzalqQ1qcYdOqR7WhG X-Proofpoint-ORIG-GUID: 1KyL5JXZLC5bb6KzalqQ1qcYdOqR7WhG 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 70178b222c..67801c3a4d 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -22,6 +22,7 @@ #include "hw/pci/pci_host.h" #include "hw/remote/iohub.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_configure_iommu(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 7b863dec4f..425e45e8b2 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -276,6 +276,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 @@ -365,6 +413,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 Fri Mar 25 19:19: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: 12791935 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 89902C433F5 for ; Fri, 25 Mar 2022 19:29:55 +0000 (UTC) Received: from localhost ([::1]:49506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpdC-0002jz-Gl for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:29:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUK-000802-E7 for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:44 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:42332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUI-00038T-3w for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:44 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHUH2O031150; Fri, 25 Mar 2022 19:20:28 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=dXElRtKeaVpbiR8AMSIG66ErK6bZOL7wLm/mXAkIwqw=; b=Sn8vFS0sS/8GbfJm36weViyd1jL8M3l7BLf8au1QthI8kq0YJIEuRcta8E0l6XyMXofF WkFl3+4MOUEr75ATX3lR5RGKoJTCHtuTCm4Op4mZeUnY2+Zm9HJH6CaKQzs2SheQ3mlo l7PXinUJ0C8iC5/X7+AfeN6W5AVIPtqzqX74w5ANXzlX1WeHz3G36lR6EQiJ9hPtsyey abEckT+cpCLgJ35M9FjheGsq7q8pRcuXW7QvmtZCLF/HnTKa14RwLbO4zoxhCIf4u3OV vm9ADOSbzQnB2bYiXgG8Dsxtc44MlEaN7eHfUl7vSYShll43XSbZP5Iyxp6zpVhPJXc0 Ow== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew5s1051k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:27 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJHF0G014645; Fri, 25 Mar 2022 19:20:26 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by aserp3030.oracle.com with ESMTP id 3ew5793v1g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hf99uDLfq6BHRnlCOyDxGYeFyc0atJSoyXfY6W1ropj1BYvnrXmoHtSoK2Eie7ekMsqSnps+UWJ8kmunmSMmBBO14l4m37Ubmw+/sjCKayx4TTSHJ9jPRrDunauFdu+Mx/2+5JqVUSAMXpKMHdFTi6s5ihsiCSxklKzg+40758o5dB7sxNfLwVRuoG9P5crelLeqBEMNYZYyfG2fzA7jHXRhp9ySfOtY5UCp7Co9Sb/RVtmpp8KEahwbrJYiRLrE8jqPjYPyRjrEe5EuNojv3DUD2x+8Z9q06ih47BYJeO5AJeu2qorBhpRB0JIqYgYzAlz0XCDygFq2u9En2Gfiog== 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=dXElRtKeaVpbiR8AMSIG66ErK6bZOL7wLm/mXAkIwqw=; b=l5oUug8W65nSO8ZHr2DFGicUtC91dWAjhbRcGm4fuJnd8UOEELDxH/Stay+kincvmV2oJqF+rNS5n2FSKcRWfTfqACy6I+cg3Vj9IibkkWgGmcyg3oiqPQnOneR+lLHgrgv7SxHTuB9wN03vphJEX7NKKieBvd7La+wbvxU6zFsTy+FfaCu5bz2rsYvyouWw9r+bfF3qxypfTEA1kNoUQluQgq/6EqxVczSNOmX/j/iZHRaSenfkL+eMGwWHidYO/g2mRs/4UraolGZ5dophDeTQqYLpb91dK08o5H/lRBdeBuVPBGF/WVnQoXLL+vrJyaebelGHRjyAwV6a6wLm/w== 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=dXElRtKeaVpbiR8AMSIG66ErK6bZOL7wLm/mXAkIwqw=; b=JVs4FCiEnEM7m3+D4oP+tzAX2fG1C0s8qzPOdRgsjbcJKcgtvnKbcd0Zf6hy5AhdwM3T7hfmHtvnIuUogWYDRvHMTiwzzimj430eaJP8zwTE/t4PjQCxd+hFiQuzDPEtxwdpdbD8MIzuhlBxghKruhs4o5YVgkA/SQ5ouOSSPOA= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN8PR10MB3729.namprd10.prod.outlook.com (2603:10b6:408:af::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:24 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:24 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 14/17] vfio-user: handle PCI BAR accesses Date: Fri, 25 Mar 2022 15:19:43 -0400 Message-Id: <1c2cc82cc72964216fb63270805fefb095f4d4a8.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 50ec3704-5245-44a2-ad72-08da0e9482f3 X-MS-TrafficTypeDiagnostic: BN8PR10MB3729: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: CMZ8ZfefA9P3FWZ6RHylCac26IM2JkhaIspFEc7c2/HBVmz47Y+MsI7MAqyDfLHurqkC+xAjztCvnCVUD31VrvBQupgwFfk9uMZT00+ljVEn7TbHDyzFZylMsmaUpQERvxo8QjtiAMPw40uz7j0ZhaSoYPZ+Se2lZDmgXbvnXsPW0jtTIAsXyoKw7wlITdDBGrqVn+9thrFa81WAYAIYdNlzku4TD/hE5ePJm6VaeSoz32T6unktcHAkuvbITvlxFS1BL9v4SyamX8oGixUNW/8EN7SgNThE02hEdMsoV8y/CYzw1lsB+EH3lVHb5O8zIRqX5jdZ+hpeGL5u1EjeVNZ4OTIy/Isr01t4T5h3itR0Vxq8N2cs4J/fQGiw4SM441GqJ2HQ3AlZhHp8rIkZl3GOrr40BYfO2VBPVjxIBDO9mnR0OvV7mfx/CtdaZMf3Lzapffi9I8lwnPQF2ZSmLt11kO/G1Qez7Yh15Yzq7tGMFEurXbhh21d62YPotIaqEjo2biPngvdRglgOSg2hYVZ9iudCQOPNYehTOAgjGTTByGT5oZylpkXoSEk8KbHafXildCPCMwJa+zZoge/W1847KATKLwv5DLGiSOtyE/dhg9AaYvJADyzSy/natei0gtSnILNCf+FvpOQ5rqTJWxAMkmTx/kWHwnVnQVUcopk4FFpgDcjOJIOpQkKq2AxrQlgoW9FVFJMaxoOQJsixzA== 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)(107886003)(6486002)(8936002)(6506007)(2616005)(8676002)(4326008)(508600001)(66476007)(86362001)(6666004)(6512007)(6916009)(66946007)(66556008)(5660300002)(52116002)(2906002)(7416002)(83380400001)(38350700002)(186003)(38100700002)(26005)(36756003)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GepRCunmAng6+CaYZ5ePsAh+6CAXLppcsD7T3l/t+lVRsP8MCjqrYFdJiqAKqkS4E2Ttp4kNkRSZUQmQ0QtZy7DcpdjbXXMGZo73aIcPA5cfz6VU3zLswDz41nBsjPcI4F6cH1YuIr0shyyodFLFBAlbJvcg/Pixl8v7HYTprRvB1JSWCkGvvKbjOZmlwagJD83IZQlZz9Ctmk0G2eTtAx8BfFFM4hGZXOca9x4HhaBF2FWcCnL3zV0hQpzrXK1hW6G6RKRnwiX8Y5GQqk9wtB9UEqL7Z99ZPNpPbdq6CJlArrc8aD5FjzkjlPjetu6rDeokZZF9cXdH4u8bN8tgZcZN0h20IZEcJNK1+4AaY0XDeoxG6SP8ipbyCPVEZDWbMg22kIoRhgF11OW0V88h5hztx21/zwO8IJeBkzSRt6vy1qqtqwcvFMNof561Ab4oCFD9bwnXv1mCH0NpJfThfU/sQnvekW/s1sa5dJY3YA22vHqdQTqDfiFy1BCT2lQogYfOu+hxJpRY9L6m3EwXuyNgonWwFE6W7CaOuV2+gLsmkcBGo9llGXqgfCAAgHSroju2fNpiCPEfql/YIFqDbzXjvW6mqnHTEU123JLRnRiFFQNUlhrrjop3wS9O1KrA+WPZN6lNJOJd8RLgudk4oU42RuxQap+N1qQ9d8/yWL9KGHLpIiLT+Vm9yvCox3VtAykFFO+I9oOfYpUVe8MK/ja56RjYRmihZPYZ2b/03W8N9sJ6CtJMzdVmzny3GaHOA4uQdQWG8hhPtg4p3bqOTFTiQrGy1uzkZTZ+NanXQwyie8XYgBtpFcCN6Oul0YZomwPEiF1hTut+VQ+YGz5r0cFYwHB7s17fkCWXTKRlXDla+83qCUrkfDn/K8Hmj9SeYkcXaC2B3eCj3VTSgXHGSEJzKAkDVk0ugZxR/z6m3x21IdlbEcWInMw0/gaVXG+FEomU2hbM9C4n3slz3H8ZDvMb9s1eA5Ym/BpCLvJDnAWvuhcXRWFUeXgv8yAObLcg74Wf4oZHKiZ/lynCfg+yqwQ3S78mj7SBkQD4y8BgbgSp52Kij4OXqnIBAOwY/big0K7WI7d+M8CyvlHE9iPTTyP3ReONc9JNib03sNOsOb8Toj76ggBvCYzCmF1RS8zT5KBu8ynbIurjlKyJx8LcDkLlbi9z/b6WW7e8cmvUAZzfERwpTGc2Em8jGE4FDz6zwt9L8wnFPh2RRxgEyVzgiS05LVtvWKOBqoyD1uMPlFczDRFBmkYod7vy4PQMhnfFxu2b4pvA7LO86Nbi+5fvmOeO6JT6Ao58bLXsmBd6o4iRbsI56oZP6b/qFcC2LMdGRdjFuh1l8qbCyWTqCwfg9Xdn/WO0oExU+iabc+fwIhv3gsKOllSlTTfVE84tNWcq0UzHFhlu4c98+j1QIPHIRXT2gy8jHMlxcIjySkAg8HhRLX+6JlljxzZGMsPOwsCUTeosC2zZuPhu7EL53KSmaMPN5wP6a7j7ybUHxFqJaTWzQ1gaVjGnJg81az93cpS2RLUgeOLPKJwtclulMtX0jFM8Mpwev9r1sDHA+cdnsai2H4/qXuG/n2KpyZnlvh/oiCEKbCGy1SkrqduLTGiwWM3lCkbbq1uUNcM1CoTWKbX08VENE5ceaKVTkDrveEhYp0kw5pK1y4AFVIBg2LMxKEQw11EAtXohIF7hVkwbSkVqrz/a+P1ngmNUicrArJCYBivjhEa1jAI3rhWoel/JAFSzy5SCbRFV4KsS93FYVFw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50ec3704-5245-44a2-ad72-08da0e9482f3 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:24.3334 (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: ZOmdf2VV9I+hCJzNm8fdyYArblzGTfDCjgxhbeYJE3X/l9bPYFVZQDPzvBXPtH2fsygJ6x7DE8X0euNm0Ppugw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR10MB3729 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: 04tig37UFYUquRXS9_tIdvZLb0eS3XBr X-Proofpoint-ORIG-GUID: 04tig37UFYUquRXS9_tIdvZLb0eS3XBr 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 --- include/exec/memory.h | 3 + hw/remote/vfio-user-obj.c | 167 ++++++++++++++++++++++++++++++++ softmmu/physmem.c | 4 +- tests/qtest/fuzz/generic_fuzz.c | 9 +- hw/remote/trace-events | 3 + 5 files changed, 180 insertions(+), 6 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 4d5997e6bb..4b061e62d5 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 425e45e8b2..6910c16243 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -53,6 +53,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) @@ -324,6 +325,170 @@ 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 size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar, + hwaddr offset, char * const buf, + hwaddr len, const bool is_write) +{ + uint8_t *ptr = (uint8_t *)buf; + uint8_t *ram_ptr = NULL; + bool release_lock = false; + MemoryRegionSection section = { 0 }; + MemoryRegion *mr = NULL; + int access_size; + hwaddr size = 0; + MemTxResult result; + uint64_t val; + + section = memory_region_find(pci_dev->io_regions[pci_bar].memory, + offset, len); + + if (!section.mr) { + return 0; + } + + mr = section.mr; + offset = section.offset_within_region; + + if (is_write && mr->readonly) { + warn_report("vfu: attempting to write to readonly region in " + "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]", + pci_bar, offset, (offset + len)); + return 0; + } + + 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); + + size = len; + + if (is_write) { + memcpy((ram_ptr + offset), buf, size); + } else { + memcpy(buf, (ram_ptr + offset), size); + } + + goto exit; + } + + while (len > 0) { + /** + * 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, len, 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) { + warn_report("vfu: failed to %s 0x%"PRIx64"", + is_write ? "write to" : "read from", + (offset - size)); + + goto exit; + } + + len -= access_size; + size += access_size; + ptr += access_size; + offset += access_size; + } + +exit: + memory_region_unref(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 @@ -420,6 +585,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 4e1b27a20e..f9a68d1fe5 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 dd7e25851c..77547fc1d8 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 Fri Mar 25 19:19: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: 12791963 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 62651C433EF for ; Fri, 25 Mar 2022 19:34:52 +0000 (UTC) Received: from localhost ([::1]:33112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXphz-0002Rj-A8 for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:34:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUO-0008Dx-KM for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:48 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:49720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUM-00038u-82 for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:48 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHS8fW031405; Fri, 25 Mar 2022 19:20: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=JYVQewzoX+sUQJRNA1z3tNqx20vy8lzb2DxjMGniLpY=; b=UtXtqVl4z48zQKH+0WmQrt6AkCgKFqmC/SvWPMe734An5GmzGqChUIQ1iVTI7cXN+f+j /pZl2D9UV3GhXizg24V/bldcjLlzrRDPTr57GDjDScKII6jWGPIa2/71++8bNcq98GPt 4T83tnl4Jmg8OfDaNf/JKHV7m/i15IADwoGP2OTgx1WL8Y0Vn+F3BuW8zIXXk8p0GQE3 Rbaf4ZL70g0zqVeOd7Gnt+cEXB3BlOpH313hHqgRxWMb2rJ9s5myVgLciM8J31LKDz1h 4Tmt7V6WiorwvHcb9qjelcfBMOg+Hr1d2dULbpOrnjCCRhwNSYMtbf6rNo/m+5+Zj/xd lQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80] (may be forged)) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:31 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGWDU043737; Fri, 25 Mar 2022 19:20:30 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by userp3030.oracle.com with ESMTP id 3ew49rgq83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=baB1+VrF8tCKWiPDy1MKnYu6obZNTUtMofKd3kWigWG3cw5zeKJBg+kSR1gHN52XInoyiHuditKyLxVsro2vqkIN7B1q7lasXhk5XIj2hbOazZGSA36Ren5V+R93fELxfW/cW/Qm/tbR5OvGECcwTJEgLAaZElrj+fIzWZxNPoTfPmD8yMhnNw2yw2N14Awu6pUQDmKVu/9uYMiTzqHCyEwqOI12sCBe7yCGApZGet9sJ17YbpYLDKAqEizzMTADldHRNaqKszKXgqhUja6l2JAmohqnXitWFT3mjZHWYgeThZRciB6FaNyMVN/jOhci3pjM80CbWQecHd3Qabi6qw== 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=JYVQewzoX+sUQJRNA1z3tNqx20vy8lzb2DxjMGniLpY=; b=iAhsNs7nTuUzDn5IUQY/fNKq0wTwqnbfsAw+vBu4hmfvxD+2gZA81OaTSM5LN3kuJTf9KMW4bVlFejguSNyZuEljYAbaFQhtbsdyKc+gl+2Rj0kSuM4Wvc24NN1w1EYvfaUvcRH4T/wXdtdYWYmfSDSSp6Mc3YfoIrQ/nqA/y6gRMnK3LzLzKf7cBJqbcdEPWDM3FFwj/f7vGOaxMjOMNGIh0QJbw72Abh8fY5JkeCtb/k1z+QQV4UMKqhfuOMNB6t6RH7OSeWgL4d/wZC816qkPoDRTdt4rLZkX7n2L88SJ6nJdnDYIGtHH2gr3TAeFvVkpW4ajVKy186rDG3RYkA== 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=JYVQewzoX+sUQJRNA1z3tNqx20vy8lzb2DxjMGniLpY=; b=pi3GNuZ9zL4ehzrd6O+F+xUCBjEVS8Y1bCxjbfJZelWqyP5NkOtpsSu5URhrRkWgoZktuJe4zzuJMSYLuJWGa9amD9c+EkYXVsVC6501ZLBgPKoul0VHQyjf3ym9bPQtMq9Zmki6oTDB5hzPXn5HgKGLjBBK6oU7jAXwnNdL0Mo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN8PR10MB3729.namprd10.prod.outlook.com (2603:10b6:408:af::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:27 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 15/17] vfio-user: handle device interrupts Date: Fri, 25 Mar 2022 15:19:44 -0400 Message-Id: <377ddc113f35efdfcdb41066cca5f5d4a6f32ec7.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: 8c1a3260-90af-4215-6c89-08da0e94847f X-MS-TrafficTypeDiagnostic: BN8PR10MB3729: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: y6Q1jQL1GY4zxX1AcbhEVNXTwugH41n4IyrfoWT0z/F5/vZFXzpl710tcCv834ONgCrlLt4K6KcXztgLUJX+RV9BPWNgXKxUEyGWJsVJg/cIldV9M8ga9ZCDkSViNL2OuhNcLJf1AsiDZe3Ju93b/Hex4+/Sxy1jZRQAPcgssrDwtntGmt1tpoP1MaR0YJ3arYddrRdoUiMbgWe7rkfGnFqUOQpiXZCNwh7P46h2Yo0/bOGp7Jcw4Q7aPnMgqUJXVOUzLiX7zaEfE7+ZXgCt/nbfwOkpUl5AUNKfh4ZhpXyyzbsRxtMgASZ57KAkSt7GZ1mUjHLocZ80zlYGsRsQlQxLLva5e8A1mDwWnaAY7UW9whrc+NL9LeWax4uGI9iempxX7o5dmBiZjHhKBtwF2ae0pNhShx7AiPpWudpJlWpWzp0LCSTYAvEPWccH0wT9hsFpxlsQc5cYrmIeBC+kvEOlfGrBtnraxBi/bX2lPSSpxhwod0oy2y+rSDeK12EzQYNNQkg2wNaU/gIsardSCRG05ObEkmq7XVKmBsSom2JewGhJpbDytmDDI6FHWk6nXnrY+2PnHg6Ud8813hiTskOaF/OBiP7+9qRyLO/5sJNoSWWAC8Ft/tX+scpcAzDVbWtDYr2OseZ49C5Fv4bVSzBvfP/QPZxqTxaZQq2FM0IUZIfRSByhzT5/+mQR+/5HKaoObgwY5Hx8Z1Ofo8df4w== 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)(107886003)(6486002)(8936002)(6506007)(2616005)(8676002)(4326008)(508600001)(66476007)(86362001)(6666004)(6512007)(6916009)(66946007)(66556008)(5660300002)(52116002)(2906002)(7416002)(83380400001)(38350700002)(186003)(38100700002)(26005)(36756003)(316002)(30864003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wKXk1vVFBATRH5GKD+Vscj7s9hdC480seqpLTdJcR15fs5Oe4Ub1XvkFCG2iyw0oMc3B76t2LBeBmsrcYrTw5ORm4gAa/oYUfoS6A4PV6C1sjRBso3L3Mai1y1JI+CBtIbIm3D28rlQpffryIjJZWkttYXu91AEagkHxH+Sxi1AwWyJ7fKff8FR1f83siTNOWzs4Z4rXThHJJ+LEudeGDtcT1A56kakG/5YTX80MaVW9M4I1k2FRdrVtvLMPSC9Mabh1do3ILyTT3oiwpUHjKTQy8bGbmrLnACLMfiaEtu08WIRZx3o6JYGt3bWp8spKBbWtzGg3365nh0n4cmakOwcEbBJi2Rfsiim9UiYgM/E6kj54uk8wCGLTwgk8VTtUgD2Qj12vFXdEnsdH3E9dZEK23mgFE9ZwxawqCRRMhgnD50Ep/08Ot68ObRF1x+UlW6t4mcEzp+9ommlOMzCy0+OPA9lrpBdsvEQ67lKQ2s2HBRIqQGKwgnqBMpkbfPtJeixNk5x8V+F+b2LTP5vbcfEUUAzg3yz/5GuC40RRlY/iPOT2IjF5GoY94I9/Mwlrwk9fbDhhn9xgQO5foTckQytnJCe7EPCg5iLvRGZluPw9Ul9QfYSjX/itRrj21eao4tSmRuq1uugbHexHjYnLJzlLPnjha47lbgh6MBCR59e2exCrn77dW2+VO2P0QRwYMJ8frrCPbzQkIiz1LsPVx/YJPy4lcH3srx53Yh2CWS1rcfsd03PXBL1VWrOdirfSUDrQwfkGjLWKAL4hs/rk0POJ8uieZBJp339Ar44/Jn+ilJJydaWmJN99XG7c6E0thMdYzzVXGLlkxssUXuyc2p4WrCVEU5CBS/6ckpZdKKUaedIcGswBBHioPrF64B1U7dO+TFwNthgphVK9hpj+IjxzDi21HSeuIx5uP4z0DzDCWEwCUESHo7ll1P84+oq71AvhK0Mi5VS4EkQDSDdb2DUuJsuZIchf8jxCYstb3J6vYPGedsXSo8gVKUHy6BituQhVPPX5LCk+ZHiDQh/9XgS276ICIMarlMt9F9wmUzXglwrSykrar2aQGtBgOQP3Udln1bb8+uLzsEb6d5kkhSLgfXW8aLC4CPY5Fl8xb6GjNs7EQ5ljG6WIDDy9LofD+rf+ovHGEW4j7yKe43loVLx6mRh1fG+rS0K5txlfmTAH1wBXw8Z6yD88+xsQqQ8oBdOzmysdgd9TOklXu9yvfNHpM2SY5GNkjjY6+3xnF5uIpgG4EZ+1ZmcIKqEHgQEkIDOEYpBkuF7a3ZMg6ip1MbTJaqLjWwQE0pyLti1tKrZ5VUvtOJ1yVoLSH70Cvn6sqgvXuy8lPLLp/CykosMQDXmfqqwgau2oBVwQRiQItvnLzpOEbt6o1vZvwpsiRfUXYDSg4jt6zvEQDNySnU6QW/fKwgTYC0iBmdpf0pMThHMs6AatOg3QsPXHDspJk6N6FzYuRCJzmxPdUTnHFcPyDdkYwwAR3C4CVW5inKHzOYHaDPX1j/wOiVDmrTfSyrFESz/4xgzpBxWVUYMY/Wg6i94vvu5ZLLImv5KoI9BEdltHIgQ9dZkYuxMnTkUAQIR4woLgqcpCMiCR9ljZ4OmOaIqaW5jdh9JdWnzt5BnXN0s70AFiQx45t/JwSvp8N64suIIREOFAuJORR/sEC5B5iInzwe2to9cu92ja35gUDRPzetpOjRD1x8CmoRWDvENBludNezhJOKWRb9/sYQFWdA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c1a3260-90af-4215-6c89-08da0e94847f X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:26.9894 (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: bOuE0w0+RZH9rVbkOUQl295MGiaXS+dzPhPpcjZcpNpgJygNxic1QAmuf+HgPb11FliZnj8/K+ZfXARG4f2umw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR10MB3729 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: mWh657PU9_S_HGcI2zJFPyIRBWcYIt-w X-Proofpoint-ORIG-GUID: mWh657PU9_S_HGcI2zJFPyIRBWcYIt-w 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 | 10 +++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 11 +++- hw/pci/msix.c | 10 ++- hw/remote/machine.c | 14 +++-- hw/remote/vfio-user-obj.c | 101 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 10 files changed, 155 insertions(+), 6 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..fb8a05ae25 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 @@ -126,6 +127,8 @@ typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, 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 PCIMSINotify(PCIDevice *pci_dev, unsigned vector); +typedef void PCIMSIxNotify(PCIDevice *pci_dev, unsigned vector); typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ @@ -321,6 +324,13 @@ 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; + + PCIMSINotify *msi_notify; + PCIMSIxNotify *msix_notify; + /* 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..a161a5380b 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -51,6 +51,8 @@ */ bool msi_nonbroken; +static void pci_msi_notify(PCIDevice *dev, unsigned int vector); + /* If we get rid of cap allocator, we won't need this. */ static inline uint8_t msi_cap_sizeof(uint16_t flags) { @@ -225,6 +227,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, dev->msi_cap = config_offset; dev->cap_present |= QEMU_PCI_CAP_MSI; + dev->msi_notify = pci_msi_notify; + pci_set_word(dev->config + msi_flags_off(dev), flags); pci_set_word(dev->wmask + msi_flags_off(dev), PCI_MSI_FLAGS_QSIZE | PCI_MSI_FLAGS_ENABLE); @@ -307,7 +311,7 @@ bool msi_is_masked(const PCIDevice *dev, unsigned int vector) return mask & (1U << vector); } -void msi_notify(PCIDevice *dev, unsigned int vector) +static void pci_msi_notify(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; @@ -332,6 +336,11 @@ void msi_notify(PCIDevice *dev, unsigned int vector) msi_send_message(dev, msg); } +void msi_notify(PCIDevice *dev, unsigned int vector) +{ + dev->msi_notify(dev, vector); +} + void msi_send_message(PCIDevice *dev, MSIMessage msg) { MemTxAttrs attrs = {}; diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331cd0b..fbf88654b3 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -31,6 +31,8 @@ #define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8) #define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8) +static void pci_msix_notify(PCIDevice *dev, unsigned vector); + MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) { uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE; @@ -334,6 +336,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, dev->msix_table = g_malloc0(table_size); dev->msix_pba = g_malloc0(pba_size); dev->msix_entry_used = g_malloc0(nentries * sizeof *dev->msix_entry_used); + dev->msix_notify = pci_msix_notify; msix_mask_all(dev, nentries); @@ -485,7 +488,7 @@ int msix_enabled(PCIDevice *dev) } /* Send an MSI-X message */ -void msix_notify(PCIDevice *dev, unsigned vector) +static void pci_msix_notify(PCIDevice *dev, unsigned vector) { MSIMessage msg; @@ -503,6 +506,11 @@ void msix_notify(PCIDevice *dev, unsigned vector) msi_send_message(dev, msg); } +void msix_notify(PCIDevice *dev, unsigned vector) +{ + dev->msix_notify(dev, vector); +} + void msix_reset(PCIDevice *dev) { if (!msix_present(dev)) { diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 67801c3a4d..95f97ab268 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,8 @@ #include "hw/remote/iohub.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) { @@ -53,13 +55,17 @@ static void remote_machine_init(MachineState *machine) pci_host = PCI_HOST_BRIDGE(rem_host); if (s->vfio_user) { + msi_nonbroken = true; + remote_configure_iommu(pci_host->bus); - } - remote_iohub_init(&s->iohub); + 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 6910c16243..19d075a9dd 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -54,6 +54,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) @@ -489,6 +492,95 @@ 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 void vfu_object_msi_notify(PCIDevice *pci_dev, unsigned vector) +{ + vfu_ctx_t *vfu_ctx = pci_dev->irq_opaque; + unsigned nr_vectors = 0; + + g_assert(vfu_ctx); + + nr_vectors = msix_nr_vectors_allocated(pci_dev); + if (!nr_vectors) { + nr_vectors = msi_nr_vectors_allocated(pci_dev); + } + + g_assert(vector < nr_vectors); + + vfu_irq_trigger(vfu_ctx, vector); +} + +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; + } + + ret = 0; + 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)); + + pci_dev->msix_notify = vfu_object_msi_notify; + } 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)); + + pci_dev->msi_notify = vfu_object_msi_notify; + } + + if (ret < 0) { + return ret; + } + + 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 @@ -587,6 +679,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", @@ -612,6 +711,7 @@ fail: o->unplug_blocker = NULL; } if (o->pci_dev) { + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } @@ -671,6 +771,7 @@ static void vfu_object_finalize(Object *obj) } if (o->pci_dev) { + 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 21694a9698..d07f2a0985 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3599,6 +3599,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 Fri Mar 25 19:19: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: 12791918 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 1D6BDC433EF for ; Fri, 25 Mar 2022 19:27:00 +0000 (UTC) Received: from localhost ([::1]:40404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpaN-000504-6Q for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:26:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUB-0007ha-VC for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:36 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:13370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUA-00038i-6h for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:35 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHI9mm010798; Fri, 25 Mar 2022 19:20: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=QN5gUsZmsVhG2Wn4x3y8/MvKgNNiXltgDD2Y1OF35SU=; b=LOWhwMoo95706WCXX7BdMN1bRkBcXLa376zWwM/ZvvN8mIUS15tAXkSTK2Pac+j0TCSo kmJI92QSm3F4wmbBnQ/o/dLdJltHHdjA/T7EPM37HYu2rIlXRWXP5y0vKrjYZbvoEjZ4 86WKRW5IQJuCSCaSGCssk4PZAgNRoilrkCh7tYsKYJYBWegEg74Itj2WlmDF7qnX4bE4 sfomP/F5yErucUYoVLvrZ2pI144VqIOz6AX8JOrF+0OikKPndmZyMO/Q1O9EaLruxMmw eo4j+bt9oSeRNlvNr7RVENr4aTOUFWd5/HmZb3a0lCKsU/em3nB/IuHH1lS+0OL4q5iM pw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80] (may be forged)) by mx0b-00069f02.pphosted.com with ESMTP id 3ew6ssg46m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:32 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGWDV043737; Fri, 25 Mar 2022 19:20:31 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by userp3030.oracle.com with ESMTP id 3ew49rgq83-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XlSyifhJ28hlXyJtsB5/FUDeZxCQwZr6XRwKI6ghxhxMrW3BaQZTAOx/wLJxpOo+x4BLp0lqbfgoNSwzzvL/A22+mhCM4W9OP7JL3k3qjbwpECtI8IBlqIXlX7PwBEhpzra4VTGR3VObiLPTpNg7iqvSLqBR943m93zi7mm6Sz7Smm4Q7Fcn/c9EeGszdXPsJBPDzZv+DCdR7l9Pf8chNPclkgfgtPwQtNe8J0U0onQTN7/2cMm0yJx2BV46h0+Xz7bfgCRAe2ADJwK2NY+kihFG2gmIxAeofn26t1dVuxr4MUQXoA62QjxhGkR7rYkQ21LYGY/6NFd1SBhh3Qyj0A== 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=QN5gUsZmsVhG2Wn4x3y8/MvKgNNiXltgDD2Y1OF35SU=; b=YaCoMRfToZyWETsq6QYmY3bSbqxN4H2CEu9vCmROxnkq4MqIcp4yoiuss7lqOnEJCF/Bf6/Ovl8u1KCoX4MaOuGjWH96PhG1zvcm7GP/JNyaI5b1vtDtNmhXWl46553BcLuBWCXMth1QfQW5sBH3nDc7vDT0CouMZHMuL+YKtdfkFZV9o2JbuN+iwPzjWgZuX1UBHdm9g15uo8qGR623lGAhiVfilfEQjiNe3gr6Fhj7/kCWx6H74l18RJWxrP6UTDi5Dh7uWIzZO7hAxWwZVuciKF07XX5Wb4AyjObE47roqupTiVfQh2lhTp99/skmAYd9JZ9xzaqkMLfc0IsneA== 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=QN5gUsZmsVhG2Wn4x3y8/MvKgNNiXltgDD2Y1OF35SU=; b=XinfCre8XQVC3ah4GJtE7HwSBEAjf6YvzQ66lE+twGhwBvsLeivJ3HU9yHafIqBgduVYVaWH/Z5XARs/ZOopchBnpoUIMMwTryEUjx/GAzvd7hosQD0NVwBm4eoemHwCjVYBIyr3Zci2eRnCER8K45xvPmWxqMXaUF/hKWgijCg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN8PR10MB3729.namprd10.prod.outlook.com (2603:10b6:408:af::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:29 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:29 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 16/17] vfio-user: handle reset of remote device Date: Fri, 25 Mar 2022 15:19:45 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: ee653491-bd62-429e-568b-08da0e9485d4 X-MS-TrafficTypeDiagnostic: BN8PR10MB3729: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: XtHgX0SKoBGZcTAdkhLbgClmUyHEK2zx9nQnYrb93UWARcWeultm7/A91hMGhywCHFrDLHYTsbwUX/df0MBFrQBqOHE01XfSej1qfUOK9cIxEMcMTgXzXCvVaYlRK2mrcTEPXkdlQNvFxg80nEEY0+KQKzAUWbbXlSSLCnKQAuMdIZ2K9OD0YHkRUjNJYZcA4S/EPE5mNMScmWSPVAQtjToFSf9Z4graiSAXIpr6q+9zIPUDmRbjb2mz7TgwwgsKcLf+UDgs/Qb6Yrvnpw874uykoBTv2x9TeJ1VyIwR6OxHLbmd+KauWdPadvcZ9MD9NrElOEJ66DCn6uUyCDMEXgexMUEXaIWq0D1sXuGIyYLbc4i2YOQ+efWB7JLZ/KeGytXVKwTgcAOIrDmo/XMzFIeF1A7V4bdd9Vvle7a6aRShsNvQ+14QVmcUtFjI2iz0dZCpbP3jke731n3y9wlQQRNOQn60wgH0xk/4yslFl6paVsWyOlBt2mZYWTemv71QO/JLBp22qYYWcWCx8uPVq0yfJbfBmNX1FLZDqBbN+JR33TFAstyJ/xsbiHhSBsSuzQBHysbKsj57Zm5lDwWlMdxJ7cAbBiWUIV/f1DbSSZUem8W9nUSbLaB8mesh9ohfbCY86ZrAEU8lqX8vBOGIpKZ4CJMYrZqhVFx1SOGr7K6DcKMRQyRP+21jSS373Hb4LfPScVYxOlxPotmHPmGYDQ== 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)(107886003)(6486002)(8936002)(6506007)(2616005)(8676002)(4326008)(508600001)(66476007)(86362001)(6666004)(6512007)(6916009)(66946007)(66556008)(5660300002)(52116002)(2906002)(7416002)(38350700002)(186003)(38100700002)(26005)(36756003)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IbrfY5iNshaBtZ58vh2R6puoUET+vIHmQTu63y3DPJM3wtXKH4+mtwtRBOBPk3JFmb0/07WzmGTqzcAkYmy1jE8e15kkBzQxaNig1pwOjpHhEuOR44iSBP78quBLG8MmzZc7FIegseKuVdda9/MZ6Aaltgopk4KUbfTSLqdl+/B0iVRCGs61rGury7N2ZYCiOpb9cHLqjV9R3YOTgRfdcgCfb4OSUVYCKQL9En54CmXkzG5RZhoyvDeI8RTvisQv62s3CJ7gKsWM2knLX37AC6g16UOD1Tkt0J7va7ovrkPZlS+0HNzwC0SxL96gxTm5p9C4afMX1b70aqfsvI0XCwZLCj+Krtnuq7dlyCXzYL+LAb+3ALYL9NemJSRUYlnseVH++MBf21oKZZvdh0OL8Z3XslnFR/vxURioUPVOdNvhB3v78/0X4krGIUzOOAAxz/iaymhF0cDPBHdwHMPNvWYNFfEcYvqUuEAp1jhUeRdnjhO9GLyuBxAIFH+qSFyNvO2PNPu8dBy7sPa6K0FtkvxaZPtzds5IQIpBcBEXQvXk8G68LKxKWS60FVO5Udq50/dB+h3DM6HQgFNVzEytqJAHac/QoC3YTXzSYn9jtvJDKOcquyCN993tAWwwDyYDnzWxvz29a9MHOAxFZku5JoaSH0HuL0IHM7k2wJ4RZmTE1Ws8TIX1we6gQYXbSq3K32cvZUvVk8EuZOsj+2iT2mI7ti5Fc7KUojEYfoq8hRJhrLJcYF6uudKSVjDIPmlLcHyI9UtVknVolHIEcLr565NcOowwVjc3gSw6Wpv9QrJryRv1GogFE8IC5ukWlHn1YCCudSuP2OZIbb/djBBb/KmsFWOFCwpMfE4sbm6R4M/uJIee8hC7b+UYDgcdb6BeOmxEYA5FHpFUoAhf3VHSawFGHiM7lWMlO9ZdrCIBrnzYqSRlppEupEs/OzAp7BnOwjHKLtr1tIzoeRLrNq+Dpx+WwmnEha1V39xzSx+BeioBeXFylsXnszcTKPtivPhbxf9Hflu32a27i0FNjJMTCZSxVsQLPNKo4rvKs7yIogQe75LbNmsFBnSK/mdLi8JVo2cRbhKYQXy32KuHqaEvoF4RtiPiv904R4iS5JB5kekcqT0iXxIYC2DuQG+aiwK/x+DRzJUcDSsjSVySmLoymkT3w/zNhdWz4lzQ/jLc3BH9JGk4HG1nk3VPoQdM62jentiH2iQXMpo7pu6owWNZA7zI04LcXFdZb6V/pYpsNUCaVuyEVi2eX6clNsq8jgDYqdg6klmrLZF1LqhfHPtQRWxQbBe/Ou1I+34godGk5Jnc7strkGd8I3Wospci2CQeOKNHF8GfrP8SuG61x0PBtRnAYjBQGG4KrbY9RuaY9OENp/WIqhzVE6H21MZfEZ7nNIPzjrRXln/C/duWTMPFB/8g/WFyBazNae1dwuLHCYCNsfVRKX4sl1HUmz31NF6BmHY/VR0gTJP+qbpyHLWYotv0+gtL/mGbBJzF96aSW2Vhm6YkCjjMlK0Gv3rbuDC9QhhDgJ+y1yWgQO62OrMpgcMEE7Rw0NL+dsP2mhaFiyKDAywc5qlxureIBDefe64h4tQdAHkFBjNV9RoIwrSiraBkPfUPLnoal1AayJW9K61KzZIvG4X00G43W93nf5XmqfditqcnNY4sM5RYUEKclqYHkv0O2lP3LGnAtEYS4MbjbUHogY8fMwrlDFj6zRv2065EZXCRhgPBvEM8lP8FCg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee653491-bd62-429e-568b-08da0e9485d4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:29.1299 (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: wcihd2ueZfq4a/6aLZFUd9EOm2niEgIAeUb6BiJwPsqFqnYoeA/K19fbvsfoTLFpcAGcNWN4J9D+OQGqqkVuBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR10MB3729 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-ORIG-GUID: aXTzYWIZnzUcIxpkqZH8uXthvvge7V_j X-Proofpoint-GUID: aXTzYWIZnzUcIxpkqZH8uXthvvge7V_j 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 19d075a9dd..65e56d39fe 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -581,6 +581,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 @@ -686,6 +700,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 Fri Mar 25 19:19: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: 12791964 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 BB4F2C433FE for ; Fri, 25 Mar 2022 19:34:58 +0000 (UTC) Received: from localhost ([::1]:33532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpi5-0002iN-Qd for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:34:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUE-0007ki-GE for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:39 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:17120) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpUC-00038x-89 for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:38 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHjSKn010804; Fri, 25 Mar 2022 19:20:34 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=Ldf4+ni4bWcNfQL885EGE6ZpQjdRaS0D0GFwl5I4vg4=; b=0MNSC/193kyKFokYV3nMI8ydbZvShXcbQTWwSck+F/d5iP6BiDtJmAa66VynIdLRtIF9 y9HWwg3Hr2CF7j9yuroHIFH9CsDEI+HJdrnKfk4dSAWpn8b4XgZBRN2asRwom/3phePC lmryEQ2U9InozyGnL0lNBYtU0jbSgwrC0HbL2790oZUwCNgRUfWK214urf1hhejG57F3 XdXsjziQI+H5Cdevf22Bq0smo0vnLKRGc9e0m6dPS2wikYAGKULbIR5CwfzltJH21mf/ YKpiYFs3yQ02MPkGYmHhLzmq6bpBn6d86HLz3kT2j1yb8QAtFOtVm8eJ4vEYfJ6nwHuq WA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew6ssg46q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:34 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJGaUV077215; Fri, 25 Mar 2022 19:20:33 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by aserp3020.oracle.com with ESMTP id 3ew701w9w0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lEIIOabJI0cDnaAxFjybPzDAANs9uPfmH/vdxHbQEeCuuTeENOIqLwe2QkU6+j9JlWyloldYaMDSX24J7UtoHSBuuE1W9gp8mqcpM5fVrg8nyu7bO3LMVHe0RJlqSKV/n/AInDcW+LLKIKj7J1AZ2vAi4lb1chnoM8I2sxljWadM+yFUZCXnDAUA0mtM4eV3esB0hyE54X/BNkwy0qvX9S4T4jXZXSvMeN4Gj7Qj1qlFb3ylABiZiWXrqR8BjwTtFrCn4zm2mIAD+TwMNjXwyd8yMZUyjTqXTsBYbFW5OyWz80vKjo64XSWf4gJdb7J5VQTA4TCb5FZmQqA/fHDTIA== 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=Ldf4+ni4bWcNfQL885EGE6ZpQjdRaS0D0GFwl5I4vg4=; b=O4wU4bUJ03UaqGmSRFRpQMhwchIrBl9wAnq2MRjJj+CZZvI/PmPJCSS0n3p4KNCQu6hL3odLZ+iAbsAQ+1Ump82ChgF9YN69iWq4HdAQ1QOW+COklLeWbr07DSon/Hk4ckA0MC6KfwdBF3BW6ql91uRv7xQJNcDLfEfwXBL5Fq1x3x86mQ/mGpqPL/OXJJuQCp7a6+yZrUeCQWMxqUF5t0ItCDL2iJbHFQo5Tg3EU4StcpM0Qy3sZnW5g51Rl7q9RqPd3YktssPDWnCHZ8ChtrxA86aAPQTMBNN4IQjB7i481nKs9Mdr/G3Zr/PqngicMjvGfCk4+cZ8mD12izSRtw== 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=Ldf4+ni4bWcNfQL885EGE6ZpQjdRaS0D0GFwl5I4vg4=; b=YybK/08TRvVSl8TIk4szTj8zshac0Q+NEc9oftC6k8P0T526xJK87NCwLub+hHFPUe7m1J/M98G2Sa8akvg6aNC0E7TPzKzxyIwxvyOya1tP65c+CsN3b8xwVnMbaNnlzO0vzqdfAmTx3kTNI9PA67lh+NQfda9K9CtUVBjKj30= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN8PR10MB3729.namprd10.prod.outlook.com (2603:10b6:408:af::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:31 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:31 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 17/17] vfio-user: avocado tests for vfio-user Date: Fri, 25 Mar 2022 15:19:46 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) 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: d3b56383-319a-45c4-0527-08da0e94872e X-MS-TrafficTypeDiagnostic: BN8PR10MB3729: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: DW45cz+/rdt+VHGgRfAVGpK8R2i0L8j7dWfBQNfOO9qAH0UoctvD/O/QTE3+0iPqC3TZL6XqM1BREiZptxoH2746fFunQQ5Qze1J/A1nPdrgBMLxjrlL0Aa8s8oxV4NqnxiUFVweoN7WmbE3FYmae6a3Midyge+AatVEJWeWoejftn3qySe+soYZJrqDPNxpDXCbCDNJGUoGeodmVQLmKblab3ZIEZLhcsZaGwDi9yRzZbZ/CysHZzFTted7QJVw/2zMl4iA5BQh7ILwQ1y1vdboMo0JmtQUYXqeiN77aj6rtY86yafhdIA/YXDnQSk9oGK5fh4eX62V8uJa3O9SZHF/Uo9wATqaa+QDrSns89Lw/gdRrGUUlMkRPTczOIxYwAtVVSWHIzRc7K2uCJ7KW5cnWk7lLtz/0LokXaMDbooGJ6O2tmC2yNNbJJBYgGUthnV0j+ULvIPDjzciy0svwN19hkFuCucE3FeUWsU2uQkQ+HWBNTdr/kNxi1ywfjFbTPDIbKKvo/5AG+0osa5gRw/GR5d36AmFuw+Lqx97xadjmfQBuDTouyMVHBzGMzFJWeVqeTQyX/vSlsmmooIfZH0JJo63Nwk6ocOF7VuWA860qyxAC1+3NhFUEnT4UYRYDlIO7D7rH86i9g2hM0dARsV8RpyT5PFoox4PUjGy5AjD2MAGdu3OyYjL1bjB8urmbMcwszIdDD4AXZUf7D90VFxoUeNw2vHfeyEV0p0A59F7Xo7JcmUVHqod2Km553Q+TR3JJ6mkaQPr6MoxP2ksdvEI+yDKHX8PkRSr+71f73k= 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)(107886003)(6486002)(8936002)(6506007)(2616005)(8676002)(4326008)(508600001)(66476007)(86362001)(6666004)(6512007)(6916009)(66946007)(66556008)(5660300002)(52116002)(2906002)(7416002)(83380400001)(38350700002)(186003)(38100700002)(26005)(36756003)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NfWl+7Tm0OZQ7HrYrEE0145hAiAcK8/DzQFE2oz5BPbSPAN12N0UWVwWE4htk7xHXy76L8eeCxIqUM0RrYznDKJWoC9SIShwao0qo1b1hXGdLO19zun53VMEE+nZYHoikJReyGwpJ4gUcER/uLjoRRXupVZSEklzQ0hDz256rY4kcMvrXOTj72e04ydiKgt+1Cg6b+i/hD6+Ymx6J2dyTTS/QNlHUCq1WQoacmacF+/J2ITfmiUHHTvaoBUsKlb7XuRCgweKQc3R1eZ0TIrwf9WXU892gu/m+gU/OEYAO6n5MOj3i+9dZV9mLkfDidMQxJQqx0qqzCakEu+8/ZIqhwFSYj6U/DbzrTjNRGFQV4x7wzqL5wldo30XJ5NhUgyKt3SbPLkE9JH9cUl8IYoWjdODNGj5vDHf7RbFtRG9t/JWoXHkK04Pi5Ai76tCEiODgTb2ud+b9/geiD8WD7m3XN2FKzhH0L9rywVTGi1YQwVxF+9CXBfIwIij43IwqcGwJFFYaLhZjesUo9Kj6ckm0BbOfXeWtoVwAJh7ExzMterls4B5T+SaeMiW2U0ofh61R/fptFrlzBDhSyVZRQ9WH+UwNABqxiEVEP+o/IMJC62IS11FJyuxPxoAv35lMIF6zaVBM4z/k8KYjnoGk7nVpX/HWOHoEWrJA5nF5U275nmMbkIHj0+U8SBCc5daiHUEhbWnPCvumiV5Fvb+eccHgMVH7/couT4ygBtkI+6Fsmwgy6bpNZ/vKH0LDMrGBEOiOzz6DJwUJMiXBB1G6fFH5MBst0nByRij+sD5yMzCXuUPZukkm8xv1zSvn1muSoEmLescDBguI2P+qsR825Pb5KNJKyZYi6LQILobeBXaHgmBnE9O2QJILJrkNFQXgSC0tAEhkIt75hXtagc6+DrX1sAwdIU836vF3WP5KQM1lKdlLqEBz9uiyrgGeHYAAoFJ6yGGLBL6cigqQjF7O4xC34TmZzVRHfIEiHVDdl+je52rL5LHEccpPAAY0ZGZVwgy/U7PIii8mtSd0dK+OS5xAfWVyPb8JZQtxWwiirYYHHacegcgH+fo5yPEmqgLO+lsgFhWYKkHSdGlL97Z18NCuI53XYfnE6vHF9hLWwq7VAaDklU+2KqbZXh5iVDhvaO7gh9OiRX38lkbt4m8nrWEkMetxEjS/m3okCsl3ZGWscDzV/18utoUti6Yt8i/Pf3irzs3aeq+TNlF0iKQPl021oWTzmUKZ1cezWPYeiLy4+MHfCj+SOntdvu29qvYmy0/pOyv+cFlA76umkZa0pCka4FRm+yGf9Rx9KiJSaoORNx0P5sdvcHhYrnqc9hGNKJ/eMiVO2YYPxcGhksDVEzl1JAIwXIf88jchSOZmOpT2fPKnvXYQyIjO1WPUGA0eyp1wonVZFXRGNBoqkz+1O3cly/7jteEYSmx8yuY05vxyfIXTIHxEOuZG4W1ZNCEQIG+ZG/5bb/OKtzaGjscPwYg0jmibqaFJyxEvaVXm42dbSdW0c+BF6btaoePCGCbznIMTAO13JwV+x3FzdI8W/omrfxWG54eOQpv/kckOhX5gdqLwpWVC1LT/8vkXiQVHpxlPz6EPenNgD8d8QRrKq33sAA0/PYLbI01/EdlVV6IUisayD5UB4qQXi7WfNk3YD4KW1n1lobcbXzXmGg2FHh9egjWuwrRJFJKPGs9MObmAGP3YJGN4Ww8sGZYA+jFh5H9tbc8PGqf2dWB/gN4JzdG2A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3b56383-319a-45c4-0527-08da0e94872e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:31.4422 (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: MHfRBiHRxvVBlSPInZMahaDT0MSI0X//6PIRQhDr+iuNhd8TU5LPUGyyrYhUCqWSSTnEBC9o3H36WQw5qujM0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR10MB3729 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-ORIG-GUID: OJlI_jUFeuQyoMzqRCv3HTZ004tDXHrS X-Proofpoint-GUID: OJlI_jUFeuQyoMzqRCv3HTZ004tDXHrS 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com 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 d07f2a0985..f165281796 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3602,6 +3602,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) +