Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1026418rwb; Thu, 11 Aug 2022 14:27:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR5mkkMJ1obERReD8v4yZeX/b4wUNIqpQzrrChg15lA8g4dDsBRTk11CT3jqDKyGlTFBpoXl X-Received: by 2002:a17:90b:3ec2:b0:1f7:3f49:17c3 with SMTP id rm2-20020a17090b3ec200b001f73f4917c3mr10281627pjb.203.1660253253218; Thu, 11 Aug 2022 14:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660253253; cv=none; d=google.com; s=arc-20160816; b=iod1FV3lPw/ffvMMgC7H3vH63RsA/x7xRDHbcIggh/qsDB8nthLXEvY2c/d0YdMEyM ylZWwPwA8BnRvpeQE+Mr9hynKV503e/tDhZ/gE2X/yba2KkyUybA2Ss7mZI0ILhgi70n OfFo2kec4JI/jYh03/72enw+1/lG3U5+mWg2GgunjdukbCIZ+ybhelG2BfSZ4C4pvabX 3XfFVDgFx7nCMFj4+mxFUpqfvgL9/nKleV2buzzTfNBk9OX3yXcRGtTmDDgnQec74WTG bqeQxrueB6r/IDxUB8s3ijkwIFUYbtQwOVCqHNDRjfyziOTs6oUB11clKWUHLWD/J0f+ /ydQ== 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=4RKOyHsKBxxvzJ9NkJFblXxDl280JutW3/L7Ar2PgqY=; b=GrPaZ7K3uCXU0DrZ75lCQ2Hmb0iHDZ2FD2NGeYpReRa039haeL2KHgvlimU1XNAqrF 5+LsPn0am8NmCv7CIXHw0Rs6Kz7PJYDm6NLChzpSWZCe7uar22sE0JnCAOc2ALoXIpK/ yMr/D6pmcEA+G9KQFDuJHmE5fXHyrW84eu6NhY5KOEFYKs6YCyZ2vyhDV/JG1MWlyknb 3wzqPyTB7YgKgZ2m9UC2mym6X9K21eI1InfPjPfvW1FwCqKM4AIJSF4wPP3aBnT/8qH+ 9ulfWGp1XWyHiqnlNU19xvLckTaeN1tPPIy9tzmR4p1U8VxKCBSa3MmVAEh2UqigRPTg cYGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FmNKG2FD; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a63fb47000000b0041ce5d6153dsi435480pgj.249.2022.08.11.14.27.20; Thu, 11 Aug 2022 14:27:33 -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=FmNKG2FD; 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 S236552AbiHKVGp (ORCPT + 99 others); Thu, 11 Aug 2022 17:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236349AbiHKVGO (ORCPT ); Thu, 11 Aug 2022 17:06:14 -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 ESMTP id 42A758A6F4 for ; Thu, 11 Aug 2022 14:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660251972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4RKOyHsKBxxvzJ9NkJFblXxDl280JutW3/L7Ar2PgqY=; b=FmNKG2FDAm2OXSscExLG0MKvXduxa72x6EtaMD0H5IeeX3jhUsOBYQCdAbMni0I3wCMsgC ZEvk8iIO7Ozrd8afZGeWwSPU1v/0pxRenWAzLeGTP9x4Xzzih+PBFkuakAmgaENmadQC3m HztWJsMDmJ4phEIyATbsCwvodos9BwY= 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-587-92xKdmgLNcSAg3dlDrfPcQ-1; Thu, 11 Aug 2022 17:06:06 -0400 X-MC-Unique: 92xKdmgLNcSAg3dlDrfPcQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74064943211; Thu, 11 Aug 2022 21:06:06 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DD74492C3B; Thu, 11 Aug 2022 21:06:06 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, mlevitsk@redhat.com, vkuznets@redhat.com Subject: [PATCH v2 1/9] KVM: x86: check validity of argument to KVM_SET_MP_STATE Date: Thu, 11 Aug 2022 17:05:57 -0400 Message-Id: <20220811210605.402337-2-pbonzini@redhat.com> In-Reply-To: <20220811210605.402337-1-pbonzini@redhat.com> References: <20220811210605.402337-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 An invalid argument to KVM_SET_MP_STATE has no effect other than making the vCPU fail to run at the next KVM_RUN. Since it is extremely unlikely that any userspace is relying on it, fail with -EINVAL just like for other architectures. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 132d662d9713..c44348bb6ef2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10653,7 +10653,8 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu) case KVM_MP_STATE_INIT_RECEIVED: break; default: - return -EINTR; + WARN_ON(1); + break; } return 1; } @@ -11094,9 +11095,22 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, vcpu_load(vcpu); - if (!lapic_in_kernel(vcpu) && - mp_state->mp_state != KVM_MP_STATE_RUNNABLE) + switch (mp_state->mp_state) { + case KVM_MP_STATE_UNINITIALIZED: + case KVM_MP_STATE_HALTED: + case KVM_MP_STATE_AP_RESET_HOLD: + case KVM_MP_STATE_INIT_RECEIVED: + case KVM_MP_STATE_SIPI_RECEIVED: + if (!lapic_in_kernel(vcpu)) + goto out; + break; + + case KVM_MP_STATE_RUNNABLE: + break; + + default: goto out; + } /* * KVM_MP_STATE_INIT_RECEIVED means the processor is in -- 2.31.1