From patchwork Thu Aug 15 01:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 819406 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp943616wrm; Wed, 14 Aug 2024 18:07:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUo508gOqHmkL7ozOFe2sGPgqvoNJ+FZ4vG70U2q/gB+plKWDdHajMRrVt0Quah1taNuEsIfJkLNuMb2nP1X/LY X-Google-Smtp-Source: AGHT+IFh+Hj7E7U4bqKVCdTKzRHoUcQZJlCyoU0MwoBHAy7dfKrjJn/k2P3nfyfgrA5LjoLQ1A/o X-Received: by 2002:a05:620a:2491:b0:79f:9fa:8224 with SMTP id af79cd13be357-7a4ee33e95cmr524384085a.36.1723684027616; Wed, 14 Aug 2024 18:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723684027; cv=none; d=google.com; s=arc-20160816; b=hd2brH3wVTEu0FQVfyd0yyYMPuKVVsN2/ApOCXVXjdxnRO6bAKLMs+7RyWJ1HxIoXh M6evr3gmdTEyx18+prnolu4aDux4Y7n1060A//KYQAHSBgt8aTHoMTtWNcQQ+IrUdU66 csv6Abh1nawakbYJpQzsDLjYvSoGjNj20j0Xh8Sg/Z6LW9JXLGU1zQX9T2Tyg0iOdNbE sOxPQZNhilhZ9+DT5dCtKXA8P5pYQQrWA5REynUleUczHE4ikxpP9y4WIGZyLJFKwEZ0 UeQ8ygHrs0TH7ADjvAMIJTlAGUAeMRRyqbnB85L2Q0ne2ODf7hExyb4qhlhsLeU4dfmI 2YOg== 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=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; fh=ZjaPNYKUQmQtR6uATRX8FLXG2zWGBgyu8P/Wz1b3nXI=; b=MO3PqwXdejnE0YTBq7cN+wN3JriXtLyWG3CkC/OHuR3hmBFP/aQn4E/tzDkdqyEpln v57twRnt7PcAsM5DBKnEZm5EXOHgbcuz3BvEUafoI/kaeVi651Kz5mPxh8g/L6lp+f2i kPmxOzFX27WRJri3xHM/eNrhrRYdhVV+oKgbhaRwuo/0lYcVwWizwuAFKl1gSRLeidRb ZWbYzdhsPmNdCQTUrBPb/YKBkJBk5rWY2FZdUnrSTb7IN7gZBq+taJe9kKkdlL22tS97 Rn2ng8MOG1SaKnsV9auSIbR7gJJQ16SJjXvotJQ3fOiVZUzGNfTyUoVRLW40XFBUkRXv UkMw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cx3vdN45; 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-7a4ff0e5cf3si57414285a.429.2024.08.14.18.07.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Aug 2024 18:07:07 -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=Cx3vdN45; 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 1seOwk-0006AL-Uq; Wed, 14 Aug 2024 21:06:35 -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 1seOwN-0005yr-Uk for qemu-devel@nongnu.org; Wed, 14 Aug 2024 21:06:14 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1seOwI-0003S7-F5 for qemu-devel@nongnu.org; Wed, 14 Aug 2024 21:06:08 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7bb75419123so437717a12.3 for ; Wed, 14 Aug 2024 18:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723683965; x=1724288765; 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=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; b=Cx3vdN45dclVWn0S4nDHLCdGCbb8ADcx4DlHBz53F9ZmDff/WMnsR1XIONmCEEKtXg E/0xPCKLuXuaeOuLv8sJ2n/xsvOx0sgKLUKMHXwLYYEf0WfRatp4l5xQnONToezf8+Ia +2srvJ9sAZsQPn91WAg9ba+jgBiHzL+H1aMpYW+9o3zG60ik7iDuIFNf4mjmdx9c9NUr xb6+Q4ENv5VHuiMqGJ3C0lHxGGN0IHh6LHyWQP94m9FhFmpcOlADLbo7HmQOfWYVH8Ro YpRnrIBBtX54PAz3R63H/TpVuQNQad0EIKcY87j0X2aVFzdU2spWf0V6camu4T4/+VFl PxKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723683965; x=1724288765; 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=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; b=LtNBt/WHZjpXaMYnd6WviAnoQo+bnJQqZKt9kYd+kqrjy9/7yB5V1VeYZ9ZfaH8q2/ Gl6wMXftV/TMgZXi6pDLp0WcEAGZrwz56hKU1AJOHbpvYWZ32v9m20haQgtU2FtFn1Gb pgbPlaUQP/s8EKFb3+/il982xc2VVVXTTyFJclJU6cIINGWocBhs5kTquUzU1LyjWRxF 2VTLvZkR6x/usAHhPLB3HqTPiMfBMF0+bnvfti2BNgq/IEQvcdYlL+pK6aV6Z9aDc6ht GlE50Hoaow4qByZexgO1+zdg2JfiMf03CmVodATvmBUVTiOFw06fK3neXCYw/HHFhU31 7TIw== X-Gm-Message-State: AOJu0YzeM/Fb4mWO7yQhOcRM90MptYvA3dOQGlUAvg+8vz2j5n7ezcUI dMF8/PwhemGSnJsklWbXmIOojT8BPatKLe0Sjru96oic8ZIVvVanfaVyBEyChsqw5pWnJTQwuKf E X-Received: by 2002:a05:6a20:d493:b0:1c4:9e5f:c645 with SMTP id adf61e73a8af0-1c8eaf54179mr5900839637.40.1723683964474; Wed, 14 Aug 2024 18:06:04 -0700 (PDT) Received: from stoup.. ([203.30.4.111]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1bd5asm179907b3a.177.2024.08.14.18.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 18:06:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PATCH 1/1] linux-user: Preserve NULL hit in target_mmap subroutines Date: Thu, 15 Aug 2024 11:05:56 +1000 Message-ID: <20240815010556.535100-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815010556.535100-1-richard.henderson@linaro.org> References: <20240815010556.535100-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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=unavailable 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 Do not pass guest_base to the host mmap instead of zero hint. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2353 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/mmap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4d09a72fad..6418e811f6 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -560,9 +560,13 @@ static abi_long mmap_h_eq_g(abi_ulong start, abi_ulong len, int host_prot, int flags, int page_flags, int fd, off_t offset) { - void *p, *want_p = g2h_untagged(start); + void *p, *want_p = NULL; abi_ulong last; + if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + want_p = g2h_untagged(start); + } + p = mmap(want_p, len, host_prot, flags, fd, offset); if (p == MAP_FAILED) { return -1; @@ -610,11 +614,15 @@ static abi_long mmap_h_lt_g(abi_ulong start, abi_ulong len, int host_prot, int mmap_flags, int page_flags, int fd, off_t offset, int host_page_size) { - void *p, *want_p = g2h_untagged(start); + void *p, *want_p = NULL; off_t fileend_adj = 0; int flags = mmap_flags; abi_ulong last, pass_last; + if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + want_p = g2h_untagged(start); + } + if (!(flags & MAP_ANONYMOUS)) { struct stat sb; @@ -740,12 +748,16 @@ static abi_long mmap_h_gt_g(abi_ulong start, abi_ulong len, int flags, int page_flags, int fd, off_t offset, int host_page_size) { - void *p, *want_p = g2h_untagged(start); + void *p, *want_p = NULL; off_t host_offset = offset & -host_page_size; abi_ulong last, real_start, real_last; bool misaligned_offset = false; size_t host_len; + if (start || (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + want_p = g2h_untagged(start); + } + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { /* * Adjust the offset to something representable on the host.