From patchwork Sun Mar 14 21:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400144 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2930252jai; Sun, 14 Mar 2021 14:57:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSnXeN9C5LFc1PvjmNje2Ft15PSCqCSGEPrwr+wxJRAkRosijrSYs5OZSorQaS9BgSZeOC X-Received: by 2002:a25:7784:: with SMTP id s126mr33549781ybc.475.1615759047203; Sun, 14 Mar 2021 14:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615759047; cv=none; d=google.com; s=arc-20160816; b=sbJvnMr9pRMjLSNilo8YVlbQlg9wwOeKljwU/UaGZVPub7+WNE5Ts5PoprN1KW6qPq i+PDrLtPFM/t9lqG/OKWVGOvSsBRkM8jJVksS9V/gd2AGigXaUj+Cn9jauBwISFm+hiG UvjQcsc4qZxMhSND2bKLY9B/2qBWTQ8x8jKQ2mQKfs8upssfrwo+56/vlplQ0a6KRWKj lJEqMUUh/IsQIz7z3wKB0CUb65nYi9Mzx07j4V2TmVNmHA5PNP/cOthshB+W/AGVlwTz m2y9/zOao8H8fD3CRBQIJm3jN/qr0J+upXK3T8OTGD/yW+LsNYGRdEhWjyMSwrW+DK4P ropA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=TYsafCpA0g9KkBJ3xlf9GcYOINr3d+8qevjzY4JwpqXdKGnFYg0Z7YF1Vsu8PYdGPm ElMEr/NSz+IyGt1KP0ACKitBDvQZbYuzZgIbfMOEuEQmRxLpHlCHm/KkL0GaZb75frQ2 DXZ1/ATBA2DILRI4SCwiYXK9Hz1Bvgkv7SLUM+aeTL/AE+R8u2nSeYEawokD9+FSF0j/ XjXxO3CtuAOriwMudCFwWlqvCBj3Q0Joo16aSPcevFt5h+HB6OVgygWRDingmhADAyV1 4G3Q1vEgh97Iuzfw3/93NuXCxMD59+L+ApCetheCn4npNdVs0Sdvf1aw4QFUBJe0T6Ff ZUlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ay2hUMtI; 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=fail (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 v15si13552284ybb.119.2021.03.14.14.57.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:57:27 -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=fail header.i=@linaro.org header.s=google header.b=ay2hUMtI; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYjm-0000qg-Lm for patch@linaro.org; Sun, 14 Mar 2021 17:57:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006QC-O4 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:42129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0008Jr-KL for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72b.google.com with SMTP id z190so29892161qka.9 for ; Sun, 14 Mar 2021 14:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=ay2hUMtI2wg2+819Yv47rInMk8PbuPyYnWXCAuzb1WZSqwXaUz64ubtNJ6k9x6ZAwS M1rA69q+02NIG27UWQPDkWZ3ykv0h2Ba40boO68hWOFILLfbRmW877CfQHBa/OCnOXCW YhW9TItp9FOFddszYGtnQsNczgcqRPevdx0D45fq4iXHgR23rM1Dii3vAZs4s76B0GuG 8KmHNjSwAVrB1zpldtTv6av+jYB0mjPGNC/tHjKVXehxLiamJF0sWhYTo7FIe8riDLqM Y4HcvgnE03NC4hT7PyVcoMKYZVHh9bVqDRsULz955nH6U9CsuqrrzcXr3Rahz78Dcsuj eNOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=TRBcnnzbsNf4/+BLYTCgqVF1679Tl0GGPCHw+eTCSVLfne0eWUG2hKG92TF0hmaELQ qn18Zo66ePyGKe8Vwk16Sg2T9/Gk13V9lumiE0SD0edPO9Kmr20FHOVfTpkZXmvcZ4pz WxMV/Jp5aCPiWQ/Qk8imCl3nY8vguuFYNIvrs1iT1wHHnt13CtMneypHBkvzVtS8QClF R5o72PXUpDjLOdXfInCNUBBaj6Lz7o9VVgApza3S2C7GWESaBmWpCzPUTFulTsXOFKtn O9TxOTR+R3mIDRqRdL5YCDVYTfNAiwgmaDnPsBJuIP1RFwvZ94G0D+m8GdqF9n/QdC4A /BrQ== X-Gm-Message-State: AOAM5332OwVRzT8oNEyKZiUYbr77SHh8aem7L62um6Sj+EGSHKBki9aV s8ieUgqP50rHRIyMd7fIpSxuO+Q5vyKXz+VD X-Received: by 2002:a05:620a:527:: with SMTP id h7mr22323566qkh.108.1615757277705; Sun, 14 Mar 2021 14:27:57 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/29] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Sun, 14 Mar 2021 15:27:23 -0600 Message-Id: <20210314212724.1917075-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There's a change in mprotect() behaviour [1] in the latest macOS on M1 and it's not yet clear if it's going to be fixed by Apple. In this case, instead of changing permissions of N guard pages, we change permissions of N rwx regions. The same number of syscalls are required either way. [1] https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f Buglink: https://bugs.launchpad.net/qemu/+bug/1914849 Signed-off-by: Richard Henderson --- tcg/region.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index fac416ebf5..53f78965c7 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -765,12 +765,15 @@ static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) error_free_or_abort(errp); } - prot = PROT_READ | PROT_WRITE | PROT_EXEC; + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect + * rejects a permission change from RWX -> NONE when reserving the + * guard pages later. We can go the other way with the same number + * of syscalls, so always begin with PROT_NONE. + */ + prot = PROT_NONE; flags = MAP_PRIVATE | MAP_ANONYMOUS; -#ifdef CONFIG_TCG_INTERPRETER - /* The tcg interpreter does not need execute permission. */ - prot = PROT_READ | PROT_WRITE; -#elif defined(CONFIG_DARWIN) +#ifdef CONFIG_DARWIN /* Applicable to both iOS and macOS (Apple Silicon). */ if (!splitwx) { flags |= MAP_JIT;