From patchwork Tue Jun 27 16:09:38 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: 696881 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3867531wrm; Tue, 27 Jun 2023 09:16:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Z+8h2R8ZhXaFLpe/TL09s3exa5qfS7tTFIcWXubkYxtGQNu/+4RexeGiazcFlVE1ndk+5 X-Received: by 2002:a05:620a:1728:b0:765:42ca:3ca5 with SMTP id az40-20020a05620a172800b0076542ca3ca5mr15254931qkb.66.1687882585710; Tue, 27 Jun 2023 09:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687882585; cv=none; d=google.com; s=arc-20160816; b=yN/gDCMpj5268QCVc3BXGr2ju8LRm2nV1zZI9blHvgN7ONiGGLiegPbrhjDZOwbSVv x1Rz7+QABNpFkDS3vfbw0Q0DynWT/lL51wQGknUaQXD/s0Ch8QolT5VktRD5m81vDTgq k4ajnsWHfRnmaS+2Jiql7sKz6d4ba8vEc7kparqIWrFUf8A73WpLv7lrmxlkYYhcMYVV Z6jkhPRS852PtlDyhYVz8ascxbtUBld3+lnMfXiZrFY2ieP96lQ6BGC/dqgg3AkTXBH4 5ubL+WpeVyAWRCD+tOQKyo0JZTRqchRCTBZ0Vh1h8mPFsS+mWjKareTpceJUQfMLCG/0 To+Q== 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=B6/adVaiTRj/g/M/QPigvyXZO+x+u/FNsaNX2Qo1+tw=; b=Yz1DMuJuUS3yzLFtL/3IuhqQAJZ0RGbHlmgflJcZrgVoS2D9IoQVQQGioAgymi5i8g 1xn4uF9HrPC2Sc1MFTvhGXHZCDd0o5ZJjO6R8v3n6IXTKkPa6KOL8fx1GCFCK851nZd7 yDQpLuH6Z355fCvimVuXdDdk16tc9vziOpK1/yykEtaGOe460UT1rAMaqXimkSexl8+C swa1UPWJ7hWkej/7eN8Ymxx+tKm/Q3XXMCUdPhxV/tAfbiga06Ud0HOsjul/nCYpGIjY nJyr4s/mjzCRNTAT+LI3EUBj6/2U5BCxaJ2wBAy62Yg0BSK6UCSjZUJ8ze8tjk7voqQp ApeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fxlzYjf9; 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 i4-20020a05620a248400b00763e13b62desi1341475qkn.400.2023.06.27.09.16.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Jun 2023 09:16:25 -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=fxlzYjf9; 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 1qEBMO-0001CK-AW; Tue, 27 Jun 2023 12:16:08 -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 1qEBMM-0001AU-9i for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:06 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEBMC-0008A8-OJ for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:05 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4fa48b5dc2eso4795630e87.1 for ; Tue, 27 Jun 2023 09:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687882554; x=1690474554; 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=fxlzYjf9WaKOCmve8bGBNYL/bEMhrdhlgYxNvwKkRuWBJ1T3ZBhczH9MLYivi0IL2D FmrTlOewL6qZY1AOUUFckHkXuyLryZVJxvO37TdeK3Oi5ubh6REiZUXm0h9EIep2uQAj rt1Fhp9fj72oPbQRhXgoPHiky9WwyO1EX0m7p5TNTT2LS84J5g5rH2yh739ODzXivHOt DzhJ0K3YeEl+KuMkwQATlRLIYdT/Zl5lFxUmn38EtNqO1FROgEgpO6WT03gpfEuhb13J B0jEOe3ca1opvJW+VxvwDOq1A/Sf+91iT3BG2MAFTtvjN0MKE5t5mY9Zqfi5/uhbNLJk 2GRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687882554; x=1690474554; 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=Xh9InrzmmDzz9NJB38oYAJvD8jD+Hj5kdRZqlpeURJVD3JWM3wuKCNGDufZH62FWf0 3fRXkfEcEMo70YeJ270bdZJQh5JUpDxn9BPhGKOTS7GnF+7JCbEVZQzNy/vIsRQBdL1q qLBufi/3/R/ioxibJcq/4SYUfFXbTwO/u+n7nA3RxQAudTMVWKatGmo3Vw370WUSbaIt fSNW2i6h2d6f9Gsr5tPJOG2l2UuwnoNdF6xwv5HUR/ypsyGlMpx/zbslx0iZx9ihpcKu bpUrnFYBxG9Di+igFKgY0Q0F5sodSHiRceyoDvmvkP6bEISapIq1RuAem45cRIyFqn26 ndcQ== X-Gm-Message-State: AC+VfDxavjOvy5BovFVhKRAk9AI5xG2YWoq3uXjqzbqu646yDKP81sf6 vtGtsmyxmKGykmHOlcO2ZEAzoQ== X-Received: by 2002:a05:6512:15aa:b0:4fb:74d6:6154 with SMTP id bp42-20020a05651215aa00b004fb74d66154mr4784538lfb.37.1687882554623; Tue, 27 Jun 2023 09:15:54 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id e3-20020a05600c218300b003f9a6f3f240sm14112956wme.14.2023.06.27.09.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 09:15:53 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8A3201FFD7; Tue, 27 Jun 2023 17:09:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Juan Quintela , Thomas Huth , Cleber Rosa , Leonardo Bras , Beraldo Leal , Peter Maydell , Bin Meng , Yanan Wang , Darren Kenny , Alexander Bulekov , Marcel Apfelbaum , Peter Xu , Radoslaw Biernacki , Laurent Vivier , Paolo Bonzini , Eduardo Habkost , qemu-arm@nongnu.org, Stefan Hajnoczi , Richard Henderson , Bandan Das , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Alexandre Iooss , Marcin Juszkiewicz , Leif Lindholm , Laurent Vivier , Qiuhao Li , Mahmoud Mandour , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Ilya Leoshkevich Subject: [PATCH v3 31/36] linux-user: Emulate /proc/self/smaps Date: Tue, 27 Jun 2023 17:09:38 +0100 Message-Id: <20230627160943.2956928-32-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627160943.2956928-1-alex.bennee@linaro.org> References: <20230627160943.2956928-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12b; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12b.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 },