From patchwork Tue May 7 12:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795205 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp269332wrc; Tue, 7 May 2024 05:31:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZC3GwkbWgXhwsPFmsO9FXruxqCkKpM+ki5arO52f2wPyjUZA77zFaeMzaX5Kl8K2MOP7HdijEpRDfHHHsMHuX X-Google-Smtp-Source: AGHT+IGBIaeRf8lnQZAxAtNypZamK8DvsfFOVmQi7QNVgpQU0geeGlPTLX+Ig2kU+rwyb4kKEvUb X-Received: by 2002:ad4:5aea:0:b0:69b:5ecd:7c9a with SMTP id c10-20020ad45aea000000b0069b5ecd7c9amr15226944qvh.51.1715085107437; Tue, 07 May 2024 05:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715085107; cv=none; d=google.com; s=arc-20160816; b=DgPvAr18xEJTNAQkWBkMFq4JaHcXpnmoS9mWOVCGUCD3wDw4bL3dxVTJF4/D7VNlJF magkicfLR6ZRCICN25qBa0MxNkOqgae+FmVkz7dhY6Z8j7dwqU8j+yJ4WYXkkjF19ftN 3nRXLLdZTvzy9SVmyt0eWC08wtSk04xXrydQA3DQR9PAp4yzVCg3CinPqoTbj0rL7gXv FNlzqRWX7PIi/G+Y+Ml5jPA/cC1NQ25NY6j3P+JHx8CS8/gg/Tk6lrct6b+fKOx3ZitO h+YimbHgRumSZ24zS9jQ3bBsUSs7xAFBrkJQ4IilAHdqqH748/x6vD2RM/HZksq4Zpoy m8DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sliD5j3ZsW+Ih/VrgBbXH2a/MnjoDv1oe45cMQ/IOgo=; fh=o+0Cxzn0vqd9qaat0OKQ9MH4Aye4czSmxiTGhWeCDvg=; b=sQwn0E3L/BghFmLhpja7TA0brlm8A2SYr1yh6NwgCCbsez6uxfMAWYbZLRntstJras yDCXGFGME6e8MNd/McrYrpzBGbvla+RGlWnxJR7t3mS0PakBtv+AnfkQYnGNwjdmYFn+ jyBpF1qN222by8b0TcWucCnYtRaZNiA7GuiiyMSeyUm9j9pn/t/Fxfw1ZqJycV7xrxm+ eelfJvlFwn+EmODZa9iw4x17NcnrckJ/mFwNPloGtR/ctu+KzUNWACw434Q7p8V5de3G Sg08/JHCXPADYJ8JmV9YFOG8ucNir8AmsGJG7VF2XG5eUz1lLEJRDG11PanRSXzxctVd MTfA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RuyzOz74; 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=pass (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 o15-20020a05622a044f00b0043ad39858a4si11878557qtx.98.2024.05.07.05.31.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2024 05:31:47 -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=pass header.i=@linaro.org header.s=google header.b=RuyzOz74; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4Jyq-00066B-Sn; Tue, 07 May 2024 08:31:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Jxx-0005lf-Dh for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:44 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4Jxv-00076E-Ov for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:41 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2e367c2457bso22553661fa.1 for ; Tue, 07 May 2024 05:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715085036; x=1715689836; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sliD5j3ZsW+Ih/VrgBbXH2a/MnjoDv1oe45cMQ/IOgo=; b=RuyzOz74ucJoZ/ZTU8wfy08MCYBqrTw3ZR/D0eLYXGOfOdPb2dd3MGmybs/+VafoB6 WgRCjom7pNkBKMmRl+BdyJY6CsRV9HIXXZqowZTazPSFZjePVviY7tjOOg71ZABqgcJI +EEnklpir90PNPGX5L0NCpMgqRMbnV+IGpVan0ALfu6n162eSlSM/NOFML+m2RZa6Zwi f/90zjWW2yvmBENayhQ1a6e4+SP6VAiUh4lXeCxSsDzLs01gUTTIiz79aPEl0of0O8om l8QGBRcVlD/2nNJNTc5/tCRfECs0tB8Jb1iKOX2YJOpHsUS2adA7HjKpGj4/PwO7vEBI yyZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715085036; x=1715689836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sliD5j3ZsW+Ih/VrgBbXH2a/MnjoDv1oe45cMQ/IOgo=; b=ZPT+VQQWaGPhcorcpgqH8hZrCDfjAX7TI48e3EVt5o3h4s7iSi2P1UOZX+FuiMAmcE ilnqHb3uOYjynD3T8ojITTqFgcfN332CIzub+wuW4l9T1h33r63mp9O38N4W7W/HHztG vfh8tt4skyPfMZ/McaIuFY+mMcDKj2ZzfvkpiwTO8WsmHtwE9KDfAssKUW0OfjnnjIpl OffmraRumLpZwAHaxBaBO3ghJHJuYuPMaDa+9NLmKmx96EmxTTUsBPkixdAB/gXLdEZv N12FunxrvNtUng0Y7llQg3ESKjZOL6mBrtoI88120aDdX25I2buCR2UWWtN13ZF+PC6s yhBQ== X-Forwarded-Encrypted: i=1; AJvYcCXbyBs1bFey3sdvxHfHbnnrSwa2gfSl/zq1txG+BzFfctnjk4YtQdhAsUrGimO6cranK/WPI4sK53tXa2Br5IOxTgr7+4s= X-Gm-Message-State: AOJu0YxAvgE6hzhqUOkA1FOQF6Tj4QDRVC5sDbyZ/rN0ynvXDJSgTQZn LqfFifJuDUomZQUJDiA8HBRwa4r4wvOYSee/Y2UpMGtNHPCc+NkIMkUZK6NJswiwnPsvJBS58vT 8 X-Received: by 2002:a2e:9297:0:b0:2e4:f8e:3a64 with SMTP id d23-20020a2e9297000000b002e40f8e3a64mr769862ljh.30.1715085036211; Tue, 07 May 2024 05:30:36 -0700 (PDT) Received: from m1x-phil.lan ([176.176.177.243]) by smtp.gmail.com with ESMTPSA id y10-20020a5d620a000000b0034ddb760da2sm13072941wru.79.2024.05.07.05.30.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 May 2024 05:30:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Mattias Nissler , qemu-devel@nongnu.org Cc: David Hildenbrand , "Marcel Apfelbaum" , Peter Xu , Richard Henderson , john.levon@nutanix.com, "Jonathan Cameron" , "Elena Ufimtseva" , Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/3] system/physmem: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Date: Tue, 7 May 2024 14:30:23 +0200 Message-ID: <20240507123025.93391-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240507123025.93391-1-philmd@linaro.org> References: <20240507123025.93391-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=philmd@linaro.org; helo=mail-lj1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Simplify cpu_[un]register_map_client() and cpu_notify_map_clients() by replacing the pair of qemu_mutex_lock/qemu_mutex_unlock calls by the WITH_QEMU_LOCK_GUARD() macro. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- system/physmem.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index d3a3d8a45c..5486014cf2 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3086,7 +3086,7 @@ void cpu_register_map_client(QEMUBH *bh) { MapClient *client = g_malloc(sizeof(*client)); - qemu_mutex_lock(&map_client_list_lock); + QEMU_LOCK_GUARD(&map_client_list_lock); client->bh = bh; QLIST_INSERT_HEAD(&map_client_list, client, link); /* Write map_client_list before reading in_use. */ @@ -3094,7 +3094,6 @@ void cpu_register_map_client(QEMUBH *bh) if (!qatomic_read(&bounce.in_use)) { cpu_notify_map_clients_locked(); } - qemu_mutex_unlock(&map_client_list_lock); } void cpu_exec_init_all(void) @@ -3117,21 +3116,19 @@ void cpu_unregister_map_client(QEMUBH *bh) { MapClient *client; - qemu_mutex_lock(&map_client_list_lock); + QEMU_LOCK_GUARD(&map_client_list_lock); QLIST_FOREACH(client, &map_client_list, link) { if (client->bh == bh) { cpu_unregister_map_client_do(client); break; } } - qemu_mutex_unlock(&map_client_list_lock); } static void cpu_notify_map_clients(void) { - qemu_mutex_lock(&map_client_list_lock); + QEMU_LOCK_GUARD(&map_client_list_lock); cpu_notify_map_clients_locked(); - qemu_mutex_unlock(&map_client_list_lock); } static bool flatview_access_valid(FlatView *fv, hwaddr addr, hwaddr len, From patchwork Tue May 7 12:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795208 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp269372wrc; Tue, 7 May 2024 05:31:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUvqqkw+32kKvcec+VgZBlHrzgPLXbJAaPT9+5nq6MkJbbNBu3mkcNcR0xYVosygOBLkKtGp9zjE0+DggYunSqM X-Google-Smtp-Source: AGHT+IEOdSxQMphF7XgpCKKUCjdy4K1kvd06L2ZZB4tslouKb7tfJfxbf8q6WWG81ZyW5vFasmG0 X-Received: by 2002:ac8:5888:0:b0:43a:7b64:2fcc with SMTP id d75a77b69052e-43d8f2f5c76mr42031111cf.7.1715085112716; Tue, 07 May 2024 05:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715085112; cv=none; d=google.com; s=arc-20160816; b=eUz/jEyb/WogbxPF35Q8mzts6QbZ537T7Q5GBWJkWotT6nHdBWW9SXpcl9q8QiJv2L hdL1M8uTqVwSmk0vUaognm3YoTTs0d6UKTQ3Vh2N8okXvKBlZqC4XYdQEVgrZQd9EzVx XvNcP+6P7Ev/WG9alddI8YSM4769Kf87CBzz2GLaHXnzikYn5wToMw3/Jy1shcaee2cm R+FuGz5DjmLb8PPkCBOSTOYWx/ymblUfKmAWK4agFJ1QylI2IhRLlYxHZZKb4Lpvub0m lg4NXRF0GQITUHuC14e420VAFWyoNERv1/BWgXsHc3F6Aky6Ygcl8hMCjZQSjX3+86mq uWOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nIvNhuB8BogFmSNK+pezmWU5o0wMBR++47H4xs8QF94=; fh=aIXAxcVmhakrf7x5N2BjBcu4ikgjemvD4xIfGmbDVxI=; b=hTNgYnD35TrtxMwPbgNoWMaJbXW9SyoAPj38nXUYtHdHw5XKFULMyWYCUenfrFs81P 6r2wg08LTJ7HRWE3JTAtQw69zvHFfWkZKyJMWWGkSMBkRk8HWwcyMjYqbCXFrHn82EBO 6Ret6oSgUq1mYdAAyqFiIHS85GD3CaCTcrwMXyUAgKpN0jRvKX9xxO1JojJDUMtJkvxQ 20q+0g/s9G+FNdGp2VcwPhaEsSn+i2IdgG+aOznSp2uIzobIWDpCp/tMu7D7dM+5qJ4V kcio5QaulOgfI2guFpWR6taZHY4Rh9GNOnSuhBisjdnfc/2WslcpxuvOQC8Fa6YI490P oWmQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BMJqW8pi; 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=pass (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 k11-20020ac85fcb000000b004367f8acd4bsi11308832qta.558.2024.05.07.05.31.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2024 05:31:52 -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=pass header.i=@linaro.org header.s=google header.b=BMJqW8pi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4Jyr-00067B-46; Tue, 07 May 2024 08:31:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Jy2-0005oj-Oq for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:49 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4Jy0-00077B-L7 for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:46 -0400 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e3e18c240fso10556681fa.0 for ; Tue, 07 May 2024 05:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715085043; x=1715689843; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nIvNhuB8BogFmSNK+pezmWU5o0wMBR++47H4xs8QF94=; b=BMJqW8piKwWif7MKrUayL4mzeegZv4kLRma6wuMLD4/cx58uk6SYbA4FTfN74PHP7O 5kWChpLdtm+P9TrTTHMoRSsgQBk9KN6mYLDakJ9dqMKb47Cjd0pafyWZiJjQb6KGCtYR JwSmfVBNqrVrII1EH6cuP4fv7VFzaJnRycEdI7IMN2o4Pz0L2oGkc0xs34UQuqEN/kD2 37SopcVDZCsSbANY5WTtByNqP7G1x1i681Tw2OqWq2JKa423lhjK+G/lGuUrKScSJcTn MzXEDmfWIFp+N3leoeg9s7LKyDIhtGMV3EKwp9m2G1eXX4t5DMZhldwwxcDke6ZVxV9p w5Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715085043; x=1715689843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nIvNhuB8BogFmSNK+pezmWU5o0wMBR++47H4xs8QF94=; b=SX8jk3k5F2nt5GpTiXQcT5N4/s9QhqgYwKAyswoO9/mhVXCYcu8YmP0APPZ8iiOOo9 OFANDlnKfnN2VlMMF8WwgfEIDTlRl87LdeAwA8V1zMSoI/qaQZBrFSEw24V1LEGrMQNS TvY6pBNalbo207pq+k4F4QdbtJstq3NBFazDW4NLyQK1C9s3MtM5NGDsLq16Clq9c6kg 46yS4ZYIcFIAapPv2pSSgXnYwg1QtXrixBt/jwcbeetRyiaVcxnLmaFdyWm+h/BSA91Y rYiI9C29xx7d1Dw6SiMtJ4OIQxkgE/ZEYACWGpAjS/7f8t7pe1mT4y5gqkhWRPipnShb 0zUQ== X-Forwarded-Encrypted: i=1; AJvYcCUzwcn7C22UpsOnpD/LPjf0uiNwO7nX2M2vV16q2u7pSmi9M43OULwPonzRUDPRtoi0yRIbkxEDt9tWTyESSRgcN22jc6o= X-Gm-Message-State: AOJu0YzJkqeRuuZ3lLUeHZvEtlzwWUyrN4fnvT+Uz1YLWBRGLniI4u6/ guTv+eatbGpEU0oZwKMGK8k1uxLkeHCCFRgrD16TEgzO4L1t3XaauoIX4kcF9u4= X-Received: by 2002:a2e:b8d2:0:b0:2da:7944:9547 with SMTP id s18-20020a2eb8d2000000b002da79449547mr14086789ljp.5.1715085042794; Tue, 07 May 2024 05:30:42 -0700 (PDT) Received: from m1x-phil.lan ([176.176.177.243]) by smtp.gmail.com with ESMTPSA id h4-20020adff4c4000000b0034cee43238fsm12830670wrp.27.2024.05.07.05.30.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 May 2024 05:30:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Mattias Nissler , qemu-devel@nongnu.org Cc: David Hildenbrand , "Marcel Apfelbaum" , Peter Xu , Richard Henderson , john.levon@nutanix.com, "Jonathan Cameron" , "Elena Ufimtseva" , Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 2/3] system/physmem: Propagate AddressSpace to MapClient helpers Date: Tue, 7 May 2024 14:30:24 +0200 Message-ID: <20240507123025.93391-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240507123025.93391-1-philmd@linaro.org> References: <20240507123025.93391-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22d; envelope-from=philmd@linaro.org; helo=mail-lj1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mattias Nissler Propagate AddressSpace handler to following helpers: - register_map_client() - unregister_map_client() - notify_map_clients[_locked]() Rename them using 'address_space_' prefix instead of 'cpu_'. The AddressSpace argument will be used in the next commit. Reviewed-by: Peter Xu Tested-by: Jonathan Cameron Signed-off-by: Mattias Nissler Message-ID: <20240507094210.300566-2-mnissler@rivosinc.com> [PMD: Split patch, part 1/2] Signed-off-by: Philippe Mathieu-Daudé --- include/exec/cpu-common.h | 2 -- include/exec/memory.h | 26 ++++++++++++++++++++++++-- system/dma-helpers.c | 4 ++-- system/physmem.c | 24 ++++++++++++------------ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 8bc397e251..815342d043 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -147,8 +147,6 @@ void *cpu_physical_memory_map(hwaddr addr, bool is_write); void cpu_physical_memory_unmap(void *buffer, hwaddr len, bool is_write, hwaddr access_len); -void cpu_register_map_client(QEMUBH *bh); -void cpu_unregister_map_client(QEMUBH *bh); bool cpu_physical_memory_is_io(hwaddr phys_addr); diff --git a/include/exec/memory.h b/include/exec/memory.h index dadb5cd65a..e1e0c5a3de 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2946,8 +2946,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len, * May return %NULL and set *@plen to zero(0), if resources needed to perform * the mapping are exhausted. * Use only for reads OR writes - not for read-modify-write operations. - * Use cpu_register_map_client() to know when retrying the map operation is - * likely to succeed. + * Use address_space_register_map_client() to know when retrying the map + * operation is likely to succeed. * * @as: #AddressSpace to be accessed * @addr: address within that address space @@ -2972,6 +2972,28 @@ void *address_space_map(AddressSpace *as, hwaddr addr, void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, bool is_write, hwaddr access_len); +/* + * address_space_register_map_client: Register a callback to invoke when + * resources for address_space_map() are available again. + * + * address_space_map may fail when there are not enough resources available, + * such as when bounce buffer memory would exceed the limit. The callback can + * be used to retry the address_space_map operation. Note that the callback + * gets automatically removed after firing. + * + * @as: #AddressSpace to be accessed + * @bh: callback to invoke when address_space_map() retry is appropriate + */ +void address_space_register_map_client(AddressSpace *as, QEMUBH *bh); + +/* + * address_space_unregister_map_client: Unregister a callback that has + * previously been registered and not fired yet. + * + * @as: #AddressSpace to be accessed + * @bh: callback to unregister + */ +void address_space_unregister_map_client(AddressSpace *as, QEMUBH *bh); /* Internal functions, part of the implementation of address_space_read. */ MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, diff --git a/system/dma-helpers.c b/system/dma-helpers.c index 9b221cf94e..74013308f5 100644 --- a/system/dma-helpers.c +++ b/system/dma-helpers.c @@ -169,7 +169,7 @@ static void dma_blk_cb(void *opaque, int ret) if (dbs->iov.size == 0) { trace_dma_map_wait(dbs); dbs->bh = aio_bh_new(ctx, reschedule_dma, dbs); - cpu_register_map_client(dbs->bh); + address_space_register_map_client(dbs->sg->as, dbs->bh); return; } @@ -197,7 +197,7 @@ static void dma_aio_cancel(BlockAIOCB *acb) } if (dbs->bh) { - cpu_unregister_map_client(dbs->bh); + address_space_unregister_map_client(dbs->sg->as, dbs->bh); qemu_bh_delete(dbs->bh); dbs->bh = NULL; } diff --git a/system/physmem.c b/system/physmem.c index 5486014cf2..27e754ff57 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3065,24 +3065,24 @@ QemuMutex map_client_list_lock; static QLIST_HEAD(, MapClient) map_client_list = QLIST_HEAD_INITIALIZER(map_client_list); -static void cpu_unregister_map_client_do(MapClient *client) +static void address_space_unregister_map_client_do(MapClient *client) { QLIST_REMOVE(client, link); g_free(client); } -static void cpu_notify_map_clients_locked(void) +static void address_space_notify_map_clients_locked(AddressSpace *as) { MapClient *client; while (!QLIST_EMPTY(&map_client_list)) { client = QLIST_FIRST(&map_client_list); qemu_bh_schedule(client->bh); - cpu_unregister_map_client_do(client); + address_space_unregister_map_client_do(client); } } -void cpu_register_map_client(QEMUBH *bh) +void address_space_register_map_client(AddressSpace *as, QEMUBH *bh) { MapClient *client = g_malloc(sizeof(*client)); @@ -3092,7 +3092,7 @@ void cpu_register_map_client(QEMUBH *bh) /* Write map_client_list before reading in_use. */ smp_mb(); if (!qatomic_read(&bounce.in_use)) { - cpu_notify_map_clients_locked(); + address_space_notify_map_clients_locked(as); } } @@ -3112,23 +3112,23 @@ void cpu_exec_init_all(void) qemu_mutex_init(&map_client_list_lock); } -void cpu_unregister_map_client(QEMUBH *bh) +void address_space_unregister_map_client(AddressSpace *as, QEMUBH *bh) { MapClient *client; QEMU_LOCK_GUARD(&map_client_list_lock); QLIST_FOREACH(client, &map_client_list, link) { if (client->bh == bh) { - cpu_unregister_map_client_do(client); + address_space_unregister_map_client_do(client); break; } } } -static void cpu_notify_map_clients(void) +static void address_space_notify_map_clients(AddressSpace *as) { QEMU_LOCK_GUARD(&map_client_list_lock); - cpu_notify_map_clients_locked(); + address_space_notify_map_clients_locked(as); } static bool flatview_access_valid(FlatView *fv, hwaddr addr, hwaddr len, @@ -3195,8 +3195,8 @@ flatview_extend_translation(FlatView *fv, hwaddr addr, * May map a subset of the requested range, given by and returned in *plen. * May return NULL if resources needed to perform the mapping are exhausted. * Use only for reads OR writes - not for read-modify-write operations. - * Use cpu_register_map_client() to know when retrying the map operation is - * likely to succeed. + * Use address_space_register_map_client() to know when retrying the map + * operation is likely to succeed. */ void *address_space_map(AddressSpace *as, hwaddr addr, @@ -3279,7 +3279,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, memory_region_unref(bounce.mr); /* Clear in_use before reading map_client_list. */ qatomic_set_mb(&bounce.in_use, false); - cpu_notify_map_clients(); + address_space_notify_map_clients(as); } void *cpu_physical_memory_map(hwaddr addr, From patchwork Tue May 7 12:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795207 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp269369wrc; Tue, 7 May 2024 05:31:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVN2wimENjkmoe8Kmtcf3pUvbMYFUdv2Ja+msUStmYfz5Ebzu2OzZW6U6Ou+m/ecjve4Pq1APlEtlEcM1/jW2my X-Google-Smtp-Source: AGHT+IGJDjf0T2IbcCabp1K2FWJ2dS25dkcu1o56zNkPBg7IjjFO9fQRLOVAk3Jzs/i+xojmXP6H X-Received: by 2002:a05:6808:2395:b0:3c9:6e10:ab35 with SMTP id bp21-20020a056808239500b003c96e10ab35mr6255203oib.58.1715085112588; Tue, 07 May 2024 05:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715085112; cv=none; d=google.com; s=arc-20160816; b=V50zA2FZ3vPM/6Cp0lGzyJtot2dET4geOKjy2HVS1VjmWNxMo4dwEbaYkcJ/xINjB7 ORkW4VNIL1wCPgqak7pXL3Vw0Hi29Btv868kRR/yBWh4tKdCJo4+6MumWodFWTG/+rzY DIMu+/PnADJckZY3fylc3PRe30YUR4GQqcnWQBfB1rojq+b7wMbWlh7OJiWkPlicoxm4 PN9nLE4OBv7Rv7ioM+GYVyfyN5reI1oqKV59+kypYcLvGy30YB1nkZuEL3J8kvLn5RfA adqzOWnl3bPL+Ax7ARts4PsdHvvjXTDVnwYHA1SfcclRZpDDLd1KhgOAyibx3/2qCWjJ QKvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1ObHVYohrlZDRKitLEsGTx0PDw1Uh/6I7bCMcmj67Ys=; fh=V3C7IY7LPWgOX9yzk9/QOk02kefUbSqqghndFL+vj3k=; b=gGPmIO6x176XsJO0dZTXJkYiaJQrGaQg771X/61/qgYZxyfojsxJTpIEo0zuxalZ1k fPma20Dwql2oSZt8EuwtqNyg0+4Rkf/PSoL2R9M3dkr/niF65XtT8jiL2UhofOUutzuD YpDl8CRvWuvbIS2hCZHDb/G48RVOUuqMdJUYVojsKvCO8VXjsGxnaUOF4BA6pKtqiNs5 K1PCOK3/OMHHd0ZnB/HcxS7i4Kq2nAQhD61T35+a6NrGSkHx8yTqRKo0enftYYqg/bvE SEsXsm5WbF+Tkk4SGs9HKGaZhYU+pZcgTJhKD4rv+7WPqUYIEjWrmPeFLK4yJJiZtz7a pP1Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VeNgHs7l; 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=pass (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 q8-20020ad45748000000b006a0d404e956si11968451qvx.101.2024.05.07.05.31.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2024 05:31:52 -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=pass header.i=@linaro.org header.s=google header.b=VeNgHs7l; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4Jyt-0006Ga-HW; Tue, 07 May 2024 08:31:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Jy9-0005q2-GL for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:55 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4Jy7-000785-CL for qemu-devel@nongnu.org; Tue, 07 May 2024 08:30:53 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-41dc9f98e8dso30258365e9.1 for ; Tue, 07 May 2024 05:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715085049; x=1715689849; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ObHVYohrlZDRKitLEsGTx0PDw1Uh/6I7bCMcmj67Ys=; b=VeNgHs7lcfHiohDOzeWkrLbb2MOW+1R4U0uvFddp9wMt7+fpM92bC8BLXtDMH4I1LA MdykV0POf+MZG7Cpg2tIPkN+HhECgp31UzpsHEaw7QDt5kdCXcJpOpShWeHvVTUiZQdW ork9D+UKLMem69cMcUyHQyZOjh/8fhW8sXszDc18n7BKK4n35DvbhNqeQ4XIHCsKWgCB HF3CFGTyMloTJlIMindXt4HOCqDv7quL3YLUnIRfZzZ5vBTyPwrs88HSjL+mANk7cm4m yFEdo0R+vGZoGDjHLFdn+QT9vcxYo8E1raent0QsB1BG5UpqKji8NqOculOkMeGXDFjZ MHAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715085049; x=1715689849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ObHVYohrlZDRKitLEsGTx0PDw1Uh/6I7bCMcmj67Ys=; b=s0J/O1fOcsEB5aW5eQsKTNarcTtYRgil7MqjJqug6IP00vA59N/BtpGmQ/a60gRPbx C1Im2WtfxYx/9C5LJApgaR0aG29DXBApYa9hv7ew9spHkb3B0EWkjGkdmrVPGOkUfw9z 4jJK56crW77V+TvabnUO8I77jJBv7RUG8FCdgN2EnqGge6qbeye0+Xa1qe5lSst7AV3N FeNMkadB1SDQr+6lBQErlcAF9/6ithZiAF4XI5AU7TVMw5ECySiw+4s4sLvA9+1B1WCe pXskndlFzmGKFet0nCoDxvHHlcyi0rr/uNWBy+dr3V/KVNrDCQDR8vyxATGbt1BDgJID FvZw== X-Forwarded-Encrypted: i=1; AJvYcCVckaizpsiOWOLQWLHJGnLFgfcAwj5XAY/AByYLkEbj5/bcfKxnU6jASOyRmLvS+TO/g29+PDiMaEptxETPCv9sMlLbGM0= X-Gm-Message-State: AOJu0YyXWVKEP/Pz5cusLJUntE42xi3Zih+rTSPc8a1TDngTLpk6Elsr FGTcFsxYRnSSLPTMXhbboHoO+t8XAyxsEGISwKEHfNb0hE+SaGvhMSC/0jHdP0hUlCzZkFrm2rC u X-Received: by 2002:a5d:58d7:0:b0:34d:93c1:c7d8 with SMTP id o23-20020a5d58d7000000b0034d93c1c7d8mr2319410wrf.4.1715085049534; Tue, 07 May 2024 05:30:49 -0700 (PDT) Received: from m1x-phil.lan ([176.176.177.243]) by smtp.gmail.com with ESMTPSA id s8-20020adfecc8000000b0034dda041ccasm12908426wro.102.2024.05.07.05.30.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 May 2024 05:30:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Mattias Nissler , qemu-devel@nongnu.org Cc: David Hildenbrand , "Marcel Apfelbaum" , Peter Xu , Richard Henderson , john.levon@nutanix.com, "Jonathan Cameron" , "Elena Ufimtseva" , Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 3/3] system/physmem: Per-AddressSpace bounce buffering Date: Tue, 7 May 2024 14:30:25 +0200 Message-ID: <20240507123025.93391-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240507123025.93391-1-philmd@linaro.org> References: <20240507123025.93391-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mattias Nissler Instead of using a single global bounce buffer, give each AddressSpace its own bounce buffer. The MapClient callback mechanism moves to AddressSpace accordingly. This is in preparation for generalizing bounce buffer handling further to allow multiple bounce buffers, with a total allocation limit configured per AddressSpace. Reviewed-by: Peter Xu Tested-by: Jonathan Cameron Signed-off-by: Mattias Nissler Message-ID: <20240507094210.300566-2-mnissler@rivosinc.com> [PMD: Split patch, part 2/2] Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé --- include/exec/memory.h | 19 +++++++++++ system/memory.c | 7 +++++ system/physmem.c | 73 ++++++++++++++++--------------------------- 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index e1e0c5a3de..d417d7f363 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1112,6 +1112,19 @@ struct MemoryListener { QTAILQ_ENTRY(MemoryListener) link_as; }; +typedef struct AddressSpaceMapClient { + QEMUBH *bh; + QLIST_ENTRY(AddressSpaceMapClient) link; +} AddressSpaceMapClient; + +typedef struct { + MemoryRegion *mr; + void *buffer; + hwaddr addr; + hwaddr len; + bool in_use; +} BounceBuffer; + /** * struct AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ @@ -1129,6 +1142,12 @@ struct AddressSpace { struct MemoryRegionIoeventfd *ioeventfds; QTAILQ_HEAD(, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; + + /* Bounce buffer to use for this address space. */ + BounceBuffer bounce; + /* List of callbacks to invoke when buffers free up */ + QemuMutex map_client_list_lock; + QLIST_HEAD(, AddressSpaceMapClient) map_client_list; }; typedef struct AddressSpaceDispatch AddressSpaceDispatch; diff --git a/system/memory.c b/system/memory.c index 49f1cb2c38..642a449f8c 100644 --- a/system/memory.c +++ b/system/memory.c @@ -3174,6 +3174,9 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) as->ioeventfds = NULL; QTAILQ_INIT(&as->listeners); QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link); + as->bounce.in_use = false; + qemu_mutex_init(&as->map_client_list_lock); + QLIST_INIT(&as->map_client_list); as->name = g_strdup(name ? name : "anonymous"); address_space_update_topology(as); address_space_update_ioeventfds(as); @@ -3181,6 +3184,10 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) static void do_address_space_destroy(AddressSpace *as) { + assert(!qatomic_read(&as->bounce.in_use)); + assert(QLIST_EMPTY(&as->map_client_list)); + qemu_mutex_destroy(&as->map_client_list_lock); + assert(QTAILQ_EMPTY(&as->listeners)); flatview_unref(as->current_map); diff --git a/system/physmem.c b/system/physmem.c index 27e754ff57..62758202cf 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3046,26 +3046,8 @@ void cpu_flush_icache_range(hwaddr start, hwaddr len) NULL, len, FLUSH_CACHE); } -typedef struct { - MemoryRegion *mr; - void *buffer; - hwaddr addr; - hwaddr len; - bool in_use; -} BounceBuffer; - -static BounceBuffer bounce; - -typedef struct MapClient { - QEMUBH *bh; - QLIST_ENTRY(MapClient) link; -} MapClient; - -QemuMutex map_client_list_lock; -static QLIST_HEAD(, MapClient) map_client_list - = QLIST_HEAD_INITIALIZER(map_client_list); - -static void address_space_unregister_map_client_do(MapClient *client) +static void +address_space_unregister_map_client_do(AddressSpaceMapClient *client) { QLIST_REMOVE(client, link); g_free(client); @@ -3073,10 +3055,10 @@ static void address_space_unregister_map_client_do(MapClient *client) static void address_space_notify_map_clients_locked(AddressSpace *as) { - MapClient *client; + AddressSpaceMapClient *client; - while (!QLIST_EMPTY(&map_client_list)) { - client = QLIST_FIRST(&map_client_list); + while (!QLIST_EMPTY(&as->map_client_list)) { + client = QLIST_FIRST(&as->map_client_list); qemu_bh_schedule(client->bh); address_space_unregister_map_client_do(client); } @@ -3084,14 +3066,14 @@ static void address_space_notify_map_clients_locked(AddressSpace *as) void address_space_register_map_client(AddressSpace *as, QEMUBH *bh) { - MapClient *client = g_malloc(sizeof(*client)); + AddressSpaceMapClient *client = g_malloc(sizeof(*client)); - QEMU_LOCK_GUARD(&map_client_list_lock); + QEMU_LOCK_GUARD(&as->map_client_list_lock); client->bh = bh; - QLIST_INSERT_HEAD(&map_client_list, client, link); + QLIST_INSERT_HEAD(&as->map_client_list, client, link); /* Write map_client_list before reading in_use. */ smp_mb(); - if (!qatomic_read(&bounce.in_use)) { + if (!qatomic_read(&as->bounce.in_use)) { address_space_notify_map_clients_locked(as); } } @@ -3109,15 +3091,14 @@ void cpu_exec_init_all(void) finalize_target_page_bits(); io_mem_init(); memory_map_init(); - qemu_mutex_init(&map_client_list_lock); } void address_space_unregister_map_client(AddressSpace *as, QEMUBH *bh) { - MapClient *client; + AddressSpaceMapClient *client; - QEMU_LOCK_GUARD(&map_client_list_lock); - QLIST_FOREACH(client, &map_client_list, link) { + QEMU_LOCK_GUARD(&as->map_client_list_lock); + QLIST_FOREACH(client, &as->map_client_list, link) { if (client->bh == bh) { address_space_unregister_map_client_do(client); break; @@ -3127,7 +3108,7 @@ void address_space_unregister_map_client(AddressSpace *as, QEMUBH *bh) static void address_space_notify_map_clients(AddressSpace *as) { - QEMU_LOCK_GUARD(&map_client_list_lock); + QEMU_LOCK_GUARD(&as->map_client_list_lock); address_space_notify_map_clients_locked(as); } @@ -3219,25 +3200,25 @@ void *address_space_map(AddressSpace *as, mr = flatview_translate(fv, addr, &xlat, &l, is_write, attrs); if (!memory_access_is_direct(mr, is_write)) { - if (qatomic_xchg(&bounce.in_use, true)) { + if (qatomic_xchg(&as->bounce.in_use, true)) { *plen = 0; return NULL; } /* Avoid unbounded allocations */ l = MIN(l, TARGET_PAGE_SIZE); - bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, l); - bounce.addr = addr; - bounce.len = l; + as->bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, l); + as->bounce.addr = addr; + as->bounce.len = l; memory_region_ref(mr); - bounce.mr = mr; + as->bounce.mr = mr; if (!is_write) { flatview_read(fv, addr, MEMTXATTRS_UNSPECIFIED, - bounce.buffer, l); + as->bounce.buffer, l); } *plen = l; - return bounce.buffer; + return as->bounce.buffer; } @@ -3255,7 +3236,7 @@ void *address_space_map(AddressSpace *as, void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, bool is_write, hwaddr access_len) { - if (buffer != bounce.buffer) { + if (buffer != as->bounce.buffer) { MemoryRegion *mr; ram_addr_t addr1; @@ -3271,14 +3252,14 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, return; } if (is_write) { - address_space_write(as, bounce.addr, MEMTXATTRS_UNSPECIFIED, - bounce.buffer, access_len); + address_space_write(as, as->bounce.addr, MEMTXATTRS_UNSPECIFIED, + as->bounce.buffer, access_len); } - qemu_vfree(bounce.buffer); - bounce.buffer = NULL; - memory_region_unref(bounce.mr); + qemu_vfree(as->bounce.buffer); + as->bounce.buffer = NULL; + memory_region_unref(as->bounce.mr); /* Clear in_use before reading map_client_list. */ - qatomic_set_mb(&bounce.in_use, false); + qatomic_set_mb(&as->bounce.in_use, false); address_space_notify_map_clients(as); }