From patchwork Fri Mar 7 13:09:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 871183 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp757471wri; Fri, 7 Mar 2025 05:11:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVKUKudXldpFnnCMa/mEJDbouW1DqIIiubf9U7KF4sn00ablrYYpfyva+dT8OInoS+nBQIf6g==@linaro.org X-Google-Smtp-Source: AGHT+IFaXdCVDGH0Tfn2/sz1EuqB6DYDLstF9DtIEmC31SsIosdMlDdoK2YPM0sglHx5FnoQvb4Y X-Received: by 2002:a05:620a:8802:b0:7c3:cc32:2c50 with SMTP id af79cd13be357-7c4e61138c2mr513970785a.34.1741353090527; Fri, 07 Mar 2025 05:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741353090; cv=none; d=google.com; s=arc-20240605; b=TnnrO3zicEllj7UK1Fd9rdH0X05+ddKr5HJraV+brYyd0V5ZbZiJtkamJN7cHVXlUk jMhwyfPZHMWvOtj1eiOCdZGsRtxTT+1WXY2OgtO3ucRYvqCG2FsSa2AJr4lo4ydrmP0Q VwkWoCZWkSMicOHbjTcGnAm/U9fjv0SfmSS6903lqA/EljhLN83z7GCHNPOyBAQLdTwd agwX2v/MD44shwKKIw5J0V/U4qsgi/EyOD1varduNjhHUz2irxtIbXzQ9pa2o1hCJgP9 sP1OfPefsmrVBkbon9Z8Q9gc3idqr1ofpk2avEdQ99oP+4DYTi1vEtSnnulsvyGZ6j9v UBTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=+zbc6tMUo3di/HoycSLWx0Ju1YVVknJoWV3wLdfwDGE=; fh=YwzZLqTkl/aXI2kmXKm3J+muCZNvgKu6t1Htrn0AL98=; b=ORepAzcAbgBIgntDUs2/3gknm5LEdd+ZVdn8yani9OsPUf87p1YVo8EY96R2EV7WIQ wEfGpAZZPEwaAfdjMaCIcFwSxn3ymvl4O5RZS316tM8oumfeEtW4bzMsErgeqdf3a+bt X4T6jZzwfLJKYt+jYQjazm652qP+m60WooOx5hFW9HrFV0QCEzFQAKlWrZC4UL4jpNoK XZzmEyl/tOEjVPJPWCVd8le+Y12pjA0sQTYExbigSNQVx7zGoPTxnI6uoLTcmdX9CgdG LCTgHLoGOetShefHxlnKWtDRXTpHuvvRipYY4ycAWTWf9YaaK8NLBqkzcPeHih6sIh2H s7Zw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kbBJNw1a; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c3e53393f7si333594185a.129.2025.03.07.05.11.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 05:11:30 -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=kbBJNw1a; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqXSo-0002lr-PD; Fri, 07 Mar 2025 08:10:06 -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 1tqXSj-0002i3-DB for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:04 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqXSh-0001Fs-Pr for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:01 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43690d4605dso11201975e9.0 for ; Fri, 07 Mar 2025 05:09:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741352998; x=1741957798; 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=+zbc6tMUo3di/HoycSLWx0Ju1YVVknJoWV3wLdfwDGE=; b=kbBJNw1aY08EoIaB+MPJ35riK7zxM93i8AaPhjzedO1eiEIEc0a3mxHJMxLQp9/ByD YzA6kJ6DTckDO8HYKpo0x+5BSArRctY2JvK1b6U4hZj2DmedmZcOnco2zSpabMvXF5KN MGr6vEJWFCT4LXfGixlvQAaSpooRZKXvTvVDBWE9FeyQ1TirGAgsCumtBrrhHE/fz27s XK2P4jlY4lgJ7mZujJTWLOs1M4Pbird1JGOOtKE+ic//0iBtq/wDs0Py2pJjskv7A+c0 XOEbK3Sc+x6Vm9c6NSgpNMGgNYmFm6LVx6OGbYDkA75sfeWvE1QQuGUoMAFGBKq+8fv/ 08BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741352998; x=1741957798; 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=+zbc6tMUo3di/HoycSLWx0Ju1YVVknJoWV3wLdfwDGE=; b=WMn8yQWXPVlTM9qy4DlHceRIsNoCXHtBjtx44adXXF8vLf+X8ttxBuBjF84DUPwMR9 /+7i6Vdw9KguEcb6HizP9PDCSVLe9tVOP3of83ySZJjL4dqqdH+oi5E6MkGwZYVgwQxx nW4f4FON9sEIy4kFQxoM2c2QJqfbzUUBYgGKw/dEbjoqeoeI8jgCDoFgbtXgKv9YtB/e w1VtzgLBeLiyx724AcAPtqO96TZwzlEMkKYm9p7EgENRAMOFMIyPBQYsQ0AFnaH8HnWU MUG7uVjaWhHAZ95+31hbnTCBClPWBZISV0mXAHJcUWwhmu0HYzxKBSyFBUPOZVlezuOr 0m+Q== X-Gm-Message-State: AOJu0YxwPB4/ofZ6HY5/NQ5UUrWgT/j3OgD4NGRgUpiun5l8Nh/AK0qx jerW2KKG2r8cC87C9S3qsyyqPZhGZzQIME5Z799aRjJJ5ovAh1a/R9yoFjE3JdQJUaZG5FA5Uit O+C4= X-Gm-Gg: ASbGnct8B2VUctcwqbmRcz7IlQOotTWan3E+8FgTalVKu7Huw3F2IG2wpMl/7H/58oy sXC62b84BIrRiCkBgPiIzinIwroMMLChqrIxA11FkZGOCRw6hg7pyZ2V2ASQE/JTUYlag3cs08c P+6NbNi0jiwWBVXmfgMXPL3gynIZSTDCqkTro6OfA4WXFjTVeVkUILx32xTUaWn0R/WxE7Qb9Cw wLBwIUVFvpvVf7VWR+s6fYhhxHgj44hfkj4Gvb6kbmjSXeKGKCTsiFeiKakaqqh8uo2ZyHsYt8Q 7e30n/RqZcsV5miG84yBazBBd0Anv+BOfUH4RoCaqx8N6RgkDmy50uy84EP22dc+F9sZjArPmdC OAz/frVJprj7fXz87jAA= X-Received: by 2002:a05:600c:198b:b0:439:b7e3:ce56 with SMTP id 5b1f17b1804b1-43c687027f5mr22709405e9.29.1741352997660; Fri, 07 Mar 2025 05:09:57 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43bd91338cesm69681285e9.7.2025.03.07.05.09.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Mar 2025 05:09:57 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Riku Voipio , Kyle Evans , Warner Losh , =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/3] bsd-user: Always use mmap_find_vma_aligned() in target_mmap() Date: Fri, 7 Mar 2025 14:09:49 +0100 Message-ID: <20250307130951.4816-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307130951.4816-1-philmd@linaro.org> References: <20250307130951.4816-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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 Massage target_mmap(): calculate alignment once, then unconditionally call mmap_find_vma_aligned(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/mmap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 346f2cefd32..28d7e387a20 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -489,13 +489,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, * before we truncate the length for mapping files below. */ if (!(flags & MAP_FIXED)) { + abi_ulong alignment = 0; + host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); - if ((flags & MAP_ALIGNMENT_MASK) != 0) - start = mmap_find_vma_aligned(real_start, host_len, - (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); - else - start = mmap_find_vma(real_start, host_len); + if ((flags & MAP_ALIGNMENT_MASK) != 0) { + alignment = (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT; + } + start = mmap_find_vma_aligned(real_start, host_len, alignment); if (start == (abi_ulong)-1) { errno = ENOMEM; goto fail;