From nobody Mon Feb 9 23:01:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529374866396199.0825252599451; Mon, 18 Jun 2018 19:21:06 -0700 (PDT) Received: from localhost ([::1]:38580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6GX-0003Gp-KK for importer@patchew.org; Mon, 18 Jun 2018 22:21:05 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; } =20 +/* Called from RCU critical section. */ static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs at= trs, const uint8_t *buf, int len) { @@ -3013,25 +3014,14 @@ static MemTxResult flatview_write(FlatView *fv, hwa= ddr addr, MemTxAttrs attrs, MemoryRegion *mr; MemTxResult result =3D MEMTX_OK; =20 - if (len > 0) { - rcu_read_lock(); - l =3D len; - mr =3D flatview_translate(fv, addr, &addr1, &l, true); - result =3D flatview_write_continue(fv, addr, attrs, buf, len, - addr1, l, mr); - rcu_read_unlock(); - } + l =3D len; + mr =3D flatview_translate(fv, addr, &addr1, &l, true); + result =3D flatview_write_continue(fv, addr, attrs, buf, len, + addr1, l, mr); =20 return result; } =20 -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, hwadd= r addr, addr, attrs, buf, len, is_write); } =20 +MemTxResult address_space_write(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const uint8_t *buf, int len) +{ + MemTxResult result =3D MEMTX_OK; + FlatView *fv; + + if (len > 0) { + rcu_read_lock(); + fv =3D address_space_to_flatview(as); + result =3D 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) { --=20 2.11.0