From patchwork Fri Jun 11 23:41:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458670 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1375609jae; Fri, 11 Jun 2021 17:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyN4KgGNpkSqaxXcREq9VWsDKKgbGnolJbOc8R5Wihbe0gPthSVrJHlchjOuXdXrNIQrru X-Received: by 2002:ad4:5005:: with SMTP id s5mr7316998qvo.25.1623456017273; Fri, 11 Jun 2021 17:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456017; cv=none; d=google.com; s=arc-20160816; b=F/e/MDs1N1EBTv3zOsBpC5zKwOHgUd7AWwlxpoFc54LzuBC+kd0DS6+kA7NQUg0VBL QVw6/WPdFCHFBxhgXS0dl3TjvGYiAHeoRU31zJXuGceP1A2v4O9VYW4tWBrfG+y7kJ0h 2ONUC8gc5FG+4WQ6lr6go/GJ2OmT5zE9CVGzwPgDDdiSgFA7A6emPF4690zUye2J4BCG lqgzzl5sLhLKRfAk4fVAONbzH/rm+i2/dXSWNhlTn+W6Amp+Cq7cr6KI/EhgcwHWOPwx TVJXv0CHmMnOIs3bKgeqLrQVkBcxqTLYoDljaB8BY7mhNGNm+LzBfnLGvGVZcl3q/oFU VZzQ== 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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=gf3ZzMThmiJCjbLYbJK60Qj7H8rQ65J/SsnagBkpvkRGvO115YQ1oqFERgNRm9FCvC 0KR7kWcNf/12m0RdW0oOwa+K9lw2+yuGLZhSuPAMJ2DvR3pkDBMrBpyqTsRIh8jd3+aE ytU7heFGE5FPChBQQCfPVvhvZuQTjBOuQM3eM2xyXpi1M3r/4RjN9FRI+2+wPWfpPSgu 2mvg2pD8ePGlLGzNMvBjk5f7Qeh+FfBIYLitDVTeGrAcxOvw126QDIN8FMlN+Zmznzv5 WmpJ8/VwKIdLICwxHeGC78itwPpyBtZk3D+0BE1D2gUtWtMmhEe3ETzvHiXvOhw1ThA7 enpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OGvRN9iB; 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 f9si5186974qkg.301.2021.06.11.17.00.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:00:17 -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=OGvRN9iB; 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]:49170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr4S-0007bN-M6 for patch@linaro.org; Fri, 11 Jun 2021 20:00:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqms-000352-OI for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:07 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:56102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002lN-Su for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:06 -0400 Received: by mail-pj1-x1029.google.com with SMTP id k7so6524818pjf.5 for ; Fri, 11 Jun 2021 16:42:03 -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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=OGvRN9iBjuorOC574RzX+WSlNAbzHwtkztdR8lNqKi7aCcRXhN3zeJj8H6q8QYAoiQ Caw7DLXUhbHz+CV+wcwBhE48iIJr9SWDDhFl9EBwrjO/agq4Go8h0F5lwrrqyxQhm+/r O+wa80oSq8sIzV7jWsopLS6dR2HEaQm5Vscp/ZW9NAf9LR3UqZfJHmXaE9j5jo5BjlzD sIUL8olCDor2TG75hYxr+/Szwg3aChe/aA4Xxb0oTND5FeQ1UUEJiZy2DVpqk/lSkCa2 ZjabL1hVe5+7GiwyM7SqLPS/VnRC9EH9dbGXzPbz8SugRd/wZWsReYUmgZSbk7AYrtQk lbAw== 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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=fMECbPfGUCQf0BtLDHQbdYvJWW3ISA6/OqDSwcMaDhNWeUnLFqDiZhAygRJ5kX4tIL XLR/ddEVD170GVSDkocfym4KbZf7iKeogdEWrcil9UfqaSG1F5QGfD1mq7118P+w84DX gS2xaHcH2VlfFMzfgkxx21IwUQVd0YX0ycM4UGvu0lu+FBtRFcxnek2uiV9XiRCq6WkB O+HAwWceMBXrKTUSK+eTTY4zztg9EnsrqZ+tNESm7G6FSQ8ocluKGEWW1PBv0b726EIA icD1JA8sqCgr1HvK8mlFehchQLjvdgPdB2Jt4YV6YaOqPTpz9vgLvEdw7iulNnZoxZ6L rZYQ== X-Gm-Message-State: AOAM533M/ixeNNjjxL/GnxVtf8CLZNSn6Txu/O3d8dc4Rh6YFTME5lSp wmOFMipXojj0+L86FDKUAzhk2R6X9tpYMw== X-Received: by 2002:a17:90a:8001:: with SMTP id b1mr11424065pjn.17.1623454922465; Fri, 11 Jun 2021 16:42:02 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 28/34] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Fri, 11 Jun 2021 16:41:38 -0700 Message-Id: <20210611234144.653682-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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: Luis Pires 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 Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/region.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 294cbd8e65..0f6808afdb 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -770,12 +770,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; @@ -906,11 +909,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) } } if (have_prot != 0) { - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failure. - */ + /* Guard pages are nice for bug detection but are not essential. */ (void)qemu_mprotect_none(end, page_size); } }