From patchwork Thu Feb 15 06:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 772866 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp681527wre; Wed, 14 Feb 2024 22:25:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXtpJjqGlDXQ2lHwbZEiaIG9cEQnSP96ddHKxhCm68EzpXJYegQx5zmPRUSYpBAa5i18UMNb78aF4NmEwK/Kb6G X-Google-Smtp-Source: AGHT+IGMWzPfw56MIpgqG8aSKVOAC7nzc1y3GT/akLTrvo90PElwkbhOQvr6QnW+j7vwWejZtfe4 X-Received: by 2002:a0d:d88b:0:b0:607:9d64:d68e with SMTP id a133-20020a0dd88b000000b006079d64d68emr852097ywe.26.1707978357959; Wed, 14 Feb 2024 22:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707978357; cv=none; d=google.com; s=arc-20160816; b=AIyqhsKqTHag/zmNViQx+XL6lMi5xzMfukgPlVokeFkuJKsYJ0tquh8PAKkCweevFu bkhwE+Qodiw9hiq39bl+VwYF4ShdgBZG8E5NxoEsoC+vQHb/Wk7TmgXOxHyiVRkPMIxI WNUnE4NMI/fOI+TtxuDhmMweOiM73EIPqAitvYTdp5Ew7Tn41v9oFWb4Gp1VdlBwksvY aTqlDyJsPPH8go808V93Xp3jvnU1kc9TUS8SzqDTztjua4wJR6exjoW3mIurGXPIxpVX Ui9t+WeEXjaiU6huNOoin+tVC+BWAs3KkUNHCNDSsENon7lTHDY8xU1n2TBekkHSFhpp OBsw== 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=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=yapMB/ZWC6aHy9rOfD9su36/HH2Q1vcr8WLaPyQxAcV/5xLt0YbxOarc35aW/TbR1O eDm9KRZf+1ZX3Q+exBfqAswXPdlOeaRo/5GNM09zAoqvlZZO1icwpE+wKbovPDZjZT9U kjU4On0znmy+C1Zp3M31+r9gbmE8/ud+3sWbqywb+003jVBFpVO+XN2GONunyWJqc834 hnTkDoV2VADzX558Lx4K7nu4SR4xwTzYwbJbTNCKH1PO8O2DwGH4nBVoMOK/vcyKc33q MMsvRrbsxKe4/SPCynwXzplhyY8vIe7EJcf4gUTxO9Hpkqwc672xj6GR5IcFIg/iQnAN AwNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YLx2hBbN; 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 a2-20020a05622a02c200b0042c4b0882dbsi734669qtx.701.2024.02.14.22.25.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2024 22:25:57 -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=pass header.i=@linaro.org header.s=google header.b=YLx2hBbN; 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 1raV78-0002Oa-7p; Thu, 15 Feb 2024 01:20:54 -0500 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 1raV75-0002NK-W5 for qemu-devel@nongnu.org; Thu, 15 Feb 2024 01:20:52 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1raV74-0005WV-0o for qemu-devel@nongnu.org; Thu, 15 Feb 2024 01:20:51 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so472684a12.1 for ; Wed, 14 Feb 2024 22:20:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707978049; x=1708582849; darn=nongnu.org; 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=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; b=YLx2hBbNTAcc2lkKvVj7S/7psvZupK5l5Idvj8nUz1B6eK6uS3jg33zMykD9YxPIlS O7RWo69eldz6OBG0A+/8/U1Me9lOxVe7ehFNnK/I8tATvIkAVfjJKJVW0zBE4IvqWoE8 fFrz8objzloX6GHOQF13dK9UCh/kPiBGPCCKHdS360X9+9pAdaoRAl6H42NDCZsapk5y 6qjTIqD76VyjEnCkVdrn+RIk7YYUNV0VW60+grOgL3uVgUp08icXnIi/I9wFF5g4dGak aeheE6zLB0vWefsLY3EQHgIxOmFTlOD5/aS7mmMrkv/uz1R+GehIKVhQFsV+NUR59kSO dW7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707978049; x=1708582849; 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=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; b=ZZaEFlPgDcscVFOpJ/46zdSxJHdmFj1+mR/S0YKkYGKVFhjAKlZz+uDYUPAqCDx4F6 9UfXQnoI6A3fIpf7a5V0NrAbyyaRms/WU2tOggsz9FJMvztiu+SEwIm/501oYctNBuJ4 TjIKaWTNwAAwoZNl0azxhQNAQDTZo1C2LvRm4473l9w7aFJfL87MHaHvBHD7YYxn/EvM DHcRFR7GGMC9/fLFODKTSd/Cv8ZAjWfBz0sZAAZYwuXBafS4qCoF5oIoFthpiF2lUHt4 Mr8JRo3CM+zdx3p8KGN8FTIE+oznlDu59K4IZeuSnjxhzwq2yoQtokkF2vS8x5dfsOaw H3DA== X-Gm-Message-State: AOJu0YyifhHRhWgmNRT1UYwjbx2c3of8WQOJFb17n7HVYqQMqZ68+nI9 G0+AK0eWT0m66eBHDazhlv4WCvqeI0VXoiFDRSoeaa0UOwyQgrgeh8Ij1ltLgvlLb4uGmVKvZ9n c X-Received: by 2002:a17:90a:d301:b0:296:2afe:25e with SMTP id p1-20020a17090ad30100b002962afe025emr892906pju.32.1707978048754; Wed, 14 Feb 2024 22:20:48 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id d5-20020a170902b70500b001d6f29c12f7sm464418pls.135.2024.02.14.22.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 22:20:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH v4 19/36] linux-user: Split out mmap_end Date: Wed, 14 Feb 2024 20:20:01 -1000 Message-Id: <20240215062018.795056-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240215062018.795056-1-richard.henderson@linaro.org> References: <20240215062018.795056-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use a subroutine instead of a goto within target_mmap__locked. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-20-richard.henderson@linaro.org> --- linux-user/mmap.c | 71 +++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 48fcdd4a32..cc983bedbd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -490,6 +490,43 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } } +/* + * Record a successful mmap within the user-exec interval tree. + */ +static abi_long mmap_end(abi_ulong start, abi_ulong last, + abi_ulong passthrough_start, + abi_ulong passthrough_last, + int flags, int page_flags) +{ + if (flags & MAP_ANONYMOUS) { + page_flags |= PAGE_ANON; + } + page_flags |= PAGE_RESET; + 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_last, + page_flags | PAGE_PASSTHROUGH); + if (passthrough_last < last) { + page_set_flags(passthrough_last + 1, last, page_flags); + } + } + shm_region_rm_complete(start, last); + trace_target_mmap_complete(start); + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + FILE *f = qemu_log_trylock(); + if (f) { + fprintf(f, "page layout changed following mmap\n"); + page_dump(f); + qemu_log_unlock(f); + } + } + return start; +} + static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, int target_prot, int flags, int page_flags, int fd, off_t offset) @@ -632,7 +669,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, ret = target_mprotect(start, len, target_prot); assert(ret == 0); } - goto the_end; + return mmap_end(start, last, -1, 0, flags, page_flags); } /* handle the start of the mapping */ @@ -643,7 +680,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, target_prot, flags, fd, offset)) { return -1; } - goto the_end; + return mmap_end(start, last, -1, 0, flags, page_flags); } if (!mmap_frag(real_start, start, real_start + host_page_size - 1, @@ -690,34 +727,8 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, passthrough_last = real_last; } } - the_end: - if (flags & MAP_ANONYMOUS) { - page_flags |= PAGE_ANON; - } - page_flags |= PAGE_RESET; - 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_last, - page_flags | PAGE_PASSTHROUGH); - if (passthrough_last < last) { - page_set_flags(passthrough_last + 1, last, page_flags); - } - } - shm_region_rm_complete(start, last); - trace_target_mmap_complete(start); - if (qemu_loglevel_mask(CPU_LOG_PAGE)) { - FILE *f = qemu_log_trylock(); - if (f) { - fprintf(f, "page layout changed following mmap\n"); - page_dump(f); - qemu_log_unlock(f); - } - } - return start; + return mmap_end(start, last, passthrough_start, passthrough_last, + flags, page_flags); } /* NOTE: all the constants are the HOST ones */