From patchwork Tue Apr 19 20:44:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819469 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 BF833C433F5 for ; Tue, 19 Apr 2022 22:48:18 +0000 (UTC) Received: from localhost ([::1]:55596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngwdt-0007tS-TE for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 18:48:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwdA-0007CR-P8 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:47:32 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:43194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwd8-0003xr-To for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:47:32 -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 23JIPdAf024809; Tue, 19 Apr 2022 20:44:38 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=NoZNpfeUbbSu+4V5eFN/EbABU1T90puNAIXMH0u9s/zvxU0OrhY2lVYfcO2PSLEbzMh5 vCczz90fVe5revMGMg91i1IVYytmAPGC8dmPQ757ReYZLoL4o/JGyaPJAJObjLDnSsqW OpY19mN2Hozw/yN51v7UmmOPQffJ+Kwbm8BZih3DzkngXORMJDeb1ObKKpEEDjYizt28 FhbqgPTGs1lNrdj7YDYuBoZ1D1VzLNPetSm7Diwwcnt6PoD73hgKx4DlkHsMEqfn4fnD MQvymcTzlejt8VoneAWTkarLe88vhldYF1VA/xZ8sGz34rrxKlrKVTMVqB4cmBOb2uwh xg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffnp9f29x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:38 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZj3F034097; Tue, 19 Apr 2022 20:44:37 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2108.outbound.protection.outlook.com [104.47.55.108]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm830c1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqTV0rjeQZmIxXjcMLxT5TE/9kHOs6eHgPCB1U6f85bDb3VESDPYGSiZZ7ko4L5bYz/hqcF5mSB6UjrgtViWFa/f/AtWjDXcOdscd3X+yuLP4/MSbmWUVmtWhAcO4Nm6jTW2O/6BD6KhDQ/NKHQUtzfZ/sMqjLDvNpUT6/Wxk+a7h655Be9owg1fpKTsBkM0aJ45cCXyIpFykIE2d22t507YyIKtRtIhlxaZYDpbyLUbHw8dHdD28y58xSwrlpbk+habK/0zkZc5ceqbMYXzZQnDeKeEGbkImmVfGakfk8wXwUhsPV0itx4lkmZlEIzuyuGsV018YxvYolOBZ2LmCA== 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=P7MbJM97bIwCL54EYHKRc25X3PGjf2P4aefV8LeMVT2cb1JVOt8qpgXjBYc33zXZjTNzeORjuOGrLAYoZUIiBlvfVxTW1Fnm6LAZorv35k+/ry1+FIxNIM/thV9hfBqsz03ncyoE5CWzoOS8KxearSbmzBPoLLLtvxADRztb4eTjOjWIpxYElNlPtwNRe/KEt676+pZGLc4dN6l7vw0vEBgyruTpJwUcpCuaSn6sqPtmC7h+L4zGezK+GHWr/X6EzwH9LrOAH5yu3tL8c8ykMs5ioZb5mmzny5qEvyFyYc5BzrN5CkNr+VvzMZOiLUjRicSkoQ+25KDX5zddYN/Ujw== 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=To5dEuTa/S9uK1+x1wvf9j4iGVjnBFdycHrbPgf8t98WP3yIk6QyBIf7kgdncxX+0VRdOGaERQD1MbJ942W6KfbvQ9iQQ5mft39yAlikmwj8608gePWYM9ztSOn3e0vIoxn6k4yrf64ZIwjJovqILw0cSCBimARKKKYtijbNISo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:35 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:34 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 01/17] tests/avocado: Specify target VM argument to helper routines Date: Tue, 19 Apr 2022 16:44:06 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: bd319b6e-0d5c-4a09-8164-08da2245697e X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: jFaybOLvrH+OdTs1p+9yGsMbSBOOqzEO23dq4x7JyPUx2cEoatC4be+xk4Ko9e75GR99uq9EfEA3TE5Sbo7ZJ6t85Y0lpKFz789Q97UH+HHd5j6yODD8vnlOXs4v8jHdtFtE0boMiX8rOnjJCNOf/YJach7mMpR8Rj7pEvB1NLrqcwtqVdv28mV/gWjc7NJQz+B3nxgyka21mMEKAd0lJjNDVDEeS9pqGO27E2twoE6nU9UdaMelYupHoIe5Ely+OIvXJprdj8Y+cEAz1p46pGwF3IZPDgUUY3UNPalZNBmplURzkInf6QdjoWAWsWGXv+mjdoIerQwzz6P621AV5jWkGuOsLDN8VMYcE8SythyBopjPPYQrrFzHU/Rm0q7bw+louWAyOrADML10BNXnC76cJaLtzcANVlHOF9qFhSdbF1ox3srO5Pgn8xNVmB4+gAbjjh6bcxFgTqwxf2cXqI3l8gGojXE44qiozSLCRp71O8oL2lhdFGgQhsCjJeXHyE/v6ruyfoXmzmOatHRxFjSYSrmPrcaZ8zphBbXFwSVdlxPNO8qkbZ15V2yWMOSJglANatzDJzkOBNR0sQ9SXxZREcv26gcjTHejmgzae7nrqJT8HnJYeulQuWQt3M2Mgr8fNhLhNJz/KbizmDzKjdw/fvZ6aV5ggsfiJ55gPoESCpusz4VDZqPMQKjnYInl2u5qilaBgB/7n7e/n/ESVA== 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)(83380400001)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9XhooB+/ujvRKh4YdfcGtcMZIMar?= =?utf-8?q?rghPog7lWIbwC1PFikT4X37IVhuPcwbG7Qz2dpDbhAMbINcnzrXmFYt/5Z4XlvTxh?= =?utf-8?q?xiCieRH2Hms0YDuo3NfnxwaQhVG/wAuPekG4G0fkvHil4Zzr/616H2DwyZdWb67w0?= =?utf-8?q?IhsSGetOfU+TGqGQeXMN4neJ7SnuJXXrjhxjrlesBTQ/xoojePbC5RKEJMTs3ffXA?= =?utf-8?q?GMTR8gTBUSk4y8awVsZSK+TFq8BIhL7WHU7NGJQZ/h6MnRwI+VNBcRvxvy/Op36X2?= =?utf-8?q?ygYJAa7qwWLDB0S2ahI5ULg5q6VlWkO80LskB9GUEqMQmVv9lCfAmzUW/QTNhslaF?= =?utf-8?q?e1CxSqlyGSfwovTCDxzCxF4LO/Qqgt+twPooOussepjcoDCosXuztogPgB0ofabVr?= =?utf-8?q?Ha/iOGbotRIfCU+6DB1XsDjzY1QZ3jZ4Jw+qyKvt0RKORJhjldva0tNTZ/cp4/FWg?= =?utf-8?q?lugovFwyreabjH5X20awOkPQWEGHEcc9wlP8tsMYvLUd0Bue+gZdTn8guvQluyaYe?= =?utf-8?q?IljN2el9RggcU65gkIxS5RonvQuSB5fTQII9J8HbswVzjFdrcc5x8Dd30AMqNcQ4v?= =?utf-8?q?SFVgwFh2JXWvzvaWA8dIaC7RG2s1iVTgO2vtt3FiAW/2kDwQgMsoZ9x9YDDcKko66?= =?utf-8?q?wyzGB3x2FWiaySqMJlfb7XWufsnwCBZn1CwNSAP4+kyJMo26ELB26J9vwdU2uAX69?= =?utf-8?q?fKhtgJgQhpyZdek//d5UKeELQPLShEn6xwsCMClPvzeHUwHVVQ16UzalDIPVMfEx/?= =?utf-8?q?Ev8hP6XNrsv6VcR3t69wC6CU/QYu5DAenQx4ENZE6corEC5uhD3dY2jBMj79xf9dX?= =?utf-8?q?iDmDtgUh7uAgXcybAamvUBgLIaLGevUwogKk4CUn79sLK56PEn005dmtN+NeTBT+t?= =?utf-8?q?ZDc4YzWeFfYwyK750tV5L9/8SzOeNJf8mYKr3CHWECWEbbfqsFKYb+GcwRrzKnRd0?= =?utf-8?q?NS8il6P1ALjRv1AQ34t/iYH71oI3XBjOh1d2LUiweWAo+cKh2b3megJ6LLki4AU8B?= =?utf-8?q?deJYzJZPWQTirxEWHxqWwE/u14ZEgoIRXUf2dG4IOIf8LAYmswZozewJL2csf0Ipw?= =?utf-8?q?XrSRyN23TROczrqS8IOD7oV0xPCBccRIgFaeUQ2moG5CeK8KJ9WkBADwWWv7tNGjh?= =?utf-8?q?FGVZbTj7BJvLN+pCG3K1P7TdeJPmHsGBBKTl1vccnj8kMkE1pwj6R3pZmWYj//x3p?= =?utf-8?q?HwhuraB3fgiv4+GtOBhpdpICrsjgJ8pP6ReT/T/MHnDJcuE1UD17sS1D+SOwjQlvJ?= =?utf-8?q?N3vJ+zhSXrXCz6+WyCHzvSAQvxus2hsEzHjoCHl47x/FCVLlfWYXzHacr2jw99tV+?= =?utf-8?q?RyUXNA0IXc9JQOOkfpq9iaNZmcNqMncqoche9XSgs8uqqspFzAF6VaGSYVsF1IbR+?= =?utf-8?q?lqQlYLUjITMiARAjXtQV8JYgHt1VoD6GDOE66ZEZ6hffrG7vMKSpEO+td5Gr9LS4g?= =?utf-8?q?JYFjeN037nfSevKQfClW8F0w/pQMlKbKQGHDBd9GHOPscMtMXWDNEXylDVgNc6wwY?= =?utf-8?q?CCQK5pkw0V952Yr/09JFdw+ufD45TxU+SL3rKgzGzGCTG+JcQxmSDFhvCAvsG5mAP?= =?utf-8?q?GYK7lt9U6lSWQY1lLd38BxzZukdm5faysg2Xar6e84+olCzrQkYiHATG5A10bDpOj?= =?utf-8?q?oyAwqKAsQ9IYFAkBdGm5yt2vPXR0jGSQ=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd319b6e-0d5c-4a09-8164-08da2245697e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:34.8707 (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: eKuffJlx83iwVnEKCDMKU/IwIYFzXTK1QnYvrmYpbybnlJ/1yKxbL1pcetbEpyi9T1D0KA9tuwnUBc8HDOa36A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: wyc4fTm_efrRa0Vg2c4xpFzoEXjaWiM1 X-Proofpoint-GUID: wyc4fTm_efrRa0Vg2c4xpFzoEXjaWiM1 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819462 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 CE664C433EF for ; Tue, 19 Apr 2022 22:02:05 +0000 (UTC) Received: from localhost ([::1]:55020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngvvA-0001Zi-LE for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 18:02:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvtZ-0000cM-16 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:00:26 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:19684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvtT-0005lR-OT for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:00:22 -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 23JI6Whd013493; Tue, 19 Apr 2022 20:44:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=2TfzwsdKkoSLpAZcAHPlG4MbvqRV9ya/urKqgtpFuuw=; b=N2P3okh7T+llAXN/09I5qkHJ2qk6EZID7omHPMB7mxjoh1E1XOH8sIotHeMO8XAQWJ/z tYWcQcV7EfuloBmL6/9xqWdd6yJNRNwI9pt+AEYDPI0kkHTKTmZVPWwxqYvZ3QITXUpA 6LutglndAgOnJeB+RJ2Ati2UGEULJX2C7dxf+oVs4unVpLfQiUbsF45r7kHpDC2viWTj ONvVT36CHRfluKKcecQgfMBEJvKjKu1n0+yv9AqAFOAsSHo2tH08nJePHzt5lcZyppFZ 5/Uhj8TJOTsyRmWUi4rBCSM/CwnK5IlYYTT9J9Ce5J7TC0+zeZdx6WnjGCOg0SmlBjeL Gw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffndtf7ks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:42 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKajjL020028; Tue, 19 Apr 2022 20:44:41 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2109.outbound.protection.outlook.com [104.47.55.109]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm892msm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aSLr1S0GRj76SNIZw4/4p6fb2h6r65o+/YbZOE1mh3tgGMm2G5al9gZKCxFTG30dt3I9zzstBVDgFX3V4UwONx1LQFr5OVnvg8gjnXEChZAS+6eOUNwtI/yle7fui+LPSR/gR3PJTdCMJs9Duk7kYM581VUywRgVkqcsvb9cnZt6Hsq/DF3YKONRfOBIsB+HC3bHQ2SAyXSawpnZSCclGj8j8LbK3woJGpmL21Db419RQn5EXeN1ReqhCOPzGBAreKjKJH2mZW5aQlQZpwURGU41/gwgXY6ZTEo8sViuGMQMTP6w0nbzsAu8OP+n+FIgg/2DeZyeFbO11Re8VypnNg== 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=Fn+viCAn3GuzN8J3UE793cbsDdd3imsJNQzBZAjKmHand3cNqTC874xjltbUeSSUD32geuFlE2xJXiZd4bT3dbH4PKstkEDDMzCCXLH084XIIoVuK57x/E51VejEBIQtpuxDjrUZEdYZ46aelSjB44IQn9NrnDpltJk9A2tpFh3mA2WMn7wZrHxnGAbaiBwFDhBPjnKwd96ZYXmsapemmKJhqm18le5lwuzkHHqJseCSXGltzJGc3uhkGE+536cQ1zeNA0fkQjxusZUzpXwHH+sSfxHKaUPJPFbhR/JeYWy4vqzwpV3OomeWlygFihH2DeoLHFUbFSEVlmMsjVylCQ== 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=lVRKNVfH3ZtkLPQYqH6V3drEVGZEtfA19ZqoQeUaPykcfb15dNFFqt7M1qMVnJ3G//YfNEc1+a76Ww00Jet/q13cYB/FAztOc+2gCIW0n3yAOJGU0FiRWT+P7nUp489JceOCa22AVFULsQ536KIRsbMZFxF5tjoPRUNrboJ87FI= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:39 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:39 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 02/17] qdev: unplug blocker for devices Date: Tue, 19 Apr 2022 16:44:07 -0400 Message-Id: <26c36cc56c0dd0021aebc9c2b7f9e6dfa1abb67e.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: a4dcc1c4-dc56-40a6-a4f1-08da22456c17 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: nnhjHwCcp+ym3GZNyPGC7sM5jh4cTyF1hSRLnfglGxRJ+wNY4CQ/Quu89l4O61IjYC0/t3pKHz5fbGguGp8RMACFuykvXcDL367HNKcRbqJ0Zz6yN3B3RDIcc0/Ed4faDMxPWdPLFx9Srk//HPnECecsQIvaW2M1AVX9H6Uj9ykiVaPQJCAfpctF1G2u7tCTGRisAldHGCbpjhv8aVFY/M8Ou3DCe6O15aCQeJGd1SZ9FZUXBbbL5OfWmCVKpId52Nn73ShB215qvdqcb+O4cELXJu4St+xJctAVS63j4ZDLFaTW4Yr6dzYIVxLD7yIKVopqf40sJsoFVhR6b6GiWwyGFjPiJpX5dxfuRaOi3sMV7Eowo+THS5vZMRkFB41DoISLda/HmZowBLfbqyc7RoCbLzs+l4NHBAHDKNXE76l4YjvlZcKTcnbN8sNDObmRlHHHcR4A4SvcMEkUqj4ear8dmftg317LLTmYUMdLO91q4SsD9v1CQ0ovoGFQSooqq7gypfiPqHqYVEHUT1E1F0tUOUiLnjB+bUnVdlIZCLV1ZFTRqy+msA2bvVdw3S1idJiNMJHQiOM40JKLGGEKNbPmStoX6uXhg/7Nf93EJmwKMr5wPOvETvdfTKT/215p3ve6ZVWIhdqeRA9utEvoy1DbLDHTQRZzkZ64Ds9QBHzpqs5uNRfdIiml8UhLUsNogkJZoqZ7v2bVpktmtTjnDg== 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)(83380400001)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kTPelfn5C/zXvvOC5kmRxcAlcozGk5kTQQw9v/gPkyEt9Sd0loX40rvZififKbk3HFskNJb4jJUyDvYX/DjYPQA82AJBRjJQDc4yT3ok+W8ph8j5dvBA/VvOF5Xy+1+xVHRyNyUZIe86IhWEMDpid4ZhQc8cNfiJhA2QUpacn0MKO+C7qLbJ6hDtotyZxFaFU6DgRAW/jO0mRLxi+oJMlPjXR8IVpa/4AyWtWUo+J7eJgsiAD+Qyhf7HzgdDNCsmXdGEkBgBnNVOMMvLDfKHoJBLoAeX0CUieG9M4vrXpTBtKNU6yF6z8IfAEq9NWkbG1FGXbMaCNrNtdKGOh5Nt1kwBb42/dwKp6nbSCd/rF9j+deLKIZBbrPeSUBHt5XiQviqZ94oV8ZlJUZbRAD6jIGSxpfMWktgEF8rgPnBkZSjqoNrNZI1TX2wfMZeKvUAfKEvgFgB8cwY99TnOuZYLIr/Cts4UbFQmpwnDmOuTgZqQAkcJFI3AmheDNMgrd6WACxH+CStpfjFoUAzfkcYIRRnttGRDdx7OPrdoLkWiDvp4oyc5UzB8rx080qnZ1kUut+1O/PsTVwqhdIRGYmriX3eX8N1idICBoSFTZ3O/dZoNgKMOiVnhDv5o7MCRCATDOpk8MxyFfwf+6qsWqTqxZzovR0K3kJBRoGP6m/b6p7oc7jCg2yf06bjw7yWiYTkUiJZ1tZxYCyFuQ7wL+K2nYbjleARjARJeP3yZWP0fhSThHo8AfkMoUFB5bYJzBJW5W9VmtoCj23rvjZkAYtHSQMfY82Dpl1Usf5RUdMaraZr8FXo35FXWKrQ7PUm/qCfpLpqgdn6A/zgvqgwDG3VUlxwhmM3HRZNV4/IHJthpz8PxlSUBIq3yo72y8Vl9Vn8+TGUDaA7n1PkLB+2IY2X7GGbIakKzSUWlTNCbfx1mp7shwMgSYLCscITtVpDFLuqYoVJfKQj1q+EK/jWhpaGSQo4r/7sqtJsWSyRxZPDuPJtAjsHATdTKZxJZg1iuQso6ALdXTJFJIWqISpvq8L/bPU7ad5dz9GIOGSiKbZdGWi2VIhi771HM/QZW5u9Ufes1M+aWY3J1wrZlPAluSjzc1CqyvWGbuC2ZojTgiMMd+4vCcqJPrINjjy5HyMCHrYD76gZnAyCcbnEE1HUFS05uMlxlC2vFzSkRVlNTXG3KjUZOcYR5tRzsBPtaIJzrpspE1nwqblZukDFIxdf3c8/2EvlCP9L/Hp6AsMGbYlG3L4wJZtaMdLqPScw603uP7S1gqMWkkbiFGDU5HqI2c2ndljBP5HLZYHANe+95Vw44JcWYo+iyWRYhV5P5SBM3gmG7AFdj9Qt0YKX03nkcuswwy1+TFQnXsQfn7ztUOSdE8hTySQJTTcHa276+jNXQeWHgSK32xe3w3mIGU0Yej2N4/O/70pvFJmCsufvW7r9oL5OXoeq+659wDKM2Vk5TrdlMwx1dKsNQUBxsXTf6pLlDA8BPQ5OsXrfGgJqqAw01psP/E3FIfgyEBynCc1EfJwtens1Vp624oM2hWDirPJYW8XIUklObyHzqwq8F9g++Le9covR9FqfLOrzSC56FQPNJZ986MzMGgr2ciCIvWIhvLTLbZ8tU8KAaaewcBUzK7yqWpjjAtn2LVvohoKXncM96TW+mu145VwlMvRB7rEQbClKMwOX+RTB3AqXXDviMXw1ZKCNiGpU4S2g0Aph5cnZMpMdBDNBEWFl9y9bee1p79w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4dcc1c4-dc56-40a6-a4f1-08da22456c17 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:38.9641 (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: dUB3E04X0FOiEZpM24Gwdo45uRVnvpgCTyMcnSXcbwpVb+uPuOkm5f8xSMrJreSJtgOWB4G5Idd1EQ78Pyqq1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: TUwPVYDyHcPHkXzcEWCyhTIlat3F8NyC X-Proofpoint-GUID: TUwPVYDyHcPHkXzcEWCyhTIlat3F8NyC 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 --- include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++ hw/core/qdev.c | 24 ++++++++++++++++++++++++ softmmu/qdev-monitor.c | 4 ++++ 3 files changed, 57 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..1b9fa25e5c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -193,6 +193,7 @@ struct DeviceState { int instance_id_alias; int alias_required_for_version; ResettableState reset; + GSList *unplug_blockers; }; struct DeviceListener { @@ -419,6 +420,34 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/* + * qdev_add_unplug_blocker: Adds an unplug blocker to a device + * + * @dev: Device to be blocked from unplug + * @reason: Reason for blocking + */ +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason); + +/* + * qdev_del_unplug_blocker: Removes an unplug blocker from a device + * + * @dev: Device to be unblocked + * @reason: Pointer to the Error used with qdev_add_unplug_blocker. + * Used as a handle to lookup the blocker for deletion. + */ +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason); + +/* + * qdev_unplug_blocked: Confirms if a device is blocked from unplug + * + * @dev: Device to be tested + * @reason: Returns one of the reasons why the device is blocked, + * if any + * + * Returns: true if device is blocked from unplug, false otherwise + */ +bool qdev_unplug_blocked(DeviceState *dev, Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..0806d8fcaa 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -468,6 +468,28 @@ char *qdev_get_dev_path(DeviceState *dev) return NULL; } +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason); +} + +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason); +} + +bool qdev_unplug_blocked(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + + if (dev->unplug_blockers) { + error_propagate(errp, error_copy(dev->unplug_blockers->data)); + return true; + } + + return false; +} + static bool device_get_realized(Object *obj, Error **errp) { DeviceState *dev = DEVICE(obj); @@ -704,6 +726,8 @@ static void device_finalize(Object *obj) DeviceState *dev = DEVICE(obj); + g_assert(!dev->unplug_blockers); + QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); qemu_free_irqs(ngl->in, ngl->num_in); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 12fe60c467..9cfd59d17c 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -898,6 +898,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) HotplugHandlerClass *hdc; Error *local_err = NULL; + if (qdev_unplug_blocked(dev, errp)) { + return; + } + if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return; From patchwork Tue Apr 19 20:44:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819468 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 B47B3C433EF for ; Tue, 19 Apr 2022 22:47:01 +0000 (UTC) Received: from localhost ([::1]:53456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngwce-0006PV-QO for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 18:47:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwbu-0005Sw-Bv for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:46:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:56192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwbq-0003ts-PY for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:46:13 -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 23JItnlP024789; Tue, 19 Apr 2022 20:44:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=/9fgYmY3VqzOkuFKOBD8Jyf5x96OyKAr6GSdY7sOTgc=; b=KN9oJlGP0zhJbibs4XB8SqYga+5NPHmkVj/ceis5QnqHJek8qkfT/jwfuPv53HHo3w94 LzGQ0RD2nEuRpK1cIvddUteoWo/6eiBfThfTTAu/RzlwEu+4YXstYk0fWjypDssZmtrV DhAXIKswfUuyw0p1e0altIh8JqthKtN2PRLqJZwF8RovsU+zUqQwuc8DJMKnx8c2pYju iP0fKfoFjPFX5scvI6qoJLbRxnonej4detAgqkBQc+0EQnQAbfpQIqNijvxS343XPdPX /9Gk8xMUsmzdgZN7T5p71ORS5eAsYD1mC3Yff2wq2buReR1O+eGrbB/mm3+zZAp4KgJz eg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffnp9f2a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:48 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZgmG016834; Tue, 19 Apr 2022 20:44:45 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88sphj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gLvtHfNJAskHW6OPvQ7Txw567t6wdjYZBjb6oK1GZiivTAXfduEzPoB2xZHMYRV3fs8nhT/hx+4y8kFHYAtfxtKZoUEg/n1MNwSn8f+9BRkECAQGCDeFJW55vCcInOJiMA2QtIC5kq65Yb9Swf6lXzQ/R1LW5N8FDcwKmEZU2lSA147aAoWjyRZlxU3OthudlTjwJ8wJTx4A6P3LcAADpaNwGUFFKYA3yjnsySP6Q2uqG2axYPJjq6SphT3RBbY6EjRFJHVzyrXZUEgkpfdSrBivKrVn+crzbqNBlX9NkLtoffcN/QeQykpJZbcpGnqYXjN5yC+tZgEsaq27VakX1A== 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=QQRyeHuk+lRSyb869SH0XgZtWhsfBgevjUezamAYOIcn2Hb0VLWKmmZnSb0gj0HHaUijV7eoUpZKGtH6alM+NIWR4BS0P9Lfjp5YefW2ddUZrqWF5tSr4C83sljsHuoFx4hucJK4hAbDkItdYtEmswap4DaFCTxDFib2wTStq4p/vVBsmkdHVU+IRbpaZsHdTJPhC73MsmmHEPsfRMTtIwmSg7ceO/EM9UF6UNZwnQUej4+uq2XxMTgHzM2YU3C1MijKO2dZmVro+t2Gm4Cwn8zjfR+UzaWBOfnDqMaMPPM8ZstoH63PBEC8Jdggs1fQEFoROfXIK3AtLvI50fZrFA== 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=XQxA6sfD61jA97O2yY5NUgifEAn7hiVFtBMUxcoTDbuSbkUh/EbHhnpEkSDWCXD+jtTPiTbhji/lOx5rgCuuk8ZmbzwcTB65Bn5dx2ynIorF8RyY+gjIUNH2f1n9BsWzRn5VOVU1znzhJXl6ZUYQvo93Yz2jfHc1hIgoZNXLa18= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:43 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:43 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 03/17] remote/machine: add HotplugHandler for remote machine Date: Tue, 19 Apr 2022 16:44:08 -0400 Message-Id: <156a5c927777f2c424daec8ec8e75c65641bf75e.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 00ad5753-2f24-4107-a5aa-08da22456e6b X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: +EPsZ5MObuTl6y26Uk1npQpC/R7bAk0yqoiyFYPJFZBub78ljWHkvB24Alq4/TSp3ACWVTXjuEAV/jmCazmpiVrSkTwWntfjRRPz/eTVsqGsQEKPZyNvBm/16i0bqkBdYuuDYErRMZDEAOSi3vZC8X+qIqXZpPKFrb7+7VqaT1bdgz3+OVpK7+b/nDWwKb2Pxi+6VH+hbE4BC4v/Gbkis8dJElFFOwXNS5+4nNdNdDs2k8woBXQWBkabivrAx/RMyS7eBo4RaLmbiQpOjzV5QtImMUbIs0nGll+cvWr97a7tu492Mzw+7aiYCtklmbjsNQyBf71eakE7ftpc/ohIjF7pcQt26Z1AjiFcFn/d8Y3pmr/3KEZ2oyo7H6MC6+q8XGxuX40jMOFdy+UwVTLP4Lj+gZ0jzcn+jZmefKy2hf42spysBD/DUFfdmHdMbNAfz07xWfJJ6YAqWz20HSlwNveksBrZdZ9fG3fe//OQWRuvckUUpKDXqxJW3lopqu2FNGjMKLD7FGKrdc1LsybAeMnefhiUGsvU2A6eotZAz+Q91c2iTVc9S5lFIBvf+7sa7XBBquOo9OZur057grgKZpKJ1qulYyNwqyV/EQOunjR0iRS6E4Yzxr24IVKnxg2qvE0XXoEBbOGO4ZaRGHgrZFWKJW4Bak/nHanCR6nEynUOk8gUY4dXW8MdixMdbz569L3hWh1WPcrU48s2Oz7S+g== 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)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MIppgOKefsVSKMau/qvKmGQBVeyig8tjueKZjbhs+ZfQmsxKQ/ySupsVmx6wh8dDdkX9DVJIGcyLKnseknBBFC1yzmwkg18PzIafzgzVkGCcMDi3wcMV+I/axvivROfcnsU49YU+kGSNs8QeRQwvwEpvKd6o/htHKzF1Q7ViuBxMB4uvGS1Jl9eKqbnr06g31xuG29Zj6PNK8n6klvis/O2pG1GM31m2pZFrG4gidDuqFQZp9HDYaWV1WOODwEeVPwK566xTXX178UWvPrw9/mUio82lIdOOYdc9eljL3kTGEbaDSKREDQRPbtA5Fm0tGEld7p7bYpH8hXGv5bOuxp/++3iTY57svKdW0Ol/ATTpq9+VkyR5LZ6XlGq9fJK/s60WqRgqx9x8/teck0mquelSNHycIT4NWuWGSZr0QTAdVL+9u4eVgveGm5o7G/Y/WsASSRW2A8l4yemgMwKun88s+ohnZ6GuFKIHvPRDS3KIbwf4gPGdMllVty6ZO9RugdHF9Bndpm4TxTB8JO/PiIjILabeVrKUV7xfx0pCNi7zr/H1CyajVfTYUZz2ercM0PwsFVzsPWLt8tX7gZBvuVsILswZClCvMdaTSREfkMDwb8drKio8u/36yRl1tJWpkQCYExhGoaWAQ3iZPwd3DSAdGSplFMEBI1+GbqPjUayLyccFDtkdSaYUNT53LrdRvIEjPId82Ab32fOr1R5seBOFYi3M0g9jAY5NdNshs4atPgJFV7UAuy+60v5y4ATbgp1Tc/A9FvgUPdRobviRnkXCKsz+qsQckd2RXjyGJAb797zLRGQ+nJ63xQ/qAdPL6PJ7KnjkZEgjletRf2SIHuchWzld6zMeGCsudjoRJL2216WwPu2rvnZvi3FncTLsMqsXI+zop6z2bFBGBWh54F57FBunjEna1gq/BT0lkDyW0AYT0MKgEw9Wum23jYh9cY9PKeF6U0njbX0hdJ+ckPt6chTTBwA+1hTKSmJDsA6fwWyKsmUdGWBnZQf7IEFNmhKXQjqZVuDGLmm6HkgXyWphytMQlu28jrKu+CjDaefcQiJHN71dV0M/B7rLdL9gHxdjN/R3KwmnRzcJXK+F0hB7q2iO1BIPoNq9xAVO39sB8vXLW9hbPJAY/54B9A2xBKX60U/+uWyALdepCUA8QULoXXmRpKwr+SvymCSPvwEPp+bzqozRTvJONqD85CaxQwHIpA8fv+86aqFDxQMzyhA6LEoKnogu/CYsWoXvmJ0459ItrCqYQHN/nVj5f4JpZx+ZIrgup9zxJGovQvWi4cUEIXzS5OFO/YuiIM3iH/un8L6Kw4bWw+NBSPfOI5Wqm+YaRlH9CXNiX9XMG86KZn4gElv/+N+0zLEFvA84S2BzJ6S14RryUcelp/JWAvjS9HMeQlVJ6Ye9IIrNKst9evVPT0T5XVBAx8XohSIopC80KVZkNOxxP7SuPeZacV/1LlnrGu3SNbeG9pEnfi3ocQHfUXjgzYvmgE6Z4sbMFQuZIYHr+U1JRY1FNstMoolgjZwZV3jT3eCKvSUJVM0W8LP6ikT3mulhrNfi5QzZu3hubunNZkVtpsJjjWI4YiBtLXL876AIMxzfaCf71aRQ6FZ2vb2eWHiYYoqJqNLsry1muraudoPT1D3dztNcHNYQCLXyBejLSqZzf6Y2KFm0yyRG+DeiO6mwqC3K+fxy7izl+WiqAq4SC2HChpMC817uW1MSFCwfZfY/Q2SRfa2WNg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00ad5753-2f24-4107-a5aa-08da22456e6b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:43.1513 (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: lLyL++mTRr/sX21HN97iWxlx/3akPkJGEfjSCUc1r3LPv7Bdubv4QjBK4A2SfgLy14Jpxg61UU1301UpOB12bg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: AuwdXkkg2EsXDF5TFiyu4yq4j-6UobIP X-Proofpoint-GUID: AuwdXkkg2EsXDF5TFiyu4yq4j-6UobIP 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819507 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 282E6C433EF for ; Tue, 19 Apr 2022 23:43:25 +0000 (UTC) Received: from localhost ([::1]:49992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngxVD-0001gt-Uz for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 19:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngxTx-0000xl-4d for qemu-devel@nongnu.org; Tue, 19 Apr 2022 19:42:05 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:38838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngxTs-0003dZ-Tv for qemu-devel@nongnu.org; Tue, 19 Apr 2022 19:42:02 -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 23JIc9h3024754; Tue, 19 Apr 2022 20:44:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=knAUhec0MZfs+BQEeOok0aa3RG+yTNRzFlP3XMvR1zE=; b=CRCSyTi6/yP2FzN5lkfWAEOpdYK0HRBwpQEs6/E0YHphVpRpnYxYF1OvqMCyOzfFB+39 pVpkvRBiSCeVdwDjRwGlNrqPA/2xntKnr6BgM02TjKxbwjTuY848EWeMARLgYu0naSeT hh5eXNO3snmIVrecuxMj+2g7b19PazTjhiKIv/eNgNrIlgBwUhU5ePp17YG3o3dEdBT9 DYsMhB+7uqjiy185wQo8kbs9b0NK/S13Ux8hoVPLMutXZgOP3UQJvifl2zOWK/PQ/FpA 4GsVQ3FdhIGA5ZIYXZGvr1GDr+hWXo4bXGyMvX50jMgoZTvbYjUtZElX/ZTrLLN4rFUl +g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffnp9f2aa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:50 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZj7P034072; Tue, 19 Apr 2022 20:44:49 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm830cbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BSHHCIjgbB0y7ldR7BzIDtiPIbKtYAQts4Vw5gp4+zxpIaS321+0yisXDJdatRgBGSimvEuFdbfP4IzrQg71vjMBYbY3wrnYZv6QlUCY9rWUeZeG9QLDs7AOU+oC1GxIB4w0Fbe5m9//vb309fcq7ln9SlP08wVZdQL1HiDVApJSKlzJCMa/gbeNl7OqoSLMHDQZazqumIt+7ijEDNlL0xlBz52OXSEaORlA9OrPC4xxCaSQATz2arwbT3WL/RR22wMN63qJo785NrPRIqzlqVKh+4ile7DvVQmynooJ/+VpshOHVarrAfLOML2512GgusF27JWrZtWsyG3cKq9+sg== 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=WQqJIB2BPyMdtkAMrypddGQZ383mI4Q5b2H/FL+SffpARy1kuEb7A7lY9i2rhGM+2kw/hSt16OKz2sKs9g3B2BzUJ+a/UNMC5/9FZBU0tXqV/Rd5o3AW+AqMSCEVNk2WyjBpatjNXGCDayGLkN98zcgBRGuw93ugkzJpQqP1tTD1g3vDf3rsYVNgodBcBgo1TVH8aHgJBQmzYVMG6rZHk8LIhzI71VCfMzjCTiorZY2UskN/gKYCiD/JNxjeV3kG60uLtR6l0dY7QNj6kI56vrSa3frkjjmznxKjwVzYw6gXrKzASIKsmiZw+DPHxBtfMbHW9Z5jixM887OG3BBWfA== 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=IO6BjxS/+I5k8k6zuKi4blg1Kqv6WiuZ2mNYtkQmAKtg7L9xlG3hNxL03TukRpunRNuop3OUFQM78+dyQraqYvGKcP99PyN9bzg5hUbvba8f/IqD82RJRzUL0Anw7lDoZM3BrJ7jb9MY7J0qBYqe/ecIselql2apkaOKOvCJo9M= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:47 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:47 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 04/17] remote/machine: add vfio-user property Date: Tue, 19 Apr 2022 16:44:09 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 5c85e9ae-833c-46fb-cb3d-08da224570e5 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: zokPnVF8Y0zWdZUzv157JI7n1gAgj/1ZBm6TDnuZ63v1u7XlTlc+6aLi4OYtDIvOduzZOyUCP7u10hf6Rvvx/nDliCrorpEz8El0Kg7RDs9xOB7+/HsDJ2hudL7KwCE9GKmQVrExl9kGg8xPiCwxxPJHFse9I0CCXRQffNvBC53yWEAzftuTnOWabilTV7T7wFncGJfCI6lEwF7uX3rMPfc2jp+3acLb7EldaBcfmEvOJKG/T8WrpoQ23FLAEqW0M0sDxnkwRD1pXTvrl9cF26ilZ/uS1fIccoKeLOIDbEx38dflCNSSEAQshfLu7kZIFlUD1KYvZFNOfGoZSo12/cpci969teHmBR0kHwN6y6tx8QtSoMZs1m4eL8u+KQ6TgPg19HgB1MZ6DobC/IF46nW7Z6NU4Wn1BCBcSeqsS0mD2gd7+5EHJbayrSwUxKENgcYu3ljkraCq9395mKAPPPJFviqdAkHTWJvsZW1WJUkflQArgZ+PQFrlQYv+KJY9+tmdAApw32mQgDXaLHuUVgjs+QPzVe4wIS5VeSmvmbd6vgfPp7v0MUR+PiNYuh6FzODu0JHLQKX3qXtfE6Si2gfR1VkMpp195cjcAHmpbD1RcMvx68+/fbYtdQiSImULt4XX8DztK7PQUbqTGxUcFdXDsPINdhFT/NlUFxpzRcEMboxdxaF0oOnkWCGkVHwWn+x27dydjK4lkiEwe+cKIQ== 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)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WAOsJE+3wFVpn2old55B8hRyyiXKZzL23rjqH35kldm5CDPqqElVV3IcMkAIX5jrlyaJKFIgTgq96GjTSy+xPagrJ04cE8o/Ag1Fdlz2c5189p6ETP4uj4Zg49afb7eEvyGgpcX1UkB40L21wjLWVQbrNZH9pkjZKVzTnDagL7qSEJNnBClyl1a/C+5cMKfvAAzJh9iHvaib2CB6R+4JxDuMiHqbZottByw1DS+s528HpR8lBQe5eDMXaVlBmmEiwIbFMyUqGvyZUFASwSXFKSS1mkl9oUjM01XE8Uum6Qats2zkEEVgXs0+bJ+45dKUxjw57CUnp9xa+hx3WV/njxOI0utCY9ZhGVeCu5zwggyeRA+3rx8wzlTs5eb/oUUJK6OIihwTmt54CIAYDN6L7EDKeXafoN39LOionagy+UpdvdW0qqx70+Ofax4cZYm0LYXxpiWh223jaxfYhBXjc0i30dH91XqU785H+BytRt6EgELwtGvdmbrUH2VRqQKJfChsQpd/kkZxOYGBVRmJ3ICN5E7YXQ7WvENToWnahA700KlXne+yf3BKe90I68lx4QgDZoXnISdBe/JD3eLDWxCc4Om9KZxRo8mQYX0Ww65103k9Wc/x5lsKNADkU+cub5Z9lwxNubtt3T02Bq1o0eKr3ofjEtKoBCgaFInudwFLpea1NldiesLBYPWgmXjV0IwHk9SofTvLhQXnVOxtB1TlMw88qh9oU8yQI2hTIA+2mSVCHU3kTaP8riS7M2mGDUTnIOxNerBuCP9ha4uBqx120JmcJA2bnMihXGNnB0+fT4l2rKgmgQ0xJMKFGWglfQQvEFif5qe2xwbhH6zwMaMxHx/zqprT0g/evZ8fn1VXoeAY6xa+Vqw5iGfWq8Zdgdx9/+/coIHJTSIB5PHRUqr/vBcRrzr99Fw7VRKXiT/SObe37YN6g4+QX7uR1LQg24zgz8w9arkG86aQSRF5oMmMH8oOn8PykKqghqCSNIzt3SmhYZV9MIq+8e2s94bfUtKVf1yulpytQkt9gmwHuz7HQrgUNYuWznUG+6Tz4wVRtny9nff06TNR7GVgFv2ydkoWB2KaLFYvj6h8Sxn5/5zjEK5+MNxjhSED92vggpY4bgYQqxOJgW4h6ZHmaU2A0Qg3JQ6dnnM0JnVDkV1JYKumwsOyZkBxQbcc4D4V1S9eogm8o1/hgkUnP5/YxYgUcxOWgYOTMnGY/RY9fMOzC2CRx4+/O4FWJ7lfsHLlm9Z1PLr3HB4QzgW7QJXmWxct/E0/7aLGV2Cvp059HTLTgge2FhLC6KJlADVz5/bq5O40X6MGUPqZl/PSYHrOiCordfeCeiDBHYMJsOhPkyBFB9Jh4+PYxg97j1viJpM1SRC4XBSAZbKncgNeeZUg/3TVA00KF+eGd7IbODFHeuNscvqv9OQ9oWnTdRQg56xQHmYfuNj67ICI7DxKlL6iHtJ0fk445INIqTXvfnW2B4vV5a4AbjqS87suUK0Hr2+En3aQRg01yGnGEU/8ZeqPGJeC0ZwxGxncU/62XTPpZNZR63GKDYqcXVQkAlPjSlO3Em85Ko/eS9fIAN/kSyqM7oogqfoqfaBDvWA6GP9BrDhVloAuqgW7vCjG61v0BQ+ot65kwpnH//44V+Kz4OAH0MyqHpumUUiH0hPEED0ZxffsyJutZynA8DL9WPZ0/3jDzzf6FR8A4ICnSfLzKnkb0z6LHDYp5GqA4bwCioTwAGMD3A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c85e9ae-833c-46fb-cb3d-08da224570e5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:47.0573 (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: 56bKNKXZDOh3gL0KV+mior/caEexqQbuUqvAqxAlW+qA/rfJF/vXqwcND2xHX39bTVB5HwZdHqqEzSDyfV/nOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: g_8GOgvUYYevOl1WS1RVIAcxVFK5GG_M X-Proofpoint-GUID: g_8GOgvUYYevOl1WS1RVIAcxVFK5GG_M 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819448 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 9B537C433F5 for ; Tue, 19 Apr 2022 21:29:37 +0000 (UTC) Received: from localhost ([::1]:47346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngvPk-0001yx-HA for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 17:29:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvP2-0001KE-Iz for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:28:52 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:53664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvP0-0000y3-P5 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:28:52 -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 23JIPdAj024809; Tue, 19 Apr 2022 20:44:55 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=CpbOo1KS9NnVJe7Fqr0tjHQVLVAIrCQyQlXZzi5kXqJv0DvJDSZNAXivYlNDaYjcvJzs jVA4+MEnreWkafphV2+b0nmhjLjuxpMzKQp4KbNA9+AuMp5tdV7JBfzlCTxk824gcL1O NxgQ5V5UVw7a9Gb4lez0rn7STu3r+NGCz6W7sSvH683+DtHeO9EseSLSByQUV+RxWiwk NVskOJU20dg9SyqdKHS9zTQUz4EVFvplW0eMHod+edxpjo7BJwjmY1qqGmI8XGTrjKU0 oUDPvXv8ZWBHVoQDGKP0xPQVSTwYRtLYWSxe/dX4LwGgE8a1iSJOf/gWoof7c5mDhgON JA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffnp9f2ah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:55 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZqfQ016962; Tue, 19 Apr 2022 20:44:53 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88spju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:44:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AuCROHUysgNppXE8pZItpKsexlvtB5Ugsrlf22Dnd97E1Z3zgj8g4OXssR89xLcWi5jU/WLLg9eUL590tru2eENQpwKEAHVG0RxxWZFaZh83biYsFi22w7y5DLYK/FFLoT4uNgBCDUDXGOygYLkK6brBlV2s/9boaEaBkckbiB4S45sEiOcPR3BqnR/+00M7fJtlDbIn+fG1Mop2DSMzOXkAauOfkcDVvtKBOKLNIE59oNeDo+AjkqGvO9g24oW9hMWAWRP7ZIlYJMAwze5A/rPXBt/Tu4fgKmHH/RAbgiGma+ERUI6NurJ2SzgOn1Ha/cchYUaDXuXdRR4edN8M6g== 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=moAjzEjAUgmrpjt0bhJ6/xdCvGS1bBGRSmTj/EibjZKibZro0wdy+Rnen036jhe6lnJGlFo0iEJztaQLudnBG1SxUFbAxfwiK27QekbE0qXf5IGn6KsP17Opt/qFiSkIU0zgvFR7/xv9mxC5vgJf3l1+Fad+yeWXbabTWNtfV0ID+I6VKBI9HuPpDUTsgCaStyCp83A8VDLgSXXbQuoizCJivIEh8ZExyNfprOe04+pnrDDOx7PABDzHcaFckws4HrhNK50FHPv5Xf2rHMo2ICDc6lFcix2fLtYb+TqlcvPK4d98rVizsQ2oaULRehecINodWnGPpj/VdKxHu22JYg== 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=U1U9JICpResChPItlCs+p4v14uWo7tHrRAVsJNTOpvS8rC/yE0gnOD6kJ1v64JZdwJ5JT4eJpOPIw4WniqbUGOsqB7kF34v7tKapxnytnbV2RCFXF2T361qpE5/L4tHuGVT1NyNbNRjTBSmah+zXBMTlIT/3PCyXkdOJNyRkPKo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:50 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:50 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 05/17] configure: require cmake 3.19 or newer Date: Tue, 19 Apr 2022 16:44:10 -0400 Message-Id: <83fd16c0d73483e75fbcc4afb13e8ca9345e6cc5.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 768cb30a-b188-4551-cdfa-08da2245731a X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: oP0XIbnb8thrzhMg1Gb8prVS7mZjqKiyVxnzsLCjMiYw5m8XUVIkr+SQ7UQYbd9rVtRvhBs+r8zqHu2yzF8iKv407LamlUZyuq+G0vJDBlJJ4mDXvcp3/h+DW5KF503T5NH2Q8WtfP1E0V82RsLx3Us3aBMamhTirsvOjt4hYS87bpBy4r/7eRZVLzVx9N8IVQpJNWlo1No+Qighi8dNc2WgMfAd2g6h7qS2kZ61hHZGvf6Q6c9bTcZgRXN8et0CYtmZgTk+am+yH86fVaO7HVu2tJOeWgx09TlB+fix8GSZpyMYhIHhy2iHTEQnXaow0bRerVZcnivex20eApLsetkboi7te9NSETPdRx3d1bVlnjS40RK2VDPh0MhVc7+HwoPpGGqM3UPxLnseyr1EIx3vyyW6dMUxZfPFu5/i0ogxYVjU6cnnJDcDLQWECTn+KiqhykkP5y1TD2E86MNCjvqSGat6cNg5SRqO1VMXCVFabxmcoG37gAhcx18+Py6TsBMZGB2cU3WrksqWnlxhezRsSL1Gok/Vkgi/7dcSU0pYpHP07bHUbFe9YP8wvi4gGA5USkR5puB2Q1dH0MD5TC5XXxpQchn9bnULYuA9Sq68Paeg2XeV/dyNi4fQRys2v0LEFcHgbegbi94wxt+xm7gXRbXSXg3BlviOc9seRgwbjIYRz6CK9r6m2e/ttnLeqvEqpDM/2yvdGS9vyFewBA== 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)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SUiKjNCrLe6R8ROA4PK5YoXfIMrZn2y1UCUtLYNsVdxG13xnpYmGjyg1fbGJ7Tk4a0C1P8swJo9XgTYNm1Q3rPi4reHdGFzqXMaxkEYHQ1bnJBk+OEg488Y71CGSesQajLe1KO4ZE6vrWVTcd1MCn4AXxQkZEy11uHgHdHqxm3E9WJI90uKwcZ5Dbb73+yle5PZajDUUYm9t4OKM2z3PvbxjP+IBeqs93YjnKLda+FUQeyR2fFQIP508zBMzrLwQJOM/vbLvX8j6fA8Kgq4XErLgFf1DNVyglNQ3QgSGnsUHi4BE19zJM7DGl45kFQ2fhVq3n8V03295o8t0TpXzOyzlCSoPb+LyM39TBFkdA3o9ln4XdKjIoJB81ZqORfsEic6/+zA1d2ONepBQ4YwCShbZTFPmrkheeZb4JeM3DirQXvad7blEQ2KPf1+la1K/3cHKyt22EonkvqO/ZSrzrbrunHZCrMwlW2Munw4FMfFjOTMGQwMTc5/V2T8TEgHAxsb1EeX2M4IhXDj7PiQzExZW4ZbcARYs9k/teg6YYALJxzp8k/HUZ4cavm6W5eWuySONxgPCbkSjeboqpDDiDLHFjdJfQ0ZK1eXk+gQA4WoCuMdpE20f9fU0ubK2riYUDU3Xtlpfhp962I5uUixIVfYlqxiTPs113GjVN5V2EtgzOZ6tFHIVn2YCAReGFHY/ruES4RoxFpKQGFGMw+L6BWsDSho3NsQ0Ux5ZIkNCwjKdMu+7eCTOt9sn6uYXF5RxNH2cubTwJVmdbBaQOtTOnrvs6qLA6F+zRAsJdZO8cG0z6Cq/Hp/WeRWad4FDyzHyXyg/EJ+cDP8sr9iMpemAe2fvii3Dy24tZmw+gtVvYDATX67h+8huKes5+SkW5MCXCWcYBHykvwdFiEymKplrbYrzQfDwL5BW44y7S0kECJ7mIygpmgXx4Nv2MODLfD3lfW+5Xq6/UWb28ANz9W8YSfI8lre/YrZkt1DM0xBJQ/UYobjwMkJzXoJ9glLAvY4w/q1ojFUfeJQAxlAdgqF0o4DE6Hdh4q94EsgjhPjmtBGRuapJju7yCkxWraa64u7U0ub8u3uiqMbxu42k5SnD8GyrLlZ8LSnj3477wuGIqXG4hSp5ZOz+uOrGbNdWWcrNk7PNWtCnQ4lXEU3BosyVVfJCnr1CqJT2/9tyPFGPyC8oZmduHYbiWGjZJLIPVI9qSmWZmYVxnFTd0kQyBr7mAwfGGsM2K1Ibndh/gy+MAlY3nFuyBjb75dZj/A4L/uI+bn1UoND3PPfaeTrGpTnr1tfT8NiCN7iA4yHDtwzQ3kOOZlrdylydE9WYee3qLGh7Dmjs6vDvrWykjzAsMhgyiplDmdfgsONlIzxxXNeb7awQXfO2h/6yCJWe2/+5w4B+R7ZEW3emYfVFuGxpmSN7xmUUNA4pui90LaS6ZSGlPPODS6pgkL14rxBOE0VdEPYnEtiQd3bZqj54LD7umajeXHfL7920bqXqJw0zFDJhD6eK9ZmUYFkIjKAMG207CLLMisNXsI5X4woTGI8y9sVj3Jnz37/nyokoA53uJ90AI9VgkuiM6qiMpAjD1lIjiw7VABLjFj+f2yv2EhfmvHjbbR7bxZIUrrCQkf40W8cNBeggRCkdpf9g0pzutnfXTTOBZXt8xwnpAMlN3yQoBoKgabwkbAU8kwlRMyHYy7iPnPW6LdxsXGDq1vrMIi0OypsdJs85RA9Uk4EkdGlFdPGr8w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 768cb30a-b188-4551-cdfa-08da2245731a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:50.7601 (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: WqHwC6RKWj6Br1pd0uucLExcY4095HaKH7/TQCrGHaGsqQeoHi0X9RZ1pgA+JotCsv5OTNzEWR+oOrRq35Yt5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: NpMHn7UfSWXrMobHArBcbQmnCyz_gMc9 X-Proofpoint-GUID: NpMHn7UfSWXrMobHArBcbQmnCyz_gMc9 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819453 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 58705C433F5 for ; Tue, 19 Apr 2022 21:42:18 +0000 (UTC) Received: from localhost ([::1]:52352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngvc1-0006bT-6C for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 17:42:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvaD-0005lZ-65 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:40:25 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:13640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngva7-0002k9-Nb for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:40:22 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23JHcfwZ009531; Tue, 19 Apr 2022 20:45:03 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=FE1luhFeahUiJWyDBZ8paU0oYsTOSdDJfI9rvSq9s8g=; b=rU6ILaTZe5vXuoysRWqM7er4/4l1lFFo/AuVsqN5s0lSz0hh0cx8HRdTaewKACQ9ItaJ RsgGaEmLe8jEYDWdnRApV4jT+yRmSBW/IhPORCcLTQyIdnJRN6nXa3BTY/Uvw2Pom/r/ Fa90qKaq84AUlt6W6EPcFdB6LxHG4Pjj75bZKtVjWSGxPcbhTDNfpWTNSQCMFzYHiEEu 0OvMGrGBJcPeN77pQSxnlDl+Ih9cTo5VO5RchgWeIol9lztmyuJjs67BjoNeOlqlWz7c f54eyfwWPuJD664x/b1u2D31mm+KrKV2g7bIjZQtVmVH2XXucBwRZ3GbSJMNg8tocbEO Xg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmk2q799-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:03 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZj7T034072; Tue, 19 Apr 2022 20:45:02 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2106.outbound.protection.outlook.com [104.47.55.106]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm830ck6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b1SKI9bpRAaerF3/+hwkvNEeOpupDUx+44QV89S5d6QB1Tw/ajXVxi+NbzQEHRxtOrsBwa9Xe/oQ8M+rUFohCr/AwWt9Ud582XE4PKzPn1Sx318JBtPSymDaRiBz7o7igi/uwppvCe1o6BQT2br0GZPae3kjLmOgQZwTQXo+T+Gr0B3k7jbdBk44l1NWGewZJcy+3yYPL6ejeDNCcnVXPbws31srMtFk6ijvKs82550mCpaBL8TtwkalkPODAueUmPqADksxC/rT9bLjxC55riZETFy3MepWJFnLQD3+q6Sqa5u/hm0PWA/8kHIw4lqV8IIvxM9XkVFHJUNVrbv/fw== 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=FE1luhFeahUiJWyDBZ8paU0oYsTOSdDJfI9rvSq9s8g=; b=ZhwYgP0DE5jreF5+9DqQ6MeS8wBKKlmDjXGetg5t+azBxA6nJgxq+WypjZzn3xSQga6frW1vqgXDnNIlsXKkSDSaF3YFlb2Kcu6eoREYyxUu0SUfDnr+8iWZ48ABsH2vrGEhV9WGvxMFeT0ZMOeKWWGyYxdrZyBWaP3egcTdMapY3MzVHFsN+tGJse+Ctbf+7hVWbds5wYLZ6o0c/q1bSBZH58nQv8t1j7hkv59CeOi5tn42xVZqAsAHmJ0Py8Rxp93EphVUE08umKSdT0aG4qAzqm86UQCImGF8L4sndxJ4icwcDF20J9yuTFc3NnDcgIdLCjj+Hztvb+NQGlWO1g== 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=FE1luhFeahUiJWyDBZ8paU0oYsTOSdDJfI9rvSq9s8g=; b=FyeiPyZ+Jj2k0pLIWKZ/7qidx4Ie8sxrFL54QS2S0EwS/+Oa1GR0Tc7QkW/+7247Mu2DUGj/6forZ8aGXXchZXuMUaHWf36W9+/opldPaEm/K4H+6LAgFtHog1X421Gi5d9k+nu5eX/iA0UvozPpdmZiCgSKlHK4d+ZiDxZNtJU= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:54 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:54 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 06/17] vfio-user: build library Date: Tue, 19 Apr 2022 16:44:11 -0400 Message-Id: <049efa4ec96f2e9f195ee94cbe7b49b07861af41.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 74bee014-a59a-45b1-6e5d-08da2245754d X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: cLcdDBvLmwwM1wo4PC7VCDUieiWbsfKIMEfAUzDNV+OpNqjGl5j+wSHxA4xCLZyF+R5KKd2N//I2Q6wqjlsXvaRMHRS/y82U0sEVao2RyL7Sq8Ify4j3qfM+DBoqidSH6x14r9lwnC0ePPVZDleWJZPn3FMwM/ScfRkDzmdDqAmlkxxJCNlUpch/0DaBJeeT2AlYZiZvFtRIHgLtq32PiczlWCIZVaNq3kb9/65Sl9dyXbk+GjW94Zxbx6UdpWL7a4Gi8K3V4UC3Uxk1661JFp7NUmZUPbnFcpRgx3R2sB95rvxAmfueT3WMTpTsrhb/dxniD/cXVT0t5LRTiorFvmn8b4Ng4ROCeFi+v8/5is+Tz5cQT8zoAxfk4PWffBcg1YsWvskwFk8mjNlSSOIWEexKVLj0C3309Unw/55NPP9RLV9i/4i8PUw0mdmZIwqzQLyqKdhqI91SOMmo57C+1SD1M3MjmzMQi/CFiyebPNWo31XfPeMVoVxjKzEJBu6hsjwqUjtQ0w6alTvYtMv2wKCVXD41IWpMHwkXlvInXl4YDd8s3uMkZYxs7SQ5uIkzicvJ4qod5XGLwBtXvl8MUdUtQkUFtx7KraTrD/Yv/SEX5rTMpF0RYQUyKKHIcLgkar8hNohwv0X/E89+P4RtYyZe7Noox8sPexPBEtqCsRQSdUOrrQ/Y8ETwpwACYh+cJ+fmd+VdQajDcGBM3YXltFY4CS0lUieGcZ6pmX23pXuroPDZ5q8bIiXgNU5Y1a3uJ/lll1Cq3/v5quYAyeZErMwaYvadNrXPPNNUG78045lvo/aQp2aoDiO3cr1sKcuHxSvzgny8Qc1OQoFFHafAhbIE3CMOgT7tLZq0iXi8Ab0= 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)(83380400001)(966005)(6486002)(30864003)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5VlmqGfPQu38oIFSyPF4d4l6XgMBI92tT8qrTTs1dApEv7FuScimS4kdh8JkPl265r0w4n34K+wtFlNddSLXkgN/33mt5OfZKIeMFOozhFBqTt46hX22Kgep+RgGjdDgkbBy55uXbSDG5C+3tooAFE0Eil2Fd6zlrB/JnaDjYXC7K3fHh+hvZPHZuTwhAnqSaT8D+HvC5mteX1VEZLIiPItaTWNqXJUvHQ5Ti8tSoGGsUzRRgYz80v+KjP9SRoOYxmY6cFEpg+unovg09Y/4dWRbAv1hjhREM8hirixtdvBOL6fpvDa6abQmf0zDzyTkApPwB1tvTcvupU+azMMeHf2y1fjBK3E76Z+AhKD8rFY3eSKXJqiVd6n7raiZBJt9vt1LdplqJYK5tqAj6ebhEBNVHcUuyTyHcseKJWTg9HXII9YvxBZXyim42r6AmIX3qJrQtL8KlmtHWXfpmeca/n15xaT4uxlglvKgsOJ49kXCr0gBeAQtRr+r2p+tIwWIw3816YncPYNtfB6GcFccdRhz9vcjpLD3pe7et2ez7Rl1lHcmkucqKZ9PuYu7/WsEjr2RDbL0bYZ1SuBCzVB147ChqULNxE5Zlh7Sq64EKXMChOWXVIXX9ZDX3V+GhiJoDQwDIHMkSV/TIFGn5JPtmw70OewHRsAKjO6ZliY7/mRGeGEmRh3KiY3dw8NkZEVO4XnFYWzW+vweHrfQZXHLobd3uIe8ll50Lb+mFoGfMg+bl8r3c1iREG2S/bqgojiaVgoDgHyY3ueNrU2VauCNeaFcaF4rD89wnB92fTTh8DaGOqZ3ckYXhaHX4ebpFZ/0Xu1Zf23syftX+xt+USPdEpoWEVHKg/dwqDh5/fbIfid1yJiwjcrABb2T8oprvI9S2xerdTY6fMErV6PNhTd9+IAZfA9cgKrl41x7dGZfP3q6jNPO+kl43jf31TvVrDiATKgWIojR/W+is6dIMqzHuv2dRLZ2tsObv711aMB+vsS9prfwzr2hiQkwBmzQe9AHq7dYf98SByTRT7+TOdZbivGdChcTWHfAVb6/nhx94HG+SgxQDBlJcKAVtaP8FAwW1SESs89KeZUe5fO/HDwYHiSGBXDqNvV8K0a+ftScL+HP5JTlMli0277rPoo000nAwswVX8qTUpTf3jLJVV7qDq1k0yHchh7BVzo2N4fc1vFJE9aDptVbsm+XiXDG+p6qwKq9sUBo76CuPb0ritFYFvg4eDIAov63pNRmQrJ+SH/UUy22jkv8GXuNYEZVGhQgNLoHPLxS2TFbTX/L2tijGbDBaNbC4gQYzFHhlt105+5sk1+3JAzZbOzGQ5Bm5Y+SmGr+qg1uF4HaGrk7kfRB8sowRUQlvRlfyK2USP7DI8RLhyiCtu4BRFiiBb+u2mza2wcE01oKpELBWhMoApz9CQ0vXoLhpiokI2Xho8JCqceTt9QIg25Ocwmj2xBdFmu/TU6pvcx3refDzrX32BG3dhJ43J6zGf/x0tUmR0L/ctB6tc7VQt8WQ01qOJ7Qk5K3a6zdkcFfKXs3SLoIimWqObSmQgc0M5eO+BmtrHD/Xzx5azd4U4EQJGrRs+E9hgF9Equ27EUjYIjHm63xGHeL+abXpt3ptixqGhfoDnG1JlQ4eNJgNrZ+kOf1qMb5YcK4SkJcu9/e17ChtXPfCeb6ct/9EP7J2MVbmryXI8IM68zVcwhv8YMwxa77Y2Txa+JQmHYSZ4Q1lz82I4pWbsH3Zw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74bee014-a59a-45b1-6e5d-08da2245754d X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:54.5880 (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: U525uIack+y/4lmuGh4khnyDfA6SKHIwEGBPjZeO36+g6ljythKDT13qBNHObIYFFkar1TNMCqqz0/DNiTd9Mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-GUID: iwsW5volIGlII9QbQl6dRXPbAN69CnPH X-Proofpoint-ORIG-GUID: iwsW5volIGlII9QbQl6dRXPbAN69CnPH 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Reviewed-by: Stefan Hajnoczi --- configure | 20 +++++++++- meson.build | 44 +++++++++++++++++++++- .gitlab-ci.d/buildtest.yml | 2 + .gitmodules | 3 ++ Kconfig.host | 4 ++ MAINTAINERS | 1 + hw/remote/Kconfig | 4 ++ hw/remote/meson.build | 2 + meson_options.txt | 3 ++ subprojects/libvfio-user | 1 + tests/docker/dockerfiles/centos8.docker | 2 + tests/docker/dockerfiles/ubuntu2004.docker | 2 + 12 files changed, 86 insertions(+), 2 deletions(-) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index 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 861de93c4f..84bc3a1c4f 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 4ad2451e03..dca81a2d22 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..030d2f6e79 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 030d2f6e7978b8ca7577b81d4f48e2771bcd8f47 diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index 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 Tue Apr 19 20:44:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819464 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 AFFB5C433EF for ; Tue, 19 Apr 2022 22:04:30 +0000 (UTC) Received: from localhost ([::1]:57656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngvxV-0003Nr-HU for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 18:04:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvwd-0002XP-L4 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:03:35 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:58216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvwa-00069Y-AF for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:03:34 -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 23JHVvG5019815; Tue, 19 Apr 2022 20:45:03 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=QA8CDNtqsi2Kj1CND27v27ykqUInHgLR1Y11TMdJEyU=; b=ucJgYOxVcVGLEHMoinJO0UtszJBvqK9BFiM/TN5HmXYqYFn0okIJVMZxQUvvIKbzBvsA 5kVkjlFFWIxKL16Jy7RzuKV/0lKh6t0EmLrrjLR2oDqrdpxaotkdjyP1uV3to0qdEKUO 0ovmPsrCCAq1gnb5uhIp+Zso3VTAWrdXotss80bwlOFpbd6YqCoC7KCFfXoPvpp9zbcl ZkVIHmWNx3cNWajUzjkr4lMkRgocKxWsQvkIdGyMUW8b06xCmYIgOlLQFEvqjBkGpb7u 1qx+9/tlFjJlPKj2vHTcuNVYRbs/7x/avms3B4Mq5Trj7pIpKH1hOBAH0QA4F8B2xIsy wg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1793e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:02 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZqfS016962; Tue, 19 Apr 2022 20:45:00 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88spma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B6jtYhV4gNMQZMts1147VN/ODrWbJMXpbFL+s+HhHXIPhioU1jSaSSKHuxrjJ10gfDXZoHVrIg+iJOfxTwlmdT+8ZXVt9WwYwX3I1ZBnCUKu3zcmyV7LcSXE3jhZ8Dr3qVt/d5l1V0sutsPDNXzVhhu+8uDWoYu4gW8R9qzu9dC7AF3jmnTaeuYg1DAz/Yluf6GCnyiLCZXaGyC6goEF6jkP5uZbA0unNANY5noUk5VfhSGLOXKFP0sEyo25S4AZjPOy2mzTQNgpFCXu1F0g2u3q5SPqif0pJoLvZ/tEHPvPNCSVZQT1GR2a+NE4kvc7v8q2ziP5Nj7sQ/oPPb+Z3w== 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=QA8CDNtqsi2Kj1CND27v27ykqUInHgLR1Y11TMdJEyU=; b=VmZ3lBqxPqAO043936HsmXAt7c0jb+EIVCTf6jUdxWW4gDQvkIZFgKHmsQvFnPSjxALoII+944wGAkETBUTsdO6t8fENmp7kAt/Js7sBlooHzufDdEFhoG8nfi3AWbaDqAuqp6yxib4Hm3po49I74TJylmTWP9wv71dU2aIRZ5xRr4nE9fNp0nXge6sVyb3NZHxLVHDbZ9YeJZDQKXYsX4utjj1GH19yFALQ3WFkAo1oFWzbY+MwTcTdHvbWUeHO1XrBminvFwPMdJRXfQBLpw3aPq/NNElWFR5cgxP5AifbUbER8yUrxRV3TtDo91B5RFW/6BU1MqoX8Fw5WK+AQw== 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=QA8CDNtqsi2Kj1CND27v27ykqUInHgLR1Y11TMdJEyU=; b=DpNZ8KrEu71nGhyDjAi7lz3QrwtkVOXCOfTf0eQy/tlp/mbfaeXx6Rgh2oJz6TeYQhTipG2MY9Jfs4TKOixTuDaYxrWd2Ht4h/NBcJLNVPSbeyEq1QFKNxEroJ7A4kG669epUrtHMEj7eQTqPBl7A8ELVGOTKMSeOsJStbH2mDE= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM6PR10MB3290.namprd10.prod.outlook.com (2603:10b6:5:1aa::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:44:58 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:44:58 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 07/17] vfio-user: define vfio-user-server object Date: Tue, 19 Apr 2022 16:44:12 -0400 Message-Id: <0ed6764870ae871ce03409f45c8e7dbe3bb31ba0.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 75638c87-6b87-4b1c-bcfb-08da224577af X-MS-TrafficTypeDiagnostic: DM6PR10MB3290: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: ITuHwpUbYYZcwG6GbfSKLkWDOC8LzoT2nuZKglVZ+nZFYhD6IMXhEqEHl+Kl8RKMAMC+h4FOnXXG5GRWG9Hwc3CgMgpOKswYbIe+tYTfoch3RuuA9yr3NriSXZCcT4/aQfW00Oy9N2v2rpXzD/+MAGT3K1R1b+nJd5wYpJ6ntQC5Ob7KW53IVzibc1ZTUT42qVtAm0VGkGAqxHCINmbXLqn8RfSk+BOtUeyqRkhnY+uXhNAWj6j3cU+461tI5iPyWEvZGwA/QIw+rOvunqamUWSwr+S2kgRt65Sp2Fn6eSOl9ZH7CqVpDgSIOQMt9LyHl5w66YNjD5vK4WbNe+MbXXXfvTve7YVLcI6gRlwHxYmhhqXX7oBYmVDGtZ2TFsd3TIp5x6n06FoVzU+qzNqt9BWullBeNI+UufoGS08T293lVuvRQc4vIUwVA6OkmrvbiJJp0z0u6VGZ2eDe6/YTeIwDiahAOdXmozIDD5DpzkL+N+MzV7j2gRRBRSw+ivNdYSy0aJm11iuhw10J72kKDIjxCNTJ0Jk2oRcv8JfYKNmHw3VbnBuS3nu9zPM6nn4szUTkzyLPnCVcJzWN3/nNZrxhYkuAt4Vz/yzqSo78/ZpoTSrlCjCM8Vlt0RXbXkxJdOPWoOb9dh9gKg7cBn6rqV6RcBsUt2qIRrHQrPq3/AjxugSw37QglBURCZuLKJwgyHw3C3FZGF0HVhmIMqq/8A== 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)(2906002)(8936002)(186003)(83380400001)(38100700002)(7416002)(6916009)(2616005)(107886003)(6486002)(36756003)(66946007)(8676002)(66476007)(66556008)(4326008)(52116002)(30864003)(6512007)(86362001)(508600001)(38350700002)(5660300002)(26005)(316002)(6666004)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?e0WHdOVMYG1hv7g6wdJvAhpX2sLR?= =?utf-8?q?+4Wf62qt7Ga7soFCSrKzZ8AHeOXxmLC6sS/XmFRHPxcMSstjof/h/DgdrHtHQK67N?= =?utf-8?q?IuxgxTqD+vVSSvbHKnsjgwWgRBc73iyp5YVnj8/zL+K4mJZYJuTEbD0BL3BigQVtr?= =?utf-8?q?gtO40lsE5Tcrb0VXi50rvIM7eOAvMXJoqvHA3gzO13muSM3illK2A1y/mhi3Tfw4M?= =?utf-8?q?V9DQImTMGB3wTmMzgefwDjd+q585BMrQ4MNH55raIJBapEfMcNI4ijNW/xqLm2D2y?= =?utf-8?q?LJkODgGfl057PuEOE3kUI+MRJpB3ygSWiv0GtmgMryHdrwYyYCMVZJ26yfZnpV93t?= =?utf-8?q?u3mT3p4j5haG2Iu/mLeFOhWQz28RR6ODdFrIbd/84TQPzhpl0nPSUw2tBLsbCeQ8I?= =?utf-8?q?9AgPX+x9fAkCtFGIrlf2oHMzCxNVhvPPB+JdUXVB7nIofdGh4bq3gqQUYE2pWWqcQ?= =?utf-8?q?fypCyV3kUZJ66hzw/+rWdb81eF/Cf6Srntjp3MfkmG10WBQBqfrLycBmguqjCXdp/?= =?utf-8?q?eZUoUwUUPRDa2L9W1OOZN5GuyeehZ9Ws2Ioiv2z3d2+JlUdgAMeb15LVugKSWCxfQ?= =?utf-8?q?ssAWb9HS5w/YtXbVhlz/xTymq1Sv4ysFOs3JDWWl2Y3aHtCKvdVWKt6pPiLJoqIar?= =?utf-8?q?Jc1rrgU/y1bqqdNs5EaDXqQK9P4tzjgYOqdxTrYKGCjN64h2fKIADz726UB32hqvz?= =?utf-8?q?VrTXoxwi21vNaemnZJF7pITb6858/c6grbrPxjPM4mTV2zY8ajSUvsEi5AhmrPaen?= =?utf-8?q?p4EZq/XQFTb66ejjDTOvudJlc1T0yRjMfBcvz8ALXezcHFhKdlkVX7CvgGW/za1xP?= =?utf-8?q?QimXQGdyf0On3XTyjkvMcfd47I3VkYq/q1ITXYEgHt2uSC7Nao7cnxl2PJS2usKFN?= =?utf-8?q?QgmohSXlf8RmhWCS5EhcMN4t1rQ6QMFlJGh9ZbKuz6YMLEr/M3JzUOhIpOfn2s/5Q?= =?utf-8?q?hRGL8M5sBly/T7g9nU/MI7PHdGsiWDWXdjFCG43VuBEZGj6mMGrdKQK1Bii/b1HGw?= =?utf-8?q?yhN3BpmgSeQ02ePI1F0RnbLG+O9nugIZYi/KYrXTDn/X05509IbD8brRWN/dGKoee?= =?utf-8?q?/knTDyCOqOFmjgutxHL5NUS+rj66p7bdBedIEQPtr4/tE3NLMhuKbnhS/XBonuo2I?= =?utf-8?q?bce4YWT/qcI13ma34Yno//X+xOmcFc0sD9Kz2DgPqKxysaQk3tq3oB0FM1jHtXxiA?= =?utf-8?q?kmeM3qi2LbDk0VhnojYhTub1QsgnbajA5E6rnrK/T9doiJFtm8Y71kQIr4S6oj7t+?= =?utf-8?q?fHmgN64bDH8tPk7vxX2fz077z49EQsPisO+3PtkhCX+mysZuV1brKbexLYOQ0tMtH?= =?utf-8?q?BU2cB+f/dOX84L3BRVzV7BAgthpMBcvZ0qCrIWqDLDbo1RULjhXCeU/7bdin9Lrwk?= =?utf-8?q?PaXOejNkDsDx4bRHunyYFIQp6RY27YEiM6UsluLDTe0qeDzgEKXKFVTysKMOS+mvE?= =?utf-8?q?RrpG5byBqS161tEQCMd1RRcNGeofYgJ9ir7bHL69Q0g4SfWrbzh1+LcjQP6l/wmsg?= =?utf-8?q?0+GiKF2i0GcGAja3LaenDkOpS/Zo9iRbsgrRsYai5f3qZlcnmUMQsvbmaGLVyI0eA?= =?utf-8?q?I/SyUTS131zETPgjvLSw76uCSvUYoDKECpSy8YdI4QMQkh388SlV7C80+BZkxL8UQ?= =?utf-8?q?9wCbN/v6WhHtWAajgKDnTybnQ2U+Ti9A=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75638c87-6b87-4b1c-bcfb-08da224577af X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:44:58.4158 (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: knpFZUS8vCrvSvU+PXuDD2W4mDfB8JuN4KGb47tPuP0C3rnCy1wHeIeDYeTkG7MPIf9R8SDkyfNLs8bR8FVijg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3290 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: 4R4mcWBjELf4Yzyg28ugpDFpMEnPqIAj X-Proofpoint-GUID: 4R4mcWBjELf4Yzyg28ugpDFpMEnPqIAj 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 | 2 + hw/remote/machine.c | 27 +++++ hw/remote/vfio-user-obj.c | 211 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 7 files changed, 263 insertions(+), 2 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..ac32fda387 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -24,6 +24,8 @@ struct RemoteMachineState { RemoteIOHubState iohub; bool vfio_user; + + bool auto_shutdown; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a9a75e170f..ed91659794 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -78,6 +78,28 @@ static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) s->vfio_user = value; } +static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->auto_shutdown; +} + +static void remote_machine_set_auto_shutdown(Object *obj, bool value, + Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = value; +} + +static void remote_machine_instance_init(Object *obj) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = true; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -91,12 +113,17 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, remote_machine_set_vfio_user); + + object_class_property_add_bool(oc, "auto-shutdown", + remote_machine_get_auto_shutdown, + remote_machine_set_auto_shutdown); } static const TypeInfo remote_machine = { .name = TYPE_REMOTE_MACHINE, .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), + .instance_init = remote_machine_instance_init, .class_init = remote_machine_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c new file mode 100644 index 0000000000..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 dca81a2d22..37afdecc61 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 Tue Apr 19 20:44:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819447 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 E79F0C433EF for ; Tue, 19 Apr 2022 21:23:24 +0000 (UTC) Received: from localhost ([::1]:44580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngvJj-0008I9-I8 for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 17:23:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvIl-0007b4-3T for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:22:23 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:31414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngvIh-0000Dv-Eb for qemu-devel@nongnu.org; Tue, 19 Apr 2022 17:22:22 -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 23JKc8fd019753; Tue, 19 Apr 2022 20:45: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=kRf7+WxtOwU3kfUY0jVueoHBR59qT4ytR5JsWs/AK2k=; b=gJqFRnn8OB2VhF/YcyU9lSR8w/ioQ5sSVGiXrXARYc7+TkH392LkFcsjzAwuNkyXwqCd M3PAaGye4SdN36XjJ4XJX+HmnKSC0A15icwItKPuQPxnqEvKv28hSsSGbOOOqBUdUMCZ KhsA0YFVpAozANVFxP2WTSQ+QxddmG/p9fFA+x6lUbHWA9R2FV3cb3awvLMPw3xQMLjw EynTtTcaJFAQoYXXv0dJAjB0BOvge8mKGxABhnKiQ8VuJ/6k4Z4R7CGf/7bVtkeujyVK 4itY33rwe2A7Es5LS0qbrqqu3AGQyT0mZtr970XN3+qetUDrgcZ+uHl/5NZzyy/9RBRc 8A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1793n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:07 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKajjP020028; Tue, 19 Apr 2022 20:45:04 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2109.outbound.protection.outlook.com [104.47.58.109]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm892mwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mxwxh3aAdldmws+tqRjhX9TrsE9PfvIFz+VRRZwi2tp7yMJ5OiydC5CCJoj5xUD5ltvuNqtf5UDqOBRtOu8Kot7oxYaZVtmjx9I/Eex13pLuqaK94suldu+CH4cOtAKvAp1HRw9Tc+TlGgagbrkxvNqMqZJlSXH8GbYSAoq60X+0PbWSL++wTC8LUFP+u2ybbueqVU8Kr1gh6t06D9o0bb6VH+ch8lRUn1qL1KLlgxemIARd8QcO+3JTLnMLI1HN0pvLTA+EZJKcrd+3EjlhECTMTR93otw6J+Mt0MbMhXB2zFOhFHLFWgoxl0Cw5RxRI12Im6zkImcS0AZG6lW/7g== 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=nklpDpKr2gZMnMvfbx1TM7qpeON3hPnRj0q+oZeQy1ZlLbsD71/2eheugmW/z3jYg4u7QZbxkygI8w2hF9DztPM/E7CgaeCgcTXyT4oT6JY8TmPPjaBXbEnJMPt9syxMlL+m9NSki6vVQHE5u/DXOSEBzi+68uy8a5f8HwyWWTRFLN53FX4gX4PZ+OKgC3ZcTJGQ+4P1fQTDrtaXGYAOYo//BOSb3ioKZ3wvo6ypYRpyN06QgjMxnkjx/WskQbwdBcpKeAQX5RudjZ28Js+r2XdY+GaWGDNV/AlZFRFI7ZADevFkgV6bhiYQAjUbIr4BRKrQdTxk7EzUWBTf0/+4Yw== 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=fwsB68kIma+0dscBaZ1fHA+3X3aY/L+R4gQIWF9LnBWkSjVuXoGtbOdZ//kJTXsNaed9GKRWr5Ye4H6CkGY0GVVW/fLqIwrVykzpYOx7ZdsjVh9ahkADhzOcL0QTpXR6i6fkraUZoztVuwJB3Z+xZyOql9fL5gyynADwkdbqcH8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM6PR10MB3290.namprd10.prod.outlook.com (2603:10b6:5:1aa::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:02 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:02 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 08/17] vfio-user: instantiate vfio-user context Date: Tue, 19 Apr 2022 16:44:13 -0400 Message-Id: <02b9ca4c303149a9bd74df1ba9d93e95e1682f48.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 51eb6ae3-5278-4084-969d-08da224579fc X-MS-TrafficTypeDiagnostic: DM6PR10MB3290: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: g/+maU1fB01mXVjwIiWA3ESwmeN2ExoYui/JMWq4Y/LjIIvTlf65EQkwbq72PvrYZ9iCAX/RVskEXWiiJGZ/LRYphyZ0lv/SYKtZEhKGUwYzjZ6wScuuAs7x2VXEzMfH4wZV0KFPD75NRf8eFjld0DBjWClHLt8wTV5X3DkNqnoxIrnYDnBCaq1prD6xupAxsxwOp6408HMXQMz8OXnIi6S5FtAvV+Sr8uYQvZ6bHRV7g0mNkscuCClqif51PDkmlE4hSHaRI5wugB7x3VCHptBqAOmWTzx2CekYVk/aaCPBW1eEwp3ZJPiN2opseBw6+JmMB7y9oZ/Awovu5hLsqxQevXEwaz3J5sGIfgrsI1skuTCd5AeVKYHtdVpsONcjzVby+JqLjds2JCz+IQ4ziicQjN5QKI99AOXhRojsNU79FiMZQ37oteoKXY2igqUKQK0OXKxcDWNnu5Q2DjES4uYA4rzfVr0YoMKNFVz69WtBWTGnpS/Xj3k24mCSFPbJY7i1XVDVucJCJtuNm/8CSsU+Msc2/RCX/tPG09o7JeQklTqDdyvN22WpT3njKb1DDoej9D64q3oxEDzwBXWcs0mHSFZ8U06p8qouxDQzxCcz50Io+MeYBSu6IkjMlhN3T+XkP1Bwi6J5gakKTvu/YCnuZXMyrjNiLsYRU2j/QGFQ3gw0rPwcU+TXf3U6YK0g2ozyn5Qq6cqzR0iCSgDgow== 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)(2906002)(8936002)(186003)(83380400001)(38100700002)(7416002)(6916009)(2616005)(107886003)(6486002)(36756003)(66946007)(8676002)(66476007)(66556008)(4326008)(52116002)(6512007)(86362001)(508600001)(38350700002)(5660300002)(26005)(316002)(6666004)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P5L57ixAGrPUgRnZ1njJBvhggtzW07HwzIOCPdB89Z5+uXwwpZmA5WQMKzfwTxEQDlxbdNTpQfLNQ2YZqCGd8nYJhZG8XNs7i3PiwZddVAz5uqQun6QWD7AgxqGMQd+5RcZA3zpHj7SzSvSjFJQHB+RIufDxWSmz2JPr5a+2d79MPkmPPQY9y2ltxAotGog5FOp+DrdOYKnpHD4aoDp9clikVledJrhkgeG5bVRzXAbaRBElZO/pTk0ITRxh+MF4zI237cf9sDZXxgaOfSUtvVDaY4UAhFax2i1dXrtfX9+kDf4+MVKATdIVKIPjX7IItPsuot63GhoVaawlmaBthdW8wCwZW5STQtPBw1zhY9e3owu1YFbJkF5E33AvBMSN2h8cM93Rvu8SENEZwFA67NceHxlO28cX/6dI605LNWPa1WiKprDR6CMJXFklmBqr1iDTHdoVS5QFfAFIfJqFIJAYx1Y2Cr/BlP3USvRTDPhTB6yiKAKAnAIeuI3B6Wbhf7N9o0CCUm25gmKGnqrs9LpsM862PtPb5ktibodqUlvC7I4G3YaqtI9cby/v8vz6kWIMfTJoKXKYxkoD57v8gLli/TmFR0+hqaR+A6ibT1mFghbRUeKQRjMiAoQScf58YXKzDHITx4XNmshFcG6/t8lsHGEJN+IEZJcAD4Vw//WXb7EMMge+t871caa1zUB444FzdR9PM9ZqxM1H6YjrsPxB0yg4pEEqfr+4tmv3E/MfymLXi1uEqW/S3p76IT1M061oiLGupGXh9bY1bo+575OkC8a76GMcE+HQUHHJiwmhl7rjQd7o3xal/i6iBvyaqzkKlOk+ngMlTMjbn/GndQHgMnxchtzuTfp3Csitw4TVHxwb2ApCLP7OiSHnlc7B1pj3p2zMR92gYNq+aG9T4K1cZbs/+XxoRTl/l0P5xA1MYXXSTRTB76LHzjAwasJ7CQe5mJ2lOwll5zg/HFEPNN7FzcGfNmdwNzTohs8kgp8Pd2HfpGtBl5mkJLVuB7eXKOtT7VB3QIdp7cwvaviCC5p8bF/jOdT9A0+on3+Grta5Mipq2kpWy2awBr6FLkeLnGxQ7OpIvDaU2ju6OQHb67noXQ+7Iv9vNN/CmqQheBdSBpN2i2r1lF98vIXM1juA7MYjCYdcnVNis7mLosEVIlTbcITfpJpG8DDue8eZeCZbx921pRx97ubPZgYI1xPhXLEvKJykZjR0ZuuehU2633v6u1vRxaJqy8TUM0p9darSBgLceYu9TEzR1c3Af2kKBefSHBjm0aZVnaWTe7OYjGFuzwXrJV9TDsVT1Tq2LgtY2wEZNIsIax8Op/e2PhvtzYYPJs+5gYpqnijRkdZH/mHPOHZFPgUTDtv9xdUEds1TVLRZy6VIg/dbkSqzG7QgLA35OpNDJtqSHQZp53cmjIYM4mS+NFfBg7c3czj1B4QoJdSVyPZFgwPGuJlBkIuo9S99f21xb2N0oiTWA/GPm9jhOYpkg9NBXkkcwuXIo7BYAvFyjMzzyN9PNw6ONqdeyn1NxJ54Jn9tMk+gRz7HGfxNHmQnAHixPalZ+kjyHFbrLpZpXadOFLIpx5c0A30uHHU80zPRL4YWCkgoawkQ9UeY171eFfH/skpdkzboPbpZtSryXlG1cf0X0TI3r+ewc1++vobZOO8MkyJT7vQ7A4iiZ4OgB+R62D/JvWiOd1rfEpVfy1q5GYQYtjpwS9f/fWzaCs4oaF/kz0eLdHdlvQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51eb6ae3-5278-4084-969d-08da224579fc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:02.5562 (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: erV2b4Yk/EbXnNAEjexduUHuVDdzH1fySSompVCWysTb/c9knN9dM3JOZZlSF8HUgLxWDzWh/noiqElCzjJ7Og== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3290 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: hcqtsGP2qzBly-zqpfmku7fEjD5p8akH X-Proofpoint-GUID: hcqtsGP2qzBly-zqpfmku7fEjD5p8akH 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 --- 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 Tue Apr 19 20:44:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819470 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 0DA4FC433EF for ; Tue, 19 Apr 2022 22:56:00 +0000 (UTC) Received: from localhost ([::1]:57810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngwlL-0001xW-Re for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 18:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwjh-0001HA-7i for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:54:17 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:6454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngwjf-0004td-0V for qemu-devel@nongnu.org; Tue, 19 Apr 2022 18:54: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 23JHlWl0020622; Tue, 19 Apr 2022 20:45:11 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=oZmTGkLPXBiUNCqqHVJMPikXg/B8l41giLDbVoT0olHXwd0t8DLgx2uiFVfDuDRVaHyq K/wXEp/+t4RER3UQ3VTiCzNbyHABmKogOEbNKHPPWaExrFoD8NmGzBP1wNfTO2ACTDaP EeFYYguSTWY0ZtkPu8EAUKtoNVNcbEGjlFqH9Tz/7NNu7hdcOWZ9LQsRRF6WzCR3+u3b gilzI4Moelsn8MJeuVPlDQicV3uFd3mZvLlGtQQk5ma1ip1SNP473P+CwSWseN+f7A9c WP7xblxJj8feo1ncx8mOjhCLBFxg/p4JR3zAr2teMTyWTFhEadoXPX2rJVpqvW1SVxlO zg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1793v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:11 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKaT5I034856; Tue, 19 Apr 2022 20:45:09 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2108.outbound.protection.outlook.com [104.47.58.108]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88hhn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CSm8WFTd/mwI9xtwvvbXxC046WPEo1GhOsaLC1UNngb3LcWxbZBs3Q2MCasVbIrZusuIEECaNpMu02FDbtJcj67Ystiy3yxNw+F4ByhGeWHRqDoZS9I/ujUCbPbbcOXJtGlFTpSDPfs9sxzP/LASqqYUkIlREcXxj0GH4eBHt+j49dPSdMivrYqcoWxKXJijlp5/0DCjWqhBSGCQTX2wGaURDx3slCRgAhgmz9WWEUXtwQ/qfG7bcMtr7pAI9NhrW/8XloK7/qqpXXIRHqYwZhEYv3jBLYlPlyCi4/XUozcP/WrOAzORS0/xdtTZN4OL3YMh8eUcva2WLNI0aK5ICA== 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=lYj7dlZE3yVp0S0TwBPjqMB8Wl58V0Z7TEfS4l0zJDUObsJAWtnPpVk+fVpPLrsDpbiUmsBhy2pyXqvG/RqTgpeM+d5wJkj6vieTvs59Y/85V3e24gOrTHRvgHfMleHkxrR1g8sVONp6UgwqoKSFo9Gzs1n+Q5M76juTxEb6GFR34XWbrn/JgIu4pPaQLFPdfVP3xpj/GG15t0T6ICNJfWqE9hqBytUCOoZTvX/HqGnV+RG2C+SGOLRyf/X/4l8+V18TqvIwvZ6qw2Yxkq9YFwO+EB6eH6iSjkDcOY5C3CCNoM4JQTvEoOE7apUt/B4XC4P4hoSD30KYyygtIKsP/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zwPhI+aSY9A8g/pGSugY9jLxWCS4xmeP2Ig6quKEBs4=; b=a4XE8O68YDJowN2dAyGw9i8SXfWBWFhSAXR+U79Su40OYRzkBP03olAJTBAKWI6DogmAYJiWPfZRjUSQqSvPHVsR2dhuhIKKVKXrt58bFbdOUhtB7di/+yMCI3ZzR459nzJV6p6e3VXlkF7nLOGfmucdnhfsd/Yv22VkzKP5Lk4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM6PR10MB3290.namprd10.prod.outlook.com (2603:10b6:5:1aa::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:07 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:07 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 09/17] vfio-user: find and init PCI device Date: Tue, 19 Apr 2022 16:44:14 -0400 Message-Id: <71aa2e4c486109174172e61428ad0c3c1da2f8bd.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 515f5866-9cc6-4cf0-5bfa-08da22457c55 X-MS-TrafficTypeDiagnostic: DM6PR10MB3290: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: Kh3j/0QC8KTWuWFb6LYjQY5K3PvD7r6+IzjYSt0Fv3ie+lRMfsSAlfV02gjSuOueAb8JWtLOWNJa7JTciGkWdiv0wDWAvsoY84rCrgePwjG6Q3GFC/sjjUYKNvztsT+kA7TcMmYcUVWhtkedrRuaxoq2y60StVxwPs7w1Ex/a/cbLKO11ntmdENYYbEiGxYBZ89kwbQ2z0QUtTzA7gK3nPPN9vakJn/T4cHnOpHEvqTaasDSIG96lwMgDWvYSm8Rbf4Tlr551BR+cFXVAsrPcZaXcwPxfo4G8MARBWQnbknu5K41tC2eXhY2e+L5Wr+6rERjMvzNYdIHqLfl8SgAC/BnGctor+VpG3IZldEaNUuMepCI8BaCGgrEVhn1SPs86cra8jDPbQQr/LaZVelAiVBRdGMCSWzEx4+2qe/KgNs2NjYcZ2iXKfOnRWxFK+D67NWN3OPhZYSGlXR44QmOyhHXlIQ1e/Jg+Bv4gvbYtfUEcnsC73UBTFMSDk0V6CMPG8jHnh6fCX2KYgqphX54/moaNH4XIa7SAu73dBHP0y1lU1jNa2ZXly/sy1Hn3vALJxrNMlwRrSurKhA70Wqpmb/RGqPg7Wucdb7rCCaE1vRqurJJ5Myo3n5e24XejKEFWFptXQIMYIgmFTavUmpD2iQNw8sT1XRM6xA5GBmoDfNEYJrCKRb+X4BbQBxEVGIb4EfkWEyL+PCWF9g5Kw7b1w== 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)(2906002)(8936002)(186003)(83380400001)(38100700002)(7416002)(6916009)(2616005)(107886003)(6486002)(36756003)(66946007)(8676002)(66476007)(66556008)(4326008)(52116002)(6512007)(86362001)(508600001)(38350700002)(5660300002)(26005)(316002)(6666004)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ewmgos3k2kftDyR6X17SnqNOMFwQ0+bCFXcn1Vzefm0NRVFzgZ/HYEOH+cUNYARslQxGhOxeDFphOrlsKCd7Pd/pyNVhdI+UCpCnve/PStTF1ToQdPADNAAgr9r+8nuHKFKqqhm89qFdrvWWhFLXViRwHOvBYXOobXhEVb0fXDkMVMDXhoHtmFGsuoYb60mMXOx+mDl9Z7Gm/runUe2RRahf97f2xdDrkgGliZ1SYREMjyfvnPU/uki3jIHBbyLxFAi1KVJFGMS74QMN3Vb88BWe8Oak7Vt4Gn6TySxL0uC2IdCNOKLZQ/lClJDhHn5zXfUaKoMcVOXRrmTbsaKe11Thmr7GfGUVQSnByBgQJ+aVYldkJBkQt1t63oRjo5mHH9SdNQ218vSCDPiFFa1IGtzN7vnoDGR3MwDwDg7xujKqzMiYHqpbOhRLGYU8M9ykUeD3+u08g0afRv/912AvD7QlMqKpu0+ZrhpJXpZNYKFNwHWElT0/0irVEcezKEnvmqsV51D4boX/aiLOijd6NxuldB5HbMIhSB4775eH2fd6LLFNHPqrVDypc8Xd4Tpb7QtcEyuIbjSTW3Qq+2x3bukTXTh6H89r3QBBiMga2wrRa6Z16XOcLyYYoHPcUH8E4E8/v33WXDH4W61P8s8OnMunNfqY3yehxXrIlI+uf5pEIovZPgGGJMEi9TruZ+Ressaz6f9MrDnaBa4BE/4g8WbcKZBVsGSKWNxLHCv0VafQ+9ZwTiK/5vBRlF8YGsBFnEeTCnN+r+P2F1w+iK1iN1PrbdgykcPjVOnVJnOYJr1adCeEgE/3qj+D2Y4CnYig7N02Ks5aKW4DoFc1UTjyvXM/06rkwpEjfc7ikIDvNJr2UT8eYslAwoEfq1LkkD9f3CY8z1zTRXsZoeMJw77OngB9/VUOagpuFsQjhjSFcNT8QRMGgeAZwstnlscENVkXR1wMkRCQqHkLJHOs2y34UVunx3ckBqv6+quxxlkqvnq9veVf+qFAtd5/qbFI5ynjO5NyPgsYthiNj5SZCUNEfhIsRVTZsiBWRyUzjB4Y3AC49QuiXvOWa5lj5QxviAvj8S+d69GCU2FnGNJ+iVSKX6ymy2YrSUdywWXa71owgjj+Ur10ZlP/mg9Zunrc+0rCA85sJihQMhj2hc6VJvpb1ZawouFVhMhU+bTklUZ0AjmlMAnTZNnfM1L9SriIjHpGnqq+Njq+gA3eYYT/927nWQny0o1Tih2NtJ1TanJqRjSd2ZuTLJemjT7TM7rxJ2SAgq3y9MDW0cTQ3PH07ynjqH5eAAnM5Exlkd4rKjIWr1X53Mi6HuOoZDoX4ksZRuYYc2Nl5BGJ2H1r5d1TSnsiXgBTDX612qGyc+AtvZlheJdAAw+RO6LfEz6AfiM5u3vlF8+KJnYc9KTMNdo8Jg2kEuk2SY6L5CzX/gZRXJ80OVUNT7GGKSbqlftsgCe6uJ1plBNeaHLqhKP5hQvnaPmZrzk+EauGXKrAmc0al6fkqkYClxWD1nW79SAhEYIUDzeNxEfs9hbAoXkFMeGnJoCUGSWokL1be39XFtEQz+7pFZvMbvqIa8uGDwo8X7FXmmqPpunhsU6qXgSFRVehKE8JFcjbc0+q+oZyPhE9LXBDSKrAa+7h5l6F7/gcBI+d3Bl+hIOrBgImNKhpMgCdnIqWXixZ5ANrJJTYxnXu7vssrQDH6iT7kgX6NL6pabibwZmJmb9ZMezPEpXjZDhL8VI0FYXi2P3CkXSvLKlzcMy5tmM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 515f5866-9cc6-4cf0-5bfa-08da22457c55 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:07.3058 (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: F1QentomKAG25q3f3NRzfIrl2TyvhNonj70fb1ycst0c+MDsarbYs00tRJoC1BtMZsROsU6QfHUFSRnaft0wLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3290 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: rNi2miQfoHGM68_r7LIqmqy80llLhvQU X-Proofpoint-GUID: rNi2miQfoHGM68_r7LIqmqy80llLhvQU 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819413 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 B701CC433F5 for ; Tue, 19 Apr 2022 20:47:40 +0000 (UTC) Received: from localhost ([::1]:53728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngul9-0000SQ-Eb for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguj2-000629-V0 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:29 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:6216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguiz-0003Oc-HB for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:28 -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 23JItnla024789; Tue, 19 Apr 2022 20:45:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=AImNOR4aVOIcL7ia0TJ+Pgoe0tp/TU+I7NELSc/Bdxg=; b=MGK/pikLPuuistzpa9TA5+V6Ib8LFKQdaeTub6Fa3OtPJAR263HuzJ84Uzt2ykIOl1P4 kiztl69R/WzAAyfrGDAXYgKCWCCHzhSWXPh3koD2gyYh4nUvroFHkggtjk0Mo1gIeU/e 0C38Shk+r4dsb6JqQb/QP3StIE1DUzrHwEF4DViXSD989a6P91ehnP7bGP/XScERRtxd YlQDoxvBzNZ8vnzknbfUlRYstrefp8m5T70qCETi4/wOnG/tMJ+ZWHKdmPGB4QqBX3sM XwXkMQjAxNgUC9KxtlTTv5Ib6PP+8IxuYru/9aJMiOCDH1g5ODj0d+jsO0W8wKWlC/f+ lQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffnp9f2bk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:16 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKa45o017127; Tue, 19 Apr 2022 20:45:14 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2108.outbound.protection.outlook.com [104.47.58.108]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88spq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RxBdVliXCzD8Jmw+dCSzfAB5uud7DeZ6a0QLlbIJ/NyTGiiqFIsUfcMxFo6mJvYAJyOIhYHHHRpE0/7i/9c9mvdI/oH3GWkDer6Ujr8sVMQ+yUbExwZjHlbo/EGVg+aNGWkGOjmuLTIj2DSLS3MLr5YshGRjHuak0cewaEp7QP1RhCtjI4+Dv1CIinDdSqApUtOAwOj73uhb3ocWG3srWg0oFCn0xxWfvXnOGdKHt5gjZz72AbutPrMizt4iXRbuUoQXt19NC6wWIH2VyY6mJkVu9FzGaHQw73E8x7SZc8lKr2wddIdjGobwaEhiru4rnnXT5JgKBRm6g0tudNgzbA== 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=cYnMHMDqDoZM9BBInzsr8zxKev9UNkOzalJTv+MZM6hfngJinEAEAc1yZVBfXgvmDWHSPwQpENXYoHSJW/OBtffOgxWBII/akPAezTdAuepPLwXXIPPm8cGpETEPT79yNso1JjWJiYMUU9BWqVzlc9kTE6t6UI/J995lO1PFcbYcwAv9xeQrJDyv/FMT8zEkTVoR/CeQAWVqY/Nv55aVHSOvWSLH2HjBM6cKqoJuKCccqO1GXqsXToLTdIRwuLtl9zmuJ/b/+YVy668tc5pBG/JqyAtb/iFZxVU6RztVwNHzYwsndjtYhKRAz69BWY50MwS+nRalwX45Ycgl5O0x7A== 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=RCotmitTs+DhshWVSdOv16qCSTY2sNJtzK9UTlbkduB7Y6SoVU830oA6K3YzkZTfxbytwxVB/SOynB7hiO5z/JmlT5KgR5GDtNAj7B6D3WvnqSgY1AZRLkdP3yU0/aAElE6NF+TGIxit6Ja+VXubuIjy6N4LztolX0o2WsVaNJw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM6PR10MB3290.namprd10.prod.outlook.com (2603:10b6:5:1aa::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:11 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:11 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 10/17] vfio-user: run vfio-user context Date: Tue, 19 Apr 2022 16:44:15 -0400 Message-Id: <1f71b01f49b461a41130ac9d19355344c3752f7d.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 75253a4d-8f2b-410e-194a-08da22457f2a X-MS-TrafficTypeDiagnostic: DM6PR10MB3290: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: feF5OoNPjylyTPNLB/UL1r2iJMt8Mywv6chB1qTjNRUUcp7Vs7c9mGqXF2PNSNt+EW2bnvXk5Bxtzv/Y1H6C84C/COIIcFYc+dYXWR/WOZhZCQAYErZS08EO3tve1TnN8bn4kRUtpTo6cNYEgkk/9ufFJnJR220h+g32/gbkBkONvhvU0ku4CXHb3U4Bbtq9t2qXIs1fbWwdBzv291ig7jo/Cj10BBqAN+K32qxBX4I0D+V7qTgiSK6e2heUhxyiPpycXFnLWKXoiV41VAifhDKhXvzsSyqIvCPe7FF3OCbpn1c3tteb3bVOsbino7Ir69G5+Ulf3m7VirzLlMjSS9V8O/lmlC6W8l8qvC59rFqAwCh3nLxh0KzumSyY8o1bnCElUTleeeUso5I63lTCMddlASYPiCJc6me/wLgKDvYtOwcm7JdSH74dx/xwej8VDIUKYCwXf1OCItqMJsq/P99WDJ3l0Cw9gn3fdaOiFvCNsS0LVL6Cjz45iD+CU0BJ/tiUlxRdwQjhsxk37pgJKV+/Uqi/csJJqt3IuLYY/9Li8WGYKqA2L+uekiNfraX6PIHnU5b7mUAYq5HrKXtvwSGSJLYzthnY5CSK/Qn2YoAA0q2SSkcF2tBTSn+usm1Bh9koH1658QAo8UsNUQ0zDZkioqVi5Xi3w4y6tDcOABxd03WntlNXv52I5mvRsZs4D83+z7MhZ+QQo0A2VDg2Dw== 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)(2906002)(8936002)(186003)(83380400001)(38100700002)(7416002)(6916009)(2616005)(107886003)(6486002)(36756003)(66946007)(8676002)(66476007)(66556008)(4326008)(52116002)(6512007)(86362001)(508600001)(38350700002)(5660300002)(26005)(316002)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vgFQzyiZs7kXRuxryoX/ywrHpIdYHLBP44sQ6V0qh4OHZtrUv+7aiD9glHWuEmIvtkL2MfFxnA9RDEfJU7YEXXys4jVvIn7Pc6OwXI60aG+oQXUodr5h9Mq26RDu8E6i5SNaYzNgerf3uiuIWuxcxpyHuWObOrUG8c9SWHOZmn5dxBrqrEcvdW0AdS8cQFfc8w0hwhJF9StzuPOwVyTGqlcW/4rcoQUmOdGyXMGEmvwaCT5od0kR09IsfzRWQ8ViDrUwKzaj937mxdvbShtIage1bo6Bo+QYJhhbpRCK6vwvVhcjx08DduU/ltiWqlKjKnIRwMtpo2Cra08S2FXiyHvlcHXTCUQfKMrHvMiQJUqmmIvBTzhRsk8uVjtNxsESheU6lTepG4nz90+z1POrchGnLTvBFf/+G8GaaUtD6T6l5CVL3MdFQJBr2dI8nFCAw09RXqfhqclx80lXVJnfXSia3JADCpcytcKggCVJJtAwJbdccII+osX1HWGhl9//8TIE2tQFEN9P+T0iU6Y9dqY6Rp748we0aJLkBlXrwwEB//LP3JZX6FFp0P8CXXvQ9FkJucNIaVB5M+Ml4epeSy7lmC45nOwPSW0/jpWCEqTXFh2xu5ox6bmmR1oH3kIROHCwf4TjvyL4YamVMMLGALm9halL2+OOtqfiVlEXjGdt6ZHlL05T1NmUY7eajXm87kMvFuZv1Z6cPAdf1Qf6hCTz8FJs3esp8dLaZXycRSQPWHAKp0PDS0F3NEzwKmDdXc3S7MY3kAtzrgQ7T0/FxgEBeJCcr9mQTBR1zVLmItLIoi5NYsXgdJPRokeUsU6eEnwzz/QdxGpE1pxrx3GgVia3bL4VR5dlGA7qrRgLLUrkFLOM19PsILv/nrjPr4/iN5n+Esdsl0MZT9EE4g2SM1qruP6Sol7AuER+VcbMssk+YDnkEVAFLsdJSBUgAD9GFKMWK+3+nTy2stO7w9sAAsfdvAN0G/c4QdzAbKd9M2RQzql+3gx9AcsFp5BtG3UtGuCm4yFKD+vv8uz8+uFVs/38pY2fZBzzz5yIDM9LzlG836w/NMizBIYl/vvSkmCWsy6fLlqSc17S4lz4uKQ8A4OMoHQZNThLuHmHIwnEtKiwJEGv8g6YFIKfxqiyL1tRBSkDpRDBfhNyS2kGzw+5A9nfj2Q9CbKbeCbNTvS2ARa7bi/75nUNTd2FXUkhBnUofSpg1lpj63ftBqES9b5f4O9iEHFWwemMV361YfW51sIEdczFpEXdriUXUBA7cHGhw7cTjR3C5b9YVkpUARzx5YPcT8JuELwffWlygYumWy0BIso7soo9C+oXxrL7qULd+ASQqn/pGFGheGBacgbMKVVkBHUGN6iYJnd7W4EuUalKw30uzhBl+YnKNpiu1M5DeGUyFibxZz+A6y5wjad6LTmGu3RahAga+hQ2sUarA8dEf9uE1aBXxK3GKq8SPBpjqJX7XRuMKB8vGRo5c99JRqSQdDZA48rzQI8320suTbwrCzs+++XNTJgTOW0Jbj/BxLQphn5HrnXTIksblhnIAIZTdAbAoSm9weK2Z8WLy1Mc1vpwp74iyZDwvmSO00vhVrpMlb0WUAzJa+k9Jgsw9b8OPQXVvVkQHXcWIpA0lO4iRbRRPLTL0SkVX8OZWgjaAnEec0/DPf1UPTFVsAJI7+W+PycdD02+jto6ItYQSeTo7jO2LzBcvl0MXiX0Ngghrslgoo8LjBLaYLoVUz3G1SPA2kpl3y2zyDephofDEe0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75253a4d-8f2b-410e-194a-08da22457f2a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:11.1493 (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: /gfKWW6ZwGXV+hW2cKorSflKP4Uv5exXkbGc27JMIbF26ER47wouMy3EHGs+AHbd2F1RWVQnpTE/NNhdA5moOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3290 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: oqvsTZASq7P30Epz0KDaJPGENJvNjN7D X-Proofpoint-GUID: oqvsTZASq7P30Epz0KDaJPGENJvNjN7D 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819416 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 8E902C433EF for ; Tue, 19 Apr 2022 20:51:08 +0000 (UTC) Received: from localhost ([::1]:60284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nguoV-0004zf-7u for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:51:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguk0-0007bR-AA for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:46:28 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:11122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujy-0003Pb-7M for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:46:28 -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 23JKasAT020195; Tue, 19 Apr 2022 20:45: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=O/LD8FzeijjBHt4w2xn2t5nZZdlRJd4UWg3qtwr/if8=; b=GKnaavoTKjiczXiVyAMxVBqZ4n/MdRVsBvDbBNkKWLu+hZYwXaw2DQiX9SzAVozH+DmW O+BH0vV7FFyEU0YfyNYM1WHnd6bozvUi9ILX7fKF6nJL1g4PiaxZMGd6lhvOWK272kAx x0VH7jFU1mJ+1XAQi8eTj6b4dcUYmb1Q1jfLfmNhm25h5rHpF2Fr8awqalvKLNWTzQib /kplSL1bds62CsQBPUr1QicVHW1xN2iPi8xS+j6qNQmDj24QqGaJ5DnURSjsIh79GsbC TwgVA6txNHx1on6u+j7edx+2XXMhC27WLnyN9u1906MO7cc4Pmex+UDAeJjrQLvKq7BK lw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1794c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:18 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKa5D4011289; Tue, 19 Apr 2022 20:45:18 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm8389qx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mr9uVtjA6BTmSXbPd0XSjc8CC1JDYb+5atpNN9nyqxzMh2Dl+o0Muwj2az4xPZteWz+ujgN5ZCqu3ZaqQ7jO+A8AebpJB3bLSQSVBJLhZGFVVpn6eQL40M7tZI7Z8FfnbELaS8YFCoGIc4LFUBW0mWf+VtbkeBdNMGwElTpPIZQDVftjnqMBSPp2c7Hx+TTRtKlYUmtt3JMN1IdYHtfXKIawAYjn0sh6ayOqtlKHaTCBs/M9Xa5BwdqdJHetdhhVgOFtE0LDYTISNHyZbtCffr219YZNfsoPxfix7YVIFd/OmRAKpoMm3IRZJ1gMe8uBeCvT18XI9SI0bZRkCy83pQ== 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=O46Bn5IdXT8P6+GQ93Npmm6jg4zkeyga6OEl2m8p2I3+NPwBdxb3SUaeBSC9335/yIT4/q8oeUHllN2XqsHd1EoqiQBcBVJuoEaXzAzUqMghonLai0tAqtENKwi4rLqSCsGTclnk9pdziOYIjxFQ+vY0g+MNXwe2NsgrLgqUj4LzxxI0CqD+Lle0IYe33FwUDJ93xWLsUzq2S1UgqR2qliCvpQ0qdkzPNEJBH5CdcB2GQgcXYL0ra3abcef/HSGNgHOs6ku3V4TyaoFXR+VzbfOrCQOGwEElU2Ab+PRXTlxTk6yg7/zJF+nSy8BbtXPwjLElgbrIjmzbxJgbj/HoVw== 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=kHz7H/Rw6TXtpt1YsNQ5wghX1K4SPzQt+wbUKXF2VXcNQgccWbqn2KU5wzGLDA9EFlRfdI+XvoQQhUgBnBGhU7RxMCjnpSpabpZFUX2OoOpcGCVkFAlB5Mi/YE86RZFHJHjuIFyjaDf/7ealNoP6J9/XvNv5XcqX5x3jyjO7VOQ= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:15 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:15 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 11/17] vfio-user: handle PCI config space accesses Date: Tue, 19 Apr 2022 16:44:16 -0400 Message-Id: <83984da67ca116313be77eef1509d3276e1775c5.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: a822cb23-ada0-41d5-553d-08da22458179 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: X6kWiS+8NK9A57VtnOGuZHO1fWFW5Kb4Ab0lLR2ioXpDe2rbGkC9fFu4ayucFioyIIT3uKCMsnmb+g+2oLn/Wzt6py7S3IiPOLD71CZy/fZApJYoR0EMBE9gfeoL7xrOKtk6YDMv/7vDcu6+lzCrYLOVTKukSbuT4EmM6ru9e0C75TiQF2kZZ8mLhGHdvmRwzANbiMHE6lUa7E4Hq6HJTMeW9Qua9DGDYxjAIJm9x+g5gQpvxRdZz4fZkND2sCT9VPpGJ/VvBGHpw7YZ8CF6fmR1I97t3ZwfNik4Q8KvjHcCcSmeNRVDXv8j6Ms8K+4oO4OTAuFVcfdhmMx+OvJJdZ45cPCaCcaoJ0c169g7lktfDNR9ThxKvRVgmy2natztt0IU4HjOWKeGPkKRy3Ru21R6WQ5YmUkzCNKgaiPhDJgqZKGLr+QHMviA03WEz7Tb/1yQs1ajJ24RvVcb3y3kezKvLPG1klavy6fG1twvqmgDVRXKifbRwnxSJCsrfshqXjVKInA4hV0rLdUr/ZN4pfC+ye5u80opdFYPH10laxMMBUUuVnE3XczLVrPySUzNHQTg0mbOI/HNKsS63PTTVrbbL5X/7wUYZY9A/w5Gyc/v40Y0MiRIqnmtkY4iBCfIc/JwICu5ercDk8bFUq1LTKoDq4en3VY12DBV8UxNiw/DbMf/W8e3O/o+6MXaGU2aoT/wnjZQGOvQ82Qc/U7H6g== 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)(83380400001)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y9egnp0WYWk1H1quXCI9tnOP9XbDP7rG4knNJuxzQT5WTmH8R6t5ytSEbEOT/KTW5rEpEDB8hu1tnWRnkXUn2laxPM9HDsZchekeedudeQWGK4KjV8K5sQQbqlBqMCnFq5K9XOb7YVcoMGanEEQlCFcAxN7QbYK61/g77cPnOdg+VtX8ZEYQZAeJwpJ2LMipanCbs7Sp9D+whbh9jUkau/DOOumgWNIxRN+w12n4dZHFgC540UEBRpToh+2oV3uOtIzzODT4f1qy/c02uZXc7lWdmvFB+P2CBkvwec2Mx//l7seGh1nPK35xm4UWeAAXxUrHoOmdI9VivIj+j9DvMuIpXl6uO7MzIU5jw/DGyszaAKBPcVFTekNs9EmKU+UujZGuEDSaXYpOsQeOMoMg9t2cHq2DsviwB9Q9+eI6ZlenB1/lu7ge/m+4C99BN0U0Y0Rr8+yNjlo9gXK6CANBSfnEjWSv/j0d6AJO0SVOxwtfbXN9e1RzkGUbRVh7hI/9qXlYBQPHwpyef4eTEI++qOaQnwTUY7PvOmgwPZM7fIjzeCTcoVXyfmNafH2JO8IbJFfXlEGXHncViKqi3NQtNxf5G81i0L46I9KiYXbX2N2JfDDvEi3bolpKn4u6bgRjD9ogYDdF30QkIE2yxT5x4OwJ5xb/efYQlPLt68UZyl8QLnNkdiQEzmZjXtHLNGuZqWiq3LyVPjAmnaiTgwWDVpCREJVkgk69rQcYzDVuTt74jYTDgDDad7ygJpZxBlVgLuhlYSHllFCOgVdDbcd8DIKFP95QAfNS+pHQTcj5n1P1eqecWa+a9c7h1aXQoap67PkmI4B/jS8OPQuP7beAfindFlTVPhnWTTgrrirhXsCOoMXxmHKW5VnIyHnL5Bs/hPkXk2DNktX+SsSVkKGHjFeVTSqdUHmOF0wYjslkjwWXOMF5QIttBmQnKJuJ9Zx8SHFWPhNmaZRuLdCsg0JvykLo1jfcssOwokLIfJemLx4hQTSlAzt+/HKPjlNsW97Y8vTfF4XoGavun+oO99Y996Jl0iSNX3dQIr90vVd8+wO8QujnxuuS40ckUQ0cl+jXprrQN5zsnUay77h7swxrTFeWs17Tr44y39wx5PYTBj+obHdosKua6mwjwU3ySfCVj5PBLR8xJHcEyFjosTgkE9fQrWVqEFfwXBoLGtA8wAwffw8B+YSUH1nHInPbrCL9nSvi0GMq3nIAy091mfVMilfmPX/AT9nKFNFkasF/bXZ91O0AgZSbl0SL5K4vqqiYx+Eeeco8aR1vPr1DluTr8/7gwDUwTd6I8ReLfJ0KNNWuDYHGf5F7i0SLnuTmpG6CjoxJqTxjwDmVT99sZOgncT4JToBuAsOD2+GhQc1mQXjqYR6yzvAowfbnNm9sKFXDHDJvC1QeDXpUo/JznjH/QutYj7ZcCpT8ti7CymOpkb0FtVJhj/8SKDSlwX9e6W12mPRxHqCitQDo/aN+xVcWWwUbRdCF6JZo/2IHiirn2sVmlKT1kkIjinwDpc3iCSdqR1X8Xmjpv+mPutXN2sNAlor7Hc+EF1K8MBqhNSVKOaaTfaoB0Cip6kuOcxRgbXpo6Hd7k0CaAkyAnpyXvqK2+Fixam5A7CWuevGgUhHzr2f5gBK8bSbx+S/NQMQp63ni1hw2iu4Ci7tkeZD0g1EQ5sERCmVIcJGuiFoWwsXem/bBmWzfFvUR+2il/niXFvd2vFtc+eo0Ejog+M0IdzWi3g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a822cb23-ada0-41d5-553d-08da22458179 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:15.6333 (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: vRUOyEK5DeUWJV8JZuCpNRkcjjsVreewOnNATd5vYifpsxKcf/ReT5Odg5vSXTqmDzUNswunUK/MV0O06r/stA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: 4c9gHZ0Vw7VWqQgUuIGLqEQG7DDcnD0- X-Proofpoint-GUID: 4c9gHZ0Vw7VWqQgUuIGLqEQG7DDcnD0- 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 Tue Apr 19 20:44:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819504 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 22394C433EF for ; Tue, 19 Apr 2022 23:20:24 +0000 (UTC) Received: from localhost ([::1]:34738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngx8w-0006qZ-Q1 for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 19:20:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngx7r-0006An-Rj for qemu-devel@nongnu.org; Tue, 19 Apr 2022 19:19:15 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:48522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngx7k-0008KQ-Qb for qemu-devel@nongnu.org; Tue, 19 Apr 2022 19:19:13 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23JI4EZC009605; Tue, 19 Apr 2022 20:45:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=RlscMOJRrWxyCic13Ics/cLdDM0/3g5IkmCjSpKNxV8=; b=c2OKI2XJj9iGFJjNoUlYltAiKo+6ZylhqC3FuoqE6ZJQsKY9xhMcCkcR1Ivew/y5rWrV y+Ma6Ny9WG514cwlO7MNxdfkAC3tfb4lWAMpUOm9DlUaC8xwEle+IzZdziIoWMfM39sk z9gaXwFWwS6PYuT7euRB7fE8JrEcdKmz0d4fyg3lzJ6orlQ0GpKCN5+kxFm7MnI1LaR6 xhVYdeklXKu/OrBzz4ziMJjlnlwqDv5fftTlAqgUCr3+raBzr8v+APouF0xFU/SIoEet bsrmKznXfYMW+dY8nmjJV5K7xDKDBkUVRr+9b441sKq+wxljEcYDxhIyYwfjumo5xelK 7A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmk2q79x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:22 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKaixE019904; Tue, 19 Apr 2022 20:45:22 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm892n1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XB6SElNiz/Lctsv6q6xc9Q54gK6pINRTarPmMVteMaq9wi+IfGMpBgO7GOtaQCm1ucN5L/y6JRpVOvUWxJBJsjI4+g0+DVvuyFj2nRULOJh+bfFm/HpFAejpzZqgaX8Sy6OJGJ5c12ilw//wPAlFZ/RE1iPSrHNSkwPcSTSM2XYNlriKm34jgk3Dnib9RJsPWe7nmGj1l2EWohV/W8QnNl4wCH9ZERJiENm8Mvym8LknI7yYjjAsGX0WLrJJUAOgf3nT04wcsz5MVTaiwc+038swAMBB7ubr9smFzazFu4spIAlkJ+LTSJ+joTIltZ/HvIkHbOqogpPOnLpHOPh7Bw== 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=RlscMOJRrWxyCic13Ics/cLdDM0/3g5IkmCjSpKNxV8=; b=OPR0TKasiYdfugAd069lyPhSlTZJwkMRb0P8thJHoXA3n5vKvwEhcgVLzxR5Jnn9yBkr8tAlRPDu3Ig0w6M3W2f8Lsusl1uTXi9SEZ2n990Q8hu/tzOePiHa/CR84pv94J1GR3aYUHxhpEmIF8e0dXxDSe5Y4uRzdRTJLyt2mmsp4F9qrPJ4nkN/BLoc+BOG6dAB26RZVTcq0LyCn4hCXxGXd8cXtHZzC+o8sJ20trhNs7314g1x3nnIz5t/INqr8cEXSOUfkE6S7XyoryMNcns8JNfM9gQGhNstrAjAKoHcdQrb7nvXsIsSuSfuiIwyhDLhKGut6QXj7HV5pS4xcw== 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=RlscMOJRrWxyCic13Ics/cLdDM0/3g5IkmCjSpKNxV8=; b=CT8RMuLJx4MVRC/xZk2Xr+hX0jF7SQ3eNGCAEy0NQVd4QSOYrD/03Eh47Ab9wenQu0lxwD3oIi6DBrsHYHDl2Wv7kXMSkwiguHMtUMW0KnLvYoT28VAhvhk86mXu/+Pyr+uAQs040bjaP8yvlI6OQeKqqc3KbA2bB5cf5cgZyS8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:19 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:19 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 12/17] vfio-user: IOMMU support for remote device Date: Tue, 19 Apr 2022 16:44:17 -0400 Message-Id: <2a42664b61cef7cdd44688679b60a8c6c397b075.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: ba5ca14b-aee5-429c-8b51-08da22458425 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: 7DA7yrPQNEv36yk+mIRGraqfcY1FBEWJqcnThY6QUvJK/SfTQdYIXMsb6MIhHM2L6vyUkX/ySnoC67tS4vCXrGFnD6eRdUZU3VtDe1zOjdziIrDBNiwg5ksjE9Za1gvVZBQ8uLDGYmT4hOpN8ZZvt8EYk37u3vVDyyAcqfcAj/O0HEe6849cKUR4/e1+wIZr+DZTF4Zba5ebGs9okcC7UEK7KmyZlkx/JF/gbVL/0+DFDoEs4rzxm48G3Be2PA51vV+seG/Sl7HospAVM0sNZDo+o2DBcZq+mkNM3DK1IR26xeCvgz83YLr0AgCK5tHgXH1Xph8UPEmIfKXFMkx/T5AWFeP3Phg3PY9L+HIvmnVs7V8sLNny+pB+X++Y0CPZrH2WK7fMjNUUHysQh6oWS07TNoVTV0AGvRidxL74jxAUcg44k7AUkFBvfQO7U1LZOSPhVcoBzGGG1B1AqRTQQDAl8sqWZvCQiozRMvN0IW+LmTVeE+eGzIl4i2OxYDU8/EdIj8DeJkXGehZTpvYMugi4UNR1cj3Yc8sM8W7orb930Apns9h1F9oyP/yxOWT1OhFs7rj87Xt5j14W3Bg4ST5gkdM2CEwQjBt/JPpBxk041aDFbDsCROwpJnqHFqNiaYzonDe5bNNA7altQf5dmLk16RQGmBBq/kVASDLgJFijAGNijsvdxrMlvk22/Hhn6vvzGBWhCY6FJtsuHItyhA== 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)(83380400001)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tJFpkrHerBx7khVXpzPxqphhR96n?= =?utf-8?q?nUz2/SKc5bD/QjPv1eRqk6Se5U6vdhx3WRI1Xg8rfeJY9Hff7L4UzL/4eReN2eZyn?= =?utf-8?q?C8aYAT0TkMXmtcjFZG3GVt8aXprC8jNJvK58jmmDnJB/feAXhcE38xCyHvZVAHWSi?= =?utf-8?q?dGAFriLVOTNeyOZo37ryagUC6BxMsT4qPm3jb+03/1jdN7yltAUhE7OFO37YX/Yhf?= =?utf-8?q?ZCTdRqVAjRFOKCkPetd+agK1Pg7m/HKk9z3sMj9XTzRAQ5l476kLiIOAEgrTu+CwY?= =?utf-8?q?1T/3fj073+82RpqzSRM7XcSPMZ7Psj2VwHqJFgI8ItlqYBIEFof5bEhqoV4Amm8FY?= =?utf-8?q?TQT6hAewudzKotovV8jpD3KLRmVGDpfUyZ6N1iqdF/GcEh3KQgvKZ0A8QsgiAo/BW?= =?utf-8?q?+JIlk1HsjgMnxpxpMrZoBvQ6IivSCF1ZeYWXKpQMWDzMZw6WWzQ+H/XFjI69sLvzs?= =?utf-8?q?hzAXSHerBAQ9oR+XNEpxBKmuQD7UAlb1oENiXG+h9uQXgmK9fSqYZWhh2rd33EVcs?= =?utf-8?q?wcGemayxiBpadeCSLajNMLoxLDe7DREWUtM1c2EGqi5q0Fyb1R+6PAYPXUQpXlqIh?= =?utf-8?q?lKfZAAdxeDdsQHgH0Y0jGiYmkZrzn/hLqmF6YFtVqUa7K8xDJqT7294yFF3h3KNTJ?= =?utf-8?q?bab1yZo0NTI5RMPpV2/S9D86B/sji2t7wQM8efCnc+Gc5og6Kmh+rblKcZw/Eckur?= =?utf-8?q?mHf6+DB+kC7PirlPobUWEJ8h5RtxQR/TQM1nGYb43NsQnl/elmxGuBuCj0mTF8QQ9?= =?utf-8?q?E73pZSeobd8R0FkuDqzgSJBpvVtdLDOH66LUVLcdETsODxYxUMzmusbYxShyO1xCZ?= =?utf-8?q?MA/2lVpFUiQE3dgVBtceYF/vR4NYBZhBAWakJnROGp6/mmEJzX1gPiDcscUhBYoLN?= =?utf-8?q?MTM0pp/MIoqh/+Xv3d9SzYmgiPqo5DUCPIsbqq2y7faKQirJgNbbiLzJxwRAqhnfq?= =?utf-8?q?Zl/QEQWFz5d9UdfARhEgNsnaiW0LaRJhs8NtNRn7P/1A6+vUBwQEiOOIp+c964Cqy?= =?utf-8?q?i3lsaM/ihFyjUmLGcvqZLFC9GURxdV8O97LcTH+66coLl1kl7c5ojCWR1IKoo8uF3?= =?utf-8?q?q8lrKCJ1cSrmcBFqjmTpK5A+UGu5cMfB5Jt2SJhybcWGy7nw2zt8pUya3BvkCcxLX?= =?utf-8?q?PxZkLifWRcRT6VZJk3/U9mAnls7zgoN9jBzm3xysnLA4oVDxJePTr7++J6LwB6w5y?= =?utf-8?q?tpFZsIfe8alIMWvxcrUjm8rca3b52OevCmSQd1z8Zdl78MkZQvMp6ZUFtD6gcwG49?= =?utf-8?q?nATzrv7drs4KY1pM/Cd0RAAcd5XTTz/hs238csZKv9jm8Kw1OSFmeNg2jwXCS5niS?= =?utf-8?q?59Q/FG5CxPSoMjQTdpWQ5CcOkx10ZoZSef7Xb5h07W8d4w66mpUd/1zuSmP/Q/1hJ?= =?utf-8?q?g46HfJmTz1yfF0bkXhrYhJmaONMMaZAGEkZ/Ji4sGqZdwphTAoMQ5UaSjV6YPtOVj?= =?utf-8?q?eglviQC/Em4LOW1CHklF3AJrvdLUzFuLBYbYt5bqBnzCCOdltm+E5+337uvwQ8tXK?= =?utf-8?q?unBC1sP57sNVEINKLn8AJqQ3OmBDliK/4FPfwuhwbW8hMDKC67S1whyVIEcG5lJhH?= =?utf-8?q?LrGXJyoTCKKjAmhVO9vMoa+Q17pJNg84Czvr81hZ38ShL96EGeU2QW2/DbJbTmdRc?= =?utf-8?q?RpNmCfKhFhX7/a0N9QY+ZwmetCe12yWw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba5ca14b-aee5-429c-8b51-08da22458425 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:19.3362 (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: L04n7gSwIwErs7QG/4Wrn/xC+lGwV/3Bi4YUmH9nQ3eI+2mM1XwMO025LtJPCnD4+YMATJtn/HH42fBAA5Yeww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-GUID: xoQdWExnYrIqFK2ovGpzmcARF869R52n X-Proofpoint-ORIG-GUID: xoQdWExnYrIqFK2ovGpzmcARF869R52n 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 | 40 +++++++++++++ hw/remote/iommu.c | 114 ++++++++++++++++++++++++++++++++++++++ hw/remote/machine.c | 13 ++++- MAINTAINERS | 2 + hw/remote/meson.build | 1 + 5 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 include/hw/remote/iommu.h create mode 100644 hw/remote/iommu.c diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h new file mode 100644 index 0000000000..33b68a8f4b --- /dev/null +++ b/include/hw/remote/iommu.h @@ -0,0 +1,40 @@ +/** + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOMMU_H +#define REMOTE_IOMMU_H + +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" + +#ifndef INT2VOIDP +#define INT2VOIDP(i) (void *)(uintptr_t)(i) +#endif + +typedef struct RemoteIommuElem { + MemoryRegion *mr; + + AddressSpace as; +} RemoteIommuElem; + +#define TYPE_REMOTE_IOMMU "x-remote-iommu" +OBJECT_DECLARE_SIMPLE_TYPE(RemoteIommu, REMOTE_IOMMU) + +struct RemoteIommu { + Object parent; + + GHashTable *elem_by_devfn; + + QemuMutex lock; +}; + +void remote_iommu_setup(PCIBus *pci_bus); + +void remote_iommu_unplug_dev(PCIDevice *pci_dev); + +#endif diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c new file mode 100644 index 0000000000..16c6b0834e --- /dev/null +++ b/hw/remote/iommu.c @@ -0,0 +1,114 @@ +/** + * 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" + +static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, + void *opaque, int devfn) +{ + RemoteIommu *iommu = opaque; + RemoteIommuElem *elem = NULL; + + qemu_mutex_lock(&iommu->lock); + + elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn)); + + if (!elem) { + elem = g_malloc0(sizeof(RemoteIommuElem)); + g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem); + } + + if (!elem->mr) { + elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION)); + memory_region_set_size(elem->mr, UINT64_MAX); + address_space_init(&elem->as, elem->mr, NULL); + } + + qemu_mutex_unlock(&iommu->lock); + + return &elem->as; +} + +void remote_iommu_unplug_dev(PCIDevice *pci_dev) +{ + AddressSpace *as = pci_device_iommu_address_space(pci_dev); + RemoteIommuElem *elem = NULL; + + if (as == &address_space_memory) { + return; + } + + elem = container_of(as, RemoteIommuElem, as); + + address_space_destroy(&elem->as); + + object_unref(elem->mr); + + elem->mr = NULL; +} + +static void remote_iommu_init(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + iommu->elem_by_devfn = g_hash_table_new_full(NULL, NULL, NULL, g_free); + + qemu_mutex_init(&iommu->lock); +} + +static void remote_iommu_finalize(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + qemu_mutex_destroy(&iommu->lock); + + if (iommu->elem_by_devfn) { + g_hash_table_destroy(iommu->elem_by_devfn); + iommu->elem_by_devfn = NULL; + } +} + +void remote_iommu_setup(PCIBus *pci_bus) +{ + RemoteIommu *iommu = NULL; + + g_assert(pci_bus); + + iommu = REMOTE_IOMMU(object_new(TYPE_REMOTE_IOMMU)); + + pci_setup_iommu(pci_bus, remote_iommu_find_add_as, iommu); + + object_property_add_child(OBJECT(pci_bus), "remote-iommu", OBJECT(iommu)); + + object_unref(OBJECT(iommu)); +} + +static const TypeInfo remote_iommu_info = { + .name = TYPE_REMOTE_IOMMU, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteIommu), + .instance_init = remote_iommu_init, + .instance_finalize = remote_iommu_finalize, +}; + +static void remote_iommu_register_types(void) +{ + type_register_static(&remote_iommu_info); +} + +type_init(remote_iommu_register_types) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index ed91659794..cca5d25f50 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/remote/iommu.h" #include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) @@ -100,6 +101,16 @@ static void remote_machine_instance_init(Object *obj) s->auto_shutdown = true; } +static void remote_machine_dev_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + qdev_unrealize(dev); + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_iommu_unplug_dev(PCI_DEVICE(dev)); + } +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -108,7 +119,7 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; - hc->unplug = qdev_simple_device_unplug_cb; + hc->unplug = remote_machine_dev_unplug_cb; object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, diff --git a/MAINTAINERS b/MAINTAINERS index 37afdecc61..3e62ccab0a 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 Tue Apr 19 20:44:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819414 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 48324C433EF for ; Tue, 19 Apr 2022 20:47:51 +0000 (UTC) Received: from localhost ([::1]:53778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngulK-0000U9-3B for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:47:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguj6-00065i-7z for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:32 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:26418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguj4-0003Q4-AQ for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:31 -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 23JKITEb011972; Tue, 19 Apr 2022 20:45:26 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=arQWPv032LXzJ8HdI3RUsukdFOD5fxl1fsIRn1gjTLg=; b=MgupnLnn5/rPBamLMl0L829aREKFfDiAtK2ijhblafqwxoHADncAx1F4LviLVePJrtd/ Q23CAVTxVuVg5pFJHtQZigWi2e26c/GCEeiYqXgBRCnC8WUXQuMb0rm3Q13QG+ehIEWu qPyY74uWlC9LuYm+bk8GrJvXSLQsEYu/sypi/ik/85Gz/JQg/Fy3dy1rylvhvaIGWD1P FX5IlmTD+S3WkLxXDlPoq3/Q8MKZ4n3xrva5edCvF8u53Q6E721zSSm1s9clPYvH5dMr qzO59P/YCdoJXeV/sB+Im+erGLh+L9F8YygjccabZpkLX0/51BVzN7ifs/7Y2egu06/5 hg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffpbv79pd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKai3V013505; Tue, 19 Apr 2022 20:45:25 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm83hhuq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=elBgIIpZUA229p+H1pADKOKb2Cp0iein64srMFyqettfpreoIzv0WWDHH0laJI7JhhyoAwYBDpk89M4KBN/CIM0AW6TMu4x+227xSBuYgkYf4WgjqD4YjLgx8IMfMM46b2ukSSeSW8BXRJLuRGdzId2z/LlG1y/IYWXLzvJbOivf+l1N2veiodFeRbvYc5n/9N0RCciP1LST7G1yJllMdDrMt9Wv+39GddpwipCeGfMB/i+nk3iZk/PE6sCAUEctDWho7ElgqqaFNgEkN9fsvBZY0EA9IEq4ZksuuLwzXyxByjLHcz4LCMBjzza/IizEqpFkIjvZaSLExS0E7fg1ig== 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=arQWPv032LXzJ8HdI3RUsukdFOD5fxl1fsIRn1gjTLg=; b=DECgI82uT9I0uAOggwPSxn6mW5kBLEIJ6Gbpdl5OMsGqNT+BNhWGBmgc8c1XMPR58z1arrsQ1PB+fvHq5yrUYByApxdwby5FU+7Hlm55vxet3Jz2V3Th8BthymmWhhO6Pux7VoTAXQZLlhExFT+lLKsAgSxwTWvo31IM50Z0Qyzrzz+W3J2Zba7U+EeD/QLo0KckvNykf7mHCVl0G42QYI9WixHR7qViJ+42DLbW4yQJhu3fHTbA3viKHe3jsvMYc8ufi0oa2PA7y1aekE7bVRX4EWPEkQl3Q/Hb+nDc4vedLXHfEAsnYFTPt095dlPe+VGBBOLhDV7JCKLyUeC/2g== 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=arQWPv032LXzJ8HdI3RUsukdFOD5fxl1fsIRn1gjTLg=; b=ka/Un3zJ+JmvW5TfPMMTNHgTSKwUshq7TcAPlYFTqWcxAxiki8YRrzFicE9MNP6njn5Pzdxf9EXgDTHR2OCjTPkxa8OdW872lxILUNnf35Aaovn1PhE0QgWI0USg6bxlpTMbj85Sfg6C1UAKA/nwLXVOC3fj8XnloQoRsACHDVA= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM6PR10MB3290.namprd10.prod.outlook.com (2603:10b6:5:1aa::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:23 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:23 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 13/17] vfio-user: handle DMA mappings Date: Tue, 19 Apr 2022 16:44:18 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 7c380484-9d40-4762-b4e4-08da22458661 X-MS-TrafficTypeDiagnostic: DM6PR10MB3290: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: qBjsJXtq62KFMLFE3UrsByDoW+8yFNGPPgfiDX3aBb0oX9xMSXpb/um3r201N1jTm1AhYKTWtH03yF6JZOzrDqVPFVDaPnRBkiq/wd+NL/hD4EvIfOn2Av1AKNWG0y4CvJX4Gd8q2WYUPlzW2eJfgeA1P9/xmN+pehizdzLlPACG979o+FLjit2Xz74NGhph4n7D64Hp9qHU3gI9aiQ+W5YScv/rJJ+cXKOCV9T4DYmTBbPEeDwDQ/NEkD0cKR9vvGpXKGP7UC7uNPut7MghW0dvcvszQIDw2qQDEbM8ay7+RqOAL368aQOsk+2/005Wiuk1q9Fi082spz8s6WJWE49RukbousdDlFhJkdY+MD6jO5ZONNiiZtaVn7PxGG3WuaxN0tm/oVpRY5kTJ1Z98ZnfArgSMaJyHyRTHnwJs087OR0WgLo/RajOj4U6B+/e8F94JfwP71JKkFEpPCu8AIi7V54C8oSHbe3ro81ZBQbsyZn0GeLZPfsnFZHCvEjeAJUykCFhURxGkO36d62V+EaFsx22ZkCfpw4+MszPXTsJRMQSdq/FPZ/04cko+NBZoanW49DAPHcAdkv8Z55hPbmfzbBWVYR4r+t6DEBT5uXCYZH3pn/soXH5XUJWW8+OIYpPXTewM1V9B4lmgr3HNMDIAIvtaJYOVBfb0PH+TCPlZUfyDbgn66Ng7JRDbk+ZpvuGFBbL2qXzM5FAQ6/PxQ== 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)(2906002)(8936002)(186003)(83380400001)(38100700002)(7416002)(6916009)(2616005)(107886003)(6486002)(36756003)(66946007)(8676002)(66476007)(66556008)(4326008)(52116002)(6512007)(86362001)(508600001)(38350700002)(5660300002)(26005)(316002)(6666004)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x2vxdheI8NWEG1UEnIadeDd3c1+O4CndsOnLXq0uOTIEFMok5j3dYxa17O6jcoYcKSfxMI3HGL69QMyig/sFxRlQAejNng+DULjOLxGG7z+C2YO5IbrOKOPwnxVlpJKNzvNUZo32Or4LebYwiJ98tqs5Bi2mrkB3lpjpY8IWN3kJjUFLCKPxO9gzSZ60WaJmu99jFxHVEuKzry4qhvgFUyxDcMHdeuAuZz3q8T8ZHquEiF5Cwmji/7e1QzQM5QjYZv/ORzVQh7pK29ZsUm0Hhp2RMSdDqUoiyU5JzL+qoUSLcOVlM8RAQXzyKk1fleIqsDqFFSVfhu4diNoTwaUxx19/hQxE7SfP+VuOwjv6jarWMG1pWl3eKHmNkGAi0i6Nz8bFaGiILP3x0y2mffWFomHFK9UA0zmzptYTPk+A0/UF3k4T20aIWnWLk1yaZ6velSEgk48cDIM7yl+arS0Z034gP9SaKAD+kclvdHKbOGlsBrx9GkzStqdXkNDP9Qo7FH24PCmjp/YiHahIsDvYHHDQ0PJSxpxnhblo4cGD0TyWAP71VjpFFYCPyQeXWojO1v29NYjWL1niRgXwApvo2OZFmzzxaw3+VtqbO8VzVLlxUoe+Jf5L1sTHtU2Ty2m+UQx3WLDR0qtT9PsgkeQgrIb5i7y3Icr2UrUvdsKH/n5vUtTdr6kRFHz/KqCvD59rExBmWfUglEIYvDHdzWI0xIZKkf7tghF4zZUYv16kmyQBuQ013wY5aXzh1vZzWD3bzBsmENLLNYdfsvZHrTlTSkfy3CE3E4LA0Jhaj33HdtYDGCTNBHkhrAqRim91qIk/ekzqCOqPv6Hcup+S4sgZlKJBpAqZaYxis5O/lgCftMiP1t0MWSC0edVQjRkCJ8fzsa5bvXk6LvS5cEdqtzX/VweOTGunS5h/MunkEb1rUi7Kp2cTyAFjuX0QFoXCxmbxRz5QPfoNMchkoT44Nf/FRPf7tfJ88m6AnI/+TleFiHOKFItBy0rQKeGc82GEK1iRdcn6KQyURyJriXaittW+DUXEaqmnhRpsoYHatt4IwLUjawxkHEdrAku6oiz6RdjoxsLLh/lFkyFm6mlvukBiGnv0kXK1llx9DIurTZ+rdTn1NPoJdMpnRgz2xX0JK5XRpt6ZAySrOojaG8fPxmAvphgKkPja+ocb1Ui+ihokPrMuDnCWx5oX6ra0FA1M2spj1z/q/yavf/asDnGGT9emjZGV8R0JDZlVVIlbjwDtcPzvHZtY2HRqaNL5THST0l/z1O7Xwi3vBsuhtiuLI1N7NwuGYJoRtKSo6cfYKVYc0+ctj4Dz4c2F5C1GHH/nAKk2UFTH3EjTHt/R9F2e0Q1P0GKFshjfmENgMa2qJBt/wuauhXwyamVc447WmtykE2yqZCqLMV49jh+YX+693UXESg7o8hfy/oev+q8DzQt+ssOojkbe7UCQDOQM37tD3ZgRD896lSSEm13ACCPGLS18mHS4LMiFF2GzLUWZTNcx7Vpk4NmHajkG1ueZypzGSGFbkPzaafeu476BCjHq2bcboaH+tA4Ia6ccTsTxuY3Rp3Vofgx6OH37VFn65pBU99ZxOv4/SZF6/DKXtZ/IK18DCVy5v9lZjqYyYvTa8upswz7aPk+m7q5qi5RHGU9kcuk+hnzuVQDaFBCtpR29lK+S+IdSaOPaa9jSalDXXj6S7earaGRGWfejbjZMmoDekUkvqxzgTvFHspwvz7jNA0krTA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c380484-9d40-4762-b4e4-08da22458661 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:23.2265 (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: VmMCoPHIiRsdIfMhxSab958GIGy51tddNMX+hK4rnnu8dSsa2cGOOqMlx8hvM6//cIIfnOsztonPgGu8uDBS8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3290 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-GUID: aumAeAD_mASn1GXt3hkr8sdPwOhxXlrg X-Proofpoint-ORIG-GUID: aumAeAD_mASn1GXt3hkr8sdPwOhxXlrg 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 cca5d25f50..7002d46980 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,7 @@ #include "hw/remote/iohub.h" #include "hw/remote/iommu.h" #include "hw/qdev-core.h" +#include "hw/remote/iommu.h" static void remote_machine_init(MachineState *machine) { @@ -52,6 +53,10 @@ static void remote_machine_init(MachineState *machine) pci_host = PCI_HOST_BRIDGE(rem_host); + if (s->vfio_user) { + remote_iommu_setup(pci_host->bus); + } + remote_iohub_init(&s->iohub); pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 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 Tue Apr 19 20:44:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819415 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 C0E2EC433EF for ; Tue, 19 Apr 2022 20:48:07 +0000 (UTC) Received: from localhost ([::1]:54156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngula-0000jJ-FC for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:48:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujB-0006D2-Eu for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:37 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:15608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nguj8-0003QW-Hl for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:36 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23JHpmTx009092; Tue, 19 Apr 2022 20:45: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=kWOXLWRACCUpI3Zg0gu1Z9iqeuf4i+npHXA5xgJb3UM=; b=0yxDSZqIsIVF8Lz8/rNurEDVRlf4LO0xechg5xf3Z8eLT/v6sqVWgPNnTFOT9+PAKpsZ EVZDCW+IORLVFb7zEjNDjUCTvMO2kCACI8lAVLGO4KgUj3lkRuA0xf/XXokJBJOs5XHr +mzzLS52qIMVcSXjNQHC+IneUC+OygK/8EhH6Nk7UCtAlsOnHUjQ32aMnBi1EQ9b0zv1 6dbhOqUqcA1QxDJbLeYA2FMjDI+FCNbrJ3pVn864CIxhyo17t3I8qx/cZ4XHSnIIOFVk LMq+cudFFcnBGB7MLwdxnPTT3cRX05JkphUaWlD+2hF6RkVfnMRzkmFP0MqjRk3ci49/ pg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmk2q7ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:31 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZhng016854; Tue, 19 Apr 2022 20:45:30 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88sps5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ACf8of4GxMUCUI+WNFGra8aHbhl4JjGOt8bKBHuyElfezYgeqS3YZWU4fe+8Yx7bTH7U1OSb+Iuf41+vHjA2N0iCmwCa7aeh1BHjHeZYe82qTG6dpF8DmNPjmhevff6MEHH5ZyB6nRjm+L4WWWokAhm5dv/aQ6HhxVUir7B5TElYEjxDqY5eBua3jnl8WFY4T7uu2D8j6Xo0x8nwlS+EFhBxySusPHAryWfuFG38MjzVdiNkE3cXpGZF8kr8xAUL99vjuR85o+6AU+r4qL7sdfE0kzQzO0kSs0hRiXBEkcHSTTvFf0lTOEFK7/qV9LXe8yCzZKZ9+s8j6P1sG2lpkA== 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=kWOXLWRACCUpI3Zg0gu1Z9iqeuf4i+npHXA5xgJb3UM=; b=cWjHhYPKYAG3qkX1lAROlIZucvAIQraEPCyioLkDMvRKOBYrEVhtY3y8KhgoACaO0bKsgx9r8rdtfWmm0qv7g0GDiTuJXTz7MXbpv3Idnvnm4Y5kbSAaZHDnF0/L1Ye2fNLLusOtETAhSthc0YD1F3wOqgGps1FbwkKXc6zsixetVJKQACihSnzAV4LrdG8efqcPbhyr9VZBdS3zbLwmGQEwewc3LUjqHLq2YZ507xdJOokhAX2+S+EfVkFTBBroOaxVoMenL+ghBBmbwivPGLEVTdixYJwaflhGGfr/xJSTGXhfIXBRdoWcqAfTI7Jml+5SK6Knw3p5D4fsPV8eQw== 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=kWOXLWRACCUpI3Zg0gu1Z9iqeuf4i+npHXA5xgJb3UM=; b=biU7dRyGFGQXHL7YguV6atEOp4hswtEqH+ZnEVo7vpeoBcESwl+j2CdKmhQ/cRSWTa6ikf4oibjdCWx3gbx6R3a84xWSZ41lJlShS3WkY8AHDVaptoNb289R00bjlpHb8L3fD1ubx6cAY4GkkYjNe5kFKys6biaXDO/xW8VX7A4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:27 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 14/17] vfio-user: handle PCI BAR accesses Date: Tue, 19 Apr 2022 16:44:19 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: bed26a67-f206-460c-f115-08da224588b0 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: AqDpf1uLJbXQug5fX7AkfkGsosMqPHi6mz3V/UXEfScZNP98odkIpSmhoMXXBpGlE0whl4YHp/IIkBpo6NprCXWJar2nkwRX6KMTmGArZVFYWmqKaG4m1hpIFknn6v5VylVxx3pACdhnDnSWyZY8sH0VxGPxODuxRAUMTdonjEP8A4XGyheps65g6uXUh3bq4rfuYzzgMe+/IamOtzGLbYyU4JWM7bBz5p2qI0VAhnQU25UnmVXMQtKET8e+l/yrbMb4LQdGqg12VzwB+7UXETsxHc149rrtIysR+uW1taPGBIYoVofISSEOOVkZfBvS+yNWTBJi68cLaxNWf15Dbfv+YqE7KuG+LjxEaPTH0MpL11gRv60UTxuCRytKgzxNpLmM/drsBO5SDlP93NAHO80qEACSo091Xo7zI2XbQZ5GWwQdFOArW4mvy0Ov9CfbJHspoL4BK86D53ywymX9804ZUaYntSEoqFv8BYlr5qcqBBxDCbd9Htz0Hlovuv1AJqm7cdIA/xmvwLKfPO5XwhIRuLraVyX/W2zpu0OjY8iFTqah3NNMH9zdm9bh5SAiBH13kGdMvbzNw8KEpxF1zgMuHvIAt/MUBNMeu4gBK6xY8exCp7RScDTtdgurK4MNjA8aClPBydLrJSvml05SKZlNpnKAY3QxIDK/ZdQVb2HFU7wW5ToxZgy3jDWj3xBn6EE6oPXn4e8lsKsgf11eNw== 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)(83380400001)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CTK5rMCVMmkBcQV+DTj5GvkRgBqU6vxdwYA6dP9yoTtNq3gZy0KigF7R+roHWk7vIEUvmL59/aUJoN1oIcfVz2VNAsIfCPM1lzaqUJpMAqUVEvo9p+tpUxqjI37SKEAb8qCBKReW758ynTQALxF0UDxiPyzuBNflf3PySVlqPZz2hiNEd5FSyeS7ZgWQnNHtvDqC8FOY1ARhW3X8ieRkZvcRPkTLSsRvZILbNEUUh66yYuAnGuXVX9bxH+92jd4/iZjP9Li4PtdLlGeSh2zKEBnMV1WDz2vSeuiVX8+vlWNOFmJaxOVfKfXruz0ml9I5W7+uQ9g2Fn2EzUfb995O4Li3X7waNKL+QJu+Dp/Kyy/wv/SdwKYt3MB+FT37Ufu5cEYY5vSGgNyRtrB0+GnhSQGd+MK8T13BOQc5kLzz4aayqzhWQNqsS0F3KdW0EnZZCxRoUGHSVF415ZndyNohkU5DE62YOGQpHBn3VpY2xWJVivp7JfAlrtfGPb4iG/Nmg51Qgm8zrKgJlTyjXczvrvH3KUEnjKiweThSXyvnGJ5adUGC5NcTGYizIkwnB4QqcXfdzsbmn7CG62t8WHALPI3TOEiEbgnhgjXlkjtGPXklZu3pA+AJD82jPeZrMYORG5bjmgpe2IHMGLEAWwCCe4ti3VMa8KQTEkKCsGvUiHwsxzAvE+tt2FgtyVNNUmVoKAPDmEbe5bgz5+t6AflYfII7odosxGavKBJ6ayIczE7TEqEu/jgCjbVOMIklInWL/g33R0RYKyJKG/3mF4JuvEOPxfORFZSftzAQdY+QWAQao3zbABET4TMpIeTm15xPSXne5E1fTzIz5jc+0X7MEHrRhXp0YLTseH21/zbeC+UElmH7SUBFrEckupY5G+EIdgUPEvK++52dmTTn7igBTT4akIu+90AsmIinn+10zJ7A3Nm3vAfjoVNkZev+4p2Yqy26fqMSWyVd1D+P4PMjm0xJst/WesoZfRFO4LlAgrEXRnveJve9FH/n7Y7GvUpVHCpMgY0+/pwAjabfGPi9gmmBOJn5DtoLZj8HQ3lJB6WeSFamv5zyeZce8yrdpbNSDaArTgM4alALqh7LmGXSb+sxciAWL+vmVMt789lbtPAvIc6iyZ/M5DInTU5k4jnU1xCLgcR+V0dg5ST4nTaYciMctfAe6gyfZmT7wlu9KL0xkv7Al8W93BsmzROGtE0BeiR5JAzghIB2rIVl/6FEpO8UUoQuXvE08NHJY3/MskgXptmFHqPkK8Vyjf+UrIp6k9ZJcfHv0T4OkKu9099m8gIH1yppWL7Zyd9WMOum2ABwMpoVHfDaoWytPrUJIYdst8A7fKQ5veRHKQdVr4hQz5UDYjxV/+x37wyTXA41mQYdpTHi2t0cowRZYo8W682uKPnaFALx4NchZwJ0YG31mDA8ZKsBJAD5VSrbR4O/EH9H2wvpu1LunhsiM6TBChRUBSxzT0zgxMtncRjoTM5VtHz475zvDhNtPacoOIr1BAayNX8Z7fJASmZY0u6yHVCa9S108F22QF4XapUjBRbefDSL12ud9r5kIPVe+PYPRDNWMACb5Y+dfxc7nq0wzb2Cyzk2pN/sHFxVSSKUft8rxqx4yn3KtHy7BhsmyFYn6ThGWIL7u9BWyn8ui4+XAskG+XMxi3YvqdYKuvlkFfSdgSKn3wKohi0TMiB/TMWZ9qHUanZ9dnM3XDTgo3GONBjFIJGNt93Yv9iVu2xHVBIeUA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bed26a67-f206-460c-f115-08da224588b0 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:27.3668 (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: 8HLaD1zbkmbXOc4dSkaNq8pZnpxrp8Omq0RtPR3LokA58eZeKYu2m2vLMFz54iLsJ+Ofubs1CFRqXnwaekFaxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-GUID: HOqQuVI92OLu7XFimoHa_psZiu5qalOI X-Proofpoint-ORIG-GUID: HOqQuVI92OLu7XFimoHa_psZiu5qalOI 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 | 189 ++++++++++++++++++++++++++++++++ softmmu/physmem.c | 4 +- tests/qtest/fuzz/generic_fuzz.c | 9 +- hw/remote/trace-events | 3 + 5 files changed, 202 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..f75197cbe3 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,192 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); } +static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, + hwaddr size, const bool is_write) +{ + uint8_t *ptr = buf; + bool release_lock = false; + uint8_t *ram_ptr = NULL; + MemTxResult result; + int access_size; + uint64_t val; + + if (memory_access_is_direct(mr, is_write)) { + /** + * Some devices expose a PCI expansion ROM, which could be buffer + * based as compared to other regions which are primarily based on + * MemoryRegionOps. memory_region_find() would already check + * for buffer overflow, we don't need to repeat it here. + */ + ram_ptr = memory_region_get_ram_ptr(mr); + + if (is_write) { + memcpy((ram_ptr + offset), buf, size); + } else { + memcpy(buf, (ram_ptr + offset), size); + } + + return 0; + } + + while (size) { + /** + * The read/write logic used below is similar to the ones in + * flatview_read/write_continue() + */ + release_lock = prepare_mmio_access(mr); + + access_size = memory_access_size(mr, size, offset); + + if (is_write) { + val = ldn_he_p(ptr, access_size); + + result = memory_region_dispatch_write(mr, offset, val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + } else { + result = memory_region_dispatch_read(mr, offset, &val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + + stn_he_p(ptr, access_size, val); + } + + if (release_lock) { + qemu_mutex_unlock_iothread(); + release_lock = false; + } + + if (result != MEMTX_OK) { + return -1; + } + + size -= access_size; + ptr += access_size; + offset += access_size; + } + + return 0; +} + +static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar, + hwaddr bar_offset, char * const buf, + hwaddr len, const bool is_write) +{ + MemoryRegionSection section = { 0 }; + uint8_t *ptr = (uint8_t *)buf; + MemoryRegion *section_mr = NULL; + uint64_t section_size; + hwaddr section_offset; + hwaddr size = 0; + + while (len) { + section = memory_region_find(pci_dev->io_regions[pci_bar].memory, + bar_offset, len); + + if (!section.mr) { + warn_report("vfu: invalid address 0x%"PRIx64"", bar_offset); + return size; + } + + section_mr = section.mr; + section_offset = section.offset_within_region; + section_size = int128_get64(section.size); + + if (is_write && section_mr->readonly) { + warn_report("vfu: attempting to write to readonly region in " + "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]", + pci_bar, bar_offset, + (bar_offset + section_size)); + memory_region_unref(section_mr); + return size; + } + + if (vfu_object_mr_rw(section_mr, ptr, section_offset, + section_size, is_write)) { + warn_report("vfu: failed to %s " + "[0x%"PRIx64" - 0x%"PRIx64"] in bar %d", + is_write ? "write to" : "read from", bar_offset, + (bar_offset + section_size), pci_bar); + return size; + } + + size += section_size; + bar_offset += section_size; + ptr += section_size; + len -= section_size; + + memory_region_unref(section_mr); + } + + return size; +} + +/** + * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs. + * + * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would + * define vfu_object_bar2_handler + */ +#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \ + static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \ + char * const buf, size_t count, \ + loff_t offset, const bool is_write) \ + { \ + VfuObject *o = vfu_get_private(vfu_ctx); \ + PCIDevice *pci_dev = o->pci_dev; \ + \ + return vfu_object_bar_rw(pci_dev, BAR_NO, offset, \ + buf, count, is_write); \ + } \ + +VFU_OBJECT_BAR_HANDLER(0) +VFU_OBJECT_BAR_HANDLER(1) +VFU_OBJECT_BAR_HANDLER(2) +VFU_OBJECT_BAR_HANDLER(3) +VFU_OBJECT_BAR_HANDLER(4) +VFU_OBJECT_BAR_HANDLER(5) +VFU_OBJECT_BAR_HANDLER(6) + +static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = { + &vfu_object_bar0_handler, + &vfu_object_bar1_handler, + &vfu_object_bar2_handler, + &vfu_object_bar3_handler, + &vfu_object_bar4_handler, + &vfu_object_bar5_handler, + &vfu_object_bar6_handler, +}; + +/** + * vfu_object_register_bars - Identify active BAR regions of pdev and setup + * callbacks to handle read/write accesses + */ +static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) +{ + int flags = VFU_REGION_FLAG_RW; + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + if ((i == VFU_PCI_DEV_ROM_REGION_IDX) || + pdev->io_regions[i].memory->readonly) { + flags &= ~VFU_REGION_FLAG_WRITE; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + flags, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -420,6 +607,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 Tue Apr 19 20:44:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819418 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 3CFCCC433F5 for ; Tue, 19 Apr 2022 20:52:03 +0000 (UTC) Received: from localhost ([::1]:34434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngupJ-0006p9-Ui for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:51:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujE-0006NO-Mj for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:40 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:21980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujC-0003Qw-1j for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:40 -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 23JHsMI2015013; Tue, 19 Apr 2022 20:45:36 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=uGUUmqIFRYA4hYl/hssn3f4Q0UuMGH3djJvMb6OJc0I=; b=wFmTbmZLuY5xithyMAKAhpuPDCq0U0MZ5XGbuLCPIOYP1JVVgRzKAUWZRj0c0EPRN0a2 vYcTNGdny1oztvikDokNUv7ORmU0NqRVpO6kYWfllfZDkLuHh/eAw7xCmGMobnrFl3fj bwlvTtR73kNfU8dVj4qHAOWh/13E7BqYNSGU33YxJZPh6yibHDj8ROkH3aoOqV/YDToY 5Y3+I11HnJC6wRVBsrPbhIkptGF2hZGqtGqu4hXpV5OgFh9B8J105JF89K8WrrhS7AYM wJqPT7OHujhV4LBfkWevCe3Rcn5MKBElOfPxnzXxyg6PiDR6ut/HBxMqkAPgJ9Uh1vdr fQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffndtf7nj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:35 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZn5h016934; Tue, 19 Apr 2022 20:45:34 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3ffm88sps7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ix2ISwf9mllTSb5PVzoX++/a9Rm+M3WV288fmdLsAkU29/CTq/SPpqLHB/1e4pRBl8sqxAQIyh/imahwgNorE/48iXApUgQgqdH6lLRsFDirMWwiw4oqUFW/Se8sJqhsMGwXNC4znSkoIVF7JZelPiR/mTHz5xhXEFapAGlNFXmC+yQCZbHwNgGvB1OH8c2FoMA/BxUlbSjVW89eMURbibvPoibbD3onDSnUL/9eZUVTtJ86GKIilBp+F3WsvgmjsDgmfMyOJepxK/YZ5mdXaWtr6itr29ghh2Pk1zyEXgNBFAX4NhRH1zpnyHKKz4pObDq+vAub6M0uLYb+VdbRzQ== 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=uGUUmqIFRYA4hYl/hssn3f4Q0UuMGH3djJvMb6OJc0I=; b=ZAGUKYDfqVHtABSzRns5P2W2xn0wAThUzXi3lHiwyPLotKu/TXUsZgGOwZ3UA+CTatF65tAqYkFKaYu73mX5iFmXXYPHs8asw12vW7ZkDssJlSH51Lx2u8ZqQLYmaJdT914yEAblbhTuC+02eUvnZS4rPwf1d7o8+7tsyM8Oo8v6W/WyJGOSwlkdWLX3ILRp6Iu2XqePS86SlWaHdbUMJUBajrbxw+fP3rr+g9NdymijGxPFldMPAavdlalmYLEa2jHCupGk3exdZgtMiAdIDxTIUarcmc8xz0yipL5IIe8qgDQxELKVppS0cnzbaqI5qrFG43t3VPPCbchCmnZv2Q== 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=uGUUmqIFRYA4hYl/hssn3f4Q0UuMGH3djJvMb6OJc0I=; b=o1cpPb9jiZwqaha898hr5w/DdEtYfdmI8598cI3f54pHV8fWnSxR22Eyf8akSoTWbodcgRnXTB5gbkBAMC+PaXnze4eDjAAjB8txAB3YkIMAVslsuZ/OHze1D+xfPWzm0az4qMgtkDOwCIQFpcQ00oovNRH9qpPdz13Ec2WuWkc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SN6PR10MB3006.namprd10.prod.outlook.com (2603:10b6:805:cf::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:31 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:31 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 15/17] vfio-user: handle device interrupts Date: Tue, 19 Apr 2022 16:44:20 -0400 Message-Id: <847e6d373eb3d8ff4cdeb7a3ad9b935785bfbf8e.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: aa04e134-f43f-4b27-d93c-08da22458b4e X-MS-TrafficTypeDiagnostic: SN6PR10MB3006: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: uUk5Td9ECnq+ZgUB8TThYm6LRBHfOCQkzVzKJy8Zw3sIouhjoJd9JjZt7VeOQFWIy3iVqFFaMNNQXGwMafhfO4SjjqQjKNX8H1ykJZJ+yQFltZpFPB4G7zi509vJaP8qvHUtgamNiD+xjcD+enpuOahBaMd9A1ZNvSvWFxFH70DRIcBP1LSLjCuJJRl1/PKx1fAnsB+d26GIj+oPKee1G2AEmzUfXD83F1JdMVS4/zF4nMLESrY28qKJbRFqZ17bD6s77UVWsP2X7w/HiQscrjYayLJa2Avo6J+OpvIR3oH0JzN5bYzTUJKOOUUj70bnojOka8ZdY0B1fBsIqrg/279r4dNnP2/uJqchnaJA6CUrB37rCyBXhDNrcct6sIDC309dM7bQuHnK1jD49awMjcXKAIL8S2n4HbGDT7g2Uek7md99etJYsv6yOXel3dI2Uu7fS1FNZClFZMDPUnAmyPNafnYU4fzWoZ47GFJ8QsnhtOBvyyeuhU+oJUqkjCocVkrl+kN5y+hcGOpFqQAkj/s3sUNN53jEGogXUs6PkOfKgMK8FWn3uXCPxxQmuU2cXCQF1vBjrxLgOJ1NjmFudFiY27emrOaatKiZBareHpENFZgj0DJ/zelsLNbjy9Mt/tN3RcP18suL7QYVweRS/yzpKvf9HhNb75eDXAX2jm1YraPOLu6c8oM/1KpfTQjaGUJx/7RJQa/9nh8DQGkOMQ== 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)(66946007)(66476007)(508600001)(107886003)(8676002)(5660300002)(6506007)(66556008)(8936002)(83380400001)(6486002)(316002)(2906002)(6916009)(36756003)(30864003)(6512007)(4326008)(52116002)(26005)(86362001)(2616005)(38100700002)(186003)(38350700002)(7416002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fAXWL5V4Ko8L67Nc/haupyBttiQ2tiux5liUdnxrGb3qcxCcIiXI4nHRglue3LmAcudBt28NcFp7Nl0AcpLwagPbZ6CcfJiKWoblxSw1kVR19jY2zfptHMKMta6rwFShnZEwk4WUMvoawbYES2U2CFY4T2kanY0J3yIqByMCiT4mfm8n5Za3+HNvty8eLSytwamOI+AzCm2V2E3Il2sTJg5zjZeaJ5aV4mREiwzY+6Uy7WhG+aYhPAoikaU4DDFnba+YUre72rvrpJ3XQxhkEVdnkjQraD4Q+7rUAvQ9gWw2RpO7o89VA0AGD5LJN67J/D3Okp3PSF0zWMKyjvMaTfvzGd2uoQ6x+dC/Do6pdORIn1zJabVI54WxmktILrLxLdmIwZxTS8Z1lDAVEfnyQmSOPUc8TUP29qR1p3rz+WACQs0hVM/iYxxJoupojP6eF8imjWc+H9u/DBuxQ1gx+J31YzLPNhzybboxcFsquygqvD17OTKAQLptffqAHgWqdHv0qfX+JolkefCcyhY/O6tVQbedpy2tUptey6oPC0E7mnBgWJZIgEuOmTZhXc8UI6tnSj3R8ht0/wtbPyHZahrYcGXflr40lE8BBjxNaDN4zIN0EYctdOjSBulqwqLkKEnZ5uym4kIOiBlN53ydqb2FBttccp0ynC944syd6x/vnlQEWIItFp67q+uxm92L18Bt0gpKd7BlxWJ36hOITa2NCg3tvlK9Y2SE+FEtIy9os4cArZpOaWMsAXCqlLCzYDjPTVb3WlIbse4uf8TizuMqibcXMEqbUapp0jA9Z4dqQW7RFk6WuaEG0Mlh+2JQZNnkMcV6vEI8OGa/wWTNwOi//d6vBzgmDU6+pJ6x+xdXUxEnvfsSTLiXVqLKpjkCdbjhhCEzB4fElD5/TJ1if7dFkXdVVinP3H1JJCh1MAXr2kg7QMKHGxjMqLOwcCH9d8fWgPil5HNSL5dTKgPLyHCCKy3PWxm8+qfBsWeuiOKSEPl99rRPzatIVH0fsnCZPk0X7j40td0WqTb3RX4iEmknTsRo4o82NY3ZvckoEV8wsRsHuLfrKENKnnTJVe7Im2YDf4KCRvBcIIVjTn2iVu85D3ipqhG2tLXbR9IHHMIyaSrGfG3XXBw5Uv6eC0Dqxal5mUULQtk3k+2VU5IJi6vFyiYVySZwf0//mWFOAyohSxacce7dXpvqoOueI6CfhUvXtYFxMfpnS9FJnR9NmF5AuLglPn3lSpxDCvTaRF7MBHvlnNgHfHrG6zmpyA1Detcwxh0z9jyeypXQwcCi10wail+WvJU1FqvN7zVqlkpANMnRBz4EWc99iu4aqJ25XpRVdgHj/F2H4DyU8EKFL7O47nB0kolhpWUar2R/Tm7MYOycxcFcCB9rGmER/dhgLtYH0hchmIFLMp+5nE5YP1atXRxGfMflXdltgCgaBVb5XBDVb7fe9qEw7c0AGZSmsZOMfDIGjiId4X5+5+lGTL+TxBv+tD0+WPhE0WaplgFO5p5n0Y73OHL9A8IfaJRf2c3Pa8DRgLSqwEIqXdxXa32I8K9VY7XHCEuTeWM/YQ55HxgbsQgNmtKJva/Q3+MQuT0J109tUYs9Sl6jlyGIaLET9TH6N6HzKatMSd+ZIoKLqsnx9Pv0+Nnd0mHUPgOPyxWXp8H97cdseZOMwyjb6ulQtiiLd22ZL5I5toavy1DZj3V8BrEbJD8bGXhrx4ZcXPDq/uDrsUQ8HkzzjLxGig== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa04e134-f43f-4b27-d93c-08da22458b4e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:31.3509 (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: AYmK3ADoTmr44cbSwqQrlVrhFswAUndmPrxZOW4t1dpz9XljCOldfkJTNLc4t87jztG4R8LTt56ijoStiDsAJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3006 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: afK-JVD4e3pxOD7iy8ugyJQS9ogbHst3 X-Proofpoint-GUID: afK-JVD4e3pxOD7iy8ugyJQS9ogbHst3 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 | 13 ++++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 16 ++-- hw/pci/msix.c | 10 ++- hw/pci/pci.c | 13 ++++ hw/remote/machine.c | 14 +++- hw/remote/vfio-user-obj.c | 123 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 11 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 include/hw/remote/vfio-user-obj.h create mode 100644 stubs/vfio-user-obj.c diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 3a32b8dd40..7595c05c98 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -16,6 +16,7 @@ extern bool pci_available; #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) #define PCI_BUILD_BDF(bus, devfn) ((bus << 8) | (devfn)) +#define PCI_BDF_TO_DEVFN(x) ((x) & 0xff) #define PCI_BUS_MAX 256 #define PCI_DEVFN_MAX 256 #define PCI_SLOT_MAX 32 @@ -127,6 +128,10 @@ typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type); typedef void PCIUnregisterFunc(PCIDevice *pci_dev); +typedef void MSITriggerFunc(PCIDevice *dev, MSIMessage msg); +typedef MSIMessage MSIPrepareMessageFunc(PCIDevice *dev, unsigned vector); +typedef MSIMessage MSIxPrepareMessageFunc(PCIDevice *dev, unsigned vector); + typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ #define PCI_BAR_UNMAPPED (~(pcibus_t)0) @@ -321,6 +326,14 @@ struct PCIDevice { /* Space to store MSIX table & pending bit array */ uint8_t *msix_table; uint8_t *msix_pba; + + /* May be used by INTx or MSI during interrupt notification */ + void *irq_opaque; + + MSITriggerFunc *msi_trigger; + MSIPrepareMessageFunc *msi_prepare_message; + MSIxPrepareMessageFunc *msix_prepare_message; + /* MemoryRegion container for msix exclusive BAR setup */ MemoryRegion msix_exclusive_bar; /* Memory Regions for MSIX table and pending bit entries. */ diff --git a/include/hw/remote/vfio-user-obj.h b/include/hw/remote/vfio-user-obj.h new file mode 100644 index 0000000000..87ab78b875 --- /dev/null +++ b/include/hw/remote/vfio-user-obj.h @@ -0,0 +1,6 @@ +#ifndef VFIO_USER_OBJ_H +#define VFIO_USER_OBJ_H + +void vfu_object_set_bus_irq(PCIBus *pci_bus); + +#endif diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f33c..d556e17a09 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -134,7 +134,7 @@ void msi_set_message(PCIDevice *dev, MSIMessage msg) pci_set_word(dev->config + msi_data_off(dev, msi64bit), msg.data); } -MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +static MSIMessage msi_prepare_message(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; @@ -159,6 +159,11 @@ MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) return msg; } +MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +{ + return dev->msi_prepare_message(dev, vector); +} + bool msi_enabled(const PCIDevice *dev) { return msi_present(dev) && @@ -241,6 +246,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, 0xffffffff >> (PCI_MSI_VECTORS_MAX - nr_vectors)); } + dev->msi_prepare_message = msi_prepare_message; + return 0; } @@ -256,6 +263,7 @@ void msi_uninit(struct PCIDevice *dev) cap_size = msi_cap_sizeof(flags); pci_del_capability(dev, PCI_CAP_ID_MSI, cap_size); dev->cap_present &= ~QEMU_PCI_CAP_MSI; + dev->msi_prepare_message = NULL; MSI_DEV_PRINTF(dev, "uninit\n"); } @@ -334,11 +342,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector) void msi_send_message(PCIDevice *dev, MSIMessage msg) { - MemTxAttrs attrs = {}; - - attrs.requester_id = pci_requester_id(dev); - address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, - attrs, NULL); + dev->msi_trigger(dev, msg); } /* Normally called by pci_default_write_config(). */ diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331cd0b..6f85192d6f 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -31,7 +31,7 @@ #define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8) #define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8) -MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +static MSIMessage msix_prepare_message(PCIDevice *dev, unsigned vector) { uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE; MSIMessage msg; @@ -41,6 +41,11 @@ MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) return msg; } +MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +{ + return dev->msix_prepare_message(dev, vector); +} + /* * Special API for POWER to configure the vectors through * a side channel. Should never be used by devices. @@ -344,6 +349,8 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, "msix-pba", pba_size); memory_region_add_subregion(pba_bar, pba_offset, &dev->msix_pba_mmio); + dev->msix_prepare_message = msix_prepare_message; + return 0; } @@ -429,6 +436,7 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar) g_free(dev->msix_entry_used); dev->msix_entry_used = NULL; dev->cap_present &= ~QEMU_PCI_CAP_MSIX; + dev->msix_prepare_message = NULL; } void msix_uninit_exclusive_bar(PCIDevice *dev) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index dae9119bfe..48d4bc5f69 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -307,6 +307,15 @@ void pci_device_deassert_intx(PCIDevice *dev) } } +static void pci_msi_trigger(PCIDevice *dev, MSIMessage msg) +{ + MemTxAttrs attrs = {}; + + attrs.requester_id = pci_requester_id(dev); + address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, + attrs, NULL); +} + static void pci_reset_regions(PCIDevice *dev) { int r; @@ -1202,6 +1211,8 @@ static void pci_qdev_unrealize(DeviceState *dev) pci_device_deassert_intx(pci_dev); do_pci_unregister_device(pci_dev); + + pci_dev->msi_trigger = NULL; } void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -2236,6 +2247,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) } pci_set_power(pci_dev, true); + + pci_dev->msi_trigger = pci_msi_trigger; } PCIDevice *pci_new_multifunction(int devfn, bool multifunction, diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 7002d46980..37538edb2f 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -24,6 +24,8 @@ #include "hw/remote/iommu.h" #include "hw/qdev-core.h" #include "hw/remote/iommu.h" +#include "hw/remote/vfio-user-obj.h" +#include "hw/pci/msi.h" static void remote_machine_init(MachineState *machine) { @@ -55,12 +57,16 @@ static void remote_machine_init(MachineState *machine) if (s->vfio_user) { remote_iommu_setup(pci_host->bus); - } - remote_iohub_init(&s->iohub); + msi_nonbroken = true; + + vfu_object_set_bus_irq(pci_host->bus); + } else { + remote_iohub_init(&s->iohub); - pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, - &s->iohub, REMOTE_IOHUB_NB_PIRQS); + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + } qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index f75197cbe3..70b4d8b9ce 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) @@ -97,6 +100,10 @@ struct VfuObject { Error *unplug_blocker; int vfu_poll_fd; + + MSITriggerFunc *default_msi_trigger; + MSIPrepareMessageFunc *default_msi_prepare_message; + MSIxPrepareMessageFunc *default_msix_prepare_message; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -511,6 +518,111 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_map_irq(PCIDevice *pci_dev, int intx) +{ + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), + pci_dev->devfn); + + return pci_bdf; +} + +static void vfu_object_set_irq(void *opaque, int pirq, int level) +{ + PCIBus *pci_bus = opaque; + PCIDevice *pci_dev = NULL; + vfu_ctx_t *vfu_ctx = NULL; + int pci_bus_num, devfn; + + if (level) { + pci_bus_num = PCI_BUS_NUM(pirq); + devfn = PCI_BDF_TO_DEVFN(pirq); + + /* + * pci_find_device() performs at O(1) if the device is attached + * to the root PCI bus. Whereas, if the device is attached to a + * secondary PCI bus (such as when a root port is involved), + * finding the parent PCI bus could take O(n) + */ + pci_dev = pci_find_device(pci_bus, pci_bus_num, devfn); + + vfu_ctx = pci_dev->irq_opaque; + + g_assert(vfu_ctx); + + vfu_irq_trigger(vfu_ctx, 0); + } +} + +static MSIMessage vfu_object_msi_prepare_msg(PCIDevice *pci_dev, + unsigned int vector) +{ + MSIMessage msg; + + msg.address = 0; + msg.data = vector; + + return msg; +} + +static void vfu_object_msi_trigger(PCIDevice *pci_dev, MSIMessage msg) +{ + vfu_ctx_t *vfu_ctx = pci_dev->irq_opaque; + + vfu_irq_trigger(vfu_ctx, msg.data); +} + +static void vfu_object_setup_msi_cbs(VfuObject *o) +{ + o->default_msi_trigger = o->pci_dev->msi_trigger; + o->default_msi_prepare_message = o->pci_dev->msi_prepare_message; + o->default_msix_prepare_message = o->pci_dev->msix_prepare_message; + + o->pci_dev->msi_trigger = vfu_object_msi_trigger; + o->pci_dev->msi_prepare_message = vfu_object_msi_prepare_msg; + o->pci_dev->msix_prepare_message = vfu_object_msi_prepare_msg; +} + +static void vfu_object_restore_msi_cbs(VfuObject *o) +{ + o->pci_dev->msi_trigger = o->default_msi_trigger; + o->pci_dev->msi_prepare_message = o->default_msi_prepare_message; + o->pci_dev->msix_prepare_message = o->default_msix_prepare_message; +} + +static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev) +{ + vfu_ctx_t *vfu_ctx = o->vfu_ctx; + int ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + if (msix_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ, + msix_nr_vectors_allocated(pci_dev)); + } else if (msi_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ, + msi_nr_vectors_allocated(pci_dev)); + } + + if (ret < 0) { + return ret; + } + + vfu_object_setup_msi_cbs(o); + + pci_dev->irq_opaque = vfu_ctx; + + return 0; +} + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ + pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, 1); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -609,6 +721,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", @@ -634,6 +753,8 @@ fail: o->unplug_blocker = NULL; } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } @@ -693,6 +814,8 @@ static void vfu_object_finalize(Object *obj) } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } diff --git a/stubs/vfio-user-obj.c b/stubs/vfio-user-obj.c new file mode 100644 index 0000000000..79100d768e --- /dev/null +++ b/stubs/vfio-user-obj.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/remote/vfio-user-obj.h" + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ +} diff --git a/MAINTAINERS b/MAINTAINERS index 3e62ccab0a..ad51ec0dc8 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 Tue Apr 19 20:44:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819417 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 5EEA9C433EF for ; Tue, 19 Apr 2022 20:51:42 +0000 (UTC) Received: from localhost ([::1]:33506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ngup3-0006BM-Ej for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujG-0006TA-Jw for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:42 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:27088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujE-0003R5-Nb for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:42 -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 23JI6Whs013493; Tue, 19 Apr 2022 20:45:38 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=Qtbqi3jNJilFCSXwpwj7SQyG41+yGTZTZXxiBislSBQ=; b=HmZR/2CVvx8B4hd8Bv/v2Ac41CH0SPsyWN2xgFDnOFnuA9yUUuPsOTnUWl8wsJjJ/M1R 0EfMccnVE84JwIoOY5rSCsesFwzQRShqft+8HsiGaC9Zyip/M3KAyxKutfsa5p0b2qdi WKvkuugUBWp42RwHhrEfnPOt82eO7tsFM9kyjCWpDfYh97vh0FtnjmALeLN9LLTSdmY1 iXUebXA/A4Uj0qsQV5eYiFvQCYoN8Q+JSdFQrmdYU25Q02bnmaD08au4AFyrNPEl9yoT 0O9QlV+KSR28PUB1lhzvKwj14lsvf4wGCkdEB7hoYfKTDdXcZgpuQ4HLCK7K0H8XD0Uh OQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffndtf7nr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:38 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKZl3J034159; Tue, 19 Apr 2022 20:45:37 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2109.outbound.protection.outlook.com [104.47.55.109]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm830dya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TAa75D603BxTjB01N7SCt1PSL7hlfOb0oVBrXRhdd2L26rOhbmtuZMsHie9TQilHka4UTHezqdfiJjFKntewckIWDMEVtPnrYhZfmgQ0seeti4TqXnV7Uk9PLdYHlVgPFX3Hbpjm1WyyNS7y9Igx9D+x2lCO80OhaGyasMTLByHCX9mg9/2FqXwFM+iJRZXAxQi4mnuHotdH5T+umLZ8htQVc/LHFalmQnOM5JMgbJcQlW+C8it/Nsxg7P1QUwK8IVmvGRcueR9hGh68325S1kZOPJUY+DYvnsJz08o75mxG/BX/eb2N34bNYyr1TQToIPmTzov7vG4Fzd3HsOjfNg== 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=Qtbqi3jNJilFCSXwpwj7SQyG41+yGTZTZXxiBislSBQ=; b=ajDwqV5TsW8vP1O7+SKiSctrOwJWiIjNUa4Pr6L8PDDmSPzygoIZ4oJTW5meiSJClCPwO2mk80DrvAybDb7jrwhl3qSpV/mo3huDQKZq7bmRiuSRvc3PTyFT8zWKp+g3bttfdalPNjbKXLUT+WFLzvwSpmArqHKmQxWAZZ4Q3kYb5NnGfQ02JUBRriw78VoWutQ8E/kQmYlJ2KDhFqNkdem/cfQjYr+Chkcnu1TxYSSSlZaLfAtGoe7UWv/X3EPpBpxp5jW6cRLz4k8cYwd7pQM63LZDUeEuRxMCWn+TLHAk4SosDJ2xpNxpa5aVr7eoaw9CDS6mocnsRXHsw4H28w== 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=Qtbqi3jNJilFCSXwpwj7SQyG41+yGTZTZXxiBislSBQ=; b=fRk/I49gvnB6WZdiuOo177E0hDSnz2oG4RDcvS0zKkHS1j10h1H6ba6HsMtcUwAVUjeTeEicnKLYd0jYXSQZJK7pnVau5IsW5NHbp2Hrf8g902JsgdzBQAGSj3KhBvKA4J8AKPGDVd8F0QxDvm5M0AVSLtA1c693BZw4vEef3Sc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB1998.namprd10.prod.outlook.com (2603:10b6:300:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:35 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:35 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 16/17] vfio-user: handle reset of remote device Date: Tue, 19 Apr 2022 16:44:21 -0400 Message-Id: <9bbc332432abcf2b0a88ce04c6017a4b98f17801.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: 8c46a0b2-ce28-4423-ee58-08da22458d96 X-MS-TrafficTypeDiagnostic: MWHPR10MB1998: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: K255OsJFD5Zo+8N5+lb6Iam4Qn5zFTVlTPRZoqlvQBig/537Xdr9EwCh0bkvLdiLqAWfX/Upv2xGPDIJe7mM8tENIM7+PtuTcYeRQnXwS7XarxGH2wjQQ5fv1rvwJBGbQWyFdXBNeIBab3SiFp+N2SYxlE59eaG9E7qTNnoWBqIy6t/o6X6SkSewAGHeAMfVnkSLISFnPRsmMMOrX02wcGeHHhGDen8IgslZaiVwLiMCZrV7Y5taaj8ybMgvEW2UV3zgVXdNDJ8/mWKqfhnxzlkZsOZB0ieje0eZeLP27B+XSUuKs/3LHx4jOFplWdKw1EXp2g3KnyEiM00GtqswTLMcvcY8qq7VuU3PSrg2E3MgrIK8cApyF55koTMuqWs26LOFgI8f7j8/FZIW/w59Orrny7KOiVCvNOHaFIbOuYaMx7mDzMOZzZnhcxrpSFNYE/enfM9gU9mtIABHd29mtmtReoF60f343VTdTCS82k6E4ixYQmeun29STqmNuJS41jcy9YkMfUqC5Sh5bibLXd/5gdryYxBWhJgHeoDeyI11wg8hbKUBYuNC4qT9QENPD08aOXmwapVNDHxj32tXD0jWxSkKET+WRZfrOTeEhuvXYebuAwSnzipqyY87BFGdBHcUFNrvhh72JBSEP+UKgkKs0QhznzZHH1jr+L0b5tbBQv+H6kqo+7NrREQpp9xHMno7Xkduhyr1sj91jqCbYQ== 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)(6486002)(4326008)(66946007)(66556008)(38100700002)(66476007)(8936002)(7416002)(5660300002)(8676002)(38350700002)(2906002)(52116002)(107886003)(508600001)(2616005)(186003)(36756003)(26005)(316002)(6916009)(6506007)(6512007)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: khWWmNIwgHUGDvAJHtxstCBCViTSGCTWcghZSQhpA8Zi9Io3g4R2dsk4CVbtbtNvLVVh32sTAukL1P5KVTJ5eGQB8KYncdlwgJnESe0LVmDU2vg4Ig15AWgF9GRMrzZvGsdl/KvEwuo+82Mvtze7HgBE9a7dgw74yUWiz1RKiuwXn2ErPN5TcCOw8Q5LZr5/7A9IeMmlwdjLUDZsdDlyzDUdDWwly02qRuq6/qkoB4sNjSFy2KjcEydWLyfXZ4lPRKeg4HsGMwHI/uburSnWr3yLFDf1pnq9Tdieq45FkpZGIq7yzJPh/2U8DCt/FvdFb47YNqVjfhVezNGQg64VyKBoIeFShQ59H4xNlKuGrhyZ24de1Zb4qYS9Y2yY0yFqv56nI6PYmPDZoSOOmfbV6UmK90Df+ZJmlyPUUAkou6rnUTJbrAQ4qF/0vW+VW9he9EGkZJbHZ3+zNdKwzgBEAj1Lx9IYwWfT0T+vw+QvtwU/gRWY4aBLdOyO5cY9mqLm8fNCtdGchG3odvGFqI5PZ+K4Grfnw96bypDlgPCipAINh3HRsrirFf0voSpEakSUXdxBycWDW8RjB87Rzd/l/jS6qtG4N/rsR+5KVrscNODlWpB7xlP4Pw/0vnEvVVQHH6PisZpgJ3js/+WNJUlGN2wZEA+lwWvmoDYB470bJ2XyjZxiFCQQJpL2px9QOmTYdcCwTgFm+FcnKvEi4Ma9M3m9a8AfPOx7YDMmW0sLd9g8Vy6QGQUTLGpdCc4SLXVMNFgWj+m3WjMG8M93r/7d7F31w1I1F+P7gYkQ/mYhpThYal+fwW9l4r/JaFE+kgxlMckTRh7VVckZf+ZvOxlMlo+ca5PGDG1qUUcN9HDepMWIn+82C3a4FeGLvNd5SBtJlVPiFrvQZA5QaqsdfEpvg/3qKV4ktKgOr59JdBQWOOAskQoNDSBilXqnJQqKrjwnBctFBkUIhis/7v5Gu8gIl+rUn7TrITmB7TlwaD5BheSud5Py1LCFTmgPSG6iktEqhYIrIH2qCSZzB91iSCPRUunRwVdngGpt3BxAQ23T88Emh3MB7sqihSQAT+7k9hFDMsGenA3J8onGzROzPgAMl9PGSrn5OAqZhnQHV/WLNaWs2CRMClRI/FNHozsRhINgCKqx6gZJoigNVUR8hEihU5Y4vi1Hrq6d276HzFOr5G4PIBsW+aLn3hxwd2Km8BKaIFMKHZtKi9jeEv9bukg4u8NUqsV+Lv99F618tHaNKsCgv5iS+IUHI5C1gHsG0+1TCoxR0dlyHEyLV/A52pXW2No6gBDDwxCBRfh7tcaPNpegG5drTepE/uhzKGUFKMaeK+l02rVVxV3rMKoXcOYA7V8jlzP0CJcvISLcOkh2F2Und7lXFULniVgSycQHAJEiBKqwtE4gsDlvQGgDMueHFESTivED/fl37FwGe/ODypxEdUVTVTSSCWT6Gmb7BMDw7M8qK5CWMIBVHHoEGGYnXZRCmcq9dJgkNY8vGs7kRRsrGizQmrZzkiY5YQ8SGeniilfU8/It9l2Cotm5tyXK/EtQFBH3lid761kF5rBtBs6LGikDllu7pwFG74a2JwMrbwOERZ4+IXnzz94swZRq3O8HyrbNaRX3COzCUqd0u3PMb9GHkU5Dp2DBUXjRspgmjUjG90Phver0gdw4MwTW6wVontjqPaMY+J6ZhS2NlVbjgCeOArQwPeECSEJ+5PNPt2tvVqqyTFVE4d/eR/WsVg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c46a0b2-ce28-4423-ee58-08da22458d96 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:35.1475 (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: 69nAID5vAAwej3NuEDGnajpi/RJ4m/Ducrnvk6ZQrqpFHHVOGQq6z2RSUZty+t7AEkL85dfBx3gMIdQmndN9/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1998 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: aQgnhY1TnigQUDFaToFzm757X6aEsISR X-Proofpoint-GUID: aQgnhY1TnigQUDFaToFzm757X6aEsISR 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 70b4d8b9ce..8ca823aa01 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -623,6 +623,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 @@ -728,6 +742,12 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_reset_cb(o->vfu_ctx, &vfu_object_device_reset); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup reset callback"); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", From patchwork Tue Apr 19 20:44:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12819419 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 E2EC1C433F5 for ; Tue, 19 Apr 2022 20:53:26 +0000 (UTC) Received: from localhost ([::1]:38354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nguqj-00015I-UB for qemu-devel@archiver.kernel.org; Tue, 19 Apr 2022 16:53:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujO-0006oj-Gn for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:50 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:58404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ngujL-0003RU-T5 for qemu-devel@nongnu.org; Tue, 19 Apr 2022 16:45:49 -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 23JKasAZ020195; Tue, 19 Apr 2022 20:45:43 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=GUQ5QDWOmp+enRKeOvoZKWGIddBaI7qXeYk0N6srFlk=; b=JKBvNbeUmbWS+udIwHsBI2Oaw22dR8y4KLG6r43EQ82b5dr004aQ7GoYJfQsrLcYa3yn DvB9VoF5C5M3r6JWgc0nJ3AH2n5gLVyp9IDq9k/9YO0jJO5DjyV+knTKtuOVCC/Omvdz Pm4NrTwjYIikkxOEgE5aRU6pPCSarrJq3BIaOVBMxKXm0ZKQzANnbQGA6lkYq08eignx bIUKxOaCdFxjvPss/aMJbDLy7J4wkm28RwrP7gBysBteGfawKe99P5GPEw6sO+BeWCio lWoHGg8RQZOMSVPClIPJlhjb+i7pjut7xn3T1ZM+jbYXXZE13vrL3TbTLb0CWSVzJ1Wx bw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1794x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:43 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23JKa5X5011256; Tue, 19 Apr 2022 20:45:42 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm838at0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 20:45:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J69QNvlJZfGBz317E30NmfIOMGZon5NxayOD2DSrrd15fAWMx/NuVlt/dROsLfMSX2dVIxSg9AYZ0KzPjBs4OVhzEssmeZ+N+nWFy5jpijaFfIH/l7TquXG8ScKwh5kxd/LxhVCSaAEuGKYlpDQKHMGq8Ukd9fzraSyjYZuwbpWdQFs2FA1dojPR9Abpvqi23KpyOPbK4WeJqWHg+yJP4E7k460pVrKdAXc6gg4qpIu0921xlS9rowkQ/z74d3pJz73Fb1bF9COUY30+YhXIEj17rjR/+xV7DqRhiLad+Tci4gdNC4xX4wrjr4eyJLaj+wDJvCrGigrWY1UrtBtWSw== 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=GUQ5QDWOmp+enRKeOvoZKWGIddBaI7qXeYk0N6srFlk=; b=ZxSaobsCPODpBxZe8mClku5RtYWqXnKjREVkp2LyBuQB4lq8gqqQScIAS5gr0PpTMdV25to0UEWwvT15CXf/3liYAa1J8xQSQ+M4zZVMI2OTudHRAZEhyOWv1kKC3zk3ViisBAxso6M9SX9D5T9bp/2x0JODFBTN88r0vCyZQemxs8Kx8BpsuLzLOk83tJEpVEP8WyVhrj8V4WZ8IR6b2/jUbuZhyxR2jePqi4N1Xqa6qq+UZhPJrtD8bnVf/wl9GG4HidTawRSXI/0zmkIF4WKuC/otPOG/45fNNSQNseUuudTQ1tBZ3gBwiqAQsvefnTZALKVnBm5UKhXOBVKJVQ== 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=GUQ5QDWOmp+enRKeOvoZKWGIddBaI7qXeYk0N6srFlk=; b=q/vNsJ+wRS9GM/Dl38Yr9YQzha8v6sK3qcYbIHFsMkcLE/US0rINLIwqv80i8qftgSgqevAslUIyAINDTZZi1bDwmmw6EykmAeL5fPYU2I9eI2mcP8fRUOUK/6wsJG8aYnIu7wm8QePiw5x6SaRVHfvqSQROtVgRYct93GIFaAc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SN6PR10MB3006.namprd10.prod.outlook.com (2603:10b6:805:cf::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 20:45:39 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e104:96ca:aa5c:2bac%4]) with mapi id 15.20.5164.025; Tue, 19 Apr 2022 20:45:39 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v8 17/17] vfio-user: avocado tests for vfio-user Date: Tue, 19 Apr 2022 16:44:22 -0400 Message-Id: <76de4c8c901073750bac314877626be51682711a.1650379269.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) 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: ed71acb6-b931-4c3d-c62a-08da22459002 X-MS-TrafficTypeDiagnostic: SN6PR10MB3006: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: bFQe/L25Oun+NO8X5BoqPu/NirrMWToFVg9eqFByWddwucwz1G+0KjkWEG0ClRtHORAaes39G6WYDH1RMBWq7MDBABll1Lmb0VnUi/USsU+ILfdNub6FK2xNKzvj250+V7GPhxfgxFjJv3/IewhUp4sBU379JMEY/7omIGgeRCWAPhGJzfTIFL/XHNlmplxUc2tvBceHh0ZmP6PlLIVb5cPQrWGLk57LARIFsVgIEdZ7TccHRhojKpwv/LfoPNsLb/R66bUTyO4gEYniNdwKGXUM2cYWxIbh9nLTH1RR36fhF9WMB5y0Boy6ndqyKVe4noiL4J1EPxadOJS5YPQRcIhVaKRfVuTdJdiI1z6L/qTLcS8N4YBopqz/TaPjEVL3sSnY2SguaC8tqTlWDjsuc1KUdb+q/RpEPsCVf6fvSkTw1UlE7JwttdLkUv23zZVQC7Y5YCI7aqcn6TMciP4rLnqOb1cvqCEfgW7ORKdOqbWam1gByNRpyhbPsJ9rB8NMik+FhnGN3GMMHTUxnm0dkAs9V11iY9nk1E/ue/QaAiFyK1agw3n27MW1toM6RmwrGrXJJtAy2IVuTca38+ZvCcyLhKboerYV8Fs3qEMUwk+ajbMCekHIzJL4mXyxsDQ7xCpRCUzhJVjA1R9wF2Cu3d6Yf4UjLfodW/VlElV7TSfA2nTNjxeZJx0LrsWlzYdFHOK0fGZnKseyAdYgYZpac35CRdMmtpVXm8d9KBFUvrqKSw2X7gcgFTjf2SdNRBlA/QD11+X5iw2R7r834OxCrtbfiPYn7a5Y3yVdWx2mH2k= 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)(66946007)(66476007)(508600001)(107886003)(8676002)(5660300002)(6506007)(66556008)(8936002)(83380400001)(6486002)(316002)(2906002)(6916009)(36756003)(6512007)(4326008)(52116002)(26005)(86362001)(2616005)(38100700002)(186003)(38350700002)(7416002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z/vPbXPkpa3/II0edgE3xw8ntF/71f+uUWp9rYS4rOxO4sYyVBLLxZFxEE4r6nEAiVZgGUmWWprGUWqErZ15bqpd7ULkUztzRx8gb5AWlDGj9Obs123/VJ6HCgpmZckiRsLJA7N8I58Z6FDjni25pyQ/dIBli/zovue35y5yaY/13ebyasIrKX4mOxCiKWQugEtyceGduOSbW5MdykRvd1MgQT04BISJ3NElZc1F0Q9VlOdBKfWuXR5YWmVxGxelr37u4o0/1eMTebBAJs2Pyuu6AjrgK/l2Dg8viB1BIiad0bEihAH2ijOmCznMlwxMXDKfDmn3R6YEyLmSVhCBJ1BPrLW6WRSknAP95qtrqIxRRyZAv316/I+n7NmLqGizIw/V9I0TXNvhqcO0Nue8METu41ei6eFrjiVeF+skVXb/Eq389jrD/9njOtQCIo1ZOYTnXdPQnBAZ/ElTOAWjKspaEhEDYmlysz3RsN7pmsAaOqQjXPjXfMxBaq+WrCb4pInJogf5wyBb2t2sucRgBHL7y7rWz9ZrbDfx3uD5M7Dkm46cGIFf+9Iy5a0OaKMOI/flg7TzazxBjqlVLMTC0pciDJnIvCoZYedQEptwMZQ5o4JcS+NR2TwRlfZpMivChbR19W95rnXoUOH8TXuCqmJe/irU2U0QoPJGSFMxLvK2UoDViQVu9TXOaq6wA25ytswh8BGUgksIE4bFp1OBwyTW9s7PoXWWHsMsBX3lfUMackMvKHvwaeIw1NyhhH2WJuILwZcPI+29MmG9iRjCyzJYesMB5tXiBUevuWELIGoJwlr9O6NYFSwX/wBa7ut7QZV3XylPv2Ssi2aSJxWnMta1DfZdrSf3p0KXS9y01R2ckn7iPKjcpkjEYZ19Rba2OzKayRqM7ax0Oinc7hts1Dr7NQTp5G0yvfyfSafNEdsNZFHObzN8untixcgpNQLJ4Y/UslUgBr6W7md0HDkLts1H13BMWNUwWJh5ZiEBc7kTqb3Jibl4R3Ssm2UN8uKL3zjLcJC/aNP1MmVL2CmfQvxVKTQOuC7I7tJun5AsLfXlx2JOdpn0OqVRCQ9byzrutbTeogSL0D9arLIVEnLhWzualckURFZhSuJv1ENEjYi7md4nvD98RnUL3UvbkHfLHKMcl3sfvLzS61qJOm6Qn5WIh5C3pUoSIo7Bvp9cSQrLP08Edzp75jwjjlXT8vCFqok/afVnKAc3nRBWCJvTsWBg0iBjPicO69NIZWs62u+9+xb6+iYRFW9kR4/60KZqlBWfKJRH/zlywh2oeYLnVG5W7Agc2R0Tntpi7ro6g9insNS7JUrrXRYxaQCTiC3Mv22ahhv0PHIwj4BInujn6UCs28OAhFo+Ndjuv3Th40jYxxnc8ycbssWwlHi1mC31bIw1ITHojYkf3a4MnKMAe7qBt+1R+BdYs6RLj/R4B5bncap1ySeffe7uOWQH5nVorNy63jlrmPBwXNxjvKwU2uWXVj9W8ZRnTldfOSRpIovIBL/EfgnvyoiYi/gHWDlAY67AECcprEqnAdX5Mt+kgPA7b6rCkKIjgEh2tekc0zK6QpTdzaDqoOsLJ6xl2sm7+wZCx/ppU2VXgmMPA0MyvOsuqAdJs0eHLU+/pffw2UgYwXbydIRe0jU9H9QTOXtzgtohr9Kos5ki6W8kJjZsN3B26+BaQ119kyO39eYNt+jHgWVz32TI3YUk9olp2ATc+ZzWLSiNXs5DOVo/EIqYGw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed71acb6-b931-4c3d-c62a-08da22459002 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 20:45:39.1941 (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: IfTy5b1Ixe/PWSzOXLlUKkenBvtUwVdoS5iNsCRdae8nEJKVj/EdDfIHUT3JEPKqkYKbIdoVy5NKXg7FNl/OGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3006 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-19_07:2022-04-15, 2022-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190115 X-Proofpoint-ORIG-GUID: arJEvMRAY39RkbuX_c8FEzlJMDJstKCH X-Proofpoint-GUID: arJEvMRAY39RkbuX_c8FEzlJMDJstKCH 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, thuth@redhat.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, thanos.makatos@nutanix.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.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 ad51ec0dc8..8676f546e9 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) +