From nobody Mon Feb 9 19:07:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487959268219186.90497190300357; Fri, 24 Feb 2017 10:01:08 -0800 (PST) Received: from localhost ([::1]:39000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKB0-0005bH-TK for importer@patchew.org; Fri, 24 Feb 2017 13:01:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chJrJ-0007vR-5F for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chJrH-0002Gu-MC for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:45 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:32802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1chJrH-0002Gf-F3 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:40:43 -0500 Received: by mail-wr0-x242.google.com with SMTP id g10so2805036wrg.0 for ; Fri, 24 Feb 2017 09:40:43 -0800 (PST) Received: from 640k.lan (94-39-187-56.adsl-ull.clienti.tiscali.it. [94.39.187.56]) by smtp.gmail.com with ESMTPSA id s26sm8814533wra.66.2017.02.24.09.40.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 09:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=oX/buaOcVLZZekiBuJB43zKw9GGtxx9nLPtjnMhu9Ds=; b=quVcj/6ScYpFvT3KtGaaXmC2EzgQZ76ImjcNv9YWlvuvlEk/lYv16W5hQl4cjDNi90 O+2Icc4177PrKd5CR4LPKXnJbOCSVJINSmFJTxwtbvM8Y9HLtScBKuARepvGIXbF3UmF iFVLcq5gTUDwmwd+5s7xXTfUYuNlxIWd5qFDuw+gBBzwaqtZJDlJmuWlSqllQRC2wQuA 7bemGlVAQC3oinNW7RY9fXYByDEvAhty8hVfAz6X7ZLmOxHUavn6qhLT/Gl8W+6ndb2B +9S+goEBERTvoOn1B/Llhn8ciKz1deIyX1/B3xrNEMnkegafqQyp99ZoHOGZ3/491qzR ZNAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=oX/buaOcVLZZekiBuJB43zKw9GGtxx9nLPtjnMhu9Ds=; b=aMBaYUl9BUMY04n59FN0k0hURQrcGuXw65aezARrU2A8FiWh6XRCoQweNsy/shU9iX gmq1AsXUmoCILtzDSssTYgkuGxceHM8zIrwG94u6/0YQuhLEpqUqgfhi1ewbHG/5X1yk wnNx+bDHwIU90+Hir9/UgVp26/RZfu0yTE/2reCaBLGvMkLDBZusjPCPpIhTh7FY2zsv 4hJu/EnjNVUIRrkbGw878Aw3QT/Jo8FOktLbh4HlNz7oAe2SvK4b3G6cpLvYARJwT1x4 JCLEvqU7AvSfdTYFWx9x6piafYaRGMvoq6Q0foc9ASr72G4A12X/V5lLp95iHTb8Uxy5 lKvw== X-Gm-Message-State: AMke39k4ztRBBrcIzkICPFcvs195GE/7Ly6A4dvu59Cjwxi4dusqxTggAqEORHiLZvlmMA== X-Received: by 10.223.163.75 with SMTP id d11mr3530147wrb.74.1487958042174; Fri, 24 Feb 2017 09:40:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 24 Feb 2017 18:40:20 +0100 Message-Id: <1487958030-51417-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487958030-51417-1-git-send-email-pbonzini@redhat.com> References: <1487958030-51417-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 07/17] KVM: x86: cleanup SIGBUS handlers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch should have no semantic change. Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 81 ++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 27fd050..0c48dfd 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -469,31 +469,34 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, vo= id *addr) ram_addr_t ram_addr; hwaddr paddr; =20 - if ((env->mcg_cap & MCG_SER_P) && addr - && (code =3D=3D BUS_MCEERR_AR || code =3D=3D BUS_MCEERR_AO)) { + if (code !=3D BUS_MCEERR_AR && code !=3D BUS_MCEERR_AO) { + return 1; + } + + /* Because the MCE happened while running the VCPU, KVM could have + * injected action required MCEs too. Action optional MCEs should + * be delivered to the main thread, which qemu_init_sigbus identifies + * as the "early kill" thread, but if we get one for whatever reason + * we just handle it just like the main thread would. + */ + if ((env->mcg_cap & MCG_SER_P) && addr) { ram_addr =3D qemu_ram_addr_from_host(addr); - if (ram_addr =3D=3D RAM_ADDR_INVALID || - !kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr= )) { - fprintf(stderr, "Hardware memory error for memory used by " - "QEMU itself instead of guest system!\n"); - /* Hope we are lucky for AO MCE */ - if (code =3D=3D BUS_MCEERR_AO) { - return 0; - } else { - hardware_memory_error(); - } - } - kvm_hwpoison_page_add(ram_addr); - kvm_mce_inject(cpu, paddr, code); - } else { - if (code =3D=3D BUS_MCEERR_AO) { + if (ram_addr !=3D RAM_ADDR_INVALID && + kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)= ) { + kvm_hwpoison_page_add(ram_addr); + kvm_mce_inject(cpu, paddr, code); return 0; - } else if (code =3D=3D BUS_MCEERR_AR) { - hardware_memory_error(); - } else { - return 1; } + + fprintf(stderr, "Hardware memory error for memory used by " + "QEMU itself instead of guest system!\n"); + } + + if (code =3D=3D BUS_MCEERR_AR) { + hardware_memory_error(); } + + /* Hope we are lucky for AO MCE */ return 0; } =20 @@ -501,29 +504,29 @@ int kvm_arch_on_sigbus(int code, void *addr) { X86CPU *cpu =3D X86_CPU(first_cpu); =20 - if ((cpu->env.mcg_cap & MCG_SER_P) && addr && code =3D=3D BUS_MCEERR_A= O) { + if (code !=3D BUS_MCEERR_AR && code !=3D BUS_MCEERR_AO) { + return 1; + } + + if (code =3D=3D BUS_MCEERR_AR) { + hardware_memory_error(); + } + + /* Hope we are lucky for AO MCE */ + if ((cpu->env.mcg_cap & MCG_SER_P) && addr) { ram_addr_t ram_addr; hwaddr paddr; =20 - /* Hope we are lucky for AO MCE */ ram_addr =3D qemu_ram_addr_from_host(addr); - if (ram_addr =3D=3D RAM_ADDR_INVALID || - !kvm_physical_memory_addr_from_host(first_cpu->kvm_state, - addr, &paddr)) { - fprintf(stderr, "Hardware memory error for memory used by " - "QEMU itself instead of guest system!: %p\n", addr); - return 0; - } - kvm_hwpoison_page_add(ram_addr); - kvm_mce_inject(X86_CPU(first_cpu), paddr, code); - } else { - if (code =3D=3D BUS_MCEERR_AO) { - return 0; - } else if (code =3D=3D BUS_MCEERR_AR) { - hardware_memory_error(); - } else { - return 1; + if (ram_addr !=3D RAM_ADDR_INVALID && + kvm_physical_memory_addr_from_host(first_cpu->kvm_state, + addr, &paddr)) { + kvm_hwpoison_page_add(ram_addr); + kvm_mce_inject(X86_CPU(first_cpu), paddr, code); } + + fprintf(stderr, "Hardware memory error for memory used by " + "QEMU itself instead of guest system!: %p\n", addr); } return 0; } --=20 1.8.3.1