From patchwork Thu Oct 26 05:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eiichi Tsukata X-Patchwork-Id: 13437265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2305C25B48 for ; Thu, 26 Oct 2023 05:44:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvt9t-00028L-H5; Thu, 26 Oct 2023 01:43:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvt9r-00027s-Po for qemu-devel@nongnu.org; Thu, 26 Oct 2023 01:43:52 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvt9o-0006Ly-Ku for qemu-devel@nongnu.org; Thu, 26 Oct 2023 01:43:51 -0400 Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 39Q4WJOp002470; Wed, 25 Oct 2023 22:43:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h= from:to:cc:subject:date:message-id:content-transfer-encoding :content-type:mime-version; s=proofpoint20171006; bh=uVrtHS6tpJt JFPYRLQTP7bCxWI+yHPfjYCxt5/A7xG0=; b=xE0/9SZ8BmtCnro4ApP1rEdHrJ6 Ba8/V+nM9ofiNojuF6t0zX20WEqdzywkTX20sOBccppoBiPQryDmGwBvfhJczwCK 9jPxE6auefUbartZmtTLv0Y9HHlW4QHjs+foKUTGPlS9cVWo7s7v7XTQ2eWQ5Elz sEiodu3W63nT5KdC/Bxdjoe14/qpy+gBirpE1FhXnW1lM4fb9XNKr8FKo8MQZS5B LzWochFSEutVNrxZehixw9u809d2M4nXjLEvJ/z7us7qNIYK6kkfLkqVySR0OQ73 Qpd415n3NnY1bnR9q6xmxLtddAPu3c6aA44KMVQuYU58SmDPwgd57xZbEww== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3tvayqyjrs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 22:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TBIwvqcEtLisV/G+lvrxpxH0lIZbesRzYjCY0zcmxgxWiVtSy/AgaOxT/LB0gRHLx+luaBmKQ360WcW4nqhy8oI33fmxptamXVpuZ6o1Lu3xfaaatvgoKCvQTV79LXEaajQJAhEk9brDdYpK+0P4vaD5Inm98k5rDo33aThyO8+LfirI5aSquyAXRV6/MpwPGzfmytE3YvDogDWoFV5+uLcKb1aG7pcz2eelwZkHkYcAhi0UjXu6vuRYp29xIKO45Wh8ys4MoSKVna7CiGH8jMmqekGwkmq3jqf4BQ+B7ShL11r1xfiEhB8uHSWtJJcwyGRgCn/n+V03jeY0yCXSOQ== 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=uVrtHS6tpJtJFPYRLQTP7bCxWI+yHPfjYCxt5/A7xG0=; b=l3ehV2raQ4vdzGQkxDCqkGMH8EjXScmK8lqXqPzrN0Hn07tr1I39uYrLchq3+klumJsAwYCpzkXnGxiPdoMGKAKkzlQUVtkD2bZnvFxsl7UVFy8FNV+L0nDIbbEhSjRPEMhm2iyhvFXQGHHjLWN4UdH2HlcyPrxXYisJqYz4J3pObIcWmSWzEoXfxY/ipC98KkC5WUGNRiUIDwBv+SlZqB0cPxqX3b4wpDXN6fiYCU4fPg3M9NjKMGehx2UXalZ8etrf5Del7CqBWd0Sz5CogkFIJLmb4YYzRDlfHR3v1FFMEkIIjzX5rbliempD/F9Bfh6uhv9ZR6KaWvmKccj5Zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uVrtHS6tpJtJFPYRLQTP7bCxWI+yHPfjYCxt5/A7xG0=; b=cCqipeqLJ2pHjykk1gE89Dybd/PDr7ZEjK9Kl45EnwkUdi/ZnA5gd+SKsLUU9dXPylD4uiJp9t6zwOJURVbS024E4VqSj207iz2nGMHMWuWn24qk6LlVPB5CbnslEIuy+8fdY22UTlUId37Uv7gUrDju5jEvASqVyBOMDyG95QuBiTQqpFW+DfiAWk6G4t/snoHHFnsKLhJECZUGN8vYIyt99i94P7KNJ0qo87wMGpB9clU32pnLgVTvM496o5KnUfWsKOULqRhOnCZEeHc2+QqGRjL2dRqiemD9vsj+Y3ZZQ36bWCyloaVGveSuTaJ2fWSKemczkY3OlwKqzhBurw== Received: from CH0PR02MB8041.namprd02.prod.outlook.com (2603:10b6:610:106::10) by CO1PR02MB8507.namprd02.prod.outlook.com (2603:10b6:303:15a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Thu, 26 Oct 2023 05:43:32 +0000 Received: from CH0PR02MB8041.namprd02.prod.outlook.com ([fe80::22f:727b:8c9a:e456]) by CH0PR02MB8041.namprd02.prod.outlook.com ([fe80::22f:727b:8c9a:e456%6]) with mapi id 15.20.6933.019; Thu, 26 Oct 2023 05:43:32 +0000 From: Eiichi Tsukata To: pbonzini@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: Eiichi Tsukata Subject: [PATCH] target/i386/kvm: call kvm_put_vcpu_events() before kvm_put_nested_state() Date: Thu, 26 Oct 2023 05:42:01 +0000 Message-Id: <20231026054201.87845-1-eiichi.tsukata@nutanix.com> X-Mailer: git-send-email 2.22.3 X-ClientProxiedBy: SJ0PR05CA0050.namprd05.prod.outlook.com (2603:10b6:a03:33f::25) To CH0PR02MB8041.namprd02.prod.outlook.com (2603:10b6:610:106::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR02MB8041:EE_|CO1PR02MB8507:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a05de5a-54a4-4a1e-10fb-08dbd5e67d2a x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QKWB6o5GxjraEbnAXSx3I+HltIr6JEXRAmauILw5aa4aMk98+H8Tod4nQXSqig+4i6sOqbjj5zVj/2//1/wURVMkBBNJzoRAFoFlmx5mgtj7ZRwl9asyJXwxN25krWzqogVQDTkhDs68DOsYvvHGpE1mERCnab6SKKoGUTbxm9enj9of1sZ12o/SyrdE2E6akVRhsVxKSC4z6EkasBtkyMwdslTrqtq7f5GNYkK+GNHnevAp3my/bILWPcVj3l5+vBNxEWOtNwG7QNFgbHvZgvf5t+5jG4lWeXCmef1e2b3APFyohD2SNdasa9urZ/X086f8SAw5u+vSeAbqUj5rnNSaj1FCurEhjFMDG2FSMz93aoBadmvstolTFwNvfCXB5bHF+FY20hXgVQMLjABQf71dce5wwK7oqeeiODnj8XNrHnHlioRFHwQSCsHm5pxNK8ZmpogooAyElBaebQT+9H+1yPqq9nTB6zjR1UnvsRqZ1LdEeyZSfQyyths5bSOZGj72bWoMcvxQsun8F2hAf2ndrdvJVU+ijma0AO3JjpY8hnBHJpCC/43TCy0QT4xblPEFHYPT1RU2hfof5FIA9Y42gBZeJ22MQpGEAj/qesFMLi2wNDRJdCG3yTXKceWO X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH0PR02MB8041.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(366004)(376002)(346002)(136003)(396003)(230922051799003)(1800799009)(64100799003)(186009)(451199024)(38350700005)(316002)(6512007)(1076003)(66476007)(5660300002)(26005)(66946007)(2616005)(83380400001)(66556008)(38100700002)(52116002)(6506007)(86362001)(478600001)(6666004)(36756003)(6486002)(2906002)(41300700001)(107886003)(8936002)(8676002)(44832011)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YwnCY5zj0vOEhFfpcNelwx2okbM53nLyjuIJGISHVoIOpPO52Zo/lGl2ePUOw9dah8lPG7YI45d0dzXwWsiXXPaF9br2YE3wwIs/zn35fgfyyRvrT3nxNMz3Z3eUKlFdutqoytsqcNXIMtbmYJPLeoVVNJ/cn0wPDArHG4m7zbenes35ekUCuCROlDHt8k3c6Zt1umZvdgjk1dpt3+hpPk+iOCNOB8eAKtyIItd3HWPv8iQfOssgTc5C3467RxyqOvByK+W0cGQK5W5CW8FXOgteLnw3SCmUyL3riow2A0LwGkWaH14WWMvN5zRUWvnsADlP4KsVmqa3kMimJvotR6uLGysRpGULeMVXoxhOnUcaLbz4PP7JLS9dgx/JWhT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g5uyNckXO2tu15X6mCARnSRYP/PUJRJO/rtkyUtW6cnRRaFKij52OjPu7cz3fdf+qZooM1YCGFOgY9Vrhp+9y5bdotulTqjZXsNVGwfrPm/cTsAqFzMxNp2MH3LiysiiA3IAC1HwkS72O4jH6BJItHjYBtUQ== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a05de5a-54a4-4a1e-10fb-08dbd5e67d2a X-MS-Exchange-CrossTenant-AuthSource: CH0PR02MB8041.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2023 05:43:32.4082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NT80kb0GGbYoPbsk1L4FcVT707IueJXQ5WYbt/G7XbsJ2HTstlY8EFVTJcLq67zuDL/xvJ/Std+c9Bk+T+oLW7UHy60rnw6/mMwWSUbIByk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR02MB8507 X-Proofpoint-GUID: nRZPC2hy5-zuuFmOsCLJUALz8xA1r62R X-Proofpoint-ORIG-GUID: nRZPC2hy5-zuuFmOsCLJUALz8xA1r62R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_03,2023-10-25_01,2023-05-22_02 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=eiichi.tsukata@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org kvm_put_vcpu_events() needs to be called before kvm_put_nested_state() because vCPU's hflag is referred in KVM vmx_get_nested_state() validation. Otherwise kvm_put_nested_state() can fail with -EINVAL when a vCPU is in VMX operation and enters SMM mode. This leads to live migration failure. Signed-off-by: Eiichi Tsukata --- target/i386/kvm/kvm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index e7c054cc16..cd635c9142 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4741,6 +4741,15 @@ int kvm_arch_put_registers(CPUState *cpu, int level) return ret; } + /* + * must be before kvm_put_nested_state so that HF_SMM_MASK is set during + * SMM. + */ + ret = kvm_put_vcpu_events(x86_cpu, level); + if (ret < 0) { + return ret; + } + if (level >= KVM_PUT_RESET_STATE) { ret = kvm_put_nested_state(x86_cpu); if (ret < 0) { @@ -4787,10 +4796,6 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } - ret = kvm_put_vcpu_events(x86_cpu, level); - if (ret < 0) { - return ret; - } if (level >= KVM_PUT_RESET_STATE) { ret = kvm_put_mp_state(x86_cpu); if (ret < 0) {