From patchwork Fri Mar 9 04:12:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10269641 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 2E9AD60236 for ; Fri, 9 Mar 2018 04:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 192DB29403 for ; Fri, 9 Mar 2018 04:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AEEA29C18; Fri, 9 Mar 2018 04:22:05 +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 7AA0429403 for ; Fri, 9 Mar 2018 04:22:04 +0000 (UTC) Received: from localhost ([::1]:43125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu9Xf-0000Sb-Bu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Mar 2018 23:22:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu9QX-0004AP-9b for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eu9QW-0006xq-Gf for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:41 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:46603) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eu9QW-0006xZ-9g for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:40 -0500 Received: by mail-pg0-x241.google.com with SMTP id r26so3113105pgv.13 for ; Thu, 08 Mar 2018 20:14:40 -0800 (PST) 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=aeKs7SuxlwsYHH8r29GkHugNz0c5+GrzvILr3D7owPA=; b=L0uXKDkyM9IBLX7/LJ6FgKRo60TwhYfdXjAQgOjXJarAbXvDch32MDQSBzsX5i8SpF uJpBEEII1+oKGlumtf7ZdvwNiOgBp3MWpGZ/aW1tSY0j9BSRnpIgZorg6T+jTQ/sdLwi yyYmuKZvsPaEL3EkTSY+Yqr/f9yi1/LL42s4xXRcMqOnZBfkod9WeTuQG8JOrdodkUAC +CkB8oyZQ0RxaZBGzWj6Mo1bk/0lpPc33y/Pxail35yebke4JQO12nSIK7YGyPjrEOYU gDhjHfriHWgr8lAAdAY4m7wSwImtyTyq8bwoHXNz6iiSpbqgXQnHZclhzed+7hbq9yiN 3pAw== 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=aeKs7SuxlwsYHH8r29GkHugNz0c5+GrzvILr3D7owPA=; b=GdwIWA3hg1f68LacrNtbb1wJS0+MtUFSIwMJ0vsqJ78tbQxrnGjcgcuKRnT6eIn+Wm elBFNL0hYZkrysphHUJTO1DUk7ttmZc6EQ0Ir+LLk2ZTdc9gLzIM/cKjcqFzC2syw6Zb JQJhT8K7wOTY0Q0P1VQ6/JKgiZH/7fsAlGtOM/Waax9+o2dUIsM+/V2Qo7TY3jkDhZ03 H2dvHFH9X3f89/m5KUTH9Lcv+GjT8dS4oKEV8N5AXJv1RdaiPDnTVqAp1Lkhs3Zn1xO+ jMz+XoOkOCvsYalyDNzP64Ylz8IbYztvxC/ZH99B02ijiaTzdZJ8gpX5XXtawwEUkRWf F1eg== X-Gm-Message-State: APf1xPAEjDhykBpKWjDnCa5Ii6zBvfAikJs3ssjlY3K6mnEpawN28mMV mRT2kYfk2scNWWCB9+A+GJbFsvourR8= X-Google-Smtp-Source: AG47ELs95cepB59D8VVgpzX7nLp0oRIAesVxcrPbE1rBUebz8fUrd9PTNv5WIcqSzF8PgFFnxWLjyA== X-Received: by 10.99.146.26 with SMTP id o26mr23206641pgd.309.1520568879378; Thu, 08 Mar 2018 20:14:39 -0800 (PST) Received: from localhost.localdomain (125-237-39-90-fibre.bb.spark.co.nz. [125.237.39.90]) by smtp.gmail.com with ESMTPSA id h15sm334141pfi.56.2018.03.08.20.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Mar 2018 20:14:38 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Fri, 9 Mar 2018 17:12:32 +1300 Message-Id: <1520568765-58189-11-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1520568765-58189-1-git-send-email-mjc@sifive.com> References: <1520568765-58189-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:c05::241 Subject: [Qemu-devel] [PATCH v2 10/23] 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: Stefan O'Rear , Bastian Koppelmann , Michael Clark , Palmer Dabbelt , Sagar Karandikar 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 CC: Stefan O'Rear Signed-off-by: Michael Clark Signed-off-by: Palmer Dabbelt --- target/riscv/helper.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/helper.c b/target/riscv/helper.c index 02cbcea..228933c 100644 --- a/target/riscv/helper.c +++ b/target/riscv/helper.c @@ -209,6 +209,7 @@ restart: as the PTE is no longer valid */ MemoryRegion *mr; hwaddr l = sizeof(target_ulong), addr1; + rcu_read_lock(); mr = address_space_translate(cs->as, pte_addr, &addr1, &l, false); if (memory_access_is_direct(mr, true)) { @@ -222,16 +223,19 @@ restart: target_ulong old_pte = atomic_cmpxchg(pte_pa, pte, updated_pte); if (old_pte != pte) { + rcu_read_unlock(); goto restart; } else { pte = updated_pte; } #endif } else { + rcu_read_unlock(); /* misconfigured PTE in ROM (AD bits are not preset) or * PTE is in IO space and can't be updated atomically */ return TRANSLATE_FAIL; } + rcu_read_unlock(); } /* for superpage mappings, make a fake leaf PTE for the TLB's