From patchwork Tue Aug 13 09:46:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 818813 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp192042wrm; Tue, 13 Aug 2024 02:48:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVU4lvSDlTQujfZ+Gej+mUs5GMe4+Az91NBkdkeNDn7zFo5vTp08yUkoZezSgQOgO4HVi6LF5NUOm2HAuKmk9lV X-Google-Smtp-Source: AGHT+IEDB28cZfNLpCjBhAB3RWHhfBJASI3eUkNJ/1/+oUEGTeuZo2/oGOKMYiGl7nlcsvn2TChZ X-Received: by 2002:a05:622a:59cc:b0:453:1554:c49d with SMTP id d75a77b69052e-45349999cb0mr43584221cf.37.1723542481559; Tue, 13 Aug 2024 02:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723542481; cv=none; d=google.com; s=arc-20160816; b=a7NMuyySFX94/L6pbJUBPebSSLIBhdb6QJoI50lsvYy6NDMLGofNz4MMM7A3YRJAx6 Mfpt5HEHwRricQJLcZczY6Sw9JE1ovrk+j5UbRWEb3XpUnzA+lmNshBFb59XjnVbkDwX uCq3tpsPGPi+1fQhZe22m31EVK8TahgBPOei/zdZWS/ogH/B0KITASP0BUSv5zIlnxv/ AwJ5d1UA01CvyjIHddW0/1weyPwbIMfy/9LyVh4bgsAgMnfjBri+crMyPYPItm3ZBU1p sslqd+V4h6dT+fLqcOon7nZbWJJCQNIzwIXHExVHmCvnmYl6aYxsIogsv/KD9ydv2ghd wD3w== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; fh=ZjaPNYKUQmQtR6uATRX8FLXG2zWGBgyu8P/Wz1b3nXI=; b=NF9OGwwmT8GVQfQ0v0crFYKs4GAjCuSCWFu+3oFCVJMgADAlPVB6WwZuxb5BDTL1Ku PPXlN/QE7RZLsPofg94zL6n3vXRXhDHgeG5O70FA9lac8dSqz6HmewnQ+uH+pl5+FtTI EsdSJzdkCdh8Cxmd0p6JnUCTWcLwhvSSLDcJGdHmXhi9vQF222v/ZyNDq0B7+hOGqghK wUwzJwEx2gyBkh/BGaytUL/Nj155oXx6r0qbZUAF8LU4AABanXodVLzf0/NcbEcXMJXb r1CKtPWCIW+dONok9EPFLxKkHZ+zfOFsCI0uNVc2gch9YRnyM/vmxMYpECu9baWwOKKJ 9J3A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QOH0tPjm; 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-4531c2b0ad2si76820721cf.698.2024.08.13.02.48.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Aug 2024 02:48:01 -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=QOH0tPjm; 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 1sdo7T-0007Xx-HA; Tue, 13 Aug 2024 05:47:11 -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 1sdo7O-0007Wj-8W for qemu-devel@nongnu.org; Tue, 13 Aug 2024 05:47:07 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdo7M-0001EC-8W for qemu-devel@nongnu.org; Tue, 13 Aug 2024 05:47:06 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2cb5e0b020eso4084066a91.2 for ; Tue, 13 Aug 2024 02:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723542422; x=1724147222; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; b=QOH0tPjm6ulWxs0MFSjc2jHZS0HlB80bWRpjzICc3CCay2lhWSEZQDplbLwSR00cHb XEOPN/4DvdcDxCHSd4ChAG5CCwqSFsaOFXtw2XeAZIEv0Ih7mkmYsRzKxW6HBted9cPt RFZ2kSp8h4qvOTABMilIwXQgbxLZRqbOh98wQ3IJFKV9WGqPhjYvTi/RZUZB0217CTdk J6Qea8Iyrf6hrZd4KY5BzpVp+o+iGYp6BssSpThF+szt8PzX1sAFTTCmrSiyy5AgIUWG etnDBjEYUpx8syut1dwQcn/xzFERXwx4jP5mgY8EnLNGzVWOwYAQcjNmi9P/WoZ4LU1C UZ9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723542422; x=1724147222; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+O6tEfQz5lUPeGvFYdt3re9qjwA4R55lMLBHq/WO0OE=; b=ALiNZqacSjqjPdUhaXO+jEKf20aiZ2CnU6MK5KJ7NWDEz//NPIDNnhcoWuj/cDoIAF 2A99UaQv4ZdXc/LqeYsr8tm3xhL+iCedN40FW5X4OAQ7etyvTqkgO6rmAMtBuAg6mnVL 5iiUzGVQgs1xtcPoD00EVLLok6DRPEGTBON0PkyOe72WciiSR54BKThwy0sTInJoUPCR 49BXVUCMZ3xgBnWqyrrlu5yxCHRAdQcgxjLOyA6bsqtVUtj7rPyUrbBHtrPwVejWePlj vmv2atHVRTzwBO3qGzfxClvyXRw2atY/gSkJ2+DmyqGmpg7myNNyKFNlad+2rIuSCIas olOw== X-Gm-Message-State: AOJu0Yy0i00USh25nnHhZUEEJgJ0+HvYobGdbuds41VuBsATlSXAHysJ QS7n3bneMsZqvp78Dk34OzPkZh523Hyi7M1NTqz3hEZvaMn+KrPqGkE/0cFh5uc1i/ANluxtl2z Sv4s= X-Received: by 2002:a17:90b:b05:b0:2ca:5a46:cbc8 with SMTP id 98e67ed59e1d1-2d39265245dmr3356282a91.26.1723542422050; Tue, 13 Aug 2024 02:47:02 -0700 (PDT) Received: from stoup.. ([203.30.4.111]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9c9d745sm9968126a91.28.2024.08.13.02.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 02:47:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PATCH for-9.1] linux-user: Preserve NULL hit in target_mmap subroutines Date: Tue, 13 Aug 2024 19:46:54 +1000 Message-ID: <20240813094654.306430-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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.