From patchwork Sun Mar 22 19:22:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 184731 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3275500ile; Sun, 22 Mar 2020 12:23:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vspn9YqbjZGa56uH2HQDLLfKVFzqvGQv7LB8SEX2MQXyTgdHSlxznL4g0E8lbLXEnREMyFY X-Received: by 2002:aed:2535:: with SMTP id v50mr18419719qtc.354.1584904995444; Sun, 22 Mar 2020 12:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584904995; cv=none; d=google.com; s=arc-20160816; b=ulIOp44a+vpQFISyvWEybwtPOFIR3NkFoaNP0e5gG63n0m0RrcKreyBn5MsP8oPtGp mX7rCe8rVUMBifk3m00T/7gFAgPX9AY/2buCvAivXq68JsmOWgprrD2tjZJqwi8Ref2o jw1IGEiB2JvYSr/KJ7vp40YTijnxMUYrTZ8Oo/yJFxdk1ftplXsHt0PZTGKW9tPFn/mq DwMkoagnHCkKIn7Tj6JcpNIPmPTI6Qlpp5LwrToIvMe8CORq0ZbY/tLj1oQHkMJ9WHJZ 1tXMMkYj4pvse2YQ3f9D3u50LLEwn91OD6JLJXPhrVj8YiizDghlbVjVIkv6c+o0mox4 XEwA== 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:message-id:date:subject:to:from:dkim-signature; bh=Ev/rARBqmxuXFlqAqZsGEHnb8NKhJeii6ub3R0/lfxI=; b=l7PrEg/FAGIJ9uDvtJM2Z4SNhzFIC+gW0kpExs3rEot2P7yyt0GNGv0B3jdLt/1GJv eXK3i1yhkgGewOnIeNG0iQBJH18/aJ0qy60MKxWussYuaWI93EueF+EmyrzlkWN+ZYAX Z7gr9OVepS6YEuDnauUBo0DYKurpVTnDpQfS/gB1r/MPxddQP97dslc4PgLOb2fisCuS s9IE9OqLNGGrQlzTiNqU+veTrgp2rPU27oWPa4ylgdTcvLqywuin6xXDYpy5b/UB81Va 9C90khlHLxBXyX6ARaR2X1pKfkJZSiartRS9/4aIbx3UCo4II1EGzQBdI5QAa1Lke64k AhHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="h/dWmYjv"; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 36si7258719qtc.334.2020.03.22.12.23.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Mar 2020 12:23:15 -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=fail header.i=@linaro.org header.s=google header.b="h/dWmYjv"; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG6Bn-0005Rb-08 for patch@linaro.org; Sun, 22 Mar 2020 15:23:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33637) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG6Bc-0005RN-GN for qemu-devel@nongnu.org; Sun, 22 Mar 2020 15:23:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jG6Ba-00080u-Vb for qemu-devel@nongnu.org; Sun, 22 Mar 2020 15:23:04 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jG6Ba-0007zu-NB for qemu-devel@nongnu.org; Sun, 22 Mar 2020 15:23:02 -0400 Received: by mail-wm1-x344.google.com with SMTP id l20so12288771wmi.3 for ; Sun, 22 Mar 2020 12:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ev/rARBqmxuXFlqAqZsGEHnb8NKhJeii6ub3R0/lfxI=; b=h/dWmYjvSLHhRegqt5P69A6otdshUfg5oJHRLswClGJmwC3LEf1IEuXyunIE7TmII7 rWstGizYTrMUGvkHV+w28a0n8LigZBs7HAb163DlpHTxIcngYm3ZVkk5f58xt4zruwge u72iAd6DsWPd1HgLVRYIp2JUC7BYh7veqzZ8Ht/T82K5zCQ7NDJaSts42UkiD5ofc7l7 jg8OC0vSM0BxFVUSvtVgjx/YIa0plmgcTRdCMl9fe0JG8XTf9hZZGF1kvsmd7ZVAFIyH QKbqD5k3HVARGXcujU35AnQZY881VDfRWdLMEvDj/aebGJbuwrsP8u1OxEh26WAIo+VC H2UA== 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:mime-version :content-transfer-encoding; bh=Ev/rARBqmxuXFlqAqZsGEHnb8NKhJeii6ub3R0/lfxI=; b=e7oMr9HLweS23g8Du6t+QA2QJOx9NNIe7xiOU8Gfig1fq2WWIg2W/c7iHoIVt3s6ar c3nVTdpLE3LmxkMd/E6PJn0fcpjiq+2VCxQtssbdrsmtYRFtwa1kpP+MCn+gVySS+DCW tscgTtVF8lSOmKatBPF4h9+GWmw5FZcLcrculAqBcqLLNnw1s6S8taj+UFthTsM5AKuG tNMwf6eF1QDr64cn75LFsuYU14vuOsiJLcgtiGkIekaaPBGfEWBWwSDgJkckZ4B/Vmv4 O4+AhIUBVaPxS1jeQIXdbbkMGl9kDpM8h0HUnzvK2Gx3KWoa+033xN7p+oudF/PSIaDS 7lWg== X-Gm-Message-State: ANhLgQ05/PaVU6Oq1YIHii53TnmasgW9Bm2NP6OpI9RTrijZ0WTO3umj rCa7Cgx/VxYhJZGosjWH+g5Nu53KM7QcYA== X-Received: by 2002:a1c:4645:: with SMTP id t66mr23561871wma.6.1584904981078; Sun, 22 Mar 2020 12:23:01 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id q8sm12086755wmj.22.2020.03.22.12.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 12:23:00 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.0] hw/ppc: Take QEMU lock when calling ppc_dcr_read/write() Date: Sun, 22 Mar 2020 19:22:58 +0000 Message-Id: <20200322192258.14039-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 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: Amit Lazar , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- Amit reported this bug via IRC. target/ppc/timebase_helper.c | 40 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) -- 2.20.1 diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c index 703bd9ed18b..d16360ab667 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()); + } } }