From nobody Wed Nov 27 14:38:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1698276590; cv=none; d=zohomail.com; s=zohoarc; b=ilGn9fvRCpBRiRvcKbsFboGRv2RIICEB29ENmP3IH8H1Y+N4okc+0+hlwBz24+aiu1E4PPzO52C3vWY+JHlyj+/4c7EHK8c3GoSLJXJifFKtiW8ThSF8bR/Ex9++8FkzQBoKiWGiJwuZCPU8S1IHIE6aOUU7YSGAXeCJEaALJtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698276590; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=6N69hZKBR7s/GlHVtWXS5lie4mi2ng7NjiM/ZccHU/4=; b=bl/KxlPC31cvbC7Zr7E29ybCHZPowSHlyZzERkrdtYvweVEAkLgdztMqwK/ATEkx0l7aKjhcLSXtbPGNQB7W0g6+bBo+UPjpvoBMO/1qX/a9c3GBURvmvaEUebRA+q6sYVLaHiMC2PWifnO/RDd+4GP1GOUrtS+ZKGZZGtYfb0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698276590694369.0712464785844; Wed, 25 Oct 2023 16:29:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvnIC-0001rH-N9; Wed, 25 Oct 2023 19:28:04 -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 1qvnI9-0001iq-JB for qemu-devel@nongnu.org; Wed, 25 Oct 2023 19:28:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvnI7-0005J4-T7 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 19:28:01 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-4jTgxCLDPXW5fX7pr4g-fQ-1; Wed, 25 Oct 2023 19:27:58 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-778999c5f1dso41788785a.2 for ; Wed, 25 Oct 2023 16:27:58 -0700 (PDT) Received: from [172.19.0.201] ([192.80.84.35]) by smtp.gmail.com with ESMTPSA id j17-20020a05620a001100b0077703f31496sm4572661qki.92.2023.10.25.16.27.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 16:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698276479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6N69hZKBR7s/GlHVtWXS5lie4mi2ng7NjiM/ZccHU/4=; b=ij9l23oJ23HyK/JCESPEcF3LIM2UaJh6J4ea2mPvBA0plQ/YWq2jVsptKFkisI4i2ZNHKS 41XSbNsr3b7XKNig+B+VspGnaL2BfpuQiQHj611MENu1yAKMft4vZiBWT0o1jwe4CS9U14 xB1p2FE2EVRBgf29YL6Hljd0OsanVCs= X-MC-Unique: 4jTgxCLDPXW5fX7pr4g-fQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698276477; x=1698881277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6N69hZKBR7s/GlHVtWXS5lie4mi2ng7NjiM/ZccHU/4=; b=BEjaSnpm79bxwn4aINiBAfhNe+Y0BfhQd0ED3Eo/dQN132JZFjsit5PgPP8Ixc8yyT 0hJWMaHYBv+tIrc2epR36FJdOG4YXQs1gPqEtsBUO558X+rxHSIfdfAW8GoPtGqd334E CzY/2CECcfV9u31U97Wr0C0zyUETO9FW2RsBYYCF5G5oQPz81ilqY7nD99Q+6A0fkVP+ ogxwSWwBJ1q9TKuxOxrg07BietyVwXWn7blOC7fYbkNubpWRDjhmaerF6IUF3pTTXG7w d6XfAqAwCACvH6ZhC0cKA36zhKdcVTr2DmcUZ3j16etltcqfPlgxSzf7VA7XjZ+ncquB IB+g== X-Gm-Message-State: AOJu0YznpnOkqG6fmntFMOFGFJqZENfF6gKnvOOwpK51Ms4NGSXdiNRj HZsb0uYsHDYLbp1xKCF8CEJ+rFIVqSX4vDiu11sm+G5eEiQQtcg8tWj3uZpyQQaRIXgvieF+xUM Au43vqfJomp5oWYQQWbOA7uYmjnVtGsgu+AOnHysNnsKamy9BWW14vQ0dj49p32PexGSbruWo6p 8= X-Received: by 2002:a05:620a:2b9a:b0:77a:59c:d849 with SMTP id dz26-20020a05620a2b9a00b0077a059cd849mr76642qkb.33.1698276477271; Wed, 25 Oct 2023 16:27:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFv6PuimlhaqSMESg5NvImMvGMiQeGp8aENn0Pubu7SsL0GEv++XpM44XxGdpK3JGz88P8gSw== X-Received: by 2002:a05:620a:2b9a:b0:77a:59c:d849 with SMTP id dz26-20020a05620a2b9a00b0077a059cd849mr76628qkb.33.1698276476846; Wed, 25 Oct 2023 16:27:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 20/24] kvm: i386: require KVM_CAP_SET_VCPU_EVENTS and KVM_CAP_X86_ROBUST_SINGLESTEP Date: Thu, 26 Oct 2023 01:27:13 +0200 Message-ID: <20231025232718.89428-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231025232718.89428-1-pbonzini@redhat.com> References: <20231025232718.89428-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1698276591587100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 9 ---- include/sysemu/kvm.h | 1 - include/sysemu/kvm_int.h | 1 - target/i386/kvm/kvm.c | 92 +--------------------------------------- 4 files changed, 2 insertions(+), 101 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index aeda902b3e9..e39a810a4e9 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2524,10 +2524,6 @@ static int kvm_init(MachineState *ms) #ifdef KVM_CAP_VCPU_EVENTS s->vcpu_events =3D kvm_check_extension(s, KVM_CAP_VCPU_EVENTS); #endif - - s->robust_singlestep =3D - kvm_check_extension(s, KVM_CAP_X86_ROBUST_SINGLESTEP); - s->max_nested_state_len =3D kvm_check_extension(s, KVM_CAP_NESTED_STAT= E); =20 s->irq_set_ioctl =3D KVM_IRQ_LINE; @@ -3143,11 +3139,6 @@ int kvm_has_vcpu_events(void) return kvm_state->vcpu_events; } =20 -int kvm_has_robust_singlestep(void) -{ - return kvm_state->robust_singlestep; -} - int kvm_max_nested_state_length(void) { return kvm_state->max_nested_state_len; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 02c031d1f29..80b69d88f6e 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -192,7 +192,6 @@ unsigned int kvm_get_max_memslots(void); unsigned int kvm_get_free_memslots(void); bool kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void); -int kvm_has_robust_singlestep(void); int kvm_max_nested_state_length(void); int kvm_has_gsi_routing(void); =20 diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 151ecc84233..fd846394be1 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -78,7 +78,6 @@ struct KVMState struct kvm_coalesced_mmio_ring *coalesced_mmio_ring; bool coalesced_flush_in_progress; int vcpu_events; - int robust_singlestep; #ifdef KVM_CAP_SET_GUEST_DEBUG QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints; #endif diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 513a90f6307..4a244174a0f 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -95,6 +95,8 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = =3D { KVM_CAP_INFO(IRQ_ROUTING), KVM_CAP_INFO(DEBUGREGS), KVM_CAP_INFO(XSAVE), + KVM_CAP_INFO(VCPU_EVENTS), + KVM_CAP_INFO(X86_ROBUST_SINGLESTEP), KVM_CAP_LAST_INFO }; =20 @@ -690,15 +692,6 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, vo= id *addr) emit_hypervisor_memory_failure(MEMORY_FAILURE_ACTION_IGNORE, false); } =20 -static void kvm_reset_exception(CPUX86State *env) -{ - env->exception_nr =3D -1; - env->exception_pending =3D 0; - env->exception_injected =3D 0; - env->exception_has_payload =3D false; - env->exception_payload =3D 0; -} - static void kvm_queue_exception(CPUX86State *env, int32_t exception_nr, uint8_t exception_has_payload, @@ -731,38 +724,6 @@ static void kvm_queue_exception(CPUX86State *env, } } =20 -static int kvm_inject_mce_oldstyle(X86CPU *cpu) -{ - CPUX86State *env =3D &cpu->env; - - if (!kvm_has_vcpu_events() && env->exception_nr =3D=3D EXCP12_MCHK) { - unsigned int bank, bank_num =3D env->mcg_cap & 0xff; - struct kvm_x86_mce mce; - - kvm_reset_exception(env); - - /* - * There must be at least one bank in use if an MCE is pending. - * Find it and use its values for the event injection. - */ - for (bank =3D 0; bank < bank_num; bank++) { - if (env->mce_banks[bank * 4 + 1] & MCI_STATUS_VAL) { - break; - } - } - assert(bank < bank_num); - - mce.bank =3D bank; - mce.status =3D env->mce_banks[bank * 4 + 1]; - mce.mcg_status =3D env->mcg_status; - mce.addr =3D env->mce_banks[bank * 4 + 2]; - mce.misc =3D env->mce_banks[bank * 4 + 3]; - - return kvm_vcpu_ioctl(CPU(cpu), KVM_X86_SET_MCE, &mce); - } - return 0; -} - static void cpu_update_state(void *opaque, bool running, RunState state) { CPUX86State *env =3D opaque; @@ -4359,10 +4320,6 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int leve= l) CPUX86State *env =3D &cpu->env; struct kvm_vcpu_events events =3D {}; =20 - if (!kvm_has_vcpu_events()) { - return 0; - } - events.flags =3D 0; =20 if (has_exception_payload) { @@ -4430,10 +4387,6 @@ static int kvm_get_vcpu_events(X86CPU *cpu) struct kvm_vcpu_events events; int ret; =20 - if (!kvm_has_vcpu_events()) { - return 0; - } - memset(&events, 0, sizeof(events)); ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_GET_VCPU_EVENTS, &events); if (ret < 0) { @@ -4499,37 +4452,6 @@ static int kvm_get_vcpu_events(X86CPU *cpu) return 0; } =20 -static int kvm_guest_debug_workarounds(X86CPU *cpu) -{ - CPUState *cs =3D CPU(cpu); - CPUX86State *env =3D &cpu->env; - int ret =3D 0; - unsigned long reinject_trap =3D 0; - - if (!kvm_has_vcpu_events()) { - if (env->exception_nr =3D=3D EXCP01_DB) { - reinject_trap =3D KVM_GUESTDBG_INJECT_DB; - } else if (env->exception_injected =3D=3D EXCP03_INT3) { - reinject_trap =3D KVM_GUESTDBG_INJECT_BP; - } - kvm_reset_exception(env); - } - - /* - * Kernels before KVM_CAP_X86_ROBUST_SINGLESTEP overwrote flags.TF - * injected via SET_GUEST_DEBUG while updating GP regs. Work around th= is - * by updating the debug state once again if single-stepping is on. - * Another reason to call kvm_update_guest_debug here is a pending deb= ug - * trap raise by the guest. On kernels without SET_VCPU_EVENTS we have= to - * reinject them via SET_GUEST_DEBUG. - */ - if (reinject_trap || - (!kvm_has_robust_singlestep() && cs->singlestep_enabled)) { - ret =3D kvm_update_guest_debug(cs, reinject_trap); - } - return ret; -} - static int kvm_put_debugregs(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; @@ -4702,11 +4624,6 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } - /* must be before kvm_put_msrs */ - ret =3D kvm_inject_mce_oldstyle(x86_cpu); - if (ret < 0) { - return ret; - } ret =3D kvm_put_msrs(x86_cpu, level); if (ret < 0) { return ret; @@ -4730,11 +4647,6 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } - /* must be last */ - ret =3D kvm_guest_debug_workarounds(x86_cpu); - if (ret < 0) { - return ret; - } return 0; } =20 --=20 2.41.0