From patchwork Fri Mar 1 23:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777083 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601730wrn; Fri, 1 Mar 2024 15:09:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWCmPXNu6mKKvOaYBHuiPgLG1Ze/9VGeehGViSIWFZS+7jMT8hGwgwDdqJc8iKXKFcP3fZRaY5dl6l8Yz54vi0u X-Google-Smtp-Source: AGHT+IFNIpAn0G1Tcqm04uCK/c8WA3ML6o9K2/+zo2scSCoyV0x8Rvx08+gCwaqX200jeFcjuCoP X-Received: by 2002:a05:620a:4081:b0:787:f8bb:9684 with SMTP id f1-20020a05620a408100b00787f8bb9684mr9154012qko.15.1709334592231; Fri, 01 Mar 2024 15:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334592; cv=none; d=google.com; s=arc-20160816; b=BV3I9h5Muv3IJLcUBMVQuAqwF8RldfqTSlCcObrNYj6lx2zT5ptLQhSc1eZaQ77puV KzI7TFT9ugUI1PmqnhzsCQ6akABt9M26wjjZ6jOHCcYcf28t8OHoHO/kowg1Q4whwTo3 dz6AcWra7aN1OOdpq/nkRK6yR+R6wENjPnbyl+FiWj5JW6OPhu6cexVzjOt6OnuX+8Y1 8Xyn3j7kW2M8XshV7KpZHOUQxzNhlVfNQWFVCsGdScl0jMA4RrqtVe3IL0BnJxOwOhh3 ryIp4S+ri+RVyoL5pMbIRBkII7RAeV0Gl61cppE+n4uJrMY+Zvh/FP8C0DnFo31YqEXF pcvA== 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=lJWeD4oFAjwWuG+9v5sfY1mwUaQM2C1n+xiiMkGDpyn08KK7tikAoGAAlFqQ4O/piG FowFArfGPcXAGfXOQwlXrabs87+zqcilyyU+b6Z3Ldiz83YYle9B7r9LYHFfWI0MwRpj jksvUkT+JcFX+UT8KRqc754XcsSoQyzvz5cLxzgVu+Hi3lKgcwCqPZOFb6J32lXBGDNm quqvshIvCunoPj/3eR9ys+wRGCp0QmPNPle3Ei7zJxImZATa1qVLKDBJzkMimGD887Ne Y1eFeF2sodm6mDhnwa+6mDsWl+YdDw+15Lct3Tq+iYRxE1kte+irUjr67QgLKqyIb9U4 C5Vw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1eiqbP6; 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 g17-20020ac84dd1000000b0042e5cc2f064si4238641qtw.616.2024.03.01.15.09.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:09:52 -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=B1eiqbP6; 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 1rgByc-0006Xh-PM; Fri, 01 Mar 2024 18:07:38 -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 1rgByJ-0005kc-F4 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:21 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgByH-0004P4-FL for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:19 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dba177c596so18019145ad.0 for ; Fri, 01 Mar 2024 15:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334435; x=1709939235; 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=B1eiqbP6pDd9G29r5L8rr75Dl/dpLhfHlvQblYbHHgLqMa46UrkL5/1012J5DmHG7B Ei6bzb3QTwcyNxBTVSHDtuREMjsRc0V0KJf6l+l235P4zOwdJxaSMX+TMRuDd4GR4lH1 FV/5q2jksOLvB/Qt30Oz4foEfD/HgW81CcUElMN6fRznuH32Q5OCvP4Lt5igA+Y71zhA IRim9lDR7p6/FWsA+32kPWx7TFstl4SV30JLc+KCeA9Zxc52RqeM6MMx01jtcpxFDQR6 Ruyo+IU2SaikYVXneqRrIdlpvIsI5zvj1eCNtgT8lvVRyJDB3f6WQGlHfmFmSHujezNy N++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334435; x=1709939235; 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=a6FIeUPtN/Usl0irXwW8+CMYK5jBGTERVlj25N+RXIWmXQZtvx1jwLpaEpBvcOnDH7 SoMOMrVVPI1SPg2NgtEnvH7zZX8GQYPubpnSg7sahOKGDuGkQJkNR11+KoWlnVhOOhbu 8W0DX9G5ucCAlb5bwQXr2fCFLxr2RqR+ZGE2Xsi0eXCpmwLtB35perM0fm21+aEMJ0ZK gabQQfdfxyKid+ECG09X2cU4PQBD6F1zG2UlDLJrB1UIdnNzPK8goa1rLXEYVGwhN3Q3 DD5ahFGVJGaVWO85O/ngQ6H4TlSEMH0y5fZMKQqiz5/gGeEykBK9OWPgx5HfgMEGJ854 0rSg== X-Gm-Message-State: AOJu0Yzsn8aKmiAH7dNYJLNtcGNHYJXfsl7NsBAh70+PmKJUmEQ1A7mj 53kWx2QxHXqYySuiDvihnvqHc1Zt9x1IwbzYV4p6Unnw1nrhsq9T7WuaPXmCoym2c3//xaQeH+5 F X-Received: by 2002:a17:902:da81:b0:1dc:cdd7:a056 with SMTP id j1-20020a170902da8100b001dccdd7a056mr4755978plx.0.1709334435733; Fri, 01 Mar 2024 15:07:15 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:15 -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 37/60] linux-user: Split out mmap_end Date: Fri, 1 Mar 2024 13:05:56 -1000 Message-Id: <20240301230619.661008-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 */