From patchwork Sat Mar 8 12:28:40 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: 871535 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp144283wri; Sat, 8 Mar 2025 04:30:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU2gwrUsGHaE7JKoMSOQGD+ehDA+ic6dCcWHooMgg38xGv/6k303DsyU32WvRZGkA4PnxQnSA==@linaro.org X-Google-Smtp-Source: AGHT+IFXAiUG4WGMO6aLQxLEbDW0gRicuGIDxHrhm94k9LKG1o0+R839dCOL2x+zp2o/PgFBvX9g X-Received: by 2002:a05:622a:1450:b0:471:f8dd:a15d with SMTP id d75a77b69052e-47610979babmr67878311cf.17.1741437032113; Sat, 08 Mar 2025 04:30:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741437032; cv=none; d=google.com; s=arc-20240605; b=lKzsUQx9C2hIePm+j3D/CMm6GrpTNU1yz0FKa+6H8BfFeZVVgn2szSZW5igvjuOsAw NEA9CxzaCaulO1tH8ZtUfvYJ0YNVAAEDU32GFzQPLgs2qvQCX08VgoF9drbkqyv1+0qR wwba8TlquKLv84Y/YrrfznAEBhBQIrqEdxi2g7NuI5Zpj32Fi6MZ9EU1mzRnqbMQvgxu ZcI9r6r7uKak5qWKO6pzouw/3U+Oo9JqSsSWBqERBD8GC7vtGxa17OJAuSS2eBH2LEMM Z2xGBUi9tO/2YG++mTcWOlbL0Eb3BSPgPHUckhX1yTr/0BgtBNNIe89azsN9F1dUfp29 +P6A== 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=bJ87N+2KXZXtdZu2WpJSCBt2aVSM5GEZOX3NVdYChCE=; fh=7y8w0k/ttQGl+8Ly794l49q82j+FjJq0JsRwOHUpcAc=; b=QSo1rf3OIENZTkNeAdF1oz292HWuVMVcR5QeH8EvwtCcbtqUTkkILIxMtK6l7DB+Ma f4qQkjMWEvrje84HVXNskhPwTKEsAVm6S5nVIQT21j/0k3MK6PHGAYoouni3HnuiztDz EQ9n2K+ic4fsNqbpB3zoFihChZVChvnb3jjoEWn1Uq0hf+copih5bWjTPyzq/rL16uZm EqQE9XDTFSqgTOEBV2UFI4didk2C0G+8VYYJwkKd+BebAzy4sqKbnUk7cIwA/CAxMGTu YzsFEwepq/PLfNA8G3z0X+nEdAYvDiaMH3VEidnNlweQA5QoXkwZEZ6sBNcCyKg8awaZ rp2g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bab3MX1y; 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-47660b97202si18230721cf.601.2025.03.08.04.30.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Mar 2025 04:30:32 -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=Bab3MX1y; 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 1tqtIr-0006X2-8R; Sat, 08 Mar 2025 07:29:17 -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 1tqtIU-0006SY-2J for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:28:56 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqtIS-0002At-HO for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:28:53 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3913d129c1aso223115f8f.0 for ; Sat, 08 Mar 2025 04:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741436930; x=1742041730; 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=bJ87N+2KXZXtdZu2WpJSCBt2aVSM5GEZOX3NVdYChCE=; b=Bab3MX1y6+A2nQWpSa1wm+RN/sSy39h09MToWRAzCUT9y6IPMVqmQwibVpzKOZXuIf wPmWy+dDkoL+Isa3IuHIa1kJIS+clDi/nFeyr6E4UrzVPYjR80jRJtpuTcoZzvjOWDEV wCTRTUOIyCeGRnwySmuSrK7OsniG1yDoym1TJPeHqgLZlpliQHV2ZCKQaSUGv1f3sPZJ vqHeW+XrzpVDjGzmwGBOu8hDQhKnCPD76Z959/Bii6sCzs4kjOH79/2YQgb490Dw/HI0 Cgklg4HPKm6UTN/g+EVjX+q4D1/blzdfKorLSFBWXMlhL2RaFUAx/WtMLj5dQA6R2IbS Oeow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741436930; x=1742041730; 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=bJ87N+2KXZXtdZu2WpJSCBt2aVSM5GEZOX3NVdYChCE=; b=CJ497Ik27amfCKTB0i6i47fNoHfqARFjjBE2XInp90yWpga1pqExjUAgzLzCRHU4NY mmRc7IpqqjoTvjx1BZLNEDQxJmfzlmv39hlidACOquXN7bc+kpLV0+Sg40xDdIpwuVDR oES8HhU72Of149qMESZR0ijgA6MA4vFGOyOhooDByNKoILeF4HOLP6IfIJXJSdb+4uGx VS4cVA12jyYFRSiFmctZqx6w+CgoDvEkqt+HzkCl6m0sIJzvPNHF4mh94KqbgV//suUF ebpasuIUf5nNiby/MOKf8jjZf/+UNdW/UgdrmtBddHBAV2tuGGC25FfUAuTSVzkH5a03 yvFA== X-Gm-Message-State: AOJu0YyQxx7ub5hFmzkH0iIvSXVk9OUx3kkeyC1qvqWhEa+2xaxqFlQX yTun+ecGXsTryGzXu8R7grdu1wZwVjuxKl9u7cBt3sXBHS9ZmABP+DNN6cUEcmySS5KnDoIZOPk vo64= X-Gm-Gg: ASbGncvUgzxG8NADsSb16iWK3b5Gfgt17vKc2y77FnZ/FsgUvf8NH/n8RJK23XLIAaT eOXuqptQJwwoHnQ3ADk8B/Uy2e+mvYrqRIIry4y2AY+86PEy4URUSv5ZrQfnM1tBP7xg4EEY7EV RQVpcrXsN0l3rin3IAmty+uMe70ugSmJdyhcQEoEG6NfSUMVInz3+nkzfHs2IzEE/Z1iY6Gifnv EF0kG0/Wcba8SUt59hhFTmtFySnmo/V6rPkBIbZ0D613dTNcZLVn5TIF8DoYK3tibWnZbJaI9Ki fixO27cqwsCSw169u1VsTEGPSYv0peGdggDHTtUXcE+GYCniLmNCvXJeS+80mzYylxkEW7NdnJ0 CRiEp2mqdX0Ad0fInh5E= X-Received: by 2002:a05:6000:18a9:b0:390:f025:9e85 with SMTP id ffacd0b85a97d-3913af2e4bemr2293185f8f.21.1741436929959; Sat, 08 Mar 2025 04:28:49 -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-43cea8076fcsm16162575e9.15.2025.03.08.04.28.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 08 Mar 2025 04:28:49 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Riku Voipio , Laurent Vivier , Kyle Evans , Warner Losh , =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v4 1/3] bsd-user: Always use mmap_find_vma_aligned() in target_mmap() Date: Sat, 8 Mar 2025 13:28:40 +0100 Message-ID: <20250308122842.76377-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250308122842.76377-1-philmd@linaro.org> References: <20250308122842.76377-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=philmd@linaro.org; helo=mail-wr1-x436.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(). Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Warner Losh --- bsd-user/mmap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 346f2cefd32..dfa6e728ab5 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -489,13 +489,12 @@ 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; + 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); + 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 Sat Mar 8 12:28:41 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: 871534 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp144231wri; Sat, 8 Mar 2025 04:30:25 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXiCGxLB/zEv4vFU4/j6ZkgXFDJJP2l7Ob91pqDN7DEDaB3mN7WdLs0S2hGTRCvSse8/pNfQA==@linaro.org X-Google-Smtp-Source: AGHT+IHeg0MOzzLMSoYkOq9EFbAN4hTgD6CDS5COBi+nse8Tj++5oj3UuHGUmT7IfMmWSPWSprAI X-Received: by 2002:a05:620a:31a1:b0:7b6:cb3c:cb81 with SMTP id af79cd13be357-7c53c8d9257mr398179285a.18.1741437024845; Sat, 08 Mar 2025 04:30:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741437024; cv=none; d=google.com; s=arc-20240605; b=PPfIn1sRvtqUOnl9qWhSZtY9uQnT+uSqNHZboBrIAn7REM2vqA8oZB5xyQHdHMfqRw CBymNUuE56uR5H1oGFpH4OCOWOdIbOfOChE93MCC0gt8p+2GAhuaJzKry7kgvkC13cRt 7yn+BrRmeQJTj3Qr1MWXvc39MrRtJ2TyFhJdsj5Jze/EUpfZTBopVXKnV3sXURoHPyX9 EK3XSeKnsy4itRmFKnnaLQ3NR9ZetDO39GijmpUucPpv/+p8r0/zbunwghILGrxUsmwX IsQ/2sIvO7F2x6nwrDtRVGpaLQxUanwIM/hrGg/ITWZys7EH3tZ72hc2xXzZ9LI/tByb i4Vg== 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=iYxfjuJgdCGSXC8a1k7IDwhqReMpmbHRqmDmJU5MeDM=; fh=LdAIQ3UdMzTnbT8Sx9J5poEoakEbtZ7VP8Oo5WZ3k8g=; b=Jic0g3+bpo2W/G9JzU1rh6GIXgNoGvaMYfhkESWLz0w6tIDfcvWu84YAhgQbnjPQ63 JxGe9Rf99o+CcBOdtrOEuVV0BOTDvDZ4Xu6U/xN4+FMvTIm7fPxvztHgVRJzSda3376g MzaEYBVJKVw2HbbyrFdmf8SA5lnxpUNXZhK6aswM3zp3BnD2TNyzNE0VF4c+30jNwooA WzZlVFuISzXHUSVo1ngurbTGP4BHo0twbLvBDdopSf/ndoeqzknmQ0YqmMH1ZsCZ6EJs /jXSpI68R2yvkK6AXyz4uJ+dUEJ9yuR9G/9i51Vwd9p3OoJCKGsqxXSw3w6Eb+QnwBfq qQhg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X0FS5IKp; 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-7c3e5511c6fsi538241985a.394.2025.03.08.04.30.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Mar 2025 04:30:24 -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=X0FS5IKp; 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 1tqtIv-0006d2-NV; Sat, 08 Mar 2025 07:29:21 -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 1tqtIa-0006T9-K9 for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:29:13 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqtIX-0002B6-NE for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:28:59 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43cec5cd73bso941115e9.3 for ; Sat, 08 Mar 2025 04:28:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741436935; x=1742041735; 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=iYxfjuJgdCGSXC8a1k7IDwhqReMpmbHRqmDmJU5MeDM=; b=X0FS5IKpyobnJd/O79kHN9BFt8Pc4KVnEcci74kq/xKzR2Of5m7dNJ+T/7yc+AEDYb 6AaggwWWED7DU596zpj2mWuICAAZuC+rkxT9Ui38Lxz17FjLCXR3LK1KNMk0U12+NvC/ OWLWuuX+izOeKywQyCmmBdbG1liTvou+3Y4QAh0i16ENQxiHKOTQB7IPj3/N9ZqINLig gY3203hL+3F5F6m25Q4bs2JeuT3VhOtM5Y1yy3VDy8aEQ3FWmP/xoFjfbeoOMGxqkFFL 5CMWbkYO8LbWhJInqlyu7Vq3/5xDvw1cA33hwWz91u3yz5SbDdYZtXusp/qaAkmy8TEY x6Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741436935; x=1742041735; 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=iYxfjuJgdCGSXC8a1k7IDwhqReMpmbHRqmDmJU5MeDM=; b=WfE4gfq7theYE6zMeCcBP3yhcmLWEN1q8EUAftIpiuUhsomz37o0b/KKJKHo2sCCjH +lucskIRIlEvbZPO33YXPAIC1gdaHW188HA5USwiYtKTPdVm/JKDa6QL+jDwB7x9IQZ/ 35vlrJcof9SqS+X+5AHLGJMOjSq/l9tEJMNHCFCEDD4otIVDYdR2wOtbpMdVb95ngDV8 DqurYbbZKIT9YgUS69Mdn4LTYC6oVEj2f3S2DG0KjFYI1Uqj8E3yaO1ceLGXNgNqTR5c FW+oCRDrHgtFDN0H6ZqVKLi94sFJ2NCLoLySzAaW/I4EvhrPU54a2VTB6qLt/t+Cb33w Mbug== X-Gm-Message-State: AOJu0YycmrdnhHS3NLmkZ9VkQFkKGZuUL2rncv/aVG8QIyx0yl0iYsi/ qB+kZGhfOsxBGcGAhcRa5OK3QQ18QEQqfiBPNlmsA5J/DpkuATwIBgfXK3Vu8tkLnzZI40++cqE JAjY= X-Gm-Gg: ASbGncsXmCNa9R0iy5O0Qn/KyX3Oqh9NGTsD315Igh3O1xOLPCX/yWsJ/UYhk7zKa4O HUX0y0bBrLFIjszV9vfMuAH/Td8p3RXd7Dm9qClf5gjwDqkRft5EzKa3xbVyA+X8ru2EF2EZtTS h6/ZDkRWzP5G2UGIVhk48l8RfRpjksCOEceDrFNtvTY66XEMcQyIXGhLsOorc1WOkr6ZViuEQa2 +UA0R1SRNjVgNhcqV3CXvHQv7F/rpOHvG3tlfMIWvW7NzhJkxgF/DmHfJ4JmrBv5SI4EAGZ9tZh ye7J4mnwKGPI1ptMJ9axfXZzEe20stma8zN96V24JsxuFPZd5hAODOx7NTj+rfbQgVrqUsB6nCP QM3HsuR6+uFl19ePhNFM= X-Received: by 2002:a05:6000:156b:b0:38d:e304:7478 with SMTP id ffacd0b85a97d-39132dc56f2mr5155066f8f.38.1741436935200; Sat, 08 Mar 2025 04:28:55 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c103f41sm8574514f8f.85.2025.03.08.04.28.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 08 Mar 2025 04:28:54 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Riku Voipio , Laurent Vivier , Kyle Evans , Warner Losh , =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 2/3] bsd-user: Propagate alignment argument to mmap_find_vma() Date: Sat, 8 Mar 2025 13:28:41 +0100 Message-ID: <20250308122842.76377-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250308122842.76377-1-philmd@linaro.org> References: <20250308122842.76377-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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(). Add a comment in do_bsd_shmat() to clarify alignment above page size is not required. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Warner Losh --- bsd-user/bsd-mem.h | 4 +++- bsd-user/qemu.h | 2 +- bsd-user/mmap.c | 10 ++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index f5ec0de24ca..90ca0e33775 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -370,9 +370,11 @@ static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmflg) if (shmaddr) { host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); } else { + abi_ulong alignment; abi_ulong mmap_start; - mmap_start = mmap_find_vma(0, shm_info.shm_segsz); + alignment = 0; /* alignment above page size not required */ + mmap_start = mmap_find_vma(0, shm_info.shm_segsz, alignment); 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 dfa6e728ab5..3f0df79c375 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) @@ -494,7 +488,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); 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 Sat Mar 8 12:28:42 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: 871532 Delivered-To: patch@linaro.org Received: by 2002:a5d:64ce:0:b0:38f:210b:807b with SMTP id f14csp144059wri; Sat, 8 Mar 2025 04:30:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUMM7Vozk5yGERPawuGnLyfbierQOoPoOrQkmHqmFfZ04y+rtxuhl9XTPjRPou9I1KALovVXQ==@linaro.org X-Google-Smtp-Source: AGHT+IFeOHjfaOv1fUhMSot0RGyWpe2vNtrNxfnkVkdivNBdbkeiK7EeYgFYRqa+8dGbURVaOw2i X-Received: by 2002:ac8:7fcd:0:b0:474:fd7c:2745 with SMTP id d75a77b69052e-47610983244mr101669501cf.20.1741437000465; Sat, 08 Mar 2025 04:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741437000; cv=none; d=google.com; s=arc-20240605; b=Uz75Nut/MGojyUcY7XaYfVl+jn3yFAFox5sWG7CuT1vMlzNNMKeKwBCZFXobx1f30t P+jbaTYMOlzzyEv6Uqptd1kzxw6i4N273A7RqMxs6Dd8lJomyxfA8Co4mY/HtwuBIdIe 4RDT9lqd9CEHb53X1dUDSV6OjcnNu54N0hJsk1DAIgz/um9Ve3Pc6fYE+ITuFtiMGJ9h IZDjsvc8xrmbSPCYq4C/M9AXjztsEACsK34kJd1K70kDxJn+ea2zAAefTnOu1sUBVf6v CecbbtcuE/2JlI/EPXK83STEzVSyIg3sfFXQaQAcSBRuJCYRDV/udzl/4B1KLVvuhMgg 9Yuw== 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=7y8w0k/ttQGl+8Ly794l49q82j+FjJq0JsRwOHUpcAc=; b=gfKZzaNeCpxVnMWG4Gqa59SYkdsD9Vr6M6abu5XwrsB6GCDajF+vH208r88/0dSBeH tDpIgO915U5BpeVCQbGVULWM9op5DOQuXM/ArE2PAek2SI+1vzRdN4BruNR5XjZ0SQgV e+gEEy58lcyBCS78ciSRXd6lA2B7IXSxm4Yqj86F1XFfcfdlM1Z+jSzAozN31DO/2Gjr vKz1GF8RThu2ECnBhCpzBMs/mbTbjgK690xdsDmqRlh/5BkFo36FQmvB7V8yv6GKP0kE Xz5Oxbmceks1s96XDs+FytFOiC+fkNqZmwoLPqUpM/m8KYduRWqy2s30M+FwYmRjVxQC S4yA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eh+zA946; 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-47676e02547si1680741cf.170.2025.03.08.04.30.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Mar 2025 04:30:00 -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=eh+zA946; 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 1tqtIs-0006X9-5u; Sat, 08 Mar 2025 07:29:18 -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 1tqtIi-0006UB-MN for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:29:14 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqtIc-0002Bd-Qm for qemu-devel@nongnu.org; Sat, 08 Mar 2025 07:29:05 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-39140bd6317so68502f8f.1 for ; Sat, 08 Mar 2025 04:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741436941; x=1742041741; 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=eh+zA946OZtKL44+9K4/NzexQYPy5C3xUiG998OVU2tr84hIWSxFDsEAoSHDanW7gC B2HTmUfhisTa8oVxxlGH12sDwdXnS4yfzF8H92IQqxMI4ai0zix8nvwNiwwnw0WvR/0I PSiqnwEl38+mTpJlshxvQvT75yFkrxhrOHeLuJgIf0OU1GqAXFiAsfBT8xfn5iH46xnO dgZo+oJrVsMHd4MotCUwME7G1m46h2DlrBqf0XwCXBMIlImrnmXu0fyjXEFW97Lx6J9u kHKFlDI+MkvVE4BOPoHlm/PbQ7xWjhlA8SvLpMRyAjP2WnTpbkfGLFvWYhOC3UVTiW5n C9sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741436941; x=1742041741; 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=e3161xwGE50dGthjdCT98Lw2qTYTKKil8vJFprChUJcdqdMVhG3b68z0ocjFtf56PJ z5SIpOzIKKLBFb99ZCMIqmIA+WYW/0u5dHn1UgS4nnUDSAiZwWHuAR/1t3jzm3BaqVQA HwEb0yODgFrVF+9BIxri1yrLHKr6HICpf8uJzOfqbo1y1G0JxK0DL7KZsTVSTWFCzQ1g GAz6Y/0jCi+a8WS2BqbndujawrZoGEoTcw/b8UhureT8zO8I+FXFHTSFdj7hke09dadJ W+kPrAF/2npxqRpv1Z8OC5NNl7Mc4kMFmZYNhd8d/pag6psjiGMRSWKP2CzmuFENmGgb 0HPQ== X-Gm-Message-State: AOJu0YxmyVVlntw6EJXTW5Dec8BhuQPj+o2BajCc8+EdNZOaKcylS0xA qcsEHe3WS0yvy0RJcJyaZb1A3/RmvU/DeOMlfXhHN1sSbV5EnK356osmo3kecLAnbnU5gDHFQIt Ee2Q= X-Gm-Gg: ASbGncvM8wZ3l403xJ1BP6/wTECeo0o2dMeIjtYLff31GlfjvMgMcj+Xo6txg+EJONX u3Ywik21dRaLs1TMJ7pdibpeD4lolXBszck9xgns6tCM0Kz561EQ9pu0FfUgX45cLVrqyxybvA1 J9e7Za2nKRqnsFUKGBRnuTaPDB2vbXZGSVij8yc3HUtKHJUYmQfDmJv/oJxTiRof5MJF5ko7OUr I4FSovqTUX34wIGZovOSx4MRGfHE9VpQq8OpNfhOYn/gx+YyGG/R8OAXjgjuU1V0aCuccHH8wzp zrEVdSyva+tx6tHcmXvGG8sr29Iyz8yeIxGRfC35Fth6ORZ0HjKaUE29K/tpYOR5Pt0qGkXFmzZ f/nxMBVgSfZdk/I+t0bw= X-Received: by 2002:adf:a39c:0:b0:391:34ef:ae6f with SMTP id ffacd0b85a97d-39134efaf51mr2877368f8f.29.1741436940882; Sat, 08 Mar 2025 04:29:00 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c1031fdsm8434950f8f.89.2025.03.08.04.28.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 08 Mar 2025 04:28:59 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Riku Voipio , Laurent Vivier , Kyle Evans , Warner Losh , =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v4 3/3] user: Extract common MMAP API to 'user/mmap.h' Date: Sat, 8 Mar 2025 13:28:42 +0100 Message-ID: <20250308122842.76377-4-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250308122842.76377-1-philmd@linaro.org> References: <20250308122842.76377-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.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);