From patchwork Tue Feb 27 18:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 776274 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp308341wro; Tue, 27 Feb 2024 10:49:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWPHznRm3IR84XbUKR2BBINH3ttO0mK1YGpdfSPWW79efD61RBCnCbptCxxrqZtUVNmCjyrWHMtQKDQe7oRFLkm X-Google-Smtp-Source: AGHT+IHf+W8Ld41ZM93GdEVZH52CnKZgrpLgQrEB2wa7n+f4+8Pm9scGjhprZBe4+SozjmENUj2V X-Received: by 2002:a05:622a:1a8d:b0:42e:8d15:41b8 with SMTP id s13-20020a05622a1a8d00b0042e8d1541b8mr5555349qtc.55.1709059769482; Tue, 27 Feb 2024 10:49:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709059769; cv=none; d=google.com; s=arc-20160816; b=eOghuKvXQQaJeLzcoeOIplvnNA7ADN2+BOrF7vjuo1gtT+WvnWAAY1rU3uQ9twX3No 8uF3ygSuTPLy/Ka+uMKF4a/flYnT22yReCazroPqxBjBhBU2z4TBlpUrjCgSslrR9r6l YOnFWdZRCn2dlNRkrvEvjJBGYTHlIysJSwn6+GtnxFCL+ZPzH+Ig5QEPOaIJhjzjcncX zOZWdNR6zYm6muWbDFzidxyKQr+tGTPIf3NPltFB9Yd5uk36WGc6l0GKsAARmqzC9rNn G5E6IaJcjZFUJsYZ9QKG+4z37KZhKp00eMqjUuagZPKnueyc7/4Xr37fzUq9px8rsrxG HdLQ== 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=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; fh=Vvliz9ENSk/yCY42nG87aL5dW+Zo0lduSx74U3lH2V8=; b=v8UQ8xuu6hLikuhYZlMvJKjN5nXXQJf0eGQ22XyljxQn2MC1ieHmzJhOSbdChshDAU Nq6BVKkNVJ4Yg8tV6o3FWC6fmS06j8S/GrrAcCCHL0HIGRofTWnbZ4slMKSVxn9+pYVz 7oJ8qbxSV/pr1hq/5iWQLOvAotycXs3GPN8Coz3i4hKqT+0UCImUulW48ZJU9aW2/zuV INg+xK89oD9ScPlIfLRgnqDT94vnZaGtB8ylBwDfpDiEGV4MgULBLF2pW7aJ7WVel5h7 BoC1VURgzpvucjTXefdVYHL0FW/3L7HVwZtwHscs0i2x9V1HX/+6lTIo7llw3lV69s6i k3jQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bk2bEhas; 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 q9-20020a05622a030900b0042dbe58b542si8573262qtw.704.2024.02.27.10.49.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 10:49:29 -0800 (PST) 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=bk2bEhas; 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 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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) } #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); } +static int wmr_page_unprotect_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + if ((flags & (PAGE_WRITE | PAGE_WRITE_ORG)) == PAGE_WRITE_ORG) { + size_t step = MAX(TARGET_PAGE_SIZE, qemu_host_page_size); + + while (1) { + page_unprotect(start, 0); + if (end - start <= step) { + break; + } + start += step; + } + } + return 0; +} + typedef struct { unsigned count; size_t size; @@ -4401,6 +4420,9 @@ static int elf_core_dump(int signr, const CPUArchState *env) cpu_list_lock(); mmap_lock(); + /* 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.