From patchwork Tue Jun 19 01:41:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10472887 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 96688601D7 for ; Tue, 19 Jun 2018 02:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C82928D78 for ; Tue, 19 Jun 2018 02:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B27428D96; Tue, 19 Jun 2018 02:21:31 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 1F6DF28DB6 for ; Tue, 19 Jun 2018 02:21:30 +0000 (UTC) Received: from localhost ([::1]:38580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6Gw-0003Gp-4x for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jun 2018 22:21:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5hj-0001H7-Qp for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5hi-0008C5-PN for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:07 -0400 Received: from mail-ot0-x22b.google.com ([2607:f8b0:4003:c0f::22b]:32863) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5hi-0008Bs-JH; Mon, 18 Jun 2018 21:45:06 -0400 Received: by mail-ot0-x22b.google.com with SMTP id h6-v6so20790079otj.0; Mon, 18 Jun 2018 18:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gRPaLti8UMgv2taMBny9kQjA3jXyjN9CTCd+BOLaWPY=; b=qltF/cNqnx7UHad11qwuxSxurdzdeMoMxWnB5J+/HDPF++6hD8Y7EyRx5Ud0U4ZoKU 53O9bwpS/VxZ+2Q6/YALsqUxsSoJZzaQQm/4y0mtqMltge9Yf0aF+kcVoSOPOHwBcztB dE/D6CTm7EBKTgQSiTKdi7kBD1K7KZx7cxCADYyijtVSG7enf5yb8pWQXwnWAMJD4Jb5 F2YpuizOibj9JWCjmX6yEP8SOwhpoG7USEMmE/LQpXjru1ky1OCVbZlCyNApJtHFIsxm Ecee5Wc/vrLvU1xwKdCzEExPbBUIcKv7k+j/WYy8d95n7ijkXvrEtxmuRHsjXAHM9mLF xAqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=gRPaLti8UMgv2taMBny9kQjA3jXyjN9CTCd+BOLaWPY=; b=ZD4snvdVSVaMbeiMN/hikj5Y7Rkp2waEq0O9JhUL8dS8fyVloL39pOORil5zz/5lME yMn8E2OJdoaQ8nWANUby0ptgYx1H1vfszo+3Ev8qKofdbloKYilSqINZenR/Djl9pc6t M3xe3NfhahyJYz51jc2Fai0IQYbvweEMJtd6zU4qaK3AjZtV7jFDc8i8e0unFKXeIwr9 TM5CWluL3cCy54sbtLjOY4hTRy0UaYiBMzvjNSyweERkR1BNFA9ILokVZL10GnPr3I+B RR9dNKq9ZRLnygYWzGh9xrBRIUptrslITbVMvSgbNeunZehVpZJPPRA0kcqjb7J3OHUx KTzw== X-Gm-Message-State: APt69E3k4atrv6EonJjKmr/C0qHJqqIo3GxNqfCVv1ghxk8PfBplieEO aPQ/dNNc/Ioa3iY+ccswWBdNFyRc X-Google-Smtp-Source: ADUXVKKzJuBOpsYRv3YkniMGX5Gh9AufCdGGZL3FT1mm9MmzW41WxOAs2dGKQA9Oc7B2AQcjeZD0dA== X-Received: by 2002:a9d:368a:: with SMTP id h10-v6mr8603590otc.19.1529372705427; Mon, 18 Jun 2018 18:45:05 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id x13-v6sm6635938oie.13.2018.06.18.18.45.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:45:04 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:41:55 -0500 Message-Id: <20180619014319.28272-30-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::22b Subject: [Qemu-devel] [PATCH 029/113] address_space_write: address_space_to_flatview needs RCU lock 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: Paolo Bonzini , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini address_space_write is calling address_space_to_flatview but it can be called outside the RCU lock. To fix it, push the rcu_read_lock/unlock pair up from flatview_write to address_space_write. Reviewed-by: Alexey Kardashevskiy Signed-off-by: Paolo Bonzini (cherry picked from commit 4c6ebbb364aa6f42c5d8e83e932e967eb83f0e44) Signed-off-by: Michael Roth --- exec.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 03238a3449..884e243a84 100644 --- a/exec.c +++ b/exec.c @@ -3005,6 +3005,7 @@ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, return result; } +/* Called from RCU critical section. */ static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, const uint8_t *buf, int len) { @@ -3013,25 +3014,14 @@ static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, MemoryRegion *mr; MemTxResult result = MEMTX_OK; - if (len > 0) { - rcu_read_lock(); - l = len; - mr = flatview_translate(fv, addr, &addr1, &l, true); - result = flatview_write_continue(fv, addr, attrs, buf, len, - addr1, l, mr); - rcu_read_unlock(); - } + l = len; + mr = flatview_translate(fv, addr, &addr1, &l, true); + result = flatview_write_continue(fv, addr, attrs, buf, len, + addr1, l, mr); return result; } -MemTxResult address_space_write(AddressSpace *as, hwaddr addr, - MemTxAttrs attrs, - const uint8_t *buf, int len) -{ - return flatview_write(address_space_to_flatview(as), addr, attrs, buf, len); -} - /* Called within RCU critical section. */ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, uint8_t *buf, @@ -3140,6 +3130,23 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, addr, attrs, buf, len, is_write); } +MemTxResult address_space_write(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const uint8_t *buf, int len) +{ + MemTxResult result = MEMTX_OK; + FlatView *fv; + + if (len > 0) { + rcu_read_lock(); + fv = address_space_to_flatview(as); + result = flatview_write(fv, addr, attrs, buf, len); + rcu_read_unlock(); + } + + return result; +} + void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, int len, int is_write) {