From patchwork Sun Aug 6 03:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710881 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826514rwb; Sat, 5 Aug 2023 20:40:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw2081YTY1YjBtQxpHE7b27y1b5ajRj1Gat8V4LM8heLugZfKN8O7TCXHgVKEjmarGHyNB X-Received: by 2002:ac8:5702:0:b0:403:fb43:bcb0 with SMTP id 2-20020ac85702000000b00403fb43bcb0mr7218038qtw.46.1691293232811; Sat, 05 Aug 2023 20:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293232; cv=none; d=google.com; s=arc-20160816; b=mPe4ihBnY2CaVQtfE08d0gb33OCxsvjnMdr+HgTPYA/DpKjcbNZjvYakTqDSEe2a6m pwfZNjRInsZ6J+CmZggacv26umnOXerM9eqp7dsHYFcNIdJCErP0JDe+GL0JhnPUztX1 3Scfef+A+Hp1iBO6GxUpuaAdODSCyLSgjoI/T6ex27sV686MDbPiKghJizOAo7nAlfYl uiZDfLkRGYGT4vCoDdaOh155/gg4adr7rPS6JLQl0PKeqNH3uBfxBkyvacxxRKr49zDY TXGzj0n+N1tbVv7g42X+lj+BhEFi9XRrow3Nr3nZponHLxhJeFZA/ORvnTSAi/wvAFNP EqVQ== 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=Yujg3V7xJEHPzV6u/xblO5HGt3PxnHg8rSzm7XHfvFxsboqr3B+bIqMMlZ6lXwo9/g lqS/by8e6sv+X4hoDaOTgwNfBAZP0SZ57C4dgeifUVUVJZUC5AkR1LDNTkURjQ7/68u5 eclZoL8TUBl14JfNze3Jgn2LZpeTAnV4M9A4dMrS9hfecsKv0kqORRRnA5hS8/YpVgZ5 Vyqe6S14/H0rXH1CCEIsTDt7nZeOHDneMMKMxrpZ1mq1UNwdjoTmg9jQdikVIPDRqtgL B1vbz4JFTTrrGiVM1UclVZEsw7qOGFFkwoBtjMBcTHYFzTpBAazDWLxnjfD4dKnDifTF n5sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hacv99Wm; 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 o15-20020ac87c4f000000b0040fc209cc9bsi3337122qtv.1.2023.08.05.20.40.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:40:32 -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=Hacv99Wm; 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 1qSUaH-0003jc-M5; Sat, 05 Aug 2023 23:37:37 -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 1qSUaG-0003j8-LU for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:36 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaF-0007ay-3Q for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:36 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2685bcd046eso1672424a91.3 for ; Sat, 05 Aug 2023 20:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293054; x=1691897854; 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; b=Hacv99WmJ9BnWfmFp/KhMmwj27f+9kUpj9WVeOdQwkjTRsabZU+Z8OKIraTjTaCJt4 oERBS4vAQxs/RzbtQiG5IsNLPvSEkWzdtDkX1sHwSTFAXRmtKRZNjVi6HZufhiva7OCq sfSd827Gt9D+lY5ZwCnDaIRJSMPbqLt5WCQGOlcr4v8hA1gZ16Z5k9iDbU0LDNDSiw29 EzZ/MuekqQr1Z/kJaMjeuzTSrKstVkuzSqRWG8qR+2Wq/fG6VJnIN/j8S5UpBawWje0m 9o7X/q1mmccpACQc4l/cf30RnxM6F3JFZnBhz9qwFhvbUXVuCVP9i/pbKUfwaycAdVv6 0JYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293054; x=1691897854; 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; b=CL92eM0R6lmEE1m+Tt3OMRH0zviwnvB0LchPUODD/pd2uHWPWd4tN9PflIQfGb3vuy 7ey9NC5LIZimwukM7CG6UO8bh49NPtUy8HXVo6uUHLRLSxsU336SKN1xaE8kkxkjly7P HMtygs1PD5c097+/6ebyeog9jzLJT8q1BmE2csPJ5Je88OMl4DmvbDFzl7RIYAXc62as QvDfVgD5W6vtsnDZa3Qb9qQmBscBMDI1mDoxbJ1Jfu2zThhGGDgpuHgaKnLGtyQ5jOF4 TjtqtdRwUuSz2EVG1FJd62Q4MjO9DSlii9eGNsGAikrUIRWTNq9G1HGZEKrs7Rgzz/P6 tgIQ== X-Gm-Message-State: AOJu0YxUbP7QQ2kw/JfVrstC/i01vNaND/aYijzKeKXIff9WlG6Y4jDM Pwj8tsLi21gKAAwlVFm9rqfOasalUBXyXFnEoVk= X-Received: by 2002:a17:90b:ed4:b0:262:df91:cdce with SMTP id gz20-20020a17090b0ed400b00262df91cdcemr4447858pjb.23.1691293053748; Sat, 05 Aug 2023 20:37:33 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 21/24] linux-user: Do not adjust zero_bss for host page size Date: Sat, 5 Aug 2023 20:37:12 -0700 Message-Id: <20230806033715.244648-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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.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 Rely on target_mmap to handle guest vs host page size mismatch. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 54 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e853a4ab33..66ab617bd1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2212,44 +2212,36 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, /* Map and zero the bss. We need to explicitly zero any fractional pages after the data section (i.e. bss). */ -static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) +static void zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) { - uintptr_t host_start, host_map_start, host_end; + abi_ulong align_bss; - last_bss = TARGET_PAGE_ALIGN(last_bss); + align_bss = TARGET_PAGE_ALIGN(start_bss); + end_bss = TARGET_PAGE_ALIGN(end_bss); - /* ??? There is confusion between qemu_real_host_page_size and - qemu_host_page_size here and elsewhere in target_mmap, which - may lead to the end of the data section mapping from the file - not being mapped. At least there was an explicit test and - comment for that here, suggesting that "the file size must - be known". The comment probably pre-dates the introduction - of the fstat system call in target_mmap which does in fact - find out the size. What isn't clear is if the workaround - here is still actually needed. For now, continue with it, - but merge it with the "normal" mmap that would allocate the bss. */ + if (start_bss < align_bss) { + int flags = page_get_flags(start_bss); - host_start = (uintptr_t) g2h_untagged(elf_bss); - host_end = (uintptr_t) g2h_untagged(last_bss); - host_map_start = REAL_HOST_PAGE_ALIGN(host_start); - - if (host_map_start < host_end) { - void *p = mmap((void *)host_map_start, host_end - host_map_start, - prot, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { - perror("cannot mmap brk"); - exit(-1); + if (!(flags & PAGE_VALID)) { + /* Map the start of the bss. */ + align_bss -= TARGET_PAGE_SIZE; + } else if (flags & PAGE_WRITE) { + /* The page is already mapped writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); + } else { + /* Read-only zeros? */ + g_assert_not_reached(); } } - /* Ensure that the bss page(s) are valid */ - if ((page_get_flags(last_bss-1) & prot) != prot) { - page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss - 1, - prot | PAGE_VALID); - } - - if (host_start < host_map_start) { - memset((void *)host_start, 0, host_map_start - host_start); + if (align_bss < end_bss) { + abi_long err = target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (err == -1) { + perror("cannot mmap brk"); + exit(-1); + } } }