From patchwork Thu Nov 3 14:13:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561401wru; Thu, 3 Nov 2022 07:17:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4mkuhSyffmbgMWT8VF529pYtp8x9g6Hv9oOerSVN55/dDVGKetsr3Oh0YQIkJHtHaAnHLQ X-Received: by 2002:a17:90b:164d:b0:213:6a84:2529 with SMTP id il13-20020a17090b164d00b002136a842529mr31738348pjb.32.1667485074130; Thu, 03 Nov 2022 07:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485074; cv=none; d=google.com; s=arc-20160816; b=nS2sY8KRvWHxvPay++lFDXFjFV+Gs4dPQOb+aqfuY2SDxyjBl7aHYyIOTjDtRO12Bw AE5QM/NtbDZjuTqF/Nz0Zf9Nmv6qID7DTG6J56RvkGGjdArbah/sPzeFLc2UN0yD55w7 92rgdRwvAENq8nH1jrJbRX1J3iwZKNR1OwBsXdjiVjS0VXw8+pbCBkln07CmlsXtSs5I 57DZAYl1hM+wSsM7mi27wxzrGSXkde5M7fLy92X5xbOTN04/zox3pAH6jIXAnqWBjHCV 4v5hImTpd7ujPWvYFlRcSPyJhi9uUqsN3DjTpL1HMRFZA10bIxptLjKB/S5IfMAciqEh FKwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MNLPTKjKZGsyp4iQjia1o+n+MQq5Qzv7rr6Sw6M18Rc=; b=OhExoj7JOuUxclZPnC3iFEmEF5ubVOP0mCNZUGPQm1dtFTiYxBGmFHRN55+KddIYaF LBSvBCxs1P7JVnkOHgRwnTWYYoOqEQur7DgjtTngq6RUWfmoC7S/KcMkV9NuUyBDeIxm qPrJh9sDLW2Zy8TJyZzd4p8O2DJWPfs51UPU8d4MWMC8ENFpnr4XBVSsQxo7GIbU4a2p aA8btRTq7x0A8R5ikx6AcvBXJA0LWpBs4ORAGyQKHaM8lbqjyRmpY8Xg852ojEa6iiVB EVJ3Dj83Hw3eCh5BNTUA4P7+H0U+v144MzJ7kFmqUZmfXVlm04uXTX8kcI+KdCSAcygd hyfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K+L864Mg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mz5-20020a17090b378500b002009d750a2dsi58328pjb.58.2022.11.03.07.17.40; Thu, 03 Nov 2022 07:17:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K+L864Mg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231683AbiKCOP3 (ORCPT + 99 others); Thu, 3 Nov 2022 10:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbiKCOPO (ORCPT ); Thu, 3 Nov 2022 10:15:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B88D513E87 for ; Thu, 3 Nov 2022 07:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MNLPTKjKZGsyp4iQjia1o+n+MQq5Qzv7rr6Sw6M18Rc=; b=K+L864MgxwE10gTrq6I0dG4io6TxI7k/l2BRemkr7XjI7yLkltBl9qQPW99dMKZnJ67SdF JvfbyWRrsloCpH/mHOMjPVKrUUnmVaRqXNWyq8ASC79uUvW3nsX7ZQj30unO9riIp9jlsN ip5sls1axOd4BHxrCm8lVYorSZGSs14= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-alTVHMgjPqmhkfdYNlUf4A-1; Thu, 03 Nov 2022 10:14:03 -0400 X-MC-Unique: alTVHMgjPqmhkfdYNlUf4A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4061811E87; Thu, 3 Nov 2022 14:13:59 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BCF340C6EC3; Thu, 3 Nov 2022 14:13:55 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 1/9] KVM: x86: nSVM: leave nested mode on vCPU free Date: Thu, 3 Nov 2022 16:13:43 +0200 Message-Id: <20221103141351.50662-2-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484829030083687?= X-GMAIL-MSGID: =?utf-8?q?1748484829030083687?= If the VM was terminated while nested, we free the nested state while the vCPU still is in nested mode. Soon a warning will be added for this condition. Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/svm/svm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index d22a809d923339..e9cec1b692051c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1440,6 +1440,7 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu) */ svm_clear_current_vmcb(svm->vmcb); + svm_leave_nested(vcpu); svm_free_nested(svm); sev_free_vcpu(vcpu); From patchwork Thu Nov 3 14:13:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp560667wru; Thu, 3 Nov 2022 07:16:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ObueKk/yvIuH3kKjCghvapifTC1dmiFDhIPeCEhya8Tw7ShjeGS7QGBbt3FqFHpWQHkll X-Received: by 2002:a17:90a:c705:b0:213:1455:1326 with SMTP id o5-20020a17090ac70500b0021314551326mr31567214pjt.244.1667484999535; Thu, 03 Nov 2022 07:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667484999; cv=none; d=google.com; s=arc-20160816; b=dDIKx3hoUZC3Lg+qWF3lu0Zj0/c7OTaUnK8Tm88xEVpHpr0zcOj9KSXk7/gGB1iFqi 0oO9FcwfWJhQ7NOqKYG93Kjk/+89ayGk/8fgroDlzVaTRWJOP14IpiWAFqunelvdILrU U3xoQfl6ByvwDfZGWQvpRebQmMrdNl8PvLoGUnC1OqlAUS0NOGO+PQVfa+yE4J3crowU Sk/KJf3lDH5/4sNNeaF9Y9/C9gzl5ORjTuOfhiYgDpugfkX5KhUgvRY5+5M8wUD8rzN3 pJuY3wVLAte/iXLDR+Yr7CRL4lYMbriXX8wDkcv6tKX7QSIYc70pgRgtX8wP73crXEN7 iGmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZLirfmVsMl7Z8L0J+XcE1Zsp+gCHNtOKzvKZLLJ8RdA=; b=lNIiQPCCgCBmDl4iL7kB3yl2YiEDTqMo6GEI1vRK9e3VT911HGDQgtJYMk7kQUmRe8 o3t/FH/lytXuiOkD0vISoRWdfkl+kDFmNr77y6jLTcvQ2SjE6+U3fgj5jnWNw7S0Hbkl XH/zZbXx6JoTWNIRESiSOe4momLjAu6EMDpT1BBx1AS4ikgA2ZnITsTJYX19LwODlzHO EHnDGdNg9trCT+UmkENmyYoWWNhDuw8b7qC/ef/UnZphNccqbyIMnusWBxwx6XW9EsOQ XNx1VKqRNT9yrIHbzh3YazHlB68ULPd/fJBojY0/nLljgboEyAgXRMxt3AuMJ//lm9sU SLsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LsoYO+v4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v20-20020a63d554000000b00470275be1b8si1107339pgi.622.2022.11.03.07.16.22; Thu, 03 Nov 2022 07:16:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LsoYO+v4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbiKCOPV (ORCPT + 99 others); Thu, 3 Nov 2022 10:15:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbiKCOPL (ORCPT ); Thu, 3 Nov 2022 10:15:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A37C101FA for ; Thu, 3 Nov 2022 07:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZLirfmVsMl7Z8L0J+XcE1Zsp+gCHNtOKzvKZLLJ8RdA=; b=LsoYO+v4QEYixIPKPf6HTdXHDwZWIfBSxLNCYnzG38vsZ5BZkDCd7fJPQRkjLRQJpsfRne 8Pn0QXmXHvApUDyngWmHlpQS60zihkc5sXyjd/PKjo7wi8oLFB2fwSgH1sL01JJrfcfzGH 6f6kI9y45iuDUklcsiWQBq4fGaYeAXQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-S-ZNYUDBODiUjCzhqFo44A-1; Thu, 03 Nov 2022 10:14:05 -0400 X-MC-Unique: S-ZNYUDBODiUjCzhqFo44A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAE2029AA3BB; Thu, 3 Nov 2022 14:14:03 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EA8040C6EC3; Thu, 3 Nov 2022 14:14:00 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 2/9] KVM: x86: nSVM: harden svm_free_nested against freeing vmcb02 while still in use Date: Thu, 3 Nov 2022 16:13:44 +0200 Message-Id: <20221103141351.50662-3-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484750527088886?= X-GMAIL-MSGID: =?utf-8?q?1748484750527088886?= Make sure that KVM uses vmcb01 before freeing nested state, and warn if that is not the case. This is a minimal fix for CVE-2022-3344 making the kernel print a warning instead of a kernel panic. Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/svm/nested.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b258d6988f5dde..b74da40c1fc40c 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1126,6 +1126,9 @@ void svm_free_nested(struct vcpu_svm *svm) if (!svm->nested.initialized) return; + if (WARN_ON_ONCE(svm->vmcb != svm->vmcb01.ptr)) + svm_switch_vmcb(svm, &svm->vmcb01); + svm_vcpu_free_msrpm(svm->nested.msrpm); svm->nested.msrpm = NULL; From patchwork Thu Nov 3 14:13:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561380wru; Thu, 3 Nov 2022 07:17:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pwMk6sCuLA2uaTL2i/3kyy4x5xTVbwSeDI8Fadmz0jal5BixiEe4qHfAoBaw6S2E3IboO X-Received: by 2002:a62:1b11:0:b0:56d:568d:c293 with SMTP id b17-20020a621b11000000b0056d568dc293mr23309571pfb.41.1667485071415; Thu, 03 Nov 2022 07:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485071; cv=none; d=google.com; s=arc-20160816; b=vV3CMl1El+kwFZ6uOc7MgSqE/iwN+PakrOBrU+H1Hd6woxixHGbESY2ACcxTYbIjrW da9rNqk4FlWIf/j2UEgse6IC74N/CUb0Arn08wL71TNMeffp4ItV+M5QGK4YHFt6dC8M 31YIW067ehdy3w1XWTrsg9o7shhFWW5IPqFIg9dV+fEU8PCATMtA8GrrpCnrSqzuW3Xm A7TMVC+qNzbbfTddrKJ1rfKFO/hQ4wrHrs4LmEbIETMTK7pxXCLcPDwSyWKf6Xk5QSZS tb7yMHAPgcpc1f+b1krpehYi0Uw+G4aEKUGRx2ZbagF1XkG5tYLPsbNtij61QAxsqyzJ HKUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=94fXNJlMtb+F/0JTvy69iWSeE6FRHdWRb8tmVfQpuZA=; b=cxh0mmOGGxXFXJn1I+73wQy2VXJaZyD7OFjwvzBMU1QAmx4x1NC8LpGtJAPFXvIS/6 NalqEoMFZ+VVvMo4QFsGJpKxEfMfKVBVfjrZOug54RCKbJkEBY8PLRk6wIUjWfnapqTh 3/7/A7oR3wKJ8T1ENZJujprmE3I80CtVn1vDiq5w8HlSW+EVDaX0+YoL8HNE6q+FIvzf zQcazzk2oGQwHs6IAR+MYrH/VR872nMZ0dbZvWPdrY1O57auIGZ2nl8KIM9ZxZ3FcJVN 1V03lxRjKTs7uH+NYzG0lRrbt7tzS38Oa8bIw8BPAfg760RdDMxbvjTPjUnF7bd0u0++ SJAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FgjUKtQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t33-20020a635361000000b00434dd6f6e21si1547287pgl.125.2022.11.03.07.17.37; Thu, 03 Nov 2022 07:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FgjUKtQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbiKCOPY (ORCPT + 99 others); Thu, 3 Nov 2022 10:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbiKCOPN (ORCPT ); Thu, 3 Nov 2022 10:15:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F9E31276F for ; Thu, 3 Nov 2022 07:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=94fXNJlMtb+F/0JTvy69iWSeE6FRHdWRb8tmVfQpuZA=; b=FgjUKtQdeNrPUsUCCCzL7gjHiHnF24qaHzPhX9H+cEJUFXsp7fca7G+SWmisE9OXnm8n6Y /aANB23FeeUusfCGI9fUn4K3AmD1PqTRTLa5US3c0igmXzv0IpNXCPElnF2JLcVq0/nM5O NhrqbawPSldtM8f24BBnAvjXphbni5k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-213-EnmTDWMaOJ2pOzA6ZiKQVg-1; Thu, 03 Nov 2022 10:14:09 -0400 X-MC-Unique: EnmTDWMaOJ2pOzA6ZiKQVg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECC8085A583; Thu, 3 Nov 2022 14:14:07 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4900D40C6EC3; Thu, 3 Nov 2022 14:14:04 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 3/9] KVM: x86: add kvm_leave_nested Date: Thu, 3 Nov 2022 16:13:45 +0200 Message-Id: <20221103141351.50662-4-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484826689999000?= X-GMAIL-MSGID: =?utf-8?q?1748484826689999000?= add kvm_leave_nested which wraps a call to nested_ops->leave_nested into a function. Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/svm/nested.c | 3 --- arch/x86/kvm/vmx/nested.c | 3 --- arch/x86/kvm/x86.c | 8 +++++++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b74da40c1fc40c..bcc4f6620f8aec 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1147,9 +1147,6 @@ void svm_free_nested(struct vcpu_svm *svm) svm->nested.initialized = false; } -/* - * Forcibly leave nested mode in order to be able to reset the VCPU later on. - */ void svm_leave_nested(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 61a2e551640a08..1ebe141a0a015f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6441,9 +6441,6 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu, return kvm_state.size; } -/* - * Forcibly leave nested mode in order to be able to reset the VCPU later on. - */ void vmx_leave_nested(struct kvm_vcpu *vcpu) { if (is_guest_mode(vcpu)) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cd9eb13e2ed7fc..316ab1d5317f92 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -627,6 +627,12 @@ static void kvm_queue_exception_vmexit(struct kvm_vcpu *vcpu, unsigned int vecto ex->payload = payload; } +/* Forcibly leave the nested mode in cases like a vCPU reset */ +static void kvm_leave_nested(struct kvm_vcpu *vcpu) +{ + kvm_x86_ops.nested_ops->leave_nested(vcpu); +} + static void kvm_multiple_exception(struct kvm_vcpu *vcpu, unsigned nr, bool has_error, u32 error_code, bool has_payload, unsigned long payload, bool reinject) @@ -5193,7 +5199,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, if (events->flags & KVM_VCPUEVENT_VALID_SMM) { #ifdef CONFIG_KVM_SMM if (!!(vcpu->arch.hflags & HF_SMM_MASK) != events->smi.smm) { - kvm_x86_ops.nested_ops->leave_nested(vcpu); + kvm_leave_nested(vcpu); kvm_smm_changed(vcpu, events->smi.smm); } From patchwork Thu Nov 3 14:13:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp560707wru; Thu, 3 Nov 2022 07:16:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Z1bMN3YL9Kq71B+OoAI2YlnB2tKDePmTVUSo4ZuEp7NKiB5unNzWDxcfWnkfaV+0ktTNh X-Received: by 2002:a63:914b:0:b0:46e:dbd5:ae15 with SMTP id l72-20020a63914b000000b0046edbd5ae15mr26504017pge.94.1667485002807; Thu, 03 Nov 2022 07:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485002; cv=none; d=google.com; s=arc-20160816; b=j62iklPbBMmw6QAnuSUVVqf20uQjIGEEkTXCxb/PchsDBLweyI79D3NenSo1uH5nO4 1NxuZZjh1FHuqjQ+917rrEkX908KbyjaFC+shLyTmDhERaQMbOfvexjVFXrUtSmo5DsP xj6Q2zxjN+fAI6Fiu2UXkEpntDH24bKliWyPYtMV73lvhVkjzgm1SXQLgtrLWmDTLVur gGAI6Tkt8Vca9bN7kjjOKg3jNHEtC329L/HyL1y6e7etgXAV+OL+jQhSjas6lcY6Qiio Xz7QX8xP5sLB8Nfd58BqWtWBI+UUPpJC6dqY7w6h2MuAbUBAYggRGPsRuD+vlpwlitik df7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5Rmr0NPOPytRRHk5QfeeqyFTJ7brcQ8/Uu01aFjhZlA=; b=OtzrijjATIU7G3AQPvGxSI25xsebZ73cJr/6EYgn4AT5Lr0fYqt/oeGAfi6Ju3nCLU 4p9f8ASS6tSOet2EfboSFPrr8SZsO8FvXSypnHFqrGE2q0/p/xzPE3IAZBwtf0bF6GU6 IIQ7820G/+054QeoUGcc3kDVImTKh+NpEj8dnDbuLtKncN+g88dEI9chgIPrIy5l8yLT WrJY+qpCKWh/MBIA+/cgqw602AIbkGNwEUt9rL4K0UlSll2hdqDyo4cIbnVJrcruwrDp HcPOWULcyz5cXh+xMP4+n/Vf2zM92/B/mQ4R3M5AWS8249rBNtKkJ38x79NJXt/SF2KN nYIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L+nxbdji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q25-20020a635c19000000b0046b1091d76bsi1356614pgb.416.2022.11.03.07.16.29; Thu, 03 Nov 2022 07:16:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L+nxbdji; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbiKCOPi (ORCPT + 99 others); Thu, 3 Nov 2022 10:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbiKCOPR (ORCPT ); Thu, 3 Nov 2022 10:15:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0605B2723 for ; Thu, 3 Nov 2022 07:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Rmr0NPOPytRRHk5QfeeqyFTJ7brcQ8/Uu01aFjhZlA=; b=L+nxbdjiHtrFF4eD5yQw1sH555zDz8VqPXi/84pwCaHrpCDurDaskJwOw+7qzFRfi9HUU7 naobVO0ZAj3Q10aTEb55jTJwKgZEjZW4rruvJbmwM9b3JYB21+28etHkEmByW2DenNcP46 /c93mel0BD36BfIi2fxvfarlYpDKcGQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-8QSbxQGbMy2_stjOx5gJeA-1; Thu, 03 Nov 2022 10:14:14 -0400 X-MC-Unique: 8QSbxQGbMy2_stjOx5gJeA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBBFD1C08780; Thu, 3 Nov 2022 14:14:12 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48C6B40C6EC3; Thu, 3 Nov 2022 14:14:08 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 4/9] KVM: x86: forcibly leave nested mode on vCPU reset Date: Thu, 3 Nov 2022 16:13:46 +0200 Message-Id: <20221103141351.50662-5-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484754679171685?= X-GMAIL-MSGID: =?utf-8?q?1748484754679171685?= While not obivous, kvm_vcpu_reset() leaves the nested mode by clearing 'vcpu->arch.hflags' but it does so without all the required housekeeping. On SVM, it is possible to have a vCPU reset while in guest mode because unlike VMX, on SVM, INIT's are not latched in SVM non root mode and in addition to that L1 doesn't have to intercept triple fault, which should also trigger L1's reset if happens in L2 while L1 didn't intercept it. If one of the above conditions happen, KVM will continue to use vmcb02 while not having in the guest mode. Later the IA32_EFER will be cleared which will lead to freeing of the nested guest state which will (correctly) free the vmcb02, but since KVM still uses it (incorrectly) this will lead to a use after free and kernel crash. This issue is assigned CVE-2022-3344 Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/x86.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 316ab1d5317f92..3fd900504e683b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11694,8 +11694,18 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) WARN_ON_ONCE(!init_event && (old_cr0 || kvm_read_cr3(vcpu) || kvm_read_cr4(vcpu))); + /* + * SVM doesn't unconditionally VM-Exit on INIT and SHUTDOWN, thus it's + * possible to INIT the vCPU while L2 is active. Force the vCPU back + * into L1 as EFER.SVME is cleared on INIT (along with all other EFER + * bits), i.e. virtualization is disabled. + */ + if (is_guest_mode(vcpu)) + kvm_leave_nested(vcpu); + kvm_lapic_reset(vcpu, init_event); + WARN_ON_ONCE(is_guest_mode(vcpu) || is_smm(vcpu)); vcpu->arch.hflags = 0; vcpu->arch.smi_pending = 0; From patchwork Thu Nov 3 14:13:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp560842wru; Thu, 3 Nov 2022 07:16:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KISJ17M0Hy2/HMdV7caH5tZytIDB6tfyASg4zRAgqWU05QWtuicVuYKnhPsL2p9cW6mp/ X-Received: by 2002:a05:6a00:78c:b0:56d:2:db06 with SMTP id g12-20020a056a00078c00b0056d0002db06mr30280780pfu.42.1667485013918; Thu, 03 Nov 2022 07:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485013; cv=none; d=google.com; s=arc-20160816; b=LFZ7jJYvVqNOd/h9XlGjUHJ1xB3OzU5Bp5pqv0ZZNNzKFeu6nhGTj8saGMqaHrRJkr J6/SRLGeR7qtUVNa/ORxdjC0UVzryCzOIKWLZ5pRUhPTpVSE/2kXpLoEWX6l1/MepEoc LoOuub7xZoLgsdYTdO0M6SHr1sIxFBQ/mwnYU6VAGPs5MFlpwzPFmP+oFTvfeGPmxj1n Xk4xu7yiBzM6xzuYBW8SQucfZnho9kY+NJyeJOjXRc9alXnNrvduQjSNaX31kvD5kTVj gdoXcR/LsrC5faiMN9eFWLGXzSEB1IE5F7XBJ0BNujhJpjV8bWiBLEUw0vRj95375Upe A57Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZJCktf5q7jZ9/undR/aqzDAHm9J60Hmp1ceVzBBD+a0=; b=ISvaA9Yr+43JB0baxQVskC5d6WL3Ulq9yTFXUCJtOZeP6xDD7idgWzvwhz5T9cRMFc /WjHhl4GhMRo2DKeyjmXWhHxNllvnPh1AUEiPdfABzclBY+olXwSMsGuFLUe5QEjcfDb DMShWqPfrGhxisXQAkQIfig4oMqmRFyJgk9K7UQ3vV+Df8zSejnnPU11IeHc9c8XOYHe 2ASRzmJqxviX6F/XENM7ixYDniBDfyUwveQ9FYUO8ybYC4lduNt4/A/hdOdy5jg9TuGO aRC9FHtGJ8ISjHVwIkmdpBl0FMeh/w6a+vMMVUyjWr2lXcu554aC8bzhVJEkvlA4+ArZ ujoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OrKJRwm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a170902e5c600b001846e0e0511si1058679plf.226.2022.11.03.07.16.38; Thu, 03 Nov 2022 07:16:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OrKJRwm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbiKCOPw (ORCPT + 99 others); Thu, 3 Nov 2022 10:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbiKCOPW (ORCPT ); Thu, 3 Nov 2022 10:15:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B404BF582 for ; Thu, 3 Nov 2022 07:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJCktf5q7jZ9/undR/aqzDAHm9J60Hmp1ceVzBBD+a0=; b=OrKJRwm0lY8xpjFRtgp+I4EpxJy+jnaRXUmYmHw5PX07qYbLloBfZOpYzhUgjYAYpQ9bhy GgarTbRyCSgLKHQcpCN+U+bz4LNHGqrdVjbxM6wyfolM3/nrk3PZ9ZmavOJorI9NgbKX6H WwADM/O+RngFwjKP+6yx3ig957yCxv8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-wA31PaRqNXCLvYz9hD7aDg-1; Thu, 03 Nov 2022 10:14:17 -0400 X-MC-Unique: wA31PaRqNXCLvYz9hD7aDg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF73485A5B6; Thu, 3 Nov 2022 14:14:16 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30DD640C6EC3; Thu, 3 Nov 2022 14:14:13 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack Subject: [PATCH v2 5/9] KVM: selftests: move idt_entry to header Date: Thu, 3 Nov 2022 16:13:47 +0200 Message-Id: <20221103141351.50662-6-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484765646331248?= X-GMAIL-MSGID: =?utf-8?q?1748484765646331248?= struct idt_entry will be used for a test which will break IDT on purpose. Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- .../selftests/kvm/include/x86_64/processor.h | 13 +++++++++++++ tools/testing/selftests/kvm/lib/x86_64/processor.c | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index e8ca0d8a6a7e0a..5da0c5e2a7afc4 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -748,6 +748,19 @@ struct ex_regs { uint64_t rflags; }; +struct idt_entry { + uint16_t offset0; + uint16_t selector; + uint16_t ist : 3; + uint16_t : 5; + uint16_t type : 4; + uint16_t : 1; + uint16_t dpl : 2; + uint16_t p : 1; + uint16_t offset1; + uint32_t offset2; uint32_t reserved; +}; + void vm_init_descriptor_tables(struct kvm_vm *vm); void vcpu_init_descriptor_tables(struct kvm_vcpu *vcpu); void vm_install_exception_handler(struct kvm_vm *vm, int vector, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 39c4409ef56a6a..41c1c73c464d48 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1074,19 +1074,6 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) } } -struct idt_entry { - uint16_t offset0; - uint16_t selector; - uint16_t ist : 3; - uint16_t : 5; - uint16_t type : 4; - uint16_t : 1; - uint16_t dpl : 2; - uint16_t p : 1; - uint16_t offset1; - uint32_t offset2; uint32_t reserved; -}; - static void set_idt_entry(struct kvm_vm *vm, int vector, unsigned long addr, int dpl, unsigned short selector) { From patchwork Thu Nov 3 14:13:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561236wru; Thu, 3 Nov 2022 07:17:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LsT/9wuqr2wvaejsiLaHBuMtK/KRZS/4D5+E14sncYW4e39Gay2Il8SIO8GzM8K4EWz/J X-Received: by 2002:a17:90a:d244:b0:213:aa62:7a91 with SMTP id o4-20020a17090ad24400b00213aa627a91mr29377631pjw.101.1667485056065; Thu, 03 Nov 2022 07:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485056; cv=none; d=google.com; s=arc-20160816; b=xYyY+nD36f8h4/9UhbJYquwQSMUkdP24dhDSDLtx9ahl+Qs7WISXWvzRIwK+9S8SBB oFE8VkiPYA9c2lEprf6YFUj6d+D1u5MQXouzp1udSVNxplWkEMK+tduoAMQp9Ae4Qa28 qQO+E077IignAePAjCcal0rS9EA12Oam3LYmDxtAC3zjadxJjnkoBxmekC1XhfM9SMo9 oiiT5yViiJbvC5onMBvDrojAOERY98HQudio3l2FFXy8o+itjuRHIwBb40KtwCUvM+60 8A7vjYNY76T1Q78NRoBwuv1ZmFUUEFwa4PNjIGO7UyZfXw7XoA4JtSrO1TvR1BUzL+lP pt8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yBY6+Wpx8c1HV9QootYh8PbPrW04DR2GqIrNFdSxlfY=; b=boRy2lYXqFJiZoHsFmGWbo9hKNLB+puGVvTUTo9sngA4avvrH+9fxgBLIAkm9zsbUF TEl4qpsDHUvin4Z4bGYjVPxOnlbhAoOlr7/cuJJtUh+YotWV4z7gJ2jTJAv/TD3hTVYe SpYe3ozrypIfJb4DV8ZlvKsI86wO6Qwc/JZzfhLKJ6L7ugZx1twqB6vF06mn6rwd0//V Pvw9Xt/5gpgng+9yRHvMgQRjQvAUc3TZQ1V/S3eau91M+J7oRepBxyndUTWXRblzFEJ7 choxJaxtn/SWnn4NM0uE8XsFgs6anmTXFabJ7Drcsrg2btAHAbTDxBYLa49Kc1BeeL/Y qUHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gbqICAox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u38-20020a634566000000b0046af646c669si1102983pgk.664.2022.11.03.07.17.21; Thu, 03 Nov 2022 07:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gbqICAox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbiKCOQF (ORCPT + 99 others); Thu, 3 Nov 2022 10:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiKCOPa (ORCPT ); Thu, 3 Nov 2022 10:15:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6DB11C1B for ; Thu, 3 Nov 2022 07:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yBY6+Wpx8c1HV9QootYh8PbPrW04DR2GqIrNFdSxlfY=; b=gbqICAoxvo2P4c9GwWyz2a2WGjm9Yk1SP1MxiIzmI3eYZvTMOCwPl6GnW/X3oj3yEdHrm8 4CDMQCm6s0H2OmR9y/wvvPo1UCPwQOSPYAAeLaF7DqlA+6HhvmQlNHytT+Y4NAe0xTGOnR JM0oYbokq9+Co3PDlMlMjk6fKcJE2I8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-8o0VhxxEOfG_-aHeLN-64g-1; Thu, 03 Nov 2022 10:14:22 -0400 X-MC-Unique: 8o0VhxxEOfG_-aHeLN-64g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E38E101A54E; Thu, 3 Nov 2022 14:14:20 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0973640C6DC7; Thu, 3 Nov 2022 14:14:16 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack Subject: [PATCH v2 6/9] kvm: selftests: add svm nested shutdown test Date: Thu, 3 Nov 2022 16:13:48 +0200 Message-Id: <20221103141351.50662-7-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484810136043759?= X-GMAIL-MSGID: =?utf-8?q?1748484810136043759?= Add test that tests that on SVM if L1 doesn't intercept SHUTDOWN, then L2 crashes L1 and doesn't crash L2 Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/svm_nested_shutdown_test.c | 67 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/svm_nested_shutdown_test.c diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index 2f0d705db9dba5..05d980fb083d17 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -41,6 +41,7 @@ /x86_64/svm_vmcall_test /x86_64/svm_int_ctl_test /x86_64/svm_nested_soft_inject_test +/x86_64/svm_nested_shutdown_test /x86_64/sync_regs_test /x86_64/tsc_msrs_test /x86_64/tsc_scaling_sync diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 0172eb6cb6eee2..4a2caef2c9396f 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -101,6 +101,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/state_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test +TEST_GEN_PROGS_x86_64 += x86_64/svm_nested_shutdown_test TEST_GEN_PROGS_x86_64 += x86_64/svm_nested_soft_inject_test TEST_GEN_PROGS_x86_64 += x86_64/tsc_scaling_sync TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_shutdown_test.c b/tools/testing/selftests/kvm/x86_64/svm_nested_shutdown_test.c new file mode 100644 index 00000000000000..e73fcdef47bbe9 --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_shutdown_test.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * svm_nested_shutdown_test + * + * Copyright (C) 2022, Red Hat, Inc. + * + * Nested SVM testing: test that unintercepted shutdown in L2 doesn't crash the host + */ + +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "svm_util.h" + +static void l2_guest_code(struct svm_test_data *svm) +{ + __asm__ __volatile__("ud2"); +} + +static void l1_guest_code(struct svm_test_data *svm, struct idt_entry *idt) +{ + #define L2_GUEST_STACK_SIZE 64 + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + struct vmcb *vmcb = svm->vmcb; + + generic_svm_setup(svm, l2_guest_code, + &l2_guest_stack[L2_GUEST_STACK_SIZE]); + + vmcb->control.intercept &= ~(BIT(INTERCEPT_SHUTDOWN)); + + idt[6].p = 0; // #UD is intercepted but its injection will cause #NP + idt[11].p = 0; // #NP is not intercepted and will cause another + // #NP that will be converted to #DF + idt[8].p = 0; // #DF will cause #NP which will cause SHUTDOWN + + run_guest(vmcb, svm->vmcb_gpa); + + /* should not reach here */ + GUEST_ASSERT(0); +} + +int main(int argc, char *argv[]) +{ + struct kvm_vcpu *vcpu; + struct kvm_run *run; + vm_vaddr_t svm_gva; + struct kvm_vm *vm; + + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); + + vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); + vm_init_descriptor_tables(vm); + vcpu_init_descriptor_tables(vcpu); + + vcpu_alloc_svm(vm, &svm_gva); + + vcpu_args_set(vcpu, 2, svm_gva, vm->idt); + run = vcpu->run; + + vcpu_run(vcpu); + TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, + "Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n", + run->exit_reason, + exit_reason_str(run->exit_reason)); + + kvm_vm_free(vm); +} From patchwork Thu Nov 3 14:13:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561134wru; Thu, 3 Nov 2022 07:17:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nJnEtT6JyJtpS+kT8TLg0OkuBFTb8DfZe9uWVjChhEmJuk9apCQMmuuRUq7doMD8vtRLr X-Received: by 2002:a63:4307:0:b0:464:a24d:8201 with SMTP id q7-20020a634307000000b00464a24d8201mr26636929pga.116.1667485043977; Thu, 03 Nov 2022 07:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485043; cv=none; d=google.com; s=arc-20160816; b=pb6+hKojh/F1QBUFpUTDvjsNH6EB876RqCMFkH9EW2bV9hkqGsrQjTzvb5iP+GIPLD JWxE8A/57e5/UOoHgu3hBsI1Eul++pbpKltjmS4R7PGBWUi+lgDFPjajE/Mapd5kFAHj oHMJ6T3z8JRnPOz+oDiUFJpzZWAFQ+kC4VHAiLR+ylaCdC2CjLzzm2fC+enLr1Zf+ZFA bZb96lTMa5scHQtGItJHGNzJLaA1HhVTACpWBijuIqo71V4airtEVmFgK8/+LVKjXkL8 XMvH4JJ0ZriHMGTbYRwqruprbPExQu20OEFw/kRCdWrT0l/c17G9auZiOuf4cAAF7CEe bRhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PcvbZGqx/pbGysS7eWOgjCD7HbL3pDHBihn3geMPwgo=; b=a+8ZBPGcMHBfquO5ybcAuymEmWTc4P5kyj4cpojiTfbCFE17fqplioY9NZTzo1zPWp a6mdAfGT+ota8/lxhoZZbwwjgdPgaerzG/y7MahuiZqrmm8hxV/rTHZ9/yLuajERcRnF dF1wpp6bYjFUk4Lg1C9HYfd8NInv2JmK7bfFcODE+BHb9hqYp6UElWWT316FFUHzDi8d 4C+exAtFACS99nTQGFKaoV2lkRTD2YeRx3aRnPserVIneG4Kp1Q0srGuaDjcKGGbsN/V J7y1UnzcQMM8tt570b2H1Xj3s17NJO4/prYHEAFOFEsmIVvPVwh9MmWZ7UTl/8U2MdzP o24w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ddWP0u5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y78-20020a626451000000b0056b940147c6si961241pfb.322.2022.11.03.07.17.10; Thu, 03 Nov 2022 07:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ddWP0u5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbiKCOQJ (ORCPT + 99 others); Thu, 3 Nov 2022 10:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbiKCOPd (ORCPT ); Thu, 3 Nov 2022 10:15:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 210C513D7A for ; Thu, 3 Nov 2022 07:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PcvbZGqx/pbGysS7eWOgjCD7HbL3pDHBihn3geMPwgo=; b=ddWP0u5eTeB7gDkz8fnQIMZSg16tduHowkfx+xpmvINqLFQPWJNS6slIto0e0BsFqr1jWC 4Qp3BzYri+/9SOANW7Jkj2ZnXPQMEPWPGHnC8VbXOFk4JBwehPZp6vOjOPTFrVJ8noasm7 EZbaIe6fxMUXR6T7t/XDzmaKCk21Q+8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-624-r7oC7QNnMnKdtxDRwXGArQ-1; Thu, 03 Nov 2022 10:14:25 -0400 X-MC-Unique: r7oC7QNnMnKdtxDRwXGArQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94C51101AA45; Thu, 3 Nov 2022 14:14:24 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDB7440C6EC3; Thu, 3 Nov 2022 14:14:20 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack Subject: [PATCH v2 7/9] KVM: x86: allow L1 to not intercept triple fault Date: Thu, 3 Nov 2022 16:13:49 +0200 Message-Id: <20221103141351.50662-8-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484797598120261?= X-GMAIL-MSGID: =?utf-8?q?1748484797598120261?= This is SVM correctness fix - although a sane L1 would intercept SHUTDOWN event, it doesn't have to, so we have to honour this. Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/svm/nested.c | 6 ++++++ arch/x86/kvm/vmx/nested.c | 1 + arch/x86/kvm/x86.c | 11 ++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index bcc4f6620f8aec..3aa9184d1e4ed7 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1092,6 +1092,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) static void nested_svm_triple_fault(struct kvm_vcpu *vcpu) { + struct vcpu_svm *svm = to_svm(vcpu); + + if (!vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_SHUTDOWN)) + return; + + kvm_clear_request(KVM_REQ_TRIPLE_FAULT, vcpu); nested_svm_simple_vmexit(to_svm(vcpu), SVM_EXIT_SHUTDOWN); } diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1ebe141a0a015f..7924dea9367813 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4855,6 +4855,7 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, static void nested_vmx_triple_fault(struct kvm_vcpu *vcpu) { + kvm_clear_request(KVM_REQ_TRIPLE_FAULT, vcpu); nested_vmx_vmexit(vcpu, EXIT_REASON_TRIPLE_FAULT, 0, 0); } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3fd900504e683b..f0a0102a78f5c3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9741,7 +9741,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu) int kvm_check_nested_events(struct kvm_vcpu *vcpu) { - if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { + if (kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { kvm_x86_ops.nested_ops->triple_fault(vcpu); return 1; } @@ -10255,15 +10255,16 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r = 0; goto out; } - if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { - if (is_guest_mode(vcpu)) { + if (kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { + if (is_guest_mode(vcpu)) kvm_x86_ops.nested_ops->triple_fault(vcpu); - } else { + + if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN; vcpu->mmio_needed = 0; r = 0; - goto out; } + goto out; } if (kvm_check_request(KVM_REQ_APF_HALT, vcpu)) { /* Page is swapped out. Do synthetic halt */ From patchwork Thu Nov 3 14:13:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561004wru; Thu, 3 Nov 2022 07:17:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uTSF+7g5Cy8MUrWYz95tEi0g3AddCfVWGgHXec8E7JzU7cJZ92qnGbrbqOZPfmd0RenwR X-Received: by 2002:a65:44c1:0:b0:428:ab8f:62dd with SMTP id g1-20020a6544c1000000b00428ab8f62ddmr26382287pgs.211.1667485029643; Thu, 03 Nov 2022 07:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485029; cv=none; d=google.com; s=arc-20160816; b=VcMNBUxk/1CPwY90bEXCj2UwyUtLM/exWUTIqGL89echX2IMCiz6Kfa8/vA7erWgs9 cWY7vy4MiIV3BYAc6syrU7RMH1gbP+MoGrugkFE60zd9Xf61nBy9GeihPSEBpjABYcd6 hkfdxu0k7W+TcILcZU8THz+tN3Gv/9H22xTxueGqvKAn9gvdJ8QFU06gehVi6+ABTCsJ SKIpIk1359kSM5c+5UYlcCayVi0zuf5TlXEp77+O8H3L8lc9rctzQj8gAqCS+9AvvNCb bcD6UaYblvq14eOF4nxRTDL0ypcpdTL2O4YoCQXUrYZWqeHFOrJ9uNqSqOZ49ltekBXl /ixA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MLisqYCuvhrvJZvVGDjJWbAbpZRyes0U6eXBtx/XUoI=; b=by0QJHayWWUElBOA2o06627TBGheBu5GS1cd96MvNOklpwUdbJ+q4znnbnOmo9oVzt fNAbVSVA+yLSlAEvz6I7rOn+aTIU7LlUq7lm4QL2iY0JsLnrZCAgGK657wPrnydTB5l+ 4qCPsxhVYRw208031y/Nc4Xt/29BPbyW9xu1ckclXEmvjQVibWQhPEcU6vaq+AbDNvzS NDCCqDO/hMY80BzeMeA7T/6yBKGYzI0VcXcK0OBB6ZV0OsuALWPwtc2BG/TtlN/Xnngh 7d64kisas0FrmVjZr9byJ0q7SUQoozU/YzQGoF/AhwFUUfkJJTvI7uX0wVE66au3Ht0l OYAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZszUz8VR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630084000000b00462566bfda8si1286363pga.788.2022.11.03.07.16.54; Thu, 03 Nov 2022 07:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZszUz8VR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231524AbiKCOQN (ORCPT + 99 others); Thu, 3 Nov 2022 10:16:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbiKCOPg (ORCPT ); Thu, 3 Nov 2022 10:15:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4830014D0C for ; Thu, 3 Nov 2022 07:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MLisqYCuvhrvJZvVGDjJWbAbpZRyes0U6eXBtx/XUoI=; b=ZszUz8VRJo+gXcwQs98VjRPXGQQ7rV+/3aPkUiM4AxrUUp5ooi9U+hCxfxF/mhG/UIc7hg Y9XG8zoNE9MTeWqIIankkVUHDzEywDEGIY0RMeirdPw2/lyBXoW2irOY1vxoHYV+26b+gp YKdYZVUvLwhT5MUNGqK5rkTSHBNTUFk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-XYaCv1I2OcytzkJHCNS6sw-1; Thu, 03 Nov 2022 10:14:31 -0400 X-MC-Unique: XYaCv1I2OcytzkJHCNS6sw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91AE0800B30; Thu, 3 Nov 2022 14:14:29 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4F4B40C6EC3; Thu, 3 Nov 2022 14:14:24 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack Subject: [PATCH v2 8/9] KVM: selftests: add svm part to triple_fault_test Date: Thu, 3 Nov 2022 16:13:50 +0200 Message-Id: <20221103141351.50662-9-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484782631205002?= X-GMAIL-MSGID: =?utf-8?q?1748484782631205002?= Add a SVM implementation to triple_fault_test to test that emulated/injected shutdown works. Since instead of the VMX, the SVM allows the hypervisor to avoid intercepting shutdown in guest, don't intercept shutdown to test that KVM suports this correctly. Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- .../kvm/x86_64/triple_fault_event_test.c | 73 ++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c b/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c index 70b44f0b52fef2..ead5d878a71c45 100644 --- a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c +++ b/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c @@ -3,6 +3,7 @@ #include "kvm_util.h" #include "processor.h" #include "vmx.h" +#include "svm_util.h" #include #include @@ -20,10 +21,11 @@ static void l2_guest_code(void) : : [port] "d" (ARBITRARY_IO_PORT) : "rax"); } -void l1_guest_code(struct vmx_pages *vmx) -{ #define L2_GUEST_STACK_SIZE 64 - unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; +unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + +void l1_guest_code_vmx(struct vmx_pages *vmx) +{ GUEST_ASSERT(vmx->vmcs_gpa); GUEST_ASSERT(prepare_for_vmx_operation(vmx)); @@ -38,24 +40,53 @@ void l1_guest_code(struct vmx_pages *vmx) GUEST_DONE(); } +void l1_guest_code_svm(struct svm_test_data *svm) +{ + struct vmcb *vmcb = svm->vmcb; + + generic_svm_setup(svm, l2_guest_code, + &l2_guest_stack[L2_GUEST_STACK_SIZE]); + + /* don't intercept shutdown to test the case of SVM allowing to do so */ + vmcb->control.intercept &= ~(BIT(INTERCEPT_SHUTDOWN)); + + run_guest(vmcb, svm->vmcb_gpa); + + /* should not reach here, L1 should crash */ + GUEST_ASSERT(0); +} + int main(void) { struct kvm_vcpu *vcpu; struct kvm_run *run; struct kvm_vcpu_events events; - vm_vaddr_t vmx_pages_gva; struct ucall uc; - TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); + bool has_vmx = kvm_cpu_has(X86_FEATURE_VMX); + bool has_svm = kvm_cpu_has(X86_FEATURE_SVM); + + TEST_REQUIRE(has_vmx || has_svm); TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_TRIPLE_FAULT_EVENT)); - vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); - vm_enable_cap(vm, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 1); + if (has_vmx) { + vm_vaddr_t vmx_pages_gva; + + vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code_vmx); + vcpu_alloc_vmx(vm, &vmx_pages_gva); + vcpu_args_set(vcpu, 1, vmx_pages_gva); + } else { + vm_vaddr_t svm_gva; + + vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code_svm); + vcpu_alloc_svm(vm, &svm_gva); + vcpu_args_set(vcpu, 1, svm_gva); + } + + vm_enable_cap(vm, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 1); run = vcpu->run; - vcpu_alloc_vmx(vm, &vmx_pages_gva); - vcpu_args_set(vcpu, 1, vmx_pages_gva); vcpu_run(vcpu); TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, @@ -78,13 +109,21 @@ int main(void) "No triple fault pending"); vcpu_run(vcpu); - switch (get_ucall(vcpu, &uc)) { - case UCALL_DONE: - break; - case UCALL_ABORT: - REPORT_GUEST_ASSERT(uc); - default: - TEST_FAIL("Unexpected ucall: %lu", uc.cmd); - } + if (has_svm) { + TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, + "Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n", + run->exit_reason, + exit_reason_str(run->exit_reason)); + } else { + switch (get_ucall(vcpu, &uc)) { + case UCALL_DONE: + break; + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + default: + TEST_FAIL("Unexpected ucall: %lu", uc.cmd); + } + } + return 0; } From patchwork Thu Nov 3 14:13:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 14914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp561251wru; Thu, 3 Nov 2022 07:17:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ne4Uel1NvZR1m3WOnIMunycAy5V3yF/Zlza4MEp19ivOP4CNxzFvD3CjXWlKyP+d4DBQk X-Received: by 2002:a63:d60b:0:b0:46f:8e44:9ce4 with SMTP id q11-20020a63d60b000000b0046f8e449ce4mr23153820pgg.308.1667485057575; Thu, 03 Nov 2022 07:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667485057; cv=none; d=google.com; s=arc-20160816; b=YDYKnzwLJAhWrd3OGiL6rLdTyPHWtJU1ITv1JPPUwaygt1pme/r2oCuKCNDOb75iU6 nW1MFEYv3fx/N/9U0gRIWliDY537t/WtJtPTjGt4VeAq+LYWPhEPxAO5YOVKrqE/XCvY ZsGNWWozMV0Jxk7HVt9Cz9xP7jc1urfmMAdqiSWybxeD6vDtce1gISl0FcP6I1SPanRa 02WZzC39Mbz1Rw4joVHa+7f5K5XwEuIc6FA4cSXceCWko5xorbpatFIS4r31qYIcfy8n GIJh1m0HZOLzN7A45A7IEVY6edlQN8IiGPPwCSMAHzmP42cHeNjausccxFCfdkvqmgoy RY2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FT9aNXqnuKXbR3StefJr7RNDWsInEBudWILSzsOk6wI=; b=qU4m7pTYz9FokUf4QveFyYpqRiF5NlEpU6ZxR+O1vDfKODQ9HGRHlAm1GURzdbVt18 LA209Tbhiq6H8YBUNfkhW38iMItT+QmrQtwcbkqVD+5gDMeNeBibKVacmHNlwSBV1l2/ 2QWgs9thwKrCcUr5UjF3lt7WVDgV7ZC7mQFS1aa681+e6vzuhCRZefTHNmWN7J3ZY+0u mPJwVQsBVyG6GtuAdJ7Z1rFz77O0Fr/Z3lXmTO+g32OpXiGa+DaBTcMHWaVn2NtWbXx0 w0fTTlRzxnwKtQlMbj/8KEQYdSdJ6R/fNxNR+k0tZ75riEd2VM7e69Fk3C1owrlvK70t L4Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=alSGSvKr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020aa7888b000000b00554e240fa1bsi1255336pfe.95.2022.11.03.07.17.24; Thu, 03 Nov 2022 07:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=alSGSvKr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbiKCOQT (ORCPT + 99 others); Thu, 3 Nov 2022 10:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbiKCOPl (ORCPT ); Thu, 3 Nov 2022 10:15:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34E6F13F07 for ; Thu, 3 Nov 2022 07:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FT9aNXqnuKXbR3StefJr7RNDWsInEBudWILSzsOk6wI=; b=alSGSvKr+WORyuxK6qzt7U9rnJVBew5MzTl0DcjKFrAfbQjSVJ7Y7jbUPPQYf3FfNKIvGQ IdVagG2hx2EdYunpyLFadGtmYI9Dey3tCd9lfhj288klCYN3aPPW0NFKEcC5PK3FZdYXNG WynhUzu8MiTaDZbnlzur5JeqfPwfk84= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-108-8Qpk1q88NTOADxqZAGJhHA-1; Thu, 03 Nov 2022 10:14:35 -0400 X-MC-Unique: 8Qpk1q88NTOADxqZAGJhHA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2C662A2AD7D; Thu, 3 Nov 2022 14:14:33 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9E4640C6EC3; Thu, 3 Nov 2022 14:14:29 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 9/9] KVM: x86: remove exit_int_info warning in svm_handle_exit Date: Thu, 3 Nov 2022 16:13:51 +0200 Message-Id: <20221103141351.50662-10-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484812069024920?= X-GMAIL-MSGID: =?utf-8?q?1748484812069024920?= It is valid to receive external interrupt and have broken IDT entry, which will lead to #GP with exit_int_into that will contain the index of the IDT entry (e.g any value). Other exceptions can happen as well, like #NP or #SS (if stack switch fails). Thus this warning can be user triggred and has very little value. Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky Reviewed-by: Liam Merwick --- arch/x86/kvm/svm/svm.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index e9cec1b692051c..36f651ce842174 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3428,15 +3428,6 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) return 0; } - if (is_external_interrupt(svm->vmcb->control.exit_int_info) && - exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR && - exit_code != SVM_EXIT_NPF && exit_code != SVM_EXIT_TASK_SWITCH && - exit_code != SVM_EXIT_INTR && exit_code != SVM_EXIT_NMI) - printk(KERN_ERR "%s: unexpected exit_int_info 0x%x " - "exit_code 0x%x\n", - __func__, svm->vmcb->control.exit_int_info, - exit_code); - if (exit_fastpath != EXIT_FASTPATH_NONE) return 1;