From patchwork Mon Mar 19 21:18:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10295191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A0C8602C2 for ; Mon, 19 Mar 2018 21:25:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58F4129432 for ; Mon, 19 Mar 2018 21:25:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D48D2943B; Mon, 19 Mar 2018 21:25:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2D5129432 for ; Mon, 19 Mar 2018 21:25:14 +0000 (UTC) Received: from localhost ([::1]:44001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ey2HK-0006AQ-2L for patchwork-qemu-devel@patchwork.kernel.org; Mon, 19 Mar 2018 17:25:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ey2C8-0001Lz-3C for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ey2C6-0002dc-L6 for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:52 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:42543) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ey2C6-0002dB-Et for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:50 -0400 Received: by mail-pl0-x241.google.com with SMTP id w15-v6so11035395plq.9 for ; Mon, 19 Mar 2018 14:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fTBPkPu2AjNF7regRB2KRgIX+vb8i7GfOe4orSk8euo=; b=P/6jOvGeidUt3zkTdbvIUpZHP3zSYH0vwJd++wBbboGfxjYJ1ad3YWAFI4xp1afSEr zp9oBVSLgU5ATzUWSdzm5aPRlDrLhb/MzC0TXd3Uz9DJFmrnX9qRnKKOIrpx6h4ZjtYV FSsSIW4Ee7SDiBbL2MsW5rP0RGj3pYw5hfiDfazM1tq45Sd7M2EAsniBAssFunANeDqy m3qt0S8okSraLEXeZ0sHcgsgh3NK+HfCi5x5jeVOx4oHKNyXtpK7gvduQtGdawD8Z18g yF9WSTEvGfay33y4W2zV87Tq6AoYZm93nhjat7IX/VCZntwVpQBJwO1Lc31GF1JBpIAk vMzA== 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; bh=fTBPkPu2AjNF7regRB2KRgIX+vb8i7GfOe4orSk8euo=; b=Nct90cBuOZ2q8MS5FQA5pg/7ayCe8ml+2QjJWaxRaVAEHwi4cRgeP+sfTHkeVuXPgZ atNaQqmVO7qIJyNSJ8d006qw/v3L95RafHzwaOpzah9e28NVc3PSAs5LP6gfzCCEkzG2 oywu/G3AWalVXuZlZMV5RYH5TmS0h5zsTY0w4KTUNm8rw+1SyEXVj+0gh2Eh2ry2o+oy NbV4Hus7KqvGmwCJU/js+imEFLsd9fBEMcLot3qTanQimfNptShUwOjS7CMmOSo2FT7G DZDT7D6CzDJynrZBlBXlVqWEUW46UMTXSGU6Rz44HVKUbrmufgsgS405qZOijlA4g8tt Bjow== X-Gm-Message-State: AElRT7EseQNRlyFcUJ5HOptWvJsuUCcog1Al598PY2IFVNZqASRRk0q6 h1zcDh1q4TuUvafo1arTMTHh6CsPvYA= X-Google-Smtp-Source: AG47ELuTGkGCkRq0pLPV2bNI5SDxDNkESQAaCjTdx63mWPq7dfVImG+G4LCHCCz4zWXlVum0P2XL/Q== X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr3625223plo.169.1521494389594; Mon, 19 Mar 2018 14:19:49 -0700 (PDT) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id i127sm120500pfc.136.2018.03.19.14.19.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Mar 2018 14:19:49 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2018 14:18:33 -0700 Message-Id: <1521494329-19546-11-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1521494329-19546-1-git-send-email-mjc@sifive.com> References: <1521494329-19546-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::241 Subject: [Qemu-devel] [PATCH v4 10/26] RISC-V: Hold rcu_read_lock when accessing memory 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: patches@groups.riscv.org, Michael Clark , Palmer Dabbelt , Sagar Karandikar , Bastian Koppelmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From reading other code that accesses memory regions directly, it appears that the rcu_read_lock needs to be held. Note: the original code for accessing RAM directly was added because there is no other way to use atomic_cmpxchg on guest physical address space. Cc: Sagar Karandikar Cc: Bastian Koppelmann Signed-off-by: Michael Clark Signed-off-by: Palmer Dabbelt --- target/riscv/helper.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/target/riscv/helper.c b/target/riscv/helper.c index 02cbcea..d148bed 100644 --- a/target/riscv/helper.c +++ b/target/riscv/helper.c @@ -209,6 +209,9 @@ restart: as the PTE is no longer valid */ MemoryRegion *mr; hwaddr l = sizeof(target_ulong), addr1; + enum { success, translate_fail, restart_walk} action = success; + + rcu_read_lock(); mr = address_space_translate(cs->as, pte_addr, &addr1, &l, false); if (memory_access_is_direct(mr, true)) { @@ -222,7 +225,7 @@ restart: target_ulong old_pte = atomic_cmpxchg(pte_pa, pte, updated_pte); if (old_pte != pte) { - goto restart; + action = restart_walk; } else { pte = updated_pte; } @@ -230,7 +233,17 @@ restart: } else { /* misconfigured PTE in ROM (AD bits are not preset) or * PTE is in IO space and can't be updated atomically */ + action = translate_fail; + } + rcu_read_unlock(); + + switch (action) { + case success: + break; + case translate_fail: return TRANSLATE_FAIL; + case restart_walk: + goto restart; } }