From patchwork Fri Aug 27 17:53:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8797FC432BE for ; Fri, 27 Aug 2021 17:55:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E7B1160F4F for ; Fri, 27 Aug 2021 17:55:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E7B1160F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:37350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg4y-0007hy-Tp for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:55:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg39-00056i-OP for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:55 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:5660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg36-0006lX-SS for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:55 -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 17RGaM4g013604; Fri, 27 Aug 2021 17:53:46 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 : mime-version; s=corp-2021-07-09; bh=nk/mNJJOF9JR+QEoTONQvGTOCsWn6uIcziEOqnTgdc8=; b=CxWrXRPlEVeNnn1Erv87eIWrSutMPPIsKfzejbZh5g+SEURDKCOaxHHtCwkSDC2xAXhj e1a24zfYscxcE0xb/jxNSk+NPmyE+O3W5oiQ+z7BOS1bFxWSRfx8Mo5Twp6oaOEOfF5i AN5SgLb2thY/ckEmM1jiPscw87iE/LdI2cjQ0QoRiYeCPj2kgEUmhbvWK4FR1eMgOdeA b2Ky4MWgJ+FTSCptBp1w3avVuJ7QvF6T8eumgmdpWVtFR7ihdj5NZLcz9Xls99q/MmXU 86LjFyB2SUbQtKYkGZeSSrotyFJIgERsgka1A5PJlfR6PrqoIf/BW5ZDcvQCSLHjOoqO Ag== 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 : mime-version; s=corp-2020-01-29; bh=nk/mNJJOF9JR+QEoTONQvGTOCsWn6uIcziEOqnTgdc8=; b=lujw1nIXtYyyZ1TaGWZOR4joHlkDeaO4h76j16Mj7UOsNagdc10QlJgCmDHo1ZYWNEOW Zy/91W+CaoQbtAqq1prnGLhsgUSO82tBTbPq9gpvlFh7xWbq5hs164BmF8fNAYGOKpOL hV/J93e800ryZ4BBwj6B85GVme8yvIzvj/ZVZNVEJHTy24OxvgOo2HxIEwYe9oCtr9qU 16zheqKqs+rXlWpGvp/9FqD1cANtkVm+n6MGVGFx4unEpjJ0VErpaDsqJ2AhBUy/NGIx 3CaIApkqGbLJCcHkVZxRnWcJm0n8MMBBM9jCFSJqHOwbt6gP192Qf5jJfIN7LHlLHhQq rw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap552c622-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:45 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHnnPM173202; Fri, 27 Aug 2021 17:53:44 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by aserp3030.oracle.com with ESMTP id 3aq2hupwfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FS13T8FfOLIl71ppGTd+9rBbStcTidcdxplhOuSNr508w8kWTj2bciq14BD4rpPlg8p/7Dc3KcmDs57yq3sLTeo6HjuS6aa8KKPNVsFENUOOecFaiSizGOaJWPZnHU8XfZYUTHMut9elTshpscgDbhhCXcYrpZxclgblubKv9aR0iDVlTrftV5ArhS2//nTW5RH6VSUA4vb0EZF99Rs20hMV+8eDjL/aYNJce2yyaCkDp3A9rjex3p3yyt1R6i1EYraGC7qnbE3Styl2wHtSRReuSLs373oz+1PCE6XjgD/qCYoWm2rq93PGi7Twd2RB2f0ZGIgoapynAF3lPCqlqQ== 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-SenderADCheck; bh=nk/mNJJOF9JR+QEoTONQvGTOCsWn6uIcziEOqnTgdc8=; b=f/meBfCnkPgkUh+eYfjylTeiM0EwOhqkzA8m07F5HfH3WbdvYPLYIRnBKOofcZC/4wEmKZpGm3Mjih73APgZpGVVYd3xPZ7GaP3hVGc5MmHV+pEF3GQ5yUzXUYWxRJ5d+5mFF8EDchhzq9bD8HvZ/hCO/UTZ7TsH0LivTIhWbxDN4SKJwb6zJzaKIoGqwo41PYzXkrB28cKEJGKJnXE8oAb1AhFfBLmdko/cBNqnPK7VWHrl6VGjL0Ip7+eEkfBjUuIwu/4BfwaRgPcpwa2+dCKnfnnvh+DCyT0SiaNtWR97FM3LPlVwBB76xpNFqerBzUf2/iZuIsbFEFlM+Bp1ig== 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=nk/mNJJOF9JR+QEoTONQvGTOCsWn6uIcziEOqnTgdc8=; b=zXdfwx0503ZLGIZ7+8QtUAdHubbUfaq39KPgNkPbT98vFo3M+B1HdPJYOszFBM7x/FGKNjymxj4Y5Lo9Z2POe4Ytm51j+oSkMBu5yiDBDxoMEOt1ZD8ZZFdM5s8tD/i7PTkVVrOhdGa81vHVgYBwHcGtuBlOGSGJyymIDgV3b2Y= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB5187.namprd10.prod.outlook.com (2603:10b6:208:334::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.21; Fri, 27 Aug 2021 17:53:41 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:41 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 01/11] vfio-user: build library Date: Fri, 27 Aug 2021 13:53:20 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4cf924a5-e113-4005-e31d-08d969839ab6 X-MS-TrafficTypeDiagnostic: BLAPR10MB5187: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /ztO5UyEAZvONA2kNfHk0/vUAx1toL5D3QMZcPmvTTt864/d4Q9YUgQ7hUuRp/9wHfPZfCgN4KwPUNHVCXmfQ0+tyVmU6CcIo002wy6h9qFQvug6nr5PRlkvnye819UvZzGkGWV1LjCMm0FxQq4IcmaSGBW4genbLPjORA0FUIf4E3yyhWlW/jEZTcGXAacHPInRo0NxmlByeVNl1CBMGquG2rxfKsdRFyvz7ExX9at6UyhvcbKxQ1jsDH2bTASp2D5rUA+ayGUcIy5g18la8n946qJAAtDodwYgFolpZ6pacxL8Kjeb7ld0LJkuOKIonrP1O42Ppi6bsyLRvscScMviRJQJ8vdyGowyZA9X4PRn7YU+9OYUlE8gOXtAtcE8161jlgs7bDteMmdCsjsleu1/j+PGpHp/YjQE5g/giv2gm1OiaQegzMU/MY/oQOGkegra8kn9C/7U1TS4IfUQZBGX9Ed8m6yS5igZGUBeStlpPo3gjJT4FeleZA9/ZfWWE3C60sJkaEhBcsmAAPil+YbKmC4pTjgpdnDoYqvE0QlSCkrJQQHKQecUfF+Q3ztjfjVxQ2iQn+XjZ7dHPl7wqtyJuqXpndEC/j2zeo3WXENenntm8kqloEKQLaeR2764ACBxs+ABWboxolpyPax6JKIzQ2AqzFhaXI239OGl1Pt3tsFfGz0IB0gwgAYg4znRW3Vbs28RDRHNOyduqzAO60yFz3ZL1riKynfH0jDooMalCpeSnpUo+s1D1NmqnPaL+K9lYDWtASbhMD868G4wySFklTmVgOwuNevxJLT2bETxTaIrXtF+qgDVCDcnWgcALTqGLGSlZOXwTP9gNuq8dQ== 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:(366004)(66556008)(66476007)(2906002)(66946007)(8936002)(7696005)(508600001)(966005)(6486002)(8676002)(6666004)(26005)(52116002)(316002)(5660300002)(186003)(36756003)(6916009)(107886003)(7416002)(4326008)(956004)(2616005)(86362001)(83380400001)(38100700002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hvc1ex0vagcIJ8+w8vtLlfAW/ckLhpIKovUm+n7fK4PGTcEIHmE4KKLBPWiyouGMiB7F2y3nclbyg/AFJ5hmMUwpM3PRltRbiQzJlibfs4yCVzIk+T7y4PfS0f6w4ie/w3fTTxW3vZumFvaSLVdWN1KkToEe2kIXWamU7v60i2DpLHjeHlVnIsQ/GX7FB75AEj52Te1aU+kedKJDfCvvys7BUB1u1ArGvt6bUa0lPsZHsg8SGJhaLyOLmLzUsw5/+RueFQHJZuiDUB+2volMopDUhpP39mH8/75mO8AcR9lYxlS9Z3HvUthwrv/wJz3Kk8iowsecrcom/OkqXChxAHob1tWsEmZxkmodD0ndwhVZYDgE/sgxwM8Q3RjapH6UrvJJR7Uoq4PI6JuM4EKLhGd++EFGWE4xfjJ32Do6d3W3xVIpIc4WaKJPgteZzFqinCTZ0kVlw4lHX5wDibG809Vgf89tmUGtWjVNLVk5Wt1pNIRhU+HtkyszomX78IoHZMlKEhR9dFntlBKz193W7B0dXgqd+TwioHaJy8T0gUi/sBjItQafGIeoj+eiPgI76BlBh3NY7OHnAmuxyHsC8/A8XBnPc7W8LIxSIyqO/esHW14GrBY7/qKG7pbtMg6vEIm3Qzav0warRG7jLYI4sdBkVi+Mo/OC1m1uaU3PEAmka5t0IcAAi+ddFHCVrQSzNvjJy5S8mB8MY8JflSDNnAHllu5/SQhMJuEpzA5hEQTD0p7CLjFaS9VU/AyZCWnmPLNRXG5SeT4RMijiA7c4L84fVHfKhFrdledSlKsQ3YpK62UyvwBrddGthFZZ3Hh9wb4HbcrX8AdvsiYYqxgi7rEGi7w2y+O6oIwa43+5gW4t1wDgFHEPV9b7JD388s6fbbi9KUc4oNX38AoPmhQCalaatB6CJqfH10P303MakhISgdDj33row+/GISo0ovuUNoM/vhPF35RBZb1L9OceDUQao4oDTNyc479cZb6T/usKp7qY7gzEEs/ejdYM/M4e4dk+EAeAlLxjoOGG8I+SWXB4hJpQ6en8xXm583fER0+ShFw1BXeYZm6lxiC+Qhy7gEPeUmdKRsZ+tMbMKJGTDfyWHTMp9hEseiPkeAQUHwNYI/6bYxFlGb2qvTBuX9QY4y20gx9SQV2iX8eEVd8zPOukkpdEPUPJkXrd3djVStbu5fy5LM5yphRu9GQWfmiF6f/YXaMMnkQPwpGb447QFo/aRNTx/RqOpwvZvS0DKWo6RA2MVUswhRMhLoG36SRrJRh4Fc6DOnwt+uhU0MsmLl6BgD4kEtWu4Y3p3h6sVolnvUPbGvKLLV7RPZnDponA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cf924a5-e113-4005-e31d-08d969839ab6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:41.2342 (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: HeXOfnvcd2J4gjWtM09e145i1QHVGfncypx77kstePWx3R6zHa5S3qe6jEx8CahbyD/EkAFzHfBq8X2bwg2ZTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB5187 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: A28R2XE6mGqFwO09Qs5f-P-LLxDss7Qk X-Proofpoint-ORIG-GUID: A28R2XE6mGqFwO09Qs5f-P-LLxDss7Qk 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" add the libvfio-user library as a submodule. build it as a cmake subproject. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- configure | 11 +++++++++++ meson.build | 28 ++++++++++++++++++++++++++++ .gitmodules | 3 +++ MAINTAINERS | 7 +++++++ hw/remote/meson.build | 2 ++ subprojects/libvfio-user | 1 + 6 files changed, 52 insertions(+) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index 9a79a00..794e900 100755 --- a/configure +++ b/configure @@ -4291,6 +4291,17 @@ but not implemented on your system" fi ########################################## +# check for multiprocess + +case "$multiprocess" in + auto | enabled ) + if test "$git_submodules_action" != "ignore"; then + git_submodules="${git_submodules} libvfio-user" + fi + ;; +esac + +########################################## # End of CC checks # After here, no more $cc or $ld runs diff --git a/meson.build b/meson.build index bf63784..2b2d5c2 100644 --- a/meson.build +++ b/meson.build @@ -1898,6 +1898,34 @@ if get_option('cfi') and slirp_opt == 'system' + ' Please configure with --enable-slirp=git') endif +vfiouser = not_found +if have_system and multiprocess_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') + 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 fdt_opt = get_option('fdt') if have_system diff --git a/.gitmodules b/.gitmodules index 08b1b48..cfeea7c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,6 @@ [submodule "roms/vbootrom"] path = roms/vbootrom url = https://gitlab.com/qemu-project/vbootrom.git +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/MAINTAINERS b/MAINTAINERS index 4039d3c..0c5a18e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3361,6 +3361,13 @@ F: semihosting/ F: include/semihosting/ F: tests/tcg/multiarch/arm-compat-semi/ +libvfio-user Library +M: Thanos Makatos +M: John Levon +T: https://github.com/nutanix/libvfio-user.git +S: Maintained +F: subprojects/libvfio-user/* + Multi-process QEMU M: Elena Ufimtseva M: Jagannathan Raman diff --git a/hw/remote/meson.build b/hw/remote/meson.build index e6a5574..fb35fb8 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_MULTIPROCESS', 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/subprojects/libvfio-user b/subprojects/libvfio-user new file mode 160000 index 0000000..647c934 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 647c9341d2e06266a710ddd075f69c95dd3b8446 From patchwork Fri Aug 27 17:53:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5EE7C43214 for ; Fri, 27 Aug 2021 17:55:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4C2A260FC4 for ; Fri, 27 Aug 2021 17:55:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4C2A260FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:37492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg50-0007n3-AL for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:55:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3B-00058C-Ur for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:58 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:9756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg37-0006nP-Oi for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:57 -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 17RGbv36013579; Fri, 27 Aug 2021 17:53:49 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=P+9XTd9MrV1X3OyNZAl9hox36Us575eGuOkcQ5SGFEE=; b=bv3JDf+frh8O2+GaT6/6mf17pq2Cvv2ojfu4JMbynZ3VHarhEm9NLn13VuhKfFmxCu0h Gk1Ld/YLgI6MX54lgQ9M/eTZtfrSLCUJOC+3kJW6zZ+bKifQhogPNgi/rg2+yZHczI4t vJoTCiIEFy7tiPMU4ODboxIEmuGIizMazqbnKDE+ocM8V4Oa2+HxIO0SMNXLSl0pb0jP fIEp3KML/lZNN9vFNss7+ag8QygQnCViCcMaBJHfLdTb4nSd5SvGU7A9ER359owFbaKu VpvIeO7zZbZYDNSdnP/aiV+AM7kpynIem154kgMQ9l+LJ6JiKDfN+rkCpA9XCerPgntL 3Q== 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-2020-01-29; bh=P+9XTd9MrV1X3OyNZAl9hox36Us575eGuOkcQ5SGFEE=; b=BZuR+XIJyNd7BybNrLRMLiSNlh1INalnwFRncJxoPx5NUBjKjeBMA9cK7SabvymjlMlg 4U2N9xj0TXnbRrHjNySPGjEVRZsmE3d7MrbPGCLEJ+/nVZU05XhTkfypnoLOoF4nivhT CACJLo+lOXwsmwUmDlm62/W1gmcnfWKZ3rvU1ac6O8whqzcP8zDidg1kureHyZiYFrNM EzWfGXkWfG5FxjAKzhNSTcfjuoUIbEFeofMy/eEmjq6f/WSBqGwxqp9wUdSW9PsGn9d2 UOUK7OAdDfTQ0AZcMdMA+l/7WgLTN+TyanMUo1gpLKG6fgC8P755L+eBf1RKXnRiuj7k KA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap552c629-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:48 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHpjc5005351; Fri, 27 Aug 2021 17:53:47 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by aserp3020.oracle.com with ESMTP id 3ajsabkbsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BrILTSVa7JDGqn20h12/PME12+gmYPfIwsVF444kMT+058uY4iw+jmVJHj/u6bgVpZ+6cpMr8AVECnfhMToFWLkK3xJZrMKdogqFaJbbfmnj694z353PXoTPBfzSb6PVBrk+C7RqKCfAB6SCZs45Xq2EONegT0ck2P9M363xm9Vks9u25Dj7rculZMyYCQo/VfPYG2NO4OS2ZcQ7igJVG+NfBvkqGgKzIcJOBq0v/ZYVNR8twigIZ85jUiLQy/M4/j0A0LpgabEDmjp9zUWkEN6o1sjj7dkcJaqLOgfVS7acMRwyfhyxAKCMnFQ+ofO1BWjNYXrrVminXY0DyaLGGA== 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-SenderADCheck; bh=P+9XTd9MrV1X3OyNZAl9hox36Us575eGuOkcQ5SGFEE=; b=emKLmwKi9z7uyPx5wUzdzWlCuTguVDoraGQHXiL0d4hNt8rz8iou5j3fKL9gQlU5iMKz3WCoIec1pecEh8rNlEhw9aWzYQckyYVDJbZEAvmZ8quAFEOOluf5f/deOLyoODb5hWVh5OTPGY/pTrvoHnnGC4wyG4BJMG1SCsq5UMZO8bgcIqX2lFnX6QOXh0/pqt/KyfvwmHptSmjfsR+JFgxSw3qnYpz5aw544w/nKomC7DHsK4QAwLRRYqKH5+MGCr5qn/blo1szr97p/iL9zXibNqakqDKSMqQc0lWUj6/AkYhhoNiP3eZzXz9uaM3c2VEH0H3GKi83lHnVCbfG+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P+9XTd9MrV1X3OyNZAl9hox36Us575eGuOkcQ5SGFEE=; b=j0FPNziKno83B4JMWQnu+9JbPQsH9Xd6ffMPgRTivLRJkgsgsos0RrVztStoVfC6LuBrIQSrm9hnVG4gsgeObtAgvpX1TAkhiJrhBdWoJXSYGG6eEcnvziVZD4as6hkSoZbCzN02U6cXHttXnegn3y/J4ggYeIbz5/08CjSJluA= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:45 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:44 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 02/11] vfio-user: define vfio-user object Date: Fri, 27 Aug 2021 13:53:21 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb5f2cff-d764-4362-7be9-08d969839c99 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:421; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Z5Y4d60wK2CR4QQxfvd4HLhCmjjxvHZY/VtNO/o+ajLpE8leqtewpj07i1WaY73ud9YKLl6eUhuSNRNmuOMKk5V4F7DLucZvB41slFdgsIDXpMbDIUP/Fjwmkk68hKroGs2U26QLBTqTnlsLKMErEVJ7AsP6molYCNp9rBIJfBDIYCgZVDt8ZyTIrKh3vjQmqmqeNJeUwmQJV/yFU2izg/FegxsTLGeZIfxxDNgktx4Z+43HBAjkUb1o+fgpY55VZVqEW3T6SeRWP4NUENEndAOuDAXD0d/Wym/sBnqBelmgx1f5y+Zi8HD8UCc4XvzBzbgw01q0kvFBvMrVArjVlwVuB2qsLlF/XE40NMKg+tRl06K/blGIOTGkPx+ryiDZVjeeT5Z/dh/5PYfiGmCavj8PqgJcSaq5h7g4voQjXfJuUxUHSYoCAyiwHwl4hDumA6jQ+a8I29+i2Bn1AHGw8stfUwHO49365HJRoZe9aI9FeTfklynk8hw+nguPXFgFyiWKzx+O0LbMNNapwq+LQ5YCgTQnFNS/VPI0nsfwkYi5oisytYk6qpDjp3YsELxnR5fLTh9qF4ArR4dYb2OB4kBvBbMO4KmQtT2baVXfwAvh1SVfC76ps4BAwFom4uQfAY9TRCABPNxsMsnmsiq0aGJk3NLgRzA1dmccfe8p3+/tPScxs1gY4FtGRRK5uQ/5ifOGVeRMUyzZN7A5lD8FQ== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xkVppHvPXQPtXun7qrteLypru16Y?= =?utf-8?q?J6CjSpyHNePgPlNGMgPq0PjHdtajk443BzdYe0aTd3W/RTpoL5YcmMjNKPlBEDSii?= =?utf-8?q?pcTWjrRgaX4aXi7GXbtVQvpv41VxpGvENvc1N3vva4r5VwhLQobOl04McncvIKQa/?= =?utf-8?q?59gD2g4yhLlqOxtVX0Nxe6lc677yIU8xWwT+wSI1hybnM+HtfLEndSJ9uXz96H1+Y?= =?utf-8?q?2n27PLdNXijug+29fBl8fuFsR1Y9+rmlh0SOo4a3HXHdY1MfS1kWEde9CQb/6qJlk?= =?utf-8?q?nDI5KFPfZg+GUEjZMKWT4WX8CDxQ9gbJbSfSh6xpMG10sUsWxsVBu8vIa/oQK8xUw?= =?utf-8?q?p7TCgkluRjGQg9J6GbanPgLaS6jNIYZd8lZVPW/QuCqDcnO/kUplJWPRKFECJPhEJ?= =?utf-8?q?a5JKVzGp+0YMkjDEp9BpE/kzdhBOrWF/mnuX6t22KEDR36NyPUkKlJALOHGzxEQdz?= =?utf-8?q?vft0y1DEycNQZQClG8muZV1DFgtYybGq+RYc3bIVnnrA8IZdOWsZKwOm9UZyjpDv4?= =?utf-8?q?qIy0BOepuG+9XF1oT7ck43ZdYeezMGzs7iGwh663FbvCsc4IgtHo76+drHPwq3ro4?= =?utf-8?q?RTaP88ZRPEVJS0KvSnjMW4cvFzaKcMBSSuQj1LXLWdLLxlQfGLdQHzJp/uj22xSJg?= =?utf-8?q?B2wVzlVce27AjDw9L1J8WQ+saNfQl+1pG/YxM/+yXwdfc8uVrDw+p7XtW5bX0M7WJ?= =?utf-8?q?7XEYCgMDE3NPCftdwZGfbS3T+ikuBSdUniRlA5T92eYHQQwoDTW5T42haAauNU3mP?= =?utf-8?q?zHK0HaJoX8U06RW7SwnW5c4sehVN0bBoI/15AI7e6eb0ZbCi9n6+b8/70WqjuQpmb?= =?utf-8?q?Qeeg2Vwnm+iDZVz+y8gK/FYcyxBk0vWEi3fyswyaZb76Hq0ueledQ0J20jBL+Phf0?= =?utf-8?q?1kJcEowhg5z3fQDbns7fTaoot01fyRsU2I7T7a+9SaLR1jNA3VogBgCIIlnugFcLr?= =?utf-8?q?Q/l3VtW/k7f5H6YLzBTbJeKoSL/xqN0t0OawzZks67xirJPbUMk/TQrwvxy4mm5Sq?= =?utf-8?q?u+/Gpdz+xENEovySwcNKg9I8OCU+E55EoBGTRkLuOW6BwZKylYt3+1PXFSGrvYhvF?= =?utf-8?q?NX2MKbxVmS7/WwFZUggUaWtOW0yGH2CktupZhqC+bx00QHzw/z1TQqY8Ire7yF32d?= =?utf-8?q?4fUGZcY7yEOLRkXrs4fctLO7G+IbmuW2W1PW65wqAh8JJ9f9fkjALxUTLqufjPHYV?= =?utf-8?q?vMZCT2NMCpxnovRgq7jIuOZ2lkqc3uhuFqEyzAILDqsVR1QgxtDJ1oPGlkGV6le4U?= =?utf-8?q?+fuhQrusI0dhx0rz?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb5f2cff-d764-4362-7be9-08d969839c99 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:44.5609 (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: paVVtMCvc47gwrUeMlsLJLXSrv53zkNRlpR2Itwx6iCF2KVP3Gc/As3r6OXdNStIlN7pCcwJug17B2LBxou1fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: vJlmNxe_SjmrLBz3S2Zdr-18shj9wTFq X-Proofpoint-ORIG-GUID: vJlmNxe_SjmrLBz3S2Zdr-18shj9wTFq 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 ++++++- hw/remote/vfio-user-obj.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 5 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index a25616b..3e941ee 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -689,6 +689,20 @@ 'data': { 'fd': 'str', 'devid': 'str' } } ## +# @VfioUserProperties: +# +# Properties for vfio-user objects. +# +# @socket: path to be used as socket by the libvfiouser library +# +# @devid: the id of the device to be associated with the file descriptor +# +# Since: 6.0 +## +{ 'struct': 'VfioUserProperties', + 'data': { 'socket': 'str', 'devid': 'str' } } + +## # @RngProperties: # # Properties for objects of classes derived from rng. @@ -812,7 +826,8 @@ 'tls-creds-psk', 'tls-creds-x509', 'tls-cipher-suites', - 'x-remote-object' + 'x-remote-object', + 'vfio-user' ] } ## @@ -868,7 +883,8 @@ 'tls-creds-psk': 'TlsCredsPskProperties', 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', - 'x-remote-object': 'RemoteObjectProperties' + 'x-remote-object': 'RemoteObjectProperties', + 'vfio-user': 'VfioUserProperties' } } ## diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c new file mode 100644 index 0000000..4a1e297 --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,145 @@ +/** + * QEMU vfio-user server object + * + * Copyright © 2021 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 + * -device ,id= + * -object vfio-user,id=,socket=,devid= + * + * Note that vfio-user object must be used with x-remote machine only. This + * server could only support PCI devices for now. + * + * socket is path to a file. This file will be created by the server. It is + * a required option + * + * devid is the id of a PCI device on the server. It is also a required option. + */ + +#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" + +#define TYPE_VFU_OBJECT "vfio-user" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +struct VfuObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; + + /* Maximum number of devices the server could support */ + unsigned int max_devs; +}; + +struct VfuObject { + /* private */ + Object parent; + + char *socket; + char *devid; +}; + +static void vfu_object_set_socket(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->socket); + + o->socket = g_strdup(str); + + trace_vfu_prop("socket", str); +} + +static void vfu_object_set_devid(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->devid); + + o->devid = g_strdup(str); + + trace_vfu_prop("devid", str); +} + +static void vfu_object_init(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_report("vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } + + if (k->nr_devs >= k->max_devs) { + error_report("Reached maximum number of vfio-user devices: %u", + k->max_devs); + return; + } + + k->nr_devs++; +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + g_free(o->socket); + g_free(o->devid); + + if (k->nr_devs == 0) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static void vfu_object_class_init(ObjectClass *klass, void *data) +{ + VfuObjectClass *k = VFU_OBJECT_CLASS(klass); + + /* Limiting maximum number of devices to 1 until IOMMU support is added */ + k->max_devs = 1; + k->nr_devs = 0; + + object_class_property_add_str(klass, "socket", NULL, + vfu_object_set_socket); + object_class_property_add_str(klass, "devid", NULL, + vfu_object_set_devid); +} + +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 0c5a18e..f9d8092 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3391,6 +3391,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: hw/remote/vfio-user-obj.c EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index fb35fb8..cd44dfc 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('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: vfiouser) diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 0b23974..7da12f0 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -2,3 +2,6 @@ mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" + +# vfio-user-obj.c +vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" From patchwork Fri Aug 27 17:53:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A664C432BE for ; Fri, 27 Aug 2021 17:59:14 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A0DF460F4F for ; Fri, 27 Aug 2021 17:59:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A0DF460F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg8G-00067N-BZ for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3C-00059N-Sx for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:58 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:15736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg39-0006oo-BC for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:58 -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 17RHD4RI025386; Fri, 27 Aug 2021 17:53:52 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 : mime-version; s=corp-2021-07-09; bh=YNNOWu2x49LZfAvAzV43p2VgWHitn4HIrGGwz36Kir8=; b=jsD4r8Ebq5/KtNAqhgp70H3Zc3ExtumHNk+J8YAbmsVvkDQLrt9gDxK42LUuO52sfdyE NEl2LRLhBqFpvKiKjoLVDy9L3S68hNU+V2pwu6rhHvUJW3ZtrsHWVur85p3ErPTNdqMD et6KrhalPiIWK5126JY46brQSEPPW8W3twIvQNiHVR09q+nxhKgsRA+aZ5KHJwKXzoNp vd/cG3fv+H7ZkLz9ep+VcgUDTEe6YpitPCaIBcuq9Xmc94UBU8N6DeYVubXL7e/RzMc5 gB44KZGBj2VRlsW/NBXewj9/OU6O/hGoGzCrnb3hUihxwJE64mqcQFJlv7EvhTlGCKj8 lA== 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 : mime-version; s=corp-2020-01-29; bh=YNNOWu2x49LZfAvAzV43p2VgWHitn4HIrGGwz36Kir8=; b=fvg4q32ad0IJg7AkesU2vRloMv8ehW1v0Vxl9d0t3I/R/P9Db3PGqMm51j+ZShW+A/jx ESYi9bCjBXtVxaZSYiy3SLECS3TcLEpwFGY2I2fRZlQfuPkndC8SzL11EIVJMzP7yzrf 2QKRxP685Frr3Cr/uBJ5Tm+0bgfERsd4wQg3LDIQ8vhddzpUvp45SRLzZMtCTWnuVano uM4qTbQ0nD9zcWyvuQZF+Awmun7qg/ce5jL8cDcZkvCbVVAgX7y8T6MljGpcJlZXF6yy CGl8wtN2J7Prt1edIwn48QRip69sFjdd4mc44Jd5G/rwvkusfp+JOzUTFIM1/fAf9smv kw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3aq1kvgh84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:51 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHoAfG037930; Fri, 27 Aug 2021 17:53:50 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2045.outbound.protection.outlook.com [104.47.56.45]) by userp3030.oracle.com with ESMTP id 3ajpm53h62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6hERN834jyUGB8qgAO/6inxK6ApztSF/ht0nOCvgXU6dIthIvllgoIbbLfvNtmeAhxYlDYtOvdHfXLIEVuDDrIZXyLoqZQmuFNDKnJMcF3ERsgPk4eSNOnUkFHynuiiNCTUJzT+PosnjWKlW9qjY/hMSQrff8X/xTVUqY7A0sPg1oaHQZnstbaqrfsrDPiElSgpLg1tJH1L4EXSjuuwH4O7Xx1vedWMNmI3jZOCT1C+fwweS0Ji8tafDtgQPl+LrUOs0eXzn6X/cjahXdLEdWBXa/7WcVIdB8X1OKpn3CBebSPc+oNdwb2tpYE0SA8Gvq/Oa0+90zjbRep/EqD+jg== 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-SenderADCheck; bh=YNNOWu2x49LZfAvAzV43p2VgWHitn4HIrGGwz36Kir8=; b=lIXXWLqzSzYIv+wfOJDumjcPtZXvuQhARrY4uxrS+NpHM/060kipLfJaXQFzT+w3kv+5AIIRrpyuuk/YKuy09pA+7K9MW4S1HeVR8A1gTpvr/H6q5sQeznHiVK0IKA+MWbCslQfU9XzY1ADw24rykKCU7/G1ww8HEFYx4RwfKXOkrrQp3H3YCOKOMZSJWeorL9TNdMqeRTXUUimDkUvqFxROgoffxP+046+QFX9RHDddrOPdNXQm6x1qNwKMZoyWTfKERFXA2agH5UEBC6vgOp9Rm5SWrpnFANdaCIj1Fi7OlUw2ccUcfeUwqkMilKJzEr1doiW2aONmsb+o5+zQkA== 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=YNNOWu2x49LZfAvAzV43p2VgWHitn4HIrGGwz36Kir8=; b=n7xL8353pOus8gf2VcC9xx28QR/0nSgOe6t7/QJIdeeXKXZfrToPHeoJguF4+YcOnSIk6JnIRxG7Gf66qyJc+vQjatpJtKFrDAvQjUCyC+CiqOG0xG5SEcEO6tNpIo5GI32K8tkMnbqUwwrMsAupe6JOdPdmFggmR2WywHLSMEw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:48 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:48 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 03/11] vfio-user: instantiate vfio-user context Date: Fri, 27 Aug 2021 13:53:22 -0400 Message-Id: <4bf892091b1c08c79907ee2460f5f7aa797139af.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eea084f4-8045-401c-32eb-08d969839f20 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:57; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ICbuV/BjXPnprFaqI/loIjv2TOUORPd2JRaMr1ADSiLVPJqO9DNQxoGlBI74DJizPz45s9JdWGtw2BnvVz3LtAEytR30wJefJGZjUbmadzE11LTLSZwTaGvEp8qHOkHpZCYs8QpbpvSICuslIaUQjwAGfK+Z//PYcp9GRhlYu4e98BJK/HXC+nhiNqE8KJm8sEJM9YpXWI1QKO1353k809vjfrADIFwcN+n3zLnF5a6ass6M4UxeHbeUHypBoGDgUWH4ySBaQKnkHUo8AnL5supA1X8y/etdCLD5CVL7lnZj9cwklo0bl/ur5FVY+96ThgRs4OY1LvQ8myxjfVZXUCUx/PWlu+9lq8kUAy/TEa2FxHFN6+Jr5ivW5htmwsS+qzK9iPFItQDXRHlZKjR2NbGJGTkx3jI+oRfU94h7piSd3BvrCzKJF6lHd75sYWf53rtGg8VtNaQpNk3uA3jl+M+4fL6Nswz/MVefsq2s7/TZCtZtZlS6gZBBObf0EgxfavVsyn9maJO4SN+oV8sWK/1vEIoxG00IihArUxkY9WYN7WnZfZ/DweJcWZbaNIYno1nyO32qIxKu8BKVH68CthHtUWdAet6P5AnGejQyqsDXVoRv/V80utSptar4VFEoJgt0dcsf4dpMbciXNQilV9Q3npfXa6BsSt4T9UcVoIKwSNp5wcz8zGVUNPsDolN9tMF93wEVj2cSXnj5Bxe12g== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rWrG+vC2fqwuNCcCtX34l9tKl+EEDa2kV6JizPdstcquhjntDeSyfL7zz7xGpiALWzvU1ZkN2pPtoVC1uq8EzOhHUDl/ZYt0vDH1/EUWOQrsNr7F3wYP6YmdjXgGQvm3Dm/Wqh2dT08xhFivp0SbeSd0O4pcfyLmh5yH4sXzUoX6FavBjsQk1sq4otK5e/NcaH9HwaLhkq5UzhAHqSz4pQh7sGsPZ32LBuDmL1e0gKu9HaNJAbSJvx7mEMnaylV1Pt3N4bKPacd98BjipRfUF4PxhQ5EGFTl5vukpy4uM7vLDzY9Sdpu1D+Jue06+cpYvul6b2CRm6EN8ST6IDlnr2GjTNIB88YJw8AlUNodHDw4kGn1Ryr/yHCAw0q5T0MWAXXpNeKuG5Zrr6DjDP05w069XRffeFW3fqKGnsqDPoUMMR3kt4PI3QVr+Q/VO1nEC7+Q4/Yj0tPEsmvROouf8phHUW1zTV/2bqCGW3Um8QbBfFU852CQunT32k5DnOULKNsuz/V1XorvHYnLeWaoNyrmjet8fOh2mWDNx09aRX9kN8fuBbZi8lZRUYunhbbbp4+Iu4Z9eEBen2G4XD48WZ4IA+hJNX86LzZZ98KDlYLd9kCT2GNUNa5u3odIEkNvXENdrBZ/3HKvWEZjG4Any7zUIj9dmPH7CSp7er3/2qXKPf6lV/JD2APASTEnJSumwvwktiE7rm70Xv5HHzULDB3AXF24XchyJtVRAO5TNahniyS0wbHueOwQodA0FxhvDvol+PS4YRAuirUkN++9hdRJQQyaJY8IdSYYB7a4iTDonuZS3f6otF4Kp86TMP+uxsRA7XDAYpfZhCHwmSrFdSnTZG0RAYPi+9+dWT3xyGlauv86v9Y06VeB4eIKOWekCfAnp6Ew1DWBwJk8BOKohnrBEK2/Z9Kng1Zlbeb6EJaNu1Qk3GeTb7x1UI7ssIp17N8hGgehq7muozwCHzj8v75U1hkvFzIOMf7FbsZ5Tq+4Loq45Z1oznvK+eD6vzmtqTkU4Nmd6hz4dd3kboBkCmf7Rxp5ADIJooTA/MlI3KcSbjOd0B56BwrbA6/+rd9gblmGPceDGtyNcQ36zzAOssw8ZyJdSlOsRSuGtKnvxyNldP8YIUm6KCCFe3naVjbCq4FVXl36Zy5JH07omNpsG6wDjFJlJTIGBNbKVYYu+qD/OKUuicTwx6AVrfbXgHCNdB4zuSBWe/z94HIOpxFv3YaGAzkjbsnzdAnMFj8bR9z20vaUW0V7/WuC1yxKGu/YtmwTZZyH9DVSUW9if5lRRu+WBWQ3ZNLLEhtzU8WpgRv4e+0PHGxETbm6m+iM+1Su X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eea084f4-8045-401c-32eb-08d969839f20 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:48.4014 (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: wGPBhqESqMRMeYj5H/ahHqNWK/Unt5zp8sXh5Nqdlo2b0Xb+VRBUGhkf6dT7mLVRRClSZkOXMMwmtwxxeLJ16Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: yVBxvBxiW7_9AY6fWDY_HMovlBPE4B09 X-Proofpoint-ORIG-GUID: yVBxvBxiW7_9AY6fWDY_HMovlBPE4B09 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 4a1e297..99d3dd1 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -27,11 +27,17 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include + #include "qom/object.h" #include "qom/object_interfaces.h" #include "qemu/error-report.h" #include "trace.h" #include "sysemu/runstate.h" +#include "qemu/notify.h" +#include "qapi/error.h" +#include "sysemu/sysemu.h" +#include "libvfio-user.h" #define TYPE_VFU_OBJECT "vfio-user" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -51,6 +57,10 @@ struct VfuObject { char *socket; char *devid; + + Notifier machine_done; + + vfu_ctx_t *vfu_ctx; }; static void vfu_object_set_socket(Object *obj, const char *str, Error **errp) @@ -75,9 +85,23 @@ static void vfu_object_set_devid(Object *obj, const char *str, Error **errp) trace_vfu_prop("devid", str); } +static void vfu_object_machine_done(Notifier *notifier, void *data) +{ + VfuObject *o = container_of(notifier, VfuObject, machine_done); + + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket, 0, + o, VFU_DEV_TYPE_PCI); + if (o->vfu_ctx == NULL) { + error_setg(&error_abort, "vfu: Failed to create context - %s", + strerror(errno)); + return; + } +} + static void vfu_object_init(Object *obj) { VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { error_report("vfu: %s only compatible with %s machine", @@ -92,6 +116,9 @@ static void vfu_object_init(Object *obj) } k->nr_devs++; + + o->machine_done.notify = vfu_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); } static void vfu_object_finalize(Object *obj) @@ -101,6 +128,8 @@ static void vfu_object_finalize(Object *obj) k->nr_devs--; + vfu_destroy_ctx(o->vfu_ctx); + g_free(o->socket); g_free(o->devid); From patchwork Fri Aug 27 17:53:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CFBCC432BE for ; Fri, 27 Aug 2021 17:58:20 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B4AC560F4F for ; Fri, 27 Aug 2021 17:58:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B4AC560F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg7O-0004ee-Uh for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:58:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3D-0005BK-P9 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:59 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:19788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3B-0006qA-VF for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:53:59 -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 17RGR5BE002221; Fri, 27 Aug 2021 17:53:54 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 : mime-version; s=corp-2021-07-09; bh=MfOVfCVOLafY4PtHYcYBB8oe7ZN33hF0Ruqu/mr2QXk=; b=ag4hGKEaoj2QUwr/HWmOQ1eHLAqhi3E0MJctHmiWcgFxd/13RkDePutxJC8OAAXj/Chb zNULNMudQJuqk7b3cv1xjsDF5KkZjKN52jmCGtr85Kd80O7MGY2C2sSs/aCQ3rD5sIcG HftzEoHSEeUsJnDxtkrmNC2/hJm0xIzNJaBRgBn1mbIvQbHmT1ctiygxBYvTAo+Qz0ty Vz6OQq+EscOo19d1LDgCzm520loGNshMaeRzDdmHCqMYqwcgIw0JCHC1HOX9KL5O8tau 1atH7U7l4z83sqjRP7RPpo5YrliiQCL5DK0lV4Emo/UhjHr7EQozjX0FMvErWhgn4h0e nQ== 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 : mime-version; s=corp-2020-01-29; bh=MfOVfCVOLafY4PtHYcYBB8oe7ZN33hF0Ruqu/mr2QXk=; b=Z83SCErEW8vzHHOdkDD+nrBJ2VWAO6fvuSUb6DWP/HGzjWn2mA0PV+CK3YNjJ2rX1Pah Td4uUWHeRYKFWvbtHxGsIMWvYE2xA++xnUKHjg08AUz+T6dHTfYDD1g0axEiqJs73h9v vocF3tLQBhZ+/xfX8SA7liK8HrQpH5nmhVO3CLJtlTlNlFXy8ZFmUxGIBnTs94zRpkFN HqqdVUBaLBQen7b/2ey4oH5WodYIxOT8rA+aUzhysBZ0qfKS9KUvgjJlixvONgK15eQW ZSuH80rB5dJKLKkNOEn4LQ+YqUW7nZJ5NCUr7jgXiJHDRsoULJ2yPluWn2L0vzRzJ07X bw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr19fq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:54 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHplWr005510; Fri, 27 Aug 2021 17:53:53 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2048.outbound.protection.outlook.com [104.47.56.48]) by aserp3020.oracle.com with ESMTP id 3ajsabkbwm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cOt6h62+4WuP27UTSWumiCXdlYMxG4aXshdBk3R9kHbWcPtElMrMwRYVGghtQHVzU3Y9c4+cFGACWKUSSU18wZCcF/AyFpBV1iXGnIE6jUlpTczcIK72+AMfEBtK40VVoaT2ghWGDN8o57STuJugPWgA8oCVwaQ9+F/MGfmjHcNNDp+5smvYp4btaWPfl41M5xhiPesJELv4buVAGHSg+LFpJ4PW0yk+cJps6uMKYaD9ZV6zexMfl364xHVazWz0K6//sdzoZpURVdpBcermeXp7oP36RupTYKTdML6VQ3DktpLb7Q+x9ICu0xQg6REPgGjvA+PXLuCh/QEH0qky+w== 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-SenderADCheck; bh=MfOVfCVOLafY4PtHYcYBB8oe7ZN33hF0Ruqu/mr2QXk=; b=PZoParB37JM/UZpv9I7dG3UtfuADE9HyyGORrjiu1Unv5uZFHazLKyLxjgvPBfkX+blj8wYAELN74Slce4o6N+l8z3JDvpYUPEte1S+1aPnrBVoJSEygEwdPqHTRhSMKilPlHBboxoKGXqc4AlZHBmnS1zmW0d2Kx+JusmblM208mgGytOPMh8v5n06k6gl5tlOIQzzLjxsnoOongm99RGsk+AwLHGmnEwnYojJB7aNc6aJnC0Gx384G5TQoDA3Vc7I48y86b1lgVvw5fXAZ2Bvx/6IFrSpICffjiKZ0ZDqpwi7Foeyt8DaybvlWG2vjsEw8RnKHrbQ9wers4YTI3Q== 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=MfOVfCVOLafY4PtHYcYBB8oe7ZN33hF0Ruqu/mr2QXk=; b=lA/uEXEb1fWPEqpHZm950GYlwvnZSep+6w2ULPIsxBZCpD2N4HH23HhdOp+CaNXxh1s4gDdTRNSRNY4ZKJDzv+SXem4kONZbhDeqe5vCR1rcAD+PVf4afal4SW7zV/GZJRpJ9dLOZ9QyV9/G8BEtWbdPTNn7rfsCC8W3//oyE4Y= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:51 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:51 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 04/11] vfio-user: find and init PCI device Date: Fri, 27 Aug 2021 13:53:23 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4c96921-563c-46c7-8224-08d96983a0e5 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:248; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BbouMk5Yhi1a+W7t3JI75R1cXQqmUHBAvKfPOP5inzy+kl3EQGDgCo6ss0ZohF2rtheE8i7DQFMyPOFoGvd7mbRrqWX1NWHutn+usq84YBVExmXebPHcxiNpRCZQZ3HLJDQbF+9TUT8ADpbUNgIkGkPWai8uGiSP70F6qJCL9mm00+l30mvJ2+7AhkfTewdQa34Dp56byC+9581lIz8zvCoIvgVqa/vv/6GsrsRkM3TRi9mOpK2B2ZBowJGv03wd3TxjB3f2n0LcMhQmlI/D1O0uTaqHvGrE59m3iG7vYFEtMBn9DKWR3661SDPgGeOFTu0mWEdSDXru9KHXIXLiBR/PgG87onxxsj4EMJllpGZH0oQvLZ8mQtmzoP7RNmNDlEc6J3HBG3JbaXfLWcl4Td9QPRgtAO49cMntJq+TTYUEt2MfaTEU400301f9DmHj9K10Ii9zdPDbSv/BjK3pYHwX9NDxhxZ5Blmd2iEU4hXMUWZELZIlRnqojESfsrxa+V5cBZ04zG7OaN+vWHNwFehxKTG+BIW1jShDgmE9yh9QXyVyn2rL8NEocm6Sb768/8FJpx4UxJAdk7KLzWxKELfdUWglbx+iuabeJ0VUpEIVt5+HhuPcBaG1in1/CDjxd0FrqzJY6O4x+FRKk10Xbjdpc94xoYRpBcAx5SgqwY1eKc6gpTZBlWzc7zrjIIyrFGYYXQp8mJR8YfguMZ3a1Q== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bkHbiH+ThENGmM2CTSGiJOzI7mkmHwp8mWvcMyHZZl99YAZHbF/tt4NWOLsXfZOqCB9yQzrDMXEXBquVKoTfUEVr/jHCwS4ImR00wkTVEt5Ff3yFN/TyIDk5QHJGIMAJC2COuJX3YuYI8djcJkGzaJv3aoebFg7xnNBYWW3rq8kpMBBKg/13mdMzFKZlXiVs2Du516Q81XBo0N2YviERxZ8WaGiqkAyiiwdI9Rzoku9f2+JnvaTzVvJ/thaJ2zyiAkh5ZE52l7qLENCF3DCrpp+6suBRzrduNIxQpR5sdIJ7ZIHI3tfdbTuYRXbYTRvwS8YM5/rctxtw2AlYHcCqYBBAFXoEwRUX9CMQ0ii29gXWTD7lXo70MI5dHwPvr6zf9AS1HDeenOr8Qxr5YgIERI4F0F6t+HXSyIEeWhs3SiuotOX6aMUTzJQJ6y8nagXYIhk0SkMKrG+8wo8rRIUP3Dl7yUFerJFjnAcNNYrv5JuPsZ1PaIaUy3r5UHH4fuNtbUIviZQChtB/Pi1uQcWInHbyvQbU9RIwwNTOJpYVc4fnJ4j4WE/aA9zo9X3S8yBhgoDjzipfSFTaT01u9dffk3+TzvzuDKmoN8Dylf/G/NmYOuZcJo8J/o/FVJJborAE+oq4VHhfr47nYUWWjytBMcQVGh6Uv+umoMEUEY1ybkMWH/WPwrtfDiZWQD42O3vZLBJC1Ba4y3l8LwVK0frB7YWn/E94zW/iPDsPBKySeGAarbSS3fKW4l4Mxy34rsbUu+8ygYxexP/Eq70Vs/8gvgsRg51GgJPbsRrvBjs60TIfYaFMB2uH2Zseak6WGZynV6tXJjfmy/VUsSrt/cdHjlsr7XOO0/mTC8b68BzWs02l+uU5y7YCM8R78eVPtZBNdPSNkY9eM4Qt8GLS2ACTwa11JXMlycCJyNWt2f+R8TseeW8YDMPR50vNXqab84xhNoAYQlSNstpEopKdK1eS4OdoI3gE2ccSev4xocq80fcjwYCA5ZKPVCgUpa/Vnw9r4pgYCyKKrE4crXuMSJuLtuw/d55wFzgm0pTyXDKNvCLOdsFS/dJmJt3deIpHK6OjtqOK5DaqkYj8kErrCScgbnij8m3jLaQjdHSXN96EiAM7CkXdc6ZAm/GbmcrJ2X2oM3xlG3BHUAseiS3WRlj7MU56Zf/FP/1uxwiPFdoI+fAYn5dWfCcwKqXMHrvA/kG9eCw3T1zlYvKvtnJr+GbwnV6Z1JApVtWU+f0hCQn/QpiW44BTzR1nfa2UKtXLFrCF7aUBF8JRkq7ZbPZI2gyqpOVHXnZQ7uZV11IJJVzkZdGF1lVuV8JxAOMLMCeAWSy+ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4c96921-563c-46c7-8224-08d96983a0e5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:51.2952 (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: IdLFapZuBVEI4XY1utk1IUDaFih8HccH5HZo8e/VFCRfeC/CV3rajcCkxf3OqURqEEXsHNMmy2QIPLP5DlAtKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: dEEBpvdE-VzI1-1nIIRNMdR3hJFAt-Lt X-Proofpoint-ORIG-GUID: dEEBpvdE-VzI1-1nIIRNMdR3hJFAt-Lt 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 --- hw/remote/vfio-user-obj.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 99d3dd1..5ae0991 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -38,6 +38,8 @@ #include "qapi/error.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" +#include "hw/qdev-core.h" +#include "hw/pci/pci.h" #define TYPE_VFU_OBJECT "vfio-user" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -61,6 +63,8 @@ struct VfuObject { Notifier machine_done; vfu_ctx_t *vfu_ctx; + + PCIDevice *pci_dev; }; static void vfu_object_set_socket(Object *obj, const char *str, Error **errp) @@ -88,6 +92,8 @@ static void vfu_object_set_devid(Object *obj, const char *str, Error **errp) static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); + DeviceState *dev = NULL; + int ret; o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket, 0, o, VFU_DEV_TYPE_PCI); @@ -96,6 +102,28 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) strerror(errno)); return; } + + dev = qdev_find_recursive(sysbus_get_default(), o->devid); + if (dev == NULL) { + error_setg(&error_abort, "vfu: Device %s not found", o->devid); + return; + } + + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(&error_abort, "vfu: %s not a PCI devices", o->devid); + return; + } + + o->pci_dev = PCI_DEVICE(dev); + + ret = vfu_pci_init(o->vfu_ctx, VFU_PCI_TYPE_CONVENTIONAL, + PCI_HEADER_TYPE_NORMAL, 0); + if (ret < 0) { + error_setg(&error_abort, + "vfu: Failed to attach PCI device %s to context - %s", + o->devid, strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) From patchwork Fri Aug 27 17:53:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24EA5C4320A for ; Fri, 27 Aug 2021 18:01:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7F82960F35 for ; Fri, 27 Aug 2021 18:01:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7F82960F35 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:51130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg9z-000079-MF for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 14:00:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3G-0005Na-SL for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:02 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:25196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3E-0006sL-Sx for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:02 -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 17RH9dZB025438; Fri, 27 Aug 2021 17:53:57 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 : mime-version; s=corp-2021-07-09; bh=vkI9doTy+j7/2OfL6gp+DWi7Z/gg+WTLjNM7brzCH/g=; b=CN+sjEphxkKmUorEdO7VIr9oOlL31wKGgRyyfu0RL0YUN6xorJAHI4UKN770vJVDEE+r cTmM+RZebv/zqwwFy217fILmtBrY2Es1Ey6Fx+MYdw2LKsXEgOiZiPwhWKiPC28OfVqZ 7URz/bYAxPMsmoSXhOTo9yFJd+kMjb2otFkD1zX3kHP0x9hTGDdTu9Oh4CjsTM77cil7 gB9Hpwuq1MUDm8JyyPX8a3LLm6gUjkn2BH3HmWfCyEclbi6zxh10Sc3By/sT9KyRBYLs HRYJeFh/JQKBikxiuQXF2oJ9zv6O6kAQO+vElJRO5GueGQidvWcT05AoGkfV3ElhDHot gw== 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 : mime-version; s=corp-2020-01-29; bh=vkI9doTy+j7/2OfL6gp+DWi7Z/gg+WTLjNM7brzCH/g=; b=cPTVaMYdFmFaszcNRjeyzXiCF41halSibTYcJBbL8Dzi8tIB2cGwSMIPbjvvQfK/Zd9W MXn/u/uRyMq5NNzR0wgePPbYLWjBvGXpVcQacL4NjbRC5v3lrtpsiW6J54PjxtKwA8lP 8IWc7cNUACOe34KGstOyVy0ypi5SMHfueHxPnkoPxhDlZLXgv5OZ6rOkJtz2KN83f4F7 8RRqyJDuIuBPrMpVDqsgj17i9UAZnz2Ycoy6UgRyBRWkghO3WiBFRSvp4+BIU/M9USiK FO3qP9JJ0cJ79UbJNMu5A4kKGTfNECA4HCYGpJYjB7hFyamunpItdqUQw1SQKAOMVMXP iw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3aq1kvgh8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:57 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHpksH005402; Fri, 27 Aug 2021 17:53:56 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by aserp3020.oracle.com with ESMTP id 3ajsabkbyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MIP7odLgeHWvFgo+aJlsSs59CkkL8i4T6Rmw+sydiISsQ7F35m/SO+rXbOUfVCufPZsVsAHPijK1FErPeNo2JCzdPFcsC3FAbkICI44rzo9HvsARapxAtGamUD0ZmuNhuPGQC7OFD3V2w6pSmduch21LGvqaZKLhlEMTPs1xQ1b0GqlMZPVSXH3qCKLX79aqlB28adBh9NLglw6wWVQZ/L4R3LPwD8ncGVmhex8OggdS2dZJ7UR4t7gr/JMoRCMvRjTlb1YSOoTeIgIusPUn7aI5DSOPlhQ5fk+rerk5wrAdzO+BWgFvoeuaFa6BQJhu5qQyYqI1wO4BQjVXO6RSGA== 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-SenderADCheck; bh=vkI9doTy+j7/2OfL6gp+DWi7Z/gg+WTLjNM7brzCH/g=; b=DcvSR4mdrTn/yAA+qfxNZ6LbcYbsbb6rNL5rQjC/qHZSvG5rU8Nlrcwa7A3Ho5lI790g7su2dT55vM0dhp9fxbnV5X31nVK5gMcs7pFkuOs7tFfzLjn7eTk/vCynSBn1W7ihecFxj/kAoc2YYbS4D2+wHkRlGndTH68zn1V6aPa+QaD+D8P0Pi355scLxCb2VqgbMln3XhFNiygckkZBn1uVTwI11JCRofyLN/HChxGGR9RAwd8HdtsU2v02QuCAo/FGaKR0NP2XnQ+loFaTBiijd2E9h3k0hKsHvVlnIdHJZ6s/Io+wJ2jxvJVN2I4C6RxUhmd6n2KVNY0/wG/67Q== 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=vkI9doTy+j7/2OfL6gp+DWi7Z/gg+WTLjNM7brzCH/g=; b=rqlcglIhG8MFkGqaWJRCIHLGjQOiVvQejp4FCdh93XOwuyOuBhS5C0g5syw4J3SFi+6zaGJJzVEbJeoAPaCG6CkeExXRZkHxBWXwd/MtY/Ng7CYjd5zT9Idkf1Rzv9wTmTo0PLnQukszCRuxYfzcTfFGpY+S2g7PyQzLwFuRbXw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:54 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:54 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 05/11] vfio-user: run vfio-user context Date: Fri, 27 Aug 2021 13:53:24 -0400 Message-Id: <3c043becf2b6e820f5392e0cadb465d5d9b9e6f8.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3ea69878-ae3f-466c-72eb-08d96983a27c X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QP8qXtnfDWHrKq8iDVbeYSO4tvI/X+PLvRuzkSI1EsP0hiE8ojTCmUdbB/RCqP3ZTO/ElI3cqDJyJmpRRZcTr4MsBJtCPUA99ZxqJLalVD+z3pBL8GqGe08XdTOAYQMBaMusxrBq1MD254Bwfaapd9ZYY84SPTyeaGiyNelgXI3LVHIZzD/7U76wRhpbRk8X/JoXEHwZC/4ZMLME7DVDZW0f7WMuBrAFMtq5GMKoUTY1E4DqGPhiMUwisdlN45WQm60NcVQZjoghaYAGApgMTIYnytQg8NmZLAwEXoGdwDJ5HFc3lvmagGGRq3x+I7Z4KeA1LM60jWFa1kG5yyMHS1aCIjf5WYlslDwcku5UyoM2avuPvTx45qQy6Vy7sf5BRw19ukRUDf1eeCFgBgqnCipDBp1iOH3LeMySiGRs0dnEIG3FnhPplwOIRsZ4xQj/Z9HBy/jq23dh9gj3BabRug4Fp09lip7cvOcpNofCpav/z4DZvdhLpP4Px7KW597HoZGp0yljiB1CJHu/2WZd+LFLBEqok/RwtQFUpIMdLt8V8q6cF09fdkLknuvrTx2U1QEQ6gDngIrKIOPPdnoqHTUdPapfTLc4uPQ+PNtyGvbERvTkRtUKUrg57GYUKU+Lp15xMX7eqAqYfhlo4FthHl1gxdCCM9BCaXbDSGnmMULaQS4iNuYP4pPMZ6kUv85MtR7B/2EeLykGRmDunPIO6Q== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HpMmg2En9r52p7N0OFGLeOAehYZqUtzQZ6LGiJpxRjYE+U190JpSpc5EigbsbHmE9IdTS7LPW+BW+6ux3Jlk9+jDFe5Vj/gNE1+CLp9v30qKRlaoW8zG44Hznwx2D9ZKcoBkTeqU8eGQ7QmmLfNOFh5hmIkAbzEVlKr8HCVwb9ukEZAXQekR1kgfQkBVuw5cDbS6w5Fb5j5+GvFkvW2Q6MyvSrJIvDTpF+T+ssEUfcsB7fCgUnFKVX5zJeORz4h5MKuO04Vj6ZMBKjgEG0o5PRGg9dF4ol3ONIlmkPrEDLcGMDumt5lRuPSwMpQIgB+isSQowEt/34YagxJ7pMJp7vHe3OZjuu0kqq1d30afN1N8vV0YABTbZk6A2FpGnqZhkGQ6rOOHbZJUh3b7pGAWclVgAxYAwjB9gSeI5NMbc+YnRFQY9jYsPcZTMjL5vFZfKpzaZzzqY0NfV7GJ0XryKDfMV7buib3XIl7ARISvSvNEiSlsX4ZGVHcDhkTnMyArwr+ZfkwR5EXUC17VhB7Pd8n3y6J2O8bD2xfyWsrWPmIZJ+UhFSZcg7OqR2Kd8TN4fdQwRL2O1c0+Rb+rDSGgdDHEyVlWMsmhEDB37Ifn6Ry/htPJBsYYZIUPyoEr0ACrXRRXV2N08yB0I4w3l6S4syG+IXoiqQ9dYvoTMe9Z0IeMDmzx4i1H+689aZxEgj7ZeSL0L3Gfctx2ngR1TAr/YM4jcArN+sRJIaQWFW4GprKwHBNUbHh0YFFfZpduqF+tw0XR7kCCogE+8v1oL/utINsn/Gy/gRRUzR6B+wopSZfVjggG5BMvaeAd4DT3JTpofZvijTEVtlAiTTiNUoGIkQV56+DY0RUwPjLiMa475r9Lvyk91v293VPBAG+Q4IQxGKn0y/oO9vO+Vvw3+AbsPII74Ce20Cd2LGZM6jJB3yxlS+gl3TjA4mT1Uk6mOimSLYdAVcJOgP9uLHDW/wmsMx7/byMqto2aZelUeuWB2SQK0PY+qyNCNxuHdQglEvaYhZI3VxH9bnZ50uyFKwkLqjdU5A5PX8c1I9AchAkYB+tQ02Qb+Q0Lqb8qB22YmAiJyqSE9zrI/pIh/SxvMV41hglFis5RDDjKva3YpiyeFM6Dy0aeO5eTe8Rn1klz8mJtaV2t0PebonlFBB9ffsIlg3J29wt9/j44xCCuqkmpjPtwtYm55hGVToYQyECyMdXN7E6RbH0IQ46HVSsY6mmO6BWqm8TonXGUkqeLMwCYzRgW3gJpS2NOoW33hd0pLX9818PMSJivOqJ5Zq6NwgPSOlmd0WEqXyraVfL/DXBkcJjpV4BWzOfUswiShxYtSnWs X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ea69878-ae3f-466c-72eb-08d96983a27c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:53.9652 (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: VCqdodF03cersX/LtogT02rk0/wZVJ0iageu0anWgYIMOe0YR7rad/LEUXmN/RPOCiQwyK+6H5262Z6szL55DQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: cmx-CZots4pp1nyVP75BdyCVCy1sLTKh X-Proofpoint-ORIG-GUID: cmx-CZots4pp1nyVP75BdyCVCy1sLTKh 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 --- hw/remote/vfio-user-obj.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 5ae0991..0726eb9 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -35,6 +35,7 @@ #include "trace.h" #include "sysemu/runstate.h" #include "qemu/notify.h" +#include "qemu/thread.h" #include "qapi/error.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" @@ -65,6 +66,8 @@ struct VfuObject { vfu_ctx_t *vfu_ctx; PCIDevice *pci_dev; + + int vfu_poll_fd; }; static void vfu_object_set_socket(Object *obj, const char *str, Error **errp) @@ -89,13 +92,67 @@ static void vfu_object_set_devid(Object *obj, const char *str, Error **errp) trace_vfu_prop("devid", str); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + break; + } else { + error_setg(&error_abort, "vfu: Failed to run device %s - %s", + o->devid, strerror(errno)); + break; + } + } + } +} + +static void *vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + int ret; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + goto retry_attach; + } else if (ret < 0) { + error_setg(&error_abort, + "vfu: Failed to attach device %s to context - %s", + o->devid, strerror(errno)); + return NULL; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(&error_abort, "vfu: Failed to get poll fd %s", o->devid); + return NULL; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, + NULL, o); + + return NULL; +} + static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); DeviceState *dev = NULL; + QemuThread thread; int ret; - o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket, 0, + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket, + LIBVFIO_USER_FLAG_ATTACH_NB, o, VFU_DEV_TYPE_PCI); if (o->vfu_ctx == NULL) { error_setg(&error_abort, "vfu: Failed to create context - %s", @@ -124,6 +181,16 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) o->devid, strerror(errno)); return; } + + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to realize device %s- %s", + o->devid, strerror(errno)); + return; + } + + qemu_thread_create(&thread, o->socket, vfu_object_attach_ctx, o, + QEMU_THREAD_DETACHED); } static void vfu_object_init(Object *obj) @@ -147,6 +214,8 @@ static void vfu_object_init(Object *obj) o->machine_done.notify = vfu_object_machine_done; qemu_add_machine_init_done_notifier(&o->machine_done); + + o->vfu_poll_fd = -1; } static void vfu_object_finalize(Object *obj) From patchwork Fri Aug 27 17:53:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77283C432BE for ; Fri, 27 Aug 2021 18:03:56 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D742560F92 for ; Fri, 27 Aug 2021 18:03:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D742560F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:55750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJgCp-0003Sa-0k for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 14:03:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3M-0005d5-Np for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:08 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3J-0006vc-B5 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:08 -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 17RH9dZJ025438; Fri, 27 Aug 2021 17:54:02 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 : mime-version; s=corp-2021-07-09; bh=KisP+5WTiznmLb6i3eK76RZlqh4SbpCBxf1ru1SblEQ=; b=ZfL1SwHSmfFe1oOj+6LBY5oL3zWK0CxKHgoqC+CpXjnqqS24CvbsODnqHYqhvnj9CQVN QiV5PJo2FUYLpIE39CvOohSr5UjDt6gJ4ci9mxnmwLDV3b3IoUEy3iDEQIvhh8MR5QMl S82ihXsYtGLMPKlDn74MuE7ECFj4ivhkaelB48ULKqkmZPn1UfABVFREurpskIFSM1h7 /JRVhknj3qg9+mgrlMCP1KI8O6hMjmYa7btAh5cqRCNNSwdoEZht8JcD+ttvHz4fbmEL xQJgzkW7C4sryJK4/ET+E45L0YozdgsNkQlWqAtu4q6CLQtDOVTd4TTTEu79o5S/cyLm Qw== 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 : mime-version; s=corp-2020-01-29; bh=KisP+5WTiznmLb6i3eK76RZlqh4SbpCBxf1ru1SblEQ=; b=mDr9hC7hPaXUNhKCe5/8PDVbpn9jyCOPxMou09bPa+dWcLiljtpHCH61tZCUL6fEuTd2 zGg7YbX5Apz+IaakscHX4GFsY6wq7KrAM8Fm4jB1rZ8okZxZtBpEuZfGuKaNcQp517n1 u5+lHYptwaFxp8Xv6rFa8en1KqghZ0S47dsu4FEEaDze0yZniHDF9N86oeyaseHnFcd5 3EEICKfEeW4AeXgUsdPPsBHQIlw6fyVPXOmtJZFdfxCt+Xc27Rpi92y5yoYGtxdiXoiW 4mULaUl2Wv2cDUNQO829igAw/7ZbCcZAMRDripUlk5W7hMdlCCTLuiA40TqeLBp21iuZ pw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3aq1kvgh9a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:01 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHnuc2179067; Fri, 27 Aug 2021 17:53:59 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by userp3020.oracle.com with ESMTP id 3akb92hj7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:53:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNvvC6uj5SONTxVnf15W2mcHCKZc5Z0h3tdN1Cb/1O99/fI+PDpTI8dwo6OsPN19VOllsBZM/mSfmdSW5v0QdcM2Hj8Y6XTeUe2mPZeIajew0F0swcDwv2A5TV5NOoOUh0Zt/iPeDdPbqOpGkOzW48QHMdRV3x6cRgzkf4XMT5MvSKwkSxk6hpG0mXGqq5hKw6BydtueYkQ7gruGoeXZPoiP68fvgmXCnDlIfBLvUX7rtWy/Xeb7uDQdRNftL4ICAfy6y63qdGBgOw60Ru7GTQGr6MVOLbEr+u+oAZfbvxyxWBRRHeDL3XLeLF9AT0asRS7NnzVkI5gFljyUGz07hA== 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-SenderADCheck; bh=KisP+5WTiznmLb6i3eK76RZlqh4SbpCBxf1ru1SblEQ=; b=dC4f2gGK26u5IZnx0HxITmiP3hW+lTXuK0jF8jATJFMvINYaAgHYAOvbD0JA0CwceSjJtB+aaPeoiUp9D65CXsxHKLfuCrjGSs3fB5FZU48leLchFLSYTJgh3UAmv2Kqwju2NqCoz5JmHIdAcjzAsuZnEPuBPmpvLT2xFCBX9CZrj13UzXrpFpyBtqk08j1X59G/q2uZha+feuuGuobTf6NH13fJi+iV3AhrvFC8gIKa22FOhZBSC2uobSR8cR0ce9kt7sxxvj5Wc/Qpwuum0JHOagOzC15RBbU09Ym2+04kqHQAYOtFVS0NLSddcX/Uj5jJdtzem90d11c3oNfH+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KisP+5WTiznmLb6i3eK76RZlqh4SbpCBxf1ru1SblEQ=; b=Q9vIJdaZfsZcts4YqpXzwA+H7i/VIfRlPaU+AoFSKaqYTiBdNfpH7vI3wUvpjbYHQPpQjqTa5ROSZhjGqT0noXmDNe16fPVJPjg80gJIAzBUOHX7Z1jRrmAUECGiMNQy5MgTn2qQovuhoCaFnflm8k1CuDYKo8XXqdaNS58dKi4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:56 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:56 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 06/11] vfio-user: handle PCI config space accesses Date: Fri, 27 Aug 2021 13:53:25 -0400 Message-Id: <5f371fa15eb347317ce9ce56a329a24c713129e0.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8376b326-fb01-4a92-d458-08d96983a415 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:91; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zIA6qHs3EKr8qb3CASQSvazISzoO8gNodpu0j9bXqEvSFLzYedmZDxpa25TjqlcggiNYpzGBdOfRt1xj6lljUYKKyYBxS5DzPRkSJmwq+LcnFwZSm5bZdvFtA+scHJuWa/ZotQr/Q+izCAOSe6DJnjOYrpjfrFFsuD+NSEqoj0C+pj7v7HpAgvNiP+I2/X5sABolQSPx7OXH6eXhYZ+ox3kvNTKCRLUTaPDw2RBYqGLx4E6YKkPtVdyo4hk9v66JS+szwO9AOPNtEsZJfW2Ebcyc6Z6aOHw2+1OA6jhup+NtDBvfdBx32fkY8H1OmjNYGFXgX3I9FR/yFsFa5c13otQYxWtkq3aXUYKcTmI19fdIaXgn53l/935GUE5eM7ei87B4j+xgknxTD4GbDnawWllzOm77emttQX1TnOfTTbIN2FoDjMS1zhICZB6E/CVMM7u0FXGt/qMBpFujUEiRg2gnraLU7mBZwxGs6uOvHJNL44Ch4MF670wJ+kOzfBP7oO854jVebFP+oYeqXMOpKIL1ZbJkbgPrY+dvPz4C6IKgPPYntUTWV5+KUjI8XlviSMO3w8exneAiUT3FDEy567fdjpAOMcKJAIbkoUUIQhfwAtcQKq/f9ri335exN8RlonY64Ee/k63/8MisNEdDsh8vvchJHplqlGLHH77vw5wdhxVdFiM9Sy0ihQmXKUe2Wc0ZDiNJoyOEbhN6oPkERQ== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i8ofpC2hInUu6WrYAXGdK73tNaxAg8IzdWc3suvGOzuBgAMqpemejPD8Hv9wzmzuN+5f6fqJBBpMXDV0RwwsPv7ZNbx9eymDRZQfD/pBaYYGR12mg5QrPbDtJ/UGdXIr44dPCXvqzs5JmCiz8zgv0Sj7p1OtoF49J6fhFw3JDEcKV1yLGlx5M561XkF97qL5/tSyGjqjAz8xR16WkfyK9dmeps44jLWWO55XhB2Kg+uR83KYdvHRpP+vkEOhBCdSRqb/3o4LyXMONJr2amFT051OIMk7iFfuKFyOMmDnn9tmqJWiPXT7VBCucAT+UuaDz194jP4zXTCvxb4DukArKrfw4AQFX+v2l8IZGf96h+3ZEbUh9HlH9Rw0+JwQ5xOh/k1eEn6z6zJJ6RLse9e6SMIgjuJMVmuTSnH4pVZCSrTCPf4y2xwrPfW0kGW85wrw9hpuMiE205XyZIsdCZ2Ix8lHctsdn1Z46Rb66wtsRyL5wgnE8J3QOeoQOMAVDZtgZyo6YqVqA+MO46w3G0MeAausxbw5O9UeUpVeOOGBea04s9qKzdPl5HGWvVFhYaxQHIU+BMOJO5KUyxOZ9dg76n8JUFvk1zs5IyiCM5ToCm3xZ6JyAWaOnw58Tzn4ZfljyoZAQG/JFzVYfInCMPA3ZyHdTCIyogAtiUsUIrHeAd8u0b2MdnqEQ14vKBSYWMxJM8ABAoAidqPkNqNXoYW+RB0A7prpZex3kxa6DFovxzpgQM4qiLHDik99po27d/nNMtXrvhQ2OUJiW8KNbvssaJ8irNVXYyEg/ROYv8RLUcOCsuxfUjVWNegN9KVdr5AZfHpEFf3ZGEqRKd1IMCyRK99EcROqIws0YjgKbQ4l8RApziIijF663zNGrF/lSIzp1KiKhRPPRKDMvNSYPpGkX6wscFMevir/LvCe9e7q62BpXEdcKqgkvEYzVoxyebCUzvk/lrNaxsigZQAXZJOjxyIr0Z14O0qoxivMILX3Q0ZovOXXClYM7sg6bjWGNCHvy+CZ3X+j4Tq9C6lmjZlv4tKDIPTadQ3b1LjiUCFzKENFCq99Y/78JQO+ZiG8R0XqC1/FUCYW/LGQ+w6Xz+f6Gc367wfjunDQm7dw9UfE/3csp9h6ZDoeEPcW/sKSPwQNPOlimrvy3sega/JLCnde4Le49OZwtCAJl8APqH4OU17p6a+RdO8lZUMXMUxh48GnA3AtaNYsJ21FozLsJVGstM/dnE/K8s/1BfzEgj7Su5U5l2kr4MTbaRubS9yn+SlGU7Pg1bOY/syE8nBF3XBS7M2qmusKG0PwgUk94x6PtxBadjgqyipGa7c4Ck/wBy5Z X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8376b326-fb01-4a92-d458-08d96983a415 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:56.6201 (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: 1842XpMvWtRNjcIBzCaSkA6Ckkxn/gcr8GBHupnxmKEwkwcqV2jrsnzl/zHk7dSOjCyj3rPTDXPLMP2OaSjTrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: tunsE8dv9RUDcb8K8cbOUk8QXcToIDqp X-Proofpoint-ORIG-GUID: tunsE8dv9RUDcb8K8cbOUk8QXcToIDqp 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 --- hw/remote/vfio-user-obj.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 46 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 0726eb9..13011ce 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -36,6 +36,7 @@ #include "sysemu/runstate.h" #include "qemu/notify.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" #include "qapi/error.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" @@ -144,6 +145,38 @@ retry_attach: return NULL; } +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; + + while (bytes > 0) { + len = (bytes > pci_access_width) ? pci_access_width : bytes; + if (is_write) { + memcpy(&val, ptr, len); + pci_default_write_config(PCI_DEVICE(o->pci_dev), + offset, val, len); + trace_vfu_cfg_write(offset, val); + } else { + val = pci_default_read_config(PCI_DEVICE(o->pci_dev), + offset, len); + memcpy(ptr, &val, len); + trace_vfu_cfg_read(offset, val); + } + offset += len; + ptr += len; + bytes -= len; + } + + return count; +} + static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); @@ -182,6 +215,17 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + 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(&error_abort, + "vfu: Failed to setup config space handlers for %s- %s", + o->devid, strerror(errno)); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0..2ef7884 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" From patchwork Fri Aug 27 17:53:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE682C432BE for ; Fri, 27 Aug 2021 17:58:23 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 775BA60F58 for ; Fri, 27 Aug 2021 17:58:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 775BA60F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg7S-0004oj-En for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:58:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3L-0005Zl-JN for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:07 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3J-0006ve-Jk for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:07 -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 17RGOv6K002206; Fri, 27 Aug 2021 17:54:02 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 : mime-version; s=corp-2021-07-09; bh=mIBZZ+JBC/6kuNITpParbi6V7GjyEop1/dB8wZM86w4=; b=XzSERacrEI3tcyM7WppHWgO6StzpxsNkkKNicMYbdIn83P3OkVI8EMgN0b3re6NBfhAK QGSS2jjYEf1UpjYpQAuWO4BwwtTiepbOx2VabbE8apQwBZEaXJha1nW5eUDa3MWsj/K1 Qi7IpToR+3A3cieRLtyefsoeEtAMykYnHAmut3X/KK/FU2IaSQtrz/rByo7dH3scObf3 cZscjgUT/c0gzzMfSGhZyCXIVV1PsXYAP1Dl5/Zz+v5xB2dN+9EV/ilAPMp80I6kO8Pn 34xhYwGrq783mhwv9co+hvdyNh98rEUaWGfATpoiEAPE2gLjXliQry3N/0XB0bAr6rl7 wQ== 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 : mime-version; s=corp-2020-01-29; bh=mIBZZ+JBC/6kuNITpParbi6V7GjyEop1/dB8wZM86w4=; b=DxX7FwEfAOubRU+X26eevxRSzCcpQKyJ+j9PiDK8O+OSJP5V/RC6/l4P1fKPIur3pb6f yDQ1wTtz+9zXhKwVFxsM9d86DQ36Faa9ZAz4dyLF/hy62y6ktJhzGulIqdaYaWWpaMIN ncCiWxO/oetQ/hYmT0yD/Dc1QRMkyvI8cypKtGuDZigWJZeF4cea+YwNSA8zpqR1DbSQ 89a31b7Nc31JhMrNH/GAUrzHioemHH1PQkgIKulpyF4xzbB5XBv3JAbrSGMlrpSEXA+A AjtnIwa2xnT7kGYq2N/Cb4Ep8t9ae0Uvd3BSG7JIQbgamFryPT4l8jgMOjRypKuqsABL dQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr19gp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHnuc4179067; Fri, 27 Aug 2021 17:54:00 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by userp3020.oracle.com with ESMTP id 3akb92hj7q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gvb2Rvu5CNoUeP3AG/fYL5f6GblZUOxmpoZ2KF5ccXb/Q6yxFZEXKEJeU+xLqJCq8qxyUkT+Y5Lw1P0+fT9O8o12boAyJj85njUpH71Hg8zIeNXGLO03dfbf6XE90kphkFFWQFfxsFvjl697YdfM0Cql9kb2RLGfZS65GY+Jlss6AhPz6s6dbqCnD1HER+fzHkwdKYWdzFBBSie+sWExcZ+ET9zx2ehJv0M1pS0GcXf4pvEx4BxnAIA2CwQkq4Tr7dacFGgZqv5h8QZ6MsWfTPS04DyiXuTX2rfRrPULD1i+yKg00+v6VZWhwUHJCeGZu3vfKDQzDZuvANslgls9Ag== 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-SenderADCheck; bh=mIBZZ+JBC/6kuNITpParbi6V7GjyEop1/dB8wZM86w4=; b=MYtWpV0uI1arv9BXkDgLQ0j0T3zMoBaeIzjA2job8byWemKU+34dGJhwaQfxFW4JMKGgw1KWMFET3buJ3o61WwYIbnunxbmRBuMZhP7vGvIHX66WyeVyrzahsc6R4ULq8V9vRzFQmNu/C3LF9HwBaMKBThJgEXwAgnWJvgcqzp6z+dUMAiOcIb74/iydcD6DPj+qXYiKEyFGy+1DZNw40z1RYMzbiNSMX0TW2O8EptrhtvmBv8I2RkZA78wR62Fj6zWB+ose+U0TCmsQCCuvlU/Am4HAk8NpwgzbQ/ZEYHtnTo4k2NZiNaD2z9TIXIMNDiYs56FhvOx5pnQQgrIgBQ== 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=mIBZZ+JBC/6kuNITpParbi6V7GjyEop1/dB8wZM86w4=; b=0G4c6CLfLkqU9J24tDzzF31JmLNvDGTjjA/7KrK+qbCGRh//uIvZfF6sUtRBkAmYaj8o6zAM/tt9AIdbbApaUc1N16L8Kia1B+RtXY70k1QXgebqsiwtoGrzBQwH6Ya/fWAw1hiwO/zkP4xLoGf1NT1TiUfzb8SintS1EUt0on0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:53:59 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:53:59 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 07/11] vfio-user: handle DMA mappings Date: Fri, 27 Aug 2021 13:53:26 -0400 Message-Id: <9fe8660c83c290e8985add3bd7e6a1e57631891f.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da957e4f-225d-480f-7691-08d96983a5ac X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:339; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aLzl79Az4Ra/oIKWHvP7pN/5QL/CvkP0dqnomqmabUJUN/I9vTiG+i7oSx+Ryq7FKcqb1jUR3Mj1C487kZByDthKcQFrP+3WDpMFSHuh2U2gi8pVEMPdLw/RXVqr7sMfckEutC7gtJYIA1lRClWj1exBnIV7BffL5lc6KJxDcBFbBV2fKoCIA9zSiwyDZSbfdarpHgprHdxEmOZmVuMkJYRlVmayLp6/uAAnPR7A8fA+Ey0mJw8ivgbiIT8/h1QZg2Qay+pSnP6676M8qwrjV4mNJMKy8QVAxAN5V7A8MvIgipjMt1nxdaTUPzmRvrtseun/M76G7f0Rwme/5Q4eGfPvIDxIwz/C2s+PWZMPzrwy4o5TmUPQ592W5L8tfd+SWFZK5aP8N7KJplvwCiwVPPNDHadbjNNCHOh7zWmClgnRkxw+Xl0zSpE6X415moMnwjAQ04n0ZtjX68yheKvM2znYbsTY0HLmAt6sml9MK1s5z9PyL+p1u5iatgek/VKGjo2x94FLbhDW0lu1PhpnTRn3eD7OXwwhONHPPqMO0jiKx9NGd76TMjzxMslWajFVgSaxllDfjxBBgnHOMelzMwdC6HtMl4XfH/SncL3yfoVDupyykqgUeQchQ18/7smEio4du3Xeov9Fc0ycp/gebpOxlzA2QAY4YgDnsURK5NEFbR6uapnwbm2LzXkGlqQLWHt3w9s2bwDZs0Wiyg/ihw== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CE2ypwT3OJomDCe7xvAcyk6XTnOApXzXc1fP3Bmi+aetQYod9+pdS2/C8o3+kydo1y0c+sTR6MsBtD99aoT9MVnGOFZqoT26RnqBb5LNhWSF87QTkT98xMBXXl5G2TUy+7gVUutH6huosEpDry+WBy9KHQLqQfdP3ysmSuQo3JQy9YkXJK1dQg2Q6N2caG5egLBclqMhNV6uzXwfafBRbtGYXbCeBwQybSaxCCqWSbFCM7LnWl3OmjONcjUgDZzTimTxun5PAuw9fm85zk7ZJZPW+nntRvODZAvk5lU/azOzukx19c/7XWONwYxWnx+mRDFDCrAxDdlBc6k80O5jATNAXfY4T64N0WdRQCLvy0MMEl7P3ubpkBSgn50717Fw0u61I4Ji0BTGxzhCQlUKc/N08keIqx4DPKjVt6r37FhsNhr3qhMJYicXP6hezujOqR5uaA5vgAk5jlKZ138evlFegCZvYozyy6BmDzhlAz/4GZewQKiljbdCW7HN6EvsZXBSGm0ZMPMgZyHCn8x6ddzWDgRrN1KllsAC1OrsUXVsDbYyPdb5RXrCl0Osi9aqEc5VYSQuJaCiwAmMQNIqI2Sevg8WhYdmGnyJiPdCMAVJMkz1Ry/mBul1DwudKG/U/NlHYtL09Wm1pKxP4NTTRPYuOKiiYI31AaMRDT6BGzvPHqPdOT+gX4UQf6ntW7tM4zjonlcr/qN34m3XntNfCN4+LvmirvdyQ0CP7ACi26kyuC7Gf8HcxBfW9KersF+SJ1pm+dDIhGLmUmdADhJahtC300Gs2tcdjm05TkJxjYfKFwmhU2OKWyJmUzfaJLEPicZ9qIbLjkSdeCe63YMF/TfCgMFmmRhQFo0hP8fMDEtcCe3RuPp1BL+tMaKIWFNvFEmT/uFYjVgxGTBOdvo1F5niQXg+SS+9vxe695QUC5w8NREk9LetoyrRaUbIKHjw/wrD+T+f6yaCb4V3bwJqrWNJCryAcluqG7XKBltDpm8VgAWKS4evb2RO+tPwviSOy3pCbSnNseyzNsqNoNQrM4ADun4zeAdgcZuB9FK8xKw0El73fg5CUXeqgPgf8JWjM3hYv/zeGFiSRkWdpgA428sKmPIpsyZfE6Gc52VURgwiu3SoD6wgqzyXdfEAPR/8mx+Sb9jomGj7RunEW5gcypGHxuPjqTTyUW1GqNrW+vp8DP6Fi7/WU9TZ3No52yfk7po3HHhnvsN9lREC7P+kJn4kxU3z9XpUfhCnxORu0FcbbCCDHGnSyp+lpfjAqbl+2Grlo3gPIqngxvrxGVmnxbZfxiPCmLD1rB1rew9GtPm3kfWMs2JE67Q7Fd+u/tUT X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da957e4f-225d-480f-7691-08d96983a5ac X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:53:59.2770 (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: Kf+BaNfhzl4yF2C5ZgiVk2xU9qq3bCGOxbZaVFu5s3TSX/udhKjlRMLfTus5uObPEju7DRleAJ3xWyu5a+hFNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: gifVbBt1_4aMS7Ciep4xLFc6iKod0lGG X-Proofpoint-ORIG-GUID: gifVbBt1_4aMS7Ciep4xLFc6iKod0lGG 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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/vfio-user-obj.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 52 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 13011ce..76fb2d4 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -177,6 +177,49 @@ 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) +{ + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + static unsigned int suffix; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("remote-mem-%u", suffix++); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + memory_region_add_subregion(get_system_memory(), (hwaddr)iov->iov_base, + subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static int dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return 0; + } + + memory_region_del_subregion(get_system_memory(), mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); + + return 0; +} + static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); @@ -226,6 +269,13 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup DMA handlers for %s", + o->devid); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 2ef7884..f945c7e 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -7,3 +7,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" +vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" +vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" From patchwork Fri Aug 27 17:53:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F2F5C432BE for ; Fri, 27 Aug 2021 18:05:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 77AC860FD9 for ; Fri, 27 Aug 2021 18:05:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 77AC860FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:58574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJgEZ-0005RF-Mb for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 14:05:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3P-0005mH-Vb for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:11 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:39608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3N-0006xp-W9 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:11 -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 17RGNg5c002209; Fri, 27 Aug 2021 17:54:06 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 : mime-version; s=corp-2021-07-09; bh=u8L5/35yRc5TruaQI2q4JkE9W7gLuv713aXGPmw3Yp0=; b=bI+YdpuUi9wYOT6/aE80kYM6Uc5Gs4bXqVEkPUAqAQCQMTE+G/D2GJVA2jNZX6ulv5Ul dzuPgzWLxXq38ozSqWBDa9H0S2iPW0dkX3b5ugn5cv6rK3HvVQktpsC3WTJpf7zteqRN L4irDvITNLz1xOPG9WxVmnu+YWBNp0NfSEc0e4mnh8HWFRAcu3nI6vcsxsKabEL/pefN ox6kOdf+13u7CcdauOlPOybbr0FUe0d0B9buJ5+0lwBSnP/TaZX38ZnajQrMyKf2yQMJ OmlUSSzGDyJuIfACia8DZOJVlkjoC2JvJGPUCAH8RANcElLflXpeAVEqGvgYFUPdj22c Ew== 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 : mime-version; s=corp-2020-01-29; bh=u8L5/35yRc5TruaQI2q4JkE9W7gLuv713aXGPmw3Yp0=; b=WbKulZx9n/0XYLQpmvWXSF5VCyrffJj7m58eb0BhxwBqmMUP2TYGHWbaIlpDHITRHh+B i1EX+GmDRJwPRsXro8c5yHXQyALYVtaiIo222qZxiyM0y/4qbp5Xy8g0PIC3nII1cJ9y oRnV2v4wqEhq4PIu/d7LyScmokccT1OPTozFVS3MAXn2LNouBqJijyvH5pTtzEWGeY4z ru5MQnXgqsdPXkJv4lrVBrt/TaMnGPqoYsEMChEDRQgZ3DNOyF4PrcQaArc2/gfV2xsS sbd6cAAC87jhDUlVVwxsozJhpn2uI0ZXLJnmVYtyNMfs7bgv95BzvpHIMXJOgIlX2LOB uw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3apvjr19gv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:05 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHo8jq037884; Fri, 27 Aug 2021 17:54:04 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by userp3030.oracle.com with ESMTP id 3ajpm53hd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P+RjjJhfAZf2sAvrX2Bez2C7/xdbfrWRfTjhpSOckABT2M+DPNw5v2VtNqncm4t0VH7/bd17X3TdR7zWXKr3KG5NXFgl1PEAcmslFsBhfOiC1jNZCp175ij4b7Ovo3rMCxRgT3xKzLxU+AsD8mXSGtHVsjkHaMFiLnDIWqkfUrBJQ96QV2zj8NSk+5RFv1uJ6vMrZTXhUv0xWhmV1xYl/a6aqh7WxGzF+BZHJCi6w5cK61e0F1vf2PJKiUVSMqfBo4pdyvEti/n5Qa3nTLQmNZSjL79YUU2gkfIEveN+7KhfN5N5+mNh9WT8D9a2vT8RryBBYvp54j7PGzzasyvyzQ== 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-SenderADCheck; bh=u8L5/35yRc5TruaQI2q4JkE9W7gLuv713aXGPmw3Yp0=; b=AS741uVlMtm5JfihgSYogrEytrvOM/gbc5YfqAfRnrnRixrQBO2abNUDwZD2Y9ByZQWL3rATguJU5fM/8Ja67kS0EqLwAhZzId6D5G7R+E4ie3h3v+Y6rQLzjDpOTuinVDURPmbn3M5tIjl+4UxApg0A6+veiCi8Fndn24R3N7u+H7UqZ8GYgPlnfnCbPXUQAyGRSsu8FkQi4ah82hi+qJfAeJGg1ZxzFcrc3/HuCRwX7Nlh5LeGImOh+YFtjkK+P4aTVTVhRC+Kn+8Y0c+5R6kwjsWeSdK3kiN8WsN6Fftk/CB62kVktgdKGK+7Ij1Z7vV/5mp8QjNrFDHZKjKfKg== 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=u8L5/35yRc5TruaQI2q4JkE9W7gLuv713aXGPmw3Yp0=; b=TT0X7lxpuSMqXQsjHNJYGhqvaExNydXG/Ih+Ru31Z/zakc/AUogdaACCYMCtU6boOKjI8zuM6rjnsJg5KJGbugKMd1K4OOubYo1Vq6eSB+2hMyPFLoUyMuqtDES1X1orpKZnR52oor60IEfipdWCr1SD31fDs/NEdBF8PIXkur4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:54:02 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:54:01 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 08/11] vfio-user: handle PCI BAR accesses Date: Fri, 27 Aug 2021 13:53:27 -0400 Message-Id: <8dde83642333cbe5e616a619507697dcfd315a10.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:53:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b426828b-3c37-4915-670d-08d96983a73a X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:346; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0iFxLxPIu+pIuvV4GjqSJ4ZNUhyjKmdZ1uanYCv0t861JKtMPSWtJ7mSJe8hSjzVih6ptmyqKIUU677QbtyZLgZTlQfZ+Ewkjyvu6hur7eoNXXguABiT6U0oyfDA9MOvBUwHXv1gQRaQj+jKEtgTa0VKR0l66IjNfxuBr40qYsvc5pPENUNb6TD8EpY4tttJQacfAnmBFsdrhCD5Ju7bRENdePOJOCRkdUZF+oyaKYbBA4CITra3VpevfzeVKq8CLPmjl2kMSQF47TREwBCRSryXVwmZIQgczgRXBUlSE2Jk6LU9ky0g4XWpW5+ProGJFlBYJslZRCZA7jM3XV6bJboVXR3IR+aG2xHRCXcgIwkn0hxHDSE4+djoP18bezZRSUUq/18y2apLTTgKxbX8qW+qRdVo4AypJuSrLavxf4a+WztIYleHO3gkSjDYGGkXa3Pl4p1C73Zxx0WK1LaILa7fx521eRFYSKOir1+HOD+s3XFMjM6xnXMsG6VGwkEJejsaS3EBTksKX5UeLlh5/SJIjrjeUQU1+qCYF0epkUU+7bwdMTQ9vZgq5xnua6BFA8hZznsOuVgBWGhZG9xd6Nq1/lalRZNx6wBsJsl1Esukn/1ObRAhGUzm2bb8bedTyDduP1SlKXOqS4ymqfK99VEEiInN+I4y2JlKI5Wpxv9QV8cKmUEoV7tfXI9ydyo7UL3XxmVNoPnbgFTr/ymGrg== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BSC9FLZWC5HlLtACQgi5BaS2ie+ZaiTsQOfUZh0EK9JK6i7PO/L5bF13wSz3Tst5G5mkjqBeGzzTMbbFs6TJ9WY3D4s6B5Yrvv3vTF37zDYBZYelJbWbKOdRpiaAEs06w6E4e4MJTPgs/kJa7NULAJWP52LfuxVIBW3ILtJsY3KbKWj2c1mElRWBj90vwya6JM9c2KaFnuFgK2NG3bIHNuPZUwTA/OFSxf7Y2rBvIjfcRDw1r2/NmFuoqP0M+BIPLGQZBRRs4B6q92sqHWLH8umAYIC+FPPQ8GVU04JuO6A88VU5j2tW0cZF5GThzdlXtCwUaR9s3EsiJDsQDvauuVgrKmr7tt02BxdsY9wn1/qLKNhE+qrTbbfPZlZahSY4ErCWDTee7gr5uLe6B7dV11iHhBdSq01WpE68jVo3amCuaYHuzd+fyleahdl1ei13oEBIgL415Ld+kMo/ri607UbPxSJhEJ+ovOsEF3pyWq/3qmh9WEmKrpQjpOkpBbEMYwSdmMYCjnVjDtdaC18yVHWtY9sJPQRu8Z15JWdTEdk0hxgWzdZqM9uHLVPM+xL1g386X5dfRd3247kx5+VZ2sAuhXG+lJHxGIU13iPwK2aFR/yPYOeVJ2DOMqny+Nd8nGRngvrHLrLk/KWKSbXP/dywEfQbEMyTQAYMK2tMr+68oeKCXxVjMGtPLD4VWXcFF/GISkP/mcnWKxcSIy+ogzb04s0dng8ASnRx0E1uxfBhWAj3f+kmZSEHE3ijdrPjeFR9D8b7GJIgoTlsTKKQ8iSiNUKhQBSXH30MFyNjDEgwxbXnMJjEgLgdMZ1L8e9Wh6bPlxL0UoAUZ/oLSpIB9dZzpiljX8m5k3f+davpryC5oCpBwa9KVdNPOJmbi+HduhEzlWcDhxi4Zo7eGqaotpN+kKVFFHZbV39wrdu3gUbgqB0Z0cNbA9QFxHjdoMhZ6zWggkbKAZcOZDSHkIfkwWot93iNB0nOh019qEaavScb1ZaQj5YeQs37vcGDFERYWpAb6aQaOA0iLN93P8kT3CwptwLUNze+YQJ2HZViIokJwqJH/0CxjI5uQp+rtIwkavnyVhJd+N54kNZ2oPX26Ir5HAo1n6lnh9uz1ceSOBjYzmoVlp/9//rnE0QJ9EKufzXw5tyB/GEch/BaGUze2f/J1utjJ+VDD6LbhIP6UBb71q0A5MFb2wA2tYqjXwQgoyY+aD7SJJy7C/qgWJbTT8N2p08Or+5KiJVzTK4kOMXXQxoSebzrMDAfNFjMo1r82ZE5NslDc+n8dmmavZtaIVERcud5dbttnZy8ipLrAd+e7N88tS7LQEBU+Ctk1ytI X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b426828b-3c37-4915-670d-08d96983a73a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:54:01.8469 (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: s/kEG+3xm0ulhcQ/i/pk6Aimken6Q47xq10qNrhNxSgpTWTGG7vJiejPkAcJVbKGnrcOgybdO+iWPMyeS46VUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: fNcCROrJLt0PmoLKVu9pGVRvb1tWS5v7 X-Proofpoint-ORIG-GUID: fNcCROrJLt0PmoLKVu9pGVRvb1tWS5v7 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 --- hw/remote/vfio-user-obj.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 + 2 files changed, 97 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 76fb2d4..299c938 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -220,6 +220,99 @@ static int dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) return 0; } +static ssize_t vfu_object_bar_rw(PCIDevice *pci_dev, hwaddr addr, size_t count, + char * const buf, const bool is_write, + uint8_t type) +{ + AddressSpace *as = NULL; + MemTxResult res; + + if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { + as = pci_device_iommu_address_space(pci_dev); + } else { + as = &address_space_io; + } + + trace_vfu_bar_rw_enter(is_write ? "Write" : "Read", (uint64_t)addr); + + res = address_space_rw(as, addr, MEMTXATTRS_UNSPECIFIED, (void *)buf, + (hwaddr)count, is_write); + if (res != MEMTX_OK) { + warn_report("vfu: failed to %s 0x%"PRIx64"", + is_write ? "write to" : "read from", + addr); + return -1; + } + + trace_vfu_bar_rw_exit(is_write ? "Write" : "Read", (uint64_t)addr); + + return count; +} + +/** + * 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); \ + hwaddr addr = (hwaddr)(pci_get_long(o->pci_dev->config + \ + PCI_BASE_ADDRESS_0 + \ + (4 * BAR_NO)) + offset); \ + \ + return vfu_object_bar_rw(o->pci_dev, addr, count, buf, is_write, \ + o->pci_dev->io_regions[BAR_NO].type); \ + } \ + +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) + +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_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) +{ + uint32_t orig_val, new_val; + int i, size; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + orig_val = pci_default_read_config(pdev, + PCI_BASE_ADDRESS_0 + (4 * i), 4); + new_val = 0xffffffff; + pci_default_write_config(pdev, + PCI_BASE_ADDRESS_0 + (4 * i), new_val, 4); + new_val = pci_default_read_config(pdev, + PCI_BASE_ADDRESS_0 + (4 * i), 4); + size = (~(new_val & 0xFFFFFFF0)) + 1; + pci_default_write_config(pdev, PCI_BASE_ADDRESS_0 + (4 * i), + orig_val, 4); + if (size) { + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, size, + vfu_object_bar_handlers[i], VFU_REGION_FLAG_RW, + NULL, 0, -1, 0); + } + } +} + static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); @@ -276,6 +369,8 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f945c7e..f3f65e2 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -9,3 +9,5 @@ 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_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" +vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" From patchwork Fri Aug 27 17:53:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ECC4C432BE for ; Fri, 27 Aug 2021 18:07:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A2EB260234 for ; Fri, 27 Aug 2021 18:07:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A2EB260234 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:33934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJgGJ-00081k-SK for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 14:07:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3R-0005qy-Im for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:13 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:40362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3O-0006yX-W1 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:13 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RGWtYW010418; Fri, 27 Aug 2021 17:54:09 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 : mime-version; s=corp-2021-07-09; bh=V+ltWcVfIoiwJaQuc/RORtOZ5xq7kVc8hIjIQsjMCoU=; b=PNh5ywFfAh/r70l249KEPcnkziI+KgBv8ayI6YP+davslyaCNvgvgbGoDY2m7m93kRXF jTzPUCDkk/0jhbTExgLngPa19URxgbSJiZypUStUvo+yh3e0pyC2wdShvIOpc+YjuOCH jDWNmt22UEX5l3AOLvc6uh432BJi8qIWS4bOaesuDLQvoo5iXvoqKC2m0U8+Vdqgy48A DUvlzbJV/SIhkvBQyVR6ES2htPnBISoQLk36EvGlJI2zzyEMsTS9G3Pwlcym7pbrmEkx sqtQM9aSqkZbGR33F2eYkXgmBrsSkIa8w2kFLXntjClC5MqRCa/YASpTfJV2sfq2WGQZ TQ== 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 : mime-version; s=corp-2020-01-29; bh=V+ltWcVfIoiwJaQuc/RORtOZ5xq7kVc8hIjIQsjMCoU=; b=h7P+8TpK6F1NiM+ixdk8lQcBuWHS4EYUk55CptCwu8QwMJ/6ZD6/Ud/V4kyFrqYsaBwB GEElVhE1u9noD6yp457O3lFLtEBE/Hs7TgXcbGCkbxg5SmWK9CV4a0QtVe6DVZA8r4Lb e/wrc74zyvaB2uuC0kdAB1ANN+dvF6HUYwA9bU1HRKsEhqKDh7+EOfQb52Utj0msMzaR 2lfxTQTkpd68c2I3+9KlsbUIS66oTqrVF7+m6ANuDb9vVu6UDenKNx84iL/7HA+pu+jd PK1R4PYx4cjjysAdX3wI5Heje1gSLXkqiUfrojJN44vpnuZFh16gpkmz04xEot5O+YVJ Zw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap3eavcd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:08 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHnsen178913; Fri, 27 Aug 2021 17:54:07 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by userp3020.oracle.com with ESMTP id 3akb92hjc0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CluvybeYoPtHUB7LcAVxxC/U9aKDRWqNXs8hy+sJgYb0vZs0QbrtC4+EI5mgpBldFlTUTNztD31D2UkbMdAkNqYAcongCz5eEtCytcOepvgvEZOX9rlpC8G6DgwXMBtBj3dcfqIbMUrg50GMjvbSFvIXyhQZauxBms/yWWlVuYEAZQHEyPH3fnYqZxhsnkqqvn708UJ57lTvto5Z/CnbA7Sg21lnoiWstvINv+kfF5YIk01O/sRTSEp1TD25wkQ/qnqAVE083LxhB/u/Wc0eMTmtkh02mXH/CdC7AkJyAr8fyMHR0eEvk2yvYraDNqfbE352WEocRrsoZycpFZTSbg== 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-SenderADCheck; bh=V+ltWcVfIoiwJaQuc/RORtOZ5xq7kVc8hIjIQsjMCoU=; b=htNXcQN7r+OGsUiLDM/MNbBVLctvGzu9s1wTu9dnMD7UqfHswWWVYx/bYEi69w4n+6Yi3L3dVlSW6hk/qwKPCUX4VHbjfsAMkDQq2/G3ZS2032q4mF9CwTGkGljK4l9DfdIdOh9uLMZ8OVX9DVsNxak5zYTe32WetWR/4it9WTyFjf8dUYfawJIlKi8rTAdmBHxBM1vmb00r77MRZ/NDcn18BsX4SLhjP8A0UkYewXyf7o0acfhjGITMV9ixTUTNR3sgceN2GQOPAtaHrGKLE5P6lBjDb8mVnEVgPyvovQIPmJ6aviUtBiCWO9x9hCOCbtMR4wj9WrkuKLVjv15y1g== 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=V+ltWcVfIoiwJaQuc/RORtOZ5xq7kVc8hIjIQsjMCoU=; b=fwf5gkLpGUNM2JWyyMLeXMAW9MFPp5dhdn6Dyny8Cl5niDP2UY2rfAMIcrHJ1KCchyvAYmCHgOoquUyUsvUMwi6InR5TGBuP7WjcmGkthBKokSsUKz22K7blWBA4WpYlqY0npBLDK9jPYYaDsYk1GZAelg6UuwcsGX5YgKpkZZw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:54:05 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:54:04 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 09/11] vfio-user: handle device interrupts Date: Fri, 27 Aug 2021 13:53:28 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:54:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1efaa16-07ab-4a3e-cc96-08d96983a8c8 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:462; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ilZOKEsYgFBp7RSsL3vcux+279ui1M0OoXtGIBPle7oMmTkSSIksEXAEHL2zoW92XzIwxqPyQR+Fq1H/dEK2pt/sghgS/isUv0UbmDdxMsTaJxWEQG17GdAOH+DoVo5INF06umXVo9bwqI1aYpUIEf6EwWVoKNnAeXZP96RyfoL762DM0hNzb8wl39Gffy5J3hJ6qxL18SkKlzqZT7rpCs0bpDJDOHr3IuMI3dmBa6duXIEi4opsiXr1xr45Ays6Ea3EhEQo1uuG9kohqnJcfOa3MUJvK3KM6jKTjXhjAQZwcZPARYfUxzPYMDY+L3SXXjMib/p5/7m2kIWXeaBtA52CIvqe+xeLkIViKaY/UoVb9L7ap8Hjcmp3CWPKV7F5ahLdHy26NaKi3OBGuhduTuNGDAiJitRKiiO6jyCGf3EHlWu07Vxl1ufqwRd9ypLMpj4ZCiFG5jWUFv+731nL10s3+ain769cYN6gsuKx4EYfsaGxgMwYyHsnvG3JvcE+bQ6Qz8uq/C1JX/wWDuHtkniJjm23VdmOuyF/J1XwUvRMOKBtcwpdmuUXwlRJHHevBBI6/3shE8aTBVeoeWVbCfVQhpKWWyvO9YDO34mMQAkqypJW0i+jYc70fUD5NO9mEmdQgRG5bWFby5zaLHLpL0aL//cu+HT1Htp/vwnepq/BBWpnMawNLrTp5cGlQPoa19KntE3fov7zDUOlS+pgdg== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m8+Ob/Tot2S/HKNBWVULgmnfayeO+B7u95jFTO86Z/bFQVBupr3lVzbyN/1k4Yi3Y4IapokmpTQwtNCHuRn+ZrkjvpNCCvlGyzemXSubQaAtxFpZoMD8GSS9X/hFROI2bypPUsJPfTs6jaUXfu5EGd6jqyZoYU8w4Ppc8+U4D0lwaaVV0U5Z5yLsWSgKu5kX+6pQJlHk/90FgAWFnotJm2G1rIlqL6i+go2SJehYKFhphK4cdhJFn8fLYGIhSfX/n0hsbi/VcZP4qpEc2OhkHUinr/vb015KpW0Xa8cBj1wOVtGKEhonAcikqAk9/dQdn8VU1h+qI2aLTLqJcPRYgY3OqF8/OdXwCGtuFU7kVOLGdEoSW5mBivZD7S6Fl5CRJ7CSU+55BvDPK2dsBx+rmzlTHaSFplwkOEkAZs9lU3AMuo5QqMz3qCTQOnLXlFUD11OuSv6OmSd/0BuHTHSJO/1DssFFh44KaFpTPc/iYqqL0ZZlMnOPb2Xt3e9ZPpk1W9jEyT21NZbkXHQ3xtt8omh1WNXhDGRDR4qZgqMHrcurR3cRrS5Gohm96ey2DeKZnUNagWG4XC3oCPKW2794t4CPuPp5MVW4ZMqzkYFmB8wmgZhpzrr/h2p+xnXbIEcIr7nJA2UtJYW3+80D26HQ38lj7LOpPlfjilPnOI4ctFRL8EA1ldsMJp9TpIxV2PttUlQBCFkJ9SZQbxk3rKTlw5qkMD8/7USDDeRRTDF2E1WePPrgRsFcFynkuh+i6MophFRl3BNmknbSL2n9He/ZyLIj0haIfrNiloMh5D3B1PKBtc1V3l+a4v1ERmi/teUOE1lQY1hnHmN7P3+M6b5gqYsTJB7DNlQME4NrmZ9uYtRimHDu614hwdlGfg+FRpMpZznD7XWCobLziWlvUhTlBgI68W8CtmeDxNwwFgD2/5rSHcwFJPVeR+E8sItXKO0ktpGbfuqxusAyEzhGIrVsDUsUUd/DuwPIN7axD31LPAypk5CU6GOaORWNdvxkQtFGzIYE6DwY6nvmJSjCUzLPdzPJ/lHt0W6b6cg67MQ1lD8rMphPsrnUKArhb0DVf1pAxsZnZxk5weXnAEej4y3QlsRhUZXViH4pOTH6ii2Q0QDIrcyGuhiaolCvzFuB3KrgdmtZpSkhTRHXWA7YALqY1RLvGgCmBK9g1WC3cuUIWjGnd9v/Nb6b6vmb3lTikmYTWZk6LD3M9PnMF0ivn5WFpM1eEuH2nsDJ18W9L9+5/ufGKQ+tfJjp8gXkGoh4JHgKq59aIaRXQSUz90ePFLoGN+Vc8gA1Q8VT4k8gG0kQ8+Dac0odR2n33gZ4sn4hYtz6 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1efaa16-07ab-4a3e-cc96-08d96983a8c8 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:54:04.6058 (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: Sl4Nft3yAVR3cY3GYo8URZmsKySs8RmW9PyW4C7ISF6HwFlbEt/sAKBVAc/6cx5a/Y2qcXO4BKL0ioBlmmDQGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-ORIG-GUID: bjO6Q21blNiKjdqtPV3gGTuPKGeU43gJ X-Proofpoint-GUID: bjO6Q21blNiKjdqtPV3gGTuPKGeU43gJ 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/iohub.h | 2 ++ hw/remote/iohub.c | 5 +++++ hw/remote/vfio-user-obj.c | 30 ++++++++++++++++++++++++++++++ hw/remote/trace-events | 1 + 4 files changed, 38 insertions(+) diff --git a/include/hw/remote/iohub.h b/include/hw/remote/iohub.h index 0bf98e0..d5bd0b0 100644 --- a/include/hw/remote/iohub.h +++ b/include/hw/remote/iohub.h @@ -15,6 +15,7 @@ #include "qemu/event_notifier.h" #include "qemu/thread-posix.h" #include "hw/remote/mpqemu-link.h" +#include "libvfio-user.h" #define REMOTE_IOHUB_NB_PIRQS PCI_DEVFN_MAX @@ -30,6 +31,7 @@ typedef struct RemoteIOHubState { unsigned int irq_level[REMOTE_IOHUB_NB_PIRQS]; ResampleToken token[REMOTE_IOHUB_NB_PIRQS]; QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS]; + vfu_ctx_t *vfu_ctx[REMOTE_IOHUB_NB_PIRQS]; } RemoteIOHubState; int remote_iohub_map_irq(PCIDevice *pci_dev, int intx); diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c index 547d597..9410233 100644 --- a/hw/remote/iohub.c +++ b/hw/remote/iohub.c @@ -18,6 +18,7 @@ #include "hw/remote/machine.h" #include "hw/remote/iohub.h" #include "qemu/main-loop.h" +#include "trace.h" void remote_iohub_init(RemoteIOHubState *iohub) { @@ -62,6 +63,10 @@ void remote_iohub_set_irq(void *opaque, int pirq, int level) QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); if (level) { + if (iohub->vfu_ctx[pirq]) { + trace_vfu_interrupt(pirq); + vfu_irq_trigger(iohub->vfu_ctx[pirq], 0); + } if (++iohub->irq_level[pirq] == 1) { event_notifier_set(&iohub->irqfds[pirq]); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 299c938..92605ed 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -42,6 +42,9 @@ #include "libvfio-user.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "hw/boards.h" +#include "hw/remote/iohub.h" +#include "hw/remote/machine.h" #define TYPE_VFU_OBJECT "vfio-user" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -313,6 +316,26 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_setup_irqs(vfu_ctx_t *vfu_ctx, PCIDevice *pci_dev) +{ + RemoteMachineState *machine = REMOTE_MACHINE(current_machine); + RemoteIOHubState *iohub = &machine->iohub; + int pirq, intx, ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + intx = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + pirq = remote_iohub_map_irq(pci_dev, intx); + + iohub->vfu_ctx[pirq] = vfu_ctx; + + return 0; +} + static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); @@ -371,6 +394,13 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o->vfu_ctx, o->pci_dev); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup interrupts for %s", + o->devid); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f3f65e2..b419d6f 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -11,3 +11,4 @@ vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %z vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 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" From patchwork Fri Aug 27 17:53:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E58FC432BE for ; Fri, 27 Aug 2021 18:09:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4EB1960F92 for ; Fri, 27 Aug 2021 18:09:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4EB1960F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:37120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJgHr-0001p4-4b for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 14:09:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3S-0005uJ-Q3 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:14 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:41890) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3Q-0006zF-3C for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:14 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17RGa3vV010409; Fri, 27 Aug 2021 17:54:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=cJtuV147Oty00gCnd0OZ+2qIeuHVTrmRmvnw/yW0uA4=; b=OjrImtFgBselH9B3m8IJun+1Op15U/YwGe1Y4TfT6Pon1GaYN7nK1Y3ogO8SO0EJJi77 Ojblywx02jzPKOdMd009jkoa9ILCgwmTwibXjzOTJhe67vHtYNCfPr/3qWXLN2RJM6tj piktyg/myrmdKUs6zaYcQRBs8hr8pVdC8S5euIsZs3BQuUSE7f4KHPM2yC/XZ83ZV1nE 7J6NcUJ2D/s4OaSx9f9HKSvjeTor27lz0wFwIHO/3rjvxvJXJwcp87BjSiadedrDxbVc C+8e5bBUhKw+N3UA3ryPgOzpE7oVpEnf1bWLwjTIV6PIyGlSOPAnQur6cuwJC5izAFyG Ug== 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 : mime-version; s=corp-2020-01-29; bh=cJtuV147Oty00gCnd0OZ+2qIeuHVTrmRmvnw/yW0uA4=; b=KuVXA+n9nI/qhBjoTo54CRARuCBFspLmZIe0KDhSJoS30vOr7JcbjsDVZHuuT8xxFahR 976McVtmXyGhskDzOda5STJWG0Qqoq6hGyffxW4XTC+92AYdZNVvR+q+T2myvalkhSQq +8sPwTreo9Nt9hNNvWEmzwghuJEJ8TKLmdY5WdDSS7Edocsj2AUEKmSLnkDivYIuETE4 gd0ni1zAH3g6E+HiNouIqVrvvPvk1Q37wuCVKTSB8RA2BSTh221QLwXQEAN30OcoVrkZ niqZU2mhsxgMMbBybOj9KjPRTyyucaUEu8/BlgWKw9DGmZVWSL5I1SpEiArt7U755tlU Hg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap3eavcd6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:10 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHnseo178913; Fri, 27 Aug 2021 17:54:08 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by userp3020.oracle.com with ESMTP id 3akb92hjc0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eTGw7IvzCzZKN0H1UezIjcn3ceg9XOUkZchbJ9FlwNRx0gdUEIh/lHGA3dGOm0B7W3LyJth6NmgTT5Dpq58YT00BVHM7kdovCljPXrtj3cWS2J2v27GEroInah0jx0vzvvuVYUls1VzF7k27ZHeiLpUajIWkW5IkMo72ZJCnWIcGM6jjF0vhKvPt/VmwhUq1mbxTuAhwaa855shtVhZgAkOeHOalvSQx0o91T8PG4T06jkgmRwpUt4dNs5HTWj411+udLPBBslUZ/NcHs3S2C2b6aygUhYSmEbHH4jV3sTGgn3au/cCku64tRw48vHuON16ZraY5vGM43cp5PSN0Ew== 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-SenderADCheck; bh=cJtuV147Oty00gCnd0OZ+2qIeuHVTrmRmvnw/yW0uA4=; b=mdIwBKDxsb5zL7OtVf+h86pb1aUNKpFQMCr1LI28iI1dvDq8XbXxLfe9MV5Q4kniw62U9ybg13gixe2rL7/VAOeSYbjHYCpBNv5XFKyI+upxi6NDlogHp6/Ou7Uk5+HfXht1XtXZovJ2Al8BfNpb646LlIzcWgjGmSf7QMQLM2f4/TzBMe4EdxqDYeMWeNAX5xLuaXBg0QKSg9gwcsxTRAxLx9n4d03KRHpbGA8bhnsD2UH6tkP9Dv38PTgC6OQ06geBBXTflo/A3n9ELOPGiRwhl85aWZXRVc6cr+nHkE3JyIiQkHphLY1BbeMlqPQGlZw5kD1pblopLVeAvYfXng== 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=cJtuV147Oty00gCnd0OZ+2qIeuHVTrmRmvnw/yW0uA4=; b=K/pvOxisfhAYeMECsfMhKtH7HbSxdyW/3JATTDGRUsluF008+yVglQdKux/gP+lsY1SbdaACxWzgSYKg2XhCPJuyN0qZFq1MEAl1TU5mx48l9JA/y64fa4srxFuoAr+H4UfNtAoEfJDphgE6NfrepzdjwKyvZhLp2q/WDp8piNM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:54:07 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:54:07 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 10/11] vfio-user: register handlers to facilitate migration Date: Fri, 27 Aug 2021 13:53:29 -0400 Message-Id: <1550222ea65ae3dc425dff236f4f36b723ab8597.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:54:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1486e02d-06cf-49d6-6dc9-08d96983aa71 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: scdzYurNQMN1WcyM+oOXV5duqColYkCxV/uzzV2r0LMg/RJ+r68R97gDWpokS1W8FHLD6XffmVvem0Uyr952TdZdaEW0+9JTk2oVLoqgpmmPV1YqLkSQZAltpX73amKK5UM8eWtcHuEH/6cscfWGOHnoMOLyMx7kKUQVpJScW7wyzklsfjpvEc+KpxxIqbqmKSWXqMx959ee0EVRcUfMILQFuP8aWQMKruCsPLzLSgCqDUT8zlotYfTzmAiRrBP3lEOthdWq1ZwdaUs09suVKB8DS+Uk6SjGbf/wUsj2faqKtjfRrR56YjcE0qtZ2L5/nSncyUDWpSJNiIrT1mg8q9MOWk+sqQrny5MCiU0Xk2TydqXsp4CMS8/ajxPyN5lboBSD0eoIDA6KJEDhH3pj0qAMxF4qgmf4Jb7ViKrma/MatG5gUC1LQELrNRxqvqHgmv+ILxfT5iuIH0pOiRPGU0KT1TH/qa8979zmEvoLCpxTcbbgA6GkLc2qXu2aEFeM5hORtfkvXv1bGbYUb3mQ4W2gfac0FtMX+FkjsXqRwzAz6Lg/u1AuZsv0YqGYBxjLzF8jNPcWAE9IRIsTcANTJdgFQWnazDo03NDuiLHrNxRSgd0K8quGISFCm7YFE5xKHm93RLk2aoHt69w4MOVpa1xXkw0eT0UODEB7B9AUYTZnsOMuL5o4wch/rui0SMlb3Xr8MWs3DPWP5IDwPnLQYA== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(30864003)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cB5/ID0oIUr0CblemOLFhuBVix+QIFQfeHqyiwCqk/yhCFnA9SPyCWVOEwFgiijTU8+ZB4EW42kvURtuVrRnFPwv1eIImGfdBy1qmdTtGqbpP5+bNs3yMPf8+r337fERYVrowxGSFdTntLQQk18h+799MrtRJQPNISi4ZgMKucLQuX83dDgILY/Tg6muXjbRwnNWQL2pfDE4MdbDtwV2HYKL+KEbyV9GdmaGdAgtbMqVXXf+0ez23ohvzU3GnsiQP6vJ5v6fXn9UufMiRlpFIvvvM4cMvFn/sHW3/Dk5l1tvxdB09VcOQFa0wDrqPhjiS0Y3TMxd7bMIMxAzIIVu634kP+gS7G3eTQnHVVfmRuYfLwcOBlvInWuABbPi88DyOgOExXnn53QhGxgjVlJlCwMfjuoT7eTJBjjnPXjSfheUVZpq72R0T3q+bpEapMOhkXE45ouiD79n02FrVFGwh2q+XV47o1H13ZTrNNLuHZ7YxHCoD4zxuXqkvz08RYl/rwchvy3oNgLBKQMofPxHHqMoBX+vf+Guzm1uN1AYx/ES3lUoDjNzF85DPEMuzFyAI+DvHYfmU3gUIuIVu42mDaOOl+drXdd80CEFbatNXQzmQfuM4KQSlYeA9o7zeuwqfpVhQYf2SuS7f2zenoq/bWAYoFIhxpbWaYSU2ExDC6wY5DSR04hZYMEPck+E/8z203ZGOU8vRC4TEsiKeV/s0l83ZCYE3KCLL8O8yzX1KlmYgfQctiweyWqQEO0GHXyiiTvb6cDpd+VwEpMR5+tohFJobyR3lQAAi7dHehITajrv0CanYa/qlTofLE2z0A18pfsVEqomfbAqevjmqcohroorlJDot3T6QYhJksmNWuoj32YXq6peiT24ihIlmNmslgILjcFJV9p1TDz9nurJmKSAJ/HRie7NW0UK0vR6G2JZiKpNj+nbFANeyZmykiUQg+x/c0jbg7DRaZ5lhkSBI8ZfAI7NnUs2jM4kSnHnQxksFXJT/GBoN/Bq/XVmi41xHzoILAbUSU1zz6a8piNtrGJPR1e4wyhKeBoUX6xSagfN0HsjMYWRymZRvNCWnYN3VMUu1J0V1giB4tDlppyuFFSC/SqlUdZ1KDhg9i9L0/r456JJ9N/hd5h2J/q5jBydnsnjBzIalygHyqJt2W041dZbpADH4Glpon67OnXwZuzHZBPlr4JWwqOE17/Z53Foaq/omdZiiGYxZk/MY5E01aHMb1FF3oTSjubgVboRqVdPfZDTFqGNfN1rvifp9JS6Kn56c5acpsnVIxmNDi9X2bx6AqVD2yQLh7sxqqaQRuWuF7QgDlZhFOo8WH8F5rOd X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1486e02d-06cf-49d6-6dc9-08d96983aa71 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:54:07.2547 (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: oV/GJxLWeGgpNh9QVYBXE18dZOYghzsOOfbwbqZEwgjeVPk72EO2T9qRr4BGj2WHQVSMKrXV8vG5+aNERcJsRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-ORIG-GUID: ejgUHTdBRW3rfwT6F144iETPYBkoI0pG X-Proofpoint-GUID: ejgUHTdBRW3rfwT6F144iETPYBkoI0pG 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Store and load the device's state during migration. use libvfio-user's handlers for this purpose Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- migration/savevm.h | 2 + hw/remote/vfio-user-obj.c | 313 ++++++++++++++++++++++++++++++++++++++++++++++ migration/savevm.c | 73 +++++++++++ 3 files changed, 388 insertions(+) diff --git a/migration/savevm.h b/migration/savevm.h index 6461342..8007064 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -67,5 +67,7 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks); +int qemu_remote_savevm(QEMUFile *f, DeviceState *dev); +int qemu_remote_loadvm(QEMUFile *f); #endif diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 92605ed..16cf515 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -45,6 +45,10 @@ #include "hw/boards.h" #include "hw/remote/iohub.h" #include "hw/remote/machine.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/global_state.h" +#include "block/block.h" #define TYPE_VFU_OBJECT "vfio-user" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -72,6 +76,33 @@ struct VfuObject { PCIDevice *pci_dev; int vfu_poll_fd; + + /* + * vfu_mig_buf holds the migration data. In the remote server, this + * buffer replaces the role of an IO channel which links the source + * and the destination. + * + * Whenever the client QEMU process initiates migration, the remote + * server gets notified via libvfio-user callbacks. The remote server + * sets up a QEMUFile object using this buffer as backend. The remote + * server passes this object to its migration subsystem, which slurps + * the VMSD of the device ('devid' above) referenced by this object + * and stores the VMSD in this buffer. + * + * The client subsequetly asks the remote server for any data that + * needs to be moved over to the destination via libvfio-user + * library's vfu_migration_callbacks_t callbacks. The remote hands + * over this buffer as data at this time. + * + * A reverse of this process happens at the destination. + */ + uint8_t *vfu_mig_buf; + + uint64_t vfu_mig_buf_size; + + uint64_t vfu_mig_buf_pending; + + QEMUFile *vfu_mig_file; }; static void vfu_object_set_socket(Object *obj, const char *str, Error **errp) @@ -96,6 +127,250 @@ static void vfu_object_set_devid(Object *obj, const char *str, Error **errp) trace_vfu_prop("devid", str); } +/** + * Migration helper functions + * + * vfu_mig_buf_read & vfu_mig_buf_write are used by QEMU's migration + * subsystem - qemu_remote_loadvm & qemu_remote_savevm. loadvm/savevm + * call these functions via QEMUFileOps to load/save the VMSD of a + * device into vfu_mig_buf + * + */ +static ssize_t vfu_mig_buf_read(void *opaque, uint8_t *buf, int64_t pos, + size_t size, Error **errp) +{ + VfuObject *o = opaque; + + if (pos > o->vfu_mig_buf_size) { + size = 0; + } else if ((pos + size) > o->vfu_mig_buf_size) { + size = o->vfu_mig_buf_size; + } + + memcpy(buf, (o->vfu_mig_buf + pos), size); + + o->vfu_mig_buf_size -= size; + + return size; +} + +static ssize_t vfu_mig_buf_write(void *opaque, struct iovec *iov, int iovcnt, + int64_t pos, Error **errp) +{ + VfuObject *o = opaque; + uint64_t end = pos + iov_size(iov, iovcnt); + int i; + + if (end > o->vfu_mig_buf_size) { + o->vfu_mig_buf = g_realloc(o->vfu_mig_buf, end); + } + + for (i = 0; i < iovcnt; i++) { + memcpy((o->vfu_mig_buf + o->vfu_mig_buf_size), iov[i].iov_base, + iov[i].iov_len); + o->vfu_mig_buf_size += iov[i].iov_len; + o->vfu_mig_buf_pending += iov[i].iov_len; + } + + return iov_size(iov, iovcnt); +} + +static int vfu_mig_buf_shutdown(void *opaque, bool rd, bool wr, Error **errp) +{ + VfuObject *o = opaque; + + o->vfu_mig_buf_size = 0; + + g_free(o->vfu_mig_buf); + + return 0; +} + +static const QEMUFileOps vfu_mig_fops_save = { + .writev_buffer = vfu_mig_buf_write, + .shut_down = vfu_mig_buf_shutdown, +}; + +static const QEMUFileOps vfu_mig_fops_load = { + .get_buffer = vfu_mig_buf_read, + .shut_down = vfu_mig_buf_shutdown, +}; + +/** + * handlers for vfu_migration_callbacks_t + * + * The libvfio-user library accesses these handlers to drive the migration + * at the remote end, and also to transport the data stored in vfu_mig_buf + * + */ +static void vfu_mig_state_precopy(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + int ret; + + if (!o->vfu_mig_file) { + o->vfu_mig_file = qemu_fopen_ops(o, &vfu_mig_fops_save, false); + } + + ret = qemu_remote_savevm(o->vfu_mig_file, DEVICE(o->pci_dev)); + if (ret) { + qemu_file_shutdown(o->vfu_mig_file); + return; + } + + qemu_fflush(o->vfu_mig_file); +} + +static void vfu_mig_state_running(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(OBJECT(o)); + static int migrated_devs; + Error *local_err = NULL; + int ret; + + ret = qemu_remote_loadvm(o->vfu_mig_file); + if (ret) { + error_setg(&error_abort, "vfu: failed to restore device state"); + return; + } + + if (++migrated_devs == k->nr_devs) { + bdrv_invalidate_cache_all(&local_err); + if (local_err) { + error_report_err(local_err); + return; + } + + vm_start(); + } +} + +static void vfu_mig_state_stop(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(OBJECT(o)); + static int migrated_devs; + + /** + * note: calling bdrv_inactivate_all() is not the best approach. + * + * Ideally, we would identify the block devices (if any) indirectly + * linked (such as via a scs-hd device) to each of the migrated devices, + * and inactivate them individually. This is essential while operating + * the server in a storage daemon mode, with devices from different VMs. + * + * However, we currently don't have this capability. As such, we need to + * inactivate all devices at the same time when migration is completed. + */ + if (++migrated_devs == k->nr_devs) { + bdrv_inactivate_all(); + } +} + +static int vfu_mig_transition(vfu_ctx_t *vfu_ctx, vfu_migr_state_t state) +{ + switch (state) { + case VFU_MIGR_STATE_RESUME: + case VFU_MIGR_STATE_STOP_AND_COPY: + break; + case VFU_MIGR_STATE_STOP: + vfu_mig_state_stop(vfu_ctx); + break; + case VFU_MIGR_STATE_PRE_COPY: + vfu_mig_state_precopy(vfu_ctx); + break; + case VFU_MIGR_STATE_RUNNING: + if (!runstate_is_running()) { + vfu_mig_state_running(vfu_ctx); + } + break; + default: + warn_report("vfu: Unknown migration state %d", state); + } + + return 0; +} + +static uint64_t vfu_mig_get_pending_bytes(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + return o->vfu_mig_buf_pending; +} + +static int vfu_mig_prepare_data(vfu_ctx_t *vfu_ctx, uint64_t *offset, + uint64_t *size) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (offset) { + *offset = 0; + } + + if (size) { + *size = o->vfu_mig_buf_size; + } + + return 0; +} + +static ssize_t vfu_mig_read_data(vfu_ctx_t *vfu_ctx, void *buf, + uint64_t size, uint64_t offset) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (offset > o->vfu_mig_buf_size) { + return -1; + } + + if ((offset + size) > o->vfu_mig_buf_size) { + warn_report("vfu: buffer overflow - check pending_bytes"); + size = o->vfu_mig_buf_size - offset; + } + + memcpy(buf, (o->vfu_mig_buf + offset), size); + + o->vfu_mig_buf_pending -= size; + + return size; +} + +static ssize_t vfu_mig_write_data(vfu_ctx_t *vfu_ctx, void *data, + uint64_t size, uint64_t offset) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + uint64_t end = offset + size; + + if (end > o->vfu_mig_buf_size) { + o->vfu_mig_buf = g_realloc(o->vfu_mig_buf, end); + o->vfu_mig_buf_size = end; + } + + memcpy((o->vfu_mig_buf + offset), data, size); + + if (!o->vfu_mig_file) { + o->vfu_mig_file = qemu_fopen_ops(o, &vfu_mig_fops_load, false); + } + + return size; +} + +static int vfu_mig_data_written(vfu_ctx_t *vfu_ctx, uint64_t count) +{ + return 0; +} + +static const vfu_migration_callbacks_t vfu_mig_cbs = { + .version = VFU_MIGR_CALLBACKS_VERS, + .transition = &vfu_mig_transition, + .get_pending_bytes = &vfu_mig_get_pending_bytes, + .prepare_data = &vfu_mig_prepare_data, + .read_data = &vfu_mig_read_data, + .data_written = &vfu_mig_data_written, + .write_data = &vfu_mig_write_data, +}; + static void vfu_object_ctx_run(void *opaque) { VfuObject *o = opaque; @@ -340,6 +615,7 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); DeviceState *dev = NULL; + size_t migr_area_size; QemuThread thread; int ret; @@ -401,6 +677,35 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + /* + * TODO: The 0x20000 number used below is a temporary. We are working on + * a cleaner fix for this. + * + * The libvfio-user library assumes that the remote knows the size of + * the data to be migrated at boot time, but that is not the case with + * VMSDs, as it can contain a variable-size buffer. 0x20000 is used + * as a sufficiently large buffer to demonstrate migration, but that + * cannot be used as a solution. + * + */ + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_MIGR_REGION_IDX, + 0x20000, NULL, + VFU_REGION_FLAG_RW, NULL, 0, -1, 0); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to register migration BAR %s- %s", + o->devid, strerror(errno)); + return; + } + + migr_area_size = vfu_get_migr_register_area_size(); + ret = vfu_setup_device_migration_callbacks(o->vfu_ctx, &vfu_mig_cbs, + migr_area_size); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup migration %s- %s", + o->devid, strerror(errno)); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", @@ -435,6 +740,14 @@ static void vfu_object_init(Object *obj) qemu_add_machine_init_done_notifier(&o->machine_done); o->vfu_poll_fd = -1; + + o->vfu_mig_file = NULL; + + o->vfu_mig_buf = NULL; + + o->vfu_mig_buf_size = 0; + + o->vfu_mig_buf_pending = 0; } static void vfu_object_finalize(Object *obj) diff --git a/migration/savevm.c b/migration/savevm.c index 7b7b64b..341fde7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1604,6 +1604,49 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp) return ret; } +static SaveStateEntry *find_se_from_dev(DeviceState *dev) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->opaque == dev) { + return se; + } + } + + return NULL; +} + +int qemu_remote_savevm(QEMUFile *f, DeviceState *dev) +{ + SaveStateEntry *se; + int ret = 0; + + se = find_se_from_dev(dev); + if (!se) { + return -ENODEV; + } + + if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) { + return ret; + } + + save_section_header(f, se, QEMU_VM_SECTION_FULL); + + ret = vmstate_save(f, se, NULL); + if (ret) { + qemu_file_set_error(f, ret); + return ret; + } + + save_section_footer(f, se); + + qemu_put_byte(f, QEMU_VM_EOF); + qemu_fflush(f); + + return 0; +} + void qemu_savevm_live_state(QEMUFile *f) { /* save QEMU_VM_SECTION_END section */ @@ -2444,6 +2487,36 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) return 0; } +int qemu_remote_loadvm(QEMUFile *f) +{ + uint8_t section_type; + int ret = 0; + + while (true) { + section_type = qemu_get_byte(f); + + ret = qemu_file_get_error(f); + if (ret) { + break; + } + + switch (section_type) { + case QEMU_VM_SECTION_FULL: + ret = qemu_loadvm_section_start_full(f, NULL); + if (ret < 0) { + break; + } + break; + case QEMU_VM_EOF: + return ret; + default: + return -EINVAL; + } + } + + return ret; +} + static int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) { From patchwork Fri Aug 27 17:53:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12462605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 203D3C432BE for ; Fri, 27 Aug 2021 17:56:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9F3AA60FC4 for ; Fri, 27 Aug 2021 17:56:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9F3AA60FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJg5J-0000LV-Rr for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 13:56:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3V-00060l-22 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:17 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:46650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJg3S-00071O-Qh for qemu-devel@nongnu.org; Fri, 27 Aug 2021 13:54:16 -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 17RGPUUa015226; Fri, 27 Aug 2021 17:54:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=qUxgYcymVUOcPkHKKIaA6/gzrd+qPRl0kJ3LRQgd/z8=; b=JSuWFFv9/LAYPK8nKLxXzwEG0DjANzXDfvb3JxoT5JyeTV0kyQr0j57SDuMTxmCs2Dpa HYmBdj6QYSb2itrjHdZJI2eMBhDYT7j/nzScQn8EAVlg//sD88drVhT/BRM6a1ssH6EE hZXmI2KA00RXO4FBBpr5C1n1XE2TErTLR7hAHTY45yPd3DahlS5+Ax/f/PPd/tVFRvgn dLrQa0bf0HlGftHXvkeF59FQi8BFfEPVb0c5n7uVmpTA1En96xup47tZ+UQJIPw3kVoe Qt39zFLIMXCoQ+4Ch48BT5jR3yNPd//PD4N9PnKms6UpQN8mbufH9wyIYrrOqq6gWknH 8w== 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 : mime-version; s=corp-2020-01-29; bh=qUxgYcymVUOcPkHKKIaA6/gzrd+qPRl0kJ3LRQgd/z8=; b=o+Js5pUaUS01lg/hrebT8pfCJPOpvsbDVo2FNuh3CMz0cUE1F5tjrDKBiLSYjnDoCXJs 7qkPoSerGGtID1WJu70IRVqh8dj2R9HqimYOJ6dTB9Q0dUmQcdiY7XsEJgeaf6TjFY8v GLMDEn5uRcCPWO2ZD+37VSSKSvd4Z8n4435ufVqB3oubLMbVYu+JgOXfpxtq9iDhdXQl 1qq8WiT9oyd3DX4oaGTY3M6smNT3/L6qGWr4iBvqMcbl2FcAQ0r2W/1sCOaLKRMn+ctF 0vHFFhRrJbYC8eYKD8qAOJqPRQYpXwLX0aPF1WvypON+pE4U06o5PwBqsGqaA4We4lXq dg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ap4ekvaag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:12 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17RHoCf9038016; Fri, 27 Aug 2021 17:54:11 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2040.outbound.protection.outlook.com [104.47.56.40]) by userp3030.oracle.com with ESMTP id 3ajpm53hh9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 17:54:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YBqpbQX06O8jkhRmztRmSF6+rXUSyy+AvguI2zz33T9IKEyrb/0efqo8FV1EaatYjRS128XUAbIiyJLJWtm7GdcVnV2d7VGiJoK6BAg5957wQf4RB88/eZirpReomNSma2tlXMPsynu8iL00VJ1g76beElTjOYRsRpc5tKab6NShslULFUP8L33V9gZhhWWqAy8uEX35lbNuHau0mmsDou+cHGQ1sTcHVqHLx16sRqTrLM2P3EUiVsBcp5iZaCJHU/wWdjq3YUDNkoMo/56AIIuS6BD5a9HJGyZOfjEcha/vK5uCkHvJMrqy6jAHG8DXS0VH36adZykThFSMmBNiZA== 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-SenderADCheck; bh=qUxgYcymVUOcPkHKKIaA6/gzrd+qPRl0kJ3LRQgd/z8=; b=e6Ra+6ByGcU1oJNv0bL+BVaVKxbOl8ZK4YtMlA0bU/4T45vSOiUV1PdTzFsUpZCctT/ngGx7ibnKAgJ89YD7R3bvDZzVGa5QYkGGkjGzm8NO8FE/nfXomSm9ois06GPGqye95g7+Ll2swR20bUig8rlBlnqdXS6JyNuPqR7qPJtbcXUhDDT1tF7J12aKsZNgFg228WD/66sqTDi6TD3GMQ9j6sEnTvmNbaClgq+lX7d+e1Z/bYC6P2SI4b1zR4J0Elc4XZJqhISHgCNlGcEoA3ZgtCWOwPg+IYCq96XmlGsuDxN3fepT7BqTLW94LL/QWjQ2wzfFDHySmtYY+wuBmg== 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=qUxgYcymVUOcPkHKKIaA6/gzrd+qPRl0kJ3LRQgd/z8=; b=uAV2/yeimzTX5khge7zFKwWvKvhglYx3RkVNIK6mSAJondMCwvd+CSL67Aiqu5G2X0swZWZr8jZzQMbpjB2SzpBzFpcjlWIN275eO6S0Mwg7AdebSQqfcsl+7vePjCpcygkmbyC/SaQgP8j9+jk+WFt3yusFiBlXiR5UZHKO1G0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Fri, 27 Aug 2021 17:54:10 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::282e:c371:7a10:b122%5]) with mapi id 15.20.4457.023; Fri, 27 Aug 2021 17:54:09 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH RFC server v2 11/11] vfio-user: acceptance test Date: Fri, 27 Aug 2021 13:53:30 -0400 Message-Id: <9bcb7b4cf45e2211913a57030aaf5809e3e381f7.1630084211.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.46) by BYAPR11CA0093.namprd11.prod.outlook.com (2603:10b6:a03:f4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20 via Frontend Transport; Fri, 27 Aug 2021 17:54:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 63341781-a479-40aa-c18d-08d96983abfe X-MS-TrafficTypeDiagnostic: BLAPR10MB4865: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UFbp+vuMr/CLNPPfnvojMS7HuJXYMAJDXFvUgbN55/tE+fhvUM33sLqfiGBwNjJflyZyLgyZb5F9sv7RP3aCLDVqDDK1YSI7mpDf+cQ96cJ9LaeRVNtQc3w5Tjp4mk7TYDDq0LFSy/90w75yy8BFO0TPOiku7cMzh5YrUpRgCnPxa4+7D3QS8VrxO/u2uDV0ZoJuYC0PgNJp0QVH859d+O+cvo8JcD4JryIZTNzDkpUVmAfzHJuPICJDU8jytURhFMPtvBE5vM1YJ6nkshIk0MhbQoz68NgaWI1ml/clDin4aZ8twS4bYmXcftUQHqkkNHcN6CMTuEl8orKusVRsxZuxigbxL499Hyi5Ohvm24LDZoaIYPiK6NAeqYip3WjE+MO0EQ96wLzOZgo39Xmqn6G5Yaxk/t/xzsiS+i2C/wqyGnxmL90eBvuW6+mh5ZxP8OmKBh+MK/AUzkCpW7KKiaLCCQOHrX1CNs1QXnwVUq7HSdptOLkELSxJpctPkLO7Hs2oMHjuYJpJh+DpAcKmigf7d2irzmey+V1qEDDLRH/zFtnhKC4cNmqI10cZUD72tKdUvdQf0Qt04/ov0QY+CraFqDjPgeYp6E6uP7evYCXfQF5ei/fHLbrUCDeXgtxT3fpJyA0s3z+1daKPlkm4/G4RiDLnWL4HhbgvUH24yBkiMA1pxPe8sL0+0rIRYGoX85lK+drstIHcqZPvNT67NMNfedmp7bERpZp2hZjyyj+CdtDHZyyCnqRSz9C0/qV5dZps7stZQyLyhDYL8ao4xQ== 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:(346002)(376002)(39860400002)(366004)(136003)(396003)(2906002)(186003)(2616005)(8936002)(26005)(8676002)(38100700002)(36756003)(52116002)(7696005)(83380400001)(107886003)(478600001)(38350700002)(956004)(7416002)(6486002)(4326008)(6666004)(66946007)(5660300002)(66556008)(66476007)(316002)(6916009)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d/B8pOkN7bEt8J0RemMAuxACsKldFJJw7SCbfXbRrzRYz6apnNRZSXkIDkxN2Ues//MGEXMzpWxUYiWZ7qlDkwXhKEXndVt/+cSnmTKd2Ja41ZkRsP/VGeUA5gGK8PfCk8k9yoiuchB0XMe5sLr/HRB0NbKbr2EHyY30ANEX0MvFQSL4IfwstrkIS3RimROimRFIBQJUNoxlm/pltGQ34Jb5m3P3G59k129WFBUMCyVAupZEvh3Sm++EGn0RnQJ/E80nL9BjCHZpdhFjsYSYSvzurzrsw6QTSRCfXcy3lpDm79CgijG75Cp0r2cjQQdePzPACC012iPuv4NJxeAtFhTpV5RAS6MwTNmiNFSG+2HftkiyyGhELySGAo5sJ8ul9Lc3Q1KLY4uQK89Yyfv1aMJ49lzRSeOmQuwUI4Oukpss4A01J9v2+BkbJv3b1gMFTmE4q9jCNg6prGBwmrc4F9kEG3hWy75dbWYqWrG40uCWGdStgpAUt6AQInh4taaozERY05InjWIYxXSnvIy1pBFHLTD8wJzdthjQhhQgHRHTYX+stZnDTN/MNNu7MPYv234lpsDiS8RIcVqXHzZDZO73eEX3w8l9CATUSDZO/9ahUc7Gn/zK6m5M2V51JrUOVwojz9yX0kmnR4A03cY5P5jSDh7AR0s/ePsDfxyCWxV1zkBRrLBFD8k/5NFam62XS+5w1mWVTs7gU9p3p4H6B6IJXLusaoudYs1vYidIQBFWrosCg4f/EgbLPEUl7xlYI9sJ8Q3WdgVshUW1Erjs93n1KnFKBhUueAopzvzvDXIMSvsSuYZjr+jkCjhEAwY2bqNZv31tP+85/HVhGmtQ+2T10U0K0uLuM1gzFeBUqUZjC/W/K8KkKdGWM1WqWByYyzT/nWMB8d0Becrzy5I2V9MfJo04tkC4TKzNcl5SpUT9Ux8RWTGoIszBJikBL0uEuIBKnvGAJmtqn1IMCzzwIh19RbZ0jY6gWzs05M3bLcat9zXoEx8aQENH7+nxj0uJZpiSCI18xIpAGY2coe/15/M2vcWGNNtsOoB7WnqEGNM3OsjCwcTgT0rwNHlbcGqrkvvun3j7OYrRsckM7hZwssDp+wQp6SQxrja8PHqPfBk7zAOXSEcYerRVTBUJ2BEOoc5eOkhr/zXBHdqCVoh5HmyyBaIYIlqhSW4O70aeARrwpyldCVK5q2Dr3ATlEIfBGxzsj2obnNizt60I//gJBFrZHCVqw+TDreHz1adatp3laehN6tl0ReWRxrB2f0vEcP3S+atGnQ5NZPXLuwANFvw0jNwbZzB3Y9/o77c2LqLp6v022aoJ/tJ1YjDMyr3W X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63341781-a479-40aa-c18d-08d96983abfe X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 17:54:09.8387 (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: iSZaIItIolrpWlnDlxG8KdjW26AVL0VCtizA4iGK+DS7w7aP7/NyWQElcOE7e69SkXru5aPiR+HPzNu94q3nFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10089 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270105 X-Proofpoint-GUID: Ugr96GCJob9b8ZQwbd6p9azTH4LyYCfv X-Proofpoint-ORIG-GUID: Ugr96GCJob9b8ZQwbd6p9azTH4LyYCfv 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Acceptance test for libvfio-user in QEMU Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- MAINTAINERS | 1 + tests/acceptance/vfio-user.py | 94 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/acceptance/vfio-user.py diff --git a/MAINTAINERS b/MAINTAINERS index f9d8092..2c7332b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3392,6 +3392,7 @@ F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: hw/remote/vfio-user-obj.c +F: tests/acceptance/vfio-user.py EBPF: M: Jason Wang diff --git a/tests/acceptance/vfio-user.py b/tests/acceptance/vfio-user.py new file mode 100644 index 0000000..ef318d9 --- /dev/null +++ b/tests/acceptance/vfio-user.py @@ -0,0 +1,94 @@ +# 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 Test +from avocado_qemu import wait_for_console_pattern +from avocado_qemu import exec_command +from avocado_qemu import exec_command_and_wait_for_pattern + +class VfioUser(Test): + """ + :avocado: tags=vfiouser + """ + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + + def do_test(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + """Main test method""" + 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) + + # Create remote process + remote_vm = self.get_vm() + remote_vm.add_args('-machine', 'x-remote') + remote_vm.add_args('-nodefaults') + remote_vm.add_args('-device', 'lsi53c895a,id=lsi1') + remote_vm.add_args('-object', 'vfio-user,id=vfioobj1,' + 'devid=lsi1,socket='+socket) + remote_vm.launch() + + # Create proxy process + self.vm.set_console() + self.vm.add_args('-machine', machine_type) + self.vm.add_args('-accel', 'kvm') + self.vm.add_args('-cpu', 'host') + self.vm.add_args('-object', + 'memory-backend-memfd,id=sysmem-file,size=2G') + self.vm.add_args('--numa', 'node,memdev=sysmem-file') + self.vm.add_args('-m', '2048') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line) + self.vm.add_args('-device', + 'vfio-user-pci,' + 'socket='+socket) + self.vm.launch() + wait_for_console_pattern(self, 'as init process', + 'Kernel panic - not syncing') + exec_command(self, 'mount -t sysfs sysfs /sys') + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/*/uevent', + 'PCI_ID=1000:0012') + + def test_multiprocess_x86_64(self): + """ + :avocado: tags=arch:x86_64 + """ + 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(kernel_url, initrd_url, kernel_command_line, machine_type) + + def test_multiprocess_aarch64(self): + """ + :avocado: tags=arch:aarch64 + """ + 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(kernel_url, initrd_url, kernel_command_line, machine_type)