From patchwork Tue Mar 24 05:14:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 184760 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4936023ile; Mon, 23 Mar 2020 22:17:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtEdlhLuozDNOpjPO+31BzNpNv/RYBVB7A6cf9XuQy0je7kYD2sSjiZNGvE4SyBP+LNnd55 X-Received: by 2002:a37:7d81:: with SMTP id y123mr24634308qkc.102.1585027034636; Mon, 23 Mar 2020 22:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585027034; cv=none; d=google.com; s=arc-20160816; b=VXOCruy3BJxmyxAmr/Iq1CJfkv5gjc3u072YZXbQhea/ChRfY535UdJVSYP19x2x66 MSa5gSYTsODFn8tHOSpj0XZ0VQ4YXUefV60hmhUyoagPvbwJgDAY97l++ojGNRxrGj+H E46gZIQnaX55riMpSbPZZpob2hh1rZFcAisbY+OuE5pR/iDDm7q/+y/9LE8wy6AOyur5 1o6i1a4/w94C/vTAFcGO3lYsbb0jHJBX7OUav5a39E2jtTuZEoEB4a6nNvRw4HKjmQAZ CuIZHLU+11eOjUePb9+FwnylYGpKopyeA5GMfjPsxWGCA4BRXoR1iyMgvITfvvFf7W8d Sidg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kBOpKqOv7hTyxercuqdNPvKboSIc0bZKlQahJKPOUgs=; b=pHZ2d4jGYKzGQW85pKXVIOWohMRv57jZhXsrjlDWF8yqMq9EhmDVbeOMuBcKOXY2vn 6ugpFnjO6WnrmXXWHVxXqaS8k/6o0v0drmBdCj7Ck0EXpOegy2FdmVOyJ5p6h4lvgSvi Zf/kxdJ1tW9WhBt0I5+uz96WVHjm4OSRNaBOfTyqkVWue5m9eZ47L8sbMoLhsX5nJitX p/XrKfwoc6wp06sqco/xTfJxU7Vzg5Tb4gvP8JgzQ1BZSP2J4wQT22MCLjpO+yp/Imaf UOE4voPlnqNnsJ9Jnuyl/SRue+W9tQL2FJK5JzzfYMLDXsNxDfgeRU2Ghu2v1nnk1LOT E8/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gibson.dropbear.id.au header.s=201602 header.b=jHmTxP5C; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m130si9653352qke.23.2020.03.23.22.17.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 22:17:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gibson.dropbear.id.au header.s=201602 header.b=jHmTxP5C; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:42920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGbwA-0007Sl-3K for patch@linaro.org; Tue, 24 Mar 2020 01:17:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36952) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGbu8-0004bB-RN for qemu-devel@nongnu.org; Tue, 24 Mar 2020 01:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGbu7-0001ew-L5 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 01:15:08 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:45371) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGbu7-0001bf-AH; Tue, 24 Mar 2020 01:15:07 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 48mfZW65T8z9sSN; Tue, 24 Mar 2020 16:14:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1585026899; bh=Xc+3RKabXHno7VL+AST1GTZnAiqqXI+OYqmv72T8XXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHmTxP5C42dI8ZUfqy0+b2sXaQP7NAORnL4ORJj3ShGeocPlCOfhFB97hWqh+BW45 W7MIG+f0SF3yy5bDq/x7QNU7+QWzlie6wFs5A0aApPjo09GjlaVjpK3iQHUwZhkEWp KXVpOhJ6+c5dDvC0emb+zjrjS+TX19JiWRmEAFVc= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 6/7] hw/ppc: Take QEMU lock when calling ppc_dcr_read/write() Date: Tue, 24 Mar 2020 16:14:55 +1100 Message-Id: <20200324051456.256116-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324051456.256116-1-david@gibson.dropbear.id.au> References: <20200324051456.256116-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, Amit Lazar , qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The ppc_dcr_read() and ppc_dcr_write() functions call into callbacks in device code, so we need to hold the QEMU iothread lock while calling them. This is the case already for the callsites in kvmppc_handle_dcr_read/write(), but we must also take the lock when calling the helpers from TCG. This fixes a bug where attempting to initialise the PPC405EP SDRAM will cause an assertion when sdram_map_bcr() attempts to remap memory regions. Reported-by: Amit Lazar Signed-off-by: Peter Maydell Message-Id: <20200322192258.14039-1-peter.maydell@linaro.org> Signed-off-by: David Gibson --- target/ppc/timebase_helper.c | 40 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c index 703bd9ed18..d16360ab66 100644 --- a/target/ppc/timebase_helper.c +++ b/target/ppc/timebase_helper.c @@ -21,6 +21,7 @@ #include "exec/helper-proto.h" #include "exec/exec-all.h" #include "qemu/log.h" +#include "qemu/main-loop.h" /*****************************************************************************/ /* SPR accesses */ @@ -167,13 +168,19 @@ target_ulong helper_load_dcr(CPUPPCState *env, target_ulong dcrn) raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL, GETPC()); - } else if (unlikely(ppc_dcr_read(env->dcr_env, - (uint32_t)dcrn, &val) != 0)) { - qemu_log_mask(LOG_GUEST_ERROR, "DCR read error %d %03x\n", - (uint32_t)dcrn, (uint32_t)dcrn); - raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, - POWERPC_EXCP_INVAL | - POWERPC_EXCP_PRIV_REG, GETPC()); + } else { + int ret; + + qemu_mutex_lock_iothread(); + ret = ppc_dcr_read(env->dcr_env, (uint32_t)dcrn, &val); + qemu_mutex_unlock_iothread(); + if (unlikely(ret != 0)) { + qemu_log_mask(LOG_GUEST_ERROR, "DCR read error %d %03x\n", + (uint32_t)dcrn, (uint32_t)dcrn); + raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, + POWERPC_EXCP_INVAL | + POWERPC_EXCP_PRIV_REG, GETPC()); + } } return val; } @@ -185,12 +192,17 @@ void helper_store_dcr(CPUPPCState *env, target_ulong dcrn, target_ulong val) raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL, GETPC()); - } else if (unlikely(ppc_dcr_write(env->dcr_env, (uint32_t)dcrn, - (uint32_t)val) != 0)) { - qemu_log_mask(LOG_GUEST_ERROR, "DCR write error %d %03x\n", - (uint32_t)dcrn, (uint32_t)dcrn); - raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, - POWERPC_EXCP_INVAL | - POWERPC_EXCP_PRIV_REG, GETPC()); + } else { + int ret; + qemu_mutex_lock_iothread(); + ret = ppc_dcr_write(env->dcr_env, (uint32_t)dcrn, (uint32_t)val); + qemu_mutex_unlock_iothread(); + if (unlikely(ret != 0)) { + qemu_log_mask(LOG_GUEST_ERROR, "DCR write error %d %03x\n", + (uint32_t)dcrn, (uint32_t)dcrn); + raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, + POWERPC_EXCP_INVAL | + POWERPC_EXCP_PRIV_REG, GETPC()); + } } }