From patchwork Wed Jan 19 21:41:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E96BC433F5 for ; Wed, 19 Jan 2022 21:58:00 +0000 (UTC) Received: from localhost ([::1]:49090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIxq-0004pS-2n for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:57:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIiz-0007dD-46 for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:40 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:37766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIix-0007Hb-Bu for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:36 -0500 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 20JJi5UW001468; Wed, 19 Jan 2022 21:42:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=fAFlWpcE2nyIkXGevE7oHLBXcSi1tOL15jqnjKomxyM=; b=TINrm4zOIzO1btZ36J//PDS13z0sgCQongB62eSleNVXVrXhfoAqjhiblGwJlchB+2EF vybeoM2r3/oxmMiDr1Kkpft9DfxZpVCU5XpoOpZRgRjlKR+v3YDeoQh8Ppr6OpY2zfDO odmH52d1jEtxKYxWn37fQznfoW9TZ5yzwj6pNaq19JfRTJHkoxUVuBwn+UpXCodJnC2N e33IKhe3drkHTTseLb15PjA7Y6rW+qXj981T0FDU+IX/8Hx6Z3xq2F89Hq6GwasdOKVh +lzneeet2VCI9RRX3wCMx2qPZx6XohK+G2jea2DetKv0ZVZBvgy/BKlAMbxplaiRSJYH Vw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc5f6ba0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:24 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLauFt147093; Wed, 19 Jan 2022 21:42:23 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by aserp3030.oracle.com with ESMTP id 3dkmaeb67q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fjOh/LZpzbcev+WvuG5SvfyLoZ5hfVgAkwzbgop6yLY8ujhKOtwhjpGzIdnq2aa5zoStbQlgz59am4oLKoLeKwgrAqXmxYYH5nRwPT50xPzsaeezwKCun+7f+634QD51nYUcjjdanWpW6HeYyuqeYj12n7Hh9eLNhUsiC0QLF9P1lwSFybGL/03WKiEbNNpJeYyilvH+W4hYnZoKlaOviyZlD8vNE3Py6s03h5JHJLpJ4i2Qzo4LqN+W+ltxCDFjJ6oFU0axmFK/geyiZi0kFMxu+fV7+87yAShWK2M+gSwgNmm8bb3bvGVXowdPjKd2EEDWr4QsFP8mzoZ70xh+EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fAFlWpcE2nyIkXGevE7oHLBXcSi1tOL15jqnjKomxyM=; b=DWTM655rD0eqREbdivSgZega1wSgQvzny1zsuiFTCDg44liFt+OzPdFWbUSzcUHF4j9ko/CisQNGGTh6kfl3/zHV2OPqKz2b7Es419Jm9R/pum4TqxCBtlxWmiODxXlC0YCKe9ZRBaEJda+kyEoNBFK5a4dzAETe9gI+Imj/WX9gA4lIBziHcUOCdVJbVu82kwz1T8+4kQ5xKfZ+YR5z8H2DoelkEg1kkw7MbltJMFRqD7XmzSw8jsgdkJkIUe9mbZSLVjZISGg2jLwwk6+dxpaxPi34BcjqG1eAiQLhu4M9NeWIh4UF+64pJnhWMaPkeRwpWOaHo3CaqNN0m5g1fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=fAFlWpcE2nyIkXGevE7oHLBXcSi1tOL15jqnjKomxyM=; b=BvlTXO+OnJBVyLr8RvOz4O69HQFHJQGueAqBfVMUI8sIdo5otvdp/FkylL5NCMtiM4pqWC8OyN1nde92K8JbuOvcFxNbWJBurZShWd8JhGc6ORGneQposlKmsnbMM3hYIC08hOx7ta54ITaGLqKirXMsOG7BK5XnfGg0Po1Oq4Q= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:20 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:20 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 01/18] configure, meson: override C compiler for cmake Date: Wed, 19 Jan 2022 16:41:50 -0500 Message-Id: <139b14d9db775e4fc8755f9974c0b5d593a14d3b.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 987f94f5-2960-43d5-3c00-08d9db94921e X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6iQ0ApmeU2ZTho/4dGgmrL+FvFSfYV8NIH+c0qieGAUXSCjf6kbuNMbB3ArafU8Y/jK+0o7hwQxAQfbuoQnGUNq5T7+WaW/kfOuzCDTpY6nsM8861PuCZrA46v4C6SK+7qqz+euKVPp6ZIsm7UarAIU4+Q/AiX0FHodkisYlgXl3wtO8aDGgmMMlcPHXInI3KGEY2JEMP6bpcdFkdyujTYzLnWyCahgqF8CUvKcn5Lh1FK9hxA9SxBBGMlISGWSOMB7iNhTtzJEWRMa9oODUJDT4vdp0uzOvUTKSRAhxBCTiKhKT8tpHJAqfOGPauQFPHD5CMYhZ7XbMnep+r4Hdt4EEyI8+h4wcLZJ9wK2fgssmEKll2dIQZor8NlwGza7n/gHmCNbb/EHKmt+MDVWtuuvE8josGDVHBBOint9WQYzRvPpdVp1x0KXe9U3FLy5INMwmq5C5hqaKgpl0ZLZJMww66EH4lkovV6MzfkZHUxl4I2dsbdvFrtDSibKKMlGP8Zjfg/d85NQRkpljiHMgkYaLnW59fjrhv9x3XN+tEEWcUKdV+lD2obfFO0gK4T3KQpSXDDzSm8SFWHJuHbGrJLtxgw36pSwjJ3mG0Qlr+h9PVw+XY0QElJqscqaSgNXuxTT5vo/8lLHcQ2+7yB00v5VTUTR9VBB5ULVdjjRDudpW+u63jC299RIvpwSlvZd9fD+LIh+FXXy5EFx8p/PaWg== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 00Zz+BKfCOKqcHfhPHDH1W6/1oRIU0Avkko3fNFgxhHp2kEPkEr4O+c9lUQOOHdR14ais1nTovq4C2YFETw1bOc7MFA18sbtAciwOJxFk1/Aey6orZSbFPSM+ZrHJBsXcnaO/edFhEvTEh95OFtV68zl0FvVwXP2uqbe3lTARL17lMhkxA7K3LWfdr5fTBPzrW2my5SUBnmV8Ds55SeUEn1t5rKBnek7P2CF4YJbP8QHmjZjuGuXjqpQRqbaViNHvxC/mZYEowmJszCFu9zWHdNGhJM0DaVUC3xubYs2NVzIo/BgppiajFOUbEDH7wvqyRa3mJj3a/RwI5z9J0htXNEX1l3dmzQMeWAUKD8ME32DwBDxNXl2lpVE1LmjnsE1ixBBiLaX+e+dE04/7FqdeTwKRGFCegAeT651mLC5fNCVic8G1zUh3e1kZdUelAxBqHF8nqXExipqz/g7T8K/yrPoK4UXYKg+46TGW8RlqQUP6jN/8rghLllhWaYW5tHOGcN/duBIxGyiXL6rhEembGp6Rx3Pyn3Pj3Rd47g2r7LKV6qXIfl7fXI2Ce2pBtSGdovu9L9KM05n1gPEevklc/VV5hH/19yppLxIdc+d5CLtVDXw18F2QIAaKiZ/8gw/5Pr21ZL7JMtH5bRwr7tmnzNzEYHjdsQ5WmRV6CgUkXxiC/dPekESt5AAW3zZ7OylrNeRIqw3w7Fg44LMj0v4HV3bbnMubP6RiibpjDB6l2T/FajoDjhWZPJDHgUS7PUOjWRBMbz0sHyPK6Ppl9Nk1m65NiDsAdX0zcJ+NSyEqqeURJG4Rfx0MSLK1UXrucUmq++vaZ4TUT4CTJ1ShDKxbjMN4OaKSfq72O2CxmyJbFo8D4/pz7VMjlwfX2jbt64WVfwbdjxjgI1gDcPSqolWWX+VsQ4X9S/GWvV5a4kKW2PryoxYnzxIyf7EBEggcQqsXp+l7E5+MpJJeC/Q3yJR/2KrmcHNJ175rKnlC9JiKyiN50So3+7yCD9a0YoNSEtxjFXZ6JgRLpucMuXvZn0MddnECDoiCTg6O2TeeOKY1qJ977SGlpVp4QwV5/oPdw2Y80xwJLOTIl6W8kmkP9GUhW7SDUt/6RZZsGY1i9ggTaTquOw7wAjKfFjW6WWFbyXK9oAQ1rK6VyJWLPWBaVZaPH1AE+rjXnpgquqzAU9eP/j9L3EF8sJ1oYFKvDtPRWuFRfYqiX00SnxJjSovXYQUvFrrZJ3Oz7YDkhmCIwxP+OoJcAwVUMncGYDh27u0+fQahl4XlvXa/oHbFtre/9rsnry2mfOW5TR/6IOSjI3zMOlZGuCFrA7aSf8BSsp9OFMQqBdw5KIKe7t+YzFV3nQsj5B1UtnLBAqOJbD4uPP7S8I7EZU7diB75iV/5wmZ3BdWjsWFuWvxuWwyKz+Qgwg8xUSp8ELFsx+9RifS+n/IxBXlFGO4cS6Il9yqNDb3dNWrcrtBGD2OKRMLS/AHdP6wCNQaC698hNhGTesC37Z6CvedqxL5boOQJBI5YEsBzvgZ6ig/f6670Sfleskt0vNFyK8nQ3k81N7vYaSV6g3JiKlJajR6JsrWKERC3K5AQnKPNvtw+ouaZ0bC+ZTzibYxOacAmPAgJ0r/0SpEr0eXtE8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 987f94f5-2960-43d5-3c00-08d9db94921e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:20.5858 (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: atLTYwWMyMQoi+3hKcVpvQAKWheWzCenRE6XY5uDVgvNAuv1pZCdYm/Cb65GqZWMH5P023Ci4ovr/66sUJutwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: O9RiVqgkV9lWiCk6IDnOyTn8X2r4nmH3 X-Proofpoint-ORIG-GUID: O9RiVqgkV9lWiCk6IDnOyTn8X2r4nmH3 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The compiler path that cmake gets from meson is corrupted. It results in the following error: | -- The C compiler identification is unknown | CMake Error at CMakeLists.txt:35 (project): | The CMAKE_C_COMPILER: | /opt/rh/devtoolset-9/root/bin/cc;-m64;-mcx16 | is not a full path to an existing compiler tool. Explicitly specify the C compiler for cmake to avoid this error Signed-off-by: Jagannathan Raman Acked-by: Paolo Bonzini --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index e1a31fb332..6a865f8713 100755 --- a/configure +++ b/configure @@ -3747,6 +3747,8 @@ if test "$skip_meson" = no; then echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross + echo "[cmake]" >> $cross + echo "CMAKE_C_COMPILER = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross echo "[binaries]" >> $cross echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross From patchwork Wed Jan 19 21:41:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF991C433F5 for ; Wed, 19 Jan 2022 21:49:38 +0000 (UTC) Received: from localhost ([::1]:34656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIpl-0002kX-Gm for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:49:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIix-0007dB-OM for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:38 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:38830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIiu-0007H1-Qi for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:35 -0500 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 20JJVgQK032608; Wed, 19 Jan 2022 21:42:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=HWg+Q6DRDHpWeu1f+ihlBCPxhS4LJGsT89Hfars5N80=; b=p2u67HwhVkJNaEQ+uZLSvuCmHeHo9JHV7fDhoRvqutB2GRr8P8y25tSu0LG4kfsmyF0e Q3MWAGFISy7RXUTQLXrNF6OxmaFXrRgNtZrQrhnBaFRe68w/57DCK9G/zDyQKS24ELWs rDBvyJPx/7k8rFFqQCbbYRR1i92NbMe3z3aw6Wg3FJghIZBZvSsRpDGmpadL37M4yN8h uaY9rIii0ToFY5IiTxX7WDM1ZuijqpDw3LMn795t+A21L2cLVDIEZKZhNfXtk8zsc0Vm LNhfe1AEBnEJkFqyR4G6ec0eT9Bs98A0tka0FZQ5ejI4tUNuK9tIPGYuAj9KrXh2NjiG rQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:28 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaSi8030907; Wed, 19 Jan 2022 21:42:26 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by aserp3020.oracle.com with ESMTP id 3dkp36kes3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZqAq7DRxf0IvChjbni2IotuwWiH6CKGwBdMHf2bL8nBVPCwViL9JMfb9mmyNGpyReoMUMQkmUljUW3Z/TYcPYUk4BUyPFfkEwLLvFHGbE9VYF1pR4WTbDHOq9nZNH4j+MdgEPj6UsMJGxx16yt3JyN8IZSmAQcKwB9nWrPU+6xCKRQHllHeToAI/r3DmcIUXf0Akx9T4Dz123IRBu8reifJYRWMZw/2N8uVhoYv39GVZxVYtxowt0cuEUEktf5lJIDEaMIABhPFmqTLDO4Im8hucNmp0rlsuuJE+L2z4MRvbTqcuB8D7ZuRUo6x4YOI6mIcWhMXbVj+akY1L+HBl1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HWg+Q6DRDHpWeu1f+ihlBCPxhS4LJGsT89Hfars5N80=; b=PPwgt3tckSywLjH+AzOpboyF7Z3gu2uuhduQVLmuL9Bh5iJtjNVl2VZxEDV/JQ5yAJaDnJQkcrGNC8xKflFx6GCLW8KoR0hrwXsWHvgfeAQbiiblAxl5Xcplju9LthZtnA0HGbVtBa7Wd6sUiA4xHJZ2mYY0HKvalVHxBOkNNy0njBPE0VXXM3C63lOZpvFdQjsbSC9IMy42/WAE47nRYhSfLQtCXMar0SA7R+AZONIO16vjBfCZRBfdfB1IdMHddXVaaGHKfm1AhpyPWYle1SM98V3304IkmbbYniUjuhyYZXXOYQJhWpwZEElJOXedY43/3lfequRw8PclV9MsYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=HWg+Q6DRDHpWeu1f+ihlBCPxhS4LJGsT89Hfars5N80=; b=Arp/qZxyh5yufhkPkiQEzbmiLCNcwrKTdEetSTa5+X2v0Bmk1yIrw+Jt/w9OBysM6OkYsNM3GiFFoMJXjNgLW6aSD6pxAtJbBvNty5qnAPenBAhsxvutq/E7upRMY3Bxe6sjYKNapbvssg3nR/fM8VLxbrin2bsWQ8YSlBNoL0Y= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:24 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:24 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 02/18] tests/avocado: Specify target VM argument to helper routines Date: Wed, 19 Jan 2022 16:41:51 -0500 Message-Id: <5ae7da5979b3f83bcf2ec620f5bbd7d4c15b5d80.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b0407d4-efde-45e0-7a2a-08d9db94944e X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A3+WL2G5XMQfih0986p1t5cvenODQdLKE2eXCdKgMLe5j1APXiKg4OjryufypHraR5tMVohKMAc+LtAT18NeRob5GQTSuXLDbwpHQzTgBEKt6a0dH4JwdBW9WETphg8OkGlhAZc5gLyOnMeK353Bmu4gps6UUvjrF/g056f6Hu2UsT6HUCGx5Q7qLBR+BeDXqY57OZuakEVfNB89YoHWrj1Q6ZMbU5Kg0EISayprKelCCzegCL/XhmM4EJ3d7GGrwEtrYxk3OGcQBXfHB8AdZ/Mi56nrWcOR5MT3JWfQ/N3m3GAqfuEDeWvyGYGF7bPKhCrn6ebraDIfW/eCqRN9FSfz6kp96NbzkOv2CMJ4bn7bc1n+ydtPnBlYODDgOU8c45Q7kuNCybo2wkMRRIGUx1GD2/89WNlpThRjm8vi1pO6malGR57NumBaifUcwWRkrSN42/hQX+yK2qkiHPh627p4mxHL+PHnvKxnZdnOLWx0CJMT5VhJzfs/cCXzj5LJ+jJMHljyX2knrGxzihR7eBymaIrsmQLq0SyxQZguHyzFXfgZqofL0rcTeOcY4y9KHx6X8SFAFaUJIK5sFCmTz+n33yL7eKa9T4A0l2EY1lNDrO9PSmXnwJPGvoFEldqJXBz1by74LgWRqiz3kvdONHLs/+HRGQIKXiHdOysocAOrN31nEn/XhPnPw9rsLccTydlVGxXWsDf1E2s8k8ww8g== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ulAdoDyV3jrEo0iJVsMC0dQ0nPCk?= =?utf-8?q?NRLIwDdw4b0cLrjPHZ/vUOw9y1Eu9qA/dwm972Zu7AxVCJhR2iT6nE7793fUUGBTF?= =?utf-8?q?WuLKCsEHchRziidnMGMfeUEXtlwOlRXhHExmI51z0r8BCdW4u3jmQ4NjmCQwaGgtp?= =?utf-8?q?cMUkdx5l4URERHmMpBCXak/QhRIPBnvUX3KPvDf2jG16m02BA/Iam4trqkoH69DGW?= =?utf-8?q?ddHvMRCsPYTO+nc7P6Xst/V8eCNbz2SMvOBjV/A5elsp7fs7tQl/ZPuHgZNDJj+rl?= =?utf-8?q?k3t31tRDsuNC8HNUh2LuqRxDa6AuXeV5js4wkBOEZfwzP73vXGNHM8qLE5g86//U8?= =?utf-8?q?mCjk64zuHFKYUXb8Su5qCt6p4uEu+8+XKRlZiuLzeFnFLIlFBDdjfaW9XHFcVBfpn?= =?utf-8?q?hx1cgxxLMyD5jB+A8MwHolgT+e/sO1yuPtv4gbLpkKpJ8UprCpWeuKlhIgQH9F+TW?= =?utf-8?q?uO0+jjfbw75plG1TtMgOQBpSdu0drzegORTrdvNeE1sSOSuawe+bI7LI7fQpjyq5G?= =?utf-8?q?pgNAd3MbehcAsOgDBjo7wj8R9OJ5DgZ1d7riybmtNeKv+vgCpsjtCUXp7g1MqjifT?= =?utf-8?q?KEmUVxvu91779O/v3+l9dMEeUecyALtym6hYBgQox+0PNR/QQcl9TzFbhUT2n2tHB?= =?utf-8?q?OMmP94sWUKIN234mhUAjqd3ueoTOqjktOHE8+Yn/wU6fI+wY3vE2BSHL+QXaUqUuQ?= =?utf-8?q?EkmCHRiOodCtywl8euntiIiYI0Vzh7PGb8WtEGq0Yp/78pVpl+ZHryZuAR5jcRlfk?= =?utf-8?q?0SG6yez7BjDo+bQhMsTxeECCvPc/vxgmnY/DpLnKHw/NvNg6eLcDlIlulc/C2bXuR?= =?utf-8?q?mt16ClQ0o14izRmWBUk391Y647DifO5ZvYotBc+Gc4SHvD8de5/hqMrelfSxMMXCQ?= =?utf-8?q?2lBfhJbTPdBIHE08e2yYEltrn2OH5Jsp1zFb2s+wJ8w5wpDeh6S1EJPuTXaSD4rK/?= =?utf-8?q?6rCWg9gf86ZyLSqU5kAIPxSTw/DnJFOqxMw/GwJZiGm+8cTZY6+2NPGrzOulBXL55?= =?utf-8?q?ScEsb40U83o95oKNTbvz1d0AsUskxmEY5vTLpiCEvXGpw2n5sFUItKHNrtpY1h6hP?= =?utf-8?q?aU1wbFwWLSC5DqWw7yU2PC2b0mfFc4vkRw60OFLFYP8DorfnbRTDTT6j2Shd2I46N?= =?utf-8?q?qL867xAPnL/5BJ/3kca7/B7xvs+2VmaD16X8hSZ1ZISiheGGUjqT7A2w+luuHcRo6?= =?utf-8?q?Ns9udqxAKFnzY3gqE6qTjf0ohfWGmCVsyQa+BK4S1qh/5QLa9O3rUo9sa8B3yhWyL?= =?utf-8?q?3RSAw7uLn6XeXtBfF43g2rnCesK/h/Wt59i0FEv7bINVd2A+yUxjA+IdALgR0Fzaz?= =?utf-8?q?AoF+A2t/mCD3NNhZntprHSSVD7mWSXZc6U0Pxjxb3HlX8QC5iBNHkwO8M41ZGg9Ww?= =?utf-8?q?0YiLsSj6BxF+RybyR4T+fhSmaYG2xo/eAZZnVWcJdRzs8kRh2cdZaVwZrkGDl56rY?= =?utf-8?q?/7Z0pJQ+eqSSgFTp3mBMDkgP0SoWz203xVrfq1E/PWHUQvUKV4Y/SnmZccKqxg1eD?= =?utf-8?q?Ic/8aRzWYLg+088UA2EA68rCQzaxHObE9GpZ/QCaeA4+XQteapDl1JY=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b0407d4-efde-45e0-7a2a-08d9db94944e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:24.0855 (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: SqBRqi1gPcpclyL05tzW5YZmrz/HKT4QNMwk6xV+fn1TnYvuU94YCQN836//2O/L3Rw0r+2iFYkEXY9Hk1WG0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: OMyOwzC6dadeVkEKGO4BU7H7IXWdNGeK X-Proofpoint-ORIG-GUID: OMyOwzC6dadeVkEKGO4BU7H7IXWdNGeK Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Specify target VM for exec_command and exec_command_and_wait_for_pattern routines Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Beraldo Leal Reviewed-by: Stefan Hajnoczi --- tests/avocado/avocado_qemu/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py index 75063c0c30..b3fbf77577 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -198,7 +198,7 @@ def wait_for_console_pattern(test, success_message, failure_message=None, """ _console_interaction(test, success_message, failure_message, None, vm=vm) -def exec_command(test, command): +def exec_command(test, command, vm=None): """ Send a command to a console (appending CRLF characters), while logging the content. @@ -207,11 +207,14 @@ def exec_command(test, command): :type test: :class:`avocado_qemu.QemuSystemTest` :param command: the command to send :type command: str + :param vm: target vm + :type vm: :class:`qemu.machine.QEMUMachine` """ - _console_interaction(test, None, None, command + '\r') + _console_interaction(test, None, None, command + '\r', vm=vm) def exec_command_and_wait_for_pattern(test, command, - success_message, failure_message=None): + success_message, failure_message=None, + vm=None): """ Send a command to a console (appending CRLF characters), then wait for success_message to appear on the console, while logging the. @@ -223,8 +226,11 @@ def exec_command_and_wait_for_pattern(test, command, :param command: the command to send :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails + :param vm: target vm + :type vm: :class:`qemu.machine.QEMUMachine` """ - _console_interaction(test, success_message, failure_message, command + '\r') + _console_interaction(test, success_message, failure_message, command + '\r', + vm=vm) class QemuBaseTest(avocado.Test): def _get_unique_tag_val(self, tag_name): From patchwork Wed Jan 19 21:41:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6438C433EF for ; Wed, 19 Jan 2022 21:53:23 +0000 (UTC) Received: from localhost ([::1]:40432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAItN-0006vR-3g for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:53:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIix-0007d8-6Y for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:38 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:43060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIiu-0007HI-SI for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:34 -0500 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 20JJPAPZ032601; Wed, 19 Jan 2022 21:42:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=wkG+6ip652Gy0UjBy4fRhuNnkoGqv/nHa6VG/6epRF0=; b=DmG2U3/Qb33W8LsM6mSDE3CfsXwaS+fxx/gA5q1OCeGrtxnNz/qlw4GH6qMDSEl7DyT3 x6IA1I49mvRxhD9zlHjZtiqlundUbFqr2re4uawzZhV9tqf5p0SevcWVHI5zD7HuNuGl Tvw7fTSnomroBAYLSsYcgZSok2o5xyEiC0X+aQ1g28mrlesGpVcP+UPYc5xdtEAhsK9Z 3cN2+LBqaGLd2FvUPBZSsIAVwwJk1kmKdQN09tiroRqSrw6oRSraAyyOYZjmPO5IlBkg rkyvmeXhpYgOkUVPzKNL/eiL42nJ1KyyN7Cdu+CxEDIfPtNzzlrknL7gQA9TqkTCN4ng /g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:30 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLa7vu131886; Wed, 19 Jan 2022 21:42:29 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by userp3020.oracle.com with ESMTP id 3dkqqr64m4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Umq1ds4lUoiO6Mexosaa0qvedAWEHV20CBZVqM9TpQWdlS9GyLD6TQFmZtgAOEL5qKGM1PjeYDl/ddDm23upa+wDf2mQ9wJk0KmAxgjv3idpMrHgapLFhIyFZA9AFjT25m0qQgfmHVibDnUkMpB8gX29lugqG5tVfX++pGKVthg+yuksyN68m+5CGKmlhTHQirrVah2+xt9rQIFyum6+qescCJbMZWpmW7EsNb4aTck+8Y6a93EATAu0GLboMEVA2SM1K+GWa/9L4/mXVLhrOnDL+k1iivWlZ5fOE0jIGbJluVx8mwLPw9b9jXWP+zH/QgB/zj+Bb48keiFMd7NZiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wkG+6ip652Gy0UjBy4fRhuNnkoGqv/nHa6VG/6epRF0=; b=H0a5v/BlLT6FugWTghNUzHmxxoxCoopNPXsZPrujOH73apsSvZK6pBDVt18pLfrIQ+sJ6xMM+L4Q4WK+aKUtHlofMyQMyckCbF/sK3E2pUAEsDcvOa/eeUC6ziuIs3nCTck/z3r54BOYyKTysA1nlrq/Ms8x05kbGy5Fh46kfvn38e1FUP2dObMY9KRz7EMiz/bhsSav7BxrFX1omDq8q6//2ErvKdkuu7p0obdAQ077BBY6gD21pq9aFJjJL9CN905rJhVtN4ORnTBWFzZPKI50vJ2VLKjQv5vrx/QcbnrWAdhdkOQnJuF7XTeA1gTlBxUi6XRmltee//JGRcuokA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=wkG+6ip652Gy0UjBy4fRhuNnkoGqv/nHa6VG/6epRF0=; b=WfYtr38w7RUSXIqM9EL8ctrI/6xAy48xHkWmXG0Bdw2td+3AUdsJgz8+l3wGlzghnnErk+NdwBmheb0X/TpL/jN35Xohws03QWl6cEg2eTNUFo0PPbGzQfMFHqCCZblr3LusLZvljlQjjKAM917jqbAriAnaNvln0idafs4SH/4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:27 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 03/18] pci: isolated address space for PCI bus Date: Wed, 19 Jan 2022 16:41:52 -0500 Message-Id: <2971c1bec04acaac4eb3c1f2b104cbeabad01e22.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6fd2cb20-11f3-49f7-7ee9-08d9db949664 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cubJmUI+rJOI3ABPZ1EMz14fUxJX8xfTYnynKMfkET+FacFZC0NExphgAZQS9QegRLHm4Zt5OCRL8M0sBJcAY5OcZXTY/06BO997o9M1lM1Q6pY1+jGsgYsywq7fVkaCOt1Be5pdEgugVrCSeWdP7XbkOYK2PbZoWf9kIL8mF1nmnLwhNoUyJMzC0OL6ha77zt1/4oxy/9Hyq210xQKTwu1+Y3Fuf8tGxw2Q69qGOa04mlAk1wzpk7HvgBzJtzRxMQrQU321S1+FuM4zyV2L4i7plVe6T4QH/uwefe3lOM64UMX8zGsDy3VDdvzh1nMwBnrBsh4ZiPChowy/7A90k9LZZ6tfXPLPADbm5NW9sZ+HbprkOUXLZ9/K97sRIrUeDmq9/l8BxaJI1DajxoYFblYVQdg0JRG27KWUfPqGGBN6IkYqnwDma7XSlFU/YIr2MDox6QQIdYX9aL4I/CWXLyLcCBZViuiksdhIY4Pd1Jpo+rgO7Evfq5RWItt+28r9mOvwLuTtRx+AGzTLuIVmVurJiAimd2eCPCgFVGcroiB7k3n6OWEtsF4kKGUUG+yKz2h5K5A0XlgHWiSqANO+gXyPqI93dKRHQvmqIZE4VmvTRIIaOvGAUlM+nik4ElbN732sH7m9BNlZnA2FdK4N/y8FE63uoTAnIh9zhY7c5PHbQqa58rZdFD92jTKTzRE8bw11Pgabrc4WAICsrSOJQw== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NWOCXr6VmiuZoReWF/47uTG96DRbDXrcMF0XSg6M9pfVohIWphN3Av7u7TLuGKxJALsx4DFNbSZRXSY8/gy5Xbd/ZEmHMFNjTMGPgHpa6yK60CeTD6F3mjovkXxPQbd355Z7RSRTAFp5ehDHYXNtRWmU/hC2+dM6Nb2rc/BiHIS7dhwjvtYM15ChN39fDLbN+X9h991CkejnSsYc/rgmCg0550TRAGR3zx1YatelhBrm8+xcwNCgS20XoDzwTs8Lv32CBnW/Dk/QHAzv+8ZbcENw4FkIjjzMSQfyon6Nt4G+vy8qlimrmh3E4s1OWtMeZzKnSA5UyhO0uuzvGzmFYWaAePcbcVXqjQL8+ueTduCWHOeTxoq2vQKexBc6VI3lYFnwzt6QsJ2exQF0YZOJqC4bhQ98p2ahXhpESY02JSkLCSf2Bks59yHxWwQW1f3cs8ZaVDQ4NR7zaKGAQ35NKPgqfnGZ2Ay75b8CTyMe975+emI7JlFAZQ4HOq3SJIBR/bjzdiy6vmru+yAJ5hI6/WJrMjYcXV78NSsj361zMoRqCPVzHYiJywwg1UF5zeELV1WErZTJJqsPYYbTVTXz2jqCRk2nkhXdAwV4Ro2lIZYQn4CpN8edt0HMWgZuWpansviauywj1nY8sk8QdUeexi/FBR6EuRsLdcOK+GhJBdpQqKhQXyBXqbwTbgm3pAeCutKbR2YdWAo72Y52zIHI0EO3lxPGIvzHja/J6/u72w1Xccbhn7dPYsHIblpPfa6mVEb67r+jkGAn40TPpdNAsij89Nc7CvD08JCO3AMMXITLjQBIBLdso93Y/oAEBJlC/DSKlQ6vwXrrS+HSaPeQ97sziEfq7tjKSpltl9iaGMJAooDzxvzz7tPWWDVqYQctIABTacXayThNuin3p2iyFecU+aw+PTw/HQnxYrFdaZF5uSM2FyHam5sC5ncZ/cxuMmTJjQA5canBRJdkvQYcJZUfbiX0hYA5QEJ4NSbl0YkpV7Pq7SPaVi5wVmBa+iVVWqmn2uKThkR8tK67hSXEqsnlou4S+QJtwI7jRt4/xziOqkARifUSTkG43SK4oWKGRzB6oBfOyw65b2QED9tKuUagtKQhaqEITwreR9DCf/AelevRY45J7BTMBUmhXWNbdzoSAGqL+YMDzPM1ILT5Dwa9yLnW7gjQAxe28/2OorsMiXlFRPcOda2d5DL8cAW8EAXaY22AoyFNa9UJUmR9oFTYbMIX/AFllf+/Hrguso4kjTar6Oe/bLnD60T5k8AHVIUPkHjghB2Ux+pASfmKVLNnMkBKFlB0cm/pu0fhIPb4xB2HGYn+eG4cMGC5U1z74P2Q2RVTABEBi1ey4lmVtC7+EC/tfGOfji1gVNfkYrenqtgQBVuLh8TiY6Tq0X0P4Pfu1gOGYy5coQAyPT0XceQl7XVH+FWT4y234qDW1j/AlgU2Aw26EIl8elpCvh6TEJ3ZQRfVsIC+GcrJGT3s9NVs+aI2T26gmcvi0rOqW0vwzUzDqMtYXuxX+PzmV9H+ZRQiGBENKfNOb25izv2HCY7CGf20udzPWu2te6nsCQxs/Tzgu/d0v4ixsIs6JHwE4PfWbFjI75iaVj1yZzWOHLkyEyDLVSJoUUtI0fCy0L4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fd2cb20-11f3-49f7-7ee9-08d9db949664 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:27.5384 (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: mjcXHM6snpg54ceTgh5e1RBjMSotCpCG+b8mn1Ea/3raiL44dQs+lZvxcFm+rEPTzFIDWz7WI9ZwUq1DGvBUtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: 0SHafPzeyxy7b5ORSLwHlC2BDHcQSyJT X-Proofpoint-ORIG-GUID: 0SHafPzeyxy7b5ORSLwHlC2BDHcQSyJT Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow PCI buses to be part of isolated CPU address spaces. This has a niche usage. TYPE_REMOTE_MACHINE allows multiple VMs to house their PCI devices in the same machine/server. This would cause address space collision as well as be a security vulnerability. Having separate address spaces for each PCI bus would solve this problem. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/pci/pci.h | 2 ++ include/hw/pci/pci_bus.h | 17 +++++++++++++++++ hw/pci/pci.c | 17 +++++++++++++++++ hw/pci/pci_bridge.c | 5 +++++ 4 files changed, 41 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 023abc0f79..9bb4472abc 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -387,6 +387,8 @@ void pci_device_save(PCIDevice *s, QEMUFile *f); int pci_device_load(PCIDevice *s, QEMUFile *f); MemoryRegion *pci_address_space(PCIDevice *dev); MemoryRegion *pci_address_space_io(PCIDevice *dev); +AddressSpace *pci_isol_as_mem(PCIDevice *dev); +AddressSpace *pci_isol_as_io(PCIDevice *dev); /* * Should not normally be used by devices. For use by sPAPR target diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index 347440d42c..d78258e79e 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -39,9 +39,26 @@ struct PCIBus { void *irq_opaque; PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX]; PCIDevice *parent_dev; + MemoryRegion *address_space_mem; MemoryRegion *address_space_io; + /** + * Isolated address spaces - these allow the PCI bus to be part + * of an isolated address space as opposed to the global + * address_space_memory & address_space_io. This allows the + * bus to be attached to CPUs from different machines. The + * following is not used used commonly. + * + * TYPE_REMOTE_MACHINE allows emulating devices from multiple + * VM clients, as such it needs the PCI buses in the same machine + * to be part of different CPU address spaces. The following is + * useful in that scenario. + * + */ + AddressSpace *isol_as_mem; + AddressSpace *isol_as_io; + QLIST_HEAD(, PCIBus) child; /* this will be replaced by qdev later */ QLIST_ENTRY(PCIBus) sibling;/* this will be replaced by qdev later */ diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 5d30f9ca60..d5f1c6c421 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -442,6 +442,8 @@ static void pci_root_bus_internal_init(PCIBus *bus, DeviceState *parent, bus->slot_reserved_mask = 0x0; bus->address_space_mem = address_space_mem; bus->address_space_io = address_space_io; + bus->isol_as_mem = NULL; + bus->isol_as_io = NULL; bus->flags |= PCI_BUS_IS_ROOT; /* host bridge */ @@ -2676,6 +2678,16 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev) return pci_get_bus(dev)->address_space_io; } +AddressSpace *pci_isol_as_mem(PCIDevice *dev) +{ + return pci_get_bus(dev)->isol_as_mem; +} + +AddressSpace *pci_isol_as_io(PCIDevice *dev) +{ + return pci_get_bus(dev)->isol_as_io; +} + static void pci_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); @@ -2699,6 +2711,7 @@ static void pci_device_class_base_init(ObjectClass *klass, void *data) AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) { + AddressSpace *iommu_as = NULL; PCIBus *bus = pci_get_bus(dev); PCIBus *iommu_bus = bus; uint8_t devfn = dev->devfn; @@ -2745,6 +2758,10 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) if (!pci_bus_bypass_iommu(bus) && iommu_bus && iommu_bus->iommu_fn) { return iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn); } + iommu_as = pci_isol_as_mem(dev); + if (iommu_as) { + return iommu_as; + } return &address_space_memory; } diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index da34c8ebcd..98366768d2 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -383,6 +383,11 @@ void pci_bridge_initfn(PCIDevice *dev, const char *typename) sec_bus->address_space_io = &br->address_space_io; memory_region_init(&br->address_space_io, OBJECT(br), "pci_bridge_io", 4 * GiB); + + /* This PCI bridge puts the sec_bus in its parent's address space */ + sec_bus->isol_as_mem = pci_isol_as_mem(dev); + sec_bus->isol_as_io = pci_isol_as_io(dev); + br->windows = pci_bridge_region_init(br); QLIST_INIT(&sec_bus->child); QLIST_INSERT_HEAD(&parent->child, sec_bus, sibling); From patchwork Wed Jan 19 21:41:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47B9BC433EF for ; Wed, 19 Jan 2022 22:02:40 +0000 (UTC) Received: from localhost ([::1]:57618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ2N-0002Yf-91 for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:02:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj3-0007eB-TG for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:42 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:49250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIiy-0007Hz-QE for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:39 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJU0LM031218; Wed, 19 Jan 2022 21:42:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=7GDmlaYvkS/vx5UBUB7NUvEFhcZLgp9qiCrYmHbnuzY=; b=DPofaA59G5u+fPCHkOJ4xzuTAafVe5y2oDz444UPXuvUEG3BX4jGLZWAFtFPZxTA8wOT 3LzNNSLoBSdkznpWHUVI/lfCZIOoy2oSscinILGbeeue406G5wVmwWUCT34iA6ed3MOe N2GNU+3eYmIyOizCWKskxF1oHFClPIVqM2LpgnBFweNdseXsZ5KQ2C8CR2pvrM/NILMq xYmmiS0fyDD/ha5dx+Il0dKD8RFW4BKDviD7zJPpJDe+NTOmEcMjHba/V8LYfj9uQSQ3 XEof65zEYG4U4giseleP6dMEgYRdfmLiOntq+50J5ex8CXyoARpwxaYg9g/Kcghm0sdO rA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgnw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:34 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLa7NZ131748; Wed, 19 Jan 2022 21:42:33 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by userp3020.oracle.com with ESMTP id 3dkqqr64pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iSx0QqUCThn05yGfhXlfYwi6nsW0MF1pGcnaW2NtpfZsO70B4XmIx2Hh4XnAHLen7tMu1avYFQd1PtlkXqbl4SRkjPyxZw4y4LK9Lr6q1+X/e6jiE06AQfGJE+ZpUc5J4f6PcWdnJvq04tX4b5uIKRQDIdQVDlXrrH2fIzvgIh/ZdsCGJ1i/0VnYlAeWmFW2OGUHBpq3hVMGKzxLW6CCdFvfA/n2PvjTk1GPXaOX+j3OyM+puAki6d2MEpt16XkdDGPTGA2Ri28fGyq4oDg3tV7cPFE99GVTUHGQClnI1nboZqEH3VLrh1IBZTwr1CLF/GkT7BynazU3Jp8w04UeJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7GDmlaYvkS/vx5UBUB7NUvEFhcZLgp9qiCrYmHbnuzY=; b=O2GjWxZMoQtz0uno9SX7TOyQpjkgY3k/W7ce9bUgFBZTu0pttIPGEq9zwcxUdBQkbZgbGxV0OY1V7loHUkXtRy0VjscQW1qhJ4+rZ7ulzoqga1Xhxm3IiZ5WzikEEndoM0V/0AuZIRJSRXSHF5SMOM1g/NfJ7NbtsOtyp4cfNimjS5ocsfN/4itIBy1sedgXPehe1G+k1/VDhV7SmS7RBCAciTUxpCsXPSgiKtOsjZ2WzP7R7wWMpksoHdSrPZYdZc/9l1wEvrgw7cIL14jBoAY+nnLtE947BObKHf6LKTCQdJGaOEaLlieUHKqhZoz8uuX6fpzeTXUa0Kmm8loRYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=7GDmlaYvkS/vx5UBUB7NUvEFhcZLgp9qiCrYmHbnuzY=; b=D8NC9YDdm+qqWqFcABASFDA4pw8SFSyqzFQZIkH7SS42q6WGDDUS+RlpvrUemGCucXcu4jd2hnmZ2OIL96ZLOBEBGW5WYl+Q8qINL2ToD6m3cHcUy1JNI3uKysfGTjSBuyKrhfe8f2jwIiz6D5qu3iWFYaS04P5Mz7YuwU7zI34= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:31 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:31 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 04/18] pci: create and free isolated PCI buses Date: Wed, 19 Jan 2022 16:41:53 -0500 Message-Id: <566b2ccf8a7a5ce2ccb21f66c988a0feee83ee8f.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe88294c-9492-40f3-5d8a-08d9db949873 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:110; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1iGpHrfMyumQYsgYps/DBDle3txeWsQGWQdGvjrLHp5msiWYZuKYdgWeFwpogbfwM8JRUHK8EM6+Kifm3nlMpVfw8ydh692u2axHO1ok0N3ME1QcAaNQ0+2YZRdsBFHErCb9YxSgWXyWcbJRrT4JPBmcDWCh2dl5yPRnXg/2dInywlGwGJRG1QJmI4LS8gdIXpOXi5cxksrgumMQQzIfFWbGZojFAtIPUZsTI8uNAuPVR1y/Atw6Ia8fH7l83QwnZC5W9Xk4m5I3khLUR1ywxi+7tpliF/rVJib16pWONe4G2Qu56e62hF/72TnfVC+b6UBQMm6B7ro1Sph71zMwM8KUzsarYckSwHpGGYkNCJZ1JE35MdJOIMhx+SZZpvsuMqOdtuGGkTTQcpNj4hDN/uP0sDkh4C9CifkdPd9HcoH707NwvHicRsBVe498gU1Luri3H4xmeG5HLifEnMlTkFjBix/Ztfv8Hn0l2Cv9BClQszcmTZFniu/iDke9x4pWVwFherdVfdHaApcMANlCbTCBD+FYzEGFPeX2hLpGB2Bfq9l4wNG7Jd1wMgnkzWovAvraxinCdO5HPNteI98qdZ9rP7oVS1zzLgf9rTLZq74CmqNXRznjoyK6710Ysc3Y7iNU+HqEpgCuuT281EecrIWLSiPTK3efobOpf5xhbL8U6UT61ufyj0hlhh8cKroDhuC4TYtR2lh45SXNitXzDA== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(30864003)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TOTe+wDKw1Xgiu9UsVNrRWgVM7n3EGRmYoJXjgAHRDpJMXhH2NHCQEf2wfnAXNFSzGODm4jFo12WRKeNwQmB/kPmBT0Njcw1eDTOLEw9F6Pn6Nrezd3NH02wNKx8IfuIqUIJf88rqpsC9IRgGJuMUH4bwdbOY9y/jBg6N5tW8KPL1xysWuRGVYvrki3kUy2+xFRoXnTdBgTkdCTu2STFgHb1LuGPbx/iKTpSh7Qa3zuWhTK1j31zAe3ExPqgvzlG0hERL0O4qEoYs3zOyKqbIJk1geYH3ktFJpL+TTEAGYa8D/qbEj6IjtSXcp3N6qFpcsJzfRdc3PmfxVlN7p2ehcuVejPP775RV6Nfu+N3ivwJ8V9Ilg3Pal2Vt9T7ghLciESfA2LW4JJh5CbHmf9ce8GvJfL17Bd8DFyJmfBir3KqARoN6+BJucykpoiZEkUmTKhUyunlfXTe3zwGFdXvWVCZkUTfIgjvZdoP8w/lBQpvuAWfDF980AfUUCAV8wa+GFYh7crACMctdDjxzuolvJyxKGo/i55Gn3ifutXEkzGn6E+lV8hT0RzKPTftTHPVypXSfW2zRb8s9dnMTU+xFIcJ6sV2n6IsGzQoVXdt0eukywgdD8rAYY1IticX7reQKXgxa8Fdo6aJs0NqBQQIY8Kn68Hf75KlGszwDGSgeMdTWNITLNN35jj6HGLwqGQaSbpMKW12IZyRVPibuWzVfsEB1+tUo2J/qa7GXvRDuQX24VjY7ZsMyFJaSTpf4Tp2443+N7saitvNNGbUsbeaA0xEaRIidz0ST3HHTCUkziYguauIn7b8b+EP/cPD2O0SddElPxDhDDhHuZQLMNJN2uSy0hyDRjkfpSJvV6+h//S17Sefk69Vk3CvpBS3ff8OnvDXGh8Xanphzuq4oRk8T8FW8fy/NCUM6kMDP9cLfgJF8mOJBcmNEg+bKC2nLeYlM6yMg6ot87R5kqtV9ikT/fQ/n4mU5OpKqhFSwAVGCgtteaYWR/saNvSxyG9Lnb+8+anh0y3EycoI9ioS7US+UcP2hgnpdrSEbo9SB587e3DZRiTH4CNPf8ZsFoy50QFIjX3cGKMsLwOIrDVljUNPGexwbRqH3GHHYfaYqJUAJkU3wo6IpxzSEyWnIQg2yMpTavNJ+FnBN+zt8Wzo9GTm5DhTJJ1yZ0m0XJTY+6uVLlrmmRD76xtSIh9KQQrqVLDqqc0N5BIGNv2vIK1mFHNGab9UuNh6w3FN4sNNz49E9ZDhhiQf5ElQGXz92RtmuXnBsXfqvvC27KzWydiMttUaAhb/LX6tC5OL9qPovLWtH5zjKESPRbkOSHXQUgggotKzS/DSEvXb2FmfO3q4jpQWnkxJbQppCijKlmRd8GiVjqsKvdwxzZp6Y9TGRiQJtM+vqz3sj9KlHUpJrIHlQln5Kdu4T9RV9Ni4hJ7be5qtAiKFaayxjhTb3AJkMjA0vmCKx1GQ4BR8/zUNGys3ER2hLsCfU9qBCDJC3pEZtFmW4yeMZJfzKN4tqXtjMcT1b/eelsRd+C4TC5DnnwsdmXlT4mLIedRTYZo5fuefeVBMU70OB8NGyEZmRXqlDds7GVjqGdr76EvpuEVUprluYNXWfQpwuSzO+dTQJrwZ8kvIiOs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe88294c-9492-40f3-5d8a-08d9db949873 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:31.0850 (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: 5EDyVqzzmkq8d4LwN3q+yHB5+0Qm8ITyaDAKuPQ7KjQU7UH04sUQxxGASFuT50vf74EZmpVCUYHfPxFs6pDeMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: 6rm0hcRbmW-ASFsLBcFcPl9hB_PZiU8L X-Proofpoint-ORIG-GUID: 6rm0hcRbmW-ASFsLBcFcPl9hB_PZiU8L Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds pci_isol_bus_new() and pci_isol_bus_free() functions to manage creation and destruction of isolated PCI buses. Also adds qdev_get_bus and qdev_put_bus callbacks to allow the choice of parent bus. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/pci/pci.h | 4 + include/hw/qdev-core.h | 16 ++++ hw/pci/pci.c | 169 +++++++++++++++++++++++++++++++++++++++++ softmmu/qdev-monitor.c | 39 +++++++++- 4 files changed, 225 insertions(+), 3 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 9bb4472abc..8c18f10d9d 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -452,6 +452,10 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, PCIDevice *pci_vga_init(PCIBus *bus); +PCIBus *pci_isol_bus_new(BusState *parent_bus, const char *new_bus_type, + Error **errp); +bool pci_isol_bus_free(PCIBus *pci_bus, Error **errp); + static inline PCIBus *pci_get_bus(const PCIDevice *dev) { return PCI_BUS(qdev_get_parent_bus(DEVICE(dev))); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..eed2983072 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -419,6 +419,20 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/** + * Find parent bus - these callbacks are used during device addition + * and deletion. + * + * During addition, if no parent bus is specified in the options, + * these callbacks provide a way to figure it out based on the + * bus type. If these callbacks are not defined, defaults to + * finding the parent bus starting from default system bus + */ +typedef bool (QDevGetBusFunc)(const char *type, BusState **bus, Error **errp); +typedef bool (QDevPutBusFunc)(BusState *bus, Error **errp); +bool qdev_set_bus_cbs(QDevGetBusFunc *get_bus, QDevPutBusFunc *put_bus, + Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * @@ -691,6 +705,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev); /*** BUS API. ***/ DeviceState *qdev_find_recursive(BusState *bus, const char *id); +BusState *qbus_find_recursive(BusState *bus, const char *name, + const char *bus_typename); /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn)(BusState *bus, void *opaque); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d5f1c6c421..63ec1e47b5 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -493,6 +493,175 @@ void pci_root_bus_cleanup(PCIBus *bus) qbus_unrealize(BUS(bus)); } +static void pci_bus_free_isol_mem(PCIBus *pci_bus) +{ + if (pci_bus->address_space_mem) { + memory_region_unref(pci_bus->address_space_mem); + pci_bus->address_space_mem = NULL; + } + + if (pci_bus->isol_as_mem) { + address_space_destroy(pci_bus->isol_as_mem); + pci_bus->isol_as_mem = NULL; + } + + if (pci_bus->address_space_io) { + memory_region_unref(pci_bus->address_space_io); + pci_bus->address_space_io = NULL; + } + + if (pci_bus->isol_as_io) { + address_space_destroy(pci_bus->isol_as_io); + pci_bus->isol_as_io = NULL; + } +} + +static void pci_bus_init_isol_mem(PCIBus *pci_bus, uint32_t unique_id) +{ + g_autofree char *mem_mr_name = NULL; + g_autofree char *mem_as_name = NULL; + g_autofree char *io_mr_name = NULL; + g_autofree char *io_as_name = NULL; + + if (!pci_bus) { + return; + } + + mem_mr_name = g_strdup_printf("mem-mr-%u", unique_id); + mem_as_name = g_strdup_printf("mem-as-%u", unique_id); + io_mr_name = g_strdup_printf("io-mr-%u", unique_id); + io_as_name = g_strdup_printf("io-as-%u", unique_id); + + pci_bus->address_space_mem = g_malloc0(sizeof(MemoryRegion)); + pci_bus->isol_as_mem = g_malloc0(sizeof(AddressSpace)); + memory_region_init(pci_bus->address_space_mem, NULL, + mem_mr_name, UINT64_MAX); + address_space_init(pci_bus->isol_as_mem, + pci_bus->address_space_mem, mem_as_name); + + pci_bus->address_space_io = g_malloc0(sizeof(MemoryRegion)); + pci_bus->isol_as_io = g_malloc0(sizeof(AddressSpace)); + memory_region_init(pci_bus->address_space_io, NULL, + io_mr_name, UINT64_MAX); + address_space_init(pci_bus->isol_as_io, + pci_bus->address_space_io, io_as_name); +} + +PCIBus *pci_isol_bus_new(BusState *parent_bus, const char *new_bus_type, + Error **errp) +{ + ERRP_GUARD(); + PCIBus *parent_pci_bus = NULL; + DeviceState *pcie_root_port = NULL; + g_autofree char *new_bus_name = NULL; + PCIBus *new_pci_bus = NULL; + HotplugHandler *hotplug_handler = NULL; + uint32_t devfn, slot; + + if (!parent_bus) { + error_setg(errp, "parent PCI bus not found"); + return NULL; + } + + if (!new_bus_type || + (strcmp(new_bus_type, TYPE_PCIE_BUS) && + strcmp(new_bus_type, TYPE_PCI_BUS))) { + error_setg(errp, "bus type must be %s or %s", TYPE_PCIE_BUS, + TYPE_PCI_BUS); + return NULL; + } + + if (!object_dynamic_cast(OBJECT(parent_bus), TYPE_PCI_BUS)) { + error_setg(errp, "Unsupported root bus type"); + return NULL; + } + + parent_pci_bus = PCI_BUS(parent_bus); + + /** + * Create TYPE_GEN_PCIE_ROOT_PORT device to interface parent and + * new buses. + */ + for (devfn = 0; devfn < (PCI_SLOT_MAX * PCI_FUNC_MAX); + devfn += PCI_FUNC_MAX) { + if (!parent_pci_bus->devices[devfn]) { + break; + } + } + if (devfn == (PCI_SLOT_MAX * PCI_FUNC_MAX)) { + error_setg(errp, "parent PCI slots full"); + return NULL; + } + + slot = devfn / PCI_FUNC_MAX; + pcie_root_port = qdev_new("pcie-root-port"); + if (!object_property_set_int(OBJECT(pcie_root_port), "slot", + slot, errp)){ + error_prepend(errp, "Failed to set slot property for root port: "); + goto fail_rp_init; + } + if (!qdev_realize(pcie_root_port, parent_bus, errp)) { + goto fail_rp_init; + } + + /** + * Create new PCI bus and plug it to the root port + */ + new_bus_name = g_strdup_printf("pci-bus-%d", (slot + 1)); + new_pci_bus = PCI_BUS(qbus_new(new_bus_type, pcie_root_port, new_bus_name)); + new_pci_bus->parent_dev = PCI_DEVICE(pcie_root_port); + hotplug_handler = qdev_get_bus_hotplug_handler(pcie_root_port); + qbus_set_hotplug_handler(BUS(new_pci_bus), OBJECT(hotplug_handler)); + pci_default_write_config(new_pci_bus->parent_dev, PCI_SECONDARY_BUS, + (slot + 1), 1); + pci_default_write_config(new_pci_bus->parent_dev, PCI_SUBORDINATE_BUS, + (slot + 1), 1); + pci_bus_init_isol_mem(new_pci_bus, (slot + 1)); + + QLIST_INIT(&new_pci_bus->child); + QLIST_INSERT_HEAD(&parent_pci_bus->child, new_pci_bus, sibling); + + if (!qbus_realize(BUS(new_pci_bus), errp)) { + QLIST_REMOVE(new_pci_bus, sibling); + pci_bus_free_isol_mem(new_pci_bus); + object_unparent(OBJECT(new_pci_bus)); + new_pci_bus = NULL; + goto fail_rp_init; + } + + return new_pci_bus; + +fail_rp_init: + qdev_unrealize(pcie_root_port); + object_unparent(OBJECT(pcie_root_port)); + pcie_root_port = NULL; + return NULL; +} + +bool pci_isol_bus_free(PCIBus *pci_bus, Error **errp) +{ + ERRP_GUARD(); + PCIDevice *pcie_root_port = pci_bus->parent_dev; + + if (!pcie_root_port) { + error_setg(errp, "Can't unplug root bus"); + return false; + } + + if (!QLIST_EMPTY(&pci_bus->child)) { + error_setg(errp, "Bus has attached device"); + return false; + } + + QLIST_REMOVE(pci_bus, sibling); + pci_bus_free_isol_mem(pci_bus); + qbus_unrealize(BUS(pci_bus)); + object_unparent(OBJECT(pci_bus)); + qdev_unrealize(DEVICE(pcie_root_port)); + object_unparent(OBJECT(pcie_root_port)); + return true; +} + void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *irq_opaque, int nirq) { diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 01f3834db5..7306074019 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -64,6 +64,9 @@ typedef struct QDevAlias #define QEMU_ARCH_VIRTIO_CCW (QEMU_ARCH_S390X) #define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K) +static QDevGetBusFunc *qdev_get_bus; +static QDevPutBusFunc *qdev_put_bus; + /* Please keep this table sorted by typename. */ static const QDevAlias qdev_alias_table[] = { { "AC97", "ac97" }, /* -soundhw name */ @@ -450,7 +453,7 @@ static inline bool qbus_is_full(BusState *bus) * If more than one exists, prefer one that can take another device. * Return the bus if found, else %NULL. */ -static BusState *qbus_find_recursive(BusState *bus, const char *name, +BusState *qbus_find_recursive(BusState *bus, const char *name, const char *bus_typename) { BusChild *kid; @@ -608,6 +611,20 @@ const char *qdev_set_id(DeviceState *dev, char *id, Error **errp) return prop->name; } + +bool qdev_set_bus_cbs(QDevGetBusFunc *get_bus, QDevPutBusFunc *put_bus, + Error **errp) +{ + if (qdev_get_bus || qdev_put_bus) { + error_setg(errp, "callbacks already set"); + return false; + } + + qdev_get_bus = get_bus; + qdev_put_bus = put_bus; + return true; +} + DeviceState *qdev_device_add_from_qdict(const QDict *opts, bool from_json, Error **errp) { @@ -642,7 +659,13 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, driver, object_get_typename(OBJECT(bus))); return NULL; } - } else if (dc->bus_type != NULL) { + } else if (dc->bus_type != NULL && qdev_get_bus != NULL) { + if (!qdev_get_bus(dc->bus_type, &bus, errp)) { + return NULL; + } + } + + if (!bus && dc->bus_type != NULL) { bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type); if (!bus || qbus_is_full(bus)) { error_setg(errp, "No '%s' bus found for device '%s'", @@ -891,10 +914,12 @@ static DeviceState *find_device_state(const char *id, Error **errp) void qdev_unplug(DeviceState *dev, Error **errp) { + ERRP_GUARD(); DeviceClass *dc = DEVICE_GET_CLASS(dev); HotplugHandler *hotplug_ctrl; HotplugHandlerClass *hdc; Error *local_err = NULL; + BusState *parent_bus = qdev_get_parent_bus(dev); if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); @@ -930,7 +955,15 @@ void qdev_unplug(DeviceState *dev, Error **errp) object_unparent(OBJECT(dev)); } } - error_propagate(errp, local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (qdev_put_bus) { + qdev_put_bus(parent_bus, errp); + } } void qmp_device_del(const char *id, Error **errp) From patchwork Wed Jan 19 21:41:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5826DC433EF for ; Wed, 19 Jan 2022 21:52:05 +0000 (UTC) Received: from localhost ([::1]:37222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIs8-0004ac-5D for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:52:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj5-0007fn-I3 for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:43 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:53682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj3-0007II-Mm for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:43 -0500 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 20JJXoEs032613; Wed, 19 Jan 2022 21:42:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Sgg3dfn6R4QsKjUop0+pdEQhxDfekvxo0eblJFMVtdw=; b=pLiKtRk96KC9A3cCq0J05/0tVk7zTu1zuNLDgLgL23pNk4fYV65vG5op4qO/PsZKZR8x /vU5yz/ztGcAF6XgcBwYEiqL8H2snMu2/yNi/LB1KVuoNxCZMGKXJ1f81GEd/tgYDjih biERlM/vrjV4Dp9VzpwqNIdQ3s4jEH0ZU2oubScudy4ad40evKcgyOfkJjvVn2VrAIi8 cdygqCLTc2Lito2RG/ATXJ+mRMMnzgBcLpwxD8JLihVSZhcrLAtF4C6TxtAUlPKvpT13 TPAR45V6w5UNjjwWygTRbN15Pulj6XyyzomVopCIaSQEil1XDZWzvytXhfzsf31SAV7Y uA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hx5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:37 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLauxn147043; Wed, 19 Jan 2022 21:42:36 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by aserp3030.oracle.com with ESMTP id 3dkmaeb6hb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YHsDKa6h9yPcC++jRZn5cfOjKHCjeDSOPUEd1JEtG4eiRykHUSJIqRQjB4bfQlsEmfByfXEuUKxV8iCfVax8t3QIgNXsIhTTJU12UfbuiXuo8rpRmJoo19LTMu5116bFyHp9NyIXz33Zo/OEespk33o7Tn0ZZK0GJaNXVcUzQMoRAoFEuSO2Npw3cDMxL6gO46CJXW9h+mVE39XZ+XBTgOY/p6ajW7tIiqI5pC/sL2J18dCVfNh8z+tzTquxlowSapNTJw2NUsWJRQ5jMivDffqIZG5MD32qlN6fIbeq1pcS98bBBnzqQzzd/aaCAlI1nV+5rAckGrSZcA/lWRU6gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sgg3dfn6R4QsKjUop0+pdEQhxDfekvxo0eblJFMVtdw=; b=T0sQD7y0EheLuhljw3daRGWiAVkQ+HISc+zpxgu+VLf+jWp2GFW12ar6BIkQfft1+DUMHguR+/GVQLFrFfCz2tjUNoEoYVj6BJsnopvXgOVrF6tazRmDIZBNLvtPK1ZggT21v5Qqy9NOatgSHKn0MzyrH/pqZfpJuq01RPS+oublmVI5hcIydvpVUKy52JNA8JMZ55ubIQoFxSYxUbE3+PELpDW9ZwJUsRPus9+jsEL06saSSIVZl12UK+ecXOcGCjQ4zLbU0A3rmlANoOINAabc4cXNpwBIsujKUP2t8d6VfGJ0X+pdB4BNI2JLx5s1RdaOWdnFDSOlxowU5XbLyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=Sgg3dfn6R4QsKjUop0+pdEQhxDfekvxo0eblJFMVtdw=; b=wDPqHIKdYMhtxoqMzp8LG26gP5HZg9UqjwSOvdHM5kq1QoqqPu4kWyQ+KWwd/wvlr1MjL1+XbfSk9oeCSHcKKKAKSJvsu53c7PLG/FeDNZc1uZxcaArB/rzS4TxUL3cMCKUlY3V4kDFRwTGSQbQrPNbY7zIEhyxMuKSo8GTTEGc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:34 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:34 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 05/18] qdev: unplug blocker for devices Date: Wed, 19 Jan 2022 16:41:54 -0500 Message-Id: <5ad3f47f9ed507211fa8db5b8c36b9d32413bbbb.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d45f73ea-57b8-42b6-c3b5-08d9db949a8b X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1443; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gyFaMIiGhn9Mt2Zg1fLCHLYDTjJqsEN2OsfHjncDLgZls+N2UJqk/tcdVHXPI8kKjUdBAJoBty88tHaTqVOjk48d4+/uzIH9CXXmvpklSNgGUF2sEY67wYC2Z/xT0Bd/m9iRDFzmbBHZH7H3/v+aKuGRAWZVLwumdGxCEjys1V6TWeFsSE/rNYO93zwjQCmschr//P5imygM2ZBHnoHHeY6x80Ir3mJXTWCDAspec5sDX1pgSgNBK/5dhsClwi06PJ8lQT0NhmeZefZiAtSW2Qmqn/NoMoGPXEE32HaCW5UQLsrXQOzEwmq+ThYpVv2jEWR3/EMF5eps+fJMFHx+JJwWwq0Q38+wEYrMwZroC59kcxxNfCtYkAN/oSsS5pKBNegwb7Fj6+l1RLos3peLEouiDBYP/MJl9JRDtPAlHkkT+F7t94xRRMP4ZD/KSRi7yHnjgS27A2Rgs8voERAO9gU/Pf2dLEAfQo/IePsT8udKBWMtmDhIw72cJI8JMxrRWFTJtCbY/6kT2MJ4AO3d+CNNQru3tq3oSTxHbFKUQeclzGcNAzAGqUvOb6YtgotCEL264QDFR9+H8EHNCVNw4javqXctD+zifXSWw7036OMNugx9ZWVEiLZ/MsatS/kJqTpPP41RayWSYBgn5SfipuE8zxTxAXMcHhYnt7bJyY5wHrpDgXUY9dtG5+urfSFAx6k0EGw3x7WwEI/YBJZ+uA== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MZmP2ZDhIx+Qv+/m4bCR/o4157zSwh4d9r0FoNzNBWE9DrY1XwymY9w4Kg8E+lfwmLhyZQn8zHwOd9akuw4aJVOv15C566fNI4R2uJxeA0uPLOI3b+6hcSgEufkk8Cz7xqt1PocpPZ1KH3hGq529/GwGOTHDg4LHotnTexcZQwvz3RPNHRXR3zUfgiDE6GeZ1QpKGX6vKXk+xeXqUIuSfyP5wV1yImHAblNq5uLSCYlrN5u0Zd5hbzRZrYOJxwwwQg+tAjOqZWYva2CI5iX9xfF5fjoC0vy0LoGQ2A0XLtjmcplQ02dFfynzZRnNmx5aCXNUgXx8pjQkpTrxfxz9nBTbx9gwIBvMIGWE7dNMgexwASdn+EPh5Z4XeMzBGLzd8P2V2ZxYW+pzAEEe8JzzvbrQ+I70R93fCnYzQAzntLlPjwx44RP0bNURbhzF1rV1bsEINelhzjwjneDsHAvVOXcTQF2RubJ9XdeLJGQcudze6y39MJBeZMhqH8JFOXEUALk0Q5SmziH3v9MQ+G9PMjfakDmF1MAlbA5ar5Rwr84MJOdfXqaqx3RSf0+f9jPscYj1C8qXSRGwvcxmmhD1CDPJNLBZHFX0mXl24lr2W413gHSH9zjD9NPL/oerPnEbbruJ8aOB4u+JGqN2hEgXXnCZ4JfnYx8/3+CcRGuwz2mJ4QQfMVwhf7Dphjb0BwsOOx3szt4Dv+UePY8Rdch5/odybCsuN0Ia52I/YcRhy3oI1bffamq21qfPx3bYWFAfDjf6G2ZZowfLz1Lk5l/d/EVf0xeXipSjnrsmCXplo34VGBcX9BhlwipE1Zf85JRsYvWGEop34KCPd1XKScHNWN8FKafOKXjBGF1XXMr3KP5O/kLaDu94+EE/ACQKsWJqmULbjirRGrgDqCZSDs0LAXdujp7gX0mJ26PTF7IKe4tJXJtZWwN4FT/sGV+6E9yMkknU10OCu08axlfq/FCc9Z4MYxi9ifJbX/n7H0G/2kzE0bU3f88bta0DhzIwcSPZgSCOAV0yWgJP9rszWekCazr+cB/TVcPnXuogY7GVqN7c8Q6nK9h8U/pej9cnD20DeSvDoT1+2NyiLA5+dBUB75c9aDURJE2G476a58/DevpOdX8CXUhLNhfzPHKoHx12YMNSEkQtlZFm2LC3Val3lNBVjcBRHJ6fmiCw4/M4QyjVxfV/5je1ITwpEckWSz7KGt8u7yGgWhBsn5nSt3L4KJ38QT+WY8i073JR30DTQ0tCOVN3i8ulbLSSfOazDrUe6/ryu32WEmnkQgMP4KTyj8wVx7Y/pBCn5TfGWSfi0z0G797mdi9FwI/YM4QfY823obz3kP4bXRkyvNsN6zddgu9AWPZRhbeA9SoqDBSRhjm3PteJnJBqWL4GkUp/sDa/DzDMgdeX8URSCqoMCIYU1bKl5ALXigkchMTQBfS12eR23XvS+BVRJRXlqsszkqZBDVEoWKR7CYBtSaAheyLCUavzGIWKXmKl/wSCEVOoQ39GKnkXh4l6oNww4Lqls7dhFVQ3/57baQ9Fzqtw6oHwHQJrRMU213BzqN04K/STYkLdKjD1d/Z8ZZ7cgQ7BSxpys9k8Ja+vArbhWV9jFnGi128kFcdqdwfUCVt/4Nt2ONA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d45f73ea-57b8-42b6-c3b5-08d9db949a8b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:34.6004 (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: zSKLNPGsqyVjxEOemeScArEbkVKG8MykBw2yQNwCFJnToIb1En4o6PYSFPJt8saFMTefp0M7QuotmQWVMXsTqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: 5WubduOuCCe_U5s-_pYzxOQsJrlIdp2m X-Proofpoint-ORIG-GUID: 5WubduOuCCe_U5s-_pYzxOQsJrlIdp2m Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/qdev-core.h | 5 +++++ softmmu/qdev-monitor.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index eed2983072..67df5e0081 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -193,6 +193,7 @@ struct DeviceState { int instance_id_alias; int alias_required_for_version; ResettableState reset; + GSList *unplug_blockers; }; struct DeviceListener { @@ -433,6 +434,10 @@ typedef bool (QDevPutBusFunc)(BusState *bus, Error **errp); bool qdev_set_bus_cbs(QDevGetBusFunc *get_bus, QDevPutBusFunc *put_bus, Error **errp); +int qdev_add_unplug_blocker(DeviceState *dev, Error *reason, Error **errp); +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason); +bool qdev_unplug_blocked(DeviceState *dev, Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 7306074019..1a169f89a2 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -978,10 +978,45 @@ void qmp_device_del(const char *id, Error **errp) return; } + if (qdev_unplug_blocked(dev, errp)) { + return; + } + qdev_unplug(dev, errp); } } +int qdev_add_unplug_blocker(DeviceState *dev, Error *reason, Error **errp) +{ + ERRP_GUARD(); + + if (!migration_is_idle()) { + error_setg(errp, "migration is in progress"); + return -EBUSY; + } + + dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason); + + return 0; +} + +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason); +} + +bool qdev_unplug_blocked(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + + if (dev->unplug_blockers) { + error_propagate(errp, error_copy(dev->unplug_blockers->data)); + return true; + } + + return false; +} + void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; From patchwork Wed Jan 19 21:41:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24003C433F5 for ; Wed, 19 Jan 2022 22:07:14 +0000 (UTC) Received: from localhost ([::1]:38018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ6n-0000UA-8b for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:07:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj7-0007i0-5n for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:45 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:59734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj5-0007JS-Dn for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:44 -0500 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 20JJVgQO032608; Wed, 19 Jan 2022 21:42:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=wyZTzIqTTMHOQtMH2lH/reAbZNCqbHUDB1iKn9ZLzh4=; b=Do3XSI5q41ilG2Msulor0kEYSfpUJh71Y2ZW/KTC42HOVDUMRcoR7eAF6fFnPrPNSVnc oNxvmDsmhYR6/HXP83dfRfFi/wWgXt1cqTGUqE/yVq3OAHApLaOWoegvhum7TV8Xa0pf qBBu+GirnC2h61GHqehc1Tz/IqCNE2pUD1YdxsWQKaPenfd9r/rJ5mOSihBbQmTj1jxB EAcUmkGS5XK2LZITSxurYf1Zm2b46ablwYbwY5E4JBn74Wnw3fjn5hOD2qrC63Ai7ecQ UHGV+BRIeYo1TFXdunrOU+8WoAeA8f0oBFVKhHvpJjtsMot38TRgo1nVwO/VHNDyZfcU TA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hx8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaukd147054; Wed, 19 Jan 2022 21:42:40 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2174.outbound.protection.outlook.com [104.47.73.174]) by aserp3030.oracle.com with ESMTP id 3dkmaeb6k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffmU7hk/Ak3Ao2/NK8jKkobyY5cBP98XkzlbNnxjEI4ZMbsJHaEkP/lfgHUbp0fsLm5g+2xCIQ0hmxCyiS8/+ZFy43lBB8ZjQ+2X7/GRzjBjAmXBod80d0uQ49br/Hwhb4Ee/8q+V4VfAtSfY5RPndcvqIprxhUuc78GNAQwVUPna82qaPdnSfIWkK5K2hQotNCMxJ5jHVUZNkEwTmieQWx2TV6Y3xoa0BE/gvvUQXPKcAWphVk3Zvkkl7dzESCUO6TV2EiJOo650NSndVBOeN5UuEBOt4V4m4DABfoS3mO/c0u65GT3u2ce8ESD8Bu2KKCevdMTi8p28ZUclemMfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wyZTzIqTTMHOQtMH2lH/reAbZNCqbHUDB1iKn9ZLzh4=; b=kBYWGuxrsEAWvcYMU/UxAJRzIDKtdbhtEfW3frQ+SOpQ77Xc6ag6mFilLIsR0EPUdOjN4UmaBC2mIEyX1G5z8edueTcYnqSYwI/6OSJdurfy0CdfwKWAsGjiSHqDyLMQ2AeeMJAmqvDh4T19msk1M2p8aIkwLxy7r5Eq5vm5XOcu+ajeBw84nFefH0qFyD2ZrCXyUNUF3mUEJtCJOWBkvk/nJxziTCMi10ADJz8dNeDuRKc+cECyUPX3LU6MTnH1ClAAB7XxTnuLCnV4oUyNIlZM2nd8UwOH8VUZZ2OAjgTtLelE1P21YQDY1Vu0xgA7HZidlAOyv0IP5ztwQhDrcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=wyZTzIqTTMHOQtMH2lH/reAbZNCqbHUDB1iKn9ZLzh4=; b=g2REhWQMYI51XAb7MUAolP8vbw+X1UD0A0ggnYQqSfVVs7QW1ijr8J92bJfuusKDdOxPkKUFnWkS/cJxdMT2RwNtf0ucd27+9yv0srs6dQOlF4Z9rB9InNh6Q2jONBLMesITdAyzN/nABhcmzZq1xJKjUePbLiUXLzv21B0KpEE= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:38 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:38 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 06/18] vfio-user: add HotplugHandler for remote machine Date: Wed, 19 Jan 2022 16:41:55 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebf07d0f-167c-4c4e-8d10-08d9db949ca6 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:98; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2QFPFE+NkyFsQ8pafpmvJrsUl4uWBXhAvcvBa8bnUwz3hVoP2Y74HCKnozcpv7K6UGACSvKuIXVgEE7ACFKBNJgNSxkodGxVJxZYnuu4759opQb1Qtn3s+moFX0285nXSqWzjrSKSrO0mOUaAhTDyOvcvyL/vBNZ93c03BJ93G8qQWsk1e3lU+oHbFnOLfwW0vscN3S+dYr7zKKPDSLQ/VEc50GDPckbrOaH7OiT3TUfQEh63LJG0fsq5XLHCjEGRY5vpQFYkTOvGEWgmJEqfd6zZHa0OC/xxZKylLO3cEdAkjY8drfg3NDVZirg4vaAMNtBquhX0XYTM323iPCPEr5a/XtGn7OdcfPR1tB0/m2TRt4XTuxKU6m0TJLUm25AJMyNc3dv60yqyNsKBZru1lGbtFSK8eXJ8uE7TVMyIlj3JJOQBAr9lSfgnvOOeV+pc4xnt7s83URkIUymbCuwDiGwquW0O6+KgBWJcatqAnMSKEFXPL/m6a52rYasuDxZp5bxwBKl+fklcrUrfj8k5XsfFZctWsquwKFYb5k2sy28zksBpLwmBwChuzu9QhlFiyoLvNU0/7VmZEH0zrBW+gv50x0IESzPgVEQq1r1doqA+JcOmlmnfihE+0Fcvjn1+CMlIcXAU4RlSdOJRX0pl1Mc2rOzR/vV40PX1XUSIoO77KWZLcG9/kFLuNcvUsj+Y2vhNKE9TdF5WU64O3l88g== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 78pGWACBJrqVjMGZAPDZt3gw7uaTFtTJVGvP8CtN0z0Tq4pMzWReFEho3PmlCLKrJDWcw/Q07E9wv2mAQa0LtqAHS1HfszsK4NkKIyJpwzZmb1UYd9NVIHI4esUeCrM0BcMbiZo4Niz/7Df4qAPD/s+58OQdyGkAFEwaXmfvo5z4g0wcie3B/v7fRz/0nvI5WlwAyeFpk/x4UnSmMEIwBbOEEs7WkjxFl4Ig0fpMOZQSPvGhg+fq0gB/josWhYQnFeBrTlToD9n4VhSZ6x2YPndq+wMV1EDbm4PupRcBBl08M6oVmD3ScUQ+cq4GBmQAmKZKpxFN87Zc0+GodIs9UBfc755uOeddq3C57ZhZszR+Dg9Zamn8WxtKRWGcL5QtDBsdDXugVHkUZ6nzSUBzNuHNINFbfoQbp4PW/r1F1dXMrjwNFs3upJt+l7glK+2xUbsbLhq0l685zFkKRvAWEBDRjze+cH/bUlh7nrjijRgO9VqkccSEyhWdkdXGaF7lIYZif7OTnwRCl/7dRnbpr0jAT7yk58QEfW40uv63q0kooOZljzrt4bYG1tboEiZoLMrqJSA+7aXs4SvrXEJCGT8s96lOHZHLsTsYyajSZS2nBABS6ap61xQdtEjGC+jZ6IhbqPpKN8V5smpeK9pM/2CVb7Fd/2TA+yhyUqdi3jeU3bHaSTWtl7SOkAsGyhnF+Nka14Jk+mg1vUsFIAFUKvTNqXWozSXS8X1Ms3HOBV6VeZ2thh3/QahWA9mg/PHTYKnkPu8AU9MzUrwx/toVIUUVQaK5deEpX80hhkVv0lbwALaQM1Knz1qbcpwGAcYhvguXaPecQY61ID2wiV/g0PYhUsVjizrp4nAZZ+1FAHRWabX5YwxrO3q5W2ZsltIvIhVBZopnE/caeVhGRkTF0+2A+hMASRTa4ld6bmk02WtV3hd4yPZJkg5FRs3uM0J9IHUJzP8k2DbykaETYwoSgoiDKaWjCsHm8EMh/H1h2UoUAQT824Lpi9J6Hty45S7P5W/36nu1wt39B79yq7M1NHP7XC1urdJOcqcYW7kvf8n4kd9/WpATt6qeOZnUhvmvdKCmrGugNZ1xIj+tf+ApyERaRy1qCM1NNBrM+WofCDQUwX5R2TAat9vpHmwoayzKW0+/2hulX/Z23Tm+o66lWoAlrAbTGM1ePi8o5pVyEtyhnjaDlmMAdybARmkxR5EyNZzttYpldYxt+v2+QZA2ZWGzUikpJ8CLNj0sN3dB2zR+GPtHHmk5MULZtRcgCB7cv00Nf+Vx0NKteKXK15l3EHYmzZu1wYUBf/pCAbRhOZqSzJjRbbhHfNsNzd1NKlba4R+ZqWMKaGAjgDM2dbp2Dxrxvt9ht+4aVBTc9dea14L08KgWdeDIGCuQ17QaKYAr50QeiB5gHVxe28e0pGMyBFgR/qdtEzIQTzheV3hM1U7WXkpmBYYUhVYb3vu4d15UrPrqgK0OicHCQf3wd87rxuQ5b/5PPI6Uxu4+7H/73/WURblRwi/6LTEv06gKrhs81yR8NsScvcAfgl3Y9DVArnwR7a/3ut7d0cBnROAFXx/ABVHqH3CfoOeuc0NTnn6xn7nsuRCZZ9Vgdu7yDW1zoekShAIgJgx6rA20Z16f+vo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebf07d0f-167c-4c4e-8d10-08d9db949ca6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:38.0689 (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: l6B+WjRMAl+B0pggSrPKosMQcj2Pbpgz46rmp9gRyrnGcqgpmJwNP41M4ZE/Lo8ZlCagZFFM+tnrIOeTAt+wPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: 0NbD483njkdLx47N5td8kZgST5nJEAIG X-Proofpoint-ORIG-GUID: 0NbD483njkdLx47N5td8kZgST5nJEAIG Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow hotplugging of PCI(e) devices to remote machine Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/machine.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 952105eab5..220ff01aa9 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -54,14 +54,39 @@ static void remote_machine_init(MachineState *machine) pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, &s->iohub, REMOTE_IOHUB_NB_PIRQS); + + qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); +} + +static void remote_machine_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(errp, "Only allowing PCI hotplug"); + } +} + +static void remote_machine_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(errp, "Only allowing PCI hot-unplug"); + return; + } + + qdev_unrealize(dev); } static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + + hc->pre_plug = remote_machine_pre_plug_cb; + hc->unplug = remote_machine_unplug_cb; } static const TypeInfo remote_machine = { @@ -69,6 +94,10 @@ static const TypeInfo remote_machine = { .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), .class_init = remote_machine_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } }; static void remote_machine_register_types(void) From patchwork Wed Jan 19 21:41:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 221DDC433F5 for ; Wed, 19 Jan 2022 21:55:01 +0000 (UTC) Received: from localhost ([::1]:45860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIuy-0002E4-8T for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:55:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjA-0007nA-1o for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:48 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:64212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIj8-0007KD-94 for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:47 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJvWvj031403; Wed, 19 Jan 2022 21:42:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=dPKOtKsyJGUcQvMnjboBXAncXgAhop1HN8BaHg/fUvM=; b=XnRdox+hkODsLH8uY/Wcp5VFg6Sbi0GT6tGGEwVrVB+I9tYK8pZ9G5lmyqUuRzY9ysXp qBeiNcGsQ9mvivQMRjO3mftGWA/OHuG9jqC2rVPmgi/qHp6wK9rlqSW9rqYD9V0i5Lv/ zKJQJpRuuO3LDR0cs9/+GBj9VMVDca45+qzcnGEMN0u8Kumq+tg1qUPJ4IKTT7Zaq4Mu aFwR4jyaXu+MCA/KbAaFUw5FJUQbLWMjrtTpe1z53np/DAdJQdEeiL9lHs4BsqHBfAN4 MB3/ylyBTrvIxLtt3Ix5gyM8//ulyGC6Q2E4CwreAv4m6U27f/MD8yJ2ccITlZmKnXwk +w== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnbrnxb4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:44 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaudN147168; Wed, 19 Jan 2022 21:42:43 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by aserp3030.oracle.com with ESMTP id 3dkmaeb6nj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G3dz3AfaOo91z8sVYgubkZsclBJsrfCYVkDXFeFa9ZQhYJnWwmvlzp/1WEtN/UUpFhRw1eeGJ5LLHG7UrViTXqRq5SuqLNEGGqJ0G60oQsGHLihvoWbQJgd7MmUe+Z13Vh4F02zVEYg8ajOjR8wyDBIDoRxFG0/h/GFaxENNhmn/SSqU4weKp/wEBJLLCHcEW+ZPG5cuRwN2BvnsRzTqOVd3E4tMe1+KU1OWcpKLdSRzhJbAf0yZMfIosXQpTmxKE8Yvdl2aMj+maHy+pRLgHwmBQnyqJKeB/n3JEl3oJ6rpqtC1Q12ZR55mcTf1Lirfc0TRNqbYbBLRAIuXy6GJUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dPKOtKsyJGUcQvMnjboBXAncXgAhop1HN8BaHg/fUvM=; b=hBv6Nrfl82DmbWklDsYC68/rk4ixB2bexy+dhriS0iN8oiuPOXhN1T/4F7haypxAQrTW35T3jRhbhVmQEzy4y0uBGi8WClhNNMUZ/nIt8/GPm2QNbNyzoXnz91cduWzoG1KTU4uGyMfQDZmoum/KSBAL62Y8yn1iyi7iINoxmVdZIR/3UmNQsh7P13QytF/F2ZO82wzmyv83rNdcH35l9/bECS/EKLTE95em/VZCNZDQ1/Hx9aMGc5ankXAnkzG/UQx0PpCnLsCI56b607hPZlfGGDTPDD3zYVETGXRi9mEC2sD52uCn7auv0v437rjiFPdIkSVt9BAacdE6r1X9lQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=dPKOtKsyJGUcQvMnjboBXAncXgAhop1HN8BaHg/fUvM=; b=q4jB8ytGR0Vvgru6T+wTFU5GrsYCCq5kpxti1hRoupYisw5OHiCRta8Io0nF43qIuIIOPKlL/of1l6HAsUo5OcTDXsA+Fvaqq5RHL4MiinOtZAKHaepOlJHfiXMoMS4ZPAtz9JhVVgprKQn1AEoKKw2Y656g1LSuG4krrVV5uuM= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:41 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:41 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 07/18] vfio-user: set qdev bus callbacks for remote machine Date: Wed, 19 Jan 2022 16:41:56 -0500 Message-Id: <1dee463f227f7a865877cd98f78e4ce48ce8ab32.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea7b18ac-70cf-4d9d-6ae6-08d9db949eb5 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:93; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cMqYftxsfQ5E5kPEfJB9c8VQxa4tampnM3dPH6ynr5WDXouZ10gdEo1JvoOU6/CKojoWdmzzXaILzIP1fp+65s6qmtk5EUNpr3K6vlfVlrOnzcQF7A5uCQeQTehmuMOdTzYWzO2Y1OG50cx73RoWD4oO49P6xQT7icPjFNuG0eAHzxEdUdhae/dwlXzU8h41o3fGo3PJwTBkXIXBfFgV9aTMKo7SpT9zOOo9bzfEbs35Z05syFCkxP21Rk/6RZclubZJ4SP4gBCQs+Dh5nX+MKSpBrfQyVpb3cYcW5kQpmC5fcfDARlchdaQPPc1uI0Av4v576U2Fc3frFn5FtPpJUa4yC6NDaMoZWcx+Q/x1fE6AIMLvQVl/BygqN2uZ6JT4a/toH9uvM0vOE7YgjGdy0ozJGhvYtdG0hCL1G04Zyv2CMss9545j2NhiZq6KxMSK71W1g0CY6aACY6utOrLz6eAJVkp+ixD2Lg+BPgkh69tH1+CKQM8d90Ml3cn1tYVyZR+nzooITuB2CYvpanZdMXKoj427FT6LSA5bmBTc41eXY4bN/t07x3c2GS0A2vfa/YCfAfuIbh7G+9GLBHhgnVVlQedEpreax1r9RvhZHheGRAfxhDU9EsWgMOYvoqQcOSLMfid+pmXBULjY0Ug+2OqmXOzrqx4FHKzSL0euM3rCIysjRI+2yy7enekXNajxn1kJlBnzDdaqEqXt2POFQ== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rSgvrAwhwEjIPrlcQb98rEABIKj6QxoSxpQ6herbdACWWbi8iEEGlDCiLzwtMU2PvnXkp5WFnpQSRBX0m9+ZujJRJThliTZbfFX1VC4rMMZwkHkvslIWRfj1vQvdE/4oiPa5OivMEgk061Y+66d1cicpbf7I/Islxli1RKgwSb5IV9hExIsMH4MLgkVWpJAN+O5iUw9UNk6iUsZF7P+t8ZLD6oFrC0Vqz+9wNqufrPL8eMt8oUT2bYW4w/w4bKuR7qJp22BwbdaevsxgYYOczMRK4zdiRZfyzoLzqfcDm2cSQ8ON3HM71UWSZMy/xMPV9RjzftuaA0tLbcpLsm/1j7DpKCU8QZtesfbnTxYTnnIPZGl2mCCGapbT3FyCIchl+NQD0/V2yeAIMFTtBSViBdOTsc7DNXOU0SH+dKqoYhf2UK/yTqUBeFmVETWS2OK1GmSqGI9DY2tdq9TXiJDGfysTY2RKVBcLT//FJgSGaM+pLv4cSgA1wh356xMsxnDfo9/4CB9CLSrVZ4i8GrCp24kTConoEwIZrldNH8lm8CbRRkyKyOA/tNeYVvk22sLkN7U+S7elivh/1i5LAhx3+ZoFbsNj/KNI2cXRDjqXURzplMfv8V8vlczzUHdZRLzHS4Gi/8GDU3cA9j375QCG7Bdhjv4cFFyyL5EYQ0tAfoTjyQJDV5bq1TKaMNaQQOqH26F1gjm1u4ZWVoEbl2VR/HsRhI5uYQIg7CY4+SLg/ZhK1fqYNtfJFPZbUwBKX8lRvmV0fK7rp26+QKSZ3uDoSIjL0Ujg+il5ns/1CnZI0L/dGodZWIwlt6QYOnyXqyKbgp2qFywvMnY5Zv2ghkc9WDM7FcWhsTrDngzkcSpUM/9d+njVbIfIEkBv9COimK2XZ7s9Hn+vYryG0B037yV6uQt0vBTpbMyyaXb53kWF46YpQlXS5CTVlxIpKsNcgqBRzvFYNvU1icpSBo+RypejQa9VDTGi9AuGel1HoUXmQnQ3hqG7VKHEz9F8/jR7jsnR8m9GU948baqpz3+MM8iGK3TnFlCnnYLwg7GsI4a1Yb9oIfueyS+vQWBiX61U5X/uhzJvoS3ZrmgYc95dfN/RmqdzGUbV1PqD3FAVgRPVIvZDuxeVfnHz7c+Qr5Eg4pZ2FkBGLKV58H4uIeE4JskS7uOAFkQ/OfQ1PLILVtxCiKKNEG/6BWr/5Jf5zbtPy/GqxX8/szRnM2AfEDuFFSEPQVT24w4kCeum67k0px0rrl9VEzYCfeMIqpiLmGU9rjM1o2z0G2Cz3nMmM4epeZiTElO/gNDl0TTkSvsWHZdQAtht5Fok4zWWmUINMBSXOhQGK47ud1D5QVh8QYWuPMUoRlAem/7DSrOQp9o6BrRxxO9NZAHnG2ChD/h/eM8Pp0KVZyueInVVk45SNeJWNcVpdxdyZN1G3YCqnTnpSYbWmydZ9fl4bKWnLzZJBUnsPdAMeI8iBss017Y0k6dcbWq23vsYqPDG24Ww+urUEnfv8Kkszf7RmhutVQx6R2SSrzh9qwz81ZG5T+WUVwLgBdbPNTEC00KS286IuTFcebcubrbx+6BbPVgmgUVEKljNUAe4W2z/wmH8Kq/7EPHJy4NYs7fVPw8E+zeSC+uInocXYfc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea7b18ac-70cf-4d9d-6ae6-08d9db949eb5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:41.5374 (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: mG3HafxtJ48UxJIsJY23CVAj5ysoDvrqzYXI+iyr6KdAGJ5SMs0U0IaGAmvLTZ9uU1diFMqkhL36wHGY0DpvAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: Yddj9vBq8ruF15q6rv92EfozKihXefPj X-Proofpoint-ORIG-GUID: Yddj9vBq8ruF15q6rv92EfozKihXefPj Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/machine.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 220ff01aa9..221a8430c1 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -22,6 +22,60 @@ #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +static bool remote_machine_get_bus(const char *type, BusState **bus, + Error **errp) +{ + ERRP_GUARD(); + RemoteMachineState *s = REMOTE_MACHINE(current_machine); + BusState *root_bus = NULL; + PCIBus *new_pci_bus = NULL; + + if (!bus) { + error_setg(errp, "Invalid argument"); + return false; + } + + if (strcmp(type, TYPE_PCI_BUS) && strcmp(type, TYPE_PCI_BUS)) { + return true; + } + + root_bus = qbus_find_recursive(sysbus_get_default(), NULL, TYPE_PCIE_BUS); + if (!root_bus) { + error_setg(errp, "Unable to find root PCI device"); + return false; + } + + new_pci_bus = pci_isol_bus_new(root_bus, type, errp); + if (!new_pci_bus) { + return false; + } + + *bus = BUS(new_pci_bus); + + pci_bus_irqs(new_pci_bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + + return true; +} + +static bool remote_machine_put_bus(BusState *bus, Error **errp) +{ + PCIBus *pci_bus = NULL; + + if (!bus) { + error_setg(errp, "Invalid argument"); + return false; + } + + if (!object_dynamic_cast(OBJECT(bus), TYPE_PCI_BUS)) { + return true; + } + + pci_bus = PCI_BUS(bus); + + return pci_isol_bus_free(pci_bus, errp); +} + static void remote_machine_init(MachineState *machine) { MemoryRegion *system_memory, *system_io, *pci_memory; @@ -56,6 +110,9 @@ static void remote_machine_init(MachineState *machine) &s->iohub, REMOTE_IOHUB_NB_PIRQS); qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); + + qdev_set_bus_cbs(remote_machine_get_bus, remote_machine_put_bus, + &error_fatal); } static void remote_machine_pre_plug_cb(HotplugHandler *hotplug_dev, From patchwork Wed Jan 19 21:41:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E517C433FE for ; Wed, 19 Jan 2022 21:54:24 +0000 (UTC) Received: from localhost ([::1]:43376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIuN-0000Xj-Gx for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:54:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjJ-0007wK-Bw for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:58 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:2646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjF-0007Kr-Is for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:55 -0500 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 20JJoQcx014084; Wed, 19 Jan 2022 21:42: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=4Bq5s7R9Ty2xTz6t1ZUOESmPw7pq+NWqDU3uwgIIbNo=; b=uogk5pJzM97wmHb1BouVUbt4QK/Iewa6DUKisnmslXBwih3hqjAs6st9VPp7cFpOWe/Y DzBh4nSl9tBLgyy5tVGgmee/hjhZucfiRp8ZJUyVXHjBb4dGo4HANwbK2JYhqHpPCkqu dZWUkJ64Y+iGPGDy8ZZvePdBiOXNRQOVgogwY2NrlJ8L3jPazqHq9/EQVnaf9s73bHBW exuekzeFcezabcx4R23C6w/BIfU81TXJ3SS8KjoWDqz2hChRYXPyh5MSi60aTSauxE5p kLJGlr7+XOb9jd0fvTYHdEGhp3C39RCibmRT6IJrh1JlBY6PhvizDowjig+9vYBnuIU4 ww== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc51e69x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:48 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaSKk030864; Wed, 19 Jan 2022 21:42:47 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by aserp3020.oracle.com with ESMTP id 3dkp36kfbf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gcMTTS2ZcenVUxAAJW4pXrGKlxTkKVwe9n3WeseLfU9lt2l1O0w+5m9KbfiCLf53xWfNmjI984GAiNNHGPzA7iPLOgoR250e5nZ7hW2cEtZOQsVCsY/UXmI4pP9I5E+1y53fJ+69v3FLLZs0tRIuivaAbmYlf1N8vHKbrq28Oy1UdadbS0+1tZoLgHuXFT7HrmR6db7mpCzJyJ/Zz16behyZSmVu/qVjd9pu6Dz8FkkycSc3NNsoI4+Vs6vPzhLgmkTSSuB+5ILNVNOcJ2a97bElcEO3b70I4qxVLiD+gaZyNZBbkc/pt/yBl5fAGdfhfuaQdNwactHuhdF5Rv+vtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Bq5s7R9Ty2xTz6t1ZUOESmPw7pq+NWqDU3uwgIIbNo=; b=kR5XdtlQLEqJyYMIdU46jXFc/b3vw1vJ2He/QavYyO9xLk3+Jd0DyWQw5lCJRvPlyNawwmLB85Dy9tjONlbirivwM70EXn1dPo5wzmS7v+d7z+5y5X7Phg6UZDGh05zor89wrBrutJebGj2Vo1j06bnmVme/Hny/dVtgp28s86ZtdDogC3Lqi4PhplrmH0Ia2Z1/wUUSLnEeKnyP9zUHpGvy1zjC9Ciqm+i49cHRPAa1RYyx9bTxBA2sOH0uQshFy1rhfeFwrYl8TO1GCanae+qH0I1iMUGFHAXXbnPFr6BntDP8CWh/zPN/4tDqfcCK3Q0B8mE4GYuoPXC2KQcFiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=4Bq5s7R9Ty2xTz6t1ZUOESmPw7pq+NWqDU3uwgIIbNo=; b=JG9g0W2fXTgOFfC77H/Th3cryroEM6FjtBAsuJRXbSx2IVT8KDyLC7kyGgfUz8iavO3n8tXviH6A5dM9Rl0oWLI7O7SqsGLjX5hASDoAsqzLvftvE99+wOMNZDXhx0nwQK4zPvcmqpfM4duE+MPc6sIQ4Pvgr5MM306pzLhcmag= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:45 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:45 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 08/18] vfio-user: build library Date: Wed, 19 Jan 2022 16:41:57 -0500 Message-Id: <54084e1623dc160201e630fda88a305bc686b1e4.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff46297b-cb86-49a8-0d57-08d9db94a0c9 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 71DyQM3jLe026PzeTFlKWuVqsjSI3iLbV2tgiY9rPnvkKaBAVMG5gNVDSTjTGTH9Uujr6spgHGqipDX6qR4lm63rULA38vFYtelspXsVI8OgC8Kmo0kSq9xza7UC4/1LbDcA4lHEZkWhT7Wz5YWT8CYP+imevWn36CSRc5qqEIg7mrcx37W6hJ2XMHBf9iDy/SlBj3AYWSPRdMCHx2jmIbwCTzr6uEdhIwf2on3henKpVjG4D4iYpdNcana4LsqKnJMow87Semi8BLkkFvrvUIM8GZZtmLAwqkB1Pn/syqKdxCq0zsDj3VKvanRCtTn4mxyKKBsa56XK4t5umu7kLKSDEIhuPBFFsWzdFSB51MRqOKgoNxx74AlGM0shExAM7W7gkK/YtW77r0mIGSYLMJGykkYVBNtE/seqw1F/WPyWUecEUgHPmCUt9he5OoAdqxI0H+LP6z2h/ccoLSziYiY6pfSG5z2knTsZexUQ8pI8aTKD5D8Z8vdTsZUpSRMmY3u8pn1csW/q8/d6y2fWX/Nut65S8Y8ix2CdjjNq/r6fcd3HBLwuvDvIW5tl4wY9uCycs3iV0pOjUh1WedL2ShMs+adT9aoyFyYOzW5qd3UbElJqNU17aDF4O8XVprwJp6m3h7P2rlKe5TXKF6pXZi1snn8NmSsj7/kOT5xChGDgg8wz9ipHe3NlptbW0xBEv3g6diZi8QUF+KqL7TpAVwu3owA7qCwdOaBvFF+HA1XYUJeOnvVLm+6VhfCmOuY3nhe8VfWMebORpuxDX+vTfJhMOKH5AjpGaGqquhfcTIIAfiUIHvzp4YboyvjHBN/zNHixxrkr6jQjfhPkCg5nA/1IQjOz7ScRW7qFwQt0MrM= 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(30864003)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(966005)(52116002)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RHqoLj8DCN1HyiY0UyJsOwJAtjMmIU2Y+GBOuc12W6H1COqA0fQcO5AKOyObJVGH2S0Spabwa3TfBwiiNxBYQ9bBXm00g7bg9/wDVyYk7TfWRmFIEWz0+FOWaAOuJ1G5tr9DbWv4wSfSVXHt6k1XmtkfqEcnv3OB0yxvs4CXmisJhZTZ/OiycIJKtGw2z1QqNsJOHGHvf3Aucdr3gYJO23zE5sSYI87YNVGBdNY9qhRYm6Xl6NNYfDoTt9o9H7WEpnXadwbgFHe5s4CMj6RsqMnqMJsCRvhdshCkOcVR5OCfVE5NP8KEW+qM0NedAMreHz2s/K3VFf97xBk9NvwwB42ApsOUQ3YsWE9xTK/hdy9rzHKyJvFZEN4yTGKwTOfCb2g95VwhZZuRzGC3ZdIItVlC9BVDXep9V8qJaUxXlkGs/b6x9HXht4UU7CpfMdMO1QRQNlFQbMWMYjVfzDRCWNAnutCvNEoBEHVq0nyaw+Mm6BndGhNuvzdpNjmxaH+oi3MPcXG4uTjj+q0uJt8El1zEJJbJKsuOeiqL4ZcMLRrswv+uCvFo4Cu6gAIEElqEjn93L9QIx1UjPAExfET0vIzpX2tVAe/m2LdZgA6AErRNVN30FvNuYI2sBf3ps95gdQUiTdOxcIOZiR2EflbrzCuabZadMD4N1ukxKqWu3YnTx3fwndwn8l9/F8z5YIfCY5uTESbBd56fsnmCaFkzv3X9bmrdkKFgtc+L2sWxBx79FXnDhZUCVtjDOtzybsPhnshTMsFLe6uvqkXBAoiseN/pYyx2C04BMafMnau72Lt8vn3AhzcGMG4J7ONhjlRkYd0y2/2W9vKzaYFrBJbpqfKSPWdIWpp7dyDmbnkv6LPxxHgnbV+eCgykUKt8QfBiufsCDRXhwpy/HfzOOnXSI9qLJylmQ8xB/TUuYQiqKBIS+nUe/9hLW1Rsp06+vHRG7kk0Vt9VZNYUNynhn38mQgB3336JSqFPQYjCilNmXnKrP51+u71NF2yTX6C+bWDKYDjFz9izR7KfUQLGB9a8Eo8c5hQ4O0hKugzO/qXx5G7L5n1S/wqP5mn0g8CE0KalUgA4GfE+ZGPXYJRSOYOSJSbJFaPzmNz2CbUPrCQC25VU6DI3FnW+p2Nl3MtFNVySFyX87ryWcYMbUxqLk/DWFSK4A9t80R7Tt1aj2rEOxbXBt9VP7/P6/E3Y0e5ryZkIj3GDhTpmzbsdgKvz9njIHYzSp9nL88+54P28KSboYXeye82SozFyNbRAymn/QgGJjY32jzcdDZ3IdGHaPhGZNf1JRZnLwjZ27iVWpH1zd2/Pzq2O3TsHAPKidcyzThQwmHdUFddggm//0d3y+ANB72npWD36Hk7cpzos2Bf5lW1AA2zviTejVdSNz9/xF2Q6QwRaxKLOBrhI+D0YfC0BOuY8ekaSSGWHXp944fs2y10TSUCp+mWKWWCo5ARWIj+Y9+zkLKOizvysrOC0+SeTzzbApwC2izpwYsKZoUeFpZq3BaCLpdw719yC/GfvhRkatxhrDZAv3/wkjrI3FXoESZtM5vwCOKI8JKLcUjrLKbg73zGsOJDmAe+VbKw+CleRtUmFniJekl/boNQioJyZ4CAm+dSOmOXatKD/7ZWuSm0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff46297b-cb86-49a8-0d57-08d9db94a0c9 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:45.0371 (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: r34TZ5ljoU8zA3OLpwKwld+t/cGn95Xumz0tBWs9pNCfRamqaH8lBKumIvbTIFpLJbhDFcfbbz//aM1yQlB1RA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: wXKcuJMgeE4v78yDzROEutI4AsbGlpVP X-Proofpoint-ORIG-GUID: wXKcuJMgeE4v78yDzROEutI4AsbGlpVP Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" add the libvfio-user library as a submodule. build it as a cmake subproject. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- configure | 19 +++++++++- meson.build | 44 +++++++++++++++++++++- .gitlab-ci.d/buildtest.yml | 2 + .gitmodules | 3 ++ Kconfig.host | 4 ++ MAINTAINERS | 1 + hw/remote/Kconfig | 4 ++ hw/remote/meson.build | 2 + meson_options.txt | 2 + subprojects/libvfio-user | 1 + tests/docker/dockerfiles/centos8.docker | 2 + tests/docker/dockerfiles/ubuntu2004.docker | 2 + 12 files changed, 84 insertions(+), 2 deletions(-) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index 6a865f8713..c8035de952 100755 --- a/configure +++ b/configure @@ -356,6 +356,7 @@ ninja="" gio="$default_feature" skip_meson=no slirp_smbd="$default_feature" +vfio_user_server="disabled" # The following Meson options are handled manually (still they # are included in the automatically generated help message) @@ -1172,6 +1173,10 @@ for opt do ;; --disable-blobs) meson_option_parse --disable-install-blobs "" ;; + --enable-vfio-user-server) vfio_user_server="enabled" + ;; + --disable-vfio-user-server) vfio_user_server="disabled" + ;; --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc ;; --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc @@ -1439,6 +1444,7 @@ cat << EOF rng-none dummy RNG, avoid using /dev/(u)random and getrandom() gio libgio support slirp-smbd use smbd (at path --smbd=*) in slirp networking + vfio-user-server vfio-user server support NOTE: The object files are built at the place where configure is launched EOF @@ -3121,6 +3127,17 @@ but not implemented on your system" fi fi +########################################## +# check for vfio_user_server + +case "$vfio_user_server" in + auto | enabled ) + if test "$git_submodules_action" != "ignore"; then + git_submodules="${git_submodules} subprojects/libvfio-user" + fi + ;; +esac + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -3811,7 +3828,7 @@ if test "$skip_meson" = no; then -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \ -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \ -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \ - -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \ + -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp -Dvfio_user_server=$vfio_user_server \ $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \ $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \ "$@" $cross_arg "$PWD" "$source_path" diff --git a/meson.build b/meson.build index 333c61deba..15c2567543 100644 --- a/meson.build +++ b/meson.build @@ -274,6 +274,11 @@ if targetos != 'linux' and get_option('multiprocess').enabled() endif multiprocess_allowed = targetos == 'linux' and not get_option('multiprocess').disabled() +if targetos != 'linux' and get_option('vfio_user_server').enabled() + error('vfio-user server is supported only on Linux') +endif +vfio_user_server_allowed = targetos == 'linux' and not get_option('vfio_user_server').disabled() + # Target-specific libraries and flags libm = cc.find_library('m', required: false) threads = dependency('threads') @@ -1877,7 +1882,8 @@ host_kconfig = \ (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ ('CONFIG_PVRDMA' in config_host ? ['CONFIG_PVRDMA=y'] : []) + \ - (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \ + (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ] @@ -2266,6 +2272,41 @@ if get_option('cfi') and slirp_opt == 'system' + ' Please configure with --enable-slirp=git') endif +vfiouser = not_found +if have_system and vfio_user_server_allowed + have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libvfio-user/Makefile') + + if not have_internal + error('libvfio-user source not found - please pull git submodule') + endif + + json_c = dependency('json-c', required: false) + if not json_c.found() + json_c = dependency('libjson-c', required: false) + endif + if not json_c.found() + json_c = dependency('libjson-c-dev', required: false) + endif + + if not json_c.found() + error('Unable to find json-c package') + endif + + cmake = import('cmake') + + vfiouser_subproj = cmake.subproject('libvfio-user') + + vfiouser_sl = vfiouser_subproj.dependency('vfio-user-static') + + # Although cmake links the json-c library with vfio-user-static + # target, that info is not available to meson via cmake.subproject. + # As such, we have to separately declare the json-c dependency here. + # This appears to be a current limitation of using cmake inside meson. + # libvfio-user is planning a switch to meson in the future, which + # would address this item automatically. + vfiouser = declare_dependency(dependencies: [vfiouser_sl, json_c]) +endif + fdt = not_found fdt_opt = get_option('fdt') if have_system @@ -3368,6 +3409,7 @@ summary_info += {'target list': ' '.join(target_dirs)} if have_system summary_info += {'default devices': get_option('default_devices')} summary_info += {'out of process emulation': multiprocess_allowed} + summary_info += {'vfio-user server': vfio_user_server_allowed} endif summary(summary_info, bool_yn: true, section: 'Targets and accelerators') diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 8f2a3c8f5b..07c36fb15d 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -42,6 +42,7 @@ build-system-ubuntu: variables: IMAGE: ubuntu2004 CONFIGURE_ARGS: --enable-docs --enable-fdt=system --enable-slirp=system + --enable-vfio-user-server TARGETS: aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build @@ -165,6 +166,7 @@ build-system-centos: IMAGE: centos8 CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system --enable-modules --enable-trace-backends=dtrace --enable-docs + --enable-vfio-user-server TARGETS: ppc64-softmmu or1k-softmmu s390x-softmmu x86_64-softmmu rx-softmmu sh4-softmmu nios2-softmmu MAKE_CHECK_ARGS: check-build diff --git a/.gitmodules b/.gitmodules index 84425d87e2..4ae2a165d9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -67,3 +67,6 @@ [submodule "tests/lcitool/libvirt-ci"] path = tests/lcitool/libvirt-ci url = http://gitlab.com/libvirt/libvirt-ci +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/Kconfig.host b/Kconfig.host index 60b9c07b5e..f2da8bcf8a 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -45,3 +45,7 @@ config MULTIPROCESS_ALLOWED config FUZZ bool select SPARSE_MEM + +config VFIO_USER_SERVER_ALLOWED + bool + imply VFIO_USER_SERVER diff --git a/MAINTAINERS b/MAINTAINERS index 2fd74c4642..8d7bebc74a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3486,6 +3486,7 @@ F: hw/remote/proxy-memory-listener.c F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h +F: subprojects/libvfio-user EBPF: M: Jason Wang diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig index 08c16e235f..2d6b4f4cf4 100644 --- a/hw/remote/Kconfig +++ b/hw/remote/Kconfig @@ -2,3 +2,7 @@ config MULTIPROCESS bool depends on PCI && PCI_EXPRESS && KVM select REMOTE_PCIHOST + +config VFIO_USER_SERVER + bool + depends on MULTIPROCESS diff --git a/hw/remote/meson.build b/hw/remote/meson.build index e6a5574242..dfea6b533b 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -7,6 +7,8 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) + specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) diff --git a/meson_options.txt b/meson_options.txt index 921967eddb..7f02794d4b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -68,6 +68,8 @@ option('multiprocess', type: 'feature', value: 'auto', description: 'Out of process device emulation support') option('dbus_display', type: 'feature', value: 'auto', description: '-display dbus support') +option('vfio_user_server', type: 'feature', value: 'auto', + description: 'vfio-user server support') option('attr', type : 'feature', value : 'auto', description: 'attr/xattr support') diff --git a/subprojects/libvfio-user b/subprojects/libvfio-user new file mode 160000 index 0000000000..7056525da5 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 7056525da5399d00831e90bed4aedb4b8442c9b2 diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index cbb909d02b..f8dff989de 100644 --- a/tests/docker/dockerfiles/centos8.docker +++ b/tests/docker/dockerfiles/centos8.docker @@ -23,6 +23,7 @@ RUN dnf update -y && \ capstone-devel \ ccache \ clang \ + cmake \ ctags \ cyrus-sasl-devel \ daxctl-devel \ @@ -45,6 +46,7 @@ RUN dnf update -y && \ gtk3-devel \ hostname \ jemalloc-devel \ + json-c-devel \ libaio-devel \ libasan \ libattr-devel \ diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dockerfiles/ubuntu2004.docker index 4e562dfdcd..d16a73dec8 100644 --- a/tests/docker/dockerfiles/ubuntu2004.docker +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -18,6 +18,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ ca-certificates \ ccache \ clang \ + cmake \ dbus \ debianutils \ diffutils \ @@ -57,6 +58,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libiscsi-dev \ libjemalloc-dev \ libjpeg-turbo8-dev \ + libjson-c-dev \ liblttng-ust-dev \ liblzo2-dev \ libncursesw5-dev \ From patchwork Wed Jan 19 21:41:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E47FBC433EF for ; Wed, 19 Jan 2022 21:54:24 +0000 (UTC) Received: from localhost ([::1]:43374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIuN-0000Xf-V2 for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:54:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjJ-0007wL-Ca for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:58 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:12718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjG-0007L9-00 for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:42:55 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJOXZ0031213; Wed, 19 Jan 2022 21:42: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 : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=pexGzxQuc+ozqqKuPRogMatRC6nfcMCb6cGBoa+pXa8=; b=SJJsN8nZDee4Jk5H+il85xkbzOTufu53br2rS3uVKT4y5y5XkzQ06NmIVrfjuGnYaAyU l/H9BvNVra5pK+t8X36NtCjZW4I29IJ65FvvND2ZvuT+ojTfwEsatVT6EdApZ1ixajmn enmFtBD8L8WcWjurZfKmTrB1N7Lrv07DzT4nK2xmfHLD+/YLB4TunUFRvfSOBUEsX0Pa 3naeofb+QH18cYifRCbdKBqvoUKfQ80b0GYNFvnei12Cr9QHTbAYxoBLG5hs1Oks5E4u tD5QirUwYkkP3jFtP24V8xzqtFG3Pw4nIHWlBtcRM6o5uAbi/bkn+3L+E/QWWqqbBYdp kg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLavnT147279; Wed, 19 Jan 2022 21:42:51 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2172.outbound.protection.outlook.com [104.47.73.172]) by aserp3030.oracle.com with ESMTP id 3dkmaeb6t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qmq4qGyfzENGglj7QghlXel6gyurliwBN1a8lb3rojfpMfbH2dPoTTzaaxfqqEZ+1zYwu1DFPZifIgU3kBkjB3SIdTcKS644fS62TjDV8rA0o9RPqDFKFpPxU04LCajGyg4BJBkIXUP/nhaTdufnlQ+IHxQ3Yk5TeeoBmM39NgmkouJOjhi55GuqU1n07AaLnazVF0efB4NAZI/Yj9GzgZ5EOnB78eJnYJPTbIK6OmL9k0GkRqE2pWNtRDIkKlNzQSSzQIqJEsI7EngIk2gv39783m2i8DOlXc+ABVuiGRuzYKS9+vE0zQyBXh9/Wb3WeifU/rEqst3AZTyOglcKlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pexGzxQuc+ozqqKuPRogMatRC6nfcMCb6cGBoa+pXa8=; b=Pp8RzmMZU6YO0xu6WAWD2YQLEJ2aCnEkknYIJBl3A/Q/EDJtrPZJw15w/8GARJaa2mz4+yPVPlFDL/r7fMqt8CvuaxychR6WFU4VaWt549/tLe2GSQHe6/vA1zRswt/D4xhZyrP3/W2JKn84hS9SC4JbCl0/p/lAFib3Rry0lqMEiuUz/mqI5+iQg20lLG6tVIDfopvPn4C4yrZdQO87gcgznBH+O4cDM69yz83RGDlbGYoEgugtOuEYzpqQt1lbS431onP/EeJ7+cMq4clslkTcq8oimuEi/vRdlY+wIYsFmgb4e1gtzTw0vU3cHwA/y/6A5kKNwVicUhRlCKJtVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=pexGzxQuc+ozqqKuPRogMatRC6nfcMCb6cGBoa+pXa8=; b=GNR5FdsesrtkWq2iO1qTldu40YdJz/Ds0Dd3OLOAfyphFM5hTAGRAKpVnxowgwn1PJefKfrbJj4mQKtBrvf6hKby3iLu4reXW2urrfZ14X57gYk6pQ7PpP/MtCcocejxw67A2z7OWXH/ivbqP4+MBP8k+nA30khpGvUxdHWwaNg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:48 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:48 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 09/18] vfio-user: define vfio-user-server object Date: Wed, 19 Jan 2022 16:41:58 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 905af95a-a405-4544-afcd-08d9db94a2dc X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:457; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nwD3yjVQt7WmxdPLNGVQVEovA4n6goUPF2HL6CJuH6TgySY65JqNCgxBJiNeL4QbXfFjAjErTcq6koLCZL4EG8thOAKn4CTjCX2U6OFWAH3+rgOSDrTm+xwWHM49GJWJ5ZkEFDBiTJ/7sXS2OYvzgvjJwRJI1MJFAyhRJRhmV/UlwfjcBN4YKAG0E+rOQ7zRzCRKJ5G5RjUuWP4kbn8ow6wknTYRApNeLgOcOb4pFbHYpLXzrJTW+q1ME9Q5Ps53RiD8spL/M41JY37158yeoPNWBtv/+s8tp96IvVAqy8RUM3+GrJnnF2mmVgFSUEYOzAzAAuHXrKLTMJXVO1Us/IamuNgdbLvWx95VzzxQbzZO42t4fenJOtycF9ZwWmcCerF1v5nrXNs2WjobkTV4bjZ4XwwP2kk+DdvMqj4wnM2VpABDbnJJyuQbVi/s5cEpCmNINRE/O6WMHbW1qKT8o7xPvwT+fwfHkhne6+ED+sQTjCR4iz/BDTrSyChxdh8ZXl1axCNwM2KFTndY9nyxnjrzGEmUHt6DNQTOCpX906AnKmwhI5DTTmyCYFIsI74mrb7NHP8pJrsFaaZGnOAE6hGzUJyZFqb4ehmaOaJ1B8C3pdMh5j7MqnCvkV9SAQxLPn73YRcVbagleSkd6B/BPxa9oN3pYYwYNijXyjrPtbQfNCEqNISr+wEQh3qb/CU4wfkcmK06fj4RdrFyMCD69g== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?L4/+icGPDYbYX9sdR+UTIxPfdAD2?= =?utf-8?q?rd2R75o7rxTMNiEUxuDbkxYi+KE2dgGd6KWvbmcWbkN9D65kSnSR4fwKBFVWtUT3v?= =?utf-8?q?dB9ucYeUUKgcer6dmznS0dYkGbryXR39pQfMNswXWtYP4qmEO/m/DLC5uBxHA8UlG?= =?utf-8?q?+Pv6gGZf3z3mtXMNs3fsqpzl9XSLHQg1WgOww761o1ZKAefsTzA4ByYN2bhZqKV40?= =?utf-8?q?suhV0y1LnKTicujZsYastIS6EcolwIL9nuz1ElCo3tlbobZb1L3paQMEeSEeU7T84?= =?utf-8?q?/7Yx/qMprgO+4tgh5nFhinc/NytT+ut/xf0kJJObkDTJYzJ9k+f7DGdyn2EAq4EWh?= =?utf-8?q?OcdQvx5IxMsNmqHIE6PQqJO8Zs2xah0QIqKhlfKSnG/WJ22Yr5gKiSbXljMGGxuMv?= =?utf-8?q?xdGIo3TWNWRt0Jx7BxlQFvWMPn7X6lXC6Y6+ePanT+e15NSntquQ8LcHzdn8fVvd0?= =?utf-8?q?rPmAAHnGJESEsfXU7xhd5WMiQYfbLiSyCNu7iv7VUfQ16E6HHMAKB0ZUPfNkM7UBG?= =?utf-8?q?ZszVP3sVI/P1EX1twLAMfXOzvywESy46CRsKN2SaB6ShDE7CyvU61J9TuKAAOCU4s?= =?utf-8?q?AOcRF0v/V9OWrhOGcF5IMqG+kYKR8g5mLl4T+LX7b2fC9nBd5FUGrriFJWJbUp/zX?= =?utf-8?q?bAlj47XOsFZpacUckJ9tJu+uA6ow7MT4AzumFSycO4YXUpuorK7fQjjkN7ggfZ38c?= =?utf-8?q?V6bkWoces5uyTObFx/4Oxu2VJFNFK6e1OKg293frdk2cfS32RJIvbSkEUWdLST7rm?= =?utf-8?q?oisNYPHp5zyFnpY6Agcm4tjN94hCEZCdB7ROVUvm3qjgY/dY3X1iKSAAHod8JcpzL?= =?utf-8?q?WUguX6qRTmQ7ROfAMRes+gbYKVsqWTuPmpHO3A7oxb9+K2q7SFIpUWnX6/SJNv6H1?= =?utf-8?q?dHBZKFlqCF6IBQxGo8KQ1mGQg8rNtyadKlTqtCKRfiZ1bWIutoTwda/aH6VyPEu5m?= =?utf-8?q?8UUEbyLuqhTwy25zIPp+MzfgnELCIltgBqqHc0xit10yskZzFw17EplP/bbB4YDDB?= =?utf-8?q?jNvhLc/rYoNXv7KFlMAhVtSwPuKZF5BL//TjWHaeu7t/Mb0fsilRI4XJFLKbNW/xo?= =?utf-8?q?JYVWBAZS+QxeWfmE4a+rPwLPQg0I1zMWQxbCOyfYQIiXeGE0abr02eYd6ygzjNaEA?= =?utf-8?q?CSRUCVSgH5elC65OU7umVLPAPD6xZEMhuh0uhHZzmWSa2Sttz939qxrsoljZ8VcrM?= =?utf-8?q?J/bg5tLv/49MzmdAG5ECt7FxWOqRZRkzUCGAMWh4gsxlD8xohdSm86GR0+DwRmFQ3?= =?utf-8?q?STe2pc1iAJPJnJwnkCKRyfg8n4tg4DNStT+BLWHPnb2I699qYOnuQTpBONvK6ZaVe?= =?utf-8?q?BczlZMMUoEkl15XKi0A4ABkwOiYuNCSvf3KJq9r4+f2R73HtATjMNW8ffzOg0aE4k?= =?utf-8?q?VEpgqb+aZ6VwD+75NcgG6s3P2TK+ArrEGc6NaOgRVuz3oGTc4Th4gyNDt5AizmIx3?= =?utf-8?q?ECUGSs8ysBQfoIDt1ZnAqnGFUT8bzQW2BfmdTraF6qMq/mVGkce6Tfe9kTEBjV6eI?= =?utf-8?q?7VFZzSbaJ6IhgtEnWMdba2FC3O7h52tSNqWwr4vE0cd3DDVGTo+8EDc=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 905af95a-a405-4544-afcd-08d9db94a2dc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:48.5212 (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: AFDR6nNZ28+2BIq83kaSPaPpgUsWSuhvOnMoYl4Dm7EM0EpM+96yRpIaAuwzHtbOWcIyQ6p6kLD3a6ggbzY0Vw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: Z5EnNbozWiNA5VRglmXtz4l-u7hEbV17 X-Proofpoint-ORIG-GUID: Z5EnNbozWiNA5VRglmXtz4l-u7hEbV17 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define vfio-user object which is remote process server for QEMU. Setup object initialization functions and properties necessary to instantiate the object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- qapi/qom.json | 20 +++- hw/remote/vfio-user-obj.c | 194 ++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 5 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index eeb5395ff3..ff266e4732 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -703,6 +703,20 @@ { 'struct': 'RemoteObjectProperties', 'data': { 'fd': 'str', 'devid': 'str' } } +## +# @VfioUserServerProperties: +# +# Properties for x-vfio-user-server objects. +# +# @socket: socket to be used by the libvfiouser library +# +# @device: the id of the device to be emulated at the server +# +# Since: 6.3 +## +{ 'struct': 'VfioUserServerProperties', + 'data': { 'socket': 'SocketAddress', 'device': 'str' } } + ## # @RngProperties: # @@ -842,7 +856,8 @@ 'tls-creds-psk', 'tls-creds-x509', 'tls-cipher-suites', - { 'name': 'x-remote-object', 'features': [ 'unstable' ] } + { 'name': 'x-remote-object', 'features': [ 'unstable' ] }, + { 'name': 'x-vfio-user-server', 'features': [ 'unstable' ] } ] } ## @@ -905,7 +920,8 @@ 'tls-creds-psk': 'TlsCredsPskProperties', 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', - 'x-remote-object': 'RemoteObjectProperties' + 'x-remote-object': 'RemoteObjectProperties', + 'x-vfio-user-server': 'VfioUserServerProperties' } } ## diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c new file mode 100644 index 0000000000..80757b0029 --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,194 @@ +/** + * QEMU vfio-user-server server object + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +/** + * Usage: add options: + * -machine x-remote + * -device ,id= + * -object x-vfio-user-server,id=,type=unix,path=, + * device= + * + * Note that x-vfio-user-server object must be used with x-remote machine only. + * This server could only support PCI devices for now. + * + * type - SocketAddress type - presently "unix" alone is supported. Required + * option + * + * path - named unix socket, it will be created by the server. It is + * a required option + * + * device - id of a device on the server, a required option. PCI devices + * alone are supported presently. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "sysemu/runstate.h" +#include "hw/boards.h" +#include "hw/remote/machine.h" +#include "qapi/error.h" +#include "qapi/qapi-visit-sockets.h" + +#define TYPE_VFU_OBJECT "x-vfio-user-server" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +/** + * VFU_OBJECT_ERROR - reports an error message. If auto_shutdown + * is set, it abort the machine on error. Otherwise, it logs an + * error message without aborting. + */ +#define VFU_OBJECT_ERROR(o, fmt, ...) \ + { \ + VfuObjectClass *oc = VFU_OBJECT_GET_CLASS(OBJECT(o)); \ + \ + if (oc->auto_shutdown) { \ + error_setg(&error_abort, (fmt), ## __VA_ARGS__); \ + } else { \ + error_report((fmt), ## __VA_ARGS__); \ + } \ + } \ + +struct VfuObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; + + /* + * Can be set to shutdown automatically when all server object + * instances are destroyed + */ + bool auto_shutdown; +}; + +struct VfuObject { + /* private */ + Object parent; + + SocketAddress *socket; + + char *device; + + Error *err; +}; + +static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + visit_type_SocketAddress(v, name, &o->socket, errp); + + if (o->socket->type != SOCKET_ADDRESS_TYPE_UNIX) { + qapi_free_SocketAddress(o->socket); + o->socket = NULL; + error_setg(errp, "vfu: Unsupported socket type - %s", + SocketAddressType_str(o->socket->type)); + return; + } + + trace_vfu_prop("socket", o->socket->u.q_unix.path); +} + +static void vfu_object_set_device(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->device); + + o->device = g_strdup(str); + + trace_vfu_prop("device", str); +} + +static void vfu_object_init(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs++; + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_setg(&o->err, "vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + g_free(o->device); + + o->device = NULL; + + if (!k->nr_devs && k->auto_shutdown) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static void vfu_object_class_init(ObjectClass *klass, void *data) +{ + VfuObjectClass *k = VFU_OBJECT_CLASS(klass); + + k->nr_devs = 0; + + k->auto_shutdown = true; + + object_class_property_add(klass, "socket", "SocketAddress", NULL, + vfu_object_set_socket, NULL, NULL); + object_class_property_set_description(klass, "socket", + "SocketAddress " + "(ex: type=unix,path=/tmp/sock). " + "Only UNIX is presently supported"); + object_class_property_add_str(klass, "device", NULL, + vfu_object_set_device); + object_class_property_set_description(klass, "device", + "device ID - only PCI devices " + "are presently supported"); +} + +static const TypeInfo vfu_object_info = { + .name = TYPE_VFU_OBJECT, + .parent = TYPE_OBJECT, + .instance_size = sizeof(VfuObject), + .instance_init = vfu_object_init, + .instance_finalize = vfu_object_finalize, + .class_size = sizeof(VfuObjectClass), + .class_init = vfu_object_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void vfu_register_types(void) +{ + type_register_static(&vfu_object_info); +} + +type_init(vfu_register_types); diff --git a/MAINTAINERS b/MAINTAINERS index 8d7bebc74a..93bce3fa62 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3487,6 +3487,7 @@ F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user +F: hw/remote/vfio-user-obj.c EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index dfea6b533b..534ac5df79 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -6,6 +6,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 0b23974f90..7da12f0d96 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -2,3 +2,6 @@ mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" + +# vfio-user-obj.c +vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" From patchwork Wed Jan 19 21:41:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A640C433F5 for ; Wed, 19 Jan 2022 21:59:44 +0000 (UTC) Received: from localhost ([::1]:52050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIzX-0006uY-OC for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:59:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjQ-00083I-Or for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:07 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:17258) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjJ-0007LM-2V for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:02 -0500 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 20JJPAPf032601; Wed, 19 Jan 2022 21:42:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=hcAm8Ou2NGwtdnTeIh2r4xjRA/UjBUC9LZPE1HxivcM=; b=p39sTncQJC6LxJnFSxtwGLtbxvQ11Dgy7RqYzxv7z3oq1QIpJLGEkZ1GSgyy/pG+3I0R FfEMEkhrtakPDccoiVUGzwq0nPQHPpQVhsg0tkoIxS51yT+gpxJcQzRSJu1XnlNLepJr 5cN6eqPo0gsIxwpyNdvVDr+XtDSON8ViQ6HQ4uWfiV5SDH1mHKrrRWUuDM1f9kqkNXML t2opeebusjghz7QV3x8+QRAPXFXpXUB8IpNur3TGF5MuWig663wmnMBG+5touZeXkGAF Cyn0eH6ZXjilf7LTZw5RKaeXWBf+CcmV2XjAPFvnbnQdBFfEJihzZaj5eUDdSnYi2oZq XA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:54 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLautH147107; Wed, 19 Jan 2022 21:42:54 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by aserp3030.oracle.com with ESMTP id 3dkmaeb6v5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lVmVLJy4fQiZx/GALP94wniXVWnIPbqkz8T9ZbfgoFMpUuhDBmeTLGzmb1dIDoFixG/QEO/St8vU8K6lejlT62w/S0a0Ufh/S2ntaiP7kG1s0BWAF+4kCXFM3jONzGeFtGmD4yemdTceN2a+jLS1vuTP1RhW19rmehAIkIO9Q9L0eEKDfnToEzuVkV3Uq2TgJXu5vH1pArHP7W8Z7bUbdbIN10aeHVfeBZ4ReBJgJgwnKPiz/uYKACiNBIsimnmiuwysIrkqka/1AgSOnZlZ4nJ2hQDeG8luJ11srVhUsqFvVHdZE5m/JwkA0vun4SCSe580wB69JYJM7N/Wldve2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hcAm8Ou2NGwtdnTeIh2r4xjRA/UjBUC9LZPE1HxivcM=; b=b+KSH2GzPKkKahNSCg9pc1WO+qHBF6gjLLSR7DYQl5w88xqXdGjJKCzB62hlOd7QsIdDsh6MoZlRgoScEVdna9fGdmbi7lMJr8iQ/NIk9GIrY+6DW8SPDVyChYDzW7NRY1jRncMX6RSR2GJTDblCqBmuhG5u5poiL40W2AFY6LRWbEnszK/j5yXyNjIqlYNfeicIvERjejbeH2N/kYkvDx7yGQfANlYje+8qhs/vMSRINCcSxfiqz6RnpEni7PvSZRIn/oAGY56b/dYAlyCBzvWClpxcdIm1uSuNt2jN/Up/tjc2gULcibdotg34pbrb9q7j/NFlaUB6rzy1p+PtNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=hcAm8Ou2NGwtdnTeIh2r4xjRA/UjBUC9LZPE1HxivcM=; b=BORxLFyig4nMUUjZs1uHfScqMMR3BBgfS5MiuMDPBpI+eh51JBiW3PgPST937cMfw32UPa51W9AB0L2M7X2nKbs6EAK0wVwwJdKDhN8vImctuFT1l/mQ5UqBDWy3xH4W8DhZ+PRxdxriskerDs/9FLCIDozKn5IZHcJM4fUKw7c= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:52 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:52 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 10/18] vfio-user: instantiate vfio-user context Date: Wed, 19 Jan 2022 16:41:59 -0500 Message-Id: <66bb8c18bb5372f72aaa66d62f09258ec7775100.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9d7daa0f-1e26-4d0f-5241-08d9db94a4f0 X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:179; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m9Nq7x5OE8K9QcgXbJ2fxhLCO4Dm92LlpDrwWEPu7AbuUveOq+D0XE7NmjggwdXEJxLPeYtOXA3+kV7wfE24lBEwM+3nBr2yvbnJvQbDJCfuX0BV9q9rnQwisMBfb8ShmhRYzq0E/EPTBrdWCBwXY/IIWkxlQu0as+KVHmnFajXX2PHLqKFWGq03KSN+J5qzqu7TOPIX0Goy81doKkAFzm4NCVZtyieaCC8/4jXAgCSwywmSJkPW3lLCm7OhR71WjpaHev9FeJEpDB1mas5MeByJNQw+qtEUCsy5mCYG6lWfJsMLDkTM4No5ttAo2iks3Rz5y0zPFikMUsF4Vb9guLHjupxbB4KbbJLTXjuBG01MKDFofjxwB1Bs/fbJz7OeihedfmtX1iUjaiU3wBa1Yi3BF8DYFpXzugYkqW5cuX3rLRO9XW075h/B12XXqRlXt6zIQk9ffZri60AjWz3SzJlWLHZL6/qXjigSpsMf3eP8Ei5eGhlFh8l7lBVD4205bViD2jnp2z+IYWZjpucNsFhKhGMs8X0HRRxgCWen05+cmtZR3z0ZTOlr6Rc97IQ1MRPG//VxzxdmOoGFHNMfKJKWce9gwTkiK4NouwMTfhpAaDANb0kC7d6AYNMSqDKbReL2ff1o62eT0EDejh+GJqI7zrvFa1Qri8diVOUkqFaEqVpnwlzpOLCAYd/po2+5qQTry1OeQvDt5ZN8CSKJXQ== 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)(5660300002)(186003)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v9vwbkLHFUMexE61toApt/NvM7SkHhJMF7slK/NwoUJsp565uN3yJkSRk4xDgMXcrxQSfr0aVIXOghNagpgTfnca0syq/6ycBiIXneqzn8n1qTlFDr7QwzhSBSIL5cQ8uKHbvIcTQrJgSUUU76mLnmmIngHY4VkweDN8xa2RyssxVO7SLZ+8iv7EosBo6GgbNq1BH+rB7+skkkvdYZdWMYtj+2zlCQ5makb8m54Vo6mN+wUKWC+v+HYrxnkuv72+Sez0E2bP/q5QiJgEFKzIRpD/n8s+ctbdwP7O6dwXt73H2yjyIgoxd2QT+OWXFCJyC+VrEJA6M0YX30ItNPdodnGAUB7K8gxd8dPtEP9FdSDrtkpUO084lM623NkmxlJ5sF+xU/sR92+4n8+tGtP0BviXs/5nURMdAdny+tWMZmXMUnh9O5bMc0gLd4BjieJ7wvpk+6hqlsqzpb8StwyLcevGwew6/nwljq9C1HSTxDsdiDonNE2Ols8DZscJ1bo2ZW9btAps3+2op6a6ycLXOQhbdn/F7R/5Tm7Ghx0mhePEAU6kDr9A+bwpDasXma5UDQ+1KQb0Ewh7NvknNyl9ScbydGdUsoSLM+inuKtUICXAUCtdmBY4hWgfq70wW2CK8sES+tU+LiQkUxlEbUI0nH0dwheIFnsYKFNDWH7/aKXVBFPBJ7Au5jpgBsv1OASoaxkw41LGldFy0LG1MgPNGoJkIDdu8EQ8lnKLZjdG+Imrl/JoupnKDx8KvGeiHLemMvVAOtdRGIhan0zM9hHW7y9axaGqIUi6ZFLpltvLpyj5SsCRpZTKvrr8ICAh1AiLv2rtKIQ2psi2T7gZRdE8zZdQr7YEqNXUM56MHIoEKSbpoV7khSvnmTm3WxyjuSI1JNJItqjO0Nsv5/Ua2SphefvmqgSqJ7CZQ3que13qzMBmhzG6SYut6ThdDPwNFLMt34CXcQtEgfL6UNDTOGOyMBVU1t65wP5uoIQ25HHL2Q5EtPETvvH0jBqTs7YQU3EDUBUW2dKk0xe4QvCahhLK/BL5mCXKrsiOPALrYzGo3gBhmz8HLf40KVt3oWiZZhi9wrjmBpIdLSiBLev+ToqLITEtcNi5Fnk4SFeaUHPrGJ8XZrCuOdBSZ5mcn9X2nzI1kzgqXgLDme7TzqhrURFU2vSoIe1cSZLT3vsy0+f4jfUN2PhB1Kdu79uRLRXvSJjuedstL2nsPxvj9763lOrj4X5GWIG6kgCT6rhvMlEp1J0IAl6JRyx5U5nj3hXQJJdvTFlcdNIQcvWH5ripV6pLP/jdyU8Efvx7X7WZk9FSaxS69vwF9oZXWJ3eWUbQSVV+66ePk5oUusl77dJ7ACZZZBXgscoPPfwQDtDgkPuyCzSPx+ty4Lq4qOT4oMabHqUPT5LVSX6zHhThXzJFRYAAkXQwIKJ62R1HETsiY++DZ0QSw7gMmGJOEOXuEu29U51wuNj66QBfNjTzHvb3yQUuITahfCuMTif2aAMOn3GFUqmEqsy6X++Jpl4wab0AVYVlf+NWgK+sDoSlqNI9tUnr3/6+oNp0/mJuskhdP1O2JrLQiWNT0G3xCw+T60J/OyiuUy5szU+2MohB2xDIbD7l3tEspB546FHHG4OuJkg3x2U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d7daa0f-1e26-4d0f-5241-08d9db94a4f0 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:51.9897 (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: xXzQiDx9QYJ5Y1kG4Qb/Bu1oF6F3bpSn5HOEEZ1IrLzwh08L3n0Or3eJ1Cum2VWqeetYJo5hPNcb6f0TKA8hlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: _LP2CEu6Z8rrBLVbx2JLdQhpo8Sjw1X1 X-Proofpoint-ORIG-GUID: _LP2CEu6Z8rrBLVbx2JLdQhpo8Sjw1X1 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" create a context with the vfio-user library to run a PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 78 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 80757b0029..810a7c3943 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -41,6 +41,9 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qemu/notify.h" +#include "sysemu/sysemu.h" +#include "libvfio-user.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -82,13 +85,23 @@ struct VfuObject { char *device; Error *err; + + Notifier machine_done; + + vfu_ctx_t *vfu_ctx; }; +static void vfu_object_init_ctx(VfuObject *o, Error **errp); + static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + return; + } + qapi_free_SocketAddress(o->socket); o->socket = NULL; @@ -104,17 +117,68 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, } trace_vfu_prop("socket", o->socket->u.q_unix.path); + + vfu_object_init_ctx(o, errp); } static void vfu_object_set_device(Object *obj, const char *str, Error **errp) { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + return; + } + g_free(o->device); o->device = g_strdup(str); trace_vfu_prop("device", str); + + vfu_object_init_ctx(o, errp); +} + +/* + * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' + * properties. It also depends on devices instantiated in QEMU. These + * dependencies are not available during the instance_init phase of this + * object's life-cycle. As such, the server is initialized after the + * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT + * when the machine is setup, and the dependencies are available. + */ +static void vfu_object_machine_done(Notifier *notifier, void *data) +{ + VfuObject *o = container_of(notifier, VfuObject, machine_done); + Error *err = NULL; + + vfu_object_init_ctx(o, &err); + + if (err) { + error_propagate(&error_abort, err); + } +} + +static void vfu_object_init_ctx(VfuObject *o, Error **errp) +{ + ERRP_GUARD(); + + if (o->vfu_ctx || !o->socket || !o->device || + !phase_check(PHASE_MACHINE_READY)) { + return; + } + + if (o->err) { + error_propagate(errp, o->err); + o->err = NULL; + return; + } + + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o, VFU_DEV_TYPE_PCI); + if (o->vfu_ctx == NULL) { + error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) @@ -124,6 +188,11 @@ static void vfu_object_init(Object *obj) k->nr_devs++; + if (!phase_check(PHASE_MACHINE_READY)) { + o->machine_done.notify = vfu_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); + } + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { error_setg(&o->err, "vfu: %s only compatible with %s machine", TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); @@ -142,6 +211,10 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_ctx) { + vfu_destroy_ctx(o->vfu_ctx); + } + g_free(o->device); o->device = NULL; @@ -149,6 +222,11 @@ static void vfu_object_finalize(Object *obj) if (!k->nr_devs && k->auto_shutdown) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } + + if (o->machine_done.notify) { + qemu_remove_machine_init_done_notifier(&o->machine_done); + o->machine_done.notify = NULL; + } } static void vfu_object_class_init(ObjectClass *klass, void *data) From patchwork Wed Jan 19 21:42:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09AC6C433F5 for ; Wed, 19 Jan 2022 22:01:56 +0000 (UTC) Received: from localhost ([::1]:54560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ1f-0000QW-QC for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:01:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjY-0008AC-Tl for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:12 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjO-0007Lo-Ta for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:05 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJSHhK031217; Wed, 19 Jan 2022 21:42:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=VvLaKghGHkfMRIeLcQO6s2fhXUFykfT/mytk88XfCks=; b=I+dou5EsfxXH5IfG/Rc0KkTPkwmgfeRF06mqTSWGd2zeeBft9vTL+7gc/oQODHnwNwOJ GADkdcbVzLtxKWSMvbUu81xISyE2pwaOK65Wbn+apzeF4z975ouKeL4iAD+J+LzS8lkw 9ywnbE+MWxRWSXLZYw2JM/AuOf37ihlvcyRONng8VkgGMPTc13ZhDr4klj1ouTGXcoql 8+LDDWodGWm/ihf3tYFZK9ywRO+Q5MtCObKHuRTCun+jwVKGwbWTxbN7VpBYUI8b8r9N vZK0ZJ1rhcuSA+gLmq1uzbv31wRvpd+vle2XHc4Bbj4wFiJERhdl3LzrKG6pgxp8imqF eA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgpq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:59 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaTuO030985; Wed, 19 Jan 2022 21:42:58 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by aserp3020.oracle.com with ESMTP id 3dkp36kfms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:42:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHV1cp8eZeJ2ObtsTst8Fbg4yapVKLhwDEFv2CXKlnTFED5P2vlZ6iq1qAmxUsDkUxqZsYEp1JdZE2xuqZrPsLMLzO/2Dc7FZT9/LDnFmKyaZw4Ytc+Lkt6hZ/pXOWXnPI17SNk/uLuwEtJiJS9X3OVR2Ss7nmiPgiFILcp2HxIOtCRj0mGWeB9k0O7Msd+4HxrvMVKJfvUOFkkTP9u8tvYodo3wjl2l/fcUYnarjPJqRGlVoDwV+l5dGQFDyQaKRelBBCVYn+MnNns5hBV0XLIKuqpsuSPGAXG+elOrgL6CgCSqAARxyTIqhd/U0bJreXQPedQ3UFhn4XxsmT4vTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VvLaKghGHkfMRIeLcQO6s2fhXUFykfT/mytk88XfCks=; b=ISaR879GHXuLV9yCjMy+mLwIMBx+JX67bwDA0Lp3QUiOo4jiZ6fp8p4B6qGWlF+ftjMaiBYwcPf7n3fq8FQYPn1KOe5+1+DV049zkkOhmQsfHPM9cy0dv4R5A5L2w+wqCon9s+pTPHF59f9DPW0MVqEvyiG/9jUF53smLNbsGL1sZAgAYUWJLOpqQVHFlL4zNJR+diid7OgX059lAAeseVYKYTeHJSeIfKRmdtCfx+zgtdI7PlF+UdS0ScwmNY/e/BOfRcBKA3eB68nkJ0gJLsi1znTGarU99OrTuYWgA/4O8Y6530GlVfQy4mMz05BYvgK2JgSamXV1FFExlg2FjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=VvLaKghGHkfMRIeLcQO6s2fhXUFykfT/mytk88XfCks=; b=Bx/3n8CVtcbQjNZ4smNUVgodi3a0opIJeTjmUaoaLLk2ijmG7QKrrSi2cmWlERBzCGC5+Gb8YoGBc+WFG/cr6de6Uys+e7uYkhNpg+q6oQOFvV99f6NnYi3Tw8AyZER1C8gZt6aW7BJgx2hLCAfOV2s4KI1e8BaLbdPLmt+gqvo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:55 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:55 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 11/18] vfio-user: find and init PCI device Date: Wed, 19 Jan 2022 16:42:00 -0500 Message-Id: <01f4837eaa73d340542961cf36a6028f4a681a0e.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 970b4684-aaa8-49d2-3004-08d9db94a6ff X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:241; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Tqp9q2RTPxyFs00z702eLDZHziDZ5sErNsnyswkhcteLSip08fzCvvfoSq81o5qax1lwuADNBQeCwF03f/oO71rrPKBEUR44QmDcwOzWlPEhtD69C0hfLEU2Af7F1sRsrqLnRMJtGRwEofc/ECtgkCUfr4O7DWPxE6/r29Ub4Xprhlq1JiHD0jhp1ookGfAqkVB92AXVvW+6eKptIzmfNivWkP9Z8xxkcJRm8iShZJTerbKJ9YDeDDMBToO7SYhLpcpDEaFWMhCMp8D3YTMk0m25nuNnvFndtYfdUPhC7r8FefNPC8fRIfeQubCjp5uMYwUa+Hq9SH72rUbnAFdPKUD7UIwJmXnCnC99I+/JQ9rFGazDjcq8rOqtZSKjaKBiKlQQHNMQLr2bgagyS5aPKzXo1lmzU1dP/xCFO01FV08ywtjoWwY53aXhMFHmOpbZy0PxFHyleKgvGIrcgKPFWRGttsr3Vyb8FQcDUNYrbbqPfAjOlGRO0DUe4X3FmPF/DdupR0y8KQYbHwYGE6K/pyOYJNVMcE1y5m/VdEkvCq2C1Zwots8+l7jQK+WkAKHLrBmQq4yJbfgJMUPuHembVnnVu7ozjrqAhpxamV5unmiiqzbL/UhWaHk6bI2trVEAHEs95aM4leU43X7//U/v8d6K4BTuT4Ga7V4Op+SodAcH6kKXTpuKDPmjdGiL0KmON3TDl3BqmgJaWai2o96TgA== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k86dSUiialveHQ+kSMlJaIHLKMhUTf8UoB3Ow6G91pWO6JiLFNm41wl8ohK5pRS73w8+KU+Oe1p8BWw2RHNHNSgIFo0/oi9iQ4reHFcNXUZQrIqQkWCl1wuuN6gYhKKnM8oozAZs8FbsYfc+NYiS6Lws9we0yiDg252TSNfk2ZvQSLwsw0fOW3zf7kBw3jnk+ubDnwhKZXpEI2UR8BFeen9iZbuGIqttMlONcTty5nH8IOVEa2tz58TvBqZnLMKj4YsnyU8R/DTmIDSYEt4qh2/Efl9XSNclRKRaUj07E10hLnj4mpkHKY8AfgVXveoR2lWs9XzEjB0YXvSr5lGUGZt5N+Tn3/RQ7oM00RWVJlm4BaKABixoChEH8kL5iB3M9cmFm5oPFt4bdRxoGmcNKN9gFCkjjwo4zOa++/HAmCZgdiVpNxiPUk3HJ8HyccMQVCOk+Nz/dvLw6bEVFQRvOogrHX/CGUoeCZ6uZQF4Vqpd5sHyWcnCPWZCGcSVQ/3j5qEZwm7t7/hPjKwA6ciHmbfHMnbE4RoKGv+tUKp69OzragxgCYhIPKdH/+2wO5NPGHkCIPJrAyShUERk5x+FUL0985MCf7Cw9ZaXxOKm/pJv9mZjn9fNZwOJjVP6kiol9w3aCdZYf04vhAB6Nm0gWbPzIo5XFeFsCny1HA48xN1/SIyxGB5JbKJUUVd2zJO5gYfhPgzTIS5H1zceP8CdSEpOkF6uYlJvgiSVohVJl61ATi9u1PQtzc74d9RzagQUIe+5Uhmy4VrlHxJ41epHWu931n307+HzrnTCL2+fTAG35/7xLHCE0W9Okfy5fQoEs+gL5zhFKeC9F1AlRTQoL6i82u/3JqZjK0GsGPDm7F8SVS7VmT/OEoMpwfEvHA2v88Y/M4nmI0H+lAANWlZRW+nMZhoKNP6FDPWu6dQECtRQ7ikUorfcxn2MiOtnkQqmcdns6CAamZgVML8HybH40wF5HgFoeLM3CQ16VbowBtC1y50+W9KzsD2Jsd4k+UlIMYX3pTjmAPiQvxE37CXf8x4uUKhm7F5hK74+17Phbbdukxyc2dXXYFkBE/R7/AiCr3iHddz41ps6OJnWJi0cTVImt5gVactA4ITG0yf5Q+K00cyrE5GXP+JY62wZIJQI+Mra16zEpxGz4zkY3jGgR5oKXziUoKSF56cjioWIc/gGKs2Dv9sx8cfn4zCPBu+EmkRAUYO4X7jnYIsLmgKpP+BxQCUgJ4Sy42ad1oBDLbZ/WE7D8+9k+6TvZ9q5WAdzfNFeV1l+jp4C0gKArvD9W5qb1dXOmFBwx7eQDkh0+01TkDSKVUg1jntRVNoq98VkmHcoRbXKLxADw5uRQtO/EEIhYZuGgUtiAwGDC3adXdy0kAxmUt7YQDE3LU1LrYixTfwGlUnGqLmVMrHLxph1kXdc8Aw1BkrkJo+ix/9Doj/EsuSlR8CEckrATdZgQHpw8QlA0xSdAJpSbrCv4sXZbtP0IXR7GUrLMkpXfv+9tWMaZGXp1SoT9nHF933xtxFCXIU6VxQaNY+VSgYvZIh5Q8WwQHGsuxz5tcrrrkWZp+s01Wk4R2kTHjkqHG+MA3+GVqGIC3YznApHkD68iGTni9WCE2P7R66VUYd1xbyOeL8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 970b4684-aaa8-49d2-3004-08d9db94a6ff X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:55.4426 (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: sgyPHyJkgDVR1ElOTl0auI1+UgfJUFzZbwpYlcLVbn0PoiHUOZowv2Cu1tJL6xONpg4n4dA5QP57mlrOQ3hoGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: DGiaLAyKL0VnKhmcxJQhVOdtA8-WPfMl X-Proofpoint-ORIG-GUID: DGiaLAyKL0VnKhmcxJQhVOdtA8-WPfMl Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Find the PCI device with specified id. Initialize the device context with the QEMU PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 810a7c3943..10db78eb8d 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -44,6 +44,8 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" +#include "hw/qdev-core.h" +#include "hw/pci/pci.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -89,6 +91,10 @@ struct VfuObject { Notifier machine_done; vfu_ctx_t *vfu_ctx; + + PCIDevice *pci_dev; + + Error *unplug_blocker; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -161,6 +167,9 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) static void vfu_object_init_ctx(VfuObject *o, Error **errp) { ERRP_GUARD(); + DeviceState *dev = NULL; + vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + int ret; if (o->vfu_ctx || !o->socket || !o->device || !phase_check(PHASE_MACHINE_READY)) { @@ -179,6 +188,49 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); return; } + + dev = qdev_find_recursive(sysbus_get_default(), o->device); + if (dev == NULL) { + error_setg(errp, "vfu: Device %s not found", o->device); + goto fail; + } + + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(errp, "vfu: %s not a PCI device", o->device); + goto fail; + } + + o->pci_dev = PCI_DEVICE(dev); + + if (pci_is_express(o->pci_dev)) { + pci_type = VFU_PCI_TYPE_EXPRESS; + } + + ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to attach PCI device %s to context - %s", + o->device, strerror(errno)); + goto fail; + } + + error_setg(&o->unplug_blocker, "%s is in use", o->device); + qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker, errp); + if (*errp) { + goto fail; + } + + return; + +fail: + vfu_destroy_ctx(o->vfu_ctx); + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + o->vfu_ctx = NULL; + o->pci_dev = NULL; } static void vfu_object_init(Object *obj) @@ -219,6 +271,14 @@ static void vfu_object_finalize(Object *obj) o->device = NULL; + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + + o->pci_dev = NULL; + if (!k->nr_devs && k->auto_shutdown) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } From patchwork Wed Jan 19 21:42:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717804 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A613C433EF for ; Wed, 19 Jan 2022 22:04:20 +0000 (UTC) Received: from localhost ([::1]:60538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ3x-0004ZW-NG for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:04:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjd-0008L2-3N for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:17 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:32808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjY-0007MJ-MI for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:16 -0500 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 20JJPAPi032601; Wed, 19 Jan 2022 21:43:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=myQFFWXBm1Jj9OwCK5BRkQ4acoQDUBpxg0VTdyAhmYg=; b=d6xlA5VubXrfyVu6prDL06MYZVubGMLdJyIITvE4zAZ28b9Hc1qFIf/x2erlW5oNAbb2 MJOyplY/6TILchqcMDE9I9cIYkYTneTCIxRB0S6T8P4zBBkH1kv7ENJbPINklK3bQpRz g/DbB7D5AwCjumffZWvqnw6Rl6a2ZCxB8tNPXF4zFbe3uVSMA9CAM2sMMwbbUOkeqLxa aaHnnUyl4SOUjZkCGyPoc5ZW7VETNuo1stHZpZJ7WP1mDLwkFx+gtWwk388jnAIzknXT xyQVpGmWJ288LNGz4K6aMPuihWnTawozPg7VztFqh+QYYoceQkKYhDHkcbexI2G+7vvK EA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q6hy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLa7pD131830; Wed, 19 Jan 2022 21:43:01 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by userp3020.oracle.com with ESMTP id 3dkqqr65a7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jriNLL3YW5Zkbgf9jJ8OL7cgOyYvpIsGNXgZ1JeGy6BHq3gaW9zvuVxJu0IiDzgbNOyICM1vlO8SAAkCHjgB2wHMI1UmT3fjeZzwiukRgUNWwhoG5T0WKiPErWtStD0hORM7gn5fI08az/Tq2utulSwi+lp7GDGTn6RTpojoFmZgn1Am8JlE2MuYT6xoOwm1ORCePDvW+qkBu8L/lECjHQXHTYN78KkIn+LdH0O9UuGFR6G5bOWYQ4raIfjLj9Z9XVXVBkfOaf5j31aul94MDRadqec0sZYKyJNGjnj7gI8vAKL7DgL72JVFAfZ0Sb/YINPq3sM/GvF1EK5XrIyEkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=myQFFWXBm1Jj9OwCK5BRkQ4acoQDUBpxg0VTdyAhmYg=; b=X+uDoqcMNhuag30NTfc3HOeWTCq52LXM12lnRlerWgXLTbbqhbqHaLZVSAfo/MR6aBSLzzKsWwMO4sSINDp7A7KZ37o3rCA3229eLi/m03BaXPRn/oLTlgPorfrLb0Zbtpwyr42UYRx0tKmu4DuwkJRrHGtwxGIGniGYjExo2K5WUSkWPsx5ah+rKtDlsMTvRZjrYhA0dLEgCvNqGKh0ygMjU2sCNQqyxNm4wJiMpvBiuZv5dXMaKkyImvhJK7p5D2CpGIsP13CRdsaOXAganPTXvhNQ9jUpbITpQ8kNoGW2/pkW3kd7aJUW0xsVOZuwsI6849FWN27hQirvkJAZaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=myQFFWXBm1Jj9OwCK5BRkQ4acoQDUBpxg0VTdyAhmYg=; b=cF9XY4dKJPwj2niR+lFk5TFMUH/x3zKO6A9ur1jHp9wyEhU8i0puZsV4B+y7ygzRfiWxJqEkervCJ3aZaRMcrAKuEDqGy5Ea9p5PXSxatihcAqEQfVNXZpGBwnUWa2XtxS0NXyakKHX9rDf/301+2Rh+7cwm0P4Z6giFoqvfJOk= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by SA1PR10MB5887.namprd10.prod.outlook.com (2603:10b6:806:22b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Wed, 19 Jan 2022 21:42:59 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:42:59 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 12/18] vfio-user: run vfio-user context Date: Wed, 19 Jan 2022 16:42:01 -0500 Message-Id: <63ef44664629ffd07d3bffe60351e808965dd13e.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77238885-8701-41ae-0dcf-08d9db94a90e X-MS-TrafficTypeDiagnostic: SA1PR10MB5887:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:608; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xYK16RT1mFXuTCi+/s9YQwtAJTGnRNk2+IUS8EdZNTBoaL7hcAZSFBdIxgTwq0m4Eg9a8yerC/DUMNQYEGWCEmfHFzNRwZ8nIgvOnGPuWT5bTBUibYGmYpP2Lru6jpOYQAhGbdZcPYO8Q14KsNiirTwo1aS6LDTB3kjR+jAgNRGLEF9TbtGwVWDl6HTrb2HMnHCeaqNVpD8btm+U/W1f7FyiohSIrtspTEvPVKjH2OLrmAHF1Mp1iMg/cToNP0bkW6XmCoSHcl1vdOzPKwGKstdqB4RvNNbMMmZcfahM1QYoSM4+XPAatyLdM7/DcruqONxBwT6cFRPsxqjr8UkabQg3l50gkxNvtpPm6P2Qac3/ZnRvGsvDIF3esW7JkFCWRbe0XkOV+WRIy+jCrjLaf4YkldcShx+Y99UvGL8WW4EHLh0yBs07f7tI/AlLVvhTCtE8XX6MlPCp9w2PDwEPJWyh1228BioFH88LAyzarHC+2RL4AhYoNHaGmEg1rHoMyHCYM/stRe8GzLhApkRHB1G0xBmCnTg+/zMh6yg7A9iq+W9KOgOMQFIF5Ex97iT/u5Kc0FPI8KOQt1UX/p5kNc3Xr1b5gCGwuihtCINLcsqhJ8lKf3+EgbyHJO1pTpIfkIsTdLk0FQs1MFjS6i2ecTBndYeZJIIsjuEwXRJ279c165nX2WSRZbYNBnysY8UaqRiGg9uEXMOCfFu+nSM1Bg== 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)(5660300002)(186003)(6666004)(6916009)(508600001)(66946007)(66556008)(26005)(7416002)(4326008)(66476007)(86362001)(107886003)(8936002)(38100700002)(38350700002)(8676002)(36756003)(83380400001)(6486002)(2616005)(6512007)(2906002)(6506007)(316002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WczR1tEi77RJTAXgYkOSh35GHYTaKWerRDusAGgZUPu4yKLt8OTuvBEjN9PjHpltrAHjP/IH/ifE6PuKPAuy/oDtkvuTXYTnoxuRiApWimTPW8wB/pj9C0DfcGgtCGdwLRGfaAGju/ixuqGsmy9cqlqI8dbb9fajBDPDxYUdu7pUrwRpSW2p4gScRy7BM1xKnM74ThtfIEGi/B4vDz7utCoR5BuCJb81Or32nyhzdLORAP6pe81PWOMrQfVcW+b6BREDE/UUll3j0av4nQGhwxLYumrwqOnuBX4okfEwza4XZBeNd3zuMWcj3EjgKKehiP+8SEgfC/+zriO7lg6AGxCnXe3mCGyuJ+Afz3P2GkulaQBEpvMJwPgvW211mgXQuAf1oJOUSCTnIE+lKbfm36uQmngMIF6X/uwkR3Ptn4ygoo198d7NgOMRSrPOYyLgsn+jH1QIH3GGiNJC1B2Eo/N3g6O6IMgu1q9sSUP/0TqR7p61dFAQLtRo/OEER2NPELdER3aXBJM1iwGRylA5z70nfTnOIZ+L0lOjh+xK5ydi8krJwqJUKc3oJIfEF6GGVsC5ZPfGCdci3bE5hsjyspvQtieATr1rNTZJPVo4YnFdEiacfGQS5tXgXi8HTqul5r4dsw+wVTrv8sfG47W3zeBz3V13/iqEHTp2l2k8Pq7nynnzyxlOAKNWLC9TNYd004qyeaYFtAdKT73tcIRKREMru1FOslDp+MH1XHVX6N+aMMH/8yYgNv4EhDYEhQX7LeAL9OVVOSySKSEQOfeM1ljOi8GNuSR0V6KbEpu71KklDaCKXgMBDROfOKMiMSqm4LeWEdKtIa0gshPCCyh0nAiqo7YEVNYOFkSiZPqRCY/DHt2pZlsN02sohEyStWBqndk7F538rJCCMfAfEwiS6Qh1IEtGxz250suF44eXNjuXb4t9co6V62KXFDu+4NQdJBn//5TqsnrCRYxrvBFCzBficl8I5FQuJZXghc0XQc0pUL5INDORw8yvZKUhHFmCeQVf3Dk2lU06jb8iVLIrpgsjE0zhXK52gWOsXSVIGrbzjixkSdaC7EA2LTz6njxn5MM7VzG3iTV9lEEyuodJHklBdYGbRChJMwuFCHJD9tSHXGOzQOoC7OFVCQ+EU3r+i1nngdym3XS1lNcLdqgp5l3Eiz2y0K/VL6pdQWlrJ7EJTw1EpffVWFTUsb3fHxE1NhtSC0xLeOF/GRMXE0I4oLitYIG2vAu383+pt8zM2h8RmCerLKLGAVZQqMgSCmxzcnqHY8tOVGZgqJHWK58kn+iXUztBV693HBYc5IEL6o0b+Dc+G3V8mTlFMpLT5U2dC4d6xJqOAk+I/HhW9x/6r784IsyZwNSDfQtncyOekmBLdONC/Y1AYuSrRw2GCg3clLB92jGu4LxUcowpW0Jzn81020GhwgGlg/ukSluIhGxsZMVodSoAUElhIz5sqHh2vyC2bWglv5kHZIh6gGSj8MDvH1i4cjcMDsnRZylJLd+NvZHxIpvUWu3nKP58BVPqyoXTuHY8B+Sys6Uot+Q4KWAcS2DdSXLtWj04dczjaN7Ma6N6c71DeoXqxURo0xa9fxMOtLeo0XHoBYZUzMQsriYbOrWHh8RY7ufZ6uG6Jqw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77238885-8701-41ae-0dcf-08d9db94a90e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:42:58.9267 (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: 8rPYkwxV4KXFgERC/Xh5fY8RwZQ53u6VhX+z7ULW9ubxNmRpzWgHSpSPOuMz9OqMQ9ABeKrgpuKDHQXDgs52vA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB5887 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: IgUKsK3zdLxNnS-p5Cvq0QOUhKrM0jFX X-Proofpoint-ORIG-GUID: IgUKsK3zdLxNnS-p5Cvq0QOUhKrM0jFX Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Setup a handler to run vfio-user context. The context is driven by messages to the file descriptor associated with it - get the fd for the context and hook up the handler with it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- qapi/misc.json | 23 ++++++++++ hw/remote/vfio-user-obj.c | 90 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/qapi/misc.json b/qapi/misc.json index e8054f415b..f0791d3311 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -527,3 +527,26 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @VFU_CLIENT_HANGUP: +# +# Emitted when the client of a TYPE_VFIO_USER_SERVER closes the +# communication channel +# +# @device: ID of attached PCI device +# +# @path: path of the socket +# +# Since: 6.3 +# +# Example: +# +# <- { "event": "VFU_CLIENT_HANGUP", +# "data": { "device": "lsi1", +# "path": "/tmp/vfu1-sock" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'VFU_CLIENT_HANGUP', + 'data': { 'device': 'str', 'path': 'str' } } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 10db78eb8d..91d49a221f 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -27,6 +27,9 @@ * * device - id of a device on the server, a required option. PCI devices * alone are supported presently. + * + * notes - x-vfio-user-server could block IO and monitor during the + * initialization phase. */ #include "qemu/osdep.h" @@ -41,11 +44,14 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qapi/qapi-events-misc.h" #include "qemu/notify.h" +#include "qemu/thread.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "qemu/timer.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -95,6 +101,8 @@ struct VfuObject { PCIDevice *pci_dev; Error *unplug_blocker; + + int vfu_poll_fd; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -144,6 +152,68 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) vfu_object_init_ctx(o, errp); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + qapi_event_send_vfu_client_hangup(o->device, + o->socket->u.q_unix.path); + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + break; + } else { + VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s", + o->device, strerror(errno)); + break; + } + } + } +} + +static void vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + GPollFD pfds[1]; + int ret; + + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + + pfds[0].fd = o->vfu_poll_fd; + pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + /** + * vfu_object_attach_ctx can block QEMU's main loop + * during attach - the monitor and other IO + * could be unresponsive during this time. + */ + qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS); + goto retry_attach; + } else if (ret < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to attach device %s to context - %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -182,7 +252,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) return; } - o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, + LIBVFIO_USER_FLAG_ATTACH_NB, o, VFU_DEV_TYPE_PCI); if (o->vfu_ctx == NULL) { error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); @@ -220,6 +291,21 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(errp, "vfu: Failed to realize device %s- %s", + o->device, strerror(errno)); + goto fail; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(errp, "vfu: Failed to get poll fd %s", o->device); + goto fail; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); + return; fail: @@ -250,6 +336,8 @@ static void vfu_object_init(Object *obj) TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); return; } + + o->vfu_poll_fd = -1; } static void vfu_object_finalize(Object *obj) From patchwork Wed Jan 19 21:42:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9679EC433F5 for ; Wed, 19 Jan 2022 21:59:33 +0000 (UTC) Received: from localhost ([::1]:52004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAIzM-0006sc-Fk for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 16:59:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjc-0008Ke-MA for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:16 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:33886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjY-0007MO-Jw for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:16 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJUwwt031225; Wed, 19 Jan 2022 21:43:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=wf13OJ+joRxQPg8Kyii0Li6FPpFwrBd0jtT1nh9fAaM=; b=dXi5gdjfUQT9s1bmjH11PcsbcGPjhpGEejeoY5ylqDIT8pEjL/cMNgBfX9HOkkrBJNXm tnczweI1/5mDjMGyMbYdwHQrnJZ64TQIx4RCR5VRaTDJY3djeBHjT6n7GVmNDVjZkp8A QSdcmmSt6kXty2HrgwPIxFS2CysiMHXIiupkMAOiQkpP5TT7hM++sIigR71frPakYFP5 j154ZsUFuSosCDEXHDKaupB+Cw2Kb9kpqZQBWcRWMG1jTMy5X+B+kEO0eGewqaEPD4Bk X4g6n6ywwZ6MLGKRsBBfLCZHibP3jZ5Vs23Md2YZ2l1oKq0/suCFJAUalaUBPZGpflUL aA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:05 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaTrw030943; Wed, 19 Jan 2022 21:43:04 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by aserp3020.oracle.com with ESMTP id 3dkp36kft9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LkNuJjuVr9EQPUb4FGoHo+R2tQnTlyPssm/cH/lbO16rtACaxv+4jar5zlN2TytnB4CV9o3eh2nMKjkfnnr2tTDQx0Hr5FdI4sl9dLPYcoI1JMM57zpRjwSzWT435RRdJqUjxRPoHHpgsodJvp5zGYdYSGFztXhP3gE1Nw8AYLbB01rp8jXGVEqCL8YO/oNChDUEJUjNNp1pXO/mcPRHOY5Z8r0rvS6ZN5vIT1ylbLZ+gCECcLfaLqwgfSPtn/b9qrUUXpzgQBesPOvQy9DULQvBPIzjf6NVIDD7kmcBYRMRKulmqguTfA1nDAPBnV4dPttXzzC1/hiMy+pjPmg1FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wf13OJ+joRxQPg8Kyii0Li6FPpFwrBd0jtT1nh9fAaM=; b=iEPgdTY2u7rsfVc1NXd7tf+yklk/gOvKrIBftcyuFRmMXrymKw/n3tUCFKqecZU1sUwp+tGcWq4UAIszaugyBuFHzygU+VTbY+pURauwk39CBy9mJU6oRtilDdaHE4Z2LNqDXitK2qqMSQ9xAoCFT02gw7CaFtS2ZWPwDWyn3kRi/trIqR1/Hu4VKBryxZR/UpShGI8lwOKcfFnsNt2tIcXBzkbD4jkgOpxOhFthsMP8Y9lpItpZwzLKLibJQGvwpS5qK+NROXGyBslJgFqKbOHqQmkdOaeHrnffm3EjK/WD2mCAkv+AxrBTIGsyw80i6iuAzeswTHWBDsHbRMWHfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=wf13OJ+joRxQPg8Kyii0Li6FPpFwrBd0jtT1nh9fAaM=; b=B173MSGc2f3f1rXj7HKV5KIWkXebZz5WCgck1yBNSjuM/oZuunhQT3Pp0TV3OgoXKns18NrDS8VRCxR0C98CQWFa3BwiHj7aPQx10Z9lY6uiyopyvlUO2Ay2h1AgDa8ZeoBJGwr0Yk+8459fVoj6PzLnyTkBLsTKF/jYoeYxjL0= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:02 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:02 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 13/18] vfio-user: handle PCI config space accesses Date: Wed, 19 Jan 2022 16:42:02 -0500 Message-Id: <173c5b40a781d2b1b604bbd169c0989a8e35753b.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9cc33b85-e733-44ee-9bc9-08d9db94ab2d X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:409; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RqNkrbTNZVV1bMg/T9zC70WTxfuywBU3jYTW/CSOExPOKHsY9OrDIC3sQYHB341tTkra3/GYZE4JZpdIsPY3eKAzPPjEcB+b/wlMuDSxCkQa9S7Ix7mWQCBv5mhOCBDQQbmJZIA0yQLn1P7mKBwQWIxkGTKbAot1MYmDanNm5fXRY+Yl0uTvfOfa1CiyYzr3POH9qNotcQRTUuddQcdOfPiQfNenRREPVi6heuLrHtD+QryE+PdlbqOoJHmA8A0WLn3kI8YtNCCGBquiMIS+6/iP7qCr/IUJUfRkSg1iG16ndK9wtK76mKW4OmWkfiwKjfZNDMRoDWBW3B1IL2o0TQfs+blAs+8gII5Fh2m5+CU4wQBHqkq2cWMYPdLQHxBQsuL/UNfCUTciFUs/jdIWOZPK/SQGIp5aBsXJzbdqJHYrBl/ra7iIvNwApPBh34dRksBdKYEt7dk8qjUTcP05Cpn9aRHNaEWXrzIZl2giycQ+FzBzvxcnQepo4EKx6XtWPPhbhbKXckAMp+34zpGTniHrajTlgwyz4l9v7MXT5fPo/625/0AzZbXnILmoHJenPUN/eZ0xJ3XSGqWLGEgtIyUveEtpS/KteDv4ZZ4aTnxKoF5vp+rov6uwIsw8NjM27Rp2LerR5gmMyw+SbDEsrYdyytDp2BW2bWkaWPzLB3F6ZdksIxPaIBA6en8E3JuOsYHtVeK9Zd06WDHdjzmSeA== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eauoqzMcG0k0v1+DFXK5eaBHpMmKdh62CKXwlsOFDAyaNYfhuPI6ETDQIz2RDd+FebsVkJvT3u1AWreJj92V0o0O1VY18J43jPEbbL3/+V6nq62GpY9Byp4kH3muo6wNfSgworr8auOsVMj/gx7Z1nXkIDRUNpC41bQIT6ePPqn80fLg1KVSf4yyd7lCfLvhmpOPqHKlimNPTljuXO3SVpDvGAD8w2J81ZFztHCwerEyRxqUGng/1S7R/Q3YRFqaN0NEYjuVH+PJ3mIFBExYfX200A2gtYh7mQ7bxR6Dvt5Iha1MO6HQivmW9I7TLg4mw1zCQXG3xGmy26kUiiMtAPyUtcVia3BH6IHFQ5CZbpNsXz9yI029TOppXwdLS8aKmJFoFqx/juCtYMNlJpe0Q6ART44ShvHjU0oj/TiVne0m42C57fu0+bbhjy36L4xEM/sYwCsadCd2T0s0ZPHEX6m0TQ4aT03EJFTNAfZK2oaYFBiBF7yJ/EJD1fLvrUc5zKhWNOdVQ+rUMTz9vffBoS3XF4roiz4I4NJTdh8OeV1qyIOtpKq7zEKpr6g/Ucu5bpeyh+uGn5RU1udOff4WH1eocBl40X7PE0kqcsxGRCvaTkuw9vewmZ4kxbsw8JwZtx/ph0QK+UbRsqzhTq/VaoKWjOLZslvzzWRGE5m4y5cGsH7XXVOvxbJvWdO0g/sP+G02pwQ7T289TI1WCUn4tIwnDxddVXAgr3uiAheby1zOF69/yHmJ6HVWXo9LAkaUZ/nt1TQZMZIS8pDF8aQ1jrHKNlZqQ6LllI5ejImlBWJkfXIIA2W3OqNDuf8OYVbFsITByAEGwZDLVZnxOqky/UwOXh8rNhYgaVfNJEFBv/cN5t6Rjix8PN+FmBwEGDlkZBtiRMs8OdaRd4asuojHGa7FOQJ1V7/iGwQEEJEo2648lLEYU67lnMpVv6XB74y2Awgq3LOIVOqSPQiBdOmsK6rVWIcnexIl/uSUxiDw0fQFK4ap/D61juR4fWm2y2RlWJyzPoM0pxdQDY+UaJYTwfDvi2S3/N/1sZsbspmwUsK+kNz4MqiqZAl+jgpJUcf3ZdChaGwzCB5Er2fCyrsy+62xdiha5a5SA2XBqp6GUJnYr7Hi6e7Y6Xpm6g68d5zMHB4f9uR0CXY2QvcvDUpdrjHnsNUGgoNtHVvRn131Ht6DjYuQ3bi1TL1Sx0WyCEQrfY/qi4wKWw6sH8zo7AX8HH0+jPeysFYi5EsCeWaEvvsax3s3lT/3WB2XUZlkP5b3sy+1P42aqQgFUMzQfZdhMO+bypqEv4idhg+joYis0yTiFvBOjF8QWRNzrrwgt2CwzYx8V78TgchhOcWbeEy7vs8gzrxzy1vBwEih/IjBPP6D8AE6zzjAChbpWrilFTrcpb24jZdfZwAkl92bD6/sBNZoAPbkIOzYzidSyjQJZ+0dcs6mr+aw7NZG4C0gRSqm8Cyq6iw9WB+XkxsPHoPDGRrqiItBI1DhevdJ785+p1umYcA3hv/kUCnb3Z+qDtECOMWxRsDAJ8kTME3eDXTdMFeBQ+vZdfJgZnGqBTg6dStDtIXylFR512AYGuJrlsDb51+VldlE4uaOdSxSRXly4YAFSLA6+mCEqC0NYlsnvpk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9cc33b85-e733-44ee-9bc9-08d9db94ab2d X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:02.4577 (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: 043IvPCdDQO3EWrLYO6oN2FldVkeXrBZgG0jwCZa69O9LaZDZ13LpK9mbDzXkPsM14x9cZcoX6/fW9cdGgNfEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: 9WJaAccfAzgXSyj8WEbQ2EeVn0HUAOoC X-Proofpoint-ORIG-GUID: 9WJaAccfAzgXSyj8WEbQ2EeVn0HUAOoC Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register handlers for PCI config space accesses Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 45 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 47 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 91d49a221f..8951617545 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -47,6 +47,7 @@ #include "qapi/qapi-events-misc.h" #include "qemu/notify.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" @@ -214,6 +215,39 @@ retry_attach: qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); } +static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, + size_t count, loff_t offset, + const bool is_write) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + uint32_t pci_access_width = sizeof(uint32_t); + size_t bytes = count; + uint32_t val = 0; + char *ptr = buf; + int len; + + while (bytes > 0) { + len = (bytes > pci_access_width) ? pci_access_width : bytes; + if (is_write) { + memcpy(&val, ptr, len); + pci_host_config_write_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), + val, len); + trace_vfu_cfg_write(offset, val); + } else { + val = pci_host_config_read_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), len); + memcpy(ptr, &val, len); + trace_vfu_cfg_read(offset, val); + } + offset += len; + ptr += len; + bytes -= len; + } + + return count; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -291,6 +325,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_access, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0d96..2ef7884346 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" From patchwork Wed Jan 19 21:42:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F38FBC433EF for ; Wed, 19 Jan 2022 22:06:17 +0000 (UTC) Received: from localhost ([::1]:34812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ5s-0006Ob-SV for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:06:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjc-0008Kw-RM for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:17 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:39700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjY-0007Nb-Kt for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:16 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJOXZ6031213; Wed, 19 Jan 2022 21:43:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=qyXgyu6ft4LhzYhUJcJExV6EPLFtpxSDTSE9Zfc4B0A=; b=AVQ5T/VF/8jTjnOi/GyABzsDqbkruOJMtzhbrr4MISkHA2XhDxGeWDQr/17Y/mTTpqIY U6bz1dWwe347HOfsyN7Xrkrh3nVakkR2ul+oK2fKSu44LCP1Qyoelka2C57kHXRkP88N 29vF9uenUzgbsllDpz8ib/wlOD6ARO1iiRMPcLisuhapQuvZYIDG6kD5qgxyr91Vkt0B wOu11MlSV6HTq1446OQQMFiWJkZrcwfFTHUB4X+iKryUV3n8qQ2lGb8+v2Kyk4Of/WyG 0QJBJcH9bJQotZOj2eshB5bBj9BSVgA0qXtvzA8+dFb/wXKnPEsrIVy9Z4JDcDEo1QqG Aw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:08 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLauA8147048; Wed, 19 Jan 2022 21:43:08 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2047.outbound.protection.outlook.com [104.47.57.47]) by aserp3030.oracle.com with ESMTP id 3dkmaeb75r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fRTWdUOwGbWh/WmyP/EzkBAEpw/BuUqC1rKaT+/qkuXwdD5yrjd4r0KCcofTEIl2XucaTgk9xKrUu6XlE7rLdqzVeg1HWD93i1kIOpcQQl3eaymYdKiYuem+Lk/yxemENuMez9yQgk2yAEQ0FyQAf43rgbTety9tf4A0zUZzeVFRtGnjT+F52ZvuCrOFp8vmNEKoE9TLwTd17kXNT+8uukJj96pJVr1dGKrhoIXv9i/gwe4NAXaJrsWURDaaQQvVBwHWev5E8lwsl2f1oB/ooWPvTQgGQC3GXiAYHbg8rpHLNQwdOwXo471vymxTCTf7/nUFHowQv25N9pYhaiEuRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qyXgyu6ft4LhzYhUJcJExV6EPLFtpxSDTSE9Zfc4B0A=; b=JBxKVQDErpZnABOc0uXKobwivSZKTjx1zSTOC54z8zf8lwXSr9EsDTIV4QgZWlcTwxOiRpZWQHmNq2CupNpZ5CIEoQpsLjfBp2grv6OSzfp4CF2pxJzXXzVzX1hL9apWBY7b9s9rdqcofyUQXmyvj8N5QO/vXITJ1x+8a2YNJoMGCB3yb5g2nBoj5UbAKXqFMRgpaPuA9n+yTzkKkfSyZEetOoroYUnS3VulMkMEjihmZNEIt9EP0VIO9hNs6F5HkQPSqJkGATU+5es6vudx+0Og8uJ8NatuUBQ0DlvneDkph6+Oy4IXHl8ZPpuL1M+eU9PiAqMCpRKa6YN/TbSaJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=qyXgyu6ft4LhzYhUJcJExV6EPLFtpxSDTSE9Zfc4B0A=; b=jsnw3rR9HddtNHjvSztc4qKfzT/OLR+W0Or21nQeuqEkbTLt6mOO+WwD9qWRmDZ0UT/n2hx/tUxDawrsFbRzuvfbDTd+gAxzoIF0tsWpyoQaW4NH/l8J4waXEz9MWKSlnnj9W0+vfKyollPi8u4Bbn8inxcq/nsF6dP32mGBazs= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:06 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:06 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 14/18] vfio-user: handle DMA mappings Date: Wed, 19 Jan 2022 16:42:03 -0500 Message-Id: <8d72691373f12887ce4ec3203e74ed0ce860d1c4.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1e23e79-a114-40a8-dbe8-08d9db94ad3e X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:483; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jpDig/YuKXVn/ikuZ4wSlDge703QviSpu8IxL6+qn5Qh/sBfRuasposBPDSCjb8BcoiWFdrTTPTz9+exZ68zMaznwMnjzc3nOOx+j+uy7WgINqm2c9DOsb40LQd992TQHdf3X3/vxxHHGI/Hqkj1ugdiBGUUdfM4V81V+12ZMwfjwsgX/6c8m2+GAkDqv3tMWN45xzJ1uUfH9r4ozy7WioD8kf1t6pN6aeEBokfFwBJytJlnVAwHBC4dRRgiiYXZQC0zXUG3OYTp+JHPmG5vWCW87SWkVrU83DqXsHmby0et+yK40Wnc+avakTSR4aw8m9Dbs+FqP0OAtZPebmV1j5AXBUQPDZ5vkeMPhLlW8xFH444k+EE3DEsGk2Hj3CEGrEZyNlwH0Bsu5pDmdEl100Y2gemShvhKQF3cFx7w10I2/4vUnVfquY15xKL6uMvuC1azVOOciwkCv8VpZl1BHSHS6L5tNqiOcTXGOKNOK+UjAJj4VNztCB0crAFa3p+Nm9FcvpS25zSWAhBVTo8DpsAr3IT/hqv9eZU3dTcntvPI9WTNdT59XgdmTcDNE3lF6dL4DHOPkkA4ELMVPs1ZS5Yt6i6R2mZsrACXWkiWVnoL5DmzvNDU4AISu3zRvz6mvvt2Kvb34luuxLXsP2vfPcE4jI/yvCahkwolNuUD4XsKXBGG9rKX/3exTaNKd/nQI88sP9cMY+E6swCWJvHYnw== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nBVm70Nkce497AtL7z0FbDOriIBFZvWER0UleD/+VeVkDljTYmUr37bZAHex3U/dFvrgKolSngIgnz/tb6m3Qv82hnift2j87UQyJ1KgFJ5+AcLtr6mBsNK+0CbBC5e6zXrhmQRFt8STMC7R44Y7g5nZygWMkh4z92sBrX6ak602WyiP89yzvHwulS09NT+vgcD7QTX4DfS8nHiJ4I//NwoqeM17Nm1fo8l6EQGdgny/8WtMeCzzOsjVMUy3tvD36Irya9tRjaKgHmEr7qMkk+vM8Rao3kCCyuaERxOkQ+IVbqsg6h7o2WVRvzrFzwZTkRQVg1XumlEDzPV+01f6W4oHGaoFb0HVn06y2r+9MyDQvnU/hp7WLC2zRP6XRU5tzE+bRxROlvqFoS9J8TlHkwU6pubVrWWsQ/WT5ozAywTiO3vUX+Hw6bg+5FXxz6cv3CTnrtZm6rTd5bqcp7xJt6cffzV9dx6fVBDKrzl44zon/9EDfzLBpnb0Dy9Ku4qlNVHvePAoaaM9CBFCzEIB4/cMdIT5BXALWsYavRsJYMI8lo3EyjahQuURBlRCwU7tUPXy5LLjiMN/ah0duq/ia0qBl3GcQ4nUhhh1vSpMYHJcFOApMfUEVX3lumTT1a5KiI5gZlm1b5FjfkHZt2F3+SK7uWBBJ4MZBfl4sy1U7z1WDE8JhFYRqx694eN99YYyWqBOvb+Kkb491/uo0Sa+xTcdVpy2mHykOycxpAjeEuIXtZlAdviE1BmxEIZSnJltMZHW5FBiBg7+x9gHzjL/xYeqnuJbqOyeDJhVcz6r4vcgs4o8MdW4HSAXlbBrmp1DjEIqOYx2quHUS8evSHV5mC6666wkO8bI/MjA3i6VsgLbVxoPPydcwMPmyaAjX7ewI2xscQp4SSGnsIF/701nUcYzaCXBUVUBxtB8O2b1rPWJN4nCFBlHfBvOve65wL8UGOUmgJOt5ErVVbPVSj0koSsq3f5t+wkPysI3bhRLzIyPWMooxEa6TGLfdQS+Qs2MvB8U5lfB5iWPxok58idEaJz1yq7EzkJatyhbwsdrDdIrXTU9k34DXMmTl3w/DAWce2QPKJZeQItynlCwW6+B0rEtXQVC93Jq7Ud6FIgXW9kuWe/UzQebL7y59wpN8a+YlF5OKIz7D8axRhofCEbTMQ8epld04OlHb7ffQdpNqoi3pXzVsMhKK6Eyf/0jx8fpAE0y2RZNxeffoQq/he5Etu6ShWQLL90YzsLqh10NSegw4pwrx5Ap4ZRYyZoqkWPw1y2ifVw8I4dJ8yNwR4X5GLWW+K9uDOphUErYj7XHDkqQ29h9QVHkLwvZcTXbRVbCqQ3vcD78eTB47sWkMTD+JwKreKmA8QQPhyddEcNUHfVnVy8yZuT1FfPfdXdz7vennP4mvrL9CIecr9gdcLDGQ6JS5XKh1WvgwbmwgZsoFsVDO17ie1qFCQ0uND6vGV/1Q3H/fSjkkAdqkKD9NzF8mWqZ/zQ6p3EvSk0zuO7/eR8gyBnha/xY41dzBmGZDXGQ0++yHopwjaazB5+D3yp1DsI09msU/5LVlM9iQZn4Powm5dkW55CVXmn78xjxRGcwIovP5kxPnaI5PIEGei0fS75RiLS+/c/OS4kFPgOc+34= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1e23e79-a114-40a8-dbe8-08d9db94ad3e X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:05.9575 (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: v9yz3R+/C1RUVRTuuxkwoy0aEBLfsRUhzqJu0s/7bILVJKsOTB3GI/WsYsQzm4VvZLCWVcR16D23snK85B+XcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: boXgJ5mBpJlZWCK0GI4oDtCN77v9eS89 X-Proofpoint-ORIG-GUID: boXgJ5mBpJlZWCK0GI4oDtCN77v9eS89 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register callbacks to manage the RAM regions used for device DMA Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/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 8951617545..e690f1eaae 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -248,6 +248,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) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("mem-%s-%"PRIx64"", o->device, + (uint64_t)info->vaddr); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + memory_region_add_subregion(pci_address_space(o->pci_dev), + (hwaddr)iov->iov_base, subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return; + } + + memory_region_del_subregion(pci_address_space(o->pci_dev), mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -336,6 +379,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup DMA handlers for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 2ef7884346..f945c7e33b 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -7,3 +7,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" +vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" +vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" From patchwork Wed Jan 19 21:42:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37075C433F5 for ; Wed, 19 Jan 2022 22:07:48 +0000 (UTC) Received: from localhost ([::1]:40546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ7L-0002FE-AK for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:07:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjd-0008La-Ag for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:17 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:48162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjb-0007O7-8S for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:16 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJSHhR031217; Wed, 19 Jan 2022 21:43: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Ujt5zfPtC5WHKvYVwzvfE/vdX+EEmzYTSrIyCNarMYM=; b=WMma+F8fry0LNe2qe5m1NVM581F6ILtD8cGLbd+rFQFOAPSUigYRS2GEE7r6o3EHV0Sz yo3/u3xwN/b95DafnR9hLQsE90ZPozGNjX+MmQPpgudmYakBH2arjAgOQXkRKIhaLwA2 71LCLCe/Dxkjy6FL1rlfEkgIO1VHXdZGsC/6PZJg3tnNyEIaRSVQEfZg/nslaBd0Db7i HpMC/z6WtaLR51/h0G7fxpiQ7V2CEqPFpAn+P9rnTc0EF/L5ZLYEuMZeP0QeF4xYmqPn Il7sOhio43NpoxP7Orc/ahSK4rkoaXmxERtjIzEzkez/nHVPG4xw/HmNwShIijwht7bj CA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:13 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLa7GV131829; Wed, 19 Jan 2022 21:43:12 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by userp3020.oracle.com with ESMTP id 3dkqqr65hc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bNBeC5bV/eGCDKvTVhmYq/vGlAooiKppkzzshQcEb6HjxydHRvw2ESooyK7c6Vf2McelgVt7sHwhlu8pkagrDTnlov1vviPXldPJhFB2AV9tPxx7kQhbe/2jnXzXK098ouPWosuj/7mjv5ShUDnbmH3giJxERuSaoWIB3Co+ER5fw7IphEZy+9BhMAh/1QDKr7qP9Hqki3lgpUHdvN224Bv8wVmPf3CkFPOp6IWTAePErRrpdiDGqiSLRCrdfzAgTYaJVyyG4NNnRkLdbNxvoO7NoT5twaoxA3AiIf6yfsl5vav21Rhkl5YLaxNm/TKwTP8feacqTBTnXKIj9aUTvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ujt5zfPtC5WHKvYVwzvfE/vdX+EEmzYTSrIyCNarMYM=; b=fy2BEmo3W++hMLc/+o21N5Ji3vDjhpj+fQZRZfgAj/mOBgiK9VGpOzPBa/Uc1LxxZPqbU9X5rgPmj+Cz7RoRLZ6Bbx2jUiTBZN6yh/4Fdricc1LBabPMChTeRghJGxyvwYMsYGoINJpApWYG69P2yYyOo+QG7sIhmLucvveSfpGw2u58wa8breBoaI0m+0nUVlHbTTmsnEZ757gQiD4YaaVOV4pZzE5RUE0gVaVidrG5ciM/ozpgvV0LF1YedJomUbE1Ooi4aPFCem9cW1LzMpTOySrbFRMdn2d3QoMFM/HRFNZn91BRrMNgOWSAFvU/l0ULfU33fdTycu8pKCJ3yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=Ujt5zfPtC5WHKvYVwzvfE/vdX+EEmzYTSrIyCNarMYM=; b=nlR2iaR4tR8/ju/xYQaX/4epbfdnwiEAmgfywJuDXrFHxCA4hpvwjDtJgDjVQucFiW8dthRfFu/Rzg0O3N6gPMGOt+m2FJbglaKtGWG96siw2aaNyQ9RtnJWYAZvtGFteq7aaAO6gHWdnZ3tYrwqez0rabNGF6O+WT6A1L5DEXY= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:09 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:09 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 15/18] vfio-user: handle PCI BAR accesses Date: Wed, 19 Jan 2022 16:42:04 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e57d2423-ad21-42a6-42f1-08d9db94af57 X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:390; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6o4qQuFioa8mSIi/lwiu6LriP6Xl72mIQtiKQwnWaxgK14paMONoY99s6uJUnmXtahFNsjyTrTHxKHWFckpq5CUSKq5rau0vyKdDPFxzr8k9hyugwFUmlqYhOw5iqrJHQFfrgXtyEW20sfC3qzOqQ3kchluyPh6iEswk6788E6LKb5ZGgbIvJmircT1xCauIJN86LlAwBAoah2ftoTG+Ww4j3gYhImzv9seT4PtQcFSbzmFBllrsG4r1n1wcyjO9ZjO2wsRvKu8USO7HNZ7THrDfR06yyVD5djcDMhU33Tij626VA8bTS18ICim1sRnsyIDrSo7WKQJj+Bg0xblIwwR1HPRzQC97HCAh/1PUH7gVi/qhG+uw1jv1i5KIGI00M9qzawX94egoP0cMHbVEp5b7oeb6wEiB3OsHI8O6GWurTALx41nzmNC0DSrvIokYrHX4iB57knO/DbFytWZNd88UhszhnKPcOvqN15nEerQ8uahuNWJ3MAj6Qnli3ZEclCS0Me6n8eW03moQHkuN/QY3IdgyUOqf/gHIZC7YYrWm9edAODh1VvH+9KRLkBLMdfzKjzTq5xYkPWifYRsTuFD9yIhb6lVvwboyY9EqMFk1ni79D/pGvXTfkGBFB1aG/JmUP+lV+uW0pwGvU2JMYJW8rX0mTcyKt3BVmDvzWeea8Y2jBQCG5OG3kPUxDcL2M6B2JbnHoT+McgSg5J8WZQ== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5YQ9AOlH4uq1NUz6kuCfmsfljDJhpTDf9c9Ue7cCNG/WlGSGXJapyB8wAiQeHIUiSkJJu6U1UlnxN5bfGP2ghOGgM1sFPmHxcEA4g1SdR0eWI9OFDA1p+HDgPKnhqLO7uMoGuThyAcQRBvnM3GMY54n29J+HVo71fDXocXghTqaDQiSQT2YedD0oFYoXiK1/oZdOEPXVKb3TLtzzizADwAla+xM1Hy87JVb/GkF1M+9/X/yuHLyoDRbDWT2PVJHKp+E7RxB2JbuBuc/5gfSzBGIjh5CQAOJZ15SKa90lRcNFn35ruQg7ygy95tcQQ6UUE3kqIk9cO5mfwp+aDR1VKJmt8ZjnKis9tCtqRQ0AZvtezIAWSVEroZ4wbKnu1S+ppsF4SmRQzyyW7caGE6W25FWCouEz/HidCkAEFhCHTM9Y+lTo0QoB1NPOqfzRrVTJosVFFjFRYbuOj2eXlevRBNnBQaDdBLAspwwVMO4XjHXw8wTXVVtxxzrPjcucPignrI7a1J8IZS++tVmKxC36ZZBo7VGqQpmOh73vCQFzI3ZDXevP3nRShE9GCF5MZDs8nlK4pDozLxzIyHK0HKLnLRxcJn84orCpDqPrjW+kViUTOtKVg3+Z4WC5dijRHqaHKxk0ErwzgUbpgOjJcrvnJEJcwToI2OsgVsoWnc2qlXhUOOa7tpv51cCgSxDJCFr4qYPPbMNlm4qP99+dDL6Xlq9eDa8ZzrYcEz4j2JwTi6OOx1YfosQbMNgOLyGHog343B6Pds+W3SneMKP+QHsbIFofAsSBWhst7mk50iaSVGfOQlXW3o6jfz9NCHdZPTReEBfbF7EfAZEQSquK5DsXMX3GAEQSWe8Hq0LHqk2thhQvLaIFhRf8hR6NmRHS7xEFB+IiwfBmGalU4hL2YAm5CSsLI3uppNSLI1VmX9SXQQllfvgSF2J2+bLHWruCFiEUYyu31vYuDenwuNiFCpTfuegfgEUAXcx6DPbJs/+fJBnQi1N+m5dK37BgPDd8m1oSMRPwPYEvfzDKpfDvpf+Qf4wnZyY4DJ6ZmMV0y2sqgwDTklkbzB3udqXoixeF5mTzF9HpBrNBdCDLI8Iu6yscvQWCPljLUEejY+g1BzyGQSSwywoFiAi2S/6+W1bUI3FWmC0lubsGXt6KyV1QFFt9DMoj7ID7hAb0pyls8a6kD6GNdI9SYFZyouQ7KI8n8nX3LKA7svu4NdltdvX46rPsyw8hqawSjAr8P+TXLFylcl6HZ9KsPv8mCGudghmjsY5AM61QeOcxjPAwkTJPticIrg9M+b1Th0WBq4TD023kmVHb6F84gliGT677WDdpTCM0YPVNsps/UOmct+L4NDmAFkPGvev+t/TAUl28xWvGooLiRIN7YA0yZ3YIQheAiO1DRdRkAJIbPFamZCY5/6fmV1N9iCxFZokN/S4zRecEFF6svoVQnw1wVTpcCMrEseiTuro4dQea5dS2bav8uYhfVnRvD9sSELhKdcweFbZzoervzRnVgDnBrImwCRaUStjAOtt3bhLJtGqpjGAeamONvBQGlyI7LC9FeSxCs4WsbkcBGqxR2DaL9/IJ46cuwabBp2TdJuFfhQcQIqIV3J8ea+/vz/dF/BgSI/wg7AMkiBQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e57d2423-ad21-42a6-42f1-08d9db94af57 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:09.4416 (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: hrT6vEpVWI+Kf6YgaKOXFyY+3P4bHebvhRfnXbJIxwd80DqRvpSWPnBIdyjjkMmHWOwTHBKNQz0Z2dqI6GnX0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: _oRvupgVsGkm253HXhr5kQmw9IvyUztx X-Proofpoint-ORIG-GUID: _oRvupgVsGkm253HXhr5kQmw9IvyUztx Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Determine the BARs used by the PCI device and register handlers to manage the access to the same. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 92 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 3 ++ 2 files changed, 95 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index e690f1eaae..bf88eac8f1 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -291,6 +291,96 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); } +static ssize_t vfu_object_bar_rw(PCIDevice *pci_dev, hwaddr addr, size_t count, + char * const buf, const bool is_write, + bool is_io) +{ + AddressSpace *as = NULL; + MemTxResult res; + + if (is_io) { + as = pci_isol_as_io(pci_dev); + as = as ? as : &address_space_io; + } else { + as = pci_isol_as_mem(pci_dev); + as = as ? as : &address_space_memory; + } + + 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); \ + PCIDevice *pci_dev = o->pci_dev; \ + hwaddr addr = (hwaddr)(pci_get_bar_addr(pci_dev, BAR_NO) + offset); \ + bool is_io = !!(pci_dev->io_regions[BAR_NO].type & \ + PCI_BASE_ADDRESS_SPACE); \ + \ + return vfu_object_bar_rw(pci_dev, addr, count, buf, is_write, is_io); \ + } \ + +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) +{ + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + VFU_REGION_FLAG_RW, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -386,6 +476,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f945c7e33b..847d50d88f 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -9,3 +9,6 @@ vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" +vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" +vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" +vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" From patchwork Wed Jan 19 21:42:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31014C433EF for ; Wed, 19 Jan 2022 22:09:16 +0000 (UTC) Received: from localhost ([::1]:42520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ8k-0003ca-RD for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:09:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjj-0008SO-Cp for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:23 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:49298) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjh-0007PG-1Y for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:23 -0500 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 20JJmflC001398; Wed, 19 Jan 2022 21:43:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Y/Rin45j80wvjkSEF5Xr1s6e4/OTeGmkoaGQvIolwVw=; b=rL7ssfA3QaxZ5xHquCjE5y0Wbdp9tAC6lLoefEJa6oNJSU+D9jpQxnUJM6hndxvJqpZS fxQBvsOiAB3czEd2bUkIeqcZRTpzXn9SG8jB8VpP4wBKN3mZ5OCbBBgWy3v7Xm+ax31b q1ONGdLPIBFlPe0NdUbKR8bHHpuoj8Rd/m7s+lOHKlsGwoIsxGyfQjMHs6vw9HAb/+qY IiKB1KWUY0QlMpseWFuoiFwYMwoO1yS4sug2oB/AiExWEK2Kf/JJrGYYfQek0DBXPGGM fvk20kip/QE6faHkZrnfWdMvOlnicYDYfEPj6gKh2D4aLzqLNEVBKK7tugmt1K4/v+mR yw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc5f6bbm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:16 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLadnn059789; Wed, 19 Jan 2022 21:43:15 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2041.outbound.protection.outlook.com [104.47.73.41]) by userp3030.oracle.com with ESMTP id 3dkkd144nt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+zqNOyW6UOk9Jrlu+GnQHeB/UGWrmk5zMaoVmS0Wuy/rS5KaYA/73Bdj6LJ8+Lpzk8wJbKxp169YwSrDSHOGXK7Y4FJlEEvXb0NW2OCbNwqnebWfgTE8msSPOy6SIPkoRorsa58XXwVi0vtsLK100TqWKBnRhQF1037NNeOC9he/vfyZzMozh5xN8ojC2RdTf0GB/fmjZBRcY/7Oftrw0BKHlFEPZYp+Q3ocraqBY3ck3om5DwaLUHWTRRFvO6C0AZ15V4LqCe1mv13TvVAWJBFu8p4gtBM9kmSmIH0m/VyGM7a3yb08W+B2iIXw27LkJHYT6Zsg2uegRY5ZHwMsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y/Rin45j80wvjkSEF5Xr1s6e4/OTeGmkoaGQvIolwVw=; b=Oy7Ksi1nlsVg15GnJOMTpRerTJ2+haUm6TkoJxT6HT7wiK+6EDl4lhX+AoRI+9Xa0BvH+qzsuVYjlYGgmMMasZTI2Z8Yzc+jFB0ZNPHKJV0q6eKVfb25EbKXncnugQarawmZC62zUCnmmDbmtofiNeyRIMRAdWmK+TXiLRMnyE0T7OphO9l/pX/oSyOCdlmZnpVkTWT+HxJs0dVHJvWRTabANJ0dCoQpqjnGZpu973D/XBvrQ1vWGe3uC1V7ILvhCr4U+YgXUQ8Yg/phi9T87nSmTn+bVwGhh+WZQFmbDt5PVp+cdXIksCQ6PADIBSEeTUJ5RZFqbQUMyq7qljTk5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=Y/Rin45j80wvjkSEF5Xr1s6e4/OTeGmkoaGQvIolwVw=; b=u2LTFjtisuFnwoIV+b2gxrmcA5ejzx4MPZZFerNpzce7OcjkWf0ZLcwbA6afVVAZqjFYfGmnFgAhM5iJ7jZenKXLyk6QEKKNwUKNLBExrV0+UXizOumJZKP7IPW5vUR7zt4dmKIVi8X589AKoU4OZYJON93WPIj4nNxldtXfsUY= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:13 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:13 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 16/18] vfio-user: handle device interrupts Date: Wed, 19 Jan 2022 16:42:05 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3928ccc0-5284-425c-831d-08d9db94b168 X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:279; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4YfsquL5JQJR62v1qppxKaie9L4zZs9FzkIVqJAa192gg5LTc7Gqu+hRfIMvBbvMfykxgpiXfREgTGZ67ydTONxBha96LlIs+XI/1JFLgLiTuOCxuAxCmE7AHHFxTV5aUqMuJBQowgWxiIA5YAtaSJNyE4K/fuUGot6FHf5PHt+oXuDIiemhF62V/Bozl/O86htavswBWACO/0ERpgBG0N4ILGJkyANppZDXn/C5rmkEEbyjZeX/S56xvo7vUaIyTVz4aQjdcC6VZS9ERcxtpC/XoZACxE0gtOB9WsZSvhrOaVar7qPXfAAPYhU1xsWmwGdty33B6IYWuGiUfGjNxkCIn7JlcNWWQzTa/7HpXsBl9g+sTdHmpq73RjIBKs2TxF2nDKH0nntaJEsUFlGdkujRDH7yypMkg88uqvyMGMeOdcCGyObQ26zcQvHxa0yFZW751hdyZukRdguwiOYbwxJah289v/lQTigItMPtICCWiuOibW0qW+UTcqyPz5aEFHdYdzCchzaWORy9WPxtxVsjW1l8uYquYfhFmK3srsWBuxQ6aBnlOANwXeTkkPA/E4tXUpI8GX4Cs6644Mrvm2GZ5ZHNl20zipGqaqBb7WpWMztTOG/0grY0TsGTCJuErprKtWviBkLhtujG3t6gzrugBkIB9t8MM4BanZYZhFxOlGC1WP7ieOuUPX0Du+ivVBxyRT23uEB2imcslbaRKw== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sZIKy0BYJg6ccQ2FecgW5VBFon5GbZ9Ira3LHz70lgyXAh8OhhGemHpDTKTvjiUG238ewU7ekzHvLwUQZ+6evCuoahqluczlGJ6rrQsgcHLCCR4EG5+aUR+Oxw4QHB7QDWq9gZO447sMBzzaRj3gxacvQrNIcvWMBIYKL8u7vDkcqn8odcXGIq35evmnQqh5OZj2HdLd+vE4IO3loBGjkBQZwVfJ7OFSN3FJG4VeNi8BxLaBi8Xwgxljy06z7uTn5LDx25Gl14dp9fEwIVTopIRV3eV8js9e7hAk9j4Flj1NwX/2rPjs99VbFaJrb6m9uFVn6fdFmY8J5dN2XTgxCITHGncz/cJuAnc5c1/DXQ/JtZrmpFck+EuwmhrV+j6bAblMyEyCgv1ZKzvQZNvGG72kKMKE56ctkVTOz8l4tsYbSi6kjaNZiu607dZUKyjUR/lAHRu1/zpmC0/eyHx2fV8PvkGVpr1lTdhc0PY1zcVylTSABWb5JZmRnKM6iYdBsO2WjVz8kGIoOLqlOU50cLy1a1StcWOiS6Sn77GAlk+kOiuEG4rrgY7FzqrViFuVhu7JA46t7pX0uyC5V5oCK+xMfhyBv8ieep/uQ+vID8NzzJtqgbNPTXpFyr+0WlXP0kmpTzjNjcM0ui+5uR1rdl7TjoC5kMfPK/TkQSBFD246lSJjca9vvMy3OumiUKMBN+k3UraWA4g/mLTS93Up4XXzB3r41L8OExT5Auusj4X1U5cqNOK0ERIkXLlrDGdcQ4LlZTXehsXQl8W9h/5D2O0mOSR4kM17sxtafrgfmHexFMGvurqiQUjWhryuX0AhoY2WgYAnkQkbRWHJGXc7fqe2kgbunXZHnpfwdjdGJ1EpnCQ13Q5VnvXa6OnPR4aAxcBTeG7HIditTO3svXdwXXGYQ0ADGjUAGw5SEsOLMMR9ooOiV+XevV2pmkMERBrEs1aOHMV6+jFi9GqZy8Zj7Us9y8cfObImXiz9jzyjXKzzWdqQ+ZmIgUaRwlHcNLS4AwXfytJ3ON8uiTptu9JNHT/90NWopL9wVRAo9FpPBpf8mYoDIptaPGCexlSG5Rp7ihnAEWFhyNOgHJsHzb+k0gBs71t+Al88/vVtIOH5x8pEGqdgk0UKqOGnPqGta93vsc0KDrAZD0sFzlvo84p+5pzo8Wf/DMm1wTj0h8LVB0Tko4Erh6PtK/3rlrk99bxUtc5cnrLwx4eRAkwlFPgYXj6FXGgVJaJ9MytdAcho4oh3WdeLPhsDS2ynX9hcr0QWCqz6Y+sdbvmnBDVixnh9Nv0jAKvXqDddbm4dJQelKKe5Pssr/jfVnLItgmHp8M1AoB6apT0K5bVFcwJcjpjJK/0N8DV0rhsBZUjLUolG+jTs3lFM7GIlVosaZfF07HEoMwf5033niLKojT0CKIGS6Fjw0RLbMex2K+mPc28EOgL53csedMTsIgIobJiFzpGp1WwwTK9nK2wR4WBav/rbrVive4beY3sSRn1n2hgvnfB7HCp60nvhFN3hZcUiUM4ic8/DLT4ZTxx2f7CGqLIu0r24OZ2/SIytSUqsezXLv9o/GvdDfRRk6/a+BOX+hdSDte7uQsKd1WLvwgZYjrL8ml42wCt/M11O3541c8WBr2k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3928ccc0-5284-425c-831d-08d9db94b168 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:12.9101 (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: UNfqVY2s9q/i/0oxzJttae8A2kifun49AbaRAgEXku0fxas8cOJXXktnOd3mMfRTB2PKDOHgH4QanKZohTObLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 adultscore=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: VzQJ2Jy-rpY5I95dwP5A2ZOxiPoRLy0e X-Proofpoint-ORIG-GUID: VzQJ2Jy-rpY5I95dwP5A2ZOxiPoRLy0e Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Forward remote device's interrupts to the guest Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/pci/pci.h | 6 +++ hw/pci/msi.c | 13 +++++- hw/pci/msix.c | 12 +++++- hw/remote/vfio-user-obj.c | 89 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 1 + 5 files changed, 119 insertions(+), 2 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 8c18f10d9d..092334d2af 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -128,6 +128,8 @@ typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type); typedef void PCIUnregisterFunc(PCIDevice *pci_dev); +typedef void PCIMSINotify(PCIDevice *pci_dev, unsigned vector); +typedef void PCIMSIxNotify(PCIDevice *pci_dev, unsigned vector); typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ @@ -322,6 +324,10 @@ struct PCIDevice { /* Space to store MSIX table & pending bit array */ uint8_t *msix_table; uint8_t *msix_pba; + + PCIMSINotify *msi_notify; + PCIMSIxNotify *msix_notify; + /* MemoryRegion container for msix exclusive BAR setup */ MemoryRegion msix_exclusive_bar; /* Memory Regions for MSIX table and pending bit entries. */ diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f33c..93f5e400cc 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -51,6 +51,8 @@ */ bool msi_nonbroken; +static void pci_msi_notify(PCIDevice *dev, unsigned int vector); + /* If we get rid of cap allocator, we won't need this. */ static inline uint8_t msi_cap_sizeof(uint16_t flags) { @@ -225,6 +227,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, dev->msi_cap = config_offset; dev->cap_present |= QEMU_PCI_CAP_MSI; + dev->msi_notify = pci_msi_notify; + pci_set_word(dev->config + msi_flags_off(dev), flags); pci_set_word(dev->wmask + msi_flags_off(dev), PCI_MSI_FLAGS_QSIZE | PCI_MSI_FLAGS_ENABLE); @@ -307,7 +311,7 @@ bool msi_is_masked(const PCIDevice *dev, unsigned int vector) return mask & (1U << vector); } -void msi_notify(PCIDevice *dev, unsigned int vector) +static void pci_msi_notify(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; @@ -332,6 +336,13 @@ void msi_notify(PCIDevice *dev, unsigned int vector) msi_send_message(dev, msg); } +void msi_notify(PCIDevice *dev, unsigned int vector) +{ + if (dev->msi_notify) { + dev->msi_notify(dev, vector); + } +} + void msi_send_message(PCIDevice *dev, MSIMessage msg) { MemTxAttrs attrs = {}; diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331cd0b..1c71e67f53 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -31,6 +31,8 @@ #define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8) #define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8) +static void pci_msix_notify(PCIDevice *dev, unsigned vector); + MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) { uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE; @@ -334,6 +336,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, dev->msix_table = g_malloc0(table_size); dev->msix_pba = g_malloc0(pba_size); dev->msix_entry_used = g_malloc0(nentries * sizeof *dev->msix_entry_used); + dev->msix_notify = pci_msix_notify; msix_mask_all(dev, nentries); @@ -485,7 +488,7 @@ int msix_enabled(PCIDevice *dev) } /* Send an MSI-X message */ -void msix_notify(PCIDevice *dev, unsigned vector) +static void pci_msix_notify(PCIDevice *dev, unsigned vector) { MSIMessage msg; @@ -503,6 +506,13 @@ void msix_notify(PCIDevice *dev, unsigned vector) msi_send_message(dev, msg); } +void msix_notify(PCIDevice *dev, unsigned vector) +{ + if (dev->msix_notify) { + dev->msix_notify(dev, vector); + } +} + void msix_reset(PCIDevice *dev) { if (!msix_present(dev)) { diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index bf88eac8f1..1771dba1bf 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -53,6 +53,8 @@ #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "qemu/timer.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -106,6 +108,8 @@ struct VfuObject { int vfu_poll_fd; }; +static GHashTable *vfu_object_dev_to_ctx_table; + static void vfu_object_init_ctx(VfuObject *o, Error **errp); static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -381,6 +385,72 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_map_irq(PCIDevice *pci_dev, int intx) +{ + /* + * We only register one INTx interrupt with the server. map_irq + * callback is required for PCIBus. + */ + return 0; +} + +static void vfu_object_set_irq(void *opaque, int pirq, int level) +{ + vfu_ctx_t *vfu_ctx = opaque; + + if (vfu_ctx && level) { + vfu_irq_trigger(vfu_ctx, 0); + } +} + +static void vfu_object_msi_notify(PCIDevice *pci_dev, unsigned vector) +{ + vfu_ctx_t *vfu_ctx = NULL; + + if (!vfu_object_dev_to_ctx_table) { + return; + } + + vfu_ctx = g_hash_table_lookup(vfu_object_dev_to_ctx_table, pci_dev); + + if (vfu_ctx) { + vfu_irq_trigger(vfu_ctx, vector); + } +} + +static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev) +{ + vfu_ctx_t *vfu_ctx = o->vfu_ctx; + int ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + pci_bus_irqs(pci_get_bus(o->pci_dev), vfu_object_set_irq, + vfu_object_map_irq, o->vfu_ctx, 1); + + ret = 0; + if (msix_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ, + msix_nr_vectors_allocated(pci_dev)); + + pci_dev->msix_notify = vfu_object_msi_notify; + } else if (msi_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ, + msi_nr_vectors_allocated(pci_dev)); + + pci_dev->msi_notify = vfu_object_msi_notify; + } + + if (ret < 0) { + return ret; + } + + return 0; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -478,6 +548,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o, o->pci_dev); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup interrupts for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -491,6 +568,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + g_hash_table_insert(vfu_object_dev_to_ctx_table, o->pci_dev, o->vfu_ctx); + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); return; @@ -552,9 +631,15 @@ static void vfu_object_finalize(Object *obj) o->unplug_blocker = NULL; } + if (o->pci_dev) { + g_hash_table_remove(vfu_object_dev_to_ctx_table, o->pci_dev); + } + o->pci_dev = NULL; if (!k->nr_devs && k->auto_shutdown) { + g_hash_table_destroy(vfu_object_dev_to_ctx_table); + vfu_object_dev_to_ctx_table = NULL; qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } @@ -572,6 +657,10 @@ static void vfu_object_class_init(ObjectClass *klass, void *data) k->auto_shutdown = true; + msi_nonbroken = true; + + vfu_object_dev_to_ctx_table = g_hash_table_new_full(NULL, NULL, NULL, NULL); + object_class_property_add(klass, "socket", "SocketAddress", NULL, vfu_object_set_socket, NULL, NULL); object_class_property_set_description(klass, "socket", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 847d50d88f..c167b3c7a5 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -12,3 +12,4 @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" +vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d" From patchwork Wed Jan 19 21:42:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46963C433F5 for ; Wed, 19 Jan 2022 22:06:22 +0000 (UTC) Received: from localhost ([::1]:35006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJ5x-0006XC-3Q for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:06:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjl-000077-EB for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:27 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:61288) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIji-0007PM-AO for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:24 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20JJU0LY031218; Wed, 19 Jan 2022 21:43:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=AQ0evnV9UvpDTIfWKxevLIFkwP8LiSEGiDcNQhmW4gs=; b=EZHZw+iXqAJ5sd41vT4Cn4UhwzuIk/+qi9vlJGug1imT0UgDy9SVAYOjqQjCF774RIV+ srxTxwzL17R/BFj9/ANj3CZSnLXw40XGQRuhA3M8C5VgxIt8dV4DigFD5vdYlv6rx4/N MKMnMACtGBnr9skMyYhBws1pdNdgk2UTLpBXHSoAoNrmSuuMcjwCMYj7b+mD717cZmSN QzQSxzCu3FhSkST+l5Y9bfTfCNcCpK89NTzH9bSqcW6B62WFTNcxmDjKf556lz8snmcM m0TCv2FcWJSuG+moC7aB7FRFH3Lp8sMuZj/Wqr6xOyxYlxxVs1VwEkG95c1y4CqUhGjy 0A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4vpgqg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:19 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLa78h131775; Wed, 19 Jan 2022 21:43:18 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by userp3020.oracle.com with ESMTP id 3dkqqr65p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TQ3A+j6sQmwKBgZbwoQtWDU09AUIeJsNgza6gPVT0w3q73KlDBPZitbwEiGFtpo5E2NzHFaUF0E1Aqi+VryETmRjYFogu+w9udZo5kXHqBcXRyC9bjCfS2bh8L4YnoI2KihSrF9zNWQwim7LU5Np4yluv4xvRKuJ4bAMclc6fwc9C91mRjCKwAzYfNY7vk1SY2BL6rxlUeGnkosmflhxzd0DsQPSG/Mb0kHG4zJ6sBYeha+pOPl8gOKX+YeyxI8rI57dxV5/9l2WR7P/ZaaIrJExl7plMNA2mHP0fufLXmqmFIxHJHXy5dAcuv/CFvS8QWAt6Qhc2trLA9xOhNLniQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AQ0evnV9UvpDTIfWKxevLIFkwP8LiSEGiDcNQhmW4gs=; b=GCChgtl02Fy3hXRBKeLtf40SSHYzODSNjF+lrGpcT6XDZhbpPwJaAubudjdz8z82jE34ruNRejZ2LPDmzWGIN1/wXg1uNq97829o0hr93QISVC3bdTYBxDAVV8I7wroc4U1y0HTzHIKMgS32oHCPCXxLB+K11WxSIRb+S0SQLQZSWaZh9k3yUYiyZwJjQWuEd1EjelrKkRw2KlxzMHuCQ/J2ftzBGBroirt2crzYi6krCOLDu+CF8RyQrjv3PNgAYoumfxuoNIzQOdWjwjyGVIbHSqoGcPF9TFm1Ij4eX9SyFig3gUKoPjqKvkCN0p7sosCnurV1vbkwFwM/VQxcTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=AQ0evnV9UvpDTIfWKxevLIFkwP8LiSEGiDcNQhmW4gs=; b=dygGttABTix4K/WTXWjPjtgR7vowUDx/Ixl/ylVtAUTC6RwRjQSqaxYOFcWWYs5xvM6IIyT/1xsV0dACynifj++lW7gP3mfrnYPKTbAUJGN54TLHUsnzxfb+5fAY7Pl5BYze0UcJ+DVSfRcWPf3BmoS7edPQrmc/8oIyepFmcwg= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:16 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:16 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 17/18] vfio-user: register handlers to facilitate migration Date: Wed, 19 Jan 2022 16:42:06 -0500 Message-Id: <0ec006e5c309166cc1920871688508c1f6270ac3.1642626515.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 011bb0d2-e988-4ec5-2574-08d9db94b37c X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1247; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EcE/iVS9h0p2XzVz8x74ItukpsKOUU5abJIQ9W65Vt7tfhgI5F/8whrq6f1bSOnPfKOhetgr8yz3NdnD6nPEAH/F6GCTy9mPou0pqWrx/BEuQskwVXgEmsaoSReBOW0oxRVCDUgyM3u3KANRpbAr9BngwxLqF+j3j9p6iFT/QehjtcZp/Q+K+Am+VZTp4Dnx4eTL8mkPyhUYrisd0yD2NdIswkgGc0jIg+j/uk/CsGz/tUpFJdAdfO3MSJ8BCw1fw2LGHgF2ztJ0aopZNXKcQe3q0x3+zfP1rfpzPCiCk97CNjLZSYIwGrbDJcLZ3IhfqB7o61IIkQPZcIMUNshkG2Y15InCcdR9bK7p7eIcLlARh8vNL6l1n61oXoFDnhp4Q+BK2gGV8eqRcRtCKP3piej3/V/d+xWBV/jnTDwBKRnRBiYj6ZKYgVhaOWjVC1xEBSEW4kCsUDVxSw0mT6ru1fZ4iqq3sU4XHjO2H3VNLp+/WIJ/zm9Uqr/NQUDKPzB3xFaVJGCawBLQRi5ZOOG8Oc4eeGHpXY+81gMDAThxGshD20G8bUcD5LRjeACZLaWXnmrt92EDsiTDHWuNvfVybDJhGFkGAwrzXavDdKVPjMttZUqsYLi/HBjZ1kNNLuvIif8kR1A4ZR4DCWv/FybNSXrLazk714Bffmjadpj5XeyZOxhgqgq/JKuiUjEXCUQDe6s9VQ6bWUBRY36rFhtfuQ== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002)(6666004)(30864003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bX5S9bvpm2QBLBHF6i6t5ifkcoLv2iNo/gAWKlXHSLELtCXTgAHjiCkRDUK/A5vXzM9dSDFlTLRmLRiVV22GjtDUUh8Cxk3ENnb3jGwGuCeGgQsZxDNXG6agEHI4tg4x12AhX/j6j2+gSFVPZrmQB6s9X6iVTy7N4tJ4AkcGsnIQcs7vJxURW9kacgrWgrvcSF0JyRWGqTYR23fX5JVgkq7jF+SKI6oHv37CeH/aNXIcJVOLo6t4LDGbjIBbds0l10S2md0hDTn4wvziowkY2gYIhmsWoV/99nSQBP56LRZKm93AJ3twiOtySBsrXtZLv5Xx0VOwZFOsdxnvmm/E+UfX2YzeYeUiRRU2ghFD4oyFJmpy4xvT56E6kqQft9XFFUcwWhIkyAoUiemrzYDaYW6wGqU2ZhvQZDwLX9T5155dBYnkvRzcb1BpTNaNm7OCFo+l4QqBGCE1O82tPZ4COYu4AHpFnh/Yp9BhWjU9RWclep0sc9iR1JhY/qPgIDREy1wtgPPREO4/ZHRdNpEtA2FQLvlwZT9t12BoOm1VPxUoGVvFR+zIPVLQIKWGPghrHLzSEi0MUiOQqDn106mWXHiIWjicYKIE1TmY7UD8VRnJNFpupZvxQgkMTkZvPDppms7S9v5oeSyuedpQ3APyaF1TuDuV1kjIIFhOW9DHdExVxaY42U5fxYqjg2aGVz8Mr8XbKtYDHp7ilrqWOotlVnP8J9m5Wf7DtoZGJrj3Uu1q+tx8AmPCcQEU5+j6DHDnAJrdPVz47lt1f/V2KRZ2Aa4xReGub6vY5Uzr5a18dYTZZu9bWlFU1XDtLqZ9mg8e8lUKkFZ+Hh2zwXj8PTuHAerupG5RIhNw5Yj2vctXKmq6F/b7fIAy1agFZlYL99XFsf7C5CqjraN0ugL2MZaPEjHms+VbtLw8bSwPo3wA0on4HbmPQM76Fp519ePgPHWBE+HZmMPUf3hxrs6PANEt/YNoojeNYJkN0BumFzDullYOq3/ADdfPOCrIgvrk7VZGSsGuvD3qNW0AVnzqB4zYzWCBdlrxNJp4Hul2k1bXG1ylcOslY0I18r/EKeGh6HXiQ8qz8n9eXJz3NV4jlqE+9yexvLkAOIQZdXAhuQHH6z14MFvLS5B9MacCcpps3ck0n/HSbnbaMvIJw5SrXwuCix6rL6qsl0w4fCvqA1gTPnL+ku8efmRg+PpJL7TBnY1A9AenqEjL8UGAW+akQLIl94FXXg7uXJtqL9d9d5dWfgXD507ELndzB66MIUD9YIeO9cadYb0FSzaXQovl519PLWS9j/n0oOHNAmAgDRSijsm6J30c5iS5llP+NeckBEwF+w4UQsH9KKISjxPWug7ey6xmegBexvX7duPZgrYPobm8A90Nsrq+HlEp32w3Sjzs4HGOIU7+uF1cfBN+ILBcivS0LwN+jtP8WkOFY1sVdZrG6jtdAasFZkR0ZPezlO9BZfHLPZlD7DEiV3sFvMkAcKL3X4422NWHbrjnNegydvId8MAd+LvlZdIuH+66N/Uhy3xTosvnYhB9LtSX6XiheH9MWbOxuYCXEbTzBdHGyDPBZa7W0VPyjePin4lN4q997jO4TviPsjwq/XTj9WksSvZlEOIFU47qBAWAmvEAc34= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 011bb0d2-e988-4ec5-2574-08d9db94b37c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:16.4254 (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: q1OFMX56KpkXy6ktH7dlaKlKH1IoWYaJ62a3yFIfcT8nMrYFIcp9Br1X4eFN4EavJM9+2ZUubzBWAQ0ciho5+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: Q5V6SyDQXu7fTnUb_2LDYXDvORhDF_tN X-Proofpoint-ORIG-GUID: Q5V6SyDQXu7fTnUb_2LDYXDvORhDF_tN Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- include/migration/vmstate.h | 2 + migration/savevm.h | 2 + hw/remote/vfio-user-obj.c | 323 ++++++++++++++++++++++++++++++++++++ migration/savevm.c | 73 ++++++++ migration/vmstate.c | 19 +++ 5 files changed, 419 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 017c03675c..68bea576ea 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1165,6 +1165,8 @@ extern const VMStateInfo vmstate_info_qlist; #define VMSTATE_END_OF_LIST() \ {} +uint64_t vmstate_vmsd_size(PCIDevice *pci_dev); + int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, diff --git a/migration/savevm.h b/migration/savevm.h index 6461342cb4..8007064ff2 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 1771dba1bf..d3c51577bd 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -55,6 +55,11 @@ #include "qemu/timer.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/vmstate.h" +#include "migration/global_state.h" +#include "block/block.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -106,6 +111,35 @@ struct VfuObject { Error *unplug_blocker; 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; + + vfu_migr_state_t vfu_state; }; static GHashTable *vfu_object_dev_to_ctx_table; @@ -157,6 +191,272 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) vfu_object_init_ctx(o, errp); } +/** + * 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 - pos; + } + + memcpy(buf, (o->vfu_mig_buf + pos), 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); + + o->vfu_mig_buf = NULL; + + o->vfu_mig_buf_pending = 0; + + 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_stop_and_copy(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); + o->vfu_mig_file = NULL; + 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; + + /** + * TODO: move to VFU_MIGR_STATE_RESUME handler. Presently, the + * VMSD data from source is not available at RESUME state. + * Working on a fix for this. + */ + if (!o->vfu_mig_file) { + o->vfu_mig_file = qemu_fopen_ops(o, &vfu_mig_fops_load, false); + } + + ret = qemu_remote_loadvm(o->vfu_mig_file); + if (ret) { + VFU_OBJECT_ERROR(o, "vfu: failed to restore device state"); + return; + } + + qemu_file_shutdown(o->vfu_mig_file); + o->vfu_mig_file = NULL; + + /* VFU_MIGR_STATE_RUNNING begins here */ + 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 scsi-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) { + vm_stop(RUN_STATE_PAUSED); + bdrv_inactivate_all(); + } +} + +static int vfu_mig_transition(vfu_ctx_t *vfu_ctx, vfu_migr_state_t state) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (o->vfu_state == state) { + return 0; + } + + switch (state) { + case VFU_MIGR_STATE_RESUME: + break; + case VFU_MIGR_STATE_STOP_AND_COPY: + vfu_mig_state_stop_and_copy(vfu_ctx); + break; + case VFU_MIGR_STATE_STOP: + vfu_mig_state_stop(vfu_ctx); + break; + case VFU_MIGR_STATE_PRE_COPY: + 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); + } + + o->vfu_state = 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); + + 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; @@ -476,6 +776,7 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) ERRP_GUARD(); DeviceState *dev = NULL; vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + uint64_t migr_regs_size, migr_size; int ret; if (o->vfu_ctx || !o->socket || !o->device || @@ -555,6 +856,26 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + migr_regs_size = vfu_get_migr_register_area_size(); + migr_size = migr_regs_size + vmstate_vmsd_size(o->pci_dev); + + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_MIGR_REGION_IDX, + migr_size, NULL, + VFU_REGION_FLAG_RW, NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, "vfu: Failed to register migration BAR %s- %s", + o->device, strerror(errno)); + goto fail; + } + + ret = vfu_setup_device_migration_callbacks(o->vfu_ctx, &vfu_mig_cbs, + migr_regs_size); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup migration %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -604,6 +925,8 @@ static void vfu_object_init(Object *obj) } o->vfu_poll_fd = -1; + + o->vfu_state = VFU_MIGR_STATE_STOP; } static void vfu_object_finalize(Object *obj) diff --git a/migration/savevm.c b/migration/savevm.c index 0bef031acb..be119e2e59 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1605,6 +1605,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 */ @@ -2446,6 +2489,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) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 05f87cdddc..83f8562792 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -63,6 +63,25 @@ static int vmstate_size(void *opaque, const VMStateField *field) return size; } +uint64_t vmstate_vmsd_size(PCIDevice *pci_dev) +{ + DeviceClass *dc = DEVICE_GET_CLASS(DEVICE(pci_dev)); + const VMStateField *field = NULL; + uint64_t size = 0; + + if (!dc->vmsd) { + return 0; + } + + field = dc->vmsd->fields; + while (field && field->name) { + size += vmstate_size(pci_dev, field); + field++; + } + + return size; +} + static void vmstate_handle_alloc(void *ptr, const VMStateField *field, void *opaque) { From patchwork Wed Jan 19 21:42:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12717812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F175C433EF for ; Wed, 19 Jan 2022 22:12:52 +0000 (UTC) Received: from localhost ([::1]:48104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAJCF-0007qd-9m for qemu-devel@archiver.kernel.org; Wed, 19 Jan 2022 17:12:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjx-0000GV-ES for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:37 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:59362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAIjo-0007Q4-Vc for qemu-devel@nongnu.org; Wed, 19 Jan 2022 16:43:32 -0500 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 20JJgVKw010655; Wed, 19 Jan 2022 21:43:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ne0x3EW/znUCIDVdfl4xc6s9TnTcOayv0rBdspSByh0=; b=kzmw8aGs84GoxnRtTxCzP/F6FP/1VkXHJgNfSfv9WtH05QpvG9vX5yd6SgZLZOgQ+ETW 0hpcPICPDgVxjs4DAz9D8LEEZiYwX3pqrArw8fnZRcclzf0Y9I0B3Fw719jk9SHAfifa cKlP4vTTS9PEA5TWoi10/I4o58KoLJFkJtVlLCR1mAV+UOpSiDxG0AGfXnbdRkvkIBlu cjk97p7EIuOMhJQfH/2CGtyzeg7u/DgYVKqG4sYZKCQndzl5Onxh8NfCQPRpa1iVO9+W J6ibNWnwHNIf300CaaGd357DKRb2KAlhwlnnS58OKjas3urQq9Sn4OjxS2L07BDnoWSw ig== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc52xedv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:23 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20JLaTuT030985; Wed, 19 Jan 2022 21:43:22 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2040.outbound.protection.outlook.com [104.47.57.40]) by aserp3020.oracle.com with ESMTP id 3dkp36kg60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 21:43:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RMGgn2umgpuYR9f8yR3T0o4UDTatztlqW9Vd0pbEdaTpiI8Tzzifga7aNMvaoTc3PDCLquSqssd5MhNwdK8jcKTJdeJtUDvqXvHS8hDE7SdYFSj3ERGBo1P7AB/fQXW6uQXIoo0MkXLactERs0Az90+Ixvuwg8FAC6mJV6bn75PkDrH1Sl/gOU6xHQwsX5ciHFtrikKtfbdYTEGQTx/zMMaEWUhP3SP1nkZstJa9JTm7FOnQiLXjzwXuZP76a4ulUSDF6z5bmROLEqa2yCxjlzZUj+HhIa3upZfswC30Hpg+wBvLFQIotUBp8otlFMhVWbo/poVQBAlJohvOVLo1hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ne0x3EW/znUCIDVdfl4xc6s9TnTcOayv0rBdspSByh0=; b=Hofq4tY8zFn1jGTCIxJFLeAR4FeZR2E77R9UkP2rkNi6wU6Q74vpnOcCel0Ii4zRDtmJ6FebgNynnfDMr8G8wnB66NsOXzJY2Ke/dm108CtiuGfsZrSRDd8CiRuFnSZb7lohOEJHQM5FUmOwFQrMKU2ltxlhcHt4wVoowPzIuu7TKBKZytU9cExE8yvVV8fJmSMtHbBGIW1FHR+tsFVlkDRHQT/7D9FolJLqMH/h6cm/vye7/+lZOoTgV7sQzx2UPD08IZgaaEDEYx3dhgZ/3p0Cg++Krp88p3dUHDyXQZk4J/tu/+jyc/Zx370RP3gGds7bfnoK4tR7k26EEc8pHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=ne0x3EW/znUCIDVdfl4xc6s9TnTcOayv0rBdspSByh0=; b=vzEmYLqR+Nlb+o96kA3Lt0SIXRtz50Fb62MHgcPWTxE6fVOQ9GEDWO0sb2Df5ecOYTRAvao5rpfC1fXMoKSjcSVFalhvQZFQhDGTtGOLp242LY9IrIRhDlVAQfSoKZdDi+MBYDKsFA3DxcYpdg9EZbfdEkylOuyhQfJ/rvlNCYo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1497.namprd10.prod.outlook.com (2603:10b6:3:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Wed, 19 Jan 2022 21:43:20 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::98b1:4348:5117:5fc%7]) with mapi id 15.20.4888.014; Wed, 19 Jan 2022 21:43:20 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 18/18] vfio-user: avocado tests for vfio-user Date: Wed, 19 Jan 2022 16:42:07 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BYAPR08CA0043.namprd08.prod.outlook.com (2603:10b6:a03:117::20) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4d708ac-3aa9-4f01-8c82-08d9db94b594 X-MS-TrafficTypeDiagnostic: DM5PR10MB1497:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e4VdbMui4nApAr5cN7QT7q5iNUkb3Jy/aKSiR4xqrH1TyQl7XD8U5Jw+dafV2IPEAV3VAaN4wu6nnF37GWbJJXhoyd07TWks/VWHlQxwHGBcvR2xRsuft1XOyoXsEwm6kAi061gN3d352TrV0HUsv/WJ5MraTizWuFFqsA/t2K6g4/FuPQLfQI5vc65RWT5x6R775TPIYaaq4inbaP6/MX9pRR/hMrPRxlks6yUoxYfSt+20D2CLymsUpZKQMPXEIGphoq6nasGAr9HYnSZFgTJQDGadQeZCNmU6eNKOyKkbZoRY7V/f6VZ+2aKxfGATQ/OPabpiebHU3vpe7BQ7QwwZhhOHJOZeZkn9by9uuMbp9b5Tj23b5wgNeMcDrnNirG/rnBWl/WxOnrQp8CFkK4g7uaWBiRfxRfEbcK2jFhGeEqIUH8fpy5AyYa4s88Ji/xPDLsTfIqvxN4828fDXcsUZrK5zg+fUsIGCw44LKjSKBGpiXZEN9jQ/TiRyTwJsMZyGFuLspOcsZSCpK8FU9qFw52M0+kopEV8LJ8S9kMJuEPtH9OdvgUIpUTIqjAfk0dNOvUasOR3NXhxDkWawfVqE8jbr9DfXnGVuHDVarN8CEkpIQuRG3ZlaLXv2PCVaq+lWcgmWcpJE3LKMADrWvba0G0kxL+1oNdgMAgn8fK1lW0+8NJulV0IgvjTd8NuXEISeKbO7PuvoMQNDo5uHnTiCchdWVSDAxN1kcOWZVAA5YY1A/5nh3ibWgdoYybsGIsriFbg8K2Hd7P1l6XUbfw== 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)(6506007)(26005)(5660300002)(2906002)(6916009)(8676002)(86362001)(4326008)(36756003)(508600001)(2616005)(6512007)(83380400001)(186003)(8936002)(107886003)(316002)(66556008)(66946007)(66476007)(38100700002)(7416002)(6486002)(52116002)(38350700002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IrsrfB0wCl4EVwKH5RphdpCpLgncriWZIGdGZd06j4/MB7uMUzm0sy6Tsw13BXP80fxBf0MeYvOr0MVrGQ5u0wVQIhFPH1YxfXMrYOHQJkNwnNPjQFbH53rNLbz0VOiLETsi2XxX6y3/1n1KO24neYoXmqAjKYI5V/RnEBqwvMTCf/XuZmKoN9mTHjpIBQoP4l+k8nJaDM69kvuF9dIgdm+j8mfshJHom3k6lLnnC3noySTAu22hMpNsjf9DMwtKKld12DVKbGHiw7+PRkvj76jwt8ZFwqz+IYiVzSmUVfkcPgwaG5HivB4JN/IaeCsaK962DQ7rN4tL779vOP6Cjx5n2azNucwwQZcSAB+pykeHwI1ONgJ3dK86tvpBrLDpJfJNWlJxt3GYJBNKJtBS9abHytf6zFH6A/blIb5rMk5nexYnYzRPZ5xUMc278t8bnIS5v6uHtuOHzNSVfrrVXIB2jVTxNPeL3BnNKpqZjUN5tTjKXkB8NW49B8UFruEY3pgY9GkVJEkS59ETM8EN1QHStmBY33Q76rrH7fy81Ei5M6apfIGT3DY2Z0NrJyzPMvdkpB1fzZG3lVmCT9XAc9jQ0ITjdV4fz21flEyxoj3TLilk8eKnjxpM9fZnWQUVXp2e0AZs0CS9iPdrG95Me3TO9DrMoxPWfUEN6oSPu15lgo/NuxLMXl4+/Xslepl9xtDfdT0OWh37sym+LbyXBbPkpuESNeuVLmL/Av8rzoUosQGcCX2PWhWlB4yXCTw/8+dhY0EPcmWgq6k/8d+0ohxbM4udGF5BJqRbn/V9jOl9mtfCKmKlU9XQdjUy9dhwuQakIkyHAbcifA6yc+EWwx+NLEOXYRBNEeIkPEzUsNcvtoH423mDCEcQSQfFYVQWRq7Yj2u8wxs8A1z2+44y0eGXBUZfDr9ok1RJ65ZS1H07DuffYo/Ot/0Gyq8rx21Z+TwOgC0/f4AOUjwGnFS8AyGwQb9qa4HLPaKI56NVKekv2yAcg5n9Dt5PVAZ96cCSaKLFUDxLKCdSCsnlmIdHAB4oVFQaHuaANnsUukIeVZdJ1/HYBIC/E2SkoHNsJ7u2ACQkfKdxsszJqm+rgi0CCdSkKCCJ4/QTtsmswwWGYq0TwWUPWZydzJZnG+pH7mvEcztCV5kAAJeunjLSrsjkcY8WQQCCdovteoZqlYYtkVLRXgFRnxCjjGAxcaMGOtv2L6xrCNLknHBZVyhcYaLv4OI+JHGtBmSp+nTfW7VIe0fmlwIGMW4MyDdYALGJaUPYAU5joDVF1SJA0dWUP0FgJdUL8tuZCbZEgrZxqleghgmKGUFqOvXk9OplMq/K3+O9572vfOK7kSotML3JH2R4VnqZIrysJ7laMiabDeStw1fk06B67kwP7+0kPkgKl7seRISIbMkI77Y1iVweB7SsDDmFlU+M15kmrh6GYslFGfMSM/G4UCHnsRDquPEu0P1UhlKVKP9sC8xpkKAImrCJ2nbuH6qgIxiwCf0nE/LxK1UMbYdjEwrE8q45h2WGhw2HaSq4hRDaSQcXozeYomQZIPHvqASjS3ST0Sd6pWZKRBLLEmRmZKrPX7BZPsa+NnsAi89wGlNfPouBV0VlDOH+beLXYlWrCK6+CSIU8xd7V2U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4d708ac-3aa9-4f01-8c82-08d9db94b594 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2022 21:43:19.9252 (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: zzGNAqVlLLiURXUEl3xi+o7atov051Kw9Adja2N9YkNu0mWoxgkOqRYObbPeRTxV9W7jKH/CzpgJzkFFD8Unrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1497 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10232 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190117 X-Proofpoint-GUID: Y0cSP6OxJhXykbbL13H9gZk_QjZv7emO X-Proofpoint-ORIG-GUID: Y0cSP6OxJhXykbbL13H9gZk_QjZv7emO Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Avocado tests for libvfio-user in QEMU - tests startup, hotplug and migration of the server object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- MAINTAINERS | 1 + tests/avocado/vfio-user.py | 225 +++++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 tests/avocado/vfio-user.py diff --git a/MAINTAINERS b/MAINTAINERS index 93bce3fa62..9ef9e1f75a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3488,6 +3488,7 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: tests/avocado/vfio-user.py EBPF: M: Jason Wang diff --git a/tests/avocado/vfio-user.py b/tests/avocado/vfio-user.py new file mode 100644 index 0000000000..376c02c41f --- /dev/null +++ b/tests/avocado/vfio-user.py @@ -0,0 +1,225 @@ +# vfio-user protocol sanity test +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + + +import os +import socket +import uuid + +from avocado_qemu import QemuSystemTest +from avocado_qemu import wait_for_console_pattern +from avocado_qemu import exec_command +from avocado_qemu import exec_command_and_wait_for_pattern + +from avocado.utils import network +from avocado.utils import wait + +class VfioUser(QemuSystemTest): + """ + :avocado: tags=vfiouser + """ + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + timeout = 20 + + @staticmethod + def migration_finished(vm): + res = vm.command('query-migrate') + if 'status' in res: + return res['status'] in ('completed', 'failed') + else: + return False + + def _get_free_port(self): + port = network.find_free_port() + if port is None: + self.cancel('Failed to find a free port') + return port + + def validate_vm_launch(self, vm): + wait_for_console_pattern(self, 'as init process', + 'Kernel panic - not syncing', vm=vm) + exec_command(self, 'mount -t sysfs sysfs /sys', vm=vm) + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/*/uevent', + 'PCI_ID=1000:0012', vm=vm) + + def launch_server_startup(self, socket, *opts): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote') + server_vm.add_args('-nodefaults') + server_vm.add_args('-device', 'lsi53c895a,id=lsi1') + server_vm.add_args('-object', 'x-vfio-user-server,id=vfioobj1,' + 'type=unix,path='+socket+',device=lsi1') + for opt in opts: + server_vm.add_args(opt) + server_vm.launch() + return server_vm + + def launch_server_hotplug(self, socket): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote') + server_vm.add_args('-nodefaults') + server_vm.add_args('-device', 'lsi53c895a,id=lsi1') + server_vm.launch() + server_vm.command('human-monitor-command', + command_line='object_add x-vfio-user-server,' + 'id=vfioobj,socket.type=unix,' + 'socket.path='+socket+',device=lsi1') + return server_vm + + def launch_client(self, kernel_path, initrd_path, kernel_command_line, + machine_type, socket, *opts): + client_vm = self.get_vm() + client_vm.set_console() + client_vm.add_args('-machine', machine_type) + client_vm.add_args('-accel', 'kvm') + client_vm.add_args('-cpu', 'host') + client_vm.add_args('-object', + 'memory-backend-memfd,id=sysmem-file,size=2G') + client_vm.add_args('--numa', 'node,memdev=sysmem-file') + client_vm.add_args('-m', '2048') + client_vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line) + client_vm.add_args('-device', + 'vfio-user-pci,x-enable-migration=true,' + 'socket='+socket) + for opt in opts: + client_vm.add_args(opt) + client_vm.launch() + return client_vm + + def do_test_startup(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(socket): + os.remove(socket) + self.launch_server_startup(socket) + client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, socket) + self.validate_vm_launch(client) + + def do_test_hotplug(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(socket): + os.remove(socket) + self.launch_server_hotplug(socket) + client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, socket) + self.validate_vm_launch(client) + + def do_test_migrate(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + srv_socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(srv_socket): + os.remove(srv_socket) + dst_socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(dst_socket): + os.remove(dst_socket) + client_uri = 'tcp:localhost:%u' % self._get_free_port() + server_uri = 'tcp:localhost:%u' % self._get_free_port() + + """ Launch destination VM """ + self.launch_server_startup(dst_socket, '-incoming', server_uri) + dst_client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, + dst_socket, '-incoming', client_uri) + + """ Launch source VM """ + self.launch_server_startup(srv_socket) + src_client = self.launch_client(kernel_path, initrd_path, + kernel_command_line, machine_type, + srv_socket) + self.validate_vm_launch(src_client) + + """ Kick off migration """ + src_client.qmp('migrate', uri=client_uri) + + wait.wait_for(self.migration_finished, + timeout=self.timeout, + step=0.1, + args=(dst_client,)) + + def test_vfio_user_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=distro:centos + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 rdinit=/bin/bash') + machine_type = 'pc' + self.do_test_startup(kernel_url, initrd_url, kernel_command_line, + machine_type) + + def test_vfio_user_aarch64(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=distro:ubuntu + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/aarch64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/aarch64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'rdinit=/bin/bash console=ttyAMA0') + machine_type = 'virt,gic-version=3' + self.do_test_startup(kernel_url, initrd_url, kernel_command_line, + machine_type) + + def test_vfio_user_hotplug_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=distro:centos + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 rdinit=/bin/bash') + machine_type = 'pc' + self.do_test_hotplug(kernel_url, initrd_url, kernel_command_line, + machine_type) + + def test_vfio_user_migrate_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=distro:centos + """ + kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/vmlinuz') + initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora' + '/linux/releases/31/Everything/x86_64/os/images' + '/pxeboot/initrd.img') + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 rdinit=/bin/bash') + machine_type = 'pc' + self.do_test_migrate(kernel_url, initrd_url, kernel_command_line, + machine_type) +