From patchwork Wed Jan 18 15:02:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9524067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8B1E26020A for ; Wed, 18 Jan 2017 15:03:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D517285B6 for ; Wed, 18 Jan 2017 15:03:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71FF5285EF; Wed, 18 Jan 2017 15:03:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1BE4F285B6 for ; Wed, 18 Jan 2017 15:03:21 +0000 (UTC) Received: from localhost ([::1]:41954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTrlg-00046g-5V for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Jan 2017 10:03:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTrl6-00043g-89 for qemu-devel@nongnu.org; Wed, 18 Jan 2017 10:02:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cTrl3-0001yL-T0 for qemu-devel@nongnu.org; Wed, 18 Jan 2017 10:02:44 -0500 Received: from mail-yb0-x242.google.com ([2607:f8b0:4002:c09::242]:33341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cTrl3-0001xz-ON for qemu-devel@nongnu.org; Wed, 18 Jan 2017 10:02:41 -0500 Received: by mail-yb0-x242.google.com with SMTP id 123so609924ybe.0 for ; Wed, 18 Jan 2017 07:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vvRrEBknj00sPrq+lcW8VIcxtQgTCTJn5M6SBoeiRlI=; b=bsy9tuPEaT1CBvLrAAv0K3GbOTKUabQ8J/zbvr7CN5U4y9kT6TUfQnSji8MrNPT0HV 1iryrfGRuiQ2p0nxMOG9WZm0pnJXr82ls9X3SdKTuMFczF+gbd30WcuzVFSAfJzFVdxR Ba/YWd9r/PGnfYn0ujJRU3nwLNV9rXxJa/+5c6MJ3DALiWCPX7idgCA7smljDmQUU1uH ExgiYs3Nx7cH9n4ZAsUtTPsIsO2WnmZsNNDNmpLBjGwFHC3+6+cpHBUPZphGM8FyzEub QMkteuPQsXH4hQk2VQFzmeD048JQaVKjFhaTejSwj/tAcGVM64YyEoCSZNPMir7C9rRJ Updw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vvRrEBknj00sPrq+lcW8VIcxtQgTCTJn5M6SBoeiRlI=; b=YKuvlgjIM1Ix4JAmx9X77sM9e4MLFNfuYf5dzJqGEYervLeeGnuAfH/+B5BzMBmaQo E0zFKUYBP8FuJErRhM6AjKsaLj6a6KP4t4yeG5NLWVITcnNkV5xI+9tsjaaF7wXfRZRd ky13we3u4uz5xAdgYHO7NK0nA3NJAt0kfk01CoNaLNvzSgAtgIpLvuUdXEKPAxGklD6J NRmBh1H8dp+lqRStEL6v5rRfLvFmRcgVLdaUl9NhavvQu4c+hDdTfNu78AZpKvVYpGP9 N2hMZowUKBGXRcWrihHF3Bg+KZ9LzWFPnBzV32uBEXJcdS1iUeAJPki1RWJMOI8DUXUQ bxZw== X-Gm-Message-State: AIkVDXLSeQV+SPYkoiuh2ZhFXtfHV1B0BpF/SW+QxoCmT2JK/pwH2KHGzNycAD6D5rTC7Q== X-Received: by 10.37.115.131 with SMTP id o125mr2680983ybc.116.1484751759416; Wed, 18 Jan 2017 07:02:39 -0800 (PST) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id v24sm243146ywh.22.2017.01.18.07.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2017 07:02:38 -0800 (PST) From: Pranith Kumar To: alex.bennee@linaro.org Date: Wed, 18 Jan 2017 10:02:35 -0500 Message-Id: <20170118150235.23850-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170118150235.23850-1-bobby.prani@gmail.com> References: <20170118150235.23850-1-bobby.prani@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c09::242 Subject: [Qemu-devel] [PATCH 2/2] linux-user: fix tcg/mmap test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau tests/tcg/mmap test fails with values other than default target page size. When creating a map beyond EOF, extra anonymous pages are added up to the target page boundary. Currently, this operation is performed only when qemu_real_host_page_size < TARGET_PAGE_SIZE, but it should be performed if the configured page size (qemu -p) is larger than qemu_real_host_page_size too. (also fixes some style issues to please checkpatch) Signed-off-by: Marc-André Lureau Signed-off-by: Pranith Kumar --- linux-user/mmap.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 61685bf79e..0794a4396a 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -418,31 +418,32 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } /* When mapping files into a memory area larger than the file, accesses - to pages beyond the file size will cause a SIGBUS. + to pages beyond the file size will cause a SIGBUS. For example, if mmaping a file of 100 bytes on a host with 4K pages emulating a target with 8K pages, the target expects to be able to access the first 8K. But the host will trap us on any access beyond - 4K. + 4K. When emulating a target with a larger page-size than the hosts, we may need to truncate file maps at EOF and add extra anonymous pages up to the targets page boundary. */ - if ((qemu_real_host_page_size < TARGET_PAGE_SIZE) - && !(flags & MAP_ANONYMOUS)) { - struct stat sb; + if ((qemu_real_host_page_size < qemu_host_page_size) && + !(flags & MAP_ANONYMOUS)) { + struct stat sb; - if (fstat (fd, &sb) == -1) - goto fail; + if (fstat(fd, &sb) == -1) { + goto fail; + } /* Are we trying to create a map beyond EOF?. */ - if (offset + len > sb.st_size) { - /* If so, truncate the file map at eof aligned with - the hosts real pagesize. Additional anonymous maps - will be created beyond EOF. */ - len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); - } + if (offset + len > sb.st_size) { + /* If so, truncate the file map at eof aligned with + the hosts real pagesize. Additional anonymous maps + will be created beyond EOF. */ + len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); + } } if (!(flags & MAP_FIXED)) {