From patchwork Fri Jun 30 18:04:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 697982 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp598254wrs; Fri, 30 Jun 2023 11:17:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHFuppwrmwK3ro0dEmAC5q+mpIBwEH+CDC8NvAnBM23WRD9XEaWDzaSVrHIDPwXHRW8YDjd X-Received: by 2002:a1f:4585:0:b0:453:b080:632d with SMTP id s127-20020a1f4585000000b00453b080632dmr2827528vka.0.1688149037538; Fri, 30 Jun 2023 11:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688149037; cv=none; d=google.com; s=arc-20160816; b=GosH5+g845yXtIEpodMd7yvesrTbon7TwO2J1kPYcCjLILWxoaIYJl5lDUfpEKA/6R 08NUizpWD9e/3WPsbr6Iec2ZLAWJpYSoth0lsVCc7VzHUXuIq0QjFs4wkov84WaIQvp8 SxXnDW4IN81EgDmE1Kan2/icWF7OjLl9I24vCfSrfDm7fL/RSHz1YCv1NiWoZiMSCxKd 4WkhHCaP4kLv1DnnArtNWGDGFR53MWSUDlxMyHOqIu38GW0fok/ofQYI9dA9HCKv7xHM uwVbtEy2o3WsaQq2yeK15aJa8RQrrgo7AkXCEkSZ0PHO0Sl0op+ELdeJJVrgnCIes0iI D5OQ== 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=FlozXpssbNBwOzj56lVjhGsxc7X6CRXAuo5Pr/qBStk=; fh=WuTBZDcfojtFbKfkJjfEwZ/JCpHxFhyq5cXQ7fdJG7M=; b=I9QCA/+hq+jpMvSZ7Qi8RF4QtWDOpfxlN1DOj/SfOVjIrG0R4qh0JW2qJML+G6ails P6piwOyQ2kb1OWQymJkFX73FMf2SnY8pCYZb5cF6RTcc0fpV/NeqlDhlmHmPK0crh0bq /2Ryxm4EA4Lx/xQln4NSsSBkRdTrSto+W8/+ooUZtSldOZlZ7H8rCfK+kykXVEsvwsF1 3u5nWCOxLfPf6XoTbVVw6MvSEVkrUep9IFmHAEsC1BmhEJabBodKlNJsVP8kzuHbur+t sCogye2Gzg9P0Oe23Ilgo14BteLa9p3BUydkYYbjOIfZA/La6iRyrmEToFjgbz87lIJO JVHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F1D3YyQI; 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 a9-20020ad45c49000000b006260ed5aba7si7924471qva.91.2023.06.30.11.17.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 11:17:17 -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=F1D3YyQI; 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 1qFIdC-0005sl-BW; Fri, 30 Jun 2023 14:14:06 -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 1qFIcm-0005ar-J0 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:41 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFIch-0003YD-FL for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:40 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc5d5746cso12929645e9.2 for ; Fri, 30 Jun 2023 11:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688148814; x=1690740814; 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=FlozXpssbNBwOzj56lVjhGsxc7X6CRXAuo5Pr/qBStk=; b=F1D3YyQIsUqLIAaICEEKjm6d0cCSBgHPHoZidptjuqHj4OspPP8SlKAXUAAWzQW8CA o4TVMouZMZ2JYSVtZaIRT2McNJ1Epwb/d35ieSmgFd7kyuwV+OgpKECvHGuzy8DP7mMx ExSmVElVtD9AOFgVxYAf4ayuEIuVqPsjZnNovNoxAORSmjhmkQwOaWfnOfGdRG8eafpO 2kmq+AJu0IgEzdzZb6mnfS9OgKAvyTmSu3l+9PcxLdJabqosHmelSPhnm9mEqFo0O7Vy whue4U50aW079Yq8tx8E675UkqpM2ZpxAQ1XpU63v7m7/GxsWYZuml0GgUaEbJSbc2yP NdlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688148814; x=1690740814; 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=FlozXpssbNBwOzj56lVjhGsxc7X6CRXAuo5Pr/qBStk=; b=TWZoiIsZRmya7AKcYBsI1a6QlbYX25DadRQgjgx3IMJEAovM5nR2lQ1Hw16cXEIbY0 FHe5QP8XJfhXdQJ6boKUnDf/ksGYDeg/I1Sgx1FDM91vyOIEJRZQnYea/FV+xOslJVOE 9WKo6B+8QFXB2PHupJKGzabWMVnHX9ns/Z6yIhlexkvy2azhbc59Fe8z5oF7RD8sNgQX pXc+CpE75UMSnFxerHD+DUrJbjxOnvY1DW4c0LNB3RdjHYMW3jOzLAbt0oMN5eccHFtx 452I3vKD+/GyMpMUxq/CnyIE3j6P/bjYkrVN1BVp6bsGzBXoUL4UengCPfgGgmad0Z7O hJPA== X-Gm-Message-State: ABy/qLbDDJuX4M/SOgkj60BrTgWA8YiJHp91PYObfCR9O1Uk3o1QVolS wgfQD3KP2160FzHdwGKqzi1Law== X-Received: by 2002:a5d:4c83:0:b0:314:1ce8:80b2 with SMTP id z3-20020a5d4c83000000b003141ce880b2mr2828534wrs.24.1688148814162; Fri, 30 Jun 2023 11:13:34 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id w11-20020a5d608b000000b00313f7fc35e9sm11940282wrt.63.2023.06.30.11.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 11:13:31 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B8FB61FFDA; Fri, 30 Jun 2023 19:04:27 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Paolo Bonzini , Stefan Hajnoczi , Leonardo Bras , Laurent Vivier , Peter Xu , Juan Quintela , Beraldo Leal , Radoslaw Biernacki , Qiuhao Li , Peter Maydell , Yanan Wang , Riku Voipio , Wainer dos Santos Moschetta , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Thomas Huth , Laurent Vivier , Bin Meng , Marcel Apfelbaum , Bandan Das , Cleber Rosa , Richard Henderson , Leif Lindholm , Marcin Juszkiewicz , qemu-arm@nongnu.org, Darren Kenny , Alexander Bulekov , Ilya Leoshkevich Subject: [PATCH v4 33/38] linux-user: Emulate /proc/self/smaps Date: Fri, 30 Jun 2023 19:04:18 +0100 Message-Id: <20230630180423.558337-34-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230630180423.558337-1-alex.bennee@linaro.org> References: <20230630180423.558337-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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 From: Ilya Leoshkevich /proc/self/smaps is an extension of /proc/self/maps: it provides the same lines, plus additional information about each range. GDB uses /proc/self/smaps when available, which means that generate-core-file tries it first before falling back to /proc/self/maps. This, in turn, causes it to dump the host mappings, since /proc/self/smaps is not emulated and is just passed through. Fix by emulating /proc/self/smaps. Provide true values only for Size, KernelPageSize, MMUPageSize and VmFlags. Leave all other values at 0, which is a valid conservative estimate. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Message-Id: <20230621203627.1808446-4-iii@linux.ibm.com> Signed-off-by: Alex Bennée --- linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ecd9f5e23d..08162cc966 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8042,7 +8042,36 @@ static int open_self_cmdline(CPUArchState *cpu_env, int fd) return 0; } -static int open_self_maps(CPUArchState *cpu_env, int fd) +static void show_smaps(int fd, unsigned long size) +{ + unsigned long page_size_kb = TARGET_PAGE_SIZE >> 10; + unsigned long size_kb = size >> 10; + + dprintf(fd, "Size: %lu kB\n" + "KernelPageSize: %lu kB\n" + "MMUPageSize: %lu kB\n" + "Rss: 0 kB\n" + "Pss: 0 kB\n" + "Pss_Dirty: 0 kB\n" + "Shared_Clean: 0 kB\n" + "Shared_Dirty: 0 kB\n" + "Private_Clean: 0 kB\n" + "Private_Dirty: 0 kB\n" + "Referenced: 0 kB\n" + "Anonymous: 0 kB\n" + "LazyFree: 0 kB\n" + "AnonHugePages: 0 kB\n" + "ShmemPmdMapped: 0 kB\n" + "FilePmdMapped: 0 kB\n" + "Shared_Hugetlb: 0 kB\n" + "Private_Hugetlb: 0 kB\n" + "Swap: 0 kB\n" + "SwapPss: 0 kB\n" + "Locked: 0 kB\n" + "THPeligible: 0\n", size_kb, page_size_kb, page_size_kb); +} + +static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps) { CPUState *cpu = env_cpu(cpu_env); TaskState *ts = cpu->opaque; @@ -8089,6 +8118,18 @@ static int open_self_maps(CPUArchState *cpu_env, int fd) } else { dprintf(fd, "\n"); } + if (smaps) { + show_smaps(fd, max - min); + dprintf(fd, "VmFlags:%s%s%s%s%s%s%s%s\n", + (flags & PAGE_READ) ? " rd" : "", + (flags & PAGE_WRITE_ORG) ? " wr" : "", + (flags & PAGE_EXEC) ? " ex" : "", + e->is_priv ? "" : " sh", + (flags & PAGE_READ) ? " mr" : "", + (flags & PAGE_WRITE_ORG) ? " mw" : "", + (flags & PAGE_EXEC) ? " me" : "", + e->is_priv ? "" : " ms"); + } } } @@ -8103,11 +8144,25 @@ static int open_self_maps(CPUArchState *cpu_env, int fd) " --xp 00000000 00:00 0", TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); dprintf(fd, "%*s%s\n", 73 - count, "", "[vsyscall]"); + if (smaps) { + show_smaps(fd, TARGET_PAGE_SIZE); + dprintf(fd, "VmFlags: ex\n"); + } #endif return 0; } +static int open_self_maps(CPUArchState *cpu_env, int fd) +{ + return open_self_maps_1(cpu_env, fd, false); +} + +static int open_self_smaps(CPUArchState *cpu_env, int fd) +{ + return open_self_maps_1(cpu_env, fd, true); +} + static int open_self_stat(CPUArchState *cpu_env, int fd) { CPUState *cpu = env_cpu(cpu_env); @@ -8459,6 +8514,7 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, const struct fake_open *fake_open; static const struct fake_open fakes[] = { { "maps", open_self_maps, is_proc_myself }, + { "smaps", open_self_smaps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, { "cmdline", open_self_cmdline, is_proc_myself },