From patchwork Fri Sep 1 02:23:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719477 Delivered-To: patch@linaro.org Received: by 2002:ab3:1981:0:b0:23f:8cfb:5ad7 with SMTP id 1csp17084lti; Thu, 31 Aug 2023 19:25:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpDq+sCjJaTX1dqBFJ53QVNR9/OcRjcqe6uLA6Dbp09JW2xdc0v2D3VgER1HoUgJVntpwe X-Received: by 2002:a0c:f0c8:0:b0:641:894e:90fe with SMTP id d8-20020a0cf0c8000000b00641894e90femr807866qvl.61.1693535135315; Thu, 31 Aug 2023 19:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693535135; cv=none; d=google.com; s=arc-20160816; b=cDyA2OKfbwqHfKnspC18ZVJogvWzWFh9n6wUT8QcPQBosRV8LdzeSKv0DXctix5J8L I23QU6TaK8Cpk1Y4GWsFFhMtEIdNUU0Y+0xY3tO7zHQU8Ad8ssRzLeFhh6sQmg8z2nl1 g2J/3CiRaNlLisqVd3yhGP3TNRKFylH7WhFnmLNizcs6qNylvZCs4qeimjL3RHJqjS5Q SwQg832Urf3nhjib/EtYvVtV3XPer/RqAFjRQ9Eit77TFK8+g7+mTlbSE8VNmClNBEAA F6Uf0prTWlT1VvX8quDfq4zSsK4mOvWSu6JMkMTp7XE+vu1c0AVYIU9a7D1dTRkeEDM6 XCyA== 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=7kaLhwLbHzHqv/PeQXejQChX9nX84J3A2xjA5ly6h/g=; fh=r1cPj2GlTGSV4V8jQu3jfCKsZwpJ5ktYEUy+P7GD/+s=; b=n8/5sUU6XCItDbytA4ttq1TivFfDJVedcLipYUQdyC0HG8pnA7lkBOp5n0hArt6fnG MC5pEzp2iwQfsPJf0cGDidubjCcmw/xdnW6zJvAShv/IYBDiJDVTJ03D/F5G8JnWyzY3 HRDYjAu19fnh577w1oyRi0cW28cUO/XYh8f32t6/OGddE/f1FGMwHwpSFvKnK4n5Befc qKi6es2QrExzuRHk2gDS5TgCLSa0Ox8MVnqAkPALLXKCsychubMAZfBkSHDKrG/CY0id D11I8SQiex5+Ie1XTy5x35tdI16G2dUV9l74bQbwzXGlNdA/KoqiHZbWeHuWHDxgoDz2 ANqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UhMnNGYX; 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 w25-20020a0cb559000000b0065160dd5cf9si1663751qvd.491.2023.08.31.19.25.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2023 19:25:35 -0700 (PDT) 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=UhMnNGYX; 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 1qbtpC-0006aT-5x; Thu, 31 Aug 2023 22:23:54 -0400 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 1qbtpA-0006Za-Gp for qemu-devel@nongnu.org; Thu, 31 Aug 2023 22:23:52 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbtp8-0001RW-Az for qemu-devel@nongnu.org; Thu, 31 Aug 2023 22:23:52 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68c0d262933so1262880b3a.0 for ; Thu, 31 Aug 2023 19:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693535029; x=1694139829; 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=7kaLhwLbHzHqv/PeQXejQChX9nX84J3A2xjA5ly6h/g=; b=UhMnNGYXFZr7WSTADl8NAcOgYpocmebTYMgxZ4PNBNqBQDWMF2EhtUfNea914Z/xfn Z4CXbhK971vODGPU/K+SvQNcQMQlhTfy2xD4mCyniUQgmByZ8OLtUygRxJ7Dx9bBbLYt PZENO2pq+Rk4r5crS0OlE7ubaNm5uazPfl+1ko9bprE6wisQH4IrWB1jm3Fl794gg/DF /fYBbqE3nh9QcBaId6fnICA5hLBGgNzE8eXrIAHTlk1Iez5cv/ZatmEBIz8iP18Z2O0j fjpi/b12RDL60kss8cWEPaLPFDLWRGSh6YZ038vnrUhbDWBq6jCAdoesbIrU0gEO2R5L g3oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693535029; x=1694139829; 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=7kaLhwLbHzHqv/PeQXejQChX9nX84J3A2xjA5ly6h/g=; b=RP5HulJJCP4VFttTQSsp2zHIG6843S4IzrLgaVqzd28Lb5J5qsu9u5j6CwsVC4H5Sh n776XCnhq13iuxF19rcDfp+R1XA7Q9/3X7sXXRgmT6sEXwR105SUzp0207RTP75rlXh0 sXiYm9LPOeSZS1lY+iV722dEiD9ZntHDq4+2b6GHITexgAbuzKzVxpN8m2Kyl/voGaCt G6oHaQ9SoweBqJ/FwSnulIfBh7xqb23RkoM2MupE+rs8j+WuwPtZcFUSd9n1Dn3YA85b m+2qWB6uZxuNAX+pTGfvVYXrCD/QQ/oz/HzE21ReT7Hlz4+tR/GCT9G1BjAoGuSq8n+s XTUQ== X-Gm-Message-State: AOJu0YxuFjZ7y+rvtvqpcEMArcKy4Yjjo845GZXK7EgKvz47SN221NaY Kh3YD5eUcV4MEbqMUn69sCfo+Mm6fwFhB0Ix+NU= X-Received: by 2002:a05:6a00:2290:b0:682:713e:e520 with SMTP id f16-20020a056a00229000b00682713ee520mr1931675pfe.8.1693535029110; Thu, 31 Aug 2023 19:23:49 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id c25-20020aa781d9000000b0068a54866ca8sm1906977pfn.134.2023.08.31.19.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 19:23:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, alex.bennee@linaro.org Subject: [PATCH v2 20/33] linux-user: Do early mmap placement only for reserved_va Date: Thu, 31 Aug 2023 19:23:18 -0700 Message-Id: <20230901022331.115247-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901022331.115247-1-richard.henderson@linaro.org> References: <20230901022331.115247-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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 For reserved_va, place all non-fixed maps then proceed as for MAP_FIXED. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index caa76eb11a..7d482df06d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -495,17 +495,19 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, host_offset = offset & -host_page_size; /* - * If the user is asking for the kernel to find a location, do that - * before we truncate the length for mapping files below. + * For reserved_va, we are in full control of the allocation. + * Find a suitible hole and convert to MAP_FIXED. */ - if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + if (reserved_va && !(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { host_len = len + offset - host_offset; - host_len = ROUND_UP(host_len, host_page_size); - start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); + start = mmap_find_vma(real_start, host_len, + MAX(host_page_size, TARGET_PAGE_SIZE)); if (start == (abi_ulong)-1) { errno = ENOMEM; return -1; } + start += offset - host_offset; + flags |= MAP_FIXED; } /*