From patchwork Thu Jan 24 07:42:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1030295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RxtSWaHB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43lYzl0kt2z9s3l for ; Thu, 24 Jan 2019 18:43:13 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmZfL-0005bH-5p for incoming@patchwork.ozlabs.org; Thu, 24 Jan 2019 02:43:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmZel-0005Zn-Hn for qemu-devel@nongnu.org; Thu, 24 Jan 2019 02:42:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gmZei-0004rr-AF for qemu-devel@nongnu.org; Thu, 24 Jan 2019 02:42:34 -0500 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:39564) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gmZeY-0004ZE-Kp for qemu-devel@nongnu.org; Thu, 24 Jan 2019 02:42:26 -0500 Received: by mail-lj1-x243.google.com with SMTP id t9-v6so4330022ljh.6 for ; Wed, 23 Jan 2019 23:42:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/u9O0lV+MlDPmdFHEmuf8Nuwam1y4TZZB88COoYfoDI=; b=RxtSWaHBcfK+ZBZkl9SSP1K6Bx0PnVR4ohrPbE2GvJyLtzBITlZuaQa5YWdo5EsVHE lBiLSbKs/72U66qAFW/sqOgZb5QWxRoxDcN01jkfSkHSb/eAajfXj6yCvSf/JVMaBqBy iLVAV0TtZeQ0NaJDUCdPUk7REDDIU1CKCDo47tIr7swEclE8jiaTzivsTPzmxcKUOa8S uneLrGkNfmyPKPKmF9HQI9mQ67l91gqfYwmwMm9TCOmyQknVrs2sPuVw8fPvM7WPj+0I zIkfOeO8fmRdWiEbQK0qnme7PikX3UNrxBASMe54yJmHoiPCZ66Sv8pt4ZXxozIiWNDb aRfw== 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; bh=/u9O0lV+MlDPmdFHEmuf8Nuwam1y4TZZB88COoYfoDI=; b=LCJwsAKAy0l5NDeNNR75WdYGu27rsrsHYovdn2aFTej+/Dh7pCS7uH5wKEOUqsk0UX O9ZL03z672waSwam5ttFRiDFwwZVlHSF7Rhh1XN4Ioaa4VkR1CgZ4lRzFrs2H92Y/+5x luuBX7hO9yxV7dYrZtrZkDNDwUMwb+rYRIkquDGCoPHu2Lk3GiSx079mAkAydSwVFyH9 uFXV7lKb8Y2sTeyekMhk7q9jYNPsqKOYNm4B3E9HiGl5OlRolF8JS7F57OjY6jk0Ez0Y 6oOOFp0Kb0HVEmyNZGpySCSX8ET2ApKl93hGY37Qyc7Fnrmj6o9OLZd0qAZFWiFCPmJN 6imw== X-Gm-Message-State: AJcUukfVr3TpwI+X3LZwCiL/PUNc1pxJNT0pjeeCrPjD0ZSYF+Ck8Q1l 2Xd1nV3zjK8d/Kkb6g7H0TmXiPeDviI= X-Google-Smtp-Source: ALg8bN7b9EineTsiFdVEvWj2T+FYhds/FJk3AayEp5h/ylBnQ0bHFJtamJU3uq50vUpSkTDPswe9eA== X-Received: by 2002:a2e:90ca:: with SMTP id o10-v6mr4477010ljg.134.1548315738863; Wed, 23 Jan 2019 23:42:18 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net. (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id u21-v6sm888432lju.46.2019.01.23.23.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 23:42:18 -0800 (PST) From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 23 Jan 2019 23:42:05 -0800 Message-Id: <20190124074205.31777-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH v2] target/xtensa: fix access to the INTERRUPT SR 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: Max Filippov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" INTERRUPT special register may be changed both by the core (by writing to INTSET and INTCLEAR registers) and by external events (by triggering and clearing HW IRQs). In MTTCG this state must be protected from concurrent access, otherwise interrupts may be lost or spurious interrupts may be detected. Use atomic operations to change INTSET SR. Fix wsr.intset so that it soesn't clear any bits. Fix wsr.intclear so that it doesn't clear bit that corresponds to NMI. Signed-off-by: Max Filippov --- Changes v1->v2: - use atomic operations to change INTSET SR. Don't use BQL in the CPU-side helpers as there's nothing else to synchronize.. hw/xtensa/pic_cpu.c | 4 ++-- target/xtensa/exc_helper.c | 13 +++++++++++++ target/xtensa/helper.h | 2 ++ target/xtensa/op_helper.c | 2 ++ target/xtensa/translate.c | 14 ++------------ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/hw/xtensa/pic_cpu.c b/hw/xtensa/pic_cpu.c index 0e812d7f061c..7e4c65e5ec30 100644 --- a/hw/xtensa/pic_cpu.c +++ b/hw/xtensa/pic_cpu.c @@ -68,9 +68,9 @@ static void xtensa_set_irq(void *opaque, int irq, int active) uint32_t irq_bit = 1 << irq; if (active) { - env->sregs[INTSET] |= irq_bit; + atomic_or(&env->sregs[INTSET], irq_bit); } else if (env->config->interrupt[irq].inttype == INTTYPE_LEVEL) { - env->sregs[INTSET] &= ~irq_bit; + atomic_and(&env->sregs[INTSET], ~irq_bit); } check_interrupts(env); diff --git a/target/xtensa/exc_helper.c b/target/xtensa/exc_helper.c index 371a32ba5ad9..4a1f7aef5dcf 100644 --- a/target/xtensa/exc_helper.c +++ b/target/xtensa/exc_helper.c @@ -127,6 +127,19 @@ void HELPER(check_interrupts)(CPUXtensaState *env) qemu_mutex_unlock_iothread(); } +void HELPER(intset)(CPUXtensaState *env, uint32_t v) +{ + atomic_or(&env->sregs[INTSET], + v & env->config->inttype_mask[INTTYPE_SOFTWARE]); +} + +void HELPER(intclear)(CPUXtensaState *env, uint32_t v) +{ + atomic_and(&env->sregs[INTSET], + ~(v & (env->config->inttype_mask[INTTYPE_SOFTWARE] | + env->config->inttype_mask[INTTYPE_EDGE]))); +} + static uint32_t relocated_vector(CPUXtensaState *env, uint32_t vector) { if (xtensa_option_enabled(env->config, diff --git a/target/xtensa/helper.h b/target/xtensa/helper.h index 89eb97e26514..2a7db35874fe 100644 --- a/target/xtensa/helper.h +++ b/target/xtensa/helper.h @@ -22,6 +22,8 @@ DEF_HELPER_1(update_ccount, void, env) DEF_HELPER_2(wsr_ccount, void, env, i32) DEF_HELPER_2(update_ccompare, void, env, i32) DEF_HELPER_1(check_interrupts, void, env) +DEF_HELPER_2(intset, void, env, i32) +DEF_HELPER_2(intclear, void, env, i32) DEF_HELPER_3(check_atomctl, void, env, i32, i32) DEF_HELPER_2(wsr_memctl, void, env, i32) diff --git a/target/xtensa/op_helper.c b/target/xtensa/op_helper.c index 1865f46c4b5f..04971b044fac 100644 --- a/target/xtensa/op_helper.c +++ b/target/xtensa/op_helper.c @@ -62,6 +62,8 @@ void HELPER(update_ccompare)(CPUXtensaState *env, uint32_t i) { uint64_t dcc; + atomic_and(&env->sregs[INTSET], + ~(1u << env->config->timerint[i])); HELPER(update_ccount)(env); dcc = (uint64_t)(env->sregs[CCOMPARE + i] - env->sregs[CCOUNT] - 1) + 1; timer_mod(env->ccompare[i].timer, diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index a435d9c36cf1..d1e9f59b31bd 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -646,20 +646,12 @@ static void gen_check_interrupts(DisasContext *dc) static void gen_wsr_intset(DisasContext *dc, uint32_t sr, TCGv_i32 v) { - tcg_gen_andi_i32(cpu_SR[sr], v, - dc->config->inttype_mask[INTTYPE_SOFTWARE]); + gen_helper_intset(cpu_env, v); } static void gen_wsr_intclear(DisasContext *dc, uint32_t sr, TCGv_i32 v) { - TCGv_i32 tmp = tcg_temp_new_i32(); - - tcg_gen_andi_i32(tmp, v, - dc->config->inttype_mask[INTTYPE_EDGE] | - dc->config->inttype_mask[INTTYPE_NMI] | - dc->config->inttype_mask[INTTYPE_SOFTWARE]); - tcg_gen_andc_i32(cpu_SR[INTSET], cpu_SR[INTSET], tmp); - tcg_temp_free(tmp); + gen_helper_intclear(cpu_env, v); } static void gen_wsr_intenable(DisasContext *dc, uint32_t sr, TCGv_i32 v) @@ -706,12 +698,10 @@ static void gen_wsr_icountlevel(DisasContext *dc, uint32_t sr, TCGv_i32 v) static void gen_wsr_ccompare(DisasContext *dc, uint32_t sr, TCGv_i32 v) { uint32_t id = sr - CCOMPARE; - uint32_t int_bit = 1 << dc->config->timerint[id]; TCGv_i32 tmp = tcg_const_i32(id); assert(id < dc->config->nccompare); tcg_gen_mov_i32(cpu_SR[sr], v); - tcg_gen_andi_i32(cpu_SR[INTSET], cpu_SR[INTSET], ~int_bit); if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) { gen_io_start(); }