From patchwork Sat Jul 22 11:35:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 705249 Delivered-To: patch@linaro.org Received: by 2002:a5d:60ca:0:b0:317:2194:b2bc with SMTP id x10csp887095wrt; Sat, 22 Jul 2023 04:36:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlHa49wQwnM2KxeDbAhbdAF3ACgN/OswIVnG+Ube9TE/5wXZWLvkuPs0lgwXKDZ86Kz81Tyg X-Received: by 2002:ac8:5ad0:0:b0:403:c687:bfbb with SMTP id d16-20020ac85ad0000000b00403c687bfbbmr3602703qtd.1.1690025773438; Sat, 22 Jul 2023 04:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690025773; cv=none; d=google.com; s=arc-20160816; b=D6PF5vjOMAVW6ue1TlaDFU3mnOtrghH09G8rgQMCNny5IZtXTBlbc6AkQPrmdd255X zlSErSGijI9AeS+M5FSeddhGOl/x4lIlCAlXvLoW50wkVNceoRChyJndrvOfv2QpwHU1 +55xw7bKFGI4LjDVp4Upb7yVGYZ/tfY6sxRlyOSyRqGoSBB6RKGEFQOcQErw69JGWpRF oZ7dtz3ja51IINcw1NUMx/F394mOMzDoqTFyxJchc9KnANQTDfjnLv9p6Mv1Hwp5CWQk gx/CufuBAnSWEGbHwwHrBZ/6Mho23NMNoH7XxB4rv+AtVtrnmRI73TbGyrB9SxLugeWy za4g== 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=6bjcssZxr7dS2LvruC06Zhi+kFpRW6MiPOiHl1L5fio=; fh=dar3VLbuhlF4sfQjYytRTFhcEwFCm4WmC7f2qzZT2aY=; b=xz8ZnW5K68weWAwpI9gnhLC7a5K7xaUPhcSXpiykdcJFW9tN0RzdXY1z1uyG4u7G9W UCJR1jma6eMukmTR7gy7fP2G0UNjHzkfeGSUQsgElGvmJS/zsdZl2yURuprW/95rOxk7 hcvTEMpTj+lCeQY6DBDrmhSgJKnOhUG3773fM4vGojBFPFkKdT7XahEoFfrdIc5FksyO F+dOQ34SGaWMCs/QAziSn8CmFdHwEHa5Zqm6pVsQdsYy+MTGvljSqypui+0f+v0X9N0V iA7vM4IZbGN0wC6pE58eTTKr1iK3qBvoTLcbw0tQpy4OQeFMgOobhk+vc1M7fSkGtffa yczg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=trBYRYC4; 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 w14-20020ac87e8e000000b004039bcc4d87si2740756qtj.313.2023.07.22.04.36.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jul 2023 04:36:13 -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=trBYRYC4; 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 1qNAtQ-000655-Qv; Sat, 22 Jul 2023 07:35:24 -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 1qNAtL-00062D-UY for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:21 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNAtI-0000hm-PA for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:19 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso25798485e9.0 for ; Sat, 22 Jul 2023 04:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690025709; x=1690630509; 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=6bjcssZxr7dS2LvruC06Zhi+kFpRW6MiPOiHl1L5fio=; b=trBYRYC4hHGNhuO8RKCgYeL8mKYly7pnjYb+ESKHg0nVsasvFOX2TQFb/BujsjGOFT KZlwrYd6gXsbnPVIcX+CQFHHqSERBkE4i/jHptexRZ1wS/DX8AaDCudETI4A+qmHL2n8 q8BLHi+6Bt9XKbYCoBrAAjjCtovl3TPzSrEJQVlwVSJlLHeK/CYkcxhoySLn+RwiGNgy sJW3UAMSKTf8wH5JDpcLiuJO/sSNm6sfAWAI35lZ/5/HQoOd551HQ51WpA8y/VKIK780 GL/96swu8fvUjXf/pEiseaik2hugB7xh036E59tjPukiCM+iqzW0c05yRL+t6GtwFMP6 f44g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690025709; x=1690630509; 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=6bjcssZxr7dS2LvruC06Zhi+kFpRW6MiPOiHl1L5fio=; b=GBM5G2SCFPIbTAwGSsYjm4wlXN34FiJLyQY8D0CMeN+KYsjbehkbBLnkc3N5Wn3+dY MP40c51lOHp7gCzvDQvUIf8mORIoHOgQX+8vn4KH6lopmkSJ9a/aKaYqcxG2ZJejLFkL GC9gp8Ok11yoXhgyYfwEji8W/4yZWnVPt5lI3Rcvo1Ce9Mjnjj6PoUXHEu8uuzGeu9uX 6yh5RxHypuogO/OMK/a+yV0vbRgqCvnZL21aUgq58D7dQ++TaWNqpeObip30jTQVcTf0 UFbQvkpRTb9a39LUCeaIZaTPY1sY8mhsgpc//j5MrKyEFstSdJArjrJIuAoXIRl19Rzv lZwA== X-Gm-Message-State: ABy/qLajDhE4bHEqoaHfmo50gCZDYvvA/UHMPR9AvidHsig2bOYfjvfi DGNmd5LyDzXcazIKzb4RheWRCPWV7kpX4QhaXQRJsw== X-Received: by 2002:a05:600c:204:b0:3f9:b748:ff37 with SMTP id 4-20020a05600c020400b003f9b748ff37mr3569835wmi.20.1690025709510; Sat, 22 Jul 2023 04:35:09 -0700 (PDT) Received: from stoup.acentic.lan (179.181-106-213.static.virginmediabusiness.co.uk. [213.106.181.179]) by smtp.gmail.com with ESMTPSA id y15-20020a7bcd8f000000b003fbdd5d0758sm5130938wmj.22.2023.07.22.04.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 04:35:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH v2 1/3] include/exec: Add WITH_MMAP_LOCK_GUARD Date: Sat, 22 Jul 2023 12:35:05 +0100 Message-Id: <20230722113507.78332-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230722113507.78332-1-richard.henderson@linaro.org> References: <20230722113507.78332-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/exec-all.h | 10 ++++++++++ bsd-user/mmap.c | 1 + linux-user/mmap.c | 1 + 3 files changed, 12 insertions(+) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 5fa0687cd2..d02517e95f 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -629,6 +629,15 @@ void TSA_NO_TSA mmap_lock(void); void TSA_NO_TSA mmap_unlock(void); bool have_mmap_lock(void); +static inline void mmap_unlock_guard(void *unused) +{ + mmap_unlock(); +} + +#define WITH_MMAP_LOCK_GUARD() \ + for (int _mmap_lock_iter __attribute__((cleanup(mmap_unlock_guard))) \ + = (mmap_lock(), 0); _mmap_lock_iter == 0; _mmap_lock_iter = 1) + /** * adjust_signal_pc: * @pc: raw pc from the host signal ucontext_t. @@ -683,6 +692,7 @@ G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, #else static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} +#define WITH_MMAP_LOCK_GUARD() void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUState *cpu, vaddr addr); diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index aca8764356..74ed00b9fe 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -32,6 +32,7 @@ void mmap_lock(void) void mmap_unlock(void) { + assert(mmap_lock_count > 0); if (--mmap_lock_count == 0) { pthread_mutex_unlock(&mmap_mutex); } diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 44b53bd446..a5dfb56545 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -36,6 +36,7 @@ void mmap_lock(void) void mmap_unlock(void) { + assert(mmap_lock_count > 0); if (--mmap_lock_count == 0) { pthread_mutex_unlock(&mmap_mutex); }