From patchwork Thu Feb 15 06:19:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 772864 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp681469wre; Wed, 14 Feb 2024 22:25:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXhN4obljvM8b66/OE/wL0jZ5oiZwFzb5POKvEOSB1repHLNNBG2qJ8gYvWTwRJqGI1psKGrKE5FKvN5oZkVwf1 X-Google-Smtp-Source: AGHT+IE9BwvjrRDoMw8NtY2ZrYnYnjRRz9oQVtVFELuIdZ9iwvRrjOgb0IL+7E+RTRS+XaNQuofw X-Received: by 2002:a81:b71b:0:b0:604:3ee2:f258 with SMTP id v27-20020a81b71b000000b006043ee2f258mr860913ywh.45.1707978345504; Wed, 14 Feb 2024 22:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707978345; cv=none; d=google.com; s=arc-20160816; b=e5FTZRm1GiZsHJbB6GrgBs6/9C+UXia3s21xf5wF9pYuxHnkjfjIuhjq19TGf63GNd Hu+BETbr/pAHEtA5UHuZ9Oalrt2ku7NRJL37dIDhp8a2iSfY+Ar3AgFRwlSa+fWNJ6Bl DhCaAepNAvF5lBAhcO5BJBmbg6WBK6mzGr+XflQH8bgVAWPrCshaNZECkSdUkoFcwGdy e9g8yNO1TviiBQhumQmDGvkGjNnWdXkLTkv2U0QHJ4iLKXfAbC08qECgVaf0PB0UPonD PRgbC8rGC7kXDTWwfEzON0NAWV5bwhYf3gJmAo3m4UTGJij8RLWeCEm1RlM+o1Xt9BPv avKA== 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=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; fh=3DhLlFzAZ2wDtINCbhCKz6cI2CK+co2YCXCK+aMgx2I=; b=k5rzmOO4WL2TT6z2gdJRASycWW+/QwSs+PDMI2pReCGqjZ/rea7usxQMXBFQ0mjlmM dfnyLAXwus5a4CDN8NV8WGyT1e1LrDJLh3dItJOJefk/V+UUEpx4qls/HAY7y3EnM2kK nlynKtaSRVgpYokhUE6y5on9b0BP84t3U40wRjCt3PLzKiCV+iLq91abUij1DwIUT7SO go/lrs54tpz/dmHmV07xsaEh8E21FeelR9XAkLOsWSXkDBvOY7FCRItqGfcvnE7LJdmw XtXipeVUwUmH/a+6SmmdFI8wrteCkwLgY8y9dr5Mq03dSK9W2/ETE9PPtvXhenca5L4V UMdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hMX3/dye"; 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 t15-20020ac8588f000000b0042c7f5297fasi747381qta.215.2024.02.14.22.25.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2024 22:25:45 -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="hMX3/dye"; 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-0002OK-25; 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 1raV71-0002LP-KO for qemu-devel@nongnu.org; Thu, 15 Feb 2024 01:20:47 -0500 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1raV6z-0005VQ-M2 for qemu-devel@nongnu.org; Thu, 15 Feb 2024 01:20:47 -0500 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5cddc5455aeso411631a12.1 for ; Wed, 14 Feb 2024 22:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707978044; x=1708582844; 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=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; b=hMX3/dye6Y3L1T1eAPoMuzPYU25ae4CvShnW2sBb1A99JSfxkzdqbqj7Eeeo1dm0yr SxGgxpoBIJKYNNZMK3Y7yYSOScwEneTuUHdokco+PpCAP538rC02O81ZTTMZm8ABUAdt KWc7xz87Moz7T7Djefvw3meWfkF8ouLDe2H1BpFNy3/J5sRVqYSHE4aqxBHKAaZYLjuM PULxN33iivAgbrw8IxIPqw017lIuf/b5iNdOypgi4EPK2TCMdDdxQUj/kMYNQCt6Q1wJ UqkyaUcOXdUn+8A90nxDR6qdKh6BVMUTJpPHb2JXbwfx9FXR9GkGt51RRN0b2c+PDbIt B5Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707978044; x=1708582844; 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=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; b=SPXXMkqPrITOxv+lYGohi4RgIrXhqVr5x6cm50wBL8ZSx/OhdKj+1443PODDzG8ykT YBj/3poWAniEDWlvi38epfOFMF/KW6ysx3UK3/ATUdn4uuysTJLCu9arHr8XCl7DaVuq sM5dC94BbjogQD0/RdR0Ss/B9kRVb2L18GsTQTNKyRq7fsldoqPWvh0SwrIEuMaPjBfm 5lJVHvL/UWbm40LYZ6Icw3tZFNYcBL6cXNSqVos6chGJfXQc2hQH9tOZdOsWrUoMJsIr EqFx+WtsU3VqE451den0oirC6T8YrHDRVfmQgrLkL0nQJI91DmArmu88S7CdNVkjucVS YcfQ== X-Gm-Message-State: AOJu0Yx4LoIx6IuarlpxWhbbuwjw/WP2gsNPDVtiRKEF8m1HThT4YDK6 ZL6jyZywdWZC/wGrAxof51XBZJlTRTfLWixCM+mIW3ZFX1vwffxKayDDbxXF7mcrXFxdCrfcba7 x X-Received: by 2002:a17:90a:dd41:b0:296:6a37:c528 with SMTP id u1-20020a17090add4100b002966a37c528mr789257pjv.24.1707978044222; Wed, 14 Feb 2024 22:20:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 22:20:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH v4 16/36] linux-user: Split out target_mmap__locked Date: Wed, 14 Feb 2024 20:19:58 -1000 Message-Id: <20240215062018.795056-17-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::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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 All "goto fail" may be transformed to "return -1". Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-17-richard.henderson@linaro.org> --- linux-user/mmap.c | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d11f758d07..b4c3cc65aa 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -490,9 +490,9 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } } -/* NOTE: all the constants are the HOST ones */ -abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, - int flags, int fd, off_t offset) +static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, + int target_prot, int flags, + int fd, off_t offset) { int host_page_size = qemu_real_host_page_size(); abi_ulong ret, last, real_start, real_last, retaddr, host_len; @@ -500,30 +500,27 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int page_flags; off_t host_offset; - mmap_lock(); - trace_target_mmap(start, len, target_prot, flags, fd, offset); - if (!len) { errno = EINVAL; - goto fail; + return -1; } page_flags = validate_prot_to_pageflags(target_prot); if (!page_flags) { errno = EINVAL; - goto fail; + return -1; } /* Also check for overflows... */ len = TARGET_PAGE_ALIGN(len); if (!len) { errno = ENOMEM; - goto fail; + return -1; } if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; - goto fail; + return -1; } /* @@ -553,7 +550,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); if (start == (abi_ulong)-1) { errno = ENOMEM; - goto fail; + return -1; } } @@ -574,7 +571,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, struct stat sb; if (fstat(fd, &sb) == -1) { - goto fail; + return -1; } /* Are we trying to create a map beyond EOF?. */ @@ -601,7 +598,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, p = mmap(g2h_untagged(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { - goto fail; + return -1; } /* update start so that it points to the file position at 'offset' */ host_start = (uintptr_t)p; @@ -610,7 +607,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, flags | MAP_FIXED, fd, host_offset); if (p == MAP_FAILED) { munmap(g2h_untagged(start), host_len); - goto fail; + return -1; } host_start += offset - host_offset; } @@ -621,7 +618,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } else { if (start & ~TARGET_PAGE_MASK) { errno = EINVAL; - goto fail; + return -1; } last = start + len - 1; real_last = ROUND_UP(last, host_page_size) - 1; @@ -633,14 +630,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, */ if (last < start || !guest_range_valid_untagged(start, len)) { errno = ENOMEM; - goto fail; + return -1; } if (flags & MAP_FIXED_NOREPLACE) { /* Validate that the chosen range is empty. */ if (!page_check_range_empty(start, last)) { errno = EEXIST; - goto fail; + return -1; } /* @@ -671,17 +668,17 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if ((flags & MAP_TYPE) == MAP_SHARED && (target_prot & PROT_WRITE)) { errno = EINVAL; - goto fail; + return -1; } retaddr = target_mmap(start, len, target_prot | PROT_WRITE, (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) { - goto fail; + return -1; } if (pread(fd, g2h_untagged(start), len, offset) == -1) { - goto fail; + return -1; } if (!(target_prot & PROT_WRITE)) { ret = target_mprotect(start, len, target_prot); @@ -696,14 +693,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* one single host page */ if (!mmap_frag(real_start, start, last, target_prot, flags, fd, offset)) { - goto fail; + return -1; } goto the_end1; } if (!mmap_frag(real_start, start, real_start + host_page_size - 1, target_prot, flags, fd, offset)) { - goto fail; + return -1; } real_start += host_page_size; } @@ -713,7 +710,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (!mmap_frag(real_page, real_page, last, target_prot, flags, fd, offset + real_page - start)) { - goto fail; + return -1; } real_last -= host_page_size; } @@ -739,7 +736,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, munmap(p, len1); errno = EEXIST; } - goto fail; + return -1; } passthrough_start = real_start; passthrough_last = real_last; @@ -773,11 +770,22 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, qemu_log_unlock(f); } } - mmap_unlock(); return start; -fail: +} + +/* NOTE: all the constants are the HOST ones */ +abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, + int flags, int fd, off_t offset) +{ + abi_long ret; + + trace_target_mmap(start, len, target_prot, flags, fd, offset); + mmap_lock(); + + ret = target_mmap__locked(start, len, target_prot, flags, fd, offset); + mmap_unlock(); - return -1; + return ret; } static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)