From patchwork Thu Aug 3 01:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709584 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354260ltf; Wed, 2 Aug 2023 18:55:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHwcQI1cbMYRgbRk5hNYMvgiOuE6CxtM56CEWejMagqO7LBj/3OU5C6uUu2xDTZ4zyAAck X-Received: by 2002:ac8:7fc3:0:b0:403:9f48:7ce1 with SMTP id b3-20020ac87fc3000000b004039f487ce1mr23086941qtk.53.1691027702690; Wed, 02 Aug 2023 18:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027702; cv=none; d=google.com; s=arc-20160816; b=NVc4WBnOi+3F5yd6vyBijQbXTU6BnTCHwRnRtDorY4+zr6LdF8pO+B/IoFJGHZ//7x MDv8VKJL1X1tQ0ZX5Z+EHXpolNzdqpTfZRTLP0dNluGTyujc2keiJC/3qVtgTgD1PYvL WOEfyVpxfWRUTyv5RfigA0YEbPk363c6kebpGrke0UJqFtLQ7q3sNrrKznKIdQ4Ew2d4 vQFSu5gM/93VBZSGtrrFI64GHR1cjYfVQqgCuDCgYH7wT1yPCrjETBLd5NoxCsq7/hMs iovinax8ekyq3X+VYydFeXx94FRqg+f2voN4uQrrklYfHDigvmOQd5bDmBDy42bTvt0F fQww== 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=QLU2ZsoU8TUfYZh12C6dARliqhL1U3Y7uOfR1EPnfvCNTGon/rfqD2NzIAbJsPl8LS c91RDnZ14N+UKp2K0Rj7HmH3IgKmIMp8VzXyXpvsXIAInRX+WgGSJCQJB400eLDPR42c ZsTco9yNk0gaR4uEbjTMrpamwhCndL6h6uCLKqhftPTi+KQ/zRVG5LaCL6/Rb5qDngti CPzJvqVBtg39WBV3Is/0q4I9kfvCntCPEFuXheNUEqkNUHh03rVIaBf5DjIvZNJ+PbEO LoNCJ72r/+mb/lxbRigun7h+yW0ygdQPEK8dkzLQ71ZbZq/TmJ5Lz09ebi1rixzZprJx JxdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vBbIm4OM; 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 h15-20020ac8584f000000b004031c543b8esi9143835qth.734.2023.08.02.18.55.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:02 -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=vBbIm4OM; 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 1qRNWY-0000dr-Ay; Wed, 02 Aug 2023 21:53:10 -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 1qRNWW-0000dP-2b for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:08 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWU-0000j3-Hj for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:07 -0400 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-7656652da3cso29663985a.1 for ; Wed, 02 Aug 2023 18:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027585; x=1691632385; 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; b=vBbIm4OMvxNnQDlgaD4YReZqq86tCOIbKHBI+EadX6byJP4oV0k8Qya5a9MUk5cZe3 Xn7WtQ024EWTyHxFfxPWE6x1OEefbgS2zsBT3zNwWNQsLbF0Pi2JMTejX/7sZYqAHKVg sREv8uU6H2RrNIL6Spo/tGEZY0VM9E4Cc3iAOoItrwM2HrjChgTKZdd3WeF+v8m/VL+9 Cb7zFV9eQ9Ss2BOsWx7ia/2H5sJxz6OFGMpDpKHlVCc1dGntevwJMnAuAuI/jPhsKoYI wDbq7MyVDFMqjDlK7oagAD+Rtc1JY8NHUyhWjxb+UzXm8fjiFsY+ZvmtEsExTYwYsMiU VVoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027585; x=1691632385; 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; b=Sjp/82IxMeZ8wxqSgK3bRvLr+i9Qf569023b8YB70ZoU9uJKOqeL6/Cdk06qvBV6Xd rJdl1pFs6U1Xj47l6KXI5i3qZF5iE58J+FRalfVEGxmZY6GFuhRXMbFzpeBHq1ELKXCy GqN7U+XTO+j+Cqu3Fec6FW7PxNfUrhuCVZMBZtRE9nmnQL5enzp+aYxHcziEmgKBcni/ JaTkB+qDmXANScDIGeEF6ePVhoy44It2KKTlXBnJt4wrseATvGqZpt65defkvQ3lf30b zw7d4ZVL80m6eIQJoEkOdqcagwqXhOyXQz5z9AmxEFezgy3VlU8YCKaR9rpIdDHI5zS7 iFWw== X-Gm-Message-State: ABy/qLZ9/YOrEbHhynflPVYtE646AQ6QLj73K34LC+Nff8kR+l/K5Jwa Du5hsY3vin0qv/jEDOmZKvyTT2fWfOeqELcSaAk= X-Received: by 2002:a05:620a:4105:b0:76c:bb4d:97cf with SMTP id j5-20020a05620a410500b0076cbb4d97cfmr9543796qko.24.1691027584875; Wed, 02 Aug 2023 18:53:04 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:b659:bbad:1a22:7ef9]) by smtp.gmail.com with ESMTPSA id s25-20020a63a319000000b005649cee408fsm157123pge.0.2023.08.02.18.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de, laurent@vivier.eu, akihiko.odaki@daynix.com, joel@jms.id.au Subject: [PATCH v7 01/14] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Wed, 2 Aug 2023 18:52:49 -0700 Message-Id: <20230803015302.407219-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803015302.407219-1-richard.henderson@linaro.org> References: <20230803015302.407219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.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 From: Akihiko Odaki Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /*