From patchwork Thu Feb 17 07:48:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749513 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 F3B3DC433F5 for ; Thu, 17 Feb 2022 07:54:17 +0000 (UTC) Received: from localhost ([::1]:34216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbcG-0000aL-TY for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 02:54:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXd-0003kP-8Z for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:30 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:62218) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXb-0004R1-69 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:28 -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 21H4RVGt010846; Thu, 17 Feb 2022 07:49:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=VTjWafM9t/8ZS+8mz/vsztcccCTsO5fahMk5KsghvJ0=; b=TBGTzSDfQ/0Hm4nL2/CwVmLgwREI5M+xx9wIFHUosmcMySz+UbLbKr85pI7c9QgGzEqT gPpOtc+Gwt6S9tXnOPGI79LRx1yeLYQJopxg8ZIPhLKGop5t2S3JTrSgqQ52t/TvjcH6 8bv2837ypYrX82OqRdp9ZM1Kg9/ZhVqRxj2gPPrOHh3PvFJemPQRsmw+lYBcxPFnxonH BL7O4Wm3lFzTU0HZz4fQVwSV3E/0ebVlaw6fS0P1Kx4Kw0auWMYmj3K1yI45lT80YeJb 2T4y9jFmqQA2QOeuE1NZg3vaWx3hAIQXRwVYGBXthNdSksPmnpQHSk94TOkwQYb0hpKS pA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:24 +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 21H7gVr3135681; Thu, 17 Feb 2022 07:49:16 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2041.outbound.protection.outlook.com [104.47.73.41]) by userp3020.oracle.com with ESMTP id 3e8n4vjduh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JXOrb0ZphP5I5dTrWwQuM0R/DN0oideOlRqzrsmMvX0nIRlLV9dwfo18NvRq/doL+OJkqhppsdYEcbhgZfStrg3UuwW5M2DmB77UhXWSYPoLOrkIaHur/BgznVhZisUSZOr95lFFxCDEuj8XKOXRQd6zdIDeVNpohtj1ns18ovVSS0BsnUHS9n40YlEHGO+ngu5TLzflfA+dTOVwx32gKD88GM2oauke+fSoOl85GBUz/AbELIJK1uFxkEDREKAC2tNZrRTRiag1xpVTUUQ/h3YGYnpcAcOgD6f4ro5KR7/1rKdQ/5eQEYMDTu2q2I7j4Fg2ZBayoF5MuPOMAXMFNA== 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=VTjWafM9t/8ZS+8mz/vsztcccCTsO5fahMk5KsghvJ0=; b=bi/M3QitoNK1oV9gTuKUf1stACRivFx8USl5JQvSlN/ZiNh4b2PvDHzfzbCYeVcjCIakaYBj5DbaiMcR8ZnX3VeF/8kqm8MA+Ea2jsaF5phG0A+WlZhQu+pPyw1ijaHjGStQHw4QYg76qaFNPeXMAYynrwwGIZOVqAVNvF7/xzKyUb1r4VA8M1MsI15KZUB0f8nv+hJJ3teJqzY68sk93FPZ9/hq1s/QohoXI8DKtGaapx3KWGGFZJPRCbFqZbSyhUsPHggTmT2MHYiBE9UruKMa6POh1WrE7QyaFDMyHr5tkxe6E8qwFE2Ul/QHRN1pLUr+5TAPA+bpIx8tyU7ucQ== 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=VTjWafM9t/8ZS+8mz/vsztcccCTsO5fahMk5KsghvJ0=; b=KiWS5jzlM5SWgRkA5t42PZeADFnbwc9GJWxgbRFZmDyZNGfWCrJmSmQ7ZuKWjzVFVAGvWJkvprSq7eDh60ovvXEiez7/3e5yj/D5Rgs3XlYwFO4LxQWBqchtb7oNii8XkK3U61y6n8sWN13aqy8kjnIU9XJuThhfuBGBHIJb4dc= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:14 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:14 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 01/19] configure, meson: override C compiler for cmake Date: Thu, 17 Feb 2022 02:48:48 -0500 Message-Id: <4bef7bdd7309e128eca140a2324a126346c9f1f1.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ffd38354-ca6c-4043-0ba5-08d9f1e9fe26 X-MS-TrafficTypeDiagnostic: BL0PR10MB3009: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: Jezw0BraAaOg29V/Dco1/vZJTo7bLF4DDvtu1bTAjekpmih4w6sjSGjH2PkVwRn7mOLUOaaFZb20S2kh4+RCkR9cWAiqKAK8P5mrnZJne0kA0MOC5R+Ce/6g1FleKD7WdI5UvvGu05JWkNCwZETruZxc7DcDJFv4gBaWv2TdwqebIfJuPz0F9rvYh+E+hoWT0483MqWEN5usDxE9hF6UrLla10Za4L11iuUS+Lq2IIeKoHC2Zd4Pqb0Xj3HJcJgGKojn70NlINVCR1uavAQD74Gi/47ZHPBfK7hsgLKxbaZjk2ajeP4xWsHY76YHal7qtRTyugd4uMPQtKsNqjprldTPKA7xZhgvArVWzvsMnXZB+TwQu0f/ZKXrwTChCorTtNt6cPJl0FJR0IVlb3crFO0FEGz+Q8AmcugTakLztBWkCDxGYhN2ERmzPYUGOjV/OSXuTZ+MxyyUkNikJe2pUmD1Qqkg3xQT8Q0gc35EcUE3z9/Ujx2qMR3a+4Z0iaLaJVIBaMa0wVZykU9oj4dEu756vzJwrtR/ALW/66DtHv1/iZtPCF2Xe5rbErqgHt+xakwQV9yoLgIGZL33bIdFgEr+CTYMdjdwO7ZAspiSRICvef4MYcvQa4dk18QrTcJnvQU0w10DFedT9aPTNvvT/wkVve4WyGI00V3go1Z5oWTe00+G9Y1FjSCMk103Qq5++mNICAoOlBtzebBwSXb6eg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Jx9920RWeQFskEl0ibWwPF4jyArb8MKW4ZvM0vmlGd/mF0Pr2lPvgVEDrKUkJSnAsuA/tQxul/rr5gwZKFrPvQyh812sAMng/1FactkG5IxbHW/fd7WJrbHzCE8RJmIWr7JGUwkK1CPdRAtw7dTLBa9p4Ci6lyjAq0STW9s95Z4sf89RO8OPS/YqmBtA7MWP/oEyPhb1vmbFslGL+6B6jvVt+K7YwLIvMmbo091WL8wFrtiAtaxesG93ebrZ3/7C1fLfPJueEUT1SU8HAjriBOMR/hgnYwrgApHyj6NjIWAuDAYRbpZVwzXZRJdTu6+cawOn7WPMGJH3iV/lqNc7EwvTl/+vD/3WA+djdL481DBl31FNGfgQqgKZD3wBGRypVEi4Gyf6FWTIKGnfpTibNNgoK4vUlsfAGiYjh38XROMpzdkHz7hJnw4ijF2N3WTlft0uJ8GoFk79ItVMLnfQuzKH9Wz8srUPc3Yk+krYXJ9tiSg9WSKNZ1v6UlXE35NvH4pJRtlEDYTkX3XtFUlfBM+JBwrxbqayhfn6p5hts3h1/qzEIuHho/N7h/QbLjhsxLgT9iN/R3wkAt/uWw1qsjpJeWnWcxHOYEfuNe9oYAg5vvqP3kw8iRbuOYmV4yakZmB1AGHZcBbxerAjgDoL8tQNeVMFPXzhNQ+kLkwFzJACcvf9RjPBKk8YTRD7n9K0/T8K4nk08r8uAZu3xlDl6swY3mzTt6IG9zCs4oaexgiB+xYrj1QsdyYHxcBIRYRmqrYTMxs0idEMRpIouBPuGv2/qFi3g4xqZ9Kue68NYnqMN0p669XM1kNSGTenOm9IL/ZWpQoPos+7vJrsI4kIbJRE1q9vk34jkdDfvW51efZb0RVdcm4AzHs1dp5vDkEUbar8hM9/UTDPo4pIOxCXVOickV9DewWhZeITbdX4KQDO5abmaQ7qkQlf/2DSoxk0ueQGL0EFR8sA0UfPIXXX1mufRN5cXDWE0FFUu2ohmuTdJ4aui9W3mKs4FV/vf81HIwma4ZGufDNfOl1Quxkm8eDXwIesJCvDEStbBgjPUkrFkncFrwzbhTUbpLvyEyIwgx463/Xqi7JvrE9QgkHRYUAFf1iZ1E23HJ6PL1H0YiqbCnFNHrCCfn7fluWh/vohF/+usy4Tf0pXNBc2rNQYyi3peBXBeR/uEz1teX67bQruDtaxiL+jPOAR0BzZIVo5JQIPb7FThWq5Ukdc4isHqIuP5xxgp3UP6jKoFSYwR2nYJN5oiuZE+21Znbg6w92yhvt4NwXTTEv10pOaCO07v18xlgQtzbDSJXMOE4bU7aQ721vqFAton3BZKdMQGU7SFCuesahlf5P2Ihdm1yqUzR1oNH6xkNumlNZ88Ou49Y9uil9OKp4j3JqpCqeNnxzL79MU+Ux6mjmjjOUoXSDE+0l3vgz14L6xJeKxoy4g1Hb4VOc1aLl8wpJdaU4LO0AQMmbuk7H+1y8DzYPLq1hwpYNwto3XJoK8O5uJdsGF7AkUneTgjAtQqNcw2fjHHWrxMlM5GkgtkVLYWaUhlPAVqYKCkD7YNd+o7TfUSS6fA22q3hVZT20BjqRKtTUbf24TP7XcglLSlhK+d3STy7pLSwrIBZAstRccBXAS2KHEqA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffd38354-ca6c-4043-0ba5-08d9f1e9fe26 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:14.4778 (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: FdhFtqnlH/KNyphUYQUJd2M6Om2Algf6F+V0oT4c+/6hIXBBsx/MhdHeKSyndJf9G1GLhR/I/FbHoFKog9jzJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: 0-mD19eV6dEn1EeNQJ4_YwNFM-mDaP4w X-Proofpoint-GUID: 0-mD19eV6dEn1EeNQJ4_YwNFM-mDaP4w Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 3a29eff5cc..9a326eda1e 100755 --- a/configure +++ b/configure @@ -3726,6 +3726,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 Thu Feb 17 07:48:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749563 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 8D276C433F5 for ; Thu, 17 Feb 2022 08:11:48 +0000 (UTC) Received: from localhost ([::1]:52716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbtD-0005LA-F1 for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:11:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXk-0003li-Lz for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:37 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:2562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXg-0004Rg-2j for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:34 -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 21H4exgZ005355; Thu, 17 Feb 2022 07:49:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=It9K0rrol0s2cBhpnABxoe+KY87TmuaxFnQOT4MBPQI=; b=fggLYx8ht6/QxwIqkCdBZKmlX+zXV7vN7zm69TXUCg0SYWHq4WYoXgtrWXO0Z8+uDJAF IkELFnabXyMd1oZH81ZZDQmA5xAHdH3OHVD3bxC/RwsLH3V3z8Ifp3hTvq6udZQwpqnk 7ZZHOfh2Ib3T0Fd+xWnoMeCO+D5+CS1SVWV4dbOC3nFOY8yXoc2z0w7VLsp54NIrGO2w Pwuwc+DGLDIAMplK93ZXoLH9H4wVPsB0VpUYePMU9ytWqxIjyhojgY0TVLPi/VPUZGP2 rBN6raKbpLJUo2mkW2qxWTqOXd4RGQooRgHfdnQoepuA7vzJdwJ1dQpEeCzwk2tvNaMW 2Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8ncavqwm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:30 +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 21H7fJOf142804; Thu, 17 Feb 2022 07:49:18 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 3e8nkyqrqj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VzybnItqRNpX7ApFZoqL4/+1IXv7/rnvhTFJX05nhWsLA3gdP0CpI38weqXV5B5eZYc4lXUWpz5AgOHtEE9WiMwXg1ttNIT5izd3m4IK3hrxJLEpC+jmRlNjY+wNYM4IK813nKgpwAxMC8JVvNhTBUnOXsNF/dYGOw1tonlexIAgK+vxcQ+dLbmMIuJEHeaxpsDb3+Th5IQbL9OqmNoy0vrWh6MI3fCxf0sQfvVuKj+uF2JSN9bCSDsnDof/eSKtKtG0Lj/NaGLgpCFu6siBUf9gvw96LKAXRp3FAFQGiXEgeKn/Yjd21uPXtTSbk16dfrBUJp1JJToMsb0FPEDUSw== 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=It9K0rrol0s2cBhpnABxoe+KY87TmuaxFnQOT4MBPQI=; b=WFxWUgb4KFlG8ZnR5EuTgNzwOmfPjBqUKp0GR4DaVts60Ry8Wfp5JdC9p4qVDQ2McwWa5ZyN5VwKKYhqwNk4Fjfz+hqmzBNhPvDu3QEA/PDTo8ZR2qAvuYDlbluMiqV+LSSkLwkAJscb1ont3nVIDnJxu9sz86euFx0BCrfI9WbpFyCQLPX6aV6Mqv7Iu/wDlrZCYQ4/Q36X6qaroDTpqLfqX8bFzzB27qbm3XevMVhMdS2ZN5NIX9aL3/6Pkay8X7HRELeH+f/q5lb69wdddKeIWfm2fzCTHaDkDziVkgImj8fr+jKF6Ue+d0/OYsnpPi/75ZwpSdYlB+A+RztnsA== 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=It9K0rrol0s2cBhpnABxoe+KY87TmuaxFnQOT4MBPQI=; b=mQbGwEXuAIx1SFW78ciVvWqqzvnkcS8fRrx4LK2pdtG/i/yk34rzmRwQ+JBe/YsHVS0oNd2viCP0AP9RifvkYTdkzFnQMEsd9QQb80EvIQgKJU4PxYs30OmaNEdrEd/Xv9clFzrdJcYh0iugebEJHH+MDB5tOkuw2l8bEedOBok= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:16 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:16 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 02/19] tests/avocado: Specify target VM argument to helper routines Date: Thu, 17 Feb 2022 02:48:49 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab083fcf-8da3-466c-6c98-08d9f1e9ff71 X-MS-TrafficTypeDiagnostic: BL0PR10MB3009: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: 3ZOnw27xeTqpiUPVtecTE9tFpq5XBFg3JbyEMOB2gT2zj7Bf4XQW2uqleJm2MsQd1PzJtvUhlpqRG9U/PLAhSGEgnJnk/4PsRWT7X8uTHvortEmETtp0dk1jOWeRjKG4BJElBin9iiRjDR3QRDLzC2VkJmC2w1ZeUFJI0+a5rSTI7CBviaRJd9QS3bJ4hoBZ3xLujs3WDeMewYx3yRX3BW1djm9hmWrfhFnKhb8pREAMon2vqd9ui57KG/O1CDiChq6HVawIbZKu2XNYeAmbw9zEQnCHC9O9G9Emu19YMsWEkp1SPtHthLvhCds0AAlg2ieY0dZYzD1bxglP9pxmnukZLmfzmirQEJUWhAkOohpyFbhF9XFaX4SY3tqNNTdqhWUCI9Nw0A70jnzcHhigOaFO8j7Pq/myA0Xi+X5lk2NVKRB5MvAlllbF3y+Vsjx0srXn0GX13epjNoENNNhw/x6cuAV/B7bTYHrz2dPjAid560zNLAu2+9vPl3kRUnocrX9ScEhjqqT3axneHP7O3ZFZf+lcceTOsWG+fitOxWHUdP+c8X5UQd/IX0L1Sv9AI3gc5ywShJObU1IlYX+OkdwT4lYUejomOTuoJhBeUAp82PsPdKuDkJNM39YlfQ+r6GXDIlDUiP8z6QFPtNBSQKTJfD4GLF2kqzBkITC3N+m+qJ+XFErQt5sXL3pBFwcqSJqvGie2WIP8xEkI/WBJ1w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(83380400001)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?kKtz9+KlvP9+H9xSwuMZN6R8pYG5?= =?utf-8?q?QplY5rrvbV3cUinZfKYXaDgct2zvTWCF9am2oGC7JUtNl8u6mVqd78AyT6XRtOnTg?= =?utf-8?q?mf9uoKq6sWAW6FQSYzD5+2sKktMLHzv++/Ky47JBmM4EvMwwEzoIwueZM9ZUuEVou?= =?utf-8?q?Fzhix3GXUGzQ+t584HqWwcyltExMq0dMv0VP674gTJprwwmd9j0ovIpRs9/0T/uYH?= =?utf-8?q?ocuMFhNJ7VKBKWxv87QaLtM8BVqM4TXW6Kym5YOud6Z+ToAXha5j1Z9Y+2Z5xAxvN?= =?utf-8?q?uXfyIQ/V7MB7s4S7QOSO8HSCrj1q6Mnn8fTmorZYDp6IBvAxccy77uxk5uXsqW/g+?= =?utf-8?q?rmSHejWK5HGlXzWfcHT0WRN3jsrzKUq6hYNxV2RzwljB4RG+WBgOrX4fQpk8jG4ZD?= =?utf-8?q?5/0SV0FOyJ4gviLM3/OoEm2l259OPkagGfYUqNpplCZ3ZMUxWaj9mSDh7rEaSalzl?= =?utf-8?q?fCdeUmTJu9+Dnpp756/c4POvERim+Y9XDl12JWv96DZfDVM2o/v/UelHaT4JD37Ji?= =?utf-8?q?FE3f54WKxGtE9XfgCAuBvMACRfEQxj51AZ1GdaeLiL4y2WooWneSJ1Rhcjb8H+5Pi?= =?utf-8?q?WkkJQYznd3JDF/ODRcUCcrxDaB/o57SbARvh9CpkmwjZpzKQ18yKlpzpsS5ASEmP2?= =?utf-8?q?WGzjLyvDXGGwbeIBoysbu4Y8QL+FmeOvDSb1wwiVanaQ1bzlWlwumTdILcwXMkQ10?= =?utf-8?q?5kAbdQ7oLb02CnsXsOq6upDKcfSTXjNFmiEEOgdLquhoUDyCOdeFFHy8cA/6fVxJW?= =?utf-8?q?d9ZANub+zzWflPNPv/VxMC7bv7IMYFb7zxYaOiLGucr/ftQI9MWMcRZrnymDs6y9t?= =?utf-8?q?Y+H3HusSnIqrHYmNWaPW7IJ5gjnYeZ52vVf6kH6/plnPUx5HOVJ/R/CCMz217jbAu?= =?utf-8?q?MqIjgWHUENV+Aa8qKc12GqEa+Kt5xIaIXmAgfEwNYP9h3P6OyeXKZA6OZxxRqm37x?= =?utf-8?q?jRCBi/tZWvt9TEcUAjyCPrmglnC3L5NhT5uTqplS2dFZ4NawuVgJOk8E7BZbRsOlD?= =?utf-8?q?aCVGi3a3ItujotRJWsA0tYVajU+1q+f5eUzV1Kj1qIpSwB6GXJn7CK5oQqu0uj5U/?= =?utf-8?q?uioW00a0gIqjFCUY3ODDIjJt1oTeMs17ePGOPLP9WyDxRP/1LrRDa2JNuYFmcqPEN?= =?utf-8?q?siZOFAoqBy4gNddQaEv6VmLu2fpA42IE1O7XU6K+PCmpVE66KMRP6uHT6c8Bilvz2?= =?utf-8?q?XUmH0b7ZGZYRJrcHcldw5ds1Mp1Zp65EOg0jgAi+lIyPIaMFqpjm9kwG+uPdnAB/k?= =?utf-8?q?pCOs5jjWfuGnpaL0JPWoTbxSu2z9aHKHagG+6rDj5Q8/2KnDChhlHvY6Fa1O1oC6s?= =?utf-8?q?r9TOZQigmyi69kRwA7YE00RWgMz5rnBhLB/Lba0lo1+3WvgT4VOP6pUyMmsdOh4j4?= =?utf-8?q?oi8MdnLMeaZQxSYzeExLcPoCf+tGAXFqhkn+dqU12B/9kCDwZol2aRZpaMQu1A8Xy?= =?utf-8?q?OrMl+/242MVvdK7J+vrYECodw/Pf0KUdvjFRrC5OD7wVW96cjPOKN8MGmgw/dAYYo?= =?utf-8?q?QHh5i4PfqmcVB+UK4BdM7AQ1PJ+zTfZF2AdX/wg9cn76h7SS5ItqK84=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab083fcf-8da3-466c-6c98-08d9f1e9ff71 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:16.6026 (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: v9img1T71rUe6m8gq5/Bpg3y28rhoFuXOB7/6jGVlj5CqSOwtLyAvjXr0zVbnIFpnLP+PjlA4ivdaD4u2XhAwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: 4cx0ZD7sBDS_f04nS5xAmGDVMvncXoZt X-Proofpoint-GUID: 4cx0ZD7sBDS_f04nS5xAmGDVMvncXoZt Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Thu Feb 17 07:48: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: 12749539 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 429B2C433F5 for ; Thu, 17 Feb 2022 08:02:45 +0000 (UTC) Received: from localhost ([::1]:45706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbkQ-00005o-7f for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:02:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXf-0003lE-Qr for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:33 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:64084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXd-0004RB-4H for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:31 -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 21H4RB0x010826; Thu, 17 Feb 2022 07:49:27 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=WeEMwwmfamCQYK/H1Q2W/6RyNxDm0faPPjQIJdS2mAA=; b=nYu0tF0r6XMZvbeSNrjMTq3k4U4w/iM4UTSv3npU67CCjphC8sbhnEcc2rEcZPKeqo58 5BYSZAtMvaOkH8IUTPGFRtkt5IEqOwQRJ/pRBmRwBTXl+AVf44nj0qQGXhrIzQfDZe44 4heX9qyvjrP+vl0Kd6rh+keRc1fPhdEin46NltQT3jw/aUeJvW4vDbgoW5cGUbdidyaG AK7jWyQWIO+9IYYWCPJXFK+DfmovAI13VwFGtSRbwUZNT4NlRyW6QEQ6dDfPraFEN54I dt0HC//wuT+2AqmymRDsHVo/VtliIcFDfS9exVy+dOLeInQtugnKO3WHhSauSEc3AFW+ PQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:27 +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 21H7gUYB135610; Thu, 17 Feb 2022 07:49:21 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2105.outbound.protection.outlook.com [104.47.55.105]) by userp3020.oracle.com with ESMTP id 3e8n4vjdvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CLaHjAcRcF4izlPbYqjJyrnHStbLlLEQl2i2fOCkCb3/Fg6v5CoBKwgCqKT9MNv7coBtLBmq9AUxsF9GVcosSSM1O7+QbtiFgjSZcwtwi4g6Ir/Gm8CwJatlQe0ekMco6ooP9uzYDskyRc5lmMDdRAbsdJZ6H0q7rAJywIgMvrNF8zEAxuLP1NhDOPkhv39i8rOBNhxNnGFSxRw5JvM7lByDAEZTZRLru3wM4x4K7TbSqAh+YEGcDDastlJTzbf+ZlrGw2cyIQ8lv6P/MXhcKT5lfcmGpiWVlRCKM3Ol4OKgfmEX/G9LmZYu4P/s1wvcxf07sCncIbqyFd5/PNHS7A== 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=WeEMwwmfamCQYK/H1Q2W/6RyNxDm0faPPjQIJdS2mAA=; b=GRdbWdAQV6t7mL9O9FbnhSEji+5hGKlkzwmCxLWTAPda/oUM6E+icNNgcrjou1Fwt1kyI2lzjZ1rO19a0ckVMBb9Xk305RomhaM6+pqwGesUuBlc9QG2PMdnvVpaFCOXJo24JmkykE2S03GITf3CJgvZPVfnr5nR/I9b1io842TUwGo6MxAEecmlCYTRDc3g18m3E0xNT15cfaAX1JpOYZyDjy29iAaLcrEaPotCdJEzA5gG25la9SAdOsbhFoLh4MMS/GKuRGosE7D0Oumo+9fkeIg9tlqZQRLL1Qpjp/sCoBL4m+0xecBrOu3VNOR/XVdF549Je59FiyWXL9c0hw== 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=WeEMwwmfamCQYK/H1Q2W/6RyNxDm0faPPjQIJdS2mAA=; b=Bn8tERSePpOMcJhhn1wq1Vxz7w5hCVGxYQ7BS26iR3/IyX9rukHbkobgN2sUvsFHoh6cFKCcBNvnahJcVxIdnjiFEo9hRB6A+bHZhznoO0k7zFEYhG06TQl897n5hHA4mJwUcn8MZawZpdyJN+IJACiTuJnBWO/XyEjtq7m4CrI= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:19 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:18 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 03/19] qdev: unplug blocker for devices Date: Thu, 17 Feb 2022 02:48:50 -0500 Message-Id: <5acc81b16d52949a47cbcbfcc2eacc0e4f3a5687.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 513fc9d8-eca6-4a50-cd8e-08d9f1ea00bc X-MS-TrafficTypeDiagnostic: BL0PR10MB3009: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: OC7P69oN8l+yG5A8QMB97uh1F9PGnGTfbgCPOpJeCtEwyiuwZOYZowyjz3jAiwSKRF7esq/PlihblGLdc5H1Skzs2BHitX5o6Fjo7vM0f9DYmXA0SgxwMcUZoTPlB0pknUNKBpEvsRdQ+NuuT3KqvasQAzHvaTnaUh5kE7ZldN0wn4UBTfqo5mmwk/GfOJPWKzryuc07LOxabmio1LKucTDWn02PDNEyyvox9O3lcVZ6/LNngefjzX9HQtL5Qs0E28tl7tyh/Xwl7zv+M5N0vde/15l5zzNf60oNULPpyxfKojY6jXk5JTv7cqFx5Fvay37ssvwZxP9Vsx7ASpIigFIPfyF+BXVPMReSlqGjHgVg4lPlv+gsF9n41eXcuHUkW860lCzhIM3BYmD6qkWjzEevtOAFzmOxcgzKM8wsSUKV+7BcOZ5lNImiV75sMQX+OiLlkuroXOkoHnp/mZGgUJBQFiAbX6pLFaE1yF7qTSbAOrny9+0ebQgrETU1gpHPWtvggDgT5Ofjl76Z1sLaVU8Apmwjms/ttaxNRPIFvMxc3Jwga6cO5AGxYuIfBJGI4pCyJReAfSQ/W/oYKuAXno+uMsDl/OEY2qXPRb9ttCKMaFD1jqXWLF1LEej2NFnWHggfVnFP5bElpy4SYZZjFHulzGu/59jlYjQdaCnuokjOPIpO5LyfOK26ppPyMJDypGragjN+AGR48eEUk0m58Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(83380400001)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T9bQGtRPAwPSFklTQriInPd5b+jiS5OKH4/HC3ud85qkCcn2fjBDu+SJ+W4MKqzf0K2H+M4gE71snF6/UKwQj6A1VDon5j42cH3oXvyE0NLkDyp+5THZn9+KkykWj+QB19hJhMyEyYw99KnasG1RFKJBhwvrKG/APyCzq6vbBMs4wqgB5ff+Z8azINqGxGu97rdNvMMwFQ/K/0u61mlquOFna+qESkwOZD7uCzjCitcARMgjZSXhC/HEN/a6zhHR68Dpe6nt6/jqtKjQMLVZv9z/oGK2FR/pLNHhJsURpdiZKakUgYp8+nGOLZSQQ7Bvt1aEctQOgHTWmMJHE6q+lx/5/B/3PMP2/eMeU4Iz1BbPljBSUWqLZwyx7FHFfCOJY0NfVxFlsJaV6pdXKHNLGw9luSzWuSDzxrSORUksmo0u6uTBDc593sYqUQFPCj3tV4rmeyFW8TPqlEpHUsodjb5aAtPhq/QCuZU+bCFCstib8rlIGSNIkORj+zjAhcic++ol4b4TT6L2isXm3Nn4SQcFfBd7KcSvWXNUUD+hmmmyiqmPMLYmvgDz/8X5Uo/hws+GO6xonrK0wRYpRuSdM4RUxqPcBSkQBeP/o7Ctgu+chFs/a2LdEjSNYjUl3HOKoTkIIE3R72c8GUMW6kaiC7JYqrKqnGYekWlDAnf2BY64u4BFh0qtAO9NtcHiBKv6mrZyL5YTsAt++zsKFbzQAOLboibIpvNCqHzs7wEDCdVo/NImmEeMW4VtkagwIg0PgVmVSAoOj8bASxs4xwdClr9Tvw5o1TfsE7goL/0Ilz5fLzYA9Y1lpuUA+RgMeohu+IXsUdNakclDgxM21hOgOqZt2oPpv26eY1yEirCCalMTgj5sW0vjfObjTQzo0BhoSph8cn9vtVxMWPnP4ciSO1M2GtlBrFmsl+0Vf77h4akfE6j8CD+eM2Z96UB+pwt/9KybsidfY4jLANjMQBnG6YsK+FuqG0yJxxgYxVHUVuMIkXiN09wKPyb6AVSsJS3CfxDMbBgx8FY/p77QmCd7N8jwT0kHdzAtc08Xi/tKHpBYHIEh1go2gpXClY9wY3/1ihrmdm3MIuu575uOxkYQ4G9lod+MkqvhEGtVfZQ4HfwP/T34R5vO3mkm7Xqd5hWZyTLo+lpl4NkyUDUfAccW2Hu7uY5Ainqe+1vw7ofNsDIsoNYziiKLiDcwEGVndJpXLkg63Vbj6tU80w69hUmX36Fiv8fIQNv3SwT7/q2Fm5U8HZt62pLyXzsWIsRwcYH5F7dlHKo3V9H/aAPVzKtglZYnl/sGveOA0BKJqlUVEowURuuekkjz8a1REW0BiVraCAG6UeOTUu0LVam9sBctojy0lup2T8c1K8f/OfniOG5G/6JaAqvDQwXL0k6lTv21agsKGI2Ua++rwAESwTfi4I13iKXUY/h7jb4Jfv2aLmbAUvYs8yiNbbOb8JK2abJIN7fbO7vkY/1ZNSumHSTOhzQvcVb3XLAK7TvqIGWb1hDaJJClbVtTQNMkKdnAIQ21L91hkINTHTLLVtq0uQDWyfEbxCu2UWXZ3/m6j65pMDSDsxxGJP+0ioZgRKtHnvhvcjYfVUA/ntrg1xcKnFr53v65siq4inJf18RLXMT+3RY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 513fc9d8-eca6-4a50-cd8e-08d9f1ea00bc X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:18.7900 (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: 79YMAA3VmRi9nfVAHL4yS58RbyxiA/vnM58MedETEbaOhAaTxAaDts5HxB3oD9RNcEOCr6OqZo2PPc/bpqtuRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: 6QSB064lWpHxyhj5UUSy97r-pVnR07jz X-Proofpoint-GUID: 6QSB064lWpHxyhj5UUSy97r-pVnR07jz Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add blocker to prevent hot-unplug of devices Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/qdev-core.h | 35 +++++++++++++++++++++++++++++++++++ softmmu/qdev-monitor.c | 26 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..4b1d77f44a 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -193,6 +193,7 @@ struct DeviceState { int instance_id_alias; int alias_required_for_version; ResettableState reset; + GSList *unplug_blockers; }; struct DeviceListener { @@ -419,6 +420,40 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/** + * Device Unplug blocker: prevents a device from being unplugged. It could + * be used to indicate that another object depends on the device. + * + * qdev_add_unplug_blocker: Adds an unplug blocker to a device + * + * @dev: Device to be blocked from unplug + * @reason: Reason for blocking + * + */ +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason); + +/** + * qdev_del_unplug_blocker: Removes an unplug blocker from a device + * + * @dev: Device to be unblocked + * @reason: Pointer to the Error used with qdev_add_unplug_blocker. + * Used as a handle to lookup the blocker for deletion. + * + */ +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason); + +/** + * qdev_unplug_blocked: Confirms if a device is blocked from unplug + * + * @dev: Device to be tested + * @reason: Returns one of the reasons why the device is blocked, + * if any + * + * Returns: true if device is blocked from unplug, false otherwise + * + */ +bool qdev_unplug_blocked(DeviceState *dev, Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 01f3834db5..69d9cf3f25 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -945,10 +945,36 @@ void qmp_device_del(const char *id, Error **errp) return; } + if (qdev_unplug_blocked(dev, errp)) { + return; + } + qdev_unplug(dev, errp); } } +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason); +} + +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason); +} + +bool qdev_unplug_blocked(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + + if (dev->unplug_blockers) { + error_propagate(errp, error_copy(dev->unplug_blockers->data)); + return true; + } + + return false; +} + void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; From patchwork Thu Feb 17 07:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749516 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 B9580C433F5 for ; Thu, 17 Feb 2022 07:56:16 +0000 (UTC) Received: from localhost ([::1]:37092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbeB-0002Yz-5x for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 02:56:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXd-0003kQ-Vq for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:30 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:62318) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXb-0004R3-HG for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:29 -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 21H5fnhJ009160; Thu, 17 Feb 2022 07:49:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=vhEYFFYX+TrtcRrGWsY3oodb0J1nU/gv+MKcvz6xNgs=; b=NERy1FTl28boyWNwjxOzvxbTZ2L378eptVi73LfcMr5CsPhWpfedIFpWhyqaC3ZdNxCg vXbE629T+3GYjkXQ0ppOx4e/UxqcGwQE3PdHFplqZeL4+ql9eOx3FpfPuswnSl42Z9Mt 18/za70h/VpJZ/aRIYv6mohdxMliSW5l2uHnJ3wDIimzzUQCg8ZB3/OUgon8PgJh1AEi zyaIb9D9zpnnBtSjasz6fhtZ5shtTmCPrc5wpHhlFKU20GJRuN0qE3/dAHi23AVDtAjX 5DCOCc7eq4TVZqZfhQdjZQvINLqsqgbkT4Mf/x2h0xIqktABsxlSDkLOBYgxPmQ243Bg uQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nb3mhqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:24 +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 21H7gUYC135610; Thu, 17 Feb 2022 07:49:22 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2105.outbound.protection.outlook.com [104.47.55.105]) by userp3020.oracle.com with ESMTP id 3e8n4vjdvt-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VZyabwPcUBOGb6U2m7pct+f1xzB8amSQyXrNa0RNBzcG4oW7ZAMizBrJI/rEnNnVkXHBx0SQZqpybzKK2W8aPt35TWJ1ROhIFWi/wgNR7JEz7g/vQTjn2TG98gWVQjv83XJ6jH4yhwjWulUqYQWG74c6hHp4TEa4k+9kOxuoOnzkBivvyCpOecL66yNC0j9GvnxX0mOA6YnwS7FOhhX0jj8U53phmjZ36eXffZRVRDE+mtWPtBx59HysiX3OY7Zf0A7ZcrfkFpzJxFolDt3kxrvkDHpsHDNrqM94asED8FEwafth+tHdoUO/eueTieU4AqGBsJFlecFPYLS9rY1qxg== 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=vhEYFFYX+TrtcRrGWsY3oodb0J1nU/gv+MKcvz6xNgs=; b=e7oKYoE07HWXDVzw04i1rAo0mJ7MSHRhYrBai3R3HZDaUwcwHaeKUFgOyWE32J7D4S4l1k7X3TtoS4vLFTIhGch8+nWfYPKycOkVYGlMfyH6FTmCGrWTOUXCvvwSVWuQfGMF6cQ/L9JkC4Jjxyc4/E4SIjFKMEDSDiLaO96eG0yan2/kfUWEJNbY+wKckyBI9hMmJC4m+nngUUPMGHdzss40AzmgghAJ7u8HSlIjv8GZpv8PGa/kGNVxmNdkKzIa7odS9cd/V06BIEcAd6s/MHIDdXl613fDjuBbDjRg0BDYjTkhpKoghdkGbsZLyp7OIzmQoPPttjbKIfA0lEscgA== 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=vhEYFFYX+TrtcRrGWsY3oodb0J1nU/gv+MKcvz6xNgs=; b=EMEojuLdJjkDCEQvZ7hg7nDmHoplrzKtv1/e7XAaenac4YWjVldHBcv8RAuzRUNhItjtMD4scPBGoN0+HbEm2GrY53Bz1MtgZ+4mLQyK9Yi14vOaaDWMCrhiOQZoYtFe/NAFIHAdzLiCn60FVfed/pO6wRD3klI1i66Xn4kqdJ4= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:21 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:21 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 04/19] remote/machine: add HotplugHandler for remote machine Date: Thu, 17 Feb 2022 02:48:51 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9f0db0ad-81e3-416f-7c64-08d9f1ea0216 X-MS-TrafficTypeDiagnostic: BL0PR10MB3009:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:85; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q336bCWNRx7fafMAGyYE0DLgtRk8+4AGTiKhddnCWUHMgiM/UQ59+2CoRGkUitCFYidBu5waUZ32KXB5EX7cr6MIMhl3SWpb5RHWVweu1F/YsmXvPkJxfip6ahfIWSzPXnJwwE0BWbsArH0V4yg6pXVX8mANscpDbnUB7H+2qpn4NTPc7iVtnlBfH8nirunT5J51hvsoeonwvG2gagVAhWReCnkU7GROgp9xhv4jxYt+eYMLwGPMEATeExBfEd5JteApx7V4xAlano19oWHrC6hvsOd3LdJIptf98hQQ8QAdmimZo1n4qiJ9BdcsjACL/FaG0dNUUSoSbZDFkyjnWHG/MKs83S6A+68u1bQNq/oCFCYR/xFItpRm9eCXTNHpuzGHxKOXafr/yoZjf6GmgSbR/+e95yI5QCUbwstH3MaktLmwoxiktVTMTbpA7XDc38GFwuR1Zh92CjHyUVlDiaLpHuIuvsH19Hpp+Q0SqDBX3rseHEVSDj/yW2ABXRyzSKPh9cBK2Sl23O91YcMp+qv0RMCh2lse1H6U6XNL8CnApzm/xJWeDrV25vwJs5M9USrd03/04Yy+pDI46H0yPNU1QFnFQzs7Geyfds8zYD9M/jicEa215NTl+8plzTHcgWrKn4IDTX6sX4vfzYAOjeiNe4VOel83lmfsvs3oCgOFPUQBi8PywAJdsXipQuObWVP3hKvSxCePb1k85KTBMQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tmWZLzo/ocwVJu5IxvTwmm0+qY8Lu48Shj/Nh0BzJh5dVRo3STmhotgRppOY8+NQhwnk+4RJkCPNU+uJNcHnUCkEtxP1S7bCl2IFxcxFMo/uG8Q24gKw7ctVWepAaLMuCcfNPkvsfWI0lYrWqonMO/g2KE92o0hjcPvxzQyjTIgivPYH6R75XmhdK+pE4Sl81bql6XwpAHEwsf0FoeLi31cDXKbf77Lubnni30V25Tr5pNzMTuUw9cGnlkMI25YJRoj5lZHojoGXDnHCSlO2aFr9FxW84Qp7KyC2uT7To8IynYK0BT/F+/NXa1Y6xTaOIjHmtHAr7vb1dXXyk79bj0SfAKliOCxd+wzNo7Bn5P0cDxZMHckKvf/wSPs3F+hyDWNnyqwwSwp06lD7hgk9dJuT8OO+GeDB6b8XuXiAId6LfMcYSnS1DcjbzgkwCYTaeGGj8bSY6xCh7/fgXDe8pbxuW0M5YsUO+WkDn4xJ2QoCYrh2MtQBePPg3fuDScI6el18PqL8QNb12OL357lnHQG7IVASnRA4p17pyPle4d87kOjSfUBdLgOB6niaUpB8U1Z4Lhjy7Fy8q/q56J6Copmr03hmSPDupj2MksmafczgtNi3qwq8LCjAuHyyniGaaJUyy/VW+n08z53A9xDUg+b8cQbEEMjXeKYl6vt/IuKAOZnCu4fZ9VnHMhIWv/xT4FHnR9ndU6K1Es2aPy7ChBWObKzZCY8AR7ZqD72Y9jlEt9myY069qx8wL1g4+kFwnXSLEoSTM4MH/iZOxr9wAnRXFX84qo1D84W2yMAm02bg6mfuxK1mnk5z+ip05t1tpFfNE6HYFweXjQxYdPsQXAQf32INtWlLV6TiGdimhOt/CnxhD7MkLA17hZd36MQXEvMFX/DYISTT9ArdF2mSzJdQrQzLhUR3bI873eZBeYtsGswkdZImoao8WFwf7gMD4tr6KTk5KHuQDh0OA+D+4eX5PToVmgxxJpiPX2Zetr4BP5q3zbW4fNWxtL4Z6iz+duhNU9H0ZXaCdmLhcA97LaGGAc6F4B+Eveu8cszh7yVUazEKBW+b5GwVDkTWaL04Ea0h/kphxyJh5DfBezwKjiIwnBszNHl21t1Zhd1+9uZw8QDYtOKNiFEARuR0HQylFPXBdrvntY48e0C3Entls6soYv+evGqmDD3sUzoDjQU6AJ2ZkAPYubR8UpLahszNgFjY2Bfv+TVxnbXujGyyZEOg7uwxpiksBMypxjDJvBrrx7/cKSHur3RrmkLeLAN0mhnYRrPGIZB35J82C41V0I/1JmCe27+dwGAZOvtxqd/y6B+W+OYTB2AADMcp0D0Zc9EA2XZumv1lZaUE+D1HjDexVs812jaxVkSMxbu8SlPThud7xvaV6e+TVQ94Hgn8TIfi2k7VRpRrU+heeDTRMbUMB57xj5Vj4AH93nVYuN/rbf8resnUgEYmlspiiX5NmoLiGgOjkMq1cZr1z9DLu4Mdr12ruxFDcbw+hZjbpwZBm4BGxTg/oD8Gj9NjOIoksXCn6CRjaA/M4LEIUW2vJ0HPUR/NbNE1rVemv3YcyWlr8nmHrZvzyVMAMOjebTkBnI8nEZ28DYOIMGubD7hCqOFww11bXom7t47GXWESHzg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f0db0ad-81e3-416f-7c64-08d9f1ea0216 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:21.0398 (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: W+FbL8Hsw4DKaOZjHgsIv/q9763zP2+JHC62F7LPQKlkf0sjzESD4V24+JN3wi64shsQizfp0h650axdGDn5EQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: zIlHBWOE7NRWteqlzaw2eIbKx-m8lPT2 X-Proofpoint-ORIG-GUID: zIlHBWOE7NRWteqlzaw2eIbKx-m8lPT2 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow hotplugging of PCI(e) devices to remote machine Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 952105eab5..0c5bd4f923 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -21,6 +21,7 @@ #include "qapi/error.h" #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +#include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) { @@ -54,14 +55,19 @@ static void remote_machine_init(MachineState *machine) pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, &s->iohub, REMOTE_IOHUB_NB_PIRQS); + + qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + + hc->unplug = qdev_simple_device_unplug_cb; } static const TypeInfo remote_machine = { @@ -69,6 +75,10 @@ static const TypeInfo remote_machine = { .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), .class_init = remote_machine_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } }; static void remote_machine_register_types(void) From patchwork Thu Feb 17 07:48: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: 12749537 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 0B6C2C433EF for ; Thu, 17 Feb 2022 08:00:40 +0000 (UTC) Received: from localhost ([::1]:44062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbiP-0007MW-Ad for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:00:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXf-0003lD-M9 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:33 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:63820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXd-0004RA-5P for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:31 -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 21H4RVGv010846; Thu, 17 Feb 2022 07:49:27 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=saOEryQDDyAtM27236xvu2pZ3ZdpadOAdYj7R2frOt8=; b=cPKaFXgA0G0CCooXx3yX15Tl6HnzfQ7ZK7V6ATRjxImgNr22C0247v/mCnxIaQqIQQJZ surSPPgvXhFE3h5Y0vOTQi+4E+eHQp3FILLMosocFeAGKUB3qneG2jt7dFG1Xp9ni6xJ jIJpAYjqNJX798B0y7kjG5jWcbXD/5XcerRKdh0NZJh/IFpsuwI7UjOJJkR4F9vzVbA6 b04uc33RL0Te0WWn9BC0bMf+TpUDdo5LaFe+klldIWE3baGf5veZvXhx/Bk4fRESgau/ 68L9beCwCMZHtC4xGCXl0d0pQd2UucSosZEj3q7khOjIsTLOmzLlSDfw0i1pIMU9xmPK BA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt2g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:27 +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 21H7gDg1030269; Thu, 17 Feb 2022 07:49:25 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by aserp3020.oracle.com with ESMTP id 3e8nvtf68q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvBg8m93DiaRF/fdMHEpIi+Z5XHci50qTNlWyipQ5VQ3jUl13PnpPVlA4sTRk41kwi9XvooBFcbP+4PYSo1IlvBrqSaCHlUWYLzpy2u37DNHrlMcNLZatef8Xz+md5aHt1n5dHIJMp7fxxSsrg3A3OrIGgBu3ZPmQ+41DhwccSYRqpfaYQt2fN6hqteV/D4QWWwR7BdHwVaTJTIY4NaML0Q9oRQr9AD3q97njj/roGlhftZOWz+p801Mnki93SzYOvGJdBTJngOecnzMevlxID8NkWC25TyghqMIuIm84oIr9yiYgG7p4CFv9H3/mtUkEW2QxyrC5ukoHla4aNoTcg== 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=saOEryQDDyAtM27236xvu2pZ3ZdpadOAdYj7R2frOt8=; b=kakdT6AXELSHhnMosnLFUVbfw5KqmpTtT8yfWs9pIfY8qcshmRPU3c5Z3B2R80lYx4oSjJqPXzsEYErcDtKbHuDIl2F7sIGxWOc5QzmDQSztRVbBZfzSKa+KoVMsz4RpXw+LajRm0C84FOsBR2+YhC5g7fXCzLy3llkOVGUNIl6lr+9HuS1HlpB4TTEEztb2dpdCTDBVS9ZODrb/MUjV2S42JFR30SxMA5czISyb5pFOgiOt7AYKeXXWIQmV98kOaly3oSLsSYqOp1SAF5kWxruZzLoWGXQTXhgM5s0Olo3WTLETjCADQXh3FeN8jr6X2jS4zKTu4R2oszmkjI6oGQ== 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=saOEryQDDyAtM27236xvu2pZ3ZdpadOAdYj7R2frOt8=; b=iDggFWbwiw2d5ZS9te/T26cg+lDuWypdX8uXmPHnUZR8S6RB1FbnzWTU3IcOdZFILF248bGOhAaQp9nEFfFL0kY81DkZoblLqG/V2ag+U6K9FE7QeTkDL0sfosYfVfSGFWvLBDyJgboXYYUM6TVmYhKNXPlFc0oAHzT0Ql2si78= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:23 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:23 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 05/19] remote/machine: add vfio-user property Date: Thu, 17 Feb 2022 02:48:52 -0500 Message-Id: <4f063dddc17a2ac1f8c9088641df455957a3f78d.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6856cc03-6beb-4f28-b66c-08d9f1ea035a X-MS-TrafficTypeDiagnostic: BL0PR10MB3009: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: sMd30+8T1+8a+KcvKQDzF0BHuSppb41JayhYCjmYlk1GIM+cP+ruLBLqxHC4z458xw/lYOYeCOw0xW4jdN2yjlLvgiTezfp9E5wMNoaD1rHbrnpHL84FEScs5kesU6veb/81ZWTzhIG0WsS3wjlajCtRRDgM8Rc4BOP8Yh9Jx/dg2JSj8EHmVWdblQ90bn64vlzP5qKur9kq64Gs6kIRHrOdn4GawsX5Ri6Tfcx+cxEnusbR5vjhhMoN4jdE2Cy85ukLCxdckNnAFhIowOCj9VXkq58tAAdK9UTu3R0fh5sZJpbKd29s1EVq0YmJm4OWs0zSs/63MOYjrQpDr+tR/mM9bAtqxITFsMcfujV7tP0LAa3HgXvgTNIxHe2GUkFL/jmfpvbFlJQ37GQ6j65MCIHynBsUIDUvCs+eXXESlPYBvg0trdBvaMO6a3kKVo75ntLX64+xEEnMPXcNGHx3bS3vmqlHaFpn4sFapqSQd280wEjUuHAOOE2N5en7QZe0ojBFllvDyD5RhSdJgsXdDxNm3Ngw3COZo/ex0szKvOaXI/nEPNs/V0hGllvuWmaCk8ey65+yrT9ZMWCN8NNGm31YcfcN5HGcq4BDNWDvt+u2fSHIMYygaT0mrK5i34LgnmATrBqwp/KJue9vFyyW2g5rxuVHkU2UZL6NT840Eh81GNARyf1Py6+pbCQ2BXMElDpYkw8NFY5o0eUFoVAAVw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0NxKnuxZVMiVsYQmMo8zZtB30jELkaLFT6KN0qhWXPwWqm9M1pQ4grKxPbFDyTM+xgR7qB/8vVpG7Azb36DhwbN5W2ZlpsQRexX3cUgqTIUxV5cMpq1mHU73WgQEZof2nid2T3I3XD8YZWy/Xr0DHqDAA3RHGiZUqGFZOo53z0M3SOAcibWDkcI5EcAGrzRprqBYG/jrjv4mQx7FOc2e+OTXA19msqWWf+h8FJuiVt6TD4WdHjoU0nVN2SWizjVEHMsU5MXYx1cCA2f4Pt2d4oxBVXh1tECaZgnYbuNdQshOYy3blvujjDZSgOxDeM1Lqy5GGlLAzw3zdB5ZRluoCpxR/PYgXrH3Ee0t+dXBquK2b7lOAcNHuy2lgY9IIUBnNInKJLOZp4140YpMEnzV0N8ak+yalDs9XsRwGnHQ6w2vUZGUxqJP/To+TW37rcmt55aoFdSSuVU0rbmntSV5u1fyW0Mol2jZwhyaoqvn0AuCbbXnZeCuK1TaLnnSmVRTGSk9LKJJdI6zbEmUDImdZIDhnaPh0h448Lnn8GjzVvxxxBPM53reZMWxFQ+mOclSzyNHNGs9zI+DWZ8pMLVuWA8vHR0i3h+CWTExv8Os2OKVCzY1DTptANXDZxBk/2uZ3+QA7wFsb1Yk2qWJ6iZwJXvOrBMv+iAV5OP9sooPwy7LvpL8iBs2h8dVTqHw8MIPgR2ueOuQ8d+iKrQJcKlHqx60TNnLPyUYohLu+ZFKKfxFt1xTpdxdf/485X447I+cApI1bxEkKYjFHR3ZI3Yw7kdjVothcgyaJ8CP91/cjgYezkh/jCjixvFYPyVhN+AyonRPOwnoQmkLeE4ceUAYjkVXvQVrS2UIfP9QO/drMNzZM0Zo4zd+mhK9AUs1PbCZUk9u2LzQicMnpOOfwx11FGN9TM9lW6vR3yOEQxxRIsXeauRZpvy2gdeLPzf5WdijonqfuYYbarMVTRMwTBBVnh5dOXBCn6r7rDN0KfKAGkOEn1AM6M0pSvKm4qFD1/JZgvPWF+ZQ/+8q0lfTZ9ryPZIW0SQ7PNVW0TGD3UG/E0QuzwlRPTZW36RiEMh6xiqrRkZR/xtcEglLZ7KOw0fZcCAHdmbtKsj+KXxJ28+NrdfHeRvi87vi3Zc868LeJor1uizh+BZApkk8nmCiAuPuOJ+lrt2Nox+xzEUu2Y3yBOWyrUrGw5Ahfy4JNVJd/GeidbH+Z4mPkVsveXHI2FttR+uXepG/zcBBpn34bcWCgiLSeKhV2SNxeJl5l/oMNFb5SpIUEJzuKOILWVjcYaDU9bm05htgE/qF3bsqKRV29QQR6qAK0LMeCCbHMzZOYWsWdBSqNt3sAz6DJOYeCNiDjwo1y2Tc+ipQN4MxTyWRV8yM6zWL8t6FTopNZRMjNy3METzq9luBCrgXWqAOfbY04WE3P75ENSv37SRZ1IGpFcJFuoMbfOmOc1WFOTroaWZbbTygR5+e9B2zoU3WBI8d4I22bW9KRRypC7tId+pWvxMgP3mCibwWdY2S5MUj66tvegidNN7pfmcZSSuWRcszo7M0P0sRr5ZtQOT+4aI1p/PYEVG+BWv3CET6rCyNckEto5/UeGLuyUaXQxncn4Mx/Z70YFCecJI4ezkVOK0BFTI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6856cc03-6beb-4f28-b66c-08d9f1ea035a X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:23.1803 (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: OQ2cmBF4aB4qY1c1oaTzK7K8PbtHsG4EkImK3z1u/erNmJeWaIQ5V67iitjHf6u8SdYIy1zW1HIZVzmIB0Jh1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: myDIJZ5hwzG7j70yD7AAxtRy1D5zT8Zw X-Proofpoint-GUID: myDIJZ5hwzG7j70yD7AAxtRy1D5zT8Zw Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add vfio-user to x-remote machine. It is a boolean, which indicates if the machine supports vfio-user protocol. The machine configures the bus differently vfio-user and multiprocess protocols, so this property informs it on how to configure the bus. This property should be short lived. Once vfio-user fully replaces multiprocess, this property could be removed. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/machine.h | 2 ++ hw/remote/machine.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index 2a2a33c4b2..8d0fa98d33 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -22,6 +22,8 @@ struct RemoteMachineState { RemotePCIHost *host; RemoteIOHubState iohub; + + bool vfio_user; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 0c5bd4f923..a9a75e170f 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -59,6 +59,25 @@ static void remote_machine_init(MachineState *machine) qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } +static bool remote_machine_get_vfio_user(Object *obj, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->vfio_user; +} + +static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + if (phase_check(PHASE_MACHINE_CREATED)) { + error_setg(errp, "Error enabling vfio-user - machine already created"); + return; + } + + s->vfio_user = value; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -68,6 +87,10 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->desc = "Experimental remote machine"; hc->unplug = qdev_simple_device_unplug_cb; + + object_class_property_add_bool(oc, "vfio-user", + remote_machine_get_vfio_user, + remote_machine_set_vfio_user); } static const TypeInfo remote_machine = { From patchwork Thu Feb 17 07:48: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: 12749568 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 7787FC433EF for ; Thu, 17 Feb 2022 08:19:41 +0000 (UTC) Received: from localhost ([::1]:32984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc0q-0002wn-6B for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:19:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXo-0003mx-1P for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:41 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:2552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXg-0004Re-2l for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:36 -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 21H4S7Z0005179; Thu, 17 Feb 2022 07:49:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=2BWrF50odGZYGfK4+kVbrwSRqiTtKmoGxp7R6Kq0DD0=; b=sJJyARIQqR6xm8iEgBVHzXLhHd+oewvWrfxGtJ0/UbsFM2YaTMnSpSX3P8LyOpxJMrxv QmJ0xJicDn+owBIUdxRUWHfN7xsgnykCTij4Ykv6KuxSEuNqAmcvWYNLlVFN5LlM+ofc DDN9CkJ5DH+uVe2Rew16UWPCx1+ZMAXGxtba8l6JW/sHptX4vXW/zGh1MMB6x61uTcL+ t9zV1KavkCalL53Hpf7wQm0RSJC7Ih+pIwSCn9+IKOCD1IDuVsdIUy0VHK/4P/RKhA22 AGfWIscKdNvkNjeXFlY29ChCnJJ/YYpx7DeqxQqghmpWdHH+I6Ch9O/ocDDUz8TSMS3p 3A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8ncavqx0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:29 +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 21H7gVhO135637; Thu, 17 Feb 2022 07:49:28 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2049.outbound.protection.outlook.com [104.47.73.49]) by userp3020.oracle.com with ESMTP id 3e8n4vjdxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aLSJzVa1Uxo/+Vtns6szN+VJZk/BsvNj6JaD3BuW275SsUsD6RyWiGwEHfOKKmOGv3W4xsOEC9EmdrNWlZezwkesINIreCmxVNnCchAY4rnU3zfpHMjusnanYsK33YMAYvksN6KV3ShVT4QWnPMTgS3ibLNX/CvfG+HZXYBndoKJAyExltkoL7GD9qkESv1kVcGPb1A5lykljzBP6TlfmQsxbLV6GNLsAVJxmiOEKyzWuqSQFb0wylabBsN3IH8C2vvRvOV05Tr2tdFhqildma/J/J0UijSER9giUB07AnN9D/qzQns6abWxJbXv9WTvdKbhzLGuN/5SLWqzdbqa7g== 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=2BWrF50odGZYGfK4+kVbrwSRqiTtKmoGxp7R6Kq0DD0=; b=NeN3zz1l+DyO+SoXNrQzzyv4S2LJ8R/khvLMfUqBtgtvqTZ+T7KPXaT72ecYrSSkMZUpZLd221KAssQlJhi8dEbyUegwP4yzcl5SbNrcmbMzlq/BLBbmR2bG7RXNYcHPK60uHKCt5PKtY9EG3NKRsPH0moLLJsITq3Jiv0vdobLJpq7osXKwjBXCy7LJyu6+GjedTJWdu5WJp84KPmxBT5cdpSqrJx/ra6kgoedxxqqerCSU9/fLZlVE+HwtMgvuEaXcsjCGkEm7k58vDxS94obYLldaihD+rm1xc/6nXPY3hdAwlozo7RPV24M5kORC4VFFzGuWG7BqMy1ByCPZmw== 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=2BWrF50odGZYGfK4+kVbrwSRqiTtKmoGxp7R6Kq0DD0=; b=ZNcfhdSfnAplIsTFZS3/8vmn8Zh+yXcjyQd4RfvfL1SKD97s/37o+p776mAlDM+4WAk6LVv6T/ayHJ0t/22aWDzQ6c1E8nYFffPsuiPXexZUFnrR5SeGaUXYz7mF3/Bmu29FJTAg3Os6OR/dL5/C92mcYIZX+oxTQ7URmw2Qus8= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by BL0PR10MB3009.namprd10.prod.outlook.com (2603:10b6:208:75::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Thu, 17 Feb 2022 07:49:25 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:25 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 06/19] vfio-user: build library Date: Thu, 17 Feb 2022 02:48:53 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94c3a5b1-7d95-41a5-52e8-08d9f1ea04a1 X-MS-TrafficTypeDiagnostic: BL0PR10MB3009: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: uO7GQW9wVAYPsv2YR8ENWS+KfKsE8SGKFMXz6h1mBHar8kzvaoLkwE97qdSuI1+rC36kZUjxFAm+suqC5v6spaqtoUapXUZkNNjM5ClpKxNGPknyVBsdkjA/nguEizihlRmBVE07KjRZmY/f0Iwa/w+QYV1h9NSPgjj4brLqAl1tLhy3netduG/ua4lTnxn5eODfDn1kkWXB6Lie+cEAlc2lhWC3Ov9nv8lGzlWyBaznaZVhNQvLmHnL7748ONZ3Z9ko6p6oSIKX3oSfD/pq1dryZ4mk7rj0GwwmF5sYVD6AVM52DuhfX2UToundEvOjQ527aIVbcDZ3IdboR9CYAfc+76DjkxiFB2Uc1fDJTwWkuuQl0vXEYyZSZg0X5XvP/EGLAiyfYoYe9VSx9wpG6md14nP/B7/SbFkMMDkSnkSrHgOiERI9HEAsyW5u3mUf4X2C38XM7Ir/MUONX7w7EcDWpQSDzc8fJVzMAyvuX69chrSeEWIUoQR1SAabAFcS+L22/ZZZ12tyDRNyHYaXaF7y7EiGVcoSQANxMBf9W7GeBxJNeTw1fq/MOPscvi2kg+nxpBLv2ML4bQsGIw0pBQ+QVsN7A1Nb7T4z5JONkmLO4hw3wF+m9DEs1FxcQ9ahty70obDRIMmhaxffG88JW/VOES2LludiAPcAUOwDS1fZzjNov7I/4KTe8pQ+3Fvj19jESF80AGRs3oQhICsh54krocsIRFy9t3VEUFrGRDYqN3hAksyehJZAr/XOv1XcTejfk+9VvHttfNS0ELwES+PQ0NAyi92Sm7bqHzNgWPLspLgad3dwXrK1gH1MjxX+AU1XreTm2yjRl4R41lX2OGbO9OM9cG7rOfn+t95o/MU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(6666004)(66946007)(30864003)(6916009)(66476007)(4326008)(38350700002)(316002)(36756003)(38100700002)(2616005)(6486002)(508600001)(966005)(66556008)(6506007)(8676002)(107886003)(26005)(2906002)(83380400001)(5660300002)(86362001)(7416002)(8936002)(6512007)(186003)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SkXkCYVFKb4aJbWLmgfmZAKnYjqsHfIlCr+/I5OVXlwXixshe/VpcgsdDrVLqnO4OOYYrjjouq34JgPCh6EhEgGQ8ZkNTVLMpws3xl4DXHUfR61TUFi8p4Vh81beLmF1NrVs9E0ZLaa1bPuDNFt5Cov3zZsTRdtkgm1JvJ4VCqK5iaLbULd7KmbDj/5t5kBoG+i6uwR4hf9l771WrOZZqamJQOxehVz9WH83xbA/AZ0f5qgqHolpCSDXfb5WBX+jFwokJX6GXfO5SJfX4eXPv0pjxhUCBmjRPwHmGP708KJAnXTWXjBqTLldOJx0Z4dmo7keWgoDHTDW474AKhhF/iD5RIgOVZpj7xzzinT0rEDfvW3oY5anukWjwBSuQwwZlfyIRGu3wM35YKyUo4e0faHKTqhrHh5KTCJb5+pzydzQfg/9PzSCACaM832VWb5y54DP4ZElXmj6ZhqXb9MFWv1ANIfMU+Uz9jefyc1tgRxJDPcqtM3AqBCIH4ajbIyfcbMg7hyVx52Dn1VmU9i5HMJNvN/hQHMfgKfaK5Wse0IHBIIxwhDSKiA4dXyDBk0E296xZStHC0pre6nPv3P9NRCCXaU5ULEpc/39oZNuOrgvfTE2OMAJfPF02L6eopdJdfxUwiyQg8UZKjBHOsZp2Nn+LCNicn4FfUw7csx8QmbyibbsGgIV3DchBAFMRmwoFlIUhN7eveuBi1SLvOIKqRoDuYesc+jgU4PBV7hMw91wvUqf9G+IhCw982xzQ/648w2HZQb2P6wXxvnDDB8/G1okOJR7o8F6bi31lGPcTeGOP9cOIv26P0QnKsN2vLJ8V6ClO6sG1rlbW6jEXfEUM57Ug0gtpbKwa+u4Tz9hSrNpin5WHRRs/VATKFjZf9/PKucZJmOg1ewKExZV2XPkEABSmzTXUkoLkGyOMXadLAmrflSncin5fomIQhKtPQLZdqdBeieuvCXsxjhVFoQwRvMmw9BwpMuttZvyt/8ple+82UK40Uhw+dYE8KR0bHLoIFR/gn3G/0Q2z3HsznT/ZuM71+yjwM0Ro36IWL7w5RPHJAcir3iM+i7RSE6dVTckJ6n/NPktgHWdN2//gpbeSw9DefGi0VWXJWSAUlfHlH8ebGr/gF9PYvNAOpr0ChCY4IsYupGsFdMF+1nz5piMTX0FfOwF3Ahoyr4FxiXboitQCSzvOiQ9EmC9uOiw7KVLSdeDAbzlgiLHDxT616ZaQP3tcvWBvNGmGvOYxwa1qSbPWkBRM8Pk3zwix8mk6GwFCCVf+wL6NFmEQq07HMim3QzEeZLItfM5fgtFFVz0svxF+210Nj0pDQA3uq9F2V6IpWal9hHKmCqYgNtteAgYIuOY6eBQfdV5gDB6j5gsehglqOiSW4WOpwYoojlfdhX+oL3ZWFuPHbpTsT1HK6N5Ynzb3FrSmLosmRKcZmXoewpeWbfBrupdG+U9ahMAkUSpH75QbV13Gsoxb5lZZvoPUdlQVV+Oq9RK/MgqeAihnKHH0oy+N1Iku0ZIja1yOEvpoN3By4DXX/qZrV6C5Kmk5cCAvcUuIkkcm3IeS115H2ITEfUk029i+ylMBOnailQKBIOUv5ME1F99+4GuViVnq8hMqFo+ymtexIzQxCv5z8o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94c3a5b1-7d95-41a5-52e8-08d9f1ea04a1 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:25.3208 (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: Lopi0gxxx7fYEkCOAzizPLCKWAY5Uz+GTQf0gN+1qSQEwCIhWTk+KLPw0Ut+038BXA5Irw924/GNPfuW0ZTxdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB3009 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: 8_gaL5-zNHOosWSN3S39TucLqxmyAmxh X-Proofpoint-GUID: 8_gaL5-zNHOosWSN3S39TucLqxmyAmxh Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 9a326eda1e..2acb2604c2 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 @@ -1425,6 +1430,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 @@ -3100,6 +3106,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 @@ -3790,7 +3807,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 ae5f7eec6e..5111b6fed8 100644 --- a/meson.build +++ b/meson.build @@ -278,6 +278,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') @@ -1876,7 +1881,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' ] @@ -2265,6 +2271,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 @@ -3366,6 +3407,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 0aa70213fb..e52391ec5c 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -42,6 +42,7 @@ build-system-ubuntu: variables: IMAGE: ubuntu2004 CONFIGURE_ARGS: --enable-docs --enable-fdt=system --enable-slirp=system + --enable-vfio-user-server TARGETS: aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build @@ -165,6 +166,7 @@ build-system-centos: IMAGE: centos8 CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system --enable-modules --enable-trace-backends=dtrace --enable-docs + --enable-vfio-user-server TARGETS: ppc64-softmmu or1k-softmmu s390x-softmmu x86_64-softmmu rx-softmmu sh4-softmmu nios2-softmmu MAKE_CHECK_ARGS: check-build diff --git a/.gitmodules b/.gitmodules index f4b6a9b401..d66af96dc9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -67,3 +67,6 @@ [submodule "tests/lcitool/libvirt-ci"] path = tests/lcitool/libvirt-ci url = https://gitlab.com/libvirt/libvirt-ci.git +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/Kconfig.host b/Kconfig.host index 60b9c07b5e..f2da8bcf8a 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -45,3 +45,7 @@ config MULTIPROCESS_ALLOWED config FUZZ bool select SPARSE_MEM + +config VFIO_USER_SERVER_ALLOWED + bool + imply VFIO_USER_SERVER diff --git a/MAINTAINERS b/MAINTAINERS index 81aa31b5e1..9af3e96d63 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3567,6 +3567,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 95d527f773..0713ef508c 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 3ede55d09b..b6b4aa9626 100644 --- a/tests/docker/dockerfiles/centos8.docker +++ b/tests/docker/dockerfiles/centos8.docker @@ -23,6 +23,7 @@ RUN dnf update -y && \ capstone-devel \ ccache \ clang \ + cmake \ ctags \ cyrus-sasl-devel \ daxctl-devel \ @@ -45,6 +46,7 @@ RUN dnf update -y && \ gtk3-devel \ hostname \ jemalloc-devel \ + json-c-devel \ libaio-devel \ libasan \ libattr-devel \ diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dockerfiles/ubuntu2004.docker index 87513125b8..22468d01e7 100644 --- a/tests/docker/dockerfiles/ubuntu2004.docker +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -18,6 +18,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ ca-certificates \ ccache \ clang \ + cmake \ dbus \ debianutils \ diffutils \ @@ -58,6 +59,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libiscsi-dev \ libjemalloc-dev \ libjpeg-turbo8-dev \ + libjson-c-dev \ liblttng-ust-dev \ liblzo2-dev \ libncursesw5-dev \ From patchwork Thu Feb 17 07:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749573 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 36F34C433F5 for ; Thu, 17 Feb 2022 08:26:03 +0000 (UTC) Received: from localhost ([::1]:41762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc70-0000kd-6d for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:26:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXq-0003nR-3s for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:43 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:5652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXj-0004Rw-AJ for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:39 -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 21H5U2GN009058; Thu, 17 Feb 2022 07:49:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=iST3K82NIeqW+bG3KB6k4nm6u1olMU0vXCsFdF5rD94=; b=lHlc8y+anRaUcKNImHo61vlLGSTyOvn+5yI9EMaaLzZ8Kj5B+KNdWc4l+ch3Axq/U03k 8DSA8cgF0wOQOedHr3QkwvBfYPGF+55U3oR0uEd+4sFVCz9ESWLxG+/QmincWTDnERMy cRw9EqSXWCilp+eGS9Xn/h5MyYDlr9ng3ijJ85Ljg+fDXDiqxMXDj2IBnuUZVWaTg5ZU FRdjAWcGp7HpUnWCiIxunVyEbLTSJD9tjqZZzolQMI/0UCKGPeoBZmiSQoRAQME8b3K9 viiitvt7rj3OXfOPI1zQ8UqeVIMpc/UhkFVwquCG7Gcve2IxsGiZLXqOVh5Gw3OuXJuE kA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nb3mhqx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:31 +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 21H7gaTG088434; Thu, 17 Feb 2022 07:49:30 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by aserp3030.oracle.com with ESMTP id 3e9brc0r8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mB+tVV/6cGnGlBzjEfkML69xfnpP7XDbUSib061r16yENLUUD70jhZdnOzyyjg/eHtVv7YscKSMxUB3YFli41ZX7bKOUiMXoBNfOr2FqOPFQmDjCclXlLg5Su7u0lXmv7DOO9LapLY9k8G+WRcgcDVG9I+uFvPIL5m4YLkcS9GylwLecvZnQQs2vaTto1z0NLEvmDaa2N0NGZC0tl0n/LfjqUogb9tDNzC+Rc6JNgxfQQg55oPL6vmcitWfwX21QUSna7OlU5s0MPfLM67M4tJAMzXdC79pO7nFi/I88VHKBKd21zS0P2ACTsBPq+mJG/HOHl1A639xEYEzfe1yIyw== 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=iST3K82NIeqW+bG3KB6k4nm6u1olMU0vXCsFdF5rD94=; b=XZHcDWS6X79Zp/JMQJTl9tMy242jkazaLV+POCBS3T5Cfx/IMD4mmrBmflcRpr9ltMgktumNcM9AgPjHClYadVKaauBNSt8nSoOJmLfS56O61uiTpBAsnr9eK9jJrMyY6WMENH/wQhiSAb7ZMfKmlCHhLbjqhkglEV53wpG9LT/PxjyhlYzJtWwa9WU6e2BTUJgeCDS1imKZC0dCzcwXXUKS74ey8uDH38UpsYVPAVG+1qrk0cGj44XDrQTBHUIshCCQBuwHN3AqTQbOOmAC4QCMbx+HvweeMpdnC/hjcLNo3b8SoP9696tcuhe5OwXdfx6WprqCKTlU1CJCvnbi5A== 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=iST3K82NIeqW+bG3KB6k4nm6u1olMU0vXCsFdF5rD94=; b=fjfKilRbkKdDfXXeqnwlReSy2fuFroSRRJj8Vrd8WFnUSx1DKCyhClUaNSoTBTNfAEZCeNz40WWSQ2hVsL+n83WWNVjHFeWTSa8kFprt9yuYssXFS647PlU0jaYjCf6bBTUNTCtk2BbC/9rm01etpRwSQ2BB0MIcTnbGLXO1te4= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:27 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 07/19] vfio-user: define vfio-user-server object Date: Thu, 17 Feb 2022 02:48:54 -0500 Message-Id: <309a6afc6f47d7e812a6f18ce591dff092efbb06.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e8ff7ce3-0192-4cfa-516c-08d9f1ea05ea X-MS-TrafficTypeDiagnostic: DM6PR10MB3211: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: U6u8rjsRRaHASkH5ETrXQ9vJ7PXNOCN+HP8vrz64aJ+bFyRT8Mi6ZHy0inlW8gvltXOolxjuxytrGvn2RfwqT+2w8to0Z0ExShXr5wRVp739rOr9Y2w0TLqG/FnDr3Tse3ICopc8ycfc1ldbHkTl5Ofdq2eOq3h0WpMjtthPvuwUAVTAW9jH8bvsLNN+5Sufww8t0osQziD4ZqqkZR5stAzQIDpvZ+bZr4l/8tWo9vORwmw49tt+7yEUL9P/hZkAI9j64oZUckYE8Fs4CueX1n5ZUI9KQXiZd5/nq+ByvIB+yyiGAEgrQcvZ5TpgnoDScI57vsE+K7fXiXoJIXonbOdBRsDfwNKkqvp/i9VK2YGU3TogBoj34rCliLunUnQiSmRM4Xoh9s6rtv6EJvEYuEfYxK0tx/6ZZpLGRK+uZ7/vtFqEbDoDVO/v1iygxCdpCB+FnL44bPyuswX34eXv0FO5C185PDNXp0SvoYyjN/pOBd0UXAP8DCUrozUdcVycwrAtSsB9kav4KvK8fLqQ7eJJksIcNQXdVWNfi2J1Dt6ajQSLL8rA/wSqERYiyeq/GjPGm3DHJCjkf/4t0kI5p8TQ1nov43Kgf4pcot+vOWiGbRjFYrlAhMDsnWppDuIJQsTJHI5XASS1e4HZiZv8kf6cFAR/UrazUC4kpjSSQdToWHQInT7mIeSXxh9/0N5EwAXyc1lqAc5yI7/ofiZ3EA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Yhupo/CtefEkD1OwopkSChxgrvNy?= =?utf-8?q?1V5M/T9qL7JeIifvnGToxzcb6/jqG83u5uBCa9ETGPwjogg4X2Uz4saPt7r/Oy97m?= =?utf-8?q?si38IJrMhBuJVqzuB2rjhCH0Cj+iB3AZunKbOBGLKJuz2Jgx+8ppxPICdr17EF7DR?= =?utf-8?q?Y1ajTEfHzPyE1q2/QolvxdNHcLVWvQbZ5X5YjeUapTuJx/kaz+7HhaU0isTjRtxUc?= =?utf-8?q?W1xIsR8uozy06UME+Xp9oqomj6XPm+T2uvQzargGn4+e0QY6gqoauldH+2yjWFU1n?= =?utf-8?q?cH0HoDr5TuMxzkb6TdC4AazYI5nMHijYJZgGD7XhPcEVEnrPqhb9v5XO6vgsMsWxw?= =?utf-8?q?+Qb2opoYosMz777btQxtHN1oHl+gdDPrc/PQR6aIFQ0yqfWcHsJCE0x9MyS4Am11S?= =?utf-8?q?73rfQOT281vssIKKSy/NmWB51i3T9SSmUvNCQR+9BQNIi0hdICLBmDmf3dsEHEore?= =?utf-8?q?yhXqxnsFfkIq/9htzbHa4UubZpI/lhvuZ5pun62UJb1tjXIvjI+c9FmJi525HYYN4?= =?utf-8?q?Sik0pqb2FIVgmWnTO89/Almic5LWGvGxoQNIKOQ5NbMSeTxU1SveNL1E80VDHc2y1?= =?utf-8?q?HK/G8pDuG6pE03SMKuqTWwWWc3eXVG2YqA8vA8rzmtImSxCS+JHdi25RnfHT/GVXW?= =?utf-8?q?MMSD2lQA7SC6lCFM3ybBkG/C3Ou04b92IbRNIXvrpHQJMoaxUA3/KZlPtHG44e2sa?= =?utf-8?q?rSZdeUXK6ctEgpx3cOOqbLl0iy0Qw6oMIDZhgquw/n2HmaRK7zh1amzhXXDdqHosU?= =?utf-8?q?QAHrz24Oz/rVo9MuBG/RvWPM++/XDqhwn/05GLHZ/WquxsvWgymJVS2ryjEBgJ/7j?= =?utf-8?q?8uplaajXIFHcDOvgTVb9Rp4ft9Yuz1NAp9skan4YGztSZPtVEa55+mSmgmnYI96LX?= =?utf-8?q?ZitRpwecP3aeafOBYOtJEuepH/hiH8T4ZgGVrHohKpd3XRVlQJPBudrHifC07izbW?= =?utf-8?q?/XZjxrFtzCqJZKW0mWide80hsRG+Zv7cDFvcYo6U2iQPkX9Q1tb1DyQ+YWSG7Up6g?= =?utf-8?q?Kd8QVfSPTyMvhUr4qbJVgkBzlErQfa49QR6D0gVqS0C8j5PxtcdVKonFsxNCwqylw?= =?utf-8?q?jYnFzWPdoazeLGeemy2iqpXTGT06DTr522G9ttT0eCqAOdxkZTqSXbTGHRPyU5yuc?= =?utf-8?q?v/60TZ6oX0xR5uahhXXVbFFo14WniNVbVumFBfVgIjTA8IBadTga7nUZa0yG/zUBZ?= =?utf-8?q?sr43O1T96nP3bRwMXX1Cae8LxdNo9bE2gxWiRyec3BDKzvhxgfCv/wnxKDCbg7L+T?= =?utf-8?q?XsGpWo4VRTAWcLV0po00bf4FWOoN7k7/mOtNZyCnyZUnGDUw+RfTeB2iHvg31dSiK?= =?utf-8?q?A9PnhMYGlNqkucB2cAIhsVb4nqJnFjVug3hOP+V1pIVp6KnLEsPWigfOteXJOp/m0?= =?utf-8?q?OYlBRRScHw2soVUGkPpRdbMI8SCB7PDyEONYwd6gR+AGeYua2h1IgN2+g/3kcxzcG?= =?utf-8?q?bJzhnV6sj6UAjjj88aO9ewkYtuXHVm16o1Foq/+BsHpqQdP/e1hNVZeb3Ytcd2asE?= =?utf-8?q?cM1iCK6LCAfFZPlcALJdGq1/XZtRnVl+zCS3fKbG7K3B5Ujit/D7u1I=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8ff7ce3-0192-4cfa-516c-08d9f1ea05ea X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:27.4769 (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: /fTKYkIB9a3qk1khgreVwDKN0w/CgENCw0X5G5mSdxjq0oXbIRcqDQDQ7ARO2UeL1oQoyAzLHAD6p8TxSaOR2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: VbvgAWl2MO6-Xc8HBmOeuCI9MMxqE0m_ X-Proofpoint-ORIG-GUID: VbvgAWl2MO6-Xc8HBmOeuCI9MMxqE0m_ Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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..84cd16c4ad --- /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,vfio-user=on + * -device ,id= + * -object x-vfio-user-server,id=,type=unix,path=, + * device= + * + * Note that x-vfio-user-server object must be used with x-remote machine only. + * This server could only support PCI devices for now. + * + * type - SocketAddress type - presently "unix" alone is supported. Required + * option + * + * path - named unix socket, it will be created by the server. It is + * a required option + * + * device - id of a device on the server, a required option. PCI devices + * alone are supported presently. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "sysemu/runstate.h" +#include "hw/boards.h" +#include "hw/remote/machine.h" +#include "qapi/error.h" +#include "qapi/qapi-visit-sockets.h" + +#define TYPE_VFU_OBJECT "x-vfio-user-server" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +/** + * VFU_OBJECT_ERROR - reports an error message. If auto_shutdown + * is set, it aborts the machine on error. Otherwise, it logs an + * error message without aborting. + */ +#define VFU_OBJECT_ERROR(o, fmt, ...) \ + { \ + 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) { + error_setg(errp, "vfu: Unsupported socket type - %s", + SocketAddressType_str(o->socket->type)); + qapi_free_SocketAddress(o->socket); + o->socket = NULL; + return; + } + + trace_vfu_prop("socket", o->socket->u.q_unix.path); +} + +static void vfu_object_set_device(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->device); + + o->device = g_strdup(str); + + trace_vfu_prop("device", str); +} + +static void vfu_object_init(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs++; + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_setg(&o->err, "vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + g_free(o->device); + + o->device = NULL; + + if (!k->nr_devs && 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 9af3e96d63..751d97852d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3568,6 +3568,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 Thu Feb 17 07:48: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: 12749562 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 0B300C433F5 for ; Thu, 17 Feb 2022 08:11:30 +0000 (UTC) Received: from localhost ([::1]:51740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbsv-0004aE-Ff for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:11:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXq-0003nP-3N for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:42 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:6230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXk-0004S0-3q for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:41 -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 21H5WxbF009086; Thu, 17 Feb 2022 07:49:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=MuKtwV7QfwaDxGzR3anOvz62SddgjVoSqiVi7p7VYbw=; b=r2z/IgGoQ0QAJ0JOWymVz2WtkqztKyqOIqmkPXnX1CTgH9bha5tKb9wfaiwHlshPFgbl 0MNLfZ5U3zCoTlwmdwmgEXtwiErPJZUEeSK6pyL6BF8a/3nt9sdPwaVoiTZcXToAUNdE XRPOlqg3lpvWJn97o6q09eJQK55kiJcVySvdxwlEFJL5xbs6FD9zRv3ay6G/uo7wdmsW j3iXeIL+liqejNDu7ainzp/PNDwU6z39VV9gC7eZNyK+cpnCq761EDjub5xe1lRbCbDg FrQ6n8zi78NHJifvuHKMma5TLYTppjU5lFK/pXZd1caGcQzCCwGuPUi0kQeEbvu6UbW/ eQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nb3mhr4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:33 +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 21H7gaTb088416; Thu, 17 Feb 2022 07:49:32 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by aserp3030.oracle.com with ESMTP id 3e9brc0r8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GBei6jqUVRJDT3RBteHQdYt7c+MyOWDwsEBJ6kb/hW3IQx69gmtQC4Ct910ieED6BWnDKIpqX+GQ12zcxJSVJnsGrPlLnhzYRGjStwtFpNgoPIqcAuqiYm/PrXYvv4VBPqhki8SNpV4GBia72mBuOP4wCbSbj1O1Ud2fOJm2SCjyrN9jtHy7zjo+kUZLqgYBXatHYuVKOj2PCd2QGpkcFm+hMqj3cJG6osMDyxO/a9xnd6juGm9Mf3PoWwFMQcchfuTYT3xVGFmzKDUKr9Xodtwviy2gh5IXtP5Ei5g4LZI+GxuCtzm7Xj0VpoX0EvvlmcgzxTec5jyXIXsDdCINGQ== 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=MuKtwV7QfwaDxGzR3anOvz62SddgjVoSqiVi7p7VYbw=; b=Vgi5IYV4YiYHKoMJovXodSgSqwIGkTH5/2nfHvwoMK/31g8MouswNXsGLuAgdi4Z9oXGJes4BVzeAV2u/qiO9I4Bv6XOMPVG6LjeN4p+e18T/E5QR0yHpNo/O6PrcMZ3FN90jyAxX9H5srFSwO08/7xiZWiFon6azvsLDgkcGddk3FpxG5BQn8BY0VuaJb9Qt6FX7GP4tw0LU9/LBX2FvPirG9D10za5PiBZAL1f0RqO3QieOxZDAn0uOzPpZE7zQCJ7UPlNe0BSjTsSQLrYuHg8vlFRq8jWBVx2+w6dEp91gGmCRPcapbyS1xBf3TC3VmEfNGfUL87ahMmYefmTLQ== 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=MuKtwV7QfwaDxGzR3anOvz62SddgjVoSqiVi7p7VYbw=; b=NO2cTHTfpX1vgGo/wrtETl7HVYHtcNT2Brg7gepAQkvegp6iHRSNFMWx7kKXSk+VpCdl+ueZQmZnyeMMBf1ziCCDZh9TutgDqzZ5U2ya4q2L/7zgYIPeEY+VPzMntWsq2s8r7PA4B9ZxLY3K6qsuUAUrnTEKnz1M7mkl+o2UmrE= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:29 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:29 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 08/19] vfio-user: instantiate vfio-user context Date: Thu, 17 Feb 2022 02:48:55 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df5250a6-1857-4452-8b78-08d9f1ea072e X-MS-TrafficTypeDiagnostic: DM6PR10MB3211: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: ErhQMZDf37zo98657vUqDxUFei4hxYDFA2cUQQJwhIPIW7itEA8PoL3E829mtVa7Bqe1EusRWiWsQuvAF/YAWv90W80vtn9lIxitw3VdKOS9xeNdVAY92eZuPdttrQznIY0g1jmAfho0snMK3Ix0enqhNmwXtUG5iGGan3t5HfIV0Ge8Fe/56ERBK28H2+5Y6s91iSKD1lmo24fpVu7TBB0IT6wNhpwTTeGO6SlfP3hqTGATkyz2NmWjU0hyRCN6lmqM03PWD6txeDVkuaSXEkSIauxDUj7lKQLQQC+pxs9eOJk9dHjxrGd+dtVTnoiRHiffBWZ509qmw/ERzQ2DpzQUHhsZ2JYgnjw5Rt1iT27Wd2/Kwgv2nSz0jna7xzd+jUcyMby0QIbw/3gx4SZXHi4Gj4ZrDyYrYK2q3czLbWGwCSpoO9pHPyV2t1Yzi5rQa0Vl+yvBV+Srr4eYafjlVafosird3w0rYergs+aiJC/OqaBSyoFQlTASeWFZyNA8UXPFNGErM1iVzWsrcB1BxxfHjoKylDGTClcGtoyFELbwWcgpw/LspKJY+ZzZGMMiGdarZyA5lyVI0FLBM3UF/eN/59AykBnajXrPDhBFQEEvJd6Dogor9RMbosGYQkDIo4SlMr+G5BGivSdmANDBN2KypD2F3A36ymXJS5J8ETfomycjRs0WinH99BpzEfUSAFlNMtrHy0pFOBSOneT98A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B+SigWyY1jCb4sxdSoc45kgOXUcnk2Yb6L0JaS+r/ZOK79qdij4/vYewakQ2SAzMV50oNW2qZ1/OK8bd+UskV0fdz3+PM1r79AUkOKDwAxpJNL4QKw40ln4ORb8bpImhD7EHXYOHbsQSoO0VVQHNB6PLlbTv0w/2yNgielW7M6u0Kp7fQsygyj95D4m5cRugMC/92aSZcJXTRZEuvfr//c3Y7hTp5KvtRWbzQ22p27k3esdib0Ur8v9dmu+5+R09eOCcYfUsGqFzUXrjRb8s/k1pVZ4JCy/6+HHb8ywkndgi9P2MShKEitwOmSxIbhSP6ytHzykmXcz3kaHsnRCy99pXma01yqn8C8LrzaL8TdIoLZlxlUjRqT34u6Lme5AO+HhfoLahsrHvcrDsbtB6rg7FuOgolTuD77Uh5/ONqU3cJrhD/NWVV7k7u209o1PuadUVcWTF7oo1mkwfZ97/xvClZMFv18Eu5v4bunfE9Dg52k2WhGkGrO46XeBj1jgBOYQYLD+f/z1ZuiET+GX7WZJLA70t6DXfsrR+jgLWiqKtL0PQtzBSrQUELoEFI68WZooY86x1+8tQ0gOzUWOVwbzpJhNgoOa9gDJRe0BzoAyAfQrmG+vY3sziZRPXqTnBpFFsiFwJQ0I4ExyoWQvsDWpg0ywAL/htJ5Ka9yJMqEWG3oqJ9KygBQeGsDzBf1MJNMZ5YuuNPlvoIYSzMild97womQ1d1cL67aLGwCua4YMr8nOzqY0SFKClTR2s/R8Sb/w1p3iEH9fzd/yoIsuA+Ho90W6sdgX3TTDlmthIKIX8huo42bbVMa+5fujKjuNpkiJkX/SjZmVmaTYElUbfoc5K+zYRvX7xeqbxJ1SQq3ukmWnxAKKM+yxB6f6e/wXkkLxT80Yh0bLXxR990Uw/Lg5QsdMElZa3TdehFnzESesq1pkrYIh29tvDNFmpCDuLnfPK8yk77dkrigNUKpolHhliz6szwD2Mv8LlJJlRO1jT4BJK5gxHu+ZHAm+SPm+x08sd7wjDQ4fzm/uGYNSEFyvTCYBSlbR+nyOm5Sg40WQM5vvSVvFlEpfYFbyitwko+jvezR4rUQgOH06lOZ81LgPvZIM9fiZmuwdlvvohy+1broj/2z3Bj7yoUrWpJHIeHvBdOmRFmgHmjLw7QeRp5Hgsa/TwUSSGH/12jw6Aue0MCbV6LvB1jIHL30fBp0xsA7AqC9RXWD/g0Gj5xJ4UTaTewAn9KiHEqakllArXFvs6slftU6BrIzZh86kI7Ku/sWE3uMgYTsmNtdpi9or7kkcXaLYjqtt4SVMPQ4YV7d/uPodCjr62iXMazZSzSe+Si9ASN2KxMZAOvgIQpmeAoK+mk9iy6JSwrwEA8Rj08cly2GaijZxTeqoUnL4Jhp0EPGa8H4goIE7MoXV3oxrpJ33sAkra+5A998PL5HJzRzvJmO+9AV1Qmk699y9LDSOb/f1z8p6ITaBZocBiUdx/Nhj/AjuVQk+9w+YenjW8f12u95QkdeN1qGDEzG/kAGtJrq0vYH/5ldlGThiYidMXvrtn4AzRSH19P5fMS8BZGI1DhKxTDvtrn1g2yTgQsMWHdjFnuTzPCYL+L84QcCAWthm/+Zbr4muf/xYwSUM803Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: df5250a6-1857-4452-8b78-08d9f1ea072e X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:29.5861 (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: Crp+ahbDTuHvhaojKL5h6Yhm37iqzz6iQGA/8MpUFftLerai7WcXSPVZ5/AGesWqBch2aBqycs78Sar9+sS2qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: CAHdcLMhoz96dBX7ktDdTDtsG2kjp4KQ X-Proofpoint-ORIG-GUID: CAHdcLMhoz96dBX7ktDdTDtsG2kjp4KQ Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 84cd16c4ad..496e6c8038 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,24 @@ 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) { + error_setg(errp, "vfu: Unable to set socket property - server busy"); + return; + } + qapi_free_SocketAddress(o->socket); o->socket = NULL; @@ -104,17 +118,69 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, } trace_vfu_prop("socket", o->socket->u.q_unix.path); + + vfu_object_init_ctx(o, errp); } static void vfu_object_set_device(Object *obj, const char *str, Error **errp) { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + error_setg(errp, "vfu: Unable to set device property - server busy"); + return; + } + g_free(o->device); o->device = g_strdup(str); trace_vfu_prop("device", str); + + vfu_object_init_ctx(o, errp); +} + +/* + * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' + * properties. It also depends on devices instantiated in QEMU. These + * dependencies are not available during the instance_init phase of this + * object's life-cycle. As such, the server is initialized after the + * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT + * when the machine is setup, and the dependencies are available. + */ +static void vfu_object_machine_done(Notifier *notifier, void *data) +{ + VfuObject *o = container_of(notifier, VfuObject, machine_done); + Error *err = NULL; + + vfu_object_init_ctx(o, &err); + + if (err) { + error_propagate(&error_abort, err); + } +} + +static void vfu_object_init_ctx(VfuObject *o, Error **errp) +{ + ERRP_GUARD(); + + if (o->vfu_ctx || !o->socket || !o->device || + !phase_check(PHASE_MACHINE_READY)) { + return; + } + + if (o->err) { + error_propagate(errp, o->err); + o->err = NULL; + return; + } + + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o, VFU_DEV_TYPE_PCI); + if (o->vfu_ctx == NULL) { + error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) @@ -124,6 +190,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 +213,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 +224,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 Thu Feb 17 07:48: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: 12749536 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 A2C07C433F5 for ; Thu, 17 Feb 2022 07:59:33 +0000 (UTC) Received: from localhost ([::1]:42972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbhM-0006c9-OE for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 02:59:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXq-0003nQ-3o for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:42 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:7244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXl-0004S4-RF for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:41 -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 21H4b68H005175; Thu, 17 Feb 2022 07:49: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=aM2fTm00qKbgVUhNkyvHNh/13RpGeTYVY+goNCYXkzY=; b=u29cNIEDHLrLptYCxUQIXCWFB0iPVlwfUfDC7XsFFjURO9ipcTGeRhCi8r6iyHuKEOXd aEBR5PVMFNewCkOqBiwGuBmAhlj/yvdg9hKLRPJfLdL+GBiK63uSum0tgItNv5bqcqWg AjHx+7Vp5L4uMjfK6WLHJJDBa0z9EMYNMgcsFwBr4zvKu3VrhLxUA3hvuSXQ0ag1nnEG 5QxF3Enac5s1rNfTvvG0Pn5lMHPen/ZM/GYcu/ShdSckTpZsfjJzamUaXpZ/7BvINVeE V8lqrJvuOEi8jSZC7TTg3e+dQc/InTlVRbve4ezhM7jAnAStmGLRBs2uKX6Wzs9xC9YR /g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8ncavqxa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:34 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21H7gCqT030201; Thu, 17 Feb 2022 07:49:34 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by aserp3020.oracle.com with ESMTP id 3e8nvtf6b1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e9YfmhGXB0Tk0i4OL+HrH77nbRJFAgn9Vr4x/MK4VnMNO/twEAvllehnZfa0UflrddvSSiLvwaJx8Gv79fvPwCzDd84pjGy9bIVLqkLQsQSkwlOxQCI5a6Pan8G24n/R0mTipZ5K7EMLnA3BOILyEPlsbCHrS1DnU7PdfA2gmwBUH1BBwUZ3XpvG4j4iw6zpAggbsj/T6LyQfHiVbTYsdd7hbBxLU4Ho5ZwvTT5//0O3HLp6n23pbQf7jq8W7DhLPLeHhTqM2YLljnVH50SwQmkJFDMNtCZWfxuOPuS7WCiRGW/dStDQMaexeB/xahnA9MR50Kccazkcg6nknXNSdg== 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=aM2fTm00qKbgVUhNkyvHNh/13RpGeTYVY+goNCYXkzY=; b=Qhmf8rRmn2Oc4MAGwUmErF1BjQ0v493UB0imXD+4325kqFRT5clnMml7LsLNZYti5ng1JtAv1XyuWNRIvzK0VVPxt0cB6iNYC+xQbWNRIKiVHXNIlx2nv3Gdzgkwp/QwfvYlP5vXaGQAQdL6brqj17n7ME7XVppMqxJ2W4+6/PUBBXSGNyc0NZ9COlg5sBjk0XoZkIyPHdT72UOx4npUlN6mG+bQIaLu3KC/xJrp7DiqL/CLjykU0qwW/dcnH7ktK8muEbT2lnoaxgPoX1PiEMkU/XtM6ns6l2X7TlVwabSkalF2ZHojjcmvvNnVLFP8CvmjDJ3irIeJxm+5uAjSBg== 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=aM2fTm00qKbgVUhNkyvHNh/13RpGeTYVY+goNCYXkzY=; b=sd8rk/9L+wuEqPWp6sZJha2ePYubKVaZ1zUpuY0BTbzw4afjixnKYiDD6ALe7Zc79l1BOBE4c6acLoHmzilIK2/3Fr5nPr37AQYfF9ySnq6gwhnKJH+sB+4fZ7c8A1nJWVfhslQjo9PjQJlrCcay42+E7VVkDvbbP1H9mbBgF68= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:31 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:31 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 09/19] vfio-user: find and init PCI device Date: Thu, 17 Feb 2022 02:48:56 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06ca75ef-6ec8-43c5-27d6-08d9f1ea0875 X-MS-TrafficTypeDiagnostic: DM6PR10MB3211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:288; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o4tggT5uSBQpM33+r8YBNENup4QSiGchec7c7U5e+ZvboD86s064BZRQP9UHT8Nwsjzq8CfKAyUyywAHQfPQn6X+5K921Qp5R+af6BVxldm2l/xV/VAeLRURKNSFtj788TPvuJhQ1nPpCYwrsGViXD3+hxpzDQnOUkZ4j7rXzgyZ2tFBRq/W7P3xoK794eSbBCkiYFdt9I5WkV64deLUyuaVM8vBSJ0nHjS5VI+Yr/DIdlfR+qvwKbw9K4zO2ZAn0P7+7AajiZKZ2KotbFO7dUkiJnONcugsQ2w7QH+GEwqIgPv1hf+zrlCHcFCBVngs184/Yy+S/0Etecn+VJZKBbHrYfC+X8NpxoP+iOgPczs8973QBrfREZblhu8kYSAyjx8bwfEk0de2gdSH6xJ02bZiiuGFs+KLoKNtnx3xDnPhDcTEYG5YVJS5j4t9gr5Wmue1MJbn5e9wBTWyqEu5YQD/dLf2R0GFUhZciX0eRTCioPfQLtXB1qjJxm7SUiGLY1MUa+MGSwSdX7CxMWvmueIS2d9jzHgtydarY9oMSeV8y5EOIjoq1vwx5UAlfGPLmNUSOPvA1mfO8u9WhxDsaGVc9q3hWOtdEAg5hzn1I8uceqR7Xfwtv7DrEARMTc3sVqwx8p8rJe/NVqXpzCFoKFKsIIJEBNGOcw09dYKskyd1jKb4FT2zEohi7zdNDfPCXYtBpH7ciYR45p5RcWMqWg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8Jn+m/n9nP5AitvDR1AF8Chtg+v0j+mYHlrcfWkXe82d3r+7Bnf2Mqexmd38v9L5ZO/GkRqUL2X1VpH4gzTdJFldDjgP9AFywkN0k17tCkhwKv/9cgEzoGcXk1fLiQQI4rmupx8ruDXmsMMzLg5ZC4O2PiQK+MqHbyKWQZyKWPBPiytcH+UXCvh7SWfL1KFZ59PraZXQFkaQIsMHPH+aEizldUsjMzIIewXuJQdspnaGjmXTgHi+Kq+xHfaJ4VkHeCIQs1GFWgn+9822hfou3GM5jNJcgsxfc3CJhzfEfy+pRI4xeG6UHC+Sz81CpRLqKHisarM5RQFMDAJ1EitjTZhiie77oDZ245MndW26569TNu41PK7oDT44J36WIQkZe5ESFP2XqPBoveykT34pcsXzGzf6wAghf/1QXfWIGkTs6iU8UHwQfdLa7tV9ddhdKQ0dVtOjSfAbNXnuAEdEHOBnA/V4WZkCeLevce+IPKge9QqbcYNKwPqowJ9MtqXQVmec6muAG78CYGP6Nip4o6HJx0CJTEgCjJtIaLW8fD4zfaa4aS2RxfwRtccp9qVLahQaoBF3Q1XtIN9qFt17ZD4zfeoaOvT0c3agszBJ6APFDky3bxFogY+RsGSHgiEz37l28GZNjjEpVlY05CvpCqbPGXD+taE6M3EqceU06sj4kKzlSqm4xNMHBq9GuM1xOCZEft5fUry33RUF+Smnh2z2QP/hXqIBE8WjVl0tUeoh/cQl6V8B7SAxiZC88TuoOs9+F6QVowHn6gaDjHFwIObI+8kjgr02GIVr92Trt/+9ATJDmDTV6YXOoJFXinPqT2KTCnPY8mM0o1zFoQbYPtXBtNmmf3KiLdDykuCTiWLgRm0Q6po6pWGN4BGT3hrcYIlwAmYe0L5C16NgmhfexSjshO8L6uPzOl0CbjrpIUqt7EKFy9LW+vcJQHOhFlR3E5mjirR6ki8dR8WMHVzYRg4TNys2CHOGdJmz4T+88UN3f6UseoZMohl6l0dexVb6RxGV4S5xQAKTGbqwxNklENIMTGrXlh+sLi5nya6Z/ZvSVS/choZGOgk8tDoW3FDbK4jVFclJa++1lFpTtZrEyMJpt6fTtHulOO1EPLEGGyjLdCotfKq6aYqu8FEqUfJYVok0rIMfa698d+s3PIWMBHrDZ30DJBt9UzSBWtCg5XNIAvrVWjy5BAwb5VBPSDUWAez1k0/r5ofc3WrfY1JAnZU8gMmRjoW/HbSOgWZ65Y4Vy2aq9lQ7HiKXT08REgejNAm4WpK4PAdfe44c7qqP8ZOGCbKNr21JGi2dtNp3QdDJW13pPaFnM1eNPVZcBXYb+xCWiIoEqTUkiC0Z5IccgumLjnlgCCByvzK8eBTphdXe10T88XhZjAQ88ZJir3tEENb2Z+bvhqMx/akUmWX4aKa0dfmZOrHFr7u28IWokQmAHV4+8Sq8dRATNhUdHvVr3vDsQdjTpKW0YghO+25VRRjZxLMlA4R9HMj80ffanuRIDGfTwc4CCVkuw1vwnAXB0ndjuoC9hmSkNh38EbsWjnLa79knG93SJoDi4YpuSjiVNUn18HvEuqXOgJWh7j3WJ+MNaWaBLKa96s+IR6olz6YDcGyOkrXo4AGrU/UIG8w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06ca75ef-6ec8-43c5-27d6-08d9f1ea0875 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:31.7891 (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: lg5Vu7NAfvRehPemF31Ye1Rq1MK2am0MEMInue3N6mwwGVkJ0SvdF5xxLltSlNoc3cLFmDSlym3L3xP/9rpeyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: Y6ndzsdJYpilxoLiLadxl-YcaUjyUKqU X-Proofpoint-GUID: Y6ndzsdJYpilxoLiLadxl-YcaUjyUKqU Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 496e6c8038..9c76913545 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); @@ -163,6 +169,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)) { @@ -181,6 +190,48 @@ 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, + "vfu: %s for %s must be deleted before unplugging", + TYPE_VFU_OBJECT, o->device); + qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + + return; + +fail: + vfu_destroy_ctx(o->vfu_ctx); + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + o->vfu_ctx = NULL; + o->pci_dev = NULL; } static void vfu_object_init(Object *obj) @@ -221,6 +272,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 Thu Feb 17 07:48: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: 12749564 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 12A1EC433F5 for ; Thu, 17 Feb 2022 08:13:29 +0000 (UTC) Received: from localhost ([::1]:54358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbur-0006Tm-1B for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:13:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXr-0003o2-Vr for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:45 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:9842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXn-0004SD-OV for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49: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 21H4RB16010826; Thu, 17 Feb 2022 07:49: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=jOT7JJjri4FHQW3sGPwSTX3h3CnfOVvFwSWkWE05Q4w=; b=VCKr8oybAHXrSHbM1USZme4FhbPdxIo/Y5uqfOi/PDOnUF+9b3ryzuvDFYP/RUfav1YH rBmtCBqh7t8giqCWEfv+rYdZ7fBn3Asa3f+wNlCO2Mzyrl/djg2YoejOcX80FeTG1/1z Z33fKBO3agjfq8iUJk4MtVOS4Psd9QpSckYxutsPT7RvnOD7PBPiR3ewCkIYn8JVTCJF iULxXhsElMyZvH4Un1hP6XFsXzifeBskIdW93Bt1dcaq7YBZWTvtP0sO8LxJVsi4Pv4S wkU4Bz4yc+Rg8AT2opd0ZP+qjLeuWzv/lz6DFilY5UP54fcuint5cexDDbZ/UtI2jUmS oQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:37 +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 21H7gCOv030200; Thu, 17 Feb 2022 07:49:36 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by aserp3020.oracle.com with ESMTP id 3e8nvtf6bs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X7s9XFjstnx3Sfu2Mcw6seFGvQXjRzuhNyNC0hMB4GpCIYK6vWLuudJfmAiT2YVct1l6YDA0qFEKa/ZVrikUS4HRHptKNNPnU6Fii84U+JAMv5jGBGA3Ef7TY/udsOBxNJDvT3covNObCPxEtQe7DynbWiwlYV73XV8lp31zv9ijS7BvCCDWv7jpmmznsgRkReEhWnfznvEOmcM+fNwfcUy6I2BfUQAhhlqM04OqsKljScZ1ixXW+cBbqzOg5sPSEbheOczkXqzaA38GH06x0XNUldSGI32yjMJ2rvFUQru9VqVLNFiZpmdnjT5mm8cwkcXW/4dNi5uDh0vp71KSrA== 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=jOT7JJjri4FHQW3sGPwSTX3h3CnfOVvFwSWkWE05Q4w=; b=lqliUS5EKWGXLz0dZbX+Qtcosv1D1UO2LZ7Y/E0vaXWYHNka4GmYsUm0pTv51bGMelFgm3Hfm+8/4Felye8Tck9dM2xpSNmS3CANCciGYrwbxngetuzHXgAr3HG9lG5RFd/0m8GsE+Khrdtq6f82kUYv7+lwQ5B/Nv/AlizB2Va2+hX2LjKgU4lgqFJvQe6YMB5OC2i8tgLHxW5b+3MqpHmTfOTK589uSsUFm9t0kNxE8OO0cChjrHF2vjSL/K+KIoHXfaV3xahzmQ5j8vTcGXlrqePOk2spOhmR+jna3brgJtMPSehIu45W8LmMupTQBs8Jkg8qYdVcLXppsc/zgg== 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=jOT7JJjri4FHQW3sGPwSTX3h3CnfOVvFwSWkWE05Q4w=; b=HWujNLxgy2JRBqd4Ezba4ly0arh7cN6/o9mJKXSPyNri9vPlciyL6jKjeG8vxYC+QNbVrEd+lRDdzC+2vbYzTXKPp0ddIqM1n9LSNJizEPgMzQDgoXb9OTgwq4uooQ2dUqnlS93w/0nHkI7WLiPHi9Zq37kCdlrgO6QhxbCMCUE= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:34 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:34 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 10/19] vfio-user: run vfio-user context Date: Thu, 17 Feb 2022 02:48:57 -0500 Message-Id: <1735f90d6a5784a93cad5e46ebc6bb1a40ba1f5f.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d389e9ab-7d97-4feb-eb1f-08d9f1ea09c2 X-MS-TrafficTypeDiagnostic: DM6PR10MB3211: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: 3f46QYOgSOR96dy/QksB4nYs9hEW7znvzgd8NxiLbRKjhX89hg1R1ZM6lbHWD3dNP8SvDqM6EXs8yqiB7IagUNTmCk0GVzE/EAuEC3iDhyJktNnWvBodtpxLQ0EQs2QYmjhf1XWVmEhKSwz17pfo0sf4QMYeXjJB2Ezyo4XYy65+2TA72ptVujAWf88N08dLa12kgvoZAD83tNgF11YaanUEAOURZtsWl24Fu+76paazQQipWK6/OxRVfGmUbVRmuE0Qk2kJJYOkMk8Ilsq4YlN8rwm5o8IWy62Kej+AI47MAiXr9Uy227/a0LByS8rn3/yNPwDyoa+8N4ayhCZ3/Gi/rtLKKFT9a2Vhs8Rs5n4MENAgBKSunZcvC07XB4Rkd74eeRWr9cCkwvmk43CW2f83mec1E64kfUtPlGB1yHX6UPpwxhPWcN/YNCMn/mja5mSaIkgv/vSVepM6R57xT/AG0YwSYuNhXrm7OjMd6FzTzm3RuzkM0IPiPnwZ37AK0UtqjFrm+kmvTMxmUJiDLFx4mmnisvOAwHKBcm35shsLVzGOh/QoOTlwt5NYT2txuE85zTfkn2uxmnXn61UTQFIHprhYDq206PplLxJAe768zhDPNQaoDh0u8wYHxjWBip2T9aLR36eT7hS09iP9AlACGx+LeydVL3zDdtLXDDI27khmh19V3MncdpQV7Iw3rphrBmx0L9S2O9wQoI6B1g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MGcXJiGTaq6Gsc5iGYGdFhiBuUN5b402E/NHQHWDNiH+KH0Fv+yJY9MVL+rhNWz6HpCUaEHibg+9QQ87yeeYecYPOGivsglpgyEGXbAH8nt57y+4qvFLvklJ1gjhvVaqfBuNi/oWlzufIbtvOpDUbC+ydBVRnWaqxYkgIjR4rip3bIIQpwnoWWw3WLDtZYdAtM7YgYzFezuPpyjeA8WA4J5Jtt4+QwTFCtYug4WJBy2sXs8Akm29b6uW6IdiHEcbXVaeGIe0qn4DRVjMTuhPg6A7fWFY7OhNmUr8NgIwwk6LQ9LKYhsqGsbiYDgq6Y7qk8WIo+93UAg+K5Wu8YRmv1gHFUDY8j1pnlXxccp15usPnUds//jvX+vOuBQ1v9Hm4VIu4tqwmZNipUPAbe3tt4d91QcZ/2dhDZZ4Ff18A8cFJ2ltZreUGBL3NTK6/vifFyt1j9xfO0wwisLHghMQSOEhR+WMxhr7m5Bs7s18+OOXfJag4cvax31wIxb1LbfSSEHsSaxFB0PLtRO5VmB8ss9oJJxsgS4Oqs3xCxhT3FbSBD43c8/kQMYbaJrpeBXRWMdIKezrnPIJ8pL0pifPFDjCd0FiXN8ocvBLxBBxsP763rXPNxcz4a8X8DwiFy01ySHsQ/6r4xPSMdBYNvhJFdpZK8ZEI+MOkrr0HJTn3rcs9wqqQZolZgTRiZVBXvkgc2toc3HaeoeSYhRaeePJU0PBi8wLmspUE8vVWdJzzZ1M3y2EcJjbLoav6/dRTtzUpLX0H73yfSxDxz3isFElvMbIg/02ptnHQ+ewwNfMSwOLNIamZD82uVH806alEzABTfAZ15e/t4IGmtYg2hNSjgvMPz8CbMZnFXsPsO7a7W+MmSs2rCATQn0qvcucDU8arqIzupadUyGwyYLUoTHdWkytLUzzMKtesZ9yrUPT4km7Mq65kTRFN4wuRL51dC3hxzCvs6khFMH78BGLzMDGwr1yEWg6SRk5Qdac4vKrIWMWiHePx3zmHBCu9hNwg6YNxk5ufMxP1OY12zUa4m1bMpd3uAyg4Y5VSn3KWxEus3rCSTxN+bzycVdk8YZu5XK7vVDbeCa7oWiopSVLPZQA9Uzkrcw1piBd24boylgtWU+CqIm7F8BVyDub5kHXKTipExzqg7LEgt+Kb7AQ8UjlS1g2zeiJ1z2J0teQdGLD05Wm7FCgPf8GeIYvrSwaOEtbmESxcqKFxwcPDnybBeKBzFk3WWWLSslTvJy7WDYHFwQm5RB90auUiBFvz55AX3Qi3Iai9ebwXZeOLVZ3bC0phYta3m2VW7wIoCWTxkwbsoe5P4VwOtteM3H+1TuMEOQOj7GRr8HC2WTKMnudQzwAAjWvCmXBSD5KWkKx5tfifDNg0DevsFgjSO4TQJhucTNNNkMLy82PIEVLyTflb7O+9XjrqIdFHPOXTjqZkOLrXNxhxUrAcmQBOsopaCxRZfXI9aLn85N959q7O2tv6anTsL6MwbstNQUa5ThJc2EfUsAK9lDKZnPjN8zk6LfBe1aXhWKr6z7wIt5zovLnbqyAHv5BnCjw2Z2Wf7PzhfchdVkBjy1FhKMly7LKSJSuFdwws6mRnWplmRvEd3opum+pWiBmUzMfofMSZNOrHMD92C4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d389e9ab-7d97-4feb-eb1f-08d9f1ea09c2 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:33.9139 (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: rSaM+c7j6+HtEUHEPiakoMNeER9uwfuWcXeyl+bbS8blq+EYsTZ9T94l7GBUT4+DSohKfmoAiwsX+k8mGXLHZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: pNEOXWsSu-9iwNUhKvqaZRk8SDTUz3rA X-Proofpoint-GUID: pNEOXWsSu-9iwNUhKvqaZRk8SDTUz3rA Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Setup a handler to run vfio-user context. The context is driven by messages to the file descriptor associated with it - get the fd for the context and hook up the handler with it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- qapi/misc.json | 23 ++++++++++ hw/remote/vfio-user-obj.c | 96 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/qapi/misc.json b/qapi/misc.json index e8054f415b..9d7f12ab04 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 +# +# @id: ID of the TYPE_VFIO_USER_SERVER object +# +# @device: ID of attached PCI device +# +# Since: 6.3 +# +# Example: +# +# <- { "event": "VFU_CLIENT_HANGUP", +# "data": { "id": "vfu1", +# "device": "lsi1" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'VFU_CLIENT_HANGUP', + 'data': { 'id': 'str', 'device': 'str' } } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 9c76913545..384ec4612d 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); @@ -146,6 +154,69 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) vfu_object_init_ctx(o, errp); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + const char *id = NULL; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + id = object_get_canonical_path_component(OBJECT(o)); + qapi_event_send_vfu_client_hangup(id, o->device); + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + break; + } else { + VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s", + o->device, strerror(errno)); + break; + } + } + } +} + +static void vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + GPollFD pfds[1]; + int ret; + + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + + pfds[0].fd = o->vfu_poll_fd; + pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + /** + * vfu_object_attach_ctx can block QEMU's main loop + * during attach - the monitor and other IO + * could be unresponsive during this time. + */ + (void)qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS); + goto retry_attach; + } else if (ret < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to attach device %s to context - %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -184,7 +255,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)); @@ -221,6 +293,21 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(errp, "vfu: Failed to realize device %s- %s", + o->device, strerror(errno)); + goto fail; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(errp, "vfu: Failed to get poll fd %s", o->device); + goto fail; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); + return; fail: @@ -251,6 +338,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) @@ -264,6 +353,11 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_poll_fd != -1) { + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + } + if (o->vfu_ctx) { vfu_destroy_ctx(o->vfu_ctx); } From patchwork Thu Feb 17 07:48:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749515 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 B1B35C433F5 for ; Thu, 17 Feb 2022 07:55:32 +0000 (UTC) Received: from localhost ([::1]:35662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbdT-0001Zp-OA for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 02:55:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY2-0003uV-I9 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:54 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:11876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbXz-0004SQ-Ql for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:54 -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 21H7nRVt010825; Thu, 17 Feb 2022 07:49:39 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=GvB/wwbHwU2lA+N0AQaiAAjf0fveEzuEUDH7LtZic7Q=; b=Zq94gPRfZGcrEyZ6JfL1f6Ml2LkX5ujR9MT9oSdW0y8SEkvkX6XfqdXUsKJ6mM0dgYWU 0sZC8WzfTFrYbXnGD0n0lwlQ5iclvb0KofrVCLzaYD1XETC0/PWqfEVNf0J3E/XsmI0v Va9vA8jIIM25VyGcKm0lSFKbkNHRHnGIarmaMirukGx+h/0ILAZL7uENtTX/DlJ3tzGD EET4dS0O8mHmfUSCM0gLxU6YJawiEzv5rH/pOd+I/nK/AEt3cJMAbWx6JNd6lDhLUu1M cE49H2G7RJcgMH7PTKE4jKuyI9fy2fkghfEZAIIC9CSd+T5/I1phMRhTlmM+a1YQA+Im sg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:38 +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 21H7gD7J030254; Thu, 17 Feb 2022 07:49:38 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by aserp3020.oracle.com with ESMTP id 3e8nvtf6c9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jDkWA4wsHyWdCJf8KJRaMmbfy/Um7RIjUH0k1R0F9bT20b9BWGT4ptr6HpddJwiT1jpqC6OFu5tyQzjgwzwosLFVEwfj7DtC9Dqx+3ja1y3Gp9N16cD00fG3NC2aYvH3th+ab5T1oAR0gHb+wfMoFggZ9953FKflUJhoQkoTrRoPpQHRIJAWVUuP2MGSOyBR66FczHXUyiRIup0gei9mW0QD4na7V5p+plemIM4XVfIrjJg8YL6C9/bb/UZgPKC+/deK2G3mqCMScRQTArDQ2FzQIjrFa1q73rH2H2Ply4sls2L8SeJwmNrF13yhcuc8jQ6+h5mRroQ3kJyMGcmSCA== 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=GvB/wwbHwU2lA+N0AQaiAAjf0fveEzuEUDH7LtZic7Q=; b=IUP3bG61rE1Eo+TUecV1iVXy90NBN7hFou4zpUr89YhibxbAaHCH0OHLdgG2plyerUiXxpPFUyYUHwOcUeMhIqUbQuWlCokgCi0XsKjdhoky8kGc8ce71cZgiFGnHuw7C0f7vSiykD+fIN0fgtJ+HcNbqCx39G/rkLkAiOxfxs53Kbck2QktgGRii2d8kFVHYs6SaPJYV0bcekv++64gfkMe3z04Miby90Tj9GDVBWFVli/xupxKfNcqd8lpL+HmvZJJ8XM9c/Tvg19x2obV6A6wLMsTwtzLPKqdDL9mnXizP+bFPEjsojpcbXNJ2xLqtzIqnfe+fKMYbFPCxNhjIg== 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=GvB/wwbHwU2lA+N0AQaiAAjf0fveEzuEUDH7LtZic7Q=; b=SbPXzbD6MBiRFQiHWM68AaYQ8TlPxYIhaq2kspvi00GhUTSa4Q3zzUYZmyyyPjpeRTwrbdkcUUZQVfvUlfAB9u/2KFoyopnfFRMZilwtQJuLY7q8AdaSVSVVLhC3bG/TJhvEy8MaIOVkVTcjZQxKcfr+34b+9SA26pwK1L7OfXY= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:36 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:36 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 11/19] vfio-user: handle PCI config space accesses Date: Thu, 17 Feb 2022 02:48:58 -0500 Message-Id: <435dad76ebf552f1b155c8ebb2becdefdb9edd10.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0003f3ce-8e6f-4ff5-c2d1-08d9f1ea0b04 X-MS-TrafficTypeDiagnostic: DM6PR10MB3211: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: ECwZTuGBJy/D9pCvI9Ojw6W+wDPZM2UdhVHn3T1ILcGV30AIgv6DtGw3Id3gws6P93BXz1EuF5zsLLc6ay18QgiALBTH82Kjvok4pDsJzMY4axms8TQS3lpmzgL5ueVs3juAqhlFVCYaNklbNNiE0/RNfU8oilp6/ydqcutripDZxlvZMDixMBD52eBl0RF0IAriS/aJk0odrAogbSmUZo5R682Hjm4WGI49Y8CErUx2/v9CI5YUaRVo4l8zemRtQPDXx3q+4r8weggzzP9AHi6+tM0zIfykBEztXEYo8tUAcLNnxk+p/6nfuaewNc/OW3UYpczM5Hqy6FaUkzKUdo0gLdCpUwRBgBe4o+0KSG59jgqYGdYwObRLxIplaGl6MU0rHWLHIZzOYyLVLpycEK01l6n25u2qcOJqnDz0MWdPwAvc0RflUeCDGzHmgoVXynW6D3DL5WXgQhQYjaiu5vHgLxI6u8JyIorEHaINeQ66D4vd/lpvfMZ8nsaa9plJe9AauFC89e3CXaK5/+MEA9Wu4Ltr3KXwe9I+Dj/ab7fpq9cYzKUYthHiyt3v3EjSypt0LseEWITSuc4vq/93g2rKVqyF/nB8BOfN7zCdMuaXY2hbBAvmuAmPL0wFUYm1mP7ll1JNrvC/nMOOGx58Mkjy/Bdf3vUpPWGb4o2RmZlIh7YpDUb/7IHrv6U+8V/wkO+7fIw6ksEZj8mhEEEZ1g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PQYfq51VvN2XAqfI2ImztdyddXt0o0mlQczWnwYx3NN9TAfiQx50JKHCMreo/EgyVavucsph0zGYGXBKwJdzau+5MP1qq2xPi0vbsaS4JnzCKhgLR+cd0VU8EbMPQvG5b/pQYeRujqzj0Gq1SbFIWQoBxIVdVG1SB91iWe3W+vfMSe2iUdId/eJlZXI4AWdZf7JMpxkeepiDH6lxDi5rYxQ1i822Mbr4tsFu9QRrlcaecLv0oMjTvUBf5uB+cKLvTd2Es7jsz6CzQJi93EDTPuW3l2tukgk6ZJm8jcbheg3hdVjk++dOOzOfQSv8v6PwnSRZ8nHinb8Am5lDhmO49E2TxtebsQsFgeSACTg+Rp41HKC9i5q7FoA17yPH4B42DGiFn6qAO8shZAlAPUBG/lVyx4S8RI9+ZtiKhZLyqsRjAOp/3XK0gbtKSeq00cG4LKNW0IEs41v7Y9E7MgrHCYgtwSaCBwqxlkJQbiX79yzIzdKgiKVf7z6Osl4R/psXph6+pLy4Dp123xQI/9EUnHQiA55XkSEAg5phOByQOnkRKi3qUnBUFWkYh+LskYm2XoMJq2f8e0fpCcxnPndCwp49eBYEZvmgRdcwWY+lzvV0c88lnj5Fftq/C2HMEczz7ryLAY+09GrXMxPwlJVsE1JUWGvTH0YB4K9na8j3ItsC47ilGZ87hfPCsyHIbRgNveTV29zJFYhCqyJnS55jNONeFQjMUSOyRSWBgZjQB7kFamNYED+JUsr3vSsUJolqakpM1giEdM5LEtElVCoBI03XbPwDARmCbutyn+OSgD9g6mpakDe4To8+5jnhTnC415cezpn0N1R+yxBR/7eVLOIBQ4z+TUsAekPJr/xU17gCYyQmtncKxzm0EpFIiC2U15Y+V75mjq1wRpUSLDMhtkIV2cR/Q1L771A26r08jiaeWsbleMZxp3lvsnVYQx391qwRzZpTy3fuCDsWOxtt8Q1aKpr+q4ODL9Dn/Zhfrwl5gKK+cL/86yZKuaRkRCNpVgWDrn1Q3FpC0/8t3dTYy4Sw/z7jN4rYzWjqR8ptJhxT3ARqTswGZYwLJ4ijS6AYkLUYQry/vrj36oFjvjRgNnkfeuNnVUukB53xRdWLQjzz31pqGEON2P0s9mn2YbLd25ixzkl/7ua2Kigi4+RxMDn9WpKQ8auwuAtq5pAPkDnsKDnEyUGRd7IgtJIjGsxrYSQDlriCTaGdqv+6F0xRxNBt5IyB1lgOjs9ACJOAI2YUKwtK7ZhlY3YfasildpPYY3grRzKWZ0hIwzK/8L67YqIsxpzE5AOsX5F5uCi44srBxChL2J/mU8E9vXEoqZPNJPtFPKfpEIYxOYCSQVpqkjLlW5u5K2k7gGpN9RdZ4bWPJPTBFMxC57z/Daex7EdWi5g1mkBy7t8qQVLCuye+gHC7ySc9+mm18NvQ0szu/jMZX1ZrtysocRuWaL6qSAJN8WEA+bnkFPD1zPTqJ63sTPOj/bFU4j2hrDoCfPiuZjUPMLuDJIh7blLtQhubHUzdjIRpB5elcVF4pmehrLrTEJnqqa4j1+W7e7lNgcAMKJ5ZghFYsH8c6Vx/HB3+lssBTXmQFNlDnLNLilKxyGmhjrJ1+XVE9PcRjBFRC+6bwRQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0003f3ce-8e6f-4ff5-c2d1-08d9f1ea0b04 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:36.0544 (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: J6UFvl/zXKSbif09dUn9Hx6xRpGuZRr9H/bo5TyUtRoGdmHjiH7VY+YGQcKHITY+BSfsRLM/PuJ4IyjDg2y2qA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: IWdVSy-MCxmNeVsgpsc6xUibAc6MG2lz X-Proofpoint-GUID: IWdVSy-MCxmNeVsgpsc6xUibAc6MG2lz Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 384ec4612d..4c4280d603 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" @@ -217,6 +218,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 @@ -293,6 +327,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_access, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0d96..2ef7884346 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" From patchwork Thu Feb 17 07:48:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12749567 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 DF6FFC433F5 for ; Thu, 17 Feb 2022 08:19:12 +0000 (UTC) Received: from localhost ([::1]:60590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc0N-0002Ws-Cw for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:19:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY5-0003yi-NU for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:57 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:15356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY3-0004Sp-2n for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:57 -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 21H7nRVu010825; Thu, 17 Feb 2022 07:49:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=u+alNkJGCskCrSF9zd0oMT5VkMK1hK4YVA0Rfqb8RCk=; b=sw1Hdlv92EI6CLQBZGGDggqUtyN2mRxcQHHnbJWd9AgQthQiY3Oz/77eFyKzr5SP/VoL j7qMWxDtEzvSzSGHI4IElQIe9b15muUlZ5Fn5pa1WzrSPPgW5dm2kJE3fs0Mc7dSvAYq ZfG8TlrOFQGAlhkPmYRPA1Y6CsuPbjlg7E6Zuv0DCwjMAPxn9MDt4RoiAexK3z6NhvLV BNEEeB4SJd1bEgYU9RIbVYQIDKPqkn/rtNBQMr9dN+/GWOWw1sPQP4APqfasg5ihMbes jTmhhz9fPWq0qqFWowAS3jRO+24AB6CSLj6s//DkwtEhntU/ObFZ7LNN43LFOblXzN0G QQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:42 +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 21H7gU2R135603; Thu, 17 Feb 2022 07:49:41 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by userp3020.oracle.com with ESMTP id 3e8n4vje24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jP5f4oZ89H3kInXO2i03/cHFtrZb8bCD/zV0uuM6y+okVK0cwvrap5YlSE6A+y1dZRjO1OExfMmhGrxE5IriukDu4IzpnbcbydAN/ZTHApER/CQjJ3r7WyYdsDkqmvduzXvvntFAF3zKoMM3xbUbQcPE7+aJvwaOpd12K3XxSF8KuPEr/NEq2HC60EyGofnbZO54jbiY1UeKrtL/Slq/7t+qzlBxz7hjIZjtW3/bitZkVL4ER/CvIn92ZtkVlISvHCpAs447W8jyGu9F06vrnAk1tsvM/2iFvEhUuy9Tx9++kzyljnLDijUs4Wn+P5lMBUliKbqYHP9NtlFV5M3DhQ== 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=u+alNkJGCskCrSF9zd0oMT5VkMK1hK4YVA0Rfqb8RCk=; b=Br8G2sPIX9orlAJLMB9sL70/bv4r9ovfICcPMcp+uja2HHbLXuK0y01Ne8xKkCvba8gqJxkys+n7i0P55i6BjaS2y7rf/iYVVRKNHriI1+e1ELf8x5FbOjsi3Cr+8+rRXMuCieZjySY+OLrNLfEDwktrm975QCrvHPBz0zn0vNuiLcQp05NZWq2b0Qp6gW7f89imz4/4rTkZDjPTzW4ORaPOoIDcwCnvDgt96epKVAoUTVDTJ3c1pS/eQJV7eQ0HRQuXGiYVplOabSlxgwBlQB56a5S2zytXiGiLRCt3sYfG6VCeQvBD9rRZTQPw2pyhTBY/txBvRcFmNbUGu9N41A== 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=u+alNkJGCskCrSF9zd0oMT5VkMK1hK4YVA0Rfqb8RCk=; b=oTpQ9cwR4TnYQNYg2RvO5/iMeAzkjWoOxBg/gVL1BOalKciuGa+sURJtqxeAVCpN62Dzxgbx0IPrSTTyvTM2d+mLHAz0hLXx6+fIQTPWmZ9qIYsCidw74f7dC5MvQNV4J3rc76EQBCElElSPVag1JHmbibbnd2GCNPhz5nAwtRY= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:38 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:38 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 12/19] vfio-user: IOMMU support for remote device Date: Thu, 17 Feb 2022 02:48:59 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a519daa-9d33-4179-c17c-08d9f1ea0c4d X-MS-TrafficTypeDiagnostic: DM6PR10MB3211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AxG5zQg3NiKgsyBO4uvRFAQfujxBj8Ir60tHF39UhysPNM9z5+XsUZt8u8vQaVWFHahC/UtLefIi3JekLfCQFPhbHESP9y/7K6wRpbGi84sUKJuZAwwSsyfoDqUoLvI28QGGTd1KGYWuTymQYs0RLQ7xN0rdi8WreJTvXCDBU3LaT14kVikUJNun/oi60krvmA6R8oHseuX+0vnfbp/N3WC9CdU2LfUL6pjZW1vlIyeEzlY6lPVPYBzxslHnwLEAQdbm1y4MxfXJFKAjAytfHjGNGKbXE4kOrYokjX4qySJDqZfJrg4QlXOuH8pF/gqGP53/WIzHNI0eYHqeZ939hB251CC82YN2hdtzmCRFcyYksFB7nWqYzqFCATvaqNq4+5EfUpTukbsuC8zfAquhrUVY/nB0c1/E59COpq3D8rb+2SVqLQu9YyWom1LD6hFGwxfZ20i42Jsj6PdQtuObUQizKTE++RVA/URquDK1z/DyBCAuXZ1LMt3Wp/EwK2XGCIOwqlkpT+bLLwYpPvkbioc32tgipJImZextGAhed73TVJq/gdqLgBs0dfJ6WJUtIqvIFvMqiNSzE8h0BOZWxWS0veCYrA1hJdyFoCJ0zBxpRwOjopr4PnZhXOJpNnBPP5yhHDMoTPAiny/dnfsAzK8lVCDze64QYtmJBDCBAHjrb/z88dlcjHOHtO/QykKPqBx+sFau/XwCOEOQAE9PtA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HRrxKp5gkgdWBtr/02aCIJpmHUtW?= =?utf-8?q?bgvj9Vy3y/+BBUKkVBIJ1M5JHKTjxIppsYwC6cIx6CdMYDQiwiYrSW57wZwt7BDOw?= =?utf-8?q?4jP8Zat5MxAAiy1hHXmMHZVBmksvMNoyq8oPdg97TZ/Le2MpljEWElZ/yOSbVbNEH?= =?utf-8?q?knzIIFny7Zj8s3zgGmonGzEZ7gZDlP4O4Zyqw3icI7fukKyfYVkvkRCZRa0HEZUY2?= =?utf-8?q?KulTIfjvuxc4/Cd4oYO/dK7OTA1c5w9F2QWjEOGAhbZinprafIgyV04/3/qeKUTSt?= =?utf-8?q?Bf9kZ8HvqGxsZft8Fp+k1QhgfszbQoCVIwrFBRRP3K06wxcw11Bm2ep4fy16pd6Kg?= =?utf-8?q?L3LQ5vBUa0AQodrXDp8lAKoeJZTg6GXLG2LpjA4RLWR3am5GHdwGsDFStyBUgkK0q?= =?utf-8?q?ePHUpPU7SPsiq7bBTfzU/FkTiGYHB5TCGmQIFY6I9oLyH+Nh2/ao8jqA+Yon9x115?= =?utf-8?q?QH7C3q2TGg2jCosWHNsC2sv4jQEpEfROYFChXRr8cU46DklQKIw5YZ1c62+MCu/hq?= =?utf-8?q?1dm/Vtlhi0huGxL/OzeY1rx45fpKhR4em1wG4cWw3r5U8FncZ61MnCDwtZyyhRla0?= =?utf-8?q?49BmQjNZQR9EohKXTKSFYyBez2oUe0oHuaYWKJtsKWgMvWaY336cTn2BroJ7IiyIH?= =?utf-8?q?EaNGwZ9AbeO5hyt9gzxQ5FMoT+xEjIGH52l4MC6vxdPCVdqkxHkszNvJmQF4c54Eq?= =?utf-8?q?ZhpzUycdszZeFXqYPKkp3PJbS8N+LWM9N4EgzHZgS1N916G26AI6mheHU5Xhyo3zq?= =?utf-8?q?YJ3fCx13Mu20IPWZ42Pk4ohyLk8aywVfLOK7BiWNX8InpiKmw00SH0ZGOgkBP3Ql3?= =?utf-8?q?YHMhzhyb8gtslHvF0V8gI1twfFObuCGdwfeFvIzy2PrGcQrIqAFWuEPoLFQcoNMDR?= =?utf-8?q?XW/tfwTJhfztGTd85nOxOqKt256Cmokj0gIyi9mVe2PbV5c9xzTGrfeyV3DMjmY/4?= =?utf-8?q?cZFYYCKESg0BGz+R5B9X/Nzy+J6dx091zHUO0QOJEKgda4wBKxNE9nx1ChXR5JgdA?= =?utf-8?q?cxBCDe5o7DZSHm2sp+WjMPBETGjilQow+3UoB0f6Mw1pcmtymzYbTe24zQebeDUPZ?= =?utf-8?q?D28kCMN5dMgcIX6nj/1SrvbtpuLIG6FjGhhSjyO6FFDCnpwV1ESDZQgM+txYM0apw?= =?utf-8?q?hK/r3w4HvPoLAqd3Au8ZSB58sTBE5a6M8meQzWWMq+GqZD+00Q5S2Gel13G+WKzAK?= =?utf-8?q?/dsrQLkC3cez78Brhx7E0Acfi9PPYaJXedU71mtyObJ6eThTX/CvKar7RsDV3aFuC?= =?utf-8?q?WgDo2m9hn27TR66Kc87aZeY6w1ZvJFHy2+f13NVxc40GypiNeFiIpjh2frTdgXYHk?= =?utf-8?q?lasbGC+qLW4es0oCQCQCeEEUpZVkOI08mV7KWrGqSjOz3e0Jbn1mpZMlyzAMmLI5a?= =?utf-8?q?msjz7HKgrppg+0wPVC7S09oIKxJ2fx9Vgj5BXIXRHPezxVjzdE1TYvXGfbOTi4V9E?= =?utf-8?q?+n0UtshxQ3E3XOoM46gD2CpbEgiWe/Sur1aTSsCVcOAuSUUY61mFqVKPkB1wsyg5u?= =?utf-8?q?adLWQciWmtzlyXpzu9FPr10CXV+z+Rt6jpFIej/s8XDMty0MD/b69Xo=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a519daa-9d33-4179-c17c-08d9f1ea0c4d X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:38.1949 (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: DFeGhCmu0dH0++DOxsyEihYheUWwRTfJPTZGNZJnsO/onnUugHk8eq5FPfsNwrEl4T7/pxHg5SbPT+GVEVtXYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: Ek_fupDNrPTsRhu3OJGr-sii5OBMxM_B X-Proofpoint-GUID: Ek_fupDNrPTsRhu3OJGr-sii5OBMxM_B Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Assign separate address space for each device in the remote processes. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/remote/iommu.h | 18 +++++++++ hw/remote/iommu.c | 78 +++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/remote/meson.build | 1 + 4 files changed, 99 insertions(+) create mode 100644 include/hw/remote/iommu.h create mode 100644 hw/remote/iommu.c diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h new file mode 100644 index 0000000000..8f850400f1 --- /dev/null +++ b/include/hw/remote/iommu.h @@ -0,0 +1,18 @@ +/** + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOMMU_H +#define REMOTE_IOMMU_H + +#include "hw/pci/pci_bus.h" + +void remote_configure_iommu(PCIBus *pci_bus); + +void remote_iommu_del_device(PCIDevice *pci_dev); + +#endif diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c new file mode 100644 index 0000000000..50d75cc22d --- /dev/null +++ b/hw/remote/iommu.c @@ -0,0 +1,78 @@ +/** + * IOMMU for remote device + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/remote/iommu.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" +#include "trace.h" + +struct RemoteIommuElem { + AddressSpace as; + MemoryRegion mr; +}; + +GHashTable *remote_iommu_elem_by_bdf; + +#define INT2VOIDP(i) (void *)(uintptr_t)(i) + +static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, + void *opaque, int devfn) +{ + struct RemoteIommuElem *elem = NULL; + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_bus), devfn); + + if (!remote_iommu_elem_by_bdf) { + return &address_space_memory; + } + + elem = g_hash_table_lookup(remote_iommu_elem_by_bdf, INT2VOIDP(pci_bdf)); + + if (!elem) { + g_autofree char *mr_name = g_strdup_printf("vfu-ram-%d", pci_bdf); + g_autofree char *as_name = g_strdup_printf("vfu-as-%d", pci_bdf); + + elem = g_malloc0(sizeof(struct RemoteIommuElem)); + + memory_region_init(&elem->mr, NULL, mr_name, UINT64_MAX); + address_space_init(&elem->as, &elem->mr, as_name); + + g_hash_table_insert(remote_iommu_elem_by_bdf, INT2VOIDP(pci_bdf), elem); + } + + return &elem->as; +} + +void remote_iommu_del_device(PCIDevice *pci_dev) +{ + int pci_bdf; + + if (!remote_iommu_elem_by_bdf || !pci_dev) { + return; + } + + pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), pci_dev->devfn); + + g_hash_table_remove(remote_iommu_elem_by_bdf, INT2VOIDP(pci_bdf)); +} + +void remote_configure_iommu(PCIBus *pci_bus) +{ + if (!remote_iommu_elem_by_bdf) { + remote_iommu_elem_by_bdf = g_hash_table_new_full(NULL, NULL, + NULL, NULL); + } + + pci_setup_iommu(pci_bus, remote_iommu_find_add_as, NULL); +} diff --git a/MAINTAINERS b/MAINTAINERS index 751d97852d..f47232c78c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3569,6 +3569,8 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: hw/remote/iommu.c +F: include/hw/remote/iommu.h EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 534ac5df79..bcef83c8cc 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -6,6 +6,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iommu.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) From patchwork Thu Feb 17 07:49: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: 12749569 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 7368CC433EF for ; Thu, 17 Feb 2022 08:20:40 +0000 (UTC) Received: from localhost ([::1]:34666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc1n-00048r-Ae for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:20:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY5-0003yL-HN for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:57 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:16084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY3-0004T3-6i for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:49:57 -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 21H4b68N005175; Thu, 17 Feb 2022 07:49:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=SbuJrI8E7mYROfGWND44Ho3onD6eAhyXw+xRa/fbYWg=; b=OzeYMbAwBFRRZ61AO4l1uuSMX60J0wr29b//Q7+HNrSbbNWPOzViD5BZwMkPgsvar4zG QCsyUIe7imzspIZ4Fq5l9MQRWlEOIr1uYrVOcKR/d833H2TTquzYBsQybFdAq1xmP3dJ 9BjskHbAH0HM+w1umMnVBdY2hGDvHeDzkvyo7u5EGRraEvVe28dsWVyOmLU0F3pRbB7q 4EWD8WH2BaAAZpsPfUcZW+eoF01UQQwxcM0BYbWlScrGCd8FL2B4Qv1zEgGCS0Tgf8qI zFmJ7cif5kw7BivJK3hIgAKQyCTw/BBi6TlOIddV0xARwjbJDY3vZ7eqGsywAPqpXJIt ZA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8ncavqxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:42 +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 21H7gU2S135603; Thu, 17 Feb 2022 07:49:42 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by userp3020.oracle.com with ESMTP id 3e8n4vje24-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mA2aKjn2lQWw9tlbJxdJ0b6zgphrG1jQ+Z+thwiLXif1V/U9mwTgG0OR/2wv2OaPj6ykocljlOI0u8AZYxxmkQXoPwSJGrJtfuJJowuQCWSRsEp+CPAhBqPaIVn0ESLUU9/neB2cUZfVFq7vPKcnq7daJ295Uk+vXhGxs4S4K91hsoIVt6jJooUyI8KqrtnxGcbTRtEpp/kS/89Fv8x+vtTtUBHCRjmzqTjkJQSzA5g2M/P8vgzwEc3GypRYhUDuGLM7xQpn1PmFNMC3uOs5jJZPSOma8EO9AfGSX9rhYYyLaMzue0Rt7LcP/SG+boHum4qEJlj670uBrv3PBWXVvA== 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=SbuJrI8E7mYROfGWND44Ho3onD6eAhyXw+xRa/fbYWg=; b=VmJ19JRMRd2ZqRM9ZeCtNjoV+t9KzlFiWdMEfcMhc+ImTLfqWmzDgxFuVC5us06juqdXeM+gfJyrX4qcKkKFeMB89nyPAANTkgo0C0MxQyqepJ6STWdsxWD84O5ZHQ/eigCghaMmk+6O0HTVYqNIv/JEstRDx2ChK7KJtIDQJ1+xlJS/nrfF/rQ8fyjBbiJ28V3HjyjIKhc83NwJ73zOUGNsuwV+/JZRHteSTpwd/7LsKkYOLirS1hTM0iomCDXL8VtNvB7Vf9MbLfEnc81r56e51XqoZynG8PwhM5TBo52CRz2iBTnB4bCt1V6/+4hhTkcjGgfqhu3hvsATJUIplg== 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=SbuJrI8E7mYROfGWND44Ho3onD6eAhyXw+xRa/fbYWg=; b=OHqhWDIJaoDRkbZhxNkFm7qCwu0Y5GDIGOA5RBwvxVCLvtlYK45e7EY3GaEMoqfBNm5BMQsx2/GI+SFtfUKRz3cOWQJt4xXbuuI/iKaeizbT9c831B2LHEa9DQk7gxNZna+WUdx2qC++Kp0ltpbDh1CiQ8djwbZA3tjwHcV4eXA= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:40 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:40 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 13/19] vfio-user: handle DMA mappings Date: Thu, 17 Feb 2022 02:49:00 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 39f603be-3faa-4054-fb86-08d9f1ea0d91 X-MS-TrafficTypeDiagnostic: DM6PR10MB3211: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: 6llhxYm5vfO6oSLH5BCn9kAt/KF+b5durqaixqLnwEBsQILNdE/0WuVzu7lhLhALg9I7cD1FBQ3vT7mut3SnGJLTTYAGkv8NSYckhtulTFHcOe7vdIq1rT/TxUgO2usfPGoWq97av0zD7sZD1FqRuK7AZmbRa8583VVsnoPOO5ru108pvo1EcK0x+bg+2mLvqZ7bHcR+mILY0K8deqEg/ezuLqTM/tD0WbqvBnLT0FuCJHEzgq+uAVEODV2NAeSMZH5b4Ushm47HuHY/RcIuPn2opRbgAvK6k25zksO9f6vFiiw5hyc0moDz2X4mHJMOpI/JEq2IeWfRCBUHlVs7/aqqyTctMgV1+KcPFTmYEVr2yApZvEazIiicXlju9hAfJpgBiZ00vviKObWdSulO2e54FgBbp6uzf6xbS+8TgjstDveWGkiT7w/xKZTpVaEciVhMOJUkgpneYxTMVmuhBjfshtNT3qFkocRWxAHWZQGUmtgKsnFt25jdgvr532JuGgkXUfRtvDoWVPvc2X+S0gPFSk7iDOHzuUeg3iPPfXgXtqiI54YBYbEPy2yFqe3+t9GJyxBHyGkV3vFRUdhzzYIPqyuh4aRSX3NMFh65LC5FjNI1CEF1kamzH+cFDzf1SKkjZ9S9iNCV/DzxkYs0sFz2Ol6IjIUXxyAHHCL2VcAeoXK/KPMONPUXablDSUKytOO1ocJ6UJJ4MZsiFPbJxQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cG9DIcqTCYATZIy97JIoRg0LcBl79XVC/y2GsmKjM6nJYzNk8byTNov+xG71sYsBeQr98WpQVY8lCVjhSPt0g3epQwr+5DPwoDCCBXbppkivzkalSwdCyaZeSccwKagQzKfd/3JTyO9k+y9Ig2SM2bEFBXFUMYRun1R6uWNsnZ1vACsRxOrlJMTxSHJbYg60QOp4INm9T8vjDGpidIL49epDJxJt/nW63XN1H70OvYg8czjboR+5rd49+OJUPhyFoaaXPgtycUYv/eI6aAsp8PVG5lCTCwQoXNd1HoxoybHCtIG+pmttkYJZ5DJXb62+QeVSghQ6JRmkl4fz7P0Zh+/i9WnfjcHEtBNiSQBb1aVfrTgpXsjqHUS1krHpD4zZCqTxqVAnyX0lK23iJiVFMMitLCDWb/WIcwLhLQBQP8AEnVgY5yyJaPv6OjBrvgH/1P6K+kNRSMrULdozrhUi/qjMYYCybldG9K1Q+KjNq9c/chCf5ANDfp9jdrsCVLEcM3VTDY+nrjKHUUZmIcojnUYO9ZjcJcKBpRsAou35HSi2ZPzze4PQpEU0IZ8HL9aMbmg77JNYagXJzDclOQ69DkMUBm56odHZnDbvvgnXq0rc11QbGbk9LK9EKSdhaM+WcLP0/rgC9IDdw2NwZR9Uihl1KZlQm2kuxy5/Oc5h+Vl9Cvn3W7982oZ09zvIAczIoDhnrBIb+PlgFrwz9+ds2tGsYI/m/D+ylizTEErl+ZmPlPnyZq8TYW/f1AQ731sl6rQBTF7ZpM3OwWZZ9wLEQwa1qNd1TQgwPgbjmVqlFekz/bKye4VYTsYl18hcPSIhRGHNZAUcsjm9CY26jdNHWypTIE7gAT8HEh5ILY2VXz0dh6rUpQ6eTY8/pVWQmt0nzbezpIHlpdvyQPf+XFNDAfSyfScuUha6ZrOqbUtr5ktkG7errBFyh4Athaq+wBX7geHvac4UaTfnNEr8AYSpni55pP9LefHDSCl+Vbhrg4akz5yP1o70QR8z4ftP5Dyn5npp0wGiX2FA0XhonHkBF+XcrlZGrz7La3V+BIXOQ7kf75JJmIpq47wAsGmANsiwitFHrtGCx2QB1dr51XRUdO5zAhfbFLKQRoxlaVdykIsYN3OjvhyvZzSHBeMf6tIvSk0Dc3p86zED9/Ums0QqO8hoqvyVnzRWd1Z8HsF1C1oA8MZqsMNcgiL2VlIOkhNbFNwnMvXhK3poHcPfr98Jfwo+qUesIsk1uksaZvu+zmBZLB5rSTd75n46qW8UsCg0tELg7xeo1tc7No1Da2FsxBNBYidFs8kOfnUcpJkwtjUK2B7hu9fh+CTJJ7by3/I46iXR8lq/dCKvNZxCfTMBDtvQBcwewYrC5WnKwuGjOvoJFMgY9Bonc32BH1TKj++5Rp1ETNefAHII+488u+rYCb/lmXDJgmdF32dCaucn1G2r75n3TLoYSKr6CvIR13p7EJz4BLARk9nmi6EBBdflqyyZeqw5rGcFYHsEVJjvME7jTO/z02McBWSuxkgH7fXuEEgJE0jCRdxMZsVbhFz11sqFVuZ7si3XpwiLwnyl9GtxHylEFxGWo2IQkIDbaG8ZoAsSGzqCGdJyBULh3JFkZDgqW57HYw0W83pGfYloYhg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39f603be-3faa-4054-fb86-08d9f1ea0d91 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:40.3041 (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: WqhnV9agptMdmfRgggmjr+pRvBoCv6nFufmY6UwlHG9fV6IgPli9oJVxFQQ44mmXDQ2sYfcisCxVFWmPTEzQkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: 0PLl5ht1kWVKObpKQ2SRRGRc2XtnUnkg X-Proofpoint-GUID: 0PLl5ht1kWVKObpKQ2SRRGRc2XtnUnkg Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register callbacks to manage the RAM regions used for device DMA Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 5 ++++ hw/remote/vfio-user-obj.c | 55 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 3 files changed, 62 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a9a75e170f..db4ae30710 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -22,6 +22,7 @@ #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" #include "hw/qdev-core.h" +#include "hw/remote/iommu.h" static void remote_machine_init(MachineState *machine) { @@ -51,6 +52,10 @@ static void remote_machine_init(MachineState *machine) pci_host = PCI_HOST_BRIDGE(rem_host); + if (s->vfio_user) { + remote_configure_iommu(pci_host->bus); + } + remote_iohub_init(&s->iohub); pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 4c4280d603..971f6ca28e 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -251,6 +251,54 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, return count; } +static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("mem-%s-%"PRIx64"", o->device, + (uint64_t)info->vaddr); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_add_subregion(dma_as->root, (hwaddr)iov->iov_base, subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return; + } + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_del_subregion(dma_as->root, mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -338,6 +386,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 Thu Feb 17 07:49: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: 12749572 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 02F5BC433EF for ; Thu, 17 Feb 2022 08:25:33 +0000 (UTC) Received: from localhost ([::1]:40972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc6W-0000Az-LG for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:25:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYA-00045h-Ch for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:02 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:20684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY6-0004TL-Jv for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:02 -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 21H5WxbK009086; Thu, 17 Feb 2022 07:49:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Ejh5N0EBlhL381SvOD1+mgeuuRLMXQaPGZO1ZMI7bh0=; b=T4nKtKbnYqLf/vLmuGQmghjflemE/mWJp1h5NCciYey5CcxKrbOmeWDnzfXte94ohaXj Y3xTgEIjcTOXYBwAGkayDu25KRle3IIm9m4iJV8aKt4Pa2maI8oBH945jyYakcMXZVmP HRDp24wyrV+WH9BeS+SQjKqCf5vvy0iALUxroqGgEdc8tgeZUbBa8Ghk983KBXMl7MZX 0yw/59DigsEekym7Hj5DIr8UEHiTzbmV4crOkGK3pM0gQqV83DsLn9TbpsV7kHKw18LV JJIepIR7F5jSq+wB1jsVnu4HM/c0oSHYs8HbQhf/tTRgNbdHP5MfhNqT8vWWBvDDfQwq uQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nb3mhrq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:46 +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 21H7gatl136179; Thu, 17 Feb 2022 07:49:45 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by userp3020.oracle.com with ESMTP id 3e8n4vje3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BRZyUYrkosmoKfya3/AO8O8R+8CPOpYk2CHFQKg2J0QqXdGZxVkpvaQVjX7ZziR/wCC4grEFtkVkJaCJ89/pE0p3WJ/4OOaMg1auxKrBPypX8LOcO5VBYZamLNKMOvyzdH6zEVxtCXG1Hth57fbVlq5vsul0yJZmT9QGcxfP6mGGE/EjylC1iFeCDanPmtSYXiD6CmM0IpYFm1+jUm5yGn8Id3Vzt6MaaiE+Z52xox3MlPDg4q4FKgVcqoiUzgJ9Jl3P6xueJNXKeVWP/N7ZLwZ4Bw+frInRoI9nMvPzV0BR9d0h2dgSZT6e9Hcj7LVOM2gWUzVz+ThM4Sa8HsI8KQ== 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=Ejh5N0EBlhL381SvOD1+mgeuuRLMXQaPGZO1ZMI7bh0=; b=Qo2ysYOQ6h/De+5Ax7vs08p7wIE1iuxgTZmWfmmZZetTID2xd2t1ClfxJUP4T3Chhj3AfvdZsL0HzGVtuZz3vhs23d1kqpR/HJwWjRB0Zj77Xn8gb9Gal3A7uDGGiwLSVB/IvsmLwS23d28Kndzgy+07E367Nt7Qv7gRXVQmej38eg5p5ze54e9msk7dvLcZv0JWBKyAXjMRXTMrrzE9tG13I14phm5ItvVgYMXcPgMKysAVNGKPUkg4lHmOdteoBVE/KGkZuvpTJw/eAjaZcN+UW00T+4pwFig2Hsx0R6CsLV3zdiagT7s6O8GeH4zkq9sjgwR1wz6QCDsRZWi3FQ== 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=Ejh5N0EBlhL381SvOD1+mgeuuRLMXQaPGZO1ZMI7bh0=; b=TA99OUTEg/Kl91DRUiexZ0aOHO2TqIotMWKJeemf9ewOs6/nXfKlXc4Us3t0Ir1K2NtkA9e2Bixp83BYtwGqYX2K+lGIi7UgQ4nmEYZKAZq9ZrDuUTVy4OquxLA0dBpAlstyBr4vsuQlgJ5dhYi8NqpXIOMYGlKOt/S4AXRf2Po= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:42 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:42 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 14/19] vfio-user: handle PCI BAR accesses Date: Thu, 17 Feb 2022 02:49:01 -0500 Message-Id: <711d01b9e52be0260f26a72feb286f6b32cbe332.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4c7322c3-23ed-45ec-3592-08d9f1ea0ed6 X-MS-TrafficTypeDiagnostic: DM6PR10MB3211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:356; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AnwsHnBwxgc59QiCkTPdCKoTbdJ9R9iRTg203IyUfnPw6UNGtTdb0gvuynIyp8DZnpxdlbSMRCsHRihRjVQ3i5SbNDLonABPY+UJe/JO/y5uVZkO/rCdfUAO1UllaG8H9suPHQPjm9Vvc5/OPmx6BJ+s9Lz9MW+IX/S+/5Q+QEybZPCct7gp4vKdYVt1rUPXsOJh+ldGHqmx2DMMK2HdqV3//sfK0qvSt48Y/NT6OmUfJV+ZJO+9n3r1ChlEo2AfprCZHfxs6N0RerjxQDShsiw4eI1L9FDXYHKdxl+C0LcPcsBoWSpcF82w9UgKbctJ5HcbIXnc34lNFGMgSnIufenrePAL1S3i6xQSaCRMxIm+rhJh4VKgfb1mE1a8atpT2IpGnT4YFgdDh1isyhwLzta/q4l1K+TerlpAFTN0n0JD8RjHgS88PSzifj2hBevAIuBF46uFO89+i8IczyJm70dBCWCfITmC87om98XK/BpPpVb8BKdMLmcf6Y8UMoXy2BLwYJR2hzqf+Lt4bAN+v5j5yIZF4TpO5IW5xDtVPKa6LK4bbUuEXeym3k1f8PUN967xC9TBEctPQGZIqjdgj9Jlra29jwBJq/PDxv6g53warI22muQNedsNAB+AoSFAGoOs+cxr/m6RujnNMwHMN37bwhf7N+xOtu2Sy6DiRvZzWbe4ayYwivbtFKbquORuZSY40M/lfTeKWtE65D9Usg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C3CPHcHNRhzxSAUicH2LHba0A7FFwfa8/js38tkuVlWjpZY9guqPMdC0TG/TG+zxOKnBzjUyHMxogR0tWIsEXvXZTVgYepV+CxS3pq+Ak31b8uCbYdTh0TOL00TfXIt2b/orRKzUOzkI0mhaDGoxxBn7obn/AzXtsqjolm7l528aARnFF5+RaxW9ma7icw2zvGrG9KuMd/9tWNAyJPd5Niw2t124IC78u562QlxDNnnjHnBp82gAPSZ6bv7K+1wBIPHM990H9vKCcz2l3dGvaMoDrKU+UHhm3HwSf7osMfkx1fsWTG/6PyhgbyzdAvcWT89ec8e0dUy2+b1LIiw364z5QQtNVJkNViCX6gNoAOTy3GQu+4mPQpv6pEMg1UgGIE4tznoqHnoE7L0RMtcgKcCpr/l6fCIDlw/a/Q05Rtt7bqLgSXnJTeAmcYmw2tJV23tvwHpDw/wu15YtvMD7j0QOxsk2H66inbq7rIOpdhDtu6BIj627beRRoTbPR7OWBFKaESsdjTO4KBtP/UslHEF8P8AEhvug72Yt1rsMqHtE4puuE7NPrxqmQlymZV0QlOdITYnwkd9y1axDfD5Aq9KBKxAbiN0o063S3dyC4+vRdDZQzNG8ooiRJzcOl28+bPcmxE3iT/UUwtsqfnzxM3gIoONrlgnp1GstOUykllvbXje5J7Ze6wpDpt+ywKjLU6sTUQNkl/g6WBpbNQtTkGog1xOCTKNQsNbwZCOLjaaLLXwG9ioEB7okpP+IK4VLpl040FByfa1B/PSipuvAnalz8lcJNcVWiNzbT2CJLUFAbSWFZh74N8AG0upVnBkjbWbzIzuxxcFKdV9TdPDOogbIi52Mr3RJVszCSISVvD4Vq3vwjO7nAxXache3lSWHjFVb3stHwlNpR8wM4hnW0UJEa5fA004SqzhlKyofjqkiUvXorEuse3NckMnRurtIjErOU3wXaeNyoTaxyo76O8FWfiPJG18AQKk+GASQ4JJv3a9c7XYIpZRSnTULa5ULYwv8wdCq7RFsEc3irblIZuED5Q9wuxWdJiAqKKkxytxyRcP64cCHrrmpipeAGJaqqa/k5yvQObpx+M+TbXSU1xEUdARNjfHwxAFux+JmKzNSx9bTgQ+GuIUbAXs5VWmSfpO31Sje37QSxFflCc9f4NIstO/l35sBgpfOGZYtO7c9AlE1dDYGOgHfIvcG7dGe9vz7jTFADm/n4V0ghq+T6CcDYzd1snP1vaWVJ7uhtrmqfvB2OaSj2l28leFyTNUfoeXh80SeMX4ZwdGsZEC7neEl/jKdvx5/ezRwno40pfNcG9+o/ilGATkXVuEmHB4NfqqYGveckhGbp4ShHjQPOSxHB5maHlt7OaU2fHLjVP8Fbth98qNfxJrbszGo74rkVCMdVbHbUZMdvoMkPbLS4qQxXJZ4F/erRVgHAtcLIimqCZ5nfTb6LESXRQMah1syXckSBKqPH9cmrYE9gmcSs3yTk67ao16wFS8Vk/WwLXg/TLbGnMS8NqyOtSnyNqnrozoyKr9R5YWoQ60Pc8ZN7jUjO0MXfbHcPH7VenY2cjoPLE5KSz0Zq+bqwRfxxMi4lsOj6ZsiZtk4e5j1Hdrk7rT+0xsxrH9c9b42EW21Q/Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c7322c3-23ed-45ec-3592-08d9f1ea0ed6 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:42.4446 (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: 7vBPghomhOcJT7PdKnjqOkepvYJny15ED0os5epY0ldOm/V+eyJHVhlnTGaf/2QJYKVDlPLFualurEiT1nV6jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: WfOUqO30bAbb6wMklBEIYweuZirRxQvu X-Proofpoint-ORIG-GUID: WfOUqO30bAbb6wMklBEIYweuZirRxQvu Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Determine the BARs used by the PCI device and register handlers to manage the access to the same. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/exec/memory.h | 3 + hw/remote/vfio-user-obj.c | 166 ++++++++++++++++++++++++++++++++ softmmu/physmem.c | 4 +- tests/qtest/fuzz/generic_fuzz.c | 9 +- hw/remote/trace-events | 3 + 5 files changed, 179 insertions(+), 6 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 4d5997e6bb..4b061e62d5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2810,6 +2810,9 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, const void *buf, hwaddr len); +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr); +bool prepare_mmio_access(MemoryRegion *mr); + static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { if (is_write) { diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 971f6ca28e..2feabd06a4 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -53,6 +53,7 @@ #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "qemu/timer.h" +#include "exec/memory.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -299,6 +300,169 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); } +static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar, + hwaddr offset, char * const buf, + hwaddr len, const bool is_write) +{ + uint8_t *ptr = (uint8_t *)buf; + uint8_t *ram_ptr = NULL; + bool release_lock = false; + MemoryRegionSection section = { 0 }; + MemoryRegion *mr = NULL; + int access_size; + hwaddr size = 0; + MemTxResult result; + uint64_t val; + + section = memory_region_find(pci_dev->io_regions[pci_bar].memory, + offset, len); + + if (!section.mr) { + return 0; + } + + mr = section.mr; + + if (is_write && mr->readonly) { + warn_report("vfu: attempting to write to readonly region in " + "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]", + pci_bar, offset, (offset + len)); + return 0; + } + + if (memory_access_is_direct(mr, is_write)) { + /** + * Some devices expose a PCI expansion ROM, which could be buffer + * based as compared to other regions which are primarily based on + * MemoryRegionOps. memory_region_find() would already check + * for buffer overflow, we don't need to repeat it here. + */ + ram_ptr = memory_region_get_ram_ptr(mr); + + size = len; + + if (is_write) { + memcpy(ram_ptr, buf, size); + } else { + memcpy(buf, ram_ptr, size); + } + + goto exit; + } + + while (len > 0) { + /** + * The read/write logic used below is similar to the ones in + * flatview_read/write_continue() + */ + release_lock = prepare_mmio_access(mr); + + access_size = memory_access_size(mr, len, offset); + + if (is_write) { + val = ldn_he_p(ptr, access_size); + + result = memory_region_dispatch_write(mr, offset, val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + } else { + result = memory_region_dispatch_read(mr, offset, &val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + + stn_he_p(ptr, access_size, val); + } + + if (release_lock) { + qemu_mutex_unlock_iothread(); + release_lock = false; + } + + if (result != MEMTX_OK) { + warn_report("vfu: failed to %s 0x%"PRIx64"", + is_write ? "write to" : "read from", + (offset - size)); + + goto exit; + } + + len -= access_size; + size += access_size; + ptr += access_size; + offset += access_size; + } + +exit: + memory_region_unref(mr); + + return size; +} + +/** + * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs. + * + * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would + * define vfu_object_bar2_handler + */ +#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \ + static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \ + char * const buf, size_t count, \ + loff_t offset, const bool is_write) \ + { \ + VfuObject *o = vfu_get_private(vfu_ctx); \ + PCIDevice *pci_dev = o->pci_dev; \ + \ + return vfu_object_bar_rw(pci_dev, BAR_NO, offset, \ + buf, count, is_write); \ + } \ + +VFU_OBJECT_BAR_HANDLER(0) +VFU_OBJECT_BAR_HANDLER(1) +VFU_OBJECT_BAR_HANDLER(2) +VFU_OBJECT_BAR_HANDLER(3) +VFU_OBJECT_BAR_HANDLER(4) +VFU_OBJECT_BAR_HANDLER(5) +VFU_OBJECT_BAR_HANDLER(6) + +static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = { + &vfu_object_bar0_handler, + &vfu_object_bar1_handler, + &vfu_object_bar2_handler, + &vfu_object_bar3_handler, + &vfu_object_bar4_handler, + &vfu_object_bar5_handler, + &vfu_object_bar6_handler, +}; + +/** + * vfu_object_register_bars - Identify active BAR regions of pdev and setup + * callbacks to handle read/write accesses + */ +static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) +{ + int flags = VFU_REGION_FLAG_RW; + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + if ((i == VFU_PCI_DEV_ROM_REGION_IDX) || + pdev->io_regions[i].memory->readonly) { + flags &= ~VFU_REGION_FLAG_WRITE; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + flags, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -393,6 +557,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/softmmu/physmem.c b/softmmu/physmem.c index dddf70edf5..3188d4e143 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2717,7 +2717,7 @@ void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size) invalidate_and_set_dirty(mr, addr, size); } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -2744,7 +2744,7 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) return l; } -static bool prepare_mmio_access(MemoryRegion *mr) +bool prepare_mmio_access(MemoryRegion *mr) { bool release_lock = false; diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c index dd7e25851c..77547fc1d8 100644 --- a/tests/qtest/fuzz/generic_fuzz.c +++ b/tests/qtest/fuzz/generic_fuzz.c @@ -144,7 +144,7 @@ static void *pattern_alloc(pattern p, size_t len) return buf; } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +static int fuzz_memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -242,11 +242,12 @@ void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr) /* * If mr1 isn't RAM, address_space_translate doesn't update l. Use - * memory_access_size to identify the number of bytes that it is safe - * to write without accidentally writing to another MemoryRegion. + * fuzz_memory_access_size to identify the number of bytes that it + * is safe to write without accidentally writing to another + * MemoryRegion. */ if (!memory_region_is_ram(mr1)) { - l = memory_access_size(mr1, l, addr1); + l = fuzz_memory_access_size(mr1, l, addr1); } if (memory_region_is_ram(mr1) || memory_region_is_romd(mr1) || diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f945c7e33b..847d50d88f 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -9,3 +9,6 @@ vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" +vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" +vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" +vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" From patchwork Thu Feb 17 07:49: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: 12749538 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 812A6C433EF for ; Thu, 17 Feb 2022 08:00:59 +0000 (UTC) Received: from localhost ([::1]:44480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKbik-0007dF-Gk for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:00:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYF-0004DT-Jl for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:07 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY9-0004TV-I0 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:07 -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 21H7nRW1010825; Thu, 17 Feb 2022 07:49:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=kIO7ytcQa1owSWvuHF9yUxUxfZyJkZcHwXlzyyoRPvY=; b=n8U2oyjO2Qh4jd9tFgzfHQoOmkEdoEeVnT1s/8oKejGuVVcPyN/3u2Ggx0tsWeDRG7rS qf3vWR9ldbif8SpeugE+x2nTkHFxpziZlz28hnhiO4mWReuYwi+ByNhefhrfuJWsV7XO kXtzLfQCfx3WSgW3Lfw1dfD/V0KzeaHpXn6WLtZYleQ6RrxAkjxca3iuwSYhFSyjEfUk IS80Y8fgtD0G5g/0Xsv4IuKWPGICtXY6dGnK8JWQD3ZP2CPKQslt3AlsUbykyuID4gp1 a/p3eGnBgA0ThT/x2KpndbBKAvrDAzhElmlIMQp9Ta5YiqkJ+ehSxpja049pUsbjKIKw bQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdmt40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:49 +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 21H7fJbN142777; Thu, 17 Feb 2022 07:49:48 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2048.outbound.protection.outlook.com [104.47.57.48]) by userp3030.oracle.com with ESMTP id 3e8nkyqrvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LzwhHTiIXhj+Su2oF1d8ImObgrdlmJxHf2XNK25Ylwj/di6XdcTO/s4ESEAoUERsLtq25KamPJshBldvD9yjDPc4HRsX0hyeSbaVyqWDd1vq5UgPfB50feAHiiVVvFh00CsakpswtM7hhFsMas93s6aIJrBFXR5VfQ3THnNOVBftbvRl1yaYSm3vhuqhPelhxJFhAeD/T7bcxUSsLqaHammMBSiDuo/GFbelRcXSFJD5yFDLfCCkgLn47fy4s3Db2MjxT5SRAuJZUa9NQNG7C8hXq7rbVGR+zakC5eQJFukX+kNQhnkRrsWNEqBXpMnK/9aIwZ8Hx+AETLCVdmNP2w== 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=kIO7ytcQa1owSWvuHF9yUxUxfZyJkZcHwXlzyyoRPvY=; b=DfbKXtB+CzKgwVp3BzI5CooLolRaRKFhjxvg3R0/tcySjFlWnWp/w+80Qv8tlcwiMq9a47OwJqrTrnCgm5iP0cyHZGeGg/S6POseJaZ389dY4fF99LYrM3rL/7Gpsb7IOtjyq6A/+tK0THPdefPuQhqrxoH5Zt32w7qQdaSXcTdGuTvpIsBveGza+t7oBNQkUyscXoyA08zO4FHcE2oIQU4fbgjyBHVlH0sxMr8Y27Vg3PzQjS1pnFEXEbX7XRlI8bECLmlBmdXPwbR2V41PMO4um2i6mdE2JGRpC/xfgw2w6JwjR4bmKRE1QoenWFc4gRNIGb8/KyinDoNf4bH8XQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kIO7ytcQa1owSWvuHF9yUxUxfZyJkZcHwXlzyyoRPvY=; b=QPNGQcXzlrmYcBaj4aIL+3TfcMGjOM1Qy7QFc2eMvu38YBKWu0nbBjFreG/fHHSBLbjI7K/S8hAJIbODNpJUfOuvyJwpP90SdsCj+38PzTG+kfIiP74H+xeTPxCTHlAEmgISKmbK+jDZuxF/uYmZj7cyhv+pziZxFJIlg168Q28= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by MWHPR10MB1374.namprd10.prod.outlook.com (2603:10b6:300:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 17 Feb 2022 07:49:45 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:44 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 15/19] vfio-user: handle device interrupts Date: Thu, 17 Feb 2022 02:49:02 -0500 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebee9380-aa07-4f46-6f8f-08d9f1ea101a X-MS-TrafficTypeDiagnostic: MWHPR10MB1374:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:172; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YL+hvOhaQ5garXFJ7hDgU7mt5aVwOVQuCUDOKpuzXDAwdpLOFuvKDP43l3k4zk8wbk2THfT2FRRaHMzz6WwPVATisHZ0uBc0lYy1Mb6bifwHkUtjhFOaAr0ne6/fj1D4EaUzXiXoDb66HuIpeYwURCGfO+KflFEoJ+/c0+pQf5kESM+m8hGlCLSb3eLEQrHV384NnOClXfdNbF0ojzwoDkyGFHuEvJGmZixBvCfflkq90QNjes9h7vNloYHTXFo7OVKrQyNv8YAwERGorj3SY3bJVtTmHUjhxAlhvGRvQCEztbKdkTmzvPYEojq3zwC2EOJb8/S6/PghKOU17t2qgURLZ4EwZ4AA7BIDDr52aNMggko4tLHuPVcO7sbTM+3ij/mf5P7yEscVj0lBg8EiBdM6qsDrmx30ULp8ODN3mTZBBK63fr5H19WKCsHaDsYhYqIHMpexWmU47EkPyLvpua56XbsXqEaQNc5TKMWC0pzav1Ktnu8tzDELFJgxeFLepLLCYG6D5QJvAcHxWe1MrnEzXa1+bbsBCpPzaiDTyBE7n2uxIi3lZUl0zwo9U3A6nsFWITGAoiJ5U08jLelT7l5El1VoZztrnOMWeFeC5DiVijcbc+2BsqhT9LK7RPTSNkzR9Digv0hjt/ls5x8Y+ezfXG5k4LXXx5glBCTdzkHAQwCXpNpxvpTaHWnwdC+8Kuiqivwi7FArr9nERJw49Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(36756003)(52116002)(6506007)(508600001)(86362001)(6486002)(6666004)(2616005)(6512007)(316002)(66476007)(6916009)(4326008)(8936002)(38100700002)(38350700002)(66946007)(83380400001)(8676002)(2906002)(186003)(26005)(107886003)(5660300002)(30864003)(7416002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ANtz+GYlKh13Etd5UdLSZ+qF6ctWCxJQn0gTX9mqb99eKyjUM3gI4a7DR1qjMuZ3SxGEhsaaZhFNA2TbcvRlIo5oVdu1xBN/IjEmVgkoL0TpKlrb0SEdX1p8N+7PI1U0pa6MXtL+D8WmXTDC4phwcl6/ly24Ur2RpfNagse7fCRyXfCou2Gk07a8hnCDMe+HTDnBhMayXCYTRselGGqrKRjbf6b4m1pjhpK7F87d3l6OFnElsoe0ytHVXKoUqVgziZV4MWofoOyiqxJAi3CaWjW3DfckdrLEdSuYNY8MPt5VipR56XxFZGnrl4Z4WgsalzM+x90sCpxOXJzp9LQ1nu2FXx8334G3HUCaqG3KTZkIx0yt5RYCALaNvCE2GxWAKPvD+XJQwHA+RRhPh/wjd63Vsco0dq1/QwKuMNIwSteOsyliqZSUGkjmSyQ3C3NEjThRpVunHa1ACnfbuuPV4cM+cQON0xcLjz4icJWr2JVKKVUGihPMTNE6VDKsv9Ixjq2gFhBbx9pSJbEikn0VgHHHlMWu+7IgU6jpTSVQ8elodGerkcusWpQWA2vYz2XO5L7Wv/Fv90XnMs4aCKRQaRrbh06iP0+iORlfErqROcaKrrdDc0X4y3ozcQe4ZPb2g64jETn9LZoyzjnx/LMHOOoXFPvgGDivtvpZqj7bSojtrTZc6gweWVjcAIA4+3Yu15xyt1cAUC/FYvNNzOQbmZyzE+cEem6b36CQpx76AW5La04hET4zJ1aj6yzJ6s3ZbNF/sI2pcUIUuvwCPD2R01+UtSXzODYcgG8YZHjOtyBVJ84BbmW4y1sM2TSX8W0WsNzZFFz1qPvNh8IvLSKdMZk2eYXR8gz1W8NGHyx8yFFIObfOk0aWrSbQxNi3uhuQtslja8FaQZrPNoW7eJzRUjTeer5RcxZa+88mPC9IPze1kCSecLAdwe32Rr2zWpaq4AojlTHRBOXGEEGQ0dsQPRg1pGYvKKZalfKqBHfv98vpFa6SqiSlf7rXnPHtsJUxSwN2ADIFzRGAqQTq+LK3Jz+jE/iwZnN0RaIEUiqWLaT8pTo+rsKSBzGEuIs2556OJ9gDvTKOml/cRYfWjZVnLL7yxSMCxsNsFzlKtKIdybMmJ3Qwli96/DN0LpCz6IU869Fad7YTuQUeroJAUlFTGNnPXiR3fpezTNe2LeI5vGJSwCQ+/pkXiMI5/ED8A0AjxtBdLS80txb3a0KcVsHsdBZ9glMr67l/PZaYL44YfR0ta1bs/+iVCc4gt7AG7EJiHIec0DdA9RDj98NlNjC5sLzoVe23QiNx83kRugoqg3lKWS1idHaz+1tTdobqVqQSnwIRy7n9aC4Rpqb1jThh6EquCCw0fL+2UMuGSXVvcCHFdnKGvmRns32y1MutADxhTobg/KqpvhTpGkHAvFNO7AQDU7+3iMyuupI5PS+apTwRFgMwPG7zbWM5b3ckjIObcxr+OETVLoETeny4ZCoM2yzJbXgXdpMN+fYiW++qzf9LuR2x5wfc28uHoUJ4PRG52+SRJnFEDoyZH3/J9H1FH6kbcM+t1BsidxfDCaTbFeccKvu3kglMMamteZRQMTl8LffNeW6rIEx3tMw1QXG/NMwDcU7uyRyOdQK0VxCZlT8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebee9380-aa07-4f46-6f8f-08d9f1ea101a X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:44.5538 (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: em0QN9Dv13RdC/8Pid8C+nvoiQaY/EEEIby7cYIARjbtIGFCX2bBKShUYfsfkhd1y6Qw7B7p8qguj5ASs/gekQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1374 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: -rJ1K-pQfD7mu8lH2kXrmqTxuaXpHS9w X-Proofpoint-GUID: -rJ1K-pQfD7mu8lH2kXrmqTxuaXpHS9w Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Forward remote device's interrupts to the guest Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/hw/pci/pci.h | 6 ++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 13 +++- hw/pci/msix.c | 12 +++- hw/remote/machine.c | 11 +-- hw/remote/vfio-user-obj.c | 107 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 10 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 include/hw/remote/vfio-user-obj.h create mode 100644 stubs/vfio-user-obj.c diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index c3f3c90473..d42d526a48 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -129,6 +129,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 */ @@ -323,6 +325,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/include/hw/remote/vfio-user-obj.h b/include/hw/remote/vfio-user-obj.h new file mode 100644 index 0000000000..87ab78b875 --- /dev/null +++ b/include/hw/remote/vfio-user-obj.h @@ -0,0 +1,6 @@ +#ifndef VFIO_USER_OBJ_H +#define VFIO_USER_OBJ_H + +void vfu_object_set_bus_irq(PCIBus *pci_bus); + +#endif diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f33c..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/machine.c b/hw/remote/machine.c index db4ae30710..a8b4a3aef3 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,7 @@ #include "hw/remote/iohub.h" #include "hw/qdev-core.h" #include "hw/remote/iommu.h" +#include "hw/remote/vfio-user-obj.h" static void remote_machine_init(MachineState *machine) { @@ -54,12 +55,14 @@ static void remote_machine_init(MachineState *machine) if (s->vfio_user) { remote_configure_iommu(pci_host->bus); - } - remote_iohub_init(&s->iohub); + vfu_object_set_bus_irq(pci_host->bus); + } else { + remote_iohub_init(&s->iohub); - pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, - &s->iohub, REMOTE_IOHUB_NB_PIRQS); + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + } qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 2feabd06a4..d79bab87f1 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -54,6 +54,9 @@ #include "hw/pci/pci.h" #include "qemu/timer.h" #include "exec/memory.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" +#include "hw/remote/vfio-user-obj.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -107,6 +110,10 @@ struct VfuObject { int vfu_poll_fd; }; +static GHashTable *vfu_object_bdf_to_ctx_table; + +#define INT2VOIDP(i) (void *)(uintptr_t)(i) + static void vfu_object_init_ctx(VfuObject *o, Error **errp); static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -463,6 +470,86 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static void vfu_object_irq_trigger(int pci_bdf, unsigned vector) +{ + vfu_ctx_t *vfu_ctx = NULL; + + if (!vfu_object_bdf_to_ctx_table) { + return; + } + + vfu_ctx = g_hash_table_lookup(vfu_object_bdf_to_ctx_table, + INT2VOIDP(pci_bdf)); + + if (vfu_ctx) { + vfu_irq_trigger(vfu_ctx, vector); + } +} + +static int vfu_object_map_irq(PCIDevice *pci_dev, int intx) +{ + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), + pci_dev->devfn); + + return pci_bdf; +} + +static void vfu_object_set_irq(void *opaque, int pirq, int level) +{ + if (level) { + vfu_object_irq_trigger(pirq, 0); + } +} + +static void vfu_object_msi_notify(PCIDevice *pci_dev, unsigned vector) +{ + int pci_bdf; + + pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), pci_dev->devfn); + + vfu_object_irq_trigger(pci_bdf, vector); +} + +static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev) +{ + vfu_ctx_t *vfu_ctx = o->vfu_ctx; + int ret, pci_bdf; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + ret = 0; + if (msix_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ, + msix_nr_vectors_allocated(pci_dev)); + + pci_dev->msix_notify = vfu_object_msi_notify; + } else if (msi_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ, + msi_nr_vectors_allocated(pci_dev)); + + pci_dev->msi_notify = vfu_object_msi_notify; + } + + if (ret < 0) { + return ret; + } + + pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), pci_dev->devfn); + + g_hash_table_insert(vfu_object_bdf_to_ctx_table, INT2VOIDP(pci_bdf), + o->vfu_ctx); + + return 0; +} + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ + pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, NULL, 1); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -559,6 +646,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o, o->pci_dev); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup interrupts for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -612,6 +706,7 @@ static void vfu_object_finalize(Object *obj) { VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); VfuObject *o = VFU_OBJECT(obj); + int pci_bdf; k->nr_devs--; @@ -638,9 +733,17 @@ static void vfu_object_finalize(Object *obj) o->unplug_blocker = NULL; } + if (o->pci_dev) { + pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(o->pci_dev)), + o->pci_dev->devfn); + g_hash_table_remove(vfu_object_bdf_to_ctx_table, INT2VOIDP(pci_bdf)); + } + o->pci_dev = NULL; if (!k->nr_devs && k->auto_shutdown) { + g_hash_table_destroy(vfu_object_bdf_to_ctx_table); + vfu_object_bdf_to_ctx_table = NULL; qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } @@ -658,6 +761,10 @@ static void vfu_object_class_init(ObjectClass *klass, void *data) k->auto_shutdown = true; + msi_nonbroken = true; + + vfu_object_bdf_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/stubs/vfio-user-obj.c b/stubs/vfio-user-obj.c new file mode 100644 index 0000000000..79100d768e --- /dev/null +++ b/stubs/vfio-user-obj.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/remote/vfio-user-obj.h" + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ +} diff --git a/MAINTAINERS b/MAINTAINERS index f47232c78c..e274cb46af 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3569,6 +3569,7 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 847d50d88f..c167b3c7a5 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -12,3 +12,4 @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" +vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d" diff --git a/stubs/meson.build b/stubs/meson.build index d359cbe1ad..c5ce979dc3 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -57,3 +57,4 @@ if have_system else stub_ss.add(files('qdev.c')) endif +stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) From patchwork Thu Feb 17 07:49: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: 12749574 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 4DA76C433EF for ; Thu, 17 Feb 2022 08:26:22 +0000 (UTC) Received: from localhost ([::1]:43192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKc7J-0001jB-9l for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:26:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYD-00049J-Rt for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:05 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbY9-0004TX-MK for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50: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 21H4YPWb005266; Thu, 17 Feb 2022 07:49:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=qd/HghLhnXj4tRPCu6B6TxV6jE+DPov8SM1cEPYB25o=; b=aLAxYKnYnD8n8BRV63bwVLYQfTiUpwPY9/Go/0F/KwpjYTJ7sVtWfb44+9Xh171txsF2 RiCX66wUrWZ6c1rbcNp0WCKGqmJeuxLRP6OXrmA1l+trIA1I5R3NW0vz709R4I6lH0I6 hHSNTCZPDwhzek8kmB8pK/LRFFYnrQvCGVKluL7kIMV8psETCvxXbkn1aZfGL65WbmDh nzmOgPvwtwkMgJ/44mm2dwQKDEAqR9v5TykqStVSEK4veAFRfCHBI7d3qRhmC6TdyZTu AW4ElJD99rMnQZYPFCnwj2HsDDzWoE4CbYz+Oen9D0+On64o8PDSL/WrnUejtjXeP3Fg qw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8ncavqy6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:50 +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 21H7fJbO142777; Thu, 17 Feb 2022 07:49:49 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2048.outbound.protection.outlook.com [104.47.57.48]) by userp3030.oracle.com with ESMTP id 3e8nkyqrvp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nL87cWeifC25gM1VsD+b2ROTtZIdcYzhCooSLR72HtYKBR5tBEDKiBcFWcl4YaZsOi+ZQknmAFgbEC44y1ZjyztJx3IG5mNj1t031mbfJzyTl+tCP/JRwjvO+M5Vg7mf5XjM5ThUywinPk6DvgUJmwFE18wS4k08rKoumXq5ucv79h1FW6T03Ugi4S3+XAcQKq5Cw4O1rENH5IlGzHVsChIS2EbJu+eL0PiIG5CqbmpKo2KMaiwER7bP8TFCQM73RzFtW++0qpNrVyvG5uNXWOATOUmkBbIYV9PrwZjZG0alfp3+CEU3FVBc8UvEukaCeZeE4PwulQ7QEYSM3oylMw== 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=qd/HghLhnXj4tRPCu6B6TxV6jE+DPov8SM1cEPYB25o=; b=edHwOzFu5wkWS5Clk9fCOwgxscoSHHDgzRospZQblBBCQ7t2bMm+4p2a1m4SBsRVG0RlqjFDf5mTgGxOkk5fqTUAi87JD6g4zPko0viliT/HlEt9wr8xc/eHuae7LaC5/oRhlihqhothj9725nYS/MWrXI/zxzwbNvBNGC5RcI/se5LjIKywRBuQfV3N+KdxD/LwjQjOu3Qq96JnfhSZkPTk6X+/js4xJr+R9zD0czhcNGavaWwwT+fz3xW6ctzewfOLEFr18cCeOa86jFuB17qCheuS86CqbaGzvEfCZKd4+onuEBwfLZcKhQyFf07NKjDeKR4tKZg7WVZ80DQ5qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qd/HghLhnXj4tRPCu6B6TxV6jE+DPov8SM1cEPYB25o=; b=YfvCWNjxYKD9S1CopGD9PYHZP+2cIMYblABSHlQf/wO80bfGGJZptDQXlm6yddUeqtHsHXJbA59gHTXzVaP7QNTNRJgi8h3chkgPpPFdlCtZBRiFdD0qonaYkuTwtLoUApuUjz3OndU+nXSv4dHnDIdPHMu37RUA/h0lKzQCdwk= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by MWHPR10MB1374.namprd10.prod.outlook.com (2603:10b6:300:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 17 Feb 2022 07:49:47 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:46 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 16/19] softmmu/vl: defer backend init Date: Thu, 17 Feb 2022 02:49:03 -0500 Message-Id: <55fa22ea0e82b204ca3c5ee2fc4b9b3d2c1669f6.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ce71d95-0071-4924-0be6-08d9f1ea1161 X-MS-TrafficTypeDiagnostic: MWHPR10MB1374:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +dkPI9qTPb0ExWb6xQ0KyFhmsfjeSL1hCNAI/dgW2KPofk17WVhr/o/C6BBqEnI+Nvct80wknUnV/6ZZvaV4b4vTGulafbs+BGqvL76KWkNYQxtTqd0m0EVxr54t8t+UGfYdPaTTts7Cwq2jfx7y5JNmjPYrpae/XRDYCgJIbV2qZH3I8/JqNvw1aoE5e0c6bU3/CuQYDJ8vpbwpG8uFOU1SVg7Q96kQHtvJR2rnjbIlKIpT13v0qmdrVxC2u4FZa3zn3G34a8AzAfjLjK7UBtlFogex6p931q+x82E/3T5Tb+h/76XpZSWSxq8zX+2BR5Tkx01peRVcSi1j2mGoUq1Jxa3X0WZX+Ij2t1NJwkTUQk/x5z4NEJI9inAbS9G0jSGs9G2dYZJeO3J0FDru4KpTPEnd5PNXWpPV2a4QqCGig2/beTpCouhFG4y2WzBxiSBkW0iV7xotkRHl6V2g9zAP6xe2yS5QItx+KPNNaWEnc4XGBweKnFBAlCJqvRYQ0bMp65f3FiYS1MxtPelOlq6QPJPNDgQdxf3R2lwLvxZ2nAqdoHTTRgD+eE6BxvIbwniAfLDpIVV5xl0jzxalLdst9YxQ5g3/5oPSVAsSOHanfyz//qS75tvveISPmSQKSmFFsVuTpW+Y3JudYm2t60kQmLqini8daovuIMLqxNqGaFMFEd/TmZEvcIaFgw63gus17gnKeVqRdXzxtH6cqA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(66946007)(2906002)(8676002)(38350700002)(6916009)(4326008)(66476007)(8936002)(38100700002)(7416002)(5660300002)(66556008)(186003)(26005)(107886003)(86362001)(6512007)(2616005)(6666004)(6486002)(508600001)(36756003)(52116002)(6506007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j33GUCK8j52/yCSoH/QV1ymh+Yg33Fb3xGW8VTnv3blA8OBUEIFC/vdC2oYvEpZ8GaHq/1sVK64UJLNrH9oxfjs8VYBL11/c8tonNjt42tH0xPesuNvaYeia3i77HQXiNunlGDB9mzJfcTOoS3i97DZG9HQE2pyPL9h12LCFHwwZvET36nE+ofSl9i7MphyWyWA5vSFJQrUcJXX7jeUS64FVox0FZSs3LeJjWt4M4okvFZ9Ivb6AVjCUnzZUHyfEtv5iME7K82u2vZmoL/DgCmz7vMPkh6dnMLcN6Krit+4wrcsFtfge6gX84KOLloTDIXGWXofVDGOfwF/QJtdv3o3TNP2kjtJ69YNT0yypSKUle19t2+4XYGYwlgIBG7TMenHdmUmbcRCBuYaZcth20hy9bFw1kUIBpnmEzGFsEJyx5xdU0nByKBg7h4xfSvRkEsk7kmUnRZeTYItQmYOYh1m5+zauQfNZVHlJwvOOcx/gxViYyB7RdR3VXr6856mjdR1xocprqtPLmQzVpVqqL3bdrVim8lIYYsLt9MdkGNRp5cytTlVNcF870iylGveZ5ueVdk1hwHlKXAXsc+s0pOjtSiQHoMbPolhFm7asQSStsIYZAx2T5PWVsKqktEGd4YtJJLDLBKMoaMeM4gr9DrETptAYUhYBgZRiuidE90n+YmIU+jBT9I8kQyehga0yte6eN1+hCZVWERei/+TQnPQn5YMdxyPWE/2UenkTVnPPFQzW5kpEqooLZIFDxk9fSxWwg+hkX6v/DOtarRDzkwc+jDhFMiM/E1xPGRF6Sw+c6XncL0UEslbwmZ4+uT9g67ppFfAQc7R7zHMe0u2czVWL1RI0FBKb4oPy4S47bs8aXAsPCc8fpzD2pKcBFepc9x2UiUnVQuT6gDgTDKR9xE4pWgf/G+K8MIJosFk7VpNx5luXAQlBpt1uA0HD/9AW+eTx83QDx2bO238gjLwQ/Hn5YGbmqYRk6cKsG/0Vu8YCYzILcUJC+GTmY78JyjHopBueQDWZr6K3HgxdVswUFuqGi4qov/KbUas3XA0y0uKGq7BWsbPQ/pIIQZpUN1eseHJmSL+6U3hMZbnXaNOEpINaoatjl5mf14reMEk4NeLyRasaRQpezyHYi0yRtxn4iwyPbv5YWrPHOs1nMvszQWT7qU23YdBWc/LPwwPZKvniCp374LEt1er0d8w8REHWutyHC5SNQ1RXP/WDCOjQjkqlxtLHmMwg9VKCmjH4/JKqUI9oDrqTc7P5vNmaz/Y+slz1hQyyBupPrXngpxCucKPaS1sePPOGCL+YJwdNy1COdMUoDPg0ZWVTRN/dUEOVRLdPSOM48uEfPMbU0waqPqs4NHhUKTePthlk/FpMsLAU6Fli00AldBctPcXOMHlmttYtxvZYYKANWHbuEWPmupQDts/YYk53FwUW2oksazs49uIxuv8IayNHcJj5XKXy3OzkWVIG0wQKNm5jtVCTwwdkV+v+atwRhC1vlA5/einYxGZTX11ud99Acs81kN+y3lBsdTci1LaQ2WPrOcNvwbD7K6dQdA6Mmqhgf8qfacCuv4k3FBGqA00P87wx+uqJto5Oz3NKFWdl+IPD9Q3hbWWyEhK/ucRr1bXDrOC2gTU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ce71d95-0071-4924-0be6-08d9f1ea1161 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:46.8505 (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: qKXNvilabzuhA+o1YGY21FeMwJ2qp79rcWIy5Q67eDGNR+qKXrTSxhGWpbHJRSgLhSrR3bwYkU0SwVYxM68BdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1374 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-ORIG-GUID: MVBBGVO7HnRll7qpUETsowwc_gatjDPO X-Proofpoint-GUID: MVBBGVO7HnRll7qpUETsowwc_gatjDPO Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow deferred initialization of backends. TYPE_REMOTE_MACHINE is agnostic to QEMU's RUN_STATE. It's state is driven by the QEMU client via the vfio-user protocol. Whereas, the backends presently defer initialization if QEMU is in RUN_STATE_INMIGRATE. Since the remote machine can't use RUN_STATE*, this commit allows it to ask for deferred initialization of backend device. It is primarily targeted towards block devices in this commit, but it needed not be limited to that. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/sysemu/sysemu.h | 4 ++++ block/block-backend.c | 3 ++- blockdev.c | 2 +- softmmu/vl.c | 17 +++++++++++++++++ stubs/defer-backend-init.c | 7 +++++++ MAINTAINERS | 1 + stubs/meson.build | 1 + 7 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 stubs/defer-backend-init.c diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index b9421e03ff..3179eb1857 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -119,4 +119,8 @@ extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_semihosting_config_opts; +bool deferred_backend_init(void); +void set_deferred_backend_init(void); +void clear_deferred_backend_init(void); + #endif diff --git a/block/block-backend.c b/block/block-backend.c index 4ff6b4d785..e04f9b6469 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -20,6 +20,7 @@ #include "sysemu/blockdev.h" #include "sysemu/runstate.h" #include "sysemu/replay.h" +#include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-events-block.h" #include "qemu/id.h" @@ -935,7 +936,7 @@ int blk_attach_dev(BlockBackend *blk, DeviceState *dev) /* While migration is still incoming, we don't need to apply the * permissions of guest device BlockBackends. We might still have a block * job or NBD server writing to the image for storage migration. */ - if (runstate_check(RUN_STATE_INMIGRATE)) { + if (runstate_check(RUN_STATE_INMIGRATE) || deferred_backend_init()) { blk->disable_perm = true; } diff --git a/blockdev.c b/blockdev.c index 42e098b458..d495070679 100644 --- a/blockdev.c +++ b/blockdev.c @@ -569,7 +569,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, qdict_set_default_str(bs_opts, BDRV_OPT_AUTO_READ_ONLY, "on"); assert((bdrv_flags & BDRV_O_CACHE_MASK) == 0); - if (runstate_check(RUN_STATE_INMIGRATE)) { + if (runstate_check(RUN_STATE_INMIGRATE) || deferred_backend_init()) { bdrv_flags |= BDRV_O_INACTIVE; } diff --git a/softmmu/vl.c b/softmmu/vl.c index 5e1b35ba48..9584ab82e3 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -496,6 +496,23 @@ static QemuOptsList qemu_action_opts = { }, }; +bool defer_backend_init; + +bool deferred_backend_init(void) +{ + return defer_backend_init; +} + +void set_deferred_backend_init(void) +{ + defer_backend_init = true; +} + +void clear_deferred_backend_init(void) +{ + defer_backend_init = false; +} + const char *qemu_get_vm_name(void) { return qemu_name; diff --git a/stubs/defer-backend-init.c b/stubs/defer-backend-init.c new file mode 100644 index 0000000000..3a74c669a1 --- /dev/null +++ b/stubs/defer-backend-init.c @@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "sysemu/sysemu.h" + +bool deferred_backend_init(void) +{ + return false; +} diff --git a/MAINTAINERS b/MAINTAINERS index e274cb46af..1f55d04ce6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3572,6 +3572,7 @@ F: hw/remote/vfio-user-obj.c F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h +F: stubs/defer-backend-init.c EBPF: M: Jason Wang diff --git a/stubs/meson.build b/stubs/meson.build index c5ce979dc3..98770966f6 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -58,3 +58,4 @@ else stub_ss.add(files('qdev.c')) endif stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) +stub_ss.add(files('defer-backend-init.c')) From patchwork Thu Feb 17 07:49: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: 12749585 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 D59BCC433F5 for ; Thu, 17 Feb 2022 08:31:33 +0000 (UTC) Received: from localhost ([::1]:49840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKcCK-0006KB-Ou for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:31:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYK-0004Ik-7D for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:12 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:26594) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYD-0004VR-EY for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:09 -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 21H5fpN1021438; Thu, 17 Feb 2022 07:49:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Ln2I2S+WE/9HtuzS4q2kAH9axvHFH6hmePIDwdjSsMM=; b=eLic0mtruPT6eEaqwmblyhhCI2Lg/yI1spLQHZpipmsmbIgtIyotW1A7G9RQVORmAiuO yPEztAiad4T2BtSqZiHvNSdp2vRV3wuFYFo+szLr7Zdri9oaBn3lBFdsegXjxRfElIvQ f9XGzMbvBorqMBSFUi6zC35to7M1Y9zgwnwoHJeuUved4NXpTHGL6uHkABX357BqOMxm bjbxFUaoyiyCRenmQwMHV2/xke9oj4Rw+X53bUOqaGvRtX18/OEFJJPQ7BgAth/M9K0O Tn+ajQxklCBX32zDFl/OU/vid1YZdRH2fcdnuEjwBfSJFTidsVA8wBxBQl4wnEk4geB5 AA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8n3fcf9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:53 +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 21H7gatm136179; Thu, 17 Feb 2022 07:49:52 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by userp3020.oracle.com with ESMTP id 3e8n4vje64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ROXt1zz/4UI+aaRMVTcvc4h5surtbWyTT7/NrwLXRp+f9C4Uc48+NVbxNdF+srqwAN+AX2a0CNacVdYup5A9325bP+0GpvFMvtYL8Myze3VVZORtcaVZa8GQVXBynkQ+QMsXk9aLGtiLclZax9GAbyqhaKDDJWCYy9rVkrKzf9flWOCRy11E23tNwH5XKMirEguVfFkUUAIBaP/5qgelKo94bJe8WUOEmnFFyhRROIJxTZUADBvDH8NyBnTBEv1vq2B2qrKVQfhupuLTxVPRsI5P5Fw/s+TIIOynO3a/RStl6GeRedHrTLkX5uHWaRzNji8ngHoPRx7u+2NYwVauYQ== 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=Ln2I2S+WE/9HtuzS4q2kAH9axvHFH6hmePIDwdjSsMM=; b=FnKuOoRCojLacoRIniSX8btW81M7i4aL1r01TWS25NfOfQFcnRVDrncpEhGNmior0lzzSdrBNxxlTtm5bpqblnlixNzyfh3qevVpRpeHR7i0m9OJnS/FZHpUSnSkZnlWfhbk+hSzY3nDcJwOxeUI7S6TK1haYrpb2Qeu9WNEU6TQmqtJFSpBrt7JRHDPgERhpw/qWfNAOULsJsyu8lgXRVpOAh6/sxRXoxaGr2NZz/wYJKzCtE+DyAzhb58lsi2ySFWsdy6vCFn6W7NaPKVgdcaAWzOS6tYw8t+bsMQFontdwj2poHQoMKK57cd63wzcPqy2sohdtB3sNxCDj1KIww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ln2I2S+WE/9HtuzS4q2kAH9axvHFH6hmePIDwdjSsMM=; b=vwRPL8OIB51ZweVmetV0K2c/Bg4qOZfP43ALDHS4miOFNpxybUuAwEk5/Y+AYexhGUBkbCfuIjYuyUvSyUWS3SCHauClJucswIlP5Uys09JIqC5e/oi+A3OzDXojt7rxPJl7SEfl2RK3hC5ai9AF9rEAMaCTdd7UQWqZMg97INc= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by MWHPR10MB1374.namprd10.prod.outlook.com (2603:10b6:300:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 17 Feb 2022 07:49:49 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:49 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 17/19] vfio-user: register handlers to facilitate migration Date: Thu, 17 Feb 2022 02:49:04 -0500 Message-Id: <2f2921668f8b3d05bb1ce1dcc10e90e61cd20405.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 26376465-3faa-4f10-1d12-08d9f1ea12bd X-MS-TrafficTypeDiagnostic: MWHPR10MB1374:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aWo3vJefuLGd6YLkpVQTSmU6hpJrVGhEJu4gsoRbnhaHJikIIzdCQGVphOkuF/PU7z2KdvBGpo9zlZCmH6XDaqCH/8UIV0UKonVTuOQQ96U+ohc/TLj8UAPiLZ/AXJvmuhMANo4X7d+uV1G49UCBE1vv0o40lRLjzpQBo77TttOCudCOkW7sPCBsJPqYBlARn4eHYC1Nk4iXNJhcR+QkLwpjH3yi7P0Qv8bFz2ABCqEKJsrDHmVaz/AzFvQZ+JFltDk/CI6med41Hu0fTf/t3DTznqvFF9HQ7o/5FLjlzLGYP+PWf4Ow+KBhdhoFpvVclwyb1FamSlnAFAU1k8KHXhyNSdi0RfbW9UG8Oiu78UJ1UcDBOS6MjS/rXFTmkCp1K38ma6EuPulBHFjkJs/BefgIynFawPobHrvNfzuarlkeMFqMOusn7nhA5Zrio9oIfrmWSFHB8hjxC62SbJs2vhULpGtClRIzZJNQFM4w8o3D3rjgwmP0YZsmzZVRJExC6Jjuk4hA7SJMykaKbO+0OS6/JN6BcIgsqO/FNUSM+BZU3ZPdCY8IMyqUhgQP4ni8hr5TAURM49DaCHYYQYRUDBezDI31xzuZTDB93q5gt42L3szA8mPa2XILMbszNvQugkueYgSN8rwb/uvQ/AsRd7NPjdWqKe/HCfs0oZ6DvktijlhowjC0VmKKzkNLUbc3umZhWDyaGZ/DxxYSw3YCjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(66946007)(2906002)(8676002)(38350700002)(6916009)(4326008)(66476007)(8936002)(38100700002)(7416002)(30864003)(5660300002)(66556008)(186003)(26005)(107886003)(86362001)(6512007)(2616005)(6666004)(6486002)(508600001)(36756003)(52116002)(6506007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AvFi+AX8Qbte77YBefT6j1yIvyrHw0/HQ4hDdGSqd1ysfbKw1BZ+rSpbdu8WeNOHmhyQrtBgWRghC/wUt5IPT50R2sxXjz0WyuXAkuoZ2qLStTbHbEENLj2OXxTMXwk8PbS1acAmzJ+zh9Vhu9UlAXYRL8p/umlRGuoqEqJIQ+QX70t2XELnIqouJpLywEdpJfWjbiJgbuVitfgpgLnbVvQisTtgJpiuWbdalsmoCMj050XDSrep5G8hZHQjMM2CmqmAEHqk079yFdHXXpmDA8WV5dXPct3IhnzzpRXw3C9BxipC3sD0acqvu9SmP6TSoTDNwK3cwLYoKTlsESdv90+QyTUOCipjavWzLbzGuCibhpnF1G46hqO0oxUfuKMQpOhmJgY9ZKREBtdto1OcsQIe+U398bZh8ZKDAOtYphBF3FQKIwrek32sf1yS0fjvyqyC7N4h0tNSs6AwhDayoJtoAB8Lvys5rLTHXhuYmW10tLhzNk6zMsNsevpjbM3IqVzMXaSFGIUJZatlezWzl81hS4RGA1fyW6CPAx3uKfXVWOkvp1SzoiVComu2btvnrXCGjWi+1ZNZF643UaXELH0359kvbRgXAOrxClr2RZMVcqjVe5nrG7Ar6wRoXy/H+WvyOvREa5N8uiMhmSHvgBTi+N8IeRI4L5Qbw0hWfoFwRI17nEpubj7LcofR3JbCZGSA8G2XcWppWJHWFfgVQHa5wpbk6buNRg6XWSjsLhqGnCQI20lkAAf27E13278VSqXGVfxYC07MXwgod6FbgyI0yT7vZwBRpmfqSLH1/Yf3Gt3wR582WLxCV2G1ZJLnPa8uG9VPDcM9WQjQiWSnx2+J1xRrtfBTMniGIBioufuzvXWLF+UH4VkyeObuLIusyZ2dzV9kx0Ly/cbHN5chxc/nN093PGt1vElN3LNOvskhc2yJpHBSk99l/eSiXODJORjlsZT4gu5N/rxZ7DrQ/kkR4cL/uNai8eipQ+cby07rGtO1kG/5JPLMHwzGNaCpWNBCmlWMZPcqdQGu1CNWLOy6wzAXOTdbV7M6lDmWcRW80CJd/hG2lWV7VbIszu+ZsEicghXRZqsnMhL9FxWxQ108m2d1VPhDlN6EYoMi9+7nh+RNvvbpU1A8GnXYT7klmy4qvagUi66LkyC1BhXcj1D4FgEIseoTLeEFwOUL6cGIi6lcl4Vgy/nJDx8WFXpz7H1xFUEBJe5b30cCN09G9xc9fsBCSN78x6njJMzrBKFX78DoGFZ/H8uMwpHoo9OoLjm2ssrnS6IyUBHHspN7JzXHL5qiwqqIef2XH10lDDe469GloKg2jy+xpYhe3aBZMV3oxevOidnuoBr0URW3qKCRPCGcIzlvg90y9C07bEBoeC6Cw+uGq2gm0v0fgZQacZzsu3Jpt0jKTqzKS+auTMvYNDARZFNqQrx26pxefzFHtJwzbwJ46qIJb29k/rHfovnYq7tuGqOTtWFW/lXW7HRdvWuCWVGET5exoI5c8PlCW1okfAHOVoGw1ZjHlFoTWKyFlqWxAxKLWFQL8y7QFyTNy3KnbIqf9YNGCk8+ddYssoaivmEXrveTS6RPfDCSuqVOo/M/aUDgtHx+617Rnz05hOYHdUzgWrYbgJaHr6g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26376465-3faa-4f10-1d12-08d9f1ea12bd X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:49.0379 (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: V2GOj3JVpjW0fW+Ftyb3kNwhe7aE9NJXKSi9zlfONKg3uRxREExzi3yky3oeQpop2XIyj16luKkt8Y7Xzc6hGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1374 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: yfjf9VDf3fOYvN6LV_2OmdKTeNYb0I4f X-Proofpoint-ORIG-GUID: yfjf9VDf3fOYvN6LV_2OmdKTeNYb0I4f Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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/block/block.h | 1 + include/migration/vmstate.h | 2 + migration/savevm.h | 2 + block.c | 5 + hw/remote/machine.c | 7 + hw/remote/vfio-user-obj.c | 467 ++++++++++++++++++++++++++++++++++++ migration/savevm.c | 89 +++++++ migration/vmstate.c | 19 ++ 8 files changed, 592 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index e1713ee306..02b89e0668 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -495,6 +495,7 @@ int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); +int bdrv_inactivate(BlockDriverState *bs); /* Ensure contents are flushed to disk. */ int generated_co_wrapper bdrv_flush(BlockDriverState *bs); 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/block.c b/block.c index b54d59d1fa..e90aaee30c 100644 --- a/block.c +++ b/block.c @@ -6565,6 +6565,11 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) return 0; } +int bdrv_inactivate(BlockDriverState *bs) +{ + return bdrv_inactivate_recurse(bs); +} + int bdrv_inactivate_all(void) { BlockDriverState *bs = NULL; diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a8b4a3aef3..31ef401e43 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -24,6 +24,7 @@ #include "hw/qdev-core.h" #include "hw/remote/iommu.h" #include "hw/remote/vfio-user-obj.h" +#include "sysemu/sysemu.h" static void remote_machine_init(MachineState *machine) { @@ -86,6 +87,11 @@ static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) s->vfio_user = value; } +static void remote_machine_instance_init(Object *obj) +{ + set_deferred_backend_init(); +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -105,6 +111,7 @@ static const TypeInfo remote_machine = { .name = TYPE_REMOTE_MACHINE, .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), + .instance_init = remote_machine_instance_init, .class_init = remote_machine_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index d79bab87f1..2304643003 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -57,6 +57,13 @@ #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/remote/vfio-user-obj.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/vmstate.h" +#include "migration/global_state.h" +#include "block/block.h" +#include "sysemu/block-backend.h" +#include "net/net.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -108,12 +115,49 @@ 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; + + uint64_t vfu_mig_data_written; + + uint64_t vfu_mig_section_offset; + + QEMUFile *vfu_mig_file; + + vfu_migr_state_t vfu_state; }; static GHashTable *vfu_object_bdf_to_ctx_table; #define INT2VOIDP(i) (void *)(uintptr_t)(i) +#define KB(x) ((size_t) (x) << 10) + +#define VFU_OBJECT_MIG_WINDOW KB(64) + static void vfu_object_init_ctx(VfuObject *o, Error **errp); static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -163,6 +207,394 @@ 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) +{ + ERRP_GUARD(); + VfuObject *o = opaque; + uint64_t end = pos + iov_size(iov, iovcnt); + int i; + + if (o->vfu_mig_buf_pending) { + error_setg(errp, "Migration is ongoing"); + return 0; + } + + 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; + } + + 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; + + o->vfu_mig_data_written = 0; + + o->vfu_mig_section_offset = 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, +}; + +static BlockDriverState *vfu_object_find_bs_by_dev(DeviceState *dev) +{ + BlockBackend *blk = blk_by_dev(dev); + + if (!blk) { + return NULL; + } + + return blk_bs(blk); +} + +static int vfu_object_bdrv_invalidate_cache_by_dev(DeviceState *dev) +{ + BlockDriverState *bs = NULL; + Error *local_err = NULL; + + bs = vfu_object_find_bs_by_dev(dev); + if (!bs) { + return 0; + } + + bdrv_invalidate_cache(bs, &local_err); + if (local_err) { + error_report_err(local_err); + return -1; + } + + return 0; +} + +static int vfu_object_bdrv_inactivate_by_dev(DeviceState *dev) +{ + BlockDriverState *bs = NULL; + + bs = vfu_object_find_bs_by_dev(dev); + if (!bs) { + return 0; + } + + return bdrv_inactivate(bs); +} + +static void vfu_object_start_stop_netdev(DeviceState *dev, bool start) +{ + NetClientState *nc = NULL; + Error *local_err = NULL; + char *netdev = NULL; + + netdev = object_property_get_str(OBJECT(dev), "netdev", &local_err); + if (local_err) { + /** + * object_property_get_str() sets Error if netdev property is + * not found, not necessarily an error in the context of + * this function + */ + error_free(local_err); + return; + } + + if (!netdev) { + return; + } + + nc = qemu_find_netdev(netdev); + + if (!nc) { + return; + } + + if (!start) { + qemu_flush_or_purge_queued_packets(nc, true); + + if (nc->info && nc->info->cleanup) { + nc->info->cleanup(nc); + } + } else if (nc->peer) { + qemu_flush_or_purge_queued_packets(nc->peer, false); + } +} + +static int vfu_object_start_devs(DeviceState *dev, void *opaque) +{ + int ret = vfu_object_bdrv_invalidate_cache_by_dev(dev); + + if (ret) { + return ret; + } + + vfu_object_start_stop_netdev(dev, true); + + return ret; +} + +static int vfu_object_stop_devs(DeviceState *dev, void *opaque) +{ + int ret = vfu_object_bdrv_inactivate_by_dev(dev); + + if (ret) { + return ret; + } + + vfu_object_start_stop_netdev(dev, false); + + return ret; +} + +/** + * 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); + int ret; + + if (o->vfu_state != VFU_MIGR_STATE_RESUME) { + goto run_ctx; + } + + 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; + +run_ctx: + ret = qdev_walk_children(DEVICE(o->pci_dev), NULL, NULL, + vfu_object_start_devs, + NULL, NULL); + if (ret) { + VFU_OBJECT_ERROR(o, "vfu: failed to setup backends for %s", + o->device); + return; + } +} + +static void vfu_mig_state_stop(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + int ret; + + ret = qdev_walk_children(DEVICE(o->pci_dev), NULL, NULL, + vfu_object_stop_devs, + NULL, NULL); + if (ret) { + VFU_OBJECT_ERROR(o, "vfu: failed to inactivate backends for %s", + o->device); + } +} + +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: + 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); + static bool mig_ongoing; + + if (!mig_ongoing && !o->vfu_mig_buf_pending) { + o->vfu_mig_buf_pending = o->vfu_mig_buf_size; + mig_ongoing = true; + } + + if (mig_ongoing && !o->vfu_mig_buf_pending) { + mig_ongoing = false; + } + + 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); + uint64_t data_size = o->vfu_mig_buf_pending; + + if (data_size > VFU_OBJECT_MIG_WINDOW) { + data_size = VFU_OBJECT_MIG_WINDOW; + } + + o->vfu_mig_section_offset = o->vfu_mig_buf_size - o->vfu_mig_buf_pending; + + o->vfu_mig_buf_pending -= data_size; + + if (offset) { + *offset = 0; + } + + if (size) { + *size = data_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); + uint64_t read_offset = o->vfu_mig_section_offset + offset; + + if (read_offset > o->vfu_mig_buf_size) { + warn_report("vfu: buffer overflow - offset outside range"); + return -1; + } + + if ((read_offset + size) > o->vfu_mig_buf_size) { + warn_report("vfu: buffer overflow - size outside range"); + size = o->vfu_mig_buf_size - read_offset; + } + + memcpy(buf, (o->vfu_mig_buf + read_offset), 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 = o->vfu_mig_data_written + 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 + o->vfu_mig_data_written + offset), data, size); + + return size; +} + +static int vfu_mig_data_written(vfu_ctx_t *vfu_ctx, uint64_t count) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + o->vfu_mig_data_written += 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; @@ -550,6 +982,13 @@ void vfu_object_set_bus_irq(PCIBus *pci_bus) pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, NULL, 1); } +static bool vfu_object_migratable(VfuObject *o) +{ + DeviceClass *dc = DEVICE_GET_CLASS(o->pci_dev); + + return dc->vmsd && !dc->vmsd->unmigratable; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -575,6 +1014,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 || @@ -653,6 +1093,31 @@ 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 + VFU_OBJECT_MIG_WINDOW; + + 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; + } + + if (!vfu_object_migratable(o)) { + goto realize_ctx; + } + + 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; + } + +realize_ctx: ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -700,6 +1165,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 1599b02fbc..2cc3b74287 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -66,6 +66,7 @@ #include "net/announce.h" #include "qemu/yank.h" #include "yank_functions.h" +#include "hw/qdev-core.h" const unsigned int postcopy_ram_discard_version; @@ -1606,6 +1607,64 @@ 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; +} + +static int qemu_remote_savevm_section_full(DeviceState *dev, void *opaque) +{ + QEMUFile *f = opaque; + SaveStateEntry *se; + int ret; + + se = find_se_from_dev(dev); + if (!se) { + return 0; + } + + if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque) || + se->vmsd->unmigratable) { + return 0; + } + + 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); + + return 0; +} + +int qemu_remote_savevm(QEMUFile *f, DeviceState *dev) +{ + int ret = qdev_walk_children(dev, NULL, NULL, + qemu_remote_savevm_section_full, + NULL, f); + + if (ret) { + return ret; + } + + 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 */ @@ -2447,6 +2506,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 Thu Feb 17 07:49: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: 12749586 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 7CAADC433F5 for ; Thu, 17 Feb 2022 08:32:12 +0000 (UTC) Received: from localhost ([::1]:50738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKcCx-0006vg-Ch for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:32:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYK-0004Ig-7H for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:12 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:29070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYE-0004Ty-Jb for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:09 -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 21H5WxbN009086; Thu, 17 Feb 2022 07:49:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=YtwyPyeZLkPGA2UyzFQiulYbfpCHWKzHu6SfZg1oS0Q=; b=GgiJf3ppNwzG2ztUZod8fxc2F6pLQOAX/rleeGBk9HWCXjVPmmj0rCEk/gn+suAMI4em 00xTsM3TYxEamDq9y8XSbd2bpPQPJrHSNnsbWZnG0lH17R9adZ1/ZNfXyxiD57JA7M9L zFIK5ILlM0VVJE2dFrGX1iIHIrE+8M55aVj5UQR12NjsJse1TDmOv+sJvLOHJsBdJgs8 7PyXHMacYnex1UWgU8g3XCSHY0XPmIGloDkLZFXgxSvV2EDLq66us6i+lCHfMcPVsnCu Rg/6NDDVVDV1/9VZDf2n6D19uXMlFJjkR3tvoVIDSbXyJsNiAyq0rv3jbzur8PYlzXg/ qw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nb3mhs0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:54 +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 21H7gDWf030241; Thu, 17 Feb 2022 07:49:53 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by aserp3020.oracle.com with ESMTP id 3e8nvtf6hf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PCwDHuDbhqC2YRMgBpRFLrSAV/tAHCaWlNhKuVjcYHpwRS+w+57rgN8FrtK/bfOdVJd+8ZpKIddUidKe1zQjPDt8qquqKuot55F0Aj9Ww1XgM4gnnQAuCd9j/7qzXvVUvZ9+gzNatD6F3SusfRZzLGhZi64rX7JdPPQKkz3p1C3j663CvN87oNQgb2XQd6qIu4SR/sjX1DW4u9tCOvJi9v4WwW0+8Tq94M/xuD+o3KHUxyWRmEhe7+iDKwQP4+888ClDg7keBcTEmISU+Yzyl0RfNFFPe6l9gI/bkQN3jtbKK6GdrWoYW9nrAh5R6NKHFdhGu+0gV6u+VfjU/OUhYA== 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=YtwyPyeZLkPGA2UyzFQiulYbfpCHWKzHu6SfZg1oS0Q=; b=lWHkLHV4yr9AQM73MJiCi0ChMHvauFczPaUMS6QNWs/A7r80FA5NBpcr+MHiHmSqAtDqY1cFnBCfK4ZTZqlWLjlPkQTaaokMqpSHp2Gxl1CV43CfF6XqfsPoxm939M6+/QIuGB7FFgDYWxmCtG31agG8iWYmd7iVzivCAwWou6Sz0Y7/braWcy0BoUGkE0Nrfg2Z6nazfl6IDF/m7n4AFSXX6RWPJ2Mh7Mfe3m1XTwQHtyUZhVzrz6RQHkUvqJT2pLfpkj6RCvrMdGYzgWrdG7N3ezQD8xsN8+qYFeZY04bqY22GSa4ydqMOAaEPNs3KZXB9FBq/eAVHuIz/1fmyvA== 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=YtwyPyeZLkPGA2UyzFQiulYbfpCHWKzHu6SfZg1oS0Q=; b=ZZ77JozQ6Qj+1pghZGZZorJriWpebEXpzvnAucUYok9Ydl49eNG6mqz90eOKpty1R2QSrXGG6B0WRnMXlFfI4eQG0V1KPtX8KPOJy5GGOHN9S070GKuAtZqLXk8oYlOI/H6dLI8vme3Yh0SmOciAo+mKQH8btef448yb292NfJE= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:51 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:51 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 18/19] vfio-user: handle reset of remote device Date: Thu, 17 Feb 2022 02:49:05 -0500 Message-Id: <54278334564d9e9f8d2eb3ff884260ac90da44e5.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34331bab-01c0-49d1-e05d-08d9f1ea140a X-MS-TrafficTypeDiagnostic: DM6PR10MB3211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:854; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GKX0yXvhQQ50vNdUrjU0nqoq0rpZGBKB/kuwEU5ODlxR6BYBLe548LxXMhsFAuPF+DAtDITyRXkCj+qVqyrNT3q6fRuL7lpxzU2JjKzgJjAAVaZ6p1ZUOCPeCAhTmmKm1M+dVKCULUdXs1xM2Zflx8VpEJNe1eO5r7IMA4pX7PMjH1LrJlJ8goHgRp2KRxJyFc7HdsyqFhAamdVgtmnJtZjoYYilGHnAUyVmFCt9I7yZPgDLJDwXNO3/rIfVeOOwsTNRSLMyURYXKU3pXjO+56OtL8MpVCIUYzozFq6Tlqro+HP2Zs0v+Z+26QECFYGMKDNaCST8zLEM649EjtSdX6URib3nw59wBOaht6Bc0kDYCdFGgXLn/uoiOwy130FRePMJ/246i7eMla39UJDP1+hJ7eKNcOWJrF2whiTaY9WZOthqe4kx6ubtV4vgjBvF3nR3/uxB9oZ7iQTJGAZe9WvxFW962wmqVRwV93iOyZufKk7t+cfSjJxjpsGbtJaY1BkLq8loBqu6HMdu70GVL1uaZWSPAf/hKfSlyKWVVjhMqG9uG9HvZd9Q/pkNEDX1f+q86Nl+yopRL6hT9FfhC4hnsC/PNOlUlQ82P5x4Eh+VPH8vx9qjVk6uY6HdLSgGBfxKcvnnRShUXtzvL0pPePZTWV8XjFF0xQ+LLRdD5cLR8hQWpPYf7rD1SMqLRDp8Izy3G7lcbn6o4vvZqYWlvw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wpXj2qsvzX4yOzwnfa8QN8+eUK+BTJb5eTb6rCfey2885J6TygLkX20LQe0I6uzPfz+FykdXEy0Om+JBbDB9OE0ezALjEUn6b9XuyevnClIT7CUPVU7a6AZUS28yNsrUk/jvfdpPFAKDrP6YhXjejIfIMsv34hXDAS83BRIn/sld37VsMHj3qY6efhj+gd6C7yj20csPuDwesWU6IySmCaedhc62Ta+cwmEZQCzyDFmQx15veYwocjbWefEkl4K6Gj22Cqy6g2Zta4uxt3EfkVzNyLxcHJbmNv38KX6pN+2Gpfz/uZfIj+JGI12J67EXB6sRZcxnJHufZCjacyBRYJ8oxQg+mWL4FmKnO76w9JKtYJurBclTqsuLG9qUFSgQUdLTGcAhD0p/zhzHIyqc49OT4h0zHm5NvtwmlAxmf3ALVS90aiE1WxeqGuyBgRtY+hAPrBc1iTVmpTXTACG8RGV7E/JCRPqsDXxGZYKxDdTf7f7oKwecyHvk5SZslesEaMVZaQbTsbhHoDg7d9gO6UK17imT166He9hxG/SxPurlyYwEPlY5R+3E3ACNap6kgb7WviUwLMbqCbNIie6VJIEtyMyjM6eKOaYmKV5PjUzR9/dxMjNIILhPw+YDEM7qNlyW/QNB/R2p33tSzFeT7xfihe3GWuFOkPlxRiqZVSTjJjs8cdzgWxLO8Tb0fzXyMAk+ru9iUbeGoJWMXUc3xBB/4LJi5PM7DDcbwDLO2aih/YDhh5jvosC4bVeSTS7wOndIhpq0rs9BzvdKVSygRCcfHq6ImVJ2iSFGwbvlNHVCCYKm+NkF4a1xe6PJ8XNvLPA5+y9XPgYbt21EZx+Qssb0HPuGpBXJVQTaROd027bjOnQZsUywhcIeIBR74wBj1DMY8Sbq9f8l9EraMUs5kI7mcIut/ijJxv5496Bb19a/UyWLUMnw/vuLbHvcxj9pL15ztviNmGWKo3/p/MWGexp9mj1kFu7jcHxAKMyCsWahDfahZ/vaPozUAIfknjfH8ilabo81N26UyTUl9XftzWtTkj6hgohLl6eMSHmRvo98wq5m+pTZ/FAsbFGMC/y9hjlkqaH4eoNTeZO805Z2AOFGR+IjgrlYkn7CcGxZ16WqjPQZxqSWMObkrhahhQbE4JT5m9xrKdWX7TlPYuchJ7B8Vmt+blgWEZLEtf+yC7BB7027LMv0jdTZAlgvGm73O/KmK82b4OTd3Y29HKvgvTu67J/r0oSFKEQpwmazsb6IljH/jDOw6/TmtMsoacSZNwrK+EZZVC6Z9gKSKUfiULRveLQtZFWqqoW//3EBz/svS1FnH/BdMK9JFtROK+3CmeZoqTuu6STlZ/QU+wrMHnwIp2ZV5XKlJhsWMaP4lG2LTbgUdSnrwRNTSeL0ptogtrIMwyB8k+JMd6kO6Rf2y9qopZUx4sd1m7bybWuk88846wocTFyEbNTEIk+TcczMz3V3/9PnRDywA9v06TSkx2UxRI04rVOm7WN+a202sAgysSVCd4dMYAAgTVYd+OmkoF1oWbJVY+vTrenwca9m4wme1CMdx+1xrLxWLWbyRITGUHRe7XWeiZTlQMJwcO9MIOYOEB53FXFPyxkdthaNKBpBND93snkSoHNklbJviYc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34331bab-01c0-49d1-e05d-08d9f1ea140a X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:51.1471 (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: 6jvnWT+L3WbhRySGyHBYsHYr3L6iKbvECar6Gzh+JwgR8+SJzYJHMsGBbP7j93uQPVrSWRXy1T7IpxoOOcaPUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: MbNXoCMZ8Jv4OTLqcl-Ze0By9E7QKg8z X-Proofpoint-ORIG-GUID: MbNXoCMZ8Jv4OTLqcl-Ze0By9E7QKg8z Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds handler to reset a remote device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 2304643003..55f1bf5e0f 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -989,6 +989,19 @@ static bool vfu_object_migratable(VfuObject *o) return dc->vmsd && !dc->vmsd->unmigratable; } +static int vfu_object_device_reset(vfu_ctx_t *vfu_ctx, vfu_reset_type_t type) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (type == VFU_RESET_LOST_CONN) { + return 0; + } + + qdev_reset_all(DEVICE(o->pci_dev)); + + return 0; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -1105,6 +1118,12 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_reset_cb(o->vfu_ctx, &vfu_object_device_reset); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup reset callback"); + goto fail; + } + if (!vfu_object_migratable(o)) { goto realize_ctx; } From patchwork Thu Feb 17 07:49: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: 12749652 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 AD7D9C433EF for ; Thu, 17 Feb 2022 08:39:45 +0000 (UTC) Received: from localhost ([::1]:56684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKcKG-0002st-G5 for qemu-devel@archiver.kernel.org; Thu, 17 Feb 2022 03:39:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYM-0004Os-D2 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:14 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:31522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKbYJ-0004h2-Sz for qemu-devel@nongnu.org; Thu, 17 Feb 2022 02:50:14 -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 21H4NP7R027719; Thu, 17 Feb 2022 07:49:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=nXThYHpchnLLASRjX99W4MtY+r3DIhAqrtlPgKqa37I=; b=fRNvWqakMiPqDUv+6vqj1BSNbDA5InfYZHkr+6KaQGZQOcmWKtndAR8VyaUkdiNj3uvw nKRsVa7pQp7hMPJiL5+h/t7f5bShkINSvKGbLQa8vgUHU6xTvZg1wPmgwdT4QElrupFa 0NGGUPVxQ3j1cJnqXxs4IO0DgJfyMjkSZfOw20c3axhrnCJx5ikJLUDvgE0/7DE1cxYm KTjGu5L6YoafaJMvkFOTWIk/JucFERq60hzfiJPRf0zWirFnp/+/+N8IIvN91KkYiWUO WJMg9WcsPHQGmC5HASUXMc+wWGGMqxCRzEa1CD2G5R41b4cqgGMvWHONv/EgHyMoMSjI gQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nr94whb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:57 +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 21H7fJKh142772; Thu, 17 Feb 2022 07:49:56 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by userp3030.oracle.com with ESMTP id 3e8nkyqrwg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 07:49:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LSS6odCtwT1bE1Sqr6UNIfoRcFU9euH2cL8m79MD6Sy8PwLhIXylwRkOuPSof9zxIfEN2W/uO0yfwCxgeRL8Vn7awru1akK2S97J79wF5SnT2uBfdtDf755BZdn3hxLKXR0P63WBxPFnBokf7HovvTWXu8mDH5UFFDTq0PNB0Pm6wWdGkuNFi7v03qchRVD2xPwXPPJY7StJk5rBwLQJc45hVHrEb9TqQQPevqMYfhvCwiukOTc90lDTUkgXu7J+B7XoQhB86HOSGYCrde6LoW0bMsxPDO9wgIWWu3rdKl/z43bops7e2xv9UTdmz8NGtlifK0gQLSMECL9Dt+AuiA== 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=nXThYHpchnLLASRjX99W4MtY+r3DIhAqrtlPgKqa37I=; b=VNsYmJ41e96+tyfJyGVYqln1ghrMruBITiGlC8O3P3BY3xMfnUwikoFUF6Oobiogr/OsUQX4FuBFxsz9kJlMMujI929CgGPw5l+F4UoIOlead2DddGfiODsAx9y90pa6I9MRbOZ3vzLu3L/+zHFbfBBw1AXNcqhcly1G85ev+zCygfIGv7DXAHpGIV2RHNgoRnu+DqjW88yaksMUk60GvjUqXiAbO2UFJocIiC83Cyq/bHIo+D0535B18ayGVOBVESSKvnziSQBoHtxjgh64qODUea58TS41EuyT9BoCb8yAGZyqO3ewWcqc9yzc0cNgTticyJ/fI5mp0+tD+SuSeg== 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=nXThYHpchnLLASRjX99W4MtY+r3DIhAqrtlPgKqa37I=; b=KnZiXA4oZS60V++EEYcwiw6AFEp+Tld8TjMcMmGL6qhBxE53+EtpzHlPF+762w597PNRZgTIQU1INpJr3r/f2fukcELEeWax2xX4kcsiKRrId4N41qdbjCxRoqGM5savtacFPJgQ41tbDhmLjIUhzsUXQE6bHJiitlM0Vg08Gco= Received: from CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) by DM6PR10MB3211.namprd10.prod.outlook.com (2603:10b6:5:1a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Thu, 17 Feb 2022 07:49:53 +0000 Received: from CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe]) by CH2PR10MB4008.namprd10.prod.outlook.com ([fe80::8062:cb07:e437:1bfe%6]) with mapi id 15.20.4995.016; Thu, 17 Feb 2022 07:49:53 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v6 19/19] vfio-user: avocado tests for vfio-user Date: Thu, 17 Feb 2022 02:49:06 -0500 Message-Id: <4f17aa680216dfe7a226553ebfe164b59fa3cf2d.1645079934.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0002.namprd10.prod.outlook.com (2603:10b6:806:a7::7) To CH2PR10MB4008.namprd10.prod.outlook.com (2603:10b6:610:c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8922d47-0d13-45b0-b818-08d9f1ea154c X-MS-TrafficTypeDiagnostic: DM6PR10MB3211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GBwydnxyCBSHh+l+g7Y5mboYWUR7OVGScLUJJmGaNMh6tNmDSav3GXwem22fyfz8etXk7KI0Tk8HKwdA3LmGGjt9+cDmI2cdc13PAe9WIxbji5Ex16OtGLhNtyH9m6iStFz+W3+cq9uQywMK/WVhemFlwaaHkG5ZFH4bpGJexdvGmf6f22Iv0hZ648QpieLcihFnH7Q77BSG9CLrpdJXQCBBlYTpupx0f8hv7le8rZ85bMHMVcnE5UvFLUESE8H7n3NeslvsC/CtiRDEsdUcILjVZPtiRbGtYEFZ6LkoslOunJ27lIrgnKUV1bJ0FELClNU3KT2ur7s8iTLYzsD9H72G4nU+Pr8uUnnimCVYdUdpk+giIfchA4eQMnJek4FCgaEEQcq0Lygvv7tFx0BICa3m4XXK3CgE2XO/iN11nd/dXkYb7Sr/LN45UuYZ9Sw7rgPW+zGS2afqILV54mjs6D4aBsFU2sMkeVbu21aGlKs0AqGmgqcarm607LlwOs3VqGuEnU1ndObn5N+jx44fnCDyRSQGahXd3IoBANsv7GhdqiwcgLI18pOFtxEXYk4tyEyyLuDqI7d2y0AYQq2tyaw4RcuF5290Jsb/sMcVBNi0VVw9NJoLUI4az/rQR87sOciZeIWHhDscQEfhW8RD3/4HCKxA/6G+RyfVLPD1Yhzc1sTBtmmIZf6gCHEl5+4zPRFqoV+fAHhXdPBjY7VJk4HNIPkxJWyrC6zAuV5UoxABPPpFeWx5CFPcbQBaGgXd5qukCBlA4HxwQEfKxRyfqM1T3gKa9O9SXL7CrwaQDdU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4008.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(186003)(66946007)(38350700002)(7416002)(4326008)(107886003)(26005)(66556008)(6916009)(8676002)(5660300002)(2616005)(8936002)(86362001)(38100700002)(66476007)(36756003)(316002)(508600001)(52116002)(6512007)(6506007)(2906002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JFSv2fHHTRLQO+NFKO3K4gg/GOO9uGciIJ/kUpcw3JZiC+a+jpeiaN83dViud3njGjgYuttYer1TlGfVy4aKoeeq2hMMclzq7Ht8b6MY+ccykzMtChFaqcZ+4idbtdRsRYYbHbJ7LuIIcDFyipSIAmG8qbEeCQUmEH0oL1YODHY+REB4Bv1FOvwtwxM14YeLzkENuEEn8vC+JR5SLwD0BbGAHCE/BZ5ubqN/hQUzYfRt3u52SNxWbMqGYwkJAz4T690xbsHfRS3KzEqdggskP8ZaezBLukVjiJO8KNa4cOMldKHgejGL/9mxTULDzoqXhB9uoCBt2d9JMtjoz3vch/9ltF2ZxtIi4aK9s6KUClAwZ0GXGcXgjL3T+vi1pNoGuP21HPphEXaAhPajuE/O0um/GCMHVo1wqZ0dHRACpDpp9esnTh1/xNdy1entfn9He7AQRBLejz7fRr4BYZbUXlWTXOLaao/mK8L0cVtuvk3RnP0ucR16RR65lMabogl1I4lIAaZGUN2VZbKQIcy+3NRA+pGdqvKqkOrudFUa7xnSMPRMzgXWNn7zCUWsi8lWB4PEno5Zkqa0vVGsXrxk/n0ojdGfpA0FGF17AjJTPzHAaPsJWtqTgADVsvOEErjFltBKQoyOkUYM6MbqW6Dt7U80Bmpms9Cyk/oZU597q49uVHWbXx5Eh97E/XKmU+/EbE3O3Lt1H4MBcFPScERSNuYelosaKOIp0vyo/lEOrOWneJ8WzSryif/Zg7hJ9ubwRxH2d6HtY2uRDKx0Mun1hmZ//LxW3khaDaGQ5OPdJfgsz9YApshmNml/02Do9LbKp5FsKzCAXBGUgZn2EITIBUjX4EsO6ON7vZygxhEqHCKfWBcS6TvAOJcRRemY/7ZIhSSonrbC2ZeKWYmALJ9kPhGM2F4tisTB9F9tVRmEJXmzouQBxS3EUGRSEgYYg6BpngLDypZugUjVjxlfJOxGzueMJ88Ht/UEFtNqmgAkmkFBSHSjdKiI7tnxAm66tlFD+uxYTrxAwHt2UcrekASTNAhQ02GgWnBq41znu23pJlq0doIdmfqhyKO9u/Nf8QG+h3oOD9kbHK0a1SzIj6KUWIscoDYWCQwZwg92OAa9v1Sg8CnFFH6pNT6eoi4C29TL8M/8h4bZvj1zBvFB7xJoqVj9I/WLdKx+pYvIQkJfb4Nq31lZdsykU+v46fB57+KPP5L0XRD2HAHpEexv8OIjk6tfA+XMrlO3Rqj52sUMY2lECFRfWaiKHKPKHRLA3DVojNh8birjsTH25cyVZBe3Eptsu72HoNUh3Uey0jC9yXtwvXMtdflgFkZM5zsOYAGlywgnOzx4DyD8ayJNztqc7YKoxO2wNCsx/O+i9m39pyP0f/mAOJApKvdKLdF5pii8t9ohytlN8Iy0ustweyPGaOVy7hGTrY1GvCDDrjWeLkGgvSgPAls1AxtuA4p15l7TL6d7LbL/MphuK9I6mwyZxTmC8YByIdXTeEhg0BO59l5/X6PpvR7Yfh82/7gOBFioXMGRzwqlobWLgGmmvnQmL0nhxJaXWv3wc68LoqERY/nmVN8cThnPpShL88Fw6jQO49oPplLrA8qwN1Gjm396I98T16UJhvoP9ZdD7ggAttk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8922d47-0d13-45b0-b818-08d9f1ea154c X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4008.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 07:49:53.2876 (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: X4Xq1ymMUIZ/RDCrwLoX5wh561KFpp6KJw5ZlTLudSxn6RgXcxnZia3FIG4Tz9DMPjZeI0vrFTRZ37E/zSwhFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3211 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10260 signatures=675971 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170034 X-Proofpoint-GUID: f1hSi6Nfn4MqGMUg8AFP57FE2zRsfMJT X-Proofpoint-ORIG-GUID: f1hSi6Nfn4MqGMUg8AFP57FE2zRsfMJT Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 234 +++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 tests/avocado/vfio-user.py diff --git a/MAINTAINERS b/MAINTAINERS index 1f55d04ce6..02728eb8b8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3573,6 +3573,7 @@ F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h F: stubs/defer-backend-init.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..3f13d9895d --- /dev/null +++ b/tests/avocado/vfio-user.py @@ -0,0 +1,234 @@ +# 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:0060', vm=vm) + + def launch_server_startup(self, socket, *opts): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote,vfio-user=on') + server_vm.add_args('-nodefaults') + server_vm.add_args('-device', 'megasas,id=sas1') + server_vm.add_args('-object', 'x-vfio-user-server,id=vfioobj1,' + 'type=unix,path='+socket+',device=sas1') + for opt in opts: + server_vm.add_args(opt) + server_vm.launch() + return server_vm + + def launch_server_hotplug(self, socket): + server_vm = self.get_vm() + server_vm.add_args('-machine', 'x-remote,vfio-user=on') + server_vm.add_args('-nodefaults') + server_vm.launch() + server_vm.qmp('device_add', args_dict=None, conv_keys=None, + driver='megasas', id='sas1') + obj_add_opts = {'qom-type': 'x-vfio-user-server', + 'id': 'vfioobj', 'device': 'sas1', + 'socket': {'type': 'unix', 'path': socket}} + server_vm.qmp('object-add', args_dict=obj_add_opts) + return server_vm + + def launch_client(self, kernel_path, initrd_path, kernel_command_line, + machine_type, socket, *opts): + client_vm = self.get_vm() + client_vm.set_console() + client_vm.add_args('-machine', machine_type) + client_vm.add_args('-accel', 'kvm') + client_vm.add_args('-cpu', 'host') + client_vm.add_args('-object', + 'memory-backend-memfd,id=sysmem-file,size=2G') + client_vm.add_args('--numa', 'node,memdev=sysmem-file') + client_vm.add_args('-m', '2048') + client_vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line) + client_vm.add_args('-device', + 'vfio-user-pci,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() + + """ Launch destination VM """ + self.launch_server_startup(dst_socket) + 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,)) + + self.assertEqual(src_client.command('query-migrate')['status'], \ + 'completed') + self.assertEqual(dst_client.command('query-migrate')['status'], \ + 'completed') + self.assertEqual(src_client.command('query-status')['status'], \ + 'postmigrate') + self.assertEqual(dst_client.command('query-status')['status'], \ + 'running') + + 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) +