From patchwork Mon Oct 11 05:31:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549033 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C26D0C433F5 for ; Mon, 11 Oct 2021 05:33:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 267D660F14 for ; Mon, 11 Oct 2021 05:33:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 267D660F14 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnwQ-0004yI-Vh for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:33:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuS-0002Rr-Eg for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:36 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:8288) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuQ-0003q1-AZ for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:36 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iPBL030032; Mon, 11 Oct 2021 05:31:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Zyim9QuNHEqDVlxVK7EPfZw+NgSgJcYDNm2FKNOnaXk=; b=v1tj6ZH79mkwlzaDmBRCoi35aJ3XX5yvMhYslla4qhEmVV1Hn49QPeavGmx75UVQUU74 B+wjTFcya+G/YK7TPzzXycGSSrcOp4Yj/9bONd9aNUKKotjX5ZN8VB7KD65BXesduAZz VaS3EANSjSaAcekh0U2pT0EbGO1ezvg4b5Hr7wUpqmacOfScbOczmYjCKWFMqFgJQ+qc ZFbQvo+i8BmpNBmAEw8voGnPA2oIR04tcCtsCH6bFNjntn0n+c1xPoNaFheFXGEr+ixy vHSxIu25EMSTiBRAF4bm/JuNG8yd/JT5reGa/qrsGDlhwgaCT6PtSgi8NDOJT4SOH5qN SA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwyuhw13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:30 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19B5V2Es123636; Mon, 11 Oct 2021 05:31:29 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3020.oracle.com with ESMTP id 3bkyv7nt3q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L52DAoI+Pr7WBgQH6X8QjmsvqcgTs4dUf24GEavkYUisiBw/a99K+sTA5PF+V19xb1kSjNXEOqXOJgdjVu1lbRLaHk6C81QpM/xsQdhZE+Py8mlNqPqODVBS2JasNFA3FdOaA+05XofIKO0FfahDI0Tn3sssUC1cW3zKD3NwgNbbsnCz2V9F6Qn5PZxEz0pLXCJMyQ9f6zMQFAikfra4gbUn30YH6K8eWFOp2rquqQ58ZNU+h9Cr1xuBaYQdGJGAC1X+CYAUDRcEZZmHAIE8EctohqN0ENt30IXsu0sifBukP0mPYZy42ULaH+dE+tv4raoBskMgMUi+zuZBhVZ4Rw== 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=Zyim9QuNHEqDVlxVK7EPfZw+NgSgJcYDNm2FKNOnaXk=; b=WcAfFgCWqvGCGgPLBvdJXrr609n+lVuTgk5pN6jFBlfrpFPMMNvWILZTIy61gOsgVB+TIE9wBftcYJGCCsVOHdO+TU2srHBHbuL8QMbhcVC1V5o6/hDbkYmqIbobPUYlAjpmNovuq5AUNJhCD0kywHNqIx+t8AhGav5QyhzF6MuFApxW9VoxkHeHKf6DaUSweldlurGLNE7X1Xz4tydD4+UZXcALWJ3SbhtUTZSPnfO+tYPN8JXlrLKTGIR4B3Dxeq6NvGL+qGxnqaDboZqaIgSrb8IJy631gdEjU9UZX7Zy/Kn1KUYHN0HJmPcy96Pbe5Wft6o8JmQJlKwMU07aOg== 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=Zyim9QuNHEqDVlxVK7EPfZw+NgSgJcYDNm2FKNOnaXk=; b=P+OX1yHjULACoIw9rHsdRrbJ2MS3mZNEYst7AAyBV0+HRXo5VtuaCy5zKW7Hpy/MskKuZUZpTrPFs0fqST2D00RWC+VApMyWikTXFJy0eOLwsCtc0Hgbc/ySLbfaf9X6YfzU9N9hyWoLwIsmZPakFYFikT6QhGTiFRAL15RZks0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:27 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:27 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 01/12] configure, meson: override C compiler for cmake Date: Mon, 11 Oct 2021 01:31:06 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ac2dd62-acb3-4fea-998a-08d98c785f0c X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True 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: Pqf+WmSiBYS4J57eOE7+1ywkn57I/WzeBUGh1tmj+RJ9fcX2vJdY2KJJmGAyXVjQsY31mGshzMaG1HLqkVVAr2UT+EoimoZLFEc4rVbeUz5euwnlNqAPjxVuSWJA9m8RBTOMMLKXNR0OtatJ+YHqESQe2rafEZ2Jnc1ufVXrPJqCuWDWcjHLwrhJfouOynA0XcMc+hAke6wOVm56Q27QHrq5X3OO32nrCaGSUop5qNHK7oDcdZ2Ngbxi5P8w66Bq8KDFHf0om00xZtANr44c4WVfWqhvGMY7sDAek8aImIOUiH4kG7yzlHHZf3gTxEl+215WR9rX8auRuGHa3848M7cr3TeF6dFriasSIIZ9PGF2/G5ZIg5AUbBewqHV+DDi+2624tEc5edozOtIDkLNIe4PGulJMeaF02g0yyDCkCu3dIYTgLDYrHT8pxe+Bzm9gcm1OpzTLycQ1skEkB9U2ytWZcrc4eLV2Ushy7C4jS1xISkeZhEacKjBrzvh5rMe/syISVGSFDbjYfWBMjNYFM48p+QRBMgR+19uIaxIKRfB6rsyn8WT3Za0AzQm9eAdOskzDN7HD9KE2vfffeoVYpYRXICwnGRkG+jXEYVpmjjzqxhCwVGZZ3OK5snZjWCUyx4jTvSDliK3qUDDT4PsH27Hj8KUARp8Z3H9deAIg5UbAT9f/KSniw6wJGDMdeY4WoB4y2FSWeRbHfDKojOqnA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(66946007)(36756003)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gvijXIEJ3RYvpnApzIM/usWseq1U1d4pOp1Sfp98iZ731qSbrqxlBVH16Fb78xmwPt+CtyPfsY0ILFupAzpKyCFVKxDqjOPMpYYmpSh/+VZnc1E/yLC70vOR+aHpFClcmpVucnF7Syk5fVbWSn6PHTst2pGO5390p32kJWwDZGIXFXE+HXwV5LbUzlJl9yfWA6DNUJGfzzKDbgzTilZJlbEdQqNZw5u/dc4vA5ti5rNQtFtrJrLE77QozRyPF0iNblGIEvTTgzL7GJKRc6/6e4+xilMVnsgT+Ly0XoOyBiw15OrMYqc1pZEYZMZHnuXH+vRv94vjoTH/GLWwN+swJ0pc7hOOlDXxumIJ2FIu6JV1bU5elIlWNHH95HTGW7lFLovu1S96+zpR8cz6B+kFHcJwyrh3TVzTiO0calTwF6Vomv82oP1AuPsyhi1J2+qFVaOrRPduFS+s7hW5BcOD4Yorfs5mgb2brrDoQoIXTMmVu/o/pHNM9VJYGYcJFYSF2PHGDIKuCpo0L1OKHak38IuMgzm/+50F0Ami1bxun0cMNV3K/MsbPYY6218hmVauxhIasbEyhDhm4o+5M8UGkpVlqYGB2TSVvxqAlaYRf4Y8f/qvB4AMn1ViyaOTmJDiKdWFAieIE0IhJQuA1g8DGbX3+LMxwn0p6UodvjTyQUxoozss78owXk/VkXZL3SjdUCFExIyW9IGIvZo7/Hy3JtLv2xcirjRrthEStmeCaWOvc47JseP1oJNzX9weXTZ+dRFhFNxNHfe1AZWuyHKLcCB78AfyPr+449TmiZshWJYfazdkaoZMKUsVnoE6+wl5kSRODod19m7gR11OgKx4M+gCuthf/yIR2uXqbae7k9xYbKisJCphmQSUH0LUVTVt1SePTKHCzSY23PUOOfbzmzVYOCEfk/yQ7v5fKagmItEhWn4hD+IZl+tZ5p2mhkgs2eOJyRNv/EGzlMbBlDbC0h77G5OH2/m+54dLP28gPHBJc23+oo/jA6tAXjyEXlrXSqAtNsc+vZ87o3uLAdkAHhyeLklUn5G2im/97/lYA/lTXrup36e8EA3u+VKO3aQ3RtLNz/n4C1aygBUNs35i0DhTIvU96NVxSnm8wRcQvGY5/Bj43JXIQDBCmZr1QCw2anvqFsfZ2tJmJ6cOdeETPUaXwaTlyMHnYF60XXXpseL0MjQO3uwQAOA+4JAQqWCVYbzFbZ/7sD0r9LCS2p93RqQBrAtVEm1NqK6eoj3MY9v5dbSqe8qHkAL4HFwiNybsIg6W8cV7v9wpPyfx4pYkekO+eObStGmu3DMwTx5lriYdssD4L/2AIIV2X2ecTmUH X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ac2dd62-acb3-4fea-998a-08d98c785f0c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:27.1099 (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: Vb8DY5LQvHCZ21JNH4rWr5lI+KTuz4L5qChNhkwNYbuwrbRQKtXjoUFXDkXLPjKxXzsmn1N9yR3PN+banmeZ9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: gIVzPhTL7bPOz0X4tveL38FSYeOxX43M X-Proofpoint-GUID: gIVzPhTL7bPOz0X4tveL38FSYeOxX43M Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org 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 877bf3d76a..e804dfba2f 100755 --- a/configure +++ b/configure @@ -5112,6 +5112,8 @@ if test "$skip_meson" = no; then echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $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 Mon Oct 11 05:31:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549037 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23FE2C433EF for ; Mon, 11 Oct 2021 05:33:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA6A960F21 for ; Mon, 11 Oct 2021 05:33:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA6A960F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:40054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnwV-0005Gs-QL for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:33:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuW-0002W3-2c for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:40 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:4172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuT-0004A8-N6 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:39 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iKPX029460; Mon, 11 Oct 2021 05:31:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=4N50js7COgJacJ+bnhAUaTi1lqqel9ergPc265m+VC4=; b=keKKiZ3g8gjvL2pNi+K4QE0mhdBFJ2zxAqd9chOkylw3bEWwfCGYrXOTXE1nw0dtlkod lFVgdx05YAPm0lFLwaoVZUUkZo8B0S9oCC1W3jUOrI+0dN2FMmIxAVIDme3roiaF/Wdh oZLY+O2pIQAD5/Rw04aZQl5Mq5bayJy1Gt0WPGSOuKl7VjkeOYcELTy5b0P3FKz+IBVU sXunc8pjWf0OLK8XiWfTCdg9nn7PDqLf/Z0OuKalNI1mNRf3bIMJNShF+Yfv8GHdCCSA aDUu5pTY/UINTHDX3aRla7Q6SKEbctCL4ZM8lGtMDemJOSMnPSl5cnnMNT27lSQGTVEu 3A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwxh1v87-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:34 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19B5V2uH123700; Mon, 11 Oct 2021 05:31:32 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by userp3020.oracle.com with ESMTP id 3bkyv7nt5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BMsbcywhgn9sBQ5YuN7hfPoVMDRqt0PIAyueRvF/4adlqDSbDweLEX4GDn2QXpYiBpVSaM3miQ0HcUYBA87loD6l2KDygWJFRnXQJpa1kDagz/2KEcEbjQt9IlLryGdznUbQQ61terycGCBWTwxl9yqzRvKahP4j1ejF8GDyDg4zv5fWA8BMBkClOjAEdhi+IztVNLONxWhQ0d48nfxm/tC89F4nBu00eHe5NLbBxa+a2l79DMBzCFlacqH8httFRGnl+MVnzKImJEiOidMpji3FPEjLW7PzUcwJicD5Yx185tabNHpVsmAJ08pv8hYSpwaAkhCgjiqY43DQMhQgdg== 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=4N50js7COgJacJ+bnhAUaTi1lqqel9ergPc265m+VC4=; b=ZUm/5B1WZq5FmxVrHRRtaBKs4Au2Y+8XrlET0Sa61g80+pG1voAOK/xenN9XndAw0gMxHKEp0SLDpalhrKPnfpS3Qa/Lcs6QO0HcLDo+MeoJzxEYc9bn0C/NQN07laTztKnkHxXlV6+W27h6ytX9bAlxhGX+ltOVP541BUqyHEqiRkp9Ow0NKhm3S8crdOI1RxFl68VR+byCQoZoY6pKHZHFjntcq3+LgRpsbhDhgbo0xj933xstAACzoS9OQUiEeo1S/Qk/KQL1z9Nl2/Da3v1pITgn/vrZBHvuAJ+024RVoVZfu1yX7pVrfGljPUT6gIpD+jccKES7nr2L8NsBoA== 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=4N50js7COgJacJ+bnhAUaTi1lqqel9ergPc265m+VC4=; b=tigiZGiutM2qQo2nNpF0CwhY22HITqvkbQfnAMF98eYpaOeCC7VgAfwU3j+xcLWolQBmrpmxhVJ5t8miCcQ4fgyNFh+pdsEd6267eaYp/ykaGa/o+OTa4kKqnC+RpN7LlSAYrgxrfeyK7jbq59tdK5uF4EboqfccZXYDWLkeOUQ= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:30 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:30 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 02/12] vfio-user: build library Date: Mon, 11 Oct 2021 01:31:07 -0400 Message-Id: <48b1ca2b5070f3655075e02966c40786028dbfd9.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0eb52201-5a29-4e18-ef86-08d98c7860c5 X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dI1E13uZ7sfoweEnCyRRiEbmDlgf8UAYMaiLhmyt0b8Q1m1arrv3Hq5QSe6/bgOuP0bk46kaWHFlDDjc1Xw2lv5sn90O0ftNKKHO3HxDDQ8z497fJUMsvTK80y8pOHUJyQgkIDX4lB4+TOJyGRTHAqokbRB6DMorFkDQHPam023EwE5N7E7p2qnnPBRzVE+pVHWzAvXZErYmOg5ul1SLOc2SaWMGc3Y/nAN5/Zkp2Zkw1rzusKDjnlSDe9eHzRXBB8bEuFNpS06nm4nFxG1dSobk/+vqc5IEV63nHM3Kh/TaleU5dh5NOeXb8aDc+HWMQYrtxz0kW3PYzJAYQ/U7ZcKCVWcBi3N7TN/n5MeIl0gAcdlQkksDaRrpd+RjGhTR3knac291CutPZmqHnj7JCIYs2rUhEHxKxYKHw7sd8FXEshmJMn6Md+R4i5odBq5CckG+Ofc/aEp7XcbdLgRiLfDpN72UwbU/AxHc9sJskViZNlipf3I5Cm/9eV0gbzWtmBCRwRHfsbob4jSY4miyyQ/o18LbRMv4jmaVfSQx7O/8gxkPXw1at5gB0yUBxG5lMg2ZVXCz19n/d512WI2j6QwSpBpqYxX8iICDlZUoqAVnyzBY+Bd7Q2T33k2SBjjY22Aa42Aj49MHRgkMWKNYuHcTjcFtPV+bHSwL1yCWv6n/xwt2RmMncIXSuS9Rx4rhn8y0dFRoUbmlmUFuY6gikgAVx7UX6QWWuRF6f8MN2tfgtU9hc6IBJwo/b2vYOTil1kN4RJyBY2J8Qcu0anpKUaVcVtJNMwFphiH3pUhM2FyfQyUcZgwmcLlrPL99uOgK+BNb1I1L7CZH4kLTHJs5mg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(83380400001)(66946007)(36756003)(966005)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lG6mKdfn+fFtC3oreO4NoILKgdXFSjSE6Yr1hCFN4fe+6Qb3xVaRmCZr2tzZY+CHdABBchFvt7BSspmbrJ2vMab7VKNblyiDXobB2gJBixug/F7IzMC3O13aU4KhswgPmzFngu5ZgJ60dcA6obyDVlnjn871pxmoQ/vjbRwIP3ujKYw7E/uEsxqhbq3g36ibC51ZZabDnSmXJ8lpVAQpsvUqbOFUE1M8TSzjYo2SBG3jP7mlydogvJ6z0WSro0kHWd+lCISjK/x23PfyJ3G58MXDOC0y0StXjVP8BGqK6c2rGSkQXKKmbRrEA0ZT0oSEKxV6CmY0bVd9NIOiyY3YFI/b9g1fHIq/KHr2dx9LUK4xtpuQIN+k9sUP16nN/Ejn2V+5ZBveUZEqlGPSey3MhbJXe686AZSBp/XgL1PVEtUqInH4bEG0TWkkAS3QyXv1bQRiMgOmQrp+bQcwOAGkXzOYjOY/OCJXIq1ALRHhPIuxHt63Rv/WF2hnubmW5cL9cEZibwANmGeZq2/JU/Vo0jykcNcctoL4lkdatf29XneuzNlAe6UlAaylavXWXvSJM6WcUd01U7w/Tlg/AWxbWxrrEMSnj+F2/KfdfwV7FmbB23pBae8991j9Fo7j4tPClZlIPA8c6Ml8OyXdkoVbYcDIIjVaZ2dilm2fk8W+ozq4d0FESE4u1pccwFg18fnW1kNmfNEgj+aW54B/AY8d4nvG0PF9Rj6qEbAENCXoFmj9bLtitW8EEQAdEGUmejPRgM1zYqgoYvD7h4nrUoKG3S1REY0YPMIcai5yLmVLl7F+jM8Df4mGgJyPEKttI+rqptjdH5bXpow7WR/75mdroQHe9dVSkEcQm9TfBAIdrqendyyYP/CPlkUaY2dpRtJZqBdBrXcGKsSZ/Hr8wtcyYQvllHyE+jyHwIwffe7dRvcIRT9tyZNZCjSsJdQCAznHBx73lSQnQrRJMHNhFkc6D1ngAiJJbyG34iT34lKqIEWX6fihpc7F1/D4L2w7Jd44rr6MPJz6WAN2fi95A7dKYiRmYBscnexxclVUbHGRaP8WOPYdk3ZGtV4ha5WNM6C3RUlAGXeeQ5Yc/Izyrrfx/LdsnrQeAoVL48YMtcir1at3u0sHmsBn1aSGQZFIaVrsPRKfqPFtVoWEEFOSx7e09Z6l6+wIB1/TxJrilfEyYm/ZBfDKkUUR8VkSiYN5v8SvU7E7MOZzF8hxrCVEQp52PqlgNNZQBAjsMO612q7IwK4UUnSCsa4pkHPfC0OvNb314Vt7fgvSGuyKomUiXyYN9Hu6mchgjmZgIzy7k1Dpu0q+J3Gc0W8ySmnKJw7f4ABa X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0eb52201-5a29-4e18-ef86-08d98c7860c5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:29.9213 (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: FdTWBYV/z/mRafSgOQ3B5myJdXH4zRwPI4UiaHA9tWA+5n97mSYXKL8d3f2zaTD7oD5hNMBf6Sgcp7alEETqNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: 2S72oCM-XaXI4yGqj4CXiL9ruNGkuqRz X-Proofpoint-GUID: 2S72oCM-XaXI4yGqj4CXiL9ruNGkuqRz Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" add the libvfio-user library as a submodule. build it as a cmake subproject. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- configure | 13 +++++++- meson.build | 39 ++++++++++++++++++++++ .gitlab-ci.d/buildtest.yml | 2 ++ .gitmodules | 3 ++ MAINTAINERS | 1 + hw/remote/Kconfig | 5 +++ hw/remote/meson.build | 2 ++ subprojects/libvfio-user | 1 + tests/acceptance/multiprocess.py | 2 ++ tests/docker/dockerfiles/centos8.docker | 2 ++ tests/docker/dockerfiles/ubuntu2004.docker | 2 ++ 11 files changed, 71 insertions(+), 1 deletion(-) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index e804dfba2f..88fb44f15a 100755 --- a/configure +++ b/configure @@ -443,7 +443,7 @@ skip_meson=no gettext="auto" fuse="auto" fuse_lseek="auto" -multiprocess="auto" +multiprocess="disabled" slirp_smbd="$default_feature" malloc_trim="auto" @@ -4284,6 +4284,17 @@ but not implemented on your system" fi fi +########################################## +# check for multiprocess + +case "$multiprocess" 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 diff --git a/meson.build b/meson.build index 99a0a3e689..5c91305f2d 100644 --- a/meson.build +++ b/meson.build @@ -172,6 +172,10 @@ if targetos != 'linux' and get_option('multiprocess').enabled() endif multiprocess_allowed = targetos == 'linux' and not get_option('multiprocess').disabled() +# libvfiouser is enabled with multiprocess. Presently, libvfiouser depends on +# multiprocess code, as such it can't be enabled independently +libvfiouser_allowed = multiprocess_allowed + libm = cc.find_library('m', required: false) threads = dependency('threads') util = cc.find_library('util', required: false) @@ -1903,6 +1907,41 @@ if get_option('cfi') and slirp_opt == 'system' + ' Please configure with --enable-slirp=git') endif +vfiouser = not_found +if have_system and libvfiouser_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 diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 5c378e35f9..515ae40d1f 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-multiprocess TARGETS: aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build @@ -142,6 +143,7 @@ build-system-centos: IMAGE: centos8 CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system --enable-modules --enable-trace-backends=dtrace + --enable-multiprocess 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 08b1b48a09..cfeea7cf20 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,6 @@ [submodule "roms/vbootrom"] path = roms/vbootrom url = https://gitlab.com/qemu-project/vbootrom.git +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/MAINTAINERS b/MAINTAINERS index 50435b8d2f..661f91a160 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3420,6 +3420,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..f9e512d44a 100644 --- a/hw/remote/Kconfig +++ b/hw/remote/Kconfig @@ -1,4 +1,9 @@ +config VFIO_USER_SERVER + bool + default n + config MULTIPROCESS bool depends on PCI && PCI_EXPRESS && KVM select REMOTE_PCIHOST + select VFIO_USER_SERVER 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/subprojects/libvfio-user b/subprojects/libvfio-user new file mode 160000 index 0000000000..647c9341d2 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 647c9341d2e06266a710ddd075f69c95dd3b8446 diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py index 96627f022a..7383c6eb58 100644 --- a/tests/acceptance/multiprocess.py +++ b/tests/acceptance/multiprocess.py @@ -67,6 +67,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line, def test_multiprocess_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' @@ -82,6 +83,7 @@ def test_multiprocess_x86_64(self): def test_multiprocess_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' diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index 46398c61ee..646abcda1f 100644 --- a/tests/docker/dockerfiles/centos8.docker +++ b/tests/docker/dockerfiles/centos8.docker @@ -12,6 +12,7 @@ ENV PACKAGES \ capstone-devel \ ccache \ clang \ + cmake \ ctags \ cyrus-sasl-devel \ daxctl-devel \ @@ -32,6 +33,7 @@ ENV PACKAGES \ 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 39de63d012..ca4dff0e6b 100644 --- a/tests/docker/dockerfiles/ubuntu2004.docker +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -6,6 +6,7 @@ ENV PACKAGES \ ca-certificates \ ccache \ clang \ + cmake \ dbus \ debianutils \ diffutils \ @@ -44,6 +45,7 @@ ENV PACKAGES \ libiscsi-dev \ libjemalloc-dev \ libjpeg-turbo8-dev \ + libjson-c-dev \ liblttng-ust-dev \ liblzo2-dev \ libncursesw5-dev \ From patchwork Mon Oct 11 05:31:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549045 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 149CBC433F5 for ; Mon, 11 Oct 2021 05:37:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F40D60E94 for ; Mon, 11 Oct 2021 05:37:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4F40D60E94 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnzq-0002r8-CG for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:37:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuV-0002Vj-UH for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:39 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:14356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuT-0004AP-Nz for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:39 -0400 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 19B2iHY0010266; Mon, 11 Oct 2021 05:31:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=jSUqZWzYsyThnFjykQxNIzxGxuhVA2UyBajG0xpbnR8=; b=j0TCKEpU/4EYpdpkF0zFxYIcr2aCDtGuMIMgc1ViBeei3eXmCJzb1iUUxrJWZhiV4HEZ PyJJaB5nAFoBB3AdTUD/DdiSvWbXHkiOWcs/dhpI2XDJXjnERv1gvlZnkQMtDj7E5k/g 8hwiTOgzIB8x6bbw3zfpVuA0ORN//7JQ5j57Q5guo4wCbGD04c9y+I03UUDEkc9tMoQv CxG9QmfwmoKgumGyMP9B2yX93vO3tBeXwEcMgcXrVTaz9xEN4mzSajDZXmKx1qzC/jrE sxDk9W40dnb/AaegaslBOruDK45eXdDayYmH6SNiy1wh3FYodwCUvPys0uq1w7dDyvaA Rw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkw3j1y1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:35 +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 19B5UHu6084545; Mon, 11 Oct 2021 05:31:35 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by aserp3030.oracle.com with ESMTP id 3bkyxpc91s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oHD5is9ZD+qLO8HoD2nZvGQZZGJWYWWzD5fl3vUcQ1Usr+6bBY9r6zn+LUOlMvmX62J1doqKpg8UquEDKrXNeUQvNzsefU3RJIRVGd/+RSFVW8GFAYQE+xIVvUD/be/6slUyIWmU9vrPhVfk+hCIaRco67tn5GqlLJnd0OYUmM4J7fD2OzOY341m1LbbVBaiWQbfJk5rBHzC2azqzEmC/IAQSxTZ5rsMyk3m0dWsQPC3zXXUMuYdKlyDGjymwxC5i5adRfKn1qciq4d7QWcP4xjjh5fB7l7LM1Fwn/PN5c8dnV2s3eXF/n7Q2FfG1p/CQUkVvnx2EFj/w2pE8ahYHw== 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=jSUqZWzYsyThnFjykQxNIzxGxuhVA2UyBajG0xpbnR8=; b=blCnQZZZy0OqeZZ61wNxYdCB59KX7HGx+5AcgamDJAky6cR6IZWFxKfLctdGrHUq+lFCQHmuOqkDKd1f3Un9oV30a8ZwsKu8Ufshd/4njpMvpSy+N3f7jdaSTA600Kij6AK8Xre5r3rraAO9zswlaR8mxA+0EtniHq90wVREqL68H16k25zjvOwgJGhF+djx1pHuAa2Cw7hXLE1GRUysdXJMqFs47JC7gbVnxP3hW29bBhhUaXCwS0hKhz0g8OYnKNTRVxZg5ueS6EdUz2q1j5wo/P9HzXIkKJefU/zM0oAonHcWrQzRk9IuVydOqN+sZpaYZ8axSDc0dDbrMwqqmQ== 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=jSUqZWzYsyThnFjykQxNIzxGxuhVA2UyBajG0xpbnR8=; b=iKHa6lwvmWm0CJTeR6yxaiEy2yatUhHL6IH740EdRezWowRLYXqc+9ck4OrkPtNtrbfjGB7v1rsnY067xI6ICx5FoebpCZwPtDSRL9wat8QcneOAtxyHtx+XCeJl8PXis+k0msTbzyG26VvxIo0uxTBa3nM15ABPAsPwN3cFWNQ= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:32 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:32 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 03/12] vfio-user: define vfio-user-server object Date: Mon, 11 Oct 2021 01:31:08 -0400 Message-Id: <13dba991f1de91711e5c3cad9a332d6e7c5eee7b.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d96dc63-6782-4e1e-64e2-08d98c786271 X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True 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: g5pekl3bYaotbev/9zoZibBWb7Ro6hnqot6fPybs7JE3Xw9zOnJg5rzaDR37pkTgcoPeoQy5HrJj4aLfBXgIaEuAJI4GHTvvypR0cYMuIQEEYxhJgA89qhCRPDSwNi9LA3Rr+3W0mTY9Is9Au7daFwoKkOHM8VuF1dEp2PCSVHguG18MRaMnB6HS/ThsXzfsfP7pG3sud5Xf+9SzDC9oRFO85z85Yl92YBZ7+3cbQ1oMH6RIQXnbJbPPqUAko3RnX36oeSmXtMGvF0R+M8vHHDjQ/O/HN5xUfX9IyzicgDhDV0M+VeW0uPgJGSq/XyVxT7+SCmjXaLZhbCALmvH4SCU97Qu/+56x23S5g7y8yKLG+xk8KITtH9qfeUKx7zvMqCk0Y9H6GkoC5SiGG1IEHQJEbdSkx2FH79X4s8skSiUFsQjrmfWhhYGbTDKFV4cQI/G+BhIGh+jPKTQZ6lksNLR5+RcKzVoKEc3gbHGfsLOF3C8z3ch/kMa/3z5b5MzfnJT8Cg/37Wdzt4vw17Z588ExtjnMhMOQ+7gSp8wljWH83bM8k5bM/e5RSLiVgSVGQFhOoPH+fBWgqX1819WO855liMch5n6Vloka8V86ReGhnUC5SEVgSMIqHJkpshtOHbZLElVSEayoE7TsBJBFUry4VilP9qa5lYpydRlEJgYITJhXM6glpT7O9NFseUmWisrXhI++v9U5/7MOv/zfhw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(83380400001)(66946007)(36756003)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1krdyqcbHfGjGoYDE1mEfSQAKLPs?= =?utf-8?q?Rn+Yj3WpDi51EuwFgDvsuhcNwsN/p0TZDf2AkdfF9Upj0ifTeUYCjO0mqJWH6KmXL?= =?utf-8?q?79aMN7qt/DSI1AQH05F3usj2nZTVBLUMavEIXncmDC5R17tpc8kxXS8Ty2rival9H?= =?utf-8?q?5LiHkalC+P9sQrpHjN6EzEfUQ+WyHFes26SQdO9lnyMiCK2N2r9l1k6mGCZq+8W6v?= =?utf-8?q?TqvbS+yI2HxfH2HkbmM6vU0QUXukynxtlvh2REcHzveUa44w31uUxS1Le7Ah2er/2?= =?utf-8?q?uF2cMkMh3EUqN/DF5su0zP7Uf6iswmS12KKfK1/rJb9VZMCbOMqQKqMXB3JrlfMPe?= =?utf-8?q?LtqmD8SzLl/6icL+PeHnzppBDoUKWkHJJMHy1TmI6OePj4Z2FLbt3xQl1ATzyISSv?= =?utf-8?q?6tPoFsaOWsrIXRicN5aOnc7Q9lmUkTByAf+/fpdcKf21NRIwkBbZQAeFcA7yonSfs?= =?utf-8?q?/MirvIYNN00cvNvfY6qmTerA8FGuwn85FSHCv75V7XKzBAMoAwR3DhAgGifHuEQuN?= =?utf-8?q?HNnq5/yXnuA7Y1qOi0Pp+o9CLi927rmtDb8rcB2vEotyKkhjX+HFLDCZKqKlobOao?= =?utf-8?q?DfTTENms8yqXMVPW018jgbfzAnrCaJ37JO/AJRWQF3akjPlx9IHeqNHwrvwZOU+jW?= =?utf-8?q?8+E8St178npOHooqXYIkyMONw+2ygzavUm1V5gpjLvO/a7bDAZH6zHaPVax+zJ2zV?= =?utf-8?q?LqZRXhvBaxDfh0nSLTLxOR/cSLyLmJRHLnbda5ZRRAS5mWM4PjK9+BpRlp1RLR5ol?= =?utf-8?q?oN5maYKhxJNrRVQ38N93rfeGRlXZF33oUi1qT4gALdgSkNZUazETvpoKNSpL1sSIU?= =?utf-8?q?aifTVlrxj/hJQWY6S4mWPRLweM4zE4nQB7KVDB4oqVwZZvy/CBq1lMSIyh0OlvuWA?= =?utf-8?q?BxQ7kSGHAXch8Y9vfXNrhe899zj3lTuy2zB+giwvihI1dS2MYPsbIBwkjgkTzbeNN?= =?utf-8?q?xhWXx1SJIQ6vK9vBEWkA4e7q/SrDfe3u7CETTLqYwJUcC6GmG6eYMMT4s65nSpGSV?= =?utf-8?q?yt9UOvq7E3Esd6SLPBw9Z8MWLBh8zaPc3GBTDJybnnYf2Hf4Ny3TE/Xdq8tJNQjeM?= =?utf-8?q?Szduam+reJ6wnGqu8edMftq+WbLc3zFg24daTX9/f9miK+lFjHgqKF1E4YZtTPVuQ?= =?utf-8?q?vbqMZb2tBDFI9Z5o904sO1FGW0Wbj8BM8lSfs1B8HmGO5J3gQMpyYcrHbJTTtQxHH?= =?utf-8?q?vdFtyi2EFC8N4K6atMu7TTbLvnsCFyGiYifHhhW2W4jyg3qhCtgt7CitEiZAgr58c?= =?utf-8?q?B06sbw3frGOv8pz9?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d96dc63-6782-4e1e-64e2-08d98c786271 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:32.7287 (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: dMOyECdquFcJrBrONpaqga9dWcb/U4Bae5IcbMNver8T2qZf74836jZPNxEP8UVBZy+lap4UDVQ4H4/sD6RnkQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-GUID: 7f4HYdFngwyvuhZCaCVI87VEMfQlAxCj X-Proofpoint-ORIG-GUID: 7f4HYdFngwyvuhZCaCVI87VEMfQlAxCj Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define vfio-user object which is remote process server for QEMU. Setup object initialization functions and properties necessary to instantiate the object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- qapi/qom.json | 20 ++++- hw/remote/vfio-user-obj.c | 173 ++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 5 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index 0222bb4506..97de79cc36 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -705,6 +705,20 @@ { 'struct': 'RemoteObjectProperties', 'data': { 'fd': 'str', 'devid': 'str' } } +## +# @VfioUserServerProperties: +# +# Properties for 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.0 +## +{ 'struct': 'VfioUserServerProperties', + 'data': { 'socket': 'SocketAddress', 'device': 'str' } } + ## # @RngProperties: # @@ -830,7 +844,8 @@ 'tls-creds-psk', 'tls-creds-x509', 'tls-cipher-suites', - 'x-remote-object' + 'x-remote-object', + 'vfio-user-server' ] } ## @@ -887,7 +902,8 @@ 'tls-creds-psk': 'TlsCredsPskProperties', 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', - 'x-remote-object': 'RemoteObjectProperties' + 'x-remote-object': 'RemoteObjectProperties', + '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..c2a300f0ff --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,173 @@ +/** + * QEMU vfio-user-server server object + * + * Copyright © 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +/** + * Usage: add options: + * -machine x-remote + * -device ,id= + * -object vfio-user-server,id=,type=unix,path=, + * device= + * + * Note that 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 "vfio-user-server" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +struct VfuObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; + + /* Maximum number of devices the server could support */ + unsigned int max_devs; +}; + +struct VfuObject { + /* private */ + Object parent; + + SocketAddress *socket; + + char *device; +}; + +static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->socket); + + o->socket = NULL; + + visit_type_SocketAddress(v, name, &o->socket, errp); + + if (o->socket->type != SOCKET_ADDRESS_TYPE_UNIX) { + error_setg(&error_abort, "vfu: Unsupported socket type - %s", + o->socket->u.q_unix.path); + 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); + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_setg(&error_abort, "vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } + + if (k->nr_devs >= k->max_devs) { + error_setg(&error_abort, + "Reached maximum number of vfio-user-server devices: %u", + k->max_devs); + return; + } + + k->nr_devs++; +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + g_free(o->socket); + + g_free(o->device); + + if (k->nr_devs == 0) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static void vfu_object_class_init(ObjectClass *klass, void *data) +{ + VfuObjectClass *k = VFU_OBJECT_CLASS(klass); + + /* Limiting maximum number of devices to 1 until IOMMU support is added */ + k->max_devs = 1; + k->nr_devs = 0; + + object_class_property_add(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 661f91a160..79ff8331dc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3421,6 +3421,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 Mon Oct 11 05:31:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549051 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDE74C433F5 for ; Mon, 11 Oct 2021 05:42:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D0E160EE7 for ; Mon, 11 Oct 2021 05:42:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D0E160EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZo4f-0007rE-Fo for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:42:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuY-0002b1-PL for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:42 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:18020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuW-0004SF-Jj for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:42 -0400 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 19B2iJkR010295; Mon, 11 Oct 2021 05:31: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=MnAuyzO8NIy0t8VjKsUyX7D40GbuQcHZlVKJG4GvpWM=; b=RpAjKTD6WIJQKfDX6uOl2TmDgMqKjWuw29Y2Zp0x0yRrDQWbAY1hvv/gmSf1Fz67WvVe /25s3640G6fLBD4rQeV3L/ooQf6uxWUrsTTZM0jp78KNGEFfZ6oaHu6tKizVkB/dhp0e TdC2ChnOEkX4eglrsUaQtznW3qPb7pNChaQNXGlaUnw4jKdCECDVOoac0GcEvep52HJl lM6TMbqF98CwLUcyuQP3cX8jawk2UIBt5ycsP0C4AdY32QpEjXcTeEbm7p82rTfhB+7U QiV+vqKBucgEpDXUzYKREFuPmCBXmvHBjLm73FY+X7F8k1bc6xON+2t6zofc2HMU3Oc0 yw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkw3j1y20-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:38 +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 19B5V1OX123589; Mon, 11 Oct 2021 05:31:37 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 3bkyv7nt8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rm0Z1prwkGmKC5oHCEu0jL9XvQe1nCxMyyW8owUZoJn2hyhbYfWNHkMbt4jdXB/oEFziucRechMfwKJJzbLYKV0+zQ5sNgIuqh6MMR+PmJTOpUuAttv9epmOV9VscMIhbhlAuT4Mpb8JrFcxBlT3PHFYqTv4sn1/ASMGhJZquGafCubPy+0zlmSkuDFqqe35BM1YrekrH6iSwdJvE+c8eGpNhZMqqxpJuvU/a41nWIyqHZmDZ/pjxm9KEjI/Ytlp4Xga04WWeN338pfg5nbzR8FH4GZfD7oc38ZP+JiDtQ5YAQuXO1OdtUDNnUwuHom1WsfYbgDEnHFAocpXTCdnXw== 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=MnAuyzO8NIy0t8VjKsUyX7D40GbuQcHZlVKJG4GvpWM=; b=F6wROzQBE2Yjt5AcIkOG+dSYT9L31S7UPndpFd6rBgjNNW40k2eYI3ADP7dGfmjw3l11oGS30AE5a+1jetS1XWbuRgQKOt0SDZ//1V3trSAqkZMZp4RInOof1ctKeQCbA+5zjRbX1zSKgUjX8SBqDgC+VuL/VgLjqb0rcGuAi7myeAQjBsuLv2AFwxmDcW83Zxy3uGITzspkhXIUvGGaTdCQuMkzlV8xFYb1GZIh6uMoevZvkZoyoSrT8HxPtqNI+yW8iehp8mQ5SZnQNXEgnEhLFqFamO8dnLalDFuqCF1nvSRByT3tq4HSi+j0ln3Fo32MCvgx95r557iXa5m9CA== 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=MnAuyzO8NIy0t8VjKsUyX7D40GbuQcHZlVKJG4GvpWM=; b=L2ei2t8tjXKdxFFnU0fC0lGNc+LVnzmKXB8Zj3+Dfvvqg3fXDsrsf3fMUuc/NyxbjKMF4UrcjDuBgYM4wKRv1SHWEYrQ7DU5rIKlFeMyZoR7J6BlQNYJVOJChk4jE2VCrMOxoeYDZdb/bgt5ZyWvhDsQqpuqKEKlEkEbUbmsvt0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:35 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:35 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 04/12] vfio-user: instantiate vfio-user context Date: Mon, 11 Oct 2021 01:31:09 -0400 Message-Id: <82b00867c07020fcf71749627414a80ef6b691cb.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1859eb00-0074-4127-7adf-08d98c78641b X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:119; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0spmXai5jQwTmU3NU0k3SOMDFPYDE6oSFSXUtq0bfmfm5Fa11nc0xcZ5MjWdUn4SkwAhbcrJKb+u55n7uOnSdKFTpxtyF3wWeOawHOi6cRpZnmC+CRKsPvQpsjlRoLPXfxzZHs0LfD+9yZ0F56+KaGJPGNI1v7t7jF0Io4luNBEwxz1dWr1QCs+LH0dITcAwlV6fjZMBMcCk0LfQrW4OOqZo/mYBeAf59DQrmJldh+RUVN0Z6H1mAPg567mAGf5N+m0my1/UlY3KY1NpRl+qkoEjzn8m/HIV23FppcTPBB4Myevd2vv4MikBr72M1fMpBMY+xbgVJn9kdKoOwBysbr+b17rdi/L+Nd9nUZYPpiJuNbLGxPsWTVA/a3pdXv/E9ggmFbgmpFpAZkULfQF3fxjwwd9NQ2yhBkI0komshJ6MUj71Vt1W6RXEc0bqcrIdo7Ws3mxAC0bLB6nTnnO4ia0ZC/D3H1uJW/HI7TUCs5YpILH/K+sxDeLsLYyTZcc4I53CUtqBIgCjfw+nOwm/X/tMH0kzOGQfJFtorlS040I0dadfFoQUYHPhP5KI5nwWgp/fP2c2kwbTgslKYRo6zHi8fzd8be0JjcZHW+6YFdEJlLL7rt/NjckZjEXTfErh9mkj9E6E233VXStzsDkAgTqxI+BGjZnyE5SqsgTaZIVyf0HTo0VV4GscN7kOYBE/ZhdKXXuKpFQxaQamSEGT1A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(66946007)(36756003)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hNn/WFF+3gV0vci5DlKq1pRSrgI1YHGEQ02M5Xwmg764PZ0+i1fdmdAlPLqcFmqOk4VVJXgs0uAiSOsS+g5EZ8BO2KAL7jxmA6wSQwNAvJqHTTMZtxm9pNr6YvIzcPP61HeND6IkA7dMQPaiIDq0Wf8v1KzYcjLrDOoIyTCit98d2tdOtdLTkyMCmFe7eDxQMjmeUaBxRVf8jcv2RZpP8W6Aly+NQ9HgfVacxe1H9J+RF0oYZQ0aR7RsrzWw7oOeAQkc4hcBkPgCUbfBl3gnQK9+FIQLSyBkBtRbw1XyWwgp5qc8kcekmA7eCiWMROUnR6bNPZ3VevGjIaDGh+aryJDDvPvY4cQEErzFkyPCOB4UpAuBC8E7roVT1dEAbG9CXlbHOCYriCs2v5Im2A29nkn4rYpO28mDH1tJ/Hzu1lFlYHiWkvbEbkHKEf49bwefEsv5ggysLOZs16IcgFXBUlm2Co9Eo0reCndZcdR/sf9uR3v+ePFb3Vl81SB//Y5mzZ4PAqpaVmY4EYGdM2cg3EL9aaVDao0C7bztub1JdaeNM6FMtswfKL3WLUpzRokfRT4Li7p0LszIP6h4u16yADduif0OKMSUVkY9PFUzbaBnJGPQklcyG7+HJHrWHh9C2ncm+ZAlJKW54Uw6FLuu4VV7y49T1BlVCFN2mBXOWI7KuQpNlHeV2qw2yqMUiLhqOgf62t/59Mz2lOsJ9XeybaKQ5fbd1XZjo1nxsqfd6Mbh/LXB0J1wGtcdh9Fq5VnEMJBy/+Uk3O1O2NoW2bWRgq9H6bIJ4jrCfZUgD4z6cYge3KqMsUEYUonHCasa39/ckT7Hvc+ZEiCn6oLos0BA79habLTW6IdXdVFTO+ebTnMojFcMjJxhYDYCnrfBlZxHhgR9zSCPVX/xB2lINstXYpeLucgRCw+GP2Ho/YgX35DX2/87KAOL0JYMy52By0eJoKw4qDZGIeXLQTHedUoG8FpgE7me2IEVN1bl0wLpcXKcrrYtc1seUN2ZE8M7IYKjoV2tZhc969cCBEH6swyhF8pisEhx/bXoNG9Xo7ZHbhmW3SgVJkfG/zylt/v34uPkISQJmY/9XA4AhGRbaS/SMZCd7Od+ZqTvqrZ9YBNn04WP7BX8esUnFjTv3+L1xi/HkrhZi+ahLzK4m+10jv0ZBaR2jbHBcmMzBVs4DZchk5KaDuDTxvzs3RX85nhWQb7gwS78mZj3JfbajYJO4KCL4deEwZILFZG5n7+3JwNOM3vAJu6bstW7ytnr3W5R/cBMK0N0cXZkm+lS352f8mxKN9DfGQRihzLFkG5MEpjjpAKE88LcZInoT5OmRk9pHwpG X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1859eb00-0074-4127-7adf-08d98c78641b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:35.4861 (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: IU/R4fVpr2qIZYPHMGortIbjo5vwoeWeLYn3I0sOfKssmBV0kLCtFEXLpmjhROB47fMLRT9nJ8kdftRLzpzEOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-GUID: liD3UZOf1OZizAFWKA8y6am1ouFhJvqc X-Proofpoint-ORIG-GUID: liD3UZOf1OZizAFWKA8y6am1ouFhJvqc Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" create a context with the vfio-user library to run a PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index c2a300f0ff..d26e5ec9e9 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 "vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -61,6 +64,10 @@ struct VfuObject { SocketAddress *socket; char *device; + + Notifier machine_done; + + vfu_ctx_t *vfu_ctx; }; static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -94,9 +101,31 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) trace_vfu_prop("device", str); } +/* + * vfio-user-server 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 vfio-user-server + * 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); + + 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(&error_abort, "vfu: Failed to create context - %s", + strerror(errno)); + return; + } +} + static void vfu_object_init(Object *obj) { VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { error_setg(&error_abort, "vfu: %s only compatible with %s machine", @@ -111,7 +140,12 @@ static void vfu_object_init(Object *obj) return; } + o->vfu_ctx = NULL; + k->nr_devs++; + + o->machine_done.notify = vfu_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); } static void vfu_object_finalize(Object *obj) @@ -123,6 +157,10 @@ static void vfu_object_finalize(Object *obj) g_free(o->socket); + if (o->vfu_ctx) { + vfu_destroy_ctx(o->vfu_ctx); + } + g_free(o->device); if (k->nr_devs == 0) { From patchwork Mon Oct 11 05:31:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549077 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19A5AC433EF for ; Mon, 11 Oct 2021 05:44:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58B1660EE7 for ; Mon, 11 Oct 2021 05:44:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 58B1660EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:59610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZo75-0001nr-AH for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:44:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnua-0002eb-Nd for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:44 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:20806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuY-0004VI-VP for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:44 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iJ5v004463; Mon, 11 Oct 2021 05:31:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=1RZKnaeEAYkXhzRLSn1V/tLPa22KWwgcgpeT9yelbmE=; b=pIUO1QZmbrH3YJB9Lmh7tUY4XEPROc/Svbt14JnIEXoN9qK7pWbiP1QcaUm5BH+FLVcC GR5E5Ola9WF0zOZVSB5eIbDm1+pwt/hKfSV7diZhqrnWRnfMmRIIUD26Syxry/qPVy31 nHPIF6m4tCiV5cIZIxpCVqiWhzMUfwRiRNiQvFmJfTubkkZC2XlohQzhEBuosXy534Yj j6i1oE6huyWered8Knfn6Bi/fEA5anbgU7yaNNhnbZXBT6zDcpSduGiImC2t3kEFgevP LAcea630Vnc5jR0aJTFtcfIAvAgH20PQLmLdGIFn0JIl1GOBjdeG9qt0UTPYHznkKrEJ rg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkxs59thv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19B5UI0X084620; Mon, 11 Oct 2021 05:31:40 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by aserp3030.oracle.com with ESMTP id 3bkyxpc94y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=naUjWRhx3HDqVdAZDxaHW8h6eXvB+b/FTMGBsrrBAlhiw9DqxofDk4/PzK7JIC2jqnFTsa6Ifsw63vX2KNPgiu1BH57in6xRU+8X4LgCZpRpKyQbRTjP8mNM44IsV573wflakCUloL7wPKB22ZKPIXY/CP1Ul24FZSrgMhtewqReiUOv0qh02BVq9+g14dZIJgqJjGG2s5PLIlHclZ0E8/PSJ4nkCkYUcpTrwTPrYCfkPJDpdcjgNdUlBUh16lGJv4G7c7U9XzglUcuiJPBnUcMS0GLvup4QQ/T7TufZKLT+pUFmN5+xFFmESkdp1B584Jfiig6xVHLrnixn0f3WpA== 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=1RZKnaeEAYkXhzRLSn1V/tLPa22KWwgcgpeT9yelbmE=; b=P15rO8ImVgQHTaSJY1wEqBywFc21E/w5BTOgfjf3T9MziAmmKfkDVVIoRNLaaNXajSLaHqD8GYMoapnJwq0hc3mvIRFUdeCC1qc2kG8I+IvakUZkpFwfciGDqBgoqdhS/6iwj+/x9OSHHzbyswDn6mu617RDgVU1PfkJBfeh366Kgp2/zHl9Lu/2JZIocL2y7lA7hMxAH1CWjy5Ig4jHiNYmJN7VR7UFH7JpZhl7EtSYj8T24GVUsd92tRXWWOpjamFr1ZNLbyUHDJMqw9QFsEon1alKEY3e3gBMNb1Y2tbNXGQp4j9TNANq3SpQd0k65K3taSR42rCw7Q3KDFP5WQ== 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=1RZKnaeEAYkXhzRLSn1V/tLPa22KWwgcgpeT9yelbmE=; b=Eekyu6QxTwcFB5I2TkGjW4VwVyUB0tIP9oS34cO95PExJHVbVWbrrYGtIDARSJ9/hgaEvS2CO+Is8ElrSxoSZsX0u87X7d3QkEy15NhH/KjnxrTBE2lz6Sui9CMtSgkbKNpfwCEVsVzbGL/ziFibSFq5IS0SN9Pfn7rN0DtaHEk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:38 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:38 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 05/12] vfio-user: find and init PCI device Date: Mon, 11 Oct 2021 01:31:10 -0400 Message-Id: <697ee91edc2af1aae07a01d49a27156d0e87c00c.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d60bf8a0-96f2-4d16-deea-08d98c7865c5 X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:158; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: geznFlPkPv35p/PbqPTLViQsVqqXqq7RDhnsWnSnWylz/4mEeN5HBl23PcEx7UGwWimOFSjKUyCXWQ/T04+HScCXFJq/64qGq6KsskDgIjwthG+KujljpWuAsS1Itn11X8EDJNa4vXZvBj/AmDvsLosk0k5mx6opCz6OeKVye5C6XlK9HqAKxffQHpUqKiluiAbUuzmEwWBxIt6MvsWCjAhc3ayntuKYxQ6gBOlwWFyC1JiRRntCATygN0vpFSBl0fKY5FG/UPg2o05iQ+NPO6HgwrdgDWDKl7kFsVRRE+pan8iR7FkV1zGo6vKaK+O+Xz6hBInxOkbXWKGa6Keehprulx4O18PS12JIlwoySeb4hSa6ultCekIDzat79pMOwhUSmFJuZWrkqLYaP2Q4pYhmfqFifby7cqCLX/rqHfZJtudln+ph4LbcritcVh5khg+85QdYcNDYEGv4sDDhorfKUBzk8nDRRmGt/9yQo+rUgXlfsWlUWhtPUcfMJdzHyTdbuXYVOPyAOW2w/tloIpAXbhG4WbSLwyS4KynpKf8LGnfv3UTmijGWiA+NOiwrZzebVi63elohqsEcF6FCnP78p3Y+yOu/kJ54ebEJDX54UVyB1trzVe5jb6SZzEoU+6ODEkFR2jcClckRGLSFxHvjlkqVxPCdC7aGPkD7ZQ+X+GMIIFFjLVRmXl6F+jPsBLQ4DnhyiBkaZlrSfic7sw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(66946007)(36756003)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +4fEWTvDiYRHCCEfnehthO7uzEOYLjhi8HiF8oEbUuJrUnhY0esqgQgVENiVe0e058neAimz+Jo2tNypXh4LuV/UcnOasJmVwI2hf35vU3eS2seD655ZFk5+BnpSknD0PLseccyGcmXVTkaKe7zj5ahCzBkLYigaJDaaXnI6PFGaRluAdQib3BG69wJFWlnddtngTy8g8FqTBk93VE2ca+CYjeIdhf77dPL4ID/choJAhNp4lbHrMBcFp7TL6GnEBiGe7Uqv562N+gF9vgpKnjTxH2tiAyYAqdvAbMDPkBIUvEV7qNs2GNFkLUH0RDpOK29szg3TCBwFz0bisEkX6TCgKvJbndRcFJ5UUEmAu1AJ/4XdaykWX5Z47YqXk+YGGaBJEmmUtkPEtaEbjK+xtb7bsHMwkIYGHOYY8PjJBe6LgJQaTRqLjASsxYFfvN9uALSCtPwDAyEakVhCnYMljVgByq2TYyRQpepacu4gFGH0sf9PJ/eCsYFpooRCEmMQwdLK7zaQXLn1cPYUqjA8lqQ5BpTM1EO2DNvij1pXGpcRzWwCedCkTsY1Me0KrDkwhrck5/bXwSiSvGQhVqJPZ208GRh/OfviLWDKcNiPLuB2mMA40j7Uhp4Fz3gPhwESzJyhdS+h4Vb9MGK7BwKRs7neBA6hWiMLcARMsMEXy838bRMF/FDXO8epqYuskk4TaJnxRIxSu0csczv7bYcwOjK45x0RHTAOuoUbzPywIUrPKeEdgGSS45cDwKpO/1gwkZBanUbdoqwJgXfTg6c45zL2IwrYtEXTI4U3ZVE7cGBegOWLPIMGXVHzBNGBfAsVrhH1sUYGmJ3d02iMMj7bM6xtGVxgVASxG3/i45FAni/NhjmZr0mX981MXICIi+r8Mq7zCbmL6bSxY1wjhPLnSFq+wrKR6Af4TqDNznjpcJwcCnmJBbqK+kLvKnhlrioeXiEjNSlF7lIa/wFEaB/7dcZaOsbZC9i7nRN4pN9ph+YHJ7M4XxWdQauBh6nZnTax/P9oumNMsMZRL7LLBmdo5IQwkjTn4G0rhdtthAKPzTPya0TR+eTSsM+GUKt5NcF470biUTOGHnOLdT+sa6ZIWR1MPKWWMOE8FCq7/ytiMmzMMWCGLyFPxqp6DzjuuJxuTzdcqcCwsmZPk1p+mHqnyIE18PFlsZLeTIysQ9rBbuXGfAPNQu7z0cqD+tM7wGRBVJaWjkPs7QfUuJKJqx3DsYtxrdAdMIlue3QA0TMVzJUMmqcE0A8jIOedlGiC2Yvwh3PQ+vTifl7s8so/qG/6FJB9CK7QWvf1VNNMGfOnfXlx1O/8O/NsDds0XMW9o96Q X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d60bf8a0-96f2-4d16-deea-08d98c7865c5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:38.3215 (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: JfjmexcMCant0PqHu9HzDNKNzPn9M+e3yenijNu+m4G/LTfIVrHrBVlZ/VtUwQR1qTgdKLzsnvEwaFwu9wYXRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-GUID: ZGHqJ26PN727LyWai-Z0EISo_qHxmsEK X-Proofpoint-ORIG-GUID: ZGHqJ26PN727LyWai-Z0EISo_qHxmsEK Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Find the PCI device with specified id. Initialize the device context with the QEMU PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index d26e5ec9e9..7ce4e5b256 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 "vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -68,6 +70,8 @@ struct VfuObject { Notifier machine_done; vfu_ctx_t *vfu_ctx; + + PCIDevice *pci_dev; }; static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -112,6 +116,9 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) static void vfu_object_machine_done(Notifier *notifier, void *data) { VfuObject *o = container_of(notifier, VfuObject, machine_done); + DeviceState *dev = NULL; + vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + int ret; o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, o, VFU_DEV_TYPE_PCI); @@ -120,6 +127,31 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) strerror(errno)); return; } + + dev = qdev_find_recursive(sysbus_get_default(), o->device); + if (dev == NULL) { + error_setg(&error_abort, "vfu: Device %s not found", o->device); + return; + } + + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(&error_abort, "vfu: %s not a PCI device", o->device); + return; + } + + 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(&error_abort, + "vfu: Failed to attach PCI device %s to context - %s", + o->device, strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) From patchwork Mon Oct 11 05:31:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549041 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41475C433F5 for ; Mon, 11 Oct 2021 05:37:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A165160F21 for ; Mon, 11 Oct 2021 05:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A165160F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnzi-0002Oq-AP for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:37:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnug-0002lT-NH for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:51 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:16704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnue-0004xf-Ip for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:50 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iKRA029456; Mon, 11 Oct 2021 05:31:45 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=eD2ekZl5jjPFtCy3GYmlWleMdhKmcbLq+SU4rNCMLE0=; b=Eoej43TFODPDsVw5dG+yeEd/SFGFP+IsqudxUkbk5hA4w/zHc8lsf4FQqmN+/d0FA8/K uKiyHPVkosYQ4co5MmiFZcERm6k+Do/H3SSupTNF7ulC6kWJeNoC5m//Y8O1TXk7M5jc 536NSm97S8xX3hHa6A01g1QcNrqw9dP0Ge2LApuJDw7WNaNYQrOPZq8/Ll4U3KdC23d3 Zpt7Zpf1wUAZqTvA4paT6hnqd32n/wa5/1zkAISwoUDXhaaxiqCCCfV4PfRaYpHkJTJJ kpRalb544pmdBo4Tt3/g+8OqwUIY5giglTkYqd0zhyFvYrNFEiDctW2ZlmAs8vxYw9ld OA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwxh1v8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:44 +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 19B5UcR5104800; Mon, 11 Oct 2021 05:31:43 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by aserp3020.oracle.com with ESMTP id 3bmadvqgw4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IgicnqEnznp0ngefvMi646F288jDsdfwu/0mDYF968mDyNuvi8wa7PHFbXNBCEkQrggUwzLwD10/MbdodOT+lBoHXN1tuI2ifzTbEuFuC/Eqztqa8dj1+1NAbg7YE5rXYuY69Pz83pa5z3SrSdWhxfxee1mzxVAu9ye6vW6/O1b0GmImFOTzK0pl49uoQHdvOljoUGlh8/Ai0uvMeS7iU8VuiV9TM4r5dJV9HFGI0W2dxQX0FF0HW2pDuIPLvJiwU/l+iyVQjz5t2ycBuLM4hn2pKL16BJYzwsoWkXE+AJ/sK8w1fgWBrY3BwpFdhG7TQMGUq6DoHvRdgv42mETZrQ== 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=eD2ekZl5jjPFtCy3GYmlWleMdhKmcbLq+SU4rNCMLE0=; b=UmI4y0FQKODXB/Gvrg4dcaLDr9c9WAP3pz63WLDM9+U3ep+QGS+Qa1JHWLYicKKLZvHPLZY40cW8NObmRswkeqhasAr7DdN4SS+HQWfstwh45/ocvibloAwCfRn4/Cg9/3zd3z4wPhGSz1/2u6yx4cjjqGQhUlyXJjR5DpV7n3YfOTFN43DIcH8DnFDP+LkQTjMB5m7qJWmoplnMllw+T/Pf+RWF1022by98iHlZ5Qhzg8dkcnL19aiyHHky2m2IY7KRczWjnlPHEUUomfqrIGNV236oNC7QRjizzdON2SzKgp8B3Zdw177urrmzfrF/vThBsQrLbDQSVVUwjcHRSw== 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=eD2ekZl5jjPFtCy3GYmlWleMdhKmcbLq+SU4rNCMLE0=; b=QDLYfeFx5x2wkEOAHPFpBPy8L+0tsoTTTzfyYpJPmGDpNWS87NkZCZGw3YbTq3UkUrRvh5LdvuALe1ssq9AF/W0ZCUway6eet9yYWKa757hwDGZ4x3UvNweirUwnUMIAkK1x4MKoO61EGO4fqGTATgwHHpSYJKf0KWo42lHO30o= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3902.namprd10.prod.outlook.com (2603:10b6:208:184::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Mon, 11 Oct 2021 05:31:41 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:41 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 06/12] vfio-user: run vfio-user context Date: Mon, 11 Oct 2021 01:31:11 -0400 Message-Id: <489671ef49381437a03917a87dc143dd9fc90559.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbf07450-92b5-4dc6-6dd9-08d98c786777 X-MS-TrafficTypeDiagnostic: MN2PR10MB3902: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:428; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l8fVW9P9dH34DZ64Z7Zxo7snL92EG3iANjqxO3MZY3jTcFznvgZJis8KPKzr0qXwtxef3RnbYazztsZmIaa+4M5fBSRP8udreE1edt8O8KOsWS0Lm7g85LfijcijmYzZM2cnVjPcgcHoEGgAPciC3W/3ucYmrt7gUj16Tfp6uDOSz7PcZ3Isse3G8JPoA1Bn+fmzJnPlmZzL8g7iuhQq476Jeo4MQEbjqPIoPb1Kv6jKCV0iRvL4Vm1Tlz6eZ/CrMU62F/8l8m7BlHRm+URAvqPSRv7SU4OsKmoluh1TKUBDpusPHZSEGd1M4jyNWnz9DlDPSwnqXfLnbJPR4nxQJjin3Iig/9HLVoKnb2rEESnZnLHP+0f96L6Gn6Sw/7Bn5mnx3IS8l6qz+aIpLuiLSxQoTlUa8IzDkRwaCTgxdx8i1TypyYtIi4SluRL+679hYi7LlXhgi59e7JOnyvM8QSQKuSN5qWW7Rnb5Vq+ESBKSH9YTkw5tUQEXcTcuHvDLnkBIoo1fDz5tGx8Luapa368Lt0AIXI13asH0hNpa3d5arZ/zsEZc5q9coM9KUpgFL59yKZ3zeDYen3+zOPT9RokFfdX6mDaOVWhDs11tw7NBvW0qaRxjaC8S2etHia1SVLDS4kjc+Y4r4k5+RBvZmISX6/5/QJ6fSKpjRgJXxuonFpLp5aoML4+GviioZZ9GVptqO9Csari7oImV95/yBA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(6916009)(6486002)(186003)(508600001)(8676002)(7696005)(26005)(2906002)(107886003)(52116002)(316002)(38350700002)(6666004)(38100700002)(5660300002)(8936002)(86362001)(66556008)(66476007)(83380400001)(66946007)(36756003)(7416002)(2616005)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lq9Bf6dXMTr51Fb9vcR6iFQg1JVjLqiNgq1CbdlJME5tzrbPg8CFFdl7+dmXjRUAfeNfoXTaJblEMXmhBY7CWdEESDWEndtIYwIHdosrgQQnSsufH0w64gufSdAF4a5eDUERU5d8AUrwLFUOlfAy7lk+pHI0TnWrdzefuc2JR8r13R1+LKm6h2jJ2rMucrpU3oCbMQkLUujJPHaA32F4qZDSjjxB8Zxjl1ffLkfW2VqOQ8E01qM/5SfgeubxuNaHtyd2Mk41fisZibQnLwx5rAx7LPTEQkNx7+frtDhuUMZenTiPk+oGwTBikAr/3xROoNnMHyqEs6mCkwV2Qfj96Q2slG12YUcCkfF6+uCd/vEBvMY6QswBsXWvAuxTn9+Bg1MUgHMir56Ck7ShiFF5T7LK0hgZCZZsSnXO4cEXNHs/RPfFqocwNraUVMDJuGZ6J6sU8nMfJcKpeFOqEuAR/E3P8gsJdurnBti/qdLG1Kiup56zPpZF1tJTozblqxUuS7LqwS7PutY9XwNQKQdsVMlpN6/UxUGcN9aZCshuX01uCKlM8vYB1jN/mBtDtWY9wLi8eJsW98QfDOaG4yVz5yVFPDeW1/Yi22dmFpAWgaztTpnqpHf82/CY0+ngeq4iKw58E1L+bKNWntzsJIaGgRUgpyVeu9oXPDHQKGmKut4JFaavgqt0mtkV1j5LxarfkPJQx9Ht7f75QsSkkRv8QUzD1cTTKne3xJTJfA/oQE70s1Z0oVARDKWwHXR/e0xkR76GxzcL2uXo8CmTgmY7Uyd69cXFMeRtRyPlcTjSCXKXCprQB7is+l8/byPTo3VipVj7s+KbZpYYIjXLVkpDjNHYNQwwAJPCy9hrIby2fypCqz3sR4zBS5O6n+KS7Qi/vqfgoLx2QrqOucxJuD+Cs1Hfd6U33nR4TNfsulh6Mtly4Xmh0faa0+YBuIZd9lYiMGPsEHc0cmgqmZbrqUOV230O9hPpgQEHGHEzYmW87uh4Yk0JDKZ81okrj/uA4lAHQDNqmxbQmalef1WZcfkpG/4Boby5WJF0c73fL2hgj3C637+rJbVE0mjHwPvP6BcjuI9IuFpsX5ekSULaoQvkF5dpWTdPG+zvhmxVNg58iPcEN0eaZ8j+SXvkkwYWuKvlKfYLP/Tagxx0XePghhwAWx/puYHJujj0G2r0U9c1Wc05z3YZhaviBPk11lAcMMsnzLeE5PDm7MDzulDtlMAY7Zt4fcDQLkW0qnIBh79rFTK3x3NBnDb8IdOBwUG+CAtkrJW2G841JHjYSXWXEj3Xp2weouim2euPmH+iVPi+VpGyNzP7eA1ETP+9ocIlXOiz X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbf07450-92b5-4dc6-6dd9-08d98c786777 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:41.0999 (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: pW6yyMZ+jvqeF2eFvkQhFGmZi8wRPEwMPEnKp2HleGKb+gP/koDMaGqTRPPBeVYUUDMflgC8Yq5lM2QeeC5pUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3902 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: SIOVuzC2WtDD7KdPNfZSaYunYOTYwU9n X-Proofpoint-GUID: SIOVuzC2WtDD7KdPNfZSaYunYOTYwU9n Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Setup a handler to run vfio-user context. The context is driven by messages to the file descriptor associated with it - get the fd for the context and hook up the handler with it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 75 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 7ce4e5b256..05f7fff19c 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -42,6 +42,7 @@ #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" #include "qemu/notify.h" +#include "qemu/thread.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" @@ -72,6 +73,8 @@ struct VfuObject { vfu_ctx_t *vfu_ctx; PCIDevice *pci_dev; + + int vfu_poll_fd; }; static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -105,6 +108,58 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) trace_vfu_prop("device", str); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + break; + } else { + error_setg(&error_abort, "vfu: Failed to run device %s - %s", + o->device, strerror(errno)); + break; + } + } + } +} + +static void vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + int ret; + + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + goto retry_attach; + } else if (ret < 0) { + error_setg(&error_abort, + "vfu: Failed to attach device %s to context - %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(&error_abort, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); +} + /* * vfio-user-server depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -120,7 +175,8 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; int ret; - 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(&error_abort, "vfu: Failed to create context - %s", @@ -152,6 +208,21 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) o->device, strerror(errno)); return; } + + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to realize device %s- %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(&error_abort, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); } static void vfu_object_init(Object *obj) @@ -178,6 +249,8 @@ static void vfu_object_init(Object *obj) o->machine_done.notify = vfu_object_machine_done; qemu_add_machine_init_done_notifier(&o->machine_done); + + o->vfu_poll_fd = -1; } static void vfu_object_finalize(Object *obj) From patchwork Mon Oct 11 05:31:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549039 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 464FDC433FE for ; Mon, 11 Oct 2021 05:33:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 991C160F14 for ; Mon, 11 Oct 2021 05:33:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 991C160F14 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:40326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnwY-0005Rp-Gy for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:33:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuj-0002mC-5q for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:53 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:20142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuh-00058h-3l for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:52 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iVKD004162; Mon, 11 Oct 2021 05:31:47 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=kKkh2AYJK6EzLdF3/TGOZT9lXWqxZUlv1hHLwg5om8k=; b=cYJEjZDwe4Az4uVBGDRIsmyDSmvamFxMTl4fiOcqluMkVqf3GtRjUuG3G6ItlcjOElIh CZtLJVg26MmmEJPpsPLXQfFMJ3RhXEQ40HZXyoHnLRraWf7MMRZhJwVqezQL3huxf5e9 51PsOaqGVVRsms5UBVIzws37bFHhrw/lbjYNRpGZW4VHmBKLRLoGXxVM9UsNnwX7meZp E2kSEL7zp8+mRBa/FkIUbEb0xCNbnc1O6qd91yUWgtOSMI3MOle6V2C2rLenA4xpqFMc ecbF/uJjTDKluY4v9ZTCJ/QGwkFL4SFYhXN+AcSvQvCFO1xOrEYH2tN+kdxfESpapqfq Ug== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkxxa9r6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:47 +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 19B5V1Te123600; Mon, 11 Oct 2021 05:31:46 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2040.outbound.protection.outlook.com [104.47.51.40]) by userp3020.oracle.com with ESMTP id 3bkyv7ntca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BAcGMCbluiaAnMuzbd7cX0TLCG74hDmTxoCfsWHos6iBg7TXXRmYRguqX1aWIv8JtWnC4WbgVvdR4lWxGxHcqA1Fdfut7b4TSIyfLvkBMgV0ZyFgBU3t70zG/fQYDZLKpP21+52bQuBAmUFfRpdERsKSstPpEwHkYLyaorfme86EAik/XhB1wOW3wv5Fld40BVIDbDwmWzxZqiAqVpyIXsPKymgirApnA+NJfaQAGiQN76TOU8/m3w2c46d10GsUO25bTtjqhrQbOJd7mVvdNmzPexci87SAeZnRkmFDRoZH5rtM6PcmuCz/t33zQoN8mgqsStPMne3oKSTjLw3/mw== 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=kKkh2AYJK6EzLdF3/TGOZT9lXWqxZUlv1hHLwg5om8k=; b=OHg7pfbhYg02YQrcPZFwk6b79AibU8LBsLKrWxt8ru/UGM/Mt/ntUZXS9nWLoNBwFmXMbW3V2tXCqJvAfUY1UruiTOn+xYYsxREWjsIQHpKLRwPdtdgfWLSfIiuzZoYnB7+HABMyJ8F/jMXmAyeRTY89oIJv0TgWUOv+8fjjrY70VkTthyv3klOtUuNv6MfpWbbnT+jWpxQWnwrPn3TPsVrmXxQOQTpZVMhedL7c/AqKnzvuHPyMbnLsLwi1Nod1qP8FDzSg9jtABqzY4D+1q5N/bURJy4jgzY9kChdUNw0iboZi77goLvNXo44A873SlBtyA/N8aUnaX49qW5sXwA== 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=kKkh2AYJK6EzLdF3/TGOZT9lXWqxZUlv1hHLwg5om8k=; b=Q6M98NW7kRCzjSj3sOVRYHEcUn0IHrmOtJBYgHJ09KA2y8Gby62h1NvloIfXPtUU3s4QEhVtGbRNAqNa3ZW7xNYbaX/vDA1NCp3J9nhEQ/HoP5+KLekNZNSsA9d8Lv1h9zIDSrKyg6ySn8CP7xymopEYSlEL7njyNoS0sJfnnAM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:44 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:44 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 07/12] vfio-user: handle PCI config space accesses Date: Mon, 11 Oct 2021 01:31:12 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c099d46-efc0-4e25-209f-08d98c786919 X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True 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: AetoVzM2q6lS4AUn9uYtCv+DZkSHAReMRTqU3CfQgl+Fg/O/aPWEluy94eYXsnX/AIInp6TI7JFCR1gFGCiR9lC5w0BIp1nrtBvEteC8d4VdYbySexdoQG5H4rzTuJFAcKp9sdEKnXg7qkILMMqto3byfvjEX574RUNFfEFlvMjRQ7wSNp/yl/BsuFPvwrENid9mW7WBzvjusSmKdD7QxQPYCpn/PmvmA0bHFYXvoI1oeDOYAP4/Gq3FfVCYurV8/qG98TP/NF1NbsmKU0v1qYGCbG0gjXbo7edKxWEdtgiqtv/sfPUeTqCgjnzCTCf+PO1vZFYxD+mISJirq6r/W4Lc/mrS6nBeIpbI4N9fJYW2tTu4cGmVsHbO8x9vH3LtikVEDuHYmgZmRnLb7iayUX7YKJK8Aa8u/m9j/8LOhAjys/w24NPJ/L1HD8vnmU9M+BMXyNAGkFsBeLbpsi2OmAmMO9E4Ijv7JZC8WtkRJHv84RfchqUzhk+z63MYqlmS8L3d5MfIlFFB11PJXgxWN+47PaGLsf16E7/1lRRgYBocnCmPyJqnTATLuy48W8PgDKJ/E9Qjc67rokBpa1C+K6O8z6YQvjJ2j+p3V44yPCsB0GZERm0t6XQ3ZsJIqfcrdYA1kOX6IUU+yErcNJN2cJ4KETA6i1W/GIcrMEmifzJ+/gcbo+Pk9u8bQ/EOBwGnGUc7v/mrDnZvGWup3OJfTw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aKkUNezJa+Ssgav0/BvF1hea2i3engl7cYWg663ut/9M3OoGRXJ5kH5HY53sBfyqJuZza2g8cX3mXc+97Zjt5IfBW7tNk3MinC+Um+kwu4hcvDwa9B9kzwuqCwQ1hI4qi2wpy/ZY7c24IdZPt8D40AMXNFpaRWLNNVhEikZ53r3ri6wzJNRY0OhYfXxgbujOOViEQ0bgflRk5P39+jIBKz6PDc8KpHS+V8h/ExjjEvFpDCtV4ZW7LoXIwhTGMTUKk2aZB7GhdKr61BNLXdaP8NAkeYE8ERmXHU2z6cbNT2w6lCMMcjE1n+DM3mSU8vrO+H0562GJOKmHrkAF6mWFEMpxBP9rD/EAVHR/hrVWEaRZsrCwcAOGM+sZE0fxNkEtnBM9XqeqopTMaijI/Ldxk0q4kI0XdIAvLyPhNzi0TqLLLS4ns+MlI4pgZRZQ7tkSQPcj8wuHXBv1XdppE8xl0yoDCbFa7UaOuAWGglUfTMhvRdR8uVIszwogZVrl9M/xkJLgTDOKtbi5Y1d7TW2gDMCnatscFKJIIfN/tWGU1J2G5jnOqEqvzhzR0NqbT7gdKxJnz3q5qr2+PUZA9J6bzTn+NjHHRg7X57MLTG3nIk6N/FYMiDINb0elVRZtbCXqomnjTWgmGQih4NHAyKBZnk9W+bgvKNFKKP+c/B7n2VuA0eZ0L6Z9uXp/yGdc6Lz3KI+C9Sq90E/tvMKoR5fD/JcV6hL9J8VrBv3PaV9UY/HjkVoxZxcTcyo5XGLUXVbceIRMCGy2p1kUsjOWE7XrHocTZpzcAz+lTPcgsNNkZrbn65fLPyX5i5MncPcfwODdSd4rrhfCC2F5mHk1RFvqd11cIgf8ClH8nZ6pH9uP7rKa+LFYamlaxHqOGEQ6K+yL+2KuKHVKZNm2uw/7CcEtuECLIs1wXCMTi8OA+ZVrc86nRICJWNBKHsTgbum6Ev7qqJs0L3PwjU9wIN9/UMwjWvQnmPaDIt3JhRCiyMCXyCuEfJ4yh5xzRHL+RXvfJZT5pXU+fip4Dd5qA5PvdxQbmRyqrq1zDGmXUbRvHc5L6qiJF1Q4QY5nS4w5UYZ350wzyULcjcBb+fBeY53HFbttQbm1krH3Sgek54Q+CyavtNZVMjdGHds056S4aNL5OVb5wX8WWxoh0vV64hD9lfXivrg1mLQmckYiyKY6EKmojN4SqhtJ1EgD2+aKV86PiLrYGpFXSuB1VMb78Fy32ilCAOIJkmgqtsPGTOB8uxqg332xjWm1pglHe9eL9QhNbjkCv80ocuvVhyylVn/mMueRl+Y1OAH+OAzcduQHsjO3rbDEKWMpoM8GV390W5GTGjKC X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c099d46-efc0-4e25-209f-08d98c786919 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:43.9153 (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: ldsplhJ+PWTw2OWXd7c+hjtGWC/SJ3iLuMMj/eBTXixaj7B+cmAGdI9t9Fpgf31K0xef0W2SrNPBn1k+oFKdQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-GUID: f1Mv41L9RpZ2Gf8TQyfbdveI-0uQb4x2 X-Proofpoint-ORIG-GUID: f1Mv41L9RpZ2Gf8TQyfbdveI-0uQb4x2 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register handlers for PCI config space accesses Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/remote/vfio-user-obj.c | 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 05f7fff19c..df5843c388 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -43,6 +43,7 @@ #include "qapi/qapi-visit-sockets.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" @@ -160,6 +161,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; +} + /* * vfio-user-server depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -209,6 +243,17 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_access, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(&error_abort, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 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 Mon Oct 11 05:31:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549043 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58CD9C433EF for ; Mon, 11 Oct 2021 05:37:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D401560E94 for ; Mon, 11 Oct 2021 05:37:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D401560E94 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZnzo-0002mn-Ur for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:37:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuj-0002mD-Cf for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:53 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:31602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuh-00059t-FF for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:53 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iP40030029; Mon, 11 Oct 2021 05:31: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=bAUutKHE2DkefOKBu7WeoG75kIEOnQLFXmqZHbGUynY=; b=or+VS/SShlWcKM4se4ltPojGriKRJDU0arSCfY2eVDz0G8GbDzhje3U0ACfnfVh8rQ+H yPkNQv8rc9v8qC99p/Kwusfpom/cP/J2EmK/AoPQp3DCLXEQM5eXZxBLP7ybqm4L8ueY V2vcQXXpMwIRghIAxhHFzUNzcyf1p9lo8iAjQpLKzclHRxR3fkX2OQyIMVSdtbsaQ/rl yDYLVCSA3TAnP8K5SYfVs7IvdoivXVxpuybJwMzR5W/6mUoJgFA/lmqIxYD7FvEKMu5H cKUAPcTM0Ugi3DJGSTc1AdweBe5HhVJYL2kdd5+/ERHhnWxVphYFccYotXfUbB8D4ZoB Zw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwyuhw37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31: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 19B5UxG2064025; Mon, 11 Oct 2021 05:31:48 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2042.outbound.protection.outlook.com [104.47.51.42]) by userp3030.oracle.com with ESMTP id 3bkyv6eymf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l8/1We2oADMCeD+xcqclwN4X/zKOC3fNOfrKlcpUi7Vh3Gla7mlnH8E49+R66dlusBgn76UZKGxyl8FfBbvS5ROA3ZsMq/0G6/+6b5UFZ8Pre/qo2L2o1go7rxFFJRgN0eUnZBqc7TskRtdsDclHBLXYFpAJ03shyhOd36VEJHP8AbmnQo0FlszpniDttYj59hTQX/tn59jlUIPCI1gqL3Nr6Lacyqbw91gDWRQtcH0FnGX5janae3alwYxZUA4JTzZ1HN0lM48H5VQhhELqUzpyW8Y/yO1UZm0rZB35a4UhcKivx25aQdpIcmBykRahpDhPfaeWUU5YYOkudtgHag== 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=bAUutKHE2DkefOKBu7WeoG75kIEOnQLFXmqZHbGUynY=; b=ZwWXknXdPeR6xMY8FvnORN0tGMicNtrutfocZplRqJH1AhQn7AxjBI3h9pmIljSApZWzTWPULRCh/7GaJemkYxRpsRPtw+DFiurbmfaCVRTOe80+efJULi8w5ubFNeQAkPPmWJWDWQTud41fdmOPU9nAGYSXXDegcZK0cJ1B5Qe1lCZ6EQ8xMIn3e8N3sCnCgdp+/1+gdr3tZ2pnKA/yMpVUUmaVGJncSvbPRnV6WOsKtZ54QLSxvYF13kGYU+dFMvKitZniZEzaGKHvBaHJgoMAzXIl+PY9JwC9hGKsh1vVc4Txb/o9UwXMmc9A4aORN+vgDOn/54zyYypm0Pm9Mw== 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=bAUutKHE2DkefOKBu7WeoG75kIEOnQLFXmqZHbGUynY=; b=isCEXUDRxR9ov1Nwp34KZLLmqknOoRTzMAwhrqOJibol3G4QXiGk0SExq0suhxIfvg43lKLFQNfUpMvwdAJWo3UPaK7sTezRVqpfzAN4RI4I3uoKRXPWHs4lPTTSZs8CQJDuDHfmUQP/fXAAuUpS59Q9olRZY+tBE/B8nqnKSDc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:46 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:46 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 08/12] vfio-user: handle DMA mappings Date: Mon, 11 Oct 2021 01:31:13 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b403503d-a323-4420-95f5-08d98c786ac4 X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True 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: Ke+ip7pX+nuPZeumrdSZRiZIDCBkJEpIZo/ZDbF1XqT0rfU4Hrr6X9utLm3PN5Ugtpb/jJD3F1ruuD3xylk64dYuh80bNgHgYfD45FdkknuRj+eZQ84NJ8mouFc0BJYooQeQIQ6gcKWY7oXo4nEzZ/LE+xuHZU59U1qbLuVkwTQz8PyKNJCjMuc5xwb7ehys4PUVFfRjUpFGB9yRHNq7pSqJBWl7d0vyatcwLlRj/FquTtHPz4RGeFTvkP7tabrfsvDPU4nGKE8FF9o3tR434W1Cz/SVSD/GTFP6238e7JonZd3aCS/59fTNCSGEDIkhKw4LFIi2YSy+8BW+8hKYn1HkM07Ds0v7+XKv9DNs1N8h2bTeaIRGhLsh8ggHGRpl7vutMuS9xI78eLoEaE3QDyhks09t2h7I51FqXtv2Pd7kTZLPQyBqlQXN9lvLe56cauELTawTj3iZsbPBGwgS1PncnOUTiGoAoX4igyPWZVuJUTCifQP51bBQrxTAkTEbiaXre7raW8Yen0YBCViG3D1SF9ObtK7m92qsmb1RZ4fg92IVuSOe8VjVeQVr1OaHHQPKtEoTSRvQ/pZC4NUrrXP8ADCx5DXOTbb83CPl3d1y7oMJomIEpuQk9BGVi9UE3FVpUT7uekc72VJvD9VGvoxBfLcIpySD2jgLu1s8eF5KooOR9ukx2foVJ7+7J4+AhdyB8nsmwJX4lhE2BnegYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wNNkchl9ZOpO1OwmGAxsXCYOV9qOc4RDQlQVRo1OTgDgSRCDq3lqNuUsR9gd+BKjyV7VJJ/Zyi3IntCXnoIkhgQZO3ZwJps9ytWeQwSuOWSG4JHtuZzbc8KuDoeAOAObFNFS5OVkdh7ybAbzTBpnbArlxph3SdDFFnEa6aZm0qVx+ByGc691qY24PLPsOOsoz4k8dEDkiAC1pQHgaUsjZ1i3A1DZib4brp4pWHU0zdMjxI3I7GeA5dZDwhBOpu8WwFUaEImbKQU25KkiCdm9AfNWYKWgMJ0u8IEi/GqM64oPHdXvqPuuiYzGIO2fro0qLnAtrNnZ26z5XzYePTUHmmUwjir0WOL4NmAArLlCAURlig0HEWB1A9pkG45Isgqrpu47KZlU8kDIe7gCuLx/x85tfPdZsfIZYcSTofNRF90WRUD+73UykRvwHwn+Wnv+YWarOaZyokRObkK9ReDhaL1ojZiaFVCFjjozH1c5f8TblQT65r4z4ZsEXab3jtHwxTfzIEy3VEYScuZfB8/exo/IZq+QOKjFrvcQgVNvo4LFVu1oTNeb9LZxygDkwN6xR/nmPVACfQLLb0CdAHXH9tk0cLrd4kJOUcHsjq1Tjn0xUNXQRIb1yJrShvGmh+61t68JczTskYrk/p42qjK2PRw7k7wbkSQpI0wmmOUKHJZg9mkumQUeCiRY2smoSRe2eNjmxOZR25wntdNFowS6WXMaxkHRYU0sUI+mBmp8vScYFq2CKq2BRZXFE5q1+aGdE/4MaLxGaK7OWJMh8kkcHUifSVpSSnb00sRurCthWOKmdiyj35tB2+QN7sltm5ODVG2oiPSTpS47W6Qrchru0y11cjqhHyfEVHy5AeBSZlawrMB3ttSIJVN4khqvP7R1ZVSSgzmN7vxOR3ZuA+V8aaYxPWZkj6y7PgqQd7+QEUBK357/YM73pCc+ZyzLwKbeog/yv1T9GdKRU1Sm9rkV7zJBCgzCDDdC2jwOlYpivH27GNEGXC8q6gmsfR5Hn90tarH/6aYdoKV98ussv6LwqIRplq0NDtrfefMFKOSl/Jv/XFMis0edt3nddHb3PbpbWXl5IjyLYdCoDZqxrqFbhwHjH884eorCRpz3s5HBtcj8toGMMxjt2JEz/gttywkHIE8H18870eUm0peRqXmtbNHm6HZoBm0An4OrbvoAgCEEQtuk+Gs3j8edJRg5dRyNQjIpu3k1PnkqC+m+020RELwFUyFrLX54jz4wB1emyAhLmKEJbuVP+hfYKa3Od2uLk+eg9IYDSAHr2scNv43FwMjS7QrTCCRwIRRrVgnut2fp4bBwIZIE0mxt/whR1Qhg X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b403503d-a323-4420-95f5-08d98c786ac4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:46.6847 (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: mjz+clN+A5/+7Cy0CJpDBsiG4C49ECcY6dwd8NuGGmTgd6A5PkmzLpvajUQESkTMKjTA3uuJlokC8EL5C8BHlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: JlgYiR7FEEvhiNfTLOkwn1lNsN9cDZOf X-Proofpoint-GUID: JlgYiR7FEEvhiNfTLOkwn1lNsN9cDZOf Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register callbacks to manage the RAM regions used for device DMA Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 50 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 52 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index df5843c388..7233562540 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -194,6 +194,49 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, return count; } +static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + static unsigned int suffix; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("remote-mem-%u", suffix++); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + memory_region_add_subregion(get_system_memory(), (hwaddr)iov->iov_base, + subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static int dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return 0; + } + + memory_region_del_subregion(get_system_memory(), mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); + + return 0; +} + /* * vfio-user-server depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -254,6 +297,13 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup DMA handlers for %s", + o->device); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 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 Mon Oct 11 05:31:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549083 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6875C433F5 for ; Mon, 11 Oct 2021 05:50:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6A8F60E52 for ; Mon, 11 Oct 2021 05:50:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D6A8F60E52 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZoD8-0005Cr-Bu for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:50:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnup-0002r3-6Q for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:59 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:26228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnun-0005Wg-5M for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:58 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iKPd029460; Mon, 11 Oct 2021 05:31:53 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=dd8na7IhWc/yX/0zz8Gc6mTz46vVrNbWL5FmNhuZE68=; b=H5D5iG7j/BRVVMJLEUIRqp7xuojA7rPprwxffoTAcBOwb3EGTDeAFDNQYEpYtKWizpbh B9AB7b8sSXkzUtv+YfNshoGiZeWUR0i6x4MUy1hKbbpP0/iKDpilEEIBDi32VTiNMuq+ ZyzKgnBwhaqbsM4Gr/xaNVZ73lKWb0njrajePpczCG+Zg4NFRBru+bh7cc+FtphUx+Bf rYunQkkPHwdcs1sPmi3KcV5BiltgZLnVoLqr9jSCBrFp7wR1jXJlWPCGugCHpclKdC4u TcCFtAfoS//yrJAgUlOXeoJpOhfZ+EFjbXA19Gl3e0DaZ8WEvIk01WLmocgL4zPQ/hg5 qA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwxh1v9a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:52 +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 19B5V1hi123542; Mon, 11 Oct 2021 05:31:51 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2049.outbound.protection.outlook.com [104.47.51.49]) by userp3020.oracle.com with ESMTP id 3bkyv7ntew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cRvEhdUF23W+wMh3/gPrYYwZ81hgBmUMzk1SWUDBEmG4FQb8q/6JC/hghw4kO+tEZUkgdViTbUf1kuKThKa2HH2Osevu6WatM2qUMg+rrVUI9dn8Y+FoM/2txDNX/7vPv18V1i3dgrsqvID/vAVJCvQ3JJswABjn/B2vjvJFxFLaKpef1C8X8/quVC4ZS4OpTrcphC6T/UwluIqsk+/ogRRuI9dr4/k1QDTQ83DfndVHhqpf6oDL6/NlJSBO2HfEc9Eg9RCirwYZX4qUBlWomIxPIwBSnPBsD0VmCEE8I4uiXYGr7yPTwExtxcSQugEodMtISakfsBE1vF7Klfo5lg== 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=dd8na7IhWc/yX/0zz8Gc6mTz46vVrNbWL5FmNhuZE68=; b=XC5L5ZG4Wb+7qGJee05PhZ20Hi9YtwvavfjTObvvh79y5ILvZXoUvMV5IdL8EaPy3jIySGHNIglDJJMSeacEwKRCPDYmZw0L6qEOweGCyW1temuNYgT0qyEMcA+CQjEJqPm/q3ehWhx5ip2agBOo2v0+N77sLqy1l+0AEWfIa2/ZIzw2R/bZhZQS+fy6lGOLbOtLB7nWIdc/g2ePljAokTtxPsdzznUxf9+dnx6XG7esV2XswsAKtQ6Hw1QRapQ2TXZS5kx21jryl7I8AM8xLzNXgZX+SvE9ucByhlxhPd+nY8i+nX8CjLCOR4yrWTODyS6ulYPpaqNfGkuIolanOA== 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=dd8na7IhWc/yX/0zz8Gc6mTz46vVrNbWL5FmNhuZE68=; b=y7xQS+k16Jm7QIOe46x+s5eke+jVkz1Rp5sCFPBJfR8iZneyU0Oidx2Sr9p1F0YedqNpc5v75nVPj7MOmF+vaIeU2YMR7rk0UEpraPyA+vCzlEKrUCwhuNPwZ8qBWX5PT/Lab4URRNnYGQwdui0kXkSfghEHnnyoX6HFLTJ3Aug= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:49 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:49 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 09/12] vfio-user: handle PCI BAR accesses Date: Mon, 11 Oct 2021 01:31:14 -0400 Message-Id: <346c432d523ac9fdf7e645f8193403385610b5f5.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4f730aa-5732-403a-18bd-08d98c786c6a X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:390; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kdb3rM3kdRzYePNb7Z8zcpSkhP5P+Js5V3pwhbBUBdR/LPGfq8pm66hSVwFP7XhHYyLTNACXpi/6t00GrVna6suA+PhXtgZiAALDR1RXV+0k0AH1RDEFWodehVzJzdZOXZmC81oE/V3GJxEGiuJBtuvQ01qB0FZTSGdys/RC/6ch1BT/nodPJ298mU1ZCF2lZdYFmNCwpY6DZllKVZKFkrqL8Is6jE9hztTcqsSOCix86uDs3g6tvfJw9jvZOXorJ4zbeq7sLzGWssIbGAbvvVeB7v6nL0oK8YwzYDdAk596zhtTnWEjvgaKBfYX3ynAXDwEqWUK6fgnbFkbWwZWzFOan58M+6lFiRPwuk6WltVmh386BmZ05TXO45i4kIXypzuAY2Cobbf7qVWrktKl8QuIVftppb5rjr8igjBl4o+s5d+ecj6hfxAFe3RMemJ6Nw4F7N6lM2bv/vrM3O8hQ7NN7mLK/bT7oOXeBTgcginKuu0j1nfHefEcgBVoLMZvSrwOqRp49suros+IgYF89nfa5tpmc3zzi1XDvRwuOXHjtM9/Jc3Xh23wRBRF4kPPOQdmoslAg0BxKx6Jru0x46pLj30wYHnV6Xq5NozWpZiVZUOt/TFnohb6Zsks7HKSacfNSrwRBsWVHZGskXADcFdQ5x9yn1VV2d17eDyq5yHYd5pulzSUxk4PMH+kPHiJfP0x6ZKTr9MGlxFXyTQPYg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZKB0aLNUfPNGK60LKwuNg0jPLascVKgihnj7HtofWBcAOZgG6I4/C4Ajnpa/eLteb+3stqfGSD7iHZtWwe6PKWSdTUZH4rVBzZ6MJ+LDAj2tOe1/5MaA3x62nMaep1mtONSlCBfDkoW9uBfdm6SplwJW/t8ljwLDjbvuiyqVBXOXjPPKBX7S6Q/OyAEPJ+He6vTUhNv9XfVzQgMn0gOlr/5JDyAf0d6w7zeV9VAvDGSEyZC2bNoFsGhPnYsLCrQ8pOed+VQ2lEXa+wVOP+hsshHblgXVmtZttVhbi8PgrhpW4aGIni3xgshrvVzibQwcmc5oV6PFLfL3gKqKfegxjXXDHM3FkWd9ZMrPDg/fojBV1T1lUSpngzCdGuQ5W/Z98LDrUfaemCXQyboRWBqwEP3rm0wbTia/3AvNlC0dg47uqCrxgVdZrqj7JY60yuljyiB4YvdaiBG7SFjwOu/HlVcrxkHth44f7J5B4LUuckCYu58WdaN2+WOfyO8mbrOMQ9W2EplKiAme1lV/sBgc6FuIsIPwQ4xhEGcb+m1CtvHsv9ZT39by32JhIPqKPqjVFJWs8LwbQ+y4ZG3GEEj/S5g9qiTrEuVzR+a+GxvoYKmoCJcw3ADByOMX2+d5sqSDVqIqwg+BepVh0uZcUDVZo4O5VgGPmDO9+2Cy+7s0lwjZ8Sv5hf6E5rmQ/rEBPqfjHD6NjF9wnkbGNX1JgUR49KQM73AujM2+SLkcnPZZjFDeqYAfDjaXcpS7vVyNEnRH8m49tgU6JI5mPzrAM4twSX6wKqCRBmEWzwDtDZ1MVy34ITit8atUxQ+CdnkxksGn//YxWSObpnmkIz1GwVY2bwa7SnFd54XDWE6BlVkdZWNqhDng1wc/5VE75qjfwzmIKAE5RJSzHXqhD1AwGxMUac3JKsVKq1Ksr29V6rhymeMrg2T5crQE832b9PtaNC/Jl4aYZSQOdSJJm7T0E/c49PTMv8u0twPgm1nhRMPRuv2iVtUbbL5Xtqy5PxkkYjQm2sedZj7ksDwy+ChM0y2itUAo6E+47YdgIKWsj4NTFf2H8GGEkJAv27kcPsByproUfTzHYrH1NgHXJo7H8YhjovV3oil0arrWa+DvOcOg3T4rxUA5GUycUib0TDH1t3ags4g3jv+L06M26fA+ZdcGmSmUs5p7ff/qLONyKtyFv3Gd8fcbYxUyK4OeIRB+Q81GQ8uVf6b4Ll6LcuvMyR6VH57YXVhkfXxe7JklArX9MEIU4hiOPWJocKM00U7aVk7VnDwjUlt3IdGV8pg+48pD1Ni452VNa0c5tZtXui4st41al0cRi+5923T84S/4PVWe X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4f730aa-5732-403a-18bd-08d98c786c6a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:49.4731 (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: xyGBdN7yef2c0E8omXdT9BwHgcnBCHRrISJU7qQHs0942poPdNh/bhXZZELs/Z+SdkWnIpXrIoS/Kwws/hx+fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: savH-VLTPTN2flReK51wDw8VJiHR7Xh5 X-Proofpoint-GUID: savH-VLTPTN2flReK51wDw8VJiHR7Xh5 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Determine the BARs used by the PCI device and register handlers to manage the access to the same. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 90 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 3 ++ 2 files changed, 93 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 7233562540..4c9ed1543c 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -237,6 +237,94 @@ static int dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) return 0; } +static ssize_t vfu_object_bar_rw(PCIDevice *pci_dev, hwaddr addr, size_t count, + char * const buf, const bool is_write, + bool is_io) +{ + AddressSpace *as = NULL; + MemTxResult res; + + if (is_io) { + as = &address_space_io; + } else { + as = pci_device_iommu_address_space(pci_dev); + } + + trace_vfu_bar_rw_enter(is_write ? "Write" : "Read", (uint64_t)addr); + + res = address_space_rw(as, addr, MEMTXATTRS_UNSPECIFIED, (void *)buf, + (hwaddr)count, is_write); + if (res != MEMTX_OK) { + warn_report("vfu: failed to %s 0x%"PRIx64"", + is_write ? "write to" : "read from", + addr); + return -1; + } + + trace_vfu_bar_rw_exit(is_write ? "Write" : "Read", (uint64_t)addr); + + return count; +} + +/** + * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs. + * + * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would + * define vfu_object_bar2_handler + */ +#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \ + static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \ + char * const buf, size_t count, \ + loff_t offset, const bool is_write) \ + { \ + VfuObject *o = vfu_get_private(vfu_ctx); \ + PCIDevice *pci_dev = o->pci_dev; \ + hwaddr addr = (hwaddr)(pci_get_bar_addr(pci_dev, BAR_NO) + offset); \ + bool is_io = !!(pci_dev->io_regions[BAR_NO].type & \ + PCI_BASE_ADDRESS_SPACE); \ + \ + return vfu_object_bar_rw(pci_dev, addr, count, buf, is_write, is_io); \ + } \ + +VFU_OBJECT_BAR_HANDLER(0) +VFU_OBJECT_BAR_HANDLER(1) +VFU_OBJECT_BAR_HANDLER(2) +VFU_OBJECT_BAR_HANDLER(3) +VFU_OBJECT_BAR_HANDLER(4) +VFU_OBJECT_BAR_HANDLER(5) + +static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = { + &vfu_object_bar0_handler, + &vfu_object_bar1_handler, + &vfu_object_bar2_handler, + &vfu_object_bar3_handler, + &vfu_object_bar4_handler, + &vfu_object_bar5_handler, +}; + +/** + * vfu_object_register_bars - Identify active BAR regions of pdev and setup + * callbacks to handle read/write accesses + */ +static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) +{ + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + VFU_REGION_FLAG_RW, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * vfio-user-server depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -304,6 +392,8 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 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 Mon Oct 11 05:31:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549049 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2406BC433EF for ; Mon, 11 Oct 2021 05:41:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FDA260230 for ; Mon, 11 Oct 2021 05:41:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8FDA260230 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:55876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZo4L-0007hS-D1 for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:41:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnup-0002rg-Qb for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:32:01 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:37564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnun-0005aM-5U for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:31:59 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iJpN004469; Mon, 11 Oct 2021 05:31:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Vi9PKes132A3iAv2VPOldOG/+O0grE3rrtKOITb32a4=; b=KAJgZjlYD4OEXmQuOKjm2MEYhddRAUM+rCuIU4ddlpvEnvp/ZSDeXex1h8G0wi3O//5C jWLnsIMBtHGnzzy06Xe6vJK2xGvVq7Y6M2ED8MRVCHXuljVDmQo4zczBlgjbrIkQKzgy s5lw9BnGigabt5xktm99L/iBCatZsDN3JK4SlvXmixaoVzpgjwW6WEBpyarE/bqjUjG7 Y+o/vWbjEB8Jh2OQoK1myBV93hUw2Yr6buztQaTBMSMd4AdSsA5NraeeSCOiODckAL3/ Cl8F/ZbSHEAs7aBOVhp8mb35Vha3Thow7YLerinP0X9Wna1dSDi5lJP/zkAvb71AjCmC Hg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkxs59tk5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:55 +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 19B5V1dN064299; Mon, 11 Oct 2021 05:31:54 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2048.outbound.protection.outlook.com [104.47.51.48]) by userp3030.oracle.com with ESMTP id 3bkyv6eyqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2sjVSHAs3s6LHWV5osk8YDR4cP68Y9CNnXXbS+rCiW3ner3MIILzQaUoBfMqfIFKQ2Nd4yJglsm7iZMH+QLDJofVSbnvpr7ixnPTxSnrixDA477T1uoIbjM2MKbkVvk3H5ouuEiSonFYjeBvXJAgjyWKLk5N24lYFz416FErwuEymVzzMVI15KeOxLbjpjk/Hz+MSYPEnbIjrnliA1cn0JjgX5sUiwDDO0Pbh+9JvQfnTpsx4YXUBg1P6MZj7SDEUBWgJXuBZRf5ycB57+lPaV7BoDCm9jU1PGONNcbX3H8dw+C4E8Z05dnOdE6/W0tAKJRDUUj99/8j5ltgyXv7g== 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=Vi9PKes132A3iAv2VPOldOG/+O0grE3rrtKOITb32a4=; b=bBLSzNgFjTUE5RBayALxoEDsa/RL/ehRCPFPaCt5MPwgZCnGrg8U+5Zrhnjc2iVtahB1GPBKTlU5pDDQ8VedlpU0fzyW/BRmgfGsFo3RIltp3Bvu/ZhE7I6DOx6ADdVsD4RlzZohzeDfwPGqrW/P8b5tA35Q+3U7I5jeNdFCSk9Hm9kC91wZpLyq9+ugpYvjlLqkGGXM4nefJ1hHdiEb6TXgExflUw+uMOQWRezxOQTOmHrclD0FP5iEGxhiCNqtpYJVAaaO1EZzphvYKw5AZaNRUbUhTXsvVsJqyq3f+I5dRZ+B+fKIzcugIOqbUTjftT4Hr1+BfBHMPrjDYuFa2A== 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=Vi9PKes132A3iAv2VPOldOG/+O0grE3rrtKOITb32a4=; b=zAoNxPBBsC0y5pPGkUKsMzK5StFZ5t4/0ejJekmm2dAveE0lJHRx/HuLyB4U4q2FsRQXG+vZfrLHw8/GzdAbAqQTxwuPwBM6sTeE6eSpZeOhOFSbimuYAG574A5f/5GVxzdPJvjxeK0kYj99uD8srHi4TO6Vrtj0HYKC5TIM1XY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:52 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:52 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 10/12] vfio-user: handle device interrupts Date: Mon, 11 Oct 2021 01:31:15 -0400 Message-Id: <3ce682409fbb7ba8ecb26e3d1491f5250dceb0f4.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e1af8056-3209-4f99-6296-08d98c786e17 X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:459; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P26lVKOyDSg7rQGBJ/rPNRAo7RkIbV6mQgDYhSPMsk7jal3bNUmerbIH4UkhXMZU2xZUdzSSUEDbuxJjvkB+65UMtTRpuomZaok1dQvnvPtoWlZgj5dMEDiovPTrIAuWyf0qZ7WEnSIOYoT3HXZD5cIJ1x0NnWESLli87e9OduLR0v0KXbqnLfZN6Vkw7A2yMXCvUqmcLLsSgBV4/rjg5mTr8tusuLTfyw6RnLDNtgBODcsv0pvfKiZPvrzroFcYlfMf7Vq9PueM6hPe/dJ+fUV6updNCuVAaMOXrBYiNNjY3rC/AKGyH07v+Xa+lvvqnN39vFBZ4l634kK5wopapACUGA8T9PrKgWTCMHJkYISI+buKLGuIIhBD85nsfCPxzDxpN0WeO44dJM5NdWdLhNekcvoCI/sBt98HIlzc9osDYn2OkvdJt07rv9USP/KCjvYiOs8F9d6kVC8dFDaQ6si+oYw4zhQY4iUWj0ijqCQX2x3jliWR/nAp9tLztssOxdLumMa3siSnQ+Dg7inii/o5A/WlOVdvaQMld478e7hkdUgB+W4INxK2Qdqon7FF2OQpv8DmdWKcdi4/cCRXUuZFGtG4+UBf8AODlR1LNGwePjLM5oJaWkdvHYR3RA2mWVyKj4cLZkY5jSErtgbrzngzQWBSJnGhjcKxHt+vcE5gp7zVC2nTjXIJi7uzaobWyPC+SG5LnkUvZBNEWES3rA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gZakfl9vFA254xDj/OUPUbODFlnKXD9qQDX0aMcN4/WQA/uih2CqcSokRSinrDcG70+WTrPggw+D+/vNVIEHpAAvAYtYh+CMQ6hN30+jBFKAt2rc7giT5R7ktkjsIefPHH86QanecOxROsOfkkWU+UvgX0RNbeCG9lLAQHSOteNSZLuuk+riCikEIZ4VqpjH6aUAhlpfvOHDGKqOhmdI8XsQBJ0L89Ix8loqSl5PAN2dr66SvMzODO+HwsAAE1eo7wzcztEs/SWOPftPkkyoI+lsnA7ETy6uieoMjgBpyZ0KgH1JoJl3Wz6F9PdjvqoWDKJLrSfLhUrbKXf7Ec1KwP8AKxK2rwB5qrjCERduDNb4gmNp3Cj36ncr4XhY+kM5NnRgGl6iMEoNBzlSY43HlQfmXDGIP6/nMvCBoIU073r1cuWqrOhFgFZsmqwDK3YNRGmkoXS9nSnTgxjUgw9AekO41+Jj5AO6bIe8H3kbqFeb45o8L0wYbhnDstTn6/mG+PdlK3/8Dt9obmHhVSj4pQ5J7vQspt4bDKTsWeB0M9/0rs4THfhKvRYtdSKv15dO4lX52dGr7e0rCUjpAj3YN3AYAsAd6Yt8xdD3k/j4qx0X9z5tyXPWOKgv+1AyafID+XSZ0A10HzDRgVY79J1GwMKbmOfUsm3Tr8K7a2uU0vFN79hi8TqbH16T/77RD6b1YwdlYJ7PjSTBGNd4AvYBtnH2v5wZSGbSY95/qdREk6peuOAogOF/Q47F013KIIu36v41nbHc2EPQeuXavhLCUut+hBf6HBPJsJQc2tEMJc6/YJdJEQUqnJpeNC/8GuCzwINQnK13xl/T2NRoNUrnAhktwjAcrU+opxDu1lj9tOJ19Hb9cAgfCunO5DDs1H/IQMJsqmzMwT8m4FgI8jAyKgW04CEcv8tcqba6t8V/26LluI4u4I4QR2mvgBp9xPxH5MMnmeeFXUlWbXw+zbb5ehnzSIguNQtzI1wiyNGDJrtvWeamSdUzpo3brsxM5v651FZOHL892akTjo/bmNMFbQcB38tAnOe6dHiLadp4HYIRTGJUPs7qgZrlYLTvOaN9APWIsaborv8G2lcEE7aSgoU3NLnNL8dnXF+OLJ/E5ZDboBFmnvZwG/31rNVpIoucLgsBy7MGNHITVWnxcQf3SvxPYVb9lo35GbuE/3Ec2fNobCXSJfipKTdQTTfGv7iCgWOkJiVVMna0kXZrb7ynOG3eFsX44hYabEKVrDS2H0EfMGvHwAZvjT+5I2Sf6/L4rolYybxeetVsfhYNX+Hh6JUpa6kvTwyz8lqR7IddOT1T/HuoTVYzAzymBM5H/K3n X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1af8056-3209-4f99-6296-08d98c786e17 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:52.2675 (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: uNVtxhKm+dCcugBEGfFicOagK0BG2273KhaC+IvEwVHLSTa2PUw6zzT768mWJHAg3UN9/IE5WvXdWRrPPz7LZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-GUID: l4sVjyn6VL2F4Z8AFC8vp-aU7s8NrI0Q X-Proofpoint-ORIG-GUID: l4sVjyn6VL2F4Z8AFC8vp-aU7s8NrI0Q Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Forward remote device's interrupts to the guest Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/iohub.h | 2 ++ hw/remote/iohub.c | 5 +++++ hw/remote/vfio-user-obj.c | 28 ++++++++++++++++++++++++++++ hw/remote/trace-events | 1 + 4 files changed, 36 insertions(+) diff --git a/include/hw/remote/iohub.h b/include/hw/remote/iohub.h index 0bf98e0d78..d5bd0b08b0 100644 --- a/include/hw/remote/iohub.h +++ b/include/hw/remote/iohub.h @@ -15,6 +15,7 @@ #include "qemu/event_notifier.h" #include "qemu/thread-posix.h" #include "hw/remote/mpqemu-link.h" +#include "libvfio-user.h" #define REMOTE_IOHUB_NB_PIRQS PCI_DEVFN_MAX @@ -30,6 +31,7 @@ typedef struct RemoteIOHubState { unsigned int irq_level[REMOTE_IOHUB_NB_PIRQS]; ResampleToken token[REMOTE_IOHUB_NB_PIRQS]; QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS]; + vfu_ctx_t *vfu_ctx[REMOTE_IOHUB_NB_PIRQS]; } RemoteIOHubState; int remote_iohub_map_irq(PCIDevice *pci_dev, int intx); diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c index 547d597f0f..94102338a8 100644 --- a/hw/remote/iohub.c +++ b/hw/remote/iohub.c @@ -18,6 +18,7 @@ #include "hw/remote/machine.h" #include "hw/remote/iohub.h" #include "qemu/main-loop.h" +#include "trace.h" void remote_iohub_init(RemoteIOHubState *iohub) { @@ -62,6 +63,10 @@ void remote_iohub_set_irq(void *opaque, int pirq, int level) QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); if (level) { + if (iohub->vfu_ctx[pirq]) { + trace_vfu_interrupt(pirq); + vfu_irq_trigger(iohub->vfu_ctx[pirq], 0); + } if (++iohub->irq_level[pirq] == 1) { event_notifier_set(&iohub->irqfds[pirq]); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 4c9ed1543c..63c468d6f3 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -48,6 +48,7 @@ #include "libvfio-user.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "hw/remote/iohub.h" #define TYPE_VFU_OBJECT "vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -325,6 +326,26 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_setup_irqs(vfu_ctx_t *vfu_ctx, PCIDevice *pci_dev) +{ + RemoteMachineState *machine = REMOTE_MACHINE(current_machine); + RemoteIOHubState *iohub = &machine->iohub; + int pirq, intx, ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + intx = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + pirq = remote_iohub_map_irq(pci_dev, intx); + + iohub->vfu_ctx[pirq] = vfu_ctx; + + return 0; +} + /* * vfio-user-server depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -394,6 +415,13 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o->vfu_ctx, o->pci_dev); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup interrupts for %s", + o->device); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 847d50d88f..c167b3c7a5 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -12,3 +12,4 @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" +vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d" From patchwork Mon Oct 11 05:31:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549087 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2556CC433F5 for ; Mon, 11 Oct 2021 05:52:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3968E60EE7 for ; Mon, 11 Oct 2021 05:52:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3968E60EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:38656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZoF1-0006w6-DH for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:52:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuv-00031c-3p for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:32:05 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnus-0005ze-AA for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:32:04 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iKQo029463; Mon, 11 Oct 2021 05:31: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=O1wqZMWk39yr286dA3PYdCN8oDXeZEiPhp+mHBjH64A=; b=DVvbBaOv1TbOvkUV/hwIfuC7XYkRsD07dIXpuLlG10qOGMy7k3gUtdWvW0Ku55bGmmLp Ed3Il1NSp1KtbexvTAbzlNJJqasJoxGENe8+EEkaTcvrwZCG1rmKTipySAsVBVjdJqEv jJ1PF1cvbWIDvDqrZaHM2+JJzl6hnex+RI558GgrGGCeUBdYoUAbw/n2oW5i1QLyYjzr e2/uoShvNmZP3kh6kc3epxv9Y38/+mYo3fcQjv+2NJvsIpaw7b4xlZScBW38RPad5ZQY WG8eSBZMjdlqgGEy4/57GnKi9iVOjZWMey5yEiP0vkDnW56NX3SR9g9yp6j8ylcj6pjw 7A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkwxh1v9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19B5UImU084597; Mon, 11 Oct 2021 05:31:57 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2040.outbound.protection.outlook.com [104.47.51.40]) by aserp3030.oracle.com with ESMTP id 3bkyxpc9ec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kCZiGaSepk1nU7CYUuWocvaJ35Do1Gj0Z9US9WEPHsCxu9gQdtk1k3drrVdo1pcTg+3gq+GGD+ce/CURuCPrHVg9WT9gKsFXSaTq2ASoVuRa3Rjish3ZTHiKI5s8P+5o+y++aYc4wO2Vwls52pacJOaYoWDM0jIahe4f4q+AJ3Kt0x0jHJ1dB+NKXxQYO7tAABPcWCotkMz7eSJ08rs1v1Cc0/RRMSXjJGHz7iOIs9cp/usr1DJIUUWITA0qaR/CdfSjbOZ5AqZcuMdEDZvIO3lFz6pdTtHG0WfgSVIaXRbEGP7lmj8KG5o+wXSwKggV5R9WKoN7y1qBnZsHwiYqHQ== 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=O1wqZMWk39yr286dA3PYdCN8oDXeZEiPhp+mHBjH64A=; b=EPnoSbXovxuORvDc3+bPcfDd5a8Cy4cZSaLo2HQagyqNotRK0dJ3IdDRitZAi7REaQOAJfD2cthdihQcXYMsKJ0S3Sfr1n+xcv2ay1COixefm7WChJNhOsYze0B5zXgJ6ZCFbTW33levQB5NDfnl4GfL6J/+Nnx2iIDkK54y2M19ojVG96AUouucPaf7DFs1RoTgtLpeTDIclAoxZbQQYNcsMFptyiv5JktO61W5FyTnQj+i5WSp+NjKVebT314HyWbkRpFrWBE0ZS8PgEqVbchecYpSSnq9n/ZGeEEv96SpvHwbIn2lPflcDSn968KvvYyo3TSqpM+uSDMqjh/sWA== 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=O1wqZMWk39yr286dA3PYdCN8oDXeZEiPhp+mHBjH64A=; b=EB2YQXQwXdLSINDnCMdjcsHIf5qyNDpDGC0pRqRfNG7tNHVlfEtDe3eQU/5WzI5IOw9TlJNFRslgyKywjJDBF2vYnjUeF2Ax9qEcArFmI19o04MYRWxlf3kICUCFGYGx/i9nLeCm8fjBKEobGwFn7ilfnRUan8vcmKDrAkEMhgc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:55 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:55 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 11/12] vfio-user: register handlers to facilitate migration Date: Mon, 11 Oct 2021 01:31:16 -0400 Message-Id: <9f85493af346c32d34cca3622e8293053b5c7440.1633929457.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b31a34d8-31d9-48eb-d373-08d98c786fc4 X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1148; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7JWs124s+2WVP0Eh7G5I4NGd9NjfKmzDS4eeK+4yq0ekeDemQJyyJQlohZ7Iy93i+sDHv0lM++TCQ1nYV1LS86e46EYC0eM+K3gbmnLHPFHxVLOKSGwNwy5jtPFl9kH+bbE3e2bI6kmuLO85LEVy1BoLVgFiE8Aw9r3hBqi30Z7yfpiKit3bDP2ZYFgN7QUWhvrXymsnuanXYaiJhV00m9Qp+ROmY8ZigV4hC4kzEwxEWMs42Lwv4OBtDKv8l3EzWW1PUvJxhoE39mGtGvPMrPmP1A6K7hJAX0np33OdVUxd/cDg/pwKFq98fjP3OQlshADVch+yrr5lPtxEx11CPs2PIT23kRgbG/vfNAy+QyfQPYR3CYiEFROW7NKf1mssZELtUTPP4eryaAICl8+oF4vLunmUUxP9TMRG0Cyj/xF8Hv2FhrfellctTbsO6p5dzPzsgsqjoKBwuaFOgk18ye4S+7Pm0cAuP7NfU/VHkRlIFzvtrLJr07cjKGFLucnbVmSemhaRohBwcsm622Gf9IYOWiqkuKeyodyY1QeUAqWFeRJJYPkB/G0sZ/UsQzmD98NffwUyMZf5AyJVnUcrZxQga5k3c1jPxBPuRQQaMd1rGK5Ls+B1hceZeJ3pAOxguWLAWX17QKyHSbr6kIcNfeYkdneAkiTOprMgr9IgZYu2CdjWXPbSrh5cxlLXo1/rsrI/u8czBmRsHx2EVc1URQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(30864003)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pxDmmbqMsQuzH8S1cHUAgjTquDGUE0Itw12NL/iAhcI2HQjpDu2DXoIHlWPdGGGXb3Lhmgmod+xjocm/syXpvjkQ8UjsAqAwE7nHdgfHHqxyACc2DjilQaI/N/oPeVPLhL2izGGSnm9tdvULSW/Ndkuchg+w7WF/6EK1ioXgj9WcSQKrnvNLM5HL6f+nhYEJdKZ5Cp3D+Kql3N3szi2J5Uz2OZUatL+6ldKHum8apbINVBKJDZ9+mkU80Qe8DzkZtmS0I80Bw7VUxSLddVOkfGmAY3rxzWa1Fvx659KaM0gqaF0eui73hwICb8v3HrMM2pOxI4HKMGPtxQU5GOYLVYo0hxubCrxDcXbzaA2kGZPfsvitaFVyQ5dXtn6DJNU3Vqs0eIvW2z3HGBLTHKbZV7Qnd/JNSsAkhT/oMz4TZlhhDFQ6LttI207G8g7EJIxK15aMofWtOPfdD0xElz8vSyN22BBMMEMrtu+gizBc4jyZ1NSrIfdkSA6NrDhNwV7gKdCLMGNummol2ts5ClXD4Oez58Yc1wGrhO2RVR0v9KaDJYBb/cBfdfVKy2FcTsFY/9+AuFYHYQScwbWffsLC+hbGzru9zIXTNPIvcZh988aZSdiFNrJTpD6hFrW2s9BnuZekKIYMWQOnEb/lakYsk51umUBWYnBivDUl32PHiZ5rJCbm2kodjbeCpq75vPQjKpqrIMS/37BhEgu8EMfr+3VS5H0r9qOOTjIZtwxnIG/+H/NqxG0GnKfRGjHQDzO1qRiQ/+dh7KNbkq8k3BuQxb+eZguXTIWDW83LARTHTcc/WQyfzZ9d+R+EGU/5AA9f79B5wMsp9YdsgCHB+/PvjahtCOzP7qStjVNMIi1i5Km6IcFuhNU9mc2Xh8Exopw6ua2/WDI+SXFXL17xyb44vvw235tpwJPLufTPFq0xbbmTxhSTo21wKHzfEu8xCNNG6FydbSA0QvS4Isk6m0Z/wiEr0yDdBtGmLYy+u7N2uB2UgTb2/ewrD1rOv87S/wgbF28HodwPjJzda4CiQCKZ8SOkL5xgyY9uEgMPKI92nxqY09CVo0TY2kYlCSj1FuAfqypc4HAkdpIvy719ayBQvku+ud3YiPYt4+WO4bXwypWT/WG6CWmcRAGhMLGTimOj0RiDXmF1uqBTZUqX/QGTSsoufCkGt5QR+ZDvgT/1fwFuhfUMaXGkAgpAuRK+n82761dL0A7jKJTS1yYOC7lLZ0fZt986ERYRcUTOl98pBHM7NA7U7TpfXNCjmb18JZZepHBk3dI2DJiwe2zl1UfSb9H81UlkqJLAwEZnZuTn2qqpHvffIwNuj/meWlea1W5u X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b31a34d8-31d9-48eb-d373-08d98c786fc4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:55.0848 (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: 0rl6VYZhGk1n14/18ltg+FLvKzsFK+B1ZZzOVLfiraBdYufAvjrsJEd6hReQiqzf4AVEUnXv5igTfWxG8p/mvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: 6Mkas_ex6E9yeHWhr8EqeCGRyojcRiB1 X-Proofpoint-GUID: 6Mkas_ex6E9yeHWhr8EqeCGRyojcRiB1 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Store and load the device's state during migration. use libvfio-user's handlers for this purpose Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- migration/savevm.h | 2 + hw/remote/vfio-user-obj.c | 339 ++++++++++++++++++++++++++++++++++++++ migration/savevm.c | 73 ++++++++ 3 files changed, 414 insertions(+) diff --git a/migration/savevm.h b/migration/savevm.h index 6461342cb4..8007064ff2 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -67,5 +67,7 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks); +int qemu_remote_savevm(QEMUFile *f, DeviceState *dev); +int qemu_remote_loadvm(QEMUFile *f); #endif diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 63c468d6f3..757355ecaf 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -49,6 +49,10 @@ #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "hw/remote/iohub.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/global_state.h" +#include "block/block.h" #define TYPE_VFU_OBJECT "vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -77,6 +81,35 @@ struct VfuObject { PCIDevice *pci_dev; int vfu_poll_fd; + + /* + * vfu_mig_buf holds the migration data. In the remote server, this + * buffer replaces the role of an IO channel which links the source + * and the destination. + * + * Whenever the client QEMU process initiates migration, the remote + * server gets notified via libvfio-user callbacks. The remote server + * sets up a QEMUFile object using this buffer as backend. The remote + * server passes this object to its migration subsystem, which slurps + * the VMSD of the device ('devid' above) referenced by this object + * and stores the VMSD in this buffer. + * + * The client subsequetly asks the remote server for any data that + * needs to be moved over to the destination via libvfio-user + * library's vfu_migration_callbacks_t callbacks. The remote hands + * over this buffer as data at this time. + * + * A reverse of this process happens at the destination. + */ + uint8_t *vfu_mig_buf; + + uint64_t vfu_mig_buf_size; + + uint64_t vfu_mig_buf_pending; + + QEMUFile *vfu_mig_file; + + vfu_migr_state_t vfu_state; }; static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, @@ -110,6 +143,272 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) trace_vfu_prop("device", str); } +/** + * Migration helper functions + * + * vfu_mig_buf_read & vfu_mig_buf_write are used by QEMU's migration + * subsystem - qemu_remote_loadvm & qemu_remote_savevm. loadvm/savevm + * call these functions via QEMUFileOps to load/save the VMSD of a + * device into vfu_mig_buf + * + */ +static ssize_t vfu_mig_buf_read(void *opaque, uint8_t *buf, int64_t pos, + size_t size, Error **errp) +{ + VfuObject *o = opaque; + + if (pos > o->vfu_mig_buf_size) { + size = 0; + } else if ((pos + size) > o->vfu_mig_buf_size) { + size = o->vfu_mig_buf_size - pos; + } + + memcpy(buf, (o->vfu_mig_buf + pos), size); + + return size; +} + +static ssize_t vfu_mig_buf_write(void *opaque, struct iovec *iov, int iovcnt, + int64_t pos, Error **errp) +{ + VfuObject *o = opaque; + uint64_t end = pos + iov_size(iov, iovcnt); + int i; + + if (end > o->vfu_mig_buf_size) { + o->vfu_mig_buf = g_realloc(o->vfu_mig_buf, end); + } + + for (i = 0; i < iovcnt; i++) { + memcpy((o->vfu_mig_buf + o->vfu_mig_buf_size), iov[i].iov_base, + iov[i].iov_len); + o->vfu_mig_buf_size += iov[i].iov_len; + o->vfu_mig_buf_pending += iov[i].iov_len; + } + + return iov_size(iov, iovcnt); +} + +static int vfu_mig_buf_shutdown(void *opaque, bool rd, bool wr, Error **errp) +{ + VfuObject *o = opaque; + + o->vfu_mig_buf_size = 0; + + g_free(o->vfu_mig_buf); + + o->vfu_mig_buf = NULL; + + o->vfu_mig_buf_pending = 0; + + return 0; +} + +static const QEMUFileOps vfu_mig_fops_save = { + .writev_buffer = vfu_mig_buf_write, + .shut_down = vfu_mig_buf_shutdown, +}; + +static const QEMUFileOps vfu_mig_fops_load = { + .get_buffer = vfu_mig_buf_read, + .shut_down = vfu_mig_buf_shutdown, +}; + +/** + * handlers for vfu_migration_callbacks_t + * + * The libvfio-user library accesses these handlers to drive the migration + * at the remote end, and also to transport the data stored in vfu_mig_buf + * + */ +static void vfu_mig_state_stop_and_copy(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + int ret; + + if (!o->vfu_mig_file) { + o->vfu_mig_file = qemu_fopen_ops(o, &vfu_mig_fops_save, false); + } + + ret = qemu_remote_savevm(o->vfu_mig_file, DEVICE(o->pci_dev)); + if (ret) { + qemu_file_shutdown(o->vfu_mig_file); + o->vfu_mig_file = NULL; + return; + } + + qemu_fflush(o->vfu_mig_file); +} + +static void vfu_mig_state_running(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(OBJECT(o)); + static int migrated_devs; + Error *local_err = NULL; + int ret; + + /** + * TODO: move to VFU_MIGR_STATE_RESUME handler. Presently, the + * VMSD data from source is not available at RESUME state. + * Working on a fix for this. + */ + if (!o->vfu_mig_file) { + o->vfu_mig_file = qemu_fopen_ops(o, &vfu_mig_fops_load, false); + } + + ret = qemu_remote_loadvm(o->vfu_mig_file); + if (ret) { + error_setg(&error_abort, "vfu: failed to restore device state"); + return; + } + + qemu_file_shutdown(o->vfu_mig_file); + o->vfu_mig_file = NULL; + + /* VFU_MIGR_STATE_RUNNING begins here */ + if (++migrated_devs == k->nr_devs) { + bdrv_invalidate_cache_all(&local_err); + if (local_err) { + error_report_err(local_err); + return; + } + + vm_start(); + } +} + +static void vfu_mig_state_stop(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(OBJECT(o)); + static int migrated_devs; + + /** + * note: calling bdrv_inactivate_all() is not the best approach. + * + * Ideally, we would identify the block devices (if any) indirectly + * linked (such as via a scs-hd device) to each of the migrated devices, + * and inactivate them individually. This is essential while operating + * the server in a storage daemon mode, with devices from different VMs. + * + * However, we currently don't have this capability. As such, we need to + * inactivate all devices at the same time when migration is completed. + */ + if (++migrated_devs == k->nr_devs) { + bdrv_inactivate_all(); + vm_stop(RUN_STATE_PAUSED); + } +} + +static int vfu_mig_transition(vfu_ctx_t *vfu_ctx, vfu_migr_state_t state) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (o->vfu_state == state) { + return 0; + } + + switch (state) { + case VFU_MIGR_STATE_RESUME: + break; + case VFU_MIGR_STATE_STOP_AND_COPY: + vfu_mig_state_stop_and_copy(vfu_ctx); + break; + case VFU_MIGR_STATE_STOP: + vfu_mig_state_stop(vfu_ctx); + break; + case VFU_MIGR_STATE_PRE_COPY: + break; + case VFU_MIGR_STATE_RUNNING: + if (!runstate_is_running()) { + vfu_mig_state_running(vfu_ctx); + } + break; + default: + warn_report("vfu: Unknown migration state %d", state); + } + + o->vfu_state = state; + + return 0; +} + +static uint64_t vfu_mig_get_pending_bytes(vfu_ctx_t *vfu_ctx) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + return o->vfu_mig_buf_pending; +} + +static int vfu_mig_prepare_data(vfu_ctx_t *vfu_ctx, uint64_t *offset, + uint64_t *size) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (offset) { + *offset = 0; + } + + if (size) { + *size = o->vfu_mig_buf_size; + } + + return 0; +} + +static ssize_t vfu_mig_read_data(vfu_ctx_t *vfu_ctx, void *buf, + uint64_t size, uint64_t offset) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + if (offset > o->vfu_mig_buf_size) { + return -1; + } + + if ((offset + size) > o->vfu_mig_buf_size) { + warn_report("vfu: buffer overflow - check pending_bytes"); + size = o->vfu_mig_buf_size - offset; + } + + memcpy(buf, (o->vfu_mig_buf + offset), size); + + o->vfu_mig_buf_pending -= size; + + return size; +} + +static ssize_t vfu_mig_write_data(vfu_ctx_t *vfu_ctx, void *data, + uint64_t size, uint64_t offset) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + uint64_t end = offset + size; + + if (end > o->vfu_mig_buf_size) { + o->vfu_mig_buf = g_realloc(o->vfu_mig_buf, end); + o->vfu_mig_buf_size = end; + } + + memcpy((o->vfu_mig_buf + offset), data, size); + + return size; +} + +static int vfu_mig_data_written(vfu_ctx_t *vfu_ctx, uint64_t count) +{ + return 0; +} + +static const vfu_migration_callbacks_t vfu_mig_cbs = { + .version = VFU_MIGR_CALLBACKS_VERS, + .transition = &vfu_mig_transition, + .get_pending_bytes = &vfu_mig_get_pending_bytes, + .prepare_data = &vfu_mig_prepare_data, + .read_data = &vfu_mig_read_data, + .data_written = &vfu_mig_data_written, + .write_data = &vfu_mig_write_data, +}; + static void vfu_object_ctx_run(void *opaque) { VfuObject *o = opaque; @@ -359,6 +658,7 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) VfuObject *o = container_of(notifier, VfuObject, machine_done); DeviceState *dev = NULL; vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + size_t migr_area_size; int ret; o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, @@ -422,6 +722,35 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) return; } + /* + * TODO: The 0x20000 number used below is a temporary. We are working on + * a cleaner fix for this. + * + * The libvfio-user library assumes that the remote knows the size of + * the data to be migrated at boot time, but that is not the case with + * VMSDs, as it can contain a variable-size buffer. 0x20000 is used + * as a sufficiently large buffer to demonstrate migration, but that + * cannot be used as a solution. + * + */ + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_MIGR_REGION_IDX, + 0x20000, NULL, + VFU_REGION_FLAG_RW, NULL, 0, -1, 0); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to register migration BAR %s- %s", + o->device, strerror(errno)); + return; + } + + migr_area_size = vfu_get_migr_register_area_size(); + ret = vfu_setup_device_migration_callbacks(o->vfu_ctx, &vfu_mig_cbs, + migr_area_size); + if (ret < 0) { + error_setg(&error_abort, "vfu: Failed to setup migration %s- %s", + o->device, strerror(errno)); + return; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(&error_abort, "vfu: Failed to realize device %s- %s", @@ -464,6 +793,16 @@ static void vfu_object_init(Object *obj) qemu_add_machine_init_done_notifier(&o->machine_done); o->vfu_poll_fd = -1; + + o->vfu_mig_file = NULL; + + o->vfu_mig_buf = NULL; + + o->vfu_mig_buf_size = 0; + + o->vfu_mig_buf_pending = 0; + + 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 7b7b64bd13..341fde73f8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1604,6 +1604,49 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp) return ret; } +static SaveStateEntry *find_se_from_dev(DeviceState *dev) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->opaque == dev) { + return se; + } + } + + return NULL; +} + +int qemu_remote_savevm(QEMUFile *f, DeviceState *dev) +{ + SaveStateEntry *se; + int ret = 0; + + se = find_se_from_dev(dev); + if (!se) { + return -ENODEV; + } + + if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) { + return ret; + } + + save_section_header(f, se, QEMU_VM_SECTION_FULL); + + ret = vmstate_save(f, se, NULL); + if (ret) { + qemu_file_set_error(f, ret); + return ret; + } + + save_section_footer(f, se); + + qemu_put_byte(f, QEMU_VM_EOF); + qemu_fflush(f); + + return 0; +} + void qemu_savevm_live_state(QEMUFile *f) { /* save QEMU_VM_SECTION_END section */ @@ -2444,6 +2487,36 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) return 0; } +int qemu_remote_loadvm(QEMUFile *f) +{ + uint8_t section_type; + int ret = 0; + + while (true) { + section_type = qemu_get_byte(f); + + ret = qemu_file_get_error(f); + if (ret) { + break; + } + + switch (section_type) { + case QEMU_VM_SECTION_FULL: + ret = qemu_loadvm_section_start_full(f, NULL); + if (ret < 0) { + break; + } + break; + case QEMU_VM_EOF: + return ret; + default: + return -EINVAL; + } + } + + return ret; +} + static int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) { From patchwork Mon Oct 11 05:31:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12549047 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05954C433F5 for ; Mon, 11 Oct 2021 05:38:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FA7B60230 for ; Mon, 11 Oct 2021 05:38:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1FA7B60230 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:50996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZo0i-0004EH-8U for qemu-devel@archiver.kernel.org; Mon, 11 Oct 2021 01:38:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnux-00038R-3a for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:32:07 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:35674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZnuu-0006D5-OH for qemu-devel@nongnu.org; Mon, 11 Oct 2021 01:32:06 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B2iPF5017564; Mon, 11 Oct 2021 05:32:01 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=ye7guYAEycWg4wKe+IBlDrF8UoW9GTKcA9AkckuCqpE=; b=q/slPyjpv82fUXVFIvIhIcDdXkJS+EYSQpBWLio4+aBSvPjICC5UKxXFTeJZ2F+hg8cP OACBRhBKzKRR5IsyAuUa2Lnwu7vkOs6aubi+xjOuVYCLGv/SXq/2AC0d4lpSYNUv2sGG rDvdi1GsV67YAjnIk5rc1S7V5o4PWloasWvONaERryREpivJlIOOdHWPCZNDpnMz6Q7P ZfY02F3ESZRF6dRTWnuYgBy7TkCMTbHTnN7lW9pUBM9Y81AmI6yD6jRgfygp2o/Rps9Q 21XgZlrj7d7Vu80n6IUOjH4Ghfk9vWNVE1dRPcskFMIDqlyilfRaq1fR1kPDpUsneyQT Qg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkvh9t2ju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:32:00 +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 19B5UIqo084641; Mon, 11 Oct 2021 05:31:59 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2042.outbound.protection.outlook.com [104.47.51.42]) by aserp3030.oracle.com with ESMTP id 3bkyxpc9gp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 05:31:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mkQ4gTJV4ldyFB1TbT6K+iO5FnCwUsOW43nyQHoWes9K8s3iFoT+mN8U+Sq1BMTNQlHl3TtGcCpcAXcjtWJ7LqFttAxSUgfPnA8hLMlZKKs4Cid8Rl/GghUQjdkGVjgQ9xXTZthBmz5xtIsQwdzg6C8DjDD67sf4vVyBkmBRy8RnfYrS9OfwhmIkXGVV2iGCn7I0E2108JuE/flLL93H7AfP//wMdq28xLerpuYirGt6jaIxZAQVp0jlZYvr/XH9sZ4Vm2h+KEHQiCBv/Pho8KmQGSABqR5e+uTAWFLBr0aLLt/kA1NkVd2dYiFJ+VwCGD+8WFnCJISW5urgEHTwHw== 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=ye7guYAEycWg4wKe+IBlDrF8UoW9GTKcA9AkckuCqpE=; b=BMFLltggl5n+/TrHgUW4kjbj0vaz6+yK//OpOZNfJej3quKH/npQ+I0OKs4mPMS1xeCRr1Kz8Q39kbC8tqUmQfJB6FIAohAWNShw6pqUwpRRqZ3+f/NrQtgmC2amTsXJlndXeHSSUsCDhYjlYezStVBs2TuU/IHiJo6M/h0P9BRLsVmdQGIdU4sDQtWUR3jwtq2WmyKKJcothrcvLBtSobkExwy5IjirDzfNgwq2ODPR6F/bqofZ+OxPiCMfeimDlAWOOlOxsEBWpeJirtUSL4dRl/ExmPP6XCtjrGYnYN2caSYozCchfuSRsZElBsjbZQboyiaRvf4NFRiUXR8oaA== 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=ye7guYAEycWg4wKe+IBlDrF8UoW9GTKcA9AkckuCqpE=; b=WRTsXyWn7NTT7XCkG28+PzY0+KarZzahHfh81EXYB4KDK4POetJz4cRMYso18MBt0sFBy88J1oG+JyCS0D1Y9CwErisw7B7Qf6yweicjSEsiIVPC4z5nq185ZYavw0/uw3GL3UkMHcTa6KtyGcgJLi4chPq8lQeCSwXRCe47PYk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3775.namprd10.prod.outlook.com (2603:10b6:208:186::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 05:31:57 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::48d7:8ff1:200c:89ca%3]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 05:31:57 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v3 12/12] vfio-user: acceptance test Date: Mon, 11 Oct 2021 01:31:17 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 Received: from jaraman-bur-1.us.oracle.com (209.17.40.40) by BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 05:31:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00ab8499-9f7b-41b9-c6d9-08d98c78716c X-MS-TrafficTypeDiagnostic: MN2PR10MB3775: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rMfIiKzz2mBlc1ozFFbKsDHkbdatbPRVsvfV84WegQxxx61IbekgN3PNxWKMPnW1ZEBKWQ559JOJvP1oCHiTi5W1X/y2uax43ZHCGmApHYrTY+/or8tN08LnueaTZkHEY/B2CItUQNtSFeHsLitH3llLVHZkxm3J79Zz65VfZ8uYTdd3IfueQB5z4CI3VA7bUWS9TIE4e2SjPLSisQWvoiPYQ0cwUqYHBncGYHpSuxWJ2jkerUYR5xxiw4XpwqBYOTY9uRMQ+wgcVXJvLq/Ldj34ATDgzvKckGtixQPkpLo/Ob6p2FnSkgnW6C44yfvl6QUvj5G1fcOMGKjKRpFbx25jF3TQzo1YFq/IClWcpYnzmgsNNsi2k8ReEL6ZLgScgqAMjhUKxZxALznWs+9T+zj8+W6zUzyYjg2ekg5AVmWt5xNPgf4Tv9uN5G8iwgkyDhc3Ewi0q0X4QAbGKj3cFfl9aoaGS3uDs36oGh7FXd2Vdn/Zzfa+ZW35LOZ8T0l/FRnTxLQNfMY1UpZlEHh3iQbICLzzObiQt11Z3Vk+XaOimXJAjD8eTb+djEZWwTqmojZNHpbKjBcIKr4dI3/JprKSSP/tNZBPiKTF0Vhfs2tNA4Fq6EmV7uklJjr0qDQubwxO9kSFf1KxOFzkiykt+92Vcgj/if6yqdElVWkhjWIdCB+0N+ayF9zqwWIIzNzUD+Bc9/P1ggGLtkjtYTbpAFiGIg6uVtQszECKPGxo6QFMWABRwcspU3lhwgQO18idB3uRIh1nH30C0vPvX7nh6NnH1+j9CpB4VKyYOT6IWug= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(86362001)(316002)(8676002)(36756003)(66476007)(956004)(66946007)(6486002)(7416002)(4326008)(2616005)(508600001)(6666004)(5660300002)(8936002)(7696005)(52116002)(6916009)(2906002)(107886003)(186003)(26005)(38100700002)(38350700002)(83380400001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DDVgf37nLulQKp3n4pd5Yy6Wy9zZ9vVGBiWiXh7deJ1zAR2wFWZk6Xjw8q+PPDHmQQZG1CBF4cbJBMzNp4t47zqEvYlAGIYx0WcYZXn2GPOgp07MJ2RuPjueG8zoqkg+jKyS/iUpZN+1zUiOqM4iSQyiGu2GuUS2GNt/j8bV0rBve4MfTvdoM4MXqv/QiGstTYU3/vptKHDGy90XOBHNy2vLpO63OjeHfhcE8zFeRQD2l63ydtEugkKg5+F5u8rbUMgl0ubuXednhKgHOgRn6CHynzyZHo1Kv1O9OJUj5/Jx2MvAEZYgr3GQfn9f6belRqk8ndTEDeuY824WYRjKaTi1HJ1yK+noXlvx+hGr6nXkGmPvxkBsOMZkNoHHv04R62Du4BmnEGzZJvI9uz5PPl8kVGT/alt4xLHUXxnJE7JSwNlvZMgdd4hVHAWdm1+JcRlJrbP7ndOONL8aBiBbKVQllReZizTbwzSFoDG1t+TsFaJys5K3LvKBtv2Y7vE1Whl5yqSfnWfIAYNoVuMug8Hn2N3tKsOiDYhJehBQw6PZNzAU0Ra3KLJ7y2Hd82RBbXIek0VsqrlUttrdoL5K7z5Di/t82sK5j4dJPJmMS28pv8KU4OIGYIx8lmV5qrenuD2EqONJgQcdaDgYHP9SwSkm6W8i9+n/sDs1FMkXnDJJQXB3B7YdG5OTF9fwfqXO/aBpRxg/xLebaWAnVhXUKY1Gqv4vkGJftEFTME7OwME19gVfbyReQmqv56oESj4bLy5tOj9rIvWxv4l20rmGQUQH4lufKq95eeCUdU+0d+ClbrwY/pH+/77hgvqYIRojooFvbSUyu0Q2qHYQxeLkbhszNGMg8M13vcxVatSznM5ywPe2U4yIMLuWRJUMrc7RHXunSHsLp5YW7y7cUIu07Zojk3EPZTZe6g59KIKr2GczdNmfbNGdoyYj5vGYeMKb8PNGfUU4v0xu6fiMxofX4NtR5t+Zm/rH14+Ey/3DIGD9dCyBx0uWIUSHYAF+dXkprUY8H4v5V8L+VXOF1IB7SU+zyZ2quqWGsYWR63bxkTTvQJb+fJABZbCVWcrsGevuWLro8uQORb96FuTdyVtZiq6gwCHfVc2biSY5VCi7fAwy0sghFV/mgKrJTude3M6o9j2RatPbZttZ/D0lpunoV+yA5snzECONZrFqmzdErzYQirrq4Kox1gCTI5eY+GO06Ij2J4qNbGQnQq1JDwtfFX85GrJbBtJp5KPgX5VxTymvgfhaAHa5XUm4YqRn1F6540sfZWrlvHx9VTINhE6ECe5feWhLWe7Np1nT1K+U5vvU0jhBpl9PnYjLQqH+F9hG X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00ab8499-9f7b-41b9-c6d9-08d98c78716c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 05:31:57.8792 (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: Xn34Tz8xz+g0yAsC7vxkaA+S+JS7Qu2Bz6/99s5cSw+3c6K1snhM85fR9jLFR9ygC/efvZZNEPCR5I5YunXt1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3775 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110032 X-Proofpoint-ORIG-GUID: e7rHSVruE2rxV5CaGEEahgzNtCg_LCdk X-Proofpoint-GUID: e7rHSVruE2rxV5CaGEEahgzNtCg_LCdk Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, jag.raman@oracle.com, swapnil.ingle@nutanix.com, john.levon@nutanix.com, philmd@redhat.com, alex.williamson@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Acceptance test for libvfio-user in QEMU Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Philippe Mathieu-Daudé --- MAINTAINERS | 1 + tests/acceptance/vfio-user.py | 96 +++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/acceptance/vfio-user.py diff --git a/MAINTAINERS b/MAINTAINERS index 79ff8331dc..a98d37423b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3422,6 +3422,7 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: tests/acceptance/vfio-user.py EBPF: M: Jason Wang diff --git a/tests/acceptance/vfio-user.py b/tests/acceptance/vfio-user.py new file mode 100644 index 0000000000..5eb5cabc68 --- /dev/null +++ b/tests/acceptance/vfio-user.py @@ -0,0 +1,96 @@ +# vfio-user protocol sanity test +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + + +import os +import socket +import uuid + +from avocado_qemu import Test +from avocado_qemu import wait_for_console_pattern +from avocado_qemu import exec_command +from avocado_qemu import exec_command_and_wait_for_pattern + +class VfioUser(Test): + """ + :avocado: tags=vfiouser + """ + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + + def do_test(self, kernel_url, initrd_url, kernel_command_line, + machine_type): + """Main test method""" + self.require_accelerator('kvm') + + kernel_path = self.fetch_asset(kernel_url) + initrd_path = self.fetch_asset(initrd_url) + + socket = os.path.join('/tmp', str(uuid.uuid4())) + if os.path.exists(socket): + os.remove(socket) + + # Create remote process + remote_vm = self.get_vm() + remote_vm.add_args('-machine', 'x-remote') + remote_vm.add_args('-nodefaults') + remote_vm.add_args('-device', 'lsi53c895a,id=lsi1') + remote_vm.add_args('-object', 'vfio-user,id=vfioobj1,' + 'devid=lsi1,socket='+socket) + remote_vm.launch() + + # Create proxy process + self.vm.set_console() + self.vm.add_args('-machine', machine_type) + self.vm.add_args('-accel', 'kvm') + self.vm.add_args('-cpu', 'host') + self.vm.add_args('-object', + 'memory-backend-memfd,id=sysmem-file,size=2G') + self.vm.add_args('--numa', 'node,memdev=sysmem-file') + self.vm.add_args('-m', '2048') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line) + self.vm.add_args('-device', + 'vfio-user-pci,' + 'socket='+socket) + self.vm.launch() + wait_for_console_pattern(self, 'as init process', + 'Kernel panic - not syncing') + exec_command(self, 'mount -t sysfs sysfs /sys') + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/*/uevent', + 'PCI_ID=1000:0012') + + def test_multiprocess_x86_64(self): + """ + :avocado: tags=arch:x86_64 + :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(kernel_url, initrd_url, kernel_command_line, machine_type) + + def test_multiprocess_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(kernel_url, initrd_url, kernel_command_line, machine_type)