From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186605696905.5083423373708; Fri, 4 Aug 2023 15:03:25 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IFEeXIqiTPMF9/MKl6L+UpoKJLhPCg/4vTSW7vvkOgruZXUsQS5qCbOITcqif525+7Pgw1U9Q== 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1691186607538100003 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=C3=A9 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, v= addr 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 =3D p->full; - vaddr addr =3D p->addr; - int i, size =3D p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i =3D 0; i < size; i++) { + for (int i =3D 0; i < size; i++) { uint8_t x =3D io_readx(env, full, mmu_idx, addr + i, ra, type, MO_= UB); ret_be =3D (ret_be << 8) | x; } @@ -2232,7 +2230,9 @@ static uint64_t do_ld_beN(CPUArchState *env, MMULooku= pPageData *p, unsigned tmp, half_size; =20 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); } =20 /* @@ -2281,11 +2281,11 @@ static Int128 do_ld16_beN(CPUArchState *env, MMULoo= kupPageData *p, MemOp atom; =20 if (unlikely(p->flags & TLB_MMIO)) { - p->size =3D size - 8; - a =3D do_ld_mmio_beN(env, p, a, mmu_idx, MMU_DATA_LOAD, ra); - p->addr +=3D p->size; - p->size =3D 8; - b =3D do_ld_mmio_beN(env, p, 0, mmu_idx, MMU_DATA_LOAD, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + a =3D do_ld_mmio_beN(env, p->full, a, p->addr, size - 8, + mmu_idx, MMU_DATA_LOAD, ra); + b =3D do_ld_mmio_beN(env, p->full, 0, p->addr + 8, 8, + mmu_idx, MMU_DATA_LOAD, ra); return int128_make128(b, a); } =20 @@ -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 =3D p->full; - vaddr addr =3D p->addr; - int i, size =3D p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i =3D 0; i < size; i++, val_le >>=3D 8) { + for (int i =3D 0; i < size; i++, val_le >>=3D 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, MMULooku= pPageData *p, unsigned tmp, half_size; =20 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, MMUL= ookupPageData *p, MemOp atom; =20 if (unlikely(p->flags & TLB_MMIO)) { - p->size =3D 8; - do_st_mmio_leN(env, p, int128_getlo(val_le), mmu_idx, ra); - p->size =3D size - 8; - p->addr +=3D 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); } --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186601582711.620389696041; Fri, 4 Aug 2023 15:03:21 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IH8HxhXZsRQDqEB2/hwbU/evBnMN0UadASQ44VRcQ2BNfwDd2yYKmmX/Q6zaKjhAosZScQAHQ== 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1691186601846100001 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=C3=A9 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, C= PUTLBEntryFull *full, uint64_t ret_be, vaddr addr, int size, int mmu_idx, MMUAccessType type, uintptr_t = ra) { - for (int i =3D 0; i < size; i++) { - uint8_t x =3D io_readx(env, full, mmu_idx, addr + i, ra, type, MO_= UB); - ret_be =3D (ret_be << 8) | x; - } + uint64_t t; + + tcg_debug_assert(size > 0 && size <=3D 8); + do { + /* Read aligned pieces up to 8 bytes. */ + switch ((size | (int)addr) & 7) { + case 1: + case 3: + case 5: + case 7: + t =3D io_readx(env, full, mmu_idx, addr, ra, type, MO_UB); + ret_be =3D (ret_be << 8) | t; + size -=3D 1; + addr +=3D 1; + break; + case 2: + case 6: + t =3D io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUW); + ret_be =3D (ret_be << 16) | t; + size -=3D 2; + addr +=3D 2; + break; + case 4: + t =3D io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUL); + ret_be =3D (ret_be << 32) | t; + size -=3D 4; + addr +=3D 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; } =20 @@ -2680,9 +2710,41 @@ static uint64_t do_st_mmio_leN(CPUArchState *env, CP= UTLBEntryFull *full, uint64_t val_le, vaddr addr, int size, int mmu_idx, uintptr_t ra) { - for (int i =3D 0; i < size; i++, val_le >>=3D 8) { - io_writex(env, full, mmu_idx, val_le, addr + i, ra, MO_UB); - } + tcg_debug_assert(size > 0 && size <=3D 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 >>=3D 8; + size -=3D 1; + addr +=3D 1; + break; + case 2: + case 6: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUW); + val_le >>=3D 16; + size -=3D 2; + addr +=3D 2; + break; + case 4: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUL); + val_le >>=3D 32; + size -=3D 4; + addr +=3D 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; } =20 --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186590; cv=none; d=zohomail.com; s=zohoarc; b=LqOek+WJVoIjamiNg6DCreBWw7jTGdDbdVY9fn/wbgvGfp51TGdGLmydHiNurEXqyYIX8jJUTWCeke/XsmqNaRmFL91lP1/6IoOH+GcZkDvBb6lkRi/0nIDjWJTdAY0QbQgo8bkRavhBkisogZ3O5pDYhy5Vu1PAJHcymyJsWLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186590; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+ogyDL6MEqk+X9fxmfimDp67js4GEaptZ9YAfaG485E=; b=Kq4lhtnIFDDBbByWu7lOMVwBjUeftwtA+0+X1yAqNw1qKPCteGRUc12iEgSK22ATP5sS9SDU+SKjMCgPcpwQXkERD/yRcR6O7DHZeARZIUqFqgMJA/eiPQ14zD9b4ETqzdlFaQPCxVyLwDZXurwZE54+YsY39jHcKdbQQgYDJpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186590961795.1091439233629; Fri, 4 Aug 2023 15:03:10 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IF7AsxcITUBHCPNRmtgRektt+H31HiN7X+vaIeUjV4p0dLO3LwaK/Zm0TNYckVBcceXWH0iGQ== 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186593102100013 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=C3=A9 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, MMULookup= PageData *p, int mmu_idx, static uint16_t do_ld_2(CPUArchState *env, MMULookupPageData *p, int mmu_i= dx, MMUAccessType type, MemOp memop, uintptr_t ra) { - uint64_t ret; + uint16_t ret; =20 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 =3D load_atom_2(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret =3D bswap16(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret =3D do_ld_mmio_beN(env, p->full, 0, p->addr, 2, mmu_idx, type,= ra); + if ((memop & MO_BSWAP) =3D=3D MO_LE) { + ret =3D bswap16(ret); + } + } else { + /* Perform the load host endian, then swap if necessary. */ + ret =3D load_atom_2(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret =3D bswap16(ret); + } } return ret; } @@ -2390,13 +2394,17 @@ static uint32_t do_ld_4(CPUArchState *env, MMULooku= pPageData *p, int mmu_idx, uint32_t ret; =20 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 =3D load_atom_4(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret =3D bswap32(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret =3D do_ld_mmio_beN(env, p->full, 0, p->addr, 4, mmu_idx, type,= ra); + if ((memop & MO_BSWAP) =3D=3D MO_LE) { + ret =3D bswap32(ret); + } + } else { + /* Perform the load host endian. */ + ret =3D load_atom_4(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret =3D bswap32(ret); + } } return ret; } @@ -2407,13 +2415,17 @@ static uint64_t do_ld_8(CPUArchState *env, MMULooku= pPageData *p, int mmu_idx, uint64_t ret; =20 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 =3D load_atom_8(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret =3D bswap64(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret =3D do_ld_mmio_beN(env, p->full, 0, p->addr, 8, mmu_idx, type,= ra); + if ((memop & MO_BSWAP) =3D=3D MO_LE) { + ret =3D bswap64(ret); + } + } else { + /* Perform the load host endian. */ + ret =3D load_atom_8(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret =3D 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 =3D 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 =3D io_readx(env, l.page[0].full, l.mmu_idx, addr, - ra, MMU_DATA_LOAD, MO_64); - b =3D io_readx(env, l.page[0].full, l.mmu_idx, addr + 8, - ra, MMU_DATA_LOAD, MO_64); - ret =3D int128_make128(HOST_BIG_ENDIAN ? b : a, - HOST_BIG_ENDIAN ? a : b); + a =3D do_ld_mmio_beN(env, l.page[0].full, 0, addr, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + b =3D do_ld_mmio_beN(env, l.page[0].full, 0, addr + 8, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + ret =3D int128_make128(b, a); + if ((l.memop & MO_BSWAP) =3D=3D MO_LE) { + ret =3D bswap128(ret); + } } else { + /* Perform the load host endian. */ ret =3D load_atom_16(env, ra, l.page[0].haddr, l.memop); - } - if (l.memop & MO_BSWAP) { - ret =3D bswap128(ret); + if (l.memop & MO_BSWAP) { + ret =3D bswap128(ret); + } } return ret; } @@ -2874,7 +2888,11 @@ static void do_st_2(CPUArchState *env, MMULookupPage= Data *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) !=3D MO_LE) { + val =3D 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, MMULookupPage= Data *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) !=3D MO_LE) { + val =3D 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, MMULookupPage= Data *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) !=3D MO_LE) { + val =3D 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 ad= dr, Int128 val, cpu_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); crosspage =3D 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 =3D bswap128(val); - } if (unlikely(l.page[0].flags & TLB_MMIO)) { - QEMU_IOTHREAD_LOCK_GUARD(); - if (HOST_BIG_ENDIAN) { - b =3D int128_getlo(val), a =3D int128_gethi(val); - } else { - a =3D int128_getlo(val), b =3D int128_gethi(val); + if ((l.memop & MO_BSWAP) !=3D MO_LE) { + val =3D 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 =3D int128_getlo(val); + b =3D 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 =3D bswap128(val); + } store_atom_16(env, ra, l.page[0].haddr, l.memop, val); } return; --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186527; cv=none; d=zohomail.com; s=zohoarc; b=QsMtz2Z21a4Q37Pts8SGObApX39KfsYDP4wcz28A0a64Kn3CqSzg0ZYUQLAMDH7eByvPKWBmk39R67rwj901afTMSAlbKgaTqxfCh5fA49a1/TkFLzCNvCZSao3ppcPpNBGB5eER737MYuzf/rDYci3zB7oVyiyzosItSwJ+Z4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186527; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PGTKa1g9aGwPuG4tk4crlE1qhIW/f2V62gcPYilpvuU=; b=ejDj3Ba5WZfE13swkRj/mry38vKYYw5JObtXBnOmnsPXF5SojeheYEU51T0JDYaG/W2YyXd/+M/RvfgWTXaLJGP+sllLjeoSfqyG0bCQZqdmosMtpjloUq8bd+dv86qlhrtvS8FCAGQ8gN4KdLekhOsUmNVpi4DXm5z/3VXUMos= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186527277362.84667891056654; Fri, 4 Aug 2023 15:02:07 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGybyUU1dJU0XPYU0BYXNuf1Sl9Qc2NvYjRHbge/8qmYWCuS8uEl7wSJ9JSbyTsIrQ0Qu+3xQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186527678100001 Content-Type: text/plain; charset="utf-8" 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_m= athbern@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 =3D 1; + p =3D 0; } =20 ret =3D qemu_strtoul(buf, &buf, 16, &t); --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186491; cv=none; d=zohomail.com; s=zohoarc; b=AB1vo58RueW2AQWoKR5B4uayWmrUBxGmYpPHknSkeX92e0+LNy8ZKlvwIMTwk/kxN5Tki5OD/JdAJJiUxgvAAblxfpqoNRrcoeouM2mKWySFchD4W7RQHoJ0zx95Gsm6dd2cegwCZVbUuU/qurBUW8EAHjFms0r/knUrk1dnHjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186491; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; b=brDgjsloKCS1Ea6dT3msshV5dZoWlYcr0/SJZFNBBCMyguvMCFEZaMKoN0OPw25K76ibCUfBWzfEg5RzRkNWPVEVupGHqfwIODG1wcJhpe7D/6O2y5qhCs15l3LBSfWFozEAehx53y7TguTjFkrMS+gMSI1jet7A44MgQwjIa6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186491340575.693652353436; Fri, 4 Aug 2023 15:01:31 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IFOMrzsnhd5ExEMKYhqpqfxzD+C6ZJAO1zVWurWbodAgOeRpZJHDAneCI0njWyBGZZmecUs6g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186492900100007 Content-Type: text/plain; charset="utf-8" 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; } =20 - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno =3D EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno =3D EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something els= e. + * 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 overwri= te + * any host address mappings. + */ + if (reserved_va) { + flags =3D (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } =20 /* --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186490; cv=none; d=zohomail.com; s=zohoarc; b=ROf/zBkCK2PUgb7fFlQ2yArZQ5DiT8NyjtCCyc5D4HmiW9yU1+1jEGWwg9/5dwYJUpVGbmn0updpLOQUKACgRCR/HkX7+EZslVcAfaCoK1JJZIPd7Q8zJa/crC9LFjMSOSksKXp3Du6XzDrWsqPGs6liLEYIAzF5fdYSqje87OA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186490; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y+al/bCM9dfQjUvbH6ERA5E1FapPNk6WKGGZIMvtMEA=; b=it66cN9PpVv7NEcY9oOP5PDr58UZUkZSLzY1TM+FZbshre6pdlMNJ1yRIEmtr2IJECkSLp2tiZmPLHAimx04wutfDCeP/8pJPR3Lpequ4jhrFtmFrLCY9FCOxVtAHCuqvASU5JW130vxaFcVKEKx3I/FetQqmvyOllf+OfQ25Sg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186490707794.201927979421; Fri, 4 Aug 2023 15:01:30 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEkYR4b+kE+t357l5OPKONFVHWmg+G3qpEMeO8t0BSWTrFkleWAheC7I9V2T4VP2+Ifhhrd4Q== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186492914100008 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 =E2=80=9Cnon-MAP_FIXED=E2=80=9D 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 =3D mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p =3D=3D MAP_FAILED) { + if (p !=3D host_start) { + if (p !=3D MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno =3D EEXIST; + } return false; } prot_old =3D prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, =20 /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; =20 if (flags & MAP_ANONYMOUS) { offset1 =3D 0; } else { offset1 =3D offset + real_start - start; } - p =3D mmap(g2h_untagged(real_start), real_last - real_start + = 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p =3D=3D MAP_FAILED) { + len1 =3D real_last - real_start + 1; + want_p =3D g2h_untagged(real_start); + + p =3D mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p !=3D want_p) { + if (p !=3D MAP_FAILED) { + munmap(p, len1); + errno =3D EEXIST; + } goto fail; } passthrough_start =3D real_start; --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=zohomail.com; s=zohoarc; b=RlXlaaaQf3oqEi2N6mCXU+9HXzRHv07w/luwiQFnPpW3kgUQD96pwBFX+SBJ8UMDItbj8D64PaejbkV1Bk1DhNgDlEFGIh134S0Tmbuusvzf9p1t6vBdiZXS5PWvTeLtpAFv9NXujDewbTVux6jS5FQ3Z81IxfSg/96ryugO5dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186809; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=iOlyg7HUhSOZdXIzWBS2rbNgeeooBhvHPH+veDZFJCkY/soaOsbro9LlIm/0GNiXkE3w0PrwaLNDdR1rNbOo12U4Jl6GSNxdqyDSI2uw9f+HUGIuXHapwIo/PyVS+U/JIRW/WCQnsPEdUH/QdzoMTMWFEXLwV3V1HFSXTsdTWfA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186809950836.3071035728664; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGj9gI8mN4y1WlD7trCMaij0y/nx+nuTFXe0rvvnqR+1fPrZK9/ku3zrEBtk2dJYDPXKEKsMw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186810777100005 Content-Type: text/plain; charset="utf-8" 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 =3D new_host_brk_page - brk_page; - mapped_addr =3D get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr =3D target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size =3D 0; mapped_addr =3D brk_page; --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186526; cv=none; d=zohomail.com; s=zohoarc; b=ZLPz7RjMWxiXR/bqOyfv5CZ8oI1YoUCClU1w7xmwQ1exoh2FIrSFUt4ZyFlYVDvRU0aPq6jTnOP3Ktpj42QFak5tUImp3lrDy9qDbWujiR5Ee0/ZTyfs8U8RmDuzr9tvglg+Zjou7U7u2au2OkPeDcYtSLXyMFLJ9BWBhKKPkHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186526; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; b=AjdRx0gpSGD4LaxoGYdnCpT+UoPrrvMCH0W3PEbiZOftFZzuWvuzk6+5u8d9p8ExWSj2Rg0kg9V3+Uq6dMFSTNtCinKxoDdkJg1QYgbf1cAzaPR2pog3qTMC5TWzYRa2nO+nUyDYxJqAMJddqI5LlD9KrIaNoqLpnXsKzFZ3hI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186526968187.6229289428593; Fri, 4 Aug 2023 15:02:06 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IG+KHBw+Kd5NUx4rZ/Y+snEUDfpH17SVvs+iCiI3iZeo+1Fwt48fD2BK8zOCqebdTNrzE7upA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186527698100002 Content-Type: text/plain; charset="utf-8" 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; } =20 - /* 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 =3D new_host_brk_page - brk_page; mapped_addr =3D 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_PRI= VATE, + -1, 0); } else { new_alloc_size =3D 0; mapped_addr =3D brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk =3D brk_val; brk_page =3D new_host_brk_page; return target_brk; - } else if (mapped_addr !=3D -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 =3D -1; } =20 #if defined(TARGET_ALPHA) --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186591; cv=none; d=zohomail.com; s=zohoarc; b=K1PbWmDXa2lbcunP99TSuoU3VrziPCr9axSMTFKMDwN7c/iKLgjEYITqVCMOauQv0rW725bXXuQvdpHh2Q2yH6UjKNfMTl+RpJD2B2VWmWZnzs5BQlBIn8aXHuuh95Ei4JDDypH7fHohie6Q/OBBojFslVriB970+GgkrLMoUkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186591; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=YG8fQeqizrOS1DxBibGO+/RDwru4ISkhgpIknhGZktJql8KNH6NOL7eMrzDrWeiDZwyS3RdAaZyDDA+RjvbFFre7hEU50zyGXuVGUs8hZxxWHjkxXcFZAHK19Cw3tBtEPs3O7NjOslfhGsLPxLenFIOYfHs++BvTSykUu2dIWIo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186591771809.3380414231673; Fri, 4 Aug 2023 15:03:11 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEssg9bEPkUkUo4ygfoMByROp49nvMIwW90HpNZTKJ4SHgHXPJsPNxEPoBTQ5zlv3CaphZnqw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186593484100015 Content-Type: text/plain; charset="utf-8" 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) =20 /* brk pointers are always untagged */ =20 - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val =3D=3D target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val =3D=3D target_brk) { return target_brk; } =20 /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val =3D initial_target_brk; + return target_brk; } =20 new_brk =3D TARGET_PAGE_ALIGN(brk_val); --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186644; cv=none; d=zohomail.com; s=zohoarc; b=BVth97Q4TpsoIqQj4C5//mos4fPD0xozJ3qTu0fAUm/Zf/9CPjojFHEJyR0Scpm7UPOyZaRd5V4yYDwc7AeZ1/t4ZcCcudoyFOUFkZO3nEVhCoWLb82upmQ9xEAfRkOsDsnYOnJUgxptbjajYyn3//KAcnJCqs0fHEHfPslt8j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186644; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=SDW6j+0y4etwQbD4sYEn7+XC4U6QdzOtqnuWUvAHPLwvYeABf5o1QZk/sqKKnfql2RV4alNC9u1Jt526AWUciNQkqEOQ76RdrfUQ27vQ7tZ1DVfW1C1nI5IQ5VWImI9n2yKAdD7tVVrcgEsGhL85K6tB/cgv3n6UU+K/nlJOepo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186644406728.9605067312121; Fri, 4 Aug 2023 15:04:04 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IHkT/EoB3si9+JeczHUZRTVpTfuBDjCQH6KzHOnaPDfgg2x+7Pr6CW6x7EkvLRGYQiO6mepjg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186645366100003 Content-Type: text/plain; charset="utf-8" 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 =3D HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk =3D HOST_PAGE_ALIGN(info->brk + info->reserve_br= k); + abi_ulong start_brk =3D TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk =3D TARGET_PAGE_ALIGN(info->brk + info->reserve_= brk); target_munmap(start_brk, end_brk - start_brk); } =20 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_t= ype) } =20 static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; =20 void target_set_brk(abi_ulong new_brk) { target_brk =3D TARGET_PAGE_ALIGN(new_brk); initial_target_brk =3D target_brk; - brk_page =3D HOST_PAGE_ALIGN(target_brk); } =20 /* 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; =20 /* brk pointers are always untagged */ =20 - /* return old brk value if brk_val unchanged */ - if (brk_val =3D=3D target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } =20 new_brk =3D TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page =3D HOST_PAGE_ALIGN(brk_val); + old_brk =3D TARGET_PAGE_ALIGN(target_brk); =20 - /* brk_val and old target_brk might be on the same page */ - if (new_brk =3D=3D 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 =3D=3D old_brk) { target_brk =3D brk_val; return target_brk; } =20 /* 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 =3D new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); =20 target_brk =3D brk_val; return target_brk; } =20 - if (new_host_brk_page > brk_page) { - new_alloc_size =3D new_host_brk_page - brk_page; - mapped_addr =3D target_mmap(brk_page, new_alloc_size, - PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRI= VATE, - -1, 0); - } else { - new_alloc_size =3D 0; - mapped_addr =3D brk_page; - } - - if (mapped_addr =3D=3D 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 =3D target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); =20 + if (mapped_addr =3D=3D old_brk) { target_brk =3D brk_val; - brk_page =3D new_host_brk_page; return target_brk; } =20 --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186617; cv=none; d=zohomail.com; s=zohoarc; b=Yuomy252JmNMY5Y0Jp8hzq+vnrG510NVZpV37OUNElj8GJw3siYF0JyAD9xpDRGrJw2OCgP8ouV0PNdNAN6eYMDOIbxPa6ao0MgLFhYO1tIte+DTgqm9cEoukBNfFXeqEkbUSw3Zq2rD6HQ+7uVrmkMxkf8FqugwutXpSvLrOQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186617; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PiKvQ5TIjJkHeXd+ZGncRxkavk8D0Yfna3UAt9/lKq8=; b=T4xLnr4xvNBhkAY6C1SxUd3E5B956wdPEnwxOYPJZb5KKw8gpaN15z86M71VFv8nQUV38qdLCZTJHO0c9rBUxu8L7ozVvWprNpNxk1dZXoCPJuzHmdXhQrnuAvXHsq5RReRaZeiyM6tqWKXl9aSggmpoTuXWl4nPAXDZu1OFRMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186617415992.020480695492; Fri, 4 Aug 2023 15:03:37 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGEI7gZLxcYvxUdm3ij0fXgfeT2TT59jv29QHOhqZX/t3VbsnacsDIboNaSfnXH8m0UkZrj7w== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186619584100007 Content-Type: text/plain; charset="utf-8" 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 s= tart, abi_ulong last, #endif abi_ulong mmap_next_start =3D TASK_UNMAPPED_BASE; =20 -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186817; cv=none; d=zohomail.com; s=zohoarc; b=INS3EN4be7l/JvLOuau26fNLIa2MBNiB+GJYuG4+hFRFN9k+ErAbPudBtcNco3YwlzY5y1VKepSDIByHxFU2vJ4wwAp318mXqdw5kgKC9F7m4Ed79thhKi5tcRuWTwq5NepX5xqocRcdMaBBLWXHQ1pYBUGzjRpkEeOwmbdh3Fo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186817; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=J232yhl28hbgha9Um5MUBL7iTmGI7sNjbRLtOJ9FhG2ljpzODY4Lb7aeAil4RCetnDMvQXcrrJN5svJ5GmGDrqkI/QWYXBk9Y0e5GfPUPav1nQE6W0D5mLZy/q0zfg9U33hXvOfcaVejkFWYd+77NggLeJctEscOlIlYFS66Nzw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186817822479.60909678542; Fri, 4 Aug 2023 15:06:57 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IH17YjlFAFfIU3JiSQtdJODOEPaT9Qd8yM/QONZOLg0m9+f1zeyTcxvim2xtst0w6TqtR+BNQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186818248100005 Content-Type: text/plain; charset="utf-8" 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 ol= d_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 =3D TASK_UNMAPPED_BASE; =20 -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of= guest * address space. --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186590; cv=none; d=zohomail.com; s=zohoarc; b=FznQ1pKsHWUAYeYgdGSRCzwFjZLLiCC/rYyJmpG4w4w87dU3C6lT0YhbQEXcOFPc9pmYJ/14AJKT4qQNyUfm0LNtyh445JLp1C9xzhPMuJzA2k29WgewY1cOyrkIm5uVLwEr4dP35WUPIQPox27ac40o/0BmPAo8OR6n+9nIDsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186590; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=VYvPUssACJi945eUOiH4v7Hb1EmWqgUjqAtVcwZp04BCiTNsl6nyAw12POG+ZF5ngB4CxpvV82H82GVuHgS5DNm6ZNHniqZvwysYwv1JBebk+c5a7rcR6m9f1RWFXcd0HmJFWbuvtO4kOhY0Kr32xXREVf5Qfvi1aWDZeTKLqAg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169118658991156.52028370355731; Fri, 4 Aug 2023 15:03:09 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEfa8G0NoJQT7i13XtjrcsU/OJ9JyT4yBXVlmWDltnUuDAo+g9wiLEh1T16DZ2FKE9KqOw34w== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186591525100007 Content-Type: text/plain; charset="utf-8" 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 =20 +#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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 =3D max_reserved_va; } =20 + /* + * 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 =3D TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base =3D TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (TASK_UNMAPPED_BASE < UINTPTR_MAX) { + task_unmapped_base =3D TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base =3D 0x10000000; + } + mmap_next_start =3D task_unmapped_base; + +#pragma GCC diagnostic pop + { Error *err =3D NULL; if (seed_optarg !=3D 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; } =20 -#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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 =3D TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; =20 /* * 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) =20 if ((addr & (align - 1)) =3D=3D 0) { /* Success. */ - if (start =3D=3D mmap_next_start && addr >=3D TASK_UNMAPPE= D_BASE) { + if (start =3D=3D mmap_next_start && addr >=3D task_unmappe= d_base) { mmap_next_start =3D addr + size; } return addr; --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186761; cv=none; d=zohomail.com; s=zohoarc; b=IVRizgrh29/3n/30pi1fIXcfrJ7kmGnsg6R2BrWsMLN49CCA+jUZE9ixVhHOlv1Rd4ZJ2S+XUet6Lfxiwvos2bZGMkfQA7h06RpPiPOChflVerYqRI10JHwC2tFtQTye5r4H2vSCug12KUUVMjJNNNAPy0BFIKRyXzeS5FYye7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186761; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nsfMjTlh4URCmzpsUVnlBQkKHMyACEHtsPPiByh/vaY=; b=KvrDN5Atq2VUt//vtknphcV3eo4sDSwqPCLOxH4B+OJl+mY5nrwQ1jj8gugi1HbxySTB1b80kYo2aw4SONo6K6n9Q1SmVmH+GXULuPRt/fhvgnSo3GUDfyGzcyV4fQP2HIwqbnaouF5KR5fNrQtfX32VKJUV8ba0S9CYxUAABmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186761562826.5641847899553; Fri, 4 Aug 2023 15:06:01 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGBdEngHw3u/1N/Gx2a1yml++ZNcTSh2esoDfLUsOTDJFXhOj1DxDGtxioVZVy1x7t2T6dFKg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186762495100003 Content-Type: text/plain; charset="utf-8" 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_m= man.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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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_m= man.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 =20 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" =20 #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/ta= rget_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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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 =20 -#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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; =20 diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mma= n.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_mma= n.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 =20 +/* + * 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" =20 #endif --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186831; cv=none; d=zohomail.com; s=zohoarc; b=Nx+Ggi3YIsCkWofan7gBMRvFedIYMdMnT8gxzzeyLCAqZkrstZxbRAJoUeoYK1rJSn5UfPF5LGD4tznIcbLdxcWavk4muMLNEYFlEUFkweM9widwgvKAFT5lMKQkVX9bC6cPSU1PsbVo4ofeG/WucU3O6vDdXPuN5w/tuOPfxl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186831; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xi2nnTJzHZgHa81d23KxFW8Q4gCAsLnkTLrg8o9pfyQ=; b=HVkH78+fHDDfxYzI4+pEI6pX+I0Mn50KyWCDno1y2W0DZh8ITRkyUUJCar5wVTI538v1fla8N7TnF/ZrslGsGb4JDmhPAegvD6Cr0m0aO4/qswQOSPZpTtvFiBzM9g6ZsAEMdn0VYOA/iVJexZixD1nflFQLjP1bMGijRLul0K0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186831247938.6466360665327; Fri, 4 Aug 2023 15:07:11 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IH+0IhE688bQDNa5xNXOUrtjVLVRnsOqElbqfszjiFuYXgpYSvrLhNZY/xy3fb3IbUPdmnzew== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186832620100001 Content-Type: text/plain; charset="utf-8" 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_m= man.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)) =20 +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" =20 #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 =20 +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" =20 #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 =20 +/* 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) =20 +/* 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_m= man.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 =20 +/* 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 =20 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" =20 #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 =20 +/* 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) =20 +/* 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 =20 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/ta= rget_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 =20 +/* 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) =20 +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" =20 #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) =20 +/* 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 =20 +/* 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 =20 +/* 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" =20 #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) =20 +/* 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) =20 +/* + * 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) =20 +/* 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 =20 +/* + * 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" =20 #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 @@ =20 extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; =20 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_mma= n.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) =20 +/* 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_mma= n.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)) =20 +/* 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" =20 #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 =3D task_unmapped_base; =20 + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (ELF_ET_DYN_BASE < reserved_va) { + elf_et_dyn_base =3D ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + elf_et_dyn_base =3D TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (ELF_ET_DYN_BASE < UINTPTR_MAX) { + elf_et_dyn_base =3D ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + elf_et_dyn_base =3D 0x18000000; + } + #pragma GCC diagnostic pop =20 { 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 s= tart, abi_ulong last, =20 abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; =20 /* * Subroutine of mmap_find_vma, used when we have pre-allocated --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186632; cv=none; d=zohomail.com; s=zohoarc; b=mgzArllHMPNuflOohdzBDsDgR4SdpfTHAkf3H/VnqaZ9MXkjpfHuKKYM55dPXUV/6H8OlhPCkdkAD74gdVEQKZYl/AEHBAXHpJSuZcEUHY170J/KureZbWzeo5MR2iuXXJ5kbAnNBMQVBhEI6cWY+HEt5T9vne78NFYG8rRN5Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186632; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; b=G3FL/F7jBs25CI7xIJEyK2ng8JgtRgHtqO/a4iBCT/bOCXIIxnIfOtFS8Auj96CP8EXNmMl1hliR5QZ6bFzI5PlLxqJ/gG3MHNijB0XpEfKCy7OOw2AvoDTpXLUfcJvyxEsWZGkH49MriXiChqdY+eUAcgPWqycFLsP8cX5L9T8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186632400156.8547305149483; Fri, 4 Aug 2023 15:03:52 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEBTsOUfwxvzwEMfBdNWS3A2nKuChwBBNqfutA5OyFKjqMV+j1xf11uFLxExvxPc/HcsIuIfA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186634005100003 Content-Type: text/plain; charset="utf-8" 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, i= nt 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 usi= ng + * 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, in= t image_fd, */ load_addr =3D target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NO= NE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED : 0), + (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED_NOREP= LACE : 0), -1, 0); if (load_addr =3D=3D -1) { goto exit_mmap; --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186769; cv=none; d=zohomail.com; s=zohoarc; b=kheQNhtcPcSuPDUeZ5KBvK/B/TBCnmRkqmR9gQXIt7gjl2wQWnWbapISVSruONYJyDilQ0q/r60J3oUhc5NUY7nTTTrEAjAN7J/8HH+qofNKx/v0tNZA0llYBxBTG3op5RRrXWCPuzd1o5b85BF2ynP0bms5v6/bR3okqvLU+L4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186769; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gDTWs7pBzjEM4yDIiLCCxRn3NjvKLf/PjlJHIm+hkqo=; b=d43NwSrr40MNmbMh7xT5BOW1Pl2xPP8b+OF87lEABpmK7iN1fkJ3Ww6Tmi9G7PfxR5cD8yZCjdyP83igUvzcxWcVvKVpv6GLU0bSNXRWyN/7ieTqnM9w6gDrtq6rzV0XOos2qRB0vyxQhieoT3tljTHgm6uT1OHa6nmthsTrstk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186769975265.05317117158563; Fri, 4 Aug 2023 15:06:09 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IH9GPZG4uLgHn43hLBSpt0pabwu+ogSSJoAj/GOPZjekO+DSSlYgIrz5qp1QfxOqmoL/8gurw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186770374100001 Content-Type: text/plain; charset="utf-8" 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, in= t image_fd, } } =20 + load_addr =3D loaddr; + if (pinterp_name !=3D 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 +=3D 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 =3D pow2ceil(info->alignment); + if (align) { + load_addr &=3D -align; + } } } =20 @@ -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 =3D target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NO= NE, + load_addr =3D target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT= _NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED_NOREP= LACE : 0), -1, 0); --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186589; cv=none; d=zohomail.com; s=zohoarc; b=IstXyu/3S70Rg1srbkbBOkI8s/pATMAOpsbIEP70QxbH788QTxGEnL5aq1E3eRKdxL99jLuNOJkmxHwekAOx3TC0bZTyUrUx0ymJLoHI24WRdFApZcb5/2S+pJ5NSnXwyA90QIiycrjtCPKkCC55iDdZNLV7ttCab1XaWhnZkAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186589; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LEtd4K5hRnVc6hrl39zIoY3R0ensohNvKsrzBxsSkfw=; b=df9V8ad1FszoGrAwk6e0X+IAUmxHZnlxMRPqUNNNcZzjoBpYzHVCduD/nbgtP9A6pIewePV5QDefHbi7o6d2h7ZDkSZz+FoneiUXNybUzAamY2CnITuNmakl+0Gb5EJeh32F+uFfd6wVPTzH0L1Oyjys9n971/TR7q1+Cv71UBI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186589173705.4720340087358; Fri, 4 Aug 2023 15:03:09 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEqH+c2S4v1kbi36OKG+dxb63Dmy2qMSJItGI3OOIpDdiPaI53Td0n3O00rukGhSdM1VoPESw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186589466100001 Content-Type: text/plain; charset="utf-8" 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, i= nt image_fd, load_addr =3D loaddr; =20 if (pinterp_name !=3D 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 =3D=3D 64 - info->reserve_brk =3D 32 * MiB; -#else - info->reserve_brk =3D 16 * MiB; -#endif - hiaddr +=3D info->reserve_brk; - if (ehdr->e_type =3D=3D 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, in= t image_fd, info->end_code =3D 0; info->start_data =3D -1; info->end_data =3D 0; - info->brk =3D 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk =3D TARGET_PAGE_ALIGN(hiaddr); info->elf_flags =3D ehdr->e_flags; =20 prot_exec =3D PROT_EXEC; @@ -3314,9 +3294,6 @@ static void load_elf_image(const char *image_name, in= t image_fd, info->end_data =3D vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk =3D vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3645,6 +3622,19 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); =20 + /* + * 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 =3D interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ =20 @@ -3698,17 +3688,6 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) bprm->core_dump =3D &elf_core_dump; #endif =20 - /* - * 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 =3D TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk =3D TARGET_PAGE_ALIGN(info->brk + info->reserve_= brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } =20 --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186512; cv=none; d=zohomail.com; s=zohoarc; b=idbTYVi4r8yr4f/J5gMYI0KrK6wvLoHbuNBJHxGY58K5OWzwPpKO05MTP5yWn1Y96pzssCgqIptc8LDy2ZwHOO6t+uNUu1teK02IIuF7heQYs9UKrMWYknnGtSmiGKbpWuyisg3cbHOAbnOtGfoqFLRBLwYv6DXogBY3uD3kZbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186512; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4+a1ntD1nPZIq5/3BuYdNWBqjL6H8GnZs4Nnik5eIQQ=; b=HluRJZtP+mMzrEUfKxwEnjHVDbtyW2U7ARR78x9JdVxevgf5Nl9ZQaN0+u+C6b7kGSaGFO0cb0bk4Z7Gy9ooWXOaeb1IcVKt9Oj1PbLisHXpFFv0B/MkcDqfwYauoEgLuId13N2ZpNCqfwYyRl9LRb9sgyzWPiG1Lxum7Dn2YJM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186512458769.497083013173; Fri, 4 Aug 2023 15:01:52 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEp/KuIVCpxq54vXOKFMG6PONDj7Upeh9HJfu/CzdOQSVNZrynHaLPKfaAmEAW4Ed8A96/MWA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186512980100001 Content-Type: text/plain; charset="utf-8" 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 i= mage_info *info) info->end_code =3D libinfo[0].start_code + libinfo[0].text_len; info->start_data =3D libinfo[0].start_data; info->end_data =3D libinfo[0].end_data; - info->start_brk =3D libinfo[0].start_brk; + info->brk =3D libinfo[0].start_brk; info->start_stack =3D sp; info->stack_limit =3D libinfo[0].start_brk; info->entry =3D 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); =20 - 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", --=20 2.34.1 From nobody Sun May 19 16:31:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186838; cv=none; d=zohomail.com; s=zohoarc; b=FDnceF3kbRkBa9AmbhjlbigSFG2QkVMcVbeGkh7pbLnAr9c76rALSkCRsFlE9RtQyrW7Khqkr9UNPXO5NwaScaUylJznb4gdHUGdQUWhXUN2tqyC3OBoN2oJIrM7Ua6S1jbzS+YdeyEkuloxr/frRuYFpF6qzE16f2tqZoYApF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186838; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0VLnmjiDjAi6Gl+LJx+pmU5KrGv5xMTSD4fN49XrjM0=; b=C1sFCjuzoMD/6eCLuF0uJlstk4rZsQ6oXJGZKdJSwmSrPJmyvDj4Y37HvDSMHQBkaF0EMaFERjTi95RKDN2AduTckVeU3MYRNwZeRhJu3twYMzeZvbpixGvS44ClBPsdtS/HGhlwM9uf/nLYv2UD9kxeLiqgdc1YCURmqe/1MwU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186838553396.1048246001261; Fri, 4 Aug 2023 15:07:18 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEdKeW9CxGO6oXuvsVm4vXphXd05qaAt+vnDgNcw6eUdOkaGKxKGXxzBRcRvrfZOCexu7IChA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186838972100001 Content-Type: text/plain; charset="utf-8" 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 =20 -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE \ - (((eppnt->p_align & ~qemu_host_page_mask) !=3D 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 =20 static inline void memcpy_fromfs(void * to, const void * from, unsigned lo= ng n) @@ -3240,8 +3231,8 @@ static void load_elf_image(const char *image_name, in= t image_fd, } =20 vaddr =3D load_bias + eppnt->p_vaddr; - vaddr_po =3D TARGET_ELF_PAGEOFFSET(vaddr); - vaddr_ps =3D TARGET_ELF_PAGESTART(vaddr); + vaddr_po =3D vaddr & ~TARGET_PAGE_MASK; + vaddr_ps =3D vaddr & TARGET_PAGE_MASK; =20 vaddr_ef =3D vaddr + eppnt->p_filesz; vaddr_em =3D vaddr + eppnt->p_memsz; @@ -3251,7 +3242,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, * but no backing file segment. */ if (eppnt->p_filesz !=3D 0) { - vaddr_len =3D TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vadd= r_po); + vaddr_len =3D eppnt->p_filesz + vaddr_po; error =3D 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, in= t image_fd, zero_bss(vaddr_ef, vaddr_em, elf_prot); } } else if (eppnt->p_memsz !=3D 0) { - vaddr_len =3D TARGET_ELF_PAGELENGTH(eppnt->p_memsz + vaddr= _po); + vaddr_len =3D eppnt->p_memsz + vaddr_po; error =3D target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOU= S, -1, 0); --=20 2.34.1 From nobody Sun May 19 16:31:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186815; cv=none; d=zohomail.com; s=zohoarc; b=FVMWk75BpN/8rW0/sHYarWRh4K8QBpOPRDfEBWQG4BhY/H/gOAIdJGXDZjLSdYnl4qOIRTQEKhjFlSM7P3trqL6jH9LmqA2DzeAIdD49khkID1rOFlp6olQEDwLVZinpURHHBRGcMPqCUvXsMRrfgeyDkd01/Wh8jFWtmYBaPyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186815; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; b=mrWanQeOOpTrnBzFWGzC6FUYJNh/VF3UZc+3NP2CIfs9YgkeWcEQUOWMJzeJSfgfiA8n9gl5Rvl7m3KHgioiEUjNlDTj03O9X/pUlBB3kko9UC9FwhkDu4KnTClOjB187FQfwaHeKBbKD1Zc3oiiswfP50GVu5itac2RiJmghr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186815406546.7903999038781; Fri, 4 Aug 2023 15:06:55 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEgGeZKTgLBqE9Si7q3hVtoVuh0G46dcv5xK/nVwQzB9fIxSYpH5SeG8MZYR3wEDsiHMt9OEg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186816547100001 Content-Type: text/plain; charset="utf-8" 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_binpr= m *bprm, =20 /* 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; =20 - last_bss =3D TARGET_PAGE_ALIGN(last_bss); + align_bss =3D TARGET_PAGE_ALIGN(start_bss); + end_bss =3D TARGET_PAGE_ALIGN(end_bss); =20 - /* ??? 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 =3D page_get_flags(start_bss); =20 - host_start =3D (uintptr_t) g2h_untagged(elf_bss); - host_end =3D (uintptr_t) g2h_untagged(last_bss); - host_map_start =3D REAL_HOST_PAGE_ALIGN(host_start); - - if (host_map_start < host_end) { - void *p =3D mmap((void *)host_map_start, host_end - host_map_start, - prot, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, = 0); - if (p =3D=3D MAP_FAILED) { - perror("cannot mmap brk"); - exit(-1); + if (!(flags & PAGE_VALID)) { + /* Map the start of the bss. */ + align_bss -=3D 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(); } } =20 - /* Ensure that the bss page(s) are valid */ - if ((page_get_flags(last_bss-1) & prot) !=3D 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 =3D target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (err =3D=3D -1) { + perror("cannot mmap brk"); + exit(-1); + } } } =20 --=20 2.34.1 From nobody Sun May 19 16:31:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=zohomail.com; s=zohoarc; b=gMAqlN6XPQsC0trd75wsugRPzRsjBk2eEW+wkYl1a2JcXseNhc66kS6hiNsWOuDp6sCPNtrju9sRhAiPA3/GGastWfgBw9+SthDhm5JWC5M7OMKffgzKTmYfFBQQXTsM9nMYuTHVzgRPkzIsPlE0gpGvMzBLccjHkgRpwPeHT4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186809; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; b=DcduI3DfHqLPZSBAKWpiomlV3z1yaXMntnV8tE0PZ6CGmbRM1l/WAVD/nkP5T/P3kx6W9j+PUs4Z0UciTZ2bHhC4VFeNXlAdFsgBHUrFnI2o6TjgZLX7PojAhHpzuA7bYBuZYb+9Hx3GeMHNfDpcETdUcy27KaS0zsKfRNRBp9M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186809545159.93570430252157; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEfzcuocQZCE7FRpsLgwQMtfIWLXdusghmb9Gng0IZ+/oOQJdjhyApYuv/HZ2mgFT9+IXd2cw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186810524100001 Content-Type: text/plain; charset="utf-8" If p_filesz =3D=3D 0, then vaddr_ef =3D=3D 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, in= t image_fd, for (i =3D 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt =3D phdr + i; if (eppnt->p_type =3D=3D 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 =3D 0; =20 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 !=3D 0) { - vaddr_len =3D eppnt->p_filesz + vaddr_po; - error =3D target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED, + error =3D target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); - if (error =3D=3D -1) { goto exit_mmap; } + } =20 - /* - * If the load segment requests extra zeros (e.g. bss), ma= p it. - */ - if (eppnt->p_filesz < eppnt->p_memsz) { - zero_bss(vaddr_ef, vaddr_em, elf_prot); - } - } else if (eppnt->p_memsz !=3D 0) { - vaddr_len =3D eppnt->p_memsz + vaddr_po; - error =3D target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOU= S, - -1, 0); - - if (error =3D=3D -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); } =20 /* Find the full program boundaries. */ --=20 2.34.1 From nobody Sun May 19 16:31:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=zohomail.com; s=zohoarc; b=RqiphQ5NdBNHRAx8R0O5RETVRco4J3RMGCnLV5b/NMNJlu6OqenislYM4jhjBu9C7d2QNBBcbrxK7Akm2zKwd2p1Q8tYP+PWkCoVbHyDSw/qA72xI3XlynAjaGxis/nrzF60staxoF4+vkEatxTIKVLi9Rs6poQpDV9UyPj2OeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186809; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; b=gi+cbPyWxYaam4Jqy0KmicwJx39HmWmJrFrKYjFPKfD0SWi4jewfqYgGODLWWgTANSzqzQdNM7fT0W9YUYAcT/4FFI4AqQZ4pDQCKYTROC2l6zDmocq4w1UtX3nUF7E/WpmQ4Iu2XZ9GdAAXzLB+CKqxzp+lBd5TmMAL4/9+PMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186809765640.2515181904834; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGMooYLZtoFe1uhKLnWrJiGfCTE4/tLyAykw/BYiAo6bJWGYl00tEA3LdKy7Lt9edl4mjAFPQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186810718100003 Content-Type: text/plain; charset="utf-8" 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, } } =20 +/* + * 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 =3D &cs->saved_iotlb; + saved->section =3D section; + saved->mr_offset =3D 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, CPUTLBEn= tryFull *full, cpu_io_recompile(cpu, retaddr); } =20 + /* + * 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 =3D memory_region_dispatch_read(mr, mr_offset, &val, op, full->a= ttrs); @@ -1398,21 +1419,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEn= tryFull *full, return val; } =20 -/* - * 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 =3D &cs->saved_iotlb; - saved->section =3D section; - saved->mr_offset =3D mr_offset; -#endif -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op) --=20 2.34.1 From nobody Sun May 19 16:31:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691186617; cv=none; d=zohomail.com; s=zohoarc; b=YjOwKrL56OgNg7jGKh7O6gtDHRHViXusclyhJKuMOOQ7FJU4F1Wj7/y5yeHttjh32wrUr5NiCAVvRySv80uOVenHRHR9YL1rUczEmNp4vTKy0hHgsTLBOWArmEQ3iEL7Ss5j5PmHi2gDjcJoy5E9iR5QdQktGiBqUHuI3ftmAxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691186617; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=33FWwcFvaizWH4t629x3Vf1EkBPMJLEp9WeUHM35B6g=; b=heHnpaw99IDC6MkF4a0WqNIG7ZrtAp9+i2/3zVDWHTUgswNrZdoXz26cI4HikEFXJSMF50VqWQHCOvIZvRBdLIhJt8D8Ug/w5Hmx6B/0f5g3BzeiOZ00AbLMVlILJJKCPRpqniz5xamzbG++ps8TKraPs25ovEUu7WbI9L6h7fk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691186617662836.5489849362724; Fri, 4 Aug 2023 15:03:37 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGcWin8c2lUmCbJVcUQ+PTXDvnThAV0oGDhFUEyYh4ktAu3oBpXLn0x5+JVHDVG4abDX3Przw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691186619544100005 Content-Type: text/plain; charset="utf-8" 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 =3D RISCV_CPU(thread_cpu); uint32_t mask =3D 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'); =20 return cpu->env.misa_ext & mask; #undef MISA_BIT --=20 2.34.1