From patchwork Fri Aug 4 22:00:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710257 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229915rwb; Fri, 4 Aug 2023 15:03:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYKE0OMNuURMjBhgYa+AxfsaclgeAJx8MSsyrCYmfP9KDDPHttHdI5Otvw+QB7gFyezqmd X-Received: by 2002:a05:622a:93:b0:40f:efce:dcf with SMTP id o19-20020a05622a009300b0040fefce0dcfmr4452735qtw.16.1691186605286; Fri, 04 Aug 2023 15:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186605; cv=none; d=google.com; s=arc-20160816; b=iGzMcj3aDxZP3sYTvSHCRmku6AxSvIjZECNJlQPDtqjzP7rqr2QLuyfpMPyr/2xbZ0 19adrhby0d1LydxNcw78goLEiph5azLVpgvbBlB/VddsRiKjU3on5+neyJtO9CRoqI78 2WThShHNndZPB0Y5ZBKr26T9ckcnjWhTsb9JwzIEpPHIQaB0E/lSJo08bl9LVKRfmaEl 95AFZ26GxhDvhBn5i9jzWbYi7rAyO+YleTT1i6Yyp1h+gga8TmVgFBzKaEM2zsTeAu/j DKIX+s6zAa4vlf+oZiNxR+A1MpSzkiuEmA4gwwT8zOaOS91kMNWmQoeNcFbzetElpkEA tIvg== 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=jsOBWOFossCHszj7zLjYTuH7ZUTZ9Rn/iuADRRkhtM4=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=QcJLgegNPpMrD9ISQtF8nP4v0LWOfNRvCfBMvCZmmiWX8/w+0pxlEdIc9t8EqRnz6m uQSCi0dUno0ChHf6wqjFeNnJ7EPL2fGeHPjjTt14tBQJ8JEoMK/b/1UzhdzMyX7TgDPf gPVlzuBVGMSINR4xnT+LU7X/6mpytBF/6x/FuzaPEbp1r9vp5jWCr9C/02x2tzOE2oo4 15b8VdalzyJE0OIrhoKMw1/VfPUZbFYGd78lxwKj0HJOjrNMjP1MRUVC687lHgxFovK4 weOYJUu3pxmO733B51Hib4otNGN/QW2ETMIff4hC74o+PyOjip0L4yQ2jvj8b4wfLMml UbRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yXscK9b9; 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=fail (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 c8-20020ac87dc8000000b00403c944b5bfsi1905617qte.320.2023.08.04.15.03.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03: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=fail header.i=@linaro.org header.s=google header.b=yXscK9b9; 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=fail (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 1qS2r2-0004nF-VK; Fri, 04 Aug 2023 18:01: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 1qS2qg-0004Vb-0q for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:44 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qb-0001co-Fs for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:41 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bba04b9df3so22272815ad.0 for ; Fri, 04 Aug 2023 15:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186435; x=1691791235; 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=jsOBWOFossCHszj7zLjYTuH7ZUTZ9Rn/iuADRRkhtM4=; b=yXscK9b9r6KNgNehdsdctpn8c7t/Kb6ORtI6SYzTSb4bhdHdiPyVv3uqHJYv9mvk8n K7gDxYs7hH4+RT0Co24U9elqtZGHrHYc99q2cu26E0NPUkaOhQ1GN9Xnl+TfKmnp7RyG 3NGMOWS3eI3POH8Al7TwnZPFSvAvMag0Knic/zRhdYD44cJxSxSAZCTlaYNzwNvgD7NS a6KAZDNkZtYaNrYo/JOhXPneQatOmCeN2GRREOxBz64Ohi4bJTz2PGEA6wrbEOTxR23f YC/pvAfWfkshLPUwGpnkwVL+dlF9rsb874eWmGs7Vvh5ABmAgVIH7LTnl9n8KO/zjloo O+Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186435; x=1691791235; 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=jsOBWOFossCHszj7zLjYTuH7ZUTZ9Rn/iuADRRkhtM4=; b=KcaGMRFmjhP+dNYwJFJu0v4jNGpG84iOBLPQXVPvhWM3vEqIk/yALGVaagAmuxH9lB QhwcB2hHturXoXlTxnsn6ahAnzIG2cFJGeOfN4ZGzlmz4JytPkGFgFyvdzCJnsb1CD0G 7MjaBSk3ikrYLcZOZUavDb6vVHi82eU/Oqj9lx1lUc++gPdNO2JLrCevrU/nVzzo2Fm8 gBGlGOIHmsOFsp6IrRqf/Tm50rLtEWf1cim67yi8dlW3UHFW5rsM2jr1NfBHb98118xB t5Uy335ik8oOC9t7dQNLoSUN1B6T1UoBr11OhiVYHMwwcSD79J2bA/Wn9pUeYFy9SWiV m+dA== X-Gm-Message-State: AOJu0YzFC3xXaz2VsVmOOqmq7Ovee4pCKvpNighrgSkc7j8HZXyNTxvR EPyttmajPabBzclJRM3vxBpoaLJv9p7OAS5MfHY= X-Received: by 2002:a17:903:41c6:b0:1bb:ab0d:4f76 with SMTP id u6-20020a17090341c600b001bbab0d4f76mr3880221ple.58.1691186435018; Fri, 04 Aug 2023 15:00:35 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v9 01/24] accel/tcg: Adjust parameters and locking with do_{ld, st}_mmio_* Date: Fri, 4 Aug 2023 15:00:09 -0700 Message-Id: <20230804220032.295411-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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 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 Replace MMULookupPageData* with CPUTLBEntryFull, addr, size. Move QEMU_IOTHREAD_LOCK_GUARD to the caller. This simplifies the usage from do_ld16_beN and do_st16_leN, where we weren't locking the entire operation, and required hoop jumping for passing addr and size. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 67 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index ba44501a7c..23386ecfde 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2066,24 +2066,22 @@ static void *atomic_mmu_lookup(CPUArchState *env, vaddr addr, MemOpIdx oi, /** * do_ld_mmio_beN: * @env: cpu context - * @p: translation parameters + * @full: page parameters * @ret_be: accumulated data + * @addr: virtual address + * @size: number of bytes * @mmu_idx: virtual address context * @ra: return address into tcg generated code, or 0 + * Context: iothread lock held * - * Load @p->size bytes from @p->addr, which is memory-mapped i/o. + * Load @size bytes from @addr, which is memory-mapped i/o. * The bytes are concatenated in big-endian order with @ret_be. */ -static uint64_t do_ld_mmio_beN(CPUArchState *env, MMULookupPageData *p, - uint64_t ret_be, int mmu_idx, - MMUAccessType type, uintptr_t ra) +static uint64_t do_ld_mmio_beN(CPUArchState *env, CPUTLBEntryFull *full, + uint64_t ret_be, vaddr addr, int size, + int mmu_idx, MMUAccessType type, uintptr_t ra) { - CPUTLBEntryFull *full = p->full; - vaddr addr = p->addr; - int i, size = p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { uint8_t x = io_readx(env, full, mmu_idx, addr + i, ra, type, MO_UB); ret_be = (ret_be << 8) | x; } @@ -2232,7 +2230,9 @@ static uint64_t do_ld_beN(CPUArchState *env, MMULookupPageData *p, unsigned tmp, half_size; if (unlikely(p->flags & TLB_MMIO)) { - return do_ld_mmio_beN(env, p, ret_be, mmu_idx, type, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + return do_ld_mmio_beN(env, p->full, ret_be, p->addr, p->size, + mmu_idx, type, ra); } /* @@ -2281,11 +2281,11 @@ static Int128 do_ld16_beN(CPUArchState *env, MMULookupPageData *p, MemOp atom; if (unlikely(p->flags & TLB_MMIO)) { - p->size = size - 8; - a = do_ld_mmio_beN(env, p, a, mmu_idx, MMU_DATA_LOAD, ra); - p->addr += p->size; - p->size = 8; - b = do_ld_mmio_beN(env, p, 0, mmu_idx, MMU_DATA_LOAD, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + a = do_ld_mmio_beN(env, p->full, a, p->addr, size - 8, + mmu_idx, MMU_DATA_LOAD, ra); + b = do_ld_mmio_beN(env, p->full, 0, p->addr + 8, 8, + mmu_idx, MMU_DATA_LOAD, ra); return int128_make128(b, a); } @@ -2664,24 +2664,23 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, /** * do_st_mmio_leN: * @env: cpu context - * @p: translation parameters + * @full: page parameters * @val_le: data to store + * @addr: virtual address + * @size: number of bytes * @mmu_idx: virtual address context * @ra: return address into tcg generated code, or 0 + * Context: iothread lock held * - * Store @p->size bytes at @p->addr, which is memory-mapped i/o. + * Store @size bytes at @addr, which is memory-mapped i/o. * The bytes to store are extracted in little-endian order from @val_le; * return the bytes of @val_le beyond @p->size that have not been stored. */ -static uint64_t do_st_mmio_leN(CPUArchState *env, MMULookupPageData *p, - uint64_t val_le, int mmu_idx, uintptr_t ra) +static uint64_t do_st_mmio_leN(CPUArchState *env, CPUTLBEntryFull *full, + uint64_t val_le, vaddr addr, int size, + int mmu_idx, uintptr_t ra) { - CPUTLBEntryFull *full = p->full; - vaddr addr = p->addr; - int i, size = p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i = 0; i < size; i++, val_le >>= 8) { + for (int i = 0; i < size; i++, val_le >>= 8) { io_writex(env, full, mmu_idx, val_le, addr + i, ra, MO_UB); } return val_le; @@ -2698,7 +2697,9 @@ static uint64_t do_st_leN(CPUArchState *env, MMULookupPageData *p, unsigned tmp, half_size; if (unlikely(p->flags & TLB_MMIO)) { - return do_st_mmio_leN(env, p, val_le, mmu_idx, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + return do_st_mmio_leN(env, p->full, val_le, p->addr, + p->size, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { return val_le >> (p->size * 8); } @@ -2751,11 +2752,11 @@ static uint64_t do_st16_leN(CPUArchState *env, MMULookupPageData *p, MemOp atom; if (unlikely(p->flags & TLB_MMIO)) { - p->size = 8; - do_st_mmio_leN(env, p, int128_getlo(val_le), mmu_idx, ra); - p->size = size - 8; - p->addr += 8; - return do_st_mmio_leN(env, p, int128_gethi(val_le), mmu_idx, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, int128_getlo(val_le), + p->addr, 8, mmu_idx, ra); + return do_st_mmio_leN(env, p->full, int128_gethi(val_le), + p->addr + 8, size - 8, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { return int128_gethi(val_le) >> ((size - 8) * 8); } From patchwork Fri Aug 4 22:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710256 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229871rwb; Fri, 4 Aug 2023 15:03:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4k8PTnVbKt19Ha3/Z/t4k++j45HRPW5ovDwV9zbBLQRb0pCP+5zsCfm5ARTHCzgsbLxnO X-Received: by 2002:a05:620a:450a:b0:767:d0c:9ec1 with SMTP id t10-20020a05620a450a00b007670d0c9ec1mr3445665qkp.59.1691186601146; Fri, 04 Aug 2023 15:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186601; cv=none; d=google.com; s=arc-20160816; b=I48YWvU9XxACRTVYKuzcIStt8z3paR1VmPohOBZvn0lwFeARX/32gL7EkEdOouQJe9 1H5+PznlhoZeDCp48Ti+T1Qe7s5uDJ/RTJqveXLSeBOKpqFtX3+m6D0D73Ri5PRdK9A0 rOcE4rRz4TGIicdd+lF5IXVslkDuYT/F2edorMB2y/4Znuqb6s1DWiNSOvKyb4N0SvKp P68gBsDSgZQWlWeub9XWeZF/E/5pcvZ9k5CoYUPSqOy3NTlSyzKtQnGCjdrZ3t/AaRAv RZyvps2HFRRYhHcZarQaE6p9Ah8cmMQT3M0PucRUtptQ+rkN9fz8t57lsQQUzE7Y9IPZ BvIw== 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=LfPki53EL/QBw74uxGxQNslYkA1KygGupPOLIF7ZjvY=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=IpB7NNHNmbZQlxpvWHbq2+Ncgv+iwYU6MGgdINp5mQbodEGQcCNTjLO2rFY9Msxxbb XzEEYPbaZfG92RdkSBMQoJRiP8bfkuqN8QAFuEAVCEBSpPJSFVbubda9HzpadRsBuonN l+Wgs1/vohierowgX/qvmOOaoVO1xs0XBcixNaPVOzhspDeRBB2OAzyhwawqIMJMGwj2 BEETIkcOnRucRhC3Z2LlXgqamf7u1zYIEIIwRXOrLM1M/6C9iAotn/DREtc4E71hX1qh Syl8lz4NHJ9wiGM7QVv2NNYB58D0F/yrZHhfwNaESS4LVMhIifgYWer4/dzuGqc9n3jb 6+Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IefWexcH; 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=fail (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 bs8-20020a05620a470800b0076cd3e63a6dsi1831260qkb.208.2023.08.04.15.03.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:21 -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=fail header.i=@linaro.org header.s=google header.b=IefWexcH; 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=fail (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 1qS2qs-0004lS-2T; Fri, 04 Aug 2023 18:00:54 -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 1qS2qg-0004Ve-48 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:44 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qe-0001f0-8H for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:41 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bba04b9df3so22273045ad.0 for ; Fri, 04 Aug 2023 15:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186436; x=1691791236; 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=LfPki53EL/QBw74uxGxQNslYkA1KygGupPOLIF7ZjvY=; b=IefWexcHWiMP7rFoMp5f4G1FMTypOx+gjgNERFVWNiNgrYQ2gr3WXHYPPxb0OVF+Ts frFqn0wCk2oWIc2UyS0jALiTOnZGi+aseoBogf5aDgoeQog8Z3idX2ye5ilp2cK2S1y9 A9q9N5ttvJAWRHh2FySK2lKTv6JDryX9H6DNam+a5inNuo3Hw5mkEBagZGJTZTQh5WeI y1Md2xKK10fLVlXHRsWWJ1YZX0qHP6whZaYBlhTREfq+yDMwnIACaYkz0LRVx5dg+mDQ JzLBoDbSDYdRrLSCPH8KCeXhoSz51VIB0c2uQumkylgoe/K1uOG3FKdTJZgvlYw/7gnV Lbnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186436; x=1691791236; 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=LfPki53EL/QBw74uxGxQNslYkA1KygGupPOLIF7ZjvY=; b=KMyU8h+1j4Vj7VAuxzCm2d0vnHbhoodkiLW+iHRA5aPWxH19wiVrwLLQ/70oEGwUPX 6ZLDGGRzdNp0rb/t7JwzhWMEFuNMzFbhPzrBmoBDThLYvDNs4fhRQV+xdse2MsPnsJAK qkmdJHtcO6xcSGousK7B2CbI7h1k4IlSgekO5Bu8UNB+Gkg5eS/1AaYeBHdA3c9FQtgV PDeWzeqC3cSSjMFtSWNJ8nkzQa990UXitjs9olTXn9B7tA1LulkPwfD61vbjLseiuJOq g5fwsUZy2c4W8LpkO6XUlMyBcsm003wQwO7/9OmiH4+0aGInHDFrigLG6bEM+zFKnKay aH+w== X-Gm-Message-State: AOJu0YyOQZ3dTyttP4AbiR4HzXAZfKkRJX/GNhOhNemtOXKQNAUOpSUi EbKDvmLFZRO39wGNc8JWPLR7vBhB8mygamSgjFw= X-Received: by 2002:a17:902:eb42:b0:1b8:7e53:704 with SMTP id i2-20020a170902eb4200b001b87e530704mr3233161pli.27.1691186435704; Fri, 04 Aug 2023 15:00:35 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v9 02/24] accel/tcg: Issue wider aligned i/o in do_{ld, st}_mmio_* Date: Fri, 4 Aug 2023 15:00:10 -0700 Message-Id: <20230804220032.295411-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 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 If the address and size are aligned, send larger chunks to the memory subsystem. This will be required to make more use of these helpers. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 76 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 23386ecfde..a308cb7534 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2081,10 +2081,40 @@ static uint64_t do_ld_mmio_beN(CPUArchState *env, CPUTLBEntryFull *full, uint64_t ret_be, vaddr addr, int size, int mmu_idx, MMUAccessType type, uintptr_t ra) { - for (int i = 0; i < size; i++) { - uint8_t x = io_readx(env, full, mmu_idx, addr + i, ra, type, MO_UB); - ret_be = (ret_be << 8) | x; - } + uint64_t t; + + tcg_debug_assert(size > 0 && size <= 8); + do { + /* Read aligned pieces up to 8 bytes. */ + switch ((size | (int)addr) & 7) { + case 1: + case 3: + case 5: + case 7: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_UB); + ret_be = (ret_be << 8) | t; + size -= 1; + addr += 1; + break; + case 2: + case 6: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUW); + ret_be = (ret_be << 16) | t; + size -= 2; + addr += 2; + break; + case 4: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUL); + ret_be = (ret_be << 32) | t; + size -= 4; + addr += 4; + break; + case 0: + return io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUQ); + default: + qemu_build_not_reached(); + } + } while (size); return ret_be; } @@ -2680,9 +2710,41 @@ static uint64_t do_st_mmio_leN(CPUArchState *env, CPUTLBEntryFull *full, uint64_t val_le, vaddr addr, int size, int mmu_idx, uintptr_t ra) { - for (int i = 0; i < size; i++, val_le >>= 8) { - io_writex(env, full, mmu_idx, val_le, addr + i, ra, MO_UB); - } + tcg_debug_assert(size > 0 && size <= 8); + + do { + /* Store aligned pieces up to 8 bytes. */ + switch ((size | (int)addr) & 7) { + case 1: + case 3: + case 5: + case 7: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_UB); + val_le >>= 8; + size -= 1; + addr += 1; + break; + case 2: + case 6: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUW); + val_le >>= 16; + size -= 2; + addr += 2; + break; + case 4: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUL); + val_le >>= 32; + size -= 4; + addr += 4; + break; + case 0: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUQ); + return 0; + default: + qemu_build_not_reached(); + } + } while (size); + return val_le; } From patchwork Fri Aug 4 22:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710254 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229779rwb; Fri, 4 Aug 2023 15:03:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4HQQVAlMcqiqFFQXYgDRUzh30x+r4bimEmP+BLd+Nl54OeRFILCgxjlZluBxmPl2JF/Eu X-Received: by 2002:a0c:f2c9:0:b0:63c:f3a3:7ebb with SMTP id c9-20020a0cf2c9000000b0063cf3a37ebbmr2671918qvm.65.1691186590574; Fri, 04 Aug 2023 15:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186590; cv=none; d=google.com; s=arc-20160816; b=J95qb/YZ0fixmqfi6tAp0vVMQ2DEYrMHzZcIBBlgOG1kKEzmLXvw6ob6Cr+w5IPjEy pAPzrBJft2wbs4Q6luDMxFEDpA/zSde2Q8Mfq8mOMT2sDr/ALrZx+xKsxej/qJy6b3St jm0jXxBhXTE5mwYx+CbB8TvexeMOfs3BroZFKjftPMvkndexLQz27w00gR53PuopRai7 PN3+Ck23oBqy/IRYzYTONqXkkCEP+EcuuSWa7GxDMCCE7rauce+8pAdqrwBuAqc27UOo yvHZqE9DYXlWlYBxMr3iicEiuaM/GCXxtNatpYWMXyvs93wsnSzN5otXpL5lrTw9OsOm Csfw== 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=+ogyDL6MEqk+X9fxmfimDp67js4GEaptZ9YAfaG485E=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=Vm5aXwpgFrSwpf1Aic+mYTDubjMo1ijcHvOOnNmpybGiGaOEgBL1Zm2Ghe0edj4mtP Rgw38llFGe+ep2koWQ7lxU0pABtugM38o8ugE/kY83icfGOxHLGE5/WWzeb84bdPmJP1 fif/AU6HW13JI1J/autgR/whHDqHs1PaVM50XI3luo3O2YusAHXNPfHeEmPZBNp2+PXz DB9wBZ0t95bY+wjFwhFMRPEppUSRdZDbNSSeIxqqAEZ+8RDyMSkF5j9hL1rfZWVqF6vV CwbstWlvyF6qO5WBSzm60PfR4D0qza+luV9Kqd8k7mo8qiEXbG3aL7Q/jKgkf4FGnReZ Fl/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HpqjF1o3; 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 j15-20020a0cf30f000000b0062596e0fb72si1807042qvl.121.2023.08.04.15.03.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:10 -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=HpqjF1o3; 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 1qS2r4-0004np-Hg; Fri, 04 Aug 2023 18:01:07 -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 1qS2qi-0004X9-O1 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:46 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qe-0001hr-BA for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:43 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bc02bd4eafso22144355ad.1 for ; Fri, 04 Aug 2023 15:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186437; x=1691791237; 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=+ogyDL6MEqk+X9fxmfimDp67js4GEaptZ9YAfaG485E=; b=HpqjF1o3iOX6U5byC6UMA9GaSJ8NkLiHi99cbJwMcOCpBM7deVgo08ExrxHBzXyglE wMixkZiha8YH6UGuuNeXJvmjmQaxI5iZC/DhODxpVuZOfybbFDSwbLZhfJ1ZcBaroy6O uze6QVho7TUtS6uHgBCCvvvFcpfnLaHcQzagkLuPMyrUbHPWAYpeBLqi2kQW66jZfOK+ 9AwRBOzdT1zvUB2fu/Wz89cUNsgOFuvb9c8OaPmba793kSr7sKyN9he863YBzC8/WDKi 1fP7GpBjAelCvR0ERQ0J0vHOsgez4xsGGP0BMR2vknNse01LrgQ7Qr6aSOGyci6a7y1A BUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186437; x=1691791237; 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=+ogyDL6MEqk+X9fxmfimDp67js4GEaptZ9YAfaG485E=; b=XkurZGysPswuJmFapp2HjqKAPJt6YncNDuyATwtrYHXyobQlm/cqCe9YlbpoR5sy4i US4CVQlxF+4ROapwCCcPTbVvLu+fi4oGxKfQpjvOEkkYLr3OWjI5L85wjyw4GLDUvUvT KguGCn6el2IocKnye1HXMCzW5TvBT/IdTV2mCUzuY7O0UDxuXqaRSFfiA8hkgX6+cGWH PWTHVibFiRA4Eg8umnI2C240QH6QxWioPVcoEO9ae/W6aTj8/QmqoZOotR2Ytla46YZX bM6pX0gRl7I857xyrBtjt+y2ZcU3vRLMGfIoE5F6zdk/MQ5G5Cu3DgF7GSXItoz9X2Ck zJsg== X-Gm-Message-State: AOJu0YyjpG4JiMJkT3VJ39VXjKKBI5exkbzTbVU9h7paoWKf2XA1z7Zl BaZe9GcjpWVe11abUgACm/mihix9u95oyGfGq7o= X-Received: by 2002:a17:903:32d0:b0:1bb:9b29:20d9 with SMTP id i16-20020a17090332d000b001bb9b2920d9mr3731002plr.20.1691186436677; Fri, 04 Aug 2023 15:00:36 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v9 03/24] accel/tcg: Do not issue misaligned i/o Date: Fri, 4 Aug 2023 15:00:11 -0700 Message-Id: <20230804220032.295411-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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 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 In the single-page case we were issuing misaligned i/o to the memory subsystem, which does not handle it properly. Split such accesses via do_{ld,st}_mmio_*. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1800 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 118 +++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 46 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index a308cb7534..4b1bfaa53d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2370,16 +2370,20 @@ static uint8_t do_ld_1(CPUArchState *env, MMULookupPageData *p, int mmu_idx, static uint16_t do_ld_2(CPUArchState *env, MMULookupPageData *p, int mmu_idx, MMUAccessType type, MemOp memop, uintptr_t ra) { - uint64_t ret; + uint16_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian, then swap if necessary. */ - ret = load_atom_2(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap16(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 2, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap16(ret); + } + } else { + /* Perform the load host endian, then swap if necessary. */ + ret = load_atom_2(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap16(ret); + } } return ret; } @@ -2390,13 +2394,17 @@ static uint32_t do_ld_4(CPUArchState *env, MMULookupPageData *p, int mmu_idx, uint32_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian. */ - ret = load_atom_4(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap32(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 4, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap32(ret); + } + } else { + /* Perform the load host endian. */ + ret = load_atom_4(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap32(ret); + } } return ret; } @@ -2407,13 +2415,17 @@ static uint64_t do_ld_8(CPUArchState *env, MMULookupPageData *p, int mmu_idx, uint64_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian. */ - ret = load_atom_8(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap64(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 8, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap64(ret); + } + } else { + /* Perform the load host endian. */ + ret = load_atom_8(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap64(ret); + } } return ret; } @@ -2561,20 +2573,22 @@ static Int128 do_ld16_mmu(CPUArchState *env, vaddr addr, cpu_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); crosspage = mmu_lookup(env, addr, oi, ra, MMU_DATA_LOAD, &l); if (likely(!crosspage)) { - /* Perform the load host endian. */ if (unlikely(l.page[0].flags & TLB_MMIO)) { QEMU_IOTHREAD_LOCK_GUARD(); - a = io_readx(env, l.page[0].full, l.mmu_idx, addr, - ra, MMU_DATA_LOAD, MO_64); - b = io_readx(env, l.page[0].full, l.mmu_idx, addr + 8, - ra, MMU_DATA_LOAD, MO_64); - ret = int128_make128(HOST_BIG_ENDIAN ? b : a, - HOST_BIG_ENDIAN ? a : b); + a = do_ld_mmio_beN(env, l.page[0].full, 0, addr, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + b = do_ld_mmio_beN(env, l.page[0].full, 0, addr + 8, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + ret = int128_make128(b, a); + if ((l.memop & MO_BSWAP) == MO_LE) { + ret = bswap128(ret); + } } else { + /* Perform the load host endian. */ ret = load_atom_16(env, ra, l.page[0].haddr, l.memop); - } - if (l.memop & MO_BSWAP) { - ret = bswap128(ret); + if (l.memop & MO_BSWAP) { + ret = bswap128(ret); + } } return ret; } @@ -2874,7 +2888,11 @@ static void do_st_2(CPUArchState *env, MMULookupPageData *p, uint16_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap16(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 2, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -2890,7 +2908,11 @@ static void do_st_4(CPUArchState *env, MMULookupPageData *p, uint32_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap32(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 4, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -2906,7 +2928,11 @@ static void do_st_8(CPUArchState *env, MMULookupPageData *p, uint64_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap64(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 8, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -3029,22 +3055,22 @@ static void do_st16_mmu(CPUArchState *env, vaddr addr, Int128 val, cpu_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); crosspage = mmu_lookup(env, addr, oi, ra, MMU_DATA_STORE, &l); if (likely(!crosspage)) { - /* Swap to host endian if necessary, then store. */ - if (l.memop & MO_BSWAP) { - val = bswap128(val); - } if (unlikely(l.page[0].flags & TLB_MMIO)) { - QEMU_IOTHREAD_LOCK_GUARD(); - if (HOST_BIG_ENDIAN) { - b = int128_getlo(val), a = int128_gethi(val); - } else { - a = int128_getlo(val), b = int128_gethi(val); + if ((l.memop & MO_BSWAP) != MO_LE) { + val = bswap128(val); } - io_writex(env, l.page[0].full, l.mmu_idx, a, addr, ra, MO_64); - io_writex(env, l.page[0].full, l.mmu_idx, b, addr + 8, ra, MO_64); + a = int128_getlo(val); + b = int128_gethi(val); + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, l.page[0].full, a, addr, 8, l.mmu_idx, ra); + do_st_mmio_leN(env, l.page[0].full, b, addr + 8, 8, l.mmu_idx, ra); } else if (unlikely(l.page[0].flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { + /* Swap to host endian if necessary, then store. */ + if (l.memop & MO_BSWAP) { + val = bswap128(val); + } store_atom_16(env, ra, l.page[0].haddr, l.memop, val); } return; From patchwork Fri Aug 4 22:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710251 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229161rwb; Fri, 4 Aug 2023 15:02:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6aVWiPYErTj4eTdaek/Nwr7Wp/M7nIEi6I95H8V7bWlngCm/49nayWKilSvT8BG+IKAq8 X-Received: by 2002:a05:622a:11c1:b0:3ff:23e4:40b4 with SMTP id n1-20020a05622a11c100b003ff23e440b4mr4285840qtk.42.1691186526879; Fri, 04 Aug 2023 15:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186526; cv=none; d=google.com; s=arc-20160816; b=SrD8jkiXZMa5TAi4mU8l8tcHhsHFsy1tDELjhORxMsfqZO3Pewq1s92mGvnucKRumf UWRFTekrg+Tsix3UBFC359CuqokMQYJUefotYg4yFHDm67ReGi1fv9rJl0t2YcsUKQ3h SUVSkvL446/pAkhxufq0vsNJwD8RTgTAunZtPMdJynkoBtNVVcAlY3ywJ5DPXtpRhWk9 N5tcBidFL3TxTyMAQnoo4kbgvGLKoAo9/eTZCkMeLK9ICw0GYczoIc2oHDD6csm/jBp3 MEwe3+EYJf1EJBGje/PMiY+3R4bACjjTRY4ZCw9vi2Mb59LLmZ3P3DY9bTxPqs4lGYM0 SsWg== 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=PGTKa1g9aGwPuG4tk4crlE1qhIW/f2V62gcPYilpvuU=; fh=2tnQCPLqmUYA/BoQGVU30HXpDTpJUwyLa9MIUyZ/Rgw=; b=P4b7TkvnWCp2eaXfueaD/BlL2AmICd52XPHyfbGSMHho4Pup/P7LrhhzhThStTQuXk tzU7oPuLARpX7fxmUq9JZexOAcjCdkoWvL8Y3AUkNo+2rqtUWhmdOnkC34aQYZrLgByi eFILauSlFqRTj7ZOqGgV+sKxutDfHyQSH8m+XIFLjZEXlxJi/OjR+dslb6YLdBy0fINt cK+/Si85kWsUroKeO7P40uDIFi62PNIetOtt45fh/IfBidSrcrVLohqhhs2nrktD0EC+ EhO9lDEFGsBPMh46WzpHQl/EWY7xyovVBWktS/Y0ZF5rHlgSGBEVp5WzlrkmJkGr+OGj pG/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s9cAvl0v; 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 e18-20020ac85dd2000000b0040fde0ea8b7si1876376qtx.285.2023.08.04.15.02.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:02:06 -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=s9cAvl0v; 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 1qS2qx-0004mf-8W; Fri, 04 Aug 2023 18:00:59 -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 1qS2qi-0004X5-HX for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:46 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qe-0001hv-9F for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:43 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6874d1c8610so1992198b3a.0 for ; Fri, 04 Aug 2023 15:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186437; x=1691791237; 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=PGTKa1g9aGwPuG4tk4crlE1qhIW/f2V62gcPYilpvuU=; b=s9cAvl0v4H4zwkHp1GZ77ZUqutqZYy1YF9LPPySv8NJK1+jttVkJxaKyoWghoOrhE5 N45bFSSOu3VJ4goYkIdbm/T3D/lasAS4AwZ+YBXzoBLbV9/9RpGGsQTAeu64H65VOGrk 5B1+ZlEpelpnHdmObccylzhTtu9d7RpNxGsHcazfbxR4Q5vpXjF+yd7aK5GyuqyAWGbT XgfWAK16jY06hwp8CO/r6bHlaV4ZokQpSVyT9f4hGV4lu1fZEn49hqa4+2LRSSlkQfM/ lopJvU3opo2NWuw8cVB/LgA22PdtDjqmg5ikr5TW9ftHMLrmC94sVCTF/MTV9FSGZgUh TeEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186437; x=1691791237; 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=PGTKa1g9aGwPuG4tk4crlE1qhIW/f2V62gcPYilpvuU=; b=S4PsaJ9T0q01esMDTOaUjajFfvc7RxYRdB33MUUosep0Crnz+LCh2GGclTTZG5HEES proDXhivkkDIFa6yEf+zHSCvIJDfmsvzDo/gc0lPusA26NYTLlFBRatYhDUoIEH5vddc ONQGp6EwSustdn7VM8ZW2DD3EcZ/F3rp0OEnEoD9Mt/Gf6aJmy8hOzItIbegcMY50VM5 h+BJznyhnWY/Q/7ZbEedWjskEvn28ysV8duCLL2yIga6zUa7ufeIAHUU8RX2k6S8w59H wdlxGgbjpHovGG8RM0H2Pf7m551xlysnunwcdWmweGwLxMvECAnaGgiz9/Z0axYBbfig HpnA== X-Gm-Message-State: AOJu0YwCbJc67VSO++Hlum653H5KOXfpl8JPPT6OBf+b6hiCgsyoV4+B ICXUlFsNZFgdVrzqLHH++bd8SQ2EO0r3Qq/9xj0= X-Received: by 2002:a05:6a21:3b49:b0:140:2805:6cc8 with SMTP id zy9-20020a056a213b4900b0014028056cc8mr1277625pzb.27.1691186437430; Fri, 04 Aug 2023 15:00:37 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Matheus Tavares Bernardino , Ilya Leoshkevich Subject: [PATCH v9 04/24] gdbstub: use 0 ("any process") on packets with no PID Date: Fri, 4 Aug 2023 15:00:12 -0700 Message-Id: <20230804220032.295411-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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 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 From: Matheus Tavares Bernardino Previously, qemu-user would always report PID 1 to GDB. This was changed at dc14a7a6e9 (gdbstub: Report the actual qemu-user pid, 2023-06-30), but read_thread_id() still considers GDB packets with "no PID" as "PID 1", which is not the qemu-user PID. Fix that by parsing "no PID" as "0", which the GDB Remote Protocol defines as "any process". Note that this should have no effect for system emulation as, in this case, gdb_create_default_process() will assign PID 1 for the first process and that is what the gdbstub uses for GDB requests with no PID, or PID 0. This issue was found with hexagon-lldb, which sends a "Hg" packet with only the thread-id, but no process-id, leading to the invalid usage of "PID 1" by qemu-hexagon and a subsequent "E22" reply. Signed-off-by: Matheus Tavares Bernardino Acked-by: Ilya Leoshkevich Message-Id: <78a3b06f6ab90a7ff8e73ae14a996eb27ec76c85.1690904195.git.quic_mathbern@quicinc.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- gdbstub/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ce8b42eb15..e74ecc78cc 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -537,7 +537,7 @@ static GDBThreadIdKind read_thread_id(const char *buf, const char **end_buf, /* Skip '.' */ buf++; } else { - p = 1; + p = 0; } ret = qemu_strtoul(buf, &buf, 16, &t); From patchwork Fri Aug 4 22:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710248 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp228778rwb; Fri, 4 Aug 2023 15:01:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaiVL4oz5rkZKUjpqi6AXEvSYqxkFd0bm78PJPIRyfTG0WiJGN2JBHmbl5+BQNg4FesRoX X-Received: by 2002:a05:6102:e41:b0:443:8b27:6dac with SMTP id p1-20020a0561020e4100b004438b276dacmr2425995vst.9.1691186490920; Fri, 04 Aug 2023 15:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186490; cv=none; d=google.com; s=arc-20160816; b=hv3FNo1S6+gv56Ljo8E6fR6EehPJfiKQc6iK613PlObK+GQ7531pjK8xbYYgyTDUkq Xb3rEAOYc69seMdq63UGvGHEqaWH60nRRLkPl3p/rf/RKYMEhbKZxCB9FcYgLN1d5N0S hT2HrH6W4oM92sHoDcM7Nzy2kpx9QY0t5v+Lg/ZmJPjE0kPQJHCPBhI/XdjakaUSJg6i NEWpkueZnv5enBrYhuoCK2d0NZalIGPQEf/5v3+IgBeO/GEJYtGRg3RfdWbngIqfVlsF DUod2Oiikn6r4Hd3e/yM9ukSZ4KrLqo3hnrUrwFI/ZvTVSh5+oLcITmtnkrKuHE6jsPt Swrg== 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=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=Hy6JaUYBFlYoihXxs4gyFPgKze/QzVvLZXm7JZtOyxiurkMUxNIiZxUwBWJJUSA0Qu oGAoS4dX+2WWR9ZsQYxfF00Id2b6jN1GVSG951yxQ23pG8E+jy6r79vfU7HGKjY1E+b/ TQcNmAdm6YW7nPuUEI+dTRqaHx0yIlAynkica4lDpeuQu86fNQfWb0b8Js6YDikRvbGu weCxlGdtsl3h8unlaw1Xf7oQUGoi8VbWUYSIjyzzTLI8nHslV0g6QP0ZZE9+761a4j0y Ipoh5TiLZ0Qg+jVaklD3IxW0FDaUOsG4t/SXR9NVYSlsxrQGh+77xhUG8a/D8bvK5bxF 7e6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lPDpZoBF; 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 c20-20020a0ce154000000b0063d38afa0c0si1844142qvl.91.2023.08.04.15.01.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:01:30 -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=lPDpZoBF; 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 1qS2qv-0004mJ-T8; Fri, 04 Aug 2023 18:00:58 -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 1qS2qi-0004X7-Jm for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:46 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qe-0001iT-Ah for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:43 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bbbbb77b38so17986585ad.3 for ; Fri, 04 Aug 2023 15:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186438; x=1691791238; 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=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; b=lPDpZoBFwd0pLT/ijWF4GExWIzzB5G6tlz9fOgyieetGdhbrzZJM220qT4NbH3+Obk zu/osbsoi6Bz7seTmP0dtq09gPESHJMVYZFPXscNFIL2GfvPNBukMXHmM8E9GOxt0+aT 7ssJUP+57sy4DcMlws03DFg3Vv9mBMwE6cmCadLkiOeHdgkQr4Kh3KB3YLEX2gY5oGM+ AVS6MFij5YQSlvHaHzGQVJrHydN/JHgDy4F3olTDbWA+1luxZ2hgY0JxMFTgl5blpcgg RolIm++nbjCnnfs9+tUeCCCF9gG/jL1TTJJCAsjsE3VUiZiFtvMu37nwa2FEjDORdYhO dKKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186438; x=1691791238; 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=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; b=Dkor0HK9iuSJDL59Qo5LPYcLgDzUE2/SWCJJoTzMXBExYzcVf6NyYTaa9R/CkR3C97 4/ai2ETCzn20ryviCAw89Fgslu1B6SM4ajf3EhgJuBe7CT7mq0TX7+OH2MiQHmL6k29S dsudzcQpqoYiTrr1RgaidEQtDfnM6YgL4dvoQ0yaZqnJZE01Kco41yzhS5DyYDbDD6v5 MXos9deFCsz/tLRUKlCLYR+JUkW1VWF2nNYeaHiNKyr0vE4NnX3WrtSBFF8urRGxcVZu d8m6HVrQxr1JpqXM2YWoyWm/hsE94CtHF2hLPkDuPOXDI0l1YQlmCQ3Q44loWzzZ9Yge JDmw== X-Gm-Message-State: AOJu0YwtiezEaJLJs+N/MAghS3ys1zh9l8a+uZ7IwqU0Y8d8/ZD3vFIN tl6yvPu0u5VmSuk3oHhyOPtECMsRtVYFAjWcz/s= X-Received: by 2002:a17:903:1cc:b0:1b3:d4ed:8306 with SMTP id e12-20020a17090301cc00b001b3d4ed8306mr2507041plh.19.1691186438190; Fri, 04 Aug 2023 15:00:38 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PATCH v9 05/24] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Fri, 4 Aug 2023 15:00:13 -0700 Message-Id: <20230804220032.295411-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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 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 From: Akihiko Odaki Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /* From patchwork Fri Aug 4 22:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710246 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp228769rwb; Fri, 4 Aug 2023 15:01:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZSQlHCfha+00hcXBkds1givAS698P1WT8uH72lG/VN/almHj+/XfLIQMQBB6dC8vWstfo X-Received: by 2002:a05:620a:2415:b0:76c:cce2:e7d5 with SMTP id d21-20020a05620a241500b0076ccce2e7d5mr3234708qkn.62.1691186490302; Fri, 04 Aug 2023 15:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186490; cv=none; d=google.com; s=arc-20160816; b=VwWD8CdKs2TmPLf0hIkKzsfnlfl9vh+lCKquFPS/oZEfPuPnjY04vjXtibaCcYkWW8 9gdaaj31mQMM7bhB6yBcJpVAugNGGIA5p7Vgrl0tM5zG2BAxF1IttAA63OsGoI/B1BvP I7v1w/OdkIG41J5F3fQ2sM/AejIhKjkA0YI1FAIk/drMaI73/5fkKsim6gl/mUCMCobN MXzHubxHKaZMbDC2QOt3a+8jO0g5ymsDs0ZlRlrHYvmq1TB4RQYqLAdLwUt1ZGH4nV8t Ex4gAvmfqfOQQzlbQL//oLWXJ+QOTnplMtnpHWfX6e2IbnXZXbrW8BLThLnzCjLkBNlo eblg== 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=Y+al/bCM9dfQjUvbH6ERA5E1FapPNk6WKGGZIMvtMEA=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=ahiBpXaJkvpVfyBnoP3/M5OwNBcRCPNW8vg7sKFMIlPdyWjiC9VePYfLawlGsRYx+a 7/eDCqrc+AFMsStdJ8QvmfznkrY6cIm6h0HzB0F+C+NtJ7TdWBRHu8bf6S7JpC7PK7bD IUyByoabwSmE0WF1JYiR7SVrsOnOnNIagFkKxegbAgJt70w2+yNxnmAc1hZg0yNyckAR PrQ9MdS0dnV8D28c5X1jFQLYqthe1KWzc+i031viK6AQwPmTlWxTo2ppIWvAXKIiKA45 EFSgPEYb9IAIp2whlW4/ta9r8YPQtMLgLnLy/PAA9LvE7x7rPJ3mNRHXGrn2EpIbiDde Gbyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SOpKkvzl; 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 j5-20020a37b905000000b00767c5ae5aa2si1747298qkf.224.2023.08.04.15.01.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:01:30 -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=SOpKkvzl; 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 1qS2rF-0004sN-ON; Fri, 04 Aug 2023 18:01:18 -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 1qS2qi-0004X6-Jm for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:46 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qe-0001jY-H1 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:43 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bbf8cb694aso22024045ad.3 for ; Fri, 04 Aug 2023 15:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186439; x=1691791239; 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=Y+al/bCM9dfQjUvbH6ERA5E1FapPNk6WKGGZIMvtMEA=; b=SOpKkvzldfmAt3LnNY3pfZO+WMTeO8e35+ej3p06mQfrHlQ5wgzGN+uKL64OgKuJLB N0LesIdg/hZQWeELVFtnk1zoL+r3mcDvPHmX/I3kcTKUgAcpBRLcW92iQlskhCQ2Quzb 33QQB9/Uw5O9qVt7MsK8CxRFfvKXQ/zEGQO8h4/fwxMhutYNjUk4PLNCxDtk0DPHJypL U8rzxYWHbELk/S0y76dnNjllwxbuLhiDQdmjq7RIliuLwHx24U0+ZpkPi76flJ8315gD ukBEoIhZXsxV87u2lcrieB5onUouLdGLGEdMByJhz7dYpJbvivSsOZfECmliQwji0/9Z IKNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186439; x=1691791239; 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=Y+al/bCM9dfQjUvbH6ERA5E1FapPNk6WKGGZIMvtMEA=; b=NQB1Q3r6EF53dzGw0JoQRoN2x4EjGH5wMjFwg/+mxbLkzHGA8S8vda8EkKhbIQq9xl E1kVCHKuLQ0GsWvnK1FT+p2A7AgGL5wKEfyvx3wVanp/xsKKEfYgZR4KD52ExVZAJFjX LuGQaJ1lDEDLv+1ekkL0AnEqT3f2aISynyDnw/9+mg0T6aJcv2zG7eaJlBldhchBSxKH a9voBhEoiW4CUGMdV/HugQexlALPHfH7xsD6cjL3FrN+0YWhVTnLt4+VK9OYne/69v9g t9ktMjTvcLUKEhoIaNjxwwYwrGJWsVVqMjUek43C8BfwpAW/a7qih66n8CPnzBMsBYvW fYtA== X-Gm-Message-State: AOJu0Yx8RRDt/bKbq4ABspxItS7nkOC1XltlEMZ1iXDHj3RXPMy3xPqa SRijtkWo9kI6P8Q0OuvgH+T1sS2m+rOupLysO+o= X-Received: by 2002:a17:903:188:b0:1bb:3498:9caa with SMTP id z8-20020a170903018800b001bb34989caamr3765589plg.58.1691186439141; Fri, 04 Aug 2023 15:00:39 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PATCH v9 06/24] linux-user: Fix MAP_FIXED_NOREPLACE on old kernels Date: Fri, 4 Aug 2023 15:00:14 -0700 Message-Id: <20230804220032.295411-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 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 From: Akihiko Odaki The man page states: > Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE > flag will typically (upon detecting a collision with a preexisting > mapping) fall back to a “non-MAP_FIXED” type of behavior: they will > return an address that is different from the requested address. > Therefore, backward-compatible software should check the returned > address against the requested address. https://man7.org/linux/man-pages/man2/mmap.2.html Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-3-akihiko.odaki@daynix.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mmap.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a11c630a7b..90b3ef2140 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -263,7 +263,11 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, void *p = mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { + if (p != host_start) { + if (p != MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno = EEXIST; + } return false; } prot_old = prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { offset1 = offset + real_start - start; } - p = mmap(g2h_untagged(real_start), real_last - real_start + 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p == MAP_FAILED) { + len1 = real_last - real_start + 1; + want_p = g2h_untagged(real_start); + + p = mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p != want_p) { + if (p != MAP_FAILED) { + munmap(p, len1); + errno = EEXIST; + } goto fail; } passthrough_start = real_start; From patchwork Fri Aug 4 22:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710266 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231583rwb; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVrM0S6FH0Qv0eDizZGvgYNrQP9E03V80NzFzLwqHZQ/pmT/FfwCfa0jcEZytgIT2n4mjC X-Received: by 2002:a05:622a:493:b0:40b:f548:affe with SMTP id p19-20020a05622a049300b0040bf548affemr4602896qtx.51.1691186809605; Fri, 04 Aug 2023 15:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=google.com; s=arc-20160816; b=piHh6MIEGftC3LJvPxE3oRmdZX36KXcUci3ZuhTliIdPiQvMzgjhyjmzmY9YW4rqWW yGnjj9o7gI+oGspN829kFXf5MK7XIEFnXiAY8u0Tcwm38AVL4kh7g8/LLOmAIsYQJZ8p xVBIluohxWtgLovT78FRPRWjeD0bWGYDOxcPo9I+mNTjeBuzbfpl7ObeoLgGXK0+Nf9b WYu6/CfMRKNWd9yQcCB7dKJ2Z7pTqGkRhqi8Tfxu9GyWrKXkMXj1ZIekmS6R5DtQmn0s UpJWrYR7dTWd3wbJqtDeTbdlZCmrhR7CfIauGO+I7zNgSDRxO59iDwToIe+R6soPQ2WD ykug== 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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; fh=KbMqH8mq9CYjRSCjjAD/0kWfnvdKe1C4f7CRd7AraEQ=; b=KiH7dUc+FzN9G2m44J3hTK8kRL/XkssWM31ceNpQxzUUH1/G2ve+Mp279JCBDy8m4X JCUw6XEoTQFJa6ngLVVYsEaL89PsAkznUfay5oR+9u7L69k/KiWjlI8LZB+P/4cQlb4h ECWp2qDjO+8CJoBFFd+1sQqkANWhcBEGnrXMyYjQR8Gs9vItB6+fi0hXKlJDnOTK/ZRu U9rAq1x/xUiIX4CAeXJj/J4uQ5CQLpv12o3iIlkutj/7xloy+3/dWBjwRapshX9Wjobe auoxtyc+UgvDcrQUHoNMbkWG3F2ecWrqRJkqRurk7heOU7L683gDGwbsCeXTy3xBRsFb L8JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iy0946Gl; 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 u21-20020a05622a011500b0040465f2c127si1888340qtw.225.2023.08.04.15.06.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:49 -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=iy0946Gl; 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 1qS2rN-00051l-E6; Fri, 04 Aug 2023 18:01:25 -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 1qS2ql-0004aS-0t for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qf-0001lJ-Bk for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:44 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bb84194bf3so18082695ad.3 for ; Fri, 04 Aug 2023 15:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186440; x=1691791240; 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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=iy0946GlXWEe18CYgAJtMtv0NSdX8zxbn8Wr5IoVxCLyJd6AG7Ju1mlIsPZA5tfxkQ xtb1Q0x1LSKoP2/2rvr7lmxjM0OrCdsejTzd/Ll87x0+mFfwTrW/vapOeh4Y92bcGype abePKqxU2fQHhuzvpjRmpG4j07wlOhK+rCs18MnslMQM5Dm9DxvVO/CD5HXv7nkzQ4+w ECYZ5yxvML3weoL0cCRJLm34VMevcJxiR6jLpJ52JJQ/YeJEquY6dnwoanSKRrJEqFgZ T372vWWrLB/Up4w4jcOZHn7ZBYU1LdKFMWimeZi1SYL0ezDBL59o2uXjXr0um2XXETRS W4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186440; x=1691791240; 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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=an64R7v7AO8xset82AIsPc/0Gr9fdEDjJGUS4Rb4TpoBqKvX3N7krflL1gIJ146dJG KF+FO4zezDnYog9SMmHpbsuqeuDY55MXH5N6ShGc1DgKJ+wVGgBlR3zn/2rCeVRtLbUk pLRHFaugoyQl1HJBwKTpDzakBWVXMe5Igc2u2kZ5AN2M65HVygQo46rJOBnFGdKnsTqZ 6xv6tR7DC7M6GjsPHvJbJwPTdAuxuguSLJ5/qtSEObOtO4b8svuhl9Tyxywemgf5PYMA +Mty+nc0wlgeBE2whbeCDpUV33uutpeqQTmF5MVA0lQDD3RFoUiNZ3gRxpO6VAO0p5d5 33uQ== X-Gm-Message-State: AOJu0YyWIlal3iNjwgvZkrQbn/Ul6r7k4VFuRyQ9SPWBIccLR8snnCTA 9NUPlrCxpvtEaiDopAgPFxdwlb4Y/BTFOdxd8rU= X-Received: by 2002:a17:902:c409:b0:1b8:7483:d488 with SMTP id k9-20020a170902c40900b001b87483d488mr3173704plk.57.1691186440118; Fri, 04 Aug 2023 15:00:40 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Helge Deller Subject: [PATCH v9 07/24] linux-user: Do not call get_errno() in do_brk() Date: Fri, 4 Aug 2023 15:00:15 -0700 Message-Id: <20230804220032.295411-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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 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 From: Akihiko Odaki Later the returned value is compared with -1, and negated errno is not expected. Fixes: 00faf08c95 ("linux-user: Don't use MAP_FIXED in do_brk()") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-4-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..b9d2ec02f9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -862,9 +862,9 @@ abi_long do_brk(abi_ulong brk_val) */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr = target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; From patchwork Fri Aug 4 22:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710250 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229153rwb; Fri, 4 Aug 2023 15:02:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMjVSlN271GJbXxpark2RwHNR8Cd2DXzTWQd1AFu2Re1RnmYcxEdGTOOnZD6saxvszfFfW X-Received: by 2002:ac8:4e41:0:b0:40f:f07f:1c01 with SMTP id e1-20020ac84e41000000b0040ff07f1c01mr4721316qtw.40.1691186526479; Fri, 04 Aug 2023 15:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186526; cv=none; d=google.com; s=arc-20160816; b=0JxbA810kT45+h+e4y82AaDEbxSfw20zalPX9HFRhbZya8WmE+qhwaC2jTyUkrjSzu gE5Kr9rVustLPkN0CYGjaL4sw8+BSfZm/I5CvDEegPe0csAxXBhiBaYNfEfS4Brq6a0f jvsT5n2Xchrfsb7b4xLX2LFo5bE9WScS9Zk9uc+7xnrwq5R+LmFgLPHZRxyYf86OP5zF qN4nBt/TRY2uflLL5vdHkNA3kzLCqQTpp18XRqHYSK61SJ5A6OFc9AvSwfeoZ+XQdKZb m2NBbhXPO4rUU8F+tuHNYG/bFF/kACVAdX/XMqgnfhD94FgZAOrlnE4JuVc7xGtNLG2O tnnQ== 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=bf/ALpOBYc7K57PasFTQxynQyfdHrLJkkT4mzU3JrrHzV571fQLtwUnAWF30a2Cy/n V59+Nuy0QMbyfIKPa31JCQLyeET56evYSan+tdlJInJeevAgthkdoQEZsN25AV6Zm47U D5bpsbi6uTX0xOUKruxhQXUN9fmvRrdxQS1/Sb9jb1hRrckQJEHdTGhMlmePrleUMFnG C0vqUT8blkUg7XmFNMulHEw22j796jguVreiZb8Oq2NSobiCAcIxyNMATECRjplEPhNB Ipz6uLDgcU4lRIJZ4xY3uyEsA4RYIaVG7IjpvXiLCXeMwPg6t1erzCa4b6GHtBGRlWQ1 W06w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=URbVDpZt; 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 d8-20020a05622a100800b00403cbd1ef77si1827533qte.208.2023.08.04.15.02.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:02:06 -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=URbVDpZt; 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 1qS2rC-0004rQ-Kh; Fri, 04 Aug 2023 18:01:16 -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 1qS2ql-0004aT-1R for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qg-0001nJ-JH for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:44 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bb84194bf3so18082755ad.3 for ; Fri, 04 Aug 2023 15:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186441; x=1691791241; 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; b=URbVDpZtOGNC5hpJterst+zcn+LmZ0H52ajLs5rR4C/g3FML0E36w5LGt9LS3t6zRr OwVQiiVwZgEp4fnP5fEYWsLpdUnOn9oqOjx1mLF91Y4DJpTPDMorngourzXdFBNw9TWC 2v00IxMjimraHuEyAfbEz2RxmTwCwynMTfEgLXLsbw4pC4EOb1NQGbfaSgQOCMGtdlym aoecHlSiVxYUZHIfpBZkcF1XyhhLFgaDir+dmqJoStxIVHYK66TDvnB12i29GgVD1l2d 1jxv29FpOEjolI3L4fux2md6rGCb4BgAF5un+EOYeyNI0mXLjRyHfi2PKn4OhCZl7KXo P2RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186441; x=1691791241; 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; b=V5rMzB3AZNHxKvFhhZKskgFSnS75aMkqkZNBlINqNL1sm7tATUGyHM1C9WpgBAbA++ OQ14hWI3AW+nsTMNxbACuekrGyRhJtnjQK3bZyhLySdg9QclRKAhAb2VzSfjp1uSapUt YmCJRl/LkINTAauMPOxTGAYn98nJWtlNu+5ppzy9sjdvi6H8kzilH9Myn5CXJVVXDcId CUQwLmvLAHc7PqFmN4rqJy8ckCI29MRBfF7sUXpGQHD74AFMonynriNMqOpRa7QNWe4s ETQAY8NCn05J87OjzKIHpepu7VQ6+wHVffd0FhDyuMRWrqnU5gJ9h+PT6gKrBlVdrUL+ oE+w== X-Gm-Message-State: AOJu0YwsEV7id3Yg/bA1DI+w2Wjx++qyDPbqdh3WQ8ZyyXUE5zaB6qqG 25PcytcGybAGfgMYbn6X0Iwr1wNhLOxXP5y2HYI= X-Received: by 2002:a17:902:ea91:b0:1b8:b442:aa97 with SMTP id x17-20020a170902ea9100b001b8b442aa97mr2824551plb.54.1691186440849; Fri, 04 Aug 2023 15:00:40 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PATCH v9 08/24] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Fri, 4 Aug 2023 15:00:16 -0700 Message-Id: <20230804220032.295411-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 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 From: Akihiko Odaki MAP_FIXED_NOREPLACE can ensure the mapped address is fixed without concerning that the new mapping overwrites something else. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-5-akihiko.odaki@daynix.com> [rth: Pass -1 as fd for MAP_ANON] Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9d2ec02f9..f64024273f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -854,17 +854,12 @@ abi_long do_brk(abi_ulong brk_val) return target_brk; } - /* We need to allocate more memory after the brk... Note that - * we don't use MAP_FIXED because that will map over the top of - * any existing mapping (like the one with the host libc or qemu - * itself); instead we treat "mapped but at wrong address" as - * a failure and unmap again. - */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0); + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk = brk_val; brk_page = new_host_brk_page; return target_brk; - } else if (mapped_addr != -1) { - /* Mapped but at wrong address, meaning there wasn't actually - * enough space for this brk. - */ - target_munmap(mapped_addr, new_alloc_size); - mapped_addr = -1; } #if defined(TARGET_ALPHA) From patchwork Fri Aug 4 22:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710255 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229787rwb; Fri, 4 Aug 2023 15:03:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdjyevZOZVH0NI9ho2M5w3VpPhDv6K+HIpnSADxagrvEde+1WNzTx0oZtCPvTanfJkD0oM X-Received: by 2002:a05:6830:1294:b0:6ba:a084:6a1b with SMTP id z20-20020a056830129400b006baa0846a1bmr2761494otp.10.1691186591435; Fri, 04 Aug 2023 15:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186591; cv=none; d=google.com; s=arc-20160816; b=c/gjmmXSq5PWonleQY23RLmCzHuGwK8c97OaTzUTes9Y/5uQYWQcpxdKX0/OK7Tswv yXUNaqq/LMv5WBk9zDYTn/YE9SZd2bZhl/TwahdXlOej8e0VB+SR492eIC+QEu193vy3 QOB0bYst8aiGlZbFqgUzvVJdUsqs5Vqa7Kzv61s2olsG9W3rX0s2t0WUa3Hg9EJCHPtA OChWBQaAQyTeIhRTq+Xas3XTf0RTUiNnskrbWunZ6PxvmBZdhcWh0IXd3o3LalpgViGz 9b9+QSJ0AqxYLqpraCgfoFuLIajvD4QsgSJytZTEjKB8S0ogWA7fSA7tRvT0wpz7nmny 2rLQ== 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; fh=KbMqH8mq9CYjRSCjjAD/0kWfnvdKe1C4f7CRd7AraEQ=; b=T2JmRQVMXH1GWRvlrTRjfFvwHFa7S5ypZ9e4uaIpk5TNNQgWOkBfsopmMEc7M1JKj3 smi6l8WV06qPnXc6uxkK3d85urB8oP0DUUaPXgHLa/BgJXloKwqqR5H333xfV9fc8H0w z/fmEE/2qvMQaPShbqngoJAmrXERJOhbWhX/Hym/YRS4w41nRIcthRCwgyhGJSRCwgXV NAp8rfN1YaTNGwkvP1V69fEpPvveCjlfd4I21fn5f0AVfJFfBWLbrqFk52PbEW4mWiJy nTCE3i5tnLl55M2KfvwBkPNdGpanZ83Mr/CDkS5tepunIY+XlXDxSU7AvcsKk3N8nzN7 f03g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yo7WI6t5; 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 y18-20020ac85f52000000b0040ff58d67dfsi1530313qta.599.2023.08.04.15.03.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:11 -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=Yo7WI6t5; 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 1qS2rR-0005EO-1N; Fri, 04 Aug 2023 18:01:29 -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 1qS2ql-0004aQ-0q for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qh-0001oG-5l for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:45 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3a78604f47fso238663b6e.1 for ; Fri, 04 Aug 2023 15:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186442; x=1691791242; 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=Yo7WI6t5glkTUAPMQ0umLk/jb0jYnLaPxcNb7rv+2cjWe2usocQOl4ivHTgJpMmnEY IDXduaygAPwnbPBjyB8IY5zEAftxzsT+qOThmgHHikm+gFCcHn8NOHtPGmZjTtR3dLNW gNwZ/JAQm9Dqe/Xo/DhF6rMCEQFpNKex6MO5QBqLJ53uGYeScV1lyUdVgTR73OsL/R8K 3pYwG4bKnmKIsEiPevJT4iOXedqMHQIN1lIdl5OAleKiazrpj5mJp7iRm7UoBIFBCTQ7 JEQZy4ul7F+Ia/QeWFL84KPyvOyUChKIRGsramN0XL8Wwx8Asjo8gE3Df7QWxbYR++Py xPBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186442; x=1691791242; 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=KsRo9XCNSHQ+0upjHYdiCypQJPAgxWoQxaTIcGKGeewwTryPWAs43bQCQqCswKtvGz JJMUvCkV4YoRVmRcqiRHCh0kP9v7u5BI08KRszpF0IWsjdsupQDWbtBbFsxVlpgT//7m emU76i+gi6Q5Hqbe9jPULA1Po91xniPFdrXHNUG4vex3BXJO/GkiEmHk9p1x0dVXAOz9 utEkC9kknA80Rkr3cH3TOCbxG1qhSiiQVzIrWBh75eRoJhQ+8fvcY3gZ7rGonGWHgs3p EfTLVZxZXVtd70hPp+8S8cVuV5nwS5u/H7oKFZABmGyFM7341fRaK90Y8pfdWL9EZAVd yacQ== X-Gm-Message-State: AOJu0YyhIIUEu1IFq0Pv+3WNfDWYEOErw1QPcGGfp5SMjaB/inVOYjrx o5eP9OxqwnLCDbtlAYpEv5QHFBF/IWq5nAFyPY8= X-Received: by 2002:a54:468f:0:b0:3a7:4a89:752c with SMTP id k15-20020a54468f000000b003a74a89752cmr2992840oic.31.1691186441690; Fri, 04 Aug 2023 15:00:41 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Helge Deller Subject: [PATCH v9 09/24] linux-user: Do nothing if too small brk is specified Date: Fri, 4 Aug 2023 15:00:17 -0700 Message-Id: <20230804220032.295411-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x233.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 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 From: Akihiko Odaki Linux 6.4.7 does nothing when a value smaller than the initial brk is specified. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-6-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f64024273f..e1436a3962 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -820,14 +820,14 @@ abi_long do_brk(abi_ulong brk_val) /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val == target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val == target_brk) { return target_brk; } /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val = initial_target_brk; + return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); From patchwork Fri Aug 4 22:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710261 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp230291rwb; Fri, 4 Aug 2023 15:04:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEluD7mogWjl3legsaEVYus3V+kMj6r5Fjlo/xwgHoJrtKPB7g5wHwT3z7OWTetK/Cq/Od+ X-Received: by 2002:a05:620a:4153:b0:767:e583:5315 with SMTP id k19-20020a05620a415300b00767e5835315mr3551832qko.71.1691186643722; Fri, 04 Aug 2023 15:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186643; cv=none; d=google.com; s=arc-20160816; b=raEj9Q6hkOv+xbznP5dYt6gZHLNUKgD+6jaQRdpFxic2nxCXio9Rfc70O82YeA1JtW QT43o9hCYsKfa54saXJTL2sAB4k7yO7zKNFznQ2p3PXafqv+YSdiIWFbSnIubwFN3Iag g7HzTCozNuOgo328Vt1Rd27BYdBg3pqIVyg9R/g5ChuEFqlLQunz6egNuMAb4eC43aQy tCypyAbxKb6EacaKPv5nyU/9Xso5Qe71aS7f1PoWrOLtmIkqc8u7UwLMCaBTP95TkNRg FSK6l5/cDiQr0VqGWxyHg7/KDCAVKIZ5jOmd7qWAgvcKKmLF4FCRgaDYYAUtf7PeUGeQ WE6g== 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=0j4qdY8wgUJ36GCFSfl82HrDqxFfSN/9xJDSJ25evd5b0TUN/xnQBS0/jgnuVQS917 EhrJluizLbWJ7cxGerrLHvB2ws4OSlnFwJ1rIduW4CDrfAVOaDvYWiahha96dxou50dj oXqPgPAxqdhw4gD5/emrn0dSrr2xV4McYHZySVU9bcuT7WwT8ZdOcEnooCpKOarqMlgE QsdDquXXzxd5gJ1flK0PPX2ANLoezRMnP/8iIwr6jaGC6tNYGrNBWE2hQrqlq1q9Ka6Q OLuDncmRm/2vzZ/Z1uf/Z1/5dpm64r4IDMFCpqR4FzaS1Fqgbkl4nZ463Eo2xyOiq+mO K1fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vALiQe0S; 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 az20-20020a05620a171400b0074e08cdf531si1911664qkb.427.2023.08.04.15.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:04:03 -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=vALiQe0S; 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 1qS2r5-0004nx-8f; Fri, 04 Aug 2023 18:01:11 -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 1qS2ql-0004aR-0m for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qi-0001qZ-94 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:46 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-267fc1d776eso1512707a91.2 for ; Fri, 04 Aug 2023 15:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186442; x=1691791242; 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=vALiQe0SydAlf+fkGUUJoBvGsj2RqfGaGRZ1jZcZana50bkDH8YTB0/ENgJLXrSncO Dfo+5itmqoATnM02V5wRO77nmimqZoHp7Vu8BAUVRXvGDLijsxXDVdDsg9hcAeCXot4j y3uqrFUIrxpWNSMUoTTe8BtIgRgi/8q/739h+ruIzqr6rWrrdnbLf3htU1XrCa8zWwsH OMb6gOSAf5yZsIAWROH0RrUERJw0ewhMaLES7KuwRvAAwt14NtDPelDR1UEByreFyrKR NsF8QyKjbuVKmg2X+ifQXPYaKl78VE7sxpjRhiEB35o/UGLzAf9/qu6Fq4nTFdCWKUDB iTRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186442; x=1691791242; 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=fknXswry8n1Rki1PAXg2SMOR9mt1FyLwa6jOBSOdEu9Rmn5DoENi/5Q8nG1t6NoF0d C0tkUjVp0D0xh7X+tc3eLWJ4sdCVdNGI1nWl5ephhGv7TJEzfE4xtdklV0K0UpUPct0Z YuOpi2xXxI/mianU+q7pQIih5H/2dCZ+vV1TGP1wUlJelBPfGuLuYBTLYBEs07DWHWJq SxhXVk9HzN5RfbpulCojoUBP44zAbgtXOmedqCruHEXxDYo9v+lLRXlkwMyXFCzbQj+C tJ0SwZEeM6Yp4dCvGIYDKZe3q/VVziimo/9RkKWS2kXikLNH6avVQK0/hBouK35rxxBl chXQ== X-Gm-Message-State: AOJu0YyEY6BMA+t1eE73t8CNEVRPUJlJW8E5VYY9epUHhkexorHbUT3C DQgg1D4H8pmvRitMhcqwP3mJ0wzbWqnm4PfU4AU= X-Received: by 2002:a17:90a:3905:b0:268:5919:a276 with SMTP id y5-20020a17090a390500b002685919a276mr2505015pjb.20.1691186442548; Fri, 04 Aug 2023 15:00:42 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PATCH v9 10/24] linux-user: Do not align brk with host page size Date: Fri, 4 Aug 2023 15:00:18 -0700 Message-Id: <20230804220032.295411-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 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 From: Akihiko Odaki do_brk() minimizes calls into target_mmap() by aligning the address with host page size, which is potentially larger than the target page size. However, the current implementation of this optimization has two bugs: - The start of brk is rounded up with the host page size while brk advertises an address aligned with the target page size as the beginning of brk. This makes the beginning of brk unmapped. - Content clearing after mapping is flawed. The size to clear is specified as HOST_PAGE_ALIGN(brk_page) - brk_page, but brk_page is aligned with the host page size so it is always zero. This optimization actually has no practical benefit. It makes difference when brk() is called multiple times with values in a range of the host page size. However, sophisticated memory allocators try to avoid to make such frequent brk() calls. For example, glibc 2.37 calls brk() to shrink the heap only when there is a room more than 128 KiB. It is rare to have a page size larger than 128 KiB if it happens. Let's remove the optimization to fix the bugs and make the code simpler. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1616 Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-7-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++-- linux-user/syscall.c | 54 ++++++++++---------------------------------- 2 files changed, 14 insertions(+), 44 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 861ec07abc..2aee2298ec 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3678,8 +3678,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * to mmap pages in this space. */ if (info->reserve_brk) { - abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk); + abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); target_munmap(start_brk, end_brk - start_brk); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e1436a3962..7c2c2f6e2f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -802,81 +802,51 @@ static inline int host_to_target_sock_type(int host_type) } static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; void target_set_brk(abi_ulong new_brk) { target_brk = TARGET_PAGE_ALIGN(new_brk); initial_target_brk = target_brk; - brk_page = HOST_PAGE_ALIGN(target_brk); } /* do_brk() must return target values and target errnos. */ abi_long do_brk(abi_ulong brk_val) { abi_long mapped_addr; - abi_ulong new_alloc_size; - abi_ulong new_brk, new_host_brk_page; + abi_ulong new_brk; + abi_ulong old_brk; /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged */ - if (brk_val == target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page = HOST_PAGE_ALIGN(brk_val); + old_brk = TARGET_PAGE_ALIGN(target_brk); - /* brk_val and old target_brk might be on the same page */ - if (new_brk == TARGET_PAGE_ALIGN(target_brk)) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); + /* new and old target_brk might be on the same page */ + if (new_brk == old_brk) { target_brk = brk_val; return target_brk; } /* Release heap if necesary */ - if (new_brk < target_brk) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); - - /* free unused host pages and set new brk_page */ - target_munmap(new_host_brk_page, brk_page - new_host_brk_page); - brk_page = new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); target_brk = brk_val; return target_brk; } - if (new_host_brk_page > brk_page) { - new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, - -1, 0); - } else { - new_alloc_size = 0; - mapped_addr = brk_page; - } - - if (mapped_addr == brk_page) { - /* Heap contents are initialized to zero, as for anonymous - * mapped pages. Technically the new pages are already - * initialized to zero since they *are* anonymous mapped - * pages, however we have to take care with the contents that - * come from the remaining part of the previous page: it may - * contains garbage data due to a previous heap usage (grown - * then shrunken). */ - memset(g2h_untagged(brk_page), 0, HOST_PAGE_ALIGN(brk_page) - brk_page); + mapped_addr = target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); + if (mapped_addr == old_brk) { target_brk = brk_val; - brk_page = new_host_brk_page; return target_brk; } From patchwork Fri Aug 4 22:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710258 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp230030rwb; Fri, 4 Aug 2023 15:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhMovyJozCLfBSx4imigpqK5/6aXfYffsIzGBF50cnr0pMW8nl12XFO0LULYGyCinhaGrA X-Received: by 2002:a05:622a:1048:b0:40f:ba4c:6222 with SMTP id f8-20020a05622a104800b0040fba4c6222mr4026142qte.3.1691186617061; Fri, 04 Aug 2023 15:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186617; cv=none; d=google.com; s=arc-20160816; b=rP7UuQItfZBFDsRrMt3u6lQ1PTEoutHDS9D6e/GlDFngULJfyJZE3RW5A2gh/HdVTD YNXeVAwh86tb8VaOpdvLsGLFmZkh6oA9imJ7tYVMT/0fGD6GTdz4xsyIIzAYoL+vx5rc /XSObgvEUr9CV6FuR4ORn0mLuMUETUb00Z10+0kUEqky0JGBiBKNLRMlkUncmRhJ5id6 13zgPdl9bzGUQzp1iEeijz5iKXDe1dTp6Yr5r2IgG6oFXi1kcqsMzJiuw4LZ3Idr/LzQ O2OA0qUiE+JeXhRsJNNQsOaV0sJ/6f2tMy9P3YeObqxBqyUTTtVd2kPxIdMcJwjUujmj uX4w== 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=PiKvQ5TIjJkHeXd+ZGncRxkavk8D0Yfna3UAt9/lKq8=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=Gxykd1QVWogx+01y4jHVfkxYYYeJYQr69eTtmv1V+4YxdIJWbdtH9FbFcYXQid8hST bPFaOLsLoWNVvHSfQvYYNLCvTsOJaFM9tY0dWS7syI4eHvTJTwq0zkLwBePepSYFV1c6 rdRL/0VmN3fRlh/P4C0MJpTTya/nHy7j59orRVyR1D7bWkhWL0XxHWISihx5Yl4G0WYs DISe4terGYJ9PulGGYGnv1ftbEC6296EqxkHLX3SH5LKOU7Or6js+5mk+aIszdkHndwd rplaYYfnCqk1M13xlI1q19GKMwvJQ5A+s8++BX9bh9mWhFHiUG0Lh6uXu1Hbb2YsnbKL CkQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kqt7l9yV; 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 v12-20020a05622a144c00b004009ca7608bsi1958521qtx.675.2023.08.04.15.03.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:37 -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=Kqt7l9yV; 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 1qS2qs-0004mH-QL; Fri, 04 Aug 2023 18:00:55 -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 1qS2qn-0004ds-Mk for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qk-0001sR-PZ for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-563df158ecaso1723346a12.0 for ; Fri, 04 Aug 2023 15:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186443; x=1691791243; 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=PiKvQ5TIjJkHeXd+ZGncRxkavk8D0Yfna3UAt9/lKq8=; b=Kqt7l9yVrB9IbiyiVJSJhiiKf1YS8Vqf0Cxlb+3DKWlbatKEkQIhzpRLfJNRMnX3xw Wp2Gp36hiLlv3F63Xw0o0owm/tKVF9Ruhkb44jJUs0oE2bN3Y7O9Y5+UTicIuymtM49E qeUIf4NnU2Fvo+l0cR85Y7rgdlhyTrBqTOzeKagBrwFzJluDMKOfHTB1auBvdJWnaO9j TNEe4id3DTNIi3czbVJURpVj29JVOQzp92oDuf/09saRiR/kc0T2Bt/cfjmoF0lbsvEf erPqWI/nKVqBXhrrSktg79upI4kzkSa4F83LxRynjD+0dHHXYxWCUgPJZUb1b/pjAqgO tj+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186443; x=1691791243; 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=PiKvQ5TIjJkHeXd+ZGncRxkavk8D0Yfna3UAt9/lKq8=; b=XljmoQ4ZXbcLwUcwt3ZSJ7BKhLI75kK7MFatN9Xyo4yXliYVTcnq946xntmKa0te86 fa9/dPmTf34ozezbPp1Tnz4b7G36zVXm9KFItrcO07U9OPEEi7qI0Gz598ZrEnBvTQAU ac0KUFvt4f4KEElKLxUa1uRfEHje755eWs8gr1tX2hMf9HpU8VIvORfCiWoyN7TivDHH 7UXYdgteeeUm9m4W2gmDu/rE7kBB3x53ihP67Y8/oWKA5Bnmv0BOj3NdsNuGXldOE/vT nu4324ZOrkCZfspF9WGTwInVoBVRwiFqg9JUV2BIJDBe5iOE1uEgBfcDjktfxAoxWhcT dj8A== X-Gm-Message-State: AOJu0YzzUonZKz0yDjivchtJZpdT51qZ7O2iXYoQi3oQ0CSixVg2TasM g+clUyUaiQ+JUFuS3ywaU++HuFrLqchgFMmxLg4= X-Received: by 2002:a17:90a:2c2:b0:262:f0e6:9e09 with SMTP id d2-20020a17090a02c200b00262f0e69e09mr2774921pjd.14.1691186443435; Fri, 04 Aug 2023 15:00:43 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 11/24] linux-user: Remove last_brk Date: Fri, 4 Aug 2023 15:00:19 -0700 Message-Id: <20230804220032.295411-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.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 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 This variable is unused. Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 1 - linux-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 3fc986f92f..7265c2c116 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -26,7 +26,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 90b3ef2140..eb04fab8ab 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -314,8 +314,6 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. From patchwork Fri Aug 4 22:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710268 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231634rwb; Fri, 4 Aug 2023 15:06:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvsp7OO5A3wQoG+RmofgLK40e5VtxT3Qjh4gq+gE1ATSvoLxDE9taudhQlfz/WkXy+MrZc X-Received: by 2002:a0c:dc90:0:b0:636:5b43:10a0 with SMTP id n16-20020a0cdc90000000b006365b4310a0mr3485987qvk.12.1691186817418; Fri, 04 Aug 2023 15:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186817; cv=none; d=google.com; s=arc-20160816; b=T36Pxkzox2kqgEXf/qPxtUFujcdWiKBi2sDpdu/b/b5TmZtO81vqrbNUL2Eo9MsZ7b rM7sgSd1jVkbZUBDC9KmhKTiYGfomQdXV28MYmvAWRWALCKPJV4WzECSjLZu/h3/c5Mq 5ZLYLJiCt9MXCQa9hKo/vwmeUQM6/QHIQAss9FAVZASj1PL/GGtp2eySeFsIRwymoKXd MiyiKd/v2VLOsnb8voCL/vrv8oJw1SgsG2HW7Ulr3waP68GSM4gaMw3dct1odzacd6dI pMcoGQZnplLftQYvEfOP97M5x6gt0Zxgdp8eD1oVWwwvtzntvpGKc1tO3JiH4WMuccVp QVgA== 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:to:from :dkim-signature; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=XadpuKhQ1SvpIteOQhw6pwbXkcmcipvQeAuW7s6xhVkWrB2npSgBHdb+LXIzgF3J0X 60WuqFZuch2s3Gbi6pNbBqeKcNcik7rZDLqbalk3b95qmL6BukOuCLnzmizA1cjp3TxM HrbmnVkhngR+R2bo52UXaSLi4H9HYdPBl+15J21TW0jgqXRS71JI/NLv0Z9PZXbi6M7J dlKWl6ri1spwG8gvqR2dlQfQwfqjuvfSniEJ+nhydWvT4borpFaqaTUjXz7azMhUwgNp mfNWqo1llpoy3Jh1H60/NFvfvt5B7O6mNb1FZsYXYGLj6+csagVmy7RfdXqC2mYNRliY nnBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BtOVCALb; 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 d20-20020a0cf0d4000000b0063cfa978898si1847057qvl.592.2023.08.04.15.06.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:57 -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=BtOVCALb; 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 1qS2rN-00053q-Mc; Fri, 04 Aug 2023 18:01:25 -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 1qS2qm-0004au-Az for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qk-0001so-PQ for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:48 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-56433b18551so1550829a12.3 for ; Fri, 04 Aug 2023 15:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186444; x=1691791244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=BtOVCALbvnLFOrhOUcbGsyqY/H8Km9l7kikFPwfKscT6KRGcMwHGAaPyX6fRKeWWWx z5GTufoNJ7zlc5LTfwPevun1faUnAZBM9ef9hXZPeGJk29YmNHi/C+iZ/Qsw9SNDqqN5 BzhMcR4/cXmVN27YD8jhvXc0gJiX/5JeSTo1+iwyUC75TX0L0d5HlkrRT8i0DApkE30P qFnLxRj7Mo3Tq2wh2lAPlmoKd87Mw/gnNKTTPE+QIT5irlaCM0rgb/BYV14uzXtzpSS1 sUvRjF3f2c6uVajtbCvAUGzJ9k/VBg16QItjNOUX4J5bDzTeqxNU8dzM7h7LMlVlnpG4 4xdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186444; x=1691791244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=S/fbKjLw0psBGjrTREI6OGlzAir4IkxoK5ni4yFKxodrW80Qxt830IOCoykuEAMS+k t8G/gh+MISw6HyevQE5htMheqKmDQksoAI/kCMOSLB7YJZb9k1qjx8n8bBzEkDEqVW13 gukHa2FGUFwFuCMRVOq4IYZd7Q4wigN3VxewTFepvFhd1RJqusVcL0CJ09ZP4ILJfMGm ogY5Wph5mujZiW0igzHVERYAKMJ3JND7JcfX6ki/ZTdhf7V7O4vBoz5GG6iksJphL8te 3nSHYTG05O63uaAUYEWm+pDHnxuXgBkGYSUVKNAzB+9sqMJhnTMDBB+owoQ7I1D+pARV +Hsg== X-Gm-Message-State: AOJu0Ywe2c1nL3ATNg89wC4VY4v4tQ0PITEw2XKgnUMXhWRciqvqvK11 Q4gdCaAvMRlT7QFw3+TFR9kfaFcexV8cYajmnlA= X-Received: by 2002:a17:90a:4e84:b0:268:3b8b:140d with SMTP id o4-20020a17090a4e8400b002683b8b140dmr2234232pjh.35.1691186444121; Fri, 04 Aug 2023 15:00:44 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 12/24] bsd-user: Remove last_brk Date: Fri, 4 Aug 2023 15:00:20 -0700 Message-Id: <20230804220032.295411-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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 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 This variable is unused. Signed-off-by: Richard Henderson --- bsd-user/qemu.h | 1 - bsd-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index edf9602f9b..8f2d6a3c78 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -232,7 +232,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); void TSA_NO_TSA mmap_fork_start(void); diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index b62a69bd07..8e148a2ea3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -214,8 +214,6 @@ static int mmap_frag(abi_ulong real_start, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of guest * address space. From patchwork Fri Aug 4 22:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710253 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229774rwb; Fri, 4 Aug 2023 15:03:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTowSCTJd1MCWYN8EiE4Of72iAkzq5eta/qWoBRGmNQrcYpA21ozup2+d+RifvbjQpg9bb X-Received: by 2002:ad4:4f0b:0:b0:63d:b67:745f with SMTP id fb11-20020ad44f0b000000b0063d0b67745fmr2450884qvb.61.1691186589552; Fri, 04 Aug 2023 15:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186589; cv=none; d=google.com; s=arc-20160816; b=uZyhSZTRjEt3XA5UMsyGOopBwoNnk339fGKzaxCh+CKfdQUSNHdHvBTLvjWF+kEQRZ 4KXattQmWKZ15OWYkSrRQN5amiRS8MCnE18Pqp8Aok8vNHM12Dp5mzxyJP4Sscbez/2y wgR7uznBGNSRGp4uzX4ls9hhLT8a7d2DMhKNoQOEdIMuYy9h7sV0lJv2AK5/gubfvHeD XUl4acUiXdT4MTGXxnW1i0q14qB/1qow55I0MTfcu4LirH9NK3DQqHq6H6oJEXQfkVug fam3gDZlJbY4aLiNknQRiQo2EzUSIsgO/oNYowt9/24RAl3fH81EwbefY1lxLDdPMEXW ktvQ== 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=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=T8/YOJaS5rOCOzefM/90jDPJha2QPwo/0OZl9tFZFPsuU9f8P2aEzdfXrJ0687JOQm 00fX1H8Aso9q49iaaitKu+Ns4WWAPy5CJyEuCVClo8hTURPKdvMzahr7ZUgjKpsxb+TM 73r137sWik0AzXX44mhAi5G8fqzauDa2HqOEDARouP6yEr9KMOx8Ou/3jVz+I/kLkVQ2 PhoMM3BtF1aOlSYbIRR35TgmvVUaYBRzsJSiICq+P/+YGBkEIGEP7mS7zEWbf4crINC8 l8n+CKYjIRW9c8HH6Bk9BlgJDmAup88n/7MXxPjyre7PAR60As6/HOaXnWn7RFAChCeS 8ZKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u218Qan5; 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 n14-20020a0cdc8e000000b00635e18cb45asi1764445qvk.534.2023.08.04.15.03.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:09 -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=u218Qan5; 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 1qS2rM-0004xC-JV; Fri, 04 Aug 2023 18:01:24 -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 1qS2qm-0004bA-Fu for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:49 -0400 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qk-0001tE-PE for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:48 -0400 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6bb140cd5a5so2226704a34.3 for ; Fri, 04 Aug 2023 15:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186445; x=1691791245; 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=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=u218Qan5vcum+Rfw9vu5O76K4IUwz2kiqi9s99Ejp0bDKGmtDJ0iw7MOAqWRzrGGty QF9IeL9KwqAV2LTYojVBOJZzrH5l84NttRQ5MGlsQUf1dAGcVwyaet8CoyCenyD1xTB7 tt+27SDUWs1IMis+P44keNwWtBE/1OE6hSejUisNudwhCzfoL5UE1EdXzfIF6AU28hIG XgcL0xAiPU7gNtn67Se5jNFtjtwwDNuwyEsXb3BbMvqS3KDgLVNbFwz1naJZbvcqcz6j yTPcICv3y37dBnfxkpX1yBOKqpzAAM5VvW7dsSTix8yvZobgEka2UBM8z71v/H95+Ipq GO7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186445; x=1691791245; 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=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=EQYGtVXaxOVHRfHlbZgbAWGsT7yW18qYuvbt250UxdZ7U4aH5Gs0Bhtl++mp+t07o0 usD1RZhd6vdonuLjCWrJ0RGVauMYrSM+S5I60IGS/LygXFdhZqUDxn8BTo3NOTM/lmkI RXZLRtRVdjkIMlzZ+nwSUwn0jtIy7lQvmO1F/tr15XjHu4qXQ45UVGZBbnCRb8/k0wil FCS0xEZyVTLeCTq4PaeOOmP2gUfEv8/Jl7KiICnufiQRsf0cNav8xQGWzvuVl/TKMReV 79do1AkvHs2aYdJSusk9OGcDK3SYPDFRY6y6LbAGAP1SLbvnp62mgOqH9SKebd82JfyX 8aLQ== X-Gm-Message-State: AOJu0YzJo3PUtqW5MJXIlHcY+6DcFEVhyLUSjOqTJUWLhtc2fEVE8F30 cUwx7DabsNTykEf8bUXM0od67twzAZx3kppsFBE= X-Received: by 2002:a05:6870:8a14:b0:1bb:75af:37b5 with SMTP id p20-20020a0568708a1400b001bb75af37b5mr3244079oaq.10.1691186444897; Fri, 04 Aug 2023 15:00:44 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 13/24] linux-user: Adjust task_unmapped_base for reserved_va Date: Fri, 4 Aug 2023 15:00:21 -0700 Message-Id: <20230804220032.295411-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32c.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 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 Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Tested-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..7ba7039988 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,34 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Temporarily disable + * "comparison is always false due to limited range of data type" + * due to comparison between (possible) uint64_t and uintptr_t. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + + /* + * Select an initial value for task_unmapped_base that is in range. + */ + if (reserved_va) { + if (TASK_UNMAPPED_BASE < reserved_va) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (TASK_UNMAPPED_BASE < UINTPTR_MAX) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x10000000; + } + mmap_next_start = task_unmapped_base; + +#pragma GCC diagnostic pop + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return true; } -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) if ((addr & (align - 1)) == 0) { /* Success. */ - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + if (start == mmap_next_start && addr >= task_unmapped_base) { mmap_next_start = addr + size; } return addr; From patchwork Fri Aug 4 22:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710262 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231179rwb; Fri, 4 Aug 2023 15:06:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVgjSD8ml6LfgOKEtyuDdbLe5bs1T6+vwum5rz+789uYaBU1mM6spuLhR/hMwFf0d/B4oR X-Received: by 2002:a05:620a:2a11:b0:76c:7d2a:2dbf with SMTP id o17-20020a05620a2a1100b0076c7d2a2dbfmr4829914qkp.57.1691186760667; Fri, 04 Aug 2023 15:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186760; cv=none; d=google.com; s=arc-20160816; b=zsRzjsYQL5M8Ae6zq0ot6vT4BvfWEyt/74AVHHoCL99VUyHsaUMY3gPnbTFu+kr7dK Niln74muL4mSf+9CjdLFG9PNefjpeK60ko1kfFzVwnm/Yoef8ECbRmIQdan+4MonW48c TcUBMWISu+o/pxHxSDkIyv9nw7cBgyL3e5jREl5HZVAOyWn9sdnrNsFOaQmoV2SUoMY5 NIVpVkFeEPOxak1vdn6FQP5IFf9bzYzoLY9aQpjA4RqPzLw4cH4NE0fkUDZliHkTiuI7 kH8OyYf8c8Z6B48g6GNjENSSk/gsApr6VPRIXp1QzbGVRAooKBFfK0+uDkjQilL6vlDR 2QBA== 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=nsfMjTlh4URCmzpsUVnlBQkKHMyACEHtsPPiByh/vaY=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=MJZssCddZdoS86F9WIqAixgk/7QBTTaQdDvXOnBrZwTXygMjhv8kwHf2BL4udgYR86 5YQ3Ei+6ehvLGCJ35CciTx2ehvZE0kSONhBEqMZvxaQm0R1fWOgIy3XYwIzLwDqeSlg3 /zGMz2BMI4JKUG0+pb28oM1J8RqtrDO238ZKmr1cm9YU8Qc6sMItIajn7tx9N+qwLlZZ SqKN5qJa1OLDs3MOQ6kMFX1ha4WYkqySj+lnDRWTTG2rZLU0iKMSAyddeDpfA/YXotHN fruibJq/PRLTMlmhdxkcVDyWBJOD0Krr1mi/+Ng90MVHZElJMv4YcAdSF3BAQyrtm2mX MpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WPYpgn6k; 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 e13-20020a05620a014d00b00766b22110absi1819735qkn.750.2023.08.04.15.06.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:00 -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=WPYpgn6k; 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 1qS2rO-000541-No; Fri, 04 Aug 2023 18:01:26 -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 1qS2qo-0004jC-P8 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2ql-0001ta-0K for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:50 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-26837895fc8so1530273a91.0 for ; Fri, 04 Aug 2023 15:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186445; x=1691791245; 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=nsfMjTlh4URCmzpsUVnlBQkKHMyACEHtsPPiByh/vaY=; b=WPYpgn6ksN0Pa/ug70Fkadc1p54n8xR2Dt8faHSVfVY+TAFBjR3mvYjahxfAsmYCEx OAau1GCHxJaSTLra/mQKx/V0Bgtk6e0qmVo5TbhhRlXK/+1Qm9Fvi2W0o0mraYwNPqfM rKXSg6MwtlcMUTbEqWHX9xr7cTD/pIfRiJeX/3hl+oIxH5otpeQksIodoABOAvyNzFuE clz6UZwh+CLzFLI5m1rILCqCTDdP4H00833UB1nIDlFhBij39qZo5l+c+aj3a2X3iit+ HFSG3RhzGI8GxwDWrP6SVDZ9ehQENS6CNFDSp3GyL65bXNfpLVPRvTaboK/A3Ie+0vKw AdLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186445; x=1691791245; 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=nsfMjTlh4URCmzpsUVnlBQkKHMyACEHtsPPiByh/vaY=; b=fO0yInf0ewn56iIuVmCMouMORKRfTfzhaZbS/skB4epNYmBcsCn106QmewxKfEjdHK /jhpZunJ8kQzUBSMEAYV7G7AzyCPQac+rSDz7O6Hw+Er+xWOfp88gsizIIx8g/tEy6YD vm1rU1A7Wa9rTK1ZQkyddffC1vnawC8bVE60BSX9t4Fp0VSBVVpQFLQLKk5/24U6a/1Q zOZuo3+CE0rgc15T9rdiwm1vVlmhUzs3r5p6rxnJvlA3MkT358tfDSxiUIeeamJKL2vJ 9Q25+OKlSC7SPHgj8YiS5d7wLoaaVOl+J3iTq8FmdyTeba38OZVeP/glzfWDQVw8NcFm OU0Q== X-Gm-Message-State: AOJu0YwNL94O00R7r8O0qN8Q/xC0QVIYsba251WIfs4ceCPwLM8Qkso2 COI0LRXn70xQF5GznDg/HZJDLCq/8ruja83qVs8= X-Received: by 2002:a17:90a:bb08:b0:267:de82:c37b with SMTP id u8-20020a17090abb0800b00267de82c37bmr2364363pjr.18.1691186445608; Fri, 04 Aug 2023 15:00:45 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 14/24] linux-user: Define TASK_UNMAPPED_BASE in $guest/target_mman.h Date: Fri, 4 Aug 2023 15:00:22 -0700 Message-Id: <20230804220032.295411-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 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 Provide default values that are as close as possible to the values used by the guest's kernel. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 10 ++++++++++ linux-user/alpha/target_mman.h | 8 ++++++++ linux-user/arm/target_mman.h | 8 ++++++++ linux-user/cris/target_mman.h | 9 +++++++++ linux-user/hexagon/target_mman.h | 10 ++++++++++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 13 +++++++++++++ linux-user/loongarch64/target_mman.h | 8 ++++++++ linux-user/m68k/target_mman.h | 3 +++ linux-user/microblaze/target_mman.h | 8 ++++++++ linux-user/mips/target_mman.h | 7 +++++++ linux-user/nios2/target_mman.h | 7 +++++++ linux-user/openrisc/target_mman.h | 7 +++++++ linux-user/ppc/target_mman.h | 13 +++++++++++++ linux-user/riscv/target_mman.h | 7 +++++++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 4 ++++ linux-user/sparc/target_mman.h | 14 ++++++++++++++ linux-user/user-mmap.h | 14 -------------- linux-user/x86_64/target_mman.h | 12 ++++++++++++ linux-user/xtensa/target_mman.h | 6 ++++++ 21 files changed, 167 insertions(+), 14 deletions(-) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index f721295fe1..4d3eecfb26 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -4,6 +4,16 @@ #define TARGET_PROT_BTI 0x10 #define TARGET_PROT_MTE 0x20 +/* + * arch/arm64/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE DEFAULT_MAP_WINDOW / 4 + * DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 + * DEFAULT_MAP_WINDOW_64 UL(1) << VA_BITS_MIN + * VA_BITS_MIN 48 (unless explicitly configured smaller) + */ +#define TASK_UNMAPPED_BASE (1ull << (48 - 2)) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index 6bb03e7336..c90b493711 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -20,6 +20,14 @@ #define TARGET_MS_SYNC 2 #define TARGET_MS_INVALIDATE 4 +/* + * arch/alpha/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE TASK_SIZE / 2 + * TASK_SIZE 0x40000000000UL + */ +#define TASK_UNMAPPED_BASE 0x20000000000ull + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index e7ba6070fe..76275b2c7e 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -1 +1,9 @@ +/* + * arch/arm/include/asm/memory.h + * TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) + * TASK_SIZE CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xC0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index e7ba6070fe..9df7b1eda5 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -1 +1,10 @@ +/* + * arch/cris/include/asm/processor.h: + * TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) + * + * arch/cris/include/arch-v32/arch/processor.h + * TASK_SIZE 0xb0000000 + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index e7ba6070fe..c5ae336e07 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -1 +1,11 @@ +/* + * arch/hexgon/include/asm/processor.h + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * + * arch/hexagon/include/asm/mem-layout.h + * TASK_SIZE PAGE_OFFSET + * PAGE_OFFSET 0xc0000000 + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 97f87d042a..6459e7dbdd 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -24,6 +24,9 @@ #define TARGET_MS_ASYNC 2 #define TARGET_MS_INVALIDATE 4 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index e7ba6070fe..cc3382007f 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -1 +1,14 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_32_types.h: + * TASK_SIZE_LOW TASK_SIZE + * TASK_SIZE __PAGE_OFFSET + * __PAGE_OFFSET CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index e7ba6070fe..d70e44d44c 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -1 +1,9 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE64 0x1UL << (... ? VA_BITS : ...) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index e7ba6070fe..d3eceb663b 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1 +1,4 @@ +/* arch/m68k/include/asm/processor.h */ +#define TASK_UNMAPPED_BASE 0xC0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index e7ba6070fe..ffee869db4 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -1 +1,9 @@ +/* + * arch/microblaze/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE CONFIG_KERNEL_START + * CONFIG_KERNEL_START 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x48000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index e97694aa4e..fe1eec2d0b 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -14,6 +14,13 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/mips/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index e7ba6070fe..ce18f4f871 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -1 +1,8 @@ +/* + * arch/nios2/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE 0x7FFF0000UL + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index e7ba6070fe..f1aaad809d 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -1 +1,8 @@ +/* + * arch/openrisc/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE (0x80000000UL) + */ +#define TASK_UNMAPPED_BASE 0x30000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 67cc218f2e..04f99c6077 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -4,6 +4,19 @@ #define TARGET_MAP_NORESERVE 0x40 #define TARGET_MAP_LOCKED 0x80 +/* + * arch/powerpc/include/asm/task_size_64.h + * TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) + * TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(DEFAULT_MAP_WINDOW_USER64 / 4)) + * TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE)) + * DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB (with 4k pages) + */ +#ifdef TARGET_PPC64 +#define TASK_UNMAPPED_BASE 0x0000100000000000ull +#else +#define TASK_UNMAPPED_BASE 0x40000000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index e7ba6070fe..0f06dadbd4 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -1 +1,8 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index e7ba6070fe..40d149b329 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -1 +1,11 @@ +/* + * arch/s390/include/asm/processor.h: + * TASK_UNMAPPED_BASE (... : (_REGION2_SIZE >> 1)) + * + * arch/s390/include/asm/pgtable.h: + * _REGION2_SIZE (1UL << _REGION2_SHIFT) + * _REGION2_SHIFT 42 + */ +#define TASK_UNMAPPED_BASE (1ull << 41) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index e7ba6070fe..bbbc223398 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -1 +1,5 @@ +/* arch/sh/include/asm/processor_32.h */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 9bad99c852..692ebf9dd7 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -5,6 +5,20 @@ #define TARGET_MAP_LOCKED 0x100 #define TARGET_MAP_GROWSDOWN 0x0200 +/* + * arch/sparc/include/asm/page_64.h: + * TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \ + * _AC(0x0000000070000000,UL) : \ + * VA_EXCLUDE_END) + * But VA_EXCLUDE_END is > 0xffff800000000000UL which doesn't work + * in userland emulation. + */ +#ifdef TARGET_ABI32 +#define TASK_UNMAPPED_BASE 0x70000000 +#else +#define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index fd456e024e..bae49059e0 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,20 +18,6 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif - extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index e7ba6070fe..f9ff652b37 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -1 +1,13 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_64_types.h: + * TASK_SIZE_LOW DEFAULT_MAP_WINDOW + * DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index 3933771b5b..c4f671adb7 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -14,6 +14,12 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/xtensa/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 2) + */ +#define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) + #include "../generic/target_mman.h" #endif From patchwork Fri Aug 4 22:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710269 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231729rwb; Fri, 4 Aug 2023 15:07:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWaYrEn/LSlXgXahdk75jPj2Zi8OnH6db5uUKopn7ODNTGbT0Am2Q3y1w+/w5FLI4kiedi X-Received: by 2002:ac8:7f81:0:b0:403:a8d2:85f with SMTP id z1-20020ac87f81000000b00403a8d2085fmr3344374qtj.33.1691186830761; Fri, 04 Aug 2023 15:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186830; cv=none; d=google.com; s=arc-20160816; b=WYjJWH8y6aUUnlgkEpBk1m1YHMN5zqYyUiPEhYMzuLYvcQiJIEy2o8qclr6eE7TCNI JrSXKeCpely9Vo42hEd/vMk1ctH1hZNxOVBv14SF0OBhbmEmrYgl31MdEfXUjIwyheXS pGWaR5/OCKZovON153q0W7LKbeyhCxCxC5/z0CA1B0vHQR8fl2j1iv/D74h+06kTbH+Y dnse8SFgpB+vqBy8HkJCJYlSs9PKMEd/gfPeUMLdwiJc2MIKzhjrBPnZoanXciUea6Bj wQSg7h/e1Mt39G4JUTWQlGoff4zKcW+nBo3Qx4s3zxF16pSDaHioSw5rw+FSGK3NW8dP WSdQ== 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=Xi2nnTJzHZgHa81d23KxFW8Q4gCAsLnkTLrg8o9pfyQ=; fh=nKwyeXx8rt8hF214OSFP+HjBpDto8utNxLoZSNqK/Bc=; b=QhjYeBE495+O9AVJ61j4VLKfnyXR5Z9ZiGY840SMxhiNrwAdjNFTUff0pI3sKvZ+hm r8aGMX2MrnZxY7Q+DGX1pxy8W9n4TUf2zFco6n9i/m77GGRjU9iwvbUBtlGfZrBepLht mE6Uz7osfEMvXWKmizMsN0R5jrBGX830Vjb+SncJsNa1GQuirZEycyCDCpsAx70dxeRt XiuZhAm8hUUbNU13mM3pT++8W1rA0iNJIFiDTdMmRjPDLPQwbFKNHRGlehwCc24l8TKG JhJOHGApaRGpOhfwVPaHPpOICB1oFtaApY9Ihre9P72iP+OboukJhGQMh+XZeAa4MXvX CVYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tuRapI6z; 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 s7-20020ac85cc7000000b00403b1d1599asi1973470qta.2.2023.08.04.15.07.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:07:10 -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=tuRapI6z; 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 1qS2rN-00050l-2s; Fri, 04 Aug 2023 18:01:25 -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 1qS2qo-0004jB-Ot for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2ql-0001tw-Nw for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:50 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bbd2761f1bso22049755ad.2 for ; Fri, 04 Aug 2023 15:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186446; x=1691791246; 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=Xi2nnTJzHZgHa81d23KxFW8Q4gCAsLnkTLrg8o9pfyQ=; b=tuRapI6zqAAPoAA6rGFWb1FR9D7bYQaBsjEHYBdkbPsXIkxBcAUB/5uoCWTBgsDEeT zI/s9AgFpJ/X8VnRdH+OWYlhilFh7D/pZhynoP0JXzaD+0dCB8bgekdjmHTqOeVXi3Fd rWMZs1XO4UNC/Fq6dXGLcE5b9WdSVAfzWcK3J9ByFZqOhZvo538ft/tTSNWTr4tisVg2 IZPlPojPHi7sh4lkJQzPb/H7OSW8ShB2pprQqZUWk9ogsQTJlGcWfBHAelKPBsdwN1c9 xq/9SF7aRIQ68VAhtUCJuQPP9Bs7IKJkr5SzW8rkAY6iGe83RpThfWbLR3rzyizqiDiJ y/IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186446; x=1691791246; 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=Xi2nnTJzHZgHa81d23KxFW8Q4gCAsLnkTLrg8o9pfyQ=; b=G+R/lGmmqXWnVTUZ59j7MituzQAS2ITw9VuGjSBMbywq+gZawV1+eSP64kVO/GmVOS spUZ40+fbl54gTeOcGS3Z/YbCgy3Nolbvci9TivjidEZitiUuAQOXqCzmvWuMINg7PGm 8cknKfgY51bUgBx5otr84BpGRLiKOsSBmuPe7Fap86XsrzNhYggFSMwPQyCngcIMVD24 mVe/h00xa+OnLfMGtVG7GBAtOv4zp278+brP1UMe5NcNrKKM1pcLAbI2MrzfXlOkTH7x UclrZ35QPhZ1r5hXMlYxYO2YhoLIwZ6cYb5XL4bpJ9cRUSeWQmu1Wr/TOvN/3ooQPAq7 mwYA== X-Gm-Message-State: AOJu0Yz8GaS/yCfOBXiItcPQr944iY05brqwmA/msLa6gzpLrcbQ+7cj b46FOT/izRQR7IudaxVunkh8V+e/yA5JsT4e4Vc= X-Received: by 2002:a17:902:ab86:b0:1b8:400a:48f2 with SMTP id f6-20020a170902ab8600b001b8400a48f2mr3057299plr.62.1691186446399; Fri, 04 Aug 2023 15:00:46 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH v9 15/24] linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h Date: Fri, 4 Aug 2023 15:00:23 -0700 Message-Id: <20230804220032.295411-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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 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 Copy each guest kernel's default value, then bound it against reserved_va or the host address space. Tested-by: Helge Deller Reviewed-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 3 +++ linux-user/alpha/target_mman.h | 3 +++ linux-user/arm/target_mman.h | 3 +++ linux-user/cris/target_mman.h | 3 +++ linux-user/hexagon/target_mman.h | 3 +++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 3 +++ linux-user/loongarch64/target_mman.h | 3 +++ linux-user/m68k/target_mman.h | 2 ++ linux-user/microblaze/target_mman.h | 3 +++ linux-user/mips/target_mman.h | 3 +++ linux-user/nios2/target_mman.h | 3 +++ linux-user/openrisc/target_mman.h | 3 +++ linux-user/ppc/target_mman.h | 7 +++++++ linux-user/riscv/target_mman.h | 3 +++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 3 +++ linux-user/sparc/target_mman.h | 11 +++++++++++ linux-user/user-mmap.h | 1 + linux-user/x86_64/target_mman.h | 3 +++ linux-user/xtensa/target_mman.h | 4 ++++ linux-user/main.c | 15 +++++++++++++++ linux-user/mmap.c | 1 + 23 files changed, 96 insertions(+) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index 4d3eecfb26..69ec5d5739 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -14,6 +14,9 @@ */ #define TASK_UNMAPPED_BASE (1ull << (48 - 2)) +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index c90b493711..8edfe2b88c 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -28,6 +28,9 @@ */ #define TASK_UNMAPPED_BASE 0x20000000000ull +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index 76275b2c7e..51005da869 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/arm/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index 9df7b1eda5..9ace8ac292 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -7,4 +7,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) +/* arch/cris/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index c5ae336e07..e6b5e2ca36 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -8,4 +8,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/hexagon/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 6459e7dbdd..ccda46e842 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -27,6 +27,9 @@ /* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index cc3382007f..e3b8e1eaa6 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -11,4 +11,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index d70e44d44c..8c2a3d5596 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -6,4 +6,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/loongarch/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index d3eceb663b..20cfe750c5 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1,4 +1,6 @@ /* arch/m68k/include/asm/processor.h */ #define TASK_UNMAPPED_BASE 0xC0000000 +/* arch/m68k/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index ffee869db4..6b3dd54f89 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x48000000 +/* arch/microblaze/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index fe1eec2d0b..b84fe1e8a8 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -21,6 +21,9 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index ce18f4f871..ab16ad4f03 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) +/* arch/nios2/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index f1aaad809d..243c1d5f26 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE 0x30000000 +/* arch/openrisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 04f99c6077..646d1ccae7 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -17,6 +17,13 @@ #define TASK_UNMAPPED_BASE 0x40000000 #endif +/* arch/powerpc/include/asm/elf.h */ +#ifdef TARGET_PPC64 +#define ELF_ET_DYN_BASE 0x100000000ull +#else +#define ELF_ET_DYN_BASE 0x000400000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index 0f06dadbd4..3049bcc67d 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -5,4 +5,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) +/* arch/riscv/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index 40d149b329..c82435e381 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -8,4 +8,14 @@ */ #define TASK_UNMAPPED_BASE (1ull << 41) +/* + * arch/s390/include/asm/elf.h: + * ELF_ET_DYN_BASE (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1) + * + * arch/s390/include/asm/processor.h: + * STACK_TOP VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE + * VDSO_LIMIT _REGION2_SIZE + */ +#define ELF_ET_DYN_BASE (((1ull << 42) / 3 * 2) & ~0xffffffffull) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index bbbc223398..dd9016081e 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -2,4 +2,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/sh/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 692ebf9dd7..696ca73fe4 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -19,6 +19,17 @@ #define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) #endif +/* + * arch/sparc/include/asm/elf_64.h + * Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE, + * so move it up a bit. + */ +#ifdef TARGET_ABI32 +#define ELF_ET_DYN_BASE 0x78000000 +#else +#define ELF_ET_DYN_BASE 0x0000010000000000ull +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index bae49059e0..5dd48a458d 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,6 +20,7 @@ extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index f9ff652b37..48fbf20b42 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -10,4 +10,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index c4f671adb7..8fa6337a97 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -20,6 +20,10 @@ */ #define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) +/* arch/xtensa/include/asm/elf.h */ +#define ELF_ET_DYN_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/main.c b/linux-user/main.c index 7ba7039988..cb5e80612b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -847,6 +847,21 @@ int main(int argc, char **argv, char **envp) } mmap_next_start = task_unmapped_base; + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (ELF_ET_DYN_BASE < reserved_va) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + elf_et_dyn_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (ELF_ET_DYN_BASE < UINTPTR_MAX) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + elf_et_dyn_base = 0x18000000; + } + #pragma GCC diagnostic pop { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 84436d45c8..949c4090f3 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -301,6 +301,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; /* * Subroutine of mmap_find_vma, used when we have pre-allocated From patchwork Fri Aug 4 22:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710260 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp230192rwb; Fri, 4 Aug 2023 15:03:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlF7zF0EMYSaHJEEjYt1lDmqq22iEaOiEa3ylouj/JjPw9kKD2ezB4JfrmlnB/uPap3scT X-Received: by 2002:ac8:5896:0:b0:406:8bc2:6ba8 with SMTP id t22-20020ac85896000000b004068bc26ba8mr4479705qta.2.1691186632014; Fri, 04 Aug 2023 15:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186632; cv=none; d=google.com; s=arc-20160816; b=OcjwLXtI6j+173d764KT6MuFTxATBj1UvxAvv+70fGIsx3gM0ssMKRAX+J/znPlDTo 7Oez6abfkTjA64RAfJUIzoL4G622LlVaSo5iuoMpZGhd92FQMaSTW4+1jlUrGBGolyMt 3XKXwdG6pksr0E6JDHwgySdU5gyqGe9Nbq8UuWeEjD/4UWlzpAzeQY3kMQTvlq30Olz8 V35YFZJYLfGhFUl9vbMriAOds5iM92IV52N48ISexH0jlZo5M+EN/Aiw6eIG4/bkP89p ibz+ugtngvtNG9p9qFVR3tdK+tfHBXdLPy0b54Yz2422cfxHz96mrldrDjojVio9fYKL gZmg== 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=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=Iq0H4obk66+b2RiWl2+H5O1qxSNfBADAWiG575qEOrWvEvwbvO3xB2iWDZ6bTBMAIK CPiSPDMSTE9LB95Eb7BiqXpynnonFBMTniZOb/n59uLFET3bpX4UAkXoRg2Tshvbgksx 0N9YOYX0TaHV9yXnq39Xf3Ssr4V4yW8h4lJ6PG6Odv+yhr19mfErkjGzQzELbnlsmVwB pfQE2nXbSGIrJ5YneUJSBZuFT2omU0n7Tkjz91FuVTWxRYWjmeBYCRSMfZ0PSPPd3RXl ygTWKzA3DCpR6STCgTEgtTDJl9fJaGCkuqsT01x//DLMooqubMQMv1wuACj4PtGrG82+ xodQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pK3wQkDQ; 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 b22-20020ac85bd6000000b0040fdfccdd48si1877667qtb.759.2023.08.04.15.03.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:52 -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=pK3wQkDQ; 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 1qS2rI-0004tf-2m; Fri, 04 Aug 2023 18:01:20 -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 1qS2qo-0004jA-OL for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qm-0001u8-KD for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:50 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1bba48b0bd2so18545125ad.3 for ; Fri, 04 Aug 2023 15:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186447; x=1691791247; 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=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; b=pK3wQkDQgtPhaZj82WmJ4r4+65CGKOEob0gPr/U2/ymvNB3pVdAJsoWfsZpPV3kTsr Na/1M8SCL3mE8Hl1hZRpD4Zt2f8YRnbWcZwPC1WyhUanPox4UzDqRs5JLbrZNC6mNIP0 GZR5XFPT4iAqUHdqd+YCF79Zkm9jef4fvcxxCS4MCyZCJkdWMtdMeYey1d/ChoHYBNF6 N5/raIA1fCLYIM/kFhqFn/uSosT7n8wkWqGh8Fp20w9g5iworApac+upaaYNGMFY72R+ W85d3MBmJcI0hoc9a2FlYKNn8MuULKkoGy8Te9nyeLE+0Ry/I+I21nqUICE2dMRo6zUX Jqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186447; x=1691791247; 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=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; b=BZxHjYl4fk2D+wuCRqQw99aVIkh++txeUDKcRg7VXHDwbherCyGLxpweFvHc+ZgBnW DOIgDIJ58iqz3XW8I4jSH20CBZwaoZ4RHHRz8TguoQNJW3OtBUMrDlRWyoAWdFT1Mz6Q tF4WzU39qVx81hqzFOpjgmr6XgDpG6+246dROEmkybkMTpylm7KvKmogxRFC5Go+LBV9 6LMZwOJ0J4Yn6CG7fg2HKL6FM1Ze+Fxxu+LhUch42MwUyC/FVgqUJDqvjjbORoWJdU4u mYuUi13UvJoWrYxoPSvani7ZOGF1s4k7dIaUqn5fX1RwyMqDgKB3hmQDrT72aBdQWJDe Jlfg== X-Gm-Message-State: AOJu0YyZuk/dMhR1db0XSPuVgr2eK+QC7g3Osm7pdlqZ50dDXCnALhnj iZdaiIbQYhv4Tdpq54sOMikWVLZfZ35KjKKhUmc= X-Received: by 2002:a17:902:c409:b0:1bc:56c1:a394 with SMTP id k9-20020a170902c40900b001bc56c1a394mr1346207plk.11.1691186447340; Fri, 04 Aug 2023 15:00:47 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 16/24] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Fri, 4 Aug 2023 15:00:24 -0700 Message-Id: <20230804220032.295411-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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 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 Use this as extra protection for the guest mapping over any qemu host mappings. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2aee2298ec..0c64aad8a5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3146,8 +3146,11 @@ static void load_elf_image(const char *image_name, int image_fd, /* * Reserve address space for all of this. * - * In the case of ET_EXEC, we supply MAP_FIXED so that we get - * exactly the address range that is required. + * In the case of ET_EXEC, we supply MAP_FIXED_NOREPLACE so that we get + * exactly the address range that is required. Without reserved_va, + * the guest address space is not isolated. We have attempted to avoid + * conflict with the host program itself via probe_guest_base, but using + * MAP_FIXED_NOREPLACE instead of MAP_FIXED provides an extra check. * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is @@ -3159,7 +3162,7 @@ static void load_elf_image(const char *image_name, int image_fd, */ load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), + (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); if (load_addr == -1) { goto exit_mmap; From patchwork Fri Aug 4 22:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710263 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231241rwb; Fri, 4 Aug 2023 15:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3d4bhnDS5Oin+wzGWNPP9QvH9kfEh+CZ748E8NOYMHlqTGgncitr00KZelRzwK43rIv1Q X-Received: by 2002:a05:620a:388c:b0:767:dd2c:9a1 with SMTP id qp12-20020a05620a388c00b00767dd2c09a1mr2779049qkn.20.1691186769349; Fri, 04 Aug 2023 15:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186769; cv=none; d=google.com; s=arc-20160816; b=b7OwhITcVZsk/hyvj4suO8UZUudr6NRmAm8ETIzRbwUyPDM1nOPPaIuwCCxN1+8foj O4DDY8u7GTUeSIQu+SCk2m1Zt+lL4iG/mCK7PWReZG3gH9vtUO5WXBRg1KdYOxw4FmIS ROSyprX+wOQziXlKBLesLffnJQtSIAgRnynTUZm7iW15OOKG+JABOOS+CubTW6EjrPhI fGzA+t9q94z70gYhHDIbdLXgt/yR1nbzZaUpIgnZ6N6ed63DN0bmvc7kODsh5LWjbYVn hvlyfLwIxgQYvCQ/luEPCo9YsjYTC5uesasSZE/4Drj2JjRw70RYgwhuNLA8kQ141vVf vcug== 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=gDTWs7pBzjEM4yDIiLCCxRn3NjvKLf/PjlJHIm+hkqo=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=P08emE3x1oRRsurNhULMxCRqLY5Hrbll9CEsP+xd/4ukQJdNkDWjCUN1O61Ej/6Qpr bNZyG4MIoLQ60S3uSCuLxhUHD/NUSjTwoaNg9jyN/Afuhw/fK1z+XwEwsLovD5BhdLom ho2z0Q2/mSdl749FEyf34JrPZbo4aDh8Kx038O88UEUE+etYxFJ8I9fZXWBMdSVfikOn BcFcaNbCVmjjobPXUxXjmxqPoQ5mH6+eDIL3xdtjazIkCoMtw0D4SQvoTaoPDDB6lpr+ zzTHbiskBOWWF5eBxHZdmlRakE2eu+1sdr+5qaapuIeYSNLTW61abDSlcC+3zHuHZNMm rLug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mFbhnmTO; 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 dw4-20020a05620a600400b0076caa0ba36csi1821442qkb.141.2023.08.04.15.06.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:09 -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=mFbhnmTO; 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 1qS2rQ-00058p-68; Fri, 04 Aug 2023 18:01:28 -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 1qS2qp-0004jD-C4 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qn-0001uU-PV for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:51 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-26928c430b2so612948a91.0 for ; Fri, 04 Aug 2023 15:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186448; x=1691791248; 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=gDTWs7pBzjEM4yDIiLCCxRn3NjvKLf/PjlJHIm+hkqo=; b=mFbhnmTOb9ortZswDG+WagB9Agyol7SfS4pfZuQXSuaMrwSpR2swynWQcxlIQm0oaB aqip3iqhxos7VSf+GYw2dK1Q/osOCMWBEu0BwF9uMnd+ymwE/FShs28LAcH4pGWRwgXe 59A7MTDJaDG+zW0f2kBLPxNlvxJBovi5nE6dHHqSs9w13oNn5OgF58mXQWZboFpznlZt K9wT2cFUGYCaehKBDUtHlFvxmRv2peCZHXrt/yKUoTBIgSCwdQbXYUqaOndl6Awz+/X1 pZxuP/ic3TNwR90ckP7URy1YNRvQyg7UkzyOjreeTQclEd+PwK0i0x4XmJ32Eo1d9b4Z F/RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186448; x=1691791248; 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=gDTWs7pBzjEM4yDIiLCCxRn3NjvKLf/PjlJHIm+hkqo=; b=kCTAlsoUg04saBi6CZV2pn2vDSdfznDQ++f2gE4zewRAltTMNE63PJwKhvT8cQHj0A H1DAuLyhIzdB8ltf8P2oVhmRpw6vGb2osy5tbzouLcTpzB+vEi3/parxGn70Rl9t8uRF SdluXVTix5CdbRXr8LH+YckDwEa/ygJOx+TjlNrvOnzAdEWGI+R3oNRkatF1ht5wcRjM B6vAcesKgCy8k7oyZTvjnH0QLHl1YHH3EM6Fz687c0rMIUoWw/XoFbuQkIoiSwm0mb0q c9nyuiNQf9YkI5SWS6dP0B57ksfo/ESLeNX1+J4xWocQekmOUJ2iZC2hwMUZptJWEq/h qVZQ== X-Gm-Message-State: AOJu0YygKGC8bjY2LMyztKYmg7sQq/pp5Ae13CbaW8kk9BMs7Zrq5/6N FxUJZzHHGxHt3QvHpx0YgcWdyRO18c7N1OQ2b1o= X-Received: by 2002:a17:90a:c8:b0:25e:bac2:314c with SMTP id v8-20020a17090a00c800b0025ebac2314cmr2611176pjd.23.1691186448452; Fri, 04 Aug 2023 15:00:48 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 17/24] linux-user: Use elf_et_dyn_base for ET_DYN with interpreter Date: Fri, 4 Aug 2023 15:00:25 -0700 Message-Id: <20230804220032.295411-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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 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 Follow the lead of the linux kernel in fs/binfmt_elf.c, in which an ET_DYN executable which uses an interpreter (usually a PIE executable) is loaded away from where the interpreter itself will be loaded. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0c64aad8a5..a3aa08a13e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3106,6 +3106,8 @@ static void load_elf_image(const char *image_name, int image_fd, } } + load_addr = loaddr; + if (pinterp_name != NULL) { /* * This is the main executable. @@ -3135,11 +3137,32 @@ static void load_elf_image(const char *image_name, int image_fd, */ probe_guest_base(image_name, loaddr, hiaddr); } else { + abi_ulong align; + /* * The binary is dynamic, but we still need to * select guest_base. In this case we pass a size. */ probe_guest_base(image_name, 0, hiaddr - loaddr); + + /* + * Avoid collision with the loader by providing a different + * default load address. + */ + load_addr += elf_et_dyn_base; + + /* + * TODO: Better support for mmap alignment is desirable. + * Since we do not have complete control over the guest + * address space, we prefer the kernel to choose some address + * rather than force the use of LOAD_ADDR via MAP_FIXED. + * But without MAP_FIXED we cannot guarantee alignment, + * only suggest it. + */ + align = pow2ceil(info->alignment); + if (align) { + load_addr &= -align; + } } } @@ -3154,13 +3177,13 @@ static void load_elf_image(const char *image_name, int image_fd, * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is - * pre-linked, LOADDR will be non-zero, and the kernel should + * pre-linked, LOAD_ADDR will be non-zero, and the kernel should * honor that address if it happens to be free. * * In both cases, we will overwrite pages in this range with mappings * from the executable. */ - load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, + load_addr = target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); From patchwork Fri Aug 4 22:00:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710252 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp229772rwb; Fri, 4 Aug 2023 15:03:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrLZG8m8zpodWt5XcvprSkvGZhJBVNkVelRArieWRQTZ7RtiDN0a+unPaYWOqUTpb1lf2e X-Received: by 2002:a67:ce05:0:b0:447:48ab:cfeb with SMTP id s5-20020a67ce05000000b0044748abcfebmr2610303vsl.11.1691186588810; Fri, 04 Aug 2023 15:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186588; cv=none; d=google.com; s=arc-20160816; b=oF15vIH+j8Q11PfeGddI/zTIXpmiJVvwPlcp9fWMSF3P4o31j6pKCY/xVNAKzLIOQ2 hBxwlOzCJ36pCqDlaFgx6uj1GInI6VY3T/B/oKAwWQJW5xrSt4m5k078wl7JvLFuf2yu HAoEQgGsAlxCoBDGI0wJP7UkoC3+j0R9mFxbMT6dQ/B42zYeCKfF6xzPXWUhNJvDz8Gf /LvDcOW3Gd++GqOLWb5ZntFaDKVe/lm19B/BaCyW/kpkw+Lo2cF2M/a24/xePxF4g0HX l+A3vUIYR/n3JRnlJGz6B/CDmO0QR5qYomKeoilqt91l3z8PGnpSb0uTR5KHZtxWEUO4 19Uw== 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=LEtd4K5hRnVc6hrl39zIoY3R0ensohNvKsrzBxsSkfw=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=opef5oSzmDgaEjxVJZk8xkJN4MRkJGz73b0U0cvRSUqCkgCw8gd3iwbgN7aXahThdp 7Qq0UiH+BB9j6yepURHHhFkbOX83bYHny2HskIMvknfXGAPW46Ut8pKKoNUA0FVzOAPC 93MFMRlr176FEhUijybkzZMsRiLW4k9HzLQtWZDJb9LchwzxliQrE7ihxV024jPCsIei qwCXEArj1EuIO5Gw1ewD5CtIrIh55XDIof/evcEApW2hVrJ1I96lCvePVuT8jagdt8vS /ZgG6DiNaQXHy5o7Dk/LaMyOnYGHjOZ7sNNIPTPesPNVjN8L5rS7ewHAQrBJnexyvrP5 n5ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V2odV32C; 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 g19-20020a05620a40d300b00767d4aad122si2013245qko.301.2023.08.04.15.03.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:08 -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=V2odV32C; 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 1qS2rO-00053t-5I; Fri, 04 Aug 2023 18:01:26 -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 1qS2qq-0004jI-FL for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qo-0001ut-Nv for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b8b4748fe4so18865885ad.1 for ; Fri, 04 Aug 2023 15:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186449; x=1691791249; 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=LEtd4K5hRnVc6hrl39zIoY3R0ensohNvKsrzBxsSkfw=; b=V2odV32CCUGvjYsqvFcVwvYXnDB71UZs6vy9o1S4G11aaFP4nF5h3rl35xZJ/qnMpU RXrrsFeyewEj2AUT1aE0ew0U4cg0CaZQ87xttli1sX+LK1GMkU2fNm6hJYsG2fezChky /MVDeGqKHMCS8PQ6+Idb4D/ycH4z8wni9Fdx4ap4N4P145EDSMsBPYOX30c4DyOa9RzF uHuByzIE+2eAkKkjc5T+4NAikFxSRpjJHVRET9Z4zkAsfuoWI0ruztg8TUZpiHUk4dwP q411fqjLkViMvcGT65bOb7gmHuNgGgJnZpiHSGmuTOc9kH1JCtF9BUER89wmjkpSMwp1 szww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186449; x=1691791249; 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=LEtd4K5hRnVc6hrl39zIoY3R0ensohNvKsrzBxsSkfw=; b=imok3u/lt9G0zzSkWVhspwhJ57pzy2yja2uW8X6NHPkPeeRUc2UlVERUSq8MU14PGk S7yituQhxd+5bBcQkjdnkACeFBZ0A8qVaq8IzQ3ygXB/6lVan61NTmPrvhofonXAjzbm SnODaDrKr8w15zbkh+tUz/qSlkbjBDLVMCTq2WPW+TavP1V8jzljb3phzKz6Tb5zqA+i oLvCLhm/8GwghY86iu+5fB5bM6DVxlz0tZ09jzQpWFyGRnLo8hdMgWSVgnTYhkwEQfZl t4xpCTnMkKE7kpDwVQ8O3tsn73gm6K3EvpSSTxCphtpy4yN28roYUW6RKuqU8ozgbQw4 jp8Q== X-Gm-Message-State: AOJu0YyAOancidT5+4M0dM2wF/7LT4WMRckg2k+PI+vesYHFkLwqsBVD W+Nsbfgmpyu6XcwceJEFSGrhkTVTUg0TN62Fw2E= X-Received: by 2002:a17:902:ecc5:b0:1b0:307c:e6fe with SMTP id a5-20020a170902ecc500b001b0307ce6femr3110738plh.10.1691186449265; Fri, 04 Aug 2023 15:00:49 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 18/24] linux-user: Adjust initial brk when interpreter is close to executable Date: Fri, 4 Aug 2023 15:00:26 -0700 Message-Id: <20230804220032.295411-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 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 From: Helge Deller While we attempt to load a ET_DYN executable far away from TASK_UNMAPPED_BASE, we are not completely in control of the address space layout. If the interpreter lands close to the executable, leaving insufficient heap space, move brk. Tested-by: Helge Deller Signed-off-by: Helge Deller [rth: Re-order after ELF_ET_DYN_BASE patch so that we do not "temporarily break" tsan, and also to minimize the changes required. Remove image_info.reserve_brk as unused.] Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/elfload.c | 51 +++++++++++++------------------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 802794db63..4b0c9da0dc 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -31,7 +31,6 @@ struct image_info { abi_ulong end_data; abi_ulong start_brk; abi_ulong brk; - abi_ulong reserve_brk; abi_ulong start_mmap; abi_ulong start_stack; abi_ulong stack_limit; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a3aa08a13e..fa0c9ace8e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3109,27 +3109,6 @@ static void load_elf_image(const char *image_name, int image_fd, load_addr = loaddr; if (pinterp_name != NULL) { - /* - * This is the main executable. - * - * Reserve extra space for brk. - * We hold on to this space while placing the interpreter - * and the stack, lest they be placed immediately after - * the data segment and block allocation from the brk. - * - * 16MB is chosen as "large enough" without being so large as - * to allow the result to not fit with a 32-bit guest on a - * 32-bit host. However some 64 bit guests (e.g. s390x) - * attempt to place their heap further ahead and currently - * nothing stops them smashing into QEMUs address space. - */ -#if TARGET_LONG_BITS == 64 - info->reserve_brk = 32 * MiB; -#else - info->reserve_brk = 16 * MiB; -#endif - hiaddr += info->reserve_brk; - if (ehdr->e_type == ET_EXEC) { /* * Make sure that the low address does not conflict with @@ -3220,7 +3199,8 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_code = 0; info->start_data = -1; info->end_data = 0; - info->brk = 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk = TARGET_PAGE_ALIGN(hiaddr); info->elf_flags = ehdr->e_flags; prot_exec = PROT_EXEC; @@ -3314,9 +3294,6 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_data = vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk = vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3645,6 +3622,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); + /* + * While unusual because of ELF_ET_DYN_BASE, if we are unlucky + * with the mappings the interpreter can be loaded above but + * near the main executable, which can leave very little room + * for the heap. + * If the current brk has less than 16MB, use the end of the + * interpreter. + */ + if (interp_info.brk > info->brk && + interp_info.load_bias - info->brk < 16 * MiB) { + info->brk = interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ @@ -3698,17 +3688,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) bprm->core_dump = &elf_core_dump; #endif - /* - * If we reserved extra space for brk, release it now. - * The implementation of do_brk in syscalls.c expects to be able - * to mmap pages in this space. - */ - if (info->reserve_brk) { - abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } From patchwork Fri Aug 4 22:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710249 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp228999rwb; Fri, 4 Aug 2023 15:01:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFLiANhJK3LxDdgDYs9yC3VCAU8nCJD6x5vQTS55Zf1IwtsmBBiPtO2JHQDA1x+z8ZeLdy X-Received: by 2002:a05:622a:512:b0:40f:d27a:4370 with SMTP id l18-20020a05622a051200b0040fd27a4370mr3817465qtx.49.1691186512139; Fri, 04 Aug 2023 15:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186512; cv=none; d=google.com; s=arc-20160816; b=ytAHLaFEqXoxuyUtTRIvn1pAmXJhi0Ujsyb8ZZxVV/1IGMeW+PAFEkotXpVhHUwQRH lpYBSESs/6FAKcKosmpLLgOM+fMg3r1UaTX1ulEWpGtxl4jkWFdFjozT0gAfhmzzF2ce 2rFYcCbnEMBVCmT7kg2YY+ZHwGEZjUNFrFrZWGbqpKYN5MOhNfBDJ/+73qz8gSTYn5bi CCee5ujlayHc1wOppyyKW/fkxKHBlm2ScrhfePmalMDfaD2dreZ6KoMB0gF9+hZPnyZe 7dLyh72qbbJ6PH6HtUNegZUa+TwhhS+4WPvUluqhxG5rHXK9x2PfYjNXblj9y3feP/rT ORBQ== 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=4+a1ntD1nPZIq5/3BuYdNWBqjL6H8GnZs4Nnik5eIQQ=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=FrTYmWxsjtlcnG+tOXJx2UztDKhlJJXBFTlFnqplvWsq+oLACrji+we5oZAY8iQrOP 0J/IyvkwQCI696l5mbyOy0+/qgCCYieLrvafd9I89YnEmVJxqNn3D84mvK70dL5kuOzE 8DqKfBjFCwiRIeNMqg/eGjF+P0Bz278H7ICIpmqNKaGvoAii9fCScmd9/V5j+I9xF3pH X9icZ4W2fKQU+SDjB7i4rfkqPlQ23+q2f/KR1/aVlVc1ti0o1LC5870dNQq7D57Tjv3o baAxiCPziWVeWtIoaPiFNQ86gCO128zYoHPLDuwAITOsbYPD1b1yEnu5FHDTPxZ5Rh4U T7Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Xqv/SKUu"; 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 s1-20020a05622a018100b004009666434fsi1927840qtw.664.2023.08.04.15.01.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:01:52 -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="Xqv/SKUu"; 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 1qS2rG-0004t1-4u; Fri, 04 Aug 2023 18:01:18 -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 1qS2qr-0004kW-1w for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:53 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qp-0001uz-Ar for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2682e33509bso1722994a91.1 for ; Fri, 04 Aug 2023 15:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186450; x=1691791250; 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=4+a1ntD1nPZIq5/3BuYdNWBqjL6H8GnZs4Nnik5eIQQ=; b=Xqv/SKUuQXPpsV5T23HQVOtPeceJm3UQP7aCM79PY6XuknhLpqMJYz+7E3pCTR8XHC tBk11FplI1128MKzc3p+DwAYdTYTlk8z/RuqXLO5+WzKoiNCAwINS3M+NkVr07EwbS9v rIpbXSoAOrN5b7nkQqp0Upw0wD277HfWuaGc+1WGIk4jWV3t/q6UTrQTz43Oe7pjtMjS rsZA27ctS2ePmBH9imqEKBcNIbFVgw5vXh1wl8Nvch0INb9qOzEOEasacZ4AAopvq9eh XO/HufO3LUvIucwyRKWRnxF34pQJSkYMEl8Udw1l0gEbflygf9plFc9Hm9TphlTvfLA5 6Jog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186450; x=1691791250; 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=4+a1ntD1nPZIq5/3BuYdNWBqjL6H8GnZs4Nnik5eIQQ=; b=ke/M1qd9cUyJUg5q0OQ7yd2HXCToCQYpiCItRF4cHQECBC8uynUJslW7neWplxKYRe t5FPkmpDQSw/KUOHowwmCOMt22txLpJ+rw8IsM+7PeCSLJBab4xuryll5JW64+iRSdai 5f3/FYwgM3ljpaQTDrkVwOwDoSw1U/50Mex54YcLJbtAc9tO2o07yMQZ/YQ6SDCtjYlq 1No0t+i3MnxxKNERU5nD44lb6piaub2tW+S61KqGrfpxez+1+vftcspYESR7q0FpYDpt FtB9IjoueT8etS6Diz/WLCiXb+wHvCEGWpgxEX+ISS+zpc1QhX2k9gF4lkZ49upjixgp Y/yg== X-Gm-Message-State: AOJu0YwV2Q32jTe8Ev0QfKOOiAQHYd+fWeMrVb+zP7nTWt2VsStsaPBK apa3bOSCasVTQEqQRBDD6luqGBt6aP57GqwQpQc= X-Received: by 2002:a17:90a:408d:b0:268:13c4:b800 with SMTP id l13-20020a17090a408d00b0026813c4b800mr2830057pjg.21.1691186450173; Fri, 04 Aug 2023 15:00:50 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 19/24] linux-user: Properly set image_info.brk in flatload Date: Fri, 4 Aug 2023 15:00:27 -0700 Message-Id: <20230804220032.295411-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 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 The heap starts at "brk" not "start_brk". With this fixed, image_info.start_brk is unused and may be removed. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/flatload.c | 2 +- linux-user/main.c | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4b0c9da0dc..4f8b55e2fb 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -29,7 +29,6 @@ struct image_info { abi_ulong end_code; abi_ulong start_data; abi_ulong end_data; - abi_ulong start_brk; abi_ulong brk; abi_ulong start_mmap; abi_ulong start_stack; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 5efec2630e..8f5e9f489b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -811,7 +811,7 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) info->end_code = libinfo[0].start_code + libinfo[0].text_len; info->start_data = libinfo[0].start_data; info->end_data = libinfo[0].end_data; - info->start_brk = libinfo[0].start_brk; + info->brk = libinfo[0].start_brk; info->start_stack = sp; info->stack_limit = libinfo[0].start_brk; info->entry = start_addr; diff --git a/linux-user/main.c b/linux-user/main.c index cb5e80612b..96be354897 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -963,8 +963,6 @@ int main(int argc, char **argv, char **envp) fprintf(f, "page layout changed following binary load\n"); page_dump(f); - fprintf(f, "start_brk 0x" TARGET_ABI_FMT_lx "\n", - info->start_brk); fprintf(f, "end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); fprintf(f, "start_code 0x" TARGET_ABI_FMT_lx "\n", From patchwork Fri Aug 4 22:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710270 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231792rwb; Fri, 4 Aug 2023 15:07:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2uPx1P1wTJ0clgxqSmOWJBscufapUOHleHGNgZEKsVnleroUdtrHjrN6mdhcauV7RguII X-Received: by 2002:ac8:4e50:0:b0:40f:f860:f025 with SMTP id e16-20020ac84e50000000b0040ff860f025mr3905944qtw.40.1691186838119; Fri, 04 Aug 2023 15:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186838; cv=none; d=google.com; s=arc-20160816; b=avbtXlEeSr9a6sQrVOAIxqMExNsxxA6Vfth11QszB+RjuvHrZJJMhG34sGjDe3cOKW EwIfu1nT+SjA1gVxPMtfVbnRyGK2wgZgJ8mX+al4txrBO1wuBRJ3b77fNIqHEm7eG+1x 2cdTA8tyJpAmUgUOoBMC4Q3Gy76tPwI6ejAXeUPVt3xxQd05iZwpUp95/UrDyrFKAgf4 sh60t0fcEx2p/MLR9zEtCGGKb8S54thZ+hVMquLLnSayVnt7nsAqX0kXlxwD51NNUEA5 4wFfJMctzxkPEBT4obFxzs7K/85A4ChYL2gokloU0XZSEl21HGhLsV2khJ8Aagd3eN62 fPNg== 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=0VLnmjiDjAi6Gl+LJx+pmU5KrGv5xMTSD4fN49XrjM0=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=oJERZEY5l4HNI56G9VTuRQMG6ETVmdDYoHPuiJgFhfu6LMlNzHKU/X82IMhoJv9U4c QFkHrsPWJeEeesFDKzHWISHBwM6Qmoa8QJnUK1K4ET07cMnvv0WB8V1f76A5mJCohU+s xUeZh8BNVEeRofGfaXXdUUwpLzjsPdGMaMIpTazLx4eZNcnOFDGU1DflntfUTlf/IClm SA5riZMjWCN3wRR0eE98xcycivuiRyM7CAuUaUjOEBYIn+iakF51he62XCVOztyRp01Y Eio9gaKUZXDpgCWQ+5qL2S7G8D/JPKDbGv0M2XtovxoHEaEP3shde5IA41wUE6WlesNm z0PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iM8rStIS; 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 v19-20020a05622a189300b00403b4d30335si1945703qtc.331.2023.08.04.15.07.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:07:18 -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=iM8rStIS; 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 1qS2rN-00053s-PJ; Fri, 04 Aug 2023 18:01:25 -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 1qS2qs-0004lP-05 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:54 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qq-0001vR-DF for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:53 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bbd2761f1bso22050105ad.2 for ; Fri, 04 Aug 2023 15:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186451; x=1691791251; 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=0VLnmjiDjAi6Gl+LJx+pmU5KrGv5xMTSD4fN49XrjM0=; b=iM8rStISP/kbHq5bgwFjLPgHYhwXqvoj/tKh+lukRLdQVI4NobFYK1dooL1XW8H2GH F8IQ/cI9cxS256vFZcEvOPnSjol36O7pcvTrUUwyozUHzcusLaTjTipXNIBPzN6w71xz yNE+TRyHHkk5Xh95pJ+vezSGxlME/JiiopdZruJLxDIq3jzUo0tQlsjWzs3XcvLXe8wM u0rayxXCCZBiIQDKpjTsbaqHkf1Z8BPtVqbDqmbLRFEI8ZqNv0ypAdEr3xmh+fFHh6cU G7zRn2l6HRy8bS4QDGVPjyt8qIK6aZhwmN5X8+taQ+4a80yVQJbxyiAoXaySbjI/Shpg DmYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186451; x=1691791251; 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=0VLnmjiDjAi6Gl+LJx+pmU5KrGv5xMTSD4fN49XrjM0=; b=iEX3R1zl+K0IvNnjQj/b9uhBEY2dIlBrPK3aaRYI2ofP3Gc+W93Z5VuDgyDuU95+Ul ZnwodqHgon8QT4XijBw4SyxrBoui6PiPQc0U2CeVcD4/H3m4Ni3/7xIPVSdHH0CrCd3m nby07O41jlIyJDuc91/weO+b2h8rpyBBbv+2TwhP0sWdUNtdFj/26IghatJvDPdpTfK2 3u6H+TDPXBcUmYm6+nJStEODQ4Cnxmabt2DohbNWFQQKAMtE1RSkobfgbROOjjNOhAH3 MerfG0oVp4Fz8Tk6cpdrdvQJqi8XqSw+gYGis4pnLwh0HDKeptki5EAQcRthz7a+ngJy Z0Qg== X-Gm-Message-State: AOJu0Yzs4GLuLSL40VYHX9a0Kv3jT7nO29o8bWiC9+AgCW99r/NtcUiv qqAZOLlfL6ynLsDnsNFygZ7mCzIxGwWrOgW3oXM= X-Received: by 2002:a17:902:ec8c:b0:1bb:edd5:4644 with SMTP id x12-20020a170902ec8c00b001bbedd54644mr3450857plg.68.1691186450989; Fri, 04 Aug 2023 15:00:50 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 20/24] linux-user: Do not adjust image mapping for host page size Date: Fri, 4 Aug 2023 15:00:28 -0700 Message-Id: <20230804220032.295411-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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 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 Remove TARGET_ELF_EXEC_PAGESIZE, and 3 other TARGET_ELF_PAGE* macros based off of that. Rely on target_mmap to handle guest vs host page size mismatch. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fa0c9ace8e..e853a4ab33 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1959,15 +1959,6 @@ struct exec #define ZMAGIC 0413 #define QMAGIC 0314 -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE \ - (((eppnt->p_align & ~qemu_host_page_mask) != 0) ? \ - TARGET_PAGE_SIZE : MAX(qemu_host_page_size, TARGET_PAGE_SIZE)) -#define TARGET_ELF_PAGELENGTH(_v) ROUND_UP((_v), TARGET_ELF_EXEC_PAGESIZE) -#define TARGET_ELF_PAGESTART(_v) ((_v) & \ - ~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) -#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) - #define DLINFO_ITEMS 16 static inline void memcpy_fromfs(void * to, const void * from, unsigned long n) @@ -3240,8 +3231,8 @@ static void load_elf_image(const char *image_name, int image_fd, } vaddr = load_bias + eppnt->p_vaddr; - vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); - vaddr_ps = TARGET_ELF_PAGESTART(vaddr); + vaddr_po = vaddr & ~TARGET_PAGE_MASK; + vaddr_ps = vaddr & TARGET_PAGE_MASK; vaddr_ef = vaddr + eppnt->p_filesz; vaddr_em = vaddr + eppnt->p_memsz; @@ -3251,7 +3242,7 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); + vaddr_len = eppnt->p_filesz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); @@ -3267,7 +3258,7 @@ static void load_elf_image(const char *image_name, int image_fd, zero_bss(vaddr_ef, vaddr_em, elf_prot); } } else if (eppnt->p_memsz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_memsz + vaddr_po); + vaddr_len = eppnt->p_memsz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); From patchwork Fri Aug 4 22:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710267 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231623rwb; Fri, 4 Aug 2023 15:06:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGekrwJxccTTaBOC5MLubmrSYw3BeYLW1CjJB9cxcC9/8o6PM39WUD0WHrf/P+tCI7qzTqx X-Received: by 2002:a0c:ab43:0:b0:63d:2567:f255 with SMTP id i3-20020a0cab43000000b0063d2567f255mr2486418qvb.24.1691186815097; Fri, 04 Aug 2023 15:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186815; cv=none; d=google.com; s=arc-20160816; b=Q+vJJ7hjJ8Zo8494eWWSYHIjY+IG7/xXnowjiWKKkQ0dJ8wNQ1q4GOXDrcBs3BuV6w Zio9JqH1YFPlBSnDtJls13njN2FmlVEqZ8i/IUkXTxJAiztuodI2OXbZG+CZoMxWVEQM MpgITOxhAnrfb6qsUbLs/Kvdpr+Ze2/2f3nUYiJH1PPLaEE1foAlwM0BKdVL6XpQYqsL jJ36IkP7q/S4nKcBPp47+pZ/iV9vm4lMiSzbG+4Aap9K9FMHlTEcIWhu/pHwxQn9LwU3 gVNSbX+COMF6eq9SdSdqQHjBOW6Wh5Fy6F1t3YLUDqWIxIjy9NdHeaddzv+PGYMc2ihc 2a2g== 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=pvFTLwUMkS+6GPsb80SMav1nz0he8vMhLPlsnSzlwUACFIRWR+Tkg2OgjSGjwPq5WW B948pHun78NL7if0labiuYT1T8OR/hV0K+tazP4oEyPdk/wVAWcE/LoQ5HGc9JxwfcgT fI4iFI6oKQcu+viHgaBhRjQHlhtkMb32amUWLhShDlRwx+16Tt15vYnWFKKzOawFs8xD fJEPRm30dXbWTjvVwvnhqgM/BFP8+K/YV7+bNJ0ztkBSSKUr96rTkll4oUlVEBXZi9Km D6WhQKnjbFicJESowYQLmVFnNtk3htehuNyn/AdPLtjcXyOzu5HjdJVvg6gvASn8AN04 9CXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gmsp8c2G; 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 z8-20020a0cf008000000b0063d2a59e430si1883022qvk.357.2023.08.04.15.06.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:55 -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=gmsp8c2G; 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 1qS2rO-00053v-BB; Fri, 04 Aug 2023 18:01:26 -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 1qS2qs-0004mI-Qg for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:55 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qr-0001vX-4N for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:54 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bb2468257fso18112725ad.0 for ; Fri, 04 Aug 2023 15:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186452; x=1691791252; 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; b=gmsp8c2GoRKN3FQWE/T+jUBYHzwWW5Cs3lkXAiQEBnaYIbWGzgDjMzexZ8lYVwCrQ8 GPlDgTnS6AKx85oa9px2YGs6oNkOPR3a4ISIJ637XPt5htOtcppM1yoM0U33ABPT57S7 N5pACJAc5Yr2Cz+gYNGTYpFsiFWI5LlSLZlFOU2DYz3mQhbX8VMuRcRafBXdIa2XRGNg E26viS+ZXARzz6vIJ0awUii8HACplyiqzUe9gbPIppQtRA/K+HNVX2u6rHsM8iUjFm09 1ywX+FVetvRKQiNJgUJx2MPOJe998aVvy+OtHWtlpUvV7M1TzXIsYqrHw1ztKtjmHJwp hZsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186452; x=1691791252; 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=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; b=QWMjdLdR4TO0Vk4y3VuBa8m7IX12jw8a2KCeFCSoV12uz+pwZxEpfLYQdinbCS6/74 8g0ibbLVPYD1t8fqUCPtHI7QLaj5gBqYEyu4dpUnlC9OVcEeT5Sj+QDnUKtu/pnT7bND +B7HOTEb+KGJBVFXqMTZpckKz0XkYvHrwv7jtNQI2KPcHuADbKB8b6PRD9MRparuxYqE iUphtDeFzdQFBQIDajVlPtg92qT8gY/9mizDFrslcFfLghL0b2JLwBUp415SGaK2VYdt bYO+1mD+Q82JZyn7IRkqBQ69Z275/U51M3GtU/86AwHwSbMFROMvjsuC7JDX+FT568wQ aAew== X-Gm-Message-State: AOJu0Yzt0jKuiFuimQUCakPkhlLrorAUQUP3V6lhO8JiOW3ygmsc0cCo I0EtXLNQYZrH1FWdAZ+dV00lUumBN4oJjU8/+r8= X-Received: by 2002:a17:902:bb8b:b0:1b9:d2fc:ba9f with SMTP id m11-20020a170902bb8b00b001b9d2fcba9fmr2751404pls.11.1691186451762; Fri, 04 Aug 2023 15:00:51 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 21/24] linux-user: Do not adjust zero_bss for host page size Date: Fri, 4 Aug 2023 15:00:29 -0700 Message-Id: <20230804220032.295411-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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 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 Rely on target_mmap to handle guest vs host page size mismatch. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 54 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e853a4ab33..66ab617bd1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2212,44 +2212,36 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, /* Map and zero the bss. We need to explicitly zero any fractional pages after the data section (i.e. bss). */ -static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) +static void zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) { - uintptr_t host_start, host_map_start, host_end; + abi_ulong align_bss; - last_bss = TARGET_PAGE_ALIGN(last_bss); + align_bss = TARGET_PAGE_ALIGN(start_bss); + end_bss = TARGET_PAGE_ALIGN(end_bss); - /* ??? There is confusion between qemu_real_host_page_size and - qemu_host_page_size here and elsewhere in target_mmap, which - may lead to the end of the data section mapping from the file - not being mapped. At least there was an explicit test and - comment for that here, suggesting that "the file size must - be known". The comment probably pre-dates the introduction - of the fstat system call in target_mmap which does in fact - find out the size. What isn't clear is if the workaround - here is still actually needed. For now, continue with it, - but merge it with the "normal" mmap that would allocate the bss. */ + if (start_bss < align_bss) { + int flags = page_get_flags(start_bss); - host_start = (uintptr_t) g2h_untagged(elf_bss); - host_end = (uintptr_t) g2h_untagged(last_bss); - host_map_start = REAL_HOST_PAGE_ALIGN(host_start); - - if (host_map_start < host_end) { - void *p = mmap((void *)host_map_start, host_end - host_map_start, - prot, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { - perror("cannot mmap brk"); - exit(-1); + if (!(flags & PAGE_VALID)) { + /* Map the start of the bss. */ + align_bss -= TARGET_PAGE_SIZE; + } else if (flags & PAGE_WRITE) { + /* The page is already mapped writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); + } else { + /* Read-only zeros? */ + g_assert_not_reached(); } } - /* Ensure that the bss page(s) are valid */ - if ((page_get_flags(last_bss-1) & prot) != prot) { - page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss - 1, - prot | PAGE_VALID); - } - - if (host_start < host_map_start) { - memset((void *)host_start, 0, host_map_start - host_start); + if (align_bss < end_bss) { + abi_long err = target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (err == -1) { + perror("cannot mmap brk"); + exit(-1); + } } } From patchwork Fri Aug 4 22:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710264 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231577rwb; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPzU+kIMU7QvI8KPPAjwboERuNh8KZ9qaTpjqsGM4pOyO6ziwWhkmcd20HCgqvmwGeBENx X-Received: by 2002:a05:620a:4707:b0:767:e807:e5d0 with SMTP id bs7-20020a05620a470700b00767e807e5d0mr3630238qkb.60.1691186809108; Fri, 04 Aug 2023 15:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=google.com; s=arc-20160816; b=Td/oj1KyFiRdSONSrUbqtIwkLPES1yCVnyukpt2rckq+IyD1p8Mc//l06ggahhKlHk UXqQW+HV5kUITEtYdCP0jbvVNWSkifKHOsO0QpNKkzJuvW0S2UfkGUKePKRW0ja8jsYv 2d28L6SigBgjv0mWutqwMFI2ceQgMjW9cbukDwapMwmd7Rnxj2pp8c1jusFu/gCAldmA pbB8Ht7CXSUiS5P0bZJDLQzeG0pJQ7WvHxcYcctMa8COKpGrsktRRk0Cddo3fCKqaa/h sEdwqaDqzpKyTG1zxqZpIrgb6qNYKcg/u/KaYI2ZlXgQlL653wiSscl/e79jBRZdyuQU 59KQ== 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=huskeRM6ExVZUoYAZp4mC/pVAmNkKT1TgboJ92h4fy6FhgbySug28kPNflEgrSL5be vzopWXDLv2QEdLJVunLcvzb+1tRUwsAXYkl+P+fp4t3VSy2vBGo++RHWEDtuWXNPnPIZ gxUozI0mtjXgkF3vDb48pBmxzrwZCL66wKosAyDvl4h5Py8ryhiZ/3PsMQRudfe8tG0p qg5efq/mjh8bxMUbHMHlAYroITMpl+IB1GFejvXGgLkcC5UwWMoV8uXiRjcUcd2gpIiJ zkLY0YyP3vMURNIRNWb/u5LycC6rVDbYCv7mfRyq/zXAMYoUU1zyJ51Y+0UVxnvRTedp 9ufw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2myYZA0; 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 u7-20020a05620a454700b00767fd0121f1si1985417qkp.252.2023.08.04.15.06.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:49 -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=D2myYZA0; 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 1qS2rO-00053u-Ak; Fri, 04 Aug 2023 18:01:26 -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 1qS2qv-0004ma-A4 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:57 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qs-0001vr-3X for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:55 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-26813cd7a8aso1718601a91.2 for ; Fri, 04 Aug 2023 15:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186452; x=1691791252; 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; b=D2myYZA0FnTgN3xdV/0JJ+PQg4BxOJIOoE/mCOhOFFK9OPnNQMczF2h28Eq6OE/6U4 yCd4TvWIOd+k3GZgDgYAsWzGCbf1tQN2ZnRXp8TeD0IOaRFqc7Om1XN0ZJcvpPvz1w9q Do5XPGuPXwFBtuFQh9+PjOvKu0+8z1jsUYaVzKmKWLz4miOskdxmrjyT5bjRMzyqqWL6 ZVBECEKIXw6yADfdltNVZuhJaWMEs8T2HCUbindSWg+FmoJy5kFs3mf1sKrRorfBq8Jn iLAxsUpaDNtFogoEJTJXPm/Hu4uRGGZwcRMMl8wyCd/brnM4VBMx1Wuw5ziHnrmNT/7/ qj6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186452; x=1691791252; 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; b=QqL1QkBoGPp8f3aVizmHdhDLKWzlCYsbAAIUtAsC0TeFEm1yQ5tkN8kBuQ0YnkkGb1 LtkJIHk7vecFyz7nVOwdaOmgMf3nrDx3/V5YgpTtNJHg2BodUB3a2snABD1YzjEtr7KX F/CepLwiFCeqjJdz0eT2c2Dvq/b6foF+J7K4DoCxn/CPY2cC6CK7BDID01z+RvJNFOA1 Qf4+xZr0Zgrbu2MLx5yzEF2FgApEbKUFPrhwNapJ6y6L36yWcLXRTF8bbpndVHechtck pjW5j7JdQ+UfOpVrZ65jgy3QQOG1aNPcxuCcsCdqRfeX+R18E8wqfxUe0YNEHOhzZpbs pV7Q== X-Gm-Message-State: AOJu0YzQCRUpVKKm0CVerskBCmLJomDvtGmC3BTzdG69IEWiQornVIsb Kz3dPKPGhEsPg+fN6ADoB2St75mRfd0qivo6b0s= X-Received: by 2002:a17:90a:c7cd:b0:268:5c3b:6f37 with SMTP id gf13-20020a17090ac7cd00b002685c3b6f37mr2927327pjb.0.1691186452517; Fri, 04 Aug 2023 15:00:52 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 22/24] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Fri, 4 Aug 2023 15:00:30 -0700 Message-Id: <20230804220032.295411-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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 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 If p_filesz == 0, then vaddr_ef == vaddr. We can reuse the code in zero_bss rather than incompletely duplicating it in load_elf_image. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 66ab617bd1..51591a1d94 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3209,7 +3209,7 @@ static void load_elf_image(const char *image_name, int image_fd, for (i = 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { - abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; + abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em; int elf_prot = 0; if (eppnt->p_flags & PF_R) { @@ -3234,30 +3234,17 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = eppnt->p_filesz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED, + error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); - if (error == -1) { goto exit_mmap; } + } - /* - * If the load segment requests extra zeros (e.g. bss), map it. - */ - if (eppnt->p_filesz < eppnt->p_memsz) { - zero_bss(vaddr_ef, vaddr_em, elf_prot); - } - } else if (eppnt->p_memsz != 0) { - vaddr_len = eppnt->p_memsz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, - -1, 0); - - if (error == -1) { - goto exit_mmap; - } + /* If the load segment requests extra zeros (e.g. bss), map it. */ + if (vaddr_ef < vaddr_em) { + zero_bss(vaddr_ef, vaddr_em, elf_prot); } /* Find the full program boundaries. */ From patchwork Fri Aug 4 22:00:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710265 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231582rwb; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFc+rcMo2PYZjQ9WZT5KSDbJUAqnveVtakpXdfqS9BKkvtwZO5B2YuaV/qXek16F//QpsTb X-Received: by 2002:ac8:5a47:0:b0:403:a385:d920 with SMTP id o7-20020ac85a47000000b00403a385d920mr4063753qta.26.1691186809402; Fri, 04 Aug 2023 15:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=google.com; s=arc-20160816; b=JhXBcMv4PVqRvQfMuu5rAPzngi9YMahFWI0dWiGFBmPbt2mUsTJG042K44JmUWBXqY O32EImZIRbFaO/W1+fD0luAtp3yPWvThFLt1eKWC5mGH2YC2X80iIVTFs0Vaxf1F4VBl o5RUC+4muaEMKRCNR2mDe46JDa0Qjxmqe7lragQKPh6rSkj/pLcf51ooOf9VSynRF3cN YoJD7aAXgqmSnmO9usVkxFOZu8m0fb37Tt1lgB+RF9gt84XAIEkFN2FVVC/5tR2Ts+Jc MTbmOF8Vl7ZNMsfUqkwk2Mv7NiJLnpn1vBhC27tPNwSaov0T85B6+hf+NF5lUwotWNo8 WW3g== 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; fh=Q92HZIlqtyucC1SOx0hVIY0BQ6aYzDDOpcVF7DuLR5k=; b=Cbt3vooL7wFJqgYuFNHlVg4vBpQ5FE/Tevi+zOfmOKhaXCmNp54bUIt4VAfIDUvN1j e7pGhDHnM+gwiRqKd3cYIF0fwMxN/k2nT88dOW5hxoib5UrRXs37OGbHhg0zjr2TA6uN iDU7OPFqtm+nzPMa9cubxVvor5Xzi0MQIP6+I+kMWf4RT+DRWYvGigEMhaWKTA0bHnD7 Pr61dxI45CsjLgkVHE5QReK7E1kl+Ks8T3EiAUsL/dKHStdmtjgs07T7+SjJvK9Z5XlL ZC7hnlylRBdC54643MoO1p2tZ7AomtiOHJF6JtlxBMmZgk1ZYTNkEL+Ie3DC6ciwwFoL 77eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yrIm1u+s; 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 u33-20020a05622a19a100b0040550f160cbsi1851581qtc.248.2023.08.04.15.06.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:49 -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=yrIm1u+s; 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 1qS2rN-00050m-3E; Fri, 04 Aug 2023 18:01:25 -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 1qS2qv-0004mb-A6 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:57 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qs-0001vy-IB for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:55 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bbd2761f1bso22050295ad.2 for ; Fri, 04 Aug 2023 15:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186453; x=1691791253; 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; b=yrIm1u+shFtPbvtO7Z8qFba5AnaVPrhLqDDO8MuFiRiP1N4ytR2QTouJSYsEvGZbAU 2kzJR7kBvcNYzzikQ7rYDE0B8NPBSLmnJ96zGNqs60MvRmAG90G/Rd/CRjXQEGGMY3UU ybQ+RqTFCsqZALGq2mJMLMLRrW+9z2YxsrEP+248gVamGBda7BYVPUGi6LIZ2ir9Ca8p 7nqaoMbL2TXo95/td/IjVkJpaXAbhNTfiA/6rpPf9KOJo+cUHW/f2pYx84NSZNZHkxTM 0NwSF8tnD+GiysZjSD1TSMmWsx8y8oT75mg6vlNseQ+BkzOigzRq/fh8LQozJwDMjnUq Y2Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186453; x=1691791253; 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; b=HQrRIWsyoWbFeJX2VF0wi5WpGDjI11wy5JnAh4fqTDwgdAD5gdECIuXSzfUUbHU52J CraNW+94pCj71Qp3NiEztTUUT47UH5sEmf5yixKJL+UqeMoYYnZUdCAN0tNjPhKmD2DN 6OUiRW8/1SrR1FGwfaZ7XhKFPHE33ZcYY2arnw7oskxYlgCv93HPev+mEwXhhF6E17zg WmEas8tTf1smW/8W1NbzheBUBsBrYEN6ojG8lCzGAf0MoEej22f1OS/wrftJnE3UZ87O DDrFvkC2PdNITm3+cvbQl+IaBixQ9JgjKSkwQotC1xBb2pL8SvMb3bJf+xNEfTYjGm6/ LSvQ== X-Gm-Message-State: AOJu0YwG81DvE+QUTg5IXAdTCSx7hmJYE1xHWcpBWcFhtE5TGUGe/NCQ EgDS6U8g5ljBDUnrH5oLI1xACd2JZ/N3vKlue9I= X-Received: by 2002:a17:902:e804:b0:1b9:e091:8037 with SMTP id u4-20020a170902e80400b001b9e0918037mr3727329plg.30.1691186453371; Fri, 04 Aug 2023 15:00:53 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikhail Tyutin , Dmitriy Solovev Subject: [PATCH v9 23/24] accel/tcg: Call save_iotlb_data from io_readx as well. Date: Fri, 4 Aug 2023 15:00:31 -0700 Message-Id: <20230804220032.295411-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 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 From: Mikhail Tyutin Apply save_iotlb_data() to io_readx() as well as to io_writex(). This fixes SEGFAULT on qemu_plugin_hwaddr_phys_addr() call plugins for addresses inside of MMIO region. Signed-off-by: Dmitriy Solovev Signed-off-by: Mikhail Tyutin Reviewed-by: Richard Henderson Message-Id: <20230804110903.19968-1-m.tyutin@yadro.com> Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 4b1bfaa53d..d68fa6867c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1363,6 +1363,21 @@ static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, } } +/* + * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. + * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match + * because of the side effect of io_writex changing memory layout. + */ +static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, + hwaddr mr_offset) +{ +#ifdef CONFIG_PLUGIN + SavedIOTLB *saved = &cs->saved_iotlb; + saved->section = section; + saved->mr_offset = mr_offset; +#endif +} + static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, vaddr addr, uintptr_t retaddr, MMUAccessType access_type, MemOp op) @@ -1382,6 +1397,12 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, cpu_io_recompile(cpu, retaddr); } + /* + * The memory_region_dispatch may trigger a flush/resize + * so for plugins we save the iotlb_data just in case. + */ + save_iotlb_data(cpu, section, mr_offset); + { QEMU_IOTHREAD_LOCK_GUARD(); r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); @@ -1398,21 +1419,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, return val; } -/* - * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. - * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match - * because of the side effect of io_writex changing memory layout. - */ -static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, - hwaddr mr_offset) -{ -#ifdef CONFIG_PLUGIN - SavedIOTLB *saved = &cs->saved_iotlb; - saved->section = section; - saved->mr_offset = mr_offset; -#endif -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op) From patchwork Fri Aug 4 22:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710259 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp230038rwb; Fri, 4 Aug 2023 15:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNSBCtrnLtlNium0CLUTT2alNQr9RUeesfXVbuaiNnw3kMlpuvzZd4IBeKaxPUBVx2L6GB X-Received: by 2002:a9d:4813:0:b0:6b9:b1a7:1f92 with SMTP id c19-20020a9d4813000000b006b9b1a71f92mr2877498otf.8.1691186617603; Fri, 04 Aug 2023 15:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186617; cv=none; d=google.com; s=arc-20160816; b=AqkRVf25+QNlahCW5qESiSNjnRZZEZ+wsWr2T/2aj25+DAu/4HKKIQNSnkC3HItzZU nt7CbJkuv5MgiFLrT9IeMamkqnxcWsf8z2txFPqyn/aE7qPylWEGeMbRwjIIQoEtRgt3 5K10DX+qhLeUsaBUlL2mse5j1aBApI24YQFlaNiDjlXazE/ekODytqN4E3FTNVAqLVxu ALxqoswTXEWFHVURg+GWrJeDHKEGPHc62iKAvGwVf6KgtSplhN1xff+g3Y+fJAy8BL2h KP8mjn+YeL4pkR1Ihxy+pe8nE6OAyVmWABlaMEbehINi45/HRaJkj6viMm7nNU3ED1A+ ZTfg== 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=33FWwcFvaizWH4t629x3Vf1EkBPMJLEp9WeUHM35B6g=; fh=v50xmCPEMFOIbaYlDCfPzxUB5xs3fQch4cdtTCJGBiQ=; b=LHUOEwJVC33q4sKzQmAqmjBsKX+ikMv2BEHwyBXY5hTsH4jrZdbWNfVturhApUmTxw htj6V3R8rOmFx1zdmk+mSzCtrDV8+eHR3v8nucUgmRSWhdi89xua73W9hyiRfgnQWGUj MJYVyen1vhPSwKNYJVbJYZaF09i023h1x6iCDPIwPOfnUVCRYmf3bu+KAcJc6ejs2b7F GfziP/dRGuhr3sjBzLF9phXX92MivJtQhz+E0ljgjhRDqus1yz8R0WaNVh3h7lvAlInm YkBEE95geSr8iZNEtnsILJHcrqTSU/W7W9DOi8NzwqFSXI4LMjQM+gnZqoctY78Oh5xp 2c6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n2P9/gib"; 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 i8-20020ac85e48000000b003f38c9bd035si1791372qtx.782.2023.08.04.15.03.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:37 -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="n2P9/gib"; 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 1qS2rP-00054R-1U; Fri, 04 Aug 2023 18:01:27 -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 1qS2qx-0004mx-Ba for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:59 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qv-0001wK-2A for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:59 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bbf8cb61aeso18851105ad.2 for ; Fri, 04 Aug 2023 15:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186454; x=1691791254; 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=33FWwcFvaizWH4t629x3Vf1EkBPMJLEp9WeUHM35B6g=; b=n2P9/gib7RFga7fGmkdai246rrDfCSpYy88tyBEHZeh9vgWCf9wV5Lkd4k91znDhbK Ly2OrFHrpNjNUx9qMZRcsRj+nk+Eeb1/wDvSaaPzSnWrgV3tUPP6eo3Xj0Z3XCAIqAra dZz8ftO9uKPiYSIuAZfukfyOaYhNHfZDDKtfex5go0b+lobCs92KilpePOkTMhCSg8q0 iXOV0R9Bf3VGPQzI6a3CctlrhX12VxWOKZnhk58vOHcFU6xBbrN/hXgIiDSbEZN80uCT fmnUjb5H95COcT25J5xAhBjbwiKeRhA15gSWzFxoCGBYnflt/aEDqTRWSxOH5UKwuiqF Se+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186454; x=1691791254; 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=33FWwcFvaizWH4t629x3Vf1EkBPMJLEp9WeUHM35B6g=; b=GBuVBkk/Osi4WguuJI4S5GCNMbKKUTtvwbYYakKehFosnswWUeWs7UYAt8sEP37BCq GtcVLu4bJf7bjWCc1VVcDBXK/uaIJV7LeLyF8Sq3Dx8XkV/ja7XFCLw4wEgV8pWcjU6s YPy5XUopDWwreLQBMzBr19fB/ieh6aNDMJl0Lb71Syt2HfDu+ei83oWG1S6mNBj8KqDs yl8SYopHLQwaXqYIRLHj7hxRbdfP7IPZ9oHKnJnDcLfA67KaiYLSlLtWO3KheFc/frI9 Nm0JKWuuKm7Lk/3nQCHoCaR7jLGdNNAmC1EZ/yWxHYCXmuzsJ8AiDmg63BP9gVnJk5f7 Ls7w== X-Gm-Message-State: AOJu0YwyjP4QIx3waNg/YBxbHYHrVFPCeLpuPn/ZNOGiOzkyRPyklUjQ exwyP+rM/OQeuHGKSnuxYxBaHKSg9ljSi4wOofE= X-Received: by 2002:a17:902:ce8c:b0:1b9:e913:b585 with SMTP id f12-20020a170902ce8c00b001b9e913b585mr2556383plg.13.1691186454267; Fri, 04 Aug 2023 15:00:54 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Nathan Egge , Daniel Henrique Barboza Subject: [PATCH v9 24/24] linux-user/elfload: Set V in ELF_HWCAP for RISC-V Date: Fri, 4 Aug 2023 15:00:32 -0700 Message-Id: <20230804220032.295411-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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 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 From: Nathan Egge Set V bit for hwcap if misa is set. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1793 Signed-off-by: Nathan Egge Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Message-Id: <20230803131424.40744-1-negge@xiph.org> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 51591a1d94..c9e176a9f6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1710,7 +1710,8 @@ static uint32_t get_elf_hwcap(void) #define MISA_BIT(EXT) (1 << (EXT - 'A')) RISCVCPU *cpu = RISCV_CPU(thread_cpu); uint32_t mask = MISA_BIT('I') | MISA_BIT('M') | MISA_BIT('A') - | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C'); + | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C') + | MISA_BIT('V'); return cpu->env.misa_ext & mask; #undef MISA_BIT