From nobody Tue Nov 26 09:50:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709059770; cv=none; d=zohomail.com; s=zohoarc; b=A6gRVw5XzpNT6atsUKgGGgGxY3FS+9LG1leDtEBAXOHyv4B+G6I/Svm7dQF+Zs6e8qKtkyr0qGgginJZYxjFo2bxG7/17SlUdon5IRjs8zGWKoRT/Ow+Ex245QVpq05EDjJtoxkd+jeDffX8uD7PHPj99lyKnuq2YdpqRFbQ/gE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059770; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=Kpxz1/9FlWlIVji+Er2Ytuv2fi+3FqVKlI4/eYDV3CGG/rqvmVzdxB0C7J4c/X8OwBSeFec+8h5/Nejellsr9GBu9GOcNaOPraZfXYy4xnktm/c/ji5wlXOtLF8DYzBfTkA+6m8Mu/OiZOd/CTVlZSxB6uH2aDYryU2q3rei4/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059769995567.7077690763789; Tue, 27 Feb 2024 10:49:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Vh-0006bt-LO; Tue, 27 Feb 2024 13:49:01 -0500 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 1rf2Vg-0006bT-Eg for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:49:00 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2Ve-0001WI-3p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:49:00 -0500 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3c19bc08f96so2645678b6e.2 for ; Tue, 27 Feb 2024 10:48:57 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059735; x=1709664535; 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=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=bk2bEhaspsIlDdm37ktyEla0/+/heZjF5/vny1ifWJlHAJ4L76lWvtpPdBmnKaKpKB y93Rwe8e3yo+OVJnX2uvyZiP2V3AMqI6rPAHLLGcsqJn93UHXY5KYxBX79yBsb7rhjAs S3iSOH8VBJdJ3rLqHCgEPqsDtr8phsbwLdVtkOqjWl8OEFQ9aF2Uhq/bQoHj7DKqECZr BH89+pweLb/GdaS2rDClziAFdwxZaCI0NiK89QcNmJ8+CltCWKWa4oQe3Y6AxGcIV4EJ jFNOAGfdYQRKB+brsZSs9+38o9/R0AE4LN3Y153ph5dtydkKdWtzckm/pvhICPu/y9Td Qzrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059735; x=1709664535; 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=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=jKWh3n0MWM7CajGpKSOagmyThxoGV8gc5jSyMwTuIxjW4kcLyrHS7T7Yh3bXLXJDef A35UExPfa5UX6DfxdwmXwdKCG2d7fttv5o86JDE4+Eljsibup/Z6wNdskr0z2xlme8xD oJLAMkFGEitC60z0SesXZunPzpe96dSR7F7b9IdyxD7frQg+fEMbCIm8WaLGM5LSFt8w i/sNRiPDvpsl14hr8YkiZlb9aesq0O6Lo1aDilkI8WGTUJ35/Ra1fUMCh7J2tuhqdhOB XU6Hq4fOj7SDKlwkydl5PjPGVlKZQFUIOuNKr7U78Q4BLHgzeDjrseqc41/+Kk/qXuAE IQGg== X-Gm-Message-State: AOJu0YxGKXBBElc4pFs0IuiFd20RI2qMGt9shsxs1eZUXuyaYi1zKW03 7WL9fMpJTxzdsoCrXLvOWdf8zCZNU2ksrpAWjj2bcKiuSvxrncylamGRf6iwGDGIHYEp82QxMJF P X-Google-Smtp-Source: AGHT+IFwPv20Lunhw0EIl5D610KWJyC2ViJkG+Z2W8wOQe0dzYY6wDqca/yIh4a4kGNXtITZ/38aLg== X-Received: by 2002:a05:6808:14c7:b0:3bf:bf81:c700 with SMTP id f7-20020a05680814c700b003bfbf81c700mr3445815oiw.16.1709059735654; Tue, 27 Feb 2024 10:48:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 14/14] linux-user/elfload: Unprotect regions before core dump Date: Tue, 27 Feb 2024 08:48:33 -1000 Message-Id: <20240227184833.193836-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x235.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059771871100001 Content-Type: text/plain; charset="utf-8" By unprotecting regions, we re-instate writability and unify regions that have been split, which may reduce the total number of regions. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ae0abc4931..38bfc9ac67 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3963,6 +3963,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) } =20 #ifdef USE_ELF_CORE_DUMP +#include "exec/translate-all.h" + /* * Definitions to generate Intel SVR4-like core files. * These mostly have the same names as the SVR4 types with "target_elf_" @@ -4280,6 +4282,23 @@ static int dump_write(int fd, const void *ptr, size_= t size) return (0); } =20 +static int wmr_page_unprotect_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flag= s) +{ + if ((flags & (PAGE_WRITE | PAGE_WRITE_ORG)) =3D=3D PAGE_WRITE_ORG) { + size_t step =3D MAX(TARGET_PAGE_SIZE, qemu_host_page_size); + + while (1) { + page_unprotect(start, 0); + if (end - start <=3D step) { + break; + } + start +=3D step; + } + } + return 0; +} + typedef struct { unsigned count; size_t size; @@ -4401,6 +4420,9 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) cpu_list_lock(); mmap_lock(); =20 + /* By unprotecting, we merge vmas that might be split. */ + walk_memory_regions(NULL, wmr_page_unprotect_regions); + /* * Walk through target process memory mappings and * set up structure containing this information. --=20 2.34.1