From patchwork Thu Mar 11 00:21:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 397470 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp7173ejz; Wed, 10 Mar 2021 16:38:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzC6P208yO2Nk9pagO9SiGdZDGg15REtEvwcJi2cEQsjmK7oGUrjKMvy4FHWT8ZhxyueIF X-Received: by 2002:aca:d708:: with SMTP id o8mr4400455oig.12.1615423089999; Wed, 10 Mar 2021 16:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615423089; cv=none; d=google.com; s=arc-20160816; b=B3UjIMvk5Bu9fGoh/cCv4n8xhXt93TY1NOVwe50OXIZnnXTKZwarXCAV1bvUIkXoRK 69XFP6CMkCJmeTKhKRrV3PNX1THBms4HTbKh2kH5xWY13aC7w/XCz2lBrxYPxHL5T4mE BxSrkPy6v7sfzIg1lKv7EFht4uh6XWbXnE0Zmi31TNuaCn2/obIlSvTiSmD2U0uWHb9Z 8MgOEILCGmilYgRuisA2St+DAL2q2+DGdslHemd/2r0/lZhd8iLsUHyJnBQLxf+iQFtN kv84h5IxrELbsXcIt5DANbpHc295NBUHop89DKYYvjh7IG5gsZvDUYHn5FCAn5wMPOv/ +/yQ== 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=SnKrls1+jQeMnbtcWOCxxqr551UwIJX44aUioNe0+w8=; b=vXeYNxV5Nt7Fg56VmUJDOsPa4vsqHxnQ91zbyBPkXxob5Tg2XpXKBzm9YBNlLHq7WM CR2QPlAZxcALU7YV5MKoWd5RAvyWkvXTd9yXk5TJ+uYxdAcka6JZSpraBF0NcjokS3Kf AKFEyueVHDYzB7zgzGCzcsZ4qCDu9aBGmH7nonZbZMOY10DxEjesWrJyttiRAUbBO958 h25tF7QKtXLUr9LietmguEYUiNutod7IYTD4k/q1FaUryQgmdVHuomwYqV7SDeo1LUhV rYzlJTBdPeCLclNtfr8+hJPAsBde61Kp47BJYagCJBD32TxKoF/SpEHKmhEBsYSecW4q iCqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GSnVI2Um; 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 r126si957930oih.26.2021.03.10.16.38.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Mar 2021 16:38:09 -0800 (PST) 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=GSnVI2Um; 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]:42738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK9L7-0007WR-9O for patch@linaro.org; Wed, 10 Mar 2021 19:38:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK966-0005As-Qd for qemu-devel@nongnu.org; Wed, 10 Mar 2021 19:22:38 -0500 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:38133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lK95z-0001S2-NS for qemu-devel@nongnu.org; Wed, 10 Mar 2021 19:22:38 -0500 Received: by mail-ot1-x32b.google.com with SMTP id a17so18336375oto.5 for ; Wed, 10 Mar 2021 16:22:31 -0800 (PST) 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=SnKrls1+jQeMnbtcWOCxxqr551UwIJX44aUioNe0+w8=; b=GSnVI2UmlYGsBFij1afNzXFNYqlg+/qMoA32FIYsrzm7D7F7pUGIiOIw6DYJ7kM1jX bgAMNDhpFEvBazFJ5Ad1YuHp6OHvK1tAxuNzdE6ZymqKVDyFLx62UUu/1dM0lNbjakwK cDPqD/oqD3LRAHNt/qWAykhFCTwwgcFrkNXuhS++T72IPxd/o9wjGfzrMqY2l4nWkdDz hciqwbJ4t6+PtixV5dlOSsYSuMlkd3oG4BQhB7UBTx3scqhADJuEwYkLN3cT7l+7FmPT wYa4Uos65HV91etw8xFVpwyTbIWKfehybnOeR/TjXQcLHmF+mCXNQRLXHsX+rEisuWWY FECQ== 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=SnKrls1+jQeMnbtcWOCxxqr551UwIJX44aUioNe0+w8=; b=fgqgSt47p4cc073dmJ8HWGEm18j4+aX7DPSFtAk5qV4KgOdZgce7ParVA6IhZh5/fh F59MDJQwgXFApibneqwD5atxPB7PbRT1Dl29o/5HHoUvFZuwbERfuSOZUg6DhmsWjRRI HrNWdjDlYizx9J22kMGSs+XUBOB+2zSu5h3/gqj9GIKAoeayds1L+gcFhdE8GBi9r+QM uBzv4iTvXjAMCQLsJsPM7zMcUxsxlOjQ1rgp6oA2MA0dh2vzkUm9D7UUTi9zKzKMNN3I 96IvCRYKZcRlbj1nj4agL2bphQZruhxfadX9K7/ANKwuHGK7m7poOjP/QbsrSa7zWaK3 rtGA== X-Gm-Message-State: AOAM531ht6jkdwzNZZqe+eATJG7Z+3sH3f//I7HJiTa1OGVwHQCpbEuT 07OHL5P8yb8phht+NhIhAmyQ7KwqyvIW7W/f X-Received: by 2002:a9d:42c:: with SMTP id 41mr4581196otc.108.1615422150420; Wed, 10 Mar 2021 16:22:30 -0800 (PST) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id a6sm300962otq.79.2021.03.10.16.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 16:22:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 26/26] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Wed, 10 Mar 2021 18:21:56 -0600 Message-Id: <20210311002156.253711-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311002156.253711-1-richard.henderson@linaro.org> References: <20210311002156.253711-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32b.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 5b46172fb5..3ffea215a2 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -749,12 +749,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;