From nobody Tue Feb 10 11:14:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1689429805; cv=none; d=zohomail.com; s=zohoarc; b=M5EaR5YFbVhS5u7/AmQUXTRDGGVbg6KVlhRW6T5f3vUjdH91FVykXYHCFFTCgftV2z5YMMp14lZjqA4FdYm75Yi8L9usYvgR24TEJQOc0EH2AhYppIDy4vBlKxSG/xd8EaBd5hZ72yiBN8VL5OBq+jnCufO8JyBpkU0pOrUGu2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689429805; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jfvLV6T2p9fP56/v/Xia6iQ7yK2dQ6zBkNiykDOKhfw=; b=eGel2twCgSnMrq9j6xuEOAbak31W76CCpk1zMDOrZ0ZJeDJdEDQXQesGWg2FSLB4hbOdo+4Qkl13QuSMK9sEFNyLOjRKAlB/c9HuPFGQ/4Sl9uPJMZcXNXVAcosQhRmHdD896ZpkB71QFGfwNkK0eiOQRhqDMZCDdordh3g2Q2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1689429805445694.9829743579633; Sat, 15 Jul 2023 07:03:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKfis-0004Ea-Dr; Sat, 15 Jul 2023 09:54:10 -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 1qKfif-00049O-Ch for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:54:00 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKfiX-0001Kb-JH for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:54 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3110ab7110aso3044055f8f.3 for ; Sat, 15 Jul 2023 06:53:48 -0700 (PDT) Received: from stoup.lan ([51.219.12.49]) by smtp.gmail.com with ESMTPSA id k10-20020a5d66ca000000b00313f9085119sm13838014wrw.113.2023.07.15.06.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 06:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689429227; x=1692021227; 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=jfvLV6T2p9fP56/v/Xia6iQ7yK2dQ6zBkNiykDOKhfw=; b=EMQyNSaeIKeDjVFlaVD5gqYRd55tk+AR81ac1OEKLIKnmiUvIb0xX9oVRez+CgM8NC xNnQkgiPfbsL0cKC+eJRVn8ON5pi6jh1MBH1tpM0NB9485xXe2hrwuDzsJ/JMGXRJkYb vlQphrJbOXT5RB8FkrSdlbxweMEpcwlh38UVd0kVsyR39n4JT10rBub3z9V6AZYlahgt S0O5DJl19Wb9dUelScpBh0bL4hCE4bEmMXKs/nnC/rJpa6wsWnDV/qULyXzQQoPpbvKQ ASp9GG0ahV4n5php7HBCBCJ0rxHqCk0YfaMGjsAbxvLfSgDb8AoyMjD5Brgp8D3bTVjy AjfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689429227; x=1692021227; 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=jfvLV6T2p9fP56/v/Xia6iQ7yK2dQ6zBkNiykDOKhfw=; b=RP22RhbOWUbkrhiMk9JDuCme8FOv2AIPzwzt7hXI+8f7XwmenR/ExfiFnkPSJF/qoI Oe4wG34q1xwtbbRM2oMiOwJqNFaS4omExysW1sofKikLTfaw4FAFAf4VOOml//2qa5wo Ma5RHi7RK9MLfyrS968ZgZ4DVPYROW8HVQ7L9OfJy73c487gvZ3DfISIydCpQ7oo77Xb +LxiXOR0zsgoaiUJvjfcVOYKWvJ565N3aOTg3I1r09xiBymAblSnSgcOBkd0s8ecc0gf eofDgdynGWUwdgWVtssNB9mh0f8SEofiMlJSYhpFacFSSaXhnTxi7CASAg+IHUjr61Ez Z73w== X-Gm-Message-State: ABy/qLYQ9MBhF8oBRisE5M4c0wGiqOmIuQQtlhYThCRLQrIw2DuH3zvB htscNUEmHWiHuOd4FNplp2lptUXT+CCEXAVTGMCHeg== X-Google-Smtp-Source: APBJJlE/DwK53V37TtkYSQjc3adoVzPqzNSyPMQAQJdfbdlCgyqqSq3tOc8oahHwv19lEE6QKZYpYA== X-Received: by 2002:a5d:5651:0:b0:314:3a3d:5d1f with SMTP id j17-20020a5d5651000000b003143a3d5d1fmr7217201wrw.19.1689429227461; Sat, 15 Jul 2023 06:53:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 36/47] linux-user: Use 'last' instead of 'end' in target_mmap Date: Sat, 15 Jul 2023 14:53:06 +0100 Message-Id: <20230715135317.7219-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230715135317.7219-1-richard.henderson@linaro.org> References: <20230715135317.7219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1689429807277100003 Complete the transition within the mmap functions to a formulation that does not overflow at the end of the address space. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20230707204054.8792-20-richard.henderson@linaro.org> --- linux-user/mmap.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 738b9b797d..bb9cbe52cd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -456,8 +456,8 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size= , abi_ulong align) abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_len, - passthrough_start =3D -1, passthrough_end =3D -1; + abi_ulong ret, last, real_start, real_last, retaddr, host_len; + abi_ulong passthrough_start =3D -1, passthrough_last =3D 0; int page_flags; off_t host_offset; =20 @@ -581,29 +581,30 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, host_start +=3D offset - host_offset; } start =3D h2g(host_start); + last =3D start + len - 1; passthrough_start =3D start; - passthrough_end =3D start + len; + passthrough_last =3D last; } else { if (start & ~TARGET_PAGE_MASK) { errno =3D EINVAL; goto fail; } - end =3D start + len; - real_end =3D HOST_PAGE_ALIGN(end); + last =3D start + len - 1; + real_last =3D HOST_PAGE_ALIGN(last) - 1; =20 /* * Test if requested memory area fits target address space * It can fail only on 64-bit host with 32-bit target. * On any other target/host host mmap() handles this error correct= ly. */ - if (end < start || !guest_range_valid_untagged(start, len)) { + if (last < start || !guest_range_valid_untagged(start, len)) { errno =3D ENOMEM; goto fail; } =20 /* Validate that the chosen range is empty. */ if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, end - 1)) { + && !page_check_range_empty(start, last)) { errno =3D EEXIST; goto fail; } @@ -642,9 +643,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, =20 /* handle the start of the mapping */ if (start > real_start) { - if (real_end =3D=3D real_start + qemu_host_page_size) { + if (real_last =3D=3D real_start + qemu_host_page_size - 1) { /* one single host page */ - if (!mmap_frag(real_start, start, end - 1, + if (!mmap_frag(real_start, start, last, target_prot, flags, fd, offset)) { goto fail; } @@ -658,18 +659,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, real_start +=3D qemu_host_page_size; } /* handle the end of the mapping */ - if (end < real_end) { - if (!mmap_frag(real_end - qemu_host_page_size, - real_end - qemu_host_page_size, end - 1, + if (last < real_last) { + abi_ulong real_page =3D real_last - qemu_host_page_size + 1; + if (!mmap_frag(real_page, real_page, last, target_prot, flags, fd, - offset + real_end - qemu_host_page_size - start= )) { + offset + real_page - start)) { goto fail; } - real_end -=3D qemu_host_page_size; + real_last -=3D qemu_host_page_size; } =20 /* map the middle (easier) */ - if (real_start < real_end) { + if (real_start < real_last) { void *p; off_t offset1; =20 @@ -678,13 +679,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, } else { offset1 =3D offset + real_start - start; } - p =3D mmap(g2h_untagged(real_start), real_end - real_start, + p =3D mmap(g2h_untagged(real_start), real_last - real_start + = 1, target_to_host_prot(target_prot), flags, fd, offset1); if (p =3D=3D MAP_FAILED) { goto fail; } passthrough_start =3D real_start; - passthrough_end =3D real_end; + passthrough_last =3D real_last; } } the_end1: @@ -692,16 +693,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, page_flags |=3D PAGE_ANON; } page_flags |=3D PAGE_RESET; - if (passthrough_start =3D=3D passthrough_end) { - page_set_flags(start, start + len - 1, page_flags); + if (passthrough_start > passthrough_last) { + page_set_flags(start, last, page_flags); } else { if (start < passthrough_start) { page_set_flags(start, passthrough_start - 1, page_flags); } - page_set_flags(passthrough_start, passthrough_end - 1, + page_set_flags(passthrough_start, passthrough_last, page_flags | PAGE_PASSTHROUGH); - if (passthrough_end < start + len) { - page_set_flags(passthrough_end, start + len - 1, page_flags); + if (passthrough_last < last) { + page_set_flags(passthrough_last + 1, last, page_flags); } } the_end: --=20 2.34.1