From patchwork Fri Jun 11 23:41:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458663 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1375332jae; Fri, 11 Jun 2021 16:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpXtHNTVdtwSwpPKAu+Sz54wi3GsUMwiWaFMHlQ1q1Q/tuTLPgMRh6iuwI0t3cA1LC22/5 X-Received: by 2002:ac8:5986:: with SMTP id e6mr6335980qte.203.1623455989984; Fri, 11 Jun 2021 16:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455989; cv=none; d=google.com; s=arc-20160816; b=ljwrU00f1c8unX8sUTdymqLy5udhwUexU11LqsBpuiDa1Ns3SipidO8aM5NX4FeDZ0 k+OjOyUByZ3ldh9UURGtOz0HGGW0um42mid3zPWlg77MKyPXkWDlU+6sYB4D7n2TXb76 /Enz5sX/pZMy8drL8rYlIuZbLSc07Qcx1176HTyx2Vk2faEJcGhbAsFu7rctYVTWu8D3 xP3Egt7p779cKrV4VJwZOPeRUzBOhgvu8shDunqq1WP78f/nmBd4XVCRaMA0qUNQbRdl jkMEkYicZHlVXDxWLuI/1pjl0e0dpIREZpzHmkz9u5hEUgpmXxYOZwshPSeYNRRetqZx b47w== 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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=hMus0aDoKWOP3ewJm2dOlumvFTKqd90H0Fhain9plfzYiUJHfx1jnHKjnj4V5asjvS rqUufeZaVLBbKWR4jL1m1PjN695IS6CBneJ3E8TcsARBH5OoThcumoanv9VwWqzvcbnT hXQIt8mXjyx0L+JwZNVteXXgkXexInY4zWSKJ/lqPWvpKyI8cctzxAvC68uti2/iqwP9 JIQWDq9dn7lkvt22bQ8oRc8nwT1G9PBay5NF9zLpqvLDaxzmeE5YAbJBwfEzve6CnK16 1yigHCXMQaqMy+rlLkE0/BJcPXmC8awb/hncjyVFM8vP36cJ8n37cBUhUhwXZTC4XtVZ V4Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bdLFHHPw; 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 l24si4961310qkg.200.2021.06.11.16.59.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:59:49 -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=bdLFHHPw; 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]:45636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr41-0005E9-DL for patch@linaro.org; Fri, 11 Jun 2021 19:59:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmr-00032o-1P for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:05 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:33455) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmo-0002kN-F4 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: by mail-pj1-x102a.google.com with SMTP id k22-20020a17090aef16b0290163512accedso8024785pjz.0 for ; Fri, 11 Jun 2021 16:42:02 -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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=bdLFHHPwOlW4VyQm3We/eXb+tvzIbp+VmnB2Zly8tWpPgPtoeRvAv1cIGMxSgYlY3V f+Veegvt7fssgEJ40mQZFwEcIDHKqK5WYB6fGkyCYJSIRDdFeoUGqc2vUSvaONXmaPsw q8FigcpwXC4XRlAI38t8RWF9JyIBiYFk+pH5kgFf04Xm8XuVwpjDWjNwIdkL4D7VwlNY tuLckFRAzHYwoRv3M55EznPELFIm9XK6WFocRN9hNgxOuHBVbPVn4YSXRc3iir+eE/7u SmZ/fCWUCd0UE8G7o3d9e8k/0RvYyDRki+a4Yze+M73i1tYNQmROeewjg9NgPTtaBkvF 1Feg== 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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=nROPJDFoXdkITSSMj/FqjTOHkLkOFalvJ9Xi9IxF6Ol1idsQbg5A6TvZ4Y43PsM4sm sIqGPoP+JtuwUQAz5WJJVtb2ra9RHsNjsyst0QEb489twO1/+Lsj+a3Qgmp6ac97+IXu NXFudXt8TekH3UX7h44bJb9ACIJqnGEvqm0m8+wnZRmzjqhRDBzb+wMJQbXnxBfKvNbv Sq6zxjrWDeYhrdAeaUDDTyR1qwSGIjuWUxKKKBP/QYswYGJc7GcGlzU9VrW51wm4ktQl sJA2YG3GOpdwfIWfTHCggaqUka+vtHQnLYvu5XivR3YMymniwf7y6evx5BW4vvAnom+y LF2Q== X-Gm-Message-State: AOAM533vFATkhG1NbDb78goMxsd2xZTDvLlKQL9MsXXh6ZYHP/uEpFrW oYStemTHrbAFwxhTQX4CAz106TbLCnbsyQ== X-Received: by 2002:a17:902:c789:b029:110:4933:71ce with SMTP id w9-20020a170902c789b0290110493371cemr6151169pla.56.1623454921175; Fri, 11 Jun 2021 16:42:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 26/34] tcg: Round the tb_size default from qemu_get_host_physmem Date: Fri, 11 Jun 2021 16:41:36 -0700 Message-Id: <20210611234144.653682-27-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::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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 , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If qemu_get_host_physmem returns an odd number of pages, then physmem / 8 will not be a multiple of the page size. The following was observed on a gitlab runner: ERROR qtest-arm/boot-serial-test - Bail out! ERROR:../util/osdep.c:80:qemu_mprotect__osdep: \ assertion failed: (!(size & ~qemu_real_host_page_mask)) Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/region.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 2e541cd2bf..e1790ce1e4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -470,26 +470,6 @@ static size_t tcg_n_regions(size_t tb_size, unsigned max_cpus) (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) -static size_t size_code_gen_buffer(size_t tb_size) -{ - /* Size the buffer. */ - if (tb_size == 0) { - size_t phys_mem = qemu_get_host_physmem(); - if (phys_mem == 0) { - tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; - } else { - tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); - } - } - if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { - tb_size = MIN_CODE_GEN_BUFFER_SIZE; - } - if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { - tb_size = MAX_CODE_GEN_BUFFER_SIZE; - } - return tb_size; -} - #ifdef __mips__ /* * In order to use J and JAL within the code_gen_buffer, we require @@ -841,13 +821,29 @@ static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - size_t page_size; + const size_t page_size = qemu_real_host_page_size; size_t region_size; size_t i; int have_prot; - have_prot = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); + /* Size the buffer. */ + if (tb_size == 0) { + size_t phys_mem = qemu_get_host_physmem(); + if (phys_mem == 0) { + tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; + } else { + tb_size = QEMU_ALIGN_DOWN(phys_mem / 8, page_size); + tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, tb_size); + } + } + if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size = MIN_CODE_GEN_BUFFER_SIZE; + } + if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { + tb_size = MAX_CODE_GEN_BUFFER_SIZE; + } + + have_prot = alloc_code_gen_buffer(tb_size, splitwx, &error_fatal); assert(have_prot >= 0); /* Request large pages for the buffer and the splitwx. */ @@ -862,9 +858,8 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) * As a result of this we might end up with a few extra pages at the end of * the buffer; we will assign those to the last region. */ - region.n = tcg_n_regions(region.total_size, max_cpus); - page_size = qemu_real_host_page_size; - region_size = region.total_size / region.n; + region.n = tcg_n_regions(tb_size, max_cpus); + region_size = tb_size / region.n; region_size = QEMU_ALIGN_DOWN(region_size, page_size); /* A region must have at least 2 pages; one code, one guard */