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; From patchwork Fri Mar 7 13:09:50 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: 871180 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp757072wri; Fri, 7 Mar 2025 05:10:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUfE1NzluE5gdL9qms5w13nB1MD/YFUn5QikMOFUNpkZ0yrft/w/r8ESzMA0GP7axx8XleWkA==@linaro.org X-Google-Smtp-Source: AGHT+IH03XpAB7sLT2ChTseeV/WGjVCLGwrIWGCv8A3QtiK9QKLvqR64cPnjp3JBYV0Ng+R+bDtF X-Received: by 2002:a05:6214:20cf:b0:6e4:4484:f357 with SMTP id 6a1803df08f44-6e9006adc5amr33003276d6.30.1741353046202; Fri, 07 Mar 2025 05:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741353046; cv=none; d=google.com; s=arc-20240605; b=UHbHo+N24NcMQ27TjCJUwbH6p0W448fVJpBPB22IxHdJ1j7zlC3v51u6nvKDkpNzum LJPLj+540USroA2rCfKXwlRj1tY9uIdFAhkhBcoFPumb2gzo5E08OI3+p+4iUC2+nWht iWyAFGmHVg9i+viYsH2QI7XoqyEnwOqeCCA2eIPifRgGAbPUnepY/e2Rbb4PVYK9OWH7 MQwoeT0tkPUF14rSd5gWtPeWjVyZdbBLF9vJMCLaMfzz4q7ot5Ua5AXg/+WtrPmqLE2R JpxB/3K4jvJD/KEPaUVBHwfENOJtnXrXzh5THPPvcAnoZJxGU2WpTjbDa2U4cJ9C9zLN zR/Q== 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=Yfyfv3HDb0p+J1qRUgpzig7LH5Vl2xWLWoUhxNEl80M=; fh=YwzZLqTkl/aXI2kmXKm3J+muCZNvgKu6t1Htrn0AL98=; b=EXoNWWePBVnpoNAx8jxMa3l8r1dPEFn9raQWkLJ9d1D/PrZy/pZa58wmFVCB0BFcdR fKV1788MesWTkD995uhKYagSbsSeUBxWi/pSQ7dJQaV7P7GP/IPovDMs8F42Ox94uzeg 3uXPuuNTUa7FG7jVgLRyUOfI+ObGDYjodHyx2WewdLJmiCjZWed5YykdbfmY2S61ivMg gxdV6Es0cA7SpFExXjgpDp93iq30/lXpfV2+mqdSxXrDJ5rpVW9tyasLvzeZ4PG5aZrZ kyz/5oPsuZgwR35yWwFpMOe5X+WtYIRk6dZBAFd8n2dz0qoNb+Txwf31qMUnR0dCc6JZ YE2w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iR0ewxhO; 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 6a1803df08f44-6e8f707cc78si33918626d6.88.2025.03.07.05.10.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 05:10:46 -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=iR0ewxhO; 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 1tqXSp-0002mC-RT; Fri, 07 Mar 2025 08:10:07 -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 1tqXSo-0002lD-3V for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:06 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqXSm-0001Ly-8q for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:05 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-43bbb440520so20623015e9.2 for ; Fri, 07 Mar 2025 05:10:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741353002; x=1741957802; 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=Yfyfv3HDb0p+J1qRUgpzig7LH5Vl2xWLWoUhxNEl80M=; b=iR0ewxhOfczaTEaRT028Zvu6/7YoiXlNxZn+U1MnuS+oeOVQyoiTUmpPVSEAAZ0M1o 3Vo3ImQcVTJGJXC87EZCZQhKAGj+2Nqbzo0JWSIIVyM1V7tPQ4eZwSe0coGrAliFJEYv in48AidUCbHOsd8WQkPrPcYYNg6bB45rygNRfPWMHnyDSENgErn9KxldLI7F5dwyRksN bBpYUlLK+O5QJ+pjky62ogKPrjets7kBo3xlzBUFIarjCQKMCfhGM4u+QbRtfOJerFD+ MaEW7Tbc6cUBmMGdXYdWYaQstD6ezPe3OQZHnkg2uvrt+7CLq5T5hByZGvAwxnXcMVzl E38w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741353002; x=1741957802; 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=Yfyfv3HDb0p+J1qRUgpzig7LH5Vl2xWLWoUhxNEl80M=; b=QCFALHOidJdG3OtVff+aUlfvKTBQQ/ZAMxoHNUf9WPOJP08VsXf2APRnQMaM8o+iGB W0pek7Mf4spWJwM8shHnBUA0AiEuExrQMq/Rv3hb+sRs14wc5YyXoAoDld/Nco4zPlLz Qod4wtoToTZ/++G60650u1SvEZmVrX3nLvfB/qjWdrTdaUsMIltqH23Ce2Apg/jOfOId grpt44JY9GIhkg2/BEaU0TvxjdL9LxyQ4lRYLBXlaBMQxe3qmhinXLxZ7PaxWd1P0CZf tRbTAhybCTeC6MjiszJ17IwHGXGMyhokdqC2dnTzZtVAs/QLKihs9v9SiKOaVeBOWWAm T0Ig== X-Gm-Message-State: AOJu0YxRmnxczWe8INx4JT+3p9/Xbmg2JhCZvmwSBKxrRgDCk5ef5eSl 3QvEPs5j1cYEV3z128C5K1gxLTl9yoXS7XYIhM4DjyYjBspXDeLAq6QobnaO1IQXA0AOmZWxHDQ uNEA= X-Gm-Gg: ASbGncsJ4Fq4tSlNleiKcsIXPVQEaughT4HYdvalJrS38RGsvnfsll2yMDPh24mK/06 YP/A8s1dGR/eYx9BsDsuI8qdLdcyb8kxD1hHXS+yhMCNMg3uSDeGIOAEmYrLar+T5LLzYPaXl/N K8Ce9QCLHNXy6geVC+jB3uWCgJY2zRdH9YrQPTN50d6CoCQX65dJZ4ibO95dj6jZzhZjN8kaXE0 6xMsIFsuCDZzmrXf9H9JoxEGkK8rU2UhyoQgjFkxbSNWXO/SGwe1w7a/ZHZ/KXyZBWBN1cwZIUH ZxZN62QE57iw5aKGM5cf9CKduRNAV88tRY34aj+tMAjWL2Yt6zm1OEKjp0Jlz+3YfzrewHIyg8g TlXU5OXn8rJeIwdzln2I= X-Received: by 2002:a05:600c:4ed1:b0:439:9b80:ca6f with SMTP id 5b1f17b1804b1-43c5a630248mr37335545e9.5.1741353002264; Fri, 07 Mar 2025 05:10:02 -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-43bd435c88esm80351355e9.36.2025.03.07.05.10.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Mar 2025 05:10:01 -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 2/3] bsd-user: Propagate alignment argument to mmap_find_vma() Date: Fri, 7 Mar 2025 14:09:50 +0100 Message-ID: <20250307130951.4816-3-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::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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 Propagate the alignment to mmap_find_vma(), effectively embedding mmap_find_vma_aligned() within mmap_find_vma(). Since we ignore the alignment in do_bsd_shmat(), leave a FIXME comment. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Warner Losh --- bsd-user/bsd-mem.h | 2 +- bsd-user/qemu.h | 2 +- bsd-user/mmap.c | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index f5ec0de24ca..87219da2919 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -372,7 +372,7 @@ static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmflg) } else { abi_ulong mmap_start; - mmap_start = mmap_find_vma(0, shm_info.shm_segsz); + mmap_start = mmap_find_vma(0, shm_info.shm_segsz, 0 /* FIXME??? */); if (mmap_start == -1) { return -TARGET_ENOMEM; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 4e97c796318..0b3bd65b180 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -242,7 +242,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); extern abi_ulong mmap_next_start; -abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong alignment); void mmap_reserve(abi_ulong start, abi_ulong size); void TSA_NO_TSA mmap_fork_start(void); void TSA_NO_TSA mmap_fork_end(int child); diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 28d7e387a20..da22fcc7c41 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -275,8 +275,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, * It must be called with mmap_lock() held. * Return -1 if error. */ -static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, - abi_ulong alignment) +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong alignment) { void *ptr, *prev; abi_ulong addr; @@ -395,11 +394,6 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, } } -abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) -{ - return mmap_find_vma_aligned(start, size, 0); -} - /* NOTE: all the constants are the HOST ones */ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset) @@ -496,7 +490,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if ((flags & MAP_ALIGNMENT_MASK) != 0) { alignment = (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT; } - start = mmap_find_vma_aligned(real_start, host_len, alignment); + start = mmap_find_vma(real_start, host_len, alignment); if (start == (abi_ulong)-1) { errno = ENOMEM; goto fail; From patchwork Fri Mar 7 13:09:51 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: 871181 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp757259wri; Fri, 7 Mar 2025 05:11:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU8Rdx4cR6LBiJHErB8eKPSI2YEPotIAKRe8Jipe/lEiXoZTZlmmx1aXUtZcw5wagb5TPCuhQ==@linaro.org X-Google-Smtp-Source: AGHT+IHo5c7Y3K0nr2pzqptEHgP0eGhBYD4XokUKzVbBmGhLb+Rs86Q/XzkFOwJ/NmF10LD+19NQ X-Received: by 2002:ac8:590b:0:b0:474:e8c8:b0e2 with SMTP id d75a77b69052e-47618b0247amr39250771cf.37.1741353067144; Fri, 07 Mar 2025 05:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741353067; cv=none; d=google.com; s=arc-20240605; b=TfzYf+kW9ewJfOwWLRCmxCEnupq7BDIHv6bfeOmH9h9LAXZVVSK+0vIg/wQ+HqLvuu aS5rsy83zj3jq0TiDDPyED9iXv3LyiAKxoZCBqqxYA2aIrgwsIelTYDZk5GziWD0k5tq wakzZ3Fu725Z7HVAKoUfnZ4IbpHp8Xch1TNukHRzFZEzqKbiD3S9MtN6iLKWgu1Fl1l+ ix6rNN0+B/wUXkzunZGKDrakdDYS0bv6WngJW7IZATNRrJOG8qtGJr2TPjK7jnpMk8M5 pQb0RHrloGOvrFm2uqIK8v14UIqN0opcfgMCJnSz5iK2Wuedez7morXGyGm60kROP52j Z0pQ== 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=lNWRd/3bpDqDY9go9fwbBzHVlSOjDlQlmHNSNyWLCFQ=; fh=yXT+x3UFwqTnYGhpBmoZAJ5rimP9UFb7TTcTAh82M2g=; b=g3+gMncU0ne0MDVLEsLN/Cop+GByVV774DjeBYYI61kswkrtV37H/b/WET+cR5OYBi CErMOztYLV957m7n215PSy5bCnvvzukotNP4KW524dAD8ABVpnjE7c6ACjZRm3n3oliT yOGQebX0hympCXe4hp4SB00otiw57EmYGK2TXuzAd02Q/J7hMiOQskzfiWaJn0TCinyQ qak9A65nVUbrX93Bn0WXyv7Wbca6bhv/U3YijQR48jsb4tD3munR6QeqnZtniq7Sn1Dr S3GdDc8Ij6KFbejit++9/6D1tkPqPVGn5EsDVIG5ym4EQnwQK0TCKeSxB+isVLxp0Qrx 7iXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yUdeLq3j; 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 d75a77b69052e-4751d986104si32444991cf.15.2025.03.07.05.11.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 05:11:07 -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=yUdeLq3j; 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 1tqXTL-0002q7-QJ; Fri, 07 Mar 2025 08:10:41 -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 1tqXSv-0002oZ-60 for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:13 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqXSr-0001TW-K6 for qemu-devel@nongnu.org; Fri, 07 Mar 2025 08:10:11 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-39127512371so1125405f8f.0 for ; Fri, 07 Mar 2025 05:10:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741353007; x=1741957807; 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=lNWRd/3bpDqDY9go9fwbBzHVlSOjDlQlmHNSNyWLCFQ=; b=yUdeLq3jnlkWZlltyx+pXnhbgeqqqF/saWeRbJtV9pF+77cyt9R1Uj6d5xMNk0GOB4 Td28VjoDk99fQRSg2LVQNr8wyEJR/6ALXc2CBcMIsWLqA6w1d0YveGgCoQKf5SlgEb1G M9gtY8NXvqdqrALyFZdL7jsAdNw0yz28QOuVDCHr+ThnNxkSHGSeODn8aKS8Rl9BwmBf 3TdG2P1CBxt5pCm1vZmjcEBl6BsN/ZYl9suhe6nUhDlFHmziz7dnhjK3v+et/vszgRUW Kgw3lNsbTaijt3rQ1adAV0Gz1OJI9hvdMj67f9sV0/5gfAY1bZgsW5QP1Z9B259LE0HM HstA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741353007; x=1741957807; 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=lNWRd/3bpDqDY9go9fwbBzHVlSOjDlQlmHNSNyWLCFQ=; b=PUVzD2rWgvUdpVWg3TcGeQess1Y0ipyZuiUKmfkz+jPqldlUXwcKVX4oC4vle0nWdT NEaO6iDCnhitfIJ7/ruuU2LrxnF7tOwHBrJ7vLd2pnAhxSYZvDD/TWgAnzhSoAyxUW42 nNrJCIVecVv6hN5Vs5cz6329SzI6+81es6FsyQXz3wGxK0XAtbQGIX0wzf2o/vTjoQsv Z71f265zXFmBie4DGUjxP2Wl9AX4rQTVkVsdo2k1bvCwtaCFpoLHInfl2EHo8fWFY2GG cnp32nPzHRidf94QWglGw2sLSMasp7WqqtgAxCjyxoPvv1gOiJhsdlmYNqql4zJH24U4 Mn0w== X-Gm-Message-State: AOJu0Yw92A2E8Mhg1zqw0GyU9N4hy0Do1zviP0vAkKOu7wdYcsXEug/H ZiNb8yzT1pXA9zERxidXkaVSehHH9CKH0hU3hdTbEaUkNGz5xZbJ/dUxOsW48DtRks07yIk7Fgc BClw= X-Gm-Gg: ASbGncvrWUyeXEzUjEx8OnkwjgMnpsZ7po2krcNW8TaoZWuWx/JYFsezwHlU8Tsa1eT DNDKVsrS40pxWVS+DBHzNaCRSV6z2C/gUJGsTorVkAQJERamoP0jGU600R2rHOQX5GoH/0lvejN UItcxBs5eR7HGrPWZBHXJBkDkLv43RmNK94ZRtO6GJusuVzPv7Zrs1pRY2qRsa2W9lOdvemGb7b AiDmu+B1TMix7Qn2Qe2C0yyZHlez2b+qEGqXgHa3thA0pp/h34X+pFzrnRjgCDxXewTt+t7A4Pv 9OUJqTYS6PGNX8NElKxHHJk6H02EAYL5P+UM3tw42kodAoJHMcJP8HzQiFLJU+ezvk25bAmcgdV xlRfnqBuNmDzk3/Az/ck= X-Received: by 2002:a5d:584e:0:b0:38d:cf33:31d6 with SMTP id ffacd0b85a97d-39132d68426mr2062622f8f.3.1741353006878; Fri, 07 Mar 2025 05:10:06 -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-43bd42c5880sm80124445e9.19.2025.03.07.05.10.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Mar 2025 05:10:06 -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?= , Richard Henderson Subject: [PATCH v3 3/3] user: Extract common MMAP API to 'user/mmap.h' Date: Fri, 7 Mar 2025 14:09:51 +0100 Message-ID: <20250307130951.4816-4-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::433; envelope-from=philmd@linaro.org; helo=mail-wr1-x433.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 Keep common MMAP-related declarations in a single place. Note, this disable ThreadSafetyAnalysis on Linux for: - mmap_fork_start() - mmap_fork_end(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 12 +----------- include/user/mmap.h | 32 ++++++++++++++++++++++++++++++++ linux-user/user-mmap.h | 19 ++----------------- 3 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 include/user/mmap.h diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 0b3bd65b180..c1c508281a8 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -32,6 +32,7 @@ extern char **environ; #include "user/thunk.h" +#include "user/mmap.h" #include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" @@ -233,19 +234,8 @@ void print_taken_signal(int target_signum, const target_siginfo_t *tinfo); extern int do_strace; /* mmap.c */ -int target_mprotect(abi_ulong start, abi_ulong len, int prot); -abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, off_t offset); -int target_munmap(abi_ulong start, abi_ulong len); -abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, - abi_ulong new_size, unsigned long flags, - abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); -extern abi_ulong mmap_next_start; -abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong alignment); void mmap_reserve(abi_ulong start, abi_ulong size); -void TSA_NO_TSA mmap_fork_start(void); -void TSA_NO_TSA mmap_fork_end(int child); /* main.c */ extern char qemu_proc_pathname[]; diff --git a/include/user/mmap.h b/include/user/mmap.h new file mode 100644 index 00000000000..4d5e9aac70a --- /dev/null +++ b/include/user/mmap.h @@ -0,0 +1,32 @@ +/* + * MMAP declarations for QEMU user emulation + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef USER_MMAP_H +#define USER_MMAP_H + +#include "user/abitypes.h" + +/* + * mmap_next_start: The base address for the next mmap without hint, + * increased after each successful map, starting at task_unmapped_base. + * This is an optimization within QEMU and not part of ADDR_COMPAT_LAYOUT. + */ +extern abi_ulong mmap_next_start; + +int target_mprotect(abi_ulong start, abi_ulong len, int prot); + +abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, int fd, off_t offset); +int target_munmap(abi_ulong start, abi_ulong len); +abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, + abi_ulong new_size, unsigned long flags, + abi_ulong new_addr); + +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong alignment); + +void TSA_NO_TSA mmap_fork_start(void); +void TSA_NO_TSA mmap_fork_end(int child); + +#endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index b94bcdcf83c..dfc4477a720 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,8 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#include "user/mmap.h" + /* * Guest parameters for the ADDR_COMPAT_LAYOUT personality * (at present this is the only layout supported by QEMU). @@ -39,24 +41,7 @@ extern abi_ulong task_unmapped_base; extern abi_ulong elf_et_dyn_base; -/* - * mmap_next_start: The base address for the next mmap without hint, - * increased after each successful map, starting at task_unmapped_base. - * This is an optimization within QEMU and not part of ADDR_COMPAT_LAYOUT. - */ -extern abi_ulong mmap_next_start; - -int target_mprotect(abi_ulong start, abi_ulong len, int prot); -abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, off_t offset); -int target_munmap(abi_ulong start, abi_ulong len); -abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, - abi_ulong new_size, unsigned long flags, - abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); -void mmap_fork_start(void); -void mmap_fork_end(int child); abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, abi_ulong shmaddr, int shmflg);