From nobody Sun Apr 28 22:48:58 2024 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; dkim=fail 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 1498720371747607.4747295220704; Thu, 29 Jun 2017 00:12:51 -0700 (PDT) Received: from localhost ([::1]:37362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQTdA-000486-Pv for importer@patchew.org; Thu, 29 Jun 2017 03:12:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQTc2-0003YR-Ns for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQTbz-0002Kd-49 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:38 -0400 Received: from mail-yw0-x241.google.com ([2607:f8b0:4002:c05::241]:36753) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQTby-0002KB-VT for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:35 -0400 Received: by mail-yw0-x241.google.com with SMTP id l21so3348218ywb.3 for ; Thu, 29 Jun 2017 00:11:33 -0700 (PDT) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id i4sm1838031ywc.68.2017.06.29.00.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 00:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7lmMbI6lQNRH4w/6G7Gim+2DJAzAY7UVtmcqayYZu/I=; b=sLyJKoqKC4oFUGWu1wrWgYdSmHB9I5ccvKhleJ9U8vC+vj811ZjndTz9K6gcb2idaH SlUteJVfEDRnEdstUx8tbVaOOKtxzv1w4NZ9csL7BwKL0AREKUD+vi+5ym+J+fyBDwW+ Adz81aFlrObFcq1aeqrf+SmLz5ftZRYsPoShhQsd8CBU9AQkBEZx+x6USyw7LlutMFUZ 4UZy4GJc5foWfgx6WlV2aZCsdDWPPQJxpZ49bw987UkZq8gyQC7AKbN5/mWTpIVCNAYe 4gwMHPtwk8F94dOx438cGGDq2/XMFNhV/uCMLndTUnVGIxzHEWZJr14kr4nYAISBk8I1 cNlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7lmMbI6lQNRH4w/6G7Gim+2DJAzAY7UVtmcqayYZu/I=; b=VLoSLpU3McwY9x7OlqJKRnWUiULzzpFO0Qry72NnH6XH7GfyV1yEQPVNqywwOJtlvD R3oSWbylMTc5VHFBkYWyR4WbPiboHPmjPn7r6o3XVimYXa27aCZxplgWW7RMDMkU63i3 o82AEBXE2MgrPoZuMaqAvmDACqZ+vGeWB/m1dr8pCg7MpdKXZvb5UCZ6xqp0HYC7msoe Jggg76NUL2F67MplFc2Z2AAKmGLjtLw6K7aQOeMUnrvkgrSMyP/53s6m82QIuwodKk5A 3GrZ/uyfLZZ16KKNmEdr79MVo9ElI4cFbxIupb9ai1K0U+IhstRi7/6bdwU6AgxUVmUi FOeA== X-Gm-Message-State: AKS2vOyOopxRg5uGsmX4f/hGp1uFQdO/ah+UuMvqwYtB5K8Fs6PFs55P r/FsH7sA0HM7TQ== X-Received: by 10.13.227.199 with SMTP id m190mr11276605ywe.293.1498720293021; Thu, 29 Jun 2017 00:11:33 -0700 (PDT) From: Pranith Kumar To: alex.bennee@linaro.org Date: Thu, 29 Jun 2017 03:11:28 -0400 Message-Id: <20170629071129.29362-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629071129.29362-1-bobby.prani@gmail.com> References: <20170629071129.29362-1-bobby.prani@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c05::241 Subject: [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race" 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: , Cc: Peter Maydell , pbonzini@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Now that we have proper locking after MTTCG patches have landed, we can revert the commit. This reverts commit a9353fe897ca2687e5b3385ed39e3db3927a90e0. CC: Peter Maydell CC: Alex Benn=C3=A9e Signed-off-by: Pranith Kumar --- exec.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 42ad1eaedd..c8403baa46 100644 --- a/exec.c +++ b/exec.c @@ -770,15 +770,28 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) #endif } =20 +#if defined(CONFIG_USER_ONLY) static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) { - /* Flush the whole TB as this will not have race conditions - * even if we don't have proper locking yet. - * Ideally we would just invalidate the TBs for the - * specified PC. - */ - tb_flush(cpu); + mmap_lock(); + tb_lock(); + tb_invalidate_phys_page_range(pc, pc + 1, 0); + tb_unlock(); + mmap_unlock(); } +#else +static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) +{ + MemTxAttrs attrs; + hwaddr phys =3D cpu_get_phys_page_attrs_debug(cpu, pc, &attrs); + int asidx =3D cpu_asidx_from_attrs(cpu, attrs); + if (phys !=3D -1) { + /* Locks grabbed by tb_invalidate_phys_addr */ + tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as, + phys | (pc & ~TARGET_PAGE_MASK)); + } +} +#endif =20 #if defined(CONFIG_USER_ONLY) void cpu_watchpoint_remove_all(CPUState *cpu, int mask) --=20 2.13.0 From nobody Sun Apr 28 22:48:58 2024 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; dkim=fail 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 14987204494811019.3460589547525; Thu, 29 Jun 2017 00:14:09 -0700 (PDT) Received: from localhost ([::1]:37365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQTeQ-000564-47 for importer@patchew.org; Thu, 29 Jun 2017 03:14:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQTc2-0003YS-Nu for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQTbz-0002KY-2f for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:38 -0400 Received: from mail-yw0-x241.google.com ([2607:f8b0:4002:c05::241]:34076) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQTby-0002KT-T5 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 03:11:35 -0400 Received: by mail-yw0-x241.google.com with SMTP id g124so4570967ywg.1 for ; Thu, 29 Jun 2017 00:11:34 -0700 (PDT) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id i4sm1838031ywc.68.2017.06.29.00.11.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 00:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SFbj6RMhcRdwRLzrL2Z6akt9f8c9eckKrFP3rm4yKlo=; b=nzRK3E2HCR6TxYT2fLabX/f8y04PqOjDr4iXFbUdpU9qcNJn/lquehe1DJND6RKNWA iYA7sOk3FOA3eJ6eUrfYxrMgaye1h03T8mGV0nviJye3OXZeF+3DIes7GGOWFTGjFGtj +1OmSsVSQ6nh8Pb0tPKoplY5RDokIq+Lkb29ZBBcYGFhee5PC9BkfRcpHt/3EeW7ZQBz 3Eo0KG/jeOM6vylkC6IoT7LmnXnnJPIGtUZAuxt1oQkOwtGxCnKMXV/nnmXkouZOfy2Z 7NkaayrHGwhebv3TJkYDbHbh/eoDSCWSfsDK+caIsuHJKYjtfm9mcUFgeEt9TpuzeQ2o icsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SFbj6RMhcRdwRLzrL2Z6akt9f8c9eckKrFP3rm4yKlo=; b=O8djadhYmXt/deV5DRe8CT9+bsK+VbXNTaGcJx9dCbjv7mnNQhTYd9GJeuPStN55df thUKkvo6V30rZSmOzpIcR7tny/ymX21Rh5yM8WawUD6hztjyo5+xOpKNr0JBi4Jyo438 trp6BSfggGnuxG3wqYMk7ZooJW4exq410usZEGZS4rpFpBkYf5QSzBHhOM3G2OcxTgHl y3wIvXGTqelYfbHzAY1ScP8egVaU2zZor3sk5jLRzpDKvNvzHsR3ZwFfa3Elb7MgNCMn 7QPzfMaLq4l4AsyyfH9TdjVUcFxAg8JWEB/F1GmHRp/3CrifZICjE3/0b48zHQp4nFos 8nrg== X-Gm-Message-State: AKS2vOwBiEAHsKXYdFHDm6gdGBsrhsyDNYo/skmqeaVvwoE8pD+jZT9z J91NdvxbKP2o/Q== X-Received: by 10.129.65.65 with SMTP id f1mr10626537ywk.100.1498720294432; Thu, 29 Jun 2017 00:11:34 -0700 (PDT) From: Pranith Kumar To: alex.bennee@linaro.org Date: Thu, 29 Jun 2017 03:11:29 -0400 Message-Id: <20170629071129.29362-3-bobby.prani@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629071129.29362-1-bobby.prani@gmail.com> References: <20170629071129.29362-1-bobby.prani@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c05::241 Subject: [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework 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: , Cc: Peter Maydell , pbonzini@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 In mttcg, calling pause_all_vcpus() during execution from the generated TBs causes a deadlock if some vCPU is waiting for exclusive execution in start_exclusive(). Fix this by using the aync_safe_* framework instead of pausing vcpus for patching instructions. CC: Paolo Bonzini CC: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Pranith Kumar --- hw/i386/kvmvapic.c | 73 +++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c index 82a49556af..5e0c8219b0 100644 --- a/hw/i386/kvmvapic.c +++ b/hw/i386/kvmvapic.c @@ -383,8 +383,7 @@ static void patch_byte(X86CPU *cpu, target_ulong addr, = uint8_t byte) cpu_memory_rw_debug(CPU(cpu), addr, &byte, 1, 1); } =20 -static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip, - uint32_t target) +static void patch_call(X86CPU *cpu, target_ulong ip, uint32_t target) { uint32_t offset; =20 @@ -393,23 +392,24 @@ static void patch_call(VAPICROMState *s, X86CPU *cpu,= target_ulong ip, cpu_memory_rw_debug(CPU(cpu), ip + 1, (void *)&offset, sizeof(offset),= 1); } =20 -static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong = ip) +struct PatchInfo { + VAPICHandlers *handler; + target_ulong ip; +}; + +static void do_patch_instruction(CPUState *cs, run_on_cpu_data data) { - CPUState *cs =3D CPU(cpu); - CPUX86State *env =3D &cpu->env; - VAPICHandlers *handlers; + X86CPU *x86_cpu =3D X86_CPU(cs); + CPUX86State *env =3D &x86_cpu->env; + struct PatchInfo *info =3D (struct PatchInfo *) data.host_ptr; + VAPICHandlers *handlers =3D info->handler; + target_ulong ip =3D info->ip; uint8_t opcode[2]; uint32_t imm32 =3D 0; target_ulong current_pc =3D 0; target_ulong current_cs_base =3D 0; uint32_t current_flags =3D 0; =20 - if (smp_cpus =3D=3D 1) { - handlers =3D &s->rom_state.up; - } else { - handlers =3D &s->rom_state.mp; - } - if (!kvm_enabled()) { cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base, ¤t_flags); @@ -421,48 +421,59 @@ static void patch_instruction(VAPICROMState *s, X86CP= U *cpu, target_ulong ip) } } =20 - pause_all_vcpus(); - cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0); =20 switch (opcode[0]) { case 0x89: /* mov r32 to r/m32 */ - patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */ - patch_call(s, cpu, ip + 1, handlers->set_tpr); + patch_byte(x86_cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg= */ + patch_call(x86_cpu, ip + 1, handlers->set_tpr); break; case 0x8b: /* mov r/m32 to r32 */ - patch_byte(cpu, ip, 0x90); - patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]= ); + patch_byte(x86_cpu, ip, 0x90); + patch_call(x86_cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])= ]); break; case 0xa1: /* mov abs to eax */ - patch_call(s, cpu, ip, handlers->get_tpr[0]); + patch_call(x86_cpu, ip, handlers->get_tpr[0]); break; case 0xa3: /* mov eax to abs */ - patch_call(s, cpu, ip, handlers->set_tpr_eax); + patch_call(x86_cpu, ip, handlers->set_tpr_eax); break; case 0xc7: /* mov imm32, r/m32 (c7/0) */ - patch_byte(cpu, ip, 0x68); /* push imm32 */ + patch_byte(x86_cpu, ip, 0x68); /* push imm32 */ cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0); cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1); - patch_call(s, cpu, ip + 5, handlers->set_tpr); + patch_call(x86_cpu, ip + 5, handlers->set_tpr); break; case 0xff: /* push r/m32 */ - patch_byte(cpu, ip, 0x50); /* push eax */ - patch_call(s, cpu, ip + 1, handlers->get_tpr_stack); + patch_byte(x86_cpu, ip, 0x50); /* push eax */ + patch_call(x86_cpu, ip + 1, handlers->get_tpr_stack); break; default: abort(); } =20 - resume_all_vcpus(); + g_free(info); +} =20 - if (!kvm_enabled()) { - /* Both tb_lock and iothread_mutex will be reset when - * longjmps back into the cpu_exec loop. */ - tb_lock(); - tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1); - cpu_loop_exit_noexc(cs); +static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong = ip) +{ + CPUState *cs =3D CPU(cpu); + VAPICHandlers *handlers; + struct PatchInfo *info; + const run_on_cpu_func fn =3D do_patch_instruction; + + if (smp_cpus =3D=3D 1) { + handlers =3D &s->rom_state.up; + } else { + handlers =3D &s->rom_state.mp; } + + info =3D g_new(struct PatchInfo, 1); + info->handler =3D handlers; + info->ip =3D ip; + + async_safe_run_on_cpu(cs, fn, RUN_ON_CPU_HOST_PTR(info)); + cpu_exit(cs); } =20 void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulong = ip, --=20 2.13.0