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); } From patchwork Sat Jul 22 11:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 705246 Delivered-To: patch@linaro.org Received: by 2002:a5d:60ca:0:b0:317:2194:b2bc with SMTP id x10csp886961wrt; Sat, 22 Jul 2023 04:35:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlFA5bTfKD1UBiXTAPve73uIvJ2cZbeDZJrE36r/PBtlC0MCSyKsjzQjEQJffSSTD89gEWBm X-Received: by 2002:a0c:e283:0:b0:637:a75:2473 with SMTP id r3-20020a0ce283000000b006370a752473mr1994897qvl.7.1690025753470; Sat, 22 Jul 2023 04:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690025753; cv=none; d=google.com; s=arc-20160816; b=EP9rCdrQsqh3TDigFGw2Wmet11pNeR6IpRj6yYk9pOaxkZBM4gwalTEu0wgVr5MdPr wcGCRVwCbRlpxGEBllqqDJrSMHVxMoOvw/CSwrFIEx1OJoUdZ+YxySokvDUfJGH+gTt7 Ew3anBG3JbSLfYVwSoykTlg0hdoW7FPKsTNC6Fm6F3qGMXhFW9cH8/LW9409pmHGT0fg Kphtnic28QlR/IDkDcCrURGMEcsoViUxhbqsdnXgXiLIaaIn0dxSVJ1+uZ14ug8Cj5NM xdLkgWDabi3b2GzQAPMflZm7++3W1P68cuFX/nStUEhPAT1zlbNYyPyJax510emnPUTi B6FQ== 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=56N41Jk8Te2RCjYHiOR0ZCSY9ldifZTYSDR9kOo+b2U=; fh=dar3VLbuhlF4sfQjYytRTFhcEwFCm4WmC7f2qzZT2aY=; b=IlxZJBI3mCpv7ptYSbg0WbP3gWOXEXUCB3P54wlKJxsa8FLF1GQyyD3KzLMIHVhPkW o6f8hXl5HVzY7ytoe1uIp1VHTIfZ6uqVgnYe7tUAkwPPovl/WTtkvJyycx1Luu4Gda6u i6m2fBJM3g8inT/VPohoeKyBbUH06Pp0liNhN9hepH1Fv3N4TWE/JulyHDZp2Em+t0jK Sas/WLZ+yYDOfMRSMejL4sRi1/VD3kBmHZ5gfxY/0YwBZRPHx2a2If+d0gzEztA8lXHj EBmcD5zlSIkOr3XhQb6YOhKW27PsSk9tiCCVCe3WCLMcPt6WNSrQmrCUcbDlFLI55LbK AXQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TDvjO372; 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 o11-20020a0c8c4b000000b00623a0060cd5si2659189qvb.458.2023.07.22.04.35.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jul 2023 04:35:53 -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=TDvjO372; 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 1qNAtP-00062j-FJ; Sat, 22 Jul 2023 07:35:23 -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-00061r-7e for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:19 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNAtG-0000hx-S0 for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:18 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3110ab7110aso2393260f8f.3 for ; Sat, 22 Jul 2023 04:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690025710; x=1690630510; 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=56N41Jk8Te2RCjYHiOR0ZCSY9ldifZTYSDR9kOo+b2U=; b=TDvjO372y0/2S/Tg67GpOM/VdYPdh942AdISz8v93jQqFloG1bc7fmKQhVTYVlfgP9 LinF3hs0tJwTgc4WMeSKzuQZvDu+ymol9B+GjjFjf8x6JzYPed7GSMNlj89hf9eBvgLc teInbui6kOCvvEfXssoiHaM4jPwuWtAJwbE+K7AWOC3OGzUdSLTTDI9xNPVa4yZa0IqE kVKtP88cuzwLa0EJ+0/oLb8goi3V37ZF3ZD9WGCTdOr1hpxehGAMf7uHd7OYP1agDJ8d 16sU62JXykq+Q673ojomUO/svoCqbxb7XLABLY9hbvE2JlhXiLfPQCSsJIy+ClTDowgS VAlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690025710; x=1690630510; 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=56N41Jk8Te2RCjYHiOR0ZCSY9ldifZTYSDR9kOo+b2U=; b=dh79XgMTUHfYmq2XL6hug/KQKcI2Mf6pvZaCb36QA8mmEiICtREWw6xrAyr3vxfSJz BQamiZ3ZvnGvpG5zD9DBCvKJnSIyrVIhtc7AuBq5o9ISf/KHrLg42Uv/ZIt3bsfCFVrq QRHuYCQUBf6oFIg4nfGGLLNYhq9QKaywMqJ3YDitGEh7zGkOjBtzuke7ljJhWQfMyjfA M7Dv/dttdNXEyPL/s/jVaq9WBTP74b6J2O4EcnjobVwKqefZo3OuDWlVOdGG3T8lc5zS J7WfGO0P6f7KrP1Q9IAhBZNZUVnRCH6mLPU+8UvvD0TpOo94mdncCrG/a/dkaS6nxtM/ 7Raw== X-Gm-Message-State: ABy/qLYzvuDRq+hkYzN3CHWA/td3nbkLzw9mZOrLokeGWcwgM2Z0NN+K oeUA1I9uny7lSsq0SM/m3hr9T//1nj9/cPjflmFCTQ== X-Received: by 2002:adf:fcc2:0:b0:314:3503:15ac with SMTP id f2-20020adffcc2000000b00314350315acmr3900272wrs.10.1690025710117; Sat, 22 Jul 2023 04:35:10 -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 2/3] accel/tcg: Fix sense of read-only probes in ldst_atomicity Date: Sat, 22 Jul 2023 12:35:06 +0100 Message-Id: <20230722113507.78332-3-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::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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 In the initial commit, cdfac37be0d, the sense of the test is incorrect, as the -1/0 return was confusing. In bef6f008b981, we mechanically invert all callers while changing to false/true return, preserving the incorrectness of the test. Now that the return sense is sane, it's easy to see that if !write, then the page is not modifiable (i.e. most likely read-only, with PROT_NONE handled via SIGSEGV). Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- accel/tcg/ldst_atomicity.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc index 4de0a80492..de70531a7a 100644 --- a/accel/tcg/ldst_atomicity.c.inc +++ b/accel/tcg/ldst_atomicity.c.inc @@ -159,7 +159,7 @@ static uint64_t load_atomic8_or_exit(CPUArchState *env, uintptr_t ra, void *pv) * another process, because the fallback start_exclusive solution * provides no protection across processes. */ - if (page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { + if (!page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { uint64_t *p = __builtin_assume_aligned(pv, 8); return *p; } @@ -194,7 +194,7 @@ static Int128 load_atomic16_or_exit(CPUArchState *env, uintptr_t ra, void *pv) * another process, because the fallback start_exclusive solution * provides no protection across processes. */ - if (page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { + if (!page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { return *p; } #endif From patchwork Sat Jul 22 11:35:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 705248 Delivered-To: patch@linaro.org Received: by 2002:a5d:60ca:0:b0:317:2194:b2bc with SMTP id x10csp886970wrt; Sat, 22 Jul 2023 04:35:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlGW+3dPayjehYA+riesNF3o9j4M3MU1gYU2w2MHHIt9mQv4Qt3Rpy2QSGJmsCc0Lq3q2aG0 X-Received: by 2002:ac8:5b88:0:b0:403:b6d2:8dc4 with SMTP id a8-20020ac85b88000000b00403b6d28dc4mr3785037qta.34.1690025753884; Sat, 22 Jul 2023 04:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690025753; cv=none; d=google.com; s=arc-20160816; b=Da81OTGwdBPU3qT/fEkpPyPiDl+GfqspVmYyCHZKu8CHtTN3cBOm92tmjATJcyGj7N iGOgRoEh78euej0/QPggx+uN+qpjyZfsbkmJ/VizXzy0ynaeY/evqK0oUASsKm+TXH7y 0p5eJjwnDoh3dS4XunA9PbZmhE1Alw+4EmHEE6wDhwkmFf5ervZRVmDkBWRvZLCkeS5T h2slcAS4RXd8yiOaBF5zQ7nduw76KpEe5b/SwptpEQG/ZSddlXTngTA11/Rt8miJym2l U1h5L73P2rQm/T1oM3NWkwraffg/RiLll/E2P5EnQat8kyimNiiRZTjGepB5UqBs9qKf AH0w== 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=cwu65N+s8vZwcpL6IuBfk53JluVR+lDy/6W6cKZOd5I=; fh=dar3VLbuhlF4sfQjYytRTFhcEwFCm4WmC7f2qzZT2aY=; b=zSaDvyeYjxXlAtvFjDQwuDoJVZFKn7hWSWKByYX6uQjHVVtD2S2guilYbnLsgpqJpS VSEml6y4blnxMwTKJ5x/EvgekvFN41lrrM96sSTBZZvOlQaRPgYTuOqEmv+BDei5SMVc 33Ig0TgIkXvd5zVfGqvf4vcu4ik0wZ/3sLdfApBCGQlJ2KZkEzq9jK/3bM/Eq8/5EBNI xzBYQR2aJyySiByzRAIe5Q1mhfjtVtfZ5mlOkXRgrTMDIKrPfy08FYOwOBGAW4FL1Efg OJPuMX80hFn79P9kvR39YcICh5kG6126fcir2E0paifMktN1uRhN3/dZ90G2SmtqIlzy /Swg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="v/KbTlbR"; 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 e14-20020a05622a110e00b0040547deb8eesi2522037qty.410.2023.07.22.04.35.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jul 2023 04:35:53 -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="v/KbTlbR"; 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 1qNAtP-00064B-QK; Sat, 22 Jul 2023 07:35:23 -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-00062C-US for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:21 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNAtI-0000i5-Ok for qemu-devel@nongnu.org; Sat, 22 Jul 2023 07:35:19 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3144bf65ce9so2126260f8f.3 for ; Sat, 22 Jul 2023 04:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690025710; x=1690630510; 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=cwu65N+s8vZwcpL6IuBfk53JluVR+lDy/6W6cKZOd5I=; b=v/KbTlbR2C5X3O70K01JPvvOucDhBj+MmTbvOyOBpBghJnuuHxGKVtaKY53t/C6G8Q /F5FfJ5cWDuyvxxqYbWwXyCombBjuY9aFUpFApLtbCwakgpUZf4hpeU3YqsUingjXHZE rFsBsgVYXTSzQVrflTyd+vHICXhdr6Cgw2KKCbaoc9z33Xp33uNCNC0+kaSM9v6BiW7Q RzTkK8iigdC/h+/SpVh47n5S7Edy5z8XWOaJsQYg1plVSqVJtVAtXaVAOrlJWYp7M8WJ IVUdTOhzbxaAPwXU99u2vrOx+dKvUJPyEyflcYUabpTR1Fu/cF/VdTdW7/KDcIg/oRyz s3ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690025710; x=1690630510; 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=cwu65N+s8vZwcpL6IuBfk53JluVR+lDy/6W6cKZOd5I=; b=LcnLmfCpSS/Ez/X7iZiLSM3VCyFjbAUsNt4ydBF3TZI/d0GlYDJogXdcwwsEQMjTCc p3PGZBn6tvSKbGSRp6SerAaE9bsF9KU7orItWZimrGrDqdw9nX3/7JJSlqf88rReXQ/B ezLHZ17OBJYcHUs7A/bFs/dFRQcD8G0eYmSYyyYUpa8cRUELK761uwHLYM9naBmif4W0 3F/uZ449IoeE7PmwGPp4vS6N2WTWv8zkaBFj0P21UZ8upIYkw0U9A7jK1lmJlDsa+WwZ cZWBq1gG2nR1B6iFb7FFS9BzaE9PYzHSjHAMPxZJFeHq3+MHjOY/fDF6gi1rOqszhT6Y 7VJg== X-Gm-Message-State: ABy/qLaIf2xmJI2rwcLfWUAClKk/ZWwj0Wp3WS2GBgiUgOJx3CQWmF5u xjKr2FfMJIujh7imvRtu1nPJsWG2Oxa0Wvz6Y7SWJA== X-Received: by 2002:adf:e584:0:b0:314:248d:d9df with SMTP id l4-20020adfe584000000b00314248dd9dfmr3559375wrm.13.1690025710639; Sat, 22 Jul 2023 04:35:10 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 04:35:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH v2 3/3] accel/tcg: Take mmap_lock in load_atomic*_or_exit Date: Sat, 22 Jul 2023 12:35:07 +0100 Message-Id: <20230722113507.78332-4-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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 For user-only, the probe for page writability may race with another thread's mprotect. Take the mmap_lock around the operation. This is still faster than the start/end_exclusive fallback. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- accel/tcg/ldst_atomicity.c.inc | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc index de70531a7a..e5c590a499 100644 --- a/accel/tcg/ldst_atomicity.c.inc +++ b/accel/tcg/ldst_atomicity.c.inc @@ -159,9 +159,11 @@ static uint64_t load_atomic8_or_exit(CPUArchState *env, uintptr_t ra, void *pv) * another process, because the fallback start_exclusive solution * provides no protection across processes. */ - if (!page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { - uint64_t *p = __builtin_assume_aligned(pv, 8); - return *p; + WITH_MMAP_LOCK_GUARD() { + if (!page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { + uint64_t *p = __builtin_assume_aligned(pv, 8); + return *p; + } } #endif @@ -186,25 +188,27 @@ static Int128 load_atomic16_or_exit(CPUArchState *env, uintptr_t ra, void *pv) return atomic16_read_ro(p); } -#ifdef CONFIG_USER_ONLY /* * We can only use cmpxchg to emulate a load if the page is writable. * If the page is not writable, then assume the value is immutable * and requires no locking. This ignores the case of MAP_SHARED with * another process, because the fallback start_exclusive solution * provides no protection across processes. + * + * In system mode all guest pages are writable. For user mode, + * we must take mmap_lock so that the query remains valid until + * the write is complete -- tests/tcg/multiarch/munmap-pthread.c + * is an example that can race. */ - if (!page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { - return *p; - } + WITH_MMAP_LOCK_GUARD() { +#ifdef CONFIG_USER_ONLY + if (!page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { + return *p; + } #endif - - /* - * In system mode all guest pages are writable, and for user-only - * we have just checked writability. Try cmpxchg. - */ - if (HAVE_ATOMIC128_RW) { - return atomic16_read_rw(p); + if (HAVE_ATOMIC128_RW) { + return atomic16_read_rw(p); + } } /* Ultimate fallback: re-execute in serial context. */